gdb/alpha-linux-tdep.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Target-dependent code for GNU/Linux on Alpha.
  2.    Copyright (C) 2002-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 "frame.h"
  16. #include "osabi.h"
  17. #include "solib-svr4.h"
  18. #include "symtab.h"
  19. #include "regset.h"
  20. #include "regcache.h"
  21. #include "linux-tdep.h"
  22. #include "alpha-tdep.h"

  23. /* This enum represents the signals' numbers on the Alpha
  24.    architecture.  It just contains the signal definitions which are
  25.    different from the generic implementation.

  26.    It is derived from the file <arch/alpha/include/uapi/asm/signal.h>,
  27.    from the Linux kernel tree.  */

  28. enum
  29.   {
  30.     /* SIGABRT is the same as in the generic implementation, but is
  31.        defined here because SIGIOT depends on it.  */
  32.     ALPHA_LINUX_SIGABRT = 6,
  33.     ALPHA_LINUX_SIGEMT = 7,
  34.     ALPHA_LINUX_SIGBUS = 10,
  35.     ALPHA_LINUX_SIGSYS = 12,
  36.     ALPHA_LINUX_SIGURG = 16,
  37.     ALPHA_LINUX_SIGSTOP = 17,
  38.     ALPHA_LINUX_SIGTSTP = 18,
  39.     ALPHA_LINUX_SIGCONT = 19,
  40.     ALPHA_LINUX_SIGCHLD = 20,
  41.     ALPHA_LINUX_SIGIO = 23,
  42.     ALPHA_LINUX_SIGINFO = 29,
  43.     ALPHA_LINUX_SIGUSR1 = 30,
  44.     ALPHA_LINUX_SIGUSR2 = 31,
  45.     ALPHA_LINUX_SIGPOLL = ALPHA_LINUX_SIGIO,
  46.     ALPHA_LINUX_SIGPWR = ALPHA_LINUX_SIGINFO,
  47.     ALPHA_LINUX_SIGIOT = ALPHA_LINUX_SIGABRT,
  48.   };

  49. /* Under GNU/Linux, signal handler invocations can be identified by
  50.    the designated code sequence that is used to return from a signal
  51.    handler.  In particular, the return address of a signal handler
  52.    points to a sequence that copies $sp to $16, loads $0 with the
  53.    appropriate syscall number, and finally enters the kernel.

  54.    This is somewhat complicated in that:
  55.      (1) the expansion of the "mov" assembler macro has changed over
  56.          time, from "bis src,src,dst" to "bis zero,src,dst",
  57.      (2) the kernel has changed from using "addq" to "lda" to load the
  58.          syscall number,
  59.      (3) there is a "normal" sigreturn and an "rt" sigreturn which
  60.          has a different stack layout.  */

  61. static long
  62. alpha_linux_sigtramp_offset_1 (struct gdbarch *gdbarch, CORE_ADDR pc)
  63. {
  64.   switch (alpha_read_insn (gdbarch, pc))
  65.     {
  66.     case 0x47de0410:                /* bis $30,$30,$16 */
  67.     case 0x47fe0410:                /* bis $31,$30,$16 */
  68.       return 0;

  69.     case 0x43ecf400:                /* addq $31,103,$0 */
  70.     case 0x201f0067:                /* lda $0,103($31) */
  71.     case 0x201f015f:                /* lda $0,351($31) */
  72.       return 4;

  73.     case 0x00000083:                /* call_pal callsys */
  74.       return 8;

  75.     default:
  76.       return -1;
  77.     }
  78. }

  79. static LONGEST
  80. alpha_linux_sigtramp_offset (struct gdbarch *gdbarch, CORE_ADDR pc)
  81. {
  82.   long i, off;

  83.   if (pc & 3)
  84.     return -1;

  85.   /* Guess where we might be in the sequence.  */
  86.   off = alpha_linux_sigtramp_offset_1 (gdbarch, pc);
  87.   if (off < 0)
  88.     return -1;

  89.   /* Verify that the other two insns of the sequence are as we expect.  */
  90.   pc -= off;
  91.   for (i = 0; i < 12; i += 4)
  92.     {
  93.       if (i == off)
  94.         continue;
  95.       if (alpha_linux_sigtramp_offset_1 (gdbarch, pc + i) != i)
  96.         return -1;
  97.     }

  98.   return off;
  99. }

  100. static int
  101. alpha_linux_pc_in_sigtramp (struct gdbarch *gdbarch,
  102.                             CORE_ADDR pc, const char *func_name)
  103. {
  104.   return alpha_linux_sigtramp_offset (gdbarch, pc) >= 0;
  105. }

  106. static CORE_ADDR
  107. alpha_linux_sigcontext_addr (struct frame_info *this_frame)
  108. {
  109.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  110.   CORE_ADDR pc;
  111.   ULONGEST sp;
  112.   long off;

  113.   pc = get_frame_pc (this_frame);
  114.   sp = get_frame_register_unsigned (this_frame, ALPHA_SP_REGNUM);

  115.   off = alpha_linux_sigtramp_offset (gdbarch, pc);
  116.   gdb_assert (off >= 0);

  117.   /* __NR_rt_sigreturn has a couple of structures on the stack.  This is:

  118.         struct rt_sigframe {
  119.           struct siginfo info;
  120.           struct ucontext uc;
  121.         };

  122.         offsetof (struct rt_sigframe, uc.uc_mcontext);  */

  123.   if (alpha_read_insn (gdbarch, pc - off + 4) == 0x201f015f)
  124.     return sp + 176;

  125.   /* __NR_sigreturn has the sigcontext structure at the top of the stack.  */
  126.   return sp;
  127. }

  128. /* Supply register REGNUM from the buffer specified by GREGS and LEN
  129.    in the general-purpose register set REGSET to register cache
  130.    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */

  131. static void
  132. alpha_linux_supply_gregset (const struct regset *regset,
  133.                             struct regcache *regcache,
  134.                             int regnum, const void *gregs, size_t len)
  135. {
  136.   const gdb_byte *regs = gregs;

  137.   gdb_assert (len >= 32 * 8);
  138.   alpha_supply_int_regs (regcache, regnum, regs, regs + 31 * 8,
  139.                          len >= 33 * 8 ? regs + 32 * 8 : NULL);
  140. }

  141. /* Collect register REGNUM from the register cache REGCACHE and store
  142.    it in the buffer specified by GREGS and LEN as described by the
  143.    general-purpose register set REGSET.  If REGNUM is -1, do this for
  144.    all registers in REGSET.  */

  145. static void
  146. alpha_linux_collect_gregset (const struct regset *regset,
  147.                              const struct regcache *regcache,
  148.                              int regnum, void *gregs, size_t len)
  149. {
  150.   gdb_byte *regs = gregs;

  151.   gdb_assert (len >= 32 * 8);
  152.   alpha_fill_int_regs (regcache, regnum, regs, regs + 31 * 8,
  153.                        len >= 33 * 8 ? regs + 32 * 8 : NULL);
  154. }

  155. /* Supply register REGNUM from the buffer specified by FPREGS and LEN
  156.    in the floating-point register set REGSET to register cache
  157.    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */

  158. static void
  159. alpha_linux_supply_fpregset (const struct regset *regset,
  160.                              struct regcache *regcache,
  161.                              int regnum, const void *fpregs, size_t len)
  162. {
  163.   const gdb_byte *regs = fpregs;

  164.   gdb_assert (len >= 32 * 8);
  165.   alpha_supply_fp_regs (regcache, regnum, regs, regs + 31 * 8);
  166. }

  167. /* Collect register REGNUM from the register cache REGCACHE and store
  168.    it in the buffer specified by FPREGS and LEN as described by the
  169.    general-purpose register set REGSET.  If REGNUM is -1, do this for
  170.    all registers in REGSET.  */

  171. static void
  172. alpha_linux_collect_fpregset (const struct regset *regset,
  173.                               const struct regcache *regcache,
  174.                               int regnum, void *fpregs, size_t len)
  175. {
  176.   gdb_byte *regs = fpregs;

  177.   gdb_assert (len >= 32 * 8);
  178.   alpha_fill_fp_regs (regcache, regnum, regs, regs + 31 * 8);
  179. }

  180. static const struct regset alpha_linux_gregset =
  181. {
  182.   NULL,
  183.   alpha_linux_supply_gregset, alpha_linux_collect_gregset
  184. };

  185. static const struct regset alpha_linux_fpregset =
  186. {
  187.   NULL,
  188.   alpha_linux_supply_fpregset, alpha_linux_collect_fpregset
  189. };

  190. /* Iterate over core file register note sections.  */

  191. static void
  192. alpha_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
  193.                                           iterate_over_regset_sections_cb *cb,
  194.                                           void *cb_data,
  195.                                           const struct regcache *regcache)
  196. {
  197.   cb (".reg", 32 * 8, &alpha_linux_gregset, NULL, cb_data);
  198.   cb (".reg2", 32 * 8, &alpha_linux_fpregset, NULL, cb_data);
  199. }

  200. /* Implementation of `gdbarch_gdb_signal_from_target', as defined in
  201.    gdbarch.h.  */

  202. static enum gdb_signal
  203. alpha_linux_gdb_signal_from_target (struct gdbarch *gdbarch,
  204.                                     int signal)
  205. {
  206.   switch (signal)
  207.     {
  208.     case ALPHA_LINUX_SIGEMT:
  209.       return GDB_SIGNAL_EMT;

  210.     case ALPHA_LINUX_SIGBUS:
  211.       return GDB_SIGNAL_BUS;

  212.     case ALPHA_LINUX_SIGSYS:
  213.       return GDB_SIGNAL_SYS;

  214.     case ALPHA_LINUX_SIGURG:
  215.       return GDB_SIGNAL_URG;

  216.     case ALPHA_LINUX_SIGSTOP:
  217.       return GDB_SIGNAL_STOP;

  218.     case ALPHA_LINUX_SIGTSTP:
  219.       return GDB_SIGNAL_TSTP;

  220.     case ALPHA_LINUX_SIGCONT:
  221.       return GDB_SIGNAL_CONT;

  222.     case ALPHA_LINUX_SIGCHLD:
  223.       return GDB_SIGNAL_CHLD;

  224.     /* No way to differentiate between SIGIO and SIGPOLL.
  225.        Therefore, we just handle the first one.  */
  226.     case ALPHA_LINUX_SIGIO:
  227.       return GDB_SIGNAL_IO;

  228.     /* No way to differentiate between SIGINFO and SIGPWR.
  229.        Therefore, we just handle the first one.  */
  230.     case ALPHA_LINUX_SIGINFO:
  231.       return GDB_SIGNAL_INFO;

  232.     case ALPHA_LINUX_SIGUSR1:
  233.       return GDB_SIGNAL_USR1;

  234.     case ALPHA_LINUX_SIGUSR2:
  235.       return GDB_SIGNAL_USR2;
  236.     }

  237.   return linux_gdb_signal_from_target (gdbarch, signal);
  238. }

  239. /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
  240.    gdbarch.h.  */

  241. static int
  242. alpha_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
  243.                                   enum gdb_signal signal)
  244. {
  245.   switch (signal)
  246.     {
  247.     case GDB_SIGNAL_EMT:
  248.       return ALPHA_LINUX_SIGEMT;

  249.     case GDB_SIGNAL_BUS:
  250.       return ALPHA_LINUX_SIGBUS;

  251.     case GDB_SIGNAL_SYS:
  252.       return ALPHA_LINUX_SIGSYS;

  253.     case GDB_SIGNAL_URG:
  254.       return ALPHA_LINUX_SIGURG;

  255.     case GDB_SIGNAL_STOP:
  256.       return ALPHA_LINUX_SIGSTOP;

  257.     case GDB_SIGNAL_TSTP:
  258.       return ALPHA_LINUX_SIGTSTP;

  259.     case GDB_SIGNAL_CONT:
  260.       return ALPHA_LINUX_SIGCONT;

  261.     case GDB_SIGNAL_CHLD:
  262.       return ALPHA_LINUX_SIGCHLD;

  263.     case GDB_SIGNAL_IO:
  264.       return ALPHA_LINUX_SIGIO;

  265.     case GDB_SIGNAL_INFO:
  266.       return ALPHA_LINUX_SIGINFO;

  267.     case GDB_SIGNAL_USR1:
  268.       return ALPHA_LINUX_SIGUSR1;

  269.     case GDB_SIGNAL_USR2:
  270.       return ALPHA_LINUX_SIGUSR2;

  271.     case GDB_SIGNAL_POLL:
  272.       return ALPHA_LINUX_SIGPOLL;

  273.     case GDB_SIGNAL_PWR:
  274.       return ALPHA_LINUX_SIGPWR;
  275.     }

  276.   return linux_gdb_signal_to_target (gdbarch, signal);
  277. }

  278. static void
  279. alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  280. {
  281.   struct gdbarch_tdep *tdep;

  282.   linux_init_abi (info, gdbarch);

  283.   /* Hook into the DWARF CFI frame unwinder.  */
  284.   alpha_dwarf2_init_abi (info, gdbarch);

  285.   /* Hook into the MDEBUG frame unwinder.  */
  286.   alpha_mdebug_init_abi (info, gdbarch);

  287.   tdep = gdbarch_tdep (gdbarch);
  288.   tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
  289.   tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
  290.   tdep->pc_in_sigtramp = alpha_linux_pc_in_sigtramp;
  291.   tdep->jb_pc = 2;
  292.   tdep->jb_elt_size = 8;

  293.   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);

  294.   set_solib_svr4_fetch_link_map_offsets
  295.     (gdbarch, svr4_lp64_fetch_link_map_offsets);

  296.   /* Enable TLS support.  */
  297.   set_gdbarch_fetch_tls_load_module_address (gdbarch,
  298.                                              svr4_fetch_objfile_link_map);

  299.   set_gdbarch_iterate_over_regset_sections
  300.     (gdbarch, alpha_linux_iterate_over_regset_sections);

  301.   set_gdbarch_gdb_signal_from_target (gdbarch,
  302.                                       alpha_linux_gdb_signal_from_target);
  303.   set_gdbarch_gdb_signal_to_target (gdbarch,
  304.                                     alpha_linux_gdb_signal_to_target);
  305. }

  306. /* Provide a prototype to silence -Wmissing-prototypes.  */
  307. extern initialize_file_ftype _initialize_alpha_linux_tdep;

  308. void
  309. _initialize_alpha_linux_tdep (void)
  310. {
  311.   gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_LINUX,
  312.                           alpha_linux_init_abi);
  313. }