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