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/gethostlatency.py b/tools/gethostlatency.py
index f1d7dea..3a967ae 100755
--- a/tools/gethostlatency.py
+++ b/tools/gethostlatency.py
@@ -129,8 +129,8 @@
 def print_event(cpu, data, size):
     event = ct.cast(data, ct.POINTER(Data)).contents
     print("%-9s %-6d %-16s %10.2f %s" % (strftime("%H:%M:%S"), event.pid,
-        event.comm.decode(), (float(event.delta) / 1000000),
-        event.host.decode()))
+        event.comm.decode('utf-8', 'replace'), (float(event.delta) / 1000000),
+        event.host.decode('utf-8', 'replace')))
 
 # loop with callback to print_event
 b["events"].open_perf_buffer(print_event)