Add translations for various sub-directories
[binutils-gdb.git] / gdb / doc / guile.texi
blobf1b638ee7e34dfaec52b8d2251a4511f827e7209
1 @c Copyright (C) 2008--2024 Free Software Foundation, Inc.
2 @c Permission is granted to copy, distribute and/or modify this document
3 @c under the terms of the GNU Free Documentation License, Version 1.3 or
4 @c any later version published by the Free Software Foundation; with the
5 @c Invariant Sections being ``Free Software'' and ``Free Software Needs
6 @c Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
7 @c and with the Back-Cover Texts as in (a) below.
8 @c 
9 @c (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
10 @c this GNU Manual.  Buying copies from GNU Press supports the FSF in
11 @c developing GNU and promoting software freedom.''
13 @node Guile
14 @section Extending @value{GDBN} using Guile
15 @cindex guile scripting
16 @cindex scripting with guile
18 You can extend @value{GDBN} using the @uref{http://www.gnu.org/software/guile/,
19 Guile implementation of the Scheme programming language}.
20 This feature is available only if @value{GDBN} was configured using
21 @option{--with-guile}.
23 @menu
24 * Guile Introduction::     Introduction to Guile scripting in @value{GDBN}
25 * Guile Commands::         Accessing Guile from @value{GDBN}
26 * Guile API::              Accessing @value{GDBN} from Guile
27 * Guile Auto-loading::     Automatically loading Guile code
28 * Guile Modules::          Guile modules provided by @value{GDBN}
29 @end menu
31 @node Guile Introduction
32 @subsection Guile Introduction
34 Guile is an implementation of the Scheme programming language
35 and is the GNU project's official extension language.
37 Guile support in @value{GDBN} follows the Python support in @value{GDBN}
38 reasonably closely, so concepts there should carry over.
39 However, some things are done differently where it makes sense.
41 @value{GDBN} requires Guile version 3.0, 2.2, or 2.0.
43 @cindex guile scripts directory
44 Guile scripts used by @value{GDBN} should be installed in
45 @file{@var{data-directory}/guile}, where @var{data-directory} is
46 the data directory as determined at @value{GDBN} startup (@pxref{Data Files}).
47 This directory, known as the @dfn{guile directory},
48 is automatically added to the Guile Search Path in order to allow
49 the Guile interpreter to locate all scripts installed at this location.
51 @node Guile Commands
52 @subsection Guile Commands
53 @cindex guile commands
54 @cindex commands to access guile
56 @value{GDBN} provides two commands for accessing the Guile interpreter:
58 @table @code
59 @kindex guile-repl
60 @kindex gr
61 @item guile-repl
62 @itemx gr
63 The @code{guile-repl} command can be used to start an interactive
64 Guile prompt or @dfn{repl}.  To return to @value{GDBN},
65 type @kbd{,q} or the @code{EOF} character (e.g., @kbd{Ctrl-D} on
66 an empty prompt).  These commands do not take any arguments.
68 @kindex guile
69 @kindex gu
70 @item guile @r{[}@var{scheme-expression}@r{]}
71 @itemx gu @r{[}@var{scheme-expression}@r{]}
72 The @code{guile} command can be used to evaluate a Scheme expression.
74 If given an argument, @value{GDBN} will pass the argument to the Guile
75 interpreter for evaluation.
77 @smallexample
78 (@value{GDBP}) guile (display (+ 20 3)) (newline)
80 @end smallexample
82 The result of the Scheme expression is displayed using normal Guile rules.
84 @smallexample
85 (@value{GDBP}) guile (+ 20 3)
87 @end smallexample
89 If you do not provide an argument to @code{guile}, it will act as a
90 multi-line command, like @code{define}.  In this case, the Guile
91 script is made up of subsequent command lines, given after the
92 @code{guile} command.  This command list is terminated using a line
93 containing @code{end}.  For example:
95 @smallexample
96 (@value{GDBP}) guile
97 >(display 23)
98 >(newline)
99 >end
101 @end smallexample
102 @end table
104 It is also possible to execute a Guile script from the @value{GDBN}
105 interpreter:
107 @table @code
108 @item source @file{script-name}
109 The script name must end with @samp{.scm} and @value{GDBN} must be configured
110 to recognize the script language based on filename extension using
111 the @code{script-extension} setting.  @xref{Extending GDB, ,Extending GDB}.
113 @item guile (load "script-name")
114 This method uses the @code{load} Guile function.
115 It takes a string argument that is the name of the script to load.
116 See the Guile documentation for a description of this function.
117 (@pxref{Loading,,, guile, GNU Guile Reference Manual}).
118 @end table
120 @node Guile API
121 @subsection Guile API
122 @cindex guile api
123 @cindex programming in guile
125 You can get quick online help for @value{GDBN}'s Guile API by issuing
126 the command @w{@kbd{help guile}}, or by issuing the command @kbd{,help}
127 from an interactive Guile session.  Furthermore, most Guile procedures
128 provided by @value{GDBN} have doc strings which can be obtained with
129 @kbd{,describe @var{procedure-name}} or @kbd{,d @var{procedure-name}}
130 from the Guile interactive prompt.
132 @menu
133 * Basic Guile::              Basic Guile Functions
134 * Guile Configuration::      Guile configuration variables
135 * GDB Scheme Data Types::    Scheme representations of GDB objects
136 * Guile Exception Handling:: How Guile exceptions are translated
137 * Values From Inferior In Guile:: Guile representation of values
138 * Arithmetic In Guile::      Arithmetic in Guile
139 * Types In Guile::           Guile representation of types
140 * Guile Pretty Printing API:: Pretty-printing values with Guile
141 * Selecting Guile Pretty-Printers:: How GDB chooses a pretty-printer
142 * Writing a Guile Pretty-Printer:: Writing a pretty-printer
143 * Commands In Guile::        Implementing new commands in Guile
144 * Parameters In Guile::      Adding new @value{GDBN} parameters
145 * Progspaces In Guile::      Program spaces
146 * Objfiles In Guile::        Object files in Guile
147 * Frames In Guile::          Accessing inferior stack frames from Guile
148 * Blocks In Guile::          Accessing blocks from Guile
149 * Symbols In Guile::         Guile representation of symbols
150 * Symbol Tables In Guile::   Guile representation of symbol tables
151 * Breakpoints In Guile::     Manipulating breakpoints using Guile
152 * Lazy Strings In Guile::    Guile representation of lazy strings
153 * Architectures In Guile::   Guile representation of architectures
154 * Disassembly In Guile::     Disassembling instructions from Guile
155 * I/O Ports in Guile::       GDB I/O ports
156 * Memory Ports in Guile::    Accessing memory through ports and bytevectors
157 * Iterators In Guile::       Basic iterator support
158 * Colors In Guile::          Colorize output with Guile
159 @end menu
161 @node Basic Guile
162 @subsubsection Basic Guile
164 @cindex guile stdout
165 @cindex guile pagination
166 At startup, @value{GDBN} overrides Guile's @code{current-output-port} and
167 @code{current-error-port} to print using @value{GDBN}'s output-paging streams.
168 A Guile program which outputs to one of these streams may have its
169 output interrupted by the user (@pxref{Screen Size}).  In this
170 situation, a Guile @code{signal} exception is thrown with value @code{SIGINT}.
172 Guile's history mechanism uses the same naming as @value{GDBN}'s,
173 namely the user of dollar-variables (e.g., $1, $2, etc.).
174 The results of evaluations in Guile and in GDB are counted separately,
175 @code{$1} in Guile is not the same value as @code{$1} in @value{GDBN}.
177 @value{GDBN} is not thread-safe.  If your Guile program uses multiple
178 threads, you must be careful to only call @value{GDBN}-specific
179 functions in the @value{GDBN} thread.
181 Some care must be taken when writing Guile code to run in
182 @value{GDBN}.  Two things are worth noting in particular:
184 @itemize @bullet
185 @item
186 @value{GDBN} installs handlers for @code{SIGCHLD} and @code{SIGINT}.
187 Guile code must not override these, or even change the options using
188 @code{sigaction}.  If your program changes the handling of these
189 signals, @value{GDBN} will most likely stop working correctly.  Note
190 that it is unfortunately common for GUI toolkits to install a
191 @code{SIGCHLD} handler.
193 @item
194 @value{GDBN} takes care to mark its internal file descriptors as
195 close-on-exec.  However, this cannot be done in a thread-safe way on
196 all platforms.  Your Guile programs should be aware of this and
197 should both create new file descriptors with the close-on-exec flag
198 set and arrange to close unneeded file descriptors before starting a
199 child process.
200 @end itemize
202 @cindex guile gdb module
203 @value{GDBN} introduces a new Guile module, named @code{gdb}.  All
204 methods and classes added by @value{GDBN} are placed in this module.
205 @value{GDBN} does not automatically @code{import} the @code{gdb} module,
206 scripts must do this themselves.  There are various options for how to
207 import a module, so @value{GDBN} leaves the choice of how the @code{gdb}
208 module is imported to the user.
209 To simplify interactive use, it is recommended to add one of the following
210 to your ~/.gdbinit.
212 @smallexample
213 guile (use-modules (gdb))
214 @end smallexample
216 @smallexample
217 guile (use-modules ((gdb) #:renamer (symbol-prefix-proc 'gdb:)))
218 @end smallexample
220 Which one to choose depends on your preference.
221 The second one adds @code{gdb:} as a prefix to all module functions
222 and variables.
224 The rest of this manual assumes the @code{gdb} module has been imported
225 without any prefix.  See the Guile documentation for @code{use-modules}
226 for more information
227 (@pxref{Using Guile Modules,,, guile, GNU Guile Reference Manual}).
229 Example:
231 @smallexample
232 (gdb) guile (value-type (make-value 1))
233 ERROR: Unbound variable: value-type
234 Error while executing Scheme code.
235 (gdb) guile (use-modules (gdb))
236 (gdb) guile (value-type (make-value 1))
238 (gdb)
239 @end smallexample
241 The @code{(gdb)} module provides these basic Guile functions.
243 @deffn {Scheme Procedure} execute command @w{@r{[}#:from-tty boolean@r{]}} @
244     @w{@r{[}#:to-string boolean@r{]}}
245 Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
246 If a @value{GDBN} exception happens while @var{command} runs, it is
247 translated as described in
248 @ref{Guile Exception Handling,,Guile Exception Handling}.
250 @var{from-tty} specifies whether @value{GDBN} ought to consider this
251 command as having originated from the user invoking it interactively.
252 It must be a boolean value.  If omitted, it defaults to @code{#f}.
254 By default, any output produced by @var{command} is sent to
255 @value{GDBN}'s standard output (and to the log output if logging is
256 turned on).  If the @var{to-string} parameter is
257 @code{#t}, then output will be collected by @code{execute} and
258 returned as a string.  The default is @code{#f}, in which case the
259 return value is unspecified.  If @var{to-string} is @code{#t}, the
260 @value{GDBN} virtual terminal will be temporarily set to unlimited width
261 and height, and its pagination will be disabled; @pxref{Screen Size}.
262 @end deffn
264 @deffn {Scheme Procedure} history-ref number
265 Return a value from @value{GDBN}'s value history (@pxref{Value
266 History}).  The @var{number} argument indicates which history element to return.
267 If @var{number} is negative, then @value{GDBN} will take its absolute value
268 and count backward from the last element (i.e., the most recent element) to
269 find the value to return.  If @var{number} is zero, then @value{GDBN} will
270 return the most recent element.  If the element specified by @var{number}
271 doesn't exist in the value history, a @code{gdb:error} exception will be
272 raised.
274 If no exception is raised, the return value is always an instance of
275 @code{<gdb:value>} (@pxref{Values From Inferior In Guile}).
277 @emph{Note:} @value{GDBN}'s value history is independent of Guile's.
278 @code{$1} in @value{GDBN}'s value history contains the result of evaluating
279 an expression from @value{GDBN}'s command line and @code{$1} from Guile's
280 history contains the result of evaluating an expression from Guile's
281 command line.
282 @end deffn
284 @deffn {Scheme Procedure} history-append! value
285 Append @var{value}, an instance of @code{<gdb:value>}, to @value{GDBN}'s
286 value history.  Return its index in the history.
288 Putting into history values returned by Guile extensions will allow
289 the user convenient access to those values via CLI history
290 facilities.
291 @end deffn
293 @deffn {Scheme Procedure} parse-and-eval expression
294 Parse @var{expression} as an expression in the current language,
295 evaluate it, and return the result as a @code{<gdb:value>}.
296 The @var{expression} must be a string.
298 This function can be useful when implementing a new command
299 (@pxref{Commands In Guile}), as it provides a way to parse the
300 command's arguments as an expression.
301 It is also is useful when computing values.
302 For example, it is the only way to get the value of a
303 convenience variable (@pxref{Convenience Vars}) as a @code{<gdb:value>}.
304 @end deffn
306 @node Guile Configuration
307 @subsubsection Guile Configuration
308 @cindex guile configuration
310 @value{GDBN} provides these Scheme functions to access various configuration
311 parameters.
313 @deffn {Scheme Procedure} data-directory
314 Return a string containing @value{GDBN}'s data directory.
315 This directory contains @value{GDBN}'s ancillary files.
316 @end deffn
318 @deffn {Scheme Procedure} guile-data-directory
319 Return a string containing @value{GDBN}'s Guile data directory.
320 This directory contains the Guile modules provided by @value{GDBN}.
321 @end deffn
323 @deffn {Scheme Procedure} gdb-version
324 Return a string containing the @value{GDBN} version.
325 @end deffn
327 @deffn {Scheme Procedure} host-config
328 Return a string containing the host configuration.
329 This is the string passed to @code{--host} when @value{GDBN} was configured.
330 @end deffn
332 @deffn {Scheme Procedure} target-config
333 Return a string containing the target configuration.
334 This is the string passed to @code{--target} when @value{GDBN} was configured.
335 @end deffn
337 @node GDB Scheme Data Types
338 @subsubsection GDB Scheme Data Types
339 @cindex gdb objects
341 The values exposed by @value{GDBN} to Guile are known as
342 @dfn{@value{GDBN} objects}.  There are several kinds of @value{GDBN}
343 object, and each is disjoint from all other types known to Guile.
345 @deffn {Scheme Procedure} gdb-object-kind object
346 Return the kind of the @value{GDBN} object, e.g., @code{<gdb:breakpoint>},
347 as a symbol.
348 @end deffn
350 @value{GDBN} defines the following object types:
352 @table @code
353 @item <gdb:arch>
354 @xref{Architectures In Guile}.
356 @item <gdb:block>
357 @xref{Blocks In Guile}.
359 @item <gdb:block-symbols-iterator>
360 @xref{Blocks In Guile}.
362 @item <gdb:breakpoint>
363 @xref{Breakpoints In Guile}.
365 @item <gdb:command>
366 @xref{Commands In Guile}.
368 @item <gdb:exception>
369 @xref{Guile Exception Handling}.
371 @item <gdb:frame>
372 @xref{Frames In Guile}.
374 @item <gdb:iterator>
375 @xref{Iterators In Guile}.
377 @item <gdb:lazy-string>
378 @xref{Lazy Strings In Guile}.
380 @item <gdb:objfile>
381 @xref{Objfiles In Guile}.
383 @item <gdb:parameter>
384 @xref{Parameters In Guile}.
386 @item <gdb:pretty-printer>
387 @xref{Guile Pretty Printing API}.
389 @item <gdb:pretty-printer-worker>
390 @xref{Guile Pretty Printing API}.
392 @item <gdb:progspace>
393 @xref{Progspaces In Guile}.
395 @item <gdb:symbol>
396 @xref{Symbols In Guile}.
398 @item <gdb:symtab>
399 @xref{Symbol Tables In Guile}.
401 @item <gdb:sal>
402 @xref{Symbol Tables In Guile}.
404 @item <gdb:type>
405 @xref{Types In Guile}.
407 @item <gdb:field>
408 @xref{Types In Guile}.
410 @item <gdb:value>
411 @xref{Values From Inferior In Guile}.
413 @item <gdb:color>
414 @xref{Colors In Guile}.
415 @end table
417 The following @value{GDBN} objects are managed internally so that the
418 Scheme function @code{eq?} may be applied to them.
420 @table @code
421 @item <gdb:arch>
422 @item <gdb:block>
423 @item <gdb:breakpoint>
424 @item <gdb:frame>
425 @item <gdb:objfile>
426 @item <gdb:progspace>
427 @item <gdb:symbol>
428 @item <gdb:symtab>
429 @item <gdb:type>
430 @end table
432 @node Guile Exception Handling
433 @subsubsection Guile Exception Handling
434 @cindex guile exceptions
435 @cindex exceptions, guile
436 @kindex set guile print-stack
438 When executing the @code{guile} command, Guile exceptions
439 uncaught within the Guile code are translated to calls to the
440 @value{GDBN} error-reporting mechanism.  If the command that called
441 @code{guile} does not handle the error, @value{GDBN} will
442 terminate it and report the error according to the setting of
443 the @code{guile print-stack} parameter.
445 The @code{guile print-stack} parameter has three settings:
447 @table @code
448 @item none
449 Nothing is printed.
451 @item message
452 An error message is printed containing the Guile exception name,
453 the associated value, and the Guile call stack backtrace at the
454 point where the exception was raised.  Example:
456 @smallexample
457 (@value{GDBP}) guile (display foo)
458 ERROR: In procedure memoize-variable-access!:
459 ERROR: Unbound variable: foo
460 Error while executing Scheme code.
461 @end smallexample
463 @item full
464 In addition to an error message a full backtrace is printed.
466 @smallexample
467 (@value{GDBP}) set guile print-stack full
468 (@value{GDBP}) guile (display foo)
469 Guile Backtrace:
470 In ice-9/boot-9.scm:
471  157: 10 [catch #t #<catch-closure 2c76e20> ...]
472 In unknown file:
473    ?: 9 [apply-smob/1 #<catch-closure 2c76e20>]
474 In ice-9/boot-9.scm:
475  157: 8 [catch #t #<catch-closure 2c76d20> ...]
476 In unknown file:
477    ?: 7 [apply-smob/1 #<catch-closure 2c76d20>]
478    ?: 6 [call-with-input-string "(display foo)" ...]
479 In ice-9/boot-9.scm:
480 2320: 5 [save-module-excursion #<procedure 2c2dc30 ... ()>]
481 In ice-9/eval-string.scm:
482   44: 4 [read-and-eval #<input: string 27cb410> #:lang ...]
483   37: 3 [lp (display foo)]
484 In ice-9/eval.scm:
485  387: 2 [eval # ()]
486  393: 1 [eval #<memoized foo> ()]
487 In unknown file:
488    ?: 0 [memoize-variable-access! #<memoized foo> ...]
490 ERROR: In procedure memoize-variable-access!:
491 ERROR: Unbound variable: foo
492 Error while executing Scheme code.
493 @end smallexample
494 @end table
496 @value{GDBN} errors that happen in @value{GDBN} commands invoked by
497 Guile code are converted to Guile exceptions.  The type of the
498 Guile exception depends on the error.
500 Guile procedures provided by @value{GDBN} can throw the standard
501 Guile exceptions like @code{wrong-type-arg} and @code{out-of-range}.
503 User interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
504 prompt) is translated to a Guile @code{signal} exception with value
505 @code{SIGINT}.
507 @value{GDBN} Guile procedures can also throw these exceptions:
509 @vtable @code
510 @item gdb:error
511 This exception is a catch-all for errors generated from within @value{GDBN}.
513 @item gdb:invalid-object
514 This exception is thrown when accessing Guile objects that wrap underlying
515 @value{GDBN} objects have become invalid.  For example, a
516 @code{<gdb:breakpoint>} object becomes invalid if the user deletes it
517 from the command line.  The object still exists in Guile, but the
518 object it represents is gone.  Further operations on this breakpoint
519 will throw this exception.
521 @item gdb:memory-error
522 This exception is thrown when an operation tried to access invalid
523 memory in the inferior.
525 @item gdb:pp-type-error
526 This exception is thrown when a Guile pretty-printer passes a bad object
527 to @value{GDBN}.
528 @end vtable
530 The following exception-related procedures are provided by the
531 @code{(gdb)} module.
533 @deffn {Scheme Procedure} make-exception key args
534 Return a @code{<gdb:exception>} object given by its @var{key} and
535 @var{args}, which are the standard Guile parameters of an exception.
536 See the Guile documentation for more information (@pxref{Exceptions,,,
537 guile, GNU Guile Reference Manual}).
538 @end deffn
540 @deffn {Scheme Procedure} exception? object
541 Return @code{#t} if @var{object} is a @code{<gdb:exception>} object.
542 Otherwise return @code{#f}.
543 @end deffn
545 @deffn {Scheme Procedure} exception-key exception
546 Return the @var{args} field of a @code{<gdb:exception>} object.
547 @end deffn
549 @deffn {Scheme Procedure} exception-args exception
550 Return the @var{args} field of a @code{<gdb:exception>} object.
551 @end deffn
553 @node Values From Inferior In Guile
554 @subsubsection Values From Inferior In Guile
555 @cindex values from inferior, in guile
556 @cindex guile, working with values from inferior
558 @tindex @code{<gdb:value>}
559 @value{GDBN} provides values it obtains from the inferior program in
560 an object of type @code{<gdb:value>}.  @value{GDBN} uses this object
561 for its internal bookkeeping of the inferior's values, and for
562 fetching values when necessary.
564 @value{GDBN} does not memoize @code{<gdb:value>} objects.
565 @code{make-value} always returns a fresh object.
567 @smallexample
568 (gdb) guile (eq? (make-value 1) (make-value 1))
569 $1 = #f
570 (gdb) guile (equal? (make-value 1) (make-value 1))
571 $1 = #t
572 @end smallexample
574 A @code{<gdb:value>} that represents a function can be executed via
575 inferior function call with @code{value-call}.
576 Any arguments provided to the call must match the function's prototype,
577 and must be provided in the order specified by that prototype.
579 For example, @code{some-val} is a @code{<gdb:value>} instance
580 representing a function that takes two integers as arguments.  To
581 execute this function, call it like so:
583 @smallexample
584 (define result (value-call some-val 10 20))
585 @end smallexample
587 Any values returned from a function call are @code{<gdb:value>} objects.
589 Note: Unlike Python scripting in @value{GDBN},
590 inferior values that are simple scalars cannot be used directly in
591 Scheme expressions that are valid for the value's data type.
592 For example, @code{(+ (parse-and-eval "int_variable") 2)} does not work.
593 And inferior values that are structures or instances of some class cannot
594 be accessed using any special syntax, instead @code{value-field} must be used.
596 The following value-related procedures are provided by the
597 @code{(gdb)} module.
599 @deffn {Scheme Procedure} value? object
600 Return @code{#t} if @var{object} is a @code{<gdb:value>} object.
601 Otherwise return @code{#f}.
602 @end deffn
604 @deffn {Scheme Procedure} make-value value @r{[}#:type type@r{]}
605 Many Scheme values can be converted directly to a @code{<gdb:value>}
606 with this procedure.  If @var{type} is specified, the result is a value
607 of this type, and if @var{value} can't be represented with this type
608 an exception is thrown.  Otherwise the type of the result is determined from
609 @var{value} as described below.
611 @xref{Architectures In Guile}, for a list of the builtin
612 types for an architecture.
614 Here's how Scheme values are converted when @var{type} argument to
615 @code{make-value} is not specified:
617 @table @asis
618 @item Scheme boolean
619 A Scheme boolean is converted the boolean type for the current language.
621 @item Scheme integer
622 A Scheme integer is converted to the first of a C @code{int},
623 @code{unsigned int}, @code{long}, @code{unsigned long},
624 @code{long long} or @code{unsigned long long} type
625 for the current architecture that can represent the value.
627 If the Scheme integer cannot be represented as a target integer
628 an @code{out-of-range} exception is thrown.
630 @item Scheme real
631 A Scheme real is converted to the C @code{double} type for the
632 current architecture.
634 @item Scheme string
635 A Scheme string is converted to a string in the current target
636 language using the current target encoding.
637 Characters that cannot be represented in the current target encoding
638 are replaced with the corresponding escape sequence.  This is Guile's
639 @code{SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE} conversion strategy
640 (@pxref{Strings,,, guile, GNU Guile Reference Manual}).
642 Passing @var{type} is not supported in this case,
643 if it is provided a @code{wrong-type-arg} exception is thrown.
645 @item @code{<gdb:lazy-string>}
646 If @var{value} is a @code{<gdb:lazy-string>} object (@pxref{Lazy Strings In
647 Guile}), then the @code{lazy-string->value} procedure is called, and
648 its result is used.
650 Passing @var{type} is not supported in this case,
651 if it is provided a @code{wrong-type-arg} exception is thrown.
653 @item Scheme bytevector
654 If @var{value} is a Scheme bytevector and @var{type} is provided,
655 @var{value} must be the same size, in bytes, of values of type @var{type},
656 and the result is essentially created by using @code{memcpy}.
658 If @var{value} is a Scheme bytevector and @var{type} is not provided,
659 the result is an array of type @code{uint8} of the same length.
660 @end table
661 @end deffn
663 @cindex optimized out value in guile
664 @deffn {Scheme Procedure} value-optimized-out? value
665 Return @code{#t} if the compiler optimized out @var{value},
666 thus it is not available for fetching from the inferior.
667 Otherwise return @code{#f}.
668 @end deffn
670 @deffn {Scheme Procedure} value-address value
671 If @var{value} is addressable, returns a
672 @code{<gdb:value>} object representing the address.
673 Otherwise, @code{#f} is returned.
674 @end deffn
676 @deffn {Scheme Procedure} value-type value
677 Return the type of @var{value} as a @code{<gdb:type>} object
678 (@pxref{Types In Guile}).
679 @end deffn
681 @deffn {Scheme Procedure} value-dynamic-type value
682 Return the dynamic type of @var{value}.  This uses C@t{++} run-time
683 type information (@acronym{RTTI}) to determine the dynamic type of the
684 value.  If the value is of class type, it will return the class in
685 which the value is embedded, if any.  If the value is of pointer or
686 reference to a class type, it will compute the dynamic type of the
687 referenced object, and return a pointer or reference to that type,
688 respectively.  In all other cases, it will return the value's static
689 type.
691 Note that this feature will only work when debugging a C@t{++} program
692 that includes @acronym{RTTI} for the object in question.  Otherwise,
693 it will just return the static type of the value as in @kbd{ptype foo}.
694 @xref{Symbols, ptype}.
695 @end deffn
697 @deffn {Scheme Procedure} value-cast value type
698 Return a new instance of @code{<gdb:value>} that is the result of
699 casting @var{value} to the type described by @var{type}, which must
700 be a @code{<gdb:type>} object.  If the cast cannot be performed for some
701 reason, this method throws an exception.
702 @end deffn
704 @deffn {Scheme Procedure} value-dynamic-cast value type
705 Like @code{value-cast}, but works as if the C@t{++} @code{dynamic_cast}
706 operator were used.  Consult a C@t{++} reference for details.
707 @end deffn
709 @deffn {Scheme Procedure} value-reinterpret-cast value type
710 Like @code{value-cast}, but works as if the C@t{++} @code{reinterpret_cast}
711 operator were used.  Consult a C@t{++} reference for details.
712 @end deffn
714 @deffn {Scheme Procedure} value-dereference value
715 For pointer data types, this method returns a new @code{<gdb:value>} object
716 whose contents is the object pointed to by @var{value}.  For example, if
717 @code{foo} is a C pointer to an @code{int}, declared in your C program as
719 @smallexample
720 int *foo;
721 @end smallexample
723 @noindent
724 then you can use the corresponding @code{<gdb:value>} to access what
725 @code{foo} points to like this:
727 @smallexample
728 (define bar (value-dereference foo))
729 @end smallexample
731 The result @code{bar} will be a @code{<gdb:value>} object holding the
732 value pointed to by @code{foo}.
734 A similar function @code{value-referenced-value} exists which also
735 returns @code{<gdb:value>} objects corresponding to the values pointed to
736 by pointer values (and additionally, values referenced by reference
737 values).  However, the behavior of @code{value-dereference}
738 differs from @code{value-referenced-value} by the fact that the
739 behavior of @code{value-dereference} is identical to applying the C
740 unary operator @code{*} on a given value.  For example, consider a
741 reference to a pointer @code{ptrref}, declared in your C@t{++} program
744 @smallexample
745 typedef int *intptr;
747 int val = 10;
748 intptr ptr = &val;
749 intptr &ptrref = ptr;
750 @end smallexample
752 Though @code{ptrref} is a reference value, one can apply the method
753 @code{value-dereference} to the @code{<gdb:value>} object corresponding
754 to it and obtain a @code{<gdb:value>} which is identical to that
755 corresponding to @code{val}.  However, if you apply the method
756 @code{value-referenced-value}, the result would be a @code{<gdb:value>}
757 object identical to that corresponding to @code{ptr}.
759 @smallexample
760 (define scm-ptrref (parse-and-eval "ptrref"))
761 (define scm-val (value-dereference scm-ptrref))
762 (define scm-ptr (value-referenced-value scm-ptrref))
763 @end smallexample
765 The @code{<gdb:value>} object @code{scm-val} is identical to that
766 corresponding to @code{val}, and @code{scm-ptr} is identical to that
767 corresponding to @code{ptr}.  In general, @code{value-dereference} can
768 be applied whenever the C unary operator @code{*} can be applied
769 to the corresponding C value.  For those cases where applying both
770 @code{value-dereference} and @code{value-referenced-value} is allowed,
771 the results obtained need not be identical (as we have seen in the above
772 example).  The results are however identical when applied on
773 @code{<gdb:value>} objects corresponding to pointers (@code{<gdb:value>}
774 objects with type code @code{TYPE_CODE_PTR}) in a C/C@t{++} program.
775 @end deffn
777 @deffn {Scheme Procedure} value-referenced-value value
778 For pointer or reference data types, this method returns a new
779 @code{<gdb:value>} object corresponding to the value referenced by the
780 pointer/reference value.  For pointer data types,
781 @code{value-dereference} and @code{value-referenced-value} produce
782 identical results.  The difference between these methods is that
783 @code{value-dereference} cannot get the values referenced by reference
784 values.  For example, consider a reference to an @code{int}, declared
785 in your C@t{++} program as
787 @smallexample
788 int val = 10;
789 int &ref = val;
790 @end smallexample
792 @noindent
793 then applying @code{value-dereference} to the @code{<gdb:value>} object
794 corresponding to @code{ref} will result in an error, while applying
795 @code{value-referenced-value} will result in a @code{<gdb:value>} object
796 identical to that corresponding to @code{val}.
798 @smallexample
799 (define scm-ref (parse-and-eval "ref"))
800 (define err-ref (value-dereference scm-ref))      ;; error
801 (define scm-val (value-referenced-value scm-ref)) ;; ok
802 @end smallexample
804 The @code{<gdb:value>} object @code{scm-val} is identical to that
805 corresponding to @code{val}.
806 @end deffn
808 @deffn {Scheme Procedure} value-reference-value value
809 Return a new @code{<gdb:value>} object which is a reference to the value
810 encapsulated by @code{<gdb:value>} object @var{value}.
811 @end deffn
813 @deffn {Scheme Procedure} value-rvalue-reference-value value
814 Return a new @code{<gdb:value>} object which is an rvalue reference to
815 the value encapsulated by @code{<gdb:value>} object @var{value}.
816 @end deffn
818 @deffn {Scheme Procedure} value-const-value value
819 Return a new @code{<gdb:value>} object which is a @samp{const} version
820 of @code{<gdb:value>} object @var{value}.
821 @end deffn
823 @deffn {Scheme Procedure} value-field value field-name
824 Return field @var{field-name} from @code{<gdb:value>} object @var{value}.
825 @end deffn
827 @deffn {Scheme Procedure} value-subscript value index
828 Return the value of array @var{value} at index @var{index}.
829 The @var{value} argument must be a subscriptable @code{<gdb:value>} object.
830 @end deffn
832 @deffn {Scheme Procedure} value-call value arg-list
833 Perform an inferior function call, taking @var{value} as a pointer
834 to the function to call.
835 Each element of list @var{arg-list} must be a <gdb:value> object or an object
836 that can be converted to a value.
837 The result is the value returned by the function.
838 @end deffn
840 @deffn {Scheme Procedure} value->bool value
841 Return the Scheme boolean representing @code{<gdb:value>} @var{value}.
842 The value must be ``integer like''.  Pointers are ok.
843 @end deffn
845 @deffn {Scheme Procedure} value->integer
846 Return the Scheme integer representing @code{<gdb:value>} @var{value}.
847 The value must be ``integer like''.  Pointers are ok.
848 @end deffn
850 @deffn {Scheme Procedure} value->real
851 Return the Scheme real number representing @code{<gdb:value>} @var{value}.
852 The value must be a number.
853 @end deffn
855 @deffn {Scheme Procedure} value->bytevector
856 Return a Scheme bytevector with the raw contents of @code{<gdb:value>}
857 @var{value}.  No transformation, endian or otherwise, is performed.
858 @end deffn
860 @deffn {Scheme Procedure} value->string value @
861     @w{@r{[}#:encoding encoding@r{]}} @w{@r{[}#:errors errors@r{]}} @
862     @w{@r{[}#:length length@r{]}}
863 If @var{value>} represents a string, then this method
864 converts the contents to a Guile string.  Otherwise, this method will
865 throw an exception.
867 Values are interpreted as strings according to the rules of the
868 current language.  If the optional length argument is given, the
869 string will be converted to that length, and will include any embedded
870 zeroes that the string may contain.  Otherwise, for languages
871 where the string is zero-terminated, the entire string will be
872 converted.
874 For example, in C-like languages, a value is a string if it is a pointer
875 to or an array of characters or ints of type @code{wchar_t}, @code{char16_t},
876 or @code{char32_t}.
878 If the optional @var{encoding} argument is given, it must be a string
879 naming the encoding of the string in the @code{<gdb:value>}, such as
880 @code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}.  It accepts
881 the same encodings as the corresponding argument to Guile's
882 @code{scm_from_stringn} function, and the Guile codec machinery will be used
883 to convert the string.  If @var{encoding} is not given, or if
884 @var{encoding} is the empty string, then either the @code{target-charset}
885 (@pxref{Character Sets}) will be used, or a language-specific encoding
886 will be used, if the current language is able to supply one.
888 The optional @var{errors} argument is one of @code{#f}, @code{error} or
889 @code{substitute}.  @code{error} and @code{substitute} must be symbols.
890 If @var{errors} is not specified, or if its value is @code{#f}, then the
891 default conversion strategy is used, which is set with the Scheme function
892 @code{set-port-conversion-strategy!}.
893 If the value is @code{'error} then an exception is thrown if there is any
894 conversion error.  If the value is @code{'substitute} then any conversion
895 error is replaced with question marks.
896 @xref{Strings,,, guile, GNU Guile Reference Manual}.
898 If the optional @var{length} argument is given, the string will be
899 fetched and converted to the given length.
900 The length must be a Scheme integer and not a @code{<gdb:value>} integer.
901 @end deffn
903 @deffn {Scheme Procedure} value->lazy-string value @
904     @w{@r{[}#:encoding encoding@r{]}} @w{@r{[}#:length length@r{]}}
905 If this @code{<gdb:value>} represents a string, then this method
906 converts @var{value} to a @code{<gdb:lazy-string} (@pxref{Lazy Strings
907 In Guile}).  Otherwise, this method will throw an exception.
909 If the optional @var{encoding} argument is given, it must be a string
910 naming the encoding of the @code{<gdb:lazy-string}.  Some examples are:
911 @code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}.  If the
912 @var{encoding} argument is an encoding that @value{GDBN} does not
913 recognize, @value{GDBN} will raise an error.
915 When a lazy string is printed, the @value{GDBN} encoding machinery is
916 used to convert the string during printing.  If the optional
917 @var{encoding} argument is not provided, or is an empty string,
918 @value{GDBN} will automatically select the encoding most suitable for
919 the string type.  For further information on encoding in @value{GDBN}
920 please see @ref{Character Sets}.
922 If the optional @var{length} argument is given, the string will be
923 fetched and encoded to the length of characters specified.  If
924 the @var{length} argument is not provided, the string will be fetched
925 and encoded until a null of appropriate width is found.
926 The length must be a Scheme integer and not a @code{<gdb:value>} integer.
927 @end deffn
929 @deffn {Scheme Procedure} value-lazy? value
930 Return @code{#t} if @var{value} has not yet been fetched
931 from the inferior.
932 Otherwise return @code{#f}.
933 @value{GDBN} does not fetch values until necessary, for efficiency.
934 For example:
936 @smallexample
937 (define myval (parse-and-eval "somevar"))
938 @end smallexample
940 The value of @code{somevar} is not fetched at this time.  It will be
941 fetched when the value is needed, or when the @code{fetch-lazy}
942 procedure is invoked.
943 @end deffn
945 @deffn {Scheme Procedure} make-lazy-value type address
946 Return a @code{<gdb:value>} that will be lazily fetched from the
947 target.  The object of type @code{<gdb:type>} whose value to fetch is
948 specified by its @var{type} and its target memory @var{address}, which
949 is a Scheme integer.
950 @end deffn
952 @deffn {Scheme Procedure} value-fetch-lazy! value
953 If @var{value} is a lazy value (@code{(value-lazy? value)} is @code{#t}),
954 then the value is fetched from the inferior.
955 Any errors that occur in the process will produce a Guile exception.
957 If @var{value} is not a lazy value, this method has no effect.
959 The result of this function is unspecified.
960 @end deffn
962 @deffn {Scheme Procedure} value-print value
963 Return the string representation (print form) of @code{<gdb:value>}
964 @var{value}.
965 @end deffn
967 @node Arithmetic In Guile
968 @subsubsection Arithmetic In Guile
970 The @code{(gdb)} module provides several functions for performing
971 arithmetic on @code{<gdb:value>} objects.
972 The arithmetic is performed as if it were done by the target,
973 and therefore has target semantics which are not necessarily
974 those of Scheme.  For example operations work with a fixed precision,
975 not the arbitrary precision of Scheme.
977 Wherever a function takes an integer or pointer as an operand,
978 @value{GDBN} will convert appropriate Scheme values to perform
979 the operation.
981 @deffn {Scheme Procedure} value-add a b
982 @end deffn
984 @deffn {Scheme Procedure} value-sub a b
985 @end deffn
987 @deffn {Scheme Procedure} value-mul a b
988 @end deffn
990 @deffn {Scheme Procedure} value-div a b
991 @end deffn
993 @deffn {Scheme Procedure} value-rem a b
994 @end deffn
996 @deffn {Scheme Procedure} value-mod a b
997 @end deffn
999 @deffn {Scheme Procedure} value-pow a b
1000 @end deffn
1002 @deffn {Scheme Procedure} value-not a
1003 @end deffn
1005 @deffn {Scheme Procedure} value-neg a
1006 @end deffn
1008 @deffn {Scheme Procedure} value-pos a
1009 @end deffn
1011 @deffn {Scheme Procedure} value-abs a
1012 @end deffn
1014 @deffn {Scheme Procedure} value-lsh a b
1015 @end deffn
1017 @deffn {Scheme Procedure} value-rsh a b
1018 @end deffn
1020 @deffn {Scheme Procedure} value-min a b
1021 @end deffn
1023 @deffn {Scheme Procedure} value-max a b
1024 @end deffn
1026 @deffn {Scheme Procedure} value-lognot a
1027 @end deffn
1029 @deffn {Scheme Procedure} value-logand a b
1030 @end deffn
1032 @deffn {Scheme Procedure} value-logior a b
1033 @end deffn
1035 @deffn {Scheme Procedure} value-logxor a b
1036 @end deffn
1038 @deffn {Scheme Procedure} value=? a b
1039 @end deffn
1041 @deffn {Scheme Procedure} value<? a b
1042 @end deffn
1044 @deffn {Scheme Procedure} value<=? a b
1045 @end deffn
1047 @deffn {Scheme Procedure} value>? a b
1048 @end deffn
1050 @deffn {Scheme Procedure} value>=? a b
1051 @end deffn
1053 Scheme does not provide a @code{not-equal} function,
1054 and thus Guile support in @value{GDBN} does not either.
1056 @node Types In Guile
1057 @subsubsection Types In Guile
1058 @cindex types in guile
1059 @cindex guile, working with types
1061 @tindex <gdb:type>
1062 @value{GDBN} represents types from the inferior in objects of type
1063 @code{<gdb:type>}.
1065 The following type-related procedures are provided by the
1066 @code{(gdb)} module.
1068 @deffn {Scheme Procedure} type? object
1069 Return @code{#t} if @var{object} is an object of type @code{<gdb:type>}.
1070 Otherwise return @code{#f}.
1071 @end deffn
1073 @deffn {Scheme Procedure} lookup-type name @r{[}#:block block@r{]}
1074 This function looks up a type by its @var{name}, which must be a string.
1076 If @var{block} is given, it is an object of type @code{<gdb:block>},
1077 and @var{name} is looked up in that scope.
1078 Otherwise, it is searched for globally.
1080 Ordinarily, this function will return an instance of @code{<gdb:type>}.
1081 If the named type cannot be found, it will throw an exception.
1082 @end deffn
1084 @deffn {Scheme Procedure} type-code type
1085 Return the type code of @var{type}.  The type code will be one of the
1086 @code{TYPE_CODE_} constants defined below.
1087 @end deffn
1089 @deffn {Scheme Procedure} type-tag type
1090 Return the tag name of @var{type}.  The tag name is the name after
1091 @code{struct}, @code{union}, or @code{enum} in C and C@t{++}; not all
1092 languages have this concept.  If this type has no tag name, then
1093 @code{#f} is returned.
1094 @end deffn
1096 @deffn {Scheme Procedure} type-name type
1097 Return the name of @var{type}.
1098 If this type has no name, then @code{#f} is returned.
1099 @end deffn
1101 @deffn {Scheme Procedure} type-print-name type
1102 Return the print name of @var{type}.
1103 This returns something even for anonymous types.
1104 For example, for an anonymous C struct @code{"struct @{...@}"} is returned.
1105 @end deffn
1107 @deffn {Scheme Procedure} type-sizeof type
1108 Return the size of this type, in target @code{char} units.  Usually, a
1109 target's @code{char} type will be an 8-bit byte.  However, on some
1110 unusual platforms, this type may have a different size.
1111 @end deffn
1113 @deffn {Scheme Procedure} type-strip-typedefs type
1114 Return a new @code{<gdb:type>} that represents the real type of @var{type},
1115 after removing all layers of typedefs.
1116 @end deffn
1118 @deffn {Scheme Procedure} type-array type n1 @r{[}n2@r{]}
1119 Return a new @code{<gdb:type>} object which represents an array of this
1120 type.  If one argument is given, it is the inclusive upper bound of
1121 the array; in this case the lower bound is zero.  If two arguments are
1122 given, the first argument is the lower bound of the array, and the
1123 second argument is the upper bound of the array.  An array's length
1124 must not be negative, but the bounds can be.
1125 @end deffn
1127 @deffn {Scheme Procedure} type-vector type n1 @r{[}n2@r{]}
1128 Return a new @code{<gdb:type>} object which represents a vector of this
1129 type.  If one argument is given, it is the inclusive upper bound of
1130 the vector; in this case the lower bound is zero.  If two arguments are
1131 given, the first argument is the lower bound of the vector, and the
1132 second argument is the upper bound of the vector.  A vector's length
1133 must not be negative, but the bounds can be.
1135 The difference between an @code{array} and a @code{vector} is that
1136 arrays behave like in C: when used in expressions they decay to a pointer
1137 to the first element whereas vectors are treated as first class values.
1138 @end deffn
1140 @deffn {Scheme Procedure} type-pointer type
1141 Return a new @code{<gdb:type>} object which represents a pointer to
1142 @var{type}.
1143 @end deffn
1145 @deffn {Scheme Procedure} type-range type
1146 Return a list of two elements: the low bound and high bound of @var{type}.
1147 If @var{type} does not have a range, an exception is thrown.
1148 @end deffn
1150 @deffn {Scheme Procedure} type-reference type
1151 Return a new @code{<gdb:type>} object which represents a reference to
1152 @var{type}.
1153 @end deffn
1155 @deffn {Scheme Procedure} type-target type
1156 Return a new @code{<gdb:type>} object which represents the target type
1157 of @var{type}.
1159 For a pointer type, the target type is the type of the pointed-to
1160 object.  For an array type (meaning C-like arrays), the target type is
1161 the type of the elements of the array.  For a function or method type,
1162 the target type is the type of the return value.  For a complex type,
1163 the target type is the type of the elements.  For a typedef, the
1164 target type is the aliased type.
1166 If the type does not have a target, this method will throw an
1167 exception.
1168 @end deffn
1170 @deffn {Scheme Procedure} type-const type
1171 Return a new @code{<gdb:type>} object which represents a
1172 @code{const}-qualified variant of @var{type}.
1173 @end deffn
1175 @deffn {Scheme Procedure} type-volatile type
1176 Return a new @code{<gdb:type>} object which represents a
1177 @code{volatile}-qualified variant of @var{type}.
1178 @end deffn
1180 @deffn {Scheme Procedure} type-unqualified type
1181 Return a new @code{<gdb:type>} object which represents an unqualified
1182 variant of @var{type}.  That is, the result is neither @code{const} nor
1183 @code{volatile}.
1184 @end deffn
1186 @deffn {Scheme Procedure} type-num-fields
1187 Return the number of fields of @code{<gdb:type>} @var{type}.
1188 @end deffn
1190 @deffn {Scheme Procedure} type-fields type
1191 Return the fields of @var{type} as a list.
1192 For structure and union types, @code{fields} has the usual meaning.
1193 Range types have two fields, the minimum and maximum values.  Enum types
1194 have one field per enum constant.  Function and method types have one
1195 field per parameter.  The base types of C@t{++} classes are also
1196 represented as fields.  If the type has no fields, or does not fit
1197 into one of these categories, an empty list will be returned.
1198 @xref{Fields of a type in Guile}.
1199 @end deffn
1201 @deffn {Scheme Procedure} make-field-iterator type
1202 Return the fields of @var{type} as a <gdb:iterator> object.
1203 @xref{Iterators In Guile}.
1204 @end deffn
1206 @deffn {Scheme Procedure} type-field type field-name
1207 Return field named @var{field-name} in @var{type}.
1208 The result is an object of type @code{<gdb:field>}.
1209 @xref{Fields of a type in Guile}.
1210 If the type does not have fields, or @var{field-name} is not a field
1211 of @var{type}, an exception is thrown.
1213 For example, if @code{some-type} is a @code{<gdb:type>} instance holding
1214 a structure type, you can access its @code{foo} field with:
1216 @smallexample
1217 (define bar (type-field some-type "foo"))
1218 @end smallexample
1220 @code{bar} will be a @code{<gdb:field>} object.
1221 @end deffn
1223 @deffn {Scheme Procedure} type-has-field? type name
1224 Return @code{#t} if @code{<gdb:type>} @var{type} has field named @var{name}.
1225 Otherwise return @code{#f}.
1226 @end deffn
1228 Each type has a code, which indicates what category this type falls
1229 into.  The available type categories are represented by constants
1230 defined in the @code{(gdb)} module:
1232 @vtable @code
1233 @item TYPE_CODE_PTR
1234 The type is a pointer.
1236 @item TYPE_CODE_ARRAY
1237 The type is an array.
1239 @item TYPE_CODE_STRUCT
1240 The type is a structure.
1242 @item TYPE_CODE_UNION
1243 The type is a union.
1245 @item TYPE_CODE_ENUM
1246 The type is an enum.
1248 @item TYPE_CODE_FLAGS
1249 A bit flags type, used for things such as status registers.
1251 @item TYPE_CODE_FUNC
1252 The type is a function.
1254 @item TYPE_CODE_INT
1255 The type is an integer type.
1257 @item TYPE_CODE_FLT
1258 A floating point type.
1260 @item TYPE_CODE_VOID
1261 The special type @code{void}.
1263 @item TYPE_CODE_SET
1264 A Pascal set type.
1266 @item TYPE_CODE_RANGE
1267 A range type, that is, an integer type with bounds.
1269 @item TYPE_CODE_STRING
1270 A string type.  Note that this is only used for certain languages with
1271 language-defined string types; C strings are not represented this way.
1273 @item TYPE_CODE_BITSTRING
1274 A string of bits.  It is deprecated.
1276 @item TYPE_CODE_ERROR
1277 An unknown or erroneous type.
1279 @item TYPE_CODE_METHOD
1280 A method type, as found in C@t{++}.
1282 @item TYPE_CODE_METHODPTR
1283 A pointer-to-member-function.
1285 @item TYPE_CODE_MEMBERPTR
1286 A pointer-to-member.
1288 @item TYPE_CODE_REF
1289 A reference type.
1291 @item TYPE_CODE_RVALUE_REF
1292 A C@t{++}11 rvalue reference type.
1294 @item TYPE_CODE_CHAR
1295 A character type.
1297 @item TYPE_CODE_BOOL
1298 A boolean type.
1300 @item TYPE_CODE_COMPLEX
1301 A complex float type.
1303 @item TYPE_CODE_TYPEDEF
1304 A typedef to some other type.
1306 @item TYPE_CODE_NAMESPACE
1307 A C@t{++} namespace.
1309 @item TYPE_CODE_DECFLOAT
1310 A decimal floating point type.
1312 @item TYPE_CODE_INTERNAL_FUNCTION
1313 A function internal to @value{GDBN}.  This is the type used to represent
1314 convenience functions (@pxref{Convenience Funs}).
1316 @vindex TYPE_CODE_XMETHOD
1317 @item gdb.TYPE_CODE_XMETHOD
1318 A method internal to @value{GDBN}.  This is the type used to represent
1319 xmethods (@pxref{Writing an Xmethod}).
1321 @vindex TYPE_CODE_FIXED_POINT
1322 @item gdb.TYPE_CODE_FIXED_POINT
1323 A fixed-point number.
1325 @vindex TYPE_CODE_NAMESPACE
1326 @item gdb.TYPE_CODE_NAMESPACE
1327 A Fortran namelist.
1328 @end vtable
1330 Further support for types is provided in the @code{(gdb types)}
1331 Guile module (@pxref{Guile Types Module}).
1333 @anchor{Fields of a type in Guile}
1334 Each field is represented as an object of type @code{<gdb:field>}.
1336 The following field-related procedures are provided by the
1337 @code{(gdb)} module:
1339 @deffn {Scheme Procedure} field? object
1340 Return @code{#t} if @var{object} is an object of type @code{<gdb:field>}.
1341 Otherwise return @code{#f}.
1342 @end deffn
1344 @deffn {Scheme Procedure} field-name field
1345 Return the name of the field, or @code{#f} for anonymous fields.
1346 @end deffn
1348 @deffn {Scheme Procedure} field-type field
1349 Return the type of the field.  This is usually an instance of
1350 @code{<gdb:type>}, but it can be @code{#f} in some situations.
1351 @end deffn
1353 @deffn {Scheme Procedure} field-enumval field
1354 Return the enum value represented by @code{<gdb:field>} @var{field}.
1355 @end deffn
1357 @deffn {Scheme Procedure} field-bitpos field
1358 Return the bit position of @code{<gdb:field>} @var{field}.
1359 This attribute is not available for @code{static} fields (as in
1360 C@t{++}).
1361 @end deffn
1363 @deffn {Scheme Procedure} field-bitsize field
1364 If the field is packed, or is a bitfield, return the size of
1365 @code{<gdb:field>} @var{field} in bits.  Otherwise, zero is returned;
1366 in which case the field's size is given by its type.
1367 @end deffn
1369 @deffn {Scheme Procedure} field-artificial? field
1370 Return @code{#t} if the field is artificial, usually meaning that
1371 it was provided by the compiler and not the user.
1372 Otherwise return @code{#f}.
1373 @end deffn
1375 @deffn {Scheme Procedure} field-base-class? field
1376 Return @code{#t} if the field represents a base class of a C@t{++}
1377 structure.
1378 Otherwise return @code{#f}.
1379 @end deffn
1381 @node Guile Pretty Printing API
1382 @subsubsection Guile Pretty Printing API
1383 @cindex guile pretty printing api
1385 An example output is provided (@pxref{Pretty Printing}).
1387 A pretty-printer is represented by an object of type <gdb:pretty-printer>.
1388 Pretty-printer objects are created with @code{make-pretty-printer}.
1390 The following pretty-printer-related procedures are provided by the
1391 @code{(gdb)} module:
1393 @deffn {Scheme Procedure} make-pretty-printer name lookup-function
1394 Return a @code{<gdb:pretty-printer>} object named @var{name}.
1396 @var{lookup-function} is a function of one parameter: the value to
1397 be printed.  If the value is handled by this pretty-printer, then
1398 @var{lookup-function} returns an object of type
1399 <gdb:pretty-printer-worker> to perform the actual pretty-printing.
1400 Otherwise @var{lookup-function} returns @code{#f}.
1401 @end deffn
1403 @deffn {Scheme Procedure} pretty-printer? object
1404 Return @code{#t} if @var{object} is a @code{<gdb:pretty-printer>} object.
1405 Otherwise return @code{#f}.
1406 @end deffn
1408 @deffn {Scheme Procedure} pretty-printer-enabled? pretty-printer
1409 Return @code{#t} if @var{pretty-printer} is enabled.
1410 Otherwise return @code{#f}.
1411 @end deffn
1413 @deffn {Scheme Procedure} set-pretty-printer-enabled! pretty-printer flag
1414 Set the enabled flag of @var{pretty-printer} to @var{flag}.
1415 The value returned is unspecified.
1416 @end deffn
1418 @deffn {Scheme Procedure} pretty-printers
1419 Return the list of global pretty-printers.
1420 @end deffn
1422 @deffn {Scheme Procedure} set-pretty-printers! pretty-printers
1423 Set the list of global pretty-printers to @var{pretty-printers}.
1424 The value returned is unspecified.
1425 @end deffn
1427 @deffn {Scheme Procedure} make-pretty-printer-worker display-hint to-string children
1428 Return an object of type @code{<gdb:pretty-printer-worker>}.
1430 This function takes three parameters:
1432 @table @samp
1433 @item display-hint
1434 @var{display-hint} provides a hint to @value{GDBN} or @value{GDBN}
1435 front end via MI to change the formatting of the value being printed.
1436 The value must be a string or @code{#f} (meaning there is no hint).
1437 Several values for @var{display-hint}
1438 are predefined by @value{GDBN}:
1440 @table @samp
1441 @item array
1442 Indicate that the object being printed is ``array-like''.  The CLI
1443 uses this to respect parameters such as @code{set print elements} and
1444 @code{set print array}.
1446 @item map
1447 Indicate that the object being printed is ``map-like'', and that the
1448 children of this value can be assumed to alternate between keys and
1449 values.
1451 @item string
1452 Indicate that the object being printed is ``string-like''.  If the
1453 printer's @code{to-string} function returns a Guile string of some
1454 kind, then @value{GDBN} will call its internal language-specific
1455 string-printing function to format the string.  For the CLI this means
1456 adding quotation marks, possibly escaping some characters, respecting
1457 @code{set print elements}, and the like.
1458 @end table
1460 @item to-string
1461 @var{to-string} is either a function of one parameter, the
1462 @code{<gdb:pretty-printer-worker>} object, or @code{#f}.
1464 When printing from the CLI, if the @code{to-string} method exists,
1465 then @value{GDBN} will prepend its result to the values returned by
1466 @code{children}.  Exactly how this formatting is done is dependent on
1467 the display hint, and may change as more hints are added.  Also,
1468 depending on the print settings (@pxref{Print Settings}), the CLI may
1469 print just the result of @code{to-string} in a stack trace, omitting
1470 the result of @code{children}.
1472 If this method returns a string, it is printed verbatim.
1474 Otherwise, if this method returns an instance of @code{<gdb:value>},
1475 then @value{GDBN} prints this value.  This may result in a call to
1476 another pretty-printer.
1478 If instead the method returns a Guile value which is convertible to a
1479 @code{<gdb:value>}, then @value{GDBN} performs the conversion and prints
1480 the resulting value.  Again, this may result in a call to another
1481 pretty-printer.  Guile scalars (integers, floats, and booleans) and
1482 strings are convertible to @code{<gdb:value>}; other types are not.
1484 Finally, if this method returns @code{#f} then no further operations
1485 are performed in this method and nothing is printed.
1487 If the result is not one of these types, an exception is raised.
1489 @var{to-string} may also be @code{#f} in which case it is left to
1490 @var{children} to print the value.
1492 @item children
1493 @var{children} is either a function of one parameter, the
1494 @code{<gdb:pretty-printer-worker>} object, or @code{#f}.
1496 @value{GDBN} will call this function on a pretty-printer to compute the
1497 children of the pretty-printer's value.
1499 This function must return a <gdb:iterator> object.
1500 Each item returned by the iterator must be a tuple holding
1501 two elements.  The first element is the ``name'' of the child; the
1502 second element is the child's value.  The value can be any Guile
1503 object which is convertible to a @value{GDBN} value.
1505 If @var{children} is @code{#f}, @value{GDBN} will act
1506 as though the value has no children.
1508 Children may be hidden from display based on the value of @samp{set
1509 print max-depth} (@pxref{Print Settings}).
1510 @end table
1511 @end deffn
1513 @value{GDBN} provides a function which can be used to look up the
1514 default pretty-printer for a @code{<gdb:value>}:
1516 @deffn {Scheme Procedure} default-visualizer value
1517 This function takes a @code{<gdb:value>} object as an argument.  If a
1518 pretty-printer for this value exists, then it is returned.  If no such
1519 printer exists, then this returns @code{#f}.
1520 @end deffn
1522 @node Selecting Guile Pretty-Printers
1523 @subsubsection Selecting Guile Pretty-Printers
1524 @cindex selecting guile pretty-printers
1526 There are three sets of pretty-printers that @value{GDBN} searches:
1528 @itemize @bullet
1529 @item
1530 Per-objfile list of pretty-printers (@pxref{Objfiles In Guile}).
1531 @item
1532 Per-progspace list of pretty-printers (@pxref{Progspaces In Guile}).
1533 @item
1534 The global list of pretty-printers (@pxref{Guile Pretty Printing API}).
1535 These printers are available when debugging any inferior.
1536 @end itemize
1538 Pretty-printer lookup is done by passing the value to be printed to the
1539 lookup function of each enabled object in turn.
1540 Lookup stops when a lookup function returns a non-@code{#f} value
1541 or when the list is exhausted.
1542 Lookup functions must return either a @code{<gdb:pretty-printer-worker>}
1543 object or @code{#f}.  Otherwise an exception is thrown.
1545 @value{GDBN} first checks the result of @code{objfile-pretty-printers}
1546 of each @code{<gdb:objfile>} in the current program space and iteratively
1547 calls each enabled lookup function in the list for that @code{<gdb:objfile>}
1548 until a non-@code{#f} object is returned.
1549 If no pretty-printer is found in the objfile lists, @value{GDBN} then
1550 searches the result of @code{progspace-pretty-printers} of the current
1551 program space, calling each enabled function until a non-@code{#f} object
1552 is returned.
1553 After these lists have been exhausted, it tries the global pretty-printers
1554 list, obtained with @code{pretty-printers}, again calling each enabled
1555 function until a non-@code{#f} object is returned.
1557 The order in which the objfiles are searched is not specified.  For a
1558 given list, functions are always invoked from the head of the list,
1559 and iterated over sequentially until the end of the list, or a
1560 @code{<gdb:pretty-printer-worker>} object is returned.
1562 For various reasons a pretty-printer may not work.
1563 For example, the underlying data structure may have changed and
1564 the pretty-printer is out of date.
1566 The consequences of a broken pretty-printer are severe enough that
1567 @value{GDBN} provides support for enabling and disabling individual
1568 printers.  For example, if @code{print frame-arguments} is on,
1569 a backtrace can become highly illegible if any argument is printed
1570 with a broken printer.
1572 Pretty-printers are enabled and disabled from Scheme by calling
1573 @code{set-pretty-printer-enabled!}.
1574 @xref{Guile Pretty Printing API}.
1576 @node Writing a Guile Pretty-Printer
1577 @subsubsection Writing a Guile Pretty-Printer
1578 @cindex writing a Guile pretty-printer
1580 A pretty-printer consists of two basic parts: a lookup function to determine
1581 if the type is supported, and the printer itself.
1583 Here is an example showing how a @code{std::string} printer might be
1584 written.  @xref{Guile Pretty Printing API}, for details.
1586 @smallexample
1587 (define (make-my-string-printer value)
1588   "Print a my::string string"
1589   (make-pretty-printer-worker
1590    "string"
1591    (lambda (printer)
1592      (value-field value "_data"))
1593    #f))
1594 @end smallexample
1596 And here is an example showing how a lookup function for the printer
1597 example above might be written.
1599 @smallexample
1600 (define (str-lookup-function pretty-printer value)
1601   (let ((tag (type-tag (value-type value))))
1602     (and tag
1603          (string-prefix? "std::string<" tag)
1604          (make-my-string-printer value))))
1605 @end smallexample
1607 Then to register this printer in the global printer list:
1609 @smallexample
1610 (append-pretty-printer!
1611  (make-pretty-printer "my-string" str-lookup-function))
1612 @end smallexample
1614 The example lookup function extracts the value's type, and attempts to
1615 match it to a type that it can pretty-print.  If it is a type the
1616 printer can pretty-print, it will return a <gdb:pretty-printer-worker> object.
1617 If not, it returns @code{#f}.
1619 We recommend that you put your core pretty-printers into a Guile
1620 package.  If your pretty-printers are for use with a library, we
1621 further recommend embedding a version number into the package name.
1622 This practice will enable @value{GDBN} to load multiple versions of
1623 your pretty-printers at the same time, because they will have
1624 different names.
1626 You should write auto-loaded code (@pxref{Guile Auto-loading}) such that it
1627 can be evaluated multiple times without changing its meaning.  An
1628 ideal auto-load file will consist solely of @code{import}s of your
1629 printer modules, followed by a call to a register pretty-printers with
1630 the current objfile.
1632 Taken as a whole, this approach will scale nicely to multiple
1633 inferiors, each potentially using a different library version.
1634 Embedding a version number in the Guile package name will ensure that
1635 @value{GDBN} is able to load both sets of printers simultaneously.
1636 Then, because the search for pretty-printers is done by objfile, and
1637 because your auto-loaded code took care to register your library's
1638 printers with a specific objfile, @value{GDBN} will find the correct
1639 printers for the specific version of the library used by each
1640 inferior.
1642 To continue the @code{my::string} example,
1643 this code might appear in @code{(my-project my-library v1)}:
1645 @smallexample
1646 (use-modules (gdb))
1647 (define (register-printers objfile)
1648   (append-objfile-pretty-printer!
1649    (make-pretty-printer "my-string" str-lookup-function)))
1650 @end smallexample
1652 @noindent
1653 And then the corresponding contents of the auto-load file would be:
1655 @smallexample
1656 (use-modules (gdb) (my-project my-library v1))
1657 (register-printers (current-objfile))
1658 @end smallexample
1660 The previous example illustrates a basic pretty-printer.
1661 There are a few things that can be improved on.
1662 The printer only handles one type, whereas a library typically has
1663 several types.  One could install a lookup function for each desired type
1664 in the library, but one could also have a single lookup function recognize
1665 several types.  The latter is the conventional way this is handled.
1666 If a pretty-printer can handle multiple data types, then its
1667 @dfn{subprinters} are the printers for the individual data types.
1669 The @code{(gdb printing)} module provides a formal way of solving this
1670 problem (@pxref{Guile Printing Module}).
1671 Here is another example that handles multiple types.
1673 These are the types we are going to pretty-print:
1675 @smallexample
1676 struct foo @{ int a, b; @};
1677 struct bar @{ struct foo x, y; @};
1678 @end smallexample
1680 Here are the printers:
1682 @smallexample
1683 (define (make-foo-printer value)
1684   "Print a foo object"
1685   (make-pretty-printer-worker
1686    "foo"
1687    (lambda (printer)
1688      (format #f "a=<~a> b=<~a>"
1689              (value-field value "a") (value-field value "a")))
1690    #f))
1692 (define (make-bar-printer value)
1693   "Print a bar object"
1694   (make-pretty-printer-worker
1695    "foo"
1696    (lambda (printer)
1697      (format #f "x=<~a> y=<~a>"
1698              (value-field value "x") (value-field value "y")))
1699    #f))
1700 @end smallexample
1702 This example doesn't need a lookup function, that is handled by the
1703 @code{(gdb printing)} module.  Instead a function is provided to build up
1704 the object that handles the lookup.
1706 @smallexample
1707 (use-modules (gdb printing))
1709 (define (build-pretty-printer)
1710   (let ((pp (make-pretty-printer-collection "my-library")))
1711     (pp-collection-add-tag-printer "foo" make-foo-printer)
1712     (pp-collection-add-tag-printer "bar" make-bar-printer)
1713     pp))
1714 @end smallexample
1716 And here is the autoload support:
1718 @smallexample
1719 (use-modules (gdb) (my-library))
1720 (append-objfile-pretty-printer! (current-objfile) (build-pretty-printer))
1721 @end smallexample
1723 Finally, when this printer is loaded into @value{GDBN}, here is the
1724 corresponding output of @samp{info pretty-printer}:
1726 @smallexample
1727 (gdb) info pretty-printer
1728 my_library.so:
1729   my-library
1730     foo
1731     bar
1732 @end smallexample
1734 @node Commands In Guile
1735 @subsubsection Commands In Guile
1737 @cindex commands in guile
1738 @cindex guile commands
1739 You can implement new @value{GDBN} CLI commands in Guile.  A CLI
1740 command object is created with the @code{make-command} Guile function,
1741 and added to @value{GDBN} with the @code{register-command!} Guile function.
1742 This two-step approach is taken to separate out the side-effect of adding
1743 the command to @value{GDBN} from @code{make-command}.
1745 There is no support for multi-line commands, that is commands that
1746 consist of multiple lines and are terminated with @code{end}.
1748 @deffn {Scheme Procedure} make-command name @w{@r{[}#:invoke invoke@r{]}} @
1749     @w{@r{[}#:command-class command-class@r{]}} @
1750     @w{@r{[}#:completer-class completer@r{]}} @
1751     @w{@r{[}#:prefix? prefix@r{]}} @w{@r{[}#:doc doc-string@r{]}}
1753 The argument @var{name} is the name of the command.  If @var{name} consists of
1754 multiple words, then the initial words are looked for as prefix
1755 commands.  In this case, if one of the prefix commands does not exist,
1756 an exception is raised.
1758 The result is the @code{<gdb:command>} object representing the command.
1759 The command is not usable until it has been registered with @value{GDBN}
1760 with @code{register-command!}.
1762 The rest of the arguments are optional.
1764 The argument @var{invoke} is a procedure of three arguments: @var{self},
1765 @var{args} and @var{from-tty}.  The argument @var{self} is the
1766 @code{<gdb:command>} object representing the command.
1767 The argument @var{args} is a string representing the arguments passed to
1768 the command, after leading and trailing whitespace has been stripped.
1769 The argument @var{from-tty} is a boolean flag and specifies whether the
1770 command should consider itself to have been originated from the user
1771 invoking it interactively.  If this function throws an exception,
1772 it is turned into a @value{GDBN} @code{error} call.
1773 Otherwise, the return value is ignored.
1775 The argument @var{command-class} is one of the @samp{COMMAND_} constants
1776 defined below.  This argument tells @value{GDBN} how to categorize the
1777 new command in the help system.  The default is @code{COMMAND_NONE}.
1779 The argument @var{completer} is either @code{#f}, one of the @samp{COMPLETE_}
1780 constants defined below, or a procedure, also defined below.
1781 This argument tells @value{GDBN} how to perform completion
1782 for this command.  If not provided or if the value is @code{#f},
1783 then no completion is performed on the command.
1785 The argument @var{prefix} is a boolean flag indicating whether the new
1786 command is a prefix command; sub-commands of this command may be
1787 registered.
1789 The argument @var{doc-string} is help text for the new command.
1790 If no documentation string is provided, the default value ``This command is
1791 not documented.'' is used.
1792 @end deffn
1794 @deffn {Scheme Procedure} register-command! command
1795 Add @var{command}, a @code{<gdb:command>} object, to @value{GDBN}'s
1796 list of commands.
1797 It is an error to register a command more than once.
1798 The result is unspecified.
1799 @end deffn
1801 @deffn {Scheme Procedure} command? object
1802 Return @code{#t} if @var{object} is a @code{<gdb:command>} object.
1803 Otherwise return @code{#f}.
1804 @end deffn
1806 @cindex don't repeat Guile command
1807 @deffn {Scheme Procedure} dont-repeat
1808 By default, a @value{GDBN} command is repeated when the user enters a
1809 blank line at the command prompt.  A command can suppress this
1810 behavior by invoking the @code{dont-repeat} function.  This is similar
1811 to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
1812 @end deffn
1814 @deffn {Scheme Procedure} string->argv string
1815 Convert a string to a list of strings split up according to
1816 @value{GDBN}'s argv parsing rules.
1817 It is recommended to use this for consistency.
1818 Arguments are separated by spaces and may be quoted.
1819 Example:
1821 @smallexample
1822 scheme@@(guile-user)> (string->argv "1 2\\ \\\"3 '4 \"5' \"6 '7\"")
1823 $1 = ("1" "2 \"3" "4 \"5" "6 '7")
1824 @end smallexample
1825 @end deffn
1827 @deffn {Scheme Procedure} throw-user-error message . args
1828 Throw a @code{gdb:user-error} exception.
1829 The argument @var{message} is the error message as a format string, like the 
1830 @var{fmt} argument to the @code{format} Scheme function.
1831 @xref{Formatted Output,,, guile, GNU Guile Reference Manual}.
1832 The argument @var{args} is a list of the optional arguments of @var{message}.
1834 This is used when the command detects a user error of some kind,
1835 say a bad command argument.
1837 @smallexample
1838 (gdb) guile (use-modules (gdb))
1839 (gdb) guile
1840 (register-command! (make-command "test-user-error"
1841   #:command-class COMMAND_OBSCURE
1842   #:invoke (lambda (self arg from-tty)
1843     (throw-user-error "Bad argument ~a" arg))))
1845 (gdb) test-user-error ugh
1846 ERROR: Bad argument ugh
1847 @end smallexample
1848 @end deffn
1850 @cindex completion of Guile commands
1851 @deffn completer self text word
1852 If the @var{completer} option to @code{make-command} is a procedure,
1853 it takes three arguments: @var{self} which is the @code{<gdb:command>}
1854 object, and @var{text} and @var{word} which are both strings.
1855 The argument @var{text} holds the complete command line up to the cursor's
1856 location.  The argument @var{word} holds the last word of the command line;
1857 this is computed using a word-breaking heuristic.
1859 All forms of completion are handled by this function, that is,
1860 the @key{TAB} and @key{M-?} key bindings (@pxref{Completion}),
1861 and the @code{complete} command (@pxref{Help, complete}).
1863 This procedure can return several kinds of values:
1865 @itemize @bullet
1866 @item
1867 If the return value is a list, the contents of the list are used as the
1868 completions.  It is up to @var{completer} to ensure that the
1869 contents actually do complete the word.  An empty list is
1870 allowed, it means that there were no completions available.  Only
1871 string elements of the list are used; other elements in the
1872 list are ignored.
1874 @item
1875 If the return value is a @code{<gdb:iterator>} object, it is iterated over to
1876 obtain the completions.  It is up to @code{completer-procedure} to ensure
1877 that the results actually do complete the word.  Only
1878 string elements of the result are used; other elements in the
1879 sequence are ignored.
1881 @item
1882 All other results are treated as though there were no available
1883 completions.
1884 @end itemize
1885 @end deffn
1887 When a new command is registered, it will have been declared as a member of
1888 some general class of commands.  This is used to classify top-level
1889 commands in the on-line help system; note that prefix commands are not
1890 listed under their own category but rather that of their top-level
1891 command.  The available classifications are represented by constants
1892 defined in the @code{gdb} module:
1894 @vtable @code
1895 @item COMMAND_NONE
1896 The command does not belong to any particular class.  A command in
1897 this category will not be displayed in any of the help categories.
1898 This is the default.
1900 @item COMMAND_RUNNING
1901 The command is related to running the inferior.  For example,
1902 @code{start}, @code{step}, and @code{continue} are in this category.
1903 Type @kbd{help running} at the @value{GDBN} prompt to see a list of
1904 commands in this category.
1906 @item COMMAND_DATA
1907 The command is related to data or variables.  For example,
1908 @code{call}, @code{find}, and @code{print} are in this category.  Type
1909 @kbd{help data} at the @value{GDBN} prompt to see a list of commands
1910 in this category.
1912 @item COMMAND_STACK
1913 The command has to do with manipulation of the stack.  For example,
1914 @code{backtrace}, @code{frame}, and @code{return} are in this
1915 category.  Type @kbd{help stack} at the @value{GDBN} prompt to see a
1916 list of commands in this category.
1918 @item COMMAND_FILES
1919 This class is used for file-related commands.  For example,
1920 @code{file}, @code{list} and @code{section} are in this category.
1921 Type @kbd{help files} at the @value{GDBN} prompt to see a list of
1922 commands in this category.
1924 @item COMMAND_SUPPORT
1925 This should be used for ``support facilities'', generally meaning
1926 things that are useful to the user when interacting with @value{GDBN},
1927 but not related to the state of the inferior.  For example,
1928 @code{help}, @code{make}, and @code{shell} are in this category.  Type
1929 @kbd{help support} at the @value{GDBN} prompt to see a list of
1930 commands in this category.
1932 @item COMMAND_STATUS
1933 The command is an @samp{info}-related command, that is, related to the
1934 state of @value{GDBN} itself.  For example, @code{info}, @code{macro},
1935 and @code{show} are in this category.  Type @kbd{help status} at the
1936 @value{GDBN} prompt to see a list of commands in this category.
1938 @item COMMAND_BREAKPOINTS
1939 The command has to do with breakpoints.  For example, @code{break},
1940 @code{clear}, and @code{delete} are in this category.  Type @kbd{help
1941 breakpoints} at the @value{GDBN} prompt to see a list of commands in
1942 this category.
1944 @item COMMAND_TRACEPOINTS
1945 The command has to do with tracepoints.  For example, @code{trace},
1946 @code{actions}, and @code{tfind} are in this category.  Type
1947 @kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
1948 commands in this category.
1950 @item COMMAND_USER
1951 The command is a general purpose command for the user, and typically
1952 does not fit in one of the other categories.
1953 Type @kbd{help user-defined} at the @value{GDBN} prompt to see
1954 a list of commands in this category, as well as the list of gdb macros
1955 (@pxref{Sequences}).
1957 @item COMMAND_OBSCURE
1958 The command is only used in unusual circumstances, or is not of
1959 general interest to users.  For example, @code{checkpoint},
1960 @code{fork}, and @code{stop} are in this category.  Type @kbd{help
1961 obscure} at the @value{GDBN} prompt to see a list of commands in this
1962 category.
1964 @item COMMAND_MAINTENANCE
1965 The command is only useful to @value{GDBN} maintainers.  The
1966 @code{maintenance} and @code{flushregs} commands are in this category.
1967 Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
1968 commands in this category.
1969 @end vtable
1971 A new command can use a predefined completion function, either by
1972 specifying it via an argument at initialization, or by returning it
1973 from the @code{completer} procedure.  These predefined completion
1974 constants are all defined in the @code{gdb} module:
1976 @vtable @code
1977 @item COMPLETE_NONE
1978 This constant means that no completion should be done.
1980 @item COMPLETE_FILENAME
1981 This constant means that filename completion should be performed.
1983 @item COMPLETE_LOCATION
1984 This constant means that location completion should be done.
1985 @xref{Location Specifications}.
1987 @item COMPLETE_COMMAND
1988 This constant means that completion should examine @value{GDBN}
1989 command names.
1991 @item COMPLETE_SYMBOL
1992 This constant means that completion should be done using symbol names
1993 as the source.
1995 @item COMPLETE_EXPRESSION
1996 This constant means that completion should be done on expressions.
1997 Often this means completing on symbol names, but some language
1998 parsers also have support for completing on field names.
1999 @end vtable
2001 The following code snippet shows how a trivial CLI command can be
2002 implemented in Guile:
2004 @smallexample
2005 (gdb) guile
2006 (register-command! (make-command "hello-world"
2007   #:command-class COMMAND_USER
2008   #:doc "Greet the whole world."
2009   #:invoke (lambda (self args from-tty) (display "Hello, World!\n"))))
2011 (gdb) hello-world
2012 Hello, World!
2013 @end smallexample
2015 @node Parameters In Guile
2016 @subsubsection Parameters In Guile
2018 @cindex parameters in guile
2019 @cindex guile parameters
2020 @tindex Parameter
2021 You can implement new @value{GDBN} @dfn{parameters} using Guile
2022 @footnote{Note that @value{GDBN} parameters must not be confused with
2023 Guile’s parameter objects (@pxref{Parameters,,, guile, GNU Guile
2024 Reference Manual}).}.
2026 There are many parameters that already exist and can be set in
2027 @value{GDBN}.  Two examples are: @code{set follow-fork} and
2028 @code{set charset}.  Setting these parameters influences certain
2029 behavior in @value{GDBN}.  Similarly, you can define parameters that
2030 can be used to influence behavior in custom Guile scripts and commands.
2032 A new parameter is defined with the @code{make-parameter} Guile function,
2033 and added to @value{GDBN} with the @code{register-parameter!} Guile function.
2034 This two-step approach is taken to separate out the side-effect of adding
2035 the parameter to @value{GDBN} from @code{make-parameter}.
2037 Parameters are exposed to the user via the @code{set} and
2038 @code{show} commands.  @xref{Help}.
2040 @deffn {Scheme Procedure} make-parameter name @
2041     @w{@r{[}#:command-class command-class@r{]}} @
2042     @w{@r{[}#:parameter-type parameter-type@r{]}} @
2043     @w{@r{[}#:enum-list enum-list@r{]}} @w{@r{[}#:set-func set-func@r{]}} @
2044     @w{@r{[}#:show-func show-func@r{]}} @w{@r{[}#:doc doc@r{]}} @
2045     @w{@r{[}#:set-doc set-doc@r{]}} @w{@r{[}#:show-doc show-doc@r{]}} @
2046     @w{@r{[}#:initial-value initial-value@r{]}}
2048 The argument @var{name} is the name of the new parameter.  If @var{name}
2049 consists of multiple words, then the initial words are looked for as prefix
2050 parameters.  An example of this can be illustrated with the
2051 @code{set print} set of parameters.  If @var{name} is
2052 @code{print foo}, then @code{print} will be searched as the prefix
2053 parameter.  In this case the parameter can subsequently be accessed in
2054 @value{GDBN} as @code{set print foo}.
2055 If @var{name} consists of multiple words, and no prefix parameter group
2056 can be found, an exception is raised.
2058 The result is the @code{<gdb:parameter>} object representing the parameter.
2059 The parameter is not usable until it has been registered with @value{GDBN}
2060 with @code{register-parameter!}.
2062 The rest of the arguments are optional.
2064 The argument @var{command-class} should be one of the @samp{COMMAND_} constants
2065 (@pxref{Commands In Guile}).  This argument tells @value{GDBN} how to
2066 categorize the new parameter in the help system.
2067 The default is @code{COMMAND_NONE}.
2069 The argument @var{parameter-type} should be one of the @samp{PARAM_} constants
2070 defined below.  This argument tells @value{GDBN} the type of the new
2071 parameter; this information is used for input validation and
2072 completion.  The default is @code{PARAM_BOOLEAN}.
2074 If @var{parameter-type} is @code{PARAM_ENUM}, then
2075 @var{enum-list} must be a list of strings.  These strings
2076 represent the possible values for the parameter.
2078 If @var{parameter-type} is not @code{PARAM_ENUM}, then the presence
2079 of @var{enum-list} will cause an exception to be thrown.
2081 The argument @var{set-func} is a function of one argument: @var{self} which
2082 is the @code{<gdb:parameter>} object representing the parameter.
2083 @value{GDBN} will call this function when a @var{parameter}'s value has
2084 been changed via the @code{set} API (for example, @kbd{set foo off}).
2085 The value of the parameter has already been set to the new value.
2086 This function must return a string to be displayed to the user.
2087 @value{GDBN} will add a trailing newline if the string is non-empty.
2088 @value{GDBN} generally doesn't print anything when a parameter is set,
2089 thus typically this function should return @samp{""}.
2090 A non-empty string result should typically be used for displaying warnings
2091 and errors.
2093 The argument @var{show-func} is a function of two arguments: @var{self} which
2094 is the @code{<gdb:parameter>} object representing the parameter, and
2095 @var{svalue} which is the string representation of the current value.
2096 @value{GDBN} will call this function when a @var{parameter}'s
2097 @code{show} API has been invoked (for example, @kbd{show foo}).
2098 This function must return a string, and will be displayed to the user.
2099 @value{GDBN} will add a trailing newline.
2101 The argument @var{doc} is the help text for the new parameter.
2102 If there is no documentation string, a default value is used.
2104 The argument @var{set-doc} is the help text for this parameter's
2105 @code{set} command.
2107 The argument @var{show-doc} is the help text for this parameter's
2108 @code{show} command.
2110 The argument @var{initial-value} specifies the initial value of the parameter.
2111 If it is a function, it takes one parameter, the @code{<gdb:parameter>}
2112 object and its result is used as the initial value of the parameter.
2113 The initial value must be valid for the parameter type,
2114 otherwise an exception is thrown.
2115 @end deffn
2117 @deffn {Scheme Procedure} register-parameter! parameter
2118 Add @var{parameter}, a @code{<gdb:parameter>} object, to @value{GDBN}'s
2119 list of parameters.
2120 It is an error to register a parameter more than once.
2121 The result is unspecified.
2122 @end deffn
2124 @deffn {Scheme Procedure} parameter? object
2125 Return @code{#t} if @var{object} is a @code{<gdb:parameter>} object.
2126 Otherwise return @code{#f}.
2127 @end deffn
2129 @deffn {Scheme Procedure} parameter-value parameter
2130 Return the value of @var{parameter} which may either be
2131 a @code{<gdb:parameter>} object or a string naming the parameter.
2132 @end deffn
2134 @deffn {Scheme Procedure} set-parameter-value! parameter new-value
2135 Assign @var{parameter} the value of @var{new-value}.
2136 The argument @var{parameter} must be an object of type @code{<gdb:parameter>}.
2137 @value{GDBN} does validation when assignments are made.
2138 @end deffn
2140 When a new parameter is defined, its type must be specified.  The
2141 available types are represented by constants defined in the @code{gdb}
2142 module:
2144 @vtable @code
2145 @item PARAM_BOOLEAN
2146 The value is a plain boolean.  The Guile boolean values, @code{#t}
2147 and @code{#f} are the only valid values.
2149 @item PARAM_AUTO_BOOLEAN
2150 The value has three possible states: true, false, and @samp{auto}.  In
2151 Guile, true and false are represented using boolean constants, and
2152 @samp{auto} is represented using @code{#:auto}.
2154 @item PARAM_UINTEGER
2155 The value is an unsigned integer.  The value of @code{#:unlimited}
2156 should be interpreted to mean ``unlimited'', and the value of @samp{0}
2157 is reserved and should not be used.
2159 @item PARAM_ZINTEGER
2160 The value is an integer.
2162 @item PARAM_ZUINTEGER
2163 The value is an unsigned integer.
2165 @item PARAM_ZUINTEGER_UNLIMITED
2166 The value is an integer in the range @samp{[0, INT_MAX]}.  The value
2167 of @code{#:unlimited} means ``unlimited'', the value of @samp{-1} is
2168 reserved and should not be used, and other negative numbers are not
2169 allowed.
2171 @item PARAM_STRING
2172 The value is a string.  When the user modifies the string, any escape
2173 sequences, such as @samp{\t}, @samp{\f}, and octal escapes, are
2174 translated into corresponding characters and encoded into the current
2175 host charset.
2177 @item PARAM_STRING_NOESCAPE
2178 The value is a string.  When the user modifies the string, escapes are
2179 passed through untranslated.
2181 @item PARAM_OPTIONAL_FILENAME
2182 The value is a either a filename (a string), or @code{#f}.
2184 @item PARAM_FILENAME
2185 The value is a filename.  This is just like
2186 @code{PARAM_STRING_NOESCAPE}, but uses file names for completion.
2188 @item PARAM_ENUM
2189 The value is a string, which must be one of a collection of string
2190 constants provided when the parameter is created.
2192 @item PARAM_COLOR
2193 The value is either a string or an unsigned integer.  Integer from 0 to 255
2194 means index into terminal's color palette.  String can be a hex RGB triplet in
2195 @samp{#RRGGBB} format or one of the following color names:
2196 @samp{none} (meaning the terminal's default color), @samp{black}, @samp{red},
2197 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
2198 or @samp{white}.
2199 @end vtable
2201 @node Progspaces In Guile
2202 @subsubsection Program Spaces In Guile
2204 @cindex progspaces in guile
2205 @tindex <gdb:progspace>
2206 A program space, or @dfn{progspace}, represents a symbolic view
2207 of an address space.
2208 It consists of all of the objfiles of the program.
2209 @xref{Objfiles In Guile}.
2210 @xref{Inferiors Connections and Programs, program spaces}, for more details
2211 about program spaces.
2213 Each progspace is represented by an instance of the @code{<gdb:progspace>}
2214 smob.  @xref{GDB Scheme Data Types}.
2216 The following progspace-related functions are available in the
2217 @code{(gdb)} module:
2219 @deffn {Scheme Procedure} progspace? object
2220 Return @code{#t} if @var{object} is a @code{<gdb:progspace>} object.
2221 Otherwise return @code{#f}.
2222 @end deffn
2224 @deffn {Scheme Procedure} progspace-valid? progspace
2225 Return @code{#t} if @var{progspace} is valid, @code{#f} if not.
2226 A @code{<gdb:progspace>} object can become invalid
2227 if the program it refers to is not loaded in @value{GDBN} any longer.
2228 @end deffn
2230 @deffn {Scheme Procedure} current-progspace
2231 This function returns the program space of the currently selected inferior.
2232 There is always a current progspace, this never returns @code{#f}.
2233 @xref{Inferiors Connections and Programs}.
2234 @end deffn
2236 @deffn {Scheme Procedure} progspaces
2237 Return a list of all the progspaces currently known to @value{GDBN}.
2238 @end deffn
2240 @deffn {Scheme Procedure} progspace-filename progspace
2241 Return the absolute file name of @var{progspace} as a string.
2242 This is the name of the file passed as the argument to the @code{file}
2243 or @code{symbol-file} commands.
2244 If the program space does not have an associated file name,
2245 then @code{#f} is returned.  This occurs, for example, when @value{GDBN}
2246 is started without a program to debug.
2248 A @code{gdb:invalid-object-error} exception is thrown if @var{progspace}
2249 is invalid.
2250 @end deffn
2252 @deffn {Scheme Procedure} progspace-objfiles progspace
2253 Return the list of objfiles of @var{progspace}.
2254 The order of objfiles in the result is arbitrary.
2255 Each element is an object of type @code{<gdb:objfile>}.
2256 @xref{Objfiles In Guile}.
2258 A @code{gdb:invalid-object-error} exception is thrown if @var{progspace}
2259 is invalid.
2260 @end deffn
2262 @deffn {Scheme Procedure} progspace-pretty-printers progspace
2263 Return the list of pretty-printers of @var{progspace}.
2264 Each element is an object of type @code{<gdb:pretty-printer>}.
2265 @xref{Guile Pretty Printing API}, for more information.
2266 @end deffn
2268 @deffn {Scheme Procedure} set-progspace-pretty-printers! progspace printer-list
2269 Set the list of registered @code{<gdb:pretty-printer>} objects for
2270 @var{progspace} to @var{printer-list}.
2271 @xref{Guile Pretty Printing API}, for more information.
2272 @end deffn
2274 @node Objfiles In Guile
2275 @subsubsection Objfiles In Guile
2277 @cindex objfiles in guile
2278 @tindex <gdb:objfile>
2279 @value{GDBN} loads symbols for an inferior from various
2280 symbol-containing files (@pxref{Files}).  These include the primary
2281 executable file, any shared libraries used by the inferior, and any
2282 separate debug info files (@pxref{Separate Debug Files}).
2283 @value{GDBN} calls these symbol-containing files @dfn{objfiles}.
2285 Each objfile is represented as an object of type @code{<gdb:objfile>}.
2287 The following objfile-related procedures are provided by the
2288 @code{(gdb)} module:
2290 @deffn {Scheme Procedure} objfile? object
2291 Return @code{#t} if @var{object} is a @code{<gdb:objfile>} object.
2292 Otherwise return @code{#f}.
2293 @end deffn
2295 @deffn {Scheme Procedure} objfile-valid? objfile
2296 Return @code{#t} if @var{objfile} is valid, @code{#f} if not.
2297 A @code{<gdb:objfile>} object can become invalid
2298 if the object file it refers to is not loaded in @value{GDBN} any
2299 longer.  All other @code{<gdb:objfile>} procedures will throw an exception
2300 if it is invalid at the time the procedure is called.
2301 @end deffn
2303 @deffn {Scheme Procedure} objfile-filename objfile
2304 Return the file name of @var{objfile} as a string,
2305 with symbolic links resolved.
2306 @end deffn
2308 @deffn {Scheme Procedure} objfile-progspace objfile
2309 Return the @code{<gdb:progspace>} that this object file lives in.
2310 @xref{Progspaces In Guile}, for more on progspaces.
2311 @end deffn
2313 @deffn {Scheme Procedure} objfile-pretty-printers objfile
2314 Return the list of registered @code{<gdb:pretty-printer>} objects for
2315 @var{objfile}.  @xref{Guile Pretty Printing API}, for more information.
2316 @end deffn
2318 @deffn {Scheme Procedure} set-objfile-pretty-printers! objfile printer-list
2319 Set the list of registered @code{<gdb:pretty-printer>} objects for
2320 @var{objfile} to @var{printer-list}.  The
2321 @var{printer-list} must be a list of @code{<gdb:pretty-printer>} objects.
2322 @xref{Guile Pretty Printing API}, for more information.
2323 @end deffn
2325 @deffn {Scheme Procedure} current-objfile
2326 When auto-loading a Guile script (@pxref{Guile Auto-loading}), @value{GDBN}
2327 sets the ``current objfile'' to the corresponding objfile.  This
2328 function returns the current objfile.  If there is no current objfile,
2329 this function returns @code{#f}.
2330 @end deffn
2332 @deffn {Scheme Procedure} objfiles
2333 Return a list of all the objfiles in the current program space.
2334 @end deffn
2336 @node Frames In Guile
2337 @subsubsection Accessing inferior stack frames from Guile.
2339 @cindex frames in guile
2340 When the debugged program stops, @value{GDBN} is able to analyze its call
2341 stack (@pxref{Frames,,Stack frames}).  The @code{<gdb:frame>} class
2342 represents a frame in the stack.  A @code{<gdb:frame>} object is only valid
2343 while its corresponding frame exists in the inferior's stack.  If you try
2344 to use an invalid frame object, @value{GDBN} will throw a
2345 @code{gdb:invalid-object} exception (@pxref{Guile Exception Handling}).
2347 Two @code{<gdb:frame>} objects can be compared for equality with the
2348 @code{equal?} function, like:
2350 @smallexample
2351 (@value{GDBP}) guile (equal? (newest-frame) (selected-frame))
2353 @end smallexample
2355 The following frame-related procedures are provided by the
2356 @code{(gdb)} module:
2358 @deffn {Scheme Procedure} frame? object
2359 Return @code{#t} if @var{object} is a @code{<gdb:frame>} object.
2360 Otherwise return @code{#f}.
2361 @end deffn
2363 @deffn {Scheme Procedure} frame-valid? frame
2364 Returns @code{#t} if @var{frame} is valid, @code{#f} if not.
2365 A frame object can become invalid if the frame it refers to doesn't
2366 exist anymore in the inferior.  All @code{<gdb:frame>} procedures will throw
2367 an exception if the frame is invalid at the time the procedure is called.
2368 @end deffn
2370 @deffn {Scheme Procedure} frame-name frame
2371 Return the function name of @var{frame}, or @code{#f} if it can't be
2372 obtained.
2373 @end deffn
2375 @deffn {Scheme Procedure} frame-arch frame
2376 Return the @code{<gdb:architecture>} object corresponding to @var{frame}'s
2377 architecture.  @xref{Architectures In Guile}.
2378 @end deffn
2380 @deffn {Scheme Procedure} frame-type frame
2381 Return the type of @var{frame}.  The value can be one of:
2383 @table @code
2384 @item NORMAL_FRAME
2385 An ordinary stack frame.
2387 @item DUMMY_FRAME
2388 A fake stack frame that was created by @value{GDBN} when performing an
2389 inferior function call.
2391 @item INLINE_FRAME
2392 A frame representing an inlined function.  The function was inlined
2393 into a @code{NORMAL_FRAME} that is older than this one.
2395 @item TAILCALL_FRAME
2396 A frame representing a tail call.  @xref{Tail Call Frames}.
2398 @item SIGTRAMP_FRAME
2399 A signal trampoline frame.  This is the frame created by the OS when
2400 it calls into a signal handler.
2402 @item ARCH_FRAME
2403 A fake stack frame representing a cross-architecture call.
2405 @item SENTINEL_FRAME
2406 This is like @code{NORMAL_FRAME}, but it is only used for the
2407 newest frame.
2408 @end table
2409 @end deffn
2411 @deffn {Scheme Procedure} frame-unwind-stop-reason frame
2412 Return an integer representing the reason why it's not possible to find
2413 more frames toward the outermost frame.  Use
2414 @code{unwind-stop-reason-string} to convert the value returned by this
2415 function to a string. The value can be one of:
2417 @table @code
2418 @item FRAME_UNWIND_NO_REASON
2419 No particular reason (older frames should be available).
2421 @item FRAME_UNWIND_NULL_ID
2422 The previous frame's analyzer returns an invalid result.
2424 @item FRAME_UNWIND_OUTERMOST
2425 This frame is the outermost.
2427 @item FRAME_UNWIND_UNAVAILABLE
2428 Cannot unwind further, because that would require knowing the 
2429 values of registers or memory that have not been collected.
2431 @item FRAME_UNWIND_INNER_ID
2432 This frame ID looks like it ought to belong to a NEXT frame,
2433 but we got it for a PREV frame.  Normally, this is a sign of
2434 unwinder failure.  It could also indicate stack corruption.
2436 @item FRAME_UNWIND_SAME_ID
2437 This frame has the same ID as the previous one.  That means
2438 that unwinding further would almost certainly give us another
2439 frame with exactly the same ID, so break the chain.  Normally,
2440 this is a sign of unwinder failure.  It could also indicate
2441 stack corruption.
2443 @item FRAME_UNWIND_NO_SAVED_PC
2444 The frame unwinder did not find any saved PC, but we needed
2445 one to unwind further.
2447 @item FRAME_UNWIND_MEMORY_ERROR
2448 The frame unwinder caused an error while trying to access memory.
2450 @item FRAME_UNWIND_FIRST_ERROR
2451 Any stop reason greater or equal to this value indicates some kind
2452 of error.  This special value facilitates writing code that tests
2453 for errors in unwinding in a way that will work correctly even if
2454 the list of the other values is modified in future @value{GDBN}
2455 versions.  Using it, you could write:
2457 @smallexample
2458 (define reason (frame-unwind-stop-readon (selected-frame)))
2459 (define reason-str (unwind-stop-reason-string reason))
2460 (if (>= reason FRAME_UNWIND_FIRST_ERROR)
2461     (format #t "An error occurred: ~s\n" reason-str))
2462 @end smallexample
2463 @end table
2464 @end deffn
2466 @deffn {Scheme Procedure} frame-pc frame
2467 Return the frame's resume address.
2468 @end deffn
2470 @deffn {Scheme Procedure} frame-block frame
2471 Return the frame's code block as a @code{<gdb:block>} object.
2472 @xref{Blocks In Guile}.
2473 @end deffn
2475 @deffn {Scheme Procedure} frame-function frame
2476 Return the symbol for the function corresponding to this frame
2477 as a @code{<gdb:symbol>} object, or @code{#f} if there isn't one.
2478 @xref{Symbols In Guile}.
2479 @end deffn
2481 @deffn {Scheme Procedure} frame-older frame
2482 Return the frame that called @var{frame}.
2483 @end deffn
2485 @deffn {Scheme Procedure} frame-newer frame
2486 Return the frame called by @var{frame}.
2487 @end deffn
2489 @deffn {Scheme Procedure} frame-sal frame
2490 Return the frame's @code{<gdb:sal>} (symtab and line) object.
2491 @xref{Symbol Tables In Guile}.
2492 @end deffn
2494 @deffn {Scheme Procedure} frame-read-register frame register
2495 Return the value of @var{register} in @var{frame}.  @var{register}
2496 should be a string, like @samp{pc}.
2497 @end deffn
2499 @deffn {Scheme Procedure} frame-read-var frame variable @r{[}#:block block@r{]}
2500 Return the value of @var{variable} in @var{frame}.  If the optional
2501 argument @var{block} is provided, search for the variable from that
2502 block; otherwise start at the frame's current block (which is
2503 determined by the frame's current program counter).  The
2504 @var{variable} must be given as a string or a @code{<gdb:symbol>}
2505 object, and @var{block} must be a @code{<gdb:block>} object.
2506 @end deffn
2508 @deffn {Scheme Procedure} frame-select frame
2509 Set @var{frame} to be the selected frame.  @xref{Stack, ,Examining the
2510 Stack}.
2511 @end deffn
2513 @deffn {Scheme Procedure} selected-frame
2514 Return the selected frame object.  @xref{Selection,,Selecting a Frame}.
2515 @end deffn
2517 @deffn {Scheme Procedure} newest-frame
2518 Return the newest frame object for the selected thread.
2519 @end deffn
2521 @deffn {Scheme Procedure} unwind-stop-reason-string reason
2522 Return a string explaining the reason why @value{GDBN} stopped unwinding
2523 frames, as expressed by the given @var{reason} code (an integer, see the
2524 @code{frame-unwind-stop-reason} procedure above in this section).
2525 @end deffn
2527 @node Blocks In Guile
2528 @subsubsection Accessing blocks from Guile.
2530 @cindex blocks in guile
2531 @tindex <gdb:block>
2533 In @value{GDBN}, symbols are stored in blocks.  A block corresponds
2534 roughly to a scope in the source code.  Blocks are organized
2535 hierarchically, and are represented individually in Guile as an object
2536 of type @code{<gdb:block>}.  Blocks rely on debugging information being
2537 available.
2539 A frame has a block.  Please see @ref{Frames In Guile}, for a more
2540 in-depth discussion of frames.
2542 The outermost block is known as the @dfn{global block}.  The global
2543 block typically holds public global variables and functions.
2545 The block nested just inside the global block is the @dfn{static
2546 block}.  The static block typically holds file-scoped variables and
2547 functions.
2549 @value{GDBN} provides a method to get a block's superblock, but there
2550 is currently no way to examine the sub-blocks of a block, or to
2551 iterate over all the blocks in a symbol table (@pxref{Symbol Tables In
2552 Guile}).
2554 Here is a short example that should help explain blocks:
2556 @smallexample
2557 /* This is in the global block.  */
2558 int global;
2560 /* This is in the static block.  */
2561 static int file_scope;
2563 /* 'function' is in the global block, and 'argument' is
2564    in a block nested inside of 'function'.  */
2565 int function (int argument)
2567   /* 'local' is in a block inside 'function'.  It may or may
2568      not be in the same block as 'argument'.  */
2569   int local;
2571   @{
2572      /* 'inner' is in a block whose superblock is the one holding
2573         'local'.  */
2574      int inner;
2576      /* If this call is expanded by the compiler, you may see
2577         a nested block here whose function is 'inline_function'
2578         and whose superblock is the one holding 'inner'.  */
2579      inline_function ();
2580   @}
2582 @end smallexample
2584 The following block-related procedures are provided by the
2585 @code{(gdb)} module:
2587 @deffn {Scheme Procedure} block? object
2588 Return @code{#t} if @var{object} is a @code{<gdb:block>} object.
2589 Otherwise return @code{#f}.
2590 @end deffn
2592 @deffn {Scheme Procedure} block-valid? block
2593 Returns @code{#t} if @code{<gdb:block>} @var{block} is valid,
2594 @code{#f} if not.  A block object can become invalid if the block it
2595 refers to doesn't exist anymore in the inferior.  All other
2596 @code{<gdb:block>} methods will throw an exception if it is invalid at
2597 the time the procedure is called.  The block's validity is also checked
2598 during iteration over symbols of the block.
2599 @end deffn
2601 @deffn {Scheme Procedure} block-start block
2602 Return the start address of @code{<gdb:block>} @var{block}.
2603 @end deffn
2605 @deffn {Scheme Procedure} block-end block
2606 Return the end address of @code{<gdb:block>} @var{block}.
2607 @end deffn
2609 @deffn {Scheme Procedure} block-function block
2610 Return the name of @code{<gdb:block>} @var{block} represented as a
2611 @code{<gdb:symbol>} object.
2612 If the block is not named, then @code{#f} is returned.
2614 For ordinary function blocks, the superblock is the static block.
2615 However, you should note that it is possible for a function block to
2616 have a superblock that is not the static block -- for instance this
2617 happens for an inlined function.
2618 @end deffn
2620 @deffn {Scheme Procedure} block-superblock block
2621 Return the block containing @code{<gdb:block>} @var{block}.
2622 If the parent block does not exist, then @code{#f} is returned.
2623 @end deffn
2625 @deffn {Scheme Procedure} block-global-block block
2626 Return the global block associated with @code{<gdb:block>} @var{block}.
2627 @end deffn
2629 @deffn {Scheme Procedure} block-static-block block
2630 Return the static block associated with @code{<gdb:block>} @var{block}.
2631 @end deffn
2633 @deffn {Scheme Procedure} block-global? block
2634 Return @code{#t} if @code{<gdb:block>} @var{block} is a global block.
2635 Otherwise return @code{#f}.
2636 @end deffn
2638 @deffn {Scheme Procedure} block-static? block
2639 Return @code{#t} if @code{<gdb:block>} @var{block} is a static block.
2640 Otherwise return @code{#f}.
2641 @end deffn
2643 @deffn {Scheme Procedure} block-symbols
2644 Return a list of all symbols (as <gdb:symbol> objects) in
2645 @code{<gdb:block>} @var{block}.
2646 @end deffn
2648 @deffn {Scheme Procedure} make-block-symbols-iterator block
2649 Return an object of type @code{<gdb:iterator>} that will iterate
2650 over all symbols of the block.
2651 Guile programs should not assume that a specific block object will
2652 always contain a given symbol, since changes in @value{GDBN} features and
2653 infrastructure may cause symbols move across blocks in a symbol table.
2654 @xref{Iterators In Guile}.
2655 @end deffn
2657 @deffn {Scheme Procedure} block-symbols-progress?
2658 Return #t if the object is a <gdb:block-symbols-progress> object.
2659 This object would be obtained from the @code{progress} element of the
2660 @code{<gdb:iterator>} object returned by @code{make-block-symbols-iterator}.
2661 @end deffn
2663 @deffn {Scheme Procedure} lookup-block pc
2664 Return the innermost @code{<gdb:block>} containing the given @var{pc}
2665 value.  If the block cannot be found for the @var{pc} value specified,
2666 the function will return @code{#f}.
2667 @end deffn
2669 @node Symbols In Guile
2670 @subsubsection Guile representation of Symbols.
2672 @cindex symbols in guile
2673 @tindex <gdb:symbol>
2675 @value{GDBN} represents every variable, function and type as an
2676 entry in a symbol table.  @xref{Symbols, ,Examining the Symbol Table}.
2677 Guile represents these symbols in @value{GDBN} with the
2678 @code{<gdb:symbol>} object.
2680 The following symbol-related procedures are provided by the
2681 @code{(gdb)} module:
2683 @deffn {Scheme Procedure} symbol? object
2684 Return @code{#t} if @var{object} is an object of type @code{<gdb:symbol>}.
2685 Otherwise return @code{#f}.
2686 @end deffn
2688 @deffn {Scheme Procedure} symbol-valid? symbol
2689 Return @code{#t} if the @code{<gdb:symbol>} object is valid,
2690 @code{#f} if not.  A @code{<gdb:symbol>} object can become invalid if
2691 the symbol it refers to does not exist in @value{GDBN} any longer.
2692 All other @code{<gdb:symbol>} procedures will throw an exception if it is
2693 invalid at the time the procedure is called.
2694 @end deffn
2696 @deffn {Scheme Procedure} symbol-type symbol
2697 Return the type of @var{symbol} or @code{#f} if no type is recorded.
2698 The result is an object of type @code{<gdb:type>}.
2699 @xref{Types In Guile}.
2700 @end deffn
2702 @deffn {Scheme Procedure} symbol-symtab symbol
2703 Return the symbol table in which @var{symbol} appears.
2704 The result is an object of type @code{<gdb:symtab>}.
2705 @xref{Symbol Tables In Guile}.
2706 @end deffn
2708 @deffn {Scheme Procedure} symbol-line symbol
2709 Return the line number in the source code at which @var{symbol} was defined.
2710 This is an integer.
2711 @end deffn
2713 @deffn {Scheme Procedure} symbol-name symbol
2714 Return the name of @var{symbol} as a string.
2715 @end deffn
2717 @deffn {Scheme Procedure} symbol-linkage-name symbol
2718 Return the name of @var{symbol}, as used by the linker (i.e., may be mangled).
2719 @end deffn
2721 @deffn {Scheme Procedure} symbol-print-name symbol
2722 Return the name of @var{symbol} in a form suitable for output.  This is either
2723 @code{name} or @code{linkage_name}, depending on whether the user
2724 asked @value{GDBN} to display demangled or mangled names.
2725 @end deffn
2727 @deffn {Scheme Procedure} symbol-addr-class symbol
2728 Return the address class of the symbol.  This classifies how to find the value
2729 of a symbol.  Each address class is a constant defined in the
2730 @code{(gdb)} module and described later in this chapter.
2731 @end deffn
2733 @deffn {Scheme Procedure} symbol-needs-frame? symbol
2734 Return @code{#t} if evaluating @var{symbol}'s value requires a frame
2735 (@pxref{Frames In Guile}) and @code{#f} otherwise.  Typically,
2736 local variables will require a frame, but other symbols will not.
2737 @end deffn
2739 @deffn {Scheme Procedure} symbol-argument? symbol
2740 Return @code{#t} if @var{symbol} is an argument of a function.
2741 Otherwise return @code{#f}.
2742 @end deffn
2744 @deffn {Scheme Procedure} symbol-constant? symbol
2745 Return @code{#t} if @var{symbol} is a constant.
2746 Otherwise return @code{#f}.
2747 @end deffn
2749 @deffn {Scheme Procedure} symbol-function? symbol
2750 Return @code{#t} if @var{symbol} is a function or a method.
2751 Otherwise return @code{#f}.
2752 @end deffn
2754 @deffn {Scheme Procedure} symbol-variable? symbol
2755 Return @code{#t} if @var{symbol} is a variable.
2756 Otherwise return @code{#f}.
2757 @end deffn
2759 @deffn {Scheme Procedure} symbol-value symbol @r{[}#:frame frame@r{]}
2760 Compute the value of @var{symbol}, as a @code{<gdb:value>}.  For
2761 functions, this computes the address of the function, cast to the
2762 appropriate type.  If the symbol requires a frame in order to compute
2763 its value, then @var{frame} must be given.  If @var{frame} is not
2764 given, or if @var{frame} is invalid, then an exception is thrown.
2765 @end deffn
2767 @deffn {Scheme Procedure} lookup-symbol name @w{@r{[}#:block block@r{]}} @
2768     @w{@r{[}#:domain domain@r{]}}
2769 This function searches for a symbol by name.  The search scope can be
2770 restricted to the parameters defined in the optional domain and block
2771 arguments.
2773 @var{name} is the name of the symbol.  It must be a string.  The
2774 optional @var{block} argument restricts the search to symbols visible
2775 in that @var{block}.  The @var{block} argument must be a
2776 @code{<gdb:block>} object.  If omitted, the block for the current frame
2777 is used.  The optional @var{domain} argument restricts
2778 the search to the domain type.  The @var{domain} argument must be a
2779 domain constant defined in the @code{(gdb)} module and described later
2780 in this chapter.
2782 The result is a list of two elements.
2783 The first element is a @code{<gdb:symbol>} object or @code{#f} if the symbol
2784 is not found.
2785 If the symbol is found, the second element is @code{#t} if the symbol
2786 is a field of a method's object (e.g., @code{this} in C@t{++}),
2787 otherwise it is @code{#f}.
2788 If the symbol is not found, the second element is @code{#f}.
2789 @end deffn
2791 @deffn {Scheme Procedure} lookup-global-symbol name @r{[}#:domain domain@r{]}
2792 This function searches for a global symbol by name.
2793 The search scope can be restricted by the domain argument.
2795 @var{name} is the name of the symbol.  It must be a string.
2796 The optional @var{domain} argument restricts the search to the domain type.
2797 The @var{domain} argument must be a domain constant defined in the @code{(gdb)}
2798 module and described later in this chapter.
2800 The result is a @code{<gdb:symbol>} object or @code{#f} if the symbol
2801 is not found.
2802 @end deffn
2804 The available domain categories in @code{<gdb:symbol>} are represented
2805 as constants in the @code{(gdb)} module:
2807 @vtable @code
2808 @item SYMBOL_UNDEF_DOMAIN
2809 This is used when a domain has not been discovered or none of the
2810 following domains apply.  This usually indicates an error either
2811 in the symbol information or in @value{GDBN}'s handling of symbols.
2813 @item SYMBOL_VAR_DOMAIN
2814 This domain contains variables, function names, typedef names and enum
2815 type values.
2817 @item SYMBOL_FUNCTION_DOMAIN
2818 This domain contains functions.
2820 @item SYMBOL_TYPE_DOMAIN
2821 This domain contains types.  In a C-like language, types using a tag
2822 (the name appearing after a @code{struct}, @code{union}, or
2823 @code{enum} keyword) will not appear here; in other languages, all
2824 types are in this domain.
2826 @item SYMBOL_STRUCT_DOMAIN
2827 This domain holds struct, union and enum tag names.  This domain is
2828 only used for C-like languages.  For example, in this code:
2829 @smallexample
2830 struct type_one @{ int x; @};
2831 typedef struct type_one type_two;
2832 @end smallexample
2833 Here @code{type_one} will be in @code{SYMBOL_STRUCT_DOMAIN}, but
2834 @code{type_two} will be in @code{SYMBOL_TYPE_DOMAIN}.
2836 @item SYMBOL_LABEL_DOMAIN
2837 This domain contains names of labels (for gotos).
2839 @item SYMBOL_VARIABLES_DOMAIN
2840 This domain holds a subset of the @code{SYMBOLS_VAR_DOMAIN}; it
2841 contains everything minus functions and types.
2843 @item SYMBOL_FUNCTIONS_DOMAIN
2844 This domain contains all functions.
2846 @item SYMBOL_TYPES_DOMAIN
2847 This domain contains all types.
2848 @end vtable
2850 The available address class categories in @code{<gdb:symbol>} are represented
2851 as constants in the @code{gdb} module:
2853 When searching for a symbol, the desired domain constant can be passed
2854 verbatim to the lookup function.
2856 For more complex searches, there is a corresponding set of constants,
2857 each named after one of the preceding constants, but with the
2858 @samp{SEARCH} prefix replacing the @samp{SYMBOL} prefix; for example,
2859 @code{SEARCH_LABEL_DOMAIN}.  These may be or'd together to form a
2860 search constant.
2862 @vtable @code
2863 @item SYMBOL_LOC_UNDEF
2864 If this is returned by address class, it indicates an error either in
2865 the symbol information or in @value{GDBN}'s handling of symbols.
2867 @item SYMBOL_LOC_CONST
2868 Value is constant int.
2870 @item SYMBOL_LOC_STATIC
2871 Value is at a fixed address.
2873 @item SYMBOL_LOC_REGISTER
2874 Value is in a register.
2876 @item SYMBOL_LOC_ARG
2877 Value is an argument.  This value is at the offset stored within the
2878 symbol inside the frame's argument list.
2880 @item SYMBOL_LOC_REF_ARG
2881 Value address is stored in the frame's argument list.  Just like
2882 @code{LOC_ARG} except that the value's address is stored at the
2883 offset, not the value itself.
2885 @item SYMBOL_LOC_REGPARM_ADDR
2886 Value is a specified register.  Just like @code{LOC_REGISTER} except
2887 the register holds the address of the argument instead of the argument
2888 itself.
2890 @item SYMBOL_LOC_LOCAL
2891 Value is a local variable.
2893 @item SYMBOL_LOC_TYPEDEF
2894 Value not used.  Symbols in the domain @code{SYMBOL_STRUCT_DOMAIN} all
2895 have this class.
2897 @item SYMBOL_LOC_BLOCK
2898 Value is a block.
2900 @item SYMBOL_LOC_CONST_BYTES
2901 Value is a byte-sequence.
2903 @item SYMBOL_LOC_UNRESOLVED
2904 Value is at a fixed address, but the address of the variable has to be
2905 determined from the minimal symbol table whenever the variable is
2906 referenced.
2908 @item SYMBOL_LOC_OPTIMIZED_OUT
2909 The value does not actually exist in the program.
2911 @item SYMBOL_LOC_COMPUTED
2912 The value's address is a computed location.
2913 @end vtable
2915 @node Symbol Tables In Guile
2916 @subsubsection Symbol table representation in Guile.
2918 @cindex symbol tables in guile
2919 @tindex <gdb:symtab>
2920 @tindex <gdb:sal>
2922 Access to symbol table data maintained by @value{GDBN} on the inferior
2923 is exposed to Guile via two objects: @code{<gdb:sal>} (symtab-and-line) and
2924 @code{<gdb:symtab>}.  Symbol table and line data for a frame is returned
2925 from the @code{frame-find-sal} @code{<gdb:frame>} procedure.
2926 @xref{Frames In Guile}.
2928 For more information on @value{GDBN}'s symbol table management, see
2929 @ref{Symbols, ,Examining the Symbol Table}.
2931 The following symtab-related procedures are provided by the
2932 @code{(gdb)} module:
2934 @deffn {Scheme Procedure} symtab? object
2935 Return @code{#t} if @var{object} is an object of type @code{<gdb:symtab>}.
2936 Otherwise return @code{#f}.
2937 @end deffn
2939 @deffn {Scheme Procedure} symtab-valid? symtab
2940 Return @code{#t} if the @code{<gdb:symtab>} object is valid,
2941 @code{#f} if not.  A @code{<gdb:symtab>} object becomes invalid when
2942 the symbol table it refers to no longer exists in @value{GDBN}.
2943 All other @code{<gdb:symtab>} procedures will throw an exception
2944 if it is invalid at the time the procedure is called.
2945 @end deffn
2947 @deffn {Scheme Procedure} symtab-filename symtab
2948 Return the symbol table's source filename.
2949 @end deffn
2951 @deffn {Scheme Procedure} symtab-fullname symtab
2952 Return the symbol table's source absolute file name.
2953 @end deffn
2955 @deffn {Scheme Procedure} symtab-objfile symtab
2956 Return the symbol table's backing object file.  @xref{Objfiles In Guile}.
2957 @end deffn
2959 @deffn {Scheme Procedure} symtab-global-block symtab
2960 Return the global block of the underlying symbol table.
2961 @xref{Blocks In Guile}.
2962 @end deffn
2964 @deffn {Scheme Procedure} symtab-static-block symtab
2965 Return the static block of the underlying symbol table.
2966 @xref{Blocks In Guile}.
2967 @end deffn
2969 The following symtab-and-line-related procedures are provided by the
2970 @code{(gdb)} module:
2972 @deffn {Scheme Procedure} sal? object
2973 Return @code{#t} if @var{object} is an object of type @code{<gdb:sal>}.
2974 Otherwise return @code{#f}.
2975 @end deffn
2977 @deffn {Scheme Procedure} sal-valid? sal
2978 Return @code{#t} if @var{sal} is valid, @code{#f} if not.
2979 A @code{<gdb:sal>} object becomes invalid when the Symbol table object
2980 it refers to no longer exists in @value{GDBN}.  All other
2981 @code{<gdb:sal>} procedures will throw an exception if it is
2982 invalid at the time the procedure is called.
2983 @end deffn
2985 @deffn {Scheme Procedure} sal-symtab sal
2986 Return the symbol table object (@code{<gdb:symtab>}) for @var{sal}.
2987 @end deffn
2989 @deffn {Scheme Procedure} sal-line sal
2990 Return the line number for @var{sal}.
2991 @end deffn
2993 @deffn {Scheme Procedure} sal-pc sal
2994 Return the start of the address range occupied by code for @var{sal}.
2995 @end deffn
2997 @deffn {Scheme Procedure} sal-last sal
2998 Return the end of the address range occupied by code for @var{sal}.
2999 @end deffn
3001 @deffn {Scheme Procedure} find-pc-line pc
3002 Return the @code{<gdb:sal>} object corresponding to the @var{pc} value.
3003 If an invalid value of @var{pc} is passed as an argument, then the
3004 @code{symtab} and @code{line} attributes of the returned @code{<gdb:sal>}
3005 object will be @code{#f} and 0 respectively.
3006 @end deffn
3008 @node Breakpoints In Guile
3009 @subsubsection Manipulating breakpoints using Guile
3011 @cindex breakpoints in guile
3012 @tindex <gdb:breakpoint>
3014 Breakpoints in Guile are represented by objects of type
3015 @code{<gdb:breakpoint>}.  New breakpoints can be created with the
3016 @code{make-breakpoint} Guile function, and then added to @value{GDBN} with the
3017 @code{register-breakpoint!} Guile function.
3018 This two-step approach is taken to separate out the side-effect of adding
3019 the breakpoint to @value{GDBN} from @code{make-breakpoint}.
3021 Support is also provided to view and manipulate breakpoints created
3022 outside of Guile.
3024 The following breakpoint-related procedures are provided by the
3025 @code{(gdb)} module:
3027 @deffn {Scheme Procedure} make-breakpoint location @w{@r{[}#:type type@r{]}} @
3028     @w{@r{[}#:wp-class wp-class@r{]}} @w{@r{[}#:internal internal@r{]}} @
3029     @w{@r{[}#:temporary temporary@r{]}}
3030 Create a new breakpoint at @var{location}, a string naming the
3031 location of the breakpoint, or an expression that defines a watchpoint.
3032 The contents can be any location recognized by the @code{break} command,
3033 or in the case of a watchpoint, by the @code{watch} command.
3035 The breakpoint is initially marked as @samp{invalid}.
3036 The breakpoint is not usable until it has been registered with @value{GDBN}
3037 with @code{register-breakpoint!}, at which point it becomes @samp{valid}.
3038 The result is the @code{<gdb:breakpoint>} object representing the breakpoint.
3040 The optional @var{type} denotes the breakpoint to create.
3041 This argument can be either @code{BP_BREAKPOINT} or @code{BP_WATCHPOINT},
3042 and defaults to @code{BP_BREAKPOINT}.
3044 The optional @var{wp-class} argument defines the class of watchpoint to
3045 create, if @var{type} is @code{BP_WATCHPOINT}.  If a watchpoint class is
3046 not provided, it is assumed to be a @code{WP_WRITE} class.
3048 The optional @var{internal} argument allows the breakpoint to become
3049 invisible to the user.  The breakpoint will neither be reported when
3050 registered, nor will it be listed in the output from @code{info breakpoints}
3051 (but will be listed with the @code{maint info breakpoints} command).
3052 If an internal flag is not provided, the breakpoint is visible
3053 (non-internal).
3055 The optional @var{temporary} argument makes the breakpoint a temporary
3056 breakpoint.  Temporary breakpoints are deleted after they have been hit,
3057 after which the Guile breakpoint is no longer usable (although it may be
3058 re-registered with @code{register-breakpoint!}).
3060 When a watchpoint is created, @value{GDBN} will try to create a
3061 hardware assisted watchpoint.  If successful, the type of the watchpoint
3062 is changed from @code{BP_WATCHPOINT} to @code{BP_HARDWARE_WATCHPOINT}
3063 for @code{WP_WRITE}, @code{BP_READ_WATCHPOINT} for @code{WP_READ},
3064 and @code{BP_ACCESS_WATCHPOINT} for @code{WP_ACCESS}.
3065 If not successful, the type of the watchpoint is left as @code{WP_WATCHPOINT}.
3067 The available types are represented by constants defined in the @code{gdb}
3068 module:
3070 @vtable @code
3071 @item BP_BREAKPOINT
3072 Normal code breakpoint.
3074 @item BP_WATCHPOINT
3075 Watchpoint breakpoint.
3077 @item BP_HARDWARE_WATCHPOINT
3078 Hardware assisted watchpoint.
3079 This value cannot be specified when creating the breakpoint.
3081 @item BP_READ_WATCHPOINT
3082 Hardware assisted read watchpoint.
3083 This value cannot be specified when creating the breakpoint.
3085 @item BP_ACCESS_WATCHPOINT
3086 Hardware assisted access watchpoint.
3087 This value cannot be specified when creating the breakpoint.
3089 @item BP_CATCHPOINT
3090 Catchpoint.
3091 This value cannot be specified when creating the breakpoint.
3092 @end vtable
3094 The available watchpoint types are represented by constants defined in the
3095 @code{(gdb)} module:
3097 @vtable @code
3098 @item WP_READ
3099 Read only watchpoint.
3101 @item WP_WRITE
3102 Write only watchpoint.
3104 @item WP_ACCESS
3105 Read/Write watchpoint.
3106 @end vtable
3108 @end deffn
3110 @deffn {Scheme Procedure} register-breakpoint! breakpoint
3111 Add @var{breakpoint}, a @code{<gdb:breakpoint>} object, to @value{GDBN}'s
3112 list of breakpoints.  The breakpoint must have been created with
3113 @code{make-breakpoint}.  One cannot register breakpoints that have been
3114 created outside of Guile.  Once a breakpoint is registered it becomes
3115 @samp{valid}.
3116 It is an error to register an already registered breakpoint.
3117 The result is unspecified.
3118 @end deffn
3120 @deffn {Scheme Procedure} delete-breakpoint! breakpoint
3121 Remove @var{breakpoint} from @value{GDBN}'s list of breakpoints.
3122 This also invalidates the Guile @var{breakpoint} object.
3123 Any further attempt to access the object will throw an exception.
3125 If @var{breakpoint} was created from Guile with @code{make-breakpoint}
3126 it may be re-registered with @value{GDBN}, in which case the breakpoint
3127 becomes valid again.
3128 @end deffn
3130 @deffn {Scheme Procedure} breakpoints
3131 Return a list of all breakpoints.
3132 Each element of the list is a @code{<gdb:breakpoint>} object.
3133 @end deffn
3135 @deffn {Scheme Procedure} breakpoint? object
3136 Return @code{#t} if @var{object} is a @code{<gdb:breakpoint>} object,
3137 and @code{#f} otherwise.
3138 @end deffn
3140 @deffn {Scheme Procedure} breakpoint-valid? breakpoint
3141 Return @code{#t} if @var{breakpoint} is valid, @code{#f} otherwise.
3142 Breakpoints created with @code{make-breakpoint} are marked as invalid
3143 until they are registered with @value{GDBN} with @code{register-breakpoint!}.
3144 A @code{<gdb:breakpoint>} object can become invalid
3145 if the user deletes the breakpoint.  In this case, the object still
3146 exists, but the underlying breakpoint does not.  In the cases of
3147 watchpoint scope, the watchpoint remains valid even if execution of the
3148 inferior leaves the scope of that watchpoint.
3149 @end deffn
3151 @deffn {Scheme Procedure} breakpoint-number breakpoint
3152 Return the breakpoint's number --- the identifier used by
3153 the user to manipulate the breakpoint.
3154 @end deffn
3156 @deffn {Scheme Procedure} breakpoint-temporary? breakpoint
3157 Return @code{#t} if the breakpoint was created as a temporary
3158 breakpoint.  Temporary breakpoints are automatically deleted after
3159 they've been hit.  Calling this procedure, and all other procedures
3160 other than @code{breakpoint-valid?} and @code{register-breakpoint!},
3161 will result in an error after the breakpoint has been hit (since it has
3162 been automatically deleted).
3163 @end deffn
3165 @deffn {Scheme Procedure} breakpoint-type breakpoint
3166 Return the breakpoint's type --- the identifier used to
3167 determine the actual breakpoint type or use-case.
3168 @end deffn
3170 @deffn {Scheme Procedure} breakpoint-visible? breakpoint
3171 Return @code{#t} if the breakpoint is visible to the user
3172 when hit, or when the @samp{info breakpoints} command is run.
3173 Otherwise return @code{#f}.
3174 @end deffn
3176 @deffn {Scheme Procedure} breakpoint-location breakpoint
3177 Return the location of the breakpoint, as specified by
3178 the user.  It is a string.  If the breakpoint does not have a location
3179 (that is, it is a watchpoint) return @code{#f}.
3180 @end deffn
3182 @deffn {Scheme Procedure} breakpoint-expression breakpoint
3183 Return the breakpoint expression, as specified by the user.  It is a string.
3184 If the breakpoint does not have an expression (the breakpoint is not a
3185 watchpoint) return @code{#f}.
3186 @end deffn
3188 @deffn {Scheme Procedure} breakpoint-enabled? breakpoint
3189 Return @code{#t} if the breakpoint is enabled, and @code{#f} otherwise.
3190 @end deffn
3192 @deffn {Scheme Procedure} set-breakpoint-enabled! breakpoint flag
3193 Set the enabled state of @var{breakpoint} to @var{flag}.
3194 If flag is @code{#f} it is disabled, otherwise it is enabled.
3195 @end deffn
3197 @deffn {Scheme Procedure} breakpoint-silent? breakpoint
3198 Return @code{#t} if the breakpoint is silent, and @code{#f} otherwise.
3200 Note that a breakpoint can also be silent if it has commands and the
3201 first command is @code{silent}.  This is not reported by the
3202 @code{silent} attribute.
3203 @end deffn
3205 @deffn {Scheme Procedure} set-breakpoint-silent! breakpoint flag
3206 Set the silent state of @var{breakpoint} to @var{flag}.
3207 If flag is @code{#f} the breakpoint is made silent,
3208 otherwise it is made non-silent (or noisy).
3209 @end deffn
3211 @deffn {Scheme Procedure} breakpoint-ignore-count breakpoint
3212 Return the ignore count for @var{breakpoint}.
3213 @end deffn
3215 @deffn {Scheme Procedure} set-breakpoint-ignore-count! breakpoint count
3216 Set the ignore count for @var{breakpoint} to @var{count}.
3217 @end deffn
3219 @deffn {Scheme Procedure} breakpoint-hit-count breakpoint
3220 Return hit count of @var{breakpoint}.
3221 @end deffn
3223 @deffn {Scheme Procedure} set-breakpoint-hit-count! breakpoint count
3224 Set the hit count of @var{breakpoint} to @var{count}.
3225 At present, @var{count} must be zero.
3226 @end deffn
3228 @deffn {Scheme Procedure} breakpoint-thread breakpoint
3229 Return the global-thread-id for thread-specific breakpoint
3230 @var{breakpoint}.  Return #f if @var{breakpoint} is not
3231 thread-specific.
3232 @end deffn
3234 @deffn {Scheme Procedure} set-breakpoint-thread! breakpoint global-thread-id|#f
3235 Set the thread-id for @var{breakpoint} to @var{global-thread-id} If
3236 set to @code{#f}, the breakpoint is no longer thread-specific.
3237 @end deffn
3239 @deffn {Scheme Procedure} breakpoint-task breakpoint
3240 If the breakpoint is Ada task-specific, return the Ada task id.
3241 If the breakpoint is not task-specific (or the underlying
3242 language is not Ada), return @code{#f}.
3243 @end deffn
3245 @deffn {Scheme Procedure} set-breakpoint-task! breakpoint task
3246 Set the Ada task of @var{breakpoint} to @var{task}.
3247 If set to @code{#f}, the breakpoint is no longer task-specific.
3248 @end deffn
3250 @deffn {Scheme Procedure} breakpoint-condition breakpoint
3251 Return the condition of @var{breakpoint}, as specified by the user.
3252 It is a string.  If there is no condition, return @code{#f}.
3253 @end deffn
3255 @deffn {Scheme Procedure} set-breakpoint-condition! breakpoint condition
3256 Set the condition of @var{breakpoint} to @var{condition},
3257 which must be a string.  If set to @code{#f} then the breakpoint
3258 becomes unconditional.
3259 @end deffn
3261 @deffn {Scheme Procedure} breakpoint-stop breakpoint
3262 Return the stop predicate of @var{breakpoint}.
3263 See @code{set-breakpoint-stop!} below in this section.
3264 @end deffn
3266 @deffn {Scheme Procedure} set-breakpoint-stop! breakpoint procedure|#f
3267 Set the stop predicate of @var{breakpoint}.  The predicate
3268 @var{procedure} takes one argument: the <gdb:breakpoint> object.
3269 If this predicate is set to a procedure then it is invoked whenever
3270 the inferior reaches this breakpoint.  If it returns @code{#t},
3271 or any non-@code{#f} value, then the inferior is stopped,
3272 otherwise the inferior will continue.
3274 If there are multiple breakpoints at the same location with a
3275 @code{stop} predicate, each one will be called regardless of the
3276 return status of the previous.  This ensures that all @code{stop}
3277 predicates have a chance to execute at that location.  In this scenario
3278 if one of the methods returns @code{#t} but the others return
3279 @code{#f}, the inferior will still be stopped.
3281 You should not alter the execution state of the inferior (i.e.@:, step,
3282 next, etc.), alter the current frame context (i.e.@:, change the current
3283 active frame), or alter, add or delete any breakpoint.  As a general
3284 rule, you should not alter any data within @value{GDBN} or the inferior
3285 at this time.
3287 Example @code{stop} implementation:
3289 @smallexample
3290 (define (my-stop? bkpt)
3291   (let ((int-val (parse-and-eval "foo")))
3292     (value=? int-val 3)))
3293 (define bkpt (make-breakpoint "main.c:42"))
3294 (register-breakpoint! bkpt)
3295 (set-breakpoint-stop! bkpt my-stop?)
3296 @end smallexample
3297 @end deffn
3299 @deffn {Scheme Procedure} breakpoint-commands breakpoint
3300 Return the commands attached to @var{breakpoint} as a string,
3301 or @code{#f} if there are none.
3302 @end deffn
3304 @node Lazy Strings In Guile
3305 @subsubsection Guile representation of lazy strings.
3307 @cindex lazy strings in guile
3308 @tindex <gdb:lazy-string>
3310 A @dfn{lazy string} is a string whose contents is not retrieved or
3311 encoded until it is needed.
3313 A @code{<gdb:lazy-string>} is represented in @value{GDBN} as an
3314 @code{address} that points to a region of memory, an @code{encoding}
3315 that will be used to encode that region of memory, and a @code{length}
3316 to delimit the region of memory that represents the string.  The
3317 difference between a @code{<gdb:lazy-string>} and a string wrapped within
3318 a @code{<gdb:value>} is that a @code{<gdb:lazy-string>} will be treated
3319 differently by @value{GDBN} when printing.  A @code{<gdb:lazy-string>} is
3320 retrieved and encoded during printing, while a @code{<gdb:value>}
3321 wrapping a string is immediately retrieved and encoded on creation.
3323 The following lazy-string-related procedures are provided by the
3324 @code{(gdb)} module:
3326 @deffn {Scheme Procedure} lazy-string? object
3327 Return @code{#t} if @var{object} is an object of type @code{<gdb:lazy-string>}.
3328 Otherwise return @code{#f}.
3329 @end deffn
3331 @deffn {Scheme Procedure} lazy-string-address lazy-sring
3332 Return the address of @var{lazy-string}.
3333 @end deffn
3335 @deffn {Scheme Procedure} lazy-string-length lazy-string
3336 Return the length of @var{lazy-string} in characters.  If the
3337 length is -1, then the string will be fetched and encoded up to the
3338 first null of appropriate width.
3339 @end deffn
3341 @deffn {Scheme Procedure} lazy-string-encoding lazy-string
3342 Return the encoding that will be applied to @var{lazy-string}
3343 when the string is printed by @value{GDBN}.  If the encoding is not
3344 set, or contains an empty string,  then @value{GDBN} will select the
3345 most appropriate encoding when the string is printed.
3346 @end deffn
3348 @deffn {Scheme Procedure} lazy-string-type lazy-string
3349 Return the type that is represented by @var{lazy-string}'s type.
3350 For a lazy string this is a pointer or array type.  To
3351 resolve this to the lazy string's character type, use @code{type-target-type}.
3352 @xref{Types In Guile}.
3353 @end deffn
3355 @deffn {Scheme Procedure} lazy-string->value lazy-string
3356 Convert the @code{<gdb:lazy-string>} to a @code{<gdb:value>}.  This value
3357 will point to the string in memory, but will lose all the delayed
3358 retrieval, encoding and handling that @value{GDBN} applies to a
3359 @code{<gdb:lazy-string>}.
3360 @end deffn
3362 @node Architectures In Guile
3363 @subsubsection Guile representation of architectures
3365 @cindex guile architectures
3366 @tindex <gdb:arch>
3368 @value{GDBN} uses architecture specific parameters and artifacts in a
3369 number of its various computations.  An architecture is represented
3370 by an instance of the @code{<gdb:arch>} class.
3372 The following architecture-related procedures are provided by the
3373 @code{(gdb)} module:
3375 @deffn {Scheme Procedure} arch? object
3376 Return @code{#t} if @var{object} is an object of type @code{<gdb:arch>}.
3377 Otherwise return @code{#f}.
3378 @end deffn
3380 @deffn {Scheme Procedure} current-arch
3381 Return the current architecture as a @code{<gdb:arch>} object.
3382 @end deffn
3384 @deffn {Scheme Procedure} arch-name arch
3385 Return the name (string value) of @code{<gdb:arch>} @var{arch}.
3386 @end deffn
3388 @deffn {Scheme Procedure} arch-charset arch
3389 Return name of target character set of @code{<gdb:arch>} @var{arch}.
3390 @end deffn
3392 @deffn {Scheme Procedure} arch-wide-charset
3393 Return name of target wide character set of @code{<gdb:arch>} @var{arch}.
3394 @end deffn
3396 Each architecture provides a set of predefined types, obtained by
3397 the following functions.
3399 @deffn {Scheme Procedure} arch-void-type arch
3400 Return the @code{<gdb:type>} object for a @code{void} type
3401 of architecture @var{arch}.
3402 @end deffn
3404 @deffn {Scheme Procedure} arch-char-type arch
3405 Return the @code{<gdb:type>} object for a @code{char} type
3406 of architecture @var{arch}.
3407 @end deffn
3409 @deffn {Scheme Procedure} arch-short-type arch
3410 Return the @code{<gdb:type>} object for a @code{short} type
3411 of architecture @var{arch}.
3412 @end deffn
3414 @deffn {Scheme Procedure} arch-int-type arch
3415 Return the @code{<gdb:type>} object for an @code{int} type
3416 of architecture @var{arch}.
3417 @end deffn
3419 @deffn {Scheme Procedure} arch-long-type arch
3420 Return the @code{<gdb:type>} object for a @code{long} type
3421 of architecture @var{arch}.
3422 @end deffn
3424 @deffn {Scheme Procedure} arch-schar-type arch
3425 Return the @code{<gdb:type>} object for a @code{signed char} type
3426 of architecture @var{arch}.
3427 @end deffn
3429 @deffn {Scheme Procedure} arch-uchar-type arch
3430 Return the @code{<gdb:type>} object for an @code{unsigned char} type
3431 of architecture @var{arch}.
3432 @end deffn
3434 @deffn {Scheme Procedure} arch-ushort-type arch
3435 Return the @code{<gdb:type>} object for an @code{unsigned short} type
3436 of architecture @var{arch}.
3437 @end deffn
3439 @deffn {Scheme Procedure} arch-uint-type arch
3440 Return the @code{<gdb:type>} object for an @code{unsigned int} type
3441 of architecture @var{arch}.
3442 @end deffn
3444 @deffn {Scheme Procedure} arch-ulong-type arch
3445 Return the @code{<gdb:type>} object for an @code{unsigned long} type
3446 of architecture @var{arch}.
3447 @end deffn
3449 @deffn {Scheme Procedure} arch-float-type arch
3450 Return the @code{<gdb:type>} object for a @code{float} type
3451 of architecture @var{arch}.
3452 @end deffn
3454 @deffn {Scheme Procedure} arch-double-type arch
3455 Return the @code{<gdb:type>} object for a @code{double} type
3456 of architecture @var{arch}.
3457 @end deffn
3459 @deffn {Scheme Procedure} arch-longdouble-type arch
3460 Return the @code{<gdb:type>} object for a @code{long double} type
3461 of architecture @var{arch}.
3462 @end deffn
3464 @deffn {Scheme Procedure} arch-bool-type arch
3465 Return the @code{<gdb:type>} object for a @code{bool} type
3466 of architecture @var{arch}.
3467 @end deffn
3469 @deffn {Scheme Procedure} arch-longlong-type arch
3470 Return the @code{<gdb:type>} object for a @code{long long} type
3471 of architecture @var{arch}.
3472 @end deffn
3474 @deffn {Scheme Procedure} arch-ulonglong-type arch
3475 Return the @code{<gdb:type>} object for an @code{unsigned long long} type
3476 of architecture @var{arch}.
3477 @end deffn
3479 @deffn {Scheme Procedure} arch-int8-type arch
3480 Return the @code{<gdb:type>} object for an @code{int8} type
3481 of architecture @var{arch}.
3482 @end deffn
3484 @deffn {Scheme Procedure} arch-uint8-type arch
3485 Return the @code{<gdb:type>} object for a @code{uint8} type
3486 of architecture @var{arch}.
3487 @end deffn
3489 @deffn {Scheme Procedure} arch-int16-type arch
3490 Return the @code{<gdb:type>} object for an @code{int16} type
3491 of architecture @var{arch}.
3492 @end deffn
3494 @deffn {Scheme Procedure} arch-uint16-type arch
3495 Return the @code{<gdb:type>} object for a @code{uint16} type
3496 of architecture @var{arch}.
3497 @end deffn
3499 @deffn {Scheme Procedure} arch-int32-type arch
3500 Return the @code{<gdb:type>} object for an @code{int32} type
3501 of architecture @var{arch}.
3502 @end deffn
3504 @deffn {Scheme Procedure} arch-uint32-type arch
3505 Return the @code{<gdb:type>} object for a @code{uint32} type
3506 of architecture @var{arch}.
3507 @end deffn
3509 @deffn {Scheme Procedure} arch-int64-type arch
3510 Return the @code{<gdb:type>} object for an @code{int64} type
3511 of architecture @var{arch}.
3512 @end deffn
3514 @deffn {Scheme Procedure} arch-uint64-type arch
3515 Return the @code{<gdb:type>} object for a @code{uint64} type
3516 of architecture @var{arch}.
3517 @end deffn
3519 Example:
3521 @smallexample
3522 (gdb) guile (type-name (arch-uchar-type (current-arch)))
3523 "unsigned char"
3524 @end smallexample
3526 @node Disassembly In Guile
3527 @subsubsection Disassembly In Guile
3529 The disassembler can be invoked from Scheme code.
3530 Furthermore, the disassembler can take a Guile port as input,
3531 allowing one to disassemble from any source, and not just target memory.
3533 @deffn {Scheme Procedure} arch-disassemble arch start-pc @
3534     @w{@r{[}#:port port@r{]}} @w{@r{[}#:offset offset@r{]}} @
3535     @w{@r{[}#:size size@r{]}} @w{@r{[}#:count count@r{]}}
3536 Return a list of disassembled instructions starting from the memory
3537 address @var{start-pc}.
3539 The optional argument @var{port} specifies the input port to read bytes from.
3540 If @var{port} is @code{#f} then bytes are read from target memory.
3542 The optional argument @var{offset} specifies the address offset of the
3543 first byte in @var{port}.  This is useful, for example, when @var{port}
3544 specifies a @samp{bytevector} and you want the bytevector to be disassembled
3545 as if it came from that address.  The @var{start-pc} passed to the reader
3546 for @var{port} is offset by the same amount.
3548 Example:
3549 @smallexample
3550 (gdb) guile (use-modules (rnrs io ports))
3551 (gdb) guile (define pc (value->integer (parse-and-eval "$pc")))
3552 (gdb) guile (define mem (open-memory #:start pc))
3553 (gdb) guile (define bv (get-bytevector-n mem 10))
3554 (gdb) guile (define bv-port (open-bytevector-input-port bv))
3555 (gdb) guile (define arch (current-arch))
3556 (gdb) guile (arch-disassemble arch pc #:port bv-port #:offset pc)
3557 (((address . 4195516) (asm . "mov    $0x4005c8,%edi") (length . 5)))
3558 @end smallexample
3560 The optional arguments @var{size} and
3561 @var{count} determine the number of instructions in the returned list.
3562 If either @var{size} or @var{count} is specified as zero, then
3563 no instructions are disassembled and an empty list is returned.
3564 If both the optional arguments @var{size} and @var{count} are
3565 specified, then a list of at most @var{count} disassembled instructions
3566 whose start address falls in the closed memory address interval from
3567 @var{start-pc} to (@var{start-pc} + @var{size} - 1) are returned.
3568 If @var{size} is not specified, but @var{count} is specified,
3569 then @var{count} number of instructions starting from the address
3570 @var{start-pc} are returned.  If @var{count} is not specified but
3571 @var{size} is specified, then all instructions whose start address
3572 falls in the closed memory address interval from @var{start-pc} to
3573 (@var{start-pc} + @var{size} - 1) are returned.
3574 If neither @var{size} nor @var{count} are specified, then a single
3575 instruction at @var{start-pc} is returned.
3577 Each element of the returned list is an alist (associative list)
3578 with the following keys:
3580 @table @code
3582 @item address
3583 The value corresponding to this key is a Guile integer of
3584 the memory address of the instruction.
3586 @item asm
3587 The value corresponding to this key is a string value which represents
3588 the instruction with assembly language mnemonics.  The assembly
3589 language flavor used is the same as that specified by the current CLI
3590 variable @code{disassembly-flavor}.  @xref{Machine Code}.
3592 @item length
3593 The value corresponding to this key is the length of the instruction in bytes.
3595 @end table
3596 @end deffn
3598 @node I/O Ports in Guile
3599 @subsubsection I/O Ports in Guile
3601 @deffn {Scheme Procedure} input-port
3602 Return @value{GDBN}'s input port as a Guile port object.
3603 @end deffn
3605 @deffn {Scheme Procedure} output-port
3606 Return @value{GDBN}'s output port as a Guile port object.
3607 @end deffn
3609 @deffn {Scheme Procedure} error-port
3610 Return @value{GDBN}'s error port as a Guile port object.
3611 @end deffn
3613 @deffn {Scheme Procedure} stdio-port? object
3614 Return @code{#t} if @var{object} is a @value{GDBN} stdio port.
3615 Otherwise return @code{#f}.
3616 @end deffn
3618 @node Memory Ports in Guile
3619 @subsubsection Memory Ports in Guile
3621 @value{GDBN} provides a @code{port} interface to target memory.
3622 This allows Guile code to read/write target memory using Guile's port and
3623 bytevector functionality.  The main routine is @code{open-memory} which
3624 returns a port object.  One can then read/write memory using that object.
3626 @deffn {Scheme Procedure} open-memory @w{@r{[}#:mode mode@r{]}} @
3627     @w{@r{[}#:start address@r{]}} @w{@r{[}#:size size@r{]}}
3628 Return a port object that can be used for reading and writing memory.
3629 The port will be open according to @var{mode}, which is the standard
3630 mode argument to Guile port open routines, except that the @samp{"a"}
3631 and @samp{"l"} modes are not supported.
3632 @xref{File Ports,,, guile, GNU Guile Reference Manual}.
3633 The @samp{"b"} (binary) character may be present, but is ignored:
3634 memory ports are binary only.  If @samp{"0"} is appended then
3635 the port is marked as unbuffered.
3636 The default is @samp{"r"}, read-only and buffered.
3638 The chunk of memory that can be accessed can be bounded.
3639 If both @var{start} and @var{size} are unspecified, all of memory can be
3640 accessed.  If only @var{start} is specified, all of memory from that point
3641 on can be accessed.  If only @var{size} if specified, all memory in the
3642 range [0,@var{size}) can be accessed.  If both are specified, all memory
3643 in the rane [@var{start},@var{start}+@var{size}) can be accessed.
3644 @end deffn
3646 @deffn {Scheme Procedure} memory-port?
3647 Return @code{#t} if @var{object} is an object of type @code{<gdb:memory-port>}.
3648 Otherwise return @code{#f}.
3649 @end deffn
3651 @deffn {Scheme Procedure} memory-port-range memory-port
3652 Return the range of @code{<gdb:memory-port>} @var{memory-port} as a list
3653 of two elements: @code{(start end)}.  The range is @var{start} to @var{end}
3654 inclusive.
3655 @end deffn
3657 @deffn {Scheme Procedure} memory-port-read-buffer-size memory-port
3658 Return the size of the read buffer of @code{<gdb:memory-port>}
3659 @var{memory-port}.
3661 This procedure is deprecated and will be removed in @value{GDBN} 11.
3662 It returns 0 when using Guile 2.2 or later.
3663 @end deffn
3665 @deffn {Scheme Procedure} set-memory-port-read-buffer-size! memory-port size
3666 Set the size of the read buffer of @code{<gdb:memory-port>}
3667 @var{memory-port} to @var{size}.  The result is unspecified.
3669 This procedure is deprecated and will be removed in @value{GDBN} 11.
3670 When @value{GDBN} is built with Guile 2.2 or later, you can call
3671 @code{setvbuf} instead (@pxref{Buffering, @code{setvbuf},, guile, GNU
3672 Guile Reference Manual}).
3673 @end deffn
3675 @deffn {Scheme Procedure} memory-port-write-buffer-size memory-port
3676 Return the size of the write buffer of @code{<gdb:memory-port>}
3677 @var{memory-port}.
3679 This procedure is deprecated and will be removed in @value{GDBN} 11.
3680 It returns 0 when @value{GDBN} is built with Guile 2.2 or later.
3681 @end deffn
3683 @deffn {Scheme Procedure} set-memory-port-write-buffer-size! memory-port size
3684 Set the size of the write buffer of @code{<gdb:memory-port>}
3685 @var{memory-port} to @var{size}.  The result is unspecified.
3687 This procedure is deprecated and will be removed in @value{GDBN} 11.
3688 When @value{GDBN} is built with Guile 2.2 or later, you can call
3689 @code{setvbuf} instead.
3690 @end deffn
3692 A memory port is closed like any other port, with @code{close-port}.
3694 Combined with Guile's @code{bytevectors}, memory ports provide a lot
3695 of utility.  For example, to fill a buffer of 10 integers in memory,
3696 one can do something like the following.
3698 @smallexample
3699 ;; In the program: int buffer[10];
3700 (use-modules (rnrs bytevectors))
3701 (use-modules (rnrs io ports))
3702 (define addr (parse-and-eval "buffer"))
3703 (define n 10)
3704 (define byte-size (* n 4))
3705 (define mem-port (open-memory #:mode "r+" #:start
3706                               (value->integer addr) #:size byte-size))
3707 (define byte-vec (make-bytevector byte-size))
3708 (do ((i 0 (+ i 1)))
3709     ((>= i n))
3710     (bytevector-s32-native-set! byte-vec (* i 4) (* i 42)))
3711 (put-bytevector mem-port byte-vec)
3712 (close-port mem-port)
3713 @end smallexample
3715 @node Iterators In Guile
3716 @subsubsection Iterators In Guile
3718 @cindex guile iterators
3719 @tindex <gdb:iterator>
3721 A simple iterator facility is provided to allow, for example,
3722 iterating over the set of program symbols without having to first
3723 construct a list of all of them.  A useful contribution would be
3724 to add support for SRFI 41 and SRFI 45.
3726 @deffn {Scheme Procedure} make-iterator object progress next!
3727 A @code{<gdb:iterator>} object is constructed with the @code{make-iterator}
3728 procedure.  It takes three arguments: the object to be iterated over,
3729 an object to record the progress of the iteration, and a procedure to
3730 return the next element in the iteration, or an implementation chosen value
3731 to denote the end of iteration.
3733 By convention, end of iteration is marked with @code{(end-of-iteration)},
3734 and may be tested with the @code{end-of-iteration?} predicate.
3735 The result of @code{(end-of-iteration)} is chosen so that it is not
3736 otherwise used by the @code{(gdb)} module.  If you are using
3737 @code{<gdb:iterator>} in your own code it is your responsibility to
3738 maintain this invariant.
3740 A trivial example for illustration's sake:
3742 @smallexample
3743 (use-modules (gdb iterator))
3744 (define my-list (list 1 2 3))
3745 (define iter
3746   (make-iterator my-list my-list
3747                  (lambda (iter)
3748                    (let ((l (iterator-progress iter)))
3749                      (if (eq? l '())
3750                          (end-of-iteration)
3751                          (begin
3752                            (set-iterator-progress! iter (cdr l))
3753                            (car l)))))))
3754 @end smallexample
3756 Here is a slightly more realistic example, which computes a list of all the
3757 functions in @code{my-global-block}.
3759 @smallexample
3760 (use-modules (gdb iterator))
3761 (define this-sal (find-pc-line (frame-pc (selected-frame))))
3762 (define this-symtab (sal-symtab this-sal))
3763 (define this-global-block (symtab-global-block this-symtab))
3764 (define syms-iter (make-block-symbols-iterator this-global-block))
3765 (define functions (iterator-filter symbol-function? syms-iter))
3766 @end smallexample
3767 @end deffn
3769 @deffn {Scheme Procedure} iterator? object
3770 Return @code{#t} if @var{object} is a @code{<gdb:iterator>} object.
3771 Otherwise return @code{#f}.
3772 @end deffn
3774 @deffn {Scheme Procedure} iterator-object iterator
3775 Return the first argument that was passed to @code{make-iterator}.
3776 This is the object being iterated over.
3777 @end deffn
3779 @deffn {Scheme Procedure} iterator-progress iterator
3780 Return the object tracking iteration progress.
3781 @end deffn
3783 @deffn {Scheme Procedure} set-iterator-progress! iterator new-value
3784 Set the object tracking iteration progress.
3785 @end deffn
3787 @deffn {Scheme Procedure} iterator-next! iterator
3788 Invoke the procedure that was the third argument to @code{make-iterator},
3789 passing it one argument, the @code{<gdb:iterator>} object.
3790 The result is either the next element in the iteration, or an end
3791 marker as implemented by the @code{next!} procedure.
3792 By convention the end marker is the result of @code{(end-of-iteration)}.
3793 @end deffn
3795 @deffn {Scheme Procedure} end-of-iteration
3796 Return the Scheme object that denotes end of iteration.
3797 @end deffn
3799 @deffn {Scheme Procedure} end-of-iteration? object
3800 Return @code{#t} if @var{object} is the end of iteration marker.
3801 Otherwise return @code{#f}.
3802 @end deffn
3804 These functions are provided by the @code{(gdb iterator)} module to
3805 assist in using iterators.
3807 @deffn {Scheme Procedure} make-list-iterator list
3808 Return a @code{<gdb:iterator>} object that will iterate over @var{list}.
3809 @end deffn
3811 @deffn {Scheme Procedure} iterator->list iterator
3812 Return the elements pointed to by @var{iterator} as a list.
3813 @end deffn
3815 @deffn {Scheme Procedure} iterator-map proc iterator
3816 Return the list of objects obtained by applying @var{proc} to the object
3817 pointed to by @var{iterator} and to each subsequent object.
3818 @end deffn
3820 @deffn {Scheme Procedure} iterator-for-each proc iterator
3821 Apply @var{proc} to each element pointed to by @var{iterator}.
3822 The result is unspecified.
3823 @end deffn
3825 @deffn {Scheme Procedure} iterator-filter pred iterator
3826 Return the list of elements pointed to by @var{iterator} that satisfy
3827 @var{pred}.
3828 @end deffn
3830 @deffn {Scheme Procedure} iterator-until pred iterator
3831 Run @var{iterator} until the result of @code{(pred element)} is true
3832 and return that as the result.  Otherwise return @code{#f}.
3833 @end deffn
3835 @node Colors In Guile
3836 @subsubsection Colors In Guile
3838 @cindex guile colors
3839 @tindex <gdb:color>
3840 You can assign instance of @code{<gdb:color>} to the value of
3841 a @code{<gdb:parameter>} object created with @code{PARAM_COLOR}.
3843 @code{<gdb:color>} may refer to an index from color palette or contain
3844 components of a color from some colorspace.
3846 @deffn {Scheme Procedure} make-color @w{@r{[}value} @
3847     @w{@r{[}#:color-space color-space@r{]}@r{]}}
3849 @var{value} is an integer index of a color in palette, tuple with color
3850 components or a string.  String can be a hex RGB triplet in @samp{#RRGGBB}
3851 format or one of the following color names:
3852 @samp{none} (meaning the terminal's default color), @samp{black}, @samp{red},
3853 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
3854 or @samp{white}.
3856 @var{color-space} should be one of the @samp{COLORSPACE_} constants.  This
3857 argument tells @value{GDBN} which color space @var{value} belongs.
3858 @end deffn
3860 @deffn {Scheme Procedure} color? object
3861 Return @code{#t} if @var{object} is a @code{<gdb:color>} object.
3862 Otherwise return @code{#f}.
3863 @end deffn
3865 @deffn {Scheme Procedure} color-none? color
3866 Return @code{#t} if @var{color} is terminal's default.
3867 Otherwise return @code{#f}.
3868 @end deffn
3870 @deffn {Scheme Procedure} color-indexed? color
3871 Return @code{#t} if @var{color} is indexed, i.e. belongs to some palette.
3872 Otherwise return @code{#f}.
3873 @end deffn
3875 @deffn {Scheme Procedure} color-direct? color
3876 Return @code{#t} if @var{color} is direct in the sense of ISO/IEC 8613-6.
3877 Otherwise return @code{#f}.
3878 @end deffn
3880 @deffn {Scheme Procedure} color-string color
3881 Return the textual representation of a @code{<gdb:color>} object.
3882 @end deffn
3884 @deffn {Scheme Procedure} color-colorspace color
3885 Return the color space of a @code{<gdb:color>} object.
3886 @end deffn
3888 @deffn {Scheme Procedure} color-index color
3889 Return index of the color of a @code{<gdb:color>} object in a palette.
3890 @end deffn
3892 @deffn {Scheme Procedure} color-components color
3893 Return components of the direct @code{<gdb:color>} object.
3894 @end deffn
3896 @deffn {Scheme Procedure} color-escape-sequence color is_foreground
3897 Return string to change terminal's color to this.
3899 If @var{is_foreground} is @code{#t}, then the returned sequence will change
3900 foreground color.  Otherwise, the returned sequence will change background
3901 color.
3902 @end deffn
3904 When color is initialized, its color space must be specified.  The
3905 available color spaces are represented by constants defined in the @code{gdb}
3906 module:
3908 @vtable @code
3909 @item COLORSPACE_MONOCHROME
3910 Palette with only terminal's default color.
3912 @item COLORSPACE_ANSI_8COLOR
3913 Palette with eight standard colors of ISO/IEC 6429 "black", "red", "green", etc.
3915 @item COLORSPACE_AIXTERM_16COLOR
3916 Palette with 16 colors.  First eight are standard colors of ISO/IEC 6429
3917 "black", "red", "green", etc.  Next eight are their bright version.
3919 @item COLORSPACE_XTERM_256COLOR
3920 Palette with 256 colors.  First 16 are from COLORSPACE_AIXTERM_16COLOR.  Next
3921 216 colors are 6x6x6 RGB cube.  And last 24 colors form grayscale ramp.
3923 @item COLORSPACE_RGB_24BIT
3924 Direct 24-bit RGB colors.
3925 @end vtable
3927 @node Guile Auto-loading
3928 @subsection Guile Auto-loading
3929 @cindex guile auto-loading
3931 When a new object file is read (for example, due to the @code{file}
3932 command, or because the inferior has loaded a shared library),
3933 @value{GDBN} will look for Guile support scripts in two ways:
3934 @file{@var{objfile}-gdb.scm} and the @code{.debug_gdb_scripts} section.
3935 @xref{Auto-loading extensions}.
3937 The auto-loading feature is useful for supplying application-specific
3938 debugging commands and scripts.
3940 Auto-loading can be enabled or disabled,
3941 and the list of auto-loaded scripts can be printed.
3943 @table @code
3944 @anchor{set auto-load guile-scripts}
3945 @kindex set auto-load guile-scripts
3946 @item set auto-load guile-scripts [on|off]
3947 Enable or disable the auto-loading of Guile scripts.
3949 @anchor{show auto-load guile-scripts}
3950 @kindex show auto-load guile-scripts
3951 @item show auto-load guile-scripts
3952 Show whether auto-loading of Guile scripts is enabled or disabled.
3954 @anchor{info auto-load guile-scripts}
3955 @kindex info auto-load guile-scripts
3956 @cindex print list of auto-loaded Guile scripts
3957 @item info auto-load guile-scripts [@var{regexp}]
3958 Print the list of all Guile scripts that @value{GDBN} auto-loaded.
3960 Also printed is the list of Guile scripts that were mentioned in
3961 the @code{.debug_gdb_scripts} section and were not found.
3962 This is useful because their names are not printed when @value{GDBN}
3963 tries to load them and fails.  There may be many of them, and printing
3964 an error message for each one is problematic.
3966 If @var{regexp} is supplied only Guile scripts with matching names are printed.
3968 Example:
3970 @smallexample
3971 (gdb) info auto-load guile-scripts
3972 Loaded Script
3973 Yes    scm-section-script.scm
3974        full name: /tmp/scm-section-script.scm
3975 No     my-foo-pretty-printers.scm
3976 @end smallexample
3977 @end table
3979 When reading an auto-loaded file, @value{GDBN} sets the
3980 @dfn{current objfile}.  This is available via the @code{current-objfile}
3981 procedure (@pxref{Objfiles In Guile}).  This can be useful for
3982 registering objfile-specific pretty-printers.
3984 @node Guile Modules
3985 @subsection Guile Modules
3986 @cindex guile modules
3988 @value{GDBN} comes with several modules to assist writing Guile code.
3990 @menu
3991 * Guile Printing Module::  Building and registering pretty-printers
3992 * Guile Types Module::     Utilities for working with types
3993 @end menu
3995 @node Guile Printing Module
3996 @subsubsection Guile Printing Module
3998 This module provides a collection of utilities for working with
3999 pretty-printers.
4001 Usage:
4003 @smallexample
4004 (use-modules (gdb printing))
4005 @end smallexample
4007 @deffn {Scheme Procedure} prepend-pretty-printer! object printer
4008 Add @var{printer} to the front of the list of pretty-printers for
4009 @var{object}.  The @var{object} must either be a @code{<gdb:objfile>} object,
4010 or @code{#f} in which case @var{printer} is added to the global list of
4011 printers.
4012 @end deffn
4014 @deffn {Scheme Procedure} append-pretty-printer! object printer
4015 Add @var{printer} to the end of the list of pretty-printers for
4016 @var{object}.  The @var{object} must either be a @code{<gdb:objfile>} object,
4017 or @code{#f} in which case @var{printer} is added to the global list of
4018 printers.
4019 @end deffn
4021 @node Guile Types Module
4022 @subsubsection Guile Types Module
4024 This module provides a collection of utilities for working with
4025 @code{<gdb:type>} objects.
4027 Usage:
4029 @smallexample
4030 (use-modules (gdb types))
4031 @end smallexample
4033 @deffn {Scheme Procedure} get-basic-type type
4034 Return @var{type} with const and volatile qualifiers stripped,
4035 and with typedefs and C@t{++} references converted to the underlying type.
4037 C@t{++} example:
4039 @smallexample
4040 typedef const int const_int;
4041 const_int foo (3);
4042 const_int& foo_ref (foo);
4043 int main () @{ return 0; @}
4044 @end smallexample
4046 Then in gdb:
4048 @smallexample
4049 (gdb) start
4050 (gdb) guile (use-modules (gdb) (gdb types))
4051 (gdb) guile (define foo-ref (parse-and-eval "foo_ref"))
4052 (gdb) guile (get-basic-type (value-type foo-ref))
4053 #<gdb:type int>
4054 @end smallexample
4055 @end deffn
4057 @deffn {Scheme Procedure} type-has-field-deep? type field
4058 Return @code{#t} if @var{type}, assumed to be a type with fields
4059 (e.g., a structure or union), has field @var{field}.
4060 Otherwise return @code{#f}.
4061 This searches baseclasses, whereas @code{type-has-field?} does not.
4062 @end deffn
4064 @deffn {Scheme Procedure} make-enum-hashtable enum-type
4065 Return a Guile hash table produced from @var{enum-type}.
4066 Elements in the hash table are referenced with @code{hashq-ref}.
4067 @end deffn