HPCToolkit
libunw-unwind.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 //
47 // This software was produced with support in part from the Defense Advanced
48 // Research Projects Agency (DARPA) through AFRL Contract FA8650-09-C-1915.
49 // Nothing in this work should be construed as reflecting the official policy or
50 // position of the Defense Department, the United States government, or
51 // Rice University.
52 //
53 //***************************************************************************
54 //
55 // File:
56 // libunw-unwind.c
57 //
58 // Purpose:
59 // Implement the hpcrun unwind primitives using libunwind
60 //
61 // hpcrun_unw_init
62 // hpcrun_unw_init_cursor
63 // hpcrun_unw_get_ra_loc
64 // hpcrun_unw_get_ip_reg
65 // hpcrun_unw_step
66 // hpcrun_unw_get_ip_unnorm_reg
67 //
68 //***************************************************************************
69 
70 //************************************************
71 // system includes
72 //************************************************
73 
74 #define UNW_LOCAL_ONLY
75 
76 #include <stdlib.h>
77 #include <stddef.h>
78 #include <stdint.h>
79 #include <inttypes.h>
80 #include <stdbool.h>
81 
82 #include <ucontext.h>
83 
84 #include <include/hpctoolkit-config.h>
85 
86 //************************************************
87 // external includes
88 //************************************************
89 
90 #include <monitor.h>
91 #include <libunwind.h>
92 
93 //************************************************
94 // local includes
95 //************************************************
96 
98 #include <messages/messages.h>
99 #include <hpcrun/hpcrun_stats.h>
101 #include <unwind/common/unwind.h>
106 
107 //************************************************
108 // interface functions
109 //************************************************
110 
111 // ----------------------------------------------------------
112 // hpcrun_unw_init
113 // ----------------------------------------------------------
114 
115 void
117 {
119 }
120 
121 
122 // ----------------------------------------------------------
123 // hpcrun_unw_get_ip_reg
124 // ----------------------------------------------------------
125 
126 int
128 {
129  unw_word_t tmp;
130  int rv = unw_get_reg(&(cursor->uc), UNW_REG_IP, &tmp);
131  *val = (void*) tmp;
132  return rv;
133 }
134 
135 int
137 {
138  *val = cursor->pc_unnorm;
139  return 0;
140 }
141 
142 int
144 {
145  *val = cursor->pc_norm;
146  return 0;
147 }
148 
149 // ----------------------------------------------------------
150 // hpcrun_unw_get_ra_loc (no trampolines yet)
151 // ----------------------------------------------------------
152 
153 void*
155 {
156  return NULL;
157 }
158 
159 // ----------------------------------------------------------
160 // hpcrun_unw_init_cursor
161 // ----------------------------------------------------------
162 
163 // Takes a sigaction() context pointer and makes a libunwind
164 // unw_cursor_t. The other fields in hpcrun_unw_cursor_t are unused,
165 // except for pc_norm and pc_unnorm.
166 //
167 void
169 {
170  libunw_unw_init_cursor(cursor, context);
171 }
172 
175 {
177  state = libunw_unw_step(cursor);
178  if (state == STEP_ERROR) {
179  unw_cursor_t *unw_cursor = &(cursor->uc);
180  if (unw_step(unw_cursor)) {
181  state = STEP_OK;
182  libunw_finalize_cursor(cursor);
183  }
184  }
185  return state;
186 }
187 
189 build_intervals(char *ins, unsigned int len, unwinder_t uw)
190 {
191  return libunw_build_intervals(ins, len);
192 }
193 
194 void
195 uw_recipe_tostr(void *uwr, char str[], unwinder_t uw)
196 {
197  return libunw_uw_recipe_tostr(uwr, str);
198 }
int hpcrun_unw_get_ip_unnorm_reg(hpcrun_unw_cursor_t *cursor, void **val)
void uw_recipe_tostr(void *uwr, char str[], unwinder_t uw)
static char * tmp
Definition: tokenize.c:63
void * hpcrun_unw_get_ra_loc(hpcrun_unw_cursor_t *c)
step_state hpcrun_unw_step(hpcrun_unw_cursor_t *cursor)
void hpcrun_unw_init_cursor(hpcrun_unw_cursor_t *cursor, void *context)
ip_normalized_t pc_norm
btuwi_status_t libunw_build_intervals(char *beg_insn, unsigned int len)
int hpcrun_unw_get_ip_reg(hpcrun_unw_cursor_t *cursor, void **val)
#define NULL
Definition: ElfHelper.cpp:85
void hpcrun_unw_init(void)
enum unwinder_e unwinder_t
static arm_state_t state
btuwi_status_t build_intervals(char *ins, unsigned int len, unwinder_t uw)
bool libunw_finalize_cursor(hpcrun_unw_cursor_t *cursor)
void libunw_uw_recipe_tostr(void *uwr, char str[])
step_state
Definition: unwind.h:124
void libunw_unw_init_cursor(hpcrun_unw_cursor_t *cursor, void *context)
step_state libunw_unw_step(hpcrun_unw_cursor_t *cursor)
int hpcrun_unw_get_ip_norm_reg(hpcrun_unw_cursor_t *cursor, ip_normalized_t *val)
void uw_recipe_map_init(void)