From 97dc43567713d30b9c0754828cb74f77b4857ee0 Mon Sep 17 00:00:00 2001 From: Florian Krohm Date: Tue, 7 Oct 2014 18:36:28 +0000 Subject: [PATCH] Merge revisions 14372 and 14607 from the BUF_REMOVAL branch to trunk. This change makes VG_(clo_suppressions), VG_(clo_fullpath_after), and VG_(clo_req_tsyms) XArrays. They used to be arrays of fixed size. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14609 --- coregrind/m_debuginfo/debuginfo.c | 7 +++--- coregrind/m_errormgr.c | 26 +++++++++++++-------- coregrind/m_main.c | 35 +++++++++------------------- coregrind/m_options.c | 9 +++----- coregrind/m_redir.c | 38 +++++++++++++++---------------- coregrind/pub_core_options.h | 21 ++++------------- 6 files changed, 59 insertions(+), 77 deletions(-) diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c index acc165a6b9..c27179240f 100644 --- a/coregrind/m_debuginfo/debuginfo.c +++ b/coregrind/m_debuginfo/debuginfo.c @@ -2257,14 +2257,15 @@ HChar* VG_(describe_IP)(Addr eip, HChar* buf, Int n_buf, InlIPCursor *iipc) APPEND(" ("); // Get the directory name, if any, possibly pruned, into dirname. HChar* dirname = NULL; - if (VG_(clo_n_fullpath_after) > 0) { + if (VG_(sizeXA)(VG_(clo_fullpath_after)) > 0) { Int i; dirname = buf_dirname; // Remove leading prefixes from the dirname. // If user supplied --fullpath-after=foo, this will remove // a leading string which matches '.*foo' (not greedy). - for (i = 0; i < VG_(clo_n_fullpath_after); i++) { - const HChar* prefix = VG_(clo_fullpath_after)[i]; + for (i = 0; i < VG_(sizeXA)(VG_(clo_fullpath_after)); i++) { + const HChar* prefix = + *(HChar**) VG_(indexXA)( VG_(clo_fullpath_after), i ); HChar* str = VG_(strstr)(dirname, prefix); if (str) { dirname = str + VG_(strlen)(prefix); diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c index f2766e9722..c2f844c536 100644 --- a/coregrind/m_errormgr.c +++ b/coregrind/m_errormgr.c @@ -957,8 +957,10 @@ static Bool show_used_suppressions ( void ) // Ensure buffer is properly terminated vg_assert(xtra[num_written] == '\0'); + HChar *filename = *(HChar**) VG_(indexXA)(VG_(clo_suppressions), + su->clo_suppressions_i); VG_(dmsg)("used_suppression: %6d %s %s:%d%s%s\n", su->count, su->sname, - VG_(clo_suppressions)[su->clo_suppressions_i], + filename, su->sname_lineno, num_written ? " " : "", xtra); VG_(free)(xtra); @@ -1259,7 +1261,8 @@ static Bool tool_name_present(const HChar *name, HChar *names) */ static void load_one_suppressions_file ( Int clo_suppressions_i ) { - const HChar* filename = VG_(clo_suppressions)[clo_suppressions_i]; + const HChar* filename = *(HChar**) VG_(indexXA)(VG_(clo_suppressions), + clo_suppressions_i); SysRes sres; Int fd, i, j, lineno = 0; Bool got_a_location_line_read_by_tool; @@ -1466,10 +1469,10 @@ void VG_(load_suppressions) ( void ) { Int i; suppressions = NULL; - for (i = 0; i < VG_(clo_n_suppressions); i++) { + for (i = 0; i < VG_(sizeXA)(VG_(clo_suppressions)); i++) { if (VG_(clo_verbosity) > 1) { VG_(dmsg)("Reading suppressions file: %s\n", - VG_(clo_suppressions)[i] ); + *(HChar**) VG_(indexXA)(VG_(clo_suppressions), i)); } load_one_suppressions_file( i ); } @@ -1598,12 +1601,14 @@ static void clearIPtoFunOrObjCompleter ( Supp *su, IPtoFunOrObjCompleter* ip2fo) { if (DEBUG_ERRORMGR || VG_(debugLog_getLevel)() >= 4) { - if (su) + if (su) { + HChar *filename = *(HChar**) VG_(indexXA)(VG_(clo_suppressions), + su->clo_suppressions_i); VG_(dmsg)("errormgr matching end suppression %s %s:%d matched:\n", su->sname, - VG_(clo_suppressions)[su->clo_suppressions_i], + filename, su->sname_lineno); - else + } else VG_(dmsg)("errormgr matching end no suppression matched:\n"); VG_(pp_StackTrace) (ip2fo->ips, ip2fo->n_ips); pp_ip2fo(ip2fo); @@ -1852,11 +1857,14 @@ static Bool supp_matches_callers(IPtoFunOrObjCompleter* ip2fo, Supp* su) UWord n_supps = su->n_callers; UWord szbPatt = sizeof(SuppLoc); Bool matchAll = False; /* we just want to match a prefix */ - if (DEBUG_ERRORMGR) + if (DEBUG_ERRORMGR) { + HChar *filename = *(HChar**) VG_(indexXA)(VG_(clo_suppressions), + su->clo_suppressions_i); VG_(dmsg)(" errormgr Checking match with %s %s:%d\n", su->sname, - VG_(clo_suppressions)[su->clo_suppressions_i], + filename, su->sname_lineno); + } return VG_(generic_match)( matchAll, diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 336a9b3ffe..b45e6f870c 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -458,6 +458,13 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, vg_assert( VG_(args_for_valgrind) ); + VG_(clo_suppressions) = VG_(newXA)(VG_(malloc), "main.mpclo.4", + VG_(free), sizeof(HChar *)); + VG_(clo_fullpath_after) = VG_(newXA)(VG_(malloc), "main.mpclo.5", + VG_(free), sizeof(HChar *)); + VG_(clo_req_tsyms) = VG_(newXA)(VG_(malloc), "main.mpclo.6", + VG_(free), sizeof(HChar *)); + /* BEGIN command-line processing loop */ for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) { @@ -712,34 +719,17 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, VG_(clo_default_supp)) { } else if VG_STR_CLO(arg, "--suppressions", tmp_str) { - if (VG_(clo_n_suppressions) >= VG_CLO_MAX_SFILES) { - VG_(fmsg_bad_option)(arg, - "Too many suppression files specified.\n" - "Increase VG_CLO_MAX_SFILES and recompile.\n"); - } - VG_(clo_suppressions)[VG_(clo_n_suppressions)] = tmp_str; - VG_(clo_n_suppressions)++; + VG_(addToXA)(VG_(clo_suppressions), &tmp_str); } else if VG_STR_CLO (arg, "--fullpath-after", tmp_str) { - if (VG_(clo_n_fullpath_after) >= VG_CLO_MAX_FULLPATH_AFTER) { - VG_(fmsg_bad_option)(arg, - "Too many --fullpath-after= specifications.\n" - "Increase VG_CLO_MAX_FULLPATH_AFTER and recompile.\n"); - } - VG_(clo_fullpath_after)[VG_(clo_n_fullpath_after)] = tmp_str; - VG_(clo_n_fullpath_after)++; + VG_(addToXA)(VG_(clo_fullpath_after), &tmp_str); } else if VG_STR_CLO (arg, "--extra-debuginfo-path", VG_(clo_extra_debuginfo_path)) {} else if VG_STR_CLO(arg, "--require-text-symbol", tmp_str) { - if (VG_(clo_n_req_tsyms) >= VG_CLO_MAX_REQ_TSYMS) { - VG_(fmsg_bad_option)(arg, - "Too many --require-text-symbol= specifications.\n" - "Increase VG_CLO_MAX_REQ_TSYMS and recompile.\n"); - } /* String needs to be of the form C?*C?*, where C is any character, but is the same both times. Having it in this form facilitates finding the boundary between the sopatt @@ -760,8 +750,7 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, VG_(fmsg_bad_option)(arg, "Invalid --require-text-symbol= specification.\n"); } - VG_(clo_req_tsyms)[VG_(clo_n_req_tsyms)] = tmp_str; - VG_(clo_n_req_tsyms)++; + VG_(addToXA)(VG_(clo_req_tsyms), &tmp_str); } /* "stuvwxyz" --> stuvwxyz (binary) */ @@ -1142,7 +1131,6 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, // Suppressions related stuff if (VG_(clo_default_supp) && - VG_(clo_n_suppressions) < VG_CLO_MAX_SFILES-1 && (VG_(needs).core_errors || VG_(needs).tool_errors)) { /* If we haven't reached the max number of suppressions, load the default one. */ @@ -1150,8 +1138,7 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, Int len = VG_(strlen)(VG_(libdir)) + 1 + sizeof(default_supp); HChar *buf = VG_(malloc)("main.mpclo.3", len); VG_(sprintf)(buf, "%s/%s", VG_(libdir), default_supp); - VG_(clo_suppressions)[VG_(clo_n_suppressions)] = buf; - VG_(clo_n_suppressions)++; + VG_(addToXA)(VG_(clo_suppressions), &buf); } *logging_to_fd = log_to == VgLogTo_Fd || log_to == VgLogTo_Socket; diff --git a/coregrind/m_options.c b/coregrind/m_options.c index 3140b810aa..eb4e0a8f9f 100644 --- a/coregrind/m_options.c +++ b/coregrind/m_options.c @@ -79,10 +79,8 @@ HChar* VG_(clo_xml_fname_expanded) = NULL; Bool VG_(clo_time_stamp) = False; Int VG_(clo_input_fd) = 0; /* stdin */ Bool VG_(clo_default_supp) = True; -Int VG_(clo_n_suppressions) = 0; -const HChar* VG_(clo_suppressions)[VG_CLO_MAX_SFILES]; -Int VG_(clo_n_fullpath_after) = 0; -const HChar* VG_(clo_fullpath_after)[VG_CLO_MAX_FULLPATH_AFTER]; +XArray *VG_(clo_suppressions); // array of strings +XArray *VG_(clo_fullpath_after); // array of strings const HChar* VG_(clo_extra_debuginfo_path) = NULL; const HChar* VG_(clo_debuginfo_server) = NULL; Bool VG_(clo_allow_mismatched_debuginfo) = False; @@ -116,8 +114,7 @@ UInt VG_(clo_sim_hints) = 0; Bool VG_(clo_sym_offsets) = False; Bool VG_(clo_read_inline_info) = False; // Or should be put it to True by default ??? Bool VG_(clo_read_var_info) = False; -Int VG_(clo_n_req_tsyms) = 0; -const HChar* VG_(clo_req_tsyms)[VG_CLO_MAX_REQ_TSYMS]; +XArray *VG_(clo_req_tsyms); // array of strings HChar* VG_(clo_require_text_symbol) = NULL; Bool VG_(clo_run_libc_freeres) = True; Bool VG_(clo_track_fds) = False; diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c index 4ca93dc7aa..78bed76f4f 100644 --- a/coregrind/m_redir.c +++ b/coregrind/m_redir.c @@ -1582,18 +1582,15 @@ static void handle_require_text_symbols ( DebugInfo* di ) frequently be used. Work through the list of specs and accumulate in fnpatts[] the fn patterns that pertain to this object. */ - HChar* fnpatts[VG_CLO_MAX_REQ_TSYMS]; - Int fnpatts_used = 0; + XArray *fnpatts = VG_(newXA)( VG_(malloc), "m_redir.hrts.5", + VG_(free), sizeof(HChar*) ); + Int i, j; const HChar* di_soname = VG_(DebugInfo_get_soname)(di); vg_assert(di_soname); // must be present - VG_(memset)(&fnpatts, 0, sizeof(fnpatts)); - - vg_assert(VG_(clo_n_req_tsyms) >= 0); - vg_assert(VG_(clo_n_req_tsyms) <= VG_CLO_MAX_REQ_TSYMS); - for (i = 0; i < VG_(clo_n_req_tsyms); i++) { - const HChar* clo_spec = VG_(clo_req_tsyms)[i]; + for (i = 0; i < VG_(sizeXA)(VG_(clo_req_tsyms)); i++) { + const HChar* clo_spec = *(HChar**) VG_(indexXA)(VG_(clo_req_tsyms), i); vg_assert(clo_spec && VG_(strlen)(clo_spec) >= 4); // clone the spec, so we can stick a zero at the end of the sopatt HChar *spec = VG_(strdup)("m_redir.hrts.1", clo_spec); @@ -1605,31 +1602,35 @@ static void handle_require_text_symbols ( DebugInfo* di ) vg_assert(fnpatt && *fnpatt == sep); *fnpatt = 0; fnpatt++; - if (VG_(string_match)(sopatt, di_soname)) - fnpatts[fnpatts_used++] - = VG_(strdup)("m_redir.hrts.2", fnpatt); + if (VG_(string_match)(sopatt, di_soname)) { + HChar *pattern = VG_(strdup)("m_redir.hrts.2", fnpatt); + VG_(addToXA)(fnpatts, &pattern); + } VG_(free)(spec); } - if (fnpatts_used == 0) + if (VG_(sizeXA)(fnpatts) == 0) { + VG_(deleteXA)(fnpatts); return; /* no applicable spec strings */ + } - /* So finally, fnpatts[0 .. fnpatts_used - 1] contains the set of + /* So finally, fnpatts contains the set of (patterns for) text symbol names that must be found in this object, in order to continue. That is, we must find at least one text symbol name that matches each pattern, else we must abort the run. */ if (0) VG_(printf)("for %s\n", di_soname); - for (i = 0; i < fnpatts_used; i++) - if (0) VG_(printf)(" fnpatt: %s\n", fnpatts[i]); + for (i = 0; i < VG_(sizeXA)(fnpatts); i++) + if (0) VG_(printf)(" fnpatt: %s\n", + *(HChar**) VG_(indexXA)(fnpatts, i)); /* For each spec, look through the syms to find one that matches. This isn't terribly efficient but it happens rarely, so no big deal. */ - for (i = 0; i < fnpatts_used; i++) { + for (i = 0; i < VG_(sizeXA)(fnpatts); i++) { Bool found = False; - HChar* fnpatt = fnpatts[i]; + const HChar* fnpatt = *(HChar**) VG_(indexXA)(fnpatts, i); Int nsyms = VG_(DebugInfo_syms_howmany)(di); for (j = 0; j < nsyms; j++) { Bool isText = False; @@ -1680,8 +1681,7 @@ static void handle_require_text_symbols ( DebugInfo* di ) } /* All required specs were found. Just free memory and return. */ - for (i = 0; i < fnpatts_used; i++) - VG_(free)(fnpatts[i]); + VG_(deleteXA)(fnpatts); } diff --git a/coregrind/pub_core_options.h b/coregrind/pub_core_options.h index e44a30fa73..e98a88c167 100644 --- a/coregrind/pub_core_options.h +++ b/coregrind/pub_core_options.h @@ -37,15 +37,7 @@ // other module imports this one, if only for VG_(clo_verbosity). //-------------------------------------------------------------------- #include "pub_tool_options.h" - -/* The max number of suppression files. */ -#define VG_CLO_MAX_SFILES 100 - -/* The max number of --require-text-symbol= specification strings. */ -#define VG_CLO_MAX_REQ_TSYMS 100 - -/* The max number of --fullpath-after= parameters. */ -#define VG_CLO_MAX_FULLPATH_AFTER 100 +#include "pub_core_xarray.h" /* Should we stop collecting errors if too many appear? default: YES */ extern Bool VG_(clo_error_limit); @@ -135,14 +127,12 @@ extern Int VG_(clo_input_fd); /* Whether or not to load the default suppressions. */ extern Bool VG_(clo_default_supp); -/* The number of suppression files specified. */ -extern Int VG_(clo_n_suppressions); + /* The names of the suppression files. */ -extern const HChar* VG_(clo_suppressions)[VG_CLO_MAX_SFILES]; +extern XArray *VG_(clo_suppressions); /* An array of strings harvested from --fullpath-after= flags. */ -extern Int VG_(clo_n_fullpath_after); -extern const HChar* VG_(clo_fullpath_after)[VG_CLO_MAX_FULLPATH_AFTER]; +extern XArray *VG_(clo_fullpath_after); /* Full path to additional path to search for debug symbols */ extern const HChar* VG_(clo_extra_debuginfo_path); @@ -276,8 +266,7 @@ extern const HChar* VG_(clo_prefix_to_strip); silently with the un-marked-up library. Note that you should put the entire flag in quotes to stop shells messing up the * and ? wildcards. */ -extern Int VG_(clo_n_req_tsyms); -extern const HChar* VG_(clo_req_tsyms)[VG_CLO_MAX_REQ_TSYMS]; +extern XArray *VG_(clo_req_tsyms); /* Track open file descriptors? */ extern Bool VG_(clo_track_fds); -- 2.47.2