linux-user: correct core dump format
PATCH 1/1 linux-user: correct core dump format
This patch allows to really use the core dumped by qemu with guest architecture tools.
- it adds a missing bswap_phdr() for the program headers of memory regions.
"objdump -x" sample:
BEFORE:
0x1000000 off 0x00200000 vaddr 0x00000400 paddr 0x00000000 align 2**21
filesz 0x00000000 memsz 0x00100000 flags ---
0x1000000 off 0x00200000 vaddr 0x00100400 paddr 0x00000000 align 2**21
filesz 0x00000000 memsz 0x00080000 flags --- 6000000AFTER:
LOAD off 0x00002000 vaddr 0x00040000 paddr 0x00000000 align 2**13
filesz 0x00000000 memsz 0x00001000 flags ---
LOAD off 0x00002000 vaddr 0x00041000 paddr 0x00000000 align 2**13
filesz 0x00000000 memsz 0x00000800 flags rw-- it doesn't pad the note size to sizeof(int32_t).
On m68k the NT_PRSTATUS note size is 154 and
must not be rounded up to 156, because this value is checked by objdump and gdb.
"gdb" symptoms:
"warning: Couldn't find general-purpose registers in core file."
"objdump -x" sample:
BEFORE:
Sections:
Idx Name Size VMA LMA File off Algn 0 note0 000001c4 00000000 00000000 000003b4 2**0
CONTENTS, READONLY
1 .auxv 00000070 00000000 00000000 00000508 2**2
CONTENTS
2 proc1 00100000 00000400 00000000 00200000 2**10
READONLY
AFTER:
Sections:
Idx Name Size VMA LMA File off Algn 0 note0 000001c4 00000000 00000000 000003b4 2**0
CONTENTS, READONLY
1 .reg/19022 00000050 00000000 00000000 0000040e 2**2
CONTENTS
2 .reg 00000050 00000000 00000000 0000040e 2**2
CONTENTS
3 .auxv 00000070 00000000 00000000 00000508 2**2
CONTENTS
4 load1 00000000 00040000 00000000 00002000 2**13
ALLOC, READONLY
--- linux-user/elfload.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)
linux-user/elfload.c +9 -7
@@ -1688,6 +1688,7 @@ struct memelfnote {size_t namesz_rounded;int type;size_t datasz; +size_t datasz_rounded;void *data;size_t notesz; };
@@ -1713,7 +1714,7 @@ struct target_elf_prstatus {struct target_timeval pr_cstime;/* XXX Cumulative system time */ target_elf_gregset_t pr_reg;/* GP registers */ int pr_fpvalid;/* XXX */ -}; +} __attribute__((packed));#define ELF_PRARGSZ (80)/* Number of chars for args */
@@ -1963,7 +1964,9 @@ static void fill_note(struct memelfnote *note, const char *name, int type, note->namesz = namesz; note->namesz_rounded =roundup (namesz,sizeof (int32_t )); note->type = type; - note->datasz =roundup (sz,sizeof (int32_t ));; + note->datasz = sz; + note->datasz_rounded =roundup (sz,sizeof (int32_t )); + note->data = data;/*
@@ -1971,7 +1974,7 @@ static void fill_note(struct memelfnote *note, const char *name, int type,* ELF document. */ note->notesz =sizeof (struct elf_note ) + - note->namesz_rounded + note->datasz; + note->namesz_rounded + note->datasz_rounded; } static void fill_elf_header(struct elfhdr *elf, int segs, uint16_t machine,
@@ -2191,7 +2194,7 @@ static int write_note(struct memelfnote *men, int fd)return (-1 );if (dump_write (fd, men->name, men->namesz_rounded) !=0 )return (-1 ); -if (dump_write (fd, men->data, men->datasz) !=0 ) +if (dump_write (fd, men->data, men->datasz_rounded) !=0 )return (-1 );return (0 );
@@ -2407,7 +2410,7 @@ static int elf_core_dump(int signr, const CPUState *env)* ELF specification wants data to start at page boundary so * we align it here. */ - offset =roundup (offset,ELF_EXEC_PAGESIZE ); + data_offset = offset =roundup (offset,ELF_EXEC_PAGESIZE );/* * Write program headers for memory regions mapped in
@@ -2430,6 +2433,7 @@ static int elf_core_dump(int signr, const CPUState *env) phdr.p_flags |=PF_X ; phdr.p_align =ELF_EXEC_PAGESIZE ; +bswap_phdr (&phdr,1 );dump_write (fd, &phdr,sizeof (phdr)); }
@@ -2441,8 +2445,6 @@ static int elf_core_dump(int signr, const CPUState *env) goto out;/* align data to page boundary */ - data_offset =lseek (fd,0 ,SEEK_CUR ); - data_offset =TARGET_PAGE_ALIGN (data_offset);if (lseek (fd, data_offset,SEEK_SET ) != data_offset) goto out;
Signature · 1 line
1.7.1