blob: 5eac5f094596fd292137dd1a45ac552f801e456b [file] [log] [blame]
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -07001/* libunwind - a platform-independent unwind library
2 Copyright (C) 2008 CodeSourcery
3
4This file is part of libunwind.
5
6Permission is hereby granted, free of charge, to any person obtaining
7a copy of this software and associated documentation files (the
8"Software"), to deal in the Software without restriction, including
9without limitation the rights to use, copy, modify, merge, publish,
10distribute, sublicense, and/or sell copies of the Software, and to
11permit persons to whom the Software is furnished to do so, subject to
12the following conditions:
13
14The above copyright notice and this permission notice shall be
15included in all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
24
25#include "unwind_i.h"
26#include "offsets.h"
27
28PROTECTED int
29unw_step (unw_cursor_t *cursor)
30{
31 struct cursor *c = (struct cursor *) cursor;
Arun Sharma00aed962010-05-26 19:28:44 -070032 int ret = -UNW_EUNSPEC;
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -070033
34 Debug (1, "(cursor=%p)\n", c);
35
36 /* Try DWARF-based unwinding... this is the only method likely to work for
37 ARM. */
Arun Sharma00aed962010-05-26 19:28:44 -070038 if (UNW_TRY_METHOD(UNW_ARM_METHOD_DWARF))
39 {
40 ret = dwarf_step (&c->dwarf);
41 Debug(1, "dwarf_step()=%d\n", ret);
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -070042
Arun Sharma00aed962010-05-26 19:28:44 -070043 if (unlikely (ret == -UNW_ESTOPUNWIND))
44 return ret;
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -070045
Arun Sharma00aed962010-05-26 19:28:44 -070046 if (ret < 0 && ret != -UNW_ENOINFO)
47 {
48 Debug (2, "returning %d\n", ret);
49 return ret;
50 }
51 }
52
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -070053 if (unlikely (ret < 0))
Arun Sharma00aed962010-05-26 19:28:44 -070054 {
55 if (UNW_TRY_METHOD(UNW_ARM_METHOD_FRAME))
56 {
57 ret = UNW_ESUCCESS;
58 /* DWARF unwinding failed, try to follow APCS/optimized APCS frame chain */
59 unw_word_t instr, i;
60 Debug (13, "dwarf_step() failed (ret=%d), trying frame-chain\n", ret);
61 dwarf_loc_t ip_loc, fp_loc;
62 unw_word_t frame;
63 /* Mark all registers unsaved, since we don't know where
64 they are saved (if at all), except for the EBP and
65 EIP. */
66 if (dwarf_get(&c->dwarf, c->dwarf.loc[UNW_ARM_R11], &frame) < 0)
67 {
68 return 0;
69 }
70 for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i) {
71 c->dwarf.loc[i] = DWARF_NULL_LOC;
72 }
73 if (frame)
74 {
75 if (dwarf_get(&c->dwarf, DWARF_LOC(frame, 0), &instr) < 0)
76 {
77 return 0;
78 }
79 instr -= 8;
80 if (dwarf_get(&c->dwarf, DWARF_LOC(instr, 0), &instr) < 0)
81 {
82 return 0;
83 }
84 if ((instr & 0xFFFFD800) == 0xE92DD800)
85 {
86 /* Standard APCS frame. */
87 ip_loc = DWARF_LOC(frame - 4, 0);
88 fp_loc = DWARF_LOC(frame - 12, 0);
89 }
90 else
91 {
92 /* Codesourcery optimized normal frame. */
93 ip_loc = DWARF_LOC(frame, 0);
94 fp_loc = DWARF_LOC(frame - 4, 0);
95 }
96 if (dwarf_get(&c->dwarf, ip_loc, &c->dwarf.ip) < 0)
97 {
98 return 0;
99 }
100 c->dwarf.loc[UNW_ARM_R12] = ip_loc;
101 c->dwarf.loc[UNW_ARM_R11] = fp_loc;
102 Debug(15, "ip=%lx\n", c->dwarf.ip);
103 }
104 else
105 {
106 ret = -UNW_ENOINFO;
107 }
108 }
109 }
110 return ret == -UNW_ENOINFO ? 0 : 1;
Daniel Jacobowitz3842dac2008-02-04 17:16:37 -0700111}