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