Commands¶
drgn’s programmatic interface excels at complex analysis. For simpler tasks, it can be more convenient to use pre-defined commands. drgn provides a set of commands for this purpose.
In interactive mode, commands are accessed by starting a line with the %
character.
In script mode, commands can be run with drgn.commands.run_command()
.
Plugins and scripts can also register additional commands. See the commands API.
Syntax¶
Most commands use shell syntax (words split on whitespace unless quoted or escaped, etc.) and command-line options:
>>> %example --foo 'hello world'
Redirecting standard input, standard output, and standard error is supported:
>>> %example > file
>>> %example >> file
>>> %example 2> err
>>> %example < file
The output of a command can also be piped to an external command:
>>> %example | grep foo | sort -r
Word expansions (including variable expansions, wildcards, etc.) are only
supported in external commands (i.e., after the |
in a pipeline).
A few commands have their own syntax. These commands do not support redirection or pipes.
Common¶
The following commands are available when debugging any program.
sh¶
execute a shell command
Synopsis¶
sh [command]
Description¶
If command is given, run it with sh -c --
. Otherwise, run an interactive shell with sh -i
.
In either case, return the command’s exit status.
source¶
run a drgn script
Synopsis¶
source script [args …]
Description¶
This loads and runs a drgn script in the current environment. Currently defined globals are available to the script, and globals defined by the script are added to the environment.
Positional Arguments¶
- script¶
script file path
- args¶
arguments to pass to the script
Linux Kernel¶
The following commands are available when debugging the Linux kernel.