예제 #1
0
파일: breakpoint.c 프로젝트: def44/mate
int breakpoint_enable(struct breakpoint *b) {
	if (b == NULL) {
		fprintf(stderr, "mvm: breakpoint not initialized!\n");
		exit(1);
	}

	b->enabled = bp_enabled;
	if (b->type == bp_address)
		breakpoint_insert(b);
	
	return 0;
}
예제 #2
0
파일: event.c 프로젝트: sstefani/mtrace
static int handle_breakpoint(struct task *task)
{
	struct breakpoint *bp = task->event.e_un.breakpoint;
	unsigned int hw = bp->hw;

	debug(DEBUG_EVENT, "+++ process pid=%d breakpoint  addr=%#lx", task->pid, bp->addr);

	assert(task->stopped);

	if (unlikely(options.verbose > 1))
		set_timer(&task->halt_time, hw ? &hw_bp_time : &sw_bp_time);

	if (unlikely(options.verbose))
		++bp->count;

	if (unlikely(task->skip_bp)) {
		struct breakpoint *skip_bp = task->skip_bp;

		task->skip_bp = NULL;

		breakpoint_put(skip_bp);

		if (likely(skip_bp == bp)) {
			skip_breakpoint(task, bp);
			goto end;
		}

		if (unlikely(options.verbose))
			fprintf(stderr, "!!!unhandled skip breakpoint for pid=%d\n", task->pid);
	}

	if (unlikely(bp->deleted)) {
		continue_task(task, 0);
		goto end;
	}

#if HW_BREAKPOINTS > 1
	if (bp->type >= BP_HW) {
		if (unlikely(++bp->hwcnt >= (BP_REORDER_THRESHOLD << hw))) {
			struct timespec start;

			if (unlikely(options.verbose > 1))
				start_time(&start);

			reorder_hw_bp(task);

			if (unlikely(options.verbose > 1))
				set_timer(&start, &reorder_time);
		}
	}
#endif

	if (bp->on_hit && bp->on_hit(task, bp)) {
		continue_task(task, 0);
		goto end;
	}

	if (likely(bp->libsym && !task->breakpoint)) {
		struct library_symbol *libsym = bp->libsym;

		save_param_context(task);

		if (libsym->func->report_out || !options.nocpp) {
			task->breakpoint = breakpoint_insert(task, get_return_addr(task), NULL, BP_HW_SCRATCH);
			if (likely(task->breakpoint)) {
				task->libsym = libsym;
				task->breakpoint->on_hit = handle_call_after;
#if HW_BREAKPOINTS > 0
				enable_scratch_hw_bp(task, task->breakpoint);
#endif
			}
		}

		if (libsym->func->report_in) {
			struct timespec start;

			if (unlikely(options.verbose > 1))
				start_time(&start);

			libsym->func->report_in(task, libsym);

			if (unlikely(options.verbose > 1))
				set_timer(&start, &report_in_time);
		}
	}

	if (task->bp_skipped)
		task->bp_skipped = 0;
	else
		skip_breakpoint(task, bp);
end:
	breakpoint_put(bp);
	return 0;
}