* gdbarch.sh (static_transform_name): New gdbarch callback.
[deliverable/binutils-gdb.git] / gdb / i386-sol2-tdep.c
CommitLineData
8201327c 1/* Target-dependent code for Solaris x86.
911bc6ee 2
6aba47ca 3 Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
8201327c
MK
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
8201327c
MK
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8201327c
MK
19
20#include "defs.h"
52e9098c 21#include "value.h"
4be87837 22#include "osabi.h"
8201327c 23
d9f8c85b
MK
24#include "gdb_string.h"
25
081bf9da 26#include "sol2-tdep.h"
8201327c 27#include "i386-tdep.h"
75f501b5 28#include "solib-svr4.h"
8201327c 29
6a9756ed
MK
30/* From <ia32/sys/reg.h>. */
31static int i386_sol2_gregset_reg_offset[] =
32{
33 11 * 4, /* %eax */
34 10 * 4, /* %ecx */
35 9 * 4, /* %edx */
36 8 * 4, /* %ebx */
37 17 * 4, /* %esp */
38 6 * 4, /* %ebp */
39 5 * 4, /* %esi */
40 4 * 4, /* %edi */
41 14 * 4, /* %eip */
42 16 * 4, /* %eflags */
43 15 * 4, /* %cs */
44 18 * 4, /* %ss */
45 3 * 4, /* %ds */
46 2 * 4, /* %es */
47 1 * 4, /* %fs */
48 0 * 4 /* %gs */
49};
50
d9f8c85b
MK
51/* Return whether the frame preceding NEXT_FRAME corresponds to a
52 Solaris sigtramp routine. */
53
8201327c 54static int
911bc6ee 55i386_sol2_sigtramp_p (struct frame_info *next_frame)
8201327c 56{
911bc6ee 57 CORE_ADDR pc = frame_pc_unwind (next_frame);
d9f8c85b 58 char *name;
911bc6ee 59
d9f8c85b
MK
60 find_pc_partial_function (pc, &name, NULL, NULL);
61 return (name && (strcmp ("sigacthandler", name) == 0
62 || strcmp (name, "ucbsigvechandler") == 0));
8201327c
MK
63}
64
8349554d
MK
65/* Solaris doesn't have a `struct sigcontext', but it does have a
66 `mcontext_t' that contains the saved set of machine registers. */
67
68static CORE_ADDR
69i386_sol2_mcontext_addr (struct frame_info *next_frame)
70{
71 CORE_ADDR sp, ucontext_addr;
72
73 sp = frame_unwind_register_unsigned (next_frame, I386_ESP_REGNUM);
74 ucontext_addr = get_frame_memory_unsigned (next_frame, sp + 8, 4);
75
76 return ucontext_addr + 36;
77}
78
149ad273
UW
79/* SunPRO encodes the static variables. This is not related to C++
80 mangling, it is done for C too. */
81
82static char *
83i386_sol2_static_transform_name (char *name)
84{
85 char *p;
86 if (name[0] == '.')
87 {
88 /* For file-local statics there will be a period, a bunch of
89 junk (the contents of which match a string given in the
90 N_OPT), a period and the name. For function-local statics
91 there will be a bunch of junk (which seems to change the
92 second character from 'A' to 'B'), a period, the name of the
93 function, and the name. So just skip everything before the
94 last period. */
95 p = strrchr (name, '.');
96 if (p != NULL)
97 name = p + 1;
98 }
99 return name;
100}
101
8201327c
MK
102/* Solaris 2. */
103
104static void
105i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
106{
107 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
108
109 /* Solaris is SVR4-based. */
110 i386_svr4_init_abi (info, gdbarch);
111
149ad273
UW
112 /* Handle SunPRO encoding of static symbols. */
113 set_gdbarch_static_transform_name (gdbarch, i386_sol2_static_transform_name);
114
6a9756ed
MK
115 /* Solaris reserves space for its FPU emulator in `fpregset_t'.
116 There is also some space reserved for the registers of a Weitek
117 math coprocessor. */
118 tdep->gregset_reg_offset = i386_sol2_gregset_reg_offset;
119 tdep->gregset_num_regs = ARRAY_SIZE (i386_sol2_gregset_reg_offset);
120 tdep->sizeof_gregset = 19 * 4;
121 tdep->sizeof_fpregset = 380;
122
911bc6ee
MK
123 /* Signal trampolines are slightly different from SVR4. */
124 tdep->sigtramp_p = i386_sol2_sigtramp_p;
8349554d
MK
125 tdep->sigcontext_addr = i386_sol2_mcontext_addr;
126 tdep->sc_reg_offset = tdep->gregset_reg_offset;
127 tdep->sc_num_regs = tdep->gregset_num_regs;
75f501b5 128
081bf9da
MK
129 /* Solaris has SVR4-style shared libraries. */
130 set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver);
75f501b5
MK
131 set_solib_svr4_fetch_link_map_offsets
132 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
8201327c
MK
133}
134\f
135
6e157172
MK
136static enum gdb_osabi
137i386_sol2_osabi_sniffer (bfd *abfd)
138{
139 /* If we have a section named .SUNW_version, then it is almost
140 certainly Solaris 2. */
141 if (bfd_get_section_by_name (abfd, ".SUNW_version"))
142 return GDB_OSABI_SOLARIS;
143
144 return GDB_OSABI_UNKNOWN;
145}
146
8201327c
MK
147/* Provide a prototype to silence -Wmissing-prototypes. */
148void _initialize_i386_sol2_tdep (void);
149
150void
151_initialize_i386_sol2_tdep (void)
152{
0c52bd59 153 /* Register an ELF OS ABI sniffer for Solaris 2 binaries. */
6e157172
MK
154 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
155 i386_sol2_osabi_sniffer);
156
05816f70 157 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SOLARIS,
8201327c
MK
158 i386_sol2_init_abi);
159}
This page took 0.505867 seconds and 4 git commands to generate.