-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtools_windbg.bat
More file actions
820 lines (723 loc) · 38.1 KB
/
tools_windbg.bat
File metadata and controls
820 lines (723 loc) · 38.1 KB
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
::Author : Shen Xiaolong((xlshen@126.com))
::Copyright : free use,modify,spread, but MUST include this original two line information.
::@set _Echo=1
::set _Stack=%~nx0
::set _Debug=1
@if {"%_Echo%"}=={"1"} ( @echo on ) else ( @echo off )
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo. & @echo [+++++ %~nx0] commandLine: %0 %*
rem title length limited to 256 chars , else dos will report "Not enough memory resources are available to process this command"
rem @title %0 %*
@echo %~fs0 %*
::config current debug parameters
if not defined bNoBreakInThread set bNoBreakInThread=1
if not defined bNoInitBp set bNoInitBp=0
if not defined bDbgChildProcess set bDbgChildProcess=1
if not defined bNoExitBp set bNoExitBp=1
if not defined bEnableLog set bEnableLog=1
::*****************************************************************************************************************************
@echo.
title %~n0 %*
call :setPath "%~fs0"
call tools_error.bat checkAdmin %~fs0 %*
set supportedDbgCmds=;loadEnvWindbg;config;dbgPid;dbgAppName;dbgNewInstance;genDump;analysisDmp;dumpCheck;reduceCache;downloadPdb;readPdb;writePdb;pdbInfo;dbhCheck;
::call :checkParameter dbgPid 2734
::call :checkParameter dbgAppName
::call :checkParameter dbgAppName "notepad.exe"
::call :checkParameter dbgNewInstance
::call :checkParameter dbgNewInstance "C:\myapp\app.exe" -appStartParam
::call :checkParameter analysisDmp
::call :checkParameter analysisDmp "D:\mydump\fulldump.dmp"
call :checkParameter %*
@rem usage : processInput dbgNewInstance ApplitionFullPath RunParameters
::call :processInput dbgNewInstance "C:\Program Files (x86)\Cisco Systems\Cisco Jabber\CiscoJabber.exe" disableSingleInstance
call :%*
goto :End
::*****************************************************************************************************************************
:checkParameter
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_error.bat checkParamCount 1 %*
call tools_error.bat checkSupportedCmd "%~1" "%supportedDbgCmds%"
goto :eof
::*****************************************************************************************************************************
:dbgPid
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :dbgPid.verifyPID %*
call :config.dbgOption.live attachPid %curPid%
call :dbgPid.showInfo %curPid%
call :dbgPid.attachPid %curPid%
goto :eof
:dbgPid.attachPid
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined windbgMode call tools_isX86X64.bat IsX86OrX64Process "%1" windbgMode
if not {%windbgMode%}=={""} call :config.applyWindbgMode "%windbgMode%"
call tools_process.bat getProcessCmdLine %1 _tmpCmdLine
cd /d "%_tmpCmdLine%\.."
call :windbg.load -T "attach process:%1" %dbgOption% -p %1
goto :eof
:dbgPid.showInfo
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
@echo **************************************************************************************
call tools_process.bat processinfo %1
@echo.
@echo debug start option : %dbgOption%
@echo **************************************************************************************
@echo.
goto :eof
:dbgPid.verifyPID
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set curPid=
::MS bug : JIT always deliver parameter -p , e.g.
:: E:\work\shenxiaolong\core\shell_script\batch_env\Windbg\tools_windbg.bat dbgPid -p 15328
if not {"%~2"}=={""} if {"%~1"}=={"-p"} set curPid=%~2
if {"%~2"}=={""} set curPid=%~1
if defined curPid call :dbgPid.verifyPID.checkExist curPid %curPid%
if not defined curPid call :dbgPid.verifyPID.waitPID curPid
goto :eof
:dbgPid.verifyPID.waitPID
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set waitStringPrompt=please input existingg process ID to debug :
call tools_userInput.bat waitNumber %~1
call :dbgPid.verifyPID.checkExist %~1 %%%~1%%
if not defined %~1 call :dbgPid.verifyPID.waitPID %*
goto :eof
:dbgPid.verifyPID.checkExist
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_process.bat isProcessExist "%~2" pidExist
if {"%pidExist%"}=={"1"} goto :eof
call set %~1=
call tools_message.bat NotifyMsg "process[pid:%~2] doesn't exist."
goto :eof
::*****************************************************************************************************************************
:dbgAppName
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set "_appName=%~n1"
if not defined _appName call :dbgAppName.waitAppName _appName
call :dbgAppName.dbgScenario "%_appName%"
goto :eof
:dbgAppName.dbgScenario
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_process.bat getProcessCount "%~nx1" ProcessNum
call tools_message.bat enableDebugMsg "%~0" "ProcessNum=%ProcessNum%"
if {%ProcessNum%}=={0} call :dbgAppName.processNameNotExist "%~nx1"
if {%ProcessNum%}=={1} call :dbgAppName.sigleProcess "%~nx1"
if %ProcessNum% GTR 1 call :dbgAppName.multipleProcess "%~nx1"
goto :eof
:dbgAppName.waitAppName
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set "waitStringPrompt=please input application name of existingg process (include extension, e.g. myApp.exe):"
call tools_userInput.bat waitString _appName
call :dbgAppName "%_appName%"
goto :eof
:dbgAppName.processNameNotExist
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_message.bat NotifyMsg "app name "%~1" doesn't exit."
call :dbgAppName
goto :eof
:dbgAppName.sigleProcess
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_process.bat getPIDByName "%~1" appPID
call :dbgPid %appPID%
goto :eof
:dbgAppName.multipleProcess
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :dbgAppName.multipleProcess.list "%~1"
call :dbgAppName.multipleProcess.selectProcess %DefAppProcIdx%
if defined DefAppProcIdx echo debug No.%DefAppProcIdx% process of "%~1"
@echo.
@echo you selected process:
@echo %processLine%
call :dbgAppName.multipleProcess.getPid %processLine%
echo appPID=%appPID%
call :dbgPid %appPID%
goto :eof
:dbgAppName.multipleProcess.getPid
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set appPID=%2
goto :eof
:dbgAppName.multipleProcess.selectProcess
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set waitStringPrompt=there are %ProcessNum% instances^(%~1^) are runing,pls select the process ID:
type %displayTmpFile%
if {"%~1"}=={""} (
for /f "usebackq delims=: tokens=1" %%i in ( ` type "%displayTmpFile%" ` ) do call :dbgAppName.multipleProcess.selectProcess.generateChoiceOpts %%i
call tools_userInput.bat waitSelect %selOpt% selChar
) else (
call set selChar=%~1
)
for /f "usebackq delims=: tokens=1*" %%i in ( %displayTmpFile% ) do if {%%i}=={%selChar%} (
set processLine=%%j
)
goto :eof
:dbgAppName.multipleProcess.selectProcess.generateChoiceOpts
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined selOpt (
set selOpt=%1
) else (
set selOpt=%selOpt%%1
)
goto :eof
:dbgAppName.multipleProcess.list
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set displayTmpFile=%temp%\tmp%random%.txt
if exist %displayTmpFile% del /f %displayTmpFile%
@echo query process "%~nx1"
wmic process WHERE ( name="%~nx1" ) get handle,name,commandline,ThreadCount | more +1 | findstr /n "%~nx1" > %displayTmpFile%
goto :eof
::*****************************************************************************************************************************
:dbgNewInstance
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set "_instancePath=%~fs1"
if defined _instancePath call :dbgNewInstance.verifyInstancePath _instancePath
if not defined _instancePath call :dbgNewInstance.waitInstancePath _instancePath
if not defined AppParam set AppParam=%2 %3 %4 %5 %6 %7 %8 %9
set bNoInitBp=0
call :config.dbgOption.onExePathFound "%~f1"
call :config.dbgOption.live newInstancePath "%~f1"
if not defined AppParam set AppParam=%2 %3 %4 %5 %6 %7 %8 %9
call :dbgNewInstance.info "%~f1"
call :dbgNewInstance.load "%~f1"
goto :eof
:dbgNewInstance.verifyInstancePath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :dbgNewInstance.verifyInstancePath.checkFileExist %~1 "%%%~1%%"
if defined %~1 call :dbgNewInstance.verifyInstancePath.checkExe %~1 "%%%~1%%"
if not exist "%newInstancePath%" set newInstancePath=
goto :eof
:dbgNewInstance.verifyInstancePath.checkFileExist
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if exist "%~fs2" goto :eof
call tools_message.bat NotifyMsg "%~2 is not a executable application."
set %~1=
goto :eof
:dbgNewInstance.verifyInstancePath.checkExe
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if {"%~x2"}=={".exe"} goto :eof
set extName=%~x2
call tools_string.bat toLower extName
if {"%extName%"}=={".exe"} goto :eof
call tools_message.bat NotifyMsg "%~nx2 is not a executable application."
set %~1=
goto :eof
:dbgNewInstance.waitInstancePath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if defined newInstancePath set "%~1=%newInstancePath%" & goto :eof
set inputSpecFilePrompt=plese input application full Path and run paramter. e.g:
set inputSpecFilePrompt2=d:\myAppDir\myApp.exe -noBox
call tools_userInput.bat inputSpecFile ".exe" %~1
goto :eof
:dbgNewInstance.info
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
@echo ready to start new instance: %~nx1.
@echo **************************************************************************************
@echo instance path : %~f1
@echo application start parameter : %appParam%
@echo debug option : %dbgOption%
@echo **************************************************************************************
@echo.
call tools_message.bat noSleepMsg "%~0" 2
goto :eof
:dbgNewInstance.load
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined windbgMode call tools_isX86X64.bat IsX86OrX64Mod "%~f1" windbgMode
if not {%windbgMode%}=={""} call :config.applyWindbgMode "%windbgMode%"
echo Disable BSTR Caching to prevent UMDH from uncorrectly determining the owner of a memory allocation
set OANOCACHE=1
@echo.
@echo startNewInstance : %~f1
cd /d "%~dp1"
call :windbg.load %dbgOption% "%~f1" %AppParam%
goto :eof
::*****************************************************************************************************************************
:dmpFile.checkSize
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined minDmpFileSize set minDmpFileSize=100
if %~z1 LSS %minDmpFileSize% (
call tools_message.bat warningMsg "%~fs1 might be not valid full dump file. its size is only %~z1"
explorer "%~dp1"
pause > nul
@echo.
@echo press any key to exit analysis dump file job.
exit
)
goto :eof
::*****************************************************************************************************************************
:analysisDmp
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set "_dmpFile=%~fs1"
if defined _dmpFile call :analysisDmp.verifyDmpFile "%~fs1"
if not defined _dmpFile call :analysisDmp.waitDmpFile _dmpFile
call :dmpFile.checkSize "%~f1"
if not defined dbgOption call :config.dbgOption.dmp "%~f1"
call :analysisDmp.info "%~f1"
call :analysisDmp.load "%~f1"
goto :eof
:analysisDmp.waitDmpFile
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set inputSpecFilePrompt=plese input dump file full Path. e.g:
set inputSpecFilePrompt2=d:\myAppDir\myApp.dmp
call tools_userInput.bat inputSpecFile ".dmp" %~1
goto :eof
:analysisDmp.verifyDmpFile
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_error.bat checkPathExist "%~fs1" "%~fs0" analysisDmp.verifyDmpFile_mark11
set extName=%~x1
call tools_string.bat toLower extName
if not {"%extName%"}=={".dmp"} call tools_message.bat errorMsg "%~nx2 is not a dump file -- .dmp"
goto :eof
:analysisDmp.info
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
@echo **************************************************************************************
@echo dump file path : %~f1
@echo debug option : %dbgOption%
@echo **************************************************************************************
@echo.
call tools_message.bat noSleepMsg "%~0" 2
goto :eof
:analysisDmp.load
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined windbgMode call tools_isX86X64.bat IsX86OrX64Dump "%~fs1" windbgMode
if not {%windbgMode%}=={""} call :config.applyWindbgMode "%windbgMode%"
cd /d "%~dp1"
call :windbg.load %dbgOption% -z "%~f1"
goto :eof
::*****************************************************************************************************************************
:genDump
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
rem call tools_error.bat checkFileExist "%~fs1"
set "_tmpExtName=%~x1"
call tools_string.bat toLower _tmpExtName
if not {"%_tmpExtName%"}=={".exe"} call tools_message.bat errorMsg "only executable file is supported to generate dump file."
::below can improve performance greatly.
set "dummySymPath=%temp%\emptySymbols"
if not exist "%dummySymPath%" rd "%dummySymPath%"
call tools_appInstallPath.bat FindPathWindbg _tmpWindbgPath
set "_tmpCdbPath=%_tmpWindbgPath%\x64\cdb.exe"
call tools_error.bat checkFileExist "%_tmpCdbPath%"
set _tmpDmpFilePath=%dmpFilePath%
if not defined _tmpDmpFilePath set "_tmpDmpFilePath=%temp%\%~nx1\%~n1.dmp"
call tools_path.bat checkOutputPath "%_tmpDmpFilePath%"
set _cmds="%_tmpCdbPath%" -kqm -failinc -y "%dummySymPath%" -c ".dump /o /mapwd \"%_tmpDmpFilePath%\";q" -G "%~fs1"
echo %_cmds%
if not defined _DebugQ call %_cmds%
rem call "%_tmpCdbPath%" -kqm -failinc -y "%dummySymPath%" -cf "c:\myscript\startfile.dbg" -G "%~fs1"
if not defined _DebugQ call tools_error.bat checkFileExist "%_tmpDmpFilePath%"
if not defined _DebugQ call tools_path.bat showPathInExplorer "%_tmpDmpFilePath%"
call tools_message.bat noPauseMsg "%~0"
goto :eof
:dumpCheck
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :dumpCheck.verifyDmpFile %*
call :dmpFile.checkSize "%~f1"
set "_dumpCheckFile=%~dp1_dumpCheckResult.txt"
if not exist "%_dumpCheckFile%" call :dumpCheck.generate "%~f1" "%_dumpCheckFile%"
call tools_error.bat checkFileExist "%_dumpCheckFile%"
if {"%~2"}=={""} start "" "%_dumpCheckFile%"
goto :eof
:dumpCheck.verifyDmpFile
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_error.bat checkFileExist "%~f1"
set extName=%~x1
call tools_string.bat toLower extName
if not {"%extName%"}=={".dmp"} call tools_message.bat errorMsg "%~nx1 is not a dump file -- .dmp"
goto :eof
:dumpCheck.generate
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined dmpSymbol set dmpSymbol=SRV*http://msdl.microsoft.com/download/symbols
if not defined windbgMode call tools_isX86X64.bat IsX86OrX64Dump "%~fs1" windbgMode
if not {%windbgMode%}=={""} call :config.applyWindbgMode "%windbgMode%"
call :dumpCheck.info "%~f1"
"%windbgPath%\%windbgMode%\dumpchk.exe" -y %dmpSymbol% "%~fs1" >> "%~fs2"
timeout /t 2 >> nul
goto :eof
:dumpCheck.info
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
@echo **************************************************************************************
@echo dump file path : %~f1
@echo symbol path : %dmpSymbol%
@echo **************************************************************************************
@echo.
call tools_message.bat noSleepMsg "%~0" 2
goto :eof
::*****************************************************************************************************************************
:downloadPdb
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_error.bat checkPathExist "%~fs1" "%~fs0" downloadPdb_mark
call :config loadEnvironmetnVariable %*
::symchk always use x64 bit
echo call "%WindbgPath%\x64\symchk.exe" /v /if "%~fs1"
call "%WindbgPath%\x64\symchk.exe" /v /if "%~fs1"
call tools_message.bat noSleepMsg "%~0" 10
goto :eof
:readPdb
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :pdbFile.verifyPdbFile %*
set "iniFile=%~f2"
if not defined iniFile call :pdbFile.srcsrvFilePath %* iniFile
call :readPdb.generateSrcsrv %* "%iniFile%"
if not defined NoCheckPdbIniExist call tools_error.bat checkFileExist "%iniFile%"
if not defined NoOpenPdbIni call tools_txtFile.bat openTxtFile "%iniFile%"
goto :eof
:readPdb.generateSrcsrv
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :readPdb.backup %*
if defined _Debug echo read srcsrv stream from %~f1
pdbstr.exe -r -p:"%~fs1" -s:srcsrv > "%~f2"
if {"%~z2"}=={"0"} (
@echo warning : size is 0 [%~fs2]
del /f/q "%~fs2"
)
goto :eof
:readPdb.backup
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if {"%~z2"}=={"0"} goto :eof
if not exist "%~fs2" goto :eof
call genNameByTime.bat _tmpStr
copy "%~dpnx2" "%~dpn2_readBak_%_tmpStr%%~x2" 1>nul
goto :eof
:writePdb
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :pdbFile.verifyPdbFile %*
set "iniFile=%~f2"
if not defined iniFile call :pdbFile.srcsrvFilePath %* iniFile
call tools_error.bat checkFileExist "%iniFile%"
call :writePdb.writeSrcsrv "%~f1" "%iniFile%"
goto :eof
:writePdb.writeSrcsrv
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :writePdb.backup %*
if defined _Debug echo write srcsrv '%~f2' stream to %~f1
pdbstr.exe -w -p:"%~fs1" -i:"%~fs2" -s:srcsrv
goto :eof
:writePdb.backup
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not exist "%~dpn1_backup.pdb" copy "%~dpnx1" "%~dpn1_backup.pdb" 1>nul
goto :eof
:dbhCheck
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :pdbFile.verifyPdbFile %*
where dbh.exe 1>nul 2>nul || set "path=%windbgPath%\x64;%path%"
dbh.exe -?? | find /v "<"
echo type ? to show more help
dbh.exe -v "%~fs1"
goto :eof
:pdbInfo
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :pdbFile.verifyPdbFile %*
call :pdbInfo.%~2 "%~f1"
call tools_message.bat noPauseMsg "%~0"
goto :eof
:pdbInfo.gitStream
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set "gitStreamFile=%~dpn1_srcsrvGit.txt"
call pdbstr.exe -r -p:"%~fs1" -s:srcsrvGit > "%gitStreamFile%"
type "%gitStreamFile%"
goto :eof
:pdbInfo.raw
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set "rawFile=%~dpn1_raw.txt"
call srctool.exe -r "%~fs1" > "%rawFile%"
type "%rawFile%"
goto :eof
:pdbInfo.src
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined srcCache set "srcCache=%~dp1%~n1"
if {"%srcCache:~-1%"}=={"\"} set "srcCache=%srcCache:~0,-1%"
call tools_message.bat enableDebugMsg "%~0" srctool.exe -x "%~fs1" -d:"%srcCache%"
call srctool.exe -x "%~fs1" -d:"%srcCache%"
set "srcFile=%~dpn1_srcList.txt"
if exist "%srcCache%" dir/s/b "%srcCache%" > "%srcFile%"
goto :eof
:pdbFile.setToolPath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined windbgMode set windbgMode=x86
@where pdbstr.exe 1>nul 2>nul || @set "path=%windbgPath%\%windbgMode%\srcsrv;%path%"
goto :eof
:pdbFile.verifyPdbFile
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :pdbFile.setToolPath %*
call tools_error.bat checkFileExist "%~f1"
set extName=%~x1
call tools_string.bat toLower extName
if not {"%extName%"}=={".pdb"} call tools_message.bat errorMsg "%~nx1 is not a pdb file -- .pdb"
goto :eof
:pdbFile.srcsrvFilePath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call set "%~2=%~dpn1.ini"
goto :eof
::*****************************************************************************************************************************
:reduceCache
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
::different symbol tool might save symbol into different directory.
set "fileListOrFolder=%~1"
call tools_error.bat checkPathExist "%fileListOrFolder%" "%~f0" :action.reduceCache_mark
set olderDays=%~2
if not defined olderDays set olderDays=7
call tools_message.bat NotifyMsg "only keep near %olderDays% days symbol."
set "waitStringPrompt=press any key to accept current setting(%olderDays% days), or input one new days (number):"
call tools_userInput.bat waitNumber newDays 1
if defined newDays set olderDays=%newDays%
call tools_path.bat isFileExist "%fileListOrFolder%" bExist
if {"%bExist%"}=={"1"} call :reduceCache.folderList "%fileListOrFolder%"
if not {"%bExist%"}=={"1"} call :reduceCache.folder "%fileListOrFolder%"
goto :eof
:reduceCache.folderList
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
echo process folder list file : "%~fs1"
for /f "usebackq tokens=*" %%i in ( ` type "%~fs1" ` ) do call :reduceCache.folder "%%i"
goto :eof
:reduceCache.folder
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not exist "%~f1" (
call tools_message.bat NotifyMsg "symbol cache path '%~f1' doesn't exist."
goto :eof
)
set "symCachePath=%~f1"
if {"%symCachePath:~-1%"}=={"\"} set "symCachePath=%symCachePath:~0,-1%"
set "realWindbgPath=%windbgPath%\x86"
if exist "%symCachePath%\..\agestore.exe" set "realWindbgPath=%symCachePath%\.."
call tools_path.bat ToNormalPath realWindbgPath
"%realWindbgPath%\agestore.exe" "%symCachePath%" -days=%olderDays% -s -y 2>nul
echo Done : "%realWindbgPath%\agestore.exe" "%symCachePath%" -days=%olderDays% -s -y 2>nul
echo.
echo --------------------------------------------------------------------------------------
goto :eof
::****************************************************************************************************************************
:windbg.load
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set actCmd="%windbgPath%\%windbgMode%\windbg.exe" %*
@echo %actCmd%
call tools_message.bat noSleepMsg "%~0" 2
start "" %actCmd%
goto :eof
:windbg.setAsDefaultDebugger
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
@echo set windbg.exe as default JIT debugger with quiet mode.
call :windbg.load -IS
goto :eof
::*****************************************************************************************************************************
:loadEnvWindbg
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if {"%~2"}=={""} start cmd.exe /k %~fs0 loadEnvWindbg %* "reentry"
if {"%~2"}=={""} goto :eof
call tools_error.bat checkPathExist "%~1" "%~fs0" loadEnvWindbg_mark
pushd "%~1"
call tools_isX86X64.bat IsX86OrX64Folder "%cd%" windbgMode x64
where windbg.exe 1>nul 2>nul || set "path=%windbgPath%\%windbgMode%;%path%"
cls
set ls=dir/w "%windbgPath%\%windbgMode%\*.exe"
%ls%
echo.
set ls
echo use %%ls%% to show windbg tool set .
goto :eof
:config
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :config.%~1 %2 %3 %4 %5 %6 %6 %8 %9
goto :eof
:config.loadEnvironmetnVariable
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :environmentVariable.setCacheDir %*
call :environmentVariable.setDebuggerExtSearchPath %*
call :environmentVariable.setIniFile
call :environmentVariable.set_NT_SYMBOL_PATH %*
goto :eof
:config.setWindbgEvnPath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :windbgEvnPath.setVar %*
goto :eof
::*****************************************************************************************************************************
:setPath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
for /f "usebackq tokens=2,*" %%a in ( ` dir "%~dp0.." ^| find /i "Directory of" ` ) do set "myWinScriptPath=%%b"
where tools_path.bat 1>nul 2>nul || set path=%path%;%~dp1;%myWinScriptPath%\common;
if not defined windbgPath call tools_appInstallPath.bat FindPathWindbg windbgPath
rem don't set default value, wait for dynamic recongnize it.
::if not defined windbgMode set windbgMode=x86
if not exist "%windbgPath%\x86\windbg.exe" call tools_message.bat errorMsg "can NOT find windbg install path. please check. "
::set windbgPath=%windbgPath%\%windbgMode%
::where windbg.exe 1>nul 2>nul || set path=%path%;%windbgPath%;
goto :eof
:findExePath.FromDump
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
rem call :findExePath.FromDump "c:\...\my.dmp" exePath
set %~2=
for /f "usebackq tokens=2* delims=:" %%i in ( ` call "%windbgPath%\x64\kd.exe" -z "%~fs1" -c "|;q" ^| find /i ".exe" ` ) do set "%~2=%%~j"
goto :eof
:findExePath.FromPid
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set %~2=
::set ExecutablePath=
:: for /f "usebackq tokens=*" %%i in ( ` wmic process where "handle=%~1" get ExecutablePath /format:list ^| find /i ".exe" ` ) do set %%~i
::set "%~2=%ExecutablePath%"
for /f "usebackq tokens=*" %%i in ( ` wmic process where processid^=%~1 get ExecutablePath ^| more +1 ` ) do if not defined %~2 set "%~2=%%~fsi"
goto :eof
::*****************************************************************************************************************************
:windbgEvnPath.getVar
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if defined %~1 goto :eof
:: MS AeDebug has one issue : it doesn't load default environmetn Variable. here is workaround
call :windbgEvnPath.varFile.getDefaultPath windbgEnvVarFile
if not exist "%windbgEnvVarFile%" call tools_message.bat warningMsg "customized startCmds file doesn't exist : %windbgEnvVarFile%"
if not exist "%windbgEnvVarFile%" goto :eof
for /f "usebackq tokens=*" %%i in ( ` type "%windbgEnvVarFile%" ^| find /i "%~1" ` ) do if not defined %~1 set "%%~i"
goto :eof
:windbgEvnPath.setVar
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call setx %~1 "%~2"
set "%~1=%~2"
call :windbgEvnPath.varFile.getDefaultPath windbgEnvVarFile
if not exist "%windbgEnvVarFile%\.." md "%windbgEnvVarFile%\.."
if {"%~2"}=={""} call :windbgEvnPath.varFile.clearVar %~1 "%windbgEnvVarFile%"
if not {"%~2"}=={""} call :windbgEvnPath.varFile.addVar %*
goto :eof
:windbgEvnPath.varFile.clearVar
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not exist "%~f2" goto :eof
set "_tmpBackupName=%~n2_bak.txt"
set "_tmpBackupFile=%~dp2%_tmpBackupName%"
if exist "%_tmpBackupFile%" del /f "%_tmpBackupFile%"
rename "%~f2" "%_tmpBackupName%"
type "%_tmpBackupFile%" | find /v "%~1" > "%~f2"
del /f "%_tmpBackupFile%"
goto :eof
:windbgEvnPath.varFile.addVar
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not exist "%windbgEnvVarFile%" (
call :windbgEvnPath.varFile.addVar.impl %*
goto :eof
)
call :windbgEvnPath.varFile.clearVar %~1 "%windbgEnvVarFile%"
call :windbgEvnPath.varFile.addVar.impl %*
goto :eof
:windbgEvnPath.varFile.addVar.impl
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if exist "%windbgEnvVarFile%" call echo %~1^=%~2>>"%windbgEnvVarFile%"
if not exist "%windbgEnvVarFile%" call echo %~1^=%~2> "%windbgEnvVarFile%"
goto :eof
:windbgEvnPath.varFile.getDefaultPath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set "%~1=%USERPROFILE%\windbg\windbgEnvVar.txt"
goto :eof
:config.dbgOption.gengerate
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if {%bNoBreakInThread%}=={1} set param_NoBreakInThread=-pb
if {%bNoInitBp%}=={1} set param_NoInitBp=-g
if {%bNoExitBp%}=={1} set param_NoExitBp=-G
if {%bEnableLog%}=={1} set param_logFile=-logo "%logFile%"
set param_NoSaveWorkspace=-Q
set testedThemeFile=%myWinScriptPath%\Windbg\setup\layout_theme\dark_theme.wew
if not defined themeFile if exist "%testedThemeFile%" set themeFile=%testedThemeFile%
if defined themeFile set param_themeFile=-WF "%themeFile%"
set dbgOption=%* %param_NoSaveWorkspace% %param_NoBreakInThread% %param_NoInitBp% %param_NoExitBp% %param_themeFile% %param_logFile% -c "$$>a<%myWinScriptPath%\Windbg\script\startCmds.dbg;"
echo call tools_message.bat enableDebugMsg "%~0" "dbgOption=%dbgOption:"='%"
call tools_message.bat enableDebugMsg "%~0" "dbgOption=%dbgOption:"='%"
goto :eof
:config.dbgOption.live
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if {%bDbgChildProcess%}=={1} set param_DbgChildProcess=-o
if defined dbgOption goto :eof
call :config.dbgOption.live.%*
call :config.dbgOption.gengerate %param_DbgChildProcess%
goto :eof
:config.dbgOption.dmp
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :findExePath.FromDump "%~fs1" exePath
call :config.dbgOption.dmp.checkExePath %*
call :config.dbgOption.onExePathFound "%exePath%"
call :config.dbgOption.setLogFilePath "%~f1" _dmp
call :config.dbgOption.gengerate
goto :eof
:config.dbgOption.live.attachPid
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :findExePath.FromPid %~1 exePath
if defined exePath call :config.dbgOption.onExePathFound "%exePath%"
if not defined logFile set "logFile=%temp%\windbg_PID\%_appName%_%~1.log"
if not exist "%logFile%\.." md "%logFile%\.."
goto :eof
:config.dbgOption.live.newInstancePath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call :config.dbgOption.onExePathFound "%~f1"
call :config.dbgOption.setLogFilePath "%~f1" _app
goto :eof
:config.dbgOption.dmp.checkExePath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if defined exePath goto :eof
call "%windbgPath%\x64\dumpchk.exe" "%~fs1"
call tools_message.bat errorMsg "dump file '%~nx1' is corrupted."
goto :eof
:config.dbgOption.setLogFilePath path optSuffix
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if defined logFile goto :eof
call genNameByTime.bat tmpDT
set "logFile=%~dpn1_windbg%~2_%tmpDT%.log"
goto :eof
:config.dbgOption.onExePathFound exePath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set "_appName=%~n1"
call :environmentVariable.startCmds
call :environmentVariable.userRepo
goto :eof
:environmentVariable.userRepo
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if defined userRepo goto :eof
if not defined _appName call tools_message.bat errorMsg "_appName is not defined" "%~fs0" config.checkStartScript_mark
if not defined userRepo_%_appName% call :windbgEvnPath.getVar "userRepo_%_appName%"
if defined userRepo_%_appName% call set "userRepo=%%userRepo_%_appName%%%"
if defined _Debug echo userRepo=%userRepo%
goto :eof
:environmentVariable.startCmds
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if defined startCmds_user goto :eof
if not defined _appName call tools_message.bat errorMsg "_appName is not defined" "%~fs0" config.checkStartScript_mark
if not defined startCmds_%_appName% call :windbgEvnPath.getVar "startCmds_%_appName%"
if defined startCmds_%_appName% call set "startCmds_user=%%startCmds_%_appName%%%"
if defined _Debug echo startCmds_user=%startCmds_user%
goto :eof
:environmentVariable.setCacheDir
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if exist "%~fs1" set "_DBGHELP_HOMEDIR=%~fs1"
if defined _DBGHELP_HOMEDIR goto :eof
if not defined defWindbgCacheDir set defWindbgCacheDir=C:\symbols
if not exist "%defWindbgCacheDir%" md "%defWindbgCacheDir%"
if not defined _DBGHELP_HOMEDIR set "_DBGHELP_HOMEDIR=%defWindbgCacheDir%"
goto :eof
:environmentVariable.setDebuggerExtSearchPath
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
::C:\PROGRA~2\WI3CF2~1\10\DEBUGG~1\x86\windbg.exe
rem set _NT_DEBUGGER_EXTENSION_PATH to path will cause that wrong path is put on front of debugger extension search path.
rem debugger loads wrong debugger extension will cause windbg crash and exit sliently.
rem debugger loads wrong debugger extension will cause windbg crash and exit sliently.
rem bad : set "_NT_DEBUGGER_EXTENSION_PATH=%path%"
rem OK : set "_NT_DEBUGGER_EXTENSION_PATH=%windbgPath%\%windbgMode%"
goto :eof
:environmentVariable.setIniFile
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined SRCSRV_INI_FILE if exist "%myWinScriptPath%\Windbg\setup\symSrv\srcSrv.ini" set SRCSRV_INI_FILE=%myWinScriptPath%\Windbg\setup\symSrv\srcSrv.ini
@echo use source server config file : %SRCSRV_INI_FILE%
goto :eof
:environmentVariable.set_NT_SYMBOL_PATH
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if not defined _NT_SYMBOL_PATH_MY call tools_message.bat NotifyMsg "no user-defined symbol path variable _NT_SYMBOL_PATH_MY"
if not defined _NT_SYMBOL_PATH set "_NT_SYMBOL_PATH=srv*;cache*%_DBGHELP_HOMEDIR%;SRV*http://msdl.microsoft.com/download/symbols;SRV*http://referencesource.microsoft.com/symbols;%_NT_SYMBOL_PATH_MY%;"
goto :eof
:config.applyWindbgMode
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
for /f "usebackq tokens=*" %%i in ( ` where Python.exe ^| find /i "Python3" ` ) do call :config.applyWindbgMode.pykdPythonVer "%~1" "%%i"
goto :eof
:config.applyWindbgMode.pykdPythonVer
rem use python 3.0 for pykd extension.
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
if {"%~1"}=={"x86"} set _verFilter=/i "-32"
if {"%~1"}=={"x64"} set _verFilter=/v "-32"
if {"%_verFilter%"}=={""} (
echo unsupported windbg mode for pykd extension.
echo only x86 or x64 is supported.
goto :eof
)
for /f "usebackq tokens=*" %%i in ( ` echo %~dp2^| find %_verFilter% ` ) do if not {"%%i"}=={""} set _pythonVer=%%i
if defined _pythonVer set path="%_pythonVer%";%path%
@echo used python path : %_pythonVer% for windbgMode[%~1]
goto :eof
::*****************************************************************************************************************************
:END
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [----- %~nx0] commandLine: %0 %* & @echo.