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