diff options
author | Roland McGrath <roland@redhat.com> | 2005-08-15 09:53:04 +0000 |
---|---|---|
committer | Roland McGrath <roland@redhat.com> | 2005-08-15 09:53:04 +0000 |
commit | 1ecb606f5af22838bf42b50dcc581d2b0f9191fe (patch) | |
tree | a3623aac5d687fd4e072774b384a5ced0c50e86d /tests/dwflmodtest.c | |
parent | 18e13427fa32a5464f1678be31512c0e0fec59c7 (diff) | |
download | elfutils-1ecb606f5af22838bf42b50dcc581d2b0f9191fe.tar.gz |
libdw/
2005-08-15 Roland McGrath <roland@redhat.com>
* dwarf_func_inline.c: New file.
* Makefile.am (libdw_a_SOURCES): Add it.
* libdw.h: Declare dwarf_func_inline, dwarf_func_inline_instances.
* libdw.map: Add them.
* dwarf_func_die.c: New file.
* Makefile.am (libdw_a_SOURCES): Add it.
* libdw.h: Declare dwarf_func_die.
* libdw.map: Add it. Bump version to ELFUTILS_0.114.
tests/
2005-08-15 Roland McGrath <roland@redhat.com>
* dwflmodtest.c (print_instance, print_inline): New functions.
(print_func): Call print_inline.
(options, parse_opt): Grok -i/--inlines.
Diffstat (limited to 'tests/dwflmodtest.c')
-rw-r--r-- | tests/dwflmodtest.c | 140 |
1 files changed, 117 insertions, 23 deletions
diff --git a/tests/dwflmodtest.c b/tests/dwflmodtest.c index e2b7d3cf..5155f6cb 100644 --- a/tests/dwflmodtest.c +++ b/tests/dwflmodtest.c @@ -23,44 +23,134 @@ #include <locale.h> #include <argp.h> #include <libdwfl.h> +#include <dwarf.h> +static bool show_inlines; + +struct info +{ + Dwarf_Die *cudie; + Dwarf_Addr dwbias; +}; static int -print_func (Dwarf_Func *func, void *arg) +print_instance (Dwarf_Die *instance, void *arg) { - const Dwarf_Addr dwbias = *(Dwarf_Addr *) arg; + const struct info *info = arg; - const char *file = dwarf_func_file (func); - int line = -1; - dwarf_func_line (func, &line); - const char *fct = dwarf_func_name (func); + printf (" inlined"); - printf (" %s:%d: %s:", file, line, fct); + Dwarf_Files *files; + if (dwarf_getsrcfiles (info->cudie, &files, NULL) == 0) + { + Dwarf_Attribute attr_mem; + Dwarf_Word val; + if (dwarf_formudata (dwarf_attr (instance, DW_AT_call_file, + &attr_mem), &val) == 0) + { + const char *file = dwarf_filesrc (files, val, NULL, NULL); + int lineno = 0, colno = 0; + if (dwarf_formudata (dwarf_attr (instance, DW_AT_call_line, + &attr_mem), &val) == 0) + lineno = val; + if (dwarf_formudata (dwarf_attr (instance, DW_AT_call_column, + &attr_mem), &val) == 0) + colno = val; + if (lineno == 0) + { + if (file != NULL) + printf (" from %s", file); + } + else if (colno == 0) + printf (" at %s:%u", file, lineno); + else + printf (" at %s:%u:%u", file, lineno, colno); + } + } Dwarf_Addr lo = -1, hi = -1, entry = -1; - if (dwarf_func_lowpc (func, &lo) == 0) - lo += dwbias; + if (dwarf_lowpc (instance, &lo) == 0) + lo += info->dwbias; else printf (" (lowpc => %s)", dwarf_errmsg (-1)); - if (dwarf_func_highpc (func, &hi) == 0) - hi += dwbias; + if (dwarf_highpc (instance, &hi) == 0) + hi += info->dwbias; else printf (" (highpc => %s)", dwarf_errmsg (-1)); - if (dwarf_func_entrypc (func, &entry) == 0) - entry += dwbias; - else - printf (" (entrypc => %s)", dwarf_errmsg (-1)); - if (lo != (Dwarf_Addr) -1 || hi != (Dwarf_Addr) -1 - || entry != (Dwarf_Addr) -1) - printf (" %#" PRIx64 "..%#" PRIx64 " => %#" PRIx64 "\n", - lo, hi, entry); + Dwarf_Attribute attr_mem; + Dwarf_Attribute *attr = INTUSE(dwarf_attr) (instance, DW_AT_entry_pc, + &attr_mem); + if (attr != NULL) + { + if (INTUSE(dwarf_formaddr) (attr, &entry) == 0) + entry += info->dwbias; + else + printf (" (entrypc => %s)", dwarf_errmsg (-1)); + } + + if (lo != (Dwarf_Addr) -1 || hi != (Dwarf_Addr) -1) + printf (" %#" PRIx64 "..%#" PRIx64, lo, hi); + if (entry != (Dwarf_Addr) -1) + printf (" => %#" PRIx64 "\n", entry); else puts (""); return DWARF_CB_OK; } +static void +print_inline (Dwarf_Func *func, void *arg) +{ + if (dwarf_func_inline_instances (func, &print_instance, arg) != 0) + printf (" error finding instances: %s\n", dwarf_errmsg (-1)); +} + +static int +print_func (Dwarf_Func *func, void *arg) +{ + const struct info *info = arg; + + const char *file = dwarf_func_file (func); + int line = -1; + dwarf_func_line (func, &line); + const char *fct = dwarf_func_name (func); + + printf (" %s:%d: %s:", file, line, fct); + + if (dwarf_func_inline (func)) + { + puts (" inline function"); + if (show_inlines) + print_inline (func, arg); + } + else + { + Dwarf_Addr lo = -1, hi = -1, entry = -1; + if (dwarf_func_lowpc (func, &lo) == 0) + lo += info->dwbias; + else + printf (" (lowpc => %s)", dwarf_errmsg (-1)); + if (dwarf_func_highpc (func, &hi) == 0) + hi += info->dwbias; + else + printf (" (highpc => %s)", dwarf_errmsg (-1)); + if (dwarf_func_entrypc (func, &entry) == 0) + entry += info->dwbias; + else + printf (" (entrypc => %s)", dwarf_errmsg (-1)); + + if (lo != (Dwarf_Addr) -1 || hi != (Dwarf_Addr) -1 + || entry != (Dwarf_Addr) -1) + printf (" %#" PRIx64 "..%#" PRIx64 " => %#" PRIx64 "\n", + lo, hi, entry); + else + puts (""); + } + + return DWARF_CB_OK; +} + static int print_module (Dwfl_Module *mod __attribute__ ((unused)), void **userdata __attribute__ ((unused)), @@ -80,9 +170,8 @@ print_module (Dwfl_Module *mod __attribute__ ((unused)), while (dwarf_nextcu (dw, off, &noff, &cuhl, NULL, NULL, NULL) == 0) { Dwarf_Die die_mem; - Dwarf_Die *die = dwarf_offdie (dw, off + cuhl, &die_mem); - - (void) dwarf_getfuncs (die, print_func, &bias, 0); + struct info info = { dwarf_offdie (dw, off + cuhl, &die_mem), bias }; + (void) dwarf_getfuncs (info.cudie, print_func, &info, 0); off = noff; } @@ -95,7 +184,8 @@ static bool show_functions; static const struct argp_option options[] = { - { "functions", 'f', NULL, 0, N_("Additional show function names"), 0 }, + { "functions", 'f', NULL, 0, N_("Additionally show function names"), 0 }, + { "inlines", 'i', NULL, 0, N_("Show instances of inlined functions"), 0 }, { NULL, 0, NULL, 0, NULL, 0 } }; @@ -113,6 +203,10 @@ parse_opt (int key, char *arg __attribute__ ((unused)), show_functions = true; break; + case 'i': + show_inlines = show_functions = true; + break; + default: return ARGP_ERR_UNKNOWN; } |