|
From: Nicholas N. <n.n...@gm...> - 2010-09-15 21:47:28
|
On Tue, Sep 14, 2010 at 4:14 PM, Scott Pakin <pa...@la...> wrote: > For a tool I'm writing, I'm finding that my instrumentation code needs > to pass a ton of arguments to some of my execution-time functions. > For example, given the statement > > PUTI(64:8xF64)[t5,0] = t1 > > the target function needs access to base (64), nElems (8), elemTy > (F64), ix (t5), ix's run-time value ([dynamic]), bias (0), data (t1), > and data's run-time value ([dynamic]). The problem is that the number > of arguments is limited on certain platforms (6 on amd64, for > example). I suppose I can work around that limitation by passing half > the arguments to each of two helper functions, which can aggregate the > arguments then call my real function, but I'm wondering if there's a > cleaner way to pass bulk information from instrumentation code to > execution code. > > It'd be great if my instrumentation code could pass a complete IRStmt > to an execution-time function and let that function extract both the > static arguments and dynamic values. However, I suspect that that's > not possible, right? The IRStmt will be destroyed before the instrumented code is run. However, if you heap-allocated some memory and copied it, you could then pass a pointer to the copy. As for deallocating the copy... if the translation gets flushed you should free the copy. The only hook that will let you know when that happens is VG_(needs_superblock_discards). That might give you enough info to do it. Or you could just not worry about it, depending on how robust your tool needs to be; code cache flushes aren't that common. > Any suggestions for an efficient way to pass all parts of an IRStmt > and all the associated execution-time values to an execution-time > function? The fewer arguments, the better. If one of the arguments has only N possible values and N is small (eg. 3 or 4) you can have N functions. So instead of these calls: foo(1, ...) foo(2, ...) foo(3, ...) you have: foo1(...) foo2(...) foo3(...) Several of the existing Valgrind tools do this. Nick |