You can use debuggers, such as the MPLAB ICD4 or REAL ICE, to debug code built with the MPLAB XC8 compiler. These debuggers use some of the data and program memory of the device for its own use, so it is important that your code does not also use these resources.
In the MPLAB X IDE, the appropriate memory is reserved when you perform
a debug build. All the device memory will be available when you perform a regular Build
Project or Clean and Build. If you are building on the command-line, then this memory
must be reserved using the compiler’s -mreserve
option. (See Reserve Option.) The
ReservedResourcesByDeviceFamilyAndTool.html file in the MPLAB X
IDE’s docs/ReservedResources directory shows the memory and
other resources that are used by each device.
Since some device memory is being used up by the debugger, there is less memory available for your program and it is possible that your code or data might not fit in the device when a debugger is selected.
Note that the specific memory locations used by the debuggers are an attribute of MPLAB X IDE, not the device or compiler. If you move a project to a new version of the IDE, the resources required can change.
To verify that the resources reserved by the compiler match those
required by the debugger, do the following. Compile your code with and without the
debugger selected and keep a copy of the map file produced for both builds. Compare the
linker options in the map files and look for changes in the -A
options
(see A: Define Linker Class). For
example, the memory defined for the CODE
class with no debugger might
be specified by this option:
-ACODE=00h-0FFh,0100h-07FFh,0800h-0FFFhx3
and with the ICD3 selected as the debugger, it becomes:
-ACODE=00h-0FFh,0100h-07FFh,0800h-0FFFhx2,01800h-01EFFh
This shows that a memory range from 1F00 to 1FFF has been removed by the compiler and cannot be used by your program (See also Why Are Some Objects Positioned Into Memory That I Reserved?).