1.4 KiB
1.4 KiB
GDB
-
Compile code for GDB:
-ggdb3
-
Run code:
gdb ./<compiledFile>
-
Go to TUI:
tui enable
-
Start running:
start
-
Take one Step:
step
ors
-
Go to end of function:
finish
-
Create Breakpoint:
break <lineNr>
- Go on with
start
- Go no breakpoint:
c
- Go on with
-
Inspect variable:
print <ariable>
-
Refresh window when "broken":
ctrl + L
-
Print:
p
Debug Assembly
-
Load file
-
Enable assembly:
layout asm
-
Start at first instruction:
starti
-
Step through using
stepi (si)
andnexti (ni)
-
Show top
10
elements of the stack:x/10x $sp
TUI
-
Change window:
CTRL + x o
-
Previous/Next Command:
CTRL + P
/CTRL + N
-
Change size:
winheight <window> <+/-> <size>
- When leaving out
<+/->
it is set to absolute size
- When leaving out
-
Execute command
n
times:python [gdb.execute('<YOUR_COMMAND>') for x in range(n)]
- Disassemble function:
disassemble <function>
Breakpoint
- At function + offset:
b *FUNC+OFFSET
- At Address:
b *ADDR
Stripped Binaries
Entry Point
- Sometimes this works:
b __libc_start_main
- Only works when dynamic libraries (libc) were loaded (which is only after start of program)
- When hitting this breakpoint, GDB tells us the location of main, which is the first argument to
__libc_start_main
(gdb) info file
tells the entry point address
x x/s x/10xw 32 bit x/10xX 64 bit
vmmap gives overwie of virtual memory