Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Low level interface for debugging Solaris threads for GDB, the GNU debugger. |
22abf04a | 2 | Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 |
b6ba6518 | 3 | Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
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 2 of the License, or | |
10 | (at your option) any later version. | |
c906108c | 11 | |
c5aa993b JM |
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. | |
c906108c | 16 | |
c5aa993b JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | /* This module implements a sort of half target that sits between the | |
23 | machine-independent parts of GDB and the /proc interface (procfs.c) to | |
24 | provide access to the Solaris user-mode thread implementation. | |
25 | ||
26 | Solaris threads are true user-mode threads, which are invoked via the thr_* | |
27 | and pthread_* (native and Posix respectivly) interfaces. These are mostly | |
28 | implemented in user-space, with all thread context kept in various | |
29 | structures that live in the user's heap. These should not be confused with | |
30 | lightweight processes (LWPs), which are implemented by the kernel, and | |
31 | scheduled without explicit intervention by the process. | |
32 | ||
33 | Just to confuse things a little, Solaris threads (both native and Posix) are | |
34 | actually implemented using LWPs. In general, there are going to be more | |
35 | threads than LWPs. There is no fixed correspondence between a thread and an | |
36 | LWP. When a thread wants to run, it gets scheduled onto the first available | |
37 | LWP and can therefore migrate from one LWP to another as time goes on. A | |
38 | sleeping thread may not be associated with an LWP at all! | |
39 | ||
40 | To make it possible to mess with threads, Sun provides a library called | |
41 | libthread_db.so.1 (not to be confused with libthread_db.so.0, which doesn't | |
42 | have a published interface). This interface has an upper part, which it | |
43 | provides, and a lower part which I provide. The upper part consists of the | |
44 | td_* routines, which allow me to find all the threads, query their state, | |
45 | etc... The lower part consists of all of the ps_*, which are used by the | |
46 | td_* routines to read/write memory, manipulate LWPs, lookup symbols, etc... | |
47 | The ps_* routines actually do most of their work by calling functions in | |
48 | procfs.c. */ | |
49 | ||
50 | #include "defs.h" | |
51 | #include <thread.h> | |
52 | #include <proc_service.h> | |
53 | #include <thread_db.h> | |
54 | #include "gdbthread.h" | |
55 | #include "target.h" | |
56 | #include "inferior.h" | |
57 | #include <fcntl.h> | |
b8a92b82 | 58 | #include "gdb_stat.h" |
c906108c SS |
59 | #include <dlfcn.h> |
60 | #include "gdbcmd.h" | |
23e04971 | 61 | #include "gdbcore.h" |
4e052eda | 62 | #include "regcache.h" |
990f9fe3 | 63 | #include "symfile.h" |
c906108c | 64 | |
6f4492c8 MK |
65 | #include "gdb_string.h" |
66 | ||
c5aa993b JM |
67 | extern struct target_ops sol_thread_ops; /* Forward declaration */ |
68 | extern struct target_ops sol_core_ops; /* Forward declaration */ | |
c906108c SS |
69 | |
70 | /* place to store core_ops before we overwrite it */ | |
71 | static struct target_ops orig_core_ops; | |
72 | ||
73 | struct target_ops sol_thread_ops; | |
74 | struct target_ops sol_core_ops; | |
75 | ||
76 | extern int procfs_suppress_run; | |
c5aa993b JM |
77 | extern struct target_ops procfs_ops; /* target vector for procfs.c */ |
78 | extern struct target_ops core_ops; /* target vector for corelow.c */ | |
39f77062 | 79 | extern char *procfs_pid_to_str (ptid_t ptid); |
c906108c | 80 | |
c60c0f5f MS |
81 | /* Prototypes for supply_gregset etc. */ |
82 | #include "gregset.h" | |
c906108c SS |
83 | |
84 | /* This struct is defined by us, but mainly used for the proc_service interface. | |
85 | We don't have much use for it, except as a handy place to get a real pid | |
86 | for memory accesses. */ | |
87 | ||
88 | struct ps_prochandle | |
c5aa993b | 89 | { |
39f77062 | 90 | ptid_t ptid; |
c5aa993b | 91 | }; |
c906108c SS |
92 | |
93 | struct string_map | |
c5aa993b JM |
94 | { |
95 | int num; | |
96 | char *str; | |
97 | }; | |
c906108c SS |
98 | |
99 | static struct ps_prochandle main_ph; | |
100 | static td_thragent_t *main_ta; | |
101 | static int sol_thread_active = 0; | |
102 | ||
a14ed312 KB |
103 | static char *td_err_string (td_err_e errcode); |
104 | static char *td_state_string (td_thr_state_e statecode); | |
39f77062 KB |
105 | static ptid_t thread_to_lwp (ptid_t thread_id, int default_lwp); |
106 | static void sol_thread_resume (ptid_t ptid, int step, enum target_signal signo); | |
107 | static ptid_t lwp_to_thread (ptid_t lwp); | |
108 | static int sol_thread_alive (ptid_t ptid); | |
a14ed312 KB |
109 | static void sol_core_close (int quitting); |
110 | ||
111 | static void init_sol_thread_ops (void); | |
112 | static void init_sol_core_ops (void); | |
c906108c | 113 | |
d4f3574e SS |
114 | /* Default definitions: These must be defined in tm.h |
115 | if they are to be shared with a process module such as procfs. */ | |
116 | ||
ca6724c1 KB |
117 | #define GET_PID(ptid) ptid_get_pid (ptid) |
118 | #define GET_LWP(ptid) ptid_get_lwp (ptid) | |
119 | #define GET_THREAD(ptid) ptid_get_tid (ptid) | |
120 | ||
121 | #define is_lwp(ptid) (GET_LWP (ptid) != 0) | |
122 | #define is_thread(ptid) (GET_THREAD (ptid) != 0) | |
123 | ||
124 | #define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0) | |
125 | #define BUILD_THREAD(tid, pid) ptid_build (pid, 0, tid) | |
c906108c SS |
126 | |
127 | /* Pointers to routines from lithread_db resolved by dlopen() */ | |
128 | ||
e245aa6b MS |
129 | static void (*p_td_log) (const int on_off); |
130 | static td_err_e (*p_td_ta_new) (const struct ps_prochandle * ph_p, | |
131 | td_thragent_t ** ta_pp); | |
132 | static td_err_e (*p_td_ta_delete) (td_thragent_t * ta_p); | |
133 | static td_err_e (*p_td_init) (void); | |
134 | static td_err_e (*p_td_ta_get_ph) (const td_thragent_t * ta_p, | |
135 | struct ps_prochandle ** ph_pp); | |
136 | static td_err_e (*p_td_ta_get_nthreads) (const td_thragent_t * ta_p, | |
137 | int *nthread_p); | |
138 | static td_err_e (*p_td_ta_tsd_iter) (const td_thragent_t * ta_p, | |
139 | td_key_iter_f * cb, | |
140 | void *cbdata_p); | |
141 | static td_err_e (*p_td_ta_thr_iter) (const td_thragent_t * ta_p, | |
142 | td_thr_iter_f * cb, | |
143 | void *cbdata_p, | |
144 | td_thr_state_e state, | |
145 | int ti_pri, | |
146 | sigset_t * ti_sigmask_p, | |
147 | unsigned ti_user_flags); | |
148 | static td_err_e (*p_td_thr_validate) (const td_thrhandle_t * th_p); | |
149 | static td_err_e (*p_td_thr_tsd) (const td_thrhandle_t * th_p, | |
150 | const thread_key_t key, | |
151 | void **data_pp); | |
152 | static td_err_e (*p_td_thr_get_info) (const td_thrhandle_t * th_p, | |
153 | td_thrinfo_t * ti_p); | |
154 | static td_err_e (*p_td_thr_getfpregs) (const td_thrhandle_t * th_p, | |
155 | prfpregset_t * fpregset); | |
156 | static td_err_e (*p_td_thr_getxregsize) (const td_thrhandle_t * th_p, | |
157 | int *xregsize); | |
158 | static td_err_e (*p_td_thr_getxregs) (const td_thrhandle_t * th_p, | |
159 | const caddr_t xregset); | |
160 | static td_err_e (*p_td_thr_sigsetmask) (const td_thrhandle_t * th_p, | |
161 | const sigset_t ti_sigmask); | |
162 | static td_err_e (*p_td_thr_setprio) (const td_thrhandle_t * th_p, | |
163 | const int ti_pri); | |
164 | static td_err_e (*p_td_thr_setsigpending) (const td_thrhandle_t * th_p, | |
165 | const uchar_t ti_pending_flag, | |
166 | const sigset_t ti_pending); | |
167 | static td_err_e (*p_td_thr_setfpregs) (const td_thrhandle_t * th_p, | |
168 | const prfpregset_t * fpregset); | |
169 | static td_err_e (*p_td_thr_setxregs) (const td_thrhandle_t * th_p, | |
170 | const caddr_t xregset); | |
171 | static td_err_e (*p_td_ta_map_id2thr) (const td_thragent_t * ta_p, | |
172 | thread_t tid, | |
173 | td_thrhandle_t * th_p); | |
174 | static td_err_e (*p_td_ta_map_lwp2thr) (const td_thragent_t * ta_p, | |
175 | lwpid_t lwpid, | |
176 | td_thrhandle_t * th_p); | |
177 | static td_err_e (*p_td_thr_getgregs) (const td_thrhandle_t * th_p, | |
178 | prgregset_t regset); | |
179 | static td_err_e (*p_td_thr_setgregs) (const td_thrhandle_t * th_p, | |
180 | const prgregset_t regset); | |
181 | ||
c906108c SS |
182 | /* |
183 | ||
c5aa993b | 184 | LOCAL FUNCTION |
c906108c | 185 | |
c5aa993b | 186 | td_err_string - Convert a thread_db error code to a string |
c906108c | 187 | |
c5aa993b | 188 | SYNOPSIS |
c906108c | 189 | |
c5aa993b | 190 | char * td_err_string (errcode) |
c906108c | 191 | |
c5aa993b | 192 | DESCRIPTION |
c906108c | 193 | |
c5aa993b JM |
194 | Return the thread_db error string associated with errcode. If errcode |
195 | is unknown, then return a message. | |
c906108c SS |
196 | |
197 | */ | |
198 | ||
199 | static char * | |
fba45db2 | 200 | td_err_string (td_err_e errcode) |
c906108c SS |
201 | { |
202 | static struct string_map | |
c5aa993b JM |
203 | td_err_table[] = |
204 | { | |
205 | {TD_OK, "generic \"call succeeded\""}, | |
206 | {TD_ERR, "generic error."}, | |
207 | {TD_NOTHR, "no thread can be found to satisfy query"}, | |
208 | {TD_NOSV, "no synch. variable can be found to satisfy query"}, | |
209 | {TD_NOLWP, "no lwp can be found to satisfy query"}, | |
210 | {TD_BADPH, "invalid process handle"}, | |
211 | {TD_BADTH, "invalid thread handle"}, | |
212 | {TD_BADSH, "invalid synchronization handle"}, | |
213 | {TD_BADTA, "invalid thread agent"}, | |
214 | {TD_BADKEY, "invalid key"}, | |
215 | {TD_NOMSG, "td_thr_event_getmsg() called when there was no message"}, | |
216 | {TD_NOFPREGS, "FPU register set not available for given thread"}, | |
217 | {TD_NOLIBTHREAD, "application not linked with libthread"}, | |
218 | {TD_NOEVENT, "requested event is not supported"}, | |
219 | {TD_NOCAPAB, "capability not available"}, | |
220 | {TD_DBERR, "Debugger service failed"}, | |
221 | {TD_NOAPLIC, "Operation not applicable to"}, | |
222 | {TD_NOTSD, "No thread specific data for this thread"}, | |
223 | {TD_MALLOC, "Malloc failed"}, | |
8e1a459b | 224 | {TD_PARTIALREG, "Only part of register set was written/read"}, |
c5aa993b JM |
225 | {TD_NOXREGS, "X register set not available for given thread"} |
226 | }; | |
c906108c SS |
227 | const int td_err_size = sizeof td_err_table / sizeof (struct string_map); |
228 | int i; | |
229 | static char buf[50]; | |
230 | ||
231 | for (i = 0; i < td_err_size; i++) | |
232 | if (td_err_table[i].num == errcode) | |
233 | return td_err_table[i].str; | |
c5aa993b | 234 | |
c906108c SS |
235 | sprintf (buf, "Unknown thread_db error code: %d", errcode); |
236 | ||
237 | return buf; | |
238 | } | |
239 | \f | |
240 | /* | |
241 | ||
c5aa993b | 242 | LOCAL FUNCTION |
c906108c | 243 | |
c5aa993b | 244 | td_state_string - Convert a thread_db state code to a string |
c906108c | 245 | |
c5aa993b | 246 | SYNOPSIS |
c906108c | 247 | |
c5aa993b | 248 | char * td_state_string (statecode) |
c906108c | 249 | |
c5aa993b | 250 | DESCRIPTION |
c906108c | 251 | |
c5aa993b JM |
252 | Return the thread_db state string associated with statecode. If |
253 | statecode is unknown, then return a message. | |
c906108c SS |
254 | |
255 | */ | |
256 | ||
257 | static char * | |
fba45db2 | 258 | td_state_string (td_thr_state_e statecode) |
c906108c SS |
259 | { |
260 | static struct string_map | |
c5aa993b JM |
261 | td_thr_state_table[] = |
262 | { | |
263 | {TD_THR_ANY_STATE, "any state"}, | |
264 | {TD_THR_UNKNOWN, "unknown"}, | |
265 | {TD_THR_STOPPED, "stopped"}, | |
266 | {TD_THR_RUN, "run"}, | |
267 | {TD_THR_ACTIVE, "active"}, | |
268 | {TD_THR_ZOMBIE, "zombie"}, | |
269 | {TD_THR_SLEEP, "sleep"}, | |
270 | {TD_THR_STOPPED_ASLEEP, "stopped asleep"} | |
271 | }; | |
c906108c SS |
272 | const int td_thr_state_table_size = sizeof td_thr_state_table / sizeof (struct string_map); |
273 | int i; | |
274 | static char buf[50]; | |
275 | ||
276 | for (i = 0; i < td_thr_state_table_size; i++) | |
277 | if (td_thr_state_table[i].num == statecode) | |
278 | return td_thr_state_table[i].str; | |
c5aa993b | 279 | |
c906108c SS |
280 | sprintf (buf, "Unknown thread_db state code: %d", statecode); |
281 | ||
282 | return buf; | |
283 | } | |
284 | \f | |
285 | /* | |
286 | ||
c5aa993b | 287 | LOCAL FUNCTION |
c906108c | 288 | |
c5aa993b | 289 | thread_to_lwp - Convert a Posix or Solaris thread id to a LWP id. |
c906108c | 290 | |
c5aa993b | 291 | SYNOPSIS |
c906108c | 292 | |
39f77062 | 293 | tpid_t thread_to_lwp (thread_id, default_lwp) |
c906108c | 294 | |
c5aa993b | 295 | DESCRIPTION |
c906108c | 296 | |
c5aa993b JM |
297 | This function converts a Posix or Solaris thread id to a lightweight |
298 | process id. If thread_id is non-existent, that's an error. If it's | |
299 | an inactive thread, then we return default_lwp. | |
c906108c | 300 | |
c5aa993b | 301 | NOTES |
c906108c | 302 | |
c5aa993b | 303 | This function probably shouldn't call error()... |
c906108c SS |
304 | |
305 | */ | |
306 | ||
39f77062 KB |
307 | static ptid_t |
308 | thread_to_lwp (ptid_t thread_id, int default_lwp) | |
c906108c SS |
309 | { |
310 | td_thrinfo_t ti; | |
311 | td_thrhandle_t th; | |
312 | td_err_e val; | |
313 | ||
314 | if (is_lwp (thread_id)) | |
c5aa993b | 315 | return thread_id; /* It's already an LWP id */ |
c906108c SS |
316 | |
317 | /* It's a thread. Convert to lwp */ | |
318 | ||
319 | val = p_td_ta_map_id2thr (main_ta, GET_THREAD (thread_id), &th); | |
320 | if (val == TD_NOTHR) | |
39f77062 | 321 | return pid_to_ptid (-1); /* thread must have terminated */ |
c906108c SS |
322 | else if (val != TD_OK) |
323 | error ("thread_to_lwp: td_ta_map_id2thr %s", td_err_string (val)); | |
324 | ||
325 | val = p_td_thr_get_info (&th, &ti); | |
326 | if (val == TD_NOTHR) | |
39f77062 | 327 | return pid_to_ptid (-1); /* thread must have terminated */ |
c906108c SS |
328 | else if (val != TD_OK) |
329 | error ("thread_to_lwp: td_thr_get_info: %s", td_err_string (val)); | |
330 | ||
331 | if (ti.ti_state != TD_THR_ACTIVE) | |
332 | { | |
333 | if (default_lwp != -1) | |
39f77062 | 334 | return pid_to_ptid (default_lwp); |
c906108c SS |
335 | error ("thread_to_lwp: thread state not active: %s", |
336 | td_state_string (ti.ti_state)); | |
337 | } | |
338 | ||
339 | return BUILD_LWP (ti.ti_lid, PIDGET (thread_id)); | |
340 | } | |
341 | \f | |
342 | /* | |
343 | ||
c5aa993b | 344 | LOCAL FUNCTION |
c906108c | 345 | |
c5aa993b | 346 | lwp_to_thread - Convert a LWP id to a Posix or Solaris thread id. |
c906108c | 347 | |
c5aa993b | 348 | SYNOPSIS |
c906108c | 349 | |
c5aa993b | 350 | int lwp_to_thread (lwp_id) |
c906108c | 351 | |
c5aa993b | 352 | DESCRIPTION |
c906108c | 353 | |
c5aa993b JM |
354 | This function converts a lightweight process id to a Posix or Solaris |
355 | thread id. If thread_id is non-existent, that's an error. | |
c906108c | 356 | |
c5aa993b | 357 | NOTES |
c906108c | 358 | |
c5aa993b | 359 | This function probably shouldn't call error()... |
c906108c SS |
360 | |
361 | */ | |
362 | ||
39f77062 KB |
363 | static ptid_t |
364 | lwp_to_thread (ptid_t lwp) | |
c906108c SS |
365 | { |
366 | td_thrinfo_t ti; | |
367 | td_thrhandle_t th; | |
368 | td_err_e val; | |
369 | ||
370 | if (is_thread (lwp)) | |
371 | return lwp; /* It's already a thread id */ | |
372 | ||
373 | /* It's an lwp. Convert it to a thread id. */ | |
374 | ||
375 | if (!sol_thread_alive (lwp)) | |
39f77062 | 376 | return pid_to_ptid (-1); /* defunct lwp */ |
c906108c SS |
377 | |
378 | val = p_td_ta_map_lwp2thr (main_ta, GET_LWP (lwp), &th); | |
379 | if (val == TD_NOTHR) | |
39f77062 | 380 | return pid_to_ptid (-1); /* thread must have terminated */ |
c906108c SS |
381 | else if (val != TD_OK) |
382 | error ("lwp_to_thread: td_ta_map_lwp2thr: %s.", td_err_string (val)); | |
383 | ||
384 | val = p_td_thr_validate (&th); | |
385 | if (val == TD_NOTHR) | |
e245aa6b MS |
386 | return lwp; /* libthread doesn't know about it; |
387 | just return lwp */ | |
c906108c SS |
388 | else if (val != TD_OK) |
389 | error ("lwp_to_thread: td_thr_validate: %s.", td_err_string (val)); | |
390 | ||
391 | val = p_td_thr_get_info (&th, &ti); | |
392 | if (val == TD_NOTHR) | |
39f77062 | 393 | return pid_to_ptid (-1); /* thread must have terminated */ |
c906108c SS |
394 | else if (val != TD_OK) |
395 | error ("lwp_to_thread: td_thr_get_info: %s.", td_err_string (val)); | |
396 | ||
397 | return BUILD_THREAD (ti.ti_tid, PIDGET (lwp)); | |
398 | } | |
399 | \f | |
c906108c SS |
400 | |
401 | /* Most target vector functions from here on actually just pass through to | |
402 | procfs.c, as they don't need to do anything specific for threads. */ | |
403 | ||
404 | ||
405 | /* ARGSUSED */ | |
406 | static void | |
fba45db2 | 407 | sol_thread_open (char *arg, int from_tty) |
c906108c SS |
408 | { |
409 | procfs_ops.to_open (arg, from_tty); | |
410 | } | |
411 | ||
412 | /* Attach to process PID, then initialize for debugging it | |
413 | and wait for the trace-trap that results from attaching. */ | |
414 | ||
415 | static void | |
fba45db2 | 416 | sol_thread_attach (char *args, int from_tty) |
c906108c SS |
417 | { |
418 | procfs_ops.to_attach (args, from_tty); | |
23715f29 | 419 | |
71150974 | 420 | /* Must get symbols from solibs before libthread_db can run! */ |
990f9fe3 | 421 | SOLIB_ADD ((char *) 0, from_tty, (struct target_ops *) 0, auto_solib_add); |
71150974 | 422 | |
c906108c SS |
423 | if (sol_thread_active) |
424 | { | |
425 | printf_filtered ("sol-thread active.\n"); | |
39f77062 | 426 | main_ph.ptid = inferior_ptid; /* Save for xfer_memory */ |
c906108c | 427 | push_target (&sol_thread_ops); |
39f77062 KB |
428 | inferior_ptid = lwp_to_thread (inferior_ptid); |
429 | if (PIDGET (inferior_ptid) == -1) | |
430 | inferior_ptid = main_ph.ptid; | |
c906108c | 431 | else |
39f77062 | 432 | add_thread (inferior_ptid); |
c906108c SS |
433 | } |
434 | /* XXX - might want to iterate over all the threads and register them. */ | |
435 | } | |
436 | ||
437 | /* Take a program previously attached to and detaches it. | |
438 | The program resumes execution and will no longer stop | |
439 | on signals, etc. We'd better not have left any breakpoints | |
440 | in the program or it'll die when it hits one. For this | |
441 | to work, it may be necessary for the process to have been | |
442 | previously attached. It *might* work if the program was | |
443 | started via the normal ptrace (PTRACE_TRACEME). */ | |
444 | ||
445 | static void | |
fba45db2 | 446 | sol_thread_detach (char *args, int from_tty) |
c906108c | 447 | { |
39f77062 | 448 | inferior_ptid = pid_to_ptid (PIDGET (main_ph.ptid)); |
c906108c SS |
449 | unpush_target (&sol_thread_ops); |
450 | procfs_ops.to_detach (args, from_tty); | |
451 | } | |
452 | ||
453 | /* Resume execution of process PID. If STEP is nozero, then | |
454 | just single step it. If SIGNAL is nonzero, restart it with that | |
455 | signal activated. We may have to convert pid from a thread-id to an LWP id | |
456 | for procfs. */ | |
457 | ||
458 | static void | |
39f77062 | 459 | sol_thread_resume (ptid_t ptid, int step, enum target_signal signo) |
c906108c SS |
460 | { |
461 | struct cleanup *old_chain; | |
462 | ||
39f77062 | 463 | old_chain = save_inferior_ptid (); |
c906108c | 464 | |
39f77062 KB |
465 | inferior_ptid = thread_to_lwp (inferior_ptid, PIDGET (main_ph.ptid)); |
466 | if (PIDGET (inferior_ptid) == -1) | |
467 | inferior_ptid = procfs_first_available (); | |
c906108c | 468 | |
39f77062 | 469 | if (PIDGET (ptid) != -1) |
c906108c | 470 | { |
39f77062 | 471 | ptid_t save_ptid = ptid; |
c906108c | 472 | |
39f77062 KB |
473 | ptid = thread_to_lwp (ptid, -2); |
474 | if (PIDGET (ptid) == -2) /* Inactive thread */ | |
c906108c | 475 | error ("This version of Solaris can't start inactive threads."); |
39f77062 KB |
476 | if (info_verbose && PIDGET (ptid) == -1) |
477 | warning ("Specified thread %ld seems to have terminated", | |
478 | GET_THREAD (save_ptid)); | |
c906108c SS |
479 | } |
480 | ||
39f77062 | 481 | procfs_ops.to_resume (ptid, step, signo); |
c906108c SS |
482 | |
483 | do_cleanups (old_chain); | |
484 | } | |
485 | ||
486 | /* Wait for any threads to stop. We may have to convert PID from a thread id | |
487 | to a LWP id, and vice versa on the way out. */ | |
488 | ||
39f77062 KB |
489 | static ptid_t |
490 | sol_thread_wait (ptid_t ptid, struct target_waitstatus *ourstatus) | |
c906108c | 491 | { |
39f77062 KB |
492 | ptid_t rtnval; |
493 | ptid_t save_ptid; | |
c906108c SS |
494 | struct cleanup *old_chain; |
495 | ||
39f77062 KB |
496 | save_ptid = inferior_ptid; |
497 | old_chain = save_inferior_ptid (); | |
c906108c | 498 | |
39f77062 KB |
499 | inferior_ptid = thread_to_lwp (inferior_ptid, PIDGET (main_ph.ptid)); |
500 | if (PIDGET (inferior_ptid) == -1) | |
501 | inferior_ptid = procfs_first_available (); | |
c906108c | 502 | |
39f77062 | 503 | if (PIDGET (ptid) != -1) |
c906108c | 504 | { |
39f77062 | 505 | ptid_t save_ptid = ptid; |
c906108c | 506 | |
39f77062 KB |
507 | ptid = thread_to_lwp (ptid, -2); |
508 | if (PIDGET (ptid) == -2) /* Inactive thread */ | |
c906108c | 509 | error ("This version of Solaris can't start inactive threads."); |
39f77062 KB |
510 | if (info_verbose && PIDGET (ptid) == -1) |
511 | warning ("Specified thread %ld seems to have terminated", | |
512 | GET_THREAD (save_ptid)); | |
c906108c SS |
513 | } |
514 | ||
39f77062 | 515 | rtnval = procfs_ops.to_wait (ptid, ourstatus); |
c906108c SS |
516 | |
517 | if (ourstatus->kind != TARGET_WAITKIND_EXITED) | |
518 | { | |
519 | /* Map the LWP of interest back to the appropriate thread ID */ | |
520 | rtnval = lwp_to_thread (rtnval); | |
39f77062 KB |
521 | if (PIDGET (rtnval) == -1) |
522 | rtnval = save_ptid; | |
c906108c SS |
523 | |
524 | /* See if we have a new thread */ | |
525 | if (is_thread (rtnval) | |
39f77062 | 526 | && !ptid_equal (rtnval, save_ptid) |
c906108c SS |
527 | && !in_thread_list (rtnval)) |
528 | { | |
529 | printf_filtered ("[New %s]\n", target_pid_to_str (rtnval)); | |
530 | add_thread (rtnval); | |
531 | } | |
532 | } | |
533 | ||
534 | /* During process initialization, we may get here without the thread package | |
535 | being initialized, since that can only happen after we've found the shared | |
536 | libs. */ | |
537 | ||
538 | do_cleanups (old_chain); | |
539 | ||
540 | return rtnval; | |
541 | } | |
542 | ||
543 | static void | |
fba45db2 | 544 | sol_thread_fetch_registers (int regno) |
c906108c SS |
545 | { |
546 | thread_t thread; | |
547 | td_thrhandle_t thandle; | |
548 | td_err_e val; | |
549 | prgregset_t gregset; | |
550 | prfpregset_t fpregset; | |
551 | #if 0 | |
552 | int xregsize; | |
553 | caddr_t xregset; | |
554 | #endif | |
555 | ||
39f77062 | 556 | if (!is_thread (inferior_ptid)) |
c5aa993b | 557 | { /* LWP: pass the request on to procfs.c */ |
c906108c SS |
558 | if (target_has_execution) |
559 | procfs_ops.to_fetch_registers (regno); | |
560 | else | |
561 | orig_core_ops.to_fetch_registers (regno); | |
562 | return; | |
563 | } | |
564 | ||
39f77062 | 565 | /* Solaris thread: convert inferior_ptid into a td_thrhandle_t */ |
c906108c | 566 | |
39f77062 | 567 | thread = GET_THREAD (inferior_ptid); |
c906108c SS |
568 | |
569 | if (thread == 0) | |
570 | error ("sol_thread_fetch_registers: thread == 0"); | |
571 | ||
572 | val = p_td_ta_map_id2thr (main_ta, thread, &thandle); | |
573 | if (val != TD_OK) | |
574 | error ("sol_thread_fetch_registers: td_ta_map_id2thr: %s", | |
575 | td_err_string (val)); | |
576 | ||
577 | /* Get the integer regs */ | |
578 | ||
579 | val = p_td_thr_getgregs (&thandle, gregset); | |
580 | if (val != TD_OK | |
581 | && val != TD_PARTIALREG) | |
582 | error ("sol_thread_fetch_registers: td_thr_getgregs %s", | |
583 | td_err_string (val)); | |
584 | ||
585 | /* For the sparc, TD_PARTIALREG means that only i0->i7, l0->l7, pc and sp | |
586 | are saved (by a thread context switch). */ | |
587 | ||
588 | /* And, now the fp regs */ | |
589 | ||
590 | val = p_td_thr_getfpregs (&thandle, &fpregset); | |
591 | if (val != TD_OK | |
592 | && val != TD_NOFPREGS) | |
593 | error ("sol_thread_fetch_registers: td_thr_getfpregs %s", | |
594 | td_err_string (val)); | |
595 | ||
596 | /* Note that we must call supply_{g fp}regset *after* calling the td routines | |
597 | because the td routines call ps_lget* which affect the values stored in the | |
598 | registers array. */ | |
599 | ||
c60c0f5f MS |
600 | supply_gregset ((gdb_gregset_t *) &gregset); |
601 | supply_fpregset ((gdb_fpregset_t *) &fpregset); | |
c906108c SS |
602 | |
603 | #if 0 | |
604 | /* thread_db doesn't seem to handle this right */ | |
605 | val = td_thr_getxregsize (&thandle, &xregsize); | |
606 | if (val != TD_OK && val != TD_NOXREGS) | |
607 | error ("sol_thread_fetch_registers: td_thr_getxregsize %s", | |
608 | td_err_string (val)); | |
609 | ||
610 | if (val == TD_OK) | |
611 | { | |
612 | xregset = alloca (xregsize); | |
613 | val = td_thr_getxregs (&thandle, xregset); | |
614 | if (val != TD_OK) | |
615 | error ("sol_thread_fetch_registers: td_thr_getxregs %s", | |
616 | td_err_string (val)); | |
617 | } | |
618 | #endif | |
619 | } | |
620 | ||
621 | static void | |
fba45db2 | 622 | sol_thread_store_registers (int regno) |
c906108c SS |
623 | { |
624 | thread_t thread; | |
625 | td_thrhandle_t thandle; | |
626 | td_err_e val; | |
c60c0f5f | 627 | prgregset_t gregset; |
c906108c SS |
628 | prfpregset_t fpregset; |
629 | #if 0 | |
630 | int xregsize; | |
631 | caddr_t xregset; | |
632 | #endif | |
633 | ||
39f77062 | 634 | if (!is_thread (inferior_ptid)) |
c5aa993b | 635 | { /* LWP: pass the request on to procfs.c */ |
c906108c SS |
636 | procfs_ops.to_store_registers (regno); |
637 | return; | |
638 | } | |
639 | ||
39f77062 | 640 | /* Solaris thread: convert inferior_ptid into a td_thrhandle_t */ |
c906108c | 641 | |
39f77062 | 642 | thread = GET_THREAD (inferior_ptid); |
c906108c SS |
643 | |
644 | val = p_td_ta_map_id2thr (main_ta, thread, &thandle); | |
645 | if (val != TD_OK) | |
646 | error ("sol_thread_store_registers: td_ta_map_id2thr %s", | |
647 | td_err_string (val)); | |
648 | ||
649 | if (regno != -1) | |
650 | { /* Not writing all the regs */ | |
87232496 MK |
651 | char old_value[MAX_REGISTER_SIZE]; |
652 | ||
653 | /* Save new register value. */ | |
654 | regcache_collect (regno, old_value); | |
c906108c | 655 | |
c60c0f5f | 656 | val = p_td_thr_getgregs (&thandle, gregset); |
c906108c SS |
657 | if (val != TD_OK) |
658 | error ("sol_thread_store_registers: td_thr_getgregs %s", | |
659 | td_err_string (val)); | |
660 | val = p_td_thr_getfpregs (&thandle, &fpregset); | |
661 | if (val != TD_OK) | |
662 | error ("sol_thread_store_registers: td_thr_getfpregs %s", | |
663 | td_err_string (val)); | |
664 | ||
87232496 MK |
665 | /* Restore new register value. */ |
666 | supply_register (regno, old_value); | |
c906108c SS |
667 | |
668 | #if 0 | |
669 | /* thread_db doesn't seem to handle this right */ | |
670 | val = td_thr_getxregsize (&thandle, &xregsize); | |
671 | if (val != TD_OK && val != TD_NOXREGS) | |
672 | error ("sol_thread_store_registers: td_thr_getxregsize %s", | |
673 | td_err_string (val)); | |
674 | ||
675 | if (val == TD_OK) | |
676 | { | |
677 | xregset = alloca (xregsize); | |
678 | val = td_thr_getxregs (&thandle, xregset); | |
679 | if (val != TD_OK) | |
680 | error ("sol_thread_store_registers: td_thr_getxregs %s", | |
681 | td_err_string (val)); | |
682 | } | |
683 | #endif | |
684 | } | |
685 | ||
c60c0f5f MS |
686 | fill_gregset ((gdb_gregset_t *) &gregset, regno); |
687 | fill_fpregset ((gdb_fpregset_t *) &fpregset, regno); | |
c906108c | 688 | |
c60c0f5f | 689 | val = p_td_thr_setgregs (&thandle, gregset); |
c906108c SS |
690 | if (val != TD_OK) |
691 | error ("sol_thread_store_registers: td_thr_setgregs %s", | |
692 | td_err_string (val)); | |
693 | val = p_td_thr_setfpregs (&thandle, &fpregset); | |
694 | if (val != TD_OK) | |
695 | error ("sol_thread_store_registers: td_thr_setfpregs %s", | |
696 | td_err_string (val)); | |
697 | ||
698 | #if 0 | |
699 | /* thread_db doesn't seem to handle this right */ | |
700 | val = td_thr_getxregsize (&thandle, &xregsize); | |
701 | if (val != TD_OK && val != TD_NOXREGS) | |
702 | error ("sol_thread_store_registers: td_thr_getxregsize %s", | |
703 | td_err_string (val)); | |
704 | ||
705 | /* Should probably do something about writing the xregs here, but what are | |
706 | they? */ | |
707 | #endif | |
708 | } | |
709 | ||
710 | /* Get ready to modify the registers array. On machines which store | |
711 | individual registers, this doesn't need to do anything. On machines | |
712 | which store all the registers in one fell swoop, this makes sure | |
713 | that registers contains all the registers from the program being | |
714 | debugged. */ | |
715 | ||
716 | static void | |
fba45db2 | 717 | sol_thread_prepare_to_store (void) |
c906108c SS |
718 | { |
719 | procfs_ops.to_prepare_to_store (); | |
720 | } | |
721 | ||
c338868a KB |
722 | /* Transfer LEN bytes between GDB address MYADDR and target address |
723 | MEMADDR. If DOWRITE is non-zero, transfer them to the target, | |
724 | otherwise transfer them from the target. TARGET is unused. | |
725 | ||
726 | Returns the number of bytes transferred. */ | |
727 | ||
c906108c | 728 | static int |
c338868a | 729 | sol_thread_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int dowrite, |
f4d650ec | 730 | struct mem_attrib *attrib, |
c338868a | 731 | struct target_ops *target) |
c906108c SS |
732 | { |
733 | int retval; | |
734 | struct cleanup *old_chain; | |
735 | ||
39f77062 | 736 | old_chain = save_inferior_ptid (); |
c906108c | 737 | |
39f77062 KB |
738 | if (is_thread (inferior_ptid) || /* A thread */ |
739 | !target_thread_alive (inferior_ptid)) /* An lwp, but not alive */ | |
740 | inferior_ptid = procfs_first_available (); /* Find any live lwp. */ | |
c906108c SS |
741 | /* Note: don't need to call switch_to_thread; we're just reading memory. */ |
742 | ||
743 | if (target_has_execution) | |
f4d650ec C |
744 | retval = procfs_ops.to_xfer_memory (memaddr, myaddr, len, |
745 | dowrite, attrib, target); | |
c906108c SS |
746 | else |
747 | retval = orig_core_ops.to_xfer_memory (memaddr, myaddr, len, | |
f4d650ec | 748 | dowrite, attrib, target); |
c906108c SS |
749 | |
750 | do_cleanups (old_chain); | |
751 | ||
752 | return retval; | |
753 | } | |
754 | ||
755 | /* Print status information about what we're accessing. */ | |
756 | ||
757 | static void | |
fba45db2 | 758 | sol_thread_files_info (struct target_ops *ignore) |
c906108c SS |
759 | { |
760 | procfs_ops.to_files_info (ignore); | |
761 | } | |
762 | ||
763 | static void | |
fba45db2 | 764 | sol_thread_kill_inferior (void) |
c906108c SS |
765 | { |
766 | procfs_ops.to_kill (); | |
767 | } | |
768 | ||
769 | static void | |
39f77062 | 770 | sol_thread_notice_signals (ptid_t ptid) |
c906108c | 771 | { |
39f77062 | 772 | procfs_ops.to_notice_signals (pid_to_ptid (PIDGET (ptid))); |
c906108c SS |
773 | } |
774 | ||
775 | /* Fork an inferior process, and start debugging it with /proc. */ | |
776 | ||
777 | static void | |
fba45db2 | 778 | sol_thread_create_inferior (char *exec_file, char *allargs, char **env) |
c906108c SS |
779 | { |
780 | procfs_ops.to_create_inferior (exec_file, allargs, env); | |
781 | ||
39f77062 | 782 | if (sol_thread_active && !ptid_equal (inferior_ptid, null_ptid)) |
c906108c | 783 | { |
39f77062 | 784 | main_ph.ptid = inferior_ptid; /* Save for xfer_memory */ |
c906108c SS |
785 | |
786 | push_target (&sol_thread_ops); | |
787 | ||
39f77062 KB |
788 | inferior_ptid = lwp_to_thread (inferior_ptid); |
789 | if (PIDGET (inferior_ptid) == -1) | |
790 | inferior_ptid = main_ph.ptid; | |
c906108c | 791 | |
39f77062 KB |
792 | if (!in_thread_list (inferior_ptid)) |
793 | add_thread (inferior_ptid); | |
c906108c SS |
794 | } |
795 | } | |
796 | ||
797 | /* This routine is called whenever a new symbol table is read in, or when all | |
798 | symbol tables are removed. libthread_db can only be initialized when it | |
799 | finds the right variables in libthread.so. Since it's a shared library, | |
800 | those variables don't show up until the library gets mapped and the symbol | |
801 | table is read in. */ | |
802 | ||
11cf8741 JM |
803 | /* This new_objfile event is now managed by a chained function pointer. |
804 | * It is the callee's responsability to call the next client on the chain. | |
805 | */ | |
806 | ||
807 | /* Saved pointer to previous owner of the new_objfile event. */ | |
507f3c78 | 808 | static void (*target_new_objfile_chain) (struct objfile *); |
11cf8741 | 809 | |
c906108c | 810 | void |
fba45db2 | 811 | sol_thread_new_objfile (struct objfile *objfile) |
c906108c SS |
812 | { |
813 | td_err_e val; | |
814 | ||
815 | if (!objfile) | |
816 | { | |
817 | sol_thread_active = 0; | |
11cf8741 | 818 | goto quit; |
c906108c SS |
819 | } |
820 | ||
821 | /* don't do anything if init failed to resolve the libthread_db library */ | |
822 | if (!procfs_suppress_run) | |
11cf8741 | 823 | goto quit; |
c906108c SS |
824 | |
825 | /* Now, initialize the thread debugging library. This needs to be done after | |
826 | the shared libraries are located because it needs information from the | |
827 | user's thread library. */ | |
828 | ||
829 | val = p_td_init (); | |
830 | if (val != TD_OK) | |
11cf8741 JM |
831 | { |
832 | warning ("sol_thread_new_objfile: td_init: %s", td_err_string (val)); | |
833 | goto quit; | |
834 | } | |
c906108c SS |
835 | |
836 | val = p_td_ta_new (&main_ph, &main_ta); | |
837 | if (val == TD_NOLIBTHREAD) | |
11cf8741 | 838 | goto quit; |
c906108c | 839 | else if (val != TD_OK) |
11cf8741 JM |
840 | { |
841 | warning ("sol_thread_new_objfile: td_ta_new: %s", td_err_string (val)); | |
842 | goto quit; | |
843 | } | |
c906108c SS |
844 | |
845 | sol_thread_active = 1; | |
11cf8741 JM |
846 | quit: |
847 | /* Call predecessor on chain, if any. */ | |
848 | if (target_new_objfile_chain) | |
849 | target_new_objfile_chain (objfile); | |
c906108c SS |
850 | } |
851 | ||
852 | /* Clean up after the inferior dies. */ | |
853 | ||
854 | static void | |
fba45db2 | 855 | sol_thread_mourn_inferior (void) |
c906108c SS |
856 | { |
857 | unpush_target (&sol_thread_ops); | |
858 | procfs_ops.to_mourn_inferior (); | |
859 | } | |
860 | ||
861 | /* Mark our target-struct as eligible for stray "run" and "attach" commands. */ | |
862 | ||
863 | static int | |
fba45db2 | 864 | sol_thread_can_run (void) |
c906108c SS |
865 | { |
866 | return procfs_suppress_run; | |
867 | } | |
868 | ||
869 | /* | |
870 | ||
c5aa993b | 871 | LOCAL FUNCTION |
c906108c | 872 | |
c5aa993b | 873 | sol_thread_alive - test thread for "aliveness" |
c906108c | 874 | |
c5aa993b | 875 | SYNOPSIS |
c906108c | 876 | |
39f77062 | 877 | static bool sol_thread_alive (ptid_t ptid); |
c906108c | 878 | |
c5aa993b | 879 | DESCRIPTION |
c906108c | 880 | |
c5aa993b | 881 | returns true if thread still active in inferior. |
c906108c SS |
882 | |
883 | */ | |
884 | ||
885 | static int | |
39f77062 | 886 | sol_thread_alive (ptid_t ptid) |
c906108c | 887 | { |
39f77062 | 888 | if (is_thread (ptid)) /* non-kernel thread */ |
c906108c SS |
889 | { |
890 | td_err_e val; | |
891 | td_thrhandle_t th; | |
39f77062 | 892 | int pid; |
c906108c | 893 | |
39f77062 | 894 | pid = GET_THREAD (ptid); |
c906108c | 895 | if ((val = p_td_ta_map_id2thr (main_ta, pid, &th)) != TD_OK) |
c5aa993b | 896 | return 0; /* thread not found */ |
c906108c | 897 | if ((val = p_td_thr_validate (&th)) != TD_OK) |
c5aa993b JM |
898 | return 0; /* thread not valid */ |
899 | return 1; /* known thread: return true */ | |
c906108c | 900 | } |
c5aa993b JM |
901 | else |
902 | /* kernel thread (LWP): let procfs test it */ | |
c906108c SS |
903 | { |
904 | if (target_has_execution) | |
39f77062 | 905 | return procfs_ops.to_thread_alive (ptid); |
c906108c | 906 | else |
39f77062 | 907 | return orig_core_ops.to_thread_alive (ptid); |
c906108c SS |
908 | } |
909 | } | |
910 | ||
911 | static void | |
fba45db2 | 912 | sol_thread_stop (void) |
c906108c SS |
913 | { |
914 | procfs_ops.to_stop (); | |
915 | } | |
916 | \f | |
917 | /* These routines implement the lower half of the thread_db interface. Ie: the | |
918 | ps_* routines. */ | |
919 | ||
920 | /* Various versions of <proc_service.h> have slightly | |
921 | different function prototypes. In particular, we have | |
922 | ||
c5aa993b JM |
923 | NEWER OLDER |
924 | struct ps_prochandle * const struct ps_prochandle * | |
925 | void* char* | |
926 | const void* char* | |
927 | int size_t | |
c906108c SS |
928 | |
929 | Which one you have depends on solaris version and what | |
930 | patches you've applied. On the theory that there are | |
931 | only two major variants, we have configure check the | |
932 | prototype of ps_pdwrite (), and use that info to make | |
933 | appropriate typedefs here. */ | |
934 | ||
935 | #ifdef PROC_SERVICE_IS_OLD | |
c5aa993b JM |
936 | typedef const struct ps_prochandle *gdb_ps_prochandle_t; |
937 | typedef char *gdb_ps_read_buf_t; | |
938 | typedef char *gdb_ps_write_buf_t; | |
c906108c | 939 | typedef int gdb_ps_size_t; |
291dcb3e | 940 | typedef paddr_t gdb_ps_addr_t; |
c906108c | 941 | #else |
c5aa993b JM |
942 | typedef struct ps_prochandle *gdb_ps_prochandle_t; |
943 | typedef void *gdb_ps_read_buf_t; | |
944 | typedef const void *gdb_ps_write_buf_t; | |
c906108c | 945 | typedef size_t gdb_ps_size_t; |
291dcb3e | 946 | typedef psaddr_t gdb_ps_addr_t; |
c906108c SS |
947 | #endif |
948 | ||
949 | ||
950 | /* The next four routines are called by thread_db to tell us to stop and stop | |
951 | a particular process or lwp. Since GDB ensures that these are all stopped | |
952 | by the time we call anything in thread_db, these routines need to do | |
953 | nothing. */ | |
954 | ||
d4f3574e SS |
955 | /* Process stop */ |
956 | ||
c906108c SS |
957 | ps_err_e |
958 | ps_pstop (gdb_ps_prochandle_t ph) | |
959 | { | |
960 | return PS_OK; | |
961 | } | |
962 | ||
d4f3574e SS |
963 | /* Process continue */ |
964 | ||
c906108c SS |
965 | ps_err_e |
966 | ps_pcontinue (gdb_ps_prochandle_t ph) | |
967 | { | |
968 | return PS_OK; | |
969 | } | |
970 | ||
d4f3574e SS |
971 | /* LWP stop */ |
972 | ||
c906108c SS |
973 | ps_err_e |
974 | ps_lstop (gdb_ps_prochandle_t ph, lwpid_t lwpid) | |
975 | { | |
976 | return PS_OK; | |
977 | } | |
978 | ||
d4f3574e SS |
979 | /* LWP continue */ |
980 | ||
c906108c SS |
981 | ps_err_e |
982 | ps_lcontinue (gdb_ps_prochandle_t ph, lwpid_t lwpid) | |
983 | { | |
984 | return PS_OK; | |
985 | } | |
986 | ||
d4f3574e SS |
987 | /* Looks up the symbol LD_SYMBOL_NAME in the debugger's symbol table. */ |
988 | ||
c906108c SS |
989 | ps_err_e |
990 | ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *ld_object_name, | |
291dcb3e | 991 | const char *ld_symbol_name, gdb_ps_addr_t * ld_symbol_addr) |
c906108c SS |
992 | { |
993 | struct minimal_symbol *ms; | |
994 | ||
995 | ms = lookup_minimal_symbol (ld_symbol_name, NULL, NULL); | |
996 | ||
997 | if (!ms) | |
998 | return PS_NOSYM; | |
999 | ||
1000 | *ld_symbol_addr = SYMBOL_VALUE_ADDRESS (ms); | |
1001 | ||
1002 | return PS_OK; | |
1003 | } | |
1004 | ||
1005 | /* Common routine for reading and writing memory. */ | |
1006 | ||
1007 | static ps_err_e | |
291dcb3e | 1008 | rw_common (int dowrite, const struct ps_prochandle *ph, gdb_ps_addr_t addr, |
c906108c SS |
1009 | char *buf, int size) |
1010 | { | |
1011 | struct cleanup *old_chain; | |
1012 | ||
39f77062 | 1013 | old_chain = save_inferior_ptid (); |
c906108c | 1014 | |
39f77062 KB |
1015 | if (is_thread (inferior_ptid) || /* A thread */ |
1016 | !target_thread_alive (inferior_ptid)) /* An lwp, but not alive */ | |
1017 | inferior_ptid = procfs_first_available (); /* Find any live lwp. */ | |
c906108c SS |
1018 | /* Note: don't need to call switch_to_thread; we're just reading memory. */ |
1019 | ||
23e04971 MS |
1020 | #if defined (__sparcv9) |
1021 | /* For Sparc64 cross Sparc32, make sure the address has not been | |
1022 | accidentally sign-extended (or whatever) to beyond 32 bits. */ | |
359431fb | 1023 | if (bfd_get_arch_size (exec_bfd) == 32) |
23e04971 MS |
1024 | addr &= 0xffffffff; |
1025 | #endif | |
1026 | ||
c906108c SS |
1027 | while (size > 0) |
1028 | { | |
1029 | int cc; | |
1030 | ||
f4d650ec | 1031 | /* FIXME: passing 0 as attrib argument. */ |
c906108c | 1032 | if (target_has_execution) |
f4d650ec C |
1033 | cc = procfs_ops.to_xfer_memory (addr, buf, size, |
1034 | dowrite, 0, &procfs_ops); | |
c906108c | 1035 | else |
f4d650ec C |
1036 | cc = orig_core_ops.to_xfer_memory (addr, buf, size, |
1037 | dowrite, 0, &core_ops); | |
c906108c SS |
1038 | |
1039 | if (cc < 0) | |
1040 | { | |
1041 | if (dowrite == 0) | |
1042 | print_sys_errmsg ("rw_common (): read", errno); | |
1043 | else | |
1044 | print_sys_errmsg ("rw_common (): write", errno); | |
1045 | ||
1046 | do_cleanups (old_chain); | |
1047 | ||
1048 | return PS_ERR; | |
1049 | } | |
d5cb3e0e MS |
1050 | else if (cc == 0) |
1051 | { | |
1052 | if (dowrite == 0) | |
1053 | warning ("rw_common (): unable to read at addr 0x%lx", | |
1054 | (long) addr); | |
1055 | else | |
1056 | warning ("rw_common (): unable to write at addr 0x%lx", | |
1057 | (long) addr); | |
1058 | ||
1059 | do_cleanups (old_chain); | |
1060 | ||
1061 | return PS_ERR; | |
1062 | } | |
1063 | ||
c906108c SS |
1064 | size -= cc; |
1065 | buf += cc; | |
1066 | } | |
1067 | ||
1068 | do_cleanups (old_chain); | |
1069 | ||
1070 | return PS_OK; | |
1071 | } | |
1072 | ||
d4f3574e SS |
1073 | /* Copies SIZE bytes from target process .data segment to debugger memory. */ |
1074 | ||
c906108c | 1075 | ps_err_e |
291dcb3e | 1076 | ps_pdread (gdb_ps_prochandle_t ph, gdb_ps_addr_t addr, |
c906108c SS |
1077 | gdb_ps_read_buf_t buf, gdb_ps_size_t size) |
1078 | { | |
1079 | return rw_common (0, ph, addr, buf, size); | |
1080 | } | |
1081 | ||
d4f3574e SS |
1082 | /* Copies SIZE bytes from debugger memory .data segment to target process. */ |
1083 | ||
c906108c | 1084 | ps_err_e |
291dcb3e | 1085 | ps_pdwrite (gdb_ps_prochandle_t ph, gdb_ps_addr_t addr, |
c906108c SS |
1086 | gdb_ps_write_buf_t buf, gdb_ps_size_t size) |
1087 | { | |
c5aa993b | 1088 | return rw_common (1, ph, addr, (char *) buf, size); |
c906108c SS |
1089 | } |
1090 | ||
d4f3574e SS |
1091 | /* Copies SIZE bytes from target process .text segment to debugger memory. */ |
1092 | ||
c906108c | 1093 | ps_err_e |
291dcb3e | 1094 | ps_ptread (gdb_ps_prochandle_t ph, gdb_ps_addr_t addr, |
c906108c SS |
1095 | gdb_ps_read_buf_t buf, gdb_ps_size_t size) |
1096 | { | |
1097 | return rw_common (0, ph, addr, buf, size); | |
1098 | } | |
1099 | ||
d4f3574e SS |
1100 | /* Copies SIZE bytes from debugger memory .text segment to target process. */ |
1101 | ||
c906108c | 1102 | ps_err_e |
291dcb3e | 1103 | ps_ptwrite (gdb_ps_prochandle_t ph, gdb_ps_addr_t addr, |
c906108c SS |
1104 | gdb_ps_write_buf_t buf, gdb_ps_size_t size) |
1105 | { | |
c5aa993b | 1106 | return rw_common (1, ph, addr, (char *) buf, size); |
c906108c SS |
1107 | } |
1108 | ||
d4f3574e | 1109 | /* Get integer regs for LWP */ |
c906108c SS |
1110 | |
1111 | ps_err_e | |
1112 | ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, | |
1113 | prgregset_t gregset) | |
1114 | { | |
1115 | struct cleanup *old_chain; | |
1116 | ||
39f77062 | 1117 | old_chain = save_inferior_ptid (); |
c906108c | 1118 | |
39f77062 | 1119 | inferior_ptid = BUILD_LWP (lwpid, PIDGET (inferior_ptid)); |
c5aa993b | 1120 | |
c906108c SS |
1121 | if (target_has_execution) |
1122 | procfs_ops.to_fetch_registers (-1); | |
1123 | else | |
1124 | orig_core_ops.to_fetch_registers (-1); | |
c60c0f5f | 1125 | fill_gregset ((gdb_gregset_t *) gregset, -1); |
c906108c SS |
1126 | |
1127 | do_cleanups (old_chain); | |
1128 | ||
1129 | return PS_OK; | |
1130 | } | |
1131 | ||
d4f3574e | 1132 | /* Set integer regs for LWP */ |
c906108c SS |
1133 | |
1134 | ps_err_e | |
1135 | ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, | |
1136 | const prgregset_t gregset) | |
1137 | { | |
1138 | struct cleanup *old_chain; | |
1139 | ||
39f77062 | 1140 | old_chain = save_inferior_ptid (); |
c906108c | 1141 | |
39f77062 | 1142 | inferior_ptid = BUILD_LWP (lwpid, PIDGET (inferior_ptid)); |
c5aa993b | 1143 | |
c60c0f5f | 1144 | supply_gregset ((gdb_gregset_t *) gregset); |
c906108c SS |
1145 | if (target_has_execution) |
1146 | procfs_ops.to_store_registers (-1); | |
1147 | else | |
1148 | orig_core_ops.to_store_registers (-1); | |
1149 | ||
1150 | do_cleanups (old_chain); | |
1151 | ||
1152 | return PS_OK; | |
1153 | } | |
1154 | ||
d4f3574e SS |
1155 | /* Log a message (sends to gdb_stderr). */ |
1156 | ||
c906108c | 1157 | void |
c5aa993b | 1158 | ps_plog (const char *fmt,...) |
c906108c SS |
1159 | { |
1160 | va_list args; | |
1161 | ||
1162 | va_start (args, fmt); | |
1163 | ||
1164 | vfprintf_filtered (gdb_stderr, fmt, args); | |
1165 | } | |
1166 | ||
1167 | /* Get size of extra register set. Currently a noop. */ | |
1168 | ||
1169 | ps_err_e | |
1170 | ps_lgetxregsize (gdb_ps_prochandle_t ph, lwpid_t lwpid, int *xregsize) | |
1171 | { | |
1172 | #if 0 | |
1173 | int lwp_fd; | |
1174 | int regsize; | |
1175 | ps_err_e val; | |
1176 | ||
1177 | val = get_lwp_fd (ph, lwpid, &lwp_fd); | |
1178 | if (val != PS_OK) | |
1179 | return val; | |
1180 | ||
1181 | if (ioctl (lwp_fd, PIOCGXREGSIZE, ®size)) | |
1182 | { | |
1183 | if (errno == EINVAL) | |
1184 | return PS_NOFREGS; /* XXX Wrong code, but this is the closest | |
1185 | thing in proc_service.h */ | |
1186 | ||
1187 | print_sys_errmsg ("ps_lgetxregsize (): PIOCGXREGSIZE", errno); | |
1188 | return PS_ERR; | |
1189 | } | |
1190 | #endif | |
1191 | ||
1192 | return PS_OK; | |
1193 | } | |
1194 | ||
1195 | /* Get extra register set. Currently a noop. */ | |
1196 | ||
1197 | ps_err_e | |
1198 | ps_lgetxregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, caddr_t xregset) | |
1199 | { | |
1200 | #if 0 | |
1201 | int lwp_fd; | |
1202 | ps_err_e val; | |
1203 | ||
1204 | val = get_lwp_fd (ph, lwpid, &lwp_fd); | |
1205 | if (val != PS_OK) | |
1206 | return val; | |
1207 | ||
1208 | if (ioctl (lwp_fd, PIOCGXREG, xregset)) | |
1209 | { | |
1210 | print_sys_errmsg ("ps_lgetxregs (): PIOCGXREG", errno); | |
1211 | return PS_ERR; | |
1212 | } | |
1213 | #endif | |
1214 | ||
1215 | return PS_OK; | |
1216 | } | |
1217 | ||
1218 | /* Set extra register set. Currently a noop. */ | |
1219 | ||
1220 | ps_err_e | |
1221 | ps_lsetxregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, caddr_t xregset) | |
1222 | { | |
1223 | #if 0 | |
1224 | int lwp_fd; | |
1225 | ps_err_e val; | |
1226 | ||
1227 | val = get_lwp_fd (ph, lwpid, &lwp_fd); | |
1228 | if (val != PS_OK) | |
1229 | return val; | |
1230 | ||
1231 | if (ioctl (lwp_fd, PIOCSXREG, xregset)) | |
1232 | { | |
1233 | print_sys_errmsg ("ps_lsetxregs (): PIOCSXREG", errno); | |
1234 | return PS_ERR; | |
1235 | } | |
1236 | #endif | |
1237 | ||
1238 | return PS_OK; | |
1239 | } | |
1240 | ||
d4f3574e | 1241 | /* Get floating-point regs for LWP */ |
c906108c SS |
1242 | |
1243 | ps_err_e | |
1244 | ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, | |
c5aa993b | 1245 | prfpregset_t * fpregset) |
c906108c SS |
1246 | { |
1247 | struct cleanup *old_chain; | |
1248 | ||
39f77062 | 1249 | old_chain = save_inferior_ptid (); |
c906108c | 1250 | |
39f77062 | 1251 | inferior_ptid = BUILD_LWP (lwpid, PIDGET (inferior_ptid)); |
c906108c SS |
1252 | |
1253 | if (target_has_execution) | |
1254 | procfs_ops.to_fetch_registers (-1); | |
1255 | else | |
1256 | orig_core_ops.to_fetch_registers (-1); | |
c60c0f5f | 1257 | fill_fpregset ((gdb_fpregset_t *) fpregset, -1); |
c906108c SS |
1258 | |
1259 | do_cleanups (old_chain); | |
1260 | ||
1261 | return PS_OK; | |
1262 | } | |
1263 | ||
d4f3574e | 1264 | /* Set floating-point regs for LWP */ |
c906108c SS |
1265 | |
1266 | ps_err_e | |
1267 | ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, | |
c5aa993b | 1268 | const prfpregset_t * fpregset) |
c906108c SS |
1269 | { |
1270 | struct cleanup *old_chain; | |
1271 | ||
39f77062 | 1272 | old_chain = save_inferior_ptid (); |
c906108c | 1273 | |
39f77062 | 1274 | inferior_ptid = BUILD_LWP (lwpid, PIDGET (inferior_ptid)); |
c5aa993b | 1275 | |
c60c0f5f | 1276 | supply_fpregset ((gdb_fpregset_t *) fpregset); |
c906108c SS |
1277 | if (target_has_execution) |
1278 | procfs_ops.to_store_registers (-1); | |
1279 | else | |
1280 | orig_core_ops.to_store_registers (-1); | |
1281 | ||
1282 | do_cleanups (old_chain); | |
1283 | ||
1284 | return PS_OK; | |
1285 | } | |
1286 | ||
23715f29 | 1287 | #ifdef PR_MODEL_LP64 |
23e04971 MS |
1288 | /* Identify process as 32-bit or 64-bit. |
1289 | At the moment I'm using bfd to do this. | |
1290 | There might be a more solaris-specific (eg. procfs) method, | |
1291 | but this ought to work. */ | |
1292 | ||
1293 | ps_err_e | |
1294 | ps_pdmodel (gdb_ps_prochandle_t ph, int *data_model) | |
1295 | { | |
1296 | if (exec_bfd == 0) | |
a95ac8b6 PS |
1297 | *data_model = PR_MODEL_UNKNOWN; |
1298 | else if (bfd_get_arch_size (exec_bfd) == 32) | |
23e04971 MS |
1299 | *data_model = PR_MODEL_ILP32; |
1300 | else | |
1301 | *data_model = PR_MODEL_LP64; | |
1302 | ||
1303 | return PS_OK; | |
1304 | } | |
23715f29 | 1305 | #endif /* PR_MODEL_LP64 */ |
23e04971 | 1306 | |
c906108c SS |
1307 | #ifdef TM_I386SOL2_H |
1308 | ||
d4f3574e SS |
1309 | /* Reads the local descriptor table of a LWP. */ |
1310 | ||
c906108c SS |
1311 | ps_err_e |
1312 | ps_lgetLDT (gdb_ps_prochandle_t ph, lwpid_t lwpid, | |
1313 | struct ssd *pldt) | |
1314 | { | |
05e28a7b | 1315 | /* NOTE: only used on Solaris, therefore OK to refer to procfs.c */ |
39f77062 | 1316 | extern struct ssd *procfs_find_LDT_entry (ptid_t); |
05e28a7b | 1317 | struct ssd *ret; |
c906108c | 1318 | |
2f09097b ND |
1319 | /* FIXME: can't I get the process ID from the prochandle or something? |
1320 | */ | |
1321 | ||
39f77062 | 1322 | if (PIDGET (inferior_ptid) <= 0 || lwpid <= 0) |
2f09097b ND |
1323 | return PS_BADLID; |
1324 | ||
39f77062 | 1325 | ret = procfs_find_LDT_entry (BUILD_LWP (lwpid, PIDGET (inferior_ptid))); |
05e28a7b | 1326 | if (ret) |
c906108c | 1327 | { |
05e28a7b AC |
1328 | memcpy (pldt, ret, sizeof (struct ssd)); |
1329 | return PS_OK; | |
c906108c | 1330 | } |
05e28a7b | 1331 | else /* LDT not found. */ |
c906108c | 1332 | return PS_ERR; |
c5aa993b | 1333 | } |
c906108c SS |
1334 | #endif /* TM_I386SOL2_H */ |
1335 | \f | |
1336 | /* Convert a pid to printable form. */ | |
1337 | ||
1338 | char * | |
39f77062 | 1339 | solaris_pid_to_str (ptid_t ptid) |
c906108c SS |
1340 | { |
1341 | static char buf[100]; | |
1342 | ||
1343 | /* in case init failed to resolve the libthread_db library */ | |
1344 | if (!procfs_suppress_run) | |
39f77062 | 1345 | return procfs_pid_to_str (ptid); |
c906108c | 1346 | |
39f77062 | 1347 | if (is_thread (ptid)) |
c906108c | 1348 | { |
39f77062 | 1349 | ptid_t lwp; |
c906108c | 1350 | |
39f77062 | 1351 | lwp = thread_to_lwp (ptid, -2); |
c906108c | 1352 | |
39f77062 KB |
1353 | if (PIDGET (lwp) == -1) |
1354 | sprintf (buf, "Thread %ld (defunct)", GET_THREAD (ptid)); | |
1355 | else if (PIDGET (lwp) != -2) | |
1356 | sprintf (buf, "Thread %ld (LWP %ld)", GET_THREAD (ptid), GET_LWP (lwp)); | |
c906108c | 1357 | else |
39f77062 | 1358 | sprintf (buf, "Thread %ld ", GET_THREAD (ptid)); |
c906108c | 1359 | } |
39f77062 KB |
1360 | else if (GET_LWP (ptid) != 0) |
1361 | sprintf (buf, "LWP %ld ", GET_LWP (ptid)); | |
c906108c | 1362 | else |
39f77062 | 1363 | sprintf (buf, "process %d ", PIDGET (ptid)); |
c906108c SS |
1364 | |
1365 | return buf; | |
1366 | } | |
1367 | \f | |
1368 | ||
1369 | /* Worker bee for find_new_threads | |
1370 | Callback function that gets called once per USER thread (i.e., not | |
1371 | kernel) thread. */ | |
1372 | ||
1373 | static int | |
fba45db2 | 1374 | sol_find_new_threads_callback (const td_thrhandle_t *th, void *ignored) |
c906108c SS |
1375 | { |
1376 | td_err_e retval; | |
1377 | td_thrinfo_t ti; | |
39f77062 | 1378 | ptid_t ptid; |
c906108c | 1379 | |
c5aa993b | 1380 | if ((retval = p_td_thr_get_info (th, &ti)) != TD_OK) |
c906108c SS |
1381 | { |
1382 | return -1; | |
1383 | } | |
39f77062 KB |
1384 | ptid = BUILD_THREAD (ti.ti_tid, PIDGET (inferior_ptid)); |
1385 | if (!in_thread_list (ptid)) | |
1386 | add_thread (ptid); | |
c906108c SS |
1387 | |
1388 | return 0; | |
1389 | } | |
1390 | ||
d4f3574e | 1391 | static void |
fba45db2 | 1392 | sol_find_new_threads (void) |
c906108c SS |
1393 | { |
1394 | /* don't do anything if init failed to resolve the libthread_db library */ | |
1395 | if (!procfs_suppress_run) | |
1396 | return; | |
1397 | ||
39f77062 | 1398 | if (PIDGET (inferior_ptid) == -1) |
c906108c | 1399 | { |
c5aa993b | 1400 | printf_filtered ("No process.\n"); |
c906108c SS |
1401 | return; |
1402 | } | |
39f77062 | 1403 | procfs_ops.to_find_new_threads (); /* first find new kernel threads */ |
c5aa993b | 1404 | p_td_ta_thr_iter (main_ta, sol_find_new_threads_callback, (void *) 0, |
c906108c SS |
1405 | TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY, |
1406 | TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS); | |
1407 | } | |
1408 | ||
1409 | static void | |
fba45db2 | 1410 | sol_core_open (char *filename, int from_tty) |
c906108c SS |
1411 | { |
1412 | orig_core_ops.to_open (filename, from_tty); | |
1413 | } | |
1414 | ||
1415 | static void | |
fba45db2 | 1416 | sol_core_close (int quitting) |
c906108c SS |
1417 | { |
1418 | orig_core_ops.to_close (quitting); | |
1419 | } | |
1420 | ||
1421 | static void | |
fba45db2 | 1422 | sol_core_detach (char *args, int from_tty) |
c906108c SS |
1423 | { |
1424 | unpush_target (&core_ops); | |
1425 | orig_core_ops.to_detach (args, from_tty); | |
1426 | } | |
1427 | ||
1428 | static void | |
fba45db2 | 1429 | sol_core_files_info (struct target_ops *t) |
c906108c SS |
1430 | { |
1431 | orig_core_ops.to_files_info (t); | |
1432 | } | |
1433 | ||
c906108c SS |
1434 | /* Worker bee for info sol-thread command. This is a callback function that |
1435 | gets called once for each Solaris thread (ie. not kernel thread) in the | |
1436 | inferior. Print anything interesting that we can think of. */ | |
1437 | ||
c5aa993b | 1438 | static int |
fba45db2 | 1439 | info_cb (const td_thrhandle_t *th, void *s) |
c906108c SS |
1440 | { |
1441 | td_err_e ret; | |
1442 | td_thrinfo_t ti; | |
c906108c SS |
1443 | |
1444 | if ((ret = p_td_thr_get_info (th, &ti)) == TD_OK) | |
1445 | { | |
c5aa993b JM |
1446 | printf_filtered ("%s thread #%d, lwp %d, ", |
1447 | ti.ti_type == TD_THR_SYSTEM ? "system" : "user ", | |
c906108c | 1448 | ti.ti_tid, ti.ti_lid); |
c5aa993b JM |
1449 | switch (ti.ti_state) |
1450 | { | |
c906108c | 1451 | default: |
c5aa993b JM |
1452 | case TD_THR_UNKNOWN: |
1453 | printf_filtered ("<unknown state>"); | |
1454 | break; | |
1455 | case TD_THR_STOPPED: | |
1456 | printf_filtered ("(stopped)"); | |
1457 | break; | |
1458 | case TD_THR_RUN: | |
1459 | printf_filtered ("(run) "); | |
1460 | break; | |
1461 | case TD_THR_ACTIVE: | |
1462 | printf_filtered ("(active) "); | |
1463 | break; | |
1464 | case TD_THR_ZOMBIE: | |
1465 | printf_filtered ("(zombie) "); | |
1466 | break; | |
1467 | case TD_THR_SLEEP: | |
1468 | printf_filtered ("(asleep) "); | |
1469 | break; | |
1470 | case TD_THR_STOPPED_ASLEEP: | |
1471 | printf_filtered ("(stopped asleep)"); | |
1472 | break; | |
1473 | } | |
c906108c SS |
1474 | /* Print thr_create start function: */ |
1475 | if (ti.ti_startfunc != 0) | |
4ce44c66 JM |
1476 | { |
1477 | struct minimal_symbol *msym; | |
1478 | msym = lookup_minimal_symbol_by_pc (ti.ti_startfunc); | |
1479 | if (msym) | |
22abf04a | 1480 | printf_filtered (" startfunc: %s\n", DEPRECATED_SYMBOL_NAME (msym)); |
4ce44c66 JM |
1481 | else |
1482 | printf_filtered (" startfunc: 0x%s\n", paddr (ti.ti_startfunc)); | |
1483 | } | |
c906108c SS |
1484 | |
1485 | /* If thread is asleep, print function that went to sleep: */ | |
1486 | if (ti.ti_state == TD_THR_SLEEP) | |
4ce44c66 JM |
1487 | { |
1488 | struct minimal_symbol *msym; | |
1489 | msym = lookup_minimal_symbol_by_pc (ti.ti_pc); | |
1490 | if (msym) | |
22abf04a | 1491 | printf_filtered (" - Sleep func: %s\n", DEPRECATED_SYMBOL_NAME (msym)); |
4ce44c66 JM |
1492 | else |
1493 | printf_filtered (" - Sleep func: 0x%s\n", paddr (ti.ti_startfunc)); | |
1494 | } | |
c906108c SS |
1495 | |
1496 | /* Wrap up line, if necessary */ | |
1497 | if (ti.ti_state != TD_THR_SLEEP && ti.ti_startfunc == 0) | |
1498 | printf_filtered ("\n"); /* don't you hate counting newlines? */ | |
1499 | } | |
1500 | else | |
1501 | warning ("info sol-thread: failed to get info for thread."); | |
1502 | ||
c5aa993b | 1503 | return 0; |
c906108c SS |
1504 | } |
1505 | ||
1506 | /* List some state about each Solaris user thread in the inferior. */ | |
1507 | ||
1508 | static void | |
fba45db2 | 1509 | info_solthreads (char *args, int from_tty) |
c906108c | 1510 | { |
c5aa993b | 1511 | p_td_ta_thr_iter (main_ta, info_cb, args, |
c906108c SS |
1512 | TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY, |
1513 | TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS); | |
1514 | } | |
c906108c | 1515 | |
be4d1333 MS |
1516 | static int |
1517 | sol_find_memory_regions (int (*func) (CORE_ADDR, | |
1518 | unsigned long, | |
1519 | int, int, int, | |
1520 | void *), | |
1521 | void *data) | |
1522 | { | |
1523 | return procfs_ops.to_find_memory_regions (func, data); | |
1524 | } | |
1525 | ||
1526 | static char * | |
1527 | sol_make_note_section (bfd *obfd, int *note_size) | |
1528 | { | |
1529 | return procfs_ops.to_make_corefile_notes (obfd, note_size); | |
1530 | } | |
1531 | ||
c906108c | 1532 | static int |
fba45db2 | 1533 | ignore (CORE_ADDR addr, char *contents) |
c906108c SS |
1534 | { |
1535 | return 0; | |
1536 | } | |
1537 | ||
1538 | ||
1539 | static void | |
fba45db2 | 1540 | init_sol_thread_ops (void) |
c906108c SS |
1541 | { |
1542 | sol_thread_ops.to_shortname = "solaris-threads"; | |
1543 | sol_thread_ops.to_longname = "Solaris threads and pthread."; | |
1544 | sol_thread_ops.to_doc = "Solaris threads and pthread support."; | |
1545 | sol_thread_ops.to_open = sol_thread_open; | |
c906108c SS |
1546 | sol_thread_ops.to_attach = sol_thread_attach; |
1547 | sol_thread_ops.to_detach = sol_thread_detach; | |
1548 | sol_thread_ops.to_resume = sol_thread_resume; | |
1549 | sol_thread_ops.to_wait = sol_thread_wait; | |
1550 | sol_thread_ops.to_fetch_registers = sol_thread_fetch_registers; | |
1551 | sol_thread_ops.to_store_registers = sol_thread_store_registers; | |
1552 | sol_thread_ops.to_prepare_to_store = sol_thread_prepare_to_store; | |
1553 | sol_thread_ops.to_xfer_memory = sol_thread_xfer_memory; | |
1554 | sol_thread_ops.to_files_info = sol_thread_files_info; | |
1555 | sol_thread_ops.to_insert_breakpoint = memory_insert_breakpoint; | |
1556 | sol_thread_ops.to_remove_breakpoint = memory_remove_breakpoint; | |
1557 | sol_thread_ops.to_terminal_init = terminal_init_inferior; | |
1558 | sol_thread_ops.to_terminal_inferior = terminal_inferior; | |
1559 | sol_thread_ops.to_terminal_ours_for_output = terminal_ours_for_output; | |
1560 | sol_thread_ops.to_terminal_ours = terminal_ours; | |
a790ad35 | 1561 | sol_thread_ops.to_terminal_save_ours = terminal_save_ours; |
c906108c SS |
1562 | sol_thread_ops.to_terminal_info = child_terminal_info; |
1563 | sol_thread_ops.to_kill = sol_thread_kill_inferior; | |
c906108c SS |
1564 | sol_thread_ops.to_create_inferior = sol_thread_create_inferior; |
1565 | sol_thread_ops.to_mourn_inferior = sol_thread_mourn_inferior; | |
1566 | sol_thread_ops.to_can_run = sol_thread_can_run; | |
1567 | sol_thread_ops.to_notice_signals = sol_thread_notice_signals; | |
1568 | sol_thread_ops.to_thread_alive = sol_thread_alive; | |
ed9a39eb | 1569 | sol_thread_ops.to_pid_to_str = solaris_pid_to_str; |
b83266a0 | 1570 | sol_thread_ops.to_find_new_threads = sol_find_new_threads; |
c906108c SS |
1571 | sol_thread_ops.to_stop = sol_thread_stop; |
1572 | sol_thread_ops.to_stratum = process_stratum; | |
1573 | sol_thread_ops.to_has_all_memory = 1; | |
1574 | sol_thread_ops.to_has_memory = 1; | |
1575 | sol_thread_ops.to_has_stack = 1; | |
1576 | sol_thread_ops.to_has_registers = 1; | |
1577 | sol_thread_ops.to_has_execution = 1; | |
1578 | sol_thread_ops.to_has_thread_control = tc_none; | |
be4d1333 MS |
1579 | sol_thread_ops.to_find_memory_regions = sol_find_memory_regions; |
1580 | sol_thread_ops.to_make_corefile_notes = sol_make_note_section; | |
c906108c SS |
1581 | sol_thread_ops.to_magic = OPS_MAGIC; |
1582 | } | |
1583 | ||
1584 | ||
1585 | static void | |
fba45db2 | 1586 | init_sol_core_ops (void) |
c906108c | 1587 | { |
c5aa993b JM |
1588 | sol_core_ops.to_shortname = "solaris-core"; |
1589 | sol_core_ops.to_longname = "Solaris core threads and pthread."; | |
1590 | sol_core_ops.to_doc = "Solaris threads and pthread support for core files."; | |
1591 | sol_core_ops.to_open = sol_core_open; | |
1592 | sol_core_ops.to_close = sol_core_close; | |
1593 | sol_core_ops.to_attach = sol_thread_attach; | |
1594 | sol_core_ops.to_detach = sol_core_detach; | |
c5aa993b | 1595 | sol_core_ops.to_fetch_registers = sol_thread_fetch_registers; |
c5aa993b JM |
1596 | sol_core_ops.to_xfer_memory = sol_thread_xfer_memory; |
1597 | sol_core_ops.to_files_info = sol_core_files_info; | |
1598 | sol_core_ops.to_insert_breakpoint = ignore; | |
1599 | sol_core_ops.to_remove_breakpoint = ignore; | |
c5aa993b JM |
1600 | sol_core_ops.to_create_inferior = sol_thread_create_inferior; |
1601 | sol_core_ops.to_stratum = core_stratum; | |
c5aa993b JM |
1602 | sol_core_ops.to_has_memory = 1; |
1603 | sol_core_ops.to_has_stack = 1; | |
1604 | sol_core_ops.to_has_registers = 1; | |
c5aa993b | 1605 | sol_core_ops.to_has_thread_control = tc_none; |
db348f27 | 1606 | sol_core_ops.to_thread_alive = sol_thread_alive; |
ed9a39eb | 1607 | sol_core_ops.to_pid_to_str = solaris_pid_to_str; |
db348f27 ND |
1608 | /* On Solaris/x86, when debugging a threaded core file from process <n>, |
1609 | the following causes "info threads" to produce "procfs: couldn't find pid | |
1610 | <n> in procinfo list" where <n> is the pid of the process that produced | |
1611 | the core file. Disable it for now. */ | |
1612 | /* sol_core_ops.to_find_new_threads = sol_find_new_threads; */ | |
c5aa993b | 1613 | sol_core_ops.to_magic = OPS_MAGIC; |
c906108c SS |
1614 | } |
1615 | ||
1616 | /* we suppress the call to add_target of core_ops in corelow because | |
1617 | if there are two targets in the stratum core_stratum, find_core_target | |
1618 | won't know which one to return. see corelow.c for an additonal | |
1619 | comment on coreops_suppress_target. */ | |
1620 | int coreops_suppress_target = 1; | |
1621 | ||
1622 | void | |
fba45db2 | 1623 | _initialize_sol_thread (void) |
c906108c SS |
1624 | { |
1625 | void *dlhandle; | |
1626 | ||
1627 | init_sol_thread_ops (); | |
1628 | init_sol_core_ops (); | |
1629 | ||
1630 | dlhandle = dlopen ("libthread_db.so.1", RTLD_NOW); | |
1631 | if (!dlhandle) | |
1632 | goto die; | |
1633 | ||
1634 | #define resolve(X) \ | |
1635 | if (!(p_##X = dlsym (dlhandle, #X))) \ | |
1636 | goto die; | |
1637 | ||
1638 | resolve (td_log); | |
1639 | resolve (td_ta_new); | |
1640 | resolve (td_ta_delete); | |
1641 | resolve (td_init); | |
1642 | resolve (td_ta_get_ph); | |
1643 | resolve (td_ta_get_nthreads); | |
1644 | resolve (td_ta_tsd_iter); | |
1645 | resolve (td_ta_thr_iter); | |
1646 | resolve (td_thr_validate); | |
1647 | resolve (td_thr_tsd); | |
1648 | resolve (td_thr_get_info); | |
1649 | resolve (td_thr_getfpregs); | |
1650 | resolve (td_thr_getxregsize); | |
1651 | resolve (td_thr_getxregs); | |
1652 | resolve (td_thr_sigsetmask); | |
1653 | resolve (td_thr_setprio); | |
1654 | resolve (td_thr_setsigpending); | |
1655 | resolve (td_thr_setfpregs); | |
1656 | resolve (td_thr_setxregs); | |
1657 | resolve (td_ta_map_id2thr); | |
1658 | resolve (td_ta_map_lwp2thr); | |
1659 | resolve (td_thr_getgregs); | |
1660 | resolve (td_thr_setgregs); | |
1661 | ||
1662 | add_target (&sol_thread_ops); | |
1663 | ||
1664 | procfs_suppress_run = 1; | |
1665 | ||
c5aa993b JM |
1666 | add_cmd ("sol-threads", class_maintenance, info_solthreads, |
1667 | "Show info on Solaris user threads.\n", &maintenanceinfolist); | |
c906108c | 1668 | |
c5aa993b JM |
1669 | memcpy (&orig_core_ops, &core_ops, sizeof (struct target_ops)); |
1670 | memcpy (&core_ops, &sol_core_ops, sizeof (struct target_ops)); | |
c906108c SS |
1671 | add_target (&core_ops); |
1672 | ||
11cf8741 JM |
1673 | /* Hook into new_objfile notification. */ |
1674 | target_new_objfile_chain = target_new_objfile_hook; | |
1675 | target_new_objfile_hook = sol_thread_new_objfile; | |
c906108c SS |
1676 | return; |
1677 | ||
c5aa993b | 1678 | die: |
c906108c SS |
1679 | |
1680 | fprintf_unfiltered (gdb_stderr, "[GDB will not be able to debug user-mode threads: %s]\n", dlerror ()); | |
1681 | ||
1682 | if (dlhandle) | |
1683 | dlclose (dlhandle); | |
1684 | ||
1685 | /* allow the user to debug non-threaded core files */ | |
c5aa993b | 1686 | add_target (&core_ops); |
c906108c SS |
1687 | |
1688 | return; | |
1689 | } |