C++ debug of nlohmann json using GDBWhat are the differences between a pointer variable and a reference variable in C++?How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?The Definitive C++ Book Guide and ListWhat is the correct JSON content type?What is the “-->” operator in C++?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?

Can I sign legal documents with a smiley face?

Is aluminum electrical wire used on aircraft?

Why should universal income be universal?

What does chmod -u do?

Aragorn's "guise" in the Orthanc Stone

Is it improper etiquette to ask your opponent what his/her rating is before the game?

Did Swami Prabhupada reject Advaita?

How do you make your own symbol when Detexify fails?

Is it safe to use olive oil to clean the ear wax?

Rising and falling intonation

How can I block email signup overlays or javascript popups in Safari?

A social experiment. What is the worst that can happen?

L1 and Ln cache: when are they written?

On a tidally locked planet, would time be quantized?

The Staircase of Paint

Why did the EU agree to delay the Brexit deadline?

Why Shazam when there is already Superman?

lightning-datatable row number error

What should you do when eye contact makes your subordinate uncomfortable?

Terse Method to Swap Lowest for Highest?

How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?

Closed-form expression for certain product

Are paving bricks differently sized for sand bedding vs mortar bedding?

copy and scale one figure (wheel)



C++ debug of nlohmann json using GDB


What are the differences between a pointer variable and a reference variable in C++?How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?The Definitive C++ Book Guide and ListWhat is the correct JSON content type?What is the “-->” operator in C++?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?













8















I'm working on a project using nlohmann's json C++ implementation.



How can one easily explore nlohmann's JSON keys/vals in GDB ?



I tried to use this STL gdb wrapping since it provides helpers to explore STL structures that lohmann's JSON lib is using.
But I don't find it convenient.



Here is a simple use case:



json foo;
foo["flex"] = 0.2;
foo["awesome_str"] = "bleh";
foo["nested"] = "bar", "barz";


What I would like to have in GDB:



(gdb) p foo

"flex" : 0.2,
"awesome_str": "bleh",
"nested": etc.



Current behavior



(gdb) p foo
$1 =
m_type = nlohmann::detail::value_t::object,
m_value =
object = 0x129ccdd0,
array = 0x129ccdd0,
string = 0x129ccdd0,
boolean = 208,
number_integer = 312266192,
number_unsigned = 312266192,
number_float = 1.5427999782486669e-315


(gdb) p foo.at("flex")
Cannot evaluate function -- may be inlined // I suppose it depends on my compilation process. But I guess it does not invalidate the question.
(gdb) p *foo.m_value.object
$2 =
_M_t =
_M_impl =
<std::allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer> > > >> =
<__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer> > > >> = <No data fields>, <No data fields>,
<std::_Rb_tree_key_compare<std::less<void> >> =
_M_key_compare = <No data fields>
,
<std::_Rb_tree_header> =
_M_header =
_M_color = std::_S_red,
_M_parent = 0x4d72d0,
_M_left = 0x4d7210,
_M_right = 0x4d7270
,
_M_node_count = 5
, <No data fields>











share|improve this question




























    8















    I'm working on a project using nlohmann's json C++ implementation.



    How can one easily explore nlohmann's JSON keys/vals in GDB ?



    I tried to use this STL gdb wrapping since it provides helpers to explore STL structures that lohmann's JSON lib is using.
    But I don't find it convenient.



    Here is a simple use case:



    json foo;
    foo["flex"] = 0.2;
    foo["awesome_str"] = "bleh";
    foo["nested"] = "bar", "barz";


    What I would like to have in GDB:



    (gdb) p foo

    "flex" : 0.2,
    "awesome_str": "bleh",
    "nested": etc.



    Current behavior



    (gdb) p foo
    $1 =
    m_type = nlohmann::detail::value_t::object,
    m_value =
    object = 0x129ccdd0,
    array = 0x129ccdd0,
    string = 0x129ccdd0,
    boolean = 208,
    number_integer = 312266192,
    number_unsigned = 312266192,
    number_float = 1.5427999782486669e-315


    (gdb) p foo.at("flex")
    Cannot evaluate function -- may be inlined // I suppose it depends on my compilation process. But I guess it does not invalidate the question.
    (gdb) p *foo.m_value.object
    $2 =
    _M_t =
    _M_impl =
    <std::allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer> > > >> =
    <__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer> > > >> = <No data fields>, <No data fields>,
    <std::_Rb_tree_key_compare<std::less<void> >> =
    _M_key_compare = <No data fields>
    ,
    <std::_Rb_tree_header> =
    _M_header =
    _M_color = std::_S_red,
    _M_parent = 0x4d72d0,
    _M_left = 0x4d7210,
    _M_right = 0x4d7270
    ,
    _M_node_count = 5
    , <No data fields>











    share|improve this question


























      8












      8








      8








      I'm working on a project using nlohmann's json C++ implementation.



      How can one easily explore nlohmann's JSON keys/vals in GDB ?



      I tried to use this STL gdb wrapping since it provides helpers to explore STL structures that lohmann's JSON lib is using.
      But I don't find it convenient.



      Here is a simple use case:



      json foo;
      foo["flex"] = 0.2;
      foo["awesome_str"] = "bleh";
      foo["nested"] = "bar", "barz";


      What I would like to have in GDB:



      (gdb) p foo

      "flex" : 0.2,
      "awesome_str": "bleh",
      "nested": etc.



      Current behavior



      (gdb) p foo
      $1 =
      m_type = nlohmann::detail::value_t::object,
      m_value =
      object = 0x129ccdd0,
      array = 0x129ccdd0,
      string = 0x129ccdd0,
      boolean = 208,
      number_integer = 312266192,
      number_unsigned = 312266192,
      number_float = 1.5427999782486669e-315


      (gdb) p foo.at("flex")
      Cannot evaluate function -- may be inlined // I suppose it depends on my compilation process. But I guess it does not invalidate the question.
      (gdb) p *foo.m_value.object
      $2 =
      _M_t =
      _M_impl =
      <std::allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer> > > >> =
      <__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer> > > >> = <No data fields>, <No data fields>,
      <std::_Rb_tree_key_compare<std::less<void> >> =
      _M_key_compare = <No data fields>
      ,
      <std::_Rb_tree_header> =
      _M_header =
      _M_color = std::_S_red,
      _M_parent = 0x4d72d0,
      _M_left = 0x4d7210,
      _M_right = 0x4d7270
      ,
      _M_node_count = 5
      , <No data fields>











      share|improve this question
















      I'm working on a project using nlohmann's json C++ implementation.



      How can one easily explore nlohmann's JSON keys/vals in GDB ?



      I tried to use this STL gdb wrapping since it provides helpers to explore STL structures that lohmann's JSON lib is using.
      But I don't find it convenient.



      Here is a simple use case:



      json foo;
      foo["flex"] = 0.2;
      foo["awesome_str"] = "bleh";
      foo["nested"] = "bar", "barz";


      What I would like to have in GDB:



      (gdb) p foo

      "flex" : 0.2,
      "awesome_str": "bleh",
      "nested": etc.



      Current behavior



      (gdb) p foo
      $1 =
      m_type = nlohmann::detail::value_t::object,
      m_value =
      object = 0x129ccdd0,
      array = 0x129ccdd0,
      string = 0x129ccdd0,
      boolean = 208,
      number_integer = 312266192,
      number_unsigned = 312266192,
      number_float = 1.5427999782486669e-315


      (gdb) p foo.at("flex")
      Cannot evaluate function -- may be inlined // I suppose it depends on my compilation process. But I guess it does not invalidate the question.
      (gdb) p *foo.m_value.object
      $2 =
      _M_t =
      _M_impl =
      <std::allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer> > > >> =
      <__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer> > > >> = <No data fields>, <No data fields>,
      <std::_Rb_tree_key_compare<std::less<void> >> =
      _M_key_compare = <No data fields>
      ,
      <std::_Rb_tree_header> =
      _M_header =
      _M_color = std::_S_red,
      _M_parent = 0x4d72d0,
      _M_left = 0x4d7210,
      _M_right = 0x4d7270
      ,
      _M_node_count = 5
      , <No data fields>








      c++ json gdb






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago







      LoneWanderer

















      asked 4 hours ago









      LoneWandererLoneWanderer

      1,072824




      1,072824






















          1 Answer
          1






          active

          oldest

          votes


















          10














          I found my own answer reading further the GDB capabilities and stack overflow questions concerning print of std::string.



          I simply defined a gdb command as follows:



          # this is a gdb script
          # can be loaded from gdb using
          # source my_script.txt (or. gdb or whatever you like)
          define pjson
          # use the lohmann's builtin dump method, ident 4 and use space separator
          printf "%sn", $arg0.dump(4, ' ', true).c_str()
          end
          # configure command helper (text displayed when typing 'help pjson' in gdb)
          document pjson
          Prints a lohmann's JSON C++ variable as a human-readable JSON string
          end


          Using it in gdb:



          (gdb) source my_custom_script.gdb
          (gdb) pjson foo

          "flex" : 0.2,
          "awesome_str": "bleh",
          "nested":
          "bar": "barz"







          share|improve this answer

























          • That looks pretty useful. Unfortunately I am out of votes ATM.

            – πάντα ῥεῖ
            4 hours ago











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316620%2fc-debug-of-nlohmann-json-using-gdb%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          10














          I found my own answer reading further the GDB capabilities and stack overflow questions concerning print of std::string.



          I simply defined a gdb command as follows:



          # this is a gdb script
          # can be loaded from gdb using
          # source my_script.txt (or. gdb or whatever you like)
          define pjson
          # use the lohmann's builtin dump method, ident 4 and use space separator
          printf "%sn", $arg0.dump(4, ' ', true).c_str()
          end
          # configure command helper (text displayed when typing 'help pjson' in gdb)
          document pjson
          Prints a lohmann's JSON C++ variable as a human-readable JSON string
          end


          Using it in gdb:



          (gdb) source my_custom_script.gdb
          (gdb) pjson foo

          "flex" : 0.2,
          "awesome_str": "bleh",
          "nested":
          "bar": "barz"







          share|improve this answer

























          • That looks pretty useful. Unfortunately I am out of votes ATM.

            – πάντα ῥεῖ
            4 hours ago
















          10














          I found my own answer reading further the GDB capabilities and stack overflow questions concerning print of std::string.



          I simply defined a gdb command as follows:



          # this is a gdb script
          # can be loaded from gdb using
          # source my_script.txt (or. gdb or whatever you like)
          define pjson
          # use the lohmann's builtin dump method, ident 4 and use space separator
          printf "%sn", $arg0.dump(4, ' ', true).c_str()
          end
          # configure command helper (text displayed when typing 'help pjson' in gdb)
          document pjson
          Prints a lohmann's JSON C++ variable as a human-readable JSON string
          end


          Using it in gdb:



          (gdb) source my_custom_script.gdb
          (gdb) pjson foo

          "flex" : 0.2,
          "awesome_str": "bleh",
          "nested":
          "bar": "barz"







          share|improve this answer

























          • That looks pretty useful. Unfortunately I am out of votes ATM.

            – πάντα ῥεῖ
            4 hours ago














          10












          10








          10







          I found my own answer reading further the GDB capabilities and stack overflow questions concerning print of std::string.



          I simply defined a gdb command as follows:



          # this is a gdb script
          # can be loaded from gdb using
          # source my_script.txt (or. gdb or whatever you like)
          define pjson
          # use the lohmann's builtin dump method, ident 4 and use space separator
          printf "%sn", $arg0.dump(4, ' ', true).c_str()
          end
          # configure command helper (text displayed when typing 'help pjson' in gdb)
          document pjson
          Prints a lohmann's JSON C++ variable as a human-readable JSON string
          end


          Using it in gdb:



          (gdb) source my_custom_script.gdb
          (gdb) pjson foo

          "flex" : 0.2,
          "awesome_str": "bleh",
          "nested":
          "bar": "barz"







          share|improve this answer















          I found my own answer reading further the GDB capabilities and stack overflow questions concerning print of std::string.



          I simply defined a gdb command as follows:



          # this is a gdb script
          # can be loaded from gdb using
          # source my_script.txt (or. gdb or whatever you like)
          define pjson
          # use the lohmann's builtin dump method, ident 4 and use space separator
          printf "%sn", $arg0.dump(4, ' ', true).c_str()
          end
          # configure command helper (text displayed when typing 'help pjson' in gdb)
          document pjson
          Prints a lohmann's JSON C++ variable as a human-readable JSON string
          end


          Using it in gdb:



          (gdb) source my_custom_script.gdb
          (gdb) pjson foo

          "flex" : 0.2,
          "awesome_str": "bleh",
          "nested":
          "bar": "barz"








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 hours ago

























          answered 4 hours ago









          LoneWandererLoneWanderer

          1,072824




          1,072824












          • That looks pretty useful. Unfortunately I am out of votes ATM.

            – πάντα ῥεῖ
            4 hours ago


















          • That looks pretty useful. Unfortunately I am out of votes ATM.

            – πάντα ῥεῖ
            4 hours ago

















          That looks pretty useful. Unfortunately I am out of votes ATM.

          – πάντα ῥεῖ
          4 hours ago






          That looks pretty useful. Unfortunately I am out of votes ATM.

          – πάντα ῥεῖ
          4 hours ago




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316620%2fc-debug-of-nlohmann-json-using-gdb%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Reverse int within the 32-bit signed integer range: [−2^31, 2^31 − 1]Combining two 32-bit integers into one 64-bit integerDetermine if an int is within rangeLossy packing 32 bit integer to 16 bitComputing the square root of a 64-bit integerKeeping integer addition within boundsSafe multiplication of two 64-bit signed integersLeetcode 10: Regular Expression MatchingSigned integer-to-ascii x86_64 assembler macroReverse the digits of an Integer“Add two numbers given in reverse order from a linked list”

          Category:Fedor von Bock Media in category "Fedor von Bock"Navigation menuUpload mediaISNI: 0000 0000 5511 3417VIAF ID: 24712551GND ID: 119294796Library of Congress authority ID: n96068363BnF ID: 12534305fSUDOC authorities ID: 034604189Open Library ID: OL338253ANKCR AUT ID: jn19990000869National Library of Israel ID: 000514068National Thesaurus for Author Names ID: 341574317ReasonatorScholiaStatistics

          Kiel Indholdsfortegnelse Historie | Transport og færgeforbindelser | Sejlsport og anden sport | Kultur | Kendte personer fra Kiel | Noter | Litteratur | Eksterne henvisninger | Navigationsmenuwww.kiel.de54°19′31″N 10°8′26″Ø / 54.32528°N 10.14056°Ø / 54.32528; 10.14056Oberbürgermeister Dr. Ulf Kämpferwww.statistik-nord.deDen danske Stats StatistikKiels hjemmesiderrrWorldCat312794080n790547494030481-4