|
| 1 | +# gdb-natvis |
| 2 | +This implements [Natvis](https://msdn.microsoft.com/en-us/library/jj620914.aspx) based pretty printing in GDB. |
| 3 | +GDB exposes a python API for writing pretty printers of certain types which is used by this project. |
| 4 | + |
| 5 | +This project will allow creating custom pretty printers for GDB without having to write and deploy python code |
| 6 | +for every type. It will also allow using the existing visualizers written for Visual Studio without changes. |
| 7 | + |
| 8 | +## Dependencies |
| 9 | +- GDB built with Python 3.6 |
| 10 | +- libclang (tested with version 5.0) with Python bindings |
| 11 | + |
| 12 | +## Installation |
| 13 | +Clone this repository somewhere and add the following to your `.gdbinit`: |
| 14 | +```python |
| 15 | +python |
| 16 | +sys.path.insert(0, "/path/to/gdb-natvis/src") |
| 17 | +try: |
| 18 | + import printer |
| 19 | +except ImportError: |
| 20 | + printer = None |
| 21 | + import traceback |
| 22 | + traceback.print_exc() |
| 23 | +else: |
| 24 | + printer.add_natvis_printers() |
| 25 | +end |
| 26 | +``` |
| 27 | + |
| 28 | +This will automatically try to load natvis files if GDB tries to pretty-print a type. The auto-discovery of natvis |
| 29 | +files works by determining the file of the type being printed and then examining every parent directory for `.natvis` |
| 30 | +files. This will obviously not work in all cases so this also adds a `add-nativs` command to GDB. |
| 31 | + |
| 32 | +This command can be called with the path to one or more `.natvis` files which will then be loaded and used by subsequent |
| 33 | +pretty printing operations. |
| 34 | + |
| 35 | +## Supported Features |
| 36 | +This already supports a wide array of features available in the Natvis system: |
| 37 | +- Type name matching with template parameters (including wildcards) |
| 38 | +- `DisplayString` with embedded expressions. Format specifiers are parsed but not used at the moment |
| 39 | +- `Condition` for most XML elements |
| 40 | +- Most `Expand` items are supported |
| 41 | + - `Item` is fully supported |
| 42 | + - `ArrayItems` is supported for the simple case (`Size` and `ValuePointer`) |
| 43 | + - `IndexListItems` including `$i` parameters |
| 44 | + - `ExpandedItem` |
| 45 | + |
| 46 | +## Known issues |
| 47 | +- The expression parser does not support all syntax elements yet |
| 48 | +- Global variables are not resolved |
| 49 | +- GDB issue: MI clients (such as CDT or CLion) do not receive the `to_string` value of a python pretty printer. This hides the `DisplayString` value since that uses `to_string`. As a workaround, the display string is added as a child instead. There is a GDB patch that fixes this issue: https://sourceware.org/bugzilla/show_bug.cgi?id=11335 |
0 commit comments