gdb/obsd-tdep.c - gdb

Functions defined

Source code

  1. /* Target-dependent code for OpenBSD.

  2.    Copyright (C) 2005-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 "symtab.h"
  17. #include "objfiles.h"

  18. #include "obsd-tdep.h"

  19. CORE_ADDR
  20. obsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
  21. {
  22.   struct bound_minimal_symbol msym;

  23.   msym = lookup_minimal_symbol("_dl_bind", NULL, NULL);
  24.   if (msym.minsym && BMSYMBOL_VALUE_ADDRESS (msym) == pc)
  25.     return frame_unwind_caller_pc (get_current_frame ());
  26.   else
  27.     return find_solib_trampoline_target (get_current_frame (), pc);
  28. }

  29. /* OpenBSD signal numbers.  From <sys/signal.h>. */

  30. enum
  31.   {
  32.     OBSD_SIGHUP = 1,
  33.     OBSD_SIGINT = 2,
  34.     OBSD_SIGQUIT = 3,
  35.     OBSD_SIGILL = 4,
  36.     OBSD_SIGTRAP = 5,
  37.     OBSD_SIGABRT = 6,
  38.     OBSD_SIGEMT = 7,
  39.     OBSD_SIGFPE = 8,
  40.     OBSD_SIGKILL = 9,
  41.     OBSD_SIGBUS = 10,
  42.     OBSD_SIGSEGV = 11,
  43.     OBSD_SIGSYS = 12,
  44.     OBSD_SIGPIPE = 13,
  45.     OBSD_SIGALRM = 14,
  46.     OBSD_SIGTERM = 15,
  47.     OBSD_SIGURG = 16,
  48.     OBSD_SIGSTOP = 17,
  49.     OBSD_SIGTSTP = 18,
  50.     OBSD_SIGCONT = 19,
  51.     OBSD_SIGCHLD = 20,
  52.     OBSD_SIGTTIN = 21,
  53.     OBSD_SIGTTOU = 22,
  54.     OBSD_SIGIO = 23,
  55.     OBSD_SIGXCPU = 24,
  56.     OBSD_SIGXFSZ = 25,
  57.     OBSD_SIGVTALRM = 26,
  58.     OBSD_SIGPROF = 27,
  59.     OBSD_SIGWINCH = 28,
  60.     OBSD_SIGINFO = 29,
  61.     OBSD_SIGUSR1 = 30,
  62.     OBSD_SIGUSR2 = 31,
  63.     OBSD_SIGTHR = 32,
  64.   };

  65. /* Implement the "gdb_signal_from_target" gdbarch method.  */

  66. static enum gdb_signal
  67. obsd_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
  68. {
  69.   switch (signal)
  70.     {
  71.     case 0:
  72.       return GDB_SIGNAL_0;

  73.     case OBSD_SIGHUP:
  74.       return GDB_SIGNAL_HUP;

  75.     case OBSD_SIGINT:
  76.       return GDB_SIGNAL_INT;

  77.     case OBSD_SIGQUIT:
  78.       return GDB_SIGNAL_QUIT;

  79.     case OBSD_SIGILL:
  80.       return GDB_SIGNAL_ILL;

  81.     case OBSD_SIGTRAP:
  82.       return GDB_SIGNAL_TRAP;

  83.     case OBSD_SIGABRT:
  84.       return GDB_SIGNAL_ABRT;

  85.     case OBSD_SIGEMT:
  86.       return GDB_SIGNAL_EMT;

  87.     case OBSD_SIGFPE:
  88.       return GDB_SIGNAL_FPE;

  89.     case OBSD_SIGKILL:
  90.       return GDB_SIGNAL_KILL;

  91.     case OBSD_SIGBUS:
  92.       return GDB_SIGNAL_BUS;

  93.     case OBSD_SIGSEGV:
  94.       return GDB_SIGNAL_SEGV;

  95.     case OBSD_SIGSYS:
  96.       return GDB_SIGNAL_SYS;

  97.     case OBSD_SIGPIPE:
  98.       return GDB_SIGNAL_PIPE;

  99.     case OBSD_SIGALRM:
  100.       return GDB_SIGNAL_ALRM;

  101.     case OBSD_SIGTERM:
  102.       return GDB_SIGNAL_TERM;

  103.     case OBSD_SIGURG:
  104.       return GDB_SIGNAL_URG;

  105.     case OBSD_SIGSTOP:
  106.       return GDB_SIGNAL_STOP;

  107.     case OBSD_SIGTSTP:
  108.       return GDB_SIGNAL_TSTP;

  109.     case OBSD_SIGCONT:
  110.       return GDB_SIGNAL_CONT;

  111.     case OBSD_SIGCHLD:
  112.       return GDB_SIGNAL_CHLD;

  113.     case OBSD_SIGTTIN:
  114.       return GDB_SIGNAL_TTIN;

  115.     case OBSD_SIGTTOU:
  116.       return GDB_SIGNAL_TTOU;

  117.     case OBSD_SIGIO:
  118.       return GDB_SIGNAL_IO;

  119.     case OBSD_SIGXCPU:
  120.       return GDB_SIGNAL_XCPU;

  121.     case OBSD_SIGXFSZ:
  122.       return GDB_SIGNAL_XFSZ;

  123.     case OBSD_SIGVTALRM:
  124.       return GDB_SIGNAL_VTALRM;

  125.     case OBSD_SIGPROF:
  126.       return GDB_SIGNAL_PROF;

  127.     case OBSD_SIGWINCH:
  128.       return GDB_SIGNAL_WINCH;

  129.     case OBSD_SIGINFO:
  130.       return GDB_SIGNAL_INFO;

  131.     case OBSD_SIGUSR1:
  132.       return GDB_SIGNAL_USR1;

  133.     case OBSD_SIGUSR2:
  134.       return GDB_SIGNAL_USR2;
  135.     }

  136.   return GDB_SIGNAL_UNKNOWN;
  137. }

  138. /* Implement the "gdb_signal_to_target" gdbarch method.  */

  139. static int
  140. obsd_gdb_signal_to_target (struct gdbarch *gdbarch,
  141.                            enum gdb_signal signal)
  142. {
  143.   switch (signal)
  144.     {
  145.     case GDB_SIGNAL_0:
  146.       return 0;

  147.     case GDB_SIGNAL_HUP:
  148.       return OBSD_SIGHUP;

  149.     case GDB_SIGNAL_INT:
  150.       return OBSD_SIGINT;

  151.     case GDB_SIGNAL_QUIT:
  152.       return OBSD_SIGQUIT;

  153.     case GDB_SIGNAL_ILL:
  154.       return OBSD_SIGILL;

  155.     case GDB_SIGNAL_TRAP:
  156.       return OBSD_SIGTRAP;

  157.     case GDB_SIGNAL_ABRT:
  158.       return OBSD_SIGABRT;

  159.     case GDB_SIGNAL_EMT:
  160.       return OBSD_SIGEMT;

  161.     case GDB_SIGNAL_FPE:
  162.       return OBSD_SIGFPE;

  163.     case GDB_SIGNAL_KILL:
  164.       return OBSD_SIGKILL;

  165.     case GDB_SIGNAL_BUS:
  166.       return OBSD_SIGBUS;

  167.     case GDB_SIGNAL_SEGV:
  168.       return OBSD_SIGSEGV;

  169.     case GDB_SIGNAL_SYS:
  170.       return OBSD_SIGSYS;

  171.     case GDB_SIGNAL_PIPE:
  172.       return OBSD_SIGPIPE;

  173.     case GDB_SIGNAL_ALRM:
  174.       return OBSD_SIGALRM;

  175.     case GDB_SIGNAL_TERM:
  176.       return OBSD_SIGTERM;

  177.     case GDB_SIGNAL_URG:
  178.       return OBSD_SIGURG;

  179.     case GDB_SIGNAL_STOP:
  180.       return OBSD_SIGSTOP;

  181.     case GDB_SIGNAL_TSTP:
  182.       return OBSD_SIGTSTP;

  183.     case GDB_SIGNAL_CONT:
  184.       return OBSD_SIGCONT;

  185.     case GDB_SIGNAL_CHLD:
  186.       return OBSD_SIGCHLD;

  187.     case GDB_SIGNAL_TTIN:
  188.       return OBSD_SIGTTIN;

  189.     case GDB_SIGNAL_TTOU:
  190.       return OBSD_SIGTTOU;

  191.     case GDB_SIGNAL_IO:
  192.       return OBSD_SIGIO;

  193.     case GDB_SIGNAL_XCPU:
  194.       return OBSD_SIGXCPU;

  195.     case GDB_SIGNAL_XFSZ:
  196.       return OBSD_SIGXFSZ;

  197.     case GDB_SIGNAL_VTALRM:
  198.       return OBSD_SIGVTALRM;

  199.     case GDB_SIGNAL_PROF:
  200.       return OBSD_SIGPROF;

  201.     case GDB_SIGNAL_WINCH:
  202.       return OBSD_SIGWINCH;

  203.     case GDB_SIGNAL_USR1:
  204.       return OBSD_SIGUSR1;

  205.     case GDB_SIGNAL_USR2:
  206.       return OBSD_SIGUSR2;

  207.     case GDB_SIGNAL_INFO:
  208.       return OBSD_SIGINFO;
  209.     }

  210.   return -1;
  211. }

  212. static int
  213. obsd_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr,
  214.                  gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
  215. {
  216.   struct type *int_type = builtin_type (gdbarch)->builtin_int;
  217.   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
  218.   const int sizeof_auxv_type = TYPE_LENGTH (int_type);
  219.   const int sizeof_auxv_val = TYPE_LENGTH (ptr_type);
  220.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  221.   gdb_byte *ptr = *readptr;

  222.   if (endptr == ptr)
  223.     return 0;

  224.   if (endptr - ptr < 2 * sizeof_auxv_val)
  225.     return -1;

  226.   *typep = extract_unsigned_integer (ptr, sizeof_auxv_type, byte_order);
  227.   ptr += sizeof_auxv_val;        /* Alignment.  */
  228.   *valp = extract_unsigned_integer (ptr, sizeof_auxv_val, byte_order);
  229.   ptr += sizeof_auxv_val;

  230.   *readptr = ptr;
  231.   return 1;
  232. }

  233. void
  234. obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  235. {
  236.   set_gdbarch_gdb_signal_from_target (gdbarch,
  237.                                       obsd_gdb_signal_from_target);
  238.   set_gdbarch_gdb_signal_to_target (gdbarch,
  239.                                     obsd_gdb_signal_to_target);

  240.   /* Unlike Linux, OpenBSD actually follows the ELF standard.  */
  241.   set_gdbarch_auxv_parse (gdbarch, obsd_auxv_parse);
  242. }