|
From: <sv...@va...> - 2014-08-27 15:15:17
|
Author: florian
Date: Wed Aug 27 15:14:57 2014
New Revision: 14372
Log:
Get rid of VG_CLO_MAX_SFILES, VG_CLO_MAX_REQ_TSYMS, and
VG_CLO_MAX_FULLPATH_AFTER. As the dynamic memory manager is already
running at the point when we're disecting the command line, we can as
well allocate the required memory dynamically.
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 Wed Aug 27 15:14:57 2014
@@ -2253,14 +2253,14 @@
APPEND(" (");
// Get the directory name, if any, possibly pruned, into dirname.
HChar* dirname = NULL;
- if (VG_(clo_n_fullpath_after) > 0) {
+ if (VG_(clo_fullpath_after).n_used > 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_(clo_fullpath_after).n_used; i++) {
+ const HChar* prefix = VG_(clo_fullpath_after).names[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 Wed Aug 27 15:14:57 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) giving filename from which suppression
- // was read, and the lineno in this file where sname was read.
+ // Index in VG_(clo_suppressions).names giving filename from which
+ // suppression was read, and the lineno in this file where sname was read.
Int clo_suppressions_i;
Int sname_lineno;
@@ -959,7 +959,7 @@
vg_assert(xtra[num_written] == '\0');
VG_(dmsg)("used_suppression: %6d %s %s:%d%s%s\n", su->count, su->sname,
- VG_(clo_suppressions)[su->clo_suppressions_i],
+ VG_(clo_suppressions).names[su->clo_suppressions_i],
su->sname_lineno,
num_written ? " " : "", xtra);
VG_(free)(xtra);
@@ -1256,13 +1256,13 @@
}
/* Read suppressions from the file specified in
- VG_(clo_suppressions)[clo_suppressions_i]
+ VG_(clo_suppressions).names[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)[clo_suppressions_i];
+ const HChar* filename = VG_(clo_suppressions).names[clo_suppressions_i];
SysRes sres;
Int fd, i, j, lineno = 0;
Bool got_a_location_line_read_by_tool;
@@ -1471,10 +1471,10 @@
{
Int i;
suppressions = NULL;
- for (i = 0; i < VG_(clo_n_suppressions); i++) {
+ for (i = 0; i < VG_(clo_suppressions).n_used; i++) {
if (VG_(clo_verbosity) > 1) {
VG_(dmsg)("Reading suppressions file: %s\n",
- VG_(clo_suppressions)[i] );
+ VG_(clo_suppressions).names[i] );
}
load_one_suppressions_file( i );
}
@@ -1606,7 +1606,7 @@
if (su)
VG_(dmsg)("errormgr matching end suppression %s %s:%d matched:\n",
su->sname,
- VG_(clo_suppressions)[su->clo_suppressions_i],
+ VG_(clo_suppressions).names[su->clo_suppressions_i],
su->sname_lineno);
else
VG_(dmsg)("errormgr matching end no suppression matched:\n");
@@ -1869,7 +1869,7 @@
if (DEBUG_ERRORMGR)
VG_(dmsg)(" errormgr Checking match with %s %s:%d\n",
su->sname,
- VG_(clo_suppressions)[su->clo_suppressions_i],
+ VG_(clo_suppressions).names[su->clo_suppressions_i],
su->sname_lineno);
return
VG_(generic_match)(
Modified: branches/BUF_REMOVAL/coregrind/m_main.c
==============================================================================
--- branches/BUF_REMOVAL/coregrind/m_main.c (original)
+++ branches/BUF_REMOVAL/coregrind/m_main.c Wed Aug 27 15:14:57 2014
@@ -386,6 +386,16 @@
}
}
+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.
@@ -701,34 +711,19 @@
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)++;
+ maybe_resize_array_of_strings(&VG_(clo_suppressions), 10);
+ VG_(clo_suppressions).names[VG_(clo_suppressions).n_used++] = 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)++;
+ maybe_resize_array_of_strings(&VG_(clo_fullpath_after), 10);
+ VG_(clo_fullpath_after).names[VG_(clo_fullpath_after).n_used++] = 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
@@ -749,8 +744,8 @@
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)++;
+ maybe_resize_array_of_strings(&VG_(clo_req_tsyms), 10);
+ VG_(clo_req_tsyms).names[VG_(clo_req_tsyms).n_used++] = tmp_str;
}
/* "stuvwxyz" --> stuvwxyz (binary) */
@@ -1125,7 +1120,6 @@
// 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. */
@@ -1133,8 +1127,8 @@
Int len = VG_(strlen)(VG_(libdir)) + 1 + sizeof(default_supp);
HChar *buf = VG_(arena_malloc)(VG_AR_CORE, "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)++;
+ maybe_resize_array_of_strings(&VG_(clo_suppressions), 10);
+ VG_(clo_suppressions).names[VG_(clo_suppressions).n_used++] = 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 Wed Aug 27 15:14:57 2014
@@ -79,10 +79,8 @@
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];
+ArrayOfStrings VG_(clo_suppressions);
+ArrayOfStrings VG_(clo_fullpath_after);
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 @@
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];
+ArrayOfStrings VG_(clo_req_tsyms);
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 Wed Aug 27 15:14:57 2014
@@ -1574,18 +1574,17 @@
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;
+ ArrayOfStrings fnpatts;
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));
+ fnpatts.n_used = 0;
+ fnpatts.n_allocated = VG_(clo_req_tsyms).n_used;
+ fnpatts.names = VG_(malloc)("m_redir.hrts.3", fnpatts.n_allocated);
- 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_(clo_req_tsyms).n_used; i++) {
+ const HChar* clo_spec = VG_(clo_req_tsyms).names[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);
@@ -1598,12 +1597,12 @@
*fnpatt = 0;
fnpatt++;
if (VG_(string_match)(sopatt, di_soname))
- fnpatts[fnpatts_used++]
+ fnpatts.names[fnpatts.n_used++]
= VG_(strdup)("m_redir.hrts.2", fnpatt);
VG_(free)(spec);
}
- if (fnpatts_used == 0)
+ if (fnpatts.n_used == 0)
return; /* no applicable spec strings */
/* So finally, fnpatts[0 .. fnpatts_used - 1] contains the set of
@@ -1613,15 +1612,15 @@
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 < fnpatts.n_used; i++)
+ if (0) VG_(printf)(" fnpatt: %s\n", fnpatts.names[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 < fnpatts.n_used; i++) {
Bool found = False;
- HChar* fnpatt = fnpatts[i];
+ const HChar* fnpatt = fnpatts.names[i];
Int nsyms = VG_(DebugInfo_syms_howmany)(di);
for (j = 0; j < nsyms; j++) {
Bool isText = False;
@@ -1672,8 +1671,8 @@
}
/* All required specs were found. Just free memory and return. */
- for (i = 0; i < fnpatts_used; i++)
- VG_(free)(fnpatts[i]);
+ for (i = 0; i < fnpatts.n_used; i++)
+ VG_(free)((HChar *)fnpatts.names[i]);
}
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 Wed Aug 27 15:14:57 2014
@@ -38,14 +38,11 @@
//--------------------------------------------------------------------
#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
+typedef struct {
+ const HChar **names;
+ UInt n_used;
+ UInt n_allocated;
+} ArrayOfStrings;
/* Should we stop collecting errors if too many appear? default: YES */
extern Bool VG_(clo_error_limit);
@@ -135,14 +132,12 @@
/* 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 ArrayOfStrings 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 ArrayOfStrings VG_(clo_fullpath_after);
/* Full path to additional path to search for debug symbols */
extern const HChar* VG_(clo_extra_debuginfo_path);
@@ -276,8 +271,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 Int VG_(clo_n_req_tsyms);
-extern const HChar* VG_(clo_req_tsyms)[VG_CLO_MAX_REQ_TSYMS];
+extern ArrayOfStrings VG_(clo_req_tsyms);
/* Track open file descriptors? */
extern Bool VG_(clo_track_fds);
|