VirtualBox

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

Last change on this file since 2244 was 1, checked in by vboxsync, 55 years ago

import

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