Created
April 2, 2017 08:06
-
-
Save goldshtn/860825d8f0f05636a80e045a55d6369a to your computer and use it in GitHub Desktop.
One-time hack for BCC's argdist to support Unicode strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/build/../tools/argdist.py b/usr/share/bcc/tools/argdist | |
index 61f8e00..746d1b7 100755 | |
--- a/build/../tools/argdist.py | |
+++ b/usr/share/bcc/tools/argdist | |
@@ -451,7 +451,10 @@ DATA_DECL | |
# Most fields can be converted with plain str(), but strings | |
# are wrapped in a __string_t which has an .s field | |
if "__string_t" in type(v).__name__: | |
- return str(v.s) | |
+ s = bytearray(v.s) | |
+ i = s.find('\x00\x00') | |
+ s = s[:i] | |
+ return s.decode("utf-8") | |
return str(v) | |
def _display_expr(self, i): | |
@@ -641,7 +644,7 @@ argdist -p 2780 -z 120 \\ | |
def _generate_program(self): | |
bpf_source = """ | |
-struct __string_t { char s[%d]; }; | |
+struct __string_t { u8 s[%d]; }; | |
#include <uapi/linux/ptrace.h> | |
""" % self.args.string_size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment