Automate Debugging with GDB Python API | Interrupt (memfault.com)
事前:

事后:
D:\gcc\gdb32\bin>gdb32 GNU gdb (GDB) 10.2 Copyright (C) 2021 Free Software Foundation, Inc. (gdb) python print(2+3) 5 (gdb)
gdb32.exe 7,863KB. 目录下还有808个.py. 为啥我不在自己的.c里加个print_linked_list()函数呢?可能是因为gdb是调试器不是虚拟机,比如虽然你定义了print_linked_list,但你的代码没有去调用它——因为你不想看到满屏的输出。然后gdb没法像JavaScript或Python那样去eval, exec print_linked_list——a.out/.exe里根本没这样的代码。Just-In-Time debugging can launch Visual Studio automatically when an app running outside Visual Studio errors or crashes. 名字起的有点大吧?我觉得Edit And Continue更难。要是gdb能无中生有地插入代码去调函数…… 当然.exe里最好留点空白区。
加个变量print, if(print) print_linked_list(); gdb可以改变量的值啊。用#if ... #endif,最后可以去掉,而且本来也占不了多少地方。
浙公网安备 33010602011771号