public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* gdb on cygwin and debugging assert() or program segmentation faults
@ 2005-07-19 22:40 Kris Thielemans
  2005-07-20  2:09 ` Brian Dessent
  0 siblings, 1 reply; 4+ messages in thread
From: Kris Thielemans @ 2005-07-19 22:40 UTC (permalink / raw)
  To: gdb

Hi all,

I need to debug a C++ program that throws up an assert(). On Linux, I'm used to
be able to run the program in gdb, and when the assert happens, the program
stops (in the assert function) and I can do a back trace (e.g. info stack).
On cygwin on the other hand, I just get the assert message, and then gdb
says "Program exited normally". No backtrace possible.
 
The same difference in behaviour between Linux and cygwin with segmentation
faults. 

It would be incredibly useful to be able to see where the
assert/segmentation fault happened.


On the cygwin list, Dave Korn suggested the following work-around (for asserts 
only): do 'break __assert'. See end of email for more on this. However, that 
still doesn't solve the segmentation fault problem

I have

GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special)
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)

Any other suggestions?

Many thanks

Kris Thielemans
Hammersmith Imanet, part of GE Healthcare 
United Kingdom


-------------
PS: more on "break __assert trick"
This works on cygwin because assert is defined in terms of __assert.

This trick did work until I updated my cygwin (it now uses gcc 3.4.4 and some 
other stuff changed). 
In fact, it will now break before entering main() (in  
__static_initialization_and_destruction_0 ) but not when the assert is 
called.

Using "break __assert" says
(gdb) break __assert
Breakpoint 1 at 0x4ac3e6: file /usr/lib/gcc/i686-pc-
cygwin/3.4.4/include/c++/iostream, line 77.
(gdb) r 
Starting program: /home/kris/MyDocuments/mytest.exe

Breakpoint 1, __static_initialization_and_destruction_0 (__initialize_p=1, 
    __priority=65535)
    at /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/iostream:77
(gdb) c
assertion "overlap>-epsilon" failed: 
file "./include/stir/numerics/overlap_interpolate.inl", line 108

Program exited normally.


(I might be able to #define assert to my own function and break there.)



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gdb on cygwin and debugging assert() or program segmentation faults
  2005-07-19 22:40 gdb on cygwin and debugging assert() or program segmentation faults Kris Thielemans
@ 2005-07-20  2:09 ` Brian Dessent
  2005-07-20  2:37   ` Christopher Faylor
  0 siblings, 1 reply; 4+ messages in thread
From: Brian Dessent @ 2005-07-20  2:09 UTC (permalink / raw)
  To: gdb

Kris Thielemans wrote:

> I need to debug a C++ program that throws up an assert(). On Linux, I'm used to
> be able to run the program in gdb, and when the assert happens, the program
> stops (in the assert function) and I can do a back trace (e.g. info stack).
> On cygwin on the other hand, I just get the assert message, and then gdb
> says "Program exited normally". No backtrace possible.

Set the error_start parameter of the CYGWIN variable to gdb and then run
the program, and you should gdb launched and attached to the process
when it encounters a SEGV or abort().  See the users manual section
about $CYGWIN.

Brian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gdb on cygwin and debugging assert() or program segmentation faults
  2005-07-20  2:09 ` Brian Dessent
@ 2005-07-20  2:37   ` Christopher Faylor
  2005-07-20 10:28     ` Dave Korn
  0 siblings, 1 reply; 4+ messages in thread
From: Christopher Faylor @ 2005-07-20  2:37 UTC (permalink / raw)
  To: gdb

On Tue, Jul 19, 2005 at 07:13:17PM -0700, Brian Dessent wrote:
>Kris Thielemans wrote:
>
>> I need to debug a C++ program that throws up an assert(). On Linux, I'm used to
>> be able to run the program in gdb, and when the assert happens, the program
>> stops (in the assert function) and I can do a back trace (e.g. info stack).
>> On cygwin on the other hand, I just get the assert message, and then gdb
>> says "Program exited normally". No backtrace possible.
>
>Set the error_start parameter of the CYGWIN variable to gdb and then run
>the program, and you should gdb launched and attached to the process
>when it encounters a SEGV or abort().  See the users manual section
>about $CYGWIN.

And, FWIW, gdb *does* do the right thing (i.e., the same thing as any
UNIX system) when the program generates a genuine SIGSEGV.  It just
doesn't do anything for cygwin-specific signals like SIGABRT.  It
also won't stop if you do something like "kill (getpid (), SIGSEGV)" since
that just sends a "cygwin signal".

cgf

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: gdb on cygwin and debugging assert() or program segmentation faults
  2005-07-20  2:37   ` Christopher Faylor
@ 2005-07-20 10:28     ` Dave Korn
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Korn @ 2005-07-20 10:28 UTC (permalink / raw)
  To: gdb

----Original Message----
>From: Christopher Faylor
>Sent: 20 July 2005 03:37

> On Tue, Jul 19, 2005 at 07:13:17PM -0700, Brian Dessent wrote:
>> Kris Thielemans wrote:
>> 
>>> I need to debug a C++ program that throws up an assert(). On Linux, I'm
>>> used to be able to run the program in gdb, and when the assert happens,
>>> the program stops (in the assert function) and I can do a back trace
>>> (e.g. info stack). 
>>> On cygwin on the other hand, I just get the assert message, and then gdb
>>> says "Program exited normally". No backtrace possible.

> And, FWIW, gdb *does* do the right thing (i.e., the same thing as any
> UNIX system) when the program generates a genuine SIGSEGV.  It just
> doesn't do anything for cygwin-specific signals like SIGABRT.  It
> also won't stop if you do something like "kill (getpid (), SIGSEGV)" since
> that just sends a "cygwin signal".

  By "genuine SIGSEGV" you mean a real x86 exception, and by "cygwin
signal", you mean writing a signal packet down the pipe to the signal
handling thread, yes?

  So this implies that cygwin-native support could in theory be added to gdb
to make it respond to cygwin signals?

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-07-20 10:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-19 22:40 gdb on cygwin and debugging assert() or program segmentation faults Kris Thielemans
2005-07-20  2:09 ` Brian Dessent
2005-07-20  2:37   ` Christopher Faylor
2005-07-20 10:28     ` Dave Korn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).