td_thr_getgregs.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Get a thread's general register set.
  2. Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "thread_dbP.h"
  17. td_err_e
  18. td_thr_getgregs (const td_thrhandle_t *th, prgregset_t gregs)
  19. {
  20. struct _pthread_descr_struct pds;
  21. LOG ("td_thr_getgregs");
  22. if (th->th_unique == NULL)
  23. {
  24. /* No data yet. Use the main thread. */
  25. pid_t pid = ps_getpid (th->th_ta_p->ph);
  26. if (ps_lgetregs (th->th_ta_p->ph, pid, gregs) != PS_OK)
  27. return TD_ERR;
  28. return TD_OK;
  29. }
  30. /* We have to get the state and the PID for this thread. */
  31. if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds,
  32. sizeof (struct _pthread_descr_struct)) != PS_OK)
  33. return TD_ERR;
  34. /* If the thread already terminated we return all zeroes. */
  35. if (pds.p_terminated)
  36. memset (gregs, '\0', sizeof (prgregset_t));
  37. /* Otherwise get the register content through the callback. */
  38. else
  39. {
  40. pid_t pid = pds.p_pid ?: ps_getpid (th->th_ta_p->ph);
  41. if (ps_lgetregs (th->th_ta_p->ph, pid, gregs) != PS_OK)
  42. return TD_ERR;
  43. }
  44. return TD_OK;
  45. }