PinCmd::PinCmd(Config* conf, const char* configFile, const char* outputDir, uint64_t shmid) { //Figure the program paths const char* zsimEnvPath = getenv("ZSIM_PATH"); g_string pinPath, zsimPath; if (zsimEnvPath) { info("Using env path %s", zsimEnvPath); pinPath = zsimEnvPath; pinPath += "/pinbin"; zsimPath = zsimEnvPath; zsimPath += "/libzsim.so"; } else { pinPath = QUOTED(PIN_PATH); zsimPath = QUOTED(ZSIM_PATH); } args.push_back(pinPath); //Global pin options args.push_back("-follow_execv"); //instrument child processes args.push_back("-tool_exit_timeout"); //don't wait much of internal threads args.push_back("1"); //Additional options (e.g., -smc_strict for Java), parsed from config const char* pinOptions = conf->get<const char*>("sim.pinOptions", ""); wordexp_t p; wordexp(pinOptions, &p, 0); for (uint32_t i = 0; i < p.we_wordc; i++) { args.push_back(g_string(p.we_wordv[i])); } wordfree(&p); //Load tool args.push_back("-t"); args.push_back(zsimPath); //Tool options if (configFile) { //Check configFile is an absolute path //NOTE: We check rather than canonicalizing it ourselves because by the time we're created, we might be in another directory char* absPath = realpath(configFile, nullptr); if (std::string(configFile) != std::string(absPath)) { panic("Internal zsim bug, configFile should be absolute"); } free(absPath); args.push_back("-config"); args.push_back(configFile); } args.push_back("-outputDir"); args.push_back(outputDir); std::stringstream shmid_ss; shmid_ss << shmid; args.push_back("-shmid"); args.push_back(shmid_ss.str().c_str()); if (conf->get<bool>("sim.logToFile", false)) { args.push_back("-logToFile"); } //Read the per-process params of the processes run directly by the harness while (true) { std::stringstream p_ss; p_ss << "process" << procInfo.size(); if (!conf->exists(p_ss.str().c_str())) break; const char* cmd = conf->get<const char*>(p_ss.str() + ".command"); const char* input = conf->get<const char*>(p_ss.str() + ".input", ""); const char* loader = conf->get<const char*>(p_ss.str() + ".loader", ""); const char* env = conf->get<const char*>(p_ss.str() + ".env", ""); ProcCmdInfo pi = {g_string(cmd), g_string(input), g_string(loader), g_string(env)}; procInfo.push_back(pi); } }
int launchXtermDebugger(int targetPid, LibInfo* libzsimAddrs) { int childPid = fork(); if (childPid == 0) { std::string targetPidStr = Str(targetPid); char symbolCmdStr[2048]; snprintf(symbolCmdStr, sizeof(symbolCmdStr), "add-symbol-file %s %p -s .data %p -s .bss %p", QUOTED(ZSIM_PATH), libzsimAddrs->textAddr, libzsimAddrs->dataAddr, libzsimAddrs->bssAddr); const char* const args[] = {"xterm", "-e", "cgdb", "-p", targetPidStr.c_str(), "-ex", "set confirm off", //we know what we're doing in the following 2 commands "-ex", symbolCmdStr, "-ex", "handle SIGTRAP nostop noprint", // For some reason we receive a lot of spurious sigtraps "-ex", "set confirm on", //reenable confirmations "-ex", "c", //start running nullptr}; execvp(args[0], (char* const*)args); panic("shouldn't reach this..."); } else { return childPid; } }