diff --git a/main.cpp b/main.cpp index 5628667..745b34d 100644 --- a/main.cpp +++ b/main.cpp @@ -206,6 +206,20 @@ void parse_debuginfo_section(const void *file) p+= 8; fprintf(stdout, "\t%#x\n", addr_value); } break; + case DW_FORM_block2: // 0x03 + { + uint16_t length = *(uint16_t*)p; + p += 2; + fprintf(stdout, "\t%d byte sized data block\n", length); + p += length; + } break; + case DW_FORM_block4: // 0x04 + { + uint32_t length = *(uint32_t*)p; + p += 4; + fprintf(stdout, "\t%d byte sized data block\n", length); + p += length; + } break; case DW_FORM_data2: // 0x05 { uint16_t data = *(uint16_t*)p; @@ -218,7 +232,7 @@ void parse_debuginfo_section(const void *file) p += 4; fprintf(stdout, "\t%#x\n", data); } break; - case DW_FORM_data8: // 0x06 + case DW_FORM_data8: // 0x07 { uint64_t data = *(uint64_t*)p; p += 8; @@ -230,7 +244,22 @@ void parse_debuginfo_section(const void *file) fprintf(stdout, "\t%s\n", p); while (*p++); } break; - case DW_FORM_data1: // 0x13 + case DW_FORM_block: // 0x09 + { + uint64_t length = 0; + p += decode_leb128((uint8_t*)p, &length); + fprintf(stdout, "\t%d byte sized data block\n", length); + p += length; + while (*p++); + } break; + case DW_FORM_block1: // 0x0a + { + uint8_t length = *(uint8_t*)p; + fprintf(stdout, "\t%d byte sized data block\n", length); + p += length; + while (*p++); + } break; + case DW_FORM_data1: // 0x0b { uint8_t data = *(uint8_t*)p; p += 1; @@ -239,12 +268,83 @@ void parse_debuginfo_section(const void *file) else fprintf(stdout, "\t%#x\n", data); } break; - - case DW_FORM_ref8: + case DW_FORM_flag: // 0x0c { - uint64_t data = *(uint64_t*)p; + uint8_t value = *(uint8_t*)p; + p += 1; + fprintf(stdout, "\t%d\n", value); + } break; + case DW_FORM_sdata: // 0x0d + { + int64_t value; + p += decode_sleb128((uint8_t*)p, &value); + fprintf(stdout, "\t%d\n", value); + } break; + case DW_FORM_strp: // 0x0e + { + // TODO: 32 addresses + // read offset into .debug_str of desired string + uint64_t str_offset = *(uint64_t*)p; + p+= 8; + uint64_t section_offset = get_offset_of_section(file, ".debug_str"); + char *string = (char*)file + section_offset + str_offset; + fprintf(stdout, "\t%s\n", string); + } break; + case DW_FORM_udata: // 0x0f + { + uint64_t value; + p += decode_leb128((uint8_t*)p, &value); + fprintf(stdout, "\t%d\n", value); + } break; + case DW_FORM_ref_addr: // 0x10 + { + // TODO: dwarf32 + uint64_t offset = *(uint64_t*)p; p += 8; - fprintf(stdout, "\t%#x\n", data); + // TODO: fetch the actual value + fprintf(stdout, "\toffset %#x\n", offset); + } break; + case DW_FORM_ref1: // 0x11 + { + uint8_t offset = *(uint8_t*)p; + p += 1; + // TODO: fetch the actual value + fprintf(stdout, "\toffset %#x\n", offset); + } break; + case DW_FORM_ref2: // 0x12 + { + uint16_t offset = *(uint16_t*)p; + p += 2; + // TODO: fetch the actual value + fprintf(stdout, "\toffset %#x\n", offset); + } break; + case DW_FORM_ref4: // 0x13 + { + uint32_t offset = *(uint32_t*)p; + p += 4; + // TODO: fetch the actual value + fprintf(stdout, "\toffset %#x\n", offset); + } break; + case DW_FORM_ref8: // 0x14 + { + uint64_t offset = *(uint64_t*)p; + p += 8; + // TODO: fetch the actual value + fprintf(stdout, "\t%#x\n", offset); + } break; + case DW_FORM_ref_udata: // 0x15 + { + uint64_t offset; + p += decode_leb128((uint8_t*)p, &offset); + // TODO: fetch the actual value + fprintf(stdout, "\t%#x\n", offset); + } break; + case DW_FORM_indirect: // 0x16 + { + uint64_t form; + p += decode_leb128((uint8_t*)p, &form); + // TODO: fetch the actual value + fprintf(stdout, "\tTODO\n"); } break; case DW_FORM_sec_offset: // 0x17 { @@ -266,27 +366,23 @@ void parse_debuginfo_section(const void *file) p += length; fprintf(stdout, "(%d bytes data)\n", length); } break; - case DW_FORM_flag_present: + case DW_FORM_flag_present: // 0x19 { // Nothing to read here, flag_present just indicates that a flag is ON. We output '1' just like objdump does fprintf(stdout, "\t1\n"); } break; - case DW_FORM_implicit_const: + case DW_FORM_strx: // 0x1a + { + uint64_t offset; + p += decode_leb128((uint8_t*)p, &offset); + uint64_t section_offset = get_offset_of_section(file, ".debug_str_offsets"); + fprintf(stdout, "\t%s\n", (char*)file + section_offset + offset); + } break; + case DW_FORM_implicit_const: // 0x21 { // We already have the value, do not advance the pointer at all fprintf(stdout, "\t%#x\n", abbrev_table.specs[code-1][i].value); } break; - case DW_FORM_strp: // 0x0e - { - // TODO: 32 addresses - // read offset into .debug_str of desired string - uint64_t str_offset = *(uint64_t*)p; - p+= 8; - uint64_t section_offset = get_offset_of_section(file, ".debug_str"); - char *string = (char*)file + section_offset + str_offset; - fprintf(stdout, "\t%s\n", string); - } break; - case DW_FORM_line_strp: // 0x1f { // TODO: 32 addresses