From: Pedro Alves Date: Mon, 4 Sep 2017 16:10:13 +0000 (+0100) Subject: Kill init_sal X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=51abb421302bdd86946827727aebc878b5c756e3;p=binutils-gdb.git Kill init_sal Instead, make symtab_and_line initialize its members itself. Many symtab_and_line declarations are moved to where the object is initialized at the same time both for clarity and to avoid double initialization. A few functions, like e.g., find_frame_sal are adjusted to return the sal using normal function return instead of an output parameter likewise to avoid having to default-construct a sal and then immediately have the object overwritten. gdb/ChangeLog: 2017-09-04 Pedro Alves * ada-lang.c (is_known_support_routine): Move sal declaration to where it is initialized. * breakpoint.c (create_internal_breakpoint, init_catchpoint) (parse_breakpoint_sals, decode_static_tracepoint_spec) (clear_command, update_static_tracepoint): Remove init_sal references. Move declarations closer to initializations. * cli/cli-cmds.c (list_command): Move sal declarations closer to initializations. * elfread.c (elf_gnu_ifunc_resolver_stop): Remove init_sal references. Move sal declarations closer to initializations. * frame.c (find_frame_sal): Return a symtab_and_line via function return instead of output parameter. Remove init_sal references. * frame.h (find_frame_sal): Return a symtab_and_line via function return instead of output parameter. * guile/scm-frame.c (gdbscm_frame_sal): Adjust. * guile/scm-symtab.c (stscm_make_sal_smob): Use in-place new instead of memset. (gdbscm_find_pc_line): Remove init_sal reference. * infcall.c (call_function_by_hand_dummy): Remove init_sal references. Move declarations closer to initializations. * infcmd.c (set_step_frame): Update. Move declarations closer to initializations. (finish_backward): Remove init_sal references. Move declarations closer to initializations. * infrun.c (process_event_stop_test, handle_step_into_function) (insert_hp_step_resume_breakpoint_at_frame) (insert_step_resume_breakpoint_at_caller): Likewise. * linespec.c (create_sals_line_offset, decode_digits_ordinary) (symbol_to_sal): Likewise. * probe.c (parse_probes_in_pspace): Remove init_sal reference. * python/py-frame.c (frapy_find_sal): Move sal declaration closer to its initialization. * reverse.c (save_bookmark_command): Use new/delete. Remove init_sal references. Move declarations closer to initializations. * source.c (get_current_source_symtab_and_line): Remove brace initialization. (set_current_source_symtab_and_line): Now takes the sal by const reference. Remove brace initialization. (line_info): Remove init_sal reference. * source.h (set_current_source_symtab_and_line): Now takes a symtab_and_line via const reference. * stack.c (set_current_sal_from_frame): Adjust. (print_frame_info): Adjust. (get_last_displayed_sal): Return the sal via function return instead of via output parameter. Simplify. (frame_info): Adjust. * stack.h (get_last_displayed_sal): Return the sal via function return instead of via output parameter. * symtab.c (init_sal): Delete. (find_pc_sect_line): Remove init_sal references. Move declarations closer to initializations. (find_function_start_sal): Remove init_sal references. Move declarations closer to initializations. * symtab.h (struct symtab_and_line): In-class initialize all fields. * tracepoint.c (set_traceframe_context) (print_one_static_tracepoint_marker): Remove init_sal references. Move declarations closer to initializations. * tui/tui-disasm.c (tui_show_disassem_and_update_source): Adjust. * tui/tui-stack.c (tui_show_frame_info): Adjust. Move declarations closer to initializations. * tui/tui-winsource.c (tui_update_source_window_as_is): Remove init_sal references. Adjust. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1fbceff98ea..6b4000b044a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,69 @@ +2017-09-04 Pedro Alves + + * ada-lang.c (is_known_support_routine): Move sal declaration to + where it is initialized. + * breakpoint.c (create_internal_breakpoint, init_catchpoint) + (parse_breakpoint_sals, decode_static_tracepoint_spec) + (clear_command, update_static_tracepoint): Remove init_sal + references. Move declarations closer to initializations. + * cli/cli-cmds.c (list_command): Move sal declarations closer to + initializations. + * elfread.c (elf_gnu_ifunc_resolver_stop): Remove init_sal + references. Move sal declarations closer to initializations. + * frame.c (find_frame_sal): Return a symtab_and_line via function + return instead of output parameter. Remove init_sal references. + * frame.h (find_frame_sal): Return a symtab_and_line via function + return instead of output parameter. + * guile/scm-frame.c (gdbscm_frame_sal): Adjust. + * guile/scm-symtab.c (stscm_make_sal_smob): Use in-place new + instead of memset. + (gdbscm_find_pc_line): Remove init_sal reference. + * infcall.c (call_function_by_hand_dummy): Remove init_sal + references. Move declarations closer to initializations. + * infcmd.c (set_step_frame): Update. Move declarations closer to + initializations. + (finish_backward): Remove init_sal references. Move declarations + closer to initializations. + * infrun.c (process_event_stop_test, handle_step_into_function) + (insert_hp_step_resume_breakpoint_at_frame) + (insert_step_resume_breakpoint_at_caller): Likewise. + * linespec.c (create_sals_line_offset, decode_digits_ordinary) + (symbol_to_sal): Likewise. + * probe.c (parse_probes_in_pspace): Remove init_sal reference. + * python/py-frame.c (frapy_find_sal): Move sal declaration closer + to its initialization. + * reverse.c (save_bookmark_command): Use new/delete. Remove + init_sal references. Move declarations closer to initializations. + * source.c (get_current_source_symtab_and_line): Remove brace + initialization. + (set_current_source_symtab_and_line): Now takes the sal by const + reference. Remove brace initialization. + (line_info): Remove init_sal reference. + * source.h (set_current_source_symtab_and_line): Now takes a + symtab_and_line via const reference. + * stack.c (set_current_sal_from_frame): Adjust. + (print_frame_info): Adjust. + (get_last_displayed_sal): Return the sal via function return + instead of via output parameter. Simplify. + (frame_info): Adjust. + * stack.h (get_last_displayed_sal): Return the sal via function + return instead of via output parameter. + * symtab.c (init_sal): Delete. + (find_pc_sect_line): Remove init_sal references. Move + declarations closer to initializations. + (find_function_start_sal): Remove init_sal references. Move + declarations closer to initializations. + * symtab.h (struct symtab_and_line): In-class initialize all + fields. + * tracepoint.c (set_traceframe_context) + (print_one_static_tracepoint_marker): Remove init_sal references. + Move declarations closer to initializations. + * tui/tui-disasm.c (tui_show_disassem_and_update_source): Adjust. + * tui/tui-stack.c (tui_show_frame_info): Adjust. Move + declarations closer to initializations. + * tui/tui-winsource.c (tui_update_source_window_as_is): Remove + init_sal references. Adjust. + 2017-09-04 Pedro Alves * ax-gdb.c (agent_command_1): Use range-for. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index cbb846c9e59..b4e193ca802 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -11980,7 +11980,6 @@ ada_exception_support_info_sniffer (void) static int is_known_support_routine (struct frame_info *frame) { - struct symtab_and_line sal; char *func_name; enum language func_lang; int i; @@ -11989,7 +11988,7 @@ is_known_support_routine (struct frame_info *frame) /* If this code does not have any debugging information (no symtab), This cannot be any user code. */ - find_frame_sal (frame, &sal); + symtab_and_line sal = find_frame_sal (frame); if (sal.symtab == NULL) return 1; diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index eeaf02716a2..778a011161f 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -3358,16 +3358,12 @@ create_internal_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address, enum bptype type, const struct breakpoint_ops *ops) { - struct symtab_and_line sal; - struct breakpoint *b; - - init_sal (&sal); /* Initialize to zeroes. */ - + symtab_and_line sal; sal.pc = address; sal.section = find_pc_overlay (sal.pc); sal.pspace = current_program_space; - b = set_raw_breakpoint (gdbarch, sal, type, ops); + breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); b->number = internal_breakpoint_number--; b->disposition = disp_donttouch; @@ -8525,9 +8521,7 @@ init_catchpoint (struct breakpoint *b, const char *cond_string, const struct breakpoint_ops *ops) { - struct symtab_and_line sal; - - init_sal (&sal); + symtab_and_line sal; sal.pspace = current_program_space; init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); @@ -9379,18 +9373,14 @@ parse_breakpoint_sals (const struct event_location *location, breakpoint address. */ if (last_displayed_sal_is_valid ()) { - struct symtab_and_line sal; - CORE_ADDR pc; - - init_sal (&sal); /* Initialize to zeroes. */ - /* Set sal's pspace, pc, symtab, and line to the values corresponding to the last call to print_frame_info. Be sure to reinitialize LINE with NOTCURRENT == 0 as the breakpoint line number is inappropriate otherwise. find_pc_line would adjust PC, re-set it back. */ - get_last_displayed_sal (&sal); - pc = sal.pc; + symtab_and_line sal = get_last_displayed_sal (); + CORE_ADDR pc = sal.pc; + sal = find_pc_line (pc, 0); /* "break" without arguments is equivalent to "break *PC" @@ -9600,10 +9590,7 @@ decode_static_tracepoint_spec (const char **arg_p) marker = VEC_index (static_tracepoint_marker_p, markers, i); - symtab_and_line sal; - init_sal (&sal); - - sal = find_pc_line (marker->address, 0); + symtab_and_line sal = find_pc_line (marker->address, 0); sal.pc = marker->address; sals.push_back (sal); @@ -11799,12 +11786,10 @@ clear_command (char *arg, int from_tty) } else { - init_sal (&last_sal); /* Initialize to zeroes. */ - /* Set sal's line, symtab, pc, and pspace to the values corresponding to the last call to print_frame_info. If the codepoint is not valid, this will set all the fields to 0. */ - get_last_displayed_sal (&last_sal); + last_sal = get_last_displayed_sal (); if (last_sal.symtab == 0) error (_("No source file specified.")); @@ -13883,7 +13868,6 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) if (!VEC_empty(static_tracepoint_marker_p, markers)) { - struct symtab_and_line sal2; struct symbol *sym; struct static_tracepoint_marker *tpmarker; struct ui_out *uiout = current_uiout; @@ -13898,11 +13882,7 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) "found at previous line number"), b->number, tp->static_trace_marker_id); - init_sal (&sal2); - - sal2.pc = tpmarker->address; - - sal2 = find_pc_line (tpmarker->address, 0); + symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); sym = find_pc_sect_function (tpmarker->address, NULL); uiout->text ("Now in "); if (sym) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index dfff87c537a..7d7e16a64a8 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -886,9 +886,6 @@ edit_command (char *arg, int from_tty) static void list_command (char *arg, int from_tty) { - struct symtab_and_line sal = { 0 }; - struct symtab_and_line sal_end = { 0 }; - struct symtab_and_line cursal = { 0 }; struct symbol *sym; char *arg1; int no_end = 1; @@ -901,7 +898,7 @@ list_command (char *arg, int from_tty) if (arg == NULL || ((arg[0] == '+' || arg[0] == '-') && arg[1] == '\0')) { set_default_source_symtab_and_line (); - cursal = get_current_source_symtab_and_line (); + symtab_and_line cursal = get_current_source_symtab_and_line (); /* If this is the first "list" since we've set the current source line, center the listing around that line. */ @@ -954,6 +951,7 @@ list_command (char *arg, int from_tty) error (_("No symbol table is loaded. Use the \"file\" command.")); std::vector sals; + symtab_and_line sal, sal_end; arg1 = arg; if (*arg1 == ',') diff --git a/gdb/elfread.c b/gdb/elfread.c index ddff16b5ef3..cad7aa8647f 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -917,12 +917,10 @@ elf_gnu_ifunc_resolver_stop (struct breakpoint *b) if (b_return == b) { - struct symtab_and_line sal; - /* No need to call find_pc_line for symbols resolving as this is only a helper breakpointer never shown to the user. */ - init_sal (&sal); + symtab_and_line sal; sal.pspace = current_inferior ()->pspace; sal.pc = prev_pc; sal.section = find_pc_overlay (sal.pc); diff --git a/gdb/frame.c b/gdb/frame.c index 30e4aeab7e2..55d4ddb396f 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -2506,8 +2506,8 @@ get_frame_address_in_block_if_available (struct frame_info *this_frame, return 1; } -void -find_frame_sal (struct frame_info *frame, struct symtab_and_line *sal) +symtab_and_line +find_frame_sal (frame_info *frame) { struct frame_info *next_frame; int notcurrent; @@ -2528,21 +2528,21 @@ find_frame_sal (struct frame_info *frame, struct symtab_and_line *sal) /* If frame is inline, it certainly has symbols. */ gdb_assert (sym); - init_sal (sal); + + symtab_and_line sal; if (SYMBOL_LINE (sym) != 0) { - sal->symtab = symbol_symtab (sym); - sal->line = SYMBOL_LINE (sym); + sal.symtab = symbol_symtab (sym); + sal.line = SYMBOL_LINE (sym); } else /* If the symbol does not have a location, we don't know where the call site is. Do not pretend to. This is jarring, but we can't do much better. */ - sal->pc = get_frame_pc (frame); + sal.pc = get_frame_pc (frame); - sal->pspace = get_frame_program_space (frame); - - return; + sal.pspace = get_frame_program_space (frame); + return sal; } /* If FRAME is not the innermost frame, that normally means that @@ -2555,13 +2555,10 @@ find_frame_sal (struct frame_info *frame, struct symtab_and_line *sal) instruction/line, consequently, for such cases, want to get the line containing fi->pc. */ if (!get_frame_pc_if_available (frame, &pc)) - { - init_sal (sal); - return; - } + return {}; notcurrent = (pc != get_frame_address_in_block (frame)); - (*sal) = find_pc_line (pc, notcurrent); + return find_pc_line (pc, notcurrent); } /* Per "frame.h", return the ``address'' of the frame. Code should diff --git a/gdb/frame.h b/gdb/frame.h index f3485af925a..3b00d362d97 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -408,8 +408,7 @@ extern int get_frame_func_if_available (struct frame_info *fi, CORE_ADDR *); find_frame_symtab(), find_frame_function(). Each will need to be carefully considered to determine if the real intent was for it to apply to the PC or the adjusted PC. */ -extern void find_frame_sal (struct frame_info *frame, - struct symtab_and_line *sal); +extern symtab_and_line find_frame_sal (frame_info *frame); /* Set the current source and line to the location given by frame FRAME, if possible. */ diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c index 994f92d41c8..b2af7432a63 100644 --- a/gdb/guile/scm-frame.c +++ b/gdb/guile/scm-frame.c @@ -761,7 +761,7 @@ gdbscm_frame_sal (SCM self) { frame = frscm_frame_smob_to_frame (f_smob); if (frame != NULL) - find_frame_sal (frame, &sal); + sal = find_frame_sal (frame); } CATCH (except, RETURN_MASK_ALL) { diff --git a/gdb/guile/scm-symtab.c b/gdb/guile/scm-symtab.c index 925ab39573e..755ea672472 100644 --- a/gdb/guile/scm-symtab.c +++ b/gdb/guile/scm-symtab.c @@ -419,7 +419,7 @@ stscm_make_sal_smob (void) SCM s_scm; s_smob->symtab_scm = SCM_BOOL_F; - memset (&s_smob->sal, 0, sizeof (s_smob->sal)); + new (&s_smob->sal) symtab_and_line (); s_scm = scm_new_smob (sal_smob_tag, (scm_t_bits) s_smob); gdbscm_init_gsmob (&s_smob->base); @@ -589,9 +589,7 @@ static SCM gdbscm_find_pc_line (SCM pc_scm) { ULONGEST pc_ull; - struct symtab_and_line sal; - - init_sal (&sal); /* -Wall */ + symtab_and_line sal; gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, NULL, "U", pc_scm, &pc_ull); diff --git a/gdb/infcall.c b/gdb/infcall.c index 38335a79962..9e434a9df41 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -1051,17 +1051,16 @@ call_function_by_hand_dummy (struct value *function, inferior. That way it breaks when it returns. */ { - struct breakpoint *bpt, *longjmp_b; - struct symtab_and_line sal; - - init_sal (&sal); /* initialize to zeroes */ + symtab_and_line sal; sal.pspace = current_program_space; sal.pc = bp_addr; sal.section = find_pc_overlay (sal.pc); + /* Sanity. The exact same SP value is returned by PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by dummy_id to form the frame ID's stack address. */ - bpt = set_momentary_breakpoint (gdbarch, sal, dummy_id, bp_call_dummy); + breakpoint *bpt = set_momentary_breakpoint (gdbarch, sal, + dummy_id, bp_call_dummy); /* set_momentary_breakpoint invalidates FRAME. */ frame = NULL; @@ -1069,7 +1068,7 @@ call_function_by_hand_dummy (struct value *function, bpt->disposition = disp_del; gdb_assert (bpt->related_breakpoint == bpt); - longjmp_b = set_longjmp_breakpoint_for_call_dummy (); + breakpoint *longjmp_b = set_longjmp_breakpoint_for_call_dummy (); if (longjmp_b) { /* Link BPT into the chain of LONGJMP_B. */ diff --git a/gdb/infcmd.c b/gdb/infcmd.c index cab9d496cca..3b7178c4d8e 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -865,14 +865,13 @@ continue_command (char *args, int from_tty) static void set_step_frame (void) { - struct symtab_and_line sal; - CORE_ADDR pc; - struct frame_info *frame = get_current_frame (); - struct thread_info *tp = inferior_thread (); + frame_info *frame = get_current_frame (); - find_frame_sal (frame, &sal); + symtab_and_line sal = find_frame_sal (frame); set_step_info (frame, sal); - pc = get_frame_pc (frame); + + CORE_ADDR pc = get_frame_pc (frame); + thread_info *tp = inferior_thread (); tp->control.step_start_function = find_pc_function (pc); } @@ -1873,11 +1872,10 @@ finish_backward (struct finish_command_fsm *sm) { struct frame_info *frame = get_selected_frame (NULL); struct gdbarch *gdbarch = get_frame_arch (frame); - struct symtab_and_line sr_sal; /* Set a step-resume at the function's entry point. Once that's hit, we'll do one more step backwards. */ - init_sal (&sr_sal); + symtab_and_line sr_sal; sr_sal.pc = sal.pc; sr_sal.pspace = get_frame_program_space (frame); insert_step_resume_breakpoint_at_sal (gdbarch, @@ -1998,10 +1996,7 @@ finish_command (char *arg, int from_tty) called by that frame. We don't use the magic "1" value for step_range_end, because then infrun will think this is nexti, and not step over the rest of this inlined function call. */ - struct symtab_and_line empty_sal; - - init_sal (&empty_sal); - set_step_info (frame, empty_sal); + set_step_info (frame, {}); tp->control.step_range_start = get_frame_pc (frame); tp->control.step_range_end = tp->control.step_range_start; tp->control.step_over_calls = STEP_OVER_ALL; diff --git a/gdb/infrun.c b/gdb/infrun.c index 06b45b44ed6..7568a5ef478 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -6558,9 +6558,7 @@ process_event_stop_test (struct execution_control_state *ecs) { /* Set up a step-resume breakpoint at the address indicated by SKIP_SOLIB_RESOLVER. */ - struct symtab_and_line sr_sal; - - init_sal (&sr_sal); + symtab_and_line sr_sal; sr_sal.pc = pc_after_resolver; sr_sal.pspace = get_frame_program_space (frame); @@ -6611,9 +6609,7 @@ process_event_stop_test (struct execution_control_state *ecs) if (real_stop_pc) { /* And put the step-breakpoint there and go until there. */ - struct symtab_and_line sr_sal; - - init_sal (&sr_sal); /* initialize to zeroes */ + symtab_and_line sr_sal; sr_sal.pc = real_stop_pc; sr_sal.section = find_pc_overlay (sr_sal.pc); sr_sal.pspace = get_frame_program_space (frame); @@ -6711,10 +6707,8 @@ process_event_stop_test (struct execution_control_state *ecs) to the caller. */ if (ecs->stop_func_start != stop_pc && ecs->stop_func_start != 0) { - struct symtab_and_line sr_sal; - /* Normal function call return (static or dynamic). */ - init_sal (&sr_sal); + symtab_and_line sr_sal; sr_sal.pc = ecs->stop_func_start; sr_sal.pspace = get_frame_program_space (frame); insert_step_resume_breakpoint_at_sal (gdbarch, @@ -6741,9 +6735,7 @@ process_event_stop_test (struct execution_control_state *ecs) if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc)) { - struct symtab_and_line sr_sal; - - init_sal (&sr_sal); + symtab_and_line sr_sal; sr_sal.pc = ecs->stop_func_start; sr_sal.pspace = get_frame_program_space (frame); @@ -6797,9 +6789,7 @@ process_event_stop_test (struct execution_control_state *ecs) { /* Set a breakpoint at callee's start address. From there we can step once and be back in the caller. */ - struct symtab_and_line sr_sal; - - init_sal (&sr_sal); + symtab_and_line sr_sal; sr_sal.pc = ecs->stop_func_start; sr_sal.pspace = get_frame_program_space (frame); insert_step_resume_breakpoint_at_sal (gdbarch, @@ -6837,9 +6827,7 @@ process_event_stop_test (struct execution_control_state *ecs) /* Stepped backward into the solib dynsym resolver. Set a breakpoint at its start and continue, then one more step will take us out. */ - struct symtab_and_line sr_sal; - - init_sal (&sr_sal); + symtab_and_line sr_sal; sr_sal.pc = ecs->stop_func_start; sr_sal.pspace = get_frame_program_space (frame); insert_step_resume_breakpoint_at_sal (gdbarch, @@ -6919,13 +6907,11 @@ process_event_stop_test (struct execution_control_state *ecs) ecs->event_thread->control.step_frame_id) && inline_skipped_frames (ecs->ptid)) { - struct symtab_and_line call_sal; - if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: stepped into inlined function\n"); - find_frame_sal (get_current_frame (), &call_sal); + symtab_and_line call_sal = find_frame_sal (get_current_frame ()); if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL) { @@ -7289,17 +7275,14 @@ static void handle_step_into_function (struct gdbarch *gdbarch, struct execution_control_state *ecs) { - struct compunit_symtab *cust; - struct symtab_and_line stop_func_sal, sr_sal; - fill_in_stop_func (gdbarch, ecs); - cust = find_pc_compunit_symtab (stop_pc); + compunit_symtab *cust = find_pc_compunit_symtab (stop_pc); if (cust != NULL && compunit_language (cust) != language_asm) ecs->stop_func_start = gdbarch_skip_prologue_noexcept (gdbarch, ecs->stop_func_start); - stop_func_sal = find_pc_line (ecs->stop_func_start, 0); + symtab_and_line stop_func_sal = find_pc_line (ecs->stop_func_start, 0); /* Use the step_resume_break to step until the end of the prologue, even if that involves jumps (as it seems to on the vax under 4.2). */ @@ -7343,7 +7326,7 @@ handle_step_into_function (struct gdbarch *gdbarch, else { /* Put the step-breakpoint there and go until there. */ - init_sal (&sr_sal); /* initialize to zeroes */ + symtab_and_line sr_sal; sr_sal.pc = ecs->stop_func_start; sr_sal.section = find_pc_overlay (ecs->stop_func_start); sr_sal.pspace = get_frame_program_space (get_current_frame ()); @@ -7442,13 +7425,11 @@ insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch, static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame) { - struct symtab_and_line sr_sal; - struct gdbarch *gdbarch; - gdb_assert (return_frame != NULL); - init_sal (&sr_sal); /* initialize to zeros */ - gdbarch = get_frame_arch (return_frame); + struct gdbarch *gdbarch = get_frame_arch (return_frame); + + symtab_and_line sr_sal; sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame)); sr_sal.section = find_pc_overlay (sr_sal.pc); sr_sal.pspace = get_frame_program_space (return_frame); @@ -7475,16 +7456,13 @@ insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame) static void insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame) { - struct symtab_and_line sr_sal; - struct gdbarch *gdbarch; - /* We shouldn't have gotten here if we don't know where the call site is. */ gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame))); - init_sal (&sr_sal); /* initialize to zeros */ + struct gdbarch *gdbarch = frame_unwind_caller_arch (next_frame); - gdbarch = frame_unwind_caller_arch (next_frame); + symtab_and_line sr_sal; sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, frame_unwind_caller_pc (next_frame)); sr_sal.section = find_pc_overlay (sr_sal.pc); diff --git a/gdb/linespec.c b/gdb/linespec.c index 5396ebab929..480180869fa 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -2126,11 +2126,8 @@ static std::vector create_sals_line_offset (struct linespec_state *self, linespec_p ls) { - struct symtab_and_line val; int use_default = 0; - init_sal (&val); - /* This is where we need to make sure we have good defaults. We must guarantee that this section of code is never executed when we are called with just a function name, since @@ -2155,6 +2152,7 @@ create_sals_line_offset (struct linespec_state *self, use_default = 1; } + symtab_and_line val; val.line = ls->explicit_loc.line_offset.offset; switch (ls->explicit_loc.line_offset.sign) { @@ -4235,9 +4233,7 @@ decode_digits_ordinary (struct linespec_state *self, pcs = find_pcs_for_symtab_line (elt, line, best_entry); for (CORE_ADDR pc : pcs) { - struct symtab_and_line sal; - - init_sal (&sal); + symtab_and_line sal; sal.pspace = SYMTAB_PSPACE (elt); sal.symtab = elt; sal.line = line; @@ -4619,7 +4615,7 @@ symbol_to_sal (struct symtab_and_line *result, { if (SYMBOL_CLASS (sym) == LOC_LABEL && SYMBOL_VALUE_ADDRESS (sym) != 0) { - init_sal (result); + *result = {}; result->symtab = symbol_symtab (sym); result->line = SYMBOL_LINE (sym); result->pc = SYMBOL_VALUE_ADDRESS (sym); @@ -4634,7 +4630,7 @@ symbol_to_sal (struct symtab_and_line *result, else if (SYMBOL_LINE (sym) != 0) { /* We know its line number. */ - init_sal (result); + *result = {}; result->symtab = symbol_symtab (sym); result->line = SYMBOL_LINE (sym); result->pspace = SYMTAB_PSPACE (result->symtab); diff --git a/gdb/probe.c b/gdb/probe.c index 5b5e6f0febb..ce2836193b7 100644 --- a/gdb/probe.c +++ b/gdb/probe.c @@ -85,9 +85,6 @@ parse_probes_in_pspace (const struct probe_ops *probe_ops, continue; symtab_and_line sal; - - init_sal (&sal); - sal.pc = get_probe_address (probe, objfile); sal.explicit_pc = 1; sal.section = find_pc_overlay (sal.pc); diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index 891f44e708f..c5ae391ef54 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -468,14 +468,13 @@ static PyObject * frapy_find_sal (PyObject *self, PyObject *args) { struct frame_info *frame; - struct symtab_and_line sal; PyObject *sal_obj = NULL; /* Initialize to appease gcc warning. */ TRY { FRAPY_REQUIRE_VALID (self, frame); - find_frame_sal (frame, &sal); + symtab_and_line sal = find_frame_sal (frame); sal_obj = symtab_and_line_to_sal_object (sal); } CATCH (except, RETURN_MASK_ALL) diff --git a/gdb/reverse.c b/gdb/reverse.c index 61f31e54730..c3c20fb2827 100644 --- a/gdb/reverse.c +++ b/gdb/reverse.c @@ -121,7 +121,6 @@ save_bookmark_command (char *args, int from_tty) { /* Get target's idea of a bookmark. */ gdb_byte *bookmark_id = target_get_bookmark (args, from_tty); - struct bookmark *b, *b1; struct gdbarch *gdbarch = get_regcache_arch (get_current_regcache ()); /* CR should not cause another identical bookmark. */ @@ -131,9 +130,8 @@ save_bookmark_command (char *args, int from_tty) error (_("target_get_bookmark failed.")); /* Set up a bookmark struct. */ - b = XCNEW (struct bookmark); + bookmark *b = new bookmark (); b->number = ++bookmark_count; - init_sal (&b->sal); b->pc = regcache_read_pc (get_current_regcache ()); b->sal = find_pc_line (b->pc, 0); b->sal.pspace = get_frame_program_space (get_current_frame ()); @@ -143,7 +141,7 @@ save_bookmark_command (char *args, int from_tty) /* Add this bookmark to the end of the chain, so that a list of bookmarks will come out in order of increasing numbers. */ - b1 = bookmark_chain; + bookmark *b1 = bookmark_chain; if (b1 == 0) bookmark_chain = b; else @@ -183,7 +181,7 @@ delete_one_bookmark (int num) break; } xfree (b->opaque_data); - xfree (b); + delete b; return 1; /* success */ } return 0; /* failure */ diff --git a/gdb/source.c b/gdb/source.c index b63db8a725e..bac404530c0 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -182,7 +182,7 @@ get_lines_to_list (void) struct symtab_and_line get_current_source_symtab_and_line (void) { - struct symtab_and_line cursal = { 0 }; + symtab_and_line cursal; cursal.pspace = current_source_pspace; cursal.symtab = current_source_symtab; @@ -218,9 +218,9 @@ set_default_source_symtab_and_line (void) NOTE: The returned sal pc and end fields are not valid. */ struct symtab_and_line -set_current_source_symtab_and_line (const struct symtab_and_line *sal) +set_current_source_symtab_and_line (const symtab_and_line &sal) { - struct symtab_and_line cursal = { 0 }; + symtab_and_line cursal; cursal.pspace = current_source_pspace; cursal.symtab = current_source_symtab; @@ -228,9 +228,9 @@ set_current_source_symtab_and_line (const struct symtab_and_line *sal) cursal.pc = 0; cursal.end = 0; - current_source_pspace = sal->pspace; - current_source_symtab = sal->symtab; - current_source_line = sal->line; + current_source_pspace = sal.pspace; + current_source_symtab = sal.symtab; + current_source_line = sal.line; /* Force the next "list" to center around the current line. */ clear_lines_listed_range (); @@ -1498,7 +1498,6 @@ info_line_command (char *arg, int from_tty) if (arg == 0) { - init_sal (&curr_sal); /* initialize to zeroes */ curr_sal.symtab = current_source_symtab; curr_sal.pspace = current_program_space; if (last_line_listed != 0) diff --git a/gdb/source.h b/gdb/source.h index 263715aeddb..41e1d8691ab 100644 --- a/gdb/source.h +++ b/gdb/source.h @@ -91,7 +91,8 @@ extern void set_default_source_symtab_and_line (void); (the returned sal pc and end fields are not valid.) and set the current default to whatever is in SAL. NOTE: The returned sal pc and end fields are not valid. */ -extern struct symtab_and_line set_current_source_symtab_and_line (const struct symtab_and_line *); +extern symtab_and_line set_current_source_symtab_and_line + (const symtab_and_line &sal); /* Reset any information stored about a default file and line to print. */ extern void clear_current_source_symtab_and_line (void); diff --git a/gdb/stack.c b/gdb/stack.c index 9c15b9f841e..8a066b2b691 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -723,11 +723,9 @@ print_frame_args (struct symbol *func, struct frame_info *frame, void set_current_sal_from_frame (struct frame_info *frame) { - struct symtab_and_line sal; - - find_frame_sal (frame, &sal); + symtab_and_line sal = find_frame_sal (frame); if (sal.symtab != NULL) - set_current_source_symtab_and_line (&sal); + set_current_source_symtab_and_line (sal); } /* If ON, GDB will display disassembly of the next source line when @@ -789,7 +787,6 @@ print_frame_info (struct frame_info *frame, int print_level, int set_current_sal) { struct gdbarch *gdbarch = get_frame_arch (frame); - struct symtab_and_line sal; int source_print; int location_print; struct ui_out *uiout = current_uiout; @@ -852,7 +849,7 @@ print_frame_info (struct frame_info *frame, int print_level, the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the next frame was not entered as the result of a call, and we want to get the line containing FRAME->pc. */ - find_frame_sal (frame, &sal); + symtab_and_line sal = find_frame_sal (frame); location_print = (print_what == LOCATION || print_what == LOC_AND_ADDRESS @@ -1017,23 +1014,20 @@ get_last_displayed_line (void) /* Get the last sal we displayed, if it's valid. */ -void -get_last_displayed_sal (struct symtab_and_line *sal) +symtab_and_line +get_last_displayed_sal () { + symtab_and_line sal; + if (last_displayed_sal_valid) { - sal->pspace = last_displayed_pspace; - sal->pc = last_displayed_addr; - sal->symtab = last_displayed_symtab; - sal->line = last_displayed_line; - } - else - { - sal->pspace = 0; - sal->pc = 0; - sal->symtab = 0; - sal->line = 0; + sal.pspace = last_displayed_pspace; + sal.pc = last_displayed_addr; + sal.symtab = last_displayed_symtab; + sal.line = last_displayed_line; } + + return sal; } @@ -1399,7 +1393,6 @@ static void info_frame_command (char *addr_exp, int from_tty) { struct frame_info *fi; - struct symtab_and_line sal; struct symbol *func; struct symtab *s; struct frame_info *calling_frame_info; @@ -1434,8 +1427,8 @@ info_frame_command (char *addr_exp, int from_tty) pc_regname = "pc"; frame_pc_p = get_frame_pc_if_available (fi, &frame_pc); - find_frame_sal (fi, &sal); func = get_frame_function (fi); + symtab_and_line sal = find_frame_sal (fi); s = sal.symtab; if (func) { diff --git a/gdb/stack.h b/gdb/stack.h index 1583200cb29..f41d21ef61e 100644 --- a/gdb/stack.h +++ b/gdb/stack.h @@ -45,6 +45,6 @@ struct program_space* get_last_displayed_pspace (void); CORE_ADDR get_last_displayed_addr (void); struct symtab* get_last_displayed_symtab (void); int get_last_displayed_line (void); -void get_last_displayed_sal (struct symtab_and_line *sal); +symtab_and_line get_last_displayed_sal (); #endif /* #ifndef STACK_H */ diff --git a/gdb/symtab.c b/gdb/symtab.c index 7ea03d4499b..84923153059 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -947,14 +947,6 @@ symbol_search_name (const struct general_symbol_info *gsymbol) else return symbol_natural_name (gsymbol); } - -/* Initialize the structure fields to zero values. */ - -void -init_sal (struct symtab_and_line *sal) -{ - memset (sal, 0, sizeof (*sal)); -} /* Return 1 if the two sections are the same, or if they could @@ -2938,7 +2930,6 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) int len; int i; struct linetable_entry *item; - struct symtab_and_line val; const struct blockvector *bv; struct bound_minimal_symbol msymbol; @@ -2965,10 +2956,6 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) But what we want is the statement containing the instruction. Fudge the pc to make sure we get that. */ - init_sal (&val); /* initialize to zeroes */ - - val.pspace = current_program_space; - /* It's tempting to assume that, if we can't find debugging info for any function enclosing PC, that we shouldn't search for line number info, either. However, GAS can emit line number info for @@ -3057,6 +3044,8 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) return find_pc_line (BMSYMBOL_VALUE_ADDRESS (mfunsym), 0); } + symtab_and_line val; + val.pspace = current_program_space; cust = find_pc_sect_compunit_symtab (pc, section); if (cust == NULL) @@ -3469,12 +3458,11 @@ find_pc_line_pc_range (CORE_ADDR pc, CORE_ADDR *startptr, CORE_ADDR *endptr) struct symtab_and_line find_function_start_sal (struct symbol *sym, int funfirstline) { - struct symtab_and_line sal; - struct obj_section *section; - fixup_symbol_section (sym, NULL); - section = SYMBOL_OBJ_SECTION (symbol_objfile (sym), sym); - sal = find_pc_sect_line (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), section, 0); + + obj_section *section = SYMBOL_OBJ_SECTION (symbol_objfile (sym), sym); + symtab_and_line sal + = find_pc_sect_line (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), section, 0); if (funfirstline && sal.symtab != NULL && (COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal.symtab)) @@ -3494,7 +3482,7 @@ find_function_start_sal (struct symbol *sym, int funfirstline) can find a line number for after the prologue. */ if (sal.pc < BLOCK_START (SYMBOL_BLOCK_VALUE (sym))) { - init_sal (&sal); + sal = {}; sal.pspace = current_program_space; sal.pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); sal.section = section; diff --git a/gdb/symtab.h b/gdb/symtab.h index a2ca8fcea75..1bf77c199ba 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1418,29 +1418,27 @@ extern CORE_ADDR find_solib_trampoline_target (struct frame_info *, CORE_ADDR); struct symtab_and_line { /* The program space of this sal. */ - struct program_space *pspace; + struct program_space *pspace = NULL; - struct symtab *symtab; - struct obj_section *section; + struct symtab *symtab = NULL; + struct obj_section *section = NULL; /* Line number. Line numbers start at 1 and proceed through symtab->nlines. 0 is never a valid line number; it is used to indicate that line number information is not available. */ - int line; + int line = 0; - CORE_ADDR pc; - CORE_ADDR end; - int explicit_pc; - int explicit_line; + CORE_ADDR pc = 0; + CORE_ADDR end = 0; + bool explicit_pc = false; + bool explicit_line = false; /* The probe associated with this symtab_and_line. */ - struct probe *probe; + struct probe *probe = NULL; /* If PROBE is not NULL, then this is the objfile in which the probe originated. */ - struct objfile *objfile; + struct objfile *objfile = NULL; }; -extern void init_sal (struct symtab_and_line *sal); - /* Given a pc value, return line number it is in. Second arg nonzero means diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 566d06bb050..f8aa3297b3c 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -253,7 +253,7 @@ set_traceframe_context (struct frame_info *trace_frame) { CORE_ADDR trace_pc; struct symbol *traceframe_fun; - struct symtab_and_line traceframe_sal; + symtab_and_line traceframe_sal; /* Save as globals for internal use. */ if (trace_frame != NULL @@ -269,7 +269,6 @@ set_traceframe_context (struct frame_info *trace_frame) } else { - init_sal (&traceframe_sal); traceframe_fun = NULL; set_internalvar_integer (lookup_internalvar ("trace_line"), -1); } @@ -3818,10 +3817,7 @@ print_one_static_tracepoint_marker (int count, struct ui_out *uiout = current_uiout; VEC(breakpoint_p) *tracepoints; - struct symtab_and_line sal; - - init_sal (&sal); - + symtab_and_line sal; sal.pc = marker->address; tracepoints = static_tracepoints_here (marker->address); diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index 123a9068f2c..a76383255ed 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -305,7 +305,7 @@ tui_show_disassem_and_update_source (struct gdbarch *gdbarch, tui_update_source_window (TUI_SRC_WIN, gdbarch, sal.symtab, val, TRUE); if (sal.symtab) { - set_current_source_symtab_and_line (&sal); + set_current_source_symtab_and_line (sal); tui_update_locator_fullname (symtab_to_fullname (sal.symtab)); } else diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c index 21a8bacebac..c075bef4e4d 100644 --- a/gdb/tui/tui-stack.c +++ b/gdb/tui/tui-stack.c @@ -366,10 +366,9 @@ tui_show_frame_info (struct frame_info *fi) CORE_ADDR low; struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); int source_already_displayed; - struct symtab_and_line sal; CORE_ADDR pc; - find_frame_sal (fi, &sal); + symtab_and_line sal = find_frame_sal (fi); source_already_displayed = sal.symtab != 0 && tui_source_is_displayed (symtab_to_fullname (sal.symtab)); diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 3ae9c712299..103b1e6658e 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -109,14 +109,13 @@ tui_update_source_window_as_is (struct tui_win_info *win_info, tui_update_exec_info (win_info); if (win_info->generic.type == SRC_WIN) { - struct symtab_and_line sal; - - init_sal (&sal); + symtab_and_line sal; + sal.line = line_or_addr.u.line_no + (win_info->generic.content_size - 2); sal.symtab = s; sal.pspace = SYMTAB_PSPACE (s); - set_current_source_symtab_and_line (&sal); + set_current_source_symtab_and_line (sal); /* If the focus was in the asm win, put it in the src win if we don't have a split layout. */ if (tui_win_with_focus () == TUI_DISASM_WIN