fixed the lauch using python
This commit is contained in:
parent
b796b70e29
commit
b4f91912ee
208
ios-deploy.c
208
ios-deploy.c
@ -19,7 +19,6 @@
|
|||||||
#define APP_VERSION "1.2.2"
|
#define APP_VERSION "1.2.2"
|
||||||
#define PREP_CMDS_PATH "/tmp/fruitstrap-lldb-prep-cmds-"
|
#define PREP_CMDS_PATH "/tmp/fruitstrap-lldb-prep-cmds-"
|
||||||
#define LLDB_SHELL "lldb -s " PREP_CMDS_PATH
|
#define LLDB_SHELL "lldb -s " PREP_CMDS_PATH
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Startup script passed to lldb.
|
* Startup script passed to lldb.
|
||||||
* To see how xcode interacts with lldb, put this into .lldbinit:
|
* To see how xcode interacts with lldb, put this into .lldbinit:
|
||||||
@ -102,7 +101,19 @@ def run_command(debugger, command, result, internal_dict):\n\
|
|||||||
print(str(error))\n\
|
print(str(error))\n\
|
||||||
\n\
|
\n\
|
||||||
def safequit_command(debugger, command, result, internal_dict):\n\
|
def safequit_command(debugger, command, result, internal_dict):\n\
|
||||||
sys.exit(0);\n\
|
process = lldb.target.process\n\
|
||||||
|
listener = debugger.GetListener()\n\
|
||||||
|
listener.StartListeningForEvents(process.GetBroadcaster(), lldb.SBProcess.eBroadcastBitStateChanged | lldb.SBProcess.eBroadcastBitSTDOUT | lldb.SBProcess.eBroadcastBitSTDERR)\n\
|
||||||
|
event = lldb.SBEvent()\n\
|
||||||
|
while True:\n\
|
||||||
|
if listener.WaitForEvent(1, event):\n\
|
||||||
|
state = process.GetStateFromEvent(event)\n\
|
||||||
|
else:\n\
|
||||||
|
state = lldb.eStateInvalid\n\
|
||||||
|
print('\\nin process\\n')\n\
|
||||||
|
print(state)\n\
|
||||||
|
process.Detach()\n\
|
||||||
|
sys.exit(0)\n\
|
||||||
\n\
|
\n\
|
||||||
def autoexit_command(debugger, command, result, internal_dict):\n\
|
def autoexit_command(debugger, command, result, internal_dict):\n\
|
||||||
process = lldb.target.process\n\
|
process = lldb.target.process\n\
|
||||||
@ -972,7 +983,7 @@ void setup_dummy_pipe_on_stdin(int pfd[2]) {
|
|||||||
perror("dup2 failed");
|
perror("dup2 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void launch_debugger(AMDeviceRef device, CFURLRef url) {
|
void setup_lldb(AMDeviceRef device, CFURLRef url) {
|
||||||
CFStringRef device_full_name = get_device_full_name(device),
|
CFStringRef device_full_name = get_device_full_name(device),
|
||||||
device_interface_name = get_device_interface_name(device);
|
device_interface_name = get_device_interface_name(device);
|
||||||
|
|
||||||
@ -1008,6 +1019,10 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
|
|||||||
signal(SIGLLDB, lldb_finished_handler);
|
signal(SIGLLDB, lldb_finished_handler);
|
||||||
|
|
||||||
parent = getpid();
|
parent = getpid();
|
||||||
|
}
|
||||||
|
|
||||||
|
void launch_debugger(AMDeviceRef device, CFURLRef url) {
|
||||||
|
setup_lldb(device, url);
|
||||||
int pid = fork();
|
int pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
signal(SIGHUP, SIG_DFL);
|
signal(SIGHUP, SIG_DFL);
|
||||||
@ -1015,10 +1030,7 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
|
|||||||
child = getpid();
|
child = getpid();
|
||||||
|
|
||||||
int pfd[2] = {-1, -1};
|
int pfd[2] = {-1, -1};
|
||||||
|
if (isatty(STDIN_FILENO))
|
||||||
if (!justlaunch)
|
|
||||||
{
|
|
||||||
if (isatty(STDIN_FILENO) && !justlaunch)
|
|
||||||
// If we are running on a terminal, then we need to bring process to foreground for input
|
// If we are running on a terminal, then we need to bring process to foreground for input
|
||||||
// to work correctly on lldb's end.
|
// to work correctly on lldb's end.
|
||||||
bring_process_to_foreground();
|
bring_process_to_foreground();
|
||||||
@ -1027,7 +1039,7 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
|
|||||||
// "quit". It seems this is caused by read() on stdin returning EOF in lldb. To hack around
|
// "quit". It seems this is caused by read() on stdin returning EOF in lldb. To hack around
|
||||||
// this we setup a dummy pipe on stdin, so read() would block expecting "user's" input.
|
// this we setup a dummy pipe on stdin, so read() would block expecting "user's" input.
|
||||||
setup_dummy_pipe_on_stdin(pfd);
|
setup_dummy_pipe_on_stdin(pfd);
|
||||||
}
|
|
||||||
char lldb_shell[400];
|
char lldb_shell[400];
|
||||||
sprintf(lldb_shell, LLDB_SHELL);
|
sprintf(lldb_shell, LLDB_SHELL);
|
||||||
if(device_id != NULL)
|
if(device_id != NULL)
|
||||||
@ -1039,24 +1051,188 @@ void launch_debugger(AMDeviceRef device, CFURLRef url) {
|
|||||||
|
|
||||||
close(pfd[0]);
|
close(pfd[0]);
|
||||||
close(pfd[1]);
|
close(pfd[1]);
|
||||||
|
|
||||||
// Notify parent we're exiting
|
// Notify parent we're exiting
|
||||||
printf("LLDB: Notifying parent\n");
|
|
||||||
kill(parent, SIGLLDB);
|
kill(parent, SIGLLDB);
|
||||||
// Pass lldb exit code
|
// Pass lldb exit code
|
||||||
_exit(WEXITSTATUS(status));
|
_exit(WEXITSTATUS(status));
|
||||||
} else if (pid > 0) {
|
} else if (pid > 0) {
|
||||||
child = pid;
|
child = pid;
|
||||||
if (justlaunch)
|
|
||||||
{
|
|
||||||
printf("writing detach\n");
|
|
||||||
write(0,"detach\n",7);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
perror("fork failed");
|
perror("fork failed");
|
||||||
exit(exitcode_error);
|
exit(exitcode_error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define USE_SYSTEM 1
|
||||||
|
void launch_debugger_and_exit(AMDeviceRef device, CFURLRef url) {
|
||||||
|
setup_lldb(device,url);
|
||||||
|
#ifdef USE_SYSTEM
|
||||||
|
#define PARENT_READ pfd[0]
|
||||||
|
#define CHILD_WRITE pfd[1]
|
||||||
|
#define CHILD_READ pfd[0]
|
||||||
|
#define PARENT_WRITE pfd[1]
|
||||||
|
|
||||||
|
int pfd[2] = {-1, -1};
|
||||||
|
if (pipe(pfd) == -1)
|
||||||
|
perror("Pipe failed");
|
||||||
|
int pid = fork();
|
||||||
|
if (pid == 0) {
|
||||||
|
signal(SIGHUP, SIG_DFL);
|
||||||
|
signal(SIGLLDB, SIG_DFL);
|
||||||
|
child = getpid();
|
||||||
|
|
||||||
|
//close(pfd[1]);
|
||||||
|
if (dup2(pfd[0],STDIN_FILENO) == -1)
|
||||||
|
perror("dup2 failed");
|
||||||
|
|
||||||
|
char lldb_shell[400];
|
||||||
|
sprintf(lldb_shell, LLDB_SHELL);
|
||||||
|
if(device_id != NULL)
|
||||||
|
strcat(lldb_shell, device_id);
|
||||||
|
|
||||||
|
int status = system(lldb_shell); // launch lldb
|
||||||
|
if (status == -1)
|
||||||
|
perror("failed launching lldb");
|
||||||
|
printf("Done launching\n");
|
||||||
|
|
||||||
|
close(pfd[0]);
|
||||||
|
|
||||||
|
// Notify parent we're exiting
|
||||||
|
kill(parent, SIGLLDB);
|
||||||
|
// Pass lldb exit code
|
||||||
|
_exit(WEXITSTATUS(status));
|
||||||
|
} else if (pid > 0) {
|
||||||
|
child = pid;
|
||||||
|
//char ch;
|
||||||
|
//while(read(pfd[1],&ch,1))
|
||||||
|
// printf("[%c]",ch);
|
||||||
|
} else {
|
||||||
|
perror("fork failed");
|
||||||
|
exit(exitcode_error);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_EXEC
|
||||||
|
#define PARENT_READ pfd[0]
|
||||||
|
#define CHILD_WRITE pfd[1]
|
||||||
|
#define CHILD_READ pfd[0]
|
||||||
|
#define PARENT_WRITE pfd[1]
|
||||||
|
|
||||||
|
int pfd[2] = {-1, -1};
|
||||||
|
if (pipe(pfd) == -1)
|
||||||
|
perror("Pipe failed");
|
||||||
|
int pid = fork();
|
||||||
|
if (pid == 0) {
|
||||||
|
signal(SIGHUP, SIG_DFL);
|
||||||
|
signal(SIGLLDB, SIG_DFL);
|
||||||
|
child = getpid();
|
||||||
|
|
||||||
|
if (dup2(pfd[0],STDIN_FILENO) == -1)
|
||||||
|
perror("dup2 failed");
|
||||||
|
if (dup2(pfd[1],STDOUT_FILENO) == -1)
|
||||||
|
perror("dup2 failed for out");
|
||||||
|
|
||||||
|
char lldb_shell[400];
|
||||||
|
sprintf(lldb_shell, PREP_CMDS_PATH);
|
||||||
|
if(device_id != NULL)
|
||||||
|
strcat(lldb_shell, device_id);
|
||||||
|
|
||||||
|
char *path[4];
|
||||||
|
path[0] = "lldb";
|
||||||
|
path[1] = "-s";
|
||||||
|
path[2] = lldb_shell;
|
||||||
|
path[3] = NULL;
|
||||||
|
|
||||||
|
/* path[0] = "echo";
|
||||||
|
path[1] = "hello";
|
||||||
|
path[2] = NULL;*/
|
||||||
|
int status = execvp(path[0],path);
|
||||||
|
if (status == -1)
|
||||||
|
perror("failed launching lldb");
|
||||||
|
|
||||||
|
close(pfd[0]);
|
||||||
|
close(pfd[1]);
|
||||||
|
|
||||||
|
// Notify parent we're exiting
|
||||||
|
kill(parent, SIGLLDB);
|
||||||
|
// Pass lldb exit code
|
||||||
|
_exit(WEXITSTATUS(status));
|
||||||
|
} else if (pid > 0) {
|
||||||
|
child = pid;
|
||||||
|
char ch;
|
||||||
|
bool eof = false;
|
||||||
|
while (!eof)
|
||||||
|
{
|
||||||
|
int ret = read(pfd[0],&ch,1);
|
||||||
|
printf("%c",ch);
|
||||||
|
}
|
||||||
|
printf("Done");
|
||||||
|
} else {
|
||||||
|
perror("fork failed");
|
||||||
|
exit(exitcode_error);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_PIPE
|
||||||
|
printf("--------USING PIPE------\n");
|
||||||
|
char lldb_shell[400];
|
||||||
|
sprintf(lldb_shell, LLDB_SHELL);
|
||||||
|
if(device_id != NULL)
|
||||||
|
strcat(lldb_shell, device_id);
|
||||||
|
FILE *lldb = popen(lldb_shell, "rw");
|
||||||
|
if (lldb == NULL)
|
||||||
|
perror("failed popen");
|
||||||
|
while (!feof(lldb))
|
||||||
|
{
|
||||||
|
char buffer[128];
|
||||||
|
char *ret = fgets(buffer, 128, lldb);
|
||||||
|
if (!ret)
|
||||||
|
break;
|
||||||
|
printf("%s",ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef SAMEASOTHER
|
||||||
|
int pid = fork();
|
||||||
|
if (pid == 0) {
|
||||||
|
signal(SIGHUP, SIG_DFL);
|
||||||
|
signal(SIGLLDB, SIG_DFL);
|
||||||
|
child = getpid();
|
||||||
|
|
||||||
|
int pfd[2] = {-1, -1};
|
||||||
|
if (isatty(STDIN_FILENO))
|
||||||
|
// If we are running on a terminal, then we need to bring process to foreground for input
|
||||||
|
// to work correctly on lldb's end.
|
||||||
|
bring_process_to_foreground();
|
||||||
|
else
|
||||||
|
// If lldb is running in a non terminal environment, then it freaks out spamming "^D" and
|
||||||
|
// "quit". It seems this is caused by read() on stdin returning EOF in lldb. To hack around
|
||||||
|
// this we setup a dummy pipe on stdin, so read() would block expecting "user's" input.
|
||||||
|
setup_dummy_pipe_on_stdin(pfd);
|
||||||
|
|
||||||
|
char lldb_shell[400];
|
||||||
|
sprintf(lldb_shell, LLDB_SHELL);
|
||||||
|
if(device_id != NULL)
|
||||||
|
strcat(lldb_shell, device_id);
|
||||||
|
|
||||||
|
int status = system(lldb_shell); // launch lldb
|
||||||
|
if (status == -1)
|
||||||
|
perror("failed launching lldb");
|
||||||
|
|
||||||
|
close(pfd[0]);
|
||||||
|
close(pfd[1]);
|
||||||
|
|
||||||
|
// Notify parent we're exiting
|
||||||
|
kill(parent, SIGLLDB);
|
||||||
|
// Pass lldb exit code
|
||||||
|
_exit(WEXITSTATUS(status));
|
||||||
|
} else if (pid > 0) {
|
||||||
|
child = pid;
|
||||||
|
} else {
|
||||||
|
perror("fork failed");
|
||||||
|
exit(exitcode_error);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
CFStringRef get_bundle_id(CFURLRef app_url)
|
CFStringRef get_bundle_id(CFURLRef app_url)
|
||||||
{
|
{
|
||||||
if (app_url == NULL)
|
if (app_url == NULL)
|
||||||
@ -1093,6 +1269,7 @@ CFStringRef get_bundle_id(CFURLRef app_url)
|
|||||||
return bundle_id;
|
return bundle_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void read_dir(service_conn_t afcFd, afc_connection* afc_conn_p, const char* dir,
|
void read_dir(service_conn_t afcFd, afc_connection* afc_conn_p, const char* dir,
|
||||||
void(*callback)(afc_connection *conn,const char *dir,int file))
|
void(*callback)(afc_connection *conn,const char *dir,int file))
|
||||||
{
|
{
|
||||||
@ -1511,6 +1688,9 @@ void handle_device(AMDeviceRef device) {
|
|||||||
if (!debug)
|
if (!debug)
|
||||||
exit(0); // no debug phase
|
exit(0); // no debug phase
|
||||||
|
|
||||||
|
if (justlaunch)
|
||||||
|
launch_debugger_and_exit(device, url);
|
||||||
|
else
|
||||||
launch_debugger(device, url);
|
launch_debugger(device, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user