aboutsummaryrefslogtreecommitdiff
path: root/gdb/gcore.h
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-01-18 16:00:38 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2021-02-01 10:35:18 +0000
commit82a1fd3a4935fe665cf08bc6820942c4a091184c (patch)
treee3b60b40dfa329387c96a226dc6c8a585e71ecb7 /gdb/gcore.h
parenta5f92c675662a7ed5353fcd0b23b69fdbd6ecf43 (diff)
downloadbinutils-82a1fd3a4935fe665cf08bc6820942c4a091184c.zip
binutils-82a1fd3a4935fe665cf08bc6820942c4a091184c.tar.gz
binutils-82a1fd3a4935fe665cf08bc6820942c4a091184c.tar.bz2
gdb: unify parts of the Linux and FreeBSD core dumping code
While reviewing the Linux and FreeBSD core dumping code within GDB for another patch series, I noticed that the code that collects the registers for each thread and writes these into ELF note format is basically identical between Linux and FreeBSD. This commit merges this code and moves it into the gcore.c file, which seemed like the right place for generic writing a core file code. The function find_signalled_thread is moved from linux-tdep.c despite not being shared. A later commit will make use of this function. There are a couple of minor changes to the FreeBSD target after this commit, but I believe that these are changes for the better: (1) For FreeBSD we always used to record the thread-id in the core file by using ptid_t.lwp (). In contrast the Linux code did this: /* For remote targets the LWP may not be available, so use the TID. */ long lwp = ptid.lwp (); if (lwp == 0) lwp = ptid.tid (); Both target now do this: /* The LWP is often not available for bare metal target, in which case use the tid instead. */ if (ptid.lwp_p ()) lwp = ptid.lwp (); else lwp = ptid.tid (); Which is equivalent for Linux, but is a change for FreeBSD. I think that all this means is that in some cases where GDB might have previously recorded a thread-id of 0 for each thread, we might now get something more useful. (2) When collecting the registers for Linux we collected into a zero initialised buffer. By contrast on FreeBSD the buffer is left uninitialised. In the new code the buffer is always zero initialised. I suspect once the registers are copied into the buffer there's probably no gaps left so this makes no difference, but if it does then using zeros rather than random bits of GDB's memory is probably a good thing. Otherwise, there should be no other user visible changes after this commit. Tested this on x86-64/GNU-Linux and x86-64/FreeBSD-12.2 with no regressions. gdb/ChangeLog: * Makefile.in (HFILES_NO_SRCDIR): Add corefile.h. * gcore.c (struct gcore_collect_regset_section_cb_data): Moved here from linux-tdep.c and given a new name. Minor cleanups. (gcore_collect_regset_section_cb): Likewise. (gcore_collect_thread_registers): Likewise. (gcore_build_thread_register_notes): Likewise. (gcore_find_signalled_thread): Likewise. * gcore.h (gcore_build_thread_register_notes): Declare. (gcore_find_signalled_thread): Declare. * fbsd-tdep.c: Add 'gcore.h' include. (struct fbsd_collect_regset_section_cb_data): Delete. (fbsd_collect_regset_section_cb): Delete. (fbsd_collect_thread_registers): Delete. (struct fbsd_corefile_thread_data): Delete. (fbsd_corefile_thread): Delete. (fbsd_make_corefile_notes): Call gcore_build_thread_register_notes instead of the now deleted FreeBSD code. * linux-tdep.c: Add 'gcore.h' include. (struct linux_collect_regset_section_cb_data): Delete. (linux_collect_regset_section_cb): Delete. (linux_collect_thread_registers): Delete. (linux_corefile_thread): Call gcore_build_thread_register_notes. (find_signalled_thread): Delete. (linux_make_corefile_notes): Call gcore_find_signalled_thread.
Diffstat (limited to 'gdb/gcore.h')
-rw-r--r--gdb/gcore.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/gdb/gcore.h b/gdb/gcore.h
index af37ff3..ce60841 100644
--- a/gdb/gcore.h
+++ b/gdb/gcore.h
@@ -21,6 +21,10 @@
#define GCORE_H 1
#include "gdb_bfd.h"
+#include "gdbsupport/gdb_signals.h"
+
+struct gdbarch;
+struct thread_info;
extern gdb_bfd_ref_ptr create_gcore_bfd (const char *filename);
extern void write_gcore_file (bfd *obfd);
@@ -28,4 +32,20 @@ extern int objfile_find_memory_regions (struct target_ops *self,
find_memory_region_ftype func,
void *obfd);
+/* Add content to *NOTE_DATA (and update *NOTE_SIZE) to describe the
+ registers of thread INFO. Report the thread as having stopped with
+ STOP_SIGNAL. The core file is being written to OFD, and GDBARCH is the
+ architecture for which the core file is being generated. */
+
+extern void gcore_build_thread_register_notes
+ (struct gdbarch *gdbarch, struct thread_info *info, gdb_signal stop_signal,
+ bfd *obfd, gdb::unique_xmalloc_ptr<char> *note_data, int *note_size);
+
+/* Find the signalled thread. In case there's more than one signalled
+ thread, prefer the current thread, if it is signalled. If no thread was
+ signalled, default to the current thread, unless it has exited, in which
+ case return NULL. */
+
+extern thread_info *gcore_find_signalled_thread ();
+
#endif /* GCORE_H */