| OLD | NEW |
| 1 # Copyright (C) 2009-2012 Free Software Foundation, Inc. | 1 # Copyright (C) 2009-2012 Free Software Foundation, Inc. |
| 2 # | 2 # |
| 3 # This file is part of GDB. | 3 # This file is part of GDB. |
| 4 # | 4 # |
| 5 # This program is free software; you can redistribute it and/or modify | 5 # This program is free software; you can redistribute it and/or modify |
| 6 # it under the terms of the GNU General Public License as published by | 6 # it under the terms of the GNU General Public License as published by |
| 7 # the Free Software Foundation; either version 3 of the License, or | 7 # the Free Software Foundation; either version 3 of the License, or |
| 8 # (at your option) any later version. | 8 # (at your option) any later version. |
| 9 # | 9 # |
| 10 # This program is distributed in the hope that it will be useful, | 10 # This program is distributed in the hope that it will be useful, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 print " `struct type' pretty-printer will be degraded" | 92 print " `struct type' pretty-printer will be degraded" |
| 93 return | 93 return |
| 94 try: | 94 try: |
| 95 iflags = gdb.lookup_type("enum type_instance_flag_value") | 95 iflags = gdb.lookup_type("enum type_instance_flag_value") |
| 96 except: | 96 except: |
| 97 print "Warning: Cannot find enum type_instance_flag_value type." | 97 print "Warning: Cannot find enum type_instance_flag_value type." |
| 98 print " `struct type' pretty-printer will be degraded" | 98 print " `struct type' pretty-printer will be degraded" |
| 99 return | 99 return |
| 100 # Note: TYPE_FLAG_MIN is a duplicate of TYPE_FLAG_UNSIGNED, | 100 # Note: TYPE_FLAG_MIN is a duplicate of TYPE_FLAG_UNSIGNED, |
| 101 # so exclude it from the list we are building. | 101 # so exclude it from the list we are building. |
| 102 TYPE_FLAGS = [TypeFlag(field.name, field.bitpos) | 102 TYPE_FLAGS = [TypeFlag(field.name, field.enumval) |
| 103 for field in flags.fields() | 103 for field in flags.fields() |
| 104 if field.name != 'TYPE_FLAG_MIN'] | 104 if field.name != 'TYPE_FLAG_MIN'] |
| 105 TYPE_FLAGS += [TypeFlag(field.name, field.bitpos) | 105 TYPE_FLAGS += [TypeFlag(field.name, field.enumval) |
| 106 for field in iflags.fields()] | 106 for field in iflags.fields()] |
| 107 TYPE_FLAGS.sort() | 107 TYPE_FLAGS.sort() |
| 108 | 108 |
| 109 class StructTypePrettyPrinter: | 109 class StructTypePrettyPrinter: |
| 110 """Pretty-print an object of type struct type""" | 110 """Pretty-print an object of type struct type""" |
| 111 def __init__(self, val): | 111 def __init__(self, val): |
| 112 self.val = val | 112 self.val = val |
| 113 def to_string(self): | 113 def to_string(self): |
| 114 fields = [] | 114 fields = [] |
| 115 fields.append("pointer_type = %s" % self.val['pointer_type']) | 115 fields.append("pointer_type = %s" % self.val['pointer_type']) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 else: | 147 else: |
| 148 return "%s (gdbarch)" % self.val['owner']['gdbarch'] | 148 return "%s (gdbarch)" % self.val['owner']['gdbarch'] |
| 149 def struct_field_location_img(self, field_val): | 149 def struct_field_location_img(self, field_val): |
| 150 """Return an image of the loc component inside the given field | 150 """Return an image of the loc component inside the given field |
| 151 gdb.Value. | 151 gdb.Value. |
| 152 """ | 152 """ |
| 153 loc_val = field_val['loc'] | 153 loc_val = field_val['loc'] |
| 154 loc_kind = str(field_val['loc_kind']) | 154 loc_kind = str(field_val['loc_kind']) |
| 155 if loc_kind == "FIELD_LOC_KIND_BITPOS": | 155 if loc_kind == "FIELD_LOC_KIND_BITPOS": |
| 156 return 'bitpos = %d' % loc_val['bitpos'] | 156 return 'bitpos = %d' % loc_val['bitpos'] |
| 157 elif loc_kind == "FIELD_LOC_KIND_ENUMVAL": |
| 158 return 'enumval = %d' % loc_val['enumval'] |
| 157 elif loc_kind == "FIELD_LOC_KIND_PHYSADDR": | 159 elif loc_kind == "FIELD_LOC_KIND_PHYSADDR": |
| 158 return 'physaddr = 0x%x' % loc_val['physaddr'] | 160 return 'physaddr = 0x%x' % loc_val['physaddr'] |
| 159 elif loc_kind == "FIELD_LOC_KIND_PHYSNAME": | 161 elif loc_kind == "FIELD_LOC_KIND_PHYSNAME": |
| 160 return 'physname = %s' % loc_val['physname'] | 162 return 'physname = %s' % loc_val['physname'] |
| 161 elif loc_kind == "FIELD_LOC_KIND_DWARF_BLOCK": | 163 elif loc_kind == "FIELD_LOC_KIND_DWARF_BLOCK": |
| 162 return 'dwarf_block = %s' % loc_val['dwarf_block'] | 164 return 'dwarf_block = %s' % loc_val['dwarf_block'] |
| 163 else: | 165 else: |
| 164 return 'loc = ??? (unsupported loc_kind value)' | 166 return 'loc = ??? (unsupported loc_kind value)' |
| 165 def struct_field_img(self, fieldno): | 167 def struct_field_img(self, fieldno): |
| 166 """Return an image of the main_type field number FIELDNO. | 168 """Return an image of the main_type field number FIELDNO. |
| 167 """ | 169 """ |
| 168 f = self.val['flds_bnds']['fields'][fieldno] | 170 f = self.val['flds_bnds']['fields'][fieldno] |
| 169 label = "field[%d]:" % fieldno | 171 label = "flds_bnds.fields[%d]:" % fieldno |
| 170 if f['artificial']: | 172 if f['artificial']: |
| 171 label += " (artificial)" | 173 label += " (artificial)" |
| 172 fields = [] | 174 fields = [] |
| 173 fields.append("name = %s" % f['name']) | 175 fields.append("name = %s" % f['name']) |
| 174 fields.append("type = %s" % f['type']) | 176 fields.append("type = %s" % f['type']) |
| 175 fields.append("loc_kind = %s" % f['loc_kind']) | 177 fields.append("loc_kind = %s" % f['loc_kind']) |
| 176 fields.append("bitsize = %d" % f['bitsize']) | 178 fields.append("bitsize = %d" % f['bitsize']) |
| 177 fields.append(self.struct_field_location_img(f)) | 179 fields.append(self.struct_field_location_img(f)) |
| 178 return label + "\n" + " {" + ",\n ".join(fields) + "}" | 180 return label + "\n" + " {" + ",\n ".join(fields) + "}" |
| 179 def bounds_img(self): | 181 def bounds_img(self): |
| 180 """Return an image of the main_type bounds. | 182 """Return an image of the main_type bounds. |
| 181 """ | 183 """ |
| 182 b = self.val['flds_bnds']['bounds'].dereference() | 184 b = self.val['flds_bnds']['bounds'].dereference() |
| 183 low = str(b['low']) | 185 low = str(b['low']) |
| 184 if b['low_undefined'] != 0: | 186 if b['low_undefined'] != 0: |
| 185 low += " (undefined)" | 187 low += " (undefined)" |
| 186 high = str(b['high']) | 188 high = str(b['high']) |
| 187 if b['high_undefined'] != 0: | 189 if b['high_undefined'] != 0: |
| 188 high += " (undefined)" | 190 high += " (undefined)" |
| 189 return "bounds = {%s, %s}" % (low, high) | 191 return "flds_bnds.bounds = {%s, %s}" % (low, high) |
| 190 def type_specific_img(self): | 192 def type_specific_img(self): |
| 191 """Return a string image of the main_type type_specific union. | 193 """Return a string image of the main_type type_specific union. |
| 192 Only the relevant component of that union is printed (based on | 194 Only the relevant component of that union is printed (based on |
| 193 the value of the type_specific_kind field. | 195 the value of the type_specific_kind field. |
| 194 """ | 196 """ |
| 195 type_specific_kind = str(self.val['type_specific_field']) | 197 type_specific_kind = str(self.val['type_specific_field']) |
| 196 type_specific = self.val['type_specific'] | 198 type_specific = self.val['type_specific'] |
| 197 if type_specific_kind == "TYPE_SPECIFIC_NONE": | 199 if type_specific_kind == "TYPE_SPECIFIC_NONE": |
| 198 img = 'type_specific_field = %s' % type_specific_kind | 200 img = 'type_specific_field = %s' % type_specific_kind |
| 199 elif type_specific_kind == "TYPE_SPECIFIC_CPLUS_STUFF": | 201 elif type_specific_kind == "TYPE_SPECIFIC_CPLUS_STUFF": |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 # objfile. | 256 # objfile. |
| 255 register_pretty_printer(gdb.current_objfile()) | 257 register_pretty_printer(gdb.current_objfile()) |
| 256 else: | 258 else: |
| 257 # We need to locate the objfile corresponding to the GDB | 259 # We need to locate the objfile corresponding to the GDB |
| 258 # executable, and register the pretty-printer for that objfile. | 260 # executable, and register the pretty-printer for that objfile. |
| 259 # FIXME: The condition used to match the objfile is too simplistic | 261 # FIXME: The condition used to match the objfile is too simplistic |
| 260 # and will not work on Windows. | 262 # and will not work on Windows. |
| 261 for objfile in gdb.objfiles(): | 263 for objfile in gdb.objfiles(): |
| 262 if os.path.basename(objfile.filename) == "gdb": | 264 if os.path.basename(objfile.filename) == "gdb": |
| 263 objfile.pretty_printers.append(type_lookup_function) | 265 objfile.pretty_printers.append(type_lookup_function) |
| OLD | NEW |