diff options
author | Andrew Burgess <aburgess@redhat.com> | 2023-03-08 16:11:30 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2023-03-30 10:25:46 +0100 |
commit | 6bf5f25bb150c0fbcb125e3ee466ba8f9680310b (patch) | |
tree | 55b9ff5bdae08c05721ef8f5030759e4f1fd864d /gdb/doc | |
parent | c22d38baefc5a7a1e1f5cdc9dbb556b1f0ec5c57 (diff) | |
download | binutils-gdb-6bf5f25bb150c0fbcb125e3ee466ba8f9680310b.tar.gz |
gdb/python: make the gdb.unwinder.Unwinder class more robust
This commit makes a few related changes to the gdb.unwinder.Unwinder
class attributes:
1. The 'name' attribute is now a read-only attribute. This prevents
user code from changing the name after registering the unwinder. It
seems very unlikely that any user is actually trying to do this in
the wild, so I'm not very worried that this will upset anyone,
2. We now validate that the name is a string in the
Unwinder.__init__ method, and throw an error if this is not the
case. Hopefully nobody was doing this in the wild. This should
make it easier to ensure the 'info unwinder' command shows sane
output (how to display a non-string name for an unwinder?),
3. The 'enabled' attribute is now implemented with a getter and
setter. In the setter we ensure that the new value is a boolean,
but the real important change is that we call
'gdb.invalidate_cached_frames()'. This means that the backtrace
will be updated if a user manually disables an unwinder (rather than
calling the 'disable unwinder' command). It is not unreasonable to
think that a user might register multiple unwinders (relating to
some project) and have one command that disables/enables all the
related unwinders. This command might operate by poking the enabled
attribute of each unwinder object directly, after this commit, this
would now work correctly.
There's tests for all the changes, and lots of documentation updates
that both cover the new changes, but also further improve (I think)
the general documentation for GDB's Unwinder API.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/doc')
-rw-r--r-- | gdb/doc/python.texi | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 13cf877b704..8dcb3daf7a2 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -2842,6 +2842,33 @@ values see @ref{gdbpy_frame_read_register,,Frame.read_register}. @var{value} is a register value (a @code{gdb.Value} object). @end defun +@subheading The @code{gdb.unwinder} Module + +@value{GDBN} comes with a @code{gdb.unwinder} module which contains +the following class: + +@deftp {class} gdb.unwinder.Unwinder +The @code{Unwinder} class is a base class from which user created +unwinders can derive, though it is not required that unwinders derive +from this class, so long as any user created unwinder has the required +@code{name} and @code{enabled} attributes. + +@defun gdb.unwinder.Unwinder.__init__(@var{name}) +The @var{name} is a string used to reference this unwinder within some +@value{GDBN} commands (@pxref{Managing Registered Unwinders}). +@end defun + +@defvar gdb.unwinder.name +A read-only attribute which is a string, the name of this unwinder. +@end defvar + +@defvar gdb.unwinder.enabled +A modifiable attribute containing a boolean; when @code{True}, the +unwinder is enabled, and will be used by @value{GDBN}. When +@code{False}, the unwinder has been disabled, and will not be used. +@end defvar +@end deftp + @subheading Registering an Unwinder Object files and program spaces can have unwinders registered with @@ -2870,9 +2897,7 @@ builtin to @value{GDBN}. @subheading Unwinder Skeleton Code -@value{GDBN} comes with the module containing the base @code{Unwinder} -class. Derive your unwinder class from it and structure the code as -follows: +Here is an example of how to structure a user created unwinder: @smallexample from gdb.unwinder import Unwinder @@ -2908,6 +2933,36 @@ class MyUnwinder(Unwinder): gdb.unwinder.register_unwinder(<locus>, MyUnwinder(), <replace>) @end smallexample +@anchor{Managing Registered Unwinders} +@subheading Managing Registered Unwinders +@value{GDBN} defines 3 commands to manage registered unwinders. These +are: + +@table @code +@item info unwinder @r{[} @var{locus} @r{[} @var{name-regexp} @r{]} @r{]} +Lists all registered unwinders. Arguments @var{locus} and +@var{name-regexp} are both optional and can be used to filter which +unwinders are listed. + +The @var{locus} argument should be either @kbd{global}, +@kbd{progspace}, or the name of an object file. Only unwinders +registered for the specified locus will be listed. + +The @var{name-regexp} is a regular expression used to match against +unwinder names. When trying to match against unwinder names that +include a string enclose @var{name-regexp} in quotes. +@item disable unwinder @r{[} @var{locus} @r{[} @var{name-regexp} @r{]} @r{]} +The @var{locus} and @var{name-regexp} are interpreted as in @kbd{info +unwinder} above, but instead of listing the matching unwinders, all of +the matching unwinders are disabled. The @code{enabled} field of each +matching unwinder is set to @code{False}. +@item enable unwinder @r{[} @var{locus} @r{[} @var{name-regexp} @r{]} @r{]} +The @var{locus} and @var{name-regexp} are interpreted as in @kbd{info +unwinder} above, but instead of listing the matching unwinders, all of +the matching unwinders are enabled. The @code{enabled} field of each +matching unwinder is set to @code{True}. +@end table + @node Xmethods In Python @subsubsection Xmethods In Python @cindex xmethods in Python |