无法实现:无法获取变量的值

时间:2021-05-23 23:16:51

I have compiled a cpp file with this command line: g++ -g test.cpp

我用以下命令行编译了一个cpp文件:g++ - gtest .cpp

It throws an exception at line 28. I want to investigate the cause by inspecting the variables in lldb. I set a break point at line 28 and run the a.out in lldb.

它在第28行抛出一个异常。我想通过检查lldb中的变量来调查原因。我在第28行设置断点并运行a。lldb。

(lldb) n
Process 84233 stopped
* thread #1: tid = 0xa44b86, 0x00000001000017fb a.out`say(s=<unavailable>) + 987 at so.cpp:28, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x00000001000017fb a.out`say(s=<unavailable>) + 987 at so.cpp:28
   25       }
   26       else{
   27           s.insert(0, to_string(sz));
-> 28           s.erase(2, sz-1);
   29       }
   30       return s;
   31   }
(lldb) po s
error: Couldn't materialize: couldn't get the value of variable s: variable not available
Errored out in Execute, couldn't PrepareToExecuteJITExpression

Why the error message? How can I inspect the variable s?

为什么错误消息?如何检查变量s?

lldb version: lldb-320.4.115.3

版本:lldb lldb-320.4.115.3

g++ version: Configured with: --prefix=/Applications/Xcode6-Beta5.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.45.3) (based on LLVM 3.5svn) Target: x86_64-apple-darwin13.3.0 Thread model: posix

g++版本:配置为:-前缀=/应用程序/Xcode6-Beta5。app/ content /Developer/usr -with-gxx-include dir=/usr/include/c++/4.2.1 Apple LLVM 6.0(基于LLVM 3.5svn)目标:x86_64-apple-darwin13.3.0线程模型:posix

3 个解决方案

#1


18  

That error means the debug information does mention the variable, but says it has no storage location at the current PC.

这个错误意味着调试信息确实提到了这个变量,但是说它在当前PC上没有存储位置。

That can be because the variable got optimized out (unlikely given you are just calling a function on the variable) or because the compiler flubbed the debug info for the variable and lost track of where it went.

这可能是因为变量得到了优化(不太可能是在变量上调用函数),或者因为编译器为变量添加了调试信息,并丢失了它的去向。

Make sure you are compiling the code you are trying to debug at -O0 as there aren't many compilers that emit good debug information at higher optimization levels. If you are compiling at -O0, this is a compiler bug. You should probably report it to the gcc folks. You could see if you have better luck with clang. Otherwise, you have to read the assembly of the function to figure out where the variable actually lives, then tell the debugger to print the appropriately cast address.

请确保您正在编译您试图在-O0处调试的代码,因为在更高的优化级别上没有许多编译器发出良好的调试信息。如果你在-O0编译,这是一个编译错误。您应该向gcc人员报告一下。你可以看看你是否有更好的运气。否则,您必须读取该函数的程序集,以确定变量实际生活的位置,然后告诉调试器打印适当的cast地址。

#2


12  

I had this problem when I enabled the "Address Sanitizer" from my app scheme. Disable it fixed the issue.

当我在应用程序方案中启用“地址消毒剂”时,我遇到了这个问题。禁用它修复了问题。

#3


8  

I see this when I run a RELEASE (vs a DEBUG) build (Product->Scheme...->Edit Scheme...->Info, then set Build Configuration to "Debug".

当我运行一个发行版(vs调试)构建(Product->Scheme)时,我看到了这一点。- >编辑计划…->信息,然后设置构建配置为“Debug”。

#1


18  

That error means the debug information does mention the variable, but says it has no storage location at the current PC.

这个错误意味着调试信息确实提到了这个变量,但是说它在当前PC上没有存储位置。

That can be because the variable got optimized out (unlikely given you are just calling a function on the variable) or because the compiler flubbed the debug info for the variable and lost track of where it went.

这可能是因为变量得到了优化(不太可能是在变量上调用函数),或者因为编译器为变量添加了调试信息,并丢失了它的去向。

Make sure you are compiling the code you are trying to debug at -O0 as there aren't many compilers that emit good debug information at higher optimization levels. If you are compiling at -O0, this is a compiler bug. You should probably report it to the gcc folks. You could see if you have better luck with clang. Otherwise, you have to read the assembly of the function to figure out where the variable actually lives, then tell the debugger to print the appropriately cast address.

请确保您正在编译您试图在-O0处调试的代码,因为在更高的优化级别上没有许多编译器发出良好的调试信息。如果你在-O0编译,这是一个编译错误。您应该向gcc人员报告一下。你可以看看你是否有更好的运气。否则,您必须读取该函数的程序集,以确定变量实际生活的位置,然后告诉调试器打印适当的cast地址。

#2


12  

I had this problem when I enabled the "Address Sanitizer" from my app scheme. Disable it fixed the issue.

当我在应用程序方案中启用“地址消毒剂”时,我遇到了这个问题。禁用它修复了问题。

#3


8  

I see this when I run a RELEASE (vs a DEBUG) build (Product->Scheme...->Edit Scheme...->Info, then set Build Configuration to "Debug".

当我运行一个发行版(vs调试)构建(Product->Scheme)时,我看到了这一点。- >编辑计划…->信息,然后设置构建配置为“Debug”。