diff options
Diffstat (limited to 'tools/perf/util/data-convert-bt.c')
-rw-r--r-- | tools/perf/util/data-convert-bt.c | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c index bbf69d248ec5..9f53020c3269 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c | |||
@@ -204,6 +204,44 @@ static unsigned long long adjust_signedness(unsigned long long value_int, int si | |||
204 | return (value_int & value_mask) | ~value_mask; | 204 | return (value_int & value_mask) | ~value_mask; |
205 | } | 205 | } |
206 | 206 | ||
207 | static int string_set_value(struct bt_ctf_field *field, const char *string) | ||
208 | { | ||
209 | char *buffer = NULL; | ||
210 | size_t len = strlen(string), i, p; | ||
211 | int err; | ||
212 | |||
213 | for (i = p = 0; i < len; i++, p++) { | ||
214 | if (isprint(string[i])) { | ||
215 | if (!buffer) | ||
216 | continue; | ||
217 | buffer[p] = string[i]; | ||
218 | } else { | ||
219 | char numstr[5]; | ||
220 | |||
221 | snprintf(numstr, sizeof(numstr), "\\x%02x", | ||
222 | (unsigned int)(string[i]) & 0xff); | ||
223 | |||
224 | if (!buffer) { | ||
225 | buffer = zalloc(i + (len - i) * 4 + 2); | ||
226 | if (!buffer) { | ||
227 | pr_err("failed to set unprintable string '%s'\n", string); | ||
228 | return bt_ctf_field_string_set_value(field, "UNPRINTABLE-STRING"); | ||
229 | } | ||
230 | if (i > 0) | ||
231 | strncpy(buffer, string, i); | ||
232 | } | ||
233 | strncat(buffer + p, numstr, 4); | ||
234 | p += 3; | ||
235 | } | ||
236 | } | ||
237 | |||
238 | if (!buffer) | ||
239 | return bt_ctf_field_string_set_value(field, string); | ||
240 | err = bt_ctf_field_string_set_value(field, buffer); | ||
241 | free(buffer); | ||
242 | return err; | ||
243 | } | ||
244 | |||
207 | static int add_tracepoint_field_value(struct ctf_writer *cw, | 245 | static int add_tracepoint_field_value(struct ctf_writer *cw, |
208 | struct bt_ctf_event_class *event_class, | 246 | struct bt_ctf_event_class *event_class, |
209 | struct bt_ctf_event *event, | 247 | struct bt_ctf_event *event, |
@@ -270,8 +308,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw, | |||
270 | } | 308 | } |
271 | 309 | ||
272 | if (flags & FIELD_IS_STRING) | 310 | if (flags & FIELD_IS_STRING) |
273 | ret = bt_ctf_field_string_set_value(field, | 311 | ret = string_set_value(field, data + offset + i * len); |
274 | data + offset + i * len); | ||
275 | else { | 312 | else { |
276 | unsigned long long value_int; | 313 | unsigned long long value_int; |
277 | 314 | ||