简体   繁体   中英

VS2017 Debugger : has no address, possibly due to compiler optimizations

Seems not relevant to some questions with similar titles.

//some other code
std::string s = Lookup->getName().str();
-> break here //some other code

Note: "Lookup" is clang::DirectoryLookup http://clang.llvm.org/doxygen/classclang_1_1DirectoryLookup.html , "Lookup->getName()" is llvm::StringRef http://llvm.org/doxygen/classllvm_1_1StringRef.html .

When break at the above place, in the "Watch" pane in VS2017, the string variable "s" is initialized successfully and its value can be shown in "Watch" pane.

But when try to show(watch) the expression "Lookup->getName().str()" which is just how "s" is initialized, it says:

Lookup->getName().str() | Function llvm::StringRef::str has no address, possibly due to compiler optimizations. 

the source code of StringRef::str() is:

/// str - Get the contents as an std::string.
LLVM_NODISCARD
std::string str() const {
  if (!Data) return std::string();
  return std::string(Data, Length);
}

And all the libraries is in debug version. Based on the above fact, there seems to be no reason for this to happen.

Such thing happens in other situations during debuging a Clang Libtooling program and it make debugging very hard.

What is the possible reason and how to solve it?

我尝试了 @user15331850 解决方案,但没有帮助,但是将 Linker-> Debugging-> Generate Debug Info 设置为 "/DEBUG:FULL" 似乎现在给了我所有变量。

This may be due to optimization option is enabled . You can disable the same by following these steps:

  • Right click on the solution
  • Click on the "properties"
  • From the left pane, click on the "Configuration Properties"
  • Click on "C/C++" from the sub-option
  • Then click on the "optimization" and select "Disabled(/Od)" from the list

That's it. Hope it works for you!!

I had this issue. I needed to change the settings for: Linker-> Debugging-> Generate Debug Info from "/DEBUG:FASTLINK" to "/DEBUG".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM