Skip to content

gdb has the wrong source location with many macros #18285

Closed
@alexcrichton

Description

@alexcrichton
Member
#![feature(macro_rules)]                             

macro_rules! call2( ($e:expr) => ($e()) )            
macro_rules! call( ($e:expr) => (handle(call2!($e))) )

fn bar() {                                           
    unsafe {                                         
        *(0 as *mut uint) = 0;                       
    }                                                
}                                                    

fn foo() {                                           
    call!(bar);                                      
}                                                    

fn handle(_:()) {}                                   

fn main() {                                          
    foo();                                           
}                                                    
$ rustc foo.rs -g
$ gdb ./foo
GNU gdb (Ubuntu 7.7-0ubuntu3.1) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./main...done.
(gdb) r
Starting program: /home/alex/code/foobar/main 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
main::bar () at src/main.rs:8
8               *(0 as *mut uint) = 0;
(gdb) bt
#0  main::bar () at src/main.rs:8
#1  0x000055555555f32e in main::foo () at src/main.rs:4
#2  0x000055555555f39e in main::main () at src/main.rs:19
#3  0x00005555555950eb in start::closure.8511 ()
#4  0x00005555555acbfc in rust_try_inner ()
#5  0x00005555555acbe6 in rust_try ()
#6  0x00005555555aa533 in unwind::try::hd12740a912640cc1imd ()
#7  0x00005555555aa3fc in task::Task::run::ha62f1c0aea75bedcWBc ()
#8  0x0000555555594f27 in start::h239c3a425c3165f7ehe ()
#9  0x0000555555594d68 in lang_start::hb36b8d7630529d77xge ()
#10 0x000055555555f3ef in main ()

The line number for the stack frame of main::foo says it's on line 4, when it should actually be lower than that. I have noticed, however, that if there's only one macro (e.g. call2 goes away) the source location is correct. This may be a bug in debuginfo, but it may also be a bug in macros in general (source locations aren't always quite correct I think).

cc @michaelwoerister

Activity

added
A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)
on Oct 24, 2014
michaelwoerister

michaelwoerister commented on Mar 26, 2015

@michaelwoerister
Member

Might be related to #23480.

aij

aij commented on Jul 10, 2015

@aij
Contributor

This bug makes debugging errors returned through try! really annoying.

huonw

huonw commented on Nov 18, 2015

@huonw
Member
added
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
on Jan 5, 2016
jethrogb

jethrogb commented on Nov 15, 2016

@jethrogb
Contributor

Will this magically get fixed when #23480 is fixed?

jseyfried

jseyfried commented on Feb 8, 2017

@jseyfried
Contributor

Yeah, this looks like a consequence of #23480 / #39450.
This should be fixed by span reform along the road to declarative macros 2.0.

self-assigned this
on Feb 8, 2017
Arthamys

Arthamys commented on Aug 17, 2019

@Arthamys

This seems to be fixed, at least from my test running the same source with rustc 1.37

Source locations are valid for both call sites.

GNU gdb (GDB) 8.3
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from ./test_macro...
    (gdb) run
    Starting program: /home/san/projects/rust/playground/test_macro
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/usr/lib/libthread_db.so.1".

    Program received signal SIGSEGV, Segmentation fault.
    main::bar () at src/main.rs:6
    6               *(0 as *mut u32) = 0;
    (gdb) bt
    #0  main::bar () at src/main.rs:6
    #1  0x0000555555558256 in main::foo () at src/main.rs:11
    #2  0x0000555555558276 in main::main () at src/main.rs:17
    (gdb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @alexcrichton@jethrogb@huonw@michaelwoerister@aij

      Issue actions

        gdb has the wrong source location with many macros · Issue #18285 · rust-lang/rust