admin管理员组

文章数量:1406913

Say I have a session like this in gdb:

320   mystruct.ticks++;
(gdb) n
321   mystruct.prev_state = mystruct.state;
(gdb) n
325   if( mystruct.variant == VARIANT_ONE )
(gdb) n
335     if( mystruct.prev_state == 0 )
(gdb) n
337       mystruct.state = 1;
(gdb) n
338       mystruct.state_final = mystruct.state;

Is it somehow possible to set up automatic printout of variables on the source line being executed after next is ran? It would look like this, dor instance:

320   mystruct.ticks++;
(gdb) n
mystruct.ticks = 102643

So, the only variable mentioned in line 320 is mystruct.ticks, and therefore after we press n and that line is executed, its value is automatically printed afterwards; then we get the next source line:

321   mystruct.prev_state = mystruct.state;
(gdb) n
mystruct.prev_state = 1
mystruct.state = 1

On this line, there are 2 variables used: mystruct.prev_state and mystruct.state - after next is executed, both of them are printed out by our imaginary functionality - and the printout confirms they are equal in value, as they should be.

Is it possible to somehow set up this kind of printout in gdb?

Say I have a session like this in gdb:

320   mystruct.ticks++;
(gdb) n
321   mystruct.prev_state = mystruct.state;
(gdb) n
325   if( mystruct.variant == VARIANT_ONE )
(gdb) n
335     if( mystruct.prev_state == 0 )
(gdb) n
337       mystruct.state = 1;
(gdb) n
338       mystruct.state_final = mystruct.state;

Is it somehow possible to set up automatic printout of variables on the source line being executed after next is ran? It would look like this, dor instance:

320   mystruct.ticks++;
(gdb) n
mystruct.ticks = 102643

So, the only variable mentioned in line 320 is mystruct.ticks, and therefore after we press n and that line is executed, its value is automatically printed afterwards; then we get the next source line:

321   mystruct.prev_state = mystruct.state;
(gdb) n
mystruct.prev_state = 1
mystruct.state = 1

On this line, there are 2 variables used: mystruct.prev_state and mystruct.state - after next is executed, both of them are printed out by our imaginary functionality - and the printout confirms they are equal in value, as they should be.

Is it possible to somehow set up this kind of printout in gdb?

Share Improve this question asked Mar 6 at 10:29 sdbbssdbbs 5,6047 gold badges58 silver badges122 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Have you checked out the display command ?
Edit: sorry, I read the question wrong and have no answer to address it.

[ranga@garuda gdb]$ cat 1.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main (int argc, char *argv[]) {
  struct {
    int argc;
    char **argv;
  } args = { argc, argv };
  argv[argc-1] = "last";
  return argc;
}
[ranga@garuda gdb]$ cc -g 1.c
[ranga@garuda gdb]$ gdb -q a.out
Reading symbols from /home/ranga/lrn/gdb/a.out...done.
(gdb) list
1       #include <stdio.h>
2       #include <stdlib.h>
3       #include <string.h>
4
5       int main (int argc, char *argv[]) {
6         struct {
7           int argc;
8           char **argv;
9         } args = { argc, argv };
10        argv[argc-1] = "last";
(gdb) break 9
Breakpoint 1 at 0x4004f8: file 1.c, line 9.
(gdb) r
Starting program: /home/ranga/lrn/gdb/a.out

Breakpoint 1, main (argc=1, argv=0x7fffffffdcb8) at 1.c:9
9         } args = { argc, argv };
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64
(gdb) display args.argc
1: args.argc = -9040
(gdb) display args.argv[0]
2: args.argv[0] = <error: Cannot access memory at address 0x0>
(gdb) n
10        argv[argc-1] = "last";
2: args.argv[0] = 0x7fffffffdf5e "/home/ranga/lrn/gdb/a.out"
1: args.argc = 1
(gdb)
11        return argc;
2: args.argv[0] = 0x4005c0 "last"
1: args.argc = 1
(gdb)

本文标签: Possible to automatically print out variables of source line on next in gdbStack Overflow