<div dir="ltr">I assume it was just an accident, but there's no commit message here. What does this change do?</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 30, 2014 at 10:38 AM, Greg Clayton <span dir="ltr"><<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: gclayton<br>
Date: Wed Jul 30 12:38:47 2014<br>
New Revision: 214319<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=214319&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=214319&view=rev</a><br>
Log: (empty)<br>
<br>
Modified:<br>
lldb/trunk/include/lldb/API/SBHostOS.h<br>
lldb/trunk/include/lldb/Host/Host.h<br>
lldb/trunk/include/lldb/lldb-enumerations.h<br>
lldb/trunk/include/lldb/lldb-private-enumerations.h<br>
lldb/trunk/scripts/Python/interface/SBHostOS.i<br>
lldb/trunk/source/API/SBHostOS.cpp<br>
lldb/trunk/source/API/SBStream.cpp<br>
lldb/trunk/source/Commands/CommandObjectProcess.cpp<br>
lldb/trunk/source/Expression/ClangExpressionParser.cpp<br>
lldb/trunk/source/Interpreter/CommandInterpreter.cpp<br>
lldb/trunk/source/Target/Process.cpp<br>
lldb/trunk/tools/driver/Driver.cpp<br>
lldb/trunk/tools/driver/Driver.h<br>
<br>
Modified: lldb/trunk/include/lldb/API/SBHostOS.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBHostOS.h?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBHostOS.h?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/API/SBHostOS.h (original)<br>
+++ lldb/trunk/include/lldb/API/SBHostOS.h Wed Jul 30 12:38:47 2014<br>
@@ -25,6 +25,9 @@ public:<br>
static lldb::SBFileSpec<br>
GetLLDBPythonPath ();<br>
<br>
+ static lldb::SBFileSpec<br>
+ GetLLDBPath (lldb::PathType path_type);<br>
+<br>
static void<br>
ThreadCreated (const char *name);<br>
<br>
<br>
Modified: lldb/trunk/include/lldb/Host/Host.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Host/Host.h (original)<br>
+++ lldb/trunk/include/lldb/Host/Host.h Wed Jul 30 12:38:47 2014<br>
@@ -460,7 +460,7 @@ public:<br>
/// \b true if \a resource_path was resolved, \a false otherwise.<br>
//------------------------------------------------------------------<br>
static bool<br>
- GetLLDBPath (PathType path_type,<br>
+ GetLLDBPath (lldb::PathType path_type,<br>
FileSpec &file_spec);<br>
<br>
//------------------------------------------------------------------<br>
<br>
Modified: lldb/trunk/include/lldb/lldb-enumerations.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)<br>
+++ lldb/trunk/include/lldb/lldb-enumerations.h Wed Jul 30 12:38:47 2014<br>
@@ -818,6 +818,23 @@ namespace lldb {<br>
eGdbSignalBreakpoint = 0x96<br>
} GdbRemoteSignal;<br>
<br>
+ //----------------------------------------------------------------------<br>
+ // Used with SBHost::GetPath (lldb::PathType) to find files that are<br>
+ // related to LLDB on the current host machine. Most files are relative<br>
+ // to LLDB or are in known locations.<br>
+ //----------------------------------------------------------------------<br>
+ typedef enum PathType<br>
+ {<br>
+ ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists<br>
+ ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)<br>
+ ePathTypeHeaderDir, // Find LLDB header file directory<br>
+ ePathTypePythonDir, // Find Python modules (PYTHONPATH) directory<br>
+ ePathTypeLLDBSystemPlugins, // System plug-ins directory<br>
+ ePathTypeLLDBUserPlugins, // User plug-ins directory<br>
+ ePathTypeLLDBTempSystemDir // The LLDB temp directory for this system that will be cleaned up on exit<br>
+<br>
+ } PathType;<br>
+<br>
} // namespace lldb<br>
<br>
<br>
<br>
Modified: lldb/trunk/include/lldb/lldb-private-enumerations.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-enumerations.h?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-enumerations.h?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/lldb-private-enumerations.h (original)<br>
+++ lldb/trunk/include/lldb/lldb-private-enumerations.h Wed Jul 30 12:38:47 2014<br>
@@ -105,24 +105,6 @@ typedef enum SortOrder<br>
eSortOrderByName<br>
} SortOrder;<br>
<br>
-<br>
-//----------------------------------------------------------------------<br>
-// Used in conjunction with Host::GetLLDBPath () to find files that<br>
-// are related to<br>
-//----------------------------------------------------------------------<br>
-typedef enum PathType<br>
-{<br>
- ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists<br>
- ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)<br>
- ePathTypeHeaderDir, // Find LLDB header file directory<br>
- ePathTypePythonDir, // Find Python modules (PYTHONPATH) directory<br>
- ePathTypeLLDBSystemPlugins, // System plug-ins directory<br>
- ePathTypeLLDBUserPlugins, // User plug-ins directory<br>
- ePathTypeLLDBTempSystemDir // The LLDB temp directory for this system that will be cleaned up on exit<br>
-<br>
-} PathType;<br>
-<br>
-<br>
typedef enum ObjCRuntimeVersions {<br>
eObjC_VersionUnknown = 0,<br>
eAppleObjC_V1 = 1,<br>
<br>
Modified: lldb/trunk/scripts/Python/interface/SBHostOS.i<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBHostOS.i?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBHostOS.i?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/scripts/Python/interface/SBHostOS.i (original)<br>
+++ lldb/trunk/scripts/Python/interface/SBHostOS.i Wed Jul 30 12:38:47 2014<br>
@@ -16,6 +16,12 @@ public:<br>
static lldb::SBFileSpec<br>
GetProgramFileSpec ();<br>
<br>
+ static lldb::SBFileSpec<br>
+ GetLLDBPythonPath ();<br>
+<br>
+ static lldb::SBFileSpec<br>
+ GetLLDBPath (lldb::PathType path_type);<br>
+<br>
static void<br>
ThreadCreated (const char *name);<br>
<br>
<br>
Modified: lldb/trunk/source/API/SBHostOS.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBHostOS.cpp?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBHostOS.cpp?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/API/SBHostOS.cpp (original)<br>
+++ lldb/trunk/source/API/SBHostOS.cpp Wed Jul 30 12:38:47 2014<br>
@@ -38,6 +38,17 @@ SBHostOS::GetLLDBPythonPath ()<br>
return sb_lldb_python_filespec;<br>
}<br>
<br>
+<br>
+SBFileSpec<br>
+SBHostOS::GetLLDBPath (lldb::PathType path_type)<br>
+{<br>
+ SBFileSpec sb_fspec;<br>
+ FileSpec fspec;<br>
+ if (Host::GetLLDBPath (path_type, fspec))<br>
+ sb_fspec.SetFileSpec (fspec);<br>
+ return sb_fspec;<br>
+}<br>
+<br>
lldb::thread_t<br>
SBHostOS::ThreadCreate<br>
(<br>
<br>
Modified: lldb/trunk/source/API/SBStream.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBStream.cpp?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBStream.cpp?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/API/SBStream.cpp (original)<br>
+++ lldb/trunk/source/API/SBStream.cpp Wed Jul 30 12:38:47 2014<br>
@@ -82,6 +82,8 @@ SBStream::RedirectToFile (const char *pa<br>
uint32_t open_options = File::eOpenOptionWrite | File::eOpenOptionCanCreate;<br>
if (append)<br>
open_options |= File::eOpenOptionAppend;<br>
+ else<br>
+ open_options |= File::eOpenOptionTruncate;<br>
stream_file->GetFile().Open (path, open_options, lldb::eFilePermissionsFileDefault);<br>
<br>
m_opaque_ap.reset (stream_file);<br>
<br>
Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)<br>
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Wed Jul 30 12:38:47 2014<br>
@@ -536,6 +536,9 @@ protected:<br>
<br>
if (error.Success())<br>
{<br>
+ // Update the execution context so the current target and process are now selected<br>
+ // in case we interrupt<br>
+ m_interpreter.UpdateExecutionContext(NULL);<br>
ListenerSP listener_sp (new Listener("lldb.CommandObjectProcessAttach.DoExecute.attach.hijack"));<br>
m_options.attach_info.SetHijackListener(listener_sp);<br>
process->HijackProcessEvents(listener_sp.get());<br>
@@ -557,7 +560,11 @@ protected:<br>
}<br>
else<br>
{<br>
- result.AppendError ("attach failed: process did not stop (no such process or permission problem?)");<br>
+ const char *exit_desc = process->GetExitDescription();<br>
+ if (exit_desc)<br>
+ result.AppendErrorWithFormat ("attach failed: %s", exit_desc);<br>
+ else<br>
+ result.AppendError ("attach failed: process did not stop (no such process or permission problem?)");<br>
process->Destroy();<br>
result.SetStatus (eReturnStatusFailed);<br>
}<br>
<br>
Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)<br>
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Wed Jul 30 12:38:47 2014<br>
@@ -309,7 +309,7 @@ ClangExpressionParser::Parse (Stream &st<br>
std::string temp_source_path;<br>
<br>
FileSpec tmpdir_file_spec;<br>
- if (Host::GetLLDBPath (ePathTypeLLDBTempSystemDir, tmpdir_file_spec))<br>
+ if (Host::GetLLDBPath (lldb::ePathTypeLLDBTempSystemDir, tmpdir_file_spec))<br>
{<br>
tmpdir_file_spec.GetFilename().SetCString("expr.XXXXXX");<br>
temp_source_path = std::move(tmpdir_file_spec.GetPath());<br>
<br>
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)<br>
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Jul 30 12:38:47 2014<br>
@@ -3141,7 +3141,16 @@ CommandInterpreter::RunCommandInterprete<br>
bool spawn_thread)<br>
{<br>
const bool multiple_lines = false; // Only get one line at a time<br>
- if (!m_command_io_handler_sp)<br>
+ if (m_command_io_handler_sp)<br>
+ {<br>
+ // Copy the current debugger file handles in case they changed.<br>
+ m_command_io_handler_sp->GetInputStreamFile() = m_debugger.GetInputFile();<br>
+ m_command_io_handler_sp->GetOutputStreamFile() = m_debugger.GetOutputFile();<br>
+ m_command_io_handler_sp->GetErrorStreamFile() = m_debugger.GetErrorFile();<br>
+ m_command_io_handler_sp->SetIsDone(false);<br>
+ }<br>
+ else<br>
+ {<br>
m_command_io_handler_sp.reset(new IOHandlerEditline (m_debugger,<br>
m_debugger.GetInputFile(),<br>
m_debugger.GetOutputFile(),<br>
@@ -3152,6 +3161,8 @@ CommandInterpreter::RunCommandInterprete<br>
multiple_lines,<br>
0, // Don't show line numbers<br>
*this));<br>
+ }<br>
+<br>
m_debugger.PushIOHandler(m_command_io_handler_sp);<br>
<br>
if (auto_handle_events)<br>
<br>
Modified: lldb/trunk/source/Target/Process.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Target/Process.cpp (original)<br>
+++ lldb/trunk/source/Target/Process.cpp Wed Jul 30 12:38:47 2014<br>
@@ -3243,6 +3243,7 @@ Process::Halt (bool clear_thread_plans)<br>
EventSP event_sp;<br>
Error error (WillHalt());<br>
<br>
+ bool restored_process_events = false;<br>
if (error.Success())<br>
{<br>
<br>
@@ -3254,6 +3255,10 @@ Process::Halt (bool clear_thread_plans)<br>
{<br>
if (m_public_state.GetValue() == eStateAttaching)<br>
{<br>
+ // Don't hijack and eat the eStateExited as the code that was doing<br>
+ // the attach will be waiting for this event...<br>
+ RestorePrivateProcessEvents();<br>
+ restored_process_events = true;<br>
SetExitStatus(SIGKILL, "Cancelled async attach.");<br>
Destroy ();<br>
}<br>
@@ -3302,7 +3307,8 @@ Process::Halt (bool clear_thread_plans)<br>
}<br>
}<br>
// Resume our private state thread before we post the event (if any)<br>
- RestorePrivateProcessEvents();<br>
+ if (!restored_process_events)<br>
+ RestorePrivateProcessEvents();<br>
<br>
// Post any event we might have consumed. If all goes well, we will have<br>
// stopped the process, intercepted the event and set the interrupted<br>
<br>
Modified: lldb/trunk/tools/driver/Driver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/driver/Driver.cpp (original)<br>
+++ lldb/trunk/tools/driver/Driver.cpp Wed Jul 30 12:38:47 2014<br>
@@ -477,63 +477,19 @@ Driver::GetScriptLanguage() const<br>
}<br>
<br>
void<br>
-Driver::ExecuteInitialCommands (bool before_file)<br>
+Driver::WriteInitialCommands (bool before_file, SBStream &strm)<br>
{<br>
- size_t num_commands;<br>
- std::vector<std::pair<bool, std::string> > *command_set;<br>
- if (before_file)<br>
- command_set = &(m_option_data.m_initial_commands);<br>
- else<br>
- command_set = &(m_option_data.m_after_file_commands);<br>
+ std::vector<std::pair<bool, std::string> > &command_set = before_file ? m_option_data.m_initial_commands :<br>
+ m_option_data.m_after_file_commands;<br>
<br>
- num_commands = command_set->size();<br>
- SBCommandReturnObject result;<br>
- bool old_async = GetDebugger().GetAsync();<br>
- GetDebugger().SetAsync(false);<br>
- for (size_t idx = 0; idx < num_commands; idx++)<br>
- {<br>
- bool is_file = (*command_set)[idx].first;<br>
- const char *command = (*command_set)[idx].second.c_str();<br>
- char command_string[PATH_MAX * 2];<br>
- const bool dump_stream_only_if_no_immediate = true;<br>
- const char *executed_command = command;<br>
- if (is_file)<br>
- {<br>
- ::snprintf (command_string, sizeof(command_string), "command source -s %i '%s'", m_option_data.m_source_quietly, command);<br>
- executed_command = command_string;<br>
- }<br>
-<br>
- m_debugger.GetCommandInterpreter().HandleCommand (executed_command, result, false);<br>
- if (!m_option_data.m_source_quietly || result.Succeeded() == false)<br>
- {<br>
- const size_t output_size = result.GetOutputSize();<br>
- if (output_size > 0)<br>
- {<br>
- const char *cstr = result.GetOutput(dump_stream_only_if_no_immediate);<br>
- if (cstr)<br>
- printf ("%s", cstr);<br>
- }<br>
- const size_t error_size = result.GetErrorSize();<br>
- if (error_size > 0)<br>
- {<br>
- const char *cstr = result.GetError(dump_stream_only_if_no_immediate);<br>
- if (cstr)<br>
- printf ("%s", cstr);<br>
- }<br>
- }<br>
-<br>
- if (result.Succeeded() == false)<br>
- {<br>
- const char *type = before_file ? "before file" : "after_file";<br>
- if (is_file)<br>
- ::fprintf(stderr, "Aborting %s command execution, command file: '%s' failed.\n", type, command);<br>
- else<br>
- ::fprintf(stderr, "Aborting %s command execution, command: '%s' failed.\n", type, command);<br>
- break;<br>
- }<br>
- result.Clear();<br>
+ for (const auto &command_pair : command_set)<br>
+ {<br>
+ const char *command = command_pair.second.c_str();<br>
+ if (command_pair.first)<br>
+ strm.Printf("command source -s %i '%s'\n", m_option_data.m_source_quietly, command);<br>
+ else<br>
+ strm.Printf("%s\n", command);<br>
}<br>
- GetDebugger().SetAsync(old_async);<br>
}<br>
<br>
bool<br>
@@ -857,8 +813,8 @@ Driver::MainLoop ()<br>
<br>
m_debugger.SetErrorFileHandle (stderr, false);<br>
m_debugger.SetOutputFileHandle (stdout, false);<br>
- m_debugger.SetInputFileHandle (stdin, true);<br>
-<br>
+ m_debugger.SetInputFileHandle (stdin, false); // Don't take ownership of STDIN yet...<br>
+<br>
m_debugger.SetUseExternalEditor(m_option_data.m_use_external_editor);<br>
<br>
struct winsize window_size;<br>
@@ -882,77 +838,56 @@ Driver::MainLoop ()<br>
}<br>
<br>
// Now we handle options we got from the command line<br>
- // First source in the commands specified to be run before the file arguments are processed.<br>
- ExecuteInitialCommands(true);<br>
-<br>
- // Was there a core file specified?<br>
- std::string core_file_spec("");<br>
- if (!m_option_data.m_core_file.empty())<br>
- core_file_spec.append("--core ").append(m_option_data.m_core_file);<br>
+ SBStream commands_stream;./<br>
<br>
- char command_string[PATH_MAX * 2];<br>
+ // First source in the commands specified to be run before the file arguments are processed.<br>
+ WriteInitialCommands(true, commands_stream);<br>
+<br>
const size_t num_args = m_option_data.m_args.size();<br>
if (num_args > 0)<br>
{<br>
- char arch_name[64];<br>
- if (m_debugger.GetDefaultArchitecture (arch_name, sizeof (arch_name)))<br>
- ::snprintf (command_string,<br>
- sizeof (command_string),<br>
- "target create --arch=%s %s \"%s\"",<br>
- arch_name,<br>
- core_file_spec.c_str(),<br>
- m_option_data.m_args[0].c_str());<br>
- else<br>
- ::snprintf (command_string,<br>
- sizeof(command_string),<br>
- "target create %s \"%s\"",<br>
- core_file_spec.c_str(),<br>
- m_option_data.m_args[0].c_str());<br>
-<br>
- m_debugger.HandleCommand (command_string);<br>
+ commands_stream.Printf("target create \"%s\"", m_option_data.m_args[0].c_str());<br>
+ if (!m_option_data.m_core_file.empty())<br>
+ {<br>
+ commands_stream.Printf(" --core \"%s\"", m_option_data.m_core_file.c_str());<br>
+ }<br>
+ commands_stream.Printf("\n");<br>
<br>
if (num_args > 1)<br>
{<br>
- m_debugger.HandleCommand ("settings clear target.run-args");<br>
- char arg_cstr[1024];<br>
+ commands_stream.Printf ("settings set -- target.run-args ");<br>
for (size_t arg_idx = 1; arg_idx < num_args; ++arg_idx)<br>
{<br>
- ::snprintf (arg_cstr,<br>
- sizeof(arg_cstr),<br>
- "settings append target.run-args \"%s\"",<br>
- m_option_data.m_args[arg_idx].c_str());<br>
- m_debugger.HandleCommand (arg_cstr);<br>
+ const char *arg_cstr = m_option_data.m_args[arg_idx].c_str();<br>
+ if (strchr(arg_cstr, '"') == NULL)<br>
+ commands_stream.Printf(" \"%s\"", arg_cstr);<br>
+ else<br>
+ commands_stream.Printf(" '%s'", arg_cstr);<br>
}<br>
+ commands_stream.Printf("\n");<br>
}<br>
}<br>
- else if (!core_file_spec.empty())<br>
+ else if (!m_option_data.m_core_file.empty())<br>
{<br>
- ::snprintf (command_string,<br>
- sizeof(command_string),<br>
- "target create %s",<br>
- core_file_spec.c_str());<br>
- m_debugger.HandleCommand (command_string);;<br>
+ commands_stream.Printf("target create --core \"%s\"\n", m_option_data.m_core_file.c_str());<br>
}<br>
else if (!m_option_data.m_process_name.empty())<br>
{<br>
- ::snprintf (command_string,<br>
- sizeof(command_string),<br>
- "process attach --name '%s'%s",<br>
- m_option_data.m_process_name.c_str(),<br>
- m_option_data.m_wait_for ? " --waitfor" : "");<br>
- m_debugger.HandleCommand (command_string);<br>
+ commands_stream.Printf ("process attach --name \"%s\"", m_option_data.m_process_name.c_str());<br>
+<br>
+ if (m_option_data.m_wait_for)<br>
+ commands_stream.Printf(" --waitfor");<br>
+<br>
+ commands_stream.Printf("\n");<br>
+<br>
}<br>
else if (LLDB_INVALID_PROCESS_ID != m_option_data.m_process_pid)<br>
{<br>
- ::snprintf (command_string,<br>
- sizeof(command_string),<br>
- "process attach --pid %" PRIu64,<br>
- m_option_data.m_process_pid);<br>
- m_debugger.HandleCommand (command_string);<br>
+ commands_stream.Printf ("process attach --pid %" PRIu64 "\n", m_option_data.m_process_pid);<br>
}<br>
<br>
- ExecuteInitialCommands(false);<br>
-<br>
+ WriteInitialCommands(false, commands_stream);<br>
+<br>
// Now that all option parsing is done, we try and parse the .lldbinit<br>
// file in the current working directory<br>
sb_interpreter.SourceInitFileInCurrentWorkingDirectory (result);<br>
@@ -964,6 +899,56 @@ Driver::MainLoop ()<br>
<br>
bool handle_events = true;<br>
bool spawn_thread = false;<br>
+<br>
+ // Check if we have any data in the commands stream, and if so, save it to a temp file<br>
+ // so we can then run the command interpreter using the file contents.<br>
+ if (commands_stream.GetData() && commands_stream.GetSize())<br>
+ {<br>
+ char lldb_cmds_file[PATH_MAX];<br>
+ SBFileSpec lldb_temp_dir_spec = SBHostOS::GetLLDBPath (lldb::ePathTypeLLDBTempSystemDir);<br>
+ lldb_temp_dir_spec.SetFilename("lldb-cmds.XXXXXX");<br>
+<br>
+ if (lldb_temp_dir_spec.GetPath(lldb_cmds_file, sizeof(lldb_cmds_file)))<br>
+ {<br>
+ int fd = mkstemp(lldb_cmds_file);<br>
+ if (fd == -1)<br>
+ {<br>
+ fprintf(stderr, "error: can't create temporary file for LLDB commands\n");<br>
+ exit (1);<br>
+ }<br>
+ FILE *file = fdopen(fd, "r+");<br>
+ if (file == NULL)<br>
+ {<br>
+ fprintf(stderr, "error: fdopen(%i, \"r+\") failed (errno = %i)\n", fd, errno);<br>
+ exit (2);<br>
+ }<br>
+ // Redirect the stream to a file and it will save its temp buffer out to the file on disk<br>
+ commands_stream.RedirectToFileHandle(file, true);<br>
+<br>
+ // Close the stream which will close the file and flush it to disk<br>
+ commands_stream.Clear();<br>
+<br>
+ // Now re-open the file so we can use it as an input file handle for the real<br>
+ // command interpreter<br>
+ FILE *commands_file = ::fopen(lldb_cmds_file, "r");<br>
+ if (commands_file)<br>
+ {<br>
+ // Hand ownership over to the debugger for "commands_file".<br>
+ m_debugger.SetInputFileHandle (commands_file, true);<br>
+ m_debugger.RunCommandInterpreter(handle_events, spawn_thread);<br>
+ }<br>
+ else<br>
+ {<br>
+ fprintf(stderr, "error: fopen(\"%s\", \"r\") failed (errno = %i) when trying to open LLDB commands file\n", lldb_cmds_file, errno);<br>
+ exit (3);<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+ // Now set the input file handle to STDIN and run the command<br>
+ // interpreter again in interactive mode and let the debugger<br>
+ // take ownership of stdin<br>
+ m_debugger.SetInputFileHandle (stdin, true);<br>
m_debugger.RunCommandInterpreter(handle_events, spawn_thread);<br>
<br>
reset_stdin_termios();<br>
<br>
Modified: lldb/trunk/tools/driver/Driver.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.h?rev=214319&r1=214318&r2=214319&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.h?rev=214319&r1=214318&r2=214319&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/driver/Driver.h (original)<br>
+++ lldb/trunk/tools/driver/Driver.h Wed Jul 30 12:38:47 2014<br>
@@ -52,7 +52,7 @@ public:<br>
GetScriptLanguage() const;<br>
<br>
void<br>
- ExecuteInitialCommands (bool before_file);<br>
+ WriteInitialCommands (bool before_file, lldb::SBStream &strm);<br>
<br>
bool<br>
GetDebugMode() const;<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br>
</blockquote></div><br></div>