Reputation: 25768
I am using XCode 6.1 to debug my C++ code, and I found some of the local variables are not displayed in debugging area, even when I use the "All Variables" setting.
I am wondering how to add those variables to the debugging list?
Or how to print out those missing variables on the LLDB? I tried with po test
, but it said:
error: use of undeclared identifier 'test'
Would I better switch to the Eclipse IDE for C++?
BTW, I am using CMake to generate XCode project, so maybe I miss something in the debug mode? I remembered if using gcc, I need -g option, do I need it when I use CLang?
Upvotes: 4
Views: 1108
Reputation: 27173
If you are getting the "undefined identifier" error, it is probably because the compiler didn't emit debug information for the variable. Even at -O0, the compiler won't emit debug info for variables that aren't used. So if all you have is:
int test = 0;
and then you never refer to test (e.g. pass it to a function or assign something to it), it is very likely the compiler won't emit debug info for it. This is true of both clang & gcc.
Note, lldb has two ways to view local variables. The "p" command runs the full expression parser, and can do lots of fancy things (access variables and types that aren't visible in the current scope, etc.) But in some cases, it can go off in the weeds.
The other command is "frame variable" which just prints all locals in the current scope. You can also do "frame variable test" to just view the local named test. This command just pulls locals straight from the debug info so while it can't be used to call functions, etc, it is pretty bullet proof.
Try that, and if test shows up in the "frame variable" output, but "p" doesn't show it, then if you can, please file a bug with your example to bugreporter.apple.com, we'd love to take a look.
If it doesn't show up in "frame variable" either, then this is probably an issue with the debug info generated by the compiler. If you have some local that you are using, and you are compiling at -O0 then it should show up in the debug info. If it isn't and you have an example showing this that you can make available, again, it would be great if you could file a bug.
Upvotes: 1
Reputation: 618
Xcode works fairly well for coding c++ from a code completion and highlighting standpoint, second only to Visual Studio in my opinion but debugging through Apple lldb is going to be very hit-or-miss. Templates are going to be the worst, often you're going to get errors about unable to materialize target or other archaic, infuriating errors related to the debugger getting confused about what you're asking or unable to find functions.
Unfortunately it's been this way for several versions and it seems c++ takes second place to objective-c and its probably going to be behind swift as well; it's probably not going to be fixed.
You're probably not going to have a better time with eclipse either and you'll be sacrificing a lot on the code completion, profiling, static analysis, etc.
The best recommendation is to make sure you're in debug mode so things don't get optimized away. If you want to inspect an expression especially one involving templates, place it in a local variable, the optimizer will do its job in a release build so there isn't a performance issue. It's the 21st century but unfortunately sometimes you'll just have to use std::cerr :(
Upvotes: 1