|
From: Nicholas N. <nj...@ca...> - 2004-09-09 13:40:51
|
CVS commit by nethercote:
Redo the regs setting for db-attach, in a way that works for PPC, which doesn't
support ptrace(SETREGS,...).
M +2 -3 core.h 1.18
M +9 -7 vg_main.c 1.210
M +43 -35 x86/state.c 1.5
--- valgrind/coregrind/core.h #1.17:1.18
@@ -1502,7 +1502,6 @@ extern void VGA_(save_state) ( arch_thre
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 );
/* ---------------------------------------------------------------------
--- valgrind/coregrind/vg_main.c #1.209:1.210
@@ -226,4 +226,12 @@ static void print_all_stats ( void )
/*====================================================================*/
+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
@@ -240,16 +248,10 @@ void VG_(start_debugger) ( Int tid )
} 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)(®s);
- else
- VGA_(regs_for_ptrace_from_tst)(&VG_(threads)[tid].arch, ®s);
-
if ((res = VG_(waitpid)(pid, &status, 0)) == pid &&
WIFSTOPPED(status) && WSTOPSIG(status) == SIGSTOP &&
- ptrace(PTRACE_SETREGS, pid, NULL, ®s) == 0 &&
+ ptrace_setregs(pid, tid) == 0 &&
kill(pid, SIGSTOP) == 0 &&
ptrace(PTRACE_DETACH, pid, NULL, 0) == 0) {
--- valgrind/coregrind/x86/state.c #1.4:1.5
@@ -30,4 +30,5 @@
#include "core.h"
+#include <sys/ptrace.h>
/*------------------------------------------------------------*/
@@ -479,43 +480,50 @@ Bool VGA_(setup_pointercheck)(void)
/*------------------------------------------------------------*/
-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, ®s);
}
-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, ®s);
}
|