How can I ask to display multiple vars in one line? So I want to get output like:
如何要求在一行中显示多个变量?所以我希望获得如下输出:
30 if(s[i] != '\0')
5: s[i] = 101 'e'
4: exp = 14
3: val = 123.45
2: sign = 1
1: i = 6
I've been typing in disp s[i] ENTER disp exp ENTER (etc, etc) and I just know there's got to be a better way to do this in one line of typing.
我一直在键入disp [i] ENTER disp exp ENTER(等等),我只知道在一行打字中必须有更好的方法。
2 个解决方案
#1
To establish multiple active "variable displays" without re-typing each of display i
, display s[i]
, etc. every time you restart GDB, use a GDB "canned command sequence".
要在不重新键入每个显示i,显示s [i]等每次重新启动GDB时建立多个活动“变量显示”,请使用GDB“固定命令序列”。
For example, add this to your ~/.gdbinit
:
例如,将其添加到〜/ .gdbinit:
define disp_vars
disp i
disp sign
disp val
disp exp
disp s[i]
end
Now you can add all the displays at once by typing disp_vars
at the GDB prompt.
现在,您可以通过在GDB提示符下键入disp_vars来一次添加所有显示。
#2
Employed Russian gave the correct solution but for those that want see it used in an example see below. If you're not sure if you want to commit to putting the .gdbinit in your home directory, you can also put it in the directory you're executing the program from to experiment.
雇用俄罗斯人提供了正确的解决方案,但对于那些希望看到它在一个例子中使用的人,请参阅下如果您不确定是否要将.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
Of course 'r' is for run, 's' is for step, 'b' is for break, etc. I've also omitted some output. Notice that I had to enter the 'disp_vars' command again after 'run'. Thanks Employed Russian.
当然'r'用于运行,'s'用于步骤,'b'用于休息等。我也省略了一些输出。请注意,我必须在'run'之后再次输入'disp_vars'命令。谢谢雇用俄语。
#1
To establish multiple active "variable displays" without re-typing each of display i
, display s[i]
, etc. every time you restart GDB, use a GDB "canned command sequence".
要在不重新键入每个显示i,显示s [i]等每次重新启动GDB时建立多个活动“变量显示”,请使用GDB“固定命令序列”。
For example, add this to your ~/.gdbinit
:
例如,将其添加到〜/ .gdbinit:
define disp_vars
disp i
disp sign
disp val
disp exp
disp s[i]
end
Now you can add all the displays at once by typing disp_vars
at the GDB prompt.
现在,您可以通过在GDB提示符下键入disp_vars来一次添加所有显示。
#2
Employed Russian gave the correct solution but for those that want see it used in an example see below. If you're not sure if you want to commit to putting the .gdbinit in your home directory, you can also put it in the directory you're executing the program from to experiment.
雇用俄罗斯人提供了正确的解决方案,但对于那些希望看到它在一个例子中使用的人,请参阅下如果您不确定是否要将.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
Of course 'r' is for run, 's' is for step, 'b' is for break, etc. I've also omitted some output. Notice that I had to enter the 'disp_vars' command again after 'run'. Thanks Employed Russian.
当然'r'用于运行,'s'用于步骤,'b'用于休息等。我也省略了一些输出。请注意,我必须在'run'之后再次输入'disp_vars'命令。谢谢雇用俄语。