]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Arch-abstraction:
authorNicholas Nethercote <n.nethercote@gmail.com>
Tue, 7 Sep 2004 22:22:39 +0000 (22:22 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Tue, 7 Sep 2004 22:22:39 +0000 (22:22 +0000)
- factored out the setting of machine registers used when attaching the
  debugger.

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

coregrind/core.h
coregrind/vg_main.c
coregrind/x86/state.c

index 438726516a5beff0c1af00e50e361f92bd3028bf..373fa3d3313bd1ea074963be57ae7f07914d6170 100644 (file)
@@ -1499,6 +1499,9 @@ extern void VGA_(init_high_baseBlock) ( Addr client_eip, Addr esp_at_startup );
 extern void VGA_(load_state) ( arch_thread_t*, ThreadId tid );
 extern void VGA_(save_state) ( arch_thread_t*, ThreadId tid );
 
+extern void VGA_(regs_for_ptrace_from_BB)  ( struct user_regs_struct* regs );
+extern void VGA_(regs_for_ptrace_from_tst) ( arch_thread_t* arch,
+                                             struct user_regs_struct* regs );
 
 /* ---------------------------------------------------------------------
    Finally - autoconf-generated settings
index c57c5e8a4cdcde6035cf704cc9571fe52171026b..d2101da405d6e7ef905213f219c0d77058f6ecb3 100644 (file)
@@ -245,43 +245,10 @@ void VG_(start_debugger) ( Int tid )
       Int status;
       Int res;
 
-      if (VG_(is_running_thread)( tid )) {
-         regs.cs  = VG_(baseBlock)[VGOFF_(m_cs)];
-         regs.ss  = VG_(baseBlock)[VGOFF_(m_ss)];
-         regs.ds  = VG_(baseBlock)[VGOFF_(m_ds)];
-         regs.es  = VG_(baseBlock)[VGOFF_(m_es)];
-         regs.fs  = VG_(baseBlock)[VGOFF_(m_fs)];
-         regs.gs  = VG_(baseBlock)[VGOFF_(m_gs)];
-         regs.eax = VG_(baseBlock)[VGOFF_(m_eax)];
-         regs.ebx = VG_(baseBlock)[VGOFF_(m_ebx)];
-         regs.ecx = VG_(baseBlock)[VGOFF_(m_ecx)];
-         regs.edx = VG_(baseBlock)[VGOFF_(m_edx)];
-         regs.esi = VG_(baseBlock)[VGOFF_(m_esi)];
-         regs.edi = VG_(baseBlock)[VGOFF_(m_edi)];
-         regs.ebp = VG_(baseBlock)[VGOFF_(m_ebp)];
-         regs.esp = VG_(baseBlock)[VGOFF_(m_esp)];
-         regs.eflags = VG_(baseBlock)[VGOFF_(m_eflags)];
-         regs.eip = VG_(baseBlock)[VGOFF_(m_eip)];
-      } else {
-         ThreadState* tst = & VG_(threads)[ tid ];
-         
-         regs.cs  = tst->arch.m_cs;
-         regs.ss  = tst->arch.m_ss;
-         regs.ds  = tst->arch.m_ds;
-         regs.es  = tst->arch.m_es;
-         regs.fs  = tst->arch.m_fs;
-         regs.gs  = tst->arch.m_gs;
-         regs.eax = tst->arch.m_eax;
-         regs.ebx = tst->arch.m_ebx;
-         regs.ecx = tst->arch.m_ecx;
-         regs.edx = tst->arch.m_edx;
-         regs.esi = tst->arch.m_esi;
-         regs.edi = tst->arch.m_edi;
-         regs.ebp = tst->arch.m_ebp;
-         regs.esp = tst->arch.m_esp;
-         regs.eflags = tst->arch.m_eflags;
-         regs.eip = tst->arch.m_eip;
-      }
+      if (VG_(is_running_thread)( tid ))
+         VGA_(regs_for_ptrace_from_BB)(&regs);
+      else
+         VGA_(regs_for_ptrace_from_tst)(&VG_(threads)[tid].arch, &regs);
 
       if ((res = VG_(waitpid)(pid, &status, 0)) == pid &&
           WIFSTOPPED(status) && WSTOPSIG(status) == SIGSTOP &&
index ab47351d1842128f320f8b2ab7278491ee551287..f9a31f3a19cd2f1cee5052855a94caad88759efd 100644 (file)
@@ -31,7 +31,7 @@
 #include "core.h"
 
 /*------------------------------------------------------------*/
-/*--- baseBlock setup                                      ---*/
+/*--- baseBlock setup and operations                       ---*/
 /*------------------------------------------------------------*/
 
 /* The variables storing offsets. */
@@ -342,7 +342,6 @@ void VGA_(load_state) ( arch_thread_t* arch, ThreadId tid )
          VG_UNUSED_SHADOW_REG_VALUE == arch->sh_esp &&
          VG_UNUSED_SHADOW_REG_VALUE == arch->sh_eflags);
    }
-
 }
 
 void VGA_(save_state)( arch_thread_t *arch, ThreadId tid )
@@ -447,6 +446,51 @@ n",
       VG_(baseBlock)[VGOFF_(m_ssestate) + i] = junk;
 }
 
+/*------------------------------------------------------------*/
+/*--- Debugger-related operations                          ---*/
+/*------------------------------------------------------------*/
+
+void VGA_(regs_for_ptrace_from_BB)(struct user_regs_struct* regs)
+{
+   regs->cs     = VG_(baseBlock)[VGOFF_(m_cs)];
+   regs->ss     = VG_(baseBlock)[VGOFF_(m_ss)];
+   regs->ds     = VG_(baseBlock)[VGOFF_(m_ds)];
+   regs->es     = VG_(baseBlock)[VGOFF_(m_es)];
+   regs->fs     = VG_(baseBlock)[VGOFF_(m_fs)];
+   regs->gs     = VG_(baseBlock)[VGOFF_(m_gs)];
+   regs->eax    = VG_(baseBlock)[VGOFF_(m_eax)];
+   regs->ebx    = VG_(baseBlock)[VGOFF_(m_ebx)];
+   regs->ecx    = VG_(baseBlock)[VGOFF_(m_ecx)];
+   regs->edx    = VG_(baseBlock)[VGOFF_(m_edx)];
+   regs->esi    = VG_(baseBlock)[VGOFF_(m_esi)];
+   regs->edi    = VG_(baseBlock)[VGOFF_(m_edi)];
+   regs->ebp    = VG_(baseBlock)[VGOFF_(m_ebp)];
+   regs->esp    = VG_(baseBlock)[VGOFF_(m_esp)];
+   regs->eflags = VG_(baseBlock)[VGOFF_(m_eflags)];
+   regs->eip    = VG_(baseBlock)[VGOFF_(m_eip)];
+}
+
+void VGA_(regs_for_ptrace_from_tst)(arch_thread_t *tst,
+                                    struct user_regs_struct* regs)
+{
+   regs->cs     = tst->m_cs;
+   regs->ss     = tst->m_ss;
+   regs->ds     = tst->m_ds;
+   regs->es     = tst->m_es;
+   regs->fs     = tst->m_fs;
+   regs->gs     = tst->m_gs;
+   regs->eax    = tst->m_eax;
+   regs->ebx    = tst->m_ebx;
+   regs->ecx    = tst->m_ecx;
+   regs->edx    = tst->m_edx;
+   regs->esi    = tst->m_esi;
+   regs->edi    = tst->m_edi;
+   regs->ebp    = tst->m_ebp;
+   regs->esp    = tst->m_esp;
+   regs->eflags = tst->m_eflags;
+   regs->eip    = tst->m_eip;
+}
+
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
 /*--------------------------------------------------------------------*/