Imported Upstream version 7.8.1
[platform/upstream/gdb.git] / gdb / doc / gdb.info-4
1 This is gdb.info, produced by makeinfo version 5.2 from gdb.texinfo.
2
3 Copyright (C) 1988-2014 Free Software Foundation, Inc.
4
5    Permission is granted to copy, distribute and/or modify this document
6 under the terms of the GNU Free Documentation License, Version 1.3 or
7 any later version published by the Free Software Foundation; with the
8 Invariant Sections being "Free Software" and "Free Software Needs Free
9 Documentation", with the Front-Cover Texts being "A GNU Manual," and
10 with the Back-Cover Texts as in (a) below.
11
12    (a) The FSF's Back-Cover Text is: "You are free to copy and modify
13 this GNU Manual.  Buying copies from GNU Press supports the FSF in
14 developing GNU and promoting software freedom."
15 INFO-DIR-SECTION Software development
16 START-INFO-DIR-ENTRY
17 * Gdb: (gdb).                     The GNU debugger.
18 * gdbserver: (gdb) Server.        The GNU debugging server.
19 END-INFO-DIR-ENTRY
20
21    This file documents the GNU debugger GDB.
22
23    This is the Tenth Edition, of 'Debugging with GDB: the GNU
24 Source-Level Debugger' for GDB (GDB) Version 7.8.1.
25
26    Copyright (C) 1988-2014 Free Software Foundation, Inc.
27
28    Permission is granted to copy, distribute and/or modify this document
29 under the terms of the GNU Free Documentation License, Version 1.3 or
30 any later version published by the Free Software Foundation; with the
31 Invariant Sections being "Free Software" and "Free Software Needs Free
32 Documentation", with the Front-Cover Texts being "A GNU Manual," and
33 with the Back-Cover Texts as in (a) below.
34
35    (a) The FSF's Back-Cover Text is: "You are free to copy and modify
36 this GNU Manual.  Buying copies from GNU Press supports the FSF in
37 developing GNU and promoting software freedom."
38
39 \1f
40 File: gdb.info,  Node: Xmethods In Python,  Next: Xmethod API,  Prev: Writing a Frame Filter,  Up: Python API
41
42 23.2.2.12 Xmethods In Python
43 ............................
44
45 "Xmethods" are additional methods or replacements for existing methods
46 of a C++ class.  This feature is useful for those cases where a method
47 defined in C++ source code could be inlined or optimized out by the
48 compiler, making it unavailable to GDB.  For such cases, one can define
49 an xmethod to serve as a replacement for the method defined in the C++
50 source code.  GDB will then invoke the xmethod, instead of the C++
51 method, to evaluate expressions.  One can also use xmethods when
52 debugging with core files.  Moreover, when debugging live programs,
53 invoking an xmethod need not involve running the inferior (which can
54 potentially perturb its state).  Hence, even if the C++ method is
55 available, it is better to use its replacement xmethod if one is
56 defined.
57
58    The xmethods feature in Python is available via the concepts of an
59 "xmethod matcher" and an "xmethod worker".  To implement an xmethod, one
60 has to implement a matcher and a corresponding worker for it (more than
61 one worker can be implemented, each catering to a different overloaded
62 instance of the method).  Internally, GDB invokes the 'match' method of
63 a matcher to match the class type and method name.  On a match, the
64 'match' method returns a list of matching _worker_ objects.  Each worker
65 object typically corresponds to an overloaded instance of the xmethod.
66 They implement a 'get_arg_types' method which returns a sequence of
67 types corresponding to the arguments the xmethod requires.  GDB uses
68 this sequence of types to perform overload resolution and picks a
69 winning xmethod worker.  A winner is also selected from among the
70 methods GDB finds in the C++ source code.  Next, the winning xmethod
71 worker and the winning C++ method are compared to select an overall
72 winner.  In case of a tie between a xmethod worker and a C++ method, the
73 xmethod worker is selected as the winner.  That is, if a winning xmethod
74 worker is found to be equivalent to the winning C++ method, then the
75 xmethod worker is treated as a replacement for the C++ method.  GDB uses
76 the overall winner to invoke the method.  If the winning xmethod worker
77 is the overall winner, then the corresponding xmethod is invoked via the
78 'invoke' method of the worker object.
79
80    If one wants to implement an xmethod as a replacement for an existing
81 C++ method, then they have to implement an equivalent xmethod which has
82 exactly the same name and takes arguments of exactly the same type as
83 the C++ method.  If the user wants to invoke the C++ method even though
84 a replacement xmethod is available for that method, then they can
85 disable the xmethod.
86
87    *Note Xmethod API::, for API to implement xmethods in Python.  *Note
88 Writing an Xmethod::, for implementing xmethods in Python.
89
90 \1f
91 File: gdb.info,  Node: Xmethod API,  Next: Writing an Xmethod,  Prev: Xmethods In Python,  Up: Python API
92
93 23.2.2.13 Xmethod API
94 .....................
95
96 The GDB Python API provides classes, interfaces and functions to
97 implement, register and manipulate xmethods.  *Note Xmethods In
98 Python::.
99
100    An xmethod matcher should be an instance of a class derived from
101 'XMethodMatcher' defined in the module 'gdb.xmethod', or an object with
102 similar interface and attributes.  An instance of 'XMethodMatcher' has
103 the following attributes:
104
105  -- Variable: name
106      The name of the matcher.
107
108  -- Variable: enabled
109      A boolean value indicating whether the matcher is enabled or
110      disabled.
111
112  -- Variable: methods
113      A list of named methods managed by the matcher.  Each object in the
114      list is an instance of the class 'XMethod' defined in the module
115      'gdb.xmethod', or any object with the following attributes:
116
117      'name'
118           Name of the xmethod which should be unique for each xmethod
119           managed by the matcher.
120
121      'enabled'
122           A boolean value indicating whether the xmethod is enabled or
123           disabled.
124
125      The class 'XMethod' is a convenience class with same attributes as
126      above along with the following constructor:
127
128       -- Function: XMethod.__init__ (self, name)
129           Constructs an enabled xmethod with name NAME.
130
131 The 'XMethodMatcher' class has the following methods:
132
133  -- Function: XMethodMatcher.__init__ (self, name)
134      Constructs an enabled xmethod matcher with name NAME.  The
135      'methods' attribute is initialized to 'None'.
136
137  -- Function: XMethodMatcher.match (self, class_type, method_name)
138      Derived classes should override this method.  It should return a
139      xmethod worker object (or a sequence of xmethod worker objects)
140      matching the CLASS_TYPE and METHOD_NAME.  CLASS_TYPE is a
141      'gdb.Type' object, and METHOD_NAME is a string value.  If the
142      matcher manages named methods as listed in its 'methods' attribute,
143      then only those worker objects whose corresponding entries in the
144      'methods' list are enabled should be returned.
145
146    An xmethod worker should be an instance of a class derived from
147 'XMethodWorker' defined in the module 'gdb.xmethod', or support the
148 following interface:
149
150  -- Function: XMethodWorker.get_arg_types (self)
151      This method returns a sequence of 'gdb.Type' objects corresponding
152      to the arguments that the xmethod takes.  It can return an empty
153      sequence or 'None' if the xmethod does not take any arguments.  If
154      the xmethod takes a single argument, then a single 'gdb.Type'
155      object corresponding to it can be returned.
156
157  -- Function: XMethodWorker.__call__ (self, *args)
158      This is the method which does the _work_ of the xmethod.  The ARGS
159      arguments is the tuple of arguments to the xmethod.  Each element
160      in this tuple is a gdb.Value object.  The first element is always
161      the 'this' pointer value.
162
163    For GDB to lookup xmethods, the xmethod matchers should be registered
164 using the following function defined in the module 'gdb.xmethod':
165
166  -- Function: register_xmethod_matcher (locus, matcher, replace=False)
167      The 'matcher' is registered with 'locus', replacing an existing
168      matcher with the same name as 'matcher' if 'replace' is 'True'.
169      'locus' can be a 'gdb.Objfile' object (*note Objfiles In Python::),
170      or a 'gdb.Progspace' object (*note Progspaces In Python::), or
171      'None'.  If it is 'None', then 'matcher' is registered globally.
172
173 \1f
174 File: gdb.info,  Node: Writing an Xmethod,  Next: Inferiors In Python,  Prev: Xmethod API,  Up: Python API
175
176 23.2.2.14 Writing an Xmethod
177 ............................
178
179 Implementing xmethods in Python will require implementing xmethod
180 matchers and xmethod workers (*note Xmethods In Python::).  Consider the
181 following C++ class:
182
183      class MyClass
184      {
185      public:
186        MyClass (int a) : a_(a) { }
187
188        int geta (void) { return a_; }
189        int operator+ (int b);
190
191      private:
192        int a_;
193      };
194
195      int
196      MyClass::operator+ (int b)
197      {
198        return a_ + b;
199      }
200
201 Let us define two xmethods for the class 'MyClass', one replacing the
202 method 'geta', and another adding an overloaded flavor of 'operator+'
203 which takes a 'MyClass' argument (the C++ code above already has an
204 overloaded 'operator+' which takes an 'int' argument).  The xmethod
205 matcher can be defined as follows:
206
207      class MyClass_geta(gdb.xmethod.XMethod):
208          def __init__(self):
209              gdb.xmethod.XMethod.__init__(self, 'geta')
210
211          def get_worker(self, method_name):
212              if method_name == 'geta':
213                  return MyClassWorker_geta()
214
215
216      class MyClass_sum(gdb.xmethod.XMethod):
217          def __init__(self):
218              gdb.xmethod.XMethod.__init__(self, 'sum')
219
220          def get_worker(self, method_name):
221              if method_name == 'operator+':
222                  return MyClassWorker_plus()
223
224
225      class MyClassMatcher(gdb.xmethod.XMethodMatcher):
226          def __init__(self):
227              gdb.xmethod.XMethodMatcher.__init__(self, 'MyClassMatcher')
228              # List of methods 'managed' by this matcher
229              self.methods = [MyClass_geta(), MyClass_sum()]
230
231          def match(self, class_type, method_name):
232              if class_type.tag != 'MyClass':
233                  return None
234              workers = []
235              for method in self.methods:
236                  if method.enabled:
237                      worker = method.get_worker(method_name)
238                      if worker:
239                          workers.append(worker)
240
241              return workers
242
243 Notice that the 'match' method of 'MyClassMatcher' returns a worker
244 object of type 'MyClassWorker_geta' for the 'geta' method, and a worker
245 object of type 'MyClassWorker_plus' for the 'operator+' method.  This is
246 done indirectly via helper classes derived from 'gdb.xmethod.XMethod'.
247 One does not need to use the 'methods' attribute in a matcher as it is
248 optional.  However, if a matcher manages more than one xmethod, it is a
249 good practice to list the xmethods in the 'methods' attribute of the
250 matcher.  This will then facilitate enabling and disabling individual
251 xmethods via the 'enable/disable' commands.  Notice also that a worker
252 object is returned only if the corresponding entry in the 'methods'
253 attribute of the matcher is enabled.
254
255    The implementation of the worker classes returned by the matcher
256 setup above is as follows:
257
258      class MyClassWorker_geta(gdb.xmethod.XMethodWorker):
259          def get_arg_types(self):
260              return None
261
262          def __call__(self, obj):
263              return obj['a_']
264
265
266      class MyClassWorker_plus(gdb.xmethod.XMethodWorker):
267          def get_arg_types(self):
268              return gdb.lookup_type('MyClass')
269
270          def __call__(self, obj, other):
271              return obj['a_'] + other['a_']
272
273    For GDB to actually lookup a xmethod, it has to be registered with
274 it.  The matcher defined above is registered with GDB globally as
275 follows:
276
277      gdb.xmethod.register_xmethod_matcher(None, MyClassMatcher())
278
279    If an object 'obj' of type 'MyClass' is initialized in C++ code as
280 follows:
281
282      MyClass obj(5);
283
284 then, after loading the Python script defining the xmethod matchers and
285 workers into 'GDBN', invoking the method 'geta' or using the operator
286 '+' on 'obj' will invoke the xmethods defined above:
287
288      (gdb) p obj.geta()
289      $1 = 5
290
291      (gdb) p obj + obj
292      $2 = 10
293
294    Consider another example with a C++ template class:
295
296      template <class T>
297      class MyTemplate
298      {
299      public:
300        MyTemplate () : dsize_(10), data_ (new T [10]) { }
301        ~MyTemplate () { delete [] data_; }
302
303        int footprint (void)
304        {
305          return sizeof (T) * dsize_ + sizeof (MyTemplate<T>);
306        }
307
308      private:
309        int dsize_;
310        T *data_;
311      };
312
313    Let us implement an xmethod for the above class which serves as a
314 replacement for the 'footprint' method.  The full code listing of the
315 xmethod workers and xmethod matchers is as follows:
316
317      class MyTemplateWorker_footprint(gdb.xmethod.XMethodWorker):
318          def __init__(self, class_type):
319              self.class_type = class_type
320
321          def get_arg_types(self):
322              return None
323
324          def __call__(self, obj):
325              return (self.class_type.sizeof +
326                      obj['dsize_'] *
327                      self.class_type.template_argument(0).sizeof)
328
329
330      class MyTemplateMatcher_footprint(gdb.xmethod.XMethodMatcher):
331          def __init__(self):
332              gdb.xmethod.XMethodMatcher.__init__(self, 'MyTemplateMatcher')
333
334          def match(self, class_type, method_name):
335              if (re.match('MyTemplate<[ \t\n]*[_a-zA-Z][ _a-zA-Z0-9]*>',
336                           class_type.tag) and
337                  method_name == 'footprint'):
338                  return MyTemplateWorker_footprint(class_type)
339
340    Notice that, in this example, we have not used the 'methods'
341 attribute of the matcher as the matcher manages only one xmethod.  The
342 user can enable/disable this xmethod by enabling/disabling the matcher
343 itself.
344
345 \1f
346 File: gdb.info,  Node: Inferiors In Python,  Next: Events In Python,  Prev: Writing an Xmethod,  Up: Python API
347
348 23.2.2.15 Inferiors In Python
349 .............................
350
351 Programs which are being run under GDB are called inferiors (*note
352 Inferiors and Programs::).  Python scripts can access information about
353 and manipulate inferiors controlled by GDB via objects of the
354 'gdb.Inferior' class.
355
356    The following inferior-related functions are available in the 'gdb'
357 module:
358
359  -- Function: gdb.inferiors ()
360      Return a tuple containing all inferior objects.
361
362  -- Function: gdb.selected_inferior ()
363      Return an object representing the current inferior.
364
365    A 'gdb.Inferior' object has the following attributes:
366
367  -- Variable: Inferior.num
368      ID of inferior, as assigned by GDB.
369
370  -- Variable: Inferior.pid
371      Process ID of the inferior, as assigned by the underlying operating
372      system.
373
374  -- Variable: Inferior.was_attached
375      Boolean signaling whether the inferior was created using 'attach',
376      or started by GDB itself.
377
378    A 'gdb.Inferior' object has the following methods:
379
380  -- Function: Inferior.is_valid ()
381      Returns 'True' if the 'gdb.Inferior' object is valid, 'False' if
382      not.  A 'gdb.Inferior' object will become invalid if the inferior
383      no longer exists within GDB.  All other 'gdb.Inferior' methods will
384      throw an exception if it is invalid at the time the method is
385      called.
386
387  -- Function: Inferior.threads ()
388      This method returns a tuple holding all the threads which are valid
389      when it is called.  If there are no valid threads, the method will
390      return an empty tuple.
391
392  -- Function: Inferior.read_memory (address, length)
393      Read LENGTH bytes of memory from the inferior, starting at ADDRESS.
394      Returns a buffer object, which behaves much like an array or a
395      string.  It can be modified and given to the
396      'Inferior.write_memory' function.  In 'Python' 3, the return value
397      is a 'memoryview' object.
398
399  -- Function: Inferior.write_memory (address, buffer [, length])
400      Write the contents of BUFFER to the inferior, starting at ADDRESS.
401      The BUFFER parameter must be a Python object which supports the
402      buffer protocol, i.e., a string, an array or the object returned
403      from 'Inferior.read_memory'.  If given, LENGTH determines the
404      number of bytes from BUFFER to be written.
405
406  -- Function: Inferior.search_memory (address, length, pattern)
407      Search a region of the inferior memory starting at ADDRESS with the
408      given LENGTH using the search pattern supplied in PATTERN.  The
409      PATTERN parameter must be a Python object which supports the buffer
410      protocol, i.e., a string, an array or the object returned from
411      'gdb.read_memory'.  Returns a Python 'Long' containing the address
412      where the pattern was found, or 'None' if the pattern could not be
413      found.
414
415 \1f
416 File: gdb.info,  Node: Events In Python,  Next: Threads In Python,  Prev: Inferiors In Python,  Up: Python API
417
418 23.2.2.16 Events In Python
419 ..........................
420
421 GDB provides a general event facility so that Python code can be
422 notified of various state changes, particularly changes that occur in
423 the inferior.
424
425    An "event" is just an object that describes some state change.  The
426 type of the object and its attributes will vary depending on the details
427 of the change.  All the existing events are described below.
428
429    In order to be notified of an event, you must register an event
430 handler with an "event registry".  An event registry is an object in the
431 'gdb.events' module which dispatches particular events.  A registry
432 provides methods to register and unregister event handlers:
433
434  -- Function: EventRegistry.connect (object)
435      Add the given callable OBJECT to the registry.  This object will be
436      called when an event corresponding to this registry occurs.
437
438  -- Function: EventRegistry.disconnect (object)
439      Remove the given OBJECT from the registry.  Once removed, the
440      object will no longer receive notifications of events.
441
442    Here is an example:
443
444      def exit_handler (event):
445          print "event type: exit"
446          print "exit code: %d" % (event.exit_code)
447
448      gdb.events.exited.connect (exit_handler)
449
450    In the above example we connect our handler 'exit_handler' to the
451 registry 'events.exited'.  Once connected, 'exit_handler' gets called
452 when the inferior exits.  The argument "event" in this example is of
453 type 'gdb.ExitedEvent'.  As you can see in the example the 'ExitedEvent'
454 object has an attribute which indicates the exit code of the inferior.
455
456    The following is a listing of the event registries that are available
457 and details of the events they emit:
458
459 'events.cont'
460      Emits 'gdb.ThreadEvent'.
461
462      Some events can be thread specific when GDB is running in non-stop
463      mode.  When represented in Python, these events all extend
464      'gdb.ThreadEvent'.  Note, this event is not emitted directly;
465      instead, events which are emitted by this or other modules might
466      extend this event.  Examples of these events are
467      'gdb.BreakpointEvent' and 'gdb.ContinueEvent'.
468
469       -- Variable: ThreadEvent.inferior_thread
470           In non-stop mode this attribute will be set to the specific
471           thread which was involved in the emitted event.  Otherwise, it
472           will be set to 'None'.
473
474      Emits 'gdb.ContinueEvent' which extends 'gdb.ThreadEvent'.
475
476      This event indicates that the inferior has been continued after a
477      stop.  For inherited attribute refer to 'gdb.ThreadEvent' above.
478
479 'events.exited'
480      Emits 'events.ExitedEvent' which indicates that the inferior has
481      exited.  'events.ExitedEvent' has two attributes:
482       -- Variable: ExitedEvent.exit_code
483           An integer representing the exit code, if available, which the
484           inferior has returned.  (The exit code could be unavailable
485           if, for example, GDB detaches from the inferior.)  If the exit
486           code is unavailable, the attribute does not exist.
487       -- Variable: ExitedEvent inferior
488           A reference to the inferior which triggered the 'exited'
489           event.
490
491 'events.stop'
492      Emits 'gdb.StopEvent' which extends 'gdb.ThreadEvent'.
493
494      Indicates that the inferior has stopped.  All events emitted by
495      this registry extend StopEvent.  As a child of 'gdb.ThreadEvent',
496      'gdb.StopEvent' will indicate the stopped thread when GDB is
497      running in non-stop mode.  Refer to 'gdb.ThreadEvent' above for
498      more details.
499
500      Emits 'gdb.SignalEvent' which extends 'gdb.StopEvent'.
501
502      This event indicates that the inferior or one of its threads has
503      received as signal.  'gdb.SignalEvent' has the following
504      attributes:
505
506       -- Variable: SignalEvent.stop_signal
507           A string representing the signal received by the inferior.  A
508           list of possible signal values can be obtained by running the
509           command 'info signals' in the GDB command prompt.
510
511      Also emits 'gdb.BreakpointEvent' which extends 'gdb.StopEvent'.
512
513      'gdb.BreakpointEvent' event indicates that one or more breakpoints
514      have been hit, and has the following attributes:
515
516       -- Variable: BreakpointEvent.breakpoints
517           A sequence containing references to all the breakpoints (type
518           'gdb.Breakpoint') that were hit.  *Note Breakpoints In
519           Python::, for details of the 'gdb.Breakpoint' object.
520       -- Variable: BreakpointEvent.breakpoint
521           A reference to the first breakpoint that was hit.  This
522           function is maintained for backward compatibility and is now
523           deprecated in favor of the 'gdb.BreakpointEvent.breakpoints'
524           attribute.
525
526 'events.new_objfile'
527      Emits 'gdb.NewObjFileEvent' which indicates that a new object file
528      has been loaded by GDB.  'gdb.NewObjFileEvent' has one attribute:
529
530       -- Variable: NewObjFileEvent.new_objfile
531           A reference to the object file ('gdb.Objfile') which has been
532           loaded.  *Note Objfiles In Python::, for details of the
533           'gdb.Objfile' object.
534
535 \1f
536 File: gdb.info,  Node: Threads In Python,  Next: Commands In Python,  Prev: Events In Python,  Up: Python API
537
538 23.2.2.17 Threads In Python
539 ...........................
540
541 Python scripts can access information about, and manipulate inferior
542 threads controlled by GDB, via objects of the 'gdb.InferiorThread'
543 class.
544
545    The following thread-related functions are available in the 'gdb'
546 module:
547
548  -- Function: gdb.selected_thread ()
549      This function returns the thread object for the selected thread.
550      If there is no selected thread, this will return 'None'.
551
552    A 'gdb.InferiorThread' object has the following attributes:
553
554  -- Variable: InferiorThread.name
555      The name of the thread.  If the user specified a name using 'thread
556      name', then this returns that name.  Otherwise, if an OS-supplied
557      name is available, then it is returned.  Otherwise, this returns
558      'None'.
559
560      This attribute can be assigned to.  The new value must be a string
561      object, which sets the new name, or 'None', which removes any
562      user-specified thread name.
563
564  -- Variable: InferiorThread.num
565      ID of the thread, as assigned by GDB.
566
567  -- Variable: InferiorThread.ptid
568      ID of the thread, as assigned by the operating system.  This
569      attribute is a tuple containing three integers.  The first is the
570      Process ID (PID); the second is the Lightweight Process ID (LWPID),
571      and the third is the Thread ID (TID). Either the LWPID or TID may
572      be 0, which indicates that the operating system does not use that
573      identifier.
574
575    A 'gdb.InferiorThread' object has the following methods:
576
577  -- Function: InferiorThread.is_valid ()
578      Returns 'True' if the 'gdb.InferiorThread' object is valid, 'False'
579      if not.  A 'gdb.InferiorThread' object will become invalid if the
580      thread exits, or the inferior that the thread belongs is deleted.
581      All other 'gdb.InferiorThread' methods will throw an exception if
582      it is invalid at the time the method is called.
583
584  -- Function: InferiorThread.switch ()
585      This changes GDB's currently selected thread to the one represented
586      by this object.
587
588  -- Function: InferiorThread.is_stopped ()
589      Return a Boolean indicating whether the thread is stopped.
590
591  -- Function: InferiorThread.is_running ()
592      Return a Boolean indicating whether the thread is running.
593
594  -- Function: InferiorThread.is_exited ()
595      Return a Boolean indicating whether the thread is exited.
596
597 \1f
598 File: gdb.info,  Node: Commands In Python,  Next: Parameters In Python,  Prev: Threads In Python,  Up: Python API
599
600 23.2.2.18 Commands In Python
601 ............................
602
603 You can implement new GDB CLI commands in Python.  A CLI command is
604 implemented using an instance of the 'gdb.Command' class, most commonly
605 using a subclass.
606
607  -- Function: Command.__init__ (name, COMMAND_CLASS [, COMPLETER_CLASS
608           [, PREFIX]])
609      The object initializer for 'Command' registers the new command with
610      GDB.  This initializer is normally invoked from the subclass' own
611      '__init__' method.
612
613      NAME is the name of the command.  If NAME consists of multiple
614      words, then the initial words are looked for as prefix commands.
615      In this case, if one of the prefix commands does not exist, an
616      exception is raised.
617
618      There is no support for multi-line commands.
619
620      COMMAND_CLASS should be one of the 'COMMAND_' constants defined
621      below.  This argument tells GDB how to categorize the new command
622      in the help system.
623
624      COMPLETER_CLASS is an optional argument.  If given, it should be
625      one of the 'COMPLETE_' constants defined below.  This argument
626      tells GDB how to perform completion for this command.  If not
627      given, GDB will attempt to complete using the object's 'complete'
628      method (see below); if no such method is found, an error will occur
629      when completion is attempted.
630
631      PREFIX is an optional argument.  If 'True', then the new command is
632      a prefix command; sub-commands of this command may be registered.
633
634      The help text for the new command is taken from the Python
635      documentation string for the command's class, if there is one.  If
636      no documentation string is provided, the default value "This
637      command is not documented."  is used.
638
639  -- Function: Command.dont_repeat ()
640      By default, a GDB command is repeated when the user enters a blank
641      line at the command prompt.  A command can suppress this behavior
642      by invoking the 'dont_repeat' method.  This is similar to the user
643      command 'dont-repeat', see *note dont-repeat: Define.
644
645  -- Function: Command.invoke (argument, from_tty)
646      This method is called by GDB when this command is invoked.
647
648      ARGUMENT is a string.  It is the argument to the command, after
649      leading and trailing whitespace has been stripped.
650
651      FROM_TTY is a boolean argument.  When true, this means that the
652      command was entered by the user at the terminal; when false it
653      means that the command came from elsewhere.
654
655      If this method throws an exception, it is turned into a GDB 'error'
656      call.  Otherwise, the return value is ignored.
657
658      To break ARGUMENT up into an argv-like string use
659      'gdb.string_to_argv'.  This function behaves identically to GDB's
660      internal argument lexer 'buildargv'.  It is recommended to use this
661      for consistency.  Arguments are separated by spaces and may be
662      quoted.  Example:
663
664           print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
665           ['1', '2 "3', '4 "5', "6 '7"]
666
667  -- Function: Command.complete (text, word)
668      This method is called by GDB when the user attempts completion on
669      this command.  All forms of completion are handled by this method,
670      that is, the <TAB> and <M-?> key bindings (*note Completion::), and
671      the 'complete' command (*note complete: Help.).
672
673      The arguments TEXT and WORD are both strings; TEXT holds the
674      complete command line up to the cursor's location, while WORD holds
675      the last word of the command line; this is computed using a
676      word-breaking heuristic.
677
678      The 'complete' method can return several values:
679         * If the return value is a sequence, the contents of the
680           sequence are used as the completions.  It is up to 'complete'
681           to ensure that the contents actually do complete the word.  A
682           zero-length sequence is allowed, it means that there were no
683           completions available.  Only string elements of the sequence
684           are used; other elements in the sequence are ignored.
685
686         * If the return value is one of the 'COMPLETE_' constants
687           defined below, then the corresponding GDB-internal completion
688           function is invoked, and its result is used.
689
690         * All other results are treated as though there were no
691           available completions.
692
693    When a new command is registered, it must be declared as a member of
694 some general class of commands.  This is used to classify top-level
695 commands in the on-line help system; note that prefix commands are not
696 listed under their own category but rather that of their top-level
697 command.  The available classifications are represented by constants
698 defined in the 'gdb' module:
699
700 'gdb.COMMAND_NONE'
701      The command does not belong to any particular class.  A command in
702      this category will not be displayed in any of the help categories.
703
704 'gdb.COMMAND_RUNNING'
705      The command is related to running the inferior.  For example,
706      'start', 'step', and 'continue' are in this category.  Type 'help
707      running' at the GDB prompt to see a list of commands in this
708      category.
709
710 'gdb.COMMAND_DATA'
711      The command is related to data or variables.  For example, 'call',
712      'find', and 'print' are in this category.  Type 'help data' at the
713      GDB prompt to see a list of commands in this category.
714
715 'gdb.COMMAND_STACK'
716      The command has to do with manipulation of the stack.  For example,
717      'backtrace', 'frame', and 'return' are in this category.  Type
718      'help stack' at the GDB prompt to see a list of commands in this
719      category.
720
721 'gdb.COMMAND_FILES'
722      This class is used for file-related commands.  For example, 'file',
723      'list' and 'section' are in this category.  Type 'help files' at
724      the GDB prompt to see a list of commands in this category.
725
726 'gdb.COMMAND_SUPPORT'
727      This should be used for "support facilities", generally meaning
728      things that are useful to the user when interacting with GDB, but
729      not related to the state of the inferior.  For example, 'help',
730      'make', and 'shell' are in this category.  Type 'help support' at
731      the GDB prompt to see a list of commands in this category.
732
733 'gdb.COMMAND_STATUS'
734      The command is an 'info'-related command, that is, related to the
735      state of GDB itself.  For example, 'info', 'macro', and 'show' are
736      in this category.  Type 'help status' at the GDB prompt to see a
737      list of commands in this category.
738
739 'gdb.COMMAND_BREAKPOINTS'
740      The command has to do with breakpoints.  For example, 'break',
741      'clear', and 'delete' are in this category.  Type 'help
742      breakpoints' at the GDB prompt to see a list of commands in this
743      category.
744
745 'gdb.COMMAND_TRACEPOINTS'
746      The command has to do with tracepoints.  For example, 'trace',
747      'actions', and 'tfind' are in this category.  Type 'help
748      tracepoints' at the GDB prompt to see a list of commands in this
749      category.
750
751 'gdb.COMMAND_USER'
752      The command is a general purpose command for the user, and
753      typically does not fit in one of the other categories.  Type 'help
754      user-defined' at the GDB prompt to see a list of commands in this
755      category, as well as the list of gdb macros (*note Sequences::).
756
757 'gdb.COMMAND_OBSCURE'
758      The command is only used in unusual circumstances, or is not of
759      general interest to users.  For example, 'checkpoint', 'fork', and
760      'stop' are in this category.  Type 'help obscure' at the GDB prompt
761      to see a list of commands in this category.
762
763 'gdb.COMMAND_MAINTENANCE'
764      The command is only useful to GDB maintainers.  The 'maintenance'
765      and 'flushregs' commands are in this category.  Type 'help
766      internals' at the GDB prompt to see a list of commands in this
767      category.
768
769    A new command can use a predefined completion function, either by
770 specifying it via an argument at initialization, or by returning it from
771 the 'complete' method.  These predefined completion constants are all
772 defined in the 'gdb' module:
773
774 'gdb.COMPLETE_NONE'
775      This constant means that no completion should be done.
776
777 'gdb.COMPLETE_FILENAME'
778      This constant means that filename completion should be performed.
779
780 'gdb.COMPLETE_LOCATION'
781      This constant means that location completion should be done.  *Note
782      Specify Location::.
783
784 'gdb.COMPLETE_COMMAND'
785      This constant means that completion should examine GDB command
786      names.
787
788 'gdb.COMPLETE_SYMBOL'
789      This constant means that completion should be done using symbol
790      names as the source.
791
792 'gdb.COMPLETE_EXPRESSION'
793      This constant means that completion should be done on expressions.
794      Often this means completing on symbol names, but some language
795      parsers also have support for completing on field names.
796
797    The following code snippet shows how a trivial CLI command can be
798 implemented in Python:
799
800      class HelloWorld (gdb.Command):
801        """Greet the whole world."""
802
803        def __init__ (self):
804          super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
805
806        def invoke (self, arg, from_tty):
807          print "Hello, World!"
808
809      HelloWorld ()
810
811    The last line instantiates the class, and is necessary to trigger the
812 registration of the command with GDB.  Depending on how the Python code
813 is read into GDB, you may need to import the 'gdb' module explicitly.
814
815 \1f
816 File: gdb.info,  Node: Parameters In Python,  Next: Functions In Python,  Prev: Commands In Python,  Up: Python API
817
818 23.2.2.19 Parameters In Python
819 ..............................
820
821 You can implement new GDB parameters using Python.  A new parameter is
822 implemented as an instance of the 'gdb.Parameter' class.
823
824    Parameters are exposed to the user via the 'set' and 'show' commands.
825 *Note Help::.
826
827    There are many parameters that already exist and can be set in GDB.
828 Two examples are: 'set follow fork' and 'set charset'.  Setting these
829 parameters influences certain behavior in GDB.  Similarly, you can
830 define parameters that can be used to influence behavior in custom
831 Python scripts and commands.
832
833  -- Function: Parameter.__init__ (name, COMMAND-CLASS, PARAMETER-CLASS
834           [, ENUM-SEQUENCE])
835      The object initializer for 'Parameter' registers the new parameter
836      with GDB.  This initializer is normally invoked from the subclass'
837      own '__init__' method.
838
839      NAME is the name of the new parameter.  If NAME consists of
840      multiple words, then the initial words are looked for as prefix
841      parameters.  An example of this can be illustrated with the 'set
842      print' set of parameters.  If NAME is 'print foo', then 'print'
843      will be searched as the prefix parameter.  In this case the
844      parameter can subsequently be accessed in GDB as 'set print foo'.
845
846      If NAME consists of multiple words, and no prefix parameter group
847      can be found, an exception is raised.
848
849      COMMAND-CLASS should be one of the 'COMMAND_' constants (*note
850      Commands In Python::).  This argument tells GDB how to categorize
851      the new parameter in the help system.
852
853      PARAMETER-CLASS should be one of the 'PARAM_' constants defined
854      below.  This argument tells GDB the type of the new parameter; this
855      information is used for input validation and completion.
856
857      If PARAMETER-CLASS is 'PARAM_ENUM', then ENUM-SEQUENCE must be a
858      sequence of strings.  These strings represent the possible values
859      for the parameter.
860
861      If PARAMETER-CLASS is not 'PARAM_ENUM', then the presence of a
862      fourth argument will cause an exception to be thrown.
863
864      The help text for the new parameter is taken from the Python
865      documentation string for the parameter's class, if there is one.
866      If there is no documentation string, a default value is used.
867
868  -- Variable: Parameter.set_doc
869      If this attribute exists, and is a string, then its value is used
870      as the help text for this parameter's 'set' command.  The value is
871      examined when 'Parameter.__init__' is invoked; subsequent changes
872      have no effect.
873
874  -- Variable: Parameter.show_doc
875      If this attribute exists, and is a string, then its value is used
876      as the help text for this parameter's 'show' command.  The value is
877      examined when 'Parameter.__init__' is invoked; subsequent changes
878      have no effect.
879
880  -- Variable: Parameter.value
881      The 'value' attribute holds the underlying value of the parameter.
882      It can be read and assigned to just as any other attribute.  GDB
883      does validation when assignments are made.
884
885    There are two methods that should be implemented in any 'Parameter'
886 class.  These are:
887
888  -- Function: Parameter.get_set_string (self)
889      GDB will call this method when a PARAMETER's value has been changed
890      via the 'set' API (for example, 'set foo off').  The 'value'
891      attribute has already been populated with the new value and may be
892      used in output.  This method must return a string.
893
894  -- Function: Parameter.get_show_string (self, svalue)
895      GDB will call this method when a PARAMETER's 'show' API has been
896      invoked (for example, 'show foo').  The argument 'svalue' receives
897      the string representation of the current value.  This method must
898      return a string.
899
900    When a new parameter is defined, its type must be specified.  The
901 available types are represented by constants defined in the 'gdb'
902 module:
903
904 'gdb.PARAM_BOOLEAN'
905      The value is a plain boolean.  The Python boolean values, 'True'
906      and 'False' are the only valid values.
907
908 'gdb.PARAM_AUTO_BOOLEAN'
909      The value has three possible states: true, false, and 'auto'.  In
910      Python, true and false are represented using boolean constants, and
911      'auto' is represented using 'None'.
912
913 'gdb.PARAM_UINTEGER'
914      The value is an unsigned integer.  The value of 0 should be
915      interpreted to mean "unlimited".
916
917 'gdb.PARAM_INTEGER'
918      The value is a signed integer.  The value of 0 should be
919      interpreted to mean "unlimited".
920
921 'gdb.PARAM_STRING'
922      The value is a string.  When the user modifies the string, any
923      escape sequences, such as '\t', '\f', and octal escapes, are
924      translated into corresponding characters and encoded into the
925      current host charset.
926
927 'gdb.PARAM_STRING_NOESCAPE'
928      The value is a string.  When the user modifies the string, escapes
929      are passed through untranslated.
930
931 'gdb.PARAM_OPTIONAL_FILENAME'
932      The value is a either a filename (a string), or 'None'.
933
934 'gdb.PARAM_FILENAME'
935      The value is a filename.  This is just like
936      'PARAM_STRING_NOESCAPE', but uses file names for completion.
937
938 'gdb.PARAM_ZINTEGER'
939      The value is an integer.  This is like 'PARAM_INTEGER', except 0 is
940      interpreted as itself.
941
942 'gdb.PARAM_ENUM'
943      The value is a string, which must be one of a collection string
944      constants provided when the parameter is created.
945
946 \1f
947 File: gdb.info,  Node: Functions In Python,  Next: Progspaces In Python,  Prev: Parameters In Python,  Up: Python API
948
949 23.2.2.20 Writing new convenience functions
950 ...........................................
951
952 You can implement new convenience functions (*note Convenience Vars::)
953 in Python.  A convenience function is an instance of a subclass of the
954 class 'gdb.Function'.
955
956  -- Function: Function.__init__ (name)
957      The initializer for 'Function' registers the new function with GDB.
958      The argument NAME is the name of the function, a string.  The
959      function will be visible to the user as a convenience variable of
960      type 'internal function', whose name is the same as the given NAME.
961
962      The documentation for the new function is taken from the
963      documentation string for the new class.
964
965  -- Function: Function.invoke (*ARGS)
966      When a convenience function is evaluated, its arguments are
967      converted to instances of 'gdb.Value', and then the function's
968      'invoke' method is called.  Note that GDB does not predetermine the
969      arity of convenience functions.  Instead, all available arguments
970      are passed to 'invoke', following the standard Python calling
971      convention.  In particular, a convenience function can have default
972      values for parameters without ill effect.
973
974      The return value of this method is used as its value in the
975      enclosing expression.  If an ordinary Python value is returned, it
976      is converted to a 'gdb.Value' following the usual rules.
977
978    The following code snippet shows how a trivial convenience function
979 can be implemented in Python:
980
981      class Greet (gdb.Function):
982        """Return string to greet someone.
983      Takes a name as argument."""
984
985        def __init__ (self):
986          super (Greet, self).__init__ ("greet")
987
988        def invoke (self, name):
989          return "Hello, %s!" % name.string ()
990
991      Greet ()
992
993    The last line instantiates the class, and is necessary to trigger the
994 registration of the function with GDB.  Depending on how the Python code
995 is read into GDB, you may need to import the 'gdb' module explicitly.
996
997    Now you can use the function in an expression:
998
999      (gdb) print $greet("Bob")
1000      $1 = "Hello, Bob!"
1001
1002 \1f
1003 File: gdb.info,  Node: Progspaces In Python,  Next: Objfiles In Python,  Prev: Functions In Python,  Up: Python API
1004
1005 23.2.2.21 Program Spaces In Python
1006 ..................................
1007
1008 A program space, or "progspace", represents a symbolic view of an
1009 address space.  It consists of all of the objfiles of the program.
1010 *Note Objfiles In Python::.  *Note program spaces: Inferiors and
1011 Programs, for more details about program spaces.
1012
1013    The following progspace-related functions are available in the 'gdb'
1014 module:
1015
1016  -- Function: gdb.current_progspace ()
1017      This function returns the program space of the currently selected
1018      inferior.  *Note Inferiors and Programs::.
1019
1020  -- Function: gdb.progspaces ()
1021      Return a sequence of all the progspaces currently known to GDB.
1022
1023    Each progspace is represented by an instance of the 'gdb.Progspace'
1024 class.
1025
1026  -- Variable: Progspace.filename
1027      The file name of the progspace as a string.
1028
1029  -- Variable: Progspace.pretty_printers
1030      The 'pretty_printers' attribute is a list of functions.  It is used
1031      to look up pretty-printers.  A 'Value' is passed to each function
1032      in order; if the function returns 'None', then the search
1033      continues.  Otherwise, the return value should be an object which
1034      is used to format the value.  *Note Pretty Printing API::, for more
1035      information.
1036
1037  -- Variable: Progspace.type_printers
1038      The 'type_printers' attribute is a list of type printer objects.
1039      *Note Type Printing API::, for more information.
1040
1041  -- Variable: Progspace.frame_filters
1042      The 'frame_filters' attribute is a dictionary of frame filter
1043      objects.  *Note Frame Filter API::, for more information.
1044
1045 \1f
1046 File: gdb.info,  Node: Objfiles In Python,  Next: Frames In Python,  Prev: Progspaces In Python,  Up: Python API
1047
1048 23.2.2.22 Objfiles In Python
1049 ............................
1050
1051 GDB loads symbols for an inferior from various symbol-containing files
1052 (*note Files::).  These include the primary executable file, any shared
1053 libraries used by the inferior, and any separate debug info files (*note
1054 Separate Debug Files::).  GDB calls these symbol-containing files
1055 "objfiles".
1056
1057    The following objfile-related functions are available in the 'gdb'
1058 module:
1059
1060  -- Function: gdb.current_objfile ()
1061      When auto-loading a Python script (*note Python Auto-loading::),
1062      GDB sets the "current objfile" to the corresponding objfile.  This
1063      function returns the current objfile.  If there is no current
1064      objfile, this function returns 'None'.
1065
1066  -- Function: gdb.objfiles ()
1067      Return a sequence of all the objfiles current known to GDB.  *Note
1068      Objfiles In Python::.
1069
1070    Each objfile is represented by an instance of the 'gdb.Objfile'
1071 class.
1072
1073  -- Variable: Objfile.filename
1074      The file name of the objfile as a string.
1075
1076  -- Variable: Objfile.pretty_printers
1077      The 'pretty_printers' attribute is a list of functions.  It is used
1078      to look up pretty-printers.  A 'Value' is passed to each function
1079      in order; if the function returns 'None', then the search
1080      continues.  Otherwise, the return value should be an object which
1081      is used to format the value.  *Note Pretty Printing API::, for more
1082      information.
1083
1084  -- Variable: Objfile.type_printers
1085      The 'type_printers' attribute is a list of type printer objects.
1086      *Note Type Printing API::, for more information.
1087
1088  -- Variable: Objfile.frame_filters
1089      The 'frame_filters' attribute is a dictionary of frame filter
1090      objects.  *Note Frame Filter API::, for more information.
1091
1092    A 'gdb.Objfile' object has the following methods:
1093
1094  -- Function: Objfile.is_valid ()
1095      Returns 'True' if the 'gdb.Objfile' object is valid, 'False' if
1096      not.  A 'gdb.Objfile' object can become invalid if the object file
1097      it refers to is not loaded in GDB any longer.  All other
1098      'gdb.Objfile' methods will throw an exception if it is invalid at
1099      the time the method is called.
1100
1101 \1f
1102 File: gdb.info,  Node: Frames In Python,  Next: Blocks In Python,  Prev: Objfiles In Python,  Up: Python API
1103
1104 23.2.2.23 Accessing inferior stack frames from Python.
1105 ......................................................
1106
1107 When the debugged program stops, GDB is able to analyze its call stack
1108 (*note Stack frames: Frames.).  The 'gdb.Frame' class represents a frame
1109 in the stack.  A 'gdb.Frame' object is only valid while its
1110 corresponding frame exists in the inferior's stack.  If you try to use
1111 an invalid frame object, GDB will throw a 'gdb.error' exception (*note
1112 Exception Handling::).
1113
1114    Two 'gdb.Frame' objects can be compared for equality with the '=='
1115 operator, like:
1116
1117      (gdb) python print gdb.newest_frame() == gdb.selected_frame ()
1118      True
1119
1120    The following frame-related functions are available in the 'gdb'
1121 module:
1122
1123  -- Function: gdb.selected_frame ()
1124      Return the selected frame object.  (*note Selecting a Frame:
1125      Selection.).
1126
1127  -- Function: gdb.newest_frame ()
1128      Return the newest frame object for the selected thread.
1129
1130  -- Function: gdb.frame_stop_reason_string (reason)
1131      Return a string explaining the reason why GDB stopped unwinding
1132      frames, as expressed by the given REASON code (an integer, see the
1133      'unwind_stop_reason' method further down in this section).
1134
1135    A 'gdb.Frame' object has the following methods:
1136
1137  -- Function: Frame.is_valid ()
1138      Returns true if the 'gdb.Frame' object is valid, false if not.  A
1139      frame object can become invalid if the frame it refers to doesn't
1140      exist anymore in the inferior.  All 'gdb.Frame' methods will throw
1141      an exception if it is invalid at the time the method is called.
1142
1143  -- Function: Frame.name ()
1144      Returns the function name of the frame, or 'None' if it can't be
1145      obtained.
1146
1147  -- Function: Frame.architecture ()
1148      Returns the 'gdb.Architecture' object corresponding to the frame's
1149      architecture.  *Note Architectures In Python::.
1150
1151  -- Function: Frame.type ()
1152      Returns the type of the frame.  The value can be one of:
1153      'gdb.NORMAL_FRAME'
1154           An ordinary stack frame.
1155
1156      'gdb.DUMMY_FRAME'
1157           A fake stack frame that was created by GDB when performing an
1158           inferior function call.
1159
1160      'gdb.INLINE_FRAME'
1161           A frame representing an inlined function.  The function was
1162           inlined into a 'gdb.NORMAL_FRAME' that is older than this one.
1163
1164      'gdb.TAILCALL_FRAME'
1165           A frame representing a tail call.  *Note Tail Call Frames::.
1166
1167      'gdb.SIGTRAMP_FRAME'
1168           A signal trampoline frame.  This is the frame created by the
1169           OS when it calls into a signal handler.
1170
1171      'gdb.ARCH_FRAME'
1172           A fake stack frame representing a cross-architecture call.
1173
1174      'gdb.SENTINEL_FRAME'
1175           This is like 'gdb.NORMAL_FRAME', but it is only used for the
1176           newest frame.
1177
1178  -- Function: Frame.unwind_stop_reason ()
1179      Return an integer representing the reason why it's not possible to
1180      find more frames toward the outermost frame.  Use
1181      'gdb.frame_stop_reason_string' to convert the value returned by
1182      this function to a string.  The value can be one of:
1183
1184      'gdb.FRAME_UNWIND_NO_REASON'
1185           No particular reason (older frames should be available).
1186
1187      'gdb.FRAME_UNWIND_NULL_ID'
1188           The previous frame's analyzer returns an invalid result.  This
1189           is no longer used by GDB, and is kept only for backward
1190           compatibility.
1191
1192      'gdb.FRAME_UNWIND_OUTERMOST'
1193           This frame is the outermost.
1194
1195      'gdb.FRAME_UNWIND_UNAVAILABLE'
1196           Cannot unwind further, because that would require knowing the
1197           values of registers or memory that have not been collected.
1198
1199      'gdb.FRAME_UNWIND_INNER_ID'
1200           This frame ID looks like it ought to belong to a NEXT frame,
1201           but we got it for a PREV frame.  Normally, this is a sign of
1202           unwinder failure.  It could also indicate stack corruption.
1203
1204      'gdb.FRAME_UNWIND_SAME_ID'
1205           This frame has the same ID as the previous one.  That means
1206           that unwinding further would almost certainly give us another
1207           frame with exactly the same ID, so break the chain.  Normally,
1208           this is a sign of unwinder failure.  It could also indicate
1209           stack corruption.
1210
1211      'gdb.FRAME_UNWIND_NO_SAVED_PC'
1212           The frame unwinder did not find any saved PC, but we needed
1213           one to unwind further.
1214
1215      'gdb.FRAME_UNWIND_MEMORY_ERROR'
1216           The frame unwinder caused an error while trying to access
1217           memory.
1218
1219      'gdb.FRAME_UNWIND_FIRST_ERROR'
1220           Any stop reason greater or equal to this value indicates some
1221           kind of error.  This special value facilitates writing code
1222           that tests for errors in unwinding in a way that will work
1223           correctly even if the list of the other values is modified in
1224           future GDB versions.  Using it, you could write:
1225                reason = gdb.selected_frame().unwind_stop_reason ()
1226                reason_str =  gdb.frame_stop_reason_string (reason)
1227                if reason >=  gdb.FRAME_UNWIND_FIRST_ERROR:
1228                    print "An error occured: %s" % reason_str
1229
1230  -- Function: Frame.pc ()
1231      Returns the frame's resume address.
1232
1233  -- Function: Frame.block ()
1234      Return the frame's code block.  *Note Blocks In Python::.
1235
1236  -- Function: Frame.function ()
1237      Return the symbol for the function corresponding to this frame.
1238      *Note Symbols In Python::.
1239
1240  -- Function: Frame.older ()
1241      Return the frame that called this frame.
1242
1243  -- Function: Frame.newer ()
1244      Return the frame called by this frame.
1245
1246  -- Function: Frame.find_sal ()
1247      Return the frame's symtab and line object.  *Note Symbol Tables In
1248      Python::.
1249
1250  -- Function: Frame.read_var (variable [, block])
1251      Return the value of VARIABLE in this frame.  If the optional
1252      argument BLOCK is provided, search for the variable from that
1253      block; otherwise start at the frame's current block (which is
1254      determined by the frame's current program counter).  The VARIABLE
1255      argument must be a string or a 'gdb.Symbol' object; BLOCK must be a
1256      'gdb.Block' object.
1257
1258  -- Function: Frame.select ()
1259      Set this frame to be the selected frame.  *Note Examining the
1260      Stack: Stack.
1261
1262 \1f
1263 File: gdb.info,  Node: Blocks In Python,  Next: Symbols In Python,  Prev: Frames In Python,  Up: Python API
1264
1265 23.2.2.24 Accessing blocks from Python.
1266 .......................................
1267
1268 In GDB, symbols are stored in blocks.  A block corresponds roughly to a
1269 scope in the source code.  Blocks are organized hierarchically, and are
1270 represented individually in Python as a 'gdb.Block'.  Blocks rely on
1271 debugging information being available.
1272
1273    A frame has a block.  Please see *note Frames In Python::, for a more
1274 in-depth discussion of frames.
1275
1276    The outermost block is known as the "global block".  The global block
1277 typically holds public global variables and functions.
1278
1279    The block nested just inside the global block is the "static block".
1280 The static block typically holds file-scoped variables and functions.
1281
1282    GDB provides a method to get a block's superblock, but there is
1283 currently no way to examine the sub-blocks of a block, or to iterate
1284 over all the blocks in a symbol table (*note Symbol Tables In Python::).
1285
1286    Here is a short example that should help explain blocks:
1287
1288      /* This is in the global block.  */
1289      int global;
1290
1291      /* This is in the static block.  */
1292      static int file_scope;
1293
1294      /* 'function' is in the global block, and 'argument' is
1295         in a block nested inside of 'function'.  */
1296      int function (int argument)
1297      {
1298        /* 'local' is in a block inside 'function'.  It may or may
1299           not be in the same block as 'argument'.  */
1300        int local;
1301
1302        {
1303           /* 'inner' is in a block whose superblock is the one holding
1304              'local'.  */
1305           int inner;
1306
1307           /* If this call is expanded by the compiler, you may see
1308              a nested block here whose function is 'inline_function'
1309              and whose superblock is the one holding 'inner'.  */
1310           inline_function ();
1311        }
1312      }
1313
1314    A 'gdb.Block' is iterable.  The iterator returns the symbols (*note
1315 Symbols In Python::) local to the block.  Python programs should not
1316 assume that a specific block object will always contain a given symbol,
1317 since changes in GDB features and infrastructure may cause symbols move
1318 across blocks in a symbol table.
1319
1320    The following block-related functions are available in the 'gdb'
1321 module:
1322
1323  -- Function: gdb.block_for_pc (pc)
1324      Return the innermost 'gdb.Block' containing the given PC value.  If
1325      the block cannot be found for the PC value specified, the function
1326      will return 'None'.
1327
1328    A 'gdb.Block' object has the following methods:
1329
1330  -- Function: Block.is_valid ()
1331      Returns 'True' if the 'gdb.Block' object is valid, 'False' if not.
1332      A block object can become invalid if the block it refers to doesn't
1333      exist anymore in the inferior.  All other 'gdb.Block' methods will
1334      throw an exception if it is invalid at the time the method is
1335      called.  The block's validity is also checked during iteration over
1336      symbols of the block.
1337
1338    A 'gdb.Block' object has the following attributes:
1339
1340  -- Variable: Block.start
1341      The start address of the block.  This attribute is not writable.
1342
1343  -- Variable: Block.end
1344      The end address of the block.  This attribute is not writable.
1345
1346  -- Variable: Block.function
1347      The name of the block represented as a 'gdb.Symbol'.  If the block
1348      is not named, then this attribute holds 'None'.  This attribute is
1349      not writable.
1350
1351      For ordinary function blocks, the superblock is the static block.
1352      However, you should note that it is possible for a function block
1353      to have a superblock that is not the static block - for instance
1354      this happens for an inlined function.
1355
1356  -- Variable: Block.superblock
1357      The block containing this block.  If this parent block does not
1358      exist, this attribute holds 'None'.  This attribute is not
1359      writable.
1360
1361  -- Variable: Block.global_block
1362      The global block associated with this block.  This attribute is not
1363      writable.
1364
1365  -- Variable: Block.static_block
1366      The static block associated with this block.  This attribute is not
1367      writable.
1368
1369  -- Variable: Block.is_global
1370      'True' if the 'gdb.Block' object is a global block, 'False' if not.
1371      This attribute is not writable.
1372
1373  -- Variable: Block.is_static
1374      'True' if the 'gdb.Block' object is a static block, 'False' if not.
1375      This attribute is not writable.
1376
1377 \1f
1378 File: gdb.info,  Node: Symbols In Python,  Next: Symbol Tables In Python,  Prev: Blocks In Python,  Up: Python API
1379
1380 23.2.2.25 Python representation of Symbols.
1381 ...........................................
1382
1383 GDB represents every variable, function and type as an entry in a symbol
1384 table.  *Note Examining the Symbol Table: Symbols.  Similarly, Python
1385 represents these symbols in GDB with the 'gdb.Symbol' object.
1386
1387    The following symbol-related functions are available in the 'gdb'
1388 module:
1389
1390  -- Function: gdb.lookup_symbol (name [, block [, domain]])
1391      This function searches for a symbol by name.  The search scope can
1392      be restricted to the parameters defined in the optional domain and
1393      block arguments.
1394
1395      NAME is the name of the symbol.  It must be a string.  The optional
1396      BLOCK argument restricts the search to symbols visible in that
1397      BLOCK.  The BLOCK argument must be a 'gdb.Block' object.  If
1398      omitted, the block for the current frame is used.  The optional
1399      DOMAIN argument restricts the search to the domain type.  The
1400      DOMAIN argument must be a domain constant defined in the 'gdb'
1401      module and described later in this chapter.
1402
1403      The result is a tuple of two elements.  The first element is a
1404      'gdb.Symbol' object or 'None' if the symbol is not found.  If the
1405      symbol is found, the second element is 'True' if the symbol is a
1406      field of a method's object (e.g., 'this' in C++), otherwise it is
1407      'False'.  If the symbol is not found, the second element is
1408      'False'.
1409
1410  -- Function: gdb.lookup_global_symbol (name [, domain])
1411      This function searches for a global symbol by name.  The search
1412      scope can be restricted to by the domain argument.
1413
1414      NAME is the name of the symbol.  It must be a string.  The optional
1415      DOMAIN argument restricts the search to the domain type.  The
1416      DOMAIN argument must be a domain constant defined in the 'gdb'
1417      module and described later in this chapter.
1418
1419      The result is a 'gdb.Symbol' object or 'None' if the symbol is not
1420      found.
1421
1422    A 'gdb.Symbol' object has the following attributes:
1423
1424  -- Variable: Symbol.type
1425      The type of the symbol or 'None' if no type is recorded.  This
1426      attribute is represented as a 'gdb.Type' object.  *Note Types In
1427      Python::.  This attribute is not writable.
1428
1429  -- Variable: Symbol.symtab
1430      The symbol table in which the symbol appears.  This attribute is
1431      represented as a 'gdb.Symtab' object.  *Note Symbol Tables In
1432      Python::.  This attribute is not writable.
1433
1434  -- Variable: Symbol.line
1435      The line number in the source code at which the symbol was defined.
1436      This is an integer.
1437
1438  -- Variable: Symbol.name
1439      The name of the symbol as a string.  This attribute is not
1440      writable.
1441
1442  -- Variable: Symbol.linkage_name
1443      The name of the symbol, as used by the linker (i.e., may be
1444      mangled).  This attribute is not writable.
1445
1446  -- Variable: Symbol.print_name
1447      The name of the symbol in a form suitable for output.  This is
1448      either 'name' or 'linkage_name', depending on whether the user
1449      asked GDB to display demangled or mangled names.
1450
1451  -- Variable: Symbol.addr_class
1452      The address class of the symbol.  This classifies how to find the
1453      value of a symbol.  Each address class is a constant defined in the
1454      'gdb' module and described later in this chapter.
1455
1456  -- Variable: Symbol.needs_frame
1457      This is 'True' if evaluating this symbol's value requires a frame
1458      (*note Frames In Python::) and 'False' otherwise.  Typically, local
1459      variables will require a frame, but other symbols will not.
1460
1461  -- Variable: Symbol.is_argument
1462      'True' if the symbol is an argument of a function.
1463
1464  -- Variable: Symbol.is_constant
1465      'True' if the symbol is a constant.
1466
1467  -- Variable: Symbol.is_function
1468      'True' if the symbol is a function or a method.
1469
1470  -- Variable: Symbol.is_variable
1471      'True' if the symbol is a variable.
1472
1473    A 'gdb.Symbol' object has the following methods:
1474
1475  -- Function: Symbol.is_valid ()
1476      Returns 'True' if the 'gdb.Symbol' object is valid, 'False' if not.
1477      A 'gdb.Symbol' object can become invalid if the symbol it refers to
1478      does not exist in GDB any longer.  All other 'gdb.Symbol' methods
1479      will throw an exception if it is invalid at the time the method is
1480      called.
1481
1482  -- Function: Symbol.value ([frame])
1483      Compute the value of the symbol, as a 'gdb.Value'.  For functions,
1484      this computes the address of the function, cast to the appropriate
1485      type.  If the symbol requires a frame in order to compute its
1486      value, then FRAME must be given.  If FRAME is not given, or if
1487      FRAME is invalid, then this method will throw an exception.
1488
1489    The available domain categories in 'gdb.Symbol' are represented as
1490 constants in the 'gdb' module:
1491
1492 'gdb.SYMBOL_UNDEF_DOMAIN'
1493      This is used when a domain has not been discovered or none of the
1494      following domains apply.  This usually indicates an error either in
1495      the symbol information or in GDB's handling of symbols.
1496
1497 'gdb.SYMBOL_VAR_DOMAIN'
1498      This domain contains variables, function names, typedef names and
1499      enum type values.
1500
1501 'gdb.SYMBOL_STRUCT_DOMAIN'
1502      This domain holds struct, union and enum type names.
1503
1504 'gdb.SYMBOL_LABEL_DOMAIN'
1505      This domain contains names of labels (for gotos).
1506
1507 'gdb.SYMBOL_VARIABLES_DOMAIN'
1508      This domain holds a subset of the 'SYMBOLS_VAR_DOMAIN'; it contains
1509      everything minus functions and types.
1510
1511 'gdb.SYMBOL_FUNCTION_DOMAIN'
1512      This domain contains all functions.
1513
1514 'gdb.SYMBOL_TYPES_DOMAIN'
1515      This domain contains all types.
1516
1517    The available address class categories in 'gdb.Symbol' are
1518 represented as constants in the 'gdb' module:
1519
1520 'gdb.SYMBOL_LOC_UNDEF'
1521      If this is returned by address class, it indicates an error either
1522      in the symbol information or in GDB's handling of symbols.
1523
1524 'gdb.SYMBOL_LOC_CONST'
1525      Value is constant int.
1526
1527 'gdb.SYMBOL_LOC_STATIC'
1528      Value is at a fixed address.
1529
1530 'gdb.SYMBOL_LOC_REGISTER'
1531      Value is in a register.
1532
1533 'gdb.SYMBOL_LOC_ARG'
1534      Value is an argument.  This value is at the offset stored within
1535      the symbol inside the frame's argument list.
1536
1537 'gdb.SYMBOL_LOC_REF_ARG'
1538      Value address is stored in the frame's argument list.  Just like
1539      'LOC_ARG' except that the value's address is stored at the offset,
1540      not the value itself.
1541
1542 'gdb.SYMBOL_LOC_REGPARM_ADDR'
1543      Value is a specified register.  Just like 'LOC_REGISTER' except the
1544      register holds the address of the argument instead of the argument
1545      itself.
1546
1547 'gdb.SYMBOL_LOC_LOCAL'
1548      Value is a local variable.
1549
1550 'gdb.SYMBOL_LOC_TYPEDEF'
1551      Value not used.  Symbols in the domain 'SYMBOL_STRUCT_DOMAIN' all
1552      have this class.
1553
1554 'gdb.SYMBOL_LOC_BLOCK'
1555      Value is a block.
1556
1557 'gdb.SYMBOL_LOC_CONST_BYTES'
1558      Value is a byte-sequence.
1559
1560 'gdb.SYMBOL_LOC_UNRESOLVED'
1561      Value is at a fixed address, but the address of the variable has to
1562      be determined from the minimal symbol table whenever the variable
1563      is referenced.
1564
1565 'gdb.SYMBOL_LOC_OPTIMIZED_OUT'
1566      The value does not actually exist in the program.
1567
1568 'gdb.SYMBOL_LOC_COMPUTED'
1569      The value's address is a computed location.
1570
1571 \1f
1572 File: gdb.info,  Node: Symbol Tables In Python,  Next: Line Tables In Python,  Prev: Symbols In Python,  Up: Python API
1573
1574 23.2.2.26 Symbol table representation in Python.
1575 ................................................
1576
1577 Access to symbol table data maintained by GDB on the inferior is exposed
1578 to Python via two objects: 'gdb.Symtab_and_line' and 'gdb.Symtab'.
1579 Symbol table and line data for a frame is returned from the 'find_sal'
1580 method in 'gdb.Frame' object.  *Note Frames In Python::.
1581
1582    For more information on GDB's symbol table management, see *note
1583 Examining the Symbol Table: Symbols, for more information.
1584
1585    A 'gdb.Symtab_and_line' object has the following attributes:
1586
1587  -- Variable: Symtab_and_line.symtab
1588      The symbol table object ('gdb.Symtab') for this frame.  This
1589      attribute is not writable.
1590
1591  -- Variable: Symtab_and_line.pc
1592      Indicates the start of the address range occupied by code for the
1593      current source line.  This attribute is not writable.
1594
1595  -- Variable: Symtab_and_line.last
1596      Indicates the end of the address range occupied by code for the
1597      current source line.  This attribute is not writable.
1598
1599  -- Variable: Symtab_and_line.line
1600      Indicates the current line number for this object.  This attribute
1601      is not writable.
1602
1603    A 'gdb.Symtab_and_line' object has the following methods:
1604
1605  -- Function: Symtab_and_line.is_valid ()
1606      Returns 'True' if the 'gdb.Symtab_and_line' object is valid,
1607      'False' if not.  A 'gdb.Symtab_and_line' object can become invalid
1608      if the Symbol table and line object it refers to does not exist in
1609      GDB any longer.  All other 'gdb.Symtab_and_line' methods will throw
1610      an exception if it is invalid at the time the method is called.
1611
1612    A 'gdb.Symtab' object has the following attributes:
1613
1614  -- Variable: Symtab.filename
1615      The symbol table's source filename.  This attribute is not
1616      writable.
1617
1618  -- Variable: Symtab.objfile
1619      The symbol table's backing object file.  *Note Objfiles In
1620      Python::.  This attribute is not writable.
1621
1622    A 'gdb.Symtab' object has the following methods:
1623
1624  -- Function: Symtab.is_valid ()
1625      Returns 'True' if the 'gdb.Symtab' object is valid, 'False' if not.
1626      A 'gdb.Symtab' object can become invalid if the symbol table it
1627      refers to does not exist in GDB any longer.  All other 'gdb.Symtab'
1628      methods will throw an exception if it is invalid at the time the
1629      method is called.
1630
1631  -- Function: Symtab.fullname ()
1632      Return the symbol table's source absolute file name.
1633
1634  -- Function: Symtab.global_block ()
1635      Return the global block of the underlying symbol table.  *Note
1636      Blocks In Python::.
1637
1638  -- Function: Symtab.static_block ()
1639      Return the static block of the underlying symbol table.  *Note
1640      Blocks In Python::.
1641
1642  -- Function: Symtab.linetable ()
1643      Return the line table associated with the symbol table.  *Note Line
1644      Tables In Python::.
1645
1646 \1f
1647 File: gdb.info,  Node: Line Tables In Python,  Next: Breakpoints In Python,  Prev: Symbol Tables In Python,  Up: Python API
1648
1649 23.2.2.27 Manipulating line tables using Python
1650 ...............................................
1651
1652 Python code can request and inspect line table information from a symbol
1653 table that is loaded in GDB.  A line table is a mapping of source lines
1654 to their executable locations in memory.  To acquire the line table
1655 information for a particular symbol table, use the 'linetable' function
1656 (*note Symbol Tables In Python::).
1657
1658    A 'gdb.LineTable' is iterable.  The iterator returns 'LineTableEntry'
1659 objects that correspond to the source line and address for each line
1660 table entry.  'LineTableEntry' objects have the following attributes:
1661
1662  -- Variable: LineTableEntry.line
1663      The source line number for this line table entry.  This number
1664      corresponds to the actual line of source.  This attribute is not
1665      writable.
1666
1667  -- Variable: LineTableEntry.pc
1668      The address that is associated with the line table entry where the
1669      executable code for that source line resides in memory.  This
1670      attribute is not writable.
1671
1672    As there can be multiple addresses for a single source line, you may
1673 receive multiple 'LineTableEntry' objects with matching 'line'
1674 attributes, but with different 'pc' attributes.  The iterator is sorted
1675 in ascending 'pc' order.  Here is a small example illustrating iterating
1676 over a line table.
1677
1678      symtab = gdb.selected_frame().find_sal().symtab
1679      linetable = symtab.linetable()
1680      for line in linetable:
1681         print "Line: "+str(line.line)+" Address: "+hex(line.pc)
1682
1683    This will have the following output:
1684
1685      Line: 33 Address: 0x4005c8L
1686      Line: 37 Address: 0x4005caL
1687      Line: 39 Address: 0x4005d2L
1688      Line: 40 Address: 0x4005f8L
1689      Line: 42 Address: 0x4005ffL
1690      Line: 44 Address: 0x400608L
1691      Line: 42 Address: 0x40060cL
1692      Line: 45 Address: 0x400615L
1693
1694    In addition to being able to iterate over a 'LineTable', it also has
1695 the following direct access methods:
1696
1697  -- Function: LineTable.line (line)
1698      Return a Python 'Tuple' of 'LineTableEntry' objects for any entries
1699      in the line table for the given LINE, which specifies the source
1700      code line.  If there are no entries for that source code LINE, the
1701      Python 'None' is returned.
1702
1703  -- Function: LineTable.has_line (line)
1704      Return a Python 'Boolean' indicating whether there is an entry in
1705      the line table for this source line.  Return 'True' if an entry is
1706      found, or 'False' if not.
1707
1708  -- Function: LineTable.source_lines ()
1709      Return a Python 'List' of the source line numbers in the symbol
1710      table.  Only lines with executable code locations are returned.
1711      The contents of the 'List' will just be the source line entries
1712      represented as Python 'Long' values.
1713
1714 \1f
1715 File: gdb.info,  Node: Breakpoints In Python,  Next: Finish Breakpoints in Python,  Prev: Line Tables In Python,  Up: Python API
1716
1717 23.2.2.28 Manipulating breakpoints using Python
1718 ...............................................
1719
1720 Python code can manipulate breakpoints via the 'gdb.Breakpoint' class.
1721
1722  -- Function: Breakpoint.__init__ (spec [, type [, wp_class [,internal
1723           [,temporary]]]])
1724      Create a new breakpoint according to SPEC, which is a string naming
1725      the location of the breakpoint, or an expression that defines a
1726      watchpoint.  The contents can be any location recognized by the
1727      'break' command, or in the case of a watchpoint, by the 'watch'
1728      command.  The optional TYPE denotes the breakpoint to create from
1729      the types defined later in this chapter.  This argument can be
1730      either 'gdb.BP_BREAKPOINT' or 'gdb.BP_WATCHPOINT'; it defaults to
1731      'gdb.BP_BREAKPOINT'.  The optional INTERNAL argument allows the
1732      breakpoint to become invisible to the user.  The breakpoint will
1733      neither be reported when created, nor will it be listed in the
1734      output from 'info breakpoints' (but will be listed with the 'maint
1735      info breakpoints' command).  The optional TEMPORARY argument makes
1736      the breakpoint a temporary breakpoint.  Temporary breakpoints are
1737      deleted after they have been hit.  Any further access to the Python
1738      breakpoint after it has been hit will result in a runtime error (as
1739      that breakpoint has now been automatically deleted).  The optional
1740      WP_CLASS argument defines the class of watchpoint to create, if
1741      TYPE is 'gdb.BP_WATCHPOINT'.  If a watchpoint class is not
1742      provided, it is assumed to be a 'gdb.WP_WRITE' class.
1743
1744  -- Function: Breakpoint.stop (self)
1745      The 'gdb.Breakpoint' class can be sub-classed and, in particular,
1746      you may choose to implement the 'stop' method.  If this method is
1747      defined in a sub-class of 'gdb.Breakpoint', it will be called when
1748      the inferior reaches any location of a breakpoint which
1749      instantiates that sub-class.  If the method returns 'True', the
1750      inferior will be stopped at the location of the breakpoint,
1751      otherwise the inferior will continue.
1752
1753      If there are multiple breakpoints at the same location with a
1754      'stop' method, each one will be called regardless of the return
1755      status of the previous.  This ensures that all 'stop' methods have
1756      a chance to execute at that location.  In this scenario if one of
1757      the methods returns 'True' but the others return 'False', the
1758      inferior will still be stopped.
1759
1760      You should not alter the execution state of the inferior (i.e.,
1761      step, next, etc.), alter the current frame context (i.e., change
1762      the current active frame), or alter, add or delete any breakpoint.
1763      As a general rule, you should not alter any data within GDB or the
1764      inferior at this time.
1765
1766      Example 'stop' implementation:
1767
1768           class MyBreakpoint (gdb.Breakpoint):
1769                 def stop (self):
1770                   inf_val = gdb.parse_and_eval("foo")
1771                   if inf_val == 3:
1772                     return True
1773                   return False
1774
1775    The available watchpoint types represented by constants are defined
1776 in the 'gdb' module:
1777
1778 'gdb.WP_READ'
1779      Read only watchpoint.
1780
1781 'gdb.WP_WRITE'
1782      Write only watchpoint.
1783
1784 'gdb.WP_ACCESS'
1785      Read/Write watchpoint.
1786
1787  -- Function: Breakpoint.is_valid ()
1788      Return 'True' if this 'Breakpoint' object is valid, 'False'
1789      otherwise.  A 'Breakpoint' object can become invalid if the user
1790      deletes the breakpoint.  In this case, the object still exists, but
1791      the underlying breakpoint does not.  In the cases of watchpoint
1792      scope, the watchpoint remains valid even if execution of the
1793      inferior leaves the scope of that watchpoint.
1794
1795  -- Function: Breakpoint.delete
1796      Permanently deletes the GDB breakpoint.  This also invalidates the
1797      Python 'Breakpoint' object.  Any further access to this object's
1798      attributes or methods will raise an error.
1799
1800  -- Variable: Breakpoint.enabled
1801      This attribute is 'True' if the breakpoint is enabled, and 'False'
1802      otherwise.  This attribute is writable.
1803
1804  -- Variable: Breakpoint.silent
1805      This attribute is 'True' if the breakpoint is silent, and 'False'
1806      otherwise.  This attribute is writable.
1807
1808      Note that a breakpoint can also be silent if it has commands and
1809      the first command is 'silent'.  This is not reported by the
1810      'silent' attribute.
1811
1812  -- Variable: Breakpoint.thread
1813      If the breakpoint is thread-specific, this attribute holds the
1814      thread id.  If the breakpoint is not thread-specific, this
1815      attribute is 'None'.  This attribute is writable.
1816
1817  -- Variable: Breakpoint.task
1818      If the breakpoint is Ada task-specific, this attribute holds the
1819      Ada task id.  If the breakpoint is not task-specific (or the
1820      underlying language is not Ada), this attribute is 'None'.  This
1821      attribute is writable.
1822
1823  -- Variable: Breakpoint.ignore_count
1824      This attribute holds the ignore count for the breakpoint, an
1825      integer.  This attribute is writable.
1826
1827  -- Variable: Breakpoint.number
1828      This attribute holds the breakpoint's number -- the identifier used
1829      by the user to manipulate the breakpoint.  This attribute is not
1830      writable.
1831
1832  -- Variable: Breakpoint.type
1833      This attribute holds the breakpoint's type -- the identifier used
1834      to determine the actual breakpoint type or use-case.  This
1835      attribute is not writable.
1836
1837  -- Variable: Breakpoint.visible
1838      This attribute tells whether the breakpoint is visible to the user
1839      when set, or when the 'info breakpoints' command is run.  This
1840      attribute is not writable.
1841
1842  -- Variable: Breakpoint.temporary
1843      This attribute indicates whether the breakpoint was created as a
1844      temporary breakpoint.  Temporary breakpoints are automatically
1845      deleted after that breakpoint has been hit.  Access to this
1846      attribute, and all other attributes and functions other than the
1847      'is_valid' function, will result in an error after the breakpoint
1848      has been hit (as it has been automatically deleted).  This
1849      attribute is not writable.
1850
1851    The available types are represented by constants defined in the 'gdb'
1852 module:
1853
1854 'gdb.BP_BREAKPOINT'
1855      Normal code breakpoint.
1856
1857 'gdb.BP_WATCHPOINT'
1858      Watchpoint breakpoint.
1859
1860 'gdb.BP_HARDWARE_WATCHPOINT'
1861      Hardware assisted watchpoint.
1862
1863 'gdb.BP_READ_WATCHPOINT'
1864      Hardware assisted read watchpoint.
1865
1866 'gdb.BP_ACCESS_WATCHPOINT'
1867      Hardware assisted access watchpoint.
1868
1869  -- Variable: Breakpoint.hit_count
1870      This attribute holds the hit count for the breakpoint, an integer.
1871      This attribute is writable, but currently it can only be set to
1872      zero.
1873
1874  -- Variable: Breakpoint.location
1875      This attribute holds the location of the breakpoint, as specified
1876      by the user.  It is a string.  If the breakpoint does not have a
1877      location (that is, it is a watchpoint) the attribute's value is
1878      'None'.  This attribute is not writable.
1879
1880  -- Variable: Breakpoint.expression
1881      This attribute holds a breakpoint expression, as specified by the
1882      user.  It is a string.  If the breakpoint does not have an
1883      expression (the breakpoint is not a watchpoint) the attribute's
1884      value is 'None'.  This attribute is not writable.
1885
1886  -- Variable: Breakpoint.condition
1887      This attribute holds the condition of the breakpoint, as specified
1888      by the user.  It is a string.  If there is no condition, this
1889      attribute's value is 'None'.  This attribute is writable.
1890
1891  -- Variable: Breakpoint.commands
1892      This attribute holds the commands attached to the breakpoint.  If
1893      there are commands, this attribute's value is a string holding all
1894      the commands, separated by newlines.  If there are no commands,
1895      this attribute is 'None'.  This attribute is not writable.
1896
1897 \1f
1898 File: gdb.info,  Node: Finish Breakpoints in Python,  Next: Lazy Strings In Python,  Prev: Breakpoints In Python,  Up: Python API
1899
1900 23.2.2.29 Finish Breakpoints
1901 ............................
1902
1903 A finish breakpoint is a temporary breakpoint set at the return address
1904 of a frame, based on the 'finish' command.  'gdb.FinishBreakpoint'
1905 extends 'gdb.Breakpoint'.  The underlying breakpoint will be disabled
1906 and deleted when the execution will run out of the breakpoint scope
1907 (i.e. 'Breakpoint.stop' or 'FinishBreakpoint.out_of_scope' triggered).
1908 Finish breakpoints are thread specific and must be create with the right
1909 thread selected.
1910
1911  -- Function: FinishBreakpoint.__init__ ([frame] [, internal])
1912      Create a finish breakpoint at the return address of the 'gdb.Frame'
1913      object FRAME.  If FRAME is not provided, this defaults to the
1914      newest frame.  The optional INTERNAL argument allows the breakpoint
1915      to become invisible to the user.  *Note Breakpoints In Python::,
1916      for further details about this argument.
1917
1918  -- Function: FinishBreakpoint.out_of_scope (self)
1919      In some circumstances (e.g. 'longjmp', C++ exceptions, GDB 'return'
1920      command, ...), a function may not properly terminate, and thus
1921      never hit the finish breakpoint.  When GDB notices such a
1922      situation, the 'out_of_scope' callback will be triggered.
1923
1924      You may want to sub-class 'gdb.FinishBreakpoint' and override this
1925      method:
1926
1927           class MyFinishBreakpoint (gdb.FinishBreakpoint)
1928               def stop (self):
1929                   print "normal finish"
1930                   return True
1931
1932               def out_of_scope ():
1933                   print "abnormal finish"
1934
1935  -- Variable: FinishBreakpoint.return_value
1936      When GDB is stopped at a finish breakpoint and the frame used to
1937      build the 'gdb.FinishBreakpoint' object had debug symbols, this
1938      attribute will contain a 'gdb.Value' object corresponding to the
1939      return value of the function.  The value will be 'None' if the
1940      function return type is 'void' or if the return value was not
1941      computable.  This attribute is not writable.
1942
1943 \1f
1944 File: gdb.info,  Node: Lazy Strings In Python,  Next: Architectures In Python,  Prev: Finish Breakpoints in Python,  Up: Python API
1945
1946 23.2.2.30 Python representation of lazy strings.
1947 ................................................
1948
1949 A "lazy string" is a string whose contents is not retrieved or encoded
1950 until it is needed.
1951
1952    A 'gdb.LazyString' is represented in GDB as an 'address' that points
1953 to a region of memory, an 'encoding' that will be used to encode that
1954 region of memory, and a 'length' to delimit the region of memory that
1955 represents the string.  The difference between a 'gdb.LazyString' and a
1956 string wrapped within a 'gdb.Value' is that a 'gdb.LazyString' will be
1957 treated differently by GDB when printing.  A 'gdb.LazyString' is
1958 retrieved and encoded during printing, while a 'gdb.Value' wrapping a
1959 string is immediately retrieved and encoded on creation.
1960
1961    A 'gdb.LazyString' object has the following functions:
1962
1963  -- Function: LazyString.value ()
1964      Convert the 'gdb.LazyString' to a 'gdb.Value'.  This value will
1965      point to the string in memory, but will lose all the delayed
1966      retrieval, encoding and handling that GDB applies to a
1967      'gdb.LazyString'.
1968
1969  -- Variable: LazyString.address
1970      This attribute holds the address of the string.  This attribute is
1971      not writable.
1972
1973  -- Variable: LazyString.length
1974      This attribute holds the length of the string in characters.  If
1975      the length is -1, then the string will be fetched and encoded up to
1976      the first null of appropriate width.  This attribute is not
1977      writable.
1978
1979  -- Variable: LazyString.encoding
1980      This attribute holds the encoding that will be applied to the
1981      string when the string is printed by GDB.  If the encoding is not
1982      set, or contains an empty string, then GDB will select the most
1983      appropriate encoding when the string is printed.  This attribute is
1984      not writable.
1985
1986  -- Variable: LazyString.type
1987      This attribute holds the type that is represented by the lazy
1988      string's type.  For a lazy string this will always be a pointer
1989      type.  To resolve this to the lazy string's character type, use the
1990      type's 'target' method.  *Note Types In Python::.  This attribute
1991      is not writable.
1992
1993 \1f
1994 File: gdb.info,  Node: Architectures In Python,  Prev: Lazy Strings In Python,  Up: Python API
1995
1996 23.2.2.31 Python representation of architectures
1997 ................................................
1998
1999 GDB uses architecture specific parameters and artifacts in a number of
2000 its various computations.  An architecture is represented by an instance
2001 of the 'gdb.Architecture' class.
2002
2003    A 'gdb.Architecture' class has the following methods:
2004
2005  -- Function: Architecture.name ()
2006      Return the name (string value) of the architecture.
2007
2008  -- Function: Architecture.disassemble (START_PC [, END_PC [, COUNT]])
2009      Return a list of disassembled instructions starting from the memory
2010      address START_PC.  The optional arguments END_PC and COUNT
2011      determine the number of instructions in the returned list.  If both
2012      the optional arguments END_PC and COUNT are specified, then a list
2013      of at most COUNT disassembled instructions whose start address
2014      falls in the closed memory address interval from START_PC to END_PC
2015      are returned.  If END_PC is not specified, but COUNT is specified,
2016      then COUNT number of instructions starting from the address
2017      START_PC are returned.  If COUNT is not specified but END_PC is
2018      specified, then all instructions whose start address falls in the
2019      closed memory address interval from START_PC to END_PC are
2020      returned.  If neither END_PC nor COUNT are specified, then a single
2021      instruction at START_PC is returned.  For all of these cases, each
2022      element of the returned list is a Python 'dict' with the following
2023      string keys:
2024
2025      'addr'
2026           The value corresponding to this key is a Python long integer
2027           capturing the memory address of the instruction.
2028
2029      'asm'
2030           The value corresponding to this key is a string value which
2031           represents the instruction with assembly language mnemonics.
2032           The assembly language flavor used is the same as that
2033           specified by the current CLI variable 'disassembly-flavor'.
2034           *Note Machine Code::.
2035
2036      'length'
2037           The value corresponding to this key is the length (integer
2038           value) of the instruction in bytes.
2039
2040 \1f
2041 File: gdb.info,  Node: Python Auto-loading,  Next: Python modules,  Prev: Python API,  Up: Python
2042
2043 23.2.3 Python Auto-loading
2044 --------------------------
2045
2046 When a new object file is read (for example, due to the 'file' command,
2047 or because the inferior has loaded a shared library), GDB will look for
2048 Python support scripts in several ways: 'OBJFILE-gdb.py' and
2049 '.debug_gdb_scripts' section.  *Note Auto-loading extensions::.
2050
2051    The auto-loading feature is useful for supplying application-specific
2052 debugging commands and scripts.
2053
2054    Auto-loading can be enabled or disabled, and the list of auto-loaded
2055 scripts can be printed.
2056
2057 'set auto-load python-scripts [on|off]'
2058      Enable or disable the auto-loading of Python scripts.
2059
2060 'show auto-load python-scripts'
2061      Show whether auto-loading of Python scripts is enabled or disabled.
2062
2063 'info auto-load python-scripts [REGEXP]'
2064      Print the list of all Python scripts that GDB auto-loaded.
2065
2066      Also printed is the list of Python scripts that were mentioned in
2067      the '.debug_gdb_scripts' section and were not found (*note
2068      dotdebug_gdb_scripts section::).  This is useful because their
2069      names are not printed when GDB tries to load them and fails.  There
2070      may be many of them, and printing an error message for each one is
2071      problematic.
2072
2073      If REGEXP is supplied only Python scripts with matching names are
2074      printed.
2075
2076      Example:
2077
2078           (gdb) info auto-load python-scripts
2079           Loaded Script
2080           Yes    py-section-script.py
2081                  full name: /tmp/py-section-script.py
2082           No     my-foo-pretty-printers.py
2083
2084    When reading an auto-loaded file, GDB sets the "current objfile".
2085 This is available via the 'gdb.current_objfile' function (*note Objfiles
2086 In Python::).  This can be useful for registering objfile-specific
2087 pretty-printers and frame-filters.
2088
2089 \1f
2090 File: gdb.info,  Node: Python modules,  Prev: Python Auto-loading,  Up: Python
2091
2092 23.2.4 Python modules
2093 ---------------------
2094
2095 GDB comes with several modules to assist writing Python code.
2096
2097 * Menu:
2098
2099 * gdb.printing::       Building and registering pretty-printers.
2100 * gdb.types::          Utilities for working with types.
2101 * gdb.prompt::         Utilities for prompt value substitution.
2102
2103 \1f
2104 File: gdb.info,  Node: gdb.printing,  Next: gdb.types,  Up: Python modules
2105
2106 23.2.4.1 gdb.printing
2107 .....................
2108
2109 This module provides a collection of utilities for working with
2110 pretty-printers.
2111
2112 'PrettyPrinter (NAME, SUBPRINTERS=None)'
2113      This class specifies the API that makes 'info pretty-printer',
2114      'enable pretty-printer' and 'disable pretty-printer' work.
2115      Pretty-printers should generally inherit from this class.
2116
2117 'SubPrettyPrinter (NAME)'
2118      For printers that handle multiple types, this class specifies the
2119      corresponding API for the subprinters.
2120
2121 'RegexpCollectionPrettyPrinter (NAME)'
2122      Utility class for handling multiple printers, all recognized via
2123      regular expressions.  *Note Writing a Pretty-Printer::, for an
2124      example.
2125
2126 'FlagEnumerationPrinter (NAME)'
2127      A pretty-printer which handles printing of 'enum' values.  Unlike
2128      GDB's built-in 'enum' printing, this printer attempts to work
2129      properly when there is some overlap between the enumeration
2130      constants.  The argument NAME is the name of the printer and also
2131      the name of the 'enum' type to look up.
2132
2133 'register_pretty_printer (OBJ, PRINTER, REPLACE=False)'
2134      Register PRINTER with the pretty-printer list of OBJ.  If REPLACE
2135      is 'True' then any existing copy of the printer is replaced.
2136      Otherwise a 'RuntimeError' exception is raised if a printer with
2137      the same name already exists.
2138
2139 \1f
2140 File: gdb.info,  Node: gdb.types,  Next: gdb.prompt,  Prev: gdb.printing,  Up: Python modules
2141
2142 23.2.4.2 gdb.types
2143 ..................
2144
2145 This module provides a collection of utilities for working with
2146 'gdb.Type' objects.
2147
2148 'get_basic_type (TYPE)'
2149      Return TYPE with const and volatile qualifiers stripped, and with
2150      typedefs and C++ references converted to the underlying type.
2151
2152      C++ example:
2153
2154           typedef const int const_int;
2155           const_int foo (3);
2156           const_int& foo_ref (foo);
2157           int main () { return 0; }
2158
2159      Then in gdb:
2160
2161           (gdb) start
2162           (gdb) python import gdb.types
2163           (gdb) python foo_ref = gdb.parse_and_eval("foo_ref")
2164           (gdb) python print gdb.types.get_basic_type(foo_ref.type)
2165           int
2166
2167 'has_field (TYPE, FIELD)'
2168      Return 'True' if TYPE, assumed to be a type with fields (e.g., a
2169      structure or union), has field FIELD.
2170
2171 'make_enum_dict (ENUM_TYPE)'
2172      Return a Python 'dictionary' type produced from ENUM_TYPE.
2173
2174 'deep_items (TYPE)'
2175      Returns a Python iterator similar to the standard
2176      'gdb.Type.iteritems' method, except that the iterator returned by
2177      'deep_items' will recursively traverse anonymous struct or union
2178      fields.  For example:
2179
2180           struct A
2181           {
2182               int a;
2183               union {
2184                   int b0;
2185                   int b1;
2186               };
2187           };
2188
2189      Then in GDB:
2190           (gdb) python import gdb.types
2191           (gdb) python struct_a = gdb.lookup_type("struct A")
2192           (gdb) python print struct_a.keys ()
2193           {['a', '']}
2194           (gdb) python print [k for k,v in gdb.types.deep_items(struct_a)]
2195           {['a', 'b0', 'b1']}
2196
2197 'get_type_recognizers ()'
2198      Return a list of the enabled type recognizers for the current
2199      context.  This is called by GDB during the type-printing process
2200      (*note Type Printing API::).
2201
2202 'apply_type_recognizers (recognizers, type_obj)'
2203      Apply the type recognizers, RECOGNIZERS, to the type object
2204      TYPE_OBJ.  If any recognizer returns a string, return that string.
2205      Otherwise, return 'None'.  This is called by GDB during the
2206      type-printing process (*note Type Printing API::).
2207
2208 'register_type_printer (locus, printer)'
2209      This is a convenience function to register a type printer PRINTER.
2210      The printer must implement the type printer protocol.  The LOCUS
2211      argument is either a 'gdb.Objfile', in which case the printer is
2212      registered with that objfile; a 'gdb.Progspace', in which case the
2213      printer is registered with that progspace; or 'None', in which case
2214      the printer is registered globally.
2215
2216 'TypePrinter'
2217      This is a base class that implements the type printer protocol.
2218      Type printers are encouraged, but not required, to derive from this
2219      class.  It defines a constructor:
2220
2221       -- Method on TypePrinter: __init__ (self, name)
2222           Initialize the type printer with the given name.  The new
2223           printer starts in the enabled state.
2224
2225 \1f
2226 File: gdb.info,  Node: gdb.prompt,  Prev: gdb.types,  Up: Python modules
2227
2228 23.2.4.3 gdb.prompt
2229 ...................
2230
2231 This module provides a method for prompt value-substitution.
2232
2233 'substitute_prompt (STRING)'
2234      Return STRING with escape sequences substituted by values.  Some
2235      escape sequences take arguments.  You can specify arguments inside
2236      "{}" immediately following the escape sequence.
2237
2238      The escape sequences you can pass to this function are:
2239
2240      '\\'
2241           Substitute a backslash.
2242      '\e'
2243           Substitute an ESC character.
2244      '\f'
2245           Substitute the selected frame; an argument names a frame
2246           parameter.
2247      '\n'
2248           Substitute a newline.
2249      '\p'
2250           Substitute a parameter's value; the argument names the
2251           parameter.
2252      '\r'
2253           Substitute a carriage return.
2254      '\t'
2255           Substitute the selected thread; an argument names a thread
2256           parameter.
2257      '\v'
2258           Substitute the version of GDB.
2259      '\w'
2260           Substitute the current working directory.
2261      '\['
2262           Begin a sequence of non-printing characters.  These sequences
2263           are typically used with the ESC character, and are not counted
2264           in the string length.  Example: "\[\e[0;34m\](gdb)\[\e[0m\]"
2265           will return a blue-colored "(gdb)" prompt where the length is
2266           five.
2267      '\]'
2268           End a sequence of non-printing characters.
2269
2270      For example:
2271
2272           substitute_prompt (``frame: \f,
2273                              print arguments: \p{print frame-arguments}'')
2274
2275 will return the string:
2276
2277           "frame: main, print arguments: scalars"
2278
2279 \1f
2280 File: gdb.info,  Node: Guile,  Next: Auto-loading extensions,  Prev: Python,  Up: Extending GDB
2281
2282 23.3 Extending GDB using Guile
2283 ==============================
2284
2285 You can extend GDB using the Guile implementation of the Scheme
2286 programming language (http://www.gnu.org/software/guile/).  This feature
2287 is available only if GDB was configured using '--with-guile'.
2288
2289 * Menu:
2290
2291 * Guile Introduction::     Introduction to Guile scripting in GDB
2292 * Guile Commands::         Accessing Guile from GDB
2293 * Guile API::              Accessing GDB from Guile
2294 * Guile Auto-loading::     Automatically loading Guile code
2295 * Guile Modules::          Guile modules provided by GDB
2296
2297 \1f
2298 File: gdb.info,  Node: Guile Introduction,  Next: Guile Commands,  Up: Guile
2299
2300 23.3.1 Guile Introduction
2301 -------------------------
2302
2303 Guile is an implementation of the Scheme programming language and is the
2304 GNU project's official extension language.
2305
2306    Guile support in GDB follows the Python support in GDB reasonably
2307 closely, so concepts there should carry over.  However, some things are
2308 done differently where it makes sense.
2309
2310    GDB requires Guile version 2.0 or greater.  Older versions are not
2311 supported.
2312
2313    Guile scripts used by GDB should be installed in
2314 'DATA-DIRECTORY/guile', where DATA-DIRECTORY is the data directory as
2315 determined at GDB startup (*note Data Files::).  This directory, known
2316 as the "guile directory", is automatically added to the Guile Search
2317 Path in order to allow the Guile interpreter to locate all scripts
2318 installed at this location.
2319
2320 \1f
2321 File: gdb.info,  Node: Guile Commands,  Next: Guile API,  Prev: Guile Introduction,  Up: Guile
2322
2323 23.3.2 Guile Commands
2324 ---------------------
2325
2326 GDB provides two commands for accessing the Guile interpreter:
2327
2328 'guile-repl'
2329 'gr'
2330      The 'guile-repl' command can be used to start an interactive Guile
2331      prompt or "repl".  To return to GDB, type ',q' or the 'EOF'
2332      character (e.g., 'Ctrl-D' on an empty prompt).  These commands do
2333      not take any arguments.
2334
2335 'guile [SCHEME-EXPRESSION]'
2336 'gu [SCHEME-EXPRESSION]'
2337      The 'guile' command can be used to evaluate a Scheme expression.
2338
2339      If given an argument, GDB will pass the argument to the Guile
2340      interpreter for evaluation.
2341
2342           (gdb) guile (display (+ 20 3)) (newline)
2343           23
2344
2345      The result of the Scheme expression is displayed using normal Guile
2346      rules.
2347
2348           (gdb) guile (+ 20 3)
2349           23
2350
2351      If you do not provide an argument to 'guile', it will act as a
2352      multi-line command, like 'define'.  In this case, the Guile script
2353      is made up of subsequent command lines, given after the 'guile'
2354      command.  This command list is terminated using a line containing
2355      'end'.  For example:
2356
2357           (gdb) guile
2358           >(display 23)
2359           >(newline)
2360           >end
2361           23
2362
2363    It is also possible to execute a Guile script from the GDB
2364 interpreter:
2365
2366 'source script-name'
2367      The script name must end with '.scm' and GDB must be configured to
2368      recognize the script language based on filename extension using the
2369      'script-extension' setting.  *Note Extending GDB: Extending GDB.
2370
2371 'guile (load "script-name")'
2372      This method uses the 'load' Guile function.  It takes a string
2373      argument that is the name of the script to load.  See the Guile
2374      documentation for a description of this function.  (*note
2375      (guile)Loading::).
2376
2377 \1f
2378 File: gdb.info,  Node: Guile API,  Next: Guile Auto-loading,  Prev: Guile Commands,  Up: Guile
2379
2380 23.3.3 Guile API
2381 ----------------
2382
2383 You can get quick online help for GDB's Guile API by issuing the command
2384 'help guile', or by issuing the command ',help' from an interactive
2385 Guile session.  Furthermore, most Guile procedures provided by GDB have
2386 doc strings which can be obtained with ',describe PROCEDURE-NAME' or ',d
2387 PROCEDURE-NAME' from the Guile interactive prompt.
2388
2389 * Menu:
2390
2391 * Basic Guile::              Basic Guile Functions
2392 * Guile Configuration::      Guile configuration variables
2393 * GDB Scheme Data Types::    Scheme representations of GDB objects
2394 * Guile Exception Handling:: How Guile exceptions are translated
2395 * Values From Inferior In Guile:: Guile representation of values
2396 * Arithmetic In Guile::      Arithmetic in Guile
2397 * Types In Guile::           Guile representation of types
2398 * Guile Pretty Printing API:: Pretty-printing values with Guile
2399 * Selecting Guile Pretty-Printers:: How GDB chooses a pretty-printer
2400 * Writing a Guile Pretty-Printer:: Writing a pretty-printer
2401 * Commands In Guile::        Implementing new commands in Guile
2402 * Parameters In Guile::      Adding new GDB parameters
2403 * Progspaces In Guile::      Program spaces
2404 * Objfiles In Guile::        Object files in Guile
2405 * Frames In Guile::          Accessing inferior stack frames from Guile
2406 * Blocks In Guile::          Accessing blocks from Guile
2407 * Symbols In Guile::         Guile representation of symbols
2408 * Symbol Tables In Guile::   Guile representation of symbol tables
2409 * Breakpoints In Guile::     Manipulating breakpoints using Guile
2410 * Lazy Strings In Guile::    Guile representation of lazy strings
2411 * Architectures In Guile::   Guile representation of architectures
2412 * Disassembly In Guile::     Disassembling instructions from Guile
2413 * I/O Ports in Guile::       GDB I/O ports
2414 * Memory Ports in Guile::    Accessing memory through ports and bytevectors
2415 * Iterators In Guile::       Basic iterator support
2416
2417 \1f
2418 File: gdb.info,  Node: Basic Guile,  Next: Guile Configuration,  Up: Guile API
2419
2420 23.3.3.1 Basic Guile
2421 ....................
2422
2423 At startup, GDB overrides Guile's 'current-output-port' and
2424 'current-error-port' to print using GDB's output-paging streams.  A
2425 Guile program which outputs to one of these streams may have its output
2426 interrupted by the user (*note Screen Size::).  In this situation, a
2427 Guile 'signal' exception is thrown with value 'SIGINT'.
2428
2429    Guile's history mechanism uses the same naming as GDB's, namely the
2430 user of dollar-variables (e.g., $1, $2, etc.).  The results of
2431 evaluations in Guile and in GDB are counted separately, '$1' in Guile is
2432 not the same value as '$1' in GDB.
2433
2434    GDB is not thread-safe.  If your Guile program uses multiple threads,
2435 you must be careful to only call GDB-specific functions in the GDB
2436 thread.
2437
2438    Some care must be taken when writing Guile code to run in GDB.  Two
2439 things are worth noting in particular:
2440
2441    * GDB installs handlers for 'SIGCHLD' and 'SIGINT'.  Guile code must
2442      not override these, or even change the options using 'sigaction'.
2443      If your program changes the handling of these signals, GDB will
2444      most likely stop working correctly.  Note that it is unfortunately
2445      common for GUI toolkits to install a 'SIGCHLD' handler.
2446
2447    * GDB takes care to mark its internal file descriptors as
2448      close-on-exec.  However, this cannot be done in a thread-safe way
2449      on all platforms.  Your Guile programs should be aware of this and
2450      should both create new file descriptors with the close-on-exec flag
2451      set and arrange to close unneeded file descriptors before starting
2452      a child process.
2453
2454    GDB introduces a new Guile module, named 'gdb'.  All methods and
2455 classes added by GDB are placed in this module.  GDB does not
2456 automatically 'import' the 'gdb' module, scripts must do this
2457 themselves.  There are various options for how to import a module, so
2458 GDB leaves the choice of how the 'gdb' module is imported to the user.
2459 To simplify interactive use, it is recommended to add one of the
2460 following to your ~/.gdbinit.
2461
2462      guile (use-modules (gdb))
2463
2464      guile (use-modules ((gdb) #:renamer (symbol-prefix-proc 'gdb:)))
2465
2466    Which one to choose depends on your preference.  The second one adds
2467 'gdb:' as a prefix to all module functions and variables.
2468
2469    The rest of this manual assumes the 'gdb' module has been imported
2470 without any prefix.  See the Guile documentation for 'use-modules' for
2471 more information (*note (guile)Using Guile Modules::).
2472
2473    Example:
2474
2475      (gdb) guile (value-type (make-value 1))
2476      ERROR: Unbound variable: value-type
2477      Error while executing Scheme code.
2478      (gdb) guile (use-modules (gdb))
2479      (gdb) guile (value-type (make-value 1))
2480      int
2481      (gdb)
2482
2483    The '(gdb)' module provides these basic Guile functions.
2484
2485  -- Scheme Procedure: execute command [#:from-tty boolean] [#:to-string
2486           boolean]
2487      Evaluate COMMAND, a string, as a GDB CLI command.  If a GDB
2488      exception happens while COMMAND runs, it is translated as described
2489      in *note Guile Exception Handling: Guile Exception Handling.
2490
2491      FROM-TTY specifies whether GDB ought to consider this command as
2492      having originated from the user invoking it interactively.  It must
2493      be a boolean value.  If omitted, it defaults to '#f'.
2494
2495      By default, any output produced by COMMAND is sent to GDB's
2496      standard output (and to the log output if logging is turned on).
2497      If the TO-STRING parameter is '#t', then output will be collected
2498      by 'execute' and returned as a string.  The default is '#f', in
2499      which case the return value is unspecified.  If TO-STRING is '#t',
2500      the GDB virtual terminal will be temporarily set to unlimited width
2501      and height, and its pagination will be disabled; *note Screen
2502      Size::.
2503
2504  -- Scheme Procedure: history-ref number
2505      Return a value from GDB's value history (*note Value History::).
2506      The NUMBER argument indicates which history element to return.  If
2507      NUMBER is negative, then GDB will take its absolute value and count
2508      backward from the last element (i.e., the most recent element) to
2509      find the value to return.  If NUMBER is zero, then GDB will return
2510      the most recent element.  If the element specified by NUMBER
2511      doesn't exist in the value history, a 'gdb:error' exception will be
2512      raised.
2513
2514      If no exception is raised, the return value is always an instance
2515      of '<gdb:value>' (*note Values From Inferior In Guile::).
2516
2517      _Note:_ GDB's value history is independent of Guile's.  '$1' in
2518      GDB's value history contains the result of evaluating an expression
2519      from GDB's command line and '$1' from Guile's history contains the
2520      result of evaluating an expression from Guile's command line.
2521
2522  -- Scheme Procedure: history-append! value
2523      Append VALUE, an instance of '<gdb:value>', to GDB's value history.
2524      Return its index in the history.
2525
2526      Putting into history values returned by Guile extensions will allow
2527      the user convenient access to those values via CLI history
2528      facilities.
2529
2530  -- Scheme Procedure: parse-and-eval expression
2531      Parse EXPRESSION as an expression in the current language, evaluate
2532      it, and return the result as a '<gdb:value>'.  The EXPRESSION must
2533      be a string.
2534
2535      This function can be useful when implementing a new command (*note
2536      Commands In Guile::), as it provides a way to parse the command's
2537      arguments as an expression.  It is also is useful when computing
2538      values.  For example, it is the only way to get the value of a
2539      convenience variable (*note Convenience Vars::) as a '<gdb:value>'.
2540
2541 \1f
2542 File: gdb.info,  Node: Guile Configuration,  Next: GDB Scheme Data Types,  Prev: Basic Guile,  Up: Guile API
2543
2544 23.3.3.2 Guile Configuration
2545 ............................
2546
2547 GDB provides these Scheme functions to access various configuration
2548 parameters.
2549
2550  -- Scheme Procedure: data-directory
2551      Return a string containing GDB's data directory.  This directory
2552      contains GDB's ancillary files.
2553
2554  -- Scheme Procedure: guile-data-directory
2555      Return a string containing GDB's Guile data directory.  This
2556      directory contains the Guile modules provided by GDB.
2557
2558  -- Scheme Procedure: gdb-version
2559      Return a string containing the GDB version.
2560
2561  -- Scheme Procedure: host-config
2562      Return a string containing the host configuration.  This is the
2563      string passed to '--host' when GDB was configured.
2564
2565  -- Scheme Procedure: target-config
2566      Return a string containing the target configuration.  This is the
2567      string passed to '--target' when GDB was configured.
2568
2569 \1f
2570 File: gdb.info,  Node: GDB Scheme Data Types,  Next: Guile Exception Handling,  Prev: Guile Configuration,  Up: Guile API
2571
2572 23.3.3.3 GDB Scheme Data Types
2573 ..............................
2574
2575 The values exposed by GDB to Guile are known as "GDB objects".  There
2576 are several kinds of GDB object, and each is disjoint from all other
2577 types known to Guile.
2578
2579  -- Scheme Procedure: gdb-object-kind object
2580      Return the kind of the GDB object, e.g., '<gdb:breakpoint>', as a
2581      symbol.
2582
2583    GDB defines the following object types:
2584
2585 '<gdb:arch>'
2586      *Note Architectures In Guile::.
2587
2588 '<gdb:block>'
2589      *Note Blocks In Guile::.
2590
2591 '<gdb:block-symbols-iterator>'
2592      *Note Blocks In Guile::.
2593
2594 '<gdb:breakpoint>'
2595      *Note Breakpoints In Guile::.
2596
2597 '<gdb:command>'
2598      *Note Commands In Guile::.
2599
2600 '<gdb:exception>'
2601      *Note Guile Exception Handling::.
2602
2603 '<gdb:frame>'
2604      *Note Frames In Guile::.
2605
2606 '<gdb:iterator>'
2607      *Note Iterators In Guile::.
2608
2609 '<gdb:lazy-string>'
2610      *Note Lazy Strings In Guile::.
2611
2612 '<gdb:objfile>'
2613      *Note Objfiles In Guile::.
2614
2615 '<gdb:parameter>'
2616      *Note Parameters In Guile::.
2617
2618 '<gdb:pretty-printer>'
2619      *Note Guile Pretty Printing API::.
2620
2621 '<gdb:pretty-printer-worker>'
2622      *Note Guile Pretty Printing API::.
2623
2624 '<gdb:progspace>'
2625      *Note Progspaces In Guile::.
2626
2627 '<gdb:symbol>'
2628      *Note Symbols In Guile::.
2629
2630 '<gdb:symtab>'
2631      *Note Symbol Tables In Guile::.
2632
2633 '<gdb:sal>'
2634      *Note Symbol Tables In Guile::.
2635
2636 '<gdb:type>'
2637      *Note Types In Guile::.
2638
2639 '<gdb:field>'
2640      *Note Types In Guile::.
2641
2642 '<gdb:value>'
2643      *Note Values From Inferior In Guile::.
2644
2645    The following GDB objects are managed internally so that the Scheme
2646 function 'eq?' may be applied to them.
2647
2648 '<gdb:arch>'
2649 '<gdb:block>'
2650 '<gdb:breakpoint>'
2651 '<gdb:frame>'
2652 '<gdb:objfile>'
2653 '<gdb:progspace>'
2654 '<gdb:symbol>'
2655 '<gdb:symtab>'
2656 '<gdb:type>'
2657
2658 \1f
2659 File: gdb.info,  Node: Guile Exception Handling,  Next: Values From Inferior In Guile,  Prev: GDB Scheme Data Types,  Up: Guile API
2660
2661 23.3.3.4 Guile Exception Handling
2662 .................................
2663
2664 When executing the 'guile' command, Guile exceptions uncaught within the
2665 Guile code are translated to calls to the GDB error-reporting mechanism.
2666 If the command that called 'guile' does not handle the error, GDB will
2667 terminate it and report the error according to the setting of the 'guile
2668 print-stack' parameter.
2669
2670    The 'guile print-stack' parameter has three settings:
2671
2672 'none'
2673      Nothing is printed.
2674
2675 'message'
2676      An error message is printed containing the Guile exception name,
2677      the associated value, and the Guile call stack backtrace at the
2678      point where the exception was raised.  Example:
2679
2680           (gdb) guile (display foo)
2681           ERROR: In procedure memoize-variable-access!:
2682           ERROR: Unbound variable: foo
2683           Error while executing Scheme code.
2684
2685 'full'
2686      In addition to an error message a full backtrace is printed.
2687
2688           (gdb) set guile print-stack full
2689           (gdb) guile (display foo)
2690           Guile Backtrace:
2691           In ice-9/boot-9.scm:
2692            157: 10 [catch #t #<catch-closure 2c76e20> ...]
2693           In unknown file:
2694              ?: 9 [apply-smob/1 #<catch-closure 2c76e20>]
2695           In ice-9/boot-9.scm:
2696            157: 8 [catch #t #<catch-closure 2c76d20> ...]
2697           In unknown file:
2698              ?: 7 [apply-smob/1 #<catch-closure 2c76d20>]
2699              ?: 6 [call-with-input-string "(display foo)" ...]
2700           In ice-9/boot-9.scm:
2701           2320: 5 [save-module-excursion #<procedure 2c2dc30 ... ()>]
2702           In ice-9/eval-string.scm:
2703             44: 4 [read-and-eval #<input: string 27cb410> #:lang ...]
2704             37: 3 [lp (display foo)]
2705           In ice-9/eval.scm:
2706            387: 2 [eval # ()]
2707            393: 1 [eval #<memoized foo> ()]
2708           In unknown file:
2709              ?: 0 [memoize-variable-access! #<memoized foo> ...]
2710
2711           ERROR: In procedure memoize-variable-access!:
2712           ERROR: Unbound variable: foo
2713           Error while executing Scheme code.
2714
2715    GDB errors that happen in GDB commands invoked by Guile code are
2716 converted to Guile exceptions.  The type of the Guile exception depends
2717 on the error.
2718
2719    Guile procedures provided by GDB can throw the standard Guile
2720 exceptions like 'wrong-type-arg' and 'out-of-range'.
2721
2722    User interrupt (via 'C-c' or by typing 'q' at a pagination prompt) is
2723 translated to a Guile 'signal' exception with value 'SIGINT'.
2724
2725    GDB Guile procedures can also throw these exceptions:
2726
2727 'gdb:error'
2728      This exception is a catch-all for errors generated from within GDB.
2729
2730 'gdb:invalid-object'
2731      This exception is thrown when accessing Guile objects that wrap
2732      underlying GDB objects have become invalid.  For example, a
2733      '<gdb:breakpoint>' object becomes invalid if the user deletes it
2734      from the command line.  The object still exists in Guile, but the
2735      object it represents is gone.  Further operations on this
2736      breakpoint will throw this exception.
2737
2738 'gdb:memory-error'
2739      This exception is thrown when an operation tried to access invalid
2740      memory in the inferior.
2741
2742 'gdb:pp-type-error'
2743      This exception is thrown when a Guile pretty-printer passes a bad
2744      object to GDB.
2745
2746    The following exception-related procedures are provided by the
2747 '(gdb)' module.
2748
2749  -- Scheme Procedure: make-exception key args
2750      Return a '<gdb:exception>' object given by its KEY and ARGS, which
2751      are the standard Guile parameters of an exception.  See the Guile
2752      documentation for more information (*note (guile)Exceptions::).
2753
2754  -- Scheme Procedure: exception? object
2755      Return '#t' if OBJECT is a '<gdb:exception>' object.  Otherwise
2756      return '#f'.
2757
2758  -- Scheme Procedure: exception-key exception
2759      Return the ARGS field of a '<gdb:exception>' object.
2760
2761  -- Scheme Procedure: exception-args exception
2762      Return the ARGS field of a '<gdb:exception>' object.
2763
2764 \1f
2765 File: gdb.info,  Node: Values From Inferior In Guile,  Next: Arithmetic In Guile,  Prev: Guile Exception Handling,  Up: Guile API
2766
2767 23.3.3.5 Values From Inferior In Guile
2768 ......................................
2769
2770 GDB provides values it obtains from the inferior program in an object of
2771 type '<gdb:value>'.  GDB uses this object for its internal bookkeeping
2772 of the inferior's values, and for fetching values when necessary.
2773
2774    GDB does not memoize '<gdb:value>' objects.  'make-value' always
2775 returns a fresh object.
2776
2777      (gdb) guile (eq? (make-value 1) (make-value 1))
2778      $1 = #f
2779      (gdb) guile (equal? (make-value 1) (make-value 1))
2780      $1 = #t
2781
2782    A '<gdb:value>' that represents a function can be executed via
2783 inferior function call with 'value-call'.  Any arguments provided to the
2784 call must match the function's prototype, and must be provided in the
2785 order specified by that prototype.
2786
2787    For example, 'some-val' is a '<gdb:value>' instance representing a
2788 function that takes two integers as arguments.  To execute this
2789 function, call it like so:
2790
2791      (define result (value-call some-val 10 20))
2792
2793    Any values returned from a function call are '<gdb:value>' objects.
2794
2795    Note: Unlike Python scripting in GDB, inferior values that are simple
2796 scalars cannot be used directly in Scheme expressions that are valid for
2797 the value's data type.  For example, '(+ (parse-and-eval "int_variable")
2798 2)' does not work.  And inferior values that are structures or instances
2799 of some class cannot be accessed using any special syntax, instead
2800 'value-field' must be used.
2801
2802    The following value-related procedures are provided by the '(gdb)'
2803 module.
2804
2805  -- Scheme Procedure: value? object
2806      Return '#t' if OBJECT is a '<gdb:value>' object.  Otherwise return
2807      '#f'.
2808
2809  -- Scheme Procedure: make-value value [#:type type]
2810      Many Scheme values can be converted directly to a '<gdb:value>'
2811      with this procedure.  If TYPE is specified, the result is a value
2812      of this type, and if VALUE can't be represented with this type an
2813      exception is thrown.  Otherwise the type of the result is
2814      determined from VALUE as described below.
2815
2816      *Note Architectures In Guile::, for a list of the builtin types for
2817      an architecture.
2818
2819      Here's how Scheme values are converted when TYPE argument to
2820      'make-value' is not specified:
2821
2822      Scheme boolean
2823           A Scheme boolean is converted the boolean type for the current
2824           language.
2825
2826      Scheme integer
2827           A Scheme integer is converted to the first of a C 'int',
2828           'unsigned int', 'long', 'unsigned long', 'long long' or
2829           'unsigned long long' type for the current architecture that
2830           can represent the value.
2831
2832           If the Scheme integer cannot be represented as a target
2833           integer an 'out-of-range' exception is thrown.
2834
2835      Scheme real
2836           A Scheme real is converted to the C 'double' type for the
2837           current architecture.
2838
2839      Scheme string
2840           A Scheme string is converted to a string in the current target
2841           language using the current target encoding.  Characters that
2842           cannot be represented in the current target encoding are
2843           replaced with the corresponding escape sequence.  This is
2844           Guile's 'SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE' conversion
2845           strategy (*note (guile)Strings::).
2846
2847           Passing TYPE is not supported in this case, if it is provided
2848           a 'wrong-type-arg' exception is thrown.
2849
2850      '<gdb:lazy-string>'
2851           If VALUE is a '<gdb:lazy-string>' object (*note Lazy Strings
2852           In Guile::), then the 'lazy-string->value' procedure is
2853           called, and its result is used.
2854
2855           Passing TYPE is not supported in this case, if it is provided
2856           a 'wrong-type-arg' exception is thrown.
2857
2858      Scheme bytevector
2859           If VALUE is a Scheme bytevector and TYPE is provided, VALUE
2860           must be the same size, in bytes, of values of type TYPE, and
2861           the result is essentially created by using 'memcpy'.
2862
2863           If VALUE is a Scheme bytevector and TYPE is not provided, the
2864           result is an array of type 'uint8' of the same length.
2865
2866  -- Scheme Procedure: value-optimized-out? value
2867      Return '#t' if the compiler optimized out VALUE, thus it is not
2868      available for fetching from the inferior.  Otherwise return '#f'.
2869
2870  -- Scheme Procedure: value-address value
2871      If VALUE is addressable, returns a '<gdb:value>' object
2872      representing the address.  Otherwise, '#f' is returned.
2873
2874  -- Scheme Procedure: value-type value
2875      Return the type of VALUE as a '<gdb:type>' object (*note Types In
2876      Guile::).
2877
2878  -- Scheme Procedure: value-dynamic-type value
2879      Return the dynamic type of VALUE.  This uses C++ run-time type
2880      information (RTTI) to determine the dynamic type of the value.  If
2881      the value is of class type, it will return the class in which the
2882      value is embedded, if any.  If the value is of pointer or reference
2883      to a class type, it will compute the dynamic type of the referenced
2884      object, and return a pointer or reference to that type,
2885      respectively.  In all other cases, it will return the value's
2886      static type.
2887
2888      Note that this feature will only work when debugging a C++ program
2889      that includes RTTI for the object in question.  Otherwise, it will
2890      just return the static type of the value as in 'ptype foo'.  *Note
2891      ptype: Symbols.
2892
2893  -- Scheme Procedure: value-cast value type
2894      Return a new instance of '<gdb:value>' that is the result of
2895      casting VALUE to the type described by TYPE, which must be a
2896      '<gdb:type>' object.  If the cast cannot be performed for some
2897      reason, this method throws an exception.
2898
2899  -- Scheme Procedure: value-dynamic-cast value type
2900      Like 'value-cast', but works as if the C++ 'dynamic_cast' operator
2901      were used.  Consult a C++ reference for details.
2902
2903  -- Scheme Procedure: value-reinterpret-cast value type
2904      Like 'value-cast', but works as if the C++ 'reinterpret_cast'
2905      operator were used.  Consult a C++ reference for details.
2906
2907  -- Scheme Procedure: value-dereference value
2908      For pointer data types, this method returns a new '<gdb:value>'
2909      object whose contents is the object pointed to by VALUE.  For
2910      example, if 'foo' is a C pointer to an 'int', declared in your C
2911      program as
2912
2913           int *foo;
2914
2915      then you can use the corresponding '<gdb:value>' to access what
2916      'foo' points to like this:
2917
2918           (define bar (value-dereference foo))
2919
2920      The result 'bar' will be a '<gdb:value>' object holding the value
2921      pointed to by 'foo'.
2922
2923      A similar function 'value-referenced-value' exists which also
2924      returns '<gdb:value>' objects corresonding to the values pointed to
2925      by pointer values (and additionally, values referenced by reference
2926      values).  However, the behavior of 'value-dereference' differs from
2927      'value-referenced-value' by the fact that the behavior of
2928      'value-dereference' is identical to applying the C unary operator
2929      '*' on a given value.  For example, consider a reference to a
2930      pointer 'ptrref', declared in your C++ program as
2931
2932           typedef int *intptr;
2933           ...
2934           int val = 10;
2935           intptr ptr = &val;
2936           intptr &ptrref = ptr;
2937
2938      Though 'ptrref' is a reference value, one can apply the method
2939      'value-dereference' to the '<gdb:value>' object corresponding to it
2940      and obtain a '<gdb:value>' which is identical to that corresponding
2941      to 'val'.  However, if you apply the method
2942      'value-referenced-value', the result would be a '<gdb:value>'
2943      object identical to that corresponding to 'ptr'.
2944
2945           (define scm-ptrref (parse-and-eval "ptrref"))
2946           (define scm-val (value-dereference scm-ptrref))
2947           (define scm-ptr (value-referenced-value scm-ptrref))
2948
2949      The '<gdb:value>' object 'scm-val' is identical to that
2950      corresponding to 'val', and 'scm-ptr' is identical to that
2951      corresponding to 'ptr'.  In general, 'value-dereference' can be
2952      applied whenever the C unary operator '*' can be applied to the
2953      corresponding C value.  For those cases where applying both
2954      'value-dereference' and 'value-referenced-value' is allowed, the
2955      results obtained need not be identical (as we have seen in the
2956      above example).  The results are however identical when applied on
2957      '<gdb:value>' objects corresponding to pointers ('<gdb:value>'
2958      objects with type code 'TYPE_CODE_PTR') in a C/C++ program.
2959
2960  -- Scheme Procedure: value-referenced-value value
2961      For pointer or reference data types, this method returns a new
2962      '<gdb:value>' object corresponding to the value referenced by the
2963      pointer/reference value.  For pointer data types,
2964      'value-dereference' and 'value-referenced-value' produce identical
2965      results.  The difference between these methods is that
2966      'value-dereference' cannot get the values referenced by reference
2967      values.  For example, consider a reference to an 'int', declared in
2968      your C++ program as
2969
2970           int val = 10;
2971           int &ref = val;
2972
2973      then applying 'value-dereference' to the '<gdb:value>' object
2974      corresponding to 'ref' will result in an error, while applying
2975      'value-referenced-value' will result in a '<gdb:value>' object
2976      identical to that corresponding to 'val'.
2977
2978           (define scm-ref (parse-and-eval "ref"))
2979           (define err-ref (value-dereference scm-ref))      ;; error
2980           (define scm-val (value-referenced-value scm-ref)) ;; ok
2981
2982      The '<gdb:value>' object 'scm-val' is identical to that
2983      corresponding to 'val'.
2984
2985  -- Scheme Procedure: value-field value field-name
2986      Return field FIELD-NAME from '<gdb:value>' object VALUE.
2987
2988  -- Scheme Procedure: value-subscript value index
2989      Return the value of array VALUE at index INDEX.  The VALUE argument
2990      must be a subscriptable '<gdb:value>' object.
2991
2992  -- Scheme Procedure: value-call value arg-list
2993      Perform an inferior function call, taking VALUE as a pointer to the
2994      function to call.  Each element of list ARG-LIST must be a
2995      <gdb:value> object or an object that can be converted to a value.
2996      The result is the value returned by the function.
2997
2998  -- Scheme Procedure: value->bool value
2999      Return the Scheme boolean representing '<gdb:value>' VALUE.  The
3000      value must be "integer like".  Pointers are ok.
3001
3002  -- Scheme Procedure: value->integer
3003      Return the Scheme integer representing '<gdb:value>' VALUE.  The
3004      value must be "integer like".  Pointers are ok.
3005
3006  -- Scheme Procedure: value->real
3007      Return the Scheme real number representing '<gdb:value>' VALUE.
3008      The value must be a number.
3009
3010  -- Scheme Procedure: value->bytevector
3011      Return a Scheme bytevector with the raw contents of '<gdb:value>'
3012      VALUE.  No transformation, endian or otherwise, is performed.
3013
3014  -- Scheme Procedure: value->string value [#:encoding encoding]
3015           [#:errors errors] [#:length length]
3016      If VALUE> represents a string, then this method converts the
3017      contents to a Guile string.  Otherwise, this method will throw an
3018      exception.
3019
3020      Values are interpreted as strings according to the rules of the
3021      current language.  If the optional length argument is given, the
3022      string will be converted to that length, and will include any
3023      embedded zeroes that the string may contain.  Otherwise, for
3024      languages where the string is zero-terminated, the entire string
3025      will be converted.
3026
3027      For example, in C-like languages, a value is a string if it is a
3028      pointer to or an array of characters or ints of type 'wchar_t',
3029      'char16_t', or 'char32_t'.
3030
3031      If the optional ENCODING argument is given, it must be a string
3032      naming the encoding of the string in the '<gdb:value>', such as
3033      '"ascii"', '"iso-8859-6"' or '"utf-8"'.  It accepts the same
3034      encodings as the corresponding argument to Guile's
3035      'scm_from_stringn' function, and the Guile codec machinery will be
3036      used to convert the string.  If ENCODING is not given, or if
3037      ENCODING is the empty string, then either the 'target-charset'
3038      (*note Character Sets::) will be used, or a language-specific
3039      encoding will be used, if the current language is able to supply
3040      one.
3041
3042      The optional ERRORS argument is one of '#f', 'error' or
3043      'substitute'.  'error' and 'substitute' must be symbols.  If ERRORS
3044      is not specified, or if its value is '#f', then the default
3045      conversion strategy is used, which is set with the Scheme function
3046      'set-port-conversion-strategy!'.  If the value is ''error' then an
3047      exception is thrown if there is any conversion error.  If the value
3048      is ''substitute' then any conversion error is replaced with
3049      question marks.  *Note (guile)Strings::.
3050
3051      If the optional LENGTH argument is given, the string will be
3052      fetched and converted to the given length.  The length must be a
3053      Scheme integer and not a '<gdb:value>' integer.
3054
3055  -- Scheme Procedure: value->lazy-string value [#:encoding encoding]
3056           [#:length length]
3057      If this '<gdb:value>' represents a string, then this method
3058      converts VALUE to a '<gdb:lazy-string' (*note Lazy Strings In
3059      Guile::).  Otherwise, this method will throw an exception.
3060
3061      If the optional ENCODING argument is given, it must be a string
3062      naming the encoding of the '<gdb:lazy-string'.  Some examples are:
3063      '"ascii"', '"iso-8859-6"' or '"utf-8"'.  If the ENCODING argument
3064      is an encoding that GDB does not recognize, GDB will raise an
3065      error.
3066
3067      When a lazy string is printed, the GDB encoding machinery is used
3068      to convert the string during printing.  If the optional ENCODING
3069      argument is not provided, or is an empty string, GDB will
3070      automatically select the encoding most suitable for the string
3071      type.  For further information on encoding in GDB please see *note
3072      Character Sets::.
3073
3074      If the optional LENGTH argument is given, the string will be
3075      fetched and encoded to the length of characters specified.  If the
3076      LENGTH argument is not provided, the string will be fetched and
3077      encoded until a null of appropriate width is found.  The length
3078      must be a Scheme integer and not a '<gdb:value>' integer.
3079
3080  -- Scheme Procedure: value-lazy? value
3081      Return '#t' if VALUE has not yet been fetched from the inferior.
3082      Otherwise return '#f'.  GDB does not fetch values until necessary,
3083      for efficiency.  For example:
3084
3085           (define myval (parse-and-eval "somevar"))
3086
3087      The value of 'somevar' is not fetched at this time.  It will be
3088      fetched when the value is needed, or when the 'fetch-lazy'
3089      procedure is invoked.
3090
3091  -- Scheme Procedure: make-lazy-value type address
3092      Return a '<gdb:value>' that will be lazily fetched from the target.
3093      The object of type '<gdb:type>' whose value to fetch is specified
3094      by its TYPE and its target memory ADDRESS, which is a Scheme
3095      integer.
3096
3097  -- Scheme Procedure: value-fetch-lazy! value
3098      If VALUE is a lazy value ('(value-lazy? value)' is '#t'), then the
3099      value is fetched from the inferior.  Any errors that occur in the
3100      process will produce a Guile exception.
3101
3102      If VALUE is not a lazy value, this method has no effect.
3103
3104      The result of this function is unspecified.
3105
3106  -- Scheme Procedure: value-print value
3107      Return the string representation (print form) of '<gdb:value>'
3108      VALUE.
3109
3110 \1f
3111 File: gdb.info,  Node: Arithmetic In Guile,  Next: Types In Guile,  Prev: Values From Inferior In Guile,  Up: Guile API
3112
3113 23.3.3.6 Arithmetic In Guile
3114 ............................
3115
3116 The '(gdb)' module provides several functions for performing arithmetic
3117 on '<gdb:value>' objects.  The arithmetic is performed as if it were
3118 done by the target, and therefore has target semantics which are not
3119 necessarily those of Scheme.  For example operations work with a fixed
3120 precision, not the arbitrary precision of Scheme.
3121
3122    Wherever a function takes an integer or pointer as an operand, GDB
3123 will convert appropriate Scheme values to perform the operation.
3124
3125  -- Scheme Procedure: value-add a b
3126
3127  -- Scheme Procedure: value-sub a b
3128
3129  -- Scheme Procedure: value-mul a b
3130
3131  -- Scheme Procedure: value-div a b
3132
3133  -- Scheme Procedure: value-rem a b
3134
3135  -- Scheme Procedure: value-mod a b
3136
3137  -- Scheme Procedure: value-pow a b
3138
3139  -- Scheme Procedure: value-not a
3140
3141  -- Scheme Procedure: value-neg a
3142
3143  -- Scheme Procedure: value-pos a
3144
3145  -- Scheme Procedure: value-abs a
3146
3147  -- Scheme Procedure: value-lsh a b
3148
3149  -- Scheme Procedure: value-rsh a b
3150
3151  -- Scheme Procedure: value-min a b
3152
3153  -- Scheme Procedure: value-max a b
3154
3155  -- Scheme Procedure: value-lognot a
3156
3157  -- Scheme Procedure: value-logand a b
3158
3159  -- Scheme Procedure: value-logior a b
3160
3161  -- Scheme Procedure: value-logxor a b
3162
3163  -- Scheme Procedure: value=? a b
3164
3165  -- Scheme Procedure: value<? a b
3166
3167  -- Scheme Procedure: value<=? a b
3168
3169  -- Scheme Procedure: value>? a b
3170
3171  -- Scheme Procedure: value>=? a b
3172
3173    Scheme does not provide a 'not-equal' function, and thus Guile
3174 support in GDB does not either.
3175
3176 \1f
3177 File: gdb.info,  Node: Types In Guile,  Next: Guile Pretty Printing API,  Prev: Arithmetic In Guile,  Up: Guile API
3178
3179 23.3.3.7 Types In Guile
3180 .......................
3181
3182 GDB represents types from the inferior in objects of type '<gdb:type>'.
3183
3184    The following type-related procedures are provided by the '(gdb)'
3185 module.
3186
3187  -- Scheme Procedure: type? object
3188      Return '#t' if OBJECT is an object of type '<gdb:type>'.  Otherwise
3189      return '#f'.
3190
3191  -- Scheme Procedure: lookup-type name [#:block block]
3192      This function looks up a type by its NAME, which must be a string.
3193
3194      If BLOCK is given, it is an object of type '<gdb:block>', and NAME
3195      is looked up in that scope.  Otherwise, it is searched for
3196      globally.
3197
3198      Ordinarily, this function will return an instance of '<gdb:type>'.
3199      If the named type cannot be found, it will throw an exception.
3200
3201  -- Scheme Procedure: type-code type
3202      Return the type code of TYPE.  The type code will be one of the
3203      'TYPE_CODE_' constants defined below.
3204
3205  -- Scheme Procedure: type-tag type
3206      Return the tag name of TYPE.  The tag name is the name after
3207      'struct', 'union', or 'enum' in C and C++; not all languages have
3208      this concept.  If this type has no tag name, then '#f' is returned.
3209
3210  -- Scheme Procedure: type-name type
3211      Return the name of TYPE.  If this type has no name, then '#f' is
3212      returned.
3213
3214  -- Scheme Procedure: type-print-name type
3215      Return the print name of TYPE.  This returns something even for
3216      anonymous types.  For example, for an anonymous C struct '"struct
3217      {...}"' is returned.
3218
3219  -- Scheme Procedure: type-sizeof type
3220      Return the size of this type, in target 'char' units.  Usually, a
3221      target's 'char' type will be an 8-bit byte.  However, on some
3222      unusual platforms, this type may have a different size.
3223
3224  -- Scheme Procedure: type-strip-typedefs type
3225      Return a new '<gdb:type>' that represents the real type of TYPE,
3226      after removing all layers of typedefs.
3227
3228  -- Scheme Procedure: type-array type n1 [n2]
3229      Return a new '<gdb:type>' object which represents an array of this
3230      type.  If one argument is given, it is the inclusive upper bound of
3231      the array; in this case the lower bound is zero.  If two arguments
3232      are given, the first argument is the lower bound of the array, and
3233      the second argument is the upper bound of the array.  An array's
3234      length must not be negative, but the bounds can be.
3235
3236  -- Scheme Procedure: type-vector type n1 [n2]
3237      Return a new '<gdb:type>' object which represents a vector of this
3238      type.  If one argument is given, it is the inclusive upper bound of
3239      the vector; in this case the lower bound is zero.  If two arguments
3240      are given, the first argument is the lower bound of the vector, and
3241      the second argument is the upper bound of the vector.  A vector's
3242      length must not be negative, but the bounds can be.
3243
3244      The difference between an 'array' and a 'vector' is that arrays
3245      behave like in C: when used in expressions they decay to a pointer
3246      to the first element whereas vectors are treated as first class
3247      values.
3248
3249  -- Scheme Procedure: type-pointer type
3250      Return a new '<gdb:type>' object which represents a pointer to
3251      TYPE.
3252
3253  -- Scheme Procedure: type-range type
3254      Return a list of two elements: the low bound and high bound of
3255      TYPE.  If TYPE does not have a range, an exception is thrown.
3256
3257  -- Scheme Procedure: type-reference type
3258      Return a new '<gdb:type>' object which represents a reference to
3259      TYPE.
3260
3261  -- Scheme Procedure: type-target type
3262      Return a new '<gdb:type>' object which represents the target type
3263      of TYPE.
3264
3265      For a pointer type, the target type is the type of the pointed-to
3266      object.  For an array type (meaning C-like arrays), the target type
3267      is the type of the elements of the array.  For a function or method
3268      type, the target type is the type of the return value.  For a
3269      complex type, the target type is the type of the elements.  For a
3270      typedef, the target type is the aliased type.
3271
3272      If the type does not have a target, this method will throw an
3273      exception.
3274
3275  -- Scheme Procedure: type-const type
3276      Return a new '<gdb:type>' object which represents a
3277      'const'-qualified variant of TYPE.
3278
3279  -- Scheme Procedure: type-volatile type
3280      Return a new '<gdb:type>' object which represents a
3281      'volatile'-qualified variant of TYPE.
3282
3283  -- Scheme Procedure: type-unqualified type
3284      Return a new '<gdb:type>' object which represents an unqualified
3285      variant of TYPE.  That is, the result is neither 'const' nor
3286      'volatile'.
3287
3288  -- Scheme Procedure: type-num-fields
3289      Return the number of fields of '<gdb:type>' TYPE.
3290
3291  -- Scheme Procedure: type-fields type
3292      Return the fields of TYPE as a list.  For structure and union
3293      types, 'fields' has the usual meaning.  Range types have two
3294      fields, the minimum and maximum values.  Enum types have one field
3295      per enum constant.  Function and method types have one field per
3296      parameter.  The base types of C++ classes are also represented as
3297      fields.  If the type has no fields, or does not fit into one of
3298      these categories, an empty list will be returned.  *Note Fields of
3299      a type in Guile::.
3300
3301  -- Scheme Procedure: make-field-iterator type
3302      Return the fields of TYPE as a <gdb:iterator> object.  *Note
3303      Iterators In Guile::.
3304
3305  -- Scheme Procedure: type-field type field-name
3306      Return field named FIELD-NAME in TYPE.  The result is an object of
3307      type '<gdb:field>'.  *Note Fields of a type in Guile::.  If the
3308      type does not have fields, or FIELD-NAME is not a field of TYPE, an
3309      exception is thrown.
3310
3311      For example, if 'some-type' is a '<gdb:type>' instance holding a
3312      structure type, you can access its 'foo' field with:
3313
3314           (define bar (type-field some-type "foo"))
3315
3316      'bar' will be a '<gdb:field>' object.
3317
3318  -- Scheme Procedure: type-has-field? type name
3319      Return '#t' if '<gdb:type>' TYPE has field named NAME.  Otherwise
3320      return '#f'.
3321
3322    Each type has a code, which indicates what category this type falls
3323 into.  The available type categories are represented by constants
3324 defined in the '(gdb)' module:
3325
3326 'TYPE_CODE_PTR'
3327      The type is a pointer.
3328
3329 'TYPE_CODE_ARRAY'
3330      The type is an array.
3331
3332 'TYPE_CODE_STRUCT'
3333      The type is a structure.
3334
3335 'TYPE_CODE_UNION'
3336      The type is a union.
3337
3338 'TYPE_CODE_ENUM'
3339      The type is an enum.
3340
3341 'TYPE_CODE_FLAGS'
3342      A bit flags type, used for things such as status registers.
3343
3344 'TYPE_CODE_FUNC'
3345      The type is a function.
3346
3347 'TYPE_CODE_INT'
3348      The type is an integer type.
3349
3350 'TYPE_CODE_FLT'
3351      A floating point type.
3352
3353 'TYPE_CODE_VOID'
3354      The special type 'void'.
3355
3356 'TYPE_CODE_SET'
3357      A Pascal set type.
3358
3359 'TYPE_CODE_RANGE'
3360      A range type, that is, an integer type with bounds.
3361
3362 'TYPE_CODE_STRING'
3363      A string type.  Note that this is only used for certain languages
3364      with language-defined string types; C strings are not represented
3365      this way.
3366
3367 'TYPE_CODE_BITSTRING'
3368      A string of bits.  It is deprecated.
3369
3370 'TYPE_CODE_ERROR'
3371      An unknown or erroneous type.
3372
3373 'TYPE_CODE_METHOD'
3374      A method type, as found in C++ or Java.
3375
3376 'TYPE_CODE_METHODPTR'
3377      A pointer-to-member-function.
3378
3379 'TYPE_CODE_MEMBERPTR'
3380      A pointer-to-member.
3381
3382 'TYPE_CODE_REF'
3383      A reference type.
3384
3385 'TYPE_CODE_CHAR'
3386      A character type.
3387
3388 'TYPE_CODE_BOOL'
3389      A boolean type.
3390
3391 'TYPE_CODE_COMPLEX'
3392      A complex float type.
3393
3394 'TYPE_CODE_TYPEDEF'
3395      A typedef to some other type.
3396
3397 'TYPE_CODE_NAMESPACE'
3398      A C++ namespace.
3399
3400 'TYPE_CODE_DECFLOAT'
3401      A decimal floating point type.
3402
3403 'TYPE_CODE_INTERNAL_FUNCTION'
3404      A function internal to GDB.  This is the type used to represent
3405      convenience functions (*note Convenience Funs::).
3406
3407    Further support for types is provided in the '(gdb types)' Guile
3408 module (*note Guile Types Module::).
3409
3410    Each field is represented as an object of type '<gdb:field>'.
3411
3412    The following field-related procedures are provided by the '(gdb)'
3413 module:
3414
3415  -- Scheme Procedure: field? object
3416      Return '#t' if OBJECT is an object of type '<gdb:field>'.
3417      Otherwise return '#f'.
3418
3419  -- Scheme Procedure: field-name field
3420      Return the name of the field, or '#f' for anonymous fields.
3421
3422  -- Scheme Procedure: field-type field
3423      Return the type of the field.  This is usually an instance of
3424      '<gdb:type>', but it can be '#f' in some situations.
3425
3426  -- Scheme Procedure: field-enumval field
3427      Return the enum value represented by '<gdb:field>' FIELD.
3428
3429  -- Scheme Procedure: field-bitpos field
3430      Return the bit position of '<gdb:field>' FIELD.  This attribute is
3431      not available for 'static' fields (as in C++ or Java).
3432
3433  -- Scheme Procedure: field-bitsize field
3434      If the field is packed, or is a bitfield, return the size of
3435      '<gdb:field>' FIELD in bits.  Otherwise, zero is returned; in which
3436      case the field's size is given by its type.
3437
3438  -- Scheme Procedure: field-artificial? field
3439      Return '#t' if the field is artificial, usually meaning that it was
3440      provided by the compiler and not the user.  Otherwise return '#f'.
3441
3442  -- Scheme Procedure: field-base-class? field
3443      Return '#t' if the field represents a base class of a C++
3444      structure.  Otherwise return '#f'.
3445
3446 \1f
3447 File: gdb.info,  Node: Guile Pretty Printing API,  Next: Selecting Guile Pretty-Printers,  Prev: Types In Guile,  Up: Guile API
3448
3449 23.3.3.8 Guile Pretty Printing API
3450 ..................................
3451
3452 An example output is provided (*note Pretty Printing::).
3453
3454    A pretty-printer is represented by an object of type
3455 <gdb:pretty-printer>.  Pretty-printer objects are created with
3456 'make-pretty-printer'.
3457
3458    The following pretty-printer-related procedures are provided by the
3459 '(gdb)' module:
3460
3461  -- Scheme Procedure: make-pretty-printer name lookup-function
3462      Return a '<gdb:pretty-printer>' object named NAME.
3463
3464      LOOKUP-FUNCTION is a function of one parameter: the value to be
3465      printed.  If the value is handled by this pretty-printer, then
3466      LOOKUP-FUNCTION returns an object of type
3467      <gdb:pretty-printer-worker> to perform the actual pretty-printing.
3468      Otherwise LOOKUP-FUNCTION returns '#f'.
3469
3470  -- Scheme Procedure: pretty-printer? object
3471      Return '#t' if OBJECT is a '<gdb:pretty-printer>' object.
3472      Otherwise return '#f'.
3473
3474  -- Scheme Procedure: pretty-printer-enabled? pretty-printer
3475      Return '#t' if PRETTY-PRINTER is enabled.  Otherwise return '#f'.
3476
3477  -- Scheme Procedure: set-pretty-printer-enabled! pretty-printer flag
3478      Set the enabled flag of PRETTY-PRINTER to FLAG.  The value returned
3479      is unspecified.
3480
3481  -- Scheme Procedure: pretty-printers
3482      Return the list of global pretty-printers.
3483
3484  -- Scheme Procedure: set-pretty-printers! pretty-printers
3485      Set the list of global pretty-printers to PRETTY-PRINTERS.  The
3486      value returned is unspecified.
3487
3488  -- Scheme Procedure: make-pretty-printer-worker display-hint to-string
3489           children
3490      Return an object of type '<gdb:pretty-printer-worker>'.
3491
3492      This function takes three parameters:
3493
3494      'display-hint'
3495           DISPLAY-HINT provides a hint to GDB or GDB front end via MI to
3496           change the formatting of the value being printed.  The value
3497           must be a string or '#f' (meaning there is no hint).  Several
3498           values for DISPLAY-HINT are predefined by GDB:
3499
3500           'array'
3501                Indicate that the object being printed is "array-like".
3502                The CLI uses this to respect parameters such as 'set
3503                print elements' and 'set print array'.
3504
3505           'map'
3506                Indicate that the object being printed is "map-like", and
3507                that the children of this value can be assumed to
3508                alternate between keys and values.
3509
3510           'string'
3511                Indicate that the object being printed is "string-like".
3512                If the printer's 'to-string' function returns a Guile
3513                string of some kind, then GDB will call its internal
3514                language-specific string-printing function to format the
3515                string.  For the CLI this means adding quotation marks,
3516                possibly escaping some characters, respecting 'set print
3517                elements', and the like.
3518
3519      'to-string'
3520           TO-STRING is either a function of one parameter, the
3521           '<gdb:pretty-printer-worker>' object, or '#f'.
3522
3523           When printing from the CLI, if the 'to-string' method exists,
3524           then GDB will prepend its result to the values returned by
3525           'children'.  Exactly how this formatting is done is dependent
3526           on the display hint, and may change as more hints are added.
3527           Also, depending on the print settings (*note Print
3528           Settings::), the CLI may print just the result of 'to-string'
3529           in a stack trace, omitting the result of 'children'.
3530
3531           If this method returns a string, it is printed verbatim.
3532
3533           Otherwise, if this method returns an instance of
3534           '<gdb:value>', then GDB prints this value.  This may result in
3535           a call to another pretty-printer.
3536
3537           If instead the method returns a Guile value which is
3538           convertible to a '<gdb:value>', then GDB performs the
3539           conversion and prints the resulting value.  Again, this may
3540           result in a call to another pretty-printer.  Guile scalars
3541           (integers, floats, and booleans) and strings are convertible
3542           to '<gdb:value>'; other types are not.
3543
3544           Finally, if this method returns '#f' then no further
3545           operations are peformed in this method and nothing is printed.
3546
3547           If the result is not one of these types, an exception is
3548           raised.
3549
3550           TO-STRING may also be '#f' in which case it is left to
3551           CHILDREN to print the value.
3552
3553      'children'
3554           CHILDREN is either a function of one parameter, the
3555           '<gdb:pretty-printer-worker>' object, or '#f'.
3556
3557           GDB will call this function on a pretty-printer to compute the
3558           children of the pretty-printer's value.
3559
3560           This function must return a <gdb:iterator> object.  Each item
3561           returned by the iterator must be a tuple holding two elements.
3562           The first element is the "name" of the child; the second
3563           element is the child's value.  The value can be any Guile
3564           object which is convertible to a GDB value.
3565
3566           If CHILDREN is '#f', GDB will act as though the value has no
3567           children.
3568
3569    GDB provides a function which can be used to look up the default
3570 pretty-printer for a '<gdb:value>':
3571
3572  -- Scheme Procedure: default-visualizer value
3573      This function takes a '<gdb:value>' object as an argument.  If a
3574      pretty-printer for this value exists, then it is returned.  If no
3575      such printer exists, then this returns '#f'.
3576
3577 \1f
3578 File: gdb.info,  Node: Selecting Guile Pretty-Printers,  Next: Writing a Guile Pretty-Printer,  Prev: Guile Pretty Printing API,  Up: Guile API
3579
3580 23.3.3.9 Selecting Guile Pretty-Printers
3581 ........................................
3582
3583 There are three sets of pretty-printers that GDB searches:
3584
3585    * Per-objfile list of pretty-printers (*note Objfiles In Guile::).
3586    * Per-progspace list of pretty-printers (*note Progspaces In
3587      Guile::).
3588    * The global list of pretty-printers (*note Guile Pretty Printing
3589      API::).  These printers are available when debugging any inferior.
3590
3591    Pretty-printer lookup is done by passing the value to be printed to
3592 the lookup function of each enabled object in turn.  Lookup stops when a
3593 lookup function returns a non-'#f' value or when the list is exhausted.
3594 Lookup functions must return either a '<gdb:pretty-printer-worker>'
3595 object or '#f'.  Otherwise an exception is thrown.
3596
3597    GDB first checks the result of 'objfile-pretty-printers' of each
3598 '<gdb:objfile>' in the current program space and iteratively calls each
3599 enabled lookup function in the list for that '<gdb:objfile>' until a
3600 non-'#f' object is returned.  If no pretty-printer is found in the
3601 objfile lists, GDB then searches the result of
3602 'progspace-pretty-printers' of the current program space, calling each
3603 enabled function until a non-'#f' object is returned.  After these lists
3604 have been exhausted, it tries the global pretty-printers list, obtained
3605 with 'pretty-printers', again calling each enabled function until a
3606 non-'#f' object is returned.
3607
3608    The order in which the objfiles are searched is not specified.  For a
3609 given list, functions are always invoked from the head of the list, and
3610 iterated over sequentially until the end of the list, or a
3611 '<gdb:pretty-printer-worker>' object is returned.
3612
3613    For various reasons a pretty-printer may not work.  For example, the
3614 underlying data structure may have changed and the pretty-printer is out
3615 of date.
3616
3617    The consequences of a broken pretty-printer are severe enough that
3618 GDB provides support for enabling and disabling individual printers.
3619 For example, if 'print frame-arguments' is on, a backtrace can become
3620 highly illegible if any argument is printed with a broken printer.
3621
3622    Pretty-printers are enabled and disabled from Scheme by calling
3623 'set-pretty-printer-enabled!'.  *Note Guile Pretty Printing API::.
3624
3625 \1f
3626 File: gdb.info,  Node: Writing a Guile Pretty-Printer,  Next: Commands In Guile,  Prev: Selecting Guile Pretty-Printers,  Up: Guile API
3627
3628 23.3.3.10 Writing a Guile Pretty-Printer
3629 ........................................
3630
3631 A pretty-printer consists of two basic parts: a lookup function to
3632 determine if the type is supported, and the printer itself.
3633
3634    Here is an example showing how a 'std::string' printer might be
3635 written.  *Note Guile Pretty Printing API::, for details.
3636
3637      (define (make-my-string-printer value)
3638        "Print a my::string string"
3639        (make-pretty-printer-worker
3640         "string"
3641         (lambda (printer)
3642           (value-field value "_data"))
3643         #f))
3644
3645    And here is an example showing how a lookup function for the printer
3646 example above might be written.
3647
3648      (define (str-lookup-function pretty-printer value)
3649        (let ((tag (type-tag (value-type value))))
3650          (and tag
3651               (string-prefix? "std::string<" tag)
3652               (make-my-string-printer value))))
3653
3654    Then to register this printer in the global printer list:
3655
3656      (append-pretty-printer!
3657       (make-pretty-printer "my-string" str-lookup-function))
3658
3659    The example lookup function extracts the value's type, and attempts
3660 to match it to a type that it can pretty-print.  If it is a type the
3661 printer can pretty-print, it will return a <gdb:pretty-printer-worker>
3662 object.  If not, it returns '#f'.
3663
3664    We recommend that you put your core pretty-printers into a Guile
3665 package.  If your pretty-printers are for use with a library, we further
3666 recommend embedding a version number into the package name.  This
3667 practice will enable GDB to load multiple versions of your
3668 pretty-printers at the same time, because they will have different
3669 names.
3670
3671    You should write auto-loaded code (*note Guile Auto-loading::) such
3672 that it can be evaluated multiple times without changing its meaning.
3673 An ideal auto-load file will consist solely of 'import's of your printer
3674 modules, followed by a call to a register pretty-printers with the
3675 current objfile.
3676
3677    Taken as a whole, this approach will scale nicely to multiple
3678 inferiors, each potentially using a different library version.
3679 Embedding a version number in the Guile package name will ensure that
3680 GDB is able to load both sets of printers simultaneously.  Then, because
3681 the search for pretty-printers is done by objfile, and because your
3682 auto-loaded code took care to register your library's printers with a
3683 specific objfile, GDB will find the correct printers for the specific
3684 version of the library used by each inferior.
3685
3686    To continue the 'my::string' example, this code might appear in
3687 '(my-project my-library v1)':
3688
3689      (use-modules (gdb))
3690      (define (register-printers objfile)
3691        (append-objfile-pretty-printer!
3692         (make-pretty-printer "my-string" str-lookup-function)))
3693
3694 And then the corresponding contents of the auto-load file would be:
3695
3696      (use-modules (gdb) (my-project my-library v1))
3697      (register-printers (current-objfile))
3698
3699    The previous example illustrates a basic pretty-printer.  There are a
3700 few things that can be improved on.  The printer only handles one type,
3701 whereas a library typically has several types.  One could install a
3702 lookup function for each desired type in the library, but one could also
3703 have a single lookup function recognize several types.  The latter is
3704 the conventional way this is handled.  If a pretty-printer can handle
3705 multiple data types, then its "subprinters" are the printers for the
3706 individual data types.
3707
3708    The '(gdb printing)' module provides a formal way of solving this
3709 problem (*note Guile Printing Module::).  Here is another example that
3710 handles multiple types.
3711
3712    These are the types we are going to pretty-print:
3713
3714      struct foo { int a, b; };
3715      struct bar { struct foo x, y; };
3716
3717    Here are the printers:
3718
3719      (define (make-foo-printer value)
3720        "Print a foo object"
3721        (make-pretty-printer-worker
3722         "foo"
3723         (lambda (printer)
3724           (format #f "a=<~a> b=<~a>"
3725                   (value-field value "a") (value-field value "a")))
3726         #f))
3727
3728      (define (make-bar-printer value)
3729        "Print a bar object"
3730        (make-pretty-printer-worker
3731         "foo"
3732         (lambda (printer)
3733           (format #f "x=<~a> y=<~a>"
3734                   (value-field value "x") (value-field value "y")))
3735         #f))
3736
3737    This example doesn't need a lookup function, that is handled by the
3738 '(gdb printing)' module.  Instead a function is provided to build up the
3739 object that handles the lookup.
3740
3741      (use-modules (gdb printing))
3742
3743      (define (build-pretty-printer)
3744        (let ((pp (make-pretty-printer-collection "my-library")))
3745          (pp-collection-add-tag-printer "foo" make-foo-printer)
3746          (pp-collection-add-tag-printer "bar" make-bar-printer)
3747          pp))
3748
3749    And here is the autoload support:
3750
3751      (use-modules (gdb) (my-library))
3752      (append-objfile-pretty-printer! (current-objfile) (build-pretty-printer))
3753
3754    Finally, when this printer is loaded into GDB, here is the
3755 corresponding output of 'info pretty-printer':
3756
3757      (gdb) info pretty-printer
3758      my_library.so:
3759        my-library
3760          foo
3761          bar
3762
3763 \1f
3764 File: gdb.info,  Node: Commands In Guile,  Next: Parameters In Guile,  Prev: Writing a Guile Pretty-Printer,  Up: Guile API
3765
3766 23.3.3.11 Commands In Guile
3767 ...........................
3768
3769 You can implement new GDB CLI commands in Guile.  A CLI command object
3770 is created with the 'make-command' Guile function, and added to GDB with
3771 the 'register-command!' Guile function.  This two-step approach is taken
3772 to separate out the side-effect of adding the command to GDB from
3773 'make-command'.
3774
3775    There is no support for multi-line commands, that is commands that
3776 consist of multiple lines and are terminated with 'end'.
3777
3778  -- Scheme Procedure: (make-command name [#:invoke invoke]
3779           [#:command-class command-class] [#:completer-class completer]
3780           [#:prefix? prefix] [#:doc doc-string])
3781
3782      The argument NAME is the name of the command.  If NAME consists of
3783      multiple words, then the initial words are looked for as prefix
3784      commands.  In this case, if one of the prefix commands does not
3785      exist, an exception is raised.
3786
3787      The result is the '<gdb:command>' object representing the command.
3788      The command is not usable until it has been registered with GDB
3789      with 'register-command!'.
3790
3791      The rest of the arguments are optional.
3792
3793      The argument INVOKE is a procedure of three arguments: SELF, ARGS
3794      and FROM-TTY.  The argument SELF is the '<gdb:command>' object
3795      representing the command.  The argument ARGS is a string
3796      representing the arguments passed to the command, after leading and
3797      trailing whitespace has been stripped.  The argument FROM-TTY is a
3798      boolean flag and specifies whether the command should consider
3799      itself to have been originated from the user invoking it
3800      interactively.  If this function throws an exception, it is turned
3801      into a GDB 'error' call.  Otherwise, the return value is ignored.
3802
3803      The argument COMMAND-CLASS is one of the 'COMMAND_' constants
3804      defined below.  This argument tells GDB how to categorize the new
3805      command in the help system.  The default is 'COMMAND_NONE'.
3806
3807      The argument COMPLETER is either '#f', one of the 'COMPLETE_'
3808      constants defined below, or a procedure, also defined below.  This
3809      argument tells GDB how to perform completion for this command.  If
3810      not provided or if the value is '#f', then no completion is
3811      performed on the command.
3812
3813      The argument PREFIX is a boolean flag indicating whether the new
3814      command is a prefix command; sub-commands of this command may be
3815      registered.
3816
3817      The argument DOC-STRING is help text for the new command.  If no
3818      documentation string is provided, the default value "This command
3819      is not documented."  is used.
3820
3821  -- Scheme Procedure: register-command! command
3822      Add COMMAND, a '<gdb:command>' object, to GDB's list of commands.
3823      It is an error to register a command more than once.  The result is
3824      unspecified.
3825
3826  -- Scheme Procedure: command? object
3827      Return '#t' if OBJECT is a '<gdb:command>' object.  Otherwise
3828      return '#f'.
3829
3830  -- Scheme Procedure: dont-repeat
3831      By default, a GDB command is repeated when the user enters a blank
3832      line at the command prompt.  A command can suppress this behavior
3833      by invoking the 'dont-repeat' function.  This is similar to the
3834      user command 'dont-repeat', see *note dont-repeat: Define.
3835
3836  -- Scheme Procedure: string->argv string
3837      Convert a string to a list of strings split up according to GDB's
3838      argv parsing rules.  It is recommended to use this for consistency.
3839      Arguments are separated by spaces and may be quoted.  Example:
3840
3841           scheme@(guile-user)> (string->argv "1 2\\ \\\"3 '4 \"5' \"6 '7\"")
3842           $1 = ("1" "2 \"3" "4 \"5" "6 '7")
3843
3844  -- Scheme Procedure: throw-user-error message . args
3845      Throw a 'gdb:user-error' exception.  The argument MESSAGE is the
3846      error message as a format string, like the FMT argument to the
3847      'format' Scheme function.  *Note (guile)Formatted Output::.  The
3848      argument ARGS is a list of the optional arguments of MESSAGE.
3849
3850      This is used when the command detects a user error of some kind,
3851      say a bad command argument.
3852
3853           (gdb) guile (use-modules (gdb))
3854           (gdb) guile
3855           (register-command! (make-command "test-user-error"
3856             #:command-class COMMAND_OBSCURE
3857             #:invoke (lambda (self arg from-tty)
3858               (throw-user-error "Bad argument ~a" arg))))
3859           end
3860           (gdb) test-user-error ugh
3861           ERROR: Bad argument ugh
3862
3863  -- completer: self text word
3864      If the COMPLETER option to 'make-command' is a procedure, it takes
3865      three arguments: SELF which is the '<gdb:command>' object, and TEXT
3866      and WORD which are both strings.  The argument TEXT holds the
3867      complete command line up to the cursor's location.  The argument
3868      WORD holds the last word of the command line; this is computed
3869      using a word-breaking heuristic.
3870
3871      All forms of completion are handled by this function, that is, the
3872      <TAB> and <M-?> key bindings (*note Completion::), and the
3873      'complete' command (*note complete: Help.).
3874
3875      This procedure can return several kinds of values:
3876
3877         * If the return value is a list, the contents of the list are
3878           used as the completions.  It is up to COMPLETER to ensure that
3879           the contents actually do complete the word.  An empty list is
3880           allowed, it means that there were no completions available.
3881           Only string elements of the list are used; other elements in
3882           the list are ignored.
3883
3884         * If the return value is a '<gdb:iterator>' object, it is
3885           iterated over to obtain the completions.  It is up to
3886           'completer-procedure' to ensure that the results actually do
3887           complete the word.  Only string elements of the result are
3888           used; other elements in the sequence are ignored.
3889
3890         * All other results are treated as though there were no
3891           available completions.
3892
3893    When a new command is registered, it will have been declared as a
3894 member of some general class of commands.  This is used to classify
3895 top-level commands in the on-line help system; note that prefix commands
3896 are not listed under their own category but rather that of their
3897 top-level command.  The available classifications are represented by
3898 constants defined in the 'gdb' module:
3899
3900 'COMMAND_NONE'
3901      The command does not belong to any particular class.  A command in
3902      this category will not be displayed in any of the help categories.
3903      This is the default.
3904
3905 'COMMAND_RUNNING'
3906      The command is related to running the inferior.  For example,
3907      'start', 'step', and 'continue' are in this category.  Type 'help
3908      running' at the GDB prompt to see a list of commands in this
3909      category.
3910
3911 'COMMAND_DATA'
3912      The command is related to data or variables.  For example, 'call',
3913      'find', and 'print' are in this category.  Type 'help data' at the
3914      GDB prompt to see a list of commands in this category.
3915
3916 'COMMAND_STACK'
3917      The command has to do with manipulation of the stack.  For example,
3918      'backtrace', 'frame', and 'return' are in this category.  Type
3919      'help stack' at the GDB prompt to see a list of commands in this
3920      category.
3921
3922 'COMMAND_FILES'
3923      This class is used for file-related commands.  For example, 'file',
3924      'list' and 'section' are in this category.  Type 'help files' at
3925      the GDB prompt to see a list of commands in this category.
3926
3927 'COMMAND_SUPPORT'
3928      This should be used for "support facilities", generally meaning
3929      things that are useful to the user when interacting with GDB, but
3930      not related to the state of the inferior.  For example, 'help',
3931      'make', and 'shell' are in this category.  Type 'help support' at
3932      the GDB prompt to see a list of commands in this category.
3933
3934 'COMMAND_STATUS'
3935      The command is an 'info'-related command, that is, related to the
3936      state of GDB itself.  For example, 'info', 'macro', and 'show' are
3937      in this category.  Type 'help status' at the GDB prompt to see a
3938      list of commands in this category.
3939
3940 'COMMAND_BREAKPOINTS'
3941      The command has to do with breakpoints.  For example, 'break',
3942      'clear', and 'delete' are in this category.  Type 'help
3943      breakpoints' at the GDB prompt to see a list of commands in this
3944      category.
3945
3946 'COMMAND_TRACEPOINTS'
3947      The command has to do with tracepoints.  For example, 'trace',
3948      'actions', and 'tfind' are in this category.  Type 'help
3949      tracepoints' at the GDB prompt to see a list of commands in this
3950      category.
3951
3952 'COMMAND_USER'
3953      The command is a general purpose command for the user, and
3954      typically does not fit in one of the other categories.  Type 'help
3955      user-defined' at the GDB prompt to see a list of commands in this
3956      category, as well as the list of gdb macros (*note Sequences::).
3957
3958 'COMMAND_OBSCURE'
3959      The command is only used in unusual circumstances, or is not of
3960      general interest to users.  For example, 'checkpoint', 'fork', and
3961      'stop' are in this category.  Type 'help obscure' at the GDB prompt
3962      to see a list of commands in this category.
3963
3964 'COMMAND_MAINTENANCE'
3965      The command is only useful to GDB maintainers.  The 'maintenance'
3966      and 'flushregs' commands are in this category.  Type 'help
3967      internals' at the GDB prompt to see a list of commands in this
3968      category.
3969
3970    A new command can use a predefined completion function, either by
3971 specifying it via an argument at initialization, or by returning it from
3972 the 'completer' procedure.  These predefined completion constants are
3973 all defined in the 'gdb' module:
3974
3975 'COMPLETE_NONE'
3976      This constant means that no completion should be done.
3977
3978 'COMPLETE_FILENAME'
3979      This constant means that filename completion should be performed.
3980
3981 'COMPLETE_LOCATION'
3982      This constant means that location completion should be done.  *Note
3983      Specify Location::.
3984
3985 'COMPLETE_COMMAND'
3986      This constant means that completion should examine GDB command
3987      names.
3988
3989 'COMPLETE_SYMBOL'
3990      This constant means that completion should be done using symbol
3991      names as the source.
3992
3993 'COMPLETE_EXPRESSION'
3994      This constant means that completion should be done on expressions.
3995      Often this means completing on symbol names, but some language
3996      parsers also have support for completing on field names.
3997
3998    The following code snippet shows how a trivial CLI command can be
3999 implemented in Guile:
4000
4001      (gdb) guile
4002      (register-command! (make-command "hello-world"
4003        #:command-class COMMAND_USER
4004        #:doc "Greet the whole world."
4005        #:invoke (lambda (self args from-tty) (display "Hello, World!\n"))))
4006      end
4007      (gdb) hello-world
4008      Hello, World!
4009
4010 \1f
4011 File: gdb.info,  Node: Parameters In Guile,  Next: Progspaces In Guile,  Prev: Commands In Guile,  Up: Guile API
4012
4013 23.3.3.12 Parameters In Guile
4014 .............................
4015
4016 You can implement new GDB "parameters" using Guile (1).
4017
4018    There are many parameters that already exist and can be set in GDB.
4019 Two examples are: 'set follow-fork' and 'set charset'.  Setting these
4020 parameters influences certain behavior in GDB.  Similarly, you can
4021 define parameters that can be used to influence behavior in custom Guile
4022 scripts and commands.
4023
4024    A new parameter is defined with the 'make-parameter' Guile function,
4025 and added to GDB with the 'register-parameter!' Guile function.  This
4026 two-step approach is taken to separate out the side-effect of adding the
4027 parameter to GDB from 'make-parameter'.
4028
4029    Parameters are exposed to the user via the 'set' and 'show' commands.
4030 *Note Help::.
4031
4032  -- Scheme Procedure: (make-parameter name [#:command-class
4033           command-class] [#:parameter-type parameter-type] [#:enum-list
4034           enum-list] [#:set-func set-func] [#:show-func show-func]
4035           [#:doc doc] [#:set-doc set-doc] [#:show-doc show-doc]
4036           [#:initial-value initial-value])
4037
4038      The argument NAME is the name of the new parameter.  If NAME
4039      consists of multiple words, then the initial words are looked for
4040      as prefix parameters.  An example of this can be illustrated with
4041      the 'set print' set of parameters.  If NAME is 'print foo', then
4042      'print' will be searched as the prefix parameter.  In this case the
4043      parameter can subsequently be accessed in GDB as 'set print foo'.
4044      If NAME consists of multiple words, and no prefix parameter group
4045      can be found, an exception is raised.
4046
4047      The result is the '<gdb:parameter>' object representing the
4048      parameter.  The parameter is not usable until it has been
4049      registered with GDB with 'register-parameter!'.
4050
4051      The rest of the arguments are optional.
4052
4053      The argument COMMAND-CLASS should be one of the 'COMMAND_'
4054      constants (*note Commands In Guile::).  This argument tells GDB how
4055      to categorize the new parameter in the help system.  The default is
4056      'COMMAND_NONE'.
4057
4058      The argument PARAMETER-TYPE should be one of the 'PARAM_' constants
4059      defined below.  This argument tells GDB the type of the new
4060      parameter; this information is used for input validation and
4061      completion.  The default is 'PARAM_BOOLEAN'.
4062
4063      If PARAMETER-TYPE is 'PARAM_ENUM', then ENUM-LIST must be a list of
4064      strings.  These strings represent the possible values for the
4065      parameter.
4066
4067      If PARAMETER-TYPE is not 'PARAM_ENUM', then the presence of
4068      ENUM-LIST will cause an exception to be thrown.
4069
4070      The argument SET-FUNC is a function of one argument: SELF which is
4071      the '<gdb:parameter>' object representing the parameter.  GDB will
4072      call this function when a PARAMETER's value has been changed via
4073      the 'set' API (for example, 'set foo off').  The value of the
4074      parameter has already been set to the new value.  This function
4075      must return a string to be displayed to the user.  GDB will add a
4076      trailing newline if the string is non-empty.  GDB generally doesn't
4077      print anything when a parameter is set, thus typically this
4078      function should return '""'.  A non-empty string result should
4079      typically be used for displaying warnings and errors.
4080
4081      The argument SHOW-FUNC is a function of two arguments: SELF which
4082      is the '<gdb:parameter>' object representing the parameter, and
4083      SVALUE which is the string representation of the current value.
4084      GDB will call this function when a PARAMETER's 'show' API has been
4085      invoked (for example, 'show foo').  This function must return a
4086      string, and will be displayed to the user.  GDB will add a trailing
4087      newline.
4088
4089      The argument DOC is the help text for the new parameter.  If there
4090      is no documentation string, a default value is used.
4091
4092      The argument SET-DOC is the help text for this parameter's 'set'
4093      command.
4094
4095      The argument SHOW-DOC is the help text for this parameter's 'show'
4096      command.
4097
4098      The argument INITIAL-VALUE specifies the initial value of the
4099      parameter.  If it is a function, it takes one parameter, the
4100      '<gdb:parameter>' object and its result is used as the initial
4101      value of the parameter.  The initial value must be valid for the
4102      parameter type, otherwise an exception is thrown.
4103
4104  -- Scheme Procedure: register-parameter! parameter
4105      Add PARAMETER, a '<gdb:parameter>' object, to GDB's list of
4106      parameters.  It is an error to register a parameter more than once.
4107      The result is unspecified.
4108
4109  -- Scheme Procedure: parameter? object
4110      Return '#t' if OBJECT is a '<gdb:parameter>' object.  Otherwise
4111      return '#f'.
4112
4113  -- Scheme Procedure: parameter-value parameter
4114      Return the value of PARAMETER which may either be a
4115      '<gdb:parameter>' object or a string naming the parameter.
4116
4117  -- Scheme Procedure: set-parameter-value! parameter new-value
4118      Assign PARAMETER the value of NEW-VALUE.  The argument PARAMETER
4119      must be an object of type '<gdb:parameter>'.  GDB does validation
4120      when assignments are made.
4121
4122    When a new parameter is defined, its type must be specified.  The
4123 available types are represented by constants defined in the 'gdb'
4124 module:
4125
4126 'PARAM_BOOLEAN'
4127      The value is a plain boolean.  The Guile boolean values, '#t' and
4128      '#f' are the only valid values.
4129
4130 'PARAM_AUTO_BOOLEAN'
4131      The value has three possible states: true, false, and 'auto'.  In
4132      Guile, true and false are represented using boolean constants, and
4133      'auto' is represented using '#:auto'.
4134
4135 'PARAM_UINTEGER'
4136      The value is an unsigned integer.  The value of 0 should be
4137      interpreted to mean "unlimited".
4138
4139 'PARAM_ZINTEGER'
4140      The value is an integer.
4141
4142 'PARAM_ZUINTEGER'
4143      The value is an unsigned integer.
4144
4145 'PARAM_ZUINTEGER_UNLIMITED'
4146      The value is an integer in the range '[0, INT_MAX]'.  A value of
4147      '-1' means "unlimited", and other negative numbers are not allowed.
4148
4149 'PARAM_STRING'
4150      The value is a string.  When the user modifies the string, any
4151      escape sequences, such as '\t', '\f', and octal escapes, are
4152      translated into corresponding characters and encoded into the
4153      current host charset.
4154
4155 'PARAM_STRING_NOESCAPE'
4156      The value is a string.  When the user modifies the string, escapes
4157      are passed through untranslated.
4158
4159 'PARAM_OPTIONAL_FILENAME'
4160      The value is a either a filename (a string), or '#f'.
4161
4162 'PARAM_FILENAME'
4163      The value is a filename.  This is just like
4164      'PARAM_STRING_NOESCAPE', but uses file names for completion.
4165
4166 'PARAM_ENUM'
4167      The value is a string, which must be one of a collection of string
4168      constants provided when the parameter is created.
4169
4170    ---------- Footnotes ----------
4171
4172    (1) Note that GDB parameters must not be confused with Guile’s
4173 parameter objects (*note (guile)Parameters::).
4174
4175 \1f
4176 File: gdb.info,  Node: Progspaces In Guile,  Next: Objfiles In Guile,  Prev: Parameters In Guile,  Up: Guile API
4177
4178 23.3.3.13 Program Spaces In Guile
4179 .................................
4180
4181 A program space, or "progspace", represents a symbolic view of an
4182 address space.  It consists of all of the objfiles of the program.
4183 *Note Objfiles In Guile::.  *Note program spaces: Inferiors and
4184 Programs, for more details about program spaces.
4185
4186    Each progspace is represented by an instance of the '<gdb:progspace>'
4187 smob.  *Note GDB Scheme Data Types::.
4188
4189    The following progspace-related functions are available in the
4190 '(gdb)' module:
4191
4192  -- Scheme Procedure: progspace? object
4193      Return '#t' if OBJECT is a '<gdb:progspace>' object.  Otherwise
4194      return '#f'.
4195
4196  -- Scheme Procedure: progspace-valid? progspace
4197      Return '#t' if PROGSPACE is valid, '#f' if not.  A
4198      '<gdb:progspace>' object can become invalid if the program it
4199      refers to is not loaded in GDB any longer.
4200
4201  -- Scheme Procedure: current-progspace
4202      This function returns the program space of the currently selected
4203      inferior.  There is always a current progspace, this never returns
4204      '#f'.  *Note Inferiors and Programs::.
4205
4206  -- Scheme Procedure: progspaces
4207      Return a list of all the progspaces currently known to GDB.
4208
4209  -- Scheme Procedure: progspace-filename progspace
4210      Return the absolute file name of PROGSPACE as a string.  This is
4211      the name of the file passed as the argument to the 'file' or
4212      'symbol-file' commands.  If the program space does not have an
4213      associated file name, then '#f' is returned.  This occurs, for
4214      example, when GDB is started without a program to debug.
4215
4216      A 'gdb:invalid-object-error' exception is thrown if PROGSPACE is
4217      invalid.
4218
4219  -- Scheme Procedure: progspace-objfiles progspace
4220      Return the list of objfiles of PROGSPACE.  The order of objfiles in
4221      the result is arbitrary.  Each element is an object of type
4222      '<gdb:objfile>'.  *Note Objfiles In Guile::.
4223
4224      A 'gdb:invalid-object-error' exception is thrown if PROGSPACE is
4225      invalid.
4226
4227  -- Scheme Procedure: progspace-pretty-printers progspace
4228      Return the list of pretty-printers of PROGSPACE.  Each element is
4229      an object of type '<gdb:pretty-printer>'.  *Note Guile Pretty
4230      Printing API::, for more information.
4231
4232  -- Scheme Procedure: set-progspace-pretty-printers! progspace
4233           printer-list
4234      Set the list of registered '<gdb:pretty-printer>' objects for
4235      PROGSPACE to PRINTER-LIST.  *Note Guile Pretty Printing API::, for
4236      more information.
4237
4238 \1f
4239 File: gdb.info,  Node: Objfiles In Guile,  Next: Frames In Guile,  Prev: Progspaces In Guile,  Up: Guile API
4240
4241 23.3.3.14 Objfiles In Guile
4242 ...........................
4243
4244 GDB loads symbols for an inferior from various symbol-containing files
4245 (*note Files::).  These include the primary executable file, any shared
4246 libraries used by the inferior, and any separate debug info files (*note
4247 Separate Debug Files::).  GDB calls these symbol-containing files
4248 "objfiles".
4249
4250    Each objfile is represented as an object of type '<gdb:objfile>'.
4251
4252    The following objfile-related procedures are provided by the '(gdb)'
4253 module:
4254
4255  -- Scheme Procedure: objfile? object
4256      Return '#t' if OBJECT is a '<gdb:objfile>' object.  Otherwise
4257      return '#f'.
4258
4259  -- Scheme Procedure: objfile-valid? objfile
4260      Return '#t' if OBJFILE is valid, '#f' if not.  A '<gdb:objfile>'
4261      object can become invalid if the object file it refers to is not
4262      loaded in GDB any longer.  All other '<gdb:objfile>' procedures
4263      will throw an exception if it is invalid at the time the procedure
4264      is called.
4265
4266  -- Scheme Procedure: objfile-filename objfile
4267      Return the file name of OBJFILE as a string.
4268
4269  -- Scheme Procedure: objfile-pretty-printers objfile
4270      Return the list of registered '<gdb:pretty-printer>' objects for
4271      OBJFILE.  *Note Guile Pretty Printing API::, for more information.
4272
4273  -- Scheme Procedure: set-objfile-pretty-printers! objfile printer-list
4274      Set the list of registered '<gdb:pretty-printer>' objects for
4275      OBJFILE to PRINTER-LIST.  The PRINTER-LIST must be a list of
4276      '<gdb:pretty-printer>' objects.  *Note Guile Pretty Printing API::,
4277      for more information.
4278
4279  -- Scheme Procedure: current-objfile
4280      When auto-loading a Guile script (*note Guile Auto-loading::), GDB
4281      sets the "current objfile" to the corresponding objfile.  This
4282      function returns the current objfile.  If there is no current
4283      objfile, this function returns '#f'.
4284
4285  -- Scheme Procedure: objfiles
4286      Return a list of all the objfiles in the current program space.
4287
4288 \1f
4289 File: gdb.info,  Node: Frames In Guile,  Next: Blocks In Guile,  Prev: Objfiles In Guile,  Up: Guile API
4290
4291 23.3.3.15 Accessing inferior stack frames from Guile.
4292 .....................................................
4293
4294 When the debugged program stops, GDB is able to analyze its call stack
4295 (*note Stack frames: Frames.).  The '<gdb:frame>' class represents a
4296 frame in the stack.  A '<gdb:frame>' object is only valid while its
4297 corresponding frame exists in the inferior's stack.  If you try to use
4298 an invalid frame object, GDB will throw a 'gdb:invalid-object' exception
4299 (*note Guile Exception Handling::).
4300
4301    Two '<gdb:frame>' objects can be compared for equality with the
4302 'equal?' function, like:
4303
4304      (gdb) guile (equal? (newest-frame) (selected-frame))
4305      #t
4306
4307    The following frame-related procedures are provided by the '(gdb)'
4308 module:
4309
4310  -- Scheme Procedure: frame? object
4311      Return '#t' if OBJECT is a '<gdb:frame>' object.  Otherwise return
4312      '#f'.
4313
4314  -- Scheme Procedure: frame-valid? frame
4315      Returns '#t' if FRAME is valid, '#f' if not.  A frame object can
4316      become invalid if the frame it refers to doesn't exist anymore in
4317      the inferior.  All '<gdb:frame>' procedures will throw an exception
4318      if the frame is invalid at the time the procedure is called.
4319
4320  -- Scheme Procedure: frame-name frame
4321      Return the function name of FRAME, or '#f' if it can't be obtained.
4322
4323  -- Scheme Procedure: frame-arch frame
4324      Return the '<gdb:architecture>' object corresponding to FRAME's
4325      architecture.  *Note Architectures In Guile::.
4326
4327  -- Scheme Procedure: frame-type frame
4328      Return the type of FRAME.  The value can be one of:
4329
4330      'NORMAL_FRAME'
4331           An ordinary stack frame.
4332
4333      'DUMMY_FRAME'
4334           A fake stack frame that was created by GDB when performing an
4335           inferior function call.
4336
4337      'INLINE_FRAME'
4338           A frame representing an inlined function.  The function was
4339           inlined into a 'NORMAL_FRAME' that is older than this one.
4340
4341      'TAILCALL_FRAME'
4342           A frame representing a tail call.  *Note Tail Call Frames::.
4343
4344      'SIGTRAMP_FRAME'
4345           A signal trampoline frame.  This is the frame created by the
4346           OS when it calls into a signal handler.
4347
4348      'ARCH_FRAME'
4349           A fake stack frame representing a cross-architecture call.
4350
4351      'SENTINEL_FRAME'
4352           This is like 'NORMAL_FRAME', but it is only used for the
4353           newest frame.
4354
4355  -- Scheme Procedure: frame-unwind-stop-reason frame
4356      Return an integer representing the reason why it's not possible to
4357      find more frames toward the outermost frame.  Use
4358      'unwind-stop-reason-string' to convert the value returned by this
4359      function to a string.  The value can be one of:
4360
4361      'FRAME_UNWIND_NO_REASON'
4362           No particular reason (older frames should be available).
4363
4364      'FRAME_UNWIND_NULL_ID'
4365           The previous frame's analyzer returns an invalid result.
4366
4367      'FRAME_UNWIND_OUTERMOST'
4368           This frame is the outermost.
4369
4370      'FRAME_UNWIND_UNAVAILABLE'
4371           Cannot unwind further, because that would require knowing the
4372           values of registers or memory that have not been collected.
4373
4374      'FRAME_UNWIND_INNER_ID'
4375           This frame ID looks like it ought to belong to a NEXT frame,
4376           but we got it for a PREV frame.  Normally, this is a sign of
4377           unwinder failure.  It could also indicate stack corruption.
4378
4379      'FRAME_UNWIND_SAME_ID'
4380           This frame has the same ID as the previous one.  That means
4381           that unwinding further would almost certainly give us another
4382           frame with exactly the same ID, so break the chain.  Normally,
4383           this is a sign of unwinder failure.  It could also indicate
4384           stack corruption.
4385
4386      'FRAME_UNWIND_NO_SAVED_PC'
4387           The frame unwinder did not find any saved PC, but we needed
4388           one to unwind further.
4389
4390      'FRAME_UNWIND_MEMORY_ERROR'
4391           The frame unwinder caused an error while trying to access
4392           memory.
4393
4394      'FRAME_UNWIND_FIRST_ERROR'
4395           Any stop reason greater or equal to this value indicates some
4396           kind of error.  This special value facilitates writing code
4397           that tests for errors in unwinding in a way that will work
4398           correctly even if the list of the other values is modified in
4399           future GDB versions.  Using it, you could write:
4400
4401                (define reason (frame-unwind-stop-readon (selected-frame)))
4402                (define reason-str (unwind-stop-reason-string reason))
4403                (if (>= reason FRAME_UNWIND_FIRST_ERROR)
4404                    (format #t "An error occured: ~s\n" reason-str))
4405
4406  -- Scheme Procedure: frame-pc frame
4407      Return the frame's resume address.
4408
4409  -- Scheme Procedure: frame-block frame
4410      Return the frame's code block as a '<gdb:block>' object.  *Note
4411      Blocks In Guile::.
4412
4413  -- Scheme Procedure: frame-function frame
4414      Return the symbol for the function corresponding to this frame as a
4415      '<gdb:symbol>' object, or '#f' if there isn't one.  *Note Symbols
4416      In Guile::.
4417
4418  -- Scheme Procedure: frame-older frame
4419      Return the frame that called FRAME.
4420
4421  -- Scheme Procedure: frame-newer frame
4422      Return the frame called by FRAME.
4423
4424  -- Scheme Procedure: frame-sal frame
4425      Return the frame's '<gdb:sal>' (symtab and line) object.  *Note
4426      Symbol Tables In Guile::.
4427
4428  -- Scheme Procedure: frame-read-var frame variable [#:block block]
4429      Return the value of VARIABLE in FRAME.  If the optional argument
4430      BLOCK is provided, search for the variable from that block;
4431      otherwise start at the frame's current block (which is determined
4432      by the frame's current program counter).  The VARIABLE must be
4433      given as a string or a '<gdb:symbol>' object, and BLOCK must be a
4434      '<gdb:block>' object.
4435
4436  -- Scheme Procedure: frame-select frame
4437      Set FRAME to be the selected frame.  *Note Examining the Stack:
4438      Stack.
4439
4440  -- Scheme Procedure: selected-frame
4441      Return the selected frame object.  *Note Selecting a Frame:
4442      Selection.
4443
4444  -- Scheme Procedure: newest-frame
4445      Return the newest frame object for the selected thread.
4446
4447  -- Scheme Procedure: unwind-stop-reason-string reason
4448      Return a string explaining the reason why GDB stopped unwinding
4449      frames, as expressed by the given REASON code (an integer, see the
4450      'frame-unwind-stop-reason' procedure above in this section).
4451
4452 \1f
4453 File: gdb.info,  Node: Blocks In Guile,  Next: Symbols In Guile,  Prev: Frames In Guile,  Up: Guile API
4454
4455 23.3.3.16 Accessing blocks from Guile.
4456 ......................................
4457
4458 In GDB, symbols are stored in blocks.  A block corresponds roughly to a
4459 scope in the source code.  Blocks are organized hierarchically, and are
4460 represented individually in Guile as an object of type '<gdb:block>'.
4461 Blocks rely on debugging information being available.
4462
4463    A frame has a block.  Please see *note Frames In Guile::, for a more
4464 in-depth discussion of frames.
4465
4466    The outermost block is known as the "global block".  The global block
4467 typically holds public global variables and functions.
4468
4469    The block nested just inside the global block is the "static block".
4470 The static block typically holds file-scoped variables and functions.
4471
4472    GDB provides a method to get a block's superblock, but there is
4473 currently no way to examine the sub-blocks of a block, or to iterate
4474 over all the blocks in a symbol table (*note Symbol Tables In Guile::).
4475
4476    Here is a short example that should help explain blocks:
4477
4478      /* This is in the global block.  */
4479      int global;
4480
4481      /* This is in the static block.  */
4482      static int file_scope;
4483
4484      /* 'function' is in the global block, and 'argument' is
4485         in a block nested inside of 'function'.  */
4486      int function (int argument)
4487      {
4488        /* 'local' is in a block inside 'function'.  It may or may
4489           not be in the same block as 'argument'.  */
4490        int local;
4491
4492        {
4493           /* 'inner' is in a block whose superblock is the one holding
4494              'local'.  */
4495           int inner;
4496
4497           /* If this call is expanded by the compiler, you may see
4498              a nested block here whose function is 'inline_function'
4499              and whose superblock is the one holding 'inner'.  */
4500           inline_function ();
4501        }
4502      }
4503
4504    The following block-related procedures are provided by the '(gdb)'
4505 module:
4506
4507  -- Scheme Procedure: block? object
4508      Return '#t' if OBJECT is a '<gdb:block>' object.  Otherwise return
4509      '#f'.
4510
4511  -- Scheme Procedure: block-valid? block
4512      Returns '#t' if '<gdb:block>' BLOCK is valid, '#f' if not.  A block
4513      object can become invalid if the block it refers to doesn't exist
4514      anymore in the inferior.  All other '<gdb:block>' methods will
4515      throw an exception if it is invalid at the time the procedure is
4516      called.  The block's validity is also checked during iteration over
4517      symbols of the block.
4518
4519  -- Scheme Procedure: block-start block
4520      Return the start address of '<gdb:block>' BLOCK.
4521
4522  -- Scheme Procedure: block-end block
4523      Return the end address of '<gdb:block>' BLOCK.
4524
4525  -- Scheme Procedure: block-function block
4526      Return the name of '<gdb:block>' BLOCK represented as a
4527      '<gdb:symbol>' object.  If the block is not named, then '#f' is
4528      returned.
4529
4530      For ordinary function blocks, the superblock is the static block.
4531      However, you should note that it is possible for a function block
4532      to have a superblock that is not the static block - for instance
4533      this happens for an inlined function.
4534
4535  -- Scheme Procedure: block-superblock block
4536      Return the block containing '<gdb:block>' BLOCK.  If the parent
4537      block does not exist, then '#f' is returned.
4538
4539  -- Scheme Procedure: block-global-block block
4540      Return the global block associated with '<gdb:block>' BLOCK.
4541
4542  -- Scheme Procedure: block-static-block block
4543      Return the static block associated with '<gdb:block>' BLOCK.
4544
4545  -- Scheme Procedure: block-global? block
4546      Return '#t' if '<gdb:block>' BLOCK is a global block.  Otherwise
4547      return '#f'.
4548
4549  -- Scheme Procedure: block-static? block
4550      Return '#t' if '<gdb:block>' BLOCK is a static block.  Otherwise
4551      return '#f'.
4552
4553  -- Scheme Procedure: block-symbols
4554      Return a list of all symbols (as <gdb:symbol> objects) in
4555      '<gdb:block>' BLOCK.
4556
4557  -- Scheme Procedure: make-block-symbols-iterator block
4558      Return an object of type '<gdb:iterator>' that will iterate over
4559      all symbols of the block.  Guile programs should not assume that a
4560      specific block object will always contain a given symbol, since
4561      changes in GDB features and infrastructure may cause symbols move
4562      across blocks in a symbol table.  *Note Iterators In Guile::.
4563
4564  -- Scheme Procedure: block-symbols-progress?
4565      Return #t if the object is a <gdb:block-symbols-progress> object.
4566      This object would be obtained from the 'progress' element of the
4567      '<gdb:iterator>' object returned by 'make-block-symbols-iterator'.
4568
4569  -- Scheme Procedure: lookup-block pc
4570      Return the innermost '<gdb:block>' containing the given PC value.
4571      If the block cannot be found for the PC value specified, the
4572      function will return '#f'.
4573
4574 \1f
4575 File: gdb.info,  Node: Symbols In Guile,  Next: Symbol Tables In Guile,  Prev: Blocks In Guile,  Up: Guile API
4576
4577 23.3.3.17 Guile representation of Symbols.
4578 ..........................................
4579
4580 GDB represents every variable, function and type as an entry in a symbol
4581 table.  *Note Examining the Symbol Table: Symbols.  Guile represents
4582 these symbols in GDB with the '<gdb:symbol>' object.
4583
4584    The following symbol-related procedures are provided by the '(gdb)'
4585 module:
4586
4587  -- Scheme Procedure: symbol? object
4588      Return '#t' if OBJECT is an object of type '<gdb:symbol>'.
4589      Otherwise return '#f'.
4590
4591  -- Scheme Procedure: symbol-valid? symbol
4592      Return '#t' if the '<gdb:symbol>' object is valid, '#f' if not.  A
4593      '<gdb:symbol>' object can become invalid if the symbol it refers to
4594      does not exist in GDB any longer.  All other '<gdb:symbol>'
4595      procedures will throw an exception if it is invalid at the time the
4596      procedure is called.
4597
4598  -- Scheme Procedure: symbol-type symbol
4599      Return the type of SYMBOL or '#f' if no type is recorded.  The
4600      result is an object of type '<gdb:type>'.  *Note Types In Guile::.
4601
4602  -- Scheme Procedure: symbol-symtab symbol
4603      Return the symbol table in which SYMBOL appears.  The result is an
4604      object of type '<gdb:symtab>'.  *Note Symbol Tables In Guile::.
4605
4606  -- Scheme Procedure: symbol-line symbol
4607      Return the line number in the source code at which SYMBOL was
4608      defined.  This is an integer.
4609
4610  -- Scheme Procedure: symbol-name symbol
4611      Return the name of SYMBOL as a string.
4612
4613  -- Scheme Procedure: symbol-linkage-name symbol
4614      Return the name of SYMBOL, as used by the linker (i.e., may be
4615      mangled).
4616
4617  -- Scheme Procedure: symbol-print-name symbol
4618      Return the name of SYMBOL in a form suitable for output.  This is
4619      either 'name' or 'linkage_name', depending on whether the user
4620      asked GDB to display demangled or mangled names.
4621
4622  -- Scheme Procedure: symbol-addr-class symbol
4623      Return the address class of the symbol.  This classifies how to
4624      find the value of a symbol.  Each address class is a constant
4625      defined in the '(gdb)' module and described later in this chapter.
4626
4627  -- Scheme Procedure: symbol-needs-frame? symbol
4628      Return '#t' if evaluating SYMBOL's value requires a frame (*note
4629      Frames In Guile::) and '#f' otherwise.  Typically, local variables
4630      will require a frame, but other symbols will not.
4631
4632  -- Scheme Procedure: symbol-argument? symbol
4633      Return '#t' if SYMBOL is an argument of a function.  Otherwise
4634      return '#f'.
4635
4636  -- Scheme Procedure: symbol-constant? symbol
4637      Return '#t' if SYMBOL is a constant.  Otherwise return '#f'.
4638
4639  -- Scheme Procedure: symbol-function? symbol
4640      Return '#t' if SYMBOL is a function or a method.  Otherwise return
4641      '#f'.
4642
4643  -- Scheme Procedure: symbol-variable? symbol
4644      Return '#t' if SYMBOL is a variable.  Otherwise return '#f'.
4645
4646  -- Scheme Procedure: symbol-value symbol [#:frame frame]
4647      Compute the value of SYMBOL, as a '<gdb:value>'.  For functions,
4648      this computes the address of the function, cast to the appropriate
4649      type.  If the symbol requires a frame in order to compute its
4650      value, then FRAME must be given.  If FRAME is not given, or if
4651      FRAME is invalid, then an exception is thrown.
4652
4653  -- Scheme Procedure: lookup-symbol name [#:block block] [#:domain
4654           domain]
4655      This function searches for a symbol by name.  The search scope can
4656      be restricted to the parameters defined in the optional domain and
4657      block arguments.
4658
4659      NAME is the name of the symbol.  It must be a string.  The optional
4660      BLOCK argument restricts the search to symbols visible in that
4661      BLOCK.  The BLOCK argument must be a '<gdb:block>' object.  If
4662      omitted, the block for the current frame is used.  The optional
4663      DOMAIN argument restricts the search to the domain type.  The
4664      DOMAIN argument must be a domain constant defined in the '(gdb)'
4665      module and described later in this chapter.
4666
4667      The result is a list of two elements.  The first element is a
4668      '<gdb:symbol>' object or '#f' if the symbol is not found.  If the
4669      symbol is found, the second element is '#t' if the symbol is a
4670      field of a method's object (e.g., 'this' in C++), otherwise it is
4671      '#f'.  If the symbol is not found, the second element is '#f'.
4672
4673  -- Scheme Procedure: lookup-global-symbol name [#:domain domain]
4674      This function searches for a global symbol by name.  The search
4675      scope can be restricted by the domain argument.
4676
4677      NAME is the name of the symbol.  It must be a string.  The optional
4678      DOMAIN argument restricts the search to the domain type.  The
4679      DOMAIN argument must be a domain constant defined in the '(gdb)'
4680      module and described later in this chapter.
4681
4682      The result is a '<gdb:symbol>' object or '#f' if the symbol is not
4683      found.
4684
4685    The available domain categories in '<gdb:symbol>' are represented as
4686 constants in the '(gdb)' module:
4687
4688 'SYMBOL_UNDEF_DOMAIN'
4689      This is used when a domain has not been discovered or none of the
4690      following domains apply.  This usually indicates an error either in
4691      the symbol information or in GDB's handling of symbols.
4692
4693 'SYMBOL_VAR_DOMAIN'
4694      This domain contains variables, function names, typedef names and
4695      enum type values.
4696
4697 'SYMBOL_STRUCT_DOMAIN'
4698      This domain holds struct, union and enum type names.
4699
4700 'SYMBOL_LABEL_DOMAIN'
4701      This domain contains names of labels (for gotos).
4702
4703 'SYMBOL_VARIABLES_DOMAIN'
4704      This domain holds a subset of the 'SYMBOLS_VAR_DOMAIN'; it contains
4705      everything minus functions and types.
4706
4707 'SYMBOL_FUNCTION_DOMAIN'
4708      This domain contains all functions.
4709
4710 'SYMBOL_TYPES_DOMAIN'
4711      This domain contains all types.
4712
4713    The available address class categories in '<gdb:symbol>' are
4714 represented as constants in the 'gdb' module:
4715
4716 'SYMBOL_LOC_UNDEF'
4717      If this is returned by address class, it indicates an error either
4718      in the symbol information or in GDB's handling of symbols.
4719
4720 'SYMBOL_LOC_CONST'
4721      Value is constant int.
4722
4723 'SYMBOL_LOC_STATIC'
4724      Value is at a fixed address.
4725
4726 'SYMBOL_LOC_REGISTER'
4727      Value is in a register.
4728
4729 'SYMBOL_LOC_ARG'
4730      Value is an argument.  This value is at the offset stored within
4731      the symbol inside the frame's argument list.
4732
4733 'SYMBOL_LOC_REF_ARG'
4734      Value address is stored in the frame's argument list.  Just like
4735      'LOC_ARG' except that the value's address is stored at the offset,
4736      not the value itself.
4737
4738 'SYMBOL_LOC_REGPARM_ADDR'
4739      Value is a specified register.  Just like 'LOC_REGISTER' except the
4740      register holds the address of the argument instead of the argument
4741      itself.
4742
4743 'SYMBOL_LOC_LOCAL'
4744      Value is a local variable.
4745
4746 'SYMBOL_LOC_TYPEDEF'
4747      Value not used.  Symbols in the domain 'SYMBOL_STRUCT_DOMAIN' all
4748      have this class.
4749
4750 'SYMBOL_LOC_BLOCK'
4751      Value is a block.
4752
4753 'SYMBOL_LOC_CONST_BYTES'
4754      Value is a byte-sequence.
4755
4756 'SYMBOL_LOC_UNRESOLVED'
4757      Value is at a fixed address, but the address of the variable has to
4758      be determined from the minimal symbol table whenever the variable
4759      is referenced.
4760
4761 'SYMBOL_LOC_OPTIMIZED_OUT'
4762      The value does not actually exist in the program.
4763
4764 'SYMBOL_LOC_COMPUTED'
4765      The value's address is a computed location.
4766
4767 \1f
4768 File: gdb.info,  Node: Symbol Tables In Guile,  Next: Breakpoints In Guile,  Prev: Symbols In Guile,  Up: Guile API
4769
4770 23.3.3.18 Symbol table representation in Guile.
4771 ...............................................
4772
4773 Access to symbol table data maintained by GDB on the inferior is exposed
4774 to Guile via two objects: '<gdb:sal>' (symtab-and-line) and
4775 '<gdb:symtab>'.  Symbol table and line data for a frame is returned from
4776 the 'frame-find-sal' '<gdb:frame>' procedure.  *Note Frames In Guile::.
4777
4778    For more information on GDB's symbol table management, see *note
4779 Examining the Symbol Table: Symbols.
4780
4781    The following symtab-related procedures are provided by the '(gdb)'
4782 module:
4783
4784  -- Scheme Procedure: symtab? object
4785      Return '#t' if OBJECT is an object of type '<gdb:symtab>'.
4786      Otherwise return '#f'.
4787
4788  -- Scheme Procedure: symtab-valid? symtab
4789      Return '#t' if the '<gdb:symtab>' object is valid, '#f' if not.  A
4790      '<gdb:symtab>' object becomes invalid when the symbol table it
4791      refers to no longer exists in GDB.  All other '<gdb:symtab>'
4792      procedures will throw an exception if it is invalid at the time the
4793      procedure is called.
4794
4795  -- Scheme Procedure: symtab-filename symtab
4796      Return the symbol table's source filename.
4797
4798  -- Scheme Procedure: symtab-fullname symtab
4799      Return the symbol table's source absolute file name.
4800
4801  -- Scheme Procedure: symtab-objfile symtab
4802      Return the symbol table's backing object file.  *Note Objfiles In
4803      Guile::.
4804
4805  -- Scheme Procedure: symtab-global-block symtab
4806      Return the global block of the underlying symbol table.  *Note
4807      Blocks In Guile::.
4808
4809  -- Scheme Procedure: symtab-static-block symtab
4810      Return the static block of the underlying symbol table.  *Note
4811      Blocks In Guile::.
4812
4813    The following symtab-and-line-related procedures are provided by the
4814 '(gdb)' module:
4815
4816  -- Scheme Procedure: sal? object
4817      Return '#t' if OBJECT is an object of type '<gdb:sal>'.  Otherwise
4818      return '#f'.
4819
4820  -- Scheme Procedure: sal-valid? sal
4821      Return '#t' if SAL is valid, '#f' if not.  A '<gdb:sal>' object
4822      becomes invalid when the Symbol table object it refers to no longer
4823      exists in GDB.  All other '<gdb:sal>' procedures will throw an
4824      exception if it is invalid at the time the procedure is called.
4825
4826  -- Scheme Procedure: sal-symtab sal
4827      Return the symbol table object ('<gdb:symtab>') for SAL.
4828
4829  -- Scheme Procedure: sal-line sal
4830      Return the line number for SAL.
4831
4832  -- Scheme Procedure: sal-pc sal
4833      Return the start of the address range occupied by code for SAL.
4834
4835  -- Scheme Procedure: sal-last sal
4836      Return the end of the address range occupied by code for SAL.
4837
4838  -- Scheme Procedure: find-pc-line pc
4839      Return the '<gdb:sal>' object corresponding to the PC value.  If an
4840      invalid value of PC is passed as an argument, then the 'symtab' and
4841      'line' attributes of the returned '<gdb:sal>' object will be '#f'
4842      and 0 respectively.
4843
4844 \1f
4845 File: gdb.info,  Node: Breakpoints In Guile,  Next: Lazy Strings In Guile,  Prev: Symbol Tables In Guile,  Up: Guile API
4846
4847 23.3.3.19 Manipulating breakpoints using Guile
4848 ..............................................
4849
4850 Breakpoints in Guile are represented by objects of type
4851 '<gdb:breakpoint>'.  New breakpoints can be created with the
4852 'make-breakpoint' Guile function, and then added to GDB with the
4853 'register-breakpoint!' Guile function.  This two-step approach is taken
4854 to separate out the side-effect of adding the breakpoint to GDB from
4855 'make-breakpoint'.
4856
4857    Support is also provided to view and manipulate breakpoints created
4858 outside of Guile.
4859
4860    The following breakpoint-related procedures are provided by the
4861 '(gdb)' module:
4862
4863  -- Scheme Procedure: make-breakpoint location [#:type type] [#:wp-class
4864           wp-class] [#:internal internal]
4865      Create a new breakpoint at LOCATION, a string naming the location
4866      of the breakpoint, or an expression that defines a watchpoint.  The
4867      contents can be any location recognized by the 'break' command, or
4868      in the case of a watchpoint, by the 'watch' command.
4869
4870      The breakpoint is initially marked as 'invalid'.  The breakpoint is
4871      not usable until it has been registered with GDB with
4872      'register-breakpoint!', at which point it becomes 'valid'.  The
4873      result is the '<gdb:breakpoint>' object representing the
4874      breakpoint.
4875
4876      The optional TYPE denotes the breakpoint to create.  This argument
4877      can be either 'BP_BREAKPOINT' or 'BP_WATCHPOINT', and defaults to
4878      'BP_BREAKPOINT'.
4879
4880      The optional WP-CLASS argument defines the class of watchpoint to
4881      create, if TYPE is 'BP_WATCHPOINT'.  If a watchpoint class is not
4882      provided, it is assumed to be a 'WP_WRITE' class.
4883
4884      The optional INTERNAL argument allows the breakpoint to become
4885      invisible to the user.  The breakpoint will neither be reported
4886      when registered, nor will it be listed in the output from 'info
4887      breakpoints' (but will be listed with the 'maint info breakpoints'
4888      command).  If an internal flag is not provided, the breakpoint is
4889      visible (non-internal).
4890
4891      When a watchpoint is created, GDB will try to create a hardware
4892      assisted watchpoint.  If successful, the type of the watchpoint is
4893      changed from 'BP_WATCHPOINT' to 'BP_HARDWARE_WATCHPOINT' for
4894      'WP_WRITE', 'BP_READ_WATCHPOINT' for 'WP_READ', and
4895      'BP_ACCESS_WATCHPOINT' for 'WP_ACCESS'.  If not successful, the
4896      type of the watchpoint is left as 'WP_WATCHPOINT'.
4897
4898      The available types are represented by constants defined in the
4899      'gdb' module:
4900
4901      'BP_BREAKPOINT'
4902           Normal code breakpoint.
4903
4904      'BP_WATCHPOINT'
4905           Watchpoint breakpoint.
4906
4907      'BP_HARDWARE_WATCHPOINT'
4908           Hardware assisted watchpoint.  This value cannot be specified
4909           when creating the breakpoint.
4910
4911      'BP_READ_WATCHPOINT'
4912           Hardware assisted read watchpoint.  This value cannot be
4913           specified when creating the breakpoint.
4914
4915      'BP_ACCESS_WATCHPOINT'
4916           Hardware assisted access watchpoint.  This value cannot be
4917           specified when creating the breakpoint.
4918
4919      The available watchpoint types represented by constants are defined
4920      in the '(gdb)' module:
4921
4922      'WP_READ'
4923           Read only watchpoint.
4924
4925      'WP_WRITE'
4926           Write only watchpoint.
4927
4928      'WP_ACCESS'
4929           Read/Write watchpoint.
4930
4931  -- Scheme Procedure: register-breakpoint! breakpoint
4932      Add BREAKPOINT, a '<gdb:breakpoint>' object, to GDB's list of
4933      breakpoints.  The breakpoint must have been created with
4934      'make-breakpoint'.  One cannot register breakpoints that have been
4935      created outside of Guile.  Once a breakpoint is registered it
4936      becomes 'valid'.  It is an error to register an already registered
4937      breakpoint.  The result is unspecified.
4938
4939  -- Scheme Procedure: delete-breakpoint! breakpoint
4940      Remove BREAKPOINT from GDB's list of breakpoints.  This also
4941      invalidates the Guile BREAKPOINT object.  Any further attempt to
4942      access the object will throw an exception.
4943
4944      If BREAKPOINT was created from Guile with 'make-breakpoint' it may
4945      be re-registered with GDB, in which case the breakpoint becomes
4946      valid again.
4947
4948  -- Scheme Procedure: breakpoints
4949      Return a list of all breakpoints.  Each element of the list is a
4950      '<gdb:breakpoint>' object.
4951
4952  -- Scheme Procedure: breakpoint? object
4953      Return '#t' if OBJECT is a '<gdb:breakpoint>' object, and '#f'
4954      otherwise.
4955
4956  -- Scheme Procedure: breakpoint-valid? breakpoint
4957      Return '#t' if BREAKPOINT is valid, '#f' otherwise.  Breakpoints
4958      created with 'make-breakpoint' are marked as invalid until they are
4959      registered with GDB with 'register-breakpoint!'.  A
4960      '<gdb:breakpoint>' object can become invalid if the user deletes
4961      the breakpoint.  In this case, the object still exists, but the
4962      underlying breakpoint does not.  In the cases of watchpoint scope,
4963      the watchpoint remains valid even if execution of the inferior
4964      leaves the scope of that watchpoint.
4965
4966  -- Scheme Procedure: breakpoint-number breakpoint
4967      Return the breakpoint's number -- the identifier used by the user
4968      to manipulate the breakpoint.
4969
4970  -- Scheme Procedure: breakpoint-type breakpoint
4971      Return the breakpoint's type -- the identifier used to determine
4972      the actual breakpoint type or use-case.
4973
4974  -- Scheme Procedure: breakpoint-visible? breakpoint
4975      Return '#t' if the breakpoint is visible to the user when hit, or
4976      when the 'info breakpoints' command is run.  Otherwise return '#f'.
4977
4978  -- Scheme Procedure: breakpoint-location breakpoint
4979      Return the location of the breakpoint, as specified by the user.
4980      It is a string.  If the breakpoint does not have a location (that
4981      is, it is a watchpoint) return '#f'.
4982
4983  -- Scheme Procedure: breakpoint-expression breakpoint
4984      Return the breakpoint expression, as specified by the user.  It is
4985      a string.  If the breakpoint does not have an expression (the
4986      breakpoint is not a watchpoint) return '#f'.
4987
4988  -- Scheme Procedure: breakpoint-enabled? breakpoint
4989      Return '#t' if the breakpoint is enabled, and '#f' otherwise.
4990
4991  -- Scheme Procedure: set-breakpoint-enabled! breakpoint flag
4992      Set the enabled state of BREAKPOINT to FLAG.  If flag is '#f' it is
4993      disabled, otherwise it is enabled.
4994
4995  -- Scheme Procedure: breakpoint-silent? breakpoint
4996      Return '#t' if the breakpoint is silent, and '#f' otherwise.
4997
4998      Note that a breakpoint can also be silent if it has commands and
4999      the first command is 'silent'.  This is not reported by the
5000      'silent' attribute.
5001
5002  -- Scheme Procedure: set-breakpoint-silent! breakpoint flag
5003      Set the silent state of BREAKPOINT to FLAG.  If flag is '#f' the
5004      breakpoint is made silent, otherwise it is made non-silent (or
5005      noisy).
5006
5007  -- Scheme Procedure: breakpoint-ignore-count breakpoint
5008      Return the ignore count for BREAKPOINT.
5009
5010  -- Scheme Procedure: set-breakpoint-ignore-count! breakpoint count
5011      Set the ignore count for BREAKPOINT to COUNT.
5012
5013  -- Scheme Procedure: breakpoint-hit-count breakpoint
5014      Return hit count of BREAKPOINT.
5015
5016  -- Scheme Procedure: set-breakpoint-hit-count! breakpoint count
5017      Set the hit count of BREAKPOINT to COUNT.  At present, COUNT must
5018      be zero.
5019
5020  -- Scheme Procedure: breakpoint-thread breakpoint
5021      Return the thread-id for thread-specific breakpoint BREAKPOINT.
5022      Return #f if BREAKPOINT is not thread-specific.
5023
5024  -- Scheme Procedure: set-breakpoint-thread! breakpoint thread-id|#f
5025      Set the thread-id for BREAKPOINT to THREAD-ID.  If set to '#f', the
5026      breakpoint is no longer thread-specific.
5027
5028  -- Scheme Procedure: breakpoint-task breakpoint
5029      If the breakpoint is Ada task-specific, return the Ada task id.  If
5030      the breakpoint is not task-specific (or the underlying language is
5031      not Ada), return '#f'.
5032
5033  -- Scheme Procedure: set-breakpoint-task! breakpoint task
5034      Set the Ada task of BREAKPOINT to TASK.  If set to '#f', the
5035      breakpoint is no longer task-specific.
5036
5037  -- Scheme Procedure: breakpoint-condition breakpoint
5038      Return the condition of BREAKPOINT, as specified by the user.  It
5039      is a string.  If there is no condition, return '#f'.
5040
5041  -- Scheme Procedure: set-breakpoint-condition! breakpoint condition
5042      Set the condition of BREAKPOINT to CONDITION, which must be a
5043      string.  If set to '#f' then the breakpoint becomes unconditional.
5044
5045  -- Scheme Procedure: breakpoint-stop breakpoint
5046      Return the stop predicate of BREAKPOINT.  See
5047      'set-breakpoint-stop!' below in this section.
5048
5049  -- Scheme Procedure: set-breakpoint-stop! breakpoint procedure|#f
5050      Set the stop predicate of BREAKPOINT.  The predicate PROCEDURE
5051      takes one argument: the <gdb:breakpoint> object.  If this predicate
5052      is set to a procedure then it is invoked whenever the inferior
5053      reaches this breakpoint.  If it returns '#t', or any non-'#f'
5054      value, then the inferior is stopped, otherwise the inferior will
5055      continue.
5056
5057      If there are multiple breakpoints at the same location with a
5058      'stop' predicate, each one will be called regardless of the return
5059      status of the previous.  This ensures that all 'stop' predicates
5060      have a chance to execute at that location.  In this scenario if one
5061      of the methods returns '#t' but the others return '#f', the
5062      inferior will still be stopped.
5063
5064      You should not alter the execution state of the inferior (i.e.,
5065      step, next, etc.), alter the current frame context (i.e., change
5066      the current active frame), or alter, add or delete any breakpoint.
5067      As a general rule, you should not alter any data within GDB or the
5068      inferior at this time.
5069
5070      Example 'stop' implementation:
5071
5072           (define (my-stop? bkpt)
5073             (let ((int-val (parse-and-eval "foo")))
5074               (value=? int-val 3)))
5075           (define bkpt (make-breakpoint "main.c:42"))
5076           (register-breakpoint! bkpt)
5077           (set-breakpoint-stop! bkpt my-stop?)
5078
5079  -- Scheme Procedure: breakpoint-commands breakpoint
5080      Return the commands attached to BREAKPOINT as a string, or '#f' if
5081      there are none.
5082
5083 \1f
5084 File: gdb.info,  Node: Lazy Strings In Guile,  Next: Architectures In Guile,  Prev: Breakpoints In Guile,  Up: Guile API
5085
5086 23.3.3.20 Guile representation of lazy strings.
5087 ...............................................
5088
5089 A "lazy string" is a string whose contents is not retrieved or encoded
5090 until it is needed.
5091
5092    A '<gdb:lazy-string>' is represented in GDB as an 'address' that
5093 points to a region of memory, an 'encoding' that will be used to encode
5094 that region of memory, and a 'length' to delimit the region of memory
5095 that represents the string.  The difference between a
5096 '<gdb:lazy-string>' and a string wrapped within a '<gdb:value>' is that
5097 a '<gdb:lazy-string>' will be treated differently by GDB when printing.
5098 A '<gdb:lazy-string>' is retrieved and encoded during printing, while a
5099 '<gdb:value>' wrapping a string is immediately retrieved and encoded on
5100 creation.
5101
5102    The following lazy-string-related procedures are provided by the
5103 '(gdb)' module:
5104
5105  -- Scheme Procedure: lazy-string? object
5106      Return '#t' if OBJECT is an object of type '<gdb:lazy-string>'.
5107      Otherwise return '#f'.
5108
5109  -- Scheme Procedure: lazy-string-address lazy-sring
5110      Return the address of LAZY-STRING.
5111
5112  -- Scheme Procedure: lazy-string-length lazy-string
5113      Return the length of LAZY-STRING in characters.  If the length is
5114      -1, then the string will be fetched and encoded up to the first
5115      null of appropriate width.
5116
5117  -- Scheme Procedure: lazy-string-encoding lazy-string
5118      Return the encoding that will be applied to LAZY-STRING when the
5119      string is printed by GDB.  If the encoding is not set, or contains
5120      an empty string, then GDB will select the most appropriate encoding
5121      when the string is printed.
5122
5123  -- Scheme Procedure: lazy-string-type lazy-string
5124      Return the type that is represented by LAZY-STRING's type.  For a
5125      lazy string this will always be a pointer type.  To resolve this to
5126      the lazy string's character type, use 'type-target-type'.  *Note
5127      Types In Guile::.
5128
5129  -- Scheme Procedure: lazy-string->value lazy-string
5130      Convert the '<gdb:lazy-string>' to a '<gdb:value>'.  This value
5131      will point to the string in memory, but will lose all the delayed
5132      retrieval, encoding and handling that GDB applies to a
5133      '<gdb:lazy-string>'.
5134
5135 \1f
5136 File: gdb.info,  Node: Architectures In Guile,  Next: Disassembly In Guile,  Prev: Lazy Strings In Guile,  Up: Guile API
5137
5138 23.3.3.21 Guile representation of architectures
5139 ...............................................
5140
5141 GDB uses architecture specific parameters and artifacts in a number of
5142 its various computations.  An architecture is represented by an instance
5143 of the '<gdb:arch>' class.
5144
5145    The following architecture-related procedures are provided by the
5146 '(gdb)' module:
5147
5148  -- Scheme Procedure: arch? object
5149      Return '#t' if OBJECT is an object of type '<gdb:arch>'.  Otherwise
5150      return '#f'.
5151
5152  -- Scheme Procedure: current-arch
5153      Return the current architecture as a '<gdb:arch>' object.
5154
5155  -- Scheme Procedure: arch-name arch
5156      Return the name (string value) of '<gdb:arch>' ARCH.
5157
5158  -- Scheme Procedure: arch-charset arch
5159      Return name of target character set of '<gdb:arch>' ARCH.
5160
5161  -- Scheme Procedure: arch-wide-charset
5162      Return name of target wide character set of '<gdb:arch>' ARCH.
5163
5164    Each architecture provides a set of predefined types, obtained by the
5165 following functions.
5166
5167  -- Scheme Procedure: arch-void-type arch
5168      Return the '<gdb:type>' object for a 'void' type of architecture
5169      ARCH.
5170
5171  -- Scheme Procedure: arch-char-type arch
5172      Return the '<gdb:type>' object for a 'char' type of architecture
5173      ARCH.
5174
5175  -- Scheme Procedure: arch-short-type arch
5176      Return the '<gdb:type>' object for a 'short' type of architecture
5177      ARCH.
5178
5179  -- Scheme Procedure: arch-int-type arch
5180      Return the '<gdb:type>' object for an 'int' type of architecture
5181      ARCH.
5182
5183  -- Scheme Procedure: arch-long-type arch
5184      Return the '<gdb:type>' object for a 'long' type of architecture
5185      ARCH.
5186
5187  -- Scheme Procedure: arch-schar-type arch
5188      Return the '<gdb:type>' object for a 'signed char' type of
5189      architecture ARCH.
5190
5191  -- Scheme Procedure: arch-uchar-type arch
5192      Return the '<gdb:type>' object for an 'unsigned char' type of
5193      architecture ARCH.
5194
5195  -- Scheme Procedure: arch-ushort-type arch
5196      Return the '<gdb:type>' object for an 'unsigned short' type of
5197      architecture ARCH.
5198
5199  -- Scheme Procedure: arch-uint-type arch
5200      Return the '<gdb:type>' object for an 'unsigned int' type of
5201      architecture ARCH.
5202
5203  -- Scheme Procedure: arch-ulong-type arch
5204      Return the '<gdb:type>' object for an 'unsigned long' type of
5205      architecture ARCH.
5206
5207  -- Scheme Procedure: arch-float-type arch
5208      Return the '<gdb:type>' object for a 'float' type of architecture
5209      ARCH.
5210
5211  -- Scheme Procedure: arch-double-type arch
5212      Return the '<gdb:type>' object for a 'double' type of architecture
5213      ARCH.
5214
5215  -- Scheme Procedure: arch-longdouble-type arch
5216      Return the '<gdb:type>' object for a 'long double' type of
5217      architecture ARCH.
5218
5219  -- Scheme Procedure: arch-bool-type arch
5220      Return the '<gdb:type>' object for a 'bool' type of architecture
5221      ARCH.
5222
5223  -- Scheme Procedure: arch-longlong-type arch
5224      Return the '<gdb:type>' object for a 'long long' type of
5225      architecture ARCH.
5226
5227  -- Scheme Procedure: arch-ulonglong-type arch
5228      Return the '<gdb:type>' object for an 'unsigned long long' type of
5229      architecture ARCH.
5230
5231  -- Scheme Procedure: arch-int8-type arch
5232      Return the '<gdb:type>' object for an 'int8' type of architecture
5233      ARCH.
5234
5235  -- Scheme Procedure: arch-uint8-type arch
5236      Return the '<gdb:type>' object for a 'uint8' type of architecture
5237      ARCH.
5238
5239  -- Scheme Procedure: arch-int16-type arch
5240      Return the '<gdb:type>' object for an 'int16' type of architecture
5241      ARCH.
5242
5243  -- Scheme Procedure: arch-uint16-type arch
5244      Return the '<gdb:type>' object for a 'uint16' type of architecture
5245      ARCH.
5246
5247  -- Scheme Procedure: arch-int32-type arch
5248      Return the '<gdb:type>' object for an 'int32' type of architecture
5249      ARCH.
5250
5251  -- Scheme Procedure: arch-uint32-type arch
5252      Return the '<gdb:type>' object for a 'uint32' type of architecture
5253      ARCH.
5254
5255  -- Scheme Procedure: arch-int64-type arch
5256      Return the '<gdb:type>' object for an 'int64' type of architecture
5257      ARCH.
5258
5259  -- Scheme Procedure: arch-uint64-type arch
5260      Return the '<gdb:type>' object for a 'uint64' type of architecture
5261      ARCH.
5262
5263    Example:
5264
5265      (gdb) guile (type-name (arch-uchar-type (current-arch)))
5266      "unsigned char"
5267
5268 \1f
5269 File: gdb.info,  Node: Disassembly In Guile,  Next: I/O Ports in Guile,  Prev: Architectures In Guile,  Up: Guile API
5270
5271 23.3.3.22 Disassembly In Guile
5272 ..............................
5273
5274 The disassembler can be invoked from Scheme code.  Furthermore, the
5275 disassembler can take a Guile port as input, allowing one to disassemble
5276 from any source, and not just target memory.
5277
5278  -- Scheme Procedure: arch-disassemble arch start-pc [#:port port]
5279           [#:offset offset] [#:size size] [#:count count]
5280      Return a list of disassembled instructions starting from the memory
5281      address START-PC.
5282
5283      The optional argument PORT specifies the input port to read bytes
5284      from.  If PORT is '#f' then bytes are read from target memory.
5285
5286      The optional argument OFFSET specifies the address offset of the
5287      first byte in PORT.  This is useful, for example, when PORT
5288      specifies a 'bytevector' and you want the bytevector to be
5289      disassembled as if it came from that address.  The START-PC passed
5290      to the reader for PORT is offset by the same amount.
5291
5292      Example:
5293           (gdb) guile (use-modules (rnrs io ports))
5294           (gdb) guile (define pc (value->integer (parse-and-eval "$pc")))
5295           (gdb) guile (define mem (open-memory #:start pc))
5296           (gdb) guile (define bv (get-bytevector-n mem 10))
5297           (gdb) guile (define bv-port (open-bytevector-input-port bv))
5298           (gdb) guile (define arch (current-arch))
5299           (gdb) guile (arch-disassemble arch pc #:port bv-port #:offset pc)
5300           (((address . 4195516) (asm . "mov    $0x4005c8,%edi") (length . 5)))
5301
5302      The optional arguments SIZE and COUNT determine the number of
5303      instructions in the returned list.  If either SIZE or COUNT is
5304      specified as zero, then no instructions are disassembled and an
5305      empty list is returned.  If both the optional arguments SIZE and
5306      COUNT are specified, then a list of at most COUNT disassembled
5307      instructions whose start address falls in the closed memory address
5308      interval from START-PC to (START-PC + SIZE - 1) are returned.  If
5309      SIZE is not specified, but COUNT is specified, then COUNT number of
5310      instructions starting from the address START-PC are returned.  If
5311      COUNT is not specified but SIZE is specified, then all instructions
5312      whose start address falls in the closed memory address interval
5313      from START-PC to (START-PC + SIZE - 1) are returned.  If neither
5314      SIZE nor COUNT are specified, then a single instruction at START-PC
5315      is returned.
5316
5317      Each element of the returned list is an alist (associative list)
5318      with the following keys:
5319
5320      'address'
5321           The value corresponding to this key is a Guile integer of the
5322           memory address of the instruction.
5323
5324      'asm'
5325           The value corresponding to this key is a string value which
5326           represents the instruction with assembly language mnemonics.
5327           The assembly language flavor used is the same as that
5328           specified by the current CLI variable 'disassembly-flavor'.
5329           *Note Machine Code::.
5330
5331      'length'
5332           The value corresponding to this key is the length of the
5333           instruction in bytes.
5334
5335 \1f
5336 File: gdb.info,  Node: I/O Ports in Guile,  Next: Memory Ports in Guile,  Prev: Disassembly In Guile,  Up: Guile API
5337
5338 23.3.3.23 I/O Ports in Guile
5339 ............................
5340
5341  -- Scheme Procedure: input-port
5342      Return GDB's input port as a Guile port object.
5343
5344  -- Scheme Procedure: output-port
5345      Return GDB's output port as a Guile port object.
5346
5347  -- Scheme Procedure: error-port
5348      Return GDB's error port as a Guile port object.
5349
5350  -- Scheme Procedure: stdio-port? object
5351      Return '#t' if OBJECT is a GDB stdio port.  Otherwise return '#f'.
5352
5353 \1f
5354 File: gdb.info,  Node: Memory Ports in Guile,  Next: Iterators In Guile,  Prev: I/O Ports in Guile,  Up: Guile API
5355
5356 23.3.3.24 Memory Ports in Guile
5357 ...............................
5358
5359 GDB provides a 'port' interface to target memory.  This allows Guile
5360 code to read/write target memory using Guile's port and bytevector
5361 functionality.  The main routine is 'open-memory' which returns a port
5362 object.  One can then read/write memory using that object.
5363
5364  -- Scheme Procedure: open-memory [#:mode mode] [#:start address]
5365           [#:size size]
5366      Return a port object that can be used for reading and writing
5367      memory.  The port will be open according to MODE, which is the
5368      standard mode argument to Guile port open routines, except that it
5369      is restricted to one of '"r"', '"w"', or '"r+"'.  For compatibility
5370      '"b"' (binary) may also be present, but we ignore it: memory ports
5371      are binary only.  The default is '"r"', read-only.
5372
5373      The chunk of memory that can be accessed can be bounded.  If both
5374      START and SIZE are unspecified, all of memory can be accessed.  If
5375      only START is specified, all of memory from that point on can be
5376      accessed.  If only SIZE if specified, all memory in the range
5377      [0,SIZE) can be accessed.  If both are specified, all memory in the
5378      rane [START,START+SIZE) can be accessed.
5379
5380  -- Scheme Procedure: memory-port?
5381      Return '#t' if OBJECT is an object of type '<gdb:memory-port>'.
5382      Otherwise return '#f'.
5383
5384  -- Scheme Procedure: memory-port-range memory-port
5385      Return the range of '<gdb:memory-port>' MEMORY-PORT as a list of
5386      two elements: '(start end)'.  The range is START to END inclusive.
5387
5388  -- Scheme Procedure: memory-port-read-buffer-size memory-port
5389      Return the size of the read buffer of '<gdb:memory-port>'
5390      MEMORY-PORT.
5391
5392  -- Scheme Procedure: set-memory-port-read-buffer-size! memory-port size
5393      Set the size of the read buffer of '<gdb:memory-port>' MEMORY-PORT
5394      to SIZE.  The result is unspecified.
5395
5396  -- Scheme Procedure: memory-port-write-buffer-size memory-port
5397      Return the size of the write buffer of '<gdb:memory-port>'
5398      MEMORY-PORT.
5399
5400  -- Scheme Procedure: set-memory-port-write-buffer-size! memory-port
5401           size
5402      Set the size of the write buffer of '<gdb:memory-port>' MEMORY-PORT
5403      to SIZE.  The result is unspecified.
5404
5405    A memory port is closed like any other port, with 'close-port'.
5406
5407    Combined with Guile's 'bytevectors', memory ports provide a lot of
5408 utility.  For example, to fill a buffer of 10 integers in memory, one
5409 can do something like the following.
5410
5411      ;; In the program: int buffer[10];
5412      (use-modules (rnrs bytevectors))
5413      (use-modules (rnrs io ports))
5414      (define addr (parse-and-eval "buffer"))
5415      (define n 10)
5416      (define byte-size (* n 4))
5417      (define mem-port (open-memory #:mode "r+" #:start
5418                                    (value->integer addr) #:size byte-size))
5419      (define byte-vec (make-bytevector byte-size))
5420      (do ((i 0 (+ i 1)))
5421          ((>= i n))
5422          (bytevector-s32-native-set! byte-vec (* i 4) (* i 42)))
5423      (put-bytevector mem-port byte-vec)
5424      (close-port mem-port)
5425
5426 \1f
5427 File: gdb.info,  Node: Iterators In Guile,  Prev: Memory Ports in Guile,  Up: Guile API
5428
5429 23.3.3.25 Iterators In Guile
5430 ............................
5431
5432 A simple iterator facility is provided to allow, for example, iterating
5433 over the set of program symbols without having to first construct a list
5434 of all of them.  A useful contribution would be to add support for SRFI
5435 41 and SRFI 45.
5436
5437  -- Scheme Procedure: make-iterator object progress next!
5438      A '<gdb:iterator>' object is constructed with the 'make-iterator'
5439      procedure.  It takes three arguments: the object to be iterated
5440      over, an object to record the progress of the iteration, and a
5441      procedure to return the next element in the iteration, or an
5442      implementation chosen value to denote the end of iteration.
5443
5444      By convention, end of iteration is marked with
5445      '(end-of-iteration)', and may be tested with the
5446      'end-of-iteration?' predicate.  The result of '(end-of-iteration)'
5447      is chosen so that it is not otherwise used by the '(gdb)' module.
5448      If you are using '<gdb:iterator>' in your own code it is your
5449      responsibility to maintain this invariant.
5450
5451      A trivial example for illustration's sake:
5452
5453           (use-modules (gdb iterator))
5454           (define my-list (list 1 2 3))
5455           (define iter
5456             (make-iterator my-list my-list
5457                            (lambda (iter)
5458                              (let ((l (iterator-progress iter)))
5459                                (if (eq? l '())
5460                                    (end-of-iteration)
5461                                    (begin
5462                                      (set-iterator-progress! iter (cdr l))
5463                                      (car l)))))))
5464
5465      Here is a slightly more realistic example, which computes a list of
5466      all the functions in 'my-global-block'.
5467
5468           (use-modules (gdb iterator))
5469           (define this-sal (find-pc-line (frame-pc (selected-frame))))
5470           (define this-symtab (sal-symtab this-sal))
5471           (define this-global-block (symtab-global-block this-symtab))
5472           (define syms-iter (make-block-symbols-iterator this-global-block))
5473           (define functions (iterator-filter symbol-function? syms-iter))
5474
5475  -- Scheme Procedure: iterator? object
5476      Return '#t' if OBJECT is a '<gdb:iterator>' object.  Otherwise
5477      return '#f'.
5478
5479  -- Scheme Procedure: iterator-object iterator
5480      Return the first argument that was passed to 'make-iterator'.  This
5481      is the object being iterated over.
5482
5483  -- Scheme Procedure: iterator-progress iterator
5484      Return the object tracking iteration progress.
5485
5486  -- Scheme Procedure: set-iterator-progress! iterator new-value
5487      Set the object tracking iteration progress.
5488
5489  -- Scheme Procedure: iterator-next! iterator
5490      Invoke the procedure that was the third argument to
5491      'make-iterator', passing it one argument, the '<gdb:iterator>'
5492      object.  The result is either the next element in the iteration, or
5493      an end marker as implemented by the 'next!' procedure.  By
5494      convention the end marker is the result of '(end-of-iteration)'.
5495
5496  -- Scheme Procedure: end-of-iteration
5497      Return the Scheme object that denotes end of iteration.
5498
5499  -- Scheme Procedure: end-of-iteration? object
5500      Return '#t' if OBJECT is the end of iteration marker.  Otherwise
5501      return '#f'.
5502
5503    These functions are provided by the '(gdb iterator)' module to assist
5504 in using iterators.
5505
5506  -- Scheme Procedure: make-list-iterator list
5507      Return a '<gdb:iterator>' object that will iterate over LIST.
5508
5509  -- Scheme Procedure: iterator->list iterator
5510      Return the elements pointed to by ITERATOR as a list.
5511
5512  -- Scheme Procedure: iterator-map proc iterator
5513      Return the list of objects obtained by applying PROC to the object
5514      pointed to by ITERATOR and to each subsequent object.
5515
5516  -- Scheme Procedure: iterator-for-each proc iterator
5517      Apply PROC to each element pointed to by ITERATOR.  The result is
5518      unspecified.
5519
5520  -- Scheme Procedure: iterator-filter pred iterator
5521      Return the list of elements pointed to by ITERATOR that satisfy
5522      PRED.
5523
5524  -- Scheme Procedure: iterator-until pred iterator
5525      Run ITERATOR until the result of '(pred element)' is true and
5526      return that as the result.  Otherwise return '#f'.
5527
5528 \1f
5529 File: gdb.info,  Node: Guile Auto-loading,  Next: Guile Modules,  Prev: Guile API,  Up: Guile
5530
5531 23.3.4 Guile Auto-loading
5532 -------------------------
5533
5534 When a new object file is read (for example, due to the 'file' command,
5535 or because the inferior has loaded a shared library), GDB will look for
5536 Guile support scripts in two ways: 'OBJFILE-gdb.scm' and the
5537 '.debug_gdb_scripts' section.  *Note Auto-loading extensions::.
5538
5539    The auto-loading feature is useful for supplying application-specific
5540 debugging commands and scripts.
5541
5542    Auto-loading can be enabled or disabled, and the list of auto-loaded
5543 scripts can be printed.
5544
5545 'set auto-load guile-scripts [on|off]'
5546      Enable or disable the auto-loading of Guile scripts.
5547
5548 'show auto-load guile-scripts'
5549      Show whether auto-loading of Guile scripts is enabled or disabled.
5550
5551 'info auto-load guile-scripts [REGEXP]'
5552      Print the list of all Guile scripts that GDB auto-loaded.
5553
5554      Also printed is the list of Guile scripts that were mentioned in
5555      the '.debug_gdb_scripts' section and were not found.  This is
5556      useful because their names are not printed when GDB tries to load
5557      them and fails.  There may be many of them, and printing an error
5558      message for each one is problematic.
5559
5560      If REGEXP is supplied only Guile scripts with matching names are
5561      printed.
5562
5563      Example:
5564
5565           (gdb) info auto-load guile-scripts
5566           Loaded Script
5567           Yes    scm-section-script.scm
5568                  full name: /tmp/scm-section-script.scm
5569           No     my-foo-pretty-printers.scm
5570
5571    When reading an auto-loaded file, GDB sets the "current objfile".
5572 This is available via the 'current-objfile' procedure (*note Objfiles In
5573 Guile::).  This can be useful for registering objfile-specific
5574 pretty-printers.
5575
5576 \1f
5577 File: gdb.info,  Node: Guile Modules,  Prev: Guile Auto-loading,  Up: Guile
5578
5579 23.3.5 Guile Modules
5580 --------------------
5581
5582 GDB comes with several modules to assist writing Guile code.
5583
5584 * Menu:
5585
5586 * Guile Printing Module::  Building and registering pretty-printers
5587 * Guile Types Module::     Utilities for working with types
5588
5589 \1f
5590 File: gdb.info,  Node: Guile Printing Module,  Next: Guile Types Module,  Up: Guile Modules
5591
5592 23.3.5.1 Guile Printing Module
5593 ..............................
5594
5595 This module provides a collection of utilities for working with
5596 pretty-printers.
5597
5598    Usage:
5599
5600      (use-modules (gdb printing))
5601
5602  -- Scheme Procedure: prepend-pretty-printer! object printer
5603      Add PRINTER to the front of the list of pretty-printers for OBJECT.
5604      The OBJECT must either be a '<gdb:objfile>' object, or '#f' in
5605      which case PRINTER is added to the global list of printers.
5606
5607  -- Scheme Procecure: append-pretty-printer! object printer
5608      Add PRINTER to the end of the list of pretty-printers for OBJECT.
5609      The OBJECT must either be a '<gdb:objfile>' object, or '#f' in
5610      which case PRINTER is added to the global list of printers.
5611
5612 \1f
5613 File: gdb.info,  Node: Guile Types Module,  Prev: Guile Printing Module,  Up: Guile Modules
5614
5615 23.3.5.2 Guile Types Module
5616 ...........................
5617
5618 This module provides a collection of utilities for working with
5619 '<gdb:type>' objects.
5620
5621    Usage:
5622
5623      (use-modules (gdb types))
5624
5625  -- Scheme Procedure: get-basic-type type
5626      Return TYPE with const and volatile qualifiers stripped, and with
5627      typedefs and C++ references converted to the underlying type.
5628
5629      C++ example:
5630
5631           typedef const int const_int;
5632           const_int foo (3);
5633           const_int& foo_ref (foo);
5634           int main () { return 0; }
5635
5636      Then in gdb:
5637
5638           (gdb) start
5639           (gdb) guile (use-modules (gdb) (gdb types))
5640           (gdb) guile (define foo-ref (parse-and-eval "foo_ref"))
5641           (gdb) guile (get-basic-type (value-type foo-ref))
5642           int
5643
5644  -- Scheme Procedure: type-has-field-deep? type field
5645      Return '#t' if TYPE, assumed to be a type with fields (e.g., a
5646      structure or union), has field FIELD.  Otherwise return '#f'.  This
5647      searches baseclasses, whereas 'type-has-field?' does not.
5648
5649  -- Scheme Procedure: make-enum-hashtable enum-type
5650      Return a Guile hash table produced from ENUM-TYPE.  Elements in the
5651      hash table are referenced with 'hashq-ref'.
5652
5653 \1f
5654 File: gdb.info,  Node: Auto-loading extensions,  Next: Multiple Extension Languages,  Prev: Guile,  Up: Extending GDB
5655
5656 23.4 Auto-loading extensions
5657 ============================
5658
5659 GDB provides two mechanisms for automatically loading extensions when a
5660 new object file is read (for example, due to the 'file' command, or
5661 because the inferior has loaded a shared library): 'OBJFILE-gdb.EXT' and
5662 the '.debug_gdb_scripts' section of modern file formats like ELF.
5663
5664 * Menu:
5665
5666 * objfile-gdb.ext file: objfile-gdbdotext file.  The 'OBJFILE-gdb.EXT' file
5667 * .debug_gdb_scripts section: dotdebug_gdb_scripts section.  The '.debug_gdb_scripts' section
5668 * Which flavor to choose?::
5669
5670    The auto-loading feature is useful for supplying application-specific
5671 debugging commands and features.
5672
5673    Auto-loading can be enabled or disabled, and the list of auto-loaded
5674 scripts can be printed.  See the 'auto-loading' section of each
5675 extension language for more information.  For GDB command files see
5676 *note Auto-loading sequences::.  For Python files see *note Python
5677 Auto-loading::.
5678
5679    Note that loading of this script file also requires accordingly
5680 configured 'auto-load safe-path' (*note Auto-loading safe path::).
5681
5682 \1f
5683 File: gdb.info,  Node: objfile-gdbdotext file,  Next: dotdebug_gdb_scripts section,  Up: Auto-loading extensions
5684
5685 23.4.1 The 'OBJFILE-gdb.EXT' file
5686 ---------------------------------
5687
5688 When a new object file is read, GDB looks for a file named
5689 'OBJFILE-gdb.EXT' (we call it SCRIPT-NAME below), where OBJFILE is the
5690 object file's name and where EXT is the file extension for the extension
5691 language:
5692
5693 'OBJFILE-gdb.gdb'
5694      GDB's own command language
5695 'OBJFILE-gdb.py'
5696      Python
5697 'OBJFILE-gdb.scm'
5698      Guile
5699
5700    SCRIPT-NAME is formed by ensuring that the file name of OBJFILE is
5701 absolute, following all symlinks, and resolving '.' and '..' components,
5702 and appending the '-gdb.EXT' suffix.  If this file exists and is
5703 readable, GDB will evaluate it as a script in the specified extension
5704 language.
5705
5706    If this file does not exist, then GDB will look for SCRIPT-NAME file
5707 in all of the directories as specified below.
5708
5709    Note that loading of these files requires an accordingly configured
5710 'auto-load safe-path' (*note Auto-loading safe path::).
5711
5712    For object files using '.exe' suffix GDB tries to load first the
5713 scripts normally according to its '.exe' filename.  But if no scripts
5714 are found GDB also tries script filenames matching the object file
5715 without its '.exe' suffix.  This '.exe' stripping is case insensitive
5716 and it is attempted on any platform.  This makes the script filenames
5717 compatible between Unix and MS-Windows hosts.
5718
5719 'set auto-load scripts-directory [DIRECTORIES]'
5720      Control GDB auto-loaded scripts location.  Multiple directory
5721      entries may be delimited by the host platform path separator in use
5722      (':' on Unix, ';' on MS-Windows and MS-DOS).
5723
5724      Each entry here needs to be covered also by the security setting
5725      'set auto-load safe-path' (*note set auto-load safe-path::).
5726
5727      This variable defaults to '$debugdir:$datadir/auto-load'.  The
5728      default 'set auto-load safe-path' value can be also overriden by
5729      GDB configuration option '--with-auto-load-dir'.
5730
5731      Any reference to '$debugdir' will get replaced by
5732      DEBUG-FILE-DIRECTORY value (*note Separate Debug Files::) and any
5733      reference to '$datadir' will get replaced by DATA-DIRECTORY which
5734      is determined at GDB startup (*note Data Files::).  '$debugdir' and
5735      '$datadir' must be placed as a directory component -- either alone
5736      or delimited by '/' or '\' directory separators, depending on the
5737      host platform.
5738
5739      The list of directories uses path separator (':' on GNU and Unix
5740      systems, ';' on MS-Windows and MS-DOS) to separate directories,
5741      similarly to the 'PATH' environment variable.
5742
5743 'show auto-load scripts-directory'
5744      Show GDB auto-loaded scripts location.
5745
5746    GDB does not track which files it has already auto-loaded this way.
5747 GDB will load the associated script every time the corresponding OBJFILE
5748 is opened.  So your '-gdb.EXT' file should be careful to avoid errors if
5749 it is evaluated more than once.
5750
5751 \1f
5752 File: gdb.info,  Node: dotdebug_gdb_scripts section,  Next: Which flavor to choose?,  Prev: objfile-gdbdotext file,  Up: Auto-loading extensions
5753
5754 23.4.2 The '.debug_gdb_scripts' section
5755 ---------------------------------------
5756
5757 For systems using file formats like ELF and COFF, when GDB loads a new
5758 object file it will look for a special section named
5759 '.debug_gdb_scripts'.  If this section exists, its contents is a list of
5760 NUL-terminated names of scripts to load.  Each entry begins with a
5761 non-NULL prefix byte that specifies the kind of entry, typically the
5762 extension language.
5763
5764    GDB will look for each specified script file first in the current
5765 directory and then along the source search path (*note Specifying Source
5766 Directories: Source Path.), except that '$cdir' is not searched, since
5767 the compilation directory is not relevant to scripts.
5768
5769    Entries can be placed in section '.debug_gdb_scripts' with, for
5770 example, this GCC macro for Python scripts.
5771
5772      /* Note: The "MS" section flags are to remove duplicates.  */
5773      #define DEFINE_GDB_PY_SCRIPT(script_name) \
5774        asm("\
5775      .pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n\
5776      .byte 1 /* Python */\n\
5777      .asciz \"" script_name "\"\n\
5778      .popsection \n\
5779      ");
5780
5781 For Guile scripts, replace '.byte 1' with '.byte 3'.  Then one can
5782 reference the macro in a header or source file like this:
5783
5784      DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
5785
5786    The script name may include directories if desired.
5787
5788    Note that loading of this script file also requires accordingly
5789 configured 'auto-load safe-path' (*note Auto-loading safe path::).
5790
5791    If the macro invocation is put in a header, any application or
5792 library using this header will get a reference to the specified script,
5793 and with the use of '"MS"' attributes on the section, the linker will
5794 remove duplicates.
5795
5796 \1f
5797 File: gdb.info,  Node: Which flavor to choose?,  Prev: dotdebug_gdb_scripts section,  Up: Auto-loading extensions
5798
5799 23.4.3 Which flavor to choose?
5800 ------------------------------
5801
5802 Given the multiple ways of auto-loading extensions, it might not always
5803 be clear which one to choose.  This section provides some guidance.
5804
5805 Benefits of the '-gdb.EXT' way:
5806
5807    * Can be used with file formats that don't support multiple sections.
5808
5809    * Ease of finding scripts for public libraries.
5810
5811      Scripts specified in the '.debug_gdb_scripts' section are searched
5812      for in the source search path.  For publicly installed libraries,
5813      e.g., 'libstdc++', there typically isn't a source directory in
5814      which to find the script.
5815
5816    * Doesn't require source code additions.
5817
5818 Benefits of the '.debug_gdb_scripts' way:
5819
5820    * Works with static linking.
5821
5822      Scripts for libraries done the '-gdb.EXT' way require an objfile to
5823      trigger their loading.  When an application is statically linked
5824      the only objfile available is the executable, and it is cumbersome
5825      to attach all the scripts from all the input libraries to the
5826      executable's '-gdb.EXT' script.
5827
5828    * Works with classes that are entirely inlined.
5829
5830      Some classes can be entirely inlined, and thus there may not be an
5831      associated shared library to attach a '-gdb.EXT' script to.
5832
5833    * Scripts needn't be copied out of the source tree.
5834
5835      In some circumstances, apps can be built out of large collections
5836      of internal libraries, and the build infrastructure necessary to
5837      install the '-gdb.EXT' scripts in a place where GDB can find them
5838      is cumbersome.  It may be easier to specify the scripts in the
5839      '.debug_gdb_scripts' section as relative paths, and add a path to
5840      the top of the source tree to the source search path.
5841
5842 \1f
5843 File: gdb.info,  Node: Multiple Extension Languages,  Next: Aliases,  Prev: Auto-loading extensions,  Up: Extending GDB
5844
5845 23.5 Multiple Extension Languages
5846 =================================
5847
5848 The Guile and Python extension languages do not share any state, and
5849 generally do not interfere with each other.  There are some things to be
5850 aware of, however.
5851
5852 23.5.1 Python comes first
5853 -------------------------
5854
5855 Python was GDB's first extension language, and to avoid breaking
5856 existing behaviour Python comes first.  This is generally solved by the
5857 "first one wins" principle.  GDB maintains a list of enabled extension
5858 languages, and when it makes a call to an extension language, (say to
5859 pretty-print a value), it tries each in turn until an extension language
5860 indicates it has performed the request (e.g., has returned the
5861 pretty-printed form of a value).  This extends to errors while
5862 performing such requests: If an error happens while, for example, trying
5863 to pretty-print an object then the error is reported and any following
5864 extension languages are not tried.
5865
5866 \1f
5867 File: gdb.info,  Node: Aliases,  Prev: Multiple Extension Languages,  Up: Extending GDB
5868
5869 23.6 Creating new spellings of existing commands
5870 ================================================
5871
5872 It is often useful to define alternate spellings of existing commands.
5873 For example, if a new GDB command defined in Python has a long name to
5874 type, it is handy to have an abbreviated version of it that involves
5875 less typing.
5876
5877    GDB itself uses aliases.  For example 's' is an alias of the 'step'
5878 command even though it is otherwise an ambiguous abbreviation of other
5879 commands like 'set' and 'show'.
5880
5881    Aliases are also used to provide shortened or more common versions of
5882 multi-word commands.  For example, GDB provides the 'tty' alias of the
5883 'set inferior-tty' command.
5884
5885    You can define a new alias with the 'alias' command.
5886
5887 'alias [-a] [--] ALIAS = COMMAND'
5888
5889    ALIAS specifies the name of the new alias.  Each word of ALIAS must
5890 consist of letters, numbers, dashes and underscores.
5891
5892    COMMAND specifies the name of an existing command that is being
5893 aliased.
5894
5895    The '-a' option specifies that the new alias is an abbreviation of
5896 the command.  Abbreviations are not shown in command lists displayed by
5897 the 'help' command.
5898
5899    The '--' option specifies the end of options, and is useful when
5900 ALIAS begins with a dash.
5901
5902    Here is a simple example showing how to make an abbreviation of a
5903 command so that there is less to type.  Suppose you were tired of typing
5904 'disas', the current shortest unambiguous abbreviation of the
5905 'disassemble' command and you wanted an even shorter version named 'di'.
5906 The following will accomplish this.
5907
5908      (gdb) alias -a di = disas
5909
5910    Note that aliases are different from user-defined commands.  With a
5911 user-defined command, you also need to write documentation for it with
5912 the 'document' command.  An alias automatically picks up the
5913 documentation of the existing command.
5914
5915    Here is an example where we make 'elms' an abbreviation of 'elements'
5916 in the 'set print elements' command.  This is to show that you can make
5917 an abbreviation of any part of a command.
5918
5919      (gdb) alias -a set print elms = set print elements
5920      (gdb) alias -a show print elms = show print elements
5921      (gdb) set p elms 20
5922      (gdb) show p elms
5923      Limit on string chars or array elements to print is 200.
5924
5925    Note that if you are defining an alias of a 'set' command, and you
5926 want to have an alias for the corresponding 'show' command, then you
5927 need to define the latter separately.
5928
5929    Unambiguously abbreviated commands are allowed in COMMAND and ALIAS,
5930 just as they are normally.
5931
5932      (gdb) alias -a set pr elms = set p ele
5933
5934    Finally, here is an example showing the creation of a one word alias
5935 for a more complex command.  This creates alias 'spe' of the command
5936 'set print elements'.
5937
5938      (gdb) alias spe = set print elements
5939      (gdb) spe 20
5940
5941 \1f
5942 File: gdb.info,  Node: Interpreters,  Next: TUI,  Prev: Extending GDB,  Up: Top
5943
5944 24 Command Interpreters
5945 ***********************
5946
5947 GDB supports multiple command interpreters, and some command
5948 infrastructure to allow users or user interface writers to switch
5949 between interpreters or run commands in other interpreters.
5950
5951    GDB currently supports two command interpreters, the console
5952 interpreter (sometimes called the command-line interpreter or CLI) and
5953 the machine interface interpreter (or GDB/MI).  This manual describes
5954 both of these interfaces in great detail.
5955
5956    By default, GDB will start with the console interpreter.  However,
5957 the user may choose to start GDB with another interpreter by specifying
5958 the '-i' or '--interpreter' startup options.  Defined interpreters
5959 include:
5960
5961 'console'
5962      The traditional console or command-line interpreter.  This is the
5963      most often used interpreter with GDB.  With no interpreter
5964      specified at runtime, GDB will use this interpreter.
5965
5966 'mi'
5967      The newest GDB/MI interface (currently 'mi2').  Used primarily by
5968      programs wishing to use GDB as a backend for a debugger GUI or an
5969      IDE. For more information, see *note The GDB/MI Interface: GDB/MI.
5970
5971 'mi2'
5972      The current GDB/MI interface.
5973
5974 'mi1'
5975      The GDB/MI interface included in GDB 5.1, 5.2, and 5.3.
5976
5977    The interpreter being used by GDB may not be dynamically switched at
5978 runtime.  Although possible, this could lead to a very precarious
5979 situation.  Consider an IDE using GDB/MI.  If a user enters the command
5980 "interpreter-set console" in a console view, GDB would switch to using
5981 the console interpreter, rendering the IDE inoperable!
5982
5983    Although you may only choose a single interpreter at startup, you may
5984 execute commands in any interpreter from the current interpreter using
5985 the appropriate command.  If you are running the console interpreter,
5986 simply use the 'interpreter-exec' command:
5987
5988      interpreter-exec mi "-data-list-register-names"
5989
5990    GDB/MI has a similar command, although it is only available in
5991 versions of GDB which support GDB/MI version 2 (or greater).
5992
5993 \1f
5994 File: gdb.info,  Node: TUI,  Next: Emacs,  Prev: Interpreters,  Up: Top
5995
5996 25 GDB Text User Interface
5997 **************************
5998
5999 * Menu:
6000
6001 * TUI Overview::                TUI overview
6002 * TUI Keys::                    TUI key bindings
6003 * TUI Single Key Mode::         TUI single key mode
6004 * TUI Commands::                TUI-specific commands
6005 * TUI Configuration::           TUI configuration variables
6006
6007 The GDB Text User Interface (TUI) is a terminal interface which uses the
6008 'curses' library to show the source file, the assembly output, the
6009 program registers and GDB commands in separate text windows.  The TUI
6010 mode is supported only on platforms where a suitable version of the
6011 'curses' library is available.
6012
6013    The TUI mode is enabled by default when you invoke GDB as 'gdb -tui'.
6014 You can also switch in and out of TUI mode while GDB runs by using
6015 various TUI commands and key bindings, such as 'C-x C-a'.  *Note TUI Key
6016 Bindings: TUI Keys.
6017
6018 \1f
6019 File: gdb.info,  Node: TUI Overview,  Next: TUI Keys,  Up: TUI
6020
6021 25.1 TUI Overview
6022 =================
6023
6024 In TUI mode, GDB can display several text windows:
6025
6026 _command_
6027      This window is the GDB command window with the GDB prompt and the
6028      GDB output.  The GDB input is still managed using readline.
6029
6030 _source_
6031      The source window shows the source file of the program.  The
6032      current line and active breakpoints are displayed in this window.
6033
6034 _assembly_
6035      The assembly window shows the disassembly output of the program.
6036
6037 _register_
6038      This window shows the processor registers.  Registers are
6039      highlighted when their values change.
6040
6041    The source and assembly windows show the current program position by
6042 highlighting the current line and marking it with a '>' marker.
6043 Breakpoints are indicated with two markers.  The first marker indicates
6044 the breakpoint type:
6045
6046 'B'
6047      Breakpoint which was hit at least once.
6048
6049 'b'
6050      Breakpoint which was never hit.
6051
6052 'H'
6053      Hardware breakpoint which was hit at least once.
6054
6055 'h'
6056      Hardware breakpoint which was never hit.
6057
6058    The second marker indicates whether the breakpoint is enabled or not:
6059
6060 '+'
6061      Breakpoint is enabled.
6062
6063 '-'
6064      Breakpoint is disabled.
6065
6066    The source, assembly and register windows are updated when the
6067 current thread changes, when the frame changes, or when the program
6068 counter changes.
6069
6070    These windows are not all visible at the same time.  The command
6071 window is always visible.  The others can be arranged in several
6072 layouts:
6073
6074    * source only,
6075
6076    * assembly only,
6077
6078    * source and assembly,
6079
6080    * source and registers, or
6081
6082    * assembly and registers.
6083
6084    A status line above the command window shows the following
6085 information:
6086
6087 _target_
6088      Indicates the current GDB target.  (*note Specifying a Debugging
6089      Target: Targets.).
6090
6091 _process_
6092      Gives the current process or thread number.  When no process is
6093      being debugged, this field is set to 'No process'.
6094
6095 _function_
6096      Gives the current function name for the selected frame.  The name
6097      is demangled if demangling is turned on (*note Print Settings::).
6098      When there is no symbol corresponding to the current program
6099      counter, the string '??' is displayed.
6100
6101 _line_
6102      Indicates the current line number for the selected frame.  When the
6103      current line number is not known, the string '??' is displayed.
6104
6105 _pc_
6106      Indicates the current program counter address.
6107
6108 \1f
6109 File: gdb.info,  Node: TUI Keys,  Next: TUI Single Key Mode,  Prev: TUI Overview,  Up: TUI
6110
6111 25.2 TUI Key Bindings
6112 =====================
6113
6114 The TUI installs several key bindings in the readline keymaps (*note
6115 Command Line Editing::).  The following key bindings are installed for
6116 both TUI mode and the GDB standard mode.
6117
6118 'C-x C-a'
6119 'C-x a'
6120 'C-x A'
6121      Enter or leave the TUI mode.  When leaving the TUI mode, the curses
6122      window management stops and GDB operates using its standard mode,
6123      writing on the terminal directly.  When reentering the TUI mode,
6124      control is given back to the curses windows.  The screen is then
6125      refreshed.
6126
6127 'C-x 1'
6128      Use a TUI layout with only one window.  The layout will either be
6129      'source' or 'assembly'.  When the TUI mode is not active, it will
6130      switch to the TUI mode.
6131
6132      Think of this key binding as the Emacs 'C-x 1' binding.
6133
6134 'C-x 2'
6135      Use a TUI layout with at least two windows.  When the current
6136      layout already has two windows, the next layout with two windows is
6137      used.  When a new layout is chosen, one window will always be
6138      common to the previous layout and the new one.
6139
6140      Think of it as the Emacs 'C-x 2' binding.
6141
6142 'C-x o'
6143      Change the active window.  The TUI associates several key bindings
6144      (like scrolling and arrow keys) with the active window.  This
6145      command gives the focus to the next TUI window.
6146
6147      Think of it as the Emacs 'C-x o' binding.
6148
6149 'C-x s'
6150      Switch in and out of the TUI SingleKey mode that binds single keys
6151      to GDB commands (*note TUI Single Key Mode::).
6152
6153    The following key bindings only work in the TUI mode:
6154
6155 <PgUp>
6156      Scroll the active window one page up.
6157
6158 <PgDn>
6159      Scroll the active window one page down.
6160
6161 <Up>
6162      Scroll the active window one line up.
6163
6164 <Down>
6165      Scroll the active window one line down.
6166
6167 <Left>
6168      Scroll the active window one column left.
6169
6170 <Right>
6171      Scroll the active window one column right.
6172
6173 'C-L'
6174      Refresh the screen.
6175
6176    Because the arrow keys scroll the active window in the TUI mode, they
6177 are not available for their normal use by readline unless the command
6178 window has the focus.  When another window is active, you must use other
6179 readline key bindings such as 'C-p', 'C-n', 'C-b' and 'C-f' to control
6180 the command window.
6181
6182 \1f
6183 File: gdb.info,  Node: TUI Single Key Mode,  Next: TUI Commands,  Prev: TUI Keys,  Up: TUI
6184
6185 25.3 TUI Single Key Mode
6186 ========================
6187
6188 The TUI also provides a "SingleKey" mode, which binds several frequently
6189 used GDB commands to single keys.  Type 'C-x s' to switch into this
6190 mode, where the following key bindings are used:
6191
6192 'c'
6193      continue
6194
6195 'd'
6196      down
6197
6198 'f'
6199      finish
6200
6201 'n'
6202      next
6203
6204 'q'
6205      exit the SingleKey mode.
6206
6207 'r'
6208      run
6209
6210 's'
6211      step
6212
6213 'u'
6214      up
6215
6216 'v'
6217      info locals
6218
6219 'w'
6220      where
6221
6222    Other keys temporarily switch to the GDB command prompt.  The key
6223 that was pressed is inserted in the editing buffer so that it is
6224 possible to type most GDB commands without interaction with the TUI
6225 SingleKey mode.  Once the command is entered the TUI SingleKey mode is
6226 restored.  The only way to permanently leave this mode is by typing 'q'
6227 or 'C-x s'.
6228
6229 \1f
6230 File: gdb.info,  Node: TUI Commands,  Next: TUI Configuration,  Prev: TUI Single Key Mode,  Up: TUI
6231
6232 25.4 TUI-specific Commands
6233 ==========================
6234
6235 The TUI has specific commands to control the text windows.  These
6236 commands are always available, even when GDB is not in the TUI mode.
6237 When GDB is in the standard mode, most of these commands will
6238 automatically switch to the TUI mode.
6239
6240    Note that if GDB's 'stdout' is not connected to a terminal, or GDB
6241 has been started with the machine interface interpreter (*note The
6242 GDB/MI Interface: GDB/MI.), most of these commands will fail with an
6243 error, because it would not be possible or desirable to enable curses
6244 window management.
6245
6246 'info win'
6247      List and give the size of all displayed windows.
6248
6249 'layout next'
6250      Display the next layout.
6251
6252 'layout prev'
6253      Display the previous layout.
6254
6255 'layout src'
6256      Display the source window only.
6257
6258 'layout asm'
6259      Display the assembly window only.
6260
6261 'layout split'
6262      Display the source and assembly window.
6263
6264 'layout regs'
6265      Display the register window together with the source or assembly
6266      window.
6267
6268 'focus next'
6269      Make the next window active for scrolling.
6270
6271 'focus prev'
6272      Make the previous window active for scrolling.
6273
6274 'focus src'
6275      Make the source window active for scrolling.
6276
6277 'focus asm'
6278      Make the assembly window active for scrolling.
6279
6280 'focus regs'
6281      Make the register window active for scrolling.
6282
6283 'focus cmd'
6284      Make the command window active for scrolling.
6285
6286 'refresh'
6287      Refresh the screen.  This is similar to typing 'C-L'.
6288
6289 'tui reg float'
6290      Show the floating point registers in the register window.
6291
6292 'tui reg general'
6293      Show the general registers in the register window.
6294
6295 'tui reg next'
6296      Show the next register group.  The list of register groups as well
6297      as their order is target specific.  The predefined register groups
6298      are the following: 'general', 'float', 'system', 'vector', 'all',
6299      'save', 'restore'.
6300
6301 'tui reg system'
6302      Show the system registers in the register window.
6303
6304 'update'
6305      Update the source window and the current execution point.
6306
6307 'winheight NAME +COUNT'
6308 'winheight NAME -COUNT'
6309      Change the height of the window NAME by COUNT lines.  Positive
6310      counts increase the height, while negative counts decrease it.
6311
6312 'tabset NCHARS'
6313      Set the width of tab stops to be NCHARS characters.
6314
6315 \1f
6316 File: gdb.info,  Node: TUI Configuration,  Prev: TUI Commands,  Up: TUI
6317
6318 25.5 TUI Configuration Variables
6319 ================================
6320
6321 Several configuration variables control the appearance of TUI windows.
6322
6323 'set tui border-kind KIND'
6324      Select the border appearance for the source, assembly and register
6325      windows.  The possible values are the following:
6326      'space'
6327           Use a space character to draw the border.
6328
6329      'ascii'
6330           Use ASCII characters '+', '-' and '|' to draw the border.
6331
6332      'acs'
6333           Use the Alternate Character Set to draw the border.  The
6334           border is drawn using character line graphics if the terminal
6335           supports them.
6336
6337 'set tui border-mode MODE'
6338 'set tui active-border-mode MODE'
6339      Select the display attributes for the borders of the inactive
6340      windows or the active window.  The MODE can be one of the
6341      following:
6342      'normal'
6343           Use normal attributes to display the border.
6344
6345      'standout'
6346           Use standout mode.
6347
6348      'reverse'
6349           Use reverse video mode.
6350
6351      'half'
6352           Use half bright mode.
6353
6354      'half-standout'
6355           Use half bright and standout mode.
6356
6357      'bold'
6358           Use extra bright or bold mode.
6359
6360      'bold-standout'
6361           Use extra bright or bold and standout mode.
6362
6363 \1f
6364 File: gdb.info,  Node: Emacs,  Next: GDB/MI,  Prev: TUI,  Up: Top
6365
6366 26 Using GDB under GNU Emacs
6367 ****************************
6368
6369 A special interface allows you to use GNU Emacs to view (and edit) the
6370 source files for the program you are debugging with GDB.
6371
6372    To use this interface, use the command 'M-x gdb' in Emacs.  Give the
6373 executable file you want to debug as an argument.  This command starts
6374 GDB as a subprocess of Emacs, with input and output through a newly
6375 created Emacs buffer.
6376
6377    Running GDB under Emacs can be just like running GDB normally except
6378 for two things:
6379
6380    * All "terminal" input and output goes through an Emacs buffer,
6381      called the GUD buffer.
6382
6383      This applies both to GDB commands and their output, and to the
6384      input and output done by the program you are debugging.
6385
6386      This is useful because it means that you can copy the text of
6387      previous commands and input them again; you can even use parts of
6388      the output in this way.
6389
6390      All the facilities of Emacs' Shell mode are available for
6391      interacting with your program.  In particular, you can send signals
6392      the usual way--for example, 'C-c C-c' for an interrupt, 'C-c C-z'
6393      for a stop.
6394
6395    * GDB displays source code through Emacs.
6396
6397      Each time GDB displays a stack frame, Emacs automatically finds the
6398      source file for that frame and puts an arrow ('=>') at the left
6399      margin of the current line.  Emacs uses a separate buffer for
6400      source display, and splits the screen to show both your GDB session
6401      and the source.
6402
6403      Explicit GDB 'list' or search commands still produce output as
6404      usual, but you probably have no reason to use them from Emacs.
6405
6406    We call this "text command mode".  Emacs 22.1, and later, also uses a
6407 graphical mode, enabled by default, which provides further buffers that
6408 can control the execution and describe the state of your program.  *Note
6409 (Emacs)GDB Graphical Interface::.
6410
6411    If you specify an absolute file name when prompted for the 'M-x gdb'
6412 argument, then Emacs sets your current working directory to where your
6413 program resides.  If you only specify the file name, then Emacs sets
6414 your current working directory to the directory associated with the
6415 previous buffer.  In this case, GDB may find your program by searching
6416 your environment's 'PATH' variable, but on some operating systems it
6417 might not find the source.  So, although the GDB input and output
6418 session proceeds normally, the auxiliary buffer does not display the
6419 current source and line of execution.
6420
6421    The initial working directory of GDB is printed on the top line of
6422 the GUD buffer and this serves as a default for the commands that
6423 specify files for GDB to operate on.  *Note Commands to Specify Files:
6424 Files.
6425
6426    By default, 'M-x gdb' calls the program called 'gdb'.  If you need to
6427 call GDB by a different name (for example, if you keep several
6428 configurations around, with different names) you can customize the Emacs
6429 variable 'gud-gdb-command-name' to run the one you want.
6430
6431    In the GUD buffer, you can use these special Emacs commands in
6432 addition to the standard Shell mode commands:
6433
6434 'C-h m'
6435      Describe the features of Emacs' GUD Mode.
6436
6437 'C-c C-s'
6438      Execute to another source line, like the GDB 'step' command; also
6439      update the display window to show the current file and location.
6440
6441 'C-c C-n'
6442      Execute to next source line in this function, skipping all function
6443      calls, like the GDB 'next' command.  Then update the display window
6444      to show the current file and location.
6445
6446 'C-c C-i'
6447      Execute one instruction, like the GDB 'stepi' command; update
6448      display window accordingly.
6449
6450 'C-c C-f'
6451      Execute until exit from the selected stack frame, like the GDB
6452      'finish' command.
6453
6454 'C-c C-r'
6455      Continue execution of your program, like the GDB 'continue'
6456      command.
6457
6458 'C-c <'
6459      Go up the number of frames indicated by the numeric argument (*note
6460      Numeric Arguments: (Emacs)Arguments.), like the GDB 'up' command.
6461
6462 'C-c >'
6463      Go down the number of frames indicated by the numeric argument,
6464      like the GDB 'down' command.
6465
6466    In any source file, the Emacs command 'C-x <SPC>' ('gud-break') tells
6467 GDB to set a breakpoint on the source line point is on.
6468
6469    In text command mode, if you type 'M-x speedbar', Emacs displays a
6470 separate frame which shows a backtrace when the GUD buffer is current.
6471 Move point to any frame in the stack and type <RET> to make it become
6472 the current frame and display the associated source in the source
6473 buffer.  Alternatively, click 'Mouse-2' to make the selected frame
6474 become the current one.  In graphical mode, the speedbar displays watch
6475 expressions.
6476
6477    If you accidentally delete the source-display buffer, an easy way to
6478 get it back is to type the command 'f' in the GDB buffer, to request a
6479 frame display; when you run under Emacs, this recreates the source
6480 buffer if necessary to show you the context of the current frame.
6481
6482    The source files displayed in Emacs are in ordinary Emacs buffers
6483 which are visiting the source files in the usual way.  You can edit the
6484 files with these buffers if you wish; but keep in mind that GDB
6485 communicates with Emacs in terms of line numbers.  If you add or delete
6486 lines from the text, the line numbers that GDB knows cease to correspond
6487 properly with the code.
6488
6489    A more detailed description of Emacs' interaction with GDB is given
6490 in the Emacs manual (*note (Emacs)Debuggers::).
6491
6492 \1f
6493 File: gdb.info,  Node: GDB/MI,  Next: Annotations,  Prev: Emacs,  Up: Top
6494
6495 27 The GDB/MI Interface
6496 ***********************
6497
6498 Function and Purpose
6499 ====================
6500
6501 GDB/MI is a line based machine oriented text interface to GDB and is
6502 activated by specifying using the '--interpreter' command line option
6503 (*note Mode Options::).  It is specifically intended to support the
6504 development of systems which use the debugger as just one small
6505 component of a larger system.
6506
6507    This chapter is a specification of the GDB/MI interface.  It is
6508 written in the form of a reference manual.
6509
6510    Note that GDB/MI is still under construction, so some of the features
6511 described below are incomplete and subject to change (*note GDB/MI
6512 Development and Front Ends: GDB/MI Development and Front Ends.).
6513
6514 Notation and Terminology
6515 ========================
6516
6517 This chapter uses the following notation:
6518
6519    * '|' separates two alternatives.
6520
6521    * '[ SOMETHING ]' indicates that SOMETHING is optional: it may or may
6522      not be given.
6523
6524    * '( GROUP )*' means that GROUP inside the parentheses may repeat
6525      zero or more times.
6526
6527    * '( GROUP )+' means that GROUP inside the parentheses may repeat one
6528      or more times.
6529
6530    * '"STRING"' means a literal STRING.
6531
6532 * Menu:
6533
6534 * GDB/MI General Design::
6535 * GDB/MI Command Syntax::
6536 * GDB/MI Compatibility with CLI::
6537 * GDB/MI Development and Front Ends::
6538 * GDB/MI Output Records::
6539 * GDB/MI Simple Examples::
6540 * GDB/MI Command Description Format::
6541 * GDB/MI Breakpoint Commands::
6542 * GDB/MI Catchpoint Commands::
6543 * GDB/MI Program Context::
6544 * GDB/MI Thread Commands::
6545 * GDB/MI Ada Tasking Commands::
6546 * GDB/MI Program Execution::
6547 * GDB/MI Stack Manipulation::
6548 * GDB/MI Variable Objects::
6549 * GDB/MI Data Manipulation::
6550 * GDB/MI Tracepoint Commands::
6551 * GDB/MI Symbol Query::
6552 * GDB/MI File Commands::
6553 * GDB/MI Target Manipulation::
6554 * GDB/MI File Transfer Commands::
6555 * GDB/MI Ada Exceptions Commands::
6556 * GDB/MI Support Commands::
6557 * GDB/MI Miscellaneous Commands::
6558
6559 \1f
6560 File: gdb.info,  Node: GDB/MI General Design,  Next: GDB/MI Command Syntax,  Up: GDB/MI
6561
6562 27.1 GDB/MI General Design
6563 ==========================
6564
6565 Interaction of a GDB/MI frontend with GDB involves three parts--commands
6566 sent to GDB, responses to those commands and notifications.  Each
6567 command results in exactly one response, indicating either successful
6568 completion of the command, or an error.  For the commands that do not
6569 resume the target, the response contains the requested information.  For
6570 the commands that resume the target, the response only indicates whether
6571 the target was successfully resumed.  Notifications is the mechanism for
6572 reporting changes in the state of the target, or in GDB state, that
6573 cannot conveniently be associated with a command and reported as part of
6574 that command response.
6575
6576    The important examples of notifications are:
6577
6578    * Exec notifications.  These are used to report changes in target
6579      state--when a target is resumed, or stopped.  It would not be
6580      feasible to include this information in response of resuming
6581      commands, because one resume commands can result in multiple events
6582      in different threads.  Also, quite some time may pass before any
6583      event happens in the target, while a frontend needs to know whether
6584      the resuming command itself was successfully executed.
6585
6586    * Console output, and status notifications.  Console output
6587      notifications are used to report output of CLI commands, as well as
6588      diagnostics for other commands.  Status notifications are used to
6589      report the progress of a long-running operation.  Naturally,
6590      including this information in command response would mean no output
6591      is produced until the command is finished, which is undesirable.
6592
6593    * General notifications.  Commands may have various side effects on
6594      the GDB or target state beyond their official purpose.  For
6595      example, a command may change the selected thread.  Although such
6596      changes can be included in command response, using notification
6597      allows for more orthogonal frontend design.
6598
6599    There's no guarantee that whenever an MI command reports an error,
6600 GDB or the target are in any specific state, and especially, the state
6601 is not reverted to the state before the MI command was processed.
6602 Therefore, whenever an MI command results in an error, we recommend that
6603 the frontend refreshes all the information shown in the user interface.
6604
6605 * Menu:
6606
6607 * Context management::
6608 * Asynchronous and non-stop modes::
6609 * Thread groups::
6610
6611 \1f
6612 File: gdb.info,  Node: Context management,  Next: Asynchronous and non-stop modes,  Up: GDB/MI General Design
6613
6614 27.1.1 Context management
6615 -------------------------
6616
6617 27.1.1.1 Threads and Frames
6618 ...........................
6619
6620 In most cases when GDB accesses the target, this access is done in
6621 context of a specific thread and frame (*note Frames::).  Often, even
6622 when accessing global data, the target requires that a thread be
6623 specified.  The CLI interface maintains the selected thread and frame,
6624 and supplies them to target on each command.  This is convenient,
6625 because a command line user would not want to specify that information
6626 explicitly on each command, and because user interacts with GDB via a
6627 single terminal, so no confusion is possible as to what thread and frame
6628 are the current ones.
6629
6630    In the case of MI, the concept of selected thread and frame is less
6631 useful.  First, a frontend can easily remember this information itself.
6632 Second, a graphical frontend can have more than one window, each one
6633 used for debugging a different thread, and the frontend might want to
6634 access additional threads for internal purposes.  This increases the
6635 risk that by relying on implicitly selected thread, the frontend may be
6636 operating on a wrong one.  Therefore, each MI command should explicitly
6637 specify which thread and frame to operate on.  To make it possible, each
6638 MI command accepts the '--thread' and '--frame' options, the value to
6639 each is GDB identifier for thread and frame to operate on.
6640
6641    Usually, each top-level window in a frontend allows the user to
6642 select a thread and a frame, and remembers the user selection for
6643 further operations.  However, in some cases GDB may suggest that the
6644 current thread be changed.  For example, when stopping on a breakpoint
6645 it is reasonable to switch to the thread where breakpoint is hit.  For
6646 another example, if the user issues the CLI 'thread' command via the
6647 frontend, it is desirable to change the frontend's selected thread to
6648 the one specified by user.  GDB communicates the suggestion to change
6649 current thread using the '=thread-selected' notification.  No such
6650 notification is available for the selected frame at the moment.
6651
6652    Note that historically, MI shares the selected thread with CLI, so
6653 frontends used the '-thread-select' to execute commands in the right
6654 context.  However, getting this to work right is cumbersome.  The
6655 simplest way is for frontend to emit '-thread-select' command before
6656 every command.  This doubles the number of commands that need to be
6657 sent.  The alternative approach is to suppress '-thread-select' if the
6658 selected thread in GDB is supposed to be identical to the thread the
6659 frontend wants to operate on.  However, getting this optimization right
6660 can be tricky.  In particular, if the frontend sends several commands to
6661 GDB, and one of the commands changes the selected thread, then the
6662 behaviour of subsequent commands will change.  So, a frontend should
6663 either wait for response from such problematic commands, or explicitly
6664 add '-thread-select' for all subsequent commands.  No frontend is known
6665 to do this exactly right, so it is suggested to just always pass the
6666 '--thread' and '--frame' options.
6667
6668 27.1.1.2 Language
6669 .................
6670
6671 The execution of several commands depends on which language is selected.
6672 By default, the current language (*note show language::) is used.  But
6673 for commands known to be language-sensitive, it is recommended to use
6674 the '--language' option.  This option takes one argument, which is the
6675 name of the language to use while executing the command.  For instance:
6676
6677      -data-evaluate-expression --language c "sizeof (void*)"
6678      ^done,value="4"
6679      (gdb)
6680
6681    The valid language names are the same names accepted by the 'set
6682 language' command (*note Manually::), excluding 'auto', 'local' or
6683 'unknown'.
6684
6685 \1f
6686 File: gdb.info,  Node: Asynchronous and non-stop modes,  Next: Thread groups,  Prev: Context management,  Up: GDB/MI General Design
6687
6688 27.1.2 Asynchronous command execution and non-stop mode
6689 -------------------------------------------------------
6690
6691 On some targets, GDB is capable of processing MI commands even while the
6692 target is running.  This is called "asynchronous command execution"
6693 (*note Background Execution::).  The frontend may specify a preferrence
6694 for asynchronous execution using the '-gdb-set mi-async 1' command,
6695 which should be emitted before either running the executable or
6696 attaching to the target.  After the frontend has started the executable
6697 or attached to the target, it can find if asynchronous execution is
6698 enabled using the '-list-target-features' command.
6699
6700 '-gdb-set mi-async on'
6701 '-gdb-set mi-async off'
6702      Set whether MI is in asynchronous mode.
6703
6704      When 'off', which is the default, MI execution commands (e.g.,
6705      '-exec-continue') are foreground commands, and GDB waits for the
6706      program to stop before processing further commands.
6707
6708      When 'on', MI execution commands are background execution commands
6709      (e.g., '-exec-continue' becomes the equivalent of the 'c&' CLI
6710      command), and so GDB is capable of processing MI commands even
6711      while the target is running.
6712
6713 '-gdb-show mi-async'
6714      Show whether MI asynchronous mode is enabled.
6715
6716    Note: In GDB version 7.7 and earlier, this option was called
6717 'target-async' instead of 'mi-async', and it had the effect of both
6718 putting MI in asynchronous mode and making CLI background commands
6719 possible.  CLI background commands are now always possible "out of the
6720 box" if the target supports them.  The old spelling is kept as a
6721 deprecated alias for backwards compatibility.
6722
6723    Even if GDB can accept a command while target is running, many
6724 commands that access the target do not work when the target is running.
6725 Therefore, asynchronous command execution is most useful when combined
6726 with non-stop mode (*note Non-Stop Mode::).  Then, it is possible to
6727 examine the state of one thread, while other threads are running.
6728
6729    When a given thread is running, MI commands that try to access the
6730 target in the context of that thread may not work, or may work only on
6731 some targets.  In particular, commands that try to operate on thread's
6732 stack will not work, on any target.  Commands that read memory, or
6733 modify breakpoints, may work or not work, depending on the target.  Note
6734 that even commands that operate on global state, such as 'print', 'set',
6735 and breakpoint commands, still access the target in the context of a
6736 specific thread, so frontend should try to find a stopped thread and
6737 perform the operation on that thread (using the '--thread' option).
6738
6739    Which commands will work in the context of a running thread is highly
6740 target dependent.  However, the two commands '-exec-interrupt', to stop
6741 a thread, and '-thread-info', to find the state of a thread, will always
6742 work.
6743
6744 \1f
6745 File: gdb.info,  Node: Thread groups,  Prev: Asynchronous and non-stop modes,  Up: GDB/MI General Design
6746
6747 27.1.3 Thread groups
6748 --------------------
6749
6750 GDB may be used to debug several processes at the same time.  On some
6751 platfroms, GDB may support debugging of several hardware systems, each
6752 one having several cores with several different processes running on
6753 each core.  This section describes the MI mechanism to support such
6754 debugging scenarios.
6755
6756    The key observation is that regardless of the structure of the
6757 target, MI can have a global list of threads, because most commands that
6758 accept the '--thread' option do not need to know what process that
6759 thread belongs to.  Therefore, it is not necessary to introduce neither
6760 additional '--process' option, nor an notion of the current process in
6761 the MI interface.  The only strictly new feature that is required is the
6762 ability to find how the threads are grouped into processes.
6763
6764    To allow the user to discover such grouping, and to support arbitrary
6765 hierarchy of machines/cores/processes, MI introduces the concept of a
6766 "thread group".  Thread group is a collection of threads and other
6767 thread groups.  A thread group always has a string identifier, a type,
6768 and may have additional attributes specific to the type.  A new command,
6769 '-list-thread-groups', returns the list of top-level thread groups,
6770 which correspond to processes that GDB is debugging at the moment.  By
6771 passing an identifier of a thread group to the '-list-thread-groups'
6772 command, it is possible to obtain the members of specific thread group.
6773
6774    To allow the user to easily discover processes, and other objects, he
6775 wishes to debug, a concept of "available thread group" is introduced.
6776 Available thread group is an thread group that GDB is not debugging, but
6777 that can be attached to, using the '-target-attach' command.  The list
6778 of available top-level thread groups can be obtained using
6779 '-list-thread-groups --available'.  In general, the content of a thread
6780 group may be only retrieved only after attaching to that thread group.
6781
6782    Thread groups are related to inferiors (*note Inferiors and
6783 Programs::).  Each inferior corresponds to a thread group of a special
6784 type 'process', and some additional operations are permitted on such
6785 thread groups.
6786
6787 \1f
6788 File: gdb.info,  Node: GDB/MI Command Syntax,  Next: GDB/MI Compatibility with CLI,  Prev: GDB/MI General Design,  Up: GDB/MI
6789
6790 27.2 GDB/MI Command Syntax
6791 ==========================
6792
6793 * Menu:
6794
6795 * GDB/MI Input Syntax::
6796 * GDB/MI Output Syntax::
6797
6798 \1f
6799 File: gdb.info,  Node: GDB/MI Input Syntax,  Next: GDB/MI Output Syntax,  Up: GDB/MI Command Syntax
6800
6801 27.2.1 GDB/MI Input Syntax
6802 --------------------------
6803
6804 'COMMAND ==>'
6805      'CLI-COMMAND | MI-COMMAND'
6806
6807 'CLI-COMMAND ==>'
6808      '[ TOKEN ] CLI-COMMAND NL', where CLI-COMMAND is any existing GDB
6809      CLI command.
6810
6811 'MI-COMMAND ==>'
6812      '[ TOKEN ] "-" OPERATION ( " " OPTION )* [ " --" ] ( " " PARAMETER
6813      )* NL'
6814
6815 'TOKEN ==>'
6816      "any sequence of digits"
6817
6818 'OPTION ==>'
6819      '"-" PARAMETER [ " " PARAMETER ]'
6820
6821 'PARAMETER ==>'
6822      'NON-BLANK-SEQUENCE | C-STRING'
6823
6824 'OPERATION ==>'
6825      _any of the operations described in this chapter_
6826
6827 'NON-BLANK-SEQUENCE ==>'
6828      _anything, provided it doesn't contain special characters such as
6829      "-", NL, """ and of course " "_
6830
6831 'C-STRING ==>'
6832      '""" SEVEN-BIT-ISO-C-STRING-CONTENT """'
6833
6834 'NL ==>'
6835      'CR | CR-LF'
6836
6837 Notes:
6838
6839    * The CLI commands are still handled by the MI interpreter; their
6840      output is described below.
6841
6842    * The 'TOKEN', when present, is passed back when the command
6843      finishes.
6844
6845    * Some MI commands accept optional arguments as part of the parameter
6846      list.  Each option is identified by a leading '-' (dash) and may be
6847      followed by an optional argument parameter.  Options occur first in
6848      the parameter list and can be delimited from normal parameters
6849      using '--' (this is useful when some parameters begin with a dash).
6850
6851    Pragmatics:
6852
6853    * We want easy access to the existing CLI syntax (for debugging).
6854
6855    * We want it to be easy to spot a MI operation.
6856
6857 \1f
6858 File: gdb.info,  Node: GDB/MI Output Syntax,  Prev: GDB/MI Input Syntax,  Up: GDB/MI Command Syntax
6859
6860 27.2.2 GDB/MI Output Syntax
6861 ---------------------------
6862
6863 The output from GDB/MI consists of zero or more out-of-band records
6864 followed, optionally, by a single result record.  This result record is
6865 for the most recent command.  The sequence of output records is
6866 terminated by '(gdb)'.
6867
6868    If an input command was prefixed with a 'TOKEN' then the
6869 corresponding output for that command will also be prefixed by that same
6870 TOKEN.
6871
6872 'OUTPUT ==>'
6873      '( OUT-OF-BAND-RECORD )* [ RESULT-RECORD ] "(gdb)" NL'
6874
6875 'RESULT-RECORD ==>'
6876      ' [ TOKEN ] "^" RESULT-CLASS ( "," RESULT )* NL'
6877
6878 'OUT-OF-BAND-RECORD ==>'
6879      'ASYNC-RECORD | STREAM-RECORD'
6880
6881 'ASYNC-RECORD ==>'
6882      'EXEC-ASYNC-OUTPUT | STATUS-ASYNC-OUTPUT | NOTIFY-ASYNC-OUTPUT'
6883
6884 'EXEC-ASYNC-OUTPUT ==>'
6885      '[ TOKEN ] "*" ASYNC-OUTPUT NL'
6886
6887 'STATUS-ASYNC-OUTPUT ==>'
6888      '[ TOKEN ] "+" ASYNC-OUTPUT NL'
6889
6890 'NOTIFY-ASYNC-OUTPUT ==>'
6891      '[ TOKEN ] "=" ASYNC-OUTPUT NL'
6892
6893 'ASYNC-OUTPUT ==>'
6894      'ASYNC-CLASS ( "," RESULT )*'
6895
6896 'RESULT-CLASS ==>'
6897      '"done" | "running" | "connected" | "error" | "exit"'
6898
6899 'ASYNC-CLASS ==>'
6900      '"stopped" | OTHERS' (where OTHERS will be added depending on the
6901      needs--this is still in development).
6902
6903 'RESULT ==>'
6904      ' VARIABLE "=" VALUE'
6905
6906 'VARIABLE ==>'
6907      ' STRING '
6908
6909 'VALUE ==>'
6910      ' CONST | TUPLE | LIST '
6911
6912 'CONST ==>'
6913      'C-STRING'
6914
6915 'TUPLE ==>'
6916      ' "{}" | "{" RESULT ( "," RESULT )* "}" '
6917
6918 'LIST ==>'
6919      ' "[]" | "[" VALUE ( "," VALUE )* "]" | "[" RESULT ( "," RESULT )*
6920      "]" '
6921
6922 'STREAM-RECORD ==>'
6923      'CONSOLE-STREAM-OUTPUT | TARGET-STREAM-OUTPUT | LOG-STREAM-OUTPUT'
6924
6925 'CONSOLE-STREAM-OUTPUT ==>'
6926      '"~" C-STRING NL'
6927
6928 'TARGET-STREAM-OUTPUT ==>'
6929      '"@" C-STRING NL'
6930
6931 'LOG-STREAM-OUTPUT ==>'
6932      '"&" C-STRING NL'
6933
6934 'NL ==>'
6935      'CR | CR-LF'
6936
6937 'TOKEN ==>'
6938      _any sequence of digits_.
6939
6940 Notes:
6941
6942    * All output sequences end in a single line containing a period.
6943
6944    * The 'TOKEN' is from the corresponding request.  Note that for all
6945      async output, while the token is allowed by the grammar and may be
6946      output by future versions of GDB for select async output messages,
6947      it is generally omitted.  Frontends should treat all async output
6948      as reporting general changes in the state of the target and there
6949      should be no need to associate async output to any prior command.
6950
6951    * STATUS-ASYNC-OUTPUT contains on-going status information about the
6952      progress of a slow operation.  It can be discarded.  All status
6953      output is prefixed by '+'.
6954
6955    * EXEC-ASYNC-OUTPUT contains asynchronous state change on the target
6956      (stopped, started, disappeared).  All async output is prefixed by
6957      '*'.
6958
6959    * NOTIFY-ASYNC-OUTPUT contains supplementary information that the
6960      client should handle (e.g., a new breakpoint information).  All
6961      notify output is prefixed by '='.
6962
6963    * CONSOLE-STREAM-OUTPUT is output that should be displayed as is in
6964      the console.  It is the textual response to a CLI command.  All the
6965      console output is prefixed by '~'.
6966
6967    * TARGET-STREAM-OUTPUT is the output produced by the target program.
6968      All the target output is prefixed by '@'.
6969
6970    * LOG-STREAM-OUTPUT is output text coming from GDB's internals, for
6971      instance messages that should be displayed as part of an error log.
6972      All the log output is prefixed by '&'.
6973
6974    * New GDB/MI commands should only output LISTS containing VALUES.
6975
6976    *Note GDB/MI Stream Records: GDB/MI Stream Records, for more details
6977 about the various output records.
6978
6979 \1f
6980 File: gdb.info,  Node: GDB/MI Compatibility with CLI,  Next: GDB/MI Development and Front Ends,  Prev: GDB/MI Command Syntax,  Up: GDB/MI
6981
6982 27.3 GDB/MI Compatibility with CLI
6983 ==================================
6984
6985 For the developers convenience CLI commands can be entered directly, but
6986 there may be some unexpected behaviour.  For example, commands that
6987 query the user will behave as if the user replied yes, breakpoint
6988 command lists are not executed and some CLI commands, such as 'if',
6989 'when' and 'define', prompt for further input with '>', which is not
6990 valid MI output.
6991
6992    This feature may be removed at some stage in the future and it is
6993 recommended that front ends use the '-interpreter-exec' command (*note
6994 -interpreter-exec::).
6995
6996 \1f
6997 File: gdb.info,  Node: GDB/MI Development and Front Ends,  Next: GDB/MI Output Records,  Prev: GDB/MI Compatibility with CLI,  Up: GDB/MI
6998
6999 27.4 GDB/MI Development and Front Ends
7000 ======================================
7001
7002 The application which takes the MI output and presents the state of the
7003 program being debugged to the user is called a "front end".
7004
7005    Although GDB/MI is still incomplete, it is currently being used by a
7006 variety of front ends to GDB.  This makes it difficult to introduce new
7007 functionality without breaking existing usage.  This section tries to
7008 minimize the problems by describing how the protocol might change.
7009
7010    Some changes in MI need not break a carefully designed front end, and
7011 for these the MI version will remain unchanged.  The following is a list
7012 of changes that may occur within one level, so front ends should parse
7013 MI output in a way that can handle them:
7014
7015    * New MI commands may be added.
7016
7017    * New fields may be added to the output of any MI command.
7018
7019    * The range of values for fields with specified values, e.g.,
7020      'in_scope' (*note -var-update::) may be extended.
7021
7022    If the changes are likely to break front ends, the MI version level
7023 will be increased by one.  This will allow the front end to parse the
7024 output according to the MI version.  Apart from mi0, new versions of GDB
7025 will not support old versions of MI and it will be the responsibility of
7026 the front end to work with the new one.
7027
7028    The best way to avoid unexpected changes in MI that might break your
7029 front end is to make your project known to GDB developers and follow
7030 development on <gdb@sourceware.org> and <gdb-patches@sourceware.org>.
7031
7032 \1f
7033 File: gdb.info,  Node: GDB/MI Output Records,  Next: GDB/MI Simple Examples,  Prev: GDB/MI Development and Front Ends,  Up: GDB/MI
7034
7035 27.5 GDB/MI Output Records
7036 ==========================
7037
7038 * Menu:
7039
7040 * GDB/MI Result Records::
7041 * GDB/MI Stream Records::
7042 * GDB/MI Async Records::
7043 * GDB/MI Breakpoint Information::
7044 * GDB/MI Frame Information::
7045 * GDB/MI Thread Information::
7046 * GDB/MI Ada Exception Information::
7047
7048 \1f
7049 File: gdb.info,  Node: GDB/MI Result Records,  Next: GDB/MI Stream Records,  Up: GDB/MI Output Records
7050
7051 27.5.1 GDB/MI Result Records
7052 ----------------------------
7053
7054 In addition to a number of out-of-band notifications, the response to a
7055 GDB/MI command includes one of the following result indications:
7056
7057 '"^done" [ "," RESULTS ]'
7058      The synchronous operation was successful, 'RESULTS' are the return
7059      values.
7060
7061 '"^running"'
7062      This result record is equivalent to '^done'.  Historically, it was
7063      output instead of '^done' if the command has resumed the target.
7064      This behaviour is maintained for backward compatibility, but all
7065      frontends should treat '^done' and '^running' identically and rely
7066      on the '*running' output record to determine which threads are
7067      resumed.
7068
7069 '"^connected"'
7070      GDB has connected to a remote target.
7071
7072 '"^error" "," "msg=" C-STRING [ "," "code=" C-STRING ]'
7073      The operation failed.  The 'msg=C-STRING' variable contains the
7074      corresponding error message.
7075
7076      If present, the 'code=C-STRING' variable provides an error code on
7077      which consumers can rely on to detect the corresponding error
7078      condition.  At present, only one error code is defined:
7079
7080      '"undefined-command"'
7081           Indicates that the command causing the error does not exist.
7082
7083 '"^exit"'
7084      GDB has terminated.
7085
7086 \1f
7087 File: gdb.info,  Node: GDB/MI Stream Records,  Next: GDB/MI Async Records,  Prev: GDB/MI Result Records,  Up: GDB/MI Output Records
7088
7089 27.5.2 GDB/MI Stream Records
7090 ----------------------------
7091
7092 GDB internally maintains a number of output streams: the console, the
7093 target, and the log.  The output intended for each of these streams is
7094 funneled through the GDB/MI interface using "stream records".
7095
7096    Each stream record begins with a unique "prefix character" which
7097 identifies its stream (*note GDB/MI Output Syntax: GDB/MI Output
7098 Syntax.).  In addition to the prefix, each stream record contains a
7099 'STRING-OUTPUT'.  This is either raw text (with an implicit new line) or
7100 a quoted C string (which does not contain an implicit newline).
7101
7102 '"~" STRING-OUTPUT'
7103      The console output stream contains text that should be displayed in
7104      the CLI console window.  It contains the textual responses to CLI
7105      commands.
7106
7107 '"@" STRING-OUTPUT'
7108      The target output stream contains any textual output from the
7109      running target.  This is only present when GDB's event loop is
7110      truly asynchronous, which is currently only the case for remote
7111      targets.
7112
7113 '"&" STRING-OUTPUT'
7114      The log stream contains debugging messages being produced by GDB's
7115      internals.
7116
7117 \1f
7118 File: gdb.info,  Node: GDB/MI Async Records,  Next: GDB/MI Breakpoint Information,  Prev: GDB/MI Stream Records,  Up: GDB/MI Output Records
7119
7120 27.5.3 GDB/MI Async Records
7121 ---------------------------
7122
7123 "Async" records are used to notify the GDB/MI client of additional
7124 changes that have occurred.  Those changes can either be a consequence
7125 of GDB/MI commands (e.g., a breakpoint modified) or a result of target
7126 activity (e.g., target stopped).
7127
7128    The following is the list of possible async records:
7129
7130 '*running,thread-id="THREAD"'
7131      The target is now running.  The THREAD field tells which specific
7132      thread is now running, and can be 'all' if all threads are running.
7133      The frontend should assume that no interaction with a running
7134      thread is possible after this notification is produced.  The
7135      frontend should not assume that this notification is output only
7136      once for any command.  GDB may emit this notification several
7137      times, either for different threads, because it cannot resume all
7138      threads together, or even for a single thread, if the thread must
7139      be stepped though some code before letting it run freely.
7140
7141 '*stopped,reason="REASON",thread-id="ID",stopped-threads="STOPPED",core="CORE"'
7142      The target has stopped.  The REASON field can have one of the
7143      following values:
7144
7145      'breakpoint-hit'
7146           A breakpoint was reached.
7147      'watchpoint-trigger'
7148           A watchpoint was triggered.
7149      'read-watchpoint-trigger'
7150           A read watchpoint was triggered.
7151      'access-watchpoint-trigger'
7152           An access watchpoint was triggered.
7153      'function-finished'
7154           An -exec-finish or similar CLI command was accomplished.
7155      'location-reached'
7156           An -exec-until or similar CLI command was accomplished.
7157      'watchpoint-scope'
7158           A watchpoint has gone out of scope.
7159      'end-stepping-range'
7160           An -exec-next, -exec-next-instruction, -exec-step,
7161           -exec-step-instruction or similar CLI command was
7162           accomplished.
7163      'exited-signalled'
7164           The inferior exited because of a signal.
7165      'exited'
7166           The inferior exited.
7167      'exited-normally'
7168           The inferior exited normally.
7169      'signal-received'
7170           A signal was received by the inferior.
7171      'solib-event'
7172           The inferior has stopped due to a library being loaded or
7173           unloaded.  This can happen when 'stop-on-solib-events' (*note
7174           Files::) is set or when a 'catch load' or 'catch unload'
7175           catchpoint is in use (*note Set Catchpoints::).
7176      'fork'
7177           The inferior has forked.  This is reported when 'catch fork'
7178           (*note Set Catchpoints::) has been used.
7179      'vfork'
7180           The inferior has vforked.  This is reported in when 'catch
7181           vfork' (*note Set Catchpoints::) has been used.
7182      'syscall-entry'
7183           The inferior entered a system call.  This is reported when
7184           'catch syscall' (*note Set Catchpoints::) has been used.
7185      'syscall-entry'
7186           The inferior returned from a system call.  This is reported
7187           when 'catch syscall' (*note Set Catchpoints::) has been used.
7188      'exec'
7189           The inferior called 'exec'.  This is reported when 'catch
7190           exec' (*note Set Catchpoints::) has been used.
7191
7192      The ID field identifies the thread that directly caused the stop -
7193      for example by hitting a breakpoint.  Depending on whether all-stop
7194      mode is in effect (*note All-Stop Mode::), GDB may either stop all
7195      threads, or only the thread that directly triggered the stop.  If
7196      all threads are stopped, the STOPPED field will have the value of
7197      '"all"'.  Otherwise, the value of the STOPPED field will be a list
7198      of thread identifiers.  Presently, this list will always include a
7199      single thread, but frontend should be prepared to see several
7200      threads in the list.  The CORE field reports the processor core on
7201      which the stop event has happened.  This field may be absent if
7202      such information is not available.
7203
7204 '=thread-group-added,id="ID"'
7205 '=thread-group-removed,id="ID"'
7206      A thread group was either added or removed.  The ID field contains
7207      the GDB identifier of the thread group.  When a thread group is
7208      added, it generally might not be associated with a running process.
7209      When a thread group is removed, its id becomes invalid and cannot
7210      be used in any way.
7211
7212 '=thread-group-started,id="ID",pid="PID"'
7213      A thread group became associated with a running program, either
7214      because the program was just started or the thread group was
7215      attached to a program.  The ID field contains the GDB identifier of
7216      the thread group.  The PID field contains process identifier,
7217      specific to the operating system.
7218
7219 '=thread-group-exited,id="ID"[,exit-code="CODE"]'
7220      A thread group is no longer associated with a running program,
7221      either because the program has exited, or because it was detached
7222      from.  The ID field contains the GDB identifier of the thread
7223      group.  The CODE field is the exit code of the inferior; it exists
7224      only when the inferior exited with some code.
7225
7226 '=thread-created,id="ID",group-id="GID"'
7227 '=thread-exited,id="ID",group-id="GID"'
7228      A thread either was created, or has exited.  The ID field contains
7229      the GDB identifier of the thread.  The GID field identifies the
7230      thread group this thread belongs to.
7231
7232 '=thread-selected,id="ID"'
7233      Informs that the selected thread was changed as result of the last
7234      command.  This notification is not emitted as result of
7235      '-thread-select' command but is emitted whenever an MI command that
7236      is not documented to change the selected thread actually changes
7237      it.  In particular, invoking, directly or indirectly (via
7238      user-defined command), the CLI 'thread' command, will generate this
7239      notification.
7240
7241      We suggest that in response to this notification, front ends
7242      highlight the selected thread and cause subsequent commands to
7243      apply to that thread.
7244
7245 '=library-loaded,...'
7246      Reports that a new library file was loaded by the program.  This
7247      notification has 4 fields--ID, TARGET-NAME, HOST-NAME, and
7248      SYMBOLS-LOADED.  The ID field is an opaque identifier of the
7249      library.  For remote debugging case, TARGET-NAME and HOST-NAME
7250      fields give the name of the library file on the target, and on the
7251      host respectively.  For native debugging, both those fields have
7252      the same value.  The SYMBOLS-LOADED field is emitted only for
7253      backward compatibility and should not be relied on to convey any
7254      useful information.  The THREAD-GROUP field, if present, specifies
7255      the id of the thread group in whose context the library was loaded.
7256      If the field is absent, it means the library was loaded in the
7257      context of all present thread groups.
7258
7259 '=library-unloaded,...'
7260      Reports that a library was unloaded by the program.  This
7261      notification has 3 fields--ID, TARGET-NAME and HOST-NAME with the
7262      same meaning as for the '=library-loaded' notification.  The
7263      THREAD-GROUP field, if present, specifies the id of the thread
7264      group in whose context the library was unloaded.  If the field is
7265      absent, it means the library was unloaded in the context of all
7266      present thread groups.
7267
7268 '=traceframe-changed,num=TFNUM,tracepoint=TPNUM'
7269 '=traceframe-changed,end'
7270      Reports that the trace frame was changed and its new number is
7271      TFNUM.  The number of the tracepoint associated with this trace
7272      frame is TPNUM.
7273
7274 '=tsv-created,name=NAME,initial=INITIAL'
7275      Reports that the new trace state variable NAME is created with
7276      initial value INITIAL.
7277
7278 '=tsv-deleted,name=NAME'
7279 '=tsv-deleted'
7280      Reports that the trace state variable NAME is deleted or all trace
7281      state variables are deleted.
7282
7283 '=tsv-modified,name=NAME,initial=INITIAL[,current=CURRENT]'
7284      Reports that the trace state variable NAME is modified with the
7285      initial value INITIAL.  The current value CURRENT of trace state
7286      variable is optional and is reported if the current value of trace
7287      state variable is known.
7288
7289 '=breakpoint-created,bkpt={...}'
7290 '=breakpoint-modified,bkpt={...}'
7291 '=breakpoint-deleted,id=NUMBER'
7292      Reports that a breakpoint was created, modified, or deleted,
7293      respectively.  Only user-visible breakpoints are reported to the MI
7294      user.
7295
7296      The BKPT argument is of the same form as returned by the various
7297      breakpoint commands; *Note GDB/MI Breakpoint Commands::.  The
7298      NUMBER is the ordinal number of the breakpoint.
7299
7300      Note that if a breakpoint is emitted in the result record of a
7301      command, then it will not also be emitted in an async record.
7302
7303 '=record-started,thread-group="ID"'
7304 '=record-stopped,thread-group="ID"'
7305      Execution log recording was either started or stopped on an
7306      inferior.  The ID is the GDB identifier of the thread group
7307      corresponding to the affected inferior.
7308
7309 '=cmd-param-changed,param=PARAM,value=VALUE'
7310      Reports that a parameter of the command 'set PARAM' is changed to
7311      VALUE.  In the multi-word 'set' command, the PARAM is the whole
7312      parameter list to 'set' command.  For example, In command 'set
7313      check type on', PARAM is 'check type' and VALUE is 'on'.
7314
7315 '=memory-changed,thread-group=ID,addr=ADDR,len=LEN[,type="code"]'
7316      Reports that bytes from ADDR to DATA + LEN were written in an
7317      inferior.  The ID is the identifier of the thread group
7318      corresponding to the affected inferior.  The optional 'type="code"'
7319      part is reported if the memory written to holds executable code.
7320