Пример #1
0
/*
================
rvDebuggerClient::ProcessMessages

Process all incomding messages from the debugger server
================
*/
bool rvDebuggerClient::ProcessMessages ( void )
{
	netadr_t adrFrom;
	msg_t	 msg;
	byte	 buffer[MAX_MSGLEN];

	MSG_Init( &msg, buffer, sizeof( buffer ) );

	// Check for pending udp packets on the debugger port
	while ( mPort.GetPacket ( adrFrom, msg.data, msg.cursize, msg.maxsize ) )
	{
		unsigned short command;

		// Only accept packets from the debugger server for security reasons
		if ( !Sys_CompareNetAdrBase ( adrFrom, mServerAdr ) )
		{
			continue;
		}

		command = (unsigned short) MSG_ReadShort ( &msg );
		
		// Is this what we are waiting for?
		if ( command == mWaitFor )
		{
			mWaitFor = DBMSG_UNKNOWN;
		}
		
		switch ( command )
		{
			case DBMSG_CONNECT:
				mConnected = true;
				SendMessage ( DBMSG_CONNECTED );
				SendBreakpoints ( );
				break;
				
			case DBMSG_CONNECTED:
				mConnected = true;
				SendBreakpoints ( );
				break;
				
			case DBMSG_DISCONNECT:
				mConnected = false;
				break;
				
			case DBMSG_BREAK:
				HandleBreak ( &msg );				
				break;
				
			// Callstack being send to the client
			case DBMSG_INSPECTCALLSTACK:
				HandleInspectCallstack ( &msg );
				break;
				
			// Thread list is being sent to the client
			case DBMSG_INSPECTTHREADS:
				HandleInspectThreads ( &msg );
				break;
				
			case DBMSG_INSPECTVARIABLE:
				HandleInspectVariable ( &msg );
				break;			
		}			
		
		// Give the window a chance to process the message
		msg.readcount = 0;		
		msg.bit = 0;
		gDebuggerApp.GetWindow().ProcessNetMessage ( &msg );
	}

	return true;
}
Пример #2
0
void SetBreakpoint(const char* MsgBuffer)
{
	const char* pLine = NULL;
	const char* pFile = NULL;
	const char* pExpr = NULL;

	//MsgBuffer has the form: cmd,line#,filename[,expression]
	
	pLine = strchr(MsgBuffer, ',');
	if (pLine)
	{
		//move past the comma
		pLine++;

		pFile = strchr(pLine , ',');
		if (pFile)
		{
			pFile++;
			pExpr = strchr(pFile, ',');
			
			if (pExpr)
			{
				*((char*)pExpr) = 0;
				pExpr++;
			}
		}
	}

	
	PyObject* pEvalRes = NULL;
	int nLineNum = -1;
	if (pLine)
		nLineNum = strtol(pLine, NULL, 10)+1;			

	switch (MsgBuffer[0])
	{
	case BREAKPT_SET:
		if (pFile && pLine && (nLineNum > -1))
		{		
			/*if (pExpr == NULL)
				pEvalRes = PyObject_CallMethod(g_pHeDebugger, "SetBreakpoint", "si", pFile, nLineNum);
			else
				pEvalRes = PyObject_CallMethod(g_pHeDebugger, "SetBreakpoint", "siis", pFile, nLineNum, 0, pExpr);*/
			
			TBpItr pBp;
			for (pBp = g_vecBreakpoints.begin(); pBp != g_vecBreakpoints.end(); pBp++)
			{
				if (*pBp == pFile)
				{
					break;
				}
			}

			if (pBp == g_vecBreakpoints.end())
			{
				//a matching file was not found
				CFileBreakpts newbp;
				newbp.SetFilename(pFile);
				newbp.AddLine(nLineNum);
				g_vecBreakpoints.push_back(newbp);
			}
			else
			{
				//breakpoint exist in this file, add the line
				pBp->AddLine(nLineNum);
			}



		}
		break;

	case BREAKPT_TOGGLE:
		if (pFile && pLine && (nLineNum > -1))
		{		
			//pEvalRes = PyObject_CallMethod(g_pHeDebugger, "ToggleBreakpoint", "si", pFile, nLineNum);
			TBpItr pBp;
			for (pBp = g_vecBreakpoints.begin(); pBp != g_vecBreakpoints.end(); pBp++)
			{
				if (*pBp == pFile)
				{
					break;
				}
			}

			if (pBp == g_vecBreakpoints.end())
			{
				CFileBreakpts newbp;
				newbp.SetFilename(pFile);
				newbp.AddLine(nLineNum);
				g_vecBreakpoints.push_back(newbp);
			}
			else
			{
				if (pBp->CheckLine(nLineNum))
				{
					pBp->RemoveLine(nLineNum);
					if (pBp->GetLinesCount() == 0)
						g_vecBreakpoints.erase(pBp);
				}
				else
				{
					pBp->AddLine(nLineNum);
				}
			}
		}
		break;

	case BREAKPT_CLEAR:
		if (pFile && pLine && (nLineNum > -1))
		{		
			//pEvalRes = PyObject_CallMethod(g_pHeDebugger, "ClearBreakpoint", "si", pFile, nLineNum);
			for (TBpItr pBp = g_vecBreakpoints.begin(); pBp != g_vecBreakpoints.end(); pBp++)
			{
				if (*pBp == pFile)
				{
					pBp->RemoveLine(nLineNum);
					if (pBp->GetLinesCount() == 0)
						g_vecBreakpoints.erase(pBp);
				}
			}
		}
		break;

	case BREAKPT_CLEARALLFILE:
		{
			for (TBpItr pBp = g_vecBreakpoints.begin(); pBp != g_vecBreakpoints.end(); pBp++)
			{
				if (*pBp == pFile)
					g_vecBreakpoints.erase(pBp);
			}
		}
		break;
	case BREAKPT_CLEARALL:
		//pEvalRes = PyObject_CallMethod(g_pHeDebugger, "ClearBreakpoint", "si", "", -1);
		g_vecBreakpoints.clear();
		break;
	case BREAKPT_DISABLE:
	case BREAKPT_ENABLE:
		break;
	}

	if ((pEvalRes != NULL) && (pEvalRes != Py_None))
	{
		dprintf(PyString_AsString(pEvalRes));
		dprintf("\n");
	}
	
	//send the client the current list of breakpoints to get them up to date
	SendBreakpoints();

	g_bBptsSet = (g_vecBreakpoints.size() > 0);

}