Index: infrun.c =================================================================== RCS file: /cvs/src/src/gdb/infrun.c,v retrieving revision 1.208 diff -u -a -u -r1.208 infrun.c --- infrun.c 17 Dec 2005 22:34:01 -0000 1.208 +++ infrun.c 4 Jan 2006 04:40:11 -0000 @@ -943,6 +943,7 @@ static void step_into_function (struct execution_control_state *ecs); static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame); +static void insert_step_resume_breakpoint_at_caller (struct frame_info *step_frame); static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal, struct frame_id sr_id); static void stop_stepping (struct execution_control_state *ecs); @@ -2390,7 +2391,8 @@ /* We're doing a "next", set a breakpoint at callee's return address (the address at which the caller will resume). */ - insert_step_resume_breakpoint_at_frame (get_prev_frame (get_current_frame ())); + + insert_step_resume_breakpoint_at_caller ( get_current_frame ()); keep_going (ecs); return; } @@ -2453,7 +2455,7 @@ /* Set a breakpoint at callee's return address (the address at which the caller will resume). */ - insert_step_resume_breakpoint_at_frame (get_prev_frame (get_current_frame ())); + insert_step_resume_breakpoint_at_caller ( get_current_frame ()); keep_going (ecs); return; } @@ -2522,7 +2524,7 @@ { /* Set a breakpoint at callee's return address (the address at which the caller will resume). */ - insert_step_resume_breakpoint_at_frame (get_prev_frame (get_current_frame ())); + insert_step_resume_breakpoint_at_caller ( get_current_frame ()); keep_going (ecs); return; } @@ -2757,6 +2759,30 @@ insert_step_resume_breakpoint_at_sal (sr_sal, get_frame_id (return_frame)); } +/* Insert a step resume breakpoint at the return address of the + caller. This is to ensure that on doing a next from before main completes + execution of the program without GDB dumping core. Look at PR 1971 + for more details. */ + +static void +insert_step_resume_breakpoint_at_caller (struct frame_info *return_frame) +{ + if (get_prev_frame (return_frame)) + { + insert_step_resume_breakpoint_at_frame (get_prev_frame (return_frame)); + } + else + { + struct symtab_and_line sr_sal; + init_sal (&sr_sal); /* initialize to zeros */ + sr_sal.pc = ADDR_BITS_REMOVE (frame_pc_unwind (return_frame)); + sr_sal.section = find_pc_overlay (sr_sal.pc); + insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); + } + +} + + static void stop_stepping (struct execution_control_state *ecs) {