1 <!doctype linuxdoc system>
4 <title>Using emulators with cc65
5 <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">
8 How to debug your code using the VICE and Oricutron emulators.
11 <!-- Table of contents -->
14 <!-- Begin the document -->
18 This document describes how to debug your programs using the cc65 development
19 tools and the VICE CBM emulator.
23 <sect>What is VICE?<p>
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:
30 <url url="http://vice-emu.sourceforge.net/">.
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:
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.
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.
45 <item>You may use the label file generated by the linker to make much more use
52 <sect>How to prepare your programs<p>
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.
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
65 <item>Use the -g switch on the assembler command line.
71 command in your source.
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.
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 (˜30%), but this is usually not a problem.
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:
91 ld65 -o hello -t c64 -Ln hello.lbl -m hello.map hello.o c64.lib
95 ld65 -o hello.tap -t atmos -Ln hello.sym -m hello.map hello.o atmos.lib
98 This will generate a file named hello.lbl that contains all symbols used in
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.
106 <sect>How to use the label file with VICE<p>
108 Load your program, then enter the monitor and use the "<tt/ll/" command to
109 load your label file like this:
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.
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
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).
131 <sect>How to use the label file with Oricutron<p>
133 Load your program, then enter the monitor and use the "<tt/sl/" command to
134 load your label file like this:
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
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).