[Lldb-commits] [lldb] r232621 - Make lldb-mi handle only MI commands

Hafiz Abid Qadeer hafiz_abid at mentor.com
Wed Mar 18 03:07:47 PDT 2015


Author: abidh
Date: Wed Mar 18 05:07:46 2015
New Revision: 232621

URL: http://llvm.org/viewvc/llvm-project?rev=232621&view=rev
Log:
Make lldb-mi handle only MI commands

Summary:
Previously lldb-mi can also act as a driver like normal lldb. It needed a lot
of redundant code in the lldb-mi for that. I think that if a user wants command
line lldb driver then he/she should use the lldb for it. This change will cleanup
the code a lot. When this change goes in, it will allow us to remove some more
redundant code too.

All tests pass on Linux. Did some sanity testing on command line and with eclipse.

Reviewers: ki.stfu

Reviewed By: ki.stfu

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D8381

Modified:
    lldb/trunk/tools/lldb-mi/MICmnConfig.h
    lldb/trunk/tools/lldb-mi/MICmnResources.cpp
    lldb/trunk/tools/lldb-mi/MIDriver.cpp
    lldb/trunk/tools/lldb-mi/MIDriverMain.cpp
    lldb/trunk/tools/lldb-mi/MIDriverMgr.cpp
    lldb/trunk/tools/lldb-mi/MIReadMe.txt

Modified: lldb/trunk/tools/lldb-mi/MICmnConfig.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnConfig.h?rev=232621&r1=232620&r2=232621&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnConfig.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnConfig.h Wed Mar 18 05:07:46 2015
@@ -9,30 +9,10 @@
 //--
 #pragma once
 
-// 1 = Yes compile MI Driver version, 0 = compile original LLDB driver code only.
-// 0 was mainly just for testing purposes and so may be removed at a later time.
-#define MICONFIG_COMPILE_MIDRIVER_VERSION 1
-
 // 1 = Show debug process attach modal dialog, 0 = do not show
 // For windows only ATM, other OS's code is an infinite loop which a debugger must change a value to continue
 #define MICONFIG_DEBUG_SHOW_ATTACH_DBG_DLG 0
 
-// 1 = Compile in and init LLDB driver code alongside MI version, 0 = do not compile in
-#define MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER 1
-
-// 1 = Give runtime our own custom buffer, 0 = Use runtime managed buffer
-#define MICONFIG_CREATE_OWN_STDIN_BUFFER 0
-
-// 1 = Use the MI driver regardless of --interpreter, 0 = require --interpreter argument
-// This depends on MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER
-#define MICONFIG_DEFAULT_TO_MI_DRIVER 0
-
-// 1 = Check for stdin before we issue blocking read, 0 = issue blocking call always
-#define MICONFIG_POLL_FOR_STD_IN 1
-
 // 1 = Write to MI's Log file warnings about commands that did not handle arguments or
 // options present to them by the driver's client, 0 = no warnings given
 #define MICONFIG_GIVE_WARNING_CMD_ARGS_NOT_HANDLED 1
-
-// 1 = Enable MI Driver in MI mode to create a local debug session, 0 = Report "Not implemented"
-#define MICONFIG_ENABLE_MI_DRIVER_MI_MODE_CMDLINE_ARG_EXECUTABLE_DEBUG_SESSION 1

Modified: lldb/trunk/tools/lldb-mi/MICmnResources.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnResources.cpp?rev=232621&r1=232620&r2=232621&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnResources.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnResources.cpp Wed Mar 18 05:07:46 2015
@@ -63,13 +63,8 @@ const CMICmnResources::SRsrcTextData CMI
     {IDE_MI_APP_ARG_HELP, "-h\n--help\n\tPrints out usage information for the MI debugger. Exit the MI\n\tDriver immediately."},
     {IDE_MI_APP_ARG_VERSION, "--version\n\tPrints out GNU (gdb) version information. Exit the MI Driver\n\timmediately."},
     {IDE_MI_APP_ARG_VERSION_LONG, "--versionLong\n\tPrints out MI Driver version information. Exit the MI Driver\n\timmediately."},
-    {IDE_MI_APP_ARG_INTERPRETER, "--interpreter\n\tUse the MI Driver for the debugger (MI mode)(Default is the\n\tLLDB driver). Any LLDB "
-                                 "command line options are ignored even\n\tif the MI Driver falls through to the LLDB driver. "
-                                 "(Depends\n\ton the build configuration see MICmnConfig.h)\n\tNormally specified by the driver client "
-                                 "i.e. Eclipse.\n\tCannot specify an executable with this option, use --executable."},
-    {IDE_MI_APP_ARG_EXECUTEABLE, "--executable\n\tUse the MI Driver in MI mode for the debugging the specified\n\texecutable. Any LLDB "
-                                 "command line options are ignored even\n\tif the MI Driver falls through to the LLDB driver. "
-                                 "(Depends\n\ton the build configuration see MICmnConfig.h)\n\tNormally specified from the command line."},
+    {IDE_MI_APP_ARG_INTERPRETER, "--interpreter\n\t This option is kept for backward compatibility. This executable always run in MI mode"},
+    {IDE_MI_APP_ARG_EXECUTEABLE, "--executable\n\tUse the MI Driver in MI mode for the debugging the specified executable." },
     {IDE_MI_APP_ARG_APP_LOG, "--log\n\tUse this argument to tell the MI Driver to update it's log\n\tfile '%s'."},
     {IDE_MI_APP_ARG_EXAMPLE, "Example MI command:\n\t3-info-gdb-mi-command gdb-set\n\t3^done,command={exists=\"true\"}"},
     {IDE_MI_APP_ARG_EXECUTABLE, "executable (NOT IMPLEMENTED)\n\tThe file path to the executable i.e. '\"C:\\My Dev\\foo.exe\"'."},

Modified: lldb/trunk/tools/lldb-mi/MIDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIDriver.cpp?rev=232621&r1=232620&r2=232621&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIDriver.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MIDriver.cpp Wed Mar 18 05:07:46 2015
@@ -175,22 +175,6 @@ CMIDriver::Initialize(void)
     bOk &= m_rLldbDebugger.SetDriver(*this);
     MI::ModuleInit<CMICmnLLDBDebugger>(IDS_MI_INIT_ERR_LLDBDEBUGGER, bOk, errMsg);
 
-#if MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER
-    CMIDriverMgr &rDrvMgr = CMIDriverMgr::Instance();
-    bOk = bOk && rDrvMgr.RegisterDriver(*g_driver, "LLDB driver"); // Will be pass thru driver
-    if (bOk)
-    {
-        bOk = SetEnableFallThru(false); // This is intentional at this time - yet to be fully implemented
-        bOk = bOk && SetDriverToFallThruTo(*g_driver);
-        CMIUtilString strOtherDrvErrMsg;
-        if (bOk && GetEnableFallThru() && !g_driver->MISetup(strOtherDrvErrMsg))
-        {
-            bOk = false;
-            errMsg = CMIUtilString::Format(MIRSRC(IDS_MI_INIT_ERR_FALLTHRUDRIVER), strOtherDrvErrMsg.c_str());
-        }
-    }
-#endif // MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER
-
     m_bExitApp = false;
 
     m_bInitialized = bOk;
@@ -403,8 +387,8 @@ CMIDriver::DoParseArgs(const int argc, c
 //          that are only handled by *this driver:
 //              --executable
 //          The application's options --interpreter and --executable in code act very similar.
-//          The --executable is necessary to differentiate whither the MI Driver is being
-//          using by a client i.e. Eclipse or from the command line. Eclipse issues the option
+//          The --executable is necessary to differentiate whether the MI Driver is being
+//          used by a client i.e. Eclipse or from the command line. Eclipse issues the option
 //          --interpreter and also passes additional arguments which can be interpreted as an
 //          executable if called from the command line. Using --executable tells the MI
 //          Driver is being called the command line and that the executable argument is indeed
@@ -461,13 +445,7 @@ CMIDriver::ParseArgs(const int argc, con
 
     if (bHaveExecutableFileNamePath && bHaveExecutableLongOption)
     {
-// CODETAG_CMDLINE_ARG_EXECUTABLE_DEBUG_SESSION
-#if MICONFIG_ENABLE_MI_DRIVER_MI_MODE_CMDLINE_ARG_EXECUTABLE_DEBUG_SESSION
         SetDriverDebuggingArgExecutable();
-#else
-        vwbExiting = true;
-        errStatus.SetErrorString(MIRSRC(IDS_DRIVER_ERR_LOCAL_DEBUG_NOT_IMPL));
-#endif // MICONFIG_ENABLE_MI_DRIVER_MI_MODE_CMDLINE_ARG_EXECUTABLE_DEBUG_SESSION
     }
 
     return errStatus;
@@ -554,8 +532,6 @@ CMIDriver::DoMainLoop(void)
     // App is not quitting currently
     m_bExitApp = false;
 
-// CODETAG_CMDLINE_ARG_EXECUTABLE_DEBUG_SESSION
-#if MICONFIG_ENABLE_MI_DRIVER_MI_MODE_CMDLINE_ARG_EXECUTABLE_DEBUG_SESSION
     if (HaveExecutableFileNamePathOnCmdLine())
     {
         if (!LocalDebugSessionStartupExecuteCommands())
@@ -564,7 +540,6 @@ CMIDriver::DoMainLoop(void)
             return MIstatus::failure;
         }
     }
-#endif // MICONFIG_ENABLE_MI_DRIVER_MI_MODE_CMDLINE_ARG_EXECUTABLE_DEBUG_SESSION
 
     // While the app is active
     while (!m_bExitApp)

Modified: lldb/trunk/tools/lldb-mi/MIDriverMain.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIDriverMain.cpp?rev=232621&r1=232620&r2=232621&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIDriverMain.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MIDriverMain.cpp Wed Mar 18 05:07:46 2015
@@ -41,43 +41,11 @@
 #include "MIUtilDebug.h"
 #include "MICmnLog.h"
 
-#if MICONFIG_COMPILE_MIDRIVER_VERSION
 
 #if defined(_MSC_VER)
 #pragma warning(once : 4530) // Warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
 #endif                       // _MSC_VER
 
-// ToDo: Reevaluate if this function needs to be implemented like the UNIX equivalent
-// CODETAG_IOR_SIGNALS
-//++ ------------------------------------------------------------------------------------
-// Details: The SIGWINCH signal is sent to a process when its controlling terminal
-//          changes its size (a window change).
-// Type:    Function.
-// Args:    vSigno  - (R) Signal number.
-// Return:  None.
-// Throws:  None.
-//--
-void
-sigwinch_handler(int vSigno)
-{
-#ifdef _WIN32 // Restore handler as it is not persistent on Windows
-    signal(SIGWINCH, sigwinch_handler);
-#endif
-    MIunused(vSigno);
-
-    struct winsize window_size;
-    if (::isatty(STDIN_FILENO) && ::ioctl(STDIN_FILENO, TIOCGWINSZ, &window_size) == 0)
-    {
-        CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance();
-        if (window_size.ws_col > 0)
-        {
-            rDriverMgr.DriverResizeWindow((uint32_t)window_size.ws_col);
-        }
-    }
-
-    CMICmnLog::Instance().WriteLog(CMIUtilString::Format(MIRSRC(IDS_PROCESS_SIGNAL_RECEIVED), "SIGWINCH", vSigno));
-}
-
 // CODETAG_IOR_SIGNALS
 //++ ------------------------------------------------------------------------------------
 // Details: The SIGINT signal is sent to a process by its controlling terminal when a
@@ -115,69 +83,6 @@ sigint_handler(int vSigno)
     rDriverMgr.DeliverSignal (vSigno);
 }
 
-// ToDo: Reevaluate if this function needs to be implemented like the UNIX equivalent
-// CODETAG_IOR_SIGNALS
-//++ ------------------------------------------------------------------------------------
-// Details: The SIGTSTP signal is sent to a process by its controlling terminal to
-//          request it to stop temporarily. It is commonly initiated by the user pressing
-//          Control-Z. Unlike SIGSTOP, the process can register a signal handler for or
-//          ignore the signal.
-//          *** The function does not behave ATM like the UNIX equivalent ***
-// Type:    Function.
-// Args:    vSigno  - (R) Signal number.
-// Return:  None.
-// Throws:  None.
-//--
-void
-sigtstp_handler(int vSigno)
-{
-#ifdef _WIN32 // Restore handler as it is not persistent on Windows
-    signal(SIGTSTP, sigtstp_handler);
-#endif
-    CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance();
-    lldb::SBDebugger *pDebugger = rDriverMgr.DriverGetTheDebugger();
-    if (pDebugger != nullptr)
-    {
-        pDebugger->SaveInputTerminalState();
-    }
-
-    CMICmnLog::Instance().WriteLog(CMIUtilString::Format(MIRSRC(IDS_PROCESS_SIGNAL_RECEIVED), "SIGTSTP", vSigno));
-
-    // Send signal to driver so that it can take suitable action
-    rDriverMgr.DeliverSignal (vSigno);
-}
-
-// ToDo: Reevaluate if this function needs to be implemented like the UNIX equivalent
-// CODETAG_IOR_SIGNALS
-//++ ------------------------------------------------------------------------------------
-// Details: The SIGCONT signal instructs the operating system to continue (restart) a
-//          process previously paused by the SIGSTOP or SIGTSTP signal. One important use
-//          of this signal is in job control in the UNIX shell.
-//          *** The function does not behave ATM like the UNIX equivalent ***
-// Type:    Function.
-// Args:    vSigno  - (R) Signal number.
-// Return:  None.
-// Throws:  None.
-//--
-void
-sigcont_handler(int vSigno)
-{
-#ifdef _WIN32 // Restore handler as it is not persistent on Windows
-    signal(SIGCONT, sigcont_handler);
-#endif
-    CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance();
-    lldb::SBDebugger *pDebugger = rDriverMgr.DriverGetTheDebugger();
-    if (pDebugger != nullptr)
-    {
-        pDebugger->RestoreInputTerminalState();
-    }
-
-    CMICmnLog::Instance().WriteLog(CMIUtilString::Format(MIRSRC(IDS_PROCESS_SIGNAL_RECEIVED), "SIGCONT", vSigno));
-
-    // Send signal to driver so that it can take suitable action
-    rDriverMgr.DeliverSignal (vSigno);
-}
-
 //++ ------------------------------------------------------------------------------------
 // Details: Init the MI driver system. Initialize the whole driver system which includes
 //          both the original LLDB driver and the MI driver.
@@ -191,13 +96,6 @@ bool
 DriverSystemInit(void)
 {
     bool bOk = MIstatus::success;
-
-#if MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER
-    Driver *pDriver = Driver::CreateSelf();
-    if (pDriver == nullptr)
-        return MIstatus::failure;
-#endif // MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER
-
     CMIDriver &rMIDriver = CMIDriver::Instance();
     CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance();
     bOk = rDriverMgr.Initialize();
@@ -226,66 +124,9 @@ DriverSystemShutdown(const bool vbAppExi
 
     // *** Order is important here ***
     CMIDriverMgr::Instance().Shutdown();
-
-#if MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER
-    delete g_driver;
-    g_driver = nullptr;
-#endif // MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER
-
     return bOk;
 }
 
-#else
-void
-sigwinch_handler(int signo)
-{
-    struct winsize window_size;
-    if (isatty(STDIN_FILENO) && ::ioctl(STDIN_FILENO, TIOCGWINSZ, &window_size) == 0)
-    {
-        if ((window_size.ws_col > 0) && g_driver != NULL)
-        {
-            g_driver->ResizeWindow(window_size.ws_col);
-        }
-    }
-}
-
-void
-sigint_handler(int signo)
-{
-    static bool g_interrupt_sent = false;
-    if (g_driver)
-    {
-        if (!g_interrupt_sent)
-        {
-            g_interrupt_sent = true;
-            g_driver->GetDebugger().DispatchInputInterrupt();
-            g_interrupt_sent = false;
-            return;
-        }
-    }
-
-    exit(signo);
-}
-
-void
-sigtstp_handler(int signo)
-{
-    g_driver->GetDebugger().SaveInputTerminalState();
-    signal(signo, SIG_DFL);
-    kill(getpid(), signo);
-    signal(signo, sigtstp_handler);
-}
-
-void
-sigcont_handler(int signo)
-{
-    g_driver->GetDebugger().RestoreInputTerminalState();
-    signal(signo, SIG_DFL);
-    kill(getpid(), signo);
-    signal(signo, sigcont_handler);
-}
-#endif // #if MICONFIG_COMPILE_MIDRIVER_VERSION
-
 //++ ------------------------------------------------------------------------------------
 // Details: MI's application start point of execution. The applicaton runs in two modes.
 //          An LLDB native driver mode where it acts no different from the LLDB driver.
@@ -306,7 +147,6 @@ sigcont_handler(int signo)
 //              -1000   = Program failed did not initailize successfully.
 // Throws:  None.
 //--
-#if MICONFIG_COMPILE_MIDRIVER_VERSION
 int
 main(int argc, char const *argv[])
 {
@@ -327,11 +167,7 @@ main(int argc, char const *argv[])
     }
 
     // CODETAG_IOR_SIGNALS
-    signal(SIGPIPE, SIG_IGN);
-    signal(SIGWINCH, sigwinch_handler);
     signal(SIGINT, sigint_handler);
-    signal(SIGTSTP, sigtstp_handler);
-    signal(SIGCONT, sigcont_handler);
 
     bool bExiting = false;
     CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance();
@@ -348,42 +184,3 @@ main(int argc, char const *argv[])
 
     return appResult;
 }
-#else  // Operate the lldb Driver only version of the code
-int
-main(int argc, char const *argv[], char *envp[])
-{
-    MIunused(envp);
-    using namespace lldb;
-    SBDebugger::Initialize();
-
-    SBHostOS::ThreadCreated("<lldb.driver.main-thread>");
-
-    signal(SIGPIPE, SIG_IGN);
-    signal(SIGWINCH, sigwinch_handler);
-    signal(SIGINT, sigint_handler);
-    signal(SIGTSTP, sigtstp_handler);
-    signal(SIGCONT, sigcont_handler);
-
-    // Create a scope for driver so that the driver object will destroy itself
-    // before SBDebugger::Terminate() is called.
-    {
-        Driver driver;
-
-        bool exiting = false;
-        SBError error(driver.ParseArgs(argc, argv, stdout, exiting));
-        if (error.Fail())
-        {
-            const char *error_cstr = error.GetCString();
-            if (error_cstr)
-                ::fprintf(stderr, "error: %s\n", error_cstr);
-        }
-        else if (!exiting)
-        {
-            driver.MainLoop();
-        }
-    }
-
-    SBDebugger::Terminate();
-    return 0;
-}
-#endif // MICONFIG_COMPILE_MIDRIVER_VERSION

Modified: lldb/trunk/tools/lldb-mi/MIDriverMgr.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIDriverMgr.cpp?rev=232621&r1=232620&r2=232621&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIDriverMgr.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MIDriverMgr.cpp Wed Mar 18 05:07:46 2015
@@ -539,11 +539,7 @@ CMIDriverMgr::ParseArgs(const int argc,
     bool bHaveArgLog = false;
     bool bHaveArgHelp = false;
 
-// Hardcode the use of the MI driver
-#if MICONFIG_DEFAULT_TO_MI_DRIVER
     bHaveArgInterpret = true;
-#endif // MICONFIG_DEFAULT_TO_MI_DRIVER
-
     if (bHaveArgs)
     {
         // CODETAG_MIDRIVE_CMD_LINE_ARG_HANDLING

Modified: lldb/trunk/tools/lldb-mi/MIReadMe.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIReadMe.txt?rev=232621&r1=232620&r2=232621&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIReadMe.txt (original)
+++ lldb/trunk/tools/lldb-mi/MIReadMe.txt Wed Mar 18 05:07:46 2015
@@ -5,16 +5,6 @@
 The MI Driver is a stand alone executable that either be used via a 
 client i.e. Eclipse or directly from the command line. 
 
-The MI Driver has two modes of operation; LLDB and MI. The MI Driver (CMIDriver)
-which operates the MI mode is a driver in its own right to work alongside
-the LLDB driver (driver .h/.cpp). Only one is operatational at a time depending
-on the options entered on the command line. The MI Driver reads MI inputs and
-outputs MI responses to be interpreted by a client i.e. Eclipse. 
-Should the MI Driver not understand an instruction it could be passed to the 
-LLDB driver for interpretation (MI Driver build configuration dependant). Should 
-the LLDB driver mode be chosen then it the MI Driver will behave as the normal 
-LLDB driver.
-
 For help information on using the MI driver type at the command line:
 
 	lldb-mi --interpreter --help
@@ -33,12 +23,7 @@ registered in the MI Driver's Command Fa
 will be generated.
 
 All the files prefix with MI are specifically for the MI driver code only.
-Non prefixed code is the original LLDB driver which has been left untouched
-as much as possible. This allows the LLDB driver code to develop 
-independently and make future integration more straight forward. 
-
-File MIDriverMain.cpp contains the executables main() function and some 
-common global functions common to the two drivers.
+File MIDriverMain.cpp contains the executables main() function.
 
 =========================================================================
 Current limitations:





More information about the lldb-commits mailing list