|
From: xinran w. <xin...@gm...> - 2009-02-26 22:25:54
|
Hi,
I'm writting a new Valgrind tool. I have a question: How can I get the
value of a temporary, eg. the value of t1 ?
For exmaple, how can I know the temporary value with index temp1 in
the below function "wrtmp_rdtmp_handler".
// wrtmp_rdtmp_handler is the function to instrument Ist_WrTmp
instruction with Iex_RdTmp data
static VG_REGPARM(2) void wrtmp_rdtmp_handler(IRTemp temp1, IRTemp temp2)
{
// The value of temp1 is just a index. My question is how can I
know the temporary value with index temp1.
// eg. if value of temp1 is 1, what is the value of t1 ?
}
~~~~~~~~~~~~~~~~~~~~~
// code snippet to instrument Ist_WrTmp instruction with Iex_RdTmp data
IRStmt* st = sbIn->stmts[i];
switch (st->tag) {
case Ist_WrTmp:
data = st->Ist.WrTmp.data;
type = typeOfIRExpr(sbOut->tyenv, data);
tl_assert(type != Ity_INVALID);
switch (data->tag) {
case Iex_RdTmp:
argv = mkIRExprVec_2( mkIRExpr_HWord(
data->Iex.RdTmp.tmp ),
mkIRExpr_HWord(st->Ist.WrTmp.tmp) );
di = unsafeIRDirty_0_N( /*regparms*/2,
"wrtmp_rdtmp_handler",
VG_(fnptr_to_fnentry)( wrtmp_rdtmp_handler ),
argv );
addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
break;
}
}
~~~~~~~~~~~~~~~~~~~~~~~
Any suggest will be greatly appreciated.
Thank you very much.
-Xinran
|
|
From: Nicholas N. <n.n...@gm...> - 2009-02-27 01:29:25
|
On Fri, Feb 27, 2009 at 9:25 AM, xinran wang <xin...@gm...> wrote: > > I'm writting a new Valgrind tool. I have a question: How can I get the > value of a temporary, eg. the value of t1 ? I think you might be confusing compile-time with run-time, which is easy to do. t1 is the name of the temporary at compile-time. You can't actually access the value that will be in it until run-time, if that makes sense. Nick |
|
From: xinran w. <xin...@gm...> - 2009-02-27 02:47:46
|
Nick, Thank you very much for your response. I do need to access the value of t1 at runtime. Could you tell me how to access the value at my function, e.g. wrtmp_rdtmp_handler. My function "wrtmp_rdtmp_handler" will be called at runtime, right ? -Xinran On Thu, Feb 26, 2009 at 7:29 PM, Nicholas Nethercote <n.n...@gm...> wrote: > On Fri, Feb 27, 2009 at 9:25 AM, xinran wang <xin...@gm...> wrote: >> >> I'm writting a new Valgrind tool. I have a question: How can I get the >> value of a temporary, eg. the value of t1 ? > > I think you might be confusing compile-time with run-time, which is > easy to do. t1 is the name of the temporary at compile-time. You > can't actually access the value that will be in it until run-time, if > that makes sense. > > Nick > |
|
From: Nicholas N. <n.n...@gm...> - 2009-02-27 03:40:36
|
On Fri, Feb 27, 2009 at 1:47 PM, xinran wang <xin...@gm...> wrote: > > Thank you very much for your response. I do need to access the value > of t1 at runtime. Could you tell me how to access the value at my > function, e.g. wrtmp_rdtmp_handler. > My function "wrtmp_rdtmp_handler" will be called at runtime, right ? Yes. The arguments won't have type IRTemp, though; that type only exists at compile-time. I think all arguments for called functions must be word-sized, eg. Word or SizeT. Have a look at the function trace_load() in lackey/lk_main.c and how it is called; I think what you have is very close to working. NIck |
|
From: xinran w. <xin...@gm...> - 2009-02-27 04:15:00
|
Nick, Thank you for your quick response. I understand how my handler function is called and it does work at runtime in my tool. My question is what is the pointer to variable t1. i.e. How to refer t1 ? Are these temporary variables stored in a global array or linked list? If yes, could you tell me the name of the array. , -Xinran On Thu, Feb 26, 2009 at 9:37 PM, Nicholas Nethercote <n.n...@gm...> wrote: > On Fri, Feb 27, 2009 at 1:47 PM, xinran wang <xin...@gm...> wrote: >> >> Thank you very much for your response. I do need to access the value >> of t1 at runtime. Could you tell me how to access the value at my >> function, e.g. wrtmp_rdtmp_handler. >> My function "wrtmp_rdtmp_handler" will be called at runtime, right ? > > Yes. The arguments won't have type IRTemp, though; that type only > exists at compile-time. > I think all arguments for called functions must be word-sized, eg. > Word or SizeT. Have a look at the function trace_load() in > lackey/lk_main.c and how it is called; I think what you have is very > close to working. > > NIck > |
|
From: Stephen M.
|
>>>>> "XW" == xinran wang <xin...@gm...> writes:
XW> Hi,
XW> I'm writting a new Valgrind tool. I have a question: How can I get
XW> the value of a temporary, eg. the value of t1 ?
XW> For exmaple, how can I know the temporary value with index temp1
XW> in the below function "wrtmp_rdtmp_handler".
There isn't any way to lookup the value of a Tmp at "runtime" (e.g.,
from inside a helper function like wrtmp_rdtmp_handler), because
they are part of the x86->IR->x86 "compilation" process. It's just
like there's no way a C function can ask "what's the value of variable
var in the code that called me?". Instead, you have to get the value
of the Tmp in the IR, and then pass that to the helper. You do that by
putting a RdTmp IRExpr in the IR. You've already checked that "data"
is a RdTmp IRExpr in this branch of the code, so I think you just need
to pass that RdTmp expression at the first element in the IRExprVec.
As Nick mentions, you then need to change the helper arguments to
"Word" type and make sure the value you're passing fits.
XW> // code snippet to instrument Ist_WrTmp instruction with Iex_RdTmp data
XW> IRStmt* st = sbIn->stmts[i];
XW> switch (st->tag) {
XW> case Ist_WrTmp:
XW> data = st->Ist.WrTmp.data;
XW> type = typeOfIRExpr(sbOut->tyenv, data);
XW> tl_assert(type != Ity_INVALID);
XW> switch (data->tag) {
XW> case Iex_RdTmp:
XW> argv = mkIRExprVec_2( mkIRExpr_HWord(
data-> Iex.RdTmp.tmp ),
XW> mkIRExpr_HWord(st->Ist.WrTmp.tmp) );
XW> di = unsafeIRDirty_0_N( /*regparms*/2,
XW> "wrtmp_rdtmp_handler",
XW> VG_(fnptr_to_fnentry)( wrtmp_rdtmp_handler ),
XW> argv );
XW> addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
XW> break;
XW> }
XW> }
XW> ~~~~~~~~~~~~~~~~~~~~~~~
XW> Any suggest will be greatly appreciated.
Another perspective that I've found helpful is to think about the IR
as a programming language, using the syntax of the way Valgrind dumps
it for tracing. (There's a good chance you'll have to learn this for
debugging, at any rate.) You can look at other "code" written in the
IR using the --trace-flags= and --trace-notbelow= options. One you get
used to that language, you can translate back into the code to build
the IR code you want.
In that language, you want to do handler(t7), while what you're doing
now is handler(0x7:I32).
Hope this helps,
-- Stephen
|
|
From: xinran w. <xin...@gm...> - 2009-02-27 06:07:15
|
Stephen,
I see. Thank you very much!
Just tried --trace-flags= and --trace-notbelow= options and they are
really helpful options.
-Xinran
On Thu, Feb 26, 2009 at 10:35 PM, Stephen McCamant <sm...@cs...> wrote:
>>>>>> "XW" == xinran wang <xin...@gm...> writes:
>
> XW> Hi,
> XW> I'm writting a new Valgrind tool. I have a question: How can I get
> XW> the value of a temporary, eg. the value of t1 ?
>
> XW> For exmaple, how can I know the temporary value with index temp1
> XW> in the below function "wrtmp_rdtmp_handler".
>
> There isn't any way to lookup the value of a Tmp at "runtime" (e.g.,
> from inside a helper function like wrtmp_rdtmp_handler), because
> they are part of the x86->IR->x86 "compilation" process. It's just
> like there's no way a C function can ask "what's the value of variable
> var in the code that called me?". Instead, you have to get the value
> of the Tmp in the IR, and then pass that to the helper. You do that by
> putting a RdTmp IRExpr in the IR. You've already checked that "data"
> is a RdTmp IRExpr in this branch of the code, so I think you just need
> to pass that RdTmp expression at the first element in the IRExprVec.
>
> As Nick mentions, you then need to change the helper arguments to
> "Word" type and make sure the value you're passing fits.
>
> XW> // code snippet to instrument Ist_WrTmp instruction with Iex_RdTmp data
> XW> IRStmt* st = sbIn->stmts[i];
>
> XW> switch (st->tag) {
> XW> case Ist_WrTmp:
> XW> data = st->Ist.WrTmp.data;
> XW> type = typeOfIRExpr(sbOut->tyenv, data);
> XW> tl_assert(type != Ity_INVALID);
> XW> switch (data->tag) {
>
> XW> case Iex_RdTmp:
> XW> argv = mkIRExprVec_2( mkIRExpr_HWord(
> data-> Iex.RdTmp.tmp ),
> XW> mkIRExpr_HWord(st->Ist.WrTmp.tmp) );
> XW> di = unsafeIRDirty_0_N( /*regparms*/2,
> XW> "wrtmp_rdtmp_handler",
> XW> VG_(fnptr_to_fnentry)( wrtmp_rdtmp_handler ),
> XW> argv );
> XW> addStmtToIRSB( sbOut, IRStmt_Dirty(di) );
> XW> break;
> XW> }
> XW> }
> XW> ~~~~~~~~~~~~~~~~~~~~~~~
>
> XW> Any suggest will be greatly appreciated.
>
> Another perspective that I've found helpful is to think about the IR
> as a programming language, using the syntax of the way Valgrind dumps
> it for tracing. (There's a good chance you'll have to learn this for
> debugging, at any rate.) You can look at other "code" written in the
> IR using the --trace-flags= and --trace-notbelow= options. One you get
> used to that language, you can translate back into the code to build
> the IR code you want.
>
> In that language, you want to do handler(t7), while what you're doing
> now is handler(0x7:I32).
>
> Hope this helps,
>
> -- Stephen
>
>
|