Skip to content

Commit 714ce52

Browse files
committed
[swift-inspect] indent RegisterSet.swift
1 parent 21ea119 commit 714ce52

File tree

1 file changed

+52
-53
lines changed

1 file changed

+52
-53
lines changed

tools/swift-inspect/Sources/SwiftInspectLinux/RegisterSet.swift

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,71 @@ import Foundation
22
import LinuxSystemHeaders
33

44
#if arch(arm64)
5-
public typealias RegisterSet = user_pt_regs
5+
public typealias RegisterSet = user_pt_regs
66

7-
extension RegisterSet {
8-
public static var trapInstructionSize: UInt { return 4 } // brk #0x0
7+
extension RegisterSet {
8+
public static var trapInstructionSize: UInt { return 4 } // brk #0x0
99

10-
public func setupCall(
11-
_ ptrace: PTrace, to funcAddr: UInt64, with args: [UInt64], returnTo returnAddr: UInt64
12-
) throws -> RegisterSet {
13-
precondition(args.count <= 6)
14-
var registers = self
15-
registers.regs.0 = args.count > 0 ? args[0] : 0
16-
registers.regs.1 = args.count > 1 ? args[1] : 0
17-
registers.regs.2 = args.count > 2 ? args[2] : 0
18-
registers.regs.3 = args.count > 3 ? args[3] : 0
19-
registers.regs.4 = args.count > 4 ? args[4] : 0
20-
registers.regs.5 = args.count > 5 ? args[5] : 0
21-
registers.pc = funcAddr
22-
registers.regs.30 = returnAddr // link register (x30)
23-
return registers
24-
}
10+
public func setupCall(
11+
_ ptrace: PTrace, to funcAddr: UInt64, with args: [UInt64], returnTo returnAddr: UInt64
12+
) throws -> RegisterSet {
13+
precondition(args.count <= 6)
14+
var registers = self
15+
registers.regs.0 = args.count > 0 ? args[0] : 0
16+
registers.regs.1 = args.count > 1 ? args[1] : 0
17+
registers.regs.2 = args.count > 2 ? args[2] : 0
18+
registers.regs.3 = args.count > 3 ? args[3] : 0
19+
registers.regs.4 = args.count > 4 ? args[4] : 0
20+
registers.regs.5 = args.count > 5 ? args[5] : 0
21+
registers.pc = funcAddr
22+
registers.regs.30 = returnAddr // link register (x30)
23+
return registers
24+
}
2525

26-
public func returnValue() -> UInt64 {
27-
return self.regs.0
28-
}
26+
public func returnValue() -> UInt64 {
27+
return self.regs.0
28+
}
2929

30-
public mutating func step(_ bytes: UInt) {
31-
self.pc += UInt64(bytes)
32-
}
30+
public mutating func step(_ bytes: UInt) {
31+
self.pc += UInt64(bytes)
3332
}
33+
}
3434

3535
#elseif arch(x86_64)
36-
public typealias RegisterSet = pt_regs
37-
38-
extension RegisterSet {
39-
public static var trapInstructionSize: UInt { return 1 } // int3
36+
public typealias RegisterSet = pt_regs
4037

41-
public func setupCall(
42-
_ ptrace: PTrace, to funcAddr: UInt64, with args: [UInt64], returnTo returnAddr: UInt64
43-
) throws -> RegisterSet {
44-
precondition(args.count <= 6)
45-
var registers = self
46-
registers.rdi = UInt(args.count > 0 ? args[0] : 0)
47-
registers.rsi = UInt(args.count > 1 ? args[1] : 0)
48-
registers.rdx = UInt(args.count > 2 ? args[2] : 0)
49-
registers.rcx = UInt(args.count > 3 ? args[3] : 0)
50-
registers.r8 = UInt(args.count > 4 ? args[4] : 0)
51-
registers.r9 = UInt(args.count > 5 ? args[5] : 0)
52-
registers.rip = UInt(funcAddr)
53-
registers.rax = 0 // rax is the number of args in a va_args function
38+
extension RegisterSet {
39+
public static var trapInstructionSize: UInt { return 1 } // int3
5440

55-
// push the return address onto the stack
56-
registers.rsp -= UInt(MemoryLayout<UInt64>.size)
57-
try ptrace.pokeData(addr: UInt64(registers.rsp), value: returnAddr)
41+
public func setupCall(
42+
_ ptrace: PTrace, to funcAddr: UInt64, with args: [UInt64], returnTo returnAddr: UInt64
43+
) throws -> RegisterSet {
44+
precondition(args.count <= 6)
45+
var registers = self
46+
registers.rdi = UInt(args.count > 0 ? args[0] : 0)
47+
registers.rsi = UInt(args.count > 1 ? args[1] : 0)
48+
registers.rdx = UInt(args.count > 2 ? args[2] : 0)
49+
registers.rcx = UInt(args.count > 3 ? args[3] : 0)
50+
registers.r8 = UInt(args.count > 4 ? args[4] : 0)
51+
registers.r9 = UInt(args.count > 5 ? args[5] : 0)
52+
registers.rip = UInt(funcAddr)
53+
registers.rax = 0 // rax is the number of args in a va_args function
5854

59-
return registers
60-
}
55+
// push the return address onto the stack
56+
registers.rsp -= UInt(MemoryLayout<UInt64>.size)
57+
try ptrace.pokeData(addr: UInt64(registers.rsp), value: returnAddr)
6158

62-
public func returnValue() -> UInt64 {
63-
return UInt64(self.rax)
64-
}
59+
return registers
60+
}
6561

66-
public mutating func step(_ bytes: UInt) {
67-
self.rip += UInt(bytes)
68-
}
62+
public func returnValue() -> UInt64 {
63+
return UInt64(self.rax)
6964
}
7065

66+
public mutating func step(_ bytes: UInt) {
67+
self.rip += UInt(bytes)
68+
}
69+
}
7170
#else
72-
#error("Only arm64 and x86_64 architectures are supported")
71+
#error("Only arm64 and x86_64 architectures are supported")
7372
#endif

0 commit comments

Comments
 (0)