1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
//
4
- #nullable disable
5
4
6
5
using System ;
7
6
using System . Collections . Generic ;
@@ -100,7 +99,7 @@ public unsafe struct ProcessEntry32W
100
99
static class @libproc
101
100
{
102
101
[ DllImport ( nameof ( libproc ) ) ]
103
- private static extern int proc_listchildpids ( int ppid , int [ ] buffer , int byteSize ) ;
102
+ private static extern int proc_listchildpids ( int ppid , int [ ] ? buffer , int byteSize ) ;
104
103
105
104
public static unsafe bool ListChildPids ( int ppid , out int [ ] buffer )
106
105
{
@@ -171,7 +170,7 @@ private unsafe static IEnumerable<Process> Windows_GetChildren(Process process)
171
170
private static IEnumerable < Process > Linux_GetChildren ( Process process )
172
171
{
173
172
var children = new List < Process > ( ) ;
174
- List < int > childPids = null ;
173
+ List < int > ? childPids = null ;
175
174
176
175
try
177
176
{
@@ -188,7 +187,7 @@ private static IEnumerable<Process> Linux_GetChildren(Process process)
188
187
pgrepInfo . RedirectStandardOutput = true ;
189
188
pgrepInfo . Arguments = $ "-P { process . Id } ";
190
189
191
- using Process pgrep = Process . Start ( pgrepInfo ) ;
190
+ using Process pgrep = Process . Start ( pgrepInfo ) ! ;
192
191
193
192
string [ ] pidStrings = pgrep . StandardOutput . ReadToEnd ( ) . Split ( '\n ' , StringSplitOptions . RemoveEmptyEntries ) ;
194
193
pgrep . WaitForExit ( ) ;
@@ -271,7 +270,11 @@ static bool CollectCrashDumpWithMiniDumpWriteDump(Process process, string crashD
271
270
272
271
static bool CollectCrashDumpWithCreateDump ( Process process , string crashDumpPath , StreamWriter outputWriter )
273
272
{
274
- string coreRoot = Environment . GetEnvironmentVariable ( "CORE_ROOT" ) ;
273
+ string ? coreRoot = Environment . GetEnvironmentVariable ( "CORE_ROOT" ) ;
274
+ if ( coreRoot is null )
275
+ {
276
+ throw new InvalidOperationException ( "CORE_ROOT environment variable is not set." ) ;
277
+ }
275
278
string createdumpPath = Path . Combine ( coreRoot , "createdump" ) ;
276
279
string arguments = $ "--crashreport --name \" { crashDumpPath } \" { process . Id } --withheap";
277
280
Process createdump = new Process ( ) ;
@@ -388,7 +391,7 @@ public static bool TryPrintStackTraceFromCrashReport(string crashReportJsonFile,
388
391
}
389
392
390
393
Console . WriteLine ( "=========================================" ) ;
391
- string userName = Environment . GetEnvironmentVariable ( "USER" ) ;
394
+ string ? userName = Environment . GetEnvironmentVariable ( "USER" ) ;
392
395
if ( ! string . IsNullOrEmpty ( userName ) )
393
396
{
394
397
if ( ! RunProcess ( "sudo" , $ "chown { userName } { crashReportJsonFile } ", Console . Out ) )
@@ -426,8 +429,8 @@ public static bool TryPrintStackTraceFromCrashReport(string crashReportJsonFile,
426
429
Console . WriteLine ( $ "Error reading { crashReportJsonFile } : { ex . ToString ( ) } ") ;
427
430
return false ;
428
431
}
429
- dynamic crashReport = JsonSerializer . Deserialize < JsonObject > ( contents ) ;
430
- var threads = crashReport [ "payload" ] [ "threads" ] ;
432
+ var crashReport = JsonNode . Parse ( contents ) ! ;
433
+ var threads = ( JsonArray ) crashReport [ "payload" ] ! [ "threads" ] ! ;
431
434
432
435
// The logic happens in 3 steps:
433
436
// 1. Read the crashReport.json file, locate all the addresses of interest and then build
@@ -443,7 +446,7 @@ public static bool TryPrintStackTraceFromCrashReport(string crashReportJsonFile,
443
446
foreach ( var thread in threads )
444
447
{
445
448
446
- if ( thread [ "native_thread_id" ] == null )
449
+ if ( thread ! [ "native_thread_id" ] == null )
447
450
{
448
451
continue ;
449
452
}
@@ -452,21 +455,21 @@ public static bool TryPrintStackTraceFromCrashReport(string crashReportJsonFile,
452
455
addrBuilder . AppendLine ( "----------------------------------" ) ;
453
456
addrBuilder . AppendLine ( $ "Thread Id: { thread [ "native_thread_id" ] } ") ;
454
457
addrBuilder . AppendLine ( " Child SP IP Call Site" ) ;
455
- var stack_frames = thread [ "stack_frames" ] ;
458
+ var stack_frames = ( JsonArray ) thread [ "stack_frames" ] ! ;
456
459
foreach ( var frame in stack_frames )
457
460
{
458
- addrBuilder . Append ( $ "{ SKIP_LINE_TAG } { frame [ "stack_pointer" ] } { frame [ "native_address" ] } ") ;
459
- bool isNative = ( string ) frame [ "is_managed" ] == "false" ;
461
+ addrBuilder . Append ( $ "{ SKIP_LINE_TAG } { frame ! [ "stack_pointer" ] } { frame [ "native_address" ] } ") ;
462
+ bool isNative = ( string ) frame [ "is_managed" ] ! == "false" ;
460
463
461
464
if ( isNative )
462
465
{
463
- string nativeModuleName = ( string ) frame [ "native_module" ] ;
464
- string unmanagedName = ( string ) frame [ "unmanaged_name" ] ;
466
+ var nativeModuleName = ( string ) frame [ "native_module" ] ! ;
467
+ var unmanagedName = ( string ) frame [ "unmanaged_name" ] ! ;
465
468
466
469
if ( ( nativeModuleName != null ) && ( knownNativeModules . Contains ( nativeModuleName ) ) )
467
470
{
468
471
// Need to use llvm-symbolizer (only if module_address != 0)
469
- AppendAddress ( addrBuilder , coreRoot , nativeModuleName , ( string ) frame [ "native_address" ] , ( string ) frame [ "module_address" ] ) ;
472
+ AppendAddress ( addrBuilder , coreRoot , nativeModuleName , ( string ) frame [ "native_address" ] ! , ( string ) frame [ "module_address" ] ! ) ;
470
473
}
471
474
else if ( ( nativeModuleName != null ) || ( unmanagedName != null ) )
472
475
{
@@ -482,8 +485,8 @@ public static bool TryPrintStackTraceFromCrashReport(string crashReportJsonFile,
482
485
}
483
486
else
484
487
{
485
- string fileName = ( string ) frame [ "filename" ] ;
486
- string methodName = ( string ) frame [ "method_name" ] ;
488
+ var fileName = ( string ) frame [ "filename" ] ! ;
489
+ var methodName = ( string ) frame [ "method_name" ] ! ;
487
490
488
491
if ( ( fileName != null ) || ( methodName != null ) )
489
492
{
@@ -507,7 +510,7 @@ public static bool TryPrintStackTraceFromCrashReport(string crashReportJsonFile,
507
510
}
508
511
}
509
512
510
- string symbolizerOutput = null ;
513
+ string ? symbolizerOutput = null ;
511
514
512
515
Process llvmSymbolizer = new Process ( )
513
516
{
@@ -602,7 +605,7 @@ private static void AppendAddress(StringBuilder sb, string coreRoot, string nati
602
605
603
606
public static bool TryPrintStackTraceFromDmp ( string dmpFile , TextWriter outputWriter )
604
607
{
605
- string targetArchitecture = Environment . GetEnvironmentVariable ( TEST_TARGET_ARCHITECTURE_ENVIRONMENT_VAR ) ;
608
+ string ? targetArchitecture = Environment . GetEnvironmentVariable ( TEST_TARGET_ARCHITECTURE_ENVIRONMENT_VAR ) ;
606
609
if ( string . IsNullOrEmpty ( targetArchitecture ) )
607
610
{
608
611
outputWriter . WriteLine ( $ "Environment variable { TEST_TARGET_ARCHITECTURE_ENVIRONMENT_VAR } is not set.") ;
@@ -675,10 +678,10 @@ public int RunTest(string executable, string outputFile, string errorFile, strin
675
678
676
679
// If a timeout was given to us by an environment variable, use it instead of the default
677
680
// timeout.
678
- string environmentVar = Environment . GetEnvironmentVariable ( TIMEOUT_ENVIRONMENT_VAR ) ;
681
+ string ? environmentVar = Environment . GetEnvironmentVariable ( TIMEOUT_ENVIRONMENT_VAR ) ;
679
682
int timeout = environmentVar != null ? int . Parse ( environmentVar ) : DEFAULT_TIMEOUT_MS ;
680
683
bool collectCrashDumps = Environment . GetEnvironmentVariable ( COLLECT_DUMPS_ENVIRONMENT_VAR ) != null ;
681
- string crashDumpFolder = Environment . GetEnvironmentVariable ( CRASH_DUMP_FOLDER_ENVIRONMENT_VAR ) ;
684
+ string ? crashDumpFolder = Environment . GetEnvironmentVariable ( CRASH_DUMP_FOLDER_ENVIRONMENT_VAR ) ;
682
685
683
686
var outputStream = new FileStream ( outputFile , FileMode . Create ) ;
684
687
var errorStream = new FileStream ( errorFile , FileMode . Create ) ;
0 commit comments