<br>Nick,<br>Your solution works well if there is a store instruction in the function but in the case where there is none (i.e. the argument is passed on directly to another function), creating a store does not help to get the memory address of the variable which takes me back to my initial question at <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-May/022590.html">http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-May/022590.html</a> - isn't there a way to obtain the address of an argument? Because doing a store seems to copy the variable and expose the address of the copy - <a href="http://www.llvm.org/docs/LangRef.html#i_store">http://www.llvm.org/docs/LangRef.html#i_store</a> is not very clear on what's going on.<br>
<br>You can imagine that if you try to do something like taint analysis you want to track each access to a memory location - therefore something like the above would be needed.<br>Any ideas?<br><br>Thanks,<br>Paul<br><br>
<div class="gmail_quote">On Sun, May 24, 2009 at 10:47 PM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca">nicholas@mxc.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Paul Martin wrote:<br>
><br>
> Nick,<br>
> Thanks for the quick answer.<br>
> Dereferencing the pointer does yield the same result in both cases but<br>
> that's not what I want to do. I want to instrument the program<br>
> dynamically and keep track of certain memory locations which is a<br>
> problem if the same variable has different addresses for the<br>
> static/dynamic code - as far I see this is what it's happening but I<br>
> have no clue why.<br>
<br>
</div>If you look at the LLVM IR you can see two distinct alloca instructions,<br>
the one your static code had named "%pi_addr" and the one you created<br>
named "%ptr32".<br>
<br>
It sounds like what you want to do is instead of creating your own stack<br>
spot to store %pi into, you should look at the first user of %pi which<br>
should be a store of %pi into its stack space, as generated by the<br>
static compilation, and pull the stack slot out of there. Something like<br>
this:<br>
<br>
   (Given Argument *A to look for:)<br>
   Value *StackSlot = 0;<br>
   if (StoreInst *SI = dyn_cast<StoreInst>(*A->use_begin()))<br>
     StackSlot = SI->getPointerOperand();<br>
<br>
though I haven't actually tried to compile or run that.<br>
<br>
Nick<br>
<div class="im"><br>
> Paul<br>
><br>
> On Sun, May 24, 2009 at 10:15 PM, Nick Lewycky <<a href="mailto:nicholas@mxc.ca">nicholas@mxc.ca</a><br>
</div><div><div></div><div class="h5">> <mailto:<a href="mailto:nicholas@mxc.ca">nicholas@mxc.ca</a>>> wrote:<br>
><br>
>     Paul Martin wrote:<br>
>      > Hi,<br>
>      > I have the following code, the lines preceded by `>` being added at<br>
>      > runtime (the snipped was also printed at runtime)<br>
>      ><br>
>      > define i32 @myfunc(i32 %pi) {<br>
>      > entry:<br>
>      >         %pi_addr = alloca i32           ; <i32*> [#uses=3]<br>
>      >         %retval = alloca i32            ; <i32*> [#uses=2]<br>
>      >         %tmp = alloca i32               ; <i32*> [#uses=2]<br>
>      >  >       %ptr32 = alloca i32             ; <i32*> [#uses=2]<br>
>      >         %"alloca point" = bitcast i32 0 to i32          ; <i32><br>
>     [#uses=0]<br>
>      ><br>
>      >  >       store i32 %pi, i32* %ptr32<br>
>      >  >       %ptr8 = bitcast i32* %ptr32 to i8*              ; <i8*><br>
>     [#uses=1]<br>
>      >  >       call void @roc( i8* %ptr8 )<br>
>      ><br>
>      >         store i32 %pi, i32* %pi_addr<br>
>      >         %pi_addr1 = bitcast i32* %pi_addr to i8*                ;<br>
>     <i8*><br>
>      > [#uses=1]<br>
>      >         call void @roc( i8* %pi_addr1 )<br>
>      > ...<br>
>      ><br>
>      > void roc(void*) is a function that only prints its argument as an<br>
>     integer.<br>
><br>
>     So it's printing the pointer.<br>
><br>
>      > I was expecting for the program to print the same thing twice (the<br>
>      > address of the myfunc argument) because the code added at runtime<br>
>     looks<br>
>      > to me identical with the code that was compiled (3 lines each).<br>
>      > However, that was not the case; what I got was:<br>
>      ><br>
>      > 147156320<br>
>      > 147117168<br>
>      ><br>
>      > What am I missing?<br>
><br>
>     Make roc() dereference the pointers it's given and print that instead.<br>
><br>
>     Nick<br>
><br>
>     _______________________________________________<br>
>     LLVM Developers mailing list<br>
</div></div>>     <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>><br>
<div class="im">>     <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
>     <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
><br>
><br>
</div>> ------------------------------------------------------------------------<br>
<div><div></div><div class="h5">><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br>