• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libunwind - a platform-independent unwind library
2 
3 This file is part of libunwind.
4 
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 
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH 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...  */
32 static int
elf_w(CD_get_proc_name)33 elf_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   /* We're about to map an elf image. If there is an elf image currently mapped,
40      then make sure to unmap it. */
41   invalidate_edi(&ui->edi);
42 
43   /* Used to be tdep_get_elf_image() in ptrace unwinding code */
44   coredump_phdr_t *cphdr = _UCD_get_elf_image(ui, ip);
45   if (!cphdr)
46     {
47       Debug(1, "returns error: _UCD_get_elf_image failed\n");
48       return -UNW_ENOINFO;
49     }
50   /* segbase: where it is mapped in virtual memory */
51   /* mapoff: offset in the file */
52   segbase = cphdr->p_vaddr;
53   /*mapoff  = phdr->p_offset; WRONG! phdr->p_offset is the offset in COREDUMP file */
54   mapoff  = 0;
55 
56   ret = elf_w (get_proc_name_in_image) (as, &ui->edi.ei, segbase, mapoff, ip, buf, buf_len, offp);
57 
58   return ret;
59 }
60 
61 int
_UCD_get_proc_name(unw_addr_space_t as,unw_word_t ip,char * buf,size_t buf_len,unw_word_t * offp,void * arg)62 _UCD_get_proc_name (unw_addr_space_t as, unw_word_t ip,
63                     char *buf, size_t buf_len, unw_word_t *offp, void *arg)
64 {
65   struct UCD_info *ui = arg;
66 
67 #if UNW_ELF_CLASS == UNW_ELFCLASS64
68   return _Uelf64_CD_get_proc_name (ui, as, ip, buf, buf_len, offp);
69 #elif UNW_ELF_CLASS == UNW_ELFCLASS32
70   return _Uelf32_CD_get_proc_name (ui, as, ip, buf, buf_len, offp);
71 #else
72   return -UNW_ENOINFO;
73 #endif
74 }
75