From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QXSqBZHc9mdaai0AWB0awg (envelope-from ) for ; Wed, 09 Apr 2025 16:46:09 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Y6Sxb2bK; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id F3F1D1E0C3; Wed, 9 Apr 2025 16:46:08 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5FBAA1E0C0 for ; Wed, 9 Apr 2025 16:46:04 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED409384188F for ; Wed, 9 Apr 2025 20:46:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED409384188F Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Y6Sxb2bK Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 0F98F386F00F for ; Wed, 9 Apr 2025 20:44:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F98F386F00F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0F98F386F00F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1744231493; cv=none; b=OkdYHQlC9pHL6TkAgqE7aQWEMUJJ7WgzNtUY1friOH0njM/iI+1ofNINUs66jsozzDLAM7RM501uBmbpudsqsA9e25Qyns2PSwERLt38m3wbkgWjom6lE3EaSi19rFwglu7vQns8eiMTrGSf+qUS8oRrFjLhIM5X7PcHg7FQxH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1744231493; c=relaxed/simple; bh=6GRERqqH3bsOqgaDX+e1rUg8xyLw9JRck/QYopfxSMQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=w2SHTkJGwOICed2V3tSZ16UY8XTg3dJB/KaR49xPBhGoYuU6RMF80NmUXMqXUoJZmLS4A96CCi5D3Idqfbuc5WF5Fnu2WcqcQGNmigAm1Q6z3vtQdL+MP2994sWfpLTXNyxU+0ws+BJGQieSazyB/jv1cXkCz365X1HJ+ms44IE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F98F386F00F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744231492; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dw3HJrG0oNn/4xMZA1lJ82r9vWQdwvFDjAJC1Z/KIKU=; b=Y6Sxb2bKGicPvDtE0KhPGx01+/UNipAln8yIfKh9/jVGROgi9sfsm0lnsREJlcTDTRVwQ1 jAUdUedp0d6MNtb7wbmzEIGptAs43yRaGdHJrg0K0ONr3Ikb2eeK3wT52SydLm+yg/UfnM 2MVKqeE1z9BBOsnwtFMEXJLWWZLj3wU= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-374-YyMPvXSFOJivlj6iVg1A-g-1; Wed, 09 Apr 2025 16:44:51 -0400 X-MC-Unique: YyMPvXSFOJivlj6iVg1A-g-1 X-Mimecast-MFC-AGG-ID: YyMPvXSFOJivlj6iVg1A-g_1744231490 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 91A5E1955DCF for ; Wed, 9 Apr 2025 20:44:50 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.96.134.159]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 651111955BC0; Wed, 9 Apr 2025 20:44:49 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH v2 2/3] gdb: factor out printing a table of solibs for info sharedlibrary Date: Wed, 9 Apr 2025 17:44:26 -0300 Message-ID: <20250409204427.1680979-3-guinevere@redhat.com> In-Reply-To: <20250409204427.1680979-1-guinevere@redhat.com> References: <20250409204427.1680979-1-guinevere@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 71T1HHgvPi_OkngW9vZbPRHSGheOt2wePAkIaVJVHF4_1744231490 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org The next patch will add a new command that will print libraries in a manner very similar to the existing "info sharedlibrary" command. To make that patch simpler to review, this commit does the bulk of refactoring work, since it ends up being a non-trivial diff to review. No functional changes are expected after this commit. --- gdb/solib.c | 137 ++++++++++++++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 63 deletions(-) diff --git a/gdb/solib.c b/gdb/solib.c index 1ba98137f5e..d641a24dc86 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1010,84 +1010,61 @@ solib_add (const char *pattern, int from_tty, int readsyms) } } -/* Implement the "info sharedlibrary" command. Walk through the - shared library list and print information about each attached - library matching PATTERN. If PATTERN is elided, print them - all. */ +/* Helper function for "info sharedlibrary" and "info namespace". + This receives a list of solibs to be printed, and prints a table + with all the relevant data. If PRINT_NAMESPACE is true, figure out + the solib_ops of the current gdbarch, to calculate the namespace + that contains an solib. + Returns true if one or more solibs are missing debug information, + false otherwise. */ static void -info_sharedlibrary_command (const char *pattern, int from_tty) +print_solib_list_table (std::vector solib_list, + bool print_namespace) { - bool so_missing_debug_info = false; - int addr_width; - int nr_libs; gdbarch *gdbarch = current_inferior ()->arch (); - struct ui_out *uiout = current_uiout; - - if (pattern) - { - char *re_err = re_comp (pattern); - - if (re_err) - error (_ ("Invalid regexp: %s"), re_err); - } - /* "0x", a little whitespace, and two hex digits per byte of pointers. */ - addr_width = 4 + (gdbarch_ptr_bit (gdbarch) / 4); - - update_solib_list (from_tty); - - /* ui_out_emit_table table_emitter needs to know the number of rows, - so we need to make two passes over the libs. */ + int addr_width = 4 + (gdbarch_ptr_bit (gdbarch) / 4); + const solib_ops *ops = gdbarch_so_ops (gdbarch); + struct ui_out *uiout = current_uiout; + bool so_missing_debug_info = false; - nr_libs = 0; - for (const solib &so : current_program_space->solibs ()) - { - if (!so.so_name.empty ()) - { - if (pattern && !re_exec (so.so_name.c_str ())) - continue; - ++nr_libs; - } - } + /* There are 3 conditions for this command to print solib namespaces, + first PRINT_NAMESPACE has to be true, second the solib_ops has to + support multiple namespaces, and third there must be more than one + active namespace. Fold all these into the PRINT_NAMESPACE condition. */ + print_namespace = print_namespace && ops->num_active_namespaces != nullptr + && ops->num_active_namespaces () > 1; - /* How many columns the table should have. If the inferior has - more than one namespace active, we need a column to show that. */ int num_cols = 4; - const solib_ops *ops = gdbarch_so_ops (gdbarch); - if (ops->num_active_namespaces != nullptr - && ops->num_active_namespaces () > 1) + if (print_namespace) num_cols++; { - ui_out_emit_table table_emitter (uiout, num_cols, nr_libs, + ui_out_emit_table table_emitter (uiout, num_cols, solib_list.size (), "SharedLibraryTable"); /* The "- 1" is because ui_out adds one space between columns. */ uiout->table_header (addr_width - 1, ui_left, "from", "From"); uiout->table_header (addr_width - 1, ui_left, "to", "To"); - if (ops->num_active_namespaces != nullptr - && ops->num_active_namespaces () > 1) + if (print_namespace) uiout->table_header (5, ui_left, "namespace", "NS"); uiout->table_header (12 - 1, ui_left, "syms-read", "Syms Read"); uiout->table_header (0, ui_noalign, "name", "Shared Object Library"); uiout->table_body (); - for (const solib &so : current_program_space->solibs ()) + for (const solib *so : solib_list) { - if (so.so_name.empty ()) - continue; - - if (pattern && !re_exec (so.so_name.c_str ())) + if (so->so_name.empty ()) continue; ui_out_emit_tuple tuple_emitter (uiout, "lib"); - if (so.addr_high != 0) + if (so->addr_high != 0) { - uiout->field_core_addr ("from", gdbarch, so.addr_low); - uiout->field_core_addr ("to", gdbarch, so.addr_high); + uiout->field_core_addr ("from", gdbarch, so->addr_low); + uiout->field_core_addr ("to", gdbarch, so->addr_high); } else { @@ -1095,12 +1072,11 @@ info_sharedlibrary_command (const char *pattern, int from_tty) uiout->field_skip ("to"); } - if (ops->num_active_namespaces != nullptr - && ops->num_active_namespaces ()> 1) + if (print_namespace) { try { - uiout->field_fmt ("namespace", "[[%d]]", ops->find_solib_ns (so)); + uiout->field_fmt ("namespace", "[[%d]]", ops->find_solib_ns (*so)); } catch (const gdb_exception_error &er) { @@ -1109,33 +1085,68 @@ info_sharedlibrary_command (const char *pattern, int from_tty) } if (!top_level_interpreter ()->interp_ui_out ()->is_mi_like_p () - && so.symbols_loaded && !objfile_has_symbols (so.objfile)) + && so->symbols_loaded && !objfile_has_symbols (so->objfile)) { so_missing_debug_info = true; uiout->field_string ("syms-read", "Yes (*)"); } else - uiout->field_string ("syms-read", so.symbols_loaded ? "Yes" : "No"); + uiout->field_string ("syms-read", so->symbols_loaded ? "Yes" : "No"); - uiout->field_string ("name", so.so_name, file_name_style.style ()); + uiout->field_string ("name", so->so_name, file_name_style.style ()); uiout->text ("\n"); } } - if (nr_libs == 0) + if (so_missing_debug_info) + uiout->message (_ ("(*): Shared library is missing " + "debugging information.\n")); +} + +/* Implement the "info sharedlibrary" command. Walk through the + shared library list and print information about each attached + library matching PATTERN. If PATTERN is elided, print them + all. */ + +static void +info_sharedlibrary_command (const char *pattern, int from_tty) +{ + struct ui_out *uiout = current_uiout; + + if (pattern) + { + char *re_err = re_comp (pattern); + + if (re_err) + error (_ ("Invalid regexp: %s"), re_err); + } + + update_solib_list (from_tty); + + /* ui_out_emit_table table_emitter needs to know the number of rows, + so we need to make two passes over the libs. */ + + std::vector print_libs; + for (const solib &so : current_program_space->solibs ()) + { + if (!so.so_name.empty ()) + { + if (pattern && !re_exec (so.so_name.c_str ())) + continue; + print_libs.push_back (&so); + } + } + + print_solib_list_table (print_libs, true); + + if (print_libs.size () == 0) { if (pattern) uiout->message (_ ("No shared libraries matched.\n")); else uiout->message (_ ("No shared libraries loaded at this time.\n")); } - else - { - if (so_missing_debug_info) - uiout->message (_ ("(*): Shared library is missing " - "debugging information.\n")); - } } /* See solib.h. */ -- 2.49.0