Skip to content

Commit 273afd9

Browse files
Fix the issue with the cdb from wrong architecture
1 parent 5069857 commit 273afd9

File tree

2 files changed

+99
-21
lines changed

2 files changed

+99
-21
lines changed

mcp_nexus/Helper/CdbSession.cs

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using System.Text;
33
using System.Text.RegularExpressions;
4+
using System.Runtime.InteropServices;
45

56
namespace mcp_nexus.Helper
67
{
@@ -59,9 +60,21 @@ public Task<bool> StartSession(string target, string? arguments = null)
5960

6061
// Determine if this is a crash dump file (ends with .dmp)
6162
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);
6365

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+
}
6578

6679
m_Logger.LogDebug("CDB arguments: {Arguments} (isCrashDump: {IsCrashDump})", cdbArguments, isCrashDump);
6780

@@ -308,35 +321,100 @@ private bool IsCommandComplete(string line)
308321
return isComplete;
309322
}
310323

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+
311339
private string FindCDBPath()
312340
{
313341
m_Logger.LogDebug("FindCDBPath called - searching for CDB executable");
314342

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)
316351
{
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+
}
332410

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);
334412
foreach (var path in possiblePaths)
335413
{
336414
m_Logger.LogTrace("Checking path: {Path}", path);
337415
if (File.Exists(path))
338416
{
339-
m_Logger.LogInformation("Found CDB at standard path: {Path}", path);
417+
m_Logger.LogInformation("Found CDB at path: {Path} (architecture-aware selection)", path);
340418
return path;
341419
}
342420
}

mcp_nexus/Tools/WindbgTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public async Task<string> OpenWindbgDump(string dumpPath, string? symbolsPath =
5757
}
5858
}
5959

60-
var target = symbolsPath != null ? $"-y \"{symbolsPath}\" \"{dumpPath}\"" : $"\"{dumpPath}\"";
60+
var target = symbolsPath != null ? $"-y \"{symbolsPath}\" -z \"{dumpPath}\"" : $"-z \"{dumpPath}\"";
6161
m_Logger.LogDebug("CDB target arguments: {Target}", target);
6262

6363
m_Logger.LogInformation("Starting CDB session for crash dump analysis...");

0 commit comments

Comments
 (0)