I'm using the LLVM exception handling intrinsics, along with a custom personality function, to do exception handling and it is working well. Now, I would like to add the ability to produce a human-readable stack backtrace for exceptions which are not caught (or rather, which are caught by some top-level function which prints the exception's stack trace). I'm assuming that the way to make this work is to modify the exception personality function to capture information about the stack. Unfortunately, none of my experiments in this area have yielded anything useful. For example, I have experimented with calling _Unwind_Backtrace from the personality function, but this only yields an _Unwind_Context pointer which is of limited use. It's hard to tell because most of the structures are opaque, but it appears as though the information I'm getting from _Unwind_Backtrace has little or no relation to the state of the stack at the time the exception was actually thrown. It may be that what I am getting is the stack at the point of the catch statement, which isn't terribly useful for this purpose. But as I say, it's hard to tell. I thought about using libunwind functions directly (unw_step and such), but it doesn't appear that libunwind is available on OS X. I've also tried using the 'backtrace' function from execinfo.h, but again the information I get when I call it from within the personality function doesn't appear to have much relation to the call stack at the time the exception is thrown. What I would like to solve is the following problems: 1) After a successful phase 1 (search phase) of the unwind, I'd like to get information about all stack frames that are in-between the initial throwing frame, and the frame that actually handled the exception. In other words, the search phase would proceed as normal, and then during phase 2 (handler/cleanup phase) it would incrementally build a list of frame infos for each frame. 2) Given a frame, a way to determine the DWARF debug information for that function. Given an _Unwind_Context, it is easy to get the program counter for that frame, so I assume that this is just a matter of converting the program counter to a function name. 3) Similarly, I'd like some means to determine the current line number that corresponds to the program counter value for a given frame. Bear in mind that I am not using any of the C++ library functions, my exception handling code is using unwind.h directly and does not link with any of the C++ libraries. -- -- Talin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091024/c7a7ca1d/attachment.html>
Hi Talin,> I'm using the LLVM exception handling intrinsics, along with a custom > personality function, to do exception handling and it is working well. > Now, I would like to add the ability to produce a human-readable stack > backtrace for exceptions which are not caught (or rather, which are > caught by some top-level function which prints the exception's stack trace).the Ada frontend does this in gcc/ada/tracebak.c. Ciao, Duncan.
Hmm, well I looked at the code, and it's significantly more complex than I really want to deal with at this moment. I was hoping for some sort of API, like libunwind, that is supported across multiple platforms, rather than something that has to be implemented for a bunch of processors that I don't have :) I realize that this is a rather hard problem to begin with - which is why I was hoping to leverage someone else's solution rather than build my own. As an aside, when I was working at Electronic Arts, we had a number of "crash dumper" tools that automatically collected stack trace info for C++ programs which were used during the QA process. After I left the company, I looked around for an open source solution that would do the same thing - that is, to give a summary report of a crash that could be uploaded or attached to a bug report. I know that Mozilla and KDE have utilities like these, as does OS X - but what I didn't find was any sort of general library or toolkit for doing this. (Maybe I was looking in the wrong places). The more that I delve into the realm of exceptions, stack dumps, source level debugging, and other areas where the compiler interfaces with the platform, the more I kind of wish that the LLVM umbrella would extend a little further, to provide the same kind of platform-neutral abstractions that it does for code generation. On Sun, Oct 25, 2009 at 2:07 AM, Duncan Sands <baldrick at free.fr> wrote:> Hi Talin, > > > I'm using the LLVM exception handling intrinsics, along with a custom >> personality function, to do exception handling and it is working well. Now, >> I would like to add the ability to produce a human-readable stack backtrace >> for exceptions which are not caught (or rather, which are caught by some >> top-level function which prints the exception's stack trace). >> > > the Ada frontend does this in gcc/ada/tracebak.c. > > Ciao, > > Duncan. >-- -- Talin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091026/b4e02815/attachment.html>
Possibly Parallel Threads
- [LLVMdev] Producing a stack dump via libunwind?
- Supporting libunwind on Windows 10 (32bit; 64bit) for MSVC and Clang
- [LLVMdev] Printing a stack trace?
- [LLVMdev] cfrontend-1.3.source: Compilation error
- [LLVMdev] How to code catch-all in the new exception handling scheme?