old-cross-binutils/gdb/doc/libgdb.texinfo

879 lines
30 KiB
Text
Raw Normal View History

1993-10-04 17:44:52 +00:00
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename libgdb.info
@settitle Libgdb
1993-10-25 19:40:46 +00:00
@setchapternewpage off
1993-10-04 17:44:52 +00:00
@c %**end of header
@ifinfo
1993-10-25 19:40:46 +00:00
This file documents libgdb, the GNU symbolic debugger in a library.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
This is Edition 0.3, Oct 1993, of @cite{Libgdb}.
1993-10-04 17:44:52 +00:00
Copyright 1993 Cygnus Support
1993-10-25 19:40:46 +00:00
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
1993-10-04 17:44:52 +00:00
@end ifinfo
@c This title page illustrates only one of the
@c two methods of forming a title page.
@titlepage
@title Libgdb
1993-10-25 19:40:46 +00:00
@subtitle Version 0.3
@subtitle Oct 1993
1993-10-04 17:44:52 +00:00
@author Thomas Lord
@c The following two commands
@c start the copyright page.
@page
@vskip 0pt plus 1filll
1993-10-25 19:40:46 +00:00
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Copyright @copyright{} 1993 Cygnus Support
1993-10-04 17:44:52 +00:00
@end titlepage
@ifinfo
1993-10-25 19:40:46 +00:00
@node Top, Overview, (dir), (dir)
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
This info file documents libgdb: an API for GDB, the GNU symbolic debugger.
1993-10-04 17:44:52 +00:00
@menu
1993-10-25 19:40:46 +00:00
* Overview:: The basics of libgdb and this document.
* Interpreter:: Libgdb is an Interpreter-Based Server.
* Top Level:: You Provide the Top Level for the Libgdb
Command Interpreter .
* I/O:: How the Server's I/O Can be Used.
* Invoking:: Invoking the Interpreter, Executing
Commands.
* Defining Commands:: How New Commands are Created.
* Variables:: How Builtin Variables are Defined.
* Asynchronous:: Scheduling Asynchronous Computations.
* Commands:: Debugger Commands for Libgdb Applications
1993-10-04 17:44:52 +00:00
@end menu
1993-10-25 19:40:46 +00:00
@end ifinfo
@node Overview, Interpreter, top, top
1993-10-04 17:44:52 +00:00
@comment node-name, next, previous, up
@chapter Overview
@cindex overview
@cindex definitions
1993-10-25 19:40:46 +00:00
@heading Function and Purpose
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Libgdb is a package which provides an API to the functionality of GDB,
the GNU symbolic debugger. It is specifically intended to support the
development of a symbolic debugger with a graphic interface.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@heading This Document
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
This document is a specification of the libgdb API. It is written in
the form of a programmer's manual. So the goal of this document is to
explain what functions make up the API, and how they can be used in a
running application.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@heading Terminology
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
In this document, @dfn{libgdb} refers to a library containing the
functions defined herein, @dfn{application} refers to any program built
with that library.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@heading Dependencies
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Programs which are linked with libgdb must be linked with libbfd,
libopcodes, libiberty, and libmmalloc.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@heading Acknowledgments
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Essential contributions to this design were made by Stu Grossman, Jim
Kingdon, and Rich Pixley.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@node Interpreter, Top Level, Overview, Top
@comment node-name, next, previous, up
@chapter Libgdb is an Interpreter Based Server
@cindex interpreter
@cindex server
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
To understand libgdb, it is necessary to understand how the library is
structured. Historically, GDB is written as a small interpreter for a
simple command language. The commands of the language perform useful
debugging functions.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Libgdb is built from GDB by turning the interpreter into a debugging
server. The server reads debugging commands from any source and
interprets them, directing the output arbitrarily.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
In addition to changing GDB from a tty-based program to a server, a
number of new GDB commands have been added to make the server more
useful for a program with a graphic interface.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Finally, libgdb includes provisions for asynchronous processing within
the application.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Most operations that can be carried out with libgdb involve the GDB
command interpreter. The usual mode of operation is that the operation
is expressed as a string of GDB commands, which the interpreter is then
invoked to carry out. The output from commands executed in this manner
can be redirected in a variety of useful ways for further processing by
the application.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
The command interpreter provides an extensive system of hooks so an
application can monitor any aspect of the debugging library's state. An
application can set its own breakpoints and attach commands and
conditions to those. It is possible to attach hooks to any debugger
command; the hooks are invoked whenever that command is about to be
invoked. By means of these, the displays of a graphical interface can
be kept fully up to date at all times.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
We show you how to define new primitives in the command language. By
defining new primitives and using them in breakpoint scripts and command
hooks, an application can schedule the execution of arbitrary C-code at
almost any point of interest in the operation of libgdb.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
We show you how to define new GDB convenience variables for which your
code computes a value on demand. Referring to such variables in a
breakpoint condition is a convenient way to conditionalize breakpoints
in novel ways.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
To summarize: in libgdb, the gdb command language is turned into a
debugging server. The server takes commands as input, and the server's
output is redirectable. An application uses libgdb by formatting
debugging commands and invoking the interpreter. The application might
maintain breakpoints, watchpoints and many kinds of hooks. An application
can define new primitives for the interpreter.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@node Top Level, I/O, Interpreter, Top
@chapter You Provide the Top Level for the Libgdb Command Interpreter
@cindex {top level}
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
When you use libgdb, your code is providing a @dfn{top level} for the
command language interpreter. The top level is significant because it
provides commands for the the interpreter to execute. In addition, the
top level is responsible for handling some kinds of errors, and
performing certain cleanup operations on behalf of the interpreter.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@heading Initialization
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Before calling any other libgdb functions, call this:
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@deftypefun void gdb_init (void)
Perform one-time initialization for libgdb.
1993-10-04 17:44:52 +00:00
@end deftypefun
1993-10-25 19:40:46 +00:00
An application may wish to evaluate specific gdb commands as part of its
own initialization. The details of how this can be accomplished are
explained below.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@heading The Top-Level Loop
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
There is a strong presumption in libgdb that the application has
the form of a loop. Here is what such a loop might look like:
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
while (gdb_still_going ())
@{
if (!GDB_TOP_LEVEL ())
@{
char * command;
gdb_start_top_loop ();
command = process_events ();
gdb_execute_command (command);
gdb_finish_top_loop ();
@}
@}
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
The function @code{gdb_still_going} returns 1 until the gdb command
`quit' is run.
The macro @code{GDB_TOP_LEVEL} invokes setjmp to set the top level error
handler. When a command results in an error, the interpreter exits with
a longjmp. There is nothing special libgdb requires of the top level
error handler other than it be present and that it restart the top level
loop. Errors are explained in detail in a later chapter.
Each time through the top level loop two important things happen: a
debugger command is constructed on the basis of user input, and the
interpreter is invoked to execute that command. In the sample code, the
call to the imaginary function @code{process_events} represents the
point at which a graphical interface should read input events until
ready to execute a debugger command. The call to
@code{gdb_execute_command} invokes the command interpreter (what happens
to the output from the command will be explained later).
Libgdb manages some resources using the top-level loop. The primary
reason for this is error-handling: even if a command terminates with an
error, it may already have allocated resources which need to be freed.
The freeing of such resources takes place at the top-level, regardless
of how the the command exits. The calls to @code{gdb_start_top_loop}
and @code{gdb_finish_top_loop} let libgdb know when it is safe to
perform operations associated with these resources.
@heading Breakpoint Commands
Breakpoint commands are scripts of GDB operations associated with
particular breakpoints. When a breakpoint is reached, its associated
commands are executed.
Breakpoint commands are invoked by the libgdb function
@code{gdb_finish_top_loop}.
Notice that if control returns to the top-level error handler, the
execution of breakpoint commands is bypassed. This can happen as a
result of errors during either @code{gdb_execute_command} or
@code{gdb_finish_top_loop}.
@heading Application Initialization
Sometimes it is inconvenient to execute commands via a command loop for
example, the commands an application uses to initialize itself. An
alternative to @code{execute_command} is @code{execute_catching_errors}.
When @code{execute_catching_errors} is used, no top level error handler
need be in effect, and it is not necessary to call
@code{gdb_start_top_loop} or @code{gdb_finish_top_loop}.
@heading Cleanup
The debugger command ``quit'' performs all necessary cleanup for libgdb.
After it has done so, it changes the return value of
@code{gdb_still_going} to 0 and returns to the top level error handler.
@node I/O, Invoking, Top Level, Top
@comment node-name, next, previous, up
@chapter How the Server's I/O Can be Used
@cindex I/O
In the last chapter it was pointed out that a libgdb application is
responsible for providing commands for the interpreter to execute.
However some commands require further input (for example, the ``quit''
command might ask for confirmation). Almost all commands produce output
of some kind. The purpose of this section is to explain how libgdb
performs its I/O, and how an application can take advantage of
this.
@heading I/O Vectors
Libgdb has no fixed strategy for I/O. Instead, all operations are
performed by functions called via structures of function pointers.
Applications supply theses structures and can change them at any
time.
@deftp Type {struct gdb_input_vector}
@deftpx Type {struct gdb_output_vector}
These structures contain a set of function pointers. Each function
determines how a particular type of i/o is performed. The details of
these strucutres are explained below.
The application allocates these structures, initializes them to all bits
zero, fills in the function pointers, and then registers names for them
them with libgdb.
@end deftp
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@deftypefun void gdb_name_input_vector (@var{name}, @var{vec})
@deftypefunx void gdb_remove_input_vector (@var{name}, @var{vec})
@deftypefunx void gdb_name_output_vector (@var{name}, @var{vec})
@deftypefunx void gdb_remove_input_vector (@var{name}, @var{vec})
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
char * @var{name};
struct gdb_output_vector * @var{vec};
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
These functions are used to give and remove names to i/o vectors. Note
that if a name is used twice, the most recent definition applies.
1993-10-04 17:44:52 +00:00
@end deftypefun
1993-10-25 19:40:46 +00:00
@subheading Output
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
An output vector is a structure with at least these fields:
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
struct gdb_output_vector
1993-10-04 17:44:52 +00:00
@{
1993-10-25 19:40:46 +00:00
/* output */
void (*put_string) (struct gdb_output_vector *, char * str);
1993-10-04 17:44:52 +00:00
@}
@end example
1993-10-25 19:40:46 +00:00
Use the function @code{memset} or something equivalent to initialize an
output vector to all bits zero. Then fill in the function pointer with
your function.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
A debugger command can produce three kinds of output: error messages
(such as when trying to delete a non-existent breakpoint), informational
messages (such as the notification printed when a breakpoint is hit),
and the output specifically requested by a command (for example, the
value printed by the ``print'' command). At any given time, then,
libgdb has three output vectors. These are called the @dfn{error},
@dfn{info}, @dfn{value} vector respectively.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@subheading Input
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
struct gdb_input_vector
@{
int (*query) (struct gdb_input_vector *,
char * prompt,
int quit_allowed);
int * (*selection) (struct gdb_input_vector *,
char * prompt,
char ** choices);
char * (*read_string) (struct gdb_input_vector *,
char * prompt);
char ** (*read_strings) (struct gdb_input_vector *,
char * prompt);
@}
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
Use the function @code{memset} or something equivalent to initialize an
input vector to all bits zero. Then fill in the function pointers with
your functions.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
There are four kinds of input requests explicitly made by libgdb.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
A @dfn{query} is a yes or no question. The user can respond to a query
with an affirmative or negative answer, or by telling gdb to abort the
command (in some cases an abort is not permitted). Query should return
'y' or 'n' or 0 to abort.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
A @dfn{selection} is a list of options from which the user selects a subset.
Selections should return a NULL terminated array of integers, which are
indexes into the array of choices. It can return NULL instead to abort
the command. The array returned by this function will be passed to
@code{free} by libgdb.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
A @dfn{read_string} asks the user to supply an arbitrary string. It may
return NULL to abort the command. The string returned by @code{read_string}
should be allocated by @code{malloc}; it will be freed by libgdb.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
A @dfn{read_strings} asks the user to supply multiple lines of input
(for example, the body of a command created using `define'). It, too,
may return NULL to abort. The array and the strings returned by this
function will be freed by libgdb.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@heading I/O Redirection from the Application Top-Level
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@deftypefun struct gdb_io_vecs gdb_set_io (struct gdb_io_vecs *)
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
struct gdb_io_vecs
@{
struct gdb_input_vector * input;
struct gdb_output_vector * error;
struct gdb_output_vector * info;
struct gdb_output_vector * value;
@}
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
This establishes a new set of i/o vectors, and returns the old setting.
Any of the pointers in this structure may be NULL, indicating that the
current value should be used.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
This function is useful for setting up i/o vectors before any libgdb
commands have been invoked (hence before any input or output has taken
place).
1993-10-04 17:44:52 +00:00
@end deftypefun
1993-10-25 19:40:46 +00:00
It is explained in a later chapter how to redirect output temporarily.
(@xref{Invoking}.)
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@heading I/O Redirection in Debugger Commands
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
A libgdb application creates input and output vectors and assigns them names.
Which input and output vectors are used by libgdb is established by
executing these debugger commands:
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@defun {set input-vector} name
@defunx {set error-output-vector} name
@defunx {set info-output-vector} name
@defunx {set value-output-vector} name
Choose an I/O vector by name.
@end defun
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
A few debugger commands are for use only within commands defined using
the debugger command `define' (they have no effect at other times).
These commands exist so that an application can maintain hooks which
redirect output without affecting the global I/O vectors.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@defun with-input-vector name
@defunx with-error-output-vector name
@defunx with-info-output-vector name
@defunx with-value-output-vector name
Set an I/O vector, but only temporarily. The setting has effect only
within the command definition in which it occurs.
@end defun
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@heading Initial Conditions
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
When libgdb is initialized, a set of default I/O vectors is put in
place. The default vectors are called @code{default-input-vector},
@code{default-output-vector}, &c.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
The default query function always returns `y'. Other input functions
always abort. The default output functions discard output silently.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@node Invoking, Defining Commands, I/O, Top
@chapter Invoking the Interpreter, Executing Commands
@cindex {executing commands}
@cindex {invoking the interpreter}
This section introduces the libgdb functions which invoke the command
interpreter.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@deftypefun void gdb_execute_command (@var{command})
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
char * @var{command};
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
Interpret the argument debugger command. An error handler must be set
when this function is called. (@xref{Top Level}.)
1993-10-04 17:44:52 +00:00
@end deftypefun
1993-10-25 19:40:46 +00:00
It is possible to override the current I/O vectors for the duration of a
single command:
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@deftypefun void gdb_execute_with_io (@var{command}, @var{vecs})
@example
char * @var{command};
struct gdb_io_vecs * @var{vecs};
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
struct gdb_io_vecs
@{
struct gdb_input_vector * input;
struct gdb_output_vector * error;
struct gdb_output_vector * info;
struct gdb_output_vector * value;
@}
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
Execute @var{command}, temporarily using the i/o vectors in @var{vecs}.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Any of the vectors may be NULL, indicating that the current value should
be used. An error handler must be in place when this function is used.
1993-10-04 17:44:52 +00:00
@end deftypefun
1993-10-25 19:40:46 +00:00
@deftypefun {struct gdb_str_output} gdb_execute_for_strings (@var{cmd})
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
char * cmd;
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
@deftypefunx {struct gdb_str_output} gdb_execute_for_strings2 (@var{cmd}, @var{input})
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
char * cmd;
struct gdb_input_vector * input;
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
@page
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
struct gdb_str_output
@{
char * error;
char * info;
char * value;
@};
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
Execute @var{cmd}, collecting its output as strings. If no error
occurs, all three strings will be present in the structure, the
empty-string rather than NULL standing for no output of a particular
kind.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
If the command aborts with an error, then the @code{value} field will be
NULL, though the other two strings will be present.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
In all cases, the strings returned are allocated by malloc and should be
freed by the caller.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
The first form listed uses the current input vector, but overrides the
current output vector. The second form additionally allows the input
vector to be overridden.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
This function does not require that an error handler be installed.
@end deftypefun
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@deftypefun void execute_catching_errors (@var{command})
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
char * @var{command};
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
Like @code{execute_command} except that no error handler is required.
1993-10-04 17:44:52 +00:00
@end deftypefun
1993-10-25 19:40:46 +00:00
@deftypefun void execute_with_text (@var{command}, @var{text})
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
char * @var{command};
char ** @var{text};
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
Like @code{execute_catching_errors}, except that the input vector is
overridden. The new input vector handles only calls to @code{query} (by
returning 'y') and calls to @code{read_strings} by returning a copy of
@var{text} and the strings it points to.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
This form of execute_command is useful for commands like @code{define},
@code{document}, and @code{commands}.
1993-10-04 17:44:52 +00:00
@end deftypefun
1993-10-25 19:40:46 +00:00
@node Defining Commands, Variables, Invoking, Top
@comment node-name, next, previous, up
@chapter How New Commands are Created
@cindex {commands, defining}
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Applications are, of course, free to take advantage of the existing GDB
macro definition capability (the @code{define} and @code{document}
functions).
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
In addition, an application can add new primitives to the GDB command
language.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@deftypefun void gdb_define_app_command (@var{name}, @var{fn}, @var{doc})
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
char * @var{name};
gdb_cmd_fn @var{fn};
char * @var{doc};
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
typedef void (*gdb_cmd_fn) (char * args);
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
Create a new command call @var{name}. The new command is in the
@code{application} help class. When invoked, the command-line arguments
to the command are passed as a single string.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Calling this function twice with the same name replaces an earlier
definition, but application commands can not replace builtin commands of
the same name.
1993-10-04 17:44:52 +00:00
The documentation string of the command is set to a copy the string
@var{doc}.
1993-10-04 17:44:52 +00:00
@end deftypefun
1993-10-25 19:40:46 +00:00
@node Variables, Asynchronous, Defining Commands, Top
@comment node-name, next, previous, up
@chapter How Builtin Variables are Defined
@cindex {variables, defining}
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Convenience variables provide a way for values maintained by libgdb to
be referenced in expressions (e.g. @code{$bpnum}). Libgdb includes a
means by which the application can define new, integer valued
convenience variables:
@page
@deftypefun void gdb_define_int_var (@var{name}, @var{fn}, @var{fn_arg})
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
char * @var{name};
int (*@var{fn}) (void *);
void * @var{fn_arg};
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
This function defines (or undefines) a convenience variable called @var{name}.
If @var{fn} is NULL, the variable becomes undefined. Otherwise,
@var{fn} is a function which, when passed @var{fn_arg} returns the value
of the newly defined variable.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
No libgdb functions should be called by @var{fn}.
1993-10-04 17:44:52 +00:00
@end deftypefun
1993-10-25 19:40:46 +00:00
One use for this function is to create breakpoint conditions computed in
novel ways. This is done by defining a convenience variable and
referring to that variable in a breakpoint condition expression.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@node Asynchronous, Commands, Variables, Top
@chapter Scheduling Asynchronous Computations
@cindex asynchronous
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
A running libgdb function can take a long time. Libgdb includes a hook
so that an application can run intermittently during long debugger
operations.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@deftypefun void gdb_set_poll_fn (@var{fn}, @var{fn_arg})
@example
void (*@var{fn})(void * fn_arg, int (*gdb_poll)());
void * @var{fn_arg};
@end example
Arrange to call @var{fn} periodically during lengthy debugger operations.
If @var{fn} is NULL, polling is turned off. @var{fn} should take two
arguments: an opaque pointer passed as @var{fn_arg} to
@code{gdb_set_poll_fn}, and a function pointer. The function pointer
passed to @var{fn} is provided by libgdb and points to a function that
returns 0 when the poll function should return. That is, when
@code{(*gdb_poll)()} returns 0, libgdb is ready to continue @var{fn}
should return quickly.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
It is possible that @code{(*gdb_poll)()} will return 0 the first time it
is called, so it is reasonable for an application to do minimal processing
before checking whether to return.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
No libgdb functions should be called from an application's poll function,
with one exception: @code{gdb_request_quit}.
1993-10-04 17:44:52 +00:00
@end deftypefun
1993-10-25 19:40:46 +00:00
@deftypefun void gdb_request_quit (void)
This function, if called from a poll function, requests that the
currently executing libgdb command be interrupted as soon as possible,
and that control be returned to the top-level via an error.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
The quit is not immediate. It will not occur until at least after the
application's poll function returns.
@end deftypefun
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@node Commands, Top, Asynchronous, Top
@comment node-name, next, previous, up
@chapter Debugger Commands for Libgdb Applications
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
The debugger commands available to libgdb applications are the same commands
available interactively via GDB. This section is an overview of the
commands newly created as part of libgdb.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
This section is not by any means a complete reference to the GDB command
language. See the GDB manual for such a reference.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@menu
* Command Hooks:: Setting Hooks to Execute With Debugger Commands.
* View Commands:: View Commands Mirror Show Commands
* Breakpoints:: The Application Can Have Its Own Breakpoints
@end menu
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@node Command Hooks, View Commands, Commands, Commands
@comment node-name, next, previous, up
@section Setting Hooks to Execute With Debugger Commands.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Debugger commands support hooks. A command hook is executed just before
the interpreter invokes the hooked command.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
There are two hooks allowed for every command. By convention, one hook
is for use by users, the other is for use by the application.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
A user hook is created for a command XYZZY by using
@code{define-command} to create a command called @code{hook-XYZZY}.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
An application hook is created for a command XYZZY by using
@code{define-command} to create a command called @code{apphook-XYZZY}.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Application hooks are useful for interfaces which wish to continuously
monitor certain aspects of debugger state. The application can set a
hook on all commands that might modify the watched state. When the hook
is executed, it can use i/o redirection to notify parts of the
application that previous data may be out of date. After the top-level loop
resumes, the application can recompute any values that may have changed.
(@xref{I/O}.)
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@node View Commands, Breakpoints, Command Hooks, Commands
@comment node-name, next, previous, up
@section View Commands Mirror Show Commands
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
The GDB command language contains many @code{set} and @code{show}
commands. These commands are used to modify or examine parameters to
the debugger.
1993-10-04 17:44:52 +00:00
It is difficult to get the current state of a parameter from the
1993-10-25 19:40:46 +00:00
@code{show} command because @code{show} is very verbose.
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
(gdb) show check type
Type checking is "auto; currently off".
(gdb) show width
Number of characters gdb thinks are in a line is 80.
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
For every @code{show} command, libgdb includes a @code{view} command.
@code{view} is like @code{show} without the verbose commentary:
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
(gdb) view check type
auto; currently off
(gdb) view width
80
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
(The precise format of the ouput from @code{view} is subject to change.
In particular, @code{view} may one-day print values which can be used as
arguments to the corresponding @code{set} command.)
@node Breakpoints, Structured Output, View Commands, Commands
@comment node-name, next, previous, up
@section The Application Can Have Its Own Breakpoints
The GDB breakpoint commands were written with a strong presumption that
all breakpoints are managed by a human user. Therefore, the command
language contains commands like `delete' which affect all breakpoints
without discrimination.
In libgdb, there is added support for breakpoints and watchpoints which
are set by the application and which should not be affected by ordinary,
indiscriminate commands. These are called @dfn{protected} breakpoints.
@deffn {Debugger Command} break-protected ...
@deffnx {Debugger Command} watch-protected ...
These work like @code{break} and @code{watch} except that the resulting
breakpoint is given a negative number. Negative numbered breakpoints do
not appear in the output of @code{info breakpoints} but do in that of
@code{info all-breakpoints}. Negative numbered breakpoints are not
affected by commands which ordinarily affect `all' breakpoints (e.g.
@code{delete} with no arguments).
Note that libgdb itself creates protected breakpoints, so programs
should not rely on being able to allocate particular protected
breakpoint numbers for themselves.
@end deffn
More than one breakpoint may be set at a given location. Libgdb adds
the concept of @dfn{priority} to breakpoints. A priority is an integer,
assigned to each breakpoint. When a breakpoint is reached, the
conditions of all breakpoints at the same location are evaluated in
order of ascending priority. When breakpoint commands are executed,
they are also executed in ascending priority (until all have been
executed, an error occurs, or one set of commands continues the
target).
@deffn {Debugger Command} priority n bplist
Set the priority for breakpoints @var{bplist} to @var{n}.
By default, breakpoints are assigned a priority of zero.
@end deffn
@node Structured Output, Commands, Breakpoints, Commands
@comment node-name, next, previous, up
@section Structured Output, The @code{Explain} Command
(This section may be subject to considerable revision.)
When GDB prints a the value of an expression, the printed representation
contains information that can be usefully fed back into future commands
and expressions. For example,
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
(gdb) print foo
$16 = @{v = 0x38ae0, v_length = 40@}
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
On the basis of this output, a user knows, for example, that
@code{$16.v} refers to a pointer valued @code{0x38ae0}
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
A new output command helps to make information like this available to
the application.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@deffn {Debugger Command} explain expression
@deffnx {Debugger Command} explain /format expression
Print the value of @var{expression} in the manner of the @code{print}
command, but embed that output in a list syntax containing information
about the structure of the output.
@end deffn
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
As an example, @code{explain argv} might produce this output:
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
(exp-attribute
((expression "$19")
(type "char **")
(address "48560")
(deref-expression "*$19"))
"$19 = 0x3800\n")
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
The syntax of output from @code{explain} is:
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
<explanation> := <quoted-string>
| (exp-concat <explanation> <explanation>*)
| (exp-attribute <property-list> <explanation>)
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
<property-list> := ( <property-pair>* )
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
<property-pair> := ( <property-name> <quoted-string> )
@end example
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
The string-concatenation of all of the @code{<quoted-string>} (except
those in property lists) yields the output generated by the equivalent
@code{print} command. Quoted strings may contain quotes and backslashes
if they are escaped by backslash. "\n" in a quoted string stands for
newline; unescaped newlines do not occur within the strings output by
@code{explain}.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Property names are made up of alphabetic characters, dashes, and
underscores.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
The set of properties is open-ended. As GDB acquires support for new
source languages and other new capabilities, new property types may be
added to the output of this command. Future commands may offer
applications some selectivity concerning which properties are reported.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
The initial set of properties defined includes:
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@itemize @bullet
@item @code{expression}
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
This is an expression, such as @code{$42} or @code{$42.x}. The
expression can be used to refer to the value printed in the attributed
part of the string.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@item @code{type}
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
This is a user-readable name for the type of the attributed value.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@item @code{address}
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
If the value is stored in a target register, this is a register number.
If the value is stored in a GDB convenience variable, this is an integer
that is unique among all the convenience variables. Otherwise, this is
the address in the target where the value is stored.
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
@item @code{deref-expression}
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
If the attributed value is a pointer type, this is an expression that
refers to the dereferenced value.
@end itemize
1993-10-04 17:44:52 +00:00
1993-10-25 19:40:46 +00:00
Here is a larger example, using the same object passed to @code{print}
in an earlier example of this section.
1993-10-04 17:44:52 +00:00
@example
1993-10-25 19:40:46 +00:00
(gdb) explain foo
(exp-attribute
( (expression "$16")
(type "struct bytecode_vector")
(address 14336) )
(exp-concat
"$16 = @{"
1993-10-25 19:40:46 +00:00
(exp-attribute
( (expression "$16.v")
1993-10-25 19:40:46 +00:00
(type "char *")
(address 14336)
(deref-expression "*$16.v") )
1993-10-25 19:40:46 +00:00
"v = 0x38ae0")
(exp-attribute
( (expression "$16.v_length")
1993-10-25 19:40:46 +00:00
(type "int")
(address 14340) )
", v_length = 40")
"@}\n"))
1993-10-04 17:44:52 +00:00
@end example
1993-10-25 19:40:46 +00:00
It is undefined how libgdb will indent these lines of output or
where newlines will be included.
1993-10-04 17:44:52 +00:00
1993-10-06 20:24:03 +00:00
@bye