1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "debuggeractions.h"
36 #include "registerpostmortemaction.h"
39 #include <utils/savedaction.h>
40 #include <utils/qtcassert.h>
41 #include <utils/pathchooser.h>
43 #include <QtCore/QDebug>
44 #include <QtCore/QVariant>
45 #include <QtCore/QSettings>
47 using namespace Utils;
49 static const char debugModeSettingsGroupC[] = "DebugMode";
54 //////////////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////////////
60 DebuggerSettings::DebuggerSettings(QSettings *settings)
62 m_settings = settings;
63 const QString debugModeGroup = QLatin1String(debugModeSettingsGroupC);
65 SavedAction *item = 0;
67 item = new SavedAction(this);
68 insertItem(SettingsDialog, item);
69 item->setText(tr("Debugger Properties..."));
74 item = new SavedAction(this);
75 item->setText(tr("Adjust Column Widths to Contents"));
76 insertItem(AdjustColumnWidths, item);
78 item = new SavedAction(this);
79 item->setText(tr("Always Adjust Column Widths to Contents"));
80 item->setCheckable(true);
81 insertItem(AlwaysAdjustColumnWidths, item);
83 item = new SavedAction(this);
84 item->setText(tr("Use Alternating Row Colors"));
85 item->setSettingsKey(debugModeGroup, QLatin1String("UseAlternatingRowColours"));
86 item->setCheckable(true);
87 item->setDefaultValue(false);
88 insertItem(UseAlternatingRowColors, item);
90 item = new SavedAction(this);
91 item->setText(tr("Show a Message Box When Receiving a Signal"));
92 item->setSettingsKey(debugModeGroup, QLatin1String("UseMessageBoxForSignals"));
93 item->setCheckable(true);
94 item->setDefaultValue(true);
96 insertItem(UseMessageBoxForSignals, item);
98 item = new SavedAction(this);
99 item->setText(tr("Log Time Stamps"));
100 item->setSettingsKey(debugModeGroup, QLatin1String("LogTimeStamps"));
101 item->setCheckable(true);
102 item->setDefaultValue(false);
103 insertItem(LogTimeStamps, item);
105 item = new SavedAction(this);
106 item->setText(tr("Verbose Log"));
107 item->setSettingsKey(debugModeGroup, QLatin1String("VerboseLog"));
108 item->setCheckable(true);
109 item->setDefaultValue(false);
110 insertItem(VerboseLog, item);
112 item = new SavedAction(this);
113 item->setText(tr("Operate by Instruction"));
114 item->setCheckable(true);
115 item->setDefaultValue(false);
116 item->setIcon(QIcon(QLatin1String(":/debugger/images/debugger_singleinstructionmode.png")));
117 item->setToolTip(tr("This switches the debugger to instruction-wise "
118 "operation mode. In this mode, stepping operates on single "
119 "instructions and the source location view also shows the "
120 "disassembled instructions."));
121 item->setIconVisibleInMenu(false);
122 insertItem(OperateByInstruction, item);
124 item = new SavedAction(this);
125 item->setText(tr("Dereference Pointers Automatically"));
126 item->setCheckable(true);
127 item->setDefaultValue(true);
128 item->setSettingsKey(debugModeGroup, QLatin1String("AutoDerefPointers"));
129 item->setToolTip(tr("This switches the Locals&&Watchers view to "
130 "automatically dereference pointers. This saves a level in the "
131 "tree view, but also loses data for the now-missing intermediate "
133 insertItem(AutoDerefPointers, item);
138 item = new SavedAction(this);
139 item->setSettingsKey(debugModeGroup, QLatin1String("ShowStandardNamespace"));
140 item->setText(tr("Show \"std::\" Namespace in Types"));
141 item->setCheckable(true);
142 item->setDefaultValue(true);
143 item->setValue(true);
144 insertItem(ShowStdNamespace, item);
146 item = new SavedAction(this);
147 item->setSettingsKey(debugModeGroup, QLatin1String("ShowQtNamespace"));
148 item->setText(tr("Show Qt's Namespace in Types"));
149 item->setCheckable(true);
150 item->setDefaultValue(true);
151 item->setValue(true);
152 insertItem(ShowQtNamespace, item);
154 item = new SavedAction(this);
155 item->setSettingsKey(debugModeGroup, QLatin1String("SortStructMembers"));
156 item->setText(tr("Sort Members of Classes and Structs Alphabetically"));
157 item->setCheckable(true);
158 item->setDefaultValue(true);
159 item->setValue(true);
160 insertItem(SortStructMembers, item);
165 item = new SavedAction(this);
166 item->setSettingsKey(debugModeGroup, QLatin1String("UseDebuggingHelper"));
167 item->setText(tr("Use Debugging Helpers"));
168 item->setCheckable(true);
169 item->setDefaultValue(true);
170 item->setValue(true);
171 insertItem(UseDebuggingHelpers, item);
173 item = new SavedAction(this);
174 item->setSettingsKey(debugModeGroup, QLatin1String("UseCustomDebuggingHelperLocation"));
175 item->setCheckable(true);
176 item->setDefaultValue(false);
177 item->setValue(false);
178 insertItem(UseCustomDebuggingHelperLocation, item);
180 item = new SavedAction(this);
181 item->setSettingsKey(debugModeGroup, QLatin1String("CustomDebuggingHelperLocation"));
182 item->setCheckable(true);
183 item->setDefaultValue(QString());
184 item->setValue(QString());
185 insertItem(CustomDebuggingHelperLocation, item);
187 item = new SavedAction(this);
188 item->setSettingsKey(debugModeGroup, QLatin1String("UseCodeModel"));
189 item->setText(tr("Use Code Model"));
190 item->setToolTip(tr("Selecting this causes the C++ Code Model being asked "
191 "for variable scope information. This might result in slightly faster "
192 "debugger operation but may fail for optimized code."));
193 item->setCheckable(true);
194 item->setDefaultValue(true);
195 item->setValue(true);
196 insertItem(UseCodeModel, item);
198 item = new SavedAction(this);
199 item->setSettingsKey(debugModeGroup, QLatin1String("ShowThreadNames"));
200 item->setCheckable(true);
201 item->setDefaultValue(false);
202 item->setValue(false);
203 insertItem(ShowThreadNames, item);
209 item = new SavedAction(this);
210 item->setText(tr("Synchronize Breakpoints"));
211 insertItem(SynchronizeBreakpoints, item);
213 item = new SavedAction(this);
214 item->setText(tr("Adjust Breakpoint Locations"));
215 item->setToolTip(tr("Not all source code lines generate "
216 "executable code. Putting a breakpoint on such a line acts as "
217 "if the breakpoint was set on the next line that generated code. "
218 "Selecting 'Adjust Breakpoint Locations' shifts the red "
219 "breakpoint markers in such cases to the location of the true "
221 item->setCheckable(true);
222 item->setDefaultValue(true);
223 item->setValue(true);
224 item->setSettingsKey(debugModeGroup, QLatin1String("AdjustBreakpointLocations"));
225 insertItem(AdjustBreakpointLocations, item);
227 item = new SavedAction(this);
228 item->setText(tr("Break on \"throw\""));
229 item->setCheckable(true);
230 item->setDefaultValue(false);
231 item->setValue(false);
232 item->setSettingsKey(debugModeGroup, QLatin1String("BreakOnThrow"));
233 insertItem(BreakOnThrow, item);
235 item = new SavedAction(this);
236 item->setText(tr("Break on \"catch\""));
237 item->setCheckable(true);
238 item->setDefaultValue(false);
239 item->setValue(false);
240 item->setSettingsKey(debugModeGroup, QLatin1String("BreakOnCatch"));
241 insertItem(BreakOnCatch, item);
247 item = new SavedAction(this);
248 item->setSettingsKey(debugModeGroup, QLatin1String("LoadGdbInit"));
249 item->setDefaultValue(QString());
250 item->setCheckable(true);
251 item->setDefaultValue(true);
252 item->setValue(true);
253 insertItem(LoadGdbInit, item);
255 item = new SavedAction(this);
256 item->setSettingsKey(debugModeGroup, QLatin1String("ScriptFile"));
257 item->setDefaultValue(QString());
258 insertItem(GdbScriptFile, item);
260 item = new SavedAction(this);
261 item->setSettingsKey(debugModeGroup, QLatin1String("CloseBuffersOnExit"));
262 item->setCheckable(true);
263 item->setDefaultValue(false);
264 insertItem(CloseBuffersOnExit, item);
266 item = new SavedAction(this);
267 item->setSettingsKey(debugModeGroup, QLatin1String("SwitchModeOnExit"));
268 item->setCheckable(true);
269 item->setDefaultValue(false);
270 insertItem(SwitchModeOnExit, item);
272 item = new SavedAction(this);
273 item->setSettingsKey(debugModeGroup, QLatin1String("AutoQuit"));
274 item->setText(tr("Automatically Quit Debugger"));
275 item->setCheckable(true);
276 item->setDefaultValue(false);
277 insertItem(AutoQuit, item);
279 item = new SavedAction(this);
280 item->setSettingsKey(debugModeGroup, QLatin1String("UseToolTips"));
281 item->setText(tr("Use tooltips in main editor when debugging"));
282 item->setToolTip(tr("Checking this will enable tooltips for variable "
283 "values during debugging. Since this can slow down debugging and "
284 "does not provide reliable information as it does not use scope "
285 "information, it is switched off by default."));
286 item->setCheckable(true);
287 item->setDefaultValue(false);
288 insertItem(UseToolTipsInMainEditor, item);
290 item = new SavedAction(this);
291 item->setSettingsKey(debugModeGroup, QLatin1String("UseToolTipsInLocalsView"));
292 item->setText(tr("Use Tooltips in Locals View When Debugging"));
293 item->setToolTip(tr("Checking this will enable tooltips in the locals "
294 "view during debugging."));
295 item->setCheckable(true);
296 item->setDefaultValue(false);
297 insertItem(UseToolTipsInLocalsView, item);
299 item = new SavedAction(this);
300 item->setSettingsKey(debugModeGroup, QLatin1String("UseToolTipsInBreakpointsView"));
301 item->setText(tr("Use Tooltips in Breakpoints View When Debugging"));
302 item->setToolTip(tr("Checking this will enable tooltips in the breakpoints "
303 "view during debugging."));
304 item->setCheckable(true);
305 item->setDefaultValue(false);
306 insertItem(UseToolTipsInBreakpointsView, item);
308 item = new SavedAction(this);
309 item->setSettingsKey(debugModeGroup, QLatin1String("UseAddressInBreakpointsView"));
310 item->setText(tr("Show Address Data in Breakpoints View When Debugging"));
311 item->setToolTip(tr("Checking this will show a column with address "
312 "information in the breakpoint view during debugging."));
313 item->setCheckable(true);
314 item->setDefaultValue(false);
315 insertItem(UseAddressInBreakpointsView, item);
317 item = new SavedAction(this);
318 item->setSettingsKey(debugModeGroup, QLatin1String("UseAddressInStackView"));
319 item->setText(tr("Show Address Data in Stack View When Debugging"));
320 item->setToolTip(tr("Checking this will show a column with address "
321 "information in the stack view during debugging."));
322 item->setCheckable(true);
323 item->setDefaultValue(false);
324 insertItem(UseAddressInStackView, item);
325 item = new SavedAction(this);
327 item->setSettingsKey(debugModeGroup, QLatin1String("ListSourceFiles"));
328 item->setText(tr("List Source Files"));
329 item->setCheckable(true);
330 item->setDefaultValue(false);
331 insertItem(ListSourceFiles, item);
333 item = new SavedAction(this);
334 item->setSettingsKey(debugModeGroup, QLatin1String("SkipKnownFrames"));
335 item->setText(tr("Skip Known Frames"));
336 item->setToolTip(tr("Selecting this results in well-known but usually "
337 "not interesting frames belonging to reference counting and "
338 "signal emission being skipped while single-stepping."));
339 item->setCheckable(true);
340 item->setDefaultValue(false);
341 insertItem(SkipKnownFrames, item);
343 item = new SavedAction(this);
344 item->setSettingsKey(debugModeGroup, QLatin1String("EnableReverseDebugging"));
345 item->setText(tr("Enable Reverse Debugging"));
346 item->setCheckable(true);
347 item->setDefaultValue(false);
348 insertItem(EnableReverseDebugging, item);
351 item = new RegisterPostMortemAction(this);
352 item->setSettingsKey(debugModeGroup, QLatin1String("RegisterForPostMortem"));
353 item->setText(tr("Register For Post-Mortem Debugging"));
354 item->setCheckable(true);
355 item->setDefaultValue(false);
356 insertItem(RegisterForPostMortem, item);
359 item = new SavedAction(this);
360 item->setSettingsKey(debugModeGroup, QLatin1String("AllPluginBreakpoints"));
361 item->setDefaultValue(true);
362 insertItem(AllPluginBreakpoints, item);
364 item = new SavedAction(this);
365 item->setSettingsKey(debugModeGroup, QLatin1String("SelectedPluginBreakpoints"));
366 item->setDefaultValue(false);
367 insertItem(SelectedPluginBreakpoints, item);
369 item = new SavedAction(this);
370 item->setSettingsKey(debugModeGroup, QLatin1String("NoPluginBreakpoints"));
371 item->setDefaultValue(false);
372 insertItem(NoPluginBreakpoints, item);
374 item = new SavedAction(this);
375 item->setSettingsKey(debugModeGroup, QLatin1String("SelectedPluginBreakpointsPattern"));
376 item->setDefaultValue(QLatin1String(".*"));
377 insertItem(SelectedPluginBreakpointsPattern, item);
379 item = new SavedAction(this);
380 item->setSettingsKey(debugModeGroup, QLatin1String("MaximalStackDepth"));
381 item->setDefaultValue(20);
382 insertItem(MaximalStackDepth, item);
384 item = new SavedAction(this);
385 item->setText(tr("Reload Full Stack"));
386 insertItem(ExpandStack, item);
388 item = new SavedAction(this);
389 item->setText(tr("Create Full Backtrace"));
390 insertItem(CreateFullBacktrace, item);
392 item = new SavedAction(this);
393 item->setText(tr("Execute Line"));
394 insertItem(ExecuteCommand, item);
396 item = new SavedAction(this);
397 item->setSettingsKey(debugModeGroup, QLatin1String("WatchdogTimeout"));
398 item->setDefaultValue(20);
399 insertItem(GdbWatchdogTimeout, item);
403 DebuggerSettings::~DebuggerSettings()
408 void DebuggerSettings::insertItem(int code, SavedAction *item)
410 QTC_ASSERT(!m_items.contains(code),
411 qDebug() << code << item->toString(); return);
412 QTC_ASSERT(item->settingsKey().isEmpty() || item->defaultValue().isValid(),
413 qDebug() << "NO DEFAULT VALUE FOR " << item->settingsKey());
414 m_items[code] = item;
417 void DebuggerSettings::readSettings()
419 foreach (SavedAction *item, m_items)
420 item->readSettings(m_settings);
423 void DebuggerSettings::writeSettings() const
425 foreach (SavedAction *item, m_items)
426 item->writeSettings(m_settings);
429 SavedAction *DebuggerSettings::item(int code) const
431 QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return 0);
432 return m_items.value(code, 0);
435 QString DebuggerSettings::dump() const
438 QTextStream ts(&out);
439 ts << "Debugger settings: ";
440 foreach (SavedAction *item, m_items) {
441 QString key = item->settingsKey();
442 if (!key.isEmpty()) {
443 const QString current = item->value().toString();
444 const QString default_ = item->defaultValue().toString();
445 ts << '\n' << key << ": " << current
446 << " (default: " << default_ << ")";
447 if (current != default_)
454 } // namespace Internal
455 } // namespace Debugger