void RTeIIOAccel::timerEvent(QTimerEvent *) { RTEIIOACCEL_DATA rawData; RTeSensorAccelData accelData; if (!m_useBuffer) { QFile dataFile; for (int i = 0; i < 3; i++) { dataFile.setFileName(m_devicePath + m_dataNames[i]); dataFile.open(QIODevice::ReadOnly); QString value = dataFile.readAll(); accelData.m_accel.setData(i, value.toDouble() / 1000.0); dataFile.close(); } m_count++; if ((RTeMath::currentUSecsSinceEpoch() - m_startTime) >= 1000000) { qDebug() << accelData.m_accel.display("Accel: "); qDebug() << "Sample rate: " << m_count; m_count = 0; m_startTime = RTeMath::currentUSecsSinceEpoch(); } } else { while (1) { int count = read(m_fp, (char *)(&rawData) + m_bytesGot, m_bytesLeft); if (count <= 0) { if (errno != EAGAIN) RTeError(getModuleName(), QString("Read failed %1").arg(errno)); return; } m_bytesGot += count; m_bytesLeft -=count; if (m_bytesLeft <= 0) { m_count++; m_bytesGot = 0; m_bytesLeft = sizeof(RTEIIOACCEL_DATA); accelData.m_accel.setX((RTEFLOAT)rawData.x / (RTEFLOAT)16384.0); accelData.m_accel.setY((RTEFLOAT)rawData.y / (RTEFLOAT)16384.0); accelData.m_accel.setZ((RTEFLOAT)rawData.z / (RTEFLOAT)16384.0); accelData.m_timestamp = rawData.timestamp / 1000; emit newAccelSample(this, &accelData); if ((RTeMath::currentUSecsSinceEpoch() - m_startTime) >= 1000000) { RTeDebug(getModuleName(), QString("Accel sample rate: %1").arg(m_count)); m_count = 0; m_startTime = RTeMath::currentUSecsSinceEpoch(); } } } } }
void readModuleVersion(uint8_t cs_pin) { uint8_t version; // RFM9x version is reg 0x42 printf("Checking register(0x42) with CS=GPIO%02d", cs_pin); getModuleName( readRegister( cs_pin, 0x42) ); // RFM69 version is reg 0x10 printf("Checking register(0x10) with CS=GPIO%02d", cs_pin); getModuleName ( readRegister( cs_pin, 0x10) ) ; }
PyObject* PythonInterface::getClassInstance() { if (pInstance == NULL) { Py_Initialize(); if (modulePath != NULL) { PyRun_SimpleString("import sys"); PyRun_SimpleString(("sys.path.append(\"" + std::string(modulePath) + "\")").c_str()); } std::string modName = getModuleName(); PyObject *pName = PyString_FromString(modName.c_str()); PyObject *pModule = PyImport_Import(pName); Py_DECREF(pName); char* fileName = PyModule_GetFilename(pModule); char* argv[1] = { fileName }; PySys_SetArgvEx(1, argv, 0); PyObject *pDict = PyModule_GetDict(pModule); Py_DECREF(pModule); PyObject *pClass = PyDict_GetItemString(pDict, getClassName().c_str()); Py_DECREF(pDict); pInstance = PyObject_CallObject(pClass, NULL); Py_DECREF(pClass); } return pInstance; }
/* ========================================================================== Function Name : (BOOL) RegSetBinary() Outline : レジストリキーの値から BINARYを読み込む Arguments : HKEY hKey (in) 値を設定するキーのハンドル : LPCTSTR lpszValueName (in) 設定する値 : void *buf (out) 値データ Return Value : 成功 TRUE : 失敗 FALSE Reference : Renewal : Notes : Attention : Up Date : ======1=========2=========3=========4=========5=========6=========7======= */ BOOL RegSetBinary(HKEY hKey, LPCTSTR lpszValueName, void *buf, DWORD dwSize) { if(bUseINI){ TCHAR t[1024] = {0}; LPBYTE s = (LPBYTE)buf; for(DWORD i=0; i<dwSize; i++){ TCHAR c[4]; _stprintf(c, _T("%02X "), s[i]); _tcscat(t, c); } BOOL ret = WritePrivateProfileString(szSectionName, lpszValueName, t, getModuleName()); return ret; }else{ long lError; DWORD dwWriteSize; dwWriteSize = dwSize * sizeof(TCHAR); if ((lError = ::RegSetValueEx(hKey, lpszValueName, 0, REG_BINARY, (CONST BYTE *) buf, dwWriteSize)) != ERROR_SUCCESS) { ::SetLastError(lError); return FALSE; } } return TRUE; }
/* ========================================================================== Function Name : (BOOL) RegGetDword() Outline : レジストリキーの値から DWORDを読み込む Arguments : HKEY hKey (in) 値を設定するキーのハンドル : LPCTSTR lpszValueName (in) 設定する値 : DWORD *dwValue (out) 値データ Return Value : 成功 TRUE : 失敗 FALSE Reference : Renewal : Notes : Attention : Up Date : ======1=========2=========3=========4=========5=========6=========7======= */ BOOL RegGetDword(HKEY hKey, LPCTSTR lpszValueName, DWORD *dwValue) { int defmark = 0xdeadbeef; if(bUseINI){ // 読み込みに失敗した場合は false を返す (2007.11.14 yutaka) *dwValue = GetPrivateProfileInt(szSectionName, lpszValueName, defmark, getModuleName()); if (*dwValue == defmark) { *dwValue = 0; return FALSE; } else { return TRUE; } }else{ long lError; DWORD dwType = REG_DWORD; DWORD dwSize = sizeof(DWORD); lError = ::RegQueryValueEx(hKey, lpszValueName, 0, &dwType, (LPBYTE) dwValue, &dwSize); if (lError != ERROR_SUCCESS) { ::SetLastError(lError); return FALSE; } } return TRUE; }
const McEnvironment* McObject::getEnvironment() const { /* Check if the environment is set into the object */ if(!environment) throw(GeneralError("Object " + getObjectName() + " from module " + getModuleName() + " attempted to access the environment but there isn't a reference to it ")); return environment; }
LONG RegDelete(HKEY hKey, LPCTSTR lpSubKey) { if(bUseINI){ return WritePrivateProfileString(szSectionName, NULL, NULL, getModuleName()) ? ERROR_SUCCESS : ERROR_ACCESS_DENIED; }else{ return ::RegDeleteKey(hKey, lpSubKey); } }
// Create is used by the type_param'ed tests. T here denotes the // module type, whereas N denotes the module name. static Try<T*> create() { Try<std::string> moduleName = getModuleName(N); if (moduleName.isError()) { return Error(moduleName.error()); } return mesos::modules::ModuleManager::create<T>(moduleName.get()); }
void RTeIIOAccel::initModule() { int rate; if (!setValue("buffer/enable", 0)) { RTeError(getModuleName(), "Failed to disable buffer"); } switch (m_sampleRate) { case 0: rate = 1; break; case 1: rate = 10; break; case 2: rate = 25; break; case 3: rate = 50; break; case 4: rate = 100; break; case 5: rate = 200; break; case 6: rate = 400; break; case 7: rate = 1600; break; default: rate = 25; break; } setValue("sampling_frequency", rate); if (m_useBuffer) { if (!setValue("scan_elements/in_accel_x_en", 1)) { RTeError(getModuleName(), "Failed enable x axis"); } if (!setValue("scan_elements/in_accel_y_en", 1)) { RTeError(getModuleName(), "Failed enable y axis"); } if (!setValue("scan_elements/in_accel_z_en", 1)) { RTeError(getModuleName(), "Failed enable z axis"); } if (!setValue("scan_elements/in_timestamp_en", 1)) { RTeError(getModuleName(), "Failed enable timestamp"); } if (!setValue("buffer/length", 128)) { RTeError(getModuleName(), "Failed to set buffer length"); } if (!setValue("buffer/enable", 1)) { RTeError(getModuleName(), "Failed to enable buffer"); } m_fp = open(qPrintable(m_deviceBuffer), O_RDONLY | O_NONBLOCK); if (m_fp == -1) { RTeError(getModuleName(), QString("Failed to open iio device ") + m_deviceBuffer); return; } m_bytesLeft = sizeof(RTEIIOACCEL_DATA); m_bytesGot = 0; } m_timer = startTimer(2); m_startTime = RTeMath::currentUSecsSinceEpoch(); }
String DroidMaintenanceModuleDataComponent::toString(){ StringBuffer str; str << getModuleName() << "\n"; str << "Number of Assigned Structures: " << assignedStructures.size() << "\n"; for (int i = 0; i < assignedStructures.size(); i++) { uint64 objectID = assignedStructures.elementAt(i); str << "\tStructure: " << objectID << "\n"; } return str.toString(); }
bool Builder::doBuildParam( const std::string& module_name, const std::string& param_name, const std::string& value, const std::string& name, int lineno ) { if( module_name == getModuleName() ) return doBuildParam( param_name, value, name, lineno ); return true; }
void Builder::createConfFile( std::ostream& conf, const std::string& module_name ) { if( module_name == getModuleName() ) doCreateConfFile( conf ); else for( std::list< Builder* >::iterator i = m_children.begin(); i != m_children.end(); ++i ) (*i)->createConfFile( conf, module_name ); }
void RTeIIOAccel::stopModule() { if (m_timer != -1) killTimer(m_timer); if (m_useBuffer) { if (m_fp != -1) close(m_fp); if (!setValue("buffer/enable", 0)) { RTeError(getModuleName(), "Failed to disable buffer"); } } }
int cellSysmoduleIsLoaded(u16 id) { cellSysmodule.Warning("cellSysmoduleIsLoaded(%s)", getModuleName(id)); Module* m = GetModuleById(id); if(!m) { return CELL_SYSMODULE_ERROR_UNKNOWN; } return m->IsLoaded() ? CELL_SYSMODULE_LOADED : CELL_SYSMODULE_ERROR_UNLOADED; }
inline void DebugTrace::printDBGMessage(const char *szDebugMessage, const char *funcName, char *modname ) { if(DebugTrace::enableTracing_ && DebugTrace::nestingIndent_ < DEFAULT_INDENT) { //fprintf(stderr,"[%20s]-%s%s-[%d]\n", getModuleName(modname), szDebugMessage, funcName, nestingIndent_); fprintf(stderr,"[%-20s]-%s%s", getModuleName(modname), szDebugMessage, funcName); } }
bool Renderer::addInputObject(int sender, const std::string &senderPort, const std::string & portName, vistle::Object::const_ptr object) { int creatorId = object->getCreator(); CreatorMap::iterator it = m_creatorMap.find(creatorId); if (it != m_creatorMap.end()) { if (it->second.age < object->getExecutionCounter()) { //std::cerr << "removing all created by " << creatorId << ", age " << object->getExecutionCounter() << ", was " << it->second.age << std::endl; removeAllCreatedBy(creatorId); } else if (it->second.age > object->getExecutionCounter()) { std::cerr << "received outdated object created by " << creatorId << ", age " << object->getExecutionCounter() << ", was " << it->second.age << std::endl; return false; } } else { std::string name = getModuleName(object->getCreator()); it = m_creatorMap.insert(std::make_pair(creatorId, Creator(object->getCreator(), name))).first; } Creator &creator = it->second; creator.age = object->getExecutionCounter(); std::shared_ptr<RenderObject> ro; #if 0 std::cout << "++++++Renderer addInputObject " << object->getType() << " creator " << object->getCreator() << " exec " << object->getExecutionCounter() << " block " << object->getBlock() << " timestep " << object->getTimestep() << std::endl; #endif if (auto tex = vistle::Texture1D::as(object)) { if (auto grid = vistle::Coords::as(tex->grid())) { ro = addObject(sender, senderPort, object, grid, grid->normals(), nullptr, tex); } } else if (auto data = vistle::DataBase::as(object)) { if (auto grid = vistle::Coords::as(data->grid())) { ro = addObject(sender, senderPort, object, grid, grid->normals(), nullptr, nullptr); } } if (!ro) { ro = addObject(sender, senderPort, object, object, vistle::Object::ptr(), vistle::Object::ptr(), vistle::Object::ptr()); } if (ro) { vassert(ro->timestep >= -1); if (m_objectList.size() <= size_t(ro->timestep+1)) m_objectList.resize(ro->timestep+2); m_objectList[ro->timestep+1].push_back(ro); } return true; }
bool Module::init(QWidget* parent) { // has it already been init? if (m_isInit) return false; qDebug() << "initializing module: " << getModuleName(); m_parent = parent; QMainWindow::setParent(m_parent); // load properties from file loadProperties(getModuleName()); // init module if (iInit(m_parent)) m_isInit = true; if (m_isInit) qDebug() << "module " << getModuleName() << " was successfully initialized"; // was it successful? return m_isInit; }
s32 cellSysmoduleLoadModule(u16 id) { cellSysmodule.Warning("cellSysmoduleLoadModule(id=0x%04x: %s)", id, getModuleName(id)); if (!Emu.GetModuleManager().CheckModuleId(id)) { cellSysmodule.Error("cellSysmoduleLoadModule() failed: unknown module (id=0x%04x)", id); return CELL_SYSMODULE_ERROR_UNKNOWN; } if (Module* m = Emu.GetModuleManager().GetModuleById(id)) { // CELL_SYSMODULE_ERROR_DUPLICATED shouldn't be returned m->Load(); } return CELL_OK; }
int cellSysmoduleUnloadModule(u16 id) { cellSysmodule.Warning("cellSysmoduleUnloadModule(%s)", getModuleName(id)); Module* m = GetModuleById(id); if(!m) { return CELL_SYSMODULE_ERROR_UNKNOWN; } if(!m->IsLoaded()) { return CELL_SYSMODULE_ERROR_UNLOADED; } m->UnLoad(); return CELL_OK; }
/* ========================================================================== Function Name : (BOOL) RegSetStr() Outline : レジストリキーの値に文字列を書き込む Arguments : HKEY hKey (in) 値を設定するキーのハンドル : LPCTSTR lpszValueName (in) 設定する値 : char *buf (in) 値データ Return Value : 成功 TRUE : 失敗 FALSE Reference : Renewal : Notes : Attention : Up Date : ======1=========2=========3=========4=========5=========6=========7======= */ BOOL RegSetStr(HKEY hKey, LPCTSTR lpszValueName, TCHAR *buf) { if(bUseINI){ return WritePrivateProfileString(szSectionName, lpszValueName, buf, getModuleName()); }else{ long lError; lError = ::RegSetValueEx(hKey, lpszValueName, 0, REG_SZ, (CONST BYTE *) buf, (::lstrlen(buf) + 1) * sizeof(TCHAR)); if (lError != ERROR_SUCCESS) { ::SetLastError(lError); return FALSE; } } return TRUE; }
s32 cellSysmoduleIsLoaded(u16 id) { cellSysmodule.Warning("cellSysmoduleIsLoaded(id=0x%04x: %s)", id, getModuleName(id)); if (!Emu.GetModuleManager().CheckModuleId(id)) { cellSysmodule.Error("cellSysmoduleIsLoaded() failed: unknown module (id=0x%04x)", id); return CELL_SYSMODULE_ERROR_UNKNOWN; } if (Module* m = Emu.GetModuleManager().GetModuleById(id)) { if (!m->IsLoaded()) { cellSysmodule.Error("cellSysmoduleIsLoaded() failed: module not loaded (id=0x%04x)", id); return CELL_SYSMODULE_ERROR_UNLOADED; } } return CELL_SYSMODULE_LOADED; }
/* ========================================================================== Function Name : (BOOL) RegGetStr() Outline : レジストリキーの値から文字列を読み込む Arguments : HKEY hKey (in) 値を設定するキーの : ハンドル : LPCTSTR lpszValueName (in) 設定する値 : char *buf (out) 値データを格納する : バッファ : DWORD dwSize (in/out) 文字数 Return Value : 成功 TRUE : 失敗 FALSE Reference : Renewal : Notes : Attention : Up Date : ======1=========2=========3=========4=========5=========6=========7======= */ BOOL RegGetStr(HKEY hKey, LPCTSTR lpszValueName, TCHAR *buf, DWORD dwSize) { if(bUseINI){ return GetPrivateProfileString(szSectionName, lpszValueName, _T(""), buf, dwSize, getModuleName()); }else{ LONG lError; DWORD dwWriteSize; DWORD dwType = REG_SZ; dwWriteSize = dwSize * sizeof(TCHAR); lError = ::RegQueryValueEx(hKey, lpszValueName, 0, &dwType, (LPBYTE) buf, &dwWriteSize); if (lError != ERROR_SUCCESS) { ::SetLastError(lError); return FALSE; } buf[dwSize - 1] = '\0'; } return TRUE; }
/* ========================================================================== Function Name : (BOOL) RegSetDword() Outline : レジストリキーの値に DWORDを書き込む Arguments : HKEY hKey (in) 値を設定するキーのハンドル : LPCTSTR lpszValueName (in) 設定する値 : DWORD dwValue (in) 値データ Return Value : 成功 TRUE : 失敗 FALSE Reference : Renewal : Notes : Attention : Up Date : ======1=========2=========3=========4=========5=========6=========7======= */ BOOL RegSetDword(HKEY hKey, LPCTSTR lpszValueName, DWORD dwValue) { if(bUseINI){ TCHAR t[64]; _stprintf(t, _T("%d"), dwValue); return WritePrivateProfileString(szSectionName, lpszValueName, t, getModuleName()); }else{ long lError; lError = ::RegSetValueEx(hKey, lpszValueName, 0, REG_DWORD, (CONST BYTE *) &dwValue, sizeof(DWORD)); if (lError != ERROR_SUCCESS) { ::SetLastError(lError); return FALSE; } } return TRUE; }
LONG RegEnumEx(HKEY hKey, DWORD dwIndex, LPTSTR lpName, LPDWORD lpcName, LPDWORD lpReserved, LPTSTR lpClass, LPDWORD lpcClass, PFILETIME lpftLastWriteTime) { static LPCTSTR ptr = szSectionNames; if(bUseINI){ if(*szSectionNames == 0){ GetPrivateProfileSectionNames(szSectionNames, sizeof(szSectionNames), getModuleName()); ptr = szSectionNames; } if(_tcscmp(ptr, _T("TTermMenu")) == 0){ //skip while(*ptr++); // ptr++; } if(*ptr == 0){ return ERROR_NO_MORE_ITEMS; } _tcscpy(lpName, ptr); while(*ptr++); // ptr++; return ERROR_SUCCESS; }else{ return ::RegEnumKeyEx(hKey, dwIndex, lpName, lpcName, lpReserved, lpClass, lpcClass, lpftLastWriteTime); } }
/** * Determine all loaded modules as well as the process module itself for the given process id. */ NaviError LinuxSystem::fillModules(pid_t pid, ModulesMap& modules) { std::string filename = "/proc/" + zylib::zycon::toString(pid) + "/maps"; msglog->log(LOG_ALL, "Trying to read the modules map from file %s", filename.c_str()); std::ifstream file(filename.c_str()); if (!file) { msglog->log(LOG_ALWAYS, "Error: Couldn't read modules map file"); return NaviErrors::COULDNT_READ_MEMORY; } std::vector < std::string > lines; std::string line; while (std::getline(file, line)) { msglog->log(LOG_ALL, "Successfully read line %s from modules map file", line.c_str()); lines.push_back(line); } // 08048000-08053000 r-xp 00000000 08:01 282412 /usr/bin/kdeinit // 08053000-08054000 r--p 0000a000 08:01 282412 /usr/bin/kdeinit // 08054000-08055000 rw-p 0000b000 08:01 282412 /usr/bin/kdeinit // 09f73000-0a016000 rw-p 09f73000 00:00 0 [heap] // b6638000-b6672000 rw-p b6672000 00:00 0 // b66bb000-b66d9000 r-xp 00000000 08:01 352021 /usr/lib/kde3/plugins/styles/plastik.so // b66d9000-b66da000 r--p 0001d000 08:01 352021 /usr/lib/kde3/plugins/styles/plastik.so // b66da000-b66db000 rw-p 0001e000 08:01 352021 /usr/lib/kde3/plugins/styles/plastik.so // b66db000-b66e1000 r--s 00000000 08:01 396230 /var/cache/fontconfig/945677eb7aeaf62f1d50efc3fb3ec7d8-x86.cache-2 // b66e1000-b66e4000 r--s 00000000 08:01 396239 /var/cache/fontconfig/e383d7ea5fbe662a33d9b44caf393297-x86.cache-2 // b66e4000-b66e5000 r--s 00000000 08:01 396225 /var/cache/fontconfig/4c73fe0c47614734b17d736dbde7580a-x86.cache-2 // b66e5000-b66e8000 r--s 00000000 08:01 396231 /var/cache/fontconfig/a755afe4a08bf5b97852ceb7400b47bc-x86.cache-2 // b66e8000-b66ef000 r--s 00000000 08:01 396608 /var/cache/fontconfig/6d41288fd70b0be22e8c3a91e032eec0-x86.cache-2 // b66ef000-b66f7000 r--s 00000000 08:01 396240 /var/cache/fontconfig/e3de0de479f42330eadf588a55fb5bf4-x86.cache-2 // b66f7000-b6702000 r--s 00000000 08:01 396220 /var/cache/fontconfig/0f34bcd4b6ee430af32735b75db7f02b-x86.cache-2 // b6702000-b6709000 r--s 00000000 08:01 396234 /var/cache/fontconfig/d52a8644073d54c13679302ca1180695-x86.cache-2 std::string lastName = ""; CPUADDRESS start = 0; CPUADDRESS end = 0; for (std::vector<std::string>::iterator Iter = lines.begin(); Iter != lines.end(); ++Iter) { std::string line = *Iter; size_t position = line.find("/"); if (position != std::string::npos) { // OK, we found a line with a name; now we gotta figure out if we found a new module // or just with a new section in the same module. std::string name = line.substr(position); // TODO: Only works in 32bit platforms std::string startString = Iter->substr(0, 8); std::string endString = Iter->substr(9, 8); if (name != lastName) { // We found a new module, so we can take the information from the previous // module and add the previous module to the list of modules. if (lastName != "") { Module newModule(getModuleName(lastName), lastName, start, end - start); modules.insert(std::make_pair(lastName, newModule)); } lastName = name; start = zylib::zycon::parseHexString < CPUADDRESS > (startString); end = zylib::zycon::parseHexString < CPUADDRESS > (endString); } else { // The module in the current line is the same module we already processed // in the previous line. Only the end information has to be updated in this // case. end = zylib::zycon::parseHexString < CPUADDRESS > (endString); } } else if (lastName != "") { // We found a line without a name and the previous module has // a valid name => Add the previous module to the list of modules. Module newModule(getModuleName(lastName), lastName, start, end - start); modules.insert(std::make_pair(lastName, newModule)); lastName = ""; } } if (lastName != "") { // Add the last module in the list. Module newModule(getModuleName(lastName), lastName, start, end - start); modules.insert(std::make_pair(lastName, newModule)); } return NaviErrors::SUCCESS; }
/** * Print stack trace (using a specified stack context) to "os" * * @param context CONTEXT record for stack trace * @param os ostream& to receive printed stack backtrace */ void printWindowsStackTrace( CONTEXT& context, std::ostream& os ) { SimpleMutex::scoped_lock lk(_stackTraceMutex); HANDLE process = GetCurrentProcess(); BOOL ret = SymInitialize(process, getSymbolSearchPath(process), TRUE); if ( ret == FALSE ) { DWORD dosError = GetLastError(); log() << "Stack trace failed, SymInitialize failed with error " << std::dec << dosError << std::endl; return; } DWORD options = SymGetOptions(); options |= SYMOPT_LOAD_LINES | SYMOPT_FAIL_CRITICAL_ERRORS; SymSetOptions( options ); STACKFRAME64 frame64; memset( &frame64, 0, sizeof(frame64) ); #if defined(_M_AMD64) DWORD imageType = IMAGE_FILE_MACHINE_AMD64; frame64.AddrPC.Offset = context.Rip; frame64.AddrFrame.Offset = context.Rbp; frame64.AddrStack.Offset = context.Rsp; #elif defined(_M_IX86) DWORD imageType = IMAGE_FILE_MACHINE_I386; frame64.AddrPC.Offset = context.Eip; frame64.AddrFrame.Offset = context.Ebp; frame64.AddrStack.Offset = context.Esp; #else #error Neither _M_IX86 nor _M_AMD64 were defined #endif frame64.AddrPC.Mode = AddrModeFlat; frame64.AddrFrame.Mode = AddrModeFlat; frame64.AddrStack.Mode = AddrModeFlat; const size_t nameSize = 1024; const size_t symbolBufferSize = sizeof(SYMBOL_INFO) + nameSize; boost::scoped_array<char> symbolCharBuffer( new char[symbolBufferSize] ); memset( symbolCharBuffer.get(), 0, symbolBufferSize ); SYMBOL_INFO* symbolBuffer = reinterpret_cast<SYMBOL_INFO*>( symbolCharBuffer.get() ); symbolBuffer->SizeOfStruct = sizeof(SYMBOL_INFO); symbolBuffer->MaxNameLen = nameSize; // build list std::vector<TraceItem> traceList; TraceItem traceItem; size_t moduleWidth = 0; size_t sourceWidth = 0; for ( size_t i = 0; i < maxBackTraceFrames; ++i ) { ret = StackWalk64( imageType, process, GetCurrentThread(), &frame64, &context, NULL, NULL, NULL, NULL ); if ( ret == FALSE || frame64.AddrReturn.Offset == 0 ) { break; } DWORD64 address = frame64.AddrPC.Offset; getModuleName( process, address, &traceItem.moduleName ); size_t width = traceItem.moduleName.length(); if ( width > moduleWidth ) { moduleWidth = width; } getSourceFileAndLineNumber( process, address, &traceItem.sourceAndLine ); width = traceItem.sourceAndLine.length(); if ( width > sourceWidth ) { sourceWidth = width; } getsymbolAndOffset( process, address, symbolBuffer, &traceItem.symbolAndOffset ); traceList.push_back( traceItem ); } SymCleanup( process ); // print list ++moduleWidth; ++sourceWidth; size_t frameCount = traceList.size(); for ( size_t i = 0; i < frameCount; ++i ) { std::stringstream ss; ss << traceList[i].moduleName << " "; size_t width = traceList[i].moduleName.length(); while ( width < moduleWidth ) { ss << " "; ++width; } ss << traceList[i].sourceAndLine << " "; width = traceList[i].sourceAndLine.length(); while ( width < sourceWidth ) { ss << " "; ++width; } ss << traceList[i].symbolAndOffset; log() << ss.str() << std::endl; } }
primitiveModuleName(void) { popthenPush(1, stringFromCString(getModuleName())); return 0; }
/** * Print stack trace (using a specified stack context) to "os" * * @param context CONTEXT record for stack trace * @param os ostream& to receive printed stack backtrace */ void printWindowsStackTrace(CONTEXT& context, std::ostream& os) { auto& symbolHandler = SymbolHandler::instance(); stdx::lock_guard<SymbolHandler> lk(symbolHandler); if (!symbolHandler) { error() << "Stack trace failed, symbol handler returned an invalid handle."; return; } STACKFRAME64 frame64; memset(&frame64, 0, sizeof(frame64)); #if defined(_M_AMD64) DWORD imageType = IMAGE_FILE_MACHINE_AMD64; frame64.AddrPC.Offset = context.Rip; frame64.AddrFrame.Offset = context.Rbp; frame64.AddrStack.Offset = context.Rsp; #elif defined(_M_IX86) DWORD imageType = IMAGE_FILE_MACHINE_I386; frame64.AddrPC.Offset = context.Eip; frame64.AddrFrame.Offset = context.Ebp; frame64.AddrStack.Offset = context.Esp; #else #error Neither _M_IX86 nor _M_AMD64 were defined #endif frame64.AddrPC.Mode = AddrModeFlat; frame64.AddrFrame.Mode = AddrModeFlat; frame64.AddrStack.Mode = AddrModeFlat; const size_t nameSize = 1024; const size_t symbolBufferSize = sizeof(SYMBOL_INFO) + nameSize; std::unique_ptr<char[]> symbolCharBuffer(new char[symbolBufferSize]); memset(symbolCharBuffer.get(), 0, symbolBufferSize); SYMBOL_INFO* symbolBuffer = reinterpret_cast<SYMBOL_INFO*>(symbolCharBuffer.get()); symbolBuffer->SizeOfStruct = sizeof(SYMBOL_INFO); symbolBuffer->MaxNameLen = nameSize; // build list std::vector<TraceItem> traceList; TraceItem traceItem; size_t moduleWidth = 0; size_t sourceWidth = 0; for (size_t i = 0; i < maxBackTraceFrames; ++i) { BOOL ret = StackWalk64(imageType, symbolHandler.getHandle(), GetCurrentThread(), &frame64, &context, NULL, NULL, NULL, NULL); if (ret == FALSE || frame64.AddrReturn.Offset == 0) { break; } DWORD64 address = frame64.AddrPC.Offset; getModuleName(symbolHandler.getHandle(), address, &traceItem.moduleName); size_t width = traceItem.moduleName.length(); if (width > moduleWidth) { moduleWidth = width; } getSourceFileAndLineNumber(symbolHandler.getHandle(), address, &traceItem.sourceAndLine); width = traceItem.sourceAndLine.length(); if (width > sourceWidth) { sourceWidth = width; } getsymbolAndOffset( symbolHandler.getHandle(), address, symbolBuffer, &traceItem.symbolAndOffset); traceList.push_back(traceItem); } // print list ++moduleWidth; ++sourceWidth; size_t frameCount = traceList.size(); for (size_t i = 0; i < frameCount; ++i) { std::stringstream ss; ss << traceList[i].moduleName << " "; size_t width = traceList[i].moduleName.length(); while (width < moduleWidth) { ss << " "; ++width; } ss << traceList[i].sourceAndLine << " "; width = traceList[i].sourceAndLine.length(); while (width < sourceWidth) { ss << " "; ++width; } ss << traceList[i].symbolAndOffset; log() << ss.str(); } }
const NAString StmtDDLDropModule::displayLabel1() const { return NAString("Module name: ") + getModuleName(); }
void initWorkerProcess(struct workerProcess *worker, char *worker_name) { struct configuration *conf; int i; struct app *app; struct moduleAttr *module; if (Server.stat_fd != 0) close(Server.stat_fd); setProctitle(worker_name); worker->pid = getpid(); worker->ppid = getppid(); worker->alive = 1; worker->start_time = Server.cron_time; worker->worker = spotWorker(worker_name); worker->master_stat_fd = 0; ASSERT(worker->worker); worker->stats = NULL; initWorkerSignals(); worker->center = eventcenterInit(WHEAT_CLIENT_MAX); if (!worker->center) { wheatLog(WHEAT_WARNING, "eventcenter_init failed"); halt(1); } if (createEvent(worker->center, Server.ipfd, EVENT_READABLE, acceptClient, NULL) == WHEAT_WRONG) { wheatLog(WHEAT_WARNING, "createEvent failed"); halt(1); } // It may nonblock after fork??? if (wheatNonBlock(Server.neterr, Server.ipfd) == NET_WRONG) { wheatLog(WHEAT_WARNING, "Set nonblock %d failed: %s", Server.ipfd, Server.neterr); halt(1); } module = NULL; conf = getConfiguration("protocol"); if (conf->target.ptr) { module = getModule(PROTOCOL, conf->target.ptr); if (module && getProtocol(module)->initProtocol() == WHEAT_WRONG) { wheatLog(WHEAT_WARNING, "init protocol failed"); halt(1); } } if (!module) { wheatLog(WHEAT_WARNING, "find protocol %s failed", conf->target.ptr); halt(1); } worker->protocol = getProtocol(module); StatTotalClient = getStatItemByName("Total client"); gettimeofday(&Server.cron_time, NULL); if (worker->worker->setup) worker->worker->setup(); WorkerProcess->refresh_time = Server.cron_time.tv_sec; FreeClients = createAndFillPool(); Clients = createList(); StatBufferSize = getStatItemByName("Max buffer size"); StatTotalRequest = getStatItemByName("Total request"); StatFailedRequest = getStatItemByName("Total failed request"); StatRunTime = getStatItemByName("Worker run time"); worker->apps = arrayCreate(sizeof(struct app*), 3); if (!worker->apps) { wheatLog(WHEAT_WARNING, "array create failed"); halt(1); } getAppsByProtocol(worker->apps, worker->protocol); for (i = 0; i < narray(worker->apps); i++) { app = *(struct app**)arrayIndex(worker->apps, i); if (app->initApp(worker->protocol) == WHEAT_WRONG) { wheatLog(WHEAT_WARNING, "init app failed %s", getModuleName(APP, app)); halt(1); } } sendStatPacket(WorkerProcess); }