linux-user: Added ELF coredump support for x86 and x86_64 targets
authorMika Westerberg <mika.westerberg@iki.fi>
Tue, 31 Mar 2009 14:10:21 +0000 (17:10 +0300)
committerRiku Voipio <riku.voipio@nokia.com>
Tue, 31 Mar 2009 15:29:37 +0000 (18:29 +0300)
linux-user/elfload.c
linux-user/i386/syscall.h
linux-user/x86_64/syscall.h

index 3c8c9a0..706c8e2 100644 (file)
@@ -133,7 +133,45 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     regs->rip = infop->entry;
 }
 
-#else
+#define USE_ELF_CORE_DUMP
+
+typedef struct target_pt_regs elf_gregset_t;
+
+/*
+ * For register format that gdb uses, see <sys/reg.h>.  These
+ * should be in same format (which is usually same as target_pt_regs).
+ */
+static void elf_core_copy_regs(elf_gregset_t *elfregs, const CPUState *env)
+{
+    (void) memset(elfregs, 0, sizeof (*elfregs));
+
+    /* GPRs */
+    elfregs->r15 = env->regs[15];
+    elfregs->r14 = env->regs[14];
+    elfregs->r13 = env->regs[13];
+    elfregs->r12 = env->regs[12];
+    elfregs->rbp = env->regs[R_EBP];
+    elfregs->rbx = env->regs[R_EBX];
+    elfregs->r11 = env->regs[11];
+    elfregs->r10 = env->regs[10];
+    elfregs->r9 = env->regs[9];
+    elfregs->r8 = env->regs[8];
+    elfregs->rax = env->regs[R_EAX];
+    elfregs->rcx = env->regs[R_ECX];
+    elfregs->rdx = env->regs[R_EDX];
+    elfregs->rsi = env->regs[R_ESI];
+    elfregs->rdi = env->regs[R_EDI];
+    elfregs->orig_rax = env->regs[R_EAX];
+    elfregs->rip = env->eip;
+    elfregs->rsp = env->regs[R_ESP];
+    elfregs->eflags = env->eflags;
+
+    /* segment registers */
+    elfregs->cs = env->segs[R_CS].selector;
+    elfregs->ss = env->segs[R_SS].selector;
+}
+
+#else /* !TARGET_X86_64 */
 
 #define ELF_START_MMAP 0x80000000
 
@@ -163,7 +201,38 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
        A value of 0 tells we have no such handler.  */
     regs->edx = 0;
 }
-#endif
+
+#define USE_ELF_CORE_DUMP
+
+typedef struct target_pt_regs elf_gregset_t;
+
+static void elf_core_copy_regs(elf_gregset_t *elfregs, const CPUState *env)
+{
+    (void) memset(elfregs, 0, sizeof (*elfregs));
+
+    /* GPRs */
+    elfregs->ebx = env->regs[R_EBX];
+    elfregs->ecx = env->regs[R_ECX];
+    elfregs->edx = env->regs[R_EDX];
+    elfregs->esi = env->regs[R_ESI];
+    elfregs->edi = env->regs[R_EDI];
+    elfregs->ebp = env->regs[R_EBP];
+    elfregs->eax = env->regs[R_EAX];
+    elfregs->orig_eax = env->regs[R_EAX]; /* XXX */
+    elfregs->esp = env->regs[R_ESP];
+    elfregs->eip = env->eip;
+    elfregs->eflags = env->eflags;
+
+    /* segment registers */
+    elfregs->xds = env->segs[R_DS].selector;
+    elfregs->xes = env->segs[R_ES].selector;
+    elfregs->xcs = env->segs[R_CS].selector;
+    elfregs->xss = env->segs[R_SS].selector;
+    elfregs->xfs = env->segs[R_FS].selector;
+    elfregs->xgs = env->segs[R_GS].selector;
+}
+
+#endif /* TARGET_i386 */
 
 #define ELF_EXEC_PAGESIZE      4096
 
@@ -206,10 +275,10 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 typedef struct target_pt_regs elf_gregset_t;
 
-static void elf_core_copy_regs(elf_gregset_t *, const CPUState *);
-
 static void elf_core_copy_regs(elf_gregset_t *elfregs, const CPUState *env)
 {
+    (void) memset(elfregs, 0, sizeof (*elfregs));
+
     elfregs->ARM_r0 = env->regs[0];
     elfregs->ARM_r1 = env->regs[1];
     elfregs->ARM_r2 = env->regs[2];
@@ -1612,9 +1681,9 @@ struct memelfnote {
 };
 
 struct elf_siginfo {
-    abi_long  si_signo; /* signal number */
-    abi_long  si_code;  /* extra code */
-    abi_long  si_errno; /* errno */
+    int  si_signo; /* signal number */
+    int  si_code;  /* extra code */
+    int  si_errno; /* errno */
 };
 
 struct elf_prstatus {
@@ -1622,10 +1691,10 @@ struct elf_prstatus {
     short              pr_cursig;    /* Current signal */
     target_ulong       pr_sigpend;   /* XXX */
     target_ulong       pr_sighold;   /* XXX */
-    abi_long           pr_pid;
-    abi_long           pr_ppid;
-    abi_long           pr_pgrp;
-    abi_long           pr_sid;
+    int                pr_pid;
+    int                pr_ppid;
+    int                pr_pgrp;
+    int                pr_sid;
     struct target_timeval pr_utime;  /* XXX User time */
     struct target_timeval pr_stime;  /* XXX System time */
     struct target_timeval pr_cutime; /* XXX Cumulative user time */
index 266e2c4..90405ea 100644 (file)
@@ -3,21 +3,23 @@
 #define __USER_DS      (0x2B)
 
 struct target_pt_regs {
-       long ebx;
-       long ecx;
-       long edx;
-       long esi;
-       long edi;
-       long ebp;
-       long eax;
-       int  xds;
-       int  xes;
-       long orig_eax;
-       long eip;
-       int  xcs;
-       long eflags;
-       long esp;
-       int  xss;
+    abi_ulong ebx;
+    abi_ulong ecx;
+    abi_ulong edx;
+    abi_ulong esi;
+    abi_ulong edi;
+    abi_ulong ebp;
+    abi_ulong eax;
+    abi_ulong xds;
+    abi_ulong xes;
+    abi_ulong xfs;
+    abi_ulong xgs;
+    abi_ulong orig_eax;
+    abi_ulong eip;
+    abi_ulong xcs;
+    abi_ulong eflags;
+    abi_ulong esp;
+    abi_ulong xss;
 };
 
 /* ioctls */
index 2a8d696..ab82ce0 100644 (file)
@@ -2,30 +2,36 @@
 #define __USER_DS      (0x2B)
 
 struct target_pt_regs {
-       abi_ulong r15;
-       abi_ulong r14;
-       abi_ulong r13;
-       abi_ulong r12;
-       abi_ulong rbp;
-       abi_ulong rbx;
+    abi_ulong r15;
+    abi_ulong r14;
+    abi_ulong r13;
+    abi_ulong r12;
+    abi_ulong rbp;
+    abi_ulong rbx;
 /* arguments: non interrupts/non tracing syscalls only save upto here*/
-       abi_ulong r11;
-       abi_ulong r10;
-       abi_ulong r9;
-       abi_ulong r8;
-       abi_ulong rax;
-       abi_ulong rcx;
-       abi_ulong rdx;
-       abi_ulong rsi;
-       abi_ulong rdi;
-       abi_ulong orig_rax;
+    abi_ulong r11;
+    abi_ulong r10;
+    abi_ulong r9;
+    abi_ulong r8;
+    abi_ulong rax;
+    abi_ulong rcx;
+    abi_ulong rdx;
+    abi_ulong rsi;
+    abi_ulong rdi;
+    abi_ulong orig_rax;
 /* end of arguments */
 /* cpu exception frame or undefined */
-       abi_ulong rip;
-       abi_ulong cs;
-       abi_ulong eflags;
-       abi_ulong rsp;
-       abi_ulong ss;
+    abi_ulong rip;
+    abi_ulong cs;
+    abi_ulong eflags;
+    abi_ulong rsp;
+    abi_ulong ss;
+    abi_ulong fs_base;
+    abi_ulong gs_base;
+    abi_ulong ds;
+    abi_ulong es;
+    abi_ulong fs;
+    abi_ulong gs;
 /* top of stack page */
 };