@@ -18,45 +18,45 @@ namespace ILCompiler.Reflection.ReadyToRun
18
18
/// </summary>
19
19
public class DebugInfo
20
20
{
21
- private List < DebugInfoBoundsEntry > _boundsList = new List < DebugInfoBoundsEntry > ( ) ;
22
- private List < NativeVarInfo > _variablesList = new List < NativeVarInfo > ( ) ;
21
+ private readonly ReadyToRunReader _readyToRunReader ;
22
+ private readonly int _offset ;
23
+ private List < DebugInfoBoundsEntry > _boundsList ;
24
+ private List < NativeVarInfo > _variablesList ;
23
25
private Machine _machine ;
24
26
25
- public DebugInfo ( byte [ ] image , int offset , Machine machine )
27
+ public DebugInfo ( ReadyToRunReader readyToRunReader , int offset )
26
28
{
27
- _machine = machine ;
28
-
29
- // Get the id of the runtime function from the NativeArray
30
- uint lookback = 0 ;
31
- uint debugInfoOffset = NativeReader . DecodeUnsigned ( image , ( uint ) offset , ref lookback ) ;
29
+ this . _readyToRunReader = readyToRunReader ;
30
+ this . _offset = offset ;
31
+ }
32
32
33
- if ( lookback != 0 )
33
+ public List < DebugInfoBoundsEntry > BoundsList
34
+ {
35
+ get
34
36
{
35
- System . Diagnostics . Debug . Assert ( 0 < lookback && lookback < offset ) ;
36
- debugInfoOffset = ( uint ) offset - lookback ;
37
+ EnsureInitialized ( ) ;
38
+ return _boundsList ;
37
39
}
40
+ }
38
41
39
- NibbleReader reader = new NibbleReader ( image , ( int ) debugInfoOffset ) ;
40
- uint boundsByteCount = reader . ReadUInt ( ) ;
41
- uint variablesByteCount = reader . ReadUInt ( ) ;
42
- int boundsOffset = reader . GetNextByteOffset ( ) ;
43
- int variablesOffset = ( int ) ( boundsOffset + boundsByteCount ) ;
44
-
45
- if ( boundsByteCount > 0 )
42
+ public List < NativeVarInfo > VariablesList
43
+ {
44
+ get
46
45
{
47
- ParseBounds ( image , boundsOffset ) ;
46
+ EnsureInitialized ( ) ;
47
+ return _variablesList ;
48
48
}
49
+ }
49
50
50
- if ( variablesByteCount > 0 )
51
+ public Machine Machine
52
+ {
53
+ get
51
54
{
52
- ParseNativeVarInfo ( image , variablesOffset ) ;
55
+ EnsureInitialized ( ) ;
56
+ return _machine ;
53
57
}
54
58
}
55
59
56
- public List < DebugInfoBoundsEntry > BoundsList => _boundsList ;
57
- public List < NativeVarInfo > VariablesList => _variablesList ;
58
- public Machine Machine => _machine ;
59
-
60
60
/// <summary>
61
61
/// Convert a register number in debug info into a machine-specific register
62
62
/// </summary>
@@ -77,6 +77,46 @@ public static string GetPlatformSpecificRegister(Machine machine, int regnum)
77
77
}
78
78
}
79
79
80
+ private void EnsureInitialized ( )
81
+ {
82
+ if ( _boundsList != null )
83
+ {
84
+ return ;
85
+ }
86
+ int offset = _offset ;
87
+ _boundsList = new List < DebugInfoBoundsEntry > ( ) ;
88
+ _variablesList = new List < NativeVarInfo > ( ) ;
89
+ Machine machine = _readyToRunReader . Machine ;
90
+ byte [ ] image = _readyToRunReader . Image ;
91
+ _machine = machine ;
92
+
93
+ // Get the id of the runtime function from the NativeArray
94
+ uint lookback = 0 ;
95
+ uint debugInfoOffset = NativeReader . DecodeUnsigned ( image , ( uint ) offset , ref lookback ) ;
96
+
97
+ if ( lookback != 0 )
98
+ {
99
+ System . Diagnostics . Debug . Assert ( 0 < lookback && lookback < offset ) ;
100
+ debugInfoOffset = ( uint ) offset - lookback ;
101
+ }
102
+
103
+ NibbleReader reader = new NibbleReader ( image , ( int ) debugInfoOffset ) ;
104
+ uint boundsByteCount = reader . ReadUInt ( ) ;
105
+ uint variablesByteCount = reader . ReadUInt ( ) ;
106
+ int boundsOffset = reader . GetNextByteOffset ( ) ;
107
+ int variablesOffset = ( int ) ( boundsOffset + boundsByteCount ) ;
108
+
109
+ if ( boundsByteCount > 0 )
110
+ {
111
+ ParseBounds ( image , boundsOffset ) ;
112
+ }
113
+
114
+ if ( variablesByteCount > 0 )
115
+ {
116
+ ParseNativeVarInfo ( image , variablesOffset ) ;
117
+ }
118
+ }
119
+
80
120
private void ParseBounds ( byte [ ] image , int offset )
81
121
{
82
122
// Bounds info contains (Native Offset, IL Offset, flags)
0 commit comments