3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
7 #include <klocale.h> /* i18n */
8 #include <kmessagebox.h>
10 #include <kstatusbar.h>
11 #include <kiconloader.h>
12 #include <kstdaccel.h>
13 #include <kstdaction.h>
15 #include <kpopupmenu.h>
16 #include <kfiledialog.h>
18 #include <kkeydialog.h>
19 #include <kanimwidget.h>
22 #include <qfileinfo.h>
23 #include "dbgmainwnd.h"
25 #include "commandids.h"
28 #include "threadlist.h"
29 #include "memwindow.h"
31 #include "procattach.h"
32 #include "dbgdriver.h"
39 DebuggerMainWnd::DebuggerMainWnd(const char* name
) :
40 KDockMainWindow(0, name
),
45 KDockWidget
* dw0
= createDockWidget("Source", p
, 0, i18n("Source"));
46 m_filesWindow
= new WinStack(dw0
, "files");
47 dw0
->setWidget(m_filesWindow
);
48 dw0
->setDockSite(KDockWidget::DockCorner
);
49 dw0
->setEnableDocking(KDockWidget::DockNone
);
51 setMainDockWidget(dw0
);
53 KDockWidget
* dw1
= createDockWidget("Stack", p
, 0, i18n("Stack"));
54 m_btWindow
= new QListBox(dw1
, "backtrace");
55 dw1
->setWidget(m_btWindow
);
56 KDockWidget
* dw2
= createDockWidget("Locals", p
, 0, i18n("Locals"));
57 m_localVariables
= new ExprWnd(dw2
, i18n("Variable"), "locals");
58 dw2
->setWidget(m_localVariables
);
59 KDockWidget
* dw3
= createDockWidget("Watches", p
, 0, i18n("Watches"));
60 m_watches
= new WatchWindow(dw3
, "watches");
61 dw3
->setWidget(m_watches
);
62 KDockWidget
* dw4
= createDockWidget("Registers", p
, 0, i18n("Registers"));
63 m_registers
= new RegisterView(dw4
, "registers");
64 dw4
->setWidget(m_registers
);
65 KDockWidget
* dw5
= createDockWidget("Breakpoints", p
, 0, i18n("Breakpoints"));
66 m_bpTable
= new BreakpointTable(dw5
, "breakpoints");
67 dw5
->setWidget(m_bpTable
);
68 KDockWidget
* dw6
= createDockWidget("Output", p
, 0, i18n("Output"));
69 m_ttyWindow
= new TTYWindow(dw6
, "output");
70 dw6
->setWidget(m_ttyWindow
);
71 KDockWidget
* dw7
= createDockWidget("Threads", p
, 0, i18n("Threads"));
72 m_threads
= new ThreadList(dw7
, "threads");
73 dw7
->setWidget(m_threads
);
74 KDockWidget
* dw8
= createDockWidget("Memory", p
, 0, i18n("Memory"));
75 m_memoryWindow
= new MemoryWindow(dw8
, "memory");
76 dw8
->setWidget(m_memoryWindow
);
78 setupDebugger(this, m_localVariables
, m_watches
->watchVariables(), m_btWindow
);
79 m_bpTable
->setDebugger(m_debugger
);
80 m_memoryWindow
->setDebugger(m_debugger
);
83 initToolbar(); // kind of obsolete?
85 connect(m_watches
, SIGNAL(addWatch()), SLOT(slotAddWatch()));
86 connect(m_watches
, SIGNAL(deleteWatch()), m_debugger
, SLOT(slotDeleteWatch()));
88 KAction
* windowMenu
= actionCollection()->action("window");
89 m_filesWindow
->setWindowMenu(static_cast<KActionMenu
*>(windowMenu
)->popupMenu());
90 connect(&m_filesWindow
->m_findDlg
, SIGNAL(closed()), SLOT(updateUI()));
91 connect(m_filesWindow
, SIGNAL(newFileLoaded()),
92 SLOT(slotNewFileLoaded()));
93 connect(m_filesWindow
, SIGNAL(toggleBreak(const QString
&,int,const DbgAddr
&,bool)),
94 this, SLOT(slotToggleBreak(const QString
&,int,const DbgAddr
&,bool)));
95 connect(m_filesWindow
, SIGNAL(enadisBreak(const QString
&,int,const DbgAddr
&)),
96 this, SLOT(slotEnaDisBreak(const QString
&,int,const DbgAddr
&)));
97 connect(m_debugger
, SIGNAL(activateFileLine(const QString
&,int,const DbgAddr
&)),
98 m_filesWindow
, SLOT(activate(const QString
&,int,const DbgAddr
&)));
99 connect(m_debugger
, SIGNAL(executableUpdated()),
100 m_filesWindow
, SLOT(reloadAllFiles()));
101 connect(m_debugger
, SIGNAL(updatePC(const QString
&,int,const DbgAddr
&,int)),
102 m_filesWindow
, SLOT(updatePC(const QString
&,int,const DbgAddr
&,int)));
103 // value popup communication
104 connect(m_filesWindow
, SIGNAL(initiateValuePopup(const QString
&)),
105 m_debugger
, SLOT(slotValuePopup(const QString
&)));
106 connect(m_debugger
, SIGNAL(valuePopup(const QString
&)),
107 m_filesWindow
, SLOT(slotShowValueTip(const QString
&)));
109 connect(m_filesWindow
, SIGNAL(disassemble(const QString
&, int)),
110 m_debugger
, SLOT(slotDisassemble(const QString
&, int)));
111 connect(m_debugger
, SIGNAL(disassembled(const QString
&,int,const QList
<DisassembledCode
>&)),
112 m_filesWindow
, SLOT(slotDisassembled(const QString
&,int,const QList
<DisassembledCode
>&)));
113 connect(m_filesWindow
, SIGNAL(moveProgramCounter(const QString
&,int,const DbgAddr
&)),
114 m_debugger
, SLOT(setProgramCounter(const QString
&,int,const DbgAddr
&)));
116 connect(m_debugger
, SIGNAL(programStopped()), SLOT(slotProgramStopped()));
117 connect(&m_backTimer
, SIGNAL(timeout()), SLOT(slotBackTimer()));
119 connect(this, SIGNAL(setTabWidth(int)), m_filesWindow
, SIGNAL(setTabWidth(int)));
121 // Establish communication when right clicked on file window.
122 connect(m_filesWindow
, SIGNAL(filesRightClick(const QPoint
&)),
123 SLOT(slotFileWndMenu(const QPoint
&)));
125 // Connection when right clicked on file window before any file is
127 connect(m_filesWindow
, SIGNAL(clickedRight(const QPoint
&)),
128 SLOT(slotFileWndEmptyMenu(const QPoint
&)));
131 connect(m_filesWindow
, SIGNAL(fileChanged()), SLOT(slotFileChanged()));
132 connect(m_filesWindow
, SIGNAL(lineChanged()), SLOT(slotLineChanged()));
134 // connect breakpoint table
135 connect(m_bpTable
, SIGNAL(activateFileLine(const QString
&,int,const DbgAddr
&)),
136 m_filesWindow
, SLOT(activate(const QString
&,int,const DbgAddr
&)));
137 connect(m_debugger
, SIGNAL(updateUI()), m_bpTable
, SLOT(updateUI()));
138 connect(m_debugger
, SIGNAL(breakpointsChanged()), m_bpTable
, SLOT(updateBreakList()));
139 connect(m_debugger
, SIGNAL(breakpointsChanged()), m_bpTable
, SLOT(updateUI()));
141 connect(m_debugger
, SIGNAL(registersChanged(QList
<RegisterInfo
>&)),
142 m_registers
, SLOT(updateRegisters(QList
<RegisterInfo
>&)));
144 connect(m_debugger
, SIGNAL(memoryDumpChanged(const QString
&, QList
<MemoryDump
>&)),
145 m_memoryWindow
, SLOT(slotNewMemoryDump(const QString
&, QList
<MemoryDump
>&)));
146 connect(m_debugger
, SIGNAL(saveProgramSpecific(KConfigBase
*)),
147 m_memoryWindow
, SLOT(saveProgramSpecific(KConfigBase
*)));
148 connect(m_debugger
, SIGNAL(restoreProgramSpecific(KConfigBase
*)),
149 m_memoryWindow
, SLOT(restoreProgramSpecific(KConfigBase
*)));
152 connect(m_debugger
, SIGNAL(threadsChanged(QList
<ThreadInfo
>&)),
153 m_threads
, SLOT(updateThreads(QList
<ThreadInfo
>&)));
154 connect(m_threads
, SIGNAL(setThread(int)),
155 m_debugger
, SLOT(setThread(int)));
157 // view menu changes when docking state changes
158 connect(dockManager
, SIGNAL(change()), SLOT(updateUI()));
160 // popup menu of the local variables window
161 connect(m_localVariables
, SIGNAL(contextMenuRequested(QListViewItem
*, const QPoint
&, int)),
162 this, SLOT(slotLocalsPopup(QListViewItem
*, const QPoint
&)));
164 restoreSettings(kapp
->config());
167 m_bpTable
->updateUI();
171 DebuggerMainWnd::~DebuggerMainWnd()
173 saveSettings(kapp
->config());
174 // must delete m_debugger early since it references our windows
178 delete m_memoryWindow
;
184 delete m_localVariables
;
186 delete m_filesWindow
;
189 void DebuggerMainWnd::initKAction()
192 KAction
* open
= KStdAction::open(this, SLOT(slotFileOpen()),
194 open
->setText(i18n("&Open Source..."));
195 (void)new KAction(i18n("&Reload Source"), "reload", 0, m_filesWindow
,
196 SLOT(slotFileReload()), actionCollection(),
198 (void)new KAction(i18n("&Executable..."), "execopen", 0, this,
199 SLOT(slotFileExe()), actionCollection(),
201 m_recentExecAction
= new KRecentFilesAction(i18n("Recent E&xecutables"), 0,
202 this, SLOT(slotRecentExec(const KURL
&)),
203 actionCollection(), "file_executable_recent");
204 (void)new KAction(i18n("&Core dump..."), 0, this, SLOT(slotFileCore()),
205 actionCollection(), "file_core_dump");
206 KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection());
209 (void)new KAction(i18n("This &Program..."), 0, this,
210 SLOT(slotFileProgSettings()), actionCollection(),
212 (void)new KAction(i18n("&Global Options..."), 0, this,
213 SLOT(slotFileGlobalSettings()), actionCollection(),
215 KStdAction::keyBindings(this, SLOT(slotConfigureKeys()), actionCollection());
216 KStdAction::showToolbar(this, SLOT(slotViewToolbar()), actionCollection());
217 KStdAction::showStatusbar(this, SLOT(slotViewStatusbar()), actionCollection());
220 (void)new KToggleAction(i18n("&Find"), "find", CTRL
+Key_F
, m_filesWindow
,
221 SLOT(slotViewFind()), actionCollection(),
223 i18n("Source &code");
224 struct { QString text
; QWidget
* w
; QString id
; } dw
[] = {
225 { i18n("Stac&k"), m_btWindow
, "view_stack"},
226 { i18n("&Locals"), m_localVariables
, "view_locals"},
227 { i18n("&Watched expressions"), m_watches
, "view_watched_expressions"},
228 { i18n("&Registers"), m_registers
, "view_registers"},
229 { i18n("&Breakpoints"), m_bpTable
, "view_breakpoints"},
230 { i18n("T&hreads"), m_threads
, "view_threads"},
231 { i18n("&Output"), m_ttyWindow
, "view_output"},
232 { i18n("&Memory"), m_memoryWindow
, "view_memory"}
234 for (unsigned i
= 0; i
< sizeof(dw
)/sizeof(dw
[0]); i
++) {
235 KDockWidget
* d
= dockParent(dw
[i
].w
);
236 (void)new KToggleAction(dw
[i
].text
, 0, d
, SLOT(changeHideShowState()),
237 actionCollection(), dw
[i
].id
);
242 KAction
* a
= new KAction(i18n("&Run"), "pgmrun", Key_F5
, m_debugger
,
243 SLOT(programRun()), actionCollection(), "exec_run");
244 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
245 a
= new KAction(i18n("Step &into"), "pgmstep", Key_F8
, m_debugger
,
246 SLOT(programStep()), actionCollection(),
248 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
249 a
= new KAction(i18n("Step &over"), "pgmnext", Key_F10
, m_debugger
,
250 SLOT(programNext()), actionCollection(),
252 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
253 a
= new KAction(i18n("Step o&ut"), "pgmfinish", Key_F6
, m_debugger
,
254 SLOT(programFinish()), actionCollection(),
256 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
257 a
= new KAction(i18n("Run to &cursor"), Key_F7
, this,
258 SLOT(slotExecUntil()), actionCollection(),
259 "exec_run_to_cursor");
260 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
261 a
= new KAction(i18n("Step i&nto by instruction"), "pgmstepi",
262 SHIFT
+Key_F8
, m_debugger
, SLOT(programStepi()),
263 actionCollection(), "exec_step_into_by_insn");
264 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
265 a
= new KAction(i18n("Step o&ver by instruction"), "pgmnexti",
266 SHIFT
+Key_F10
, m_debugger
, SLOT(programNexti()),
267 actionCollection(), "exec_step_over_by_insn");
268 connect(a
, SIGNAL(activated()), this, SLOT(intoBackground()));
269 (void)new KAction(i18n("&Program counter to current line"), 0,
270 m_filesWindow
, SLOT(slotMoveProgramCounter()),
271 actionCollection(), "exec_movepc");
272 (void)new KAction(i18n("&Break"), 0, m_debugger
,
273 SLOT(programBreak()), actionCollection(),
275 (void)new KAction(i18n("&Kill"), 0, m_debugger
,
276 SLOT(programKill()), actionCollection(),
278 (void)new KAction(i18n("Re&start"), 0, m_debugger
,
279 SLOT(programRunAgain()), actionCollection(),
281 (void)new KAction(i18n("A&ttach..."), 0, this,
282 SLOT(slotExecAttach()), actionCollection(),
284 (void)new KAction(i18n("&Arguments..."), 0, this,
285 SLOT(slotExecArgs()), actionCollection(),
289 (void)new KAction(i18n("Set/Clear &breakpoint"), "brkpt", Key_F9
,
290 m_filesWindow
, SLOT(slotBrkptSet()), actionCollection(),
292 (void)new KAction(i18n("Set &temporary breakpoint"), SHIFT
+Key_F9
,
293 m_filesWindow
, SLOT(slotBrkptSetTemp()), actionCollection(),
294 "breakpoint_set_temporary");
295 (void)new KAction(i18n("&Enable/Disable breakpoint"), CTRL
+Key_F9
,
296 m_filesWindow
, SLOT(slotBrkptEnable()), actionCollection(),
297 "breakpoint_enable");
299 // only in popup menus
300 (void)new KAction(i18n("Watch Expression"), 0, this,
301 SLOT(slotLocalsToWatch()), actionCollection(),
303 (void)new KAction(i18n("Edit Value"), Key_F2
, this,
304 SLOT(slotEditValue()), actionCollection(),
307 (void)new KActionMenu(i18n("&Window"), actionCollection(), "window");
309 // all actions force an UI update
310 QValueList
<KAction
*> actions
= actionCollection()->actions();
311 QValueList
<KAction
*>::Iterator it
= actions
.begin();
312 for (; it
!= actions
.end(); ++it
) {
313 connect(*it
, SIGNAL(activated()), this, SLOT(updateUI()));
316 createGUI("kdbgui.rc");
319 void DebuggerMainWnd::initToolbar()
321 KToolBar
* toolbar
= toolBar("mainToolBar");
322 toolbar
->setBarPos(KToolBar::Top
);
323 //moveToolBar(toolbar);
325 toolbar
->insertAnimatedWidget(ID_STATUS_BUSY
,
326 actionCollection()->action("exec_break"), SLOT(activate()),
328 toolbar
->alignItemRight(ID_STATUS_BUSY
, true);
329 m_animRunning
= false;
331 KStatusBar
* statusbar
= statusBar();
332 statusbar
->insertItem(m_statusActive
, ID_STATUS_ACTIVE
);
333 m_lastActiveStatusText
= m_statusActive
;
334 statusbar
->insertItem(i18n("Line 00000"), ID_STATUS_LINENO
);
335 statusbar
->insertItem("", ID_STATUS_MSG
); /* message pane */
337 // reserve some translations
343 * We must override KTMainWindow's handling of close events since we have
344 * only one toplevel window, which lives on the stack (which KTMainWindow
345 * can't live with :-( )
347 void DebuggerMainWnd::closeEvent(QCloseEvent
* e
)
349 clearWFlags(WDestructiveClose
);
351 if (m_debugger
!= 0) {
352 m_debugger
->shutdown();
360 // instance properties
361 void DebuggerMainWnd::saveProperties(KConfig
* config
)
363 // session management
364 QString executable
= "";
365 if (m_debugger
!= 0) {
366 executable
= m_debugger
->executable();
368 config
->writeEntry("executable", executable
);
371 void DebuggerMainWnd::readProperties(KConfig
* config
)
373 // session management
374 QString execName
= config
->readEntry("executable");
376 TRACE("readProperties: executable=" + execName
);
377 if (!execName
.isEmpty()) {
378 debugProgram(execName
, "");
382 const char WindowGroup
[] = "Windows";
383 const char RecentExecutables
[] = "RecentExecutables";
384 const char LastSession
[] = "LastSession";
386 void DebuggerMainWnd::saveSettings(KConfig
* config
)
388 KConfigGroupSaver
g(config
, WindowGroup
);
390 writeDockConfig(config
);
391 fixDockConfig(config
, false); // downgrade
393 m_recentExecAction
->saveEntries(config
, RecentExecutables
);
395 KConfigGroupSaver
g2(config
, LastSession
);
396 config
->writeEntry("Width0Locals", m_localVariables
->columnWidth(0));
397 config
->writeEntry("Width0Watches", m_watches
->columnWidth(0));
399 DebuggerMainWndBase::saveSettings(config
);
402 void DebuggerMainWnd::restoreSettings(KConfig
* config
)
404 KConfigGroupSaver
g(config
, WindowGroup
);
406 fixDockConfig(config
, true); // upgrade
407 readDockConfig(config
);
409 // Workaround bug #87787: KDockManager stores the titles of the KDockWidgets
410 // in the config files, although they are localized:
411 // If the user changes the language, the titles remain in the previous language.
412 struct { QString text
; QWidget
* w
; } dw
[] = {
413 { i18n("Stack"), m_btWindow
},
414 { i18n("Locals"), m_localVariables
},
415 { i18n("Watches"), m_watches
},
416 { i18n("Registers"), m_registers
},
417 { i18n("Breakpoints"), m_bpTable
},
418 { i18n("Threads"), m_threads
},
419 { i18n("Output"), m_ttyWindow
},
420 { i18n("Memory"), m_memoryWindow
}
422 for (int i
= 0; i
< int(sizeof(dw
)/sizeof(dw
[0])); i
++)
424 KDockWidget
* w
= dockParent(dw
[i
].w
);
425 w
->setTabPageLabel(dw
[i
].text
);
426 // this actually changes the captions in the tabs:
427 QEvent
ev(QEvent::CaptionChange
);
431 m_recentExecAction
->loadEntries(config
, RecentExecutables
);
433 KConfigGroupSaver
g2(config
, LastSession
);
435 w
= config
->readNumEntry("Width0Locals", -1);
436 if (w
>= 0 && w
< 30000)
437 m_localVariables
->setColumnWidth(0, w
);
438 w
= config
->readNumEntry("Width0Watches", -1);
439 if (w
>= 0 && w
< 30000)
440 m_watches
->setColumnWidth(0, w
);
442 DebuggerMainWndBase::restoreSettings(config
);
444 emit
setTabWidth(m_tabWidth
);
447 void DebuggerMainWnd::updateUI()
449 KToggleAction
* viewFind
=
450 static_cast<KToggleAction
*>(actionCollection()->action("view_find"));
451 viewFind
->setChecked(m_filesWindow
->m_findDlg
.isVisible());
452 viewFind
->setEnabled(m_filesWindow
->hasWindows());
453 actionCollection()->action("breakpoint_set")->setEnabled(m_debugger
->canChangeBreakpoints());
454 actionCollection()->action("breakpoint_set_temporary")->setEnabled(m_debugger
->canChangeBreakpoints());
455 actionCollection()->action("breakpoint_enable")->setEnabled(m_debugger
->canChangeBreakpoints());
456 dockUpdateHelper("view_breakpoints", m_bpTable
);
457 dockUpdateHelper("view_stack", m_btWindow
);
458 dockUpdateHelper("view_locals", m_localVariables
);
459 dockUpdateHelper("view_watched_expressions", m_watches
);
460 dockUpdateHelper("view_registers", m_registers
);
461 dockUpdateHelper("view_threads", m_threads
);
462 dockUpdateHelper("view_memory", m_memoryWindow
);
463 dockUpdateHelper("view_output", m_ttyWindow
);
465 // AB: maybe in mainwndbase.cpp?
466 actionCollection()->action("file_executable")->setEnabled(m_debugger
->isIdle());
467 actionCollection()->action("settings_program")->setEnabled(m_debugger
->haveExecutable());
468 actionCollection()->action("file_core_dump")->setEnabled(m_debugger
->canStart());
469 actionCollection()->action("exec_step_into")->setEnabled(m_debugger
->canSingleStep());
470 actionCollection()->action("exec_step_into_by_insn")->setEnabled(m_debugger
->canSingleStep());
471 actionCollection()->action("exec_step_over")->setEnabled(m_debugger
->canSingleStep());
472 actionCollection()->action("exec_step_over_by_insn")->setEnabled(m_debugger
->canSingleStep());
473 actionCollection()->action("exec_step_out")->setEnabled(m_debugger
->canSingleStep());
474 actionCollection()->action("exec_run_to_cursor")->setEnabled(m_debugger
->canSingleStep());
475 actionCollection()->action("exec_movepc")->setEnabled(m_debugger
->canSingleStep());
476 actionCollection()->action("exec_restart")->setEnabled(m_debugger
->canSingleStep());
477 actionCollection()->action("exec_attach")->setEnabled(m_debugger
->isReady());
478 actionCollection()->action("exec_run")->setEnabled(m_debugger
->canStart() || m_debugger
->canSingleStep());
479 actionCollection()->action("exec_kill")->setEnabled(m_debugger
->haveExecutable() && m_debugger
->isProgramActive());
480 actionCollection()->action("exec_break")->setEnabled(m_debugger
->isProgramRunning());
481 actionCollection()->action("exec_arguments")->setEnabled(m_debugger
->haveExecutable());
482 actionCollection()->action("edit_value")->setEnabled(m_debugger
->canSingleStep());
485 KAnimWidget
* w
= toolBar("mainToolBar")->animatedWidget(ID_STATUS_BUSY
);
486 if (m_debugger
->isIdle()) {
489 m_animRunning
= false;
492 if (!m_animRunning
) {
494 m_animRunning
= true;
500 if (m_debugger
->isProgramActive())
501 newStatus
= m_statusActive
;
502 if (newStatus
!= m_lastActiveStatusText
) {
503 statusBar()->changeItem(newStatus
, ID_STATUS_ACTIVE
);
504 m_lastActiveStatusText
= newStatus
;
506 // line number is updated in slotLineChanged
509 void DebuggerMainWnd::dockUpdateHelper(QString action
, QWidget
* w
)
511 KToggleAction
* item
=
512 static_cast<KToggleAction
*>(actionCollection()->action(action
));
513 bool canChange
= canChangeDockVisibility(w
);
514 item
->setEnabled(canChange
);
515 item
->setChecked(canChange
&& isDockVisible(w
));
518 void DebuggerMainWnd::updateLineItems()
520 m_filesWindow
->updateLineItems(m_debugger
);
523 void DebuggerMainWnd::slotAddWatch()
525 if (m_debugger
!= 0) {
526 QString t
= m_watches
->watchText();
527 m_debugger
->addWatch(t
);
531 void DebuggerMainWnd::slotFileChanged()
536 if (m_debugger
->haveExecutable()) {
537 // basename part of executable
538 QString executable
= m_debugger
->executable();
539 const char* execBase
= executable
.data();
540 int lastSlash
= executable
.findRev('/');
542 execBase
+= lastSlash
+ 1;
547 bool anyWindows
= m_filesWindow
->activeLine(file
, line
);
548 updateLineStatus(anyWindows
? line
: -1);
557 void DebuggerMainWnd::slotLineChanged()
561 bool anyWindows
= m_filesWindow
->activeLine(file
, line
);
562 updateLineStatus(anyWindows
? line
: -1);
565 void DebuggerMainWnd::slotNewFileLoaded()
567 // updates program counter in the new file
569 m_filesWindow
->updateLineItems(m_debugger
);
572 void DebuggerMainWnd::updateLineStatus(int lineNo
)
575 statusBar()->changeItem("", ID_STATUS_LINENO
);
578 strLine
.sprintf(i18n("Line %d"), lineNo
+ 1);
579 statusBar()->changeItem(strLine
, ID_STATUS_LINENO
);
583 KDockWidget
* DebuggerMainWnd::dockParent(QWidget
* w
)
585 while ((w
= w
->parentWidget()) != 0) {
586 if (w
->isA("KDockWidget"))
587 return static_cast<KDockWidget
*>(w
);
592 bool DebuggerMainWnd::isDockVisible(QWidget
* w
)
594 KDockWidget
* d
= dockParent(w
);
595 return d
!= 0 && d
->mayBeHide();
598 bool DebuggerMainWnd::canChangeDockVisibility(QWidget
* w
)
600 KDockWidget
* d
= dockParent(w
);
601 return d
!= 0 && (d
->mayBeHide() || d
->mayBeShow());
604 // upgrades the entries from version 0.0.4 to 0.0.5 and back
605 void DebuggerMainWnd::fixDockConfig(KConfig
* c
, bool upgrade
)
607 static const char dockGroup
[] = "dock_setting_default";
608 if (!c
->hasGroup(dockGroup
))
611 static const char oldVersion
[] = "0.0.4";
612 static const char newVersion
[] = "0.0.5";
613 const char* from
= upgrade
? oldVersion
: newVersion
;
614 const char* to
= upgrade
? newVersion
: oldVersion
;
615 QMap
<QString
,QString
> e
= c
->entryMap(dockGroup
);
616 if (e
["Version"] != from
)
619 KConfigGroupSaver
g(c
, dockGroup
);
620 c
->writeEntry("Version", to
);
621 TRACE(upgrade
? "upgrading dockconfig" : "downgrading dockconfig");
623 // turn all orientation entries from 0 to 1 and from 1 to 0
624 QMap
<QString
,QString
>::Iterator i
;
625 for (i
= e
.begin(); i
!= e
.end(); ++i
)
627 if (i
.key().right(12) == ":orientation") {
628 TRACE("upgrading " + i
.key() + " old value: " + *i
);
629 int orientation
= c
->readNumEntry(i
.key(), -1);
630 if (orientation
>= 0) { // paranoia
631 c
->writeEntry(i
.key(), 1 - orientation
);
637 TTYWindow
* DebuggerMainWnd::ttyWindow()
642 bool DebuggerMainWnd::debugProgram(const QString
& exe
, QCString lang
)
644 // check the file name
647 bool success
= fi
.isFile();
650 QString msg
= i18n("`%1' is not a file or does not exist");
651 KMessageBox::sorry(this, msg
.arg(exe
));
655 success
= DebuggerMainWndBase::debugProgram(fi
.absFilePath(), lang
, this);
660 m_recentExecAction
->addURL(KURL(fi
.absFilePath()));
662 // keep the directory
663 m_lastDirectory
= fi
.dirPath(true);
664 m_filesWindow
->setExtraDirectory(m_lastDirectory
);
668 m_recentExecAction
->removeURL(KURL(fi
.absFilePath()));
674 void DebuggerMainWnd::slotNewStatusMsg()
676 newStatusMsg(statusBar());
679 void DebuggerMainWnd::slotFileGlobalSettings()
681 int oldTabWidth
= m_tabWidth
;
683 doGlobalOptions(this);
685 if (m_tabWidth
!= oldTabWidth
) {
686 emit
setTabWidth(m_tabWidth
);
690 void DebuggerMainWnd::slotDebuggerStarting()
692 DebuggerMainWndBase::slotDebuggerStarting();
695 void DebuggerMainWnd::slotToggleBreak(const QString
& fileName
, int lineNo
,
696 const DbgAddr
& address
, bool temp
)
698 // lineNo is zero-based
699 if (m_debugger
!= 0) {
700 m_debugger
->setBreakpoint(fileName
, lineNo
, address
, temp
);
704 void DebuggerMainWnd::slotEnaDisBreak(const QString
& fileName
, int lineNo
,
705 const DbgAddr
& address
)
707 // lineNo is zero-based
708 if (m_debugger
!= 0) {
709 m_debugger
->enableDisableBreakpoint(fileName
, lineNo
, address
);
713 QString
DebuggerMainWnd::createOutputWindow()
715 QString tty
= DebuggerMainWndBase::createOutputWindow();
716 if (!tty
.isEmpty()) {
717 connect(m_outputTermProc
, SIGNAL(processExited(KProcess
*)),
718 SLOT(slotTermEmuExited()));
723 void DebuggerMainWnd::slotTermEmuExited()
725 shutdownTermWindow();
728 void DebuggerMainWnd::slotProgramStopped()
730 // when the program stopped, move the window to the foreground
731 if (m_popForeground
) {
732 // unfortunately, this requires quite some force to work :-(
733 KWin::raiseWindow(winId());
734 KWin::forceActiveWindow(winId());
739 void DebuggerMainWnd::intoBackground()
741 if (m_popForeground
) {
742 m_backTimer
.start(m_backTimeout
, true); /* single-shot */
746 void DebuggerMainWnd::slotBackTimer()
751 void DebuggerMainWnd::slotRecentExec(const KURL
& url
)
753 QString exe
= url
.path();
754 debugProgram(exe
, "");
757 QString
DebuggerMainWnd::makeSourceFilter()
760 f
= m_sourceFilter
+ " " + m_headerFilter
+ i18n("|All source files\n");
761 f
+= m_sourceFilter
+ i18n("|Source files\n");
762 f
+= m_headerFilter
+ i18n("|Header files\n");
763 f
+= i18n("*|All files");
768 * Pop up the context menu in the locals window
770 void DebuggerMainWnd::slotLocalsPopup(QListViewItem
*, const QPoint
& pt
)
773 static_cast<QPopupMenu
*>(factory()->container("popup_locals", this));
777 if (popup
->isVisible()) {
785 * Copies the currently selected item to the watch window.
787 void DebuggerMainWnd::slotLocalsToWatch()
789 VarTree
* item
= m_localVariables
->selectedItem();
791 if (item
!= 0 && m_debugger
!= 0) {
792 QString text
= item
->computeExpr();
793 m_debugger
->addWatch(text
);
798 * Starts editing a value in a value display
800 void DebuggerMainWnd::slotEditValue()
802 // does one of the value trees have the focus
803 QWidget
* f
= kapp
->focusWidget();
805 if (f
== m_localVariables
) {
806 wnd
= m_localVariables
;
807 } else if (f
== m_watches
->watchVariables()) {
808 wnd
= m_watches
->watchVariables();
813 if (m_localVariables
->isEditing() ||
814 m_watches
->watchVariables()->isEditing())
816 return; /* don't edit twice */
819 VarTree
* expr
= wnd
->currentItem();
820 if (expr
!= 0 && m_debugger
!= 0 && m_debugger
->canSingleStep())
823 // determine the text to edit
824 QString text
= m_debugger
->driver()->editableValue(expr
);
825 wnd
->editValue(expr
, text
);
829 // Pop up the context menu of the files window (for loaded files)
830 void DebuggerMainWnd::slotFileWndMenu(const QPoint
& pos
)
833 static_cast<QPopupMenu
*>(factory()->container("popup_files", this));
837 if (popup
->isVisible()) {
840 // pos is still in widget coordinates of the sender
841 const QWidget
* w
= static_cast<const QWidget
*>(sender());
842 popup
->popup(w
->mapToGlobal(pos
));
846 // Pop up the context menu of the files window (while no file is loaded)
847 void DebuggerMainWnd::slotFileWndEmptyMenu(const QPoint
& pos
)
850 static_cast<QPopupMenu
*>(factory()->container("popup_files_empty", this));
854 if (popup
->isVisible()) {
857 // pos is still in widget coordinates of the sender
858 const QWidget
* w
= static_cast<const QWidget
*>(sender());
859 popup
->popup(w
->mapToGlobal(pos
));
863 void DebuggerMainWnd::slotFileOpen()
865 // start browsing in the active file's directory
866 // fall back to last used directory (executable)
867 QString dir
= m_lastDirectory
;
868 QString fileName
= m_filesWindow
->activeFileName();
869 if (!fileName
.isEmpty()) {
870 QFileInfo
fi(fileName
);
874 fileName
= myGetFileName(i18n("Open"),
876 makeSourceFilter(), this);
878 if (!fileName
.isEmpty())
880 QFileInfo
fi(fileName
);
881 m_lastDirectory
= fi
.dirPath();
882 m_filesWindow
->setExtraDirectory(m_lastDirectory
);
883 m_filesWindow
->activateFile(fileName
);
887 void DebuggerMainWnd::slotFileQuit()
889 if (m_debugger
!= 0) {
890 m_debugger
->shutdown();
895 void DebuggerMainWnd::slotFileExe()
897 if (m_debugger
->isIdle())
899 // open a new executable
900 QString executable
= myGetFileName(i18n("Select the executable to debug"),
901 m_lastDirectory
, 0, this);
902 if (executable
.isEmpty())
905 debugProgram(executable
, "");
909 void DebuggerMainWnd::slotFileCore()
911 if (m_debugger
->canStart())
913 QString corefile
= myGetFileName(i18n("Select core dump"),
914 m_lastDirectory
, 0, this);
915 if (!corefile
.isEmpty()) {
916 m_debugger
->useCoreFile(corefile
, false);
921 void DebuggerMainWnd::slotFileProgSettings()
923 if (m_debugger
!= 0) {
924 m_debugger
->programSettings(this);
928 void DebuggerMainWnd::slotViewToolbar()
930 if (toolBar()->isVisible())
936 void DebuggerMainWnd::slotViewStatusbar()
938 if (statusBar()->isVisible())
944 void DebuggerMainWnd::slotExecUntil()
950 if (m_filesWindow
->activeLine(file
, lineNo
))
951 m_debugger
->runUntil(file
, lineNo
);
955 void DebuggerMainWnd::slotExecAttach()
958 ProcAttachPS
dlg(this);
959 // seed filter with executable name
960 QFileInfo fi
= m_debugger
->executable();
961 dlg
.filterEdit
->setText(fi
.fileName());
963 ProcAttach
dlg(this);
964 dlg
.setText(m_debugger
->attachedPid());
967 m_debugger
->attachProgram(dlg
.text());
971 void DebuggerMainWnd::slotExecArgs()
973 if (m_debugger
!= 0) {
974 m_debugger
->programArgs(this);
978 void DebuggerMainWnd::slotConfigureKeys()
980 KKeyDialog::configure(actionCollection(), this);
983 #include "dbgmainwnd.moc"