_UPT_get_dyn_info_list_addr.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2003-2005 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. This file is part of libunwind.
  5. Permission is hereby granted, free of charge, to any person obtaining
  6. a copy of this software and associated documentation files (the
  7. "Software"), to deal in the Software without restriction, including
  8. without limitation the rights to use, copy, modify, merge, publish,
  9. distribute, sublicense, and/or sell copies of the Software, and to
  10. permit persons to whom the Software is furnished to do so, subject to
  11. the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  21. #include "_UCD_lib.h"
  22. #include "_UCD_internal.h"
  23. #if UNW_TARGET_IA64 && defined(__linux)
  24. # include "elf64.h"
  25. # include "os-linux.h"
  26. static inline int
  27. get_list_addr (unw_addr_space_t as, unw_word_t *dil_addr, void *arg,
  28. int *countp)
  29. {
  30. unsigned long lo, hi, off;
  31. struct UPT_info *ui = arg;
  32. struct map_iterator mi;
  33. char path[PATH_MAX];
  34. unw_dyn_info_t *di;
  35. unw_word_t res;
  36. int count = 0;
  37. maps_init (&mi, ui->pid);
  38. while (maps_next (&mi, &lo, &hi, &off))
  39. {
  40. if (off)
  41. continue;
  42. invalidate_edi (&ui->edi);
  43. if (elf_map_image (&ui->ei, path) < 0)
  44. /* ignore unmappable stuff like "/SYSV00001b58 (deleted)" */
  45. continue;
  46. Debug (16, "checking object %s\n", path);
  47. di = dwarf_find_unwind_table (&ui->edi, as, path, lo, off);
  48. if (di)
  49. {
  50. res = _Uia64_find_dyn_list (as, di, arg);
  51. if (res && count++ == 0)
  52. {
  53. Debug (12, "dyn_info_list_addr = 0x%lx\n", (long) res);
  54. *dil_addr = res;
  55. }
  56. }
  57. }
  58. maps_close (&mi);
  59. *countp = count;
  60. return 0;
  61. }
  62. #else
  63. static inline int
  64. get_list_addr (unw_addr_space_t as, unw_word_t *dil_addr, void *arg,
  65. int *countp)
  66. {
  67. # warning Implement get_list_addr(), please.
  68. *countp = 0;
  69. return 0;
  70. }
  71. #endif
  72. int
  73. _UCD_get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dil_addr,
  74. void *arg)
  75. {
  76. int count, ret;
  77. Debug (12, "looking for dyn_info list\n");
  78. if ((ret = get_list_addr (as, dil_addr, arg, &count)) < 0)
  79. return ret;
  80. /* If multiple dynamic-info list addresses are found, we would have
  81. to determine which was is the one actually in use (since the
  82. dynamic name resolution algorithm will pick one "winner").
  83. Perhaps we'd have to track them all until we find one that's
  84. non-empty. Hopefully, this case simply will never arise, since
  85. only libunwind defines the dynamic info list head. */
  86. assert (count <= 1);
  87. return (count > 0) ? 0 : -UNW_ENOINFO;
  88. }