1 /* Low level interface for debugging Solaris threads for GDB, the GNU debugger.
2 Copyright 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
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.
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.
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!
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
51 #include <proc_service.h>
52 #include <thread_db.h>
53 #include "gdbthread.h"
62 extern struct target_ops sol_thread_ops
; /* Forward declaration */
63 extern struct target_ops sol_core_ops
; /* Forward declaration */
65 /* place to store core_ops before we overwrite it */
66 static struct target_ops orig_core_ops
;
68 struct target_ops sol_thread_ops
;
69 struct target_ops sol_core_ops
;
71 extern int procfs_suppress_run
;
72 extern struct target_ops procfs_ops
; /* target vector for procfs.c */
73 extern struct target_ops core_ops
; /* target vector for corelow.c */
74 extern char *procfs_pid_to_str (int pid
);
76 /* Prototypes for supply_gregset etc. */
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. */
94 static struct ps_prochandle main_ph
;
95 static td_thragent_t
*main_ta
;
96 static int sol_thread_active
= 0;
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
);
108 static void init_sol_thread_ops (void);
109 static void init_sol_core_ops (void);
111 /* Default definitions: These must be defined in tm.h
112 if they are to be shared with a process module such as procfs. */
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)
121 #define BUILD_THREAD(TID, PID) (MERGEPID (PID, TID) | THREAD_FLAG)
123 /* Pointers to routines from lithread_db resolved by dlopen() */
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
,
134 static td_err_e (*p_td_ta_tsd_iter
) (const td_thragent_t
* ta_p
,
137 static td_err_e (*p_td_ta_thr_iter
) (const td_thragent_t
* ta_p
,
140 td_thr_state_e state
,
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
,
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
,
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
,
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
,
169 td_thrhandle_t
* th_p
);
170 static td_err_e (*p_td_ta_map_lwp2thr
) (const td_thragent_t
* ta_p
,
172 td_thrhandle_t
* th_p
);
173 static td_err_e (*p_td_thr_getgregs
) (const td_thrhandle_t
* th_p
,
175 static td_err_e (*p_td_thr_setgregs
) (const td_thrhandle_t
* th_p
,
176 const prgregset_t regset
);
182 td_err_string - Convert a thread_db error code to a string
186 char * td_err_string (errcode)
190 Return the thread_db error string associated with errcode. If errcode
191 is unknown, then return a message.
196 td_err_string (td_err_e errcode
)
198 static struct string_map
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 written/read"},
221 {TD_NOXREGS
, "X register set not available for given thread"}
223 const int td_err_size
= sizeof td_err_table
/ sizeof (struct string_map
);
227 for (i
= 0; i
< td_err_size
; i
++)
228 if (td_err_table
[i
].num
== errcode
)
229 return td_err_table
[i
].str
;
231 sprintf (buf
, "Unknown thread_db error code: %d", errcode
);
240 td_state_string - Convert a thread_db state code to a string
244 char * td_state_string (statecode)
248 Return the thread_db state string associated with statecode. If
249 statecode is unknown, then return a message.
254 td_state_string (td_thr_state_e statecode
)
256 static struct string_map
257 td_thr_state_table
[] =
259 {TD_THR_ANY_STATE
, "any state"},
260 {TD_THR_UNKNOWN
, "unknown"},
261 {TD_THR_STOPPED
, "stopped"},
263 {TD_THR_ACTIVE
, "active"},
264 {TD_THR_ZOMBIE
, "zombie"},
265 {TD_THR_SLEEP
, "sleep"},
266 {TD_THR_STOPPED_ASLEEP
, "stopped asleep"}
268 const int td_thr_state_table_size
= sizeof td_thr_state_table
/ sizeof (struct string_map
);
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
;
276 sprintf (buf
, "Unknown thread_db state code: %d", statecode
);
285 thread_to_lwp - Convert a Posix or Solaris thread id to a LWP id.
289 int thread_to_lwp (thread_id, default_lwp)
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.
299 This function probably shouldn't call error()...
304 thread_to_lwp (int thread_id
, int default_lwp
)
310 if (is_lwp (thread_id
))
311 return thread_id
; /* It's already an LWP id */
313 /* It's a thread. Convert to lwp */
315 val
= p_td_ta_map_id2thr (main_ta
, GET_THREAD (thread_id
), &th
);
317 return -1; /* thread must have terminated */
318 else if (val
!= TD_OK
)
319 error ("thread_to_lwp: td_ta_map_id2thr %s", td_err_string (val
));
321 val
= p_td_thr_get_info (&th
, &ti
);
323 return -1; /* thread must have terminated */
324 else if (val
!= TD_OK
)
325 error ("thread_to_lwp: td_thr_get_info: %s", td_err_string (val
));
327 if (ti
.ti_state
!= TD_THR_ACTIVE
)
329 if (default_lwp
!= -1)
331 error ("thread_to_lwp: thread state not active: %s",
332 td_state_string (ti
.ti_state
));
335 return BUILD_LWP (ti
.ti_lid
, PIDGET (thread_id
));
342 lwp_to_thread - Convert a LWP id to a Posix or Solaris thread id.
346 int lwp_to_thread (lwp_id)
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.
355 This function probably shouldn't call error()...
360 lwp_to_thread (int lwp
)
367 return lwp
; /* It's already a thread id */
369 /* It's an lwp. Convert it to a thread id. */
371 if (!sol_thread_alive (lwp
))
372 return -1; /* defunct lwp */
374 val
= p_td_ta_map_lwp2thr (main_ta
, GET_LWP (lwp
), &th
);
376 return -1; /* thread must have terminated */
377 else if (val
!= TD_OK
)
378 error ("lwp_to_thread: td_ta_map_lwp2thr: %s.", td_err_string (val
));
380 val
= p_td_thr_validate (&th
);
382 return lwp
; /* libthread doesn't know about it;
384 else if (val
!= TD_OK
)
385 error ("lwp_to_thread: td_thr_validate: %s.", td_err_string (val
));
387 val
= p_td_thr_get_info (&th
, &ti
);
389 return -1; /* thread must have terminated */
390 else if (val
!= TD_OK
)
391 error ("lwp_to_thread: td_thr_get_info: %s.", td_err_string (val
));
393 return BUILD_THREAD (ti
.ti_tid
, PIDGET (lwp
));
400 save_inferior_pid - Save inferior_pid on the cleanup list
401 restore_inferior_pid - Restore inferior_pid from the cleanup list
405 struct cleanup *save_inferior_pid ()
406 void restore_inferior_pid (int pid)
410 These two functions act in unison to restore inferior_pid in
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.
424 static struct cleanup
*
425 save_inferior_pid (void)
427 int *saved_pid
= xmalloc (sizeof (int));
428 *saved_pid
= inferior_pid
;
429 return make_cleanup (restore_inferior_pid
, saved_pid
);
433 restore_inferior_pid (void *data
)
435 int *saved_pid
= data
;
436 inferior_pid
= *saved_pid
;
441 /* Most target vector functions from here on actually just pass through to
442 procfs.c, as they don't need to do anything specific for threads. */
447 sol_thread_open (char *arg
, int from_tty
)
449 procfs_ops
.to_open (arg
, from_tty
);
452 /* Attach to process PID, then initialize for debugging it
453 and wait for the trace-trap that results from attaching. */
456 sol_thread_attach (char *args
, int from_tty
)
458 procfs_ops
.to_attach (args
, from_tty
);
460 /* Must get symbols from solibs before libthread_db can run! */
461 SOLIB_ADD ((char *) 0, from_tty
, (struct target_ops
*) 0);
463 if (sol_thread_active
)
465 printf_filtered ("sol-thread active.\n");
466 main_ph
.pid
= inferior_pid
; /* Save for xfer_memory */
467 push_target (&sol_thread_ops
);
468 inferior_pid
= lwp_to_thread (inferior_pid
);
469 if (inferior_pid
== -1)
470 inferior_pid
= main_ph
.pid
;
472 add_thread (inferior_pid
);
474 /* XXX - might want to iterate over all the threads and register them. */
477 /* Take a program previously attached to and detaches it.
478 The program resumes execution and will no longer stop
479 on signals, etc. We'd better not have left any breakpoints
480 in the program or it'll die when it hits one. For this
481 to work, it may be necessary for the process to have been
482 previously attached. It *might* work if the program was
483 started via the normal ptrace (PTRACE_TRACEME). */
486 sol_thread_detach (char *args
, int from_tty
)
488 inferior_pid
= PIDGET (main_ph
.pid
);
489 unpush_target (&sol_thread_ops
);
490 procfs_ops
.to_detach (args
, from_tty
);
493 /* Resume execution of process PID. If STEP is nozero, then
494 just single step it. If SIGNAL is nonzero, restart it with that
495 signal activated. We may have to convert pid from a thread-id to an LWP id
499 sol_thread_resume (int pid
, int step
, enum target_signal signo
)
501 struct cleanup
*old_chain
;
503 old_chain
= save_inferior_pid ();
505 inferior_pid
= thread_to_lwp (inferior_pid
, main_ph
.pid
);
506 if (inferior_pid
== -1)
507 inferior_pid
= procfs_first_available ();
513 pid
= thread_to_lwp (pid
, -2);
514 if (pid
== -2) /* Inactive thread */
515 error ("This version of Solaris can't start inactive threads.");
516 if (info_verbose
&& pid
== -1)
517 warning ("Specified thread %d seems to have terminated",
518 GET_THREAD (save_pid
));
521 procfs_ops
.to_resume (pid
, step
, signo
);
523 do_cleanups (old_chain
);
526 /* Wait for any threads to stop. We may have to convert PID from a thread id
527 to a LWP id, and vice versa on the way out. */
530 sol_thread_wait (int pid
, struct target_waitstatus
*ourstatus
)
534 struct cleanup
*old_chain
;
536 save_pid
= inferior_pid
;
537 old_chain
= save_inferior_pid ();
539 inferior_pid
= thread_to_lwp (inferior_pid
, main_ph
.pid
);
540 if (inferior_pid
== -1)
541 inferior_pid
= procfs_first_available ();
547 pid
= thread_to_lwp (pid
, -2);
548 if (pid
== -2) /* Inactive thread */
549 error ("This version of Solaris can't start inactive threads.");
550 if (info_verbose
&& pid
== -1)
551 warning ("Specified thread %d seems to have terminated",
552 GET_THREAD (save_pid
));
555 rtnval
= procfs_ops
.to_wait (pid
, ourstatus
);
557 if (ourstatus
->kind
!= TARGET_WAITKIND_EXITED
)
559 /* Map the LWP of interest back to the appropriate thread ID */
560 rtnval
= lwp_to_thread (rtnval
);
564 /* See if we have a new thread */
565 if (is_thread (rtnval
)
566 && rtnval
!= save_pid
567 && !in_thread_list (rtnval
))
569 printf_filtered ("[New %s]\n", target_pid_to_str (rtnval
));
574 /* During process initialization, we may get here without the thread package
575 being initialized, since that can only happen after we've found the shared
578 do_cleanups (old_chain
);
584 sol_thread_fetch_registers (int regno
)
587 td_thrhandle_t thandle
;
590 prfpregset_t fpregset
;
596 if (!is_thread (inferior_pid
))
597 { /* LWP: pass the request on to procfs.c */
598 if (target_has_execution
)
599 procfs_ops
.to_fetch_registers (regno
);
601 orig_core_ops
.to_fetch_registers (regno
);
605 /* Solaris thread: convert inferior_pid into a td_thrhandle_t */
607 thread
= GET_THREAD (inferior_pid
);
610 error ("sol_thread_fetch_registers: thread == 0");
612 val
= p_td_ta_map_id2thr (main_ta
, thread
, &thandle
);
614 error ("sol_thread_fetch_registers: td_ta_map_id2thr: %s",
615 td_err_string (val
));
617 /* Get the integer regs */
619 val
= p_td_thr_getgregs (&thandle
, gregset
);
621 && val
!= TD_PARTIALREG
)
622 error ("sol_thread_fetch_registers: td_thr_getgregs %s",
623 td_err_string (val
));
625 /* For the sparc, TD_PARTIALREG means that only i0->i7, l0->l7, pc and sp
626 are saved (by a thread context switch). */
628 /* And, now the fp regs */
630 val
= p_td_thr_getfpregs (&thandle
, &fpregset
);
632 && val
!= TD_NOFPREGS
)
633 error ("sol_thread_fetch_registers: td_thr_getfpregs %s",
634 td_err_string (val
));
636 /* Note that we must call supply_{g fp}regset *after* calling the td routines
637 because the td routines call ps_lget* which affect the values stored in the
640 supply_gregset ((gdb_gregset_t
*) &gregset
);
641 supply_fpregset ((gdb_fpregset_t
*) &fpregset
);
644 /* thread_db doesn't seem to handle this right */
645 val
= td_thr_getxregsize (&thandle
, &xregsize
);
646 if (val
!= TD_OK
&& val
!= TD_NOXREGS
)
647 error ("sol_thread_fetch_registers: td_thr_getxregsize %s",
648 td_err_string (val
));
652 xregset
= alloca (xregsize
);
653 val
= td_thr_getxregs (&thandle
, xregset
);
655 error ("sol_thread_fetch_registers: td_thr_getxregs %s",
656 td_err_string (val
));
662 sol_thread_store_registers (int regno
)
665 td_thrhandle_t thandle
;
668 prfpregset_t fpregset
;
674 if (!is_thread (inferior_pid
))
675 { /* LWP: pass the request on to procfs.c */
676 procfs_ops
.to_store_registers (regno
);
680 /* Solaris thread: convert inferior_pid into a td_thrhandle_t */
682 thread
= GET_THREAD (inferior_pid
);
684 val
= p_td_ta_map_id2thr (main_ta
, thread
, &thandle
);
686 error ("sol_thread_store_registers: td_ta_map_id2thr %s",
687 td_err_string (val
));
690 { /* Not writing all the regs */
691 /* save new register value */
692 char* old_value
= (char*) alloca (REGISTER_SIZE
);
693 memcpy (old_value
, ®isters
[REGISTER_BYTE (regno
)], REGISTER_SIZE
);
695 val
= p_td_thr_getgregs (&thandle
, gregset
);
697 error ("sol_thread_store_registers: td_thr_getgregs %s",
698 td_err_string (val
));
699 val
= p_td_thr_getfpregs (&thandle
, &fpregset
);
701 error ("sol_thread_store_registers: td_thr_getfpregs %s",
702 td_err_string (val
));
704 /* restore new register value */
705 memcpy (®isters
[REGISTER_BYTE (regno
)], old_value
, REGISTER_SIZE
);
708 /* thread_db doesn't seem to handle this right */
709 val
= td_thr_getxregsize (&thandle
, &xregsize
);
710 if (val
!= TD_OK
&& val
!= TD_NOXREGS
)
711 error ("sol_thread_store_registers: td_thr_getxregsize %s",
712 td_err_string (val
));
716 xregset
= alloca (xregsize
);
717 val
= td_thr_getxregs (&thandle
, xregset
);
719 error ("sol_thread_store_registers: td_thr_getxregs %s",
720 td_err_string (val
));
725 fill_gregset ((gdb_gregset_t
*) &gregset
, regno
);
726 fill_fpregset ((gdb_fpregset_t
*) &fpregset
, regno
);
728 val
= p_td_thr_setgregs (&thandle
, gregset
);
730 error ("sol_thread_store_registers: td_thr_setgregs %s",
731 td_err_string (val
));
732 val
= p_td_thr_setfpregs (&thandle
, &fpregset
);
734 error ("sol_thread_store_registers: td_thr_setfpregs %s",
735 td_err_string (val
));
738 /* thread_db doesn't seem to handle this right */
739 val
= td_thr_getxregsize (&thandle
, &xregsize
);
740 if (val
!= TD_OK
&& val
!= TD_NOXREGS
)
741 error ("sol_thread_store_registers: td_thr_getxregsize %s",
742 td_err_string (val
));
744 /* Should probably do something about writing the xregs here, but what are
749 /* Get ready to modify the registers array. On machines which store
750 individual registers, this doesn't need to do anything. On machines
751 which store all the registers in one fell swoop, this makes sure
752 that registers contains all the registers from the program being
756 sol_thread_prepare_to_store (void)
758 procfs_ops
.to_prepare_to_store ();
761 /* Transfer LEN bytes between GDB address MYADDR and target address
762 MEMADDR. If DOWRITE is non-zero, transfer them to the target,
763 otherwise transfer them from the target. TARGET is unused.
765 Returns the number of bytes transferred. */
768 sol_thread_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int dowrite
,
769 struct mem_attrib
*attrib
,
770 struct target_ops
*target
)
773 struct cleanup
*old_chain
;
775 old_chain
= save_inferior_pid ();
777 if (is_thread (inferior_pid
) || /* A thread */
778 !target_thread_alive (inferior_pid
)) /* An lwp, but not alive */
779 inferior_pid
= procfs_first_available (); /* Find any live lwp. */
780 /* Note: don't need to call switch_to_thread; we're just reading memory. */
782 if (target_has_execution
)
783 retval
= procfs_ops
.to_xfer_memory (memaddr
, myaddr
, len
,
784 dowrite
, attrib
, target
);
786 retval
= orig_core_ops
.to_xfer_memory (memaddr
, myaddr
, len
,
787 dowrite
, attrib
, target
);
789 do_cleanups (old_chain
);
794 /* Print status information about what we're accessing. */
797 sol_thread_files_info (struct target_ops
*ignore
)
799 procfs_ops
.to_files_info (ignore
);
803 sol_thread_kill_inferior (void)
805 procfs_ops
.to_kill ();
809 sol_thread_notice_signals (int pid
)
811 procfs_ops
.to_notice_signals (PIDGET (pid
));
814 /* Fork an inferior process, and start debugging it with /proc. */
817 sol_thread_create_inferior (char *exec_file
, char *allargs
, char **env
)
819 procfs_ops
.to_create_inferior (exec_file
, allargs
, env
);
821 if (sol_thread_active
&& inferior_pid
!= 0)
823 main_ph
.pid
= inferior_pid
; /* Save for xfer_memory */
825 push_target (&sol_thread_ops
);
827 inferior_pid
= lwp_to_thread (inferior_pid
);
828 if (inferior_pid
== -1)
829 inferior_pid
= main_ph
.pid
;
831 if (!in_thread_list (inferior_pid
))
832 add_thread (inferior_pid
);
836 /* This routine is called whenever a new symbol table is read in, or when all
837 symbol tables are removed. libthread_db can only be initialized when it
838 finds the right variables in libthread.so. Since it's a shared library,
839 those variables don't show up until the library gets mapped and the symbol
842 /* This new_objfile event is now managed by a chained function pointer.
843 * It is the callee's responsability to call the next client on the chain.
846 /* Saved pointer to previous owner of the new_objfile event. */
847 static void (*target_new_objfile_chain
) (struct objfile
*);
850 sol_thread_new_objfile (struct objfile
*objfile
)
856 sol_thread_active
= 0;
860 /* don't do anything if init failed to resolve the libthread_db library */
861 if (!procfs_suppress_run
)
864 /* Now, initialize the thread debugging library. This needs to be done after
865 the shared libraries are located because it needs information from the
866 user's thread library. */
871 warning ("sol_thread_new_objfile: td_init: %s", td_err_string (val
));
875 val
= p_td_ta_new (&main_ph
, &main_ta
);
876 if (val
== TD_NOLIBTHREAD
)
878 else if (val
!= TD_OK
)
880 warning ("sol_thread_new_objfile: td_ta_new: %s", td_err_string (val
));
884 sol_thread_active
= 1;
886 /* Call predecessor on chain, if any. */
887 if (target_new_objfile_chain
)
888 target_new_objfile_chain (objfile
);
891 /* Clean up after the inferior dies. */
894 sol_thread_mourn_inferior (void)
896 unpush_target (&sol_thread_ops
);
897 procfs_ops
.to_mourn_inferior ();
900 /* Mark our target-struct as eligible for stray "run" and "attach" commands. */
903 sol_thread_can_run (void)
905 return procfs_suppress_run
;
912 sol_thread_alive - test thread for "aliveness"
916 static bool sol_thread_alive (int pid);
920 returns true if thread still active in inferior.
925 sol_thread_alive (int pid
)
927 if (is_thread (pid
)) /* non-kernel thread */
932 pid
= GET_THREAD (pid
);
933 if ((val
= p_td_ta_map_id2thr (main_ta
, pid
, &th
)) != TD_OK
)
934 return 0; /* thread not found */
935 if ((val
= p_td_thr_validate (&th
)) != TD_OK
)
936 return 0; /* thread not valid */
937 return 1; /* known thread: return true */
940 /* kernel thread (LWP): let procfs test it */
942 if (target_has_execution
)
943 return procfs_ops
.to_thread_alive (pid
);
945 return orig_core_ops
.to_thread_alive (pid
);
950 sol_thread_stop (void)
952 procfs_ops
.to_stop ();
955 /* These routines implement the lower half of the thread_db interface. Ie: the
958 /* Various versions of <proc_service.h> have slightly
959 different function prototypes. In particular, we have
962 struct ps_prochandle * const struct ps_prochandle *
967 Which one you have depends on solaris version and what
968 patches you've applied. On the theory that there are
969 only two major variants, we have configure check the
970 prototype of ps_pdwrite (), and use that info to make
971 appropriate typedefs here. */
973 #ifdef PROC_SERVICE_IS_OLD
974 typedef const struct ps_prochandle
*gdb_ps_prochandle_t
;
975 typedef char *gdb_ps_read_buf_t
;
976 typedef char *gdb_ps_write_buf_t
;
977 typedef int gdb_ps_size_t
;
978 typedef paddr_t gdb_ps_addr_t
;
980 typedef struct ps_prochandle
*gdb_ps_prochandle_t
;
981 typedef void *gdb_ps_read_buf_t
;
982 typedef const void *gdb_ps_write_buf_t
;
983 typedef size_t gdb_ps_size_t
;
984 typedef psaddr_t gdb_ps_addr_t
;
988 /* The next four routines are called by thread_db to tell us to stop and stop
989 a particular process or lwp. Since GDB ensures that these are all stopped
990 by the time we call anything in thread_db, these routines need to do
996 ps_pstop (gdb_ps_prochandle_t ph
)
1001 /* Process continue */
1004 ps_pcontinue (gdb_ps_prochandle_t ph
)
1012 ps_lstop (gdb_ps_prochandle_t ph
, lwpid_t lwpid
)
1020 ps_lcontinue (gdb_ps_prochandle_t ph
, lwpid_t lwpid
)
1025 /* Looks up the symbol LD_SYMBOL_NAME in the debugger's symbol table. */
1028 ps_pglobal_lookup (gdb_ps_prochandle_t ph
, const char *ld_object_name
,
1029 const char *ld_symbol_name
, gdb_ps_addr_t
* ld_symbol_addr
)
1031 struct minimal_symbol
*ms
;
1033 ms
= lookup_minimal_symbol (ld_symbol_name
, NULL
, NULL
);
1038 *ld_symbol_addr
= SYMBOL_VALUE_ADDRESS (ms
);
1043 /* Common routine for reading and writing memory. */
1046 rw_common (int dowrite
, const struct ps_prochandle
*ph
, gdb_ps_addr_t addr
,
1047 char *buf
, int size
)
1049 struct cleanup
*old_chain
;
1051 old_chain
= save_inferior_pid ();
1053 if (is_thread (inferior_pid
) || /* A thread */
1054 !target_thread_alive (inferior_pid
)) /* An lwp, but not alive */
1055 inferior_pid
= procfs_first_available (); /* Find any live lwp. */
1056 /* Note: don't need to call switch_to_thread; we're just reading memory. */
1058 #if defined (__sparcv9)
1059 /* For Sparc64 cross Sparc32, make sure the address has not been
1060 accidentally sign-extended (or whatever) to beyond 32 bits. */
1061 if (bfd_get_arch_size (exec_bfd
) == 32)
1069 /* FIXME: passing 0 as attrib argument. */
1070 if (target_has_execution
)
1071 cc
= procfs_ops
.to_xfer_memory (addr
, buf
, size
,
1072 dowrite
, 0, &procfs_ops
);
1074 cc
= orig_core_ops
.to_xfer_memory (addr
, buf
, size
,
1075 dowrite
, 0, &core_ops
);
1080 print_sys_errmsg ("rw_common (): read", errno
);
1082 print_sys_errmsg ("rw_common (): write", errno
);
1084 do_cleanups (old_chain
);
1091 warning ("rw_common (): unable to read at addr 0x%lx",
1094 warning ("rw_common (): unable to write at addr 0x%lx",
1097 do_cleanups (old_chain
);
1106 do_cleanups (old_chain
);
1111 /* Copies SIZE bytes from target process .data segment to debugger memory. */
1114 ps_pdread (gdb_ps_prochandle_t ph
, gdb_ps_addr_t addr
,
1115 gdb_ps_read_buf_t buf
, gdb_ps_size_t size
)
1117 return rw_common (0, ph
, addr
, buf
, size
);
1120 /* Copies SIZE bytes from debugger memory .data segment to target process. */
1123 ps_pdwrite (gdb_ps_prochandle_t ph
, gdb_ps_addr_t addr
,
1124 gdb_ps_write_buf_t buf
, gdb_ps_size_t size
)
1126 return rw_common (1, ph
, addr
, (char *) buf
, size
);
1129 /* Copies SIZE bytes from target process .text segment to debugger memory. */
1132 ps_ptread (gdb_ps_prochandle_t ph
, gdb_ps_addr_t addr
,
1133 gdb_ps_read_buf_t buf
, gdb_ps_size_t size
)
1135 return rw_common (0, ph
, addr
, buf
, size
);
1138 /* Copies SIZE bytes from debugger memory .text segment to target process. */
1141 ps_ptwrite (gdb_ps_prochandle_t ph
, gdb_ps_addr_t addr
,
1142 gdb_ps_write_buf_t buf
, gdb_ps_size_t size
)
1144 return rw_common (1, ph
, addr
, (char *) buf
, size
);
1147 /* Get integer regs for LWP */
1150 ps_lgetregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
,
1151 prgregset_t gregset
)
1153 struct cleanup
*old_chain
;
1155 old_chain
= save_inferior_pid ();
1157 inferior_pid
= BUILD_LWP (lwpid
, PIDGET (inferior_pid
));
1159 if (target_has_execution
)
1160 procfs_ops
.to_fetch_registers (-1);
1162 orig_core_ops
.to_fetch_registers (-1);
1163 fill_gregset ((gdb_gregset_t
*) gregset
, -1);
1165 do_cleanups (old_chain
);
1170 /* Set integer regs for LWP */
1173 ps_lsetregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
,
1174 const prgregset_t gregset
)
1176 struct cleanup
*old_chain
;
1178 old_chain
= save_inferior_pid ();
1180 inferior_pid
= BUILD_LWP (lwpid
, PIDGET (inferior_pid
));
1182 supply_gregset ((gdb_gregset_t
*) gregset
);
1183 if (target_has_execution
)
1184 procfs_ops
.to_store_registers (-1);
1186 orig_core_ops
.to_store_registers (-1);
1188 do_cleanups (old_chain
);
1193 /* Log a message (sends to gdb_stderr). */
1196 ps_plog (const char *fmt
,...)
1200 va_start (args
, fmt
);
1202 vfprintf_filtered (gdb_stderr
, fmt
, args
);
1205 /* Get size of extra register set. Currently a noop. */
1208 ps_lgetxregsize (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, int *xregsize
)
1215 val
= get_lwp_fd (ph
, lwpid
, &lwp_fd
);
1219 if (ioctl (lwp_fd
, PIOCGXREGSIZE
, ®size
))
1221 if (errno
== EINVAL
)
1222 return PS_NOFREGS
; /* XXX Wrong code, but this is the closest
1223 thing in proc_service.h */
1225 print_sys_errmsg ("ps_lgetxregsize (): PIOCGXREGSIZE", errno
);
1233 /* Get extra register set. Currently a noop. */
1236 ps_lgetxregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, caddr_t xregset
)
1242 val
= get_lwp_fd (ph
, lwpid
, &lwp_fd
);
1246 if (ioctl (lwp_fd
, PIOCGXREG
, xregset
))
1248 print_sys_errmsg ("ps_lgetxregs (): PIOCGXREG", errno
);
1256 /* Set extra register set. Currently a noop. */
1259 ps_lsetxregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, caddr_t xregset
)
1265 val
= get_lwp_fd (ph
, lwpid
, &lwp_fd
);
1269 if (ioctl (lwp_fd
, PIOCSXREG
, xregset
))
1271 print_sys_errmsg ("ps_lsetxregs (): PIOCSXREG", errno
);
1279 /* Get floating-point regs for LWP */
1282 ps_lgetfpregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
,
1283 prfpregset_t
* fpregset
)
1285 struct cleanup
*old_chain
;
1287 old_chain
= save_inferior_pid ();
1289 inferior_pid
= BUILD_LWP (lwpid
, PIDGET (inferior_pid
));
1291 if (target_has_execution
)
1292 procfs_ops
.to_fetch_registers (-1);
1294 orig_core_ops
.to_fetch_registers (-1);
1295 fill_fpregset ((gdb_fpregset_t
*) fpregset
, -1);
1297 do_cleanups (old_chain
);
1302 /* Set floating-point regs for LWP */
1305 ps_lsetfpregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
,
1306 const prfpregset_t
* fpregset
)
1308 struct cleanup
*old_chain
;
1310 old_chain
= save_inferior_pid ();
1312 inferior_pid
= BUILD_LWP (lwpid
, PIDGET (inferior_pid
));
1314 supply_fpregset ((gdb_fpregset_t
*) fpregset
);
1315 if (target_has_execution
)
1316 procfs_ops
.to_store_registers (-1);
1318 orig_core_ops
.to_store_registers (-1);
1320 do_cleanups (old_chain
);
1325 #ifdef PR_MODEL_LP64
1326 /* Identify process as 32-bit or 64-bit.
1327 At the moment I'm using bfd to do this.
1328 There might be a more solaris-specific (eg. procfs) method,
1329 but this ought to work. */
1332 ps_pdmodel (gdb_ps_prochandle_t ph
, int *data_model
)
1335 *data_model
= PR_MODEL_UNKNOWN
;
1336 else if (bfd_get_arch_size (exec_bfd
) == 32)
1337 *data_model
= PR_MODEL_ILP32
;
1339 *data_model
= PR_MODEL_LP64
;
1343 #endif /* PR_MODEL_LP64 */
1345 #ifdef TM_I386SOL2_H
1347 /* Reads the local descriptor table of a LWP. */
1350 ps_lgetLDT (gdb_ps_prochandle_t ph
, lwpid_t lwpid
,
1353 /* NOTE: only used on Solaris, therefore OK to refer to procfs.c */
1354 extern struct ssd
*procfs_find_LDT_entry (int);
1357 /* FIXME: can't I get the process ID from the prochandle or something?
1360 if (inferior_pid
<= 0 || lwpid
<= 0)
1363 ret
= procfs_find_LDT_entry (BUILD_LWP (lwpid
, PIDGET (inferior_pid
)));
1366 memcpy (pldt
, ret
, sizeof (struct ssd
));
1369 else /* LDT not found. */
1372 #endif /* TM_I386SOL2_H */
1374 /* Convert a pid to printable form. */
1377 solaris_pid_to_str (int pid
)
1379 static char buf
[100];
1381 /* in case init failed to resolve the libthread_db library */
1382 if (!procfs_suppress_run
)
1383 return procfs_pid_to_str (pid
);
1385 if (is_thread (pid
))
1389 lwp
= thread_to_lwp (pid
, -2);
1392 sprintf (buf
, "Thread %d (defunct)", GET_THREAD (pid
));
1394 sprintf (buf
, "Thread %d (LWP %d)", GET_THREAD (pid
), GET_LWP (lwp
));
1396 sprintf (buf
, "Thread %d ", GET_THREAD (pid
));
1398 else if (GET_LWP (pid
) != 0)
1399 sprintf (buf
, "LWP %d ", GET_LWP (pid
));
1401 sprintf (buf
, "process %d ", PIDGET (pid
));
1407 /* Worker bee for find_new_threads
1408 Callback function that gets called once per USER thread (i.e., not
1412 sol_find_new_threads_callback (const td_thrhandle_t
*th
, void *ignored
)
1418 if ((retval
= p_td_thr_get_info (th
, &ti
)) != TD_OK
)
1422 pid
= BUILD_THREAD (ti
.ti_tid
, PIDGET (inferior_pid
));
1423 if (!in_thread_list (pid
))
1430 sol_find_new_threads (void)
1432 /* don't do anything if init failed to resolve the libthread_db library */
1433 if (!procfs_suppress_run
)
1436 if (inferior_pid
== -1)
1438 printf_filtered ("No process.\n");
1441 procfs_find_new_threads (); /* first find new kernel threads. */
1442 p_td_ta_thr_iter (main_ta
, sol_find_new_threads_callback
, (void *) 0,
1443 TD_THR_ANY_STATE
, TD_THR_LOWEST_PRIORITY
,
1444 TD_SIGNO_MASK
, TD_THR_ANY_USER_FLAGS
);
1448 sol_core_open (char *filename
, int from_tty
)
1450 orig_core_ops
.to_open (filename
, from_tty
);
1454 sol_core_close (int quitting
)
1456 orig_core_ops
.to_close (quitting
);
1460 sol_core_detach (char *args
, int from_tty
)
1462 unpush_target (&core_ops
);
1463 orig_core_ops
.to_detach (args
, from_tty
);
1467 sol_core_files_info (struct target_ops
*t
)
1469 orig_core_ops
.to_files_info (t
);
1472 /* Worker bee for info sol-thread command. This is a callback function that
1473 gets called once for each Solaris thread (ie. not kernel thread) in the
1474 inferior. Print anything interesting that we can think of. */
1477 info_cb (const td_thrhandle_t
*th
, void *s
)
1482 if ((ret
= p_td_thr_get_info (th
, &ti
)) == TD_OK
)
1484 printf_filtered ("%s thread #%d, lwp %d, ",
1485 ti
.ti_type
== TD_THR_SYSTEM
? "system" : "user ",
1486 ti
.ti_tid
, ti
.ti_lid
);
1487 switch (ti
.ti_state
)
1490 case TD_THR_UNKNOWN
:
1491 printf_filtered ("<unknown state>");
1493 case TD_THR_STOPPED
:
1494 printf_filtered ("(stopped)");
1497 printf_filtered ("(run) ");
1500 printf_filtered ("(active) ");
1503 printf_filtered ("(zombie) ");
1506 printf_filtered ("(asleep) ");
1508 case TD_THR_STOPPED_ASLEEP
:
1509 printf_filtered ("(stopped asleep)");
1512 /* Print thr_create start function: */
1513 if (ti
.ti_startfunc
!= 0)
1515 struct minimal_symbol
*msym
;
1516 msym
= lookup_minimal_symbol_by_pc (ti
.ti_startfunc
);
1518 printf_filtered (" startfunc: %s\n", SYMBOL_NAME (msym
));
1520 printf_filtered (" startfunc: 0x%s\n", paddr (ti
.ti_startfunc
));
1523 /* If thread is asleep, print function that went to sleep: */
1524 if (ti
.ti_state
== TD_THR_SLEEP
)
1526 struct minimal_symbol
*msym
;
1527 msym
= lookup_minimal_symbol_by_pc (ti
.ti_pc
);
1529 printf_filtered (" - Sleep func: %s\n", SYMBOL_NAME (msym
));
1531 printf_filtered (" - Sleep func: 0x%s\n", paddr (ti
.ti_startfunc
));
1534 /* Wrap up line, if necessary */
1535 if (ti
.ti_state
!= TD_THR_SLEEP
&& ti
.ti_startfunc
== 0)
1536 printf_filtered ("\n"); /* don't you hate counting newlines? */
1539 warning ("info sol-thread: failed to get info for thread.");
1544 /* List some state about each Solaris user thread in the inferior. */
1547 info_solthreads (char *args
, int from_tty
)
1549 p_td_ta_thr_iter (main_ta
, info_cb
, args
,
1550 TD_THR_ANY_STATE
, TD_THR_LOWEST_PRIORITY
,
1551 TD_SIGNO_MASK
, TD_THR_ANY_USER_FLAGS
);
1555 ignore (CORE_ADDR addr
, char *contents
)
1562 init_sol_thread_ops (void)
1564 sol_thread_ops
.to_shortname
= "solaris-threads";
1565 sol_thread_ops
.to_longname
= "Solaris threads and pthread.";
1566 sol_thread_ops
.to_doc
= "Solaris threads and pthread support.";
1567 sol_thread_ops
.to_open
= sol_thread_open
;
1568 sol_thread_ops
.to_close
= 0;
1569 sol_thread_ops
.to_attach
= sol_thread_attach
;
1570 sol_thread_ops
.to_detach
= sol_thread_detach
;
1571 sol_thread_ops
.to_resume
= sol_thread_resume
;
1572 sol_thread_ops
.to_wait
= sol_thread_wait
;
1573 sol_thread_ops
.to_fetch_registers
= sol_thread_fetch_registers
;
1574 sol_thread_ops
.to_store_registers
= sol_thread_store_registers
;
1575 sol_thread_ops
.to_prepare_to_store
= sol_thread_prepare_to_store
;
1576 sol_thread_ops
.to_xfer_memory
= sol_thread_xfer_memory
;
1577 sol_thread_ops
.to_files_info
= sol_thread_files_info
;
1578 sol_thread_ops
.to_insert_breakpoint
= memory_insert_breakpoint
;
1579 sol_thread_ops
.to_remove_breakpoint
= memory_remove_breakpoint
;
1580 sol_thread_ops
.to_terminal_init
= terminal_init_inferior
;
1581 sol_thread_ops
.to_terminal_inferior
= terminal_inferior
;
1582 sol_thread_ops
.to_terminal_ours_for_output
= terminal_ours_for_output
;
1583 sol_thread_ops
.to_terminal_ours
= terminal_ours
;
1584 sol_thread_ops
.to_terminal_info
= child_terminal_info
;
1585 sol_thread_ops
.to_kill
= sol_thread_kill_inferior
;
1586 sol_thread_ops
.to_load
= 0;
1587 sol_thread_ops
.to_lookup_symbol
= 0;
1588 sol_thread_ops
.to_create_inferior
= sol_thread_create_inferior
;
1589 sol_thread_ops
.to_mourn_inferior
= sol_thread_mourn_inferior
;
1590 sol_thread_ops
.to_can_run
= sol_thread_can_run
;
1591 sol_thread_ops
.to_notice_signals
= sol_thread_notice_signals
;
1592 sol_thread_ops
.to_thread_alive
= sol_thread_alive
;
1593 sol_thread_ops
.to_pid_to_str
= solaris_pid_to_str
;
1594 sol_thread_ops
.to_find_new_threads
= sol_find_new_threads
;
1595 sol_thread_ops
.to_stop
= sol_thread_stop
;
1596 sol_thread_ops
.to_stratum
= process_stratum
;
1597 sol_thread_ops
.to_has_all_memory
= 1;
1598 sol_thread_ops
.to_has_memory
= 1;
1599 sol_thread_ops
.to_has_stack
= 1;
1600 sol_thread_ops
.to_has_registers
= 1;
1601 sol_thread_ops
.to_has_execution
= 1;
1602 sol_thread_ops
.to_has_thread_control
= tc_none
;
1603 sol_thread_ops
.to_sections
= 0;
1604 sol_thread_ops
.to_sections_end
= 0;
1605 sol_thread_ops
.to_magic
= OPS_MAGIC
;
1610 init_sol_core_ops (void)
1612 sol_core_ops
.to_shortname
= "solaris-core";
1613 sol_core_ops
.to_longname
= "Solaris core threads and pthread.";
1614 sol_core_ops
.to_doc
= "Solaris threads and pthread support for core files.";
1615 sol_core_ops
.to_open
= sol_core_open
;
1616 sol_core_ops
.to_close
= sol_core_close
;
1617 sol_core_ops
.to_attach
= sol_thread_attach
;
1618 sol_core_ops
.to_detach
= sol_core_detach
;
1619 /* sol_core_ops.to_resume = 0; */
1620 /* sol_core_ops.to_wait = 0; */
1621 sol_core_ops
.to_fetch_registers
= sol_thread_fetch_registers
;
1622 /* sol_core_ops.to_store_registers = 0; */
1623 /* sol_core_ops.to_prepare_to_store = 0; */
1624 sol_core_ops
.to_xfer_memory
= sol_thread_xfer_memory
;
1625 sol_core_ops
.to_files_info
= sol_core_files_info
;
1626 sol_core_ops
.to_insert_breakpoint
= ignore
;
1627 sol_core_ops
.to_remove_breakpoint
= ignore
;
1628 /* sol_core_ops.to_terminal_init = 0; */
1629 /* sol_core_ops.to_terminal_inferior = 0; */
1630 /* sol_core_ops.to_terminal_ours_for_output = 0; */
1631 /* sol_core_ops.to_terminal_ours = 0; */
1632 /* sol_core_ops.to_terminal_info = 0; */
1633 /* sol_core_ops.to_kill = 0; */
1634 /* sol_core_ops.to_load = 0; */
1635 /* sol_core_ops.to_lookup_symbol = 0; */
1636 sol_core_ops
.to_create_inferior
= sol_thread_create_inferior
;
1637 sol_core_ops
.to_stratum
= core_stratum
;
1638 sol_core_ops
.to_has_all_memory
= 0;
1639 sol_core_ops
.to_has_memory
= 1;
1640 sol_core_ops
.to_has_stack
= 1;
1641 sol_core_ops
.to_has_registers
= 1;
1642 sol_core_ops
.to_has_execution
= 0;
1643 sol_core_ops
.to_has_thread_control
= tc_none
;
1644 sol_core_ops
.to_thread_alive
= sol_thread_alive
;
1645 sol_core_ops
.to_pid_to_str
= solaris_pid_to_str
;
1646 /* On Solaris/x86, when debugging a threaded core file from process <n>,
1647 the following causes "info threads" to produce "procfs: couldn't find pid
1648 <n> in procinfo list" where <n> is the pid of the process that produced
1649 the core file. Disable it for now. */
1650 /* sol_core_ops.to_find_new_threads = sol_find_new_threads; */
1651 sol_core_ops
.to_sections
= 0;
1652 sol_core_ops
.to_sections_end
= 0;
1653 sol_core_ops
.to_magic
= OPS_MAGIC
;
1656 /* we suppress the call to add_target of core_ops in corelow because
1657 if there are two targets in the stratum core_stratum, find_core_target
1658 won't know which one to return. see corelow.c for an additonal
1659 comment on coreops_suppress_target. */
1660 int coreops_suppress_target
= 1;
1663 _initialize_sol_thread (void)
1667 init_sol_thread_ops ();
1668 init_sol_core_ops ();
1670 dlhandle
= dlopen ("libthread_db.so.1", RTLD_NOW
);
1674 #define resolve(X) \
1675 if (!(p_##X = dlsym (dlhandle, #X))) \
1679 resolve (td_ta_new
);
1680 resolve (td_ta_delete
);
1682 resolve (td_ta_get_ph
);
1683 resolve (td_ta_get_nthreads
);
1684 resolve (td_ta_tsd_iter
);
1685 resolve (td_ta_thr_iter
);
1686 resolve (td_thr_validate
);
1687 resolve (td_thr_tsd
);
1688 resolve (td_thr_get_info
);
1689 resolve (td_thr_getfpregs
);
1690 resolve (td_thr_getxregsize
);
1691 resolve (td_thr_getxregs
);
1692 resolve (td_thr_sigsetmask
);
1693 resolve (td_thr_setprio
);
1694 resolve (td_thr_setsigpending
);
1695 resolve (td_thr_setfpregs
);
1696 resolve (td_thr_setxregs
);
1697 resolve (td_ta_map_id2thr
);
1698 resolve (td_ta_map_lwp2thr
);
1699 resolve (td_thr_getgregs
);
1700 resolve (td_thr_setgregs
);
1702 add_target (&sol_thread_ops
);
1704 procfs_suppress_run
= 1;
1706 add_cmd ("sol-threads", class_maintenance
, info_solthreads
,
1707 "Show info on Solaris user threads.\n", &maintenanceinfolist
);
1709 memcpy (&orig_core_ops
, &core_ops
, sizeof (struct target_ops
));
1710 memcpy (&core_ops
, &sol_core_ops
, sizeof (struct target_ops
));
1711 add_target (&core_ops
);
1713 /* Hook into new_objfile notification. */
1714 target_new_objfile_chain
= target_new_objfile_hook
;
1715 target_new_objfile_hook
= sol_thread_new_objfile
;
1720 fprintf_unfiltered (gdb_stderr
, "[GDB will not be able to debug user-mode threads: %s]\n", dlerror ());
1725 /* allow the user to debug non-threaded core files */
1726 add_target (&core_ops
);