diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/.gdbinit | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/src/.gdbinit b/src/.gdbinit index 80aa95ba405..b5a974bb38d 100644 --- a/src/.gdbinit +++ b/src/.gdbinit | |||
| @@ -1300,18 +1300,52 @@ if hasattr(gdb, 'printing'): | |||
| 1300 | 1300 | ||
| 1301 | def to_string (self): | 1301 | def to_string (self): |
| 1302 | "Yield a string that can be fed back into GDB." | 1302 | "Yield a string that can be fed back into GDB." |
| 1303 | |||
| 1304 | # This implementation should work regardless of C compiler, and | ||
| 1305 | # it should not attempt to run any code in the inferior. | ||
| 1306 | EMACS_INT_WIDTH = int(gdb.lookup_symbol("EMACS_INT_WIDTH")[0].value()) | ||
| 1307 | USE_LSB_TAG = int(gdb.lookup_symbol("USE_LSB_TAG")[0].value()) | ||
| 1308 | GCTYPEBITS = 3 | ||
| 1309 | VALBITS = EMACS_INT_WIDTH - GCTYPEBITS | ||
| 1310 | Lisp_Int0 = 2 | ||
| 1311 | Lisp_Int1 = 6 if USE_LSB_TAG else 3 | ||
| 1312 | |||
| 1313 | # Unpack the Lisp value from its containing structure, if necessary. | ||
| 1303 | val = self.val | 1314 | val = self.val |
| 1304 | basic_type = gdb.types.get_basic_type (val.type) | 1315 | basic_type = gdb.types.get_basic_type (val.type) |
| 1305 | if (basic_type.code == gdb.TYPE_CODE_STRUCT | 1316 | if (basic_type.code == gdb.TYPE_CODE_STRUCT |
| 1306 | and gdb.types.has_field (basic_type, "i")): | 1317 | and gdb.types.has_field (basic_type, "i")): |
| 1307 | val = val["i"] | 1318 | val = val["i"] |
| 1308 | # Yield "XIL(N)", where N is a C integer. This helps humans | 1319 | |
| 1309 | # distinguish Lisp_Object values from ordinary integers even | 1320 | # For nil, yield "XIL(0)", which is easier to read than "XIL(0x0)". |
| 1310 | # when Lisp_Object is an integer. Perhaps some day the | ||
| 1311 | # pretty-printing could be fancier. | ||
| 1312 | if not val: | 1321 | if not val: |
| 1313 | return "XIL(0)" # Easier to read than "XIL(0x0)". | 1322 | return "XIL(0)" |
| 1314 | return "XIL(0x%x)" % int(val) | 1323 | |
| 1324 | # Extract the integer representation of the value and its Lisp type. | ||
| 1325 | ival = int(val) | ||
| 1326 | itype = ival >> (0 if USE_LSB_TAG else VALBITS) | ||
| 1327 | itype = itype & ((1 << GCTYPEBITS) - 1) | ||
| 1328 | |||
| 1329 | # For a Lisp integer N, yield "make_number(N)". | ||
| 1330 | if itype == Lisp_Int0 or itype == Lisp_Int1: | ||
| 1331 | if USE_LSB_TAG: | ||
| 1332 | ival = ival >> (GCTYPEBITS - 1) | ||
| 1333 | elif (ival >> VALBITS) & 1: | ||
| 1334 | ival = ival | (-1 << VALBITS) | ||
| 1335 | else: | ||
| 1336 | ival = ival & ((1 << VALBITS) - 1) | ||
| 1337 | return "make_number(%d)" % ival | ||
| 1338 | |||
| 1339 | # For non-integers other than nil yield "XIL(N)", where N is a C integer. | ||
| 1340 | # This helps humans distinguish Lisp_Object values from ordinary | ||
| 1341 | # integers even when Lisp_Object is an integer. | ||
| 1342 | # Perhaps some day the pretty-printing could be fancier. | ||
| 1343 | # Prefer the unsigned representation to negative values, converting | ||
| 1344 | # by hand as val.cast(gdb.lookup_type("EMACS_UINT") does not work in | ||
| 1345 | # GDB 7.12.1; see <http://patchwork.sourceware.org/patch/11557/>. | ||
| 1346 | if ival < 0: | ||
| 1347 | ival = ival + (1 << EMACS_INT_WIDTH) | ||
| 1348 | return "XIL(0x%x)" % ival | ||
| 1315 | 1349 | ||
| 1316 | def build_pretty_printer (): | 1350 | def build_pretty_printer (): |
| 1317 | pp = Emacs_Pretty_Printers ("Emacs") | 1351 | pp = Emacs_Pretty_Printers ("Emacs") |
| @@ -1321,3 +1355,8 @@ if hasattr(gdb, 'printing'): | |||
| 1321 | gdb.printing.register_pretty_printer (gdb.current_objfile (), | 1355 | gdb.printing.register_pretty_printer (gdb.current_objfile (), |
| 1322 | build_pretty_printer (), True) | 1356 | build_pretty_printer (), True) |
| 1323 | end | 1357 | end |
| 1358 | |||
| 1359 | # GDB mishandles indentation with leading tabs when feeding it to Python. | ||
| 1360 | # Local Variables: | ||
| 1361 | # indent-tabs-mode: nil | ||
| 1362 | # End: | ||