1/* libunwind - a platform-independent unwind library 2 3This file is part of libunwind. 4 5Permission is hereby granted, free of charge, to any person obtaining 6a copy of this software and associated documentation files (the 7"Software"), to deal in the Software without restriction, including 8without limitation the rights to use, copy, modify, merge, publish, 9distribute, sublicense, and/or sell copies of the Software, and to 10permit persons to whom the Software is furnished to do so, subject to 11the following conditions: 12 13The above copyright notice and this permission notice shall be 14included in all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 23 24#include "_UCD_lib.h" 25#include "_UCD_internal.h" 26 27 28/* Find the ELF image that contains IP and return the "closest" 29 procedure name, if there is one. With some caching, this could be 30 sped up greatly, but until an application materializes that's 31 sensitive to the performance of this routine, why bother... */ 32static int 33elf_w (CD_get_proc_name) (struct UCD_info *ui, unw_addr_space_t as, unw_word_t ip, 34 char *buf, size_t buf_len, unw_word_t *offp) 35{ 36 unsigned long segbase, mapoff; 37 int ret; 38 39 /* Used to be tdep_get_elf_image() in ptrace unwinding code */ 40 coredump_phdr_t *cphdr = _UCD_get_elf_image(ui, ip); 41 if (!cphdr) 42 { 43 Debug(1, "returns error: _UCD_get_elf_image failed\n"); 44 return -UNW_ENOINFO; 45 } 46 /* segbase: where it is mapped in virtual memory */ 47 /* mapoff: offset in the file */ 48 segbase = cphdr->p_vaddr; 49 /*mapoff = phdr->p_offset; WRONG! phdr->p_offset is the offset in COREDUMP file */ 50 mapoff = 0; 51 52 ret = elf_w (get_proc_name_in_image) (as, &ui->edi.ei, segbase, mapoff, ip, buf, buf_len, offp); 53 54 return ret; 55} 56 57int 58_UCD_get_proc_name (unw_addr_space_t as, unw_word_t ip, 59 char *buf, size_t buf_len, unw_word_t *offp, void *arg) 60{ 61 struct UCD_info *ui = arg; 62 63#if ELF_CLASS == ELFCLASS64 64 return _Uelf64_CD_get_proc_name (ui, as, ip, buf, buf_len, offp); 65#elif ELF_CLASS == ELFCLASS32 66 return _Uelf32_CD_get_proc_name (ui, as, ip, buf, buf_len, offp); 67#else 68 return -UNW_ENOINFO; 69#endif 70} 71