Bytes/string encoding (#2004)

* tools: uses 'replace' error handler by default in decode()

Tools might encouter characters from non utf-8 charset (e.g. a file
name). When this happen, it's better to replace the unexpected
character by a question mark than crash the tool when all we do is
to print the string.

* tools: fix a bytes/string issue in attach_perf_event()
diff --git a/tools/tcpaccept.py b/tools/tcpaccept.py
index 044f15c..884b0c5 100755
--- a/tools/tcpaccept.py
+++ b/tools/tcpaccept.py
@@ -239,7 +239,7 @@
             start_ts = event.ts_us
         print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
     print("%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
-        event.task.decode(), event.ip,
+        event.task.decode('utf-8', 'replace'), event.ip,
         inet_ntop(AF_INET, pack("I", event.daddr)),
         inet_ntop(AF_INET, pack("I", event.saddr)), event.lport))
 
@@ -251,8 +251,9 @@
             start_ts = event.ts_us
         print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
     print("%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
-        event.task.decode(), event.ip, inet_ntop(AF_INET6, event.daddr),
-        inet_ntop(AF_INET6, event.saddr), event.lport))
+        event.task.decode('utf-8', 'replace'), event.ip,
+        inet_ntop(AF_INET6, event.daddr),inet_ntop(AF_INET6, event.saddr),
+        event.lport))
 
 # initialize BPF
 b = BPF(text=bpf_text)