GDB (xrefs)
/tmp/gdb-7.10/gdb/fbsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for FreeBSD, architecture-independent.
2 
3  Copyright (C) 2002-2015 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
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.
11 
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.
16 
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/>. */
19 
20 #include "defs.h"
21 #include "gdbcore.h"
22 #include "inferior.h"
23 #include "regcache.h"
24 #include "regset.h"
25 #include "gdbthread.h"
26 
27 #include "elf-bfd.h"
28 #include "fbsd-tdep.h"
29 
30 
31 static int
32 find_signalled_thread (struct thread_info *info, void *data)
33 {
34  if (info->suspend.stop_signal != GDB_SIGNAL_0
36  return 1;
37 
38  return 0;
39 }
40 
41 static enum gdb_signal
43 {
44  struct thread_info *info =
46 
47  if (info)
48  return info->suspend.stop_signal;
49  else
50  return GDB_SIGNAL_0;
51 }
52 
54 {
55  const struct regcache *regcache;
56  bfd *obfd;
57  char *note_data;
58  int *note_size;
59 };
60 
61 static void
62 fbsd_collect_regset_section_cb (const char *sect_name, int size,
63  const struct regset *regset,
64  const char *human_name, void *cb_data)
65 {
66  char *buf;
67  struct fbsd_collect_regset_section_cb_data *data = cb_data;
68 
69  gdb_assert (regset->collect_regset);
70 
71  buf = xmalloc (size);
72  regset->collect_regset (regset, data->regcache, -1, buf, size);
73 
74  /* PRSTATUS still needs to be treated specially. */
75  if (strcmp (sect_name, ".reg") == 0)
76  data->note_data = (char *) elfcore_write_prstatus
77  (data->obfd, data->note_data, data->note_size,
79  else
80  data->note_data = (char *) elfcore_write_register_note
81  (data->obfd, data->note_data, data->note_size,
82  sect_name, buf, size);
83  xfree (buf);
84 }
85 
86 /* Create appropriate note sections for a corefile, returning them in
87  allocated memory. */
88 
89 static char *
91 {
93  char *note_data;
94  Elf_Internal_Ehdr *i_ehdrp;
96 
97  /* Put a "FreeBSD" label in the ELF header. */
98  i_ehdrp = elf_elfheader (obfd);
99  i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
100 
102 
103  data.regcache = regcache;
104  data.obfd = obfd;
105  data.note_data = NULL;
106  data.note_size = note_size;
107  target_fetch_registers (regcache, -1);
110  &data, regcache);
111  note_data = data.note_data;
112 
113  if (get_exec_file (0))
114  {
115  const char *fname = lbasename (get_exec_file (0));
116  char *psargs = xstrdup (fname);
117 
118  if (get_inferior_args ())
119  psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
120  (char *) NULL);
121 
122  note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
123  fname, psargs);
124  }
125 
126  return note_data;
127 }
128 
129 /* To be called from GDB_OSABI_FREEBSD_ELF handlers. */
130 
131 void
133 {
135 }
void xfree(void *)
Definition: common-utils.c:97
char * get_inferior_args(void)
Definition: infcmd.c:187
void target_fetch_registers(struct regcache *regcache, int regno)
Definition: target.c:3419
enum gdb_signal stop_signal
Definition: gdbthread.h:159
struct regcache * get_current_regcache(void)
Definition: regcache.c:541
Definition: regset.h:34
struct thread_info * iterate_over_threads(thread_callback_func, void *)
Definition: thread.c:419
int gdbarch_iterate_over_regset_sections_p(struct gdbarch *gdbarch)
Definition: gdbarch.c:3381
static enum gdb_signal find_stop_signal(void)
Definition: fbsd-tdep.c:42
void fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: fbsd-tdep.c:132
#define gdb_assert(expr)
Definition: gdb_assert.h:33
void set_gdbarch_make_corefile_notes(struct gdbarch *gdbarch, gdbarch_make_corefile_notes_ftype make_corefile_notes)
Definition: gdbarch.c:3422
void * xmalloc(YYSIZE_T)
int ptid_get_pid(ptid_t ptid)
Definition: ptid.c:52
static void fbsd_collect_regset_section_cb(const char *sect_name, int size, const struct regset *regset, const char *human_name, void *cb_data)
Definition: fbsd-tdep.c:62
ptid_t ptid
Definition: gdbthread.h:169
ptid_t inferior_ptid
Definition: infcmd.c:124
struct thread_suspend_state suspend
Definition: gdbthread.h:202
const struct regcache * regcache
Definition: fbsd-tdep.c:55
char * get_exec_file(int err)
Definition: corefile.c:179
static int find_signalled_thread(struct thread_info *info, void *data)
Definition: fbsd-tdep.c:32
size_t size
Definition: go32-nat.c:242
void gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
Definition: gdbarch.c:3388
static char * fbsd_make_corefile_notes(struct gdbarch *gdbarch, bfd *obfd, int *note_size)
Definition: fbsd-tdep.c:90
collect_regset_ftype * collect_regset
Definition: regset.h:45