Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework code base to have a single debugger and messaging port #238

Merged
merged 1 commit into from
Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMake/Modules/FindNF_Debugger.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ list(APPEND NF_Debugger_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Include)
# source files for nanoFramework Debugger
set(NF_Debugger_SRCS

# Debugger.cpp
# Debugger_full.cpp
Debugger.cpp
Debugger_full.cpp

# Messaging.cpp
# WireProtocol.cpp
Messaging.cpp
WireProtocol.cpp

WireProtocol_Message.c
WireProtocol_MonitorCommands.c
Expand Down
6 changes: 3 additions & 3 deletions src/CLR/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ CLR_HW_Hardware g_CLR_HW_Hardware;
//};

// UNDONE: FIXME: the Arm 3.0 compiler drags in a bunch of ABI methods (for initialization) if struct arrays are not initialized
CLR_UINT32 g_scratchDebugger [ sizeof(CLR_DBG_Debugger) * NUM_DEBUGGERS / sizeof(unsigned int) + 1 ];
CLR_UINT32 g_scratchDebuggerMessaging[ sizeof(CLR_Messaging) * NUM_DEBUGGERS / sizeof(unsigned int) + 1 ];
CLR_DBG_Debugger *g_CLR_DBG_Debuggers;
CLR_UINT32 g_scratchDebugger [ sizeof(CLR_DBG_Debugger) ];
CLR_UINT32 g_scratchDebuggerMessaging[ sizeof(CLR_Messaging) ];
CLR_DBG_Debugger *g_CLR_DBG_Debugger;

CLR_RT_Persistence_Manager g_CLR_RT_Persistence_Manager;

Expand Down
28 changes: 6 additions & 22 deletions src/CLR/Core/Hardware/Hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,41 +89,25 @@ void CLR_HW_Hardware::ProcessActivity()
if(!HAL_CONTINUATION::Dequeue_And_Execute()) break;
}

NANOCLR_FOREACH_MESSAGING(msg)
if(!msg.IsDebuggerInitialized())
{
if(!msg.IsDebuggerInitialized())
{
msg.InitializeDebugger();
}
msg.PurgeCache();
msg.InitializeDebugger();
}
NANOCLR_FOREACH_MESSAGING_END();
msg.PurgeCache();

NANOCLR_FOREACH_DEBUGGER(dbg)
{
dbg.PurgeCache();
}
NANOCLR_FOREACH_DEBUGGER_END();
dbg.PurgeCache();

unsigned int events = ::Events_Get( m_wakeupEvents );
unsigned int eventsCLR = 0;

if(events & m_MessagingEventsMask)
{
NANOCLR_FOREACH_MESSAGING(msg)
{
msg.ProcessCommands();
}
NANOCLR_FOREACH_MESSAGING_END();
msg.ProcessCommands();
}

if(events & m_DebuggerEventsMask)
{
NANOCLR_FOREACH_DEBUGGER(dbg)
{
dbg.ProcessCommands();
}
NANOCLR_FOREACH_DEBUGGER_END();
dbg.ProcessCommands();

#if defined(PLATFORM_ARM)
if(CLR_EE_DBG_IS(RebootPending))
Expand Down
45 changes: 16 additions & 29 deletions src/CLR/Debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,22 @@ HRESULT CLR_DBG_Debugger::CreateInstance()

int iDebugger = 0;

g_CLR_DBG_Debuggers = (CLR_DBG_Debugger*)&g_scratchDebugger[ 0 ];
g_CLR_DBG_Debugger = (CLR_DBG_Debugger*)&g_scratchDebugger[ 0 ];

CLR_RT_Memory::ZeroFill( g_scratchDebuggerMessaging, sizeof(CLR_Messaging) * NUM_DEBUGGERS );
CLR_RT_Memory::ZeroFill( g_scratchDebuggerMessaging, sizeof(CLR_Messaging) );

CLR_RT_Memory::ZeroFill( g_CLR_DBG_Debuggers, sizeof(CLR_DBG_Debugger) * NUM_DEBUGGERS );
CLR_RT_Memory::ZeroFill( g_CLR_DBG_Debugger, sizeof(CLR_DBG_Debugger) );

NANOCLR_FOREACH_DEBUGGER_NO_TEMP()
if(HalSystemConfig.DebuggerPort == HalSystemConfig.MessagingPort)
{
if(HalSystemConfig.DebuggerPorts[ iDebugger ] == HalSystemConfig.MessagingPorts[ 0 ])
{
g_CLR_DBG_Debuggers[ iDebugger ].m_messaging = &g_CLR_Messaging[ 0 ];
}
else
{
g_CLR_DBG_Debuggers[iDebugger].m_messaging = (CLR_Messaging*)&g_scratchDebuggerMessaging[ iDebugger ];
}

NANOCLR_CHECK_HRESULT(g_CLR_DBG_Debuggers[ iDebugger ].Debugger_Initialize( HalSystemConfig.DebuggerPorts[ iDebugger ] ));
iDebugger++;
g_CLR_DBG_Debugger->m_messaging = &g_CLR_Messaging[ 0 ];
}
else
{
g_CLR_DBG_Debugger->m_messaging = (CLR_Messaging*)&g_scratchDebuggerMessaging[0];
}
NANOCLR_FOREACH_DEBUGGER_END();

NANOCLR_CHECK_HRESULT(g_CLR_DBG_Debugger->Debugger_Initialize(HalSystemConfig.DebuggerPort));

BlockStorageStream stream;

Expand Down Expand Up @@ -162,11 +157,7 @@ HRESULT CLR_DBG_Debugger::DeleteInstance()
NATIVE_PROFILE_CLR_DEBUGGER();
NANOCLR_HEADER();

NANOCLR_FOREACH_DEBUGGER(dbg)
{
dbg.Debugger_Cleanup();
}
NANOCLR_FOREACH_DEBUGGER_END();
g_CLR_DBG_Debugger->Debugger_Cleanup();

NANOCLR_NOCLEANUP_NOLABEL();
}
Expand Down Expand Up @@ -194,11 +185,7 @@ void CLR_DBG_Debugger::PurgeCache()
void CLR_DBG_Debugger::BroadcastEvent( unsigned int cmd, unsigned int payloadSize, unsigned char* payload, unsigned int flags )
{
NATIVE_PROFILE_CLR_DEBUGGER();
NANOCLR_FOREACH_DEBUGGER(dbg)
{
dbg.m_messaging->SendEvent( cmd, payloadSize, payload, flags );
}
NANOCLR_FOREACH_DEBUGGER_END();
g_CLR_DBG_Debugger->m_messaging->SendEvent( cmd, payloadSize, payload, flags );
}

//--//
Expand Down Expand Up @@ -523,7 +510,7 @@ bool CLR_DBG_Debugger::CheckPermission( ByteAddress address, int mode )
}
else
{
hasPermission = DebuggerPort_IsUsingSsl(HalSystemConfig.DebuggerPorts[ 0 ]) == true;
hasPermission = DebuggerPort_IsUsingSsl(HalSystemConfig.DebuggerPort) == true;
}
break;
case AccessMemory_Erase:
Expand Down Expand Up @@ -1130,7 +1117,7 @@ bool CLR_DBG_Debugger::Debugging_UpgradeToSsl(WP_Message* msg, void* owner )
CLR_DBG_Commands::Debugging_UpgradeToSsl* cmd = (CLR_DBG_Commands::Debugging_UpgradeToSsl*)msg->m_payload;
CLR_DBG_Commands::Debugging_UpgradeToSsl::Reply reply;

if(!DebuggerPort_IsSslSupported(HalSystemConfig.DebuggerPorts[0]))
if(!DebuggerPort_IsSslSupported(HalSystemConfig.DebuggerPort))
{
return false;
}
Expand All @@ -1141,7 +1128,7 @@ bool CLR_DBG_Debugger::Debugging_UpgradeToSsl(WP_Message* msg, void* owner )

Events_WaitForEvents(0, 300);

return true == DebuggerPort_UpgradeToSsl(HalSystemConfig.DebuggerPorts[0], cmd->m_flags);
return true == DebuggerPort_UpgradeToSsl(HalSystemConfig.DebuggerPort, cmd->m_flags);
}

static CLR_UINT32 s_missingPkts[64];
Expand Down
2 changes: 1 addition & 1 deletion src/CLR/Debugger/Debugger_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ __nfweak void CLR_DBG_Debugger::PurgeCache()
__nfweak HRESULT CLR_DBG_Debugger::CreateInstance()
{
NATIVE_PROFILE_CLR_DEBUGGER();
g_CLR_DBG_Debuggers = (CLR_DBG_Debugger*)&g_scratchDebugger[0];
g_CLR_DBG_Debugger = (CLR_DBG_Debugger*)&g_scratchDebugger[0];
NANOCLR_SYSTEM_STUB_RETURN();
}

Expand Down
25 changes: 1 addition & 24 deletions src/CLR/Include/nanoCLR_Debugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,6 @@

////////////////////////////////////////////////////////////////////////////////////////////////////

#if NUM_DEBUGGERS > 1
#define NANOCLR_FOREACH_DEBUGGER(ptr) \
for(int iDebuggerT = 0; iDebuggerT < NUM_DEBUGGERS; iDebuggerT++) \
{ \
CLR_DBG_Debugger& ptr = g_CLR_DBG_Debuggers[ iDebuggerT ];

#define NANOCLR_FOREACH_DEBUGGER_NO_TEMP() \
for(int iDebuggerT = 0; iDebuggerT < NUM_DEBUGGERS; iDebuggerT++) \
{
#else
#define NANOCLR_FOREACH_DEBUGGER(ptr) \
{ \
CLR_DBG_Debugger& ptr = g_CLR_DBG_Debuggers[ 0 ];

#define NANOCLR_FOREACH_DEBUGGER_NO_TEMP() \
{
#endif

#define NANOCLR_FOREACH_DEBUGGER_END() \
}

////////////////////////////////////////////////////////////////////////////////////////////////////

//#if defined(_MSC_VER)
struct CLR_DBG_Commands
{
Expand Down Expand Up @@ -1161,7 +1138,7 @@ struct CLR_DBG_Debugger

extern CLR_UINT32 g_scratchDebugger[];
extern CLR_UINT32 g_scratchDebuggerMessaging[];
extern CLR_DBG_Debugger *g_CLR_DBG_Debuggers;
extern CLR_DBG_Debugger *g_CLR_DBG_Debugger;

//--//

Expand Down
21 changes: 0 additions & 21 deletions src/CLR/Include/nanoCLR_Messaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,6 @@
#include <nanoCLR_Types.h>
#include <WireProtocol.h>

#if NUM_MESSAGING > 1
#define NANOCLR_FOREACH_MESSAGING(ptr) \
for(int iMessageT = 0; iMessageT < NUM_MESSAGING; iMessageT++) \
{ \
CLR_Messaging& ptr = g_CLR_Messaging[ iMessageT ];

#define NANOCLR_FOREACH_MESSAGING_NO_TEMP() \
for(int iMessageT = 0; iMessageT < NUM_MESSAGING; iMessageT++) \
{
#else
#define NANOCLR_FOREACH_MESSAGING(ptr) \
{ \
CLR_Messaging& ptr = g_CLR_Messaging[ 0 ];

#define NANOCLR_FOREACH_MESSAGING_NO_TEMP() \
{
#endif

#define NANOCLR_FOREACH_MESSAGING_END() \
}

////////////////////////////////////////////////////////////////////////////////////////////////////

typedef bool (*CLR_Messaging_CommandHandler)( WP_Message* msg, void* owner );
Expand Down
14 changes: 3 additions & 11 deletions src/CLR/Include/nanoCLR_Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -2910,19 +2910,11 @@ struct CLR_RT_ExecutionEngine
#define CLR_EE_REBOOT_SET( Cond ) g_CLR_RT_ExecutionEngine.m_iReboot_Options |= CLR_RT_ExecutionEngine::c_fReboot_##Cond
#define CLR_EE_REBOOT_CLR( Cond ) g_CLR_RT_ExecutionEngine.m_iReboot_Options &= ~CLR_RT_ExecutionEngine::c_fReboot_##Cond

#define CLR_EE_DBG_EVENT_SEND( cmd, size, payload, flags ) ((g_CLR_DBG_Debuggers[ DEBUGGER_PORT_INDEX ].m_messaging != NULL) ? g_CLR_DBG_Debuggers[ DEBUGGER_PORT_INDEX ].m_messaging->SendEvent( cmd, size, (unsigned char*)payload, flags ) : false)
#define CLR_EE_DBG_EVENT_SEND( cmd, size, payload, flags ) ((g_CLR_DBG_Debugger->m_messaging != NULL) ? g_CLR_DBG_Debugger->m_messaging->SendEvent( cmd, size, (unsigned char*)payload, flags ) : false)

#if NUM_MESSAGING == 1
#define CLR_EE_MSG_EVENT_RPC( cmd, size, payload, flags ) g_CLR_Messaging[ 0 ].SendEvent( cmd, size, (unsigned char*)payload, flags )
#else
#define CLR_EE_MSG_EVENT_RPC( cmd, size, payload, flags ) CLR_Messaging::BroadcastEvent( cmd, size, (unsigned char*)payload, flags )
#endif
#define CLR_EE_MSG_EVENT_RPC( cmd, size, payload, flags ) g_CLR_Messaging.SendEvent( cmd, size, (unsigned char*)payload, flags )

#if NUM_DEBUGGERS == 1
#define CLR_EE_DBG_EVENT_BROADCAST( cmd, size, payload, flags ) CLR_EE_DBG_EVENT_SEND( cmd, size, payload, flags )
#else
#define CLR_EE_DBG_EVENT_BROADCAST( cmd, size, payload, flags ) CLR_DBG_Debugger::BroadcastEvent( cmd, size, (unsigned char*)payload, flags )
#endif
#define CLR_EE_DBG_EVENT_BROADCAST( cmd, size, payload, flags ) CLR_EE_DBG_EVENT_SEND( cmd, size, payload, flags )

////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
44 changes: 15 additions & 29 deletions src/CLR/Messaging/Messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#endif

// the Arm 3.0 compiler drags in a bunch of ABI methods (for initialization) if struct arrays are not initialized
CLR_UINT32 g_scratchMessaging[ sizeof(CLR_Messaging) * NUM_MESSAGING / sizeof(unsigned int) + 1 ];
CLR_UINT32 g_scratchMessaging[ sizeof(CLR_Messaging) ];
CLR_Messaging *g_CLR_Messaging;

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -278,23 +278,16 @@ HRESULT CLR_Messaging::CreateInstance()

g_CLR_Messaging = (CLR_Messaging*)&g_scratchMessaging[ 0 ];

CLR_RT_Memory::ZeroFill( g_CLR_Messaging, sizeof(CLR_Messaging) * NUM_MESSAGING );

int iMsg = 0;
CLR_RT_Memory::ZeroFill( g_CLR_Messaging, sizeof(CLR_Messaging) );

NANOCLR_FOREACH_MESSAGING_NO_TEMP()
{
g_CLR_Messaging[ iMsg ].Initialize(
HalSystemConfig.MessagingPorts[ iMsg ],
NULL,
0,
NULL,
0,
&g_CLR_Messaging[ iMsg ]
);
iMsg++;
}
NANOCLR_FOREACH_MESSAGING_END();
g_CLR_Messaging->Initialize(
HalSystemConfig.MessagingPort,
NULL,
0,
NULL,
0,
g_CLR_Messaging
);

NANOCLR_NOCLEANUP_NOLABEL();
}
Expand All @@ -311,8 +304,8 @@ void CLR_Messaging::Initialize(
)
{
// If the debugger and Messaging share the same port (Legacy) then we will not initialze the Messaging port (because the debugger will take care of it)
if((port == HalSystemConfig.MessagingPorts[ 0 ]) &&
(port == HalSystemConfig.DebuggerPorts[ 0 ] ) &&
if((port == HalSystemConfig.MessagingPort) &&
(port == HalSystemConfig.DebuggerPort) &&
requestLookup == NULL) // messaging is null so don't initialize the port
{
return;
Expand Down Expand Up @@ -355,11 +348,7 @@ HRESULT CLR_Messaging::DeleteInstance()
NATIVE_PROFILE_CLR_MESSAGING();
NANOCLR_HEADER();

NANOCLR_FOREACH_MESSAGING(msg)
{
msg.Cleanup();
}
NANOCLR_FOREACH_MESSAGING_END();
g_CLR_Messaging->Cleanup();

NANOCLR_NOCLEANUP_NOLABEL();
}
Expand Down Expand Up @@ -608,11 +597,8 @@ bool CLR_Messaging::SendEvent( unsigned int cmd, unsigned int payloadSize, unsig
void CLR_Messaging::BroadcastEvent( unsigned int cmd, unsigned int payloadSize, unsigned char* payload, unsigned int flags )
{
NATIVE_PROFILE_CLR_MESSAGING();
NANOCLR_FOREACH_MESSAGING(msg)
{
msg.m_controller.SendProtocolMessage( cmd, flags, payloadSize, payload );
}
NANOCLR_FOREACH_MESSAGING_END();

g_CLR_Messaging->m_controller.SendProtocolMessage( cmd, flags, payloadSize, payload );
}

//--//
Expand Down
2 changes: 1 addition & 1 deletion src/CLR/Messaging/Messaging_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

__nfweak CLR_Messaging *g_CLR_Messaging;

__nfweak CLR_UINT32 g_scratchMessaging[sizeof(CLR_Messaging) * NUM_MESSAGING / sizeof(unsigned int) + 1];
__nfweak CLR_UINT32 g_scratchMessaging[sizeof(CLR_Messaging) ];

__nfweak HRESULT CLR_Messaging::CreateInstance()
{
Expand Down
6 changes: 3 additions & 3 deletions src/HAL/Include/nanoHAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -1135,10 +1135,10 @@ template <typename T> class Hal_Queue_UnknownSize

//#include <..\Initialization\MasterConfig.h>

#define NUM_DEBUGGERS 1 // UNDONE: Remove
#define NUM_MESSAGING 1 // UNDONE: Remove

#define DEBUGGER_PORT_INDEX 0 // UNDONE: Remove




//--//

Expand Down
4 changes: 2 additions & 2 deletions src/HAL/Include/nanoHAL_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ typedef struct HAL_SYSTEM_CONFIG

//--//

COM_HANDLE DebuggerPorts[1];
COM_HANDLE MessagingPorts[1];
COM_HANDLE DebuggerPort;
COM_HANDLE MessagingPort;
// communication channel for debug messages in the debugger
// which may be VS, MFDEPLOY, etc... Accessed via debug_printf
// in the HAL/PAL and System.Diagnostics.Debug.Print() in managed
Expand Down