|
1 | 1 | using System.Diagnostics; |
2 | 2 | using System.Text; |
3 | 3 | using System.Text.RegularExpressions; |
| 4 | +using System.Runtime.InteropServices; |
4 | 5 |
|
5 | 6 | namespace mcp_nexus.Helper |
6 | 7 | { |
@@ -59,9 +60,21 @@ public Task<bool> StartSession(string target, string? arguments = null) |
59 | 60 |
|
60 | 61 | // Determine if this is a crash dump file (ends with .dmp) |
61 | 62 | var isCrashDump = target.EndsWith(".dmp", StringComparison.OrdinalIgnoreCase) || |
62 | | - target.Contains(".dmp\"", StringComparison.OrdinalIgnoreCase); |
| 63 | + target.Contains(".dmp\"", StringComparison.OrdinalIgnoreCase) || |
| 64 | + target.Contains(".dmp ", StringComparison.OrdinalIgnoreCase); |
63 | 65 |
|
64 | | - var cdbArguments = isCrashDump ? $"-z {target}" : target; |
| 66 | + // For crash dumps, ensure we use -z flag. The target may already contain other arguments. |
| 67 | + string cdbArguments; |
| 68 | + if (isCrashDump && !target.TrimStart().StartsWith("-z", StringComparison.OrdinalIgnoreCase)) |
| 69 | + { |
| 70 | + // If target doesn't already start with -z, add it |
| 71 | + cdbArguments = $"-z {target}"; |
| 72 | + } |
| 73 | + else |
| 74 | + { |
| 75 | + // Target already has proper formatting or is not a crash dump |
| 76 | + cdbArguments = target; |
| 77 | + } |
65 | 78 |
|
66 | 79 | m_Logger.LogDebug("CDB arguments: {Arguments} (isCrashDump: {IsCrashDump})", cdbArguments, isCrashDump); |
67 | 80 |
|
@@ -308,35 +321,100 @@ private bool IsCommandComplete(string line) |
308 | 321 | return isComplete; |
309 | 322 | } |
310 | 323 |
|
| 324 | + private string GetCurrentArchitecture() |
| 325 | + { |
| 326 | + var architecture = RuntimeInformation.ProcessArchitecture; |
| 327 | + m_Logger.LogDebug("Detected process architecture: {Architecture}", architecture); |
| 328 | + |
| 329 | + return architecture switch |
| 330 | + { |
| 331 | + Architecture.X64 => "x64", |
| 332 | + Architecture.X86 => "x86", |
| 333 | + Architecture.Arm64 => "arm64", |
| 334 | + Architecture.Arm => "arm", |
| 335 | + _ => "x64" // Default to x64 for unknown architectures |
| 336 | + }; |
| 337 | + } |
| 338 | + |
311 | 339 | private string FindCDBPath() |
312 | 340 | { |
313 | 341 | m_Logger.LogDebug("FindCDBPath called - searching for CDB executable"); |
314 | 342 |
|
315 | | - var possiblePaths = new[] |
| 343 | + var currentArch = GetCurrentArchitecture(); |
| 344 | + m_Logger.LogInformation("Current machine architecture: {Architecture}", currentArch); |
| 345 | + |
| 346 | + // Create prioritized list based on current architecture |
| 347 | + var possiblePaths = new List<string>(); |
| 348 | + |
| 349 | + // Add paths for current architecture first |
| 350 | + switch (currentArch) |
316 | 351 | { |
317 | | - // ARM64 versions first (for ARM64 crash dumps) |
318 | | - @"C:\Program Files (x86)\Windows Kits\10\Debuggers\arm64\cdb.exe", |
319 | | - @"C:\Program Files\Windows Kits\10\Debuggers\arm64\cdb.exe", |
320 | | - // x64 versions |
321 | | - @"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\cdb.exe", |
322 | | - @"C:\Program Files\Windows Kits\10\Debuggers\x64\cdb.exe", |
323 | | - // x86 versions |
324 | | - @"C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\cdb.exe", |
325 | | - @"C:\Program Files\Windows Kits\10\Debuggers\x86\cdb.exe", |
326 | | - // Legacy debugging tools paths |
327 | | - @"C:\Program Files (x86)\Debugging Tools for Windows (x64)\cdb.exe", |
328 | | - @"C:\Program Files\Debugging Tools for Windows (x64)\cdb.exe", |
329 | | - @"C:\Program Files (x86)\Debugging Tools for Windows (x86)\cdb.exe", |
330 | | - @"C:\Program Files\Debugging Tools for Windows (x86)\cdb.exe" |
331 | | - }; |
| 352 | + case "x64": |
| 353 | + possiblePaths.AddRange(new[] |
| 354 | + { |
| 355 | + @"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\cdb.exe", |
| 356 | + @"C:\Program Files\Windows Kits\10\Debuggers\x64\cdb.exe", |
| 357 | + @"C:\Program Files (x86)\Debugging Tools for Windows (x64)\cdb.exe", |
| 358 | + @"C:\Program Files\Debugging Tools for Windows (x64)\cdb.exe" |
| 359 | + }); |
| 360 | + break; |
| 361 | + case "x86": |
| 362 | + possiblePaths.AddRange(new[] |
| 363 | + { |
| 364 | + @"C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\cdb.exe", |
| 365 | + @"C:\Program Files\Windows Kits\10\Debuggers\x86\cdb.exe", |
| 366 | + @"C:\Program Files (x86)\Debugging Tools for Windows (x86)\cdb.exe", |
| 367 | + @"C:\Program Files\Debugging Tools for Windows (x86)\cdb.exe" |
| 368 | + }); |
| 369 | + break; |
| 370 | + case "arm64": |
| 371 | + possiblePaths.AddRange(new[] |
| 372 | + { |
| 373 | + @"C:\Program Files (x86)\Windows Kits\10\Debuggers\arm64\cdb.exe", |
| 374 | + @"C:\Program Files\Windows Kits\10\Debuggers\arm64\cdb.exe" |
| 375 | + }); |
| 376 | + break; |
| 377 | + } |
| 378 | + |
| 379 | + // Add fallback paths for other architectures |
| 380 | + if (currentArch != "x64") |
| 381 | + { |
| 382 | + possiblePaths.AddRange(new[] |
| 383 | + { |
| 384 | + @"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\cdb.exe", |
| 385 | + @"C:\Program Files\Windows Kits\10\Debuggers\x64\cdb.exe", |
| 386 | + @"C:\Program Files (x86)\Debugging Tools for Windows (x64)\cdb.exe", |
| 387 | + @"C:\Program Files\Debugging Tools for Windows (x64)\cdb.exe" |
| 388 | + }); |
| 389 | + } |
| 390 | + |
| 391 | + if (currentArch != "x86") |
| 392 | + { |
| 393 | + possiblePaths.AddRange(new[] |
| 394 | + { |
| 395 | + @"C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\cdb.exe", |
| 396 | + @"C:\Program Files\Windows Kits\10\Debuggers\x86\cdb.exe", |
| 397 | + @"C:\Program Files (x86)\Debugging Tools for Windows (x86)\cdb.exe", |
| 398 | + @"C:\Program Files\Debugging Tools for Windows (x86)\cdb.exe" |
| 399 | + }); |
| 400 | + } |
| 401 | + |
| 402 | + if (currentArch != "arm64") |
| 403 | + { |
| 404 | + possiblePaths.AddRange(new[] |
| 405 | + { |
| 406 | + @"C:\Program Files (x86)\Windows Kits\10\Debuggers\arm64\cdb.exe", |
| 407 | + @"C:\Program Files\Windows Kits\10\Debuggers\arm64\cdb.exe" |
| 408 | + }); |
| 409 | + } |
332 | 410 |
|
333 | | - m_Logger.LogDebug("Checking {Count} standard CDB paths", possiblePaths.Length); |
| 411 | + m_Logger.LogDebug("Checking {Count} prioritized CDB paths (current arch: {Architecture})", possiblePaths.Count, currentArch); |
334 | 412 | foreach (var path in possiblePaths) |
335 | 413 | { |
336 | 414 | m_Logger.LogTrace("Checking path: {Path}", path); |
337 | 415 | if (File.Exists(path)) |
338 | 416 | { |
339 | | - m_Logger.LogInformation("Found CDB at standard path: {Path}", path); |
| 417 | + m_Logger.LogInformation("Found CDB at path: {Path} (architecture-aware selection)", path); |
340 | 418 | return path; |
341 | 419 | } |
342 | 420 | } |
|
0 commit comments