如何让gdb允许我打电话;“地板”;即使安装了调试信息文件?
作为回应,我验证了我确实有调试包,这些调试包应该提供足够的调试信息,以便从gdb命令行调用函数,例如如何让gdb允许我打电话;“地板”;即使安装了调试信息文件?,gdb,debug-symbols,Gdb,Debug Symbols,作为回应,我验证了我确实有调试包,这些调试包应该提供足够的调试信息,以便从gdb命令行调用函数,例如floor,但gdb中仍有一些异常行为 我通过以下方式运行此版本的gdb: gdb --version 是: 是: 我期望gdb使用的调试包,以便通过以下方式找到floor符号: dpkg --listfiles libc6-dbg | grep libm 是: 通过以下方式编译、运行和运行gdb: #!/bin/bash exec 2>&1 set -x rm -rf "/
floor
,但gdb中仍有一些异常行为
我通过以下方式运行此版本的gdb:
gdb --version
是:
是:
我期望gdb使用的调试包,以便通过以下方式找到floor
符号:
dpkg --listfiles libc6-dbg | grep libm
是:
通过以下方式编译、运行和运行gdb:
#!/bin/bash
exec 2>&1
set -x
rm -rf "/tmp/testdir"
mkdir -p "/tmp/testdir"
cd "/tmp/testdir"
cat > main.cpp <<'EOF'
#include <stdio.h>
#include <math.h> // double floor(double x);
int main(int argc, char *argv[], char *const envp[])
{
printf("From inside C++: floor(2.12) %g\n", floor(2.12));
return 0;
} // end main
EOF
/usr/bin/c++ -MD -DDEBUG -g -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type $cxx_args main.cpp -c -o main.o
/usr/bin/c++ -MD -DDEBUG -g -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type $cxx_args main.o -L. -L/usr/lib64 -lstdc++ -o main.exe
(./main.exe; exit 0)
cat > /tmp/gdb.commands <<EOF
# https://stackoverflow.com/a/60909020/257924
set trace-commands on
b main
r
info shared
p floor(2.12)
EOF
gdb -batch -x /tmp/gdb.commands main.exe
exit 0
是:
+cxx_args=-fno内置
+rm-rf/tmp/testdir
+mkdir-p/tmp/testdir
+cd/tmp/testdir
+猫
+/usr/bin/c++-MD-DDEBUG-g-fPIC-Wall-Werror-Wsynth-Wno comment-Wreturn-type-fno builtin main.cpp-c-o main.o
+/usr/bin/c++-MD-DDEBUG-g-fPIC-Wall-Werror-Wsynth-Wno comment-Wreturn type-fno builtin main.o-L-L/usr/lib64-lstdc++-o main.exe
+/main.exe
从C++内部:地板(2.12)2
+出口0
+猫
+gdb-batch-x/tmp/gdb.commands main.exe
+主干道
0x1169处的断点1:文件main.cpp,第5行。
+r
main处的断点1(argc=0,argv=0x7fffffdbc0,envp=0x555080)。cpp:5
5 {
+信息共享
从到Syms读取共享对象库
0x00007ffff7fd1100 0x00007ffff7ff23f4是/lib64/ld-linux-x86-64.so.2
0x00007ffff7e553c0 0x00007ffff7efbe78是/lib/x86_64-linux-gnu/libm.so.6
0x00007ffff7c7a670 0x00007ffff7def74f是/lib/x86_64-linux-gnu/libc.so.6
+p层(2.12)
$1 = 2
+出口0
我重复了这一点。问题有两个方面:
floor(2.12)
,而无需调用libm.so.6
,并且--
参数libm.so.6
=> 0x0000555555555148 <+19>: mov 0xee1(%rip),%rax # 0x555555556030
0x000055555555514f <+26>: movq %rax,%xmm0
0x0000555555555154 <+31>: lea 0xead(%rip),%rdi # 0x555555556008
0x000055555555515b <+38>: mov $0x1,%eax
0x0000555555555160 <+43>: callq 0x555555555030 <printf@plt>
(gdb) p *(double*)0x555555556030
$1 = 2
结果:
(gdb) start
Temporary breakpoint 1 at 0x1158: file main.cpp, line 6.
Starting program: /tmp/testdir/a.out
Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdca8, envp=0x7fffffffdcb8) at main.cpp:6
6 double d = 2.12;
(gdb) n
7 printf("From inside C++: floor(2.12) %g\n", floor(d));
(gdb) p floor
$1 = {<text gnu-indirect-function variable, no debug info>} 0x7ffff7e8e820 <__floor_ifunc>
(gdb) p floor(d)
$2 = 2
(gdb)启动
0x1158处的临时断点1:文件main.cpp,第6行。
启动程序:/tmp/testdir/a.out
main.cpp:6处的临时断点1,main(argc=1,argv=0x7fffffffdca8,envp=0x7fffffffdcb8)
6双d=2.12;
(gdb)n
7 printf(“从C++内部:地板(2.12)%g\n”,地板(d));
(gdb)p层
$1={}0x7ffff7e8e820
(gdb)p层(d)
$2 = 2
另外,除了修改源代码,您还可以禁止编译器知道
-fno-builtin
或-fno-builtin-floor
的floor是否可以显示的输出(gdb)信息共享
?添加了更新1和更新2,其中2个用于添加信息共享
gdb命令。添加了更新3以确认答案。这是答案,谢谢!上面foor(2.12)
中的一个小拼写错误。
/usr/lib/debug/lib/x86_64-linux-gnu/libm-2.30.so
/usr/lib/debug/lib/x86_64-linux-gnu/libmemusage.so
/usr/lib/debug/lib/x86_64-linux-gnu/libmvec-2.30.so
#!/bin/bash
exec 2>&1
set -x
rm -rf "/tmp/testdir"
mkdir -p "/tmp/testdir"
cd "/tmp/testdir"
cat > main.cpp <<'EOF'
#include <stdio.h>
#include <math.h> // double floor(double x);
int main(int argc, char *argv[], char *const envp[])
{
printf("From inside C++: floor(2.12) %g\n", floor(2.12));
return 0;
} // end main
EOF
/usr/bin/c++ -MD -DDEBUG -g -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type $cxx_args main.cpp -c -o main.o
/usr/bin/c++ -MD -DDEBUG -g -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type $cxx_args main.o -L. -L/usr/lib64 -lstdc++ -o main.exe
(./main.exe; exit 0)
cat > /tmp/gdb.commands <<EOF
# https://stackoverflow.com/a/60909020/257924
set trace-commands on
b main
r
info shared
p floor(2.12)
EOF
gdb -batch -x /tmp/gdb.commands main.exe
exit 0
+ rm -rf /tmp/testdir
+ mkdir -p /tmp/testdir
+ cd /tmp/testdir
+ cat
+ /usr/bin/c++ -MD -DDEBUG -g -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type main.cpp -c -o main.o
+ /usr/bin/c++ -MD -DDEBUG -g -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type main.o -L. -L/usr/lib64 -lstdc++ -o main.exe
+ ./main.exe
From inside C++: floor(2.12) 2
+ exit 0
+ cat
+ gdb -batch -x /tmp/gdb.commands main.exe
+b main
Breakpoint 1 at 0x1149: file main.cpp, line 5.
+r
Breakpoint 1, main (argc=0, argv=0x7fffffffdbc0, envp=0x555555555060 <_start>) at main.cpp:5
5 {
+info shared
From To Syms Read Shared Object Library
0x00007ffff7fd1100 0x00007ffff7ff23f4 Yes /lib64/ld-linux-x86-64.so.2
0x00007ffff7dc9670 0x00007ffff7f3e74f Yes /lib/x86_64-linux-gnu/libc.so.6
+p floor(2.12)
/tmp/gdb.commands:6: Error in sourced command file:
No symbol "floor" in current context.
+ exit 0
#!/bin/bash
exec 2>&1
set -x
cxx_args='-fno-builtin'
rm -rf "/tmp/testdir"
mkdir -p "/tmp/testdir"
cd "/tmp/testdir"
cat > main.cpp <<'EOF'
#include <stdio.h>
#include <math.h> // double floor(double x);
int main(int argc, char *argv[], char *const envp[])
{
printf("From inside C++: floor(2.12) %g\n", floor(2.12));
return 0;
} // end main
EOF
/usr/bin/c++ -MD -DDEBUG -g -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type $cxx_args main.cpp -c -o main.o
/usr/bin/c++ -MD -DDEBUG -g -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type $cxx_args main.o -L. -L/usr/lib64 -lstdc++ -o main.exe
(./main.exe; exit 0)
cat > /tmp/gdb.commands <<EOF
# https://stackoverflow.com/a/60909020/257924
set trace-commands on
b main
r
info shared
p floor(2.12)
EOF
gdb -batch -x /tmp/gdb.commands main.exe
exit 0
+ cxx_args=-fno-builtin
+ rm -rf /tmp/testdir
+ mkdir -p /tmp/testdir
+ cd /tmp/testdir
+ cat
+ /usr/bin/c++ -MD -DDEBUG -g -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type -fno-builtin main.cpp -c -o main.o
+ /usr/bin/c++ -MD -DDEBUG -g -fPIC -Wall -Werror -Wsynth -Wno-comment -Wreturn-type -fno-builtin main.o -L. -L/usr/lib64 -lstdc++ -o main.exe
+ ./main.exe
From inside C++: floor(2.12) 2
+ exit 0
+ cat
+ gdb -batch -x /tmp/gdb.commands main.exe
+b main
Breakpoint 1 at 0x1169: file main.cpp, line 5.
+r
Breakpoint 1, main (argc=0, argv=0x7fffffffdbc0, envp=0x555555555080 <_start>) at main.cpp:5
5 {
+info shared
From To Syms Read Shared Object Library
0x00007ffff7fd1100 0x00007ffff7ff23f4 Yes /lib64/ld-linux-x86-64.so.2
0x00007ffff7e553c0 0x00007ffff7efbe78 Yes /lib/x86_64-linux-gnu/libm.so.6
0x00007ffff7c7a670 0x00007ffff7def74f Yes /lib/x86_64-linux-gnu/libc.so.6
+p floor(2.12)
$1 = 2
+ exit 0
=> 0x0000555555555148 <+19>: mov 0xee1(%rip),%rax # 0x555555556030
0x000055555555514f <+26>: movq %rax,%xmm0
0x0000555555555154 <+31>: lea 0xead(%rip),%rdi # 0x555555556008
0x000055555555515b <+38>: mov $0x1,%eax
0x0000555555555160 <+43>: callq 0x555555555030 <printf@plt>
(gdb) p *(double*)0x555555556030
$1 = 2
1 #include <stdio.h>
2 #include <math.h> // double floor(double x);
3
4 int main(int argc, char *argv[], char *const envp[])
5 {
6 double d = 2.12;
7 printf("From inside C++: floor(2.12) %g\n", floor(d));
8 return 0;
9 } // end main
(gdb) start
Temporary breakpoint 1 at 0x1158: file main.cpp, line 6.
Starting program: /tmp/testdir/a.out
Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdca8, envp=0x7fffffffdcb8) at main.cpp:6
6 double d = 2.12;
(gdb) n
7 printf("From inside C++: floor(2.12) %g\n", floor(d));
(gdb) p floor
$1 = {<text gnu-indirect-function variable, no debug info>} 0x7ffff7e8e820 <__floor_ifunc>
(gdb) p floor(d)
$2 = 2