📄 symsynclib.c
字号:
return (status); }/******************************************************************************** syncTgtModInfoFill - fill target module information** From a host module descriptor we get the information to store on the target* side.** note: flag LOAD_LOADED_BY_TGTSVR is set in order we know that if the* target-server restarts these modules become obsolete.* note: To prevent from displaying 0xffffffff on target moduleShow(), segment* address is set to 0 when the segment does not exist.* note: The segment flag SEG_FREE_MEMORY is removed to prevent the memory from* being freed twice when unloading (1 by host and 1 by target).** RETURNS: target module Id or NULL.** NOMANUAL*/MODULE_ID syncTgtModInfoFill ( WTX_MODULE_INFO * pModInfo ) { MODULE_ID modId; int format = -1; int flags = 0; int segType; int segAddr; int ix; STATUS status = OK; /* tarnslate host format into target format */ if (strcmp (pModInfo->format, "a.out") == 0) format = MODULE_A_OUT; else if (strcmp (pModInfo->format, "coff") == 0) format = MODULE_ECOFF; else if (strcmp (pModInfo->format, "elf") == 0) format = MODULE_ELF; /* translate host load flags into target host flags */ if (pModInfo->loadFlag & 0x1) flags |= LOAD_NO_SYMBOLS; if (pModInfo->loadFlag & 0x2) flags |= LOAD_LOCAL_SYMBOLS; if (pModInfo->loadFlag & 0x4) flags |= LOAD_GLOBAL_SYMBOLS; flags |= (pModInfo->loadFlag & 0x00fffff0); flags |= LOAD_LOADED_BY_TGTSVR; /* create the module on the target */ if ((modId = moduleCreate (pModInfo->moduleName, format, flags)) == NULL) return (NULL); /* add the segments */ for (ix = 0; (ix < pModInfo->nSegments) && (status == OK); ix++) { switch (ix) { case 0: segType = SEGMENT_TEXT; break; case 1: segType = SEGMENT_DATA; break; case 2: segType = SEGMENT_BSS; break;#ifdef INCLUDE_SDA case 3: segType = SEGMENT_SDATA; break; case 4: segType = SEGMENT_SBSS; break; case 5: segType = SEGMENT_SDATA2; break; case 6: segType = SEGMENT_SBSS2; break;#endif default: segType = -1; break; } segAddr = ((int)pModInfo->segment[ix].addr != -1) ? (int)pModInfo->segment[ix].addr : 0; status = moduleSegAdd (modId, segType, (void *)segAddr, pModInfo->segment[ix].length, (pModInfo->segment[ix].flags & ~SEG_FREE_MEMORY)); } if (status == OK) return (modId); else { moduleDelete (modId); return (NULL); } }/* TARGET ----> HOST *//******************************************************************************** symSyncHostUpdate - update host side depending on <evtString>** This routine dispatch the WTX events received from the target server** RETURNS:** NOMANUAL*/STATUS symSyncHostUpdate ( HWTX hWtx, /* WTX API handle */ char * evtString, /* event received */ char * doneEvt /* event sent when sync is done */ ) { char * pLast = NULL; STATUS status = OK; char * evtType; /* synchronization event type */ char * info[4]; /* store event tokens */ BOOL eventSend = TRUE; evtType = strtok_r (evtString, " ", &pLast); if (strcmp (evtType, OBJ_LOADED_EVT) == 0) { info[1] = strtok_r (NULL, " ", &pLast); /* module id */ info[0] = strtok_r (NULL, " ", &pLast); /* module name */ status = syncModCHostUpdate (hWtx, &symSyncLst, (MODULE_ID)H_STR_TO_L(info[1]), &eventSend, TRUE); } else if (strcmp (evtType, OBJ_UNLOADED_EVT) == 0) { info[0] = strtok_r (NULL, " ", &pLast); /* mod name */ info[1] = strtok_r (NULL, " ", &pLast); /* mod group */ status = syncModDHostUpdate (hWtx, info[0], H_STR_TO_L(info[1])); } else if (strcmp (evtType, SYM_ADDED_EVT) == 0) { info[0] = strtok_r (NULL, " ", &pLast); /* sym name */ info[1] = strtok_r (NULL, " ", &pLast); /* sym val */ info[2] = strtok_r (NULL, " ", &pLast); /* sym type */ info[3] = strtok_r (NULL, " ", &pLast); /* sym group */ status = syncSymAddHostUpdate (hWtx, info[0], (char *)H_STR_TO_L(info[1]), H_STR_TO_L(info[2]), H_STR_TO_L(info[3])); } else if (strcmp (evtType, SYM_REMOVED_EVT) == 0) { info[0] = strtok_r (NULL, " ", &pLast); /* sym name */ info[1] = strtok_r (NULL, " ", &pLast); /* sym type */ status = syncSymRemHostUpdate (hWtx, info[0], H_STR_TO_L(info[1])); } else if (strcmp (evtType, USR_RQST_EVT) == 0) { info[0] = "target_modules"; info[1] = strtok_r (NULL, " ", &pLast); /* sense */ info[2] = strtok_r (NULL, " ", &pLast); /* starting tgtsvr? */ status = syncUsrUpdate (hWtx, H_STR_TO_L(info[1]), H_STR_TO_L(info[2])); } else {#ifdef DEBUG logMsg ("unknown target event\n", 0, 0, 0, 0, 0, 0);#endif return (OK); } if (eventSend) { if (strlen (info[0]) > OBJ_NAME_MAX) info[0][OBJ_NAME_MAX - 1] = '\0'; sprintf (doneEvt, "SYNC_DONE h %s %s %d", evtType, info[0], status); wtxEventAdd (hWtx, doneEvt, 0, NULL); } return (status); }/******************************************************************************** syncModCHostUpdate - update host side when a module is created on target** This routine creates a module on the host with the same information than on* the target (except group number). If <addSym> is TRUE the routine looks for* the symbol of that module and add them in the host symbol table, otherwise* symbols are not added here.** RETURNS:** NOMANUAL*/STATUS syncModCHostUpdate ( HWTX hWtx, /* WTX API handle */ DL_LIST * pList, /* where to add the synchronized module */ MODULE_ID modId, /* target module Id */ BOOL * pEventSend, /* send back an event when synchro is done */ BOOL addSym /* add module's symbol or not */ ) { STATUS status = OK; /* synchro status */ WTX_LD_M_FILE_DESC in; /* host mod creation input */ WTX_LD_M_FILE_DESC * pObjInfo; /* object file info */ WTX_MODULE_INFO * pModInfo; /* host module info */ BY_GROUP_ARG_T modFind; MODULE sMod; /* stored module */ /* store module information to get them safely later */ taskLock(); if (OBJ_VERIFY (modId, moduleClassId) == OK) memcpy (&sMod, modId, sizeof(MODULE)); else { taskUnlock (); return (ERROR); } taskUnlock(); /* check if the module was previously synchronized */ if (groupFind (&symSyncLst, sMod.group, isInTgtGroupList) != NULL) { /* we do not send an event to tgtsvr because no work is performed */ *pEventSend = FALSE; return (OK); } /* prepare host module creation */ if (syncHostModInfoFill (&in, &sMod, TRUE) == ERROR) return (ERROR); /* create the host module (flag LOAD_MODULE_INFO_ONLY is set) */ if ((pObjInfo = wtxObjModuleLoad (hWtx, &in)) == NULL) { free (in.filename); free (in.section); return (ERROR); } free (in.filename); free (in.section); /* get newly created host module information */ if ((pModInfo = wtxObjModuleInfoGet (hWtx, pObjInfo->moduleId)) == NULL) { wtxResultFree (hWtx, pObjInfo); return (ERROR); } /* add the module in the synchronized group list */ groupAdd (pList, sMod.group, pModInfo->group); if (addSym) { /* add the symbols of the new module */ /* * XXX ELP there is no routine that returns a symbol list as tgtsvr does. * The solution is to go through the whole symTbl and add the concerned * symbols one by one. Building a list and sending it once should be faster. */ modFind.hWtx = hWtx; modFind.tgtGroup = sMod.group; modFind.hostGroup = pModInfo->group; if (symEach (sysSymTbl, (FUNCPTR)syncSymByGrpToHost, (int)&modFind) != NULL) /* because of an error we did not go through the all list */ status = ERROR; } wtxResultFree (hWtx, pObjInfo); wtxResultFree (hWtx, pModInfo); return (status); }/******************************************************************************** syncModDHostUpdate - upadte host side when a module is deleted on target** RETURNS:** NOMANUAL*/STATUS syncModDHostUpdate ( HWTX hWtx, /* WTX API handle */ char * modName, /* name of the deleted module */ UINT16 modGroup /* group of the deleted module */ ) { GROUP_NODE * pGroup; UINT32 moduleId = 0; /* remove the module from the synchronized group list */ if ((pGroup = groupRemove (&symSyncLst, modGroup , isInTgtGroupList)) == NULL) return (OK); free (pGroup); /* check to see if the module should be unloaded on host side */ moduleId = wtxObjModuleFindId (hWtx, modName); if (moduleId) wtxObjModuleUnload (hWtx, moduleId); return (OK); }/******************************************************************************** syncSymAddHostUpdate - update host symTbl when a symbol is added on target** RETURNS: ** NOMANUAL*/STATUS syncSymAddHostUpdate ( HWTX hWtx, /* WTX API handle */ char * name, /* symbol name */ char * val, /* symbol value */ SYM_TYPE type, /* symbol type */ UINT16 group /* symbol group */ ) { GROUP_NODE * pGroup; UINT32 hGroup; MODULE_ID modId; STATUS status = OK; BOOL eventSend = TRUE; char buf[SYNC_TGT_EVT_LGTH]; char doneEvt[SYNC_TGT_EVT_LGTH]; /* find the corresponding host group */ if (group == symGroupDefault) hGroup = 0; else if ((pGroup = groupFind (&symSyncLst, group, (FUNCPTR)isInTgtGroupList)) != NULL) hGroup = pGroup->hostGroup; else { /* symbol's group is unknown on host side */ if ((modId = moduleFindByGroup (group)) == NULL) hGroup = 0; /* XXX ELP */ else { /* * it seems very hard to come here but... we answer we failed * and try to load the unsynchronized module. */ memset (buf, 0, SYNC_TGT_EVT_LGTH); taskLock(); if (OBJ_VERIFY (modId, moduleClassId) == OK) { strncpy (buf, modId->name, SYNC_TGT_EVT_LGTH - 1); buf[SYNC_TGT_EVT_LGTH - 1] = EOS; } taskUnlock(); status = syncModCHostUpdate (hWtx, &symSyncLst, modId, &eventSend, FALSE); if (eventSend) { if (strlen (buf) > OBJ_NAME_MAX) buf [OBJ_NAME_MAX - 1] = '\0'; sprintf (doneEvt, "SYNC_DONE h OBJ_LOADED %s %d", buf, status); wtxEventAdd (hWtx, doneEvt, 0, NULL); } return (status); } } if (wtxSymAddWithGroup (hWtx, name, (TGT_ADDR_T)val, type, hGroup) == WTX_ERROR) status = ERROR; return (status); }/******************************************************************************** syncSymRemHostUpdate - update host symTbl when a target symbol is removed* * This routine is called if the target remove a symbol.** RETURNS: OK or ERROR.** NOMANUAL*/STATUS syncSymRemHostUpdate ( HWTX hWtx, /* WTX API handle */ char * symName, /* symbol name */ SYM_TYPE symType /* symbol type */ ) { STATUS status = OK; if (wtxSymRemove (hWtx, symName, symType) == WTX_ERROR) status = ERROR; return (status); }/******************************************************************************** syncUsrUpdate - update target from host and host from target** This routine is called when the user asks for it.* if <sense> is 1 then synchronization is done from target to host.** the following is unused* if <sense> is 2 then synchronization is done from host to target. * if <sense> is 0 then both synchronization are performed. * <toolId> is used to identify the tool that requested for synchronization** note: host symbols that don't belong to a module are not synchronized.** RETURNS: OK or ERROR.** NOMANUAL*/STATUS syncUsrUpdate ( HWTX hWtx, /* WTX API handle */ int sense, /* synchronization sense */ int start /* TRUE if the target server is starting */ ) { WTX_MODULE_LIST * pModList; STATUS status = OK; int ix; char evtBuf[60]; if ((sense == 0) || (sense == 1)) { /* * Check every modules that will be synchronized are target modules. * Otherwise the target server may have restarted, thus it considers * segments are no more allocated! */ if (start) { moduleEach (syncTgtSafeModCheck, (int) hWtx); } /* process each symbol of the target symbol table */ if (OBJ_VERIFY (sysSymTbl, symTblClassId) == OK) { if (symEach (sysSymTbl, (FUNCPTR)syncEachSymToHost, (int)hWtx) != NULL) return (ERROR); /* add modules that was not yet in the sync group list */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -