define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / rom / intuition / dumpintuistate.c
blobc9ca2e91f3a5fb9e4b11ed9d985549c10eda4041
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include "intuition_intern.h"
9 static void ShowSemaphore(const char *, struct SignalSemaphore *);
10 static void ShowLayer(struct Layer *);
12 /*****************************************************************************
14 NAME */
15 #include <proto/intuition.h>
17 AROS_LH0(void, DumpIntuiState,
19 /* SYNOPSIS */
21 /* LOCATION */
22 struct IntuitionBase *, IntuitionBase, 152, Intuition)
24 /* FUNCTION
25 Private: dump the internal state of intuition.
27 INPUTS
29 RESULT
30 none
32 NOTES
34 EXAMPLE
36 BUGS
38 SEE ALSO
40 INTERNALS
42 *****************************************************************************/
44 AROS_LIBFUNC_INIT
46 #if 1
48 struct IntIntuitionBase *IBase = GetPrivIBase(IntuitionBase);
49 struct Screen *scr;
50 struct Window *win;
52 Forbid();
54 dprintf("----------------------------------------------------------------\n");
55 dprintf("IntuitionBase 0x%lx\n", (ULONG) IntuitionBase);
56 ShowSemaphore("IBaseLock", IBase->IBaseLock);
57 ShowSemaphore("PubScrListLock", &IBase->PubScrListLock);
58 ShowSemaphore("GadgetLock", &IBase->GadgetLock);
59 ShowSemaphore("MenuLock", &IBase->MenuLock);
60 ShowSemaphore("IntuiActionLock", &IBase->IntuiActionLock);
61 ShowSemaphore("InputHandlerLock", &IBase->InputHandlerLock);
62 ShowSemaphore("ClassListLock", &IBase->ClassListLock);
64 dprintf("\nScreens:\n");
66 for (scr = IntuitionBase->FirstScreen; scr; scr = scr->NextScreen)
68 dprintf("\nScreen 0x%lx <%s>\n", (ULONG) scr, scr->Title ? scr->Title : (UBYTE *)"NULL");
70 dprintf("LayerInfo 0x%lx LockLayersCount %ld\n",
71 (ULONG) &scr->LayerInfo, (LONG) scr->LayerInfo.LockLayersCount);
72 ShowSemaphore("LayerInfo", &scr->LayerInfo.Lock);
73 ShowLayer(GetPrivScreen(scr)->rootLayer);
74 ShowLayer(scr->BarLayer);
76 for (win = scr->FirstWindow; win; win = win->NextWindow)
78 dprintf("\nWindow 0x%lx <%s>\n", (ULONG) win, win->Title ? win->Title : (UBYTE *)"NULL");
80 ShowLayer(WLAYER(win));
82 if (IS_GZZWINDOW(win))
84 ShowLayer(BLAYER(win));
89 dprintf("----------------------------------------------------------------\n");
91 Permit();
93 #endif
95 AROS_LIBFUNC_EXIT
98 #if 1
100 void *CheckValidPtr(void *Ptr)
102 if (((ULONG) Ptr >= 0x20000000UL) &&
103 ((ULONG) Ptr < 0x30000000UL))
105 return(Ptr);
107 if (((ULONG) Ptr >= 0x7000000UL) &&
108 ((ULONG) Ptr < 0xb510000UL))
110 return(Ptr);
112 else if (((ULONG) Ptr >= ((ULONG) 0x11000000)) &&
113 ((ULONG) Ptr < ((ULONG) 0x14000000)))
115 return(Ptr);
117 else if (((ULONG) Ptr >= ((ULONG) 0x10100000)) &&
118 ((ULONG) Ptr < ((ULONG) 0x10400000)))
120 return(Ptr);
122 else if (((ULONG) Ptr >= ((ULONG) 0x10800000)) &&
123 ((ULONG) Ptr < ((ULONG) 0x10900000)))
125 return(Ptr);
127 else if (((ULONG) Ptr >= 0x1000) &&
128 ((ULONG) Ptr < 0x00200000))
130 return(Ptr);
132 else if (((ULONG) Ptr >= 0x00f80000) &&
133 ((ULONG) Ptr < 0x01000000))
135 return(Ptr);
137 else if ((ULONG) Ptr == (ULONG) 0x100000f0)
139 return(Ptr);
141 return(NULL);
144 #pragma pack(2)
145 struct SegTrackerSemaphore
147 struct SignalSemaphore Semaphore;
148 void (*Search)(void);
149 struct MinList List;
152 struct SegArray
154 ULONG Address;
155 ULONG Size;
158 struct SegTrackerNode
160 struct MinNode Node;
161 char *Name;
162 struct SegArray Array[1];
164 #pragma pack()
166 static struct SegTrackerSemaphore *MySegInfo;
168 #define DEBUG_SEGTRACKER(x) ;
170 #undef SysBase
172 char *FindAddress(ULONG Address,
173 ULONG *Hunk,
174 ULONG *Offset)
176 struct SegTrackerNode *MyNode;
177 char *Name=NULL;
178 ULONG Count;
180 DEBUG_SEGTRACKER(dprintf("FindAddress(Address 0x%lx Hunk 0x%lx Offset 0x%lx)\n",
181 Address,
182 Hunk,
183 Offset));
185 /* MySegInfo isn`t valid after a coldreboot
186 * therefore scan for it everytime
188 if (TRUE)//(MySegInfo==NULL)
190 struct ExecBase *SysBase = *(struct ExecBase **)4;
191 MySegInfo =(struct SegTrackerSemaphore*) FindSemaphore("SegTracker");
192 DEBUG_SEGTRACKER(dprintf("FindAddress: SegInfo 0x%lx\n",
193 MySegInfo));
195 if (MySegInfo)
197 if (CheckValidPtr(MySegInfo))
199 MyNode =(struct SegTrackerNode*) MySegInfo->List.mlh_Head;
200 DEBUG_SEGTRACKER(dprintf("FindAddress: 1st Node 0x%lx\n",
201 MyNode));
202 while ((CheckValidPtr(MyNode)) &&
203 (MyNode->Node.mln_Succ) &&
204 (!Name))
206 Count = 0;
207 DEBUG_SEGTRACKER(dprintf("FindAddress: Current Segment %s\n",
208 MyNode->Name));
210 while (MyNode->Array[Count].Address)
212 DEBUG_SEGTRACKER(dprintf("FindAddress: Current Address 0x%lx Size 0x%lx\n",
213 MyNode->Array[Count].Address,
214 MyNode->Array[Count].Size));
216 if ((Address > MyNode->Array[Count].Address) &&
217 (Address < (MyNode->Array[Count].Address + MyNode->Array[Count].Size)))
219 *Hunk = Count;
220 *Offset = Address - MyNode->Array[Count].Address - 4;
221 Name = MyNode->Name;
223 if (Hunk==Offset)
225 *Hunk = MyNode->Array[0].Address;
227 DEBUG_SEGTRACKER(dprintf("FindAddress: Found %s\n",
228 Name));
230 Count++;
232 MyNode =(struct SegTrackerNode*) MyNode->Node.mln_Succ;
236 return(Name);
239 void ShowStack(ULONG Address,
240 ULONG Size)
242 ULONG Ptr;
243 char *MyName;
244 ULONG Hunk;
245 ULONG Offset;
247 if (CheckValidPtr((ULONG*) Address))
249 Ptr = Address;
250 while (Ptr < (Address+Size))
252 if ((MyName=FindAddress(*((ULONG*) Ptr),
253 &Hunk,
254 &Offset)))
256 dprintf("\t\t0x%lx -> %s Hunk %ld Offset 0x%08lx\n",
257 *((ULONG*) Ptr),
258 MyName,
259 Hunk,
260 Offset);
261 Ptr += 4;
263 else
265 Ptr += 2;
271 #define MAXLEVEL 10
272 #define DEBUG_SHOWHISTORY(x) ;
274 void ShowPPCStackHistory(ULONG *Stack,
275 ULONG *StackEnd)
277 char *MyName;
278 ULONG Hunk;
279 ULONG Offset;
280 ULONG *CurrentStack;
281 ULONG *StackPtr;
282 int i;
285 i = 0;
286 CurrentStack = Stack;
288 DEBUG_SHOWHISTORY(dprintf("ShowPPCStackHistory: Stack 0x%lx StackEnd 0x%lx\n",
289 Stack,
290 StackEnd));
292 while (CurrentStack < StackEnd)
294 StackPtr =(ULONG*) CurrentStack[0]; /* Get previous stackframe */
295 DEBUG_SHOWHISTORY(dprintf("ShowPPCStackHistory: StackPtr 0x%lx\n",
296 StackPtr));
297 if ((StackPtr >= Stack) &&
298 (StackPtr < StackEnd))
300 if (CheckValidPtr((ULONG*) StackPtr[1]))
302 /* Legal LR */
304 if ((MyName=FindAddress(StackPtr[1],
305 &Hunk,
306 &Offset)))
308 dprintf("\t\tStackFrame[%ld].LR-> Address 0x%08lx -> %s Hunk %ld Offset 0x%08lx\n",
309 (LONG) i,
310 StackPtr[1],
311 MyName,
312 Hunk,
313 Offset);
315 else
317 dprintf("\t\tStackFrame[%ld].LR-> Address 0x%08lx\n",
318 (LONG) i,
319 StackPtr[1]);
321 #if 0
322 PPCDissasemble((APTR) StackPtr[1],
324 PPCLibBase);
325 #endif
327 else
329 dprintf("\t\tStackFrame[%ld].LR-> Address 0x%08lx **Not Valid**\n\n",
330 (LONG) i,
331 StackPtr[1]);
333 i--;
334 CurrentStack = StackPtr;
335 if (i < -MAXLEVEL)
337 DEBUG_SHOWHISTORY(dprintf("ShowPPCStackHistory: MaxLevel end\n"));
338 break;
341 else
343 DEBUG_SHOWHISTORY(dprintf("ShowPPCStackHistory: address outside\n"));
344 break;
350 /* hack-o-rama */
351 #if 0
352 typedef unsigned int u_int32_t;
353 typedef double float64_t;
354 struct __QVector
356 u_int32_t A;
357 u_int32_t B;
358 u_int32_t C;
359 u_int32_t D;
362 typedef struct __QVector vector128_t;
363 #endif
365 #if 1
367 * Yeah yeah, this is ugly.. who cares..
369 typedef unsigned int u_int32_t;
370 typedef double float64_t;
371 struct __QVector
373 u_int32_t A;
374 u_int32_t B;
375 u_int32_t C;
376 u_int32_t D;
378 typedef struct __QVector vector128_t;
381 struct PPCRegFrame
383 u_int32_t StackGap[4]; /* StackFrame Gap..so a function working
384 * with the PPCRegFrame as the GPR1 doesn`t
385 * overwrite any contents with a LR store at 4(1)
388 u_int32_t Version; /* Version of the structure */
389 u_int32_t Type; /* Type of the regframe */
390 u_int32_t Flags; /* The filled up registers */
391 u_int32_t State; /* State of the Thread(only used for Get) */
393 u_int32_t SRR0;
394 u_int32_t SRR1;
395 u_int32_t LR;
396 u_int32_t CTR;
398 u_int32_t CR;
399 u_int32_t XER;
401 u_int32_t GPR[32];
403 float64_t FPR[32];
404 float64_t FPSCR;
406 u_int32_t VSAVE;
407 u_int32_t AlignPad0;
408 u_int32_t AlignPad1;
409 u_int32_t AlignPad2;
410 vector128_t VSCR;
411 vector128_t VMX[32];
412 /* no size
415 #endif
417 void ShowTaskState(struct Task *task)
419 struct PPCRegFrame *frame = task->tc_ETask->PPCRegFrame;
420 struct EmulHandle *emul = (APTR)frame->GPR[2];
421 char *MyName;
422 ULONG Offset, Hunk;
424 dprintf("\t\tSRR0 0x%lx LR 0x%lx CTR 0x%lx PC 0x%lx\n",
425 (ULONG) frame->SRR0, (ULONG) frame->LR, (ULONG) frame->CTR,
426 emul->Flags & EMULFLAGSF_PPC ? (ULONG) emul->PC : (ULONG) frame->GPR[13]);
428 if (emul->Flags & EMULFLAGSF_PPC)
430 if ((MyName=FindAddress((ULONG) frame->SRR0,
431 &Hunk,
432 &Offset)))
434 dprintf("\t\tSRR0 -> %s Hunk %ld Offset 0x%08lx\n",
435 MyName,
436 Hunk,
437 Offset);
440 if ((MyName=FindAddress((ULONG) frame->LR,
441 &Hunk,
442 &Offset)))
444 dprintf("\t\t LR -> %s Hunk %ld Offset 0x%08lx\n",
445 MyName,
446 Hunk,
447 Offset);
450 if ((MyName=FindAddress((ULONG) frame->CTR,
451 &Hunk,
452 &Offset)))
454 dprintf("\t\t CTR -> %s Hunk %ld Offset 0x%08lx\n",
455 MyName,
456 Hunk,
457 Offset);
461 ShowPPCStackHistory((ULONG*) frame->GPR[1],
462 (ULONG*) (frame->GPR[1] + 1000));
464 if ((MyName=FindAddress((ULONG) emul->PC,
465 &Hunk,
466 &Offset)))
468 dprintf("\t\tPC -> %s Hunk %ld Offset 0x%08lx\n",
469 MyName,
470 Hunk,
471 Offset);
473 ShowStack(emul->An[7],
474 0x80);
476 else
478 if ((MyName=FindAddress((ULONG) frame->GPR[13],
479 &Hunk,
480 &Offset)))
482 dprintf("\t\tPC -> %s Hunk %ld Offset 0x%08lx\n",
483 MyName,
484 Hunk,
485 Offset);
487 ShowStack(frame->GPR[31],
488 0x80);
492 void ShowSemaphore(const char *name, struct SignalSemaphore *sem)
494 struct SemaphoreRequest *req;
496 if (name)
497 dprintf("Semaphore %s:\n", name);
499 dprintf("Semaphore 0x%lx NestCount %d QueueCount %d Owner 0x%lx <%s>\n",
500 (ULONG) sem, sem->ss_NestCount, sem->ss_QueueCount,
501 (ULONG) sem->ss_Owner, sem->ss_Owner && sem->ss_Owner->tc_Node.ln_Name ?
502 sem->ss_Owner->tc_Node.ln_Name : "NULL");
503 if (sem->ss_Owner)
504 ShowTaskState(sem->ss_Owner);
506 ForeachNode(&sem->ss_WaitQueue, req)
508 dprintf("\tTask 0x%lx <%s>\n", (ULONG) req->sr_Waiter,
509 req->sr_Waiter->tc_Node.ln_Name ? req->sr_Waiter->tc_Node.ln_Name : "NULL");
510 ShowTaskState(req->sr_Waiter);
514 void ShowLayer(struct Layer *layer)
516 if (layer)
518 dprintf("Layer 0x%lx\n", (ULONG) layer);
519 ShowSemaphore(NULL, &layer->Lock);
523 #endif