#include "pub_tool_options.h"
#include "pub_tool_oset.h"
#include "pub_tool_tooliface.h"
+#include "pub_tool_xarray.h"
#include "pub_tool_clientstate.h"
#include "pub_tool_machine.h" // VG_(fnptr_to_fnentry)
VG_(write)(fd, VG_(args_the_exename),
VG_(strlen)( VG_(args_the_exename) ));
}
- for (i = 0; i < VG_(args_for_client).used; i++) {
- if (VG_(args_for_client).strs[i]) {
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+ HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
+ if (arg) {
VG_(write)(fd, " ", 1);
- VG_(write)(fd, VG_(args_for_client).strs[i],
- VG_(strlen)(VG_(args_for_client).strs[i]));
+ VG_(write)(fd, arg, VG_(strlen)( arg ));
}
}
// "events:" line
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
VG_(sprintf)(buf, " %s", VG_(args_the_exename));
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
- for (i = 0; i < VG_(args_for_client).used; i++) {
- if (!VG_(args_for_client).strs[i]) continue;
- VG_(sprintf)(buf, " %s", VG_(args_for_client).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+ HChar* arg = * (HChar**)VG_(indexXA)( VG_(args_for_client), i );
+ if (!arg) continue;
+ tl_assert( VG_(strlen)(arg) < 512-4 ); /* see [512] above */
+ VG_(sprintf)(buf, " %s", arg);
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
}
VG_(write)(fd, "\n", 1);
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
VG_(sprintf)(buf, " %s", VG_(args_the_exename));
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
- for (i = 0; i < VG_(args_for_client).used; i++) {
- if (!VG_(args_for_client).strs[i]) continue;
- VG_(sprintf)(buf, " %s", VG_(args_for_client).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+ HChar* arg = * (HChar**)VG_(indexXA)( VG_(args_for_client), i );
+ if (!arg) continue;
+ VG_(sprintf)(buf, " %s", arg);
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
}
VG_(write)(fd, "\n", 1);
if (VG_(args_the_exename))
size = VG_(sprintf)(cmdbuf, " %s", VG_(args_the_exename));
- for(i = 0; i < VG_(args_for_client).used; i++) {
- argv = VG_(args_for_client).strs[i];
+ for(i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+ argv = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
if (!argv) continue;
if ((size>0) && (size < BUF_LEN)) cmdbuf[size++] = ' ';
for(j=0;argv[j]!=0;j++)
}
#else
for(i = 0; i < VG_(client_argc); i++) {
- argv = VG_(client_argv[i]);
+ argv = VG_(client_argv)[i];
if (!argv) continue;
if ((size>0) && (size < BUF_LEN)) cmdbuf[size++] = ' ';
for(j=0;argv[j]!=0;j++)
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
#include "pub_tool_tooliface.h"
+#include "pub_tool_xarray.h"
#include "pub_tool_clientstate.h"
#include "pub_tool_machine.h" // VG_(fnptr_to_fnentry)
#include "pub_core_basics.h"
#include "pub_core_vki.h"
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h"
/*-----------------------------------------------------------------*/
// (the default arena). They are never freed.
/* Args for the client. */
-XArrayStrings VG_(args_for_client) = {0,0,NULL};
+XArray* /* of HChar* */ VG_(args_for_client) = NULL;
/* Args for V (augments, then those from the launcher). */
-XArrayStrings VG_(args_for_valgrind) = {0,0,NULL};
+XArray* /* of HChar* */ VG_(args_for_valgrind) = NULL;
/* How many of the above not to pass on at execve time? */
Int VG_(args_for_valgrind_noexecpass) = 0;
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
#include "pub_core_mallocfree.h"
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h"
-#include "pub_core_commandline.h"
+#include "pub_core_commandline.h" /* self */
/* Add a string to an expandable array of strings. */
-static void add_string ( XArrayStrings* xa, HChar* str )
+static void add_string ( XArray* /* of HChar* */xa, HChar* str )
{
- Int i;
- HChar** strs2;
- vg_assert(xa->used >= 0);
- vg_assert(xa->size >= 0);
- vg_assert(xa->used <= xa->size);
- if (xa->strs == NULL) vg_assert(xa->size == 0);
-
- if (xa->used == xa->size) {
- xa->size = xa->size==0 ? 2 : 2*xa->size;
- strs2 = VG_(malloc)( xa->size * sizeof(HChar*) );
- for (i = 0; i < xa->used; i++)
- strs2[i] = xa->strs[i];
- if (xa->strs)
- VG_(free)(xa->strs);
- xa->strs = strs2;
- }
- vg_assert(xa->used < xa->size);
- xa->strs[xa->used++] = str;
+ VG_(addToXA)( xa, (void*)(&str) );
}
tmp = cp;
while ( !VG_(isspace)(*cp) && *cp != 0 ) cp++;
if ( *cp != 0 ) *cp++ = '\0'; // terminate if not the last
- add_string( &VG_(args_for_valgrind), tmp );
+ add_string( VG_(args_for_valgrind), tmp );
}
}
Bool augment = True;
static Bool already_called = False;
- XArrayStrings tmp_xarray = {0,0,NULL};
+ XArray* /* of HChar* */ tmp_xarray;
/* This function should be called once, at startup, and then never
again. */
vg_assert(!already_called);
already_called = True;
+ tmp_xarray = VG_(newXA)( VG_(malloc), VG_(free), sizeof(HChar*) );
+ vg_assert(tmp_xarray);
+
+ vg_assert( ! VG_(args_for_valgrind) );
+ VG_(args_for_valgrind)
+ = VG_(newXA)( VG_(malloc), VG_(free), sizeof(HChar*) );
+ vg_assert( VG_(args_for_valgrind) );
+
+ vg_assert( ! VG_(args_for_client) );
+ VG_(args_for_client)
+ = VG_(newXA)( VG_(malloc), VG_(free), sizeof(HChar*) );
+ vg_assert( VG_(args_for_client) );
+
/* Collect up the args-for-V. */
i = 1; /* skip the exe (stage2) name. */
for (; i < argc; i++) {
augment = False;
if (argv[i][0] != '-')
break;
- add_string( &tmp_xarray, argv[i] );
+ add_string( tmp_xarray, argv[i] );
}
/* Should now be looking at the exe name. */
/* The rest are args for the client. */
for (; i < argc; i++) {
vg_assert(argv[i]);
- add_string( &VG_(args_for_client), argv[i] );
+ add_string( VG_(args_for_client), argv[i] );
}
- VG_(args_for_valgrind).size = 0;
- VG_(args_for_valgrind).used = 0;
- VG_(args_for_valgrind).strs = NULL;
-
/* Get extra args from ~/.valgrindrc, $VALGRIND_OPTS and
./.valgrindrc into VG_(args_for_valgrind). */
if (augment) {
}
/* .. and record how many extras we got. */
- VG_(args_for_valgrind_noexecpass) = VG_(args_for_valgrind).used;
+ VG_(args_for_valgrind_noexecpass)
+ = VG_(sizeXA)( VG_(args_for_valgrind) );
/* Finally, copy tmp_xarray onto the end. */
- for (i = 0; i < tmp_xarray.used; i++)
- add_string( &VG_(args_for_valgrind), tmp_xarray.strs[i] );
+ for (i = 0; i < VG_(sizeXA)( tmp_xarray ); i++)
+ add_string( VG_(args_for_valgrind),
+ * (HChar**)VG_(indexXA)( tmp_xarray, i ) );
- if (tmp_xarray.strs)
- VG_(free)(tmp_xarray.strs);
+ VG_(deleteXA)( tmp_xarray );
}
/*--------------------------------------------------------------------*/
#include "pub_core_libcassert.h" // VG_(exit), vg_assert
#include "pub_core_mallocfree.h" // VG_(malloc), VG_(free)
#include "pub_core_threadstate.h"
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h"
#include "pub_core_options.h"
#include "pub_core_basics.h"
#include "pub_core_vki.h"
#include "pub_core_threadstate.h"
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h"
#include "pub_core_debugger.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcfile.h"
#include "pub_core_libcproc.h"
#include "pub_core_libcprint.h"
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_mallocfree.h"
Bool have_exename;
vg_assert(VG_IS_PAGE_ALIGNED(clstack_end+1));
+ vg_assert( VG_(args_for_client) );
/* use our own auxv as a prototype */
orig_auxv = VG_(find_auxv)(init_sp);
if (have_exename)
stringsize += VG_(strlen)( VG_(args_the_exename) ) + 1;
- for (i = 0; i < VG_(args_for_client).used; i++) {
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
argc++;
- stringsize += VG_(strlen)( VG_(args_for_client).strs[i] ) + 1;
+ stringsize += VG_(strlen)( * (HChar**)
+ VG_(indexXA)( VG_(args_for_client), i ))
+ + 1;
}
/* ...and the environment */
if (have_exename)
*ptr++ = (Addr)copy_str(&strtab, VG_(args_the_exename));
- for (i = 0; i < VG_(args_for_client).used; i++) {
- *ptr++ = (Addr)copy_str(&strtab, VG_(args_for_client).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+ *ptr++ = (Addr)copy_str(
+ &strtab,
+ * (HChar**) VG_(indexXA)( VG_(args_for_client), i )
+ );
}
*ptr++ = 0;
#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h" // VG_(sprintf)
#include "pub_core_libcproc.h" // VG_(getpid), VG_(getppid)
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h" // VG_(fd_hard_limit)
#include "pub_core_syscall.h"
#include "pub_core_libcsignal.h"
#include "pub_core_mallocfree.h"
#include "pub_core_syscall.h"
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h"
/* ---------------------------------------------------------------------
#include "pub_core_vki.h"
#include "pub_core_vkiscnums.h"
#include "pub_core_threadstate.h"
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_commandline.h"
UInt i;
HChar* str;
+ vg_assert( VG_(args_for_valgrind) );
+
/* parse the options we have (only the options we care about now) */
- for (i = 0; i < VG_(args_for_valgrind).used; i++) {
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) {
- str = VG_(args_for_valgrind).strs[i];
+ str = * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i );
vg_assert(str);
if (VG_STREQ(str, "--version")) {
VG_(err_config_error)("Please use absolute paths in "
"./configure --prefix=... or --libdir=...");
- for (i = 0; i < VG_(args_for_valgrind).used; i++) {
+ vg_assert( VG_(args_for_valgrind) );
+
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) {
- HChar* arg = VG_(args_for_valgrind).strs[i];
+ HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i );
HChar* colon = arg;
/* Look for a colon in the switch name */
VG_(err_bad_option)(arg);
}
skip_arg:
- if (arg != VG_(args_for_valgrind).strs[i]) {
+ if (arg != * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i )) {
VG_(free)(arg);
}
}
HChar* xpost = VG_(clo_xml) ? "</line>" : "";
Int i;
+ vg_assert( VG_(args_for_client) );
+ vg_assert( VG_(args_for_valgrind) );
+
if (VG_(clo_xml)) {
VG_(message)(Vg_UserMsg, "<?xml version=\"1.0\"?>");
VG_(message)(Vg_UserMsg, "");
VG_(getpid)(), VG_(getppid)() );
if (VG_(args_the_exename))
VG_(message)(Vg_UserMsg, " %s", VG_(args_the_exename));
- for (i = 0; i < VG_(args_for_client).used; i++)
- VG_(message)(Vg_UserMsg, " %s", VG_(args_for_client).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++)
+ VG_(message)(Vg_UserMsg,
+ " %s",
+ * (HChar**) VG_(indexXA)( VG_(args_for_client), i ));
if (VG_(clo_log_file_qualifier)) {
HChar* val = VG_(getenv)(VG_(clo_log_file_qualifier));
VG_(message)(Vg_UserMsg, "");
if (VG_(name_of_launcher))
VG_(message)(Vg_UserMsg, " <exe>%t</exe>",
VG_(name_of_launcher));
- for (i = 0; i < VG_(args_for_valgrind).used; i++) {
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) {
VG_(message)(Vg_UserMsg,
" <arg>%t</arg>",
- VG_(args_for_valgrind).strs[i]);
+ * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i ));
}
VG_(message)(Vg_UserMsg, " </vargv>");
if (VG_(args_the_exename))
VG_(message)(Vg_UserMsg, " <exe>%t</exe>",
VG_(args_the_exename));
- for (i = 0; i < VG_(args_for_client).used; i++) {
- VG_(message)(Vg_UserMsg, " <arg>%t</arg>",
- VG_(args_for_client).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+ VG_(message)(Vg_UserMsg,
+ " <arg>%t</arg>",
+ * (HChar**) VG_(indexXA)( VG_(args_for_client), i ));
}
VG_(message)(Vg_UserMsg, " </argv>");
VG_(message)(Vg_DebugMsg, "Command line");
if (VG_(args_the_exename))
VG_(message)(Vg_DebugMsg, " %s", VG_(args_the_exename));
- for (i = 0; i < VG_(args_for_client).used; i++)
- VG_(message)(Vg_DebugMsg, " %s", VG_(args_for_client).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++)
+ VG_(message)(Vg_DebugMsg,
+ " %s",
+ * (HChar**) VG_(indexXA)( VG_(args_for_client), i ));
VG_(message)(Vg_DebugMsg, "Startup, with flags:");
- for (i = 0; i < VG_(args_for_valgrind).used; i++) {
- VG_(message)(Vg_DebugMsg, " %s", VG_(args_for_valgrind).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) {
+ VG_(message)(Vg_DebugMsg,
+ " %s",
+ * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i ));
}
VG_(message)(Vg_DebugMsg, "Contents of /proc/version:");
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Split up command line\n");
VG_(split_up_argv)( argc, argv );
+ vg_assert( VG_(args_for_valgrind) );
+ vg_assert( VG_(args_for_client) );
if (0) {
- for (i = 0; i < VG_(args_for_valgrind).used; i++)
- VG_(printf)("varg %s\n", VG_(args_for_valgrind).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++)
+ VG_(printf)(
+ "varg %s\n",
+ * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i )
+ );
VG_(printf)(" exe %s\n", VG_(args_the_exename));
- for (i = 0; i < VG_(args_for_client).used; i++)
- VG_(printf)("carg %s\n", VG_(args_for_client).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++)
+ VG_(printf)(
+ "carg %s\n",
+ * (HChar**) VG_(indexXA)( VG_(args_for_client), i )
+ );
}
//--------------------------------------------------------------
VG_(strlen)( VG_(args_the_exename) ));
VG_(write)(fd, nul, 1);
- for (i = 0; i < VG_(args_for_client).used; i++) {
- VG_(write)(fd, VG_(args_for_client).strs[i],
- VG_(strlen)( VG_(args_for_client).strs[i] ));
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+ HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
+ VG_(write)(fd, arg, VG_(strlen)( arg ));
VG_(write)(fd, nul, 1);
}
#include "pub_core_tooliface.h" // VG_(needs).malloc_replacement
#include "pub_core_machine.h" // VG_(fnptr_to_fnentry)
#include "pub_core_aspacemgr.h" // VG_(am_find_nsegment)
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h" // VG_(client___libc_freeres_wrapper)
#include "pub_core_demangle.h" // VG_(maybe_Z_demangle)
#include "pub_core_vkiscnums.h"
#include "pub_core_debuglog.h"
#include "pub_core_threadstate.h"
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_debugger.h" // For VG_(start_debugger)
#include "pub_core_machine.h"
#include "pub_core_options.h"
#include "pub_core_stacktrace.h"
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h" // VG_(client__dl_sysinfo_int80)
#include "pub_core_trampoline.h"
#include "pub_core_debuginfo.h" // VG_(di_notify_*)
#include "pub_core_aspacemgr.h"
#include "pub_core_transtab.h" // VG_(discard_translations)
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h" // VG_(brk_base), VG_(brk_limit)
#include "pub_core_debuglog.h"
#include "pub_core_errormgr.h"
if (!VG_(clo_trace_children)) {
argv = (Char**)ARG2;
} else {
+ vg_assert( VG_(args_for_valgrind) );
vg_assert( VG_(args_for_valgrind_noexecpass) >= 0 );
vg_assert( VG_(args_for_valgrind_noexecpass)
- <= VG_(args_for_valgrind).used );
+ <= VG_(sizeXA)( VG_(args_for_valgrind) ) );
/* how many args in total will there be? */
// launcher basename
tot_args = 1;
// V's args
- tot_args += VG_(args_for_valgrind).used;
+ tot_args += VG_(sizeXA)( VG_(args_for_valgrind) );
tot_args -= VG_(args_for_valgrind_noexecpass);
// name of client exe
tot_args++;
// copy
j = 0;
argv[j++] = launcher_basename;
- for (i = 0; i < VG_(args_for_valgrind).used; i++) {
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) {
if (i < VG_(args_for_valgrind_noexecpass))
continue;
- argv[j++] = VG_(args_for_valgrind).strs[i];
+ argv[j++] = * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i );
}
argv[j++] = (Char*)ARG1;
if (arg2copy && arg2copy[0])
#include "pub_core_aspacemgr.h"
#include "pub_core_debuginfo.h" // VG_(di_notify_*)
#include "pub_core_transtab.h" // VG_(discard_translations)
+#include "pub_core_xarray.h"
#include "pub_core_clientstate.h"
#include "pub_core_debuglog.h"
#include "pub_core_libcbase.h"
pub_tool_tooliface.h \
pub_tool_vki.h \
pub_tool_vkiscnums.h \
+ pub_tool_xarray.h \
valgrind.h
#ifndef __PUB_TOOL_CLIENTSTATE_H
#define __PUB_TOOL_CLIENTSTATE_H
+/* Note, this header requires pub_{core,tool}_xarray.h to be
+ included ahead of it. */
// Command line pieces, after they have been extracted from argv in
// m_main.main(). These are all NULL-terminated vectors.
-/* Expandable arrays of strings. */
-typedef
- struct {
- Int size;
- Int used;
- HChar** strs;
- }
- XArrayStrings;
-
/* Args for the client. */
-extern XArrayStrings VG_(args_for_client);
+extern XArray* /* of HChar* */ VG_(args_for_client);
/* Args for V. This is the concatenation of the following:
- contents of ~/.valgrindrc
categories for themselves. Therefore we also record the number of
these no-pass-at-execve arguments -- that is what
VG_(args_for_valgrind_noexecpass) is. */
-extern XArrayStrings VG_(args_for_valgrind);
+extern XArray* /* of HChar* */ VG_(args_for_valgrind);
/* Number of leading args in VG_(args_for_valgrind) not to pass on at
exec time. */
#include "pub_tool_replacemalloc.h"
#include "pub_tool_stacktrace.h"
#include "pub_tool_tooliface.h"
+#include "pub_tool_xarray.h"
#include "pub_tool_clientstate.h"
#include "valgrind.h" // For {MALLOC,FREE}LIKE_BLOCK
if (VG_(args_the_exename)) {
SPRINTF(buf, "%s", VG_(args_the_exename));
}
- for (i = 0; i < VG_(args_for_client).used; i++) {
- if (VG_(args_for_client).strs[i])
- SPRINTF(buf, " %s", VG_(args_for_client).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+ HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
+ if (arg)
+ SPRINTF(buf, " %s", arg);
}
SPRINTF(buf, /*" (%d ms/sample)\"\n"*/ "\"\n"
"DATE \"\"\n"
if (VG_(args_the_exename)) {
SPRINTF(buf, " %s", VG_(args_the_exename));
}
- for (i = 0; i < VG_(args_for_client).used; i++) {
- if (VG_(args_for_client).strs[i])
- SPRINTF(buf, " %s", VG_(args_for_client).strs[i]);
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+ HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
+ if (arg)
+ SPRINTF(buf, " %s", arg);
}
SPRINTF(buf, "\n%s\n", maybe_p);