欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

[c++] gdb 调试

最编程 2024-09-30 16:36:48
...
$ ps -ef |grep .*gauss.* xxx 298366 255537 1 02:18 pts/1 00:00:25 gaussdb -D /home/xxx/db --single_node -p 28922 // 通过进程名查看需要跟踪的进程ID $ gdb attach 298366 (gdb) b hnswinsert_internal Function "hnswinsert_internal" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (hnswinsert_internal) pending. // 利用函数名建立断点,如果函数名在共享库中,不能被加载到,可以选择pending (gdb) info b Num Type Disp Enb Address What 1 breakpoint keep y <PENDING> hnswinsert_internal // 查看断点信息 (gdb) c Continuing. Program received signal SIGUSR2, User defined signal 2. [Switching to Thread 0x7f4517bfb700 (LWP 298386)] 0x00007f4612514ddd in poll () from /usr/lib64/libc.so.6 // 可以发现,执行c(continue)之后并没有停止在断点,这是因为被其它信号中断了,例如上面的信号`SIGUSR2` // 可以执行下面的命令来忽视这些特定的信号,例如忽视`SIGUSR2` (gdb) handle SIGUSR2 nostop noprint pass Signal Stop Print Pass to program Description SIGUSR2 No No Yes User defined signal 2 (gdb) c Continuing. [New Thread 0x7fd2425ef700 (LWP 303881)] [Thread 0x7fd2425ef700 (LWP 303881) exited] [New Thread 0x7fd2425ef700 (LWP 303882)] [Thread 0x7fd2425ef700 (LWP 303882) exited] [New Thread 0x7fd2425ef700 (LWP 303893)] [Switching to Thread 0x7fd2425ef700 (LWP 303893)] Breakpoint 1, hnswinsert_internal (index=0x7fd23f1aa2b0, values=0x7fd2425bae20, isnull=0x7fd2425bad90, heap_tid=0x7fd23fdc8068, heap=0x7fd23f1acee8, checkUnique=UNIQUE_CHECK_NO) at src/hnswinsert.cpp:815 815 { // 可以发现,忽视其它中断信号后,执行`c`可以直接到达预设的断点处 (gdb) c Continuing. [New Thread 0x7fd23e993700 (LWP 304442)] Breakpoint 1, hnswinsert_internal (index=0x7fd23f1aa2b0, values=0x7fd2425bae20, isnull=0x7fd2425bad90, heap_tid=0x7fd23fdc8068, heap=0x7fd23f1acee8, checkUnique=UNIQUE_CHECK_NO) at src/hnswinsert.cpp:815 815 { (gdb) info b Num Type Disp Enb Address What 1 breakpoint keep y 0x00007fd23e9b8cff in hnswinsert_internal(RelationData*, unsigned long*, bool*, ItemPointerData*, RelationData*, IndexUniqueCheck) at src/hnswinsert.cpp:815 breakpoint already hit 2 times // 查看断点信息,并可以看到断点已经命中的次数 (gdb) ignore 1 1830 Will ignore next 1830 crossings of breakpoint 1. // 如果断点在循环中, 需要被大量重复执行, 如果我们只需要查看其中某一次,例如1831次的情况,可以利用`ignore`来忽视前面`1380`次 // 的断点 (gdb) c