int main (int argc, char **argv) { char* args[3]; int res = 0; Dwfl *dwfl; Dwarf_Addr bias; if (argc != 2) fprintf(stderr, "Usage %s <file>", argv[0]); // Pretend "dwarfsrcfiles -e <file>" was given, so we can use standard // dwfl argp parser to open the file for us and get our Dwfl. Useful // in case argument is an ET_REL file (like kernel modules). libdwfl // will fix up relocations for us. args[0] = argv[0]; args[1] = "-e"; args[2] = argv[1]; argp_parse (dwfl_standard_argp (), 3, args, 0, NULL, &dwfl); Dwarf_Die *cu = NULL; while ((cu = dwfl_nextcu (dwfl, cu, &bias)) != NULL) res |= process_cu (cu); dwfl_end (dwfl); return res; }
int main (int argc, char *argv[]) { int remaining; /* Set locale. */ (void) setlocale (LC_ALL, ""); Dwfl *dwfl = NULL; (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, &dwfl); assert (dwfl != NULL); int result = 0; /* Now handle the addresses. In case none are given on the command line, read from stdin. */ if (remaining == argc) { /* We use no threads here which can interfere with handling a stream. */ (void) __fsetlocking (stdin, FSETLOCKING_BYCALLER); char *buf = NULL; size_t len = 0; while (!feof_unlocked (stdin)) { if (getline (&buf, &len, stdin) < 0) break; char *endp; uintmax_t addr = strtoumax (buf, &endp, 0); if (endp != buf) result |= handle_address (addr, dwfl); else result = 1; } free (buf); } else { do { char *endp; uintmax_t addr = strtoumax (argv[remaining], &endp, 0); if (endp != argv[remaining]) result |= handle_address (addr, dwfl); else result = 1; } while (++remaining < argc); } dwfl_end (dwfl); return result; }
int main (int argc, char *argv[]) { int remaining; /* Set locale. */ (void) setlocale (LC_ALL, ""); struct args a = { .dwfl = NULL, .cu = NULL }; (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, &a.dwfl); assert (a.dwfl != NULL); a.argv = &argv[remaining]; int result = 0; while ((a.cu = dwfl_nextcu (a.dwfl, a.cu, &a.dwbias)) != NULL) dwarf_getfuncs (a.cu, &handle_function, &a, 0); dwfl_end (a.dwfl); return result; }
int main (int argc, char *argv[]) { int cnt; Dwfl *dwfl = NULL; (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &cnt, &dwfl); assert (dwfl != NULL); Dwarf_Die *cu = NULL; Dwarf_Addr bias; do { cu = dwfl_nextcu (dwfl, cu, &bias); if (cu != NULL) { Dwfl_Module *mod = dwfl_cumodule (cu); const char *modname = (dwfl_module_info (mod, NULL, NULL, NULL, NULL, NULL, NULL, NULL) ?: "<unknown>"); const char *cuname = (dwarf_diename (cu) ?: "<unknown>"); printf ("mod: %s CU: [%" PRIx64 "] %s\n", modname, dwarf_dieoffset (cu), cuname); size_t lines; if (dwfl_getsrclines (cu, &lines) != 0) continue; // No lines... for (size_t i = 0; i < lines; i++) { Dwfl_Line *line = dwfl_onesrcline (cu, i); Dwarf_Addr addr; int lineno; int colno; Dwarf_Word mtime; Dwarf_Word length; const char *src = dwfl_lineinfo (line, &addr, &lineno, &colno, &mtime, &length); Dwarf_Addr dw_bias; Dwarf_Line *dw_line = dwfl_dwarf_line (line, &dw_bias); assert (bias == dw_bias); Dwarf_Addr dw_addr; if (dwarf_lineaddr (dw_line, &dw_addr) != 0) error (EXIT_FAILURE, 0, "dwarf_lineaddr: %s", dwarf_errmsg (-1)); assert (addr == dw_addr + dw_bias); unsigned int dw_op_index; if (dwarf_lineop_index (dw_line, &dw_op_index) != 0) error (EXIT_FAILURE, 0, "dwarf_lineop_index: %s", dwarf_errmsg (-1)); int dw_lineno; if (dwarf_lineno (dw_line, &dw_lineno) != 0) error (EXIT_FAILURE, 0, "dwarf_lineno: %s", dwarf_errmsg (-1)); assert (lineno == dw_lineno); int dw_colno; if (dwarf_linecol (dw_line, &dw_colno) != 0) error (EXIT_FAILURE, 0, "dwarf_lineno: %s", dwarf_errmsg (-1)); assert (colno == dw_colno); bool begin; if (dwarf_linebeginstatement (dw_line, &begin) != 0) error (EXIT_FAILURE, 0, "dwarf_linebeginstatement: %s", dwarf_errmsg (-1)); bool end; if (dwarf_lineendsequence (dw_line, &end) != 0) error (EXIT_FAILURE, 0, "dwarf_lineendsequence: %s", dwarf_errmsg (-1)); bool pend; if (dwarf_lineprologueend (dw_line, &pend) != 0) error (EXIT_FAILURE, 0, "dwarf_lineprologueend: %s", dwarf_errmsg (-1)); bool ebegin; if (dwarf_lineepiloguebegin (dw_line, &ebegin) != 0) error (EXIT_FAILURE, 0, "dwarf_lineepiloguebegin: %s", dwarf_errmsg (-1)); bool block; if (dwarf_lineblock (dw_line, &block) != 0) error (EXIT_FAILURE, 0, "dwarf_lineblock: %s", dwarf_errmsg (-1)); unsigned int isa; if (dwarf_lineisa (dw_line, &isa) != 0) error (EXIT_FAILURE, 0, "dwarf_lineisa: %s", dwarf_errmsg (-1)); unsigned int disc; if (dwarf_linediscriminator (dw_line, &disc) != 0) error (EXIT_FAILURE, 0, "dwarf_linediscriminator: %s", dwarf_errmsg (-1)); const char *dw_src; Dwarf_Word dw_mtime; Dwarf_Word dw_length; dw_src = dwarf_linesrc (dw_line, &dw_mtime, &dw_length); assert (strcmp (src, dw_src) == 0); assert (mtime == dw_mtime); assert (length == dw_length); printf ("%zd %#" PRIx64 " %s:%d:%d\n" " time: %#" PRIX64 ", len: %" PRIu64 ", idx: %d, b: %d, e: %d" ", pe: %d, eb: %d, block: %d" ", isa: %d, disc: %d\n", i, addr, src, lineno, colno, mtime, length, dw_op_index, begin, end, pend, ebegin, block, isa, disc); Dwarf_Die *linecu = dwfl_linecu (line); assert (cu == linecu); Dwfl_Module *linemod = dwfl_linemodule (line); assert (mod == linemod); } } } while (cu != NULL); dwfl_end (dwfl); return 0; }
int main (int argc, char *argv[]) { int remaining; int result = 0; /* We use no threads here which can interfere with handling a stream. */ (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER); /* Set locale. */ (void) setlocale (LC_ALL, ""); /* Make sure the message catalog can be found. */ (void) bindtextdomain (PACKAGE_TARNAME, LOCALEDIR); /* Initialize the message catalog. */ (void) textdomain (PACKAGE_TARNAME); /* Parse and process arguments. This includes opening the modules. */ argp_children[0].argp = dwfl_standard_argp (); argp_children[0].group = 1; Dwfl *dwfl = NULL; (void) argp_parse (&argp, argc, argv, 0, &remaining, &dwfl); assert (dwfl != NULL); /* Now handle the addresses. In case none are given on the command line, read from stdin. */ if (remaining == argc) { /* We use no threads here which can interfere with handling a stream. */ (void) __fsetlocking (stdin, FSETLOCKING_BYCALLER); char *buf = NULL; size_t len = 0; ssize_t chars; while (!feof_unlocked (stdin)) { if ((chars = getline (&buf, &len, stdin)) < 0) break; if (buf[chars - 1] == '\n') buf[chars - 1] = '\0'; result = handle_address (buf, dwfl); } free (buf); } else { do result = handle_address (argv[remaining], dwfl); while (++remaining < argc); } dwfl_end (dwfl); #ifdef USE_DEMANGLE free (demangle_buffer); #endif return result; }