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