aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2012-04-25 13:42:07 +0200
committerPetr Machata <pmachata@redhat.com>2012-04-25 13:42:07 +0200
commitcc0e1e4b83d69441cc5f61ea87eda5458ee9fae3 (patch)
tree38378e9ba7fc871111c488c5e2bdee9dc06a2407
parentfd2641c0d27705c89d224e3205b1296110b6598c (diff)
downloadltrace-cc0e1e4b83d69441cc5f61ea87eda5458ee9fae3.tar.gz
Replace some uses of error with fprintf
error is not standard so it has no business being used in generic code. The linux-gnu back end is useful for android, and that doesn't have that interface either.
-rw-r--r--breakpoints.c1
-rw-r--r--filter.c5
-rw-r--r--handle_event.c5
-rw-r--r--libltrace.c9
-rw-r--r--ltrace-elf.c222
-rw-r--r--options.c31
-rw-r--r--proc.c15
-rw-r--r--sysdeps/linux-gnu/breakpoint.c26
-rw-r--r--sysdeps/linux-gnu/proc.c25
-rw-r--r--sysdeps/linux-gnu/trace.c1
10 files changed, 187 insertions, 153 deletions
diff --git a/breakpoints.c b/breakpoints.c
index 85d228f..2b1f304 100644
--- a/breakpoints.c
+++ b/breakpoints.c
@@ -3,7 +3,6 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
-#include <error.h>
#include <errno.h>
#ifdef __powerpc__
diff --git a/filter.c b/filter.c
index b4fa330..003010d 100644
--- a/filter.c
+++ b/filter.c
@@ -19,8 +19,9 @@
*/
#include <stdlib.h>
-#include <error.h>
#include <assert.h>
+#include <stdio.h>
+#include <string.h>
#include "filter.h"
#include "library.h"
@@ -117,7 +118,7 @@ re_match_or_error(regex_t *re, const char *name, const char *what)
char buf[200];
regerror(status, re, buf, sizeof buf);
- error(0, 0, "Error when matching %s: %s", name, buf);
+ fprintf(stderr, "Error when matching %s: %s\n", name, buf);
return 0;
}
diff --git a/handle_event.c b/handle_event.c
index 7648248..73c118a 100644
--- a/handle_event.c
+++ b/handle_event.c
@@ -3,7 +3,6 @@
#include <assert.h>
#include <errno.h>
-#include <error.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -441,8 +440,8 @@ handle_exec(Event * event) {
output_line(proc, "--- Called exec() ---");
if (process_exec(proc) < 0) {
- error(0, errno,
- "couldn't reinitialize process %d after exec", pid);
+ fprintf(stderr,
+ "couldn't reinitialize process %d after exec\n", pid);
goto untrace;
}
diff --git a/libltrace.c b/libltrace.c
index 8020c6e..92f2701 100644
--- a/libltrace.c
+++ b/libltrace.c
@@ -3,7 +3,6 @@
#include <sys/param.h>
#include <sys/wait.h>
#include <errno.h>
-#include <error.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -114,9 +113,11 @@ ltrace_init(int argc, char **argv) {
pid_t pid = execute_program(command, argv);
struct Process *proc = open_program(command, pid);
- if (proc == NULL)
- error(EXIT_FAILURE, errno,
- "couldn't open program '%s'", command);
+ if (proc == NULL) {
+ fprintf(stderr, "couldn't open program '%s': %s\n",
+ command, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
trace_set_options(proc);
continue_process(pid);
diff --git a/ltrace-elf.c b/ltrace-elf.c
index d6f13bb..f94e5fe 100644
--- a/ltrace-elf.c
+++ b/ltrace-elf.c
@@ -3,12 +3,12 @@
#include <assert.h>
#include <endian.h>
#include <errno.h>
-#include <error.h>
#include <fcntl.h>
#include <gelf.h>
#include <inttypes.h>
#include <search.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -197,17 +197,22 @@ open_elf(struct ltelf *lte, const char *filename)
lte->elf = elf_begin(lte->fd, ELF_C_READ, NULL);
#endif
- if (lte->elf == NULL || elf_kind(lte->elf) != ELF_K_ELF)
- error(EXIT_FAILURE, 0, "Can't open ELF file \"%s\"", filename);
+ if (lte->elf == NULL || elf_kind(lte->elf) != ELF_K_ELF) {
+ fprintf(stderr, "\"%s\" is not an ELF file\n", filename);
+ exit(EXIT_FAILURE);
+ }
- if (gelf_getehdr(lte->elf, &lte->ehdr) == NULL)
- error(EXIT_FAILURE, 0, "Can't read ELF header of \"%s\"",
- filename);
+ if (gelf_getehdr(lte->elf, &lte->ehdr) == NULL) {
+ fprintf(stderr, "can't read ELF header of \"%s\": %s\n",
+ filename, elf_errmsg(-1));
+ exit(EXIT_FAILURE);
+ }
- if (lte->ehdr.e_type != ET_EXEC && lte->ehdr.e_type != ET_DYN)
- error(EXIT_FAILURE, 0,
- "\"%s\" is not an ELF executable nor shared library",
- filename);
+ if (lte->ehdr.e_type != ET_EXEC && lte->ehdr.e_type != ET_DYN) {
+ fprintf(stderr, "\"%s\" is neither an ELF executable"
+ " nor a shared library\n", filename);
+ exit(EXIT_FAILURE);
+ }
if ((lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS
|| lte->ehdr.e_machine != LT_ELF_MACHINE)
@@ -219,13 +224,52 @@ open_elf(struct ltelf *lte, const char *filename)
&& (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS3
|| lte->ehdr.e_machine != LT_ELF_MACHINE3)
#endif
- )
- error(EXIT_FAILURE, 0,
- "\"%s\" is ELF from incompatible architecture", filename);
+ ) {
+ fprintf(stderr,
+ "\"%s\" is ELF from incompatible architecture\n",
+ filename);
+ exit(EXIT_FAILURE);
+ }
return 0;
}
+static void
+read_symbol_table(struct ltelf *lte, const char *filename,
+ Elf_Scn *scn, GElf_Shdr *shdr, const char *name,
+ Elf_Data **datap, size_t *countp, const char **strsp)
+{
+ *datap = elf_getdata(scn, NULL);
+ *countp = shdr->sh_size / shdr->sh_entsize;
+ if ((*datap == NULL || elf_getdata(scn, *datap) != NULL)
+ && options.static_filter != NULL) {
+ fprintf(stderr, "Couldn't get data of section"
+ " %s from \"%s\": %s\n",
+ name, filename, elf_errmsg(-1));
+ exit(EXIT_FAILURE);
+ }
+
+ scn = elf_getscn(lte->elf, shdr->sh_link);
+ GElf_Shdr shdr2;
+ if (scn == NULL || gelf_getshdr(scn, &shdr2) == NULL) {
+ fprintf(stderr, "Couldn't get header of section"
+ " #%d from \"%s\": %s\n",
+ shdr2.sh_link, filename, elf_errmsg(-1));
+ exit(EXIT_FAILURE);
+ }
+
+ Elf_Data *data = elf_getdata(scn, NULL);
+ if (data == NULL || elf_getdata(scn, data) != NULL
+ || shdr2.sh_size != data->d_size || data->d_off) {
+ fprintf(stderr, "Couldn't get data of section"
+ " #%d from \"%s\": %s\n",
+ shdr2.sh_link, filename, elf_errmsg(-1));
+ exit(EXIT_FAILURE);
+ }
+
+ *strsp = data->d_buf;
+}
+
static int
do_init_elf(struct ltelf *lte, const char *filename, GElf_Addr bias)
{
@@ -265,68 +309,29 @@ do_init_elf(struct ltelf *lte, const char *filename, GElf_Addr bias)
const char *name;
scn = elf_getscn(lte->elf, i);
- if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get section header from \"%s\"",
- filename);
+ if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) {
+ fprintf(stderr, "Couldn't get section #%d from"
+ " \"%s\": %s\n", i, filename, elf_errmsg(-1));
+ exit(EXIT_FAILURE);
+ }
name = elf_strptr(lte->elf, lte->ehdr.e_shstrndx, shdr.sh_name);
- if (name == NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get section header from \"%s\"",
- filename);
+ if (name == NULL) {
+ fprintf(stderr, "Couldn't get name of section #%d from"
+ " \"%s\": %s\n", i, filename, elf_errmsg(-1));
+ exit(EXIT_FAILURE);
+ }
if (shdr.sh_type == SHT_SYMTAB) {
- Elf_Data *data;
+ read_symbol_table(lte, filename,
+ scn, &shdr, name, &lte->symtab,
+ &lte->symtab_count, &lte->strtab);
- lte->symtab = elf_getdata(scn, NULL);
- lte->symtab_count = shdr.sh_size / shdr.sh_entsize;
- if ((lte->symtab == NULL
- || elf_getdata(scn, lte->symtab) != NULL)
- && options.static_filter != NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get .symtab data from \"%s\"",
- filename);
-
- scn = elf_getscn(lte->elf, shdr.sh_link);
- if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get section header from \"%s\"",
- filename);
-
- data = elf_getdata(scn, NULL);
- if (data == NULL || elf_getdata(scn, data) != NULL
- || shdr.sh_size != data->d_size || data->d_off)
- error(EXIT_FAILURE, 0,
- "Couldn't get .strtab data from \"%s\"",
- filename);
-
- lte->strtab = data->d_buf;
} else if (shdr.sh_type == SHT_DYNSYM) {
- Elf_Data *data;
-
- lte->dynsym = elf_getdata(scn, NULL);
- lte->dynsym_count = shdr.sh_size / shdr.sh_entsize;
- if (lte->dynsym == NULL
- || elf_getdata(scn, lte->dynsym) != NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get .dynsym data from \"%s\"",
- filename);
-
- scn = elf_getscn(lte->elf, shdr.sh_link);
- if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get section header from \"%s\"",
- filename);
+ read_symbol_table(lte, filename,
+ scn, &shdr, name, &lte->dynsym,
+ &lte->dynsym_count, &lte->dynstr);
- data = elf_getdata(scn, NULL);
- if (data == NULL || elf_getdata(scn, data) != NULL
- || shdr.sh_size != data->d_size || data->d_off)
- error(EXIT_FAILURE, 0,
- "Couldn't get .dynstr data from \"%s\"",
- filename);
-
- lte->dynstr = data->d_buf;
} else if (shdr.sh_type == SHT_DYNAMIC) {
Elf_Data *data;
size_t j;
@@ -335,18 +340,22 @@ do_init_elf(struct ltelf *lte, const char *filename, GElf_Addr bias)
lte->dyn_sz = shdr.sh_size;
data = elf_getdata(scn, NULL);
- if (data == NULL || elf_getdata(scn, data) != NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get .dynamic data from \"%s\"",
- filename);
+ if (data == NULL || elf_getdata(scn, data) != NULL) {
+ fprintf(stderr, "Couldn't get .dynamic data"
+ " from \"%s\": %s\n",
+ filename, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
for (j = 0; j < shdr.sh_size / shdr.sh_entsize; ++j) {
GElf_Dyn dyn;
- if (gelf_getdyn(data, j, &dyn) == NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get .dynamic data from \"%s\"",
- filename);
+ if (gelf_getdyn(data, j, &dyn) == NULL) {
+ fprintf(stderr, "Couldn't get .dynamic"
+ " data from \"%s\": %s\n",
+ filename, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
if (dyn.d_tag == DT_JMPREL)
relplt_addr = dyn.d_un.d_ptr;
else if (dyn.d_tag == DT_PLTRELSZ)
@@ -375,9 +384,11 @@ do_init_elf(struct ltelf *lte, const char *filename, GElf_Addr bias)
}
}
- if (lte->dynsym == NULL || lte->dynstr == NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't find .dynsym or .dynstr in \"%s\"", filename);
+ if (lte->dynsym == NULL || lte->dynstr == NULL) {
+ fprintf(stderr, "Couldn't find .dynsym or .dynstr in \"%s\"\n",
+ filename);
+ exit(EXIT_FAILURE);
+ }
if (!relplt_addr || !lte->plt_addr) {
debug(1, "%s has no PLT relocations", filename);
@@ -394,28 +405,34 @@ do_init_elf(struct ltelf *lte, const char *filename, GElf_Addr bias)
GElf_Shdr shdr;
scn = elf_getscn(lte->elf, i);
- if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get section header from \"%s\"",
- filename);
+ if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL) {
+ fprintf(stderr, "Couldn't get section header"
+ " from \"%s\": %s\n",
+ filename, elf_errmsg(-1));
+ exit(EXIT_FAILURE);
+ }
if (shdr.sh_addr == relplt_addr
&& shdr.sh_size == lte->relplt_size) {
lte->relplt = elf_getdata(scn, NULL);
lte->relplt_count =
shdr.sh_size / shdr.sh_entsize;
if (lte->relplt == NULL
- || elf_getdata(scn, lte->relplt) != NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get .rel*.plt data from \"%s\"",
- filename);
+ || elf_getdata(scn, lte->relplt) != NULL) {
+ fprintf(stderr, "Couldn't get .rel*.plt"
+ " data from \"%s\": %s\n",
+ filename, elf_errmsg(-1));
+ exit(EXIT_FAILURE);
+ }
break;
}
}
- if (i == lte->ehdr.e_shnum)
- error(EXIT_FAILURE, 0,
- "Couldn't find .rel*.plt section in \"%s\"",
- filename);
+ if (i == lte->ehdr.e_shnum) {
+ fprintf(stderr,
+ "Couldn't find .rel*.plt section in \"%s\"\n",
+ filename);
+ exit(EXIT_FAILURE);
+ }
debug(1, "%s %zd PLT relocations", filename, lte->relplt_count);
}
@@ -458,10 +475,12 @@ populate_plt(struct Process *proc, const char *filename,
if (ret == NULL
|| ELF64_R_SYM(rela.r_info) >= lte->dynsym_count
|| gelf_getsym(lte->dynsym, ELF64_R_SYM(rela.r_info),
- &sym) == NULL)
- error(EXIT_FAILURE, 0,
- "Couldn't get relocation from \"%s\"",
- filename);
+ &sym) == NULL) {
+ fprintf(stderr,
+ "Couldn't get relocation from \"%s\": %s\n",
+ filename, elf_errmsg(-1));
+ exit(EXIT_FAILURE);
+ }
char const *name = lte->dynstr + sym.st_name;
@@ -517,7 +536,8 @@ populate_this_symtab(struct Process *proc, const char *filename,
size_t num_symbols = 0;
struct unique_symbol *symbols = malloc(sizeof(*symbols) * size);
if (symbols == NULL) {
- error(0, errno, "couldn't insert symbols for -x");
+ fprintf(stderr, "couldn't insert symbols for -x: %s\n",
+ strerror(errno));
return -1;
}
@@ -538,8 +558,9 @@ populate_this_symtab(struct Process *proc, const char *filename,
GElf_Sym sym;
if (gelf_getsym(symtab, i, &sym) == NULL) {
fail:
- error(0, errno, "couldn't get symbol #%zd from %s: %s",
- i, filename, elf_errmsg(-1));
+ fprintf(stderr,
+ "couldn't get symbol #%zd from %s: %s\n",
+ i, filename, elf_errmsg(-1));
continue;
}
@@ -563,8 +584,9 @@ populate_this_symtab(struct Process *proc, const char *filename,
if (secflags[sym.st_shndx] & SHF_EXECINSTR) {
naddr = addr;
} else if (arch_translate_address(proc, addr, &naddr) < 0) {
- error(0, errno, "couldn't translate address of %s@%s",
- name, lib->soname);
+ fprintf(stderr,
+ "couldn't translate address of %s@%s: %s\n",
+ name, lib->soname, strerror(errno));
continue;
}
diff --git a/options.c b/options.c
index 36fad5b..d5edc1a 100644
--- a/options.c
+++ b/options.c
@@ -3,10 +3,10 @@
#include <sys/ioctl.h>
#include <assert.h>
#include <errno.h>
-#include <error.h>
#include <fcntl.h>
#include <getopt.h>
#include <limits.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -183,7 +183,8 @@ add_filter_rule(struct filter *filt, const char *expr,
struct filter_lib_matcher *matcher = malloc(sizeof(*matcher));
if (rule == NULL || matcher == NULL) {
- error(0, errno, "rule near '%s' will be ignored", expr);
+ fprintf(stderr, "rule near '%s' will be ignored: %s\n",
+ expr, strerror(errno));
fail:
free(rule);
free(matcher);
@@ -202,8 +203,8 @@ add_filter_rule(struct filter *filt, const char *expr,
if (status != 0) {
char buf[100];
regerror(status, &symbol_re, buf, sizeof buf);
- error(0, 0, "rule near '%s' will be ignored: %s",
- expr, buf);
+ fprintf(stderr, "rule near '%s' will be ignored: %s\n",
+ expr, buf);
goto fail;
}
}
@@ -223,8 +224,8 @@ add_filter_rule(struct filter *filt, const char *expr,
if (status != 0) {
char buf[100];
regerror(status, &lib_re, buf, sizeof buf);
- error(0, 0, "rule near '%s' will be ignored: %s",
- expr, buf);
+ fprintf(stderr, "rule near '%s' will be ignored: %s\n",
+ expr, buf);
regfree(&symbol_re);
goto fail;
@@ -310,8 +311,8 @@ parse_filter(struct filter *filt, char *expr)
/* /XXX@YYY/ is the same as
* /XXX/@/YYY/. */
if (libend[0] != '/')
- error(0, 0, "unmatched '/'"
- " in symbol name");
+ fprintf(stderr, "unmatched '/'"
+ " in symbol name\n");
else
*libend-- = 0;
}
@@ -326,7 +327,8 @@ parse_filter(struct filter *filt, char *expr)
if (libname != libend && libname[0] == '/')
++libname;
else
- error(0, 0, "unmatched '/' in library name");
+ fprintf(stderr, "unmatched '/'"
+ " in library name\n");
}
if (*symname == 0) /* /@AA/ */
@@ -347,7 +349,8 @@ recursive_parse_chain(char *expr)
{
struct filter *filt = malloc(sizeof(*filt));
if (filt == NULL) {
- error(0, errno, "(part of) filter will be ignored: '%s'", expr);
+ fprintf(stderr, "(part of) filter will be ignored: '%s': %s\n",
+ expr, strerror(errno));
return NULL;
}
@@ -366,7 +369,8 @@ parse_filter_chain(const char *expr, struct filter **retp)
{
char *str = strdup(expr);
if (str == NULL) {
- error(0, errno, "filter '%s' will be ignored", expr);
+ fprintf(stderr, "filter '%s' will be ignored: %s\n",
+ expr, strerror(errno));
return;
}
/* Support initial '!' for backward compatibility. */
@@ -496,8 +500,9 @@ process_options(int argc, char **argv)
case 'o':
options.output = fopen(optarg, "w");
if (!options.output) {
- error(0, errno,
- "can't open %s for writing", optarg);
+ fprintf(stderr,
+ "can't open %s for writing: %s\n",
+ optarg, strerror(errno));
exit(1);
}
setvbuf(options.output, (char *)NULL, _IOLBF, 0);
diff --git a/proc.c b/proc.c
index 627e93c..51833fe 100644
--- a/proc.c
+++ b/proc.c
@@ -11,7 +11,6 @@
#include <errno.h>
#include <stdlib.h>
#include <assert.h>
-#include <error.h>
#include "common.h"
#include "breakpoint.h"
@@ -126,7 +125,8 @@ process_init(struct Process *proc, const char *filename, pid_t pid)
{
if (process_bare_init(proc, filename, pid, 0) < 0) {
fail:
- error(0, errno, "init process %d", pid);
+ fprintf(stderr, "failed to initialize process %d: %s\n",
+ pid, strerror(errno));
return -1;
}
@@ -245,7 +245,8 @@ process_clone(struct Process *retp, struct Process *proc, pid_t pid)
{
if (process_bare_init(retp, proc->filename, pid, 0) < 0) {
fail:
- error(0, errno, "clone process %d->%d", proc->pid, pid);
+ fprintf(stderr, "failed to clone process %d->%d : %s\n",
+ proc->pid, pid, strerror(errno));
return -1;
}
@@ -644,7 +645,8 @@ proc_add_library(struct Process *proc, struct library *lib)
struct library_symbol *libsym = NULL;
while ((libsym = library_each_symbol(lib, libsym, breakpoint_for_symbol,
proc)) != NULL)
- error(0, errno, "insert breakpoint for %s", libsym->name);
+ fprintf(stderr, "couldn't insert breakpoint for %s to %d: %s",
+ libsym->name, proc->pid, strerror(errno));
}
int
@@ -709,8 +711,9 @@ proc_add_breakpoint(struct Process *proc, struct breakpoint *bp)
assert(dict_find_entry(proc->breakpoints, bp->addr) == NULL);
if (dict_enter(proc->breakpoints, bp->addr, bp) < 0) {
- error(0, errno, "couldn't enter breakpoint %s@%p to dictionary",
- breakpoint_name(bp), bp->addr);
+ fprintf(stderr,
+ "couldn't enter breakpoint %s@%p to dictionary: %s\n",
+ breakpoint_name(bp), bp->addr, strerror(errno));
return -1;
}
diff --git a/sysdeps/linux-gnu/breakpoint.c b/sysdeps/linux-gnu/breakpoint.c
index 5f60bec..e05e730 100644
--- a/sysdeps/linux-gnu/breakpoint.c
+++ b/sysdeps/linux-gnu/breakpoint.c
@@ -2,8 +2,8 @@
#include <sys/ptrace.h>
#include <errno.h>
-#include <error.h>
#include <string.h>
+#include <stdio.h>
#include "common.h"
#include "sysdep.h"
@@ -28,9 +28,10 @@ arch_enable_breakpoint(pid_t pid, struct breakpoint *sbp)
long a = ptrace(PTRACE_PEEKTEXT, pid,
sbp->addr + i * sizeof(long), 0);
if (a == -1 && errno) {
- error(0, errno,
- "enable_breakpoint pid=%d, addr=%p, symbol=%s",
- pid, sbp->addr, breakpoint_name(sbp));
+ fprintf(stderr, "enable_breakpoint"
+ " pid=%d, addr=%p, symbol=%s: %s\n",
+ pid, sbp->addr, breakpoint_name(sbp),
+ strerror(errno));
return;
}
for (j = 0;
@@ -44,9 +45,10 @@ arch_enable_breakpoint(pid_t pid, struct breakpoint *sbp)
a = ptrace(PTRACE_POKETEXT, pid,
sbp->addr + i * sizeof(long), a);
if (a == -1) {
- error(0, errno,
- "enable_breakpoint pid=%d, addr=%p, symbol=%s",
- pid, sbp->addr, breakpoint_name(sbp));
+ fprintf(stderr, "enable_breakpoint"
+ " pid=%d, addr=%p, symbol=%s: %s\n",
+ pid, sbp->addr, breakpoint_name(sbp),
+ strerror(errno));
return;
}
}
@@ -77,8 +79,9 @@ arch_disable_breakpoint(pid_t pid, const struct breakpoint *sbp)
long a = ptrace(PTRACE_PEEKTEXT, pid,
sbp->addr + i * sizeof(long), 0);
if (a == -1 && errno) {
- error(0, errno, "disable_breakpoint pid=%d, addr=%p",
- pid, sbp->addr);
+ fprintf(stderr,
+ "disable_breakpoint pid=%d, addr=%p: %s\n",
+ pid, sbp->addr, strerror(errno));
return;
}
for (j = 0;
@@ -91,8 +94,9 @@ arch_disable_breakpoint(pid_t pid, const struct breakpoint *sbp)
a = ptrace(PTRACE_POKETEXT, pid,
sbp->addr + i * sizeof(long), a);
if (a == -1 && errno) {
- error(0, errno, "disable_breakpoint pid=%d, addr=%p",
- pid, sbp->addr);
+ fprintf(stderr,
+ "disable_breakpoint pid=%d, addr=%p: %s\n",
+ pid, sbp->addr, strerror(errno));
return;
}
}
diff --git a/sysdeps/linux-gnu/proc.c b/sysdeps/linux-gnu/proc.c
index e1e3c36..b3b41c9 100644
--- a/sysdeps/linux-gnu/proc.c
+++ b/sysdeps/linux-gnu/proc.c
@@ -1,20 +1,19 @@
#define _GNU_SOURCE /* For getline. */
#include "config.h"
-#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <link.h>
+#include <signal.h>
#include <stdio.h>
#include <string.h>
-#include <signal.h>
#include <unistd.h>
-#include <dirent.h>
-#include <ctype.h>
-#include <errno.h>
-#include <sys/syscall.h>
-#include <error.h>
#include "common.h"
#include "breakpoint.h"
@@ -182,7 +181,8 @@ process_status(pid_t pid)
each_line_starting(file, "State:\t", &process_status_cb, &ret);
fclose(file);
if (ret == ps_invalid)
- error(0, errno, "process_status %d", pid);
+ fprintf(stderr, "process_status %d: %s", pid,
+ strerror(errno));
} else
/* If the file is not present, the process presumably
* exited already. */
@@ -466,8 +466,8 @@ crawl_linkmap(struct Process *proc, struct lt_r_debug_64 *dbg)
fail:
if (lib != NULL)
library_destroy(lib);
- error(0, errno, "Couldn't load ELF object %s\n",
- lib_name);
+ fprintf(stderr, "Couldn't load ELF object %s: %s\n",
+ lib_name, strerror(errno));
continue;
}
library_init(lib, LT_LIBTYPE_DSO);
@@ -539,7 +539,8 @@ linkmap_init(struct Process *proc, target_address_t dyn_addr)
struct debug_struct *debug = malloc(sizeof(*debug));
if (debug == NULL) {
- error(0, errno, "couldn't allocate debug struct");
+ fprintf(stderr, "couldn't allocate debug struct: %s\n",
+ strerror(errno));
fail:
proc->debug = NULL;
free(debug);
@@ -612,7 +613,7 @@ process_get_entry(struct Process *proc,
int fd = open(fn, O_RDONLY);
if (fd == -1) {
fail:
- error(0, errno, "couldn't read %s", fn);
+ fprintf(stderr, "couldn't read %s: %s", fn, strerror(errno));
done:
if (fd != -1)
close(fd);
diff --git a/sysdeps/linux-gnu/trace.c b/sysdeps/linux-gnu/trace.c
index 5ad82cd..d5c5262 100644
--- a/sysdeps/linux-gnu/trace.c
+++ b/sysdeps/linux-gnu/trace.c
@@ -5,7 +5,6 @@
#include <sys/wait.h>
#include <assert.h>
#include <errno.h>
-#include <error.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>