How to modify memory contents using GDB?

后端 未结 3 778
终归单人心
终归单人心 2020-12-04 08:12

I know that we can use several commands to access and read memory: for example, print, p, x...

But how can I change the contents of memory at any specific location (

3条回答
  •  无人及你
    2020-12-04 08:17

    Expanding on the answers provided here.

    You can just do set idx = 1 to set a variable, but that syntax is not recommended because the variable name may clash with a set sub-command. As an example set w=1 would not be valid.

    This means that you should prefer the syntax: set variable idx = 1 or set var idx = 1.

    Last but not least, you can just use your trusty old print command, since it evaluates an expression. The only difference being that he also prints the result of the expression.

    (gdb) p idx = 1
    $1 = 1
    

    You can read more about gdb here.

提交回复
热议问题