Tweaked m_tooliface to reduce its dependencies on other things:
- VG_(sanity_check_needs)() now returns a message to m_main if it fails,
for m_main to print and abort, rather than printing an error message and
aborting itself. This removes the dependency on m_libcprint and
m_libcassert.
- Passing in an extra param to VG_(sanity_check_needs)() that says if
shadow memory has been allocated, rather than using
VG_(get_shadow_size)(). This removes the dependency on m_aspacemgr.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3978 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c
index a780c1d..2cdd646 100644
--- a/coregrind/m_aspacemgr/aspacemgr.c
+++ b/coregrind/m_aspacemgr/aspacemgr.c
@@ -1415,11 +1415,6 @@
return a >= VG_(shadow_base) && a < VG_(shadow_end);
}
-Addr VG_(get_shadow_size)(void)
-{
- return VG_(shadow_end)-VG_(shadow_base);
-}
-
/*--------------------------------------------------------------------*/
/*--- Handling shadow memory ---*/
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index aa1c912..a862c4d 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -2530,9 +2530,16 @@
// p: parse_procselfmaps [so VG segments are setup so tool can
// call VG_(malloc)]
//--------------------------------------------------------------
- VG_(debugLog)(1, "main", "Initialise the tool\n");
- (*toolinfo->tl_pre_clo_init)();
- VG_(sanity_check_needs)();
+ {
+ Char* s;
+ Bool ok;
+ VG_(debugLog)(1, "main", "Initialise the tool\n");
+ (*toolinfo->tl_pre_clo_init)();
+ ok = VG_(sanity_check_needs)( VG_(shadow_base) != VG_(shadow_end), &s );
+ if (!ok) {
+ VG_(tool_panic)(s);
+ }
+ }
// If --tool and --help/--help-debug was given, now give the core+tool
// help message
diff --git a/coregrind/m_tooliface.c b/coregrind/m_tooliface.c
index c384bf5..db8962e 100644
--- a/coregrind/m_tooliface.c
+++ b/coregrind/m_tooliface.c
@@ -30,10 +30,6 @@
*/
#include "pub_core_basics.h"
-#include "pub_core_debuginfo.h" // Needed for pub_core_aspacemgr :(
-#include "pub_core_aspacemgr.h" // For VG_(get_shadow_size)()
-#include "pub_core_libcassert.h"
-#include "pub_core_libcprint.h"
#include "pub_core_mallocfree.h" // For VG_(set_client_malloc_redzone_szB)()
#include "pub_core_tooliface.h"
@@ -102,12 +98,12 @@
};
/* static */
-void VG_(sanity_check_needs) ( void)
+Bool VG_(sanity_check_needs)(Bool non_zero_shadow_memory, Char** failmsg)
{
-#define CHECK_NOT(var, value) \
- if ((var)==(value)) { \
- VG_(printf)("\nTool error: '%s' not initialised\n", #var);\
- VG_(tool_panic)("Uninitialised details field\n"); \
+#define CHECK_NOT(var, value) \
+ if ((var)==(value)) { \
+ *failmsg = "Tool error: '" #var "' not initialised\n"; \
+ return False; \
}
/* Ones that must be set */
@@ -124,9 +120,10 @@
VG_(tdict).track_new_mem_stack_32 ) &&
! VG_(tdict).track_new_mem_stack)
{
- VG_(printf)("\nTool error: one of the specialised 'new_mem_stack_n'\n"
- "events tracked, but not the generic 'new_mem_stack' one.\n");
- VG_(tool_panic)("'new_mem_stack' should be defined\n");
+ *failmsg = "Tool error: one of the specialised 'new_mem_stack_n'\n"
+ " events tracked, but not the generic 'new_mem_stack' one.\n"
+ " 'new_mem_stack' should be defined\n";
+ return False;
}
if ( (VG_(tdict).track_die_mem_stack_4 ||
@@ -136,21 +133,20 @@
VG_(tdict).track_die_mem_stack_32 ) &&
! VG_(tdict).track_die_mem_stack)
{
- VG_(printf)("\nTool error: one of the specialised 'die_mem_stack_n'\n"
- "events tracked, but not the generic 'die_mem_stack' one.\n");
- VG_(tool_panic)("'die_mem_stack' should be defined\n");
+ *failmsg = "Tool error: one of the specialised 'die_mem_stack_n'\n"
+ " events tracked, but not the generic 'die_mem_stack' one.\n"
+ " 'die_mem_stack' should be defined\n";
+ return False;
}
- if (VG_(needs).shadow_memory != (VG_(get_shadow_size)() != 0)) {
- if (VG_(get_shadow_size)() != 0)
- VG_(printf)("\nTool error: tool allocated shadow memory, but apparently doesn't "
- "need it.\n");
- else
- VG_(printf)("\nTool error: tool didn't allocate shadow memory, but apparently "
- "needs it.\n");
- VG_(tool_panic)("VG_(needs).shadow_memory need should be set to match 'shadow_ratio'\n");
+ if (VG_(needs).shadow_memory != non_zero_shadow_memory) {
+ *failmsg = "Tool error: VG_(needs).shadow_memory doesn't match\n"
+ " the 'shadow_ratio' set in VG_DETERMINE_INTERFACE_VERSION\n";
+ return False;
}
+ return True;
+
#undef CHECK_NOT
}
@@ -337,6 +333,3 @@
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
-
-
-
diff --git a/coregrind/pub_core_tooliface.h b/coregrind/pub_core_tooliface.h
index 341fc29..dcd30ee 100644
--- a/coregrind/pub_core_tooliface.h
+++ b/coregrind/pub_core_tooliface.h
@@ -211,7 +211,7 @@
Miscellaneous functions
------------------------------------------------------------------ */
-void VG_(sanity_check_needs)(void);
+Bool VG_(sanity_check_needs) ( Bool non_zero_shadow_memory, Char** failmsg );
#endif // __PUB_CORE_TOOLIFACE_H
diff --git a/include/pub_tool_aspacemgr.h b/include/pub_tool_aspacemgr.h
index c888ffb..b2b4236 100644
--- a/include/pub_tool_aspacemgr.h
+++ b/include/pub_tool_aspacemgr.h
@@ -34,7 +34,6 @@
extern Bool VG_(is_client_addr) (Addr a);
extern Bool VG_(is_shadow_addr) (Addr a);
-extern Addr VG_(get_shadow_size)(void);
extern void *VG_(shadow_alloc)(UInt size);