Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | #include <fcntl.h> |
| 2 | #include <inttypes.h> |
| 3 | #include <libdw.h> |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <unistd.h> |
| 7 | |
| 8 | |
| 9 | int |
| 10 | main (int argc, char *argv[]) |
| 11 | { |
| 12 | for (int cnt = 1; cnt < argc; ++cnt) |
| 13 | { |
| 14 | char *fname; |
| 15 | char *file; |
| 16 | int line; |
| 17 | |
| 18 | switch (sscanf (argv[cnt], "%a[^:]:%a[^:]:%d", |
| 19 | &fname, &file, &line)) |
| 20 | { |
| 21 | default: |
| 22 | case 0: |
| 23 | case 1: |
| 24 | printf ("ignored %s\n", argv[cnt]); |
| 25 | continue; |
| 26 | case 2: |
| 27 | line = 0; |
| 28 | break; |
| 29 | case 3: |
| 30 | break; |
| 31 | } |
| 32 | |
| 33 | int fd = open (fname, O_RDONLY); |
| 34 | if (fd == -1) |
| 35 | continue; |
| 36 | |
| 37 | Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ); |
| 38 | if (dbg != NULL) |
| 39 | { |
| 40 | Dwarf_Line **lines = NULL; |
| 41 | size_t nlines = 0; |
| 42 | |
| 43 | if (dwarf_getsrc_file (dbg, file, line, 0, &lines, &nlines) == 0) |
| 44 | { |
| 45 | for (size_t inner = 0; inner < nlines; ++inner) |
| 46 | { |
| 47 | Dwarf_Addr addr; |
| 48 | if (dwarf_lineaddr (lines[inner], &addr) == 0) |
| 49 | printf ("%s -> %#" PRIxMAX "\n", |
| 50 | argv[cnt], (uintmax_t) addr); |
| 51 | } |
| 52 | |
| 53 | free (lines); |
| 54 | } |
| 55 | |
| 56 | dwarf_end (dbg); |
| 57 | } |
| 58 | |
| 59 | close (fd); |
| 60 | free (fname); |
| 61 | free (file); |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |