jwakely.gcc at gmail dot com
2014-12-18 13:55:24 UTC
https://sourceware.org/bugzilla/show_bug.cgi?id=17728
Bug ID: 17728
Summary: gdb.LazyString is confused by typedefs
Product: gdb
Version: 7.8
Status: NEW
Severity: normal
Priority: P2
Component: python
Assignee: unassigned at sourceware dot org
Reporter: jwakely.gcc at gmail dot com
tmp$ cat > str.cc
struct Foo {
Foo() : str("foo"), len(3) { }
const char* str;
int len;
};
struct Bar {
Bar() : str("bar"), len(3) { }
typedef const char* pointer;
pointer str;
int len;
};
int main()
{
Foo foo;
Bar bar;
return 0;
}
tmp$ cat > a.out-gdb.py
import gdb
class StrPrinter:
"Print a stringy thingie"
def __init__ (self, val):
self.val = val
def to_string (self):
s = self.val['str']
l = self.val['len']
return s.lazy_string(length = l)
def display_hint(self):
return 'string'
def str_lookup_function(val):
lookup_tag = val.type.tag
if lookup_tag == "Foo" or lookup_tag == "Bar":
return StrPrinter(val)
return None
gdb.current_objfile().pretty_printers.append(str_lookup_function)
tmp$ g++ -g str.cc
tmp$ ~/gcc/gdb/7.8.50/bin/gdb
GNU gdb (GDB) 7.8.50.20141216-cvs
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) set auto-load safe-path /
(gdb) file a.out
Reading symbols from a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x4005b8: file str.cc, line 16.
Starting program: /tmp/a.out
Temporary breakpoint 1, main () at str.cc:16
16 Foo foo;
(gdb) n
17 Bar bar;
(gdb) p foo
$1 = "foo"
(gdb) n
18 return 0;
(gdb) p bar
$2 = "\x4006b4\003\000\000\000\000\000\000\000\x4006b0"
(gdb)
The LazyString seems to be confused by the fact that Bar::str is declared with
a typedef, so it prints the contents of &bar.str instead of bar.str
The only solution I've found is to strip the typedef first:
def to_string (self):
s = self.val['str']
s = s.cast(s.type.strip_typedefs())
l = self.val['len']
return s.lazy_string(length = l)
Bug ID: 17728
Summary: gdb.LazyString is confused by typedefs
Product: gdb
Version: 7.8
Status: NEW
Severity: normal
Priority: P2
Component: python
Assignee: unassigned at sourceware dot org
Reporter: jwakely.gcc at gmail dot com
tmp$ cat > str.cc
struct Foo {
Foo() : str("foo"), len(3) { }
const char* str;
int len;
};
struct Bar {
Bar() : str("bar"), len(3) { }
typedef const char* pointer;
pointer str;
int len;
};
int main()
{
Foo foo;
Bar bar;
return 0;
}
tmp$ cat > a.out-gdb.py
import gdb
class StrPrinter:
"Print a stringy thingie"
def __init__ (self, val):
self.val = val
def to_string (self):
s = self.val['str']
l = self.val['len']
return s.lazy_string(length = l)
def display_hint(self):
return 'string'
def str_lookup_function(val):
lookup_tag = val.type.tag
if lookup_tag == "Foo" or lookup_tag == "Bar":
return StrPrinter(val)
return None
gdb.current_objfile().pretty_printers.append(str_lookup_function)
tmp$ g++ -g str.cc
tmp$ ~/gcc/gdb/7.8.50/bin/gdb
GNU gdb (GDB) 7.8.50.20141216-cvs
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) set auto-load safe-path /
(gdb) file a.out
Reading symbols from a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x4005b8: file str.cc, line 16.
Starting program: /tmp/a.out
Temporary breakpoint 1, main () at str.cc:16
16 Foo foo;
(gdb) n
17 Bar bar;
(gdb) p foo
$1 = "foo"
(gdb) n
18 return 0;
(gdb) p bar
$2 = "\x4006b4\003\000\000\000\000\000\000\000\x4006b0"
(gdb)
The LazyString seems to be confused by the fact that Bar::str is declared with
a typedef, so it prints the contents of &bar.str instead of bar.str
The only solution I've found is to strip the typedef first:
def to_string (self):
s = self.val['str']
s = s.cast(s.type.strip_typedefs())
l = self.val['len']
return s.lazy_string(length = l)
--
You are receiving this mail because:
You are on the CC list for the bug.
You are receiving this mail because:
You are on the CC list for the bug.