Gget_save_loc.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2004 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. Modified for x86_64 by Max Asbock <masbock@us.ibm.com>
  5. This file is part of libunwind.
  6. Permission is hereby granted, free of charge, to any person obtaining
  7. a copy of this software and associated documentation files (the
  8. "Software"), to deal in the Software without restriction, including
  9. without limitation the rights to use, copy, modify, merge, publish,
  10. distribute, sublicense, and/or sell copies of the Software, and to
  11. permit persons to whom the Software is furnished to do so, subject to
  12. the following conditions:
  13. The above copyright notice and this permission notice shall be
  14. included in all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  22. #include "unwind_i.h"
  23. PROTECTED int
  24. unw_get_save_loc (unw_cursor_t *cursor, int reg, unw_save_loc_t *sloc)
  25. {
  26. struct cursor *c = (struct cursor *) cursor;
  27. dwarf_loc_t loc;
  28. loc = DWARF_NULL_LOC; /* default to "not saved" */
  29. switch (reg)
  30. {
  31. case UNW_X86_64_RBX: loc = c->dwarf.loc[RBX]; break;
  32. case UNW_X86_64_RSP: loc = c->dwarf.loc[RSP]; break;
  33. case UNW_X86_64_RBP: loc = c->dwarf.loc[RBP]; break;
  34. case UNW_X86_64_R12: loc = c->dwarf.loc[R12]; break;
  35. case UNW_X86_64_R13: loc = c->dwarf.loc[R13]; break;
  36. case UNW_X86_64_R14: loc = c->dwarf.loc[R14]; break;
  37. case UNW_X86_64_R15: loc = c->dwarf.loc[R15]; break;
  38. default:
  39. break;
  40. }
  41. memset (sloc, 0, sizeof (*sloc));
  42. if (DWARF_IS_NULL_LOC (loc))
  43. {
  44. sloc->type = UNW_SLT_NONE;
  45. return 0;
  46. }
  47. #if !defined(UNW_LOCAL_ONLY)
  48. if (DWARF_IS_REG_LOC (loc))
  49. {
  50. sloc->type = UNW_SLT_REG;
  51. sloc->u.regnum = DWARF_GET_LOC (loc);
  52. }
  53. else
  54. #endif
  55. {
  56. sloc->type = UNW_SLT_MEMORY;
  57. sloc->u.addr = DWARF_GET_LOC (loc);
  58. }
  59. return 0;
  60. }