1 /* Copyright (C) 2002, 2004 Red Hat, Inc.
2 This file is part of elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 elfutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include ELFUTILS_HEADER(dw)
31 main (int argc, char *argv[])
36 for (cnt = 1; cnt < argc; ++cnt)
38 int fd = open (argv[cnt], O_RDONLY);
40 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
43 printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1));
49 Dwarf_Off old_cuoff = 0;
54 while (dwarf_nextcu (dbg, cuoff, &cuoff, &hsize, &ao, &asz, &osz) == 0)
56 printf ("cuhl = %zu, o = %llu, asz = %hhu, osz = %hhu, ncu = %llu\n",
57 hsize, (unsigned long long int) ao,
58 asz, osz, (unsigned long long int) cuoff);
60 /* Get the DIE for the CU. */
62 if (dwarf_offdie (dbg, old_cuoff + hsize, &die) == NULL)
64 /* Something went wrong. */
65 printf ("%s: cannot get CU die\n", argv[cnt]);
73 if (dwarf_getsrclines (&die, &lb, &nlb) != 0)
75 printf ("%s: cannot get lines\n", argv[cnt]);
80 printf (" %zu lines\n", nlb);
82 for (size_t i = 0; i < nlb; ++i)
84 Dwarf_Line *l = dwarf_onesrcline (lb, i);
87 printf ("%s: cannot get individual line\n", argv[cnt]);
93 if (dwarf_lineaddr (l, &addr) != 0)
95 const char *file = dwarf_linesrc (l, NULL, NULL);
97 if (dwarf_lineno (l, &line) != 0)
100 printf ("%" PRIx64 ": %s:%d:", (uint64_t) addr,
101 file ?: "???", line);
104 if (dwarf_linecol (l, &column) != 0)
107 printf ("%d:", column);
110 if (dwarf_linebeginstatement (l, &is_stmt) != 0)
113 if (dwarf_lineendsequence (l, &end_sequence) != 0)
114 end_sequence = false;
116 if (dwarf_lineblock (l, &basic_block) != 0)
119 if (dwarf_lineprologueend (l, &prologue_end) != 0)
120 prologue_end = false;
122 if (dwarf_lineepiloguebegin (l, &epilogue_begin) != 0)
123 epilogue_begin = false;
125 printf (" is_stmt:%s, end_seq:%s, bb:%s, prologue:%s, epilogue:%s\n",
126 is_stmt ? "yes" : "no", end_sequence ? "yes" : "no",
127 basic_block ? "yes" : "no", prologue_end ? "yes" : "no",
128 epilogue_begin ? "yes" : "no");