bool DataLocation::getParams( vector<string>& params, Walker* proc) { assert(proc != 0); bool found = false; vector<Stackwalker::Frame> stackWalk; vector<localVar *> vars; vector<localVar *>::iterator varIter; if(!proc->walkStack(stackWalk)) { return Err::warn(false, "Could not walk stack"); } Stackwalker::Frame& curFrame = stackWalk[0]; string frameName; curFrame.getName(frameName); SymtabAPI::Function* func = getFunctionForFrame(curFrame); if (!func) { return Err::warn(false, "Function for frame '%s' not found", frameName.c_str()); } func->getParams(vars); if(!vars.empty()) { varIter = vars.begin(); for(; varIter != vars.end(); varIter++) { localVar* var = *varIter; if(var) { string name = var->getName(); params.push_back(name); } } } return true; }
bool DataLocation::getParams( vector<string>& params, Walker* proc) { assert(proc != 0); bool found = false; vector<localVar *> vars; vector<localVar *>::iterator varIter; Stackwalker::Frame curFrame(proc); if(!proc->getInitialFrame(curFrame)) { return DYSECTWARN(false, "FuncParamNames could not get Initial Frame: %s", Stackwalker::getLastErrorMsg()); } string frameName; if(!curFrame.getName(frameName)) DYSECTWARN(false, "Failed to get frame name: %s", Stackwalker::getLastErrorMsg()); SymtabAPI::Function* func = getFunctionForFrame(curFrame); if (!func) { return DYSECTWARN(false, "Function for frame '%s' not found", frameName.c_str()); } func->getParams(vars); if(!vars.empty()) { varIter = vars.begin(); for(; varIter != vars.end(); varIter++) { localVar* var = *varIter; if(var) { string name = var->getName(); params.push_back(name); } } } return true; }
bool DataLocation::findVariable(Process::const_ptr process, Walker* proc, string name, DataLocation*& location) { assert(proc != 0); bool found = false; string baseStr, memberStr; int len = name.size(); #if 0 // XXX: Quick hack to get structure members // Should really be a part of the expression engine enum struct_parser { base, dash, gt, member } state = base; const char* str = name.c_str(); for(int i = 0; i < len; i++) { char c = str[i]; if((state == base) && (c == '-')) state = dash; else if((state == dash) && (c == '>')) state = member; else { if(state == base) baseStr += c; if(state == member) memberStr += c; } } #endif if(!memberStr.empty()) { name = baseStr; } // 1st approach - look for local variable (resident in function for current frame) vector<Stackwalker::Frame> stackWalk; vector<localVar *> vars; vector<localVar *>::iterator varIter; if(!proc->walkStack(stackWalk)) { return Err::warn(false, "Could not walk stack"); } Stackwalker::Frame& curFrame = stackWalk[0]; string frameName; curFrame.getName(frameName); SymtabAPI::Function* func = getFunctionForFrame(curFrame); if (!func) { return Err::warn(false, "Function for frame '%s' not found", frameName.c_str()); } func->findLocalVariable(vars, name); Err::verbose(true, "Is variables for '%s' empty? %s", name.c_str(), vars.empty() ? "yes" : "no"); if(!vars.empty()) { found = true; Module* mod = func->getModule(); Symtab* symtab = 0; if(mod) { symtab = mod->exec(); } else { return Err::warn(false, "Could not find symbol table containing variable '%s'", name.c_str()); } location = new LocalVariableLocation(stackWalk, 0, vars[0], symtab); #if 0 // XXX: Hack continued if(!memberStr.empty()) { Type* symType = location->getType(); if(symType) { typeStruct *stType = symType->getStructType(); if(stType) { vector<Field*>* fields = stType->getComponents(); if(fields) { vector<Field*>::iterator fieldIter = fields->begin(); for(;fieldIter != fields->end(); fieldIter++) { Field* field = *fieldIter; if(field && (field->getName().compare(memberStr) == 0)) { // Rebase Err::verbose(true, "Rebasing to member '%s' from %s", field->getName().c_str(), memberStr.c_str()); int offset = field->getOffset(); Type* fieldType = field->getType(); DataLocation* fieldVariable = location->getInnerVariable(fieldType, offset); if(fieldVariable) { location = fieldVariable; } } } } } } } #endif return true; } // Is parameter? if(func->getParams(vars)) { Err::verbose(true, "Is parameters empty? %s", vars.empty() ? "yes" : "no" ); if(!vars.empty()) { varIter = vars.begin(); for(;varIter != vars.end(); varIter++) { Err::verbose(true, "Parameter found: '%s'", (*varIter)->getName().c_str()); } } } if(func->getLocalVariables(vars)) { Err::verbose(true, "Is locals empty? %s", vars.empty() ? "yes" : "no" ); if(!vars.empty()) { varIter = vars.begin(); for(;varIter != vars.end(); varIter++) { Err::verbose(true, "Local found: '%s'", (*varIter)->getName().c_str()); } } } else { Err::verbose(true, "Local variables not present"); } if(!found) { // Try "global" variable / Available through symbol table vector<LibAddrPair> libs; vector<LibAddrPair>::iterator libIter; if(SymbolTable::getLibraries(libs, proc) != OK) { return Error; } // Search through libraries for(libIter = libs.begin(); libIter != libs.end(); libIter++) { string curLibName = libIter->first; Dyninst::Address offset = libIter->second; Symtab* symtab = 0; if(SymbolTable::getSymbolTable(curLibName, symtab) != OK) { return Err::warn(false, "Could not get symbol table"); } if(findVariable(offset, symtab, process, name, location)) { return true; } } } return false; }