Is it possible that an address is mapping to more than one source lines of code?

Yang Yibiao via Gdb <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <SYYP282MB2079235963CCFC1402A57D49D8CC0@SYYP282MB2079.AUSP282.PROD.OUTLOOK.COM>

Hi,



Consider the following code:



$ cat small.c

/* { dg-do run } */



char *pa;

char *pb;

char *pc;



void access (volatile char *ptr)

{

  *ptr = 'x';

}



int main (int argc, char **argv)

{

  char a;

  char b;

  char c;



  pa = &a;

  pb = &b;

  pc = &c;



  access (pb);

  access (pc);

  // access 'b' here

  access (pa + 32);



  return 0;

}



/** Compile with ‘-O1’ optimization **/

$ gcc -O1 -g small.c



/** debug under gdb **/

$ gdb a.out

(gdb) b main

Breakpoint 1 at 0x68e: file small.c, line 13.

(gdb) r

Starting program: /root/DeVIL/a.out



Breakpoint 1, main (argc=1, argv=0x7fffffffe588) at small.c:13

13      {

(gdb) s

18        pa = &a;

(gdb) s

19        pb = &b;

(gdb) s

20        pc = &c;

(gdb) s

22        access (pb);

(gdb) where -frame-info location-and-address

#0  0x00005555555546c6 in main (argc=1, argv=0x7fffffffe588) at small.c:22

(gdb) s

access (ptr=0x7fffffffe496 "") at small.c:9

9         *ptr = 'x';

(gdb) where -frame-info location-and-address

#0  0x00005555555546c6 in access (ptr=0x7fffffffe496 "") at small.c:9

#1  0x00005555555546c6 in main (argc=1, argv=0x7fffffffe588) at small.c:22





############################################################

We can found that 0x00005555555546c6 not only belongs to source line "small.c:22" but also belongs to "small.c:9"

When compiling "small.c" without optimization, there is no such problem.

I was wondering that this might be a bug of gdb, thus I also submitted it as a new bug report in Bugzilla of gdb:

https://sourceware.org/bugzilla/show_bug.cgi?id=27036
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.