From 30a254669b16b86166fed1f9a4c4f9cc55a07fdc Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 22 May 2017 03:55:58 -0600 Subject: [PATCH] Don't always zero pad in print_*_chars This changes print_octal_chars and print_decimal_chars to never zero pad, and changes print_binary_chars and print_hex_chars to only optionally zero-pad, based on a flag. ChangeLog 2017-06-12 Tom Tromey PR exp/16225: * valprint.h (print_binary_chars, print_hex_chars): Update. * valprint.c (val_print_type_code_int): Update. (print_binary_chars): Add "zero_pad" argument. (emit_octal_digit): New function. (print_octal_chars): Don't zero-pad. (print_decimal_chars): Likewise. (print_hex_chars): Add "zero_pad" argument. * sh64-tdep.c (sh64_do_fp_register): Update. * regcache.c (regcache::dump): Update. * printcmd.c (print_scalar_formatted): Update. * infcmd.c (default_print_one_register_info): Update. 2017-06-12 Tom Tromey PR exp/16225: * gdb.reverse/i386-sse-reverse.exp: Update tests. * gdb.arch/vsx-regs.exp: Update tests. * gdb.arch/s390-vregs.exp (hex128): New proc. Update test. * gdb.arch/altivec-regs.exp: Update tests. --- gdb/ChangeLog | 15 ++ gdb/infcmd.c | 3 +- gdb/printcmd.c | 14 +- gdb/regcache.c | 4 +- gdb/sh64-tdep.c | 2 +- gdb/testsuite/ChangeLog | 9 ++ gdb/testsuite/gdb.arch/altivec-regs.exp | 8 +- gdb/testsuite/gdb.arch/s390-vregs.exp | 17 ++- gdb/testsuite/gdb.arch/vsx-regs.exp | 8 +- .../gdb.reverse/i386-sse-reverse.exp | 94 ++++++------ gdb/valprint.c | 137 ++++++++++++------ gdb/valprint.h | 4 +- 12 files changed, 197 insertions(+), 118 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0298a159b3c..16b5a3a8c39 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +2017-06-12 Tom Tromey + + PR exp/16225: + * valprint.h (print_binary_chars, print_hex_chars): Update. + * valprint.c (val_print_type_code_int): Update. + (print_binary_chars): Add "zero_pad" argument. + (emit_octal_digit): New function. + (print_octal_chars): Don't zero-pad. + (print_decimal_chars): Likewise. + (print_hex_chars): Add "zero_pad" argument. + * sh64-tdep.c (sh64_do_fp_register): Update. + * regcache.c (regcache::dump): Update. + * printcmd.c (print_scalar_formatted): Update. + * infcmd.c (default_print_one_register_info): Update. + 2017-06-12 Pedro Alves Alan Hayward diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 09060b51d29..db09f19699d 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2310,7 +2310,8 @@ default_print_one_register_info (struct ui_file *file, if (print_raw_format) { fprintf_filtered (file, "\t(raw "); - print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order); + print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order, + true); fprintf_filtered (file, ")"); } } diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 02d6e1c7b2f..66395d594e3 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -377,10 +377,13 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type, print_decimal_chars (stream, valaddr, len, byte_order); return; case 't': - print_binary_chars (stream, valaddr, len, byte_order); + print_binary_chars (stream, valaddr, len, byte_order, size > 0); return; case 'x': - print_hex_chars (stream, valaddr, len, byte_order); + print_hex_chars (stream, valaddr, len, byte_order, size > 0); + return; + case 'z': + print_hex_chars (stream, valaddr, len, byte_order, true); return; case 'c': print_char_chars (stream, type, valaddr, len, byte_order); @@ -439,10 +442,7 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type, break; case 'o': - if (val_long) - print_longest (stream, 'o', 1, val_long); - else - fprintf_filtered (stream, "0"); + print_longest (stream, 'o', 1, val_long); break; case 'a': @@ -524,7 +524,7 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type, break; case 'z': - print_hex_chars (stream, valaddr, len, byte_order); + print_hex_chars (stream, valaddr, len, byte_order, true); break; default: diff --git a/gdb/regcache.c b/gdb/regcache.c index 46f4641c2b0..43ea4307919 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -1594,7 +1594,7 @@ regcache::dump (ui_file *file, enum regcache_dump_what what_to_dump) raw_update (regnum); print_hex_chars (file, register_buffer (regnum), m_descr->sizeof_register[regnum], - gdbarch_byte_order (gdbarch)); + gdbarch_byte_order (gdbarch), true); } } @@ -1636,7 +1636,7 @@ regcache::dump (ui_file *file, enum regcache_dump_what what_to_dump) else print_hex_chars (file, buf, m_descr->sizeof_register[regnum], - gdbarch_byte_order (gdbarch)); + gdbarch_byte_order (gdbarch), true); if (value != NULL) { diff --git a/gdb/sh64-tdep.c b/gdb/sh64-tdep.c index 4eb8947f74a..dd18e9ff23a 100644 --- a/gdb/sh64-tdep.c +++ b/gdb/sh64-tdep.c @@ -1945,7 +1945,7 @@ sh64_do_fp_register (struct gdbarch *gdbarch, struct ui_file *file, fprintf_filtered (file, "\t(raw "); print_hex_chars (file, raw_buffer, register_size (gdbarch, regnum), - gdbarch_byte_order (gdbarch)); + gdbarch_byte_order (gdbarch), true); fprintf_filtered (file, ")"); fprintf_filtered (file, "\n"); } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 6df961ff371..075f94e8517 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2017-06-12 Tom Tromey + + PR exp/16225: + * gdb.reverse/i386-sse-reverse.exp: Update tests. + * gdb.arch/vsx-regs.exp: Update tests. + * gdb.arch/s390-vregs.exp (hex128): New proc. + Update test. + * gdb.arch/altivec-regs.exp: Update tests. + 2017-06-07 Sergio Durigan Junior * gdb.base/startup-with-shell.c: New file. diff --git a/gdb/testsuite/gdb.arch/altivec-regs.exp b/gdb/testsuite/gdb.arch/altivec-regs.exp index 680b5125ce2..cc679b2b403 100644 --- a/gdb/testsuite/gdb.arch/altivec-regs.exp +++ b/gdb/testsuite/gdb.arch/altivec-regs.exp @@ -94,9 +94,9 @@ gdb_test_multiple "show endian" "$msg" { # b) the register read (below) also works. if {$endianness == "big"} { -set vector_register ".uint128 = 0x00000001000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1., v16_int8 = .0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1.." +set vector_register ".uint128 = 0x1000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1., v16_int8 = .0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1.." } else { -set vector_register ".uint128 = 0x00000001000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0., v16_int8 = .0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0.." +set vector_register ".uint128 = 0x1000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0., v16_int8 = .0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0.." } for {set i 0} {$i < 32} {incr i 1} { @@ -113,9 +113,9 @@ gdb_test "info reg vscr" "vscr.*0x1\t1" "info reg vscr" # the way gdb works. if {$endianness == "big"} { - set decimal_vector ".uint128 = 0x00000001000000010000000100000001, v4_float = .1.*e-45, 1.*e-45, 1.*e-45, 1.*e-45., v4_int32 = .1, 1, 1, 1., v8_int16 = .0, 1, 0, 1, 0, 1, 0, 1., v16_int8 = .0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1.." + set decimal_vector ".uint128 = 0x1000000010000000100000001, v4_float = .1.*e-45, 1.*e-45, 1.*e-45, 1.*e-45., v4_int32 = .1, 1, 1, 1., v8_int16 = .0, 1, 0, 1, 0, 1, 0, 1., v16_int8 = .0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1.." } else { - set decimal_vector ".uint128 = 0x00000001000000010000000100000001, v4_float = .1.*e-45, 1.*e-45, 1.*e-45, 1.*e-45., v4_int32 = .1, 1, 1, 1., v8_int16 = .1, 0, 1, 0, 1, 0, 1, 0., v16_int8 = .1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.." + set decimal_vector ".uint128 = 0x1000000010000000100000001, v4_float = .1.*e-45, 1.*e-45, 1.*e-45, 1.*e-45., v4_int32 = .1, 1, 1, 1., v8_int16 = .1, 0, 1, 0, 1, 0, 1, 0., v16_int8 = .1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.." } for {set i 0} {$i < 32} {incr i 1} { diff --git a/gdb/testsuite/gdb.arch/s390-vregs.exp b/gdb/testsuite/gdb.arch/s390-vregs.exp index 800cc0b5261..078c15395a5 100644 --- a/gdb/testsuite/gdb.arch/s390-vregs.exp +++ b/gdb/testsuite/gdb.arch/s390-vregs.exp @@ -146,16 +146,23 @@ if { $i != 32 } { gdb_continue_to_breakpoint "change vrs" set vregs [capture_command_output "info registers vector" ""] +# Format a 128-bit value, given individual 4-byte values, as hex. +# Leading zeros are suppressed. +proc hex128 {a_high a_low b_high b_low} { + set result [format %08x%08x%08x%08x \ + [expr $a_high * ($i + 1) * $a_high ] \ + [expr $a_low * ($i + 1) * $a_low ] \ + [expr $b_high * (32 - $i) * $b_high * 32] \ + [expr $b_low * (32 - $i) * $b_low * 32] ] + return [regsub -- "^0*" $result ""] +} + set j 1 foreach {- r i val} [regexp -all -inline -line \ {^(\D*)(\d+)\s+.*?uint128 = 0x([0-9a-f]+?)} $vregs] { if { $r ne "v" } { fail "info registers vector: bad line $j" - } elseif { $val ne [format %08x%08x%08x%08x \ - [expr $a_high * ($i + 1) * $a_high ] \ - [expr $a_low * ($i + 1) * $a_low ] \ - [expr $b_high * (32 - $i) * $b_high * 32] \ - [expr $b_low * (32 - $i) * $b_low * 32] ] } { + } elseif { $val ne [hex128 $a_high $a_low $b_high $b_low] } { fail "compare \$v$i" } incr j 1 diff --git a/gdb/testsuite/gdb.arch/vsx-regs.exp b/gdb/testsuite/gdb.arch/vsx-regs.exp index bedbcaaa612..15e7196367a 100644 --- a/gdb/testsuite/gdb.arch/vsx-regs.exp +++ b/gdb/testsuite/gdb.arch/vsx-regs.exp @@ -79,9 +79,9 @@ if {$endianness == "big"} { set vector_register2_vr "uint128 = 0xdeadbeefdeadbeefdeadbeefdeadbeef, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef., v8_int16 = .0xdead, 0xbeef, 0xdead, 0xbeef, 0xdead, 0xbeef, 0xdead, 0xbeef., v16_int8 = .0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef.." - set vector_register3 ".uint128 = 0x00000001000000010000000100000001, v2_double = .0x0, 0x0., v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1., v16_int8 = .0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1.." + set vector_register3 ".uint128 = 0x1000000010000000100000001, v2_double = .0x0, 0x0., v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1., v16_int8 = .0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1.." - set vector_register3_vr ".uint128 = 0x00000001000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1., v16_int8 = .0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1.." + set vector_register3_vr ".uint128 = 0x1000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1., v16_int8 = .0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1.." } else { set vector_register1 ".uint128 = 0x3ff4cccccccccccc0000000000000000, v2_double = .0x0, 0x1., v4_float = .0x0, 0x0, 0xf99999a0, 0x1., v4_int32 = .0x0, 0x0, 0xcccccccc, 0x3ff4cccc., v8_int16 = .0x0, 0x0, 0x0, 0x0, 0xcccc, 0xcccc, 0xcccc, 0x3ff4., v16_int8 = .0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xf4, 0x3f.." @@ -91,9 +91,9 @@ if {$endianness == "big"} { set vector_register2_vr "uint128 = 0xdeadbeefdeadbeefdeadbeefdeadbeef, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef., v8_int16 = .0xbeef, 0xdead, 0xbeef, 0xdead, 0xbeef, 0xdead, 0xbeef, 0xdead., v16_int8 = .0xef, 0xbe, 0xad, 0xde, 0xef, 0xbe, 0xad, 0xde, 0xef, 0xbe, 0xad, 0xde, 0xef, 0xbe, 0xad, 0xde.." - set vector_register3 ".uint128 = 0x00000001000000010000000100000001, v2_double = .0x0, 0x0., v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0., v16_int8 = .0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0.." + set vector_register3 ".uint128 = 0x1000000010000000100000001, v2_double = .0x0, 0x0., v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0., v16_int8 = .0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0.." - set vector_register3_vr ".uint128 = 0x00000001000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0., v16_int8 = .0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0.." + set vector_register3_vr ".uint128 = 0x1000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0., v16_int8 = .0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0.." } set float_register ".raw 0xdeadbeefdeadbeef." diff --git a/gdb/testsuite/gdb.reverse/i386-sse-reverse.exp b/gdb/testsuite/gdb.reverse/i386-sse-reverse.exp index 1d9cd195bcf..6f36476d0e8 100644 --- a/gdb/testsuite/gdb.reverse/i386-sse-reverse.exp +++ b/gdb/testsuite/gdb.reverse/i386-sse-reverse.exp @@ -200,7 +200,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "orpd.*" "reverse-step to orpd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0000000000000000fff80000ffc00000.*" \ + "xmm0 .*uint128 = 0xfff80000ffc00000.*" \ "verify xmm0 after reverse orps" gdb_test "info register xmm1" \ @@ -214,7 +214,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "mulss.*" "reverse-step to mulss" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0000000000000000fff80000ffc00000.*" \ + "xmm0 .*uint128 = 0xfff80000ffc00000.*" \ "verify xmm0 after reverse orpd" gdb_test "info register xmm1" \ @@ -228,7 +228,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "mulsd.*" "reverse-step to mulsd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0000000000000000fff80000ffc00000.*" \ + "xmm0 .*uint128 = 0xfff80000ffc00000.*" \ "verify xmm0 after reverse mulss" gdb_test "info register xmm1" \ @@ -242,7 +242,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "mulps.*" "reverse-step to mulps" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0000000000000000fff80000ffc00000.*" \ + "xmm0 .*uint128 = 0xfff80000ffc00000.*" \ "verify xmm0 after reverse mulsd" gdb_test "info register xmm1" \ @@ -256,7 +256,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "mulpd.*" "reverse-step to mulpd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0000000000000000fff80000ffc00000.*" \ + "xmm0 .*uint128 = 0xfff80000ffc00000.*" \ "verify xmm0 after reverse mulps" gdb_test "info register xmm1" \ @@ -270,7 +270,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "divss.*" "reverse-step to divss" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0000000000000000fff80000ffc00000.*" \ + "xmm0 .*uint128 = 0xfff80000ffc00000.*" \ "verify xmm0 after reverse mulpd" gdb_test "info register xmm1" \ @@ -284,7 +284,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "divsd.*" "reverse-step to divsd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x00000000000000008000000080000000.*" \ + "xmm0 .*uint128 = 0x8000000080000000.*" \ "verify xmm0 after reverse divss" gdb_test "info register xmm1" \ @@ -298,11 +298,11 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "divps.*" "reverse-step to divps" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x00000000000000008000000080000000.*" \ + "xmm0 .*uint128 = 0x8000000080000000.*" \ "verify xmm0 after reverse divsd" gdb_test "info register xmm1" \ - "xmm1 .*uint128 = 0x00000000000000000000000080000000.*" \ + "xmm1 .*uint128 = 0x80000000.*" \ "verify xmm1 after reverse divsd" gdb_test "info register xmm2" \ @@ -312,11 +312,11 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "divpd.*" "reverse-step to divpd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x00000000000000008000000080000000.*" \ + "xmm0 .*uint128 = 0x8000000080000000.*" \ "verify xmm0 after reverse divps" gdb_test "info register xmm1" \ - "xmm1 .*uint128 = 0x00000000000000000000000080000000.*" \ + "xmm1 .*uint128 = 0x80000000.*" \ "verify xmm1 after reverse divps" gdb_test "info register xmm2" \ @@ -326,7 +326,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "cvtpd2ps.*" "reverse-step to cvtpd2ps" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x00000000000000008000000080000000.*" \ + "xmm0 .*uint128 = 0x8000000080000000.*" \ "verify xmm0 after reverse divpd" gdb_test "info register xmm1" \ @@ -340,7 +340,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "cvtpd2dq.*" "reverse-step to cvtpd2dq" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a090807060504ffffffff.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a090807060504ffffffff.*" \ "verify xmm0 after reverse cvtpd2ps" gdb_test "info register xmm1" \ @@ -354,11 +354,11 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "cvtdq2ps.*" "reverse-step to cvtdq2ps" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a090807060504ffffffff.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a090807060504ffffffff.*" \ "verify xmm0 after reverse cvtpd2dq" gdb_test "info register xmm1" \ - "xmm1 .*uint128 = 0x0000000000000000ffffffffffffffff.*" \ + "xmm1 .*uint128 = 0xffffffffffffffff.*" \ "verify xmm1 after reverse cvtpd2dq" gdb_test "info register xmm2" \ @@ -368,11 +368,11 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "cvtdq2pd.*" "reverse-step to cvtdq2pd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a090807060504ffffffff.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a090807060504ffffffff.*" \ "verify xmm0 after reverse cvtdq2ps" gdb_test "info register xmm1" \ - "xmm1 .*uint128 = 0x0000000000000000ffffffffffffffff.*" \ + "xmm1 .*uint128 = 0xffffffffffffffff.*" \ "verify xmm1 after reverse cvtdq2ps" gdb_test "info register xmm2" \ @@ -382,11 +382,11 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "comiss.*" "reverse-step to comiss" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a090807060504ffffffff.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a090807060504ffffffff.*" \ "verify xmm0 after reverse cvtdq2pd" gdb_test "info register xmm1" \ - "xmm1 .*uint128 = 0x0000000000000000ffffffffffffffff.*" \ + "xmm1 .*uint128 = 0xffffffffffffffff.*" \ "verify xmm1 after reverse cvtdq2pd" gdb_test "info register xmm2" \ @@ -396,11 +396,11 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "comisd.*" "reverse-step to comisd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a090807060504ffffffff.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a090807060504ffffffff.*" \ "verify xmm0 after reverse comiss" gdb_test "info register xmm1" \ - "xmm1 .*uint128 = 0x0000000000000000ffffffffffffffff.*" \ + "xmm1 .*uint128 = 0xffffffffffffffff.*" \ "verify xmm1 after reverse comiss" gdb_test "info register xmm2" \ @@ -410,11 +410,11 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "cmpss.*" "reverse-step to cmpss" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050423222120.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050423222120.*" \ "verify xmm0 after reverse comisd" gdb_test "info register xmm1" \ - "xmm1 .*uint128 = 0x0000000000000000ffffffffffffffff.*" \ + "xmm1 .*uint128 = 0xffffffffffffffff.*" \ "verify xmm1 after reverse comisd" gdb_test "info register xmm2" \ @@ -424,11 +424,11 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "cmpsd.*" "reverse-step to cmpsd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050423222120.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050423222120.*" \ "verify xmm0 after reverse cmpss" gdb_test "info register xmm1" \ - "xmm1 .*uint128 = 0x00000000000000000000000000000000.*" \ + "xmm1 .*uint128 = 0x.*" \ "verify xmm1 after reverse cmpss" gdb_test "info register xmm2" \ @@ -438,35 +438,35 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "cmpps.*" "reverse-step to cmpps" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050423222120.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050423222120.*" \ "verify xmm0 after reverse cmpsd" gdb_test "info register xmm1" \ - "xmm1 .*uint128 = 0x00000000000000000000000000000000.*" \ + "xmm1 .*uint128 = 0x.*" \ "verify xmm1 after reverse cmpsd" gdb_test "info register xmm2" \ - "xmm2 .*uint128 = 0x0f0e0d0c0b0a09082726252400000000.*" \ + "xmm2 .*uint128 = 0xf0e0d0c0b0a09082726252400000000.*" \ "verify xmm2 after reverse cmpsd" gdb_test "reverse-step" "cmppd.*" "reverse-step to cmppd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050423222120.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050423222120.*" \ "verify xmm0 after reverse cmpps" gdb_test "info register xmm1" \ - "xmm1 .*uint128 = 0x0f0e0d0c0b0a09082726252400000000.*" \ + "xmm1 .*uint128 = 0xf0e0d0c0b0a09082726252400000000.*" \ "verify xmm1 after reverse cmpps" gdb_test "info register xmm2" \ - "xmm2 .*uint128 = 0x0f0e0d0c0b0a09082726252400000000.*" \ + "xmm2 .*uint128 = 0xf0e0d0c0b0a09082726252400000000.*" \ "verify xmm2 after reverse cmpps" gdb_test "reverse-step" "andps.*" "reverse-step to andps" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050423222120.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050423222120.*" \ "verify xmm0 after reverse cmppd" gdb_test "info register xmm1" \ @@ -474,13 +474,13 @@ gdb_test "info register xmm1" \ "verify xmm1 after reverse cmppd" gdb_test "info register xmm2" \ - "xmm2 .*uint128 = 0x0f0e0d0c0b0a09082726252400000000.*" \ + "xmm2 .*uint128 = 0xf0e0d0c0b0a09082726252400000000.*" \ "verify xmm2 after reverse cmppd" gdb_test "reverse-step" "andpd.*" "reverse-step to andpd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050423222120.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050423222120.*" \ "verify xmm0 after reverse andps" gdb_test "info register xmm1" \ @@ -494,7 +494,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "addsubps.*" "reverse-step to addsubps" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050423222120.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050423222120.*" \ "verify xmm0 after reverse andpd" gdb_test "info register xmm1" \ @@ -508,7 +508,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "addsubpd.*" "reverse-step to addsubpd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050423222120.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050423222120.*" \ "verify xmm0 after reverse addsubps" gdb_test "info register xmm1" \ @@ -522,7 +522,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "addss.*" "reverse-step to addss" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050403020100.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050403020100.*" \ "verify xmm0 after reverse addsubpd" gdb_test "info register xmm1" \ @@ -536,7 +536,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "addsd.*" "reverse-step to addsd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050403020100.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050403020100.*" \ "verify xmm0 after reverse addss" gdb_test "info register xmm1" \ @@ -550,7 +550,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "addps.*" "reverse-step to addps" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050403020100.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050403020100.*" \ "verify xmm0 after reverse addsd" gdb_test "info register xmm1" \ @@ -564,7 +564,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "addpd.*" "reverse-step to addpd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050403020100.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050403020100.*" \ "verify xmm0 after reverse addps" gdb_test "info register xmm1" \ @@ -612,7 +612,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "pabsd.*" "reverse-step to pabsd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050403020100.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050403020100.*" \ "verify xmm0 after reverse pabsd" gdb_test "info register xmm1" \ @@ -626,7 +626,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "pabsw.*" "reverse-step to pabsw" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050403020100.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050403020100.*" \ "verify xmm0 after reverse pabsw" gdb_test "info register xmm1" \ @@ -640,7 +640,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "pabsb.*" "reverse-step to pabsb" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050403020100.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050403020100.*" \ "verify xmm0 after reverse pabsb" gdb_test "info register xmm1" \ @@ -676,7 +676,7 @@ gdb_test_multiple "continue" $test { gdb_test "reverse-step" "blendvps.*" "reverse-step to blendvps" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09082726252413121110.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09082726252413121110.*" \ "verify xmm0 at end of sse4_test" gdb_test "info register xmm1" \ @@ -690,7 +690,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "blendvpd.*" "reverse-step to blendvpd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09082726252413121110.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09082726252413121110.*" \ "verify xmm0 after reverse blendvps" gdb_test "info register xmm1" \ @@ -704,7 +704,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "blendps.*" "reverse-step to blendps" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09081716151413121110.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09081716151413121110.*" \ "verify xmm0 after reverse blendvpd" gdb_test "info register xmm1" \ @@ -718,7 +718,7 @@ gdb_test "info register xmm2" \ gdb_test "reverse-step" "blendpd.*" "reverse-step to blendpd" gdb_test "info register xmm0" \ - "xmm0 .*uint128 = 0x0f0e0d0c0b0a09080706050403020100.*" \ + "xmm0 .*uint128 = 0xf0e0d0c0b0a09080706050403020100.*" \ "verify xmm0 after reverse blendps" gdb_test "info register xmm1" \ diff --git a/gdb/valprint.c b/gdb/valprint.c index 6937dab7c63..aa34b68c833 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -1264,7 +1264,7 @@ val_print_type_code_int (struct type *type, const gdb_byte *valaddr, complement (a reasonable assumption, I think) and do better than this. */ print_hex_chars (stream, (unsigned char *) valaddr, - TYPE_LENGTH (type), byte_order); + TYPE_LENGTH (type), byte_order, false); } } else @@ -1537,7 +1537,7 @@ print_decimal_floating (const gdb_byte *valaddr, struct type *type, void print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr, - unsigned len, enum bfd_endian byte_order) + unsigned len, enum bfd_endian byte_order, bool zero_pad) { #define BITS_IN_BYTES 8 @@ -1545,14 +1545,13 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr, const gdb_byte *p; unsigned int i; int b; + bool seen_a_one = false; /* Declared "int" so it will be signed. This ensures that right shift will shift in zeros. */ const int mask = 0x080; - /* FIXME: We should be not printing leading zeroes in most cases. */ - if (byte_order == BFD_ENDIAN_BIG) { for (p = valaddr; @@ -1565,11 +1564,14 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr, for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++) { if (*p & (mask >> i)) - b = 1; + b = '1'; else - b = 0; + b = '0'; - fprintf_filtered (stream, "%1d", b); + if (zero_pad || seen_a_one || b == '1') + fputc_filtered (b, stream); + if (b == '1') + seen_a_one = true; } } } @@ -1582,14 +1584,34 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr, for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++) { if (*p & (mask >> i)) - b = 1; + b = '1'; else - b = 0; + b = '0'; - fprintf_filtered (stream, "%1d", b); + if (zero_pad || seen_a_one || b == '1') + fputc_filtered (b, stream); + if (b == '1') + seen_a_one = true; } } } + + /* When not zero-padding, ensure that something is printed when the + input is 0. */ + if (!zero_pad && !seen_a_one) + fputc_filtered ('0', stream); +} + +/* A helper for print_octal_chars that emits a single octal digit, + optionally suppressing it if is zero and updating SEEN_A_ONE. */ + +static void +emit_octal_digit (struct ui_file *stream, bool *seen_a_one, int digit) +{ + if (*seen_a_one || digit != 0) + fprintf_filtered (stream, "%o", digit); + if (digit != 0) + *seen_a_one = true; } /* VALADDR points to an integer of LEN bytes. @@ -1603,9 +1625,6 @@ print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr, unsigned char octa1, octa2, octa3, carry; int cycle; - /* FIXME: We should be not printing leading zeroes in most cases. */ - - /* Octal is 3 bits, which doesn't fit. Yuk. So we have to track * the extra bits, which cycle every three bytes: * @@ -1640,6 +1659,7 @@ print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr, carry = 0; fputs_filtered ("0", stream); + bool seen_a_one = false; if (byte_order == BFD_ENDIAN_BIG) { for (p = valaddr; @@ -1654,8 +1674,8 @@ print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr, octa1 = (HIGH_ZERO & *p) >> 5; octa2 = (LOW_ZERO & *p) >> 2; carry = (CARRY_ZERO & *p); - fprintf_filtered (stream, "%o", octa1); - fprintf_filtered (stream, "%o", octa2); + emit_octal_digit (stream, &seen_a_one, octa1); + emit_octal_digit (stream, &seen_a_one, octa2); break; case 1: @@ -1665,9 +1685,9 @@ print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr, octa2 = (MID_ONE & *p) >> 4; octa3 = (LOW_ONE & *p) >> 1; carry = (CARRY_ONE & *p); - fprintf_filtered (stream, "%o", octa1); - fprintf_filtered (stream, "%o", octa2); - fprintf_filtered (stream, "%o", octa3); + emit_octal_digit (stream, &seen_a_one, octa1); + emit_octal_digit (stream, &seen_a_one, octa2); + emit_octal_digit (stream, &seen_a_one, octa3); break; case 2: @@ -1677,9 +1697,9 @@ print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr, octa2 = (MID_TWO & *p) >> 3; octa3 = (LOW_TWO & *p); carry = 0; - fprintf_filtered (stream, "%o", octa1); - fprintf_filtered (stream, "%o", octa2); - fprintf_filtered (stream, "%o", octa3); + emit_octal_digit (stream, &seen_a_one, octa1); + emit_octal_digit (stream, &seen_a_one, octa2); + emit_octal_digit (stream, &seen_a_one, octa3); break; default: @@ -1704,8 +1724,8 @@ print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr, octa1 = (HIGH_ZERO & *p) >> 5; octa2 = (LOW_ZERO & *p) >> 2; carry = (CARRY_ZERO & *p); - fprintf_filtered (stream, "%o", octa1); - fprintf_filtered (stream, "%o", octa2); + emit_octal_digit (stream, &seen_a_one, octa1); + emit_octal_digit (stream, &seen_a_one, octa2); break; case 1: @@ -1715,9 +1735,9 @@ print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr, octa2 = (MID_ONE & *p) >> 4; octa3 = (LOW_ONE & *p) >> 1; carry = (CARRY_ONE & *p); - fprintf_filtered (stream, "%o", octa1); - fprintf_filtered (stream, "%o", octa2); - fprintf_filtered (stream, "%o", octa3); + emit_octal_digit (stream, &seen_a_one, octa1); + emit_octal_digit (stream, &seen_a_one, octa2); + emit_octal_digit (stream, &seen_a_one, octa3); break; case 2: @@ -1727,9 +1747,9 @@ print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr, octa2 = (MID_TWO & *p) >> 3; octa3 = (LOW_TWO & *p); carry = 0; - fprintf_filtered (stream, "%o", octa1); - fprintf_filtered (stream, "%o", octa2); - fprintf_filtered (stream, "%o", octa3); + emit_octal_digit (stream, &seen_a_one, octa1); + emit_octal_digit (stream, &seen_a_one, octa2); + emit_octal_digit (stream, &seen_a_one, octa3); break; default: @@ -1758,7 +1778,6 @@ print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr, #define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4) const gdb_byte *p; - unsigned char *digits; int carry; int decimal_len; int i, j, decimal_digits; @@ -1769,12 +1788,7 @@ print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr, as the base 16 number, which is 2 digits per byte. */ decimal_len = len * 2 * 2; - digits = (unsigned char *) xmalloc (decimal_len); - - for (i = 0; i < decimal_len; i++) - { - digits[i] = 0; - } + std::vector digits (decimal_len, 0); /* Ok, we have an unknown number of bytes of data to be printed in * decimal. @@ -1868,40 +1882,73 @@ print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr, /* Ok, now "digits" is the decimal representation, with the "decimal_digits" actual digits. Print! */ - for (i = decimal_digits - 1; i >= 0; i--) + for (i = decimal_digits - 1; i > 0 && digits[i] == 0; --i) + ; + + for (; i >= 0; i--) { fprintf_filtered (stream, "%1d", digits[i]); } - xfree (digits); } /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */ void print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr, - unsigned len, enum bfd_endian byte_order) + unsigned len, enum bfd_endian byte_order, + bool zero_pad) { const gdb_byte *p; - /* FIXME: We should be not printing leading zeroes in most cases. */ - fputs_filtered ("0x", stream); if (byte_order == BFD_ENDIAN_BIG) { - for (p = valaddr; + p = valaddr; + + if (!zero_pad) + { + /* Strip leading 0 bytes, but be sure to leave at least a + single byte at the end. */ + for (; p < valaddr + len - 1 && !*p; ++p) + ; + } + + const gdb_byte *first = p; + for (; p < valaddr + len; p++) { - fprintf_filtered (stream, "%02x", *p); + /* When not zero-padding, use a different format for the + very first byte printed. */ + if (!zero_pad && p == first) + fprintf_filtered (stream, "%x", *p); + else + fprintf_filtered (stream, "%02x", *p); } } else { - for (p = valaddr + len - 1; + p = valaddr + len - 1; + + if (!zero_pad) + { + /* Strip leading 0 bytes, but be sure to leave at least a + single byte at the end. */ + for (; p >= valaddr + 1 && !*p; --p) + ; + } + + const gdb_byte *first = p; + for (; p >= valaddr; p--) { - fprintf_filtered (stream, "%02x", *p); + /* When not zero-padding, use a different format for the + very first byte printed. */ + if (!zero_pad && p == first) + fprintf_filtered (stream, "%x", *p); + else + fprintf_filtered (stream, "%02x", *p); } } } diff --git a/gdb/valprint.h b/gdb/valprint.h index 835296af88f..8bfad21790e 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -132,7 +132,7 @@ extern void val_print_scalar_formatted (struct type *, struct ui_file *); extern void print_binary_chars (struct ui_file *, const gdb_byte *, - unsigned int, enum bfd_endian); + unsigned int, enum bfd_endian, bool); extern void print_octal_chars (struct ui_file *, const gdb_byte *, unsigned int, enum bfd_endian); @@ -141,7 +141,7 @@ extern void print_decimal_chars (struct ui_file *, const gdb_byte *, unsigned int, enum bfd_endian); extern void print_hex_chars (struct ui_file *, const gdb_byte *, - unsigned int, enum bfd_endian); + unsigned int, enum bfd_endian, bool); extern void print_char_chars (struct ui_file *, struct type *, const gdb_byte *, unsigned int, enum bfd_endian); -- 2.30.2