How GDB implements break command

When you want to add a breakpoint, you usually use the command "break". GDB will first parse the command, and find the address, as described here. But what's the next?

GDB will create a breakpoint after it parses the command and finds the address and the symbol table . The breakpoint is represented by the type struct breakpoint (see create_breakpoint). At this point, GDB only creates the structure and adds it to the collection of breakpoints. It does not really insert them. The insertion only occurs before the inferior starts to run. For example, when the function proceed is called, which will make the inferior run, it will call insert_breakpoints to insert the breakpoints in the collection of breakpoints.
When a breakpoint is hit, a trap, a signal or whatever will cause the inferior to stop. At this point, GDB will take over of it and handle the event first. It calls the function handle_inferior_event. It will check the reason why the inferior stops. And it will detect whether there is a breakpoint hit. Remember you can add conditions to breakpoints. If the conditions is false, even if there is a breakpoint hit, GDB won't do anything. GDB stops the inferior only when a breakpoint is hit and the conditions are true.
Facebooktwitterredditlinkedintumblr

Leave a comment

Your email address will not be published. Required fields are marked *