gdb/hppabsd-tdep.c - gdb

Functions defined

Source code

  1. /* Target-dependent code for HP PA-RISC BSD's.

  2.    Copyright (C) 2004-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 "objfiles.h"
  16. #include "target.h"
  17. #include "value.h"

  18. #include "elf/common.h"

  19. #include "hppa-tdep.h"
  20. #include "hppabsd-tdep.h"
  21. #include "dwarf2-frame.h"
  22. #include "solib-svr4.h"

  23. static CORE_ADDR
  24. hppabsd_find_global_pointer (struct gdbarch *gdbarch, struct value *function)
  25. {
  26.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  27.   CORE_ADDR faddr = value_as_address (function);
  28.   struct obj_section *faddr_sec;
  29.   gdb_byte buf[4];

  30.   /* Is this a plabel? If so, dereference it to get the Global Pointer
  31.      value.  */
  32.   if (faddr & 2)
  33.     {
  34.       if (target_read_memory ((faddr & ~3) + 4, buf, sizeof buf) == 0)
  35.         return extract_unsigned_integer (buf, sizeof buf, byte_order);
  36.     }

  37.   /* If the address is in the .plt section, then the real function
  38.      hasn't yet been fixed up by the linker so we cannot determine the
  39.      Global Pointer for that function.  */
  40.   if (in_plt_section (faddr))
  41.     return 0;

  42.   faddr_sec = find_pc_section (faddr);
  43.   if (faddr_sec != NULL)
  44.     {
  45.       struct obj_section *sec;

  46.       ALL_OBJFILE_OSECTIONS (faddr_sec->objfile, sec)
  47.         {
  48.           if (strcmp (sec->the_bfd_section->name, ".dynamic") == 0)
  49.             break;
  50.         }

  51.       if (sec < faddr_sec->objfile->sections_end)
  52.         {
  53.           CORE_ADDR addr = obj_section_addr (sec);
  54.           CORE_ADDR endaddr = obj_section_endaddr (sec);

  55.           while (addr < endaddr)
  56.             {
  57.               gdb_byte buf[4];
  58.               LONGEST tag;

  59.               if (target_read_memory (addr, buf, sizeof buf) != 0)
  60.                 break;

  61.               tag = extract_signed_integer (buf, sizeof buf, byte_order);
  62.               if (tag == DT_PLTGOT)
  63.                 {
  64.                   CORE_ADDR pltgot;

  65.                   if (target_read_memory (addr + 4, buf, sizeof buf) != 0)
  66.                     break;

  67.                   /* The NetBSD/OpenBSD ld.so doesn't relocate DT_PLTGOT, so
  68.                      we have to do it ourselves.  */
  69.                   pltgot = extract_unsigned_integer (buf, sizeof buf,
  70.                                                      byte_order);
  71.                   pltgot += ANOFFSET (sec->objfile->section_offsets,
  72.                                       SECT_OFF_TEXT (sec->objfile));

  73.                   return pltgot;
  74.                 }

  75.               if (tag == DT_NULL)
  76.                 break;

  77.               addr += 8;
  78.             }
  79.         }
  80.     }

  81.   return 0;
  82. }


  83. static void
  84. hppabsd_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
  85.                                struct dwarf2_frame_state_reg *reg,
  86.                                struct frame_info *this_frame)
  87. {
  88.   if (regnum == HPPA_PCOQ_HEAD_REGNUM)
  89.     reg->how = DWARF2_FRAME_REG_RA;
  90.   else if (regnum == HPPA_SP_REGNUM)
  91.     reg->how = DWARF2_FRAME_REG_CFA;
  92. }

  93. void
  94. hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  95. {
  96.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  97.   /* OpenBSD and NetBSD have a 64-bit 'long double'.  */
  98.   set_gdbarch_long_double_bit (gdbarch, 64);
  99.   set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);

  100.   /* OpenBSD and NetBSD use ELF.  */
  101.   tdep->is_elf = 1;
  102.   tdep->find_global_pointer = hppabsd_find_global_pointer;
  103.   tdep->in_solib_call_trampoline = hppa_in_solib_call_trampoline;
  104.   set_gdbarch_skip_trampoline_code (gdbarch, hppa_skip_trampoline_code);

  105.   /* OpenBSD and NetBSD use SVR4-style shared libraries.  */
  106.   set_solib_svr4_fetch_link_map_offsets
  107.     (gdbarch, svr4_ilp32_fetch_link_map_offsets);

  108.   /* Hook in the DWARF CFI frame unwinder.  */
  109.   dwarf2_frame_set_init_reg (gdbarch, hppabsd_dwarf2_frame_init_reg);
  110.   dwarf2_append_unwinders (gdbarch);
  111. }