Tôi đã chương trình C này được biên soạn với một trong hai gcc test.c
hoặc clang test.c
:Valgrind báo cáo giá trị chưa khởi tạo trên chương trình C trống
int main (void) {
return 0;
}
valgrind ./a.out
mang lại cho tôi điều này: phiên bản
==9232== Memcheck, a memory error detector
==9232== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==9232== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==9232== Command: ./a.out
==9232==
==9232== Conditional jump or move depends on uninitialised value(s)
==9232== at 0x4017876: index (in /usr/lib/ld-2.16.so)
==9232== by 0x4007902: expand_dynamic_string_token (in /usr/lib/ld-2.16.so)
==9232== by 0x4008204: _dl_map_object (in /usr/lib/ld-2.16.so)
==9232== by 0x400180D: map_doit (in /usr/lib/ld-2.16.so)
==9232== by 0x400E785: _dl_catch_error (in /usr/lib/ld-2.16.so)
==9232== by 0x40010DB: do_preload (in /usr/lib/ld-2.16.so)
==9232== by 0x4004546: dl_main (in /usr/lib/ld-2.16.so)
==9232== by 0x4014B5D: _dl_sysdep_start (in /usr/lib/ld-2.16.so)
==9232== by 0x4004DFD: _dl_start (in /usr/lib/ld-2.16.so)
==9232== by 0x4001627: ??? (in /usr/lib/ld-2.16.so)
==9232==
==9232== Conditional jump or move depends on uninitialised value(s)
==9232== at 0x401787B: index (in /usr/lib/ld-2.16.so)
==9232== by 0x4007902: expand_dynamic_string_token (in /usr/lib/ld-2.16.so)
==9232== by 0x4008204: _dl_map_object (in /usr/lib/ld-2.16.so)
==9232== by 0x400180D: map_doit (in /usr/lib/ld-2.16.so)
==9232== by 0x400E785: _dl_catch_error (in /usr/lib/ld-2.16.so)
==9232== by 0x40010DB: do_preload (in /usr/lib/ld-2.16.so)
==9232== by 0x4004546: dl_main (in /usr/lib/ld-2.16.so)
==9232== by 0x4014B5D: _dl_sysdep_start (in /usr/lib/ld-2.16.so)
==9232== by 0x4004DFD: _dl_start (in /usr/lib/ld-2.16.so)
==9232== by 0x4001627: ??? (in /usr/lib/ld-2.16.so)
==9232==
==9232==
==9232== HEAP SUMMARY:
==9232== in use at exit: 0 bytes in 0 blocks
==9232== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==9232==
==9232== All heap blocks were freed -- no leaks are possible
==9232==
==9232== For counts of detected and suppressed errors, rerun with: -v
==9232== Use --track-origins=yes to see where uninitialised values come from
==9232== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
GCC 4.7.1 và phiên bản Clang 3.1. là gì với điều này? Có gì sai với trí nhớ của tôi không? Có một số thời gian kể từ lần cuối tôi sử dụng valgrind nhưng điều này tôi nghĩ không phải là hành vi bình thường. Yelp?
Giải pháp: Có thể từ những gì tôi học được từ @Shawn để ngăn chặn các lỗi này mối liên kết sử dụng một valgrind .supp
tập tin. Những gì tôi đã làm được chạy valgrind trên chương trình của tôi bằng cách sử dụng --gen-suppressions=all
tùy chọn:
valgrind --gen-suppressions=all ./a.out
Sau đó, tôi trích xuất các khối mới kèm theo trong ngoặc đơn và đặt chúng trực tiếp vào một tập tin my.supp
:
{
<linker>
Memcheck:Cond
fun:index
fun:expand_dynamic_string_token
fun:_dl_map_object
fun:map_doit
fun:_dl_catch_error
fun:do_preload
fun:dl_main
fun:_dl_sysdep_start
fun:_dl_start
obj:/usr/lib/ld-2.16.so
}
Bây giờ tôi có thể chạy valgrind với tùy chọn --suppressions
để trỏ đến tệp mới của tôi và các tin nhắn sẽ bị chặn:
valgrind --suppressions=/home/foo/my.supp ./a.out
Như @ypnos ám chỉ, một chương trình c "trống" được biên soạn bởi gcc là cách xa trống. Hãy thử 'ldd a.out' trong một thời điểm tốt. – msw
@msw - học một cái gì đó mỗi ngày :) –