From: Nicholas Nethercote Date: Thu, 9 Sep 2004 13:40:31 +0000 (+0000) Subject: Redo the regs setting for db-attach, in a way that works for PPC, which doesn't X-Git-Tag: svn/VALGRIND_3_0_0~1605 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0a67ac22b43e8157a16da544ef0c7ee307de1e90;p=thirdparty%2Fvalgrind.git Redo the regs setting for db-attach, in a way that works for PPC, which doesn't support ptrace(SETREGS,...). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2678 --- diff --git a/coregrind/core.h b/coregrind/core.h index 17d428066c..12285de3ae 100644 --- a/coregrind/core.h +++ b/coregrind/core.h @@ -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 diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c index dcafb15d7a..183fa2ea1a 100644 --- a/coregrind/vg_main.c +++ b/coregrind/vg_main.c @@ -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)(®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) { Char pidbuf[15]; diff --git a/coregrind/x86/state.c b/coregrind/x86/state.c index f1780b1557..72ca1a7c17 100644 --- a/coregrind/x86/state.c +++ b/coregrind/x86/state.c @@ -29,6 +29,7 @@ */ #include "core.h" +#include /*------------------------------------------------------------*/ /*--- 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, ®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); } /*--------------------------------------------------------------------*/