]> git.sur5r.net Git - cc65/blob - doc/debugging.sgml
remote TABs in doc/ and test/
[cc65] / doc / debugging.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4 <title>Using emulators with cc65
5 <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">
6
7 <abstract>
8 How to debug your code using the VICE and Oricutron emulators.
9 </abstract>
10
11 <!-- Table of contents -->
12 <toc>
13
14 <!-- Begin the document -->
15
16 <sect>Overview<p>
17
18 This document describes how to debug your programs using the cc65 development
19 tools and the VICE CBM emulator.
20
21
22
23 <sect>What is VICE?<p>
24
25 VICE is an emulator for many of the CBM machines. It runs on Unix, MS-DOS,
26 Win32, OS/2, Acorn RISC OS, BeOS, QNX 6.x, Amiga, GP2X and Mac OS X. It emulates
27 the Commodore 64, 128, VIC20, PET and the 600/700 machines. For more information
28 see the VICE home page:
29
30 <url url="http://vice-emu.sourceforge.net/">.
31
32 VICE has a builtin machine language monitor that may be used for debugging
33 your programs. Using an emulator for debugging has some advantages:
34
35 <itemize>
36
37 <item>Since you're using a crossassembler/-compiler anyway, you don't need to
38 transfer the program to the real machine until it is done.
39
40 <item>An emulator allows many things that are almost impossible one of the
41 original machines. You may set watchpoints (detect read or write access to
42 arbitary addresses), debug interrupt handlers and even debug routines that run
43 inside the 1541 floppy.
44
45 <item>You may use the label file generated by the linker to make much more use
46 from the monitor.
47
48 </itemize>
49
50
51
52 <sect>How to prepare your programs<p>
53
54 VICE support is mostly done via a label file that is generated by the linker
55 and that may be read by the VICE monitor, so it knows about your program.
56 Source level debugging is <tt/not/ available, you have to debug your programs
57 in the assembler view.
58
59 The first step is to generate object files that contain information about
60 <em/all/ labels in your sources, not just the exported ones. This can be done
61 by several means:
62
63 <itemize>
64
65 <item>Use the -g switch on the assembler command line.
66
67 <item>Use the
68 <tscreen><verb>
69       .debuginfo +
70 </verb></tscreen>
71     command in your source.
72
73 <item>Use the <tt/-g/ switch when invoking the compiler. The compiler will
74 then place a <tt/.debuginfo/ command into the generated assembler source.
75
76 </itemize>
77
78 So, if you have just C code, all you need is to invoke the compiler with
79 <tt/-g/. If you're using assembler code, you have to use <tt/-g/ for the
80 assembler, or add "<tt/.debuginfo on/" to your source files. Since the
81 generated debug info is not appended to the generated executables, it is a
82 good idea to always use <tt/-g/. It makes the object files and libraries
83 slightly larger (&tilde;30%), but this is usually not a problem.
84
85 The second step is to tell the linker that it should generate a VICE label
86 file. This is done by the <tt/-Ln/ switch followed by the name of the label
87 file (I'm usually using a <tt/.lbl/ extension for these files). An example for
88 a linker command line would be:
89
90 <tscreen><verb>
91     ld65 -o hello -t c64 -Ln hello.lbl -m hello.map hello.o c64.lib
92 </verb></tscreen>
93 or
94 <tscreen><verb>
95     ld65 -o hello.tap -t atmos -Ln hello.sym -m hello.map hello.o atmos.lib
96 </verb></tscreen>
97
98 This will generate a file named hello.lbl that contains all symbols used in
99 your program.
100
101 <bf>Note</bf>: The runtime libraries and startup files were generated with
102 debug info, so you don't have to care about this.
103
104
105
106 <sect>How to use the label file with VICE<p>
107
108 Load your program, then enter the monitor and use the "<tt/ll/" command to
109 load your label file like this:
110
111 <tscreen><verb>
112         ll "hello.lbl"
113 </verb></tscreen>
114
115 You will get lots of warnings and even a few errors. You may ignore safely all
116 these warnings and errors as long as they reference any problems VICE thinks
117 it has with the labels.
118
119 After loading the labels, they are used by VICE in the disassembler listing,
120 and you may use them whereever you need to specify an address. Try
121
122 <tscreen><verb>
123         d ._main
124 </verb></tscreen>
125
126 as an example (note that VICE needs a leading dot before all labels, and that
127 the compiler prepends an underline under most named labels).
128
129
130
131 <sect>How to use the label file with Oricutron<p>
132
133 Load your program, then enter the monitor and use the "<tt/sl/" command to
134 load your label file like this:
135
136 <tscreen><verb>
137         sl hello.sym
138 </verb></tscreen>
139
140 After loading the labels, they are used by Oricutron in the disassembler listing,
141 and you may use them whereever you need to specify an address. Try
142
143 <tscreen><verb>
144         d ._main
145 </verb></tscreen>
146
147 as an example (note that VICE needs a leading dot before all labels, and that
148 the compiler prepends an underline under most named labels).
149
150
151
152 </article>