summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2013-05-06 22:10:33 +0000
committerEnrico Granata <egranata@apple.com>2013-05-06 22:10:33 +0000
commit6e088d810e99eca9e14ddcdf332eb4793e0bbae1 (patch)
treef5451a2b94f07df1411749e038140b4ddcc1ffce
parent9af6baaaa3bf991f38f7bfe6cfb995fbdc0554d0 (diff)
downloadbcm5719-llvm-6e088d810e99eca9e14ddcdf332eb4793e0bbae1.tar.gz
bcm5719-llvm-6e088d810e99eca9e14ddcdf332eb4793e0bbae1.zip
<rdar://problem/13063912>
If the user pressed ^D, that would bypass the exit confirmation mechanism This checkin remedies that by making sure that users get prompted on exit when appropriate even if they use CTRL+D instead of typing quit at the prompt llvm-svn: 181257
-rw-r--r--lldb/tools/driver/IOChannel.cpp25
-rw-r--r--lldb/tools/driver/IOChannel.h11
2 files changed, 30 insertions, 6 deletions
diff --git a/lldb/tools/driver/IOChannel.cpp b/lldb/tools/driver/IOChannel.cpp
index 247d930ca40..7adf2e4e85e 100644
--- a/lldb/tools/driver/IOChannel.cpp
+++ b/lldb/tools/driver/IOChannel.cpp
@@ -329,9 +329,10 @@ IOChannel::LibeditOutputBytesReceived (void *baton, const void *src, size_t src_
}
}
-bool
+IOChannel::LibeditGetInputResult
IOChannel::LibeditGetInput (std::string &new_line)
{
+ IOChannel::LibeditGetInputResult retval = IOChannel::eLibeditGetInputResultUnknown;
if (m_edit_line != NULL)
{
int line_len = 0;
@@ -349,6 +350,7 @@ IOChannel::LibeditGetInput (std::string &new_line)
if (line)
{
+ retval = IOChannel::eLibeditGetInputValid;
// strip any newlines off the end of the string...
while (line_len > 0 && (line[line_len - 1] == '\n' || line[line_len - 1] == '\r'))
--line_len;
@@ -359,17 +361,22 @@ IOChannel::LibeditGetInput (std::string &new_line)
}
else
{
+ retval = IOChannel::eLibeditGetInputEmpty;
// Someone just hit ENTER, return the empty string
new_line.clear();
}
// Return true to indicate success even if a string is empty
- return true;
+ return retval;
+ }
+ else
+ {
+ retval = (line_len == 0 ? IOChannel::eLibeditGetInputEOF : IOChannel::eLibeditGetInputResultError);
}
}
// Return false to indicate failure. This can happen when the file handle
// is closed (EOF).
new_line.clear();
- return false;
+ return retval;
}
void *
@@ -422,9 +429,17 @@ IOChannel::Run ()
if (CommandQueueIsEmpty())
{
- if (LibeditGetInput(line) == false)
+ IOChannel::LibeditGetInputResult getline_result = LibeditGetInput(line);
+ if (getline_result == IOChannel::eLibeditGetInputEOF)
+ {
+ // EOF occurred
+ // pretend that a quit was typed so the user gets a potential
+ // chance to confirm
+ line.assign("quit");
+ }
+ else if (getline_result == IOChannel::eLibeditGetInputResultError || getline_result == IOChannel::eLibeditGetInputResultUnknown)
{
- // EOF or some other file error occurred
+ // some random error occurred, exit and don't ask because the state might be corrupt
done = true;
continue;
}
diff --git a/lldb/tools/driver/IOChannel.h b/lldb/tools/driver/IOChannel.h
index 0a6b2d0ec65..36653a0c289 100644
--- a/lldb/tools/driver/IOChannel.h
+++ b/lldb/tools/driver/IOChannel.h
@@ -38,6 +38,15 @@ public:
eBroadcastBitsSTDIN = (1 << 7),
eAllEventBits = 0xffffffff
};
+
+ enum LibeditGetInputResult
+ {
+ eLibeditGetInputEOF = 0,
+ eLibeditGetInputValid = 1,
+ eLibeditGetInputEmpty = 2,
+ eLibeditGetInputResultError = 4,
+ eLibeditGetInputResultUnknown = 0xffffffff
+ };
IOChannel (FILE *editline_in,
FILE *editline_out,
@@ -66,7 +75,7 @@ public:
void
ErrWrite (const char *buffer, size_t len, bool asynchronous);
- bool
+ LibeditGetInputResult
LibeditGetInput (std::string &);
static void
OpenPOWER on IntegriCloud