|
From: <sv...@va...> - 2005-08-27 15:07:23
|
Author: tom
Date: 2005-08-27 16:07:21 +0100 (Sat, 27 Aug 2005)
New Revision: 4537
Log:
Implement VG_(ptrace) and VG_(fork) and get debugger attaching going agai=
n.
Modified:
branches/ASPACEM/coregrind/m_debugger.c
branches/ASPACEM/coregrind/m_libcproc.c
branches/ASPACEM/coregrind/pub_core_libcproc.h
branches/ASPACEM/include/vki-linux.h
Modified: branches/ASPACEM/coregrind/m_debugger.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_debugger.c 2005-08-27 14:21:41 UTC (rev =
4536)
+++ branches/ASPACEM/coregrind/m_debugger.c 2005-08-27 15:07:21 UTC (rev =
4537)
@@ -32,22 +32,16 @@
#include "pub_core_threadstate.h"
#include "pub_core_debugger.h"
#include "pub_core_libcbase.h"
-#include "pub_core_libcassert.h" // For I_die_here
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
#include "pub_core_libcsignal.h"
#include "pub_core_options.h"
=20
-// We can remove these easily by implementing our own VG_(ptrace)() and
-// VG_(fork)().
-//#include <sys/ptrace.h>
-//#include <sys/wait.h>
-//#include <unistd.h>
+#define WIFSTOPPED(status) (((status) & 0xff) =3D=3D 0x7f)
+#define WSTOPSIG(status) (((status) & 0xff00) >> 8)
=20
static Int ptrace_setregs(Int pid, VexGuestArchState* vex)
{
- I_die_here;
-#if 0
struct vki_user_regs_struct regs;
#if defined(VGA_x86)
regs.cs =3D vex->guest_CS;
@@ -67,7 +61,7 @@
regs.eflags =3D LibVEX_GuestX86_get_eflags(vex);
regs.eip =3D vex->guest_EIP;
=20
- return ptrace(PTRACE_SETREGS, pid, NULL, ®s);
+ return VG_(ptrace)(VKI_PTRACE_SETREGS, pid, NULL, ®s);
#elif defined(VGA_amd64)
regs.rax =3D vex->guest_RAX;
regs.rbx =3D vex->guest_RBX;
@@ -88,14 +82,13 @@
regs.eflags =3D LibVEX_GuestAMD64_get_rflags(vex);
regs.rip =3D vex->guest_RIP;
=20
- return ptrace(PTRACE_SETREGS, pid, NULL, ®s);
+ return VG_(ptrace)(VKI_PTRACE_SETREGS, pid, NULL, ®s);
#elif defined(VGA_ppc32)
I_die_here;
regs.gpr[0] =3D 0; // stop compiler complaints
#else
# error Unknown arch
#endif
-#endif /* 0 */
}
=20
/* Start debugger and get it to attach to this process. Called if the
@@ -105,12 +98,10 @@
continue, quit the debugger. */
void VG_(start_debugger) ( ThreadId tid )
{
- I_die_here;
-#if 0
Int pid;
=20
- if ((pid =3D fork()) =3D=3D 0) {
- ptrace(PTRACE_TRACEME, 0, NULL, NULL);
+ if ((pid =3D VG_(fork)()) =3D=3D 0) {
+ VG_(ptrace)(VKI_PTRACE_TRACEME, 0, NULL, NULL);
VG_(kill)(VG_(getpid)(), VKI_SIGSTOP);
=20
} else if (pid > 0) {
@@ -118,10 +109,10 @@
Int res;
=20
if ((res =3D VG_(waitpid)(pid, &status, 0)) =3D=3D pid &&
- WIFSTOPPED(status) && WSTOPSIG(status) =3D=3D SIGSTOP &&
+ WIFSTOPPED(status) && WSTOPSIG(status) =3D=3D VKI_SIGSTOP &&
ptrace_setregs(pid, &(VG_(threads)[tid].arch.vex)) =3D=3D 0 &&
- VG_(kill)(pid, SIGSTOP) =3D=3D 0 &&
- ptrace(PTRACE_DETACH, pid, NULL, 0) =3D=3D 0)
+ VG_(kill)(pid, VKI_SIGSTOP) =3D=3D 0 &&
+ VG_(ptrace)(VKI_PTRACE_DETACH, pid, NULL, 0) =3D=3D 0)
{
Char pidbuf[15];
Char file[30];
@@ -177,7 +168,6 @@
VG_(kill)(pid, VKI_SIGKILL);
VG_(waitpid)(pid, &status, 0);
}
-#endif
}
=20
=20
Modified: branches/ASPACEM/coregrind/m_libcproc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_libcproc.c 2005-08-27 14:21:41 UTC (rev =
4536)
+++ branches/ASPACEM/coregrind/m_libcproc.c 2005-08-27 15:07:21 UTC (rev =
4537)
@@ -434,6 +434,32 @@
}
=20
/* ---------------------------------------------------------------------
+ Process tracing
+ ------------------------------------------------------------------ */
+
+Int VG_(ptrace) ( Int request, Int pid, void *addr, void *data )
+{
+ SysRes res;
+ res =3D VG_(do_syscall4)(__NR_ptrace, request, pid, (UWord)addr, (UWo=
rd)data);
+ if (res.isError)
+ return -1;
+ return res.val;
+}
+
+/* ---------------------------------------------------------------------
+ Fork
+ ------------------------------------------------------------------ */
+
+Int VG_(fork) ( void )
+{
+ SysRes res;
+ res =3D VG_(do_syscall0)(__NR_fork);
+ if (res.isError)
+ return -1;
+ return res.val;
+}
+
+/* ---------------------------------------------------------------------
Timing stuff
------------------------------------------------------------------ */
=20
Modified: branches/ASPACEM/coregrind/pub_core_libcproc.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/pub_core_libcproc.h 2005-08-27 14:21:41 UT=
C (rev 4536)
+++ branches/ASPACEM/coregrind/pub_core_libcproc.h 2005-08-27 15:07:21 UT=
C (rev 4537)
@@ -76,6 +76,8 @@
extern Int VG_(poll)( struct vki_pollfd *, UInt nfds, Int timeout);
extern void VG_(nanosleep) ( struct vki_timespec * );
extern Int VG_(getgroups)( Int size, UInt* list );
+extern Int VG_(ptrace)( Int request, Int pid, void *addr, void *data );
+extern Int VG_(fork)( void );
=20
// atfork
typedef void (*vg_atfork_t)(ThreadId);
Modified: branches/ASPACEM/include/vki-linux.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/include/vki-linux.h 2005-08-27 14:21:41 UTC (rev 453=
6)
+++ branches/ASPACEM/include/vki-linux.h 2005-08-27 15:07:21 UTC (rev 453=
7)
@@ -1952,10 +1952,13 @@
// From linux-2.6.9/include/linux/ptrace.h
//----------------------------------------------------------------------
=20
+#define VKI_PTRACE_TRACEME 0
#define VKI_PTRACE_PEEKTEXT 1
#define VKI_PTRACE_PEEKDATA 2
#define VKI_PTRACE_PEEKUSR 3
=20
+#define VKI_PTRACE_DETACH 0x11
+
#endif // __VKI_LINUX_H
=20
/*--------------------------------------------------------------------*/
|