Index: /trunk/include/VBox/dbggui.h
===================================================================
--- /trunk/include/VBox/dbggui.h	(revision 12423)
+++ /trunk/include/VBox/dbggui.h	(revision 12424)
@@ -48,4 +48,28 @@
 typedef struct DBGGUI *PDBGGUI;
 
+/** Virtual method table for the debugger GUI. */
+typedef struct DBGGUIVT
+{
+    /** The version. (DBGGUIVT_VERSION) */
+    uint32_t u32Version;
+    /** @copydoc DBGGuiDestroy */
+    DECLCALLBACKMEMBER(int,  pfnDestroy)(PDBGGUI pGui);
+    /** @copydoc DBGGuiAdjustRelativePos */
+    DECLCALLBACKMEMBER(void, pfnAdjustRelativePos)(PDBGGUI pGui, int x, int y, unsigned cx, unsigned cy);
+    /** @copydoc DBGGuiShowStatistics */
+    DECLCALLBACKMEMBER(int,  pfnShowStatistics)(PDBGGUI pGui);
+    /** @copydoc DBGGuiShowCommandLine */
+    DECLCALLBACKMEMBER(int,  pfnShowCommandLine)(PDBGGUI pGui);
+    /** The end version. (DBGGUIVT_VERSION) */
+    uint32_t u32EndVersion;
+} DBGGUIVT;
+/** Pointer to the virtual method table for the debugger GUI. */
+typedef DBGGUIVT const *PCDBGGUIVT;
+/** The u32Version value.
+ * The first byte is the minor version, the 2nd byte is major version number.
+ * The high 16-bit word is a magic.  */
+#define DBGGUIVT_VERSION 0xbead0100
+
+
 /**
  * Creates the debugger GUI.
@@ -54,6 +78,12 @@
  * @param   pSession    The VirtualBox session.
  * @param   ppGui       Where to store the pointer to the debugger instance.
+ * @param   ppGuiVT     Where to store the virtual method table pointer.
+ *                      Optional.
  */
-DBGDECL(int) DBGGuiCreate(ISession *pSession, PDBGGUI *ppGui);
+DBGDECL(int) DBGGuiCreate(ISession *pSession, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT);
+/** @copydoc DBGGuiCreate. */
+typedef DECLCALLBACK(int) FNDBGGUICREATE(ISession *pSession, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT);
+/** Pointer to DBGGuiCreate. */
+typedef FNDBGGUICREATE *PFNDBGGUICREATE;
 
 /**
Index: /trunk/src/VBox/Debugger/VBoxDbg.cpp
===================================================================
--- /trunk/src/VBox/Debugger/VBoxDbg.cpp	(revision 12423)
+++ /trunk/src/VBox/Debugger/VBoxDbg.cpp	(revision 12424)
@@ -20,5 +20,7 @@
  */
 
-
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
 #define VBOX_COM_NO_ATL
 #include <VBox/dbggui.h>
@@ -31,4 +33,7 @@
 
 
+/*******************************************************************************
+*   Structures and Typedefs                                                    *
+*******************************************************************************/
 /**
  * Debugger GUI instance data.
@@ -42,6 +47,24 @@
 } DBGGUI;
 
-/** DBGGUI magic value (Elizabeth Kostova). */
-#define DBGGUI_MAGIC    0x19640804
+/** DBGGUI magic value (Werner Heisenberg). */
+#define DBGGUI_MAGIC        0x19011205
+/** Invalid DBGGUI magic value. */
+#define DBGGUI_MAGIC_DEAD   0x19760201
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+/** Virtual method table for simplifying dynamic linking. */
+static const DBGGUIVT g_dbgGuiVT =
+{
+    DBGGUIVT_VERSION,
+    DBGGuiDestroy,
+    DBGGuiAdjustRelativePos,
+    DBGGuiShowStatistics,
+    DBGGuiShowCommandLine,
+    DBGGUIVT_VERSION
+};
+
 
 
@@ -52,6 +75,8 @@
  * @param   pSession    The Virtual Box session.
  * @param   ppGui       Where to store the pointer to the debugger instance.
+ * @param   ppGuiVT     Where to store the virtual method table pointer.
+ *                      Optional.
  */
-DBGDECL(int) DBGGuiCreate(ISession *pSession, PDBGGUI *ppGui)
+DBGDECL(int) DBGGuiCreate(ISession *pSession, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
 {
     PDBGGUI pGui = (PDBGGUI)RTMemAlloc(sizeof(*pGui));
@@ -65,4 +90,6 @@
     {
         *ppGui = pGui;
+        if (ppGuiVT)
+            *ppGuiVT = &g_dbgGuiVT;
         return rc;
     }
@@ -71,4 +98,6 @@
     RTMemFree(pGui);
     *ppGui = NULL;
+    if (ppGuiVT)
+        *ppGuiVT = NULL;
     return rc;
 }
@@ -93,5 +122,5 @@
      * Do the job.
      */
-    pGui->u32Magic++;
+    pGui->u32Magic = DBGGUI_MAGIC_DEAD;
     delete pGui->pVBoxDbgGui;
     RTMemFree(pGui);
Index: /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp	(revision 12423)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp	(revision 12424)
@@ -2187,5 +2187,5 @@
     setWindowState (windowState() ^ WindowFullScreen);
 
-#ifdef Q_WS_MAC 
+#ifdef Q_WS_MAC
     if (aOn && aSeamless)
     {
@@ -3448,5 +3448,5 @@
     if (dbg_gui)
         return true;
-    int rc = DBGGuiCreate (csession.iface(), &dbg_gui);
+    int rc = DBGGuiCreate (csession.iface(), &dbg_gui, NULL);
     if (VBOX_SUCCESS (rc))
     {
Index: /trunk/src/VBox/Frontends/VirtualBox4/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox4/Makefile.kmk	(revision 12423)
+++ /trunk/src/VBox/Frontends/VirtualBox4/Makefile.kmk	(revision 12424)
@@ -152,8 +152,6 @@
 VirtualBox4_DEFS.win       = VBOX_GUI_USE_QIMAGE UNICODE QT_DLL
 VirtualBox4_DEFS.win.amd64 = VBOX_WITHOUT_QHTTP
-#ifndef VBOX_OSE
 ## @todo VBOX_WITH_HACKED_QT doesn't apply to Qt4, so why is this still here?
- VirtualBox4_DEFS.darwin  += VBOX_WITH_HACKED_QT
-#endif
+VirtualBox4_DEFS.darwin  += VBOX_WITH_HACKED_QT
 ifdef VBOX_WITH_ICHAT_THEATER
  VirtualBox4_DEFS.darwin += VBOX_WITH_ICHAT_THEATER
@@ -225,15 +223,4 @@
  VirtualBox4_LIBS         += $(PATH_DLL)/VBoxKeyboard$(VBOX_SUFF_DLL)
 endif
-
-if "$(USER)" == "bird"
-ifdef VBOX_WITH_DEBUGGER_GUI ## @todo make this dynamically loadable and ship with release builds too.
- ifeq ($(KBUILD_TARGET),win)
-  VirtualBox4_LIBS        += $(PATH_LIB)/VBoxDbg$(VBOX_SUFF_LIB)
- else
-  VirtualBox4_LIBS        += $(PATH_DLL)/VBoxDbg$(VBOX_SUFF_DLL)
- endif
-endif
-endif
-
 
 # Headers containing definitions of classes that use the Q_OBJECT macro.
Index: /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleWnd.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleWnd.h	(revision 12423)
+++ /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleWnd.h	(revision 12424)
@@ -36,5 +36,5 @@
 #include <QDialog>
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
 # include <VBox/dbggui.h>
 #endif
@@ -104,5 +104,5 @@
     void retranslateUi();
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     bool dbgCreated();
     void dbgDestroy();
@@ -193,4 +193,5 @@
     void dbgShowStatistics();
     void dbgShowCommandLine();
+    void dbgLoggingToggled(bool aBool);
 
     void onExitFullscreen();
@@ -234,8 +235,9 @@
     QAction *devicesInstallGuestToolsAction;
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     // Debugger actions
     QAction *dbgStatisticsAction;
     QAction *dbgCommandLineAction;
+    QAction *dbgLoggingAction;
 #endif
 
@@ -264,5 +266,5 @@
     VBoxUSBMenu *mDevicesUSBMenu;
     /* VBoxSwitchMenu *mDevicesVRDPMenu; */
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     // Debugger popup menu
     QMenu *mDbgMenu;
@@ -324,7 +326,9 @@
     bool mIsAutoSaveMedia : 1;
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
-    // Debugger GUI
-    PDBGGUI dbg_gui;
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    /** The handle to the debugger gui. */
+    PDBGGUI mDbgGui;
+    /** The virtual method table for the debugger GUI. */
+    PCDBGGUIVT mDbgGuiVT;
 #endif
 
Index: /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h	(revision 12423)
+++ /trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h	(revision 12424)
@@ -237,7 +237,8 @@
     const char *vmRenderModeStr() const { return vm_render_mode_str; }
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
-    bool isDebuggerEnabled() const { return dbg_enabled; }
-    bool isDebuggerVisibleAtStartup() const { return dbg_visible_at_startup; }
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    bool isDebuggerEnabled() const { return mDbgEnabled; }
+    bool isDebuggerAutoShowEnabled() const { return mDbgAutoShow; }
+    RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; }
 #endif
 
@@ -716,7 +717,14 @@
     const char * vm_render_mode_str;
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
-    bool dbg_enabled;
-    bool dbg_visible_at_startup;
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    /** Whether the debugger should be accessible or not.
+     * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
+     * VBOX_GUI_DBG_AUTO_SHOW to enable. */
+    bool mDbgEnabled;
+    /** Whether to show the debugger automatically with the console.
+     * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
+    bool mDbgAutoShow;
+    /** VBoxDbg module handle. */
+    RTLDRMOD mhVBoxDbg;
 #endif
 
Index: /trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp	(revision 12423)
+++ /trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp	(revision 12424)
@@ -63,6 +63,7 @@
 #endif
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
-#include <VBox/err.h>
+#ifdef VBOX_WITH_DEBUGGER_GUI
+# include <VBox/err.h>
+# include <iprt/ldr.h>
 #endif
 
@@ -115,7 +116,8 @@
     : QIWithRetranslateUI2<QMainWindow> (aParent, aFlags)
     , mMainMenu (0)
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     , dbgStatisticsAction (NULL)
     , dbgCommandLineAction (NULL)
+    , dbgLoggingAction (NULL)
     , mDbgMenu (NULL)
 #endif
@@ -133,6 +135,7 @@
     , mIsFirstTimeStarted (false)
     , mIsAutoSaveMedia (true)
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
-    , dbg_gui (NULL)
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    , mDbgGui (NULL)
+    , mDbgGuiVT (NULL)
 #endif
 #ifdef Q_WS_MAC
@@ -262,9 +265,12 @@
                                                                      ":/guesttools_disabled_16px.png"));
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     if (vboxGlobal().isDebuggerEnabled())
     {
         dbgStatisticsAction = new QAction (this);
         dbgCommandLineAction = new QAction (this);
+        dbgLoggingAction = new QAction (this);
+        dbgLoggingAction->setCheckable (true);
+        dbgLoggingAction->setIcon (VBoxGlobal::iconSet (":/start_16px.png")); /// @todo find the default check boxes.
     }
     else
@@ -272,4 +278,5 @@
         dbgStatisticsAction = NULL;
         dbgCommandLineAction = NULL;
+        dbgLoggingAction = NULL;
     }
 #endif
@@ -355,5 +362,5 @@
     mDevicesUSBMenu->menuAction()->setData (false);
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     /* Debug popup menu */
     if (vboxGlobal().isDebuggerEnabled())
@@ -363,4 +370,5 @@
         mDbgMenu->addAction (dbgStatisticsAction);
         mDbgMenu->addAction (dbgCommandLineAction);
+        mDbgMenu->addAction (dbgLoggingAction);
     }
     else
@@ -555,5 +563,5 @@
              this, SLOT (processGlobalSettingChange (const char *, const char *)));
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     if (dbgStatisticsAction)
         connect (dbgStatisticsAction, SIGNAL (triggered()),
@@ -562,4 +570,7 @@
         connect (dbgCommandLineAction, SIGNAL (triggered()),
                  this, SLOT (dbgShowCommandLine()));
+    if (dbgLoggingAction)
+        connect (dbgLoggingAction, SIGNAL (toggled (bool)),
+                 this, SLOT (dbgLoggingToggled (bool)));
 #endif
 
@@ -852,4 +863,14 @@
     console->onViewOpened();
 
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    /* open debugger windows if requested */
+    if (vboxGlobal().isDebuggerAutoShowEnabled())
+    {
+        move (QPoint (0, 0));
+        dbgShowStatistics();
+        dbgShowCommandLine();
+    }
+#endif
+
     bool saved = machine_state == KMachineState_Saved;
 
@@ -918,14 +939,4 @@
         return;
     }
-
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
-    /* open debugger windows if requested */
-    if (vboxGlobal().isDebuggerVisibleAtStartup())
-    {
-        move (QPoint (0, 0));
-        dbgShowStatistics();
-        dbgShowCommandLine();
-    }
-#endif
 
     /* Currently the machine is started and the guest API could be used...
@@ -1100,5 +1111,5 @@
             {
                 mNormalGeo.setSize (re->size());
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
                 dbgAdjustRelativePos();
 #endif
@@ -1120,5 +1131,5 @@
             {
                 mNormalGeo.moveTo (geometry().x(), geometry().y());
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
                 dbgAdjustRelativePos();
 #endif
@@ -1539,5 +1550,5 @@
         tr ("Mount the Guest Additions installation image"));
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     /* Debug actions */
 
@@ -1546,4 +1557,6 @@
     if (dbgCommandLineAction)
         dbgCommandLineAction->setText (tr ("&Command Line...", "debug action"));
+    if (dbgLoggingAction)
+        dbgLoggingAction->setText (tr ("&Logging...", "debug action"));
 #endif
 
@@ -1567,5 +1580,5 @@
 //    mDevicesMenu->setIcon (VBoxGlobal::iconSet (":/settings_16px.png"));
 
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     if (vboxGlobal().isDebuggerEnabled())
         mDbgMenu->setTitle (tr ("De&bug"));
@@ -3391,7 +3404,7 @@
 void VBoxConsoleWnd::dbgShowStatistics()
 {
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     if (dbgCreated())
-        DBGGuiShowStatistics (dbg_gui);
+        mDbgGuiVT->pfnShowStatistics (mDbgGui);
 #endif
 }
@@ -3402,11 +3415,28 @@
 void VBoxConsoleWnd::dbgShowCommandLine()
 {
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+#ifdef VBOX_WITH_DEBUGGER_GUI
     if (dbgCreated())
-        DBGGuiShowCommandLine (dbg_gui);
-#endif
-}
-
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
+        mDbgGuiVT->pfnShowCommandLine (mDbgGui);
+#endif
+}
+
+/**
+ * Called when the Debug->Logging menu item is selected.
+ */
+void VBoxConsoleWnd::dbgLoggingToggled(bool aState)
+{
+    NOREF(aState);
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    CConsole cconsole = csession.GetConsole();
+    if (cconsole.isOk())
+    {
+        CMachineDebugger cdebugger = cconsole.GetDebugger();
+        if (cconsole.isOk())
+            cdebugger.SetLogEnabled(aState);
+    }
+#endif
+}
+
+#ifdef VBOX_WITH_DEBUGGER_GUI
 
 /**
@@ -3418,12 +3448,28 @@
 bool VBoxConsoleWnd::dbgCreated()
 {
-    if (dbg_gui)
+    if (mDbgGui)
         return true;
-    int rc = DBGGuiCreate (csession.iface(), &dbg_gui);
-    if (VBOX_SUCCESS (rc))
-    {
-        dbgAdjustRelativePos();
-        return true;
-    }
+
+    RTLDRMOD hLdrMod = vboxGlobal().getDebuggerModule();
+    if (hLdrMod == NIL_RTLDRMOD)
+        return false;
+
+    PFNDBGGUICREATE pfnGuiCreate;
+    int rc = RTLdrGetSymbol (hLdrMod, "DBGGuiCreate", (void **)&pfnGuiCreate);
+    if (RT_SUCCESS (rc))
+    {
+        rc = pfnGuiCreate (csession.iface(), &mDbgGui, &mDbgGuiVT);
+        if (RT_SUCCESS (rc))
+        {
+            dbgAdjustRelativePos();
+            return true;
+        }
+        LogRel(("DBGGuiCreate failed, rc=%Rrc\n", rc));
+    }
+    else
+        LogRel(("RTLdrGetSymbol(,\"DBGGuiCreate\",) -> %Rrc\n", rc));
+
+    mDbgGui = NULL;
+    mDbgGuiVT = NULL;
     return false;
 }
@@ -3434,8 +3480,9 @@
 void VBoxConsoleWnd::dbgDestroy()
 {
-    if (dbg_gui)
-    {
-        DBGGuiDestroy (dbg_gui);
-        dbg_gui = NULL;
+    if (mDbgGui)
+    {
+        mDbgGuiVT->pfnDestroy (mDbgGui);
+        mDbgGui = NULL;
+        mDbgGuiVT = NULL;
     }
 }
@@ -3446,12 +3493,12 @@
 void VBoxConsoleWnd::dbgAdjustRelativePos()
 {
-    if (dbg_gui)
+    if (mDbgGui)
     {
         QRect rct = frameGeometry();
-        DBGGuiAdjustRelativePos (dbg_gui, rct.x(), rct.y(), rct.width(), rct.height());
-    }
-}
-
-#endif
+        mDbgGuiVT->pfnAdjustRelativePos (mDbgGui, rct.x(), rct.y(), rct.width(), rct.height());
+    }
+}
+
+#endif /* VBOX_WITH_DEBUGGER_GUI */
 
 VBoxSFDialog::VBoxSFDialog (QWidget *aParent, CSession &aSession)
Index: /trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp	(revision 12423)
+++ /trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp	(revision 12424)
@@ -85,4 +85,5 @@
 #include <iprt/env.h>
 #include <iprt/file.h>
+#include <iprt/ldr.h>
 
 #if defined (Q_WS_X11)
@@ -4000,5 +4001,5 @@
 /**
  * Automatically figure out which hdd backends are currently support by vbox.
- * Returned is a list of pairs with the form 
+ * Returned is a list of pairs with the form
  * <"Backend Name", "*.suffix1 *.suffix2 ...">.
  */
@@ -4510,11 +4511,11 @@
 
     vm_render_mode_str = 0;
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
-#ifdef VBOX_WITH_DEBUGGER_GUI_MENU
-    dbg_enabled = true;
-#else
-    dbg_enabled = false;
-#endif
-    dbg_visible_at_startup = false;
+#ifdef VBOX_WITH_DEBUGGER_GUI
+# ifdef VBOX_WITH_DEBUGGER_GUI_MENU
+    mDbgEnabled = true;
+# else
+    mDbgEnabled = RTEnvExist("VBOX_GUI_DBG_ENABLED");
+# endif
+    mDbgAutoShow = RTEnvExist("VBOX_GUI_DBG_AUTO_SHOW");
 #endif
 
@@ -4555,23 +4556,21 @@
                 vm_render_mode_str = qApp->argv() [i];
         }
-#if defined(VBOX_WITH_DEBUGGER_GUI) && 0
-        else if (!::strcmp (arg, "-dbg"))
-        {
-            dbg_enabled = true;
-        }
-#ifdef DEBUG
-        else if (!::strcmp (arg, "-nodebug"))
-        {
-            dbg_enabled = false;
-            dbg_visible_at_startup = false;
-        }
-#else
-        else if (!::strcmp( arg, "-debug"))
-        {
-            dbg_enabled = true;
-            dbg_visible_at_startup = true;
+#ifdef VBOX_WITH_DEBUGGER_GUI
+        else if (!::strcmp (arg, "-dbg") || !::strcmp (arg, "--dbg"))
+        {
+            mDbgEnabled = true;
+        }
+        else if (!::strcmp( arg, "-debug") || !::strcmp( arg, "--debug"))
+        {
+            mDbgEnabled = true;
+            mDbgAutoShow = true;
+        }
+        else if (!::strcmp (arg, "-no-debug") || !::strcmp (arg, "--no-debug"))
+        {
+            mDbgEnabled = false;
+            mDbgAutoShow = false;
         }
 #endif
-#endif
+        /** @todo add an else { msgbox(syntax error); exit(1); } here, pretty please... */
         i++;
     }
@@ -4585,4 +4584,20 @@
     if (!mVBox.isOk())
         return;
+
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    /* setup the debugger gui. */
+    if (RTEnvExist("VBOX_GUI_NO_DEBUGGER"))
+        mDbgEnabled = mDbgAutoShow = false;
+    if (mDbgEnabled)
+    {
+        int rc = SUPR3HardenedLdrLoadAppPriv("VBoxDbg", &mhVBoxDbg);
+        if (RT_FAILURE(rc))
+        {
+            mhVBoxDbg = NIL_RTLDRMOD;
+            mDbgAutoShow = false;
+            LogRel(("Failed to load VBoxDbg, rc=%Rrc\n", rc));
+        }
+    }
+#endif
 
     mValid = true;
