1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox Debugger GUI - Console.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef __VBoxDbgConsole_h__
|
---|
19 | #define __VBoxDbgConsole_h__
|
---|
20 |
|
---|
21 | #include "VBoxDbgBase.h"
|
---|
22 |
|
---|
23 | #include <qtextedit.h>
|
---|
24 | #include <qcombobox.h>
|
---|
25 | #include <qvbox.h>
|
---|
26 | #include <qtimer.h>
|
---|
27 |
|
---|
28 | #include <iprt/critsect.h>
|
---|
29 | #include <iprt/semaphore.h>
|
---|
30 |
|
---|
31 |
|
---|
32 | class VBoxDbgConsoleOutput : public QTextEdit
|
---|
33 | {
|
---|
34 | Q_OBJECT
|
---|
35 |
|
---|
36 | public:
|
---|
37 | /**
|
---|
38 | * Constructor.
|
---|
39 | *
|
---|
40 | * @param pParent Parent Widget.
|
---|
41 | * @param pszName Widget name.
|
---|
42 | */
|
---|
43 | VBoxDbgConsoleOutput(QWidget *pParent = NULL, const char *pszName = NULL);
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Destructor
|
---|
47 | */
|
---|
48 | virtual ~VBoxDbgConsoleOutput();
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Appends text.
|
---|
52 | * This differs from QTextEdit::append() in that it won't start on a new paragraph
|
---|
53 | * unless the previous char was a newline ('\n').
|
---|
54 | *
|
---|
55 | * @param rStr The text string to append.
|
---|
56 | */
|
---|
57 | virtual void appendText(const QString &rStr);
|
---|
58 |
|
---|
59 | protected:
|
---|
60 | /** The current line (paragraph) number. */
|
---|
61 | unsigned m_uCurLine;
|
---|
62 | /** The position in the current line. */
|
---|
63 | unsigned m_uCurPos;
|
---|
64 | };
|
---|
65 |
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * The Debugger Console Input widget.
|
---|
69 | *
|
---|
70 | * This is a combobox which only responds to <return>.
|
---|
71 | */
|
---|
72 | class VBoxDbgConsoleInput : public QComboBox
|
---|
73 | {
|
---|
74 | Q_OBJECT
|
---|
75 |
|
---|
76 | public:
|
---|
77 | /**
|
---|
78 | * Constructor.
|
---|
79 | *
|
---|
80 | * @param pParent Parent Widget.
|
---|
81 | * @param pszName Widget name.
|
---|
82 | */
|
---|
83 | VBoxDbgConsoleInput(QWidget *pParent = NULL, const char *pszName = NULL);
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Destructor
|
---|
87 | */
|
---|
88 | virtual ~VBoxDbgConsoleInput();
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * We overload this method to get signaled upon returnPressed().
|
---|
92 | *
|
---|
93 | * See QComboBox::setLineEdit for full description.
|
---|
94 | * @param pEdit The new line edit widget.
|
---|
95 | * @remark This won't be called during the constructor.
|
---|
96 | */
|
---|
97 | virtual void setLineEdit(QLineEdit *pEdit);
|
---|
98 |
|
---|
99 | signals:
|
---|
100 | /**
|
---|
101 | * New command submitted.
|
---|
102 | */
|
---|
103 | void commandSubmitted(const QString &rCommand);
|
---|
104 |
|
---|
105 | private slots:
|
---|
106 | /**
|
---|
107 | * Returned was pressed.
|
---|
108 | *
|
---|
109 | * Will emit commandSubmitted().
|
---|
110 | */
|
---|
111 | void returnPressed();
|
---|
112 | };
|
---|
113 |
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * The Debugger Console.
|
---|
117 | */
|
---|
118 | class VBoxDbgConsole : public QVBox, public VBoxDbgBase
|
---|
119 | {
|
---|
120 | Q_OBJECT
|
---|
121 |
|
---|
122 | public:
|
---|
123 | /**
|
---|
124 | * Constructor.
|
---|
125 | *
|
---|
126 | * @param pVM VM handle.
|
---|
127 | * @param pParent Parent Widget.
|
---|
128 | * @param pszName Widget name.
|
---|
129 | */
|
---|
130 | VBoxDbgConsole(PVM pVM, QWidget *pParent = NULL, const char *pszName = NULL);
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Destructor
|
---|
134 | */
|
---|
135 | virtual ~VBoxDbgConsole();
|
---|
136 |
|
---|
137 | protected slots:
|
---|
138 | /**
|
---|
139 | * Handler called when a command is submitted.
|
---|
140 | * (Enter or return pressed in the combo box.)
|
---|
141 | *
|
---|
142 | * @param rCommand The submitted command.
|
---|
143 | */
|
---|
144 | void commandSubmitted(const QString &rCommand);
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Updates the output with what's currently in the output buffer.
|
---|
148 | * This is called by a timer or a User event posted by the debugger thread.
|
---|
149 | */
|
---|
150 | void updateOutput();
|
---|
151 |
|
---|
152 |
|
---|
153 | protected:
|
---|
154 | /**
|
---|
155 | * Lock the object.
|
---|
156 | */
|
---|
157 | void lock();
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Unlocks the object.
|
---|
161 | */
|
---|
162 | void unlock();
|
---|
163 |
|
---|
164 | protected:
|
---|
165 | /** @name Debug Console Backend.
|
---|
166 | * @{
|
---|
167 | */
|
---|
168 |
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Checks if there is input.
|
---|
172 | *
|
---|
173 | * @returns true if there is input ready.
|
---|
174 | * @returns false if there not input ready.
|
---|
175 | * @param pBack Pointer to VBoxDbgConsole::m_Back.
|
---|
176 | * @param cMillies Number of milliseconds to wait on input data.
|
---|
177 | */
|
---|
178 | static DECLCALLBACK(bool) backInput(PDBGCBACK pBack, uint32_t cMillies);
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Read input.
|
---|
182 | *
|
---|
183 | * @returns VBox status code.
|
---|
184 | * @param pBack Pointer to VBoxDbgConsole::m_Back.
|
---|
185 | * @param pvBuf Where to put the bytes we read.
|
---|
186 | * @param cbBuf Maximum nymber of bytes to read.
|
---|
187 | * @param pcbRead Where to store the number of bytes actually read.
|
---|
188 | * If NULL the entire buffer must be filled for a
|
---|
189 | * successful return.
|
---|
190 | */
|
---|
191 | static DECLCALLBACK(int) backRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Write (output).
|
---|
195 | *
|
---|
196 | * @returns VBox status code.
|
---|
197 | * @param pBack Pointer to VBoxDbgConsole::m_Back.
|
---|
198 | * @param pvBuf What to write.
|
---|
199 | * @param cbBuf Number of bytes to write.
|
---|
200 | * @param pcbWritten Where to store the number of bytes actually written.
|
---|
201 | * If NULL the entire buffer must be successfully written.
|
---|
202 | */
|
---|
203 | static DECLCALLBACK(int) backWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * The Debugger Console Thread
|
---|
207 | *
|
---|
208 | * @returns VBox status code (ignored).
|
---|
209 | * @param Thread The thread handle.
|
---|
210 | * @param pvUser Pointer to the VBoxDbgConsole object.s
|
---|
211 | */
|
---|
212 | static DECLCALLBACK(int) backThread(RTTHREAD Thread, void *pvUser);
|
---|
213 |
|
---|
214 | /** @} */
|
---|
215 |
|
---|
216 | protected:
|
---|
217 | /**
|
---|
218 | * Use to get the GUI thread to insert the output data.
|
---|
219 | */
|
---|
220 | void customEvent(QCustomEvent *pEvent);
|
---|
221 |
|
---|
222 | protected:
|
---|
223 | /** The output widget. */
|
---|
224 | VBoxDbgConsoleOutput *m_pOutput;
|
---|
225 | /** The input widget. */
|
---|
226 | VBoxDbgConsoleInput *m_pInput;
|
---|
227 | /** A hack to restore focus to the combobox after a command execution. */
|
---|
228 | bool m_fInputRestoreFocus;
|
---|
229 | /** The input buffer. */
|
---|
230 | char *m_pszInputBuf;
|
---|
231 | /** The amount of input in the buffer. */
|
---|
232 | size_t m_cbInputBuf;
|
---|
233 | /** The allocated size of the buffer. */
|
---|
234 | size_t m_cbInputBufAlloc;
|
---|
235 |
|
---|
236 | /** The output buffer. */
|
---|
237 | char *m_pszOutputBuf;
|
---|
238 | /** The amount of output in the buffer. */
|
---|
239 | size_t m_cbOutputBuf;
|
---|
240 | /** The allocated size of the buffer. */
|
---|
241 | size_t m_cbOutputBufAlloc;
|
---|
242 | /** The timer object used to process output in a delayed fashion. */
|
---|
243 | QTimer m_Timer;
|
---|
244 | /** Set when an output update is pending. */
|
---|
245 | bool volatile m_fUpdatePending;
|
---|
246 |
|
---|
247 | /** The debugger console thread. */
|
---|
248 | RTTHREAD m_Thread;
|
---|
249 | /** The event semaphore used to signal the debug console thread about input. */
|
---|
250 | RTSEMEVENT m_EventSem;
|
---|
251 | /** The critical section used to lock the object. */
|
---|
252 | RTCRITSECT m_Lock;
|
---|
253 | /** When set the thread will cause the debug console thread to terminate. */
|
---|
254 | bool volatile m_fTerminate;
|
---|
255 |
|
---|
256 | /** The debug console backend structure.
|
---|
257 | * Use VBOXDBGCONSOLE_FROM_DBGCBACK to convert the DBGCBACK pointer to a object pointer. */
|
---|
258 | struct VBoxDbgConsoleBack
|
---|
259 | {
|
---|
260 | DBGCBACK Core;
|
---|
261 | VBoxDbgConsole *pSelf;
|
---|
262 | } m_Back;
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Converts a pointer to VBoxDbgConsole::m_Back to VBoxDbgConsole pointer.
|
---|
266 | * @todo find a better way because offsetof is undefined on objects and g++ gets very noisy because of that.
|
---|
267 | */
|
---|
268 | #define VBOXDBGCONSOLE_FROM_DBGCBACK(pBack) ( ((struct VBoxDbgConsoleBack *)(pBack))->pSelf )
|
---|
269 | };
|
---|
270 |
|
---|
271 |
|
---|
272 | #endif
|
---|