setting strings in gdb
Asked Answered
N

1

9

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?

Nonaligned answered 23/11, 2009 at 0:18 Comment(3)
"setting" a string is a complex operation not necessarily supported by gdb.Winniewinnifred
ok... so you can set int variables using gdb, but not strings? I'm confused because setting strings doesn't seem much more complex than setting ints, and i know that this works: int main() { int b = 9; } (gdb) set var b = 8 // doesn't complain "setting" is the correct term for what i'm trying to do, right?Nonaligned
"setting strings doesn't seem much more complex than setting ints" - well, it is.Cowart
C
19

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).

Cowart answered 23/11, 2009 at 0:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.