homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 1 | /* libunwind - a platform-independent unwind library |
mostang.com!davidm | fa0828a | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 2 | Copyright (C) 2002-2004 Hewlett-Packard Co |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 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 "unwind_i.h" |
| 27 | #include "offsets.h" |
| 28 | |
| 29 | PROTECTED int |
| 30 | unw_step (unw_cursor_t *cursor) |
| 31 | { |
| 32 | struct cursor *c = (struct cursor *) cursor; |
Konstantin Belousov | aeee03d | 2010-04-05 16:28:46 +0300 | [diff] [blame^] | 33 | int ret, i; |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 34 | |
mostang.com!davidm | fa0828a | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 35 | Debug (1, "(cursor=%p, ip=0x%08x)\n", c, (unsigned) c->dwarf.ip); |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 36 | |
| 37 | /* Try DWARF-based unwinding... */ |
| 38 | ret = dwarf_step (&c->dwarf); |
| 39 | |
mostang.com!davidm | fa0828a | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 40 | if (ret < 0 && ret != -UNW_ENOINFO) |
| 41 | { |
| 42 | Debug (2, "returning %d\n", ret); |
| 43 | return ret; |
| 44 | } |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 45 | |
| 46 | if (unlikely (ret < 0)) |
| 47 | { |
| 48 | /* DWARF failed, let's see if we can follow the frame-chain |
| 49 | or skip over the signal trampoline. */ |
| 50 | struct dwarf_loc ebp_loc, eip_loc; |
| 51 | |
Arun Sharma | ff0ae70 | 2009-03-16 11:06:26 -0700 | [diff] [blame] | 52 | /* We could get here because of missing/bad unwind information. |
| 53 | Validate all addresses before dereferencing. */ |
| 54 | c->validate = 1; |
| 55 | |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 56 | Debug (13, "dwarf_step() failed (ret=%d), trying frame-chain\n", ret); |
| 57 | |
| 58 | if (unw_is_signal_frame (cursor)) |
Arun Sharma | 8e53e62 | 2010-04-04 16:17:32 -0700 | [diff] [blame] | 59 | { |
| 60 | ret = unw_handle_signal_frame(cursor); |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 61 | if (ret < 0) |
mostang.com!davidm | fa0828a | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 62 | { |
| 63 | Debug (2, "returning 0\n"); |
| 64 | return 0; |
| 65 | } |
Arun Sharma | 8e53e62 | 2010-04-04 16:17:32 -0700 | [diff] [blame] | 66 | } |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 67 | else |
| 68 | { |
| 69 | ret = dwarf_get (&c->dwarf, c->dwarf.loc[EBP], &c->dwarf.cfa); |
| 70 | if (ret < 0) |
mostang.com!davidm | fa0828a | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 71 | { |
| 72 | Debug (2, "returning %d\n", ret); |
| 73 | return ret; |
| 74 | } |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 75 | |
homeip.net!davidm | 5742642 | 2004-08-19 12:26:11 +0000 | [diff] [blame] | 76 | Debug (13, "[EBP=0x%x] = 0x%x\n", DWARF_GET_LOC (c->dwarf.loc[EBP]), |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 77 | c->dwarf.cfa); |
| 78 | |
| 79 | ebp_loc = DWARF_LOC (c->dwarf.cfa, 0); |
| 80 | eip_loc = DWARF_LOC (c->dwarf.cfa + 4, 0); |
| 81 | c->dwarf.cfa += 8; |
mostang.com!davidm | fa0828a | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 82 | |
| 83 | /* Mark all registers unsaved, since we don't know where |
| 84 | they are saved (if at all), except for the EBP and |
| 85 | EIP. */ |
| 86 | for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i) |
| 87 | c->dwarf.loc[i] = DWARF_NULL_LOC; |
Arun Sharma | 8e53e62 | 2010-04-04 16:17:32 -0700 | [diff] [blame] | 88 | |
| 89 | c->dwarf.loc[EBP] = ebp_loc; |
| 90 | c->dwarf.loc[EIP] = eip_loc; |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 91 | } |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 92 | c->dwarf.ret_addr_column = EIP; |
| 93 | |
| 94 | if (!DWARF_IS_NULL_LOC (c->dwarf.loc[EBP])) |
| 95 | { |
| 96 | ret = dwarf_get (&c->dwarf, c->dwarf.loc[EIP], &c->dwarf.ip); |
| 97 | if (ret < 0) |
mostang.com!davidm | fa0828a | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 98 | { |
| 99 | Debug (2, "returning %d\n", ret); |
| 100 | return ret; |
| 101 | } |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 102 | } |
| 103 | else |
| 104 | c->dwarf.ip = 0; |
| 105 | } |
mostang.com!davidm | fa0828a | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 106 | ret = (c->dwarf.ip == 0) ? 0 : 1; |
| 107 | Debug (2, "returning %d\n", ret); |
| 108 | return ret; |
homeip.net!davidm | 3dab98e | 2004-08-17 15:34:28 +0000 | [diff] [blame] | 109 | } |