-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathBugId.py
1309 lines (1275 loc) · 63.8 KB
/
BugId.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
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ____________________________________________________________________________
# __
# ││▌║█▐▐║▌▌█│║║│ _,siSP**YSis,_ ╒╦╦══╦╗ ╒╦╦╕ ╔╦╕
# ││▌║█▐▐║▌▌█│║║│ ,SP*'` . `'*YS, ║╠══╬╣ ╔╗ ╔╗ ╔╦═╦╗ ║║ ╔╦═╬╣
# ╵2808197631337╵ dS' _ | _ 'Sb ╘╩╩══╩╝ ╚╩═╩╝ ╚╩═╬╣ ╘╩╩╛ ╚╩═╩╝
# dP \,-` `-<` ` Y; ╚╩═╩╝ ╮╷╭
# ╮╷╭ ,S` \+' \ \ `Sissssssssssssssssssss, :O() ╲ö╱
# :O() (S ( | --====) :SSSSSSSSSSSSSSSSSSSSSSD ╯╵╰ ─O─
# ╯╵╰ ╮╷╭ 'S, /+, / / ,S?********************' ╱O╲
# ()O: Yb _/'-_ _-<._. dP
# ╯╵╰ YS, | ,SP https://bugid.skylined.nl
# ____________________`Sbs,_ ' _,sdS`______________________________________
# `'*YSissiSY*'`
# ``
import json, os, re, sys, time;
sModulePath = os.path.dirname(__file__);
sys.path = [sModulePath] + [sPath for sPath in sys.path if sPath.lower() != sModulePath.lower()];
from fInitializeProduct import fInitializeProduct;
fInitializeProduct();
try: # mDebugOutput use is Optional
import mDebugOutput as m0DebugOutput;
except ModuleNotFoundError as oException:
if oException.args[0] != "No module named 'mDebugOutput'":
raise;
m0DebugOutput = None;
guExitCodeInternalError = 1; # Just in case mExitCodes is not loaded, as we need this later.
gbPauseBeforeExit = False; # will be set to true when we are handling a JIT event:
# the console will be closed when we exit and we want the
# user to be able to see the error.
try:
# Load the stuff from external modules that we need.
from mBugId import cBugId;
from mDateTime import cDateTime, cDateTimeDuration;
from mFileSystemItem import cFileSystemItem;
import mProductDetails, mWindowsAPI;
from ddxApplicationSettings_by_sKeyword import ddxApplicationSettings_by_sKeyword;
from dxConfig import dxConfig;
from fApplicationDebugOutputCallbackHandler import fApplicationDebugOutputCallbackHandler;
from fApplicationMaxRunTimeCallbackHandler import fApplicationMaxRunTimeCallbackHandler;
from fApplicationResumedCallbackHandler import fApplicationResumedCallbackHandler;
from fApplicationRunningCallbackHandler import fApplicationRunningCallbackHandler;
from fApplicationStdErrOutputCallbackHandler import fApplicationStdErrOutputCallbackHandler;
from fApplicationStdOutOutputCallbackHandler import fApplicationStdOutOutputCallbackHandler;
from fApplicationSuspendedCallbackHandler import fApplicationSuspendedCallbackHandler;
from fASanDetectedCallbackHandler import fASanDetectedCallbackHandler;
from fatsArgumentLowerNameAndValue import fatsArgumentLowerNameAndValue;
from fbApplyConfigSetting import fbApplyConfigSetting;
from fbInstallAsJITDebugger import fbInstallAsJITDebugger;
from fCdbCommandStartedExecutingCallbackHandler import fCdbCommandStartedExecutingCallbackHandler;
from fCdbCommandFinishedExecutingCallbackHandler import fCdbCommandFinishedExecutingCallbackHandler;
from fCdbStdErrOutputCallbackHandler import fCdbStdErrOutputCallbackHandler;
from fCdbStdInInputCallbackHandler import fCdbStdInInputCallbackHandler;
from fCdbStdOutOutputCallbackHandler import fCdbStdOutOutputCallbackHandler;
from fCheckPythonVersion import fCheckPythonVersion;
from fCollateralCannotIgnoreBugCallbackHandler import fCollateralCannotIgnoreBugCallbackHandler;
from fCollateralBugIgnoredCallbackHandler import fCollateralBugIgnoredCallbackHandler;
from fdsGetAdditionalVersionByName import fdsGetAdditionalVersionByName;
from fiCollateralInteractiveAskForValue import fiCollateralInteractiveAskForValue;
from fLogMessageCallbackHandler import fLogMessageCallbackHandler;
from foConsoleLoader import foConsoleLoader;
from fOutputApplicationKeyWordHelp import fOutputApplicationKeyWordHelp;
from fOutputCurrentJITDebuggerSettings import fOutputCurrentJITDebuggerSettings;
from fOutputExceptionInformation import fOutputExceptionInformation;
from fOutputMessageForProcess import fOutputMessageForProcess;
from fProcessStartedCallbackHandler import fProcessStartedCallbackHandler;
from fProcessTerminatedCallbackHandler import fProcessTerminatedCallbackHandler;
from mColorsAndChars import *;
from mExitCodes import *;
oConsole = foConsoleLoader();
def fxProcessBooleanArgument(sArgumentName, s0Value, u0CanAlsoBeAnIntegerLargerThan = None):
if s0Value is None or s0Value.lower() == "true":
return True;
if s0Value.lower() == "false":
return False;
if u0CanAlsoBeAnIntegerLargerThan is not None:
try:
uValue = int(s0Value);
except:
pass;
else:
if uValue > u0CanAlsoBeAnIntegerLargerThan:
return uValue;
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The value for ",
COLOR_INFO, sArgumentName,
COLOR_NORMAL, " must be \"",
COLOR_INFO, "true",
COLOR_NORMAL, "\" (default) or \"",
COLOR_INFO, "false",
COLOR_NORMAL, "\"",
[
" or an integer larger than ", COLOR_INFO, str(u0CanAlsoBeAnIntegerLargerThan), COLOR_NORMAL,
] if u0CanAlsoBeAnIntegerLargerThan is not None else [],
".",
);
fTerminate(guExitCodeBadArgument);
def fTerminateIfNoArgumentValueProvided(sArgumentName, s0Value, sExpectedValueType):
if not s0Value:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The value for ",
COLOR_INFO, sArgumentName,
COLOR_NORMAL, " must contain ", sExpectedValueType, ".",
);
fTerminate(guExitCodeBadArgument);
if __name__ == "__main__":
asTestedPythonVersions = ["3.8.5", "3.9.1", "3.9.7", "3.10.0", "3.11.1", "3.11.4", "3.12.0"];
gasAttachForProcessExecutableNames = [];
gasLowercaseBinaryNamesThatAreAllowedToRunWithoutPageHeap = [
"conhost.exe", # Used to create console windows, not part of the target application (unless the target is conhost)
];
gasReportedLowercaseBinaryNamesWithoutPageHeap = [];
gasBinaryNamesThatAreAllowedToRunWithNonIdealCdbISA = [
# No application is known to require running processes with a non-ideal cdb ISA at this point.
];
gasReportedBinaryNameWithNonIdealCdbISA = [];
gbAnInternalErrorOccurred = False;
gbFailedToApplyMemoryLimitsErrorShown = False;
gbSaveDump = False;
gbSaveFullDump = False;
guDetectedBugsCount = 0;
guNumberOfTimesToRunTheApplication = 1;
gu0MaximumNumberOfBugsEachRun = 1;
gduNumberOfRepros_by_sBugIdAndLocation = {};
gbSaveOutputWithReport = False;
gbRunningAsJITDebugger = False;
# o0Parent can be used without checking for None because every file has a parent:
goInternalErrorReportsFolder = cFileSystemItem(__file__).o0Parent.foGetChild("Internal error reports");
goBugIdStartDateTime = cDateTime.foNow();
def fsGetFileName(sFileNamesBase):
# Translate characters that are not valid in file names.
# Optionally add the BugId start date as a prefix.
return cFileSystemItem.fsGetValidName(
sFileNamesBase.replace("{timestamp}", goBugIdStartDateTime.fsToString()),
bUseUnicodeHomographs = dxConfig["bUseUnicodeReportFileNames"],
);
def fTerminate(uExitCode):
oConsole.fCleanup();
if gbPauseBeforeExit:
oConsole.fOutput("Press ENTER to quit...");
input();
os._exit(uExitCode);
def fFailedToDebugApplicationCallback(oBugId, sErrorMessage):
global gbAnInternalErrorOccurred;
gbAnInternalErrorOccurred = True;
oConsole.fLock();
try:
oConsole.fOutput("┌───[", COLOR_ERROR, " Failed to debug the application ", COLOR_NORMAL, "]", sPadding = "─");
for sLine in sErrorMessage.split("\n"):
oConsole.fOutput("│ ", COLOR_INFO, sLine.rstrip("\r"));
oConsole.fOutput("└", sPadding = "─");
oConsole.fOutput();
finally:
oConsole.fUnlock();
def fFailedToApplyApplicationMemoryLimitsCallback(oBugId, oProcess, bIsMainProcess):
global gbFailedToApplyMemoryLimitsErrorShown;
if not dxConfig["bQuiet"]:
fOutputMessageForProcess(
COLOR_ERROR, CHAR_ERROR,
oProcess, bIsMainProcess,
"Cannot apply application memory limits",
);
gbFailedToApplyMemoryLimitsErrorShown = True;
if not dxConfig["bVerbose"]:
oConsole.fOutput(" Any additional failures to apply memory limits to processes will not be shown.");
def fFailedToApplyProcessMemoryLimitsCallback(oBugId, oProcess, bIsMainProcess):
global gbFailedToApplyMemoryLimitsErrorShown;
if dxConfig["bVerbose"] or not gbFailedToApplyMemoryLimitsErrorShown:
fOutputMessageForProcess(
COLOR_ERROR, CHAR_ERROR,
oProcess, bIsMainProcess,
"Cannot apply process memory limits",
);
gbFailedToApplyMemoryLimitsErrorShown = True;
if not dxConfig["bVerbose"]:
oConsole.fOutput(" Any additional failures to apply memory limits to processes will not be shown.");
def fInternalExceptionCallback(oBugId, oThread, oException, oTraceBack):
global gbAnInternalErrorOccurred;
gbAnInternalErrorOccurred = True;
fSaveInternalExceptionReportAndTerminate(oException, oTraceBack);
def fSaveInternalExceptionReportAndTerminate(oException, oTraceBack):
fOutputExceptionInformation(oException, oTraceBack);
rErrorReportFileName = re.compile(
r"\A"
r"\d{4}.\d\d.\d\d " r"\d\d.\d\d.\d\d(?:.\d+)? " # Date Time
r"BugId error report #(\d+)\.txt" # Name #<number>
r"\Z"
);
uIndex = 1;
if not goInternalErrorReportsFolder.fbIsFolder:
if not goInternalErrorReportsFolder.fbCreateAsFolder(bCreateParents = True):
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The internal error report folder ",
COLOR_INFO, goInternalErrorReportsFolder.sPath,
COLOR_NORMAL, " cannot be created.",
);
else:
# Scan for previous error reports, so we can number them:
a0oPotentialOlderErrorReports = goInternalErrorReportsFolder.fa0oGetChildren(bThrowErrors = False);
if a0oPotentialOlderErrorReports is None:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The internal error report folder ",
COLOR_INFO, goInternalErrorReportsFolder.sPath,
COLOR_NORMAL, " cannot be read.",
);
else:
for oPotentialOlderErrorReport in a0oPotentialOlderErrorReports:
oErrorReportFileNameMatch = rErrorReportFileName.match(oPotentialOlderErrorReport.sName);
if oErrorReportFileNameMatch:
uExistingIndex = int(oErrorReportFileNameMatch.group(1));
if uExistingIndex >= uIndex:
uIndex = uExistingIndex + 1;
sExceptionReportFileName = fsGetFileName(
"{timestamp} BugId error report #%d.txt" % uIndex,
);
oExceptionReportFile = goInternalErrorReportsFolder.foGetChild(sExceptionReportFileName);
oConsole.fStatus(
COLOR_BUSY, CHAR_BUSY,
COLOR_NORMAL, " Creating a copy of the error report in ",
COLOR_INFO, oExceptionReportFile.sPath,
COLOR_NORMAL, "...",
);
assert oConsole.fbCopyOutputToFilePath(oExceptionReportFile.sPath, bOverwrite = True, bThrowErrors = True), \
"UNREACHABLE CODE (bThrowErrors = True)";
oConsole.fOutput(
COLOR_OK, CHAR_OK,
COLOR_NORMAL, " A copy of the error report can be found in ",
COLOR_INFO, oExceptionReportFile.sPath,
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeInternalError);
def fLicenseErrorsCallback(oBugId, asErrors):
# These should have been reported before cBugId was even instantiated, so this is kind of unexpected.
# But rather than raise AssertionError("NOT REACHED"), we'll report the license error gracefully:
global gbAnInternalErrorOccurred;
gbAnInternalErrorOccurred = True;
oConsole.fLock();
try:
oConsole.fOutput("┌───[", COLOR_INFO, " Software license error ", COLOR_NORMAL, "]", sPadding = "─");
for sError in asErrors:
oConsole.fOutput("│ ", COLOR_INFO, sError);
oConsole.fOutput("└", sPadding = "─");
finally:
oConsole.fUnlock();
fTerminate(guExitCodeLicenseError);
def fLicenseWarningsCallback(oBugId, asWarnings):
# These were already reported when BugId started; ignore them.
pass;
def fCdbISANotIdealCallback(oBugId, oProcess, bIsMainProcess, sCdbISA, bPreventable):
global \
gasBinaryNamesThatAreAllowedToRunWithNonIdealCdbISA, \
gasReportedBinaryNameWithNonIdealCdbISA, \
gbAnInternalErrorOccurred;
sBinaryName = oProcess.sBinaryName;
if sBinaryName.lower() in gasBinaryNamesThatAreAllowedToRunWithNonIdealCdbISA:
return;
if not bPreventable:
if not dxConfig["bQuiet"] and sBinaryName not in gasReportedBinaryNameWithNonIdealCdbISA:
gasReportedBinaryNameWithNonIdealCdbISA.append(sBinaryName);
oConsole.fLock();
try:
oConsole.fOutput(
COLOR_WARNING, CHAR_WARNING,
COLOR_NORMAL, " You are debugging an ",
COLOR_INFO, oProcess.sISA,
COLOR_NORMAL, " process running ",
COLOR_INFO, sBinaryName,
COLOR_NORMAL, " with a ",
COLOR_INFO, sCdbISA,
COLOR_NORMAL, " cdb.exe.",
);
oConsole.fOutput(" This appears to be due to the application running both x86 and x64 processes.");
oConsole.fOutput(" Unfortunately, this means use-after-free bugs in this process may be reported");
oConsole.fOutput(" as attempts to access reserved memory regions, which is technically true but");
oConsole.fOutput(" not as accurate as you might expect.");
oConsole.fOutput();
finally:
oConsole.fUnlock();
else:
gbAnInternalErrorOccurred = True;
oConsole.fLock();
try:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You are debugging an ",
COLOR_INFO, oProcess.sISA,
COLOR_NORMAL, " process running ",
COLOR_INFO, sBinaryName,
COLOR_NORMAL, " with a ",
COLOR_INFO, sCdbISA,
COLOR_NORMAL, " version of cdb.exe.",
);
oConsole.fOutput(
" You should use the ",
COLOR_INFO, "--isa=", oProcess.sISA, COLOR_NORMAL,
" command line argument to let BugId know it should be using a ",
COLOR_INFO, oProcess.sISA,
COLOR_NORMAL, " version of cdb.exe.");
oConsole.fOutput(" Please restart BugId with the above command line argument to try again.");
oConsole.fOutput();
oConsole.fStatus(COLOR_BUSY, CHAR_BUSY, COLOR_NORMAL, " BugId is stopping...");
finally:
oConsole.fUnlock();
# There is no reason to run without page heap, so terminated.
oBugId.fStop();
# If you really want to run without page heap, set `dxConfig["cBugId"]["bEnsurePageHeap"]` to `False` in
# `dxConfig.py`or run with the command-line switch `--cBugId.bEnsurePageHeap=false`
def fPageHeapNotEnabledCallback(oBugId, oProcess, bIsMainProcess, bPreventable):
global \
gasLowercaseBinaryNamesThatAreAllowedToRunWithoutPageHeap, \
gasReportedLowercaseBinaryNamesWithoutPageHeap;
sLowerBinaryName = oProcess.sBinaryName.lower();
if (
dxConfig["bQuiet"]
or sLowerBinaryName in gasLowercaseBinaryNamesThatAreAllowedToRunWithoutPageHeap
or sLowerBinaryName in gasReportedLowercaseBinaryNamesWithoutPageHeap
):
return;
gasReportedLowercaseBinaryNamesWithoutPageHeap.append(sLowerBinaryName);
oConsole.fLock();
try:
oConsole.fOutput(
COLOR_WARNING, CHAR_WARNING,
COLOR_NORMAL, " Full page heap is not enabled for ",
COLOR_INFO, oProcess.sBinaryName,
COLOR_NORMAL, " in process ",
COLOR_INFO, "%s" % oProcess.uId,
COLOR_NORMAL, "/",
COLOR_INFO, "0x%X" % oProcess.uId,
COLOR_NORMAL, ".",
);
if bPreventable:
oConsole.fOutput(" Without page heap enabled, detection and analysis of any bugs will be sub-");
oConsole.fOutput(" optimal. Please enable page heap to improve detection and analysis.");
oConsole.fOutput();
oConsole.fOutput(" You can enable full page heap for ", sLowerBinaryName, " by running:");
oConsole.fOutput();
oConsole.fOutput(" ", COLOR_INFO, 'PageHeap.cmd "', oProcess.sBinaryName, '" ON');
else:
oConsole.fOutput(" This appears to be due to a bug in page heap that prevents it from");
oConsole.fOutput(" determining the binary name correctly. Unfortunately, there is no known fix");
oConsole.fOutput(" or work-around for this. BugId will continue, but detection and analysis of");
oConsole.fOutput(" any bugs in this process will be sub-optimal.");
oConsole.fOutput();
finally:
oConsole.fUnlock();
def fProcessAttachedCallback(oBugId, oProcess, bIsMainProcess):
global gasAttachForProcessExecutableNames;
if not dxConfig["bQuiet"]: # Main processes
fOutputMessageForProcess(
COLOR_ADD, CHAR_ADD,
oProcess, bIsMainProcess,
"Attached (",
COLOR_INFO, oProcess.sCommandLine or "command line unknown",
COLOR_NORMAL, ").",
);
# Now is a good time to look for additional binaries that may need to be debugged as well.
if gasAttachForProcessExecutableNames:
oBugId.fAttachForProcessExecutableNames(*gasAttachForProcessExecutableNames);
def fBugReportCallback(oBugId, oBugReport):
global guDetectedBugsCount, \
gu0MaximumNumberOfBugsEachRun, \
gduNumberOfRepros_by_sBugIdAndLocation, \
gbAnInternalErrorOccurred;
guDetectedBugsCount += 1;
oConsole.fLock();
try:
oConsole.fOutput("┌───[", COLOR_HILITE, " A bug was detected ", COLOR_NORMAL, "]", sPadding = "─");
if oBugReport.s0BugLocation:
oConsole.fOutput("│ Id @ Location: ", COLOR_INFO, oBugReport.sId, COLOR_NORMAL, " @ ", COLOR_INFO, oBugReport.s0BugLocation);
sBugIdAndLocation = "%s @ %s" % (oBugReport.sId, oBugReport.s0BugLocation);
else:
oConsole.fOutput("│ Id: ", COLOR_INFO, oBugReport.sId);
sBugIdAndLocation = oBugReport.sId;
gduNumberOfRepros_by_sBugIdAndLocation.setdefault(sBugIdAndLocation, 0);
gduNumberOfRepros_by_sBugIdAndLocation[sBugIdAndLocation] += 1;
if oBugReport.sBugSourceLocation:
oConsole.fOutput("│ Source: ", COLOR_INFO, oBugReport.sBugSourceLocation);
oConsole.fOutput("│ Description: ", COLOR_INFO, oBugReport.s0BugDescription or "None provided");
oConsole.fOutput("│ Security impact: ", COLOR_INFO, (oBugReport.s0SecurityImpact or "None"));
if oBugReport.asVersionInformation:
oConsole.fOutput("│ Version: ", COLOR_NORMAL, oBugReport.asVersionInformation[0]); # The process' binary.
for sVersionInformation in oBugReport.asVersionInformation[1:]: # There may be two if the crash was in a
oConsole.fOutput("│ ", COLOR_NORMAL, sVersionInformation); # different binary (e.g. a .dll)
if dxConfig["bGenerateReportHTML"]:
# Use a report file name base on the BugId.
# In collateral mode, we will number the reports, so they can more easily be ordered chronologically.
bCountBugs = (
gu0MaximumNumberOfBugsEachRun is None
or gu0MaximumNumberOfBugsEachRun > 1
or guNumberOfTimesToRunTheApplication > 1
);
sOutputFileNamesHeader = "".join([
# guDetectedBugsCount has already been increased from zero, so the first file will be "#1"
("#%d " % guDetectedBugsCount) if bCountBugs else "",
sBugIdAndLocation,
]);
sReportFileName = fsGetFileName(
"%s%s.html" % (
# In JIT mode and when counting bugs we prefix the report with the date and time.
"{timestamp} " if (gbRunningAsJITDebugger or bCountBugs) else "",
sOutputFileNamesHeader,
),
);
if dxConfig["sReportFolderPath"] is not None:
oReportFile = cFileSystemItem(dxConfig["sReportFolderPath"]).foGetChild(sReportFileName);
else:
oReportFile = cFileSystemItem(sReportFileName);
oConsole.fStatus(
COLOR_BUSY, CHAR_BUSY,
COLOR_NORMAL, " Saving bug report ",
COLOR_INFO, oReportFile.sPath,
COLOR_NORMAL, "...",
);
try:
sbReportHTML = bytes(oBugReport.sReportHTML, "utf-8", "strict");
if oReportFile.fbIsFile():
oReportFile.fWrite(sbReportHTML);
else:
oReportFile.fCreateAsFile(sbReportHTML, bCreateParents = True);
except Exception as oException:
oConsole.fOutput(
COLOR_NORMAL, "│ ",
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " Bug report: ",
COLOR_INFO, oReportFile.sPath,
COLOR_NORMAL, "could not be saved!",
);
oConsole.fOutput(
COLOR_NORMAL, "│ => ",
COLOR_INFO, str(oException),
);
gbAnInternalErrorOccurred = True;
else:
oConsole.fOutput(
COLOR_NORMAL, "│ Bug report: ",
COLOR_INFO, oReportFile.sName,
COLOR_NORMAL, ".",
);
if gbSaveOutputWithReport:
# We want the BugId output file to be stored in the same folder as the bug report,
# with a similar file name, so where to store it is determined in a very similar way:
sBugIdOutputFileName = fsGetFileName(
"%s%s BugId output.txt" % (
"{timestamp} " if (gbRunningAsJITDebugger or bCountBugs) else "",
sOutputFileNamesHeader,
),
);
if dxConfig["sReportFolderPath"] is not None:
oBugIdOutputFile = cFileSystemItem(dxConfig["sReportFolderPath"]).foGetChild(sBugIdOutputFileName);
else:
oBugIdOutputFile = cFileSystemItem(sBugIdOutputFileName);
oConsole.fStatus(
COLOR_BUSY, CHAR_BUSY,
COLOR_NORMAL, " Saving BugId output log ",
COLOR_INFO, oBugIdOutputFile.sPath,
COLOR_NORMAL, "...",
);
try:
oConsole.fbCopyOutputToFilePath(oBugIdOutputFile.sWindowsPath);
except Exception as oException:
oConsole.fCleanup();
oConsole.fOutput("│ ", COLOR_ERROR, CHAR_ERROR, COLOR_NORMAL, " BugId output: ", oBugIdOutputFile.sPath, COLOR_ERROR, "could not be saved!");
oConsole.fOutput("│ => ", COLOR_INFO, str(oException));
gbAnInternalErrorOccurred = True;
else:
oConsole.fOutput("│ BugId output log: ", COLOR_INFO, oBugIdOutputFile.sPath, COLOR_NORMAL, ".");
if gbSaveDump:
# We want the debugger dump file to be stored in the same folder as the bug report,
# with a similar file name, so where to store it is determined in a very similar way:
sDebuggerDumpFileName = fsGetFileName(
"%s%s.dmp" % (
"{timestamp} " if (gbRunningAsJITDebugger or bCountBugs) else "",
sOutputFileNamesHeader,
),
);
# Because of limitations in cdb.exe, we can only use ASCII chars in the file name
# all non-ASCII chars will be replaced with ".":
sDebuggerDumpASCIIFileName = "".join([
sChar if 0x20 <= ord(sChar) < 0x7F else "."
for sChar in sDebuggerDumpFileName
]);
if dxConfig["sReportFolderPath"] is not None:
oDebuggerDumpFile = cFileSystemItem(dxConfig["sReportFolderPath"]).foGetChild(sDebuggerDumpASCIIFileName);
else:
oDebuggerDumpFile = cFileSystemItem(sDebuggerDumpASCIIFileName);
oConsole.fStatus(
COLOR_BUSY, CHAR_BUSY,
COLOR_NORMAL, " Saving dump file ",
COLOR_INFO, oDebuggerDumpFile.sPath,
COLOR_NORMAL, "...",
);
oBugId.fSaveDumpToFile(oDebuggerDumpFile.sPath, True, gbSaveFullDump);
oConsole.fOutput("│ Dump file: ", COLOR_INFO, oDebuggerDumpFile.sPath, COLOR_NORMAL, ".");
oConsole.fOutput("└", sPadding = "─");
finally:
oConsole.fUnlock();
def fMain():
global \
gasAttachForProcessExecutableNames, \
gasLowercaseBinaryNamesThatAreAllowedToRunWithoutPageHeap, \
gbSaveDump, \
gbSaveFullDump, \
guDetectedBugsCount, \
guNumberOfTimesToRunTheApplication, \
gu0MaximumNumberOfBugsEachRun, \
gbSaveOutputWithReport;
# Make sure Windows and the Python binary are up to date; we don't want our users to unknowingly run outdated
# software as this is likely to cause unexpected issues.
if mWindowsAPI.oSystemInfo.sOSVersion != "10.0":
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " BugId only runs on Windows 10.",
);
fTerminate(guExitCodeBadDependencyError);
if mWindowsAPI.oSystemInfo.sOSISA == "x64" and mWindowsAPI.fsGetPythonISA() == "x86":
oConsole.fLock();
try:
oConsole.fOutput("┌───[", COLOR_WARNING, " Warning ", COLOR_NORMAL, "]", sPadding = "─");
oConsole.fOutput(
"│ You are running a ",
COLOR_INFO, "32-bit",
COLOR_NORMAL, " version of Python on a ",
COLOR_INFO, "64-bit",
COLOR_NORMAL, " version of Windows.",
);
oConsole.fOutput(
"│ BugId will not be able to debug 64-bit applications unless you run it in a 64-bit version of Python.",
);
oConsole.fOutput(
"│ If you experience any issues, use a 64-bit version of Python and try again.",
);
oConsole.fOutput("└", sPadding = "─");
finally:
oConsole.fUnlock();
# Parse all arguments until we encounter "--".
s0ApplicationKeyword = None;
s0ApplicationBinaryPath = None;
auApplicationProcessIds = [];
u0JITDebuggerEventId = None;
o0UWPApplication = None;
asApplicationOptionalArguments = [];
sApplicationISA = None;
bRepeatForever = False;
uNumberOfTimesTheApplicationHasBeenRun = 0;
dxUserProvidedConfigSettings = {};
bDoNotLoadSymbols = False;
asAdditionalLocalSymbolPaths = [];
bFast = False;
a0sJITDebuggerArguments = None;
for (sArgument, s0LowerName, s0Value) in fatsArgumentLowerNameAndValue(fdsGetAdditionalVersionByName):
if a0sJITDebuggerArguments is not None:
# Stop processing arguments after "-I"
a0sJITDebuggerArguments.append(sArgument);
continue;
if s0LowerName in ["q", "quiet"]:
dxConfig["bQuiet"] = fxProcessBooleanArgument(s0LowerName, s0Value);
elif s0LowerName in ["v", "verbose"]:
dxConfig["bVerbose"] = fxProcessBooleanArgument(s0LowerName, s0Value);
elif s0LowerName in ["p", "pause"]:
gbPauseBeforeExit = fxProcessBooleanArgument(s0LowerName, s0Value);
elif s0LowerName in ["f", "fast", "quick"]:
bFast = fxProcessBooleanArgument(s0LowerName, s0Value);
elif s0LowerName in ["r", "repeat", "forever"]:
xValue = fxProcessBooleanArgument(s0LowerName, s0Value, u0CanAlsoBeAnIntegerLargerThan = 1 if s0LowerName != "forever" else None);
if isinstance(xValue, bool):
bRepeatForever = xValue;
else:
bRepeatForever = False;
guNumberOfTimesToRunTheApplication = xValue;
elif s0LowerName in ["d", "dump", "full-dump"]:
if fxProcessBooleanArgument(s0LowerName, s0Value):
gbSaveDump = True;
if s0LowerName in ["full-dump"]:
gbSaveFullDump = True; # --full-dump[=true] enables dump & full dump
elif s0LowerName in ["full-dump"]:
gbSaveFullDump = False; # --full-dump=false disables full dump only (not dump)
else:
gbSaveDump = False;
elif s0LowerName in ["i"]:
if s0Value is not None:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The option ",
COLOR_INFO, sArgument,
COLOR_NORMAL, " does not accept a value.",
)
fTerminate(guExitCodeBadArgument);
# Install as JIT Debugger. Remaining arguments are passed on the command line to the JIT debugger.
a0sJITDebuggerArguments = []; # Remaining arguments will be added to this list.
elif s0LowerName in ["c", "collateral"]:
if s0Value is None:
gu0MaximumNumberOfBugsEachRun = None;
elif s0Value == "?":
gu0MaximumNumberOfBugsEachRun = None;
dxConfig["bInteractive"] = True;
else:
# `--collateral=2` means one collateral bug in addition to the first bug.
try:
gu0MaximumNumberOfBugsEachRun = int(s0Value);
assert gu0MaximumNumberOfBugsEachRun > 0;
except:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The value for ",
COLOR_INFO, sArgument,
COLOR_NORMAL, " must be empty or an integer larger than ",
COLOR_INFO, "0",
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
elif s0LowerName in ["pid", "pids"]:
if not s0Value:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The value for ",
COLOR_INFO, sArgument,
COLOR_NORMAL, " must contain at least one process id.",
);
fTerminate(guExitCodeBadArgument);
if s0ApplicationBinaryPath is not None:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide both an application binary and process ids.",
);
fTerminate(guExitCodeBadArgument);
if o0UWPApplication is not None:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide both UWP application details and process ids.",
);
fTerminate(guExitCodeBadArgument);
for sPid in s0Value.split(","):
try:
uProcessId = int(sPid);
if uProcessId <= 0 or uProcessId % 4 != 0:
raise ValueError();
auApplicationProcessIds.append(uProcessId);
except ValueError:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The value for ",
COLOR_INFO, sArgument,
COLOR_NORMAL, " must contain a list of comma separated process ids and ",
COLOR_INFO, repr(sPid),
COLOR_NORMAL, " is not a valid process id.",
);
fTerminate(guExitCodeBadArgument);
elif s0LowerName in ["handle-jit-event"]:
fTerminateIfNoArgumentValueProvided(s0LowerName, s0Value, "a JIT debugger event id");
try:
u0JITDebuggerEventId = int(s0Value);
except ValueError:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The value for ",
COLOR_INFO, sArgument,
COLOR_NORMAL, " must contain a JIT debugger event id and ",
COLOR_INFO, repr(s0Value),
COLOR_NORMAL, " is not a valid event id.",
);
fTerminate(guExitCodeBadArgument);
elif s0LowerName in ["uwp", "uwp-app"]:
if not s0Value:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You must provide UWP application details.",
);
fTerminate(guExitCodeBadArgument);
if o0UWPApplication is not None:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide UWP application details more than once.",
);
fTerminate(guExitCodeBadArgument);
if s0ApplicationBinaryPath is not None:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide an application binary and UWP application details.",
);
fTerminate(guExitCodeBadArgument);
if len(auApplicationProcessIds) > 0:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide process ids and UWP application details.",
);
fTerminate(guExitCodeBadArgument);
tsUWPApplicationPackageNameAndId = s0Value.split("!", 1);
sUWPApplicationPackageName = tsUWPApplicationPackageNameAndId[0];
sUWPApplicationId = tsUWPApplicationPackageNameAndId[1] if len(tsUWPApplicationPackageNameAndId) == 2 else None;
o0UWPApplication = mWindowsAPI.cUWPApplication(sUWPApplicationPackageName, sUWPApplicationId);
elif s0LowerName in ["jit"]:
fOutputCurrentJITDebuggerSettings();
fTerminate(guExitCodeSuccess);
elif s0LowerName in ["log-output"]:
gbSaveOutputWithReport = fxProcessBooleanArgument(s0LowerName, s0Value);
elif s0LowerName in ["isa", "cpu"]:
if not s0Value:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You must provide an Instruction Set Architecture.",
);
fTerminate(guExitCodeBadArgument);
if s0Value not in ["x86", "x64"]:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " Unknown Instruction Set Architecture ", repr(s0Value),
);
fTerminate(guExitCodeBadArgument);
sApplicationISA = s0Value;
elif s0LowerName in ["symbols"]:
if s0Value is None or not cFileSystemItem(s0Value).fbIsFolder():
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The value for ",
COLOR_INFO, sArgument,
COLOR_NORMAL, " must be a valid folder path.",
);
fTerminate(guExitCodeBadArgument);
asAdditionalLocalSymbolPaths.append(s0Value);
elif s0LowerName in ["no-symbols"]:
bDoNotLoadSymbols = fxProcessBooleanArgument(s0LowerName, s0Value);
elif s0LowerName in ["report", "reports", "report-folder", "reports-folder", "report-folder-path", "reports-folder-path"]:
if s0Value is None:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The value for ",
COLOR_INFO, sArgument,
COLOR_NORMAL, " must be a valid folder path.",
);
fTerminate(guExitCodeBadArgument);
oReportFolder = cFileSystemItem(s0Value);
if (
not oReportFolder.fbIsFolder()
and not oReportFolder.fbCreateAsFolder(bCreateParents = True)
):
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The folder ",
COLOR_INFO, s0Value,
COLOR_NORMAL, " does not exist and cannot be created.",
);
fTerminate(guExitCodeBadArgument);
dxConfig["sReportFolderPath"] = s0Value;
elif s0LowerName in ["test-internal-error", "internal-error-test"]:
raise Exception("This exception was raised to test internal error handling.");
elif s0LowerName:
if not s0Value:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide a setting name (",
COLOR_INFO, sArgument,
COLOR_NORMAL, ") without a value.",
);
fTerminate(guExitCodeBadArgument);
try:
xValue = json.loads(s0Value);
except ValueError as oError:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " Cannot decode argument JSON value ",
COLOR_INFO, sArgument,
COLOR_NORMAL, "=",
COLOR_INFO, s0Value,
COLOR_NORMAL, ": ",
COLOR_INFO, " ".join(oError.args),
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
# User provided config settings must be applied after any keyword specific config settings, so we
# save them and apply them later. We also need to get the non-lowercase name.
sName = sArgument.split("=", 1)[0].lstrip("--"); # Good enough.
dxUserProvidedConfigSettings[sName] = xValue;
elif s0Value: # Before "--":
if s0ApplicationKeyword is None and s0ApplicationBinaryPath is None:
if sArgument in ddxApplicationSettings_by_sKeyword:
s0ApplicationKeyword = sArgument;
elif sArgument[-1] == "?":
sApplicationKeyword = sArgument[:-1];
dxApplicationSettings = ddxApplicationSettings_by_sKeyword.get(sApplicationKeyword);
if not dxApplicationSettings:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " Unknown application keyword ",
COLOR_INFO, sApplicationKeyword,
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
fOutputApplicationKeyWordHelp(sApplicationKeyword, dxApplicationSettings);
fTerminate(guExitCodeSuccess);
else:
if len(auApplicationProcessIds) > 0:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide process ids and an application binary.",
);
fTerminate(guExitCodeBadArgument);
if o0UWPApplication is not None:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide an application UWP package name and a binary.",
);
fTerminate(guExitCodeBadArgument);
s0ApplicationBinaryPath = sArgument;
else:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " Unknown argument: ",
COLOR_INFO, sArgument,
COLOR_NORMAL, ".",
);
else: # After "--":
if len(auApplicationProcessIds) > 0:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide process ids and application arguments.",
);
fTerminate(guExitCodeBadArgument);
asApplicationOptionalArguments.append(sArgument);
if a0sJITDebuggerArguments is not None:
if fbInstallAsJITDebugger(a0sJITDebuggerArguments):
fTerminate(guExitCodeSuccess);
fTerminate(guExitCodeInternalError);
if bFast:
dxConfig["bQuiet"] = True;
dxUserProvidedConfigSettings["bGenerateReportHTML"] = False;
dxUserProvidedConfigSettings["azsSymbolServerURLs"] = [];
bDoNotLoadSymbols = True;
dxUserProvidedConfigSettings["cBugId.bUse_NT_SYMBOL_PATH"] = False;
if u0JITDebuggerEventId is not None and dxConfig["sReportFolderPath"] is None:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " JIT debugging is not possible without providing a value for ",
COLOR_INFO, "sReportFolderPath",
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
dsApplicationURLTemplate_by_srSourceFilePath = {};
if gbSaveOutputWithReport:
oConsole.fEnableLog();
fSetup = None; # Function specific to a keyword application, used to setup stuff before running.
fCleanup = None; # Function specific to a keyword application, used to cleanup stuff before & after running.
if s0ApplicationKeyword:
dxApplicationSettings = ddxApplicationSettings_by_sKeyword.get(s0ApplicationKeyword);
if not dxApplicationSettings:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " Unknown application keyword ",
COLOR_INFO, s0ApplicationKeyword,
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
fSetup = dxApplicationSettings.get("fSetup");
fCleanup = dxConfig["bCleanup"] and dxApplicationSettings.get("fCleanup");
# Get application binary/UWP package name/process ids as needed:
if "sBinaryPath" in dxApplicationSettings:
# This application is started from the command-line.
if auApplicationProcessIds:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide process ids for application keyword ",
COLOR_INFO, s0ApplicationKeyword,
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
if o0UWPApplication:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide an application UWP package name for application keyword ",
COLOR_INFO, s0ApplicationKeyword,
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
if s0ApplicationBinaryPath is None:
s0ApplicationBinaryPath = dxApplicationSettings["sBinaryPath"];
if s0ApplicationBinaryPath is None:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " The main application binary for ",
COLOR_INFO, s0ApplicationKeyword,
COLOR_NORMAL, " could not be detected on your system.",
);
oConsole.fOutput(
COLOR_NORMAL, " Please provide the path to this binary in the arguments.",
);
fTerminate(guExitCodeApplicationBinaryNotFound);
elif "dxUWPApplication" in dxApplicationSettings:
dxUWPApplication = dxApplicationSettings["dxUWPApplication"];
# This application is started as a Universal Windows Platform application.
if s0ApplicationBinaryPath:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide an application binary for application keyword ",
COLOR_INFO, s0ApplicationKeyword,
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
if auApplicationProcessIds:
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide process ids for application keyword ",
COLOR_INFO, s0ApplicationKeyword,
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
sUWPApplicationPackageName = dxUWPApplication["sPackageName"];
sUWPApplicationId = dxUWPApplication["sId"];
o0UWPApplication = mWindowsAPI.cUWPApplication(sUWPApplicationPackageName, sUWPApplicationId);
elif not auApplicationProcessIds:
# This application is attached to.
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You must provide process ids for application keyword ",
COLOR_INFO, s0ApplicationKeyword,
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
elif asApplicationOptionalArguments:
# Cannot provide arguments if we're attaching to processes
oConsole.fOutput(
COLOR_ERROR, CHAR_ERROR,
COLOR_NORMAL, " You cannot provide arguments for application keyword ",
COLOR_INFO, s0ApplicationKeyword,
COLOR_NORMAL, ".",
);
fTerminate(guExitCodeBadArgument);
if "asApplicationAttachForProcessExecutableNames" in dxApplicationSettings:
gasAttachForProcessExecutableNames = dxApplicationSettings["asApplicationAttachForProcessExecutableNames"];
# Get application arguments;
if "fasGetStaticArguments" in dxApplicationSettings:
fasGetApplicationStaticArguments = dxApplicationSettings["fasGetStaticArguments"];
asApplicationStaticArguments = fasGetApplicationStaticArguments(bForHelp = False);
else:
asApplicationStaticArguments = [];
if asApplicationOptionalArguments is None and "fasGetOptionalArguments" in dxApplicationSettings:
fasGetApplicationOptionalArguments = dxApplicationSettings["fasGetOptionalArguments"];
asApplicationOptionalArguments = fasGetApplicationOptionalArguments(dxConfig, bForHelp = False);
asApplicationArguments = asApplicationStaticArguments + asApplicationOptionalArguments;
# Apply application specific settings
if dxApplicationSettings.get("dxConfigSettings"):
dxApplicationConfigSettings = dxApplicationSettings["dxConfigSettings"];
if dxConfig["bVerbose"]:
oConsole.fOutput(
COLOR_INFO, CHAR_INFO,
COLOR_NORMAL, " Applying application specific configuration for ",
COLOR_INFO, s0ApplicationKeyword,
COLOR_NORMAL, ":",
);
for (sSettingName, xValue) in dxApplicationConfigSettings.items():
if sSettingName not in dxUserProvidedConfigSettings:
# Apply and show result indented or errors.
if not fbApplyConfigSetting(sSettingName, xValue, [None, " "][dxConfig["bVerbose"]]):
fTerminate(guExitCodeBadArgument);
if dxConfig["bVerbose"]:
oConsole.fOutput();
# Apply application specific source settings
if "dsURLTemplate_by_srSourceFilePath" in dxApplicationSettings:
dsApplicationURLTemplate_by_srSourceFilePath = dxApplicationSettings["dsURLTemplate_by_srSourceFilePath"];
# If not ISA is specified, apply the application specific ISA (if any).
if not sApplicationISA and "sISA" in dxApplicationSettings:
sApplicationISA = dxApplicationSettings["sISA"];
if "asBinaryNamesThatAreAllowedToRunWithoutPageHeap" in dxApplicationSettings:
gasLowercaseBinaryNamesThatAreAllowedToRunWithoutPageHeap += [
sBinaryName.lower() for sBinaryName in dxApplicationSettings["asBinaryNamesThatAreAllowedToRunWithoutPageHeap"]
];
elif (auApplicationProcessIds or o0UWPApplication or s0ApplicationBinaryPath):
# There are no static arguments if there is no application keyword, only the user-supplied optional arguments
# are used if they are supplied:
asApplicationArguments = asApplicationOptionalArguments or [];