public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/13267] New: python: gdb.Value needs a method to get raw memory as a string
@ 2011-10-05 20:42 stbya at yahoo dot com
  2012-02-02 15:07 ` [Bug python/13267] " tromey at redhat dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: stbya at yahoo dot com @ 2011-10-05 20:42 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13267

             Bug #: 13267
           Summary: python: gdb.Value needs a method to get raw memory as
                    a string
           Product: gdb
           Version: 7.3
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
        AssignedTo: unassigned@sourceware.org
        ReportedBy: stbya@yahoo.com
    Classification: Unclassified


gdb.Value provides a way to get a textual string (gdb.Value.string(...)), but
there's no way to get it as a raw sequence of bytes.  Maybe this could be done
with an encoding argument of None?

e.g.

v = gdb.parse_and_eval("var")
data = v.string(None, length=64)

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug python/13267] python: gdb.Value needs a method to get raw memory as a string
  2011-10-05 20:42 [Bug gdb/13267] New: python: gdb.Value needs a method to get raw memory as a string stbya at yahoo dot com
@ 2012-02-02 15:07 ` tromey at redhat dot com
  2022-06-05 16:29 ` tromey at sourceware dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: tromey at redhat dot com @ 2012-02-02 15:07 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13267

Tom Tromey <tromey at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at redhat dot com
          Component|gdb                         |python

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug python/13267] python: gdb.Value needs a method to get raw memory as a string
  2011-10-05 20:42 [Bug gdb/13267] New: python: gdb.Value needs a method to get raw memory as a string stbya at yahoo dot com
  2012-02-02 15:07 ` [Bug python/13267] " tromey at redhat dot com
@ 2022-06-05 16:29 ` tromey at sourceware dot org
  2023-10-26 19:26 ` cvs-commit at gcc dot gnu.org
  2023-11-14 15:29 ` tromey at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: tromey at sourceware dot org @ 2022-06-05 16:29 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=13267

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
It seems to me that there are two different things we might
want to expose.

One thing is access to the underlying bytes of a Value.
This is maybe a little tricky because a Value might not have
all the bytes available.

The other thing is using a pointer value to fetch memory.
This can be done via read_memory, though it might be
nice to also have a convenience method on Value.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug python/13267] python: gdb.Value needs a method to get raw memory as a string
  2011-10-05 20:42 [Bug gdb/13267] New: python: gdb.Value needs a method to get raw memory as a string stbya at yahoo dot com
  2012-02-02 15:07 ` [Bug python/13267] " tromey at redhat dot com
  2022-06-05 16:29 ` tromey at sourceware dot org
@ 2023-10-26 19:26 ` cvs-commit at gcc dot gnu.org
  2023-11-14 15:29 ` tromey at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-26 19:26 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=13267

--- Comment #3 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Andrew Burgess <aburgess@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ef8cf9093dcf2f2320336f2d9bb9cca33f098189

commit ef8cf9093dcf2f2320336f2d9bb9cca33f098189
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Wed Oct 18 15:46:23 2023 +0100

    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>

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug python/13267] python: gdb.Value needs a method to get raw memory as a string
  2011-10-05 20:42 [Bug gdb/13267] New: python: gdb.Value needs a method to get raw memory as a string stbya at yahoo dot com
                   ` (2 preceding siblings ...)
  2023-10-26 19:26 ` cvs-commit at gcc dot gnu.org
@ 2023-11-14 15:29 ` tromey at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: tromey at sourceware dot org @ 2023-11-14 15:29 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=13267

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |15.1
             Status|NEW                         |RESOLVED

--- Comment #4 from Tom Tromey <tromey at sourceware dot org> ---
Nowadays I think the Value.bytes method is enough.
For a pointer you can use deref or indexing, which should be plenty.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-14 15:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-05 20:42 [Bug gdb/13267] New: python: gdb.Value needs a method to get raw memory as a string stbya at yahoo dot com
2012-02-02 15:07 ` [Bug python/13267] " tromey at redhat dot com
2022-06-05 16:29 ` tromey at sourceware dot org
2023-10-26 19:26 ` cvs-commit at gcc dot gnu.org
2023-11-14 15:29 ` tromey at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).