From patchwork Sat Feb 3 11:42:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Kabatsayev X-Patchwork-Id: 25785 Received: (qmail 19360 invoked by alias); 3 Feb 2018 11:42:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 19350 invoked by uid 89); 3 Feb 2018 11:42:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-spam-relays-external:209.85.215.65, H*RU:209.85.215.65 X-HELO: mail-lf0-f65.google.com Received: from mail-lf0-f65.google.com (HELO mail-lf0-f65.google.com) (209.85.215.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 03 Feb 2018 11:42:44 +0000 Received: by mail-lf0-f65.google.com with SMTP id f136so35274579lff.8 for ; Sat, 03 Feb 2018 03:42:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UF/OPDr0Ayd85ReMBcftGxXSc0e3xkw3JX4hmSAwQ8o=; b=Q0WtRpAKOV55WNrnJPERjoc91VeV5albnng9tNTI20n5UK3rd7cyHiocUWqhJnZqzQ AJYWjyxpS1cJiZx6z2F5H4mlM3i9j5Jir4BU9jO3hQbdY7FmaFHyvml6MH5sJ5enCfNc EYdISuraiSgmiYUM0BbCj4I5Gi4zJP+GX7joqLh9w1nkQUkQHxXo39kJkULHKZ0cKGSK ky/zqJlX4/3v4ojKoT9RKay9pdhirPhBekR7FjzhcETJRPWBkRpNEBvCd4VaiDkXuvNQ ZI7eM83ppmC2UnhyyOaQWXo/H08JjUxXidZJS5OREFumBliWXzPGql1Bwc5UyxvvzlbZ 6b4A== X-Gm-Message-State: AKwxytc48NJjLeiMmaNApDyT3CvogYJ9KXl8OITsf/0/nH7Cejijzu/6 /9PTryGkZsX//qKZ2Bo2CyzRQWo3 X-Google-Smtp-Source: AH8x225EztSDZBCKb/CtffTRe2n4mCpax+1Lf6w1a5kmKtYntW3LdbsbvnoQGg01V9YI+qOSgYWftg== X-Received: by 10.46.57.10 with SMTP id g10mr3356975lja.10.1517658161744; Sat, 03 Feb 2018 03:42:41 -0800 (PST) Received: from localhost.localdomain ([91.215.122.25]) by smtp.gmail.com with ESMTPSA id 95sm865018lfv.2.2018.02.03.03.42.40 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 03 Feb 2018 03:42:40 -0800 (PST) From: Ruslan Kabatsayev To: gdb-patches@sourceware.org Cc: Ruslan Kabatsayev Subject: [PATCH v4] Align natural-format register values to the same column Date: Sat, 3 Feb 2018 14:42:23 +0300 Message-Id: <1517658143-946-1-git-send-email-b7.10110111@gmail.com> X-IsSubscribed: yes Currently, commands such as "info reg", "info all-reg", as well as register window in the TUI print badly aligned columns, like here: eax 0x1 1 ecx 0xffffd3e0 -11296 edx 0xffffd404 -11260 ebx 0xf7fa5ff4 -134586380 esp 0xffffd390 0xffffd390 ebp 0xffffd3c8 0xffffd3c8 esi 0x0 0 edi 0x0 0 eip 0x8048b60 0x8048b60 eflags 0x286 [ PF SF IF ] cs 0x23 35 ss 0x2b 43 ds 0x2b 43 es 0x2b 43 fs 0x0 0 gs 0x63 99 After this patch, these commands print the third column values consistently aligned one under another, provided the second column is not too long. Originally, the third column was (attempted to be) aligned using a simple tab character. This patch changes the alignment to spaces only. The tests checking the output and expecting the single tab have been fixed in a previous patch, so this change doesn't break any. gdb/ChangeLog: * infcmd.c (default_print_one_register_info): Align natural-format column values consistently one under another. (pad_to_column): New function. --- gdb/infcmd.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index ccf08bd..3879df3 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2283,6 +2283,16 @@ path_command (const char *dirname, int from_tty) } +static void +pad_to_column (string_file &stream, int col) +{ + /* At least one space must be printed to separate columns. */ + stream.putc (' '); + const int size = stream.size (); + if (size < col) + stream.puts (n_spaces (col - size)); +} + /* Print out the register NAME with value VAL, to FILE, in the default fashion. */ @@ -2293,9 +2303,17 @@ default_print_one_register_info (struct ui_file *file, { struct type *regtype = value_type (val); int print_raw_format; + string_file format_stream; + enum tab_stops + { + value_column_1 = 15, + /* Give enough room for "0x", 16 hex digits and two spaces in + preceding column. */ + value_column_2 = value_column_1 + 2 + 16 + 2, + }; - fputs_filtered (name, file); - print_spaces_filtered (15 - strlen (name), file); + format_stream.puts (name); + pad_to_column (format_stream, value_column_1); print_raw_format = (value_entirely_available (val) && !value_optimized_out (val)); @@ -2314,14 +2332,15 @@ default_print_one_register_info (struct ui_file *file, val_print (regtype, value_embedded_offset (val), 0, - file, 0, val, &opts, current_language); + &format_stream, 0, val, &opts, current_language); if (print_raw_format) { - fprintf_filtered (file, "\t(raw "); - print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order, - true); - fprintf_filtered (file, ")"); + pad_to_column (format_stream, value_column_2); + format_stream.puts ("(raw "); + print_hex_chars (&format_stream, valaddr, TYPE_LENGTH (regtype), + byte_order, true); + format_stream.putc (')'); } } else @@ -2333,20 +2352,21 @@ default_print_one_register_info (struct ui_file *file, opts.deref_ref = 1; val_print (regtype, value_embedded_offset (val), 0, - file, 0, val, &opts, current_language); + &format_stream, 0, val, &opts, current_language); /* If not a vector register, print it also according to its natural format. */ if (print_raw_format && TYPE_VECTOR (regtype) == 0) { + pad_to_column (format_stream, value_column_2); get_user_print_options (&opts); opts.deref_ref = 1; - fprintf_filtered (file, "\t"); val_print (regtype, value_embedded_offset (val), 0, - file, 0, val, &opts, current_language); + &format_stream, 0, val, &opts, current_language); } } + fputs_filtered (format_stream.c_str (), file); fprintf_filtered (file, "\n"); }