Cthulhu  0.2.10
Cthulhu compiler collection
unwind.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #include "backtrace/backtrace.h"
4 #include <stdio.h>
5 
6 #define UNW_LOCAL_ONLY
7 #include <unwind.h>
8 
9 static unw_context_t gContext;
10 
11 void bt_init(void)
12 {
13  unw_getcontext(&gContext);
14 }
15 
16 void bt_update(void)
17 {
18 
19 }
20 
22 const char *bt_backend(void)
23 {
24  return "libunwind";
25 }
26 
27 void bt_read_inner(bt_trace_t callback, void *user)
28 {
29  unw_cursor_t cursor;
30  unw_word_t ip, sp;
31 
32  unw_init_local(&cursor, &gContext);
33 
34  while (unw_step(&cursor) > 0)
35  {
36  unw_get_reg(&cursor, UNW_REG_IP, &ip);
37  unw_get_reg(&cursor, UNW_REG_SP, &sp);
38 
39  bt_address_t frame = ip;
40 
41  callback(frame, &frame);
42  }
43 }
44 
46 {
47  text_t name = symbol->name;
48  (void)snprintf(name.text, name.length, "0x%" PRIxPTR, frame);
49 
50  return eResolveNothing;
51 }
#define STA_DECL
sal2 annotation on function implementations to copy annotations from the declaration
void bt_init(void)
initialize the backtrace backend
Definition: unwind.c:11
uint_least64_t bt_address_t
an address of a symbol
Definition: backtrace.h:26
void(* bt_trace_t)(bt_address_t frame, void *user)
user callback for bt_read
Definition: backtrace.h:74
bt_resolve_t
how much of a frame was reconstructed
Definition: backtrace.h:47
void bt_update(void)
update the loaded module cache
Definition: unwind.c:16
STA_DECL const char * bt_backend(void)
get the backtrace backend name
Definition: unwind.c:22
@ eResolveNothing
nothing was resolved
Definition: backtrace.h:49
a symbol
Definition: backtrace.h:33
text_t name
a buffer to hold the name
Definition: backtrace.h:39
a range of text
Definition: text.h:14
size_t length
the number of characters in the text
Definition: text.h:19
bt_resolve_t bt_resolve_inner(bt_address_t frame, bt_symbol_t *symbol)
Definition: unwind.c:45
void bt_read_inner(bt_trace_t callback, void *user)
Definition: unwind.c:27