Index: breakpoint.c =================================================================== --- breakpoint.c (revision 117) +++ breakpoint.c (revision 124) @@ -246,6 +246,20 @@ Automatic usage of hardware breakpoints value); } +/* When a user inserts a breakpoint on a specific line that corresponds + to a function prologue, GDB should automatically adjust the location + to the first line past the prologue if BREAKPOINT_SKIP_PROLOGUE_P + is non-zero. */ +static int breakpoint_skip_prologue_p = 0; +static void +show_breakpoint_skip_prologue (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, _("\ +When breaking on a specific line, automatic adjustment of the breakpoint\n\ +location past the function prologue is %s.\n"), + value); +} void _initialize_breakpoint (void); @@ -5446,6 +5460,25 @@ gdb_breakpoint (char *address, char *con 0); } +/* Adjust SAL to the first instruction past the function prologue. + The end of the prologue is determined using the line table from + the debugging information. + + If SAL is already past the prologue, then do nothing. */ + +static void +skip_prologue_sal (struct symtab_and_line *sal) +{ + struct symbol *sym = find_pc_function (sal->pc); + struct symtab_and_line start_sal; + + if (sym == NULL) + return; + + start_sal = find_function_start_sal (sym, 1); + if (sal->pc < start_sal.pc) + *sal = start_sal; +} /* Helper function for break_command_1 and disassemble_command. */ @@ -5460,6 +5493,13 @@ resolve_sal_pc (struct symtab_and_line * error (_("No line %d in file \"%s\"."), sal->line, sal->symtab->filename); sal->pc = pc; + + /* If this SAL corresponds to a breakpoint inserted using + a line number, and the debugger is configured to skip + function prologues in that case, then adjust the SAL + if necessary. */ + if (sal->explicit_line && breakpoint_skip_prologue_p) + skip_prologue_sal (sal); } if (sal->section == 0 && sal->symtab != NULL) @@ -8282,6 +8322,18 @@ a warning will be emitted for such break show_automatic_hardware_breakpoints, &breakpoint_set_cmdlist, &breakpoint_show_cmdlist); - + + add_setshow_boolean_cmd ("skip-prologue", class_breakpoint, + &breakpoint_skip_prologue_p, _("\ +Set the debugger behavior when inserting a breakpoint on a specific line."), + _("\ +Show the debugger behavior when inserting a breakpoint on a specific line."), + _("\ +When inserting a breakpoint on a specific line number that corresponds\n\ +to the prologue of a function, the debugger will automatically adjust\n\ +its location to the first line past the prologue if this option is set."), + NULL, show_breakpoint_skip_prologue, + &breakpoint_set_cmdlist, &breakpoint_show_cmdlist); + automatic_hardware_breakpoints = 1; }