2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
10 #include <exec/execbase.h>
11 #include <exec/tasks.h>
13 #include <proto/exec.h>
14 #include <proto/dos.h>
16 #include <aros/debug.h>
22 #define ARG_TEMPLATE "TASK/K,STDOUT/S"
28 static struct RDArgs
*MyArgs
;
29 static IPTR Args
[NUM_ARGS
];
32 static UBYTE outbuffer
[20000];
33 static LONG outbuffer_size
;
34 static BOOL to_stdout
;
36 static void Cleanup(char *msg
)
42 printf("stacksnoop: %s\n",msg
);
48 if (MyArgs
) FreeArgs(MyArgs
);
53 static void OpenLibs(void)
58 static void GetArguments(void)
60 if (!(MyArgs
= ReadArgs(ARG_TEMPLATE
,Args
,0)))
62 Fault(IoErr(),0,s
,255);
66 if (Args
[ARG_STDOUT
]) to_stdout
= TRUE
;
69 static int out (const UBYTE
* fmt
, ...)
77 result
= vsprintf(&outbuffer
[outbuffer_size
], fmt
, ap
);
78 outbuffer_size
+= result
;
82 result
= vkprintf(fmt
, ap
);
90 static void CheckTaskStack(struct Task
*task
)
92 UBYTE
*startcheck
, *endcheck
;
93 LONG stacksize
, stackinc
, unusedstack
= 0;
95 stacksize
= (LONG
)( ((UBYTE
*)task
->tc_SPUpper
) - ((UBYTE
*)task
->tc_SPLower
) );
97 #if AROS_STACK_GROWS_DOWNWARDS
98 startcheck
= (UBYTE
*)task
->tc_SPLower
;
99 endcheck
= ((UBYTE
*)task
->tc_SPUpper
) - 1;
102 startcheck
= ((UBYTE
*)task
->tc_SPUpper
) - 1;
103 endcheck
= (UBYTE
*)task
->tc_SPLower
;
107 for(; startcheck
!= endcheck
; startcheck
+= stackinc
)
109 if (*startcheck
!= 0xE1) break;
113 out("Task %x (%25s) Stack Size =%6d, Left =%6d, Used %s%6d%s\n",
115 task
->tc_Node
.ln_Name
? task
->tc_Node
.ln_Name
: "<NONAME>",
118 ((stacksize
- unusedstack
) < stacksize
) ? "=" : ">",
119 stacksize
- unusedstack
,
120 (unusedstack
< 512) ? ": Needs more stack!!!!!!!!!" : "");
123 static void Action(void)
130 out("\n------------------------------------------------------------------------------\n\n");
132 task
= (struct Task
*)SysBase
->TaskReady
.lh_Head
;
133 for(i
= 0; i
< 2;i
++)
135 while(task
->tc_Node
.ln_Succ
)
137 CheckTaskStack(task
);
139 task
= (struct Task
*)task
->tc_Node
.ln_Succ
;
140 } /* while(task->tc_Node.ln_Succ) */
142 task
= (struct Task
*)SysBase
->TaskWait
.lh_Head
;
144 } /* for(i = 0; i < 2;i++) */
146 CheckTaskStack(FindTask(NULL
));
147 out("\n------------------------------------------------------------------------------\n\n");
151 if (to_stdout
) puts(outbuffer
);