From: Philippe Waroquiers Date: Sat, 23 Sep 2017 11:26:12 +0000 (+0200) Subject: massif: match --ignore-fn with the first IP that has a fnname X-Git-Tag: VALGRIND_3_14_0~254 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1232dd32a94f7b3dabd66e8cac3c0cf12d014f3;p=thirdparty%2Fvalgrind.git massif: match --ignore-fn with the first IP that has a fnname Currently, --ignore-fn is only matched with the top IP entries that have a fnname. With this change, we first search for the first IP that has a fnname. This e.g. allows to ignore the allocation for a stacktrace such as: 0x1 0x2 0x3 fn_to_ignore otherfn This is then used in massif c++ tests new-cpp and overloaded-new to ignore the c++ libstdc++ allocation similar to: ==10754== 72,704 bytes in 1 blocks are still reachable in loss record 10 of 10 ==10754== at 0x4C2BBCD: malloc (vg_replace_malloc.c:299) ==10754== by 0x4EC39BF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22) ==10754== by 0x400F8A9: call_init.part.0 (dl-init.c:72) ==10754== by 0x400F9BA: call_init (dl-init.c:30) ==10754== by 0x400F9BA: _dl_init (dl-init.c:120) ==10754== by 0x4000C59: ??? (in /lib/x86_64-linux-gnu/ld-2.24.so) --- diff --git a/massif/ms_main.c b/massif/ms_main.c index 953eda7e82..3748821240 100644 --- a/massif/ms_main.c +++ b/massif/ms_main.c @@ -507,7 +507,7 @@ void filter_IPs (Addr* ips, Int n_ips, UInt* top, UInt* n_ips_sel) { Int i; - Bool top_has_fnname; + Bool top_has_fnname = False; const HChar *fnname; *top = 0; @@ -519,7 +519,7 @@ void filter_IPs (Addr* ips, Int n_ips, // 'sliding' a bunch of functions without names by removing an // alloc function 'inside' a stacktrace e.g. // 0x1 0x2 0x3 alloc func1 main - // becomes 0x1 0x2 0x3 func1 main + // became 0x1 0x2 0x3 func1 main for (i = *top; i < n_ips; i++) { top_has_fnname = VG_(get_fnname)(ips[*top], &fnname); if (top_has_fnname && VG_(strIsMemberXA)(alloc_fns, fnname)) { @@ -532,14 +532,19 @@ void filter_IPs (Addr* ips, Int n_ips, } // filter the whole stacktrace if this allocation has to be ignored. - if (*n_ips_sel > 0 - && top_has_fnname - && VG_(strIsMemberXA)(ignore_fns, fnname)) { - VERB(4, "ignored allocation from fn %s\n", fnname); - *top = n_ips; - *n_ips_sel = 0; - } - + if (*n_ips_sel > 0 && VG_(sizeXA)(ignore_fns) > 0) { + if (!top_has_fnname) { + // top has no fnname => search for the first entry that has a fnname + for (i = *top; i < n_ips && !top_has_fnname; i++) { + top_has_fnname = VG_(get_fnname)(ips[i], &fnname); + } + } + if (top_has_fnname && VG_(strIsMemberXA)(ignore_fns, fnname)) { + VERB(4, "ignored allocation from fn %s\n", fnname); + *top = n_ips; + *n_ips_sel = 0; + } + } if (!VG_(clo_show_below_main) && *n_ips_sel > 0 ) { Int mbm = VG_(XT_offset_main_or_below_main)(ips, n_ips); diff --git a/massif/tests/new-cpp.post.exp b/massif/tests/new-cpp.post.exp index 1fe91e60ce..9d90cf6c22 100644 --- a/massif/tests/new-cpp.post.exp +++ b/massif/tests/new-cpp.post.exp @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- Command: ./new-cpp -Massif arguments: --stacks=no --time-unit=B --massif-out-file=massif.out --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook --ignore-fn=get_or_create_key_element --ignore-fn=_GLOBAL__sub_I_eh_alloc.cc +Massif arguments: --stacks=no --time-unit=B --massif-out-file=massif.out --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook --ignore-fn=get_or_create_key_element --ignore-fn=_GLOBAL__sub_I_eh_alloc.cc --ignore-fn=call_init.part.0 ms_print arguments: massif.out -------------------------------------------------------------------------------- diff --git a/massif/tests/new-cpp.vgtest b/massif/tests/new-cpp.vgtest index 09dba32977..88bdf939b9 100644 --- a/massif/tests/new-cpp.vgtest +++ b/massif/tests/new-cpp.vgtest @@ -1,6 +1,6 @@ prog: new-cpp vgopts: --stacks=no --time-unit=B --massif-out-file=massif.out vgopts: --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook -vgopts: --ignore-fn=get_or_create_key_element --ignore-fn=_GLOBAL__sub_I_eh_alloc.cc +vgopts: --ignore-fn=get_or_create_key_element --ignore-fn=_GLOBAL__sub_I_eh_alloc.cc --ignore-fn=call_init.part.0 post: perl ../../massif/ms_print massif.out | ../../tests/filter_addresses cleanup: rm massif.out diff --git a/massif/tests/overloaded-new.post.exp b/massif/tests/overloaded-new.post.exp index 2a53b90b70..e55885fc57 100644 --- a/massif/tests/overloaded-new.post.exp +++ b/massif/tests/overloaded-new.post.exp @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- Command: ./overloaded-new -Massif arguments: --stacks=no --time-unit=B --massif-out-file=massif.out --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook --ignore-fn=get_or_create_key_element --ignore-fn=_GLOBAL__sub_I_eh_alloc.cc +Massif arguments: --stacks=no --time-unit=B --massif-out-file=massif.out --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook --ignore-fn=get_or_create_key_element --ignore-fn=_GLOBAL__sub_I_eh_alloc.cc --ignore-fn=call_init.part.0 ms_print arguments: massif.out -------------------------------------------------------------------------------- diff --git a/massif/tests/overloaded-new.vgtest b/massif/tests/overloaded-new.vgtest index 2ffb3eceb4..20bcd97e62 100644 --- a/massif/tests/overloaded-new.vgtest +++ b/massif/tests/overloaded-new.vgtest @@ -1,6 +1,6 @@ prog: overloaded-new vgopts: --stacks=no --time-unit=B --massif-out-file=massif.out vgopts: --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook -vgopts: --ignore-fn=get_or_create_key_element --ignore-fn=_GLOBAL__sub_I_eh_alloc.cc +vgopts: --ignore-fn=get_or_create_key_element --ignore-fn=_GLOBAL__sub_I_eh_alloc.cc --ignore-fn=call_init.part.0 post: perl ../../massif/ms_print massif.out | ../../tests/filter_addresses cleanup: rm massif.out