gdb/sol-thread.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Solaris threads debugging interface.

  2.    Copyright (C) 1996-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. /* This module implements a sort of half target that sits between the
  15.    machine-independent parts of GDB and the /proc interface (procfs.c)
  16.    to provide access to the Solaris user-mode thread implementation.

  17.    Solaris threads are true user-mode threads, which are invoked via
  18.    the thr_* and pthread_* (native and POSIX respectivly) interfaces.
  19.    These are mostly implemented in user-space, with all thread context
  20.    kept in various structures that live in the user's heap.  These
  21.    should not be confused with lightweight processes (LWPs), which are
  22.    implemented by the kernel, and scheduled without explicit
  23.    intervention by the process.

  24.    Just to confuse things a little, Solaris threads (both native and
  25.    POSIX) are actually implemented using LWPs.  In general, there are
  26.    going to be more threads than LWPs.  There is no fixed
  27.    correspondence between a thread and an LWP.  When a thread wants to
  28.    run, it gets scheduled onto the first available LWP and can
  29.    therefore migrate from one LWP to another as time goes on.  A
  30.    sleeping thread may not be associated with an LWP at all!

  31.    To make it possible to mess with threads, Sun provides a library
  32.    called libthread_db.so.1 (not to be confused with
  33.    libthread_db.so.0, which doesn't have a published interface).  This
  34.    interface has an upper part, which it provides, and a lower part
  35.    which we provide.  The upper part consists of the td_* routines,
  36.    which allow us to find all the threads, query their state, etc...
  37.    The lower part consists of all of the ps_*, which are used by the
  38.    td_* routines to read/write memory, manipulate LWPs, lookup
  39.    symbols, etc...  The ps_* routines actually do most of their work
  40.    by calling functions in procfs.c.  */

  41. #include "defs.h"
  42. #include <thread.h>
  43. #include <proc_service.h>
  44. #include <thread_db.h>
  45. #include "gdbthread.h"
  46. #include "target.h"
  47. #include "inferior.h"
  48. #include <fcntl.h>
  49. #include <sys/stat.h>
  50. #include <dlfcn.h>
  51. #include "gdbcmd.h"
  52. #include "gdbcore.h"
  53. #include "regcache.h"
  54. #include "solib.h"
  55. #include "symfile.h"
  56. #include "observer.h"
  57. #include "procfs.h"
  58. #include "symtab.h"
  59. #include "minsyms.h"
  60. #include "objfiles.h"

  61. struct target_ops sol_thread_ops;

  62. /* Prototypes for supply_gregset etc.  */
  63. #include "gregset.h"

  64. /* This struct is defined by us, but mainly used for the proc_service
  65.    interface.  We don't have much use for it, except as a handy place
  66.    to get a real PID for memory accesses.  */

  67. struct ps_prochandle
  68. {
  69.   ptid_t ptid;
  70. };

  71. struct string_map
  72. {
  73.   int num;
  74.   char *str;
  75. };

  76. static struct ps_prochandle main_ph;
  77. static td_thragent_t *main_ta;
  78. static int sol_thread_active = 0;

  79. static void init_sol_thread_ops (void);

  80. /* Default definitions: These must be defined in tm.h if they are to
  81.    be shared with a process module such as procfs.  */

  82. /* Pointers to routines from libthread_db resolved by dlopen().  */

  83. static void (*p_td_log)(const int on_off);
  84. static td_err_e (*p_td_ta_new)(const struct ps_prochandle *ph_p,
  85.                                td_thragent_t **ta_pp);
  86. static td_err_e (*p_td_ta_delete)(td_thragent_t *ta_p);
  87. static td_err_e (*p_td_init)(void);
  88. static td_err_e (*p_td_ta_get_ph)(const td_thragent_t *ta_p,
  89.                                   struct ps_prochandle **ph_pp);
  90. static td_err_e (*p_td_ta_get_nthreads)(const td_thragent_t *ta_p,
  91.                                         int *nthread_p);
  92. static td_err_e (*p_td_ta_tsd_iter)(const td_thragent_t *ta_p,
  93.                                     td_key_iter_f *cb, void *cbdata_p);
  94. static td_err_e (*p_td_ta_thr_iter)(const td_thragent_t *ta_p,
  95.                                     td_thr_iter_f *cb, void *cbdata_p,
  96.                                     td_thr_state_e state, int ti_pri,
  97.                                     sigset_t *ti_sigmask_p,
  98.                                     unsigned ti_user_flags);
  99. static td_err_e (*p_td_thr_validate)(const td_thrhandle_t *th_p);
  100. static td_err_e (*p_td_thr_tsd)(const td_thrhandle_t * th_p,
  101.                                 const thread_key_t key, void **data_pp);
  102. static td_err_e (*p_td_thr_get_info)(const td_thrhandle_t *th_p,
  103.                                      td_thrinfo_t *ti_p);
  104. static td_err_e (*p_td_thr_getfpregs)(const td_thrhandle_t *th_p,
  105.                                       prfpregset_t *fpregset);
  106. static td_err_e (*p_td_thr_getxregsize)(const td_thrhandle_t *th_p,
  107.                                         int *xregsize);
  108. static td_err_e (*p_td_thr_getxregs)(const td_thrhandle_t *th_p,
  109.                                      const caddr_t xregset);
  110. static td_err_e (*p_td_thr_sigsetmask)(const td_thrhandle_t *th_p,
  111.                                        const sigset_t ti_sigmask);
  112. static td_err_e (*p_td_thr_setprio)(const td_thrhandle_t *th_p,
  113.                                     const int ti_pri);
  114. static td_err_e (*p_td_thr_setsigpending)(const td_thrhandle_t *th_p,
  115.                                           const uchar_t ti_pending_flag,
  116.                                           const sigset_t ti_pending);
  117. static td_err_e (*p_td_thr_setfpregs)(const td_thrhandle_t *th_p,
  118.                                       const prfpregset_t *fpregset);
  119. static td_err_e (*p_td_thr_setxregs)(const td_thrhandle_t *th_p,
  120.                                      const caddr_t xregset);
  121. static td_err_e (*p_td_ta_map_id2thr)(const td_thragent_t *ta_p,
  122.                                       thread_t tid,
  123.                                       td_thrhandle_t *th_p);
  124. static td_err_e (*p_td_ta_map_lwp2thr)(const td_thragent_t *ta_p,
  125.                                        lwpid_t lwpid,
  126.                                        td_thrhandle_t *th_p);
  127. static td_err_e (*p_td_thr_getgregs)(const td_thrhandle_t *th_p,
  128.                                      prgregset_t regset);
  129. static td_err_e (*p_td_thr_setgregs)(const td_thrhandle_t *th_p,
  130.                                      const prgregset_t regset);


  131. /* Return the libthread_db error string associated with ERRCODE.  If
  132.    ERRCODE is unknown, return an appropriate message.  */

  133. static char *
  134. td_err_string (td_err_e errcode)
  135. {
  136.   static struct string_map td_err_table[] =
  137.   {
  138.     { TD_OK, "generic \"call succeeded\"" },
  139.     { TD_ERR, "generic error." },
  140.     { TD_NOTHR, "no thread can be found to satisfy query" },
  141.     { TD_NOSV, "no synch. variable can be found to satisfy query" },
  142.     { TD_NOLWP, "no lwp can be found to satisfy query" },
  143.     { TD_BADPH, "invalid process handle" },
  144.     { TD_BADTH, "invalid thread handle" },
  145.     { TD_BADSH, "invalid synchronization handle" },
  146.     { TD_BADTA, "invalid thread agent" },
  147.     { TD_BADKEY, "invalid key" },
  148.     { TD_NOMSG, "td_thr_event_getmsg() called when there was no message" },
  149.     { TD_NOFPREGS, "FPU register set not available for given thread" },
  150.     { TD_NOLIBTHREAD, "application not linked with libthread" },
  151.     { TD_NOEVENT, "requested event is not supported" },
  152.     { TD_NOCAPAB, "capability not available" },
  153.     { TD_DBERR, "Debugger service failed" },
  154.     { TD_NOAPLIC, "Operation not applicable to" },
  155.     { TD_NOTSD, "No thread specific data for this thread" },
  156.     { TD_MALLOC, "Malloc failed" },
  157.     { TD_PARTIALREG, "Only part of register set was written/read" },
  158.     { TD_NOXREGS, "X register set not available for given thread" }
  159.   };
  160.   const int td_err_size = sizeof td_err_table / sizeof (struct string_map);
  161.   int i;
  162.   static char buf[50];

  163.   for (i = 0; i < td_err_size; i++)
  164.     if (td_err_table[i].num == errcode)
  165.       return td_err_table[i].str;

  166.   xsnprintf (buf, sizeof (buf), "Unknown libthread_db error code: %d",
  167.              errcode);

  168.   return buf;
  169. }

  170. /* Return the libthread_db state string assicoated with STATECODE.
  171.    If STATECODE is unknown, return an appropriate message.  */

  172. static char *
  173. td_state_string (td_thr_state_e statecode)
  174. {
  175.   static struct string_map td_thr_state_table[] =
  176.   {
  177.     { TD_THR_ANY_STATE, "any state" },
  178.     { TD_THR_UNKNOWN, "unknown" },
  179.     { TD_THR_STOPPED, "stopped" },
  180.     { TD_THR_RUN, "run" },
  181.     { TD_THR_ACTIVE, "active" },
  182.     { TD_THR_ZOMBIE, "zombie" },
  183.     { TD_THR_SLEEP, "sleep" },
  184.     { TD_THR_STOPPED_ASLEEP, "stopped asleep" }
  185.   };
  186.   const int td_thr_state_table_size =
  187.     sizeof td_thr_state_table / sizeof (struct string_map);
  188.   int i;
  189.   static char buf[50];

  190.   for (i = 0; i < td_thr_state_table_size; i++)
  191.     if (td_thr_state_table[i].num == statecode)
  192.       return td_thr_state_table[i].str;

  193.   xsnprintf (buf, sizeof (buf), "Unknown libthread_db state code: %d",
  194.              statecode);

  195.   return buf;
  196. }


  197. /* Convert a POSIX or Solaris thread ID into a LWP ID.  If THREAD_ID
  198.    doesn't exist, that's an error.  If it's an inactive thread, return
  199.    DEFAULT_LWP.

  200.    NOTE: This function probably shouldn't call error().  */

  201. static ptid_t
  202. thread_to_lwp (ptid_t thread_id, int default_lwp)
  203. {
  204.   td_thrinfo_t ti;
  205.   td_thrhandle_t th;
  206.   td_err_e val;

  207.   if (ptid_lwp_p (thread_id))
  208.     return thread_id;                /* It's already an LWP ID.  */

  209.   /* It's a thread.  Convert to LWP.  */

  210.   val = p_td_ta_map_id2thr (main_ta, ptid_get_tid (thread_id), &th);
  211.   if (val == TD_NOTHR)
  212.     return pid_to_ptid (-1);        /* Thread must have terminated.  */
  213.   else if (val != TD_OK)
  214.     error (_("thread_to_lwp: td_ta_map_id2thr %s"), td_err_string (val));

  215.   val = p_td_thr_get_info (&th, &ti);
  216.   if (val == TD_NOTHR)
  217.     return pid_to_ptid (-1);        /* Thread must have terminated.  */
  218.   else if (val != TD_OK)
  219.     error (_("thread_to_lwp: td_thr_get_info: %s"), td_err_string (val));

  220.   if (ti.ti_state != TD_THR_ACTIVE)
  221.     {
  222.       if (default_lwp != -1)
  223.         return pid_to_ptid (default_lwp);
  224.       error (_("thread_to_lwp: thread state not active: %s"),
  225.              td_state_string (ti.ti_state));
  226.     }

  227.   return ptid_build (ptid_get_pid (thread_id), ti.ti_lid, 0);
  228. }

  229. /* Convert an LWP ID into a POSIX or Solaris thread ID.  If LWP_ID
  230.    doesn't exists, that's an error.

  231.    NOTE: This function probably shouldn't call error().  */

  232. static ptid_t
  233. lwp_to_thread (ptid_t lwp)
  234. {
  235.   td_thrinfo_t ti;
  236.   td_thrhandle_t th;
  237.   td_err_e val;

  238.   if (ptid_tid_p (lwp))
  239.     return lwp;                        /* It's already a thread ID.  */

  240.   /* It's an LWP.  Convert it to a thread ID.  */

  241.   if (!target_thread_alive (lwp))
  242.     return pid_to_ptid (-1);        /* Must be a defunct LPW.  */

  243.   val = p_td_ta_map_lwp2thr (main_ta, ptid_get_lwp (lwp), &th);
  244.   if (val == TD_NOTHR)
  245.     return pid_to_ptid (-1);        /* Thread must have terminated.  */
  246.   else if (val != TD_OK)
  247.     error (_("lwp_to_thread: td_ta_map_lwp2thr: %s."), td_err_string (val));

  248.   val = p_td_thr_validate (&th);
  249.   if (val == TD_NOTHR)
  250.     return lwp;                        /* Unknown to libthread; just return LPW,  */
  251.   else if (val != TD_OK)
  252.     error (_("lwp_to_thread: td_thr_validate: %s."), td_err_string (val));

  253.   val = p_td_thr_get_info (&th, &ti);
  254.   if (val == TD_NOTHR)
  255.     return pid_to_ptid (-1);        /* Thread must have terminated.  */
  256.   else if (val != TD_OK)
  257.     error (_("lwp_to_thread: td_thr_get_info: %s."), td_err_string (val));

  258.   return ptid_build (ptid_get_pid (lwp), 0 , ti.ti_tid);
  259. }


  260. /* Most target vector functions from here on actually just pass
  261.    through to the layer beneath, as they don't need to do anything
  262.    specific for threads.  */

  263. /* Take a program previously attached to and detaches it.  The program
  264.    resumes execution and will no longer stop on signals, etc.  We'd
  265.    better not have left any breakpoints in the program or it'll die
  266.    when it hits one.  For this to work, it may be necessary for the
  267.    process to have been previously attached.  It *might* work if the
  268.    program was started via the normal ptrace (PTRACE_TRACEME).  */

  269. static void
  270. sol_thread_detach (struct target_ops *ops, const char *args, int from_tty)
  271. {
  272.   struct target_ops *beneath = find_target_beneath (ops);

  273.   sol_thread_active = 0;
  274.   inferior_ptid = pid_to_ptid (ptid_get_pid (main_ph.ptid));
  275.   unpush_target (ops);
  276.   beneath->to_detach (beneath, args, from_tty);
  277. }

  278. /* Resume execution of process PTID.  If STEP is nozero, then just
  279.    single step it.  If SIGNAL is nonzero, restart it with that signal
  280.    activated.  We may have to convert PTID from a thread ID to an LWP
  281.    ID for procfs.  */

  282. static void
  283. sol_thread_resume (struct target_ops *ops,
  284.                    ptid_t ptid, int step, enum gdb_signal signo)
  285. {
  286.   struct cleanup *old_chain;
  287.   struct target_ops *beneath = find_target_beneath (ops);

  288.   old_chain = save_inferior_ptid ();

  289.   inferior_ptid = thread_to_lwp (inferior_ptid, ptid_get_pid (main_ph.ptid));
  290.   if (ptid_get_pid (inferior_ptid) == -1)
  291.     inferior_ptid = procfs_first_available ();

  292.   if (ptid_get_pid (ptid) != -1)
  293.     {
  294.       ptid_t save_ptid = ptid;

  295.       ptid = thread_to_lwp (ptid, -2);
  296.       if (ptid_get_pid (ptid) == -2)                /* Inactive thread.  */
  297.         error (_("This version of Solaris can't start inactive threads."));
  298.       if (info_verbose && ptid_get_pid (ptid) == -1)
  299.         warning (_("Specified thread %ld seems to have terminated"),
  300.                  ptid_get_tid (save_ptid));
  301.     }

  302.   beneath->to_resume (beneath, ptid, step, signo);

  303.   do_cleanups (old_chain);
  304. }

  305. /* Wait for any threads to stop.  We may have to convert PTID from a
  306.    thread ID to an LWP ID, and vice versa on the way out.  */

  307. static ptid_t
  308. sol_thread_wait (struct target_ops *ops,
  309.                  ptid_t ptid, struct target_waitstatus *ourstatus, int options)
  310. {
  311.   ptid_t rtnval;
  312.   ptid_t save_ptid;
  313.   struct target_ops *beneath = find_target_beneath (ops);
  314.   struct cleanup *old_chain;

  315.   save_ptid = inferior_ptid;
  316.   old_chain = save_inferior_ptid ();

  317.   inferior_ptid = thread_to_lwp (inferior_ptid, ptid_get_pid (main_ph.ptid));
  318.   if (ptid_get_pid (inferior_ptid) == -1)
  319.     inferior_ptid = procfs_first_available ();

  320.   if (ptid_get_pid (ptid) != -1)
  321.     {
  322.       ptid_t save_ptid = ptid;

  323.       ptid = thread_to_lwp (ptid, -2);
  324.       if (ptid_get_pid (ptid) == -2)                /* Inactive thread.  */
  325.         error (_("This version of Solaris can't start inactive threads."));
  326.       if (info_verbose && ptid_get_pid (ptid) == -1)
  327.         warning (_("Specified thread %ld seems to have terminated"),
  328.                  ptid_get_tid (save_ptid));
  329.     }

  330.   rtnval = beneath->to_wait (beneath, ptid, ourstatus, options);

  331.   if (ourstatus->kind != TARGET_WAITKIND_EXITED)
  332.     {
  333.       /* Map the LWP of interest back to the appropriate thread ID.  */
  334.       rtnval = lwp_to_thread (rtnval);
  335.       if (ptid_get_pid (rtnval) == -1)
  336.         rtnval = save_ptid;

  337.       /* See if we have a new thread.  */
  338.       if (ptid_tid_p (rtnval)
  339.           && !ptid_equal (rtnval, save_ptid)
  340.           && (!in_thread_list (rtnval)
  341.               || is_exited (rtnval)))
  342.         add_thread (rtnval);
  343.     }

  344.   /* During process initialization, we may get here without the thread
  345.      package being initialized, since that can only happen after we've
  346.      found the shared libs.  */

  347.   do_cleanups (old_chain);

  348.   return rtnval;
  349. }

  350. static void
  351. sol_thread_fetch_registers (struct target_ops *ops,
  352.                             struct regcache *regcache, int regnum)
  353. {
  354.   thread_t thread;
  355.   td_thrhandle_t thandle;
  356.   td_err_e val;
  357.   prgregset_t gregset;
  358.   prfpregset_t fpregset;
  359.   gdb_gregset_t *gregset_p = &gregset;
  360.   gdb_fpregset_t *fpregset_p = &fpregset;
  361.   struct target_ops *beneath = find_target_beneath (ops);

  362.   if (!ptid_tid_p (inferior_ptid))
  363.     {
  364.       /* It's an LWP; pass the request on to the layer beneath.  */
  365.       beneath->to_fetch_registers (beneath, regcache, regnum);
  366.       return;
  367.     }

  368.   /* Solaris thread: convert INFERIOR_PTID into a td_thrhandle_t.  */
  369.   thread = ptid_get_tid (inferior_ptid);
  370.   if (thread == 0)
  371.     error (_("sol_thread_fetch_registers: thread == 0"));

  372.   val = p_td_ta_map_id2thr (main_ta, thread, &thandle);
  373.   if (val != TD_OK)
  374.     error (_("sol_thread_fetch_registers: td_ta_map_id2thr: %s"),
  375.            td_err_string (val));

  376.   /* Get the general-purpose registers.  */

  377.   val = p_td_thr_getgregs (&thandle, gregset);
  378.   if (val != TD_OK && val != TD_PARTIALREG)
  379.     error (_("sol_thread_fetch_registers: td_thr_getgregs %s"),
  380.            td_err_string (val));

  381.   /* For SPARC, TD_PARTIALREG means that only %i0...%i7, %l0..%l7, %pc
  382.      and %sp are saved (by a thread context switch).  */

  383.   /* And, now the floating-point registers.  */

  384.   val = p_td_thr_getfpregs (&thandle, &fpregset);
  385.   if (val != TD_OK && val != TD_NOFPREGS)
  386.     error (_("sol_thread_fetch_registers: td_thr_getfpregs %s"),
  387.            td_err_string (val));

  388.   /* Note that we must call supply_gregset and supply_fpregset *after*
  389.      calling the td routines because the td routines call ps_lget*
  390.      which affect the values stored in the registers array.  */

  391.   supply_gregset (regcache, (const gdb_gregset_t *) gregset_p);
  392.   supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset_p);
  393. }

  394. static void
  395. sol_thread_store_registers (struct target_ops *ops,
  396.                             struct regcache *regcache, int regnum)
  397. {
  398.   thread_t thread;
  399.   td_thrhandle_t thandle;
  400.   td_err_e val;
  401.   prgregset_t gregset;
  402.   prfpregset_t fpregset;

  403.   if (!ptid_tid_p (inferior_ptid))
  404.     {
  405.       struct target_ops *beneath = find_target_beneath (ops);

  406.       /* It's an LWP; pass the request on to the layer beneath.  */
  407.       beneath->to_store_registers (beneath, regcache, regnum);
  408.       return;
  409.     }

  410.   /* Solaris thread: convert INFERIOR_PTID into a td_thrhandle_t.  */
  411.   thread = ptid_get_tid (inferior_ptid);

  412.   val = p_td_ta_map_id2thr (main_ta, thread, &thandle);
  413.   if (val != TD_OK)
  414.     error (_("sol_thread_store_registers: td_ta_map_id2thr %s"),
  415.            td_err_string (val));

  416.   if (regnum != -1)
  417.     {
  418.       /* Not writing all the registers.  */
  419.       char old_value[MAX_REGISTER_SIZE];

  420.       /* Save new register value.  */
  421.       regcache_raw_collect (regcache, regnum, old_value);

  422.       val = p_td_thr_getgregs (&thandle, gregset);
  423.       if (val != TD_OK)
  424.         error (_("sol_thread_store_registers: td_thr_getgregs %s"),
  425.                td_err_string (val));
  426.       val = p_td_thr_getfpregs (&thandle, &fpregset);
  427.       if (val != TD_OK)
  428.         error (_("sol_thread_store_registers: td_thr_getfpregs %s"),
  429.                td_err_string (val));

  430.       /* Restore new register value.  */
  431.       regcache_raw_supply (regcache, regnum, old_value);
  432.     }

  433.   fill_gregset (regcache, (gdb_gregset_t *) &gregset, regnum);
  434.   fill_fpregset (regcache, (gdb_fpregset_t *) &fpregset, regnum);

  435.   val = p_td_thr_setgregs (&thandle, gregset);
  436.   if (val != TD_OK)
  437.     error (_("sol_thread_store_registers: td_thr_setgregs %s"),
  438.            td_err_string (val));
  439.   val = p_td_thr_setfpregs (&thandle, &fpregset);
  440.   if (val != TD_OK)
  441.     error (_("sol_thread_store_registers: td_thr_setfpregs %s"),
  442.            td_err_string (val));
  443. }

  444. /* Perform partial transfers on OBJECT.  See target_read_partial and
  445.    target_write_partial for details of each variantOne, and only
  446.    one, of readbuf or writebuf must be non-NULL.  */

  447. static enum target_xfer_status
  448. sol_thread_xfer_partial (struct target_ops *ops, enum target_object object,
  449.                           const char *annex, gdb_byte *readbuf,
  450.                           const gdb_byte *writebuf,
  451.                          ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
  452. {
  453.   enum target_xfer_status retval;
  454.   struct cleanup *old_chain;
  455.   struct target_ops *beneath = find_target_beneath (ops);

  456.   old_chain = save_inferior_ptid ();

  457.   if (ptid_tid_p (inferior_ptid) || !target_thread_alive (inferior_ptid))
  458.     {
  459.       /* It's either a thread or an LWP that isn't alive.  Any live
  460.          LWP will do so use the first available.

  461.          NOTE: We don't need to call switch_to_thread; we're just
  462.          reading memory.  */
  463.       inferior_ptid = procfs_first_available ();
  464.     }

  465.   retval = beneath->to_xfer_partial (beneath, object, annex, readbuf,
  466.                                      writebuf, offset, len, xfered_len);

  467.   do_cleanups (old_chain);

  468.   return retval;
  469. }

  470. static void
  471. check_for_thread_db (void)
  472. {
  473.   td_err_e err;
  474.   ptid_t ptid;

  475.   /* Don't attempt to use thread_db for remote targets.  */
  476.   if (!(target_can_run (&current_target) || core_bfd))
  477.     return;

  478.   /* Do nothing if we couldn't load libthread_db.so.1.  */
  479.   if (p_td_ta_new == NULL)
  480.     return;

  481.   if (sol_thread_active)
  482.     /* Nothing to do.  The thread library was already detected and the
  483.        target vector was already activated.  */
  484.     return;

  485.   /* Now, initialize libthread_db.  This needs to be done after the
  486.      shared libraries are located because it needs information from
  487.      the user's thread library.  */

  488.   err = p_td_init ();
  489.   if (err != TD_OK)
  490.     {
  491.       warning (_("sol_thread_new_objfile: td_init: %s"), td_err_string (err));
  492.       return;
  493.     }

  494.   /* Now attempt to open a connection to the thread library.  */
  495.   err = p_td_ta_new (&main_ph, &main_ta);
  496.   switch (err)
  497.     {
  498.     case TD_NOLIBTHREAD:
  499.       /* No thread library was detected.  */
  500.       break;

  501.     case TD_OK:
  502.       printf_unfiltered (_("[Thread debugging using libthread_db enabled]\n"));

  503.       /* The thread library was detected.  Activate the sol_thread target.  */
  504.       push_target (&sol_thread_ops);
  505.       sol_thread_active = 1;

  506.       main_ph.ptid = inferior_ptid; /* Save for xfer_memory.  */
  507.       ptid = lwp_to_thread (inferior_ptid);
  508.       if (ptid_get_pid (ptid) != -1)
  509.         inferior_ptid = ptid;

  510.       target_update_thread_list ();
  511.       break;

  512.     default:
  513.       warning (_("Cannot initialize thread debugging library: %s"),
  514.                td_err_string (err));
  515.       break;
  516.     }
  517. }

  518. /* This routine is called whenever a new symbol table is read in, or
  519.    when all symbol tables are removed.  libthread_db can only be
  520.    initialized when it finds the right variables in libthread.so.
  521.    Since it's a shared library, those variables don't show up until
  522.    the library gets mapped and the symbol table is read in.  */

  523. static void
  524. sol_thread_new_objfile (struct objfile *objfile)
  525. {
  526.   if (objfile != NULL)
  527.     check_for_thread_db ();
  528. }

  529. /* Clean up after the inferior dies.  */

  530. static void
  531. sol_thread_mourn_inferior (struct target_ops *ops)
  532. {
  533.   struct target_ops *beneath = find_target_beneath (ops);

  534.   sol_thread_active = 0;

  535.   unpush_target (ops);

  536.   beneath->to_mourn_inferior (beneath);
  537. }

  538. /* Return true if PTID is still active in the inferior.  */

  539. static int
  540. sol_thread_alive (struct target_ops *ops, ptid_t ptid)
  541. {
  542.   if (ptid_tid_p (ptid))
  543.     {
  544.       /* It's a (user-level) thread.  */
  545.       td_err_e val;
  546.       td_thrhandle_t th;
  547.       int pid;

  548.       pid = ptid_get_tid (ptid);
  549.       if ((val = p_td_ta_map_id2thr (main_ta, pid, &th)) != TD_OK)
  550.         return 0;                /* Thread not found.  */
  551.       if ((val = p_td_thr_validate (&th)) != TD_OK)
  552.         return 0;                /* Thread not valid.  */
  553.       return 1;                        /* Known thread.  */
  554.     }
  555.   else
  556.     {
  557.       struct target_ops *beneath = find_target_beneath (ops);

  558.       /* It's an LPW; pass the request on to the layer below.  */
  559.       return beneath->to_thread_alive (beneath, ptid);
  560.     }
  561. }


  562. /* These routines implement the lower half of the thread_db interface,
  563.    i.e. the ps_* routines.  */

  564. /* Various versions of <proc_service.h> have slightly different
  565.    function prototypes.  In particular, we have

  566.    NEWER                        OLDER
  567.    struct ps_prochandle *       const struct ps_prochandle *
  568.    void*                        char*
  569.    const void*                  char*
  570.    int                          size_t

  571.    Which one you have depends on the Solaris version and what patches
  572.    you've applied.  On the theory that there are only two major
  573.    variants, we have configure check the prototype of ps_pdwrite (),
  574.    and use that info to make appropriate typedefs here.  */

  575. #ifdef PROC_SERVICE_IS_OLD
  576. typedef const struct ps_prochandle *gdb_ps_prochandle_t;
  577. typedef char *gdb_ps_read_buf_t;
  578. typedef char *gdb_ps_write_buf_t;
  579. typedef int gdb_ps_size_t;
  580. typedef psaddr_t gdb_ps_addr_t;
  581. #else
  582. typedef struct ps_prochandle *gdb_ps_prochandle_t;
  583. typedef void *gdb_ps_read_buf_t;
  584. typedef const void *gdb_ps_write_buf_t;
  585. typedef size_t gdb_ps_size_t;
  586. typedef psaddr_t gdb_ps_addr_t;
  587. #endif

  588. /* The next four routines are called by libthread_db to tell us to
  589.    stop and stop a particular process or lwp.  Since GDB ensures that
  590.    these are all stopped by the time we call anything in thread_db,
  591.    these routines need to do nothing.  */

  592. /* Process stop.  */

  593. ps_err_e
  594. ps_pstop (gdb_ps_prochandle_t ph)
  595. {
  596.   return PS_OK;
  597. }

  598. /* Process continue.  */

  599. ps_err_e
  600. ps_pcontinue (gdb_ps_prochandle_t ph)
  601. {
  602.   return PS_OK;
  603. }

  604. /* LWP stop.  */

  605. ps_err_e
  606. ps_lstop (gdb_ps_prochandle_t ph, lwpid_t lwpid)
  607. {
  608.   return PS_OK;
  609. }

  610. /* LWP continue.  */

  611. ps_err_e
  612. ps_lcontinue (gdb_ps_prochandle_t ph, lwpid_t lwpid)
  613. {
  614.   return PS_OK;
  615. }

  616. /* Looks up the symbol LD_SYMBOL_NAME in the debugger's symbol table.  */

  617. ps_err_e
  618. ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *ld_object_name,
  619.                    const char *ld_symbol_name, gdb_ps_addr_t *ld_symbol_addr)
  620. {
  621.   struct bound_minimal_symbol ms;

  622.   ms = lookup_minimal_symbol (ld_symbol_name, NULL, NULL);
  623.   if (!ms.minsym)
  624.     return PS_NOSYM;

  625.   *ld_symbol_addr = BMSYMBOL_VALUE_ADDRESS (ms);
  626.   return PS_OK;
  627. }

  628. /* Common routine for reading and writing memory.  */

  629. static ps_err_e
  630. rw_common (int dowrite, const struct ps_prochandle *ph, gdb_ps_addr_t addr,
  631.            gdb_byte *buf, int size)
  632. {
  633.   int ret;
  634.   struct cleanup *old_chain;

  635.   old_chain = save_inferior_ptid ();

  636.   if (ptid_tid_p (inferior_ptid) || !target_thread_alive (inferior_ptid))
  637.     {
  638.       /* It's either a thread or an LWP that isn't alive.  Any live
  639.          LWP will do so use the first available.

  640.          NOTE: We don't need to call switch_to_thread; we're just
  641.          reading memory.  */
  642.       inferior_ptid = procfs_first_available ();
  643.     }

  644. #if defined (__sparcv9)
  645.   /* For Sparc64 cross Sparc32, make sure the address has not been
  646.      accidentally sign-extended (or whatever) to beyond 32 bits.  */
  647.   if (bfd_get_arch_size (exec_bfd) == 32)
  648.     addr &= 0xffffffff;
  649. #endif

  650.   if (dowrite)
  651.     ret = target_write_memory (addr, (gdb_byte *) buf, size);
  652.   else
  653.     ret = target_read_memory (addr, (gdb_byte *) buf, size);

  654.   do_cleanups (old_chain);

  655.   return (ret == 0 ? PS_OK : PS_ERR);
  656. }

  657. /* Copies SIZE bytes from target process .data segment to debugger memory.  */

  658. ps_err_e
  659. ps_pdread (gdb_ps_prochandle_t ph, gdb_ps_addr_t addr,
  660.            gdb_ps_read_buf_t buf, gdb_ps_size_t size)
  661. {
  662.   return rw_common (0, ph, addr, buf, size);
  663. }

  664. /* Copies SIZE bytes from debugger memory .data segment to target process.  */

  665. ps_err_e
  666. ps_pdwrite (gdb_ps_prochandle_t ph, gdb_ps_addr_t addr,
  667.             gdb_ps_write_buf_t buf, gdb_ps_size_t size)
  668. {
  669.   return rw_common (1, ph, addr, (gdb_byte *) buf, size);
  670. }

  671. /* Copies SIZE bytes from target process .text segment to debugger memory.  */

  672. ps_err_e
  673. ps_ptread (gdb_ps_prochandle_t ph, gdb_ps_addr_t addr,
  674.            gdb_ps_read_buf_t buf, gdb_ps_size_t size)
  675. {
  676.   return rw_common (0, ph, addr, buf, size);
  677. }

  678. /* Copies SIZE bytes from debugger memory .text segment to target process.  */

  679. ps_err_e
  680. ps_ptwrite (gdb_ps_prochandle_t ph, gdb_ps_addr_t addr,
  681.             gdb_ps_write_buf_t buf, gdb_ps_size_t size)
  682. {
  683.   return rw_common (1, ph, addr, (gdb_byte *) buf, size);
  684. }

  685. /* Get general-purpose registers for LWP.  */

  686. ps_err_e
  687. ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
  688. {
  689.   struct cleanup *old_chain;
  690.   struct regcache *regcache;

  691.   old_chain = save_inferior_ptid ();

  692.   inferior_ptid = ptid_build (ptid_get_pid (inferior_ptid), lwpid, 0);
  693.   regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ());

  694.   target_fetch_registers (regcache, -1);
  695.   fill_gregset (regcache, (gdb_gregset_t *) gregset, -1);

  696.   do_cleanups (old_chain);

  697.   return PS_OK;
  698. }

  699. /* Set general-purpose registers for LWP.  */

  700. ps_err_e
  701. ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
  702.              const prgregset_t gregset)
  703. {
  704.   struct cleanup *old_chain;
  705.   struct regcache *regcache;

  706.   old_chain = save_inferior_ptid ();

  707.   inferior_ptid = ptid_build (ptid_get_pid (inferior_ptid), lwpid, 0);
  708.   regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ());

  709.   supply_gregset (regcache, (const gdb_gregset_t *) gregset);
  710.   target_store_registers (regcache, -1);

  711.   do_cleanups (old_chain);

  712.   return PS_OK;
  713. }

  714. /* Log a message (sends to gdb_stderr).  */

  715. void
  716. ps_plog (const char *fmt, ...)
  717. {
  718.   va_list args;

  719.   va_start (args, fmt);

  720.   vfprintf_filtered (gdb_stderr, fmt, args);
  721. }

  722. /* Get size of extra register set.  Currently a noop.  */

  723. ps_err_e
  724. ps_lgetxregsize (gdb_ps_prochandle_t ph, lwpid_t lwpid, int *xregsize)
  725. {
  726.   return PS_OK;
  727. }

  728. /* Get extra register set.  Currently a noop.  */

  729. ps_err_e
  730. ps_lgetxregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, caddr_t xregset)
  731. {
  732.   return PS_OK;
  733. }

  734. /* Set extra register set.  Currently a noop.  */

  735. ps_err_e
  736. ps_lsetxregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, caddr_t xregset)
  737. {
  738.   return PS_OK;
  739. }

  740. /* Get floating-point registers for LWP.  */

  741. ps_err_e
  742. ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
  743.                prfpregset_t *fpregset)
  744. {
  745.   struct cleanup *old_chain;
  746.   struct regcache *regcache;

  747.   old_chain = save_inferior_ptid ();

  748.   inferior_ptid = ptid_build (ptid_get_pid (inferior_ptid), lwpid, 0);
  749.   regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ());

  750.   target_fetch_registers (regcache, -1);
  751.   fill_fpregset (regcache, (gdb_fpregset_t *) fpregset, -1);

  752.   do_cleanups (old_chain);

  753.   return PS_OK;
  754. }

  755. /* Set floating-point regs for LWP.  */

  756. ps_err_e
  757. ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
  758.                const prfpregset_t * fpregset)
  759. {
  760.   struct cleanup *old_chain;
  761.   struct regcache *regcache;

  762.   old_chain = save_inferior_ptid ();

  763.   inferior_ptid = ptid_build (ptid_get_pid (inferior_ptid), lwpid, 0);
  764.   regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ());

  765.   supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset);
  766.   target_store_registers (regcache, -1);

  767.   do_cleanups (old_chain);

  768.   return PS_OK;
  769. }

  770. #ifdef PR_MODEL_LP64
  771. /* Identify process as 32-bit or 64-bit.  At the moment we're using
  772.    BFD to do this.  There might be a more Solaris-specific
  773.    (e.g. procfs) method, but this ought to work.  */

  774. ps_err_e
  775. ps_pdmodel (gdb_ps_prochandle_t ph, int *data_model)
  776. {
  777.   if (exec_bfd == 0)
  778.     *data_model = PR_MODEL_UNKNOWN;
  779.   else if (bfd_get_arch_size (exec_bfd) == 32)
  780.     *data_model = PR_MODEL_ILP32;
  781.   else
  782.     *data_model = PR_MODEL_LP64;

  783.   return PS_OK;
  784. }
  785. #endif /* PR_MODEL_LP64 */

  786. #if (defined(__i386__) || defined(__x86_64__)) && defined (sun)

  787. /* Reads the local descriptor table of a LWP.

  788.    This function is necessary on x86-solaris only.  Without it, the loading
  789.    of libthread_db would fail because of ps_lgetLDT being undefined.  */

  790. ps_err_e
  791. ps_lgetLDT (gdb_ps_prochandle_t ph, lwpid_t lwpid,
  792.             struct ssd *pldt)
  793. {
  794.   /* NOTE: only used on Solaris, therefore OK to refer to procfs.c.  */
  795.   struct ssd *ret;

  796.   /* FIXME: can't I get the process ID from the prochandle or
  797.      something?  */

  798.   if (ptid_get_pid (inferior_ptid) <= 0 || lwpid <= 0)
  799.     return PS_BADLID;

  800.   ret = procfs_find_LDT_entry (ptid_build (ptid_get_pid (inferior_ptid),
  801.                                lwpid, 0));
  802.   if (ret)
  803.     {
  804.       memcpy (pldt, ret, sizeof (struct ssd));
  805.       return PS_OK;
  806.     }
  807.   else
  808.     /* LDT not found.  */
  809.     return PS_ERR;
  810. }
  811. #endif


  812. /* Convert PTID to printable form.  */

  813. static char *
  814. solaris_pid_to_str (struct target_ops *ops, ptid_t ptid)
  815. {
  816.   static char buf[100];

  817.   if (ptid_tid_p (ptid))
  818.     {
  819.       ptid_t lwp;

  820.       lwp = thread_to_lwp (ptid, -2);

  821.       if (ptid_get_pid (lwp) == -1)
  822.         xsnprintf (buf, sizeof (buf), "Thread %ld (defunct)",
  823.                    ptid_get_tid (ptid));
  824.       else if (ptid_get_pid (lwp) != -2)
  825.         xsnprintf (buf, sizeof (buf), "Thread %ld (LWP %ld)",
  826.                  ptid_get_tid (ptid), ptid_get_lwp (lwp));
  827.       else
  828.         xsnprintf (buf, sizeof (buf), "Thread %ld        ",
  829.                    ptid_get_tid (ptid));
  830.     }
  831.   else if (ptid_get_lwp (ptid) != 0)
  832.     xsnprintf (buf, sizeof (buf), "LWP    %ld        ", ptid_get_lwp (ptid));
  833.   else
  834.     xsnprintf (buf, sizeof (buf), "process %d    ", ptid_get_pid (ptid));

  835.   return buf;
  836. }


  837. /* Worker bee for update_thread_list.  Callback function that gets
  838.    called once per user-level thread (i.e. not for LWP's).  */

  839. static int
  840. sol_update_thread_list_callback (const td_thrhandle_t *th, void *ignored)
  841. {
  842.   td_err_e retval;
  843.   td_thrinfo_t ti;
  844.   ptid_t ptid;

  845.   retval = p_td_thr_get_info (th, &ti);
  846.   if (retval != TD_OK)
  847.     return -1;

  848.   ptid = ptid_build (ptid_get_pid (inferior_ptid), 0, ti.ti_tid);
  849.   if (!in_thread_list (ptid) || is_exited (ptid))
  850.     add_thread (ptid);

  851.   return 0;
  852. }

  853. static void
  854. sol_update_thread_list (struct target_ops *ops)
  855. {
  856.   struct target_ops *beneath = find_target_beneath (ops);

  857.   /* Delete dead threads.  */
  858.   prune_threads ();

  859.   /* Find any new LWP's.  */
  860.   beneath->to_update_thread_list (beneath);

  861.   /* Then find any new user-level threads.  */
  862.   p_td_ta_thr_iter (main_ta, sol_update_thread_list_callback, (void *) 0,
  863.                     TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY,
  864.                     TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS);
  865. }

  866. /* Worker bee for the "info sol-thread" command.  This is a callback
  867.    function that gets called once for each Solaris user-level thread
  868.    (i.e. not for LWPs) in the inferior.  Print anything interesting
  869.    that we can think of.  */

  870. static int
  871. info_cb (const td_thrhandle_t *th, void *s)
  872. {
  873.   td_err_e ret;
  874.   td_thrinfo_t ti;

  875.   ret = p_td_thr_get_info (th, &ti);
  876.   if (ret == TD_OK)
  877.     {
  878.       printf_filtered ("%s thread #%d, lwp %d, ",
  879.                        ti.ti_type == TD_THR_SYSTEM ? "system" : "user  ",
  880.                        ti.ti_tid, ti.ti_lid);
  881.       switch (ti.ti_state)
  882.         {
  883.         default:
  884.         case TD_THR_UNKNOWN:
  885.           printf_filtered ("<unknown state>");
  886.           break;
  887.         case TD_THR_STOPPED:
  888.           printf_filtered ("(stopped)");
  889.           break;
  890.         case TD_THR_RUN:
  891.           printf_filtered ("(run)    ");
  892.           break;
  893.         case TD_THR_ACTIVE:
  894.           printf_filtered ("(active) ");
  895.           break;
  896.         case TD_THR_ZOMBIE:
  897.           printf_filtered ("(zombie) ");
  898.           break;
  899.         case TD_THR_SLEEP:
  900.           printf_filtered ("(asleep) ");
  901.           break;
  902.         case TD_THR_STOPPED_ASLEEP:
  903.           printf_filtered ("(stopped asleep)");
  904.           break;
  905.         }
  906.       /* Print thr_create start function.  */
  907.       if (ti.ti_startfunc != 0)
  908.         {
  909.           const struct bound_minimal_symbol msym
  910.             = lookup_minimal_symbol_by_pc (ti.ti_startfunc);

  911.           printf_filtered ("   startfunc=%s",
  912.                            msym.minsym
  913.                            ? MSYMBOL_PRINT_NAME (msym.minsym)
  914.                            : paddress (target_gdbarch (), ti.ti_startfunc));
  915.         }

  916.       /* If thread is asleep, print function that went to sleep.  */
  917.       if (ti.ti_state == TD_THR_SLEEP)
  918.         {
  919.           const struct bound_minimal_symbol msym
  920.             = lookup_minimal_symbol_by_pc (ti.ti_pc);

  921.           printf_filtered ("   sleepfunc=%s",
  922.                            msym.minsym
  923.                            ? MSYMBOL_PRINT_NAME (msym.minsym)
  924.                            : paddress (target_gdbarch (), ti.ti_pc));
  925.         }

  926.       printf_filtered ("\n");
  927.     }
  928.   else
  929.     warning (_("info sol-thread: failed to get info for thread."));

  930.   return 0;
  931. }

  932. /* List some state about each Solaris user-level thread in the
  933.    inferior.  */

  934. static void
  935. info_solthreads (char *args, int from_tty)
  936. {
  937.   p_td_ta_thr_iter (main_ta, info_cb, args,
  938.                     TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY,
  939.                     TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS);
  940. }

  941. /* Callback routine used to find a thread based on the TID part of
  942.    its PTID.  */

  943. static int
  944. thread_db_find_thread_from_tid (struct thread_info *thread, void *data)
  945. {
  946.   long *tid = (long *) data;

  947.   if (ptid_get_tid (thread->ptid) == *tid)
  948.     return 1;

  949.   return 0;
  950. }

  951. static ptid_t
  952. sol_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
  953. {
  954.   struct thread_info *thread_info =
  955.     iterate_over_threads (thread_db_find_thread_from_tid, &thread);

  956.   if (thread_info == NULL)
  957.     {
  958.       /* The list of threads is probably not up to date.  Find any
  959.          thread that is missing from the list, and try again.  */
  960.       sol_update_thread_list (&current_target);
  961.       thread_info = iterate_over_threads (thread_db_find_thread_from_tid,
  962.                                           &thread);
  963.     }

  964.   gdb_assert (thread_info != NULL);

  965.   return (thread_info->ptid);
  966. }

  967. static void
  968. init_sol_thread_ops (void)
  969. {
  970.   sol_thread_ops.to_shortname = "solaris-threads";
  971.   sol_thread_ops.to_longname = "Solaris threads and pthread.";
  972.   sol_thread_ops.to_doc = "Solaris threads and pthread support.";
  973.   sol_thread_ops.to_detach = sol_thread_detach;
  974.   sol_thread_ops.to_resume = sol_thread_resume;
  975.   sol_thread_ops.to_wait = sol_thread_wait;
  976.   sol_thread_ops.to_fetch_registers = sol_thread_fetch_registers;
  977.   sol_thread_ops.to_store_registers = sol_thread_store_registers;
  978.   sol_thread_ops.to_xfer_partial = sol_thread_xfer_partial;
  979.   sol_thread_ops.to_mourn_inferior = sol_thread_mourn_inferior;
  980.   sol_thread_ops.to_thread_alive = sol_thread_alive;
  981.   sol_thread_ops.to_pid_to_str = solaris_pid_to_str;
  982.   sol_thread_ops.to_update_thread_list = sol_update_thread_list;
  983.   sol_thread_ops.to_stratum = thread_stratum;
  984.   sol_thread_ops.to_get_ada_task_ptid = sol_get_ada_task_ptid;
  985.   sol_thread_ops.to_magic = OPS_MAGIC;
  986. }

  987. /* Silence -Wmissing-prototypes.  */
  988. extern void _initialize_sol_thread (void);

  989. void
  990. _initialize_sol_thread (void)
  991. {
  992.   void *dlhandle;

  993.   init_sol_thread_ops ();

  994.   dlhandle = dlopen ("libthread_db.so.1", RTLD_NOW);
  995.   if (!dlhandle)
  996.     goto die;

  997. #define resolve(X) \
  998.   if (!(p_##X = dlsym (dlhandle, #X))) \
  999.     goto die;

  1000.   resolve (td_log);
  1001.   resolve (td_ta_new);
  1002.   resolve (td_ta_delete);
  1003.   resolve (td_init);
  1004.   resolve (td_ta_get_ph);
  1005.   resolve (td_ta_get_nthreads);
  1006.   resolve (td_ta_tsd_iter);
  1007.   resolve (td_ta_thr_iter);
  1008.   resolve (td_thr_validate);
  1009.   resolve (td_thr_tsd);
  1010.   resolve (td_thr_get_info);
  1011.   resolve (td_thr_getfpregs);
  1012.   resolve (td_thr_getxregsize);
  1013.   resolve (td_thr_getxregs);
  1014.   resolve (td_thr_sigsetmask);
  1015.   resolve (td_thr_setprio);
  1016.   resolve (td_thr_setsigpending);
  1017.   resolve (td_thr_setfpregs);
  1018.   resolve (td_thr_setxregs);
  1019.   resolve (td_ta_map_id2thr);
  1020.   resolve (td_ta_map_lwp2thr);
  1021.   resolve (td_thr_getgregs);
  1022.   resolve (td_thr_setgregs);

  1023.   complete_target_initialization (&sol_thread_ops);

  1024.   add_cmd ("sol-threads", class_maintenance, info_solthreads,
  1025.            _("Show info on Solaris user threads."), &maintenanceinfolist);

  1026.   /* Hook into new_objfile notification.  */
  1027.   observer_attach_new_objfile (sol_thread_new_objfile);
  1028.   return;

  1029. die:
  1030.   fprintf_unfiltered (gdb_stderr, "\
  1031. [GDB will not be able to debug user-mode threads: %s]\n", dlerror ());

  1032.   if (dlhandle)
  1033.     dlclose (dlhandle);

  1034.   return;
  1035. }