delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/11/08/02:13:29

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <20051108071317.63276.qmail@web36307.mail.mud.yahoo.com>
Date: Mon, 7 Nov 2005 23:13:17 -0800 (PST)
From: mario rossi <mario30468 AT yahoo DOT com>
Subject: running gdb and attaching back: why doesn't this work?
To: cygwin AT cygwin DOT com
MIME-Version: 1.0
X-IsSubscribed: yes

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019