here is a simple code I am trying to test.
int main()
{
shared_ptr<int> pa = make_shared<int>(3);
return 0;
}
And i am using gdb to debug in VScode as followed. ( breakpoint is in return 0
)
-exec p *pa
Could not find operator*.
I think it may happen because the function operator* of shared_ptr is not defined. So I try to call the * in main *pa
before return 0
;, and it turns out work.
-exec p *pa
$1 = (std::__shared_ptr_access<int, (__gnu_cxx::_Lock_policy)2, false, false>::element_type &) @0x24354c31930: 3
I am wondering if I haven't used *, can I use it during debug. After some search, I try the following code, by instantiating the template in the beginning.
template class shared_ptr<int>;
int main()
{
shared_ptr<int> pa = make_shared<int>(3);
return 0;
}
However it still won't work, I guess it may be caused by linker? I am not so sure about compile and link. So how can I use * during debug without use it main, it would be very great if someone can explain it, thanks!
I am using x86_64-w64-mingw32 with gcc version 10.2.0, GNU gdb (GDB) 10.1, and g++ compile with args"-o", "-g", "-Wall", "-Wextra", "-static-libgcc", "-fexec-charset=GBK", "-std=c++11", "-D__USE_MINGW_ANSI_STDIO=1"