Load the original command created in Python into LLDB of Xcode.
Xcode seems to read one of the following two at startup.
Basically it seems that .lldbinit-Xcode
is loaded.
However, since the above is read from the command line etc., if you describe the basic settings in .lldbinit
and put the process to read .lldbinit
in .lldbinit-Xcode
as follows It's okay.
command source ~/.lldbinit
After setting as above, the command will be loaded automatically by setting to read the Python file in .lldbinit
.
command script import ~/.lldb/hoge.py
After setting the reading settings described above, define the contents to be actually read. The main format and required description are as follows.
new-command.py
#!/usr/bin/env python
#coding: utf-8
import lldb
import commands
import os
def command_function(debugger, command, result, internal_dict):
cmd = "po self"
debugger.HandleCommand(cmd)
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand("command script add -f new-command:command_function commandname")
print "commandname has been installed."
After defining it, read it as follows.
(lldb) command script import /path/to/command.py
It is easy to check the operation by setting it inline and executing it for a little operation test.
The following will start the python interpreter.
(lldb) script⏎
Then define as follows and exit the interpreter.
(lldb) script⏎
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> def hoge_function(debugger, command, result, internal_dict):
... cmd = "po self"
... debugger.HandleCommand(cmd)
...
>>> quit⏎
(lldb) command script add hoge -f hoge_func
(lldb) hoge
<UIView...
You can use the placeholder by writing as follows. This is convenient when processing is performed based on the character string specified in the command.
val = "This is %s %s" % ("a", "pen")
# --- or ---
val = "This is %(unit)s %(msg)s" % {"unit": "a", "msg": "pen"}
# --- or ---
val = """This is
%s %s""" % ("a", "pen")
The command is passed as a single string, so use shlex.split
to split it.
command_list = shlex.split(command)
What I wanted to do this time was to create a command that duplicates the view using the specified view size and ʻadd Subview: `to see if the view is properly generated at the desired position. ..
I think it's a bit redundant, but for the time being, it worked if I did the following, so I'll describe it.
#!/usr/bin/env python
# -*- coding: utf-8
import lldb
import commands
import os
import shlex
def dmy_func(debugger, command, result, internal_dict):
commands = shlex.split(command)
count = len(commands)
if count < 2:
return
cmd = "po CGRect $frame = (CGRect)[%s frame]" % commands[0]
print(cmd)
debugger.HandleCommand(cmd)
cmd = "po UIView *$view = [[UIView alloc] initWithFrame:(CGRect)$frame]"
print(cmd)
debugger.HandleCommand(cmd)
cmd = "po [$view setBackgroundColor:(UIColor*)[UIColor redColor]]"
print(cmd)
debugger.HandleCommand(cmd)
cmd = "po [%s addSubview:(UIView*)$view]" % commands[1]
print(cmd)
debugger.HandleCommand(cmd)
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand("command script add -f dmy.dmy_func dmy")
print "dmy command has been installed."
(lldb) dmy self.hogeView self.view
Create a UIView using the frame of self.hogeView
and ʻaddSubview:to
self.view`.
Recommended Posts