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

编程入门 行业动态 更新时间:2024-10-23 08:26:22

gdb 日志记录不显示到屏幕的方法(gdb13<a href=https://www.elefans.com/category/jswz/34/1768290.html style=最新版)"/>

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 <.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:
</>.
Find the GDB manual and other documentation resources online at:</>.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 文件.

更多推荐

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

本文发布于:2023-11-16 16:36:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627916.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最新版   屏幕   方法   日志   gdb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!