doscmd(1): Raise WARNS to 6 and silence all warnings.
[dragonfly.git] / libexec / rtld-elf / debug.c
blobb0d102e575f52ec76b62e7520430962db564b42d
1 /*-
2 * Copyright 1996-1998 John D. Polstra.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * $FreeBSD: src/libexec/rtld-elf/debug.c,v 1.2 1999/08/28 00:10:09 peter Exp $
26 * $DragonFly: src/libexec/rtld-elf/debug.c,v 1.4 2005/03/30 00:53:59 joerg Exp $
30 * Support for printing debugging messages.
33 #include <stdarg.h>
34 #include <stdio.h>
36 #include "debug.h"
37 #include "rtld.h"
39 static const char rel_header[] =
40 " symbol name r_info r_offset st_value st_size address value\n"
41 " ------------------------------------------------------------------------------\n";
42 static const char rel_format[] = " %-25s %6x %08x %08x %7d %10p %08x\n";
44 int debug = 0;
46 void
47 debug_printf(const char *format, ...)
49 if (debug) {
50 va_list ap;
51 va_start(ap, format);
53 fflush(stdout);
54 vfprintf(stderr, format, ap);
55 putc('\n', stderr);
57 va_end(ap);
61 void
62 dump_relocations (Obj_Entry *obj0)
64 Obj_Entry *obj;
66 for (obj = obj0; obj != NULL; obj = obj->next) {
67 dump_obj_relocations(obj);
71 void
72 dump_obj_relocations (Obj_Entry *obj)
75 printf("Object \"%s\", relocbase %p\n", obj->path, obj->relocbase);
77 if (obj->relsize) {
78 printf("Non-PLT Relocations: %ld\n",
79 (obj->relsize / sizeof(Elf_Rel)));
80 dump_Elf_Rel(obj, obj->rel, obj->relsize);
83 if (obj->relasize) {
84 printf("Non-PLT Relocations with Addend: %ld\n",
85 (obj->relasize / sizeof(Elf_Rela)));
86 dump_Elf_Rela(obj, obj->rela, obj->relasize);
89 if (obj->pltrelsize) {
90 printf("PLT Relocations: %ld\n",
91 (obj->pltrelsize / sizeof(Elf_Rel)));
92 dump_Elf_Rel(obj, obj->pltrel, obj->pltrelsize);
95 if (obj->pltrelasize) {
96 printf("PLT Relocations with Addend: %ld\n",
97 (obj->pltrelasize / sizeof(Elf_Rela)));
98 dump_Elf_Rela(obj, obj->pltrela, obj->pltrelasize);
102 void
103 dump_Elf_Rel (Obj_Entry *obj, const Elf_Rel *rel0, u_long relsize)
105 const Elf_Rel *rel;
106 const Elf_Rel *rellim;
107 const Elf_Sym *sym;
108 Elf_Addr *dstaddr;
110 printf("%s", rel_header);
111 rellim = (const Elf_Rel *)((const char *)rel0 + relsize);
112 for (rel = rel0; rel < rellim; rel++) {
113 dstaddr = (Elf_Addr *)(obj->relocbase + rel->r_offset);
114 sym = obj->symtab + ELF_R_SYM(rel->r_info);
115 printf(rel_format,
116 obj->strtab + sym->st_name,
117 rel->r_info, rel->r_offset,
118 sym->st_value, sym->st_size,
119 dstaddr, *dstaddr);
121 return;
124 void
125 dump_Elf_Rela (Obj_Entry *obj, const Elf_Rela *rela0, u_long relasize)
127 const Elf_Rela *rela;
128 const Elf_Rela *relalim;
129 const Elf_Sym *sym;
130 Elf_Addr *dstaddr;
132 printf("%s", rel_header);
133 relalim = (const Elf_Rela *)((const char *)rela0 + relasize);
134 for (rela = rela0; rela < relalim; rela++) {
135 dstaddr = (Elf_Addr *)(obj->relocbase + rela->r_offset);
136 sym = obj->symtab + ELF_R_SYM(rela->r_info);
137 printf(rel_format,
138 obj->strtab + sym->st_name,
139 rela->r_info, rela->r_offset,
140 sym->st_value, sym->st_size,
141 dstaddr, *dstaddr);
143 return;