<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi all,</div><div>sorry to ask again but this problem is killing me :)</div><div><br></div><div>So I have the following C code:</div><div><br></div><div>#include<stdio.h><br><br>int main(int argc, char *argv[]) {<br><br>    printf("%s\n", argv[0]);<br>    return argc;<br>}<br></div><div><br></div><div>That is translated into</div><div><br></div><div>; ModuleID = 'argv.bc'<br>source_filename = "argv.c"<br>target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>target triple = "x86_64-pc-linux-gnu"<br><br>@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1<br><br>; Function Attrs: noinline nounwind optnone uwtable<br>define i32 @main(i32, i8**) #0 {<br>  %3 = alloca i32, align 4<br>  %4 = alloca i32, align 4<br>  %5 = alloca i8**, align 8<br>  store i32 0, i32* %3, align 4<br>  store i32 %0, i32* %4, align 4<br>  store i8** %1, i8*** %5, align 8<br>  %6 = load i8**, i8*** %5, align 8<br>  %7 = getelementptr inbounds i8*, i8** %6, i64 0<br>  %8 = load i8*, i8** %7, align 8<br>  %9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* %8)<br>  %10 = load i32, i32* %4, align 4<br>  ret i32 %10<br>}<br><br>declare i32 @printf(i8*, ...) #1<br><br>attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }<br><br>!llvm.module.flags = !{!0}<br>!llvm.ident = !{!1}<br><br>!0 = !{i32 1, !"wchar_size", i32 4}<br>!1 = !{!"clang version 6.0.1-svn334776-1~exp1~20181018152737.116 (branches/release_60)"}</div><div><br></div><div>I'm still experimenting with the Interpreter class...</div><div><br></div><div>I know that %8 holds the pointer to argv[0] and I would like to extract the value. I though the right approach would have been to do what it is done inside visitLoadInst:</div><div><br></div><div>ExecutionContext &SF = ECStack.back();<br>  GenericValue SRC = getOperandValue(I.getPointerOperand(), SF);<br>  GenericValue *Ptr = (GenericValue*)GVTOP(SRC);<br>  GenericValue Result;<br>  LoadValueFromMemory(Result, Ptr, I.getType());</div><div><br></div><div>Instead of I.getType() I used getInt32Ty(context) and instead of Ptr I used the result returned by first LoadValueFromMemory. After that I print "newResult.Int" but I always have 0 as a result. I cannot understand why.</div><div><br></div><div>Can someone help me to have argv[0] taken from the memory?</div><div><br></div><div>Thanks a lot<br></div><div><br></div></div></div></div></div>