简体   繁体   中英

How to call a C++ function in GDB?

I need to call a function with a following signature in GDB:

std::string demangle(const char* name);

How can I call it in GDB?

Here is what I'm trying:

(gdb) info function demangle*
std::__cxx11::string demangle[abi:cxx11](char const*);


(gdb) call demangle[abi:cxx11]("d")
A syntax error in expression, near `:cxx11]("d")'.
(gdb) call demangle("d")
No symbol "demangle" in current context.

I'm trying with G++ 7.0, GDB 8.0

The workaround I've found is to wrap C++ function (with std::string) into a C function:

static std::string tmp_demangle_str;

const char * cdemangle(const char* name) {
    tmp_demangle_str = demangle(name);
    return tmp_demangle_str.c_str();
}

This works as expected:

(gdb) p cdemangle("d") 
$1 = 0x7ffff7dd6070 <tmp_demangle_str+16> "double"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM