This extension adds 4 new commands to gdb that improve the experience of debugging the Apache TVM code. The commands are explained below with examples.
-
Run the below command
bash < <(curl -s https://raw.githubusercontent.com/anirudhsundar/tvm-gdb-commands/master/install.sh)
-
Alternatively, download the
commands.pyto some location and source thecommands.pyfile, either directly in your gdb session or add the below line to your.gdbinit:source /path/to/commands.py
-
tvm_dump/tvdCalls
p tvm::Dump(<value>)for a given valuetvdis an alias totvm_dumpEg:
(gdb) tvd index (((j.outer*64) + (i*n)) + j.inner) -
tvm_type/tvtPrints the original object type of a given value. When a function gets a
PrimExpras argument, this commands prints which sub-class ofPrimExprthe given value is. This is in same spirit to whatis command in gdbtvtis an alias totvm_typeFor example,
AddNodecould be the underlying original type of the object, declared using it's parentPrimExprNodeUsage:
(gdb) whatis index type = tvm::PrimExpr (gdb) tvt index tvm::tir::AddNode
-
tvm_attr/tvatThis commmand extends the use of
tvm_typeand tries to access the underlying attributes/members of the original object.tvatis an alias totvm_attrFor example, AddNode has the members
aandb, so this allows us to access those members.This prints out 3 lines, where the first line shows the access string used to access the member, second line shows the type of the object, and the last line prints a dump of the object
(gdb) tvat index.a access string '((tvm::tir::AddNode*)index).a' Type of object: 'tvm::tir::AddNode' ((j.outer*64) + (i*n))
This command can also take attributes recursively For example:
(gdb) tvat index.a.a.b access string '((tvm::tir::MulNode*)((tvm::tir::AddNode*)((tvm::tir::AddNode*)index).a).a).b' Type of object: 'tvm::IntImmNode' 64
-
tvm_fields/tvfThis command prints the list of fields available in the given object/object.attributes. This can be called with either a single object, or the object.attr.attr syntax
tvfis an alias totvm_fieldsNote: The fields can also be directly found by completion when using the
tvm_attrcommand, but there are some gotchas in that method, especially when trying completion more than once, so this command was written to help with that.For example:
(gdb) tvf index.a.a tvm::PrimExprNode a b _type_final _type_child_slots
-
There are 4 aliases (as shown below) defined in the code and if you wish to remove them in favor of others one might like, please comment out the last 4 lines in
commands.pyalias tvd = tvm_dump alias tvt = tvm_type alias tvat = tvm_attr alias tvf = tvm_fields
The .vscode/launch.json configuration enables hybrid debugging of TVM's Python frontend (Python debugger) and C++ backend (GDB) in VSCode.
Before using this configuration to debug TVM, we should install the following extensions for VSCode:
- Python Debugger: Search
ms-python.debugpyin VSCode extension marketplace. - C/C++: Search
ms-vscode.cpptoolsin VSCode extension marketplace. - Python C++ Debugger: Search
benjamin-simmonds.pythoncpp-debugin VSCode extension marketplace.
After installing the extensions, we should copy the .vscode/launch.json file to the root directory of your own TVM project. And the next steps will explain some details that you should modify in the launch.json file.
The current configuration supports two debugging modes:
- Hybrid Python Frontend + C++ Backend Debugging for TVM
- Pure C++ Backend Debugging for TVM
As the fowllowing image shows, we can choose the debugging mode in graphical interface. Ther are four choices:
Full Auto Debug (Python+C++)is the entry for Hybrid Python Frontend + C++ Backend Debugging.Python: TVM Frontendis responsible for the debugging of the Python Frontend.C++: TVM Backendis responsible for the debugging of the C++ Backend.
Pure C++ Debug (C++)is the entry for Pure C++ Backend Debugging.
This is a hybrid debugging approach, and requires users to first launch the Python script, after which the C++ process will be automatically attached.
Important
Customize the "program" entry in .vscode/launch.json to point to your Python virtual environment executable. Example path:
"program": "/home/user/miniconda3/envs/tvm-build-venv/bin/python3"
Commands that interact with the Debug Console should be preceded by -exec, example:
-exec p pcor-exec call tvm::Dump(mod)
Example:
This is a pure C++ debugging approach, where users can debug C++ components without Python scripts.
Important
Customize the "program" entry in .vscode/launch.json to your C++ executable path.
Example path:
"program": "${workspaceFolder}/get_started/tutorials/a.out"
Example:
You can also check .vscode/launch.json for debugging mode details - we've added extensive comments there.
Always welcome.
Thanks to Lunderberg for valuable feedback and whose tvm-gdb-extension was the inspiration to create this one


