Imported Upstream version 1.1
[platform/upstream/libunwind.git] / src / ptrace / _UPT_get_dyn_info_list_addr.c
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
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 "_UPT_internal.h"
27
28 #if UNW_TARGET_IA64 && defined(__linux)
29 # include "elf64.h"
30 # include "os-linux.h"
31
32 static inline int
33 get_list_addr (unw_addr_space_t as, unw_word_t *dil_addr, void *arg,
34                int *countp)
35 {
36   unsigned long lo, hi, off;
37   struct UPT_info *ui = arg;
38   struct map_iterator mi;
39   char path[PATH_MAX];
40   unw_word_t res;
41   int count = 0;
42
43   maps_init (&mi, ui->pid);
44   while (maps_next (&mi, &lo, &hi, &off))
45     {
46       if (off)
47         continue;
48
49       invalidate_edi(&ui->edi);
50
51       if (elf_map_image (&ui->edi.ei, path) < 0)
52         /* ignore unmappable stuff like "/SYSV00001b58 (deleted)" */
53         continue;
54
55       Debug (16, "checking object %s\n", path);
56
57       if (tdep_find_unwind_table (&ui->edi, as, path, lo, off, 0) > 0)
58         {
59           res = _Uia64_find_dyn_list (as, &ui->edi.di_cache, arg);
60           if (res && count++ == 0)
61             {
62               Debug (12, "dyn_info_list_addr = 0x%lx\n", (long) res);
63               *dil_addr = res;
64             }
65         }
66     }
67   maps_close (&mi);
68   *countp = count;
69   return 0;
70 }
71
72 #else
73
74 static inline int
75 get_list_addr (unw_addr_space_t as, unw_word_t *dil_addr, void *arg,
76                int *countp)
77 {
78 # warning Implement get_list_addr(), please.
79   *countp = 0;
80   return 0;
81 }
82
83 #endif
84
85 int
86 _UPT_get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dil_addr,
87                              void *arg)
88 {
89   int count, ret;
90
91   Debug (12, "looking for dyn_info list\n");
92
93   if ((ret = get_list_addr (as, dil_addr, arg, &count)) < 0)
94     return ret;
95
96   /* If multiple dynamic-info list addresses are found, we would have
97      to determine which was is the one actually in use (since the
98      dynamic name resolution algorithm will pick one "winner").
99      Perhaps we'd have to track them all until we find one that's
100      non-empty.  Hopefully, this case simply will never arise, since
101      only libunwind defines the dynamic info list head. */
102   assert (count <= 1);
103
104   return (count > 0) ? 0 : -UNW_ENOINFO;
105 }