- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I have followed the instructions to enabled the "instruction related exception" and is able to catch the exception. The exception handler provides the cause and address which can be used to determine what instruction caused the exception. However, I also would like to get the backtrace when this exception happened. Could anyone help me to figure out how to get the backtrace? Thanks
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The easiest method is that used by the linux kernel:
Just scan through the stack and report every value that is inside the code area. Stale values (caused by unwritten locations in the current call sequence) are a slight problem. If the code is compiled to use a frame pointer, then it should be possible to follow the fp chain (fp should point to the previous value and the return address should be in the adjacent location). But IIRC someone has reported that gcc doesn't always get this right. Or you can use the debug info generated by the compiler that contains the stack offset at every instruction offset - not for the faint hearted. Or you can follow the instruction stream forwards while monitoring the value of sp (and fp) until you hit a return instruction. You need to remember the instructions processed and be willing to restart assuming that a branch is taken. Works quite well provided you are in a function that can return. Probably not to bad to implement for nios either (a pain for x86).- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, I will try to do what you have suggested.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page