Commit Graph

300 Commits

Author SHA1 Message Date
Simon Marchi 5d14b6e5d6 gdb: add field::type / field::set_type
Add the `type` and `set_type` methods on `struct field`, in order to
remoremove the `FIELD_TYPE` macro.  In this patch, the `FIELD_TYPE`
macro is changed to use `field::type`, so all the call sites that are
useused to set the field's type are changed to use `field::set_type`.
The next patch will remove `FIELD_TYPE` completely.

Note that because of the name clash between the existing field named
`type` and the new method, I renamed the field `m_type`.  It is not
private per-se, because we can't make `struct field` a non-POD yet, but
it should be considered private anyway (not accessed outside `struct
field`).

gdb/ChangeLog:

	* gdbtypes.h (struct field) <type, set_type>: New methods.
	Rename `type` field to...
	<m_type>: ... this.  Change references throughout to use type or
	set_type methods.
	(FIELD_TYPE): Use field::type.  Change call sites that modify
	the field's type to use field::set_type instead.

Change-Id: Ie21f866e3b7f8a51ea49b722d07d272a724459a0
2020-06-08 15:26:04 -04:00
Simon Marchi 3cabb6b069 gdb: add type::fields / type::set_fields
Add the `fields` and `set_fields` methods on `struct type`, in order to
remove the `TYPE_FIELDS` macro.  In this patch, the `TYPE_FIELDS` macro
is changed to the `type::fields`, so all the call sites that use it to
set the fields array are changed to use `type::set_fields`.  The next
patch will remove `TYPE_FIELDS` entirely.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <fields, set_fields>: New methods.
	(TYPE_FIELDS): Use type::fields.  Change all call sites that
	modify the propery to use type::set_fields instead.

Change-Id: I05174ce68f2ce3fccdf5d8b469ff141f14886b33
2020-05-22 16:55:16 -04:00
Simon Marchi 1f704f761b gdb: remove TYPE_NFIELDS macro
Remove `TYPE_NFIELDS`, changing all the call sites to use
`type::num_fields` directly.  This is quite a big diff, but this was
mostly done using sed and coccinelle.  A few call sites were done by
hand.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_NFIELDS): Remove.  Change all cal sites to use
	type::num_fields instead.

Change-Id: Ib73be4c36f9e770e0f729bac3b5257d7cb2f9591
2020-05-22 16:55:15 -04:00
Simon Marchi 5e33d5f4e1 gdb: add type::num_fields / type::set_num_fields
Add the `num_fields` and `set_num_fields` methods on `struct type`, in
order to remove the `TYPE_NFIELDS` macro.  In this patch, the
`TYPE_NFIELDS` macro is changed to use `type::num_fields`, so all the
call sites that are used to set the number of fields are changed to use
`type::set_num_fields`.  The next patch will remove `TYPE_NFIELDS`
completely.

I think that in the future, we should consider making the interface of
`struct type` better.  For example, right now it's possible for the
number of fields property and the actual number of fields set to be out
of sync.  However, I want to keep the existing behavior in this patch,
just translate from macros to methods.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <num_fields, set_num_fields>: New
	methods.
	(TYPE_NFIELDS): Use type::num_fields.  Change all call sites
	that modify the number of fields to use type::set_num_fields
	instead.

Change-Id: I5ad9de5be4097feaf942d111077434bf91d13dc5
2020-05-22 16:55:14 -04:00
Tom Tromey 08feed99cb Change get_objfile_arch to a method on objfile
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.
2020-04-18 08:35:04 -06:00
Bernd Edlinger a25198bba2 Partially revert my UB fix in record_line
This reverts the following commit partially:

commit 64dc2d4bd2
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Thu Mar 12 11:52:34 2020 +0100

    Fix an undefined behavior in record_line

    Additionally do not completely remove symbols
    at the same PC than the end marker, instead
    make them non-is-stmt breakpoints.

We keep the undefined behavoir fix,
but have to restore the original behavior
regarding deletion of the line entries.

2020-04-09  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	revert partially:
	2020-04-01  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * buildsym.c (record_line): Fix undefined behavior and preserve
        lines at eof.
2020-04-09 17:06:58 +02:00
Andrew Burgess c90d28ac89 gdb: Don't remove duplicate entries from the line table
In this commit:

  commit 8c95582da8
  Date:   Mon Dec 30 21:04:51 2019 +0000

      gdb: Add support for tracking the DWARF line table is-stmt field

A change was made in buildsym_compunit::record_line to remove
duplicate line table entries in some cases.  This was an invalid
change, as these duplicate line table entries are used in _some_ cases
as part of prologue detection (see skip_prologue_using_sal).

It might be possible to identify those line table entries that are
required by skip_prologue_using_sal and only keep those duplicates
around, however, I have not done this here.  The original duplicate
removal was done because (a) it was easy to implement, and (b) it
seemed obviously harmless.

As (b) is now known to be false, and implementation would be more
complex, and so (a) is also false.  As such, it seems better to keep
all duplicates until an actual reason presents itself for why we
should remove any.

The original regression was spotted on RISC-V, which makes use of
skip_prologue_using_sal as part of riscv_skip_prologue.  Originally I
created the test gdb.dwarf2/dw2-inline-small-func.exp, however, this
test will not compile on RISC-V as this target doesn't support
.uleb128 or .sleb128 assembler directives containing complex
expressions.  As a result I added the gdb.opt/inline-small-func.exp
test, which exposes the bug on RISC-V, but obviously depends on the
compiler to produce specific DWARF information in order to expose the
bug.  Still this test does ensure we always get the desired result,
even if the DWARF changes.

Originally the gdb.dwarf2/dw2-inline-small-func.exp test passed on
x86-64 even with the duplicate line table entries incorrectly
removed.  The reason for this is that when a compilation unit doesn't
have a 'producer' string then skip_prologue_using_sal is not used,
instead the prologue is always skipped using analysis of the assembler
code.

However, for Clang on x86-64 skip_prologue_using_sal is used, so I
modified the gdb.dwarf2/dw2-inline-small-func.exp test to include a
'producer' string that names the Clang compiler.  With this done the
test would fail on x86-64.

One thing to note is that the gdb.opt/inline-small-func.exp test might
fail on some targets.  For example, if we compare sparc to risc-v by
looking at sparc32_skip_prologue we see that this function doesn't use
skip_prologue_using_sal, but instead uses find_pc_partial_function
directly.  I don't know the full history behind why the code is like
it is, but it feels like sparc32_skip_prologue is an attempt to
duplicate some of the functionality of skip_prologue_using_sal, but
without all of the special cases.  If this is true then the new test
could easily fail on this target, this would suggest that sparc should
consider switching to use skip_prologue_using_sal like risc-v does.

gdb/ChangeLog:

	* buildsym.c (buildsym_compunit::record_line): Remove
	deduplication code.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-inline-small-func-lbls.c: New file.
	* gdb.dwarf2/dw2-inline-small-func.c: New file.
	* gdb.dwarf2/dw2-inline-small-func.exp: New file.
	* gdb.dwarf2/dw2-inline-small-func.h: New file.
	* gdb.opt/inline-small-func.c: New file.
	* gdb.opt/inline-small-func.exp: New file.
	* gdb.opt/inline-small-func.h: New file.
2020-04-02 17:44:03 +01:00
Bernd Edlinger 64dc2d4bd2 Fix an undefined behavior in record_line
Additionally do not completely remove symbols
at the same PC than the end marker, instead
make them non-is-stmt breakpoints.

2020-04-01  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* buildsym.c (record_line): Fix undefined behavior and preserve
	lines at eof.
2020-04-01 23:41:12 +02:00
Bernd Edlinger bbe3dc410b Fix the resizing condition of the line table
That was wasting one element.

2020-04-01  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* buildsym.c (record_line): Fix the resizing condition.
2020-04-01 23:37:46 +02:00
Andrew Burgess dcc050c86c gdb: Fix out of bounds array access in buildsym_compunit::record_line
This commit:

  commit 8c95582da8
  Date:   Mon Dec 30 21:04:51 2019 +0000

      gdb: Add support for tracking the DWARF line table is-stmt field

Introduced an invalid memory access, by reading outside the bounds of
an array.

This would cause this valgrind error:

  ==7633== Invalid read of size 4
  ==7633==    at 0x4D002C: buildsym_compunit::record_line(subfile*, int, unsigned long, bool) (buildsym.c:688)
  ==7633==    by 0x5F60A5: dwarf_record_line_1(gdbarch*, subfile*, unsigned int, unsigned long, bool, dwarf2_cu*) (read.c:19956)
  ==7633==    by 0x5F63B0: lnp_state_machine::record_line(bool) (read.c:20024)
  ==7633==    by 0x5F5DD5: lnp_state_machine::handle_special_opcode(unsigned char) (read.c:19851)
  ==7633==    by 0x5F6706: dwarf_decode_lines_1(line_header*, dwarf2_cu*, int, unsigned long) (read.c:20135)
  ==7633==    by 0x5F6C57: dwarf_decode_lines(line_header*, char const*, dwarf2_cu*, dwarf2_psymtab*, unsigned long, int) (read.c:20328)
  ==7633==    by 0x5DF5F1: handle_DW_AT_stmt_list(die_info*, dwarf2_cu*, char const*, unsigned long) (read.c:10748)
  ==7633==    by 0x5DF823: read_file_scope(die_info*, dwarf2_cu*) (read.c:10796)
  ==7633==    by 0x5DDA63: process_die(die_info*, dwarf2_cu*) (read.c:9815)
  ==7633==    by 0x5DD44A: process_full_comp_unit(dwarf2_per_cu_data*, language) (read.c:9580)
  ==7633==    by 0x5DAB58: process_queue(dwarf2_per_objfile*) (read.c:8867)
  ==7633==    by 0x5CB30E: dw2_do_instantiate_symtab(dwarf2_per_cu_data*, bool) (read.c:2374)
  ==7633==  Address 0xa467f48 is 8 bytes before a block of size 16,024 alloc'd
  ==7633==    at 0x4C2CDCB: malloc (vg_replace_malloc.c:299)
  ==7633==    by 0x451FC4: xmalloc (alloc.c:60)
  ==7633==    by 0x4CFFDF: buildsym_compunit::record_line(subfile*, int, unsigned long, bool) (buildsym.c:678)
  ==7633==    by 0x5F60A5: dwarf_record_line_1(gdbarch*, subfile*, unsigned int, unsigned long, bool, dwarf2_cu*) (read.c:19956)
  ==7633==    by 0x5F63B0: lnp_state_machine::record_line(bool) (read.c:20024)
  ==7633==    by 0x5F5DD5: lnp_state_machine::handle_special_opcode(unsigned char) (read.c:19851)
  ==7633==    by 0x5F6706: dwarf_decode_lines_1(line_header*, dwarf2_cu*, int, unsigned long) (read.c:20135)
  ==7633==    by 0x5F6C57: dwarf_decode_lines(line_header*, char const*, dwarf2_cu*, dwarf2_psymtab*, unsigned long, int) (read.c:20328)
  ==7633==    by 0x5DF5F1: handle_DW_AT_stmt_list(die_info*, dwarf2_cu*, char const*, unsigned long) (read.c:10748)
  ==7633==    by 0x5DF823: read_file_scope(die_info*, dwarf2_cu*) (read.c:10796)
  ==7633==    by 0x5DDA63: process_die(die_info*, dwarf2_cu*) (read.c:9815)
  ==7633==    by 0x5DD44A: process_full_comp_unit(dwarf2_per_cu_data*, language) (read.c:9580)

gdb/ChangeLog:

	* buildsyms.c (buildsym_compunit::record_line): Avoid accessing
	previous item in the list, when the list has no items.
2020-03-11 11:24:50 +00:00
Andrew Burgess 8c95582da8 gdb: Add support for tracking the DWARF line table is-stmt field
This commit brings support for the DWARF line table is_stmt field to
GDB.  The is_stmt field is used by the compiler when a single source
line is split into multiple assembler instructions, especially if the
assembler instructions are interleaved with instruction from other
source lines.

The compiler will set the is_stmt flag false from some instructions
from the source lines, these instructions are not a good place to
insert a breakpoint in order to stop at the source line.
Instructions which are marked with the is_stmt flag true are a good
place to insert a breakpoint for that source line.

Currently GDB ignores all instructions for which is_stmt is false.
This is fine in a lot of cases, however, there are some cases where
this means the debug experience is not as good as it could be.

Consider stopping at a random instruction, currently this instruction
will be attributed to the last line table entry before this point for
which is_stmt was true - as these are the only line table entries that
GDB tracks.  This can easily be incorrect in code with even a low
level of optimisation.

With is_stmt tracking in place, when stopping at a random instruction
we now attribute the instruction back to the real source line, even
when is_stmt is false for that instruction in the line table.

When inserting breakpoints we still select line table entries for
which is_stmt is true, so the breakpoint placing behaviour should not
change.

When stepping though code (at the line level, not the instruction
level) we will still stop at instruction where is_stmt is true, I
think this is more likely to be the desired behaviour.

Instruction stepping is, of course, unchanged, stepping one
instruction at a time, but we should now report more accurate line
table information with each instruction step.

The original motivation for this work was a patch posted by Bernd
here:
  https://sourceware.org/ml/gdb-patches/2019-11/msg00792.html

As part of that thread it was suggested that many issues would be
resolved if GDB supported line table views, this isn't something I've
attempted in this patch, though reading the spec, it seems like this
would be a useful feature to support in GDB in the future.  The spec
is here:
  http://dwarfstd.org/ShowIssue.php?issue=170427.1

And Bernd gives a brief description of the benefits here:
  https://sourceware.org/ml/gdb-patches/2020-01/msg00147.html

With that all said, I think that there is benefit to having proper
is_stmt support regardless of whether we have views support, so I
think we should consider getting this in first, and then building view
support on top of this.

The gdb.cp/step-and-next-inline.exp test is based off a test proposed
by Bernd Edlinger in this message:
  https://sourceware.org/ml/gdb-patches/2019-12/msg00842.html

gdb/ChangeLog:

	* buildsym-legacy.c (record_line): Pass extra parameter to
	record_line.
	* buildsym.c (buildsym_compunit::record_line): Take an extra
	parameter, reduce duplication in the line table, and record the
	is_stmt flag in the line table.
	* buildsym.h (buildsym_compunit::record_line): Add extra
	parameter.
	* disasm.c (do_mixed_source_and_assembly_deprecated): Ignore
	non-statement lines.
	* dwarf2/read.c (dwarf_record_line_1): Add extra parameter, pass
	this to the symtab builder.
	(dwarf_finish_line): Pass extra parameter to dwarf_record_line_1.
	(lnp_state_machine::record_line): Pass a suitable is_stmt flag
	through to dwarf_record_line_1.
	* infrun.c (process_event_stop_test): When stepping, don't stop at
	a non-statement instruction, and only refresh the step info when
	we land in the middle of a line's range.  Also add an extra
	comment.
	* jit.c (jit_symtab_line_mapping_add_impl): Initialise is_stmt
	field.
	* record-btrace.c (btrace_find_line_range): Only record lines
	marked as is-statement.
	* stack.c (frame_show_address): Show the frame address if we are
	in a non-statement sal.
	* symmisc.c (dump_symtab_1): Print the is_stmt flag.
	(maintenance_print_one_line_table): Print a header for the is_stmt
	column, and include is_stmt information in the output.
	* symtab.c (find_pc_sect_line): Find lines marked as statements in
	preference to non-statements.
	(find_pcs_for_symtab_line): Prefer is-statement entries.
	(find_line_common): Likewise.
	* symtab.h (struct linetable_entry): Add is_stmt field.
	(struct symtab_and_line): Likewise.
	* xcoffread.c (arrange_linetable): Initialise is_stmt field when
	arranging the line table.

gdb/testsuite/ChangeLog:

	* gdb.cp/step-and-next-inline.cc: New file.
	* gdb.cp/step-and-next-inline.exp: New file.
	* gdb.cp/step-and-next-inline.h: New file.
	* gdb.dwarf2/dw2-is-stmt.c: New file.
	* gdb.dwarf2/dw2-is-stmt.exp: New file.
	* gdb.dwarf2/dw2-is-stmt-2.c: New file.
	* gdb.dwarf2/dw2-is-stmt-2.exp: New file.
	* gdb.dwarf2/dw2-ranges-base.exp: Update line table pattern.
2020-03-10 22:32:07 +00:00
Tom Tromey be1e3d3eab Introduce objfile::intern
This introduces a string cache on the per-BFD object, replacing the
macro and filename caches.  Both of these caches just store strings,
so this consolidation by itself saves a little memory (about the size
of a bcache per objfile).

Then this patch switches some allocations on the objfile obstack to
use this bcache instead.  This saves more space; and turns out to be a
bit faster as well.

Here are the before and after "maint time" + "maint space" results of
"file ./gdb":

    Command execution time: 4.664021 (cpu), 4.728518 (wall)
    Space used: 39190528 (+29212672 for this command)

    Command execution time: 4.216209 (cpu), 4.107023 (wall)
    Space used: 36667392 (+26689536 for this command)

The main interface to the string cache is a new pair of overloaded
methods, objfile::intern.

gdb/ChangeLog
2020-03-04  Tom Tromey  <tom@tromey.com>

	* symmisc.c (print_symbol_bcache_statistics)
	(print_objfile_statistics): Update.
	* symfile.c (allocate_symtab): Use intern.
	* psymtab.c (partial_symtab::partial_symtab): Use intern.
	* objfiles.h (struct objfile_per_bfd_storage) <filename_cache,
	macro_cache>: Remove.
	<string_cache>: New member.
	(struct objfile) <intern>: New methods.
	* elfread.c (elf_symtab_read): Use intern.
	* dwarf2/read.c (fixup_go_packaging): Intern package name.
	(dwarf2_compute_name, dwarf2_physname)
	(create_dwo_unit_in_dwp_v1, create_dwo_unit_in_dwp_v2): Intern
	names.
	(guess_partial_die_structure_name): Update.
	(partial_die_info::fixup): Intern name.
	(dwarf2_canonicalize_name): Change parameter to objfile.  Intern
	name.
	(dwarf2_name): Intern name.  Update.
	* buildsym.c (buildsym_compunit::get_macro_table): Use
	string_cache.
2020-03-04 16:34:49 -07:00
Andrew Burgess 3d92a3e313 gdb: Don't reorder line table entries too much when sorting.
Don't reorder line table entries for the same address when sorting the
line table, maintain the compiler given line order.  Usually this will
reflect the order in which lines are conceptually encountered at a
given address.

Consider this example:

/* 1  */    volatile int global_var;
/* 2  */    int  __attribute__ ((noinline))
/* 3  */    bar ()
/* 4  */    {
/* 5  */      return global_var;
/* 6  */    }
/* 7  */    static inline int __attribute__ ((always_inline))
/* 8  */    foo ()
/* 9  */    {
/* 10 */      return bar ();
/* 11 */    }
/* 12 */    int
/* 13 */    main ()
/* 14 */    {
/* 15 */      global_var = 0;
/* 16 */      return foo ();
/* 17 */    }

GCC 10 currently generates a line table like this (as shown by
objdump):

  CU: ./test.c:
  File name          Line number    Starting address
  test.c                       4            0x4004b0
  test.c                       5            0x4004b0
  test.c                       6            0x4004b6
  test.c                       6            0x4004b7

  test.c                      14            0x4003b0
  test.c                      15            0x4003b0
  test.c                      16            0x4003ba
  test.c                      10            0x4003ba
  test.c                      10            0x4003c1

The interesting entries are those for lines 16 and 10 at address
0x4003ba, these represent the call to foo and the inlined body of
foo.

With the current line table sorting GDB builds the line table like
this (as shown by 'maintenance info line-table'):

  INDEX    LINE ADDRESS
  0          14 0x00000000004003b0
  1          15 0x00000000004003b0
  2          10 0x00000000004003ba
  3          16 0x00000000004003ba
  4         END 0x00000000004003c1
  5           4 0x00000000004004b0
  6           5 0x00000000004004b0
  7         END 0x00000000004004b7

Notice that entries 2 and 3 for lines 10 and 16 are now in a different
order to the line table as given by the compiler.  With this patch
applied the order is now:

  INDEX    LINE ADDRESS
  0          14 0x00000000004003b0
  1          15 0x00000000004003b0
  2          16 0x00000000004003ba
  3          10 0x00000000004003ba
  4         END 0x00000000004003c1
  5           4 0x00000000004004b0
  6           5 0x00000000004004b0
  7         END 0x00000000004004b7

Notice that entries 2 and 3 are now in their original order again.

The consequence of the incorrect ordering is that when stepping
through inlined functions GDB will display the wrong line for the
inner most frame.  Here's a GDB session before this patch is applied:

  Starting program: /home/andrew/tmp/inline/test

  Temporary breakpoint 1, main () at test.c:15
  15	/* 15 */      global_var = 0;
  (gdb) step
  16	/* 16 */      return foo ();
  (gdb) step
  foo () at test.c:16
  16	/* 16 */      return foo ();
  (gdb) step
  bar () at test.c:5
  5	/* 5  */      return global_var;

The step from line 15 to 16 was fine, but the next step should have
taken us to line 10, instead we are left at line 16.  The final step
to line 5 is as expected.

With this patch applied the session goes better:

  Starting program: /home/andrew/tmp/inline/test

  Temporary breakpoint 1, main () at test.c:15
  15	/* 15 */      global_var = 0;
  (gdb) step
  16	/* 16 */      return foo ();
  (gdb) step
  foo () at test.c:10
  10	/* 10 */      return bar ();
  (gdb) step
  bar () at test.c:5
  5	/* 5  */      return global_var;

We now visit the lines as 15, 16, 10, 5 as we would like.

The reason for this issue is that the inline frame unwinder is
detecting that foo is inlined in main.  When we stop at the shared
address 0x4003ba the inline frame unwinder first shows us the outer
frame, this information is extracted from the DWARF's
DW_TAG_inlined_subroutine entries and passed via GDB's block data.

When we step again the inlined frame unwinder moves us up the call
stack to the inner most frame at which point the frame is displayed as
normal, with the location for the address being looked up in the line
table.

As GDB uses the last line table entry for an address as "the" line to
report for that address it is critical that GDB maintain the order of
the line table entries.  In the first case, by reordering the line
table we report the wrong location.

I had to make a small adjustment in find_pc_sect_line in order to
correctly find the previous line in the line table.  In some line
tables I was seeing an actual line entry and an end of sequence marker
at the same address, before this commit these would reorder to move
the end of sequence marker before the line entry (end of sequence has
line number 0).  Now the end of sequence marker remains in its correct
location, and in order to find a previous line we should step backward
over any end of sequence markers.

As an example, the binary:
  gdb/testsuite/outputs/gdb.dwarf2/dw2-ranges-func/dw2-ranges-func-lo-cold

Has this line table before the patch:

  INDEX    LINE ADDRESS
  0          48 0x0000000000400487
  1         END 0x000000000040048e
  2          52 0x000000000040048e
  3          54 0x0000000000400492
  4          56 0x0000000000400497
  5         END 0x000000000040049a
  6          62 0x000000000040049a
  7         END 0x00000000004004a1
  8          66 0x00000000004004a1
  9          68 0x00000000004004a5
  10         70 0x00000000004004aa
  11         72 0x00000000004004b9
  12        END 0x00000000004004bc
  13         76 0x00000000004004bc
  14         78 0x00000000004004c0
  15         80 0x00000000004004c5
  16        END 0x00000000004004cc

And after this patch:

  INDEX    LINE ADDRESS
  0          48 0x0000000000400487
  1          52 0x000000000040048e
  2         END 0x000000000040048e
  3          54 0x0000000000400492
  4          56 0x0000000000400497
  5         END 0x000000000040049a
  6          62 0x000000000040049a
  7          66 0x00000000004004a1
  8         END 0x00000000004004a1
  9          68 0x00000000004004a5
  10         70 0x00000000004004aa
  11         72 0x00000000004004b9
  12        END 0x00000000004004bc
  13         76 0x00000000004004bc
  14         78 0x00000000004004c0
  15         80 0x00000000004004c5
  16        END 0x00000000004004cc

When calling find_pc_sect_line with the address 0x000000000040048e, in
both cases we find entry #3, we then try to find the previous entry,
which originally found this entry '2         52 0x000000000040048e',
after the patch it finds '2         END 0x000000000040048e', which
cases the lookup to fail.

By skipping the END marker after this patch we get back to the correct
entry, which is now #1: '1          52 0x000000000040048e', and
everything works again.

gdb/ChangeLog:

	* buildsym.c (lte_is_less_than): Delete.
	(buildsym_compunit::end_symtab_with_blockvector): Create local
	lambda function to sort line table entries, and use
	std::stable_sort instead of std::sort.
	* symtab.c (find_pc_sect_line): Skip backward over end of sequence
	markers when looking for a previous line.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-inline-stepping.c: New file.
	* gdb.dwarf2/dw2-inline-stepping.exp: New file.

Change-Id: Ia0309494be4cfd9dcc554f30209477f5f040b21b
2020-01-24 23:43:16 +00:00
Joel Brobecker b811d2c292 Update copyright year range in all GDB files.
gdb/ChangeLog:

        Update copyright year range in all GDB files.
2020-01-01 10:20:53 +04:00
Bernd Edlinger c296cbe681 Fix setting breakpoints or stepping on line 65535
This removes code that was present from the very first git revisison
7b4ac7e1ed from 1988.  It was in the
gdb/dbxread.c at the time (and makes more sense for dbx line info format
since line numbers are 16-bit entities in that debug format and debugging
files with more than 65535 lines would not work anyway) but moved from
there to gdb/buildsym.c which is used for dwarf line info as well, and
excluding an arbitrary line number does certainly not make sense nowadays.

Add a test case for line 65535

gdb:
2019-12-29  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* buildsym.c (buildsym_compunit::record_line): Do no longer ignore
	line 65535.

gdb/testsuite:
2019-12-29  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* gdb.base/line65535.exp: New file.
	* gdb.base/line65535.c: New file.
2019-12-29 22:34:29 +01:00
Christian Biesinger 4d4eaa3005 Make symbol_set_names a member function
This also renames it to make it clearer that this is not a cheap
function (to compute_and_set_names).  Also renames name to m_name
to make the implementation of the renamed function more readable.

Most of the places that access sym->m_name directly were also changed
to call linkage_name () instead, to make it clearer which name they
are accessing.

gdb/ChangeLog:

2019-12-26  Christian Biesinger  <cbiesinger@google.com>

	* ada-lang.c (ada_decode_symbol): Update.
	* buildsym.c (add_symbol_to_list): Update.
	* coffread.c (process_coff_symbol): Update.
	* ctfread.c (ctf_add_enum_member_cb): Update.
	(new_symbol): Update.
	(ctf_add_var_cb): Update.
	* dwarf2read.c (fixup_go_packaging): Update.
	(dwarf2_compute_name): Update.
	(new_symbol): Update.
	* jit.c (finalize_symtab): Update.
	* language.c (language_alloc_type_symbol): Update.
	* mdebugread.c (new_symbol): Update.
	* minsyms.c (minimal_symbol_reader::record_full): Update.
	(minimal_symbol_reader::install): Update.
	* psymtab.c (print_partial_symbols): Update.
	(psymbol_hash): Update.
	(psymbol_compare): Update.
	(add_psymbol_to_bcache): Update.
	(maintenance_check_psymtabs): Update.
	* stabsread.c (define_symbol): Update.
	* symtab.c (symbol_set_names): Rename to...
	(general_symbol_info::compute_and_set_names): ...this.
	(general_symbol_info::natural_name): Update.
	(general_symbol_info::search_name): Update.
	(fixup_section): Update.
	* symtab.h (struct general_symbol_info) <name>: Rename to...
	<m_name>: ...this.
	<compute_and_set_names>: Rename from...
	(symbol_set_names): ...this.
	(SYMBOL_SET_NAMES): Remove.
	(struct symbol) <ctor>: Update.

Change-Id: I8da1f10cab4e0b89f19d5750fa4e6e2ac8d2b24f
2019-12-27 01:41:35 -03:00
Christian Biesinger 987012b89b Replace SYMBOL_*_NAME accessors with member functions
Similar to the MSYMBOL version of this patch, improves readability
and will eventually allow making name private.

gdb/ChangeLog:

2019-11-22  Christian Biesinger  <cbiesinger@google.com>

	* ada-exp.y: Update.
	* ada-lang.c (sort_choices): Update.
	(ada_print_symbol_signature): Update.
	(resolve_subexp): Update.
	(ada_parse_renaming): Update.
	(ada_read_renaming_var_value): Update.
	(lesseq_defined_than): Update.
	(remove_extra_symbols): Update.
	(remove_irrelevant_renamings): Update.
	(ada_add_block_symbols): Update.
	(ada_collect_symbol_completion_matches): Update.
	(ada_is_renaming_symbol): Update.
	(aggregate_assign_from_choices): Update.
	(ada_evaluate_subexp): Update.
	(ada_has_this_exception_support): Update.
	(ada_is_non_standard_exception_sym): Update.
	(ada_add_exceptions_from_frame): Update.
	(ada_add_global_exceptions): Update.
	(ada_print_subexp): Update.
	* ax-gdb.c (gen_var_ref): Update.
	(gen_maybe_namespace_elt): Update.
	(gen_expr_for_cast): Update.
	(gen_expr): Update.
	* block.h: Update.
	* blockframe.c (find_pc_partial_function): Update.
	* breakpoint.c (print_breakpoint_location): Update.
	(update_static_tracepoint): Update.
	* btrace.c (ftrace_print_function_name): Update.
	(ftrace_function_switched): Update.
	* buildsym.c (find_symbol_in_list): Update.
	* c-exp.y: Update.
	* c-typeprint.c (c_print_typedef): Update.
	(c_type_print_template_args): Update.
	* cli/cli-cmds.c (edit_command): Update.
	(list_command): Update.
	(print_sal_location): Update.
	* coffread.c (patch_opaque_types): Update.
	(process_coff_symbol): Update.
	(coff_read_enum_type): Update.
	* compile/compile-c-symbols.c (c_symbol_substitution_name): Update.
	(convert_one_symbol): Update.
	(hash_symname): Update.
	(eq_symname): Update.
	* compile/compile-cplus-symbols.c (convert_one_symbol): Update.
	* compile/compile-cplus-types.c (debug_print_scope): Update.
	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update.
	* compile/compile-object-load.c (get_out_value_type): Update.
	* cp-namespace.c (cp_scan_for_anonymous_namespaces): Update.
	(search_symbol_list): Update.
	(cp_lookup_symbol_imports_or_template): Update.
	* cp-support.c (overload_list_add_symbol): Update.
	* ctfread.c (psymtab_to_symtab): Update.
	* dbxread.c (cp_set_block_scope): Update.
	* dictionary.c (iter_match_first_hashed): Update.
	(iter_match_next_hashed): Update.
	(insert_symbol_hashed): Update.
	(iter_match_next_linear): Update.
	* dictionary.h: Update.
	* dwarf2loc.c (func_get_frame_base_dwarf_block): Update.
	(locexpr_describe_location_piece): Update.
	(locexpr_describe_location_1): Update.
	(locexpr_generate_c_location): Update.
	(loclist_describe_location): Update.
	(loclist_generate_c_location): Update.
	* dwarf2read.c (dw2_debug_names_lookup_symbol): Update.
	(read_func_scope): Update.
	(process_enumeration_scope): Update.
	(new_symbol): Update.
	(dwarf2_const_value): Update.
	(dwarf2_symbol_mark_computed): Update.
	* eval.c (evaluate_funcall): Update.
	(evaluate_subexp_standard): Update.
	* expprint.c (print_subexp_standard): Update.
	(dump_subexp_body_standard): Update.
	* f-valprint.c (info_common_command_for_block): Update.
	* findvar.c (get_hosting_frame): Update.
	(default_read_var_value): Update.
	* go-lang.c (go_symbol_package_name): Update.
	* guile/scm-block.c (bkscm_print_block_smob): Update.
	* guile/scm-symbol.c (syscm_print_symbol_smob): Update.
	(gdbscm_symbol_name): Update.
	(gdbscm_symbol_linkage_name): Update.
	(gdbscm_symbol_print_name): Update.
	* infcall.c (get_function_name): Update.
	* infcmd.c (jump_command): Update.
	(finish_command): Update.
	* infrun.c (insert_exception_resume_breakpoint): Update.
	* linespec.c (canonicalize_linespec): Update.
	(create_sals_line_offset): Update.
	(convert_linespec_to_sals): Update.
	(complete_label): Update.
	(find_label_symbols_in_block): Update.
	* m2-typeprint.c (m2_print_typedef): Update.
	* mdebugread.c (mdebug_reg_to_regnum): Update.
	(parse_symbol): Update.
	(mylookup_symbol): Update.
	* mi/mi-cmd-stack.c (list_arg_or_local): Update.
	(list_args_or_locals): Update.
	* objc-lang.c (compare_selectors): Update.
	(info_selectors_command): Update.
	(compare_classes): Update.
	(info_classes_command): Update.
	(find_imps): Update.
	* p-typeprint.c (pascal_print_typedef): Update.
	* printcmd.c (build_address_symbolic): Update.
	(info_address_command): Update.
	(print_variable_and_value): Update.
	* python/py-framefilter.c (extract_sym): Update.
	(py_print_single_arg): Update.
	* python/py-symbol.c (sympy_str): Update.
	(sympy_get_name): Update.
	(sympy_get_linkage_name): Update.
	* python/python.c (gdbpy_rbreak): Update.
	* record-btrace.c (btrace_get_bfun_name): Update.
	(btrace_call_history): Update.
	* rust-lang.c (rust_print_typedef): Update.
	* solib-frv.c (frv_fdpic_find_canonical_descriptor): Update.
	* stabsread.c (stab_reg_to_regnum): Update.
	(define_symbol): Update.
	(read_enum_type): Update.
	(common_block_end): Update.
	(cleanup_undefined_types_1): Update.
	(scan_file_globals): Update.
	* stack.c (print_frame_arg): Update.
	(print_frame_args): Update.
	(find_frame_funname): Update.
	(info_frame_command_core): Update.
	(iterate_over_block_locals): Update.
	(print_block_frame_labels): Update.
	(do_print_variable_and_value): Update.
	(iterate_over_block_arg_vars): Update.
	(return_command): Update.
	* symmisc.c (dump_symtab_1): Update.
	(print_symbol): Update.
	* symtab.c (eq_symbol_entry): Update.
	(symbol_cache_dump): Update.
	(lookup_language_this): Update.
	(find_pc_sect_line): Update.
	(skip_prologue_sal): Update.
	(symbol_search::compare_search_syms): Update.
	(treg_matches_sym_type_name): Update.
	(search_symbols): Update.
	(print_symbol_info): Update.
	(rbreak_command): Update.
	(completion_list_add_symbol): Update.
	(find_gnu_ifunc): Update.
	(get_symbol_address): Update.
	(search_module_symbols): Update.
	(info_module_subcommand): Update.
	* symtab.h (SYMBOL_NATURAL_NAME): Remove.
	(SYMBOL_LINKAGE_NAME): Remove.
	(SYMBOL_DEMANGLED_NAME): Remove.
	(SYMBOL_PRINT_NAME): Remove.
	(SYMBOL_SEARCH_NAME): Remove.
	* tracepoint.c (set_traceframe_context): Update.
	(validate_actionline): Update.
	(collection_list::collect_symbol): Update.
	(encode_actions_1): Update.
	(info_scope_command): Update.
	(print_one_static_tracepoint_marker): Update.
	* typeprint.c (typedef_hash_table::add_template_parameters): Update.
	* valops.c (address_of_variable): Update.
	(find_overload_match): Update.
	(find_oload_champ): Update.

Change-Id: I76bdc8b44eea6876bf03af9d351f8e90cc0154b2
2019-11-22 12:05:14 -06:00
Christian Biesinger 468c0cbb32 Make struct symbol inherit from general_symbol_info
Since this is now no longer a POD, also give it a constructor that
initializes all fields. (I have considered overloading operator new
to zero-initialize the memory instead; let me know if you prefer that)

gdb/ChangeLog:

2019-11-12  Christian Biesinger  <cbiesinger@google.com>

	* ada-exp.y (write_ambiguous_var): Update.
	* buildsym.c (add_symbol_to_list): Update.
	* dwarf2read.c (read_variable): Update.
	(new_symbol): Update.
	* jit.c (finalize_symtab): Update.
	* language.c (language_alloc_type_symbol): Update.
	* symtab.c (fixup_symbol_section): Update.
	(initialize_objfile_symbol_1): Move code to...
	(initialize_objfile_symbol): ...here. Remove now-unnecessary memset.
	(allocate_symbol): Update.
	(allocate_template_symbol): Update.
	(get_symbol_address): Update.
	* symtab.h (struct symbol): Inherit from general_symbol_info instead
	of having as a field, and add a constructor.
	(SYMBOL_VALUE): Update.
	(SYMBOL_VALUE_ADDRESS): Update.
	(SET_SYMBOL_VALUE_ADDRESS): Update.
	(SYMBOL_VALUE_BYTES): Update.
	(SYMBOL_VALUE_COMMON_BLOCK): Update.
	(SYMBOL_BLOCK_VALUE): Update.
	(SYMBOL_VALUE_CHAIN): Update.
	(SYMBOL_LANGUAGE): Update.
	(SYMBOL_SECTION): Update.
	(SYMBOL_OBJ_SECTION): Update.
	(SYMBOL_SET_LANGUAGE): Update.
	(SYMBOL_SET_LINKAGE_NAME): Update.
	(SYMBOL_SET_NAMES): Update.
	(SYMBOL_NATURAL_NAME): Update.
	(SYMBOL_LINKAGE_NAME): Update.
	(SYMBOL_DEMANGLED_NAME): Update.
	(SYMBOL_SEARCH_NAME): Update.
	(SYMBOL_MATCHES_SEARCH_NAME): Update.
	(struct symbol): Update.
	(struct template_symbol): Update.
	(struct rust_vtable_symbol): Update.
	* xcoffread.c (SYMBOL_DUP): Update.

Change-Id: I05b1628455bcce3efaa101e65ef051708d17eb07
2019-11-12 15:21:35 -06:00
Christian Biesinger 39ef2f6256 Replace some more qsort calls with std::sort
This has better typesafety, avoids a function pointer indirection,
and can benefit from inlining.

gdb/ChangeLog:

2019-10-19  Christian Biesinger  <cbiesinger@google.com>

	* bcache.c (bcache::print_statistics): Use std::sort instead of qsort.
	* breakpoint.c (bp_locations_compare): Rename to...
	(bp_location_is_less_than): ...this, and change to std::sort semantics.
	(update_global_location_list): Use std::sort instead of qsort.
	* buildsym.c (compare_line_numbers): Rename to...
	(lte_is_less_than): ...this, and change to std::sort semantics.
	(buildsym_compunit::end_symtab_with_blockvector): Use std::sort
	instead of qsort.
	* disasm.c (compare_lines): Rename to...
	(line_is_less_than): ...this, and change to std::sort semantics.
	(do_mixed_source_and_assembly_deprecated): Call std::sort instead
	of qsort.
	* dwarf2-frame.c (qsort_fde_cmp): Rename to...
	(fde_is_less_than): ...this, and change to std::sort semantics.
	(dwarf2_build_frame_info): Call std::sort instead of qsort.
	* mdebugread.c (compare_blocks):
	(block_is_less_than): ...this, and change to std::sort semantics.
	(sort_blocks): Call std::sort instead of qsort.
	* objfiles.c (qsort_cmp): Rename to...
	(sort_cmp): ...this, and change to std::sort semantics.
	(update_section_map): Call std::sort instead of qsort.
	* remote.c (compare_pnums): Remove.
	(map_regcache_remote_table): Call std::sort instead of qsort.
	* utils.c (compare_positive_ints): Remove.
	* utils.h (compare_positive_ints): Remove.
	* xcoffread.c (compare_lte): Remove.
	(arrange_linetable): Call std::sort instead of qsort.

Change-Id: Ibcddce12a3d07448701e731b7150fa23611d86de
2019-10-19 15:45:33 -05:00
Tom Tromey 021887d88a Use obstack_strdup more
This changes gdb to use obstack_strdup when appropriate, rather than
the wordier obstack_copy0.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (SYMNAME_ALLOC, process_xcoff_symbol): Use
	obstack_strdup.
	* typeprint.c (typedef_hash_table::find_global_typedef): Use
	obstack_strdup.
	* symfile.c (allocate_compunit_symtab): Use obstack_strdup.
	* stabsread.c (common_block_start): Use obstack_strdup.
	* objfiles.c (set_objfile_main_name, objfile): Use
	obstack_strdup.
	* namespace.c (add_using_directive): Use obstack_strdup.
	* mdebugread.c (parse_symbol, parse_type): Use obstack_strdup.
	* jit.c (finalize_symtab): Use obstack_strdup.
	* dwarf2read.c (fixup_go_packaging, dwarf2_physname)
	(guess_partial_die_structure_name, partial_die_info::fixup)
	(dwarf2_name): Use obstack_strdup.
	* coffread.c (coff_read_struct_type, coff_read_enum_type): Use
	obstack_strdup.
	* c-exp.y (scan_macro_expansion): Use obstack_strdup.
	* buildsym.c (buildsym_compunit::end_symtab_with_blockvector): Use
	obstack_strdup.
	* ada-lang.c (ada_decode_symbol): Use obstack_strdup.
2019-08-06 20:08:48 -06:00
Tom Tromey 4de283e4b5 Revert the header-sorting patch
Andreas Schwab and John Baldwin pointed out some bugs in the header
sorting patch; and I noticed that the output was not correct when
limited to a subset of files (a bug in my script).

So, I'm reverting the patch.  I may try again after fixing the issues
pointed out.

gdb/ChangeLog
2019-04-05  Tom Tromey  <tom@tromey.com>

	Revert the header-sorting patch.
	* ft32-tdep.c: Revert.
	* frv-tdep.c: Revert.
	* frv-linux-tdep.c: Revert.
	* frame.c: Revert.
	* frame-unwind.c: Revert.
	* frame-base.c: Revert.
	* fork-child.c: Revert.
	* findvar.c: Revert.
	* findcmd.c: Revert.
	* filesystem.c: Revert.
	* filename-seen-cache.h: Revert.
	* filename-seen-cache.c: Revert.
	* fbsd-tdep.c: Revert.
	* fbsd-nat.h: Revert.
	* fbsd-nat.c: Revert.
	* f-valprint.c: Revert.
	* f-typeprint.c: Revert.
	* f-lang.c: Revert.
	* extension.h: Revert.
	* extension.c: Revert.
	* extension-priv.h: Revert.
	* expprint.c: Revert.
	* exec.h: Revert.
	* exec.c: Revert.
	* exceptions.c: Revert.
	* event-top.c: Revert.
	* event-loop.c: Revert.
	* eval.c: Revert.
	* elfread.c: Revert.
	* dwarf2read.h: Revert.
	* dwarf2read.c: Revert.
	* dwarf2loc.c: Revert.
	* dwarf2expr.h: Revert.
	* dwarf2expr.c: Revert.
	* dwarf2-frame.c: Revert.
	* dwarf2-frame-tailcall.c: Revert.
	* dwarf-index-write.h: Revert.
	* dwarf-index-write.c: Revert.
	* dwarf-index-common.c: Revert.
	* dwarf-index-cache.h: Revert.
	* dwarf-index-cache.c: Revert.
	* dummy-frame.c: Revert.
	* dtrace-probe.c: Revert.
	* disasm.h: Revert.
	* disasm.c: Revert.
	* disasm-selftests.c: Revert.
	* dictionary.c: Revert.
	* dicos-tdep.c: Revert.
	* demangle.c: Revert.
	* dcache.h: Revert.
	* dcache.c: Revert.
	* darwin-nat.h: Revert.
	* darwin-nat.c: Revert.
	* darwin-nat-info.c: Revert.
	* d-valprint.c: Revert.
	* d-namespace.c: Revert.
	* d-lang.c: Revert.
	* ctf.c: Revert.
	* csky-tdep.c: Revert.
	* csky-linux-tdep.c: Revert.
	* cris-tdep.c: Revert.
	* cris-linux-tdep.c: Revert.
	* cp-valprint.c: Revert.
	* cp-support.c: Revert.
	* cp-namespace.c: Revert.
	* cp-abi.c: Revert.
	* corelow.c: Revert.
	* corefile.c: Revert.
	* continuations.c: Revert.
	* completer.h: Revert.
	* completer.c: Revert.
	* complaints.c: Revert.
	* coffread.c: Revert.
	* coff-pe-read.c: Revert.
	* cli-out.h: Revert.
	* cli-out.c: Revert.
	* charset.c: Revert.
	* c-varobj.c: Revert.
	* c-valprint.c: Revert.
	* c-typeprint.c: Revert.
	* c-lang.c: Revert.
	* buildsym.c: Revert.
	* buildsym-legacy.c: Revert.
	* build-id.h: Revert.
	* build-id.c: Revert.
	* btrace.c: Revert.
	* bsd-uthread.c: Revert.
	* breakpoint.h: Revert.
	* breakpoint.c: Revert.
	* break-catch-throw.c: Revert.
	* break-catch-syscall.c: Revert.
	* break-catch-sig.c: Revert.
	* blockframe.c: Revert.
	* block.c: Revert.
	* bfin-tdep.c: Revert.
	* bfin-linux-tdep.c: Revert.
	* bfd-target.c: Revert.
	* bcache.c: Revert.
	* ax-general.c: Revert.
	* ax-gdb.h: Revert.
	* ax-gdb.c: Revert.
	* avr-tdep.c: Revert.
	* auxv.c: Revert.
	* auto-load.c: Revert.
	* arm-wince-tdep.c: Revert.
	* arm-tdep.c: Revert.
	* arm-symbian-tdep.c: Revert.
	* arm-pikeos-tdep.c: Revert.
	* arm-obsd-tdep.c: Revert.
	* arm-nbsd-tdep.c: Revert.
	* arm-nbsd-nat.c: Revert.
	* arm-linux-tdep.c: Revert.
	* arm-linux-nat.c: Revert.
	* arm-fbsd-tdep.c: Revert.
	* arm-fbsd-nat.c: Revert.
	* arm-bsd-tdep.c: Revert.
	* arch-utils.c: Revert.
	* arc-tdep.c: Revert.
	* arc-newlib-tdep.c: Revert.
	* annotate.h: Revert.
	* annotate.c: Revert.
	* amd64-windows-tdep.c: Revert.
	* amd64-windows-nat.c: Revert.
	* amd64-tdep.c: Revert.
	* amd64-sol2-tdep.c: Revert.
	* amd64-obsd-tdep.c: Revert.
	* amd64-obsd-nat.c: Revert.
	* amd64-nbsd-tdep.c: Revert.
	* amd64-nbsd-nat.c: Revert.
	* amd64-nat.c: Revert.
	* amd64-linux-tdep.c: Revert.
	* amd64-linux-nat.c: Revert.
	* amd64-fbsd-tdep.c: Revert.
	* amd64-fbsd-nat.c: Revert.
	* amd64-dicos-tdep.c: Revert.
	* amd64-darwin-tdep.c: Revert.
	* amd64-bsd-nat.c: Revert.
	* alpha-tdep.c: Revert.
	* alpha-obsd-tdep.c: Revert.
	* alpha-nbsd-tdep.c: Revert.
	* alpha-mdebug-tdep.c: Revert.
	* alpha-linux-tdep.c: Revert.
	* alpha-linux-nat.c: Revert.
	* alpha-bsd-tdep.c: Revert.
	* alpha-bsd-nat.c: Revert.
	* aix-thread.c: Revert.
	* agent.c: Revert.
	* addrmap.c: Revert.
	* ada-varobj.c: Revert.
	* ada-valprint.c: Revert.
	* ada-typeprint.c: Revert.
	* ada-tasks.c: Revert.
	* ada-lang.c: Revert.
	* aarch64-tdep.c: Revert.
	* aarch64-ravenscar-thread.c: Revert.
	* aarch64-newlib-tdep.c: Revert.
	* aarch64-linux-tdep.c: Revert.
	* aarch64-linux-nat.c: Revert.
	* aarch64-fbsd-tdep.c: Revert.
	* aarch64-fbsd-nat.c: Revert.
	* aarch32-linux-nat.c: Revert.
2019-04-06 13:47:34 -06:00
Tom Tromey d55e5aa6b2 Sort includes for files gdb/[a-f]*.[chyl].
This patch sorts the include files for the files [a-f]*.[chyl].
The patch was written by a script.

Tested by the buildbot.

I will follow up with patches to sort the remaining files, by sorting
a subset, testing them, and then checking them in.

gdb/ChangeLog
2019-04-05  Tom Tromey  <tom@tromey.com>

	* ft32-tdep.c: Sort headers.
	* frv-tdep.c: Sort headers.
	* frv-linux-tdep.c: Sort headers.
	* frame.c: Sort headers.
	* frame-unwind.c: Sort headers.
	* frame-base.c: Sort headers.
	* fork-child.c: Sort headers.
	* findvar.c: Sort headers.
	* findcmd.c: Sort headers.
	* filesystem.c: Sort headers.
	* filename-seen-cache.h: Sort headers.
	* filename-seen-cache.c: Sort headers.
	* fbsd-tdep.c: Sort headers.
	* fbsd-nat.h: Sort headers.
	* fbsd-nat.c: Sort headers.
	* f-valprint.c: Sort headers.
	* f-typeprint.c: Sort headers.
	* f-lang.c: Sort headers.
	* extension.h: Sort headers.
	* extension.c: Sort headers.
	* extension-priv.h: Sort headers.
	* expprint.c: Sort headers.
	* exec.h: Sort headers.
	* exec.c: Sort headers.
	* exceptions.c: Sort headers.
	* event-top.c: Sort headers.
	* event-loop.c: Sort headers.
	* eval.c: Sort headers.
	* elfread.c: Sort headers.
	* dwarf2read.h: Sort headers.
	* dwarf2read.c: Sort headers.
	* dwarf2loc.c: Sort headers.
	* dwarf2expr.h: Sort headers.
	* dwarf2expr.c: Sort headers.
	* dwarf2-frame.c: Sort headers.
	* dwarf2-frame-tailcall.c: Sort headers.
	* dwarf-index-write.h: Sort headers.
	* dwarf-index-write.c: Sort headers.
	* dwarf-index-common.c: Sort headers.
	* dwarf-index-cache.h: Sort headers.
	* dwarf-index-cache.c: Sort headers.
	* dummy-frame.c: Sort headers.
	* dtrace-probe.c: Sort headers.
	* disasm.h: Sort headers.
	* disasm.c: Sort headers.
	* disasm-selftests.c: Sort headers.
	* dictionary.c: Sort headers.
	* dicos-tdep.c: Sort headers.
	* demangle.c: Sort headers.
	* dcache.h: Sort headers.
	* dcache.c: Sort headers.
	* darwin-nat.h: Sort headers.
	* darwin-nat.c: Sort headers.
	* darwin-nat-info.c: Sort headers.
	* d-valprint.c: Sort headers.
	* d-namespace.c: Sort headers.
	* d-lang.c: Sort headers.
	* ctf.c: Sort headers.
	* csky-tdep.c: Sort headers.
	* csky-linux-tdep.c: Sort headers.
	* cris-tdep.c: Sort headers.
	* cris-linux-tdep.c: Sort headers.
	* cp-valprint.c: Sort headers.
	* cp-support.c: Sort headers.
	* cp-namespace.c: Sort headers.
	* cp-abi.c: Sort headers.
	* corelow.c: Sort headers.
	* corefile.c: Sort headers.
	* continuations.c: Sort headers.
	* completer.h: Sort headers.
	* completer.c: Sort headers.
	* complaints.c: Sort headers.
	* coffread.c: Sort headers.
	* coff-pe-read.c: Sort headers.
	* cli-out.h: Sort headers.
	* cli-out.c: Sort headers.
	* charset.c: Sort headers.
	* c-varobj.c: Sort headers.
	* c-valprint.c: Sort headers.
	* c-typeprint.c: Sort headers.
	* c-lang.c: Sort headers.
	* buildsym.c: Sort headers.
	* buildsym-legacy.c: Sort headers.
	* build-id.h: Sort headers.
	* build-id.c: Sort headers.
	* btrace.c: Sort headers.
	* bsd-uthread.c: Sort headers.
	* breakpoint.h: Sort headers.
	* breakpoint.c: Sort headers.
	* break-catch-throw.c: Sort headers.
	* break-catch-syscall.c: Sort headers.
	* break-catch-sig.c: Sort headers.
	* blockframe.c: Sort headers.
	* block.c: Sort headers.
	* bfin-tdep.c: Sort headers.
	* bfin-linux-tdep.c: Sort headers.
	* bfd-target.c: Sort headers.
	* bcache.c: Sort headers.
	* ax-general.c: Sort headers.
	* ax-gdb.h: Sort headers.
	* ax-gdb.c: Sort headers.
	* avr-tdep.c: Sort headers.
	* auxv.c: Sort headers.
	* auto-load.c: Sort headers.
	* arm-wince-tdep.c: Sort headers.
	* arm-tdep.c: Sort headers.
	* arm-symbian-tdep.c: Sort headers.
	* arm-pikeos-tdep.c: Sort headers.
	* arm-obsd-tdep.c: Sort headers.
	* arm-nbsd-tdep.c: Sort headers.
	* arm-nbsd-nat.c: Sort headers.
	* arm-linux-tdep.c: Sort headers.
	* arm-linux-nat.c: Sort headers.
	* arm-fbsd-tdep.c: Sort headers.
	* arm-fbsd-nat.c: Sort headers.
	* arm-bsd-tdep.c: Sort headers.
	* arch-utils.c: Sort headers.
	* arc-tdep.c: Sort headers.
	* arc-newlib-tdep.c: Sort headers.
	* annotate.h: Sort headers.
	* annotate.c: Sort headers.
	* amd64-windows-tdep.c: Sort headers.
	* amd64-windows-nat.c: Sort headers.
	* amd64-tdep.c: Sort headers.
	* amd64-sol2-tdep.c: Sort headers.
	* amd64-obsd-tdep.c: Sort headers.
	* amd64-obsd-nat.c: Sort headers.
	* amd64-nbsd-tdep.c: Sort headers.
	* amd64-nbsd-nat.c: Sort headers.
	* amd64-nat.c: Sort headers.
	* amd64-linux-tdep.c: Sort headers.
	* amd64-linux-nat.c: Sort headers.
	* amd64-fbsd-tdep.c: Sort headers.
	* amd64-fbsd-nat.c: Sort headers.
	* amd64-dicos-tdep.c: Sort headers.
	* amd64-darwin-tdep.c: Sort headers.
	* amd64-bsd-nat.c: Sort headers.
	* alpha-tdep.c: Sort headers.
	* alpha-obsd-tdep.c: Sort headers.
	* alpha-nbsd-tdep.c: Sort headers.
	* alpha-mdebug-tdep.c: Sort headers.
	* alpha-linux-tdep.c: Sort headers.
	* alpha-linux-nat.c: Sort headers.
	* alpha-bsd-tdep.c: Sort headers.
	* alpha-bsd-nat.c: Sort headers.
	* aix-thread.c: Sort headers.
	* agent.c: Sort headers.
	* addrmap.c: Sort headers.
	* ada-varobj.c: Sort headers.
	* ada-valprint.c: Sort headers.
	* ada-typeprint.c: Sort headers.
	* ada-tasks.c: Sort headers.
	* ada-lang.c: Sort headers.
	* aarch64-tdep.c: Sort headers.
	* aarch64-ravenscar-thread.c: Sort headers.
	* aarch64-newlib-tdep.c: Sort headers.
	* aarch64-linux-tdep.c: Sort headers.
	* aarch64-linux-nat.c: Sort headers.
	* aarch64-fbsd-tdep.c: Sort headers.
	* aarch64-fbsd-nat.c: Sort headers.
	* aarch32-linux-nat.c: Sort headers.
2019-04-05 19:09:35 -06:00
Tom Tromey 25629dfdb4 C++-ify bcache
This somewhat C++-ifies bcache.  It replaces bcache_xmalloc and
bcache_xfree with constructors; changes some functions into methods;
and changes various structures to include a bcache directly (as
opposed to a pointer to a bcache).

Tested by the buildbot.

gdb/ChangeLog
2019-03-07  Tom Tromey  <tom@tromey.com>

	* symmisc.c (print_symbol_bcache_statistics): Update.
	(print_objfile_statistics): Update.
	* symfile.c (allocate_symtab): Update.
	* stabsread.c: Don't include bcache.h.
	* psymtab.h (struct psymbol_bcache): Don't declare.
	(class psymtab_storage) <psymbol_cache>: Now a bcache.
	(psymbol_bcache_init, psymbol_bcache_free)
	(psymbol_bcache_get_bcache): Don't declare.
	* psymtab.c (struct psymbol_bcache): Remove.
	(psymtab_storage::psymtab_storage): Update.
	(psymtab_storage::~psymtab_storage): Update.
	(psymbol_bcache_init, psymbol_bcache_free)
	(psymbol_bcache_get_bcache, psymbol_bcache_full): Remove.
	(add_psymbol_to_bcache): Update.
	(allocate_psymtab): Update.
	* objfiles.h (struct objfile_per_bfd_storage) <filename_cache,
	macro_cache>: No longer pointers.
	* objfiles.c (get_objfile_bfd_data): Don't call bcache_xmalloc.
	(free_objfile_per_bfd_storage): Don't call bcache_xfree.
	* macrotab.c (macro_bcache): Update.
	* macroexp.c: Don't include bcache.h.
	* gdbtypes.c (check_types_worklist): Update.
	(types_deeply_equal): Remove TRY/CATCH.  Update.
	* elfread.c (elf_symtab_read): Update.
	* dwarf2read.c: Don't include bcache.h.
	* buildsym.c (buildsym_compunit::get_macro_table): Update.
	* bcache.h (bcache, bcache_full, bcache_xffree, bcache_xmalloc)
	(print_bcache_statistics, bcache_memory_used): Don't declare.
	(struct bcache): Move from bcache.c.  Add constructor, destructor,
	methods.  Rename all data members.
	* bcache.c (struct bcache): Move to bcache.h.
	(bcache::expand_hash_table): Rename from expand_hash_table.
	(bcache): Remove.
	(bcache::insert): Rename from bcache_full.
	(bcache::compare): Rename from bcache_compare.
	(bcache_xmalloc): Remove.
	(bcache::~bcache): Rename from bcache_xfree.
	(bcache::print_statistics): Rename from print_bcache_statistics.
	(bcache::memory_used): Rename from bcache_memory_used.
2019-03-07 10:48:02 -07:00
Keith Seitz b026f59345 gdb/23712: Use new multidictionary API
This patch builds on the previous by enabling the `new' multidictionary
API.  A lot of the hunks are simply textual replacements of "dict_"
with "mdict_" and similar transformations.

A word of warning, even with the use of multidictionaries, the code
still does not satisfactorily fix the reported problems with gdb/23712
(or gdb/23010). We still have additional changes to make before that
happens.

gdb/ChangeLog:

	PR gdb/23712
	PR symtab/23010
	* dictionary.h (struct dictionary): Replace declaration with
	multidictionary.
	(dict_create_hashed, dict_create_hashed_expandable)
	(dict_create_linear, dict_create_linear_expandable)
	(dict_free, dict_add_symbol, dict_add_pending, dict_empty)
	(dict_iterator_first, dict_iterator_next, dict_iter_match_first)
	(dict_iter_match_next, dict_size): Rename to "mdict_" versions
	taking multidictionary argument.
	[ALL_DICT_SYMBOLS]: Update for multidictionary.
	* block.h (struct block) <dict>: Change to multidictionary
	and rename `multidict'.
	* block.c, buildsym.c, jit.c, mdebugread.c, objfiles.c,
	symmisc.c: Update all dictionary references to multidictionary.
2019-01-10 13:57:08 -08:00
Tom Tromey 5accd1a07e Remove ALL_COMPUNIT_FILETABS
This removes ALL_COMPUNIT_FILETABS, replacing its uses with ranged for
loops.

Because this is still used in the ALL_OBJFILE_FILETABS macro, in some
places a declaration had to be removed or renamed to avoid shadowing.

gdb/ChangeLog
2019-01-09  Tom Tromey  <tom@tromey.com>

	* symtab.h (ALL_COMPUNIT_FILETABS): Remove.
	(compunit_filetabs): New.
	* symtab.c (iterate_over_some_symtabs, find_pc_sect_line): Use
	compunit_filetabs.
	(info_sources_command, make_source_files_completion_list): Remove
	declaration.
	* symmisc.c (print_objfile_statistics, dump_objfile)
	(maintenance_print_symbols): Remove declaration.
	(maintenance_info_symtabs): Use compunit_filetabs.
	(maintenance_info_line_tables): Likewise.
	* source.c (select_source_symtab): Change local variable name.
	(forget_cached_source_info_for_objfile): Remove declaration.
	* objfiles.h (ALL_OBJFILE_FILETABS): Use compunit_filetabs.
	* objfiles.c (objfile_relocate1): Remove declaration.
	* mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Remove
	declaration.
	* maint.c (count_symtabs_and_blocks): Use compunit_filetabs.
	* coffread.c (coff_symtab_read): Remove declaration.
	* buildsym.c (buildsym_compunit::end_symtab_with_blockvector): Use
	compunit_filetabs.
2019-01-09 18:28:15 -07:00
Joel Brobecker 42a4f53d2b Update copyright year range in all GDB files.
This commit applies all changes made after running the gdb/copyright.py
script.

Note that one file was flagged by the script, due to an invalid
copyright header
(gdb/unittests/basic_string_view/element_access/char/empty.cc).
As the file was copied from GCC's libstdc++-v3 testsuite, this commit
leaves this file untouched for the time being; a patch to fix the header
was sent to gcc-patches first.

gdb/ChangeLog:

	Update copyright year range in all GDB files.
2019-01-01 10:01:51 +04:00
Keith Seitz cbb09508e4 Rename remaining members of buildsym_compunit to start with "m_"
This renames all the remaining members of buildsym_compunit to start
with "m_" to follow the general naming convention.

gdb/ChangeLog
2018-07-20  Keith Seitz  <keiths@redhat.com>

	* buildsym.h (struct buildsym_compunit) <m_objfile, m_subfiles,
	m_main_subfile, m_comp_dir, m_producer, m_debugformat,
	m_compunit_symtab, m_language>: Add "m_" prefix.
	Update all uses.
	* buildsym.c: Update all uses.
2018-07-20 09:42:56 -06:00
Tom Tromey 0baae8dbd3 Introduce buildsym-legacy.h
This introduces a new header, buildsym-legacy.h, and changes all the
symbol readers to use it.  The idea is to put the function-based
interface, that relies on the buildsym_compunit global, into a
separate header.  Then when a symbol reader is updated to use the new
interface, it can simply not include buildsym-legacy.h, so it's easy
to be sure that the new API is used everywhere.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* xcoffread.c: Include buildsym-legacy.h.
	* windows-nat.c: Include buildsym-legacy.h.
	* stabsread.c: Include buildsym-legacy.h.
	* mdebugread.c: Include buildsym-legacy.h.
	* buildsym-legacy.h: New file.
	* buildsym-legacy.c: New file, from buildsym.c.
	* go32-nat.c: Include buildsym-legacy.h.
	* dwarf2read.c: Include buildsym-legacy.h.
	* dbxread.c: Include buildsym-legacy.h.
	* cp-namespace.c: Include buildsym-legacy.h.
	* coffread.c: Include buildsym-legacy.h.
	* buildsym.h: Move some contents to buildsym-legacy.h.
	* buildsym.c: Include buildsym-legacy.h.  Move many functions to
	buildsym-legacy.c.
	* Makefile.in (HFILES_NO_SRCDIR): Add buildsym-legacy.h.
2018-07-20 09:42:53 -06:00
Tom Tromey ab209f6fa9 Move struct buildsym_compunit to buildsym.h
This moves struct buildsym_compunit to buildsym.h.  Now that the
members are private, and it no longer affects any global state in
buildsym.c, an instance can be used directly for symtab creation.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* buildsym.h (struct buildsym_compunit): Move from buildsym.c.
	* buildsym.c (struct buildsym_compunit): Move to buildsym.h.
	(buildsym_compunit::buildsym_compunit)
	(buildsym_compunit::~buildsym_compunit)
	(buildsym_compunit::get_macro_table): Define.
2018-07-20 09:42:52 -06:00
Tom Tromey 74c72eac23 Remove reset_symtab_globals
This patch arranges for the remaining buildsym global --
buildsym_compunit -- to only be cleared by the wrapper functions, not
by methods on struct buildsym_compunit.  In the process,
reset_symtab_globals is removed.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* buildsym.c (reset_symtab_globals): Remove.
	(buildsym_compunit::end_symtab_from_static_block): Update.
	(buildsym_compunit::augment_type_symtab): Update.
	(end_symtab_from_static_block): Call free_buildsym_compunit.
	(augment_type_symtab, end_symtab, end_expandable_symtab):
	Likewise.
2018-07-20 09:42:51 -06:00
Tom Tromey 4a2125f531 Add many methods to buildsym_compunit
This adds many methods to buildsym_compunit and makes the data members
private.  Essentially the entire buildsym API is now available as a
method on buildsym_compunit.  However, standalone functions are still
provided, as this is what the sybmol readers actually use.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* buildsym.c (buildsym_compunit::buildsym_compunit): Do more
	initialization.
	(buildsym_compunit): Add new constructor.
	(struct buildsym_compunit) <get_last_source_file, finish_block,
	record_block_range, start_subfile, patch_subfile_names,
	push_subfile, pop_subfile, record_line, get_compunit_symtab,
	set_last_source_start_addr, get_last_source_start_addr,
	get_local_using_directives, set_local_using_directives,
	get_global_using_directives, outermost_context_p,
	get_current_context_stack, get_context_stack_depth,
	get_current_subfile, get_local_symbols, get_file_symbols,
	get_global_symbols, record_debugformat, record_producer,
	push_context, pop_context, end_symtab_get_static_block,
	end_symtab_from_static_block, end_symtab, end_expandable_symtab>:
	New public methods.
	<record_pending_block, finish_block_internal, make_blockvector,
	watch_main_source_file_lossage, end_symtab_with_blockvector>: New
	private methods.
	Update all users.
2018-07-20 09:42:50 -06:00
Tom Tromey 6b213a4778 Remove parameter from record_pending_block
This removes a redundant parameter from record_pending_block.  It also
moves record_pending_block earlier in the file, so that a forward
declaration is no longer needed.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* buildsym.c (record_pending_block): Move earlier.  Remove objfile
	parameter.
	(finish_block_internal): Update.
2018-07-20 09:42:49 -06:00
Tom Tromey b80a981d08 Remove EXTERN from buildsym.h
Nothing in buildsym.h relies on the "EXTERN" method of
declaration/definition, so remove the traces.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* buildsym.h (EXTERN): Don't define or undef.
	* buildsym.c (EXTERN): Don't define.
2018-07-20 09:42:49 -06:00
Tom Tromey ddb7060226 Remove a TODO
This removes a TODO comment -- the work has been done.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* buildsym.c: Remove TODO comment.
2018-07-20 09:42:48 -06:00
Tom Tromey b37dd3bcaa Remove buildsym_init
Now that buildsym_init does nothing, it can be removed.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* coffread.c (coff_symtab_read): Update.
	* xcoffread.c (xcoff_psymtab_to_symtab_1): Update.
	(xcoff_new_init): Update.
	* mipsread.c (mipscoff_new_init): Update.
	* mdebugread.c (mdebug_build_psymtabs): Update.
	* elfread.c (elf_new_init): Update.
	* dwarf2read.c (process_full_comp_unit, process_full_type_unit):
	Update.
	* dbxread.c (dbx_new_init, dbx_psymtab_to_symtab_1)
	(coffstab_build_psymtabs, elfstab_build_psymtabs)
	(stabsect_build_psymtabs): Update.
	* buildsym.h (buildsym_init): Don't declare.
	* buildsym.c: Update comment.
	(prepare_for_building): Remove.
	(start_symtab, restart_symtab): Update.
	(reset_symtab_globals): Update comment.
	(buildsym_init): Remove.
2018-07-20 09:42:47 -06:00
Tom Tromey e148f09d75 Move the symbol lists to buildsym_compunit
This moves the global symbol lists into buildsym_compunit, adds
accessors, and updates all the users.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (read_xcoff_symtab, process_xcoff_symbol): Update.
	* stabsread.c (patch_block_stabs, define_symbol, read_type)
	(read_enum_type, common_block_start, common_block_end)
	(cleanup_undefined_types_1, finish_global_stabs): Update.
	* mdebugread.c (psymtab_to_symtab_1): Update.
	* dwarf2read.c (fixup_go_packaging, read_func_scope)
	(read_lexical_block_scope, new_symbol): Update.
	* dbxread.c (process_one_symbol): Update.
	* coffread.c (coff_symtab_read, process_coff_symbol)
	(coff_read_enum_type): Update.
	* buildsym.h (file_symbols, global_symbols, local_symbols): Don't
	declare.
	(get_local_symbols, get_file_symbols, get_global_symbols): New
	functions.
	* buildsym.c (~buildsym_compunit): Clean up m_file_symbols and
	m_global_symbols.
	<m_file_symbols, m_local_symbols, m_global_symbols>: New members.
	(~scoped_free_pendings): Update.
	(finish_block, prepare_for_building, reset_symtab_globals)
	(end_symtab_get_static_block, end_symtab_with_blockvector)
	(augment_type_symtab, push_context): Update.
	(get_local_symbols, get_file_symbols, get_global_symbols): New
	functions.
	(buildsym_init): Update.
2018-07-20 09:42:46 -06:00
Tom Tromey 1d376700df Remove free_pendings
buildsym.c currently keeps a free list of "struct pending"s.  However,
this didn't seem necessary to me, and so this patch removes the free
list.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* buildsym.c (free_pendings): Remove.
	(add_symbol_to_list, scoped_free_pendings)
	(finish_block_internal, buildsym_init): Update.
2018-07-20 09:42:44 -06:00
Tom Tromey c233e9c641 Remove the "listhead" argument from finish_block
finish_block is only ever called with "&local_symbols" as the
"listhead" argument.  So, remove this argument.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (read_xcoff_symtab): Update.
	* dwarf2read.c (read_func_scope, read_lexical_block_scope):
	Update.
	* dbxread.c (process_one_symbol): Update.
	* coffread.c (coff_symtab_read): Update.
	* buildsym.h (finish_block): Update.
	* buildsym.c (finish_block): Remove "listhead" argument.
	(end_symtab_get_static_block): Update.
2018-07-20 09:42:44 -06:00
Tom Tromey 5ac045503d Move pending_blocks and pending_block_obstack to buildsym_compunit
This moves the pending_blocks and pending_block_obstack into
buildsym_compunit.

The obstack could perhaps be merged with the addrmap obstack, but I
did not do that in this series.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* buildsym.h (class scoped_free_pendings): Remove constructor.
	* buildsym.c (struct buildsym_compunit) <free_pending_blocks>: New
	method.
	<m_pending_block_obstack, m_pending_blocks>: New members.
	(pending_block_obstack, pending_blocks): Remove.
	(scoped_free_pendings::scoped_free_pendings): Default.
	(~scoped_free_pendings): Update.
	(free_pending_blocks): Remove.
	(finish_block_internal, record_pending_block, make_blockvector)
	(end_symtab_get_static_block, augment_type_symtab, push_context)
	(buildsym_init): Update.
2018-07-20 09:42:43 -06:00
Tom Tromey 7ea05a7b63 Move pending addrmap globals to buildsym_compunit
This moves the pending addrmap-related globals into buildsym_compunit.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* buildsym.c (struct buildsym_compunit) <m_pending_addrmap,
	m_pending_addrmap_obstack, m_pending_addrmap_interesting>: New
	members.
	(pending_addrmap, pending_addrmap_obstack)
	(pending_addrmap_interesting): Remove.
	(scoped_free_pendings, record_block_range, make_blockvector)
	(prepare_for_building, reset_symtab_globals, buildsym_init):
	Update.
2018-07-20 09:42:43 -06:00
Tom Tromey 3c65e5b31c Move current_subfile to buildsym_compunit
This moves the global current_subfile into buildsym_compunit.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (process_linenos): Update.
	* stabsread.c (define_symbol, read_type, read_enum_type): Update.
	* mdebugread.c (psymtab_to_symtab_1): Update.
	* dwarf2read.c (setup_type_unit_groups)
	(lnp_state_machine::handle_set_file, dwarf_record_line_p)
	(lnp_state_machine::record_line, dwarf_decode_lines): Update.
	* dbxread.c (process_one_symbol): Update.
	* coffread.c (coff_symtab_read, enter_linenos)
	(process_coff_symbol): Update.
	* buildsym.h (current_subfile): Don't declare.
	(get_current_subfile): Declare.
	* buildsym.c (struct buildsym_compunit) <m_current_subfile>: New
	member.
	(start_subfile, free_buildsym_compunit, push_subfile)
	(prepare_for_building, start_symtab): Update.
	(get_current_subfile): New function.
2018-07-20 09:42:42 -06:00
Tom Tromey a60f3166aa Move the context stack to buildsym_compunit
This moves the context stack globals to be members of
buildsym_compunit, changing the type to a std::vector in the process.

Because the callers expect the context stack object to be valid after
being popped, at Simon's suggestion I've changed pop_context to return
the object rather than the pointer.

gdb/ChangeLog
2018-07-20  Tom Tromey  <tom@tromey.com>

	* coffread.c (coff_symtab_read): Update.
	* xcoffread.c (read_xcoff_symtab): Update.
	* dwarf2read.c (new_symbol): Update.
	(read_func_scope, read_lexical_block_scope): Update.
	* dbxread.c (process_one_symbol): Update.
	* buildsym.h (context_stack, context_stack_depth): Don't declare.
	(outermost_context_p): Remove macro.
	(outermost_context_p, get_current_context_stack)
	(get_context_stack_depth): Declare.
	(pop_context): Return struct context_stack.
	* buildsym.c (struct buildsym_compunit) <m_context_stack: New
	member.
	(context_stack_size): Remove.
	(INITIAL_CONTEXT_STACK_SIZE): Remove.
	(prepare_for_building, end_symtab_get_static_block)
	(augment_type_symtab, push_context): Update.
	(pop_context): Return struct context_stack.
	(outermost_context_p, get_current_context_stack)
	(get_context_stack_depth): New functions.
	(buildsym_init): Update.
2018-07-20 09:42:41 -06:00
Tom Tromey 6cccc9a891 Move the using directives to buildsym_compunit
This moves the globals local_using_directives and
global_using_directives to be members of buildsym_compunit, and adds
the necessary accessors.

gdb/ChangeLog
2018-07-16  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (using_directives, read_func_scope)
	(read_lexical_block_scope): Update.
	* cp-namespace.c (cp_scan_for_anonymous_namespaces): Update.
	* buildsym.h (local_using_directives, global_using_directives):
	Don't declare.
	(get_local_using_directives, set_local_using_directives)
	(get_global_using_directives): Declare.
	* buildsym.c (struct buildsym_compunit) <m_local_using_directives,
	m_global_using_directives>: New members.
	(finish_block_internal, prepare_for_building)
	(reset_symtab_globals, end_symtab_get_static_block)
	(push_context): Update.
	(get_local_using_directives, set_local_using_directives)
	(get_global_using_directives): New functions.
	(buildsym_init): Update.
2018-07-16 08:55:22 -06:00
Tom Tromey 652788a731 Make free_pending_blocks static
free_pending_blocks can be static because scoped_free_pendings (et al)
arrange for it to be NULL in the "steady state".  This removes a
couple of unnecessary calls to free_pending_blocks and changes it to
be static.

gdb/ChangeLog
2018-07-16  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_initial_scan): Don't call
	free_pending_blocks.
	* dbxread.c (dbx_symfile_read): Don't call free_pending_blocks.
	* buildsym.h (class scoped_free_pendings): Add constructor.
	(free_pending_blocks): Don't declare.
	* buildsym.c (scoped_free_pendings::scoped_free_pendings): New.
	(free_pending_blocks): Now static.
2018-07-16 08:55:21 -06:00
Tom Tromey 8419ee5331 Move the subfile stack to buildsym_compunit
This moves the global subfile_stack to be a member of
buildsym_compunit.  It also change this to be a std::vector, which
simplifies the code.

gdb/ChangeLog
2018-07-16  Tom Tromey  <tom@tromey.com>

	* buildsym.h (push_subfile, pop_subfile): Update declarations.
	* buildsym.c (struct buildsym_compunit) <m_subfile_stack>: New
	member.
	(struct subfile_stack): Remove.
	(subfile_stack): Remove.
	(push_subfile, pop_subfile, buildsym_init): Update.
2018-07-16 08:55:21 -06:00
Tom Tromey ccdac490bb Use gdb_assert in two places in buildsym.c
This changes buildsym.c to use gdb_assert rather than internal_error
in a couple of spots.

gdb/ChangeLog
2018-07-16  Tom Tromey  <tom@tromey.com>

	* buildsym.c (push_subfile): Use gdb_assert.
	(pop_subfile): Use gdb_assert.
2018-07-16 08:55:20 -06:00
Tom Tromey 43130d6f96 Remove merge_symbol_lists
I discovered that merge_symbol_lists is unused, so this removes it.

gdb/ChangeLog
2018-07-16  Tom Tromey  <tom@tromey.com>

	* buildsym.h (merge_symbol_lists): Remove.
	* buildsym.c (merge_symbol_lists): Remove.
2018-07-16 08:55:20 -06:00
Tom Tromey 2c722d18f3 Remove buildsym_new_init
buildsym_new_init is just an alias for buildsym_init.  This removes
it.  In the long run buildsym_init will also go away; this patch just
helps make things a bit clearer in the meantime.

gdb/ChangeLog
2018-07-16  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (xcoff_new_init): Update.
	* mipsread.c (mipscoff_new_init): Update.
	* mdebugread.c (mdebug_build_psymtabs): Update.
	* elfread.c (elf_new_init): Update.
	* dbxread.c (dbx_new_init, coffstab_build_psymtabs)
	(elfstab_build_psymtabs, stabsect_build_psymtabs): Update.
	* buildsym.h (buildsym_new_init): Don't declare.
	* buildsym.c (buildsym_new_init): Remove.
2018-07-16 08:55:19 -06:00
Tom Tromey 5985ac614d Move within_function to stabsread
The global within_function is only used by a few symbol readers.  This
patch moves the global out of buildsym and into stabsread, which
seemed like a better fit.  It also arranges for the existing readers
to clear the global at the appropriate time.

gdb/ChangeLog
2018-07-16  Tom Tromey  <tom@tromey.com>

	* stabsread.h (within_function): Move from buildsym.h.
	* stabsread.c (start_stabs): Clear within_function.
	* coffread.c (coff_start_symtab): Clear within_function.
	* buildsym.h (within_function): Move to stabsread.h.
	* buildsym.c (prepare_for_building): Update.
2018-07-16 08:55:18 -06:00
Tom Tromey 2150c3ef04 Move some code from buildsym to stabsread
A few things that currently reside in buildsym.c turn out to be
specific to the stabs reader.  This patch moves these from
buildsym.[ch] to stabsread.[ch].

gdb/ChangeLog
2018-07-16  Tom Tromey  <tom@tromey.com>

	* stabsread.h (HASHSIZE, hashname, symnum, next_symbol_text)
	(next_symbol_text_func): Move from buildsym.h.
	* stabsread.c (hashname): Move from buildsym.c.
	* buildsym.h (HASHSIZE, symnum, next_symbol_text)
	(next_symbol_text_func, hashname): Move to stabsread.h.
	* buildsym.c: Don't include bcache.h
	(hashname): Move to stasbread.c.
2018-07-16 08:55:17 -06:00