23.2.1 Python Commands
pythoncommand can be used to evaluate Python code.
If given an argument, the
pythoncommand will evaluate the argument as a Python command. For example:
(gdb) python print 23 23
If you do not provide an argument to
python, it will act as a multi-line command, like
define. In this case, the Python script is made up of subsequent command lines, given after the
pythoncommand. This command list is terminated using a line containing
end. For example:
(gdb) python Type python script End with a line saying just "end". >print 23 >end 23
maint set python print-stack
- By default, gdb will print a stack trace when an error occurs
in a Python script. This can be controlled using
maint set python print-stack: if
on, the default, then Python stack printing is enabled; if
off, then Python stack printing is disabled.
It is also possible to execute a Python script from the gdb interpreter:
- The script name must end with .py and gdb must be configured
to recognize the script language based on filename extension using
script-extensionsetting. See Extending GDB.
python execfile ("script-name")
- This method is based on the
execfilePython built-in function, and thus is always available.