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