I am currently investigating the GDB sources. I tried to find where the transition from GDB to BFD is where the interaction with the memory to "apply" a breakpoint is. So where the place in code is where the memory is manipulated in order to set a breakpoint.
Can anyone guide me?
BFD is not involved in inserting breakpoints.
GDB has a number of mechanisms by which breakpoints can be inserted. But if we look at just memory breakpoints then you should start looking in gdb/mem-break.c.
When inserting a memory breakpoint you'll end up in memory_insert_breakpoint
, which, for most architectures will then call to default_memory_insert_breakpoint
.
This function then makes use of target_read_memory
and target_write_raw_memory
to read and write memory.
These target functions are going to do different things depending on what your target is, a native Linux target is going to use ptrace commands to poke memory, a remote target is going to send packets to the gdbserver.
You also have to consider that remote targets can support hardware breakpoints, or can also insert/remote packets using the z/Z remote protocol packets, these can all be found in gdb/remote.c, but as you specifically asked about memory breakpoints I'll not go into detail for these cases.