GDB (xrefs)
/tmp/gdb-7.10/gdb/vaxobsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for OpenBSD/vax.
2 
3  Copyright (C) 2005-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 "arch-utils.h"
22 #include "frame.h"
23 #include "frame-unwind.h"
24 #include "osabi.h"
25 #include "symtab.h"
26 #include "trad-frame.h"
27 
28 #include "vax-tdep.h"
29 
30 /* Signal trampolines. */
31 
32 /* Since OpenBSD 3.2, the sigtramp routine is mapped at a random page
33  in virtual memory. The randomness makes it somewhat tricky to
34  detect it, but fortunately we can rely on the fact that the start
35  of the sigtramp routine is page-aligned. We recognize the
36  trampoline by looking for the code that invokes the sigreturn
37  system call. The offset where we can find that code varies from
38  release to release.
39 
40  By the way, the mapping mentioned above is read-only, so you cannot
41  place a breakpoint in the signal trampoline. */
42 
43 /* Default page size. */
44 static const int vaxobsd_page_size = 4096;
45 
46 /* Offset for sigreturn(2). */
47 static const int vaxobsd_sigreturn_offset = 0x11;
48 
49 /* Instruction sequence for sigreturn(2). VAX doesn't have
50  fixed-length instructions so we include the ensuing exit(2) to
51  reduce the chance of spurious matches. */
52 static const gdb_byte vaxobsd_sigreturn[] = {
53  0xbc, 0x8f, 0x67, 0x00, /* chmk $SYS_sigreturn */
54  0xbc, 0x01 /* chmk $SYS_exit */
55 };
56 
57 static int
59  struct frame_info *this_frame,
60  void **this_cache)
61 {
62  CORE_ADDR pc = get_frame_pc (this_frame);
63  CORE_ADDR start_pc = (pc & ~(vaxobsd_page_size - 1));
64  CORE_ADDR sigreturn_addr = start_pc + vaxobsd_sigreturn_offset;
65  gdb_byte *buf;
66  const char *name;
67 
68  find_pc_partial_function (pc, &name, NULL, NULL);
69  if (name)
70  return 0;
71 
72  buf = alloca(sizeof vaxobsd_sigreturn);
73  if (!safe_frame_unwind_memory (this_frame, sigreturn_addr,
74  buf, sizeof vaxobsd_sigreturn))
75  return 0;
76 
77  if (memcmp(buf, vaxobsd_sigreturn, sizeof vaxobsd_sigreturn) == 0)
78  return 1;
79 
80  return 0;
81 }
82 
83 static struct trad_frame_cache *
85 {
86  struct trad_frame_cache *cache;
87  CORE_ADDR addr, base, func;
88 
89  if (*this_cache)
90  return *this_cache;
91 
92  cache = trad_frame_cache_zalloc (this_frame);
93  *this_cache = cache;
94 
95  func = get_frame_pc (this_frame);
96  func &= ~(vaxobsd_page_size - 1);
97 
98  base = get_frame_register_unsigned (this_frame, VAX_SP_REGNUM);
99  addr = get_frame_memory_unsigned (this_frame, base - 4, 4);
100 
101  trad_frame_set_reg_addr (cache, VAX_SP_REGNUM, addr + 8);
102  trad_frame_set_reg_addr (cache, VAX_FP_REGNUM, addr + 12);
103  trad_frame_set_reg_addr (cache, VAX_AP_REGNUM, addr + 16);
104  trad_frame_set_reg_addr (cache, VAX_PC_REGNUM, addr + 20);
105  trad_frame_set_reg_addr (cache, VAX_PS_REGNUM, addr + 24);
106 
107  /* Construct the frame ID using the function start. */
108  trad_frame_set_id (cache, frame_id_build (base, func));
109 
110  return cache;
111 }
112 
113 static void
115  void **this_cache, struct frame_id *this_id)
116 {
117  struct trad_frame_cache *cache =
118  vaxobsd_sigtramp_frame_cache (this_frame, this_cache);
119 
120  trad_frame_get_id (cache, this_id);
121 }
122 
123 static struct value *
125  void **this_cache, int regnum)
126 {
127  struct trad_frame_cache *cache =
128  vaxobsd_sigtramp_frame_cache (this_frame, this_cache);
129 
130  return trad_frame_get_register (cache, this_frame, regnum);
131 }
132 
133 static const struct frame_unwind vaxobsd_sigtramp_frame_unwind = {
138  NULL,
140 };
141 
142 
143 /* OpenBSD a.out. */
144 
145 static void
147 {
148  frame_unwind_append_unwinder (gdbarch, &vaxobsd_sigtramp_frame_unwind);
149 }
150 
151 /* FIXME: kettenis/20050821: Since OpenBSD/vax binaries are
152  indistingushable from NetBSD/vax a.out binaries, building a GDB
153  that should support both these targets will probably not work as
154  expected. */
155 #define GDB_OSABI_OPENBSD_AOUT GDB_OSABI_NETBSD_AOUT
156 
157 static enum gdb_osabi
159 {
160  if (strcmp (bfd_get_target (abfd), "a.out-vax-netbsd") == 0)
161  return GDB_OSABI_OPENBSD_AOUT;
162 
163  return GDB_OSABI_UNKNOWN;
164 }
165 
166 
167 /* Provide a prototype to silence -Wmissing-prototypes. */
168 void _initialize_vaxobsd_tdep (void);
169 
170 void
172 {
173  gdbarch_register_osabi_sniffer (bfd_arch_vax, bfd_target_aout_flavour,
175 
178 }
void trad_frame_set_reg_addr(struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr)
Definition: trad-frame.c:119
static int vaxobsd_sigtramp_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **this_cache)
Definition: vaxobsd-tdep.c:58
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:554
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2217
bfd_vma CORE_ADDR
Definition: common-types.h:41
void(* func)(char *)
static struct value * vaxobsd_sigtramp_frame_prev_register(struct frame_info *this_frame, void **this_cache, int regnum)
Definition: vaxobsd-tdep.c:124
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition: trad-frame.c:164
static struct trad_frame_cache * vaxobsd_sigtramp_frame_cache(struct frame_info *this_frame, void **this_cache)
Definition: vaxobsd-tdep.c:84
void gdbarch_register_osabi_sniffer(enum bfd_architecture arch, enum bfd_flavour flavour, enum gdb_osabi(*sniffer_fn)(bfd *))
Definition: osabi.c:225
static const gdb_byte vaxobsd_sigreturn[]
Definition: vaxobsd-tdep.c:52
ULONGEST get_frame_memory_unsigned(struct frame_info *this_frame, CORE_ADDR addr, int len)
Definition: frame.c:2515
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
Definition: frame-unwind.c:78
static const int vaxobsd_page_size
Definition: vaxobsd-tdep.c:44
static const int vaxobsd_sigreturn_offset
Definition: vaxobsd-tdep.c:47
void trad_frame_get_id(struct trad_frame_cache *this_trad_cache, struct frame_id *this_id)
Definition: trad-frame.c:171
const char *const name
Definition: aarch64-tdep.c:68
int safe_frame_unwind_memory(struct frame_info *this_frame, CORE_ADDR addr, gdb_byte *buf, int len)
Definition: frame.c:2525
int find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr)
Definition: blockframe.c:321
struct trad_frame_cache * trad_frame_cache_zalloc(struct frame_info *this_frame)
Definition: trad-frame.c:36
int regnum
Definition: aarch64-tdep.c:69
ULONGEST get_frame_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1194
struct frame_info * this_frame
Definition: trad-frame.c:29
void _initialize_vaxobsd_tdep(void)
Definition: vaxobsd-tdep.c:171
Definition: value.c:172
struct frame_id this_id
Definition: trad-frame.c:32
#define GDB_OSABI_OPENBSD_AOUT
Definition: vaxobsd-tdep.c:155
bfd_byte gdb_byte
Definition: common-types.h:38
static enum gdb_osabi vaxobsd_aout_osabi_sniffer(bfd *abfd)
Definition: vaxobsd-tdep.c:158
enum unwind_stop_reason default_frame_unwind_stop_reason(struct frame_info *this_frame, void **this_cache)
Definition: frame-unwind.c:180
static void vaxobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: vaxobsd-tdep.c:146
static void vaxobsd_sigtramp_frame_this_id(struct frame_info *this_frame, void **this_cache, struct frame_id *this_id)
Definition: vaxobsd-tdep.c:114
struct value * trad_frame_get_register(struct trad_frame_cache *this_trad_cache, struct frame_info *this_frame, int regnum)
Definition: trad-frame.c:155
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition: osabi.c:148
gdb_osabi
Definition: defs.h:540