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