Re: [DynInst_API:] Building a local struct for a funcCall parameter


Date: Tue, 02 Oct 2012 15:04:04 -0700
From: Josh Stone <jistone@xxxxxxxxxx>
Subject: Re: [DynInst_API:] Building a local struct for a funcCall parameter
On 10/01/2012 06:36 PM, Josh Stone wrote:
> As a fallback, I'm considering passing all of those register values as
> individual parameters, but I'm hoping there's a better way.

I tried to do this, but got an assertion failure.  I can reproduce it
with the simple attached mutator, processMainRegs.cc, like:

$ ./processMainRegs /bin/true
Error: tried to allocate register 9 and failed!
processMainRegs: ../../dyninstAPI/src/emit-x86.C:1758: virtual Register
EmitterAMD64::emitCall(opCode, codeGen&, const
std::vector<boost::shared_ptr<AstNode> >&, bool, func_instance*):
Assertion `0' failed.
Aborted

I also ran it with env DYNINST_DEBUG_REGALLOC=1 and got a big log that
I've also attached.  The last additional info that gives is:
  [UI]: Error: register currently in use!

This seems to be not really related to the fact that I'm using all of
the BPatch_registerExpr, just that there are so many arguments.  Even
replacing that part with all BPatch_constExpr((unsigned long)i) still
triggers this assertion failure.

Is there anything I can do to mitigate this?

Josh
#include <iostream>
#include <sstream>

#include <BPatch.h>
#include <BPatch_function.h>
#include <BPatch_point.h>
#include <BPatch_process.h>
#include <BPatch_snippet.h>

using namespace std;

int
main(int argc, const char* argv[])
{
    if (argc < 2) {
        clog << "ERROR: need to specify an app to run" << endl;
        return 1;
    }

    BPatch bpatch;
    BPatch_process *proc = bpatch.processCreate(argv[1], &argv[1]);
    if (!proc) {
        clog << "ERROR: couldn't create process" << endl;
        return 1;
    }

    vector<BPatch_function *> printfFuncs;
    vector<BPatch_snippet *> printfArgs;
    proc->getImage()->findFunction("printf", printfFuncs);
    if (printfFuncs.empty()) {
        clog << "ERROR: couldn't find printf" << endl;
        return 1;
    }

    stringstream format;
    format << "main:";
    BPatch_Vector<BPatch_register> regs;
    proc->getRegisters(regs);
    for (size_t i = 0; i < regs.size(); ++i) {
        format << " " << regs[i].name() << ":%lx";
        printfArgs.push_back(new BPatch_registerExpr(regs[i]));
    }
    format << endl;

    printfArgs.insert(printfArgs.begin(),
            new BPatch_constExpr(format.str().c_str()));
    BPatch_funcCallExpr printfCall(*printfFuncs[0], printfArgs);

    std::vector<BPatch_function *> functions;
    proc->getImage()->findFunction("main", functions);
    if (functions.empty()) {
        clog << "ERROR: couldn't find main" << endl;
        return 1;
    }
    proc->insertSnippet(printfCall,
            *functions[0]->findPoint(BPatch_entry));

    proc->continueExecution();
    while (!proc->isTerminated())
        bpatch.waitForStatusChange();

    return 0;
}

Attachment: processMainRegs.log.bz2
Description: application/bzip

[← Prev in Thread] Current Thread [Next in Thread→]