Example #1
0
	bool DebugCLI::filterException(Exception *exception, bool /*willBeCaught*/)
	{
		// Filter exceptions when -d switch specified
		if (activeFlag) {
			core->console << "Exception has been thrown:\n"
						  << core->string(exception->atom)
						  << '\n';
			enterDebugger();
			return true;
		}
		return false;
	}
Example #2
0
int mainloop(int flags)
{
	unsigned char a, f, b, c, d, e, h, l;
	unsigned char r, i, iff1, iff2, im;
	unsigned short pc;
	unsigned short sp;
	extern unsigned long tstates;
	unsigned int radjust;
	unsigned char intsample;
	unsigned char op;
	int	states_until_timerint;
	unsigned long last_tstates;
	unsigned startTime = tstates;
	int cpuRunning = 1;
	clock_t max_run_time = clock() + CLOCKS_PER_SEC*30;
	unsigned run_time_check_mod = 0;

	int j, runOne = 0;

	struct sregs regs =
	{
	  &a, &f, &b, &c, &d, &e, &h, &l, &pc, &sp, &cpuRunning
	};
	a = f = b = c = d = e = h = l = i = r = iff1 = iff2 = im = 0;
	fun_first = NULL;
	sp = pc = 0;
	sp = 0xdfff;
	pc = 0x100;		/* GB start address */
	tstates = 0;
	last_tstates=0;
	callback_stack_pos = 0;
	states_until_timerint = 40000;

	for (j = 0; j < 5; j++)
		breakpoints[j] = 0;

	if (flags&DSTARTDEBUG)
		breakpoints[0] = 0x100;

	while (cpuRunning) {
		if (runOne) {
			if (enterDebugger(&regs))
				runOne = 1;
			else
				runOne = 0;
		}
		j = 0;
		while (j < 5) {
			if (breakpoints[j] == pc) {
				if (enterDebugger(&regs))
					runOne = 1;
				break;
			}
			j++;
		}
		op = fetch(pc);
		pc++;
		switch (op) {
#include "z80ops.c"
		default:
			printf("\nrrgb: warning - invalid opcode %02x at %04x.\n", op, pc - 1);
			enterDebugger(&regs);
			break;
		}
		if (flags&DTIMERINT) {
			states_until_timerint-=tstates-last_tstates;
			last_tstates=tstates;
			if (states_until_timerint<0) {
				states_until_timerint=40000;
				push2(pc);
				pc=0x50;
			}
		}
		if (flags&DLIMITEDRUN && (++run_time_check_mod) == 100) {
		  if (clock() > max_run_time) {
    		    	printf("Error: Maximum runtime exceeded\n");
		  	cpuRunning = 0;
		  }
		  run_time_check_mod = 0;
		}
	}
	return 0;
}
Example #3
0
    void Debugger::debugLine(int linenum)
    {
        AvmAssert( core->callStack !=0 );
        if (!core->callStack)
            return;

        AvmAssert(linenum > 0);

        int prev = core->callStack->linenum();
        core->callStack->set_linenum(linenum);

        int line = linenum;

        // line number has changed
        bool changed = (prev == line) ? false : true;
        bool exited =  (prev == -1) ? true : false; // are we being called as a result of function exit?
        if (!changed && !exited)
            return;  // still on the same line in the same function?

        Profiler* profiler = core->profiler();
        Sampler* s = core->get_sampler();
        if (profiler && profiler->profilingDataWanted && profiler->profileSwitch && !(s && s->sampling()))
        {
            profiler->sendLineTimestamp(line);
        }

        // tracing information
        if (!exited)
            traceLine(line);

        // check if we should stop due to breakpoint or step
        bool stop = false;
        if (stepState.flag)
        {
            if (stepState.startingDepth != -1 && core->callStack->depth() < stepState.startingDepth)
            {
                // We stepped out of whatever function was executing when the
                // stepInto/stepOver/stepOut command was executed.  We may be
                // in the middle of a line of code, but we still want to stop
                // immediately.  See bug 126633.
                stop = true;
            }
            else if (!exited && (stepState.depth == -1 || core->callStack->depth() <= stepState.depth) )
            {
                // We reached the beginning of a new line of code.
                stop = true;
            }
        }

        // we didn't decide to stop due to a step, but check if we hit a breakpoint
        if (!stop && !exited)
        {
            MethodInfo* f = core->callStack->info();
#ifdef VMCFG_AOT
            if (f && (f->hasMethodBody() || f->isCompiledMethod()))
#else
            if (f && f->hasMethodBody())
#endif
            {
                AbcFile* abc = f->file();
                if (abc)
                {
                    SourceFile* source = abc->sourceNamed( core->callStack->filename() );
                    if (source && source->hasBreakpoint(line))
                    {
                        stop = true;
                    }
                }
            }
        }

        // we still haven't decided to stop; check our watchpoints
        if (!stop && !exited)
        {
            if (hitWatchpoint())
                stop = true;
        }

        if (stop)
        {
            // Terminate whatever step operation may have been happening.  But first,
            // save the state of the step, so that if someone calls stepContinue(),
            // then we can restore it.
            StepState oldOldStepState = oldStepState; // save oldStepState in case of reentrancy
            oldStepState = stepState; // save stepState so that stepContinue() can find it
            stepState.clear(); // turn off stepping

            enterDebugger();

            oldStepState = oldOldStepState; // restore oldStepState
        }
    }
Example #4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // Register QtKeypadBridge for the virtual keyboard functionality
    ui->keypadWidget->installEventFilter(&qt_keypad_bridge);
    ui->lcdView->installEventFilter(&qt_keypad_bridge);

    //Emu -> GUI (QueuedConnection as they're different threads)
    connect(&emu, SIGNAL(serialChar(char)), this, SLOT(serialChar(char)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(debugStr(QString)), this, SLOT(debugStr(QString))); //Not queued connection as it may cause a hang
    connect(&emu, SIGNAL(speedChanged(double)), this, SLOT(showSpeed(double)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(statusMsg(QString)), ui->statusbar, SLOT(showMessage(QString)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(turboModeChanged(bool)), ui->buttonSpeed, SLOT(setChecked(bool)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(usblinkChanged(bool)), this, SLOT(usblinkChanged(bool)), Qt::QueuedConnection);

    //Menu "Emulator"
    connect(ui->buttonReset, SIGNAL(clicked(bool)), &emu, SLOT(reset()));
    connect(ui->actionReset, SIGNAL(triggered()), &emu, SLOT(reset()));
    connect(ui->actionRestart, SIGNAL(triggered()), this, SLOT(restart()));
    connect(ui->actionDebugger, SIGNAL(triggered()), &emu, SLOT(enterDebugger()));
    connect(ui->buttonPause, SIGNAL(clicked(bool)), &emu, SLOT(setPaused(bool)));
    connect(ui->buttonPause, SIGNAL(clicked(bool)), ui->actionPause, SLOT(setChecked(bool)));
    connect(ui->actionPause, SIGNAL(toggled(bool)), &emu, SLOT(setPaused(bool)));
    connect(ui->actionPause, SIGNAL(toggled(bool)), ui->buttonPause, SLOT(setChecked(bool)));
    connect(ui->buttonSpeed, SIGNAL(clicked(bool)), &emu, SLOT(setTurboMode(bool)));
    QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_F11), this);
    shortcut->setAutoRepeat(false);
    connect(shortcut, SIGNAL(activated()), &emu, SLOT(toggleTurbo()));

    //Menu "Tools"
    connect(ui->buttonScreenshot, SIGNAL(clicked()), this, SLOT(screenshot()));
    connect(ui->actionScreenshot, SIGNAL(triggered()), this, SLOT(screenshot()));
    connect(ui->actionConnect, SIGNAL(triggered()), this, SLOT(connectUSB()));
    connect(ui->buttonUSB, SIGNAL(clicked(bool)), this, SLOT(connectUSB()));
    connect(ui->actionXModem, SIGNAL(triggered()), this, SLOT(xmodemSend()));
    ui->actionConnect->setShortcut(QKeySequence(Qt::Key_F10));
    ui->actionConnect->setAutoRepeat(false);

    //Menu "Flash"
    connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveFlash()));
    connect(ui->actionCreate_flash, SIGNAL(triggered()), this, SLOT(createFlash()));

    //Debugging
    connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(debugCommand()));

    //File transfer
    connect(ui->refreshButton, SIGNAL(clicked(bool)), this, SLOT(reload_filebrowser()));
    connect(this, SIGNAL(usblink_progress_changed(int)), this, SLOT(changeProgress(int)), Qt::QueuedConnection);

    //Settings
    connect(ui->checkDebugger, SIGNAL(toggled(bool)), this, SLOT(setDebuggerOnStartup(bool)));
    connect(ui->checkWarning, SIGNAL(toggled(bool)), this, SLOT(setDebuggerOnWarning(bool)));
    connect(ui->uiDocks, SIGNAL(toggled(bool)), this, SLOT(setUIMode(bool)));
    connect(ui->checkAutostart, SIGNAL(toggled(bool)), this, SLOT(setAutostart(bool)));
    connect(ui->fileBoot1, SIGNAL(pressed()), this, SLOT(selectBoot1()));
    connect(ui->fileFlash, SIGNAL(pressed()), this, SLOT(selectFlash()));
    connect(ui->pathTransfer, SIGNAL(textEdited(QString)), this, SLOT(setUSBPath(QString)));
    connect(ui->spinGDB, SIGNAL(valueChanged(int)), this, SLOT(setGDBPort(int)));
    connect(ui->spinRDBG, SIGNAL(valueChanged(int)), this, SLOT(setRDBGPort(int)));
    connect(ui->orderDiags, SIGNAL(toggled(bool)), this, SLOT(setBootOrder(bool)));

    //Set up monospace fonts
    QFont monospace = QFontDatabase::systemFont(QFontDatabase::FixedFont);
    ui->debugConsole->setFont(monospace);
    ui->serialConsole->setFont(monospace);

    qRegisterMetaType<QVector<int>>();

#ifdef Q_OS_ANDROID
    //On android the settings file is deleted everytime you update or uninstall,
    //so choose a better, safer, location
    QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
    settings = new QSettings(path + "/nspire_emu.ini", QSettings::IniFormat);
#else
    settings = new QSettings();
#endif

    //Load settings
    setUIMode(settings->value("docksEnabled", true).toBool());
    restoreGeometry(settings->value("windowGeometry").toByteArray());
    restoreState(settings->value("windowState").toByteArray(), WindowStateVersion);
    selectBoot1(settings->value("boot1", "").toString());
    selectFlash(settings->value("flash", "").toString());
    setDebuggerOnStartup(settings->value("debugOnStart", false).toBool());
    setDebuggerOnWarning(settings->value("debugOnWarn", false).toBool());
    setUSBPath(settings->value("usbdir", QString("ndless")).toString());
    setGDBPort(settings->value("gdbPort", 3333).toUInt());
    setRDBGPort(settings->value("rdbgPort", 3334).toUInt());
    setBootOrder(false);

    bool autostart = settings->value("emuAutostart", false).toBool();
    setAutostart(autostart);
    if(emu.boot1 != "" && emu.flash != "" && autostart)
        emu.start();
    else
        ui->statusbar->showMessage(trUtf8("Start the emulation via Emulation->Restart."));

    #ifdef Q_OS_MAC
        QTimer::singleShot(50, [&] {dockVisibilityChanged(false);}); // Trigger dock update (after UI was shown)
    #endif
}