1 handle SIGUSR1 pass noprint nostop
2 handle SIGUSR2 pass noprint nostop
3 set follow-fork-mode child
5 # This is a bit tricky, because we have several cases,
6 # and gdb has no easy 'is this symbol defined' tests.
8 # Case 1: Hosted AROSBootstrap (ie linux-i386)
9 # Provides SysBase, Debug_ModList, and Debug_KickList
10 # Case 2: ROM (ie amiga-m68k)
11 # Provides AbsExecBase and SysBase
14 init-if-undefined $AbsExecBase = 0
15 init-if-undefined $_debug_DebugBase = 0
17 # This is the case for ROM debugging - the user must
18 # 'set $AbsExecBase = 4', then this kicks in.
19 if $AbsExecBase != 0 && $_debug_DebugBase == 0
20 set $AbsExecBase = (struct IntExecBase *)$AbsExecBase
21 set $_debug_DebugBase = (struct DebugBase *)($AbsExecBase->DebugBase)
24 if $_debug_DebugBase != 0
25 # This is the case for debugging a ROM
26 set $_debug_ModList = &($_debug_DebugBase->db_Modules)
27 set $_debug_KickList = $_debug_DebugBase->db_KernelModules
29 # This is the case for debugging a bootstrap
30 init-if-undefined $_debug_ModList = Debug_ModList
31 init-if-undefined $_debug_KickList = Debug_KickList
35 Initialize debugging convenience variables
40 set $lib = ((struct ExecBase *)$AbsExecBase)->LibList.lh_Head
42 printf "Base OpenC Name\n"
43 printf "---------------------------------------------------------------\n"
44 while ($lib->ln_Succ != 0)
45 printf "%p %5d %s\n", \
47 ((struct Library *)$lib)->lib_OpenCnt, \
49 set $lib = $lib->ln_Succ
53 List the current libraries in the system
58 set $dev = ((struct ExecBase *)$AbsExecBase)->DeviceList.lh_Head
59 printf "Base OpenC Name\n"
60 printf "---------------------------------------------------------------\n"
61 while ($dev->ln_Succ != 0)
62 printf "%p %5d %s\n", \
64 ((struct Library *)$dev)->lib_OpenCnt, \
66 set $dev = $dev->ln_Succ
70 List the current devices in the system
75 set $res = ((struct ExecBase *)$AbsExecBase)->ResourceList.lh_Head
77 printf "---------------------------------------------------------------\n"
78 while ($res->ln_Succ != 0)
79 printf "%p %s\n", $res, $res->ln_Name
80 set $res = $res->ln_Succ
84 List the current resources in the system
89 set $resp = (struct Resident **)((struct ExecBase *)$AbsExecBase)->ResModules
92 printf "Address Pri Flags Vers Type Name\n"
93 printf "--------------------------------------------------------------\n"
94 while (($resp)[$i] != 0)
95 set $res = ($resp)[$i]
96 printf "%p %4d %02x %3d %3d %s\n", \
98 ((struct Resident *)$res)->rt_Pri, \
99 ((struct Resident *)$res)->rt_Flags, \
100 ((struct Resident *)$res)->rt_Version, \
101 ((struct Resident *)$res)->rt_Type, \
102 ((struct Resident *)$res)->rt_Name
106 document residentlist
107 List the system resident list
112 set $task = (struct Task *)((struct ExecBase *)$AbsExecBase)->TaskReady.lh_Head
114 printf "Task SigWait SigRecvd StkSize StkUsed Pri Type Name\n"
115 printf "-----------------------------------------------------------------------------\n"
116 while ($task->tc_Node.ln_Succ != 0)
117 printf "%p %p %p %8d %8d %3d %3ld %s\n", \
120 $task->tc_SigRecvd, \
121 $task->tc_SPUpper - $task->tc_SPLower, \
122 $task->tc_SPUpper - $task->tc_SPReg, \
123 $task->tc_Node.ln_Pri, \
124 $task->tc_Node.ln_Type, \
125 $task->tc_Node.ln_Name
126 set $task = (struct Task *)$task->tc_Node.ln_Succ
130 List of tasks currently ready to run
135 set $task = (struct Task *)((struct ExecBase *)$AbsExecBase)->TaskWait.lh_Head
137 printf "Task SigWait SigRecvd StkSize StkUsed Pri Type Name\n"
138 printf "-----------------------------------------------------------------------------\n"
139 while ($task->tc_Node.ln_Succ != 0)
140 printf "%p %p %p %8d %8d %3d %3ld %s\n", \
143 $task->tc_SigRecvd, \
144 $task->tc_SPUpper - $task->tc_SPLower, \
145 $task->tc_SPUpper - $task->tc_SPReg, \
146 $task->tc_Node.ln_Pri, \
147 $task->tc_Node.ln_Type, \
148 $task->tc_Node.ln_Name
149 set $task = (struct Task *)$task->tc_Node.ln_Succ
153 List of tasks currently waiting for an event
158 set $task = (struct Task *)((struct ExecBase *)$AbsExecBase)->ThisTask
159 printf "Task SigWait SigRecvd StkSize StkUsed Pri Type Name\n"
160 printf "-----------------------------------------------------------------------------\n"
161 printf "%p %p %p %8d %8d %3d %3ld %s\n", \
164 $task->tc_SigRecvd, \
165 $task->tc_SPUpper - $task->tc_SPLower, \
166 $task->tc_SPUpper - $task->tc_SPReg, \
167 $task->tc_Node.ln_Pri, \
168 $task->tc_Node.ln_Type, \
169 $task->tc_Node.ln_Name
172 Print out information about the currently running task.
177 printf "Segment Module\n"
180 printf "---------------------------------------------------------------------\n"
181 set $segnode = (struct segment *)$_debug_ModList->mlh_Head
183 while ($segnode->s_node.mln_Succ != 0)
184 printf "%p %12s %2u %32s\n", $segnode->s_lowest, $segnode->s_name, $segnode->s_num, $segnode->s_mod->m_name
186 set $segnode = (struct segment *)$segnode->s_node.mln_Succ
190 printf "---------------------------------------------------------------------\n"
191 set $kicknode = $_debug_KickList
193 while ($kicknode != 0)
194 set $eh = $kicknode->eh
195 set $sh = $kicknode->sh
196 set $shnum = $eh->shnum
200 if ($sh->addr != 0) && ($sh->size != 0)
201 printf "%p %2u %32s\n", $sh->addr, $i, $kicknode->Name
206 set $kicknode = $kicknode->Next
210 List of all the modules currently loaded in memory
217 #first search in modules loaded from disk
218 printf "Searching in the loaded modules...\n"
220 set $segnode = (struct segment *)$_debug_ModList->mlh_Head
222 while ($segnode->s_node.mln_Succ != 0) && $cont
223 if $arg0 >= $segnode->s_lowest && $arg0 <= $segnode->s_highest
224 printf "Address found in %s, in segment %p.\nIf this is an executable, its .text section starts at %p.\n", $segnode->s_mod->m_name, $segnode->s_seg, $segnode->s_lowest
228 set $segnode = (struct segment *)$segnode->s_node.mln_Succ
233 printf "Searching in the kickstart list...\n"
234 set $kicknode = $_debug_KickList
236 while ($kicknode != 0) && $cont
237 set $eh = $kicknode->eh
238 set $sh = $kicknode->sh
239 set $shnum = $eh->shnum
242 while ($i < $shnum) && $cont
243 if ($sh->addr != 0) && ($sh->size != 0)
244 set $lowest = $sh->addr
245 set $highest = $sh->addr + $sh->size - 1
247 if $arg0 >= $lowest && $arg0 <= $highest
248 printf "Address found in %s in section number %d starting at %p.\n", $kicknode->Name, $i, $lowest
256 set $kicknode = $kicknode->Next
260 #then in the resident list
262 printf "Searching in the resident list...\n"
265 set $resp = (struct Resident **)((struct ExecBase *)$AbsExecBase)->ResModules
268 while (($resp)[$i] != 0) && $cont
269 set $res = ($resp)[$i]
271 if ($arg0 >= $res) && ($arg0 <= $res->rt_EndSkip)
272 printf "Address found in %s, which resides at %p\n", $res->rt_Name, $res
280 printf "No matching module for this address\n"
284 -Shows the module that contains the given address
286 -To debug a problem in AROS, do the following:
288 -1. Get a stacktrace with bt or similar.
289 -2. Use findaddr with such an address to find out in which
291 -3. Use add-symbol-file to load that modules symbols.
292 -4. Now you can run bt (or similar) again and you should see the
293 - addresses resolved as symbols.
299 -(gdb) findaddr 0x4058d45b
301 -Searching in the loaded modules...
302 -Address found in Workbench:contrib/Zune/Libs/muimaster.library, which is loaded at 0x405379a4.
303 -If this is an executable, its .text section starts at 0x405379b0.
304 -(gdb) add-symbol-file contrib/Zune/Libs/muimaster.library 0x405379b0
305 -add symbol table from file "contrib/Zune/Libs/muimaster.library" at
306 - .text_addr = 0x405379b0
308 -Reading symbols from contrib/Zune/Libs/muimaster.library...done.
310 -#0 0x4058d45b in strlen (ptr=0x80 <Address 0x80 out of bounds>) at strlen.c:45
311 -#1 0x00000000 in lastx.78 ()
315 set $list = (struct TagItem *)$arg0
317 printf "Tag Data (Hex) Data (Dec)\n"
318 printf "--------------------------------------\n"
320 while $list->ti_Tag != 0
321 # Handle the possible control tag...
322 if $list->ti_Tag == 1
323 printf "TAG_IGNORE\n"
324 else if $list->ti_Tag == 2
325 printf "TAG_MORE %p\n", $list->ti_Data
326 set $list = (struct TagItem *)$list->ti_Data
327 else if $list->ti_Tag == 3
328 printf "TAG_SKIP %d\n", $list->ti_Data
329 set $list = $list + $list->ti_Tag + 1
331 printf "%p %p %9lu\n", $list->ti_Tag, $list->ti_Data, $list->ti_Data
332 set $list = $list + 1
337 document printtaglist
341 set logging file $arg0
342 set logging redirect on
343 set logging overwrite $arg1
356 set $segnode = (struct segment *)$_debug_ModList->mlh_Head
357 while ($segnode->s_node.mln_Succ != 0) && $step == 1
358 if $arg0 >= $segnode->s_lowest && $arg0 <= $segnode->s_highest
359 log_to_file segname.tmp on
360 printf "%s", $segnode->s_mod->m_name
362 shell sed -i 's/.*:\(.*\)/\1/' segname.tmp
363 log_to_file loadseg.tmp on
364 printf "add-symbol-file "
366 shell head -n1 segname.tmp >>loadseg.tmp
367 log_to_file loadseg.tmp off
368 printf " %p", $segnode->s_lowest
369 if $segnode->s_node.mln_Succ != 0
370 set $segnode = (struct segment *)$segnode->s_node.mln_Succ
371 while ($segnode->s_node.mln_Succ != 0) && $step < 5
372 if strcmp($segnode->s_name, ".text") == 0
375 printf " -s %s %p", $segnode->s_name, $segnode->s_lowest
376 set $step = $step + 1
377 set $segnode = (struct segment *)$segnode->s_node.mln_Succ
384 set $segnode = (struct segment *)$segnode->s_node.mln_Succ
389 set $kicknode = $_debug_KickList
391 while ($kicknode != 0) && $step == 1
392 set $eh = $kicknode->eh
393 set $sh = $kicknode->sh
394 set $shnum = $eh->shnum
398 if ($sh->addr != 0) && ($sh->size != 0)
399 set $lowest = $sh->addr
400 set $highest = $sh->addr + $sh->size - 1
402 if $arg0 >= $lowest && $arg0 <= $highest
403 set $shstrndx = $eh->shstrndx
406 if ($shstrndx < 0xFF00)
407 set $shstr = $shstrndx
409 if ($shstrndx > 0xFFFF)
410 set $shstr = $shstrndx - (0x10000 - 0xFF00)
413 log_to_file segname.tmp on
414 printf "%s", $kicknode->Name
416 shell sed -i 's/.*:\(.*\)/\1/' segname.tmp
417 log_to_file loadseg.tmp on
418 printf "add-symbol-file "
420 shell head -n1 segname.tmp >>loadseg.tmp
421 log_to_file loadseg.tmp off
422 printf " %p", $lowest
428 if ($sh->addr != 0) && ($sh->size != 0)
429 # This code does not work, cause error. I have no knowledge on how to make it work.
430 # set $segname = $kicknode->sh[$shstr] + $sh->name
431 # printf " -s %s %p", $segname, $sh->addr
433 set $step = $step + 1
447 set $kicknode = $kicknode->Next
452 printf "No matching module for this address\n"
459 Loads the module that contains the given address
464 set $_kicknode = $_debug_KickList
466 while ($_kicknode != 0)
467 set $_eh = $_kicknode->eh
468 set $_sh = $_kicknode->sh
469 set $_shnum = $_eh->shnum
472 while ($_i < $_shnum)
473 if ($_i == 1) && ($_sh->addr != 0) && ($_sh->size != 0)
479 set $_kicknode = $_kicknode->Next
483 Loads the Kickstart (symbols)
490 set $_segnode = (struct segment *)$_debug_ModList->mlh_Head
492 while ($_segnode->s_node.mln_Succ != 0)
493 if $_segnode->s_num == 1
494 loadseg $_segnode->s_lowest
496 set $_segnode = (struct segment *)$_segnode->s_node.mln_Succ
501 Loads all the modules (symbols)
509 Loads the symbols of the Kickstart and all modules
513 log_to_file frameinfo.tmp on
517 shell grep "eip =" frameinfo.tmp >loadseg.tmp
518 shell sed -e 's/eip = \(0x[0-9,a-f]*\).*/loadseg \1/' loadseg.tmp >frameinfo.tmp
523 Loads the symbols for the given stack frame number
532 printf "\nEnter stack frame number to resolve or RETURN to stop: \n\n"
536 shell read _gdb_answer && echo $_gdb_answer | grep -E "[0-9]+" | sed "s/\(.*\)/set \$_answer=\1/" >frameinfo.tmp
549 Interactive multiple loading of symbols for given stack frame numbers
553 set $_frame_counter = 0
557 printf "Checking frame #%d\n", $_frame_counter
561 log_to_file loadseg.tmp on
565 # Check if frame exists
567 log_to_file frameinfo.tmp on
568 printf "shell grep \"#%d .*\" loadseg.tmp | sed \"s/#.*/set \\$_again = 1/\" >loadbt.tmp\n", $_frame_counter
576 # If frame is unresolved ("in ??") transform to "loadseg address"
578 log_to_file frameinfo.tmp on
579 printf "shell grep \"#%d .* in ??\" loadseg.tmp | sed \"s/#.*\\(0x[0-9,a-f]*\\) .*/loadseg \\1/\" >loadbt.tmp\n", $_frame_counter
585 set $_frame_counter = $_frame_counter + 1
586 if ($_frame_counter == 1000)
593 Tries to automatically load the symbols for all unresolved stack frames
601 printf "Hunk num. | Start addr | Size \n"
602 printf "----------+------------+------------\n"
604 printf "%9d | %p | %10d\n", $count, $nextseg + sizeof(BPTR), *((ULONG *)$nextseg - 1) - sizeof(BPTR)
606 set $nextseg = *(BPTR *)$nextseg
607 set $count = $count+1
611 Shows the segments chain of the given seglist
615 set $task = (struct Task *)$arg0
616 if ($task->tc_Node.ln_Type != 1) && ($task->tc_Node.ln_Type != 13)
617 printf "ERROR: Given address does not look like a task or process!\n"
619 #FIXME: The following assumes Linux x86
623 if $task->tc_State == 2
624 printf "WARNING: TS_RUN Task. Showing normal backtrace!\n"
626 set $esp = $task->tc_SPReg
627 set $taskcontext = (struct AROSCPUContext *)$task->tc_UnionETask.tc_ETask.et_RegFrame
628 set $eip = $taskcontext.regs.eip
638 Shows the backtrace of the given TS_READY/TS_WAIT task
642 set $sem = (struct SignalSemaphore *)$arg0
643 if $sem->ss_Link.ln_Type != 15
644 printf "ERROR: Given address does not look like a semaphore!\n"
646 if $sem->ss_QueueCount == -1
647 printf "The semaphore is free\n"
649 if $sem->ss_Owner == 0
650 printf "The semaphore is locked in shared mode by one or more tasks\n"
652 printf "The semaphore is owned by task %p (%s)\n", $sem->ss_Owner, $sem->ss_Owner->tc_Node.ln_Name
655 printf "\nWait Queue:\n\n"
657 set $waitnode = (struct SemaphoreRequest *)$sem->ss_WaitQueue.mlh_Head
659 while ($waitnode->sr_Link.mln_Succ != 0)
660 set $waitertask = $waitnode->sr_Waiter
661 if (int)$waitertask & 1
662 set $waitertask = $waitertask & ~1
667 printf"%p %s\n", $waitertask, $waitertask->tc_Node.ln_Name
668 set $waitnode = (struct SemaphoreRequest *)$waitnode->sr_Link.mln_Succ
674 Shows the owner of the given Exec Semaphore and the Wait Queue