samedi 25 février 2017

Calling std::~basic_string() in gdb

As per @EvanED in http://ift.tt/2lWvdas I created a gdb command newstr to create a new std::string and put it in a gdb convenience variable:

define newstr
set ($arg0)=(std::string*)malloc(sizeof(std::string))
call ($arg0)->basic_string()
# 'assign' returns *this; casting return to void avoids printing of the struct.
call (void)( ($arg0)->assign($arg1) )
end

It works great:

(gdb) newstr $foo "hello world"
(gdb) p $foo->c_str()
$57 = 0xb22e388 "hello world"

I use newstr in other custom gdb commands, so for tidyness I also created delstr:

define delstr
call ($arg0)->~basic_string($arg0)
call free($arg0)
set ($arg0)=(void*)0
end

It works, but the destructor call produces an annoying message:

(gdb) delstr $foo
warning: Using non-standard conversion to match method std::string::~basic_string to supplied arguments
$62 = 0

Can I avoid the "non-standard conversion" message? (I'm using gdb 7.10.)

Aucun commentaire:

Enregistrer un commentaire