📄 symlib.c
字号:
) { return (symFindByValueAndType (symTblId, value, name, pValue, pType, SYM_MASK_ANY_TYPE, SYM_MASK_ANY_TYPE)); }/********************************************************************************* symFindByValueAndType - look up a symbol by value and type** This routine is obsolete. It is replaced by the routine* symByValueAndTypeFind().* * 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. The symbol name (with terminating* EOS), the actual value, and the type are copied to <name>, <pValue>, and* <pType>. The <mask> parameter can be used to match sub-classes of type.** 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>.* * INTERNAL* This routine contains a weird hack designed to deal with the additional* symbols the loader puts in the symbol table. The loader adds three symbols* to the symbol table: <filename>_text, <filename>_data, <filename>_bss.* These symbols may have the same address (i.e. value in the symbol table)* as real routine or variable names. When looking up a symbol for display* it is desirable to find the real routine or variable names in preference* to these made up names. For example, loading "demo.o" will cause a* symbol "demo.o_text" to be added to the symbol table with the same value* as the real symbol "_demo". In a disassembly or "i" printout, etc, we* would rather see "_demo". So the test inside the loop in this routine* that normally terminates the search if we find an exact match, has been* changed to keep searching if the match it finds ends in "_text", "_data",* or "_bss". ** If no other exact match is found, the special symbols will be returned* 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 or <value> is less* than the lowest value in the table. */STATUS symFindByValueAndType ( 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 */ SYM_TYPE sType, /* symbol type to look for */ SYM_TYPE mask /* bits in <sType> to pay attention to */ ) { SYMBOL * pSymbol = NULL; if (symFindSymbol (symTblId, NULL, (char *) value, sType, mask, &pSymbol) != OK) { /* * remap the errno for backward compatibility - can't change * what errno's are returned for a particular failure mode */ if (errno == S_symLib_INVALID_SYMTAB_ID) errnoSet (S_objLib_OBJ_ID_ERROR); return ERROR; } /* * XXX - JLN - This API is broken and should not be used anymore. * The next line is the best of several bad options for providing * some version of this routine for backward compatibility. We * truncate the number of characters we return to match the size * that the documentation tells the caller to allocate. */ strncpy (name, pSymbol->name, MAX_SYS_SYM_LEN + 1); /* Null-terminate the string in case the name was truncated. */ if (name[MAX_SYS_SYM_LEN] != EOS) name[MAX_SYS_SYM_LEN] = EOS; if (pValue != NULL) *pValue = (int) pSymbol->value; if (pType != NULL) *pType = pSymbol->type; return (OK); }/********************************************************************************* symEach - call a routine to examine each entry in a symbol table** This routine calls a user-supplied routine to examine each entry in the* symbol table; it calls the specified routine once for each entry. The* routine should be declared as follows:* .CS* BOOL routine* (* char *name, /@ entry name @/* int val, /@ value associated with entry @/* SYM_TYPE type, /@ entry type @/* int arg, /@ arbitrary user-supplied arg @/* UINT16 group /@ group number @/* )* .CE* The user-supplied routine should return TRUE if symEach() is to continue* calling it for each entry, or FALSE if it is done and symEach() can exit.** RETURNS: A pointer to the last symbol reached,* or NULL if all symbols are reached.** INTERNAL* In addition to the parameters given, it also passes a pointer to a symbol* as the last arguement.**/SYMBOL *symEach ( SYMTAB_ID symTblId, /* pointer to symbol table */ FUNCPTR routine, /* func to call for each tbl entry */ int routineArg /* arbitrary user-supplied arg */ ) { SYMBOL *pSymbol; RTN_DESC rtnDesc; if (OBJ_VERIFY (symTblId, symTblClassId) != OK) return (NULL); /* invalid symbol table ID */ /* fill in a routine descriptor with the routine and argument to call */ rtnDesc.routine = routine; rtnDesc.routineArg = routineArg; semTake (&symTblId->symMutex, WAIT_FOREVER); pSymbol = (SYMBOL *) hashTblEach (symTblId->nameHashId, symEachRtn, (int) &rtnDesc); semGive (&symTblId->symMutex); /* release exclusion to table */ return (pSymbol); /* symbol we stopped on */ }/********************************************************************************* symEachRtn - call a user routine for a hashed symbol** This routine supports hashTblEach(), by unpackaging the routine descriptor* and calling the user routine specified to symEach() with the right calling* sequence.** RETURNS: Boolean result of user specified symEach routine.** NOMANUAL*/LOCAL BOOL symEachRtn ( SYMBOL *pSymbol, /* ptr to symbol */ RTN_DESC *pRtnDesc /* ptr to a routine descriptor */ ) { return ((* pRtnDesc->routine) (pSymbol->name, (int) pSymbol->value, pSymbol->type, pRtnDesc->routineArg, pSymbol->group, pSymbol)); }/********************************************************************************* symHFuncName - symbol name hash function** This routine checksums the name and applies a multiplicative hashing function* provided by hashFuncMultiply().** RETURNS: An integer between 0 and (elements - 1).*/LOCAL int symHFuncName ( int elements, /* no. of elements in hash table */ SYMBOL *pSymbol, /* pointer to symbol */ int seed /* seed to be used as scalar */ ) { int hash; char *tkey; int key = 0; /* checksum the string and use a multiplicative hashing function */ for (tkey = pSymbol->name; *tkey != '\0'; tkey++) key = key + (unsigned int) *tkey; hash = key * seed; /* multiplicative hash func */ hash = hash >> (33 - ffsMsb (elements)); /* take only the leading bits */ return (hash & (elements - 1)); /* mask hash to (0,elements-1)*/ }/********************************************************************************* symKeyCmpName - compare two symbol's names for equivalence** This routine returns TRUE if the match symbol's type masked by the specified* symbol mask, is equivalent to the second symbol's type also masked by the* symbol mask, and if the symbol's names agree.** RETURNS: TRUE if symbols match, FALSE if they differ.*/LOCAL BOOL symKeyCmpName ( SYMBOL *pMatchSymbol, /* pointer to match criteria symbol */ SYMBOL *pSymbol, /* pointer to symbol */ int maskArg /* symbol type bits than matter (int) */ ) { SYM_TYPE mask; /* symbol type bits than matter (char)*/ /* * If maskArg is equal to SYM_MASK_EXACT, then check to see if the pointers * match exactly. */ if (maskArg == SYM_MASK_EXACT) return (pMatchSymbol == pSymbol ? TRUE : FALSE); mask = (SYM_TYPE) maskArg; return (((pSymbol->type & mask) == (pMatchSymbol->type & mask)) && (strcmp (pMatchSymbol->name, pSymbol->name) == 0)); }/********************************************************************************* symName - get the name associated with a symbol value** This routine returns a pointer to the name of the symbol of specified value.** RETURNS: A pointer to the symbol name, or* NULL if symbol cannot be found or <symTbl> doesn't exist.** NOMANUAL*/char *symName ( SYMTAB_ID symTbl, /* symbol table */ char *value /* symbol value */ ) { SYMBOL sym; sym.value = (void *)value; /* initialize symbol */ sym.name = NULL; (void)symEach (symTbl, (FUNCPTR) symNameValueCmp, (int) (&sym)); return (sym.name); }/********************************************************************************* symNameValueCmp - compares a symbol value with a name** This routine was written to be invoked by symEach().* <pSym> is a pointer to a symbol which contains a value that this routine* compares to the passed symbol value <val>. If the two values match, then the* name field in <pSym>'s name field is set to point to the symbol name in the* symbol table.** RETURNS: FALSE if <val> matches <pSym>->value and sets <pSym>->name,* or TRUE otherwise.*/LOCAL BOOL symNameValueCmp ( char *name, /* symbol name */ int val, /* symbol value */ SYM_TYPE type, /* symbol type -- not used */ int pSym /* pointer to symbol trying to be matched */ ) { if (val == (int) (((SYMBOL *)pSym)->value)) { ((SYMBOL *)pSym)->name = name; return (FALSE); } return (TRUE); }/********************************************************************************* symNameGet - get name of a symbol* * This routine is currently intended only for internal use. ** It provides the name of the symbol specified by the SYMBOL_ID* <symbolId>. The SYMBOL_ID of a symbol may be obtained by using the* routine symFindSymbol(). A pointer to the symbol table's copy of the* symbol name is returned in <pName>.** RETURNS: OK, or ERROR if either <pName> or <symbolId> is NULL.** NOMANUAL */STATUS symNameGet ( SYMBOL_ID symbolId, char ** pName ) { if ((symbolId == NULL) || (pName == NULL)) return ERROR; *pName = symbolId->name; return OK; }/********************************************************************************* symValueGet - get value of a symbol* * This routine is currently intended only for internal use. ** It provides the value of the symbol specified by the SYMBOL_ID* <symbolId>. The SYMBOL_ID of a symbol may be obtained by using the* routine symFindSymbol(). The value of the symbol is copied to * the location specified by <pValue>.** RETURNS: OK, or ERROR if either <pValue> or <symbolId> is NULL.** NOMANUAL */STATUS symValueGet ( SYMBOL_ID symbolId, void ** pValue ) { if ((symbolId == NULL) || (pValue == NULL)) return ERROR; *pValue = symbolId->value; return OK; }/********************************************************************************* symTypeGet - get type of a symbol* * This routine is currently intended only for internal use. ** It provides the type of the symbol specified by the SYMBOL_ID* <symbolId>. The SYMBOL_ID of a symbol may be obtained by using the* routine symFindSymbol(). The type of the symbol is copied to * the location specified by <pType>.** RETURNS: OK, or ERROR if either <pType> or <symbolId> is NULL.** NOMANUAL */STATUS symTypeGet ( SYMBOL_ID symbolId, SYM_TYPE * pType ) { if ((symbolId == NULL) || (pType == NULL)) return ERROR; *pType = symbolId->type; return OK; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -