Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

debugger plugin: catch the inferior PID under gdb

<< < (2/6) > >>

oBFusCATed:
If it was that simple it would have been so easy, but this output is meant for people not IDEs, so it is random and not consistent.

ollydbg:

--- Quote from: jens on April 05, 2012, 07:24:02 am ---Did you also test it with non-threaded application (simple hello world example should do it) ?

--- End quote ---
My original test was a wxWidgets app(single thread), now I test a single thread hello world console app, both of them show the correct message that I needed.


--- Quote ---I don't get any such message here on linux in this case.

--- End quote ---
If you look at the original post's code snippet, you can see

--- Code: ---    else if (!platform::windows && m_ChildPID == 0)
    {
        if (reChildPid3.Matches(output)) // [Switching to Thread -1234655568 (LWP 18590)]
        {
            wxString pidStr = reChildPid3.GetMatch(output, 1);
            long pid = 0;
            pidStr.ToLong(&pid);
            SetChildPID(pid);
            m_pDBG->Log(wxString::Format(_("Child process PID: %d"), pid));
        }
    }

--- End code ---
This means, under Linux, it use reChildPid3, which is defined as:

--- Code: ---// [Switching to Thread -1234655568 (LWP 18590)]
// [New Thread -1234655568 (LWP 18590)]
static wxRegEx reChildPid3(_T("Thread[ \t]+[xA-Fa-f0-9-]+[ \t]+\\(LWP ([0-9]+)\\)]"));

--- End code ---

So, as a conclusion, under Linux we don't need some kind of tricks (set on debugevents and later set off debugevents).

@obf:
I tested under Windows, both gdb 6.8 and gdb 7.4 show the PID correctly under the message pattern like:

--- Code: ---[New thread 1748.0x1300]

--- End code ---

oBFusCATed:
ollydbg: Patches welcome, but please wait for 2-3 days until we do the merge...

And Jens is correct because gdb doesn't always print the threading notifications, but if it works on windows I have nothing against it.

ollydbg:

--- Quote from: oBFusCATed on April 05, 2012, 12:52:50 pm ---ollydbg: Patches welcome, but please wait for 2-3 days until we do the merge...

And Jens is correct because gdb doesn't always print the threading notifications, but if it works on windows I have nothing against it.

--- End quote ---
Ok, I put this in my TODO list. Also, the patch should be only touch the Windows side (not Linux side).

ollydbg:

--- Code: ---Index: gdb_driver.cpp
===================================================================
--- gdb_driver.cpp (revision 7929)
+++ gdb_driver.cpp (working copy)
@@ -75,6 +75,7 @@
 // [Switching to Thread -1234655568 (LWP 18590)]
 // [New Thread -1234655568 (LWP 18590)]
 static wxRegEx reChildPid3(_T("Thread[ \t]+[xA-Fa-f0-9-]+[ \t]+\\(LWP ([0-9]+)\\)]"));
+static wxRegEx reChildPid4(_T("\\[New [tT]hread[ \t]+[0-9]+\\.[xA-Fa-f0-9-]+\\]"));
 static wxRegEx reAttachedChildPid(wxT("Attaching to process ([0-9]+)"));
 
 static wxRegEx reInferiorExited(wxT("^\\[Inferior[ \\t].+[ \\t]exited normally\\]$"), wxRE_EXTENDED);
@@ -92,8 +93,6 @@
     m_IsStarted(false),
     m_GDBVersionMajor(0),
     m_GDBVersionMinor(0),
-    want_debug_events(true),
-    disable_debug_events(false),
     m_attachedToProcess(false),
     m_catchThrowIndex(-1)
 {
@@ -243,19 +242,6 @@
     // disalbe result string truncations
     QueueCommand(new DebuggerCmd(this, wxString::Format(wxT("set print elements %d"), printElements)));
 
-    // want debug events
-    if(platform::windows)
-    {
-        QueueCommand(new DebuggerCmd(this, _T("set debugevents on")));
-        want_debug_events = true;
-        disable_debug_events = false;
-    }
-    else
-    {
-        want_debug_events = false;
-        disable_debug_events = false;
-    }
-
     if (platform::windows && isConsole)
         QueueCommand(new DebuggerCmd(this, _T("set new-console on")));
 
@@ -750,43 +736,18 @@
 {
     m_Cursor.changed = false;
 
-    // Watch for initial debug info and grab the child PID
-    // this is put here because we need this info even if
-    // we don't get a prompt back.
-    // It's "cheap" anyway because the line we 're after is
-    // the very first line printed by gdb when running our
-    // program. It then sets the child PID and never enters here
-    // again because the "want_debug_events" condition below
-    // is not satisfied anymore...
-    if (platform::windows && want_debug_events)
+    if (platform::windows && m_ChildPID == 0)
     {
-        wxRegEx* re = 0;
-        if ((m_GDBVersionMajor > 6 || (m_GDBVersionMajor == 6 && m_GDBVersionMinor >= 7)) &&
-            output.Contains(_T("CREATE_PROCESS_DEBUG_EVENT")))
+        if (reChildPid4.Matches(output)) // [New Thread 2684.0xf40] or [New thread 2684.0xf40]
         {
-            re = &reChildPid2;
+            wxString pidStr = reChildPid4.GetMatch(output, 0);
+            pidStr = pidStr.BeforeFirst(_T('.')); //[New Thread 2684.0xf40] -> [New Thread 2684
+            pidStr = pidStr.AfterFirst(_T('d')); //[New Thread 2684 ->  2684
+            long pid = 0;
+            pidStr.ToLong(&pid);
+            SetChildPID(pid);
+            m_pDBG->Log(wxString::Format(_("Child process PID: %d"), pid));
         }
-        else if (m_GDBVersionMajor <= 6 && output.Contains(_T("do_initial_child_stuff")))
-            re = &reChildPid;
-        else if (m_attachedToProcess)
-            re = &reAttachedChildPid;
-
-        if (re)
-        {
-            // got the line with the PID, parse it out:
-            // e.g.
-            // gdb: do_initial_child_stuff: process 1392
-            if (re->Matches(output))
-            {
-                wxString pidStr = re->GetMatch(output, 1);
-                long pid = 0;
-                pidStr.ToLong(&pid);
-                SetChildPID(pid);
-                want_debug_events = false;
-                disable_debug_events = true;
-                m_pDBG->Log(wxString::Format(_("Child process PID: %d"), pid));
-            }
-        }
     }
     else if (!platform::windows && m_ChildPID == 0)
     {
@@ -800,10 +761,9 @@
         }
     }
 
-    if (!want_debug_events &&
-        (output.StartsWith(_T("gdb: ")) ||
-        output.StartsWith(_T("Warning: ")) ||
-        output.StartsWith(_T("ContinueDebugEvent "))))
+    if (  output.StartsWith(_T("gdb: "))
+        ||output.StartsWith(_T("Warning: "))
+        ||output.StartsWith(_T("ContinueDebugEvent ")))
     {
         return;
     }
@@ -822,13 +782,6 @@
         return; // come back later
     }
 
-    if (disable_debug_events)
-    {
-        // we don't want debug events anymore (we got the pid)
-        QueueCommand(new DebuggerCmd(this, _T("set debugevents off")));
-        disable_debug_events = false;
-    }
-
     m_QueueBusy = false;
     int changeFrameAddr = 0 ;
     DebuggerCmd* cmd = CurrentCommand();
Index: gdb_driver.h
===================================================================
--- gdb_driver.h (revision 7929)
+++ gdb_driver.h (working copy)
@@ -127,8 +127,6 @@
         long m_GDBVersionMinor;
         wxString flavour;
 
-        bool want_debug_events;
-        bool disable_debug_events;
         bool m_attachedToProcess;
 
         // for remote debugging usage (mainly)

--- End code ---

This patch works OK under MinGW GDB6.8 and GDB7.4.

Comments are welcome.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version