2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
10 #include <exec/execbase.h>
11 #include <exec/tasks.h>
12 #include <exec/rawfmt.h>
14 #include <proto/exec.h>
15 #include <proto/dos.h>
16 #include <proto/debug.h>
17 #include <proto/alib.h>
21 #define ARG_TEMPLATE "TASK/K,DEBUG/S"
27 static struct RDArgs
*MyArgs
;
28 static IPTR Args
[NUM_ARGS
];
31 static UBYTE outbuffer
[20000];
32 static LONG outbuffer_size
;
34 static void Cleanup(char *msg
)
37 Printf("stacksnoop: %s\n",msg
);
39 if (MyArgs
) FreeArgs(MyArgs
);
42 static ULONG
GetArguments(void)
44 if (!(MyArgs
= ReadArgs(ARG_TEMPLATE
,Args
,0)))
46 Fault(IoErr(),0,s
,255);
53 static int out (const UBYTE
* fmt
, ...)
60 VNewRawDoFmt(fmt
, RAWFMTFUNC_STRING
, &outbuffer
[outbuffer_size
], ap
);
61 result
= strlen(&outbuffer
[outbuffer_size
]);
64 KPutStr(&outbuffer
[outbuffer_size
]);
66 outbuffer_size
+= result
;
74 static void CheckTaskStack(struct Task
*task
)
76 UBYTE
*startcheck
, *endcheck
;
77 LONG stacksize
, stackinc
, unusedstack
= 0;
79 stacksize
= (LONG
)( ((UBYTE
*)task
->tc_SPUpper
) - ((UBYTE
*)task
->tc_SPLower
) );
81 #if AROS_STACK_GROWS_DOWNWARDS
82 startcheck
= (UBYTE
*)task
->tc_SPLower
;
83 endcheck
= ((UBYTE
*)task
->tc_SPUpper
) - 1;
86 startcheck
= ((UBYTE
*)task
->tc_SPUpper
) - 1;
87 endcheck
= (UBYTE
*)task
->tc_SPLower
;
91 for(; startcheck
!= endcheck
; startcheck
+= stackinc
)
93 if (*startcheck
!= 0xE1) break;
97 out("Task %x (%25s) Stack Size =%6d, Left =%6d, Used %s%6d%s\n",
99 task
->tc_Node
.ln_Name
? task
->tc_Node
.ln_Name
: "<NONAME>",
102 ((stacksize
- unusedstack
) < stacksize
) ? "=" : ">",
103 stacksize
- unusedstack
,
104 (unusedstack
< 512) ? ": Needs more stack!!!!!!!!!" : "");
107 static void Action(void)
114 out("\n------------------------------------------------------------------------------\n\n");
116 task
= (struct Task
*)SysBase
->TaskReady
.lh_Head
;
117 for(i
= 0; i
< 2;i
++)
119 while(task
->tc_Node
.ln_Succ
)
121 CheckTaskStack(task
);
123 task
= (struct Task
*)task
->tc_Node
.ln_Succ
;
124 } /* while(task->tc_Node.ln_Succ) */
126 task
= (struct Task
*)SysBase
->TaskWait
.lh_Head
;
128 } /* for(i = 0; i < 2;i++) */
130 CheckTaskStack(FindTask(NULL
));
131 out("\n------------------------------------------------------------------------------\n\n");
138 ULONG __nocommandline
= 1;