581ab4448982e7d815aac5cf448a0081eb9093e3
[mono.git] / mono / utils / mono-stack-unwinding.h
1 #ifndef __MONO_MONO_STACK_UNWINDING_H__
2 #define __MONO_MONO_STACK_UNWINDING_H__
3
4 #include <mono/metadata/appdomain.h>
5 #include <mono/metadata/metadata.h>
6 #include <mono/utils/mono-context.h>
7
8 /*
9  * Possible frame types returned by the stack walker.
10  */
11 typedef enum {
12         /* Normal managed frames */
13         FRAME_TYPE_MANAGED = 0,
14         /* Pseudo frame marking the start of a method invocation done by the soft debugger */
15         FRAME_TYPE_DEBUGGER_INVOKE = 1,
16         /* Frame for transitioning to native code */
17         FRAME_TYPE_MANAGED_TO_NATIVE = 2,
18         FRAME_TYPE_SENTINEL = 3
19 } MonoStackFrameType;
20
21 typedef enum {
22         MONO_UNWIND_NONE = 0x0,
23         MONO_UNWIND_LOOKUP_IL_OFFSET = 0x1,
24         /* NOT signal safe */
25         MONO_UNWIND_LOOKUP_ACTUAL_METHOD = 0x2,
26         /*
27          * Store the locations where caller-saved registers are saved on the stack in
28          * frame->reg_locations. The pointer is only valid during the call to the unwind
29          * callback.
30          */
31         MONO_UNWIND_REG_LOCATIONS = 0x4,
32         MONO_UNWIND_DEFAULT = MONO_UNWIND_LOOKUP_ACTUAL_METHOD,
33         MONO_UNWIND_SIGNAL_SAFE = MONO_UNWIND_NONE,
34         MONO_UNWIND_LOOKUP_ALL = MONO_UNWIND_LOOKUP_IL_OFFSET | MONO_UNWIND_LOOKUP_ACTUAL_METHOD,
35 } MonoUnwindOptions;
36
37 typedef struct {
38         MonoStackFrameType type;
39         /* 
40          * For FRAME_TYPE_MANAGED, otherwise NULL.
41          */
42         MonoJitInfo *ji;
43         /*
44          * Same as ji->method.
45          */
46         MonoMethod *method;
47         /*
48          * If ji->method is a gshared method, this is the actual method instance.
49          * This is only filled if lookup for actual method was requested (MONO_UNWIND_LOOKUP_ACTUAL_METHOD)
50          */
51         MonoMethod *actual_method;
52         /* The domain containing the code executed by this frame */
53         MonoDomain *domain;
54         gboolean managed;
55         int native_offset;
56         /*
57          * IL offset of this frame.
58          * Only available if the runtime have debugging enabled (--debug switch) and 
59          *  il offset resultion was requested (MONO_UNWIND_LOOKUP_IL_OFFSET)
60          */
61         int il_offset;
62
63         /*The next fields are only usefull for the jit*/
64         gpointer lmf;
65         guint32 unwind_info_len;
66         guint8 *unwind_info;
67
68         mgreg_t **reg_locations;
69 } MonoStackFrameInfo;
70
71 /*Index into MonoThreadState::unwind_data. */
72 enum {
73         MONO_UNWIND_DATA_DOMAIN,
74         MONO_UNWIND_DATA_LMF,
75         MONO_UNWIND_DATA_JIT_TLS,       
76 };
77
78 /*
79  * This structs holds all information needed to unwind the stack
80  * of a thread.
81  */
82 typedef struct {
83         MonoContext ctx;
84         gpointer unwind_data [3]; /*right now: domain, lmf and jit_tls*/
85         gboolean valid;
86 } MonoThreadUnwindState;
87
88
89 #endif