From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12627 invoked by alias); 6 May 2011 21:33:09 -0000 Received: (qmail 12614 invoked by uid 22791); 6 May 2011 21:33:08 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_FX X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 06 May 2011 21:32:54 +0000 From: "fxcoudert at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/46686] Improve backtracing (unwinding) on MinGW X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fxcoudert at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: CC Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Fri, 06 May 2011 21:33:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg00600.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46686 Francois-Xavier Coudert changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |fxcoudert at gcc dot | |gnu.org --- Comment #1 from Francois-Xavier Coudert 2011-05-06 21:25:24 UTC --- The generic code below relies on libgcc routines, it should work anywhere, doesn't it? (Well, on mingw you won't be able to resolve function names using dladdr(), so you're stuck with the address only, but that's already useful information). Anyway, I don't have time to propose a patch, but the code below works nicely on Mac OS (where gfortran doesn't currently support backtraces). ------------------------------------------ #include #include #include #include typedef enum { _URC_NO_REASON = 0, _URC_FOREIGN_EXCEPTION_CAUGHT = 1, _URC_FATAL_PHASE2_ERROR = 2, _URC_FATAL_PHASE1_ERROR = 3, _URC_NORMAL_STOP = 4, _URC_END_OF_STACK = 5, _URC_HANDLER_FOUND = 6, _URC_INSTALL_CONTEXT = 7, _URC_CONTINUE_UNWIND = 8 } _Unwind_Reason_Code; struct _Unwind_Context; typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *, void *); extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *); #if defined(__ia64__) && defined(__hpux__) typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__))); #else typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__))); #endif extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *); static _Unwind_Reason_Code trace_function (struct _Unwind_Context *context, void *unused) { void * ip = (void *)(uintptr_t) _Unwind_GetIP (context); Dl_info dlinfo; dladdr (ip, &dlinfo); if (dlinfo.dli_sname != NULL) printf ("%p (%s)\n", ip, dlinfo.dli_sname); else printf ("%p\n", ip); return _URC_NO_REASON; } void show_backtrace (void) { _Unwind_Backtrace (trace_function, NULL); }