From: Yang Yibiao <yangyibiao@outlook.com>
To: "gdb@sourceware.org" <gdb@sourceware.org>
Subject: Is it possible that an address is mapping to more than one source lines of code?
Date: Wed, 9 Dec 2020 01:14:30 +0000 [thread overview]
Message-ID: <SYYP282MB2079235963CCFC1402A57D49D8CC0@SYYP282MB2079.AUSP282.PROD.OUTLOOK.COM> (raw)
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
reply other threads:[~2020-12-09 1:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=SYYP282MB2079235963CCFC1402A57D49D8CC0@SYYP282MB2079.AUSP282.PROD.OUTLOOK.COM \
--to=yangyibiao@outlook.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).