mirror of
https://github.com/nlohmann/json.git
synced 2025-07-28 12:02:00 +03:00
Reorganize directories (#3462)
* 🚚 move files * 🚚 rename doc folder to docs * 🚚 rename test folder to tests
This commit is contained in:
28
tools/gdb_pretty_printer/nlohmann-json.py
Normal file
28
tools/gdb_pretty_printer/nlohmann-json.py
Normal file
@ -0,0 +1,28 @@
|
||||
import gdb
|
||||
|
||||
class JsonValuePrinter:
|
||||
"Print a json-value"
|
||||
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
def to_string(self):
|
||||
if self.val.type.strip_typedefs().code == gdb.TYPE_CODE_FLT:
|
||||
return ("%.6f" % float(self.val)).rstrip("0")
|
||||
return self.val
|
||||
|
||||
def json_lookup_function(val):
|
||||
name = val.type.strip_typedefs().name
|
||||
if name and name.startswith("nlohmann::basic_json<") and name.endswith(">"):
|
||||
t = str(val['m_type'])
|
||||
if t.startswith("nlohmann::detail::value_t::"):
|
||||
try:
|
||||
union_val = val['m_value'][t[27:]]
|
||||
if union_val.type.code == gdb.TYPE_CODE_PTR:
|
||||
return gdb.default_visualizer(union_val.dereference())
|
||||
else:
|
||||
return JsonValuePrinter(union_val)
|
||||
except:
|
||||
return JsonValuePrinter(val['m_type'])
|
||||
|
||||
gdb.pretty_printers.append(json_lookup_function)
|
Reference in New Issue
Block a user