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