public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* backtrace(3) in Cygwin?
@ 2015-03-11 17:22 David Stacey
  2015-03-11 17:44 ` Corinna Vinschen
  2015-03-11 18:21 ` Yaakov Selkowitz
  0 siblings, 2 replies; 5+ messages in thread
From: David Stacey @ 2015-03-11 17:22 UTC (permalink / raw)
  To: cygwin

Please could you tell me if Cygwin supports backtrace(3) and 
backtrace_symbols(3) [1]? I can't find the execinfo.h header file, but 
presumably Cygwin is capable of generating a backtrace because the 'bt' 
command works in gdb.

Thanks in advance for your help,

Dave.

[1] - http://linux.die.net/man/3/backtrace


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: backtrace(3) in Cygwin?
  2015-03-11 17:22 backtrace(3) in Cygwin? David Stacey
@ 2015-03-11 17:44 ` Corinna Vinschen
  2015-03-11 18:48   ` David Stacey
  2015-03-11 18:21 ` Yaakov Selkowitz
  1 sibling, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2015-03-11 17:44 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 915 bytes --]

On Mar 11 17:10, David Stacey wrote:
> Please could you tell me if Cygwin supports backtrace(3) and
> backtrace_symbols(3) [1]? I can't find the execinfo.h header file, but
> presumably Cygwin is capable of generating a backtrace because the 'bt'
> command works in gdb.

GDB's `bt' implementation has nothing to do with Cygwin's capability
to walk a stack.  Cygwin only has limited capabilities there which
are used to create the stackdump file, see the stack_walk class in
exceptions.cc:
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob_plain;f=winsup/cygwin/exceptions.cc 

If you want to create a backtrace(3) function set for Cygwin, feel
free: https://cygwin.com/contrib.html
I'm certainly not averse to patches...


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: backtrace(3) in Cygwin?
  2015-03-11 17:22 backtrace(3) in Cygwin? David Stacey
  2015-03-11 17:44 ` Corinna Vinschen
@ 2015-03-11 18:21 ` Yaakov Selkowitz
  1 sibling, 0 replies; 5+ messages in thread
From: Yaakov Selkowitz @ 2015-03-11 18:21 UTC (permalink / raw)
  To: cygwin

On Wed, 2015-03-11 at 17:10 +0000, David Stacey wrote:
> Please could you tell me if Cygwin supports backtrace(3) and 
> backtrace_symbols(3) [1]? I can't find the execinfo.h header file

It does not.  However, if anyone has cycles to implement it, that would
be nice.  You may wish to see how WebKit fakes backtrace(3) on Windows
by using RtlCaptureStackBackTrace:

https://trac.webkit.org/browser/trunk/Source/WTF/wtf/Assertions.cpp#L226
https://msdn.microsoft.com/en-us/library/windows/hardware/ff552119.aspx

> presumably Cygwin is capable of generating a backtrace because the 'bt' 
> command works in gdb.

No, gdb has it's own implementation to meet its own needs.

--
Yaakov



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: backtrace(3) in Cygwin?
  2015-03-11 17:44 ` Corinna Vinschen
@ 2015-03-11 18:48   ` David Stacey
  2015-03-11 19:58     ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: David Stacey @ 2015-03-11 18:48 UTC (permalink / raw)
  To: cygwin

On 11/03/15 17:22, Corinna Vinschen wrote:
> On Mar 11 17:10, David Stacey wrote:
>> Please could you tell me if Cygwin supports backtrace(3) and
>> backtrace_symbols(3) [1]? I can't find the execinfo.h header file, but
>> presumably Cygwin is capable of generating a backtrace because the 'bt'
>> command works in gdb.
> GDB's `bt' implementation has nothing to do with Cygwin's capability
> to walk a stack.  Cygwin only has limited capabilities there which
> are used to create the stackdump file, see the stack_walk class in
> exceptions.cc:
> https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob_plain;f=winsup/cygwin/exceptions.cc  
>
> If you want to create a backtrace(3) function set for Cygwin, feel
> free:https://cygwin.com/contrib.html
> I'm certainly not averse to patches...

Thanks for your reply. It shouldn't be too hard to create 
implementations of backtrace(3) and backtrace_symbols(3) using 
CaptureStackBackTrace() [1] and SymFromAddr() [2]. There should be 
enough information in a SYMBOL_INFO structure to create strings in the 
same format as backtrace_symbols().

backtrace_symbols_fd(3) might be harder, because I'm not sure I can 
honour the promise not to use heap memory internally. Also, note that 
the Windows functions mentioned above are single-threaded, and therefore 
any implementation based on them will be single-threaded also. Further, 
Windows XP is limited to 63 stack frames.

I'm rather busy at the moment, but if I have time then I'll have a go.

Dave.

[1] - 
https://msdn.microsoft.com/en-us/library/windows/desktop/bb204633%28v=vs.85%29.aspx
[2] - 
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681323%28v=vs.85%29.aspx


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: backtrace(3) in Cygwin?
  2015-03-11 18:48   ` David Stacey
@ 2015-03-11 19:58     ` Corinna Vinschen
  0 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2015-03-11 19:58 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2366 bytes --]

On Mar 11 18:41, David Stacey wrote:
> On 11/03/15 17:22, Corinna Vinschen wrote:
> >On Mar 11 17:10, David Stacey wrote:
> >>Please could you tell me if Cygwin supports backtrace(3) and
> >>backtrace_symbols(3) [1]? I can't find the execinfo.h header file, but
> >>presumably Cygwin is capable of generating a backtrace because the 'bt'
> >>command works in gdb.
> >GDB's `bt' implementation has nothing to do with Cygwin's capability
> >to walk a stack.  Cygwin only has limited capabilities there which
> >are used to create the stackdump file, see the stack_walk class in
> >exceptions.cc:
> >https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob_plain;f=winsup/cygwin/exceptions.cc
> >
> >If you want to create a backtrace(3) function set for Cygwin, feel
> >free:https://cygwin.com/contrib.html
> >I'm certainly not averse to patches...
> 
> Thanks for your reply. It shouldn't be too hard to create implementations of
> backtrace(3) and backtrace_symbols(3) using CaptureStackBackTrace() [1] and
> SymFromAddr() [2]. There should be enough information in a SYMBOL_INFO
> structure to create strings in the same format as backtrace_symbols().
> 
> backtrace_symbols_fd(3) might be harder, because I'm not sure I can honour
> the promise not to use heap memory internally.

This is something we can analyze and discuss on the cygwin-developers
mailing list if you're really interested in implementing this stuff at
one point.

> Also, note that the Windows
> functions mentioned above are single-threaded, and therefore any
> implementation based on them will be single-threaded also.

What about StackWalk64?  And what about the existing implementation
in stack_info::walk using RtlLookupFunctionEntry and RtlVirtualUnwind
on x86_64?

Ideally we only have one stack walk implementation and use them in
both situations, implementing backtrace(3) and creating the stackdump.
The stack_info::walk code for 32 bit really needs a thorough revamp
anyway.

> Further, Windows
> XP is limited to 63 stack frames.

Meh.

> I'm rather busy at the moment, but if I have time then I'll have a go.

That would be cool.  I'm looking forward to this.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2015-03-11 19:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-11 17:22 backtrace(3) in Cygwin? David Stacey
2015-03-11 17:44 ` Corinna Vinschen
2015-03-11 18:48   ` David Stacey
2015-03-11 19:58     ` Corinna Vinschen
2015-03-11 18:21 ` Yaakov Selkowitz

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).