[ktap] [PATCH 1/2] userspace: add options to print sdt notes and symbols from DSO.

  • From: Azat Khuzhin <a3at.mail@xxxxxxxxx>
  • To: ktap@xxxxxxxxxxxxx
  • Date: Sun, 17 Nov 2013 01:10:42 +0400

Examples:
./ktap -F ./ktap # print symbols
./ktap -M ./ktap # print sdt markers

Don't available without libelf.

Signed-off-by: Azat Khuzhin <a3at.mail@xxxxxxxxx>
---
 userspace/main.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/userspace/main.c b/userspace/main.c
index 658c608..459fc97 100644
--- a/userspace/main.c
+++ b/userspace/main.c
@@ -39,6 +39,7 @@
 #include "../interpreter/kp_obj.h"
 #include "../interpreter/kp_str.h"
 #include "../interpreter/kp_tab.h"
+#include "symbol.h"
 
 
 /*******************************************************************/
@@ -348,6 +349,10 @@ static void usage(const char *msg_fmt, ...)
 "  -v             : enable verbose mode\n"
 "  -s             : simple event tracing\n"
 "  -b             : list byte codes\n"
+#ifndef NO_LIBELF
+"  -F             : list available functions from DSO\n"
+"  -M             : list available sdt notes from DSO\n"
+#endif
 "  file           : program read from script file\n"
 "  -- cmd [args]  : workload to tracing\n");
 
@@ -465,6 +470,14 @@ static const char *script_file;
 static int script_args_start;
 static int script_args_end;
 
+#ifndef NO_LIBELF
+static int print_symbol(const char *name, vaddr_t addr, void *arg)
+{
+       printf("%s (0x%lx)\n", name, addr);
+       return 0;
+}
+#endif
+
 static void parse_option(int argc, char **argv)
 {
        char pid[32] = {0};
@@ -532,6 +545,21 @@ static void parse_option(int argc, char **argv)
                case 'b':
                        dump_bytecode = 1;
                        break;
+#ifndef NO_LIBELF
+               case 'F':
+               case 'M': {
+                       const char *binary = next_arg;
+                       int type = argv[i][1] == 'F' ? FIND_SYMBOL : 
FIND_STAPSDT_NOTE;
+                       int ret = parse_dso_symbols(binary, type,
+                                       print_symbol, NULL);
+                       if (!ret || ret < 0) {
+                               fprintf(stderr, "error: no symbols in binary 
%s\n",
+                                       binary);
+                               exit(EXIT_FAILURE);
+                       }
+                       exit(EXIT_SUCCESS);
+               }
+#endif
                case 'V':
                case '?':
                case 'h':
-- 
1.8.4.rc3


Other related posts: