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