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