2 Written by Stu Grossman
3 Updated 9/26/95 by Fred Fish for gdb 4.15 release
5 This file describes how to build, install, use and hack on GDBtk, a TK based
6 GUI for GDB, the GNU debugger.
11 GDBtk is a version of GDB that uses Tcl/Tk to implement a graphical
12 user inter- face. It is a fully integrated GUI, not a separate
13 front-end program. The interface consists of several seperate X
14 windows, which use standard elements like buttons, scrollbars, entry
15 boxes and such to create a fairly easy to use interface. Each window
16 has a distinct content and purpose, and can be enabled or disabled
17 individually. The windows contain things like the current source
18 file, a disassembly of the current function, text commands (for things
19 that aren't accessible via a button), and so forth.
21 Building and installing
22 =======================
24 Building GDBtk is very straightforward. The main difference is that you will
25 need to use the `--enable-gdbtk' option when you run configure in the top level
26 directory. You will also need to install Tcl version 7.5a2, and Tk 4.1a2.
28 You will also need to have X11 (R4/R5/R6) installed (this is a prerequisite to
31 [See the GDB README file for more details on configure options and such.]
36 host> ./configure --enable-gdbtk
43 Just run it like you would a normal GDB (in fact, it's actually called `gdb').
44 If everything goes well, you should have several windows pop up. To get going,
45 hit the start button, and go exploring.
47 If you want to use GDB in command line mode, just use the -nw option. Or, you
48 can undefine the DISPLAY environment variable.
50 In the current version, you can have up to 6 windows active at once. They are:
59 Most windows have a similar layout consisting of a menubar, display area,
60 scrollbar, status box and window-specific buttons.
62 The menubar contains the following items:
64 File - General file control. Also has window close and quit buttons.
65 Options - Window specific options.
66 Window - A menu of other windows that can be popped up or created.
67 Help - Mostly unimplemented.
69 The status box indicates things like the current file and function, or the
70 current PC and function depending upon the window.
74 This can be used to type commands at GDB (useful for when there isn't a
75 button for what you want to do).
79 This contains the current source file. The margin displays line
80 numbers, and has an indicator for lines that actually contain code (and
81 therefore can have breakpoints as well). When a breakpoint is set at
82 that line, the indicator is replaced with a `B'.
86 Start - Put a breakpoint at main, and then run.
87 Stop - Stop the program (only active when program is running).
88 Step, Next, Cont[inue], Finish, Up, Down - Same as the corresponding
89 GDB command. (Finish runs the current subroutine until it's done.)
90 Bottom - Does a `frame 0' to put you at the innermost call frame.
92 There are also accelerators for various buttons (just type the letter
93 without any control/meta/alt/shift in the text frame):
102 The mouse can also be used to set and clear breakpoints when clicked
103 in the margin (on a breakpoint indicator).
107 This displays a disassembly of the current function. It's buttons are
108 similar to those of the source window, except that it uses Stepi and
109 Nexti to run one instruction at a time instead of one statement at a
110 time. The accelerators and mouse actions are also similar.
112 Additionally, there is an option to enable mixed source and assembly.
116 This displays the registers. It may have to be resized to properly
117 display all the registers. The displayed registers can be selected
118 via the Options|Config menu item.
122 Using this window, you can specify a command to be executed frequently.
123 The output will be automatically updated. Options|Accumulate-output
124 can be used to avoid clearing the window each time so that you can
125 accumulate a history.
129 The expression window can be used to just calculate an expression, or
130 to watch the value of an expression (ala the `display' command), using
131 the Update button. The expression window will also pop up
132 automatically when an expression is double-clicked in the source window.
137 There are three primary ways to customize GDBtk. One is to modifiy the appropriate
138 X resources. The other is to hack a ~/.gdbtkinit file. The last is to change
139 gdbtk.tcl, which defines the most basic interface elements.
141 X resources give you control over things like the choice of fonts, color
142 schemes and some geometry info.
144 For more serious customizations, you will probably need to hack your ~/.gdbtkinit
150 The class name for GDBtk is `Gdb', and it's appname is `gdb'. The top-
151 level windows have instance names of `src', 'asm', 'reg', and 'cmd'. The main
152 display area in each has the class `Text'. So, to change the font in all the
153 main display areas, something like the following will do:
157 To change the font in only the source window:
159 Gdb*src*Text*font: fixed
161 To find out the names of the widgets do the following (in the command window):
165 To get the list of resources (and their classes) for a given widget, do some-
170 This will return a list of lists, where each sublist looks something like this:
172 {-height height Height 24 25}
174 The first item is the name of the config option used when creating the widget.
175 The second item is the instance name of this resource, the third is the class
176 name. The fourth item is the default value, and the last item is the current
179 To get info about a single resource, add the config option name to the end of
180 the previous command. Ie:
182 tk .asm.text config -font
184 will return just the info about the font.
186 To find out the class of a window, just do:
188 tk winfo class .asm.text
190 Note that some things may be explicitly overridden by gdbtk.tcl. In
191 particular, the `tk colormodel . monochrome' command should probably be
192 disabled if you want to use color.
194 Hacking ~/.gdbtkinit and gdbtk.tcl
195 ==================================
196 ~/.gdbtkinit is sourced at the end of gdbtk.tcl. Currently there is no good
197 doc on this. See gdbtk.tcl for see what you can change.
199 The GUI is primarily implemented by Tcl/Tk code which lives in gdbtk.tcl and a
200 C file called gdbtk.c. The Tcl/Tk code determines the look and feel, the
201 layout, and the functions associated with all of the interface elements. The C
202 code is mostly just glue between GDB internals and Tclland. In essence, all of
203 the policy is implemented in Tcl/Tk, and is easily changed without recompiling.
205 To make more serious changes to the interface, such as adding a new window or
206 changing the framework, you will have to hack gdbtk.tcl. This file is
207 installed in $(libdir) (probably /usr/local/lib/). But, you will probably want
208 to hack on your own private copy before putting it up for the rest of the
209 users. GDB actually searches three places for gdbtk.tcl. First, it looks in
210 the GDBTK_FILENAME environment variable. Second, it looks for ./gdbtk.tcl.
211 And third, it looks for $(libdir)/gdbtk.tcl.
213 Internally, GDBtk is basically GDB, linked with Tcl/Tk, and some glue code that
214 interfaces GDB internals to Tclland. This means that GDBtk operates as a
215 single program, not a front-end to GDB. All GDB commands, and a great deal of
216 the target program state are accessible to the Tcl programmer. In addition,
217 there are many callbacks from GDB to notify Tclland of important events.
219 Here is a brief rundown of the GDB<=>Tcl interfaces:
222 gdb_cmd - sends a text command to gdb. Returns the result
223 gdb_loc - takes PC, and returns a list consisting of a short file name,
224 the function name, a long file name, the line number and the
225 PC (in case you didn't supply it).
226 gdb_sourcelines - Takes a filename, and returns a list of lines that
228 gdb_listfiles - Returns a list of all of the source files.
229 gdb_stop - Stops the target process.
230 gdb_regnames - Returns a list of all of the register names.
231 gdb_fetch_registers - Returns the contents of the specified registers.
232 gdb_changed_register_list - Returns a list of registers that have
233 changed since the last call.
234 gdb_disassemble - Takes a function or PC. Returns the text of a dis-
235 assembly of the entire function.
236 gdb_eval - Takes an expression. Returns it's value.
237 gdb_get_breakpoint_list - Does the obvious.
238 gdb_get_breakpoint_info - Takes a breakpoint number. Returns a list of
239 info about that breakpoint.
242 gdb_tcl_fputs - Sends output into Tcl for the command window.
243 gdb_tcl_query - Pops up a query window.
244 gdbtk_tcl_breakpoint - Notifies Tcl of changes to a breakpoint.
245 gdbtk_tcl_idle - Notifies Tcl that debugged process is now idle.
246 gdbtk_tcl_busy - Notifies Tcl that debugged process is now running.
248 For details, see the usage in gdbtk.tcl, or the definitions in gdbtk.c.
250 Additionally, there is a new GDB command `tk', which can be used to poke at
251 Tk/Tcl from the command window.
256 During building, you may run into problems with finding Tcl, Tk or X11. Look
257 in gdb/Makefile, and fix TCL_CFLAGS, TCL, TK_CFLAGS, TK, and ENABLE_CLIBS as
260 If you one of the following messages when you run gdb:
262 Tcl_Init failed: can't find init.tcl; perhaps you need to
263 install Tcl or set your TCL_LIBRARY environment variable?
265 Tk_Init failed: can't find tk.tcl; perhaps you need to
266 install Tk or set your TK_LIBRARY environment variable?
268 then you haven't installed Tcl or TK properly. Fix the appropriate environment
269 variable to point at the {tcl tk}/library directory, and restart gdb.
271 If you get the following:
273 /usr/local/lib/gdbtk.tcl:1: couldn't read file "/usr/local/lib/gdbtk.tcl": No such file or directory
275 can't unset "auto_index": no such variable
279 then GDBtk wasn't installed properly. You can set the GDBTK_FILENAME
280 environment variable to point at the gdbtk.tcl in your source directory. Note
281 that the stack trace displayed here is not valid. If you actually get an error
282 in gdbtk.tcl, the stack trace is useful to pinpoint the location.
289 o If you open an Assembly window before you have run the program, gdbtk
290 pops up a dialog box titled "Error in Tcl Script" with the contents
291 "Error: No function contains the specified address". Trying to then
292 do other things brings up a dialog box with the contents "Error:
293 can't read 'current_asm_label': no such variable.
295 Solution: Close Assembly window when there is no program running.
297 o If you open Registers window before you have run the program, gdbtk
298 pops up a dialog box titled "Error in Tcl Script" with the contents
299 "Error: No registers". Trying to then do other things, like use the
300 Start button to run the program, repeatedly produce the same dialog
301 box and the action is not performed.
303 Solution: Close Registers window when there is no program running.
305 o Expressions are sometimes not displayed correctly in the Expression
306 window. I.E. "argc" works, as does "*(argv+argc)" but not "argv[argc]".
309 [ I believe this problem is fixed, but I have not tested it ]
311 o The Breakpoint window does not get automatically updated and changes
312 made in the window are not reflected back in the results from "info br".
313 I.E. the breakpoint count in the window is not updated at each hit and
314 enabling/disabling the breakpoint from the Breakpoint window has no effect.
316 Solution: Use the command interface to control breakpoints and don't
317 open a Breakpoint window.
319 o Sometimes while an expression window is active you get a dialog box
320 that complains "Error: invalide command name ".expr.e5.expr" for
321 example. The Tcl stack trace looks something like:
323 invalid command name ".expr.e5.expr"
325 "$e.expr get 0.0 end"
327 "set expr [$e.expr get 0.0 end]..."
328 (procedure "update_expr" line 17)
330 "update_expr $expr_num"
332 "if $expr_update_list($expr_num) {
333 update_expr $expr_num
338 Solution: None except close expression window and reopen it.
340 o If you select the "Down" button in either the Source or Assembly
341 window while in the bottom (innermost) frame, the error message that
342 results goes just to the command window and may be missed if the
343 command window is not open. This may also apply to other messages
344 as well. It should probably put up a notification box instead.
346 Solution: Keep Command window open to see error messages.
348 o Not really a problem, but it would be nice to have a backtrace
351 Solution: Do bt in command window?
353 o Also not really a problem, but it might be nice to have a frame/stack
354 window that displays the last N words on the stack, along with
355 indications about which function owns a particular frame, how the
356 frame pointers are chained, and possibly the names of variables
357 alongside their frame slots.
361 o Attempting to use a Register window results in a Tcl Script Error
362 "Error: Erroneous arithmetic operation". The Tcl stack trace is:
365 "gdb_fetch_registers $reg_format $regnum"
367 "set regval [gdb_fetch_registers $reg_format $regnum]..."
368 ("foreach" body line 2)
370 "foreach regnum $reg_display_list {
371 set regval [gdb_fetch_registers $reg_format $regnum]
372 set regval [format "%-*s" $valwidth $regval]
375 "if {$which == "all"} {
377 foreach regnum $reg_display_list {
378 set regval [gdb_fetch_registers $reg_format $regnum]
380 (procedure "update_registers" line 16)
382 "update_registers all"