Problems with debugging this line : executor_codegen_->Codegen(func_module, func, mod_name);

hi all, I’m learning code using debug.

I used gdb to attach the running python process and set breakpoint at this line:

src/relay/backend/ 431

    executor_codegen_->Codegen(func_module, func, mod_name);

But when I try to step into this function, I failed. It just skipped, could anyone give some help? I have post my debugging log below. You can see line 431 was skipped. Is there anything wrong? Thank you!

(gdb) b src/relay/backend/                               
Breakpoint 1 at 0x7fa418bd75d1: file /root/codes/tvm/src/relay/backend/, line 431.                                                        
(gdb) c                                                                                                                                                  
Thread 1 "python" hit Breakpoint 1, tvm::relay::backend::RelayBuildModule::BuildRelay (                                                                  
    this=0x1ea5830, relay_module=..., mod_name=...)                                                                                                      
    at /root/codes/tvm/src/relay/backend/                                                                                             
warning: Source file is more recent than executable.                                                                                                     
431         executor_codegen_->Codegen(func_module, func, mod_name);                                                                                     
(gdb) s                                                                                                                                                  
std::unique_ptr<tvm::relay::backend::ExecutorCodegen, std::default_delete<tvm::relay::backend::ExecutorCodegen> >::operator-> 
        (this=0x1fe52f0) at /usr/include/c++/9/bits/unique_ptr.h:352                                                                                                                        
352           operator->() const noexcept                                                                                                                
(gdb) s                               
355             return get();                                                                                                                            
(gdb) s                                                                                                                                                  
std::unique_ptr<tvm::relay::backend::ExecutorCodegen, std::default_delete<tvm::relay::backend::ExecutorCodegen> >::get (this=0x1ea5980) 
        at /usr/include/c++/9/bits/unique_ptr.h:360            
360           get() const noexcept                                                                                                                       
(gdb) fin                                                                                                                                                
Run till exit from #0  std::unique_ptr<tvm::relay::backend::ExecutorCodegen, std::default_delete<tvm::relay::backend::ExecutorCodegen> >::get (this=0x1ea5980) at /usr/include/c++/9/bits/unique_ptr.h:360                           
std::unique_ptr<tvm::relay::backend::ExecutorCodegen, std::default_delete<tvm::relay::backend::ExecutorCodegen> >::operator-> 
    (this=0x1ea58c0) at /usr/include/c++/9/bits/unique_ptr.h:356                                                                                                                        
356           }                            
Value returned is $1 = (tvm::relay::backend::ExecutorCodegen *) 0x1fe52f0                                                                                
(gdb) s                               
tvm::runtime::String::String (this=0x1ea58c0, other=...)                                                                                                 
    at /root/codes/tvm/include/tvm/runtime/container/string.h:256                                                                                        
256       TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(String, ObjectRef, StringObj);                                                                       
(gdb) s                               
tvm::runtime::ObjectRef::ObjectRef (this=0x1ea58c0)                         
    at /root/codes/tvm/include/tvm/runtime/object.h:511                                                                                                  
    511     class ObjectRef {             
(gdb) s                               
tvm::runtime::ObjectPtr<tvm::runtime::Object>::ObjectPtr (this=0x1ea58c0, other=...)                                                                     
    at /root/codes/tvm/include/tvm/runtime/object.h:368                                                                                                  
    368       ObjectPtr(const ObjectPtr<T>& other)  // NOLINT(*)                                                                                             
(gdb) s                               
369           : ObjectPtr(other.data_) {}                                   (gdb) s                               
tvm::runtime::ObjectPtr<tvm::runtime::Object>::ObjectPtr (this=0x1ea58c0, data=0x7fffac08fe30)                                                           
    at /root/codes/tvm/include/tvm/runtime/object.h:475                                                                                                  
475       explicit ObjectPtr(Object* data) : data_(data) {                                                                                               
(gdb) s                               
476         if (data != nullptr) {                                          
(gdb) s                                                                     
477           data_->IncRef();                                                                                                                           
(gdb) p data                                                                                                                                             
$2 = (tvm::runtime::Object *) 0x190db90                                                                                                                  
(gdb) s                                                                                                                                                  
tvm::runtime::Object::IncRef (this=0x7fa418be28a0 <std::__get_helper<0ul, tvm::relay::backend::ExecutorCodegen*, 
              std::default_delete<tvm::relay::backend::ExecutorCodegen> >(std::_Tuple_impl<0ul, tvm::relay::backend::ExecutorCodegen*, 
              std::default_delete<tvm::relay::backend::ExecutorCodegen> > const&)+28>)                          
    at /root/codes/tvm/include/tvm/runtime/object.h:799                                                                                                  
799     inline void Object::IncRef() { ref_counter_.fetch_add(1, std::memory_order_relaxed); }                                                           
(gdb) s                                                                                                                                                  
std::__atomic_base<int>::fetch_add (__m=std::memory_order_relaxed, __i=1, this=0x190db94)                                                                
    at /usr/include/c++/9/bits/atomic_base.h:541                                                                                                         
541           { return __atomic_fetch_add(&_M_i, __i, int(__m)); }                                                                                       
(gdb) fin                                                                                                                                                
Run till exit from #0  std::__atomic_base<int>::fetch_add (__m=std::memory_order_relaxed, __i=1,                                                         
    this=0x190db94) at /usr/include/c++/9/bits/atomic_base.h:541                                                                                         
tvm::runtime::Object::IncRef (this=0x190db90) at /root/codes/tvm/include/tvm/runtime/object.h:799                                                        
799     inline void Object::IncRef() { ref_counter_.fetch_add(1, std::memory_order_relaxed); }                                                           
(gdb) n                               
tvm::runtime::ObjectPtr<tvm::runtime::Object>::ObjectPtr (this=0x7fffac08ff40, data=0x190db90)                                                           
    at /root/codes/tvm/include/tvm/runtime/object.h:479                                                                                                  
479       }                                                                                                                                              
(gdb) n                               
tvm::runtime::ObjectPtr<tvm::runtime::Object>::ObjectPtr (this=0x7fffac08ff40, other=...)                                                                
    at /root/codes/tvm/include/tvm/runtime/object.h:369                                                                                                  
369           : ObjectPtr(other.data_) {}                                                                                                                
(gdb) n                                                                     
tvm::relay::backend::RelayBuildModule::BuildRelay (this=0x1ea5830, relay_module=..., mod_name=...)                                                       
    at /root/codes/tvm/src/relay/backend/                                                                                             
432         executor_codegen_->UpdateOutput(&ret_);

The easiest way to step into the Codegen function in that case is to add break Codegen once you stop at line 431. GDB automatically sets breakpoints into all functions named Codegen. Then just by running continue as many times as needed, we would eventually reach that function.

The problem you’re seeing is that gdb steps into each copy/move constructor and other such functions for each argument in Codegen, so in order to use step to enter the function, you first need to step and finish for a few times for each intermediate function until you reach Codegen. Since this is not easy or straight forward, the above method I mentioned is what I normally find easier.

Indeed I tried this way, you can see it in my log above. It still skipped. Finally I used ffi_navigator to find the function really called and directly add breakpoint at this function.