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

Trouble calling a function from a debugger #12868

Closed
alexcrichton opened this issue Mar 13, 2014 · 10 comments
Closed

Trouble calling a function from a debugger #12868

alexcrichton opened this issue Mar 13, 2014 · 10 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug.

Comments

@alexcrichton
Copy link
Member

Output of a session of mine:

fn factorial(x: int) -> int {
    if x <= 0 { 1 } else { x * factorial(x - 1) }
}

fn main() {
    let x = 4;
    println!("{}", factorial(x));
}
$ rustc -g inspect.rs  
$ lldb ./inspect        
Current executable set to './inspect' (x86_64).
(lldb) b main
Breakpoint 1: 2 locations.
(lldb) r
Process 45203 launched: './inspect' (x86_64)
Process 45203 stopped
* thread #1: tid = 0x370ce1, 0x0000000100001780 inspect`main, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2
    frame #0: 0x0000000100001780 inspect`main
inspect`main:
-> 0x100001780:  cmpq   %gs:0x330, %rsp
   0x100001789:  ja     0x1000017a5               ; main + 37
   0x10000178b:  movabsq $0x18, %r10
   0x100001795:  movabsq $0x0, %r11
(lldb) c
Process 45203 resuming
Process 45203 stopped
* thread #2: tid = 0x370cf7, 0x00000001000016b4 inspect`inspect::main + 52 at inspect.rs:6, stop reason = breakpoint 1.1
    frame #0: 0x00000001000016b4 inspect`inspect::main + 52 at inspect.rs:6
   3    }
   4   
   5    fn main() {
-> 6        let x = 4;
   7        println!("{}", factorial(x));
   8    }
(lldb) print factorial(5)
Error [IRForTarget]: Size of result type 'long (long)' couldn't be determined
error: warning: function 'factorial' has internal linkage but is not defined
note: used here
error: The expression could not be prepared to run in the target
(lldb) 

cc @michaelwoerister

@alexcrichton
Copy link
Member Author

I'm not sure if this is the fault of some debuginfo, or possibly that the default OSX lldb is a little out of date. Some other things that I did:

// lldb thinks it's returning a function, so call it again!
(lldb) print factorial(4)(3)
zsh: segmentation fault  lldb ./inspect

// cast the return value to an integer.
(lldb) print (long) factorial(4)
Instruction returns a non-scalar type!
  %9 = call i64 (i64) inttoptr (i64 4294972928 to i64 (i64) (i64)*)(i64 4), !lldb.call.realName !9
PtrToInt source must be pointer
  %10 = ptrtoint i64 (i64) %9 to i64
Broken module found, compilation aborted!
zsh: abort      lldb ./inspect

@alexcrichton
Copy link
Member Author

This may also be an lldb bug, I'm unsure

@jdm
Copy link
Contributor

jdm commented Mar 13, 2014

If Rust is still dealing with return values through an outparam, DWARF does not appear to have a way to represent that. Function return values in gdb are always meaningless.

@thestinger
Copy link
Contributor

Rust only uses an out parameter for what it calls non-immediate types. An int is an immediate type.

@michaelwoerister
Copy link
Member

Mind that calling functions in the debugger is explicitly not supported at the moment. This will definitely be interesting in the future but it isn't a high priority right now.

@steveklabnik
Copy link
Member

Triage: today, a different error:

(lldb) print factorial(5)
error: warning: duplicate 'signed' declaration specifier
error: cannot combine with previous 'unsigned' declaration specifier
error: use of undeclared identifier 'factorial'
error: 2 errors parsing expression

@brson
Copy link
Contributor

brson commented Dec 27, 2016

Updated test

fn factorial(x: isize) -> isize {
    if x <= 0 { 1 } else { x * factorial(x - 1) }
}

fn main() {
    let x = 4;
    println!("{}", factorial(x));
}

It looks to me like the paths in the debugger want to be crate-prefixed today.

Results in gdb on Ubuntu 16.04:

(gdb) print test::factorial(10)
$1 = 3628800
(gdb) print factorial(10)
No symbol "factorial" in current context.
(gdb)

Results in lldb on Ubuntu 16.04:

(lldb) print test::factorial(10)
error: use of undeclared identifier 'test'
error: 1 errors parsing expression
(lldb) print factorial(10)
error: use of undeclared identifier 'factorial'
error: 1 errors parsing expression

@brson brson added I-wrong and removed I-wishlist labels Dec 27, 2016
@xanlpz
Copy link

xanlpz commented Mar 1, 2017

This seems to work fine with current rust?

(gdb) print factorial(4)
$1 = 24
(gdb) print factorial::factorial(4)
$2 = 24
(gdb) 

@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 20, 2017
@sanmai-NL
Copy link

@alexcrichton: This appears to be fixed according to @xanlpz?

@alexcrichton
Copy link
Member Author

Ok!

fasterthanlime pushed a commit to fasterthanlime/rust that referenced this issue Jul 26, 2022
flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 13, 2024
chore: fix some comments

 fix some comments

----

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.
Projects
None yet
Development

No branches or pull requests

9 participants