aboutsummaryrefslogtreecommitdiff
path: root/gdb/jit.c
AgeCommit message (Collapse)AuthorFilesLines
2023-11-21gdb: Replace gdb::optional with std::optionalLancelot Six1-1/+1
Since GDB now requires C++17, we don't need the internally maintained gdb::optional implementation. This patch does the following replacing: - gdb::optional -> std::optional - gdb::in_place -> std::in_place - #include "gdbsupport/gdb_optional.h" -> #include <optional> This change has mostly been done automatically. One exception is gdbsupport/thread-pool.* which did not use the gdb:: prefix as it already lives in the gdb namespace. Change-Id: I19a92fa03e89637bab136c72e34fd351524f65e9 Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-10-10gdb: remove target_gdbarchSimon Marchi1-1/+2
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>
2023-10-10gdb: add inferior::{arch, set_arch}Simon Marchi1-1/+1
Make the inferior's gdbarch field private, and add getters and setters. This helped me by allowing putting breakpoints on set_arch to know when the inferior's arch was set. A subsequent patch in this series also adds more things in set_arch. Change-Id: I0005bd1ef4cd6b612af501201cec44e457998eec Reviewed-By: John Baldwin <jhb@FreeBSD.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-06-05Use "unrelocated" terminology in linetable_entryTom Tromey1-1/+2
I forgot to convert struct linetable_entry to use the "unrelocated" (as opposed to "raw") terminology. This patch corrects the oversight.
2023-05-25gdb: remove bp_location_pointer_iteratorSimon Marchi1-3/+3
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-04-17gdb: pass execing and following inferior to inferior_execd observersSimon Marchi1-6/+14
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-03-18Reuse existing builtin typesTom Tromey1-4/+1
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-17Fix line table regressionTom Tromey1-1/+1
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-11Change linetable_entry::is_stmt to boolTom Tromey1-1/+1
This changes linetable_entry::is_stmt to type bool, rather than unsigned. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-03-11Constify linetablesTom Tromey1-3/+5
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-11Change linetables to be objfile-independentTom Tromey1-1/+1
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-02-27Catch gdb_exception_error instead of gdb_exception (in many places)Kevin Buettner1-1/+1
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-19Remove allocate_block and allocate_global_blockTom Tromey1-4/+5
This removes allocate_block and allocate_global_block in favor of simply calling 'new'.
2023-02-19Convert set_block_compunit_symtab to methodTom Tromey1-1/+1
This converts set_block_compunit_symtab to be a method. This was mostly written by script.
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker1-1/+1
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.
2022-10-10Change GDB to use frame_info_ptrTom Tromey1-6/+6
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-09-21gdb: remove TYPE_LENGTHSimon Marchi1-2/+2
Remove the macro, replace all uses with calls to type::length. Change-Id: Ib9bdc954576860b21190886534c99103d6a47afb
2022-08-04Use registry in gdbarchTom Tromey1-26/+11
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-03Use gdb_bfd_ref_ptr in objfileTom Tromey1-1/+1
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-04-27gdb: remove BLOCKVECTOR_MAP macroSimon Marchi1-1/+1
Replace with equivalent methods. Change-Id: I4e56c76dfc363c1447686fb29c4212ea18b4dba0
2022-04-27gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macrosSimon Marchi1-5/+4
Replace with calls to blockvector::blocks, and the appropriate method call on the returned array_view. Change-Id: I04d1f39603e4d4c21c96822421431d9a029d8ddd
2022-04-27gdb: remove BLOCK_MULTIDICT macroSimon Marchi1-4/+4
Replace with equivalent methods. Change-Id: If9a239c511a664f2a59fecb6d1cd579881b23dc2
2022-04-27gdb: remove BLOCK_SUPERBLOCK macroSimon Marchi1-5/+6
Replace with equivalent methods. Change-Id: I334a319909a50b5cc5570a45c38c70e10dc00630
2022-04-27gdb: remove BLOCK_FUNCTION macroSimon Marchi1-1/+1
Replace with equivalent methods. Change-Id: I31ec00f5bf85335c8b23d306ca0fe0b84d489101
2022-04-27gdb: remove BLOCK_{START,END} macrosSimon Marchi1-8/+8
Replace with equivalent methods. Change-Id: I10a6c8a2a86462d9d4a6a6409a3f07a6bea66310
2022-04-20Replace symbol_symtab with symbol::symtabTom Tromey1-1/+1
This turns symbol_symtab into a method on symbol. It also replaces symbol_set_symtab with a method.
2022-04-11gdb: remove symbol value macrosSimon Marchi1-7/+5
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-06Use new and delete in jit.cTom Tromey1-10/+7
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-03-29Unify gdb printf functionsTom Tromey1-12/+12
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-29Unify gdb puts functionsTom Tromey1-2/+2
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-02-11gdb: extend the information printed by 'maint info jit'Jan Vrany1-6/+37
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-06gdb: remove SYMBOL_TYPE macroSimon Marchi1-1/+1
Add a getter and a setter for a symbol's type. Remove the corresponding macro and adjust all callers. Change-Id: Ie1a137744c5bfe1df4d4f9ae5541c5299577c8de
2022-02-06gdb: remove SYMBOL_DOMAIN macroSimon Marchi1-1/+1
Add a getter and a setter for a symbol's domain. Remove the corresponding macro and adjust all callers. Change-Id: I54465b50ac89739c663859a726aef8cdc6e4b8f3
2022-02-06gdb: remove SYMBOL_ACLASS_INDEX macro, add getter/setterSimon Marchi1-1/+1
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-06gdb: remove SYMTAB_LINETABLE macro, add getter/setterSimon Marchi1-4/+3
Add a getter and a setter for a symtab's linetable. Remove the corresponding macro and adjust all callers. Change-Id: I159183fc0ccd8e18ab937b3c2f09ef2244ec6e9c
2022-02-06gdb: remove COMPUNIT_BLOCKVECTOR macro, add getter/setterSimon Marchi1-1/+1
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-06gdb: remove COMPUNIT_DIRNAME macro, add getter/setterSimon Marchi1-1/+1
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-06gdb: remove COMPUNIT_FILETABS macroSimon Marchi1-4/+4
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-04gdb: include jit_code_entry::symfile_addr value in names of objfiles created ↵Simon Marchi1-14/+27
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-01-01Automatic Copyright Year update after running gdb/copyright.pyJoel Brobecker1-1/+1
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.
2021-12-29Send jit.c errors to gdb_stderrTom Tromey1-10/+13
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-11-16gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptrAndrew Burgess1-2/+2
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-07-14gdb: call post_create_inferior at end of follow_fork_inferiorSimon Marchi1-0/+28
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-06-29gdb: add names to unwinders, add debug messages when looking for unwinderSimon Marchi1-0/+1
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-05-27gdb: add breakpoint::locations methodSimon Marchi1-1/+1
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-21[gdb/breakpoint] Fix assert in jit_event_handlerTom de Vries1-1/+5
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-04-24gdbsupport, gdb: give names to observersSimon Marchi1-4/+4
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-01-13gdb: convert jit to new-style debug macrosSimon Marchi1-40/+24
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-11gdb: change jit_debug to a boolSimon Marchi1-9/+9
gdb/ChangeLog: * jit.c (jit_debug): Change type to bool. (_initialize_jit): Adjust. Change-Id: Ic2b1eec28eafe8ccb2899f38ddc91ba9703cb38e
2021-01-01Update copyright year range in all GDB filesJoel Brobecker1-1/+1
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.