Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting strings in gdb

c++:

int main() 
    { 
    string a = "a"; 
    ... ... 
    }

when i debug in gdb:

(gdb) set var a = "ok"
Invalid cast

I run the program and pause at a break point after string a has been initialized. I'm trying to set its value, but it complains about invalid cast. What's the proper syntax for this?

like image 502
nightfire Avatar asked Nov 23 '09 00:11

nightfire


1 Answers

You can do this:

call a.assign("ok")

This way, gdb knows right away that it needs to call a function (rather than what you tried using operator=), it knows what function to call (std::string::assign), and it doesn't need to convert types at all (since there's an overload of assign which matches exactly).

like image 102
John Zwinck Avatar answered Nov 14 '22 06:11

John Zwinck