コード例 #1
0
ファイル: BPatch_image.C プロジェクト: vishalmistry/imitate
/*
 * BPatch_image::getProcedures
 *
 * Returns a list of all procedures in the image upon success, and NULL
 * upon failure.
 */
BPatch_Vector<BPatch_variableExpr *> *BPatch_image::getGlobalVariablesInt()
{
    BPatch_variableExpr *var;
    BPatch_Vector<BPatch_variableExpr *> *varlist =
        new BPatch_Vector<BPatch_variableExpr *>;

    if (varlist == NULL) return NULL;

    // XXX - should this stuff really be by image ??? jkh 3/19/99
    BPatch_Vector<BPatch_module *> *mods = getModules();
    //BPatch_type *type;
    for (unsigned int m = 0; m < mods->size(); m++) {
        BPatch_module *module = (*mods)[m];
        char name[255];
        module->getName(name, sizeof(name));
        pdvector<pdstring> keys = module->getModuleTypes()->globalVarsByName.keys();
        int limit = keys.size();
        for (int j = 0; j < limit; j++) {
            pdstring name = keys[j];
            var = createVarExprByName(module, name.c_str());
            if (var != NULL)
                varlist->push_back(var);
        }
    }


    return varlist;
}
コード例 #2
0
ファイル: BPatch_image.C プロジェクト: vishalmistry/imitate
/*
 * BPatch_image::findModule
 *
 * Returns module with <name>, NULL if not found
 */
BPatch_module *BPatch_image::findModuleInt(const char *name, bool substring_match)
{
    if (!name) {
        bperr("%s[%d]:  findModule:  no module name provided\n",
              __FILE__, __LINE__);
        return NULL;
    }

    BPatch_module *target = NULL;

    char buf[512];
    for (unsigned int i = 0; i < modlist.size(); ++i) {
        BPatch_module *mod = modlist[i];
        assert(mod);
        mod->getName(buf, 512);
        if (substring_match)
            if (strstr(buf, name)) {
                target = mod;
                break;
            }
            else  //exact match required
                if (!strcmp(name, buf)) {
                    target = mod;
                    break;
                }
    }

    if (target)
        return target;

    // process::findModule does a wildcard match, not a substring match

    char *tmp = (char *) malloc(strlen(name) + 2);
    if(substring_match)
        sprintf(tmp, "*%s*", name);
    else
        sprintf(tmp, "%s", name);
    mapped_module *mod = proc->llproc->findModule(pdstring(tmp),substring_match);
    free(tmp);
    if (!mod) return false;

    target = findOrCreateModule(mod);

    return target;
}
コード例 #3
0
ファイル: BPatch_image.C プロジェクト: vishalmistry/imitate
/*
 * BPatch_image::findVariable
 *
 * Returns a BPatch_variableExpr* representing the given variable in the
 * application image.  If no such variable exists, returns NULL.
 *
 * name		The name of the variable to look up.
 *
 * First look for the name with an `_' prepended to it, and if that is not
 *   found try the original name.
 */
BPatch_variableExpr *BPatch_image::findVariableInt(const char *name, bool showError)
{
    pdvector<int_variable *> vars;
    process *llproc = proc->llproc;

    if (!llproc->findVarsByAll(name, vars)) {
        // _name?
        pdstring under_name = pdstring("_") + pdstring(name);
        if (!llproc->findVarsByAll(under_name, vars)) {
            // "default Namespace prefix?
            if (defaultNamespacePrefix) {
                pdstring prefix_name = pdstring(defaultNamespacePrefix) + pdstring(".") + pdstring(name);
                if (!llproc->findVarsByAll(prefix_name, vars)) {
                    if (showError) {
                        pdstring msg = pdstring("Unable to find variable: ") + pdstring(prefix_name);
                        showErrorCallback(100, msg);
                    }
                    return NULL;
                }
            } else {
                if (showError) {
                    pdstring msg = pdstring("Unable to find variable: ") + pdstring(name);
                    showErrorCallback(100, msg);
                }
                return NULL;
            }
        }
    }
    assert(vars.size());

    if (vars.size() > 1) {
        cerr << "Warning: found multiple matches for var " << name << endl;
    }

    int_variable *var = vars[0];

    BPatch_variableExpr *bpvar = AddrToVarExpr->hash[var->getAddress()];
    if (bpvar) {
        return bpvar;
    }
    // XXX - should this stuff really be by image ??? jkh 3/19/99
    BPatch_Vector<BPatch_module *> *mods = getModules();
    BPatch_type *type = NULL;

    // XXX look up the type off of the int_variable's module
    BPatch_module *module = NULL;
    for (unsigned int m = 0; m < mods->size(); m++) {
        if( (*mods)[m]->lowlevel_mod() == var->mod() ) {
            module = (*mods)[m];
            break;
        }
    }
    if(module) {
        type = module->getModuleTypes()->findVariableType(name);
    }
    else {
        bperr("findVariable: failed look up module %s\n",
              var->mod()->fileName().c_str());
    }
    if(!type) {
        //  if we can't find the type in the module, check the other modules
        //  (fixes prob on alpha) --  actually seems like most missing types
        //  end up in DEFAULT_MODULE
        for (unsigned int m = 0; m < mods->size(); m++) {
            BPatch_module *tm = (*mods)[m];
            type = tm->getModuleTypes()->findVariableType(name);
            if (type) {
#if 0
                char buf1[1024], buf2[1024];
                tm->getName(buf1, 1024);
                module->getName(buf2, 1024);
                fprintf(stderr, "%s[%d]:  found type for %s in module %s, not %s\n", FILE__, __LINE__, name, buf2, buf1);
#endif
                break;
            }

        }

        if (!type) {
            char buf[128];
            sprintf(buf, "%s[%d]:  cannot find type for var %s\n", FILE__, __LINE__, name);
            BPatch_reportError(BPatchWarning, 0, buf);
            type = BPatch::bpatch->type_Untyped;
        }
    }

    char *nameCopy = strdup(name);
    assert(nameCopy);
    BPatch_variableExpr *ret = new BPatch_variableExpr((char *) nameCopy,
            proc, (void *)var->getAddress(),
            type);
    AddrToVarExpr->hash[var->getAddress()] = ret;
    return ret;
}
コード例 #4
0
ファイル: test1_41.C プロジェクト: cuviper/testsuite
// static int mutatorTest(char *pathname, BPatch *bpatch)
test_results_t test1_41_Mutator::executeTest() {
   unsigned int n=0;
   const char *child_argv[5];
   child_argv[n++] = pathname;
   if (debugPrint) child_argv[n++] = const_cast<char*>("-verbose");
   child_argv[n++] = const_cast<char*>("-run");
   child_argv[n++] = const_cast<char*>("test1_41"); // run test41 in mutatee
   child_argv[n++] = NULL;

   int counts[iterations];

   // Run the mutatee twice, querying line info each time & store the info
   for (n = 0; n < iterations; n++) {
      dprintf("Starting \"%s\"\n", pathname);
      BPatch_process *proc = bpatch->processCreate(pathname, child_argv,
                                                    NULL);
      if (!proc) {
         logerror("*ERROR*: unable to create handle for executable\n", n);
         logerror("**Failed** test #41 (repeated line information)\n");
         return FAILED;
      }
      dprintf("Mutatee started, pid=%d\n", n, proc->getPid());

      BPatch_image *image = proc->getImage();
      if (!image) {
         logerror("*ERROR*: unable to get image from thread\n");
         logerror("**Failed** test #41 (repeated line information)\n");
         return FAILED;
      }
      if (isMutateeFortran(image)) {
         // This shouldn't happen..
         proc->terminateExecution();
         logerror("Skipped test #41 (repeated line information)\n");
         return SKIPPED;
      }

      BPatch_module *module = image->findModule("test1_41_mutatee.c", true);
      if (!module) {
         module = image->findModule("solo_mutatee_boilerplate.c", true);
         if (true) {
            logerror("*ERROR*: unable to get module from image\n");
            logerror("Looking for \"test1_41_solo_me.c\" or \"solo_mutatee_boilerplate.c\". Available modules:\n");
            BPatch_Vector<BPatch_module *> *mods = image->getModules();
            char buffer[512];
            for (unsigned i = 0; i < mods->size(); i++) {
               BPatch_module *mod = (*mods)[i];
               char name[512];
               mod->getName(name, 512);
               sprintf(buffer, "\t%s\n",
                       name);
               logerror(buffer);
            }
		 }
      }

      if (!module) {
		  fprintf(stderr, "%s[%d]:  could not find module solo_mutatee_boilerplate.c\n", FILE__, __LINE__);
         // First try again for 'test1_41_solo_me.c'
         module = image->findModule("test1_41_solo_me.c", true);
         if (!module) {
            logerror("*ERROR*: unable to get module from image\n");
            logerror("Looking for \"test1_41_solo_me.c\" or \"solo_mutatee_boilerplate.c\". Available modules:\n");
            BPatch_Vector<BPatch_module *> *mods = image->getModules();
            char buffer[512];
            for (unsigned i = 0; i < mods->size(); i++) {
               BPatch_module *mod = (*mods)[i];
               char name[512];
               mod->getName(name, 512);
               sprintf(buffer, "\t%s\n",
                       name);
               logerror(buffer);
            }

            logerror("**Failed** test #41 (repeated line information)\n");

            return FAILED;
         }
      }

      char buffer[16384]; // FIXME ugly magic number; No module name should be that long..
      module->getName(buffer, sizeof(buffer));

      BPatch_Vector<BPatch_statement> statements;
      bool res = module->getStatements(statements);
      if (!res) {
         fprintf(stderr, "%s[%d]:  getStatements()\n", __FILE__, __LINE__);
         return FAILED;
      }

      counts[n] = statements.size();
      dprintf("Trial %d: found %d statements\n", n, statements.size());

      proc->terminateExecution();
   }

   // Make sure we got the same info each time we ran the mutatee
   int last_count = -1;
   for (int i = 0; i < iterations; i++) {
      if ((last_count >= 0) && (last_count != counts[i])) {
         logerror("*ERROR*: statement counts didn't match: %d vs. %d\n", last_count, counts[i]);
         logerror("**Failed** test #41 (repeated line information)\n");
         return FAILED;
      }
      last_count = counts[i];
   }

   logerror("Passed test #41 (repeated line information)\n");
   return PASSED;
}