Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line-based breakpoints in inline functions don't show correct source #13442

Open
jdm opened this issue Apr 10, 2014 · 13 comments
Open

Line-based breakpoints in inline functions don't show correct source #13442

jdm opened this issue Apr 10, 2014 · 13 comments
Assignees
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jdm
Copy link
Contributor

jdm commented Apr 10, 2014

#[inline(always)]
fn bar() -> int {
    5
}

fn main() {
    let _ = bar();
}
(gdb) break inline.rs:3
Breakpoint 1 at 0x404e80: file inline.rs, line 3.
(gdb) r
Starting program: /tmp/inline 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Breakpoint 1, inline::main () at inline.rs:6
6   fn main() {
(gdb) 
@michaelwoerister
Copy link
Member

Taking some notes here:

  • What should actually be shown here is line 3
  • Take a look at the DWARF line tables to see what machine code is associated with what source code.
  • Verify that source positions are created correctly for the inlined function in the IR.
  • Check whether this only occurs with trivial inlined functions like this with longer ones (e.g. containing a function call) too.

@michaelwoerister
Copy link
Member

Interesting, the unoptimized IR of the above program does not even contain a function bar()...

; Function Attrs: uwtable
define internal void @_ZN4main20h4bedfa0b9eaa7039jaaE() unnamed_addr #0 {
entry-block:
  %0 = alloca i32
  %let = alloca i32
  store i32 5, i32* %0, !dbg !18 ; <=== no function call 
  %1 = load i32* %0, !dbg !18
  store i32 %1, i32* %let
  ret void, !dbg !20
}

@jdm
Copy link
Contributor Author

jdm commented Mar 5, 2015

Maybe inline(always) is serious about inlining?

@michaelwoerister
Copy link
Member

Yeah, I need to find out where this inlining happens. Do we do it? Does LLVM do it?

@dotdash
Copy link
Contributor

dotdash commented Mar 5, 2015

Try looking at the .0.noopt.bc file produced by -C save-temps instead
Am 05.03.2015 16:17 schrieb "Josh Matthews" [email protected]:

Maybe inline(always) is serious about inlining?


Reply to this email directly or view it on GitHub
#13442 (comment).

@michaelwoerister
Copy link
Member

@dotdash Good tip!

; Function Attrs: alwaysinline uwtable
define internal i64 @_ZN3bar20h4b0789288b21a387eaaE() unnamed_addr #0 {
entry-block:
  ret i64 5, !dbg !19
}

; Function Attrs: uwtable
define internal void @_ZN4main20h0007eb42fb7e75b0jaaE() unnamed_addr #1 {
entry-block:
  %0 = alloca i64
  %let = alloca i64
  %1 = call i64 @_ZN3bar20h4b0789288b21a387eaaE(), !dbg !20
  store i64 %1, i64* %0, !dbg !20
  %2 = load i64* %0, !dbg !20
  store i64 %2, i64* %let
  ret void, !dbg !22
}
...
!19 = !MDLocation(line: 4, scope: !4)
!20 = !MDLocation(line: 7, scope: !21)

This one contains the function but the return statement is described as being on line 4 instead of line 3. That's definitely wrong.
Making it an actual return statement fixes that, kind of:

; Function Attrs: alwaysinline uwtable
define internal i64 @_ZN3bar20he4086b460583a695eaaE() unnamed_addr #0 {
entry-block:
  br label %return, !dbg !19

return:                                           ; preds = %entry-block
  ret i64 5, !dbg !21
}
...
!19 = !MDLocation(line: 3, scope: !20)
!21 = !MDLocation(line: 4, scope: !4)

The outcome is still wrong though.

@brson brson added I-wrong T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 22, 2016
@brson
Copy link
Contributor

brson commented Sep 22, 2016

Nominating to prioritize.

@michaelwoerister michaelwoerister self-assigned this Sep 22, 2016
@nikomatsakis
Copy link
Contributor

triage: P-medium

@rust-highfive rust-highfive added P-medium Medium priority and removed I-nominated labels Sep 22, 2016
@pnkfelix
Copy link
Member

@michaelwoerister FYI this still seems to reproduce today, I think.

@Mark-Simulacrum
Copy link
Member

Appears to still reproduce today.

(gdb) break test.rs:3
Breakpoint 1 at 0x8924: file test.rs, line 3.
(gdb) r
Starting program: test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, test::main () at test.rs:7
7	    let _ = bar();

@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jul 21, 2017
@myrfy001
Copy link

myrfy001 commented Apr 2, 2022

it seems that still can't set breakpoint in inlined functions now

@bors bors closed this as completed in 7741e3d Oct 27, 2022
@jdm
Copy link
Contributor Author

jdm commented Oct 27, 2022

I believe this issue was closed incorrectly. 7741e3d does not appear to have anything to do with it.

@michaelwoerister
Copy link
Member

Indeed!

flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 3, 2024
Add reasons for or remove some `//@no-rustfix` annotations

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants