Bug 21675

Summary: Regression since 8.0 printing has changed format for decimal/octal/others
Product: gdb Reporter: Jonah Graham <jonah>
Component: gdbAssignee: Tom Tromey <tromey>
Status: RESOLVED FIXED    
Severity: normal CC: pedro, tromey
Priority: P2    
Version: HEAD   
Target Milestone: 8.1   
Host: Target:
Build: Last reconfirmed: 2017-07-11 00:00:00

Description Jonah Graham 2017-06-26 13:07:16 UTC
For example on current HEAD:

$ gdb/gdb -q -ex 'print/o -5' -ex quit
$1 = 037773777773

Instead previous versions do this:

$ gdb.8.0 -q -ex 'print/o -5' -ex quit
$1 = 037777777773

AFAICT This is a regression caused by d9109c8080ac0a2caeaa5f3d51e8a3b4891a68a8 (Simplify print_scalar_formatted)

There are many other examples of things that fail in a similar way. They were picked up by the DSF-GDB testsuite for Eclipse CDT. https://ci.eclipse.org/cdt/view/Debug/job/debug-tests-master-gdb-master
Comment 1 Jonah Graham 2017-06-26 13:30:21 UTC
Here is another example, demonstrating the problem is not just octal printing:

$ gdb/gdb -q -ex 'print/d 1.5' -ex quit
$1 = 1.5

$ gdb.8.0 -q -ex 'print/d 1.5' -ex quit
$1 = 1

and

$ gdb/gdb -q -ex 'print/u 1.5' -ex quit
$1 = 4609434218613702656

$ gdb.8.0 -q -ex 'print/u 1.5' -ex quit
$1 = 1
Comment 2 Tom Tromey 2017-07-11 02:34:05 UTC
(In reply to Jonah Graham from comment #1)
> Here is another example, demonstrating the problem is not just octal
> printing:

> $ gdb.8.0 -q -ex 'print/d 1.5' -ex quit
> $1 = 1

> $ gdb.8.0 -q -ex 'print/u 1.5' -ex quit
> $1 = 1

These still seem weird to me but I think we agreed to try to preserve
this in:

https://sourceware.org/ml/gdb-patches/2017-06/msg00314.html
Comment 3 Tom Tromey 2017-07-11 12:25:40 UTC
(In reply to Jonah Graham from comment #0)
> For example on current HEAD:

> $ gdb/gdb -q -ex 'print/o -5' -ex quit
> $1 = 037773777773

This bug is that one of the constants in print_octals_chars is wrong.
I guess it's been wrong for years and years and nobody noticed before...
Comment 4 Pedro Alves 2017-07-11 12:56:38 UTC
(In reply to Tom Tromey from comment #2)
> (In reply to Jonah Graham from comment #1)
> > Here is another example, demonstrating the problem is not just octal
> > printing:
> 
> > $ gdb.8.0 -q -ex 'print/d 1.5' -ex quit
> > $1 = 1
> 
> > $ gdb.8.0 -q -ex 'print/u 1.5' -ex quit
> > $1 = 1
> 
> These still seem weird to me 

OOC, how would you see them ideally be printed?

> but I think we agreed to try to preserve this in:

> https://sourceware.org/ml/gdb-patches/2017-06/msg00314.html
Comment 5 Tom Tromey 2017-07-11 15:35:35 UTC
(In reply to Pedro Alves from comment #4)

> > https://sourceware.org/ml/gdb-patches/2017-06/msg00314.html

For floating point types, I think /d and /u should work just like
not having a flag; /o should probably just be an error or ignored,
and /x should print in hex float.  I'm not sure what /t should do.
Comment 6 Pedro Alves 2017-07-11 19:58:52 UTC
Given structs with mixed types, it seems to me that erroring wouldn't be desirable.  E.g.:

  struct { int i; float f; } var;
  (gdb) p /o var
Comment 7 Tom Tromey 2017-07-12 02:19:32 UTC
(In reply to Pedro Alves from comment #6)
> Given structs with mixed types, it seems to me that erroring wouldn't be
> desirable.  E.g.:
> 
>   struct { int i; float f; } var;
>   (gdb) p /o var

Good point.  Maybe /o and /t could be ignored for floating point.
My main concern there would be possible confusion (like, "p/t 1.1"
could be weird) -- though on the other hand I think the current
behavior is already very confusing.
Comment 8 Jonah Graham 2017-08-16 09:47:16 UTC
Thanks for fixing this, the test failures in Eclipse CDT are now resolved.

PS due to https://sourceware.org/ml/overseers/2017-q3/msg00065.html some comments are missing in this bug:
https://sourceware.org/ml/gdb-prs/2017-q3/msg00203.html
https://sourceware.org/ml/gdb-prs/2017-q3/msg00204.html
Comment 9 Tom Tromey 2017-08-16 13:06:56 UTC
Thanks for posting those links.

The bug is fixed, I'm closing this.