sol2-tdep.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Target-dependent code for Solaris.
  2. Copyright (C) 2006-2022 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 "inferior.h"
  18. #include "objfiles.h"
  19. #include "sol2-tdep.h"
  20. /* The Solaris signal trampolines reside in libc. For normal signals,
  21. the function `sigacthandler' is used. This signal trampoline will
  22. call the signal handler using the System V calling convention,
  23. where the third argument is a pointer to an instance of
  24. `ucontext_t', which has a member `uc_mcontext' that contains the
  25. saved registers. Incidentally, the kernel passes the `ucontext_t'
  26. pointer as the third argument of the signal trampoline too, and
  27. `sigacthandler' simply passes it on. However, if you link your
  28. program with "-L/usr/ucblib -R/usr/ucblib -lucb", the function
  29. `ucbsigvechandler' will be used, which invokes the using the BSD
  30. convention, where the third argument is a pointer to an instance of
  31. `struct sigcontext'. It is the `ucbsigvechandler' function that
  32. converts the `ucontext_t' to a `sigcontext', and back. Unless the
  33. signal handler modifies the `struct sigcontext' we can safely
  34. ignore this. */
  35. static int
  36. sol2_pc_in_sigtramp (CORE_ADDR pc, const char *name)
  37. {
  38. return (name && (strcmp (name, "sigacthandler") == 0
  39. || strcmp (name, "ucbsigvechandler") == 0
  40. || strcmp (name, "__sighndlr") == 0));
  41. }
  42. /* Return whether THIS_FRAME corresponds to a Solaris sigtramp routine. */
  43. int
  44. sol2_sigtramp_p (struct frame_info *this_frame)
  45. {
  46. CORE_ADDR pc = get_frame_pc (this_frame);
  47. const char *name;
  48. find_pc_partial_function (pc, &name, NULL, NULL);
  49. return sol2_pc_in_sigtramp (pc, name);
  50. }
  51. static CORE_ADDR
  52. sol2_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
  53. {
  54. struct bound_minimal_symbol msym;
  55. msym = lookup_minimal_symbol("elf_bndr", NULL, NULL);
  56. if (msym.minsym && BMSYMBOL_VALUE_ADDRESS (msym) == pc)
  57. return frame_unwind_caller_pc (get_current_frame ());
  58. return 0;
  59. }
  60. /* This is how we want PTIDs from Solaris core files to be printed. */
  61. static std::string
  62. sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
  63. {
  64. struct inferior *inf;
  65. int pid;
  66. /* Check whether we're printing an LWP (gdb thread) or a process. */
  67. pid = ptid.lwp ();
  68. if (pid != 0)
  69. {
  70. /* A thread. */
  71. return string_printf ("LWP %ld", ptid.lwp ());
  72. }
  73. /* GDB didn't use to put a NT_PSTATUS note in Solaris cores. If
  74. that's missing, then we're dealing with a fake PID corelow.c made up. */
  75. inf = find_inferior_ptid (current_inferior ()->process_target (), ptid);
  76. if (inf == NULL || inf->fake_pid_p)
  77. return "<core>";
  78. /* Not fake; print as usual. */
  79. return normal_pid_to_str (ptid);
  80. }
  81. /* To be called from GDB_OSABI_SOLARIS handlers. */
  82. void
  83. sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  84. {
  85. /* The Sun compilers (Sun ONE Studio, Forte Developer, Sun WorkShop, SunPRO)
  86. compiler puts out 0 instead of the address in N_SO stabs. Starting with
  87. SunPRO 3.0, the compiler does this for N_FUN stabs too. */
  88. set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
  89. /* Solaris uses SVR4-style shared libraries. */
  90. set_gdbarch_skip_solib_resolver (gdbarch, sol2_skip_solib_resolver);
  91. /* How to print LWP PTIDs from core files. */
  92. set_gdbarch_core_pid_to_str (gdbarch, sol2_core_pid_to_str);
  93. }