Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | #include <fcntl.h> |
| 2 | #include <libdw.h> |
| 3 | #include <stdio.h> |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | |
| 7 | static int |
| 8 | cb (Dwarf_Func *func, void *arg __attribute__ ((unused))) |
| 9 | { |
| 10 | const char *file = dwarf_func_file (func); |
| 11 | int line = -1; |
| 12 | dwarf_func_line (func, &line); |
| 13 | const char *fct = dwarf_func_name (func); |
| 14 | |
| 15 | printf ("%s:%d:%s\n", file, line, fct); |
| 16 | |
| 17 | return DWARF_CB_OK; |
| 18 | } |
| 19 | |
| 20 | |
| 21 | int |
| 22 | main (int argc, char *argv[]) |
| 23 | { |
| 24 | for (int i = 1; i < argc; ++i) |
| 25 | { |
| 26 | int fd = open (argv[i], O_RDONLY); |
| 27 | |
| 28 | Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ); |
| 29 | if (dbg != NULL) |
| 30 | { |
| 31 | Dwarf_Off off = 0; |
| 32 | size_t cuhl; |
| 33 | Dwarf_Off noff; |
| 34 | |
| 35 | while (dwarf_nextcu (dbg, off, &noff, &cuhl, NULL, NULL, NULL) == 0) |
| 36 | { |
| 37 | Dwarf_Die die_mem; |
| 38 | Dwarf_Die *die = dwarf_offdie (dbg, off + cuhl, &die_mem); |
| 39 | |
| 40 | (void) dwarf_getfuncs (die, cb, NULL, 0); |
| 41 | |
| 42 | off = noff; |
| 43 | } |
| 44 | |
| 45 | dwarf_end (dbg); |
| 46 | } |
| 47 | |
| 48 | close (fd); |
| 49 | } |
| 50 | } |