The Linux Foundation is a non-profit consortium dedicated to fostering the growth of Linux.
Back to Main DMI page (http://freestandards.org/en/DMI)
The content in this section of the wiki contains MI commands from the gdb manual. It will be the basis of the DMI specification.
This specification uses the following notation:
command ==>
cli-command | mi-command
cli-command ==>
[ token ] cli-command nl, where cli-command is any existing GDB CLI command.
mi-command ==>
[ token ] "-" operation ( " " option )* [ " --" ] ( " " parameter )* nl
token ==>
"any sequence of digits"
option ==>
"-" parameter [ " " parameter ]
parameter ==>
non-blank-sequence | c-string
operation ==>
any of the operations described in this chapter
non-blank-sequence ==>
anything, provided it doesn't contain special characters such as "-", nl, """ and of course " "
c-string ==>
""" seven-bit-iso-c-string-content """
nl ==>
CR | CR-LF
The output from GDB/MI consists of zero or more out-of-band records followed, optionally, by a single result record. This result record is for the most recent command. The sequence of output records is terminated by `(gdb)'.
If an input command was prefixed with a token then the corresponding output for that command will also be prefixed by that same token.
output ==>
( out-of-band-record )* [ result-record ] "(gdb)" nl
result-record ==>
[ token ] "^" result-class ( "," result )* nl
out-of-band-record ==>
async-record | stream-record
async-record ==>
exec-async-output | status-async-output | notify-async-output
exec-async-output ==>
[ token ] "*" async-output
status-async-output ==>
[ token ] "+" async-output
notify-async-output ==>
[ token ] "=" async-output
async-output ==>
async-class ( "," result )* nl
result-class ==>
"done" | "running" | "connected" | "error" | "exit"
async-class ==>
"stopped" | others (where others will be added depending on the needs--this is still in development).
result ==>
variable "=" value
variable ==>
string
value ==>
const | tuple | list
const ==>
c-string
tuple==>
"{}" | "{" result ( "," result )* "}"
list ==>
"[]" | "[" value ( "," value )* "]" | "[" result ( "," result )* "]"
stream-record ==>
console-stream-output | target-stream-output | log-stream-output
console-stream-output ==>
"~" c-string
target-stream-output ==>
"@" c-string
log-stream-output ==>
"&" c-string
nl ==>
CR | CR-LF
token ==>
any sequence of digits
See section #Stream Records, for more details about the various output records.
To help users familiar with GDB's existing CLI interface, GDB/MI accepts existing CLI commands. As specified by the syntax, such commands can be directly entered into the GDB/MI interface and GDB will respond.
This mechanism is provided as an aid to developers of GDB/MI clients and not as a reliable interface into the CLI. Since the command is being interpreteted in an environment that assumes GDB/MI behaviour, the exact output of such commands is likely to end up being an un-supported hybrid of GDB/MI and CLI output.
The application which takes the MI output and presents the state of the program being debugged to the user is called a front end.
Although GDB/MI is still incomplete, it is currently being used by a variety of front ends to GDB. This makes it difficult to introduce new functionality without breaking existing usage. This section tries to minimize the problems by describing how the protocol might change.
Some changes in MI need not break a carefully designed front end, and for these the MI version will remain unchanged. The following is a list of changes that may occur within one level, so front ends should parse MI output in a way that can handle them:
If the changes are likely to break front ends, the MI version level will be increased by one. This will allow the front end to parse the output according to the MI version. Apart from mi0, new versions of GDB will not support old versions of MI and it will be the responsibility of the front end to work with the new one.
In addition to a number of out-of-band notifications, the response to a GDB/MI command includes one of the following result indications:
"^done" [ "," results ]
The synchronous operation was successful, results are the return values.
"^running"
The asynchronous operation was successfully started. The target is running.
"^connected"
GDB has connected to a remote target.
"^error" "," c-string
The operation failed. The c-string contains the corresponding error message.
"^exit"
GDB has terminated.
GDB internally maintains a number of output streams: the console, the target, and the log. The output intended for each of these streams is funneled through the GDB/MI interface using stream records.
Each stream record begins with a unique prefix character which identifies its stream (see section #Output Syntax). In addition to the prefix, each stream record contains a string-output. This is either raw text (with an implicit new line) or a quoted C string (which does not contain an implicit newline).
"~" string-output
The console output stream contains text that should be displayed in the CLI console window. It contains the textual responses to CLI commands.
"@" string-output
The target output stream contains any textual output from the running target.
"&" string-output
The log stream contains debugging messages being produced by GDB's internals.
Out-of-band records are used to notify the GDB/MI client of additional changes that have occurred. Those changes can either be a consequence of GDB/MI (e.g., a breakpoint modified) or a result of target activity (e.g., target stopped).
The following is a preliminary list of possible out-of-band records. In particular, the exec-async-output records.
*stopped,reason="reason"
reason can be one of the following:
A breakpoint was reached.
A watchpoint was triggered.
A read watchpoint was triggered.
An access watchpoint was triggered.
An -exec-finish or similar CLI command was accomplished.
An -exec-until or similar CLI command was accomplished.
A watchpoint has gone out of scope.
An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or similar CLI command was accomplished.
The inferior exited because of a signal.
The inferior exited.
The inferior exited normally.
A signal was received by the inferior.
The remaining sections describe blocks of commands. Each block of commands is laid out in a fashion similar to this section.
Note the the line breaks shown in the examples are here only for readability. They don't appear in the real output. Also note that the commands with a non-available example (N.A.) are not yet implemented.
The motivation for this collection of commands.
A brief introduction to this collection of commands as a whole.
For each command in the block, the following is described:
-command args...
This section documents GDB/MI commands for manipulating breakpoints.
-break-after number count
The breakpoint number number is not in effect until it has been hit count times. To see how this is reflected in the output of the `-break-list' command, see the description of the `-break-list' command below.
-break-condition number expr
Breakpoint number will stop the program only if the condition in expr is true. The condition becomes part of the `-break-list' output (see the description of the `-break-list' command below).
-break-delete ( breakpoint )+
Delete the breakpoint(s) whose number(s) are specified in the argument list. This is obviously reflected in the breakpoint list.
-break-disable ( breakpoint )+
Disable the named breakpoint(s). The field `enabled' in the break list is now set to `n' for the named breakpoint(s).
-break-enable ( breakpoint )+
Enable (previously disabled) breakpoint(s).
-break-info breakpoint
Get information about a single breakpoint.
-break-insert [ -t ] [ -h ] [ -r ] [ -c condition ] [ -i ignore-count ] [ -p thread ] [ line | addr ]
If specified, line, can be one of:
function filename:linenum filename:function *address
The possible optional parameters of this command are:
Insert a temporary breakpoint.
Insert a hardware breakpoint.
Make the breakpoint conditional on condition.
Initialize the ignore-count.
Insert a regular breakpoint in all the functions whose names match the given regular expression. Other flags are not applicable to regular expresson.
The result is in the form:
^done,bkpt={number="number",type="type",disp="del"|"keep",
enabled="y"|"n",addr="hex",func="funcname",file="filename",
fullname="full_filename",line="lineno",times="times"}
where number is the GDB number for this breakpoint, funcname is the name of the function where the breakpoint was inserted, filename is the name of the source file which contains this function, lineno is the source line number within that file and times the number of times that the breakpoint has been hit (always 0 for -break-insert but may be greater for -break-info or -break-list which use the same output).
Note: this format is open to change.
-break-list
Displays the list of inserted breakpoints.
The breakpoint list has the following fields:
number of the breakpoint
type of the breakpoint: `breakpoint' or `watchpoint'
should the breakpoint be deleted or disabled when it is hit: `keep' or `nokeep'
is the breakpoint enabled or no: `y' or `n'
memory location at which the breakpoint is set
logical location of the breakpoint, expressed by function name, file name, line number
number of times the breakpoint has been hit
If there are no breakpoints or watchpoints, the BreakpointTable body field is an empty list.
-break-watch [ -a | -r ]
Create a watchpoint. With the `-a' option it will create an access watchpoint, i.e. a watchpoint that triggers either on a read from or on a write to the memory location. With the `-r' option, the watchpoint created is a read watchpoint, i.e. it will trigger only when the memory location is accessed for reading. Without either of the options, the watchpoint created is a regular watchpoint, i.e. it will trigger when the memory location is accessed for writing. See section #Setting Watchpoints.
Note that `-break-list' will report a single list of watchpoints and breakpoints inserted.
-exec-arguments args
Set the inferior program arguments, to be used in the next `-exec-run'.
-exec-show-arguments
Print the arguments of the program.
-environment-cd pathdir
Set GDB's working directory.
-environment-directory [ -r ] [ pathdir ]+
Add directories pathdir to beginning of search path for source files. If the `-r' option is used, the search path is reset to the default search path. If directories pathdir are supplied in addition to the `-r' option, the search path is first reset and then addition occurs as normal. Multiple directories may be specified, separated by blanks. Specifying multiple directories in a single command results in the directories added to the beginning of the search path in the same order they were presented in the command. If blanks are needed as part of a directory name, double-quotes should be used around the name. In the command output, the path will show up separated by the system directory-separator character. The directory-seperator character must not be used in any directory name. If no directories are specified, the current search path is displayed.
-environment-path [ -r ] [ pathdir ]+
Add directories pathdir to beginning of search path for source files. If the `-r' option is used, the search path is reset to the default search path. If directories pathdir are supplied in addition to the `-r' option, the search path is first reset and then addition occurs as normal. Multiple directories may be specified, separated by blanks. Specifying multiple directories in a single command results in the directories added to the beginning of the search path in the same order they were presented in the command. If blanks are needed as part of a directory name, double-quotes should be used around the name. In the command output, the path will show up separated by the system directory-separator character. The directory-seperator character must not be used in any directory name. If no directories are specified, the current path is displayed.
-environment-pwd
Show the current working directory.
-thread-info
-thread-list-all-threads
-thread-list-ids
Produces a list of the currently known GDB thread ids. At the end of the list it also prints the total number of such threads.
-thread-select threadnum
Make threadnum the current thread. It prints the number of the new current thread, and the topmost frame for that thread.
These are the asynchronous commands which generate the out-of-band record `*stopped'. Currently GDB only really executes asynchronously with remote targets and this interaction is mimicked in other cases.
-exec-continue
Resumes the execution of the inferior program until a breakpoint is encountered, or until the inferior exits.
-exec-finish
Resumes the execution of the inferior program until the current function is exited. Displays the results returned by the function.
-exec-interrupt
Interrupts the background execution of the target. Note how the token associated with the stop message is the one for the execution command that has been interrupted. The token for the interrupt itself only appears in the `^done' output. If the user is trying to interrupt a non-running program, an error message will be printed.
-exec-next
Resumes execution of the inferior program, stopping when the beginning of the next source line is reached.
-exec-next-instruction
Executes one machine instruction. If the instruction is a function call, continues until the function returns. If the program stops at an instruction in the middle of a source line, the address will be printed as well.
-exec-return
Makes current function return immediately. Doesn't execute the inferior. Displays the new current frame.
-exec-run
Starts execution of the inferior from the beginning. The inferior executes until either a breakpoint is encountered or the program exits. In the latter case the output will include an exit code, if the program has exited exceptionally.
-exec-step
Resumes execution of the inferior program, stopping when the beginning of the next source line is reached, if the next source line is not a function call. If it is, stop at the first instruction of the called function.
-exec-step-instruction
Resumes the inferior which executes one machine instruction. The output, once GDB has stopped, will vary depending on whether we have stopped in the middle of a source line or not. In the former case, the address at which the program stopped will be printed as well.
-exec-until [ location ]
Executes the inferior until the location specified in the argument is reached. If there is no argument, the inferior executes until a source line greater than the current one is reached. The reason for stopping in this case will be `location-reached'.
-stack-info-frame
Get info on the selected frame.
-stack-info-depth [ max-depth ]
Return the depth of the stack. If the integer argument max-depth is specified, do not count beyond max-depth frames.
-stack-list-arguments show-values [ low-frame high-frame ]
Display a list of the arguments for the frames between low-frame and high-frame (inclusive). If low-frame and high-frame are not provided, list the arguments for the whole call stack.
The show-values argument must have a value of 0 or 1. A value of 0 means that only the names of the arguments are listed, a value of 1 means that both names and values of the arguments are printed.
-stack-list-frames [ low-frame high-frame ]
List the frames currently on the stack.
For each frame it displays the following info:
The frame number, 0 being the topmost frame, i.e. the innermost function.
The $pc value for that frame.
Function name.
File name of the source file where the function lives.
Line number corresponding to the $pc.
If invoked without arguments, this command prints a backtrace for the whole stack. If given two integer arguments, it shows the frames whose levels are between the two arguments (inclusive). If the two arguments are equal, it shows the single frame at the corresponding level.
-stack-list-locals print-values
Display the local variable names for the selected frame. If print-values is 0 or --no-values, print only the names of the variables; if it is 1 or --all-values, print also their values; and if it is 2 or --simple-values, print the name, type and value for simple data types and the name and type for arrays, structures and unions. In this last case, a frontend can immediately display the value of simple data types and create variable objects for other data types when the the user wishes to explore their values in more detail.
-stack-select-frame framenum
Change the selected frame. Select a different frame framenum on the stack.
Variable objects are provided to support the implementation of a variable debugger window (locals, watched expressions, etc.). The original concept was developed for the Insight debugger.
Note: In addition to the set of operations described here, we expect the GUI implementation of a variable window to require, at least, the following operations:
-gdb-show output-radix -stack-list-arguments -stack-list-locals -stack-select-frame
The basic idea behind variable objects is the creation of a named object to represent a variable, an expression, a memory location or even a CPU register. For each object created, a set of operations is available for examining or changing its properties.
Furthermore, complex data types, such as C structures, are represented in a tree format. For instance, the struct type variable is the root and the children will represent the struct members. If a child is itself of a complex type, it will also have children of its own. Appropriate language differences are handled for C, C++ and Java.
When returning the actual values of the objects, this facility allows for the individual selection of the display format used in the result creation. It can be chosen among: binary, decimal, hexadecimal, octal and natural. Natural refers to a default format automatically chosen based on the variable type (like decimal for an int, hex for pointers, etc.).
-var-create {name | "-"} {frame-addr | "*"} expression
This operation creates a variable object, which allows the monitoring of a variable, the result of an expression, a memory cell or a CPU register.
The name parameter is the string by which the object can be referenced. It must be unique. If `-' is specified, the varobj system will generate a string "varNNNNNN" automatically. It will be unique provided that one does not specify name on that format. The command fails if a duplicate name is found.
The frame under which the expression should be evaluated can be specified by frame-addr. A `*' indicates that the current frame should be used.
expression is any expression valid on the current language set (must not begin with a `*'), or one of the following:
where addr is the address of a memory cell
a memory address range (TBD)
a CPU register name
This operation returns the name, number of children and the type of the object created. Type is returned as a string as the ones generated by the GDB CLI:
name="name",numchild="N",type="type"
-var-delete name
Deletes a previously created variable object and all of its children.
Returns an error if the object name is not found.
-var-set-format name format-spec
Sets the output format for the value of the object name to be format-spec.
The syntax for the format-spec is as follows:
format-spec ==> {binary | decimal | hexadecimal | octal | natural}
-var-show-format name
Returns the format used to display the value of the object name.
format ==> format-spec
-var-info-num-children name
Returns the number of children of a variable object name.
numchild=n
-var-list-children [ print-values ] name
Return a list of the children of the specified variable object and create variable objects for them, if they do not already exist.
With a single argument or if print-values has a value for of 0 or --no-values, print only the names of the variables; if print-values is 1 or --all-values, also print their values; and if it is 2 or --simple-values print the name and value for simple data types and just the name for arrays, structures and unions.
-var-info-type name
Returns the type of the specified variable name. The type is returned as a string in the same format as it is output by the GDB CLI.
type=typename
-var-info-expression name
Returns what is represented by the variable object name.
lang=lang-spec,exp=expression
where lang-spec is {"C" | "C++" | "Java"}.
-var-show-attributes name
List attributes of the specified variable object name.
status=attr [ ( ,attr )* ]
where attr is { { editable | noneditable } | TBD }.
-var-evaluate-expression name
Evaluates the expression that is represented by the specified variable object and returns its value as a string in the current format specified for the object.
value=value
Note that one must invoke -var-list-children for a variable before the value of a child variable can be evaluated.
-var-assign name expression
Assigns the value of expression to the variable object specified by name. The object must be `editable'. If the variable's value is altered by the assign, the variable will show up in any subsequent -var-update list.
-var-update [ print-values ] {name | "*"}
Update the value of the variable object name by evaluating its expression after fetching all the new values from memory or registers. A `*' causes all existing variable objects to be updated. The option print-values determines whether names both and values, or just names are printed in the manner described for -var-list-children (see #-var-list-children).
This section describes the GDB/MI commands that manipulate data: examine memory and registers, evaluate expressions, etc.
-data-disassemble [ -s start-addr -e end-addr ] | [ -f filename -l linenum [ -n lines ] ] -- mode
Where:
is the beginning address (or $pc)
is the end address
is the name of the file to disassemble
is the line number to disassemble around
is the the number of disassembly lines to be produced. If it is -1, the whole function will be disassembled, in case no end-addr is specified. If end-addr is specified as a non-zero value, and lines is lower than the number of disassembly lines between start-addr and end-addr, only lines lines are displayed; if lines is higher than the number of lines between start-addr and end-addr, only the lines up to end-addr are displayed.
is either 0 (meaning only disassembly) or 1 (meaning mixed source and disassembly).
The output for each instruction is composed of four fields:
Address Func-name Offset Instruction
Note that whatever included in the instruction field, is not manipulated directely by GDB/MI, i.e. it is not possible to adjust its format.
-data-evaluate-expression expr
Evaluate expr as an expression. The expression could contain an inferior function call. The function call will execute synchronously. If the expression contains spaces, it must be enclosed in double quotes.
-data-list-changed-registers
Display a list of the registers that have changed.
-data-list-register-names [ ( regno )+ ]
Show a list of register names for the current target.
If no arguments are given, it shows a list of the names of all the registers. If integer numbers are given as arguments, it will print a list of the names of the registers corresponding to the arguments. To ensure consistency between a register name and its number, the output list may include empty register names.
-data-list-register-values fmt [ ( regno )*]
Display the registers' contents. fmt is the format according to which the registers' contents are to be returned, followed by an optional list of numbers specifying the registers to display. A missing list of numbers indicates that the contents of all the registers must be returned.
Allowed formats for fmt are:
Hexadecimal
Octal
Binary
Decimal
Raw
Natural
-data-read-memory [ -o byte-offset ] address word-format word-size nr-rows nr-cols [ aschar ]
where:
An expression specifying the address of the first memory word to be read. Complex expressions containing embedded white space should be quoted using the C convention.
The format to be used to print the memory words. The notation is the same as for GDB's print command (see section #Output formats).
The size of each memory word in bytes.
The number of rows in the output table.
The number of columns in the output table.
If present, indicates that each row should include an ASCII dump. The value of aschar is used as a padding character when a byte is not a member of the printable ASCII character set (printable ASCII characters are those whose code is between 32 and 126, inclusively).
An offset to add to the address before fetching memory.
This command displays memory contents as a table of nr-rows by nr-cols words, each word being word-size bytes. In total, nr-rows * nr-cols * word-size bytes are read (returned as `total-bytes'). Should less than the requested number of bytes be returned by the target, the missing words are identified using `N/A'. The number of bytes read from the target is returned in `nr-bytes' and the starting address used to read memory in `addr'.
The address of the next/previous row or page is available in `next-row and `prev-row, `next-page and `prev-page.
-symbol-info-address symbol
Describe where symbol is stored.
-symbol-info-file
Show the file for the symbol.
-symbol-info-function
Show which function the symbol lives in.
-symbol-info-line
Show the core addresses of the code for a source line.
-symbol-info-symbol addr
Describe what symbol is at location addr.
-symbol-list-functions
List the functions in the executable.
-symbol-list-lines filename
Print the list of lines that contain code and their associated program addresses for the given source filename. The entries are sorted in ascending PC order.
-symbol-list-types
List all the type names.
-symbol-list-variables
List all the global and static variable names.
-symbol-locate
-symbol-type variable
Show type of variable.
This section describes the GDB/MI commands to specify executable file names and to read in and obtain symbol table information.
-file-exec-and-symbols file
Specify the executable file to be debugged. This file is the one from which the symbol table is also read. If no file is specified, the command clears the executable and symbol information.
If breakpoints are set when using this command with no arguments, GDB will produce error messages. Otherwise, no output is produced, except a completion notification.
-file-exec-file file
Specify the executable file to be debugged. Unlike `-file-exec-and-symbols', the symbol table is not read from this file. If used without argument, GDB clears the information about the executable file.
No output is produced, except a completion notification.
-file-list-exec-sections
List the sections of the current executable file.
-file-list-exec-source-file
List the line number, the current source file, and the absolute path to the current source file for the current executable.
-file-list-exec-source-files
List the source files for the current executable.
It will always output the filename, but only when GDB can find the absolute file name of a source file, will it output the fullname.
-file-list-shared-libraries
List the shared libraries in the program.
-file-list-symbol-files
List symbol files.
-file-symbol-file file
Read symbol table info from the specified file argument. When used without arguments, clears GDB's symbol table info.
No output is produced, except for a completion notification.
-target-attach pid | file
Attach to a process pid or a file file outside of GDB.
-target-compare-sections [ section ]
Compare data of section section on target to the exec file. Without the argument, all sections are compared.
-target-detach
Detach from the remote target which normally resumes its execution. There's no output.
-target-disconnect
Disconnect from the remote target. There's no output and the target is generally not resumed.
-target-download
Loads the executable onto the remote target.
It prints out an update message every half second, which includes the fields:
The name of the section.
The size of what has been sent so far for that section.
The size of the section.
The total size of what was sent so far (the current and the previous sections).
The size of the overall executable to download.
Each message is sent as status record (see section #Output Syntax).
In addition, it prints the name and size of the sections, as they are downloaded. These messages include the following fields:
The name of the section.
The size of the section.
The size of the overall executable to download.
At the end, a summary is printed.
-target-exec-status
Provide information on the state of the target (whether it is running or not, for instance).
-target-list-available-targets
List the possible targets to connect to.
-target-list-current-targets
Describe the current target.
-target-list-parameters
-target-select type parameters type parameters
Connect GDB to the remote target. This command takes two args:
The type of target, for instance `async', `remote', etc.
Device names, host names and the like. See section Commands for managing targets, for more details.
The output is a connection notification, followed by the address at which the target program is, in the following form:
^connected,addr="address",func="function name",args=[arg list]
-gdb-exit
Exit GDB immediately.
-exec-abort
Kill the inferior running program.
-gdb-set
Set an internal GDB variable.
-gdb-show
Show the current value of a GDB variable.
-gdb-version
Show version information for GDB. Used mostly in testing.
-interpreter-exec interpreter command
Execute the specified command in the given interpreter.
-inferior-tty-set device
Set terminal for future runs of the program being debugged.
-inferior-tty-show
Show terminal for future runs of program being debugged.