2

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?

jw_
  • 1,663
  • 18
  • 32
  • 1
    Please see these, [one](https://stackoverflow.com/questions/54388905/compiler-optimizations-function-has-no-address), [two](https://stackoverflow.com/questions/27300112/function-has-no-address-despite-disabled-optimization-od).And maybe you can change to use static link library and then If it is implicit, the above method might work fine. If it is explicit, the call needs to be made using the stored function pointer. – Mr Qian Jan 14 '20 at 10:16

3 Answers3

2

I tried @user15331850 solution and it didn't help, but setting Linker-> Debugging-> Generate Debug Info to "/DEBUG:FULL" seems giving me all variables now.

rlf89
  • 1,336
  • 1
  • 11
  • 17
  • Thank. It works. How do you know the answer? May you provide some references? – cppBeginner Jul 01 '21 at 06:53
  • 1
    Glad it helped! I found it accidentally, but now here is a [link](https://learn.microsoft.com/en-us/cpp/build/reference/debug-generate-debug-info?view=msvc-160&viewFallbackFrom=vs-2019) that tells "/DEBUG:FULL" takes all symbols from all places to one big database file. It is heavy and slow, but it can show all variables. – rlf89 Jul 01 '21 at 16:05
0

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!!

  • 1
    It is already disabled. The question also mentioned other facts about why this should not happen. – jw_ Jan 13 '20 at 01:07
0

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