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