ibm.com!masbock | a766efd | 2004-08-19 13:39:10 +0000 | [diff] [blame] | 1 | /* libunwind - a platform-independent unwind library |
| 2 | Copyright (C) 2002-2004 Hewlett-Packard Co |
| 3 | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
| 4 | |
| 5 | Modified for x86_64 by Max Asbock <masbock@us.ibm.com> |
| 6 | |
| 7 | This file is part of libunwind. |
| 8 | |
| 9 | Permission is hereby granted, free of charge, to any person obtaining |
| 10 | a copy of this software and associated documentation files (the |
| 11 | "Software"), to deal in the Software without restriction, including |
| 12 | without limitation the rights to use, copy, modify, merge, publish, |
| 13 | distribute, sublicense, and/or sell copies of the Software, and to |
| 14 | permit persons to whom the Software is furnished to do so, subject to |
| 15 | the following conditions: |
| 16 | |
| 17 | The above copyright notice and this permission notice shall be |
| 18 | included in all copies or substantial portions of the Software. |
| 19 | |
| 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 27 | |
| 28 | #ifndef LIBUNWIND_H |
| 29 | #define LIBUNWIND_H |
| 30 | |
| 31 | #if defined(__cplusplus) || defined(c_plusplus) |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
Konstantin Belousov | 64b5391 | 2010-03-08 00:24:32 +0200 | [diff] [blame] | 35 | #include <sys/types.h> |
ibm.com!masbock | a766efd | 2004-08-19 13:39:10 +0000 | [diff] [blame] | 36 | #include <inttypes.h> |
| 37 | #include <ucontext.h> |
| 38 | |
| 39 | #define UNW_TARGET x86_64 |
| 40 | #define UNW_TARGET_X86_64 1 |
| 41 | |
| 42 | #define _U_TDEP_QP_TRUE 0 /* see libunwind-dynamic.h */ |
| 43 | |
| 44 | /* This needs to be big enough to accommodate "struct cursor", while |
| 45 | leaving some slack for future expansion. Changing this value will |
| 46 | require recompiling all users of this library. Stack allocation is |
| 47 | relatively cheap and unwind-state copying is relatively rare, so we |
| 48 | want to err on making it rather too big than too small. */ |
| 49 | #define UNW_TDEP_CURSOR_LEN 127 |
| 50 | |
| 51 | typedef uint64_t unw_word_t; |
Arun Sharma | 11ea127 | 2006-07-26 22:12:10 -0600 | [diff] [blame] | 52 | typedef int64_t unw_sword_t; |
ibm.com!masbock | a766efd | 2004-08-19 13:39:10 +0000 | [diff] [blame] | 53 | |
| 54 | typedef long double unw_tdep_fpreg_t; |
| 55 | |
| 56 | typedef enum |
| 57 | { |
| 58 | UNW_X86_64_RAX, |
| 59 | UNW_X86_64_RDX, |
| 60 | UNW_X86_64_RCX, |
| 61 | UNW_X86_64_RBX, |
| 62 | UNW_X86_64_RSI, |
| 63 | UNW_X86_64_RDI, |
| 64 | UNW_X86_64_RBP, |
| 65 | UNW_X86_64_RSP, |
| 66 | UNW_X86_64_R8, |
| 67 | UNW_X86_64_R9, |
| 68 | UNW_X86_64_R10, |
| 69 | UNW_X86_64_R11, |
| 70 | UNW_X86_64_R12, |
| 71 | UNW_X86_64_R13, |
| 72 | UNW_X86_64_R14, |
| 73 | UNW_X86_64_R15, |
| 74 | UNW_X86_64_RIP, |
| 75 | |
| 76 | /* XXX Add other regs here */ |
| 77 | |
| 78 | /* frame info (read-only) */ |
| 79 | UNW_X86_64_CFA, |
| 80 | |
| 81 | UNW_TDEP_LAST_REG = UNW_X86_64_RIP, |
| 82 | |
| 83 | UNW_TDEP_IP = UNW_X86_64_RIP, |
| 84 | UNW_TDEP_SP = UNW_X86_64_RSP, |
| 85 | UNW_TDEP_BP = UNW_X86_64_RBP, |
| 86 | UNW_TDEP_EH = UNW_X86_64_RAX |
| 87 | } |
| 88 | x86_64_regnum_t; |
| 89 | |
| 90 | #define UNW_TDEP_NUM_EH_REGS 2 /* XXX Not sure what this means */ |
| 91 | |
| 92 | typedef struct unw_tdep_save_loc |
| 93 | { |
| 94 | /* Additional target-dependent info on a save location. */ |
| 95 | } |
| 96 | unw_tdep_save_loc_t; |
| 97 | |
| 98 | /* On x86_64, we can directly use ucontext_t as the unwind context. */ |
| 99 | typedef ucontext_t unw_tdep_context_t; |
| 100 | |
ibm.com!masbock | a766efd | 2004-08-19 13:39:10 +0000 | [diff] [blame] | 101 | typedef struct |
| 102 | { |
mostang.com!davidm | 27f7d7d | 2005-05-03 09:13:17 +0000 | [diff] [blame] | 103 | /* no x86-64-specific auxiliary proc-info */ |
ibm.com!masbock | a766efd | 2004-08-19 13:39:10 +0000 | [diff] [blame] | 104 | } |
| 105 | unw_tdep_proc_info_t; |
| 106 | |
Lassi Tuura | 9e98f15 | 2011-03-19 10:00:48 +0100 | [diff] [blame^] | 107 | typedef enum |
| 108 | { |
| 109 | UNW_X86_64_FRAME_STANDARD = -2, /* regular rbp, rsp +/- offset */ |
| 110 | UNW_X86_64_FRAME_SIGRETURN = -1, /* special sigreturn frame */ |
| 111 | UNW_X86_64_FRAME_OTHER = 0, /* not cacheable (special or unrecognised) */ |
| 112 | UNW_X86_64_FRAME_GUESSED = 1 /* guessed it was regular, but not known */ |
| 113 | } |
| 114 | unw_tdep_frame_type_t; |
| 115 | |
| 116 | typedef struct |
| 117 | { |
| 118 | uint64_t virtual_address; |
| 119 | int64_t frame_type : 2; /* unw_tdep_frame_type_t classification */ |
| 120 | int64_t last_frame : 1; /* non-zero if last frame in chain */ |
| 121 | int64_t cfa_reg_rsp : 1; /* cfa dwarf base register is rsp vs. rbp */ |
| 122 | int64_t cfa_reg_offset : 30; /* cfa is at this offset from base register value */ |
| 123 | int64_t rbp_cfa_offset : 15; /* rbp saved at this offset from cfa (-1 = not saved) */ |
| 124 | int64_t rsp_cfa_offset : 15; /* rsp saved at this offset from cfa (-1 = not saved) */ |
| 125 | } |
| 126 | unw_tdep_frame_t; |
| 127 | |
Arun Sharma | ef29ead | 2008-06-16 14:42:16 -0600 | [diff] [blame] | 128 | #include "libunwind-dynamic.h" |
ibm.com!masbock | a766efd | 2004-08-19 13:39:10 +0000 | [diff] [blame] | 129 | #include "libunwind-common.h" |
| 130 | |
Arun Sharma | ef29ead | 2008-06-16 14:42:16 -0600 | [diff] [blame] | 131 | #define unw_tdep_getcontext UNW_ARCH_OBJ(getcontext) |
ibm.com!masbock | a766efd | 2004-08-19 13:39:10 +0000 | [diff] [blame] | 132 | #define unw_tdep_is_fpreg UNW_ARCH_OBJ(is_fpreg) |
Lassi Tuura | 9e98f15 | 2011-03-19 10:00:48 +0100 | [diff] [blame^] | 133 | #define unw_tdep_make_frame_cache UNW_OBJ(make_frame_cache) |
| 134 | #define unw_tdep_free_frame_cache UNW_OBJ(free_frame_cache) |
| 135 | #define unw_tdep_trace UNW_OBJ(trace) |
| 136 | |
| 137 | extern int unw_tdep_getcontext (unw_tdep_context_t *); |
ibm.com!masbock | a766efd | 2004-08-19 13:39:10 +0000 | [diff] [blame] | 138 | extern int unw_tdep_is_fpreg (int); |
| 139 | |
Lassi Tuura | 9e98f15 | 2011-03-19 10:00:48 +0100 | [diff] [blame^] | 140 | extern unw_tdep_frame_t *unw_tdep_make_frame_cache (size_t n); |
| 141 | extern int unw_tdep_free_frame_cache (unw_tdep_frame_t *p); |
| 142 | extern int unw_tdep_trace (unw_cursor_t *cursor, void **addresses, |
| 143 | int *n, unw_tdep_frame_t *cache); |
| 144 | |
ibm.com!masbock | a766efd | 2004-08-19 13:39:10 +0000 | [diff] [blame] | 145 | #if defined(__cplusplus) || defined(c_plusplus) |
| 146 | } |
| 147 | #endif |
| 148 | |
| 149 | #endif /* LIBUNWIND_H */ |