From patchwork Sun Oct 6 19:02:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 98442 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD983386101B for ; Sun, 6 Oct 2024 19:02:57 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta36.uswest2.a.cloudfilter.net (omta36.uswest2.a.cloudfilter.net [35.89.44.35]) by sourceware.org (Postfix) with ESMTPS id BDD963858C41 for ; Sun, 6 Oct 2024 19:02:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDD963858C41 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BDD963858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728241348; cv=none; b=Kiy0YCuEfREdKetLxJgExKDlY+jfhf0NBtSmcyoA4Pc9AH1xEm+eUB6rTrQbHPkdyYpRQrI4FDG82rIzdtBnReZUcyB1fShE1bwcLLO17eqoOC+6J0KxIJTltu2UXmQnuPY9aHakcSgc/AWvU6UqpcVfWGGndLhStK8io6cwASU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728241348; c=relaxed/simple; bh=+W8yhAWQKpXom4/ue+0PkHJUJa5999OqsOK12XxfyBA=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=FoOMZu2hG92Stc2rpraESRK18N0O7AbKGcmiATlqrgdX55Jhors31OZqS6L339Ear/ilgjEpMy1rY6bMLZsyavnDgFp+ui8ABovjWsCYYR0PyOt/khgoPV3z56F/X1kTLTaoe0/YnTkqpN7TOlrMblFHus1YvfTu63+7qwtC7xY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5007a.ext.cloudfilter.net ([10.0.29.141]) by cmsmtp with ESMTPS id xUL0sJHkKqvuoxWWNsKDzy; Sun, 06 Oct 2024 19:02:23 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id xWWMsBCowky5UxWWNsbbCT; Sun, 06 Oct 2024 19:02:23 +0000 X-Authority-Analysis: v=2.4 cv=Cum5cG4D c=1 sm=1 tr=0 ts=6702debf a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=DAUX931o1VcA:10 a=ItBw4LHWJt0A:10 a=EafSMyPjRCuOCwPxAtAA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=XOXf5fZP09tLuQ5/AdYv7Yl1gOjGYYuuOXaEL7cX5As=; b=XfyIHFbajhx9x7uBEhYWnb7uXP 3s51m4DRmaxmg8CeS68CBPulLRHvSXV/NzlzlZY2Ayq4ChzmDO3YK/i3qDl7nDWiCbOhcoaSnR+bZ 6FIvCn72nOpbG2691Pw4WwRxU; Received: from 97-122-122-36.hlrn.qwest.net ([97.122.122.36]:56376 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1sxWWM-004OG1-19 for gdb-patches@sourceware.org; Sun, 06 Oct 2024 13:02:22 -0600 From: Tom Tromey Date: Sun, 06 Oct 2024 13:02:19 -0600 Subject: [PATCH 1/2] Use ui-out tables for info proc mappings MIME-Version: 1.0 Message-Id: <20241006-more-use-of-ui-table-v1-1-baf53ee69161@tromey.com> References: <20241006-more-use-of-ui-table-v1-0-baf53ee69161@tromey.com> In-Reply-To: <20241006-more-use-of-ui-table-v1-0-baf53ee69161@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.14.2 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.122.36 X-Source-L: No X-Exim-ID: 1sxWWM-004OG1-19 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-122-36.hlrn.qwest.net (prentzel.local) [97.122.122.36]:56376 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfMfYYnkVLokMofc4bTUDtf4+wI1EeyUkyloOtvxkZU5q0BFkXhjecRSQbr6HQoqy4ZrcJq1Da63RiNu3DNwNOM3t2GbQ/EARarJM/vGa/WkS/usYkMnU QrzG9rj2McpIEktR1u45AkbLtQqtccrYvzN9KvnApjo21dK7s9YuXCOdeO70TXMIs8LqVs2SWTQu6YN2bi5VQUrGP3IitOMUhCI= X-Spam-Status: No, score=-3019.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_LOTSOFHASH, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org This changes a few implementations of "info proc mappings" to use ui-out tables rather than printf. Note that NetBSD and FreeBSD also use printfs here, but since I can't test these, I didn't update them. --- gdb/corelow.c | 55 ++++------ gdb/linux-tdep.c | 122 +++++++++------------ .../gdb.debuginfod/corefile-mapped-file.exp | 2 +- 3 files changed, 76 insertions(+), 103 deletions(-) diff --git a/gdb/corelow.c b/gdb/corelow.c index ab2fa746de8e5f51d76bf48fa739215660b3901c..5820ffed3322cc44d5ebc1417db8c78bdac9b015 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -1698,24 +1698,19 @@ get_current_core_target () void core_target::info_proc_mappings (struct gdbarch *gdbarch) { - if (!m_core_file_mappings.empty ()) - { - gdb_printf (_("Mapped address spaces:\n\n")); - if (gdbarch_addr_bit (gdbarch) == 32) - { - gdb_printf ("\t%10s %10s %10s %10s %s\n", - "Start Addr", - " End Addr", - " Size", " Offset", "objfile"); - } - else - { - gdb_printf (" %18s %18s %10s %10s %s\n", - "Start Addr", - " End Addr", - " Size", " Offset", "objfile"); - } - } + if (m_core_file_mappings.empty ()) + return; + + gdb_printf (_("Mapped address spaces:\n\n")); + ui_out_emit_table emitter (current_uiout, 5, -1, "ProcMappings"); + + int width = gdbarch_addr_bit (gdbarch) == 32 ? 10 : 18; + current_uiout->table_header (width, ui_left, "start", "Start Addr"); + current_uiout->table_header (width, ui_left, "end", "End Addr"); + current_uiout->table_header (width, ui_left, "size", "Size"); + current_uiout->table_header (width, ui_left, "offset", "Offset"); + current_uiout->table_header (0, ui_left, "objfile", "File"); + current_uiout->table_body (); for (const target_section &tsp : m_core_file_mappings) { @@ -1724,20 +1719,16 @@ core_target::info_proc_mappings (struct gdbarch *gdbarch) ULONGEST file_ofs = tsp.the_bfd_section->filepos; const char *filename = bfd_get_filename (tsp.the_bfd_section->owner); - if (gdbarch_addr_bit (gdbarch) == 32) - gdb_printf ("\t%10s %10s %10s %10s %s\n", - paddress (gdbarch, start), - paddress (gdbarch, end), - hex_string (end - start), - hex_string (file_ofs), - filename); - else - gdb_printf (" %18s %18s %10s %10s %s\n", - paddress (gdbarch, start), - paddress (gdbarch, end), - hex_string (end - start), - hex_string (file_ofs), - filename); + ui_out_emit_tuple tuple_emitter (current_uiout, nullptr); + current_uiout->field_core_addr ("start", gdbarch, start); + current_uiout->field_core_addr ("end", gdbarch, end); + /* These next two aren't really addresses and so shouldn't be + styled as such. */ + current_uiout->field_string ("size", paddress (gdbarch, end - start)); + current_uiout->field_string ("offset", paddress (gdbarch, file_ofs)); + current_uiout->field_string ("objfile", filename, + file_name_style.style ()); + current_uiout->text ("\n"); } } diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 284996106a9734b3d08bcb580ce75a5abbaeec33..65ec221ef48d940427a63330602102d6dd607aa5 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -43,6 +43,7 @@ #include "gcore-elf.h" #include "solib-svr4.h" #include "memtag.h" +#include "cli/cli-style.h" #include #include @@ -457,7 +458,7 @@ struct mapping { ULONGEST addr; ULONGEST endaddr; - std::string_view permissions; + std::string permissions; ULONGEST offset; std::string_view device; ULONGEST inode; @@ -484,7 +485,8 @@ read_mapping (const char *line) const char *permissions_start = p; while (*p && !isspace (*p)) p++; - mapping.permissions = {permissions_start, (size_t) (p - permissions_start)}; + mapping.permissions = std::string (permissions_start, + (size_t) (p - permissions_start)); mapping.offset = strtoulst (p, &p, 16); @@ -897,51 +899,39 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, = target_fileio_read_stralloc (NULL, filename); if (map != NULL) { - char *line; - gdb_printf (_("Mapped address spaces:\n\n")); - if (gdbarch_addr_bit (gdbarch) == 32) - { - gdb_printf ("\t%10s %10s %10s %10s %s %s\n", - "Start Addr", " End Addr", " Size", - " Offset", "Perms ", "objfile"); - } - else - { - gdb_printf (" %18s %18s %10s %10s %s %s\n", - "Start Addr", " End Addr", " Size", - " Offset", "Perms ", "objfile"); - } + ui_out_emit_table emitter (current_uiout, 6, -1, "ProcMappings"); + + int width = gdbarch_addr_bit (gdbarch) == 32 ? 10 : 18; + current_uiout->table_header (width, ui_left, "start", "Start Addr"); + current_uiout->table_header (width, ui_left, "end", "End Addr"); + current_uiout->table_header (width, ui_left, "size", "Size"); + current_uiout->table_header (width, ui_left, "offset", "Offset"); + current_uiout->table_header (5, ui_left, "perms", "Perms"); + current_uiout->table_header (0, ui_left, "objfile", "File"); + current_uiout->table_body (); char *saveptr; - for (line = strtok_r (map.get (), "\n", &saveptr); - line; - line = strtok_r (NULL, "\n", &saveptr)) + for (const char *line = strtok_r (map.get (), "\n", &saveptr); + line != nullptr; + line = strtok_r (nullptr, "\n", &saveptr)) { struct mapping m = read_mapping (line); - if (gdbarch_addr_bit (gdbarch) == 32) - { - gdb_printf ("\t%10s %10s %10s %10s %-5.*s %s\n", - paddress (gdbarch, m.addr), - paddress (gdbarch, m.endaddr), - hex_string (m.endaddr - m.addr), - hex_string (m.offset), - (int) m.permissions.size (), - m.permissions.data (), - m.filename); - } - else - { - gdb_printf (" %18s %18s %10s %10s %-5.*s %s\n", - paddress (gdbarch, m.addr), - paddress (gdbarch, m.endaddr), - hex_string (m.endaddr - m.addr), - hex_string (m.offset), - (int) m.permissions.size (), - m.permissions.data (), - m.filename); - } + ui_out_emit_tuple tuple_emitter (current_uiout, nullptr); + current_uiout->field_core_addr ("start", gdbarch, m.addr); + current_uiout->field_core_addr ("end", gdbarch, m.endaddr); + /* These next two aren't really addresses and so + shouldn't be styled as such. */ + current_uiout->field_string ("size", + paddress (gdbarch, + m.endaddr - m.addr)); + current_uiout->field_string ("offset", + paddress (gdbarch, m.offset)); + current_uiout->field_string ("perms", m.permissions); + current_uiout->field_string ("objfile", m.filename, + file_name_style.style ()); + current_uiout->text ("\n"); } } else @@ -1242,42 +1232,34 @@ linux_read_core_file_mappings static void linux_core_info_proc_mappings (struct gdbarch *gdbarch, const char *args) { + std::optional emitter; + linux_read_core_file_mappings (gdbarch, current_program_space->core_bfd (), - [=] (ULONGEST count) + [&] (ULONGEST count) { gdb_printf (_("Mapped address spaces:\n\n")); - if (gdbarch_addr_bit (gdbarch) == 32) - { - gdb_printf ("\t%10s %10s %10s %10s %s\n", - "Start Addr", - " End Addr", - " Size", " Offset", "objfile"); - } - else - { - gdb_printf (" %18s %18s %10s %10s %s\n", - "Start Addr", - " End Addr", - " Size", " Offset", "objfile"); - } + emitter.emplace (current_uiout, 5, -1, "ProcMappings"); + int width = gdbarch_addr_bit (gdbarch) == 32 ? 10 : 18; + current_uiout->table_header (width, ui_left, "start", "Start Addr"); + current_uiout->table_header (width, ui_left, "end", "End Addr"); + current_uiout->table_header (width, ui_left, "size", "Size"); + current_uiout->table_header (width, ui_left, "offset", "Offset"); + current_uiout->table_header (0, ui_left, "objfile", "File"); + current_uiout->table_body (); }, [=] (int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, const char *filename, const bfd_build_id *build_id) { - if (gdbarch_addr_bit (gdbarch) == 32) - gdb_printf ("\t%10s %10s %10s %10s %s\n", - paddress (gdbarch, start), - paddress (gdbarch, end), - hex_string (end - start), - hex_string (file_ofs), - filename); - else - gdb_printf (" %18s %18s %10s %10s %s\n", - paddress (gdbarch, start), - paddress (gdbarch, end), - hex_string (end - start), - hex_string (file_ofs), - filename); + ui_out_emit_tuple tuple_emitter (current_uiout, nullptr); + current_uiout->field_core_addr ("start", gdbarch, start); + current_uiout->field_core_addr ("end", gdbarch, end); + /* These next two aren't really addresses and so shouldn't be + styled as such. */ + current_uiout->field_string ("size", paddress (gdbarch, end - start)); + current_uiout->field_string ("offset", paddress (gdbarch, file_ofs)); + current_uiout->field_string ("objfile", filename, + file_name_style.style ()); + current_uiout->text ("\n"); }); } diff --git a/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp b/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp index b5dee228ca0091ac2b3f21b8fcdf5dc22c71957e..cf96b41ac9a1ed093de7611193b4a454e1bbb839 100644 --- a/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp +++ b/gdb/testsuite/gdb.debuginfod/corefile-mapped-file.exp @@ -93,7 +93,7 @@ set ptr_address [get_hexadecimal_valueof "&library_ptr" "unknown"] set ptr_offset "unknown" gdb_test_multiple "info proc mappings" "" { - -re "^\\s+($hex)\\s+($hex)\\s+$hex\\s+($hex)\[^\r\n\]+$library_filename\r\n" { + -re "^($hex)\\s+($hex)\\s+$hex\\s+($hex)\[^\r\n\]+$library_filename\\s*\r\n" { set low_addr $expect_out(1,string) set high_addr $expect_out(2,string) set file_offset $expect_out(3,string)