/* * Given a string variable name and an expected value, lookup the varaible * in the process, and verify that the value matches. * */ bool verifyProcMemory(BPatch_thread *appThread, const char *name, int expectedVal, procType proc_type) { BPatch_image *appImage = appThread->getImage(); if (!appImage) { dprintf("unable to locate image for %d\n", appThread->getPid()); return false; } BPatch_variableExpr *var = appImage->findVariable(name); if (!var) { dprintf("unable to located variable %s in child\n", name); return false; } int actualVal; var->readValue(&actualVal); if (expectedVal != actualVal) { fprintf(stderr,"*** for %s (%s), expected val = %d, but actual was %d\n", name, procName[proc_type], expectedVal, actualVal); return false; } else { dprintf("verified %s (%s) was = %d\n", name, procName[proc_type], actualVal); return true; } }
// Returns true on error, false on success bool test_thread_2_Mutator::getVar(const char *vname, void *addr, int len, int testno, const char *testname) { BPatch_variableExpr *v; if (NULL == (v = appImage->findVariable(vname))) { logerror("**Failed test #%d (%s)\n", testno, testname); logerror(" cannot find variable %s: avail vars:\n", vname); dumpVars(); return true; } if (! v->readValue(addr, len)) { logerror("**Failed test #%d (%s)\n", testno, testname); logerror(" failed to read var in mutatee\n"); return true; } return false; // No error }