Printing C++ class objects with GDB

前端 未结 4 1270
不思量自难忘°
不思量自难忘° 2021-01-12 19:54

Is there some \"default function\" to print an object like a string on the GDB when we are debugging C++ applications? Something like: toString();

Or my class have t

4条回答
  •  自闭症患者
    2021-01-12 20:52

    You can call any member functions from Standard Library or your own data type during debug session. This is sometimes the easiest way to output object state in gdb. For std::string you could call it's c_str() member which returns const char*:

    (gdb) p str.c_str()
    $1 = "Hello, World!"
    

    Though this will work only for debugging live process, but not for core dump debugging.

提交回复
热议问题