1 <!doctype linuxdoc system>
5 <title>Using emulators with cc65
6 <author>Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">
10 How to debug your code using the VICE and Oricutron emulators.
13 <!-- Table of contents -->
16 <!-- Begin the document -->
20 This document describes how to debug your programs using the cc65 development
21 tools and the VICE CBM emulator.
25 <sect>What is VICE?<p>
27 VICE is an emulator for many of the CBM machines. It runs on Unix, MS-DOS,
28 Win32, OS/2, Acorn RISC OS, BeOS, QNX 6.x, Amiga, GP2X and Mac OS X. It emulates
29 the Commodore 64, 128, VIC20, PET and the 600/700 machines. For more information
30 see the VICE home page:
32 <htmlurl url="http://www.viceteam.org/">
34 VICE has a builtin machine language monitor that may be used for debugging
35 your programs. Using an emulator for debugging has some advantages:
39 <item>Since you're using a crossassembler/-compiler anyway, you don't need to
40 transfer the program to the real machine until it is done.
42 <item>An emulator allows many things that are almost impossible one of the
43 original machines. You may set watchpoints (detect read or write access to
44 arbitary addresses), debug interrupt handlers and even debug routines that run
45 inside the 1541 floppy.
47 <item>You may use the label file generated by the linker to make much more use
54 <sect>How to prepare your programs<p>
56 VICE support is mostly done via a label file that is generated by the linker
57 and that may be read by the VICE monitor, so it knows about your program.
58 Source level debugging is <tt/not/ available, you have to debug your programs
59 in the assembler view.
61 The first step is to generate object files that contain information about
62 <em/all/ labels in your sources, not just the exported ones. This can be done
67 <item>Use the -g switch on the assembler command line.
73 command in your source.
75 <item>Use the <tt/-g/ switch when invoking the compiler. The compiler will
76 then place a <tt/.debuginfo/ command into the generated assembler source.
80 So, if you have just C code, all you need is to invoke the compiler with
81 <tt/-g/. If you're using assembler code, you have to use <tt/-g/ for the
82 assembler, or add "<tt/.debuginfo on/" to your source files. Since the
83 generated debug info is not appended to the generated executables, it is a
84 good idea to always use <tt/-g/. It makes the object files and libraries
85 slightly larger (˜30%), but this is usually not a problem.
87 The second step is to tell the linker that it should generate a VICE label
88 file. This is done by the <tt/-Ln/ switch followed by the name of the label
89 file (I'm usually using a <tt/.lbl/ extension for these files). An example for
90 a linker command line would be:
93 ld65 -o hello -t c64 -Ln hello.lbl -m hello.map hello.o c64.lib
97 ld65 -o hello.tap -t atmos -Ln hello.sym -m hello.map hello.o atmos.lib
100 This will generate a file named hello.lbl that contains all symbols used in
103 <bf>Note</bf>: The runtime libraries and startup files were generated with
104 debug info, so you don't have to care about this.
108 <sect>How to use the label file with VICE<p>
110 Load your program, then enter the monitor and use the "<tt/ll/" command to
111 load your label file like this:
117 You will get lots of warnings and even a few errors. You may ignore safely all
118 these warnings and errors as long as they reference any problems VICE thinks
119 it has with the labels.
121 After loading the labels, they are used by VICE in the disassembler listing,
122 and you may use them whereever you need to specify an address. Try
128 as an example (note that VICE needs a leading dot before all labels, and that
129 the compiler prepends an underline under most named labels).
133 <sect>How to use the label file with Oricutron<p>
135 Load your program, then enter the monitor and use the "<tt/sl/" command to
136 load your label file like this:
142 After loading the labels, they are used by Oricutron in the disassembler listing,
143 and you may use them whereever you need to specify an address. Try
149 as an example (note that VICE needs a leading dot before all labels, and that
150 the compiler prepends an underline under most named labels).