summaryrefslogtreecommitdiffstats
path: root/kdbg/main.cpp
blob: 0f067e321e98368945702915936fe800b8d00604 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * Copyright Johannes Sixt
 * This file is licensed under the GNU General Public License Version 2.
 * See the file COPYING in the toplevel directory of the source directory.
 */

#include <kapplication.h>
#include <klocale.h>			/* i18n */
#include <kmessagebox.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <kcmdlineargs.h> 
#include <kaboutdata.h>
#include <kpopupmenu.h>
#include <kmenubar.h>
#include "dbgmainwnd.h"
#include "typetable.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef VERSION
#define VERSION ""
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>			/* open(2) */
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>			/* getopt(3) */
#endif
#include <stdlib.h>			/* getenv(3) */
#include "mydebug.h"


int main(int argc, char** argv)
{
    KAboutData aboutData("kdbg", "KDbg",
			 VERSION,
			 I18N_NOOP("A Debugger"),
			 KAboutData::License_GPL, 
			 "(c) 1998-2010 Johannes Sixt",
			 0,		/* any text */
			 "http://www.kdbg.org/",
			 "j6t@kdbg.org");
    aboutData.addAuthor("Johannes Sixt", 0, "j6t@kdbg.org");
    aboutData.addCredit("Keith Isdale",
			I18N_NOOP("XSLT debugging"),
			"k_isdale@tpg.com.au");
    aboutData.addCredit("Daniel Kristjansson",
			I18N_NOOP("Register groups and formating"),
			"danielk@cat.nyu.edu");
    KCmdLineArgs::init( argc, argv, &aboutData );

    static KCmdLineOptions options[] = {
	{ "t <file>", I18N_NOOP("transcript of conversation with the debugger"), 0 },
	{ "r <device>", I18N_NOOP("remote debugging via <device>"), 0 },
	{ "l <language>", I18N_NOOP("specify language: C, XSLT"), ""},
	{ "x", I18N_NOOP("use language XSLT (deprecated)"), 0 },
	{ "a <args>", I18N_NOOP("specify arguments of debugged executable"), 0},
	{ "p <pid>", I18N_NOOP("specify PID of process to debug"), 0},
	{ "+[program]", I18N_NOOP("path of executable to debug"), 0 },
	{ "+[core]", I18N_NOOP("a core file to use"), 0},
	{ 0, 0, 0 }
    };
    KCmdLineArgs::addCmdLineOptions(options);
    
    KApplication app;

    KGlobal::dirs()->addResourceType("types", "share/apps/kdbg/types");

    DebuggerMainWnd* debugger = new DebuggerMainWnd("kdbg_main");

    /* type libraries */
    TypeTable::initTypeLibraries();

    // session management
    bool restored = false;
    if (app.isRestored()) {
	if (KMainWindow::canBeRestored(1)) {
	    debugger->restore(1);
	    restored = true;
	}
    }

    app.setMainWidget(debugger);

    debugger->show();

    // handle options

    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    QString transcript = args->getOption("t");
    QString remote = args->getOption("r");
    if (!remote.isEmpty())
	debugger->setRemoteDevice(remote);

    QString lang = args->getOption("l");

    // deprecated option; overrides -l
    if (args->isSet("x")){
         /* run in xsldbg mode  */
         lang = "xslt";
    }

    // check environment variable for transcript file name
    if (transcript.isEmpty()) {
	transcript = getenv("KDBG_TRANSCRIPT");
    }
    debugger->setTranscript(transcript);

    QString pid = args->getOption("p");
    QString programArgs = args->getOption("a");

    if (!restored && args->count() > 0) {
	// attach to process?
	if (!pid.isEmpty()) {
	    TRACE("pid: " + pid);
	    debugger->setAttachPid(pid);
	}
	// check for core file; use it only if we're not attaching to a process
	else if (args->count() > 1 && pid.isEmpty()) {
	    debugger->setCoreFile(args->arg(1));
	}
	if (!debugger->debugProgram(args->arg(0), lang)) {
	    // failed
	    TRACE("cannot start debugger");
	    KMessageBox::error(debugger, i18n("Cannot start debugger."));

	    debugger->setCoreFile(QString());
	    debugger->setAttachPid(QString());
	} else {
	    if (!programArgs.isEmpty()) {
		debugger->overrideProgramArguments(programArgs);
	    }
	}
    }

    int rc = app.exec();
    return rc;
}