diff options
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/API/SBDebugger.cpp | 22 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectBreakpointCommand.cpp | 23 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectExpression.cpp | 11 | ||||
-rw-r--r-- | lldb/source/Core/Communication.cpp | 11 | ||||
-rw-r--r-- | lldb/source/Core/ConnectionFileDescriptor.cpp | 14 | ||||
-rw-r--r-- | lldb/source/Core/Debugger.cpp | 45 | ||||
-rw-r--r-- | lldb/source/Core/InputReader.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 54 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h | 2 | ||||
-rw-r--r-- | lldb/source/Target/Process.cpp | 14 |
12 files changed, 162 insertions, 47 deletions
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index 1721d24264f..2777741ee5e 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -659,6 +659,20 @@ SBDebugger::DispatchInput (void *baton, const void *data, size_t data_len) } void +SBDebugger::DispatchInputInterrupt () +{ + if (m_opaque_sp) + m_opaque_sp->DispatchInputInterrupt (); +} + +void +SBDebugger::DispatchInputEndOfFile () +{ + if (m_opaque_sp) + m_opaque_sp->DispatchInputEndOfFile (); +} + +void SBDebugger::PushInputReader (SBInputReader &reader) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -837,3 +851,11 @@ SBDebugger::GetDescription (SBStream &description) return true; } + +lldb::user_id_t +SBDebugger::GetID() +{ + if (m_opaque_sp) + return m_opaque_sp->GetID(); + return LLDB_INVALID_UID; +} diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index e8bd399b131..aad7158d28f 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -468,6 +468,29 @@ CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback } break; + case eInputReaderInterrupt: + { + // Finish, and cancel the breakpoint command. + reader.SetIsDone (true); + BreakpointOptions *bp_options = (BreakpointOptions *) baton; + if (bp_options) + { + Baton *bp_options_baton = bp_options->GetBaton (); + if (bp_options_baton) + { + ((BreakpointOptions::CommandData *) bp_options_baton->m_data)->user_source.Clear(); + ((BreakpointOptions::CommandData *) bp_options_baton->m_data)->script_source.Clear(); + } + } + ::fprintf (out_fh, "Warning: No command attached to breakpoint.\n"); + ::fflush (out_fh); + } + break; + + case eInputReaderEndOfFile: + reader.SetIsDone (true); + break; + case eInputReaderDone: break; } diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 436b2e7540c..32236f8c917 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -199,7 +199,18 @@ CommandObjectExpression::MultiLineExpressionCallback // ::fprintf (out_fh, "%3u: ", cmd_object_expr->m_expr_line_count); break; + case eInputReaderInterrupt: + cmd_object_expr->m_expr_lines.clear(); + reader.SetIsDone (true); + reader.GetDebugger().GetOutputStream().Printf("%s\n", "Expression evaluation cancelled."); + break; + + case eInputReaderEndOfFile: + reader.SetIsDone (true); + break; + case eInputReaderDone: + if (cmd_object_expr->m_expr_lines.size() > 0) { cmd_object_expr->EvaluateExpression (cmd_object_expr->m_expr_lines.c_str(), reader.GetDebugger().GetOutputStream(), diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp index f6c689c7aa5..22a9f9ae293 100644 --- a/lldb/source/Core/Communication.cpp +++ b/lldb/source/Core/Communication.cpp @@ -260,12 +260,13 @@ Communication::GetCachedBytes (void *dst, size_t dst_len) } void -Communication::AppendBytesToCache (const uint8_t * bytes, size_t len, bool broadcast) +Communication::AppendBytesToCache (const uint8_t * bytes, size_t len, bool broadcast, ConnectionStatus status) { lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION, "%p Communication::AppendBytesToCache (src = %p, src_len = %zu, broadcast = %i)", this, bytes, len, broadcast); - if (bytes == NULL || len == 0) + if ((bytes == NULL || len == 0) + && (status != eConnectionStatusEndOfFile)) return; if (m_callback) { @@ -319,12 +320,16 @@ Communication::ReadThread (void *p) { size_t bytes_read = comm->ReadFromConnection (buf, sizeof(buf), status, &error); if (bytes_read > 0) - comm->AppendBytesToCache (buf, bytes_read, true); + comm->AppendBytesToCache (buf, bytes_read, true, status); + else if ((bytes_read == 0) + && status == eConnectionStatusEndOfFile) + comm->AppendBytesToCache (buf, bytes_read, true, status); } switch (status) { case eConnectionStatusSuccess: + case eConnectionStatusEndOfFile: break; case eConnectionStatusNoConnection: // No connection diff --git a/lldb/source/Core/ConnectionFileDescriptor.cpp b/lldb/source/Core/ConnectionFileDescriptor.cpp index 96d70bc1012..bdf550e5953 100644 --- a/lldb/source/Core/ConnectionFileDescriptor.cpp +++ b/lldb/source/Core/ConnectionFileDescriptor.cpp @@ -156,8 +156,18 @@ ConnectionFileDescriptor::Read (void *dst, size_t dst_len, ConnectionStatus &sta ssize_t bytes_read = ::read (m_fd, dst, dst_len); if (bytes_read == 0) { - error.SetErrorStringWithFormat("End-of-file.\n"); - status = eConnectionStatusLostConnection; + // 'read' did not return an error, but it didn't return any bytes either ==> End-of-File. + // If the file descriptor is still valid, then we don't return an error; otherwise we do. + // This allows whoever called us to act on the end-of-file, with a valid file descriptor, if they wish. + if (fcntl (m_fd, F_GETFL, 0) >= 0) + { + error.Clear(); // End-of-file, but not an error. Pass along for the end-of-file handlers. + } + else + { + error.SetErrorStringWithFormat("End-of-file.\n"); + } + status = eConnectionStatusEndOfFile; } else if (bytes_read < 0) { diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 617edd2fdf4..a06095fa80b 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -338,20 +338,57 @@ Debugger::GetTargetList () void Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len) { - ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len); -} + if (bytes_len > 0) + ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len); + else + ((Debugger *)baton)->DispatchInputEndOfFile (); +} void Debugger::DispatchInput (const char *bytes, size_t bytes_len) { -// if (bytes == NULL || bytes_len == 0) -// return; + if (bytes == NULL || bytes_len == 0) + return; WriteToDefaultReader (bytes, bytes_len); } void +Debugger::DispatchInputInterrupt () +{ + m_input_reader_data.clear(); + + if (!m_input_readers.empty()) + { + while (CheckIfTopInputReaderIsDone ()) ; + + InputReaderSP reader_sp(m_input_readers.top()); + if (reader_sp) + reader_sp->Notify (eInputReaderInterrupt); + + while (CheckIfTopInputReaderIsDone ()) ; + } +} + +void +Debugger::DispatchInputEndOfFile () +{ + m_input_reader_data.clear(); + + if (!m_input_readers.empty()) + { + while (CheckIfTopInputReaderIsDone ()) ; + + InputReaderSP reader_sp(m_input_readers.top()); + if (reader_sp) + reader_sp->Notify (eInputReaderEndOfFile); + + while (CheckIfTopInputReaderIsDone ()) ; + } +} + +void Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len) { if (bytes && bytes_len) diff --git a/lldb/source/Core/InputReader.cpp b/lldb/source/Core/InputReader.cpp index 06cfb5b5ff6..b8a61c29953 100644 --- a/lldb/source/Core/InputReader.cpp +++ b/lldb/source/Core/InputReader.cpp @@ -324,6 +324,10 @@ InputReader::Notify (InputReaderAction notification) m_active = false; break; + case eInputReaderInterrupt: + case eInputReaderEndOfFile: + break; + case eInputReaderGotToken: return; // We don't notify the tokens here, it is done in HandleRawBytes } diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 0dc4a34aa7b..86a635a6b2b 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -860,6 +860,12 @@ CommandInterpreter::GetConfirmationInputReaderCallback (void *baton, } break; + case eInputReaderInterrupt: + case eInputReaderEndOfFile: + *response_ptr = false; // Assume ^C or ^D means cancel the proposed action + reader.SetIsDone (true); + break; + case eInputReaderDone: break; } diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index 1927531fb89..1e3a308e83c 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -272,11 +272,6 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete PyRun_SimpleString (run_string.GetData()); PyRun_SimpleString ("sys.stdin = new_stdin"); - PyRun_SimpleString ("new_mode = tcgetattr(new_stdin)"); - PyRun_SimpleString ("new_mode[3] = new_mode[3] | ECHO | ICANON"); - PyRun_SimpleString ("new_mode[6][VEOF] = 255"); - PyRun_SimpleString ("tcsetattr (new_stdin, TCSANOW, new_mode)"); - run_string.Clear(); run_string.Printf ("lldb.debugger_unique_id = %d", interpreter.GetDebugger().GetID()); PyRun_SimpleString (run_string.GetData()); @@ -302,26 +297,10 @@ ScriptInterpreterPython::ExecuteOneLine (const char *command, CommandReturnObjec { int success; - - // Save the current input file handle state before executing the command. - int input_fd; - struct termios tmp_termios; - bool valid_termios = false; - FILE *input_fh = m_interpreter.GetDebugger().GetInputFileHandle(); - if (input_fh != NULL) - { - input_fd = ::fileno (input_fh); - valid_termios = ::tcgetattr (input_fd, &tmp_termios) == 0; - } - success = PyRun_SimpleString (command); if (success == 0) return true; - // Restore the input file handle state after executing the command. - if (valid_termios) - ::tcsetattr (input_fd, TCSANOW, &tmp_termios); - // The one-liner failed. Append the error message. if (result) result->AppendErrorWithFormat ("python failed attempting to evaluate '%s'\n", command); @@ -366,12 +345,6 @@ ScriptInterpreterPython::InputReaderCallback script_interpreter->m_termios_valid = ::tcgetattr (input_fd, &script_interpreter->m_termios) == 0; - if (script_interpreter->m_termios_valid) - { - struct termios tmp_termios = script_interpreter->m_termios; - tmp_termios.c_cc[VEOF] = _POSIX_VDISABLE; - ::tcsetattr (input_fd, TCSANOW, &tmp_termios); - } char error_str[1024]; if (script_interpreter->m_embedded_python_pty.OpenFirstAvailableMaster (O_RDWR|O_NOCTTY, error_str, sizeof(error_str))) @@ -411,6 +384,14 @@ ScriptInterpreterPython::InputReaderCallback case eInputReaderReactivate: break; + + case eInputReaderInterrupt: + ::write (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor(), "raise KeyboardInterrupt\n", 24); + break; + + case eInputReaderEndOfFile: + ::write (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor(), "quit()\n", 7); + break; case eInputReaderGotToken: if (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor() != -1) @@ -724,6 +705,17 @@ ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback } break; + case eInputReaderEndOfFile: + case eInputReaderInterrupt: + // Control-c (SIGINT) & control-d both mean finish & exit. + reader.SetIsDone(true); + + // Control-c (SIGINT) ALSO means cancel; do NOT create a breakpoint command. + if (notification == eInputReaderInterrupt) + commands_in_progress.Clear(); + + // Fall through here... + case eInputReaderDone: { BreakpointOptions *bp_options = (BreakpointOptions *)baton; @@ -843,6 +835,10 @@ ScriptInterpreterPython::GenerateBreakpointCommandCallbackData (StringList &user int num_lines = user_input.GetSize (); StreamString sstr; + // Check to see if we have any data; if not, just return. + if (user_input.GetSize() == 0) + return false; + // Take what the user wrote, wrap it all up inside one big auto-generated Python function, passing in the // frame and breakpoint location as parameters to the function. @@ -933,10 +929,6 @@ ScriptInterpreterPython::RunEmbeddedPythonInterpreter (lldb::thread_arg_t baton) PyRun_SimpleString ("save_stdin = sys.stdin"); run_string.Printf ("sys.stdin = open ('%s', 'r')", pty_slave_name); PyRun_SimpleString (run_string.GetData()); - PyRun_SimpleString ("new_mode = tcgetattr(sys.stdin)"); - PyRun_SimpleString ("new_mode[3] = new_mode[3] | ECHO | ICANON"); - PyRun_SimpleString ("new_mode[6][VEOF] = 255"); - PyRun_SimpleString ("tcsetattr (sys.stdin, TCSANOW, new_mode)"); // The following call drops into the embedded interpreter loop and stays there until the // user chooses to exit from the Python interpreter. diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index ee03424e528..63fb35783ea 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -551,7 +551,8 @@ GDBRemoteCommunication::WaitForPacketNoLock (StringExtractorGDBRemote &response, } void -GDBRemoteCommunication::AppendBytesToCache (const uint8_t *src, size_t src_len, bool broadcast) +GDBRemoteCommunication::AppendBytesToCache (const uint8_t *src, size_t src_len, bool broadcast, + ConnectionStatus status) { // Put the packet data into the buffer in a thread safe fashion Mutex::Locker locker(m_bytes_mutex); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h index ac49bf271f1..e7ef38ab1e0 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h @@ -110,7 +110,7 @@ public: // Communication overrides //------------------------------------------------------------------ virtual void - AppendBytesToCache (const uint8_t *src, size_t src_len, bool broadcast); + AppendBytesToCache (const uint8_t *src, size_t src_len, bool broadcast, lldb::ConnectionStatus status); lldb::pid_t diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index e50ecf27ef0..cebec5bbd31 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -1478,10 +1478,6 @@ Process::Halt () } else { - // Since we are eating the event, we need to update our state - // otherwise the process state will not match reality... - SetPublicState(state); - if (StateIsStoppedState (state)) { // We caused the process to interrupt itself, so mark this @@ -1508,7 +1504,7 @@ Process::Halt () // stopped the process, intercepted the event and set the interrupted // bool in the event. if (event_sp) - BroadcastEvent(event_sp); + m_private_state_broadcaster.BroadcastEvent(event_sp); } return error; @@ -2175,6 +2171,14 @@ Process::ProcessInputReaderCallback (void *baton, } break; + case eInputReaderInterrupt: + process->Halt (); + break; + + case eInputReaderEndOfFile: + process->AppendSTDOUT ("^D", 2); + break; + case eInputReaderDone: break; |