-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgdb
More file actions
236 lines (173 loc) · 6.59 KB
/
gdb
File metadata and controls
236 lines (173 loc) · 6.59 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
Looks like great resource:
http://www.ibm.com/developerworks/aix/library/au-gdb.html
"GNU Project Debugger: More fun with GDB
Customizing the debugger"
Another:
http://cat.pdx.edu/documents/advgdb.html
"A Tutorial on the Intermediate Use of GDB"
From cary:
Date: 2007-05-02 16:54
Subject: Re: totalview/zeno
If you use emacs, I'm quite fond of gud-mode, which is an integration of gdb into emacs. It has a 70's era quality to it, but late 70's...
% zeno -exec emacs
Then emacs starts, say ^M gdb, and then
Run gdb (like this): zeno -debug gdb
Then gdb starts in a buffer, and just type run. It loads the source files into emacs buffers, you can step, etc. Ahh, freak out.
And if you are new to gdb at ILM, with zeno, put this in your ~/.gdbinit file:
set auto-solib-add off
Then, when you run the program and want to examine examine the stack trace, etc, type "shared" at the gdb prompt. This delays loading the symbol tables until you need them, which makes it way faster to start up.
- Cary
Ronald Mallet wrote:
> Hi
> anyone has a quick tutorial on how to debug zeno using totalview
> what's the setup, how to launch it etc...
> my printfs can't help any longer
> Thanks
=========================================================================
This is supposedly much better than the one in /usr/bin:
/dept/rnd/vendor/gdb-6.7/bin/gdb
=========================================
Commands I always forget:
finish - continues until return
info b - show breakpoints
info th - show threads
info r - show registers
on my amd64 machine:
$rdi = first param
$rsi = second param
$rdx = third param
$rcx = fourth param
$r8 = fifth param
$r9 = sixth param
$rax = return value
stepi
nexti
disassemble $pc,$pc+1
or:
x/i <addr>
or:
disas
to print the first num elements of array, starting with startindex:
p array[startindex]@num
or:
p *(array+startindex)@num
QUESTIONS:
Q: how do I debug particular threads?
PA: http://www.qnx.com/developers/docs/660/index.jsp?topic=%2Fcom.qnx.doc.neutrino.prog%2Ftopic%2Fusing_gdb_DebuggingMultithreads.html
PARTIALLY ANSWERED QUESTIONS:
Q: how to run a shell that doesn't honor the SHELL variable?
(SHELL is set to /bin/tcsh which is too slow!)
PA: unsetenv SHELL (or set it to /bin/sh) before running gdb.
can't seem to find a way to change it once gdb has started
("set environment" sets it for the invoked process, but not for gdb stuff)
Q: how to make it NOT say "The program is running. Exit anyway? (y or n)"
on quit or ctrl-d?
PA: well here's how to make q not do it:
define q
detach
quit
end
document q
detach and quit (defined in my .gdbinit)
end
The problem is, quit still does it, and ctrl-d executes quit.
Maybe can redefine quit, and use some sort of "shell kill parent of $$" thing?
Hmm, "set confirm off" is supposed to do it, but I think it
has other undesired side effects
Q: how does the "shared" trick go?
A: http://visualgdb.com/gdbreference/commands/sharedlibrary
put the following in ~/.gdbinit:
# by default gdb loads symbols from every shared library when it starts,
# which takes forever.
# we disable that here, so that on startup, it doesn't load any.
# at runtime, you can say "shared" to load them all,
# or "shared <substring>" to load symbols from all DSOs
# containing the given substring.
set auto-solib-add off
# the following gives nice verbosity during .so loading,
# but it also gives some other undesired behavior :-(
set verbose on
Q: how to make it "shared" just enough to get a good stack trace?
(assuming "set auto-solib-add off")
A: see what I put in my .gdbinit XXXTODO: copy to here!
Q: how to make it stop when loading just one library,
so that I can shared that library and set a breakpoint in it?
PA:
set stop-on-solib-events 1
Q: how to recover if I type "wh" by mistake?
PA: not sure, but you can prevent that from happening by:
define wh
echo wh is NOT defined, to prevent you from shooting yourself in the foot.\n
end
Q: how to make it NOT repeat the previous command when I hit Enter?
PA: I don't think there's a way (short of using a front-end program),
see http://sourceware.org/gdb/onlinedocs/gdb/Command-Syntax.html
but usually the reason I want this is just so I can have
some blank lines between sections of what I've done.
This can be accomplished by typing one space on my blank line;
then I can hit enter as many times as I want and get
the desired behavior.
Q: show first arg, etc.?
PA: info registers, and then something like:
print (char *)$rax
print (char *)$rbx
print (char *)$rcx
print (char *)$rdx
print (char *)$rsi
until it shows something interesting.
$rdi seems to be first arg
$rsi seems to be second arg
$rdx seems to be third arg
Q: show what dso an address is in?
PA: info files
ANSWERED QUESTIONS:
Q: delete all breakpoints?
A: d
Q: how do I turn paging completely off?
A: set height 0
Q: how to go to a particular numbered stack frame (not using "up" or "down"
which are relative?)
A: frame <n>
Q: how to make "w" an alias for "where"?
A: put this in .gdbinit:
define w
if $argc == 0
where
end
if $argc == 1
where $arg0
end
if $argc == 2
where $arg0 $arg1
end
end
document w
"w" is a (user-defined) abbreviation for "where"
end
Q: how to stop on an exception being thrown?
A:
b __cxa_throw
or
catch throw
(both of them require libstdc++.so to be loaded)
or maybe __raise_exception (see http://www.delorie.com/gnu/docs/gdb/gdb_31.html)
Q: how to stop on terminal output?
A: b write if $rdi==1||$rdi==2
(since the args are fd=$rdi, buf=$rsi, n=$rdx)
Q: how to tell the source file it's looking at?
(strace gdb's pid and see what it's opening, is one way,
but what's the real way?)
A: info source
Q: how to tell it where a given source file is, when I know?
A: "dir <dirname>" adds <dirname> to front of search path
Q: how to set the window size, so it doesn't page in such
small increments (actually it would be nice if it didn't page at all)
A:
show width
show height
set width 10000
set height 10000
(I put that in my .gdbinit)
Q: how to I print something every time a given line is hit?
A: commands <breakpoint number>
For more info, type "help commands"