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