Merge branch 'master' into isa/arm64
[lunaix-os.git] / lunaix-os / includes / lunaix / trace.h
1 #ifndef __LUNAIX_TRACE_H
2 #define __LUNAIX_TRACE_H
3
4 #include <lunaix/boot_generic.h>
5 #include <lunaix/hart_state.h>
6
7 #include <sys-generic/trace_arch.h>
8
9 struct ksym_entry
10 {
11     ptr_t pc;
12     char* label;
13 } align(8);
14
15 struct trace_record
16 {
17     ptr_t pc;
18     ptr_t sym_pc;
19     char* symbol;
20 };
21
22 struct ksyms
23 {
24     unsigned long ksym_count;
25     struct ksym_entry syms[0];
26 };
27
28 struct trace_context
29 {
30     struct ksyms* ksym_table;
31 };
32
33 /**
34  * @brief Init the trace service using loaded modksyms module
35  *
36  * @param bhctx
37  */
38 void
39 trace_modksyms_init(struct boot_handoff* bhctx);
40
41 /**
42  * @brief Locate the symbol which is the closest to given pc.
43  *
44  * @param pc
45  * @return struct ksym_entry*
46  */
47 struct ksym_entry*
48 trace_sym_lookup(ptr_t pc);
49
50 /**
51  * @brief Walk the stack backwards to generate stack trace
52  *
53  * @param tb_buffer
54  * @param fp
55  * @param limit
56  * @param last_fp
57  * @return int
58  */
59 int
60 trace_walkback(struct trace_record* tb_buffer,
61                ptr_t fp,
62                int limit,
63                ptr_t* last_fp);
64
65 /**
66  * @brief Print the stack trace starting from the given frame pointer
67  *
68  * @param fp
69  */
70 void
71 trace_printstack_of(ptr_t fp);
72
73 /**
74  * @brief Print the stack trace given the current interrupt context. In addition
75  * to the stacktrace, this will also print all context switches happened
76  * beforehand, and all stack trace in each context. Recommended for verbose
77  * debugging.
78  *
79  * @param isrm
80  */
81 void
82 trace_printstack_isr(const struct hart_state* hstate);
83
84 /**
85  * @brief Print the stack trace starting from caller's frame pointer.
86  *
87  */
88 void
89 trace_printstack();
90
91 void
92 trace_log(const char* fmt, ...);
93
94 #endif /* __LUNAIX_TRACE_H */