mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
Some fixes for the expression evaluator:
Evaluate static symbols Evaulate local symbols Still has bugs locating type definitions, at least for pointer types There also seems to be a bug matching up lines of source with the correct instruction addresses svn path=/trunk/; revision=2690
This commit is contained in:
parent
48e308623c
commit
5126871fcf
1 changed files with 192 additions and 170 deletions
|
@ -817,8 +817,8 @@ LPSTR FindFunctionByAddress(ULONG ulValue,PULONG pulstart,PULONG pulend)
|
||||||
|
|
||||||
while( pSym < pSymEnd )
|
while( pSym < pSymEnd )
|
||||||
{
|
{
|
||||||
//symbol is a function is it's type is 0x20, storage class is external and section>0
|
//symbol is a function is it's type is 0x20, and section>0
|
||||||
if(( (pSym->Type == 0x20) && (pSym->StorageClass==IMAGE_SYM_CLASS_EXTERNAL) &&
|
if(( (pSym->Type == 0x20) &&
|
||||||
(pSym->SectionNumber > 0 )))
|
(pSym->SectionNumber > 0 )))
|
||||||
{
|
{
|
||||||
ULONG ulCurrAddr;
|
ULONG ulCurrAddr;
|
||||||
|
@ -1035,7 +1035,9 @@ ULONG ExtractTypeNumber(LPSTR p)
|
||||||
ULONG ulTypeNumber = 0;
|
ULONG ulTypeNumber = 0;
|
||||||
|
|
||||||
DPRINT((0,"ExtractTypeNumber(%s)\n",p));
|
DPRINT((0,"ExtractTypeNumber(%s)\n",p));
|
||||||
|
|
||||||
pTypeNumber = PICE_strchr(p,'(');
|
pTypeNumber = PICE_strchr(p,'(');
|
||||||
|
|
||||||
if(pTypeNumber)
|
if(pTypeNumber)
|
||||||
{
|
{
|
||||||
pTypeNumber++;
|
pTypeNumber++;
|
||||||
|
@ -1203,88 +1205,88 @@ LPSTR FindTypeDefinition(PICE_SYMBOLFILE_HEADER* pSymbols,ULONG ulTypeNumber,ULO
|
||||||
|
|
||||||
switch(pStab->n_type)
|
switch(pStab->n_type)
|
||||||
{
|
{
|
||||||
case N_UNDF:
|
case N_UNDF:
|
||||||
nOffset += nNextOffset;
|
nOffset += nNextOffset;
|
||||||
nNextOffset = pStab->n_value;
|
nNextOffset = pStab->n_value;
|
||||||
break;
|
break;
|
||||||
case N_SO:
|
case N_SO:
|
||||||
if((strLen = PICE_strlen(pName)))
|
if((strLen = PICE_strlen(pName)))
|
||||||
{
|
{
|
||||||
if(pName[strLen-1]!='/')
|
if(pName[strLen-1]!='/')
|
||||||
{
|
{
|
||||||
ulCurrentFileNumber++;
|
ulCurrentFileNumber++;
|
||||||
if(PICE_strlen(szCurrentPath))
|
if(PICE_strlen(szCurrentPath))
|
||||||
{
|
{
|
||||||
PICE_strcat(szCurrentPath,pName);
|
PICE_strcat(szCurrentPath,pName);
|
||||||
DPRINT((0,"FindTypeDefinition()1: cha %s, %u\n",szCurrentPath, ulCurrentFileNumber));
|
DPRINT((0,"FindTypeDefinition()1: cha %s, %u\n",szCurrentPath, ulCurrentFileNumber));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DPRINT((0,"FindTypeDefinition(): cha %s, %u\n",pName, ulCurrentFileNumber));
|
DPRINT((0,"FindTypeDefinition(): cha %s, %u\n",pName, ulCurrentFileNumber));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PICE_strcpy(szCurrentPath,pName);
|
PICE_strcpy(szCurrentPath,pName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
szCurrentPath[0]=0;
|
szCurrentPath[0]=0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case N_LSYM:
|
case N_LSYM:
|
||||||
// stab has no value -> must be type definition
|
// stab has no value -> must be type definition
|
||||||
//ei File number count is not reliable
|
//ei File number count is not reliable
|
||||||
if(pStab->n_value == 0 /*&& ulCurrentFileNumber==ulFileNumber*/)
|
if(pStab->n_value == 0 /*&& ulCurrentFileNumber==ulFileNumber*/)
|
||||||
{
|
{
|
||||||
DPRINT((0,"FindTypeDefinition(): pre type definition %s\n",pName));
|
DPRINT((0,"FindTypeDefinition(): pre type definition %s\n",pName));
|
||||||
// handle multi-line symbols
|
// handle multi-line symbols
|
||||||
if(strrchr(pName,'\\'))
|
if(strrchr(pName,'\\'))
|
||||||
{
|
{
|
||||||
if(PICE_strlen(szAccumulatedName))
|
if(PICE_strlen(szAccumulatedName))
|
||||||
{
|
{
|
||||||
PICE_strcat(szAccumulatedName,pName);
|
PICE_strcat(szAccumulatedName,pName);
|
||||||
DPRINT((0,"FindTypeDefinition(): [1] accum. %s\n",szAccumulatedName));
|
DPRINT((0,"FindTypeDefinition(): [1] accum. %s\n",szAccumulatedName));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PICE_strcpy(szAccumulatedName,pName);
|
PICE_strcpy(szAccumulatedName,pName);
|
||||||
DPRINT((0,"FindTypeDefinition(): [2] accum. %s\n",szAccumulatedName));
|
DPRINT((0,"FindTypeDefinition(): [2] accum. %s\n",szAccumulatedName));
|
||||||
}
|
}
|
||||||
szAccumulatedName[PICE_strlen(szAccumulatedName)-1]=0;
|
szAccumulatedName[PICE_strlen(szAccumulatedName)-1]=0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DPRINT((0,"FindTypeDefinition(): [3] accum. %s, pname: %s\n",szAccumulatedName, pName));
|
DPRINT((0,"FindTypeDefinition(): [3] accum. %s, pname: %s\n",szAccumulatedName, pName));
|
||||||
if(PICE_strlen(szAccumulatedName)==0)
|
if(PICE_strlen(szAccumulatedName)==0)
|
||||||
{
|
{
|
||||||
PICE_strcpy(szAccumulatedName,pName);
|
PICE_strcpy(szAccumulatedName,pName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PICE_strcat(szAccumulatedName,pName);
|
PICE_strcat(szAccumulatedName,pName);
|
||||||
}
|
}
|
||||||
pTypeString = szAccumulatedName;
|
pTypeString = szAccumulatedName;
|
||||||
|
|
||||||
pTypeSymbol = PICE_strchr(pTypeString,':');
|
pTypeSymbol = PICE_strchr(pTypeString,':');
|
||||||
if(pTypeSymbol && (*(pTypeSymbol+1)=='t' || *(pTypeSymbol+1)=='T'))
|
if(pTypeSymbol && (*(pTypeSymbol+1)=='t' || *(pTypeSymbol+1)=='T'))
|
||||||
{
|
{
|
||||||
// parse it
|
// parse it
|
||||||
ulCurrentTypeNumber = ExtractTypeNumber(pTypeString);
|
ulCurrentTypeNumber = ExtractTypeNumber(pTypeString);
|
||||||
DPRINT((0,"FindTypeDefinition(): ulCurrType: %u, LSYM is type %s\n",ulCurrentTypeNumber,pName));
|
DPRINT((0,"FindTypeDefinition(): ulCurrType: %u, LSYM is type %s\n",ulCurrentTypeNumber,pName));
|
||||||
if(ulCurrentTypeNumber == ulTypeNumber)
|
if(ulCurrentTypeNumber == ulTypeNumber)
|
||||||
{
|
{
|
||||||
DPRINT((0,"FindTypeDefinition(): type definition %s\n",pTypeString));
|
DPRINT((0,"FindTypeDefinition(): type definition %s\n",pTypeString));
|
||||||
return pTypeString;
|
return pTypeString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*szAccumulatedName=0;
|
*szAccumulatedName=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pStab++;
|
pStab++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FindTypeDefinitionForCombinedTypes(pSymbols,ulTypeNumber,ulFileNumber);
|
return FindTypeDefinitionForCombinedTypes(pSymbols,ulTypeNumber,ulFileNumber);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2288,103 +2290,108 @@ void SkipSpaces(void)
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
BOOLEAN FindGlobalStabSymbol(LPSTR pExpression,PULONG pValue,PULONG pulTypeNumber,PULONG pulFileNumber)
|
BOOLEAN FindGlobalStabSymbol(LPSTR pExpression,PULONG pValue,PULONG pulTypeNumber,PULONG pulFileNumber)
|
||||||
{
|
{
|
||||||
ULONG i;
|
ULONG i;
|
||||||
PSTAB_ENTRY pStab;
|
PSTAB_ENTRY pStab;
|
||||||
LPSTR pStr,pName;
|
LPSTR pStr,pName;
|
||||||
int nStabLen;
|
int nStabLen;
|
||||||
int nOffset=0,nNextOffset=0,nLen,strLen;
|
int nOffset=0,nNextOffset=0,nLen,strLen;
|
||||||
PICE_SYMBOLFILE_HEADER* pSymbols;
|
PICE_SYMBOLFILE_HEADER* pSymbols;
|
||||||
ULONG ulTypeNumber;
|
ULONG ulTypeNumber;
|
||||||
static char SymbolName[1024];
|
static char SymbolName[1024];
|
||||||
static char szCurrentPath[256];
|
static char szCurrentPath[256];
|
||||||
ULONG ulCurrentFileNumber=0;
|
ULONG ulCurrentFileNumber=0;
|
||||||
LPSTR pTypeDefIncluded;
|
LPSTR pTypeDefIncluded;
|
||||||
ULONG addr;
|
ULONG addr;
|
||||||
|
|
||||||
// must have a current module
|
// must have a current module
|
||||||
if(pCurrentMod)
|
if(pCurrentMod)
|
||||||
|
{
|
||||||
|
// in case we query for the kernel we need to use the fake kernel module
|
||||||
|
addr = (ULONG)pCurrentMod->BaseAddress;
|
||||||
|
|
||||||
|
// find the symbols for the module
|
||||||
|
pSymbols = FindModuleSymbols(addr);
|
||||||
|
if(pSymbols)
|
||||||
{
|
{
|
||||||
// in case we query for the kernel we need to use the fake kernel module
|
// prepare table access
|
||||||
addr = (ULONG)pCurrentMod->BaseAddress;
|
pStab = (PSTAB_ENTRY )((ULONG)pSymbols + pSymbols->ulOffsetToStabs);
|
||||||
|
nStabLen = pSymbols->ulSizeOfStabs;
|
||||||
|
pStr = (LPSTR)((ULONG)pSymbols + pSymbols->ulOffsetToStabsStrings);
|
||||||
|
// starting at file 0
|
||||||
|
*pulFileNumber = 0;
|
||||||
|
|
||||||
// find the symbols for the module
|
// go through stabs
|
||||||
pSymbols = FindModuleSymbols(addr);
|
for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++)
|
||||||
if(pSymbols)
|
{
|
||||||
|
pName = &pStr[pStab->n_strx + nOffset];
|
||||||
|
|
||||||
|
switch(pStab->n_type)
|
||||||
{
|
{
|
||||||
// prepare table access
|
// an N_UNDF symbol marks a change of string table offset
|
||||||
pStab = (PSTAB_ENTRY )((ULONG)pSymbols + pSymbols->ulOffsetToStabs);
|
case N_UNDF:
|
||||||
nStabLen = pSymbols->ulSizeOfStabs;
|
nOffset += nNextOffset;
|
||||||
pStr = (LPSTR)((ULONG)pSymbols + pSymbols->ulOffsetToStabsStrings);
|
nNextOffset = pStab->n_value;
|
||||||
// starting at file 0
|
break;
|
||||||
*pulFileNumber = 0;
|
// a source file symbol
|
||||||
|
case N_SO:
|
||||||
// go through stabs
|
if((strLen = PICE_strlen(pName)))
|
||||||
for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++)
|
{
|
||||||
|
if(pName[strLen-1]!='/')
|
||||||
{
|
{
|
||||||
pName = &pStr[pStab->n_strx + nOffset];
|
ulCurrentFileNumber++;
|
||||||
|
if(PICE_strlen(szCurrentPath))
|
||||||
switch(pStab->n_type)
|
{
|
||||||
{
|
PICE_strcat(szCurrentPath,pName);
|
||||||
// an N_UNDF symbol marks a change of string table offset
|
DPRINT((0,"changing source file %s\n",szCurrentPath));
|
||||||
case N_UNDF:
|
}
|
||||||
nOffset += nNextOffset;
|
else
|
||||||
nNextOffset = pStab->n_value;
|
{
|
||||||
break;
|
DPRINT((0,"changing source file %s\n",pName));
|
||||||
// a source file symbol
|
}
|
||||||
case N_SO:
|
|
||||||
if((strLen = PICE_strlen(pName)))
|
|
||||||
{
|
|
||||||
if(pName[strLen-1]!='/')
|
|
||||||
{
|
|
||||||
ulCurrentFileNumber++;
|
|
||||||
if(PICE_strlen(szCurrentPath))
|
|
||||||
{
|
|
||||||
PICE_strcat(szCurrentPath,pName);
|
|
||||||
DPRINT((0,"changing source file %s\n",szCurrentPath));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT((0,"changing source file %s\n",pName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
PICE_strcpy(szCurrentPath,pName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
szCurrentPath[0]=0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case N_GSYM:
|
|
||||||
// symbol-name:type-identifier type-number =
|
|
||||||
nLen = StrLenUpToWhiteChar(pName,":");
|
|
||||||
PICE_strncpy(SymbolName,pName,nLen);
|
|
||||||
SymbolName[nLen] = 0;
|
|
||||||
if(PICE_strcmpi(SymbolName,pExpression)==0)
|
|
||||||
{
|
|
||||||
DPRINT((0,"global symbol %s\n",pName));
|
|
||||||
// extract type-number from stab
|
|
||||||
ulTypeNumber = ExtractTypeNumber(pName);
|
|
||||||
DPRINT((0,"type number = %x\n",ulTypeNumber));
|
|
||||||
*pulTypeNumber = ulTypeNumber;
|
|
||||||
// look for symbols address in external symbols
|
|
||||||
*pValue = FindFunctionInModuleByName(SymbolName,pCurrentMod);
|
|
||||||
DPRINT((0,"value = %x\n",*pValue));
|
|
||||||
*pulFileNumber = ulCurrentFileNumber;
|
|
||||||
DPRINT((0,"file = %x\n",ulCurrentFileNumber));
|
|
||||||
if((pTypeDefIncluded = PICE_strchr(pName,'=')) )
|
|
||||||
{
|
|
||||||
DPRINT((0,"symbol includes type definition (%s)\n",pTypeDefIncluded));
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pStab++;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
PICE_strcpy(szCurrentPath,pName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
szCurrentPath[0]=0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case N_GSYM:
|
||||||
|
case N_LSYM:
|
||||||
|
case N_PSYM:
|
||||||
|
// symbol-name:type-identifier type-number =
|
||||||
|
nLen = StrLenUpToWhiteChar(pName,":");
|
||||||
|
PICE_strncpy(SymbolName,pName,nLen);
|
||||||
|
SymbolName[nLen] = 0;
|
||||||
|
if(PICE_strcmpi(SymbolName,pExpression)==0)
|
||||||
|
{
|
||||||
|
DPRINT((0,"global symbol %s\n",pName));
|
||||||
|
// extract type-number from stab
|
||||||
|
ulTypeNumber = ExtractTypeNumber(pName);
|
||||||
|
DPRINT((0,"type number = %x, from %s\n",ulTypeNumber, pName));
|
||||||
|
*pulTypeNumber = ulTypeNumber;
|
||||||
|
// look for symbols address in external symbols
|
||||||
|
if( pStab->n_type == N_LSYM || pStab->n_type == N_PSYM )
|
||||||
|
*pValue = CurrentEBP + pStab->n_value;
|
||||||
|
else *pValue = FindFunctionInModuleByName(SymbolName,pCurrentMod);
|
||||||
|
|
||||||
|
DPRINT((0,"value = %x\n",*pValue));
|
||||||
|
*pulFileNumber = ulCurrentFileNumber;
|
||||||
|
DPRINT((0,"file = %x\n",ulCurrentFileNumber));
|
||||||
|
if((pTypeDefIncluded = PICE_strchr(pName,'=')) )
|
||||||
|
{
|
||||||
|
DPRINT((0,"symbol includes type definition (%s)\n",pTypeDefIncluded));
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
pStab++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
}
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
|
@ -2682,7 +2689,6 @@ BOOLEAN EvaluateSymbol(PVRET pvr,LPSTR pToken)
|
||||||
{
|
{
|
||||||
if(!(pTypeDef = FindTypeDefinition(pvr->pSymbols,pvr->type,pvr->file)))
|
if(!(pTypeDef = FindTypeDefinition(pvr->pSymbols,pvr->type,pvr->file)))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
PICE_strcpy(type_def,pTypeDef);
|
PICE_strcpy(type_def,pTypeDef);
|
||||||
|
|
||||||
pTypeDef = type_def;
|
pTypeDef = type_def;
|
||||||
|
@ -2851,7 +2857,23 @@ BOOLEAN EvaluateSymbol(PVRET pvr,LPSTR pToken)
|
||||||
bDone = TRUE; // meanwhile
|
bDone = TRUE; // meanwhile
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DPRINT((0,"DEFAULT %x\n",pvr->type));
|
DPRINT((0,"DEFAULT %x, base: %c\n",pvr->type, *pTypeBase));
|
||||||
|
pvr->address = pvr->value;
|
||||||
|
if(IsRangeValid(pvr->value,ulBytes))
|
||||||
|
{
|
||||||
|
switch(ulBytes)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
pvr->value = *(PUCHAR)pvr->value;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
pvr->value = *(PUSHORT)pvr->value;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
pvr->value = *(PULONG)pvr->value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
bDone = TRUE;
|
bDone = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue