* Is it possible that an address is mapping to more than one source lines of code?
@ 2020-12-09 1:14 Yang Yibiao
0 siblings, 0 replies; only message in thread
From: Yang Yibiao @ 2020-12-09 1:14 UTC (permalink / raw)
To: gdb
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-12-09 1:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 1:14 Is it possible that an address is mapping to more than one source lines of code? Yang Yibiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).