Small patch to ELF core dumper

Jeremy Fitzhardinge (jeremy@zip.com.au)
Sun, 14 Apr 1996 16:35:15 +1000


This is a multi-part message in MIME format.

--------------55A7E90869379D2A1F0CAE8A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi all,

I modified the ELF core dumper to include program headers for all
memory segments in the process, even for those it doesn't dump. For
the undumped ones, it sets the memory size to the size of the segment,
but the file size is 0.

This matches what the ELF core dumper does in Solaris, and makes the
core file more complete without unduly increasing its size. GDB
doesn't seem to care either way.

Patches are attached as diffs against 1.3.86.

J

--------------55A7E90869379D2A1F0CAE8A
Content-Type: text/plain; charset=us-ascii; name="fullcore.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="fullcore.diff"

--- binfmt_elf.c-1.3.86 Fri Apr 12 09:33:11 1996
+++ binfmt_elf.c Fri Apr 12 11:58:05 1996
@@ -964,16 +964,17 @@
segs = 0;
size = 0;
for(vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
- int sz = vma->vm_end-vma->vm_start;
+ if (maydump(vma))
+ {
+ int sz = vma->vm_end-vma->vm_start;

- if (!maydump(vma))
- continue;
-
- if (size+sz > limit)
- break;
+ if (size+sz >= limit)
+ break;
+ else
+ size += sz;
+ }

segs++;
- size += sz;
}
#ifdef DEBUG
printk("elf_core_dump: %d segs taking %d bytes\n", segs, size);
@@ -1152,8 +1153,6 @@
struct elf_phdr phdr;
size_t sz;

- if (!maydump(vma))
- continue;
i++;

sz = vma->vm_end - vma->vm_start;
@@ -1162,9 +1161,9 @@
phdr.p_offset = offset;
phdr.p_vaddr = vma->vm_start;
phdr.p_paddr = 0;
- phdr.p_filesz = sz;
+ phdr.p_filesz = maydump(vma) ? sz : 0;
phdr.p_memsz = sz;
- offset += sz;
+ offset += phdr.p_filesz;
phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
if (vma->vm_flags & VM_WRITE) phdr.p_flags |= PF_W;
if (vma->vm_flags & VM_EXEC) phdr.p_flags |= PF_X;

--------------55A7E90869379D2A1F0CAE8A--