Watching the debugger

What is the debugger doing under the hood when I ask it to set a breakpoint? Let's watch how GDB is changing the machine code of a program at runtime, from within the program itself. Here's a somewhat sketchy 1 C program that prints out the first 20 bytes of its own machine code, starting at the first instruction of the main function. #include <stdio.h> int main(void) { unsigned char *addr = (void…