简体   繁体   English

使用gdb通过共享库进入第三方功能

[英]using gdb to step into 3rd party functions with shared libraries

I am using gdb and some shared libraries. 我正在使用gdb和一些共享库。 I can get gdb to step into my own shared library, but not a 3rd party one. 我可以让gdb进入我自己的共享库,但不是第三方库。

When using gdb, I expect "s" (step) to step into the 3rd party library and show me the lines it is executing inside these opj_* functions instead of just going to the next line in my own shared library code. 当使用gdb时,我希望“s”(步骤)进入第三方库并向我展示它在这些opj_ *函数中执行的行,而不是仅仅转到我自己的共享库代码中的下一行。

I'm pretty sure I'm just missing something during compiling, having to do with linking (getting gcc to pass some debug flags to ld), but I don't know what it is, or something when running gdb to tell it where the debug symbols are. 我很确定我在编译期间只是遗漏了一些东西,与链接有关(让gcc将一些调试标志传递给ld),但是我不知道它是什么,或者在运行gdb时告诉它在哪里调试符号是。

Here are the details: 以下是详细信息:

I have the openjpeg library, debug info and devel packages installed. 我安装了openjpeg库,调试信息和开发包。

# zypper search -si openjpeg
Loading repository data...
Reading installed packages...

S | Name                     | Type    | Version   | Arch   | Repository
--+--------------------------+---------+-----------+--------+-----------
i | libopenjpeg2_0           | package | 2.0.0-1.4 | x86_64 | packman   
i | libopenjpeg2_0-debuginfo | package | 2.0.0-1.4 | x86_64 | packman   
i | openjpeg2-devel          | package | 2.0.0-1.4 | x86_64 | packman   

# rpm -ql libopenjpeg2_0
/usr/lib64/libopenjpeg.so.2.0
/usr/lib64/libopenjpeg.so.2.0.0

# rpm -ql openjpeg2-devel
/usr/include/openjpeg-2.0
/usr/include/openjpeg-2.0/openjpeg.h
/usr/lib64/libopenjpeg.so
/usr/lib64/openjpeg-2.0
/usr/lib64/openjpeg-2.0/OpenJPEGConfig.cmake
/usr/lib64/openjpeg-2.0/OpenJPEGTargets-release.cmake
/usr/lib64/openjpeg-2.0/OpenJPEGTargets.cmake

# rpm -ql libopenjpeg2_0-debuginfo
/usr/lib/debug
/usr/lib/debug/.build-id
/usr/lib/debug/.build-id/85/f8603c75aadee0bd66653332d7ce16d0292752
/usr/lib/debug/.build-id/85/f8603c75aadee0bd66653332d7ce16d0292752.debug
/usr/lib/debug/usr/lib64/libopenjpeg.so.2.0.0.debug

I have a shared library libjna_openjpeg linked to libopenjpeg. 我有一个链接到libopenjpeg的共享库libjna_openjpeg。

I have a test program "pathtest" linked to libopenjpeg and libjna_openjpeg 我有一个测试程序“pathtest”链接到libopenjpeg和libjna_openjpeg

I compiled each with "gcc -g ..." and also tried "gcc -ggdb ..." 我用“gcc -g ...”编译了每一个,并尝试了“gcc -ggdb ...”

gcc -ggdb -c -fpic -I/usr/include/openjpeg-2.0 jna_openjpeg.c -lopenjpeg
gcc -ggdb -shared -o libjna_openjpeg.so jna_openjpeg.o -lopenjpeg
gcc -ggdb -I/usr/include/openjpeg-2.0 -L. -o pathtest pathtest.c -ljna_openjpeg -lopenjpeg

A snippet of my shared library code with some comments removed: 我的共享库代码片段,删除了一些注释:

opj_stream_t* p_stream = opj_stream_create_default_file_stream( p_file, p_is_read_stream );

opj_codec_t *p_decompressor = opj_create_decompress(CODEC_J2K);

// my bug I want to debug is here... this always returns 0
p_image =  opj_decode( p_decompressor, p_stream );

running gdb 运行gdb

$ gdp pathtest

...

(gdb) s
52          opj_codec_t *p_decompressor = opj_create_decompress(CODEC_J2K);
(gdb) s
59          p_image =  opj_decode( p_decompressor, p_stream );
(gdb) s

gdb version gdb版本

# gdb --version
GNU gdb (GDB) SUSE (7.3-41.1.2)
...    

can you try by enabling step-mode on ? 你能尝试启用步进模式吗?

(gdb) set step-mode on

This causes the step command to stop at the first instruction of a function which contains no debug line information(usually 3rd party like libc) rather than stepping over it. 这导致step命令停止在函数的第一条指令处,该函数不包含调试行信息(通常是第三方,如libc),而不是单步调试它。

You didn't give your gdb version. 你没有给你的gdb版本。 Apparently this could have been a bug in gdb, because I had the same problem with 7.0.1 but upgrading to 7.3.50 fixed it. 显然这可能是gdb中的一个错误,因为我遇到了与7.0.1相同的问题但升级到7.3.50修复了它。

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

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