0

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?

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
Toroid
  • 117
  • 1
  • 7

1 Answers1

1

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.

Andrew
  • 3,770
  • 15
  • 22
  • thanks for the reply. That was already the direction I found. I read somewhere that BFD is used by GDB and assumed that this also is used here. Where is BFD then used by GDB? – Toroid Jan 11 '22 at 08:32
  • 1
    BFD provides the ability to open an executable file and extract section contents from it. So GDB doesn't actually care if an executable is ELF or some other format, so long as BFD can understand it, GDB can handle it. I think that's pretty much it for BFD (as far as GDB is concerned). – Andrew Jan 11 '22 at 09:33