1 |
578 |
markom |
This is gdbint.info, produced by makeinfo version 4.0 from
|
2 |
|
|
./gdbint.texinfo.
|
3 |
|
|
|
4 |
|
|
INFO-DIR-SECTION Programming & development tools.
|
5 |
|
|
START-INFO-DIR-ENTRY
|
6 |
|
|
START-INFO-DIR-ENTRY
|
7 |
|
|
* Gdb-Internals: (gdbint). The GNU debugger's internals.
|
8 |
|
|
END-INFO-DIR-ENTRY
|
9 |
|
|
END-INFO-DIR-ENTRY
|
10 |
|
|
|
11 |
|
|
This file documents the internals of the GNU debugger GDB.
|
12 |
|
|
Copyright 1990,1991,1992,1993,1994,1996,1998,1999,2000,2001 Free
|
13 |
|
|
Software Foundation, Inc. Contributed by Cygnus Solutions. Written by
|
14 |
|
|
John Gilmore. Second Edition by Stan Shebs.
|
15 |
|
|
|
16 |
|
|
Permission is granted to copy, distribute and/or modify this document
|
17 |
|
|
under the terms of the GNU Free Documentation License, Version 1.1 or
|
18 |
|
|
any later version published by the Free Software Foundation; with the
|
19 |
|
|
Invariant Sections being "Algorithms" and "Porting GDB", with the
|
20 |
|
|
Front-Cover texts being "A GNU Manual," and with the Back-Cover Texts
|
21 |
|
|
as in (a) below.
|
22 |
|
|
|
23 |
|
|
(a) The FSF's Back-Cover Text is: "You have freedom to copy and
|
24 |
|
|
modify this GNU Manual, like GNU software. Copies published by the Free
|
25 |
|
|
Software Foundation raise funds for GNU development."
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
File: gdbint.info, Node: Top, Next: Requirements, Up: (dir)
|
29 |
|
|
|
30 |
|
|
Scope of this Document
|
31 |
|
|
**********************
|
32 |
|
|
|
33 |
|
|
This document documents the internals of the GNU debugger, GDB. It
|
34 |
|
|
includes description of GDB's key algorithms and operations, as well as
|
35 |
|
|
the mechanisms that adapt GDB to specific hosts and targets.
|
36 |
|
|
|
37 |
|
|
* Menu:
|
38 |
|
|
|
39 |
|
|
* Requirements::
|
40 |
|
|
* Overall Structure::
|
41 |
|
|
* Algorithms::
|
42 |
|
|
* User Interface::
|
43 |
|
|
* Symbol Handling::
|
44 |
|
|
* Language Support::
|
45 |
|
|
* Host Definition::
|
46 |
|
|
* Target Architecture Definition::
|
47 |
|
|
* Target Vector Definition::
|
48 |
|
|
* Native Debugging::
|
49 |
|
|
* Support Libraries::
|
50 |
|
|
* Coding::
|
51 |
|
|
* Porting GDB::
|
52 |
|
|
* Testsuite::
|
53 |
|
|
* Hints::
|
54 |
|
|
* Index::
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
File: gdbint.info, Node: Requirements, Next: Overall Structure, Prev: Top, Up: Top
|
58 |
|
|
|
59 |
|
|
Requirements
|
60 |
|
|
************
|
61 |
|
|
|
62 |
|
|
Before diving into the internals, you should understand the formal
|
63 |
|
|
requirements and other expectations for GDB. Although some of these
|
64 |
|
|
may seem obvious, there have been proposals for GDB that have run
|
65 |
|
|
counter to these requirements.
|
66 |
|
|
|
67 |
|
|
First of all, GDB is a debugger. It's not designed to be a front
|
68 |
|
|
panel for embedded systems. It's not a text editor. It's not a shell.
|
69 |
|
|
It's not a programming environment.
|
70 |
|
|
|
71 |
|
|
GDB is an interactive tool. Although a batch mode is available,
|
72 |
|
|
GDB's primary role is to interact with a human programmer.
|
73 |
|
|
|
74 |
|
|
GDB should be responsive to the user. A programmer hot on the trail
|
75 |
|
|
of a nasty bug, and operating under a looming deadline, is going to be
|
76 |
|
|
very impatient of everything, including the response time to debugger
|
77 |
|
|
commands.
|
78 |
|
|
|
79 |
|
|
GDB should be relatively permissive, such as for expressions. While
|
80 |
|
|
the compiler should be picky (or have the option to be made picky),
|
81 |
|
|
since source code lives for a long time usuazlly, the programmer doing
|
82 |
|
|
debugging shouldn't be spending time figuring out to mollify the
|
83 |
|
|
debugger.
|
84 |
|
|
|
85 |
|
|
GDB will be called upon to deal with really large programs.
|
86 |
|
|
Executable sizes of 50 to 100 megabytes occur regularly, and we've
|
87 |
|
|
heard reports of programs approaching 1 gigabyte in size.
|
88 |
|
|
|
89 |
|
|
GDB should be able to run everywhere. No other debugger is
|
90 |
|
|
available for even half as many configurations as GDB supports.
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
File: gdbint.info, Node: Overall Structure, Next: Algorithms, Prev: Requirements, Up: Top
|
94 |
|
|
|
95 |
|
|
Overall Structure
|
96 |
|
|
*****************
|
97 |
|
|
|
98 |
|
|
GDB consists of three major subsystems: user interface, symbol
|
99 |
|
|
handling (the "symbol side"), and target system handling (the "target
|
100 |
|
|
side").
|
101 |
|
|
|
102 |
|
|
The user interface consists of several actual interfaces, plus
|
103 |
|
|
supporting code.
|
104 |
|
|
|
105 |
|
|
The symbol side consists of object file readers, debugging info
|
106 |
|
|
interpreters, symbol table management, source language expression
|
107 |
|
|
parsing, type and value printing.
|
108 |
|
|
|
109 |
|
|
The target side consists of execution control, stack frame analysis,
|
110 |
|
|
and physical target manipulation.
|
111 |
|
|
|
112 |
|
|
The target side/symbol side division is not formal, and there are a
|
113 |
|
|
number of exceptions. For instance, core file support involves symbolic
|
114 |
|
|
elements (the basic core file reader is in BFD) and target elements (it
|
115 |
|
|
supplies the contents of memory and the values of registers). Instead,
|
116 |
|
|
this division is useful for understanding how the minor subsystems
|
117 |
|
|
should fit together.
|
118 |
|
|
|
119 |
|
|
The Symbol Side
|
120 |
|
|
===============
|
121 |
|
|
|
122 |
|
|
The symbolic side of GDB can be thought of as "everything you can do
|
123 |
|
|
in GDB without having a live program running". For instance, you can
|
124 |
|
|
look at the types of variables, and evaluate many kinds of expressions.
|
125 |
|
|
|
126 |
|
|
The Target Side
|
127 |
|
|
===============
|
128 |
|
|
|
129 |
|
|
The target side of GDB is the "bits and bytes manipulator".
|
130 |
|
|
Although it may make reference to symbolic info here and there, most of
|
131 |
|
|
the target side will run with only a stripped executable available--or
|
132 |
|
|
even no executable at all, in remote debugging cases.
|
133 |
|
|
|
134 |
|
|
Operations such as disassembly, stack frame crawls, and register
|
135 |
|
|
display, are able to work with no symbolic info at all. In some cases,
|
136 |
|
|
such as disassembly, GDB will use symbolic info to present addresses
|
137 |
|
|
relative to symbols rather than as raw numbers, but it will work either
|
138 |
|
|
way.
|
139 |
|
|
|
140 |
|
|
Configurations
|
141 |
|
|
==============
|
142 |
|
|
|
143 |
|
|
"Host" refers to attributes of the system where GDB runs. "Target"
|
144 |
|
|
refers to the system where the program being debugged executes. In
|
145 |
|
|
most cases they are the same machine, in which case a third type of
|
146 |
|
|
"Native" attributes come into play.
|
147 |
|
|
|
148 |
|
|
Defines and include files needed to build on the host are host
|
149 |
|
|
support. Examples are tty support, system defined types, host byte
|
150 |
|
|
order, host float format.
|
151 |
|
|
|
152 |
|
|
Defines and information needed to handle the target format are target
|
153 |
|
|
dependent. Examples are the stack frame format, instruction set,
|
154 |
|
|
breakpoint instruction, registers, and how to set up and tear down the
|
155 |
|
|
stack to call a function.
|
156 |
|
|
|
157 |
|
|
Information that is only needed when the host and target are the
|
158 |
|
|
same, is native dependent. One example is Unix child process support;
|
159 |
|
|
if the host and target are not the same, doing a fork to start the
|
160 |
|
|
target process is a bad idea. The various macros needed for finding the
|
161 |
|
|
registers in the `upage', running `ptrace', and such are all in the
|
162 |
|
|
native-dependent files.
|
163 |
|
|
|
164 |
|
|
Another example of native-dependent code is support for features that
|
165 |
|
|
are really part of the target environment, but which require `#include'
|
166 |
|
|
files that are only available on the host system. Core file handling
|
167 |
|
|
and `setjmp' handling are two common cases.
|
168 |
|
|
|
169 |
|
|
When you want to make GDB work "native" on a particular machine, you
|
170 |
|
|
have to include all three kinds of information.
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
File: gdbint.info, Node: Algorithms, Next: User Interface, Prev: Overall Structure, Up: Top
|
174 |
|
|
|
175 |
|
|
Algorithms
|
176 |
|
|
**********
|
177 |
|
|
|
178 |
|
|
GDB uses a number of debugging-specific algorithms. They are often
|
179 |
|
|
not very complicated, but get lost in the thicket of special cases and
|
180 |
|
|
real-world issues. This chapter describes the basic algorithms and
|
181 |
|
|
mentions some of the specific target definitions that they use.
|
182 |
|
|
|
183 |
|
|
Frames
|
184 |
|
|
======
|
185 |
|
|
|
186 |
|
|
A frame is a construct that GDB uses to keep track of calling and
|
187 |
|
|
called functions.
|
188 |
|
|
|
189 |
|
|
`FRAME_FP' in the machine description has no meaning to the
|
190 |
|
|
machine-independent part of GDB, except that it is used when setting up
|
191 |
|
|
a new frame from scratch, as follows:
|
192 |
|
|
|
193 |
|
|
create_new_frame (read_register (FP_REGNUM), read_pc ()));
|
194 |
|
|
|
195 |
|
|
Other than that, all the meaning imparted to `FP_REGNUM' is imparted
|
196 |
|
|
by the machine-dependent code. So, `FP_REGNUM' can have any value that
|
197 |
|
|
is convenient for the code that creates new frames.
|
198 |
|
|
(`create_new_frame' calls `INIT_EXTRA_FRAME_INFO' if it is defined;
|
199 |
|
|
that is where you should use the `FP_REGNUM' value, if your frames are
|
200 |
|
|
nonstandard.)
|
201 |
|
|
|
202 |
|
|
Given a GDB frame, define `FRAME_CHAIN' to determine the address of
|
203 |
|
|
the calling function's frame. This will be used to create a new GDB
|
204 |
|
|
frame struct, and then `INIT_EXTRA_FRAME_INFO' and `INIT_FRAME_PC' will
|
205 |
|
|
be called for the new frame.
|
206 |
|
|
|
207 |
|
|
Breakpoint Handling
|
208 |
|
|
===================
|
209 |
|
|
|
210 |
|
|
In general, a breakpoint is a user-designated location in the program
|
211 |
|
|
where the user wants to regain control if program execution ever reaches
|
212 |
|
|
that location.
|
213 |
|
|
|
214 |
|
|
There are two main ways to implement breakpoints; either as
|
215 |
|
|
"hardware" breakpoints or as "software" breakpoints.
|
216 |
|
|
|
217 |
|
|
Hardware breakpoints are sometimes available as a builtin debugging
|
218 |
|
|
features with some chips. Typically these work by having dedicated
|
219 |
|
|
register into which the breakpoint address may be stored. If the PC
|
220 |
|
|
(shorthand for "program counter") ever matches a value in a breakpoint
|
221 |
|
|
registers, the CPU raises an exception and reports it to GDB.
|
222 |
|
|
|
223 |
|
|
Another possibility is when an emulator is in use; many emulators
|
224 |
|
|
include circuitry that watches the address lines coming out from the
|
225 |
|
|
processor, and force it to stop if the address matches a breakpoint's
|
226 |
|
|
address.
|
227 |
|
|
|
228 |
|
|
A third possibility is that the target already has the ability to do
|
229 |
|
|
breakpoints somehow; for instance, a ROM monitor may do its own
|
230 |
|
|
software breakpoints. So although these are not literally "hardware
|
231 |
|
|
breakpoints", from GDB's point of view they work the same; GDB need not
|
232 |
|
|
do nothing more than set the breakpoint and wait for something to
|
233 |
|
|
happen.
|
234 |
|
|
|
235 |
|
|
Since they depend on hardware resources, hardware breakpoints may be
|
236 |
|
|
limited in number; when the user asks for more, GDB will start trying
|
237 |
|
|
to set software breakpoints. (On some architectures, notably the
|
238 |
|
|
32-bit x86 platforms, GDB cannot alsways know whether there's enough
|
239 |
|
|
hardware resources to insert all the hardware breakpoints and
|
240 |
|
|
watchpoints. On those platforms, GDB prints an error message only when
|
241 |
|
|
the program being debugged is continued.)
|
242 |
|
|
|
243 |
|
|
Software breakpoints require GDB to do somewhat more work. The
|
244 |
|
|
basic theory is that GDB will replace a program instruction with a
|
245 |
|
|
trap, illegal divide, or some other instruction that will cause an
|
246 |
|
|
exception, and then when it's encountered, GDB will take the exception
|
247 |
|
|
and stop the program. When the user says to continue, GDB will restore
|
248 |
|
|
the original instruction, single-step, re-insert the trap, and continue
|
249 |
|
|
on.
|
250 |
|
|
|
251 |
|
|
Since it literally overwrites the program being tested, the program
|
252 |
|
|
area must be writeable, so this technique won't work on programs in
|
253 |
|
|
ROM. It can also distort the behavior of programs that examine
|
254 |
|
|
themselves, although such a situation would be highly unusual.
|
255 |
|
|
|
256 |
|
|
Also, the software breakpoint instruction should be the smallest
|
257 |
|
|
size of instruction, so it doesn't overwrite an instruction that might
|
258 |
|
|
be a jump target, and cause disaster when the program jumps into the
|
259 |
|
|
middle of the breakpoint instruction. (Strictly speaking, the
|
260 |
|
|
breakpoint must be no larger than the smallest interval between
|
261 |
|
|
instructions that may be jump targets; perhaps there is an architecture
|
262 |
|
|
where only even-numbered instructions may jumped to.) Note that it's
|
263 |
|
|
possible for an instruction set not to have any instructions usable for
|
264 |
|
|
a software breakpoint, although in practice only the ARC has failed to
|
265 |
|
|
define such an instruction.
|
266 |
|
|
|
267 |
|
|
The basic definition of the software breakpoint is the macro
|
268 |
|
|
`BREAKPOINT'.
|
269 |
|
|
|
270 |
|
|
Basic breakpoint object handling is in `breakpoint.c'. However,
|
271 |
|
|
much of the interesting breakpoint action is in `infrun.c'.
|
272 |
|
|
|
273 |
|
|
Single Stepping
|
274 |
|
|
===============
|
275 |
|
|
|
276 |
|
|
Signal Handling
|
277 |
|
|
===============
|
278 |
|
|
|
279 |
|
|
Thread Handling
|
280 |
|
|
===============
|
281 |
|
|
|
282 |
|
|
Inferior Function Calls
|
283 |
|
|
=======================
|
284 |
|
|
|
285 |
|
|
Longjmp Support
|
286 |
|
|
===============
|
287 |
|
|
|
288 |
|
|
GDB has support for figuring out that the target is doing a
|
289 |
|
|
`longjmp' and for stopping at the target of the jump, if we are
|
290 |
|
|
stepping. This is done with a few specialized internal breakpoints,
|
291 |
|
|
which are visible in the output of the `maint info breakpoint' command.
|
292 |
|
|
|
293 |
|
|
To make this work, you need to define a macro called
|
294 |
|
|
`GET_LONGJMP_TARGET', which will examine the `jmp_buf' structure and
|
295 |
|
|
extract the longjmp target address. Since `jmp_buf' is target
|
296 |
|
|
specific, you will need to define it in the appropriate `tm-TARGET.h'
|
297 |
|
|
file. Look in `tm-sun4os4.h' and `sparc-tdep.c' for examples of how to
|
298 |
|
|
do this.
|
299 |
|
|
|
300 |
|
|
Watchpoints
|
301 |
|
|
===========
|
302 |
|
|
|
303 |
|
|
Watchpoints are a special kind of breakpoints (*note breakpoints:
|
304 |
|
|
Algorithms.) which break when data is accessed rather than when some
|
305 |
|
|
instruction is executed. When you have data which changes without your
|
306 |
|
|
knowing what code does that, watchpoints are the silver bullet to hunt
|
307 |
|
|
down and kill such bugs.
|
308 |
|
|
|
309 |
|
|
Watchpoints can be either hardware-assisted or not; the latter type
|
310 |
|
|
is known as "software watchpoints." GDB always uses hardware-assisted
|
311 |
|
|
watchpoints if they are available, and falls back on software
|
312 |
|
|
watchpoints otherwise. Typical situations where GDB will use software
|
313 |
|
|
watchpoints are:
|
314 |
|
|
|
315 |
|
|
* The watched memory region is too large for the underlying hardware
|
316 |
|
|
watchpoint support. For example, each x86 debug register can
|
317 |
|
|
watch up to 4 bytes of memory, so trying to watch data structures
|
318 |
|
|
whose size is more than 16 bytes will cause GDB to use software
|
319 |
|
|
watchpoints.
|
320 |
|
|
|
321 |
|
|
* The value of the expression to be watched depends on data held in
|
322 |
|
|
registers (as opposed to memory).
|
323 |
|
|
|
324 |
|
|
* Too many different watchpoints requested. (On some architectures,
|
325 |
|
|
this situation is impossible to detect until the debugged program
|
326 |
|
|
is resumed.) Note that x86 debug registers are used both for
|
327 |
|
|
hardware breakpoints and for watchpoints, so setting too many
|
328 |
|
|
hardware breakpoints might cause watchpoint insertion to fail.
|
329 |
|
|
|
330 |
|
|
* No hardware-assisted watchpoints provided by the target
|
331 |
|
|
implementation.
|
332 |
|
|
|
333 |
|
|
Software watchpoints are very slow, since GDB needs to single-step
|
334 |
|
|
the program being debugged and test the value of the watched
|
335 |
|
|
expression(s) after each instruction. The rest of this section is
|
336 |
|
|
mostly irrelevant for software watchpoints.
|
337 |
|
|
|
338 |
|
|
GDB uses several macros and primitives to support hardware
|
339 |
|
|
watchpoints:
|
340 |
|
|
|
341 |
|
|
`TARGET_HAS_HARDWARE_WATCHPOINTS'
|
342 |
|
|
If defined, the target supports hardware watchpoints.
|
343 |
|
|
|
344 |
|
|
`TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE, COUNT, OTHER)'
|
345 |
|
|
Return the number of hardware watchpoints of type TYPE that are
|
346 |
|
|
possible to be set. The value is positive if COUNT watchpoints of
|
347 |
|
|
this type can be set, zero if setting watchpoints of this type is
|
348 |
|
|
not supported, and negative if COUNT is more than the maximum
|
349 |
|
|
number of watchpoints of type TYPE that can be set. OTHER is
|
350 |
|
|
non-zero if other types of watchpoints are currently enabled (there
|
351 |
|
|
are architectures which cannot set watchpoints of different types
|
352 |
|
|
at the same time).
|
353 |
|
|
|
354 |
|
|
`TARGET_REGION_OK_FOR_HW_WATCHPOINT (ADDR, LEN)'
|
355 |
|
|
Return non-zero if hardware watchpoints can be used to watch a
|
356 |
|
|
region whose address is ADDR and whose length in bytes is LEN.
|
357 |
|
|
|
358 |
|
|
`TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (SIZE)'
|
359 |
|
|
Return non-zero if hardware watchpoints can be used to watch a
|
360 |
|
|
region whose size is SIZE. GDB only uses this macro as a
|
361 |
|
|
fall-back, in case `TARGET_REGION_OK_FOR_HW_WATCHPOINT' is not
|
362 |
|
|
defined.
|
363 |
|
|
|
364 |
|
|
`TARGET_DISABLE_HW_WATCHPOINTS (PID)'
|
365 |
|
|
Disables watchpoints in the process identified by PID. This is
|
366 |
|
|
used, e.g., on HP-UX which provides operations to disable and
|
367 |
|
|
enable the page-level memory protection that implements hardware
|
368 |
|
|
watchpoints on that platform.
|
369 |
|
|
|
370 |
|
|
`TARGET_ENABLE_HW_WATCHPOINTS (PID)'
|
371 |
|
|
Enables watchpoints in the process identified by PID. This is
|
372 |
|
|
used, e.g., on HP-UX which provides operations to disable and
|
373 |
|
|
enable the page-level memory protection that implements hardware
|
374 |
|
|
watchpoints on that platform.
|
375 |
|
|
|
376 |
|
|
`TARGET_RANGE_PROFITABLE_FOR_HW_WATCHPOINT (PID,START,LEN)'
|
377 |
|
|
Some addresses may not be profitable to use hardware to watch, or
|
378 |
|
|
may be difficult to understand when the addressed object is out of
|
379 |
|
|
scope, and hence should not be watched with hardware watchpoints.
|
380 |
|
|
On some targets, this may have severe performance penalties, such
|
381 |
|
|
that we might as well use regular watchpoints, and save (possibly
|
382 |
|
|
precious) hardware watchpoints for other locations.
|
383 |
|
|
|
384 |
|
|
`target_insert_watchpoint (ADDR, LEN, TYPE)'
|
385 |
|
|
`target_remove_watchpoint (ADDR, LEN, TYPE)'
|
386 |
|
|
Insert or remove a hardware watchpoint starting at ADDR, for LEN
|
387 |
|
|
bytes. TYPE is the watchpoint type, one of the possible values of
|
388 |
|
|
the enumerated data type `target_hw_bp_type', defined by
|
389 |
|
|
`breakpoint.h' as follows:
|
390 |
|
|
|
391 |
|
|
enum target_hw_bp_type
|
392 |
|
|
{
|
393 |
|
|
hw_write = 0, /* Common (write) HW watchpoint */
|
394 |
|
|
hw_read = 1, /* Read HW watchpoint */
|
395 |
|
|
hw_access = 2, /* Access (read or write) HW watchpoint */
|
396 |
|
|
hw_execute = 3 /* Execute HW breakpoint */
|
397 |
|
|
};
|
398 |
|
|
|
399 |
|
|
These two macros should return 0 for success, non-zero for failure.
|
400 |
|
|
|
401 |
|
|
`target_remove_hw_breakpoint (ADDR, SHADOW)'
|
402 |
|
|
`target_insert_hw_breakpoint (ADDR, SHADOW)'
|
403 |
|
|
Insert or remove a hardware-assisted breakpoint at address ADDR.
|
404 |
|
|
Returns zero for success, non-zero for failure. SHADOW is the
|
405 |
|
|
real contents of the byte where the breakpoint has been inserted;
|
406 |
|
|
it is generally not valid when hardware breakpoints are used, but
|
407 |
|
|
since no other code touches these values, the implementations of
|
408 |
|
|
the above two macros can use them for their internal purposes.
|
409 |
|
|
|
410 |
|
|
`target_stopped_data_address ()'
|
411 |
|
|
If the inferior has some watchpoint that triggered, return the
|
412 |
|
|
address associated with that watchpoint. Otherwise, return zero.
|
413 |
|
|
|
414 |
|
|
`DECR_PC_AFTER_HW_BREAK'
|
415 |
|
|
If defined, GDB decrements the program counter by the value of
|
416 |
|
|
`DECR_PC_AFTER_HW_BREAK' after a hardware break-point. This
|
417 |
|
|
overrides the value of `DECR_PC_AFTER_BREAK' when a breakpoint
|
418 |
|
|
that breaks is a hardware-assisted breakpoint.
|
419 |
|
|
|
420 |
|
|
`HAVE_STEPPABLE_WATCHPOINT'
|
421 |
|
|
If defined to a non-zero value, it is not necessary to disable a
|
422 |
|
|
watchpoint to step over it.
|
423 |
|
|
|
424 |
|
|
`HAVE_NONSTEPPABLE_WATCHPOINT'
|
425 |
|
|
If defined to a non-zero value, GDB should disable a watchpoint to
|
426 |
|
|
step the inferior over it.
|
427 |
|
|
|
428 |
|
|
`HAVE_CONTINUABLE_WATCHPOINT'
|
429 |
|
|
If defined to a non-zero value, it is possible to continue the
|
430 |
|
|
inferior after a watchpoint has been hit.
|
431 |
|
|
|
432 |
|
|
`CANNOT_STEP_HW_WATCHPOINTS'
|
433 |
|
|
If this is defined to a non-zero value, GDB will remove all
|
434 |
|
|
watchpoints before stepping the inferior.
|
435 |
|
|
|
436 |
|
|
`STOPPED_BY_WATCHPOINT (WAIT_STATUS)'
|
437 |
|
|
Return non-zero if stopped by a watchpoint. WAIT_STATUS is of the
|
438 |
|
|
type `struct target_waitstatus', defined by `target.h'.
|
439 |
|
|
|
440 |
|
|
x86 Watchpoints
|
441 |
|
|
---------------
|
442 |
|
|
|
443 |
|
|
The 32-bit Intel x86 (a.k.a. ia32) processors feature special debug
|
444 |
|
|
registers designed to facilitate debugging. GDB provides a generic
|
445 |
|
|
library of functions that x86-based ports can use to implement support
|
446 |
|
|
for watchpoints and hardware-assisted breakpoints. This subsection
|
447 |
|
|
documents the x86 watchpoint facilities in GDB.
|
448 |
|
|
|
449 |
|
|
To use the generic x86 watchpoint support, a port should do the
|
450 |
|
|
following:
|
451 |
|
|
|
452 |
|
|
* Define the macro `I386_USE_GENERIC_WATCHPOINTS' somewhere in the
|
453 |
|
|
target-dependent headers.
|
454 |
|
|
|
455 |
|
|
* Include the `config/i386/nm-i386.h' header file _after_ defining
|
456 |
|
|
`I386_USE_GENERIC_WATCHPOINTS'.
|
457 |
|
|
|
458 |
|
|
* Add `i386-nat.o' to the value of the Make variable `NATDEPFILES'
|
459 |
|
|
(*note NATDEPFILES: Native Debugging.) or `TDEPFILES' (*note
|
460 |
|
|
TDEPFILES: Target Architecture Definition.).
|
461 |
|
|
|
462 |
|
|
* Provide implementations for the `I386_DR_LOW_*' macros described
|
463 |
|
|
below. Typically, each macro should call a target-specific
|
464 |
|
|
function which does the real work.
|
465 |
|
|
|
466 |
|
|
The x86 watchpoint support works by maintaining mirror images of the
|
467 |
|
|
debug registers. Values are copied between the mirror images and the
|
468 |
|
|
real debug registers via a set of macros which each target needs to
|
469 |
|
|
provide:
|
470 |
|
|
|
471 |
|
|
`I386_DR_LOW_SET_CONTROL (VAL)'
|
472 |
|
|
Set the Debug Control (DR7) register to the value VAL.
|
473 |
|
|
|
474 |
|
|
`I386_DR_LOW_SET_ADDR (IDX, ADDR)'
|
475 |
|
|
Put the address ADDR into the debug register number IDX.
|
476 |
|
|
|
477 |
|
|
`I386_DR_LOW_RESET_ADDR (IDX)'
|
478 |
|
|
Reset (i.e. zero out) the address stored in the debug register
|
479 |
|
|
number IDX.
|
480 |
|
|
|
481 |
|
|
`I386_DR_LOW_GET_STATUS'
|
482 |
|
|
Return the value of the Debug Status (DR6) register. This value is
|
483 |
|
|
used immediately after it is returned by `I386_DR_LOW_GET_STATUS',
|
484 |
|
|
so as to support per-thread status register values.
|
485 |
|
|
|
486 |
|
|
For each one of the 4 debug registers (whose indices are from 0 to 3)
|
487 |
|
|
that store addresses, a reference count is maintained by GDB, to allow
|
488 |
|
|
sharing of debug registers by several watchpoints. This allows users
|
489 |
|
|
to define several watchpoints that watch the same expression, but with
|
490 |
|
|
different conditions and/or commands, without wasting debug registers
|
491 |
|
|
which are in short supply. GDB maintains the reference counts
|
492 |
|
|
internally, targets don't have to do anything to use this feature.
|
493 |
|
|
|
494 |
|
|
The x86 debug registers can each watch a region that is 1, 2, or 4
|
495 |
|
|
bytes long. The ia32 architecture requires that each watched region be
|
496 |
|
|
appropriately aligned: 2-byte region on 2-byte boundary, 4-byte region
|
497 |
|
|
on 4-byte boundary. However, the x86 watchpoint support in GDB can
|
498 |
|
|
watch unaligned regions and regions larger than 4 bytes (up to 16
|
499 |
|
|
bytes) by allocating several debug registers to watch a single region.
|
500 |
|
|
This allocation of several registers per a watched region is also done
|
501 |
|
|
automatically without target code intervention.
|
502 |
|
|
|
503 |
|
|
The generic x86 watchpoint support provides the following API for the
|
504 |
|
|
GDB's application code:
|
505 |
|
|
|
506 |
|
|
`i386_region_ok_for_watchpoint (ADDR, LEN)'
|
507 |
|
|
The macro `TARGET_REGION_OK_FOR_HW_WATCHPOINT' is set to call this
|
508 |
|
|
function. It counts the number of debug registers required to
|
509 |
|
|
watch a given region, and returns a non-zero value if that number
|
510 |
|
|
is less than 4, the number of debug registers available to x86
|
511 |
|
|
processors.
|
512 |
|
|
|
513 |
|
|
`i386_stopped_data_address (void)'
|
514 |
|
|
The macros `STOPPED_BY_WATCHPOINT' and
|
515 |
|
|
`target_stopped_data_address' are set to call this function. The
|
516 |
|
|
argument passed to `STOPPED_BY_WATCHPOINT' is ignored. This
|
517 |
|
|
function examines the breakpoint condition bits in the DR6 Debug
|
518 |
|
|
Status register, as returned by the `I386_DR_LOW_GET_STATUS'
|
519 |
|
|
macro, and returns the address associated with the first bit that
|
520 |
|
|
is set in DR6.
|
521 |
|
|
|
522 |
|
|
`i386_insert_watchpoint (ADDR, LEN, TYPE)'
|
523 |
|
|
`i386_remove_watchpoint (ADDR, LEN, TYPE)'
|
524 |
|
|
Insert or remove a watchpoint. The macros
|
525 |
|
|
`target_insert_watchpoint' and `target_remove_watchpoint' are set
|
526 |
|
|
to call these functions. `i386_insert_watchpoint' first looks for
|
527 |
|
|
a debug register which is already set to watch the same region for
|
528 |
|
|
the same access types; if found, it just increments the reference
|
529 |
|
|
count of that debug register, thus implementing debug register
|
530 |
|
|
sharing between watchpoints. If no such register is found, the
|
531 |
|
|
function looks for a vacant debug register, sets its mirrorred
|
532 |
|
|
value to ADDR, sets the mirrorred value of DR7 Debug Control
|
533 |
|
|
register as appropriate for the LEN and TYPE parameters, and then
|
534 |
|
|
passes the new values of the debug register and DR7 to the
|
535 |
|
|
inferior by calling `I386_DR_LOW_SET_ADDR' and
|
536 |
|
|
`I386_DR_LOW_SET_CONTROL'. If more than one debug register is
|
537 |
|
|
required to cover the given region, the above process is repeated
|
538 |
|
|
for each debug register.
|
539 |
|
|
|
540 |
|
|
`i386_remove_watchpoint' does the opposite: it resets the address
|
541 |
|
|
in the mirrorred value of the debug register and its read/write and
|
542 |
|
|
length bits in the mirrorred value of DR7, then passes these new
|
543 |
|
|
values to the inferior via `I386_DR_LOW_RESET_ADDR' and
|
544 |
|
|
`I386_DR_LOW_SET_CONTROL'. If a register is shared by several
|
545 |
|
|
watchpoints, each time a `i386_remove_watchpoint' is called, it
|
546 |
|
|
decrements the reference count, and only calls
|
547 |
|
|
`I386_DR_LOW_RESET_ADDR' and `I386_DR_LOW_SET_CONTROL' when the
|
548 |
|
|
count goes to zero.
|
549 |
|
|
|
550 |
|
|
`i386_insert_hw_breakpoint (ADDR, SHADOW'
|
551 |
|
|
`i386_remove_hw_breakpoint (ADDR, SHADOW)'
|
552 |
|
|
These functions insert and remove hardware-assisted breakpoints.
|
553 |
|
|
The macros `target_insert_hw_breakpoint' and
|
554 |
|
|
`target_remove_hw_breakpoint' are set to call these functions.
|
555 |
|
|
These functions work like `i386_insert_watchpoint' and
|
556 |
|
|
`i386_remove_watchpoint', respectively, except that they set up
|
557 |
|
|
the debug registers to watch instruction execution, and each
|
558 |
|
|
hardware-assisted breakpoint always requires exactly one debug
|
559 |
|
|
register.
|
560 |
|
|
|
561 |
|
|
`i386_stopped_by_hwbp (void)'
|
562 |
|
|
This function returns non-zero if the inferior has some watchpoint
|
563 |
|
|
or hardware breakpoint that triggered. It works like
|
564 |
|
|
`i386_stopped_data_address', except that it doesn't return the
|
565 |
|
|
address whose watchpoint triggered.
|
566 |
|
|
|
567 |
|
|
`i386_cleanup_dregs (void)'
|
568 |
|
|
This function clears all the reference counts, addresses, and
|
569 |
|
|
control bits in the mirror images of the debug registers. It
|
570 |
|
|
doesn't affect the actual debug registers in the inferior process.
|
571 |
|
|
|
572 |
|
|
*Notes:*
|
573 |
|
|
1. x86 processors support setting watchpoints on I/O reads or writes.
|
574 |
|
|
However, since no target supports this (as of March 2001), and
|
575 |
|
|
since `enum target_hw_bp_type' doesn't even have an enumeration
|
576 |
|
|
for I/O watchpoints, this feature is not yet available to GDB
|
577 |
|
|
running on x86.
|
578 |
|
|
|
579 |
|
|
2. x86 processors can enable watchpoints locally, for the current task
|
580 |
|
|
only, or globally, for all the tasks. For each debug register,
|
581 |
|
|
there's a bit in the DR7 Debug Control register that determines
|
582 |
|
|
whether the associated address is watched locally or globally. The
|
583 |
|
|
current implementation of x86 watchpoint support in GDB always
|
584 |
|
|
sets watchpoints to be locally enabled, since global watchpoints
|
585 |
|
|
might interfere with the underlying OS and are probably
|
586 |
|
|
unavailable in many platforms.
|
587 |
|
|
|
588 |
|
|
|
589 |
|
|
File: gdbint.info, Node: User Interface, Next: Symbol Handling, Prev: Algorithms, Up: Top
|
590 |
|
|
|
591 |
|
|
User Interface
|
592 |
|
|
**************
|
593 |
|
|
|
594 |
|
|
GDB has several user interfaces. Although the command-line interface
|
595 |
|
|
is the most common and most familiar, there are others.
|
596 |
|
|
|
597 |
|
|
Command Interpreter
|
598 |
|
|
===================
|
599 |
|
|
|
600 |
|
|
The command interpreter in GDB is fairly simple. It is designed to
|
601 |
|
|
allow for the set of commands to be augmented dynamically, and also has
|
602 |
|
|
a recursive subcommand capability, where the first argument to a
|
603 |
|
|
command may itself direct a lookup on a different command list.
|
604 |
|
|
|
605 |
|
|
For instance, the `set' command just starts a lookup on the
|
606 |
|
|
`setlist' command list, while `set thread' recurses to the
|
607 |
|
|
`set_thread_cmd_list'.
|
608 |
|
|
|
609 |
|
|
To add commands in general, use `add_cmd'. `add_com' adds to the
|
610 |
|
|
main command list, and should be used for those commands. The usual
|
611 |
|
|
place to add commands is in the `_initialize_XYZ' routines at the ends
|
612 |
|
|
of most source files.
|
613 |
|
|
|
614 |
|
|
Before removing commands from the command set it is a good idea to
|
615 |
|
|
deprecate them for some time. Use `deprecate_cmd' on commands or
|
616 |
|
|
aliases to set the deprecated flag. `deprecate_cmd' takes a `struct
|
617 |
|
|
cmd_list_element' as it's first argument. You can use the return value
|
618 |
|
|
from `add_com' or `add_cmd' to deprecate the command immediately after
|
619 |
|
|
it is created.
|
620 |
|
|
|
621 |
|
|
The first time a comamnd is used the user will be warned and offered
|
622 |
|
|
a replacement (if one exists). Note that the replacement string passed
|
623 |
|
|
to `deprecate_cmd' should be the full name of the command, i.e. the
|
624 |
|
|
entire string the user should type at the command line.
|
625 |
|
|
|
626 |
|
|
UI-Independent Output--the `ui_out' Functions
|
627 |
|
|
=============================================
|
628 |
|
|
|
629 |
|
|
The `ui_out' functions present an abstraction level for the GDB
|
630 |
|
|
output code. They hide the specifics of different user interfaces
|
631 |
|
|
supported by GDB, and thus free the programmer from the need to write
|
632 |
|
|
several versions of the same code, one each for every UI, to produce
|
633 |
|
|
output.
|
634 |
|
|
|
635 |
|
|
Overview and Terminology
|
636 |
|
|
------------------------
|
637 |
|
|
|
638 |
|
|
In general, execution of each GDB command produces some sort of
|
639 |
|
|
output, and can even generate an input request.
|
640 |
|
|
|
641 |
|
|
Output can be generated for the following purposes:
|
642 |
|
|
|
643 |
|
|
* to display a _result_ of an operation;
|
644 |
|
|
|
645 |
|
|
* to convey _info_ or produce side-effects of a requested operation;
|
646 |
|
|
|
647 |
|
|
* to provide a _notification_ of an asynchronous event (including
|
648 |
|
|
progress indication of a prolonged asynchronous operation);
|
649 |
|
|
|
650 |
|
|
* to display _error messages_ (including warnings);
|
651 |
|
|
|
652 |
|
|
* to show _debug data_;
|
653 |
|
|
|
654 |
|
|
* to _query_ or prompt a user for input (a special case).
|
655 |
|
|
|
656 |
|
|
This section mainly concentrates on how to build result output,
|
657 |
|
|
although some of it also applies to other kinds of output.
|
658 |
|
|
|
659 |
|
|
Generation of output that displays the results of an operation
|
660 |
|
|
involves one or more of the following:
|
661 |
|
|
|
662 |
|
|
* output of the actual data
|
663 |
|
|
|
664 |
|
|
* formatting the output as appropriate for console output, to make it
|
665 |
|
|
easily readable by humans
|
666 |
|
|
|
667 |
|
|
* machine oriented formatting-a more terse formatting to allow for
|
668 |
|
|
easy parsing by programs which read GDB's output
|
669 |
|
|
|
670 |
|
|
* annotation, whose purpose is to help a GUI (such as GDBTK or
|
671 |
|
|
Emacs) to identify interesting parts in the output
|
672 |
|
|
|
673 |
|
|
The `ui_out' routines take care of the first three aspects.
|
674 |
|
|
Annotations are provided by separate annotation routines. Note that
|
675 |
|
|
use of annotations for an interface between a GUI and GDB is deprecated.
|
676 |
|
|
|
677 |
|
|
Output can be in the form of a single item, which we call a "field";
|
678 |
|
|
a "list" of fields; or a "table", which is a list of fields with a
|
679 |
|
|
header. In a BNF-like form:
|
680 |
|
|
|
681 |
|
|
::= any single item of data kept by gdb ;;
|
682 |
|
|
|
683 |
|
|
::= { } ;;
|
684 |
|
|
|
685 |
|
|
::= { } ;;
686 |
|
|
|
687 |
|
|
|
688 |
|
|
|
689 |
|
|
::= ;;
|
690 |
|
|
|
691 |
|
|
General Conventions
|
692 |
|
|
-------------------
|
693 |
|
|
|
694 |
|
|
All `ui_out' routines currently are of type `void', except for
|
695 |
|
|
`ui_out_stream_new' which returns a pointer to the newly created object.
|
696 |
|
|
|
697 |
|
|
The first parameter is always the `ui_out' vector object, a pointer
|
698 |
|
|
to a `struct ui_out'.
|
699 |
|
|
|
700 |
|
|
The FORMAT parameter is like in `printf' family of functions. When
|
701 |
|
|
it is present, there is usually also a variable list of arguments used
|
702 |
|
|
to satisfy the `%' specifiers in the supplied format.
|
703 |
|
|
|
704 |
|
|
When a character string argument is not used in a `ui_out' function
|
705 |
|
|
call, a `NULL' pointer has to be supplied instead.
|
706 |
|
|
|
707 |
|
|
Table and List Functions
|
708 |
|
|
------------------------
|
709 |
|
|
|
710 |
|
|
This section introduces `ui_out' routines for building lists and
|
711 |
|
|
tables. The routines to output the actual data items (fields) are
|
712 |
|
|
presented in the next section.
|
713 |
|
|
|
714 |
|
|
To recap: A "list" is a sequence of "fields" with information about
|
715 |
|
|
an object; a "table" is a list of lists, each on a separate line,
|
716 |
|
|
prefixed by a "header" line with the column "titles".
|
717 |
|
|
|
718 |
|
|
Use the table functions if your output is composed of a list of
|
719 |
|
|
fields for several objects and the console output should have a header.
|
720 |
|
|
Use this even when you are listing just one object but you still want
|
721 |
|
|
the header.
|
722 |
|
|
|
723 |
|
|
Use the list functions for the output of each object of a table or if
|
724 |
|
|
your output consists of a single list of fields.
|
725 |
|
|
|
726 |
|
|
You can nest a list into a table, but not the other way around.
|
727 |
|
|
|
728 |
|
|
Lists can also be nested: some of your fields may be lists or
|
729 |
|
|
"tuples"-`{NAME,VALUE}' pairs. The maximum nesting level is currently
|
730 |
|
|
4.
|
731 |
|
|
|
732 |
|
|
The overall structure of the table output code is something like
|
733 |
|
|
this:
|
734 |
|
|
|
735 |
|
|
ui_out_table_begin
|
736 |
|
|
ui_out_table_header
|
737 |
|
|
...
|
738 |
|
|
ui_out_table_body
|
739 |
|
|
ui_out_list_begin
|
740 |
|
|
ui_out_field_*
|
741 |
|
|
...
|
742 |
|
|
ui_out_list_end
|
743 |
|
|
...
|
744 |
|
|
ui_out_table_end
|
745 |
|
|
|
746 |
|
|
Here's the description of table- and list-related `ui_out' functions:
|
747 |
|
|
|
748 |
|
|
- Function: void ui_out_table_begin (struct ui_out *UIOUT, int
|
749 |
|
|
NBROFCOLS, char *TBLID)
|
750 |
|
|
The function `ui_out_table_begin' marks the beginning of the
|
751 |
|
|
output of a table. It should always be called before any other
|
752 |
|
|
`ui_out' function for a given table. NBROFCOLS is the number of
|
753 |
|
|
columns in the table, and TBLID is an optional string identifying
|
754 |
|
|
the table. The string pointed to by TBLID is copied by the
|
755 |
|
|
implementation of `ui_out_table_begin', so the application can
|
756 |
|
|
free the string if it was `malloc'ed.
|
757 |
|
|
|
758 |
|
|
The companion function `ui_out_table_end', described below, marks
|
759 |
|
|
the end of the table's output.
|
760 |
|
|
|
761 |
|
|
- Function: void ui_out_table_header (struct ui_out *UIOUT, int WIDTH,
|
762 |
|
|
enum ui_align ALIGNMENT, char *COLHDR)
|
763 |
|
|
`ui_out_table_header' provides the header information for a single
|
764 |
|
|
table column. You call this function several times, one each for
|
765 |
|
|
every column of the table, after `ui_out_table_begin', but before
|
766 |
|
|
`ui_out_table_body'.
|
767 |
|
|
|
768 |
|
|
The value of WIDTH gives the column width in characters. The
|
769 |
|
|
value of ALIGNMENT is one of `left', `center', and `right', and it
|
770 |
|
|
specifies how to align the header: left-justify, center, or
|
771 |
|
|
right-justify it. COLHDR points to a string that specifies the
|
772 |
|
|
column header; the implementation copies that string, so column
|
773 |
|
|
header strings in `malloc'ed storage can be freed after the call.
|
774 |
|
|
|
775 |
|
|
- Function: void ui_out_table_body (struct ui_out *UIOUT)
|
776 |
|
|
This function marks the end of header information and the
|
777 |
|
|
beginning of table body output. It doesn't by itself produce any
|
778 |
|
|
data output; that is done by the list and field output functions
|
779 |
|
|
described below.
|
780 |
|
|
|
781 |
|
|
- Function: void ui_out_table_end (struct ui_out *UIOUT)
|
782 |
|
|
This function signals the end of a table's output. It should be
|
783 |
|
|
called after the table body has been produced by the list and field
|
784 |
|
|
output functions.
|
785 |
|
|
|
786 |
|
|
There should be exactly one call to `ui_out_table_end' for each
|
787 |
|
|
call to `ui_out_table_begin', otherwise the `ui_out' functions
|
788 |
|
|
will signal an internal error.
|
789 |
|
|
|
790 |
|
|
The output of the lists that represent the table rows must follow the
|
791 |
|
|
call to `ui_out_table_body' and precede the call to `ui_out_table_end'.
|
792 |
|
|
You produce the lists by calling `ui_out_list_begin' and
|
793 |
|
|
`ui_out_list_end', with suitable calls to functions which actually
|
794 |
|
|
output fields between them.
|
795 |
|
|
|
796 |
|
|
- Function: void ui_out_list_begin (struct ui_out *UIOUT, char *LSTID)
|
797 |
|
|
This function marks the beginning or a list output. LSTID points
|
798 |
|
|
to an optional string that identifies the list; it is copied by
|
799 |
|
|
the implementation, and so strings in `malloc'ed storage can be
|
800 |
|
|
freed after the call.
|
801 |
|
|
|
802 |
|
|
- Function: void ui_out_list_end (struct ui_out *UIOUT)
|
803 |
|
|
This function signals an end of a list output. There should be
|
804 |
|
|
exactly one call to `ui_out_list_end' for each call to
|
805 |
|
|
`ui_out_list_begin', otherwise an internal GDB error will be
|
806 |
|
|
signaled.
|
807 |
|
|
|
808 |
|
|
Item Output Functions
|
809 |
|
|
---------------------
|
810 |
|
|
|
811 |
|
|
The functions described below produce output for the actual data
|
812 |
|
|
items, or fields, which contain information about the object.
|
813 |
|
|
|
814 |
|
|
Choose the appropriate function accordingly to your particular needs.
|
815 |
|
|
|
816 |
|
|
- Function: void ui_out_field_fmt (struct ui_out *UIOUT, char
|
817 |
|
|
*FLDNAME, char *FORMAT, ...)
|
818 |
|
|
This is the most general output function. It produces the
|
819 |
|
|
representation of the data in the variable-length argument list
|
820 |
|
|
according to formatting specifications in FORMAT, a `printf'-like
|
821 |
|
|
format string. The optional argument FLDNAME supplies the name of
|
822 |
|
|
the field. The data items themselves are supplied as additional
|
823 |
|
|
arguments after FORMAT.
|
824 |
|
|
|
825 |
|
|
This generic function should be used only when it is not possible
|
826 |
|
|
to use one of the specialized versions (see below).
|
827 |
|
|
|
828 |
|
|
- Function: void ui_out_field_int (struct ui_out *UIOUT, char
|
829 |
|
|
*FLDNAME, int VALUE)
|
830 |
|
|
This function outputs a value of an `int' variable. It uses the
|
831 |
|
|
`"%d"' output conversion specification. FLDNAME specifies the
|
832 |
|
|
name of the field.
|
833 |
|
|
|
834 |
|
|
- Function: void ui_out_field_core_addr (struct ui_out *UIOUT, char
|
835 |
|
|
*FLDNAME, CORE_ADDR ADDRESS)
|
836 |
|
|
This function outputs an address.
|
837 |
|
|
|
838 |
|
|
- Function: void ui_out_field_string (struct ui_out *UIOUT, char
|
839 |
|
|
*FLDNAME, const char *STRING)
|
840 |
|
|
This function outputs a string using the `"%s"' conversion
|
841 |
|
|
specification.
|
842 |
|
|
|
843 |
|
|
Sometimes, there's a need to compose your output piece by piece using
|
844 |
|
|
functions that operate on a stream, such as `value_print' or
|
845 |
|
|
`fprintf_symbol_filtered'. These functions accept an argument of the
|
846 |
|
|
type `struct ui_file *', a pointer to a `ui_file' object used to store
|
847 |
|
|
the data stream used for the output. When you use one of these
|
848 |
|
|
functions, you need a way to pass their results stored in a `ui_file'
|
849 |
|
|
object to the `ui_out' functions. To this end, you first create a
|
850 |
|
|
`ui_stream' object by calling `ui_out_stream_new', pass the `stream'
|
851 |
|
|
member of that `ui_stream' object to `value_print' and similar
|
852 |
|
|
functions, and finally call `ui_out_field_stream' to output the field
|
853 |
|
|
you constructed. When the `ui_stream' object is no longer needed, you
|
854 |
|
|
should destroy it and free its memory by calling `ui_out_stream_delete'.
|
855 |
|
|
|
856 |
|
|
- Function: struct ui_stream *ui_out_stream_new (struct ui_out *UIOUT)
|
857 |
|
|
This function creates a new `ui_stream' object which uses the same
|
858 |
|
|
output methods as the `ui_out' object whose pointer is passed in
|
859 |
|
|
UIOUT. It returns a pointer to the newly created `ui_stream'
|
860 |
|
|
object.
|
861 |
|
|
|
862 |
|
|
- Function: void ui_out_stream_delete (struct ui_stream *STREAMBUF)
|
863 |
|
|
This functions destroys a `ui_stream' object specified by
|
864 |
|
|
STREAMBUF.
|
865 |
|
|
|
866 |
|
|
- Function: void ui_out_field_stream (struct ui_out *UIOUT, char
|
867 |
|
|
*FIELDNAME, struct ui_stream *STREAMBUF)
|
868 |
|
|
This function consumes all the data accumulated in
|
869 |
|
|
`streambuf->stream' and outputs it like `ui_out_field_string'
|
870 |
|
|
does. After a call to `ui_out_field_stream', the accumulated data
|
871 |
|
|
no longer exists, but the stream is still valid and may be used
|
872 |
|
|
for producing more fields.
|
873 |
|
|
|
874 |
|
|
*Important:* If there is any chance that your code could bail out
|
875 |
|
|
before completing output generation and reaching the point where
|
876 |
|
|
`ui_out_stream_delete' is called, it is necessary to set up a cleanup,
|
877 |
|
|
to avoid leaking memory and other resources. Here's a skeleton code to
|
878 |
|
|
do that:
|
879 |
|
|
|
880 |
|
|
struct ui_stream *mybuf = ui_out_stream_new (uiout);
|
881 |
|
|
struct cleanup *old = make_cleanup (ui_out_stream_delete, mybuf);
|
882 |
|
|
...
|
883 |
|
|
do_cleanups (old);
|
884 |
|
|
|
885 |
|
|
If the function already has the old cleanup chain set (for other
|
886 |
|
|
kinds of cleanups), you just have to add your cleanup to it:
|
887 |
|
|
|
888 |
|
|
mybuf = ui_out_stream_new (uiout);
|
889 |
|
|
make_cleanup (ui_out_stream_delete, mybuf);
|
890 |
|
|
|
891 |
|
|
Note that with cleanups in place, you should not call
|
892 |
|
|
`ui_out_stream_delete' directly, or you would attempt to free the same
|
893 |
|
|
buffer twice.
|
894 |
|
|
|
895 |
|
|
Utility Output Functions
|
896 |
|
|
------------------------
|
897 |
|
|
|
898 |
|
|
- Function: void ui_out_field_skip (struct ui_out *UIOUT, char
|
899 |
|
|
*FLDNAME)
|
900 |
|
|
This function skips a field in a table. Use it if you have to
|
901 |
|
|
leave an empty field without disrupting the table alignment. The
|
902 |
|
|
argument FLDNAME specifies a name for the (missing) filed.
|
903 |
|
|
|
904 |
|
|
- Function: void ui_out_text (struct ui_out *UIOUT, char *STRING)
|
905 |
|
|
This function outputs the text in STRING in a way that makes it
|
906 |
|
|
easy to be read by humans. For example, the console
|
907 |
|
|
implementation of this method filters the text through a built-in
|
908 |
|
|
pager, to prevent it from scrolling off the visible portion of the
|
909 |
|
|
screen.
|
910 |
|
|
|
911 |
|
|
Use this function for printing relatively long chunks of text
|
912 |
|
|
around the actual field data: the text it produces is not aligned
|
913 |
|
|
according to the table's format. Use `ui_out_field_string' to
|
914 |
|
|
output a string field, and use `ui_out_message', described below,
|
915 |
|
|
to output short messages.
|
916 |
|
|
|
917 |
|
|
- Function: void ui_out_spaces (struct ui_out *UIOUT, int NSPACES)
|
918 |
|
|
This function outputs NSPACES spaces. It is handy to align the
|
919 |
|
|
text produced by `ui_out_text' with the rest of the table or list.
|
920 |
|
|
|
921 |
|
|
- Function: void ui_out_message (struct ui_out *UIOUT, int VERBOSITY,
|
922 |
|
|
char *FORMAT, ...)
|
923 |
|
|
This function produces a formatted message, provided that the
|
924 |
|
|
current verbosity level is at least as large as given by
|
925 |
|
|
VERBOSITY. The current verbosity level is specified by the user
|
926 |
|
|
with the `set verbositylevel' command.(1)
|
927 |
|
|
|
928 |
|
|
- Function: void ui_out_wrap_hint (struct ui_out *UIOUT, char *INDENT)
|
929 |
|
|
This function gives the console output filter (a paging filter) a
|
930 |
|
|
hint of where to break lines which are too long. Ignored for all
|
931 |
|
|
other output consumers. INDENT, if non-`NULL', is the string to
|
932 |
|
|
be printed to indent the wrapped text on the next line; it must
|
933 |
|
|
remain accessible until the next call to `ui_out_wrap_hint', or
|
934 |
|
|
until an explicit newline is produced by one of the other
|
935 |
|
|
functions. If INDENT is `NULL', the wrapped text will not be
|
936 |
|
|
indented.
|
937 |
|
|
|
938 |
|
|
- Function: void ui_out_flush (struct ui_out *UIOUT)
|
939 |
|
|
This function flushes whatever output has been accumulated so far,
|
940 |
|
|
if the UI buffers output.
|
941 |
|
|
|
942 |
|
|
Examples of Use of `ui_out' functions
|
943 |
|
|
-------------------------------------
|
944 |
|
|
|
945 |
|
|
This section gives some practical examples of using the `ui_out'
|
946 |
|
|
functions to generalize the old console-oriented code in GDB. The
|
947 |
|
|
examples all come from functions defined on the `breakpoints.c' file.
|
948 |
|
|
|
949 |
|
|
This example, from the `breakpoint_1' function, shows how to produce
|
950 |
|
|
a table.
|
951 |
|
|
|
952 |
|
|
The original code was:
|
953 |
|
|
|
954 |
|
|
if (!found_a_breakpoint++)
|
955 |
|
|
{
|
956 |
|
|
annotate_breakpoints_headers ();
|
957 |
|
|
|
958 |
|
|
annotate_field (0);
|
959 |
|
|
printf_filtered ("Num ");
|
960 |
|
|
annotate_field (1);
|
961 |
|
|
printf_filtered ("Type ");
|
962 |
|
|
annotate_field (2);
|
963 |
|
|
printf_filtered ("Disp ");
|
964 |
|
|
annotate_field (3);
|
965 |
|
|
printf_filtered ("Enb ");
|
966 |
|
|
if (addressprint)
|
967 |
|
|
{
|
968 |
|
|
annotate_field (4);
|
969 |
|
|
printf_filtered ("Address ");
|
970 |
|
|
}
|
971 |
|
|
annotate_field (5);
|
972 |
|
|
printf_filtered ("What\n");
|
973 |
|
|
|
974 |
|
|
annotate_breakpoints_table ();
|
975 |
|
|
}
|
976 |
|
|
|
977 |
|
|
Here's the new version:
|
978 |
|
|
|
979 |
|
|
if (!found_a_breakpoint++)
|
980 |
|
|
{
|
981 |
|
|
annotate_breakpoints_headers ();
|
982 |
|
|
if (addressprint)
|
983 |
|
|
ui_out_table_begin (ui, 6);
|
984 |
|
|
else
|
985 |
|
|
ui_out_table_begin (ui, 5);
|
986 |
|
|
|
987 |
|
|
annotate_field (0);
|
988 |
|
|
ui_out_table_header (ui, 4, left, "Num");
|
989 |
|
|
annotate_field (1);
|
990 |
|
|
ui_out_table_header (ui, 15, left, "Type");
|
991 |
|
|
annotate_field (2);
|
992 |
|
|
ui_out_table_header (ui, 5, left, "Disp");
|
993 |
|
|
annotate_field (3);
|
994 |
|
|
ui_out_table_header (ui, 4, left, "Enb");
|
995 |
|
|
if (addressprint)
|
996 |
|
|
{
|
997 |
|
|
annotate_field (4);
|
998 |
|
|
ui_out_table_header (ui, 11, left, "Address");
|
999 |
|
|
}
|
1000 |
|
|
annotate_field (5);
|
1001 |
|
|
ui_out_table_header (ui, 40, left, "What");
|
1002 |
|
|
|
1003 |
|
|
ui_out_table_body (ui);
|
1004 |
|
|
annotate_breakpoints_table ();
|
1005 |
|
|
}
|
1006 |
|
|
|
1007 |
|
|
This example, from the `print_one_breakpoint' function, shows how to
|
1008 |
|
|
produce the actual data for the table whose structure was defined in
|
1009 |
|
|
the above example. The original code was:
|
1010 |
|
|
|
1011 |
|
|
annotate_record ();
|
1012 |
|
|
annotate_field (0);
|
1013 |
|
|
printf_filtered ("%-3d ", b->number);
|
1014 |
|
|
annotate_field (1);
|
1015 |
|
|
if ((int)b->type > (sizeof(bptypes)/sizeof(bptypes[0]))
|
1016 |
|
|
|| ((int) b->type != bptypes[(int) b->type].type))
|
1017 |
|
|
internal_error ("bptypes table does not describe type #%d.",
|
1018 |
|
|
(int)b->type);
|
1019 |
|
|
printf_filtered ("%-14s ", bptypes[(int)b->type].description);
|
1020 |
|
|
annotate_field (2);
|
1021 |
|
|
printf_filtered ("%-4s ", bpdisps[(int)b->disposition]);
|
1022 |
|
|
annotate_field (3);
|
1023 |
|
|
printf_filtered ("%-3c ", bpenables[(int)b->enable]);
|
1024 |
|
|
|
1025 |
|
|
This is the new version:
|
1026 |
|
|
|
1027 |
|
|
annotate_record ();
|
1028 |
|
|
ui_out_list_begin (uiout, "bkpt");
|
1029 |
|
|
annotate_field (0);
|
1030 |
|
|
ui_out_field_int (uiout, "number", b->number);
|
1031 |
|
|
annotate_field (1);
|
1032 |
|
|
if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
|
1033 |
|
|
|| ((int) b->type != bptypes[(int) b->type].type))
|
1034 |
|
|
internal_error ("bptypes table does not describe type #%d.",
|
1035 |
|
|
(int) b->type);
|
1036 |
|
|
ui_out_field_string (uiout, "type", bptypes[(int)b->type].description);
|
1037 |
|
|
annotate_field (2);
|
1038 |
|
|
ui_out_field_string (uiout, "disp", bpdisps[(int)b->disposition]);
|
1039 |
|
|
annotate_field (3);
|
1040 |
|
|
ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int)b->enable]);
|
1041 |
|
|
|
1042 |
|
|
This example, also from `print_one_breakpoint', shows how to produce
|
1043 |
|
|
a complicated output field using the `print_expression' functions which
|
1044 |
|
|
requires a stream to be passed. It also shows how to automate stream
|
1045 |
|
|
destruction with cleanups. The original code was:
|
1046 |
|
|
|
1047 |
|
|
annotate_field (5);
|
1048 |
|
|
print_expression (b->exp, gdb_stdout);
|
1049 |
|
|
|
1050 |
|
|
The new version is:
|
1051 |
|
|
|
1052 |
|
|
struct ui_stream *stb = ui_out_stream_new (uiout);
|
1053 |
|
|
struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
|
1054 |
|
|
...
|
1055 |
|
|
annotate_field (5);
|
1056 |
|
|
print_expression (b->exp, stb->stream);
|
1057 |
|
|
ui_out_field_stream (uiout, "what", local_stream);
|
1058 |
|
|
|
1059 |
|
|
This example, also from `print_one_breakpoint', shows how to use
|
1060 |
|
|
`ui_out_text' and `ui_out_field_string'. The original code was:
|
1061 |
|
|
|
1062 |
|
|
annotate_field (5);
|
1063 |
|
|
if (b->dll_pathname == NULL)
|
1064 |
|
|
printf_filtered (" ");
|
1065 |
|
|
else
|
1066 |
|
|
printf_filtered ("library \"%s\" ", b->dll_pathname);
|
1067 |
|
|
|
1068 |
|
|
It became:
|
1069 |
|
|
|
1070 |
|
|
annotate_field (5);
|
1071 |
|
|
if (b->dll_pathname == NULL)
|
1072 |
|
|
{
|
1073 |
|
|
ui_out_field_string (uiout, "what", "");
|
1074 |
|
|
ui_out_spaces (uiout, 1);
|
1075 |
|
|
}
|
1076 |
|
|
else
|
1077 |
|
|
{
|
1078 |
|
|
ui_out_text (uiout, "library \"");
|
1079 |
|
|
ui_out_field_string (uiout, "what", b->dll_pathname);
|
1080 |
|
|
ui_out_text (uiout, "\" ");
|
1081 |
|
|
}
|
1082 |
|
|
|
1083 |
|
|
The following example from `print_one_breakpoint' shows how to use
|
1084 |
|
|
`ui_out_field_int' and `ui_out_spaces'. The original code was:
|
1085 |
|
|
|
1086 |
|
|
annotate_field (5);
|
1087 |
|
|
if (b->forked_inferior_pid != 0)
|
1088 |
|
|
printf_filtered ("process %d ", b->forked_inferior_pid);
|
1089 |
|
|
|
1090 |
|
|
It became:
|
1091 |
|
|
|
1092 |
|
|
annotate_field (5);
|
1093 |
|
|
if (b->forked_inferior_pid != 0)
|
1094 |
|
|
{
|
1095 |
|
|
ui_out_text (uiout, "process ");
|
1096 |
|
|
ui_out_field_int (uiout, "what", b->forked_inferior_pid);
|
1097 |
|
|
ui_out_spaces (uiout, 1);
|
1098 |
|
|
}
|
1099 |
|
|
|
1100 |
|
|
Here's an example of using `ui_out_field_string'. The original code
|
1101 |
|
|
was:
|
1102 |
|
|
|
1103 |
|
|
annotate_field (5);
|
1104 |
|
|
if (b->exec_pathname != NULL)
|
1105 |
|
|
printf_filtered ("program \"%s\" ", b->exec_pathname);
|
1106 |
|
|
|
1107 |
|
|
It became:
|
1108 |
|
|
|
1109 |
|
|
annotate_field (5);
|
1110 |
|
|
if (b->exec_pathname != NULL)
|
1111 |
|
|
{
|
1112 |
|
|
ui_out_text (uiout, "program \"");
|
1113 |
|
|
ui_out_field_string (uiout, "what", b->exec_pathname);
|
1114 |
|
|
ui_out_text (uiout, "\" ");
|
1115 |
|
|
}
|
1116 |
|
|
|
1117 |
|
|
Finally, here's an example of printing an address. The original
|
1118 |
|
|
code:
|
1119 |
|
|
|
1120 |
|
|
annotate_field (4);
|
1121 |
|
|
printf_filtered ("%s ",
|
1122 |
|
|
local_hex_string_custom ((unsigned long) b->address, "08l"));
|
1123 |
|
|
|
1124 |
|
|
It became:
|
1125 |
|
|
|
1126 |
|
|
annotate_field (4);
|
1127 |
|
|
ui_out_field_core_addr (uiout, "Address", b->address);
|
1128 |
|
|
|
1129 |
|
|
Console Printing
|
1130 |
|
|
================
|
1131 |
|
|
|
1132 |
|
|
TUI
|
1133 |
|
|
===
|
1134 |
|
|
|
1135 |
|
|
libgdb
|
1136 |
|
|
======
|
1137 |
|
|
|
1138 |
|
|
`libgdb' was an abortive project of years ago. The theory was to
|
1139 |
|
|
provide an API to GDB's functionality.
|
1140 |
|
|
|
1141 |
|
|
---------- Footnotes ----------
|
1142 |
|
|
|
1143 |
|
|
(1) As of this writing (April 2001), setting verbosity level is not
|
1144 |
|
|
yet implemented, and is always returned as zero. So calling
|
1145 |
|
|
`ui_out_message' with a VERBOSITY argument more than zero will cause
|
1146 |
|
|
the message to never be printed.
|
1147 |
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.
|