diff options
| author | Paul Eggert | 2017-05-05 15:59:24 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-05-05 16:04:49 -0700 |
| commit | 2b91f3d1eac402128c753e0780c50488a4f9cacb (patch) | |
| tree | c72eaee26faaed98c54c545fa243da1f61846b57 | |
| parent | 1c9c02f51cc24954536e3e2536c5b2c1d571e3df (diff) | |
| download | emacs-2b91f3d1eac402128c753e0780c50488a4f9cacb.tar.gz emacs-2b91f3d1eac402128c753e0780c50488a4f9cacb.zip | |
Pretty-print Lisp_Object values in GDB
* src/.gdbinit: Add a pretty-printer for Lisp_Object values. Now,
GDB displays them as "XIL(0xXXX)" rather than displaying them
as "..." when CHECK_LISP_OBJECT_TYPE is in effect and as "DDDDD"
otherwise.
| -rw-r--r-- | src/.gdbinit | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/.gdbinit b/src/.gdbinit index 6d7476d5a72..0596188e050 100644 --- a/src/.gdbinit +++ b/src/.gdbinit | |||
| @@ -1264,3 +1264,60 @@ commands | |||
| 1264 | end | 1264 | end |
| 1265 | continue | 1265 | continue |
| 1266 | end | 1266 | end |
| 1267 | |||
| 1268 | |||
| 1269 | # Put the Python code at the end of .gdbinit so that if GDB does not | ||
| 1270 | # support Python, GDB will do all the above initializations before | ||
| 1271 | # reporting an error. | ||
| 1272 | |||
| 1273 | python | ||
| 1274 | |||
| 1275 | # Omit pretty-printing in older (pre-7.3) GDBs that lack it. | ||
| 1276 | if hasattr(gdb, 'printing'): | ||
| 1277 | |||
| 1278 | class Emacs_Pretty_Printers (gdb.printing.RegexpCollectionPrettyPrinter): | ||
| 1279 | """A collection of pretty-printers. This is like GDB's | ||
| 1280 | RegexpCollectionPrettyPrinter except when printing Lisp_Object.""" | ||
| 1281 | def __call__ (self, val): | ||
| 1282 | """Look up the pretty-printer for the provided value.""" | ||
| 1283 | type = val.type | ||
| 1284 | typename = type.tag or type.name | ||
| 1285 | basic_type = gdb.types.get_basic_type (type) | ||
| 1286 | basic_typename = basic_type.tag or basic_type.name | ||
| 1287 | for printer in self.subprinters: | ||
| 1288 | if (printer.enabled | ||
| 1289 | and ((printer.regexp == '^Lisp_Object$' | ||
| 1290 | and typename == 'Lisp_Object') | ||
| 1291 | or (basic_typename | ||
| 1292 | and printer.compiled_re.search (basic_typename)))): | ||
| 1293 | return printer.gen_printer (val) | ||
| 1294 | return None | ||
| 1295 | |||
| 1296 | class Lisp_Object_Printer: | ||
| 1297 | "A printer for Lisp_Object values." | ||
| 1298 | def __init__ (self, val): | ||
| 1299 | self.val = val | ||
| 1300 | |||
| 1301 | def to_string (self): | ||
| 1302 | "Yield a string that can be fed back into GDB." | ||
| 1303 | val = self.val | ||
| 1304 | basic_type = gdb.types.get_basic_type (val.type) | ||
| 1305 | if (basic_type.code == gdb.TYPE_CODE_STRUCT | ||
| 1306 | and gdb.types.has_field (basic_type, "i")): | ||
| 1307 | val = val["i"] | ||
| 1308 | # Yield "XIL(N)", where N is a C integer. This helps humans | ||
| 1309 | # distinguish Lisp_Object values from ordinary integers even | ||
| 1310 | # when Lisp_Object is an integer. Perhaps some day the | ||
| 1311 | # pretty-printing could be fancier. | ||
| 1312 | if not val: | ||
| 1313 | return "XIL(0)" # Easier to read than "XIL(0x0)". | ||
| 1314 | return "XIL(0x%x)" % val | ||
| 1315 | |||
| 1316 | def build_pretty_printer (): | ||
| 1317 | pp = Emacs_Pretty_Printers ("Emacs") | ||
| 1318 | pp.add_printer ('Lisp_Object', '^Lisp_Object$', Lisp_Object_Printer) | ||
| 1319 | return pp | ||
| 1320 | |||
| 1321 | gdb.printing.register_pretty_printer (gdb.current_objfile (), | ||
| 1322 | build_pretty_printer (), True) | ||
| 1323 | end | ||