|
From: <sv...@va...> - 2005-08-29 01:15:16
|
Author: njn
Date: 2005-08-29 02:15:13 +0100 (Mon, 29 Aug 2005)
New Revision: 4556
Log:
Mashed around and simplified main() a bit now that we don't need to
load the tool.
Modified:
branches/ASPACEM/coregrind/m_main.c
branches/ASPACEM/include/pub_tool_tooliface.h
Modified: branches/ASPACEM/coregrind/m_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_main.c 2005-08-28 19:34:39 UTC (rev 4555=
)
+++ branches/ASPACEM/coregrind/m_main.c 2005-08-29 01:15:13 UTC (rev 4556=
)
@@ -109,7 +109,7 @@
=20
// HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK HACK A
// temporary bootstrapping allocator, for use until such time as we
-// can get rid of the circularites in allocator dependencies at
+// can get rid of the circularities in allocator dependencies at
// startup. There is also a copy of this in m_ume.c.
#define N_HACK_BYTES 10000
static Int hack_bytes_used =3D 0;
@@ -353,38 +353,50 @@
If this needs to handle any more variables it should be hacked
into something table driven.
*/
-static HChar **fix_environment(HChar **origenv, const HChar *preload)
+static HChar **fix_environment(HChar **origenv, const HChar *toolname)
{
- static const HChar preload_core_so[] =3D "vg_preload_core.so";
- static const HChar ld_preload[] =3D "LD_PRELOAD=3D";
- static const HChar valgrind_clo[] =3D VALGRINDCLO "=3D";
- static const int ld_preload_len =3D sizeof(ld_preload)-1;
- static const int valgrind_clo_len =3D sizeof(valgrind_clo)-1;
- int ld_preload_done =3D 0;
- HChar *preload_core_path;
- int preload_core_path_len;
- int vgliblen =3D VG_(strlen)(VG_(libdir));
- HChar **cpp;
- HChar **ret;
- int envc;
- const int preloadlen =3D (preload =3D=3D NULL) ? 0 : VG_(strlen)(prel=
oad);
+ static const HChar preload_core_so[] =3D "vg_preload_core.so";
+ static const HChar ld_preload[] =3D "LD_PRELOAD=3D";
+ static const HChar valgrind_clo[] =3D VALGRINDCLO "=3D";
+ static const Int ld_preload_len =3D sizeof(ld_preload)-1;
+ static const Int valgrind_clo_len =3D sizeof(valgrind_clo)-1;
+ Bool ld_preload_done =3D False;
+ Int vgliblen =3D VG_(strlen)(VG_(libdir));
+ HChar** cpp;
+ HChar** ret;
+ HChar* preload_tool_path;;
+ Int envc;
=20
- /* Find the vg_preload_core.so; also make room for the tool preload
- library */
- preload_core_path_len =3D sizeof(preload_core_so) + vgliblen + preloa=
dlen + 16;
+ /* Alloc space for the vgpreload_core.so path and vgpreload_<tool>.so
+ paths. We might not need the space for vgpreload_<tool>.so, but i=
t
+ doesn't hurt to over-allocate briefly. The 16s are just cautious
+ slop. */
+ Int preload_core_path_len =3D vgliblen + sizeof(preload_core_so) + 16=
;
+ Int preload_tool_path_len =3D vgliblen + VG_(strlen)(toolname) + 16=
;
+ Int preload_string_len =3D preload_core_path_len + preload_tool_pa=
th_len;
/* FIXME */
- preload_core_path =3D /*VG_(malloc)*/ hack_malloc(preload_core_path_l=
en);
- vg_assert(preload_core_path);
-
- if (preload)
- VG_(snprintf)(preload_core_path, preload_core_path_len, "%s/%s:%s"=
,=20
- VG_(libdir), preload_core_so, preload);
- else
- VG_(snprintf)(preload_core_path, preload_core_path_len, "%s/%s",=20
- VG_(libdir), preload_core_so);
+ HChar* preload_string =3D /*VG_(malloc)*/ hack_malloc(preload_str=
ing_len);
+ vg_assert(preload_string);
=20
+ /* Determine if there's a vgpreload_<tool>.so file, and setup
+ preload_string. */
+ preload_tool_path =3D /*VG_(malloc)*/ hack_malloc(preload_tool_path_l=
en);
+ vg_assert(preload_tool_path);
+ VG_(snprintf)(preload_tool_path, preload_tool_path_len,
+ "%s/vgpreload_%s.so", VG_(libdir), toolname);
+ if (VG_(access)(preload_tool_path, True/*r*/, False/*w*/, False/*x*/)=
=3D=3D 0) {
+ VG_(snprintf)(preload_string, preload_string_len, "%s/%s:%s",=20
+ VG_(libdir), preload_core_so, preload_tool_path);
+ } else {
+ VG_(snprintf)(preload_string, preload_string_len, "%s/%s",=20
+ VG_(libdir), preload_core_so);
+ }
+ //FIXME VG_(free)(preload_tool);
+
+ VG_(debugLog)(1, "main", "preload_string =3D %s\n", preload_string);
+
/* Count the original size of the env */
- envc =3D 0; /* trailing NULL */
+ envc =3D 0; /* trailing NULL */
for (cpp =3D origenv; cpp && *cpp; cpp++)
envc++;
=20
@@ -402,39 +414,39 @@
/* Walk over the new environment, mashing as we go */
for (cpp =3D ret; cpp && *cpp; cpp++) {
if (VG_(memcmp)(*cpp, ld_preload, ld_preload_len) =3D=3D 0) {
- int len =3D VG_(strlen)(*cpp) + preload_core_path_len;
- HChar *cp =3D /*FIXME VG_(malloc)*/ hack_malloc(len);
+ Int len =3D VG_(strlen)(*cpp) + preload_string_len;
+ HChar *cp =3D /*FIXME VG_(malloc)*/ hack_malloc(len);
vg_assert(cp);
=20
- VG_(snprintf)(cp, len, "%s%s:%s",
- ld_preload, preload_core_path, (*cpp)+ld_preload_=
len);
+ VG_(snprintf)(cp, len, "%s%s:%s",
+ ld_preload, preload_string, (*cpp)+ld_preload_len=
);
=20
- *cpp =3D cp;
- =20
- ld_preload_done =3D 1;
+ *cpp =3D cp;
+
+ ld_preload_done =3D True;
} else if (VG_(memcmp)(*cpp, valgrind_clo, valgrind_clo_len) =3D=3D=
0) {
- *cpp =3D "";
+ *cpp =3D "";
}
}
=20
/* Add the missing bits */
if (!ld_preload_done) {
- int len =3D ld_preload_len + preload_core_path_len;
+ Int len =3D ld_preload_len + preload_string_len;
HChar *cp =3D /*FIXME VG_(malloc)*/ hack_malloc (len);
vg_assert(cp);
- =20
- VG_(snprintf)(cp, len, "%s%s", ld_preload, preload_core_path);
- =20
+
+ VG_(snprintf)(cp, len, "%s%s", ld_preload, preload_string);
+
ret[envc++] =3D cp;
}
=20
- //FIXME VG_(free)(preload_core_path);
+ //FIXME VG_(free)(preload_string);
ret[envc] =3D NULL;
=20
return ret;
}
=20
-extern char **environ; /* our environment */
+extern char **environ; /* our environment */
=20
/* Add a string onto the string table, and return its address */
static char *copy_str(char **tab, const char *str)
@@ -767,39 +779,6 @@
=20
=20
/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
-/*=3D=3D=3D Loading tools =
=3D=3D=3D*/
-/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
-
-/* Return a pointer to the tool_info struct. Also looks to see if
- there's a matching vgpreload_*.so file, and returns its name in
- *preloadpath. */
-
-/* HACK required because we can't use VG_(strdup) yet -- dynamic
- memory allocation is not running. */
-static HChar load_tool__preloadpath[VKI_PATH_MAX];
-
-static void load_tool( const char *toolname,
- ToolInfo** toolinfo_out, char **preloadpath_out )
-{
- extern ToolInfo VG_(tool_info);
- *toolinfo_out =3D &VG_(tool_info);
-
- Int len =3D VG_(strlen)(VG_(libdir)) + VG_(strlen)(toolname) + 16;
- HChar buf[len];
-
- VG_(snprintf)(buf, len, "%s/vgpreload_%s.so", VG_(libdir), toolname);
- if (VG_(access)(buf, True/*r*/, False/*w*/, False/*x*/) =3D=3D 0=20
- && len < VKI_PATH_MAX-1) {
- VG_(strncpy)( load_tool__preloadpath, buf, VKI_PATH_MAX-1 );
- load_tool__preloadpath[VKI_PATH_MAX-1] =3D 0;
- *preloadpath_out =3D load_tool__preloadpath;
- } else {
- *preloadpath_out =3D NULL;
- }
-}
-
-
-/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
/*=3D=3D=3D Command line errors =
=3D=3D=3D*/
/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
=20
@@ -1012,7 +991,7 @@
}
=20
static void pre_process_cmd_line_options
- ( Int* need_help, const char** tool, const char** exec )
+ ( Int* need_help, HChar** tool, HChar** exec )
{
UInt i;
=20
@@ -2052,11 +2031,9 @@
HChar** cl_argv;
HChar* tool =3D "memcheck"; // default to Memcheck
HChar* exec =3D NULL;
- HChar* preload =3D NULL; /* tool-specific LD_PRELOAD .so */
HChar** env;
Int need_help =3D 0; // 0 =3D no, 1 =3D --help, 2 =3D --help=
-debug
struct exeinfo info;
- ToolInfo* toolinfo =3D NULL;
Addr client_eip;
Addr sp_at_startup; /* client's SP at the point we
gained control. */
@@ -2133,7 +2110,7 @@
// Look for alternative libdir =20
// p: none
//--------------------------------------------------------------
- if (1) {
+ {
HChar *cp =3D VG_(getenv)(VALGRINDLIB);
if (cp !=3D NULL)
VG_(libdir) =3D cp;
@@ -2165,29 +2142,16 @@
}
=20
//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
- // Nb: once a tool is specified, the tool.so must be loaded even if=20
- // they specified --help or didn't specify a client program.
- //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
-
- //--------------------------------------------------------------
- // With client padded out, map in tool
- // p: set-libdir [for VG_(libdir)]
- // p: pre_process_cmd_line_options() [for 'tool']
- //--------------------------------------------------------------
- VG_(debugLog)(1, "main", "Loading tool '%s'\n", tool);
- load_tool(tool, &toolinfo, &preload);
-
- //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
// Can use VG_(malloc)() and VG_(arena_malloc)() only after load_tool=
()
// -- redzone size is now set. This is checked by vg_malloc2.c.
//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=20
//--------------------------------------------------------------
// Finalise address space layout
- // p: load_tool() [for 'toolinfo']
+ // p: load_tool() [probably?]
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Laying out remaining space\n");
- layout_remaining_space( (Addr) & argc, toolinfo->shadow_ratio );
+ layout_remaining_space( (Addr) & argc, VG_(tool_info).shadow_ratio );
=20
//--------------------------------------------------------------
// Load client executable, finding in $PATH if necessary
@@ -2207,11 +2171,11 @@
=20
//--------------------------------------------------------------
// Set up client's environment
- // p: set-libdir [for VG_(libdir)]
- // p: load_tool() [for 'preload']
+ // p: set-libdir [for VG_(libdir)]
+ // p: pre_process_cmd_line_options [for tool]
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Setup client env\n");
- env =3D fix_environment(envp, preload);
+ env =3D fix_environment(envp, tool);
=20
//--------------------------------------------------------------
// Setup client stack, eip, and VG_(client_arg[cv])
@@ -2259,7 +2223,6 @@
//--------------------------------------------------------------
// Init tool: pre_clo_init, process cmd line, post_clo_init
// p: setup_client_stack() [for 'VG_(client_arg[cv]']
- // p: load_tool() [for 'toolinfo']
// p: setup_file_descriptors() [for 'VG_(fd_xxx_limit)']
// p: parse_procselfmaps [so VG segments are setup so tool c=
an
// call VG_(malloc)]
@@ -2268,7 +2231,7 @@
Char* s;
Bool ok;
VG_(debugLog)(1, "main", "Initialise the tool\n");
- (*toolinfo->tl_pre_clo_init)();
+ (VG_(tool_info).tl_pre_clo_init)();
ok =3D VG_(sanity_check_needs)( VG_(shadow_base) !=3D VG_(shadow_e=
nd), &s );
if (!ok) {
VG_(tool_panic)(s);
Modified: branches/ASPACEM/include/pub_tool_tooliface.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/include/pub_tool_tooliface.h 2005-08-28 19:34:39 UTC=
(rev 4555)
+++ branches/ASPACEM/include/pub_tool_tooliface.h 2005-08-29 01:15:13 UTC=
(rev 4556)
@@ -64,6 +64,8 @@
float shadow_ratio;
} ToolInfo;
=20
+extern const ToolInfo VG_(tool_info);
+
/* Every tool must include this macro somewhere, exactly once. */
#define VG_DETERMINE_INTERFACE_VERSION(pre_clo_init, shadow) \
const ToolInfo VG_(tool_info) =3D { \
|