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 <kaboutdata.h>
14 #include <kpopupmenu.h>
16 #include "dbgmainwnd.h"
17 #include "typetable.h"
24 #include <stdlib.h> /* getenv(3) */
28 int main(int argc
, char** argv
)
30 KAboutData
aboutData("kdbg", "KDbg",
32 I18N_NOOP("A Debugger"),
33 KAboutData::License_GPL
,
34 "(c) 1998-2009 Johannes Sixt",
36 "http://www.kdbg.org/",
38 aboutData
.addAuthor("Johannes Sixt", 0, "j6t@kdbg.org");
39 aboutData
.addCredit("Keith Isdale",
40 I18N_NOOP("XSLT debugging"),
41 "k_isdale@tpg.com.au");
42 aboutData
.addCredit("Daniel Kristjansson",
43 I18N_NOOP("Register groups and formating"),
44 "danielk@cat.nyu.edu");
45 KCmdLineArgs::init( argc
, argv
, &aboutData
);
47 static KCmdLineOptions options
[] = {
48 { "t <file>", I18N_NOOP("transcript of conversation with the debugger"), 0 },
49 { "r <device>", I18N_NOOP("remote debugging via <device>"), 0 },
50 { "l <language>", I18N_NOOP("specify language: C, XSLT"), ""},
51 { "x", I18N_NOOP("use language XSLT (deprecated)"), 0 },
52 { "a <args>", I18N_NOOP("specify arguments of debugged executable"), 0},
53 { "p <pid>", I18N_NOOP("specify PID of process to debug"), 0},
54 { "+[program]", I18N_NOOP("path of executable to debug"), 0 },
55 { "+[core]", I18N_NOOP("a core file to use"), 0},
58 KCmdLineArgs::addCmdLineOptions(options
);
62 KGlobal::dirs()->addResourceType("types", "share/apps/kdbg/types");
64 DebuggerMainWnd
* debugger
= new DebuggerMainWnd("kdbg_main");
67 TypeTable::initTypeLibraries();
70 bool restored
= false;
71 if (app
.isRestored()) {
72 if (KMainWindow::canBeRestored(1)) {
78 app
.setMainWidget(debugger
);
84 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
85 QString transcript
= args
->getOption("t");
86 QString remote
= args
->getOption("r");
87 if (!remote
.isEmpty())
88 debugger
->setRemoteDevice(remote
);
90 QString lang
= args
->getOption("l");
92 // deprecated option; overrides -l
93 if (args
->isSet("x")){
94 /* run in xsldbg mode */
98 // check environment variable for transcript file name
99 if (transcript
.isEmpty()) {
100 transcript
= getenv("KDBG_TRANSCRIPT");
102 debugger
->setTranscript(transcript
);
104 QString pid
= args
->getOption("p");
105 QString programArgs
= args
->getOption("a");
107 if (!restored
&& args
->count() > 0) {
108 // attach to process?
109 if (!pid
.isEmpty()) {
110 TRACE("pid: " + pid
);
111 debugger
->setAttachPid(pid
);
113 // check for core file; use it only if we're not attaching to a process
114 else if (args
->count() > 1 && pid
.isEmpty()) {
115 debugger
->setCoreFile(args
->arg(1));
117 if (!debugger
->debugProgram(args
->arg(0), lang
)) {
119 TRACE("cannot start debugger");
120 KMessageBox::error(debugger
, i18n("Cannot start debugger."));
122 debugger
->setCoreFile(QString());
123 debugger
->setAttachPid(QString());
125 if (!programArgs
.isEmpty()) {
126 debugger
->overrideProgramArguments(programArgs
);