Skip to content

Commit b1546ad

Browse files
Fix some ground rules issues and enhance the stack downloader extension
1 parent 3a96c11 commit b1546ad

File tree

3 files changed

+58
-25
lines changed

3 files changed

+58
-25
lines changed

mcp_nexus/Extensions/ExtensionExecutor.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ private IProcessHandle CreateProcess(
334334
// Try to find PowerShell - prefer pwsh (PowerShell 7+), fall back to powershell (5.1)
335335
string? powershellPath = FindPowerShell() ?? throw new InvalidOperationException("PowerShell not found. Please ensure pwsh.exe or powershell.exe is in PATH or installed.");
336336
fileName = powershellPath;
337-
337+
338338
// Build PowerShell arguments with parameters
339339
var argumentsBuilder = new StringBuilder();
340340
argumentsBuilder.Append($"-NoProfile -ExecutionPolicy Bypass -File \"{metadata.FullScriptPath}\"");
341-
341+
342342
// Add parameters as PowerShell command-line arguments
343343
if (parameters != null)
344344
{
@@ -349,7 +349,7 @@ private IProcessHandle CreateProcess(
349349
argumentsBuilder.Append(paramArgs);
350350
}
351351
}
352-
352+
353353
arguments = argumentsBuilder.ToString();
354354
}
355355
else
@@ -385,7 +385,7 @@ private string BuildPowerShellParameterArguments(object parameters)
385385
if (parameters is JsonElement jsonElement)
386386
{
387387
m_Logger.LogDebug("Parameters is a JsonElement, type: {Type}", jsonElement.ValueKind);
388-
388+
389389
// If JsonElement is a string, it's a JSON string that needs to be unwrapped
390390
if (jsonElement.ValueKind == JsonValueKind.String)
391391
{
@@ -432,7 +432,7 @@ private string BuildPowerShellParameterArguments(object parameters)
432432
{
433433
// Convert camelCase to PascalCase for PowerShell convention
434434
var paramName = char.ToUpper(property.Name[0]) + property.Name[1..];
435-
435+
436436
if (argumentsBuilder.Length > 0)
437437
argumentsBuilder.Append(' ');
438438

@@ -443,9 +443,9 @@ private string BuildPowerShellParameterArguments(object parameters)
443443
{
444444
case JsonValueKind.String:
445445
var stringValue = property.Value.GetString() ?? string.Empty;
446-
446+
447447
// Only quote if the value contains spaces or special characters
448-
if (stringValue.Contains(' ') || stringValue.Contains('"') || stringValue.Contains('\'') ||
448+
if (stringValue.Contains(' ') || stringValue.Contains('"') || stringValue.Contains('\'') ||
449449
stringValue.Contains('$') || stringValue.Contains('`') || string.IsNullOrWhiteSpace(stringValue))
450450
{
451451
// Escape single quotes and wrap in single quotes

mcp_nexus/Extensions/stack_with_sources/stack_with_sources.ps1

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ $threadDisplay = if ($ThreadId -eq ".") { "current thread" } else { "thread $Thr
3535
Write-NexusProgress "Starting stack analysis with source download for $threadDisplay"
3636

3737
try {
38+
Write-NexusProgress "Enable source verbosity for $threadDisplay..."
39+
$stackOutput = Invoke-NexusCommand ".srcnoisy 3"
40+
3841
# Step 1: Get stack with line numbers
3942
Write-NexusProgress "Retrieving stack trace for $threadDisplay..."
4043
$stackCommand = if ($ThreadId -eq ".") { "kL" } else { "~${ThreadId}kL" }
@@ -64,7 +67,8 @@ try {
6467
addresses = @()
6568
error = "Thread '$ThreadId' not found. The thread ID may be invalid or the thread may not exist in this dump file."
6669
suggestion = "Use the '!threads' or '~' command to list available threads, then try again with a valid thread ID."
67-
} | ConvertTo-Json
70+
stackTrace = $stackOutput
71+
} | ConvertTo-Json -Depth 10
6872
Write-Output $result
6973
exit 0
7074
}
@@ -99,51 +103,78 @@ try {
99103
sourcesDownloaded = 0
100104
addresses = @()
101105
error = "No valid return addresses found in stack trace"
102-
} | ConvertTo-Json
106+
stackTrace = $stackOutput
107+
} | ConvertTo-Json -Depth 10
103108
Write-Output $result
104109
exit 0
105110
}
106111

107112
Write-NexusLog "Found $($addresses.Count) return addresses to process" -Level Information
108113
Write-NexusProgress "Found $($addresses.Count) return addresses to process"
109114

110-
# Step 3: Download sources for each address
115+
# Step 3: Download sources for each address (first pass)
116+
Write-NexusProgress "[$threadDisplay] Downloading sources for $($addresses.Count) addresses..."
117+
$processedCount = 0
118+
119+
foreach ($addr in $addresses) {
120+
$processedCount++
121+
$percent = [int](($processedCount / $addresses.Count) * 100)
122+
Write-NexusProgress "[$threadDisplay] Downloading source for address $addr ($processedCount of $($addresses.Count), $percent%)"
123+
124+
try {
125+
# First pass: Just download, don't verify yet
126+
$null = Invoke-NexusCommand "lsa $addr"
127+
}
128+
catch {
129+
Write-NexusLog "Failed to execute lsa for address $addr`: $_" -Level Warning
130+
}
131+
}
132+
133+
# Step 4: Verify downloaded sources (second pass)
134+
Write-NexusProgress "[$threadDisplay] Verifying downloaded sources..."
111135
$downloadedCount = 0
112136
$failedAddresses = @()
113137
$processedCount = 0
114-
138+
$sourceOutputs = @{} # Collect all lsa outputs
139+
115140
foreach ($addr in $addresses) {
116141
$processedCount++
117142
$percent = [int](($processedCount / $addresses.Count) * 100)
118-
Write-NexusProgress "[$threadDisplay] Downloading source for address $addr ($processedCount of $($addresses.Count), $percent%)"
119-
143+
Write-NexusProgress "[$threadDisplay] Verifying source for address $addr ($processedCount of $($addresses.Count), $percent%)"
144+
120145
try {
121-
$lsaOutput = Invoke-NexusCommand "lsa $addr"
146+
$verifyOutput = Invoke-NexusCommand "lsa $addr"
147+
$sourceOutputs[$addr] = $verifyOutput
122148

123-
# Check if source was actually downloaded
124-
if ($lsaOutput -match 'source' -or $lsaOutput -match '\.c' -or $lsaOutput -match '\.cpp' -or $lsaOutput -match '\.h') {
149+
# Check if source was found in cache (with .srcnoisy 3, should show "already loaded")
150+
# Also accept if output shows line numbers (source is displayed)
151+
if ($verifyOutput -match 'Found already loaded file:|already loaded' -or
152+
$verifyOutput -match '^\s*\d+:') {
125153
$downloadedCount++
154+
Write-NexusLog "[$threadDisplay] Verified source for address $addr (cached)" -Level Debug
126155
}
127156
else {
128157
$failedAddresses += $addr
158+
Write-NexusLog "[$threadDisplay] No source found for address $addr" -Level Debug
129159
}
130160
}
131161
catch {
132-
Write-Warning "Failed to download source for address $addr`: $_"
133162
$failedAddresses += $addr
163+
$sourceOutputs[$addr] = "ERROR: $_"
164+
Write-NexusLog "Failed to verify source for address $addr`: $_" -Level Warning
134165
}
135166
}
136167

137-
Write-NexusProgress "[$threadDisplay] Source download complete: $downloadedCount of $($addresses.Count) sources downloaded"
168+
Write-NexusProgress "[$threadDisplay] Source download complete: $downloadedCount of $($addresses.Count) sources verified"
138169

139170
$successRate = [math]::Round(($downloadedCount / $addresses.Count) * 100, 2)
140-
Write-NexusLog "[$threadDisplay] Source download completed: $downloadedCount/$($addresses.Count) sources ($successRate% success rate)" -Level Information
171+
Write-NexusLog "[$threadDisplay] Source download completed: $downloadedCount/$($addresses.Count) sources verified ($successRate% success rate)" -Level Information
141172

142173
if ($failedAddresses.Count -gt 0) {
143174
Write-NexusLog "Failed to download sources for $($failedAddresses.Count) addresses" -Level Warning
144175
}
145176

146-
# Return structured result
177+
# Return structured result with all command outputs
147178
$result = @{
148179
success = $true
149180
threadId = $ThreadId
@@ -153,8 +184,10 @@ try {
153184
successRate = $successRate
154185
addresses = $addresses
155186
failedAddresses = $failedAddresses
156-
message = "Successfully downloaded $downloadedCount of $($addresses.Count) source files"
157-
} | ConvertTo-Json
187+
message = "Successfully downloaded and verified $downloadedCount of $($addresses.Count) source files"
188+
stackTrace = $stackOutput
189+
sourceOutputs = $sourceOutputs
190+
} | ConvertTo-Json -Depth 10
158191

159192
Write-Output $result
160193
exit 0

mcp_nexus/mcp_nexus.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
88
<WarningsAsErrors />
9-
<Version>1.0.6.85</Version>
10-
<AssemblyVersion>1.0.6.85</AssemblyVersion>
11-
<FileVersion>1.0.6.85</FileVersion>
9+
<Version>1.0.6.86</Version>
10+
<AssemblyVersion>1.0.6.86</AssemblyVersion>
11+
<FileVersion>1.0.6.86</FileVersion>
1212
<Product>MCP Nexus</Product>
1313
<Description>Model Context Protocol Server for Windows Debugging Tools</Description>
1414
<Company>CapulusCodeNinja</Company>

0 commit comments

Comments
 (0)