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

Yang Yibiao yangyibiao@outlook.com
Wed Dec 9 01:14:30 GMT 2020



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





More information about the Gdb mailing list