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