Move common handlers to sol2_init_abi
[deliverable/binutils-gdb.git] / gdb / sol2-tdep.c
1 /* Target-dependent code for Solaris.
2
3 Copyright (C) 2006-2020 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 "frame.h"
22 #include "symtab.h"
23 #include "inferior.h"
24 #include "objfiles.h"
25
26 #include "sol2-tdep.h"
27
28 /* The Solaris signal trampolines reside in libc. For normal signals,
29 the function `sigacthandler' is used. This signal trampoline will
30 call the signal handler using the System V calling convention,
31 where the third argument is a pointer to an instance of
32 `ucontext_t', which has a member `uc_mcontext' that contains the
33 saved registers. Incidentally, the kernel passes the `ucontext_t'
34 pointer as the third argument of the signal trampoline too, and
35 `sigacthandler' simply passes it on. However, if you link your
36 program with "-L/usr/ucblib -R/usr/ucblib -lucb", the function
37 `ucbsigvechandler' will be used, which invokes the using the BSD
38 convention, where the third argument is a pointer to an instance of
39 `struct sigcontext'. It is the `ucbsigvechandler' function that
40 converts the `ucontext_t' to a `sigcontext', and back. Unless the
41 signal handler modifies the `struct sigcontext' we can safely
42 ignore this. */
43
44 static int
45 sol2_pc_in_sigtramp (CORE_ADDR pc, const char *name)
46 {
47 return (name && (strcmp (name, "sigacthandler") == 0
48 || strcmp (name, "ucbsigvechandler") == 0
49 || strcmp (name, "__sighndlr") == 0));
50 }
51
52 /* Return whether THIS_FRAME corresponds to a Solaris sigtramp routine. */
53
54 int
55 sol2_sigtramp_p (struct frame_info *this_frame)
56 {
57 CORE_ADDR pc = get_frame_pc (this_frame);
58 const char *name;
59
60 find_pc_partial_function (pc, &name, NULL, NULL);
61 return sol2_pc_in_sigtramp (pc, name);
62 }
63
64 /* Unglobalize NAME. */
65
66 static const char *
67 sol2_static_transform_name (const char *name)
68 {
69 /* The Sun compilers (Sun ONE Studio, Forte Developer, Sun WorkShop,
70 SunPRO) convert file static variables into global values, a
71 process known as globalization. In order to do this, the
72 compiler will create a unique prefix and prepend it to each file
73 static variable. For static variables within a function, this
74 globalization prefix is followed by the function name (nested
75 static variables within a function are supposed to generate a
76 warning message, and are left alone). The procedure is
77 documented in the Stabs Interface Manual, which is distributed
78 with the compilers, although version 4.0 of the manual seems to
79 be incorrect in some places, at least for SPARC. The
80 globalization prefix is encoded into an N_OPT stab, with the form
81 "G=<prefix>". The globalization prefix always seems to start
82 with a dollar sign '$' (sparc) resp. a dot '.' (x86); a dot '.'
83 is used as a separator. So we simply strip everything up until
84 the last dot. */
85 int prefix;
86
87 switch (gdbarch_bfd_arch_info (target_gdbarch ())->arch)
88 {
89 case bfd_arch_i386:
90 prefix = '.';
91 break;
92 case bfd_arch_sparc:
93 prefix = '$';
94 break;
95 default:
96 internal_error (__FILE__, __LINE__, "Unexpected arch");
97 break;
98 }
99
100 if (name[0] == prefix)
101 {
102 const char *p = strrchr (name, '.');
103 if (p)
104 return p + 1;
105 }
106
107 return name;
108 }
109
110 static CORE_ADDR
111 sol2_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
112 {
113 struct bound_minimal_symbol msym;
114
115 msym = lookup_minimal_symbol("elf_bndr", NULL, NULL);
116 if (msym.minsym && BMSYMBOL_VALUE_ADDRESS (msym) == pc)
117 return frame_unwind_caller_pc (get_current_frame ());
118
119 return 0;
120 }
121
122 /* This is how we want PTIDs from Solaris core files to be printed. */
123
124 static std::string
125 sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
126 {
127 struct inferior *inf;
128 int pid;
129
130 /* Check whether we're printing an LWP (gdb thread) or a process. */
131 pid = ptid.lwp ();
132 if (pid != 0)
133 {
134 /* A thread. */
135 return string_printf ("LWP %ld", ptid.lwp ());
136 }
137
138 /* GDB didn't use to put a NT_PSTATUS note in Solaris cores. If
139 that's missing, then we're dealing with a fake PID corelow.c made up. */
140 inf = find_inferior_ptid (current_inferior ()->process_target (), ptid);
141 if (inf == NULL || inf->fake_pid_p)
142 return "<core>";
143
144 /* Not fake; print as usual. */
145 return normal_pid_to_str (ptid);
146 }
147
148 /* To be called from GDB_OSABI_SOLARIS handlers. */
149
150 void
151 sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
152 {
153 /* The Sun compilers (Sun ONE Studio, Forte Developer, Sun WorkShop, SunPRO)
154 compiler puts out 0 instead of the address in N_SO stabs. Starting with
155 SunPRO 3.0, the compiler does this for N_FUN stabs too. */
156 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
157
158 /* The Sun compilers also do "globalization"; see the comment in
159 sol2_static_transform_name for more information. */
160 set_gdbarch_static_transform_name (gdbarch, sol2_static_transform_name);
161
162 /* Solaris uses SVR4-style shared libraries. */
163 set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver);
164
165 /* How to print LWP PTIDs from core files. */
166 set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str);
167 }
This page took 0.032304 seconds and 4 git commands to generate.