revert between 56095 -> 55830 in arch
[AROS.git] / rom / exec / alertextra.c
blobe89dafdaed894b7fa04fab3fa6782e284600d50e
1 /*
2 Copyright © 2010-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Alert context parsing routines
6 Lang: english
7 */
9 #include <exec/rawfmt.h>
10 #include <libraries/debug.h>
11 #include <proto/debug.h>
13 #include "exec_intern.h"
14 #include "exec_util.h"
15 #include "etask.h"
16 #include "memory.h"
18 #define TRACE_DEPTH 10
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 static const char unknownstr[] = "\n0x%P Address not found";
23 static const char invalidstr[] = "\n0x%P Invalid stack frame address";
26 * Make a readable text out of task's alert context
27 * The supplied buffer pointer points to the end of already existing
28 * text, so we start every our line with '\n'.
30 void FormatAlertExtra(char *buffer, APTR stack, UBYTE type, APTR data, struct ExecBase *SysBase)
32 char *buf = buffer;
34 switch (type)
36 case AT_CPU:
37 buf = Alert_AddString(buf, "\nCPU context:\n");
38 buf = FormatCPUContext(buf, data, SysBase);
40 break;
42 case AT_MUNGWALL:
43 buf = Alert_AddString(buf, "\nMungwall data:\n");
44 buf = FormatMWContext(buf, data, SysBase);
46 break;
48 case AT_MEMORY:
49 buf = Alert_AddString(buf, "\nMemory manager data:\n");
50 buf = FormatMMContext(buf, data, SysBase);
52 break;
56 /* If we have AlertStack, compose a backtrace */
57 if (stack)
59 APTR fp = stack;
60 ULONG i;
62 buf = Alert_AddString(buf, "\nStack trace:");
64 for (i = 0; i < TRACE_DEPTH; i++)
66 /* Safety check: ensure that frame pointer address is valid */
67 if (TypeOfMem(fp))
69 APTR caller = NULL;
70 char *modname, *segname, *symname;
71 void *segaddr, *symaddr;
72 unsigned int segnum;
74 fp = UnwindFrame(fp, &caller);
76 if (DebugBase && DecodeLocation(caller,
77 DL_ModuleName , &modname, DL_SegmentNumber, &segnum ,
78 DL_SegmentName, &segname, DL_SegmentStart , &segaddr,
79 DL_SymbolName , &symname, DL_SymbolStart , &symaddr,
80 TAG_DONE))
82 if (symaddr)
84 if (!symname)
85 symname = "- unknown -";
87 buf = NewRawDoFmt(funstring, RAWFMTFUNC_STRING, buf, caller, modname, symname, caller - symaddr);
89 else
91 if (!segname)
92 segname = "- unknown -";
94 buf = NewRawDoFmt(modstring, RAWFMTFUNC_STRING, buf, caller, modname, segnum, segname, caller - segaddr);
97 else
98 buf = NewRawDoFmt(unknownstr, RAWFMTFUNC_STRING, buf, caller);
100 else
102 /* Invalid address stops unwinding */
103 buf = NewRawDoFmt(invalidstr, RAWFMTFUNC_STRING, buf, fp);
104 break;
107 /* Stop if we have no more frames */
108 if (!fp)
109 break;
112 * After NewRawDoFmt() returned pointer points to the location AFTER
113 * NULL terminator, so we need to step back in order to append one
114 * more line
116 buf--;