]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Undo the awful Leak Error type-abuse.
authorNicholas Nethercote <njn@valgrind.org>
Tue, 17 May 2005 04:00:11 +0000 (04:00 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Tue, 17 May 2005 04:00:11 +0000 (04:00 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3754

include/pub_tool_errormgr.h
memcheck/mac_leakcheck.c
memcheck/mac_shared.c
memcheck/mac_shared.h

index 7cc389375ae81aea37701f0decae22fe3e2ff73b..5ed2f04e73d3c4d45c57e0feb47f29df5393b661 100644 (file)
@@ -78,9 +78,9 @@ extern void VG_(maybe_record_error) ( ThreadId tid, ErrorKind ekind,
 /* Similar to VG_(maybe_record_error)(), except this one doesn't record the
    error -- useful for errors that can only happen once.  The errors can be
    suppressed, though.  Return value is True if it was suppressed.
-   `print_error' dictates whether to print the error, which is a bit of a
+   'print_error' dictates whether to print the error, which is a bit of a
    hack that's useful sometimes if you just want to know if the error would
-   be suppressed without possibly printing it.  `count_error' dictates
+   be suppressed without possibly printing it.  'count_error' dictates
    whether to add the error in the error total count (another mild hack). */
 extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
                                 Addr a, Char* s, void* extra,
index c538bfd53010b7abcaa67e1dc51c57a159bc5c13..38e6d49ddfbbe2c3962935f413678d03db0359e4 100644 (file)
@@ -99,6 +99,12 @@ typedef
    }
    LossRecord;
 
+/* The 'extra' struct for leak errors. */
+typedef struct {
+   UInt        n_this_record;
+   UInt        n_total_records;
+   LossRecord* lossRecord;
+} LeakExtra;
 
 /* Find the i such that ptr points at or inside the block described by
    shadows[i].  Return -1 if none found.  This assumes that shadows[]
@@ -178,7 +184,7 @@ static SizeT            lc_scanned;
 static Bool      (*lc_is_within_valid_secondary) (Addr addr);
 static Bool      (*lc_is_valid_aligned_word)     (Addr addr);
 
-static const Char *pp_lossmode(Reachedness lossmode)
+static const Char *str_lossmode(Reachedness lossmode)
 {
    const Char *loss = "?";
 
@@ -194,10 +200,11 @@ static const Char *pp_lossmode(Reachedness lossmode)
 
 /* Used for printing leak errors, avoids exposing the LossRecord type (which
    comes in as void*, requiring a cast. */
-void MAC_(pp_LeakError)(void* vl, UInt n_this_record, UInt n_total_records)
+void MAC_(pp_LeakError)(void* vextra)
 {
-   LossRecord* l = (LossRecord*)vl;
-   const Char *loss = pp_lossmode(l->loss_mode);
+   LeakExtra* extra = (LeakExtra*)vextra;
+   LossRecord* l    = extra->lossRecord;
+   const Char *loss = str_lossmode(l->loss_mode);
 
    VG_(message)(Vg_UserMsg, "");
    if (l->indirect_bytes) {
@@ -205,12 +212,12 @@ void MAC_(pp_LeakError)(void* vl, UInt n_this_record, UInt n_total_records)
                   "%d (%d direct, %d indirect) bytes in %d blocks are %s in loss record %d of %d",
                   l->total_bytes + l->indirect_bytes, 
                   l->total_bytes, l->indirect_bytes, l->num_blocks,
-                  loss, n_this_record, n_total_records);
+                  loss, extra->n_this_record, extra->n_total_records);
    } else {
       VG_(message)(Vg_UserMsg, 
                   "%d bytes in %d blocks are %s in loss record %d of %d",
                   l->total_bytes, l->num_blocks,
-                  loss, n_this_record, n_total_records);
+                  loss, extra->n_this_record, extra->n_total_records);
    }
    VG_(pp_ExeContext)(l->allocated_at);
 }
@@ -409,6 +416,7 @@ static void full_report(ThreadId tid)
    LossRecord* errlist;
    LossRecord* p;
    Bool   is_suppressed;
+   LeakExtra leak_extra;
 
    /* Go through and group lost structures into cliques.  For each
       Unreached block, push it onto the mark stack, and find all the
@@ -419,7 +427,7 @@ static void full_report(ThreadId tid)
    for (i = 0; i < lc_n_shadows; i++) {
       if (VG_DEBUG_CLIQUE)
         VG_(printf)("cliques: %d at %p -> %s\n",
-                    i, lc_shadows[i]->data, pp_lossmode(lc_markstack[i].state));
+                    i, lc_shadows[i]->data, str_lossmode(lc_markstack[i].state));
       if (lc_markstack[i].state != Unreached)
         continue;
 
@@ -487,18 +495,23 @@ static void full_report(ThreadId tid)
       /* Ok to have tst==NULL;  it's only used if --gdb-attach=yes, and
          we disallow that when --leak-check=yes.  
          
-         Prints the error if not suppressed, unless it's reachable (Proper or IndirectLeak)
-         and --show-reachable=no */
+         Prints the error if not suppressed, unless it's reachable (Proper
+         or IndirectLeak) and --show-reachable=no */
 
       print_record = ( MAC_(clo_show_reachable) || 
-                      Unreached == p_min->loss_mode || Interior == p_min->loss_mode );
+                      Unreached == p_min->loss_mode || 
+                       Interior == p_min->loss_mode );
+
+      // Nb: because VG_(unique_error) does all the error processing
+      // immediately, and doesn't save the error, leakExtra can be
+      // stack-allocated.
+      leak_extra.n_this_record   = i+1;
+      leak_extra.n_total_records = n_lossrecords;
+      leak_extra.lossRecord      = p_min;
       is_suppressed = 
-         VG_(unique_error) ( tid, LeakErr, (UInt)i+1,
-                             /* HACK ALERT */
-                             ULong_to_Ptr((ULong)(UInt)n_lossrecords), 
-                             /* end HACK ALERT */
-                             (void*) p_min,
-                             p_min->allocated_at, print_record,
+         VG_(unique_error) ( tid, LeakErr, /*Addr*/0, /*s*/NULL,
+                             /*extra*/&leak_extra, 
+                             /*where*/p_min->allocated_at, print_record,
                              /*allow_GDB_attach*/False, /*count_error*/False );
 
       if (is_suppressed) {
index 9594474f1eabbeb36ec6db219851323ae9c77921..2fc4b319114f6a7ad2537f57a8621f384ab045f9 100644 (file)
@@ -337,11 +337,7 @@ void MAC_(pp_shared_Error) ( Error* err )
          break;
       }
       case LeakErr: {
-         /* Totally abusing the types of these spare fields... oh well. */
-         UInt n_this_record   = (UWord)VG_(get_error_address)(err);
-         UInt n_total_records = (UWord)VG_(get_error_string) (err);
-
-         MAC_(pp_LeakError)(err_extra, n_this_record, n_total_records);
+         MAC_(pp_LeakError)(err_extra);
          break;
       }
 
index 1554fc696974a470ceacc6695266dd6257e80e12..304803221411dc187876c9199a0f5e9cab8f1f73 100644 (file)
@@ -418,8 +418,7 @@ extern Bool MAC_(handle_common_client_requests) ( ThreadId tid,
                                                   UWord* arg_block, UWord* ret );
 
 /* For leak checking */
-extern void MAC_(pp_LeakError)(void* vl, UInt n_this_record, 
-                                         UInt n_total_records); 
+extern void MAC_(pp_LeakError)(void* extra);
                            
 extern void MAC_(print_malloc_stats) ( void );