-
Notifications
You must be signed in to change notification settings - Fork 5
/
strace-with-colors.patch
914 lines (827 loc) · 26.6 KB
/
strace-with-colors.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
diff --git a/src/color.h b/src/color.h
new file mode 100644
index 000000000..e84b06672
--- /dev/null
+++ b/src/color.h
@@ -0,0 +1,12 @@
+#ifndef COLOR_H
+#define COLOR_H
+
+#define C_RESET "\033[0m"
+#define C_RED "\033[31m"
+#define C_GREEN "\033[32m"
+#define C_YELLOW "\033[33m"
+#define C_BLUE "\033[34m"
+#define C_MAGENTA "\033[35m"
+#define C_CYAN "\033[36m"
+
+#endif
diff --git a/src/futex.c b/src/futex.c
index ac2c7ffd8..6c094b0a6 100644
--- a/src/futex.c
+++ b/src/futex.c
@@ -25,6 +25,7 @@
#include "xlat/futexops.h"
#include "xlat/futexwakeops.h"
#include "xlat/futexwakecmps.h"
+#include "color.h"
static int
do_futex(struct tcb *const tcp, const print_obj_by_addr_fn print_ts)
diff --git a/src/ioctl.c b/src/ioctl.c
index fc6cef933..55ad6966e 100644
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -12,6 +12,7 @@
#include "defs.h"
#include <linux/ioctl.h>
#include "xlat/ioctl_dirs.h"
+#include "color.h"
#if defined(SPARC) || defined(SPARC64)
/*
@@ -480,10 +481,10 @@ SYS_FUNC(ioctl)
if (iop) {
if (ret)
tprint_alternative_value();
- tprints_string(iop->symbol);
+ tprintf_string(C_YELLOW "%s" C_RESET, iop->symbol);
while ((iop = ioctl_next_match(iop))) {
tprint_alternative_value();
- tprints_string(iop->symbol);
+ tprintf_string(C_YELLOW "%s" C_RESET, iop->symbol);
}
} else if (!ret) {
ioctl_print_code(tcp->u_arg[1]);
diff --git a/src/ipc.c b/src/ipc.c
index c9ccf2687..26cb80b4c 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -8,6 +8,7 @@
#include "defs.h"
#include "xlat/ipccalls.h"
+#include "color.h"
SYS_FUNC(ipc)
{
diff --git a/src/ipc_shm.c b/src/ipc_shm.c
index e9999c5f2..946851391 100644
--- a/src/ipc_shm.c
+++ b/src/ipc_shm.c
@@ -26,6 +26,7 @@
#include "xlat/shm_resource_flags.h"
#include "xlat/shm_flags.h"
+#include "color.h"
SYS_FUNC(shmget)
{
diff --git a/src/mem.c b/src/mem.c
index a959bf708..9f09a1258 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -14,6 +14,7 @@
#include "defs.h"
#include <linux/mman.h>
#include <sys/mman.h>
+#include "color.h"
unsigned long
get_pagesize(void)
@@ -90,7 +91,7 @@ print_mmap_flags(kernel_ulong_t flags)
* print_xlat_u is not used here because the whole thing
* is potentially inside a comment already.
*/
- tprints_string("MAP_HUGE_SHIFT");
+ tprints_string(C_YELLOW "MAP_HUGE_SHIFT" C_RESET);
tprint_shift_end();
}
diff --git a/src/memfd_create.c b/src/memfd_create.c
index a4509a27d..6fbed3f1f 100644
--- a/src/memfd_create.c
+++ b/src/memfd_create.c
@@ -9,6 +9,7 @@
#include "defs.h"
#include <linux/memfd.h>
#include "xlat/memfd_create_flags.h"
+#include "color.h"
#ifndef MFD_NAME_MAX_LEN
# define MFD_NAME_MAX_LEN (255 - (sizeof("memfd:") - 1))
@@ -52,7 +53,7 @@ SYS_FUNC(memfd_create)
* print_xlat_u is not used here because the whole thing
* is potentially inside a comment already.
*/
- tprints_string("MFD_HUGE_SHIFT");
+ tprints_string(C_YELLOW "MFD_HUGE_SHIFT" C_RESET);
tprint_shift_end();
}
diff --git a/src/mmsghdr.c b/src/mmsghdr.c
index ce793f4b5..668f506fb 100644
--- a/src/mmsghdr.c
+++ b/src/mmsghdr.c
@@ -13,6 +13,7 @@
#include "msghdr.h"
#include "xstring.h"
#include <limits.h>
+#include "color.h"
static bool
fetch_struct_mmsghdr_for_print(struct tcb *const tcp,
@@ -138,7 +139,7 @@ dumpiov_in_mmsghdr(struct tcb *const tcp, kernel_ulong_t addr)
fetched = fetch_struct_mmsghdr(tcp, addr, &mmsg);
if (!fetched)
break;
- tprintf_string(" = %" PRI_klu " buffers in vector %u\n",
+ tprintf_string(" = " C_CYAN "%" PRI_klu C_RESET " buffers in vector " C_CYAN "%u" C_RESET "\n",
(kernel_ulong_t) mmsg.msg_hdr.msg_iovlen, i);
dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
ptr_to_kulong(mmsg.msg_hdr.msg_iov),
diff --git a/src/netlink.c b/src/netlink.c
index e75e90440..e36031fc0 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -52,6 +52,7 @@
#include "xlat/nl_sock_diag_types.h"
#include "xlat/nl_xfrm_types.h"
#include "xlat/nlmsgerr_attrs.h"
+#include "color.h"
/*
* Fetch a struct nlmsghdr from the given address.
diff --git a/src/netlink_netlink_diag.c b/src/netlink_netlink_diag.c
index e0d689421..70829659e 100644
--- a/src/netlink_netlink_diag.c
+++ b/src/netlink_netlink_diag.c
@@ -19,6 +19,7 @@
#include "xlat/netlink_diag_show.h"
#include "xlat/netlink_socket_flags.h"
#include "xlat/netlink_states.h"
+#include "color.h"
DECL_NETLINK_DIAG_DECODER(decode_netlink_diag_req)
{
diff --git a/src/numa.c b/src/numa.c
index 3e7fb2984..b2f74992f 100644
--- a/src/numa.c
+++ b/src/numa.c
@@ -8,6 +8,7 @@
*/
#include "defs.h"
+#include "color.h"
static bool
print_node(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
@@ -96,7 +97,7 @@ print_mode(struct tcb *const tcp, const kernel_ulong_t mode_arg)
tprint_comment_begin();
tprint_flags_begin();
- tprints_string(mode_str);
+ tprintf_string(C_YELLOW "%s" C_RESET, mode_str);
tprint_flags_or();
printflags_ex(flags, NULL, XLAT_STYLE_ABBREV, mpol_mode_flags, NULL);
tprint_flags_end();
diff --git a/src/perf.c b/src/perf.c
index 1a39cd0c7..4fe1bff1d 100644
--- a/src/perf.c
+++ b/src/perf.c
@@ -25,6 +25,7 @@
#include "xlat/perf_hw_id.h"
#include "xlat/perf_sw_ids.h"
#include "xlat/perf_type_id.h"
+#include "color.h"
struct pea_desc {
struct perf_event_attr *attr;
diff --git a/src/print_fields.h b/src/print_fields.h
index 60ecf56af..b51683460 100644
--- a/src/print_fields.h
+++ b/src/print_fields.h
@@ -10,6 +10,7 @@
# define STRACE_PRINT_FIELDS_H
# include "static_assert.h"
+#include "color.h"
# ifdef IN_STRACE
@@ -140,13 +141,13 @@ tprint_bitset_end(void)
static inline void
tprint_comment_begin(void)
{
- STRACE_PRINTS(" /* ");
+ STRACE_PRINTS(C_MAGENTA " /* ");
}
static inline void
tprint_comment_end(void)
{
- STRACE_PRINTS(" */");
+ STRACE_PRINTS(" */" C_RESET);
}
static inline void
@@ -256,7 +257,7 @@ tprint_space(void)
static inline void
tprint_null(void)
{
- STRACE_PRINTS("NULL");
+ STRACE_PRINTS(C_CYAN "NULL" C_RESET);
}
static inline void
@@ -268,13 +269,13 @@ tprint_newline(void)
static inline void
tprints_field_name(const char *name)
{
- STRACE_PRINTF("%s=", name);
+ STRACE_PRINTF(C_BLUE "%s" C_RESET "=", name);
}
static inline void
tprints_arg_name_begin(const char *name)
{
- STRACE_PRINTF("%s=", name);
+ STRACE_PRINTF(C_BLUE "%s" C_RESET "=", name);
}
static inline void
@@ -285,7 +286,7 @@ tprint_arg_name_end(void)
static inline void
tprints_arg_begin(const char *name)
{
- STRACE_PRINTF("%s(", name);
+ STRACE_PRINTF(C_RED "%s" C_RESET "(", name);
}
static inline void
@@ -319,19 +320,19 @@ tprint_sysret_end(void)
}
# define PRINT_VAL_D(val_) \
- STRACE_PRINTF("%lld", sign_extend_unsigned_to_ll(val_))
+ STRACE_PRINTF(C_CYAN "%lld" C_RESET, sign_extend_unsigned_to_ll(val_))
# define PRINT_VAL_U(val_) \
- STRACE_PRINTF("%llu", zero_extend_signed_to_ull(val_))
+ STRACE_PRINTF(C_CYAN "%llu" C_RESET, zero_extend_signed_to_ull(val_))
# define PRINT_VAL_X(val_) \
- STRACE_PRINTF("%#llx", zero_extend_signed_to_ull(val_))
+ STRACE_PRINTF(C_CYAN "%#llx" C_RESET, zero_extend_signed_to_ull(val_))
# define PRINT_VAL_03O(val_) \
- STRACE_PRINTF("%#03llo", zero_extend_signed_to_ull(val_))
+ STRACE_PRINTF(C_CYAN "%#03llo" C_RESET, zero_extend_signed_to_ull(val_))
# define PRINT_VAL_0X(val_) \
- STRACE_PRINTF("%#0*llx", (int) sizeof(val_) * 2, \
+ STRACE_PRINTF(C_CYAN "%#0*llx" C_RESET, (int) sizeof(val_) * 2, \
zero_extend_signed_to_ull(val_))
# define PRINT_VAL_ID(val_) \
diff --git a/src/print_instruction_pointer.c b/src/print_instruction_pointer.c
index d2cc7628b..80692d6cf 100644
--- a/src/print_instruction_pointer.c
+++ b/src/print_instruction_pointer.c
@@ -15,8 +15,8 @@ print_instruction_pointer(struct tcb *tcp)
tprint_attribute_begin();
if (get_instruction_pointer(tcp, &ip)) {
tprintf_string(current_wordsize == 4
- ? "%08" PRI_klx
- : "%016" PRI_klx, ip);
+ ? C_CYAN "%08" PRI_klx C_RESET
+ : C_CYAN "%016" PRI_klx C_RESET, ip);
} else {
tprints_string(current_wordsize == 4
? "????????"
diff --git a/src/print_syscall_number.c b/src/print_syscall_number.c
index 82a1eaa66..ec046e43f 100644
--- a/src/print_syscall_number.c
+++ b/src/print_syscall_number.c
@@ -6,13 +6,14 @@
*/
#include "defs.h"
+#include "color.h"
void
print_syscall_number(struct tcb *tcp)
{
tprint_attribute_begin();
if (tcp->true_scno != (kernel_ulong_t) -1)
- tprintf_string("%4" PRI_klu, tcp->true_scno);
+ tprintf_string(C_CYAN "%4" PRI_klu C_RESET, tcp->true_scno);
else
tprint_unavailable();
tprint_attribute_end();
diff --git a/src/printmode.c b/src/printmode.c
index baab46449..a718627cf 100644
--- a/src/printmode.c
+++ b/src/printmode.c
@@ -16,6 +16,7 @@
#include <sys/stat.h>
#include "xlat/modetypes.h"
+#include "color.h"
void
print_symbolic_mode_t(const unsigned int mode)
@@ -31,13 +32,21 @@ print_symbolic_mode_t(const unsigned int mode)
if (!ifmt || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
return;
- (xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV
- ? tprintf_string : tprintf_comment)("%s%s%s%s%s%#03o",
+ if(xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV) {
+ tprintf_string(C_YELLOW "%s" C_RESET "%s%s%s%s" C_CYAN "%#03o" C_RESET,
+ ifmt, ifmt[0] ? "|" : "",
+ (mode & S_ISUID) ? C_YELLOW "S_ISUID" C_RESET "|" : "",
+ (mode & S_ISGID) ? C_YELLOW "S_ISGID" C_RESET "|" : "",
+ (mode & S_ISVTX) ? C_YELLOW "S_ISVTX" C_RESET "|" : "",
+ mode & ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX));
+ } else {
+ tprintf_comment("%s%s%s%s%s%#03o",
ifmt, ifmt[0] ? "|" : "",
(mode & S_ISUID) ? "S_ISUID|" : "",
(mode & S_ISGID) ? "S_ISGID|" : "",
(mode & S_ISVTX) ? "S_ISVTX|" : "",
mode & ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX));
+ }
}
void
diff --git a/src/ptrace.c b/src/ptrace.c
index 663a5f314..be9b7d61b 100644
--- a/src/ptrace.c
+++ b/src/ptrace.c
@@ -31,6 +31,7 @@
#include "xlat/compat_ptrace_cmds.h"
#include "xlat/ptrace_setoptions_flags.h"
#include "xlat/ptrace_peeksiginfo_flags.h"
+#include "color.h"
#define uoff(member) offsetof(struct user, member)
#define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" }
diff --git a/src/s390.c b/src/s390.c
index ca71730c4..7b0dd6bea 100644
--- a/src/s390.c
+++ b/src/s390.c
@@ -16,6 +16,7 @@
# include "xlat/s390_guarded_storage_commands.h"
# include "xlat/s390_runtime_instr_commands.h"
# include "xlat/s390_sthyi_function_codes.h"
+#include "color.h"
/*
* Since, for some reason, kernel doesn't expose all these nice constants and
@@ -510,7 +511,7 @@ print_sthyi_machine(struct tcb *tcp, struct sthyi_machine *hdr, uint16_t size,
CHECK_SIZE_EX(hdr, last_decoded, size, "machine structure");
- tprints_string("/* machine */ ");
+ tprints_string(C_MAGENTA "/* machine */ " C_RESET);
tprint_struct_begin();
if (!abbrev(tcp)) {
if (hdr->infmflg1) { /* Reserved */
@@ -620,7 +621,7 @@ print_sthyi_partition(struct tcb *tcp, struct sthyi_partition *hdr,
*mt = !!(hdr->infpflg1 & 0x80);
- tprints_string("/* partition */ ");
+ tprints_string(C_MAGENTA "/* partition */ " C_RESET);
tprint_struct_begin();
PRINT_FIELD_0X(*hdr, infpflg1);
if (!abbrev(tcp) && hdr->infpflg1)
@@ -791,7 +792,7 @@ print_funcs(const uint8_t funcs[8])
tprint_comment_begin();
cont = true;
}
- tprintf_string("%u: %s", i, func_descs[i]);
+ tprintf_string(C_CYAN "%u" C_RESET ": %s", i, func_descs[i]);
}
if (cont)
@@ -806,7 +807,7 @@ print_sthyi_hypervisor(struct tcb *tcp, struct sthyi_hypervisor *hdr,
CHECK_SIZE_EX(hdr, last_decoded, size, "hypervisor %d structure", num);
- tprintf_string("/* hypervisor %d */ ", num);
+ tprintf_string(C_MAGENTA "/* hypervisor %d */ " C_RESET, num);
tprint_struct_begin();
PRINT_FIELD_0X(*hdr, infyflg1);
if (!abbrev(tcp) && hdr->infyflg1)
@@ -922,7 +923,7 @@ print_sthyi_guest(struct tcb *tcp, struct sthyi_guest *hdr, uint16_t size,
{
CHECK_SIZE(hdr, size, "guest %d structure", num);
- tprintf_string("/* guest %d */ ", num);
+ tprintf_string(C_MAGENTA "/* guest %d */ " C_RESET, num);
tprint_struct_begin();
PRINT_FIELD_0X(*hdr, infgflg1);
if (!abbrev(tcp) && hdr->infgflg1)
@@ -1132,7 +1133,7 @@ print_sthyi_buf(struct tcb *tcp, kernel_ulong_t ptr)
tprint_struct_begin();
/* Header */
- tprints_string("/* header */ ");
+ tprints_string(C_MAGENTA "/* header */ " C_RESET);
tprint_struct_begin();
PRINT_FIELD_0X(*hdr, infhflg1);
@@ -1349,7 +1350,7 @@ guard_storage_print_gsepl(struct tcb *tcp, uint64_t addr)
/* Since it is 64-bit even on 31-bit s390... */
if (sizeof(addr) > current_klongsize &&
addr >= (1ULL << (current_klongsize * 8))) {
- tprintf_string("%#" PRIx64, addr);
+ tprintf_string(C_CYAN "%#" PRIx64 C_RESET, addr);
return;
}
diff --git a/src/signal.c b/src/signal.c
index 98f84d500..c1879aaaa 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -15,6 +15,7 @@
#include "defs.h"
#include "nsig.h"
#include "xstring.h"
+#include "color.h"
/* The libc headers do not define this constant since it should only be
used by the implementation. So we define it here. */
@@ -241,8 +242,12 @@ printsignal(int nr)
PRINT_VAL_D(nr);
if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
return;
- (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
- ? tprints_comment : tprints_string)(str);
+
+ if(xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE) {
+ tprints_comment(str);
+ } else {
+ tprintf_string(C_YELLOW "%s" C_RESET, str);
+ }
}
static void
@@ -810,8 +815,11 @@ SYS_FUNC(rt_sigtimedwait_time64)
SYS_FUNC(restart_syscall)
{
- tprintf_string("<... resuming interrupted %s ...>",
- tcp->s_prev_ent ? tcp->s_prev_ent->sys_name : "system call");
+ if(tcp->s_prev_ent) {
+ tprintf_string("<... resuming interrupted " C_RED "%s" C_RESET " ...>", tcp->s_prev_ent->sys_name);
+ } else {
+ tprints_string("<... resuming interrupted system call ...>");
+ }
return RVAL_DECODED;
}
diff --git a/src/sockaddr.c b/src/sockaddr.c
index ee1ce8828..7b7b77d39 100644
--- a/src/sockaddr.c
+++ b/src/sockaddr.c
@@ -39,6 +39,7 @@
#include "xlat/bluetooth_l2_cid.h"
#include "xlat/bluetooth_l2_psm.h"
#include "xlat/hci_channels.h"
+#include "color.h"
#include "xlat/rxrpc_services.h"
@@ -181,7 +182,7 @@ print_inet_addr(const int af,
if (var_name &&
(xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV)) {
tprint_arg_next();
- tprintf_string("&%s", var_name);
+ tprintf_string(C_BLUE "&%s" C_RESET, var_name);
}
tprint_arg_end();
@@ -628,7 +629,7 @@ print_bluetooth_l2_psm(uint16_t psm)
tprint_plus();
PRINT_VAL_U(psm_he - L2CAP_PSM_DYN_START);
} else {
- tprints_string("L2CAP_PSM_???");
+ tprints_string(C_YELLOW "L2CAP_PSM_???" C_RESET);
}
if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE || !psm_str)
@@ -663,7 +664,7 @@ print_bluetooth_l2_cid(uint16_t cid)
tprint_plus();
PRINT_VAL_U(cid_he - L2CAP_CID_DYN_START);
} else {
- tprints_string("L2CAP_CID_???");
+ tprints_string(C_YELLOW "L2CAP_CID_???" C_RESET);
}
if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE || !cid_str)
diff --git a/src/strace.c b/src/strace.c
index 85d69485f..0c43e0d6d 100644
--- a/src/strace.c
+++ b/src/strace.c
@@ -43,6 +43,8 @@
#include "wait.h"
#include "secontext.h"
+#include "color.h"
+
/* In some libc, these aren't declared. Do it ourself: */
extern char **environ;
extern int optind;
@@ -95,6 +97,12 @@ static int rflag_scale = 1000;
static int rflag_width = 6;
static bool print_pid_pfx;
+/* -1 = auto
+ * 0 = never
+ * 1 = always
+ */
+int no_color_flag = -1;
+
static unsigned int version_verbosity;
/* -I n */
@@ -350,6 +358,8 @@ Filtering:\n\
print only syscalls that returned with an error code\n\
\n\
Output format:\n\
+ --color[=WHEN]\n\
+ colorize the output; WHEN can be 'always', 'auto' (default), or 'never'\n\
-a COLUMN, --columns=COLUMN\n\
alignment COLUMN for printing syscall results (default %d)\n\
-e abbrev=SET, --abbrev=SET\n\
@@ -716,7 +726,23 @@ static void
tvprintf(const char *const fmt, va_list args)
{
if (current_tcp) {
- int n = vfprintf(current_tcp->outf, fmt, args);
+ int n;
+ if(no_color_flag) {
+ char new_fmt[strlen(fmt) + 1];
+ int i = 0;
+ for(const char *c = fmt; *c; c++) {
+ if(*c == '\033') {
+ for(c++; *c && *c != 'm'; c++);
+ continue;
+ }
+
+ new_fmt[i++] = *c;
+ }
+ new_fmt[i] = '\0';
+ n = vfprintf(current_tcp->outf, new_fmt, args);
+ } else
+ n = vfprintf(current_tcp->outf, fmt, args);
+
if (n < 0) {
/* very unlikely due to vfprintf buffering */
outf_perror(current_tcp);
@@ -742,7 +768,22 @@ void
tprints_string(const char *str)
{
if (current_tcp) {
- int n = fputs_unlocked(str, current_tcp->outf);
+ int n;
+ if(no_color_flag) {
+ char new_str[strlen(str) + 1];
+ int i = 0;
+ for(const char *c = str; *c; c++) {
+ if(*c == '\033') {
+ for(c++; *c && *c != 'm'; c++);
+ continue;
+ }
+ new_str[i++] = *c;
+ }
+ new_str[i] = '\0';
+ n = fputs_unlocked(new_str, current_tcp->outf);
+ } else
+ n = fputs_unlocked(str, current_tcp->outf);
+
if (n >= 0) {
current_tcp->curcol += strlen(str);
return;
@@ -885,7 +926,7 @@ printleader(struct tcb *tcp)
else
xsprintf(str, "%lld", (long long) local);
if (tflag_width)
- tprintf_string("%s.%0*ld ", str, tflag_width,
+ tprintf_string("%s." C_CYAN "%0*ld" C_RESET " ", str, tflag_width,
(long) ts.tv_nsec / tflag_scale);
else
tprintf_string("%s ", str);
@@ -903,10 +944,10 @@ printleader(struct tcb *tcp)
ts_sub(&dts, &ts, &ots);
ots = ts;
- tprintf_string("%s%6ld",
+ tprintf_string("%s" C_CYAN "%6ld" C_RESET,
tflag_format ? "(+" : "", (long) dts.tv_sec);
if (rflag_width) {
- tprintf_string(".%0*ld", rflag_width,
+ tprintf_string("." C_CYAN "%0*ld" C_RESET, rflag_width,
(long) dts.tv_nsec / rflag_scale);
}
tprints_string(tflag_format ? ") " : " ");
@@ -2263,6 +2304,7 @@ init(int argc, char *argv[])
enum {
GETOPT_SECCOMP = 0x100,
+ GETOPT_COLOR,
GETOPT_DAEMONIZE,
GETOPT_HEX_STR,
GETOPT_FOLLOWFORKS,
@@ -2291,6 +2333,7 @@ init(int argc, char *argv[])
GETOPT_QUAL_SECONTEXT,
};
static const struct option longopts[] = {
+ { "color", optional_argument, 0, GETOPT_COLOR },
{ "columns", required_argument, 0, 'a' },
{ "output-append-mode", no_argument, 0, 'A' },
{ "detach-on", required_argument, 0, 'b' },
@@ -2401,6 +2444,23 @@ init(int argc, char *argv[])
case 'D':
daemonized_tracer++;
break;
+ case GETOPT_COLOR:
+ if(optarg) {
+ if(!strcmp(optarg , "always"))
+ no_color_flag = 0;
+ else if(!strcmp(optarg, "never"))
+ no_color_flag = 1;
+ else if(!strcmp(optarg, "auto"))
+ no_color_flag = -1;
+ else
+ error_msg_and_die("invalid argument \"%s\" for \"--color\"\n"
+ "Valid arguments are:\n"
+ " - \"always\"\n"
+ " - \"never\"\n"
+ " - \"auto\"",
+ optarg);
+ }
+ break;
case GETOPT_DAEMONIZE:
daemonized_tracer_long =
find_arg_val(optarg, daemonize_str,
@@ -2935,6 +2995,14 @@ init(int argc, char *argv[])
qflag_short == 2 ? qqflag_qual : qqqflag_qual);
}
+ // --color=auto (default)
+ if(no_color_flag == -1)
+ no_color_flag = !isatty(STDOUT_FILENO);
+
+ // if we set NO_COLOR or use --output
+ if((getenv("NO_COLOR")) || outfname)
+ no_color_flag = 1;
+
/*
* startup_child() must be called before the signal handlers get
* installed below as they are inherited into the spawned process.
diff --git a/src/swapon.c b/src/swapon.c
index aaa409a66..03446d282 100644
--- a/src/swapon.c
+++ b/src/swapon.c
@@ -10,6 +10,7 @@
#include <sys/swap.h>
#include "xlat/swap_flags.h"
+#include "color.h"
SYS_FUNC(swapon)
{
diff --git a/src/syscall.c b/src/syscall.c
index c636ba37c..db39380b1 100644
--- a/src/syscall.c
+++ b/src/syscall.c
@@ -25,6 +25,7 @@
#include "retval.h"
#include <limits.h>
#include <fcntl.h>
+#include "color.h"
/* for struct iovec */
#include <sys/uio.h>
@@ -421,7 +422,7 @@ print_err(int64_t err, bool negated)
const char *str = err_name(negated ? -err : err);
if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
- tprintf_string(negated ? "%" PRId64 : "%" PRIu64, err);
+ tprintf_string(negated ? C_CYAN "%" PRId64 C_RESET : C_CYAN "%" PRIu64 C_RESET, err);
if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
return;
(xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV
@@ -443,7 +444,7 @@ print_err_ret(kernel_ulong_t ret, unsigned long u_error)
tprints_sysret_string("strerror", strerror(u_error));
} else {
tprints_sysret_next("strerror");
- tprintf_string("(errno %lu)", u_error);
+ tprintf_string("(errno " C_CYAN "%lu" C_RESET ")", u_error);
}
}
@@ -760,7 +761,7 @@ print_syscall_resume(struct tcb *tcp)
|| (tcp->flags & TCB_REPRINT)) {
tcp->flags &= ~TCB_REPRINT;
printleader(tcp);
- tprintf_string("<... %s resumed>", tcp_sysent(tcp)->sys_name);
+ tprintf_string("<... " C_RED "%s" C_RESET " resumed>", tcp_sysent(tcp)->sys_name);
}
printing_tcp = tcp;
}
@@ -1012,7 +1013,7 @@ syscall_exiting_trace(struct tcb *tcp, struct timespec *ts, int res)
ts_sub(ts, ts, &tcp->etime);
PRINT_VAL_D(ts->tv_sec);
if (Tflag_width) {
- tprintf_string(".%0*ld", Tflag_width,
+ tprintf_string("." C_CYAN "%0*ld" C_RESET, Tflag_width,
(long) ts->tv_nsec / Tflag_scale);
}
tprint_associated_info_end();
diff --git a/src/sysctl.c b/src/sysctl.c
index 8624e018e..bd48df718 100644
--- a/src/sysctl.c
+++ b/src/sysctl.c
@@ -11,6 +11,7 @@
#include <linux/sysctl.h>
typedef struct __sysctl_args struct_sysctl_args;
#include MPERS_DEFS
+#include "color.h"
SYS_FUNC(sysctl)
{
diff --git a/src/term.c b/src/term.c
index f392af3fd..2b2e0c786 100644
--- a/src/term.c
+++ b/src/term.c
@@ -41,6 +41,7 @@
#endif
#include "xlat/term_cmds_overlapping.h"
+#include "color.h"
static void
decode_oflag(uint64_t val)
diff --git a/src/util.c b/src/util.c
index 343cf8850..efea2b16a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -32,6 +32,7 @@
#include "string_to_uint.h"
#include "xlat.h"
#include "xstring.h"
+#include "color.h"
const struct xlat_data *
find_xlat_val_ex(const struct xlat_data * const items, const char * const s,
@@ -696,7 +697,7 @@ printdev(struct tcb *tcp, int fd, const char *path, const struct finfo *finfo)
QUOTE_OMIT_LEADING_TRAILING_QUOTES,
"<>");
tprint_associated_info_begin();
- tprintf_string("%s %u:%u",
+ tprintf_string(C_BLUE "%s" C_RESET " " C_CYAN "%u" C_RESET ":" C_CYAN "%u" C_RESET,
(finfo->type == FINFO_DEV_BLK)? "block" : "char",
finfo->dev.major, finfo->dev.minor);
tprint_associated_info_end();
@@ -1163,7 +1164,7 @@ print_quoted_string_ex(const char *str, unsigned int size,
}
rc = string_quote(str, outstr, size, style, escape_chars);
- tprints_string(outstr);
+ tprintf_string(C_GREEN "%s" C_RESET, outstr);
if (((style & (QUOTE_0_TERMINATED | QUOTE_EXPECT_TRAILING_0))
== (QUOTE_0_TERMINATED | QUOTE_EXPECT_TRAILING_0)) && rc) {
@@ -1316,7 +1317,7 @@ printstr_ex(struct tcb *const tcp, const kernel_ulong_t addr,
&& ((style & (QUOTE_0_TERMINATED | QUOTE_EXPECT_TRAILING_0))
|| len > max_strlen);
- tprints_string(outstr);
+ tprintf_string(C_GREEN "%s" C_RESET, outstr);
if (ellipsis)
tprint_more_data_follows();
@@ -1357,7 +1358,7 @@ print_nonzero_bytes(struct tcb *const tcp,
ret = false;
} else {
prefix_fun();
- tprintf_string("/* bytes %u..%u */ ", start_offs, total_len - 1);
+ tprintf_string(C_MAGENTA "/* bytes %u..%u */ " C_RESET, start_offs, total_len - 1);
print_quoted_string(str, size, style);
@@ -1415,8 +1416,7 @@ dumpiov_upto(struct tcb *const tcp, const int len, const kernel_ulong_t addr,
data_size -= iov_len;
/* include the buffer number to make it easy to
* match up the trace with the source */
- tprintf_string(" * %" PRI_klu " bytes in buffer %d\n",
- iov_len, i);
+ tprintf_string(" * " C_CYAN "%" PRI_klu C_RESET " bytes in buffer " C_CYAN "%d" C_RESET "\n", iov_len, i);
dumpstr(tcp, iov_iov_base(i), iov_len);
}
}
@@ -1556,7 +1556,7 @@ dumpstr(struct tcb *const tcp, const kernel_ulong_t addr,
src++;
} while (++i & DUMPSTR_BYTES_MASK);
- tprintf_string(" | %0*" PRI_klx " %s |\n",
+ tprintf_string(" | " C_CYAN "%0*" PRI_klx C_RESET " %s |\n",
offs_chars, i - DUMPSTR_WIDTH_BYTES, outbuf);
}
}
diff --git a/src/wait.c b/src/wait.c
index 1f04e836e..950c8f526 100644
--- a/src/wait.c
+++ b/src/wait.c
@@ -20,6 +20,7 @@
#include "xlat/wait4_options.h"
#include "xlat/ptrace_events.h"
+#include "color.h"
static int
printstatus(int status)
@@ -37,7 +38,7 @@ printstatus(int status)
int sig = WSTOPSIG(status);
tprintf_string("{WIFSTOPPED(s) && WSTOPSIG(s) == %s%s}",
sprintsigname(sig & 0x7f),
- sig & 0x80 ? " | 0x80" : "");
+ sig & 0x80 ? " |" C_CYAN "0x80" C_RESET : "");
status &= ~W_STOPCODE(sig);
} else if (WIFSIGNALED(status)) {
tprintf_string("{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
@@ -45,7 +46,7 @@ printstatus(int status)
WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
} else if (WIFEXITED(status)) {
- tprintf_string("{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
+ tprintf_string("{WIFEXITED(s) && WEXITSTATUS(s) == " C_CYAN "%d" C_RESET "}",
WEXITSTATUS(status));
exited = 1;
status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
diff --git a/src/xlat.c b/src/xlat.c
index 5135ab440..6d6c72290 100644
--- a/src/xlat.c
+++ b/src/xlat.c
@@ -12,6 +12,7 @@
#include "defs.h"
#include "xstring.h"
#include <stdarg.h>
+#include "color.h"
static enum xlat_style
get_xlat_style(enum xlat_style style)
@@ -47,7 +48,7 @@ sprint_xlat_val(uint64_t val, enum xlat_style style)
static void
print_xlat_val(uint64_t val, enum xlat_style style)
{
- tprints_string(sprint_xlat_val(val, style));
+ tprintf_string(C_CYAN "%s" C_RESET, sprint_xlat_val(val, style));
}
static int
@@ -231,7 +232,7 @@ printxvals_ex(const uint64_t val, const char *dflt, enum xlat_style style,
print_xlat_val(val, style);
tprints_comment(str);
} else {
- tprints_string(str);
+ tprintf_string(C_YELLOW "%s" C_RESET, str);
}
goto printxvals_ex_end;
@@ -441,7 +442,7 @@ printflags_ex(uint64_t flags, const char *dflt, enum xlat_style style,
tprint_flags_or();
else if (need_comment)
tprint_comment_begin();
- tprints_string(xlat->data[idx].str);
+ tprintf_string(C_YELLOW "%s" C_RESET, xlat->data[idx].str);
flags &= ~v;
}
if (!flags)
@@ -486,7 +487,7 @@ print_xlat_ex(const uint64_t val, const char *str, uint32_t style)
print_xlat_val(val, style);
tprints_comment(str);
} else {
- tprints_string(str);
+ tprintf_string(C_YELLOW "%s" C_RESET, str);
}
break;
}