VirtualBox

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

Last change on this file since 41309 was 38813, checked in by vboxsync, 13 years ago

VBoxDbgConsole: Fixed busted text handling wrt selections and cursor positioning.

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