-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_command.py
40 lines (35 loc) · 1.6 KB
/
send_command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import lldb
import asyncio
def send_visual(debugger, var_name, result, internal_dict):
debugger = lldb.debugger.GetCommandInterpreter()
output = expr(debugger, """import Darwin
let _encoder: JSONEncoder = JSONEncoder()
_encoder.outputFormatting = .prettyPrinted
let _data: Data = try _encoder.encode({name})
let _string: String = String(data: _data, encoding: .utf8)!
let _type: Any.Type = type(of: {name})
let _pointer = UnsafeRawPointer(bitPattern: unsafeBitCast(_type, to: Int.self))
var _info = Dl_info()
dladdr(_pointer, &_info)
let _fileName = String(cString: _info.dli_fname)
let _mangledName = String(cString: _info.dli_sname)
let _processPID = ProcessInfo.processInfo.processIdentifier
let _dict = ["pid": String(_processPID), "fileName": _fileName, "mangledName": _mangledName, "data": _string]
String(data: JSONEncoder().encode(_dict), encoding: .utf8)!
""".format(name=var_name))
asyncio.run(send(output))
def expr(debugger, cmd):
cmd = 'po ' + ';'.join(cmd.split('\n')) # unclear if this is necessary, but was the only way I could get it to work
result = lldb.SBCommandReturnObject()
debugger.HandleCommand(cmd, result)
if result.Succeeded():
return result.GetOutput()
else:
print(result.GetError())
raise
async def send(message):
_, writer = await asyncio.open_connection('localhost', 7001)
writer.write(message.encode())
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('command script add -f send_command.send_visual send_visual')
print('The "send_visual" python command has been installed and is ready for use.')