[cfe-users] fetch variable names through debugInfo attached to load instructors

Bella V via cfe-users cfe-users at lists.llvm.org
Thu May 20 12:18:10 PDT 2021


Hello All,

I read the documentation and I was able to fetch the variable names and
source locations attached to metadata for call instructions
(@llvm.dbg.declare) using dyn_cast<DbgVariableIntrinsic>. I wanted to check
if we could fetch the variable names in the load/gep instructors using
debugInfo. I want to collect the use variable object details within the
function.



I could only fetch the source locations (not the variable names) using !dbg
attached to the load instructions. Any pointers if that is allowed.


*C code:*

int foo (bar_t *b, int len)

{

    if (b == (bar_t *)NULL) {

        return 0;

    }

    return -1;

}



*IR optimised code through LTO:*

; Function Attrs: noinline nounwind optnone uwtable

define i32 @foo(%struct.bar_t*, i32) #0 !dbg !10 {

  %3 = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]

  %4 = add i64 %3, 1

  %5 = alloca i32, align 4

  %6 = alloca % struct.bar_t*, align 8

  %7 = alloca i32, align 4

  store % struct.bar_t* %0, % struct.bar_t** %6, align 8

  call void @llvm.dbg.declare(metadata % struct.bar_t** %6, metadata !11,
metadata !DIExpression()), !dbg !12

  store i32 %1, i32* %7, align 4

  call void @llvm.dbg.declare(metadata i32* %7, metadata !12, metadata
!DIExpression()), !dbg !14

  %8 = load % struct.bar_t*, % struct.bar_t** %6, align 8, !dbg !15

  %9 = icmp eq % struct.bar_t* %8, null, !dbg !16

  br i1 %9, label %10, label %11, !dbg !17



Many Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20210520/653d017e/attachment.html>


More information about the cfe-users mailing list