VirtualBox

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

Last change on this file since 95512 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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