gdb/microblaze-linux-tdep.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Target-dependent code for Xilinx MicroBlaze.

  2.    Copyright (C) 2009-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 "inferior.h"
  17. #include "symtab.h"
  18. #include "target.h"
  19. #include "gdbcore.h"
  20. #include "gdbcmd.h"
  21. #include "symfile.h"
  22. #include "objfiles.h"
  23. #include "regcache.h"
  24. #include "value.h"
  25. #include "osabi.h"
  26. #include "regset.h"
  27. #include "solib-svr4.h"
  28. #include "microblaze-tdep.h"
  29. #include "trad-frame.h"
  30. #include "frame-unwind.h"
  31. #include "tramp-frame.h"
  32. #include "linux-tdep.h"

  33. static int
  34. microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
  35.                                            struct bp_target_info *bp_tgt)
  36. {
  37.   CORE_ADDR addr = bp_tgt->reqstd_address;
  38.   const gdb_byte *bp;
  39.   int val;
  40.   int bplen;
  41.   gdb_byte old_contents[BREAKPOINT_MAX];

  42.   /* Determine appropriate breakpoint contents and size for this address.  */
  43.   bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
  44.   if (bp == NULL)
  45.     error (_("Software breakpoints not implemented for this target."));

  46.   val = target_read_memory (addr, old_contents, bplen);

  47.   /* If our breakpoint is no longer at the address, this means that the
  48.      program modified the code on us, so it is wrong to put back the
  49.      old value.  */
  50.   if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
  51.     val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);

  52.   return val;
  53. }

  54. static void
  55. microblaze_linux_sigtramp_cache (struct frame_info *next_frame,
  56.                                  struct trad_frame_cache *this_cache,
  57.                                  CORE_ADDR func, LONGEST offset,
  58.                                  int bias)
  59. {
  60.   CORE_ADDR base;
  61.   CORE_ADDR gpregs;
  62.   int regnum;
  63.   struct gdbarch *gdbarch = get_frame_arch (next_frame);
  64.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  65.   base = frame_unwind_register_unsigned (next_frame, MICROBLAZE_SP_REGNUM);
  66.   if (bias > 0 && get_frame_address_in_block (next_frame) != func)
  67.     /* See below, some signal trampolines increment the stack as their
  68.        first instruction, need to compensate for that.  */
  69.     base -= bias;

  70.   /* Find the address of the register buffer.  */
  71.   gpregs = base + offset;

  72.   /* Registers saved on stack.  */
  73.   for (regnum = 0; regnum < MICROBLAZE_BTR_REGNUM; regnum++)
  74.     trad_frame_set_reg_addr (this_cache, regnum,
  75.                              gpregs + regnum * MICROBLAZE_REGISTER_SIZE);
  76.   trad_frame_set_id (this_cache, frame_id_build (base, func));
  77. }


  78. static void
  79. microblaze_linux_sighandler_cache_init (const struct tramp_frame *self,
  80.                                         struct frame_info *next_frame,
  81.                                         struct trad_frame_cache *this_cache,
  82.                                         CORE_ADDR func)
  83. {
  84.   microblaze_linux_sigtramp_cache (next_frame, this_cache, func,
  85.                                    0 /* Offset to ucontext_t.  */
  86.                                    + 24 /* Offset to .reg.  */,
  87.                                    0);
  88. }

  89. static struct tramp_frame microblaze_linux_sighandler_tramp_frame =
  90. {
  91.   SIGTRAMP_FRAME,
  92.   4,
  93.   {
  94.     { 0x31800077, -1 }, /* addik R12,R0,119.  */
  95.     { 0xb9cc0008, -1 }, /* brki R14,8.  */
  96.     { TRAMP_SENTINEL_INSN },
  97.   },
  98.   microblaze_linux_sighandler_cache_init
  99. };


  100. static void
  101. microblaze_linux_init_abi (struct gdbarch_info info,
  102.                            struct gdbarch *gdbarch)
  103. {
  104.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  105.   linux_init_abi (info, gdbarch);

  106.   set_gdbarch_memory_remove_breakpoint (gdbarch,
  107.                                         microblaze_linux_memory_remove_breakpoint);

  108.   /* Shared library handling.  */
  109.   set_solib_svr4_fetch_link_map_offsets (gdbarch,
  110.                                          svr4_ilp32_fetch_link_map_offsets);

  111.   /* Trampolines.  */
  112.   tramp_frame_prepend_unwinder (gdbarch,
  113.                                 &microblaze_linux_sighandler_tramp_frame);
  114. }

  115. /* -Wmissing-prototypes */
  116. extern initialize_file_ftype _initialize_microblaze_linux_tdep;

  117. void
  118. _initialize_microblaze_linux_tdep (void)
  119. {
  120.   gdbarch_register_osabi (bfd_arch_microblaze, 0, GDB_OSABI_LINUX,
  121.                           microblaze_linux_init_abi);
  122. }