VirtualBox

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

Last change on this file since 12880 was 12880, checked in by vboxsync, 17 years ago

Debugger: fixed busy/ready.

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

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