OSDN Git Service

Update license.
[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 (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "debuggeractions.h"
34 #ifdef Q_OS_WIN
35 #include "registerpostmortemaction.h"
36 #endif
37
38 #include <utils/savedaction.h>
39 #include <utils/qtcassert.h>
40 #include <utils/pathchooser.h>
41
42 #include <QtCore/QDebug>
43 #include <QtCore/QVariant>
44 #include <QtCore/QSettings>
45
46 using namespace Utils;
47
48 static const char debugModeSettingsGroupC[] = "DebugMode";
49 static const char sourcePathMappingArrayNameC[] = "SourcePathMappings";
50 static const char sourcePathMappingSourceKeyC[] = "Source";
51 static const char sourcePathMappingTargetKeyC[] = "Target";
52
53 namespace Debugger {
54 namespace Internal {
55
56 void GlobalDebuggerOptions::toSettings(QSettings *s) const
57 {
58     s->beginWriteArray(QLatin1String(sourcePathMappingArrayNameC));
59     if (!sourcePathMap.isEmpty()) {
60         const QString sourcePathMappingSourceKey = QLatin1String(sourcePathMappingSourceKeyC);
61         const QString sourcePathMappingTargetKey = QLatin1String(sourcePathMappingTargetKeyC);
62         int i = 0;
63         const SourcePathMap::const_iterator cend = sourcePathMap.constEnd();
64         for (SourcePathMap::const_iterator it = sourcePathMap.constBegin(); it != cend; ++it, ++i) {
65             s->setArrayIndex(i);
66             s->setValue(sourcePathMappingSourceKey, it.key());
67             s->setValue(sourcePathMappingTargetKey, it.value());
68         }
69     }
70     s->endArray();
71 }
72
73 void GlobalDebuggerOptions::fromSettings(QSettings *s)
74 {
75     sourcePathMap.clear();
76     if (const int count = s->beginReadArray(QLatin1String(sourcePathMappingArrayNameC))) {
77         const QString sourcePathMappingSourceKey = QLatin1String(sourcePathMappingSourceKeyC);
78         const QString sourcePathMappingTargetKey = QLatin1String(sourcePathMappingTargetKeyC);
79         for (int i = 0; i < count; ++i) {
80              s->setArrayIndex(i);
81              sourcePathMap.insert(s->value(sourcePathMappingSourceKey).toString(),
82                                   s->value(sourcePathMappingTargetKey).toString());
83         }
84     }
85     s->endArray();
86 }
87
88 //////////////////////////////////////////////////////////////////////////
89 //
90 // DebuggerSettings
91 //
92 //////////////////////////////////////////////////////////////////////////
93
94 DebuggerSettings::DebuggerSettings(QSettings *settings)
95 {
96     m_settings = settings;
97     const QString debugModeGroup = QLatin1String(debugModeSettingsGroupC);
98
99     SavedAction *item = 0;
100
101     item = new SavedAction(this);
102     insertItem(SettingsDialog, item);
103     item->setText(tr("Debugger Properties..."));
104
105     //
106     // View
107     //
108     item = new SavedAction(this);
109     item->setText(tr("Always Adjust Column Widths to Contents"));
110     item->setCheckable(true);
111     item->setValue(false);
112     item->setDefaultValue(false);
113     item->setSettingsKey(debugModeGroup,
114         QLatin1String("AlwaysAdjustLocalsColumnWidths"));
115     insertItem(AlwaysAdjustLocalsColumnWidths, item);
116
117     item = new SavedAction(this);
118     item->setText(tr("Always Adjust Column Widths to Contents"));
119     item->setCheckable(true);
120     item->setValue(false);
121     item->setDefaultValue(false);
122     item->setSettingsKey(debugModeGroup,
123         QLatin1String("AlwaysAdjustStackColumnWidths"));
124     insertItem(AlwaysAdjustStackColumnWidths, item);
125
126     item = new SavedAction(this);
127     item->setText(tr("Always Adjust Column Widths to Contents"));
128     item->setCheckable(true);
129     item->setValue(false);
130     item->setDefaultValue(false);
131     item->setSettingsKey(debugModeGroup,
132         QLatin1String("AlwaysAdjustThreadsColumnWidths"));
133     insertItem(AlwaysAdjustThreadsColumnWidths, item);
134
135     item = new SavedAction(this);
136     item->setText(tr("Always Adjust Column Widths to Contents"));
137     item->setCheckable(true);
138     item->setValue(false);
139     item->setDefaultValue(false);
140     item->setSettingsKey(debugModeGroup,
141         QLatin1String("AlwaysAdjustRegistersColumnWidths"));
142     insertItem(AlwaysAdjustRegistersColumnWidths, item);
143
144     item = new SavedAction(this);
145     item->setText(tr("Always Adjust Column Widths to Contents"));
146     item->setCheckable(true);
147     item->setValue(false);
148     item->setDefaultValue(false);
149     item->setSettingsKey(debugModeGroup,
150         QLatin1String("AlwaysAdjustSnapshotsColumnWidths"));
151     insertItem(AlwaysAdjustSnapshotsColumnWidths, item);
152
153     item = new SavedAction(this);
154     item->setText(tr("Always Adjust Column Widths to Contents"));
155     item->setCheckable(true);
156     item->setValue(false);
157     item->setDefaultValue(false);
158     item->setSettingsKey(debugModeGroup,
159         QLatin1String("AlwaysAdjustBreakpointsColumnWidths"));
160     insertItem(AlwaysAdjustBreakpointsColumnWidths, item);
161
162     item = new SavedAction(this);
163     item->setText(tr("Always Adjust Column Widths to Contents"));
164     item->setCheckable(true);
165     item->setValue(false);
166     item->setDefaultValue(false);
167     item->setSettingsKey(debugModeGroup,
168         QLatin1String("AlwaysAdjustModulesColumnWidths"));
169     insertItem(AlwaysAdjustModulesColumnWidths, item);
170
171     item = new SavedAction(this);
172     item->setText(tr("Use Alternating Row Colors"));
173     item->setSettingsKey(debugModeGroup, QLatin1String("UseAlternatingRowColours"));
174     item->setCheckable(true);
175     item->setDefaultValue(false);
176     insertItem(UseAlternatingRowColors, item);
177
178     item = new SavedAction(this);
179     item->setText(tr("Show a Message Box When Receiving a Signal"));
180     item->setSettingsKey(debugModeGroup, QLatin1String("UseMessageBoxForSignals"));
181     item->setCheckable(true);
182     item->setDefaultValue(true);
183     item->setValue(true);
184     insertItem(UseMessageBoxForSignals, item);
185
186     item = new SavedAction(this);
187     item->setText(tr("Log Time Stamps"));
188     item->setSettingsKey(debugModeGroup, QLatin1String("LogTimeStamps"));
189     item->setCheckable(true);
190     item->setDefaultValue(false);
191     insertItem(LogTimeStamps, item);
192
193     item = new SavedAction(this);
194     item->setText(tr("Verbose Log"));
195     item->setSettingsKey(debugModeGroup, QLatin1String("VerboseLog"));
196     item->setCheckable(true);
197     item->setDefaultValue(false);
198     insertItem(VerboseLog, item);
199
200     item = new SavedAction(this);
201     item->setText(tr("Operate by Instruction"));
202     item->setCheckable(true);
203     item->setDefaultValue(false);
204     item->setIcon(QIcon(QLatin1String(":/debugger/images/debugger_singleinstructionmode.png")));
205     item->setToolTip(tr("This switches the debugger to instruction-wise "
206         "operation mode. In this mode, stepping operates on single "
207         "instructions and the source location view also shows the "
208         "disassembled instructions."));
209     item->setIconVisibleInMenu(false);
210     insertItem(OperateByInstruction, item);
211
212     item = new SavedAction(this);
213     item->setText(tr("Dereference Pointers Automatically"));
214     item->setCheckable(true);
215     item->setDefaultValue(true);
216     item->setSettingsKey(debugModeGroup, QLatin1String("AutoDerefPointers"));
217     item->setToolTip(tr("This switches the Locals&&Watchers view to "
218         "automatically dereference pointers. This saves a level in the "
219         "tree view, but also loses data for the now-missing intermediate "
220         "level."));
221     insertItem(AutoDerefPointers, item);
222
223     //
224     // Locals & Watchers
225     //
226     item = new SavedAction(this);
227     item->setSettingsKey(debugModeGroup, QLatin1String("ShowStandardNamespace"));
228     item->setText(tr("Show \"std::\" Namespace in Types"));
229     item->setCheckable(true);
230     item->setDefaultValue(true);
231     item->setValue(true);
232     insertItem(ShowStdNamespace, item);
233
234     item = new SavedAction(this);
235     item->setSettingsKey(debugModeGroup, QLatin1String("ShowQtNamespace"));
236     item->setText(tr("Show Qt's Namespace in Types"));
237     item->setCheckable(true);
238     item->setDefaultValue(true);
239     item->setValue(true);
240     insertItem(ShowQtNamespace, item);
241
242     item = new SavedAction(this);
243     item->setSettingsKey(debugModeGroup, QLatin1String("SortStructMembers"));
244     item->setText(tr("Sort Members of Classes and Structs Alphabetically"));
245     item->setCheckable(true);
246     item->setDefaultValue(true);
247     item->setValue(true);
248     insertItem(SortStructMembers, item);
249
250     //
251     // DebuggingHelper
252     //
253     item = new SavedAction(this);
254     item->setSettingsKey(debugModeGroup, QLatin1String("UseDebuggingHelper"));
255     item->setText(tr("Use Debugging Helpers"));
256     item->setCheckable(true);
257     item->setDefaultValue(true);
258     item->setValue(true);
259     insertItem(UseDebuggingHelpers, item);
260
261     item = new SavedAction(this);
262     item->setSettingsKey(debugModeGroup, QLatin1String("UseCustomDebuggingHelperLocation"));
263     item->setCheckable(true);
264     item->setDefaultValue(false);
265     item->setValue(false);
266     insertItem(UseCustomDebuggingHelperLocation, item);
267
268     item = new SavedAction(this);
269     item->setSettingsKey(debugModeGroup, QLatin1String("CustomDebuggingHelperLocation"));
270     item->setCheckable(true);
271     item->setDefaultValue(QString());
272     item->setValue(QString());
273     insertItem(CustomDebuggingHelperLocation, item);
274
275     item = new SavedAction(this);
276     item->setSettingsKey(debugModeGroup, QLatin1String("UseCodeModel"));
277     item->setText(tr("Use Code Model"));
278     item->setToolTip(tr("Selecting this causes the C++ Code Model being asked "
279       "for variable scope information. This might result in slightly faster "
280       "debugger operation but may fail for optimized code."));
281     item->setCheckable(true);
282     item->setDefaultValue(true);
283     item->setValue(true);
284     insertItem(UseCodeModel, item);
285
286     item = new SavedAction(this);
287     item->setSettingsKey(debugModeGroup, QLatin1String("ShowThreadNames"));
288     item->setCheckable(true);
289     item->setDefaultValue(false);
290     item->setValue(false);
291     insertItem(ShowThreadNames, item);
292
293
294     //
295     // Breakpoints
296     //
297     item = new SavedAction(this);
298     item->setText(tr("Synchronize Breakpoints"));
299     insertItem(SynchronizeBreakpoints, item);
300
301     item = new SavedAction(this);
302     item->setText(tr("Adjust Breakpoint Locations"));
303     item->setToolTip(tr("Not all source code lines generate "
304       "executable code. Putting a breakpoint on such a line acts as "
305       "if the breakpoint was set on the next line that generated code. "
306       "Selecting 'Adjust Breakpoint Locations' shifts the red "
307       "breakpoint markers in such cases to the location of the true "
308       "breakpoint."));
309     item->setCheckable(true);
310     item->setDefaultValue(true);
311     item->setValue(true);
312     item->setSettingsKey(debugModeGroup, QLatin1String("AdjustBreakpointLocations"));
313     insertItem(AdjustBreakpointLocations, item);
314
315     item = new SavedAction(this);
316     item->setText(tr("Break on \"throw\""));
317     item->setCheckable(true);
318     item->setDefaultValue(false);
319     item->setValue(false);
320     item->setSettingsKey(debugModeGroup, QLatin1String("BreakOnThrow"));
321     insertItem(BreakOnThrow, item);
322
323     item = new SavedAction(this);
324     item->setText(tr("Break on \"catch\""));
325     item->setCheckable(true);
326     item->setDefaultValue(false);
327     item->setValue(false);
328     item->setSettingsKey(debugModeGroup, QLatin1String("BreakOnCatch"));
329     insertItem(BreakOnCatch, item);
330
331     //
332     // Settings
333     //
334
335     item = new SavedAction(this);
336     item->setSettingsKey(debugModeGroup, QLatin1String("LoadGdbInit"));
337     item->setDefaultValue(QString());
338     item->setCheckable(true);
339     item->setDefaultValue(true);
340     item->setValue(true);
341     insertItem(LoadGdbInit, item);
342
343     item = new SavedAction(this);
344     item->setSettingsKey(debugModeGroup, QLatin1String("TargetAsync"));
345     item->setCheckable(true);
346     item->setDefaultValue(false);
347     item->setValue(false);
348     insertItem(TargetAsync, item);
349
350     item = new SavedAction(this);
351     item->setSettingsKey(debugModeGroup, QLatin1String("ScriptFile"));
352     item->setDefaultValue(QString());
353     insertItem(GdbScriptFile, item);
354
355     item = new SavedAction(this);
356     item->setSettingsKey(debugModeGroup, QLatin1String("CloseBuffersOnExit"));
357     item->setCheckable(true);
358     item->setDefaultValue(false);
359     insertItem(CloseBuffersOnExit, item);
360
361     item = new SavedAction(this);
362     item->setSettingsKey(debugModeGroup, QLatin1String("SwitchModeOnExit"));
363     item->setCheckable(true);
364     item->setDefaultValue(false);
365     insertItem(SwitchModeOnExit, item);
366
367     item = new SavedAction(this);
368     item->setSettingsKey(debugModeGroup, QLatin1String("AutoQuit"));
369     item->setText(tr("Automatically Quit Debugger"));
370     item->setCheckable(true);
371     item->setDefaultValue(false);
372     insertItem(AutoQuit, item);
373
374     item = new SavedAction(this);
375     item->setSettingsKey(debugModeGroup, QLatin1String("UseToolTips"));
376     item->setText(tr("Use tooltips in main editor when debugging"));
377     item->setToolTip(tr("Checking this will enable tooltips for variable "
378         "values during debugging. Since this can slow down debugging and "
379         "does not provide reliable information as it does not use scope "
380         "information, it is switched off by default."));
381     item->setCheckable(true);
382     item->setDefaultValue(false);
383     insertItem(UseToolTipsInMainEditor, item);
384
385     item = new SavedAction(this);
386     item->setSettingsKey(debugModeGroup, QLatin1String("UseToolTipsInLocalsView"));
387     item->setText(tr("Use Tooltips in Locals View When Debugging"));
388     item->setToolTip(tr("Checking this will enable tooltips in the locals "
389         "view during debugging."));
390     item->setCheckable(true);
391     item->setDefaultValue(false);
392     insertItem(UseToolTipsInLocalsView, item);
393
394     item = new SavedAction(this);
395     item->setSettingsKey(debugModeGroup, QLatin1String("UseToolTipsInBreakpointsView"));
396     item->setText(tr("Use Tooltips in Breakpoints View When Debugging"));
397     item->setToolTip(tr("Checking this will enable tooltips in the breakpoints "
398         "view during debugging."));
399     item->setCheckable(true);
400     item->setDefaultValue(false);
401     insertItem(UseToolTipsInBreakpointsView, item);
402
403     item = new SavedAction(this);
404     item->setSettingsKey(debugModeGroup, QLatin1String("UseAddressInBreakpointsView"));
405     item->setText(tr("Show Address Data in Breakpoints View When Debugging"));
406     item->setToolTip(tr("Checking this will show a column with address "
407         "information in the breakpoint view during debugging."));
408     item->setCheckable(true);
409     item->setDefaultValue(false);
410     insertItem(UseAddressInBreakpointsView, item);
411
412     item = new SavedAction(this);
413     item->setSettingsKey(debugModeGroup, QLatin1String("UseAddressInStackView"));
414     item->setText(tr("Show Address Data in Stack View When Debugging"));
415     item->setToolTip(tr("Checking this will show a column with address "
416         "information in the stack view during debugging."));
417     item->setCheckable(true);
418     item->setDefaultValue(false);
419     insertItem(UseAddressInStackView, item);
420     item = new SavedAction(this);
421
422     item->setSettingsKey(debugModeGroup, QLatin1String("ListSourceFiles"));
423     item->setText(tr("List Source Files"));
424     item->setCheckable(true);
425     item->setDefaultValue(false);
426     insertItem(ListSourceFiles, item);
427
428     item = new SavedAction(this);
429     item->setSettingsKey(debugModeGroup, QLatin1String("SkipKnownFrames"));
430     item->setText(tr("Skip Known Frames"));
431     item->setCheckable(true);
432     item->setDefaultValue(false);
433     insertItem(SkipKnownFrames, item);
434
435     item = new SavedAction(this);
436     item->setSettingsKey(debugModeGroup, QLatin1String("EnableReverseDebugging"));
437     item->setText(tr("Enable Reverse Debugging"));
438     item->setCheckable(true);
439     item->setDefaultValue(false);
440     insertItem(EnableReverseDebugging, item);
441
442 #ifdef Q_OS_WIN
443     item = new RegisterPostMortemAction(this);
444     item->setSettingsKey(debugModeGroup, QLatin1String("RegisterForPostMortem"));
445     item->setText(tr("Register For Post-Mortem Debugging"));
446     item->setCheckable(true);
447     item->setDefaultValue(false);
448     insertItem(RegisterForPostMortem, item);
449 #endif
450
451     item = new SavedAction(this);
452     item->setSettingsKey(debugModeGroup, QLatin1String("AllPluginBreakpoints"));
453     item->setDefaultValue(true);
454     insertItem(AllPluginBreakpoints, item);
455
456     item = new SavedAction(this);
457     item->setSettingsKey(debugModeGroup, QLatin1String("SelectedPluginBreakpoints"));
458     item->setDefaultValue(false);
459     insertItem(SelectedPluginBreakpoints, item);
460
461     item = new SavedAction(this);
462     item->setSettingsKey(debugModeGroup, QLatin1String("NoPluginBreakpoints"));
463     item->setDefaultValue(false);
464     insertItem(NoPluginBreakpoints, item);
465
466     item = new SavedAction(this);
467     item->setSettingsKey(debugModeGroup, QLatin1String("SelectedPluginBreakpointsPattern"));
468     item->setDefaultValue(QLatin1String(".*"));
469     insertItem(SelectedPluginBreakpointsPattern, item);
470
471     item = new SavedAction(this);
472     item->setSettingsKey(debugModeGroup, QLatin1String("MaximalStackDepth"));
473     item->setDefaultValue(20);
474     insertItem(MaximalStackDepth, item);
475
476     item = new SavedAction(this);
477     item->setText(tr("Reload Full Stack"));
478     insertItem(ExpandStack, item);
479
480     item = new SavedAction(this);
481     item->setText(tr("Create Full Backtrace"));
482     insertItem(CreateFullBacktrace, item);
483
484     item = new SavedAction(this);
485     item->setSettingsKey(debugModeGroup, QLatin1String("WatchdogTimeout"));
486     item->setDefaultValue(20);
487     insertItem(GdbWatchdogTimeout, item);
488 }
489
490 DebuggerSettings::~DebuggerSettings()
491 {
492     qDeleteAll(m_items);
493 }
494
495 void DebuggerSettings::insertItem(int code, SavedAction *item)
496 {
497     QTC_ASSERT(!m_items.contains(code),
498         qDebug() << code << item->toString(); return);
499     QTC_ASSERT(item->settingsKey().isEmpty() || item->defaultValue().isValid(),
500         qDebug() << "NO DEFAULT VALUE FOR " << item->settingsKey());
501     m_items[code] = item;
502 }
503
504 void DebuggerSettings::readSettings()
505 {
506     foreach (SavedAction *item, m_items)
507         item->readSettings(m_settings);
508 }
509
510 void DebuggerSettings::writeSettings() const
511 {
512     foreach (SavedAction *item, m_items)
513         item->writeSettings(m_settings);
514 }
515
516 SavedAction *DebuggerSettings::item(int code) const
517 {
518     QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return 0);
519     return m_items.value(code, 0);
520 }
521
522 QString DebuggerSettings::dump() const
523 {
524     QString out;
525     QTextStream ts(&out);
526     ts << "Debugger settings: ";
527     foreach (SavedAction *item, m_items) {
528         QString key = item->settingsKey();
529         if (!key.isEmpty()) {
530             const QString current = item->value().toString();
531             const QString default_ = item->defaultValue().toString();
532             ts << '\n' << key << ": " << current
533                << "  (default: " << default_ << ")";
534             if (current != default_)
535                 ts <<  "  ***";
536         }
537     }
538     return out;
539 }
540
541 } // namespace Internal
542 } // namespace Debugger
543