2 * Copyright Johannes Sixt
3 * This file is licensed under the GNU General Public License Version 2.
4 * See the file COPYING in the toplevel directory of the source directory.
7 #include <kapplication.h>
8 #include <klocale.h> /* i18n */
9 #include <kmessagebox.h>
11 #include <kstandarddirs.h>
12 #include <kcmdlineargs.h>
13 #include <k4aboutdata.h>
14 #include "dbgmainwnd.h"
15 #include "typetable.h"
17 #include <stdlib.h> /* getenv(3) */
21 int main(int argc
, char** argv
)
23 K4AboutData
aboutData("kdbg", "kdbg", ki18n("KDbg"),
26 K4AboutData::License_GPL
,
27 ki18n("(c) 1998-2016 Johannes Sixt"),
28 KLocalizedString(), /* any text */
29 "http://www.kdbg.org/",
31 aboutData
.addAuthor(ki18n("Johannes Sixt"), KLocalizedString(), "j6t@kdbg.org");
32 aboutData
.addCredit(ki18n("Keith Isdale"),
33 ki18n("XSLT debugging"),
34 "k_isdale@tpg.com.au");
35 aboutData
.addCredit(ki18n("Daniel Kristjansson"),
36 ki18n("Register groups and formatting"),
37 "danielk@cat.nyu.edu");
38 aboutData
.addCredit(ki18n("David Edmundson"),
39 ki18n("KDE4 porting"),
40 "david@davidedmundson.co.uk");
41 KCmdLineArgs::init( argc
, argv
, &aboutData
);
44 opts
.add("t <file>", ki18n("transcript of conversation with the debugger"));
45 opts
.add("r <device>", ki18n("remote debugging via <device>"));
46 opts
.add("l <language>", ki18n("specify language: C, XSLT"));
47 opts
.add("x", ki18n("use language XSLT (deprecated)"));
48 opts
.add("a <args>", ki18n("specify arguments of debugged executable"));
49 opts
.add("p <pid>", ki18n("specify PID of process to debug"));
50 opts
.add("+[program]", ki18n("path of executable to debug"));
51 opts
.add("+[core]", ki18n("a core file to use"));
52 KCmdLineArgs::addCmdLineOptions(opts
);
56 KGlobal::dirs()->addResourceType("types", "data", "kdbg/types");
57 KGlobal::dirs()->addResourceType("sessions", "data", "kdbg/sessions");
59 DebuggerMainWnd
* debugger
= new DebuggerMainWnd
;
60 debugger
->setObjectName("mainwindow");
63 TypeTable::initTypeLibraries();
66 bool restored
= false;
67 if (app
.isSessionRestored()) {
68 if (KMainWindow::canBeRestored(1)) {
78 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
79 QString transcript
= args
->getOption("t");
80 QString remote
= args
->getOption("r");
81 if (!remote
.isEmpty())
82 debugger
->setRemoteDevice(remote
);
84 QString lang
= args
->getOption("l");
86 // deprecated option; overrides -l
87 if (args
->isSet("x")){
88 /* run in xsldbg mode */
92 // check environment variable for transcript file name
93 if (transcript
.isEmpty()) {
94 transcript
= getenv("KDBG_TRANSCRIPT");
96 debugger
->setTranscript(transcript
);
98 QString pid
= args
->getOption("p");
99 QString programArgs
= args
->getOption("a");
101 if (!restored
&& args
->count() > 0) {
102 // attach to process?
103 if (!pid
.isEmpty()) {
104 TRACE("pid: " + pid
);
105 debugger
->setAttachPid(pid
);
107 // check for core file; use it only if we're not attaching to a process
108 else if (args
->count() > 1 && pid
.isEmpty()) {
109 debugger
->setCoreFile(args
->arg(1));
111 if (!debugger
->debugProgram(args
->arg(0), lang
)) {
113 TRACE("cannot start debugger");
114 KMessageBox::error(debugger
, i18n("Cannot start debugger."));
116 debugger
->setCoreFile(QString());
117 debugger
->setAttachPid(QString());
119 if (!programArgs
.isEmpty()) {
120 debugger
->overrideProgramArguments(programArgs
);