[Lldb-commits] Set interpreter.prompt-on-quit to false in lldbtest.py?

Malea, Daniel daniel.malea at intel.com
Fri Jan 25 11:04:58 PST 2013


Hi Enrico,

I'm noticing at least one test-case (functionalities/embedded_interpreter) appear to hang after this commit. It looks like it's waiting for someone to answer the prompt after the "quit" command. Interestingly though, the test-case does eventually succeed, but after a 30s delay…not sure how that works, but since I'm trying to speed up testing, does the following fix look OK to you:

diff --git a/test/lldbtest.py b/test/lldbtest.py
index 17ad718..fbfb269 100644
--- a/test/lldbtest.py
+++ b/test/lldbtest.py
@@ -733,6 +733,7 @@ class Base(unittest2.TestCase):
             if self.child_in_script_interpreter:
                 self.child.sendline('quit()')
                 self.child.expect_exact(self.child_prompt)
+            self.child.sendline('settings set interpreter.prompt-on-quit false')
             self.child.sendline('quit')
             try:
                 self.child.expect(pexpect.EOF)


The idea is that before the test harness sends the "quit" command, it sets the prompt-on-quit setting to false. Since this bit of code appears to only handle tests that use the lldb subprocess (as opposed to most tests that just use the API) there's no need to clear the setting afterwards.


Thanks,
Dan

On 2013-01-17, at 4:36 PM, Enrico Granata <egranata at apple.com<mailto:egranata at apple.com>> wrote:

Author: enrico
Date: Thu Jan 17 15:36:19 2013
New Revision: 172757

URL: http://llvm.org/viewvc/llvm-project?rev=172757&view=rev
Log:
<rdar://problem/12786725>

If there is any alive process being debugged, the user is asked for confirmation before quitting LLDB
This should prevent situations where the user mistakenly types "q" and LLDB slaughters their process without any mercy whatsoever
Since it can quickly get tedious, there is a new setting on the command interpreter to disable this and replicate the previous behavior


Modified:
   lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
   lldb/trunk/source/Commands/CommandObjectQuit.cpp
   lldb/trunk/source/Commands/CommandObjectQuit.h
   lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=172757&r1=172756&r2=172757&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Thu Jan 17 15:36:19 2013
@@ -436,6 +436,9 @@
    bool
    GetExpandRegexAliases () const;

+    bool
+    GetPromptOnQuit () const;
+
protected:
    friend class Debugger;


Modified: lldb/trunk/source/Commands/CommandObjectQuit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectQuit.cpp?rev=172757&r1=172756&r2=172757&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectQuit.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectQuit.cpp Thu Jan 17 15:36:19 2013
@@ -34,9 +34,63 @@
{
}

+// returns true if there is at least one alive process
+// is_a_detach will be true if all alive processes will be detached when you quit
+// and false if at least one process will be killed instead
+bool
+CommandObjectQuit::ShouldAskForConfirmation (bool& is_a_detach)
+{
+    if (m_interpreter.GetPromptOnQuit() == false)
+        return false;
+    bool should_prompt = false;
+    is_a_detach = true;
+    for (uint32_t debugger_idx = 0;
+         debugger_idx < Debugger::GetNumDebuggers();
+         debugger_idx++)
+    {
+        DebuggerSP debugger_sp(Debugger::GetDebuggerAtIndex(debugger_idx));
+        if (!debugger_sp)
+            continue;
+        const TargetList& target_list(debugger_sp->GetTargetList());
+        for (uint32_t target_idx = 0;
+             target_idx < target_list.GetNumTargets();
+             target_idx++)
+        {
+            TargetSP target_sp(target_list.GetTargetAtIndex(target_idx));
+            if (!target_sp)
+                continue;
+            ProcessSP process_sp(target_sp->GetProcessSP());
+            if (process_sp &&
+                process_sp->IsValid() &&
+                process_sp->IsAlive())
+            {
+                should_prompt = true;
+                if (process_sp->GetShouldDetach() == false)
+                {
+                    // if we need to kill at least one process, just say so and return
+                    is_a_detach = false;
+                    return should_prompt;
+                }
+            }
+        }
+    }
+    return should_prompt;
+}
+
bool
CommandObjectQuit::DoExecute (Args& command, CommandReturnObject &result)
{
+    bool is_a_detach = true;
+    if (ShouldAskForConfirmation (is_a_detach))
+    {
+        StreamString message;
+        message.Printf("Quitting LLDB will %s one or more processes. Do you really want to proceed", (is_a_detach ? "detach from" : "kill"));
+        if (!m_interpreter.Confirm(message.GetData(), true))
+        {
+            result.SetStatus(eReturnStatusFailed);
+            return false;
+        }
+    }
    m_interpreter.BroadcastEvent (CommandInterpreter::eBroadcastBitQuitCommandReceived);
    result.SetStatus (eReturnStatusQuit);
    return true;

Modified: lldb/trunk/source/Commands/CommandObjectQuit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectQuit.h?rev=172757&r1=172756&r2=172757&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectQuit.h (original)
+++ lldb/trunk/source/Commands/CommandObjectQuit.h Thu Jan 17 15:36:19 2013
@@ -35,6 +35,9 @@
    virtual bool
    DoExecute (Args& args,
             CommandReturnObject &result);
+
+    bool
+    ShouldAskForConfirmation (bool& is_a_detach);

};


Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=172757&r1=172756&r2=172757&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Thu Jan 17 15:36:19 2013
@@ -72,12 +72,14 @@
g_properties[] =
{
    { "expand-regex-aliases", OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, regular expression alias commands will show the expanded command that will be executed. This can be used to debug new regular expression alias commands." },
+    { "prompt-on-quit", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, LLDB will prompt you before quitting if there are any live processes being debugged. If false, LLDB will quit without asking in any case." },
    { NULL                  , OptionValue::eTypeInvalid, true, 0    , NULL, NULL, NULL }
};

enum
{
-    ePropertyExpandRegexAliases = 0
+    ePropertyExpandRegexAliases = 0,
+    ePropertyPromptOnQuit = 1
};

ConstString &
@@ -121,7 +123,12 @@
    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
}

-
+bool
+CommandInterpreter::GetPromptOnQuit () const
+{
+    const uint32_t idx = ePropertyPromptOnQuit;
+    return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
+}

void
CommandInterpreter::Initialize ()


_______________________________________________
lldb-commits mailing list
lldb-commits at cs.uiuc.edu<mailto:lldb-commits at cs.uiuc.edu>
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits





More information about the lldb-commits mailing list