forked from cheat/cheatsheets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdb
130 lines (94 loc) · 3.05 KB
/
gdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# To start the debugger:
gdb <executable>, gdb --args <executable> [<args>...], gdb -p <pid>
# To exit gdb (after program terminated):
q, quit
# To set a breakpoint at a function:
b, break <function>
# To set a (conditional) breakpoint at a general location:
b, break <loc> [if <condition>]
with <loc> as <function>|<file>:<line>|<line>|*<address>|-offset|+offset
# To set a watchpoint, i.e., stop when expression changes its value:
watch <expr>
# To show all breakpoints and watchpoints:
info breakpoints, info watchpoints
# To delete all or given breakpoints and watchpoints:
clear, delete
delete <num>
clear <loc>
with <loc> as <function>|<file>:<line>|<line>|*<address>|-offset|+offset
# To disable a breakpoint:
dis, disable <num>
# To run the program, optionally with arguments for the program:
r, run [<args>]
# To run the current line, stepping over any invocations:
n, next
# To run the current line, stepping into any invocations:
s, step
# To run until the next line below, i.e., without new loop iteration:
u, until
# Like run, but stop at the first machine instruction:
starti
# To step or go to next line by a machine instruction
si, stepi
ni, nexti
# To run until given location is reached
advance <loc>
with <loc> as <function>|<file>:<line>|<line>|*<address>|-offset|+offset
# To run until function ends, i.e., jump out of a function:
fin, finish
# To continue execution:
c, continue
# To print a stacktrace, optionally with local variables:
bt, backtrace [full]
# Move to stack frame of given number or a frame up or down:
frame <num>, up, down
# To show summary info on selected frame:
info frame
# To print the arguments or local variables to the current function:
info args, info locals
# To print the registers:
info registers
# To print a list of all the threads:
info threads
# To print a list of all the loaded shared libraries:
info sharedlibrary
# To evaluate an expression and print the result:
p length=strlen(string)
# To print an array of given length:
p *<array>@<len>
# Examine content at address with a format and letter size:
x/<count><fmt><size> <address>
------- <fmt> ------ ------- <size> -------
a | Address b | 8 bits - byte
i | Instruction h | 16 bits - halfword
t | Binary w | 32 bits - word
o | Octal g | 64 bits - giant
h | Hex
z | Hex, zero padded
d | Decimal
u | Unsigned decimal
f | Float
c | Char
s | String
# To list surrounding source code:
l, list
# Disassemble the current or given function:
disas, disassemble [/m] [<func>]
with /m to show mixed source
# Disassemble the given address range:
disas <start>,<end>
disas <start>,+<length>
# To specify a given register, program counter, frame pointer, stack pointer
$reg, $pc, $fp, $sp
# To enable pretty print of arrays and more:
set pretty print on
# To toggle TUI mode:
C-x C-a, C-x a, C-x A
# To use a TUI layout with only one window:
C-x 1
# To use a TUI layout with two windows:
C-x 2
# To change active window:
C-x o
# To Switch in and out of the TUI SingleKey mode:
C-x s