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