]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Redo the regs setting for db-attach, in a way that works for PPC, which doesn't
authorNicholas Nethercote <n.nethercote@gmail.com>
Thu, 9 Sep 2004 13:40:31 +0000 (13:40 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Thu, 9 Sep 2004 13:40:31 +0000 (13:40 +0000)
support ptrace(SETREGS,...).

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

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

index 17d428066c7b20af4b7a4c355658fe5150923fb4..12285de3aed1ee177514e9fa1c9f5be537e5d31d 100644 (file)
@@ -1501,9 +1501,8 @@ extern void VGA_(save_state) ( arch_thread_t*, ThreadId tid );
 
 extern Bool VGA_(setup_pointercheck) ( void );
 
-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 );
+extern Int  VGA_(ptrace_setregs_from_BB)  ( Int pid );
+extern Int  VGA_(ptrace_setregs_from_tst) ( Int pid, arch_thread_t* arch );
 
 /* ---------------------------------------------------------------------
    Finally - autoconf-generated settings
index dcafb15d7a70e748cf317432a516a9e27c22893c..183fa2ea1a15647dde2535e04e88c42b9d07ca2c 100644 (file)
@@ -225,6 +225,14 @@ static void print_all_stats ( void )
 /*=== Miscellaneous global functions                               ===*/
 /*====================================================================*/
 
+static Int ptrace_setregs(Int pid, ThreadId tid)
+{
+   if (VG_(is_running_thread)( tid ))
+      return VGA_(ptrace_setregs_from_BB)(pid);
+   else
+      return VGA_(ptrace_setregs_from_tst)(pid, &VG_(threads)[tid].arch);
+}
+
 /* Start debugger and get it to attach to this process.  Called if the
    user requests this service after an error has been shown, so she can
    poke around and look at parameters, memory, etc.  You can't
@@ -239,18 +247,12 @@ void VG_(start_debugger) ( Int tid )
       VG_(kkill)(VG_(getpid)(), VKI_SIGSTOP);
 
    } else if (pid > 0) {
-      struct user_regs_struct regs;
       Int status;
       Int res;
 
-      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 &&
-          ptrace(PTRACE_SETREGS, pid, NULL, &regs) == 0 &&
+          ptrace_setregs(pid, tid) == 0 &&
           kill(pid, SIGSTOP) == 0 &&
           ptrace(PTRACE_DETACH, pid, NULL, 0) == 0) {
          Char pidbuf[15];
index f1780b155783f1699f19d247ddc29e5c68cc8c60..72ca1a7c17764a4c9e6f8bb8100a25c78f99923c 100644 (file)
@@ -29,6 +29,7 @@
 */
 
 #include "core.h"
+#include <sys/ptrace.h>
 
 /*------------------------------------------------------------*/
 /*--- baseBlock setup and operations                       ---*/
@@ -478,45 +479,52 @@ Bool VGA_(setup_pointercheck)(void)
 /*--- Debugger-related operations                          ---*/
 /*------------------------------------------------------------*/
 
-void VGA_(regs_for_ptrace_from_BB)(struct user_regs_struct* regs)
+Int VGA_(ptrace_setregs_from_BB)(Int pid)
 {
-   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)];
+   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)];
+
+   return ptrace(PTRACE_SETREGS, pid, NULL, &regs);
 }
 
-void VGA_(regs_for_ptrace_from_tst)(arch_thread_t *tst,
-                                    struct user_regs_struct* regs)
+Int VGA_(ptrace_setregs_from_tst)(Int pid, arch_thread_t* arch)
 {
-   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;
+   struct user_regs_struct regs;
+
+   regs.cs     = arch->m_cs;
+   regs.ss     = arch->m_ss;
+   regs.ds     = arch->m_ds;
+   regs.es     = arch->m_es;
+   regs.fs     = arch->m_fs;
+   regs.gs     = arch->m_gs;
+   regs.eax    = arch->m_eax;
+   regs.ebx    = arch->m_ebx;
+   regs.ecx    = arch->m_ecx;
+   regs.edx    = arch->m_edx;
+   regs.esi    = arch->m_esi;
+   regs.edi    = arch->m_edi;
+   regs.ebp    = arch->m_ebp;
+   regs.esp    = arch->m_esp;
+   regs.eflags = arch->m_eflags;
+   regs.eip    = arch->m_eip;
+
+   return ptrace(PTRACE_SETREGS, pid, NULL, &regs);
 }
 
 /*--------------------------------------------------------------------*/