1 /* Target-dependent code for FreeBSD, architecture-independent.
3 Copyright (C) 2002-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "gdbthread.h"
27 #include "gdb_assert.h"
31 #include "fbsd-tdep.h"
35 find_signalled_thread (struct thread_info *info, void *data)
37 if (info->suspend.stop_signal != GDB_SIGNAL_0
38 && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid))
44 static enum gdb_signal
45 find_stop_signal (void)
47 struct thread_info *info =
48 iterate_over_threads (find_signalled_thread, NULL);
51 return info->suspend.stop_signal;
56 struct fbsd_collect_regset_section_cb_data
58 const struct regcache *regcache;
65 fbsd_collect_regset_section_cb (const char *sect_name, int size,
66 const struct regset *regset,
67 const char *human_name, void *cb_data)
70 struct fbsd_collect_regset_section_cb_data *data = cb_data;
72 gdb_assert (regset->collect_regset);
75 regset->collect_regset (regset, data->regcache, -1, buf, size);
77 /* PRSTATUS still needs to be treated specially. */
78 if (strcmp (sect_name, ".reg") == 0)
79 data->note_data = (char *) elfcore_write_prstatus
80 (data->obfd, data->note_data, data->note_size,
81 ptid_get_pid (inferior_ptid), find_stop_signal (), buf);
83 data->note_data = (char *) elfcore_write_register_note
84 (data->obfd, data->note_data, data->note_size,
85 sect_name, buf, size);
89 /* Create appropriate note sections for a corefile, returning them in
93 fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
95 const struct regcache *regcache = get_current_regcache ();
97 Elf_Internal_Ehdr *i_ehdrp;
98 struct fbsd_collect_regset_section_cb_data data;
100 /* Put a "FreeBSD" label in the ELF header. */
101 i_ehdrp = elf_elfheader (obfd);
102 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
104 gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch));
106 data.regcache = regcache;
108 data.note_data = NULL;
109 data.note_size = note_size;
110 gdbarch_iterate_over_regset_sections (gdbarch,
111 fbsd_collect_regset_section_cb,
113 note_data = data.note_data;
115 if (get_exec_file (0))
117 const char *fname = lbasename (get_exec_file (0));
118 char *psargs = xstrdup (fname);
120 if (get_inferior_args ())
121 psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
124 note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
131 /* To be called from GDB_OSABI_FREEBSD_ELF handlers. */
134 fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
136 set_gdbarch_make_corefile_notes (gdbarch, fbsd_make_corefile_notes);