VirtualBox

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

Last change on this file since 102869 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

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

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