blob: cdde5579cd33811afeeef45dfda2de8c479cffb1 [file] [log] [blame]
ibm.com!masbocka766efd2004-08-19 13:39:10 +00001/* 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
7This file is part of libunwind.
8
9Permission is hereby granted, free of charge, to any person obtaining
10a copy of this software and associated documentation files (the
11"Software"), to deal in the Software without restriction, including
12without limitation the rights to use, copy, modify, merge, publish,
13distribute, sublicense, and/or sell copies of the Software, and to
14permit persons to whom the Software is furnished to do so, subject to
15the following conditions:
16
17The above copyright notice and this permission notice shall be
18included in all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26WITH 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)
32extern "C" {
33#endif
34
Konstantin Belousov64b53912010-03-08 00:24:32 +020035#include <sys/types.h>
ibm.com!masbocka766efd2004-08-19 13:39:10 +000036#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
51typedef uint64_t unw_word_t;
Arun Sharma11ea1272006-07-26 22:12:10 -060052typedef int64_t unw_sword_t;
ibm.com!masbocka766efd2004-08-19 13:39:10 +000053
54typedef long double unw_tdep_fpreg_t;
55
56typedef 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 }
88x86_64_regnum_t;
89
90#define UNW_TDEP_NUM_EH_REGS 2 /* XXX Not sure what this means */
91
92typedef struct unw_tdep_save_loc
93 {
94 /* Additional target-dependent info on a save location. */
95 }
96unw_tdep_save_loc_t;
97
98/* On x86_64, we can directly use ucontext_t as the unwind context. */
99typedef ucontext_t unw_tdep_context_t;
100
ibm.com!masbocka766efd2004-08-19 13:39:10 +0000101typedef struct
102 {
mostang.com!davidm27f7d7d2005-05-03 09:13:17 +0000103 /* no x86-64-specific auxiliary proc-info */
ibm.com!masbocka766efd2004-08-19 13:39:10 +0000104 }
105unw_tdep_proc_info_t;
106
Lassi Tuura9e98f152011-03-19 10:00:48 +0100107typedef 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 }
114unw_tdep_frame_type_t;
115
116typedef 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 }
126unw_tdep_frame_t;
127
Arun Sharmaef29ead2008-06-16 14:42:16 -0600128#include "libunwind-dynamic.h"
ibm.com!masbocka766efd2004-08-19 13:39:10 +0000129#include "libunwind-common.h"
130
Arun Sharmaef29ead2008-06-16 14:42:16 -0600131#define unw_tdep_getcontext UNW_ARCH_OBJ(getcontext)
ibm.com!masbocka766efd2004-08-19 13:39:10 +0000132#define unw_tdep_is_fpreg UNW_ARCH_OBJ(is_fpreg)
Lassi Tuura9e98f152011-03-19 10:00:48 +0100133#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
137extern int unw_tdep_getcontext (unw_tdep_context_t *);
ibm.com!masbocka766efd2004-08-19 13:39:10 +0000138extern int unw_tdep_is_fpreg (int);
139
Lassi Tuura9e98f152011-03-19 10:00:48 +0100140extern unw_tdep_frame_t *unw_tdep_make_frame_cache (size_t n);
141extern int unw_tdep_free_frame_cache (unw_tdep_frame_t *p);
142extern int unw_tdep_trace (unw_cursor_t *cursor, void **addresses,
143 int *n, unw_tdep_frame_t *cache);
144
ibm.com!masbocka766efd2004-08-19 13:39:10 +0000145#if defined(__cplusplus) || defined(c_plusplus)
146}
147#endif
148
149#endif /* LIBUNWIND_H */