|
From: <sv...@va...> - 2005-08-28 04:38:20
|
Author: njn
Date: 2005-08-28 05:38:12 +0100 (Sun, 28 Aug 2005)
New Revision: 4545
Log:
Move the core dumping code out of m_signals to a new module,
m_coredump. The code is still commented out, though.
Added:
trunk/coregrind/m_coredump.c
trunk/coregrind/pub_core_coredump.h
Modified:
trunk/coregrind/Makefile.am
trunk/coregrind/m_signals.c
Modified: trunk/coregrind/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/Makefile.am 2005-08-27 19:35:42 UTC (rev 4544)
+++ trunk/coregrind/Makefile.am 2005-08-28 04:38:12 UTC (rev 4545)
@@ -36,6 +36,7 @@
coregrind.h \
pub_core_aspacemgr.h \
pub_core_basics.h \
+ pub_core_coredump.h \
pub_core_cpuid.h \
pub_core_debuginfo.h \
pub_core_debugger.h \
@@ -95,6 +96,7 @@
valgrind_LDADD=3D
=20
stage2_SOURCES =3D \
+ m_coredump.c \
m_cpuid.S \
m_debugger.c \
m_debuglog.c \
Added: trunk/coregrind/m_coredump.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_coredump.c 2005-08-27 19:35:42 UTC (rev 4544)
+++ trunk/coregrind/m_coredump.c 2005-08-28 04:38:12 UTC (rev 4545)
@@ -0,0 +1,376 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Dumping core. m_coredump.c ---*/
+/*--------------------------------------------------------------------*/
+=20
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward=20
+ js...@ac...
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#include "pub_core_basics.h"
+#include "pub_core_coredump.h"
+#include "pub_core_libcassert.h"
+
+// Core dumping is disabled until someone can work out how to abstract o=
ut
+// the arch-specific and word-size-specific parts neatly.
+//
+// Note that the code below is not 64-bit clean!
+//
+#if 0
+/*
+ Dump core
+ =20
+ Generate a standard ELF core file corresponding to the client state
+ at the time of a crash.
+ */
+#include <elf.h>
+#ifndef NT_PRXFPREG
+#define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/el=
f/common.h */
+#endif /* NT_PRXFPREG */
+
+/* If true, then this Segment may be mentioned in the core */
+static Bool may_dump(const Segment *seg)
+{
+ return (seg->flags & (SF_DEVICE|SF_VALGRIND)) =3D=3D 0 && VG_(is_clie=
nt_addr)(seg->addr);
+}
+
+/* If true, then this Segment's contents will be in the core */
+static Bool should_dump(const Segment *seg)
+{
+ return may_dump(seg); // && (seg->prot & VKI_PROT_WRITE);
+}
+
+static void fill_ehdr(Elf32_Ehdr *ehdr, Int num_phdrs)
+{
+ VG_(memset)(ehdr, 0, sizeof(*ehdr));
+
+ VG_(memcpy)(ehdr->e_ident, ELFMAG, SELFMAG);
+ ehdr->e_ident[EI_CLASS] =3D VG_ELF_CLASS;
+ ehdr->e_ident[EI_DATA] =3D VG_ELF_ENDIANNESS;
+ ehdr->e_ident[EI_VERSION] =3D EV_CURRENT;
+
+ ehdr->e_type =3D ET_CORE;
+ ehdr->e_machine =3D VG_ELF_MACHINE;
+ ehdr->e_version =3D EV_CURRENT;
+ ehdr->e_entry =3D 0;
+ ehdr->e_phoff =3D sizeof(Elf32_Ehdr);
+ ehdr->e_shoff =3D 0;
+ ehdr->e_flags =3D 0;
+ ehdr->e_ehsize =3D sizeof(Elf32_Ehdr);
+ ehdr->e_phentsize =3D sizeof(Elf32_Phdr);
+ ehdr->e_phnum =3D num_phdrs;
+ ehdr->e_shentsize =3D 0;
+ ehdr->e_shnum =3D 0;
+ ehdr->e_shstrndx =3D 0;
+
+}
+
+static void fill_phdr(Elf32_Phdr *phdr, const Segment *seg, UInt off, Bo=
ol write)
+{
+ write =3D write && should_dump(seg);
+
+ VG_(memset)(phdr, 0, sizeof(*phdr));
+
+ phdr->p_type =3D PT_LOAD;
+ phdr->p_offset =3D off;
+ phdr->p_vaddr =3D seg->addr;
+ phdr->p_paddr =3D 0;
+ phdr->p_filesz =3D write ? seg->len : 0;
+ phdr->p_memsz =3D seg->len;
+ phdr->p_flags =3D 0;
+
+ if (seg->prot & VKI_PROT_READ)
+ phdr->p_flags |=3D PF_R;
+ if (seg->prot & VKI_PROT_WRITE)
+ phdr->p_flags |=3D PF_W;
+ if (seg->prot & VKI_PROT_EXEC)
+ phdr->p_flags |=3D PF_X;
+
+ phdr->p_align =3D VKI_PAGE_SIZE;
+}
+
+struct note {
+ struct note *next;
+ Elf32_Nhdr note;
+ Char name[0];
+};
+
+static UInt note_size(const struct note *n)
+{
+ return sizeof(Elf32_Nhdr) + VG_ROUNDUP(VG_(strlen)(n->name)+1, 4) + V=
G_ROUNDUP(n->note.n_descsz, 4);
+}
+
+static void add_note(struct note **list, const Char *name, UInt type, co=
nst void *data, UInt datasz)
+{
+ Int namelen =3D VG_(strlen)(name)+1;
+ Int notelen =3D sizeof(struct note) +=20
+ VG_ROUNDUP(namelen, 4) +=20
+ VG_ROUNDUP(datasz, 4);
+ struct note *n =3D VG_(arena_malloc)(VG_AR_CORE, notelen);
+
+ VG_(memset)(n, 0, notelen);
+
+ n->next =3D *list;
+ *list =3D n;
+
+ n->note.n_type =3D type;
+ n->note.n_namesz =3D namelen;
+ n->note.n_descsz =3D datasz;
+
+ VG_(memcpy)(n->name, name, namelen);
+ VG_(memcpy)(n->name+VG_ROUNDUP(namelen,4), data, datasz);
+}
+
+static void write_note(Int fd, const struct note *n)
+{
+ VG_(write)(fd, &n->note, note_size(n));
+}
+
+static void fill_prpsinfo(const ThreadState *tst, struct vki_elf_prpsinf=
o *prpsinfo)
+{
+ static Char name[VKI_PATH_MAX];
+ Bool res;
+
+ VG_(memset)(prpsinfo, 0, sizeof(*prpsinfo));
+
+ switch(tst->status) {
+ case VgTs_Runnable:
+ case VgTs_Yielding:
+ prpsinfo->pr_sname =3D 'R';
+ break;
+
+ case VgTs_WaitSys:
+ prpsinfo->pr_sname =3D 'S';
+ break;
+
+ case VgTs_Zombie:
+ prpsinfo->pr_sname =3D 'Z';
+ break;
+
+ case VgTs_Empty:
+ case VgTs_Init:
+ prpsinfo->pr_sname =3D '?';
+ break;
+ }
+
+ prpsinfo->pr_uid =3D 0;
+ prpsinfo->pr_gid =3D 0;
+ =20
+ if (VG_(resolve_filename)(VG_(clexecfd), name, VKI_PATH_MAX)) {
+ Char *n =3D name+VG_(strlen)(name)-1;
+
+ while (n > name && *n !=3D '/')
+ n--;
+ if (n !=3D name)
+ n++;
+
+ VG_(strncpy)(prpsinfo->pr_fname, n, sizeof(prpsinfo->pr_fname));
+ }
+}
+
+static void fill_prstatus(const ThreadState *tst,=20
+ struct vki_elf_prstatus *prs,=20
+ const vki_siginfo_t *si)
+{
+ struct vki_user_regs_struct *regs;
+
+ VG_(memset)(prs, 0, sizeof(*prs));
+
+ prs->pr_info.si_signo =3D si->si_signo;
+ prs->pr_info.si_code =3D si->si_code;
+ prs->pr_info.si_errno =3D 0;
+
+ prs->pr_cursig =3D si->si_signo;
+
+ prs->pr_pid =3D tst->os_state.lwpid;
+ prs->pr_ppid =3D 0;
+ prs->pr_pgrp =3D VG_(getpgrp)();
+ prs->pr_sid =3D VG_(getpgrp)();
+ =20
+ regs =3D (struct vki_user_regs_struct *)prs->pr_reg;
+
+ vg_assert(sizeof(*regs) =3D=3D sizeof(prs->pr_reg));
+
+ VG_(fill_elfregs_from_tst)(regs, &tst->arch);
+}
+
+static void fill_fpu(const ThreadState *tst, vki_elf_fpregset_t *fpu)
+{
+ VG_(fill_elffpregs_from_tst)(fpu, &tst->arch);
+}
+
+static void fill_xfpu(const ThreadState *tst, vki_elf_fpxregset_t *xfpu)
+{
+ VG_(fill_elffpxregs_from_tst)(xfpu, &tst->arch);
+}
+
+void VG_(make_coredump)(ThreadId tid, const vki_siginfo_t *si, UInt max_=
size)
+{
+ Char buf[1000];
+ Char *basename =3D "vgcore";
+ Char *coreext =3D "";
+ Int seq =3D 0;
+ Int core_fd;
+ Segment *seg;
+ Elf32_Ehdr ehdr;
+ Elf32_Phdr *phdrs;
+ Int num_phdrs;
+ Int i, idx;
+ UInt off;
+ struct note *notelist, *note;
+ UInt notesz;
+ struct vki_elf_prpsinfo prpsinfo;
+ struct vki_elf_prstatus prstatus;
+
+ if (VG_(clo_log_name) !=3D NULL) {
+ coreext =3D ".core";
+ basename =3D VG_(clo_log_name);
+ }
+
+ for(;;) {
+ if (seq =3D=3D 0)
+ VG_(sprintf)(buf, "%s%s.pid%d",
+ basename, coreext, VG_(getpid)());
+ else
+ VG_(sprintf)(buf, "%s%s.pid%d.%d",
+ basename, coreext, VG_(getpid)(), seq);
+ seq++;
+
+ core_fd =3D VG_(open)(buf, =20
+ VKI_O_CREAT|VKI_O_WRONLY|VKI_O_EXCL|VKI_O_TRUNC,=20
+ VKI_S_IRUSR|VKI_S_IWUSR);
+ if (core_fd >=3D 0)
+ break;
+
+ if (core_fd !=3D -VKI_EEXIST)
+ return; /* can't create file */
+ }
+
+ /* First, count how many memory segments to dump */
+ num_phdrs =3D 1; /* start with notes */
+ for(seg =3D VG_(first_segment)();
+ seg !=3D NULL;
+ seg =3D VG_(next_segment)(seg)) {
+ if (!may_dump(seg))
+ continue;
+
+ num_phdrs++;
+ }
+
+ fill_ehdr(&ehdr, num_phdrs);
+
+ notelist =3D NULL;
+
+ /* Second, work out their layout */
+ phdrs =3D VG_(arena_malloc)(VG_AR_CORE, sizeof(*phdrs) * num_phdrs);
+
+ for(i =3D 1; i < VG_N_THREADS; i++) {
+ vki_elf_fpregset_t fpu;
+ vki_elf_fpxregset_t xfpu;
+
+ if (VG_(threads)[i].status =3D=3D VgTs_Empty)
+ continue;
+
+ fill_xfpu(&VG_(threads)[i], &xfpu);
+ add_note(¬elist, "LINUX", NT_PRXFPREG, &xfpu, sizeof(xfpu));
+
+ fill_fpu(&VG_(threads)[i], &fpu);
+ add_note(¬elist, "CORE", NT_FPREGSET, &fpu, sizeof(fpu));
+
+ fill_prstatus(&VG_(threads)[i], &prstatus, si);
+ add_note(¬elist, "CORE", NT_PRSTATUS, &prstatus, sizeof(prstatu=
s));
+ }
+
+ fill_prpsinfo(&VG_(threads)[tid], &prpsinfo);
+ add_note(¬elist, "CORE", NT_PRPSINFO, &prpsinfo, sizeof(prpsinfo))=
;
+
+ for(note =3D notelist, notesz =3D 0; note !=3D NULL; note =3D note->n=
ext)
+ notesz +=3D note_size(note);
+
+ off =3D sizeof(ehdr) + sizeof(*phdrs) * num_phdrs;
+
+ phdrs[0].p_type =3D PT_NOTE;
+ phdrs[0].p_offset =3D off;
+ phdrs[0].p_vaddr =3D 0;
+ phdrs[0].p_paddr =3D 0;
+ phdrs[0].p_filesz =3D notesz;
+ phdrs[0].p_memsz =3D 0;
+ phdrs[0].p_flags =3D 0;
+ phdrs[0].p_align =3D 0;
+
+ off +=3D notesz;
+
+ off =3D VG_PGROUNDUP(off);
+
+ for(seg =3D VG_(first_segment)(), idx =3D 1;
+ seg !=3D NULL;
+ seg =3D VG_(next_segment)(seg)) {
+ if (!may_dump(seg))
+ continue;
+
+ fill_phdr(&phdrs[idx], seg, off, (seg->len + off) < max_size);
+ =20
+ off +=3D phdrs[idx].p_filesz;
+
+ idx++;
+ }
+
+ /* write everything out */
+ VG_(write)(core_fd, &ehdr, sizeof(ehdr));
+ VG_(write)(core_fd, phdrs, sizeof(*phdrs) * num_phdrs);
+
+ for(note =3D notelist; note !=3D NULL; note =3D note->next)
+ write_note(core_fd, note);
+ =20
+ VG_(lseek)(core_fd, phdrs[1].p_offset, VKI_SEEK_SET);
+
+ for(seg =3D VG_(first_segment)(), idx =3D 1;
+ seg !=3D NULL;
+ seg =3D VG_(next_segment)(seg)) {
+ if (!should_dump(seg))
+ continue;
+
+ if (phdrs[idx].p_filesz > 0) {
+ Int ret;
+
+ vg_assert(VG_(lseek)(core_fd, phdrs[idx].p_offset, VKI_SEEK_SET) =3D=3D=
phdrs[idx].p_offset);
+ vg_assert(seg->len >=3D phdrs[idx].p_filesz);
+
+ ret =3D VG_(write)(core_fd, (void *)seg->addr, phdrs[idx].p_filesz);
+ }
+ idx++;
+ }
+
+ VG_(close)(core_fd);
+}
+#endif
+
+void VG_(make_coredump)(ThreadId tid, const vki_siginfo_t *si, UInt max_=
size)
+{
+ I_die_here;
+}
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
Modified: trunk/coregrind/m_signals.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_signals.c 2005-08-27 19:35:42 UTC (rev 4544)
+++ trunk/coregrind/m_signals.c 2005-08-28 04:38:12 UTC (rev 4545)
@@ -81,6 +81,7 @@
=20
#include "pub_core_basics.h"
#include "pub_core_threadstate.h"
+#include "pub_core_coredump.h"
#include "pub_core_debuginfo.h" // Needed for pub_core_aspacemgr :(
#include "pub_core_aspacemgr.h"
#include "pub_core_debugger.h" // For VG_(start_debugger)
@@ -908,340 +909,6 @@
VG_(sigprocmask)(VKI_SIG_SETMASK, &origmask, NULL);
}
=20
-// Core dumping is disabled until someone can work out how to abstract o=
ut
-// the arch-specific and word-size-specific parts neatly.
-//
-// Note that the code below is not 64-bit clean!
-//
-#if 0
-/*
- Dump core
- =20
- Generate a standard ELF core file corresponding to the client state
- at the time of a crash.
- */
-#include <elf.h>
-#ifndef NT_PRXFPREG
-#define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/el=
f/common.h */
-#endif /* NT_PRXFPREG */
-
-/* If true, then this Segment may be mentioned in the core */
-static Bool may_dump(const Segment *seg)
-{
- return (seg->flags & (SF_DEVICE|SF_VALGRIND)) =3D=3D 0 && VG_(is_clie=
nt_addr)(seg->addr);
-}
-
-/* If true, then this Segment's contents will be in the core */
-static Bool should_dump(const Segment *seg)
-{
- return may_dump(seg); // && (seg->prot & VKI_PROT_WRITE);
-}
-
-static void fill_ehdr(Elf32_Ehdr *ehdr, Int num_phdrs)
-{
- VG_(memset)(ehdr, 0, sizeof(*ehdr));
-
- VG_(memcpy)(ehdr->e_ident, ELFMAG, SELFMAG);
- ehdr->e_ident[EI_CLASS] =3D VG_ELF_CLASS;
- ehdr->e_ident[EI_DATA] =3D VG_ELF_ENDIANNESS;
- ehdr->e_ident[EI_VERSION] =3D EV_CURRENT;
-
- ehdr->e_type =3D ET_CORE;
- ehdr->e_machine =3D VG_ELF_MACHINE;
- ehdr->e_version =3D EV_CURRENT;
- ehdr->e_entry =3D 0;
- ehdr->e_phoff =3D sizeof(Elf32_Ehdr);
- ehdr->e_shoff =3D 0;
- ehdr->e_flags =3D 0;
- ehdr->e_ehsize =3D sizeof(Elf32_Ehdr);
- ehdr->e_phentsize =3D sizeof(Elf32_Phdr);
- ehdr->e_phnum =3D num_phdrs;
- ehdr->e_shentsize =3D 0;
- ehdr->e_shnum =3D 0;
- ehdr->e_shstrndx =3D 0;
-
-}
-
-static void fill_phdr(Elf32_Phdr *phdr, const Segment *seg, UInt off, Bo=
ol write)
-{
- write =3D write && should_dump(seg);
-
- VG_(memset)(phdr, 0, sizeof(*phdr));
-
- phdr->p_type =3D PT_LOAD;
- phdr->p_offset =3D off;
- phdr->p_vaddr =3D seg->addr;
- phdr->p_paddr =3D 0;
- phdr->p_filesz =3D write ? seg->len : 0;
- phdr->p_memsz =3D seg->len;
- phdr->p_flags =3D 0;
-
- if (seg->prot & VKI_PROT_READ)
- phdr->p_flags |=3D PF_R;
- if (seg->prot & VKI_PROT_WRITE)
- phdr->p_flags |=3D PF_W;
- if (seg->prot & VKI_PROT_EXEC)
- phdr->p_flags |=3D PF_X;
-
- phdr->p_align =3D VKI_PAGE_SIZE;
-}
-
-struct note {
- struct note *next;
- Elf32_Nhdr note;
- Char name[0];
-};
-
-static UInt note_size(const struct note *n)
-{
- return sizeof(Elf32_Nhdr) + VG_ROUNDUP(VG_(strlen)(n->name)+1, 4) + V=
G_ROUNDUP(n->note.n_descsz, 4);
-}
-
-static void add_note(struct note **list, const Char *name, UInt type, co=
nst void *data, UInt datasz)
-{
- Int namelen =3D VG_(strlen)(name)+1;
- Int notelen =3D sizeof(struct note) +=20
- VG_ROUNDUP(namelen, 4) +=20
- VG_ROUNDUP(datasz, 4);
- struct note *n =3D VG_(arena_malloc)(VG_AR_CORE, notelen);
-
- VG_(memset)(n, 0, notelen);
-
- n->next =3D *list;
- *list =3D n;
-
- n->note.n_type =3D type;
- n->note.n_namesz =3D namelen;
- n->note.n_descsz =3D datasz;
-
- VG_(memcpy)(n->name, name, namelen);
- VG_(memcpy)(n->name+VG_ROUNDUP(namelen,4), data, datasz);
-}
-
-static void write_note(Int fd, const struct note *n)
-{
- VG_(write)(fd, &n->note, note_size(n));
-}
-
-static void fill_prpsinfo(const ThreadState *tst, struct vki_elf_prpsinf=
o *prpsinfo)
-{
- static Char name[VKI_PATH_MAX];
- Bool res;
-
- VG_(memset)(prpsinfo, 0, sizeof(*prpsinfo));
-
- switch(tst->status) {
- case VgTs_Runnable:
- case VgTs_Yielding:
- prpsinfo->pr_sname =3D 'R';
- break;
-
- case VgTs_WaitSys:
- prpsinfo->pr_sname =3D 'S';
- break;
-
- case VgTs_Zombie:
- prpsinfo->pr_sname =3D 'Z';
- break;
-
- case VgTs_Empty:
- case VgTs_Init:
- prpsinfo->pr_sname =3D '?';
- break;
- }
-
- prpsinfo->pr_uid =3D 0;
- prpsinfo->pr_gid =3D 0;
- =20
- if (VG_(resolve_filename)(VG_(clexecfd), name, VKI_PATH_MAX)) {
- Char *n =3D name+VG_(strlen)(name)-1;
-
- while (n > name && *n !=3D '/')
- n--;
- if (n !=3D name)
- n++;
-
- VG_(strncpy)(prpsinfo->pr_fname, n, sizeof(prpsinfo->pr_fname));
- }
-}
-
-static void fill_prstatus(const ThreadState *tst,=20
- struct vki_elf_prstatus *prs,=20
- const vki_siginfo_t *si)
-{
- struct vki_user_regs_struct *regs;
-
- VG_(memset)(prs, 0, sizeof(*prs));
-
- prs->pr_info.si_signo =3D si->si_signo;
- prs->pr_info.si_code =3D si->si_code;
- prs->pr_info.si_errno =3D 0;
-
- prs->pr_cursig =3D si->si_signo;
-
- prs->pr_pid =3D tst->os_state.lwpid;
- prs->pr_ppid =3D 0;
- prs->pr_pgrp =3D VG_(getpgrp)();
- prs->pr_sid =3D VG_(getpgrp)();
- =20
- regs =3D (struct vki_user_regs_struct *)prs->pr_reg;
-
- vg_assert(sizeof(*regs) =3D=3D sizeof(prs->pr_reg));
-
- VG_(fill_elfregs_from_tst)(regs, &tst->arch);
-}
-
-static void fill_fpu(const ThreadState *tst, vki_elf_fpregset_t *fpu)
-{
- VG_(fill_elffpregs_from_tst)(fpu, &tst->arch);
-}
-
-static void fill_xfpu(const ThreadState *tst, vki_elf_fpxregset_t *xfpu)
-{
- VG_(fill_elffpxregs_from_tst)(xfpu, &tst->arch);
-}
-
-static void make_coredump(ThreadId tid, const vki_siginfo_t *si, UInt ma=
x_size)
-{
- Char buf[1000];
- Char *basename =3D "vgcore";
- Char *coreext =3D "";
- Int seq =3D 0;
- Int core_fd;
- Segment *seg;
- Elf32_Ehdr ehdr;
- Elf32_Phdr *phdrs;
- Int num_phdrs;
- Int i, idx;
- UInt off;
- struct note *notelist, *note;
- UInt notesz;
- struct vki_elf_prpsinfo prpsinfo;
- struct vki_elf_prstatus prstatus;
-
- if (VG_(clo_log_name) !=3D NULL) {
- coreext =3D ".core";
- basename =3D VG_(clo_log_name);
- }
-
- for(;;) {
- if (seq =3D=3D 0)
- VG_(sprintf)(buf, "%s%s.pid%d",
- basename, coreext, VG_(getpid)());
- else
- VG_(sprintf)(buf, "%s%s.pid%d.%d",
- basename, coreext, VG_(getpid)(), seq);
- seq++;
-
- core_fd =3D VG_(open)(buf, =20
- VKI_O_CREAT|VKI_O_WRONLY|VKI_O_EXCL|VKI_O_TRUNC,=20
- VKI_S_IRUSR|VKI_S_IWUSR);
- if (core_fd >=3D 0)
- break;
-
- if (core_fd !=3D -VKI_EEXIST)
- return; /* can't create file */
- }
-
- /* First, count how many memory segments to dump */
- num_phdrs =3D 1; /* start with notes */
- for(seg =3D VG_(first_segment)();
- seg !=3D NULL;
- seg =3D VG_(next_segment)(seg)) {
- if (!may_dump(seg))
- continue;
-
- num_phdrs++;
- }
-
- fill_ehdr(&ehdr, num_phdrs);
-
- notelist =3D NULL;
-
- /* Second, work out their layout */
- phdrs =3D VG_(arena_malloc)(VG_AR_CORE, sizeof(*phdrs) * num_phdrs);
-
- for(i =3D 1; i < VG_N_THREADS; i++) {
- vki_elf_fpregset_t fpu;
- vki_elf_fpxregset_t xfpu;
-
- if (VG_(threads)[i].status =3D=3D VgTs_Empty)
- continue;
-
- fill_xfpu(&VG_(threads)[i], &xfpu);
- add_note(¬elist, "LINUX", NT_PRXFPREG, &xfpu, sizeof(xfpu));
-
- fill_fpu(&VG_(threads)[i], &fpu);
- add_note(¬elist, "CORE", NT_FPREGSET, &fpu, sizeof(fpu));
-
- fill_prstatus(&VG_(threads)[i], &prstatus, si);
- add_note(¬elist, "CORE", NT_PRSTATUS, &prstatus, sizeof(prstatu=
s));
- }
-
- fill_prpsinfo(&VG_(threads)[tid], &prpsinfo);
- add_note(¬elist, "CORE", NT_PRPSINFO, &prpsinfo, sizeof(prpsinfo))=
;
-
- for(note =3D notelist, notesz =3D 0; note !=3D NULL; note =3D note->n=
ext)
- notesz +=3D note_size(note);
-
- off =3D sizeof(ehdr) + sizeof(*phdrs) * num_phdrs;
-
- phdrs[0].p_type =3D PT_NOTE;
- phdrs[0].p_offset =3D off;
- phdrs[0].p_vaddr =3D 0;
- phdrs[0].p_paddr =3D 0;
- phdrs[0].p_filesz =3D notesz;
- phdrs[0].p_memsz =3D 0;
- phdrs[0].p_flags =3D 0;
- phdrs[0].p_align =3D 0;
-
- off +=3D notesz;
-
- off =3D VG_PGROUNDUP(off);
-
- for(seg =3D VG_(first_segment)(), idx =3D 1;
- seg !=3D NULL;
- seg =3D VG_(next_segment)(seg)) {
- if (!may_dump(seg))
- continue;
-
- fill_phdr(&phdrs[idx], seg, off, (seg->len + off) < max_size);
- =20
- off +=3D phdrs[idx].p_filesz;
-
- idx++;
- }
-
- /* write everything out */
- VG_(write)(core_fd, &ehdr, sizeof(ehdr));
- VG_(write)(core_fd, phdrs, sizeof(*phdrs) * num_phdrs);
-
- for(note =3D notelist; note !=3D NULL; note =3D note->next)
- write_note(core_fd, note);
- =20
- VG_(lseek)(core_fd, phdrs[1].p_offset, VKI_SEEK_SET);
-
- for(seg =3D VG_(first_segment)(), idx =3D 1;
- seg !=3D NULL;
- seg =3D VG_(next_segment)(seg)) {
- if (!should_dump(seg))
- continue;
-
- if (phdrs[idx].p_filesz > 0) {
- Int ret;
-
- vg_assert(VG_(lseek)(core_fd, phdrs[idx].p_offset, VKI_SEEK_SET) =3D=3D=
phdrs[idx].p_offset);
- vg_assert(seg->len >=3D phdrs[idx].p_filesz);
-
- ret =3D VG_(write)(core_fd, (void *)seg->addr, phdrs[idx].p_filesz);
- }
- idx++;
- }
-
- VG_(close)(core_fd);
-}
-#endif
-
/*=20
Perform the default action of a signal. If the signal is fatal, it
marks all threads as needing to exit, but it doesn't actually kill
@@ -1401,7 +1068,7 @@
if (core) {
const static struct vki_rlimit zero =3D { 0, 0 };
=20
- make_coredump(tid, info, corelim.rlim_cur);
+ VG_(make_coredump)(tid, info, corelim.rlim_cur);
=20
/* Make sure we don't get a confusing kernel-generated
coredump when we finally exit */
Added: trunk/coregrind/pub_core_coredump.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/pub_core_coredump.h 2005-08-27 19:35:42 UTC (rev 4544=
)
+++ trunk/coregrind/pub_core_coredump.h 2005-08-28 04:38:12 UTC (rev 4545=
)
@@ -0,0 +1,45 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Dumping core. pub_core_coredump.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ js...@ac...
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_COREDUMP_H
+#define __PUB_CORE_COREDUMP_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module produces a core dump when asked.
+//--------------------------------------------------------------------
+
+extern void VG_(make_coredump) ( ThreadId tid, const vki_siginfo_t *si,
+ UInt max_size );
+
+#endif // __PUB_CORE_COREDUMP_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
|