Can the debugger display information for the most derived type?

Whenever I am debugging code, the debugger seems to limit itself to displaying the identify of the object as declared, for example:

class Thing {
func bar () {}
class Animal : Thing {
 var name : String = ""

func dump (t: Thing) { ();

dump (Animal ())

While debugging dump, while the instance is Animal, the debugger can only display the value as a Thing. Is there some way of showing that additional information, or the fact that the object itself is an Animal, or some method that can display at runtime the most derived type.

Try something like po type(of: t) then if you know the type force cast it in llbd, for example po (t as! Animal).

What I am hoping is to get the information without having to probe all the types on my own.

The hierarchy I am dealing with is more extensive, so it is quite cumbersome to print the type for each version. That said, it looks like "po object" is a little more useful than p already. Thanks for that part!

This sounds like a bug. lldb can and should already present values as their most-derived dynamic type:

(lldb) run
Process 7634 launched: '/Users/jgroff/swift/public/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/foo' (x86_64)
Process 7634 stopped
* thread #1, queue = '', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000c9b foo`main() at foo.swift:8:9
   5   	func main() {
   6   	  var x: C = D()
-> 8   	  print(x)
   9   	}
   10  	main()
Target 0: (foo) stopped.
(lldb) p x
(foo.D) $R0 = 0x0000000100f04f80 {
  foo.C = {}
(lldb) fr var x
(foo.D) x = 0x0000000100f04f80 {
  foo.C = {}

So if it isn't in some circumstance, would you have a moment to file a bug report?

I am doing this from Xcode, but will certainly file the bug!

The display looks like this. In this method "self" is of type "Toplevel" which is a subclass of View, but on the debugger display it shows as "View" (I am inside a "View" method right now). Notice on the bottom that using "lldb" there as well shows just the type.

Xcode's debugger support is all driven by lldb under the hood, so I wouldn't expect any difference. Good to know, though. Thanks for filing a bug!

Terms of Service

Privacy Policy

Cookie Policy