Is there a way to abruptly halt the debugger, so I may add breakpoints or do other debugging tasks?
I'm using Code::Blocks in a unix-like environment, using gcc4.2 to build and gdb6.7 to debug.
When I use gdb on the command line, I can freeze an already running program by hitting Ctrl+C. I get my debugger prompt right away. Other IDEs usually have a "pause button" or similar to do that in the graphic environment.
The only enabled debugging button that I see in C::B is "Stop Debugging", which seems to end the entire debugging session. Have I missed something, or is this feature still in the oven?
Thanks in advance for your help. :)
I am not familiar with C::B debugger code, but for my debugger code I am using this code, which works fine on Windows & Linux:
bool DbgGdb::Interrupt()
{
if (m_debuggeePid > 0) {
#ifdef __WXMSW__
HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)m_debuggeePid);
BOOL res = DebugBreakProcess(process);
return res == TRUE;
#else
m_observer->UpdateAddLine(wxT("Interrupting debugee process"));
kill(m_debuggeePid, SIGINT);
#endif
}
return true;
}
Note that m_debugeePid is the PID of the child process of gdb, and not gdb itself.
Eran
It's nearly the same in C::B.
void DebuggerGDB::Break()
{
// m_Process is PipedProcess I/O; m_Pid is debugger pid
if (m_pProcess && m_Pid && !IsStopped())
{
long pid = m_State.GetDriver()->GetChildPID();
if (pid <= 0)
pid = m_Pid; // try poking gdb directly
#ifndef __WXMSW__
// non-windows gdb can interrupt the running process. yay!
if (pid <= 0) // look out for the "fake" PIDs (killall)
cbMessageBox(_("Unable to stop the debug process!"), _("Error"), wxOK | wxICON_WARNING);
else
wxKill(pid, wxSIGINT);
#else
// windows gdb can interrupt the running process too. yay!
bool done = false;
if (DebugBreakProcessFunc && pid > 0)
{
Log(_("Trying to pause the running process..."));
HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
if (proc)
{
DebugBreakProcessFunc(proc); // yay!
CloseHandle(proc);
done = true;
}
else
Log(_("Failed."));
}
#endif
}
}
but on windows (at least on my W2K in kvm virtualbox) it does not work.
I'll try to debug it later.
EDIT:
On linux it works: first click -> Pause, second click -> stop.
It's nearly the same in C::B.
void DebuggerGDB::Break()
{
// m_Process is PipedProcess I/O; m_Pid is debugger pid
if (m_pProcess && m_Pid && !IsStopped())
{
long pid = m_State.GetDriver()->GetChildPID();
if (pid <= 0)
pid = m_Pid; // try poking gdb directly
#ifndef __WXMSW__
// non-windows gdb can interrupt the running process. yay!
if (pid <= 0) // look out for the "fake" PIDs (killall)
cbMessageBox(_("Unable to stop the debug process!"), _("Error"), wxOK | wxICON_WARNING);
else
wxKill(pid, wxSIGINT);
#else
// windows gdb can interrupt the running process too. yay!
bool done = false;
if (DebugBreakProcessFunc && pid > 0)
{
Log(_("Trying to pause the running process..."));
HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
if (proc)
{
DebugBreakProcessFunc(proc); // yay!
CloseHandle(proc);
done = true;
}
else
Log(_("Failed."));
}
#endif
}
}
but on windows (at least on my W2K in kvm virtualbox) it does not work.
I'll try to debug it later.
EDIT:
On linux it works: first click -> Pause, second click -> stop.
Hi, jens.
Yes, I see that now.
Here's the scenario on my Solaris machine:
This is setting pid to 0.
long pid = m_State.GetDriver()->GetChildPID();
...and here it's set to the debugger's pid. Unfortunately gdb doesn't respond to SIGINT as we would like it to.
if (pid <= 0)
pid = m_Pid; // try poking gdb directly
I have it working with this horrible hack, which is working but certainly isn't reliable and could do Bad Things.
if (pid <= 0)
// pid = m_Pid; // try poking gdb directly
pid = m_Pid+1; // Assume debuggee's pid is 1 past gdb's pid
Hi,
I found a workaround how the debugger can be interrupted under windows or other platforms. Select the menu item Debug->Send user command to debugger and type:
interpreter-exec mi interrupt
This will have the same effect like Ctrl+C in the gdb console.
Bye,
Mario