首页 > 解决方案 > 为什么 GDB 回溯会出现?() 使用 vgdb 进行远程调试时?

问题描述

valgrind --vgdb-error=0 <binary> <binary args>在一个 shell 和gdb <binary>另一个 shell 中运行 valgrind。我从with连接到valgrind服务器。我打开并收到一个并检查回溯:gdbtarget remote | /usr/lib64/valgrind/../../bin/vgdb --pid=<pid>continuegdbSIGTRAP

Remote debugging using | /usr/lib64/valgrind/../../bin/vgdb --pid=<pid>
relaying data between gdb and process <pid>
warning: remote target does not support file transfer, attempting to access files from local filesystem.
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/usr/lib64/ld-2.26.so.debug...done.
done.
0x0000000004000ef0 in _start () from /lib64/ld-linux-x86-64.so.2
(gdb) c
Continuing.
warning: Probes-based dynamic linker interface failed.
Reverting to original interface.

[New Thread 15252]
[New Thread 15249]
[New Thread 15250]
[New Thread 15253]
[New Thread 15254]

Thread 2 received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 15252]
0x0000000004c2eb99 in ?? ()
(gdb) bt
#0  0x0000000004c2eb99 in ?? ()
#1  0x0000000008b6ae50 in ?? ()
#2  0x000000000042a980 in std::_Hashtable<long, std::pair<long const, retracted_type>, std::allocator<std::pair<long const, retracted_type> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_assign<std::_Hashtable<long, std::pair<long const, retracted_type>, std::allocator<std::pair<long const, retracted_type> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::operator=(std::_Hashtable<long, std::pair<long const, retracted_type>, std::allocator<std::pair<long const, retracted_type> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> > const&)::{lambda(std::__detail::_Hash_node<std::pair<long const, retracted_type>, false> const*)#1}>(std::_Hashtable<long, std::pair<long const, retracted_type>, std::allocator<std::pair<long const, retracted_type> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> > const&, std::_Hashtable<long, std::pair<long const, retracted_type>, std::allocator<std::pair<long const, retracted_type> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::operator=(std::_Hashtable<long, std::pair<long const, retracted_type>, std::allocator<std::pair<long const, retracted_type> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> > const&)::{lambda(std::__detail::_Hash_node<std::pair<long const, retracted_type>, false> const*)#1} const&) (this=0x4f6fc02, __ht=..., __node_gen=...) at /usr/local/include/c++/9.2.0/bits/hashtable.h:1139
Backtrace stopped: frame did not save the PC

file在二进制文件上运行

$ file <binary name>
<binary name>: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 3.2.0, not stripped

为什么 GDB 回溯会出现?? ()在回溯中?

此外,回溯似乎比它应该的要短。那是因为the frame did not save the PC?为什么/如何没有保存程序计数器?

无论如何我可以获得更多信息来帮助调试吗?正常gdb调试通常会解析回溯的符号。

编辑: 添加评论中要求的附加输出

(gdb) info shared
From                To                  Syms Read   Shared Object Library
0x0000000004000d70  0x000000000401c570  Yes         /lib64/ld-linux-x86-64.so.2
(gdb) info file
Symbols from "/home/ec2-user/<redacted>".
Remote serial target in gdb-specific protocol:
Debugging a target over a serial line.
        While running this, GDB does not access memory from...
Local exec file:
        `/home/ec2-user/<redacted>', file type elf64-x86-64.
        Entry point: 0x40f000
        0x0000000000400270 - 0x000000000040028c is .interp
        0x000000000040028c - 0x00000000004002ac is .note.ABI-tag
        0x00000000004002b0 - 0x000000000040135c is .hash
        0x0000000000401360 - 0x0000000000404660 is .dynsym
        0x0000000000404660 - 0x00000000004088e7 is .dynstr
        0x00000000004088e8 - 0x0000000000408d28 is .gnu.version
        0x0000000000408d28 - 0x0000000000408fd8 is .gnu.version_r
        0x0000000000408fd8 - 0x0000000000409530 is .rela.dyn
        0x0000000000409530 - 0x000000000040c4a0 is .rela.plt
        0x000000000040c4a0 - 0x000000000040c4bc is .init
        0x000000000040c4c0 - 0x000000000040e470 is .plt
        0x000000000040f000 - 0x0000000000ac8890 is .text
        0x0000000000ac8890 - 0x0000000000ac8899 is .fini
        0x0000000000ac88c0 - 0x0000000000e67008 is .rodata
        0x0000000000e67008 - 0x0000000000eb44dc is .eh_frame_hdr
        0x0000000000eb44e0 - 0x0000000000ff1fb0 is .eh_frame
        0x0000000000ff1fb0 - 0x0000000001006236 is .gcc_except_table
        0x0000000001206db0 - 0x0000000001206dd0 is .tbss
        0x0000000001206db0 - 0x0000000001206f78 is .init_array
        0x0000000001206f78 - 0x0000000001206f80 is .fini_array
        0x0000000001206f80 - 0x0000000001243c70 is .data.rel.ro
        0x0000000001243c70 - 0x0000000001243ec0 is .dynamic
        0x0000000001243ec0 - 0x0000000001243ff8 is .got
        0x0000000001244000 - 0x0000000001244fe8 is .got.plt
        0x0000000001245000 - 0x000000000156db88 is .data
        0x000000000156dba0 - 0x000000000157d9b0 is .bss
        0x00000000040001c8 - 0x00000000040001ec is .note.gnu.build-id in /lib64/ld-linux-x86-64.so.2
        0x00000000040001f0 - 0x00000000040002b4 is .hash in /lib64/ld-linux-x86-64.so.2
        0x00000000040002b8 - 0x00000000040003a0 is .gnu.hash in /lib64/ld-linux-x86-64.so.2
        0x00000000040003a0 - 0x0000000004000670 is .dynsym in /lib64/ld-linux-x86-64.so.2
        0x0000000004000670 - 0x000000000400083c is .dynstr in /lib64/ld-linux-x86-64.so.2
        0x000000000400083c - 0x0000000004000878 is .gnu.version in /lib64/ld-linux-x86-64.so.2
        0x0000000004000878 - 0x000000000400091c is .gnu.version_d in /lib64/ld-linux-x86-64.so.2
        0x0000000004000920 - 0x0000000004000c68 is .rela.dyn in /lib64/ld-linux-x86-64.so.2
        0x0000000004000c68 - 0x0000000004000cf8 is .rela.plt in /lib64/ld-linux-x86-64.so.2
        0x0000000004000d00 - 0x0000000004000d70 is .plt in /lib64/ld-linux-x86-64.so.2
        0x0000000004000d70 - 0x000000000401c570 is .text in /lib64/ld-linux-x86-64.so.2
        0x000000000401c580 - 0x0000000004020980 is .rodata in /lib64/ld-linux-x86-64.so.2
        0x0000000004020980 - 0x0000000004020981 is .stapsdt.base in /lib64/ld-linux-x86-64.so.2
        0x0000000004020984 - 0x0000000004021008 is .eh_frame_hdr in /lib64/ld-linux-x86-64.so.2
        0x0000000004021008 - 0x000000000402346c is .eh_frame in /lib64/ld-linux-x86-64.so.2
        0x0000000004223780 - 0x0000000004223e14 is .data.rel.ro in /lib64/ld-linux-x86-64.so.2
        0x0000000004223e18 - 0x0000000004223fa8 is .dynamic in /lib64/ld-linux-x86-64.so.2
        0x0000000004223fa8 - 0x0000000004224000 is .got in /lib64/ld-linux-x86-64.so.2
        0x0000000004224000 - 0x0000000004224f78 is .data in /lib64/ld-linux-x86-64.so.2
        0x0000000004224f80 - 0x0000000004225130 is .bss in /lib64/ld-linux-x86-64.so.2

Valgrind 输出:

==2693== Thread 4:
==2693== Conditional jump or move depends on uninitialised value(s)
==2693==    at 0x4C2EB99: strlen (vg_replace_strmem.c:458)
==2693==    by 0x42A97F: <redacted_func_1>() (in /home/ec2-user/bin/<redacted>)
==2693==    by 0x4353BD: <redacted_func_2>() (in /home/ec2-user/bin/<redacted>)
==2693==    by 0x4F05F6F: execute_native_thread_routine (thread.cc:80)
==2693==    by 0x562140A: start_thread (pthread_create.c:465)
==2693==    by 0x5E7CE7E: clone (clone.S:95)
==2693==
==2693== (action on error) vgdb me ...

Valgrind 版本

[ec2-user@ip-172-31-12-111 ~]$ valgrind --version
valgrind-3.13.0

GDB 版本

[ec2-user@ip-172-31-12-111 ~]$ gdb --version
GNU gdb (GDB) Red Hat Enterprise Linux 8.0.1-30.amzn2.0.3
Copyright (C) 2017 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.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

GLIBC 版本

[ec2-user@ip-172-31-12-111 ~]$ ldd --version
ldd (GNU libc) 2.26
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

编辑 2: 遵循@Employed 俄语说明:

查找.text二进制部分的地址

[ec2-user@ip-172-31-12-111 ~]$ readelf -WS ~/<redacted> | grep '\.text'
  [12] .text             PROGBITS        000000000040f000 00f000 6b9890 00  AX  0   0 4096

valgrind以与gdb前面所述相同的方式启动并手动添加符号文件:

(gdb) add-symbol-file <redacted> 0x000000000040f000
add symbol table from file "<redacted>" at
        .text_addr = 0x40f000

Valgrind 输出:

==5915== Thread 4:
==5915== Conditional jump or move depends on uninitialised value(s)
==5915==    at 0x4C2EB99: strlen (vg_replace_strmem.c:458)
==5915==    by 0x42A97F: <redacted function 1>() (in /home/ec2-user/bin/<redacted>)
==5915==    by 0x4353BD: <redacted function 2>() (in /home/ec2-user/bin/<redacted>)
==5915==    by 0x4F05F6F: execute_native_thread_routine (thread.cc:80)
==5915==    by 0x562140A: start_thread (pthread_create.c:465)
==5915==    by 0x5E7CE7E: clone (clone.S:95)
==5915==
==5915== (action on error) vgdb me ...

GDB 输出:

(gdb)  target remote | /usr/lib64/valgrind/../../bin/vgdb --pid=5915
Remote debugging using | /usr/lib64/valgrind/../../bin/vgdb --pid=5915
relaying data between gdb and process 5915
warning: remote target does not support file transfer, attempting to access files from local filesystem.
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/usr/lib64/ld-2.26.so.debug...done.
done.
0x0000000004000ef0 in _start () from /lib64/ld-linux-x86-64.so.2
(gdb) c
Continuing.
warning: Probes-based dynamic linker interface failed.
Reverting to original interface.

[New Thread 6502]
[New Thread 6492]
[New Thread 6498]
[New Thread 6503]
[New Thread 6504]

Thread 2 received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 6502]
0x0000000004c2eb99 in ?? ()
(gdb) bt
#0  0x0000000004c2eb99 in ?? ()
#1  0x0000000008b6ae50 in ?? ()
#2  0x000000000042a980 in std::_Hashtable<long, std::pair<long const, <redacted function>>, std::allocator<std::pair<long const, <redacted function>> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_assign<std::_Hashtable<long, std::pair<long const, <redacted function>>, std::allocator<std::pair<long const, <redacted function>> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::operator=(std::_Hashtable<long, std::pair<long const, <redacted function>>, std::allocator<std::pair<long const, <redacted function>> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> > const&)::{lambda(std::__detail::_Hash_node<std::pair<long const, <redacted function>>, false> const*)#1}>(std::_Hashtable<long, std::pair<long const, <redacted function>>, std::allocator<std::pair<long const, <redacted function>> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> > const&, std::_Hashtable<long, std::pair<long const, <redacted function>>, std::allocator<std::pair<long const, <redacted function>> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::operator=(std::_Hashtable<long, std::pair<long const, <redacted function>>, std::allocator<std::pair<long const, <redacted function>> >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> > const&)::{lambda(std::__detail::_Hash_node<std::pair<long const, <redacted function>>, false> const*)#1} const&) (this=0x4f6fc02, __ht=..., __node_gen=...) at /usr/local/include/c++/9.2.0/bits/hashtable.h:1149
Backtrace stopped: frame did not save the PC
[ec2-user@ip-172-31-12-111 ~]$ cat /proc/5915/maps
00400000-00c1f000 r-xp 00000000 103:01 922996444                         /home/ec2-user/bin/<redacted>
00e1e000-00e5c000 r--p 0081e000 103:01 922996444                         /home/ec2-user/bin/<redacted>
00e5c000-01167000 rw-p 0085c000 103:01 922996444                         /home/ec2-user/bin/<redacted>
01167000-01172000 rw-p 00000000 00:00 0
04000000-04024000 r-xp 00000000 103:01 1372                              /usr/lib64/ld-2.26.so
04024000-04028000 rw-p 00000000 00:00 0
04031000-04036000 rw-p 00000000 00:00 0
04223000-04224000 r--p 00023000 103:01 1372                              /usr/lib64/ld-2.26.so
04224000-04225000 rw-p 00024000 103:01 1372                              /usr/lib64/ld-2.26.so
04225000-04226000 rw-p 00000000 00:00 0
04226000-04227000 rwxp 00000000 00:00 0
04a26000-04a27000 r-xp 00000000 103:01 291504350                         /usr/lib64/valgrind/vgpreload_core-amd64-linux.so
04a27000-04c26000 ---p 00001000 103:01 291504350                         /usr/lib64/valgrind/vgpreload_core-amd64-linux.so
04c26000-04c27000 r--p 00000000 103:01 291504350                         /usr/lib64/valgrind/vgpreload_core-amd64-linux.so
04c27000-04c28000 rw-p 00001000 103:01 291504350                         /usr/lib64/valgrind/vgpreload_core-amd64-linux.so
04c28000-04c37000 r-xp 00000000 103:01 291504362                         /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
04c37000-04e36000 ---p 0000f000 103:01 291504362                         /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
04e36000-04e37000 r--p 0000e000 103:01 291504362                         /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
04e37000-04e38000 rw-p 0000f000 103:01 291504362                         /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
04e38000-04ffe000 r-xp 00000000 103:01 4676257                           /usr/local/lib64/libstdc++.so.6.0.27
04ffe000-051fd000 ---p 001c6000 103:01 4676257                           /usr/local/lib64/libstdc++.so.6.0.27
051fd000-05208000 r--p 001c5000 103:01 4676257                           /usr/local/lib64/libstdc++.so.6.0.27
05208000-0520b000 rw-p 001d0000 103:01 4676257                           /usr/local/lib64/libstdc++.so.6.0.27
0520b000-0520e000 rw-p 00000000 00:00 0
0520e000-05215000 r-xp 00000000 103:01 1402                              /usr/lib64/librt-2.26.so
05215000-05414000 ---p 00007000 103:01 1402                              /usr/lib64/librt-2.26.so
05414000-05415000 r--p 00006000 103:01 1402                              /usr/lib64/librt-2.26.so
05415000-05416000 rw-p 00007000 103:01 1402                              /usr/lib64/librt-2.26.so
05416000-05419000 r-xp 00000000 103:01 1384                              /usr/lib64/libdl-2.26.so
05419000-05618000 ---p 00003000 103:01 1384                              /usr/lib64/libdl-2.26.so
05618000-05619000 r--p 00002000 103:01 1384                              /usr/lib64/libdl-2.26.so
05619000-0561a000 rw-p 00003000 103:01 1384                              /usr/lib64/libdl-2.26.so
0561a000-05632000 r-xp 00000000 103:01 1398                              /usr/lib64/libpthread-2.26.so
05632000-05832000 ---p 00018000 103:01 1398                              /usr/lib64/libpthread-2.26.so
05832000-05833000 r--p 00018000 103:01 1398                              /usr/lib64/libpthread-2.26.so
05833000-05834000 rw-p 00019000 103:01 1398                              /usr/lib64/libpthread-2.26.so
05834000-05838000 rw-p 00000000 00:00 0
05838000-05977000 r-xp 00000000 103:01 1386                              /usr/lib64/libm-2.26.so
05977000-05b76000 ---p 0013f000 103:01 1386                              /usr/lib64/libm-2.26.so
05b76000-05b77000 r--p 0013e000 103:01 1386                              /usr/lib64/libm-2.26.so
05b77000-05b78000 rw-p 0013f000 103:01 1386                              /usr/lib64/libm-2.26.so
05b78000-05b8e000 r-xp 00000000 103:01 4675484                           /usr/local/lib64/libgcc_s.so.1
05b8e000-05d8e000 ---p 00016000 103:01 4675484                           /usr/local/lib64/libgcc_s.so.1
05d8e000-05d8f000 r--p 00016000 103:01 4675484                           /usr/local/lib64/libgcc_s.so.1
05d8f000-05d90000 rw-p 00017000 103:01 4675484                           /usr/local/lib64/libgcc_s.so.1
05d90000-05f31000 r-xp 00000000 103:01 1380                              /usr/lib64/libc-2.26.so
05f31000-06131000 ---p 001a1000 103:01 1380                              /usr/lib64/libc-2.26.so
06131000-06135000 r--p 001a1000 103:01 1380                              /usr/lib64/libc-2.26.so
06135000-06137000 rw-p 001a5000 103:01 1380                              /usr/lib64/libc-2.26.so
06137000-0613b000 rw-p 00000000 00:00 0
0613b000-0653b000 rwxp 00000000 00:00 0
0653b000-0653c000 ---p 00000000 00:00 0
0653c000-06d3c000 rw-p 00000000 00:00 0
06d3c000-06d3d000 ---p 00000000 00:00 0
06d3d000-0753d000 rw-p 00000000 00:00 0
0753d000-0793d000 rwxp 00000000 00:00 0
0793d000-07948000 r-xp 00000000 103:01 1396                              /usr/lib64/libnss_files-2.26.so
07948000-07b47000 ---p 0000b000 103:01 1396                              /usr/lib64/libnss_files-2.26.so
07b47000-07b48000 r--p 0000a000 103:01 1396                              /usr/lib64/libnss_files-2.26.so
07b48000-07b49000 rw-p 0000b000 103:01 1396                              /usr/lib64/libnss_files-2.26.so
07b49000-07b4f000 rw-p 00000000 00:00 0
07b4f000-07b54000 r-xp 00000000 103:01 1394                              /usr/lib64/libnss_dns-2.26.so
07b54000-07d53000 ---p 00005000 103:01 1394                              /usr/lib64/libnss_dns-2.26.so
07d53000-07d54000 r--p 00004000 103:01 1394                              /usr/lib64/libnss_dns-2.26.so
07d54000-07d55000 rw-p 00005000 103:01 1394                              /usr/lib64/libnss_dns-2.26.so
07d55000-07d67000 r-xp 00000000 103:01 1400                              /usr/lib64/libresolv-2.26.so
07d67000-07f67000 ---p 00012000 103:01 1400                              /usr/lib64/libresolv-2.26.so
07f67000-07f68000 r--p 00012000 103:01 1400                              /usr/lib64/libresolv-2.26.so
07f68000-07f69000 rw-p 00013000 103:01 1400                              /usr/lib64/libresolv-2.26.so
07f69000-07f6b000 rw-p 00000000 00:00 0
07f6b000-0836b000 rwxp 00000000 00:00 0
0836b000-0836c000 ---p 00000000 00:00 0
0836c000-08b6c000 rw-p 00000000 00:00 0
08b6c000-08b6d000 ---p 00000000 00:00 0
08b6d000-0936d000 rw-p 00000000 00:00 0
0936d000-0936e000 ---p 00000000 00:00 0
0936e000-09b6e000 rw-p 00000000 00:00 0
58000000-5823c000 r-xp 00000000 103:01 291504283                         /usr/lib64/valgrind/memcheck-amd64-linux
5843c000-5843f000 rw-p 0023c000 103:01 291504283                         /usr/lib64/valgrind/memcheck-amd64-linux
5843f000-59e41000 rw-p 00000000 00:00 0
1002001000-1002f04000 rwxp 00000000 00:00 0
1002f06000-1002f8a000 rwxp 00000000 00:00 0
1002f8c000-1002fb0000 rwxp 00000000 00:00 0
1002fb0000-1002fb2000 ---p 00000000 00:00 0
1002fb2000-10030b2000 rwxp 00000000 00:00 0
10030b2000-10030b4000 ---p 00000000 00:00 0
10030b4000-10030b5000 rw-s 00000000 103:01 218555                        /tmp/vgdb-pipe-shared-mem-vgdb-5915-by-ec2-user-on-ip-172-31-12-111.ap-northeast-1.compute.internal
10030b5000-10058d7000 rwxp 00000000 00:00 0
10058d7000-10058d9000 ---p 00000000 00:00 0
10058d9000-10059d9000 rwxp 00000000 00:00 0
10059d9000-10059db000 ---p 00000000 00:00 0
10059db000-1005af3000 rwxp 00000000 00:00 0
1005af6000-1005cde000 rwxp 00000000 00:00 0
1005cde000-1005ce0000 ---p 00000000 00:00 0
1005ce0000-1005de0000 rwxp 00000000 00:00 0
1005de0000-1005de2000 ---p 00000000 00:00 0
1005de2000-1005dea000 rwxp 00000000 00:00 0
1005deb000-1006c9f000 rwxp 00000000 00:00 0
1006c9f000-1006ca1000 ---p 00000000 00:00 0
1006ca1000-1006da1000 rwxp 00000000 00:00 0
1006da1000-1006da3000 ---p 00000000 00:00 0
1006da3000-1006fa3000 rwxp 00000000 00:00 0
1006fa3000-1006fa5000 ---p 00000000 00:00 0
1006fa5000-10070a5000 rwxp 00000000 00:00 0
10070a5000-10070a7000 ---p 00000000 00:00 0
10070a7000-10072a7000 rwxp 00000000 00:00 0
10072a7000-10072a9000 ---p 00000000 00:00 0
10072a9000-10073a9000 rwxp 00000000 00:00 0
10073a9000-10073ab000 ---p 00000000 00:00 0
10073ab000-10073eb000 rwxp 00000000 00:00 0
1ffeffa000-1fff001000 rw-p 00000000 00:00 0
7ffed08e8000-7ffed0909000 rw-p 00000000 00:00 0                          [stack]
7ffed0964000-7ffed0967000 r--p 00000000 00:00 0                          [vvar]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

标签: c++gdbvalgrind

解决方案


从输出中可以清楚地看到“坏堆栈”的原因info file:GDB认为/lib64/ld-linux-x86-64.so.2是在 加载的0x4000000,但我们知道它是在该地址加载的主二进制文件,并ld-linux在其他地方加载。

您可以通过检查来确认这一点/proc/$pid/maps

为什么 GDB 会认为ld-linux是在0x4000000?因为有些事情不太奏效。GDB 确实说过:

warning: Probes-based dynamic linker interface failed.
Reverting to original interface.

但显然“还原”部分也不起作用。

可以通过手动将符号从主二进制文件添加到 GDB 来解决此问题:

(gdb) add-symbol-file /home/ec2-user/<redacted> $addr

主要可执行文件$addr中部分的地址在哪里(用于查找该地址)。.textreadelf -WS /home/ec2-user/<redacted> | grep '\.text'


推荐阅读