1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2003-2004 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of libunwind.
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:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
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. */
33 #include "_UPT_internal.h"
36 get_unwind_info (struct elf_dyn_info
*edi
, pid_t pid
, unw_addr_space_t as
, unw_word_t ip
)
38 unsigned long segbase
, mapoff
;
41 #if UNW_TARGET_IA64 && defined(__linux)
42 if (!edi
->ktab
.start_ip
&& _Uia64_get_kernel_table (&edi
->ktab
) < 0)
45 if (edi
->ktab
.format
!= -1 && ip
>= edi
->ktab
.start_ip
&& ip
< edi
->ktab
.end_ip
)
49 if ((edi
->di_cache
.format
!= -1
50 && ip
>= edi
->di_cache
.start_ip
&& ip
< edi
->di_cache
.end_ip
)
52 || (edi
->di_debug
.format
!= -1
53 && ip
>= edi
->di_arm
.start_ip
&& ip
< edi
->di_arm
.end_ip
)
55 || (edi
->di_debug
.format
!= -1
56 && ip
>= edi
->di_debug
.start_ip
&& ip
< edi
->di_debug
.end_ip
))
61 if (tdep_get_elf_image (&edi
->ei
, pid
, ip
, &segbase
, &mapoff
, path
,
65 /* Here, SEGBASE is the starting-address of the (mmap'ped) segment
66 which covers the IP we're looking for. */
67 if (tdep_find_unwind_table (edi
, as
, path
, segbase
, mapoff
, ip
) < 0)
70 /* This can happen in corner cases where dynamically generated
71 code falls into the same page that contains the data-segment
72 and the page-offset of the code is within the first page of
74 if (edi
->di_cache
.format
!= -1
75 && (ip
< edi
->di_cache
.start_ip
|| ip
>= edi
->di_cache
.end_ip
))
76 edi
->di_cache
.format
= -1;
78 if (edi
->di_debug
.format
!= -1
79 && (ip
< edi
->di_debug
.start_ip
|| ip
>= edi
->di_debug
.end_ip
))
80 edi
->di_debug
.format
= -1;
82 if (edi
->di_cache
.format
== -1
84 && edi
->di_arm
.format
== -1
86 && edi
->di_debug
.format
== -1)
93 _UPT_find_proc_info (unw_addr_space_t as
, unw_word_t ip
, unw_proc_info_t
*pi
,
94 int need_unwind_info
, void *arg
)
96 struct UPT_info
*ui
= arg
;
97 int ret
= -UNW_ENOINFO
;
99 if (get_unwind_info (&ui
->edi
, ui
->pid
, as
, ip
) < 0)
103 if (ui
->edi
.ktab
.format
!= -1)
105 /* The kernel unwind table resides in local memory, so we have
106 to use the local address space to search it. Since
107 _UPT_put_unwind_info() has no easy way of detecting this
108 case, we simply make a copy of the unwind-info, so
109 _UPT_put_unwind_info() can always free() the unwind-info
110 without ill effects. */
111 ret
= tdep_search_unwind_table (unw_local_addr_space
, ip
, &ui
->edi
.ktab
, pi
,
112 need_unwind_info
, arg
);
115 if (!need_unwind_info
)
116 pi
->unwind_info
= NULL
;
119 void *mem
= malloc (pi
->unwind_info_size
);
123 memcpy (mem
, pi
->unwind_info
, pi
->unwind_info_size
);
124 pi
->unwind_info
= mem
;
130 if (ret
== -UNW_ENOINFO
&& ui
->edi
.di_cache
.format
!= -1)
131 ret
= tdep_search_unwind_table (as
, ip
, &ui
->edi
.di_cache
,
132 pi
, need_unwind_info
, arg
);
135 if (ret
== -UNW_ENOINFO
&& ui
->edi
.di_arm
.format
!= -1)
136 ret
= tdep_search_unwind_table (as
, ip
, &ui
->edi
.di_arm
, pi
,
137 need_unwind_info
, arg
);
140 if (ret
== -UNW_ENOINFO
&& ui
->edi
.di_debug
.format
!= -1)
141 ret
= tdep_search_unwind_table (as
, ip
, &ui
->edi
.di_debug
, pi
,
142 need_unwind_info
, arg
);