Merge pull request #799 from kebby/master
[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_SENTINEL = 3
23 } MonoStackFrameType;
24
25 typedef enum {
26         MONO_UNWIND_NONE = 0x0,
27         MONO_UNWIND_LOOKUP_IL_OFFSET = 0x1,
28         /* NOT signal safe */
29         MONO_UNWIND_LOOKUP_ACTUAL_METHOD = 0x2,
30         /*
31          * Store the locations where caller-saved registers are saved on the stack in
32          * frame->reg_locations. The pointer is only valid during the call to the unwind
33          * callback.
34          */
35         MONO_UNWIND_REG_LOCATIONS = 0x4,
36         MONO_UNWIND_DEFAULT = MONO_UNWIND_LOOKUP_ACTUAL_METHOD,
37         MONO_UNWIND_SIGNAL_SAFE = MONO_UNWIND_NONE,
38         MONO_UNWIND_LOOKUP_ALL = MONO_UNWIND_LOOKUP_IL_OFFSET | MONO_UNWIND_LOOKUP_ACTUAL_METHOD,
39 } MonoUnwindOptions;
40
41 typedef struct {
42         MonoStackFrameType type;
43         /* 
44          * For FRAME_TYPE_MANAGED, otherwise NULL.
45          */
46         MonoJitInfo *ji;
47         /*
48          * Same as ji->method.
49          * Not valid if ASYNC_CONTEXT is true.
50          */
51         MonoMethod *method;
52         /*
53          * If ji->method is a gshared method, this is the actual method instance.
54          * This is only filled if lookup for actual method was requested (MONO_UNWIND_LOOKUP_ACTUAL_METHOD)
55          * Not valid if ASYNC_CONTEXT is true.
56          */
57         MonoMethod *actual_method;
58         /* The domain containing the code executed by this frame */
59         MonoDomain *domain;
60         gboolean managed;
61         /*
62          * Whenever this frame was loaded in async context.
63          */
64         gboolean async_context;
65         int native_offset;
66         /*
67          * IL offset of this frame.
68          * Only available if the runtime have debugging enabled (--debug switch) and 
69          *  il offset resultion was requested (MONO_UNWIND_LOOKUP_IL_OFFSET)
70          */
71         int il_offset;
72
73         /* The next fields are only useful for the jit */
74         gpointer lmf;
75         guint32 unwind_info_len;
76         guint8 *unwind_info;
77
78         mgreg_t **reg_locations;
79 } MonoStackFrameInfo;
80
81 /*Index into MonoThreadState::unwind_data. */
82 enum {
83         MONO_UNWIND_DATA_DOMAIN,
84         MONO_UNWIND_DATA_LMF,
85         MONO_UNWIND_DATA_JIT_TLS,       
86 };
87
88 /*
89  * This structs holds all information needed to unwind the stack
90  * of a thread.
91  */
92 typedef struct {
93         MonoContext ctx;
94         gpointer unwind_data [3]; /*right now: domain, lmf and jit_tls*/
95         gboolean valid;
96 } MonoThreadUnwindState;
97
98
99 #endif