Reputation: 79
I want to interpret a hexedecimal value during debugging as a string so that I know what is stored. I don't know what the command is for that so any help is greatly appreciated.
Consider the example
#include <stdio.h>
#include <string.h>
int main(){
char str_b[] = "Hello";
printf("%s",str_b);
return 0;
}
When I disassemble the main method I get the following
Now, how can I use gdb to interpret line 4 as a string? I tried the s
command but it did not work for me.
Upvotes: 1
Views: 910
Reputation: 69326
Well, in this particular case, those are moves of an immediate value and therefore the string is actually part of the code. Your string is split in two mov
instructions (plus one for the terminating \0
byte).
One way to (partially) see it would be x/10s 0x113d
(that 10 is just an arbitrary number here), and that would print your string in the middle of the instructions.
Another way would be to stop right after the last move and print its value from the stack, like this:
(gdb) break *0x114a
(gdb) run
Breakpoint 1, 0x000000000000114a in main ()
(gdb) ni
(gdb) x/s $rbp-0x27
0xXXXX: "Hello"
Also, from what I can see, your string in the disassembled code isn't consistent with the snippet you posted above, it's 48656c6c6f32
= Hello2
.
On the contrary, if you were to do something like:
int main(void) {
char *s = "Hello";
puts(s);
}
The string would be stored in the read only data section and you would see a load of a specific address where the string is stored, like this:
lea rdi, [<address>]
call <puts>
Allowing you to do x/s <address>
to see its content.
Upvotes: 1