Valgrind 显示???对于行号,尽管 -g 标志

2024-01-01

main.cpp

#include <iostream>

int main() {
  int* x = new int;
  std::cout << x[3] << std::endl;
  return 0;
}

命令行:

$ g++ -g main.cpp -o main
$ valgrind ./main

valgrind 输出

==27732== Memcheck, a memory error detector
==27732== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==27732== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==27732== Command: ./main
==27732== 
==27732== Invalid read of size 4
==27732==    at 0x1091A3: ??? (in /home/rofl/test_program/main)
==27732==    by 0x57FDE76: (below main) (libc-start.c:308)
==27732==  Address 0x5bb7c8c is 8 bytes after a block of size 4 alloc'd
==27732==    at 0x4C2F4FF: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==27732==    by 0x109196: ??? (in /home/rofl/test_program/main)
==27732==    by 0x57FDE76: (below main) (libc-start.c:308)
==27732== 
0
==27732== 
==27732== HEAP SUMMARY:
==27732==     in use at exit: 4 bytes in 1 blocks
==27732==   total heap usage: 3 allocs, 2 frees, 73,732 bytes allocated
==27732== 
==27732== LEAK SUMMARY:
==27732==    definitely lost: 4 bytes in 1 blocks
==27732==    indirectly lost: 0 bytes in 0 blocks
==27732==      possibly lost: 0 bytes in 0 blocks
==27732==    still reachable: 0 bytes in 0 blocks
==27732==         suppressed: 0 bytes in 0 blocks
==27732== Rerun with --leak-check=full to see details of leaked memory
==27732== 
==27732== For counts of detected and suppressed errors, rerun with: -v
==27732== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

如果我跑gdb ./main我可以中断主函数并逐行执行,因此我非常确定二进制文件中存在调试符号。


With g++ -fno-omit-frame-pointer and valgrind -v

g++ -g -fno-omit-frame-pointer main.cpp -o main
valgrind -v ./main

Valgrind 输出:

==20116== Memcheck, a memory error detector
==20116== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==20116== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==20116== Command: ./main
==20116==
--20116-- Valgrind options:
--20116--    -v
--20116-- Contents of /proc/version:
--20116--   Linux version 4.14.65-gentoo (root@KILLINGMACHINE) (gcc version 7.3.0 (Gentoo 7.3.0-r3 p1.4)) #1 SMP Mon Apr 15 05:45:45 -00 2019
--20116--
--20116-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-avx-avx2-bmi
--20116-- Page sizes: currently 4096, max supported 4096
--20116-- Valgrind library directory: /usr/lib64/valgrind
--20116-- Reading syms from /home/rofl/test_program/main
--20116-- ELF section outside all mapped regions
--20116-- Reading syms from /lib64/ld-2.28.so
--20116-- ELF section outside all mapped regions
--20116-- Reading syms from /usr/lib64/valgrind/memcheck-amd64-linux
--20116-- ELF section outside all mapped regions
--20116-- Scheduler: using generic scheduler lock implementation.
--20116-- Reading suppressions file: /usr/lib64/valgrind/default.supp
==20116== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-20116-by-rofl-on-???
==20116== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-20116-by-rofl-on-???
==20116== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-20116-by-rofl-on-???
==20116==
==20116== TO CONTROL THIS PROCESS USING vgdb (which you probably
==20116== don't want to do, unless you know exactly what you're doing,
==20116== or are doing some strange experiment):
==20116==   /usr/lib64/valgrind/../../bin/vgdb --pid=20116 ...command...
==20116==
==20116== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==20116==   /path/to/gdb ./main
==20116== and then give GDB the following command
==20116==   target remote | /usr/lib64/valgrind/../../bin/vgdb --pid=20116
==20116== --pid is optional if only one valgrind process is running
==20116==
--20116-- Reading syms from /usr/lib64/valgrind/vgpreload_core-amd64-linux.so
--20116-- ELF section outside all mapped regions
--20116-- Reading syms from /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
--20116-- ELF section outside all mapped regions
--20116-- Reading syms from /usr/lib64/gcc/x86_64-pc-linux-gnu/8.2.0/libstdc++.so.6.0.25
--20116-- Reading syms from /lib64/libm-2.28.so
--20116-- ELF section outside all mapped regions
--20116-- Reading syms from /usr/lib64/gcc/x86_64-pc-linux-gnu/8.2.0/libgcc_s.so.1
--20116-- Reading syms from /lib64/libc-2.28.so
--20116-- ELF section outside all mapped regions
==20116== Conditional jump or move depends on uninitialised value(s)
==20116==    at 0x49A65EA: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.tcc:874)
==20116==    by 0x49B3671: put (locale_facets.h:2371)
==20116==    by 0x49B3671: std::ostream& std::ostream::_M_insert<long>(long) (ostream.tcc:73)
==20116==    by 0x1091B2: ??? (in /home/rofl/test_program/main)
==20116==    by 0x503D45A: ??? (in /lib64/libc-2.28.so)
==20116==    by 0x51E7407: ???
==20116==    by 0x1FFF0001F7: ???
==20116==    by 0x1051E7407: ???
==20116==    by 0x109184: ??? (in /home/rofl/test_program/main)
==20116==
==20116== Use of uninitialised value of size 8
==20116==    at 0x49A60BE: int std::__int_to_char<char, unsigned long>(char*, unsigned long, char const*, std::_Ios_Fmtflags, bool) (locale_facets.tcc:803)
==20116==    by 0x49A6613: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.tcc:876)
==20116==    by 0x49B3671: put (locale_facets.h:2371)
==20116==    by 0x49B3671: std::ostream& std::ostream::_M_insert<long>(long) (ostream.tcc:73)
==20116==    by 0x1091B2: ??? (in /home/rofl/test_program/main)
==20116==    by 0x503D45A: ??? (in /lib64/libc-2.28.so)
==20116==    by 0x51E7407: ???
==20116==    by 0x1FFF0001F7: ???
==20116==    by 0x1051E7407: ???
==20116==    by 0x109184: ??? (in /home/rofl/test_program/main)
==20116==
==20116== Conditional jump or move depends on uninitialised value(s)
==20116==    at 0x49A60CB: int std::__int_to_char<char, unsigned long>(char*, unsigned long, char const*, std::_Ios_Fmtflags, bool) (locale_facets.tcc:806)
==20116==    by 0x49A6613: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.tcc:876)
==20116==    by 0x49B3671: put (locale_facets.h:2371)
==20116==    by 0x49B3671: std::ostream& std::ostream::_M_insert<long>(long) (ostream.tcc:73)
==20116==    by 0x1091B2: ??? (in /home/rofl/test_program/main)
==20116==    by 0x503D45A: ??? (in /lib64/libc-2.28.so)
==20116==    by 0x51E7407: ???
==20116==    by 0x1FFF0001F7: ???
==20116==    by 0x1051E7407: ???
==20116==    by 0x109184: ??? (in /home/rofl/test_program/main)
==20116==
==20116== Conditional jump or move depends on uninitialised value(s)
==20116==    at 0x49A6646: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.tcc:896)
==20116==    by 0x49B3671: put (locale_facets.h:2371)
==20116==    by 0x49B3671: std::ostream& std::ostream::_M_insert<long>(long) (ostream.tcc:73)
==20116==    by 0x1091B2: ??? (in /home/rofl/test_program/main)
==20116==    by 0x503D45A: ??? (in /lib64/libc-2.28.so)
==20116==    by 0x51E7407: ???
==20116==    by 0x1FFF0001F7: ???
==20116==    by 0x1051E7407: ???
==20116==    by 0x109184: ??? (in /home/rofl/test_program/main)
==20116==
0
==20116==
==20116== HEAP SUMMARY:
==20116==     in use at exit: 0 bytes in 0 blocks
==20116==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==20116==
==20116== All heap blocks were freed -- no leaks are possible
==20116==
==20116== Use --track-origins=yes to see where uninitialised values come from
==20116== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
==20116==
==20116== 1 errors in context 1 of 4:
==20116== Conditional jump or move depends on uninitialised value(s)
==20116==    at 0x49A6646: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.tcc:896)
==20116==    by 0x49B3671: put (locale_facets.h:2371)
==20116==    by 0x49B3671: std::ostream& std::ostream::_M_insert<long>(long) (ostream.tcc:73)
==20116==    by 0x1091B2: ??? (in /home/rofl/test_program/main)
==20116==    by 0x503D45A: ??? (in /lib64/libc-2.28.so)
==20116==    by 0x51E7407: ???
==20116==    by 0x1FFF0001F7: ???
==20116==    by 0x1051E7407: ???
==20116==    by 0x109184: ??? (in /home/rofl/test_program/main)
==20116==
==20116==
==20116== 1 errors in context 2 of 4:
==20116== Conditional jump or move depends on uninitialised value(s)
==20116==    at 0x49A60CB: int std::__int_to_char<char, unsigned long>(char*, unsigned long, char const*, std::_Ios_Fmtflags, bool) (locale_facets.tcc:806)
==20116==    by 0x49A6613: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.tcc:876)
==20116==    by 0x49B3671: put (locale_facets.h:2371)
==20116==    by 0x49B3671: std::ostream& std::ostream::_M_insert<long>(long) (ostream.tcc:73)
==20116==    by 0x1091B2: ??? (in /home/rofl/test_program/main)
==20116==    by 0x503D45A: ??? (in /lib64/libc-2.28.so)
==20116==    by 0x51E7407: ???
==20116==    by 0x1FFF0001F7: ???
==20116==    by 0x1051E7407: ???
==20116==    by 0x109184: ??? (in /home/rofl/test_program/main)
==20116==
==20116==
==20116== 1 errors in context 3 of 4:
==20116== Use of uninitialised value of size 8
==20116==    at 0x49A60BE: int std::__int_to_char<char, unsigned long>(char*, unsigned long, char const*, std::_Ios_Fmtflags, bool) (locale_facets.tcc:803)
==20116==    by 0x49A6613: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.tcc:876)
==20116==    by 0x49B3671: put (locale_facets.h:2371)
==20116==    by 0x49B3671: std::ostream& std::ostream::_M_insert<long>(long) (ostream.tcc:73)
==20116==    by 0x1091B2: ??? (in /home/rofl/test_program/main)
==20116==    by 0x503D45A: ??? (in /lib64/libc-2.28.so)
==20116==    by 0x51E7407: ???
==20116==    by 0x1FFF0001F7: ???
==20116==    by 0x1051E7407: ???
==20116==    by 0x109184: ??? (in /home/rofl/test_program/main)
==20116==
==20116==
==20116== 1 errors in context 4 of 4:
==20116== Conditional jump or move depends on uninitialised value(s)
==20116==    at 0x49A65EA: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (locale_facets.tcc:874)
==20116==    by 0x49B3671: put (locale_facets.h:2371)
==20116==    by 0x49B3671: std::ostream& std::ostream::_M_insert<long>(long) (ostream.tcc:73)
==20116==    by 0x1091B2: ??? (in /home/rofl/test_program/main)
==20116==    by 0x503D45A: ??? (in /lib64/libc-2.28.so)
==20116==    by 0x51E7407: ???
==20116==    by 0x1FFF0001F7: ???
==20116==    by 0x1051E7407: ???
==20116==    by 0x109184: ??? (in /home/rofl/test_program/main)
==20116==
==20116== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)

最有可能的是,这已经修复了 Valgrind 在读取调试信息时的错误:https://bugs.kde.org/show_bug.cgi?id=395682 https://bugs.kde.org/show_bug.cgi?id=395682。根据发行说明 http://valgrind.org/docs/manual/dist.news.html,该修复从 3.14 版本开始可用。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Valgrind 显示???对于行号,尽管 -g 标志 的相关文章

随机推荐