diff options
author | Greg Clayton <gclayton@apple.com> | 2011-07-02 21:07:54 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2011-07-02 21:07:54 +0000 |
commit | 197bacfffaac38a69966799a2b76b73e0c62f57b (patch) | |
tree | 09d5554b087d882a2f3f874306bee95ddc048c08 /lldb/source/Interpreter/CommandReturnObject.cpp | |
parent | d024a508230db67061887b43f2ad9d17f141d3b5 (diff) | |
download | bcm5719-llvm-197bacfffaac38a69966799a2b76b73e0c62f57b.tar.gz bcm5719-llvm-197bacfffaac38a69966799a2b76b73e0c62f57b.zip |
Cleanup errors that come out of commands and make sure they all have newlines
_only_ in the resulting stream, not in the error objects (lldb_private::Error).
lldb_private::Error objects should always just have an error string with no
terminating newline characters or periods.
Fixed an issue with GDB remote packet detection that could end up deadlocking
if a full packet wasn't received in one chunk. Also modified the packet
checking function to properly toss one or more bytes when it detects bad
data.
llvm-svn: 134357
Diffstat (limited to 'lldb/source/Interpreter/CommandReturnObject.cpp')
-rw-r--r-- | lldb/source/Interpreter/CommandReturnObject.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp index 9d32279edab..eb6fae4ce1b 100644 --- a/lldb/source/Interpreter/CommandReturnObject.cpp +++ b/lldb/source/Interpreter/CommandReturnObject.cpp @@ -18,6 +18,29 @@ using namespace lldb; using namespace lldb_private; +static void +DumpStringToStreamWithNewline (Stream &strm, const std::string &s, bool add_newline_if_empty) +{ + bool add_newline = false; + if (s.empty()) + { + add_newline = add_newline_if_empty; + } + else + { + // We already checked for empty above, now make sure there is a newline + // in the error, and if there isn't one, add one. + strm.Write(s.c_str(), s.size()); + + const char last_char = *s.rbegin(); + add_newline = last_char != '\n' && last_char != '\r'; + + } + if (add_newline) + strm.EOL(); +} + + CommandReturnObject::CommandReturnObject () : m_out_stream (), m_err_stream (), @@ -39,7 +62,14 @@ CommandReturnObject::AppendErrorWithFormat (const char *format, ...) sstrm.PrintfVarArg(format, args); va_end (args); - GetErrorStream().Printf("error: %s", sstrm.GetData()); + + const std::string &s = sstrm.GetString(); + if (!s.empty()) + { + Stream &error_strm = GetErrorStream(); + error_strm.PutCString ("error: "); + DumpStringToStreamWithNewline (error_strm, s, false); + } } void |