I'm using CLion on Linux and having difficulties with debugging. I evaluated an expression which ends up being a string, but the debugger is useless at showing me what the return value is, other than that it is a string. How do I see the actual value? (also note it doesn't even show the value of char
values)
Asked
Active
Viewed 6,597 times
31

patatahooligan
- 3,111
- 1
- 18
- 27

Earlz
- 62,085
- 98
- 303
- 499
-
Please check that *Enable GNU C++ Value Renderers* option is on in *Settings -> Build, Execution, Deployment -> Debugger*. – Eldar Abusalimov Feb 13 '17 at 09:00
-
@EldarAbusalimov I have enabled that, but all I got is random hexadecimal value, not the real one. – ismailsunni Mar 21 '17 at 01:53
-
@ismailsunni Could you check a workaround suggested in https://youtrack.jetbrains.com/issue/CPP-6828 (`add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)`)? Does it help? – Eldar Abusalimov Mar 22 '17 at 09:18
-
I know old question, but just refer to this [issue](https://stackoverflow.com/questions/40327089/in-clions-debugger-how-do-i-show-the-entire-contents-of-an-int-array) here. – kuwiano Jan 16 '20 at 22:24
3 Answers
6
With gdb you can print std::string by below 2 methods.
- p mystr.c_str() -this can be used to print value of type std::string.
- p *(char**) 0x7f8fbb7a9c20 -this works for a memory with type std::string.

leoram111
- 61
- 1
- 3
-
18It’s 2020, and this is how we have to print std::string Values in a debugger: `p *(char**) 0x7f8fbb7a9c20`... – NicholasM Jan 28 '20 at 06:53
1
It seems like a bug of LLDB. You can check this issue: https://youtrack.jetbrains.com/issue/CPP-13701
I have tried GDB, and it works well, so you can switch to GDB toolchains to avoid this problem.
However, in 2021, if you have to use LLDB, you can use the memory address of the variable std::string mystr;
- In LLDB console:
p *(char**) &mystr
- Or, add this expression
*(char**) &mystr
into the watcher window of CLion-2021 debugger

micfan
- 800
- 8
- 12
0
Just add a watch for a desired std::string
expression and edit the watch to append .c_str()
(F2 will work fine for that).
E.g. for examining the my_cpp_str
variable, add the following watch:
my_cpp_str.c_str()

Maxim Grachev
- 429
- 4
- 5