add lunaix dynamic linker as submodule
[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 <sys/interrupts.h>
6
7 struct ksym_entry
8 {
9     ptr_t pc;
10     u32_t label_off;
11 };
12
13 struct trace_record
14 {
15     ptr_t pc;
16     char* symbol;
17 };
18
19 struct ksyms
20 {
21     u32_t ksym_count;
22     u32_t ksym_label_off;
23     struct ksym_entry syms[0];
24 };
25
26 struct trace_context
27 {
28     struct ksyms* ksym_table;
29 };
30
31 /**
32  * @brief Init the trace service using loaded modksyms module
33  *
34  * @param bhctx
35  */
36 void
37 trace_modksyms_init(struct boot_handoff* bhctx);
38
39 /**
40  * @brief Locate the symbol which is the closest to given pc.
41  *
42  * @param pc
43  * @return struct ksym_entry*
44  */
45 struct ksym_entry*
46 trace_sym_lookup(ptr_t pc);
47
48 /**
49  * @brief Walk the stack backwards to generate stack trace
50  *
51  * @param tb_buffer
52  * @param fp
53  * @param limit
54  * @param last_fp
55  * @return int
56  */
57 int
58 trace_walkback(struct trace_record* tb_buffer,
59                ptr_t fp,
60                int limit,
61                ptr_t* last_fp);
62
63 /**
64  * @brief Print the stack trace starting from the given frame pointer
65  *
66  * @param fp
67  */
68 void
69 trace_printstack_of(ptr_t fp);
70
71 /**
72  * @brief Print the stack trace given the current interrupt context. In addition
73  * to the stacktrace, this will also print all context switches happened
74  * beforehand, and all stack trace in each context. Recommended for verbose
75  * debugging.
76  *
77  * @param isrm
78  */
79 void
80 trace_printstack_isr(const isr_param* isrm);
81
82 /**
83  * @brief Print the stack trace starting from caller's frame pointer.
84  *
85  */
86 void
87 trace_printstack();
88
89 #endif /* __LUNAIX_TRACE_H */