Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
debugger plugin: catch the inferior PID under gdb
oBFusCATed:
You're very bold in removing the debug events code.
Are you really really sure that gdb will print these messages for every program you start?
What about remote debugging, can you try it?
ollydbg:
--- Quote from: oBFusCATed on April 10, 2012, 07:56:55 am ---You're very bold in removing the debug events code.
--- End quote ---
:)
--- Quote ---Are you really really sure that gdb will print these messages for every program you start?
--- End quote ---
I'm sure at least Windows GDB 6.8-7.4.
--- Quote ---What about remote debugging, can you try it?
--- End quote ---
I have never used remote debugging. I will try it under WinXP.
BTW:
The debug event on/off feature is a windows only feature implemented in GDB's source file:
--- Code: ---gdb\windows-nat.c
--- End code ---
It have such code snippet:
--- Code: ---#define DEBUG_EVENTS(x) if (debug_events) printf_unfiltered x
--- End code ---
and: Windows debug event handling.
--- Code: --- case CREATE_PROCESS_DEBUG_EVENT:
DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%x code=%s)\n",
(unsigned) current_event.dwProcessId,
(unsigned) current_event.dwThreadId,
"CREATE_PROCESS_DEBUG_EVENT"));
CloseHandle (current_event.u.CreateProcessInfo.hFile);
if (++saw_create != 1)
break;
--- End code ---
ollydbg:
@OBF:
I have finally find that how the
--- Code: ---[New Thread 2684.0xf40]
--- End code ---
Message come from under Windows.
In GDB top level, there is a function in: "gdb\thread.c"
--- Code: ---struct thread_info *
add_thread_with_info (ptid_t ptid, struct private_thread_info *private)
{
struct thread_info *result = add_thread_silent (ptid);
result->private = private;
if (print_thread_events)
printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid));
annotate_new_thread ();
return result;
}
--- End code ---
The function target_pid_to_str() has different implementation in different target, under Windows, it lowers down to "gdb\windows-nat.c"
--- Code: ---/* Convert pid to printable format. */
static char *
windows_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
static char buf[80];
if (ptid_get_tid (ptid) != 0)
{
snprintf (buf, sizeof (buf), "Thread %d.0x%lx",
ptid_get_pid (ptid), ptid_get_tid (ptid));
return buf;
}
return normal_pid_to_str (ptid);
}
--- End code ---
You see, the "Thread %d.0x%lx", the ptid_get_pid (ptid) value is just the PID.
BTW:
In gdb/thread.c
--- Code: ---/* Print notices when new threads are attached and detached. */
int print_thread_events = 1;
static void
show_print_thread_events (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file,
_("Printing of thread events is %s.\n"),
value);
}
--- End code ---
This means: the value print_thread_events is enabled by default. That's why we get such message under both Windows and Linux.
oBFusCATed:
--- Quote from: ollydbg on April 10, 2012, 09:34:40 am ---This means: the value print_thread_events is enabled by default. That's why we get such message under both Windows and Linux.
--- End quote ---
This is not 100% true for Linux and some (if not all) versions of gdb-7.xx, if you program doesn't use pthreads, it doesn't print it.
ollydbg:
--- Quote from: oBFusCATed on April 10, 2012, 10:20:20 am ---
--- Quote from: ollydbg on April 10, 2012, 09:34:40 am ---This means: the value print_thread_events is enabled by default. That's why we get such message under both Windows and Linux.
--- End quote ---
This is not 100% true for Linux and some (if not all) versions of gdb-7.xx, if you program doesn't use pthreads, it doesn't print it.
--- End quote ---
Ok, I'm not quite familiar with Linux, so I may wrong.
I have just did under Windows (gdb.exe, this is the local side and gdbserver.exe, this is the remote target side)
See the log on gdbserver side (remote side)
--- Code: ---E:\code\gdb\gdbservertest>gdbserver localhost:777 IsAlphaConsole.exe
Process IsAlphaConsole.exe created; pid = 1804
Listening on port 777
Remote debugging from host 127.0.0.1
48 is a digit
49 is a digit
50 is a digit
51 is a digit
52 is a digit
53 is a digit
54 is a digit
55 is a digit
56 is a digit
57 is a digit
178 is a digit
179 is a digit
185 is a digit
--- End code ---
GDB side: (local side)
--- Code: ---E:\code\gdb\gdbbin>gdb IsAlphaConsole.exe
GNU gdb (GDB) 7.4.50.20120331-cvs
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from E:\code\gdb\gdbbin\IsAlphaConsole.exe...done.
(gdb) target remote localhost:777
Remote debugging using localhost:777
0x7c90120f in ntdll!DbgUiConnectToDbg () from C:\WINDOWS\system32\ntdll.dll
(gdb) b main
Breakpoint 1 at 0x4016ee: file E:\code\cb\test_code\IsAlphaConsole\main.cpp, lin
e 10.
(gdb) b main.cpp:15
Breakpoint 2 at 0x401753: file E:\code\cb\test_code\IsAlphaConsole\main.cpp, lin
e 15.
(gdb) continue
Continuing.
Breakpoint 1, main () at E:\code\cb\test_code\IsAlphaConsole\main.cpp:10
10 for (i = 0; i < 500; ++i)
(gdb) c
Continuing.
Breakpoint 2, main () at E:\code\cb\test_code\IsAlphaConsole\main.cpp:16
16 for (i = 0; i < 500; ++i)
(gdb)
--- End code ---
I'm not sure how Codeblocks catch the PID in the remote side?
It seems that the only interested line is:
--- Code: ---Process IsAlphaConsole.exe created; pid = 1804
--- End code ---
This is the PID in the remote target. So, my patch does not touch the remote debugging feature in c::b.
See the log when I enable debugevent on in gdb.exe side:
--- Code: ---E:\code\gdb\gdbbin>gdb IsAlphaConsole.exe
GNU gdb (GDB) 7.4.50.20120331-cvs
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from E:\code\gdb\gdbbin\IsAlphaConsole.exe...done.
(gdb) set debugevents on
(gdb) target remote localhost:777
Remote debugging using localhost:777
0x7c90120f in ntdll!DbgUiConnectToDbg () from C:\WINDOWS\system32\ntdll.dll
(gdb) b main
Breakpoint 1 at 0x4016ee: file E:\code\cb\test_code\IsAlphaConsole\main.cpp, lin
e 10.
(gdb) b main.cpp:15
Breakpoint 2 at 0x401753: file E:\code\cb\test_code\IsAlphaConsole\main.cpp, lin
e 15.
(gdb) c
Continuing.
Breakpoint 1, main () at E:\code\cb\test_code\IsAlphaConsole\main.cpp:10
10 for (i = 0; i < 500; ++i)
(gdb) c
Continuing.
--- End code ---
So, As a conclusion: no PID information about the process in remote side is shown here if I enable debugevents on.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version