This kind of indirect form is generated by some ARM compilers. A temporary workaround might be: Dwarf_Attribute *attr = dwarf_attr_integrate(die, DW_AT_type, &attr_mem); if (attr != NULL) { unsigned int whatform = dwarf_whatform(attr); while(whatform == DW_FORM_indirect) { uint64_t val; const unsigned char *p = (const unsigned char *) attr->valp; get_uleb128_unchecked(val, p); whatform = (unsigned int) val; attr_mem.form = whatform; attr_mem.valp = (void *) p; } Dwarf_Die *type = dwarf_formref_die(attr, type_die); ... However, this method is rather ugly, because it needs the internal function get_uleb128_unchecked().
I don't believe I have ever seen a DWARF producer that uses DW_FORM_indirect, I wouldn't be surprised if other libdw function don't handle it correctly too. Do you have an example file that shows DW_FORM_indirect being used? What producer generated it?
Unfortunately I cannot provide the example file (due to legal restrictions), but I can tell that the producer is the following: "ARM C/C++ Compiler, 5.03 [Build 76]" The machine is (obviously) ARM. Here someone already mentioned the problem: http://lists.gnu.org/archive/html/bug-gdb/2000-11/msg00009.html
As with your other bug without at least some example DWARF files this will be somewhat hard to support. I think I know what would be needed, but without actual testcases it will be hard to get right.
This was implemented by: commit d63b26b8d21fb554049789290cd245cbe0446735 Author: Omar Sandoval <osandov@fb.com> Date: Fri Apr 23 16:36:15 2021 -0700 libdw: handle DW_FORM_indirect when reading attributes Whenever we encounter an attribute with DW_FORM_indirect, we need to read its true form from the DIE data. Then, we can continue normally. This adds support to the most obvious places: __libdw_find_attr() and dwarf_getattrs(). There may be more places that need to be updated. I encountered this when inspecting a file that was processed by our BOLT tool: https://github.com/facebookincubator/BOLT. This also adds a couple of test cases using a file generated by that tool. Signed-off-by: Omar Sandoval <osandov@fb.com>