/*=== 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
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];
*/
#include "core.h"
+#include <sys/ptrace.h>
/*------------------------------------------------------------*/
/*--- baseBlock setup and operations ---*/
/*--- 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);
}
/*--------------------------------------------------------------------*/