3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
8 #include <klocale.h> /* i18n */
9 #include <kmessagebox.h>
12 #include <kcmdlineargs.h>
13 #include <kaboutdata.h>
14 #include <kpopupmenu.h>
16 #include "dbgmainwnd.h"
17 #include "typetable.h"
25 #include <fcntl.h> /* open(2) */
28 #include <unistd.h> /* getopt(3) */
30 #include <stdlib.h> /* getenv(3) */
34 int main(int argc
, char** argv
)
36 KAboutData
aboutData("kdbg", "KDbg",
38 I18N_NOOP("A Debugger"),
39 KAboutData::License_GPL
,
40 "(c) 1998-2007 Johannes Sixt",
42 "http://www.kdbg.org/",
43 "Johannes.Sixt@telecom.at");
44 aboutData
.addAuthor("Johannes Sixt", 0, "Johannes.Sixt@telecom.at");
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},
64 KCmdLineArgs::addCmdLineOptions(options
);
68 KGlobal::dirs()->addResourceType("types", "share/apps/kdbg/types");
70 DebuggerMainWnd
debugger("kdbg_main");
73 TypeTable::initTypeLibraries();
76 bool restored
= false;
77 if (app
.isRestored()) {
78 if (KMainWindow::canBeRestored(1)) {
84 app
.setMainWidget(&debugger
);
90 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
91 QCString t
= args
->getOption("t");
92 const char* transcript
= t
.data();
93 QString remote
= args
->getOption("r");
94 if (!remote
.isEmpty())
95 debugger
.setRemoteDevice(remote
);
97 QCString lang
= args
->getOption("l");
99 // deprecated option; overrides -l
100 if (args
->isSet("x")){
101 /* run in xsldbg mode */
105 // check environment variable for transcript file name
106 if (transcript
== 0) {
107 transcript
= getenv("KDBG_TRANSCRIPT");
109 debugger
.setTranscript(transcript
);
111 QString pid
= args
->getOption("p");
112 QString programArgs
= args
->getOption("a");
114 if (!restored
&& args
->count() > 0) {
115 // attach to process?
116 if (!pid
.isEmpty()) {
117 TRACE("pid: " + pid
);
118 debugger
.setAttachPid(pid
);
120 // check for core file; use it only if we're not attaching to a process
121 else if (args
->count() > 1 && pid
.isEmpty()) {
122 debugger
.setCoreFile(args
->arg(1));
124 if (!debugger
.debugProgram(args
->arg(0), lang
)) {
126 TRACE("cannot start debugger");
127 KMessageBox::error(&debugger
, i18n("Cannot start debugger."));
129 debugger
.setCoreFile(QString());
130 debugger
.setAttachPid(QString());
132 if (!programArgs
.isEmpty()) {
133 debugger
.overrideProgramArguments(programArgs
);