简体   繁体   English

在Linux上的gdb中加载核心文件时,如何在库路径前添加目录

[英]How do I prepend a directory the library path when loading a core file in gdb on Linux

I have a core file generated on a remote system that I don't have direct access to. 我有一个在远程系统上生成的核心文件,我没有直接访问权限。 I also have local copies of the library files from the remote system, and the executable file for the crashing program. 我还有来自远程系统的库文件的本地副本,以及崩溃程序的可执行文件。

I'd like to analyse this core dump in gdb. 我想在gdb中分析这个核心转储。

For example: 例如:

gdb path/to/executable path/to/corefile

My libraries are in the current directory. 我的库位于当前目录中。

In the past I've seen debuggers implement this by supplying the option "-p ." 在过去,我见过调试器通过提供选项“-p”来实现它。 or "-p /=."; 或“-p / =。”; so my question is: 所以我的问题是:

How can I specify that libraries be loaded first from paths relative to my current directory when analysing a corefile in gdb? 在分析gdb中的核心文件时,如何指定首先从相对于当前目录的路径加载库?

Start gdb without specifying the executable or core file, then type the following commands: 在不指定可执行文件或核心文件的情况下启动gdb,然后键入以下命令:

set solib-absolute-prefix ./usr
file path/to/executable
core-file path/to/corefile

You will need to make sure to mirror your library path exactly from the target system. 您需要确保完全从目标系统镜像库路径。 The above is meant for debugging targets that don't match your host, that is why it's important to replicate your root filesystem structure containing your libraries. 以上内容适用于调试与主机不匹配的目标,这就是复制包含库的根文件系统结构的重要原因。

If you are remote debugging a server that is the same architecture and Linux/glibc version as your host, then you can do as fd suggested: 如果您正在远程调试与主机相同的架构和Linux / glibc版本的服务器,那么您可以按照fd建议执行:

set solib-search-path <path>

If you are trying to override some of the libraries, but not all then you can copy the target library directory structure into a temporary place and use the solib-absolute-prefix solution described above. 如果您试图覆盖某些库,但不是全部,那么您可以将目标库目录结构复制到临时位置并使用上述solib-absolute-prefix解决方案。

I'm not sure this is possible at all within gdb but then I'm no expert. 我不确定这在gdb中是否可行,但后来我不是专家。

However I can comment on the Linux dynamic linker. 但是我可以对Linux动态链接器发表评论。 The following should print the path of all resolved shared libraries and the unresolved ones. 以下内容应该打印所有已解析的共享库和未解析的共享库的路径。

ldd path/to/executable

We need to know how your shared libraries were linked with your executable. 我们需要知道您的共享库如何与您的可执行文件链接。 To do this, use the following command: 为此,请使用以下命令:

readelf -d path/to/executable | grep RPATH
  • Should the command print nothing, the dynamic linker will use standard locations plus the LD_LIBRARY_PATH environment variable to find the shared libraries. 如果命令不打印,动态链接器将使用标准位置和LD_LIBRARY_PATH环境变量来查找共享库。

  • If the command prints some lines, the dynamic linker will ignore LD_LIBRARY_PATH and use the hardcoded rpaths instead. 如果命令打印某些行,则动态链接器将忽略LD_LIBRARY_PATH并使用硬编码的rpath。

    If the listed rpaths are absolute, the only solution I know is to copy (or symlink) your libraries to the listed locations. 如果列出的rpath是绝对的,我知道的唯一解决方案是将库复制(或符号链接)到列出的位置。

    If the listed rpaths are relative, they will contain a $ORIGIN which will be replaced at run time by the path of the executable. 如果列出的rpath是相对的,它们将包含$ ORIGIN,它将在运行时由可执行文件的路径替换。 Move either the executable or the libraries to match. 移动可执行文件或库以匹配。

For further informations, you could start with: 有关更多信息,您可以从以下开始:

man ld.so

I found this excerpt on developer.apple.com 我在developer.apple.com上找到了这段摘录

 set solib-search-path path 

If this variable is set, path is a colon-separated list of directories to search for shared libraries. 如果设置了此变量,则path是以冒号分隔的目录列表,用于搜索共享库。 solib-search-path' is used after solib-absolute-prefix' fails to locate the library, or if the path to the library is relative instead of absolute. solib-search-path' is used after solib-absolute-prefix'无法定位库之后使用,或者库的路径是相对的而不是绝对的。 If you want to use solib-search-path' instead of solib-absolute-prefix', be sure to set `solib-absolute-prefix' to a nonexistant directory to prevent GDB from finding your host's libraries. 如果要使用solib-search-path' instead of solib-absolute-prefix',请确保将`solib-absolute-prefix'设置为不存在的目录,以防止GDB找到主机的库。

EDIT: 编辑:

I don't think using the above setting prepends the directories I added, but it does seem to append them, so files missing from my current system are picked up in the paths I added. 我不认为使用上面的设置会预先添加我添加的目录,但它似乎会附加它们,因此我在当前系统中丢失的文件会在我添加的路径中被选中。 I guess setting the solib-absolute-prefix to something bogus and adding directories in the solib-search-path in the order I need might be a full solution. 我想将solib-absolute-prefix设置为虚假的东西,并按照我需要的顺序在solib-search-path中添加目录可能是一个完整的解决方案。

You can also just set LD_PRELOAD to each of the libraries or LD_LIBRARY_PATH to the current directory when invoking gdb. 您还可以在调用gdb时将LD_PRELOAD设置为每个库,或者将LD_LIBRARY_PATH设置为当前目录。 This will only cause problems if gdb itself tries to use any of the libraries you're preloading. 如果gdb本身尝试使用您正在预加载的任何库,这只会导致问题。

One important note: 一个重要的说明:

if you're doing a cross compiling and trying to debug with gdb, then after you've done 如果您正在进行交叉编译并尝试使用gdb进行调试,那么在您完成之后
file ECECUTABLE_NAME if you see smth. 如果你看到smth,请file ECECUTABLE_NAME like : 喜欢 :

Using host libthread_db library "/lib/libthread_db.so.1"

then check whether you have libthread_db for your target system. 然后检查您的目标系统是否有libthread_db。 I found a lot of similar problems on the web. 我在网上发现了很多类似的问题。 Such problem cannot be solved just using "set solib-", you has to build libthread_db using your cross-compiler as well. 仅使用“set solib-”无法解决此类问题,您还必须使用交叉编译器构建libthread_db。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当程序具有命令行参数时,如何使用 GDB 分析程序的核心转储文件? - How do I analyze a program's core dump file with GDB when it has command-line parameters? linux:如何生成核心文件? - linux: how do I generate a core file? 当我没有可用的共享库时,如何从 GDB 中的核心转储中获取共享库基址列表? - How do I get a list of shared library base addresses from a core dump in GDB when I don't have the shared library available? 如何使用 .Net Core 在 linux 上获取当前执行目录? - How do I get the current executing directory on linux with .Net Core? 如何将字符串添加到与我的模式匹配的目录中的每个文件? - How do I prepend a string to each file in directory that matches my pattern? 在Linux(Ubuntu)中,当我看到“没有这样的文件或目录”时,如何确定找不到哪个特定文件 - In Linux (Ubuntu), how do I determine which specific file was not found when I see “No such file or directory” 使用拆分创建 csv 时,如何添加变量以打开文件 stream? - How do I prepend variable to open file stream when using split to create csv's? 如何确定linux机器目录中最新创建的文件? - How do I determine the newest created file in a directory on a linux machine? 如何让gdb在linux下使用D程序? - How do I get gdb working with D programs under linux? 在Linux / Debian上如何在java.library.path中包含目录? - How to include a directory to java.library.path on Linux/Debian?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM