Symbol breadcrumb

Using Xcode (or Instruments), is there a way to know all the functions/symbols that are touched by a line of code?

struct Test {
    private func intro() {
        
    }
    
    func partOne() {
        intro()
    }
    
    func partTwo() {
        partOne()
    }
    
    func partThree() {
        partTwo()
        print(credits)
    }
    
    private var credits: String {
        ""
    }
}

let test = Test()
test.partTwo() // partTwo, partOne, intro
test.partThree() // partThree, partTwo, partOne, intro, credits
Answered by DTS Engineer in 759840022

There’s no built-in functionality that’ll do that. If you’d like to see that change, I encourage you to file an enhancement request describing your requirements.

Please post your bug number, just for the record.

In the meantime, you might be able to work around this using Xcode’s code coverage support. I’ve not explored the Swift side of this, but in C-based languages the code coverage support works by inserting calls to runtime functions at the beginning and end of each routine. If you replace those runtime functions with your own code, you could build this data yourself.

Share and Enjoy

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

Are you trying to determine this statically? Or at runtime?

This matters because there’s only so far you can go using static analysis, for example, you won’t ‘see’ stuff called via any of the dynamic dispatch mechanisms that Swift supports.

Share and Enjoy

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

At runtime.

For example, if I set test.shouldSkipPartTwo = true

test.partThree() // partThree, shouldSkipPartTwo, credits

Otherwise

test.partThree() // partThree, shouldSkipPartTwo, partTwo, partOne, intro, credits
Accepted Answer

There’s no built-in functionality that’ll do that. If you’d like to see that change, I encourage you to file an enhancement request describing your requirements.

Please post your bug number, just for the record.

In the meantime, you might be able to work around this using Xcode’s code coverage support. I’ve not explored the Swift side of this, but in C-based languages the code coverage support works by inserting calls to runtime functions at the beginning and end of each routine. If you replace those runtime functions with your own code, you could build this data yourself.

Share and Enjoy

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

Symbol breadcrumb
 
 
Q