0004-xtensa-implement-NPTL-helpers.patch 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. From d4eb69fc4b50f9a0babd70b28d0601b40f31bd0f Mon Sep 17 00:00:00 2001
  2. From: Max Filippov <jcmvbkbc@gmail.com>
  3. Date: Thu, 2 Jul 2015 15:10:58 +0300
  4. Subject: [PATCH] xtensa: implement NPTL helpers
  5. These changes allow debugging multithreaded NPTL xtensa applications.
  6. 2015-08-20 Max Filippov <jcmvbkbc@gmail.com>
  7. gdb/gdbserver/
  8. * configure.srv (xtensa*-*-linux*): Add srv_linux_thread_db=yes.
  9. * linux-xtensa-low.c (arch/xtensa.h gdb_proc_service.h): New
  10. #includes.
  11. (ps_get_thread_area): New function.
  12. 2015-08-20 Max Filippov <jcmvbkbc@gmail.com>
  13. gdb/
  14. * arch/xtensa.h: New file.
  15. * xtensa-linux-nat.c (gdb_proc_service.h): New #include.
  16. (ps_get_thread_area): New function.
  17. * xtensa-linux-tdep.c (xtensa_linux_init_abi): Add call to
  18. set_gdbarch_fetch_tls_load_module_address to enable TLS support.
  19. * xtensa-tdep.c (osabi.h): New #include.
  20. (xtensa_gdbarch_init): Call gdbarch_init_osabi to register
  21. xtensa-specific hooks.
  22. * xtensa-tdep.h (struct xtensa_elf_gregset_t): Add threadptr
  23. member and move the structure to arch/xtensa.h.
  24. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
  25. ---
  26. Backported from: 40045d91812b25c88c8275b8c08d27c234b68ba8
  27. Changes to ChangeLog files are dropped.
  28. gdb/arch/xtensa.h | 46 ++++++++++++++++++++++++++++++++++++++++
  29. gdb/gdbserver/configure.srv | 1 +
  30. gdb/gdbserver/linux-xtensa-low.c | 21 ++++++++++++++++++
  31. gdb/xtensa-linux-nat.c | 22 ++++++++++++++++++
  32. gdb/xtensa-linux-tdep.c | 4 ++++
  33. gdb/xtensa-tdep.c | 4 ++++
  34. gdb/xtensa-tdep.h | 24 ++------------------
  35. 7 files changed, 100 insertions(+), 22 deletions(-)
  36. create mode 100644 gdb/arch/xtensa.h
  37. diff --git a/gdb/arch/xtensa.h b/gdb/arch/xtensa.h
  38. new file mode 100644
  39. index 0000000..fe96584
  40. --- /dev/null
  41. +++ b/gdb/arch/xtensa.h
  42. @@ -0,0 +1,46 @@
  43. +/* Common Target-dependent code for the Xtensa port of GDB, the GNU debugger.
  44. +
  45. + Copyright (C) 2003-2015 Free Software Foundation, Inc.
  46. +
  47. + This file is part of GDB.
  48. +
  49. + This program is free software; you can redistribute it and/or modify
  50. + it under the terms of the GNU General Public License as published by
  51. + the Free Software Foundation; either version 3 of the License, or
  52. + (at your option) any later version.
  53. +
  54. + This program is distributed in the hope that it will be useful,
  55. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  56. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  57. + GNU General Public License for more details.
  58. +
  59. + You should have received a copy of the GNU General Public License
  60. + along with this program. If not, see <http://www.gnu.org/licenses/>. */
  61. +
  62. +#ifndef XTENSA_H
  63. +#define XTENSA_H
  64. +
  65. +/* Xtensa ELF core file register set representation ('.reg' section).
  66. + Copied from target-side ELF header <xtensa/elf.h>. */
  67. +
  68. +typedef uint32_t xtensa_elf_greg_t;
  69. +
  70. +typedef struct
  71. +{
  72. + xtensa_elf_greg_t pc;
  73. + xtensa_elf_greg_t ps;
  74. + xtensa_elf_greg_t lbeg;
  75. + xtensa_elf_greg_t lend;
  76. + xtensa_elf_greg_t lcount;
  77. + xtensa_elf_greg_t sar;
  78. + xtensa_elf_greg_t windowstart;
  79. + xtensa_elf_greg_t windowbase;
  80. + xtensa_elf_greg_t threadptr;
  81. + xtensa_elf_greg_t reserved[7+48];
  82. + xtensa_elf_greg_t ar[64];
  83. +} xtensa_elf_gregset_t;
  84. +
  85. +#define XTENSA_ELF_NGREG (sizeof (xtensa_elf_gregset_t) \
  86. + / sizeof (xtensa_elf_greg_t))
  87. +
  88. +#endif
  89. diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
  90. index 0b18d1d..320c26a 100644
  91. --- a/gdb/gdbserver/configure.srv
  92. +++ b/gdb/gdbserver/configure.srv
  93. @@ -352,6 +352,7 @@ case "${target}" in
  94. xtensa*-*-linux*) srv_regobj=reg-xtensa.o
  95. srv_tgtobj="$srv_linux_obj linux-xtensa-low.o"
  96. srv_linux_regsets=yes
  97. + srv_linux_thread_db=yes
  98. ;;
  99. tilegx-*-linux*) srv_regobj=reg-tilegx.o
  100. srv_regobj="${srv_regobj} reg-tilegx32.o"
  101. diff --git a/gdb/gdbserver/linux-xtensa-low.c b/gdb/gdbserver/linux-xtensa-low.c
  102. index 4daccee..debe467 100644
  103. --- a/gdb/gdbserver/linux-xtensa-low.c
  104. +++ b/gdb/gdbserver/linux-xtensa-low.c
  105. @@ -26,6 +26,8 @@ extern const struct target_desc *tdesc_xtensa;
  106. #include <asm/ptrace.h>
  107. #include <xtensa-config.h>
  108. +#include "arch/xtensa.h"
  109. +#include "gdb_proc_service.h"
  110. #include "xtensa-xtregs.c"
  111. @@ -179,6 +181,25 @@ xtensa_breakpoint_at (CORE_ADDR where)
  112. xtensa_breakpoint, xtensa_breakpoint_len) == 0;
  113. }
  114. +/* Called by libthread_db. */
  115. +
  116. +ps_err_e
  117. +ps_get_thread_area (const struct ps_prochandle *ph,
  118. + lwpid_t lwpid, int idx, void **base)
  119. +{
  120. + xtensa_elf_gregset_t regs;
  121. +
  122. + if (ptrace (PTRACE_GETREGS, lwpid, NULL, &regs) != 0)
  123. + return PS_ERR;
  124. +
  125. + /* IDX is the bias from the thread pointer to the beginning of the
  126. + thread descriptor. It has to be subtracted due to implementation
  127. + quirks in libthread_db. */
  128. + *base = (void *) ((char *) regs.threadptr - idx);
  129. +
  130. + return PS_OK;
  131. +}
  132. +
  133. static struct regsets_info xtensa_regsets_info =
  134. {
  135. xtensa_regsets, /* regsets */
  136. diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c
  137. index 77ad3e0..5538d5b 100644
  138. --- a/gdb/xtensa-linux-nat.c
  139. +++ b/gdb/xtensa-linux-nat.c
  140. @@ -37,6 +37,9 @@
  141. #include "gregset.h"
  142. #include "xtensa-tdep.h"
  143. +/* Defines ps_err_e, struct ps_prochandle. */
  144. +#include "gdb_proc_service.h"
  145. +
  146. /* Extended register set depends on hardware configs.
  147. Keeping these definitions separately allows to introduce
  148. hardware-specific overlays. */
  149. @@ -280,6 +283,25 @@ xtensa_linux_store_inferior_registers (struct target_ops *ops,
  150. store_xtregs (regcache, regnum);
  151. }
  152. +/* Called by libthread_db. */
  153. +
  154. +ps_err_e
  155. +ps_get_thread_area (const struct ps_prochandle *ph,
  156. + lwpid_t lwpid, int idx, void **base)
  157. +{
  158. + xtensa_elf_gregset_t regs;
  159. +
  160. + if (ptrace (PTRACE_GETREGS, lwpid, NULL, &regs) != 0)
  161. + return PS_ERR;
  162. +
  163. + /* IDX is the bias from the thread pointer to the beginning of the
  164. + thread descriptor. It has to be subtracted due to implementation
  165. + quirks in libthread_db. */
  166. + *base = (void *) ((char *) regs.threadptr - idx);
  167. +
  168. + return PS_OK;
  169. +}
  170. +
  171. void _initialize_xtensa_linux_nat (void);
  172. void
  173. diff --git a/gdb/xtensa-linux-tdep.c b/gdb/xtensa-linux-tdep.c
  174. index 61ea9b0..99e0d3e 100644
  175. --- a/gdb/xtensa-linux-tdep.c
  176. +++ b/gdb/xtensa-linux-tdep.c
  177. @@ -106,6 +106,10 @@ xtensa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  178. xtensa_linux_gdb_signal_from_target);
  179. set_gdbarch_gdb_signal_to_target (gdbarch,
  180. xtensa_linux_gdb_signal_to_target);
  181. +
  182. + /* Enable TLS support. */
  183. + set_gdbarch_fetch_tls_load_module_address (gdbarch,
  184. + svr4_fetch_objfile_link_map);
  185. }
  186. /* Provide a prototype to silence -Wmissing-prototypes. */
  187. diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
  188. index 55e7d98..4b693ed 100644
  189. --- a/gdb/xtensa-tdep.c
  190. +++ b/gdb/xtensa-tdep.c
  191. @@ -28,6 +28,7 @@
  192. #include "value.h"
  193. #include "dis-asm.h"
  194. #include "inferior.h"
  195. +#include "osabi.h"
  196. #include "floatformat.h"
  197. #include "regcache.h"
  198. #include "reggroups.h"
  199. @@ -3273,6 +3274,9 @@ xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  200. set_solib_svr4_fetch_link_map_offsets
  201. (gdbarch, svr4_ilp32_fetch_link_map_offsets);
  202. + /* Hook in the ABI-specific overrides, if they have been registered. */
  203. + gdbarch_init_osabi (info, gdbarch);
  204. +
  205. return gdbarch;
  206. }
  207. diff --git a/gdb/xtensa-tdep.h b/gdb/xtensa-tdep.h
  208. index caa2988..5b28cab 100644
  209. --- a/gdb/xtensa-tdep.h
  210. +++ b/gdb/xtensa-tdep.h
  211. @@ -18,6 +18,8 @@
  212. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  213. +#include "arch/xtensa.h"
  214. +
  215. /* XTENSA_TDEP_VERSION can/should be changed along with XTENSA_CONFIG_VERSION
  216. whenever the "tdep" structure changes in an incompatible way. */
  217. @@ -81,28 +83,6 @@ typedef enum
  218. } xtensa_target_flags_t;
  219. -/* Xtensa ELF core file register set representation ('.reg' section).
  220. - Copied from target-side ELF header <xtensa/elf.h>. */
  221. -
  222. -typedef uint32_t xtensa_elf_greg_t;
  223. -
  224. -typedef struct
  225. -{
  226. - xtensa_elf_greg_t pc;
  227. - xtensa_elf_greg_t ps;
  228. - xtensa_elf_greg_t lbeg;
  229. - xtensa_elf_greg_t lend;
  230. - xtensa_elf_greg_t lcount;
  231. - xtensa_elf_greg_t sar;
  232. - xtensa_elf_greg_t windowstart;
  233. - xtensa_elf_greg_t windowbase;
  234. - xtensa_elf_greg_t reserved[8+48];
  235. - xtensa_elf_greg_t ar[64];
  236. -} xtensa_elf_gregset_t;
  237. -
  238. -#define XTENSA_ELF_NGREG (sizeof (xtensa_elf_gregset_t) \
  239. - / sizeof (xtensa_elf_greg_t))
  240. -
  241. /* Mask. */
  242. typedef struct
  243. --
  244. 1.8.1.4