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