LLDB: Print valued returned by a function

LLDB supports printing the return value of a function. Here's an example in Xcode, on a simple C project:

It appears that this behaviour isn't available in Swift. I wasn't able to find any related issues on the Swift repo, or Apple's fork of LLVM.

Has this been looked into before? Is there any reason why it can't be done, or would be difficult?.

I find this feature really useful, to prevent needing to write smelly code like:

func add(_ a: Int, _ b: Int) -> Int {
    // I don't actually want this useless variable,
    // but I add it in just for debugging.
	let result = a + b
    return result

Interesting to note: this value is only set on a "step out".

You can "step over" the return a + b; line, which will take you to the caller, but without setting lldb.thread.return_value:

>>> lldb.thread.return_value
No value
1 Like

IIRC, this is a known issue. LLDB currently doesn't know enough about the Swift calling convention to know where to find the return value of a Swift function. Unfortunately the calling convention details in LLVM are not neatly organized into a TableGen file but rather spread out over a few thousand lines of code so fixing this is a non-trivial amount of work.

Ahhh I see. Do you know if there’s an open issue for this? If not, I can open one.

Though by the sounds of it, don’t think that’s something I could take in without significant help.

I’m sure there’s no GitHub issue for it. I’d be excited to help you if you are interested in taking this on!