How to add a new structure to a GDB session
❯ gcc -g minimal.c -o minimal | |
❯ sudo gdb minimal | |
Password: | |
(gdb) break main | |
Breakpoint 1 at 0x100000f90: file minimal.c, line 3. | |
(gdb) run | |
Starting program: /private/tmp/c-repl/minimal | |
Breakpoint 1, main () at minimal.c:3 | |
3 int i = 1337; | |
### Ctrl-Z to suspend GDB session; edit structs.h and struct.c; and do: | |
### ❯ gcc -c -g structs.c -o structs.o | |
### then bring GDB back to foreground with `fg` | |
(gdb) add-symbol-file structs.o 0 | |
add symbol table from file "structs.o" at | |
.text_addr = 0x0 | |
(y or n) y | |
Reading symbols from structs.o...done. | |
(gdb) p (struct sample *){23, 34} | |
$1 = (struct sample *) 0x100400000 | |
(gdb) set $foo = *$1 | |
(gdb) ptype $foo | |
type = struct sample { | |
int i; | |
int j; | |
} | |
(gdb) p $foo.i | |
$2 = 23 | |
(gdb) p $foo.j | |
$3 = 34 | |
(gdb) quit |
struct sample { | |
int i; | |
int j; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment