From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5668 invoked by alias); 27 Aug 2012 17:41:20 -0000 Received: (qmail 5443 invoked by uid 22791); 27 Aug 2012 17:41:17 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_FD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 27 Aug 2012 17:40:57 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7RHesxe021994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 27 Aug 2012 13:40:54 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7RHepwC012502; Mon, 27 Aug 2012 13:40:52 -0400 Message-ID: <503BB123.50500@redhat.com> Date: Mon, 27 Aug 2012 17:41:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: Ulrich Weigand CC: Pedro Alves , Sergio Durigan Junior , GDB Patches , Tom Tromey , Jan Kratochvil Subject: Re: info registers output References: <201208012049.q71Kn9jQ011712@d06av02.portsmouth.uk.ibm.com> In-Reply-To: <201208012049.q71Kn9jQ011712@d06av02.portsmouth.uk.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00812.txt.bz2 On 08/01/2012 09:49 PM, Ulrich Weigand wrote: > Pedro Alves wrote: >> Ah. I wonder if that's been made on purpose. You get this on amd64: >> >> (gdb) info registers rip pc >> rip 0x390f407e68 0x390f407e68 >> pc: 0x390f407e68 >> >> GDB knows the type of "pc", and so should be able to print "pc" like "rip". >> >> Would that be a good idea? > > Would make sense to me. (In fact, there probably ought to be a single > routine to print a register, called by both code paths, to avoid having > the code diverge again in the future ...) Here's a patch that does that. If some arch wants to print user regs differently, we'll either have to add a new gdbarch, or make gdbarch_print_registers_info handle user regs. We now get, for amd64: (gdb) info registers pc rip sp rsp fp rbp pc 0x45762b 0x45762b rip 0x45762b 0x45762b sp 0x7fffffffdbe0 0x7fffffffdbe0 rsp 0x7fffffffdbe0 0x7fffffffdbe0 fp 0x7fffffffdc10 0x7fffffffdc10 rbp 0x7fffffffdc10 0x7fffffffdc10 Before we'd get: (gdb) info registers pc rip sp rsp fp rbp pc: 0x45762b rip 0x45762b 0x45762b sp: 0x7fffffffdbe0 rsp 0x7fffffffdbe0 0x7fffffffdbe0 fp: 0x7fffffffdc10 rbp 0x7fffffffdc10 0x7fffffffdc10 How does it look? Tested on AMD64 Fedora 17. 2012-08-27 Pedro Alves PR gdb/14428 * infcmd.c (default_print_one_register_info): New, factored out from default_print_registers_info. (default_print_registers_info): Use it. Mark value unavailable if necessary. (registers_info): Print user registers with default_print_one_register_info. --- gdb/infcmd.c | 167 +++++++++++++++++++++----------------- gdb/testsuite/gdb.base/pc-fp.exp | 2 2 files changed, 93 insertions(+), 76 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 9d43193..2067948 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2015,6 +2015,84 @@ path_command (char *dirname, int from_tty) } +/* Print out the register NAME, of GDBARCH, with value VAL, to FILE, + in the default fashion. */ + +static void +default_print_one_register_info (struct gdbarch *gdbarch, + struct ui_file *file, + const char *name, + struct value *val) +{ + struct type *regtype = value_type (val); + + fputs_filtered (name, file); + print_spaces_filtered (15 - strlen (name), file); + + if (!value_entirely_available (val)) + { + fprintf_filtered (file, "*value not available*\n"); + return; + } + + /* If virtual format is floating, print it that way, and in raw + hex. */ + if (TYPE_CODE (regtype) == TYPE_CODE_FLT + || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT) + { + int j; + struct value_print_options opts; + const gdb_byte *valaddr = value_contents_for_printing (val); + + get_user_print_options (&opts); + opts.deref_ref = 1; + + val_print (regtype, + value_contents_for_printing (val), + value_embedded_offset (val), 0, + file, 0, val, &opts, current_language); + + fprintf_filtered (file, "\t(raw 0x"); + for (j = 0; j < TYPE_LENGTH (regtype); j++) + { + int idx; + + if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) + idx = j; + else + idx = TYPE_LENGTH (regtype) - 1 - j; + fprintf_filtered (file, "%02x", (unsigned char) valaddr[idx]); + } + fprintf_filtered (file, ")"); + } + else + { + struct value_print_options opts; + + /* Print the register in hex. */ + get_formatted_print_options (&opts, 'x'); + opts.deref_ref = 1; + val_print (regtype, + value_contents_for_printing (val), + value_embedded_offset (val), 0, + file, 0, val, &opts, current_language); + /* If not a vector register, print it also according to its + natural format. */ + if (TYPE_VECTOR (regtype) == 0) + { + get_user_print_options (&opts); + opts.deref_ref = 1; + fprintf_filtered (file, "\t"); + val_print (regtype, + value_contents_for_printing (val), + value_embedded_offset (val), 0, + file, 0, val, &opts, current_language); + } + } + + fprintf_filtered (file, "\n"); +} + /* Print out the machine register regnum. If regnum is -1, print all registers (print_all == 1) or all non-float and non-vector registers (print_all == 0). @@ -2068,76 +2146,16 @@ default_print_registers_info (struct gdbarch *gdbarch, || *(gdbarch_register_name (gdbarch, i)) == '\0') continue; - fputs_filtered (gdbarch_register_name (gdbarch, i), file); - print_spaces_filtered (15 - strlen (gdbarch_register_name - (gdbarch, i)), file); - regtype = register_type (gdbarch, i); val = allocate_value (regtype); /* Get the data in raw format. */ if (! frame_register_read (frame, i, value_contents_raw (val))) - { - fprintf_filtered (file, "*value not available*\n"); - continue; - } - - /* If virtual format is floating, print it that way, and in raw - hex. */ - if (TYPE_CODE (regtype) == TYPE_CODE_FLT - || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT) - { - int j; - struct value_print_options opts; - const gdb_byte *valaddr = value_contents_for_printing (val); - - get_user_print_options (&opts); - opts.deref_ref = 1; - - val_print (regtype, - value_contents_for_printing (val), - value_embedded_offset (val), 0, - file, 0, val, &opts, current_language); - - fprintf_filtered (file, "\t(raw 0x"); - for (j = 0; j < register_size (gdbarch, i); j++) - { - int idx; - - if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) - idx = j; - else - idx = register_size (gdbarch, i) - 1 - j; - fprintf_filtered (file, "%02x", (unsigned char) valaddr[idx]); - } - fprintf_filtered (file, ")"); - } - else - { - struct value_print_options opts; - - /* Print the register in hex. */ - get_formatted_print_options (&opts, 'x'); - opts.deref_ref = 1; - val_print (regtype, - value_contents_for_printing (val), - value_embedded_offset (val), 0, - file, 0, val, &opts, current_language); - /* If not a vector register, print it also according to its - natural format. */ - if (TYPE_VECTOR (regtype) == 0) - { - get_user_print_options (&opts); - opts.deref_ref = 1; - fprintf_filtered (file, "\t"); - val_print (regtype, - value_contents_for_printing (val), - value_embedded_offset (val), 0, - file, 0, val, &opts, current_language); - } - } + mark_value_bytes_unavailable (val, 0, TYPE_LENGTH (value_type (val))); - fprintf_filtered (file, "\n"); + default_print_one_register_info (gdbarch, file, + gdbarch_register_name (gdbarch, i), + val); } } @@ -2198,17 +2216,16 @@ registers_info (char *addr_exp, int fpregs) if (regnum >= gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch)) { - struct value_print_options opts; - struct value *val = value_of_user_reg (regnum, frame); - - printf_filtered ("%.*s: ", (int) (end - start), start); - get_formatted_print_options (&opts, 'x'); - val_print_scalar_formatted (check_typedef (value_type (val)), - value_contents_for_printing (val), - value_embedded_offset (val), - val, - &opts, 0, gdb_stdout); - printf_filtered ("\n"); + struct value *regval = value_of_user_reg (regnum, frame); + const char *regname = user_reg_map_regnum_to_name (gdbarch, + regnum); + + /* Print in the same fashion + gdbarch_print_registers_info's default + implementation prints. */ + default_print_one_register_info (gdbarch, gdb_stdout, + regname, + regval); } else gdbarch_print_registers_info (gdbarch, gdb_stdout, diff --git a/gdb/testsuite/gdb.base/pc-fp.exp b/gdb/testsuite/gdb.base/pc-fp.exp index beb5087..685e2d9 100644 --- a/gdb/testsuite/gdb.base/pc-fp.exp +++ b/gdb/testsuite/gdb.base/pc-fp.exp @@ -66,4 +66,4 @@ gdb_test "info register \$fp" "${valueof_fp}.*" # Regression test for # http://sourceware.org/bugzilla/show_bug.cgi?id=12659 gdb_test "info register pc fp" \ - "pc(:)?( |\t)+${valueof_pc}(( |\t)+${valueof_pc} <.*>)?\[\r\n\]+fp(:)?( |\t)+${valueof_fp}(( |\t)+${valueof_fp})?\[\r\n\]+" + "pc +${valueof_pc}\t${valueof_pc} <.*>\[\r\n\]+fp +${valueof_fp}\t${valueof_fp}\[\r\n\]+"