当前位置: 首页 > news >正文

gdb 日志记录不显示到屏幕的方法(gdb13最新版)


tags: gdb
categories: [Debug]

写在前面

gdb 的更新好快啊…

之前的选项都有改动了, 比如 logging…

需要屏幕重定向不能简单设置:

set logging on
set logging redirect on

了, 而是要多开一个配置, 踩坑了

方法

在此之前先看一下我的 gdbinit 配置:

set debuginfod enabled off
set pagination off

分别用于设置自动下载 Debug 信息和禁止分页(否则显示完一页之后就结束了)

步骤

[arch@archlinux gdb_test]$ gdb /bin/ls
GNU gdb (GDB) 13.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:<http://www.gnu.org/software/gdb/documentation/>.For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /bin/ls...
(No debugging symbols found in /bin/ls)
(gdb) b *0x555555559fa0
Breakpoint 1 at 0x555555559fa0
(gdb) set logging enabled on
Copying output to gdb.txt.
Copying debug output to gdb.txt.
(gdb) set logging redirect on
warning: Currently logging to gdb.txt.  Turn the logging off and on to make the new setting effective.
(gdb) set logging debugredirect on
warning: Currently logging to gdb.txt.  Turn the logging off and on to make the new setting effective.
(gdb) set logging enabled off
Done logging to gdb.txt.
(gdb) set logging enabled on
Redirecting output to gdb.txt.
Redirecting debug output to gdb.txt.
(gdb) r
(gdb) display /i $pc
(gdb) while 1>si>end

这里的测试脚本参考 了二进制分析实战一书.

上面的脚本内容就是从 entry point 进入程序, 然后单指令执行并打印 pc 指针的值(display 为自动变量)

需要注意的是, 上面的:

b *0x555555559fa0

不是随便指定的, 而是通过 startii files 查看的.

starti是跳到第一个指令的位置并暂停的新命令, 主要用于strip 之后的程序的进入点查询(例如本次测试用到的/bin/ls系统程序的调试)

核心步骤就是:

  • set logging enabled on
  • set logging redirect on
  • set logging debugredirect on
  • set logging enabled off # 用于刷新设置
  • show logging # 查看当前的 logging 设置, 非必要
  • set logging enabled on # 重新开启 logging 记录, 此时屏幕不会有任何输出

然后就可以通过 watch 监控或者 tail -f 监控来实现内容获取了, 这里还可以指定 logging 的文件名, 默认就是打开 gdb 的目录下的 gdb.txt 文件.

http://www.lryc.cn/news/217987.html

相关文章:

  • JAVA智慧工地管理系统源码基于微服务
  • 学习笔记三十四:Ingress和 Ingress Controller概述
  • Webpack的Tree Shaking。它的作用是什么?
  • 研发效能DevOps: Git安装
  • ZZ038 物联网应用与服务赛题第D套
  • 基于STM32设计的室内环境监测系统(华为云IOT)_2023
  • UE5C++学习(一)--- 增强输入系统
  • 好物周刊#29:项目管理软件
  • 玻色量子“天工量子大脑”亮相中关村论坛,大放异彩
  • 使用Gorm进行高级查询
  • 基于梯度算法的无人机航迹规划-附代码
  • 【工具】【IDE】Qt Creator社区版
  • 王道p18 6.从有序顺序表中删除所有其值重复的元素,使表中所有元素的值均不同(c语言代码实现)
  • Python入门:6个好用的Python代码,快来收藏!
  • Linux常用指令(二)——文件管理
  • AI开源 - LangChain UI 之 Flowise
  • java的集合类中哪些可以添加不同类型数据,哪些不可以?
  • 基于51单片机的烟雾和温湿度检测控制系统仿真(智能防火系统,火灾报警灭火系统)
  • 【多线程】静态代理
  • 线性代数 第二章 矩阵
  • vue实现自定义字体
  • Selenium安装WebDriver Chrome驱动(含 116/117/118/119/120/)
  • springboot的安全机制
  • 学习c++的第四天
  • BIOS开发笔记 – 显示
  • 数据库实验:SQL的数据视图
  • k8s-调度约束
  • C++设计模式_26_设计模式总结
  • 解锁AI语言模型的秘密武器 - 提示工程
  • qt手撕菜单栏