Merge branch 'maint'
[kdbg.git] / kdbg / main.cpp
blob259c4d7c32bbee6a5d5e3dd61050206f33ca1dad
1 /*
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.
5 */
7 #include <kapplication.h>
8 #include <klocale.h> /* i18n */
9 #include <kmessagebox.h>
10 #include <kglobal.h>
11 #include <kstandarddirs.h>
12 #include <kcmdlineargs.h>
13 #include <kaboutdata.h>
14 #include <kpopupmenu.h>
15 #include <kmenubar.h>
16 #include "dbgmainwnd.h"
17 #include "typetable.h"
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 #ifndef VERSION
22 #define VERSION ""
23 #endif
24 #ifdef HAVE_FCNTL_H
25 #include <fcntl.h> /* open(2) */
26 #endif
27 #ifdef HAVE_UNISTD_H
28 #include <unistd.h> /* getopt(3) */
29 #endif
30 #include <stdlib.h> /* getenv(3) */
31 #include "mydebug.h"
34 int main(int argc, char** argv)
36 KAboutData aboutData("kdbg", "KDbg",
37 VERSION,
38 I18N_NOOP("A Debugger"),
39 KAboutData::License_GPL,
40 "(c) 1998-2009 Johannes Sixt",
41 0, /* any text */
42 "http://www.kdbg.org/",
43 "j6t@kdbg.org");
44 aboutData.addAuthor("Johannes Sixt", 0, "j6t@kdbg.org");
45 aboutData.addCredit("Keith Isdale",
46 I18N_NOOP("XSLT debugging"),
47 "k_isdale@tpg.com.au");
48 aboutData.addCredit("Daniel Kristjansson",
49 I18N_NOOP("Register groups and formating"),
50 "danielk@cat.nyu.edu");
51 KCmdLineArgs::init( argc, argv, &aboutData );
53 static KCmdLineOptions options[] = {
54 { "t <file>", I18N_NOOP("transcript of conversation with the debugger"), 0 },
55 { "r <device>", I18N_NOOP("remote debugging via <device>"), 0 },
56 { "l <language>", I18N_NOOP("specify language: C, XSLT"), ""},
57 { "x", I18N_NOOP("use language XSLT (deprecated)"), 0 },
58 { "a <args>", I18N_NOOP("specify arguments of debugged executable"), 0},
59 { "p <pid>", I18N_NOOP("specify PID of process to debug"), 0},
60 { "+[program]", I18N_NOOP("path of executable to debug"), 0 },
61 { "+[core]", I18N_NOOP("a core file to use"), 0},
62 { 0, 0, 0 }
64 KCmdLineArgs::addCmdLineOptions(options);
66 KApplication app;
68 KGlobal::dirs()->addResourceType("types", "share/apps/kdbg/types");
70 DebuggerMainWnd* debugger = new DebuggerMainWnd("kdbg_main");
72 /* type libraries */
73 TypeTable::initTypeLibraries();
75 // session management
76 bool restored = false;
77 if (app.isRestored()) {
78 if (KMainWindow::canBeRestored(1)) {
79 debugger->restore(1);
80 restored = true;
84 app.setMainWidget(debugger);
86 debugger->show();
88 // handle options
90 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
91 QString transcript = args->getOption("t");
92 QString remote = args->getOption("r");
93 if (!remote.isEmpty())
94 debugger->setRemoteDevice(remote);
96 QString lang = args->getOption("l");
98 // deprecated option; overrides -l
99 if (args->isSet("x")){
100 /* run in xsldbg mode */
101 lang = "xslt";
104 // check environment variable for transcript file name
105 if (transcript.isEmpty()) {
106 transcript = getenv("KDBG_TRANSCRIPT");
108 debugger->setTranscript(transcript);
110 QString pid = args->getOption("p");
111 QString programArgs = args->getOption("a");
113 if (!restored && args->count() > 0) {
114 // attach to process?
115 if (!pid.isEmpty()) {
116 TRACE("pid: " + pid);
117 debugger->setAttachPid(pid);
119 // check for core file; use it only if we're not attaching to a process
120 else if (args->count() > 1 && pid.isEmpty()) {
121 debugger->setCoreFile(args->arg(1));
123 if (!debugger->debugProgram(args->arg(0), lang)) {
124 // failed
125 TRACE("cannot start debugger");
126 KMessageBox::error(debugger, i18n("Cannot start debugger."));
128 debugger->setCoreFile(QString());
129 debugger->setAttachPid(QString());
130 } else {
131 if (!programArgs.isEmpty()) {
132 debugger->overrideProgramArguments(programArgs);
137 int rc = app.exec();
138 return rc;