VirtualBox

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

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

The debugger is back in the OSE.

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