Blame debug.c

Packit 0021fb
/*
Packit 0021fb
 * This file is part of ltrace.
Packit 0021fb
 * Copyright (C) 2012 Petr Machata, Red Hat Inc.
Packit 0021fb
 * Copyright (C) 2003,2008,2009 Juan Cespedes
Packit 0021fb
 * Copyright (C) 2006 Ian Wienand
Packit 0021fb
 *
Packit 0021fb
 * This program is free software; you can redistribute it and/or
Packit 0021fb
 * modify it under the terms of the GNU General Public License as
Packit 0021fb
 * published by the Free Software Foundation; either version 2 of the
Packit 0021fb
 * License, or (at your option) any later version.
Packit 0021fb
 *
Packit 0021fb
 * This program is distributed in the hope that it will be useful, but
Packit 0021fb
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0021fb
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 0021fb
 * General Public License for more details.
Packit 0021fb
 *
Packit 0021fb
 * You should have received a copy of the GNU General Public License
Packit 0021fb
 * along with this program; if not, write to the Free Software
Packit 0021fb
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
Packit 0021fb
 * 02110-1301 USA
Packit 0021fb
 */
Packit 0021fb
Packit 0021fb
#include <stdio.h>
Packit 0021fb
#include <stdarg.h>
Packit 0021fb
Packit 0021fb
#include "common.h"
Packit 0021fb
#include "backend.h"
Packit 0021fb
Packit 0021fb
void
Packit 0021fb
debug_(int level, const char *file, int line, const char *fmt, ...) {
Packit 0021fb
	char buf[1024];
Packit 0021fb
	va_list args;
Packit 0021fb
Packit 0021fb
	if (!(options.debug & level)) {
Packit 0021fb
		return;
Packit 0021fb
	}
Packit 0021fb
	va_start(args, fmt);
Packit 0021fb
	vsnprintf(buf, 1024, fmt, args);
Packit 0021fb
	va_end(args);
Packit 0021fb
Packit 0021fb
	output_line(NULL, "DEBUG: %s:%d: %s", file, line, buf);
Packit 0021fb
	fflush(options.output);
Packit 0021fb
}
Packit 0021fb
Packit 0021fb
static int
Packit 0021fb
xwritedump(long *ptr, arch_addr_t addr, size_t count)
Packit 0021fb
{
Packit 0021fb
	size_t i;
Packit 0021fb
	for (i = 0; i < count; ++i) {
Packit 0021fb
		if (fprintf(stderr, "%p->%0*lx\n",
Packit 0021fb
			    addr, 2 * (int)sizeof(long), ptr[i]) < 0)
Packit 0021fb
			return -1;
Packit 0021fb
		addr += sizeof(long);
Packit 0021fb
	}
Packit 0021fb
Packit 0021fb
	return 0;
Packit 0021fb
}
Packit 0021fb
Packit 0021fb
int
Packit 0021fb
xinfdump(struct process *proc, arch_addr_t addr, size_t length)
Packit 0021fb
{
Packit 0021fb
	unsigned char buf[length];
Packit 0021fb
	size_t got = umovebytes(proc, addr, buf, length);
Packit 0021fb
	if (got == (size_t)-1)
Packit 0021fb
		return -1;
Packit 0021fb
	return xwritedump((long *)buf, addr, got / sizeof(long));
Packit 0021fb
}