[前][次][番号順一覧][スレッド一覧]

ruby-changes:52795

From: naruse <ko1@a...>
Date: Fri, 12 Oct 2018 08:55:52 +0900 (JST)
Subject: [ruby-changes:52795] naruse:r65007 (trunk): Show backtrace with .debug_info

naruse	2018-10-12 08:55:44 +0900 (Fri, 12 Oct 2018)

  New Revision: 65007

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65007

  Log:
    Show backtrace with .debug_info

  Modified files:
    trunk/addr2line.c
Index: addr2line.c
===================================================================
--- addr2line.c	(revision 65006)
+++ addr2line.c	(revision 65007)
@@ -113,7 +113,7 @@ void *alloca(); https://github.com/ruby/ruby/blob/trunk/addr2line.c#L113
 
 PRINTF_ARGS(static int kprintf(const char *fmt, ...), 1, 2);
 
-typedef struct {
+typedef struct line_info {
     const char *dirname;
     const char *filename;
     const char *path; /* object path */
@@ -122,6 +122,8 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/addr2line.c#L122
     uintptr_t base_addr;
     uintptr_t saddr;
     const char *sname; /* function name */
+
+    struct line_info *next;
 } line_info_t;
 typedef struct obj_info obj_info_t;
 struct obj_info {
@@ -194,8 +196,7 @@ get_nth_dirname(unsigned long dir, char https://github.com/ruby/ruby/blob/trunk/addr2line.c#L196
 }
 
 static void
-fill_filename(int file, char *include_directories, char *filenames,
-	      line_info_t *line)
+fill_filename(int file, char *include_directories, char *filenames, line_info_t *line)
 {
     int i;
     char *p = filenames;
@@ -522,11 +523,18 @@ fail: https://github.com/ruby/ruby/blob/trunk/addr2line.c#L523
 
 void hexdump0(const unsigned char *p, size_t n) {
     size_t i;
+    fprintf(stderr, "     0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F\n");
     for (i=0; i < n; i++){
-        if ((i & 15) != 15) {
-            fprintf(stderr, "%02X ", p[i]);
-        } else {
+        switch (i & 15) {
+          case 0:
+            fprintf(stderr, "%02zd: %02X ", i/16, p[i]);
+            break;
+          case 15:
             fprintf(stderr, "%02X\n", p[i]);
+            break;
+          default:
+            fprintf(stderr, "%02X ", p[i]);
+            break;
         }
     }
     if ((i & 15) != 15) {
@@ -535,200 +543,214 @@ void hexdump0(const unsigned char *p, si https://github.com/ruby/ruby/blob/trunk/addr2line.c#L543
 }
 #define hexdump(p,n) hexdump0((const unsigned char *)p, n)
 
+enum
+{
+    DW_TAG_inlined_subroutine = 0x1d,
+    DW_TAG_subprogram = 0x2e,
+};
+
 /* Attributes encodings */
 enum
 {
-  DW_AT_sibling = 0x01,
-  DW_AT_location = 0x02,
-  DW_AT_name = 0x03,
-  /* Reserved 0x04 */
-  /* Reserved 0x05 */
-  /* Reserved 0x06 */
-  /* Reserved 0x07 */
-  /* Reserved 0x08 */
-  DW_AT_ordering = 0x09,
-  /* Reserved 0x0a */
-  DW_AT_byte_size = 0x0b,
-  /* Reserved 0x0c */
-  DW_AT_bit_size = 0x0d,
-  /* Reserved 0x0e */
-  /* Reserved 0x0f */
-  DW_AT_stmt_list = 0x10,
-  DW_AT_low_pc = 0x11,
-  DW_AT_high_pc = 0x12,
-  DW_AT_language = 0x13,
-  /* Reserved 0x14 */
-  DW_AT_discr = 0x15,
-  DW_AT_discr_value = 0x16,
-  DW_AT_visibility = 0x17,
-  DW_AT_import = 0x18,
-  DW_AT_string_length = 0x19,
-  DW_AT_common_reference = 0x1a,
-  DW_AT_comp_dir = 0x1b,
-  DW_AT_const_value = 0x1c,
-  DW_AT_containing_type = 0x1d,
-  DW_AT_default_value = 0x1e,
-  /* Reserved 0x1f */
-  DW_AT_inline = 0x20,
-  DW_AT_is_optional = 0x21,
-  DW_AT_lower_bound = 0x22,
-  /* Reserved 0x23 */
-  /* Reserved 0x24 */
-  DW_AT_producer = 0x25,
-  /* Reserved 0x26 */
-  DW_AT_prototyped = 0x27,
-  /* Reserved 0x28 */
-  /* Reserved 0x29 */
-  DW_AT_return_addr = 0x2a,
-  /* Reserved 0x2b */
-  DW_AT_start_scope = 0x2c,
-  /* Reserved 0x2d */
-  DW_AT_bit_stride = 0x2e,
-  DW_AT_upper_bound = 0x2f,
-  /* Reserved 0x30 */
-  DW_AT_abstract_origin = 0x31,
-  DW_AT_accessibility = 0x32,
-  DW_AT_address_class = 0x33,
-  DW_AT_artificial = 0x34,
-  DW_AT_base_types = 0x35,
-  DW_AT_calling_convention = 0x36,
-  DW_AT_count = 0x37,
-  DW_AT_data_member_location = 0x38,
-  DW_AT_decl_column = 0x39,
-  DW_AT_decl_file = 0x3a,
-  DW_AT_decl_line = 0x3b,
-  DW_AT_declaration = 0x3c,
-  DW_AT_discr_list = 0x3d,
-  DW_AT_encoding = 0x3e,
-  DW_AT_external = 0x3f,
-  DW_AT_frame_base = 0x40,
-  DW_AT_friend = 0x41,
-  DW_AT_identifier_case = 0x42,
-  /* Reserved 0x43 */
-  DW_AT_namelist_item = 0x44,
-  DW_AT_priority = 0x45,
-  DW_AT_segment = 0x46,
-  DW_AT_specification = 0x47,
-  DW_AT_static_link = 0x48,
-  DW_AT_type = 0x49,
-  DW_AT_use_location = 0x4a,
-  DW_AT_variable_parameter = 0x4b,
-  DW_AT_virtuality = 0x4c,
-  DW_AT_vtable_elem_location = 0x4d,
-  DW_AT_allocated = 0x4e,
-  DW_AT_associated = 0x4f,
-  DW_AT_data_location = 0x50,
-  DW_AT_byte_stride = 0x51,
-  DW_AT_entry_pc = 0x52,
-  DW_AT_use_UTF8 = 0x53,
-  DW_AT_extension = 0x54,
-  DW_AT_ranges = 0x55,
-  DW_AT_trampoline = 0x56,
-  DW_AT_call_column = 0x57,
-  DW_AT_call_file = 0x58,
-  DW_AT_call_line = 0x59,
-  DW_AT_description = 0x5a,
-  DW_AT_binary_scale = 0x5b,
-  DW_AT_decimal_scale = 0x5c,
-  DW_AT_small = 0x5d,
-  DW_AT_decimal_sign = 0x5e,
-  DW_AT_digit_count = 0x5f,
-  DW_AT_picture_string = 0x60,
-  DW_AT_mutable = 0x61,
-  DW_AT_threads_scaled = 0x62,
-  DW_AT_explicit = 0x63,
-  DW_AT_object_pointer = 0x64,
-  DW_AT_endianity = 0x65,
-  DW_AT_elemental = 0x66,
-  DW_AT_pure = 0x67,
-  DW_AT_recursive = 0x68,
-  DW_AT_signature = 0x69,
-  DW_AT_main_subprogram = 0x6a,
-  DW_AT_data_bit_offset = 0x6b,
-  DW_AT_const_expr = 0x6c,
-  DW_AT_enum_class = 0x6d,
-  DW_AT_linkage_name = 0x6e,
-  DW_AT_string_length_bit_size = 0x6f,
-  DW_AT_string_length_byte_size = 0x70,
-  DW_AT_rank = 0x71,
-  DW_AT_str_offsets_base = 0x72,
-  DW_AT_addr_base = 0x73,
-  DW_AT_rnglists_base = 0x74,
-  /* Reserved 0x75 */
-  DW_AT_dwo_name = 0x76,
-  DW_AT_reference = 0x77,
-  DW_AT_rvalue_reference = 0x78,
-  DW_AT_macros = 0x79,
-  DW_AT_call_all_calls = 0x7a,
-  DW_AT_call_all_source_calls = 0x7b,
-  DW_AT_call_all_tail_calls = 0x7c,
-  DW_AT_call_return_pc = 0x7d,
-  DW_AT_call_value = 0x7e,
-  DW_AT_call_origin = 0x7f,
-  DW_AT_call_parameter = 0x80,
-  DW_AT_call_pc = 0x81,
-  DW_AT_call_tail_call = 0x82,
-  DW_AT_call_target = 0x83,
-  DW_AT_call_target_clobbered = 0x84,
-  DW_AT_call_data_location = 0x85,
-  DW_AT_call_data_value = 0x86,
-  DW_AT_noreturn = 0x87,
-  DW_AT_alignment = 0x88,
-  DW_AT_export_symbols = 0x89,
-  DW_AT_deleted = 0x8a,
-  DW_AT_defaulted = 0x8b,
-  DW_AT_loclists_base = 0x8c,
-  DW_AT_lo_user = 0x2000,
-  DW_AT_hi_user = 0x3fff
+    DW_AT_sibling = 0x01,
+    DW_AT_location = 0x02,
+    DW_AT_name = 0x03,
+    /* Reserved 0x04 */
+    /* Reserved 0x05 */
+    /* Reserved 0x06 */
+    /* Reserved 0x07 */
+    /* Reserved 0x08 */
+    DW_AT_ordering = 0x09,
+    /* Reserved 0x0a */
+    DW_AT_byte_size = 0x0b,
+    /* Reserved 0x0c */
+    DW_AT_bit_size = 0x0d,
+    /* Reserved 0x0e */
+    /* Reserved 0x0f */
+    DW_AT_stmt_list = 0x10,
+    DW_AT_low_pc = 0x11,
+    DW_AT_high_pc = 0x12,
+    DW_AT_language = 0x13,
+    /* Reserved 0x14 */
+    DW_AT_discr = 0x15,
+    DW_AT_discr_value = 0x16,
+    DW_AT_visibility = 0x17,
+    DW_AT_import = 0x18,
+    DW_AT_string_length = 0x19,
+    DW_AT_common_reference = 0x1a,
+    DW_AT_comp_dir = 0x1b,
+    DW_AT_const_value = 0x1c,
+    DW_AT_containing_type = 0x1d,
+    DW_AT_default_value = 0x1e,
+    /* Reserved 0x1f */
+    DW_AT_inline = 0x20,
+    DW_AT_is_optional = 0x21,
+    DW_AT_lower_bound = 0x22,
+    /* Reserved 0x23 */
+    /* Reserved 0x24 */
+    DW_AT_producer = 0x25,
+    /* Reserved 0x26 */
+    DW_AT_prototyped = 0x27,
+    /* Reserved 0x28 */
+    /* Reserved 0x29 */
+    DW_AT_return_addr = 0x2a,
+    /* Reserved 0x2b */
+    DW_AT_start_scope = 0x2c,
+    /* Reserved 0x2d */
+    DW_AT_bit_stride = 0x2e,
+    DW_AT_upper_bound = 0x2f,
+    /* Reserved 0x30 */
+    DW_AT_abstract_origin = 0x31,
+    DW_AT_accessibility = 0x32,
+    DW_AT_address_class = 0x33,
+    DW_AT_artificial = 0x34,
+    DW_AT_base_types = 0x35,
+    DW_AT_calling_convention = 0x36,
+    DW_AT_count = 0x37,
+    DW_AT_data_member_location = 0x38,
+    DW_AT_decl_column = 0x39,
+    DW_AT_decl_file = 0x3a,
+    DW_AT_decl_line = 0x3b,
+    DW_AT_declaration = 0x3c,
+    DW_AT_discr_list = 0x3d,
+    DW_AT_encoding = 0x3e,
+    DW_AT_external = 0x3f,
+    DW_AT_frame_base = 0x40,
+    DW_AT_friend = 0x41,
+    DW_AT_identifier_case = 0x42,
+    /* Reserved 0x43 */
+    DW_AT_namelist_item = 0x44,
+    DW_AT_priority = 0x45,
+    DW_AT_segment = 0x46,
+    DW_AT_specification = 0x47,
+    DW_AT_static_link = 0x48,
+    DW_AT_type = 0x49,
+    DW_AT_use_location = 0x4a,
+    DW_AT_variable_parameter = 0x4b,
+    DW_AT_virtuality = 0x4c,
+    DW_AT_vtable_elem_location = 0x4d,
+    DW_AT_allocated = 0x4e,
+    DW_AT_associated = 0x4f,
+    DW_AT_data_location = 0x50,
+    DW_AT_byte_stride = 0x51,
+    DW_AT_entry_pc = 0x52,
+    DW_AT_use_UTF8 = 0x53,
+    DW_AT_extension = 0x54,
+    DW_AT_ranges = 0x55,
+    DW_AT_trampoline = 0x56,
+    DW_AT_call_column = 0x57,
+    DW_AT_call_file = 0x58,
+    DW_AT_call_line = 0x59,
+    DW_AT_description = 0x5a,
+    DW_AT_binary_scale = 0x5b,
+    DW_AT_decimal_scale = 0x5c,
+    DW_AT_small = 0x5d,
+    DW_AT_decimal_sign = 0x5e,
+    DW_AT_digit_count = 0x5f,
+    DW_AT_picture_string = 0x60,
+    DW_AT_mutable = 0x61,
+    DW_AT_threads_scaled = 0x62,
+    DW_AT_explicit = 0x63,
+    DW_AT_object_pointer = 0x64,
+    DW_AT_endianity = 0x65,
+    DW_AT_elemental = 0x66,
+    DW_AT_pure = 0x67,
+    DW_AT_recursive = 0x68,
+    DW_AT_signature = 0x69,
+    DW_AT_main_subprogram = 0x6a,
+    DW_AT_data_bit_offset = 0x6b,
+    DW_AT_const_expr = 0x6c,
+    DW_AT_enum_class = 0x6d,
+    DW_AT_linkage_name = 0x6e,
+    DW_AT_string_length_bit_size = 0x6f,
+    DW_AT_string_length_byte_size = 0x70,
+    DW_AT_rank = 0x71,
+    DW_AT_str_offsets_base = 0x72,
+    DW_AT_addr_base = 0x73,
+    DW_AT_rnglists_base = 0x74,
+    /* Reserved 0x75 */
+    DW_AT_dwo_name = 0x76,
+    DW_AT_reference = 0x77,
+    DW_AT_rvalue_reference = 0x78,
+    DW_AT_macros = 0x79,
+    DW_AT_call_all_calls = 0x7a,
+    DW_AT_call_all_source_calls = 0x7b,
+    DW_AT_call_all_tail_calls = 0x7c,
+    DW_AT_call_return_pc = 0x7d,
+    DW_AT_call_value = 0x7e,
+    DW_AT_call_origin = 0x7f,
+    DW_AT_call_parameter = 0x80,
+    DW_AT_call_pc = 0x81,
+    DW_AT_call_tail_call = 0x82,
+    DW_AT_call_target = 0x83,
+    DW_AT_call_target_clobbered = 0x84,
+    DW_AT_call_data_location = 0x85,
+    DW_AT_call_data_value = 0x86,
+    DW_AT_noreturn = 0x87,
+    DW_AT_alignment = 0x88,
+    DW_AT_export_symbols = 0x89,
+    DW_AT_deleted = 0x8a,
+    DW_AT_defaulted = 0x8b,
+    DW_AT_loclists_base = 0x8c,
+    DW_AT_lo_user = 0x2000,
+    DW_AT_hi_user = 0x3fff
 };
 
 /* Attribute form encodings */
 enum
 {
-  DW_FORM_addr = 0x01,
-  /* Reserved 0x02 */
-  DW_FORM_block2 = 0x03,
-  DW_FORM_block4 = 0x04,
-  DW_FORM_data2 = 0x05,
-  DW_FORM_data4 = 0x06,
-  DW_FORM_data8 = 0x07,
-  DW_FORM_string = 0x08,
-  DW_FORM_block = 0x09,
-  DW_FORM_block1 = 0x0a,
-  DW_FORM_data1 = 0x0b,
-  DW_FORM_flag = 0x0c,
-  DW_FORM_sdata = 0x0d,
-  DW_FORM_strp = 0x0e,
-  DW_FORM_udata = 0x0f,
-  DW_FORM_ref_addr = 0x10,
-  DW_FORM_ref1 = 0x11,
-  DW_FORM_ref2 = 0x12,
-  DW_FORM_ref4 = 0x13,
-  DW_FORM_ref8 = 0x14,
-  DW_FORM_ref_udata = 0x15,
-  DW_FORM_indirect = 0x16,
-  DW_FORM_sec_offset = 0x17,
-  DW_FORM_exprloc = 0x18,
-  DW_FORM_flag_present = 0x19,
-  DW_FORM_strx = 0x1a,
-  DW_FORM_addrx = 0x1b,
-  DW_FORM_ref_sup4 = 0x1c,
-  DW_FORM_strp_sup = 0x1d,
-  DW_FORM_data16 = 0x1e,
-  DW_FORM_line_strp = 0x1f,
-  DW_FORM_ref_sig8 = 0x20,
-  DW_FORM_implicit_const = 0x21,
-  DW_FORM_loclistx = 0x22,
-  DW_FORM_rnglistx = 0x23,
-  DW_FORM_ref_sup8 = 0x24,
-  DW_FORM_strx1 = 0x25,
-  DW_FORM_strx2 = 0x26,
-  DW_FORM_strx3 = 0x27,
-  DW_FORM_strx4 = 0x28,
-  DW_FORM_addrx1 = 0x29,
-  DW_FORM_addrx2 = 0x2a,
-  DW_FORM_addrx3 = 0x2b,
-  DW_FORM_addrx4 = 0x2c
+    DW_FORM_addr = 0x01,
+    /* Reserved 0x02 */
+    DW_FORM_block2 = 0x03,
+    DW_FORM_block4 = 0x04,
+    DW_FORM_data2 = 0x05,
+    DW_FORM_data4 = 0x06,
+    DW_FORM_data8 = 0x07,
+    DW_FORM_string = 0x08,
+    DW_FORM_block = 0x09,
+    DW_FORM_block1 = 0x0a,
+    DW_FORM_data1 = 0x0b,
+    DW_FORM_flag = 0x0c,
+    DW_FORM_sdata = 0x0d,
+    DW_FORM_strp = 0x0e,
+    DW_FORM_udata = 0x0f,
+    DW_FORM_ref_addr = 0x10,
+    DW_FORM_ref1 = 0x11,
+    DW_FORM_ref2 = 0x12,
+    DW_FORM_ref4 = 0x13,
+    DW_FORM_ref8 = 0x14,
+    DW_FORM_ref_udata = 0x15,
+    DW_FORM_indirect = 0x16,
+    DW_FORM_sec_offset = 0x17,
+    DW_FORM_exprloc = 0x18,
+    DW_FORM_flag_present = 0x19,
+    DW_FORM_strx = 0x1a,
+    DW_FORM_addrx = 0x1b,
+    DW_FORM_ref_sup4 = 0x1c,
+    DW_FORM_strp_sup = 0x1d,
+    DW_FORM_data16 = 0x1e,
+    DW_FORM_line_strp = 0x1f,
+    DW_FORM_ref_sig8 = 0x20,
+    DW_FORM_implicit_const = 0x21,
+    DW_FORM_loclistx = 0x22,
+    DW_FORM_rnglistx = 0x23,
+    DW_FORM_ref_sup8 = 0x24,
+    DW_FORM_strx1 = 0x25,
+    DW_FORM_strx2 = 0x26,
+    DW_FORM_strx3 = 0x27,
+    DW_FORM_strx4 = 0x28,
+    DW_FORM_addrx1 = 0x29,
+    DW_FORM_addrx2 = 0x2a,
+    DW_FORM_addrx3 = 0x2b,
+    DW_FORM_addrx4 = 0x2c
+};
+
+enum {
+    VAL_none = 0,
+    VAL_cstr = 1,
+    VAL_data = 2,
+    VAL_uint = 3,
+    VAL_int = 4
 };
 
 typedef struct {
@@ -747,25 +769,44 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/addr2line.c#L769
 } __attribute__((packed)) DW_CompilationUnitHeader64;
 
 typedef struct {
-    char *file;
+    ElfW(Shdr) *abbrev;
     ElfW(Shdr) *info;
+    ElfW(Shdr) *ranges;
+    ElfW(Shdr) *str;
+    ElfW(Shdr) *line;
+} dwarf_args;
+
+typedef struct {
+    dwarf_args *dwarf;
+    obj_info_t *obj;
+    char *file;
+    char *current_cu;
+    char *debug_line_cu_end;
+    char *debug_line_files;
+    char *debug_line_directories;
     char *p0;
     char *p;
     char *pend;
-    ElfW(Shdr) *abbrev;
     char *q0;
     char *q;
-    ElfW(Shdr) *str;
     int format; /* 32 or 64 */;
     uint8_t address_size;
     int level;
 } DebugInfoReader;
 
 typedef struct {
+    int tag;
+    int has_children;
+} DIE;
+
+typedef struct {
     union {
         char *ptr;
         uint64_t uint64;
+        int64_t int64;
     } as;
+    uint64_t at;
+    uint64_t form;
     size_t size;
     int type;
 } DebugInfoValue;
@@ -842,64 +883,107 @@ read_sleb128(DebugInfoReader *reader) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L883
     return sleb128(&reader->p);
 }
 
-static DebugInfoReader *
-debug_info_reader_new(char *file, ElfW(Shdr) *debug_info_shdr, ElfW(Shdr) *debug_abbrev_shdr, ElfW(Shdr) *debug_str_shdr)
+static void
+debug_info_reader_init(DebugInfoReader *reader, obj_info_t *obj, dwarf_args *dwarf)
 {
-    DebugInfoReader *p = malloc(sizeof(DebugInfoReader));
-    p->file = file;
-    p->info = debug_info_shdr;
-    p->abbrev = debug_abbrev_shdr;
-    p->str = debug_str_shdr;
-    p->p0 = p->p = p->file + debug_info_shdr->sh_offset;
-    p->pend = p->file + debug_info_shdr->sh_offset + debug_info_shdr->sh_size;
-    return p;
+    reader->file = obj->mapped;
+    reader->obj = obj;
+    reader->dwarf = dwarf;
+    reader->p0 = reader->p = reader->file + dwarf->info->sh_offset;
+    reader->pend = reader->file + dwarf->info->sh_offset + dwarf->info->sh_size;
+    reader->debug_line_cu_end = reader->file + dwarf->line->sh_offset;
+}
+
+static void
+di_read_debug_line_cu(DebugInfoReader *reader)
+{
+    char *p;
+    unsigned long unit_length;
+    unsigned int opcode_base;
+
+    p = reader->debug_line_cu_end;
+
+    unit_length = *(unsigned int *)p;
+    p += sizeof(unsigned int);
+    if (unit_length == 0xffffffff) {
+	unit_length = *(unsigned long *)p;
+	p += sizeof(unsigned long);
+    }
+
+    reader->debug_line_cu_end = p + unit_length;
+    p += 2;
+    p += sizeof(unsigned int);
+    p += 4;
+    opcode_base = *(unsigned char *)p++;
+
+    /* standard_opcode_lengths = (unsigned char *)p - 1; */
+    p += opcode_base - 1;
+
+    reader->debug_line_directories = p;
+
+    /* skip include directories */
+    while (*p) {
+	p = memchr(p, '\0', reader->debug_line_cu_end - p);
+	if (!p) {
+            fprintf(stderr, "Wrongly reached the end of Directory Table at %tx",
+                    reader->debug_line_directories - (reader->file + reader->dwarf->line->sh_offset));
+            abort();
+        }
+	p++;
+    }
+    p++;
+    reader->debug_line_files = p;
 }
 
+
 static void
-debug_info_reader_read_cu(DebugInfoReader *reader)
+di_read_cu(DebugInfoReader *reader)
 {
     DW_CompilationUnitHeader32 *hdr32 = (DW_CompilationUnitHeader32 *)reader->p;
+    reader->current_cu = reader->p;
     if (hdr32->unit_length == 0xffffffff) {
         DW_CompilationUnitHeader64 *hdr = (DW_CompilationUnitHeader64 *)hdr32;
         reader->p += 23;
-        reader->q0 = reader->file + reader->abbrev->sh_offset + hdr->debug_abbrev_offset;
+        reader->q0 = reader->file + reader->dwarf->abbrev->sh_offset + hdr->debug_abbrev_offset;
         reader->address_size = hdr->address_size;
         reader->format = 64;
     } else {
         DW_CompilationUnitHeader32 *hdr = hdr32;
         reader->p += 11;
-        reader->q0 = reader->file + reader->abbrev->sh_offset + hdr->debug_abbrev_offset;
+        reader->q0 = reader->file + reader->dwarf->abbrev->sh_offset + hdr->debug_abbrev_offset;
         reader->address_size = hdr->address_size;
         reader->format = 32;
     }
+    reader->level = 0;
+    di_read_debug_line_cu(reader);
 }
 
 static void
 set_uint_value(DebugInfoValue *v, uint64_t n)
 {
     v->as.uint64 = n;
-    v->type = 1;
+    v->type = VAL_uint;
 }
 
 static void
-set_sint_value(DebugInfoValue *v, int64_t n)
+set_int_value(DebugInfoValue *v, int64_t n)
 {
-    v->as.uint64 = (uint64_t)n;
-    v->type = 2;
+    v->as.int64 = n;
+    v->type = VAL_int;
 }
 
 static void
 set_cstr_value(DebugInfoValue *v, char *s)
 {
     v->as.ptr = s;
-    v->type = 3;
+    v->type = VAL_cstr;
 }
 
 static void
-set_bytes_value(DebugInfoValue *v, char *s)
+set_data_value(DebugInfoValue *v, char *s)
 {
     v->as.ptr = s;
-    v->type = 4;
+    v->type = VAL_data;
 }
 
 static void
@@ -907,7 +991,6 @@ debug_info_reader_read_value(DebugInfoRe https://github.com/ruby/ruby/blob/trunk/addr2line.c#L991
 {
     switch (form) {
       case DW_FORM_addr:
-        fprintf(stderr, "%d: %d\n", __LINE__, reader->address_size);
         if (reader->address_size == 4) {
             set_uint_value(v, read_uint32(&reader->p));
         } else if (reader->address_size == 8) {
@@ -919,12 +1002,12 @@ debug_info_reader_read_value(DebugInfoRe https://github.com/ruby/ruby/blob/trunk/addr2line.c#L1002
         break;
       case DW_FORM_block2:
         v->size = read_uint16(&reader->p);
-        set_bytes_value(v, reader->p);
+        set_data_value(v, reader->p);
         reader->p += v->size;
         break;
       case DW_FORM_block4:
         v->size = read_uint32(&reader->p);
-        set_bytes_value(v, reader->p);
+        set_data_value(v, reader->p);
         reader->p += v->size;
         break;
       case DW_FORM_data2:
@@ -943,12 +1026,12 @@ debug_info_reader_read_value(DebugInfoRe https://github.com/ruby/ruby/blob/trunk/addr2line.c#L1026
         break;
       case DW_FORM_block:
         v->size = uleb128(&reader->p);
-        set_bytes_value(v, reader->p);
+        set_data_value(v, reader->p);
         reader->p += v->size;
         break;
       case DW_FORM_block1:
         v->size = read_uint8(&reader->p);
-        set_bytes_value(v, reader->p);
+        set_data_value(v, reader->p);
         reader->p += v->size;
         break;
       case DW_FORM_data1:
@@ -958,10 +1041,10 @@ debug_info_reader_read_value(DebugInfoRe https://github.com/ruby/ruby/blob/trunk/addr2line.c#L1041
         set_uint_value(v, read_uint8(&reader->p));
         break;
       case DW_FORM_sdata:
-        set_sint_value(v, read_sleb128(reader));
+        set_int_value(v, read_sleb128(reader));
         break;
       case DW_FORM_strp:
-        set_cstr_value(v, reader->file + reader->str->sh_offset + read_uint(reader));
+        set_cstr_value(v, reader->file + reader->dwarf->str->sh_offset + read_uint(reader));
         break;
       case DW_FORM_udata:
         set_uint_value(v, read_uleb128(reader));
@@ -1000,8 +1083,7 @@ debug_info_reader_read_value(DebugInfoRe https://github.com/ruby/ruby/blob/trunk/a (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]