Cannot view std::string when compiled with clang

前端 未结 4 911
深忆病人
深忆病人 2021-02-12 13:38

g++ (GCC) 5.2.0

clang version 3.7.1 (tags/RELEASE_371/final)

GNU gdb (GDB) 7.12

Gdb is unable to locate the definition of std::string when compiled with

相关标签:
4条回答
  • 2021-02-12 14:22

    The last workaround mentioned in bug 24202 as linked by ks1322 is worth having a look at:

    -fno-limit-debug-info will make your debug info larger, slow link (if you're not using -gsplit-dwarf) and debugger performance. But, yes, will address this.

    Using -fno-limit-debug-info forces Clang to emit debug information for e.g. std::string at the cost of a larger binary while preserving compatibility with other libraries and the rest of the system/SDK.

    As ks1322 and Kevin mentioned, one can instead use -D_GLIBCXX_DEBUG to switch libstdc++ into debug mode but this comes at a heavy price: any library you link against and with which you exchange STL containers (string, vector, etc.) must also be built with -D_GLIBCXX_DEBUG. Meaning: your system/SDK must either support this with a separate set of libraries or you will have to rebuild them yourself.

    0 讨论(0)
  • 2021-02-12 14:31

    As ks1322 mentioned, this is because clang has decided not to emit debug information for libstc++.

    You can force clang to do so by providing the following flag: -D_GLIBCXX_DEBUG

    I would only provide the flag for debug builds, but if debug is the default and release builds are a special target you should remove it:

    release: CXXFLAGS := $(filter-out -D_GLIBCXX_DEBUG,$(CXXFLAGS)) -O2
    

    This has fixed the same problem for me.

    0 讨论(0)
  • 2021-02-12 14:34

    I've reproduced this issue on Fedora with system clang.

    It appears that clang is not emitting debug information for std::string because it was told that libstdc++ provides it. See this comment from bug 24202:

    Looks like you don't have debug information for libstdc++ installed:

    Missing separate debuginfos, use: dnf debuginfo-install libgcc-5.1.1-4.fc22.x86_64 libstdc++-5.1.1-4.fc22.x86_64

    Clang is not emitting debug information for std::string because it was told that libstdc++ provides it (but in your case, it's not installed); this is a debug size optimization that GCC apparently doesn't perform.

    Does this work if you install the debug information for libstdc++?

    I've installed debug info for libstdc++ with command dnf debuginfo-install libstdc++-6.2.1-2.fc25.x86_64 and that resolved the issue.

    0 讨论(0)
  • 2021-02-12 14:36

    clang trusts that debugging symbols for libstd++ are available, so you have to install them. See ks1322's answer for how to do that on Fedora. On Ubuntu, run:

    sudo apt-get install libstdc++6-dbgsym
    

    After that, things will just work.

    Do not define _GLIBCXX_DEBUG since that'll break libstdc++'s abi.

    -fno-limit-debug-info will make clang emit debug info that's larger than necessary, so I'd advise against that too. Just install the debug info package for libstdc++.

    0 讨论(0)
提交回复
热议问题