This simplifies things a little bit, removing some `find_if` when
inserting or removing objfiles, and the whole
unwrapping_objfile_iterator thing.
Change-Id: Idd1851d36c7834820c9c1639a6a252de643eafba
Use `this` instead of `current_program_space`. Presumably, the method
wants to check the solibs of "this" program space, not the current
global program space (although they are likely always the same at the
moment).
Change-Id: Iaf0534f36bfd47c04c53ed0657da332bdb8fb906
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Make the current program space reference bubble up one level. Pass
`current_program_space` everywhere, except in some cases where we can
get the pspace another way, and it's relatively obvious that it's the
same as the current program space.
Change-Id: Id86b79f1e44f92a398f49d137d57457174dfa96d
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
The `no_shared_libraries` function is currently used to implement the
`nosharedlibrary` command, but it also used internally by other
functions. This does not make a very good internal API.
Add the `no_shared_libraries_command` function to implement the CLI
command. Remove the unused parameters from `no_shared_libraries`.
Remove the `from_tty` parameter of `target_pre_inferior`, since it's now
unused.
Change-Id: I4fcba5ee1e0f7d250aab1a7b62b9ea16265fe962
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Just like the title says... I think this makes things a bit clearer, for
instance where the exec filename is set. It also makes the read call
sites a bit nicer, avoiding the `.get ()`.
Change-Id: If8b58ae8f6270c8a34b868f6ca06128c6671ea3c
Approved-By: Tom Tromey <tom@tromey.com>
Most files including gdbcmd.h currently rely on it to access things
actually declared in cli/cli-cmds.h (setlist, showlist, etc). To make
things easy, replace all includes of gdbcmd.h with includes of
cli/cli-cmds.h. This might lead to some unused includes of
cli/cli-cmds.h, but it's harmless, and much faster than going through
the 170 or so files by hand.
Change-Id: I11f884d4d616c12c05f395c98bbc2892950fb00f
Approved-By: Tom Tromey <tom@tromey.com>
Move declarations of initialize_progspace and initialize_inferiors to
progspace.h and inferior.h, respectively.
Change-Id: I62292ffda429861b9f27d8c836a56d161dfa548d
Approved-By: John Baldwin <jhb@FreeBSD.org>
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>
`struct so_list` was recently renamed to `struct shobj` (in 3fe0dfd160
("gdb: rename struct so_list to shobj")). In hindsight, `solib` would
have been a better name. We have solib.c, the implementations in
solib-*.c, many functions with solib in their name, the solib_loaded /
solib_unloaded observables, etc.
Rename shobj to solib.
Change-Id: I0af1c7a9b29bdda027e9af633f6d37e1cfcacd5d
Approved-By: Tom Tromey <tom@tromey.com>
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.
When running test-case gdb.base/vfork-follow-parent.exp on powerpc64 (likewise
on s390x), I run into:
...
(gdb) PASS: gdb.base/vfork-follow-parent.exp: \
exec_file=vfork-follow-parent-exit: target-non-stop=on: non-stop=off: \
resolution_method=schedule-multiple: print unblock_parent = 1
continue^M
Continuing.^M
Reading symbols from vfork-follow-parent-exit...^M
^M
^M
Fatal signal: Segmentation fault^M
----- Backtrace -----^M
0x1027d3e7 gdb_internal_backtrace_1^M
src/gdb/bt-utils.c:122^M
0x1027d54f _Z22gdb_internal_backtracev^M
src/gdb/bt-utils.c:168^M
0x1057643f handle_fatal_signal^M
src/gdb/event-top.c:889^M
0x10576677 handle_sigsegv^M
src/gdb/event-top.c:962^M
0x3fffa7610477 ???^M
0x103f2144 for_each_block^M
src/gdb/dcache.c:199^M
0x103f235b _Z17dcache_invalidateP13dcache_struct^M
src/gdb/dcache.c:251^M
0x10bde8c7 _Z24target_dcache_invalidatev^M
src/gdb/target-dcache.c:50^M
...
or similar.
The root cause for the segmentation fault is that linux_is_uclinux gives an
incorrect result: it should always return false, given that we're running on a
regular linux system, but instead it returns first true, then false.
In more detail, the segmentation fault happens as follows:
- a program space with an address space is created
- a second program space is about to be created. maybe_new_address_space
is called, and because linux_is_uclinux returns true, maybe_new_address_space
returns false, and no new address space is created
- a second program space with the same address space is created
- a program space is deleted. Because linux_is_uclinux now returns false,
gdbarch_has_shared_address_space (current_inferior ()->arch ()) returns
false, and the address space is deleted
- when gdb uses the address space of the remaining program space, we run into
the segfault, because the address space is deleted.
Hardcoding linux_is_uclinux to false makes the test-case pass.
We leave addressing the root cause for the following commit in this series.
For now, prevent the segmentation fault by making the address space a refcounted
object.
This was already suggested here [1]:
...
A better solution might be to have the address spaces be reference counted
...
Tested on top of trunk on x86_64-linux and ppc64le-linux.
Tested on top of gdb-14-branch on ppc64-linux.
Co-Authored-By: Simon Marchi <simon.marchi@polymtl.ca>
PR gdb/30547
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30547
[1] https://sourceware.org/pipermail/gdb-patches/2023-October/202928.html
Commit 8971d2788e ("gdb: link so_list using intrusive_list") introduced
a bug in clear_solib. Instead of passing an `so_list *` to
remove_target_sections, it passed an `so_list **`. This was not caught
by the compiler, because remove_target_sections takes a `void *` as the
"owner", so you can pass it any pointer and it won't complain.
This happened because I previously had a patch to change the type of the
disposer parameter to be a reference rather than a pointer, so had to
change `so` to `&so`. When dropping that patch, I forgot to revert this
bit and / or it got re-introduced when handling subsequent merge
conflicts. And I didn't properly retest.
Fix that, but try to make things less error prone. Add a union to
represent the possible owner kinds for a target_section. Trying to pass
a pointer to another type than those will not compile.
Change-Id: I600cab5ea0408ccc5638467b760768161ca3036c
Now that so_list lists are implemented using intrusive_list, it doesn't
really make sense for the element type to be named "_list". Rename to
just `struct shobj` (`struct so` was deemed to be not greppable enough).
Change-Id: I1063061901298bb40fee73bf0cce44cd12154c0e
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
Replace the hand-made linked list implementation with intrusive_list,
simplying management of list items.
Change-Id: I7f55fd88325bb197cc655c9be5a2ec966d8cc48d
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
This function is just a wrapper around the current inferior's gdbarch.
I find that having that wrapper just obscures where the arch is coming
from, and that it's often used as "I don't know which arch to use so
I'll use this magical target_gdbarch function that gets me an arch" when
the arch should in fact come from something in the context (a thread,
objfile, symbol, etc). I think that removing it and inlining
`current_inferior ()->arch ()` everywhere will make it a bit clearer
where that arch comes from and will trigger people into reflecting
whether this is the right place to get the arch or not.
Change-Id: I79f14b4e4934c88f91ca3a3155f5fc3ea2fadf6b
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
Initially I just wanted a Python event for when GDB removes a program
space, I'm writing a Python extension that caches information for each
program space, and need to know when I should discard entries for a
particular program space.
But, it seemed easy enough to also add an event for when GDB adds a
new program space, so I went ahead and added both new events.
Of course, we don't currently have an observable for program space
addition or removal, so I first needed to add these. After that it's
pretty simple to add two new Python events and have these trigger.
The two new event registries are:
events.new_progspace
events.free_progspace
These emit NewProgspaceEvent and FreeProgspaceEvent objects
respectively, each of these new event types has a 'progspace'
attribute that contains the relevant gdb.Progspace object.
There's a couple of things to be mindful of.
First, it is not possible to catch the NewProgspaceEvent for the very
first program space, the one that is created when GDB first starts, as
this program space is created before any Python scripts are sourced.
In order to allow this event to be caught we would need to defer
creating the first program space, and as a consequence the first
inferior, until some later time. But, existing scripts could easily
depend on there being an initial inferior, so I really don't think we
should change that -- and so, we end up with the consequence that we
can't catch the event for the first program space.
The second, I think minor, issue, is that GDB doesn't clean up its
program spaces upon exit -- or at least, they are not cleaned up
before Python is shut down. As a result, any program spaces in use at
the time GDB exits don't generate a FreeProgspaceEvent. I'm not
particularly worried about this for my use case, I'm using the event
to ensure that a cache doesn't hold stale entries within a single GDB
session. It's also easy enough to add a Python at-exit callback which
can do any final cleanup if needed.
Finally, when testing, I did hit a slightly weird issue with some of
the remote boards (e.g. remote-stdio-gdbserver). As a consequence of
this issue I see some output like this in the gdb.log:
(gdb) PASS: gdb.python/py-progspace-events.exp: inferior 1
step
FreeProgspaceEvent: <gdb.Progspace object at 0x7fb7e1d19c10>
warning: cannot close "target:/lib64/libm.so.6": Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
warning: cannot close "target:/lib64/libc.so.6": Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
warning: cannot close "target:/lib64/ld-linux-x86-64.so.2": Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
do_parent_stuff () at py-progspace-events.c:41
41 ++global_var;
(gdb) PASS: gdb.python/py-progspace-events.exp: step
The 'FreeProgspaceEvent ...' line is expected, that's my test Python
extension logging the event. What isn't expected are all the blocks
like:
warning: cannot close "target:/lib64/libm.so.6": Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
It turns out that this has nothing to do with my changes, this is just
a consequence of reading files over the remote protocol. The test
forks a child process which GDB stays attached too. When the child
exits, GDB cleans up by calling prune_inferiors, which in turn can
result in GDB trying to close some files that are open because of the
inferior being deleted.
If the prune_inferiors call occurs when the remote target is
running (and in non-async mode) then GDB will try to send a fileio
packet while the remote target is waiting for a stop reply, and the
remote target will throw an error, see remote_target::putpkt_binary in
remote.c for details.
I'm going to look at fixing this, but, as I said, this is nothing to
do with this change, I just mention it because I ended up needing to
account for these warning messages in one of my tests, and it all
looks a bit weird.
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
This adds a new objfile_for_address method to gdb.Progspace. This
makes it easy to find the objfile for a given address.
There's a related PR; and while this change would have been sufficient
for my original need, it's not clear to me whether I should close the
bug. Nevertheless I think it makes sense to at least mention it here.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19288
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
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.
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.
This changes address_space to use new and delete, and makes some other
small C++-ification changes as well, like changing address_space_num
to be a method.
This patch was needed for the subsequent patch to rewrite the registry
system.
A while back, I changed objfiles to be held via a shared_ptr. The
idea at the time was that this was a step toward writing to the index
cache in the background, and this would let gdb keep a reference alive
to do so. However, since then we've rewritten the DWARF reader, and
the new index can do this without requiring a shared pointer -- in
fact there are patches pending to implement this.
This patch switches objfile management to unique_ptr, which makes more
sense now.
Regression tested on x86-64 Fedora 34.
Now that filtered and unfiltered output can be treated identically, we
can unify the printf family of functions. This is done under the name
"gdb_printf". Most of this patch was written by script.
This commit brings all the changes made by running gdb/copyright.py
as per GDB's Start of New Year Procedure.
For the avoidance of doubt, all changes in this commits were
performed by the script.
Change inferior_list, the global list of inferiors, to use
intrusive_list. I think most other changes are somewhat obvious
fallouts from this change.
There is a small change in behavior in scoped_mock_context. Before this
patch, constructing a scoped_mock_context would replace the whole
inferior list with only the new mock inferior. Tests using two
scoped_mock_contexts therefore needed to manually link the two inferiors
together, as the second scoped_mock_context would bump the first mock
inferior from the thread list. With this patch, a scoped_mock_context
adds its mock inferior to the inferior list on construction, and removes
it on destruction. This means that tests run with mock inferiors in the
inferior list in addition to any pre-existing inferiors (there is always
at least one). There is no possible pid clash problem, since each
scoped mock inferior uses its own process target, and pids are per
process target.
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I7eb6a8f867d4dcf8b8cd2dcffd118f7270756018
I was always a bit confused by next_adapter, because it kind of mixes
the element type and the iterator type. In reality, it is not much more
than a class that wraps two iterators (begin and end). However, it
assumes that:
- you can construct the begin iterator by passing a pointer to the
first element of the iterable
- you can default-construct iterator to make the end iterator
I think that by generalizing it a little bit, we can re-use it at more
places.
Rename it to "iterator_range". I think it describes a bit better: it's
a range made by wrapping a begin and end iterator. Move it to its own
file, since it's not related to next_iterator anymore.
iterator_range has two constructors. The variadic one, where arguments
are forwarded to construct the underlying begin iterator. The end
iterator is constructed through default construction. This is a
generalization of what we have today.
There is another constructor which receives already constructed begin
and end iterators, useful if the end iterator can't be obtained by
default-construction. Or, if you wanted to make a range that does not
end at the end of the container, you could pass any iterator as the
"end".
This generalization allows removing some "range" classes, like
all_inferiors_range. These classes existed only to pass some arguments
when constructing the begin iterator. With iterator_range, those same
arguments are passed to the iterator_range constructed and then
forwarded to the constructed begin iterator.
There is a small functional difference in how iterator_range works
compared to next_adapter. next_adapter stored the pointer it received
as argument and constructeur an iterator in the `begin` method.
iterator_range constructs the begin iterator and stores it as a member.
Its `begin` method returns a copy of that iterator.
With just iterator_range, uses of next_adapter<foo> would be replaced
with:
using foo_iterator = next_iterator<foo>;
using foo_range = iterator_range<foo_iterator>;
However, I added a `next_range` wrapper as a direct replacement for
next_adapter<foo>. IMO, next_range is a slightly better name than
next_adapter.
The rest of the changes are applications of this new class.
gdbsupport/ChangeLog:
* next-iterator.h (class next_adapter): Remove.
* iterator-range.h: New.
gdb/ChangeLog:
* breakpoint.h (bp_locations_range): Remove.
(bp_location_range): New.
(struct breakpoint) <locations>: Adjust type.
(breakpoint_range): Use iterator_range.
(tracepoint_range): Use iterator_range.
* breakpoint.c (breakpoint::locations): Adjust return type.
* gdb_bfd.h (gdb_bfd_section_range): Use iterator_range.
* gdbthread.h (all_threads_safe): Pass argument to
all_threads_safe_range.
* inferior-iter.h (all_inferiors_range): Use iterator_range.
(all_inferiors_safe_range): Use iterator_range.
(all_non_exited_inferiors_range): Use iterator_range.
* inferior.h (all_inferiors, all_non_exited_inferiors): Pass
inferior_list as argument.
* objfiles.h (struct objfile) <compunits_range>: Remove.
<compunits>: Return compunit_symtab_range.
* progspace.h (unwrapping_objfile_iterator)
<unwrapping_objfile_iterator>: Take parameter by value.
(unwrapping_objfile_range): Use iterator_range.
(struct program_space) <objfiles_range>: Define with "using".
<objfiles>: Adjust.
<objfiles_safe_range>: Define with "using".
<objfiles_safe>: Adjust.
<solibs>: Return so_list_range, define here.
* progspace.c (program_space::solibs): Remove.
* psymtab.h (class psymtab_storage) <partial_symtab_iterator>:
New.
<partial_symtab_range>: Use iterator_range.
* solist.h (so_list_range): New.
* symtab.h (compunit_symtab_range):
New.
(symtab_range): New.
(compunit_filetabs): Change to a function.
* thread-iter.h (inf_threads_range,
inf_non_exited_threads_range, safe_inf_threads_range,
all_threads_safe_range): Use iterator_range.
* top.h (ui_range): New.
(all_uis): Use ui_range.
Change-Id: Ib7a9d2a3547f45f01aa1c6b24536ba159db9b854
This commits the result of running gdb/copyright.py as per our Start
of New Year procedure...
gdb/ChangeLog
Update copyright year range in copyright header of all GDB files.
There's no need to call exec_close from ~progspace, because that
method just does some cleanup that's already going to be done during
destruction. This patch removes the call.
gdb/ChangeLog
2020-10-29 Tom Tromey <tom@tromey.com>
* progspace.c (program_space::~program_space): Don't call
exec_close.
This changes program_space_empty_p to be a method on program_space.
It also changes it to return bool. I removed the "_p" suffix because
"empty" is a "well-known" C++ method name.
gdb/ChangeLog
2020-10-29 Tom Tromey <tom@tromey.com>
* inferior.c (delete_inferior): Update.
* progspace.c (program_space::empty): Rename from
program_space_empty_p. Return bool.
* progspace.h (struct program_space) <empty>: New method.
(program_space_empty_p): Don't declare.
This changes clear_program_space_solib_cache to be a method on
program_space. Also, it removes a call to this function from the
program_space destructor, as that is not necessary.
gdb/ChangeLog
2020-10-29 Tom Tromey <tom@tromey.com>
* progspace.c (program_space::~program_space): Don't call
clear_program_space_solib_cache.
(program_space::clear_solib_cache): Rename from
clear_solib_cache.
* solib.c (handle_solib_event): Update.
* progspace.h (struct program_space) <clear_solib_cache>: New
method.
(clear_program_space_solib_cache): Don't declare.
exec_close uses the current program space, so it seemed cleaner to
change it to be a method on program_space. This patch makes this
change.
gdb/ChangeLog
2020-10-29 Tom Tromey <tom@tromey.com>
* progspace.c (program_space::exec_close): New method, from
exec_close in exec.c.
* exec.c (exec_close): Move to progspace.c.
(exec_target::close, exec_file_attach): Update.
* progspace.h (struct program_space) <exec_close>: Declare
method.
This removes the exec_filename macro, replacing it with uses of the
member of current_program_space. This also renames that member, and
changes it to be a unique pointer.
gdb/ChangeLog
2020-10-29 Tom Tromey <tom@tromey.com>
* progspace.h (struct program_space) <exec_filename>: Rename from
pspace_exec_filename. Now a unique_xmalloc_ptr.
* inferior.c (print_selected_inferior): Update.
(print_inferior): Update.
* mi/mi-main.c (print_one_inferior): Update.
* exec.h (exec_filename): Remove macro.
* corefile.c (get_exec_file): Update.
* exec.c (exec_close): Update.
(exec_file_attach): Update.
* progspace.c (clone_program_space): Update.
(print_program_space): Update.
The call to clear_section_table in ~program_space is now clearly not
needed -- the section table will clear itself. This patch removes
this call and then inlines the one remaining call to
clear_section_table.
gdb/ChangeLog
2020-10-12 Tom Tromey <tom@tromey.com>
* progspace.c (program_space::~program_space): Don't call
clear_section_table.
* exec.h (clear_section_table): Don't declare.
* exec.c (exec_target::close): Update.
(clear_section_table): Remove.
By inspection, I noticed that print_program_space is calling
target_pid_to_str on the wrong target stack. Most targets print a
process pid the same way, so it isn't actually visible.
gdb/ChangeLog:
* progspace.c (print_program_space): Use all_inferiors. Switch to
the inferior before calling target_pid_to_str.
gdb.base/corefile.exp is showing an unexpected failure and an
unresolved testcase when testing against unix/-m32:
(gdb) PASS: gdb.base/corefile.exp: attach: sanity check we see the core file
attach 15741
gdb/dwarf2-frame.c:1009: internal-error: dwarf2_frame_cache* dwarf2_frame_cache(frame_info*, void**): Assertion `fde != NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) FAIL: gdb.base/corefile.exp: attach: with core (GDB internal error)
Resyncing due to internal error.
This regressed with:
From 5b6d1e4fa4 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Fri, 10 Jan 2020 20:06:08 +0000
Subject: [PATCH] Multi-target support
The assertion is here:
#0 internal_error (file=0xbffffccb0 <error: Cannot access memory at address 0xbffffccb0>, line=0, fmt=0x555556327320 "en_US.UTF-8") at sr
c/gdbsupport/errors.cc:51
#1 0x00005555557d4e45 in dwarf2_frame_cache (this_frame=0x55555672f950, this_cache=0x55555672f968) at src/gdb/dwarf2/frame.c:1013
#2 0x00005555557d5886 in dwarf2_frame_this_id (this_frame=0x55555672f950, this_cache=0x55555672f968, this_id=0x55555672f9b0) at src/gdb/d
warf2/frame.c:1226
#3 0x00005555558b184e in compute_frame_id (fi=0x55555672f950) at src/gdb/frame.c:558
#4 0x00005555558b19b2 in get_frame_id (fi=0x55555672f950) at src/gdb/frame.c:588
#5 0x0000555555bda338 in scoped_restore_current_thread::scoped_restore_current_thread (this=0x7fffffffd0d8) at src/gdb/thread.c:1458
#6 0x00005555556ce41f in scoped_restore_current_pspace_and_thread::scoped_restore_current_pspace_and_thread (During symbol reading: .debug_line address at offset 0x1db2d3
is 0 [in module /home/pedro/gdb/cascais-builds/binutils-gdb/gdb/gdb]
this=0x7fffffffd0d0) at src/gdb/progspace-and-thread.h:29
#7 0x0000555555898ea6 in remove_target_sections (owner=0x555556935550) at src/gdb/exec.c:798
#8 0x0000555555b700b6 in symfile_free_objfile (objfile=0x555556935550) at src/gdb/symfile.c:3742
#9 0x000055555565050e in std::_Function_handler<void (objfile*), void (*)(objfile*)>::_M_invoke(std::_Any_data const&, objfile*&&) (__functor=..., __args#0=@0x7fffffffd190
: 0x555556935550) at /usr/include/c++/9/bits/std_function.h:300
#10 0x0000555555a3053d in std::function<void (objfile*)>::operator()(objfile*) const (this=0x555556752a20, __args#0=0x555556935550) at /usr/include/c++/9/bits/std_function.
h:688
#11 0x0000555555a2ff01 in gdb::observers::observable<objfile*>::notify (this=0x5555562eaa80 <gdb::observers::free_objfile>, args#0=0x555556935550) at /net/cascais.nfs/gdb/b
inutils-gdb/src/gdb/../gdbsupport/observable.h:106
#12 0x0000555555a2c56a in objfile::~objfile (this=0x555556935550, __in_chrg=<optimized out>) at src/gdb/objfiles.c:521
#13 0x0000555555a31d46 in std::_Sp_counted_ptr<objfile*, (__gnu_cxx::_Lock_policy)2>::_M_dispose (this=0x555556c1f6f0) at /usr/include/c++/9/bits/shared_ptr_base.h:377
#14 0x00005555556d3444 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x555556c1f6f0) at /usr/include/c++/9/bits/shared_ptr_base.h:155
#15 0x00005555556cec77 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=0x555556b99ee8, __in_chrg=<optimized out>) at /usr/include/c++/9/bits/shared_ptr_base.h:730
#16 0x0000555555a2f8da in std::__shared_ptr<objfile, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x555556b99ee0, __in_chrg=<optimized out>) at /usr/include/c++/9/bits/shared_ptr_base.h:1169
#17 0x0000555555a2f8fa in std::shared_ptr<objfile>::~shared_ptr (this=0x555556b99ee0, __in_chrg=<optimized out>) at /usr/include/c++/9/bits/shared_ptr.h:103
#18 0x0000555555a63fba in __gnu_cxx::new_allocator<std::_List_node<std::shared_ptr<objfile> > >::destroy<std::shared_ptr<objfile> > (this=0x55555679f0c0, __p=0x555556b99ee0) at /usr/include/c++/9/ext/new_allocator.h:153
#19 0x0000555555a638fb in std::allocator_traits<std::allocator<std::_List_node<std::shared_ptr<objfile> > > >::destroy<std::shared_ptr<objfile> > (__a=..., __p=0x555556b99ee0) at /usr/include/c++/9/bits/alloc_traits.h:497
#20 0x0000555555a6351c in std::__cxx11::list<std::shared_ptr<objfile>, std::allocator<std::shared_ptr<objfile> > >::_M_erase (this=0x55555679f0c0, __position=std::shared_ptr<objfile> (expired, weak count 1) = {get() = 0x555556935550}) at /usr/include/c++/9/bits/stl_list.h:1921
#21 0x0000555555a62dab in std::__cxx11::list<std::shared_ptr<objfile>, std::allocator<std::shared_ptr<objfile> > >::erase (this=0x55555679f0c0, __position=std::shared_ptr<objfile> (expired, weak count 1) = {get() = 0x555556935550}) at /usr/include/c++/9/bits/list.tcc:158
#22 0x0000555555a614dd in program_space::remove_objfile (this=0x55555679f080, objfile=0x555556935550) at src/gdb/progspace.c:207
#23 0x0000555555a2c4dc in objfile::unlink (this=0x555556935550) at src/gdb/objfiles.c:497
#24 0x0000555555a2da65 in objfile_purge_solibs () at src/gdb/objfiles.c:904
#25 0x0000555555b3af74 in no_shared_libraries (ignored=0x0, from_tty=1) at src/gdb/solib.c:1236
#26 0x0000555555bbafc7 in target_pre_inferior (from_tty=1) at src/gdb/target.c:1900
#27 0x0000555555940afb in attach_command (args=0x5555563277c7 "15741", from_tty=1) at src/gdb/infcmd.c:2582
...
The problem is that the multi-target commit added a
scoped_restore_current_thread to remove_target_sections (frame #7
above). scoped_restore_current_thread's ctor fetches the selected
frame's frame id. If the frame had not had its frame id computed yet,
it is computed then (frame #4 above). Because it has been determined
earlier that the frame's unwinder is the DWARF unwinder, we end up
here:
static struct dwarf2_frame_cache *
dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
{
...
/* Find the correct FDE. */
fde = dwarf2_frame_find_fde (&pc1, &cache->per_objfile);
gdb_assert (fde != NULL);
And, that assertion fails. The assertion is reasonable, because the
DWARF unwinder only claims the frame if it managed to find the FDE
earlier (in dwarf2_frame_sniffer).
(unix/-m32 is thus really a red herring here -- it's just that on
x86_64 -m64, the frame is not claimed by the DWARF unwinder.)
The reason the assertion is failing, is because the objfile that
contains the FDE has been removed from the objfiles list already when
we get here (frame #22 above). This suggests that the fix should be
to invalidate DWARF frames when their objfile is removed. Or to keep
it simple and safe, invalidate the frame cache when an objfile is
removed. That is what this commit does.
OOC, I checked why is it that when you unload a file with plain "(gdb)
file", we don't hit the assertion. It must be because we're already
flushing the frame cache somewhere else in that case. And indeed, we
flush the frame cache here:
(gdb) bt
#0 reinit_frame_cache () at src/gdb/frame.c:1857
#1 0x0000555555ad1ad6 in registers_changed_ptid (target=0x0, ptid=...) at src/gdb/regcache.c:470
#2 0x0000555555ad1b58 in registers_changed () at src/gdb/regcache.c:485
#3 0x00005555558d095e in set_target_gdbarch (new_gdbarch=0x555556d5f5b0) at src/gdb/gdbarch.c:5528
#4 0x0000555555677175 in set_gdbarch_from_file (abfd=0x0) at src/gdb/arch-utils.c:601
#5 0x0000555555897c6b in exec_file_attach (filename=0x0, from_tty=1) at src/gdb/exec.c:409
#6 0x000055555589852d in exec_file_command (args=0x0, from_tty=1) at src/gdb/exec.c:571
#7 0x00005555558985a1 in file_command (arg=0x0, from_tty=1) at src/gdb/exec.c:583
#8 0x000055555572b55f in do_const_cfunc (c=0x55555672e200, args=0x0, from_tty=1) at src/gdb/cli/cli-decode.c:95
#9 0x000055555572f3d3 in cmd_func (cmd=0x55555672e200, args=0x0, from_tty=1) at src/gdb/cli/cli-decode.c:2181
#10 0x0000555555be1ecc in execute_command (p=0x555556327804 "", from_tty=1) at src/gdb/top.c:668
#11 0x0000555555895427 in command_handler (command=0x555556327800 "file") at src/gdb/event-top.c:588
#12 0x00005555558958af in command_line_handler (rl=...) at src/gdb/event-top.c:773
#13 0x0000555555894b3e in gdb_rl_callback_handler (rl=0x55555a09e240 "file") at src/gdb/event-top.c:219
#14 0x0000555555ccfeec in rl_callback_read_char () at src/readline/readline/callback.c:281
#15 0x000055555589495a in gdb_rl_callback_read_char_wrapper_noexcept () at src/gdb/event-top.c:177
#16 0x0000555555894a08 in gdb_rl_callback_read_char_wrapper (client_data=0x555556327520) at src/gdb/event-top.c:194
#17 0x00005555558952a5 in stdin_event_handler (error=0, client_data=0x555556327520) at src/gdb/event-top.c:516
#18 0x0000555555e027d6 in handle_file_event (file_ptr=0x555558d20840, ready_mask=1) at src/gdbsupport/event-loop.cc:548
#19 0x0000555555e02d88 in gdb_wait_for_event (block=1) at src/gdbsupport/event-loop.cc:673
#20 0x0000555555e01c42 in gdb_do_one_event () at src/gdbsupport/event-loop.cc:215
#21 0x00005555559c47c2 in start_event_loop () at src/gdb/main.c:356
#22 0x00005555559c490d in captured_command_loop () at src/gdb/main.c:416
#23 0x00005555559c6217 in captured_main (data=0x7fffffffdc00) at src/gdb/main.c:1253
#24 0x00005555559c6289 in gdb_main (args=0x7fffffffdc00) at src/gdb/main.c:1268
#25 0x0000555555621756 in main (argc=3, argv=0x7fffffffdd18) at src/gdb/gdb.c:32
gdb/ChangeLog:
PR gdb/26336
* progspace.c (program_space::remove_objfile): Invalidate the
frame cache.
This patch started as an attempt to replace ALL_SO_LIBS with an
ordinary C++ iterator. However, then I tripped over the so_list_head
define again, and decided to remove it as well.
gdb/ChangeLog
2020-05-08 Tom Tromey <tom@tromey.com>
* mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Update.
* solib-svr4.c (svr4_fetch_objfile_link_map): Update.
(enable_break): Update.
* solib-frv.c (frv_fdpic_find_global_pointer): Update.
(frv_fdpic_find_canonical_descriptor): Update.
(frv_fetch_objfile_link_map): Update.
* progspace.c (program_space::free_all_objfiles): Update.
(program_space::solibs): New method.
* progspace.h (struct program_space) <solibs>: New method.
* solist.h (master_so_list): Don't declare.
(ALL_SO_LIBS): Remove.
* solib.h (so_list_head): Remove.
(update_solib_list): Update comment.
* solib.c (master_so_list): Remove.
(solib_used, update_solib_list, solib_add)
(info_sharedlibrary_command, clear_solib)
(reload_shared_libraries_1, remove_user_added_objfile): Update.
Currently, while the program_space's ctor adds the new pspace to the
pspaces list, the destructor doesn't remove the pspace from the pspace
list. Instead, you're supposed to use delete_program_space, to both
remove the pspace from the list, and deleting the pspace.
This patch eliminates delete_program_space, and makes the pspace dtor
remove the deleted pspace from the pspace list itself, i.e., makes the
dtor do the mirror opposite of the ctor.
I found this helps with a following patch that will allocate a mock
program_space on the stack. It's easier to just let the regular dtor
remove the mock pspace from the pspace list than arrange to call
delete_program_space instead of the pspace dtor in that situation.
While at it, move the ctor/dtor intro comments to the header file, and
make the ctor explicit.
gdb/ChangeLog:
2020-04-16 Pedro Alves <palves@redhat.com>
* inferior.c (delete_inferior): Use delete operator directly
instead of delete_program_space.
* progspace.c (add_program_space): New, factored out from
program_space::program_space.
(remove_program_space): New, factored out from
delete_program_space.
(program_space::program_space): Remove intro comment. Rewrite.
(program_space::~program_space): Remove intro comment. Call
remove_program_space.
(delete_program_space): Delete.
* progspace.h (program_space::program_space): Make explicit. Move
intro comment here, adjusted.
(program_space::~program_space): Move intro comment here,
adjusted.
(delete_program_space): Remove.
With multi-target, each inferior now has its own target connection.
The problem in switch_to_program_space_and_thread is that in the
current state GDB switches to "no thread" and also sets the program
space but because the inferior is not switched, potentially an
incorrect target remains selected.
Here is a sample scenario that exploits this flow:
On terminal 1, start a gdbserver on a program named foo:
$ gdbserver :1234 ./foo
On terminal 2, start gdb on a program named bar. Suppose foo and bar
are compiled from foo.c and bar.c. They are completely separate. So,
bar.c:2 has no meaning for foo.
$ gdb -q ./bar
Reading symbols from ./bar...
(gdb) add-inferior
[New inferior 2]
Added inferior 2
(gdb) inferior 2
[Switching to inferior 2 [<null>] (<noexec>)]
(gdb) target remote :1234
...
(gdb) set debug remote 2
(gdb) break bar.c:2
Sending packet: $Hgp0.0#ad...Packet received: OK
Sending packet: $m5fa,12#f8...Packet received: E01
Sending packet: $m5fa,1#c6...Packet received: E01
Sending packet: $m5fb,3#c9...Packet received: E01
Sending packet: $m5fe,1#ca...Packet received: E01
Breakpoint 1 at 0x5fe: file bar.c, line 2.
(gdb)
Here we have an unnecessary sending of the packets to the gdbserver.
With this fix in progspace-and-thread.c, we'll get this:
(gdb) break bar.c:2
Breakpoint 1 at 0x5fe: file bar.c, line 2.
(gdb)
Now there is no sending of the packets to gdbserver.
The changes around clear_symtab_users calls are necessary because
otherwise we regress gdb.base/step-over-exit.exp, hitting the new
assertion in switch_to_program_space_and_thread. The problem is, a
forked child terminates, and when GDB decides to auto-purge that
inferior, GDB tries to switch to the pspace of that no-longer-existing
inferior.
The root of the problem is within the program_space destructor:
program_space::~program_space ()
{
...
set_current_program_space (this); # (1)
...
breakpoint_program_space_exit (this); # (2)
...
free_all_objfiles (); # (3)
...
}
We get here from delete_inferior -> delete_program_space.
So we're deleting an inferior, and the inferior to be
deleted is no longer in the inferior list.
At (2), we've deleted all the breakpoints and locations for the
program space being deleted.
The crash happens while doing a breakpoint re-set, called by
clear_symtab_users at the tail end of (3). That is, while recreating
breakpoints for the current program space, which is the program space
we're tearing down. During breakpoint re-set, we try to switch to the
new location's pspace (the current pspace set in (1), so the pspace
we're tearing down) with switch_to_program_space_and_thread, and that
hits the failed assertion. It's the fact that we recreate breakpoints
in the program_space destructor that is the latent bug here. Just
don't do that, and we don't end up in the crash situation.
My first approach to fix this added a symfile_add_flags parameter to
program_space::free_all_objfiles, and then passed that down to
clear_symtab_users. The program_space dtor would then pass down
SYMFILE_DEFER_BP_RESET to free_all_objfiles. I couldn't help feeling
that adding that parameter to free_all_objfiles looked a little
awkward, so I settled on something a little different -- hoist the
clear_symtab_users call to the callers. There are only two callers.
I felt that that didn't look as odd, particularly since
remove_symbol_file_command also does:
objf->unlink ();
clear_symtab_users (0);
I.e., objfile deletion is already separate from calling
clear_symtab_users in some places.
gdb/ChangeLog:
2020-01-10 Aleksandar Paunovic <aleksandar.paunovic@intel.com>
Pedro Alves <palves@redhat.com>
* progspace-and-thread.c (switch_to_program_space_and_thread):
Assert there's an inferior for PSPACE. Use
switch_to_inferior_no_thread to switch the inferior too.
* progspace.c (program_space::~program_space): Call
clear_symtab_users here, with SYMFILE_DEFER_BP_RESET.
(program_space::free_all_objfiles): Don't call clear_symtab_users
here.
* symfile.c (symbol_file_clear): Call clear_symtab_users here.
gdb/testsuite/ChangeLog:
2020-01-10 Pedro Alves <palves@redhat.com>
* gdb.server/bkpt-other-inferior.exp: New file.
This changes objfiles to be managed using a shared_ptr. shared_ptr is
chosen because it enables the use of objfiles in background threads.
The simplest way to do this was to introduce a new iterator that will
return the underlying objfile, rather than a shared_ptr. (I also
tried changing the rest of gdb to use shared_ptr, but this was quite
large; and to using intrusive reference counting, but this also was
tricky.)
gdb/ChangeLog
2019-12-12 Tom Tromey <tom@tromey.com>
* progspace.h (objfile_list): New typedef.
(class unwrapping_objfile_iterator)
(struct unwrapping_objfile_range): Newl
(struct program_space) <objfiles_range>: Change type.
<objfiles>: Change return type.
<add_objfile>: Change type of "objfile" parameter.
<objfiles_list>: Now a list of shared_ptr.
* progspace.c (program_space::add_objfile): Change type of
"objfile". Update.
(program_space::remove_objfile): Update.
* objfiles.h (struct objfile) <~objfile>: Make public.
* objfiles.c (objfile::make): Update.
(objfile::unlink): Don't call delete.
Change-Id: I6fb7fbf06efb7cb7474c525908365863eae27eb3
This changes free_all_objfiles to be a method on program_space, in
line with the other changes to treat program_space as a container for
objfiles.
gdb/ChangeLog
2019-12-12 Tom Tromey <tom@tromey.com>
* symfile.c (symbol_file_clear): Update.
* progspace.h (struct program_space) <free_all_objfiles>: Declare
method.
* progspace.c (program_space::free_all_objfiles): New method.
* objfiles.h (free_all_objfiles): Don't declare.
* objfiles.c (free_all_objfiles): Move to program_space.
Change-Id: I908b549d2981b6005f7ca181fc0e6d24fc8b7b6f
This removes the MULTI_OBJFILE_P macro in favor of a method on the
program space.
gdb/ChangeLog
2019-12-12 Tom Tromey <tom@tromey.com>
* progspace.c (program_space::multi_objfile_p): New method.
* printcmd.c (info_symbol_command): Update.
* maint.c (maintenance_translate_address): Update.
* objfiles.h (MULTI_OBJFILE_P): Remove.
* progspace.h (struct program_space) <multi_objfile_p>: New
method.
Change-Id: I2779e26ea8909078d63fea8f13bce94cab73948c