This is the mail archive of the gdb-patches@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]

[patch 1/2] gdb-gdb.py: Make the fields copy-paste friendly


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']):


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