Commit 06c02804 authored by Russ Cox's avatar Russ Cox

libmach: use different names for different Ureg types

Everything was doing this already with #defines.
Do it right.

R=golang-codereviews, jsing, 0intro, iant
CC=golang-codereviews
https://golang.org/cl/49090043
parent fca453e0
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
struct Ureg { typedef struct UregAmd64 UregAmd64;
struct UregAmd64 {
u64int ax; u64int ax;
u64int bx; u64int bx;
u64int cx; u64int cx;
......
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
struct Ureg { typedef struct UregArm UregArm;
struct UregArm {
uint r0; uint r0;
uint r1; uint r1;
uint r2; uint r2;
......
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
struct Ureg typedef struct Ureg386 Ureg386;
struct Ureg386
{ {
uint32 di; /* general registers */ uint32 di; /* general registers */
uint32 si; /* ... */ uint32 si; /* ... */
......
...@@ -9,21 +9,16 @@ ...@@ -9,21 +9,16 @@
#include <libc.h> #include <libc.h>
#include <bio.h> #include <bio.h>
#include <ctype.h> #include <ctype.h>
#include <ureg_amd64.h>
#define Ureg Ureg_amd64 #include <ureg_x86.h>
#include <ureg_amd64.h>
#undef Ureg
#define Ureg Ureg_x86
#include <ureg_x86.h>
#undef Ureg
#include <mach.h> #include <mach.h>
char* file = "6.out"; char* file = "6.out";
static Fhdr fhdr; static Fhdr fhdr;
int have_syms; int have_syms;
int fd; int fd;
struct Ureg_amd64 ureg_amd64; struct UregAmd64 ureg_amd64;
struct Ureg_x86 ureg_x86; struct Ureg386 ureg_x86;
int total_sec = 0; int total_sec = 0;
int delta_msec = 100; int delta_msec = 100;
int nsample; int nsample;
...@@ -132,7 +127,7 @@ amd64_getregs(Map *map) ...@@ -132,7 +127,7 @@ amd64_getregs(Map *map)
int i; int i;
union { union {
uvlong regs[1]; uvlong regs[1];
struct Ureg_amd64 ureg; struct UregAmd64 ureg;
} u; } u;
for(i = 0; i < sizeof ureg_amd64; i+=8) { for(i = 0; i < sizeof ureg_amd64; i+=8) {
...@@ -149,7 +144,7 @@ amd64_getPC(Map *map) ...@@ -149,7 +144,7 @@ amd64_getPC(Map *map)
uvlong x; uvlong x;
int r; int r;
r = get8(map, offsetof(struct Ureg_amd64, ip), &x); r = get8(map, offsetof(struct UregAmd64, ip), &x);
ureg_amd64.ip = x; ureg_amd64.ip = x;
return r; return r;
} }
...@@ -160,7 +155,7 @@ amd64_getSP(Map *map) ...@@ -160,7 +155,7 @@ amd64_getSP(Map *map)
uvlong x; uvlong x;
int r; int r;
r = get8(map, offsetof(struct Ureg_amd64, sp), &x); r = get8(map, offsetof(struct UregAmd64, sp), &x);
ureg_amd64.sp = x; ureg_amd64.sp = x;
return r; return r;
} }
...@@ -229,13 +224,13 @@ x86_getregs(Map *map) ...@@ -229,13 +224,13 @@ x86_getregs(Map *map)
int int
x86_getPC(Map* map) x86_getPC(Map* map)
{ {
return get4(map, offsetof(struct Ureg_x86, pc), &ureg_x86.pc); return get4(map, offsetof(struct Ureg386, pc), &ureg_x86.pc);
} }
int int
x86_getSP(Map* map) x86_getSP(Map* map)
{ {
return get4(map, offsetof(struct Ureg_x86, sp), &ureg_x86.sp); return get4(map, offsetof(struct Ureg386, sp), &ureg_x86.sp);
} }
uvlong uvlong
......
...@@ -35,12 +35,12 @@ ...@@ -35,12 +35,12 @@
#include "ureg_arm.h" #include "ureg_arm.h"
#include <mach.h> #include <mach.h>
#define REGOFF(x) (uintptr) (&((struct Ureg *) 0)->x) #define REGOFF(x) (uintptr) (&((struct UregArm *) 0)->x)
#define SP REGOFF(r13) #define SP REGOFF(r13)
#define PC REGOFF(pc) #define PC REGOFF(pc)
#define REGSIZE sizeof(struct Ureg) #define REGSIZE sizeof(struct UregArm)
Reglist armreglist[] = Reglist armreglist[] =
{ {
......
...@@ -40,8 +40,6 @@ static int debug = 0; ...@@ -40,8 +40,6 @@ static int debug = 0;
#define ASR(v, s) ((long)(v) >> (s)) #define ASR(v, s) ((long)(v) >> (s))
#define ROR(v, s) (LSR((v), (s)) | (((v) & ((1 << (s))-1)) << (32 - (s)))) #define ROR(v, s) (LSR((v), (s)) | (((v) & ((1 << (s))-1)) << (32 - (s))))
typedef struct Instr Instr; typedef struct Instr Instr;
struct Instr struct Instr
{ {
......
...@@ -35,9 +35,9 @@ ...@@ -35,9 +35,9 @@
#include "ureg_amd64.h" #include "ureg_amd64.h"
#include <mach.h> #include <mach.h>
#define REGOFF(x) offsetof(struct Ureg, x) #define REGOFF(x) offsetof(struct UregAmd64, x)
#define REGSIZE sizeof(struct Ureg) #define REGSIZE sizeof(struct UregAmd64)
#define FP_CTLS(x) (REGSIZE+2*(x)) #define FP_CTLS(x) (REGSIZE+2*(x))
#define FP_CTL(x) (REGSIZE+4*(x)) #define FP_CTL(x) (REGSIZE+4*(x))
#define FP_REG(x) (FP_CTL(8)+16*(x)) #define FP_REG(x) (FP_CTL(8)+16*(x))
......
...@@ -35,13 +35,13 @@ ...@@ -35,13 +35,13 @@
#include <ureg_x86.h> #include <ureg_x86.h>
#include <mach.h> #include <mach.h>
#define REGOFF(x) (uintptr)(&((struct Ureg *) 0)->x) #define REGOFF(x) (uintptr)(&((struct Ureg386 *) 0)->x)
#define PC REGOFF(pc) #define PC REGOFF(pc)
#define SP REGOFF(sp) #define SP REGOFF(sp)
#define AX REGOFF(ax) #define AX REGOFF(ax)
#define REGSIZE sizeof(struct Ureg) #define REGSIZE sizeof(struct Ureg386)
#define FP_CTL(x) (REGSIZE+4*(x)) #define FP_CTL(x) (REGSIZE+4*(x))
#define FP_REG(x) (FP_CTL(7)+10*(x)) #define FP_REG(x) (FP_CTL(7)+10*(x))
#define FPREGSIZE (7*4+8*10) #define FPREGSIZE (7*4+8*10)
......
...@@ -30,15 +30,8 @@ ...@@ -30,15 +30,8 @@
#include <libc.h> #include <libc.h>
#include <bio.h> #include <bio.h>
#include <mach.h> #include <mach.h>
#define Ureg UregAmd64
#include <ureg_amd64.h> #include <ureg_amd64.h>
#undef Ureg
#define Ureg Ureg386
#include <ureg_x86.h> #include <ureg_x86.h>
#undef Ureg
typedef struct UregAmd64 UregAmd64;
typedef struct Ureg386 Ureg386;
/* /*
* i386-specific debugger interface * i386-specific debugger interface
......
...@@ -29,17 +29,10 @@ ...@@ -29,17 +29,10 @@
#include <libc.h> #include <libc.h>
#include <bio.h> #include <bio.h>
#include <mach.h> #include <mach.h>
#define Ureg Ureg32
#include <ureg_x86.h> #include <ureg_x86.h>
#undef Ureg
#define Ureg Ureg64
#include <ureg_amd64.h> #include <ureg_amd64.h>
#undef Ureg
#undef waitpid /* want Unix waitpid, not Plan 9 */ #undef waitpid /* want Unix waitpid, not Plan 9 */
typedef struct Ureg32 Ureg32;
typedef struct Ureg64 Ureg64;
extern mach_port_t mach_reply_port(void); // should be in system headers, is not extern mach_port_t mach_reply_port(void); // should be in system headers, is not
// Mach-error wrapper. // Mach-error wrapper.
...@@ -450,31 +443,31 @@ static int ...@@ -450,31 +443,31 @@ static int
go2darwin32(uvlong addr) go2darwin32(uvlong addr)
{ {
switch(addr){ switch(addr){
case offsetof(Ureg32, ax): case offsetof(Ureg386, ax):
return offsetof(x86_thread_state32_t, eax); return offsetof(x86_thread_state32_t, eax);
case offsetof(Ureg32, bx): case offsetof(Ureg386, bx):
return offsetof(x86_thread_state32_t, ebx); return offsetof(x86_thread_state32_t, ebx);
case offsetof(Ureg32, cx): case offsetof(Ureg386, cx):
return offsetof(x86_thread_state32_t, ecx); return offsetof(x86_thread_state32_t, ecx);
case offsetof(Ureg32, dx): case offsetof(Ureg386, dx):
return offsetof(x86_thread_state32_t, edx); return offsetof(x86_thread_state32_t, edx);
case offsetof(Ureg32, si): case offsetof(Ureg386, si):
return offsetof(x86_thread_state32_t, esi); return offsetof(x86_thread_state32_t, esi);
case offsetof(Ureg32, di): case offsetof(Ureg386, di):
return offsetof(x86_thread_state32_t, edi); return offsetof(x86_thread_state32_t, edi);
case offsetof(Ureg32, bp): case offsetof(Ureg386, bp):
return offsetof(x86_thread_state32_t, ebp); return offsetof(x86_thread_state32_t, ebp);
case offsetof(Ureg32, fs): case offsetof(Ureg386, fs):
return offsetof(x86_thread_state32_t, fs); return offsetof(x86_thread_state32_t, fs);
case offsetof(Ureg32, gs): case offsetof(Ureg386, gs):
return offsetof(x86_thread_state32_t, gs); return offsetof(x86_thread_state32_t, gs);
case offsetof(Ureg32, pc): case offsetof(Ureg386, pc):
return offsetof(x86_thread_state32_t, eip); return offsetof(x86_thread_state32_t, eip);
case offsetof(Ureg32, cs): case offsetof(Ureg386, cs):
return offsetof(x86_thread_state32_t, cs); return offsetof(x86_thread_state32_t, cs);
case offsetof(Ureg32, flags): case offsetof(Ureg386, flags):
return offsetof(x86_thread_state32_t, eflags); return offsetof(x86_thread_state32_t, eflags);
case offsetof(Ureg32, sp): case offsetof(Ureg386, sp):
return offsetof(x86_thread_state32_t, esp); return offsetof(x86_thread_state32_t, esp);
} }
return -1; return -1;
...@@ -485,47 +478,47 @@ static int ...@@ -485,47 +478,47 @@ static int
go2darwin64(uvlong addr) go2darwin64(uvlong addr)
{ {
switch(addr){ switch(addr){
case offsetof(Ureg64, ax): case offsetof(UregAmd64, ax):
return offsetof(x86_thread_state64_t, rax); return offsetof(x86_thread_state64_t, rax);
case offsetof(Ureg64, bx): case offsetof(UregAmd64, bx):
return offsetof(x86_thread_state64_t, rbx); return offsetof(x86_thread_state64_t, rbx);
case offsetof(Ureg64, cx): case offsetof(UregAmd64, cx):
return offsetof(x86_thread_state64_t, rcx); return offsetof(x86_thread_state64_t, rcx);
case offsetof(Ureg64, dx): case offsetof(UregAmd64, dx):
return offsetof(x86_thread_state64_t, rdx); return offsetof(x86_thread_state64_t, rdx);
case offsetof(Ureg64, si): case offsetof(UregAmd64, si):
return offsetof(x86_thread_state64_t, rsi); return offsetof(x86_thread_state64_t, rsi);
case offsetof(Ureg64, di): case offsetof(UregAmd64, di):
return offsetof(x86_thread_state64_t, rdi); return offsetof(x86_thread_state64_t, rdi);
case offsetof(Ureg64, bp): case offsetof(UregAmd64, bp):
return offsetof(x86_thread_state64_t, rbp); return offsetof(x86_thread_state64_t, rbp);
case offsetof(Ureg64, r8): case offsetof(UregAmd64, r8):
return offsetof(x86_thread_state64_t, r8); return offsetof(x86_thread_state64_t, r8);
case offsetof(Ureg64, r9): case offsetof(UregAmd64, r9):
return offsetof(x86_thread_state64_t, r9); return offsetof(x86_thread_state64_t, r9);
case offsetof(Ureg64, r10): case offsetof(UregAmd64, r10):
return offsetof(x86_thread_state64_t, r10); return offsetof(x86_thread_state64_t, r10);
case offsetof(Ureg64, r11): case offsetof(UregAmd64, r11):
return offsetof(x86_thread_state64_t, r11); return offsetof(x86_thread_state64_t, r11);
case offsetof(Ureg64, r12): case offsetof(UregAmd64, r12):
return offsetof(x86_thread_state64_t, r12); return offsetof(x86_thread_state64_t, r12);
case offsetof(Ureg64, r13): case offsetof(UregAmd64, r13):
return offsetof(x86_thread_state64_t, r13); return offsetof(x86_thread_state64_t, r13);
case offsetof(Ureg64, r14): case offsetof(UregAmd64, r14):
return offsetof(x86_thread_state64_t, r14); return offsetof(x86_thread_state64_t, r14);
case offsetof(Ureg64, r15): case offsetof(UregAmd64, r15):
return offsetof(x86_thread_state64_t, r15); return offsetof(x86_thread_state64_t, r15);
case offsetof(Ureg64, fs): case offsetof(UregAmd64, fs):
return offsetof(x86_thread_state64_t, fs); return offsetof(x86_thread_state64_t, fs);
case offsetof(Ureg64, gs): case offsetof(UregAmd64, gs):
return offsetof(x86_thread_state64_t, gs); return offsetof(x86_thread_state64_t, gs);
case offsetof(Ureg64, ip): case offsetof(UregAmd64, ip):
return offsetof(x86_thread_state64_t, rip); return offsetof(x86_thread_state64_t, rip);
case offsetof(Ureg64, cs): case offsetof(UregAmd64, cs):
return offsetof(x86_thread_state64_t, cs); return offsetof(x86_thread_state64_t, cs);
case offsetof(Ureg64, flags): case offsetof(UregAmd64, flags):
return offsetof(x86_thread_state64_t, rflags); return offsetof(x86_thread_state64_t, rflags);
case offsetof(Ureg64, sp): case offsetof(UregAmd64, sp):
return offsetof(x86_thread_state64_t, rsp); return offsetof(x86_thread_state64_t, rsp);
} }
return -1; return -1;
......
...@@ -38,12 +38,8 @@ ...@@ -38,12 +38,8 @@
#include <libc.h> #include <libc.h>
#include <bio.h> #include <bio.h>
#include <mach.h> #include <mach.h>
#define Ureg Ureg32
#include <ureg_x86.h> #include <ureg_x86.h>
#undef Ureg
#define Ureg Ureg64
#include <ureg_amd64.h> #include <ureg_amd64.h>
#undef Ureg
#undef waitpid #undef waitpid
// The old glibc used with crosstool compilers on thresher // The old glibc used with crosstool compilers on thresher
...@@ -71,8 +67,6 @@ ...@@ -71,8 +67,6 @@
#define PTRACE_EVENT_EXIT 0x6 #define PTRACE_EVENT_EXIT 0x6
#endif #endif
typedef struct Ureg64 Ureg64;
static Maprw ptracesegrw; static Maprw ptracesegrw;
static Maprw ptraceregrw; static Maprw ptraceregrw;
...@@ -882,53 +876,53 @@ go2linux(uvlong addr) ...@@ -882,53 +876,53 @@ go2linux(uvlong addr)
} }
switch(addr){ switch(addr){
case offsetof(Ureg64, ax): case offsetof(UregAmd64, ax):
return offsetof(struct user_regs_struct, rax); return offsetof(struct user_regs_struct, rax);
case offsetof(Ureg64, bx): case offsetof(UregAmd64, bx):
return offsetof(struct user_regs_struct, rbx); return offsetof(struct user_regs_struct, rbx);
case offsetof(Ureg64, cx): case offsetof(UregAmd64, cx):
return offsetof(struct user_regs_struct, rcx); return offsetof(struct user_regs_struct, rcx);
case offsetof(Ureg64, dx): case offsetof(UregAmd64, dx):
return offsetof(struct user_regs_struct, rdx); return offsetof(struct user_regs_struct, rdx);
case offsetof(Ureg64, si): case offsetof(UregAmd64, si):
return offsetof(struct user_regs_struct, rsi); return offsetof(struct user_regs_struct, rsi);
case offsetof(Ureg64, di): case offsetof(UregAmd64, di):
return offsetof(struct user_regs_struct, rdi); return offsetof(struct user_regs_struct, rdi);
case offsetof(Ureg64, bp): case offsetof(UregAmd64, bp):
return offsetof(struct user_regs_struct, rbp); return offsetof(struct user_regs_struct, rbp);
case offsetof(Ureg64, r8): case offsetof(UregAmd64, r8):
return offsetof(struct user_regs_struct, r8); return offsetof(struct user_regs_struct, r8);
case offsetof(Ureg64, r9): case offsetof(UregAmd64, r9):
return offsetof(struct user_regs_struct, r9); return offsetof(struct user_regs_struct, r9);
case offsetof(Ureg64, r10): case offsetof(UregAmd64, r10):
return offsetof(struct user_regs_struct, r10); return offsetof(struct user_regs_struct, r10);
case offsetof(Ureg64, r11): case offsetof(UregAmd64, r11):
return offsetof(struct user_regs_struct, r11); return offsetof(struct user_regs_struct, r11);
case offsetof(Ureg64, r12): case offsetof(UregAmd64, r12):
return offsetof(struct user_regs_struct, r12); return offsetof(struct user_regs_struct, r12);
case offsetof(Ureg64, r13): case offsetof(UregAmd64, r13):
return offsetof(struct user_regs_struct, r13); return offsetof(struct user_regs_struct, r13);
case offsetof(Ureg64, r14): case offsetof(UregAmd64, r14):
return offsetof(struct user_regs_struct, r14); return offsetof(struct user_regs_struct, r14);
case offsetof(Ureg64, r15): case offsetof(UregAmd64, r15):
return offsetof(struct user_regs_struct, r15); return offsetof(struct user_regs_struct, r15);
case offsetof(Ureg64, ds): case offsetof(UregAmd64, ds):
return offsetof(struct user_regs_struct, ds); return offsetof(struct user_regs_struct, ds);
case offsetof(Ureg64, es): case offsetof(UregAmd64, es):
return offsetof(struct user_regs_struct, es); return offsetof(struct user_regs_struct, es);
case offsetof(Ureg64, fs): case offsetof(UregAmd64, fs):
return offsetof(struct user_regs_struct, fs); return offsetof(struct user_regs_struct, fs);
case offsetof(Ureg64, gs): case offsetof(UregAmd64, gs):
return offsetof(struct user_regs_struct, gs); return offsetof(struct user_regs_struct, gs);
case offsetof(Ureg64, ip): case offsetof(UregAmd64, ip):
return offsetof(struct user_regs_struct, rip); return offsetof(struct user_regs_struct, rip);
case offsetof(Ureg64, cs): case offsetof(UregAmd64, cs):
return offsetof(struct user_regs_struct, cs); return offsetof(struct user_regs_struct, cs);
case offsetof(Ureg64, flags): case offsetof(UregAmd64, flags):
return offsetof(struct user_regs_struct, eflags); return offsetof(struct user_regs_struct, eflags);
case offsetof(Ureg64, sp): case offsetof(UregAmd64, sp):
return offsetof(struct user_regs_struct, rsp); return offsetof(struct user_regs_struct, rsp);
case offsetof(Ureg64, ss): case offsetof(UregAmd64, ss):
return offsetof(struct user_regs_struct, ss); return offsetof(struct user_regs_struct, ss);
} }
return -1; return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment