OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / tools / misc / gdb.txt
1
2 Debugging with gdb
3 ------------------
4
5
6 Gdb is a great way to debug uClinux/ColdFire. Here is some simple gdb
7 usage instructions from Chris Johns <ccj@acm.org>.
8
9
10 -----------------------------------------------------------------------------
11
12 The driver currently uses the P&E BDM interface. For the driver and gdb
13 patch you can get the archive from:
14
15  
16 ftp://skatter.usask.ca/pub/eric/BDM-Linux-gdb/gdb-4.17-bdm-990115.tar.gz
17   http://www.calm.hw.ac.uk/davidf/coldfire/gdb-4.17-bdm-990115.tar.gz
18
19 Unpack with a command like :
20
21   $ cd somewhere; tar zxf gdb-4.17-bdm-990115.tar.gz
22
23 Then look at the README file contained in the archive. This has the
24 detailed steps you need to follow. Comments and corrects are welcome.
25
26 Compile the driver, and library module and install. You will need to run
27 the MAKEDEV script in the `local_scripts' directory as root to create
28 the device nodes in the /dev directory.
29
30 Compile the test program and run it. The command line argument in the
31 release is not quite correct. Try :
32
33   ./chk /dev/bdmcf0
34
35 If your BDM module is not connected to parallel port 0 you need to use a
36 different number at the end of the device filename. If you get failures
37 try :
38
39  ./chk -d /dev/bdmcf0
40
41 On RedHat this should place debug info into `/var/log/messages' and the
42 console. The chk program only raises the driver debug level to 1. It can
43 go higher for more info. High numbers can get quite verbose so watch
44 out. Send me any info or questions if you have problems.
45
46 The chk test covers most critical areas in the driver.
47
48 Patch gdb then build and install.
49
50 The driver is a kernel module and currently only supports 2.0.x kernels.
51 The driver breaks on 2.2.x kernels. I have not received any 2.2.x
52 patches. They are welcome.
53
54 To test gdb, start it with :
55
56   $ m68k-bdm-coff-gdb
57   GNU gdb 4.17
58   Copyright 1998 Free Software Foundation, Inc.
59   GDB is free software, covered by the GNU General Public License, and
60 you are
61   welcome to change it and/or distribute copies of it under certain
62 conditions.
63   Type "show copying" to see the conditions.
64   There is absolutely no warranty for GDB.  Type "show warranty" for
65 details.
66   This GDB was configured as "--host=i686-pc-linux-gnulibc1
67 --target=m68k-bdm-coff".
68   (gdb) 
69
70 Once you have the gdb prompt, connect to the target with the gdb command
71 :
72
73   (gdb) target bdm /dev/bdmcf0
74   Remote bdm connected to /dev/bdmcf0
75
76 Again change the last number to be the parallel port you are connected
77 to.
78
79 The driver and gdb patch also supports the cpu32 core as found in the
80 68360. You connect using another device, eg /dev/bdmcpu320.
81
82 Your target will have been reset and halted. You can now look at the
83 ROM. To dump the vector table try :
84
85   (gdb) x /12w 0
86   0x0:    0x000071c8      0xffe00400      0xffe00518      0xffe00518
87   0x10:   0xffe00518      0xffe00518      0xffe00518      0xffe00518
88   0x20:   0xffe00518      0xffe00518      0xffe00518      0xffe00518
89
90 This is from my 5206 eval board. GDB has no stack history at this point
91 so dumping all the registers will fail. You can select a frame then gdb
92 will dump the registers.
93
94   (gdb) p /x $pc
95   $4 = 0xffe0c860
96   (gdb) info reg
97   No selected frame.
98   (gdb) select-frame 0
99   (gdb) info reg
100   d0             0x0      0
101   d1             0x0      0
102   d2             0xfb9e6ec2       -73503038
103   d3             0xbd85fe43       -1115292093
104   d4             0x0      0
105   d5             0xbd3931fd       -1120325123
106   d6             0xbf3a28d0       -1086707504
107   d7             0x0      0
108   a0             0x30000000       0x30000000
109   a1             0xffe08391       0xffe08391
110   a2             0x9b1b2fd3       0x9b1b2fd3
111   a3             0x33ef6c49       0x33ef6c49
112   a4             0x7fea5983       0x7fea5983
113   a5             0x2fabcbcf       0x2fabcbcf
114   fp             0x70fc   0x70fc
115   sp             0x70fc   0x70fc
116   ps             0x2704   0x2704
117   pc             0xffe0c860       0xffe0c860
118   vbr            0x3fc    0x3fc
119   cacr           0x0      0x0
120   acr0           0x300f6000       0x300f6000
121   acr1           0x300f6000       0x300f6000
122   rambar         0x20000000       0x20000000
123   mbar           0x10000000       0x10000000
124   csr            0x1000000        0x1000000
125   aatr           0x5      0x5
126   tdr            0x0      0x0
127   pbr            0x0      0x0
128   pbmr           0x0      0x0
129   abhr           0x0      0x0
130   ablr           0x0      0x0
131   dbr            0x0      0x0
132
133 Notice MBAR is not set. This could be confusing if are expecting to look
134 at devices connected to chip selects. The dbug monitor ROM has not run
135 so no coldfire resources have been setup.
136
137 The Coldfire has a nice feature for BDM reset debugging. If you do not
138 change the program counter with a command such as:
139
140   (gdb) set $pc=start
141
142 or
143
144   (gdb) set $pc=0xdeaddead
145
146 The coldfire core will perform the normal stack pointer and reset vector
147 fetch. For the sbc5206 eval board I am connected to, to step the dbug
148 boot code do :
149
150   (gdb) display /i $pc
151   1: x/i $pc  0xffe0c860: moveb %a0@(21),%d0
152   (gdb) si
153   0xffe00404 in ?? ()
154   1: x/i $pc  0xffe00404: movel #-2097152,%d0
155   (gdb) 
156   0xffe0040a in ?? ()
157   1: x/i $pc  0xffe0040a: moveal %d0,%sp
158   (gdb) 
159   0xffe0040c in ?? ()
160   1: x/i $pc  0xffe0040c: movec %sp,%vbr
161   (gdb) 
162   0xffe00410 in ?? ()
163   1: x/i $pc  0xffe00410: movel #16777216,%d0
164   (gdb) 
165   0xffe00416 in ?? ()
166   1: x/i $pc  0xffe00416: movec %d0,%cacr
167   (gdb) 
168
169 You might notice GDB repeats the last command entered if you just hit
170 enter.
171
172 When you run gdb connected to an embedded target like this the `run'
173 command is not used. The `target' command connects you to an existing
174 "process". The run command when used on a native system such as Linux
175 creates the "process" to be debugged. Your embedded target is an
176 existing "process" so no need to use the run command. You just step or
177 continue.
178
179 Now to running some code you have compiled with the -g option. The
180 driver has an example gdb init script. Look in `gdbScripts/5206.gdb'. I
181 usually copy this script to the directory where the coff file to be
182 debugged sits and rename it to `.gdbinit'. I am working on a boot rom
183 for the sbc5206 eval board. All I added to the end of the file in the
184 driver archive is :
185
186   dir ../../../kernel/boot/net
187   dir ../../../kernel/boot/net/drivers/clock
188   dir ../../../kernel/boot/net/drivers/net
189   dir ../../../kernel/boot/net/loaders
190   dir ../../../kernel/boot/support
191   dir ../../../arch/m68k/5206/boot
192
193   target bdm /dev/bdmcf0
194   addresses
195   setup-cs
196   setup-dram
197
198   load
199
200   set print pretty
201   set print asm-demangle
202
203 I then run :
204
205   $ m68k-bdm-coff-gdb sbc5206.coff 
206   GNU gdb 4.17
207   Copyright 1998 Free Software Foundation, Inc.
208   GDB is free software, covered by the GNU General Public License, and
209 you are
210   welcome to change it and/or distribute copies of it under certain
211 conditions.
212   Type "show copying" to see the conditions.
213   There is absolutely no warranty for GDB.  Type "show warranty" for
214 details.
215   This GDB was configured as "--host=i686-pc-linux-gnulibc1
216 --target=m68k-bdm-coff"...
217   (gdb) si 
218   0x404 in start ()
219   (gdb) x /20i $pc
220   0x404 <start+4>:        lea 0x0 <V___ISSP>,%sp
221   0x40a <start+10>:       movec %sp,%vbr
222   0x40e <start+14>:       movel #536870913,%d0
223   0x414 <start+20>:       movec %d0,3076
224   0x418 <start+24>:       moveal #536871420,%sp
225   0x41e <start+30>:       nop
226   0x420 <start+32>:       nop
227   0x422 <start+34>:       moveal #536870912,%a0
228   0x428 <start+40>:       moveq #51,%d0
229   0x42a <start+42>:       moveq #0,%d1
230   0x42c <start+44>:       moveb %d0,%a0@
231   0x42e <start+46>:       moveb %a0@,%d1
232   0x430 <start+48>:       cmpl %d1,%d0
233   0x432 <start+50>:       bnew 0x518 <_stop_cf>
234   0x436 <start+54>:       notl %d0
235   0x438 <start+56>:       andil #255,%d0
236   0x43e <start+62>:       moveb %d0,%a0@
237   0x440 <start+64>:       moveb %a0@,%d1
238   0x442 <start+66>:       cmpl %d1,%d0
239   0x444 <start+68>:       bnew 0x518 <_stop_cf>
240   (gdb) b boot_cpu
241   Breakpoint 1 at 0x522: file cpuboot.c, line 63.
242   (gdb) c
243   Continuing.
244
245   Breakpoint 1, boot_cpu () at cpuboot.c:63
246   63        CF_DISABLE_AND_INVALIDATE_CACHE();
247   (gdb) l
248   58        UINT32 i;
249   59      #endif
250   60        
251   61        /* disable and invalidate the instruction cache */
252   62
253   63        CF_DISABLE_AND_INVALIDATE_CACHE();
254   64        
255   65        /* program the system protection register */
256   66        
257   67        CF_SIM_WRITE_SYPCR(CF5206_BASE,
258   (gdb) 
259
260 What happens here is the .gdbinit script programs the MBAR, chip selects
261 and enables the DRAM. DRAM is at 0. My linker command file places
262 `.text', '.data', and '.bss' one after each other at address 0. The
263 first part of the text seciton is the vector table. This how-ever is
264 moving away from gdb to the other tools and this mail is long enough at
265 it is.
266
267 -- 
268  Chris Johns  Networks, Plessey Asia Pacfic Pty. Ltd.
269   mailto:ccj@acm.org    mailto:cjohns@plessey.com.au
270
271 ________________________________________________________________________
272 ColdFire Discussion List
273 See: <http://www.WildRice.com/ColdFire/>
274
275 -----------------------------------------------------------------------------