VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbgConsole.cpp@ 12880

Last change on this file since 12880 was 12880, checked in by vboxsync, 17 years ago

Debugger: fixed busy/ready.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.9 KB
Line 
1/* $Id: VBoxDbgConsole.cpp 12880 2008-10-01 21:45:19Z vboxsync $ */
2/** @file
3 * VBox Debugger GUI - Console.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_DBGG
27#include "VBoxDbgConsole.h"
28
29#ifdef VBOXDBG_USE_QT4
30# include <QLabel>
31# include <QApplication>
32# include <QFont>
33# include <QLineEdit>
34# include <QHBoxLayout>
35# include <QAction>
36#else
37# include <qlabel.h>
38# include <qapplication.h>
39# include <qfont.h>
40# include <qtextview.h>
41# include <qlineedit.h>
42#endif
43
44#include <VBox/dbg.h>
45#include <VBox/cfgm.h>
46#include <VBox/err.h>
47
48#include <iprt/thread.h>
49#include <iprt/tcp.h>
50#include <VBox/log.h>
51#include <iprt/assert.h>
52#include <iprt/asm.h>
53#include <iprt/alloc.h>
54#include <iprt/string.h>
55
56
57
58
59/*
60 *
61 * V B o x D b g C o n s o l e O u t p u t
62 * V B o x D b g C o n s o l e O u t p u t
63 * V B o x D b g C o n s o l e O u t p u t
64 *
65 *
66 */
67
68
69VBoxDbgConsoleOutput::VBoxDbgConsoleOutput(QWidget *pParent/* = NULL*/, const char *pszName/* = NULL*/)
70#ifdef VBOXDBG_USE_QT4
71 : QTextEdit(pParent),
72#else
73 : QTextEdit(pParent, pszName),
74#endif
75 m_uCurLine(0), m_uCurPos(0), m_hGUIThread(RTThreadNativeSelf())
76{
77 setReadOnly(true);
78 setUndoRedoEnabled(false);
79#ifdef VBOXDBG_USE_QT4
80 setOverwriteMode(false);
81 setPlainText("");
82 setTextInteractionFlags(Qt::TextBrowserInteraction);
83 setAutoFormatting(QTextEdit::AutoAll);
84 setTabChangesFocus(true);
85 setAcceptRichText(false);
86#else
87 setOverwriteMode(true);
88 setTextFormat(PlainText); /* minimal HTML: setTextFormat(LogText); */
89#endif
90
91#ifdef Q_WS_MAC
92 QFont Font("Monaco", 10, QFont::Normal, FALSE);
93 Font.setStyleStrategy(QFont::NoAntialias);
94#else
95 QFont Font = font();
96 Font.setStyleHint(QFont::TypeWriter);
97 Font.setFamily("Courier [Monotype]");
98#endif
99 setFont(Font);
100
101 /* green on black */
102#ifdef VBOXDBG_USE_QT4
103 QPalette Pal(palette());
104 Pal.setColor(QPalette::All, QPalette::Base, QColor(Qt::black));
105 setPalette(Pal);
106 setTextColor(QColor(qRgb(0, 0xe0, 0)));
107#else
108 setPaper(QBrush(Qt::black));
109 setColor(QColor(qRgb(0, 0xe0, 0)));
110#endif
111 NOREF(pszName);
112}
113
114
115VBoxDbgConsoleOutput::~VBoxDbgConsoleOutput()
116{
117 Assert(m_hGUIThread == RTThreadNativeSelf());
118}
119
120
121void
122VBoxDbgConsoleOutput::appendText(const QString &rStr)
123{
124 Assert(m_hGUIThread == RTThreadNativeSelf());
125
126 if (rStr.isEmpty() || rStr.isNull() || !rStr.length())
127 return;
128
129#ifdef VBOXDBG_USE_QT4
130 /*
131 * Insert all in one go and make sure it's visible.
132 */
133 QTextCursor Cursor = textCursor();
134 if (!Cursor.atEnd())
135 moveCursor(QTextCursor::End); /* make sure we append the text */
136 Cursor.insertText(rStr);
137 ensureCursorVisible();
138#else
139 /*
140 * Insert line by line.
141 */
142 unsigned cch = rStr.length();
143 unsigned iPos = 0;
144 while (iPos < cch)
145 {
146 int iPosNL = rStr.find('\n', iPos);
147 int iPosEnd = iPosNL >= 0 ? iPosNL : cch;
148 if ((unsigned)iPosNL != iPos)
149 {
150 QString Str = rStr.mid(iPos, iPosEnd - iPos);
151 if (m_uCurPos == 0)
152 append(Str);
153 else
154 insertAt(Str, m_uCurLine, m_uCurPos);
155 if (iPosNL >= 0)
156 {
157 m_uCurLine++;
158 m_uCurPos = 0;
159 }
160 else
161 m_uCurPos += Str.length();
162 }
163 else
164 {
165 m_uCurLine++;
166 m_uCurPos = 0;
167 }
168
169 /* next */
170 iPos = iPosEnd + 1;
171 }
172#endif
173}
174
175
176
177
178/*
179 *
180 * V B o x D b g C o n s o l e I n p u t
181 * V B o x D b g C o n s o l e I n p u t
182 * V B o x D b g C o n s o l e I n p u t
183 *
184 *
185 */
186
187
188VBoxDbgConsoleInput::VBoxDbgConsoleInput(QWidget *pParent/* = NULL*/, const char *pszName/* = NULL*/)
189#ifdef VBOXDBG_USE_QT4
190 : QComboBox(pParent),
191#else
192 : QComboBox(true, pParent, pszName),
193#endif
194 m_iBlankItem(0), m_hGUIThread(RTThreadNativeSelf())
195{
196#ifdef VBOXDBG_USE_QT4
197 insertItem(m_iBlankItem, "");
198 setEditable(true);
199 setInsertPolicy(NoInsert);
200 setAutoCompletion(false);
201#else
202 insertItem("", m_iBlankItem);
203 setInsertionPolicy(NoInsertion);
204#endif
205 setMaxCount(50);
206 const QLineEdit *pEdit = lineEdit();
207 if (pEdit)
208 connect(pEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
209
210 NOREF(pszName);
211}
212
213
214VBoxDbgConsoleInput::~VBoxDbgConsoleInput()
215{
216 Assert(m_hGUIThread == RTThreadNativeSelf());
217}
218
219
220void
221VBoxDbgConsoleInput::setLineEdit(QLineEdit *pEdit)
222{
223 Assert(m_hGUIThread == RTThreadNativeSelf());
224 QComboBox::setLineEdit(pEdit);
225 if (lineEdit() == pEdit && pEdit)
226 connect(pEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
227}
228
229
230void
231VBoxDbgConsoleInput::returnPressed()
232{
233 Assert(m_hGUIThread == RTThreadNativeSelf());
234 /* deal with the current command. */
235 QString Str = currentText();
236 emit commandSubmitted(Str);
237
238 /* update the history and clear the entry field */
239#ifdef VBOXDBG_USE_QT4
240 if (itemText(m_iBlankItem - 1) != Str)
241 {
242 setItemText(m_iBlankItem, Str);
243 removeItem(m_iBlankItem - maxCount() - 1);
244 insertItem(++m_iBlankItem, "");
245 }
246
247 clearEditText();
248 setCurrentIndex(m_iBlankItem);
249#else
250 if (text(m_iBlankItem - 1) != Str)
251 {
252 changeItem(Str, m_iBlankItem);
253 removeItem(m_iBlankItem - maxCount() - 1);
254 insertItem("", ++m_iBlankItem);
255 }
256
257 clearEdit();
258 setCurrentItem(m_iBlankItem);
259#endif
260}
261
262
263
264
265
266
267/*
268 *
269 * V B o x D b g C o n s o l e
270 * V B o x D b g C o n s o l e
271 * V B o x D b g C o n s o l e
272 *
273 *
274 */
275
276
277VBoxDbgConsole::VBoxDbgConsole(PVM pVM, QWidget *pParent/* = NULL*/, const char *pszName/* = NULL*/)
278 : VBoxDbgBase(pVM), m_pOutput(NULL), m_pInput(NULL), m_fInputRestoreFocus(false),
279 m_pszInputBuf(NULL), m_cbInputBuf(0), m_cbInputBufAlloc(0),
280 m_pszOutputBuf(NULL), m_cbOutputBuf(0), m_cbOutputBufAlloc(0),
281 m_pTimer(NULL), m_fUpdatePending(false), m_Thread(NIL_RTTHREAD), m_EventSem(NIL_RTSEMEVENT), m_fTerminate(false)
282{
283#ifdef VBOXDBG_USE_QT4
284 setWindowTitle("VBoxDbg - Console");
285#else
286 setCaption("VBoxDbg - Console");
287#endif
288
289 NOREF(pszName);
290 NOREF(pParent);
291
292 /*
293 * Create the output text box.
294 */
295 m_pOutput = new VBoxDbgConsoleOutput(this);
296
297 /* try figure a suitable size */
298#ifdef VBOXDBG_USE_QT4
299 QLabel *pLabel = new QLabel( "11111111111111111111111111111111111111111111111111111111111111111111111111111112222222222", this);
300#else
301 QLabel *pLabel = new QLabel(NULL, "11111111111111111111111111111111111111111111111111111111111111111111111111111112222222222", this); /// @todo
302#endif
303 pLabel->setFont(m_pOutput->font());
304 QSize Size = pLabel->sizeHint();
305 delete pLabel;
306 Size.setWidth((int)(Size.width() * 1.10));
307 Size.setHeight(Size.width() / 2);
308 resize(Size);
309
310 /*
311 * Create the input combo box (with a label).
312 */
313#ifdef VBOXDBG_USE_QT4
314 QHBoxLayout *pLayout = new QHBoxLayout();
315 //pLayout->setSizeConstraint(QLayout::SetMaximumSize);
316
317 pLabel = new QLabel(" Command ");
318 pLayout->addWidget(pLabel);
319 pLabel->setMaximumSize(pLabel->sizeHint());
320 pLabel->setAlignment(Qt::AlignCenter);
321
322 m_pInput = new VBoxDbgConsoleInput(NULL);
323 pLayout->addWidget(m_pInput);
324 m_pInput->setDuplicatesEnabled(false);
325 connect(m_pInput, SIGNAL(commandSubmitted(const QString &)), this, SLOT(commandSubmitted(const QString &)));
326
327# if 0//def Q_WS_MAC
328 pLabel = new QLabel(" ");
329 pLayout->addWidget(pLabel);
330 pLabel->setMaximumSize(20, m_pInput->sizeHint().height() + 6);
331 pLabel->setMinimumSize(20, m_pInput->sizeHint().height() + 6);
332# endif
333
334 QWidget *pHBox = new QWidget(this);
335 pHBox->setLayout(pLayout);
336
337#else /* QT3 */
338 QHBox *pHBox = new QHBox(this);
339
340 pLabel = new QLabel(NULL, " Command ", pHBox);
341 pLabel->setMaximumSize(pLabel->sizeHint());
342 pLabel->setAlignment(AlignHCenter | AlignVCenter);
343
344 m_pInput = new VBoxDbgConsoleInput(pHBox);
345 m_pInput->setDuplicatesEnabled(false);
346 connect(m_pInput, SIGNAL(commandSubmitted(const QString &)), this, SLOT(commandSubmitted(const QString &)));
347
348# ifdef Q_WS_MAC
349 pLabel = new QLabel(NULL, " ", pHBox); /// @todo
350 pLabel->setMaximumSize(20, m_pInput->sizeHint().height() + 6);
351 pLabel->setMinimumSize(20, m_pInput->sizeHint().height() + 6);
352# endif
353#endif /* QT3 */
354
355#ifdef VBOXDBG_USE_QT4
356 /*
357 * Vertical layout box on the whole widget.
358 */
359 QVBoxLayout *pVLayout = new QVBoxLayout;
360 pVLayout->setSpacing(5);
361 pVLayout->setContentsMargins(0, 0, 0, 0);
362 pVLayout->addWidget(m_pOutput);
363 pVLayout->addWidget(pHBox);
364 setLayout(pVLayout);
365#endif
366
367 /*
368 * The tab order is from input to output, not the otherway around as it is by default.
369 */
370 setTabOrder(m_pInput, m_pOutput);
371
372 /*
373 * Setup the timer.
374 */
375 m_pTimer = new QTimer(this);
376 connect(m_pTimer, SIGNAL(timeout()), SLOT(updateOutput()));
377
378 /*
379 * Init the backend structure.
380 */
381 m_Back.Core.pfnInput = backInput;
382 m_Back.Core.pfnRead = backRead;
383 m_Back.Core.pfnWrite = backWrite;
384 m_Back.Core.pfnSetReady = backSetReady;
385 m_Back.pSelf = this;
386
387 /*
388 * Create the critical section, the event semaphore and the debug console thread.
389 */
390 int rc = RTCritSectInit(&m_Lock);
391 AssertRC(rc);
392
393 rc = RTSemEventCreate(&m_EventSem);
394 AssertRC(rc);
395
396 rc = RTThreadCreate(&m_Thread, backThread, this, 0, RTTHREADTYPE_DEBUGGER, RTTHREADFLAGS_WAITABLE, "VBoxDbgC");
397 AssertRC(rc);
398 if (VBOX_FAILURE(rc))
399 m_Thread = NIL_RTTHREAD;
400
401#ifdef VBOXDBG_USE_QT4
402 /*
403 * Shortcuts.
404 */
405 m_pFocusToInput = new QAction("", this);
406 m_pFocusToInput->setShortcut(QKeySequence("Ctrl+L"));
407 addAction(m_pFocusToInput);
408 connect(m_pFocusToInput, SIGNAL(triggered(bool)), this, SLOT(actFocusToInput()));
409
410 m_pFocusToOutput = new QAction("", this);
411 m_pFocusToOutput->setShortcut(QKeySequence("Ctrl+O"));
412 addAction(m_pFocusToOutput);
413 connect(m_pFocusToOutput, SIGNAL(triggered(bool)), this, SLOT(actFocusToOutput()));
414#endif
415}
416
417
418VBoxDbgConsole::~VBoxDbgConsole()
419{
420 Assert(isGUIThread());
421
422 /*
423 * Wait for the thread.
424 */
425 ASMAtomicWriteBool(&m_fTerminate, true);
426 RTSemEventSignal(m_EventSem);
427 if (m_Thread != NIL_RTTHREAD)
428 {
429 int rc = RTThreadWait(m_Thread, 15000, NULL);
430 AssertRC(rc);
431 m_Thread = NIL_RTTHREAD;
432 }
433
434 /*
435 * Free resources.
436 */
437 delete m_pTimer;
438 m_pTimer = NULL;
439 RTCritSectDelete(&m_Lock);
440 RTSemEventDestroy(m_EventSem);
441 m_EventSem = 0;
442 m_pOutput = NULL;
443 m_pInput = NULL;
444 if (m_pszInputBuf)
445 {
446 RTMemFree(m_pszInputBuf);
447 m_pszInputBuf = NULL;
448 }
449 m_cbInputBuf = 0;
450 m_cbInputBufAlloc = 0;
451
452#ifdef VBOXDBG_USE_QT4
453 delete m_pFocusToInput;
454 m_pFocusToInput = NULL;
455 delete m_pFocusToOutput;
456 m_pFocusToOutput = NULL;
457#endif
458}
459
460
461void
462VBoxDbgConsole::commandSubmitted(const QString &rCommand)
463{
464 Assert(isGUIThread());
465
466 lock();
467 RTSemEventSignal(m_EventSem);
468
469#ifdef VBOXDBG_USE_QT4
470 QByteArray Utf8Array = rCommand.toUtf8();
471 const char *psz = Utf8Array.constData();
472#else
473 const char *psz = rCommand;//.utf8();
474#endif
475 size_t cb = strlen(psz);
476
477 /*
478 * Make sure we've got space for the input.
479 */
480 if (cb + m_cbInputBuf >= m_cbInputBufAlloc)
481 {
482 size_t cbNew = RT_ALIGN_Z(cb + m_cbInputBufAlloc + 1, 128);
483 void *pv = RTMemRealloc(m_pszInputBuf, cbNew);
484 if (!pv)
485 {
486 unlock();
487 return;
488 }
489 m_pszInputBuf = (char *)pv;
490 m_cbInputBufAlloc = cbNew;
491 }
492
493 /*
494 * Add the input and output it.
495 */
496 memcpy(m_pszInputBuf + m_cbInputBuf, psz, cb);
497 m_cbInputBuf += cb;
498 m_pszInputBuf[m_cbInputBuf++] = '\n';
499
500 m_pOutput->appendText(rCommand + "\n");
501#ifdef VBOXDBG_USE_QT4
502 m_pOutput->ensureCursorVisible();
503#else
504 m_pOutput->scrollToBottom();
505#endif
506
507 m_fInputRestoreFocus = m_pInput->hasFocus(); /* dirty focus hack */
508 m_pInput->setEnabled(false);
509
510 Log(("VBoxDbgConsole::commandSubmitted: %s (input-enabled=%RTbool)\n", psz, m_pInput->isEnabled()));
511 unlock();
512}
513
514
515void
516VBoxDbgConsole::updateOutput()
517{
518 Assert(isGUIThread());
519
520 lock();
521 m_fUpdatePending = false;
522 if (m_cbOutputBuf)
523 {
524 m_pOutput->appendText(QString::fromUtf8((const char *)m_pszOutputBuf, m_cbOutputBuf));
525 m_cbOutputBuf = 0;
526 }
527 unlock();
528}
529
530
531/**
532 * Lock the object.
533 */
534void
535VBoxDbgConsole::lock()
536{
537 RTCritSectEnter(&m_Lock);
538}
539
540
541/**
542 * Unlocks the object.
543 */
544void
545VBoxDbgConsole::unlock()
546{
547 RTCritSectLeave(&m_Lock);
548}
549
550
551
552/**
553 * Checks if there is input.
554 *
555 * @returns true if there is input ready.
556 * @returns false if there not input ready.
557 * @param pBack Pointer to VBoxDbgConsole::m_Back.
558 * @param cMillies Number of milliseconds to wait on input data.
559 */
560/*static*/ DECLCALLBACK(bool)
561VBoxDbgConsole::backInput(PDBGCBACK pBack, uint32_t cMillies)
562{
563 VBoxDbgConsole *pThis = VBOXDBGCONSOLE_FROM_DBGCBACK(pBack);
564 pThis->lock();
565
566 bool fRc = true;
567 if (!pThis->m_cbInputBuf)
568 {
569 /*
570 * Wait outside the lock for the requested time, then check again.
571 */
572 pThis->unlock();
573 RTSemEventWait(pThis->m_EventSem, cMillies);
574 pThis->lock();
575 fRc = pThis->m_cbInputBuf
576 || ASMAtomicUoReadBool(&pThis->m_fTerminate);
577 }
578
579 pThis->unlock();
580 return fRc;
581}
582
583
584/**
585 * Read input.
586 *
587 * @returns VBox status code.
588 * @param pBack Pointer to VBoxDbgConsole::m_Back.
589 * @param pvBuf Where to put the bytes we read.
590 * @param cbBuf Maximum nymber of bytes to read.
591 * @param pcbRead Where to store the number of bytes actually read.
592 * If NULL the entire buffer must be filled for a
593 * successful return.
594 */
595/*static*/ DECLCALLBACK(int)
596VBoxDbgConsole::backRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead)
597{
598 VBoxDbgConsole *pThis = VBOXDBGCONSOLE_FROM_DBGCBACK(pBack);
599 Assert(pcbRead); /** @todo implement this bit */
600 if (pcbRead)
601 *pcbRead = 0;
602
603 pThis->lock();
604 int rc = VINF_SUCCESS;
605 if (!ASMAtomicUoReadBool(&pThis->m_fTerminate))
606 {
607 if (pThis->m_cbInputBuf)
608 {
609 const char *psz = pThis->m_pszInputBuf;
610 size_t cbRead = RT_MIN(pThis->m_cbInputBuf, cbBuf);
611 memcpy(pvBuf, psz, cbRead);
612 psz += cbRead;
613 pThis->m_cbInputBuf -= cbRead;
614 if (*psz)
615 memmove(pThis->m_pszInputBuf, psz, pThis->m_cbInputBuf);
616 pThis->m_pszInputBuf[pThis->m_cbInputBuf] = '\0';
617 *pcbRead = cbRead;
618 }
619 }
620 else
621 rc = VERR_GENERAL_FAILURE;
622 pThis->unlock();
623 return rc;
624}
625
626
627/**
628 * Write (output).
629 *
630 * @returns VBox status code.
631 * @param pBack Pointer to VBoxDbgConsole::m_Back.
632 * @param pvBuf What to write.
633 * @param cbBuf Number of bytes to write.
634 * @param pcbWritten Where to store the number of bytes actually written.
635 * If NULL the entire buffer must be successfully written.
636 */
637/*static*/ DECLCALLBACK(int)
638VBoxDbgConsole::backWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten)
639{
640 VBoxDbgConsole *pThis = VBOXDBGCONSOLE_FROM_DBGCBACK(pBack);
641 int rc = VINF_SUCCESS;
642
643 pThis->lock();
644 if (cbBuf + pThis->m_cbOutputBuf >= pThis->m_cbOutputBufAlloc)
645 {
646 size_t cbNew = RT_ALIGN_Z(cbBuf + pThis->m_cbOutputBufAlloc + 1, 1024);
647 void *pv = RTMemRealloc(pThis->m_pszOutputBuf, cbNew);
648 if (!pv)
649 {
650 pThis->unlock();
651 if (pcbWritten)
652 *pcbWritten = 0;
653 return VERR_NO_MEMORY;
654 }
655 pThis->m_pszOutputBuf = (char *)pv;
656 pThis->m_cbOutputBufAlloc = cbNew;
657 }
658
659 /*
660 * Add the output.
661 */
662 memcpy(pThis->m_pszOutputBuf + pThis->m_cbOutputBuf, pvBuf, cbBuf);
663 pThis->m_cbOutputBuf += cbBuf;
664 pThis->m_pszOutputBuf[pThis->m_cbOutputBuf] = '\0';
665 if (pcbWritten)
666 *pcbWritten = cbBuf;
667
668 if (ASMAtomicUoReadBool(&pThis->m_fTerminate))
669 rc = VERR_GENERAL_FAILURE;
670
671 /*
672 * Tell the GUI thread to draw this text.
673 * We cannot do it from here without frequent crashes.
674 */
675 if (!pThis->m_fUpdatePending)
676 QApplication::postEvent(pThis, new VBoxDbgConsoleEvent(VBoxDbgConsoleEvent::kUpdate));
677
678 pThis->unlock();
679
680 return rc;
681}
682
683
684/*static*/ DECLCALLBACK(void)
685VBoxDbgConsole::backSetReady(PDBGCBACK pBack, bool fReady)
686{
687 VBoxDbgConsole *pThis = VBOXDBGCONSOLE_FROM_DBGCBACK(pBack);
688 if (fReady)
689 QApplication::postEvent(pThis, new VBoxDbgConsoleEvent(VBoxDbgConsoleEvent::kInputEnable));
690}
691
692
693/**
694 * The Debugger Console Thread
695 *
696 * @returns VBox status code (ignored).
697 * @param Thread The thread handle.
698 * @param pvUser Pointer to the VBoxDbgConsole object.s
699 */
700/*static*/ DECLCALLBACK(int)
701VBoxDbgConsole::backThread(RTTHREAD Thread, void *pvUser)
702{
703 VBoxDbgConsole *pThis = (VBoxDbgConsole *)pvUser;
704 LogFlow(("backThread: Thread=%p pvUser=%p\n", (void *)Thread, pvUser));
705
706 NOREF(Thread);
707
708 /*
709 * Create and execute the console.
710 */
711 int rc = pThis->dbgcCreate(&pThis->m_Back.Core, 0);
712 if (!ASMAtomicUoReadBool(&pThis->m_fTerminate))
713 QApplication::postEvent(pThis, new VBoxDbgConsoleEvent(rc == VINF_SUCCESS
714 ? VBoxDbgConsoleEvent::kTerminatedUser
715 : VBoxDbgConsoleEvent::kTerminatedOther));
716 LogFlow(("backThread: returns %Rrc (m_fTerminate=%RTbool)\n", rc, ASMAtomicUoReadBool(&pThis->m_fTerminate)));
717 return rc;
718}
719
720
721bool
722VBoxDbgConsole::event(QEvent *pGenEvent)
723{
724 Assert(isGUIThread());
725 if (pGenEvent->type() == (QEvent::Type)VBoxDbgConsoleEvent::kEventNumber)
726 {
727 VBoxDbgConsoleEvent *pEvent = (VBoxDbgConsoleEvent *)pGenEvent;
728
729 switch (pEvent->command())
730 {
731 /* make update pending. */
732 case VBoxDbgConsoleEvent::kUpdate:
733 lock();
734 if (!m_fUpdatePending)
735 {
736 m_fUpdatePending = true;
737#ifdef VBOXDBG_USE_QT4
738 m_pTimer->setSingleShot(true);
739 m_pTimer->start(10);
740#else
741 m_pTimer->start(10, true /* single shot */);
742#endif
743 }
744 unlock();
745 break;
746
747 /* Re-enable the input field and restore focus. */
748 case VBoxDbgConsoleEvent::kInputEnable:
749 Log(("VBoxDbgConsole: kInputEnable (input-enabled=%RTbool)\n", m_pInput->isEnabled()));
750 m_pInput->setEnabled(true);
751 if ( m_fInputRestoreFocus
752 && !m_pInput->hasFocus())
753 m_pInput->setFocus(); /* this is a hack. */
754 m_fInputRestoreFocus = false;
755 break;
756
757 /* The thread terminated by user command (exit, quit, bye). */
758 case VBoxDbgConsoleEvent::kTerminatedUser:
759 Log(("VBoxDbgConsole: kTerminatedUser (input-enabled=%RTbool)\n", m_pInput->isEnabled()));
760 close();
761 break;
762
763 /* The thread terminated for some unknown reason., disable input */
764 case VBoxDbgConsoleEvent::kTerminatedOther:
765 Log(("VBoxDbgConsole: kTerminatedOther (input-enabled=%RTbool)\n", m_pInput->isEnabled()));
766 m_pInput->setEnabled(false);
767 break;
768
769 /* paranoia */
770 default:
771 AssertMsgFailed(("command=%d\n", pEvent->command()));
772 break;
773 }
774 return true;
775 }
776
777#ifdef VBOXDBG_USE_QT4
778 return QWidget::event(pGenEvent);
779#else
780 return QVBox::event(pGenEvent);
781#endif
782}
783
784
785void
786VBoxDbgConsole::actFocusToInput()
787{
788 if (!m_pInput->hasFocus())
789#ifdef VBOXDBG_USE_QT4
790 m_pInput->setFocus(Qt::ShortcutFocusReason);
791#else
792 m_pInput->setFocus();
793#endif
794}
795
796
797void
798VBoxDbgConsole::actFocusToOutput()
799{
800 if (!m_pOutput->hasFocus())
801#ifdef VBOXDBG_USE_QT4
802 m_pOutput->setFocus(Qt::ShortcutFocusReason);
803#else
804 m_pOutput->setFocus();
805#endif
806}
807
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette