MDB User Guide
MDB User Guide
MDB User Guide
Users Guide
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchips Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
Microchip is willing to work with the customer who is concerned about the integrity of their code.
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as unbreakable.
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchips code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Table of Contents
Preface ........................................................................................................................... 5
Chapter 1. How to Use Microchip Debugger
1.1 Introduction ..................................................................................................... 9
1.2 Getting Started ............................................................................................. 10
1.3 Invoking the MDB ......................................................................................... 10
1.4 Debugging Methods ..................................................................................... 12
1.5 Running a Command File Method ................................................................ 15
1.6 Using Multiple Instances of the MDB ........................................................... 16
Chapter 2. MDB Reference
2.1 Help Commands ........................................................................................... 17
2.2 Classes of Commands ................................................................................. 17
2.3 List of Commands within Classes ................................................................ 18
Appendix A. Revision History
Index ............................................................................................................................. 35
Worldwide Sales and Service .................................................................................... 38
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and
documentation are constantly evolving to meet customer needs, so some actual dialogs and/
or tool descriptions may differ from those in this document. Please refer to our web site
(www.microchip.com) to obtain the latest documentation available.
Documents are identified with a DS number. This number is located on the bottom of each
page, in front of the page number. The numbering convention for the DS number is
DSXXXXXXXXA, where XXXXXXXX is the document number and A is the revision level
of the document.
For the most up-to-date information on development tools, see the MPLAB X IDE help. Select
the Help menu, and then Topics to open a list of available help files.
INTRODUCTION
This chapter contains general information that will be helpful to know before using the
Microchip Debugger (MDB). Items that are discussed include:
Document Layout
Conventions Used in This Guide
Recommended Reading
DOCUMENT LAYOUT
This document is organized as follows:
Chapter 1. How to Use Microchip Debugger describes how to get started with
the MDB, invoking the MDB, and the debugging methods that are available.
Chapter 2. MDB Reference details the classes of commands and describes the
available lists of commands.
Appendix A. Revision History identifies the changes that have been made to the
document.
RECOMMENDED READING
This document describes how to use the MDB. Other useful documents are listed
below. The following Microchip presentation and documents are available and
recommended as supplemental reference resources.
Note: The mdb.bat and mdb.sh scripts do not need to be run from the directory where they were
installed. If the directory where these scripts are installed is added to the system path, then
mdb.bat and msb.sh may run from any directory.
Note: Although the MPLAB X IDE can run multiple tools simultaneously, the MDB
will run only one tool at a time. However, you can have multiple instances
of the MDB running.
Refer to Section 1.6 Using Multiple Instances of the MDB for details.
Entering commands is a step-by-step method to run a test with MDB. Once the MDB
is running, you can start entering commands. Note that while the MDB commands are
not case-sensitive, the property options and file names are case-sensitive.
Type help for a list of classes of commands in MDB. Refer to Chapter 2. MDB
Reference, Table 2-1 MDB Classes of Commands.
For other commands available, see Chapter 2. MDB Reference, Table 2-2 through
Table 2-10.
The following sections describe these topics:
Programming a Production Image for Testing Purposes
Debugging a Device
The file or hardware tool you need to use for MDB cannot be active or open
simultaneously in the MPLAB X IDE, IPE, or a third party program. Make sure you close
(or make inactive) the file or hardware tool before you attempt to use it with the MDB.
Set Breakpoint there are two ways to set a breakpoint for debugging:
- Set a breakpoint by source-line-number using the command:
Break filename: linenumber
For example: Break main.c:53
or
Watch address breakontype[:value] [passcount]
For example: Watch 0xa0007ff0 R:0xf 1
Run Program the Run command can be used to run the program until it reaches
a breakpoint.
Step Through to step through the program, use the Step command or Next
command.
See Variable Value a Print [variable] command can be used to see the
value of a variable or an SFR.
If programming and debugging needs to be done frequently or multiple times, run the
test by running a command file. This is more efficient than entering the commands
repeatedly. Put all the commands in a file and run the MDB using this command file in
the Command Prompt, for example:
C:\Program Files\Microchip\MPLABX\vn.nn\mplab_ide\bin>mdb.bat
<commandfile.txt>
The following is an example of a command file:
C:\MDB-SIMCommand_Target.txt
A line starting with # means that it is a comment. A Sleep command should be added
to make sure the MDB has enough time to finish the previous command before it
executes the next command. The MDB will run all the commands in the command file
sequentially.
For a list of all commands within a particular class, type help followed by the class
name. The help command can also be abbreviated to h. See the following tables for
information about each class of commands.
For documentation on a particular command, type help [command or class of
commands] to display information about the command. For example, if you type:
help breakpoints or h Breakpoints
the MDB displays information about the break, watch, delete and halt commands.
The following tables provide information on these commands:
Breakpoints Commands
Data Commands
Device and Tool Commands
Others Commands
Tool Property Options Used with the Set Command
Simulator Options Used with the Set Command
Programming Commands
Running Commands
Stack Commands
Watch Sets a data breakpoint at the specified memory address, variable name, or an SFR (special function register)
Command format:
Watch address breakonType[:value] [passCount]
address the name of a global variable, SFR, or data memory address to be watched
Use command 'print /a' to get a variable address.
breakonType:
R -- Read.
W -- Write.
RW -- Read or Write.
value this parameter is optional
If it is specified, the program will break only when the value held in the data memory matches the specified
value.
passCount this parameter is optional
The number of times the breakon condition is met before the program breaks.
Examples:
watch 0xa0007ff0 R:0xf 1
watch 0xa0007ff0 R:10 1
watch my_Variable W 4
MDB will assign and return the watchpoint number, for example: Watchpoint 1.
x Examine memory
You can use the command x (for examine) to examine memory in any of several formats, independent of your pro-
grams data types.
Command format:
x [/tnfu] [addr]
t the type of memory
Each time you specify a memory type with x, that type becomes the default memory the next time you use
x.The type of memory is any of the following:
r File Registers (RAM) memory. This is the initial default.
p Program (flash) memory.
m Memory-mapped control registers (PIC32 peripheral memory)
e EE Data memory.
n the repeat count
The repeat count is a decimal integer; the default is 1. It specifies how much memory (counting by units u) to
display.
f the display format.
The display format is one of the formats used by print (x, d, o, f, s), and in addition i (for machine
instructions). The default is x (hexadecimal) initially. The default changes each time you use x.
u the unit size
Each time you specify a unit size with x, that size becomes the default unit the next time you use x. (For the
s and i formats, the unit size is ignored and is normally not written.)
The unit size is any of following:
b Bytes.
h Halfwords (two bytes).
w Words (four bytes). This is the initial default.
addr - the starting display address where you want MDB to begin displaying memory
The addr can be a literal or a symbol name. The default for addr, if not specified, is taken as the value just after
the last address examined.
However, several other commands also set the default address: info breakpoints (to the address of the last
breakpoint listed); info line (to the starting address of a line); and print (if you use it to display a value from
memory).
Hwtool Sets the debug tool or list all the available hardware tools on the system
(The device must be set with the Device command before a tool can be used/set.)
Command format:
Hwtool [toolType] [-p] [index]
Following are the supported tool names (not case-sensitive):
ICD3 MPLAB ICD 3 In-Circuit Debugger
RealICE MPLAB REAL ICE In-Circuit Emulator
PICkit3 PICkit 3 In-Circuit Debugger
SIM Simulator
PM3 MPLAB PM3 Programmer
LicensedDebugger third party debugger
LicensedProgrammer third party programmer
SK Microchip Starter Kit (PICkit On Board PKOB)
To set the tool for programming only, a space must precede the -p option.
Command format:
Hwtool [toolType] -p
Example:
Hwtool ICD3 -p
Use the index option to select the tool if there are more than one instance of a tool type. If you have two
MPLAB ICD 3 units connected to the PC, use the hwtool command to find the assigned index number of the
tool.
Example:
>hwtool
index Description
0 MPLAB ICD 3 tm (MRK1000000000)
1 MPLAB ICD 3 tm (MRK1000001111)
Example:
Hwtool ICD3 -p 1
Note: By default, when a hardware tool is selected, it is loaded as a debugger. This means that it always
programs the device and adds the necessary debug requirements to enable the image to be
debugged.
To use a tool for programming only, use the -p option when setting the hardware tool.
Echo Echo is a command typically used in command files and batch files to output status text to the screen or a file. The
echo command will print text surrounded by /* */. Use \n in the text to print a new line.
Command format:
echo text
Example:
echo Hello World
Result:
/*Hello World*/
This command prints text only. To print variables or other information, use commands such as print, info, list,
etc.
Set The tool property name and value are from the project properties that are selected when creating the project in
MPLAB X IDE.
IMPORTANT: The Set command, including the tool property options, must be executed before the program
command is issued, otherwise the changes to the tool properties will be ignored.
Command format:
Set tool-property-name value
Example:
Set programoptions.eraseb4program true
Refer to Table 2-6 for other tool properties options that can used with the Set command.
Refer to Table 2-7 for simulator options that can be used with the Set command.
Sleep Makes the current script processor sleep until specified milliseconds have elapsed
Command format:
Sleep milliseconds
Example:
Sleep 10
Wait The Wait command makes the current script processor wait until the debugger halts before processing the next com-
mand.
Command format:
Wait
Wait Milliseconds makes the processor process the next command if the debugger does not halt and millisec-
onds have elapsed.
Command format:
Wait [milliseconds]
cd This command changes the directory that you are currently working in to the directory you designate.
Command format:
cd [directory]
info Prints a table of all breakpoints that have been set and not deleted
Optional argument n means print information only about the specified breakpoint.
For each breakpoint the following columns are printed:
Breakpoint Numbers
Enabled or Disabled
Enabled breakpoints are marked with y
Disabled breakpoints are marked with n
Address
Where the breakpoint is in your program, as a memory address.
What
Where the breakpoint is in the source for your program: as a file and line number.
Command format:
info breakpoints [n]
info break [n]
list\ The list command prints (displays) the source code for the current PC location, or a different file, if specified.
The list command displays lines from a source file.
By default, 10 lines are displayed.
list
displays 10 lines (5 above, 5 below) around the current line
list linenum
displays 10 lines around a given line
list first,
displays 10 lines from first line specified
list ,last
displays 10 lines up to last line specified
list first,last
displays all lines from the first to the last line specified
list -
displays 10 previous lines from the last output
list +
displays 10 more lines from the last output
list function
displays 10 lines around the given function
list file:linenum
displays 10 lines around the given line in a given file
list file:function
displays 10 lines around the given function in a given file
set system.listsize count
changes the number of lines shown.
Using 0 or -1 means unlimited list size
Note 1: MDB commands are not case-sensitive. However, when using the set command, where tool
option properties are passed as parameters, the parameter portion of the command line
entered is case-sensitive.
2: Tool property options that you want to use with the set command must be selected before
using the program command.
Note: For the following table, the break options allow you to set the conditions that will cause program
execution to halt. In general, the program will either break on option, ignore the option, or report
the option.
codecoverage.enabled Disable, No
Enables or disables code coverage Enabled_Reset_on_POR
Example: Enabled_Reset_on_Run
set codecoverage.enabled Disable
oscillator.frequency numeric No
Instruction Execution Frequency
Example:
set oscillator.frequency 4700
oscillator.rcfrequency Numeric No
RC Oscillator Frequency
Example:
set oscillator.rcfrequency 4500
Program Programs device memory with the image specified by the file
Note: if the path or filename has spaces in it, you must use the quotation marks. If there
are no spaces in the path of filename, the quotation marks are not needed, as shown
below.
Command format:
Program executableImageFile
Stepi Execute one machine instruction, then stop and return to the debugger
The optional argument count is a repeat count.
Command format:
Stepi [count]
Backtrace Print a backtrace of the entire stack, one line per frame for all frames in the stack
Command format:
Backtrace [full] [<n, -n>]
full prints the values of local variables
n prints the innermost n frames
-n prints the outermost n frames
Index
A Creating a Printable Log File.................................... 15
AutoSelectMemRanges ........................................... 25 D
B Data
Backtrace ................................................................. 31 Print................................................................... 20
Break...................................................................14, 19 Stim................................................................... 20
breakoptions.coreerrors ........................................... 27 Write.................................................................. 21
breakoptions.corewarnings ...................................... 27 x ........................................................................ 21
breakoptions.peripheralerrors .................................. 27 data .......................................................................... 17
breakoptions.peripheralwarnings ............................. 27 Debugging a Device................................................. 14
breakoptions.stimulusmessages.notes .................... 27 debugoptions.useswbreakpoints.............................. 25
breakoptions.stimulusmessags.errors...................... 27 Delete....................................................................... 19
breakoptions.stimulusmessags.warnings................. 27 Delete Breakpoint..................................................... 14
breakoptions.wdtwarnings ....................................... 27 Device ...................................................................... 22
Breakpoints Device and Tool
Break ................................................................ 19 Device ............................................................... 22
Delete ............................................................... 19 Deviceandtool ................................................... 22
Halt ................................................................... 19 Hwtool ............................................................... 22
Watch................................................................ 19 Deviceandtool .......................................................... 22
breakpoints .............................................................. 17 deviceandtool ........................................................... 17
Documentation
C Conventions ........................................................ 6
cd ............................................................................. 23 Dump........................................................................ 30
Classes of Commands ............................................. 17
E
breakpoints ....................................................... 17
data ................................................................... 17 Echo ......................................................................... 23
deviceandtool.................................................... 17 elf file........................................................................ 13
others ................................................................ 17 Entering Commands Method ................................... 12
programming..................................................... 17 Exit ........................................................................... 14
running .............................................................. 17 H
stack ................................................................. 17
Halt..................................................................... 19, 30
codecoverage.enabled............................................. 27
Header Specification .................................................. 7
codecoverage.enableoutputtofile ............................. 27
Help.......................................................................... 23
codecoverage.outputtofile ........................................ 28
Help Commands ...................................................... 17
cof file....................................................................... 13
Hwtool ...................................................................... 22
Command
Delete ............................................................... 14 M
Device ............................................................... 13 MDB ........................................................................... 9
list ..................................................................... 24 mdb --help ................................................................ 10
Print .................................................................. 14 MDB.bat file.............................................................. 15
Program ............................................................ 13 mdblog.txt file ........................................................... 15
Quit ................................................................... 14 memories.aux........................................................... 26
Reset MCLR ..................................................... 14 memories.bootflash.................................................. 25
Run ................................................................... 14 memories.eeprom .................................................... 25
Sleep................................................................. 15 memories.id.............................................................. 25
Step .................................................................. 14 memories.programmemory ...................................... 25
Stim................................................................... 13 memories.programmemory.end ............................... 25
help .......................................................................... 18 memories.programmemory.start .............................. 25
Command Line Parameters ..................................... 10 Microchip Debugger ................................................... 9
Command Prompt .................................................... 11
Continue................................................................... 30