Using __PRETTY_FUNCTION__ and some macros, removed 148 lines of very repetitive
code (also removing the perennial problem of matching the error strings to the
functions they were in).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1649 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_default.c b/coregrind/vg_default.c
index b74c740..58cb0a0 100644
--- a/coregrind/vg_default.c
+++ b/coregrind/vg_default.c
@@ -66,207 +66,6 @@
    VG_(skin_panic)("Missing skin function");
 }
 
-/* ---------------------------------------------------------------------
-   Fundamental template functions
-   ------------------------------------------------------------------ */
-
-__attribute__ ((weak))
-void SK_(pre_clo_init)( void )
-{
-   fund_panic("SK_(pre_clo_init)");
-}
-
-__attribute__ ((weak))
-void SK_(post_clo_init)(void)
-{
-   fund_panic("SK_(post_clo_init)");
-}
-
-__attribute__ ((weak))
-UCodeBlock* SK_(instrument)(UCodeBlock* cb, Addr not_used)
-{
-   fund_panic("SK_(instrument)");
-}
-
-__attribute__ ((weak))
-void SK_(fini)(Int exitcode)
-{
-   fund_panic("SK_(fini)");
-}
-
-/* ---------------------------------------------------------------------
-   For error reporting and suppression handling
-   ------------------------------------------------------------------ */
-
-__attribute__ ((weak))
-Bool SK_(eq_SkinError)(VgRes res, Error* e1, Error* e2)
-{
-   non_fund_panic("SK_(eq_SkinError)");
-}
-
-__attribute__ ((weak))
-void SK_(pp_SkinError)(Error* err)
-{
-   non_fund_panic("SK_(pp_SkinError)");
-}
-
-__attribute__ ((weak))
-UInt SK_(update_extra)(Error* err)
-{
-   non_fund_panic("SK_(update_extra)");
-}
-
-__attribute__ ((weak))
-Bool SK_(recognised_suppression)(Char* name, Supp* su)
-{
-   non_fund_panic("SK_(recognised_suppression)");
-}
-
-__attribute__ ((weak))
-Bool SK_(read_extra_suppression_info)(Int fd, Char* buf, Int nBuf, Supp* su)
-{
-   non_fund_panic("SK_(read_extra_suppression_info)");
-}
-
-__attribute__ ((weak))
-Bool SK_(error_matches_suppression)(Error* err, Supp* su)
-{
-   non_fund_panic("SK_(error_matches_suppression)");
-}
-
-__attribute__ ((weak))
-Char* SK_(get_error_name)(Error* err)
-{
-   non_fund_panic("SK_(get_error_name)");
-}
-
-__attribute__ ((weak))
-void SK_(print_extra_suppression_info)(Error* err)
-{
-   non_fund_panic("SK_(print_extra_suppression_info)");
-}
-
-
-/* ---------------------------------------------------------------------
-   For throwing out basic block level info when code is invalidated
-   ------------------------------------------------------------------ */
-
-__attribute__ ((weak))
-void SK_(discard_basic_block_info)(Addr a, UInt size)
-{
-   non_fund_panic("SK_(discard_basic_block_info)");
-}
-
-
-/* ---------------------------------------------------------------------
-   Command line arg template function
-   ------------------------------------------------------------------ */
-
-__attribute__ ((weak))
-Bool SK_(process_cmd_line_option)(Char* argv)
-{
-   non_fund_panic("SK_(process_cmd_line_option)");
-}
-
-__attribute__ ((weak))
-void SK_(print_usage)(void)
-{
-   non_fund_panic("SK_(print_usage)");
-}
-
-__attribute__ ((weak))
-void SK_(print_debug_usage)(void)
-{
-   non_fund_panic("SK_(print_debug_usage)");
-}
-
-/* ---------------------------------------------------------------------
-   Client request template function
-   ------------------------------------------------------------------ */
-
-__attribute__ ((weak))
-Bool SK_(handle_client_request)(ThreadState* tst, UInt* arg_block, UInt *ret)
-{
-   non_fund_panic("SK_(handle_client_request)");
-}
-
-/* ---------------------------------------------------------------------
-   UCode extension
-   ------------------------------------------------------------------ */
-
-__attribute__ ((weak))
-void SK_(emit_XUInstr)(UInstr* u, RRegSet regs_live_before)
-{
-   non_fund_panic("SK_(emit_XUInstr)");
-}
-
-__attribute__ ((weak))
-Bool SK_(sane_XUInstr)(Bool beforeRA, Bool beforeLiveness, UInstr* u)
-{
-   non_fund_panic("SK_(sane_XUInstr)");
-}
-
-__attribute__ ((weak))
-Char* SK_(name_XUOpcode)(Opcode opc)
-{
-   non_fund_panic("SK_(name_XUOpcode)");
-}
-
-__attribute__ ((weak))
-void SK_(pp_XUInstr)(UInstr* u)
-{
-   non_fund_panic("SK_(pp_XUInstr)");
-}
-
-__attribute__ ((weak))
-Int SK_(get_Xreg_usage)(UInstr* u, Tag tag, Int* regs, Bool* isWrites)
-{
-   non_fund_panic("SK_(get_Xreg_usage)");
-}
-
-/* ---------------------------------------------------------------------
-   Syscall wrapping
-   ------------------------------------------------------------------ */
-
-__attribute__ ((weak))
-void* SK_(pre_syscall)(ThreadId tid, UInt syscallno, Bool is_blocking)
-{
-   non_fund_panic("SK_(pre_syscall)");
-}
-
-__attribute__ ((weak))
-void  SK_(post_syscall)(ThreadId tid, UInt syscallno,
-                         void* pre_result, Int res, Bool is_blocking)
-{
-   non_fund_panic("SK_(post_syscall)");
-}
-
-/* ---------------------------------------------------------------------
-   Sanity checks
-   ------------------------------------------------------------------ */
-
-__attribute__ ((weak))
-Bool SK_(cheap_sanity_check)(void)
-{
-   non_fund_panic("SK_(cheap_sanity_check)");
-}
-
-__attribute__ ((weak))
-Bool SK_(expensive_sanity_check)(void)
-{
-   non_fund_panic("SK_(expensive_sanity_check)");
-}
-
-/*------------------------------------------------------------*/
-/*--- Replacing malloc et al                               ---*/
-/*------------------------------------------------------------*/
-
-/* Default redzone for CLIENT arena of Valgrind's malloc() is 4 bytes */
-__attribute__ ((weak))
-UInt VG_(vg_malloc_redzone_szB) = 4;
-
-Bool VG_(sk_malloc_called_by_scheduler) = False;
-
 static __attribute__ ((noreturn))
 void malloc_panic ( Char* fn )
 {
@@ -278,6 +77,92 @@
    VG_(skin_panic)("Missing skin function");
 }
 
+#define FUND(proto)                       \
+__attribute__((weak))                     \
+proto                                     \
+{                                         \
+   fund_panic(__PRETTY_FUNCTION__);       \
+}
+
+#define NON_FUND(proto)                   \
+__attribute__((weak))                     \
+proto                                     \
+{                                         \
+   non_fund_panic(__PRETTY_FUNCTION__);   \
+}
+
+#define MALLOC(proto)                     \
+__attribute__((weak))                     \
+proto                                     \
+{                                         \
+   malloc_panic(__PRETTY_FUNCTION__);     \
+}
+
+/* ---------------------------------------------------------------------
+   Default functions
+   ------------------------------------------------------------------ */
+
+/* Fundamental template functions */
+FUND( void        SK_(pre_clo_init) (void) );
+FUND( void        SK_(post_clo_init)(void) );
+FUND( UCodeBlock* SK_(instrument)   (UCodeBlock* cb, Addr not_used) );
+FUND( void        SK_(fini)         (Int exitcode) );
+
+/* For error reporting and suppression handling */
+NON_FUND( Bool  SK_(eq_SkinError)(VgRes res, Error* e1, Error* e2) );
+NON_FUND( void  SK_(pp_SkinError)(Error* err) );
+NON_FUND( UInt  SK_(update_extra)(Error* err) );
+NON_FUND( Bool  SK_(recognised_suppression)(Char* name, Supp* su) );
+NON_FUND( Bool  SK_(read_extra_suppression_info)(Int fd, Char* buf, Int nBuf,
+                                                 Supp* su) );
+NON_FUND( Bool  SK_(error_matches_suppression)(Error* err, Supp* su) );
+NON_FUND( Char* SK_(get_error_name)(Error* err) );
+NON_FUND( void  SK_(print_extra_suppression_info)(Error* err) );
+
+/* For throwing out basic block level info when code is invalidated */
+NON_FUND( void SK_(discard_basic_block_info)(Addr a, UInt size) );
+
+/* For throwing out basic block level info when code is invalidated */
+NON_FUND( void SK_(written_shadow_regs_values)(UInt* gen_reg, UInt* eflags) );
+
+/* Command line arg handling functions */
+NON_FUND( Bool SK_(process_cmd_line_option)(Char* argv) );
+NON_FUND( void SK_(print_usage)(void) );
+NON_FUND( void SK_(print_debug_usage)(void) );
+
+/* Client request template function */
+NON_FUND( Bool SK_(handle_client_request)(ThreadState* tst, UInt* arg_block,
+                                          UInt *ret) );
+
+/* UCode extension */
+NON_FUND( void  SK_(emit_XUInstr)  (UInstr* u, RRegSet regs_live_before) );
+NON_FUND( Bool  SK_(sane_XUInstr)  (Bool beforeRA, Bool beforeLiveness, 
+                                    UInstr* u) );
+NON_FUND( Char* SK_(name_XUOpcode) (Opcode opc) );
+NON_FUND( void  SK_(pp_XUInstr)    (UInstr* u) );
+NON_FUND( Int   SK_(get_Xreg_usage)(UInstr* u, Tag tag, Int* regs,
+                                    Bool* isWrites) );               
+
+/* Syscall wrapping */
+NON_FUND( void* SK_(pre_syscall) (ThreadId tid, UInt syscallno,
+                                  Bool is_blocking) );
+NON_FUND( void  SK_(post_syscall)(ThreadId tid, UInt syscallno,
+                                 void* pre_result, Int res, Bool is_blocking) );
+
+/* Sanity checks */
+NON_FUND( Bool SK_(cheap_sanity_check)(void) );
+NON_FUND( Bool SK_(expensive_sanity_check)(void) );
+
+/*------------------------------------------------------------*/
+/*--- Replacing malloc et al                               ---*/
+/*------------------------------------------------------------*/
+
+/* Default redzone for CLIENT arena of Valgrind's malloc() is 4 bytes */
+__attribute__ ((weak))
+UInt VG_(vg_malloc_redzone_szB) = 4;
+
+Bool VG_(sk_malloc_called_by_scheduler) = False;
+
 /* If the skin hasn't replaced malloc(), this one can be called from the
    scheduler, for the USERREQ__MALLOC user request used by vg_libpthread.c. 
    (Nb: it cannot call glibc's malloc().)  The lock variable ensures that the
@@ -285,66 +170,33 @@
    malloc()-replacing skin cannot forget to implement SK_(malloc)() or
    SK_(free)().  */
 __attribute__ ((weak))
-void* SK_(malloc)               ( ThreadState* tst, Int size )
+void* SK_(malloc)( ThreadState* tst, Int size )
 {
    if (VG_(sk_malloc_called_by_scheduler))
       return VG_(cli_malloc)(4, size);
    else 
-      malloc_panic("SK_(malloc)");
+      malloc_panic(__PRETTY_FUNCTION__);
 }
 
 __attribute__ ((weak))
-void* SK_(__builtin_new)        ( ThreadState* tst, Int size )
-{
-   malloc_panic("SK_(__builtin_new)");
-}
-
-__attribute__ ((weak))
-void* SK_(__builtin_vec_new)    ( ThreadState* tst, Int size )
-{
-   malloc_panic("SK_(__builtin_vec_new)");
-}
-
-__attribute__ ((weak))
-void* SK_(memalign)             ( ThreadState* tst, Int align, Int size )
-{
-   malloc_panic("SK_(memalign)");
-}
-
-__attribute__ ((weak))
-void* SK_(calloc)               ( ThreadState* tst, Int nmemb, Int size )
-{
-   malloc_panic("SK_(calloc)");
-}
-
-__attribute__ ((weak))
-void  SK_(free)                 ( ThreadState* tst, void* p )
+void  SK_(free)( ThreadState* tst, void* p )
 {
    /* see comment for SK_(malloc)() above */
    if (VG_(sk_malloc_called_by_scheduler))
       VG_(cli_free)(p);
    else 
-      malloc_panic("SK_(free)");
+      malloc_panic(__PRETTY_FUNCTION__);
 }
 
-__attribute__ ((weak))
-void  SK_(__builtin_delete)     ( ThreadState* tst, void* p )
-{
-   malloc_panic("SK_(__builtin_delete)");
-}
+MALLOC( void* SK_(__builtin_new)    ( ThreadState* tst, Int size ) );
+MALLOC( void* SK_(__builtin_vec_new)( ThreadState* tst, Int size ) );
+MALLOC( void* SK_(memalign)         ( ThreadState* tst, Int align, Int size ) );
+MALLOC( void* SK_(calloc)           ( ThreadState* tst, Int nmemb, Int size ) );
 
-__attribute__ ((weak))
-void  SK_(__builtin_vec_delete) ( ThreadState* tst, void* p )
-{
-   malloc_panic("SK_(__builtin_vec_delete)");
-}
-
-__attribute__ ((weak))
-void* SK_(realloc)              ( ThreadState* tst, void* p, Int new_size )
-{
-   malloc_panic("SK_(realloc)");
-}
-
+MALLOC( void  SK_(__builtin_delete)     ( ThreadState* tst, void* p ) );
+MALLOC( void  SK_(__builtin_vec_delete) ( ThreadState* tst, void* p ) );
+MALLOC( void* SK_(realloc)              ( ThreadState* tst, void* p,
+                                          Int new_size ) );
 
 /*--------------------------------------------------------------------*/
 /*--- end                                            vg_defaults.c ---*/