mb_debug_enable |
status_t mb_debug_enable( mb_interpreter_t* s, WORD wEnable, DWORD dwParam )
Enables or disables the MyBASIC2 debugger interface. This will not start a debugger. It will only enable a debugger to intercept the code while it is running. There are currently 2 different debuggers available, the GUI Debugger and a Command Line Debugger.
The following Enable Flags can be specified
MB_DBG_ENABLE_NONE 0x0000 MB_DBG_ENABLE_RTL 0x00FF MB_DBG_ENABLE_SOURCE 0x0001 MB_DBG_ENABLE_COMPILED 0x0002 MB_DBG_ENABLE_ALL MB_DBG_ENABLE_SOURCE|MB_DBG_ENABLE_COMPILED MB_DBG_ENABLE_PARSING 0xFF00 MB_DBG_ENABLE_COMMENTS 0x0100
The dwParam parameter should be set to main window handle of the host application.
Example
BOOL CDebugger::Start( mb_interpreter_t* bas, BOOL bGUI ) { CEvent event( FALSE, FALSE, MB_DEBUG_EVENT_NAME );
// Get the Handle of the main window
HWND hWnd = NULL;
CWnd* pWnd = AfxGetMainWnd();
if ( pWnd ) { hWnd = pWnd->m_hWnd; } endif
// Enable Debugger Interface
if ( mb_debug_enable( bas, MB_DBG_ENABLE_ALL, (DWORD)hWnd ) != MB_FUNC_OK ) { return FALSE; } endif
if ( !event.Lock( 10 ) ) { // Debugger not running. Start the debugger
CString strDebugger; CString strCommands;
strDebugger = "\"";
if ( bGUI ) { if ( m_strDebugger.IsEmpty() ) m_strDebugger = "MyBASIC2Debugger.exe";
strDebugger += AfxGetApp()->GetProfileString( "Debugger", "Path", m_strDebugger ); } else { if ( m_strDebugger.IsEmpty() ) m_strDebugger = "MB2DebugConsole.exe";
strDebugger += AfxGetApp()->GetProfileString( "Debugger", "Path", m_strDebugger ); strCommands = AfxGetApp()->GetProfileString( "Debugger", "Commands", m_strCommands ); } endif
strDebugger += "\"";
if ( strCommands.GetLength() > 0 ) { strDebugger += " \""; strDebugger += strCommands; strDebugger += "\""; } endif
STARTUPINFO stStartUpInfo = { 0 }; PROCESS_INFORMATION stProcInfo = { 0 };
if ( !CreateProcess( NULL, strDebugger.GetBuffer( 2 ), 0, 0, TRUE, CREATE_NEW_CONSOLE, 0, 0, &stStartUpInfo, &stProcInfo ) ) { DWORD err = GetLastError();
mb_debug_enable( bas, MB_DBG_ENABLE_NONE, 0 );
return( FALSE ); } endif
if ( !event.Lock( m_dwTimeout ) ) { mb_debug_enable( bas, MB_DBG_ENABLE_NONE, 0 );
return FALSE; } endif
event.ResetEvent(); } endif
return TRUE; } endfunc
|