From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id ED6103858D1E; Fri, 11 Feb 2022 14:52:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED6103858D1E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: extend the information printed by 'maint info jit' X-Act-Checkin: binutils-gdb X-Git-Author: Jan Vrany X-Git-Refname: refs/heads/master X-Git-Oldrev: 5d0d011be3403bf6fa62e8a7cc72762ef66e17a0 X-Git-Newrev: 18d07d1ea78f1bc225ac6d1203eed6fca8c52b53 Message-Id: <20220211145208.ED6103858D1E@sourceware.org> Date: Fri, 11 Feb 2022 14:52:08 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Feb 2022 14:52:09 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D18d07d1ea78f= 1bc225ac6d1203eed6fca8c52b53 commit 18d07d1ea78f1bc225ac6d1203eed6fca8c52b53 Author: Jan Vrany Date: Mon Feb 7 11:39:22 2022 +0000 gdb: extend the information printed by 'maint info jit' =20 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. =20 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. =20 Additionally, the symfile address is the same address that is now used in the objfile names after commit 4a620b7e. =20 One test that relies on the output of 'maint info jit' was updated to allow for the new output format. Diff: --- gdb/jit.c | 43 ++++++++++++++++++++++++++++-= ---- gdb/jit.h | 13 ++++++++-- gdb/testsuite/gdb.base/jit-elf-fork.exp | 36 ++++++++++++++++++++++----- 3 files changed, 78 insertions(+), 14 deletions(-) diff --git a/gdb/jit.c b/gdb/jit.c index 7819d763ab3..9f57d521a8b 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -82,6 +82,8 @@ maint_info_jit_cmd (const char *args, int from_tty) inferior *inf =3D current_inferior (); bool printed_header =3D false; =20 + gdb::optional table_emitter; + /* Print a line for each JIT-ed objfile. */ for (objfile *obj : inf->pspace->objfiles ()) { @@ -90,11 +92,35 @@ maint_info_jit_cmd (const char *args, int from_tty) =20 if (!printed_header) { - printf_filtered ("Base address of known JIT-ed objfiles:\n"); + table_emitter.emplace (current_uiout, 3, -1, "jit-created-objfiles"); + + /* The +2 allows for the leading '0x', then one character for + every 4-bits. */ + int addr_width =3D 2 + (gdbarch_ptr_bit (obj->arch ()) / 4); + + /* The std::max here selects between the width of an address (as + a string) and the width of the column header string. */ + current_uiout->table_header (std::max (addr_width, 22), ui_left, + "jit_code_entry-address", + "jit_code_entry address"); + current_uiout->table_header (std::max (addr_width, 15), ui_left, + "symfile-address", "symfile address"); + current_uiout->table_header (20, ui_left, + "symfile-size", "symfile size"); + current_uiout->table_body (); + printed_header =3D true; } =20 - printf_filtered (" %s\n", paddress (obj->arch (), obj->jited_data->= addr)); + ui_out_emit_tuple tuple_emitter (current_uiout, "jit-objfile"); + + current_uiout->field_core_addr ("jit_code_entry-address", obj->arch = (), + obj->jited_data->addr); + current_uiout->field_core_addr ("symfile-address", obj->arch (), + obj->jited_data->symfile_addr); + current_uiout->field_unsigned ("symfile-size", + obj->jited_data->symfile_size); + current_uiout->text ("\n"); } } =20 @@ -211,11 +237,13 @@ get_jiter_objfile_data (objfile *objf) at inferior address ENTRY. */ =20 static void -add_objfile_entry (struct objfile *objfile, CORE_ADDR entry) +add_objfile_entry (struct objfile *objfile, CORE_ADDR entry, + CORE_ADDR symfile_addr, ULONGEST symfile_size) { gdb_assert (objfile->jited_data =3D=3D nullptr); =20 - objfile->jited_data.reset (new jited_objfile_data (entry)); + objfile->jited_data.reset (new jited_objfile_data (entry, symfile_addr, + symfile_size)); } =20 /* Helper function for reading the global JIT descriptor from remote @@ -644,7 +672,9 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb, for (gdb_symtab &symtab : obj->symtabs) finalize_symtab (&symtab, objfile); =20 - add_objfile_entry (objfile, priv_data->entry_addr); + add_objfile_entry (objfile, priv_data->entry_addr, + priv_data->entry.symfile_addr, + priv_data->entry.symfile_size); =20 delete obj; } @@ -773,7 +803,8 @@ JITed symbol file is not an object file, ignoring it.\n= ")); &sai, OBJF_SHARED | OBJF_NOT_FILENAME, NULL); =20 - add_objfile_entry (objfile, entry_addr); + add_objfile_entry (objfile, entry_addr, code_entry->symfile_addr, + code_entry->symfile_size); } =20 /* This function registers code associated with a JIT code entry. It uses= the diff --git a/gdb/jit.h b/gdb/jit.h index 09dbce21f5c..274ce456f47 100644 --- a/gdb/jit.h +++ b/gdb/jit.h @@ -95,12 +95,21 @@ struct jiter_objfile_data =20 struct jited_objfile_data { - jited_objfile_data (CORE_ADDR addr) - : addr (addr) + jited_objfile_data (CORE_ADDR addr, CORE_ADDR symfile_addr, + ULONGEST symfile_size) + : addr (addr), + symfile_addr (symfile_addr), + symfile_size (symfile_size) {} =20 /* Address of struct jit_code_entry for this objfile. */ CORE_ADDR addr; + + /* Value of jit_code_entry->symfile_addr for this objfile. */ + CORE_ADDR symfile_addr; + + /* Value of jit_code_entry->symfile_size for this objfile. */ + ULONGEST symfile_size; }; =20 /* Re-establish the jit breakpoint(s). */ diff --git a/gdb/testsuite/gdb.base/jit-elf-fork.exp b/gdb/testsuite/gdb.ba= se/jit-elf-fork.exp index e5b9a18d00c..635248cd8e4 100644 --- a/gdb/testsuite/gdb.base/jit-elf-fork.exp +++ b/gdb/testsuite/gdb.base/jit-elf-fork.exp @@ -81,7 +81,11 @@ proc do_setup { detach-on-fork follow-fork-mode } { gdb_continue_to_breakpoint "continue to before fork" ".*break before fork= .*" =20 # We should have one JIT object loaded. - gdb_test "maint info jit" " ${::hex}" "jit-ed objfiles before fork" + gdb_test "maint info jit" \ + [multi_line \ + "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \ + "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \ + "jit-ed objfiles before fork" =20 # Put a breakpoint just after the fork, continue there. gdb_breakpoint [gdb_get_line_number "break after fork" $::main_srcfile] @@ -89,7 +93,11 @@ proc do_setup { detach-on-fork follow-fork-mode } { =20 # We should still have one JIT object loaded in whatever inferior we are # currently stopped in, regardless of the mode. - gdb_test "maint info jit" " ${::hex}" "jit-ed objfiles after fork" + gdb_test "maint info jit" \ + [multi_line \ + "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \ + "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \ + "jit-ed objfiles after fork" =20 # Delete our breakpoints. delete_breakpoints @@ -108,7 +116,11 @@ proc_with_prefix test_detach_on_fork_off_follow_fork_m= ode_parent { } { =20 # Switch to the child, verify there is a JIT-ed objfile. gdb_test "inferior 2" "Switching to inferior 2.*" - gdb_test "maint info jit" " ${::hex}" "jit-ed objfile in child" + gdb_test "maint info jit" \ + [multi_line \ + "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \ + "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \ + "jit-ed objfile in child" =20 # Continue child past JIT unload, verify there are no more JIT-ed objfile= s. gdb_continue_to_breakpoint "continue to before return - child" ".*break b= efore return.*" @@ -116,7 +128,11 @@ proc_with_prefix test_detach_on_fork_off_follow_fork_m= ode_parent { } { =20 # Go back to parent, the JIT-ed objfile should still be there. gdb_test "inferior 1" "Switching to inferior 1.*" - gdb_test "maint info jit" " ${::hex}" "jit-ed objfile in parent" + gdb_test "maint info jit" \ + [multi_line \ + "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \ + "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \ + "jit-ed objfile in parent" =20 # Continue parent past JIT unload, verify there are no more JIT-ed objfil= es. gdb_continue_to_breakpoint "continue to before return - parent" ".*break = before return.*" @@ -135,7 +151,11 @@ proc_with_prefix test_detach_on_fork_off_follow_fork_m= ode_child { } { =20 # Switch to the parent, verify there is a JIT-ed objfile. gdb_test "inferior 1" "Switching to inferior 1.*" - gdb_test "maint info jit" " ${::hex}" "jit-ed objfile in parent" + gdb_test "maint info jit" \ + [multi_line \ + "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \ + "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \ + "jit-ed objfile in parent" =20 # Continue parent past JIT unload, verify there are no more JIT-ed objfil= es. gdb_continue_to_breakpoint "continue to before return - parent" ".*break = before return.*" @@ -143,7 +163,11 @@ proc_with_prefix test_detach_on_fork_off_follow_fork_m= ode_child { } { =20 # Go back to child, the JIT-ed objfile should still be there. gdb_test "inferior 2" "Switching to inferior 2.*" - gdb_test "maint info jit" " ${::hex}" "jit-ed objfile in child" + gdb_test "maint info jit" \ + [multi_line \ + "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \ + "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \ + "jit-ed objfile in child" =20 # Continue child past JIT unload, verify there are no more JIT-ed objfile= s. gdb_continue_to_breakpoint "continue to before return - child" ".*break b= efore return.*"