Confused about LLDB's "p" and "expr" commands

As I was watching WWDC19 Session: "LLDB: beyond "po" " I got confused about "p" command. In the session there was a following example to show how "p" command works:

// Struct for demonstration purposes
struct Trip {
var name: String
var destinations: [String]

let cruise = Trip (
name: "Mediterranean Cruise"
destinations: ["Sorrento", "Capri", "Taormina"])

Using "p" to get info about cruise instance:

(lldb) p cruise
(Travel.Trip) $R0 = {
name = "Mediterranean Cruise"
destinations = 3 values {
  [0] = "Sorrento"
  [1] = "Capri"
  [2] = "Taormina"
 }
}

I was following along and wrote the same code. But the output from LLDB turned out to be different:

(lldb) p cruise
(LLDB_Apple_Session_FollowAlong.Trip) {
  name = "Mediterranean Cruise"
  destinations = 3 values {
    [0] = "Sorrento"
    [1] = "Capri"
    [2] = "Taormina"
  }
}

As you can see LLDB didn't create a global variable R0 which I could later use in my debugging session and that seemed strange to me.

Then the presenter said the following:

"p" is just an alias for the "expression" command.

So, I tried to use the "expr" command to see if they're actually the same and they turned out to be different commands. The output I got from "expr" was the one I expected from "p":

(lldb) expr cruise
(LLDB_Apple_Session_FollowAlong.Trip) $R0 = {
  name = "Mediterranean Cruise"
  destinations = 3 values {
    [0] = "Sorrento"
    [1] = "Capri"
    [2] = "Taormina"
  }
}

Finally, my question is:

Am I wrong somewhere or did something change in LLDB regarding "p" and "expr" commands and if so, where could I get more information about the changes?

Accepted Reply

You are not wrong, something did change - "The p and po command aliases have been redefined to the new dwim-print command."

More info here https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes

in the section "Debugging, New Features", or search for dwim-print, or scroll through the whole thing

  • Thank you very much! Just didn't know where to look

Add a Comment

Replies

You are not wrong, something did change - "The p and po command aliases have been redefined to the new dwim-print command."

More info here https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes

in the section "Debugging, New Features", or search for dwim-print, or scroll through the whole thing

  • Thank you very much! Just didn't know where to look

Add a Comment

… and for more details on ‘do what I mean’ print, see WWDC 2023 Session 10226 Debug with structured logging.

Share and Enjoy

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

  • Definitely going to check it out. Thank you!

Add a Comment