diff options
author | Andrew Burgess <aburgess@redhat.com> | 2023-10-18 15:46:23 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2023-10-26 18:27:17 +0100 |
commit | ef8cf9093dcf2f2320336f2d9bb9cca33f098189 (patch) | |
tree | 66d4ccc7058a6d05582e93c0ef4e782e4e549b70 /gdb/doc | |
parent | fd492bf1e20a0410189307c5063acc444c4bd5d3 (diff) | |
download | binutils-ef8cf9093dcf2f2320336f2d9bb9cca33f098189.zip binutils-ef8cf9093dcf2f2320336f2d9bb9cca33f098189.tar.gz binutils-ef8cf9093dcf2f2320336f2d9bb9cca33f098189.tar.bz2 |
gdb/python: Add new gdb.Value.bytes attribute
Add a gdb.Value.bytes attribute. This attribute contains the bytes of
the value (assuming the complete bytes of the value are available).
If the bytes of the gdb.Value are not available then accessing this
attribute raises an exception.
The bytes object returned from gdb.Value.bytes is cached within GDB so
that the same bytes object is returned each time. The bytes object is
created on-demand though to reduce unnecessary work.
For some values we can of course obtain the same information by
reading inferior memory based on gdb.Value.address and
gdb.Value.type.sizeof, however, not every value is in memory, so we
don't always have an address.
The gdb.Value.bytes attribute will convert any value to a bytes
object, so long as the contents are available. The value can be one
created purely in Python code, the value could be in a register,
or (of course) the value could be in memory.
The Value.bytes attribute can also be assigned too. Assigning to this
attribute is similar to calling Value.assign, the value of the
underlying value is updated within the inferior. The value assigned
to Value.bytes must be a buffer which contains exactly the correct
number of bytes (i.e. unlike value creation, we don't allow oversized
buffers).
To support this assignment like behaviour I've factored out the core
of valpy_assign. I've also updated convert_buffer_and_type_to_value
so that it can (for my use case) check the exact buffer length.
The restrictions for when the Value.bytes can or cannot be written too
are exactly the same as for Value.assign.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=13267
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/doc')
-rw-r--r-- | gdb/doc/python.texi | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 546b4d4..8cc3f92 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -916,6 +916,21 @@ fetched when the value is needed, or when the @code{fetch_lazy} method is invoked. @end defvar +@defvar Value.bytes +The value of this attribute is a @code{bytes} object containing the +bytes that make up this @code{Value}'s complete value in little endian +order. If the complete contents of this value are not available then +accessing this attribute will raise an exception. + +This attribute can also be assigned to. The new value should be a +buffer object (e.g.@: a @code{bytes} object), the length of the new +buffer must exactly match the length of this @code{Value}'s type. The +bytes values in the new buffer should be in little endian order. + +As with @code{Value.assign} (@pxref{Value.assign}), if this value +cannot be assigned to, then an exception will be thrown. +@end defvar + The following methods are provided: @defun Value.__init__ (val) @@ -966,6 +981,7 @@ If @var{type} is @code{None} then this version of @code{__init__} behaves as though @var{type} was not passed at all. @end defun +@anchor{Value.assign} @defun Value.assign (rhs) Assign @var{rhs} to this value, and return @code{None}. If this value cannot be assigned to, or if the assignment is invalid for some reason |