如何要求在一行中显示多个变量?所以我想得到如下输出:
30 if(s[i] != '\0')
5: s[i] = 101 'e'
4: exp = 14
3: val = 123.45
2: sign = 1
1: i = 6
我一直在输入 disp s[i] ENTER disp exp ENTER (etc, etc),我只知道必须有更好的方法在一行输入中做到这一点。
要在每次重新启动 GDB 时建立多个活动的“变量显示”而不重新键入每个display i
、display s[i]
等,请使用 GDB“固定命令序列”。
例如,将此添加到您的~/.gdbinit
:
define disp_vars
disp i
disp sign
disp val
disp exp
disp s[i]
end
disp_vars
现在您可以通过在 GDB 提示符下键入来一次添加所有显示。
Employed Russian 给出了正确的解决方案,但对于那些想要在示例中使用它的人来说,请参见下文。如果您不确定是否要承诺将 .gdbinit 放在您的主目录中,您也可以将它放在您正在执行程序的目录中以进行实验。
$ gcc -g atof_ex4.2.c
$ gdb ./a.out
(gdb) b 30
Breakpoint 1 at 0x1907: file atof_ex4.2.c, line 30.
(gdb) h user-defined
List of commands:
disp_vars -- User-defined
(gdb) disp_vars #this will enable the user defined canned sequence (but I haven't done run yet! So I'll this actually doesn't work yet.)
No symbol "i" in current context.
(gdb) r
Starting program: a.out
Breakpoint 1, atof (s=0xbffff028 "123.45e-6") at atof_ex4.2.c:30
30 if(s[i] != '\0')
(gdb) s # No disp_vars output yet because I have to do it AFTER 'run' command
32 if(s[i] == 'e' || s[i] == 'E')
(gdb) disp_vars # Now it will work ;)
(gdb) s
35 sign = (s[i] == '-') ? -1 : 1;
5: s[i] = 45 '-'
4: exp = 14
3: val = 123.45
2: sign = 1
1: i = 7
当然,'r' 代表运行,'s' 代表步,'b' 代表中断,等等。我也省略了一些输出。请注意,我必须在“运行”之后再次输入“disp_vars”命令。感谢雇用俄罗斯人。