This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug python/11417] New: lazy string of zero length requires a valid pointer


I don't know if this behaviour is intentional, but it used to work when I was
using gdb.Value.string and fails with gdb.Value.lazy_string

I have a pretty printer for a string-like C++ class holding a char pointer and a
length.  The pointer can be NULL, in which case the length will be 0.

struct Str {
    Str(const char* s = 0) : str(s), len(s ? strlen(s) : 0) { }
    const char* str;
    int len;
};

Previously my pretty printer looked like:

class StrPrinter:
    "Print a Str"

    def __init__ (self, val):
        self.val = val

    def to_string (self):
        return '"' + self.val['str'].string('', 'ignore', self.val['len']) + '"'

If the pointer was null this printed ""

(gdb) p/r null
$5 = {str = 0x0, len = 0}
(gdb) p null
$6 = ""

(this despite the docs for Value.string saying "The string is assumed to be
terminated by a zero of the appropriate width.")

I changed the printer to:

class Str2Printer:
    "Print a Str2"

    def __init__ (self, val):
        self.val = val

    def to_string (self):
        return self.val['str'].lazy_string('', self.val['len'])

I like that I don't need to add double-quotes now, but it seems I now need to
handle NULL explicitly because lazy string doesn't like NULL even when the
length is zero:

(gdb) p/r null2
$2 = {str = 0x0, len = 0}
(gdb) p null2
$3 = Traceback (most recent call last):
  File "/home/wakelj/src/tests/pretty/str-gdb.py", line 23, in to_string
    return self.val['str'].lazy_string('', self.val['len'])
MemoryError: Cannot create a lazy string from a GDB-side string.

Are these differences between Value.string and Value.lazy_string intentional?

-- 
           Summary: lazy string of zero length requires a valid pointer
           Product: gdb
           Version: 7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: python
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: zilla at kayari dot org
                CC: gdb-prs at sourceware dot org


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

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]