// idbg - IJVM debugger.
// Copyright 2000 Tom Rothamel <tom-idbg@onegeek.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  

#include "idbg.h"

Breakpoint *bps = NULL;

Breakpoint *lookup_breakpoint(int pc) {
	Breakpoint *b = bps;

	while (b) {
		if (b->pc == pc) return b;
		b = b->next;
	}

	return b;
}

void add_breakpoint(int pc) {
	Breakpoint *b;
	
	if (lookup_breakpoint(pc)) {
		oprintf("Breakpoint already exists.\n");
		return;
	}

	b = new Breakpoint;
	b->pc = pc;
	b->prev = NULL;
	b->next = bps;

	if (bps) bps->prev = b;
	bps = b;

	oprint("Breakpoint added at %06X", pc);
	method_name(pc, 0);
	oprintf(".\n");
}

void drop_breakpoint(int pc) {
	Breakpoint *b;

	b = lookup_breakpoint(pc);

	if (!b) {
		oprintf("Couldn't find breakpoint.\n");
		return;
	}

	if (b->next) b->next->prev = b->prev;
	if (b->prev) b->prev->next = b->next;
	if (!b->prev) bps = b->next;

	oprint("Breakpoint dropped from %06X", pc);
	method_name(pc, 0);
	oprintf(".\n");
	
	delete b;
}

void show_breakpoints() {
	Breakpoint *b;

	b = bps;

	while (b) {
		oprint("- Breakpoint at %06X", b->pc);
		method_name(b->pc, 0);
		oprintf("\n");
		b = b->next;
	}
}
			
			
