Bug 23220 - Gdb prints the wrong address for local variables, in 32 bit mode
Summary: Gdb prints the wrong address for local variables, in 32 bit mode
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: exp (show other bugs)
Version: 7.11.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 23221 23222 23223 23224 23225 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-05-23 17:30 UTC by kkireeva
Modified: 2021-04-17 16:48 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Binary for the source code (8.27 KB, application/x-executable)
2018-05-23 17:30 UTC, kkireeva
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kkireeva 2018-05-23 17:30:59 UTC
Created attachment 11041 [details]
Binary for the source code

I didn't compile the binary myself.
It has no stack protections

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv)
{
  volatile int modified;
  char buffer[64];

  modified = 0;
  gets(buffer);

  if(modified != 0) {
      printf("you have changed the 'modified' variable\n");
  } else {
      printf("Try again?\n");
  }
}

The addresses of modified and buffer are printed above argv, which is nonsense.
Also their true location is different, as evidenced by what strcpy modifies. 
print &modified
$1 = (volatile int*) 0xffffcf3c
print &argv
$2 = (char***) 0xffffcf64
Comment 1 Andreas Schwab 2018-05-23 20:23:40 UTC
*** Bug 23221 has been marked as a duplicate of this bug. ***
Comment 2 Andreas Schwab 2018-05-23 20:27:36 UTC
*** Bug 23222 has been marked as a duplicate of this bug. ***
Comment 3 Andreas Schwab 2018-05-23 20:27:50 UTC
*** Bug 23223 has been marked as a duplicate of this bug. ***
Comment 4 Andreas Schwab 2018-05-23 20:28:13 UTC
*** Bug 23224 has been marked as a duplicate of this bug. ***
Comment 5 Andreas Schwab 2018-05-23 20:28:27 UTC
*** Bug 23225 has been marked as a duplicate of this bug. ***
Comment 6 Tom Tromey 2021-04-17 16:48:55 UTC
This executable was compiled using the stabs debug format.
stabs is long since deprecated.  It may work sometimes,
but as you've found, there are bugs -- some of which, I believe,
are what lead the world to abandon stabs in favor of DWARF.
I don't know stabs well enough (they were deprecated before
I started working on gdb, which is quite a long time ago now)
to even say whether you've hit one of these.

The fix is to not use stabs but instead use DWARF.
This is the default in all contemporary free software compilers,
and has been for a decade or more.

I tend to think we should "wontfix" stabs bugs, since that
reflects the real situation -- nobody works on stabs at all,
I don't recall the last time a bug was fixed there.
However, that always seems a little rude somehow in bugzilla.