[Bug gdb/25321] New: Subtracting two pointers in value history variables gives wrong result

simark at simark dot ca sourceware-bugzilla@sourceware.org
Sun Dec 29 18:54:00 GMT 2019


https://sourceware.org/bugzilla/show_bug.cgi?id=25321

            Bug ID: 25321
           Summary: Subtracting two pointers in value history variables
                    gives wrong result
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: simark at simark dot ca
  Target Milestone: ---

I found this while trying to find by how much a global variable gets relocated.
 I first print the variable address:

(gdb) p &some_global
$1 = (int *) 0x402c <some_global>

Then start the inferior:

(gdb) start
Temporary breakpoint 1 at 0x111d: file test.c, line 9.
Starting program: /home/simark/src/aoc/08/p2/a.out 

Temporary breakpoint 1, main () at test.c:9
9         for (i = 0; i < 1000; i++) {

Then print the variable again:
(gdb) p &some_global
$2 = (int *) 0x55555555802c <some_global>

This is the difference between the two addresses:

(gdb) p/x 0x55555555802c - 0x402c
$3 = 0x555555554000

Trying to compute the same using the numbered history variables gives a
different result:

(gdb) p/x $2 - $1
$4 = 0x155555555000

I haven't investigated at all.  All I know is that the type of the pointers
appear to be the same:

(gdb) p sizeof($1)
$5 = 8
(gdb) p sizeof($2)
$6 = 8
(gdb) p sizeof(*$1)
$7 = 4
(gdb) p sizeof(*$2)
$8 = 4
(gdb) ptype $1
type = int *
(gdb) ptype $2
type = int *

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Gdb-prs mailing list