OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / debuggeractions.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "debuggeractions.h"
35 #ifdef Q_OS_WIN
36 #include "registerpostmortemaction.h"
37 #endif
38
39 #include <utils/savedaction.h>
40 #include <utils/qtcassert.h>
41 #include <utils/pathchooser.h>
42
43 #include <QtCore/QDebug>
44 #include <QtCore/QVariant>
45 #include <QtCore/QSettings>
46
47 using namespace Utils;
48
49 static const char debugModeSettingsGroupC[] = "DebugMode";
50
51 namespace Debugger {
52 namespace Internal {
53
54 //////////////////////////////////////////////////////////////////////////
55 //
56 // DebuggerSettings
57 //
58 //////////////////////////////////////////////////////////////////////////
59
60 DebuggerSettings::DebuggerSettings(QSettings *settings)
61 {
62     m_settings = settings;
63     const QString debugModeGroup = QLatin1String(debugModeSettingsGroupC);
64
65     SavedAction *item = 0;
66
67     item = new SavedAction(this);
68     insertItem(SettingsDialog, item);
69     item->setText(tr("Debugger Properties..."));
70
71     //
72     // View
73     //
74     item = new SavedAction(this);
75     item->setText(tr("Adjust Column Widths to Contents"));
76     insertItem(AdjustColumnWidths, item);
77
78     item = new SavedAction(this);
79     item->setText(tr("Always Adjust Column Widths to Contents"));
80     item->setCheckable(true);
81     insertItem(AlwaysAdjustColumnWidths, item);
82
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);
89
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);
95     item->setValue(true);
96     insertItem(UseMessageBoxForSignals, item);
97
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);
104
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);
111
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);
123
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 "
132         "level."));
133     insertItem(AutoDerefPointers, item);
134
135     //
136     // Locals & Watchers
137     //
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);
145
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);
153
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);
161
162     //
163     // DebuggingHelper
164     //
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);
172
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);
179
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);
186
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);
197
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);
204
205
206     //
207     // Breakpoints
208     //
209     item = new SavedAction(this);
210     item->setText(tr("Synchronize Breakpoints"));
211     insertItem(SynchronizeBreakpoints, item);
212
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 "
220       "breakpoint."));
221     item->setCheckable(true);
222     item->setDefaultValue(true);
223     item->setValue(true);
224     item->setSettingsKey(debugModeGroup, QLatin1String("AdjustBreakpointLocations"));
225     insertItem(AdjustBreakpointLocations, item);
226
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);
234
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);
242
243     //
244     // Settings
245     //
246
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);
254
255     item = new SavedAction(this);
256     item->setSettingsKey(debugModeGroup, QLatin1String("ScriptFile"));
257     item->setDefaultValue(QString());
258     insertItem(GdbScriptFile, item);
259
260     item = new SavedAction(this);
261     item->setSettingsKey(debugModeGroup, QLatin1String("CloseBuffersOnExit"));
262     item->setCheckable(true);
263     item->setDefaultValue(false);
264     insertItem(CloseBuffersOnExit, item);
265
266     item = new SavedAction(this);
267     item->setSettingsKey(debugModeGroup, QLatin1String("SwitchModeOnExit"));
268     item->setCheckable(true);
269     item->setDefaultValue(false);
270     insertItem(SwitchModeOnExit, item);
271
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);
278
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);
289
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);
298
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);
307
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);
316
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);
326
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);
332
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);
342
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);
349
350 #ifdef Q_OS_WIN
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);
357 #endif
358
359     item = new SavedAction(this);
360     item->setSettingsKey(debugModeGroup, QLatin1String("AllPluginBreakpoints"));
361     item->setDefaultValue(true);
362     insertItem(AllPluginBreakpoints, item);
363
364     item = new SavedAction(this);
365     item->setSettingsKey(debugModeGroup, QLatin1String("SelectedPluginBreakpoints"));
366     item->setDefaultValue(false);
367     insertItem(SelectedPluginBreakpoints, item);
368
369     item = new SavedAction(this);
370     item->setSettingsKey(debugModeGroup, QLatin1String("NoPluginBreakpoints"));
371     item->setDefaultValue(false);
372     insertItem(NoPluginBreakpoints, item);
373
374     item = new SavedAction(this);
375     item->setSettingsKey(debugModeGroup, QLatin1String("SelectedPluginBreakpointsPattern"));
376     item->setDefaultValue(QLatin1String(".*"));
377     insertItem(SelectedPluginBreakpointsPattern, item);
378
379     item = new SavedAction(this);
380     item->setSettingsKey(debugModeGroup, QLatin1String("MaximalStackDepth"));
381     item->setDefaultValue(20);
382     insertItem(MaximalStackDepth, item);
383
384     item = new SavedAction(this);
385     item->setText(tr("Reload Full Stack"));
386     insertItem(ExpandStack, item);
387
388     item = new SavedAction(this);
389     item->setText(tr("Create Full Backtrace"));
390     insertItem(CreateFullBacktrace, item);
391
392     item = new SavedAction(this);
393     item->setText(tr("Execute Line"));
394     insertItem(ExecuteCommand, item);
395
396     item = new SavedAction(this);
397     item->setSettingsKey(debugModeGroup, QLatin1String("WatchdogTimeout"));
398     item->setDefaultValue(20);
399     insertItem(GdbWatchdogTimeout, item);
400 }
401
402
403 DebuggerSettings::~DebuggerSettings()
404 {
405     qDeleteAll(m_items);
406 }
407
408 void DebuggerSettings::insertItem(int code, SavedAction *item)
409 {
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;
415 }
416
417 void DebuggerSettings::readSettings()
418 {
419     foreach (SavedAction *item, m_items)
420         item->readSettings(m_settings);
421 }
422
423 void DebuggerSettings::writeSettings() const
424 {
425     foreach (SavedAction *item, m_items)
426         item->writeSettings(m_settings);
427 }
428
429 SavedAction *DebuggerSettings::item(int code) const
430 {
431     QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return 0);
432     return m_items.value(code, 0);
433 }
434
435 QString DebuggerSettings::dump() const
436 {
437     QString out;
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_)
448                 ts <<  "  ***";
449         }
450     }
451     return out;
452 }
453
454 } // namespace Internal
455 } // namespace Debugger
456