Is there any way to get the corresponding metadata through type?

For example, there is the following code segment:

%hid35 = getelementptr inbounds %struct.hidraw, %struct.hidraw* %49, i32 0, i32 4, !dbg !42245
%50 = load %struct.hid_device*, %struct.hid_device** %hid35, align 8, !dbg !42245

I can use GetElementPtr.getResultElementType() to get struct.hid_device* type of %hid35, but how can I get get the corresponding DICompositeType metadata through this type?

!13709 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "hid_device", file: !31, line: 465, size: 58368, elements: !13710)

Or if I can get all the metadata of the module, and then search for the target metadata through traversal, but I can’t find a way to get all the metadata.

I don’t believe there’s a direct connection between the two – the type provides data layout information for optimisations during compilation, while the debug-info metadata provides declaration information, field names, line numbers and so forth.

The only connection between the two (as far as I’m aware) is when LLVM records debug-info about variables. The simplest example is that if you declare (in the source language) a global variable then you should find a !dbg attachment to the global from which you can reach a DIGlobalVariableExpression, then DIGlobalVariable, and from there the DICompositeType or other type record.