# LLDB: Print valued returned by a function

**URL:** <https://forums.swift.org/t/lldb-print-valued-returned-by-a-function/68416>\
**Category:** LLDB\
**Tags:** debugging, lldb\
**Created:** [November 12, 2023, 9:47pm UTC](https://forums.swift.org/t/lldb-print-valued-returned-by-a-function/68416 "2023-11-12T21:47:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexanderM](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alexanderm/32/9781_2.png) [@AlexanderM](https://forums.swift.org/u/AlexanderM)\
**Post date:** [November 12, 2023, 9:47pm UTC](https://forums.swift.org/t/lldb-print-valued-returned-by-a-function/68416/1 "2023-11-12T21:47:33Z")

</div>

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

 ![image](https://global.discourse-cdn.com/swift/original/3X/9/5/95b49b83095d645c0cbeec5ad63eb1f0a7af60ac.png)

It appears that this behaviour isn't available in Swift. I wasn't able to find any related issues on the [Swift repo](https://github.com/apple/swift), or [Apple's fork of LLVM](https://github.com/apple/llvm-project).

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:

```swift
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
}
```

---

<div class="post-metadata">

**Author:** ![AlexanderM](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alexanderm/32/9781_2.png) [@AlexanderM](https://forums.swift.org/u/AlexanderM)\
**Post date:** [November 12, 2023, 9:54pm UTC](https://forums.swift.org/t/lldb-print-valued-returned-by-a-function/68416/2 "2023-11-12T21:54:59Z")

</div>

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`:

```python
>>> lldb.thread.return_value
No value

```

---

<div class="post-metadata">

**Author:** ![Adrian\_Prantl](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adrian_prantl/32/1582_2.png) [@Adrian\_Prantl](https://forums.swift.org/u/Adrian_Prantl)\
**Post date:** [November 12, 2023, 11:56pm UTC](https://forums.swift.org/t/lldb-print-valued-returned-by-a-function/68416/3 "2023-11-12T23:56:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AlexanderM](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alexanderm/32/9781_2.png) [@AlexanderM](https://forums.swift.org/u/AlexanderM)\
**Post date:** [November 13, 2023, 1:48am UTC](https://forums.swift.org/t/lldb-print-valued-returned-by-a-function/68416/4 "2023-11-13T01:48:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Adrian\_Prantl](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adrian_prantl/32/1582_2.png) [@Adrian\_Prantl](https://forums.swift.org/u/Adrian_Prantl)\
**Post date:** [November 13, 2023, 3:50am UTC](https://forums.swift.org/t/lldb-print-valued-returned-by-a-function/68416/5 "2023-11-13T03:50:04Z")

</div>

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!
