为什么 gdb 向我抱怨没有可用的源(使用 g++ -ggdb3)

Why gdb complain to me that No Source Available (with g++ -ggdb3)

出于某种原因,我昨天重新安装了 OS(manjaro linux),并通过 pacman 安装了 gccgdb,然后我写了一个非常小的示例程序,以确保我的环境是正确的,因为我是 linux 和 gdb 的初学者。编译后,一切如我所愿。然后想通过gdb看一下STL源码,于是用tui模式打开了我的gdb。起初一切似乎都很正常,但我的 gdb 无法进入我想看到的 ss.insert(),屏幕顶部显示 [ 无可用资源 ]。而且我发现operator<<的源文件目录和重装前的版本不一样OS,/usr/shared/c++/已经不存在了!

这是GCC(g++)gdb

的版本信息
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-werror gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC) 
GNU gdb (GDB) 10.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Why gdb complain to me that No Source Available (with g++ -ggdb3)

因为您在 libstdc++ 中停止,它是在一个临时目录(这里是 /build/gcc/src/gcc-build/...)中构建的,并且该目录不存在于 您的 机器上.

您实际上 极度 不太可能需要查看 operator<<() 的源代码,但如果您真的想这样做,请安装 GCC 源代码,并且使用 (gdb) directory 将 GDB 指向相关来源。