|
From: <sv...@va...> - 2014-10-07 17:50:52
|
Author: florian
Date: Tue Oct 7 18:50:44 2014
New Revision: 14607
Log:
Use XArray instead of custom data structure ArrayOfStrings.
Modified:
branches/BUF_REMOVAL/coregrind/m_debuginfo/debuginfo.c
branches/BUF_REMOVAL/coregrind/m_errormgr.c
branches/BUF_REMOVAL/coregrind/m_main.c
branches/BUF_REMOVAL/coregrind/m_options.c
branches/BUF_REMOVAL/coregrind/m_redir.c
branches/BUF_REMOVAL/coregrind/pub_core_options.h
Modified: branches/BUF_REMOVAL/coregrind/m_debuginfo/debuginfo.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_debuginfo/debuginfo.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_debuginfo/debuginfo.c Tue Oct 7 18:50:44 2014
@@ -2253,14 +2253,15 @@
APPEND(" (");
// Get the directory name, if any, possibly pruned, into dirname.
HChar* dirname = NULL;
- if (VG_(clo_fullpath_after).n_used > 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_fullpath_after).n_used; i++) {
- const HChar* prefix = VG_(clo_fullpath_after).names[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);
Modified: branches/BUF_REMOVAL/coregrind/m_errormgr.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_errormgr.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_errormgr.c Tue Oct 7 18:50:44 2014
@@ -229,8 +229,8 @@
Int count; // The number of times this error has been suppressed.
HChar* sname; // The name by which the suppression is referred to.
- // Index in VG_(clo_suppressions).names giving filename from which
- // suppression was read, and the lineno in this file where sname was read.
+ // Index in VG_(clo_suppressions) giving filename from which suppression
+ // was read, and the lineno in this file where sname was read.
Int clo_suppressions_i;
Int sname_lineno;
@@ -957,8 +957,10 @@
// 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).names[su->clo_suppressions_i],
+ filename,
su->sname_lineno,
num_written ? " " : "", xtra);
VG_(free)(xtra);
@@ -1253,13 +1255,14 @@
}
/* Read suppressions from the file specified in
- VG_(clo_suppressions).names[clo_suppressions_i]
+ VG_(clo_suppressions)[clo_suppressions_i]
and place them in the suppressions list. If there's any difficulty
doing this, just give up -- there's no point in trying to recover.
*/
static void load_one_suppressions_file ( Int clo_suppressions_i )
{
- const HChar* filename = VG_(clo_suppressions).names[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 @@
{
Int i;
suppressions = NULL;
- for (i = 0; i < VG_(clo_suppressions).n_used; 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).names[i] );
+ *(HChar**) VG_(indexXA)(VG_(clo_suppressions), i));
}
load_one_suppressions_file( i );
}
@@ -1598,12 +1601,14 @@
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).names[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);
@@ -1861,11 +1866,14 @@
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).names[su->clo_suppressions_i],
+ filename,
su->sname_lineno);
+ }
return
VG_(generic_match)(
matchAll,
Modified: branches/BUF_REMOVAL/coregrind/m_main.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_main.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_main.c Tue Oct 7 18:50:44 2014
@@ -393,16 +393,6 @@
}
}
-static void
-maybe_resize_array_of_strings(ArrayOfStrings *aos, UInt amount)
-{
- if (aos->n_used == aos->n_allocated) {
- aos->n_allocated += amount;
- aos->names = VG_(realloc)("clo", aos->names, aos->n_allocated);
- }
-}
-
-
/* The main processing for command line options. See comments above
on early_process_cmd_line_options.
@@ -468,6 +458,13 @@
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++) {
@@ -722,13 +719,11 @@
VG_(clo_default_supp)) { }
else if VG_STR_CLO(arg, "--suppressions", tmp_str) {
- maybe_resize_array_of_strings(&VG_(clo_suppressions), 10);
- VG_(clo_suppressions).names[VG_(clo_suppressions).n_used++] = tmp_str;
+ VG_(addToXA)(VG_(clo_suppressions), &tmp_str);
}
else if VG_STR_CLO (arg, "--fullpath-after", tmp_str) {
- maybe_resize_array_of_strings(&VG_(clo_fullpath_after), 10);
- VG_(clo_fullpath_after).names[VG_(clo_fullpath_after).n_used++] = tmp_str;
+ VG_(addToXA)(VG_(clo_fullpath_after), &tmp_str);
}
else if VG_STR_CLO (arg, "--extra-debuginfo-path",
@@ -755,8 +750,7 @@
VG_(fmsg_bad_option)(arg,
"Invalid --require-text-symbol= specification.\n");
}
- maybe_resize_array_of_strings(&VG_(clo_req_tsyms), 10);
- VG_(clo_req_tsyms).names[VG_(clo_req_tsyms).n_used++] = tmp_str;
+ VG_(addToXA)(VG_(clo_req_tsyms), &tmp_str);
}
/* "stuvwxyz" --> stuvwxyz (binary) */
@@ -1144,8 +1138,7 @@
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);
- maybe_resize_array_of_strings(&VG_(clo_suppressions), 10);
- VG_(clo_suppressions).names[VG_(clo_suppressions).n_used++] = buf;
+ VG_(addToXA)(VG_(clo_suppressions), &buf);
}
*logging_to_fd = log_to == VgLogTo_Fd || log_to == VgLogTo_Socket;
Modified: branches/BUF_REMOVAL/coregrind/m_options.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_options.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_options.c Tue Oct 7 18:50:44 2014
@@ -79,8 +79,8 @@
Bool VG_(clo_time_stamp) = False;
Int VG_(clo_input_fd) = 0; /* stdin */
Bool VG_(clo_default_supp) = True;
-ArrayOfStrings VG_(clo_suppressions);
-ArrayOfStrings VG_(clo_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;
@@ -114,7 +114,7 @@
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;
-ArrayOfStrings VG_(clo_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;
Modified: branches/BUF_REMOVAL/coregrind/m_redir.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_redir.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_redir.c Tue Oct 7 18:50:44 2014
@@ -1578,17 +1578,15 @@
frequently be used. Work through the list of specs and
accumulate in fnpatts[] the fn patterns that pertain to this
object. */
- ArrayOfStrings fnpatts;
+ 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
- fnpatts.n_used = 0;
- fnpatts.n_allocated = VG_(clo_req_tsyms).n_used;
- fnpatts.names = VG_(malloc)("m_redir.hrts.3", fnpatts.n_allocated);
-
- for (i = 0; i < VG_(clo_req_tsyms).n_used; i++) {
- const HChar* clo_spec = VG_(clo_req_tsyms).names[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);
@@ -1600,31 +1598,35 @@
vg_assert(fnpatt && *fnpatt == sep);
*fnpatt = 0;
fnpatt++;
- if (VG_(string_match)(sopatt, di_soname))
- fnpatts.names[fnpatts.n_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.n_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.n_used; i++)
- if (0) VG_(printf)(" fnpatt: %s\n", fnpatts.names[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.n_used; i++) {
+ for (i = 0; i < VG_(sizeXA)(fnpatts); i++) {
Bool found = False;
- const HChar* fnpatt = fnpatts.names[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;
@@ -1675,8 +1677,7 @@
}
/* All required specs were found. Just free memory and return. */
- for (i = 0; i < fnpatts.n_used; i++)
- VG_(free)((HChar *)fnpatts.names[i]);
+ VG_(deleteXA)(fnpatts);
}
Modified: branches/BUF_REMOVAL/coregrind/pub_core_options.h
==============================================================================
--- branches/BUF_REMOVAL/coregrind/pub_core_options.h (original)
+++ branches/BUF_REMOVAL/coregrind/pub_core_options.h Tue Oct 7 18:50:44 2014
@@ -37,12 +37,7 @@
// other module imports this one, if only for VG_(clo_verbosity).
//--------------------------------------------------------------------
#include "pub_tool_options.h"
-
-typedef struct {
- const HChar **names;
- UInt n_used;
- UInt n_allocated;
-} ArrayOfStrings;
+#include "pub_core_xarray.h"
/* Should we stop collecting errors if too many appear? default: YES */
extern Bool VG_(clo_error_limit);
@@ -134,10 +129,10 @@
extern Bool VG_(clo_default_supp);
/* The names of the suppression files. */
-extern ArrayOfStrings VG_(clo_suppressions);
+extern XArray *VG_(clo_suppressions);
/* An array of strings harvested from --fullpath-after= flags. */
-extern ArrayOfStrings VG_(clo_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);
@@ -271,7 +266,7 @@
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 ArrayOfStrings VG_(clo_req_tsyms);
+extern XArray *VG_(clo_req_tsyms);
/* Track open file descriptors? */
extern Bool VG_(clo_track_fds);
|