3.4.3 What Do I Need to Do When Compiling to Use a Debugger?
You can use debuggers, such as the MPLAB PICkit™ 4 or ICD 4 in-circuit debuggers or the MPLAB REAL ICE™ in-circuit emulator, to debug code built with the MPLAB XC32 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.
The command-line option -g
(see 5.7.6 Options for Debugging) is used to tell
the compiler to generate debugging information. The compiler can then reserve the memory
used by the debugger so that your code will not be placed in these locations.
In the MPLAB X IDE, the appropriate debugger option is specified if you perform a Debug Run. It will not be specified if you perform a regular Run, Build Project, or Clean and Build.
Since some device memory is being reserved for use by the debugger, there is less available for your program and it is possible that your code or data may no longer fit in the device when a debugger is selected. For 32-bit devices, some boot flash memory is required for debugging. In addition, some data memory (RAM) is used by the debug tool and may impact the variable allocation in your application.
The specific memory locations used by the debuggers are attributes of MPLAB X IDE, the debug tool in use and the target device. If you move a project to a new version of the IDE, the resources required may change. For this reason, you should not manually reserve memory for the debugger, or make any assumptions in your code as to what memory is used. A summary of the debugger requirements is available in the MPLAB X IDE help files.
To verify that the resources reserved by the compiler match those required by the debugger, you may view the boot-flash, application-flash and data-memory usage in the map file or memory-usage report.
To create a map file in MPLAB X IDE, open the Project Properties window (File>Project Properties) and click on the linker category (xc32-ld). Under “Option Categories,” select “Diagnostics.” Next to “Generate map file,” enter a path and name for the map file. The logical place to put the map file is in the project folder.
Debug Run your code to generate the map file. View in your favorite text viewer.
See also 3.5.14 Why Are Some Objects Positioned Into Memory That I Reserved?.