This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PRELIM/RFC] Creating corefile note sections for gdb
- From: Michael Snyder <msnyder at cygnus dot com>
- To: binutils at sources dot redhat dot com
- Date: Wed, 26 Dec 2001 12:24:26 -0800
- Subject: [PRELIM/RFC] Creating corefile note sections for gdb
The following is very preliminary, not intended for submission
but as an early request for comment and feedback.
The idea is to enable GDB to create a corefile from a running
process. There are already functions exported from elf.c for
reading the .note section(s) from a corefile. I want to add
analogous functions for writing them.
To the best of my current understanding, I can't actually
write the contents of a section, though, until I know how big
the section will be -- so I've written these functions so that
they write their output into a realloc buffer (making it bigger
as needed). The caller will call bfd_set_section_contents
when output to the .note section(s) is finished.
Would something like this be acceptable?
I hope to have something for actual submission in a week or two.
Thanks,
Michael Snyder
2001-12-26 Michael Snyder <msnyder@redhat.com>
Add capability to write corefile note sections, for gdb.
* elf.c (elfcore_write_note): New function.
(elfcore_write_prpsinfo): New function.
(elfcore_write_prstatus): New function.
(elfcore_write_pstatus): New function.
(elfcore_write_prfpreg): New function.
Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.117
diff -c -3 -p -r1.117 elf.c
*** elf.c 2001/12/19 05:16:47 1.117
--- elf.c 2001/12/26 20:14:02
*************** elfcore_grok_netbsd_note (abfd, note)
*** 6485,6490 ****
--- 6485,6621 ----
}
}
/* NOTREACHED */
+ }
+
+ /* Function: elfcore_write_note
+
+ Inputs:
+ buffer to hold note
+ name of note
+ type of note
+ data for note
+ size of data for note
+
+ Return:
+ End of buffer containing note. */
+
+ char *elfcore_write_note (bfd *, char *, int *, char *, int, void *, int);
+
+ char *
+ elfcore_write_note (abfd, buf, bufsiz, name, type, input, size)
+ bfd *abfd;
+ char *buf;
+ int *bufsiz;
+ char *name;
+ int type;
+ void *input;
+ int size;
+ {
+ Elf_External_Note *xnp;
+ int namesz = strlen (name);
+ int newspace = BFD_ALIGN (sizeof (Elf_External_Note) + size + namesz - 1, 4);
+ char *p, *dest;
+
+ p = realloc (buf, *bufsiz + newspace);
+ dest = p + *bufsiz;
+ *bufsiz += newspace;
+ xnp = (Elf_External_Note *) dest;
+ H_PUT_32 (abfd, namesz, xnp->namesz);
+ H_PUT_32 (abfd, size, xnp->descsz);
+ H_PUT_32 (abfd, type, xnp->type);
+ strcpy (xnp->name, name);
+ memcpy (xnp->name + BFD_ALIGN (namesz, 4), input, size);
+ return p;
+ }
+
+ #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
+ char *elfcore_write_prpsinfo (bfd *, char *, int *, char *, char *);
+
+ char *
+ elfcore_write_prpsinfo (abfd, buf, bufsiz, fname, psargs)
+ bfd *abfd;
+ char *buf;
+ int *bufsiz;
+ char *fname;
+ char *psargs;
+ {
+ int note_type;
+ char *note_name = "CORE";
+
+ #if defined (HAVE_PSINFO_T)
+ psinfo_t data;
+ note_type = NT_PSINFO;
+ #else
+ prpsinfo_t data;
+ note_type = NT_PRPSINFO;
+ #endif
+
+ memset (&data, 0, sizeof (data));
+ strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
+ strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
+ return elfcore_write_note (abfd, buf, bufsiz,
+ note_name, note_type, &data, sizeof (data));
+ }
+ #endif /* PSINFO_T or PRPSINFO_T */
+
+ #if defined (HAVE_PRSTATUS_T)
+ char *elfcore_write_prstatus (bfd *, char *, int *, pid_t, int, void *);
+
+ char *
+ elfcore_write_prstatus (abfd, buf, bufsiz, pid, cursig, gregs)
+ bfd *abfd;
+ char *buf;
+ int *bufsiz;
+ pid_t pid;
+ int cursig;
+ void *gregs;
+ {
+ prstatus_t prstat;
+ char *note_name = "CORE";
+
+ memset (&prstat, 0, sizeof (prstat));
+ prstat.pr_pid = pid;
+ prstat.pr_cursig = cursig;
+ memcpy (prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
+ return elfcore_write_note (abfd, buf, bufsiz,
+ note_name, NT_PRSTATUS, &prstat, sizeof (prstat));
+ }
+ #endif /* HAVE_PRSTATUS_T */
+
+ #if defined (HAVE_PSTATUS_T)
+ char *
+ elfcore_write_pstatus (abfd, buf, bufsiz, pid, cursig, gregs)
+ bfd *abfd;
+ char *buf;
+ int *bufsiz;
+ pid_t pid;
+ int cursig;
+ void *gregs;
+ {
+ pstatus_t pstat;
+ char *note_name = "CORE";
+
+ memset (&pstat, 0, sizeof (prstat));
+ pstat.pr_pid = pid;
+ memcpy (pstat.pr_reg, gregs, sizeof (pstat.pr_reg));
+ return elfcore_write_note (abfd, buf, bufsiz,
+ note_name, NT_PSTATUS, &pstat, sizeof (pstat));
+ }
+ #endif /* HAVE_PSTATUS_T */
+
+ char *elfcore_write_prfpreg (bfd *, char *, int *, void *, int);
+
+ char *
+ elfcore_write_prfpreg (abfd, buf, bufsiz, fpregs, size)
+ bfd *abfd;
+ char *buf;
+ int *bufsiz;
+ void *fpregs;
+ int size;
+ {
+ char *note_name = "CORE";
+ return elfcore_write_note (abfd, buf, bufsiz,
+ note_name, NT_FPREGSET, fpregs, size);
}
static boolean