📄 symlib.c
字号:
* anyway. Thus this routine simply has a "bias" against such symbols, but* will not return an erroneous result in any event. This nonsense should be* removed when the loader is changed to not add the special symbols.** The GNU toolkit adds symbols of the form "gcc2_compiled." and "xxx.o".* These symbols are also biased against. ** RETURNS: OK, or ERROR if <symTblId> is invalid, <pSymbolId> is NULL,* symbol not found (for a search by name), or if <value> is less than* the lowest value in the table (for search by value).** NOMANUAL */STATUS symFindSymbol ( SYMTAB_ID symTblId, /* symbol table ID */ char * name, /* name to search for */ void * value, /* value of symbol to search for */ SYM_TYPE type, /* symbol type */ SYM_TYPE mask, /* type bits that matter */ SYMBOL_ID * pSymbolId /* where to return id of matching symbol */ ) { HASH_NODE * pNode; /* node in symbol hash table */ SYMBOL keySymbol; /* dummy symbol for search by name */ int index; /* counter for search by value */ SYMBOL * pSymbol; /* current symbol, search by value */ SYMBOL * pBestSymbol = NULL; /* symbol with lower value, matching type */ char * pUnder; /* string for _text, etc., check */ void * bestValue = NULL; /* current value of symbol with matching type */ if ((symTblId == NULL) || (OBJ_VERIFY (symTblId, symTblClassId) != OK)) { errnoSet (S_symLib_INVALID_SYMTAB_ID); return (ERROR); } if (pSymbolId == NULL) { errnoSet (S_symLib_INVALID_SYM_ID_PTR); return (ERROR); } if (name != NULL) { /* Search by name or by name and type: */ /* fill in keySymbol */ keySymbol.name = name; /* match this name */ keySymbol.type = type; /* match this type */ semTake (&symTblId->symMutex, WAIT_FOREVER); pNode = hashTblFind (symTblId->nameHashId, &keySymbol.nameHNode, (int)mask); semGive (&symTblId->symMutex); /* release exclusion to table */ if (pNode == NULL) { errnoSet (S_symLib_SYMBOL_NOT_FOUND); /* couldn't find symbol */ return (ERROR); } *pSymbolId = (SYMBOL_ID) pNode; } else { /* Search by value or by value and type: */ semTake (&symTblId->symMutex, WAIT_FOREVER); for (index = 0; index < symTblId->nameHashId->elements; index++) { pSymbol = (SYMBOL *) SLL_FIRST(&symTblId->nameHashId->pHashTbl [index]); while (pSymbol != NULL) /* list empty */ { if (((pSymbol->type & mask) == (type & mask)) && (pSymbol->value == value) && (((pUnder = rindex (pSymbol->name, '_')) == NULL) || ((strcmp (pUnder, "_text") != 0) && (strcmp (pUnder, "_data") != 0) && (strcmp (pUnder, "_bss") != 0) && (strcmp (pUnder, "_compiled.") != 0))) && (((pUnder = rindex (pSymbol->name, '.')) == NULL) || ((strcmp (pUnder, ".o") != 0)))) { /* We've found the entry. Return it. */ *pSymbolId = pSymbol; semGive (&symTblId->symMutex); return (OK); } else if (((pSymbol->type & mask) == (type & mask)) && ((pSymbol->value <= value) && (pSymbol->value > bestValue))) { /* * this symbol is of correct type and closer than last one */ bestValue = pSymbol->value; pBestSymbol = pSymbol; } pSymbol = (SYMBOL *) SLL_NEXT (&pSymbol->nameHNode); } } if (bestValue == NULL || pBestSymbol == NULL) /* any closer symbol? */ { semGive (&symTblId->symMutex); /* release exclusion to table */ errnoSet (S_symLib_SYMBOL_NOT_FOUND); return (ERROR); } *pSymbolId = pBestSymbol; semGive (&symTblId->symMutex); /* release exclusion to table */ } return (OK); }/********************************************************************************* symFindByName - look up a symbol by name** This routine searches a symbol table for a symbol matching a specified* name. If the symbol is found, its value and type are copied to <pValue>* and <pType>. If multiple symbols have the same name but differ in type,* the routine chooses the matching symbol most recently added to the symbol* table.** To search the global VxWorks symbol table, specify \f3sysSymTbl\f1* as <symTblId>.* * RETURNS: OK, or ERROR if the symbol table ID is invalid* or the symbol cannot be found.*/STATUS symFindByName ( SYMTAB_ID symTblId, /* ID of symbol table to look in */ char *name, /* symbol name to look for */ char **pValue, /* where to put symbol value */ SYM_TYPE *pType /* where to put symbol type */ ) { return (symFindByNameAndType (symTblId, name, pValue, pType, SYM_MASK_ANY_TYPE, SYM_MASK_ANY_TYPE)); }/********************************************************************************* symByCNameFind - find a symbol in a symbol table, look for a '_'** Find a symbol in the table, by name. If the symbol isn't found,* try looking for it with a '_' prepended to it. If we find the* symbol, we fill in the type and the value of the symbol.** RETURNS: OK, or ERROR if <symTblId> is invalid or symbol is not found.** INTERNAL* The size of the symbol name is NOT limited.** NOMANUAL*/STATUS symByCNameFind ( SYMTAB_ID symTblId, /* ID of symbol table to look in */ char * name, /* symbol name to look for */ char ** pValue, /* where to put symbol value */ SYM_TYPE * pType /* where to put symbol type */ ) { char * symBuf = NULL; STATUS retVal; if (symFindByName (symTblId, name, pValue, pType) == ERROR) { /* prepend a '_' and try again */ /* * XXX JLN - KHEAP_ALLOC isn't necessary for this function - * it should be rewritten to search directly and not use KHEAP_ALLOC. */ if ((symBuf = (char *) KHEAP_ALLOC (strlen (name) + 2)) == NULL) return ERROR; *symBuf = '_'; strcpy (&symBuf[1], name); retVal = symFindByName (symTblId, symBuf, pValue, pType); KHEAP_FREE (symBuf); return (retVal); } return (OK); }/********************************************************************************* symFindByCName - find a symbol in a symbol table, look for a '_'** This routine is obsolete. It is replaced by the routine* symByCNameFind(). * Find a symbol in the table, by name. If the symbol isn't found, try* looking for it with a '_' prepended to it. If we find the symbol,* we fill in the type and the value of the symbol.** RETURNS: OK, or ERROR if <symTblId> is invalid or symbol is not found.** INTERNAL* The size of the symbol name is no longer limited by MAX_SYS_SYM_LEN.* * NOMANUAL */STATUS symFindByCName ( SYMTAB_ID symTblId, /* ID of symbol table to look in */ char *name, /* symbol name to look for */ char **pValue, /* where to put symbol value */ SYM_TYPE *pType /* where to put symbol type */ ) { return symByCNameFind (symTblId, name, pValue, pType); }/********************************************************************************* symFindByNameAndType - look up a symbol by name and type** This routine searches a symbol table for a symbol matching both name and* type (<name> and <sType>). If the symbol is found, its value and type are* copied to <pValue> and <pType>. The <mask> parameter can be used to match* sub-classes of type.** To search the global VxWorks symbol table, specify \f3sysSymTbl\f1* as <symTblId>.* * RETURNS: OK, or ERROR if the symbol table ID is invalid* or the symbol is not found.*/STATUS symFindByNameAndType ( SYMTAB_ID symTblId, /* ID of symbol table to look in */ char *name, /* symbol name to look for */ char **pValue, /* where to put symbol value */ SYM_TYPE *pType, /* where to put symbol type */ SYM_TYPE sType, /* symbol type to look for */ SYM_TYPE mask /* bits in <sType> to pay attention to */ ) { SYMBOL *pSymbol = NULL; if (symFindSymbol (symTblId, name, NULL, sType, mask, &pSymbol) == ERROR) return (ERROR); if (pValue != NULL) *pValue = (char *) pSymbol->value; if (pType != NULL) *pType = pSymbol->type; return OK; }/********************************************************************************* symByValueFind - look up a symbol by value** This routine searches a symbol table for a symbol matching a* specified value. If there is no matching entry, it chooses the* table entry with the next lower value. A pointer to a copy of the* symbol name string (with terminating EOS) is returned into* <pName>. The actual value and the type are copied to <pValue> and* <pType>.** <pName> is a pointer to memory allocated by symByValueFind; * the memory must be freed by the caller after the use of <pName>.** To search the global VxWorks symbol table, specify \f3sysSymTbl\f1* as <symTblId>.** RETURNS: OK or ERROR if <symTblId> is invalid, <pName> is NULL, or* <value> is less than the lowest value in the table.*/STATUS symByValueFind ( SYMTAB_ID symTblId, /* ID of symbol table to look in */ UINT value, /* value of symbol to find */ char ** pName, /* where return symbol name string */ int * pValue, /* where to put symbol value */ SYM_TYPE * pType /* where to put symbol type */ ) { return (symByValueAndTypeFind (symTblId, value, pName, pValue, pType, SYM_MASK_ANY_TYPE, SYM_MASK_ANY_TYPE)); }/********************************************************************************* symByValueAndTypeFind - look up a symbol by value and type** This routine searches a symbol table for a symbol matching both* value and type (<value> and <sType>). If there is no matching* entry, it chooses the table entry with the next lower value (among* entries with the same type). A pointer to the symbol name string* (with terminating EOS) is returned into <pName>. The actual value* and the type are copied to <pValue> and <pType>. The <mask>* parameter can be used to match sub-classes of type.* * <pName> is a pointer to memory allocated by symByValueAndTypeFind; * the memory must be freed by the caller after the use of <pName>.** To search the global VxWorks symbol table, specify \f3sysSymTbl\f1* as <symTblId>.** RETURNS: OK or ERROR if <symTblId> is invalid, <pName> is NULL, or* <value> is less than the lowest value in the table.*/STATUS symByValueAndTypeFind ( SYMTAB_ID symTblId, /* ID of symbol table to look in */ UINT value, /* value of symbol to find */ char ** pName, /* where to return symbol name string */ int * pValue, /* where to put symbol value */ SYM_TYPE * pType, /* where to put symbol type */ SYM_TYPE sType, /* symbol type to look for */ SYM_TYPE mask /* bits in <sType> to pay attention to */ ) { SYMBOL * pSymbol = NULL; if (pName == NULL) return ERROR; if (symFindSymbol(symTblId, NULL, (char *)value, sType, mask, &pSymbol) != OK) return ERROR; if (pValue != NULL) *pValue = (int) pSymbol->value; if (pType != NULL) *pType = pSymbol->type; if (((*pName) = (char *) malloc (strlen (pSymbol->name) + 1)) == NULL) return ERROR; strcpy ((*pName), pSymbol->name); return (OK); }/********************************************************************************* symFindByValue - look up a symbol by value** This routine is obsolete. It is replaced by symByValueFind().** This routine searches a symbol table for a symbol matching a specified* value. If there is no matching entry, it chooses the table entry with the* next lower value. The symbol name (with terminating EOS), the actual* value, and the type are copied to <name>, <pValue>, and <pType>.** For the <name> buffer, allocate MAX_SYS_SYM_LEN + 1 bytes. The value* MAX_SYS_SYM_LEN is defined in sysSymTbl.h. If the name of the symbol * is longer than MAX_SYS_SYM_LEN bytes, it will be truncated to fit into the* buffer. Whether or not the name was truncated, the string returned in the* buffer will be null-terminated.** To search the global VxWorks symbol table, specify \f3sysSymTbl\f1* as <symTblId>.* * RETURNS: OK, or ERROR if <symTblId> is invalid or <value> is less* than the lowest value in the table. */STATUS symFindByValue ( SYMTAB_ID symTblId, /* ID of symbol table to look in */ UINT value, /* value of symbol to find */ char * name, /* where to put symbol name string */ int * pValue, /* where to put symbol value */ SYM_TYPE * pType /* where to put symbol type */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -