Skip to content

Commit 1ed4f0c

Browse files
authored
Update Graph and DebugServer API (#1)
* Update Graph and DebugServer API * Update DemoApp * Add DebugClientApp * DebugServer + graph/description complete * Update DebugServerMode * Update Package.swift * Add output info area * Update README
1 parent 1f21754 commit 1ed4f0c

19 files changed

+630
-54
lines changed

Package.resolved

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@ let package = Package(
1717
.library(name: "AGDebugKit", targets: ["AGDebugKit"]),
1818
],
1919
dependencies: [
20-
.package(url: "https://github.com/OpenSwiftUIProject/OpenGraph.git", from: "0.0.1"),
20+
.package(url: "https://github.com/OpenSwiftUIProject/OpenGraph.git", from: "0.0.3"),
21+
.package(url: "https://github.com/OpenSwiftUIProject/Socket.git", from: "0.3.3"),
2122
],
2223
targets: [
23-
.executableTarget(
24-
name: "DemoApp",
25-
dependencies: [
26-
"AGDebugKit"
27-
]
28-
),
2924
.target(
3025
name: "AGDebugKit",
3126
dependencies: [
@@ -35,6 +30,21 @@ let package = Package(
3530
.enableExperimentalFeature("AccessLevelOnImport"),
3631
]
3732
),
33+
// A demo app showing how to use AGDebugKit
34+
.executableTarget(
35+
name: "DemoApp",
36+
dependencies: [
37+
"AGDebugKit",
38+
]
39+
),
40+
// A client sending command to AGDebugServer
41+
.executableTarget(
42+
name: "DebugClient",
43+
dependencies: [
44+
"AGDebugKit",
45+
.product(name: "Socket", package: "Socket"),
46+
]
47+
),
3848
.testTarget(
3949
name: "AGDebugKitTests",
4050
dependencies: ["AGDebugKit"]

README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@
22

33
A package to get debug information from the private AttributeGraph framework behind SwiftUI.
44

5-
For visualization the JSON result, see [GraphConverter](https://github.com/OpenSwiftUIProject/GraphConverter)
5+
If you need JSON result visualization, you can refer to [GraphConverter](https://github.com/OpenSwiftUIProject/GraphConverter)
66

7-
For SwiftUI debug information, see [SwiftUIViewDebug](https://github.com/OpenSwiftUIProject/SwiftUIViewDebug)
7+
If you need SwiftUI debug information, you can refer to [SwiftUIViewDebug](https://github.com/OpenSwiftUIProject/SwiftUIViewDebug)
88

99
## Example
1010

11-
![Demo App](Resources/demo_app.png)
11+
![Demo App Console](Resources/demo_app.png)
1212

13-
![Demo JSON](Resources/demo_json.png)
13+
![Demo App Screenshot](Resources/demo_app_2.png)
1414

15-
## TODO
15+
![Demo JSON](Resources/demo_json.png)
1616

17-
- [ ] AGDescriptionFormat
18-
- [ ] AGGraphGetAttributeGraph
19-
- [ ] AGGraphDescription
20-
- [ ] AGGraphCreate
21-
- [ ] AGDebugServer
17+
![Debug Client Screenshot](Resources/debug_client.png)

Resources/debug_client.png

137 KB
Loading

Resources/demo_app_2.png

95.1 KB
Loading

Sources/AGDebugKit/AGDebugKit.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// DebugServer.swift
3+
//
4+
//
5+
// Created by Kyle on 2024/1/21.
6+
//
7+
8+
private import AttributeGraph
9+
import Foundation
10+
11+
public final class DebugServer {
12+
private var server: UnsafeRawPointer?
13+
14+
public static let shared = DebugServer()
15+
16+
public func start(_ mode: Mode = .local) {
17+
server = debugServerStart(mode.rawValue)
18+
}
19+
20+
public func stop() {
21+
debugServerStop()
22+
server = nil
23+
}
24+
25+
public func run(timeout: Int) {
26+
guard let _ = server else { return }
27+
debugServerRun(timeout)
28+
}
29+
30+
public var url: URL? {
31+
guard let _ = server,
32+
let url = debugServerCopyURL() as? URL
33+
else { return nil }
34+
return url
35+
}
36+
37+
/// A Bool value indicating whether the server has been started successfully
38+
///
39+
/// To make AttributeGraph start debugServer successfully, we need to pass its internal diagnostics check.
40+
/// In debug mode, add a symbolic breakpoint on `_ZN2AG11DebugServer5startEj`, run `start(_:)` and
41+
/// executable `reg write w0 1` after `os_variant_has_internal_diagnostics` call.
42+
public var startSuccess: Bool {
43+
server != nil
44+
}
45+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// DebugServerCommand.swift
3+
//
4+
//
5+
// Created by Kyle on 2024/1/22.
6+
//
7+
8+
extension DebugServer {
9+
public enum Command: String, CaseIterable, Hashable, Identifiable {
10+
case graphDescription = "graph/description"
11+
case profilerStart = "profiler/start"
12+
case profilerStop = "profiler/stop"
13+
case profilerReset = "profiler/reset"
14+
case profilerMark = "profiler/mark"
15+
16+
public var id: String { rawValue }
17+
}
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// DebugServerMessageHeader.swift
3+
//
4+
//
5+
// Created by Kyle on 2024/1/22.
6+
//
7+
8+
extension DebugServer {
9+
public struct MessageHeader: Codable {
10+
public var token: UInt32
11+
public var reserved: UInt32
12+
public var length: UInt32
13+
public var reserved2: UInt32
14+
public init(token: UInt32, length: UInt32) {
15+
self.token = token
16+
self.reserved = 0
17+
self.length = length
18+
self.reserved2 = 0
19+
}
20+
21+
public static var size: Int { MemoryLayout<Self>.size }
22+
}
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// DebugServerMode.swift
3+
//
4+
//
5+
// Created by Kyle on 2024/1/22.
6+
//
7+
8+
extension DebugServer {
9+
/// The run mode of DebugServer
10+
///
11+
public struct Mode: RawRepresentable, Hashable {
12+
public let rawValue: UInt
13+
14+
public init(rawValue: UInt) {
15+
self.rawValue = rawValue
16+
}
17+
18+
/// Localhost mode: example host is `127.0.0.1`
19+
public static let local = Mode(rawValue: 1)
20+
21+
/// Network mode: example host is `192.168.8.230`
22+
public static let network = Mode(rawValue: 3)
23+
}
24+
}

0 commit comments

Comments
 (0)