Ok, last commit for the running processes in a new window. Now you can

optionally specify the tty you want to use if you want to use an existing
terminal window by giving a partial or full path name:

(lldb) process launch --tty=ttys002

This would find the terminal window (or tab on MacOSX) that has ttys002 in its
tty path and use it. If it isn't found, it will use a new terminal window.

llvm-svn: 116878
This commit is contained in:
Greg Clayton 2010-10-19 23:16:00 +00:00
parent c81155eef7
commit 913c4fa15b
3 changed files with 62 additions and 15 deletions

View File

@ -310,7 +310,8 @@ public:
LaunchApplication (const FileSpec &app_file_spec); LaunchApplication (const FileSpec &app_file_spec);
static lldb::pid_t static lldb::pid_t
LaunchInNewTerminal (const char **argv, // argv[0] is executable LaunchInNewTerminal (const char *tty_name, // Optional partial or full tty name ("/dev/ttys000" or "ttys000")
const char **argv, // argv[0] is executable
const char **envp, const char **envp,
const ArchSpec *arch_spec, const ArchSpec *arch_spec,
bool stop_at_entry, bool stop_at_entry,

View File

@ -62,7 +62,11 @@ public:
case 'i': stdin_path = option_arg; break; case 'i': stdin_path = option_arg; break;
case 'o': stdout_path = option_arg; break; case 'o': stdout_path = option_arg; break;
case 'p': plugin_name = option_arg; break; case 'p': plugin_name = option_arg; break;
case 't': in_new_tty = true; break; case 't':
if (option_arg && option_arg[0])
tty_name.assign (option_arg);
in_new_tty = true;
break;
default: default:
error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
break; break;
@ -77,6 +81,7 @@ public:
Options::ResetOptionValues(); Options::ResetOptionValues();
stop_at_entry = false; stop_at_entry = false;
in_new_tty = false; in_new_tty = false;
tty_name.clear();
stdin_path.clear(); stdin_path.clear();
stdout_path.clear(); stdout_path.clear();
stderr_path.clear(); stderr_path.clear();
@ -97,6 +102,7 @@ public:
bool stop_at_entry; bool stop_at_entry;
bool in_new_tty; bool in_new_tty;
std::string tty_name;
std::string stderr_path; std::string stderr_path;
std::string stdin_path; std::string stdin_path;
std::string stdout_path; std::string stdout_path;
@ -216,7 +222,8 @@ public:
if (m_options.in_new_tty) if (m_options.in_new_tty)
{ {
lldb::pid_t pid = Host::LaunchInNewTerminal (inferior_argv, lldb::pid_t pid = Host::LaunchInNewTerminal (m_options.tty_name.c_str(),
inferior_argv,
inferior_envp, inferior_envp,
&exe_module->GetArchitecture(), &exe_module->GetArchitecture(),
true, true,
@ -322,7 +329,7 @@ CommandObjectProcessLaunch::CommandOptions::g_option_table[] =
{ SET1 , false, "stdout", 'o', required_argument, NULL, 0, eArgTypePath, "Redirect stdout for the process to <path>."}, { SET1 , false, "stdout", 'o', required_argument, NULL, 0, eArgTypePath, "Redirect stdout for the process to <path>."},
{ SET1 , false, "stderr", 'e', required_argument, NULL, 0, eArgTypePath, "Redirect stderr for the process to <path>."}, { SET1 , false, "stderr", 'e', required_argument, NULL, 0, eArgTypePath, "Redirect stderr for the process to <path>."},
{ SET1 | SET2, false, "plugin", 'p', required_argument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, { SET1 | SET2, false, "plugin", 'p', required_argument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."},
{ SET2, false, "tty", 't', no_argument, NULL, 0, eArgTypeNone, "Start the process in a new terminal (tty)."}, { SET2, false, "tty", 't', optional_argument, NULL, 0, eArgTypePath, "Start the process in a terminal. If <path> is specified, look for a terminal whose name contains <path>, else start the process in a new terminal."},
{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
}; };

View File

@ -369,10 +369,35 @@ LaunchInNewTerminalWithCommandFile
return pid; return pid;
} }
const char *applscript_in_new_tty =
"tell application \"Terminal\"\n"
" do script \"%s\"\n"
"end tell\n";
const char *applscript_in_existing_tty = "\
set the_shell_script to \"%s\"\n\
tell application \"Terminal\"\n\
repeat with the_window in (get windows)\n\
repeat with the_tab in tabs of the_window\n\
set the_tty to tty in the_tab\n\
if the_tty contains \"%s\" then\n\
if the_tab is not busy then\n\
set selected of the_tab to true\n\
set frontmost of the_window to true\n\
do script the_shell_script in the_tab\n\
return\n\
end if\n\
end if\n\
end repeat\n\
end repeat\n\
do script the_shell_script\n\
end tell\n";
lldb::pid_t lldb::pid_t
LaunchInNewTerminalWithAppleScript LaunchInNewTerminalWithAppleScript
( (
const char *tty_name,
const char **argv, const char **argv,
const char **envp, const char **envp,
const ArchSpec *arch_spec, const ArchSpec *arch_spec,
@ -392,7 +417,6 @@ LaunchInNewTerminalWithAppleScript
unix_socket_name.assign (temp_file_path); unix_socket_name.assign (temp_file_path);
StreamString command; StreamString command;
FileSpec darwin_debug_file_spec; FileSpec darwin_debug_file_spec;
if (!Host::GetLLDBPath (ePathTypeSupportExecutableDir, darwin_debug_file_spec)) if (!Host::GetLLDBPath (ePathTypeSupportExecutableDir, darwin_debug_file_spec))
return LLDB_INVALID_PROCESS_ID; return LLDB_INVALID_PROCESS_ID;
@ -403,19 +427,14 @@ LaunchInNewTerminalWithAppleScript
char launcher_path[PATH_MAX]; char launcher_path[PATH_MAX];
darwin_debug_file_spec.GetPath(launcher_path, sizeof(launcher_path)); darwin_debug_file_spec.GetPath(launcher_path, sizeof(launcher_path));
command.Printf ("tell application \"Terminal\"\n do script \"'%s'", launcher_path);
command.Printf("'%s' --unix-socket=%s", launcher_path, unix_socket_name.c_str());
command.Printf(" --unix-socket=%s", unix_socket_name.c_str());
if (arch_spec && arch_spec->IsValid()) if (arch_spec && arch_spec->IsValid())
{
command.Printf(" --arch=%s", arch_spec->AsCString()); command.Printf(" --arch=%s", arch_spec->AsCString());
}
if (disable_aslr) if (disable_aslr)
{
command.PutCString(" --disable-aslr"); command.PutCString(" --disable-aslr");
}
command.PutCString(" --"); command.PutCString(" --");
@ -426,8 +445,26 @@ LaunchInNewTerminalWithAppleScript
command.Printf(" '%s'", argv[i]); command.Printf(" '%s'", argv[i]);
} }
} }
command.PutCString (" ; echo Process exited with status $?\"\nend tell\n"); command.PutCString (" ; echo Process exited with status $?");
const char *script_source = command.GetString().c_str();
StreamString applescript_source;
if (tty_name && tty_name[0])
{
applescript_source.Printf (applscript_in_existing_tty,
command.GetString().c_str(),
tty_name);
}
else
{
applescript_source.Printf (applscript_in_new_tty,
command.GetString().c_str());
}
const char *script_source = applescript_source.GetString().c_str();
//puts (script_source);
NSAppleScript* applescript = [[NSAppleScript alloc] initWithSource:[NSString stringWithCString:script_source encoding:NSUTF8StringEncoding]]; NSAppleScript* applescript = [[NSAppleScript alloc] initWithSource:[NSString stringWithCString:script_source encoding:NSUTF8StringEncoding]];
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
@ -461,6 +498,7 @@ LaunchInNewTerminalWithAppleScript
WaitForProcessToSIGSTOP (pid, 5); WaitForProcessToSIGSTOP (pid, 5);
} }
} }
::unlink (unix_socket_name.c_str());
[applescript release]; [applescript release];
return pid; return pid;
} }
@ -471,6 +509,7 @@ LaunchInNewTerminalWithAppleScript
lldb::pid_t lldb::pid_t
Host::LaunchInNewTerminal Host::LaunchInNewTerminal
( (
const char *tty_name,
const char **argv, const char **argv,
const char **envp, const char **envp,
const ArchSpec *arch_spec, const ArchSpec *arch_spec,
@ -479,7 +518,7 @@ Host::LaunchInNewTerminal
) )
{ {
#if defined (LLDB_HOST_USE_APPLESCRIPT) #if defined (LLDB_HOST_USE_APPLESCRIPT)
return LaunchInNewTerminalWithAppleScript (argv, envp, arch_spec, stop_at_entry, disable_aslr); return LaunchInNewTerminalWithAppleScript (tty_name, argv, envp, arch_spec, stop_at_entry, disable_aslr);
#else #else
return LaunchInNewTerminalWithCommandFile (argv, envp, arch_spec, stop_at_entry, disable_aslr); return LaunchInNewTerminalWithCommandFile (argv, envp, arch_spec, stop_at_entry, disable_aslr);
#endif #endif