0

With GDB and Python I tried to get the char* value on x1 register

python
a= gdb.execute("x/s $x1", to_string=True)
print(a)
end

But I got 0xbb4aaa: "SomeString"

I want to get only the SomeString without the address

How can I do that directly with python GDB (without regex/split)

8
  • Try gdb.convenience_variable('x1').string(). Commented Jun 27, 2023 at 15:36
  • @ssbssa $x1 is a register ,not a variable . that doesn't work Commented Jun 27, 2023 at 15:48
  • In that case, gdb.selected_frame().read_register('x1').cast(gdb.lookup_type('char').pointer()).string(). Commented Jun 27, 2023 at 16:43
  • @ssbssa Wow that crazy command, work, so strange that there is no simple python command for that Commented Jun 27, 2023 at 16:51
  • 1
    Another alternative that's not as efficient, but is compact: a = gdb.execute('printf "%s", $x1', to_string=True) Commented Jun 27, 2023 at 19:21

1 Answer 1

-1

I had the exact same problem and was super annoyed by the output of the address. Using the method .string() worked for me:

print(a.string())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.