Skip to content

Commit

Permalink
Merge pull request rocmarchive#1 from nadeaud/master
Browse files Browse the repository at this point in the history
Using breakpoints instead of SIGUSR2.
  • Loading branch information
perhaad authored Jul 1, 2016
2 parents b41cb1d + 8382fef commit cdf1f8e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 deletions.
37 changes: 20 additions & 17 deletions src/HSADebugAgent/CommandLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@ static HsailParentStatus CheckParentStatus(const AgentContext* pActiveContext)
return parentStatus;
}

/* GDB will install a breakpoint on this function that will be used when
* a GPU kernel breakpoint is hit.
* It is defined as extern C to facilitate the name lookup by GDB. This
* could be changed to use exported symbol referring to locations
* as it is done in the in-process agent library.
*/
extern "C" {
void __attribute__((optimize("O0"))) TriggerGPUBreakpointStop(void)
{
return;
}
}

/// The DebugEvent loop is run as a separate thread.
/// It is launched from the predispatch callback.
/// The predispatch callback will have created a breakpoint, so we can
Expand Down Expand Up @@ -390,23 +403,13 @@ void* DebugEventThread(void* pArgs)

if (isStopNeeded)
{
// Hand control to GDB - Send signal to GDB
// Using pthread_kill vs regular kill gives better control over
// the stopping location.
// It is the same old notion of multithreaded signalling where
// using a kill can result in a signal that be delivered
// to any thread in a process
if (pthread_kill(pthread_self(), SIGUSR2) == -1)
{
// Get out of the thread,
// I am not sure on how to handle signaling failure
AGENT_ERROR("Could not signal gdb");
exitSignal = 1;
}
else
{
AGENT_LOG("DebugEventThread: Raise SIGUSR2 to stop");
}
// Hand control to GDB
// GDB will have inserted a breakpoint
// in TriggerGPUBreakpointStop during
// initialisation. Calling this function
// will notify GDB that a GPU breakpoint
// has been hit.
TriggerGPUBreakpointStop();
}
else
{
Expand Down
20 changes: 0 additions & 20 deletions src/HSADebugAgent/HSADebugAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,6 @@ void tempHandleSIGUSR1(int signal)
return;
}

void tempHandleSIGUSR2(int signal)
{
if (signal != SIGUSR2)
{
AGENT_ERROR("A spurious signal detected when we expect SIGUSR2");
AGENT_ERROR("We don't know what to do");
}
else
{
AGENT_LOG("tempHandleSIGUSR2: Handling SIGUSR2 by doing nothing");
}

return;
}


// We initialize the AgentContext object by calling this function
// on the library load and then pass it to the predispatch callback
static void CreateHsaAgentContext()
Expand Down Expand Up @@ -201,10 +185,6 @@ static void InitHsaAgent()

signal(SIGUSR1, tempHandleSIGUSR1);

// Add a do nothing handler on SIGUSR2.
// Needed since HCC or the HSA runtime seem to mess with handlers
signal(SIGUSR2, tempHandleSIGUSR2);

AgentTriggerGDBEventLoop();

status = InitFifoWriteEnd();
Expand Down
2 changes: 1 addition & 1 deletion src/HSADebugAgent/Include/CommunicationControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef enum
HSAIL_COMMAND_MOMENTARY_BREAKPOINT, // Set an HSAIL momentary breakpoint (which is automatically deleted)
HSAIL_COMMAND_CONTINUE, // Continue the inferior process
HSAIL_COMMAND_SET_LOGGING, // Configure the logging in the Agent
HSAIL_COMMAND_SET_ISA_DUMP // Configure dumping of ISA
HSAIL_COMMAND_SET_ISA_DUMP // Configure dumping of ISA
} HsailCommand;

typedef enum
Expand Down

0 comments on commit cdf1f8e

Please sign in to comment.