dwarves: Check if a member type wasn't found and avoid a NULL deref
This dodges a SEGFAULT at type__check_structs_at_unnatural_alignments()
so that we can finish processing, give the warnings and produce as much
as we can:
$ pahole examples/fortran95/derived-type.debug
die__process_unit: DW_TAG_string_type (0x12) @ <0x122> not handled!
namespace__recode_dwarf_types: couldn't find 0x122 type for 0x116 (member)!
struct bar {
integer(kind=4) c; /* 0 4 */
real(kind=4) d; /* 4 4 */
/* size: 8, cachelines: 1, members: 2 */
/* last cacheline: 8 bytes */
};
struct foo {
real(kind=4) a; /* 0 4 */
struct bar x; /* 4 8 */
<ERROR(__class__fprintf:1519): 0 not found!>
/* size: 20, cachelines: 1, members: 3 */
/* padding: 8 */
/* last cacheline: 20 bytes */
};
$
Reported-by: Tom de Vries
Bugtracker: https://github.com/acmel/dwarves/issues/9
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
diff --git a/dwarves.c b/dwarves.c
index 5d07641..90d4229 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -1488,6 +1488,13 @@
type__for_each_member(type, member) {
struct tag *member_type = tag__strip_typedefs_and_modifiers(&member->tag, cu);
+ if (member_type == NULL) {
+ // just be conservative and ignore
+ // Found first when a FORTRAN95 DWARF file was processed
+ // and the DW_TAG_string_type wasn't yet supported
+ continue;
+ }
+
if (!tag__is_struct(member_type))
continue;