I'm on linux with GDB 7.10, and CB never gets the correct pid for me. This means I can't pause or set any breakpoints after I start debugging. Here's some log:
[...]
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /home/gokul/Documents/Projects/CodeBlocks/src/devel/codeblocks --debug-log --multiple-instance -ns -ni -v -p debug
[debug][Thread debugging using libthread_db enabled]
[debug]Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
Child process PID: 14736
[debug][New Thread 0xb5565b40 (LWP 14736)]
[debug][New Thread 0xb4d64b40 (LWP 14737)]
[debug][New Thread 0xb4563b40 (LWP 14738)]
[debug][New Thread 0xb3b0db40 (LWP 14739)]
[debug][New Thread 0xb330cb40 (LWP 14740)]
[debug][New Thread 0xb1966b40 (LWP 14747)]
[debug][New Thread 0xb0fcdb40 (LWP 14801)]
[debug][New Thread 0xb076db40 (LWP 14802)]
[debug][New Thread 0xafec0b40 (LWP 14803)]
[debug][Thread 0xafec0b40 (LWP 14803) exited]
[debug][Thread 0xb0fcdb40 (LWP 14801) exited]
[debug][Thread 0xb076db40 (LWP 14802) exited]
[debug][Thread 0xb1966b40 (LWP 14747) exited]
[debug]Starting Code::Blocks svn build rev 10703 Jan 29 2016, 03:07:41 - wx2.8.12 (Linux, unicode) - 32 bit
[debug][Thread 0xb4563b40 (LWP 14738) exited]
[debug][Thread 0xb4d64b40 (LWP 14737) exited]
[debug][Thread 0xb5565b40 (LWP 14736) exited]
[debug][Thread 0xb330cb40 (LWP 14740) exited]
[debug][Thread 0xb3b0db40 (LWP 14739) exited]
[debug][Inferior 1 (process 14101) exited normally]
[debug]>>>>>>cb_gdb:
[Inferior 1 (process 14101) exited normally]
[debug]> quit
Debugger finished with status 0
You can see CB tries to get the pid by parsing the thread info, i.e., the line in red:
"[New Thread 0xb5565b40 (LWP 14736)]"
but this is not the correct pid of the inferior process! The correct pid can be seen at the end, in the green line:
"[Inferior 1 (process 14101) exited normally]"
The only proper way to get the pid seems to be to start gdb in "break on entry" mode and run "info program" or "info inferior" at the gdb prompt, parse the result and then continue. I see there is already support for "info program", so why not use that? I'll post a patch in a while...
Edit: Here's the patch which works for me:
From 9f668e2611366fde9e9ee3a8bd17f553bafd30fb Mon Sep 17 00:00:00 2001
From: huki <gk7huki@gmail.com>
Date: Sat, 30 Jan 2016 02:51:50 +0530
Subject: [PATCH] debugger_gdb: [huki] properly get the pid of the inferior
process
We now break on entry and extract the pid through "info program", then continue if needed.
Fixed functionality of m_ManualBreakOnEntry.
Keep old way of catching pid for remoteDebugging.
---
src/plugins/debuggergdb/gdb_commands.h | 3 +++
src/plugins/debuggergdb/gdb_driver.cpp | 10 ++++++++++
2 files changed, 13 insertions(+)
diff --git a/src/plugins/debuggergdb/gdb_commands.h b/src/plugins/debuggergdb/gdb_commands.h
index 3021cd7..5536c84 100644
--- a/src/plugins/debuggergdb/gdb_commands.h
+++ b/src/plugins/debuggergdb/gdb_commands.h
@@ -722,7 +722,10 @@ class GdbCmd_InfoProgram : public DebuggerCmd
{
long pid;
if (pid_str.ToLong(&pid, 10) && pid != 0)
+ {
m_pDriver->SetChildPID(pid);
+ m_pDriver->GetDebugger()->Log(wxString::Format(_("Child process PID: %ld"), pid));
+ }
}
}
};
diff --git a/src/plugins/debuggergdb/gdb_driver.cpp b/src/plugins/debuggergdb/gdb_driver.cpp
index cc1ccd5..b2365c9 100644
--- a/src/plugins/debuggergdb/gdb_driver.cpp
+++ b/src/plugins/debuggergdb/gdb_driver.cpp
@@ -503,6 +503,7 @@ void GDB_driver::Start(bool breakOnEntry)
{
m_ManualBreakOnEntry = !remoteDebugging;
// start the process
+ #if 0
if (breakOnEntry)
QueueCommand(new GdbCmd_Start(this, remoteDebugging ? _T("continue") : _T("start")));
else
@@ -511,6 +512,9 @@ void GDB_driver::Start(bool breakOnEntry)
m_ManualBreakOnEntry=false; // must be reset or gdb does not stop at first breakpoint
QueueCommand(new GdbCmd_Start(this, remoteDebugging ? _T("continue") : _T("run")));
}
+ #endif
+ // NOTE(huki): use "start" command so we can break on entry and run "info program" to get the pid
+ QueueCommand(new GdbCmd_Start(this, remoteDebugging ? _T("continue") : _T("start")));
m_IsStarted = true;
}
} // Start
@@ -778,6 +782,7 @@ void GDB_driver::ParseOutput(const wxString& output)
{
m_Cursor.changed = false;
+ // NOTE(huki): this doesn't work on linux with GDB 7 - the pid given in the output is wrong
if (platform::windows && m_ChildPID == 0)
{
if (reChildPid2.Matches(output)) // [New Thread 2684.0xf40] or [New thread 2684.0xf40]
@@ -1043,6 +1048,7 @@ void GDB_driver::ParseOutput(const wxString& output)
m_needsUpdate = true;
}
}
+ m_ManualBreakOnEntry = false; // must be reset or gdb does not stop at first breakpoint
}
else if (lines[i].StartsWith(wxT("Temporary breakpoint")))
@@ -1177,7 +1183,11 @@ void GDB_driver::HandleMainBreakPoint(const wxRegEx& reBreak_in, wxString line)
QueueCommand(new GdbCmd_InfoProgram(this), DebuggerDriver::High);
if (m_ManualBreakOnEntry && !m_BreakOnEntry)
+ {
+ m_ManualBreakOnEntry = false;
+ m_ProgramIsStopped = true;
Continue();
+ }
else
{
m_ManualBreakOnEntry = false;
--
2.5.0
Edit2: Updated the patch with few fixes, also keeps the old way of catching pid as a fallback (eg, for remote debugging).
commit on git