From e4beec265f9289821dd47c7d18893bbf74a8c68e Mon Sep 17 00:00:00 2001 From: josesimoes Date: Tue, 5 May 2020 16:16:52 +0100 Subject: [PATCH] Work on boot and debugger - Add Debugger_Discovery to debugger. - Add call to Debugger_Discovery in CLRStartup. - Add Ping_Source_Host to Monitor_Ping_Source_Flags enum. - Remove wrong debug messages from startup. - Improve debug messages on startup. - Bring Win32 CLRStartup in sync with native one. Signed-off-by: josesimoes --- src/CLR/Debugger/Debugger.cpp | 50 ++++++++++++++++++++++++- src/CLR/Debugger/Debugger_stub.cpp | 4 ++ src/CLR/Include/WireProtocol.h | 1 + src/CLR/Include/nanoCLR_Debugging.h | 1 + src/CLR/Startup/CLRStartup.cpp | 10 ++--- targets/os/win32/nanoCLR/CLRStartup.cpp | 16 +++----- 6 files changed, 63 insertions(+), 19 deletions(-) diff --git a/src/CLR/Debugger/Debugger.cpp b/src/CLR/Debugger/Debugger.cpp index a120fa0c3f..7c0a9003ed 100644 --- a/src/CLR/Debugger/Debugger.cpp +++ b/src/CLR/Debugger/Debugger.cpp @@ -53,6 +53,50 @@ void CLR_DBG_Debugger::Debugger_WaitForCommands() } } +void CLR_DBG_Debugger::Debugger_Discovery() +{ + NATIVE_PROFILE_CLR_DEBUGGER(); + + CLR_INT32 wait_sec = 5; + + CLR_INT64 expire = HAL_Time_CurrentTime() + (wait_sec * TIME_CONVERSION__TO_SECONDS); + + // Send "presence" ping. + Monitor_Ping_Command cmd; + cmd.m_source = Monitor_Ping_c_Ping_Source_NanoCLR; + + while(true) + { + CLR_EE_DBG_EVENT_BROADCAST(CLR_DBG_Commands::c_Monitor_Ping, sizeof(cmd), &cmd, WP_Flags_c_NoCaching | WP_Flags_c_NonCritical); + + // if we support soft reboot and the debugger is not stopped then we don't need to connect the debugger + if(!CLR_EE_DBG_IS(Stopped) && ::CPU_IsSoftRebootSupported()) + { + break; + } + + g_CLR_RT_ExecutionEngine.DebuggerLoop(); + + if(CLR_EE_DBG_IS(Enabled)) + { + // Debugger on the other side, let's exit the discovery loop. + CLR_Debug::Printf( "Debugger found. Resuming boot sequence.\r\n" ); + break; + } + + CLR_INT64 now = HAL_Time_CurrentTime(); + + if(expire < now) + { + // no response after timeout... + CLR_Debug::Printf( "No debugger found...\r\n" ); + break; + } + } + + g_CLR_RT_ExecutionEngine.WaitForDebugger(); +} + //////////////////////////////////////////////////////////////////////////////////////////////////// HRESULT CLR_DBG_Debugger::CreateInstance() @@ -884,10 +928,12 @@ bool CLR_DBG_Debugger::Monitor_Reboot( WP_Message* msg) g_CLR_RT_ExecutionEngine.m_iReboot_Options = cmd->m_flags; } - CLR_EE_DBG_SET( RebootPending ); - WP_ReplyToCommand(msg, true, false, NULL, 0); + Events_WaitForEvents( 0, 100 ); // give message a little time to be flushed + + CLR_EE_DBG_SET( RebootPending ); + return true; } diff --git a/src/CLR/Debugger/Debugger_stub.cpp b/src/CLR/Debugger/Debugger_stub.cpp index edffed30a9..a292ec81d6 100644 --- a/src/CLR/Debugger/Debugger_stub.cpp +++ b/src/CLR/Debugger/Debugger_stub.cpp @@ -7,6 +7,10 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// +__nfweak void CLR_DBG_Debugger::Debugger_Discovery() +{ + NATIVE_PROFILE_CLR_DEBUGGER(); +} __nfweak void CLR_DBG_Debugger::Debugger_WaitForCommands() { diff --git a/src/CLR/Include/WireProtocol.h b/src/CLR/Include/WireProtocol.h index 790f8125c3..2ccc63fe8d 100644 --- a/src/CLR/Include/WireProtocol.h +++ b/src/CLR/Include/WireProtocol.h @@ -152,6 +152,7 @@ typedef enum Monitor_Ping_Source_Flags { Monitor_Ping_c_Ping_Source_NanoCLR = 0x00010000, Monitor_Ping_c_Ping_Source_NanoBooter = 0x00010001, + Monitor_Ping_c_Ping_Source_Host = 0x00010002, Monitor_Ping_c_Ping_DbgFlag_Stop = 0x00000001, Monitor_Ping_c_Ping_DbgFlag_AppExit = 0x00000004, diff --git a/src/CLR/Include/nanoCLR_Debugging.h b/src/CLR/Include/nanoCLR_Debugging.h index 3869e81f67..d6c4115ad5 100644 --- a/src/CLR/Include/nanoCLR_Debugging.h +++ b/src/CLR/Include/nanoCLR_Debugging.h @@ -1021,6 +1021,7 @@ struct CLR_DBG_Debugger //--// + static void Debugger_Discovery(); static void Debugger_WaitForCommands(); static HRESULT CreateInstance(); diff --git a/src/CLR/Startup/CLRStartup.cpp b/src/CLR/Startup/CLRStartup.cpp index 6e43502882..797cc7c055 100644 --- a/src/CLR/Startup/CLRStartup.cpp +++ b/src/CLR/Startup/CLRStartup.cpp @@ -57,6 +57,8 @@ struct Settings CLR_Debug::Printf( "Started Hardware.\r\n" ); #endif + CLR_DBG_Debugger::Debugger_Discovery(); + m_fInitialized = true; NANOCLR_NOCLEANUP(); @@ -111,9 +113,8 @@ struct Settings CLR_EE_DBG_CLR(StateResolutionFailed); #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Create TS.\r\n" ); + CLR_Debug::Printf( "Create Type System.\r\n" ); #endif - //NANOCLR_CHECK_HRESULT(LoadKnownAssemblies( (char*)&__deployment_start__, (char*)&__deployment_end__ )); #if !defined(BUILD_RTM) CLR_Debug::Printf( "Loading Deployment Assemblies.\r\n" ); @@ -282,10 +283,6 @@ struct Settings // we have good Assembly CLR_RT_Assembly* assm; -#if !defined(BUILD_RTM) - CLR_Debug::Printf( "Attaching deployed file.\r\n" ); -#endif - // Creates instance of assembly, sets pointer to native functions, links to g_CLR_RT_TypeSystem if (FAILED(LoadAssembly(header, assm))) { @@ -384,7 +381,6 @@ void ClrStartup(CLR_SETTINGS params) CLR_Debug::Printf( "Starting...\r\n" ); #endif - HRESULT hr; if(SUCCEEDED(hr = s_ClrSettings.Initialize(params))) diff --git a/targets/os/win32/nanoCLR/CLRStartup.cpp b/targets/os/win32/nanoCLR/CLRStartup.cpp index d4686e7e83..cefd8d66df 100644 --- a/targets/os/win32/nanoCLR/CLRStartup.cpp +++ b/targets/os/win32/nanoCLR/CLRStartup.cpp @@ -71,13 +71,13 @@ struct Settings CLR_Debug::Printf( "Started Hardware.\r\n" ); #endif - m_fInitialized = true; + CLR_DBG_Debugger::Debugger_Discovery(); + m_fInitialized = true; NANOCLR_NOCLEANUP(); } - HRESULT LoadAssembly( const CLR_RECORD_ASSEMBLY* header, CLR_RT_Assembly*& assm ) { NANOCLR_HEADER(); @@ -95,7 +95,7 @@ struct Settings // First verify that check sum in assembly object matches hardcoded check sum. if ( assm->m_header->nativeMethodsChecksum != pNativeAssmData->m_checkSum ) { - CLR_Debug::Printf("***********************************************************************\r\n"); + CLR_Debug::Printf("\r\n\r\n***********************************************************************\r\n"); CLR_Debug::Printf("* *\r\n"); CLR_Debug::Printf("* ERROR!!!! Firmware version does not match managed code version!!!! *\r\n"); CLR_Debug::Printf("* *\r\n"); @@ -193,7 +193,7 @@ struct Settings #else #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Create TS.\r\n" ); + CLR_Debug::Printf( "Create Type System.\r\n" ); #endif NANOCLR_CHECK_HRESULT(LoadKnownAssemblies( nanoCLR_Dat_Start, nanoCLR_Dat_End )); @@ -359,10 +359,6 @@ struct Settings // we have good Assembly CLR_RT_Assembly* assm; -#if !defined(BUILD_RTM) - CLR_Debug::Printf( "Attaching deployed file.\r\n" ); -#endif - // Creates instance of assembly, sets pointer to native functions, links to g_CLR_RT_TypeSystem if (FAILED(LoadAssembly( header, assm ) )) { @@ -376,7 +372,6 @@ struct Settings NANOCLR_NOCLEANUP(); } - HRESULT LoadDeploymentAssemblies( unsigned int memoryUsage ) { NANOCLR_HEADER(); @@ -661,9 +656,10 @@ void ClrStartup( CLR_SETTINGS params ) #if !defined(BUILD_RTM) CLR_Debug::Printf( "\r\nnanoCLR (Build %d.%d.%d.%d)\r\n\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION ); + CLR_Debug::Printf( "\r\n%s\r\n\r\n", OEMSYSTEMINFOSTRING ); #endif - CLR_RT_Memory::Reset (); + CLR_RT_Memory::Reset(); #if !defined(BUILD_RTM) CLR_Debug::Printf( "Starting...\r\n" );