|
From: <sv...@va...> - 2005-06-18 01:35:21
|
Author: njn
Date: 2005-06-18 02:35:16 +0100 (Sat, 18 Jun 2005)
New Revision: 3925
Log:
Moved two functions out of $ARCH/state.c into m_main, the only module
that uses them.
Modified:
trunk/coregrind/amd64/state.c
trunk/coregrind/m_main.c
trunk/coregrind/x86/state.c
Modified: trunk/coregrind/amd64/state.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
--- trunk/coregrind/amd64/state.c 2005-06-17 22:27:21 UTC (rev 3924)
+++ trunk/coregrind/amd64/state.c 2005-06-18 01:35:16 UTC (rev 3925)
@@ -54,68 +54,6 @@
}
=20
=20
-/*------------------------------------------------------------*/
-/*--- Initialising the first thread ---*/
-/*------------------------------------------------------------*/
-
-/* Given a pointer to the ThreadArchState for thread 1 (the root
- thread), initialise the VEX guest state, and copy in essential
- starting values.
-*/
-void VGA_(init_thread1state) ( Addr client_rip,=20
- Addr rsp_at_startup,
- /*MOD*/ ThreadArchState* arch )
-{
- vg_assert(0 =3D=3D sizeof(VexGuestAMD64State) % 8);
-
- /* Zero out the initial state, and set up the simulated FPU in a
- sane way. */
- LibVEX_GuestAMD64_initialise(&arch->vex);
-
- /* Zero out the shadow area. */
- VG_(memset)(&arch->vex_shadow, 0, sizeof(VexGuestAMD64State));
-
- /* Put essential stuff into the new state. */
-
- arch->vex.guest_RSP =3D rsp_at_startup;
- arch->vex.guest_RIP =3D client_rip;
-
- VG_TRACK( post_reg_write, Vg_CoreStartup, /*tid*/1, /*offset*/0,
- sizeof(VexGuestArchState));
-}
-
-
-/*------------------------------------------------------------*/
-/*--- Debugger-related operations ---*/
-/*------------------------------------------------------------*/
-
-Int VGA_(ptrace_setregs_from_tst)(Int pid, ThreadArchState* arch)
-{
- I_die_here;
-#if 0
- struct vki_user_regs_struct regs;
-
- regs.cs =3D arch->vex.guest_CS;
- regs.ss =3D arch->vex.guest_SS;
- regs.ds =3D arch->vex.guest_DS;
- regs.es =3D arch->vex.guest_ES;
- regs.fs =3D arch->vex.guest_FS;
- regs.gs =3D arch->vex.guest_GS;
- regs.eax =3D arch->vex.guest_EAX;
- regs.ebx =3D arch->vex.guest_EBX;
- regs.ecx =3D arch->vex.guest_ECX;
- regs.edx =3D arch->vex.guest_EDX;
- regs.esi =3D arch->vex.guest_ESI;
- regs.edi =3D arch->vex.guest_EDI;
- regs.ebp =3D arch->vex.guest_EBP;
- regs.esp =3D arch->vex.guest_ESP;
- regs.eflags =3D LibVEX_GuestX86_get_eflags(&arch->vex);
- regs.eip =3D arch->vex.guest_EIP;
-
- return ptrace(PTRACE_SETREGS, pid, NULL, ®s);
-#endif
-}
-
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
Modified: trunk/coregrind/m_main.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
--- trunk/coregrind/m_main.c 2005-06-17 22:27:21 UTC (rev 3924)
+++ trunk/coregrind/m_main.c 2005-06-18 01:35:16 UTC (rev 3925)
@@ -173,9 +173,33 @@
/*=3D=3D=3D Miscellaneous global functions =
=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=3D=3D=3D=3D*/
=20
-static Int ptrace_setregs(Int pid, ThreadId tid)
+static Int ptrace_setregs(Int pid, VexGuestArchState* vex)
{
- return VGA_(ptrace_setregs_from_tst)(pid, &VG_(threads)[tid].arch);
+ struct vki_user_regs_struct regs;
+#if defined(VGA_x86)
+ regs.cs =3D vex->guest_CS;
+ regs.ss =3D vex->guest_SS;
+ regs.ds =3D vex->guest_DS;
+ regs.es =3D vex->guest_ES;
+ regs.fs =3D vex->guest_FS;
+ regs.gs =3D vex->guest_GS;
+ regs.eax =3D vex->guest_EAX;
+ regs.ebx =3D vex->guest_EBX;
+ regs.ecx =3D vex->guest_ECX;
+ regs.edx =3D vex->guest_EDX;
+ regs.esi =3D vex->guest_ESI;
+ regs.edi =3D vex->guest_EDI;
+ regs.ebp =3D vex->guest_EBP;
+ regs.esp =3D vex->guest_ESP;
+ regs.eflags =3D LibVEX_GuestX86_get_eflags(vex);
+ regs.eip =3D vex->guest_EIP;
+
+ return ptrace(PTRACE_SETREGS, pid, NULL, ®s);
+#elif defined(VGA_amd64)
+ I_die_here;
+#else
+# error Unknown arch
+#endif
}
=20
/* Start debugger and get it to attach to this process. Called if the
@@ -197,9 +221,10 @@
=20
if ((res =3D VG_(waitpid)(pid, &status, 0)) =3D=3D pid &&
WIFSTOPPED(status) && WSTOPSIG(status) =3D=3D SIGSTOP &&
- ptrace_setregs(pid, tid) =3D=3D 0 &&
+ ptrace_setregs(pid, &(VG_(threads)[tid].arch.vex)) =3D=3D 0 &&
kill(pid, SIGSTOP) =3D=3D 0 &&
- ptrace(PTRACE_DETACH, pid, NULL, 0) =3D=3D 0) {
+ ptrace(PTRACE_DETACH, pid, NULL, 0) =3D=3D 0)
+ {
Char pidbuf[15];
Char file[30];
Char buf[100];
@@ -2235,7 +2260,59 @@
}
}
=20
+/*=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=3D*/
+/*=3D=3D=3D Initialise the first thread. =
=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=3D=3D=3D=3D*/
=20
+/* Given a pointer to the ThreadArchState for thread 1 (the root
+ thread), initialise the VEX guest state, and copy in essential
+ starting values.
+*/
+static void init_thread1state ( Addr client_ip,=20
+ Addr sp_at_startup,
+ /*inout*/ ThreadArchState* arch )
+{
+#if defined(VGA_x86)
+ vg_assert(0 =3D=3D sizeof(VexGuestX86State) % 8);
+
+ /* Zero out the initial state, and set up the simulated FPU in a
+ sane way. */
+ LibVEX_GuestX86_initialise(&arch->vex);
+
+ /* Zero out the shadow area. */
+ VG_(memset)(&arch->vex_shadow, 0, sizeof(VexGuestX86State));
+
+ /* Put essential stuff into the new state. */
+ arch->vex.guest_ESP =3D sp_at_startup;
+ arch->vex.guest_EIP =3D client_ip;
+
+ /* initialise %cs, %ds and %ss to point at the operating systems
+ default code, data and stack segments */
+ asm volatile("movw %%cs, %0" : : "m" (arch->vex.guest_CS));
+ asm volatile("movw %%ds, %0" : : "m" (arch->vex.guest_DS));
+ asm volatile("movw %%ss, %0" : : "m" (arch->vex.guest_SS));
+#elif defined(VGA_amd64)
+ vg_assert(0 =3D=3D sizeof(VexGuestAMD64State) % 8);
+
+ /* Zero out the initial state, and set up the simulated FPU in a
+ sane way. */
+ LibVEX_GuestAMD64_initialise(&arch->vex);
+
+ /* Zero out the shadow area. */
+ VG_(memset)(&arch->vex_shadow, 0, sizeof(VexGuestAMD64State));
+
+ /* Put essential stuff into the new state. */
+ arch->vex.guest_RSP =3D sp_at_startup;
+ arch->vex.guest_RIP =3D client_ip;
+#else
+# error Unknown arch
+#endif
+ // Tell the tool that we just wrote to the registers.
+ VG_TRACK( post_reg_write, Vg_CoreStartup, /*tid*/1, /*offset*/0,
+ sizeof(VexGuestArchState));
+}
+
+
/*=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=3D*/
/*=3D=3D=3D Sanity check machinery (permanently engaged) =
=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=3D=3D=3D=3D*/
@@ -2685,12 +2762,8 @@
// setup_scheduler() [for the rest of state 1 stuff]
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Initialise thread 1's state\n");
- VGA_(init_thread1state)(client_eip, sp_at_startup, &VG_(threads)[1].a=
rch );
+ init_thread1state(client_eip, sp_at_startup, &VG_(threads)[1].arch);
=20
- // Tell the tool that we just wrote to the registers.
- VG_TRACK( post_reg_write, Vg_CoreStartup, /*tid*/1, /*offset*/0,
- sizeof(VexGuestArchState));
-
//--------------------------------------------------------------
// Initialise the pthread model
// p: ?
Modified: trunk/coregrind/x86/state.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
--- trunk/coregrind/x86/state.c 2005-06-17 22:27:21 UTC (rev 3924)
+++ trunk/coregrind/x86/state.c 2005-06-18 01:35:16 UTC (rev 3925)
@@ -88,77 +88,6 @@
return False;
}
=20
-
-/*------------------------------------------------------------*/
-/*--- Initialising the first thread ---*/
-/*------------------------------------------------------------*/
-
-/* Given a pointer to the ThreadArchState for thread 1 (the root
- thread), initialise the VEX guest state, and copy in essential
- starting values.
-*/
-void VGA_(init_thread1state) ( Addr client_eip,=20
- Addr esp_at_startup,
- /*MOD*/ ThreadArchState* arch )
-{
- vg_assert(0 =3D=3D sizeof(VexGuestX86State) % 8);
-
- /* Zero out the initial state, and set up the simulated FPU in a
- sane way. */
- LibVEX_GuestX86_initialise(&arch->vex);
-
- /* Zero out the shadow area. */
- VG_(memset)(&arch->vex_shadow, 0, sizeof(VexGuestX86State));
-
- /* Put essential stuff into the new state. */
-
- arch->vex.guest_ESP =3D esp_at_startup;
- arch->vex.guest_EIP =3D client_eip;
-
- /* initialise %cs, %ds and %ss to point at the operating systems
- default code, data and stack segments */
- asm volatile("movw %%cs, %0"
- :
- : "m" (arch->vex.guest_CS));
- asm volatile("movw %%ds, %0"
- :
- : "m" (arch->vex.guest_DS));
- asm volatile("movw %%ss, %0"
- :
- : "m" (arch->vex.guest_SS));
-
- VG_TRACK( post_reg_write, Vg_CoreStartup, /*tid*/1, /*offset*/0,
- sizeof(VexGuestArchState));
-}
-
-/*------------------------------------------------------------*/
-/*--- Debugger-related operations ---*/
-/*------------------------------------------------------------*/
-
-Int VGA_(ptrace_setregs_from_tst)(Int pid, ThreadArchState* arch)
-{
- struct vki_user_regs_struct regs;
-
- regs.cs =3D arch->vex.guest_CS;
- regs.ss =3D arch->vex.guest_SS;
- regs.ds =3D arch->vex.guest_DS;
- regs.es =3D arch->vex.guest_ES;
- regs.fs =3D arch->vex.guest_FS;
- regs.gs =3D arch->vex.guest_GS;
- regs.eax =3D arch->vex.guest_EAX;
- regs.ebx =3D arch->vex.guest_EBX;
- regs.ecx =3D arch->vex.guest_ECX;
- regs.edx =3D arch->vex.guest_EDX;
- regs.esi =3D arch->vex.guest_ESI;
- regs.edi =3D arch->vex.guest_EDI;
- regs.ebp =3D arch->vex.guest_EBP;
- regs.esp =3D arch->vex.guest_ESP;
- regs.eflags =3D LibVEX_GuestX86_get_eflags(&arch->vex);
- regs.eip =3D arch->vex.guest_EIP;
-
- return ptrace(PTRACE_SETREGS, pid, NULL, ®s);
-}
-
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
|