VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbgConsole.h@ 12884

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

Debugger: destroy the console window on close if the debugger is terminated. Some ready fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/* $Id: VBoxDbgConsole.h 12882 2008-10-01 22:49:51Z 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#ifndef ___Debugger_VBoxDbgConsole_h
23#define ___Debugger_VBoxDbgConsole_h
24
25#include "VBoxDbgBase.h"
26
27#ifdef VBOXDBG_USE_QT4
28# include <QTextEdit>
29# include <QComboBox>
30# include <QTimer>
31# include <QEvent>
32#else
33# include <qtextedit.h>
34# include <qcombobox.h>
35# include <qvbox.h>
36# include <qtimer.h>
37#endif
38
39#include <iprt/critsect.h>
40#include <iprt/semaphore.h>
41#include <iprt/thread.h>
42
43
44class VBoxDbgConsoleOutput : public QTextEdit
45{
46 Q_OBJECT
47
48public:
49 /**
50 * Constructor.
51 *
52 * @param pParent Parent Widget.
53 * @param pszName Widget name.
54 */
55 VBoxDbgConsoleOutput(QWidget *pParent = NULL, const char *pszName = NULL);
56
57 /**
58 * Destructor
59 */
60 virtual ~VBoxDbgConsoleOutput();
61
62 /**
63 * Appends text.
64 * This differs from QTextEdit::append() in that it won't start on a new paragraph
65 * unless the previous char was a newline ('\n').
66 *
67 * @param rStr The text string to append.
68 */
69 virtual void appendText(const QString &rStr);
70
71protected:
72 /** The current line (paragraph) number. */
73 unsigned m_uCurLine;
74 /** The position in the current line. */
75 unsigned m_uCurPos;
76 /** The handle to the GUI thread. */
77 RTNATIVETHREAD m_hGUIThread;
78};
79
80
81/**
82 * The Debugger Console Input widget.
83 *
84 * This is a combobox which only responds to <return>.
85 */
86class VBoxDbgConsoleInput : public QComboBox
87{
88 Q_OBJECT
89
90public:
91 /**
92 * Constructor.
93 *
94 * @param pParent Parent Widget.
95 * @param pszName Widget name.
96 */
97 VBoxDbgConsoleInput(QWidget *pParent = NULL, const char *pszName = NULL);
98
99 /**
100 * Destructor
101 */
102 virtual ~VBoxDbgConsoleInput();
103
104 /**
105 * We overload this method to get signaled upon returnPressed().
106 *
107 * See QComboBox::setLineEdit for full description.
108 * @param pEdit The new line edit widget.
109 * @remark This won't be called during the constructor.
110 */
111 virtual void setLineEdit(QLineEdit *pEdit);
112
113signals:
114 /**
115 * New command submitted.
116 */
117 void commandSubmitted(const QString &rCommand);
118
119private slots:
120 /**
121 * Returned was pressed.
122 *
123 * Will emit commandSubmitted().
124 */
125 void returnPressed();
126
127protected:
128 /** The current blank entry. */
129 int m_iBlankItem;
130 /** The handle to the GUI thread. */
131 RTNATIVETHREAD m_hGUIThread;
132};
133
134
135/**
136 * The Debugger Console.
137 */
138class VBoxDbgConsole :
139#ifdef VBOXDBG_USE_QT4
140 public QWidget,
141#else
142 public QVBox,
143#endif
144 public VBoxDbgBase
145{
146 Q_OBJECT
147
148public:
149 /**
150 * Constructor.
151 *
152 * @param pVM VM handle.
153 * @param pParent Parent Widget.
154 * @param pszName Widget name.
155 */
156 VBoxDbgConsole(PVM pVM, QWidget *pParent = NULL, const char *pszName = NULL);
157
158 /**
159 * Destructor
160 */
161 virtual ~VBoxDbgConsole();
162
163protected slots:
164 /**
165 * Handler called when a command is submitted.
166 * (Enter or return pressed in the combo box.)
167 *
168 * @param rCommand The submitted command.
169 */
170 void commandSubmitted(const QString &rCommand);
171
172 /**
173 * Updates the output with what's currently in the output buffer.
174 * This is called by a timer or a User event posted by the debugger thread.
175 */
176 void updateOutput();
177
178 /**
179 * Changes the focus to the input field.
180 */
181 void actFocusToInput();
182
183 /**
184 * Changes the focus to the output viewer widget.
185 */
186 void actFocusToOutput();
187
188protected:
189#ifdef VBOXDBG_USE_QT4
190 /**
191 * Override the closeEvent so we can choose delete the window when
192 * it is closed.
193 *
194 * @param a_pCloseEvt The close event.
195 */
196 virtual void closeEvent(QCloseEvent *a_pCloseEvt);
197#endif
198
199 /**
200 * Lock the object.
201 */
202 void lock();
203
204 /**
205 * Unlocks the object.
206 */
207 void unlock();
208
209protected:
210 /** @name Debug Console Backend.
211 * @{
212 */
213
214
215 /**
216 * Checks if there is input.
217 *
218 * @returns true if there is input ready.
219 * @returns false if there not input ready.
220 * @param pBack Pointer to VBoxDbgConsole::m_Back.
221 * @param cMillies Number of milliseconds to wait on input data.
222 */
223 static DECLCALLBACK(bool) backInput(PDBGCBACK pBack, uint32_t cMillies);
224
225 /**
226 * Read input.
227 *
228 * @returns VBox status code.
229 * @param pBack Pointer to VBoxDbgConsole::m_Back.
230 * @param pvBuf Where to put the bytes we read.
231 * @param cbBuf Maximum nymber of bytes to read.
232 * @param pcbRead Where to store the number of bytes actually read.
233 * If NULL the entire buffer must be filled for a
234 * successful return.
235 */
236 static DECLCALLBACK(int) backRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
237
238 /**
239 * Write (output).
240 *
241 * @returns VBox status code.
242 * @param pBack Pointer to VBoxDbgConsole::m_Back.
243 * @param pvBuf What to write.
244 * @param cbBuf Number of bytes to write.
245 * @param pcbWritten Where to store the number of bytes actually written.
246 * If NULL the entire buffer must be successfully written.
247 */
248 static DECLCALLBACK(int) backWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
249
250 /**
251 * @copydoc FNDBGCBACKSETREADY
252 */
253 static DECLCALLBACK(void) backSetReady(PDBGCBACK pBack, bool fReady);
254
255 /**
256 * The Debugger Console Thread
257 *
258 * @returns VBox status code (ignored).
259 * @param Thread The thread handle.
260 * @param pvUser Pointer to the VBoxDbgConsole object.s
261 */
262 static DECLCALLBACK(int) backThread(RTTHREAD Thread, void *pvUser);
263
264 /** @} */
265
266protected:
267 /**
268 * Processes GUI command posted by the console thread.
269 *
270 * Qt3 isn't thread safe on any platform, meaning there is no locking, so, as
271 * a result we have to be very careful. All operations on objects which we share
272 * with the main thread has to be posted to it so it can perform it.
273 */
274 bool event(QEvent *pEvent);
275
276protected:
277 /** The output widget. */
278 VBoxDbgConsoleOutput *m_pOutput;
279 /** The input widget. */
280 VBoxDbgConsoleInput *m_pInput;
281 /** A hack to restore focus to the combobox after a command execution. */
282 bool m_fInputRestoreFocus;
283 /** The input buffer. */
284 char *m_pszInputBuf;
285 /** The amount of input in the buffer. */
286 size_t m_cbInputBuf;
287 /** The allocated size of the buffer. */
288 size_t m_cbInputBufAlloc;
289
290 /** The output buffer. */
291 char *m_pszOutputBuf;
292 /** The amount of output in the buffer. */
293 size_t m_cbOutputBuf;
294 /** The allocated size of the buffer. */
295 size_t m_cbOutputBufAlloc;
296 /** The timer object used to process output in a delayed fashion. */
297 QTimer *m_pTimer;
298 /** Set when an output update is pending. */
299 bool volatile m_fUpdatePending;
300
301 /** The debugger console thread. */
302 RTTHREAD m_Thread;
303 /** The event semaphore used to signal the debug console thread about input. */
304 RTSEMEVENT m_EventSem;
305 /** The critical section used to lock the object. */
306 RTCRITSECT m_Lock;
307 /** When set the thread will cause the debug console thread to terminate. */
308 bool volatile m_fTerminate;
309 /** Has the thread terminated?
310 * Used to do the right thing in closeEvent; the console is dead if the
311 * thread has terminated. */
312 bool volatile m_fThreadTerminated;
313
314 /** The debug console backend structure.
315 * Use VBOXDBGCONSOLE_FROM_DBGCBACK to convert the DBGCBACK pointer to a object pointer. */
316 struct VBoxDbgConsoleBack
317 {
318 DBGCBACK Core;
319 VBoxDbgConsole *pSelf;
320 } m_Back;
321
322 /**
323 * Converts a pointer to VBoxDbgConsole::m_Back to VBoxDbgConsole pointer.
324 * @todo find a better way because offsetof is undefined on objects and g++ gets very noisy because of that.
325 */
326# define VBOXDBGCONSOLE_FROM_DBGCBACK(pBack) ( ((struct VBoxDbgConsoleBack *)(pBack))->pSelf )
327
328#ifdef VBOXDBG_USE_QT4
329 /** Change focus to the input field. */
330 QAction *m_pFocusToInput;
331 /** Change focus to the output viewer widget. */
332 QAction *m_pFocusToOutput;
333#endif
334};
335
336
337/**
338 * Simple event class for push certain operations over
339 * onto the GUI thread.
340 */
341class VBoxDbgConsoleEvent : public QEvent
342{
343public:
344 typedef enum { kUpdate, kInputEnable, kTerminatedUser, kTerminatedOther } VBoxDbgConsoleEventType;
345 enum { kEventNumber = QEvent::User + 42 };
346
347 VBoxDbgConsoleEvent(VBoxDbgConsoleEventType enmCommand)
348 : QEvent((QEvent::Type)kEventNumber), m_enmCommand(enmCommand)
349 {
350 }
351
352 VBoxDbgConsoleEventType command() const
353 {
354 return m_enmCommand;
355 }
356
357private:
358 VBoxDbgConsoleEventType m_enmCommand;
359};
360
361
362#endif
363
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