Skip to content

Commit

Permalink
Added support for sending break-in requests from main thread using a …
Browse files Browse the repository at this point in the history
…semaphore
  • Loading branch information
sysprogs committed Mar 16, 2014
1 parent 203c67a commit 298b80f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
72 changes: 69 additions & 3 deletions MSP430EEMTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,75 @@ void MSP430Proxy::MSP430EEMTarget::sEEMHandler( UINT MsgId, UINT wParam, LONG lP
((MSP430EEMTarget *)clientHandle)->EEMNotificationHandler((MSP430_MSG)MsgId, wParam, lParam);
}

void MSP430Proxy::MSP430EEMTarget::DoSendBreakInRequest()
{
LONG state = 0;
LONG cpuCycles = 0;
m_BreakInPending = true;
STATUS_T status = MSP430_State(&state, TRUE, &cpuCycles);
if (m_bVerbose)
printf("Break-in request: MSP430_State() => %d, state = %d, CPU cycles = %d\n", status, state, cpuCycles);
if (status != STATUS_OK)
ReportLastMSP430Error("Cannot stop device");
}

bool MSP430Proxy::MSP430EEMTarget::WaitForJTAGEvent()
{
for (;;)
{
if (m_bVerbose)
printf("Waiting for the target to stop (EEM event will be generated)...\n");
m_TargetStopped.Wait();

for (;;)
{
HANDLE events[] = {m_TargetStopped.GetHandle(), m_BreakInSemaphore.GetHandle()};
DWORD waitResult = WaitForMultipleObjects(2, events, FALSE, INFINITE);
if (waitResult == WAIT_OBJECT_0)
break; //Target stopped
else if (waitResult == (WAIT_OBJECT_0 + 1))
{
if (m_bVerbose)
printf("Handling break-in request from main worker thread...\n");
DoSendBreakInRequest();

//Sleep(1000);

//We have requested a break-in. Let's give the target some time to react.

for (;;)
{
if (WaitForSingleObject(m_TargetStopped.GetHandle(), 100) == WAIT_OBJECT_0)
{
if (m_bVerbose)
printf("Break-in handled normally. Target stop reported...\n");
break; //Done
}

LONG state = 0, cpuCycles = 0;
STATUS_T status = MSP430_State(&state, FALSE, &cpuCycles);
if (m_bVerbose)
printf("Post-break-in check: MSP430_State() => %d, state = %d, CPU cycles = %d\n", status, state, cpuCycles);

if (state == STOPPED)
{
if (m_bVerbose)
printf("Stop event not reported, but the CPU state is STOPPED. Exiting wait loop...\n");
break;
}

if (m_bVerbose)
printf("CPU state is not STOPPED. Continuing...\n");
}

break;
}
else
{
if (m_bVerbose)
printf("Unexpected wait result: 0x%x\n", waitResult);
break;
}
}

bool breakIn = m_BreakInPending;
m_BreakInPending = false;
Expand Down Expand Up @@ -311,13 +373,17 @@ bool MSP430Proxy::MSP430EEMTarget::DoResumeTarget( RUN_MODES_t mode )

GDBServerFoundation::GDBStatus MSP430Proxy::MSP430EEMTarget::SendBreakInRequestAsync()
{
LONG state = 0;
if (m_bVerbose)
printf("Received an asynchronous break-in request.\n");
m_BreakInSemaphore.Signal();
m_BreakInPending = true;

/*LONG state = 0;
STATUS_T status = MSP430_State(&state, TRUE, NULL);
if (m_bVerbose)
printf("Break-in request: MSP430_State() => %d, state = %d\n", status, state);
if (status != STATUS_OK)
REPORT_AND_RETURN("Cannot stop device", kGDBNotSupported);
REPORT_AND_RETURN("Cannot stop device", kGDBNotSupported);*/
return kGDBSuccess;
}

Expand Down
3 changes: 3 additions & 0 deletions MSP430EEMTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace MSP430Proxy
bool m_bEEMInitialized;

BazisLib::Event m_TargetStopped;
BazisLib::Semaphore m_BreakInSemaphore;
DWORD m_LastStopEvent;

WORD m_SoftwareBreakpointWrapperHandle;
Expand Down Expand Up @@ -94,6 +95,8 @@ namespace MSP430Proxy
GDBStatus DoCreateCodeBreakpoint(bool hardware, ULONGLONG Address, INT_PTR *pCookie);
GDBStatus DoRemoveCodeBreakpoint(bool hardware, ULONGLONG Address, INT_PTR Cookie);

void DoSendBreakInRequest();

public:
virtual GDBStatus CreateBreakpoint(BreakpointType type, ULONGLONG Address, unsigned kind, OUT INT_PTR *pCookie) override;
virtual GDBStatus RemoveBreakpoint(BreakpointType type, ULONGLONG Address, INT_PTR Cookie) override;
Expand Down
2 changes: 1 addition & 1 deletion msp430-gdbproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ int main(int argc, char* argv[])
return 1;
}

printf("msp430-gdbproxy++ v1.4 [http://gnutoolchains.com/msp430/gdbproxy]\nSuccessfully initialized MSP430.DLL on %s\nListening on port %d.\n", settings.PortName, settings.ListenPort);
printf("msp430-gdbproxy++ v1.5 [http://gnutoolchains.com/msp430/gdbproxy]\nSuccessfully initialized MSP430.DLL on %s\nListening on port %d.\n", settings.PortName, settings.ListenPort);
if (!settings.NoHint)
{
printf("\nRun \"msp430-gdbproxy --help\" to learn about command line options.\n\
Expand Down

0 comments on commit 298b80f

Please sign in to comment.