public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "brenorg at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug c++/25987] New: Wrong line for code containing inlined functions
Date: Wed, 13 May 2020 14:16:46 +0000	[thread overview]
Message-ID: <bug-25987-4717@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=25987

            Bug ID: 25987
           Summary: Wrong line for code containing inlined functions
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: brenorg at gmail dot com
  Target Milestone: ---

TLDR:

GDB is showing the wrong line information for a function call in a line with
inlined functions. Like this:

```
some_unique_ptr->fn();
```

In the backtrace, GDB shows "unique_ptr::operator->" as line information for
the call to "fn".


The long version: 


For the following code:

```

struct MyClass;
struct ptr {
    MyClass* get() { return t; }
    MyClass* t;
};
struct MyClass { void call(); };
void MyClass::call() {
    *(char*)(nullptr) = 1;
}
static void intermediate(ptr p) {
    p.get()->call();
}
int main() {
    intermediate(ptr{new MyClass});
}

```

Compiled with GCC 8 or above with these flags:

```
g++ -Og -g -o main main.cpp
```

The function "call" will crash and the backtrace using GDB HEAD looks like
this:

```
#0  MyClass::call (this=0x416c20) at main.cpp:8
#1  0x0000000000401140 in intermediate (p=...) at main.cpp:3
#2  0x0000000000401157 in main () at main.cpp:14
```

Notice that the "intermediate" frame is pointing to main.cpp:3 which is the
call to "get". I would expect it to show main.cpp:11

I tested GDB 8 and it shows the correct information but that seems by chance.
If I move the "ptr" definition to a header, then it also fails with GDB 8 (but
works with GDB head).

Looking at the decoded line information, it seems that there is no way for GDB
to tell which is the correct call:

```
$ objdump -D main | grep callq.*intermediate
  401152:       e8 e4 ff ff ff          callq  40113b <_ZL12intermediate3ptr


$ objdump --dwarf=decodedline main | grep 40113b
main.cpp 10 0x40113b               x
main.cpp 11 0x40113b       1       x
main.cpp  3 0x40113b       2       x
main.cpp  3 0x40113b       3       x
main.cpp  3 0x40113b       4
main.cpp 11 0x40113b       5

```

There seems to be multiple line information for the same "callq" instruction.
So I'm not sure how GDB would tell the difference. Maybe from the dwarf
information it should be able to figure out which of those lines refer to
inlined functions ?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2020-05-13 14:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13 14:16 brenorg at gmail dot com [this message]
2020-05-13 14:18 ` [Bug c++/25987] " brenorg at gmail dot com
2020-05-14 13:33 ` ssbssa at sourceware dot org
2020-12-29  9:15 ` bernd.edlinger at hotmail dot de
2020-12-29  9:28 ` bernd.edlinger at hotmail dot de

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=bug-25987-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@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).