pub const CommonInformationEntry = struct version: u8format: Formataddr_size_bytes: u8In version 4, CIEs can specify the address size used in the CIE and associated FDEs. This value must be used only to parse associated FDEs in FrameDescriptionEntry.parse.
segment_selector_size: u8Always 0 for versions which do not specify this (currently all versions other than 4).
code_alignment_factor: u32data_alignment_factor: i32return_address_register: u8fde_pointer_enc: EH.PEis_signal_frame: boolaugmentation_kind: AugmentationKindinitial_instructions: []const u8last_row: ?struct { offset: u64, cfa: VirtualMachine.CfaRule, cols: []VirtualMachine.Column, }fn parse(format: Format, cie_bytes: []const u8, section: Section, default_addr_size_bytes: u8) !CommonInformationEntryThis function expects to read the CIE starting with the version field. The returned struct references memory backed by cie_bytes.
length_offset specifies the offset of this CIE's length field in the .eh_frame / .debug_frame section.
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418pub const CommonInformationEntry = struct {
version: u8,
format: Format,
/// In version 4, CIEs can specify the address size used in the CIE and associated FDEs.
/// This value must be used *only* to parse associated FDEs in `FrameDescriptionEntry.parse`.
addr_size_bytes: u8,
/// Always 0 for versions which do not specify this (currently all versions other than 4).
segment_selector_size: u8,
code_alignment_factor: u32,
data_alignment_factor: i32,
return_address_register: u8,
fde_pointer_enc: EH.PE,
is_signal_frame: bool,
augmentation_kind: AugmentationKind,
initial_instructions: []const u8,
last_row: ?struct {
offset: u64,
cfa: VirtualMachine.CfaRule,
cols: []VirtualMachine.Column,
},
pub const AugmentationKind = enum { none, gcc_eh, lsb_z };
/// This function expects to read the CIE starting with the version field.
/// The returned struct references memory backed by `cie_bytes`.
///
/// `length_offset` specifies the offset of this CIE's length field in the
/// .eh_frame / .debug_frame section.
fn parse(
format: Format,
cie_bytes: []const u8,
section: Section,
default_addr_size_bytes: u8,
) !CommonInformationEntry {
// We only read the data through this reader.
var r: Reader = .fixed(cie_bytes);
const version = try r.takeByte();
switch (section) {
.eh_frame => if (version != 1 and version != 3) return error.UnsupportedDwarfVersion,
.debug_frame => if (version != 4) return error.UnsupportedDwarfVersion,
}
const aug_str = try r.takeSentinel(0);
const aug_kind: AugmentationKind = aug: {
if (aug_str.len == 0) break :aug .none;
if (aug_str[0] == 'z') break :aug .lsb_z;
if (std.mem.eql(u8, aug_str, "eh")) break :aug .gcc_eh;
return error.UnsupportedAugmentation;
};
switch (aug_kind) {
.none => {}, // no extra data
.lsb_z => {}, // no extra data yet, but there is a bit later
.gcc_eh => try r.discardAll(default_addr_size_bytes), // unsupported data
}
const addr_size_bytes = if (version == 4) try r.takeByte() else default_addr_size_bytes;
const segment_selector_size: u8 = if (version == 4) try r.takeByte() else 0;
const code_alignment_factor = try r.takeLeb128(u32);
const data_alignment_factor = try r.takeLeb128(i32);
const return_address_register = if (version == 1) try r.takeByte() else try r.takeLeb128(u8);
// This is where LSB's augmentation might add some data.
const fde_pointer_enc: EH.PE, const is_signal_frame: bool = aug: {
const default_fde_pointer_enc: EH.PE = .{ .type = .absptr, .rel = .abs };
if (aug_kind != .lsb_z) break :aug .{ default_fde_pointer_enc, false };
const aug_data_len = try r.takeLeb128(u32);
var aug_data: Reader = .fixed(try r.take(aug_data_len));
var fde_pointer_enc: EH.PE = default_fde_pointer_enc;
var is_signal_frame = false;
for (aug_str[1..]) |byte| switch (byte) {
'L' => _ = try aug_data.takeByte(), // we ignore the LSDA pointer
'P' => {
const enc: EH.PE = @bitCast(try aug_data.takeByte());
const endian: Endian = .little; // irrelevant because we're discarding the value anyway
_ = try readEhPointerAbs(&aug_data, enc.type, addr_size_bytes, endian); // we ignore the personality routine; endianness is irrelevant since we're discarding
},
'R' => fde_pointer_enc = @bitCast(try aug_data.takeByte()),
'S' => is_signal_frame = true,
'B', 'G' => {},
else => return error.UnsupportedAugmentation,
};
break :aug .{ fde_pointer_enc, is_signal_frame };
};
return .{
.format = format,
.version = version,
.addr_size_bytes = addr_size_bytes,
.segment_selector_size = segment_selector_size,
.code_alignment_factor = code_alignment_factor,
.data_alignment_factor = data_alignment_factor,
.return_address_register = return_address_register,
.fde_pointer_enc = fde_pointer_enc,
.is_signal_frame = is_signal_frame,
.augmentation_kind = aug_kind,
.initial_instructions = r.buffered(),
.last_row = null,
};
}
}