mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-06 12:09:26 +08:00
08feed99cb
This changes get_objfile_arch to be a new inline method, objfile::arch. To my surprise, this function came up while profiling DWARF psymbol reading. Making this change improved performance from 1.986 seconds to 1.869 seconds. Both measurements were done by taking the mean of 10 runs on a fixed copy of the gdb executable. gdb/ChangeLog 2020-04-18 Tom Tromey <tom@tromey.com> * xcoffread.c (enter_line_range, scan_xcoff_symtab): Update. * value.c (value_fn_field): Update. * valops.c (find_function_in_inferior) (value_allocate_space_in_inferior): Update. * tui/tui-winsource.c (tui_update_source_windows_with_line): Update. * tui/tui-source.c (tui_source_window::set_contents): Update. * symtab.c (lookup_global_or_static_symbol) (find_function_start_sal_1, skip_prologue_sal) (print_msymbol_info, find_gnu_ifunc, symbol_arch): Update. * symmisc.c (dump_msymbols, dump_symtab_1) (maintenance_print_one_line_table): Update. * symfile.c (init_entry_point_info, section_is_mapped) (list_overlays_command, simple_read_overlay_table) (simple_overlay_update_1): Update. * stap-probe.c (handle_stap_probe): Update. * stabsread.c (dbx_init_float_type, define_symbol) (read_one_struct_field, read_enum_type, read_range_type): Update. * source.c (info_line_command): Update. * python/python.c (gdbpy_source_objfile_script) (gdbpy_execute_objfile_script): Update. * python/py-type.c (save_objfile_types): Update. * python/py-objfile.c (py_free_objfile): Update. * python/py-inferior.c (python_new_objfile): Update. * psymtab.c (psym_find_pc_sect_compunit_symtab, dump_psymtab) (dump_psymtab_addrmap_1, maintenance_info_psymtabs) (maintenance_check_psymtabs): Update. * printcmd.c (info_address_command): Update. * objfiles.h (struct objfile) <arch>: New method, from get_objfile_arch. (get_objfile_arch): Don't declare. * objfiles.c (get_objfile_arch): Remove. (filter_overlapping_sections): Update. * minsyms.c (msymbol_is_function): Update. * mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines) (output_nondebug_symbol): Update. * mdebugread.c (parse_symbol, basic_type, parse_partial_symbols) (mdebug_expand_psymtab): Update. * machoread.c (macho_add_oso_symfile): Update. * linux-tdep.c (linux_infcall_mmap, linux_infcall_munmap): Update. * linux-fork.c (checkpoint_command): Update. * linespec.c (convert_linespec_to_sals): Update. * jit.c (finalize_symtab): Update. * infrun.c (insert_exception_resume_from_probe): Update. * ia64-tdep.c (ia64_find_unwind_table): Update. * hppa-tdep.c (internalize_unwinds): Update. * gdbtypes.c (get_type_arch, init_float_type, objfile_type): Update. * gcore.c (call_target_sbrk): Update. * elfread.c (record_minimal_symbol, elf_symtab_read) (elf_rel_plt_read, elf_gnu_ifunc_record_cache) (elf_gnu_ifunc_resolve_by_got): Update. * dwarf2/read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (read_debug_names_from_section) (process_psymtab_comp_unit_reader, add_partial_symbol) (add_partial_subprogram, process_full_comp_unit) (read_file_scope, read_func_scope, read_lexical_block_scope) (read_call_site_scope, dwarf2_ranges_read) (dwarf2_record_block_ranges, dwarf2_add_field) (mark_common_block_symbol_computed, read_tag_pointer_type) (read_tag_string_type, dwarf2_init_float_type) (dwarf2_init_complex_target_type, read_base_type) (partial_die_info::read, partial_die_info::read) (read_attribute_value, dwarf_decode_lines_1, new_symbol) (dwarf2_fetch_die_loc_sect_off): Update. * dwarf2/loc.c (dwarf2_find_location_expression) (class dwarf_evaluate_loc_desc, rw_pieced_value) (dwarf2_evaluate_loc_desc_full, dwarf2_locexpr_baton_eval) (dwarf2_loc_desc_get_symbol_read_needs) (locexpr_describe_location_piece, locexpr_describe_location_1) (loclist_describe_location): Update. * dwarf2/index-write.c (write_debug_names): Update. * dwarf2/frame.c (dwarf2_build_frame_info): Update. * dtrace-probe.c (dtrace_process_dof): Update. * dbxread.c (read_dbx_symtab, dbx_end_psymtab) (process_one_symbol): Update. * ctfread.c (ctf_init_float_type, read_base_type): Update. * coffread.c (coff_symtab_read, enter_linenos, decode_base_type) (coff_read_enum_type): Update. * cli/cli-cmds.c (edit_command, list_command): Update. * buildsym.c (buildsym_compunit::finish_block_internal): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint, get_sal_arch): Update. * block.c (block_gdbarch): Update. * annotate.c (annotate_source_line): Update.
228 lines
6.1 KiB
C
228 lines
6.1 KiB
C
/* TUI display source window.
|
|
|
|
Copyright (C) 1998-2020 Free Software Foundation, Inc.
|
|
|
|
Contributed by Hewlett-Packard Company.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "defs.h"
|
|
#include <math.h>
|
|
#include <ctype.h>
|
|
#include "symtab.h"
|
|
#include "frame.h"
|
|
#include "breakpoint.h"
|
|
#include "source.h"
|
|
#include "objfiles.h"
|
|
#include "filenames.h"
|
|
#include "source-cache.h"
|
|
|
|
#include "tui/tui.h"
|
|
#include "tui/tui-data.h"
|
|
#include "tui/tui-io.h"
|
|
#include "tui/tui-stack.h"
|
|
#include "tui/tui-win.h"
|
|
#include "tui/tui-winsource.h"
|
|
#include "tui/tui-source.h"
|
|
#include "gdb_curses.h"
|
|
|
|
/* Function to display source in the source window. */
|
|
bool
|
|
tui_source_window::set_contents (struct gdbarch *arch,
|
|
const struct symtab_and_line &sal)
|
|
{
|
|
struct symtab *s = sal.symtab;
|
|
int line_no = sal.line;
|
|
|
|
if (s == NULL)
|
|
return false;
|
|
|
|
int line_width, nlines;
|
|
|
|
line_width = width - TUI_EXECINFO_SIZE - 1;
|
|
/* Take hilite (window border) into account, when
|
|
calculating the number of lines. */
|
|
nlines = height - 2;
|
|
|
|
std::string srclines;
|
|
const std::vector<off_t> *offsets;
|
|
if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines,
|
|
&srclines)
|
|
|| !g_source_cache.get_line_charpos (s, &offsets))
|
|
return false;
|
|
|
|
int cur_line_no, cur_line;
|
|
struct tui_locator_window *locator
|
|
= tui_locator_win_info_ptr ();
|
|
const char *s_filename = symtab_to_filename_for_display (s);
|
|
|
|
title = s_filename;
|
|
|
|
m_fullname = make_unique_xstrdup (symtab_to_fullname (s));
|
|
|
|
cur_line = 0;
|
|
m_gdbarch = SYMTAB_OBJFILE (s)->arch ();
|
|
m_start_line_or_addr.loa = LOA_LINE;
|
|
cur_line_no = m_start_line_or_addr.u.line_no = line_no;
|
|
|
|
int digits = 0;
|
|
if (compact_source)
|
|
{
|
|
/* Solaris 11+gcc 5.5 has ambiguous overloads of log10, so we
|
|
cast to double to get the right one. */
|
|
double l = log10 ((double) offsets->size ());
|
|
digits = 1 + (int) l;
|
|
}
|
|
|
|
const char *iter = srclines.c_str ();
|
|
m_content.resize (nlines);
|
|
while (cur_line < nlines)
|
|
{
|
|
struct tui_source_element *element = &m_content[cur_line];
|
|
|
|
std::string text;
|
|
if (*iter != '\0')
|
|
text = tui_copy_source_line (&iter, cur_line_no,
|
|
m_horizontal_offset,
|
|
line_width, digits);
|
|
|
|
/* Set whether element is the execution point
|
|
and whether there is a break point on it. */
|
|
element->line_or_addr.loa = LOA_LINE;
|
|
element->line_or_addr.u.line_no = cur_line_no;
|
|
element->is_exec_point
|
|
= (filename_cmp (locator->full_name.c_str (),
|
|
symtab_to_fullname (s)) == 0
|
|
&& cur_line_no == locator->line_no);
|
|
|
|
m_content[cur_line].line = std::move (text);
|
|
|
|
cur_line++;
|
|
cur_line_no++;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/* Answer whether the source is currently displayed in the source
|
|
window. */
|
|
bool
|
|
tui_source_window::showing_source_p (const char *fullname) const
|
|
{
|
|
return (!m_content.empty ()
|
|
&& (filename_cmp (tui_locator_win_info_ptr ()->full_name.c_str (),
|
|
fullname) == 0));
|
|
}
|
|
|
|
|
|
/* Scroll the source forward or backward vertically. */
|
|
void
|
|
tui_source_window::do_scroll_vertical (int num_to_scroll)
|
|
{
|
|
if (!m_content.empty ())
|
|
{
|
|
struct symtab *s;
|
|
struct symtab_and_line cursal = get_current_source_symtab_and_line ();
|
|
struct gdbarch *arch = m_gdbarch;
|
|
|
|
if (cursal.symtab == NULL)
|
|
{
|
|
struct frame_info *fi = get_selected_frame (NULL);
|
|
s = find_pc_line_symtab (get_frame_pc (fi));
|
|
arch = get_frame_arch (fi);
|
|
}
|
|
else
|
|
s = cursal.symtab;
|
|
|
|
int line_no = m_start_line_or_addr.u.line_no + num_to_scroll;
|
|
const std::vector<off_t> *offsets;
|
|
if (g_source_cache.get_line_charpos (s, &offsets)
|
|
&& line_no > offsets->size ())
|
|
line_no = m_start_line_or_addr.u.line_no;
|
|
if (line_no <= 0)
|
|
line_no = 1;
|
|
|
|
cursal.line = line_no;
|
|
find_line_pc (cursal.symtab, cursal.line, &cursal.pc);
|
|
for (struct tui_source_window_base *win_info : tui_source_windows ())
|
|
win_info->update_source_window_as_is (arch, cursal);
|
|
}
|
|
}
|
|
|
|
bool
|
|
tui_source_window::location_matches_p (struct bp_location *loc, int line_no)
|
|
{
|
|
return (m_content[line_no].line_or_addr.loa == LOA_LINE
|
|
&& m_content[line_no].line_or_addr.u.line_no == loc->line_number
|
|
&& loc->symtab != NULL
|
|
&& filename_cmp (m_fullname.get (),
|
|
symtab_to_fullname (loc->symtab)) == 0);
|
|
}
|
|
|
|
/* See tui-source.h. */
|
|
|
|
bool
|
|
tui_source_window::line_is_displayed (int line) const
|
|
{
|
|
if (m_content.size () < SCROLL_THRESHOLD)
|
|
return false;
|
|
|
|
for (size_t i = 0; i < m_content.size () - SCROLL_THRESHOLD; ++i)
|
|
{
|
|
if (m_content[i].line_or_addr.loa == LOA_LINE
|
|
&& m_content[i].line_or_addr.u.line_no == line)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void
|
|
tui_source_window::maybe_update (struct frame_info *fi, symtab_and_line sal)
|
|
{
|
|
int start_line = (sal.line - ((height - 2) / 2)) + 1;
|
|
if (start_line <= 0)
|
|
start_line = 1;
|
|
|
|
bool source_already_displayed = (sal.symtab != 0
|
|
&& showing_source_p (m_fullname.get ()));
|
|
|
|
if (!(source_already_displayed && line_is_displayed (sal.line)))
|
|
{
|
|
sal.line = start_line;
|
|
update_source_window (get_frame_arch (fi), sal);
|
|
}
|
|
else
|
|
{
|
|
struct tui_line_or_address l;
|
|
|
|
l.loa = LOA_LINE;
|
|
l.u.line_no = sal.line;
|
|
set_is_exec_point_at (l);
|
|
}
|
|
}
|
|
|
|
void
|
|
tui_source_window::display_start_addr (struct gdbarch **gdbarch_p,
|
|
CORE_ADDR *addr_p)
|
|
{
|
|
struct symtab_and_line cursal = get_current_source_symtab_and_line ();
|
|
|
|
*gdbarch_p = m_gdbarch;
|
|
find_line_pc (cursal.symtab, m_start_line_or_addr.u.line_no, addr_p);
|
|
}
|