Impossible to use $R* variables after `continue` command

I’m trying to use the allocated variables given after p self ($R1 for instance) but after resuming the process and then pausing it again, I cannot access to $R1.

(lldb) p self
(Signals.MainContainerViewController) $R1 = 0x000000012ba19dc0 {
...

(lldb) po $R1
<Signals.MainContainerViewController: 0x12ba19dc0>

(lldb) c
Process 88944 resuming
(lldb) expression -O -l swift -- $R1
warning: Module "/usr/lib/system/libsystem_kernel.dylib" uses triple "arm64-apple-macosx13.4.0", which is not compatible with the target triple "arm64-apple-ios16.0.0-simulator". Enabling per-module Swift scratch context.
error: expression failed to parse:
error: <EXPR>:3:1: error: cannot find '$R1' in scope
$R1
^~~

(lldb) 
Does someone have an idea?

macOS: 13.4.1 (22F82) Xcode Version 14.3.1

I tried outside of Xcode, attaching the debugger to the Notes app:

(lldb) b -[NSView hitTest:]
Breakpoint 1: where = AppKit`-[NSView hitTest:], address = 0x0000000183857e18

(lldb) process launch -e /dev/null --
Process 4125 launched: '/System/Applications/Notes.app/Contents/MacOS/Notes' (arm64e)
Process 4125 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x000000018c093e18 AppKit` -[NSView hitTest:]
AppKit`-[NSView hitTest:]:
->  0x18c093e18 <+0>:  pacibsp
    0x18c093e1c <+4>:  sub    sp, sp, #0x70
    0x18c093e20 <+8>:  stp    x24, x23, [sp, #0x30]
    0x18c093e24 <+12>: stp    x22, x21, [sp, #0x40]
    0x18c093e28 <+16>: stp    x20, x19, [sp, #0x50]
    0x18c093e2c <+20>: stp    x29, x30, [sp, #0x60]
    0x18c093e30 <+24>: add    x29, sp, #0x60
    0x18c093e34 <+28>: mov    x19, x0
Target 0: (Notes) stopped.

(lldb) p $arg1
(unsigned long) $2 = 4312972736
(lldb) po $2
<NSTitlebarContainerView: 0x10112bdc0>

It seems to work in this context.

Edit:


(lldb) b -[NSView hitTest:]

Breakpoint 1: where = AppKit`-[NSView hitTest:], address = 0x0000000183857e18


(lldb) process launch -e /dev/null --

Process 4125 launched: '/System/Applications/Notes.app/Contents/MacOS/Notes' (arm64e)

Process 4125 stopped

* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1

    frame #0: 0x000000018c093e18 AppKit` -[NSView hitTest:]

AppKit`-[NSView hitTest:]:

->  0x18c093e18 <+0>:  pacibsp

    0x18c093e1c <+4>:  sub    sp, sp, #0x70

    0x18c093e20 <+8>:  stp    x24, x23, [sp, #0x30]

    0x18c093e24 <+12>: stp    x22, x21, [sp, #0x40]

    0x18c093e28 <+16>: stp    x20, x19, [sp, #0x50]

    0x18c093e2c <+20>: stp    x29, x30, [sp, #0x60]

    0x18c093e30 <+24>: add    x29, sp, #0x60

    0x18c093e34 <+28>: mov    x19, x0

Target 0: (Notes) stopped.


(lldb) p $arg1

(unsigned long) $2 = 4312972736

(lldb) po $2

<NSTitlebarContainerView: 0x10112bdc0>


(lldb) c

Process 4125 resuming

-- later 

Process 4125 stopped

* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1

    frame #0: 0x000000018c093e18 AppKit` -[NSView hitTest:]

AppKit`-[NSView hitTest:]:

->  0x18c093e18 <+0>:  pacibsp

    0x18c093e1c <+4>:  sub    sp, sp, #0x70

    0x18c093e20 <+8>:  stp    x24, x23, [sp, #0x30]

    0x18c093e24 <+12>: stp    x22, x21, [sp, #0x40]

    0x18c093e28 <+16>: stp    x20, x19, [sp, #0x50]

    0x18c093e2c <+20>: stp    x29, x30, [sp, #0x60]

    0x18c093e30 <+24>: add    x29, sp, #0x60

    0x18c093e34 <+28>: mov    x19, x0

Target 0: (Notes) stopped.

(lldb) po $2

<NSTitlebarContainerView: 0x10112bdc0>

(lldb) c


-- later, after pausing --


(lldb) po $2

<NSTitlebarContainerView: 0x10112bdc0>

This is working for me. Consider tiny command-line tool program:

import Foundation

class Main {
    func run() {
        print("Hello Cruel World!")
    }
}

func main() {
    let m = Main()
    m.run()
    withExtendedLifetime(m) {
        dispatchMain()
    }
}

main()

I set a breakpoint on the first line of run(). I then ran the program and printed self:

(lldb) p self 
(xxst.Main) $R0 = 0x0000600000008030 {}
(lldb) p $R0
(xxst.Main) $R1 = 0x0000600000008030 {}

I continued and, after a second, paused the program again. This command fails:

(lldb) p $R0
error: expression failed to parse:
error: <user expression 0>:1:1: use of undeclared identifier '$R0'
$R0
^

because the language is wrong. But this command works:

(lldb) expression --language swift -- $R0
(xxst.Main) $R2 = 0x0000600000008030 {}

macOS: 13.4.1 (22F82) Xcode Version 14.3.1

Ditto.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi @eskimo 👋

Thank you for this answer.

I tried to reproduce this little project on Xcode but still got into the same trouble.

I recorded my screen and uploaded it here: https://www.youtube.com/watch?v=Cn0VOjU7MJY

Maybe I created the breakpoint in the wrong place?

It seems like we're working through the same book/resource haha.

I'm also seeing this error, but I've found that going up the call stack to get out of libsystem_kernel.dylib brings me back to the right context.

So:

(lldb) expr self
(Signals.MainContainerViewController) $R0 = 0x0000000109f083a0 {
  UIKit.UIViewController = {
     ...
  }
}
(lldb) c
Process 8065 resuming
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x0000000100e04c10 libsystem_kernel.dylib`mach_msg2_trap + 8
    frame #1: 0x0000000100e15da4 libsystem_kernel.dylib`mach_msg2_internal + 76
    frame #2: 0x0000000100e0ce34 libsystem_kernel.dylib`mach_msg_overwrite + 532
    frame #3: 0x0000000100e04f88 libsystem_kernel.dylib`mach_msg + 20
    frame #4: 0x00000001803c5ed8 CoreFoundation`__CFRunLoopServiceMachPort + 156
    ...
(lldb) up 4
frame #4: 0x00000001803c5ed8 CoreFoundation`__CFRunLoopServiceMachPort + 156
CoreFoundation`:
->  0x1803c5ed8 <+156>: mov    x26, x0
    0x1803c5edc <+160>: ldr    x0, [x22]
    0x1803c5ee0 <+164>: bl     0x1804f5080               ; symbol stub for: voucher_mach_msg_revert
    0x1803c5ee4 <+168>: mov    x0, x25
(lldb) expr -l swift -- $R0
(Signals.MainContainerViewController) $R1 = 0x0000000109f083a0 {
  UIKit.UIViewController = {
     ...
  }
}

The warning definitely has something to do with it (my exact warning is slightly different given I'm running the OSX 14 Beta):

warning: Module "/usr/lib/system/libsystem_kernel.dylib" uses triple "arm64-apple-macosx14.0.0", which is not compatible with the target triple "arm64-apple-ios16.0.0-simulator". Enabling per-module Swift scratch context.
Impossible to use $R* variables after `continue` command
 
 
Q