Commit Graph

208 Commits

Author SHA1 Message Date
Tom Tromey
0434c3ef8d Use "unrelocated" terminology in linetable_entry
I forgot to convert struct linetable_entry to use the "unrelocated"
(as opposed to "raw") terminology.  This patch corrects the oversight.
2023-06-05 09:59:18 -06:00
Simon Marchi
b00b30b298 gdb: remove bp_location_pointer_iterator
Remove the bp_location_pointer_iterator layer.  Adjust all users of
breakpoint::locations to use references instead of pointers.

Change-Id: Iceed34f5e0f5790a9cf44736aa658be6d1ba1afa
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-05-25 09:40:58 -04:00
Simon Marchi
4a1283c8d5 gdb: pass execing and following inferior to inferior_execd observers
The upcoming patch to support exec in the amd-dbgapi target needs to
detach amd-dbgapi from the inferior doing the exec and attach amd-dbgapi
to the inferior continuing the execution.  They may or may not be the
same, depending on the `set follow-exec-mode` setting.  But even if they
are the same, we need to do the detach / attach dance.

With the current observable signature, the observers only receive the
inferior in which execution continues (the "following" inferior).

Change the signature to pass both inferiors, and update all existing
observers.

Change-Id: I259d1ea09f70f43be739378d6023796f2fce2659
Reviewed-By: Pedro Alves <pedro@palves.net>
2023-04-17 13:47:13 -04:00
Tom Tromey
95751990e4 Reuse existing builtin types
This changes a few spots to reuse the existing builting "void" type,
rather than construct a new one.

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
ddc6677b17 Change linetable_entry::is_stmt to bool
This changes linetable_entry::is_stmt to type bool, rather than
unsigned.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-11 08:48:29 -07:00
Tom Tromey
977a0c161d Constify linetables
Linetables no longer change after they are created.  This patch
applies const to them.

Note there is one hack to cast away const in mdebugread.c.  This code
allocates a linetable using 'malloc', then later copies it to the
obstack.  While this could be cleaned up, I chose not to do so because
I have no way of testing it.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-11 08:48:10 -07: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
Kevin Buettner
b1ffd1124a Catch gdb_exception_error instead of gdb_exception (in many places)
As described in the previous commit for this series, I became
concerned that there might be instances in which a QUIT (due to either
a SIGINT or SIGTERM) might not cause execution to return to the top
level.  In some (though very few) instances, it is okay to not
propagate the exception for a Ctrl-C / SIGINT, but I don't think that
it is ever okay to swallow the exception caused by a SIGTERM.
Allowing that to happen would definitely be a deviation from the
current behavior in which GDB exits upon receipt of a SIGTERM.

I looked at all cases where an exception handler catches a
gdb_exception.  Handlers which did NOT need modification were those
which satisifed one or more of the following conditions:

  1) There is no call path to maybe_quit() in the try block.  I used a
     static analysis tool to help make this determination.  In
     instances where the tool didn't provide an answer of "yes, this
     call path can result in maybe_quit() being called", I reviewed it
     by hand.

  2) The catch block contains a throw for conditions that it
     doesn't want to handle; these "not handled" conditions
     must include the quit exception and the new "forced quit" exception.

  3) There was (also) a catch for gdb_exception_quit.

Any try/catch blocks not meeting the above conditions could
potentially swallow a QUIT exception.

My first thought was to add catch blocks for gdb_exception_quit and
then rethrow the exception.  But Pedro pointed out that this can be
handled without adding additional code by simply catching
gdb_exception_error instead.  That's what this patch series does.

There are some oddball cases which needed to be handled differently,
plus the extension languages, but those are handled in later patches.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761
Tested-by: Tom de Vries <tdevries@suse.de>
Approved-by: Pedro Alves <pedro@palves.net>
2023-02-27 16:20:39 -07:00
Tom Tromey
522553837b Remove allocate_block and allocate_global_block
This removes allocate_block and allocate_global_block in favor of
simply calling 'new'.
2023-02-19 12:51:06 -07:00
Tom Tromey
cade9c8a45 Convert set_block_compunit_symtab to method
This converts set_block_compunit_symtab to be a method.  This was
mostly written by script.
2023-02-19 12:51:06 -07: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
Tom Tromey
bd2b40ac12 Change GDB to use frame_info_ptr
This changes GDB to use frame_info_ptr instead of frame_info *
The substitution was done with multiple sequential `sed` commands:

sed 's/^struct frame_info;/class frame_info_ptr;/'
sed 's/struct frame_info \*/frame_info_ptr /g' - which left some
    issues in a few files, that were manually fixed.
sed 's/\<frame_info \*/frame_info_ptr /g'
sed 's/frame_info_ptr $/frame_info_ptr/g' - used to remove whitespace
    problems.

The changed files were then manually checked and some 'sed' changes
undone, some constructors and some gets were added, according to what
made sense, and what Tromey originally did

Co-Authored-By: Bruno Larsen <blarsen@redhat.com>
Approved-by: Tom Tomey <tom@tromey.com>
2022-10-10 11:57:10 +02: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
Tom Tromey
cb275538db Use registry in gdbarch
gdbarch implements its own registry-like approach.  This patch changes
it to instead use registry.h.  It's a rather large patch but largely
uninteresting -- it's mostly a straightforward conversion from the old
approach to the new one.

The main benefit of this change is that it introduces type safety to
the gdbarch registry.  It also removes a bunch of code.

One possible drawback is that, previously, the gdbarch registry
differentiated between pre- and post-initialization setup.  This
doesn't seem very important to me, though.
2022-08-04 13:28:04 -06: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
Simon Marchi
414705d1c2 gdb: remove BLOCKVECTOR_MAP macro
Replace with equivalent methods.

Change-Id: I4e56c76dfc363c1447686fb29c4212ea18b4dba0
2022-04-27 22:05:03 -04: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
Simon Marchi
24d74bb5df gdb: remove BLOCK_MULTIDICT macro
Replace with equivalent methods.

Change-Id: If9a239c511a664f2a59fecb6d1cd579881b23dc2
2022-04-27 22:05:03 -04:00
Simon Marchi
f135fe728e gdb: remove BLOCK_SUPERBLOCK macro
Replace with equivalent methods.

Change-Id: I334a319909a50b5cc5570a45c38c70e10dc00630
2022-04-27 22:05:03 -04:00
Simon Marchi
6c00f721c8 gdb: remove BLOCK_FUNCTION macro
Replace with equivalent methods.

Change-Id: I31ec00f5bf85335c8b23d306ca0fe0b84d489101
2022-04-27 22:05:03 -04:00
Simon Marchi
4b8791e10e gdb: remove BLOCK_{START,END} macros
Replace with equivalent methods.

Change-Id: I10a6c8a2a86462d9d4a6a6409a3f07a6bea66310
2022-04-27 22:05:02 -04:00
Tom Tromey
4206d69e96 Replace symbol_symtab with symbol::symtab
This turns symbol_symtab into a method on symbol.  It also replaces
symbol_set_symtab with a method.
2022-04-20 09:28:40 -06:00
Simon Marchi
4aeddc50d7 gdb: remove symbol value macros
Remove all macros related to getting and setting some symbol value:

    #define SYMBOL_VALUE(symbol)           (symbol)->value.ivalue
    #define SYMBOL_VALUE_ADDRESS(symbol)                         \
    #define SET_SYMBOL_VALUE_ADDRESS(symbol, new_value)    \
    #define SYMBOL_VALUE_BYTES(symbol)     (symbol)->value.bytes
    #define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->value.common_block
    #define SYMBOL_BLOCK_VALUE(symbol)     (symbol)->value.block
    #define SYMBOL_VALUE_CHAIN(symbol)     (symbol)->value.chain
    #define MSYMBOL_VALUE(symbol)          (symbol)->value.ivalue
    #define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->value.address + 0)
    #define MSYMBOL_VALUE_ADDRESS(objfile, symbol)                         \
    #define BMSYMBOL_VALUE_ADDRESS(symbol) \
    #define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value)   \
    #define MSYMBOL_VALUE_BYTES(symbol)    (symbol)->value.bytes
    #define MSYMBOL_BLOCK_VALUE(symbol)    (symbol)->value.block

Replace them with equivalent methods on the appropriate objects.

Change-Id: Iafdab3b8eefc6dc2fd895aa955bf64fafc59ed50
2022-04-11 10:45:36 -04:00
Tom Tromey
8fb1059308 Use new and delete in jit.c
This changes jit.c to use new and delete, rather than XCNEW.  This
simplifies the code a little.  This was useful for another patch I'm
working on, and I thought it would make sense to send it separately.

Regression tested on x86-64 Fedora 34.
2022-04-06 14:16:07 -06:00
Tom Tromey
6cb06a8cda Unify gdb printf functions
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.
2022-03-29 12:46:24 -06:00
Tom Tromey
0426ad513f Unify gdb puts functions
Now that filtered and unfiltered output can be treated identically, we
can unify the puts family of functions.  This is done under the name
"gdb_puts".  Most of this patch was written by script.
2022-03-29 12:46:24 -06:00
Jan Vrany
18d07d1ea7 gdb: extend the information printed by 'maint info jit'
This commit updates the output of 'maint info jit' to print not just
the jit_code_entry address, but also the symfile address, and the
symfile size.

The new information could be obtained by looking into target memory at
the contents of the jit_code_entry, but, by storing this information
within gdb at the time the jit object is loaded, it is now possible to
check if the jit_code_entry has been modified in target memory behind
gdb's back.

Additionally, the symfile address is the same address that is now used
in the objfile names after commit 4a620b7e.

One test that relies on the output of 'maint info jit' was updated to
allow for the new output format.
2022-02-11 14:51:56 +00:00
Simon Marchi
5f9c5a63ce gdb: remove SYMBOL_TYPE macro
Add a getter and a setter for a symbol's type.  Remove the corresponding
macro and adjust all callers.

Change-Id: Ie1a137744c5bfe1df4d4f9ae5541c5299577c8de
2022-02-06 16:03:47 -05:00
Simon Marchi
6c9c307c67 gdb: remove SYMBOL_DOMAIN macro
Add a getter and a setter for a symbol's domain.  Remove the
corresponding macro and adjust all callers.

Change-Id: I54465b50ac89739c663859a726aef8cdc6e4b8f3
2022-02-06 16:03:46 -05:00
Simon Marchi
ba44b1a3e0 gdb: remove SYMBOL_ACLASS_INDEX macro, add getter/setter
Add a getter and a setter for a symbol's aclass index.  Remove the
corresponding macro and adjust all callers.

Change-Id: Ie8c8d732624cfadb714aba5ddafa3d29409b3d39
2022-02-06 16:03:46 -05:00
Simon Marchi
5b6074611e gdb: remove SYMTAB_LINETABLE macro, add getter/setter
Add a getter and a setter for a symtab's linetable.  Remove the
corresponding macro and adjust all callers.

Change-Id: I159183fc0ccd8e18ab937b3c2f09ef2244ec6e9c
2022-02-06 15:48:19 -05:00
Simon Marchi
af39c5c874 gdb: remove COMPUNIT_BLOCKVECTOR macro, add getter/setter
Add a getter and a setter for a compunit_symtab's blockvector.  Remove
the corresponding macro and adjust all callers.

Change-Id: I99484c6619dcbbea7c5d89c72aa660316ca62f64
2022-02-06 15:48:18 -05:00
Simon Marchi
0d9acb4531 gdb: remove COMPUNIT_DIRNAME macro, add getter/setter
Add a getter and a setter for a compunit_symtab's dirname.  Remove the
corresponding macro and adjust all callers.

Change-Id: If2f39b295fd26822586485e04a8b8b5aa5cc9b2e
2022-02-06 15:48:18 -05:00
Simon Marchi
510860f278 gdb: remove COMPUNIT_FILETABS macro
I think that most remaining uses of COMPUNIT_FILETABS intend to get the
primary filetab of the compunit_symtab specifically (and not to iterate
over all filetabs, for example, those cases would use compunit_filetabs,
which has been converted to compunit_symtab::filetabs), so replace mosts
uses with compunit_symtab::primary_filetab.

In jit.c, function finalize_symtab, we can save the symtab object
returned by allocate_symtab and use it, it makes things simpler.

Change-Id: I4e51d6d4b40759de8768b61292e5e13c8eae2e38
2022-02-06 15:48:18 -05:00
Simon Marchi
4a620b7e30 gdb: include jit_code_entry::symfile_addr value in names of objfiles created by jit reader API
This commit includes the JIT object's symfile address in the names of
objfiles created by JIT reader API (e.g., << JIT compiled code at
0x7ffd8a0c77a0 >>).  This allows one to at least differentiate one from
another.

The address is the one that the debugged program has put in
jit_code_entry::symfile_addr, and that the JIT reader's read function
receives.  As we can see in gdb.base/jit-reader-host.c and
gdb.base/jit-reader.c, that may not be the actual value of where the
JIT-ed code is.  But it is a value chosen by the author of the JIT
engine and the JIT reader, so including this value in the objfile name
may help them correlate the JIT objfiles created by with their logs /
data structures.

To access this field, we need to pass down a reference to the
jit_code_entry.  So make jit_dbg_reader_data a structure (instead of an
alias for a CORE_ADDR) that includes the address of the code entry in
the inferior's address space (the previous meaning of
jit_dbg_reader_data) plus a reference to the jit_code_entry as read into
GDB's address space.  And while at it, pass down the gdbarch, so that we
don't have to call target_gdbarch.

Co-Authored-By: Jan Vrany <jan.vrany@labware.com>
Change-Id: Ib26c4d1bd8de503d651aff89ad2e500cb312afa5
2022-02-04 11:07:37 -05:00
Joel Brobecker
4a94e36819 Automatic Copyright Year update after running gdb/copyright.py
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.
2022-01-01 19:13:23 +04:00
Tom Tromey
0fed74615b Send jit.c errors to gdb_stderr
jit.c writes some error messages to gdb_stdout, but using gdb_stderr
is better.  This is part of PR gdb/7233.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7233
2021-12-29 10:40:10 -07:00
Andrew Burgess
8579fd136a gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptr
The motivation is to reduce the number of places where unmanaged
pointers are returned from allocation type routines.  All of the
callers are updated.

There should be no user visible changes after this commit.
2021-11-16 17:45:45 +00:00
Simon Marchi
ff77083572 gdb: call post_create_inferior at end of follow_fork_inferior
GDB doesn't handle well the case of an inferior using the JIT interface
to register JIT-ed objfiles and forking.  If an inferior registers a
code object using the JIT interface and then forks, the child process
conceptually has the same code object loaded, so GDB should look it up
and learn about it (it currently doesn't).

To achieve this, I think it would make sense to have the
inferior_created observable called when an inferior is created due to a
fork in follow_fork_inferior.  The inferior_created observable is
currently called both after starting a new inferior and after attaching
to an inferior, allowing various sub-components to learn about that new
executing inferior.  We can see handling a fork child just like
attaching to it, so any work done when attaching should also be done in
the case of a fork child.

Instead of just calling the inferior_created observable, this patch
makes follow_fork_inferior call the whole post_create_inferior function.
This way, the attach and follow-fork code code paths are more alike.

Given that post_create_inferior calls solib_create_inferior_hook,
follow_fork_inferior doesn't need to do it itself, so those calls to
solib_create_inferior_hook are removed.

One question you may have: why not just call post_create_inferior at the
places where solib_create_inferior_hook is currently called, instead of
after target_follow_fork?

 - there's something fishy for the second solib_create_inferior_hook
   call site: at this point we have switched the current program space
   to the child's, but not the current inferior nor the current thread.
   So solib_create_inferior_hook (and everything under, including
   check_for_thread_db, for example) is called with inferior 1 as the
   current inferior and inferior 2's program space as the current
   program space.  I think that's wrong, because at this point we are
   setting up inferior 2, and all that code relies on the current
   inferior.  We could just add a switch_to_thread call before it to
   make inferior 2 the current one, but there are other problems (see
   below).

 - solib_create_inferior_hook is currently not called on the
   `follow_child && detach_fork` path.  I think we need to call it,
   because we still get a new inferior in that case (even though we
   detach the parent).  If we only call post_create_inferior where
   solib_create_inferior_hook used to be called, then the JIT
   subcomponent doesn't get informed about the new inferior, and that
   introduces a failure in the new gdb.base/jit-elf-fork.exp test.

 - if we try to put the post_create_inferior just after the
   switch_to_thread that was originally at line 662, or just before the
   call to target_follow_fork, we introduce a subtle failure in
   gdb.threads/fork-thread-pending.exp.  What happens then is that
   libthread_db gets loaded (somewhere under post_create_inferior)
   before the linux-nat target learns about the LWPs (which happens in
   linux_nat_target::follow_fork).  As a result, the ALL_LWPS loop in
   try_thread_db_load_1 doesn't see the child LWP, and the thread-db
   target doesn't have the chance to fill in thread_info::priv.  A bit
   later, when the test does "info threads", and
   thread_db_target::pid_to_str is called, the thread-db target doesn't
   recognize the thread as one of its own, and delegates the request to
   the target below.  Because the pid_to_str output is not the expected
   one, the test fails.

   This tells me that we need to call the process target's follow_fork
   first, to make the process target create the necessary LWP and thread
   structures.  Then, we can call post_create_inferior to let the other
   components of GDB do their thing.

   But then you may ask: check_for_thread_db is already called today,
   somewhere under solib_create_inferior_hook, and that is before
   target_follow_fork, why don't we see this ordering problem!?  Well,
   because of the first bullet point: when check_for_thread_db /
   thread_db_load are called, the current inferior is (erroneously)
   inferior 1, the parent.  Because libthread_db is already loaded for
   the parent, thread_db_load early returns.  check_for_thread_db later
   gets called by linux_nat_target::follow_fork.  At this point, the
   current inferior is the correct one and the child's LWP exists, so
   all is well.

Since we now call post_create_inferior after target_follow_fork, which
calls the inferior_created observable, which calls check_for_thread_db,
I don't think linux_nat_target needs to explicitly call
check_for_thread_db itself, so that is removed.

In terms of testing, this patch adds a new gdb.base/jit-elf-fork.exp
test.  It makes an inferior register a JIT code object and then fork.
It then verifies that whatever the detach-on-fork and follow-fork-child
parameters are, GDB knows about the JIT code object in all the inferiors
that survive the fork.  It verifies that the inferiors can unload that
code object.

There isn't currently a way to get visibility into GDB's idea of the JIT
code objects for each inferior.  For the purpose of this test, add the
"maintenance info jit" command.  There isn't much we can print about the
JIT code objects except their load address.  So the output looks a bit
bare, but it's good enough for the test.

gdb/ChangeLog:

	* NEWS: Mention "maint info jit" command.
	* infrun.c (follow_fork_inferior): Don't call
	solib_create_inferior_hook, call post_create_inferior if a new
	inferior was created.
	* jit.c (maint_info_jit_cmd): New.
	(_initialize_jit): Register new command.
	* linux-nat.c (linux_nat_target::follow_fork): Don't call
	check_for_thread_db.
	* linux-nat.h (check_for_thread_db): Remove declaration.
	* linux-thread-db.c (check_thread_signals): Make static.

gdb/doc/ChangeLog:

	* gdb.texinfo (Maintenance Commands): Mention "maint info jit".

gdb/testsuite/ChangeLog:

	* gdb.base/jit-elf-fork-main.c: New test.
	* gdb.base/jit-elf-fork-solib.c: New test.
	* gdb.base/jit-elf-fork.exp: New test.

Change-Id: I9a192e55b8a451c00e88100669283fc9ca60de5c
2021-07-14 23:18:24 -04:00
Simon Marchi
a154d838a7 gdb: add names to unwinders, add debug messages when looking for unwinder
I wrote this while debugging a problem where the expected unwinder for a
frame wasn't used.  It adds messages to show which unwinders are
considered for a frame, why they are not selected (if an exception is
thrown), and finally which unwinder is selected in the end.

To be able to show a meaningful, human-readable name for the unwinders,
add a "name" field to struct frame_unwind, and update all instances to
include a name.

Here's an example of the output:

    [frame] frame_unwind_find_by_frame: this_frame=0
    [frame] frame_unwind_try_unwinder: trying unwinder "dummy"
    [frame] frame_unwind_try_unwinder: no
    [frame] frame_unwind_try_unwinder: trying unwinder "dwarf2 tailcall"
    [frame] frame_unwind_try_unwinder: no
    [frame] frame_unwind_try_unwinder: trying unwinder "inline"
    [frame] frame_unwind_try_unwinder: no
    [frame] frame_unwind_try_unwinder: trying unwinder "jit"
    [frame] frame_unwind_try_unwinder: no
    [frame] frame_unwind_try_unwinder: trying unwinder "python"
    [frame] frame_unwind_try_unwinder: no
    [frame] frame_unwind_try_unwinder: trying unwinder "amd64 epilogue"
    [frame] frame_unwind_try_unwinder: no
    [frame] frame_unwind_try_unwinder: trying unwinder "i386 epilogue"
    [frame] frame_unwind_try_unwinder: no
    [frame] frame_unwind_try_unwinder: trying unwinder "dwarf2"
    [frame] frame_unwind_try_unwinder: yes

gdb/ChangeLog:

	* frame-unwind.h (struct frame_unwind) <name>: New.  Update
	instances everywhere to include this field.
	* frame-unwind.c (frame_unwind_try_unwinder,
	frame_unwind_find_by_frame): Add debug messages.

Change-Id: I813f17777422425f0d08b22499817b23922e8ddb
2021-06-29 12:05:03 -04:00
Simon Marchi
40cb8ca539 gdb: add breakpoint::locations method
Add the breakpoint::locations method, which returns a range that can be
used to iterate over a breakpoint's locations.  This shortens

  for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next)

into

  for (bp_location *loc : b->locations ())

Change all the places that I found that could use it.

gdb/ChangeLog:

	* breakpoint.h (bp_locations_range): New.
	(struct breakpoint) <locations>: New.  Use where possible.

Change-Id: I1ba2f7d93d57e544e1f8609124587dcf2e1da037
2021-05-27 14:58:37 -04:00
Tom de Vries
6d1a09b77a [gdb/breakpoint] Fix assert in jit_event_handler
Consider a minimal test-case test.c:
...
int main (void) { return 0; }
...
which we can compile into llvm byte code using clang:
...
$ clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf test.c
...
and then run using lli, which uses the llvm jit:
...
$ lli test.ll
...

If we run this under gdb, we run into an assert:
...
$ gdb -q -batch -ex run --args /usr/bin/lli test.ll
Dwarf Error: Cannot not find DIE at 0x18a936e7 \
  [from module libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug]

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
src/gdb/jit.c:1178: internal-error: \
  void jit_event_handler(gdbarch*, objfile*): \
  Assertion `jiter->jiter_data != nullptr' failed.
...

This is caused by the following.

When running jit_breakpoint_re_set_internal, we first handle
libLLVM.so.10.debug, and set a jit breakpoint.

Next we handle libLLVM.so.10:
...
(gdb) p the_objfile.original_name
$42 = 0x2494170 "libLLVM.so.10"
...
but the minimal symbols we find are from libLLVM.so.10.debug:
...
(gdb) p reg_symbol.objfile.original_name
$43 = 0x38e7c50 "libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug"
(gdb) p desc_symbol.objfile.original_name
$44 = 0x38e7c50 "libLLVM.so.10-10.0.1-lp152.30.4.x86_64.debug"
...
and consequently, the objf_data is the one from libLLVM.so.10.debug:
...
      jiter_objfile_data *objf_data
        = get_jiter_objfile_data (reg_symbol.objfile);
...
and so we hit this:
...
      if (objf_data->cached_code_address == addr)
        continue;
...
and no second jit breakpoint is inserted.

Subsequently, the jit breakpoint is triggered and handled, but when finding
the symbol for the breakpoint address we get:
...
(gdb) p jit_bp_sym.objfile.original_name
$52 = 0x2494170 "libLLVM.so.10"
...

The assert 'jiter->jiter_data != nullptr' triggers because it checks
libLLVM.so.10 while the one with jiter_data setup is libLLVM.so.10.debug.

This fixes the assert:
...
       jiter_objfile_data *objf_data
-        = get_jiter_objfile_data (reg_symbol.objfile);
-        = get_jiter_objfile_data (the_objfile);
...
but consequently we'll have two jit breakpoints, so we also make sure we don't
set a jit breakpoint on separate debug objects like libLLVM.so.10.debug.

Tested on x86_64-linux.

gdb/ChangeLog:

2021-05-21  Tom de Vries  <tdevries@suse.de>

	PR breakpoint/27889
	* jit.c (jit_breakpoint_re_set_internal): Skip separate debug
	objects.  Call get_jiter_objfile_data with the_objfile.
2021-05-21 15:09:14 +02:00
Simon Marchi
c90e7d6352 gdbsupport, gdb: give names to observers
Give a name to each observer, this will help produce more meaningful
debug message.

gdbsupport/ChangeLog:

	* observable.h (class observable) <struct observer> <observer>:
	Add name parameter.
	<name>: New field.
	<attach>: Add name parameter, update all callers.

Change-Id: Ie0cc4664925215b8d2b09e026011b7803549fba0
2021-04-24 19:26:41 -04:00
Simon Marchi
54ca900277 gdb: convert jit to new-style debug macros
Here's a sample output, with infrun debug enabled as well to show
nesting:

    [infrun] fetch_inferior_event: enter
      [infrun] print_target_wait_results: target_wait (-1.0.0 [process -1], status) =
      [infrun] print_target_wait_results:   4116727.4116727.0 [process 4116727],
      [infrun] print_target_wait_results:   status->kind = stopped, signal = GDB_SIGNAL_TRAP
      [infrun] handle_inferior_event: status->kind = stopped, signal = GDB_SIGNAL_TRAP
      [infrun] start_step_over: enter
        [infrun] start_step_over: stealing global queue of threads to step, length = 0
        [infrun] operator(): step-over queue now empty
      [infrun] start_step_over: exit
      [infrun] handle_signal_stop: stop_pc=0x555555555229
      [infrun] handle_jit_event: handling bp_jit_event
      [jit] jit_read_descriptor: descriptor_addr = 0x5555555580b0
      [jit] jit_register_code: symfile_addr = 0x7000000, symfile_size = 15560
      [jit] jit_bfd_try_read_symtab: symfile_addr = 0x7000000, symfile_size = 15560
      [jit] jit_breakpoint_re_set_internal: breakpoint_addr = 0x555555555229
      [infrun] process_event_stop_test: BPSTAT_WHAT_SINGLE
      [infrun] process_event_stop_test: no stepping, continue
      [infrun] resume_1: step=1, signal=GDB_SIGNAL_0, trap_expected=1, current thread [process 4116727] at 0x555555555229
      [infrun] prepare_to_wait: prepare_to_wait
    [infrun] fetch_inferior_event: exit

gdb/ChangeLog:

	* jit.c (jit_debug_printf): New, use throughout file.

Change-Id: Ic0f5eb3ffc926fb555de4914e7dc1076ada63a97
2021-01-13 11:08:08 -05:00
Simon Marchi
062eaacbac gdb: change jit_debug to a bool
gdb/ChangeLog:

	* jit.c (jit_debug): Change type to bool.
	(_initialize_jit): Adjust.

Change-Id: Ic2b1eec28eafe8ccb2899f38ddc91ba9703cb38e
2021-01-11 16:18:48 -05:00
Joel Brobecker
3666a04883 Update copyright year range in all GDB files
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.
2021-01-01 12:12:21 +04:00
Mihails Strasuns
15cc148fb8 gdb: move bfd_open_from_target_memory to gdb_bfd
This function allows to create a BFD handle using an accessible memory
range in a target memory.  It is currently contained in a JIT module but
this functionality may be of wider usefullness - for example, reading
ELF binaries contained within a core dump.

gdb/ChangeLog:
2020-12-07  Mihails Strasuns  <mihails.strasuns@intel.com>

	* jit.c (mem_bfd*, bfd_open_from_target_memory): Removed.
	* gdb_bfd.h (gdb_bfd_open_from_target_memory): New function.
	* gdb_bfd.c (mem_bfd*, gdb_bfd_open_from_target_memory): New functions.
2020-12-10 11:18:00 +01:00
Simon Marchi
42a4fec513 gdb: add inferior_execd observable
I want to add another action (clearing displaced stepping state) that
happens when an inferior execs.  I think it would be cleaner to have an
observer for this event, rather than have infrun know about each other
sub-component.

Replace the calls to solib_create_inferior_hook and
jit_inferior_created_hook in follow_exec by observers.

gdb/ChangeLog:

	* observable.h (inferior_execd): Declare new observable.
	* observable.c (inferior_execd): Declare new observable.
	* infrun.c (follow_exec): Notify inferior_execd observer.
	* jit.c (jit_inferior_created_hook): Make static.
	(_initialize_jit): Register inferior_execd observer.
	* jit.h (jit_inferior_created_hook): Remove declaration.
	* solib.c (_initialize_solib): Register inferior_execd observer.

Change-Id: I000cce00094e23baa67df693d912646b6ae38e44
2020-12-04 16:43:52 -05:00
Simon Marchi
324956617c gdb: make jit.c use the inferior_created inferior parameter
Use the inferior parameter now available in jit_inferior_created_hook.
It is passed down to jit_inferior_init, which uses it as much as
possible instead of the current inferior or current program space.

gdb/ChangeLog:

	* jit.c (jit_reader_load_command): Pass current inferior.
	(jit_inferior_init): Change parameter type to inferior, use it.
	(jit_inferior_created): Remove.
	(jit_inferior_created_hook): Pass inferior parameter down.
	(_initialize_jit): Use jit_inferior_created_hook instead of
	jit_inferior_created.
	* jit.h (jit_inferior_created_hook): Add inferior parameter.
	* infrun.c (follow_exec): Pass inferior to
	jit_inferior_created_hook.

Change-Id: If3a2114a933370dd313d5abd623136d273cdb8fa
2020-10-25 09:06:09 -04:00