VirtualBox

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

Last change on this file since 31530 was 31530, checked in by vboxsync, 14 years ago

Debugger: Updated the file headers.

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