简体   繁体   中英

How can I set std::map variable with gdb?

#include<map>
#include<iostream>
using std::map;
using std::cout;
int main(int argc,char* argv[])
{
    map<int,int> kv({{1,1},{2,2},{3,3}});
    kv[1]=2;
    cout<<kv[1];
    return 0;
}

I start it from GDB and break at kv[1]=2 . After kv[1]=2 was executed, I want to set kv[1]=3 in GDB. How can I do it?

You can use GDB set command to set the value

GDB Mode modifying_command : set [ variable ] expression

The following example shows how to deposit the value 5 into the data member of a C++ variable: GDB Mode

(idb) print kv[1]

(idb) set variable {int}0x82040 = 5  //82040 is memory address

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