随笔分类 - 【13】gdb
摘要:打印函数局部变量的值 1.例子: #include <stdio.h> void fun_a(void) { int a = 0; printf("%d\n", a); } void fun_b(void) { int b = 1; fun_a(); printf("%d\n", b); } voi
阅读全文
摘要:在匿名空间设置断点 1. 例子 namespace Foo { void foo() { } } namespace { void bar() { } } 在gdb中,如果要对namespace Foo中的foo函数设置断点,可以使用如下命令: (gdb) b Foo::foo 如果要对匿名空间中的
阅读全文
摘要:为fork调用设置catchpoint 1.例子: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main(void) { pid_t pid; pid = fork();
阅读全文
摘要:为exec调用设置catchpoint 1. 例子: #include <unistd.h> int main(void) { execl("/bin/ls", "ls", NULL); return 0; } 使用gdb调试程序时,可以用catch exec命令为exec系列系统调用设置catch
阅读全文
摘要:为vfork调用设置catchpoint 1.例子: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main(void) { pid_t pid; pid = vfork()
阅读全文
摘要:同时调试父进程和子进程 1. 参考资料 1. gdb手册 2. 同时调试父进程和子进程
阅读全文
摘要:设置读写观察点 1.例子: #include <stdio.h> #include <pthread.h> #include <unistd.h> int a = 0; void *thread1_func(void *p_arg) { while (1) { a++; sleep(10); } }
阅读全文
摘要:设置读观察点 1. 例子 #include <stdio.h> #include <pthread.h> #include <unistd.h> int a = 0; void *thread1_func(void *p_arg) { while (1) { a++; sleep(10); } }
阅读全文
摘要:设置观察点只针对特定线程生效 1. 说明 #include <stdio.h> #include <pthread.h> #include <unistd.h> int a = 0; void *thread1_func(void *p_arg) { while (1) { a++; sleep(1
阅读全文
摘要:显示gdb版权相关信息 使用gdb时,如果想查看gdb版权相关信息,可以使用“show copying”命令: (gdb) show copying GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free
阅读全文
摘要:设置观察点 1. 例子 #include <stdio.h> #include <pthread.h> #include <unistd.h> int a = 0; void *thread1_func(void *p_arg) { while (1) { a++; sleep(10); } } i
阅读全文
摘要:退出时不显示提示信息 gdb在退出时会提示: A debugging session is active. Inferior 1 [process 29686 ] will be killed. Quit anyway? (y or n) n 如果不想显示这个信息,则可以在gdb中使用如下命令把提示
阅读全文
摘要:调试已经运行的进程 1.例子: #include <stdio.h> #include <pthread.h> void *thread_func(void *p_arg) { while (1) { printf("%s\n", (char *)p_arg); sleep(10); } } int
阅读全文
摘要:让catchpoint只触发一次 1. 例子: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main(void) { pid_t pid; int i = 0; for (
阅读全文
摘要:打印数组中任意连续元素 1. 例子 #include <stdio.h> int main(void) { int array[201]; int i; for (i = 0; i < 201; i++) array[i] = i; return 0; } 在gdb中,如果要打印数组中任意连续元素的
阅读全文
摘要:设置观察点 1. 例子: #include <stdio.h> #include <pthread.h> typedef struct { int a; int b; int c; int d; pthread_mutex_t mutex; } ex_st; int main(void) { ex_
阅读全文
摘要:断点管理 命令说明: 命令 说明 break 断点命令 break 函数名 为函数设置断点 break 代码函数 为某一行设置断点 break 类名:函数名 在某个类的函数设置断点 break 文件名:函数名 在文件名指定某个函数设置断点 break 文件名:行数 在文件名执行的代码行设置断点 br
阅读全文
摘要:向上或向下切换函数堆栈帧 1. 例子: #include <stdio.h> int func1(int a) { return 2 * a; } int func2(int a) { int c = 0; c = 2 * func1(a); return c; } int func3(int a)
阅读全文
摘要:支持STL的标准库的方法 1. 测试示例: #include <iostream> #include <vector> using namespace std; int main () { vector<int> vec(10); for (int i = 0; i < vec.size(); i+
阅读全文
摘要:gdb attach gdb attach的用法: #include <stdio.h> #include <thread> #include <queue> #include <mutex> #include <condition_variable> #include <chrono> names
阅读全文

浙公网安备 33010602011771号