1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//! Raw `MethodDebugInformation` table representation for Portable PDB format.
//!
//! This module provides the [`crate::metadata::tables::methoddebuginformation::raw::MethodDebugInformationRaw`] struct that represents
//! the binary format of `MethodDebugInformation` table entries as they appear in
//! the metadata tables stream. This is the low-level representation used during
//! the initial parsing phase, containing unresolved heap indices that enable efficient
//! batch processing of Portable PDB debugging metadata.
//!
//! # Architecture
//!
//! The raw implementation provides the foundation for Portable PDB debug information parsing:
//! - **Unresolved References**: Contains raw heap indices that require blob resolution
//! - **Memory Efficiency**: Minimal footprint during initial parsing phases
//! - **Binary Format**: Direct representation of ECMA-335 Portable PDB table structure
//! - **Batch Processing**: Optimized for parsing multiple debug entries efficiently
//!
//! # Binary Format
//!
//! Each `MethodDebugInformation` table row follows the Portable PDB specification:
//!
//! ```text
//! Offset | Size | Field | Description
//! -------|---------|----------------|------------------------------------------
//! 0x00 | 2-4 | Document | Simple index into Document table
//! 0x02 | 2-4 | SequencePoints | Blob heap index containing sequence data
//! ```
//!
//! Index sizes are determined by metadata header flags and table/heap sizes.
//!
//! # Sequence Points Encoding
//!
//! The sequence points blob contains compressed data that maps IL instruction offsets
//! to source code locations using a variable-length encoding scheme:
//! - **Delta Compression**: Offsets and positions are delta-encoded for efficiency
//! - **Variable Length**: Values use LEB128 encoding to minimize storage
//! - **Source Mapping**: Links IL instructions to specific line/column positions
//! - **Debugging Support**: Enables step-through debugging and stack trace resolution
//!
//! # Processing Pipeline
//!
//! 1. **Parsing**: Raw entries are read from metadata tables stream
//! 2. **Validation**: Document indices and blob indices are validated
//! 3. **Resolution**: Blob heap indices are resolved to actual sequence data
//! 4. **Conversion**: Raw entries are converted to owned representations
//! 5. **Integration**: Debug information is integrated with method definitions
//!
//! # Thread Safety
//!
//! All types in this module are thread-safe for concurrent read access:
//! - [`crate::metadata::tables::methoddebuginformation::raw::MethodDebugInformationRaw`] is [`std::marker::Send`] and [`std::marker::Sync`]
//! - Raw parsing operations can be performed concurrently
//! - Conversion methods are thread-safe with proper heap synchronization
//! - No shared mutable state during parsing operations
//!
//! # Integration
//!
//! This module integrates with:
//! - Method debug information owned types - Owned representation for runtime use
//! - [`crate::metadata::tables::document`] - Document table for source file references
//! - [`crate::metadata::streams::Blob`] - Blob heap for sequence points data resolution
//! - [`crate::metadata::method`] - Method definition association and debugging
use crate::;
use Arc;
/// Raw binary representation of a `MethodDebugInformation` table entry.
///
/// This structure matches the exact binary layout of `MethodDebugInformation` table
/// entries in the metadata tables stream. All heap references remain as unresolved
/// indices that must be resolved through the appropriate heap during the conversion
/// to the owned [`crate::metadata::tables::MethodDebugInformation`] variant.
///
/// # Binary Format
///
/// Each `MethodDebugInformation` table entry consists of:
/// - **Document**: Simple index into Document table (0 = no associated document)
/// - **SequencePoints**: Blob heap index containing compressed sequence point data
///
/// The exact byte size depends on whether large heap indices are used, determined
/// by the heap size flags in the metadata header and table row counts.
///
/// # Heap Index Resolution
///
/// - **`document`**: Simple table index into Document table (0 = no document)
/// - **`sequence_points`**: Must be resolved through blob heap to get encoded sequence data
///
/// # Usage Patterns
///
/// ```rust,ignore
/// use dotscope::metadata::tables::methoddebuginformation::raw::MethodDebugInformationRaw;
/// use dotscope::metadata::streams::Blob;
///
/// # fn process_debug_entry(raw_entry: &MethodDebugInformationRaw, blobs: &Blob) -> dotscope::Result<()> {
/// // Check for associated document
/// if raw_entry.document != 0 {
/// println!("Method has source document: {}", raw_entry.document);
/// }
///
/// // Check for sequence points
/// if raw_entry.sequence_points != 0 {
/// let sequence_data = blobs.get(raw_entry.sequence_points as usize)?;
/// println!("Method has {} bytes of sequence data", sequence_data.len());
/// }
///
/// // Convert to owned representation
/// let owned = raw_entry.to_owned(blobs)?;
/// # Ok(())
/// # }
/// ```
///
/// # Thread Safety
///
/// [`MethodDebugInformationRaw`] is [`std::marker::Send`] and [`std::marker::Sync`] as it contains only primitive data types.
/// Instances can be safely shared across threads and accessed concurrently without synchronization.
///
/// # Reference
/// - [Portable PDB Format - `MethodDebugInformation` Table](https://github.com/dotnet/core/blob/main/Documentation/diagnostics/portable_pdb.md#methoddebuginformation-table-0x31)
/// - Table ID: 0x31
/// - Purpose: Associate methods with debugging information and source locations