前提:使用的是带debug信息的动态库
1 info
(1)types 查看该类型符号是否存在,若存在显示该类型符号相关信息
info types SDL_WindowData
info types ucontext_t
(2)functions 打印函数的相关信息
info functions X11_DispatchFocusIn
(3)sharedlibrary 打印所有动态库
info sharedlibrary
set solib-search-path /opt/apps/xxx/lib
(4)info address 函数名
(5)info symbol 地址
(6)info register
i r
2 print
(1)p struct table键不能识别问题
p SDL_Window table键
有SDL_WindowData,SDL_WindowEvent
p struct SDL_Window table键
无SDL_WindowData,有SDL_WindowEvent
通过对比info types SDL_WindowData和info types SDL_WindowEvent:
原因是p struct识别不出SDL_WindowData是个结构体!!!
typedef struct{
...
}SDL_WindowData;
修改为如下即可table识别struct
typedef struct SDL_WindowData{
...
};
typedef struct SDL_WindowData SDL_WindowData;
或者直接p *(SDL_WindowData*) 0xffff12343222
(2)打印static变量
static SDL_VideoDevice * _this;
p (struct SDL_VideoDevice *) _this;
p *(struct SDL_VideoDevice *) _this;
(3)打印进程上下文
p *(struct ucontext_t *)_ctx
(4)以16进制打印内存值,默认会打印4个字节
p/x 281473230680868
3 break
(1)断点函数
b X11_DispatchFocusIn
(2)断点文件
b SDL_x11events.c:388
4 disassemble
反汇编
disassemble XSetICFocus
或disassemble address
5 x
(1)以16进制打印内存地址后的100个字节
x/100x 0xffff1861b020
(2)打印指定偏移的内存值
x 0xffff9c88c000+296
6 只给thead_num这个线程的xx函数打断点
tid:281472160947648线程的X11_ShowCursor函数
p/x 281472160947648
0xffff582addc0
info thread
b X11_ShowCursor thread 23
c
7 生成coredump,gdb coredump
(1)root用户下
echo /tmp/core_%e_%p > /proc/sys/kernel/core_pattern
(2)普通用户下
ulimit -c unlimited
ulimit -c
(3)cd /tmp
gdb 可执行文件 core_xxx_xxx
注意:在出现问题的环境上gdb,不要更新so,不要破坏环境
(4)bt看调用栈
8 gdb -p
gdb -p pid
b SDL_Destroy
c
bt
9 gdb加断点后自动打印bt栈
>commands
>bt
>continue
>end
10 watch
(1)watch expr:
gdb在expr被程序写时停止
如果有一个指针p指向一块内存,则:
watch p:监控p指针变量本身,如果p中存储的内存地址发生变化,调试程序停住;
watch *p:监控p所指向的内存(*p本身就是一个地址数据),如果这块内存发生变化
,调试程序停住;
(2)rwatch expr
gdb在expr被程序读时停止
(3)awatch expr
gdb在expr被程序读和写时停止