3 Debugging your code using VICE
5 Ullrich von Bassewitz, March 1999
15 3. How to prepare your sources
17 4. How to use the label file
19 5. Problems and workarounds
26 This document describes how to debug your programs using the cc65
27 development tools and the VICE CBM emulator.
34 VICE is an emulator for many of the CBM machines. It runs on Unix, DOS and
35 Windows 95. It emulates the Commodore 64, 128, VIC20, PET and the 600/700
36 machines. For more information see the VICE home page:
38 http://www.cs.cmu.edu/~dsladic/vice/vice.html
40 VICE has a builtin machine language monitor that may be used for debugging
41 your programs. Using an emulator for debugging has some advantages:
43 - Since you're using a crossassembler/-compiler anyway, you don't need
44 to transfer the program to the real machine until it is done.
46 - An emulator allows many things that are almost impossible one of the
47 original machines. You may set watchpoints (detect read or write
48 access to arbitary addresses), debug interrupt handlers and even debug
49 routines that run inside the 1541 floppy.
51 - You may use the label file generated by the linker to make much more
54 Please note that you need at least VICE version 0.16 for the label file
55 feature to work. This version has still some problems (see section 5 for
56 descriptions and some workarounds), but older versions had even more
57 problems and do NOT work correctly.
61 3. How to prepare your programs
62 -------------------------------
64 VICE support is mostly done via a label file that is generated by the
65 linker and that may be read by the VICE monitor, so it knows about your
66 program. Source level debugging is *not* available, you have to debug your
67 programs in the assembler view.
69 The first step is to generate object files that contain information about
70 ALL labels in your sources, not just the exported ones. This can be done
73 - Use the -g switch on the assembler command line.
79 command in your source.
81 - Use the -g switch when invoking the compiler. The compiler will then
82 put the .debuginfo command into the generated assembler source.
84 So, if you have just C code, all you need is to invoke the compiler with
85 -g. If you're using assembler code, you have to use -g for the assembler,
86 or add ".debuginfo +" to your source files. Since the generated debug info
87 is not appended to the generated executables, it is a good idea to always
88 use -g. It makes the object files and libraries slightly larger (~30%),
89 but this is usually not a problem.
91 The second step is to tell the linker that it should generate a VICE label
92 file. This is done by the -L switch followed by the name of the label file
93 (I'm usually using a .lbl extension for these files). An example for a
94 linker command line would be:
96 ld65 -t c64 -L hello.lbl -m hello.map -o hello crt0 hello.o c64.lib
98 This will generate a file named hello.lbl that contains all symbols used
101 Note: The runtime libraries and startup files were generated with debug
102 info, so you don't have to care about this.
106 4. How to use the label file
107 ----------------------------
109 Load your program, then enter the monitor and use the "pb" command to load
110 your label file like this:
114 You will get lots of warnings and even a few errors. You may ignore safely
115 all these warnings and errors as long as they reference any problems VICE
116 thinks it has with the labels.
118 After loading the labels, they are used by VICE in the disassembler
119 listing, and you may use them whereever you need to specify an address.
124 as an example (note that VICE needs a leading dot before all labels, and
125 that the compiler prepends an underline under most named labels).
129 5. Problems and workarounds
130 ---------------------------
132 Unfortunately, the VICE monitor has several problems with labels. However,
133 it is still tremendously useful, and I think that most problems are gone
134 in the next version. So, here is a list of the problems known to me as of
137 * The "ll" command does not work. Worse, it seems that internal memory
138 gets corrupted when using this command, so VICE will crash after use.
139 Be sure to use the "pb" command to load the label file.
141 * VICE will crash if you use a label that is undefined. This is probably
142 the worst problem of all, since it needs just one typo to kill VICE.
143 So, watch your steps:-)
145 * Cheap labels, that is, labels starting with '@' or '?' are not
148 * The disassembly output is somewhat suboptimal. However, most things are
149 just cosmetical, e.g. labels appended to the right side of the