Skip to contentSkip to conversation

linux-user: core dump enhancements

PATCH In review Nathan Froyd 2 participants 9 messages Dec 11, 2009

lore
Share & tools
lore
#0 lore raw

cover linux-user: core dump enhancements

This patch series adds core dump capabilities for Linux user-mode emulation for several additional architectures. It also fixes core dumps for ARM targets on opposite-endian hosts.

Nathan Froyd (7):
linux-user: fix ELF_USE_CORE_DUMP/USE_ELF_CORE_DUMP confusion
linux-user: commonify definitions of target typedefs
linux-user: fix ARM core dumps on opposite-endian hosts
linux-user: add core dump support for PPC
linux-user: add core dump support for MIPS
linux-user: add core dump support for M68K
linux-user: add core dump support for SH

 linux-user/elfload.c |  206 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 164 insertions(+), 42 deletions(-)
#1 lore raw

PATCH 1/7 linux-user: fix ELF_USE_CORE_DUMP/USE_ELF_CORE_DUMP confusion

---
 linux-user/elfload.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
linux-user/elfload.c +1 -1
index 682a813..76eb031 100644
@@ -1767,7 +1767,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
  * Core dump code is copied from linux kernel (fs/binfmt_elf.c).
  *
  * Porting ELF coredump for target is (quite) simple process.  First you
- * define ELF_USE_CORE_DUMP in target ELF code (where init_thread() for
+ * define USE_ELF_CORE_DUMP in target ELF code (where init_thread() for
  * the target resides):
  *
  * #define USE_ELF_CORE_DUMP
Signature · 1 line
1.6.3.2
#2 lore raw

PATCH 2/7 linux-user: commonify definitions of target typedefs

In reply to Nathan Froyd

There's no sense in separately declaring target_{elf_greg,uid,gid,pid}_t for every architecture. Just declare them once with appropriate USE_UID16 handling.

---
 linux-user/elfload.c |   32 ++++++++++----------------------
 1 files changed, 10 insertions(+), 22 deletions(-)
linux-user/elfload.c +10 -22
index 76eb031..024dcc2 100644
@@ -97,6 +97,16 @@ enum {
 #define ELIBBAD 80
 #endif
 
+typedef target_ulong	target_elf_greg_t;
+#ifdef USE_UID16
+typedef uint16_t	target_uid_t;
+typedef uint16_t	target_gid_t;
+#else
+typedef uint32_t	target_uid_t;
+typedef uint32_t	target_gid_t;
+#endif
+typedef int32_t		target_pid_t;
+
 #ifdef TARGET_I386
 
 #define ELF_PLATFORM get_elf_platform()
@@ -134,11 +144,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     regs->rip = infop->entry;
 }
 
-typedef target_ulong    target_elf_greg_t;
-typedef uint32_t        target_uid_t;
-typedef uint32_t        target_gid_t;
-typedef int32_t         target_pid_t;
-
 #define ELF_NREG    27
 typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
 
@@ -211,11 +216,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     regs->edx = 0;
 }
 
-typedef target_ulong    target_elf_greg_t;
-typedef uint16_t        target_uid_t;
-typedef uint16_t        target_gid_t;
-typedef int32_t         target_pid_t;
-
 #define ELF_NREG    17
 typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
 
@@ -286,11 +286,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     regs->ARM_r10 = infop->start_data;
 }
 
-typedef uint32_t target_elf_greg_t;
-typedef uint16_t target_uid_t;
-typedef uint16_t target_gid_t;
-typedef int32_t  target_pid_t;
-
 #define ELF_NREG    18
 typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
 
@@ -1779,13 +1774,6 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
  * #define ELF_NREG <number of registers>
  * typedef taret_elf_greg_t target_elf_gregset_t[ELF_NREG];
  *
- * Then define following types to match target types.  Actual types can
- * be found from linux kernel (arch/<ARCH>/include/asm/posix_types.h):
- *
- * typedef <target_uid_type> target_uid_t;
- * typedef <target_gid_type> target_gid_t;
- * typedef <target_pid_type> target_pid_t;
- *
  * Last step is to implement target specific function that copies registers
  * from given cpu into just specified register set.  Prototype is:
  *
Signature · 1 line
1.6.3.2
#3 lore raw

PATCH 3/7 linux-user: fix ARM core dumps on opposite-endian hosts

In reply to Nathan Froyd
---
 linux-user/elfload.c |   38 +++++++++++++++++++-------------------
 1 files changed, 19 insertions(+), 19 deletions(-)
linux-user/elfload.c +19 -19
index 024dcc2..3551d34 100644
@@ -291,25 +291,25 @@ typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
 
 static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUState *env)
 {
-    (*regs)[0] = env->regs[0];
-    (*regs)[1] = env->regs[1];
-    (*regs)[2] = env->regs[2];
-    (*regs)[3] = env->regs[3];
-    (*regs)[4] = env->regs[4];
-    (*regs)[5] = env->regs[5];
-    (*regs)[6] = env->regs[6];
-    (*regs)[7] = env->regs[7];
-    (*regs)[8] = env->regs[8];
-    (*regs)[9] = env->regs[9];
-    (*regs)[10] = env->regs[10];
-    (*regs)[11] = env->regs[11];
-    (*regs)[12] = env->regs[12];
-    (*regs)[13] = env->regs[13];
-    (*regs)[14] = env->regs[14];
-    (*regs)[15] = env->regs[15];
-
-    (*regs)[16] = cpsr_read((CPUState *)env);
-    (*regs)[17] = env->regs[0]; /* XXX */
+    (*regs)[0] = tswapl(env->regs[0]);
+    (*regs)[1] = tswapl(env->regs[1]);
+    (*regs)[2] = tswapl(env->regs[2]);
+    (*regs)[3] = tswapl(env->regs[3]);
+    (*regs)[4] = tswapl(env->regs[4]);
+    (*regs)[5] = tswapl(env->regs[5]);
+    (*regs)[6] = tswapl(env->regs[6]);
+    (*regs)[7] = tswapl(env->regs[7]);
+    (*regs)[8] = tswapl(env->regs[8]);
+    (*regs)[9] = tswapl(env->regs[9]);
+    (*regs)[10] = tswapl(env->regs[10]);
+    (*regs)[11] = tswapl(env->regs[11]);
+    (*regs)[12] = tswapl(env->regs[12]);
+    (*regs)[13] = tswapl(env->regs[13]);
+    (*regs)[14] = tswapl(env->regs[14]);
+    (*regs)[15] = tswapl(env->regs[15]);
+
+    (*regs)[16] = tswapl(cpsr_read((CPUState *)env));
+    (*regs)[17] = tswapl(env->regs[0]); /* XXX */
 }
 
 #define USE_ELF_CORE_DUMP
Signature · 1 line
1.6.3.2
#4 lore raw

PATCH 4/7 linux-user: add core dump support for PPC

In reply to Nathan Froyd
---
 linux-user/elfload.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
linux-user/elfload.c +26 -0
index 3551d34..97dc3a7 100644
@@ -539,6 +539,32 @@ static inline void init_thread(struct target_pt_regs *_regs, struct image_info *
     _regs->gpr[5] = pos;
 }
 
+/* See linux kernel: arch/powerpc/include/asm/elf.h.  */
+#define ELF_NREG 48
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUState *env)
+{
+    int i;
+    target_ulong ccr = 0;
+
+    for (i = 0; i < ARRAY_SIZE(env->gpr); i++) {
+        (*regs)[i] = tswapl(env->gpr[i]);
+    }
+
+    (*regs)[32] = tswapl(env->nip);
+    (*regs)[33] = tswapl(env->msr);
+    (*regs)[35] = tswapl(env->ctr);
+    (*regs)[36] = tswapl(env->lr);
+    (*regs)[37] = tswapl(env->xer);
+
+    for (i = 0; i < ARRAY_SIZE(env->crf); i++) {
+        ccr |= env->crf[i] << (32 - ((i + 1) * 4));
+    }
+    (*regs)[38] = tswapl(ccr);
+}
+
+#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE	4096
 
 #endif
Signature · 1 line
1.6.3.2
#6 lore raw

PATCH 5/7 linux-user: add core dump support for MIPS

In reply to Nathan Froyd
---
 linux-user/elfload.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
linux-user/elfload.c +46 -0
index 97dc3a7..eb89f5f 100644
@@ -594,6 +594,52 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     regs->regs[29] = infop->start_stack;
 }
 
+/* See linux kernel: arch/mips/include/asm/elf.h.  */
+#define ELF_NREG 45
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+/* See linux kernel: arch/mips/include/asm/reg.h.  */
+enum {
+#ifdef TARGET_MIPS64
+    TARGET_EF_R0 = 0,
+#else
+    TARGET_EF_R0 = 6,
+#endif
+    TARGET_EF_R26 = TARGET_EF_R0 + 26,
+    TARGET_EF_R27 = TARGET_EF_R0 + 27,
+    TARGET_EF_LO = TARGET_EF_R0 + 32,
+    TARGET_EF_HI = TARGET_EF_R0 + 33,
+    TARGET_EF_CP0_EPC = TARGET_EF_R0 + 34,
+    TARGET_EF_CP0_BADVADDR = TARGET_EF_R0 + 35,
+    TARGET_EF_CP0_STATUS = TARGET_EF_R0 + 36,
+    TARGET_EF_CP0_CAUSE = TARGET_EF_R0 + 37
+};
+
+/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs.  */
+static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUState *env)
+{
+    int i;
+
+    for (i = 0; i < TARGET_EF_R0; i++) {
+        (*regs)[i] = 0;
+    }
+    (*regs)[TARGET_EF_R0] = 0;
+
+    for (i = 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) {
+        (*regs)[TARGET_EF_R0 + i] = tswapl(env->active_tc.gpr[i]);
+    }
+
+    (*regs)[TARGET_EF_R26] = 0;
+    (*regs)[TARGET_EF_R27] = 0;
+    (*regs)[TARGET_EF_LO] = tswapl(env->active_tc.LO[0]);
+    (*regs)[TARGET_EF_HI] = tswapl(env->active_tc.HI[0]);
+    (*regs)[TARGET_EF_CP0_EPC] = tswapl(env->active_tc.PC);
+    (*regs)[TARGET_EF_CP0_BADVADDR] = tswapl(env->CP0_BadVAddr);
+    (*regs)[TARGET_EF_CP0_STATUS] = tswapl(env->CP0_Status);
+    (*regs)[TARGET_EF_CP0_CAUSE] = tswapl(env->CP0_Cause);
+}
+
+#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
 #endif /* TARGET_MIPS */
Signature · 1 line
1.6.3.2
#7 lore raw

PATCH 6/7 linux-user: add core dump support for M68K

In reply to Nathan Froyd
---
 linux-user/elfload.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
linux-user/elfload.c +29 -0
index eb89f5f..53851d9 100644
@@ -725,6 +725,35 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     regs->pc = infop->entry;
 }
 
+/* See linux kernel: arch/m68k/include/asm/elf.h.  */
+#define ELF_NREG 20
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUState *env)
+{
+    (*regs)[0] = tswapl(env->dregs[1]);
+    (*regs)[1] = tswapl(env->dregs[2]);
+    (*regs)[2] = tswapl(env->dregs[3]);
+    (*regs)[3] = tswapl(env->dregs[4]);
+    (*regs)[4] = tswapl(env->dregs[5]);
+    (*regs)[5] = tswapl(env->dregs[6]);
+    (*regs)[6] = tswapl(env->dregs[7]);
+    (*regs)[7] = tswapl(env->aregs[0]);
+    (*regs)[8] = tswapl(env->aregs[1]);
+    (*regs)[9] = tswapl(env->aregs[2]);
+    (*regs)[10] = tswapl(env->aregs[3]);
+    (*regs)[11] = tswapl(env->aregs[4]);
+    (*regs)[12] = tswapl(env->aregs[5]);
+    (*regs)[13] = tswapl(env->aregs[6]);
+    (*regs)[14] = tswapl(env->dregs[0]);
+    (*regs)[15] = tswapl(env->aregs[7]);
+    (*regs)[16] = tswapl(env->dregs[0]); /* FIXME: orig_d0 */
+    (*regs)[17] = tswapl(env->sr);
+    (*regs)[18] = tswapl(env->pc);
+    (*regs)[19] = 0;  /* FIXME: regs->format | regs->vector */
+}
+
+#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE	8192
 
 #endif
Signature · 1 line
1.6.3.2
#8 lore raw

PATCH 7/7 linux-user: add core dump support for SH

In reply to Nathan Froyd
---
 linux-user/elfload.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
linux-user/elfload.c +33 -0
index 53851d9..e210956 100644
@@ -682,6 +682,39 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
   regs->regs[15] = infop->start_stack;
 }
 
+/* See linux kernel: arch/sh/include/asm/elf.h.  */
+#define ELF_NREG 23
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+/* See linux kernel: arch/sh/include/asm/ptrace.h.  */
+enum {
+    TARGET_REG_PC = 16,
+    TARGET_REG_PR = 17,
+    TARGET_REG_SR = 18,
+    TARGET_REG_GBR = 19,
+    TARGET_REG_MACH = 20,
+    TARGET_REG_MACL = 21,
+    TARGET_REG_SYSCALL = 22
+};
+
+static inline void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUState *env)
+{
+    int i;
+
+    for (i = 0; i < 16; i++) {
+        (*regs[i]) = tswapl(env->gregs[i]);
+    }
+
+    (*regs)[TARGET_REG_PC] = tswapl(env->pc);
+    (*regs)[TARGET_REG_PR] = tswapl(env->pr);
+    (*regs)[TARGET_REG_SR] = tswapl(env->sr);
+    (*regs)[TARGET_REG_GBR] = tswapl(env->gbr);
+    (*regs)[TARGET_REG_MACH] = tswapl(env->mach);
+    (*regs)[TARGET_REG_MACL] = tswapl(env->macl);
+    (*regs)[TARGET_REG_SYSCALL] = 0; /* FIXME */
+}
+
+#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
 #endif
Signature · 1 line
1.6.3.2