gdb/ia64-linux-tdep.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* Target-dependent code for the IA-64 for GDB, the GNU debugger.

  2.    Copyright (C) 2000-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. #include "defs.h"
  15. #include "ia64-tdep.h"
  16. #include "arch-utils.h"
  17. #include "gdbcore.h"
  18. #include "regcache.h"
  19. #include "osabi.h"
  20. #include "solib-svr4.h"
  21. #include "symtab.h"
  22. #include "linux-tdep.h"
  23. #include "regset.h"

  24. #include <ctype.h>

  25. /* The sigtramp code is in a non-readable (executable-only) region
  26.    of memory called the ``gate page''.  The addresses in question
  27.    were determined by examining the system headers.  They are
  28.    overly generous to allow for different pages sizes.  */

  29. #define GATE_AREA_START 0xa000000000000100LL
  30. #define GATE_AREA_END   0xa000000000020000LL

  31. /* Offset to sigcontext structure from frame of handler.  */
  32. #define IA64_LINUX_SIGCONTEXT_OFFSET 192

  33. static int
  34. ia64_linux_pc_in_sigtramp (CORE_ADDR pc)
  35. {
  36.   return (pc >= (CORE_ADDR) GATE_AREA_START && pc < (CORE_ADDR) GATE_AREA_END);
  37. }

  38. /* IA-64 GNU/Linux specific function which, given a frame address and
  39.    a register number, returns the address at which that register may be
  40.    found.  0 is returned for registers which aren't stored in the
  41.    sigcontext structure.  */

  42. static CORE_ADDR
  43. ia64_linux_sigcontext_register_address (struct gdbarch *gdbarch,
  44.                                         CORE_ADDR sp, int regno)
  45. {
  46.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  47.   gdb_byte buf[8];
  48.   CORE_ADDR sigcontext_addr = 0;

  49.   /* The address of the sigcontext area is found at offset 16 in the
  50.      sigframe.  */
  51.   read_memory (sp + 16, buf, 8);
  52.   sigcontext_addr = extract_unsigned_integer (buf, 8, byte_order);

  53.   if (IA64_GR0_REGNUM <= regno && regno <= IA64_GR31_REGNUM)
  54.     return sigcontext_addr + 200 + 8 * (regno - IA64_GR0_REGNUM);
  55.   else if (IA64_BR0_REGNUM <= regno && regno <= IA64_BR7_REGNUM)
  56.     return sigcontext_addr + 136 + 8 * (regno - IA64_BR0_REGNUM);
  57.   else if (IA64_FR0_REGNUM <= regno && regno <= IA64_FR127_REGNUM)
  58.     return sigcontext_addr + 464 + 16 * (regno - IA64_FR0_REGNUM);
  59.   else
  60.     switch (regno)
  61.       {
  62.       case IA64_IP_REGNUM :
  63.         return sigcontext_addr + 40;
  64.       case IA64_CFM_REGNUM :
  65.         return sigcontext_addr + 48;
  66.       case IA64_PSR_REGNUM :
  67.         return sigcontext_addr + 56;                /* user mask only */
  68.       /* sc_ar_rsc is provided, from which we could compute bspstore, but
  69.          I don't think it's worth it.  Anyway, if we want it, it's at offset
  70.          64.  */
  71.       case IA64_BSP_REGNUM :
  72.         return sigcontext_addr + 72;
  73.       case IA64_RNAT_REGNUM :
  74.         return sigcontext_addr + 80;
  75.       case IA64_CCV_REGNUM :
  76.         return sigcontext_addr + 88;
  77.       case IA64_UNAT_REGNUM :
  78.         return sigcontext_addr + 96;
  79.       case IA64_FPSR_REGNUM :
  80.         return sigcontext_addr + 104;
  81.       case IA64_PFS_REGNUM :
  82.         return sigcontext_addr + 112;
  83.       case IA64_LC_REGNUM :
  84.         return sigcontext_addr + 120;
  85.       case IA64_PR_REGNUM :
  86.         return sigcontext_addr + 128;
  87.       default :
  88.         return 0;
  89.       }
  90. }

  91. static void
  92. ia64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
  93. {
  94.   ia64_write_pc (regcache, pc);

  95.   /* We must be careful with modifying the instruction-pointer: if we
  96.      just interrupt a system call, the kernel would ordinarily try to
  97.      restart it when we resume the inferior, which typically results
  98.      in SIGSEGV or SIGILL.  We prevent this by clearing r10, which
  99.      will tell the kernel that r8 does NOT contain a valid error code
  100.      and hence it will skip system-call restart.

  101.      The clearing of r10 is safe as long as ia64_write_pc() is only
  102.      called as part of setting up an inferior call.  */
  103.   regcache_cooked_write_unsigned (regcache, IA64_GR10_REGNUM, 0);
  104. }

  105. /* Implementation of `gdbarch_stap_is_single_operand', as defined in
  106.    gdbarch.h.  */

  107. static int
  108. ia64_linux_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
  109. {
  110.   return ((isdigit (*s) && s[1] == '[' && s[2] == 'r') /* Displacement.  */
  111.           || *s == 'r' /* Register value.  */
  112.           || isdigit (*s));  /* Literal number.  */
  113. }

  114. /* Core file support. */

  115. static const struct regcache_map_entry ia64_linux_gregmap[] =
  116.   {
  117.     { 32, IA64_GR0_REGNUM, 8 },        /* r0 ... r31 */
  118.     { 1, REGCACHE_MAP_SKIP, 8 }, /* FIXME: NAT collection bits? */
  119.     { 1, IA64_PR_REGNUM, 8 },
  120.     { 8, IA64_BR0_REGNUM, 8 },        /* b0 ... b7 */
  121.     { 1, IA64_IP_REGNUM, 8 },
  122.     { 1, IA64_CFM_REGNUM, 8 },
  123.     { 1, IA64_PSR_REGNUM, 8 },
  124.     { 1, IA64_RSC_REGNUM, 8 },
  125.     { 1, IA64_BSP_REGNUM, 8 },
  126.     { 1, IA64_BSPSTORE_REGNUM, 8 },
  127.     { 1, IA64_RNAT_REGNUM, 8 },
  128.     { 1, IA64_CCV_REGNUM, 8 },
  129.     { 1, IA64_UNAT_REGNUM, 8 },
  130.     { 1, IA64_FPSR_REGNUM, 8 },
  131.     { 1, IA64_PFS_REGNUM, 8 },
  132.     { 1, IA64_LC_REGNUM, 8 },
  133.     { 1, IA64_EC_REGNUM, 8 },
  134.     { 0 }
  135.   };

  136. /* Size of 'gregset_t', as defined by the Linux kernel.  Note that
  137.    this is more than actually mapped in the regmap above.  */

  138. #define IA64_LINUX_GREGS_SIZE (128 * 8)

  139. static const struct regcache_map_entry ia64_linux_fpregmap[] =
  140.   {
  141.     { 128, IA64_FR0_REGNUM, 16 }, /* f0 ... f127 */
  142.     { 0 }
  143.   };

  144. #define IA64_LINUX_FPREGS_SIZE (128 * 16)

  145. static void
  146. ia64_linux_supply_fpregset (const struct regset *regset,
  147.                             struct regcache *regcache,
  148.                             int regnum, const void *regs, size_t len)
  149. {
  150.   const gdb_byte f_zero[16] = { 0 };
  151.   const gdb_byte f_one[16] =
  152.     { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0xff, 0, 0, 0, 0, 0, 0 };

  153.   regcache_supply_regset (regset, regcache, regnum, regs, len);

  154.   /* Kernel generated cores have fr1==0 instead of 1.0.  Older GDBs
  155.      did the same.  So ignore whatever might be recorded in fpregset_t
  156.      for fr0/fr1 and always supply their expected values.  */
  157.   if (regnum == -1 || regnum == IA64_FR0_REGNUM)
  158.     regcache_raw_supply (regcache, IA64_FR0_REGNUM, f_zero);
  159.   if (regnum == -1 || regnum == IA64_FR1_REGNUM)
  160.     regcache_raw_supply (regcache, IA64_FR1_REGNUM, f_one);
  161. }

  162. static const struct regset ia64_linux_gregset =
  163.   {
  164.     ia64_linux_gregmap,
  165.     regcache_supply_regset, regcache_collect_regset
  166.   };

  167. static const struct regset ia64_linux_fpregset =
  168.   {
  169.     ia64_linux_fpregmap,
  170.     ia64_linux_supply_fpregset, regcache_collect_regset
  171.   };

  172. static void
  173. ia64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
  174.                                          iterate_over_regset_sections_cb *cb,
  175.                                          void *cb_data,
  176.                                          const struct regcache *regcache)
  177. {
  178.   cb (".reg", IA64_LINUX_GREGS_SIZE, &ia64_linux_gregset, NULL, cb_data);
  179.   cb (".reg2", IA64_LINUX_FPREGS_SIZE, &ia64_linux_fpregset, NULL, cb_data);
  180. }

  181. static void
  182. ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  183. {
  184.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  185.   static const char *const stap_register_prefixes[] = { "r", NULL };
  186.   static const char *const stap_register_indirection_prefixes[] = { "[",
  187.                                                                     NULL };
  188.   static const char *const stap_register_indirection_suffixes[] = { "]",
  189.                                                                     NULL };

  190.   linux_init_abi (info, gdbarch);

  191.   /* Set the method of obtaining the sigcontext addresses at which
  192.      registers are saved.  */
  193.   tdep->sigcontext_register_address = ia64_linux_sigcontext_register_address;

  194.   /* Set the pc_in_sigtramp method.  */
  195.   tdep->pc_in_sigtramp = ia64_linux_pc_in_sigtramp;

  196.   set_gdbarch_write_pc (gdbarch, ia64_linux_write_pc);

  197.   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);

  198.   set_solib_svr4_fetch_link_map_offsets
  199.     (gdbarch, svr4_lp64_fetch_link_map_offsets);

  200.   /* Enable TLS support.  */
  201.   set_gdbarch_fetch_tls_load_module_address (gdbarch,
  202.                                              svr4_fetch_objfile_link_map);

  203.   /* Core file support. */
  204.   set_gdbarch_iterate_over_regset_sections
  205.     (gdbarch, ia64_linux_iterate_over_regset_sections);

  206.   /* SystemTap related.  */
  207.   set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
  208.   set_gdbarch_stap_register_indirection_prefixes (gdbarch,
  209.                                           stap_register_indirection_prefixes);
  210.   set_gdbarch_stap_register_indirection_suffixes (gdbarch,
  211.                                             stap_register_indirection_suffixes);
  212.   set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
  213.   set_gdbarch_stap_is_single_operand (gdbarch,
  214.                                       ia64_linux_stap_is_single_operand);
  215. }

  216. /* Provide a prototype to silence -Wmissing-prototypes.  */
  217. extern initialize_file_ftype _initialize_ia64_linux_tdep;

  218. void
  219. _initialize_ia64_linux_tdep (void)
  220. {
  221.   gdbarch_register_osabi (bfd_arch_ia64, 0, GDB_OSABI_LINUX,
  222.                           ia64_linux_init_abi);
  223. }