Skip to content

Commit

Permalink
[debug] Add line number information with Dwarf in elf executable (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
s123unny authored Aug 22, 2023
1 parent 6c560f6 commit 98595dd
Show file tree
Hide file tree
Showing 15 changed files with 904 additions and 64 deletions.
496 changes: 496 additions & 0 deletions aeneas/src/debug/Dwarf.v3

Large diffs are not rendered by default.

275 changes: 275 additions & 0 deletions aeneas/src/debug/DwarfConst.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@

component DW {
def DW_UT_compile = 1;

def DW_children_no = 0;
def DW_children_yes = 1;

def DW_AT_sibling: u32 = 0x01;
def DW_AT_location: u32 = 0x02;
def DW_AT_name: u32 = 0x03;
def DW_AT_ordering: u32 = 0x09;
def DW_AT_subscr_data: u32 = 0x0a;
def DW_AT_byte_size: u32 = 0x0b;
def DW_AT_bit_offset: u32 = 0x0c;
def DW_AT_bit_size: u32 = 0x0d;
def DW_AT_element_list: u32 = 0x0f;
def DW_AT_stmt_list: u32 = 0x10;
def DW_AT_low_pc: u32 = 0x11;
def DW_AT_high_pc: u32 = 0x12;
def DW_AT_language: u32 = 0x13;
def DW_AT_member: u32 = 0x14;
def DW_AT_discr: u32 = 0x15;
def DW_AT_discr_value: u32 = 0x16;
def DW_AT_visibility: u32 = 0x17;
def DW_AT_import: u32 = 0x18;
def DW_AT_string_length: u32 = 0x19;
def DW_AT_common_reference: u32 = 0x1a;
def DW_AT_comp_dir: u32 = 0x1b;
def DW_AT_const_value: u32 = 0x1c;
def DW_AT_containing_type: u32 = 0x1d;
def DW_AT_default_value: u32 = 0x1e;
def DW_AT_inline: u32 = 0x20;
def DW_AT_is_optional: u32 = 0x21;
def DW_AT_lower_bound: u32 = 0x22;
def DW_AT_producer: u32 = 0x25;
def DW_AT_prototyped: u32 = 0x27;
def DW_AT_return_addr: u32 = 0x2a;
def DW_AT_start_scope: u32 = 0x2c;
def DW_AT_bit_stride: u32 = 0x2e;
def DW_AT_upper_bound: u32 = 0x2f;
def DW_AT_abstract_origin: u32 = 0x31;
def DW_AT_accessibility: u32 = 0x32;
def DW_AT_address_class: u32 = 0x33;
def DW_AT_artificial: u32 = 0x34;
def DW_AT_base_types: u32 = 0x35;
def DW_AT_calling_convention: u32 = 0x36;
def DW_AT_count: u32 = 0x37;
def DW_AT_data_member_location: u32 = 0x38;
def DW_AT_decl_column: u32 = 0x39;
def DW_AT_decl_file: u32 = 0x3a;
def DW_AT_decl_line: u32 = 0x3b;
def DW_AT_declaration: u32 = 0x3c;
def DW_AT_discr_list: u32 = 0x3d;
def DW_AT_encoding: u32 = 0x3e;
def DW_AT_external: u32 = 0x3f;
def DW_AT_frame_base: u32 = 0x40;
def DW_AT_friend: u32 = 0x41;
def DW_AT_identifier_case: u32 = 0x42;
def DW_AT_macro_info: u32 = 0x43;
def DW_AT_namelist_item: u32 = 0x44;
def DW_AT_priority: u32 = 0x45;
def DW_AT_segment: u32 = 0x46;
def DW_AT_specification: u32 = 0x47;
def DW_AT_static_link: u32 = 0x48;
def DW_AT_type: u32 = 0x49;
def DW_AT_use_location: u32 = 0x4a;
def DW_AT_variable_parameter: u32 = 0x4b;
def DW_AT_virtuality: u32 = 0x4c;
def DW_AT_vtable_elem_location: u32 = 0x4d;
/* DWARF 3 values. */
def DW_AT_allocated: u32 = 0x4e;
def DW_AT_associated: u32 = 0x4f;
def DW_AT_data_location: u32 = 0x50;
def DW_AT_byte_stride: u32 = 0x51;
def DW_AT_entry_pc: u32 = 0x52;
def DW_AT_use_UTF8: u32 = 0x53;
def DW_AT_extension: u32 = 0x54;
def DW_AT_ranges: u32 = 0x55;
def DW_AT_trampoline: u32 = 0x56;
def DW_AT_call_column: u32 = 0x57;
def DW_AT_call_file: u32 = 0x58;
def DW_AT_call_line: u32 = 0x59;
def DW_AT_description: u32 = 0x5a;
def DW_AT_binary_scale: u32 = 0x5b;
def DW_AT_decimal_scale: u32 = 0x5c;
def DW_AT_small: u32 = 0x5d;
def DW_AT_decimal_sign: u32 = 0x5e;
def DW_AT_digit_count: u32 = 0x5f;
def DW_AT_picture_string: u32 = 0x60;
def DW_AT_mutable: u32 = 0x61;
def DW_AT_threads_scaled: u32 = 0x62;
def DW_AT_explicit: u32 = 0x63;
def DW_AT_object_pointer: u32 = 0x64;
def DW_AT_endianity: u32 = 0x65;
def DW_AT_elemental: u32 = 0x66;
def DW_AT_pure: u32 = 0x67;
def DW_AT_recursive: u32 = 0x68;
/* DWARF 4. */
def DW_AT_signature: u32 = 0x69;
def DW_AT_main_subprogram: u32 = 0x6a;
def DW_AT_data_bit_offset: u32 = 0x6b;
def DW_AT_const_expr: u32 = 0x6c;
def DW_AT_enum_class: u32 = 0x6d;
def DW_AT_linkage_name: u32 = 0x6e;
/* DWARF 5. */
def DW_AT_string_length_bit_size: u32 = 0x6f;
def DW_AT_string_length_byte_size: u32 = 0x70;
def DW_AT_rank: u32 = 0x71;
def DW_AT_str_offsets_base: u32 = 0x72;
def DW_AT_addr_base: u32 = 0x73;
def DW_AT_rnglists_base: u32 = 0x74;
def DW_AT_dwo_name: u32 = 0x76;
def DW_AT_reference: u32 = 0x77;
def DW_AT_rvalue_reference: u32 = 0x78;
def DW_AT_macros: u32 = 0x79;
def DW_AT_call_all_calls: u32 = 0x7a;
def DW_AT_call_all_source_calls: u32 = 0x7b;
def DW_AT_call_all_tail_calls: u32 = 0x7c;
def DW_AT_call_return_pc: u32 = 0x7d;
def DW_AT_call_value: u32 = 0x7e;
def DW_AT_call_origin: u32 = 0x7f;
def DW_AT_call_parameter: u32 = 0x80;
def DW_AT_call_pc: u32 = 0x81;
def DW_AT_call_tail_call: u32 = 0x82;
def DW_AT_call_target: u32 = 0x83;
def DW_AT_call_target_clobbered: u32 = 0x84;
def DW_AT_call_data_location: u32 = 0x85;
def DW_AT_call_data_value: u32 = 0x86;
def DW_AT_noreturn: u32 = 0x87;
def DW_AT_alignment: u32 = 0x88;
def DW_AT_export_symbols: u32 = 0x89;
def DW_AT_deleted: u32 = 0x8a;
def DW_AT_defaulted: u32 = 0x8b;
def DW_AT_loclists_base: u32 = 0x8c;

def DW_FORM_addr: u32 = 0x01;
def DW_FORM_block2: u32 = 0x03;
def DW_FORM_block4: u32 = 0x04;
def DW_FORM_data2: u32 = 0x05;
def DW_FORM_data4: u32 = 0x06;
def DW_FORM_data8: u32 = 0x07;
def DW_FORM_string: u32 = 0x08;
def DW_FORM_block: u32 = 0x09;
def DW_FORM_block1: u32 = 0x0a;
def DW_FORM_data1: u32 = 0x0b;
def DW_FORM_flag: u32 = 0x0c;
def DW_FORM_sdata: u32 = 0x0d;
def DW_FORM_strp: u32 = 0x0e;
def DW_FORM_udata: u32 = 0x0f;
def DW_FORM_ref_addr: u32 = 0x10;
def DW_FORM_ref1: u32 = 0x11;
def DW_FORM_ref2: u32 = 0x12;
def DW_FORM_ref4: u32 = 0x13;
def DW_FORM_ref8: u32 = 0x14;
def DW_FORM_ref_udata: u32 = 0x15;
def DW_FORM_indirect: u32 = 0x16;
/* DWARF 4. */
def DW_FORM_sec_offset: u32 = 0x17;
def DW_FORM_exprloc: u32 = 0x18;
def DW_FORM_flag_present: u32 = 0x19;
def DW_FORM_ref_sig8: u32 = 0x20;
/* DWARF 5. */
def DW_FORM_strx: u32 = 0x1a;
def DW_FORM_addrx: u32 = 0x1b;
def DW_FORM_ref_sup4: u32 = 0x1c;
def DW_FORM_strp_sup: u32 = 0x1d;
def DW_FORM_data16: u32 = 0x1e;
def DW_FORM_line_strp: u32 = 0x1f;
def DW_FORM_implicit_const: u32 = 0x21;
def DW_FORM_loclistx: u32 = 0x22;
def DW_FORM_rnglistx: u32 = 0x23;
def DW_FORM_ref_sup8: u32 = 0x24;
def DW_FORM_strx1: u32 = 0x25;
def DW_FORM_strx2: u32 = 0x26;
def DW_FORM_strx3: u32 = 0x27;
def DW_FORM_strx4: u32 = 0x28;
def DW_FORM_addrx1: u32 = 0x29;
def DW_FORM_addrx2: u32 = 0x2a;
def DW_FORM_addrx3: u32 = 0x2b;
def DW_FORM_addrx4: u32 = 0x2c;

def DW_TAG_array_type: u32 = 0x01;
def DW_TAG_class_type: u32 = 0x02;
def DW_TAG_entry_point: u32 = 0x03;
def DW_TAG_enumeration_type: u32 = 0x04;
def DW_TAG_formal_parameter: u32 = 0x05;
def DW_TAG_imported_declaration: u32 = 0x08;
def DW_TAG_label: u32 = 0x0a;
def DW_TAG_lexical_block: u32 = 0x0b;
def DW_TAG_member: u32 = 0x0d;
def DW_TAG_pointer_type: u32 = 0x0f;
def DW_TAG_reference_type: u32 = 0x10;
def DW_TAG_compile_unit: u32 = 0x11;
def DW_TAG_string_type: u32 = 0x12;
def DW_TAG_structure_type: u32 = 0x13;
def DW_TAG_subroutine_type: u32 = 0x15;
def DW_TAG_typedef: u32 = 0x16;
def DW_TAG_union_type: u32 = 0x17;
def DW_TAG_unspecified_parameters: u32 = 0x18;
def DW_TAG_variant: u32 = 0x19;
def DW_TAG_common_block: u32 = 0x1a;
def DW_TAG_common_inclusion: u32 = 0x1b;
def DW_TAG_inheritance: u32 = 0x1c;
def DW_TAG_inlined_subroutine: u32 = 0x1d;
def DW_TAG_module: u32 = 0x1e;
def DW_TAG_ptr_to_member_type: u32 = 0x1f;
def DW_TAG_set_type: u32 = 0x20;
def DW_TAG_subrange_type: u32 = 0x21;
def DW_TAG_with_stmt: u32 = 0x22;
def DW_TAG_access_declaration: u32 = 0x23;
def DW_TAG_base_type: u32 = 0x24;
def DW_TAG_catch_block: u32 = 0x25;
def DW_TAG_const_type: u32 = 0x26;
def DW_TAG_constant: u32 = 0x27;
def DW_TAG_enumerator: u32 = 0x28;
def DW_TAG_file_type: u32 = 0x29;
def DW_TAG_friend: u32 = 0x2a;
def DW_TAG_namelist: u32 = 0x2b;
def DW_TAG_namelist_item: u32 = 0x2c;
def DW_TAG_packed_type: u32 = 0x2d;
def DW_TAG_subprogram: u32 = 0x2e;
def DW_TAG_template_type_param: u32 = 0x2f;
def DW_TAG_template_value_param: u32 = 0x30;
def DW_TAG_thrown_type: u32 = 0x31;
def DW_TAG_try_block: u32 = 0x32;
def DW_TAG_variant_part: u32 = 0x33;
def DW_TAG_variable: u32 = 0x34;
def DW_TAG_volatile_type: u32 = 0x35;
/* DWARF 3. */
def DW_TAG_dwarf_procedure: u32 = 0x36;
def DW_TAG_restrict_type: u32 = 0x37;
def DW_TAG_interface_type: u32 = 0x38;
def DW_TAG_namespace: u32 = 0x39;
def DW_TAG_imported_module: u32 = 0x3a;
def DW_TAG_unspecified_type: u32 = 0x3b;
def DW_TAG_partial_unit: u32 = 0x3c;
def DW_TAG_imported_unit: u32 = 0x3d;
def DW_TAG_condition: u32 = 0x3f;
def DW_TAG_shared_type: u32 = 0x40;
/* DWARF 4. */
def DW_TAG_type_unit: u32 = 0x41;
def DW_TAG_rvalue_reference_type: u32 = 0x42;
def DW_TAG_template_alias: u32 = 0x43;
/* DWARF 5. */
def DW_TAG_coarray_type: u32 = 0x44;
def DW_TAG_generic_subrange: u32 = 0x45;
def DW_TAG_dynamic_type: u32 = 0x46;
def DW_TAG_atomic_type: u32 = 0x47;
def DW_TAG_call_site: u32 = 0x48;
def DW_TAG_call_site_parameter: u32 = 0x49;
def DW_TAG_skeleton_unit: u32 = 0x4a;
def DW_TAG_immutable_type: u32 = 0x4b;

def DW_LNCT_path: u32 = 1;
def DW_LNCT_directory_index: u32 = 2;

def DW_LNS_extended_op = 0;
def DW_LNS_copy = 1;
def DW_LNS_advance_pc = 2;
def DW_LNS_advance_line = 3;
def DW_LNS_set_file = 4;
def DW_LNS_set_column = 5;
def DW_LNS_negate_stmt = 6;
def DW_LNS_set_basic_block = 7;
def DW_LNS_const_add_pc = 8;
def DW_LNS_fixed_advance_pc = 9;
def DW_LNS_set_prologue_end = 10;
def DW_LNS_set_epilogue_begin = 11;
def DW_LNS_set_isa = 12;

def DW_LNE_end_sequence = 1;
def DW_LNE_set_address = 2;
def DW_LNE_define_file = 3;
def DW_LNE_set_discriminator = 4;
}
13 changes: 13 additions & 0 deletions aeneas/src/mach/MachBackend.v3
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ component ArchInstrs {
def NUM_FLAGS: u5 = 4;

// block and SSA resolution instructions
def ARCH_SOURCELINE = -14;
def ARCH_GETSHADOWSTACKPTR = -13;
def ARCH_ALLOCSHADOWSTACK = -12;
def ARCH_SETSHADOWSTACKPTR = -11;
Expand Down Expand Up @@ -291,6 +292,7 @@ class SsaMachGen(context: SsaContext, mach: MachProgram, regSet: MachRegSet, w:
var frame: MachFrame;
var curBlock: SsaBlock;
var computingLiveness: bool;
var firstSourceLine: bool; // used by SsaX86_64Gen in assemble
var out: ArchInstrBuffer;
var rtsrc = if(mach.runtime != null, mach.runtime.src);

Expand All @@ -311,6 +313,7 @@ class SsaMachGen(context: SsaContext, mach: MachProgram, regSet: MachRegSet, w:
this.frame = frame;
this.curBlock = null;
this.computingLiveness = true;
this.firstSourceLine = true;
}
def generate(m: IrMethod, frame: MachFrame) {
context.enterMethod(m);
Expand Down Expand Up @@ -420,11 +423,16 @@ class SsaMachGen(context: SsaContext, mach: MachProgram, regSet: MachRegSet, w:
x: SsaReturn => visitReturn(block, x);
x: SsaSwitch => visitSwitch(block, x);
x: SsaThrow => visitThrow(block, x);
x: SsaCheckpoint => visitCheckpoint(x);
x: SsaNewVar => ;
x: SsaDeleteVar => ;
_ => context.fail("invalid instruction type");
}
}
def visitCheckpoint(x: SsaCheckpoint) {
var label = Label.new();
emit2(ArchInstrs.ARCH_SOURCELINE, op(Operand.Label(null, label)), op(Operand.ExSource(null, x.source)));
}
def emitPhiResolutionMoves(block: SsaBlock, edge: SsaCfEdge) {
var index = edge.desti;
// Add definitions of all phis.
Expand Down Expand Up @@ -1126,6 +1134,11 @@ class ArchInstrBuffer(codegen: SsaMachGen, prog: Program, regSet: MachRegSet) ex
ArchInstrs.ARCH_RESTORE => {
putNamedInstr(indent + 1, "restore", a);
}
ArchInstrs.ARCH_SOURCELINE => {
putIndent(indent + 1);
puts("sourceline ");
putOperand(a[1]); // ExSource
}
_ => {
indent = putArchInstr(indent + 1, i) - 1;
}
Expand Down
4 changes: 4 additions & 0 deletions aeneas/src/main/CLOptions.v3
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ component CLOptions {
"Specify an explicit name for the compilation results.");
def SYMBOLS = compileOpt.newBoolOption("symbols", false,
"Generate symbols in the compiled binary.");
def DWARF = compileOpt.newBoolOption("dwarf", false,
"Generate dwarf debug information in the compiled binary.");
def DWARF_CWD = compileOpt.newPathOption("dwarf-cwd", ".",
"Specify the current directory to be included in dwarf debug infomation.");
def RA = sharedOpt.newBoolOption("ra", false,
"Enable reachability analysis and normalization before running the program.");
def MA = sharedOpt.newBoolOption("ma", true,
Expand Down
3 changes: 3 additions & 0 deletions aeneas/src/main/Compiler.v3
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class Compiler(target: Target) {
var DisableNullChecks = flags.getUnsafe("DisableNullChecks");
var DisableTypeChecks = flags.getUnsafe("DisableTypeChecks");
var DisableLengthChecks = flags.getUnsafe("DisableLengthChecks");
// debug symbol setting
var DebugSymbol = false;

new() {
// default settings for normalization
Expand All @@ -116,6 +118,7 @@ class Compiler(target: Target) {
NormConfig.AnyRefOverflow = true;
// target configures the compiler only once
if (target != null) target.configureCompiler(this);
if (CLOptions.DEBUG.get() || (CLOptions.DWARF.get() && LinuxTarget.?(target))) DebugSymbol = true;
}

def getOutputFileName(fileName: string, ext: string) -> string {
Expand Down
2 changes: 1 addition & 1 deletion aeneas/src/main/Version.v3
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

// Updated by VCS scripts. DO NOT EDIT.
component Version {
def version: string = "III-7.1649";
def version: string = "III-7.1650";
var buildData: string;
}
Loading

0 comments on commit 98595dd

Please sign in to comment.