nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
41.3k stars 6.58k forks source link

gdb-pretty-print broken since m_data added #4309

Closed blackworm27 closed 2 months ago

blackworm27 commented 3 months ago

Description

The pretty printer Python script for gdb, located at tools/gdb_pretty_printer/nlohmann-json.py, is broken since the addition of the m_data member in the json object. SOLUTION: The solution is to first dereference 'm_data' before dereferencing 'm_type' or 'm_value' in the three places they occur in the nlohmann-json.py script. A corrected script (renamed to .txt) nlohmann-json.py.txt is attached to this bug.

Reproduction steps

Following the README.md in tools/gdb_pretty_printer/README.md does not work as described. gdb reports 'Cannot instantiate printer for default visualiser' and the console says Python Exception <class 'gdb.error'>: There is no member or method named m_type. This is a regression from 3.11.2, where it does work.

Expected vs. actual results

Expected printing of json objects in gdb to work. Instead, an error message is given.

Minimal code example

nlohmann::json a;
// Attempting to pretty-print this object in gdb fails in nlohmann-json 3.11.3

Error messages

Python Exception <class 'gdb.error'>: There is no member or method named m_type.
Python Exception <class 'gdb.error'>: There is no member or method named m_type.
$1 = {
  <nlohmann::json_abi_v3_11_3::detail::json_default_base> = {<No data fields>}, 
  members of nlohmann::json_abi_v3_11_3::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void>:
  m_data = {
    m_type = nlohmann::json_abi_v3_11_3::detail::value_t::object,
    m_value = {
      object = 0x555555a543e0,
      array = 0x555555a543e0,
      string = 0x555555a543e0,
      binary = 0x555555a543e0,
      boolean = 224,
      number_integer = 93824997475296,
      number_unsigned = 93824997475296,
      number_float = 4.6355707973685445e-310
    }
  }
}

Compiler and operating system

Linux Ubuntu 20.04, gdb 12.1

Library version

3.11.3

Validation