(DJGPP Native): Fix overfull hboxes in examples. From Brian Youmans
[deliverable/binutils-gdb.git] / gdb / doc / libgdb.texinfo
CommitLineData
c906108c
SS
1\input texinfo @c -*-texinfo-*-
2@c %**start of header
3@setfilename libgdb.info
4@settitle Libgdb
5@setchapternewpage off
6@c %**end of header
7
8@ifinfo
9This file documents libgdb, the GNU symbolic debugger in a library.
10
11This is Edition 0.3, Oct 1993, of @cite{Libgdb}.
12Copyright 1993 Cygnus Support
13
2a6585f0
EZ
14Permission is granted to copy, distribute and/or modify this document
15under the terms of the GNU Free Documentation License, Version 1.1 or
16any later version published by the Free Software Foundation; with no
17Invariant Sections, with no Front-Cover Texts, and no Back-Cover Texts.
c906108c
SS
18@end ifinfo
19
20@c This title page illustrates only one of the
21@c two methods of forming a title page.
22
23@titlepage
24@title Libgdb
25@subtitle Version 0.3
26@subtitle Oct 1993
27@author Thomas Lord
28
29@c The following two commands
30@c start the copyright page.
31@page
32@vskip 0pt plus 1filll
33Permission is granted to make and distribute verbatim copies of
34this manual provided the copyright notice and this permission notice
35are preserved on all copies.
36
37Copyright @copyright{} 1993 Cygnus Support
38@end titlepage
39
40@ifinfo
41@node Top, Overview, (dir), (dir)
42
43This info file documents libgdb: an API for GDB, the GNU symbolic debugger.
44
45@menu
46* Overview:: The basics of libgdb and this document.
47* Interpreter:: Libgdb is an Interpreter-Based Server.
48* Top Level:: You Provide the Top Level for the Libgdb
49 Command Interpreter .
50* I/O:: How the Server's I/O Can be Used.
51* Invoking:: Invoking the Interpreter, Executing
52 Commands.
53* Defining Commands:: How New Commands are Created.
54* Variables:: How Builtin Variables are Defined.
55* Asynchronous:: Scheduling Asynchronous Computations.
56* Commands:: Debugger Commands for Libgdb Applications
57@end menu
58
59@end ifinfo
60@node Overview, Interpreter, top, top
61@comment node-name, next, previous, up
62@chapter Overview
63@cindex overview
64@cindex definitions
65
66@heading Function and Purpose
67
68Libgdb is a package which provides an API to the functionality of GDB,
69the GNU symbolic debugger. It is specifically intended to support the
70development of a symbolic debugger with a graphic interface.
71
72
73@heading This Document
74
75This document is a specification of the libgdb API. It is written in
76the form of a programmer's manual. So the goal of this document is to
77explain what functions make up the API, and how they can be used in a
78running application.
79
80
81@heading Terminology
82
83In this document, @dfn{libgdb} refers to a library containing the
84functions defined herein, @dfn{application} refers to any program built
85with that library.
86
87
88@heading Dependencies
89
90Programs which are linked with libgdb must be linked with libbfd,
91libopcodes, libiberty, and libmmalloc.
92
93@heading Acknowledgments
94
95Essential contributions to this design were made by Stu Grossman, Jim
96Kingdon, and Rich Pixley.
97
98@node Interpreter, Top Level, Overview, Top
99@comment node-name, next, previous, up
100@chapter Libgdb is an Interpreter Based Server
101@cindex interpreter
102@cindex server
103
104To understand libgdb, it is necessary to understand how the library is
105structured. Historically, GDB is written as a small interpreter for a
106simple command language. The commands of the language perform useful
107debugging functions.
108
109Libgdb is built from GDB by turning the interpreter into a debugging
110server. The server reads debugging commands from any source and
111interprets them, directing the output arbitrarily.
112
113In addition to changing GDB from a tty-based program to a server, a
114number of new GDB commands have been added to make the server more
115useful for a program with a graphic interface.
116
117Finally, libgdb includes provisions for asynchronous processing within
118the application.
119
120Most operations that can be carried out with libgdb involve the GDB
121command interpreter. The usual mode of operation is that the operation
122is expressed as a string of GDB commands, which the interpreter is then
123invoked to carry out. The output from commands executed in this manner
124can be redirected in a variety of useful ways for further processing by
125the application.
126
127The command interpreter provides an extensive system of hooks so an
128application can monitor any aspect of the debugging library's state. An
129application can set its own breakpoints and attach commands and
130conditions to those. It is possible to attach hooks to any debugger
131command; the hooks are invoked whenever that command is about to be
132invoked. By means of these, the displays of a graphical interface can
133be kept fully up to date at all times.
134
135We show you how to define new primitives in the command language. By
136defining new primitives and using them in breakpoint scripts and command
137hooks, an application can schedule the execution of arbitrary C-code at
138almost any point of interest in the operation of libgdb.
139
140We show you how to define new GDB convenience variables for which your
141code computes a value on demand. Referring to such variables in a
142breakpoint condition is a convenient way to conditionalize breakpoints
143in novel ways.
144
145To summarize: in libgdb, the gdb command language is turned into a
146debugging server. The server takes commands as input, and the server's
147output is redirectable. An application uses libgdb by formatting
148debugging commands and invoking the interpreter. The application might
149maintain breakpoints, watchpoints and many kinds of hooks. An application
150can define new primitives for the interpreter.
151
152@node Top Level, I/O, Interpreter, Top
153@chapter You Provide the Top Level for the Libgdb Command Interpreter
154@cindex {top level}
155
156When you use libgdb, your code is providing a @dfn{top level} for the
157command language interpreter. The top level is significant because it
158provides commands for the the interpreter to execute. In addition, the
159top level is responsible for handling some kinds of errors, and
160performing certain cleanup operations on behalf of the interpreter.
161
162@heading Initialization
163
164Before calling any other libgdb functions, call this:
165
166@deftypefun void gdb_init (void)
167Perform one-time initialization for libgdb.
168@end deftypefun
169
170An application may wish to evaluate specific gdb commands as part of its
171own initialization. The details of how this can be accomplished are
172explained below.
173
174@heading The Top-Level Loop
175
176There is a strong presumption in libgdb that the application has
177the form of a loop. Here is what such a loop might look like:
178
179@example
180while (gdb_still_going ())
181 @{
182 if (!GDB_TOP_LEVEL ())
183 @{
184 char * command;
185 gdb_start_top_loop ();
186 command = process_events ();
187 gdb_execute_command (command);
188 gdb_finish_top_loop ();
189 @}
190 @}
191@end example
192
193The function @code{gdb_still_going} returns 1 until the gdb command
194`quit' is run.
195
196The macro @code{GDB_TOP_LEVEL} invokes setjmp to set the top level error
197handler. When a command results in an error, the interpreter exits with
198a longjmp. There is nothing special libgdb requires of the top level
199error handler other than it be present and that it restart the top level
200loop. Errors are explained in detail in a later chapter.
201
202Each time through the top level loop two important things happen: a
203debugger command is constructed on the basis of user input, and the
204interpreter is invoked to execute that command. In the sample code, the
205call to the imaginary function @code{process_events} represents the
206point at which a graphical interface should read input events until
207ready to execute a debugger command. The call to
208@code{gdb_execute_command} invokes the command interpreter (what happens
209to the output from the command will be explained later).
210
211Libgdb manages some resources using the top-level loop. The primary
212reason for this is error-handling: even if a command terminates with an
213error, it may already have allocated resources which need to be freed.
214The freeing of such resources takes place at the top-level, regardless
215of how the the command exits. The calls to @code{gdb_start_top_loop}
216and @code{gdb_finish_top_loop} let libgdb know when it is safe to
217perform operations associated with these resources.
218
219@heading Breakpoint Commands
220
221Breakpoint commands are scripts of GDB operations associated with
222particular breakpoints. When a breakpoint is reached, its associated
223commands are executed.
224
225Breakpoint commands are invoked by the libgdb function
226@code{gdb_finish_top_loop}.
227
228Notice that if control returns to the top-level error handler, the
229execution of breakpoint commands is bypassed. This can happen as a
230result of errors during either @code{gdb_execute_command} or
231@code{gdb_finish_top_loop}.
232
233@heading Application Initialization
234
235Sometimes it is inconvenient to execute commands via a command loop for
236example, the commands an application uses to initialize itself. An
237alternative to @code{execute_command} is @code{execute_catching_errors}.
238When @code{execute_catching_errors} is used, no top level error handler
239need be in effect, and it is not necessary to call
240@code{gdb_start_top_loop} or @code{gdb_finish_top_loop}.
241
242
243@heading Cleanup
244
245The debugger command ``quit'' performs all necessary cleanup for libgdb.
246After it has done so, it changes the return value of
247@code{gdb_still_going} to 0 and returns to the top level error handler.
248
249
250@node I/O, Invoking, Top Level, Top
251@comment node-name, next, previous, up
252@chapter How the Server's I/O Can be Used
253@cindex I/O
254
255In the last chapter it was pointed out that a libgdb application is
256responsible for providing commands for the interpreter to execute.
257However some commands require further input (for example, the ``quit''
258command might ask for confirmation). Almost all commands produce output
259of some kind. The purpose of this section is to explain how libgdb
260performs its I/O, and how an application can take advantage of
261this.
262
263
264@heading I/O Vectors
265
266Libgdb has no fixed strategy for I/O. Instead, all operations are
267performed by functions called via structures of function pointers.
268Applications supply theses structures and can change them at any
269time.
270
271@deftp Type {struct gdb_input_vector}
272@deftpx Type {struct gdb_output_vector}
273These structures contain a set of function pointers. Each function
274determines how a particular type of i/o is performed. The details of
275these strucutres are explained below.
276
277The application allocates these structures, initializes them to all bits
278zero, fills in the function pointers, and then registers names for them
279them with libgdb.
280@end deftp
281
282@deftypefun void gdb_name_input_vector (@var{name}, @var{vec})
283@deftypefunx void gdb_remove_input_vector (@var{name}, @var{vec})
284@deftypefunx void gdb_name_output_vector (@var{name}, @var{vec})
285@deftypefunx void gdb_remove_input_vector (@var{name}, @var{vec})
286@example
287 char * @var{name};
288 struct gdb_output_vector * @var{vec};
289@end example
290These functions are used to give and remove names to i/o vectors. Note
291that if a name is used twice, the most recent definition applies.
292@end deftypefun
293
294
295
296@subheading Output
297
298An output vector is a structure with at least these fields:
299
300@example
301struct gdb_output_vector
302@{
303 /* output */
304 void (*put_string) (struct gdb_output_vector *, char * str);
305@}
306@end example
307
308Use the function @code{memset} or something equivalent to initialize an
309output vector to all bits zero. Then fill in the function pointer with
310your function.
311
312A debugger command can produce three kinds of output: error messages
313(such as when trying to delete a non-existent breakpoint), informational
314messages (such as the notification printed when a breakpoint is hit),
315and the output specifically requested by a command (for example, the
316value printed by the ``print'' command). At any given time, then,
317libgdb has three output vectors. These are called the @dfn{error},
318@dfn{info}, @dfn{value} vector respectively.
319
320@subheading Input
321
322@example
323struct gdb_input_vector
324@{
325 int (*query) (struct gdb_input_vector *,
326 char * prompt,
327 int quit_allowed);
328 int * (*selection) (struct gdb_input_vector *,
329 char * prompt,
330 char ** choices);
331 char * (*read_string) (struct gdb_input_vector *,
332 char * prompt);
333 char ** (*read_strings) (struct gdb_input_vector *,
334 char * prompt);
335@}
336@end example
337
338Use the function @code{memset} or something equivalent to initialize an
339input vector to all bits zero. Then fill in the function pointers with
340your functions.
341
342There are four kinds of input requests explicitly made by libgdb.
343
344A @dfn{query} is a yes or no question. The user can respond to a query
345with an affirmative or negative answer, or by telling gdb to abort the
346command (in some cases an abort is not permitted). Query should return
347'y' or 'n' or 0 to abort.
348
349A @dfn{selection} is a list of options from which the user selects a subset.
350Selections should return a NULL terminated array of integers, which are
351indexes into the array of choices. It can return NULL instead to abort
352the command. The array returned by this function will be passed to
353@code{free} by libgdb.
354
355A @dfn{read_string} asks the user to supply an arbitrary string. It may
356return NULL to abort the command. The string returned by @code{read_string}
357should be allocated by @code{malloc}; it will be freed by libgdb.
358
359A @dfn{read_strings} asks the user to supply multiple lines of input
360(for example, the body of a command created using `define'). It, too,
361may return NULL to abort. The array and the strings returned by this
362function will be freed by libgdb.
363
364@heading I/O Redirection from the Application Top-Level
365
366@deftypefun struct gdb_io_vecs gdb_set_io (struct gdb_io_vecs *)
367@example
368
369struct gdb_io_vecs
370@{
371 struct gdb_input_vector * input;
372 struct gdb_output_vector * error;
373 struct gdb_output_vector * info;
374 struct gdb_output_vector * value;
375@}
376@end example
377
378This establishes a new set of i/o vectors, and returns the old setting.
379Any of the pointers in this structure may be NULL, indicating that the
380current value should be used.
381
382This function is useful for setting up i/o vectors before any libgdb
383commands have been invoked (hence before any input or output has taken
384place).
385@end deftypefun
386
387It is explained in a later chapter how to redirect output temporarily.
388(@xref{Invoking}.)
389
390@heading I/O Redirection in Debugger Commands
391
392A libgdb application creates input and output vectors and assigns them names.
393Which input and output vectors are used by libgdb is established by
394executing these debugger commands:
395
396@defun {set input-vector} name
397@defunx {set error-output-vector} name
398@defunx {set info-output-vector} name
399@defunx {set value-output-vector} name
400Choose an I/O vector by name.
401@end defun
402
403
404A few debugger commands are for use only within commands defined using
405the debugger command `define' (they have no effect at other times).
406These commands exist so that an application can maintain hooks which
407redirect output without affecting the global I/O vectors.
408
409@defun with-input-vector name
410@defunx with-error-output-vector name
411@defunx with-info-output-vector name
412@defunx with-value-output-vector name
413Set an I/O vector, but only temporarily. The setting has effect only
414within the command definition in which it occurs.
415@end defun
416
417
418@heading Initial Conditions
419
420When libgdb is initialized, a set of default I/O vectors is put in
421place. The default vectors are called @code{default-input-vector},
422@code{default-output-vector}, &c.
423
424The default query function always returns `y'. Other input functions
425always abort. The default output functions discard output silently.
426
427
428@node Invoking, Defining Commands, I/O, Top
429@chapter Invoking the Interpreter, Executing Commands
430@cindex {executing commands}
431@cindex {invoking the interpreter}
432
433This section introduces the libgdb functions which invoke the command
434interpreter.
435
436@deftypefun void gdb_execute_command (@var{command})
437@example
438char * @var{command};
439@end example
440Interpret the argument debugger command. An error handler must be set
441when this function is called. (@xref{Top Level}.)
442@end deftypefun
443
444It is possible to override the current I/O vectors for the duration of a
445single command:
446
447@deftypefun void gdb_execute_with_io (@var{command}, @var{vecs})
448@example
449char * @var{command};
450struct gdb_io_vecs * @var{vecs};
451
452struct gdb_io_vecs
453@{
454 struct gdb_input_vector * input;
455 struct gdb_output_vector * error;
456 struct gdb_output_vector * info;
457 struct gdb_output_vector * value;
458@}
459@end example
460
461Execute @var{command}, temporarily using the i/o vectors in @var{vecs}.
462
463Any of the vectors may be NULL, indicating that the current value should
464be used. An error handler must be in place when this function is used.
465@end deftypefun
466
467@deftypefun {struct gdb_str_output} gdb_execute_for_strings (@var{cmd})
468@example
469char * cmd;
470@end example
471@deftypefunx {struct gdb_str_output} gdb_execute_for_strings2 (@var{cmd}, @var{input})
472@example
473char * cmd;
474struct gdb_input_vector * input;
475@end example
476@page
477@example
478struct gdb_str_output
479@{
480 char * error;
481 char * info;
482 char * value;
483@};
484@end example
485
486Execute @var{cmd}, collecting its output as strings. If no error
487occurs, all three strings will be present in the structure, the
488empty-string rather than NULL standing for no output of a particular
489kind.
490
491If the command aborts with an error, then the @code{value} field will be
492NULL, though the other two strings will be present.
493
494In all cases, the strings returned are allocated by malloc and should be
495freed by the caller.
496
497The first form listed uses the current input vector, but overrides the
498current output vector. The second form additionally allows the input
499vector to be overridden.
500
501This function does not require that an error handler be installed.
502@end deftypefun
503
504@deftypefun void execute_catching_errors (@var{command})
505@example
506char * @var{command};
507@end example
508Like @code{execute_command} except that no error handler is required.
509@end deftypefun
510
511@deftypefun void execute_with_text (@var{command}, @var{text})
512@example
513char * @var{command};
514char ** @var{text};
515@end example
516Like @code{execute_catching_errors}, except that the input vector is
517overridden. The new input vector handles only calls to @code{query} (by
518returning 'y') and calls to @code{read_strings} by returning a copy of
519@var{text} and the strings it points to.
520
521This form of execute_command is useful for commands like @code{define},
522@code{document}, and @code{commands}.
523@end deftypefun
524
525
526
527@node Defining Commands, Variables, Invoking, Top
528@comment node-name, next, previous, up
529@chapter How New Commands are Created
530@cindex {commands, defining}
531
532Applications are, of course, free to take advantage of the existing GDB
533macro definition capability (the @code{define} and @code{document}
534functions).
535
536In addition, an application can add new primitives to the GDB command
537language.
538
539@deftypefun void gdb_define_app_command (@var{name}, @var{fn}, @var{doc})
540@example
541char * @var{name};
542gdb_cmd_fn @var{fn};
543char * @var{doc};
544
545typedef void (*gdb_cmd_fn) (char * args);
546@end example
547
548Create a new command call @var{name}. The new command is in the
549@code{application} help class. When invoked, the command-line arguments
550to the command are passed as a single string.
551
552Calling this function twice with the same name replaces an earlier
553definition, but application commands can not replace builtin commands of
554the same name.
555
556The documentation string of the command is set to a copy the string
557@var{doc}.
558@end deftypefun
559
560@node Variables, Asynchronous, Defining Commands, Top
561@comment node-name, next, previous, up
562@chapter How Builtin Variables are Defined
563@cindex {variables, defining}
564
565Convenience variables provide a way for values maintained by libgdb to
566be referenced in expressions (e.g. @code{$bpnum}). Libgdb includes a
567means by which the application can define new, integer valued
568convenience variables:
569@page
570@deftypefun void gdb_define_int_var (@var{name}, @var{fn}, @var{fn_arg})
571@example
572char * @var{name};
573int (*@var{fn}) (void *);
574void * @var{fn_arg};
575@end example
576This function defines (or undefines) a convenience variable called @var{name}.
577If @var{fn} is NULL, the variable becomes undefined. Otherwise,
578@var{fn} is a function which, when passed @var{fn_arg} returns the value
579of the newly defined variable.
580
581No libgdb functions should be called by @var{fn}.
582@end deftypefun
583
584One use for this function is to create breakpoint conditions computed in
585novel ways. This is done by defining a convenience variable and
586referring to that variable in a breakpoint condition expression.
587
588
589@node Asynchronous, Commands, Variables, Top
590@chapter Scheduling Asynchronous Computations
591@cindex asynchronous
592
593
594A running libgdb function can take a long time. Libgdb includes a hook
595so that an application can run intermittently during long debugger
596operations.
597
598@deftypefun void gdb_set_poll_fn (@var{fn}, @var{fn_arg})
599@example
600void (*@var{fn})(void * fn_arg, int (*gdb_poll)());
601void * @var{fn_arg};
602@end example
603Arrange to call @var{fn} periodically during lengthy debugger operations.
604If @var{fn} is NULL, polling is turned off. @var{fn} should take two
605arguments: an opaque pointer passed as @var{fn_arg} to
606@code{gdb_set_poll_fn}, and a function pointer. The function pointer
607passed to @var{fn} is provided by libgdb and points to a function that
608returns 0 when the poll function should return. That is, when
609@code{(*gdb_poll)()} returns 0, libgdb is ready to continue @var{fn}
610should return quickly.
611
612It is possible that @code{(*gdb_poll)()} will return 0 the first time it
613is called, so it is reasonable for an application to do minimal processing
614before checking whether to return.
615
616No libgdb functions should be called from an application's poll function,
617with one exception: @code{gdb_request_quit}.
618@end deftypefun
619
620
621@deftypefun void gdb_request_quit (void)
622This function, if called from a poll function, requests that the
623currently executing libgdb command be interrupted as soon as possible,
624and that control be returned to the top-level via an error.
625
626The quit is not immediate. It will not occur until at least after the
627application's poll function returns.
628@end deftypefun
629
630@node Commands, Top, Asynchronous, Top
631@comment node-name, next, previous, up
632@chapter Debugger Commands for Libgdb Applications
633
634The debugger commands available to libgdb applications are the same commands
635available interactively via GDB. This section is an overview of the
636commands newly created as part of libgdb.
637
638This section is not by any means a complete reference to the GDB command
639language. See the GDB manual for such a reference.
640
641@menu
642* Command Hooks:: Setting Hooks to Execute With Debugger Commands.
643* View Commands:: View Commands Mirror Show Commands
644* Breakpoints:: The Application Can Have Its Own Breakpoints
645@end menu
646
647@node Command Hooks, View Commands, Commands, Commands
648@comment node-name, next, previous, up
649@section Setting Hooks to Execute With Debugger Commands.
650
651Debugger commands support hooks. A command hook is executed just before
652the interpreter invokes the hooked command.
653
654There are two hooks allowed for every command. By convention, one hook
655is for use by users, the other is for use by the application.
656
657A user hook is created for a command XYZZY by using
658@code{define-command} to create a command called @code{hook-XYZZY}.
659
660An application hook is created for a command XYZZY by using
661@code{define-command} to create a command called @code{apphook-XYZZY}.
662
663Application hooks are useful for interfaces which wish to continuously
664monitor certain aspects of debugger state. The application can set a
665hook on all commands that might modify the watched state. When the hook
666is executed, it can use i/o redirection to notify parts of the
667application that previous data may be out of date. After the top-level loop
668resumes, the application can recompute any values that may have changed.
669(@xref{I/O}.)
670
671@node View Commands, Breakpoints, Command Hooks, Commands
672@comment node-name, next, previous, up
673@section View Commands Mirror Show Commands
674
675The GDB command language contains many @code{set} and @code{show}
676commands. These commands are used to modify or examine parameters to
677the debugger.
678
679It is difficult to get the current state of a parameter from the
680@code{show} command because @code{show} is very verbose.
681
682@example
683(gdb) show check type
684Type checking is "auto; currently off".
685(gdb) show width
686Number of characters gdb thinks are in a line is 80.
687@end example
688
689For every @code{show} command, libgdb includes a @code{view} command.
690@code{view} is like @code{show} without the verbose commentary:
691
692@example
693(gdb) view check type
694auto; currently off
695(gdb) view width
69680
697@end example
698
699(The precise format of the ouput from @code{view} is subject to change.
700In particular, @code{view} may one-day print values which can be used as
701arguments to the corresponding @code{set} command.)
702
703@node Breakpoints, Structured Output, View Commands, Commands
704@comment node-name, next, previous, up
705@section The Application Can Have Its Own Breakpoints
706
707The GDB breakpoint commands were written with a strong presumption that
708all breakpoints are managed by a human user. Therefore, the command
709language contains commands like `delete' which affect all breakpoints
710without discrimination.
711
712In libgdb, there is added support for breakpoints and watchpoints which
713are set by the application and which should not be affected by ordinary,
714indiscriminate commands. These are called @dfn{protected} breakpoints.
715
716@deffn {Debugger Command} break-protected ...
717@deffnx {Debugger Command} watch-protected ...
718These work like @code{break} and @code{watch} except that the resulting
719breakpoint is given a negative number. Negative numbered breakpoints do
720not appear in the output of @code{info breakpoints} but do in that of
721@code{info all-breakpoints}. Negative numbered breakpoints are not
722affected by commands which ordinarily affect `all' breakpoints (e.g.
723@code{delete} with no arguments).
724
725Note that libgdb itself creates protected breakpoints, so programs
726should not rely on being able to allocate particular protected
727breakpoint numbers for themselves.
728@end deffn
729
730More than one breakpoint may be set at a given location. Libgdb adds
731the concept of @dfn{priority} to breakpoints. A priority is an integer,
732assigned to each breakpoint. When a breakpoint is reached, the
733conditions of all breakpoints at the same location are evaluated in
734order of ascending priority. When breakpoint commands are executed,
735they are also executed in ascending priority (until all have been
736executed, an error occurs, or one set of commands continues the
737target).
738
739@deffn {Debugger Command} priority n bplist
740Set the priority for breakpoints @var{bplist} to @var{n}.
741By default, breakpoints are assigned a priority of zero.
742@end deffn
743
744@node Structured Output, Commands, Breakpoints, Commands
745@comment node-name, next, previous, up
746@section Structured Output, The @code{Explain} Command
747
748(This section may be subject to considerable revision.)
749
750When GDB prints a the value of an expression, the printed representation
751contains information that can be usefully fed back into future commands
752and expressions. For example,
753
754@example
755(gdb) print foo
756$16 = @{v = 0x38ae0, v_length = 40@}
757@end example
758
759On the basis of this output, a user knows, for example, that
760@code{$16.v} refers to a pointer valued @code{0x38ae0}
761
762A new output command helps to make information like this available to
763the application.
764
765@deffn {Debugger Command} explain expression
766@deffnx {Debugger Command} explain /format expression
767Print the value of @var{expression} in the manner of the @code{print}
768command, but embed that output in a list syntax containing information
769about the structure of the output.
770@end deffn
771
772As an example, @code{explain argv} might produce this output:
773
774@example
775(exp-attribute
776 ((expression "$19")
777 (type "char **")
778 (address "48560")
779 (deref-expression "*$19"))
780 "$19 = 0x3800\n")
781@end example
782
783The syntax of output from @code{explain} is:
784
785@example
786<explanation> := <quoted-string>
787 | (exp-concat <explanation> <explanation>*)
788 | (exp-attribute <property-list> <explanation>)
789
790<property-list> := ( <property-pair>* )
791
792<property-pair> := ( <property-name> <quoted-string> )
793@end example
794
795The string-concatenation of all of the @code{<quoted-string>} (except
796those in property lists) yields the output generated by the equivalent
797@code{print} command. Quoted strings may contain quotes and backslashes
798if they are escaped by backslash. "\n" in a quoted string stands for
799newline; unescaped newlines do not occur within the strings output by
800@code{explain}.
801
802Property names are made up of alphabetic characters, dashes, and
803underscores.
804
805The set of properties is open-ended. As GDB acquires support for new
806source languages and other new capabilities, new property types may be
807added to the output of this command. Future commands may offer
808applications some selectivity concerning which properties are reported.
809
810The initial set of properties defined includes:
811
812@itemize @bullet
813@item @code{expression}
814
815This is an expression, such as @code{$42} or @code{$42.x}. The
816expression can be used to refer to the value printed in the attributed
817part of the string.
818
819@item @code{type}
820
821This is a user-readable name for the type of the attributed value.
822
823@item @code{address}
824
825If the value is stored in a target register, this is a register number.
826If the value is stored in a GDB convenience variable, this is an integer
827that is unique among all the convenience variables. Otherwise, this is
828the address in the target where the value is stored.
829
830@item @code{deref-expression}
831
832If the attributed value is a pointer type, this is an expression that
833refers to the dereferenced value.
834@end itemize
835
836Here is a larger example, using the same object passed to @code{print}
837in an earlier example of this section.
838
839@example
840(gdb) explain foo
841(exp-attribute
842 ( (expression "$16")
843 (type "struct bytecode_vector")
844 (address 14336) )
845 (exp-concat
846 "$16 = @{"
847 (exp-attribute
848 ( (expression "$16.v")
849 (type "char *")
850 (address 14336)
851 (deref-expression "*$16.v") )
852 "v = 0x38ae0")
853 (exp-attribute
854 ( (expression "$16.v_length")
855 (type "int")
856 (address 14340) )
857 ", v_length = 40")
858 "@}\n"))
859@end example
860
861It is undefined how libgdb will indent these lines of output or
862where newlines will be included.
863
864@bye
This page took 0.160211 seconds and 4 git commands to generate.