How to get information from llvm's metadata

I have two questions:

  1. Given the getelementPtr instruction, how can I get the field name using metada??


%b = getelementptr inbounds %struct.T* %7, i32 0, i32 1, !dbg !31

I want get it’s field name “b”.

  1. Given a llvm.dbg.declare, how can I get it’s llvm value.


call void @llvm.dbg.declare(metadata !{i32** %r}, metadata !23), !dbg !24

I want get the Value i32** %r.

Please pose the code ! Thank you in advance!!