ef51c4
--- a/addr2line.c
ef51c4
+++ b/addr2line.c
ef51c4
@@ -159,11 +159,12 @@
ef51c4
     struct dwarf_section debug_info;
ef51c4
     struct dwarf_section debug_line;
ef51c4
     struct dwarf_section debug_ranges;
ef51c4
+    struct dwarf_section debug_rnglists;
ef51c4
     struct dwarf_section debug_str;
ef51c4
     struct obj_info *next;
ef51c4
 } obj_info_t;
ef51c4
 
ef51c4
-#define DWARF_SECTION_COUNT 5
ef51c4
+#define DWARF_SECTION_COUNT 6
ef51c4
 
ef51c4
 static struct dwarf_section *
ef51c4
 obj_dwarf_section_at(obj_info_t *obj, int n)
ef51c4
@@ -173,6 +174,7 @@
ef51c4
         &obj->debug_info,
ef51c4
         &obj->debug_line,
ef51c4
         &obj->debug_ranges,
ef51c4
+        &obj->debug_rnglists,
ef51c4
         &obj->debug_str
ef51c4
     };
ef51c4
     if (n < 0 || DWARF_SECTION_COUNT <= n) {
ef51c4
@@ -411,7 +413,7 @@
ef51c4
 	    FILL_LINE();
ef51c4
 	    break;
ef51c4
 	case DW_LNS_advance_pc:
ef51c4
-	    a = uleb128((char **)&p);
ef51c4
+	    a = uleb128((char **)&p) * header.minimum_instruction_length;
ef51c4
 	    addr += a;
ef51c4
 	    break;
ef51c4
 	case DW_LNS_advance_line: {
ef51c4
@@ -450,7 +452,7 @@
ef51c4
 	    /* isa = (unsigned int)*/(void)uleb128((char **)&p);
ef51c4
 	    break;
ef51c4
 	case 0:
ef51c4
-	    a = *(unsigned char *)p++;
ef51c4
+	    a = uleb128((char **)&p);
ef51c4
 	    op = *p++;
ef51c4
 	    switch (op) {
ef51c4
 	    case DW_LNE_end_sequence:
ef51c4
@@ -807,6 +809,18 @@
ef51c4
     DW_FORM_addrx4 = 0x2c
ef51c4
 };
ef51c4
 
ef51c4
+/* Range list entry encodings */
ef51c4
+enum {
ef51c4
+    DW_RLE_end_of_list = 0x00,
ef51c4
+    DW_RLE_base_addressx = 0x01,
ef51c4
+    DW_RLE_startx_endx = 0x02,
ef51c4
+    DW_RLE_startx_length = 0x03,
ef51c4
+    DW_RLE_offset_pair = 0x04,
ef51c4
+    DW_RLE_base_address = 0x05,
ef51c4
+    DW_RLE_start_end = 0x06,
ef51c4
+    DW_RLE_start_length = 0x07
ef51c4
+};
ef51c4
+
ef51c4
 enum {
ef51c4
     VAL_none = 0,
ef51c4
     VAL_cstr = 1,
ef51c4
@@ -961,6 +975,23 @@
ef51c4
 }
ef51c4
 
ef51c4
 static void
ef51c4
+di_skip_die_attributes(char **p)
ef51c4
+{
ef51c4
+    for (;;) {
ef51c4
+        uint64_t at = uleb128(p);
ef51c4
+        uint64_t form = uleb128(p);
ef51c4
+        if (!at && !form) break;
ef51c4
+        switch (form) {
ef51c4
+          default:
ef51c4
+            break;
ef51c4
+          case DW_FORM_implicit_const:
ef51c4
+            sleb128(p);
ef51c4
+            break;
ef51c4
+        }
ef51c4
+    }
ef51c4
+}
ef51c4
+
ef51c4
+static void
ef51c4
 di_read_debug_abbrev_cu(DebugInfoReader *reader)
ef51c4
 {
ef51c4
     uint64_t prev = 0;
ef51c4
@@ -974,12 +1005,7 @@
ef51c4
         prev = abbrev_number;
ef51c4
         uleb128(&p); /* tag */
ef51c4
         p++; /* has_children */
ef51c4
-        /* skip content */
ef51c4
-        for (;;) {
ef51c4
-            uint64_t at = uleb128(&p);
ef51c4
-            uint64_t form = uleb128(&p);
ef51c4
-            if (!at && !form) break;
ef51c4
-        }
ef51c4
+        di_skip_die_attributes(&p);
ef51c4
     }
ef51c4
 }
ef51c4
 
ef51c4
@@ -1243,12 +1269,7 @@
ef51c4
     /* skip 255th record */
ef51c4
     uleb128(&p); /* tag */
ef51c4
     p++; /* has_children */
ef51c4
-    /* skip content */
ef51c4
-    for (;;) {
ef51c4
-        uint64_t at = uleb128(&p);
ef51c4
-        uint64_t form = uleb128(&p);
ef51c4
-        if (!at && !form) break;
ef51c4
-    }
ef51c4
+    di_skip_die_attributes(&p);
ef51c4
     for (uint64_t n = uleb128(&p); abbrev_number != n; n = uleb128(&p)) {
ef51c4
         if (n == 0) {
ef51c4
             fprintf(stderr,"%d: Abbrev Number %"PRId64" not found\n",__LINE__, abbrev_number);
ef51c4
@@ -1256,12 +1277,7 @@
ef51c4
         }
ef51c4
         uleb128(&p); /* tag */
ef51c4
         p++; /* has_children */
ef51c4
-        /* skip content */
ef51c4
-        for (;;) {
ef51c4
-            uint64_t at = uleb128(&p);
ef51c4
-            uint64_t form = uleb128(&p);
ef51c4
-            if (!at && !form) break;
ef51c4
-        }
ef51c4
+        di_skip_die_attributes(&p);
ef51c4
     }
ef51c4
     return p;
ef51c4
 }
ef51c4
@@ -1389,6 +1405,21 @@
ef51c4
     }
ef51c4
 }
ef51c4
 
ef51c4
+static uint64_t
ef51c4
+read_dw_form_addr(DebugInfoReader *reader, char **ptr)
ef51c4
+{
ef51c4
+    char *p = *ptr;
ef51c4
+    *ptr = p + reader->format;
ef51c4
+    if (reader->format == 4) {
ef51c4
+        return read_uint32(&p);
ef51c4
+    } else if (reader->format == 8) {
ef51c4
+        return read_uint64(&p);
ef51c4
+    } else {
ef51c4
+        fprintf(stderr,"unknown address_size:%d", reader->address_size);
ef51c4
+        abort();
ef51c4
+    }
ef51c4
+}
ef51c4
+
ef51c4
 static uintptr_t
ef51c4
 ranges_include(DebugInfoReader *reader, ranges_t *ptr, uint64_t addr)
ef51c4
 {
ef51c4
@@ -1402,8 +1433,50 @@
ef51c4
     }
ef51c4
     else if (ptr->ranges_set) {
ef51c4
         /* TODO: support base address selection entry */
ef51c4
-        char *p = reader->obj->debug_ranges.ptr + ptr->ranges;
ef51c4
+        char *p;
ef51c4
         uint64_t base = ptr->low_pc_set ? ptr->low_pc : reader->current_low_pc;
ef51c4
+        if (reader->obj->debug_rnglists.ptr) {
ef51c4
+            p = reader->obj->debug_rnglists.ptr + ptr->ranges;
ef51c4
+            for (;;) {
ef51c4
+                uint8_t rle = read_uint8(&p);
ef51c4
+                uintptr_t base_address = 0;
ef51c4
+                uintptr_t from, to;
ef51c4
+                if (rle == DW_RLE_end_of_list) break;
ef51c4
+                switch (rle) {
ef51c4
+                  case DW_RLE_base_addressx:
ef51c4
+                    uleb128(&p);
ef51c4
+                    break;
ef51c4
+                  case DW_RLE_startx_endx:
ef51c4
+                    uleb128(&p);
ef51c4
+                    uleb128(&p);
ef51c4
+                    break;
ef51c4
+                  case DW_RLE_startx_length:
ef51c4
+                    uleb128(&p);
ef51c4
+                    uleb128(&p);
ef51c4
+                    break;
ef51c4
+                  case DW_RLE_offset_pair:
ef51c4
+                    from = base_address + uleb128(&p);
ef51c4
+                    to = base_address + uleb128(&p);
ef51c4
+                    if (base + from <= addr && addr < base + to) {
ef51c4
+                        return from;
ef51c4
+                    }
ef51c4
+                    break;
ef51c4
+                  case DW_RLE_base_address:
ef51c4
+                    base_address = read_dw_form_addr(reader, &p);
ef51c4
+                    break;
ef51c4
+                  case DW_RLE_start_end:
ef51c4
+                    read_dw_form_addr(reader, &p);
ef51c4
+                    read_dw_form_addr(reader, &p);
ef51c4
+                    break;
ef51c4
+                  case DW_RLE_start_length:
ef51c4
+                    read_dw_form_addr(reader, &p);
ef51c4
+                    uleb128(&p);
ef51c4
+                    break;
ef51c4
+                }
ef51c4
+            }
ef51c4
+            return false;
ef51c4
+        }
ef51c4
+        p = reader->obj->debug_ranges.ptr + ptr->ranges;
ef51c4
         for (;;) {
ef51c4
             uintptr_t from = read_uintptr(&p);
ef51c4
             uintptr_t to = read_uintptr(&p);
ef51c4
@@ -1747,6 +1820,7 @@
ef51c4
                     ".debug_info",
ef51c4
                     ".debug_line",
ef51c4
                     ".debug_ranges",
ef51c4
+                    ".debug_rnglists",
ef51c4
                     ".debug_str"
ef51c4
                 };
ef51c4
 
ef51c4
@@ -2003,6 +2077,7 @@
ef51c4
                     "__debug_info",
ef51c4
                     "__debug_line",
ef51c4
                     "__debug_ranges",
ef51c4
+                    "__debug_rnglists",
ef51c4
                     "__debug_str"
ef51c4
                 };
ef51c4
                 struct LP(segment_command) *scmd = (struct LP(segment_command) *)lcmd;