📄 debugtask.c
字号:
// argument : pStr Pointer to string inputted
// return : DBG_STATUS_SUCCESS Normal
// : DBG_STATUS_INVALID_COMMAND Input command error
// : DBG_STATUS_INVALID_ADDRESS Input address error
// =============================================================================
*/
LONG StringAnalysis( CHAR* pStr )
{
LONG result; // return value
/* Save command of last time before initialization */
OldData = CurrentData;
/* Initialization */
memset( &CurrentData , 0x00, sizeof( DATA_COMPOSITION ) );
/* Change process */
result = ChangeStr( pStr );
/* Command analysis process */
result = CmdAnalysis() ;
if ( result == DBG_STATUS_SUCCESS )
{
if( FlowToggle == TRUE )
{
if( CurrentData.cmdType != DBG_CMDID_FLOW )
{
/* In case of flow function is ON, invalidate commands other than flow */
result = DBG_STATUS_INVALID_COMMAND;
}
}
else
{
/* Case of command analysis is normal finish */
/* If there is no address on DB DW DD EB EW ED, become error */
if( CurrentData.cmdType == DBG_CMDID_DUMP_BYTE ||
CurrentData.cmdType == DBG_CMDID_DUMP_WORD ||
CurrentData.cmdType == DBG_CMDID_DUMP_DWORD ||
CurrentData.cmdType == DBG_CMDID_ENTER_BYTE ||
CurrentData.cmdType == DBG_CMDID_ENTER_WORD ||
CurrentData.cmdType == DBG_CMDID_ENTER_DWORD )
{
if( ( result == DBG_STATUS_INVALID_ADDRESS ||
result == DBG_STATUS_NOADDRESS ) &&
( CurrentData.dataMember.rcvAddress == 0x00 ) )
{
/* There is a error in address input */
result = DBG_STATUS_INVALID_ADDRESS;
}
}
else
{
if( CurrentData.cmdType == DBG_CMDID_FLOW )
{
if( CurrentData.dataMember.rcvAddress > 0x03)
{
/* There is a error in parameter input */
result = DBG_STATUS_PARAM_ERROR;
}
}
}
}
}
else if( result != DBG_STATUS_NOINPUT )
{
/* Case of there is error in command analysis */
result = DBG_STATUS_INVALID_COMMAND;
}
return result;
}
/*=============================================================================
// Function_Name: ChangeStr
// description : Change process
// argument : pStrBuf Pointer to string inputted
// return : DBG_STATUS_SUCCESS Normal
// : DBG_STATUS_INVALID_COMMAND Input command error
// : DBG_STATUS_INVALID_ADDRESS Input address error
// : DBG_STATUS_NOADDRESS State of no address inputted
// =============================================================================
*/
LONG ChangeStr( CHAR* pStrBuf )
{
int i = 0;
CHAR str[DBG_STR_MAX];
LONG result;
// Command change
i = SplitStr( pStrBuf , CurrentData.dataMember.rcvCmd );
/* Initialization of string for saving */
memset( &str , 0x00, sizeof( str ) );
// Address change
i += SplitStr( pStrBuf + i , str );
/* Change address string to numeric value */
result = StrChangeHex( &CurrentData.dataMember.rcvAddress , str , DBG_VALUE_SIZE_DWORD );
if( result < DBG_STATUS_SUCCESS )
/* Case of numeric value change error */
{
result = DBG_STATUS_INVALID_ADDRESS;
CurrentData.dataMember.rcvAddress = 0xFF;
return result;
}
else if( result != DBG_STATUS_SUCCESS )
/* Case of no input */
{
result = DBG_STATUS_NOADDRESS;
return result;
}
/* Initialization of string for saving */
memset( &str , 0x00, sizeof( str ) );
// Data change
i += SplitStr( pStrBuf + i , str );
/* Change data string to numeric value */
result = StrChangeHex( &CurrentData.dataMember.rcvData , str , DBG_VALUE_SIZE_BYTE);
if( result < DBG_STATUS_SUCCESS )
/* Case of numeric value change error */
{
result = DBG_STATUS_INVALID_DATA;
return result;
}
else if( result != DBG_STATUS_SUCCESS )
/* Case of no input */
{
result = DBG_STATUS_NODATA;
return result;
}
result = DBG_STATUS_SUCCESS;
return result;
}
/*=============================================================================
// Function_Name: CmdAnalysis
// description : Command analysis function
// argument : None
// return : DBG_STATUS_SUCCESS Normal
// : DBG_STATUS_NOINPUT No command inputted
// : DBG_STATUS_INVALID_COMMAND Input command error
// : DBG_STATUS_INVALID_ADDRESS Input address error
// : DBG_STATUS_NOADDRESS No address inputted
// =============================================================================
*/
LONG CmdAnalysis( void )
{
LONG result; // return value
int i , j; /*
i : Offset of command information table
j : Offset of command string
*/
CHAR *p_str;
UCHAR flg = 0; // Flag to judge corresponding command
/* Support for continuously display function */
/* In case of the command of the last time is Dump/Enter function which there is NULL inputted in start, copy information of the last time and add 40h to the address */
if( *CurrentData.dataMember.rcvCmd == DBG_ENTER_NEXT )
{
if( OldData.cmdType == DBG_CMDID_DUMP_BYTE ||
OldData.cmdType == DBG_CMDID_DUMP_WORD ||
OldData.cmdType == DBG_CMDID_DUMP_DWORD )
{
memcpy( &CurrentData, &OldData, sizeof(CurrentData) ); // Copy information of the last time
CurrentData.dataMember.rcvAddress += DBG_DUMP_DIS; // Address + 40h
}
else
{
/* Handle as return */
result = DBG_STATUS_NOINPUT;
return result;
}
}
/* In case of the command of the last time is Dump/Enter function which there is Cap key inputted in start, copy information of the last time and subtract 40h from the address */
if( *CurrentData.dataMember.rcvCmd == DBG_ENTER_BACK )
{
if( OldData.cmdType == DBG_CMDID_DUMP_BYTE ||
OldData.cmdType == DBG_CMDID_DUMP_WORD ||
OldData.cmdType == DBG_CMDID_DUMP_DWORD )
{
memcpy( &CurrentData, &OldData, sizeof(CurrentData) ); // Copy information of the last time
CurrentData.dataMember.rcvAddress -= DBG_DUMP_DIS; // Address - 40h
}
else
{
/* If command of the last time was not Dump, assume error */
result = DBG_STATUS_INVALID_COMMAND;
return result;
}
}
/* Compare whether there is correspond table & command search */
for( i = 0; ; i++ )
{
p_str = g_Tbl_CmdInfo[ i ].pString;
if( p_str == NULL )
{
/* Error setting */
result = DBG_STATUS_INVALID_COMMAND;
break; // If it reach the end of table, finish in error
}
if( CheckCapitalAndSmall( *CurrentData.dataMember.rcvCmd , *p_str ) == TRUE ) /* Does the first character correspond? */
{
flg = 0;
/* Comparison from 2nd character */
for( j = 1; ; j++ )
{
/* Judgement of the end of command table */
if( *(p_str + j ) == '\0')
{
/* Judgement of the end of command */
if( * (CurrentData.dataMember.rcvCmd + j ) == '\0' )
{
/* Table information */
CurrentData.cmdType = g_Tbl_CmdInfo[ i ].cmdId;
CurrentData.pfnCallBackRutin = g_Tbl_CmdInfo[ i ].cCmdProc;
/* Complete agree */
return DBG_STATUS_SUCCESS; // Since complete agree, analysis is finishing normlly here!!
}
else
{
/* Because there is no corresponding, check next command */
flg = 1;
break;
}
}
else if( CheckCapitalAndSmall( *( CurrentData.dataMember.rcvCmd + j ) , *( p_str + j) ) == TRUE ) /* Does the (1 + j) character correspond? */
{
/* One character is agreed */
continue; /* Go to next character */
}
else
{
/* Because the (1 + j)th character is not conrrespond, check next command */
flg = 1;
break;
}
}
if ( flg == 1 )
{
/* Even if there is one time that no corresponding, go to next command */
continue;
}
}
else
{
/* Because the first character is not correspond, check next command */
continue;
}
}
return result;
}
/*=============================================================================
// Function_Name: SplitStr
// description : String extraction process ( extract from start of string to NULL )
// argument : pInputStr String before extraction
// : pOutputStr String after extraction
// return : Number of characters after extraction
// =============================================================================
*/
int SplitStr( CHAR* pInputStr, CHAR* pOutputStr )
{
int i = 0;
int j = 0;
// Remove spaces of start
while( *(pInputStr + i) == ' ' )
{
i++;
}
/* Saving command process */
for( ; i < DBG_STR_MAX ; i++ )
{
/* Saving command process will finish at the ' ' or '\0' */
if( *(pInputStr + i) == '\0' || *(pInputStr + i) == ' ' )
{
break;
}
else
{
/* Save command */
*(pOutputStr + j) = *(pInputStr + i);
j++;
}
}
return i;
}
/*=============================================================================
// Function_Name: FuncCmdProcDB
// description : Command ( dump byte ) process
// argument : extra Extra information
// return : DBG_STATUS_SUCCESS Normal
// =============================================================================
*/
LONG FuncCmdProcDB( LONG extra )
{
LONG result = DBG_STATUS_SUCCESS;
/* Address editing */
CurrentData.dataMember.rcvAddress &= ~(0x0F);
/* Carry out dump output */
DBOutput( (UCHAR *)CurrentData.dataMember.rcvAddress );
return result;
}
/*=============================================================================
// Function_Name: DBOutput
// description : Command ( dump byte ) output process
// argument : pAddress Address of output object
// return : None
// =============================================================================
*/
void DBOutput(UCHAR* pAddress)
{
UCHAR linecnt; // Number of lines to output
CHAR string[DBG_STR_MAX]; // String for editing
CHAR* pCurAdd;
UCHAR strCnt; //String counter
int i; // Index
// Caption output
PrintOut(" Address | +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F |0123456789ABCDEF");
PrintOut("\r\n");
PrintOut("---------|-------------------------------------------------+---- ASCII -----");
// Dump 4Line Print Out
for( linecnt = 0; linecnt < PRINT_OUT_MAX_LINE; linecnt++)
{
PrintOut("\r\n");
// Address output
memset( string , 0x00 , sizeof( string ) );
ValChangeStr( string , (ULONG)pAddress, DBG_VALUE_SIZE_DWORD , PRINT_HEXA_MODE );
PrintOut( string );
PrintOut( " |" );
// Binary output
memset( string , 0x00 , sizeof( string ) );
pCurAdd = string;
for( i = 0; i < PRINT_DB_MAX_BYTE; i++ )
{
*pCurAdd++ = ' ';
ValChangeStr( pCurAdd , *( pAddress + i) , DBG_VALUE_SIZE_BYTE , PRINT_HEXA_MODE );
pCurAdd+=2;
}
PrintOut( string );
PrintOut(" |" );
pCurAdd = string;
for( i = 0; i < PRINT_DB_MAX_BYTE; i++ )
{
if ( *( pAddress + i) >= '0' && *( pAddress + i) <= 'z' ){
/* ASCII output */
sprintf( pCurAdd , "%c" , *( pAddress + i) );
pCurAdd++;
}else{
/* For character which can not be displayed, output with period */
*pCurAdd++ = '.';
}
}
*pCurAdd = 0x00; // insert null
PrintOut( string );
pAddress+=0x10;
}
}
/*=============================================================================
// Function_Name: FuncCmdProcDW
// description : Command ( dump word ) process
// argument : extra Extra information
// return : None
// =============================================================================
*/
LONG FuncCmdProcDW( LONG extra )
{
LONG result = DBG_STATUS_SUCCESS;
/* Address editing */
CurrentData.dataMember.rcvAddress &= ~(0x0F);
/* Carry out dump word output */
DWOutput( (UCHAR *)CurrentData.dataMember.rcvAddress );
return result;
}
/*=============================================================================
// Function_Name: FuncCmdProcDW
// description : Command ( dump word ) process
// argument : pAddress Address of output object
// return : None
// =============================================================================
*/
void DWOutput(UCHAR* pAddress)
{
UCHAR linecnt;
CHAR string[DBG_STR_MAX];
int i;
CHAR* pCurAdd;
UCHAR strCnt; //String counter
// Caption output
PrintOut(" Address | +0 +2 +4 +6 +8 +A +C +E |0123456789ABCDEF");
PrintOut("\r\n");
PrintOut("---------|-----------------------------------------+---- ASCII -----");
// Dump 4Line Print Out
for( linecnt = 0; linecnt < PRINT_OUT_MAX_LINE; linecnt++)
{
PrintOut("\r\n");
// Address output
memset( string , 0x00 , sizeof( string ) );
ValChangeStr ( string , (ULONG) (pAddress + linecnt * 0x10) , DBG_VALUE_SIZE_DWORD , PRINT_HEXA_MODE );
PrintOut( string );
PrintOut( " |" );
// Binary output
memset( string , 0x00 , sizeof( string ) );
pCurAdd = string;
for( i = linecnt * PRINT_DW_MAX_BYTE; i < ( linecnt + 1 ) * PRINT_DW_MAX_BYTE; i++)
{
*pCurAdd++ = ' ';
ValChangeStr( pCurAdd , *((USHORT* )pAddress + i) , DBG_VALUE_SIZE_WORD , PRINT_HEXA_MODE );
pCurAdd+=4;
}
PrintOut( string );
PrintOut(" |" );
pCurAdd = string;
for( i = linecnt * PRINT_DB_MAX_BYTE; i < ( linecnt + 1 ) * PRINT_DB_MAX_BYTE; i++ )
{
if ( *( pAddress + i) >= '0' && *( pAddress + i) <= 'z' ){
/* ASCII output */
sprintf( pCurAdd , "%c" , *( pAddress + i) );
pCurAdd++;
}else{
/* For character which can not be displayed, output with period */
*pCurAdd++ = '.';
}
}
*pCurAdd = 0x00; // insert null
PrintOut( string );
}
}
/*=============================================================================
// Function_Name: FuncCmdProcDD
// description : Command ( dump double word ) process
// argument : extra Extra information
// return : None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -