* [patch 1/2] gdb-gdb.py: Make the fields copy-paste friendly
@ 2010-01-15 19:28 Jan Kratochvil
2010-01-15 19:49 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kratochvil @ 2010-01-15 19:28 UTC (permalink / raw)
To: gdb-patches
Hi,
I would like to copy-paste the fields when I am not allowed to click on them
in CLI. This patch makes the copy-pasting more friendly such as I can do:
(gdb) p *(struct type *) 0x1dfabf0
Without having to figure out first target_type has type `struct type *'.
The same applies to "field[x]:" which may not be clear for the user one has to
translate into "flds_bnds.fields[x]." to access the printed fields (for
further dereferencing).
But such printing should be probably more integrated into the framework if
approved than doing it this way in each case.
Regards,
Jan
before:
$1 =
{name = 0x0,
tag_name = 0x0,
code = TYPE_CODE_RANGE,
flags = [unsigned|objfile_owned],
owner = 0x1de89b0 (objfile),
target_type = 0x1dfabf0,
vptr_basetype = 0x0,
bounds = {0, 8},
type_specific_field = TYPE_SPECIFIC_NONE}
after:
$1 =
{name = 0x0,
tag_name = 0x0,
code = TYPE_CODE_RANGE,
flags = [unsigned|objfile_owned],
owner = (struct objfile *) 0x1de89b0,
target_type = (struct type *) 0x1dfabf0,
vptr_basetype = 0x0,
bounds = {0, 8},
type_specific_field = TYPE_SPECIFIC_NONE}
2010-01-15 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb-gdb.py: Use `(type *) address' copy-paste notation. Rename
`field[%d]:' to `flds_bnds.fields[%d].'.
--- ./gdb/gdb-gdb.py-range 2010-01-15 20:10:29.000000000 +0100
+++ ./gdb/gdb-gdb.py 2010-01-15 20:13:38.000000000 +0100
@@ -118,7 +118,7 @@ class StructTypePrettyPrinter:
fields.append("instance_flags = %s"
% TypeFlagsPrinter(self.val['instance_flags']))
fields.append("length = %d" % self.val['length'])
- fields.append("main_type = %s" % self.val['main_type'])
+ fields.append("main_type = (%s) %s" % (self.val['main_type'].type, self.val['main_type']))
return "\n{" + ",\n ".join(fields) + "}"
class StructMainTypePrettyPrinter:
@@ -143,9 +143,9 @@ class StructMainTypePrettyPrinter:
"""Return an image of component "owner".
"""
if self.val['flag_objfile_owned'] != 0:
- return "%s (objfile)" % self.val['owner']['objfile']
+ return "(%s) %s" % (self.val['owner']['objfile'].type, self.val['owner']['objfile'])
else:
- return "%s (gdbarch)" % self.val['owner']['gdbarch']
+ return "(%s) %s" % (self.val['owner']['gdbarch'].type, self.val['owner']['gdbarch'])
def struct_field_location_img(self, field_val):
"""Return an image of the loc component inside the given field
gdb.Value.
@@ -166,12 +166,12 @@ class StructMainTypePrettyPrinter:
"""Return an image of the main_type field number FIELDNO.
"""
f = self.val['flds_bnds']['fields'][fieldno]
- label = "field[%d]:" % fieldno
+ label = "flds_bnds.fields[%d]." % fieldno
if f['artificial']:
label += " (artificial)"
fields = []
fields.append("name = %s" % f['name'])
- fields.append("type = %s" % f['type'])
+ fields.append("type = (%s) %s" % (f['type'].type, f['type']))
fields.append("loc_kind = %s" % f['loc_kind'])
fields.append("bitsize = %d" % f['bitsize'])
fields.append(self.struct_field_location_img(f))
@@ -220,7 +220,7 @@ class StructMainTypePrettyPrinter:
fields.append("code = %s" % self.val['code'])
fields.append("flags = [%s]" % self.flags_to_string())
fields.append("owner = %s" % self.owner_to_string())
- fields.append("target_type = %s" % self.val['target_type'])
+ fields.append("target_type = (%s) %s" % (self.val['target_type'].type, self.val['target_type']))
fields.append("vptr_basetype = %s" % self.val['vptr_basetype'])
if self.val['nfields'] > 0:
for fieldno in range(self.val['nfields']):
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch 1/2] gdb-gdb.py: Make the fields copy-paste friendly
2010-01-15 19:28 [patch 1/2] gdb-gdb.py: Make the fields copy-paste friendly Jan Kratochvil
@ 2010-01-15 19:49 ` Tom Tromey
2010-01-15 19:56 ` Jan Kratochvil
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2010-01-15 19:49 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
Jan> (gdb) p *(struct type *) 0x1dfabf0
Jan> But such printing should be probably more integrated into the framework if
Jan> approved than doing it this way in each case.
Maybe a new option like "set print type" or "set print pointer-type"?
Then it could apply everywhere, not just to the gdb-specific
pretty-printers.
Jan> - fields.append("main_type = %s" % self.val['main_type'])
Jan> + fields.append("main_type = (%s) %s" % (self.val['main_type'].type, self.val['main_type']))
... and in conjunction, changing this to just return values rather than
doing the formatting by hand.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch 1/2] gdb-gdb.py: Make the fields copy-paste friendly
2010-01-15 19:49 ` Tom Tromey
@ 2010-01-15 19:56 ` Jan Kratochvil
0 siblings, 0 replies; 3+ messages in thread
From: Jan Kratochvil @ 2010-01-15 19:56 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Fri, 15 Jan 2010 20:49:35 +0100, Tom Tromey wrote:
> Maybe a new option like "set print type" or "set print pointer-type"?
> Then it could apply everywhere, not just to the gdb-specific
> pretty-printers.
Such as even to non-Python struct printing which currently print:
$1 = {pointer_type = 0x0, reference_type = 0x0, chain = 0x1dfaa40,
instance_flags = 0, length = 36, main_type = 0x1dfaa70}
> Jan> - fields.append("main_type = %s" % self.val['main_type'])
> Jan> + fields.append("main_type = (%s) %s" % (self.val['main_type'].type, self.val['main_type']))
>
> ... and in conjunction, changing this to just return values rather than
> doing the formatting by hand.
yes.
Thanks,
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-01-15 19:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-15 19:28 [patch 1/2] gdb-gdb.py: Make the fields copy-paste friendly Jan Kratochvil
2010-01-15 19:49 ` Tom Tromey
2010-01-15 19:56 ` Jan Kratochvil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox