Modify char* in GDB while debugging

Viewed 42

While I debug with GDB I can print string:

x/s $r0

The output is

IDog123456

I want to change the value so when I print x/s $r0 I will see

ICat45555

I have tried to :

set $r0+1 ={int} 0x43617434 #Cat4
set $r0+5 ={int} 0x35353535 #5555

But it doesn't work , How can I do that without malloc ? only with hex string please?

1 Answers

Generally, the gdb expression parser operates similar to the current language, so, in the above, when you write:

set $r0+1 ={int} 0x43617434 #Cat4

The left hand side is an integer constant, which can't be assigned to.

Instead, you should write this as you would in C:

set *($r0+1) = (int) 0x43617434

Which should do the job.

Sometime, you might end up needing to case the pointer of the LHS too, like this:

set *((int *) ($r0+1)) = (int) 0x43617434

But I suspect in your case you'll be OK.

Related