2 * This file is part of ltrace.
3 * Copyright (C) 2003,2008,2009 Juan Cespedes
4 * Copyright (C) 2006 Ian Wienand
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 debug_(int level, const char *file, int line, const char *fmt, ...) {
32 if (!(options.debug & level)) {
36 vsnprintf(buf, 1024, fmt, args);
39 output_line(NULL, "DEBUG: %s:%d: %s", file, line, buf);
40 fflush(options.output);
44 * The following section provides a way to print things, like hex dumps,
45 * with out using buffered output. This was written by Steve Munroe of IBM.
52 #include <sys/ptrace.h>
59 unsigned long temp = (unsigned long)i;
61 for (j = 15; j >= 0; j--) {
63 c = (char)((temp & 0x0f) + '0');
65 c = (char)(c + ('a' - '9' - 1));
71 rc = write(1, text, 16);
80 rc = write(1, text, 1);
90 xwritedump(void *ptr, long addr, int len) {
92 long *tprt = (long *)ptr;
95 for (i = 0; i < len; i += 8) {
101 addr += sizeof(long);
108 xinfdump(long pid, void *ptr, int len) {
115 wrdcnt = len / sizeof(long) + 1;
116 infwords = malloc(wrdcnt * sizeof(long));
118 perror("ltrace: malloc");
123 addr = ((addr + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
125 for (i = 0; i < wrdcnt; ++i) {
126 infwords[i] = ptrace(PTRACE_PEEKTEXT, pid, (void *)addr, NULL);
127 addr += sizeof(long);
130 rc = xwritedump(infwords, (long)ptr, len);