gdb/ChangeLog * infrun.c (handle_inferior_event): Delay calling reinit_frame_cache to after calling target_mourn_inferior when target has exited or was signalled. --- gdb/infrun.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) Index: src/gdb/infrun.c =================================================================== --- src.orig/gdb/infrun.c 2007-03-18 23:22:38.000000000 +0000 +++ src/gdb/infrun.c 2007-03-19 20:36:40.000000000 +0000 @@ -1299,8 +1299,6 @@ handle_inferior_event (struct execution_ } ecs->infwait_state = infwait_normal_state; - reinit_frame_cache (); - /* If it's a new process, add it to the thread database */ ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid) @@ -1308,13 +1306,22 @@ handle_inferior_event (struct execution_ && !in_thread_list (ecs->ptid)); if (ecs->ws.kind != TARGET_WAITKIND_EXITED - && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event) + && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED) { - add_thread (ecs->ptid); + /* When the inferior exited, postpone frame related operations + until the new target state is recorded. There may be + hooks installed that may try to fetch data from the + inferior without realizing it is gone. */ + reinit_frame_cache (); + + if (ecs->new_thread_event) + { + add_thread (ecs->ptid); - ui_out_text (uiout, "[New "); - ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid)); - ui_out_text (uiout, "]\n"); + ui_out_text (uiout, "[New "); + ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid)); + ui_out_text (uiout, "]\n"); + } } switch (ecs->ws.kind) @@ -1387,6 +1394,11 @@ handle_inferior_event (struct execution_ target_mourn_inferior (); singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */ stop_print_frame = 0; + + /* Now that the target state is recorded we can safelly + do frame related operations. */ + reinit_frame_cache (); + stop_stepping (ecs); return; @@ -1404,6 +1416,10 @@ handle_inferior_event (struct execution_ may be needed. */ target_mourn_inferior (); + /* Now that the target state is recorded we can safelly + do frame related operations. */ + reinit_frame_cache (); + print_stop_reason (SIGNAL_EXITED, stop_signal); singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */ stop_stepping (ecs);