GNU Debugger (GDB) : Computing Laboratory
GNU Debugger (GDB) : Computing Laboratory
Computing Laboratory
http://www.isical.ac.in/~dfslab
#include<stdio.h>
#include<string.h>
int main() {
char *str;
printf("Size of the string = %lu", strlen(str));
return 0;
}
$ gdb a.out
...
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...done.
(gdb) r
Starting program: ...
(gdb) where
#0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#1 0x000055555555469e in main () at gdb-basic.c:5
(gdb) l
60 in ../sysdeps/x86_64/multiarch/strlen-avx2.S
(gdb) up
#1 0x000055555555469e in main () at gdb-basic.c:5
5 printf("Size of the string = %lu", strlen(str));
(gdb) p str
$1 = 0x0
(gdb)
c(ontinue)
n(ext) (step over)
Continue execution until the next line in the current function is
reached or it returns.
s(tep) (step into)
Execute the current line and stop at the first possible occasion
(either in a function that is called or in the current function).
Run upto the end of current function and display return value
(gdb) finish or (gdb) f
unt(il) [lineno] (very useful for loops)
Without lineno, continue execution until the line with a number
greater than the current one is reached. With lineno, continue
execution until a line with a number greater or equal to that is
reached. In both cases, also stop when the current frame returns.
w(here) or bt
Print a stack trace, with the most recent frame at the bottom. An
arrow indicates the current frame, which determines the context of
most commands.
u(p) [count]
Move the current frame count (default one) levels up in the stack
trace (to an older frame).
d(own) [count]
Move the current frame count (default one) levels down in the
stack trace (to a newer frame).
https://ucsb-cs24.github.io/m19/lectures/GDB-cheatsheet.pdf
http://www.yolinux.com/TUTORIALS/GDB-Commands.html
https://github.com/reveng007/GDB-Cheat-Sheet
https://bytes.usc.edu/cs104/wiki/gdb