Commit Graph

16 Commits

Author SHA1 Message Date
Tom Tromey 5bfd760d66 Convert dwarf2_per_objfile to type-safe registry API
This changes dwarf2_per_objfile to use the type-safe registry API.
This also changes dwarf2_per_objfile not to be allocated on an
obstack.  It seemed clearer to me to simply allocate it on the heap;
and I didn't see a drawback from doing so.

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

	* dwarf2read.h (struct dwarf2_per_objfile): Don't inherit from
	allocate_on_obstack.
	* dwarf2read.c (dwarf2_objfile_data_key): Change type.
	(get_dwarf2_per_objfile): Update.
	(set_dwarf2_per_objfile): Remove.
	(dwarf2_has_info, dwarf2_get_section_info): Update.
	(dwarf2_free_objfile): Remove.
	(_initialize_dwarf2_read): Update.
2019-05-08 16:01:48 -06:00
Tom Tromey 587ee17bd4 Don't declare read_unsigned_leb128 in defs.h
I noticed that read_unsigned_leb128 is declared in defs.h.  There's no
reason this should be here, so this patch moves it to dwarf2read.h.

gdb/ChangeLog
2019-05-08  Tom Tromey  <tromey@adacore.com>

	* dwarf2loc.c: Include dwarf2read.h.
	* defs.h (read_unsigned_leb128): Don't declare.
	* dwarf2read.h (read_unsigned_leb128): Declare.
2019-05-08 10:38:02 -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
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
Tom de Vries e4a62c65fa [gdb/exp] Handle DW_OP_GNU_variable_value refs to abstract dies
Consider a vla variable 'a' in function f1:
...
 <2><1a7>: Abbrev Number: 11 (DW_TAG_variable)
    <1a8>   DW_AT_description : a
    <1aa>   DW_AT_abstract_origin: <0x311>
...
with abstract origin 'a':
...
 <2><311>: Abbrev Number: 3 (DW_TAG_variable)
    <312>   DW_AT_name        : a
    <317>   DW_AT_type        : <0x325>
...
and inherited abstract vla type:
...
 <1><325>: Abbrev Number: 9 (DW_TAG_array_type)
    <326>   DW_AT_type        : <0x33a>
 <2><32e>: Abbrev Number: 10 (DW_TAG_subrange_type)
    <32f>   DW_AT_type        : <0x2ea>
    <333>   DW_AT_upper_bound : 5 byte block: fd 1b 3 0 0
                                (DW_OP_GNU_variable_value: <0x31b>)
...
where the upper bound refers to this artificial variable D.1922 without location
attribute:
...
 <2><31b>: Abbrev Number: 8 (DW_TAG_variable)
    <31c>   DW_AT_description : (indirect string, offset: 0x39a): D.1922
    <320>   DW_AT_type        : <0x2ea>
    <324>   DW_AT_artificial  : 1
...

Currently, when we execute "p sizeof (a)" in f1, the upper bound is calculated
by evaluating the DW_OP_GNU_variable_value expression referring to D.1922, but
since that die doesn't have a location attribute, we get:
...
value has been optimized out
...

However, there's also artificial variable D.4283 that is sibling of vla
variable 'a', has artificial variable D.1922 as abstract origin, and has a
location attribute:
...
 <2><1ae>: Abbrev Number: 12 (DW_TAG_variable)
    <1af>   DW_AT_description : (indirect string, offset: 0x1f8): D.4283
    <1b3>   DW_AT_abstract_origin: <0x31b>
    <1b7>   DW_AT_location    : 11 byte block: 75 1 8 20 24 8 20 26 31 1c 9f
                                (DW_OP_breg5 (rdi):1; DW_OP_const1u: 32;
				 DW_OP_shl; DW_OP_const1u: 32; DW_OP_shra;
				 DW_OP_lit1; DW_OP_minus; DW_OP_stack_value)
...

The intended behaviour for DW_OP_GNU_variable_value is to find a die that
refers to D.1922 as abstract origin, has a location attribute and is
'in scope', so the expected behaviour is:
...
$1 = 6
...

The 'in scope' concept can be thought of as variable D.1922 having name
attribute "D.1922", and variable D.4283 inheriting that attribute, resulting
in D.4283 being declared with name "D.1922" alongside vla a in f1, and when we
lookup "DW_OP_GNU_variable_value D.1922", it should work as if we try to find
the value of a variable named "D.1922" on the gdb command line using
"p D.1922", and we should return the value of D.4283.

This patch fixes the case described above, by:
- adding a field abstract_to_concrete to struct dwarf2_per_objfile,
- using that field to keep track of which concrete dies are instances of an
  abstract die, and
- using that information when getting the value DW_OP_GNU_variable_value.

Build and reg-tested on x86_64-linux.

2018-09-05  Tom de Vries  <tdevries@suse.de>

	* dwarf2loc.c (sect_variable_value): Call indirect_synthetic_pointer
	with resolve_abstract_p == true.
	(indirect_synthetic_pointer): Add resolve_abstract_p parameter,
	defaulting to false. Propagate resolve_abstract_p to
	dwarf2_fetch_die_loc_sect_off.
	* dwarf2loc.h (dwarf2_fetch_die_loc_sect_off): Add resolve_abstract_p
	parameter, defaulting to false.
	* dwarf2read.c (read_variable): Add variable to abstract_to_concrete.
	(dwarf2_fetch_die_loc_sect_off): Add and handle resolve_abstract_p
	parameter.
	* dwarf2read.h (struct die_info): Forward-declare.
	(die_info_ptr): New typedef.
	(struct dwarf2_per_objfile): Add abstract_to_concrete field.

	* gdb.dwarf2/varval.exp: Add test.
2018-09-05 10:39:19 +02:00
Simon Marchi 87d6a7aa93 Add DWARF index cache
New in v3:

- Remove things related to the dwarf-5 format.
- Fix compilation on mingw (scoped_mmap.c).

GDB can generate indexes for DWARF debug information, which, when
integrated in the original binary, can speed up loading object files.
This can be done using the gdb-add-index script or directly by the
linker itself.  However, not many people know about this.  And even
among those who do, because it requires additional steps, I don't know a
lot of people who actually go through that trouble.

To help make using the DWARF index more transparent, this patch
introduces a DWARF index cache.  When enabled, loading an index-less
binary in GDB will automatically save an index file in ~/.cache/gdb.
When loading that same object file again, the index file will be looked
up and used to load the DWARF index.  You therefore get the benefit of
the DWARF index without having to do additional manual steps or
modifying your build system.  When an index section is already present
in the file, GDB will prefer that one over looking up the cache.

When doing my edit-compile-debug cycle, I often debug multiple times the
same build, so the cache helps reducing the load time of the debug
sessions after the first one.

- The saved index file is exactly the same as the output of the "save
  gdb-index" command.  It is therefore the exact same content that would
  be found in the .gdb_index or .debug_names section.  We just leave it
  as a standalone file instead of merging it in the binary.

- The cache is just a directory with files named after the object
  file's build-id.  It is not possible to save/load the index for an
  object file without build-id in the cache.

- The cache uses the gdb index format.  The problem with the dwarf-5
  format is that we can generate an addendum to the .debug_str section
  that you're supposed to integrate to the original binary.  This
  complicates a little bit loading the data from the cached index files,
  so I would leave this for later.

- The size taken up by ~/.cache/gdb is not limited.  I was thinking we
  could add configurable limit (like ccache does), but that would come
  after.  Also, maybe a command to flush the cache.

- The cache is disabled by default.  I think once it's been out there
  and tested for a while, it could be turned on by default, so that
  everybody can enjoy it.

- The code was made to follow the XDG specification: if the
  XDG_CACHE_HOME environment variable, it is used, otherwise it falls
  back to ~/.cache/gdb.  It is possible to change it using "set
  index-cache directory".  On other OSes than GNU/Linux, ~/.cache may
  not be the best place to put such data.  On macOS it should probably
  default to ~/Library/Caches/...  On Windows, %LocalAppData%/...  I
  don't intend to do this part, but further patches are welcome.

- I think that we need to be careful that multiple instances of GDB
  don't interfere with each other (not far fetched at all if you run GDB
  in some automated script) and the cache is always coherent (either the
  file is not found, or it is found and entirely valid).  Writing the
  file directly to its final location seems like a recipe for failure.
  One GDB could read a file in the index while it is being written by
  another GDB.  To mitigate this, I made write_psymtabs_to_index write
  to temporary files and rename them once it's done.  Two GDB instances
  writing the index for the same file should not step on each other's
  toes (the last file to be renamed will stay).  A GDB looking up a file
  will only see a complete file or no file.  Also, if GDB crashes while
  generating the index file, it will leave a work-in-progress file, but
  it won't be picked up by other instances looking up in the cache.

gdb/ChangeLog:

	* common/pathstuff.h (get_standard_cache_dir): New.
	* common/pathstuff.c (get_standard_cache_dir): New.
	* build-id.h (build_id_to_string): New.
	* dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX,
	DEBUG_STR_SUFFIX): Move to here.
	* dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX,
	DEBUG_STR_SUFFIX): Move from there.
	(write_psymtabs_to_index): Make non-static, add basename
	parameter.  Write to temporary files, rename when done.
	(save_gdb_index_command): Adjust call to
	write_psymtabs_to_index.
	* dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New
	field.
	* dwarf2read.c (dwz_file) <index_cache_res>: New field.
	(get_gdb_index_contents_from_cache): New.
	(get_gdb_index_contents_from_cache_dwz): New.
	(dwarf2_initialize_objfile): Read index from cache.
	(dwarf2_build_psymtabs): Save to index.
	* dwarf-index-cache.h: New file.
	* dwarf-index-cache.c: New file.
	* dwarf-index-write.h: New file.

gdb/testsuite/ChangeLog:

	* boards/index-cache-gdb.exp: New file.
	* gdb.dwarf2/index-cache.exp: New file.
	* gdb.dwarf2/index-cache.c: New file.
	* gdb.base/maint.exp: Check if we are using the index cache.
2018-08-07 18:14:20 -04:00
Andrew Burgess 3c3bb0580b gdb: Add switch to disable DWARF stack unwinders
Add a maintenance command to disable the DWARF stack unwinders.
Normal users would not need this feature, but it is useful to allow
extended testing of fallback stack unwinding strategies, for example,
prologue scanners.

This is a partial implementation of the idea discussed in pr gdb/8434,
which talks about a generic ability to disable any frame unwinder.

Being able to arbitrarily disable any frame unwinder would be a more
complex patch, and I was unsure how useful such a feature would really
be, however, I can see (and have) a real need to disable DWARF
unwinders.  That's why this patch only targets that specific set of
unwinders.

If in the future we find ourselves adding more switches to disable
different unwinders, then we should probably move to a more generic
solution, and remove this patch.

gdb/ChangeLog:

	* dwarf2-frame-tailcall.c (tailcall_frame_sniffer): Exit early if
	DWARF unwinders are disabled.
	* dwarf2-frame.c: Add dwarf2read.h include.
	(dwarf2_frame_sniffer): Exit early if DWARF unwinders are
	disabled.
	(dwarf2_frame_unwinders_enabled_p): Define.
	(show_dwarf_unwinders_enabled_p): New function.
	(_initialize_dwarf2_frame): Register switch to control DWARF
	unwinder use.
	* dwarf2-frame.h (dwarf2_frame_unwinders_enabled_p): Declare.
	* dwarf2read.c (set_dwarf_cmdlist): Remove static keyword.
	(show_dwarf_cmdlist): Remove static keyword.
	* dwarf2read.h (set_dwarf_cmdlist): Declare.
	(show_dwarf_cmdlist): Declare.
	* NEWS: Document new feature.

gdb/doc/ChangeLog:

	* gdb.texinfo (Maintenance Commands): Add description of
	maintenance command to control dwarf unwinders.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: Add check that dwarf unwinders control flag
	is visible.
2018-07-26 08:53:02 +01:00
Tom Tromey c5d0225d25 Remove a VEC from dwarf2read.c
This removes a VEC from dwarf2read.c, replacing it with a std::vector.

Tested by the buildbot.

gdb/ChangeLog
2018-06-09  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (process_cu_includes): Update.
	(process_full_comp_unit): Update.
	* dwarf2read.h (struct dwarf2_per_objfile) <just_read_cus>: Now a
	std::vector.
2018-06-09 16:05:48 -06:00
Tom Tromey 7ff8cb8c51 Allocate dwz_file with new
This adds a constructor to struct dwz_file and arranges for it to be
allocated with "new" and wrapped in a unique_ptr.  This cuts down on
the amount of manual memory management that must be done.

Regression tested by the buildbot.

gdb/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct dwz_file): Add constructor, initializers.
	<dwz_bfd>: Now a gdb_bfd_ref_ptr.
	(~dwarf2_per_objfile): Update
	(dwarf2_get_dwz_file): Use new.
	* dwarf2read.h (struct dwarf2_per_objfile) <dwz_file>: Now a
	unique_ptr.
2018-05-18 15:12:14 -06:00
Tom Tromey 400174b12a Allocate dwp_file with new
This adds a constructor and initializer to dwp_file and changes it to
be allocated with "new".  This removes a bit of manual refcount
management.

Tested by the buildbot.

gdb/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (struct dwarf2_per_objfile) <dwp_file>: Now a
	unique_ptr.
	* dwarf2read.c (struct dwp_file): Add constructor and
	initializers.
	(open_and_init_dwp_file): Return a unique_ptr.
	(dwarf2_per_objfile, create_dwp_hash_table)
	(create_dwo_unit_in_dwp_v1, create_dwo_unit_in_dwp_v2)
	(lookup_dwo_unit_in_dwp): Update.
	(open_and_init_dwp_file, get_dwp_file): Update.
2018-05-18 14:33:24 -06:00
Tom Tromey 3063847f29 Use new to allocate mapped_index
This changes struct mapped_index to be allocated with new.  This
simplifies the creation a bit (see dwarf2_read_index) and also removes
a somewhat ugly explicit destructor call from ~dwarf2_per_objfile.

Tested by the buildbot.

gdb/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_per_objfile): Update.
	(struct mapped_index): Add initializers.
	(dwarf2_read_index): Use new.
	(dw2_symtab_iter_init): Update.
	* dwarf2read.h (struct dwarf2_per_objfile) <index_table>: Now a
	unique_ptr.
2018-05-18 14:10:09 -06:00
Simon Marchi b2bdb8cf39 Make dwarf2_per_objfile::all_type_units an std::vector
Make all_type_units an std::vector, remove
n_type_units/n_allocated_type_units and some manual memory management.

gdb/ChangeLog:

	* dwarf2read.h (struct dwarf2_per_objfile) <n_type_units>:
	Remove.
	<n_allocated_type_units>: Remove.
	<all_type_units>: Change to std::vector.
	* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust
	to std::vector change.
	(dwarf2_per_objfile::get_cutu): Likewise.
	(dwarf2_per_objfile::get_tu): Likewise.
	(create_signatured_type_table_from_index): Likewise.
	(create_signatured_type_table_from_debug_names): Likewise.
	(dw2_symtab_iter_next): Likewise.
	(dw2_print_stats): Likewise.
	(dw2_expand_all_symtabs): Likewise.
	(dw2_expand_marked_cus): Likewise.
	(dw2_debug_names_iterator::next): Likewise.
	(dwarf2_initialize_objfile): Likewise.
	(add_signatured_type_cu_to_table): Likewise.
	(create_all_type_units): Likewise.
	(add_type_unit): Likewise.
	(struct tu_abbrev_offset): Add constructor.
	(build_type_psymtabs_1): Adjust to std::vector change.
	(print_tu_stats): Likewise.
	* dwarf-index-write.c (check_dwarf64_offsets): Likewise.
	(write_debug_names): Likewise.
2018-04-07 13:53:44 -04:00
Simon Marchi b76e467de3 Make dwarf2_per_objfile::all_comp_units an std::vector
Make all_comp_units an std::vector, remove n_comp_units and some manual
memory management.

gdb/ChangeLog:

	* dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise.
	Make an std::vector.
	<n_comp_units>: Remove.
	* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust
	to std::vector change.
	(dwarf2_per_objfile::get_cutu): Likewise.
	(dwarf2_per_objfile::get_cu): Likewise.
	(create_cus_from_index): Likewise.
	(create_addrmap_from_index): Likewise.
	(create_addrmap_from_aranges): Likewise.
	(dwarf2_read_index): Likewise.
	(dw2_find_last_source_symtab): Likewise.
	(dw2_map_symtabs_matching_filename): Likewise.
	(dw2_symtab_iter_next): Likewise.
	(dw2_print_stats): Likewise.
	(dw2_expand_all_symtabs): Likewise.
	(dw2_expand_symtabs_with_fullname): Likewise.
	(dw2_expand_marked_cus): Likewise.
	(dw2_map_symbol_filenames): Likewise.
	(create_cus_from_debug_names): Likewise.
	(dwarf2_read_debug_names): Likewise.
	(dw2_debug_names_iterator::next): Likewise.
	(dwarf2_initialize_objfile): Likewise.
	(set_partial_user): Likewise.
	(dwarf2_build_psymtabs_hard): Likewise.
	(read_comp_units_from_section): Remove arguments, adjust to
	std::vector change.
	(create_all_comp_units): Adjust to std::vector and
	read_comp_units_from_section changes.
	(dwarf2_find_containing_comp_unit): Adjust to std::vector
	change.
	* dwarf-index-write.c (check_dwarf64_offsets): Likewise.
	(psyms_seen_size): Likewise.
	(write_gdbindex): Likewise.
	(write_debug_names): Likewise.
2018-04-07 13:53:43 -04:00
Simon Marchi ff4c9fec84 Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile
Those two functions look like good candidates to become methods of
dwarf2_per_objfile.  I did that, and added get_tu as well.  When
replacing usages of dw2_get_cutu, I changed some instances to get_cutu
and others to get_cu, when appropriate (when we know we want a CU and
not a TU).

gdb/ChangeLog:

	* dwarf2read.h (struct signatured_type): Forward declare.
	(struct dwarf2_per_objfile) <get_cutu, get_cu, get_tu>:
	New methods.
	* dwarf2read.c (dwarf2_per_objfile::get_cutu): Rename from...
	(dw2_get_cutu): ...this.
	(dwarf2_per_objfile::get_cu): Rename from...
	(dw2_get_cu): ...this.
	(dwarf2_per_objfile::get_tu): New.
	(create_addrmap_from_index): Adjust.
	(create_addrmap_from_aranges): Adjust.
	(dw2_find_last_source_symtab): Adjust.
	(dw2_map_symtabs_matching_filename): Adjust.
	(dw2_symtab_iter_next): Adjust.
	(dw2_print_stats): Adjust.
	(dw2_expand_all_symtabs): Adjust.
	(dw2_expand_symtabs_with_fullname): Adjust.
	(dw2_expand_marked_cus): Adjust.
	(dw_expand_symtabs_matching_file_matcher): Adjust.
	(dw2_map_symbol_filenames): Adjust.
	(dw2_debug_names_iterator::next): Adjust.
	(dwarf2_initialize_objfile): Adjust.
	(set_partial_user): Adjust.
	(dwarf2_build_psymtabs_hard): Adjust.
2018-04-07 13:53:41 -04:00
Simon Marchi cd4fb1b2ff Move DWARF index-related things to a separate file
I want to add a DWARF index-related feature (automatically produce index
files when loading objfiles in GDB), but I don't want to add many
hundred lines to the already too big dwarf2read.c.  I thought it would
be a logical split to move everything related to the DWARF index to its
own file.

I first tried to move everything that reads and writes DWARF indices to
a separate file, but found that the "read" part is a little bit
entangled with the rest of dwarf2read.c, so the line is hard to draw
about where to split.  The write part is quite isolated though, so I
moved this part to a new file, dwarf-index-write.c.  Some things are
necessary to both reading and writing indices, so I placed them in
dwarf-index-common.{c,h}.  The idea would be to have a
dwarf-index-read.c eventually that would use it too (for now that code
is still in dwarf2read.c).

This required moving some things to a new dwarf2read.h header, so they
can be read by the code that writes the index.

The patch is big in number of lines, but it's all existing code being
moved around.  The only changes are that some functions are not static
anymore, a declaration is added in a .h file, and therefore the comment
is moved there.

I built-tested it with a little and big endian target.

This patch is also available on the users/simark/split-dwarf2read
branch.

gdb/ChangeLog:

	* Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and
	dwarf-index-write.c
	(HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h.
	* dwarf-index-common.c: New file.
	* dwarf-index-common.h: New file.
	* dwarf-index-write.c: New file.
	* dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h.
	(struct dwarf2_section_info): Move from here.
	(dwarf2_section_info_def): Likewise.
	(DEF_VEC_O (dwarf2_section_info_def)): Likewise.
	(offset_type): Likewise.
	(DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise.
	(DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise.
	(DW2_GDB_INDEX_CU_SET_VALUE): Likewise.
	(byte_swap): Likewise.
	(MAYBE_SWAP): Likewise.
	(dwarf2_per_cu_ptr): Likewise.
	(DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise.
	(struct tu_stats): Likewise.
	(struct dwarf2_per_objfile): Likewise.
	(struct dwarf2_per_cu_data): Likewise.
	(struct signatured_type): Likewise.
	(sig_type_ptr): Likewise.
	(DEF_VEC_P (sig_type_ptr)): Likewise.
	(INDEX4_SUFFIX): Likewise.
	(INDEX5_SUFFIX): Likewise.
	(DEBUG_STR_SUFFIX): Likewise.
	(dwarf2_read_section): Make non-static.
	(mapped_index_string_hash): Move from here.
	(dwarf5_djb_hash): Likewise.
	(file_write): Likewise.
	(class data_buf): Likewise.
	(struct symtab_index_entry): Likewise.
	(struct mapped_symtab): Likewise.
	(find_slot): Likewise.
	(hash_expand): Likewise.
	(add_index_entry): Likewise.
	(uniquify_cu_indices): Likewise.
	(class c_str_view): Likewise.
	(class c_str_view_hasher): Likewise.
	(class vector_hasher): Likewise.
	(write_hash_table): Likewise.
	(psym_index_map): Likewise.
	(struct addrmap_index_data): Likewise.
	(add_address_entry): Likewise.
	(add_address_entry_worker): Likewise.
	(write_address_map): Likewise.
	(symbol_kind): Likewise.
	(write_psymbols): Likewise.
	(struct signatured_type_index_data): Likewise.
	(write_one_signatured_type): Likewise.
	(recursively_count_psymbols): Likewise.
	(recursively_write_psymbols): Likewise.
	(class debug_names): Likewise.
	(check_dwarf64_offsets): Likewise.
	(psyms_seen_size): Likewise.
	(write_gdbindex): Likewise.
	(write_debug_names): Likewise.
	(assert_file_size): Likewise.
	(write_psymtabs_to_index): Likewise.
	(save_gdb_index_command): Likewise.
	(_initialize_dwarf2_read): Don't register the "save gdb-index"
	command.
	* dwarf2read.h: New file.
2018-03-27 10:07:47 -04:00