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