3

I debug a remote Linux process with GdbServer. And I want to put a breakpoint in some function.

The problem is that this process use ASLR so each time that process load in another address. I can watch in /proc/PID/maps the base address of the process and calculate where the function is located but this is tedious.

Is there a way to put break point with GDB in address the rebase? So the GDB will automatically calculate the rebase of the process?

1 Answer 1

2

Is there a way to put break point

All the ways you can put a breakpoint in GDB are documented here.

You want something like $image_base(myprogram) + image_offset, which is not a supported address location.

What you could do is write a shell wrapper which computes the desired address and invokes GDB. Something along the lines of:

#/bin/bash

PID="$1"  # process we'll attach.
IMAGE_BASE="0x$(grep myprogram /proc/$PID/maps | sed -e 's/-.*//' -eq)"
IMAGE_OFFSET=0x1234  # use whatever offset corresponds to your function

exec gdb -p "$PID" -ex "break *($IMAGE_BASE+$IMAGE_OFFSET)" 
Sign up to request clarification or add additional context in comments.

1 Comment

Yeh ,but with ASLR . Each running I need to calculate the offset again, and if I using GSBSERVER in remote machine that complicate the debugging. Maybe is there a way to calculate that into GDBSERVER itself? Maybe with info proc mappings

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.