User forums > Using Code::Blocks

Pausing the debugger?

<< < (2/2)

Jenna:
It's nearly the same in C::B.


--- Code: ---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
    }
}

--- End code ---

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.

DrewBoo:

--- Quote from: jens on March 10, 2008, 07:44:56 pm ---It's nearly the same in C::B.


--- Code: ---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
    }
}

--- End code ---

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.

--- End quote ---



Hi, jens.

Yes, I see that now.

Here's the scenario on my Solaris machine:

This is setting pid to 0.

--- Code: ---        long pid = m_State.GetDriver()->GetChildPID();

--- End code ---


...and here it's set to the debugger's pid.  Unfortunately gdb doesn't respond to SIGINT as we would like it to.

--- Code: ---        if (pid <= 0)
            pid = m_Pid; // try poking gdb directly

--- End code ---


I have it working with this horrible hack, which is working but certainly isn't reliable and could do Bad Things.


--- Code: ---        if (pid <= 0)
        //    pid = m_Pid; // try poking gdb directly
              pid = m_Pid+1; // Assume debuggee's pid is 1 past gdb's pid

--- End code ---

mariocup:
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:


--- Code: ---interpreter-exec mi interrupt

--- End code ---

This will have the same effect like Ctrl+C in the gdb console.

Bye,

Mario

Navigation

[0] Message Index

[*] Previous page

Go to full version