Blame SOURCES/bcc-0.8.0-tools-fix-some-python3-bytes-vs-strings-issues-2205.patch

5d1f51
From f03beca4d6e6bc3fa7089416d752387bd26904dc Mon Sep 17 00:00:00 2001
5d1f51
From: Jerome Marchand <jmarchan@redhat.com>
5d1f51
Date: Fri, 15 Feb 2019 17:35:37 +0100
5d1f51
Subject: [PATCH] tools: fix some python3 bytes vs strings issues (#2205)
5d1f51
5d1f51
It fixes the following errors:
5d1f51
5d1f51
$ execsnoop.py -q
5d1f51
PCOMM            PID    PPID   RET ARGS
5d1f51
Traceback (most recent call last):
5d1f51
  File "_ctypes/callbacks.c", line 234, in 'calling callback function'
5d1f51
  File "/usr/lib/python3.6/site-packages/bcc/table.py", line 572, in raw_cb_
5d1f51
    callback(cpu, data, size)
5d1f51
  File "tools/execsnoop.py", line 229, in print_event
5d1f51
    for arg in argv[event.pid]
5d1f51
  File "tools/execsnoop.py", line 229, in <listcomp>
5d1f51
    for arg in argv[event.pid]
5d1f51
TypeError: a bytes-like object is required, not 'str'
5d1f51
5d1f51
$ offcputime.py -K -f 5
5d1f51
Traceback (most recent call last):
5d1f51
  File "./tools/offcputime.py", line 298, in <module>
5d1f51
    print("%s %d" % (";".join(line), v.value))
5d1f51
TypeError: sequence item 1: expected str instance, bytes found
5d1f51
5d1f51
$ offwaketime.py -f 5
5d1f51
Traceback (most recent call last):
5d1f51
  File "./tools/offwaketime.py", line 350, in <module>
5d1f51
    print("%s %d" % (";".join(line), v.value))
5d1f51
TypeError: sequence item 1: expected str instance, bytes found
5d1f51
---
5d1f51
 tools/execsnoop.py   | 2 +-
5d1f51
 tools/offcputime.py  | 6 ++++--
5d1f51
 tools/offwaketime.py | 8 ++++----
5d1f51
 3 files changed, 9 insertions(+), 7 deletions(-)
5d1f51
5d1f51
diff --git a/tools/execsnoop.py b/tools/execsnoop.py
5d1f51
index c4021165..1ce83e07 100755
5d1f51
--- a/tools/execsnoop.py
5d1f51
+++ b/tools/execsnoop.py
5d1f51
@@ -210,7 +210,7 @@ argv = defaultdict(list)
5d1f51
             skip = True
5d1f51
         if args.quote:
5d1f51
             argv[event.pid] = [
5d1f51
-                "\"" + arg.replace("\"", "\\\"") + "\""
5d1f51
+                b"\"" + arg.replace(b"\"", b"\\\"") + b"\""
5d1f51
                 for arg in argv[event.pid]
5d1f51
             ]
5d1f51
 
5d1f51
diff --git a/tools/offcputime.py b/tools/offcputime.py
5d1f51
index d84ae529..ac3b7281 100755
5d1f51
--- a/tools/offcputime.py
5d1f51
+++ b/tools/offcputime.py
5d1f51
@@ -288,13 +288,15 @@ stack_traces = b.get_table("stack_traces")
5d1f51
             if stack_id_err(k.user_stack_id):
5d1f51
                 line.append("[Missed User Stack]")
5d1f51
             else:
5d1f51
-                line.extend([b.sym(addr, k.tgid) for addr in reversed(user_stack)])
5d1f51
+                line.extend([b.sym(addr, k.tgid).decode('utf-8', 'replace')
5d1f51
+                    for addr in reversed(user_stack)])
5d1f51
         if not args.user_stacks_only:
5d1f51
             line.extend(["-"] if (need_delimiter and k.kernel_stack_id >= 0 and k.user_stack_id >= 0) else [])
5d1f51
             if stack_id_err(k.kernel_stack_id):
5d1f51
                 line.append("[Missed Kernel Stack]")
5d1f51
             else:
5d1f51
-                line.extend([b.ksym(addr) for addr in reversed(kernel_stack)])
5d1f51
+                line.extend([b.ksym(addr).decode('utf-8', 'replace')
5d1f51
+                    for addr in reversed(kernel_stack)])
5d1f51
         print("%s %d" % (";".join(line), v.value))
5d1f51
     else:
5d1f51
         # print default multi-line stack output
5d1f51
diff --git a/tools/offwaketime.py b/tools/offwaketime.py
5d1f51
index 38a9ff25..4a1cebab 100755
5d1f51
--- a/tools/offwaketime.py
5d1f51
+++ b/tools/offwaketime.py
5d1f51
@@ -323,28 +323,28 @@ need_delimiter = args.delimited and not (args.kernel_stacks_only or
5d1f51
             if stack_id_err(k.t_u_stack_id):
5d1f51
                 line.append("[Missed User Stack]")
5d1f51
             else:
5d1f51
-                line.extend([b.sym(addr, k.t_tgid)
5d1f51
+                line.extend([b.sym(addr, k.t_tgid).decode('utf-8', 'replace')
5d1f51
                     for addr in reversed(list(target_user_stack)[1:])])
5d1f51
         if not args.user_stacks_only:
5d1f51
             line.extend(["-"] if (need_delimiter and k.t_k_stack_id > 0 and k.t_u_stack_id > 0) else [])
5d1f51
             if stack_id_err(k.t_k_stack_id):
5d1f51
                 line.append("[Missed Kernel Stack]")
5d1f51
             else:
5d1f51
-                line.extend([b.ksym(addr)
5d1f51
+                line.extend([b.ksym(addr).decode('utf-8', 'replace')
5d1f51
                     for addr in reversed(list(target_kernel_stack)[1:])])
5d1f51
         line.append("--")
5d1f51
         if not args.user_stacks_only:
5d1f51
             if stack_id_err(k.w_k_stack_id):
5d1f51
                 line.append("[Missed Kernel Stack]")
5d1f51
             else:
5d1f51
-                line.extend([b.ksym(addr)
5d1f51
+                line.extend([b.ksym(addr).decode('utf-8', 'replace')
5d1f51
                     for addr in reversed(list(waker_kernel_stack))])
5d1f51
         if not args.kernel_stacks_only:
5d1f51
             line.extend(["-"] if (need_delimiter and k.w_u_stack_id > 0 and k.w_k_stack_id > 0) else [])
5d1f51
             if stack_id_err(k.w_u_stack_id):
5d1f51
                 line.append("[Missed User Stack]")
5d1f51
             else:
5d1f51
-                line.extend([b.sym(addr, k.w_tgid)
5d1f51
+                line.extend([b.sym(addr, k.w_tgid).decode('utf-8', 'replace')
5d1f51
                     for addr in reversed(list(waker_user_stack))])
5d1f51
         line.append(k.waker.decode('utf-8', 'replace'))
5d1f51
         print("%s %d" % (";".join(line), v.value))
5d1f51
-- 
5d1f51
2.20.1
5d1f51