How to modify memory contents using GDB?

后端 未结 3 782
终归单人心
终归单人心 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:34

    The easiest is setting a program variable (see GDB: assignment):

    (gdb) l
    6       {
    7           int i;
    8           struct file *f, *ftmp;
    9
    (gdb) set variable i = 10
    (gdb) p i
    $1 = 10
    

    Or you can just update arbitrary (writable) location by address:

    (gdb) set {int}0x83040 = 4
    

    There's more. Read the manual.

提交回复
热议问题