2 Copyright © 2010, The AROS Development Team. All rights reserved.
5 Desc: Alert context parsing routines
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"
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";
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
);
36 switch (iet
->iet_AlertType
)
39 buf
= Alert_AddString(buf
, "\nCPU context:\n");
40 buf
= FormatCPUContext(buf
, &iet
->iet_AlertData
.u
.acpu
, SysBase
);
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
;
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 */
62 #ifdef KrnDecodeLocation
63 char *modname
, *segname
, *symname
;
64 void *segaddr
, *symaddr
;
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
,
80 symname
= "- unknown -";
82 buf
= NewRawDoFmt(funstring
, RAWFMTFUNC_STRING
, buf
, caller
, modname
, symname
, caller
- symaddr
);
87 segname
= "- unknown -";
89 buf
= NewRawDoFmt(modstring
, RAWFMTFUNC_STRING
, buf
, caller
, modname
, segnum
, segname
, caller
- segaddr
);
94 buf
= NewRawDoFmt(unknownstr
, RAWFMTFUNC_STRING
, buf
, caller
);
98 /* Invalid address stops unwinding */
99 buf
= NewRawDoFmt(invalidstr
, RAWFMTFUNC_STRING
, buf
, fp
);
103 /* Stop if we have no more frames */
108 * After NewRawDoFmt() returned pointer points to the location AFTER
109 * NULL terminator, so we need to step back in order to append one