Commit Graph

421 Commits

Author SHA1 Message Date
Tom de Vries
8f6606b6e3 [gdb] Fix common misspellings
Fix the following common misspellings:
...
accidently -> accidentally
additonal -> additional
addresing -> addressing
adress -> address
agaisnt -> against
albiet -> albeit
arbitary -> arbitrary
artifical -> artificial
auxillary -> auxiliary
auxilliary -> auxiliary
bcak -> back
begining -> beginning
cannonical -> canonical
compatiblity -> compatibility
completetion -> completion
diferent -> different
emited -> emitted
emiting -> emitting
emmitted -> emitted
everytime -> every time
excercise -> exercise
existance -> existence
fucntion -> function
funtion -> function
guarentee -> guarantee
htis -> this
immediatly -> immediately
layed -> laid
noone -> no one
occurances -> occurrences
occured -> occurred
originaly -> originally
preceeded -> preceded
preceeds -> precedes
propogate -> propagate
publically -> publicly
refering -> referring
substract -> subtract
substracting -> subtracting
substraction -> subtraction
taht -> that
targetting -> targeting
teh -> the
thier -> their
thru -> through
transfered -> transferred
transfering -> transferring
upto -> up to
vincinity -> vicinity
whcih -> which
whereever -> wherever
wierd -> weird
withing -> within
writen -> written
wtih -> with
doesnt -> doesn't
...

Tested on x86_64-linux.
2024-10-06 07:59:48 +02:00
Guinevere Larsen
59d41830a3 gdb: fully separate coff and elf reading from dbx
With the previous commits, the only thing entangling elf and coff file
reading with dbx file reading is the functions
{elf|coff}stab_build_psymtabs, defined in dbxread.c. These functions
depend on dbx_symfile_read.

To solve this, I renamed read_stabs_symtab to read_stabs_symtab_1, and
created a function with the original name that does what
dbx_symfile_read used to do.

This way, dbx_symfile_read can just call read_stabs_symtab, and the elf
and coff psymtab builders can also call it directly, fully disentangling
the readers, which would allow us to selectively not compile dbxread in
the future.

Approved-By: Tom Tromey <tom@tromey.com>
2024-09-20 17:02:16 -03:00
Simon Marchi
4144d36a68 gdb: add program_space parameter to lookup_minimal_symbol
>From what I can see, lookup_minimal_symbol doesn't have any dependencies
on the global current state other than the single reference to
current_program_space.  Add a program_space parameter and make that
current_program_space reference bubble up one level.

Change-Id: I759415e2f9c74c9627a2fe05bd44eb4147eee6fe
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12 10:31:09 -04:00
Simon Marchi
c8979ae4fb gdb: make lookup_minimal_symbol objf and sfile parameters optional
Most calls to lookup_minimal_symbol don't pass a value for sfile and
objf.  Make these parameters optional (have a default value of
nullptr).  And since passing a value to `objf` is much more common than
passing a value to `sfile`, swap the order so `objf` comes first, to
avoid having to pass a nullptr value to `sfile` when wanting to pass a
value to `objf`.

Change-Id: I8e9cc6b942e593bec640f9dfd30f62786b0f5a27
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12 10:31:09 -04:00
Simon Marchi
03b40f6f55 gdb: drop struct keyword when using bound_minimal_symbol
This is a simple find / replace from "struct bound_minimal_symbol" to
"bound_minimal_symbol", to make things shorter and more consisten
througout.  In some cases, move variable declarations where first used.

Change-Id: Ica4af11c4ac528aa842bfa49a7afe8fe77a66849
Reviewed-by: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-08-12 10:31:09 -04:00
Simon Marchi
e5dc0d5d04 gdb: move a bunch of quit-related things to event-top.{c,h}
Move some declarations related to the "quit" machinery from defs.h to
event-top.h.  Most of the definitions associated to these declarations
are in event-top.c.  The exceptions are `quit()` and `maybe_quit()`,
that are defined in utils.c.  For consistency, move these two
definitions to event-top.c.

Include "event-top.h" in many files that use these things.

Change-Id: I6594f6df9047a9a480e7b9934275d186afb14378
Approved-By: Tom Tromey <tom@tromey.com>
2024-04-23 11:26:14 -04:00
Simon Marchi
18d2988e5d gdb, gdbserver, gdbsupport: remove includes of early headers
Now that defs.h, server.h and common-defs.h are included via the
`-include` option, it is no longer necessary for source files to include
them.  Remove all the inclusions of these files I could find.  Update
the generation scripts where relevant.

Change-Id: Ia026cff269c1b7ae7386dd3619bc9bb6a5332837
Approved-By: Pedro Alves <pedro@palves.net>
2024-03-26 21:13:22 -04:00
Tom Tromey
974b36c2ae Use the new symbol domains
This patch changes the DWARF reader to use the new symbol domains.  It
also adjusts many bits of associated code to adapt to this change.

The non-DWARF readers are updated on a best-effort basis.  This is
somewhat simpler since most of them only support C and C++.  I have no
way to test a few of these.

I went back and forth a few times on how to handle the "tag"
situation.  The basic problem is that C has a special namespace for
tags, which is separate from the type namespace.  Other languages
don't do this.  So, the question is, should a DW_TAG_structure_type
end up in the tag domain, or the type domain, or should it be
language-dependent?

I settled on making it language-dependent using a thought experiment.
Suppose there was a Rust compiler that only emitted nameless
DW_TAG_structure_type objects, and specified all structure type names
using DW_TAG_typedef.  This DWARF would be correct, in that it
faithfully represents the source language -- but would not work with a
purely struct-domain implementation in gdb.  Therefore gdb would be
wrong.

Now, this approach is a little tricky for C++, which uses tags but
also enters a typedef for them.  I notice that some other readers --
like stabsread -- actually emit a typedef symbol as well.  And, I
think this is a reasonable approach.  It uses more memory, but it
makes the internals simpler.  However, DWARF never did this for
whatever reason, and so in the interest of keeping the series slightly
shorter, I've left some C++-specific hacks in place here.

Note that this patch includes language_minimal as a language that uses
tags.  I did this to avoid regressing gdb.dwarf2/debug-names-tu.exp,
which doesn't specify the language for a type unit.  Arguably this
test case is wrong.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30164
2024-01-28 10:58:16 -07:00
Andrew Burgess
1d506c26d9 Update copyright year range in header of all files managed by GDB
This commit is the result of the following actions:

  - Running gdb/copyright.py to update all of the copyright headers to
    include 2024,

  - Manually updating a few files the copyright.py script told me to
    update, these files had copyright headers embedded within the
    file,

  - Regenerating gdbsupport/Makefile.in to refresh it's copyright
    date,

  - Using grep to find other files that still mentioned 2023.  If
    these files were updated last year from 2022 to 2023 then I've
    updated them this year to 2024.

I'm sure I've probably missed some dates.  Feel free to fix them up as
you spot them.
2024-01-12 15:49:57 +00:00
Tom Tromey
aecbdf5f34 Simplify the public DWARF API
dwarf2_has_info and dwarf2_initialize_objfile are only separate
because the DWARF reader implemented lazy psymtab reading.  However,
now that this is gone, we can simplify the public DWARF API again.
2024-01-08 18:40:21 -07:00
Tom Tromey
d182e39881 Use C++17 [[fallthrough]] attribute
This changes gdb to use the C++17 [[fallthrough]] attribute rather
than special comments.

This was mostly done by script, but I neglected a few spellings and so
also fixed it up by hand.

I suspect this fixes the bug mentioned below, by switching to a
standard approach that, presumably, clang supports.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23159
Approved-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Pedro Alves <pedro@palves.net>
2023-11-29 14:29:43 -07:00
Andrew Burgess
27807da584 gdb: merge debug symbol file lookup code from coffread & elfread paths
This commit merges the code that looks for and loads the separate
debug symbol files from coffread.c and elfread.c.  The factored out
code is moved into a new objfile::find_and_add_separate_symbol_file()
method.

For the elfread.c path there should be no user visible changes after
this commit.

For the coffread.c path GDB will now attempt to perform a debuginfod
lookup for the missing debug information, assuming that GDB can find a
build-id in the COFF file.

I don't know if COFF files can include a build-id, but I the existing
coffread.c code already includes a call to
find_separate_debug_file_by_build-id, so I know that it is at least OK
for GDB to ask a COFF file for a build-id.  If the COFF file doesn't
include a build-id then the debuginfod lookup code will not trigger
and the new code is harmless.

If the COFF file does include a build-id, then we're going to end up
asking debuginfod for the debug file.  As build-ids should be unique,
this should be harmless, even if debuginfod doesn't contain any
suitable debug data, it just costs us one debuginfod lookup, so I'm
not too worried about this for now.

As with the previous commit, I've done some minimal testing using the
mingw toolchain on a Linux machine, GDB seems to still access the
split debug information just fine.

Approved-By: Tom Tromey <tom@tromey.com>
2023-11-14 11:32:02 +00:00
Andrew Burgess
7628a997f2 gdb/coffread: bring separate debug file logic into line with elfread.c
In this commit:

  commit 8a92335bfc
  Date:   Fri Feb 1 19:39:04 2013 +0000

the logic for when we try to load a separate debug file in elfread.c
was extended.  The new code checks that the objfile doesn't already
have a separate debug objfile linked to it, and that the objfile isn't
itself a separate debug objfile for some other objfile.

The coffread code wasn't extended at the same time.

I don't know if it's possible for the coffread code to get into the
same state where these checks are needed, but I don't see why having
these checks would be a problem.  In a later commit I plan to merge
this part of the elfread and coffread code, so bringing these two
pieces of code into line first makes that job easier.

I've tested this with a simple test binary compiled with the mingw
toolchain on a Linux host.  After compiling the binary and splitting
out the debug info GDB still finds and loads the separate debug info.

Approved-By: Tom Tromey <tom@tromey.com>
2023-11-14 11:32:02 +00:00
Tom Tromey
ef0f16ccf8 Remove explanatory comments from includes
I noticed a comment by an include and remembered that I think these
don't really provide much value -- sometimes they are just editorial,
and sometimes they are obsolete.  I think it's better to just remove
them.  Tested by rebuilding.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-20 11:45:16 -06:00
Tom Tromey
76fc0f6213 Give a language to a type
This changes main_type to hold a language, and updates the debug
readers to set this field.  This is done by adding the language to the
type-allocator object.

Note that the non-DWARF readers are changed on a "best effort" basis.

This patch also reimplements type::is_array_like to use the type's
language, and it adds a new type::is_string_like as well.  This in
turn lets us change the Python implementation of these methods to
simply defer to the type.
2023-09-19 13:28:42 -06:00
Simon Marchi
886176b865 gdb: introduce field::bitsize / field::set_bitsize
Add these two methods, rename the field to m_bitsize to make it pseudo
private.

Change-Id: Ief95e5cf106e72f2c22ae47b033d0fa47202b413
Approved-By: Tom Tromey <tom@tromey.com>
2023-08-31 13:16:13 -04:00
Tom de Vries
4b3d893ac8 [gdb/symtab] Do more zero-initialization of type::fields
Now that we've introduced type::{alloc_fields,copy_fields}, the places where
no zero-initialization of allocated fields is done are easy to spot:
...
$ find gdb* -type f | grep -v ChangeLog | xargs grep alloc_fields | grep false
gdb/coffread.c:  type->alloc_fields (nfields, false);
gdb/coffread.c:  type->alloc_fields (nsyms, false);
gdb/stabsread.c:	  ftype->alloc_fields (nsemi, false);
gdb/gdbtypes.c:  resolved_type->alloc_fields (nfields, false);
gdb/gdbtypes.c:  alloc_fields (nfields, false);
gdb/gdbtypes.c:  alloc_fields (nfields, false);
gdb/mdebugread.c:	t->alloc_fields (nfields, false);
gdb/mdebugread.c:		  ftype->alloc_fields (nparams, false);
...

All hits in gdbtypes.c are ok.  There are two hits in the two variants of
copy_fields, and there's already a comment for the third.

AFAICT, the other ones are not ok, so fix those by dropping the "false"
argument.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2023-08-31 09:37:44 +02:00
Tom de Vries
2774f2dad5 [gdb/symtab] Factor out type::{alloc_fields,copy_fields}
After finding this code in buildsym_compunit::finish_block_internal:
...
              ftype->set_fields
                ((struct field *)
                 TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
...
and fixing PR30810 by using TYPE_ZALLOC, I wondered if there were more
locations that needed fixing.

I decided to make things easier to spot by factoring out a new function
alloc_fields:
...
 /* Allocate the fields array of this type, with NFIELDS elements.  If INIT,
     zero-initialize the allocated memory.  */
  void
  type::alloc_fields (unsigned int nfields, bool init = true);
...
where:
- a regular use would be "alloc_fields (nfields)", and
- an exceptional use that needed no initialization would be
  "alloc_fields (nfields, false)".

Pretty soon I discovered that most of the latter cases are due to
initialization by memcpy, so I added two variants of copy_fields as well.

After this rewrite there are 8 uses of set_fields left:
...
gdb/coffread.c:	  type->set_fields (nullptr);
gdb/coffread.c:	  type->set_fields (nullptr);
gdb/coffread.c:	  type->set_fields (nullptr);
gdb/eval.c:  type->set_fields
gdb/gdbtypes.c:  type->set_fields (args);
gdb/gdbtypes.c:  t->set_fields (XRESIZEVEC (struct field, t->fields (),
gdb/dwarf2/read.c:      type->set_fields (new_fields);
gdb/dwarf2/read.c:	      sub_type->set_fields (sub_type->fields () + 1);
...

These fall into the following categories:
- set to nullptr (coffread.c),
- type not owned by objfile or gdbarch (eval.c), and
- modifying an existing fields array, like adding an element at the end or
  dropping an element at the start (the rest).

Tested on x86_64-linux.
2023-08-31 09:37:44 +02:00
Mark Wielaard
a6ce491c3d Use hex_string in gdb/coffread.c instead of PRIxPTR
The getsymname function uses PRIxPTR to print and uintptr_t value in
an error message. Use hex_string instead.

Approved-By: Tom Tromey <tom@tromey.com>
2023-08-28 18:34:05 +02:00
Mark Wielaard
91df9a6f81 Fix gdb/coffread.c build on 32bit architectures
The getsymname function tries to emit an error using %ld for an
uintptr_t argument. Use PRIxPTR instead. Which works on any architecture
for uintptr_t.
2023-08-25 23:12:28 +02:00
Keith Seitz
58abdf8878 Verify COFF symbol stringtab offset
This patch addresses an issue with malformed/fuzzed debug information that
was recently reported in gdb/30639. That bug specifically deals with
an ASAN issue, but the reproducer provided by the reporter causes a
another failure outside of ASAN:

$ ./gdb --data-directory data-directory -nx -q UAF_2
Reading symbols from /home/keiths/UAF_2...


Fatal signal: Segmentation fault
----- Backtrace -----
0x59a53a gdb_internal_backtrace_1
	../../src/gdb/bt-utils.c:122
0x59a5dd _Z22gdb_internal_backtracev
	../../src/gdb/bt-utils.c:168
0x786380 handle_fatal_signal
	../../src/gdb/event-top.c:889
0x7864ec handle_sigsegv
	../../src/gdb/event-top.c:962
0x7ff354c5fb6f ???
0x611f9a process_coff_symbol
	../../src/gdb/coffread.c:1556
0x611025 coff_symtab_read
	../../src/gdb/coffread.c:1172
0x60f8ff coff_read_minsyms
	../../src/gdb/coffread.c:549
0x60fe4b coff_symfile_read
	../../src/gdb/coffread.c:698
0xbde0f6 read_symbols
	../../src/gdb/symfile.c:772
0xbde7a3 syms_from_objfile_1
	../../src/gdb/symfile.c:966
0xbde867 syms_from_objfile
	../../src/gdb/symfile.c:983
0xbded42 symbol_file_add_with_addrs
	../../src/gdb/symfile.c:1086
0xbdf083 _Z24symbol_file_add_from_bfdRKN3gdb7ref_ptrI3bfd18gdb_bfd_ref_policyEEPKc10enum_flagsI16symfile_add_flagEPSt6vectorI14other_sectionsSaISC_EES8_I12objfile_flagEP7objfile
	../../src/gdb/symfile.c:1166
0xbdf0d2 _Z15symbol_file_addPKc10enum_flagsI16symfile_add_flagEPSt6vectorI14other_sectionsSaIS5_EES1_I12objfile_flagE
	../../src/gdb/symfile.c:1179
0xbdf197 symbol_file_add_main_1
	../../src/gdb/symfile.c:1203
0xbdf13e _Z20symbol_file_add_mainPKc10enum_flagsI16symfile_add_flagE
	../../src/gdb/symfile.c:1194
0x90f97f symbol_file_add_main_adapter
	../../src/gdb/main.c:549
0x90f895 catch_command_errors
	../../src/gdb/main.c:518
0x9109b6 captured_main_1
	../../src/gdb/main.c:1203
0x910fc8 captured_main
	../../src/gdb/main.c:1310
0x911067 _Z8gdb_mainP18captured_main_args
	../../src/gdb/main.c:1339
0x418c71 main
	../../src/gdb/gdb.c:39
---------------------
A fatal error internal to GDB has been detected, further
debugging is not possible.  GDB will now terminate.

This is a bug, please report it.  For instructions, see:
<https://www.gnu.org/software/gdb/bugs/>.

Segmentation fault (core dumped)

The issue here is that the COFF offset for the fuzzed symbol's
name is outside the string table. That is, the offset is greater
than the actual string table size.

coffread.c:getsymname actually contains a FIXME about this, and that's
what I've chosen to address to fix this issue, following what is done
in the DWARF reader:

$ ./gdb --data-directory data-directory -nx -q UAF_2
Reading symbols from /home/keiths/UAF_2...
COFF Error: string table offset (256) outside string table (length 0)
(gdb)

Unfortunately, I haven't any idea how else to test this patch since
COFF is not very common anymore. GCC removed support for it five
years ago with GCC 8.
2023-08-25 12:42:19 -07:00
Andrew Burgess
cdb090c88b gdb: fix up a few places where a char was treated as a bool
Spotted a few places where a char is being treated as a bool.  The GDB
style is to use explicit comparisons, so fix things up.

There should be no user visible changes after this commit.
2023-08-23 14:56:24 +01:00
Alan Modra
0e3513d256 gdb: bfd_get_symbol_leading_char vs. ""
Some places matching the first char of a string against
bfd_get_symbol_leading_char, which may be zero, didn't check for "".
This could lead to accesses past the end of the string and potential
buffer overruns.  Fix that, and also get rid of a stupid optimisation
in dbxread when looking for "__DYNAMIC" that also might access past
the end of a string.
2023-08-23 10:07:45 +09:30
Tom Tromey
cbd44c311f Remove most includes of psymtab.h
I found that most spots including psymtab.h do not need it.  This
patch removes these includes, and also one unnecessary include of
psympriv.h.
2023-08-18 10:08:22 -06:00
Alan Modra
2db20b97f1 gdb: warn unused result for bfd IO functions
This fixes the compilation warnings introduced by my bfdio.c patch.

The removed bfd_seeks in coff_symfile_read date back to 1994, commit
7f4c859520, prior to which the file used stdio rather than bfd to read
symbols.  Since it now uses bfd to read the file there should be no
need to synchronise to bfd's idea of the file position.  I also fixed
a potential uninitialised memory access.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-08-11 22:16:32 +09:30
Alan Modra
226f9f4fad Rename bfd_bread and bfd_bwrite
These were renamed from bfd_read and bfd_write back in 2001 when they
lost an unnecessary parameter.  Rename them back, and get rid of a few
casts that are only needed without prototyped functions (K&R C).
2023-08-09 08:48:09 +09:30
Tom de Vries
200546f1a3 [gdb/build] Fix Wstringop-truncation in coff_getfilename
When building gdb with -O2 -fsanitize-threads, I ran into
a Werror=stringop-truncation.

The problem is here in coff_getfilename in coffread.c:
...
      strncpy (buffer, aux_entry->x_file.x_n.x_fname, FILNMLEN);
      buffer[FILNMLEN] = '\0';
...

The constant FILNMLEN is expected to designate the size of
aux_entry->x_file.x_n.x_fname, but that's no longer the case since commit
60ebc25751 ("Fixes a buffer overflow when compiling assembler for the MinGW
targets.").

Fix this by using "sizeof (aux_entry->x_file.x_n.x_fname)" instead.

Likewise in xcoffread.c.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>

PR build/30669
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30669
2023-07-26 17:06:23 +02:00
Andrew Burgess
34f997c8f7 gdb: style filenames in separate debug file warnings
After the commit:

  commit 6647f05df0
  Date:   Tue Jan 24 18:13:38 2023 +0100

      gdb: defer warnings when loading separate debug files

It was pointed out[1] that the warnings being deferred and then later
emitted lacked styling.  The warnings lacked styling before the above
commit, but it was suggested that the filenames in these warnings
should be styled, and this commit does this.

There were a couple of previous attempts[2][3][4] to solve this
problem, but these all tried to extend the mechanism introduced in the
above commit, the deferred warnings were placed directly into a
std::vector, but now we tried to, when appropriate, style these
warnings.  The review feedback that this approach looked too complex.

So instead, this revision adds a new helper class 'deferred_warnings'
which can be used to collect a set of deferred warnings, and then emit
these deferred warnings later, if needed.  This helper class hides the
complexity, so at the point the deferred warning is created no extra
logic is required.

The deferred_warnings class will style the deferred warnings only if
gdb_stderr supports styling.  GDB's warnings are sent to gdb_stderr,
so this should ensure we only style when expected.

There was also review feedback[5] that all of the warnings should be
bundled into a single string_file, this has not been done.  I feel
pretty strongly that separate warnings should be emitted using
separate "warning" calls.  If we do end up with multiple warnings in
this case they aren't really related, one will be about looking up
debug via .gnu_debuglink, while the other will be about build-id based
lookup.  So I'd really rather keep the warnings separate.

[1] https://inbox.sourceware.org/gdb-patches/87edr9pcku.fsf@tromey.com/
[2] https://inbox.sourceware.org/gdb-patches/20230216195604.2685177-1-ahajkova@redhat.com/
[3] https://inbox.sourceware.org/gdb-patches/20230217123547.2737612-1-ahajkova@redhat.com/
[4] https://inbox.sourceware.org/gdb-patches/20230320145638.1202335-1-ahajkova@redhat.com/
[5] https://inbox.sourceware.org/gdb-patches/87o7nh1g8h.fsf@tromey.com/

Co-Authored-By: Alexandra Hájková <ahajkova@redhat.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-07-15 11:27:30 +01:00
Tom Tromey
9675da2535 Use unrelocated_addr in minimal symbols
This changes minimal symbols to use unrelocated_addr.  I believe this
detected a latent bug in add_pe_forwarded_sym.
2023-03-28 15:12:44 -06:00
Alan Modra
a2c7ca15a5 Use stdint types in coff internal_auxent
long is a poor choice of type to store 32-bit values read from
objects files by H_GET_32.  H_GET_32 doesn't sign extend so tests like
that in gdb/coffread.c for "negative" values won't work if long is
larger than 32 bits.  If long is 32-bit then code needs to be careful
to not accidentally index negative array elements.  (I'd rather see a
segfault on an unmapped 4G array index than silently reading bogus
data.)  long is also a poor choice for x_sect.s_scnlen, which might
have 64-bit values.  It's better to use unsigned exact width types to
avoid surprises.

I decided to change the field names too, which makes most of this
patch simply renaming.  Besides that there are a few places where
casts are no longer needed, and where printf format strings or tests
need adjusting.

include/
	* coff/internal.h (union internal_auxent): Use unsigned stdint
	types.  Rename l fields to u32 and u64 as appropriate.
bfd/
	* coff-bfd.c,
	* coff-rs6000.c,
	* coff64-rs6000.c,
	* coffcode.h,
	* coffgen.c,
	* cofflink.c,
	* coffswap.h,
	* peXXigen.c,
	* xcofflink.c: Adjust to suit internal_auxent changes.
binutils/
	* rdcoff.c: Adjust to suit internal_auxent changes.
gas/
	* config/obj-coff.h,
	* config/tc-ppc.c: Adjust to suit internal_auxent changes.
gdb/
	* coffread.c,
	* xcoffread.c: Adjust to suit internal_auxent changes.
ld/
	* pe-dll.c: Adjust to suit internal_auxent changes.
2023-03-27 21:58:46 +10:30
Tom Tromey
a8ed3dde83 Rename objfile_type to builtin_type
This renames objfile_type to be an overload of builtin_type, in
preparation for their unification.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
9e76b17aa5 Use type allocator for array types
This changes the array type creation functions to accept a type
allocator, and updates all the callers.  Note that symbol readers
should generally allocate on the relevant objfile, regardless of the
placement of the index type of the array, which is what this patch
implements.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
e727c536c6 Use type allocator for range types
This changes the range type creation functions to accept a type
allocator, and updates all the callers.  Note that symbol readers
should generally allocate on the relevant objfile, regardless of the
underlying type of the range, which is what this patch implements.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:38 -06:00
Tom Tromey
8a17bdd9cc Remove alloc_type
This removes alloc_type, replacing all uses with the new type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-18 11:12:37 -06:00
Tom Tromey
48e0f38c30 Fix line table regression
Simon pointed out a line table regression, and after a couple of false
starts, I was able to reproduce it by hand using his instructions.

The bug is that most of the code in do_mixed_source_and_assembly uses
unrelocated addresses, but one spot does:

  pc = low;

... after the text offset has been removed.

This patch fixes the problem by introducing a new type to represent
unrelocated addresses in the line table.  This prevents this sort of
bug to some degree (it's still possible to manipulate a CORE_ADDR in a
bad way, this is unavoidable).

However, this did let the compiler flag a few spots in that function,
and now it's not possible to compare an unrelocated address from a
line table with an ordinary CORE_ADDR.

Regression tested on x86-64 Fedora 36, though note this setup never
reproduced the bug in the first place.  I also tested it by hand on
the disasm-optim test program.
2023-03-17 16:17:43 -06:00
Tom Tromey
1acc9dca42 Change linetables to be objfile-independent
This changes linetables to not add the text offset to the addresses
they contain.  I did this in a few steps, necessarily combined
together in one patch: I renamed the 'pc' member to 'm_pc', added the
appropriate accessors, and then recompiled.  Then I fixed all the
errors.  Where possible I generally chose to use the raw_pc accessor,
as it is less expensive.

Note that this patch discounts the possibility that the text section
offset might cause wraparound in the addresses in the line table.
However, this was already discounted -- in particular,
objfile_relocate1 did not re-sort the table in this scenario.  (There
was a bug open about this, but as far as I can tell this has never
happened, it's not even clear what inspired that bug.)

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-11 08:47:40 -07:00
Tom Tromey
100e393531 Remove OBJF_REORDERED
OBJF_REORDERED is set for nearly every object format.  And, despite
the ominous warnings here and there, it does not seem very expensive.
This patch removes the flag entirely.

Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-03-08 12:11:49 -07:00
Tom Tromey
548a89df23 Remove ALL_BLOCK_SYMBOLS
This removes ALL_BLOCK_SYMBOLS in favor of foreach.
2023-02-19 12:51:06 -07:00
Tom Tromey
83bad3162d Do not pass section index to end_compunit_symtab
Right now, the section index passed to end_compunit_symtab is always
SECT_OFF_TEXT.  Remove this parameter and simply always use
SECT_OFF_TEXT.
2023-02-08 08:20:12 -07:00
Alexandra Hájková
6647f05df0 gdb: defer warnings when loading separate debug files
Currently, when GDB loads debug information from a separate debug
file, there are a couple of warnings that could be produced if things
go wrong.

In find_separate_debug_file_by_buildid (build-id.c) GDB can give a
warning if the separate debug file doesn't include any actual debug
information, and in separate_debug_file_exists (symfile.c) we can warn
if the CRC checksum in the separate debug file doesn't match the
checksum in the original executable.

The problem here is that, when looking up debug information, GDB will
try several different approaches, lookup by build-id, lookup by
debug-link, and then a lookup from debuginfod.  GDB can potentially
give a warning from an earlier attempt, and then succeed with a later
attempt.  In the cases I have run into this is primarily a warning
about some out of date debug information on my machine, but then GDB
finds the correct information using debuginfod.  This can be confusing
to a user, they will see warnings from GDB when really everything is
working just fine.

For example:

  warning: the debug information found in "/usr/lib/debug//lib64/ld-2.32.so.debug" \
      does not match "/lib64/ld-linux-x86-64.so.2" (CRC mismatch).

This diagnostic was printed on Fedora 33 even when the correct
debuginfo was downloaded.

In this patch I propose that we defer any warnings related to looking
up debug information from a separate debug file.  If any of the
approaches are successful then GDB will not print any of the warnings.
As far as the user is concerned, everything "just worked".  Only if
GDB completely fails to find any suitable debug information will the
warnings be printed.

The crc_mismatch test compiles two executables: crc_mismatch and
crc_mismatch-2 and then strips them of debuginfo creating separate
debug files. The test then replaces crc_mismatch-2.debug with
crc_mismatch.debug to trigger "CRC mismatch" warning. A local
debuginfod server is setup to supply the correct debug file, now when
GDB looks up the debug info no warning is given.

The build-id-no-debug-warning.exp is similar to the previous test. It
triggers the "separate debug info file has no debug info" warning by
replacing the build-id based .debug file with the stripped binary and
then loading it to GDB.  It then also sets up local debuginfod server
with the correct debug file to download to make sure no warnings are
emitted.
2023-02-01 11:12:35 +00:00
Joel Brobecker
213516ef31 Update copyright year range in header of all files managed by GDB
This commit is the result of running the gdb/copyright.py script,
which automated the update of the copyright year range for all
source files managed by the GDB project to be updated to include
year 2023.
2023-01-01 17:01:16 +04:00
Pedro Alves
f34652de0b internal_error: remove need to pass __FILE__/__LINE__
Currently, every internal_error call must be passed __FILE__/__LINE__
explicitly, like:

  internal_error (__FILE__, __LINE__, "foo %d", var);

The need to pass in explicit __FILE__/__LINE__ is there probably
because the function predates widespread and portable variadic macros
availability.  We can use variadic macros nowadays, and in fact, we
already use them in several places, including the related
gdb_assert_not_reached.

So this patch renames the internal_error function to something else,
and then reimplements internal_error as a variadic macro that expands
__FILE__/__LINE__ itself.

The result is that we now should call internal_error like so:

  internal_error ("foo %d", var);

Likewise for internal_warning.

The patch adjusts all calls sites.  99% of the adjustments were done
with a perl/sed script.

The non-mechanical changes are in gdbsupport/errors.h,
gdbsupport/gdb_assert.h, and gdb/gdbarch.py.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Ia6f372c11550ca876829e8fd85048f4502bdcf06
2022-10-19 15:32:36 +01:00
Simon Marchi
df86565b31 gdb: remove TYPE_LENGTH
Remove the macro, replace all uses with calls to type::length.

Change-Id: Ib9bdc954576860b21190886534c99103d6a47afb
2022-09-21 11:05:21 -04:00
Simon Marchi
b6cdbc9a81 gdb: add type::length / type::set_length
Add the `length` and `set_length` methods on `struct type`, in order to remove
the `TYPE_LENGTH` macro.  In this patch, the macro is changed to use the
getter, so all the call sites of the macro that are used as a setter are
changed to use the setter method directly.  The next patch will remove the
macro completely.

Change-Id: Id1090244f15c9856969b9be5006aefe8d8897ca4
2022-09-21 10:59:51 -04:00
Simon Marchi
27710edb4e gdb: remove TYPE_TARGET_TYPE
Remove the macro, replace all uses by calls to type::target_type.

Change-Id: Ie51d3e1e22f94130176d6abd723255282bb6d1ed
2022-09-21 10:59:49 -04:00
Tom Tromey
98badbfdc2 Use gdb_bfd_ref_ptr in objfile
This changes struct objfile to use a gdb_bfd_ref_ptr.  In addition to
removing some manual memory management, this fixes a use-after-free
that was introduced by the registry rewrite series.  The issue there
was that, in some cases, registry shutdown could refer to memory that
had already been freed.  This help fix the bug by delaying the
destruction of the BFD reference (and thus the per-bfd object) until
after the registry has been shut down.
2022-08-03 13:26:58 -06:00
Tom Tromey
08b8a139c9 Rewrite registry.h
This rewrites registry.h, removing all the macros and replacing it
with relatively ordinary template classes.  The result is less code
than the previous setup.  It replaces large macros with a relatively
straightforward C++ class, and now manages its own cleanup.

The existing type-safe "key" class is replaced with the equivalent
template class.  This approach ended up requiring relatively few
changes to the users of the registry code in gdb -- code using the key
system just required a small change to the key's declaration.

All existing users of the old C-like API are now converted to use the
type-safe API.  This mostly involved changing explicit deletion
functions to be an operator() in a deleter class.

The old "save/free" two-phase process is removed, and replaced with a
single "free" phase.  No existing code used both phases.

The old "free" callbacks took a parameter for the enclosing container
object.  However, this wasn't truly needed and is removed here as
well.
2022-07-28 14:16:50 -06:00
Tom Tromey
ddfc4ef124 ODR warning for "struct find_targ_sec_arg"
"struct find_targ_sec_arg" is defined in multiple .c files, causing
ODR warnings.  This patch renames the types.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
28c5801a94 Do not double-read minimal symbols for PE COFF
This changes coffread.c to avoid re-reading minimal symbols when
possible.  This only works when there are no COFF symbols to be read,
but at least for my mingw builds of gdb, this seems to be the case.

Tested using the AdaCore internal test suite on Windows.  I also did
some local builds to ensure that no warnings crept in.
2022-05-13 08:06:12 -06:00
Simon Marchi
63d609debb gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macros
Replace with calls to blockvector::blocks, and the appropriate method
call on the returned array_view.

Change-Id: I04d1f39603e4d4c21c96822421431d9a029d8ddd
2022-04-27 22:05:03 -04:00