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 = *(struct IntExecBase **)&SysBase
16 document _sysbase_init
17 Initialize $AbsExecBase convenience variables
22 init-if-undefined $_debug_DebugBase = 0
24 if $AbsExecBase != 0 && $_debug_DebugBase == 0
25 set $_debug_DebugBase = (struct DebugBase *)($AbsExecBase->DebugBase)
28 if $_debug_DebugBase != 0
29 set $_debug_DebugBase = (struct DebugBase *)($_debug_DebugBase)
30 # This is the case for debugging a ROM
31 set $_debug_ModList = &($_debug_DebugBase->db_Modules)
33 # This is the case for debugging a bootstrap
34 init-if-undefined $_debug_ModList = Debug_ModList
38 Initialize debugging convenience variables
43 set $lib = ((struct ExecBase *)$AbsExecBase)->LibList.lh_Head
45 printf "Base OpenC Name\n"
46 printf "---------------------------------------------------------------\n"
47 while ($lib->ln_Succ != 0)
48 printf "%p %5d %s\n", \
50 ((struct Library *)$lib)->lib_OpenCnt, \
52 set $lib = $lib->ln_Succ
56 List the current libraries in the system
61 set $dev = ((struct ExecBase *)$AbsExecBase)->DeviceList.lh_Head
62 printf "Base OpenC Name\n"
63 printf "---------------------------------------------------------------\n"
64 while ($dev->ln_Succ != 0)
65 printf "%p %5d %s\n", \
67 ((struct Library *)$dev)->lib_OpenCnt, \
69 set $dev = $dev->ln_Succ
73 List the current devices in the system
78 set $res = ((struct ExecBase *)$AbsExecBase)->ResourceList.lh_Head
80 printf "---------------------------------------------------------------\n"
81 while ($res->ln_Succ != 0)
82 printf "%p %s\n", $res, $res->ln_Name
83 set $res = $res->ln_Succ
87 List the current resources in the system
92 set $resp = (struct Resident **)((struct ExecBase *)$AbsExecBase)->ResModules
95 printf "Address Pri Flags Vers Type Name\n"
96 printf "--------------------------------------------------------------\n"
97 while (($resp)[$i] != 0)
98 set $res = ($resp)[$i]
99 printf "%p %4d %02x %3d %3d %s\n", \
101 ((struct Resident *)$res)->rt_Pri, \
102 ((struct Resident *)$res)->rt_Flags, \
103 ((struct Resident *)$res)->rt_Version, \
104 ((struct Resident *)$res)->rt_Type, \
105 ((struct Resident *)$res)->rt_Name
109 document residentlist
110 List the system resident list
115 set $task = (struct Task *)((struct ExecBase *)$AbsExecBase)->TaskReady.lh_Head
117 printf "Task SigWait SigRecvd StkSize StkUsed Pri Type Name\n"
118 printf "-----------------------------------------------------------------------------\n"
119 while ($task->tc_Node.ln_Succ != 0)
120 printf "%p %p %p %8d %8d %3d %3ld %s\n", \
123 $task->tc_SigRecvd, \
124 $task->tc_SPUpper - $task->tc_SPLower, \
125 $task->tc_SPUpper - $task->tc_SPReg, \
126 $task->tc_Node.ln_Pri, \
127 $task->tc_Node.ln_Type, \
128 $task->tc_Node.ln_Name
129 set $task = (struct Task *)$task->tc_Node.ln_Succ
133 List of tasks currently ready to run
138 set $task = (struct Task *)((struct ExecBase *)$AbsExecBase)->TaskWait.lh_Head
140 printf "Task SigWait SigRecvd StkSize StkUsed Pri Type Name\n"
141 printf "-----------------------------------------------------------------------------\n"
142 while ($task->tc_Node.ln_Succ != 0)
143 printf "%p %p %p %8d %8d %3d %3ld %s\n", \
146 $task->tc_SigRecvd, \
147 $task->tc_SPUpper - $task->tc_SPLower, \
148 $task->tc_SPUpper - $task->tc_SPReg, \
149 $task->tc_Node.ln_Pri, \
150 $task->tc_Node.ln_Type, \
151 $task->tc_Node.ln_Name
152 set $task = (struct Task *)$task->tc_Node.ln_Succ
156 List of tasks currently waiting for an event
161 set $task = (struct Task *)((struct ExecBase *)$AbsExecBase)->ThisTask
162 printf "Task SigWait SigRecvd StkSize StkUsed Pri Type Name\n"
163 printf "-----------------------------------------------------------------------------\n"
164 printf "%p %p %p %8d %8d %3d %3ld %s\n", \
167 $task->tc_SigRecvd, \
168 $task->tc_SPUpper - $task->tc_SPLower, \
169 $task->tc_SPUpper - $task->tc_SPReg, \
170 $task->tc_Node.ln_Pri, \
171 $task->tc_Node.ln_Type, \
172 $task->tc_Node.ln_Name
175 Print out information about the currently running task.
180 printf "Segment Module\n"
183 printf "---------------------------------------------------------------------\n"
184 set $modnode = (module_t *)$_debug_ModList->mlh_Head
186 while ($modnode->m_node.mln_Succ != 0)
188 while ($segidx < $modnode->m_segcnt)
189 set $segnode = $modnode->m_segments[$segidx]
190 printf "%p %12s %2u %42s\n", $segnode->s_lowest, $segnode->s_name, $segnode->s_num, $segnode->s_mod->m_name
191 set $segidx = $segidx + 1
194 set $modnode = (module_t *)$modnode->m_node.mln_Succ
199 List of all the modules currently loaded in memory
202 # Execute a binary search over sorter array of segments
203 # Keep this function synchronized with decodelocation.c, FindSegmentInModule
204 define find_segment_in_module
205 set $arg_address = $arg0
207 set $find_segment_in_module_result = 0
208 set $local_minsegidx = 0
209 set $local_maxsegidx = $arg_mod->m_segcnt - 1
213 set $local_segidx = ($local_maxsegidx + $local_minsegidx) / 2
215 if $arg_mod->m_segments[$local_segidx]->s_lowest <= $arg_address
216 if $arg_mod->m_segments[$local_segidx]->s_highest >= $arg_address
217 set $find_segment_in_module_result = $arg_mod->m_segments[$local_segidx]
220 set $local_minsegidx = $local_segidx + 1
223 set $local_maxsegidx = $local_segidx - 1
226 if $local_maxsegidx < $local_minsegidx
227 # Not found, aborting
233 # Keep this function synchronized with decodelocation.c, FindSegment
236 set $find_segment_result = 0
239 set $modnode = (module_t *)$_debug_ModList->mlh_Head
241 while ($modnode->m_node.mln_Succ != 0)
242 if !($modnode->m_gaplowest <= $arg0 && $modnode->m_gaphighest >= $arg0)
243 if $modnode->m_lowest <= $arg0 && $modnode->m_highest >= $arg0
245 find_segment_in_module $arg0 $modnode
247 if $find_segment_in_module_result
248 set $find_segment_result = $find_segment_in_module_result
253 set $modnode = (module_t *)$modnode->m_node.mln_Succ
262 #first search in modules loaded from disk
263 printf "Searching in the loaded modules...\n"
267 if $find_segment_result
268 set $segnode = $find_segment_result
269 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
273 #then in the resident list
275 printf "Searching in the resident list...\n"
278 set $resp = (struct Resident **)((struct ExecBase *)$AbsExecBase)->ResModules
281 while (($resp)[$i] != 0) && $cont
282 set $res = ($resp)[$i]
284 if ($arg0 >= $res) && ($arg0 <= $res->rt_EndSkip)
285 printf "Address found in %s, which resides at %p\n", $res->rt_Name, $res
293 printf "No matching module for this address\n"
297 -Shows the module that contains the given address
299 -To debug a problem in AROS, do the following:
301 -1. Get a stacktrace with bt or similar.
302 -2. Use findaddr with such an address to find out in which
304 -3. Use add-symbol-file to load that modules symbols.
305 -4. Now you can run bt (or similar) again and you should see the
306 - addresses resolved as symbols.
312 -(gdb) findaddr 0x4058d45b
314 -Searching in the loaded modules...
315 -Address found in Workbench:contrib/Zune/Libs/muimaster.library, which is loaded at 0x405379a4.
316 -If this is an executable, its .text section starts at 0x405379b0.
317 -(gdb) add-symbol-file contrib/Zune/Libs/muimaster.library 0x405379b0
318 -add symbol table from file "contrib/Zune/Libs/muimaster.library" at
319 - .text_addr = 0x405379b0
321 -Reading symbols from contrib/Zune/Libs/muimaster.library...done.
323 -#0 0x4058d45b in strlen (ptr=0x80 <Address 0x80 out of bounds>) at strlen.c:45
324 -#1 0x00000000 in lastx.78 ()
328 set $list = (struct TagItem *)$arg0
330 printf "Tag Data (Hex) Data (Dec)\n"
331 printf "--------------------------------------\n"
333 while $list->ti_Tag != 0
334 # Handle the possible control tag...
335 if $list->ti_Tag == 1
336 printf "TAG_IGNORE\n"
337 else if $list->ti_Tag == 2
338 printf "TAG_MORE %p\n", $list->ti_Data
339 set $list = (struct TagItem *)$list->ti_Data
340 else if $list->ti_Tag == 3
341 printf "TAG_SKIP %d\n", $list->ti_Data
342 set $list = $list + $list->ti_Tag + 1
344 printf "%p %p %9lu\n", $list->ti_Tag, $list->ti_Data, $list->ti_Data
345 set $list = $list + 1
350 document printtaglist
354 set logging file $arg0
355 set logging redirect on
356 set logging overwrite $arg1
366 set $this_mod = $arg0
368 log_to_file segname.tmp on
369 printf "%s", $this_mod->m_name
371 shell sed -i 's/.*:\(.*\)/\1/' segname.tmp
372 log_to_file loadseg.tmp on
373 printf "add-symbol-file \""
375 shell head -n1 segname.tmp >>loadseg.tmp
376 log_to_file loadseg.tmp off
377 printf "\" %s", $this_mod->m_seggdbhlp
392 if $find_segment_result
393 # This is workaround for some flushing problem when loadseg.tmp had module name before command
396 loadmod $find_segment_result->s_mod
402 printf "No matching module for this address\n"
408 Loads the module that contains the given address
415 set $loadmods_modnode = (module_t *)$_debug_ModList->mlh_Head
417 while ($loadmods_modnode->m_node.mln_Succ != 0)
418 loadmod $loadmods_modnode
419 set $loadmods_modnode = (module_t *)$loadmods_modnode->m_node.mln_Succ
424 Loads all the modules (symbols)
428 log_to_file frameinfo.tmp on
432 shell grep "eip =" frameinfo.tmp >loadseg.tmp
433 shell sed -e 's/eip = \(0x[0-9,a-f]*\).*/loadseg \1/' loadseg.tmp >frameinfo.tmp
438 Loads the symbols for the given stack frame number
447 printf "\nEnter stack frame number to resolve or RETURN to stop: \n\n"
451 shell read _gdb_answer && echo $_gdb_answer | grep -E "[0-9]+" | sed "s/\(.*\)/set \$_answer=\1/" >frameinfo.tmp
464 Interactive multiple loading of symbols for given stack frame numbers
468 set $_frame_counter = 0
472 printf "Checking frame #%d\n", $_frame_counter
476 log_to_file loadseg.tmp on
481 # Check if frame exists
483 log_to_file frameinfo.tmp on
484 printf "shell grep \"#%d .*\" loadseg.tmp | sed \"s/#.*/set \\$_again = 1/\" >loadbt.tmp\n", $_frame_counter
492 # If frame is unresolved ("in ??") transform to "loadseg address"
494 log_to_file frameinfo.tmp on
495 printf "shell grep \"#%d .* in ??\" loadseg.tmp | sed \"s/#.*\\(0x[0-9,a-f]*\\) .*/loadseg \\1/\" >loadbt.tmp\n", $_frame_counter
501 set $_frame_counter = $_frame_counter + 1
502 if ($_frame_counter == 1000)
511 Tries to automatically load the symbols for all unresolved stack frames
519 printf "Hunk num. | Start addr | Size \n"
520 printf "----------+------------+------------\n"
522 printf "%9d | %p | %10d\n", $count, $nextseg + sizeof(BPTR), *((ULONG *)$nextseg - 1) - sizeof(BPTR)
524 set $nextseg = *(BPTR *)$nextseg
525 set $count = $count+1
529 Shows the segments chain of the given seglist
533 set $task = (struct Task *)$arg0
534 if ($task->tc_Node.ln_Type != 1) && ($task->tc_Node.ln_Type != 13)
535 printf "ERROR: Given address does not look like a task or process!\n"
537 #FIXME: The following assumes Linux x86
541 if $task->tc_State == 2
542 printf "WARNING: TS_RUN Task. Showing normal backtrace!\n"
544 set $esp = $task->tc_SPReg
545 set $taskcontext = (struct AROSCPUContext *)$task->tc_UnionETask.tc_ETask.et_RegFrame
546 set $eip = $taskcontext.regs.eip
556 Shows the backtrace of the given TS_READY/TS_WAIT task
560 set $sem = (struct SignalSemaphore *)$arg0
561 if $sem->ss_Link.ln_Type != 15
562 printf "ERROR: Given address does not look like a semaphore!\n"
564 if $sem->ss_QueueCount == -1
565 printf "The semaphore is free\n"
567 if $sem->ss_Owner == 0
568 printf "The semaphore is locked in shared mode by one or more tasks\n"
570 printf "The semaphore is owned by task %p (%s)\n", $sem->ss_Owner, $sem->ss_Owner->tc_Node.ln_Name
573 printf "\nWait Queue:\n\n"
575 set $waitnode = (struct SemaphoreRequest *)$sem->ss_WaitQueue.mlh_Head
577 while ($waitnode->sr_Link.mln_Succ != 0)
578 set $waitertask = $waitnode->sr_Waiter
579 if (int)$waitertask & 1
580 set $waitertask = $waitertask & ~1
585 printf"%p %s\n", $waitertask, $waitertask->tc_Node.ln_Name
586 set $waitnode = (struct SemaphoreRequest *)$waitnode->sr_Link.mln_Succ
592 Shows the owner of the given Exec Semaphore and the Wait Queue