• Home
Name Date Size #Lines LOC

..--

README.mdD07-Sep-20242.7 KiB7963

nlohmann-json.pyD07-Sep-20241.2 KiB3327

README.md

1# GDB Pretty Printer
2
3File [nlohmann-json.py](nlohmann-json.py) contains a pretty printer for GDB for JSON values of this library. It was originally published as [Gist](https://gist.github.com/ssbssa/60da5339c6e6036b2afce17de06050ea#file-nlohmann-json-py) by [Hannes Domani](https://github.com/ssbssa).
4
5## How to use
6
7- Add line
8
9  ```
10  source /path/to/nlohmann-json.py
11  ```
12
13  to `~/.gdbinit`. Note you must replace `/path/to` with whatever path you stored file `nlohmann-json.py`.
14- In GDB, debug as usual. When you want to pretty-print a JSON value `var`, type
15
16  ```
17  p -pretty on -array on -- var
18  ```
19
20  The result should look like
21
22  ```
23    $1 = std::map with 5 elements = {
24        ["Baptiste"] = std::map with 1 element = {
25            ["first"] = "second"
26        },
27        ["Emmanuel"] = std::vector of length 3, capacity 3 = {
28            3,
29            "25",
30            0.5
31        },
32        ["Jean"] = 0.7,
33        ["Zorg"] = std::map with 8 elements = {
34            ["array"] = std::vector of length 3, capacity 3 = {
35                1,
36                0,
37                2
38            },
39            ["awesome_str"] = "bleh",
40            ["bool"] = true,
41            ["flex"] = 0.2,
42            ["float"] = 5.22,
43            ["int"] = 5,
44            ["nested"] = std::map with 1 element = {
45                ["bar"] = "barz"
46            },
47            ["trap "] = "you fell"
48        },
49        ["empty"] = nlohmann::detail::value_t::null
50    }
51    ```
52
53Requires Python 3.9+. Last tested with GDB 12.1.
54See [#1952](https://github.com/nlohmann/json/issues/1952) for more information. Please post questions there.
55
56## Copyright
57
58MIT License
59
60Copyright (C) 2020 [Hannes Domani](https://github.com/ssbssa)
61
62Permission is hereby granted, free of charge, to any person obtaining a copy
63of this software and associated documentation files (the "Software"), to deal
64in the Software without restriction, including without limitation the rights
65to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
66copies of the Software, and to permit persons to whom the Software is
67furnished to do so, subject to the following conditions:
68
69The above copyright notice and this permission notice shall be included in all
70copies or substantial portions of the Software.
71
72THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
73IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
74FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
75AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
76LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
77OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
78SOFTWARE.
79