0

Example of p/x:

(gdb)  p/x (long long)-2147483647 #still works
$1 = 0xffffffff80000001
(gdb) p/x (long long)-2147483648 #truncated once input exceed max int
$2 = 0x80000000
(gdb) p/x (long long)-2147483649
$3 = 0x7fffffff
(gdb) whatis $1
type = long long
(gdb) whatis $2
type = long long
(gdb) whatis $3
type = long long

And p/u:

(gdb) p/u (long long)-2147483647
$1 = 18446744071562067969
(gdb) p/u (long long)-2147483648
$2 = 2147483648
(gdb) whatis $1
type = long long
(gdb) whatis $2
type = long long

I always concluded that this is gdb bug, but now I think I may misunderstanding and decided to post this question here.

Output (as requested by comment):

(gdb) whatis -2147483647
type = int
(gdb) whatis -2147483648
type = unsigned int
(gdb) whatis -2147483648LL
type = long long
(gdb) p (long long)-2147483648LL
$1 = -2147483648
林果皞
  • 7,539
  • 3
  • 55
  • 70
  • 1
    Can you show the output of `whatis -2147483647` and `whatis -2147483648` and `whatis -2147483648LL` and `p (long long)-2147483648LL` – Mark Plotnick Feb 07 '18 at 15:01
  • @MarkPlotnick `LL` did the trick, but does that means I should never use (cast) with literal ? – 林果皞 Feb 07 '18 at 15:14
  • @MarkPlotnick And the output doesn't post-fix with `LL` and make me confuse. Is there any way to force gdb output with `LL` if it is long long ? – 林果皞 Feb 07 '18 at 15:25
  • 1
    Casts with literals are OK, as long as you take into account how gdb does its type inferencing for literals. `p (long long)(int)-2147483648` likely does what you expect, but `p (long long)-2147483648` may not be what you expect, because gdb inferred that `-2147483648` is an unsigned. – Mark Plotnick Feb 07 '18 at 17:27

0 Answers0