(GDB) GDB调试技巧,调试命令
调试时查看依赖DSO
pidof tvm_rpc_server
cat /proc/<pid_of_tvm_rpc_server>/maps
子进程调试
1.vscode -- launch.json
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}, {
"description": "libs for gdb",
"text": "set environment LD_LIBRARY_PATH=${workspaceFolder}/output/cpu_simu_dev/bin:$LD_LIBRARY_PATH",
"ignoreFailures": false
}, {
"description": "debug forked child",
"text": "-gdb-set follow-fork-mode child",
"ignoreFailures": false
}
调试跟try{...} catch(...){...}相关的问题(表现为崩溃后,调用栈没有用户代码,或者没有GDB中断)。
点击暂停调试,调试控制台中执行:
-exec catch throw
2.gdb
gdb --args ./tvm_rpc_server --port=9080
gdb> set follow-fork-mode child
gdb> catch throw
补充知识:catch point
有时程序中有未捕获的异常会导致程序异常的行为甚至导致程序的直接退出。 这对服务器程序来说是不可接受的。
可以使用gdb的catch命令来帮助我们调试异常。
使用gdb捕获异常的扔出点(相当于在扔出异常的地方添加断点):
catch throw
使用gdb捕获线程退出(相当于在线程退出的时候添加断点):
catch pthread_exit
这样,如果相应的事件发生,gdb就会中断程序的执行, 就可以使用gdb的bt命令来检查出现错误的调用栈了。
cache命令:
(gdb) help catch
Set catchpoints to catch events.
Raised signals may be caught:
catch signal - all signals
catch signal <signame> - a particular signal
Raised exceptions may be caught:
catch throw - all exceptions, when thrown
catch throw <exceptname> - a particular exception, when thrown
catch catch - all exceptions, when caught
catch catch <exceptname> - a particular exception, when caught
Thread or process events may be caught:
catch thread_start - any threads, just after creation
catch thread_exit - any threads, just before expiration
catch thread_join - any threads, just after joins
Process events may be caught:
catch start - any processes, just after creation
catch exit - any processes, just before expiration
catch fork - calls to fork()
catch vfork - calls to vfork()
catch exec - calls to exec()
Dynamically-linked library events may be caught:
catch load - loads of any library
catch load <libname> - loads of a particular library
catch unload - unloads of any library
catch unload <libname> - unloads of a particular library
The act of your program's execution stopping may also be caught:
catch stop
C++ exceptions may be caught:
catch throw - all exceptions, when thrown
catch catch - all exceptions, when caught
Do "help set follow-fork-mode" for info on debugging your program
after a fork or vfork is caught.
Do "help breakpoints" for info on other commands dealing with breakpoints.
参考:
使用gdb调试异常
gdb doc -- Setting Catchpoints
- vscode调试补充1
出现找不到glibc的情况。
无法打开“pthread_join_common.c”: 无法读取文件'vscode-remote://ssh-remote+192.168.33.205/build/glibc-S9d2JN/glibc-2.27/nptl/pthread_join_common.c' (Error: 无法解析不存在的文件 'vscode-remote://ssh-remote+192.168.33.205/build/glibc-S9d2JN/glibc-2.27/nptl/pthread_join_common.c')。
此时在launch.json中添加如下设置:
"sourceFileMap": {
"/build/glibc-S9d2JN": "/usr/src/glibc"
}
- gdb调试补充
调试时,查看进程空间调用的DSO及其路径,内存map:
cat /proc/<pid>/maps
标签:
C++ / template
, Linux调试
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构