Skip to content

Trouble calling a function from a debugger #12868

Closed
@alexcrichton

Description

@alexcrichton
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

Activity

alexcrichton

alexcrichton commented on Mar 13, 2014

@alexcrichton
MemberAuthor

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

alexcrichton commented on Mar 13, 2014

@alexcrichton
MemberAuthor

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

jdm

jdm commented on Mar 13, 2014

@jdm
Contributor

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

thestinger commented on Mar 13, 2014

@thestinger
Contributor

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

michaelwoerister

michaelwoerister commented on Mar 14, 2014

@michaelwoerister
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

steveklabnik commented on Apr 20, 2015

@steveklabnik
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

brson commented on Dec 27, 2016

@brson
Contributor

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
xanlpz

xanlpz commented on Mar 1, 2017

@xanlpz

This seems to work fine with current rust?

(gdb) print factorial(4)
$1 = 24
(gdb) print factorial::factorial(4)
$2 = 24
(gdb) 
added
C-bugCategory: This is a bug.
and removed
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jul 20, 2017
sanmai-NL

sanmai-NL commented on Oct 20, 2017

@sanmai-NL

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

alexcrichton

alexcrichton commented on Oct 20, 2017

@alexcrichton
MemberAuthor

Ok!

added a commit that references this issue on Jul 26, 2022

Auto merge of rust-lang#12868 - lowr:follow-up-on-12832, r=lnicola

added a commit that references this issue on Jun 13, 2024

Auto merge of rust-lang#12868 - VitalikButerinEth:master, r=llogiq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)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

        @jdm@steveklabnik@alexcrichton@brson@thestinger

        Issue actions

          Trouble calling a function from a debugger · Issue #12868 · rust-lang/rust