Commit | Line | Data |
---|---|---|
8fc2b417 SG |
1 | /* Low level interface for debugging Solaris threads for GDB, the GNU debugger. |
2 | Copyright 1996 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
a50cedad SG |
20 | /* This module implements a sort of half target that sits between the |
21 | machine-independent parts of GDB and the /proc interface (procfs.c) to | |
22 | provide access to the Solaris user-mode thread implementation. | |
23 | ||
24 | Solaris threads are true user-mode threads, which are invoked via the thr_* | |
25 | and pthread_* (native and Posix respectivly) interfaces. These are mostly | |
26 | implemented in user-space, with all thread context kept in various | |
27 | structures that live in the user's heap. These should not be confused with | |
28 | lightweight processes (LWPs), which are implemented by the kernel, and | |
29 | scheduled without explicit intervention by the process. | |
30 | ||
31 | Just to confuse things a little, Solaris threads (both native and Posix) are | |
32 | actually implemented using LWPs. In general, there are going to be more | |
33 | threads than LWPs. There is no fixed correspondence between a thread and an | |
34 | LWP. When a thread wants to run, it gets scheduled onto the first available | |
35 | LWP and can therefore migrate from one LWP to another as time goes on. A | |
36 | sleeping thread may not be associated with an LWP at all! | |
37 | ||
38 | To make it possible to mess with threads, Sun provides a library called | |
39 | libthread_db.so.1 (not to be confused with libthread_db.so.0, which doesn't | |
40 | have a published interface). This interface has an upper part, which it | |
41 | provides, and a lower part which I provide. The upper part consists of the | |
42 | td_* routines, which allow me to find all the threads, query their state, | |
43 | etc... The lower part consists of all of the ps_*, which are used by the | |
44 | td_* routines to read/write memory, manipulate LWPs, lookup symbols, etc... | |
45 | The ps_* routines actually do most of their work by calling functions in | |
46 | procfs.c. */ | |
47 | ||
8fc2b417 SG |
48 | #include "defs.h" |
49 | ||
934741a1 SG |
50 | /* Undefine gregset_t and fpregset_t to avoid conflict with defs in xm file. */ |
51 | ||
8fc2b417 SG |
52 | #ifdef gregset_t |
53 | #undef gregset_t | |
54 | #endif | |
55 | ||
56 | #ifdef fpregset_t | |
57 | #undef fpregset_t | |
58 | #endif | |
59 | ||
934741a1 | 60 | #include <thread.h> |
8fc2b417 SG |
61 | #include <proc_service.h> |
62 | #include <thread_db.h> | |
fdfa3315 | 63 | #include "gdbthread.h" |
8fc2b417 SG |
64 | #include "target.h" |
65 | #include "inferior.h" | |
66 | #include <fcntl.h> | |
67 | #include <unistd.h> | |
68 | #include <sys/stat.h> | |
4915acad | 69 | #include <dlfcn.h> |
8fc2b417 | 70 | |
8fc2b417 SG |
71 | extern struct target_ops sol_thread_ops; /* Forward declaration */ |
72 | ||
73 | extern int procfs_suppress_run; | |
934741a1 | 74 | extern struct target_ops procfs_ops; /* target vector for procfs.c */ |
3780c337 | 75 | extern char *procfs_pid_to_str PARAMS ((int pid)); |
934741a1 | 76 | |
a50cedad SG |
77 | /* Note that these prototypes differ slightly from those used in procfs.c |
78 | for of two reasons. One, we can't use gregset_t, as that's got a whole | |
79 | different meaning under Solaris (also, see above). Two, we can't use the | |
80 | pointer form here as these are actually arrays of ints (for Sparc's at | |
81 | least), and are automatically coerced into pointers to ints when used as | |
82 | parameters. That makes it impossible to avoid a compiler warning when | |
83 | passing pr{g fp}regset_t's from a parameter to an argument of one of | |
84 | these functions. */ | |
85 | ||
934741a1 SG |
86 | extern void supply_gregset PARAMS ((const prgregset_t)); |
87 | extern void fill_gregset PARAMS ((prgregset_t, int)); | |
88 | extern void supply_fpregset PARAMS ((const prfpregset_t)); | |
89 | extern void fill_fpregset PARAMS ((prfpregset_t, int)); | |
8fc2b417 | 90 | |
a50cedad SG |
91 | /* This struct is defined by us, but mainly used for the proc_service interface. |
92 | We don't have much use for it, except as a handy place to get a real pid | |
93 | for memory accesses. */ | |
94 | ||
8fc2b417 SG |
95 | struct ps_prochandle |
96 | { | |
97 | pid_t pid; | |
98 | }; | |
99 | ||
934741a1 SG |
100 | struct string_map |
101 | { | |
102 | int num; | |
103 | char *str; | |
104 | }; | |
105 | ||
8fc2b417 SG |
106 | static struct ps_prochandle main_ph; |
107 | static td_thragent_t *main_ta; | |
8fc2b417 SG |
108 | static int sol_thread_active = 0; |
109 | ||
934741a1 SG |
110 | static struct cleanup * save_inferior_pid PARAMS ((void)); |
111 | static void restore_inferior_pid PARAMS ((int pid)); | |
112 | static char *td_err_string PARAMS ((td_err_e errcode)); | |
113 | static char *td_state_string PARAMS ((td_thr_state_e statecode)); | |
3780c337 | 114 | static int thread_to_lwp PARAMS ((int thread_id, int default_lwp)); |
934741a1 SG |
115 | static void sol_thread_resume PARAMS ((int pid, int step, |
116 | enum target_signal signo)); | |
117 | static int lwp_to_thread PARAMS ((int lwp)); | |
3780c337 | 118 | static int sol_thread_alive PARAMS ((int pid)); |
934741a1 SG |
119 | |
120 | #define THREAD_FLAG 0x80000000 | |
121 | #define is_thread(ARG) (((ARG) & THREAD_FLAG) != 0) | |
122 | #define is_lwp(ARG) (((ARG) & THREAD_FLAG) == 0) | |
123 | #define GET_LWP(LWP_ID) (TIDGET(LWP_ID)) | |
124 | #define GET_THREAD(THREAD_ID) (((THREAD_ID) >> 16) & 0x7fff) | |
125 | #define BUILD_LWP(LWP_ID, PID) ((LWP_ID) << 16 | (PID)) | |
126 | #define BUILD_THREAD(THREAD_ID, PID) (THREAD_FLAG | BUILD_LWP (THREAD_ID, PID)) | |
4915acad SG |
127 | |
128 | /* Pointers to routines from lithread_db resolved by dlopen() */ | |
129 | ||
130 | static void | |
131 | (*p_td_log) (const int on_off); | |
132 | static td_err_e | |
133 | (*p_td_ta_new) (const struct ps_prochandle *ph_p, td_thragent_t **ta_pp); | |
134 | static td_err_e | |
135 | (*p_td_ta_delete) (td_thragent_t *ta_p); | |
136 | static td_err_e | |
137 | (*p_td_init) (void); | |
138 | static td_err_e | |
139 | (*p_td_ta_get_ph) (const td_thragent_t *ta_p, struct ps_prochandle **ph_pp); | |
140 | static td_err_e | |
141 | (*p_td_ta_get_nthreads) (const td_thragent_t *ta_p, int *nthread_p); | |
142 | static td_err_e | |
143 | (*p_td_ta_tsd_iter) (const td_thragent_t *ta_p, td_key_iter_f *cb, void *cbdata_p); | |
144 | static td_err_e | |
145 | (*p_td_ta_thr_iter) (const td_thragent_t *ta_p, td_thr_iter_f *cb, void *cbdata_p, td_thr_state_e state, | |
146 | int ti_pri, sigset_t *ti_sigmask_p, unsigned ti_user_flags); | |
147 | static td_err_e | |
148 | (*p_td_thr_validate) (const td_thrhandle_t *th_p); | |
149 | static td_err_e | |
150 | (*p_td_thr_tsd) (const td_thrhandle_t *th_p, const thread_key_t key, void **data_pp); | |
151 | static td_err_e | |
152 | (*p_td_thr_get_info) (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p); | |
153 | static td_err_e | |
154 | (*p_td_thr_getfpregs) (const td_thrhandle_t *th_p, prfpregset_t *fpregset); | |
155 | static td_err_e | |
156 | (*p_td_thr_getxregsize) (const td_thrhandle_t *th_p, int *xregsize); | |
157 | static td_err_e | |
158 | (*p_td_thr_getxregs) (const td_thrhandle_t *th_p, const caddr_t xregset); | |
159 | static td_err_e | |
160 | (*p_td_thr_sigsetmask) (const td_thrhandle_t *th_p, const sigset_t ti_sigmask); | |
161 | static td_err_e | |
162 | (*p_td_thr_setprio) (const td_thrhandle_t *th_p, const int ti_pri); | |
163 | static td_err_e | |
164 | (*p_td_thr_setsigpending) (const td_thrhandle_t *th_p, const uchar_t ti_pending_flag, const sigset_t ti_pending); | |
165 | static td_err_e | |
166 | (*p_td_thr_setfpregs) (const td_thrhandle_t *th_p, const prfpregset_t *fpregset); | |
167 | static td_err_e | |
168 | (*p_td_thr_setxregs) (const td_thrhandle_t *th_p, const caddr_t xregset); | |
169 | static td_err_e | |
170 | (*p_td_ta_map_id2thr) (const td_thragent_t *ta_p, thread_t tid, td_thrhandle_t *th_p); | |
171 | static td_err_e | |
172 | (*p_td_ta_map_lwp2thr) (const td_thragent_t *ta_p, lwpid_t lwpid, td_thrhandle_t *th_p); | |
173 | static td_err_e | |
174 | (*p_td_thr_getgregs) (const td_thrhandle_t *th_p, prgregset_t regset); | |
175 | static td_err_e | |
176 | (*p_td_thr_setgregs) (const td_thrhandle_t *th_p, const prgregset_t regset); | |
8fc2b417 | 177 | \f |
934741a1 SG |
178 | /* |
179 | ||
180 | LOCAL FUNCTION | |
181 | ||
182 | td_err_string - Convert a thread_db error code to a string | |
183 | ||
184 | SYNOPSIS | |
185 | ||
186 | char * td_err_string (errcode) | |
187 | ||
188 | DESCRIPTION | |
189 | ||
190 | Return the thread_db error string associated with errcode. If errcode | |
191 | is unknown, then return a message. | |
192 | ||
193 | */ | |
194 | ||
195 | static char * | |
196 | td_err_string (errcode) | |
197 | td_err_e errcode; | |
198 | { | |
199 | static struct string_map | |
200 | td_err_table[] = { | |
201 | {TD_OK, "generic \"call succeeded\""}, | |
202 | {TD_ERR, "generic error."}, | |
203 | {TD_NOTHR, "no thread can be found to satisfy query"}, | |
204 | {TD_NOSV, "no synch. variable can be found to satisfy query"}, | |
205 | {TD_NOLWP, "no lwp can be found to satisfy query"}, | |
206 | {TD_BADPH, "invalid process handle"}, | |
207 | {TD_BADTH, "invalid thread handle"}, | |
208 | {TD_BADSH, "invalid synchronization handle"}, | |
209 | {TD_BADTA, "invalid thread agent"}, | |
210 | {TD_BADKEY, "invalid key"}, | |
211 | {TD_NOMSG, "td_thr_event_getmsg() called when there was no message"}, | |
212 | {TD_NOFPREGS, "FPU register set not available for given thread"}, | |
213 | {TD_NOLIBTHREAD, "application not linked with libthread"}, | |
214 | {TD_NOEVENT, "requested event is not supported"}, | |
215 | {TD_NOCAPAB, "capability not available"}, | |
216 | {TD_DBERR, "Debugger service failed"}, | |
217 | {TD_NOAPLIC, "Operation not applicable to"}, | |
218 | {TD_NOTSD, "No thread specific data for this thread"}, | |
219 | {TD_MALLOC, "Malloc failed"}, | |
220 | {TD_PARTIALREG, "Only part of register set was writen/read"}, | |
221 | {TD_NOXREGS, "X register set not available for given thread"} | |
222 | }; | |
223 | const int td_err_size = sizeof td_err_table / sizeof (struct string_map); | |
224 | int i; | |
225 | static char buf[50]; | |
226 | ||
227 | for (i = 0; i < td_err_size; i++) | |
228 | if (td_err_table[i].num == errcode) | |
229 | return td_err_table[i].str; | |
230 | ||
231 | sprintf (buf, "Unknown thread_db error code: %d", errcode); | |
8fc2b417 | 232 | |
934741a1 SG |
233 | return buf; |
234 | } | |
235 | \f | |
236 | /* | |
8fc2b417 | 237 | |
934741a1 | 238 | LOCAL FUNCTION |
8fc2b417 | 239 | |
934741a1 SG |
240 | td_state_string - Convert a thread_db state code to a string |
241 | ||
242 | SYNOPSIS | |
243 | ||
244 | char * td_state_string (statecode) | |
245 | ||
246 | DESCRIPTION | |
247 | ||
248 | Return the thread_db state string associated with statecode. If | |
249 | statecode is unknown, then return a message. | |
250 | ||
251 | */ | |
252 | ||
253 | static char * | |
254 | td_state_string (statecode) | |
255 | td_thr_state_e statecode; | |
256 | { | |
257 | static struct string_map | |
258 | td_thr_state_table[] = { | |
259 | {TD_THR_ANY_STATE, "any state"}, | |
260 | {TD_THR_UNKNOWN, "unknown"}, | |
261 | {TD_THR_STOPPED, "stopped"}, | |
262 | {TD_THR_RUN, "run"}, | |
263 | {TD_THR_ACTIVE, "active"}, | |
264 | {TD_THR_ZOMBIE, "zombie"}, | |
265 | {TD_THR_SLEEP, "sleep"}, | |
266 | {TD_THR_STOPPED_ASLEEP, "stopped asleep"} | |
267 | }; | |
268 | const int td_thr_state_table_size = sizeof td_thr_state_table / sizeof (struct string_map); | |
269 | int i; | |
270 | static char buf[50]; | |
271 | ||
272 | for (i = 0; i < td_thr_state_table_size; i++) | |
273 | if (td_thr_state_table[i].num == statecode) | |
274 | return td_thr_state_table[i].str; | |
275 | ||
276 | sprintf (buf, "Unknown thread_db state code: %d", statecode); | |
277 | ||
278 | return buf; | |
279 | } | |
280 | \f | |
281 | /* | |
282 | ||
283 | LOCAL FUNCTION | |
284 | ||
285 | thread_to_lwp - Convert a Posix or Solaris thread id to a LWP id. | |
286 | ||
287 | SYNOPSIS | |
288 | ||
289 | int thread_to_lwp (thread_id, default_lwp) | |
290 | ||
291 | DESCRIPTION | |
292 | ||
293 | This function converts a Posix or Solaris thread id to a lightweight | |
294 | process id. If thread_id is non-existent, that's an error. If it's | |
295 | an inactive thread, then we return default_lwp. | |
296 | ||
297 | NOTES | |
298 | ||
299 | This function probably shouldn't call error()... | |
300 | ||
301 | */ | |
8fc2b417 SG |
302 | |
303 | static int | |
304 | thread_to_lwp (thread_id, default_lwp) | |
305 | int thread_id; | |
306 | int default_lwp; | |
307 | { | |
308 | td_thrinfo_t ti; | |
309 | td_thrhandle_t th; | |
310 | td_err_e val; | |
8fc2b417 | 311 | |
934741a1 | 312 | if (is_lwp (thread_id)) |
8fc2b417 SG |
313 | return thread_id; /* It's already an LWP id */ |
314 | ||
315 | /* It's a thread. Convert to lwp */ | |
316 | ||
3780c337 MS |
317 | val = p_td_ta_map_id2thr (main_ta, GET_THREAD (thread_id), &th); |
318 | if (val == TD_NOTHR) | |
319 | return -1; /* thread must have terminated */ | |
320 | else if (val != TD_OK) | |
934741a1 | 321 | error ("thread_to_lwp: td_ta_map_id2thr %s", td_err_string (val)); |
8fc2b417 | 322 | |
4915acad | 323 | val = p_td_thr_get_info (&th, &ti); |
3780c337 MS |
324 | if (val == TD_NOTHR) |
325 | return -1; /* thread must have terminated */ | |
326 | else if (val != TD_OK) | |
934741a1 | 327 | error ("thread_to_lwp: td_thr_get_info: %s", td_err_string (val)); |
8fc2b417 SG |
328 | |
329 | if (ti.ti_state != TD_THR_ACTIVE) | |
330 | { | |
331 | if (default_lwp != -1) | |
332 | return default_lwp; | |
934741a1 SG |
333 | error ("thread_to_lwp: thread state not active: %s", |
334 | td_state_string (ti.ti_state)); | |
8fc2b417 | 335 | } |
8fc2b417 | 336 | |
3780c337 | 337 | return BUILD_LWP (ti.ti_lid, PIDGET (thread_id)); |
8fc2b417 | 338 | } |
a50cedad SG |
339 | \f |
340 | /* | |
341 | ||
342 | LOCAL FUNCTION | |
343 | ||
344 | lwp_to_thread - Convert a LWP id to a Posix or Solaris thread id. | |
345 | ||
346 | SYNOPSIS | |
347 | ||
348 | int lwp_to_thread (lwp_id) | |
8fc2b417 | 349 | |
a50cedad SG |
350 | DESCRIPTION |
351 | ||
352 | This function converts a lightweight process id to a Posix or Solaris | |
353 | thread id. If thread_id is non-existent, that's an error. | |
354 | ||
355 | NOTES | |
356 | ||
357 | This function probably shouldn't call error()... | |
358 | ||
359 | */ | |
8fc2b417 | 360 | |
8fc2b417 SG |
361 | static int |
362 | lwp_to_thread (lwp) | |
363 | int lwp; | |
364 | { | |
365 | td_thrinfo_t ti; | |
366 | td_thrhandle_t th; | |
367 | td_err_e val; | |
8fc2b417 | 368 | |
934741a1 | 369 | if (is_thread (lwp)) |
8fc2b417 SG |
370 | return lwp; /* It's already a thread id */ |
371 | ||
372 | /* It's an lwp. Convert it to a thread id. */ | |
373 | ||
3780c337 MS |
374 | if (!sol_thread_alive (lwp)) |
375 | return -1; /* defunct lwp */ | |
8fc2b417 | 376 | |
3780c337 MS |
377 | val = p_td_ta_map_lwp2thr (main_ta, GET_LWP (lwp), &th); |
378 | if (val == TD_NOTHR) | |
379 | return -1; /* thread must have terminated */ | |
380 | else if (val != TD_OK) | |
934741a1 | 381 | error ("lwp_to_thread: td_thr_get_info: %s.", td_err_string (val)); |
8fc2b417 | 382 | |
3780c337 MS |
383 | val = p_td_thr_validate (&th); |
384 | if (val == TD_NOTHR) | |
385 | return lwp; /* libthread doesn't know about it, just return lwp */ | |
386 | else if (val != TD_OK) | |
387 | error ("lwp_to_thread: td_thr_validate: %s.", td_err_string (val)); | |
8fc2b417 | 388 | |
3780c337 MS |
389 | val = p_td_thr_get_info (&th, &ti); |
390 | if (val == TD_NOTHR) | |
391 | return -1; /* thread must have terminated */ | |
392 | else if (val != TD_OK) | |
934741a1 | 393 | error ("lwp_to_thread: td_thr_get_info: %s.", td_err_string (val)); |
8fc2b417 | 394 | |
3780c337 | 395 | return BUILD_THREAD (ti.ti_tid, PIDGET (lwp)); |
8fc2b417 | 396 | } |
934741a1 | 397 | \f |
a50cedad SG |
398 | /* |
399 | ||
400 | LOCAL FUNCTION | |
401 | ||
402 | save_inferior_pid - Save inferior_pid on the cleanup list | |
403 | restore_inferior_pid - Restore inferior_pid from the cleanup list | |
404 | ||
405 | SYNOPSIS | |
406 | ||
407 | struct cleanup *save_inferior_pid () | |
408 | void restore_inferior_pid (int pid) | |
409 | ||
410 | DESCRIPTION | |
411 | ||
412 | These two functions act in unison to restore inferior_pid in | |
413 | case of an error. | |
414 | ||
415 | NOTES | |
416 | ||
417 | inferior_pid is a global variable that needs to be changed by many of | |
418 | these routines before calling functions in procfs.c. In order to | |
419 | guarantee that inferior_pid gets restored (in case of errors), you | |
420 | need to call save_inferior_pid before changing it. At the end of the | |
421 | function, you should invoke do_cleanups to restore it. | |
422 | ||
423 | */ | |
424 | ||
425 | ||
934741a1 SG |
426 | static struct cleanup * |
427 | save_inferior_pid () | |
428 | { | |
429 | return make_cleanup (restore_inferior_pid, inferior_pid); | |
430 | } | |
8fc2b417 | 431 | |
934741a1 SG |
432 | static void |
433 | restore_inferior_pid (pid) | |
434 | int pid; | |
435 | { | |
436 | inferior_pid = pid; | |
437 | } | |
438 | \f | |
a50cedad SG |
439 | |
440 | /* Most target vector functions from here on actually just pass through to | |
441 | procfs.c, as they don't need to do anything specific for threads. */ | |
442 | ||
443 | ||
8fc2b417 SG |
444 | /* ARGSUSED */ |
445 | static void | |
446 | sol_thread_open (arg, from_tty) | |
447 | char *arg; | |
448 | int from_tty; | |
449 | { | |
450 | procfs_ops.to_open (arg, from_tty); | |
451 | } | |
452 | ||
453 | /* Attach to process PID, then initialize for debugging it | |
454 | and wait for the trace-trap that results from attaching. */ | |
455 | ||
456 | static void | |
457 | sol_thread_attach (args, from_tty) | |
458 | char *args; | |
459 | int from_tty; | |
460 | { | |
461 | procfs_ops.to_attach (args, from_tty); | |
3780c337 MS |
462 | /* Must get symbols from solibs before libthread_db can run! */ |
463 | SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0); | |
464 | if (sol_thread_active) | |
465 | { | |
466 | printf_filtered ("sol-thread active.\n"); | |
467 | main_ph.pid = inferior_pid; /* Save for xfer_memory */ | |
468 | push_target (&sol_thread_ops); | |
469 | inferior_pid = lwp_to_thread (inferior_pid); | |
470 | if (inferior_pid == -1) | |
471 | inferior_pid = main_ph.pid; | |
472 | else | |
473 | add_thread (inferior_pid); | |
474 | } | |
8fc2b417 SG |
475 | /* XXX - might want to iterate over all the threads and register them. */ |
476 | } | |
477 | ||
478 | /* Take a program previously attached to and detaches it. | |
479 | The program resumes execution and will no longer stop | |
480 | on signals, etc. We'd better not have left any breakpoints | |
481 | in the program or it'll die when it hits one. For this | |
482 | to work, it may be necessary for the process to have been | |
483 | previously attached. It *might* work if the program was | |
484 | started via the normal ptrace (PTRACE_TRACEME). */ | |
485 | ||
486 | static void | |
487 | sol_thread_detach (args, from_tty) | |
488 | char *args; | |
489 | int from_tty; | |
490 | { | |
3780c337 | 491 | unpush_target (&sol_thread_ops); |
8fc2b417 SG |
492 | procfs_ops.to_detach (args, from_tty); |
493 | } | |
494 | ||
495 | /* Resume execution of process PID. If STEP is nozero, then | |
496 | just single step it. If SIGNAL is nonzero, restart it with that | |
a50cedad SG |
497 | signal activated. We may have to convert pid from a thread-id to an LWP id |
498 | for procfs. */ | |
8fc2b417 SG |
499 | |
500 | static void | |
501 | sol_thread_resume (pid, step, signo) | |
502 | int pid; | |
503 | int step; | |
504 | enum target_signal signo; | |
505 | { | |
934741a1 | 506 | struct cleanup *old_chain; |
8fc2b417 | 507 | |
934741a1 | 508 | old_chain = save_inferior_pid (); |
8fc2b417 SG |
509 | |
510 | inferior_pid = thread_to_lwp (inferior_pid, main_ph.pid); | |
3780c337 MS |
511 | if (inferior_pid == -1) |
512 | inferior_pid = procfs_first_available (); | |
8fc2b417 SG |
513 | |
514 | if (pid != -1) | |
a50cedad | 515 | { |
3780c337 MS |
516 | int save_pid = pid; |
517 | ||
a50cedad SG |
518 | pid = thread_to_lwp (pid, -2); |
519 | if (pid == -2) /* Inactive thread */ | |
520 | error ("This version of Solaris can't start inactive threads."); | |
3780c337 MS |
521 | if (info_verbose && pid == -1) |
522 | warning ("Specified thread %d seems to have terminated", | |
523 | GET_THREAD (save_pid)); | |
a50cedad | 524 | } |
8fc2b417 SG |
525 | |
526 | procfs_ops.to_resume (pid, step, signo); | |
527 | ||
934741a1 | 528 | do_cleanups (old_chain); |
8fc2b417 SG |
529 | } |
530 | ||
a50cedad SG |
531 | /* Wait for any threads to stop. We may have to convert PID from a thread id |
532 | to a LWP id, and vice versa on the way out. */ | |
8fc2b417 SG |
533 | |
534 | static int | |
535 | sol_thread_wait (pid, ourstatus) | |
536 | int pid; | |
537 | struct target_waitstatus *ourstatus; | |
538 | { | |
8fc2b417 SG |
539 | int rtnval; |
540 | int save_pid; | |
934741a1 | 541 | struct cleanup *old_chain; |
8fc2b417 | 542 | |
8fc2b417 | 543 | save_pid = inferior_pid; |
934741a1 | 544 | old_chain = save_inferior_pid (); |
8fc2b417 SG |
545 | |
546 | inferior_pid = thread_to_lwp (inferior_pid, main_ph.pid); | |
3780c337 MS |
547 | if (inferior_pid == -1) |
548 | inferior_pid = procfs_first_available (); | |
8fc2b417 SG |
549 | |
550 | if (pid != -1) | |
3780c337 MS |
551 | { |
552 | int save_pid = pid; | |
553 | ||
554 | pid = thread_to_lwp (pid, -2); | |
555 | if (pid == -2) /* Inactive thread */ | |
556 | error ("This version of Solaris can't start inactive threads."); | |
557 | if (info_verbose && pid == -1) | |
558 | warning ("Specified thread %d seems to have terminated", | |
559 | GET_THREAD (save_pid)); | |
560 | } | |
8fc2b417 SG |
561 | |
562 | rtnval = procfs_ops.to_wait (pid, ourstatus); | |
563 | ||
3780c337 | 564 | if (ourstatus->kind != TARGET_WAITKIND_EXITED) |
8fc2b417 | 565 | { |
3780c337 MS |
566 | /* Map the LWP of interest back to the appropriate thread ID */ |
567 | rtnval = lwp_to_thread (rtnval); | |
568 | if (rtnval == -1) | |
569 | rtnval = save_pid; | |
570 | ||
571 | /* See if we have a new thread */ | |
572 | if (is_thread (rtnval) | |
573 | && rtnval != save_pid | |
574 | && !in_thread_list (rtnval)) | |
575 | { | |
576 | printf_filtered ("[New %s]\n", target_pid_to_str (rtnval)); | |
577 | add_thread (rtnval); | |
578 | } | |
8fc2b417 SG |
579 | } |
580 | ||
8fc2b417 SG |
581 | /* During process initialization, we may get here without the thread package |
582 | being initialized, since that can only happen after we've found the shared | |
583 | libs. */ | |
584 | ||
934741a1 SG |
585 | do_cleanups (old_chain); |
586 | ||
8fc2b417 SG |
587 | return rtnval; |
588 | } | |
589 | ||
590 | static void | |
591 | sol_thread_fetch_registers (regno) | |
592 | int regno; | |
593 | { | |
594 | thread_t thread; | |
595 | td_thrhandle_t thandle; | |
596 | td_err_e val; | |
9b33e492 | 597 | prgregset_t gregset; |
8fc2b417 | 598 | prfpregset_t fpregset; |
934741a1 | 599 | #if 0 |
8fc2b417 SG |
600 | int xregsize; |
601 | caddr_t xregset; | |
934741a1 | 602 | #endif |
8fc2b417 | 603 | |
8fc2b417 SG |
604 | /* Convert inferior_pid into a td_thrhandle_t */ |
605 | ||
934741a1 | 606 | thread = GET_THREAD (inferior_pid); |
8fc2b417 SG |
607 | |
608 | if (thread == 0) | |
609 | error ("sol_thread_fetch_registers: thread == 0"); | |
610 | ||
4915acad | 611 | val = p_td_ta_map_id2thr (main_ta, thread, &thandle); |
8fc2b417 | 612 | if (val != TD_OK) |
934741a1 SG |
613 | error ("sol_thread_fetch_registers: td_ta_map_id2thr: %s", |
614 | td_err_string (val)); | |
8fc2b417 SG |
615 | |
616 | /* Get the integer regs */ | |
617 | ||
4915acad | 618 | val = p_td_thr_getgregs (&thandle, gregset); |
9b33e492 SG |
619 | if (val != TD_OK |
620 | && val != TD_PARTIALREG) | |
934741a1 SG |
621 | error ("sol_thread_fetch_registers: td_thr_getgregs %s", |
622 | td_err_string (val)); | |
8fc2b417 | 623 | |
9b33e492 SG |
624 | /* For the sparc, TD_PARTIALREG means that only i0->i7, l0->l7, pc and sp |
625 | are saved (by a thread context switch). */ | |
626 | ||
8fc2b417 SG |
627 | /* And, now the fp regs */ |
628 | ||
4915acad | 629 | val = p_td_thr_getfpregs (&thandle, &fpregset); |
9b33e492 SG |
630 | if (val != TD_OK |
631 | && val != TD_NOFPREGS) | |
934741a1 SG |
632 | error ("sol_thread_fetch_registers: td_thr_getfpregs %s", |
633 | td_err_string (val)); | |
8fc2b417 | 634 | |
9b33e492 SG |
635 | /* Note that we must call supply_{g fp}regset *after* calling the td routines |
636 | because the td routines call ps_lget* which affect the values stored in the | |
637 | registers array. */ | |
638 | ||
639 | supply_gregset (gregset); | |
640 | supply_fpregset (fpregset); | |
641 | ||
8fc2b417 SG |
642 | #if 0 |
643 | /* thread_db doesn't seem to handle this right */ | |
644 | val = td_thr_getxregsize (&thandle, &xregsize); | |
645 | if (val != TD_OK && val != TD_NOXREGS) | |
934741a1 SG |
646 | error ("sol_thread_fetch_registers: td_thr_getxregsize %s", |
647 | td_err_string (val)); | |
8fc2b417 SG |
648 | |
649 | if (val == TD_OK) | |
650 | { | |
651 | xregset = alloca (xregsize); | |
652 | val = td_thr_getxregs (&thandle, xregset); | |
653 | if (val != TD_OK) | |
934741a1 SG |
654 | error ("sol_thread_fetch_registers: td_thr_getxregs %s", |
655 | td_err_string (val)); | |
8fc2b417 SG |
656 | } |
657 | #endif | |
658 | } | |
659 | ||
660 | static void | |
661 | sol_thread_store_registers (regno) | |
662 | int regno; | |
663 | { | |
664 | thread_t thread; | |
665 | td_thrhandle_t thandle; | |
666 | td_err_e val; | |
667 | prgregset_t regset; | |
668 | prfpregset_t fpregset; | |
934741a1 | 669 | #if 0 |
8fc2b417 SG |
670 | int xregsize; |
671 | caddr_t xregset; | |
934741a1 | 672 | #endif |
8fc2b417 | 673 | |
8fc2b417 SG |
674 | /* Convert inferior_pid into a td_thrhandle_t */ |
675 | ||
934741a1 | 676 | thread = GET_THREAD (inferior_pid); |
8fc2b417 | 677 | |
4915acad | 678 | val = p_td_ta_map_id2thr (main_ta, thread, &thandle); |
8fc2b417 | 679 | if (val != TD_OK) |
934741a1 SG |
680 | error ("sol_thread_store_registers: td_ta_map_id2thr %s", |
681 | td_err_string (val)); | |
8fc2b417 SG |
682 | |
683 | if (regno != -1) | |
684 | { /* Not writing all the regs */ | |
4915acad | 685 | val = p_td_thr_getgregs (&thandle, regset); |
8fc2b417 | 686 | if (val != TD_OK) |
934741a1 SG |
687 | error ("sol_thread_store_registers: td_thr_getgregs %s", |
688 | td_err_string (val)); | |
4915acad | 689 | val = p_td_thr_getfpregs (&thandle, &fpregset); |
8fc2b417 | 690 | if (val != TD_OK) |
934741a1 SG |
691 | error ("sol_thread_store_registers: td_thr_getfpregs %s", |
692 | td_err_string (val)); | |
8fc2b417 SG |
693 | |
694 | #if 0 | |
695 | /* thread_db doesn't seem to handle this right */ | |
696 | val = td_thr_getxregsize (&thandle, &xregsize); | |
697 | if (val != TD_OK && val != TD_NOXREGS) | |
934741a1 SG |
698 | error ("sol_thread_store_registers: td_thr_getxregsize %s", |
699 | td_err_string (val)); | |
8fc2b417 SG |
700 | |
701 | if (val == TD_OK) | |
702 | { | |
703 | xregset = alloca (xregsize); | |
704 | val = td_thr_getxregs (&thandle, xregset); | |
705 | if (val != TD_OK) | |
934741a1 SG |
706 | error ("sol_thread_store_registers: td_thr_getxregs %s", |
707 | td_err_string (val)); | |
8fc2b417 SG |
708 | } |
709 | #endif | |
710 | } | |
711 | ||
712 | fill_gregset (regset, regno); | |
934741a1 | 713 | fill_fpregset (fpregset, regno); |
8fc2b417 | 714 | |
4915acad | 715 | val = p_td_thr_setgregs (&thandle, regset); |
8fc2b417 | 716 | if (val != TD_OK) |
934741a1 SG |
717 | error ("sol_thread_store_registers: td_thr_setgregs %s", |
718 | td_err_string (val)); | |
4915acad | 719 | val = p_td_thr_setfpregs (&thandle, &fpregset); |
8fc2b417 | 720 | if (val != TD_OK) |
934741a1 SG |
721 | error ("sol_thread_store_registers: td_thr_setfpregs %s", |
722 | td_err_string (val)); | |
8fc2b417 SG |
723 | |
724 | #if 0 | |
725 | /* thread_db doesn't seem to handle this right */ | |
726 | val = td_thr_getxregsize (&thandle, &xregsize); | |
727 | if (val != TD_OK && val != TD_NOXREGS) | |
934741a1 SG |
728 | error ("sol_thread_store_registers: td_thr_getxregsize %s", |
729 | td_err_string (val)); | |
8fc2b417 SG |
730 | |
731 | /* Should probably do something about writing the xregs here, but what are | |
732 | they? */ | |
733 | #endif | |
734 | } | |
735 | ||
736 | /* Get ready to modify the registers array. On machines which store | |
737 | individual registers, this doesn't need to do anything. On machines | |
738 | which store all the registers in one fell swoop, this makes sure | |
739 | that registers contains all the registers from the program being | |
740 | debugged. */ | |
741 | ||
742 | static void | |
743 | sol_thread_prepare_to_store () | |
744 | { | |
745 | procfs_ops.to_prepare_to_store (); | |
746 | } | |
747 | ||
748 | static int | |
749 | sol_thread_xfer_memory (memaddr, myaddr, len, dowrite, target) | |
750 | CORE_ADDR memaddr; | |
751 | char *myaddr; | |
752 | int len; | |
753 | int dowrite; | |
754 | struct target_ops *target; /* ignored */ | |
755 | { | |
756 | int retval; | |
934741a1 | 757 | struct cleanup *old_chain; |
8fc2b417 | 758 | |
934741a1 | 759 | old_chain = save_inferior_pid (); |
8fc2b417 | 760 | |
934741a1 | 761 | if (is_thread (inferior_pid)) |
8fc2b417 SG |
762 | inferior_pid = main_ph.pid; /* It's a thread. Convert to lwp */ |
763 | ||
764 | retval = procfs_ops.to_xfer_memory (memaddr, myaddr, len, dowrite, target); | |
765 | ||
934741a1 | 766 | do_cleanups (old_chain); |
8fc2b417 SG |
767 | |
768 | return retval; | |
769 | } | |
770 | ||
771 | /* Print status information about what we're accessing. */ | |
772 | ||
773 | static void | |
774 | sol_thread_files_info (ignore) | |
775 | struct target_ops *ignore; | |
776 | { | |
777 | procfs_ops.to_files_info (ignore); | |
778 | } | |
779 | ||
780 | static void | |
781 | sol_thread_kill_inferior () | |
782 | { | |
783 | procfs_ops.to_kill (); | |
784 | } | |
785 | ||
786 | static void | |
787 | sol_thread_notice_signals (pid) | |
788 | int pid; | |
789 | { | |
790 | procfs_ops.to_notice_signals (pid); | |
791 | } | |
792 | ||
8fc2b417 SG |
793 | /* Fork an inferior process, and start debugging it with /proc. */ |
794 | ||
795 | static void | |
796 | sol_thread_create_inferior (exec_file, allargs, env) | |
797 | char *exec_file; | |
798 | char *allargs; | |
799 | char **env; | |
800 | { | |
801 | procfs_ops.to_create_inferior (exec_file, allargs, env); | |
802 | ||
3780c337 | 803 | if (sol_thread_active && inferior_pid != 0) |
8fc2b417 | 804 | { |
8fc2b417 SG |
805 | main_ph.pid = inferior_pid; /* Save for xfer_memory */ |
806 | ||
807 | push_target (&sol_thread_ops); | |
808 | ||
809 | inferior_pid = lwp_to_thread (inferior_pid); | |
3780c337 MS |
810 | if (inferior_pid == -1) |
811 | inferior_pid = main_ph.pid; | |
8fc2b417 SG |
812 | |
813 | add_thread (inferior_pid); | |
814 | } | |
815 | } | |
816 | ||
817 | /* This routine is called whenever a new symbol table is read in, or when all | |
a50cedad SG |
818 | symbol tables are removed. libthread_db can only be initialized when it |
819 | finds the right variables in libthread.so. Since it's a shared library, | |
820 | those variables don't show up until the library gets mapped and the symbol | |
821 | table is read in. */ | |
8fc2b417 SG |
822 | |
823 | void | |
824 | sol_thread_new_objfile (objfile) | |
825 | struct objfile *objfile; | |
826 | { | |
827 | td_err_e val; | |
828 | ||
829 | if (!objfile) | |
830 | { | |
831 | sol_thread_active = 0; | |
832 | ||
833 | return; | |
834 | } | |
835 | ||
3780c337 MS |
836 | /* don't do anything if init failed to resolve the libthread_db library */ |
837 | if (!procfs_suppress_run) | |
838 | return; | |
839 | ||
8fc2b417 SG |
840 | /* Now, initialize the thread debugging library. This needs to be done after |
841 | the shared libraries are located because it needs information from the | |
842 | user's thread library. */ | |
843 | ||
4915acad | 844 | val = p_td_init (); |
8fc2b417 | 845 | if (val != TD_OK) |
934741a1 | 846 | error ("target_new_objfile: td_init: %s", td_err_string (val)); |
8fc2b417 | 847 | |
4915acad | 848 | val = p_td_ta_new (&main_ph, &main_ta); |
8fc2b417 SG |
849 | if (val == TD_NOLIBTHREAD) |
850 | return; | |
851 | else if (val != TD_OK) | |
934741a1 | 852 | error ("target_new_objfile: td_ta_new: %s", td_err_string (val)); |
8fc2b417 SG |
853 | |
854 | sol_thread_active = 1; | |
855 | } | |
856 | ||
857 | /* Clean up after the inferior dies. */ | |
858 | ||
859 | static void | |
860 | sol_thread_mourn_inferior () | |
861 | { | |
3780c337 | 862 | unpush_target (&sol_thread_ops); |
8fc2b417 SG |
863 | procfs_ops.to_mourn_inferior (); |
864 | } | |
865 | ||
866 | /* Mark our target-struct as eligible for stray "run" and "attach" commands. */ | |
a50cedad | 867 | |
8fc2b417 SG |
868 | static int |
869 | sol_thread_can_run () | |
870 | { | |
871 | return procfs_suppress_run; | |
872 | } | |
873 | ||
3780c337 MS |
874 | /* |
875 | ||
876 | LOCAL FUNCTION | |
877 | ||
878 | sol_thread_alive - test thread for "aliveness" | |
879 | ||
880 | SYNOPSIS | |
881 | ||
882 | static bool sol_thread_alive (int pid); | |
883 | ||
884 | DESCRIPTION | |
885 | ||
886 | returns true if thread still active in inferior. | |
887 | ||
888 | */ | |
889 | ||
a50cedad | 890 | static int |
8fc2b417 SG |
891 | sol_thread_alive (pid) |
892 | int pid; | |
893 | { | |
3780c337 MS |
894 | if (is_thread (pid)) /* non-kernel thread */ |
895 | { | |
896 | td_err_e val; | |
897 | td_thrhandle_t th; | |
898 | ||
899 | pid = GET_THREAD (pid); | |
900 | if ((val = p_td_ta_map_id2thr (main_ta, pid, &th)) != TD_OK) | |
901 | return 0; /* thread not found */ | |
902 | if ((val = p_td_thr_validate (&th)) != TD_OK) | |
903 | return 0; /* thread not valid */ | |
904 | return 1; /* known thread: return true */ | |
905 | } | |
906 | else /* kernel thread (LWP): let procfs test it */ | |
907 | return procfs_ops.to_thread_alive (pid); | |
8fc2b417 SG |
908 | } |
909 | ||
a50cedad | 910 | static void |
8fc2b417 SG |
911 | sol_thread_stop () |
912 | { | |
913 | procfs_ops.to_stop (); | |
914 | } | |
a50cedad SG |
915 | \f |
916 | /* These routines implement the lower half of the thread_db interface. Ie: the | |
917 | ps_* routines. */ | |
8fc2b417 | 918 | |
a50cedad SG |
919 | /* The next four routines are called by thread_db to tell us to stop and stop |
920 | a particular process or lwp. Since GDB ensures that these are all stopped | |
921 | by the time we call anything in thread_db, these routines need to do | |
922 | nothing. */ | |
8fc2b417 | 923 | |
8fc2b417 SG |
924 | ps_err_e |
925 | ps_pstop (const struct ps_prochandle *ph) | |
926 | { | |
8fc2b417 SG |
927 | return PS_OK; |
928 | } | |
929 | ||
930 | ps_err_e | |
931 | ps_pcontinue (const struct ps_prochandle *ph) | |
932 | { | |
8fc2b417 SG |
933 | return PS_OK; |
934 | } | |
935 | ||
936 | ps_err_e | |
937 | ps_lstop (const struct ps_prochandle *ph, lwpid_t lwpid) | |
938 | { | |
8fc2b417 SG |
939 | return PS_OK; |
940 | } | |
941 | ||
942 | ps_err_e | |
943 | ps_lcontinue (const struct ps_prochandle *ph, lwpid_t lwpid) | |
944 | { | |
8fc2b417 SG |
945 | return PS_OK; |
946 | } | |
947 | ||
948 | ps_err_e | |
949 | ps_pglobal_lookup (const struct ps_prochandle *ph, const char *ld_object_name, | |
950 | const char *ld_symbol_name, paddr_t *ld_symbol_addr) | |
951 | { | |
952 | struct minimal_symbol *ms; | |
953 | ||
954 | ms = lookup_minimal_symbol (ld_symbol_name, NULL, NULL); | |
955 | ||
956 | if (!ms) | |
957 | return PS_NOSYM; | |
958 | ||
959 | *ld_symbol_addr = SYMBOL_VALUE_ADDRESS (ms); | |
960 | ||
961 | return PS_OK; | |
962 | } | |
963 | ||
a50cedad SG |
964 | /* Common routine for reading and writing memory. */ |
965 | ||
8fc2b417 SG |
966 | static ps_err_e |
967 | rw_common (int dowrite, const struct ps_prochandle *ph, paddr_t addr, | |
968 | char *buf, int size) | |
969 | { | |
934741a1 | 970 | struct cleanup *old_chain; |
8fc2b417 | 971 | |
934741a1 | 972 | old_chain = save_inferior_pid (); |
8fc2b417 | 973 | |
934741a1 | 974 | if (is_thread (inferior_pid)) |
8fc2b417 SG |
975 | inferior_pid = main_ph.pid; /* It's a thread. Convert to lwp */ |
976 | ||
977 | while (size > 0) | |
978 | { | |
979 | int cc; | |
980 | ||
981 | cc = procfs_ops.to_xfer_memory (addr, buf, size, dowrite, &procfs_ops); | |
982 | ||
983 | if (cc < 0) | |
984 | { | |
985 | if (dowrite == 0) | |
3780c337 | 986 | print_sys_errmsg ("rw_common (): read", errno); |
8fc2b417 | 987 | else |
3780c337 | 988 | print_sys_errmsg ("rw_common (): write", errno); |
8fc2b417 | 989 | |
934741a1 | 990 | do_cleanups (old_chain); |
8fc2b417 SG |
991 | |
992 | return PS_ERR; | |
993 | } | |
994 | size -= cc; | |
995 | buf += cc; | |
996 | } | |
997 | ||
934741a1 | 998 | do_cleanups (old_chain); |
8fc2b417 SG |
999 | |
1000 | return PS_OK; | |
1001 | } | |
1002 | ||
1003 | ps_err_e | |
1004 | ps_pdread (const struct ps_prochandle *ph, paddr_t addr, char *buf, int size) | |
1005 | { | |
1006 | return rw_common (0, ph, addr, buf, size); | |
1007 | } | |
1008 | ||
1009 | ps_err_e | |
1010 | ps_pdwrite (const struct ps_prochandle *ph, paddr_t addr, char *buf, int size) | |
1011 | { | |
1012 | return rw_common (1, ph, addr, buf, size); | |
1013 | } | |
1014 | ||
1015 | ps_err_e | |
1016 | ps_ptread (const struct ps_prochandle *ph, paddr_t addr, char *buf, int size) | |
1017 | { | |
1018 | return rw_common (0, ph, addr, buf, size); | |
1019 | } | |
1020 | ||
1021 | ps_err_e | |
1022 | ps_ptwrite (const struct ps_prochandle *ph, paddr_t addr, char *buf, int size) | |
1023 | { | |
1024 | return rw_common (1, ph, addr, buf, size); | |
1025 | } | |
1026 | ||
a50cedad SG |
1027 | /* Get integer regs */ |
1028 | ||
8fc2b417 SG |
1029 | ps_err_e |
1030 | ps_lgetregs (const struct ps_prochandle *ph, lwpid_t lwpid, | |
1031 | prgregset_t gregset) | |
1032 | { | |
934741a1 | 1033 | struct cleanup *old_chain; |
8fc2b417 | 1034 | |
934741a1 | 1035 | old_chain = save_inferior_pid (); |
8fc2b417 | 1036 | |
934741a1 | 1037 | inferior_pid = BUILD_LWP (lwpid, PIDGET (inferior_pid)); |
8fc2b417 SG |
1038 | |
1039 | procfs_ops.to_fetch_registers (-1); | |
1040 | fill_gregset (gregset, -1); | |
1041 | ||
934741a1 | 1042 | do_cleanups (old_chain); |
8fc2b417 SG |
1043 | |
1044 | return PS_OK; | |
1045 | } | |
1046 | ||
a50cedad SG |
1047 | /* Set integer regs */ |
1048 | ||
8fc2b417 SG |
1049 | ps_err_e |
1050 | ps_lsetregs (const struct ps_prochandle *ph, lwpid_t lwpid, | |
1051 | const prgregset_t gregset) | |
1052 | { | |
934741a1 | 1053 | struct cleanup *old_chain; |
8fc2b417 | 1054 | |
934741a1 | 1055 | old_chain = save_inferior_pid (); |
8fc2b417 | 1056 | |
934741a1 | 1057 | inferior_pid = BUILD_LWP (lwpid, PIDGET (inferior_pid)); |
8fc2b417 SG |
1058 | |
1059 | supply_gregset (gregset); | |
1060 | procfs_ops.to_store_registers (-1); | |
1061 | ||
934741a1 | 1062 | do_cleanups (old_chain); |
8fc2b417 SG |
1063 | |
1064 | return PS_OK; | |
1065 | } | |
1066 | ||
1067 | void | |
1068 | ps_plog (const char *fmt, ...) | |
1069 | { | |
1070 | va_list args; | |
1071 | ||
1072 | va_start (args, fmt); | |
1073 | ||
1074 | vfprintf_filtered (gdb_stderr, fmt, args); | |
1075 | } | |
1076 | ||
a50cedad SG |
1077 | /* Get size of extra register set. Currently a noop. */ |
1078 | ||
8fc2b417 SG |
1079 | ps_err_e |
1080 | ps_lgetxregsize (const struct ps_prochandle *ph, lwpid_t lwpid, int *xregsize) | |
1081 | { | |
934741a1 | 1082 | #if 0 |
8fc2b417 SG |
1083 | int lwp_fd; |
1084 | int regsize; | |
1085 | ps_err_e val; | |
1086 | ||
8fc2b417 SG |
1087 | val = get_lwp_fd (ph, lwpid, &lwp_fd); |
1088 | if (val != PS_OK) | |
1089 | return val; | |
1090 | ||
1091 | if (ioctl (lwp_fd, PIOCGXREGSIZE, ®size)) | |
1092 | { | |
1093 | if (errno == EINVAL) | |
1094 | return PS_NOFREGS; /* XXX Wrong code, but this is the closest | |
1095 | thing in proc_service.h */ | |
1096 | ||
1097 | print_sys_errmsg ("ps_lgetxregsize (): PIOCGXREGSIZE", errno); | |
1098 | return PS_ERR; | |
1099 | } | |
1100 | #endif | |
1101 | ||
1102 | return PS_OK; | |
1103 | } | |
1104 | ||
a50cedad SG |
1105 | /* Get extra register set. Currently a noop. */ |
1106 | ||
8fc2b417 SG |
1107 | ps_err_e |
1108 | ps_lgetxregs (const struct ps_prochandle *ph, lwpid_t lwpid, caddr_t xregset) | |
1109 | { | |
934741a1 | 1110 | #if 0 |
8fc2b417 SG |
1111 | int lwp_fd; |
1112 | ps_err_e val; | |
1113 | ||
8fc2b417 SG |
1114 | val = get_lwp_fd (ph, lwpid, &lwp_fd); |
1115 | if (val != PS_OK) | |
1116 | return val; | |
1117 | ||
1118 | if (ioctl (lwp_fd, PIOCGXREG, xregset)) | |
1119 | { | |
1120 | print_sys_errmsg ("ps_lgetxregs (): PIOCGXREG", errno); | |
1121 | return PS_ERR; | |
1122 | } | |
1123 | #endif | |
1124 | ||
1125 | return PS_OK; | |
1126 | } | |
1127 | ||
a50cedad SG |
1128 | /* Set extra register set. Currently a noop. */ |
1129 | ||
8fc2b417 SG |
1130 | ps_err_e |
1131 | ps_lsetxregs (const struct ps_prochandle *ph, lwpid_t lwpid, caddr_t xregset) | |
1132 | { | |
934741a1 | 1133 | #if 0 |
8fc2b417 SG |
1134 | int lwp_fd; |
1135 | ps_err_e val; | |
1136 | ||
8fc2b417 SG |
1137 | val = get_lwp_fd (ph, lwpid, &lwp_fd); |
1138 | if (val != PS_OK) | |
1139 | return val; | |
1140 | ||
1141 | if (ioctl (lwp_fd, PIOCSXREG, xregset)) | |
1142 | { | |
1143 | print_sys_errmsg ("ps_lsetxregs (): PIOCSXREG", errno); | |
1144 | return PS_ERR; | |
1145 | } | |
1146 | #endif | |
1147 | ||
1148 | return PS_OK; | |
1149 | } | |
1150 | ||
a50cedad SG |
1151 | /* Get floating-point regs. */ |
1152 | ||
8fc2b417 SG |
1153 | ps_err_e |
1154 | ps_lgetfpregs (const struct ps_prochandle *ph, lwpid_t lwpid, | |
1155 | prfpregset_t *fpregset) | |
1156 | { | |
934741a1 | 1157 | struct cleanup *old_chain; |
8fc2b417 | 1158 | |
934741a1 | 1159 | old_chain = save_inferior_pid (); |
8fc2b417 | 1160 | |
934741a1 | 1161 | inferior_pid = BUILD_LWP (lwpid, PIDGET (inferior_pid)); |
8fc2b417 SG |
1162 | |
1163 | procfs_ops.to_fetch_registers (-1); | |
934741a1 | 1164 | fill_fpregset (*fpregset, -1); |
8fc2b417 | 1165 | |
934741a1 | 1166 | do_cleanups (old_chain); |
8fc2b417 SG |
1167 | |
1168 | return PS_OK; | |
1169 | } | |
1170 | ||
a50cedad SG |
1171 | /* Set floating-point regs. */ |
1172 | ||
8fc2b417 SG |
1173 | ps_err_e |
1174 | ps_lsetfpregs (const struct ps_prochandle *ph, lwpid_t lwpid, | |
1175 | const prfpregset_t *fpregset) | |
1176 | { | |
934741a1 | 1177 | struct cleanup *old_chain; |
8fc2b417 | 1178 | |
934741a1 | 1179 | old_chain = save_inferior_pid (); |
8fc2b417 | 1180 | |
934741a1 | 1181 | inferior_pid = BUILD_LWP (lwpid, PIDGET (inferior_pid)); |
8fc2b417 | 1182 | |
934741a1 | 1183 | supply_fpregset (*fpregset); |
8fc2b417 SG |
1184 | procfs_ops.to_store_registers (-1); |
1185 | ||
934741a1 | 1186 | do_cleanups (old_chain); |
8fc2b417 SG |
1187 | |
1188 | return PS_OK; | |
1189 | } | |
1190 | \f | |
a50cedad SG |
1191 | /* Convert a pid to printable form. */ |
1192 | ||
8fc2b417 SG |
1193 | char * |
1194 | solaris_pid_to_str (pid) | |
1195 | int pid; | |
1196 | { | |
1197 | static char buf[100]; | |
1198 | ||
3780c337 MS |
1199 | /* in case init failed to resolve the libthread_db library */ |
1200 | if (!procfs_suppress_run) | |
1201 | return procfs_pid_to_str (pid); | |
1202 | ||
934741a1 | 1203 | if (is_thread (pid)) |
8fc2b417 SG |
1204 | { |
1205 | int lwp; | |
1206 | ||
1207 | lwp = thread_to_lwp (pid, -2); | |
1208 | ||
3780c337 MS |
1209 | if (lwp == -1) |
1210 | sprintf (buf, "Thread %d (defunct)", GET_THREAD (pid)); | |
1211 | else if (lwp != -2) | |
934741a1 | 1212 | sprintf (buf, "Thread %d (LWP %d)", GET_THREAD (pid), GET_LWP (lwp)); |
8fc2b417 | 1213 | else |
934741a1 | 1214 | sprintf (buf, "Thread %d ", GET_THREAD (pid)); |
8fc2b417 | 1215 | } |
3780c337 | 1216 | else if (GET_LWP (pid) != 0) |
934741a1 | 1217 | sprintf (buf, "LWP %d ", GET_LWP (pid)); |
3780c337 MS |
1218 | else |
1219 | sprintf (buf, "process %d ", PIDGET (pid)); | |
8fc2b417 SG |
1220 | |
1221 | return buf; | |
1222 | } | |
1223 | \f | |
1224 | struct target_ops sol_thread_ops = { | |
1225 | "solaris-threads", /* to_shortname */ | |
1226 | "Solaris threads and pthread.", /* to_longname */ | |
1227 | "Solaris threads and pthread support.", /* to_doc */ | |
1228 | sol_thread_open, /* to_open */ | |
1229 | 0, /* to_close */ | |
4915acad | 1230 | sol_thread_attach, /* to_attach */ |
8fc2b417 | 1231 | sol_thread_detach, /* to_detach */ |
4915acad SG |
1232 | sol_thread_resume, /* to_resume */ |
1233 | sol_thread_wait, /* to_wait */ | |
8fc2b417 SG |
1234 | sol_thread_fetch_registers, /* to_fetch_registers */ |
1235 | sol_thread_store_registers, /* to_store_registers */ | |
1236 | sol_thread_prepare_to_store, /* to_prepare_to_store */ | |
4915acad SG |
1237 | sol_thread_xfer_memory, /* to_xfer_memory */ |
1238 | sol_thread_files_info, /* to_files_info */ | |
8fc2b417 SG |
1239 | memory_insert_breakpoint, /* to_insert_breakpoint */ |
1240 | memory_remove_breakpoint, /* to_remove_breakpoint */ | |
1241 | terminal_init_inferior, /* to_terminal_init */ | |
1242 | terminal_inferior, /* to_terminal_inferior */ | |
1243 | terminal_ours_for_output, /* to_terminal_ours_for_output */ | |
1244 | terminal_ours, /* to_terminal_ours */ | |
1245 | child_terminal_info, /* to_terminal_info */ | |
1246 | sol_thread_kill_inferior, /* to_kill */ | |
1247 | 0, /* to_load */ | |
1248 | 0, /* to_lookup_symbol */ | |
1249 | sol_thread_create_inferior, /* to_create_inferior */ | |
1250 | sol_thread_mourn_inferior, /* to_mourn_inferior */ | |
1251 | sol_thread_can_run, /* to_can_run */ | |
1252 | sol_thread_notice_signals, /* to_notice_signals */ | |
1253 | sol_thread_alive, /* to_thread_alive */ | |
1254 | sol_thread_stop, /* to_stop */ | |
1255 | process_stratum, /* to_stratum */ | |
1256 | 0, /* to_next */ | |
1257 | 1, /* to_has_all_memory */ | |
1258 | 1, /* to_has_memory */ | |
1259 | 1, /* to_has_stack */ | |
1260 | 1, /* to_has_registers */ | |
1261 | 1, /* to_has_execution */ | |
1262 | 0, /* sections */ | |
1263 | 0, /* sections_end */ | |
1264 | OPS_MAGIC /* to_magic */ | |
1265 | }; | |
1266 | ||
1267 | void | |
1268 | _initialize_sol_thread () | |
1269 | { | |
4915acad SG |
1270 | void *dlhandle; |
1271 | ||
1272 | dlhandle = dlopen ("libthread_db.so.1", RTLD_NOW); | |
1273 | if (!dlhandle) | |
1274 | goto die; | |
1275 | ||
1276 | #define resolve(X) \ | |
1277 | if (!(p_##X = dlsym (dlhandle, #X))) \ | |
1278 | goto die; | |
1279 | ||
1280 | resolve (td_log); | |
1281 | resolve (td_ta_new); | |
1282 | resolve (td_ta_delete); | |
1283 | resolve (td_init); | |
1284 | resolve (td_ta_get_ph); | |
1285 | resolve (td_ta_get_nthreads); | |
1286 | resolve (td_ta_tsd_iter); | |
1287 | resolve (td_ta_thr_iter); | |
1288 | resolve (td_thr_validate); | |
1289 | resolve (td_thr_tsd); | |
1290 | resolve (td_thr_get_info); | |
1291 | resolve (td_thr_getfpregs); | |
1292 | resolve (td_thr_getxregsize); | |
1293 | resolve (td_thr_getxregs); | |
1294 | resolve (td_thr_sigsetmask); | |
1295 | resolve (td_thr_setprio); | |
1296 | resolve (td_thr_setsigpending); | |
1297 | resolve (td_thr_setfpregs); | |
1298 | resolve (td_thr_setxregs); | |
1299 | resolve (td_ta_map_id2thr); | |
1300 | resolve (td_ta_map_lwp2thr); | |
1301 | resolve (td_thr_getgregs); | |
1302 | resolve (td_thr_setgregs); | |
1303 | ||
8fc2b417 SG |
1304 | add_target (&sol_thread_ops); |
1305 | ||
1306 | procfs_suppress_run = 1; | |
4915acad SG |
1307 | |
1308 | return; | |
1309 | ||
1310 | die: | |
1311 | ||
1312 | fprintf_unfiltered (gdb_stderr, "[GDB will not be able to debug user-mode threads: %s]\n", dlerror ()); | |
1313 | ||
1314 | if (dlhandle) | |
1315 | dlclose (dlhandle); | |
1316 | ||
1317 | return; | |
8fc2b417 | 1318 | } |