Build fix, include deflibdefs.h during dependencies generation.
[AROS.git] / rom / exec / alertextra.c
blob423dfebe77f74ac82d8ca58a03fd0152d24de159
1 /*
2 Copyright © 2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Alert context parsing routines
6 Lang: english
7 */
9 #include <aros/kernel.h>
10 #include <exec/rawfmt.h>
11 #include <proto/kernel.h>
13 #include "exec_intern.h"
14 #include "exec_util.h"
15 #include "etask.h"
17 #define TRACE_DEPTH 10
19 #ifdef KrnDecodeLocation
20 static const char *modstring = "\n0x%P %s Segment %lu %s + 0x%P";
21 static const char *funstring = "\n0x%P %s Function %s + 0x%P";
22 #endif
23 static const char *unknownstr = "\n0x%P Address not found";
24 static const char *invalidstr = "\n0x%P Invalid stack frame address";
27 * Make a readable text out of task's alert context
28 * The supplied buffer pointer points to the end of already existing
29 * text, so we start every our line with '\n'.
31 void FormatAlertExtra(char *buffer, struct Task *task, struct ExecBase *SysBase)
33 struct IntETask *iet = GetIntETask(task);
34 char *buf = buffer;
36 switch (iet->iet_AlertType)
38 case AT_CPU:
39 buf = Alert_AddString(buf, "\nCPU context:\n");
40 buf = FormatCPUContext(buf, &iet->iet_AlertData.u.acpu, SysBase);
42 break;
44 /* TODO: add more types (memory manager is the first candidate) */
48 /* If we have AlertStack, compose a backtrace */
49 if (iet->iet_AlertStack)
51 APTR fp = iet->iet_AlertStack;
52 ULONG i;
54 buf = Alert_AddString(buf, "\nStack trace:");
56 for (i = 0; i < TRACE_DEPTH; i++)
58 /* Safety check: ensure that frame pointer address is valid */
59 if (TypeOfMem(fp))
61 APTR caller = NULL;
62 #ifdef KrnDecodeLocation
63 char *modname, *segname, *symname;
64 void *segaddr, *symaddr;
65 unsigned int segnum;
66 #endif
68 fp = UnwindFrame(fp, &caller);
70 #ifdef KrnDecodeLocation
71 if (KrnDecodeLocation(caller,
72 KDL_ModuleName , &modname, KDL_SegmentNumber, &segnum ,
73 KDL_SegmentName, &segname, KDL_SegmentStart , &segaddr,
74 KDL_SymbolName , &symname, KDL_SymbolStart , &symaddr,
75 TAG_DONE))
77 if (symaddr)
79 if (!symname)
80 symname = "- unknown -";
82 buf = NewRawDoFmt(funstring, RAWFMTFUNC_STRING, buf, caller, modname, symname, caller - symaddr);
84 else
86 if (!segname)
87 segname = "- unknown -";
89 buf = NewRawDoFmt(modstring, RAWFMTFUNC_STRING, buf, caller, modname, segnum, segname, caller - segaddr);
92 else
93 #endif
94 buf = NewRawDoFmt(unknownstr, RAWFMTFUNC_STRING, buf, caller);
96 else
98 /* Invalid address stops unwinding */
99 buf = NewRawDoFmt(invalidstr, RAWFMTFUNC_STRING, buf, fp);
100 break;
103 /* Stop if we have no more frames */
104 if (!fp)
105 break;
108 * After NewRawDoFmt() returned pointer points to the location AFTER
109 * NULL terminator, so we need to step back in order to append one
110 * more line
112 buf--;