aboutsummaryrefslogtreecommitdiff
path: root/gdb/nbsd-tdep.c
blob: 1d7230feef84dd2bfc21f448579bc94d31a907e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/* Common target-dependent code for NetBSD systems.

   Copyright (C) 2002-2020 Free Software Foundation, Inc.

   Contributed by Wasabi Systems, Inc.
  
   This file is part of GDB.
  
   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 3 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, see <http://www.gnu.org/licenses/>.  */

#include "defs.h"
#include "solib-svr4.h"
#include "nbsd-tdep.h"
#include "gdbarch.h"
#include "objfiles.h"

/* FIXME: kettenis/20060115: We should really eliminate the next two
   functions completely.  */

struct link_map_offsets *
nbsd_ilp32_solib_svr4_fetch_link_map_offsets (void)
{
  return svr4_ilp32_fetch_link_map_offsets ();
}

struct link_map_offsets *
nbsd_lp64_solib_svr4_fetch_link_map_offsets (void)
{
  return svr4_lp64_fetch_link_map_offsets ();
}

int
nbsd_pc_in_sigtramp (CORE_ADDR pc, const char *func_name)
{
  /* Check for libc-provided signal trampoline.  All such trampolines
     have function names which begin with "__sigtramp".  */

  return (func_name != NULL
	  && startswith (func_name, "__sigtramp"));
}

/* This enum is derived from NETBSD's <sys/signal.h>.  */

enum
  {
   NBSD_SIGHUP = 1,
   NBSD_SIGINT = 2,
   NBSD_SIGQUIT = 3,
   NBSD_SIGILL = 4,
   NBSD_SIGTRAP = 5,
   NBSD_SIGABRT = 6,
   NBSD_SIGEMT = 7,
   NBSD_SIGFPE = 8,
   NBSD_SIGKILL = 9,
   NBSD_SIGBUS = 10,
   NBSD_SIGSEGV = 11,
   NBSD_SIGSYS = 12,
   NBSD_SIGPIPE = 13,
   NBSD_SIGALRM = 14,
   NBSD_SIGTERM = 15,
   NBSD_SIGURG = 16,
   NBSD_SIGSTOP = 17,
   NBSD_SIGTSTP = 18,
   NBSD_SIGCONT = 19,
   NBSD_SIGCHLD = 20,
   NBSD_SIGTTIN = 21,
   NBSD_SIGTTOU = 22,
   NBSD_SIGIO = 23,
   NBSD_SIGXCPU = 24,
   NBSD_SIGXFSZ = 25,
   NBSD_SIGVTALRM = 26,
   NBSD_SIGPROF = 27,
   NBSD_SIGWINCH = 28,
   NBSD_SIGINFO = 29,
   NBSD_SIGUSR1 = 30,
   NBSD_SIGUSR2 = 31,
   NBSD_SIGPWR = 32,
   NBSD_SIGRTMIN = 33,
   NBSD_SIGRTMAX = 63,
  };

/* Implement the "gdb_signal_from_target" gdbarch method.  */

static enum gdb_signal
nbsd_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
{
  switch (signal)
    {
    case 0:
      return GDB_SIGNAL_0;

    case NBSD_SIGHUP:
      return GDB_SIGNAL_HUP;

    case NBSD_SIGINT:
      return GDB_SIGNAL_INT;

    case NBSD_SIGQUIT:
      return GDB_SIGNAL_QUIT;

    case NBSD_SIGILL:
      return GDB_SIGNAL_ILL;

    case NBSD_SIGTRAP:
      return GDB_SIGNAL_TRAP;

    case NBSD_SIGABRT:
      return GDB_SIGNAL_ABRT;

    case NBSD_SIGEMT:
      return GDB_SIGNAL_EMT;

    case NBSD_SIGFPE:
      return GDB_SIGNAL_FPE;

    case NBSD_SIGKILL:
      return GDB_SIGNAL_KILL;

    case NBSD_SIGBUS:
      return GDB_SIGNAL_BUS;

    case NBSD_SIGSEGV:
      return GDB_SIGNAL_SEGV;

    case NBSD_SIGSYS:
      return GDB_SIGNAL_SYS;

    case NBSD_SIGPIPE:
      return GDB_SIGNAL_PIPE;

    case NBSD_SIGALRM:
      return GDB_SIGNAL_ALRM;

    case NBSD_SIGTERM:
      return GDB_SIGNAL_TERM;

    case NBSD_SIGURG:
      return GDB_SIGNAL_URG;

    case NBSD_SIGSTOP:
      return GDB_SIGNAL_STOP;

    case NBSD_SIGTSTP:
      return GDB_SIGNAL_TSTP;

    case NBSD_SIGCONT:
      return GDB_SIGNAL_CONT;

    case NBSD_SIGCHLD:
      return GDB_SIGNAL_CHLD;

    case NBSD_SIGTTIN:
      return GDB_SIGNAL_TTIN;

    case NBSD_SIGTTOU:
      return GDB_SIGNAL_TTOU;

    case NBSD_SIGIO:
      return GDB_SIGNAL_IO;

    case NBSD_SIGXCPU:
      return GDB_SIGNAL_XCPU;

    case NBSD_SIGXFSZ:
      return GDB_SIGNAL_XFSZ;

    case NBSD_SIGVTALRM:
      return GDB_SIGNAL_VTALRM;

    case NBSD_SIGPROF:
      return GDB_SIGNAL_PROF;

    case NBSD_SIGWINCH:
      return GDB_SIGNAL_WINCH;

    case NBSD_SIGINFO:
      return GDB_SIGNAL_INFO;

    case NBSD_SIGUSR1:
      return GDB_SIGNAL_USR1;

    case NBSD_SIGUSR2:
      return GDB_SIGNAL_USR2;

    case NBSD_SIGPWR:
      return GDB_SIGNAL_PWR;

    /* SIGRTMIN and SIGRTMAX are not continuous in <gdb/signals.def>,
       therefore we have to handle them here.  */
    case NBSD_SIGRTMIN:
      return GDB_SIGNAL_REALTIME_33;

    case NBSD_SIGRTMAX:
      return GDB_SIGNAL_REALTIME_63;
    }

  if (signal >= NBSD_SIGRTMIN + 1 && signal <= NBSD_SIGRTMAX - 1)
    {
      int offset = signal - NBSD_SIGRTMIN + 1;

      return (enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_34 + offset);
    }

  return GDB_SIGNAL_UNKNOWN;
}

/* Implement the "gdb_signal_to_target" gdbarch method.  */

static int
nbsd_gdb_signal_to_target (struct gdbarch *gdbarch,
                enum gdb_signal signal)
{
  switch (signal)
    {
    case GDB_SIGNAL_0:
      return 0;

    case GDB_SIGNAL_HUP:
      return NBSD_SIGHUP;

    case GDB_SIGNAL_INT:
      return NBSD_SIGINT;

    case GDB_SIGNAL_QUIT:
      return NBSD_SIGQUIT;

    case GDB_SIGNAL_ILL:
      return NBSD_SIGILL;

    case GDB_SIGNAL_TRAP:
      return NBSD_SIGTRAP;

    case GDB_SIGNAL_ABRT:
      return NBSD_SIGABRT;

    case GDB_SIGNAL_EMT:
      return NBSD_SIGEMT;

    case GDB_SIGNAL_FPE:
      return NBSD_SIGFPE;

    case GDB_SIGNAL_KILL:
      return NBSD_SIGKILL;

    case GDB_SIGNAL_BUS:
      return NBSD_SIGBUS;

    case GDB_SIGNAL_SEGV:
      return NBSD_SIGSEGV;

    case GDB_SIGNAL_SYS:
      return NBSD_SIGSYS;

    case GDB_SIGNAL_PIPE:
      return NBSD_SIGPIPE;

    case GDB_SIGNAL_ALRM:
      return NBSD_SIGALRM;

    case GDB_SIGNAL_TERM:
      return NBSD_SIGTERM;

    case GDB_SIGNAL_URG:
      return NBSD_SIGSTOP;

    case GDB_SIGNAL_TSTP:
      return NBSD_SIGTSTP;

    case GDB_SIGNAL_CONT:
      return NBSD_SIGCONT;

    case GDB_SIGNAL_CHLD:
      return NBSD_SIGCHLD;

    case GDB_SIGNAL_TTIN:
      return NBSD_SIGTTIN;

    case GDB_SIGNAL_TTOU:
      return NBSD_SIGTTOU;

    case GDB_SIGNAL_IO:
      return NBSD_SIGIO;

    case GDB_SIGNAL_XCPU:
      return NBSD_SIGXCPU;

    case GDB_SIGNAL_XFSZ:
      return NBSD_SIGXFSZ;

    case GDB_SIGNAL_VTALRM:
      return NBSD_SIGVTALRM;

    case GDB_SIGNAL_PROF:
      return NBSD_SIGPROF;

    case GDB_SIGNAL_WINCH:
      return NBSD_SIGWINCH;

    case GDB_SIGNAL_INFO:
      return NBSD_SIGINFO;

    case GDB_SIGNAL_USR1:
      return NBSD_SIGUSR1;

    case GDB_SIGNAL_USR2:
      return NBSD_SIGUSR2;

    case GDB_SIGNAL_PWR:
      return NBSD_SIGPWR;

    /* GDB_SIGNAL_REALTIME_33 is not continuous in <gdb/signals.def>,
       therefore we have to handle it here.  */
    case GDB_SIGNAL_REALTIME_33:
      return NBSD_SIGRTMIN;

    /* Same comment applies to _64.  */
    case GDB_SIGNAL_REALTIME_63:
      return NBSD_SIGRTMAX;
    }

  if (signal >= GDB_SIGNAL_REALTIME_34
      && signal <= GDB_SIGNAL_REALTIME_62)
    {
      int offset = signal - GDB_SIGNAL_REALTIME_32;

      return NBSD_SIGRTMIN + 1 + offset;
    }

  return -1;
}

/* Shared library resolver handling.  */

static CORE_ADDR
nbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
{
  struct bound_minimal_symbol msym;

  msym = lookup_minimal_symbol ("_rtld_bind_start", NULL, NULL);
  if (msym.minsym && BMSYMBOL_VALUE_ADDRESS (msym) == pc)
    return frame_unwind_caller_pc (get_current_frame ());
  else
    return find_solib_trampoline_target (get_current_frame (), pc);
}

/* See nbsd-tdep.h.  */

void
nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
  set_gdbarch_gdb_signal_from_target (gdbarch, nbsd_gdb_signal_from_target);
  set_gdbarch_gdb_signal_to_target (gdbarch, nbsd_gdb_signal_to_target);
  set_gdbarch_skip_solib_resolver (gdbarch, nbsd_skip_solib_resolver);
}