running gdb and attaching back: why doesn't this work?
mario rossi
mario30468@yahoo.com
Tue Nov 8 07:21:00 GMT 2005
Hi,
I've been trying to run gdb from a thread to get a
stack trace of such thread...but it doesn't seem to
work as expected under cygwin. The code I tried is
attached below.
The output I get from the code is:
[Switching to thread 3420.0xab0]
* 4 thread 3420.0xab0 0x77f75a59 in
ntdll!DbgUiConnectToDbg () from
/c/WINDOWS/System32/ntdll.dll
3 thread 3420.0xe24 0x7ffe0304 in ?? ()
2 thread 3420.0xfa4 0x7ffe0304 in ?? ()
1 thread 3420.0xffc 0x7ffe0304 in ?? ()
[Switching to thread 1 (thread 3420.0xffc)]#0
0x7ffe0304 in ?? ()
#0 0x7ffe0304 in ?? ()
#1 0x77f5c524 in ntdll!ZwWaitForMultipleObjects ()
from
/c/WINDOWS/System32/ntdll.dll
#2 0x77e75f0b in WaitForMultipleObjectsEx () from
/c/WINDOWS/system32/kernel32.dll
#3 0x00000002 in ?? ()
#4 0x0022dc1c in ?? ()
#5 0x00000001 in ?? ()
#6 0x00000000 in ?? () from
Now, thread 1 is in fact the one running main() and
the called functions, but it doesn't show the proper
stack trace. I can verifty that thread 1 is the right
one by attaching one more gdb started manually to the
very same app. If I do that and type "info threads" I
get:
* 4 thread 3420.0xfc0 0x77f75a59 in
ntdll!DbgUiConnectToDbg () from
/c/WINDOWS/System32/ntdll.dll
3 thread 3420.0xe24 0x7ffe0304 in ?? ()
2 thread 3420.0xfa4 0x7ffe0304 in ?? ()
1 thread 3420.0xffc f () at test.c:31
Any Idea what might be wrong, and how to solve it?
Thanks,
Mario
-----------------------------------8<---------------------------------------------------------------------
#include "stdio.h"
static char program_name[256];
#define CMD_FILE_NAME "./.teja_gdb_cmds"
void backtrace() {
char hugebuf[512];
FILE *cmds;
cmds = fopen(CMD_FILE_NAME, "w");
if (!cmds) {
printf("unable to obtain stack trace (couldn't
open cmd file)\n");
return;
}
fprintf(cmds, "attach %d\n", getpid());
fprintf(cmds, "info threads\n");
fprintf(cmds, "thread 1\n");
fprintf(cmds, "bt\n");
fprintf(cmds, "detach\n");
fprintf(cmds, "quit\n");
fclose(cmds);
snprintf( hugebuf, sizeof hugebuf, "gdb -batch -x %s
%s",
CMD_FILE_NAME, program_name);
system(hugebuf);
}
void f() {
backtrace();
while(1);
}
void g() {
f();
}
int main(int argc, char **argv) {
strcpy(program_name, argv[0]);
g();
return 0;
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list