StructType --> DICompositeType?

Is there a more convenient way to obtain a DIType given a Type than matching up the strings for the names?

For example, given:

struct S {
int x, y;
} s;

void foo(S *a) {
a->x = 0;
a->y = 1;
}

There are DIType nodes for the struct Type:

!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: “S”, file: !3, line: 1, size: 64, flags: DIFlagTypePassByValue, elements: !7, identifier: “_ZTS1S”)
!7 = !{!8, !10}
!8 = !DIDerivedType(tag: DW_TAG_member, name: “x”, scope: !6, file: !3, line: 2, baseType: !9, size: 32)
!9 = !DIBasicType(name: “int”, size: 32, encoding: DW_ATE_signed)
!10 = !DIDerivedType(tag: DW_TAG_member, name: “y”, scope: !6, file: !3, line: 2, baseType: !9, size: 32, offset: 32)

but given just the StructType for S there is no direct way to get to the DICompositeType. I’ve made something work by prescanning all the DITypes in my Module and creating a map that uses type names as the key, being careful to strip “struct.” prefixes and maintain scoping for nested structs (e.g., S1::S2), which works, but seems awfully complicated to need to do.

Seems like StructType should have a getMetaData() function, but I don’t see one.

-Troy

They aren’t directly tied together, as a type by its lonesome isn’t all that interesting to either compilers or debuggers.

But for example a global variable has a link to its DIGlobalVariable, which has a link to its DIType, and so you can associate the variable’s Type with a DIType that way.

–paulr

Right, a GlobalVariable actually has interesting debug metadata attached, but if one is dealing with the target type of a pointer operand of a GEP that’s accessing a structure field, then tracing that back to something with debug metadata is nontrivial. It may not be a GlobalVariable.

-Troy

struct types and DITypes aren’t 1:1 - the same struct type might be used for many DITypes and a single variable (with a single DIType) might be described by multiple different pieces of memory/registers with different struct types throughout its lifetime.

The nontrivial mapping from debug info to IR is the only real mapping, unfortunately. There’s no shortcut.

  • Dave