1# gdb-json-pretty-printer 2This is a printer that prints variables in json format. 3## Install in GDB 4Copy the content in gdbinit into your ~/.gdbinit, replace the path <path_to_gdb_json_printer> by the actual path of gdb_json_printer directory. 5## Run tests 6First, in the gdb_json_printer directory, compile each example program with O0 optimization 7``` 8g++ test_examples/basic_types.cpp -O0 -g -o test_examples/basic_types 9g++ test_examples/objects1.cpp -O0 -g -o test_examples/objects1 10g++ test_examples/objects2.cpp -O0 -g -o test_examples/objects2 11g++ test_examples/objects.cpp -O0 -g -o test_examples/objects 12g++ test_examples/array.cpp -O0 -g -o test_examples/array 13g++ test_examples/reference.cpp -O0 -g -o test_examples/reference 14``` 15second, run gdb in the gdb_json_printer directory: 16``` 17gdb 18``` 19finally, source the test script: 20``` 21source test/gdb_json_printer_test.py 22``` 23## printing format 24``` 25Pointer := { 26 type: 'pointer', 27 ctype: ctype for pointer, 28 address: Address, 29 reference: Struct 30} 31 32Struct := { 33 type: 'struct', 34 ctype: ctype for struct, 35 address: Address, 36 fields: StructField[] 37} 38 39StructField := { 40 field: name of field, 41 field_type: 'base_class' or 'argument' 42 value: Value 43} 44 45Int := { 46 type: 'int', 47 ctype: ctype for int, 48 address: Address, 49 value: number 50} 51 52Float := { 53 type: 'float', 54 ctype: 'float' or 'double', 55 address: Address, 56 value: number 57} 58 59Enum := { 60 type: 'enum', 61 ctype: ctype for enum, 62 address: Address, 63 value: number 64} 65 66Visit variable := { 67 type: 'visited', 68 ctype: ctype for struct, 69 address: Address, 70} 71 72``` 73 74## problem to solve 75* support for print parent/child class members. 76* the printer treats all arrays as pointers now. We expected it to have ability to extract array/buffer length. 77* the printer prints smart pointers into a super complex json block. Maybe we need some specific printer for these common objects.