x86-tdep.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Target-dependent code for X86-based targets.
  2. Copyright (C) 2018-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 "x86-tdep.h"
  16. #include "symtab.h"
  17. /* Check whether NAME is included in NAMES[LO] (inclusive) to NAMES[HI]
  18. (exclusive). */
  19. static bool
  20. x86_is_thunk_register_name (const char *name, const char * const *names,
  21. int lo, int hi)
  22. {
  23. int reg;
  24. for (reg = lo; reg < hi; ++reg)
  25. if (strcmp (name, names[reg]) == 0)
  26. return true;
  27. return false;
  28. }
  29. /* See x86-tdep.h. */
  30. bool
  31. x86_in_indirect_branch_thunk (CORE_ADDR pc, const char * const *register_names,
  32. int lo, int hi)
  33. {
  34. struct bound_minimal_symbol bmfun = lookup_minimal_symbol_by_pc (pc);
  35. if (bmfun.minsym == nullptr)
  36. return false;
  37. const char *name = bmfun.minsym->linkage_name ();
  38. if (name == nullptr)
  39. return false;
  40. /* Check the indirect return thunk first. */
  41. if (strcmp (name, "__x86_return_thunk") == 0)
  42. return true;
  43. /* Then check a family of indirect call/jump thunks. */
  44. static const char thunk[] = "__x86_indirect_thunk";
  45. static const size_t length = sizeof (thunk) - 1;
  46. if (strncmp (name, thunk, length) != 0)
  47. return false;
  48. /* If that's the complete name, we're in the memory thunk. */
  49. name += length;
  50. if (*name == '\0')
  51. return true;
  52. /* Check for suffixes. */
  53. if (*name++ != '_')
  54. return false;
  55. if (x86_is_thunk_register_name (name, register_names, lo, hi))
  56. return true;
  57. return false;
  58. }