Avoid subdirectories for program configuration files.
[kdbg.git] / kdbg / main.cpp
blob3deb62f456a1718b57a2f3d195dc34e3ce4ea2f5
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 "dbgmainwnd.h"
15 #include "typetable.h"
16 #include "version.h"
17 #include <stdlib.h> /* getenv(3) */
18 #include "mydebug.h"
21 int main(int argc, char** argv)
23 KAboutData aboutData("kdbg", "kdbg", ki18n("KDbg"),
24 KDBG_VERSION,
25 ki18n("A Debugger"),
26 KAboutData::License_GPL,
27 ki18n("(c) 1998-2010 Johannes Sixt"),
28 KLocalizedString(), /* any text */
29 "http://www.kdbg.org/",
30 "j6t@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 formating"),
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 );
43 KCmdLineOptions opts;
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);
54 KApplication app;
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");
62 /* type libraries */
63 TypeTable::initTypeLibraries();
65 // session management
66 bool restored = false;
67 if (app.isSessionRestored()) {
68 if (KMainWindow::canBeRestored(1)) {
69 debugger->restore(1);
70 restored = true;
74 debugger->show();
76 // handle options
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 */
89 lang = "xslt";
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)) {
112 // failed
113 TRACE("cannot start debugger");
114 KMessageBox::error(debugger, i18n("Cannot start debugger."));
116 debugger->setCoreFile(QString());
117 debugger->setAttachPid(QString());
118 } else {
119 if (!programArgs.isEmpty()) {
120 debugger->overrideProgramArguments(programArgs);
125 int rc = app.exec();
126 return rc;