]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Simplified the interface to VG_(translate)(), and merged it with
authorNicholas Nethercote <n.nethercote@gmail.com>
Tue, 3 Aug 2004 17:16:51 +0000 (17:16 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Tue, 3 Aug 2004 17:16:51 +0000 (17:16 +0000)
create_translation_for().  Cut about 40 lines of code as a side-effect.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2558

coregrind/vg_errcontext.c
coregrind/vg_from_ucode.c
coregrind/vg_include.h
coregrind/vg_scheduler.c
coregrind/vg_translate.c

index 4f7fc92546f13c1700213170269240d7e1a2756c..53e94a4f19402e671cb6416f6bf420be8efbbb49 100644 (file)
@@ -665,8 +665,8 @@ void VG_(show_all_errors) ( void )
       pp_Error( p_min, False );
 
       if ((i+1 == VG_(clo_dump_error))) {
-       VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to below NULLs */,
-                         p_min->where->eips[0], NULL, NULL, NULL, NULL );
+       VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to debugging*/,
+                         p_min->where->eips[0], /*debugging*/True);
       }
 
       p_min->count = 1 << 30;
index 988448aca148f2e6b635ca807ee610b8baacd73d..8dfb4f9bbfcbfb748a7bd6332c53d7904a5e5fbd 100644 (file)
@@ -4510,11 +4510,10 @@ UChar* VG_(emit_code) ( UCodeBlock* cb,
    vg_assert(!sselive);                  /* SSE state must be saved by end of BB */
    vg_assert(eflags_state != UPD_Real);        /* flags can't just be in CPU */
 
-   if (j != NULL) {
-      vg_assert(jumpidx <= VG_MAX_JUMPS);
-      for(i = 0; i < jumpidx; i++)
-        j[i] = jumps[i];
-   }
+   vg_assert(NULL != j);
+   vg_assert(jumpidx <= VG_MAX_JUMPS);
+   for(i = 0; i < jumpidx; i++)
+      j[i] = jumps[i];
 
    /* Returns a pointer to the emitted code.  This will have to be
       copied by the caller into the translation cache, and then freed */
index 501a21be64754d633ee0b07d1deead254edeb150..ff6735bf9ea45761079387c6f42571ff821f64d2 100644 (file)
@@ -1151,12 +1151,7 @@ struct _UCodeBlock {
 
 extern UCodeBlock* VG_(alloc_UCodeBlock) ( void );
 
-extern void VG_(translate)  ( ThreadId tid,
-                              Addr  orig_addr,
-                              UInt* orig_size,
-                              Addr* trans_addr,
-                              UInt* trans_size,
-                              UShort jumps[VG_MAX_JUMPS]);
+extern void VG_(translate)  ( ThreadId tid, Addr orig_addr, Bool debugging );
 
 extern Bool VG_(saneUInstr)          ( Bool beforeRA, Bool beforeLiveness,
                                        UInstr* u );
index 77f42d8047081cd1d92a5d8ed4161aa425ca28bc..3449ebf6e861ff12ed72e761f40cc16820a69c56 100644 (file)
@@ -228,37 +228,6 @@ Char* name_of_sched_event ( UInt event )
 }
 
 
-/* Create a translation of the client basic block beginning at
-   orig_addr, and add it to the translation cache & translation table.
-   This probably doesn't really belong here, but, hey ... 
-*/
-static
-void create_translation_for ( ThreadId tid, Addr orig_addr )
-{
-   Addr   trans_addr;
-   Int    orig_size, trans_size;
-   UShort jumps[VG_MAX_JUMPS];
-   Int    i;
-
-   for(i = 0; i < VG_MAX_JUMPS; i++)
-      jumps[i] = (UShort)-1;
-
-   /* Make a translation, into temporary storage. */
-   VG_(translate)( tid, orig_addr,                                /* in */
-                   &orig_size, &trans_addr, &trans_size, jumps ); /* out */
-
-   /* Copy data at trans_addr into the translation cache. */
-   /* Since the .orig_size and .trans_size fields are UShort, be paranoid. */
-   vg_assert(orig_size  > 0 && orig_size  < 65536);
-   vg_assert(trans_size > 0 && trans_size < 65536);
-
-   VG_(add_to_trans_tab)( orig_addr, orig_size, trans_addr, trans_size, jumps );
-
-   /* Free the intermediary -- was allocated by VG_(emit_code). */
-   VG_(arena_free)( VG_AR_JITTER, (void*)trans_addr );
-}
-
-
 /* Allocate a completely empty ThreadState record. */
 static
 ThreadId vg_alloc_ThreadState ( void )
@@ -1018,7 +987,7 @@ VgSchedReturnCode VG_(scheduler) ( Int* exitcode )
          if (VG_(bbs_done) > 31700000 + 0) {
             dispatch_ctr_SAVED = VG_(dispatch_ctr) = 2;
             VG_(translate)(&VG_(threads)[tid], VG_(threads)[tid].m_eip,
-                           NULL,NULL,NULL);
+                           /*debugging*/True);
          }
          vg_assert(VG_(threads)[tid].m_eip != 0);
 #        endif
@@ -1040,11 +1009,10 @@ VgSchedReturnCode VG_(scheduler) ( Int* exitcode )
 
             /* Trivial event.  Miss in the fast-cache.  Do a full
                lookup for it. */
-            trans_addr 
-               = VG_(search_transtab) ( VG_(threads)[tid].m_eip );
+            trans_addr = VG_(search_transtab) ( VG_(threads)[tid].m_eip );
             if (trans_addr == (Addr)0) {
                /* Not found; we need to request a translation. */
-               create_translation_for( tid, VG_(threads)[tid].m_eip ); 
+               VG_(translate)( tid, VG_(threads)[tid].m_eip, /*debug*/False ); 
                trans_addr = VG_(search_transtab) ( VG_(threads)[tid].m_eip ); 
                if (trans_addr == (Addr)0)
                   VG_(core_panic)("VG_TRC_INNER_FASTMISS: missing tt_fast entry");
index 716b426466cbeb288836a787400a92dd11b3fe70..ededb6ef834f5fac6d6ac9535f7bc3863d7daa5c 100644 (file)
@@ -2396,45 +2396,40 @@ static void vg_realreg_liveness_analysis ( UCodeBlock* cb )
 /*--- Main entry point for the JITter.                     ---*/
 /*------------------------------------------------------------*/
 
-/* Translate the basic block beginning at orig_addr, placing the
-   translation in a vg_malloc'd block, the address and size of which
-   are returned in trans_addr and trans_size.  Length of the original
-   block is also returned in orig_size.  If the latter three are NULL,
-   this call is being done for debugging purposes, in which case (a)
-   throw away the translation once it is made, and (b) produce a load
-   of debugging output. 
-
-   'tst' is the identity of the thread needing this block.
+/* Translate the basic block beginning at orig_addr, and add it to
+   the translation cache & translation table.  Unless 'debugging' is true,
+   in which case the call is being done for debugging purposes, so
+   (a) throw away the translation once it is made, and (b) produce a
+   load of debugging output. 
+
+   'tid' is the identity of the thread needing this block.
 */
-void VG_(translate) ( /*IN*/  ThreadId tid, 
-                     /*IN*/  Addr  orig_addr,  
-                      /*OUT*/ UInt* orig_size,
-                      /*OUT*/ Addr* trans_addr, 
-                      /*OUT*/ UInt* trans_size,
-                     /*OUT*/ UShort jumps[VG_MAX_JUMPS])
+void VG_(translate) ( ThreadId tid, Addr orig_addr,
+                      Bool debugging_translation )
 {
-   Int         n_disassembled_bytes, final_code_size;
-   Bool        debugging_translation;
-   UChar*      final_code;
+   Addr        trans_addr, redir, orig_addr0 = orig_addr;
+   UShort      jumps[VG_MAX_JUMPS];
+   Int         i, orig_size, trans_size;
    UCodeBlock* cb;
    Bool        notrace_until_done;
    UInt        notrace_until_limit = 0;
    Segment     *seg;
-   Addr                redir;
 
    VGP_PUSHCC(VgpTranslate);
-   debugging_translation
-      = orig_size == NULL || trans_addr == NULL || trans_size == NULL;
+
+   for (i = 0; i < VG_MAX_JUMPS; i++)
+      jumps[i] = (UShort)-1;
 
    /* Look in the code redirect table to see if we should
       translate an alternative address for orig_addr. */
    redir = VG_(code_redirect)(orig_addr);
 
-   if (redir != orig_addr && VG_(clo_verbosity) >= 2)
+   if (redir != orig_addr && VG_(clo_verbosity) >= 2) {
       VG_(message)(Vg_UserMsg, 
                   "TRANSLATE: %p redirected to %p",
                   orig_addr, 
                   redir );
+   }
    orig_addr = redir;
 
    /* If codegen tracing, don't start tracing until
@@ -2443,8 +2438,7 @@ void VG_(translate) ( /*IN*/  ThreadId tid,
       few blocks translated prior to a failure.  Set
       notrace_until_limit to be the number of translations to be made
       before --trace-codegen= style printing takes effect. */
-   notrace_until_done
-      = VG_(overall_in_count) >= notrace_until_limit;
+   notrace_until_done = VG_(overall_in_count) >= notrace_until_limit;
 
    seg = VG_(find_segment)(orig_addr);
 
@@ -2490,7 +2484,7 @@ void VG_(translate) ( /*IN*/  ThreadId tid,
    /* Disassemble this basic block into cb. */
    VG_(print_codegen) = DECIDE_IF_PRINTING_CODEGEN_FOR_PHASE(1);
    VGP_PUSHCC(VgpToUCode);
-   n_disassembled_bytes = VG_(disBB) ( cb, orig_addr );
+   orig_size = VG_(disBB) ( cb, orig_addr );
    VGP_POPCC(VgpToUCode);
 
    /* Try and improve the code a bit. */
@@ -2533,26 +2527,34 @@ void VG_(translate) ( /*IN*/  ThreadId tid,
 
    /* Emit final code */
    VG_(print_codegen) = DECIDE_IF_PRINTING_CODEGEN_FOR_PHASE(5);
-
    VGP_PUSHCC(VgpFromUcode);
-   final_code = VG_(emit_code)(cb, &final_code_size, jumps );
+   trans_addr = (Addr)VG_(emit_code)(cb, &trans_size, jumps );
    VGP_POPCC(VgpFromUcode);
    VG_(free_UCodeBlock)(cb);
 
 #undef DECIDE_IF_PRINTING_CODEGEN_FOR_PHASE
 
-   if (debugging_translation) {
-      /* Only done for debugging -- throw away final result. */
-      VG_(arena_free)(VG_AR_JITTER, final_code);
-   } else {
-      /* Doing it for real -- return values to caller. */
-      *orig_size = n_disassembled_bytes;
-      *trans_addr = (Addr)final_code;
-      *trans_size = final_code_size;
+   /* Copy data at trans_addr into the translation cache. */
+   /* Since the .orig_size and .trans_size fields are UShort, be paranoid. */
+   vg_assert(orig_size  > 0 && orig_size  < 65536);
+   vg_assert(trans_size > 0 && trans_size < 65536);
+
+   // If debugging, don't do anything with the translated block;  we
+   // only did this for the debugging output produced along the way.
+   if (!debugging_translation) {
+      // Note that we use orig_addr0, not orig_addr, which might have been
+      // changed by the redirection
+      VG_(add_to_trans_tab)( orig_addr0, orig_size, trans_addr, trans_size,
+                             jumps );
    }
+
+   /* Free the intermediary -- was allocated by VG_(emit_code). */
+   VG_(arena_free)( VG_AR_JITTER, (void*)trans_addr );
+
    VGP_POPCC(VgpTranslate);
 }
 
+
 /*--------------------------------------------------------------------*/
 /*--- end                                           vg_translate.c ---*/
 /*--------------------------------------------------------------------*/