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/tcptracer.py b/tools/tcptracer.py
index 5e97ee6..16bb4b1 100755
--- a/tools/tcptracer.py
+++ b/tools/tcptracer.py
@@ -556,7 +556,7 @@
print("%-2s " % (type_str), end="")
print("%-6d %-16s %-2d %-16s %-16s %-6d %-6d" %
- (event.pid, event.comm.decode('utf-8'),
+ (event.pid, event.comm.decode('utf-8', 'replace'),
event.ip,
inet_ntop(AF_INET, pack("I", event.saddr)),
inet_ntop(AF_INET, pack("I", event.daddr)),
@@ -593,7 +593,7 @@
print("%-2s " % (type_str), end="")
print("%-6d %-16s %-2d %-16s %-16s %-6d %-6d" %
- (event.pid, event.comm.decode('utf-8'),
+ (event.pid, event.comm.decode('utf-8', 'replace'),
event.ip,
"[" + inet_ntop(AF_INET6, event.saddr) + "]",
"[" + inet_ntop(AF_INET6, event.daddr) + "]",