public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "dje at google dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug python/18779] New: collection of issues handling C strings in python
Date: Thu, 06 Aug 2015 17:59:00 -0000	[thread overview]
Message-ID: <bug-18779-4717@http.sourceware.org/bugzilla/> (raw)

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

            Bug ID: 18779
           Summary: collection of issues handling C strings in python
           Product: gdb
           Version: unknown
            Status: NEW
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: dje at google dot com
  Target Milestone: ---

Wanting to extract a nul-terminated string from memory given just an ELF symbol
I ran into a few warts/bugs.
This bug is to record what I find, though I may not list them all in this
initial report (I *could* file a separate report per bug, but I'm not sure how
many there will be and since they're all related I wanted to keep them
together).

Given:

const char string[] = "hello";

bug #1:

(gdb) py print
gdb.parse_and_eval("&string[0]").string(length=7,encoding="ASCII")
Traceback (most recent call last):
  File "<string>", line 1, in <module>
gdb.MemoryError: Cannot access memory at address 0x40075c
Error while executing Python code.

One can certainly argue that's an error, but not a memory access error.

bug #2:

(gdb) py print gdb.parse_and_eval("&string[0]").lazy_string()
<gdb.LazyString object at 0x7f3444f8a750>

Question: what should str(lazy_string_object) be?
If one wants the above there is "repr".
The only useful thing to me seems to be the value returned as a python string.
IOW I expected to see "hello".

feature request #1:

IWBN if one could specify that the string is nul-terminated,
which we can by specifying a length of -1, but also specify
a maximum length (for those wanting more robustness).

maybe bug #3:

I don't have a string opinion on whether this works or not,
in c or c++, just filing this for reference sake since it seems odd:

(gdb) py print gdb.parse_and_eval("&string").string()
Traceback (most recent call last):
  File "<string>", line 1, in <module>
gdb.error: Trying to read string with inappropriate type `const char (*)[6]'.
Error while executing Python code.

maybe bug #4:

If we know the array's length, how come the lazy string length is always -1?

(gdb) pt &string
type = const char (*)[6]
(gdb) py print gdb.parse_and_eval("&string[0]").lazy_string().length
-1
(gdb) py print gdb.parse_and_eval("&string").lazy_string().length
-1
(gdb) py print gdb.parse_and_eval("string").lazy_string().length
-1

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


             reply	other threads:[~2015-08-06 17:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-06 17:59 dje at google dot com [this message]
2021-01-15 14:43 ` [Bug python/18779] " ssbssa at sourceware dot org
2022-06-12 16:16 ` tromey at sourceware dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-18779-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).