Hi all,
I’ve created a small gdb extension to find types and access attributes of the Object
and ObjectRef
subclasses.
What I mean by that is, say there is an AddNode
passed to a function as a PrimExpr
and while debugging this function, there is no easy way to find that it actually belongs to an AddNode
. Trying whatis object
or ptype object
just prints that it’s a PrimExpr
.
I found a rather hacky way to do this by accessing the deleter_
member of the enclosing object and the template argument to the Handler contains the proper type (a sample output for AddNode
is as shown below:)
$65 = (tvm::runtime::Object::FDeleter) 0x7fffaf6c9300 <tvm::runtime::SimpleObjAllocator::Handler<tvm::tir::AddNode>::Deleter_(tvm::runtime::Object*)>
I created a separate post asking if there’s a better way to find the types of an object, and if I find any answers I’ll update my extension.
Anyway, I took this hack to find the type and created a small extension that I’ve pushed to https://github.com/anirudhsundar/tvm-gdb-commands.
It provides 4 new commands (all with tvm_*
prefix),
tvm_dump
- just saves from typing print tvm::Dump(...)
tvm_type
- extracts the type from the deleter_
handler, and prints it out
tvm_attr
- Uses tvm_type
to allow us to recursively access attributes of a tvm object
For example
(gdb) tvm_attr for_node.body.seq[0].body.then_case
access string '((tvm::tir::IfThenElseNode*)((tvm::tir::ForNode*)((tvm::tir::SeqStmtNode*)((tvm::tir::ForNode*)for_node).body).seq[0]).body).then_case'
Type of object: 'tvm::tir::StoreNode'
Cb[(((j.outer*64) + (i*n)) + j.inner.s)] = 0h
prints out the then_case
member of the if condition present in that for body
.
tvm_fields - prints out the attributes/fields available for a given object expression. For example,
(gdb) tvm_fields for_node.body.seq[0].body
tvm::tir::StmtNode condition then_case else_case _type_key _type_final _type_child_slots
prints out the list of fields of the IfThenElseNode
, from which we can find that there are attributes like then_case
and else_case
Do let me know if there are better ways to do what I’m doing, and be as brutal as needed with the feedback.
Thanks, Anirudh
Edit: Just a quick update, I had to refactor my git history due to a small mistake, so if you need to pull new changes, you might have to pull with git pull --force
to force update history beyond fast-forward