From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id HITDEy2RAmIgYQAAWB0awg (envelope-from ) for ; Tue, 08 Feb 2022 10:50:05 -0500 Received: by simark.ca (Postfix, from userid 112) id 403F41F3C6; Tue, 8 Feb 2022 10:50:05 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 492A81EE1A for ; Tue, 8 Feb 2022 10:50:04 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B90703858404 for ; Tue, 8 Feb 2022 15:50:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B90703858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1644335403; bh=JYmfYRjNLniW81DpnI/Vi8J0pmmlk6pnM+Tgxwxvetg=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jq2aRiZx/kAasV1lSilp6Ph41kh8El3Ia52abwBRSulk4HCr54P9eoCujsNM+xZ8I TyaT3jGo9/IhYMEJcWDzaZ52mWi/QV/GlgWR4F0/c4Z85AAoLVMV2BBMbZNHRBLbxu ivrC1Zpai64sL/6b5yQB3d8Ev1yqZV/3LQDLeCPs= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id F26273858D1E for ; Tue, 8 Feb 2022 15:49:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F26273858D1E Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-194-2AqKNIwQPDeyLDDkOPN2Fg-1; Tue, 08 Feb 2022 10:49:41 -0500 X-MC-Unique: 2AqKNIwQPDeyLDDkOPN2Fg-1 Received: by mail-wr1-f69.google.com with SMTP id h24-20020adfaa98000000b001e33eb81e71so527341wrc.9 for ; Tue, 08 Feb 2022 07:49:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JYmfYRjNLniW81DpnI/Vi8J0pmmlk6pnM+Tgxwxvetg=; b=Xo621WyybEbEKdJ42rECztIcLMSI/pR1xugn32I9/I/sHlNyjpLB4KUREpydEogvPp wUET0uREeJAB8TiRerFHt24+cM2A6sQ52nlEeVOEJAnWewcKA0P03YzpKv/Yr4UJ3UBt +EIr+ljr5izPJnxjIoPYdFBduEnrD2Kc9kyaSYWfsmf4SBUJsak9oeLB/VtDJffuuJoQ C44IM/y1tLhSwbmf79fc4lqtImJE519k0DLYKiedfS0ugXz5PUDgvYIocSpTGBSbXJ2x tF//iouw86LSWAb37qhaNxTTzU5QMDjsmUlU34yTSRGoxYXjuu2RJ7kzZL6u+3Y8BH4j JG5A== X-Gm-Message-State: AOAM533spKScFbC4l0oQMk3z4UQ8k76kL0BC4bm5wZg7rm9RxUzG61bo LzzSVa9huGCjPN+StVcK1Y05KqsElOTq9KzsK0I/rTJBoQIOf8rYy1g2s1PfyN1kwDX41VtDyII pSQz3n2pnBhQfobaMpZg9Uw== X-Received: by 2002:adf:f241:: with SMTP id b1mr3982691wrp.444.1644335379970; Tue, 08 Feb 2022 07:49:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhNm9vJuoLQj6E0ZyBIuDTndNhn0u8L2PZ+Kv8OY39yFOjL4BSOslIL/CGYPoyPoGWx+anJQ== X-Received: by 2002:adf:f241:: with SMTP id b1mr3982659wrp.444.1644335379483; Tue, 08 Feb 2022 07:49:39 -0800 (PST) Received: from localhost (host86-134-151-224.range86-134.btcentralplus.com. [86.134.151.224]) by smtp.gmail.com with ESMTPSA id n4sm115547wmq.42.2022.02.08.07.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 07:49:39 -0800 (PST) Date: Tue, 8 Feb 2022 15:49:37 +0000 To: Jan Vrany Subject: Re: [PATCH] gdb: change "maint info jit" to print jit_code_entry::symfile_addr value Message-ID: <20220208154937.GF2706@redhat.com> References: <20220207113923.2366281-1-jan.vrany@labware.com> MIME-Version: 1.0 In-Reply-To: <20220207113923.2366281-1-jan.vrany@labware.com> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 15:46:07 up 3 days, 4:42, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Jan, Thanks for this patch. While reviewing this, I wondered about using ui_out's table mechanism to format the output, rather than just printing the addresses. Additionally, while reminding myself about how the jit stuff works, I thought, maybe we should keep the jit_code_entry address in the 'maint info jit' output - after all, given a jit_code_entry, we can, in theory, figure out the symfile address, but we can't (easily) go from a symfile address back to a jit_code_entry, right? Anyway, while I ended up with the patch below. What do you think about this instead? Thanks, Andrew --- commit 3982fbc710447f9323c75f297c464c102f921e1e Author: Jan Vrany via Gdb-patches Date: Mon Feb 7 11:39:22 2022 +0000 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. 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 = current_inferior (); bool printed_header = false; + 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) 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 = 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 = true; } - 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"); } } @@ -211,11 +237,13 @@ get_jiter_objfile_data (objfile *objf) at inferior address ENTRY. */ 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 == nullptr); - objfile->jited_data.reset (new jited_objfile_data (entry)); + objfile->jited_data.reset (new jited_objfile_data (entry, symfile_addr, + symfile_size)); } /* 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); - 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); delete obj; } @@ -773,7 +803,8 @@ JITed symbol file is not an object file, ignoring it.\n")); &sai, OBJF_SHARED | OBJF_NOT_FILENAME, NULL); - add_objfile_entry (objfile, entry_addr); + add_objfile_entry (objfile, entry_addr, code_entry->symfile_addr, + code_entry->symfile_size); } /* 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 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) {} /* 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; }; /* Re-establish the jit breakpoint(s). */ diff --git a/gdb/testsuite/gdb.base/jit-elf-fork.exp b/gdb/testsuite/gdb.base/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.*" # 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" # 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 } { # 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" # Delete our breakpoints. delete_breakpoints @@ -108,7 +116,11 @@ proc_with_prefix test_detach_on_fork_off_follow_fork_mode_parent { } { # 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" # Continue child past JIT unload, verify there are no more JIT-ed objfiles. gdb_continue_to_breakpoint "continue to before return - child" ".*break before return.*" @@ -116,7 +128,11 @@ proc_with_prefix test_detach_on_fork_off_follow_fork_mode_parent { } { # 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" # Continue parent past JIT unload, verify there are no more JIT-ed objfiles. 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_mode_child { } { # 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" # Continue parent past JIT unload, verify there are no more JIT-ed objfiles. 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_mode_child { } { # 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" # Continue child past JIT unload, verify there are no more JIT-ed objfiles. gdb_continue_to_breakpoint "continue to before return - child" ".*break before return.*"