Fix IO memory access .. SB128 driver makes noises in VMWare - CMI is untested (Curren...
[AROS.git] / _gdbinit
blob87138c83558ced4e25b3be0ccb37bed45c709491
1 handle SIGUSR1 pass noprint nostop
2 handle SIGUSR2 pass noprint nostop
3 set follow-fork-mode child
5 define liblist
6     set $lib = ((struct ExecBase *)SysBase)->LibList.lh_Head
8     printf "Base     OpenC   Name\n"
9     printf "---------------------------------------------------------------\n"
10     while ($lib->ln_Succ != 0)
11         printf "%p %5d   %s\n", \
12             $lib, \
13             ((struct Library *)$lib)->lib_OpenCnt, \
14             $lib->ln_Name
15         set $lib = $lib->ln_Succ
16     end
17 end
18 document liblist
19 List the current libraries in the system
20 end
22 define devlist
23     set $dev = ((struct ExecBase *)SysBase)->DeviceList.lh_Head
24     printf "Base     OpenC   Name\n"
25     printf "---------------------------------------------------------------\n"
26     while ($dev->ln_Succ != 0)
27         printf "%p %5d   %s\n", \
28             $dev, \
29             ((struct Library *)$dev)->lib_OpenCnt, \
30             $dev->ln_Name
31         set $dev = $dev->ln_Succ
32     end
33 end
34 document devlist
35 List the current devices in the system
36 end
38 define resourcelist
39     set $res = ((struct ExecBase *)SysBase)->ResourceList.lh_Head
40     printf "Base     Name\n"
41     printf "---------------------------------------------------------------\n"
42     while ($res->ln_Succ != 0)
43         printf "%p %s\n", $res, $res->ln_Name
44         set $res = $res->ln_Succ
45     end
46 end
47 document resourcelist
48 List the current resources in the system
49 end
51 define residentlist
52     set $resp = (struct Resident **)((struct ExecBase *)SysBase)->ResModules
53     set $i = 0
55     printf "Address    Pri Flags Vers Type  Name\n"
56     printf "--------------------------------------------------------------\n"
57     while (($resp)[$i] != 0)
58         set $res = ($resp)[$i]
59         printf "%p  %4d    %02x  %3d  %3d  %s\n", \
60             $res, \
61             ((struct Resident *)$res)->rt_Pri, \
62             ((struct Resident *)$res)->rt_Flags, \
63             ((struct Resident *)$res)->rt_Version, \
64             ((struct Resident *)$res)->rt_Type, \
65             ((struct Resident *)$res)->rt_Name
66         set $i = $i + 1
67     end
68 end
69 document residentlist
70 List the system resident list
71 end
73 define taskready
74     set $task = (struct Task *)((struct ExecBase *)SysBase)->TaskReady.lh_Head
76     printf "Task     SigWait  SigRecvd StkSize   StkUsed Pri Type Name\n"
77     printf "-----------------------------------------------------------------------------\n"
78     while ($task->tc_Node.ln_Succ != 0)
79         printf "%p %p %p %8d %8d %3d  %3ld %s\n", \
80             $task, \
81             $task->tc_SigWait, \
82             $task->tc_SigRecvd, \
83             $task->tc_SPUpper - $task->tc_SPLower, \
84             $task->tc_SPUpper - $task->tc_SPReg, \
85             $task->tc_Node.ln_Pri, \
86             $task->tc_Node.ln_Type, \
87             $task->tc_Node.ln_Name
88         set $task = (struct Task *)$task->tc_Node.ln_Succ
89     end
90 end
91 document taskready
92 List of tasks currently ready to run
93 end
95 define taskwait
96     set $task = (struct Task *)((struct ExecBase *)SysBase)->TaskWait.lh_Head
98     printf "Task     SigWait  SigRecvd StkSize   StkUsed Pri Type Name\n"
99     printf "-----------------------------------------------------------------------------\n"
100     while ($task->tc_Node.ln_Succ != 0)
101         printf "%p %p %p %8d %8d %3d  %3ld %s\n", \
102             $task, \
103             $task->tc_SigWait, \
104             $task->tc_SigRecvd, \
105             $task->tc_SPUpper - $task->tc_SPLower, \
106             $task->tc_SPUpper - $task->tc_SPReg, \
107             $task->tc_Node.ln_Pri, \
108             $task->tc_Node.ln_Type, \
109             $task->tc_Node.ln_Name
110         set $task = (struct Task *)$task->tc_Node.ln_Succ
111     end
113 document taskwait
114 List of tasks currently waiting for an event
117 define thistask
118     set $task = (struct Task *)((struct ExecBase *)SysBase)->ThisTask
119     printf "Task     SigWait  SigRecvd StkSize   StkUsed Pri Type Name\n"
120     printf "-----------------------------------------------------------------------------\n"
121     printf "%p %p %p %8d %8d %3d  %3ld %s\n", \
122         $task, \
123         $task->tc_SigWait, \
124         $task->tc_SigRecvd, \
125         $task->tc_SPUpper - $task->tc_SPLower, \
126         $task->tc_SPUpper - $task->tc_SPReg, \
127         $task->tc_Node.ln_Pri, \
128         $task->tc_Node.ln_Type, \
129         $task->tc_Node.ln_Name
131 document thistask
132 Print out information about the currently running task.
135 define modlist
136     printf "Segment           Module\n"
138     if Debug_ModList
139         printf "---------------------------------------------------------------------\n"
140         set $segnode = (struct segment *)Debug_ModList->mlh_Head
142         while ($segnode->s_node.mln_Succ != 0)
143             printf "%p %12s %2u %32s\n", $segnode->s_lowest, $segnode->s_name, $segnode->s_num, $segnode->s_mod->m_name
145             set $segnode = (struct segment *)$segnode->s_node.mln_Succ
146         end
147     end
149     printf "---------------------------------------------------------------------\n"
150     set $kicknode = Debug_KickList
152     while ($kicknode != 0)
153         set $eh = $kicknode->eh
154         set $sh = $kicknode->sh
155         set $shnum = $eh->shnum
157         set $i = 0
158         while ($i < $shnum)
159             if ($sh->addr != 0) && ($sh->size != 0)
160                 printf "%p              %2u %32s\n", $sh->addr, $i, $kicknode->Name
161             end
162             set $sh = $sh + 1
163             set $i = $i + 1
164         end
165         set $kicknode = $kicknode->Next
166     end
168 document modlist
169 List of all the modules currently loaded in memory
172 define findaddr
173     set $cont = 1
175     #first search in modules loaded from disk
176     printf "Searching in the loaded modules...\n"
177     if Debug_ModList
178         set $segnode = (struct segment *)Debug_ModList->mlh_Head
180         while ($segnode->s_node.mln_Succ != 0) && $cont
181             if $arg0 >= $segnode->s_lowest && $arg0 <= $segnode->s_highest
182                 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
184                 set $cont = 0
185             end
186             set $segnode = (struct segment *)$segnode->s_node.mln_Succ
187         end
188     end
190     if $cont
191         printf "Searching in the kickstart list...\n"
192         set $kicknode = Debug_KickList
194         while ($kicknode != 0) && $cont
195             set $eh = $kicknode->eh
196             set $sh = $kicknode->sh
197             set $shnum = $eh->shnum
199             set $i = 0
200             while ($i < $shnum) && $cont
201                 if ($sh->addr != 0) && ($sh->size != 0)
202                     set $lowest  = $sh->addr
203                     set $highest = $sh->addr + $sh->size - 1
205                     if $arg0 >= $lowest && $arg0 <= $highest
206                         printf "Address found in %s in section number %d starting at %p.\n", $kicknode->Name, $i, $lowest
207                         set $cont = 0
208                     end
209                 end
211                 set $sh = $sh + 1
212                 set $i = $i + 1
213             end
214             set $kicknode = $kicknode->Next
215         end
216     end
218     #then in the resident list
219     if $cont
220         printf "Searching in the resident list...\n"
221     end
223     set $resp = (struct Resident **)((struct ExecBase *)SysBase)->ResModules
224     set $i = 0
226     while (($resp)[$i] != 0) && $cont
227         set $res = ($resp)[$i]
229         if ($arg0 >= $res) && ($arg0 <= $res->rt_EndSkip)
230             printf "Address found in %s, which resides at %p\n", $res->rt_Name, $res
231             set $cont = 0
232         end
234         set $i = $i + 1
235     end
237     if $cont
238         printf "No matching module for this address\n"
239     end
241 document findaddr
242 -Shows the module that contains the given address
244 -To debug a problem in AROS, do the following:
246 -1. Get a stacktrace with bt or similar.
247 -2. Use findaddr with such an address to find out in which
248 -   module it is:
249 -3. Use add-symbol-file to load that modules symbols.
250 -4. Now you can run bt (or similar) again and you should see the
251 -   addresses resolved as symbols.
253 -Example:
255 -0x4058d45b in ?? ()
257 -(gdb) findaddr 0x4058d45b
259 -Searching in the loaded modules...
260 -Address found in Workbench:contrib/Zune/Libs/muimaster.library, which is loaded at 0x405379a4.
261 -If this is an executable, its .text section starts at 0x405379b0.
262 -(gdb) add-symbol-file contrib/Zune/Libs/muimaster.library 0x405379b0
263 -add symbol table from file "contrib/Zune/Libs/muimaster.library" at
264 -        .text_addr = 0x405379b0
265 -(y or n) y
266 -Reading symbols from contrib/Zune/Libs/muimaster.library...done.
267 -(gdb) bt
268 -#0  0x4058d45b in strlen (ptr=0x80 <Address 0x80 out of bounds>) at strlen.c:45
269 -#1  0x00000000 in lastx.78 ()
272 define printtaglist
273     set $list = (struct TagItem *)$arg0
275     printf "Tag         Data (Hex)     Data (Dec)\n"
276     printf "--------------------------------------\n"
278     while $list->ti_Tag != 0
279         # Handle the possible control tag...
280         if $list->ti_Tag == 1
281             printf "TAG_IGNORE\n"
282         else if $list->ti_Tag == 2
283             printf "TAG_MORE    %p\n", $list->ti_Data
284             set $list = (struct TagItem *)$list->ti_Data
285         else if $list->ti_Tag == 3
286             printf "TAG_SKIP    %d\n", $list->ti_Data
287             set $list = $list + $list->ti_Tag + 1
288         else
289             printf "%p  %p      %9lu\n", $list->ti_Tag, $list->ti_Data, $list->ti_Data
290             set $list = $list + 1
291         end
292     end
293     printf "TAG_DONE\n"
295 document printtaglist
298 define log_to_file
299   set logging file $arg0
300   set logging redirect on
301   set logging overwrite $arg1
302   set logging on
305 define end_log
306   set logging off
309 define loadseg
310   dont-repeat
311   if Debug_ModList
312   set $step = 1
313   set $segnode = (struct segment *)Debug_ModList->mlh_Head
314   while ($segnode->s_node.mln_Succ != 0) && $step == 1
315     if $arg0 >= $segnode->s_lowest && $arg0 <= $segnode->s_highest
316       log_to_file segname.tmp on
317       printf "%s", $segnode->s_mod->m_name
318       end_log
319       shell sed -i 's/.*:\(.*\)/\1/' segname.tmp
320       log_to_file loadseg.tmp on
321       printf "add-symbol-file "
322       end_log
323       shell head -n1 segname.tmp >>loadseg.tmp
324       log_to_file loadseg.tmp off
325       printf " %p", $segnode->s_lowest
326       if $segnode->s_node.mln_Succ != 0
327         set $segnode = (struct segment *)$segnode->s_node.mln_Succ
328         while ($segnode->s_node.mln_Succ != 0) && $step < 5
329           if strcmp($segnode->s_name, ".text") == 0
330             loop_break
331           end
332           printf " -s %s %p", $segnode->s_name, $segnode->s_lowest
333           set $step = $step + 1
334           set $segnode = (struct segment *)$segnode->s_node.mln_Succ
335         end
336       end
337       end_log
338       source loadseg.tmp
339       loop_break
340     end
341     set $segnode = (struct segment *)$segnode->s_node.mln_Succ
342   end
343   if $step < 2
344     set $kicknode = Debug_KickList
346     while ($kicknode != 0) && $step == 1
347         set $eh = $kicknode->eh
348         set $sh = $kicknode->sh
349         set $shnum = $eh->shnum
351         set $i = 0
352         while ($i < $shnum) && $cont
353             if ($sh->addr != 0) && ($sh->size != 0)
354                 set $lowest  = $sh->addr
355                 set $highest = $sh->addr + $sh->size - 1
357                 if $arg0 >= $lowest && $arg0 <= $highest
358                 
359                     set $shstrndx = $eh->shstrndx
360                     set $shstr = 0
362                     if ($shstrndx < 0xFF00)
363                         set $shstr = $shstrndx
364                     if ($shstrndx > 0xFFFF)
365                         set $shstr = $shstrndx - (0x10000 - 0xFF00)
367                     log_to_file segname.tmp on
368                     printf "%s", $kicknode->s_module.m_name
369                     end_log
370                     shell sed -i 's/.*:\(.*\)/\1/' segname.tmp
371                     log_to_file loadseg.tmp on
372                     printf "add-symbol-file "
373                     end_log
374                     shell head -n1 segname.tmp >>loadseg.tmp
375                     log_to_file loadseg.tmp off
376                     printf " %p", $s_lowest
378                     set $sh = $sh + 1
379                     set $i = $i + 1
380                     while ($i < $shnum)
381                         if ($sh->addr != 0) && ($sh->size != 0)
382                             set $segname = $kicknode->sh[$shstr] + $sh->name
383                             printf " -s %s %p", $segname, $sh->addr
384                         end
385                         set $step = $step + 1
386                     end
388                     end_log
389                     source loadseg.tmp
390                     loop_break
391                 end
392             end
394             set $sh = $sh + 1
395             set $i = $i + 1
396         end
397         set $kicknode = $kicknode->Next
398     end
399   end
400   if $step < 2
401     printf "no matching module for this address\n"
402   else
403     printf "no debug symbols found\n"
404   end
406 document loadseg
407 Loads the module that contains the given address
410 define seglistdump
411     set $nextseg = $arg0
412     set $count   = 1
414     printf "Hunk num. | Start addr | Size       \n"
415     printf "----------+------------+------------\n"
416     while $nextseg
417         printf "%9d | %p | %10d\n", $count, $nextseg + sizeof(BPTR), *((ULONG *)$nextseg - 1) - sizeof(BPTR)
419         set $nextseg = *(BPTR *)$nextseg
420         set $count = $count+1
421     end
423 document seglistdump
424 Shows the segments chain of the given seglist