VirtualBox

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

Last change on this file since 12850 was 12850, checked in by vboxsync, 16 years ago

Debugger: some shortcuts for the console.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 KB
Line 
1/* $Id: VBoxDbgConsole.h 12850 2008-10-01 04:15:05Z 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.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 * 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 * The Debugger Console Thread
242 *
243 * @returns VBox status code (ignored).
244 * @param Thread The thread handle.
245 * @param pvUser Pointer to the VBoxDbgConsole object.s
246 */
247 static DECLCALLBACK(int) backThread(RTTHREAD Thread, void *pvUser);
248
249 /** @} */
250
251protected:
252 /**
253 * Processes GUI command posted by the console thread.
254 *
255 * Qt3 isn't thread safe on any platform, meaning there is no locking, so, as
256 * a result we have to be very careful. All operations on objects which we share
257 * with the main thread has to be posted to it so it can perform it.
258 */
259 bool event(QEvent *pEvent);
260
261protected:
262 /** The output widget. */
263 VBoxDbgConsoleOutput *m_pOutput;
264 /** The input widget. */
265 VBoxDbgConsoleInput *m_pInput;
266 /** A hack to restore focus to the combobox after a command execution. */
267 bool m_fInputRestoreFocus;
268 /** The input buffer. */
269 char *m_pszInputBuf;
270 /** The amount of input in the buffer. */
271 size_t m_cbInputBuf;
272 /** The allocated size of the buffer. */
273 size_t m_cbInputBufAlloc;
274
275 /** The output buffer. */
276 char *m_pszOutputBuf;
277 /** The amount of output in the buffer. */
278 size_t m_cbOutputBuf;
279 /** The allocated size of the buffer. */
280 size_t m_cbOutputBufAlloc;
281 /** The timer object used to process output in a delayed fashion. */
282 QTimer *m_pTimer;
283 /** Set when an output update is pending. */
284 bool volatile m_fUpdatePending;
285
286 /** The debugger console thread. */
287 RTTHREAD m_Thread;
288 /** The event semaphore used to signal the debug console thread about input. */
289 RTSEMEVENT m_EventSem;
290 /** The critical section used to lock the object. */
291 RTCRITSECT m_Lock;
292 /** When set the thread will cause the debug console thread to terminate. */
293 bool volatile m_fTerminate;
294
295 /** The debug console backend structure.
296 * Use VBOXDBGCONSOLE_FROM_DBGCBACK to convert the DBGCBACK pointer to a object pointer. */
297 struct VBoxDbgConsoleBack
298 {
299 DBGCBACK Core;
300 VBoxDbgConsole *pSelf;
301 } m_Back;
302
303 /**
304 * Converts a pointer to VBoxDbgConsole::m_Back to VBoxDbgConsole pointer.
305 * @todo find a better way because offsetof is undefined on objects and g++ gets very noisy because of that.
306 */
307# define VBOXDBGCONSOLE_FROM_DBGCBACK(pBack) ( ((struct VBoxDbgConsoleBack *)(pBack))->pSelf )
308
309#ifdef VBOXDBG_USE_QT4
310 /** Change focus to the input field. */
311 QAction *m_pFocusToInput;
312 /** Change focus to the output viewer widget. */
313 QAction *m_pFocusToOutput;
314#endif
315};
316
317
318/**
319 * Simple event class for push certain operations over
320 * onto the GUI thread.
321 */
322class VBoxDbgConsoleEvent : public QEvent
323{
324public:
325 typedef enum { kUpdate, kInputRestoreFocus, kTerminated } VBoxDbgConsoleEventType;
326 enum { kEventNumber = QEvent::User + 42 };
327
328 VBoxDbgConsoleEvent(VBoxDbgConsoleEventType enmCommand)
329 : QEvent((QEvent::Type)kEventNumber), m_enmCommand(enmCommand)
330 {
331 }
332
333 VBoxDbgConsoleEventType command() const
334 {
335 return m_enmCommand;
336 }
337
338private:
339 VBoxDbgConsoleEventType m_enmCommand;
340};
341
342
343#endif
344
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