This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
parsers.py
898 lines (742 loc) · 24.3 KB
/
parsers.py
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
import argparse
import multiprocessing as mp
from typing import Any, Sequence
def config_parser(
expected_entries: Sequence[tuple[Any, ...]]
) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(add_help=False)
for _, path, desc in expected_entries:
parser.add_argument("--" + ".".join(path), help=desc)
parser.add_argument("--config", type=str, help="Path to config.json")
parser.add_argument(
"-ll",
"--log-level",
type=str,
choices=("debug", "info", "warning", "error", "critical"),
help="Log level",
)
parser.add_argument(
"--cores",
help="Amount of build cores to use. Defaults to all.",
type=int,
default=mp.cpu_count(),
)
return parser
def builder_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
"-c", "--compiler", help="Which compiler project to use", nargs=1, type=str
)
parser.add_argument(
"-r",
"--revision",
help="Which revision of the compiler project to use. Use 'trunk' to use the latest commit",
nargs="+",
type=str,
)
parser.add_argument(
"--build-releases", help="Build release versions", action="store_true"
)
parser.add_argument(
"--add-patches",
help="Which patches to apply in addition to the ones found in patchDB",
nargs="+",
type=str,
)
parser.add_argument(
"-f",
"--force",
help="Force build even if patch combo is known to be bad",
action="store_true",
)
return parser
def patcher_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(add_help=False)
mut_excl_group = parser.add_mutually_exclusive_group(required=True)
# ====================
mut_excl_group.add_argument(
"--find-range",
help="Try to find the range where a patch is required",
action="store_true",
)
parser.add_argument(
"-c",
"--compiler",
help="Which compiler project to use",
nargs=1,
type=str,
required=True,
)
parser.add_argument(
"-pr",
"--patchable-revision",
help="Which revision is patchable with the commit specified in --patches",
type=str,
)
parser.add_argument(
"--patches",
nargs="*",
help="Which patch(es) to apply.",
type=str,
)
# ====================
mut_excl_group.add_argument(
"--find-introducer",
help="Try to find the introducer commit of a build failure.",
action="store_true",
)
parser.add_argument(
"-br", "--broken-revision", help="Which revision is borken", type=str
)
# ====================
return parser
def generator_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
"-a", "--amount", help="Amount of cases to generate.", type=int, default=0
)
parser.add_argument(
"--interesting",
help="If the generated case should be an interesting one.",
action=argparse.BooleanOptionalAction,
default=True,
)
parser.add_argument(
"-t",
"--targets",
help="Project name and revision of compiler to use.",
nargs="+",
type=str,
)
parser.add_argument(
"-tdol",
"--targets-default-opt-levels",
help="Default optimization levels for the target to be checked against.",
nargs="+",
default=[],
type=str,
)
parser.add_argument(
"-ac",
"--additional-compilers",
help="Additional compiler to compare the target against.",
nargs="*",
type=str,
)
parser.add_argument(
"-acdol",
"--additional-compilers-default-opt-levels",
help="Default optimization levels for the additional compilers to be checked against.",
nargs="+",
default=[],
type=str,
)
parser.add_argument("-s", "--scenario", help="Which scenario to work on.", type=str)
parser.add_argument(
"-p",
"--parallel",
help="Run the search in parallel for --parallel processes. Works only in combination with --interesting.",
type=int,
)
parser.add_argument(
"-d", "--output-directory", help="Where the cases should be saved to.", type=str
)
return parser
def checker_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(add_help=False)
group = parser.add_mutually_exclusive_group()
parser.add_argument(
"-f", "--file", help="Which file to work on.", type=str, required=True
)
parser.add_argument("-m", "--marker", help="Marker to check for.", type=str)
group.add_argument(
"-s",
"--scenario",
help="Which scenario to use as testing replacement.",
type=str,
)
group.add_argument(
"-is",
"--interesting-settings",
help="Which interesting settings to use.",
type=str,
)
parser.add_argument(
"-bad",
"--bad-settings",
help="Settings which are supposed to *not* eliminate the marker",
nargs="+",
type=str,
)
parser.add_argument(
"-bsdol",
"--bad-settings-default-opt-levels",
help="Default optimization levels for the bad-settings to be checked against.",
nargs="+",
default=[],
type=str,
)
parser.add_argument(
"-good",
"--good-settings",
help="Settings which are supposed to eliminate the marker",
nargs="+",
type=str,
)
parser.add_argument(
"-gsdol",
"--good-settings-default-opt-levels",
help="Default optimization levels for the good-settings to be checked against.",
nargs="+",
default=[],
type=str,
)
parser.add_argument(
"-cr",
"--check-reduced",
help="Instead of checking the original file, check the latest reduced code.",
action="store_true",
)
parser.add_argument(
"--check-pp",
help="Run the preprocessed version through the checker.",
action="store_true",
)
parser.add_argument(
"--dont-preprocess",
help="Force no preprocessing",
action="store_true",
)
return parser
def reducer_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("-f", "--file", help="Which file to work on.", type=str)
parser.add_argument(
"-g",
"--generate",
help="Whether or not to generate and reduce cases",
action="store_true",
)
parser.add_argument(
"--work-through",
help="Look at all cases found in directory specified in --output-directory and reduce them when they are not.",
action="store_true",
)
parser.add_argument("-s", "--scenario", help="Which scenario to work on.", type=str)
parser.add_argument(
"-a", "--amount", help="How many cases to find and reduce.", type=int, default=0
)
parser.add_argument(
"-d", "--output-directory", help="Where the cases should be saved to.", type=str
)
parser.add_argument(
"-t",
"--targets",
help="Project name and revision of compiler to use.",
nargs="+",
type=str,
)
parser.add_argument(
"-tdol",
"--targets-default-opt-levels",
help="Default optimization levels for the target to be checked against.",
nargs="+",
default=[],
type=str,
)
parser.add_argument(
"-ac",
"--additional-compilers",
help="Additional compiler to compare the target against.",
nargs="*",
type=str,
)
parser.add_argument(
"-acdol",
"--additional-compilers-default-opt-levels",
help="Default optimization levels for the additional compilers to be checked against.",
nargs="+",
default=[],
type=str,
)
parser.add_argument(
"--force",
help="Force another reduction even if one already exists.",
action="store_true",
)
parser.add_argument(
"-rr",
"--re-reduce",
help="Re-reduce the last reduce code",
action="store_true",
)
return parser
def bisector_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("-f", "--file", help="Which file to work on.", type=str)
parser.add_argument(
"-d", "--output-directory", help="Where the cases should be saved to.", type=str
)
parser.add_argument(
"-a", "--amount", help="How many cases to find and reduce.", type=int, default=0
)
parser.add_argument(
"-g",
"--generate",
help="Whether or not to generate, reduce and bisect cases",
action="store_true",
)
parser.add_argument("-s", "--scenario", help="Which scenario to work on.", type=str)
parser.add_argument(
"-t",
"--targets",
help="Project name and revision of compiler to use.",
nargs="+",
type=str,
)
parser.add_argument(
"-tdol",
"--targets-default-opt-levels",
help="Default optimization levels for the target to be checked against.",
nargs="+",
default=[],
type=str,
)
parser.add_argument(
"-ac",
"--additional-compilers",
help="Additional compiler to compare the target against.",
nargs="*",
type=str,
)
parser.add_argument(
"-acdol",
"--additional-compilers-default-opt-levels",
help="Default optimization levels for the additional compilers to be checked against.",
nargs="+",
default=[],
type=str,
)
parser.add_argument(
"--work-through",
help="Look at all cases found in directory specified in --output-directory and bisect them when they are not.",
action="store_true",
)
parser.add_argument(
"--force",
help="Force another bisection even if they already exist",
action="store_true",
)
parser.add_argument(
"--reducer",
help="If the generated case should be reduced or not.",
action=argparse.BooleanOptionalAction,
default=True,
)
return parser
def debugtool_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("-f", "--file", help="Which file to work on.", type=str)
parser.add_argument(
"-crb",
"--clean-reduced-bisections",
help="Delete all files related to reduction and bisection",
action="store_true",
)
parser.add_argument(
"--reduced",
help="Work on reduced files. (where applicable)",
action="store_true",
)
parser.add_argument(
"--preprocessed",
help="Work on preprocessed files. (where applicable)",
action="store_true",
)
parser.add_argument(
"--asm",
help="Get assembly for a case asmgood.s and asmbad.s",
action="store_true",
)
parser.add_argument(
"--static",
help="Get code where functions and global variables are static in static.c",
action="store_true",
)
# TODO: help information for --viz
parser.add_argument("--viz", help="", action="store_true")
parser.add_argument("--preprocess-code", help="", action="store_true")
parser.add_argument(
"-di", "--diagnose", help="Run general tests.", action="store_true"
)
parser.add_argument(
"--empty-marker-code",
help="Get empty marker body code in empty_body.c",
action="store_true",
)
return parser
def main_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(add_help=False)
subparser = parser.add_subparsers(title="sub", dest="sub")
run_parser = subparser.add_parser("run", help="Let DEAD search for cases.")
run_parser.add_argument(
"-d", "--output-directory", help="Where the cases should be saved to.", type=str
)
run_parser.add_argument(
"-a", "--amount", help="How many cases to find and reduce.", type=int, default=0
)
run_parser.add_argument(
"-s", "--scenario", help="Which scenario to work on.", type=str
)
run_parser.add_argument(
"-t",
"--targets",
help="Project name and revision of compiler to use.",
nargs="+",
type=str,
)
run_parser.add_argument(
"-tdol",
"--targets-default-opt-levels",
help="Default optimization levels for the target to be checked against.",
nargs="+",
default=[],
type=str,
)
run_parser.add_argument(
"-ac",
"--additional-compilers",
help="Additional compiler to compare the target against.",
nargs="*",
type=str,
)
run_parser.add_argument(
"-acdol",
"--additional-compilers-default-opt-levels",
help="Default optimization levels for the additional compilers to be checked against.",
nargs="+",
default=[],
type=str,
)
run_parser.add_argument(
"--reducer",
help="If the generated case should be reduced or not.",
action=argparse.BooleanOptionalAction,
default=None,
)
run_parser.add_argument(
"--bisector",
help="If the generated case should be bisected or not.",
action=argparse.BooleanOptionalAction,
default=True,
)
run_parser.add_argument(
"-pg",
"--parallel-generation",
action=argparse.BooleanOptionalAction,
default=True,
help="Run the case generation part in parallel. This will disable timing for the generation part.",
)
run_parser.add_argument(
"--update-trunk-after-X-hours",
help="Enable automatic updating target compilers which are at the current trunk after X hours of running.",
metavar="X",
type=int,
)
absorb_parser = subparser.add_parser(
"absorb", help="Read cases outside of the database into the database."
)
absorb_parser.add_argument(
"absorb_object",
metavar="DIR|FILE",
help="Directory or file to read .tar cases from into the database.",
)
report_parser = subparser.add_parser("report", help="Generate a report for a case.")
report_parser.add_argument(
"case_id",
metavar="CASE_ID",
type=int,
help="Generate a bug report for the given id.",
)
report_parser.add_argument(
"--pull",
help="Pull the repo to check against upsteam.",
action=argparse.BooleanOptionalAction,
default=False,
)
tofile_parser = subparser.add_parser(
"tofile",
help="Save a case from the database into a file. This is a LOSSY operation.",
)
tofile_parser.add_argument(
"case_id",
metavar="CASE_ID",
type=int,
help="Case to get a .tar from ",
)
rereduce_parser = subparser.add_parser(
"rereduce",
help="Reduce code from outside the database w.r.t. a specified case.",
)
rereduce_parser.add_argument(
"case_id",
metavar="CASE_ID",
type=int,
help="Case to work with.",
)
rereduce_parser.add_argument(
"code_path",
metavar="CODE_PATH",
type=str,
help="Path to code to rereduce",
)
diagnose_parser = subparser.add_parser(
"diagnose", help="Run tests on a specified case and print a summary."
)
diagnose_parser.add_argument(
"-ci",
"--case-id",
metavar="CASE_ID",
type=int,
help="Case to work with.",
)
diagnose_parser.add_argument(
"--file",
metavar="PATH",
type=str,
help="Path to case to work with",
)
diagnose_parser.add_argument(
"-t",
"--targets",
help="Option to override the bad setting/target of the case. Only the first specified target will be used!",
nargs="+",
type=str,
)
diagnose_parser.add_argument(
"-tdol",
"--targets-default-opt-levels",
help="Default optimization levels for the target that override the targets of the case.",
nargs="+",
default=[],
type=str,
)
diagnose_parser.add_argument(
"-ac",
"--additional-compilers",
help="Override the attacking compilers of the case.",
nargs="*",
type=str,
)
diagnose_parser.add_argument(
"-acdol",
"--additional-compilers-default-opt-levels",
help="Default optimization levels for the overriding attacking compilers.",
nargs="+",
default=[],
type=str,
)
diagnose_parser.add_argument("-s", "--scenario", help="", type=str)
checkreduced_parser = subparser.add_parser(
"checkreduced",
help="Check if code outside of the database passes the checks of a specified case.",
)
checkreduced_parser.add_argument(
"case_id",
metavar="CASE_ID",
type=int,
help="Case to work with.",
)
checkreduced_parser.add_argument(
"code_path",
metavar="CODE_PATH",
type=str,
help="Path to code to checkreduced",
)
cache_parser = subparser.add_parser("cache", help="Perform actions on the cache.")
cache_parser.add_argument(
"what",
choices=("clean", "stats"),
type=str,
help="What you want to do with the cache. Clean will search and remove all unfinished cache entries. `stats` will print some statistics about the cache.",
)
asm_parser = subparser.add_parser(
"asm",
help="Save assembly outputs (-S) for the good and bad settings for each code found in a case.",
)
asm_parser.add_argument(
"case_id",
metavar="CASE_ID",
type=int,
help="Case to work with.",
)
set_parser = subparser.add_parser("set", help="Set values of a case.")
get_parser = subparser.add_parser(
"get", help="Print values of a case to the command line."
)
get_parser.add_argument(
"what",
choices=("link", "fixed", "mcode", "rcode", "ocode", "bisection", "marker"),
type=str,
help="What you want to get. `ocode` is the original code. `rcode` is the reduced code. `mcode` is the massaged code. fixed is the commit the commit the case was `fixed` with and `link` the link to the bug report.",
)
get_parser.add_argument(
"case_id",
metavar="CASE_ID",
type=int,
help="Case from which to get what you chose",
)
set_parser.add_argument(
"what",
choices=("link", "fixed", "mcode", "rcode", "ocode", "bisection"),
type=str,
help="What you want to set. `ocode` is the original code. `rcode` is the reduced code. `mcode` is the massaged code. `fixed` is the commit the commit the case was fixed` with and `link` the link to the bug report. `ocode`, `rcode` and `mcode` expect files, `link`, `fixed` and `bisection` strings.",
)
set_parser.add_argument(
"case_id",
metavar="CASE_ID",
type=int,
help="Case to set the value of",
)
set_parser.add_argument(
"var",
metavar="VAR",
type=str,
help="What to set the chosen value to. Expected input may change based on what you are setting.",
)
build_parser = subparser.add_parser(
"build", help="Build a specific compiler version."
)
build_parser.add_argument(
"project",
choices=("gcc", "llvm", "clang"),
type=str,
help="Which compiler to build",
)
build_parser.add_argument(
"rev", nargs="+", type=str, help="Which revision(s)/commit(s) to build"
)
build_parser.add_argument(
"--force",
action=argparse.BooleanOptionalAction,
help="Whether or not to force another build.",
)
build_parser.add_argument(
"--add-patches",
help="Which patches to apply in addition to the ones found in patchDB",
nargs="+",
type=str,
)
reduce_parser = subparser.add_parser(
"reduce", help="Reduce the initially found code of a case."
)
reduce_parser.add_argument(
"case_id", nargs="+", type=int, help="Which case to reduce"
)
reduce_parser.add_argument(
"--force",
action=argparse.BooleanOptionalAction,
help="Whether or not to force another reduction. This will override the old reduced code.",
)
bisect_parser = subparser.add_parser(
"bisect", help="Find the bisection commit for a specified case."
)
bisect_parser.add_argument(
"case_id", nargs="+", type=int, help="Which case to bisect"
)
bisect_parser.add_argument(
"--force",
action=argparse.BooleanOptionalAction,
help="Whether or not to force another bisection. This will override the old bisection.",
)
edit_parser = subparser.add_parser("edit", help="Open DEADs config in $EDITOR.")
unreported_parser = subparser.add_parser(
"unreported", help="List cases which have not been reported or fixed."
)
unreported_parser.add_argument(
"--id-only",
action="store_true",
help="Print only the case ids. Useful for scripting.",
)
unrep_mut_ex_red = unreported_parser.add_mutually_exclusive_group()
unrep_mut_ex_red.add_argument(
"--not-reduced",
action="store_true",
help="If the listed cases should NOT be reduced",
)
unrep_mut_ex_red.add_argument(
"--reduced", action="store_true", help="If the listed cases should be reduced"
)
unrep_mut_ex = unreported_parser.add_mutually_exclusive_group()
# I'd call the options --gcc, --clang etc. but
# running ./main.py unreported --gcc will complain about ambiguity
# wrt to --gcc.repo etc. from the config.
# However when running ./main.py unreported --gcc.repo it is an unknown option
# as these flags are only parsed directly after ./main.py.
unrep_mut_ex.add_argument(
"--gcc-only", action="store_true", help="Print only GCC related bisections."
)
unrep_mut_ex.add_argument(
"--llvm-only",
action="store_true",
help="Print only LLVM related bisections. Same as --clang-only.",
)
unrep_mut_ex.add_argument(
"--clang-only",
action="store_true",
help="Print only clang related bisections. Same as --llvm-only.",
)
unreported_parser.add_argument(
"--OX-only",
type=str,
metavar="OPT_LEVEL",
help="Print only bisections with OPT_LEVEL as bad setting.",
)
unreported_parser.add_argument(
"--good-version",
type=str,
metavar="REV",
help="Print only bisections which have REV as a good compiler matching the opt level of the bad compiler.",
)
reported_parser = subparser.add_parser(
"reported", help="List cases which have been reported."
)
reported_parser.add_argument(
"--id-only",
action="store_true",
help="Print only the case ids. Useful for scripting.",
)
rep_mut_ex = reported_parser.add_mutually_exclusive_group()
rep_mut_ex.add_argument(
"--gcc-only", action="store_true", help="Print only GCC related bisections."
)
rep_mut_ex.add_argument(
"--llvm-only",
action="store_true",
help="Print only LLVM related bisections. Same as --clang-only.",
)
rep_mut_ex.add_argument(
"--clang-only",
action="store_true",
help="Print only clang related bisections. Same as --llvm-only.",
)
reported_parser.add_argument(
"--good-settings",
action="store_true",
help="Print the good settings of the cases.",
)
findby_parser = subparser.add_parser(
"findby", help="Find case IDs given only a part of a case."
)
findby_parser.add_argument(
"what",
type=str,
choices=("link", "case", "code", "fixed"),
)
findby_parser.add_argument(
"var",
type=str,
metavar="VAR",
help="Is a string, when choosing link or fixed, is a path when choosing case or code.",
)
return parser