1 /* Copyright (C) 2013 Red Hat, Inc.
2 This file is part of elfutils.
4 This file is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 elfutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include ELFUTILS_HEADER(dw)
24 #include ELFUTILS_HEADER(dwfl)
33 main (int argc, char *argv[])
38 (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &cnt, &dwfl);
39 assert (dwfl != NULL);
45 cu = dwfl_nextcu (dwfl, cu, &bias);
48 Dwfl_Module *mod = dwfl_cumodule (cu);
49 const char *modname = (dwfl_module_info (mod, NULL, NULL, NULL,
50 NULL, NULL, NULL, NULL)
52 const char *cuname = (dwarf_diename (cu) ?: "<unknown>");
54 printf ("mod: %s CU: [%" PRIx64 "] %s\n", modname,
55 dwarf_dieoffset (cu), cuname);
58 if (dwfl_getsrclines (cu, &lines) != 0)
59 continue; // No lines...
61 for (size_t i = 0; i < lines; i++)
63 Dwfl_Line *line = dwfl_onesrcline (cu, i);
70 const char *src = dwfl_lineinfo (line, &addr, &lineno, &colno,
74 Dwarf_Line *dw_line = dwfl_dwarf_line (line, &dw_bias);
75 assert (bias == dw_bias);
78 if (dwarf_lineaddr (dw_line, &dw_addr) != 0)
79 error (EXIT_FAILURE, 0, "dwarf_lineaddr: %s",
81 assert (addr == dw_addr + dw_bias);
83 unsigned int dw_op_index;
84 if (dwarf_lineop_index (dw_line, &dw_op_index) != 0)
85 error (EXIT_FAILURE, 0, "dwarf_lineop_index: %s",
89 if (dwarf_lineno (dw_line, &dw_lineno) != 0)
90 error (EXIT_FAILURE, 0, "dwarf_lineno: %s",
92 assert (lineno == dw_lineno);
95 if (dwarf_linecol (dw_line, &dw_colno) != 0)
96 error (EXIT_FAILURE, 0, "dwarf_lineno: %s",
98 assert (colno == dw_colno);
101 if (dwarf_linebeginstatement (dw_line, &begin) != 0)
102 error (EXIT_FAILURE, 0, "dwarf_linebeginstatement: %s",
106 if (dwarf_lineendsequence (dw_line, &end) != 0)
107 error (EXIT_FAILURE, 0, "dwarf_lineendsequence: %s",
111 if (dwarf_lineprologueend (dw_line, &pend) != 0)
112 error (EXIT_FAILURE, 0, "dwarf_lineprologueend: %s",
116 if (dwarf_lineepiloguebegin (dw_line, &ebegin) != 0)
117 error (EXIT_FAILURE, 0, "dwarf_lineepiloguebegin: %s",
121 if (dwarf_lineblock (dw_line, &block) != 0)
122 error (EXIT_FAILURE, 0, "dwarf_lineblock: %s",
126 if (dwarf_lineisa (dw_line, &isa) != 0)
127 error (EXIT_FAILURE, 0, "dwarf_lineisa: %s",
131 if (dwarf_linediscriminator (dw_line, &disc) != 0)
132 error (EXIT_FAILURE, 0, "dwarf_linediscriminator: %s",
137 Dwarf_Word dw_length;
138 dw_src = dwarf_linesrc (dw_line, &dw_mtime, &dw_length);
139 assert (strcmp (src, dw_src) == 0);
140 assert (mtime == dw_mtime);
141 assert (length == dw_length);
143 printf ("%zd %#" PRIx64 " %s:%d:%d\n"
144 " time: %#" PRIX64 ", len: %" PRIu64
145 ", idx: %d, b: %d, e: %d"
146 ", pe: %d, eb: %d, block: %d"
147 ", isa: %d, disc: %d\n",
148 i, addr, src, lineno, colno, mtime, length,
149 dw_op_index, begin, end, pend, ebegin, block, isa, disc);
151 Dwarf_Die *linecu = dwfl_linecu (line);
152 assert (cu == linecu);
154 Dwfl_Module *linemod = dwfl_linemodule (line);
155 assert (mod == linemod);