2 * Copyright (c) 2009 Kai Wang
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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 AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/param.h>
30 #include <capsicum_helpers.h>
46 ELFTC_VCSID("$Id: addr2line.c 3499 2016-11-25 16:06:29Z emaste $");
52 Dwarf_Unsigned call_file;
53 Dwarf_Unsigned call_line;
55 Dwarf_Signed ranges_cnt;
56 struct Func *inlined_caller;
57 STAILQ_ENTRY(Func) next;
61 RB_ENTRY(range) entry;
66 Dwarf_Signed nsrcfiles;
67 STAILQ_HEAD(, Func) funclist;
72 static struct option longopts[] = {
73 {"addresses", no_argument, NULL, 'a'},
74 {"target" , required_argument, NULL, 'b'},
75 {"demangle", no_argument, NULL, 'C'},
76 {"exe", required_argument, NULL, 'e'},
77 {"functions", no_argument, NULL, 'f'},
78 {"inlines", no_argument, NULL, 'i'},
79 {"section", required_argument, NULL, 'j'},
80 {"pretty-print", no_argument, NULL, 'p'},
81 {"basename", no_argument, NULL, 's'},
82 {"help", no_argument, NULL, 'H'},
83 {"version", no_argument, NULL, 'V'},
87 static int demangle, func, base, inlines, print_addr, pretty_print;
88 static char unknown[] = { '?', '?', '\0' };
89 static Dwarf_Addr section_base;
90 /* Need a new curlopc that stores last lopc value. */
91 static Dwarf_Unsigned curlopc = ~0ULL;
92 static RB_HEAD(cutree, range) cuhead = RB_INITIALIZER(&cuhead);
95 lopccmp(struct range *e1, struct range *e2)
97 return (e1->lopc < e2->lopc ? -1 : e1->lopc > e2->lopc);
100 RB_PROTOTYPE(cutree, range, entry, lopccmp);
101 RB_GENERATE(cutree, range, entry, lopccmp)
103 #define USAGE_MESSAGE "\
104 Usage: %s [options] hexaddress...\n\
105 Map program addresses to source file names and line numbers.\n\n\
107 -a | --addresses Display address prior to line number info.\n\
108 -b TGT | --target=TGT (Accepted but ignored).\n\
109 -e EXE | --exe=EXE Use program \"EXE\" to translate addresses.\n\
110 -f | --functions Display function names.\n\
111 -i | --inlines Display caller info for inlined functions.\n\
112 -j NAME | --section=NAME Values are offsets into section \"NAME\".\n\
113 -p | --pretty-print Display line number info and function name\n\
114 in human readable manner.\n\
115 -s | --basename Only show the base name for each file name.\n\
116 -C | --demangle Demangle C++ names.\n\
117 -H | --help Print a help message.\n\
118 -V | --version Print a version identifier and exit.\n"
123 (void) fprintf(stderr, USAGE_MESSAGE, ELFTC_GETPROGNAME());
131 fprintf(stderr, "%s (%s)\n", ELFTC_GETPROGNAME(), elftc_version());
136 * Handle DWARF 4 'offset from' DW_AT_high_pc. Although we don't
137 * fully support DWARF 4, some compilers (like FreeBSD Clang 3.5.1)
138 * generate DW_AT_high_pc as an offset from DW_AT_low_pc.
140 * "If the value of the DW_AT_high_pc is of class address, it is the
141 * relocated address of the first location past the last instruction
142 * associated with the entity; if it is of class constant, the value
143 * is an unsigned integer offset which when added to the low PC gives
144 * the address of the first location past the last instruction
145 * associated with the entity."
147 * DWARF4 spec, section 2.17.2.
150 handle_high_pc(Dwarf_Die die, Dwarf_Unsigned lopc, Dwarf_Unsigned *hipc)
157 ret = dwarf_attr(die, DW_AT_high_pc, &at, &de);
158 if (ret == DW_DLV_ERROR) {
159 warnx("dwarf_attr failed: %s", dwarf_errmsg(de));
162 ret = dwarf_whatform(at, &form, &de);
163 if (ret == DW_DLV_ERROR) {
164 warnx("dwarf_whatform failed: %s", dwarf_errmsg(de));
167 if (dwarf_get_form_class(2, 0, 0, form) == DW_FORM_CLASS_CONSTANT)
174 search_func(struct range *range, Dwarf_Unsigned addr)
177 Dwarf_Unsigned lopc, hipc, addr_base;
182 STAILQ_FOREACH(f, &range->funclist, next) {
183 if (f->ranges != NULL) {
185 for (i = 0; i < f->ranges_cnt; i++) {
186 if (f->ranges[i].dwr_type == DW_RANGES_END)
188 if (f->ranges[i].dwr_type ==
189 DW_RANGES_ADDRESS_SELECTION) {
190 addr_base = f->ranges[i].dwr_addr2;
194 /* DW_RANGES_ENTRY */
195 lopc = f->ranges[i].dwr_addr1 + addr_base;
196 hipc = f->ranges[i].dwr_addr2 + addr_base;
197 if (addr >= lopc && addr < hipc) {
208 } else if (addr >= f->lopc && addr < f->hipc) {
210 (f->lopc >= f0->lopc && f->hipc <= f0->hipc))
219 collect_func(Dwarf_Debug dbg, Dwarf_Die die, struct Func *parent,
222 Dwarf_Die ret_die, abst_die, spec_die;
225 Dwarf_Unsigned lopc, hipc, ranges_off;
226 Dwarf_Signed ranges_cnt;
228 Dwarf_Attribute abst_at, spec_at;
229 Dwarf_Ranges *ranges;
230 const char *funcname;
232 int found_ranges, ret;
235 abst_die = spec_die = NULL;
237 if (dwarf_tag(die, &tag, &de)) {
238 warnx("dwarf_tag: %s", dwarf_errmsg(de));
241 if (tag == DW_TAG_subprogram || tag == DW_TAG_entry_point ||
242 tag == DW_TAG_inlined_subroutine || tag == DW_TAG_label) {
244 * Function address range can be specified by either
245 * a DW_AT_ranges attribute which points to a range list or
246 * by a pair of DW_AT_low_pc and DW_AT_high_pc attributes.
251 if (dwarf_attrval_unsigned(die, DW_AT_ranges, &ranges_off,
253 dwarf_get_ranges(dbg, (Dwarf_Off) ranges_off, &ranges,
254 &ranges_cnt, NULL, &de) == DW_DLV_OK) {
255 if (ranges != NULL && ranges_cnt > 0) {
262 * Ranges pointer not found. Search for DW_AT_low_pc, and
263 * DW_AT_high_pc iff die is not a label. Labels doesn't have
265 if (tag == DW_TAG_label) {
266 if (dwarf_attrval_unsigned(die, DW_AT_low_pc, &lopc,
270 if (dwarf_attrval_unsigned(die, DW_AT_low_pc, &lopc,
271 &de) || dwarf_attrval_unsigned(die, DW_AT_high_pc,
274 if (handle_high_pc(die, lopc, &hipc) != DW_DLV_OK)
280 * Most common case the function name is stored in DW_AT_name
283 if (dwarf_attrval_string(die, DW_AT_name, &funcname, &de) ==
288 * For inlined function, the actual name is probably in the DIE
289 * referenced by DW_AT_abstract_origin. (if present)
291 if (dwarf_attr(die, DW_AT_abstract_origin, &abst_at, &de) ==
293 dwarf_global_formref(abst_at, &ref, &de) == DW_DLV_OK &&
294 dwarf_offdie(dbg, ref, &abst_die, &de) == DW_DLV_OK &&
295 dwarf_attrval_string(abst_die, DW_AT_name, &funcname,
300 * If DW_AT_name is not present, but DW_AT_specification is
301 * present, then probably the actual name is in the DIE
302 * referenced by DW_AT_specification.
304 if (dwarf_attr(die, DW_AT_specification, &spec_at, &de) ==
306 dwarf_global_formref(spec_at, &ref, &de) == DW_DLV_OK &&
307 dwarf_offdie(dbg, ref, &spec_die, &de) == DW_DLV_OK &&
308 dwarf_attrval_string(spec_die, DW_AT_name, &funcname,
312 /* Skip if no name associated with this DIE. */
316 if ((f = calloc(1, sizeof(*f))) == NULL)
317 err(EXIT_FAILURE, "calloc");
318 if ((f->name = strdup(funcname)) == NULL)
319 err(EXIT_FAILURE, "strdup");
322 f->ranges_cnt = ranges_cnt;
327 if (tag == DW_TAG_inlined_subroutine) {
328 f->inlined_caller = parent;
329 dwarf_attrval_unsigned(die, DW_AT_call_file,
331 dwarf_attrval_unsigned(die, DW_AT_call_line,
334 STAILQ_INSERT_TAIL(&range->funclist, f, next);
339 /* Search children. */
340 ret = dwarf_child(die, &ret_die, &de);
341 if (ret == DW_DLV_ERROR)
342 warnx("dwarf_child: %s", dwarf_errmsg(de));
343 else if (ret == DW_DLV_OK) {
345 collect_func(dbg, ret_die, f, range);
347 collect_func(dbg, ret_die, parent, range);
350 /* Search sibling. */
351 ret = dwarf_siblingof(dbg, die, &ret_die, &de);
352 if (ret == DW_DLV_ERROR)
353 warnx("dwarf_siblingof: %s", dwarf_errmsg(de));
354 else if (ret == DW_DLV_OK)
355 collect_func(dbg, ret_die, parent, range);
358 if (die != range->die)
359 dwarf_dealloc(dbg, die, DW_DLA_DIE);
361 if (abst_die != NULL)
362 dwarf_dealloc(dbg, abst_die, DW_DLA_DIE);
364 if (spec_die != NULL)
365 dwarf_dealloc(dbg, spec_die, DW_DLA_DIE);
369 print_inlines(struct range *range, struct Func *f, Dwarf_Unsigned call_file,
370 Dwarf_Unsigned call_line)
372 char demangled[1024];
375 if (call_file > 0 && (Dwarf_Signed) call_file <= range->nsrcfiles)
376 file = range->srcfiles[call_file - 1];
381 printf(" (inlined by) ");
384 if (demangle && !elftc_demangle(f->name, demangled,
385 sizeof(demangled), 0)) {
387 printf("%s at ", demangled);
389 printf("%s\n", demangled);
392 printf("%s at ", f->name);
394 printf("%s\n", f->name);
397 (void) printf("%s:%ju\n", base ? basename(file) : file,
398 (uintmax_t) call_line);
400 if (f->inlined_caller != NULL)
401 print_inlines(range, f->inlined_caller, f->call_file,
405 static struct range *
406 culookup(Dwarf_Unsigned addr)
408 struct range find, *res;
411 res = RB_NFIND(cutree, &cuhead, &find);
413 if (res->lopc != addr)
414 res = RB_PREV(cutree, &cuhead, res);
415 if (res != NULL && addr >= res->lopc && addr < res->hipc)
418 res = RB_MAX(cutree, &cuhead);
419 if (res != NULL && addr >= res->lopc && addr < res->hipc)
426 * When DW_AT_ranges, DW_AT_low_pc/DW_AT_high_pc are all absent, we check the
427 * children of cu die for labels. If the address falls into one of the labels
428 * ranges(aranges), return the label DIE.
431 check_labels(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Unsigned addr,
432 struct range **range) {
434 Dwarf_Arange *aranges;
435 Dwarf_Die prev_die, ret_die;
439 Dwarf_Unsigned lopc, length;
441 struct range *labelp, **labels;
442 int i, j, label_cnt, ret;
444 prev_die = ret_die = NULL;
449 ret = dwarf_get_aranges(dbg, &aranges, &arcnt, &de);
450 if (ret != DW_DLV_OK && ret != DW_DLV_NO_ENTRY)
451 warnx("dwarf_get_aranges failed: %s", dwarf_errmsg(de));
453 /* Child of current CU. */
454 ret = dwarf_child(die, &prev_die, &de);
455 if (ret == DW_DLV_ERROR)
456 warnx("dwarf_child: %s", dwarf_errmsg(de));
460 if (dwarf_tag(prev_die, &tag, &de) != DW_DLV_OK) {
461 warnx("dwarf_tag failed: %s",
465 if (tag == DW_TAG_label) {
466 if (dwarf_attrval_unsigned(prev_die, DW_AT_low_pc,
467 &lopc, &de) == DW_DLV_OK)
471 if (dwarf_siblingof(dbg, prev_die, &ret_die, &de) != DW_DLV_OK)
474 if (prev_die != NULL)
475 dwarf_dealloc(dbg, prev_die, DW_DLA_DIE);
480 return (DW_DLV_NO_ENTRY);
482 /* Allocate space for labels. */
483 if ((labels = calloc(label_cnt, sizeof(struct range *))) == NULL)
484 err(EXIT_FAILURE, "calloc");
486 /* Add labels to list. */
487 ret = dwarf_child(die, &prev_die, &de);
488 if (ret == DW_DLV_ERROR)
489 warnx("dwarf_child: %s", dwarf_errmsg(de));
491 if (dwarf_tag(prev_die, &tag, &de) != DW_DLV_OK) {
492 warnx("dwarf_tag failed: %s",
497 if (tag == DW_TAG_label) {
498 if (dwarf_attrval_unsigned(prev_die, DW_AT_low_pc,
499 &lopc, &de) == DW_DLV_OK) {
500 if (curlopc == lopc) {
501 for (i = 0; i < label_cnt - 1; i++) {
502 if (labels[i] != *range)
508 labelp = calloc(1, sizeof(struct range));
510 err(EXIT_FAILURE, "calloc");
512 labelp->die = prev_die;
514 STAILQ_INIT(&labelp->funclist);
515 labels[i++] = labelp;
518 if (dwarf_siblingof(dbg, prev_die, &ret_die, &de) != DW_DLV_OK)
520 if (prev_die != NULL && tag != DW_TAG_label)
521 dwarf_dealloc(dbg, prev_die, DW_DLA_DIE);
525 /* Set hipc for each label using aranges */
526 for (i = 0; i < label_cnt; i++) {
527 for (j = 0; j < arcnt; j++) {
528 if (dwarf_get_arange_info(aranges[j], &start, &length,
529 &die_off, &de) != DW_DLV_OK) {
530 warnx("dwarf_get_arange_info failed: %s",
534 if (labels[i]->lopc == (Dwarf_Unsigned)start) {
535 labels[i]->hipc = start + length;
541 /* If addr in label's range, we have found the range for this label. */
542 for (i = 0; i < label_cnt; i++) {
543 if (addr >= labels[i]->lopc && addr < labels[i]->hipc) {
545 RB_INSERT(cutree, &cuhead, (*range));
546 curlopc = (*range)->lopc;
551 for (i = 0; i < label_cnt - 1; i++) {
552 if (labels[i] != *range)
560 return (DW_DLV_NO_ENTRY);
564 * Check whether addr falls into range(s) of current CU.
565 * If so, save current CU to lookup tree.
568 check_range(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Unsigned addr,
569 struct range **range)
572 Dwarf_Unsigned addr_base, lopc, hipc;
573 Dwarf_Off ranges_off;
574 Dwarf_Signed ranges_cnt;
575 Dwarf_Ranges *ranges;
584 if (dwarf_attrval_unsigned(die, DW_AT_ranges, &ranges_off, &de) ==
586 ret = dwarf_get_ranges(dbg, ranges_off, &ranges,
587 &ranges_cnt, NULL, &de);
588 if (ret != DW_DLV_OK)
591 if (!ranges || ranges_cnt <= 0)
592 return (DW_DLV_ERROR);
594 for (i = 0; i < ranges_cnt; i++) {
595 if (ranges[i].dwr_type == DW_RANGES_END)
596 return (DW_DLV_NO_ENTRY);
598 if (ranges[i].dwr_type ==
599 DW_RANGES_ADDRESS_SELECTION) {
600 addr_base = ranges[i].dwr_addr2;
604 /* DW_RANGES_ENTRY */
605 lopc = ranges[i].dwr_addr1 + addr_base;
606 hipc = ranges[i].dwr_addr2 + addr_base;
609 return (DW_DLV_ERROR);
611 if (addr >= lopc && addr < hipc){
616 } else if (dwarf_attrval_unsigned(die, DW_AT_low_pc, &lopc, &de) ==
619 return (DW_DLV_ERROR);
620 if (dwarf_attrval_unsigned(die, DW_AT_high_pc, &hipc, &de) ==
623 * Check if the address falls into the PC
626 if (handle_high_pc(die, lopc, &hipc) != DW_DLV_OK)
627 return (DW_DLV_ERROR);
629 /* Assume ~0ULL if DW_AT_high_pc not present. */
633 if (addr >= lopc && addr < hipc) {
637 /* Addr not found above, try labels. */
638 ret = check_labels(dbg, die, addr, range);
643 if ((*range = calloc(1, sizeof(struct range))) == NULL)
644 err(EXIT_FAILURE, "calloc");
645 (*range)->lopc = lopc;
646 (*range)->hipc = hipc;
649 STAILQ_INIT(&(*range)->funclist);
650 RB_INSERT(cutree, &cuhead, *range);
654 return (DW_DLV_NO_ENTRY);
659 translate(Dwarf_Debug dbg, Elf *e, const char* addrstr)
661 Dwarf_Die die, ret_die;
665 Dwarf_Unsigned addr, lineno, plineno;
667 Dwarf_Addr lineaddr, plineaddr;
670 const char *funcname;
671 char *file, *file0, *pfile;
672 char demangled[1024];
675 addr = strtoull(addrstr, NULL, 16);
676 addr += section_base;
682 range = culookup(addr);
691 * We resume the CU scan from the last place we found a match.
692 * Because when we have 2 sequential addresses, and the second
693 * one is of the next CU, it is faster to just go to the next CU
694 * instead of starting from the beginning.
696 ret = dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL, NULL,
698 if (ret == DW_DLV_NO_ENTRY) {
699 if (curlopc == ~0ULL)
701 ret = dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL,
705 while (dwarf_siblingof(dbg, die, &ret_die, &de) == DW_DLV_OK) {
707 dwarf_dealloc(dbg, die, DW_DLA_DIE);
709 if (dwarf_tag(die, &tag, &de) != DW_DLV_OK) {
710 warnx("dwarf_tag failed: %s",
715 /* XXX: What about DW_TAG_partial_unit? */
716 if (tag == DW_TAG_compile_unit)
720 if (ret_die == NULL) {
721 warnx("could not find DW_TAG_compile_unit die");
724 ret = check_range(dbg, die, addr, &range);
725 if (ret == DW_DLV_OK)
727 if (ret == DW_DLV_ERROR)
731 dwarf_dealloc(dbg, die, DW_DLA_DIE);
736 if (ret != DW_DLV_OK || die == NULL)
740 switch (dwarf_srclines(die, &lbuf, &lcount, &de)) {
743 case DW_DLV_NO_ENTRY:
744 /* If a CU lacks debug info, just skip it. */
747 warnx("dwarf_srclines: %s", dwarf_errmsg(de));
754 for (i = 0; i < lcount; i++) {
755 if (dwarf_lineaddr(lbuf[i], &lineaddr, &de)) {
756 warnx("dwarf_lineaddr: %s", dwarf_errmsg(de));
759 if (dwarf_lineno(lbuf[i], &lineno, &de)) {
760 warnx("dwarf_lineno: %s", dwarf_errmsg(de));
763 if (dwarf_linesrc(lbuf[i], &file0, &de)) {
764 warnx("dwarf_linesrc: %s", dwarf_errmsg(de));
767 if (addr == lineaddr)
769 else if (addr < lineaddr && addr > plineaddr) {
774 plineaddr = lineaddr;
782 if (ret == DW_DLV_OK && (func || inlines) && range != NULL) {
783 if (range->srcfiles == NULL)
784 if (dwarf_srcfiles(die, &range->srcfiles,
785 &range->nsrcfiles, &de))
786 warnx("dwarf_srcfiles: %s", dwarf_errmsg(de));
787 if (STAILQ_EMPTY(&range->funclist)) {
788 collect_func(dbg, range->die, NULL, range);
791 f = search_func(range, addr);
797 if ((ec = gelf_getclass(e)) == ELFCLASSNONE) {
798 warnx("gelf_getclass failed: %s", elf_errmsg(-1));
801 if (ec == ELFCLASS32) {
803 printf("0x%08jx: ", (uintmax_t) addr);
805 printf("0x%08jx\n", (uintmax_t) addr);
808 printf("0x%016jx: ", (uintmax_t) addr);
810 printf("0x%016jx\n", (uintmax_t) addr);
815 if (funcname == NULL)
817 if (demangle && !elftc_demangle(funcname, demangled,
818 sizeof(demangled), 0)) {
820 printf("%s at ", demangled);
822 printf("%s\n", demangled);
825 printf("%s at ", funcname);
827 printf("%s\n", funcname);
831 (void) printf("%s:%ju\n", base ? basename(file) : file,
834 if (ret == DW_DLV_OK && inlines && range != NULL &&
835 range->srcfiles != NULL && f != NULL && f->inlined_caller != NULL)
836 print_inlines(range, f->inlined_caller, f->call_file,
841 find_section_base(const char *exe, Elf *e, const char *section)
851 if (gelf_getehdr(e, &eh) != &eh) {
852 warnx("gelf_getehdr failed: %s", elf_errmsg(-1));
856 if (!elf_getshstrndx(e, &shstrndx)) {
857 warnx("elf_getshstrndx failed: %s", elf_errmsg(-1));
864 while ((scn = elf_nextscn(e, scn)) != NULL) {
865 if (gelf_getshdr(scn, &sh) == NULL) {
866 warnx("gelf_getshdr failed: %s", elf_errmsg(-1));
869 if ((name = elf_strptr(e, shstrndx, sh.sh_name)) == NULL)
871 if (!strcmp(section, name)) {
872 if (eh.e_type == ET_EXEC || eh.e_type == ET_DYN) {
874 * For executables, section base is the virtual
875 * address of the specified section.
877 section_base = sh.sh_addr;
878 } else if (eh.e_type == ET_REL) {
880 * For relocatables, section base is the
881 * relative offset of the specified section
882 * to the start of the first section.
886 warnx("unknown e_type %u", eh.e_type);
892 elferr = elf_errno();
894 warnx("elf_nextscn failed: %s", elf_errmsg(elferr));
896 errx(EXIT_FAILURE, "%s: cannot find section %s", exe, section);
900 main(int argc, char **argv)
906 const char *exe, *section;
912 while ((opt = getopt_long(argc, argv, "ab:Ce:fij:psHV", longopts,
957 if ((fd = open(exe, O_RDONLY)) < 0)
958 err(EXIT_FAILURE, "%s", exe);
960 if (caph_rights_limit(fd, cap_rights_init(&rights, CAP_FSTAT,
962 errx(EXIT_FAILURE, "caph_rights_limit");
964 caph_cache_catpages();
965 if (caph_limit_stdio() < 0)
966 errx(EXIT_FAILURE, "failed to limit stdio rights");
967 if (caph_enter() < 0)
968 errx(EXIT_FAILURE, "failed to enter capability mode");
970 if (dwarf_init(fd, DW_DLC_READ, NULL, NULL, &dbg, &de))
971 errx(EXIT_FAILURE, "dwarf_init: %s", dwarf_errmsg(de));
973 if (dwarf_get_elf(dbg, &e, &de) != DW_DLV_OK)
974 errx(EXIT_FAILURE, "dwarf_get_elf: %s", dwarf_errmsg(de));
977 find_section_base(exe, e, section);
982 for (i = 0; i < argc; i++)
983 translate(dbg, e, argv[i]);
985 setvbuf(stdout, NULL, _IOLBF, 0);
986 while (fgets(line, sizeof(line), stdin) != NULL)
987 translate(dbg, e, line);
990 dwarf_finish(dbg, &de);