Debugging a running .NET application with WinDbg and an AI agent

 
 
  • Gérald Barré

This post is part of the series 'Debugging .NET with an AI agent'. Be sure to check out the rest of the blog posts of the series!

Every post in this series so far started from a file: a dump, a gcdump, a trace. That works as long as the answer is in memory at the moment the file is written. Some answers never are. A dump can show that a value is wrong. It cannot show who wrote it, because by the time the dump is taken, the write is long gone.

That question needs a debugger attached to the running process, one that stops the process when something happens. This post gives an AI agent exactly that: a live WinDbg session, breakpoints, data breakpoints, and raw memory reads. Then it follows the investigation of a bug that no dump can explain.

The workflow from the first post does not carry over as is, and the reason is the most useful part of this post: an agent runs each shell command separately, and a breakpoint does not survive between two of them. The fix is a small MCP server, under 400 lines of C#. The skill is still there, and it still does the teaching.

The sample contains the application, the MCP server, and the skill. Every command output below comes from it, on Windows 11 ARM64 with cdb 10.0.29617.1000, SOS 10.0.14 and .NET 10.0.11.

#The application that fails more and more

PricingService prices an order every 500 milliseconds. When an order fails, it logs the error and moves on, like any service that should not stop for one bad request:

PricingService started, process id 4960. Press Ctrl+C to stop.
Order 1000: 7.25
Order 1001: 37.59
...
Order 1112: 76.29
Order 1113 failed: Invoice total cannot be negative
Order 1114 failed: Invoice total cannot be negative
Order 1115 failed: Invoice total cannot be negative
Order 1116: 36.72

The first orders are fine. After a few seconds some fail, and the longer the process runs, the more of them fail. The code that throws is simple:

C#
sealed class PricingPipeline(IPricingRule[] rules)
{
    public Invoice Price(Cart cart)
    {
        foreach (var rule in rules)
        {
            rule.Apply(cart);
        }

        var subtotal = cart.Subtotal;
        var total = subtotal - cart.Discount;
        if (total < 0)
            throw new InvalidOperationException("Invoice total cannot be negative");

        return new Invoice(cart.OrderId, subtotal, cart.Discount, total);
    }
}

The discount comes from a promotion catalog, loaded once at startup and shared by every order. The catalog defines a single code, SPRING, worth 5.

The bug is in the sample, and in an application this small you could find it by reading. Pretend you cannot: there are forty rules, the catalog comes from a database, and the only thing you have is a log line that gets more frequent every hour.

#Why a dump is not enough here

Take a dump when the exception is thrown, and the approach from the previous posts works up to a point. dumpobj on the cart shows a discount of 49. dumpobj on the promotion shows an amount of 49, where the catalog says 5.

That is where the dump stops. The value is wrong, and it got wrong gradually, since the first orders were fine. Something writes to an object that is supposed to be read only. The dump contains the result of the last write and nothing about the code that performed it.

A debugger can answer that question directly: put a data breakpoint on the memory of that field, let the process run, and the processor stops it on the next write, with the guilty code on the stack. That needs a debugger that stays attached for as long as the investigation takes.

#Why the agent needs an MCP server this time

In the first post, the agent ran dotnet-dump analyze <dump> -c "<command>" -c "exit". Every call reloaded the dump, did its work, and exited. That is fine for a dump, because a dump does not change between two commands.

A live session is different. Setting a breakpoint, resuming the process, and reading the stack when it stops are three steps, and the agent wants to decide the second and third steps after reading the output of the first. If each step is a separate shell command, the debugger exits after the first one, and the breakpoint goes with it. Worse, when a debugger that is attached to a process exits abruptly, Windows terminates the process.

The agent needs a debugger that outlives each tool call. That is what an MCP server is for: a process that the agent starts once, keeps for the whole session, and calls through tools. The skill still matters, because a server that runs commands says nothing about which command to run.

There are community MCP servers for WinDbg, listed at the end of this post. Some wrap the whole debugger engine in dozens of tools. The one in the sample does less on purpose: it keeps one cdb.exe alive and passes commands through. The model already knows the WinDbg command language, so five tools are enough, and every design decision fits in this post.

#Step 1: Install the tools

PowerShell
winget install Microsoft.WinDbg
dotnet tool install --global dotnet-debugger-extensions
dotnet-debugger-extensions install --accept-license-agreement

The WinDbg package includes cdb.exe, the console version of the debugger, and exposes it on the PATH as cdbX64.exe, cdbX86.exe and cdbARM64.exe. dotnet-debugger-extensions installs SOS, the extension that understands .NET, in %USERPROFILE%\.dotnet\sos.

WinDbg can load SOS automatically from its extension gallery. On my machine, cdb printed The call to LoadLibrary(sos) failed instead, so the MCP server loads the installed copy explicitly.

#Step 2: Write the MCP server

##Hosting

The server uses the official C# SDK, the ModelContextProtocol package. The whole Program.cs is the hosting code, with one detail that matters:

C#
var builder = Host.CreateApplicationBuilder(args);

// stdout is the MCP channel: every log must go to stderr
builder.Logging.AddConsole(options => options.LogToStandardErrorThreshold = LogLevel.Trace);

builder.Services.AddSingleton<DebuggerSession>();
builder.Services
    .AddMcpServer()
    .WithStdioServerTransport()
    .WithToolsFromAssembly();

await builder.Build().RunAsync();

A stdio MCP server talks to the agent on its standard output. A single log line written there corrupts the protocol, so all logs go to stderr.

##Tools

The tools are thin wrappers around a singleton DebuggerSession. The descriptions matter more than the code: they are all the agent knows about each tool until it calls it.

C#
[McpServerToolType]
public sealed class DebuggerTools(DebuggerSession session)
{
    [McpServerTool(Name = "execute")]
    [Description("""
        Run one or more cdb commands, separated by ';', and return their output. SOS commands such as !clrstack,
        !dumpobj or !bpmd are available once the process has loaded the .NET runtime.
        'g' resumes the process: the call returns when the process breaks again (breakpoint, exception) or
        when the timeout expires. On timeout the process is still running, call 'wait' or 'break'.
        """)]
    public Task<string> Execute(
        [Description("cdb commands, for instance '!clrstack -a' or 'bl; g'")] string command,
        [Description("Seconds to wait for the command to complete")] int timeoutSeconds = 30,
        CancellationToken cancellationToken = default)
        => session.ExecuteAsync(command, TimeSpan.FromSeconds(timeoutSeconds), cancellationToken);

    // attach, wait, break and detach follow the same pattern
}
ToolWhat it does
attachStarts cdb -pd -lines -p <pid>, loads SOS. The process is frozen afterwards
executeRuns cdb commands and returns their output
waitWaits for a running process to break
breakInterrupts a running process
detachRemoves the breakpoints and lets the process continue

There is no set_breakpoint or read_memory tool. bp, ba, dq and !bpmd are commands the model already knows, and the skill covers the details that trip it up.

##Knowing when a command is done

This is the one hard part. cdb reads commands on its standard input and writes the results on its standard output, but it never says "this command is complete". The prompt (0:000>) looks like an end marker, but it has no newline, and some commands print it several times.

The server sends its own marker after every command:

C#
private async Task<string> SendAsync(string command, TimeSpan timeout, CancellationToken cancellationToken)
{
    _pendingMarker = $"<<mcp-command-complete-{++_markerIndex}>>";
    await _cdb!.StandardInput.WriteLineAsync(command);
    await _cdb.StandardInput.WriteLineAsync(".echo " + _pendingMarker);
    await _cdb.StandardInput.FlushAsync(cancellationToken);
    return await WaitForMarkerAsync(timeout, cancellationToken);
}

A background task appends everything cdb prints to a buffer. WaitForMarkerAsync returns the text that comes before the marker, with the prompts removed.

The same trick handles g, the command that resumes the process. While the process runs, cdb does not read its input, so the .echo is only executed once the process breaks again. "The marker appeared" therefore also means "the process stopped". If the timeout expires first, the marker stays pending, and the tool says so:

[The process is still running after 30s. Call 'wait' to keep waiting, or 'break' to interrupt it.]

wait keeps waiting for the same marker. break calls the Win32 DebugBreakProcess function on the target, which makes it break into the debugger exactly like Ctrl+Break in WinDbg, and then waits for the marker too.

##Not killing the process

Two details keep the debugged process alive whatever the agent does:

  • cdb starts with -pd, so exiting cdb detaches from the process instead of terminating it.
  • DebuggerSession implements IAsyncDisposable. When the agent session ends, the host disposes it, and it breaks into the process if needed and sends qd (quit and detach).

I tested the bad case: attach, resume with g, then close the MCP server while the process is running. The process kept pricing orders, and no cdb.exe was left behind.

##Output size

A command such as !dumpheap can print megabytes of text. The server returns at most 20,000 characters: the first and last 10,000, with a line in the middle that tells the agent to use a more specific command. The agent cannot pipe cdb output through grep the way it did with dotnet-dump, so this limit is the only thing that protects its context.

The server also discards the startup output of attach, a list of every loaded module, and replaces it with three lines: attached or not, .NET runtime loaded or not, SOS loaded or not. It also runs .prompt_allow -dis -ea -reg -src -sym, which stops cdb from printing registers and disassembly every time the process breaks.

#Step 3: Register the server

For Claude Code, a .mcp.json file at the root of the project declares it for everyone who opens that folder:

JSON
{
  "mcpServers": {
    "windbg": {
      "command": "dotnet",
      "args": ["run", "--project", "WinDbgMcp", "--configuration", "Release"]
    }
  }
}

claude mcp add --scope project windbg -- dotnet run --project WinDbgMcp --configuration Release writes the same file. Claude Code asks for confirmation the first time it starts a server declared by a project. GitHub Copilot and Codex have their own configuration files with the same information: a command and its arguments.

dotnet run builds the project the first time, which is a risk for a protocol that runs on standard output. I checked it with no bin or obj folder: the build happened, and the first line on standard output was still the MCP initialize response.

#Step 4: Write the skill

The skill follows the same structure as the one from the first post: how to run the tools, a table from question to command, known limits, rules, and an output format. It lives in .claude/skills/debugging-live-dotnet-processes/SKILL.md, and its description names what someone types when they need it:

Markdown
---
name: debugging-live-dotnet-processes
description: Debug a running .NET process on Windows with WinDbg (cdb) through the windbg MCP tools, using breakpoints, data breakpoints and memory inspection. Use when asked to attach to a process or a pid, to find who modifies a value or calls a method, or when a problem cannot be explained from logs or a dump.
---

The question table is new:

| Question                                  | Commands                                                                 |
| ----------------------------------------- | ------------------------------------------------------------------------ |
| Why is this exception thrown?             | `sxe clr; g`, then `!pe`, `!clrstack -a`, `!dso`, `!dumpobj`             |
| What is the value of this object?         | `!dumpobj <address>`, `!dumpvc <MethodTable> <address>` for a struct      |
| Who calls this method, with which data?   | `!bpmd <module>.dll <Type>.<Method>`, check it with `!dumpmd`, then `g`   |
| Who modifies this field?                  | `ba w8 <address of the field>`, then `g` and `!clrstack`                  |
| Where is an instance of this type?        | `!dumpheap -type <name>`: it is a substring match, check the type column  |

So is a section that the post-mortem skill never needed:

## Before you attach

- Attaching freezes every thread of the process. Never attach to a production process unless the user said so
- Only one session exists at a time. Always call `detach` when you are done, even after an error: it removes
  the breakpoints and lets the process continue

Most of the Known limits section comes from this investigation, and the following sections explain each line.

#Step 5: Ask the question

Start the service, and let it run for a minute:

PowerShell
dotnet run --project PricingService --configuration Release

Then, from the sample folder:

PricingService (process id 4960) logs "Invoice total cannot be negative" for more and more orders.
Attach to it and find the root cause.

"Attach" and "process id" match the description, so the agent loads the skill, and the skill tells it which tools to use.

#Step 6: Follow the investigation

##Stop where the exception is thrown

attach(processId: 4960)

Attached to process 4960 (PricingService). The process is frozen, resume it with 'g'.
The .NET runtime is loaded.
SOS loaded from C:\Users\mezia\.dotnet\sos\sos.dll.

The process is frozen. sxe clr tells the debugger to stop on every .NET exception, as soon as it is thrown (first chance), before any catch runs. g resumes the process:

execute(command: "sxe clr; g")

(1360.1fcc): CLR exception - code e0434352 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.

The process stopped on the throw of an order that is failing right now. !pe confirms which exception it is:

Exception object: 0000020a090b1760
Exception type:   System.InvalidOperationException
Message:          Invoice total cannot be negative

##Optimized code hides its variables

!clrstack -a shows the frame that threw, but not its arguments:

000000A2181BE380 00007FFC771999F0 PricingPipeline.Price(Cart) [C:\demo\PricingService\Program.cs @ 125]
    PARAMETERS:
        this = <no data>
        cart = <no data>

After a minute, Price has run more than a hundred times. The runtime has recompiled it with full optimizations (tiered compilation), and the optimized code keeps cart in a register that is gone by now. A dump of a process that has been running for a while shows the same thing.

!dso lists the objects referenced from the stack instead:

          SP/REG           Object Name
    00a2181bccd8     020a090b1670 System.Collections.Generic.List<CartLine>
    00a2181bcd88     020a090b0e68 System.Collections.Generic.List<CartLine>
    ...
    00a2181be4e0     020a090b0fc8 System.InvalidOperationException
    00a2181be5b0     020a090b15b0 Invoice
    00a2181be5b8     020a090b1720 Cart

There is exactly one Cart. There are also two List<CartLine>, an Invoice that Price never created for this order, and an older exception. !dso scans raw stack memory, which still holds references from previous iterations of the loop. The skill has a line about it: prefer an object that !clrstack -a shows in a caller frame. Main still shows its locals here, and they include 0x0000020a090b1720, the same Cart.

##Read the cart

execute(command: "!dumpobj 020a090b1720")

Name:        Cart
Fields:
              MT    Field   Offset                 Type   VT     Attr            Value Name
00007ffc77147520 0400000d       20         System.Int32  Yes instance             1121 <OrderId>k__BackingField
00007ffc77379ba8 0400000e        8             Customer   No instance 0000020a090b1650 <Customer>k__BackingField
00007ffc7737a0d0 0400000f       10 ... PricingService]]   No instance 0000020a090b1670 <Lines>k__BackingField
00007ffc7716dda0 04000010       18        System.String   No instance 00000211970566b0 <PromotionCode>k__BackingField
00007ffc772206c0 04000011       28       System.Decimal  Yes instance 0000020a090b1748 <Discount>k__BackingField

Order 1121. Discount is a decimal, a struct, so !dumpobj prints its address instead of its value. !dumpvc reads a struct given its method table and its address:

execute(command: "!dumpvc 00007ffc772206c0 0000020a090b1748")

Name:        System.Decimal
Fields:
              MT    Field   Offset                 Type   VT     Attr            Value Name
00007ffc77147520 0400022c        0         System.Int32  Yes instance                0 _flags
00007ffc77156f88 0400022d        4        System.UInt32  Yes instance                0 _hi32
00007ffc7715ba18 0400022e        8        System.UInt64  Yes instance               49 _lo64

A decimal is a 96-bit integer and a scale. _flags is 0, so the scale is 0 and the discount is 49. Following the other fields the same way gives the rest of the picture:

  • PromotionCode is the string SPRING,
  • the customer has Tier = 0, which is CustomerTier.Standard,
  • the cart has one line, quantity 2.

The unit price is another decimal, and this time the agent read the raw memory with dq, which displays 64-bit values:

execute(command: "dq 0000020a090b16d0 L2")

0000020a`090b16d0  00000000`00020000 00000000`000004ee

The third byte of _flags is the scale, 2, and 0x4ee is 1262, so the price is 12.62. The subtotal is 25.24, the discount is 49, and the total is negative. A standard customer, with a promotion worth 5, got 49 off.

##Read the promotion

The promotion is not referenced by the cart, it is in the catalog. !dumpheap -type finds it:

execute(command: "!dumpheap -type Promotion")

         Address               MT           Size
    020a0909e498     7ffc7732df20             24
    020a0909e4b0     7ffc77378480             80
    020a0909e500     7ffc77378408             40
    ...
Statistics:
          MT Count TotalSize Class Name
7ffc7732df20     1        24 PromotionCatalog
7ffc77340a28     1        24 PromotionRule
7ffc77378408     1        40 Promotion

-type is a substring match, so the list includes PromotionCatalog and PromotionRule. The one with the Promotion method table is at 020a0909e500, and there is only one:

execute(command: "!dumpobj 020a0909e500")

Name:        Promotion
Fields:
              MT    Field   Offset                 Type   VT     Attr            Value Name
00007ffc7716dda0 04000012        8        System.String   No instance 00000211970566b0 <Code>k__BackingField
00007ffc772206c0 04000013       10       System.Decimal  Yes instance 0000020a0909e510 <Amount>k__BackingField
execute(command: "dq 020a0909e510 L2")

0000020a`0909e510  00000000`00000000 00000000`00000031

_flags and _hi32 are 0, _lo64 is 0x31: the SPRING promotion is worth 49. The only promotion object in the process, which every order shares, has been modified. This is as far as a dump can go.

##Who writes to it

The Amount field starts at 020a0909e510, and its low 64 bits, the part that changes, are 8 bytes further. A data breakpoint on those 8 bytes stops the process on the next write, whatever code performs it:

execute(command: "sxd clr; ba w8 020a0909e510+8; g")

(1360.1fcc): CLR exception - code e0434352 (first chance)
(1360.1fcc): CLR exception - code e0434352 (first chance)
(1360.1fcc): Break instruction exception - code 80000003 (first chance)

sxd clr was meant to stop breaking on exceptions, and it did, but cdb still prints a line for each of them. sxi clr ignores them completely, and the agent used that later. The third line is the data breakpoint. On ARM64, cdb reports it as a break instruction instead of Breakpoint 0 hit. The stack is what tells the two apart.

execute(command: "!clrstack")

        Child SP               IP Call Site
000000A2181BE340 00007FFC77199B20 GoldCustomerRule.Apply(Cart) [C:\demo\PricingService\Program.cs @ 97]
000000A2181BE380 00007FFC771990FC PricingPipeline.Price(Cart) [C:\demo\PricingService\Program.cs @ 117]
000000A2181BE4B0 00007FFC77185104 Program.<Main>$(System.String[]) [C:\demo\PricingService\Program.cs @ 12]

GoldCustomerRule.Apply, line 97. The stack has no Promotion.set_Amount frame, even though the code assigns a property. The setter was inlined in the optimized Apply. That detail comes back below.

##Confirm it

On ARM64, a data breakpoint stops the process before the write. g executes the same instruction, which triggers the same breakpoint again:

execute(command: "dq 020a0909e510+8 L1")
0000020a`0909e518  00000000`00000031

execute(command: "g; r pc; dq 020a0909e510+8 L1")
(1360.1fcc): Break instruction exception - code 80000003 (first chance)
pc=00007ffc77199b20
0000020a`0909e518  00000000`00000031

Same pc, same value. Disabling the breakpoint, executing one instruction with t, and enabling it again moves past it:

execute(command: "bd 0; t; be 0; dq 020a0909e510+8 L1")
0000020a`0909e518  00000000`00000033

49 became 51: this instruction adds 2 to the promotion. On x64, the processor reports a data breakpoint after the write, so this step is not needed there. The skill carries both cases.

In the optimized Apply, !clrstack -a again prints <no data>, but the caller frame has it this time:

000000A2181BE380 00007FFC771990FC PricingPipeline.Price(Cart) [C:\demo\PricingService\Program.cs @ 117]
    PARAMETERS:
        this = <no data>
        cart (<CLR reg>) = 0x0000020a090b2c88
execute(command: "!dumpobj 0000020a090b2c88")
00007ffc77147520 0400000d       20         System.Int32  Yes instance             1130 <OrderId>k__BackingField

execute(command: "!dumpobj 0000020a090b2bb8")
00007ffc773798e0 04000005       10         System.Int32  Yes instance                1 <Tier>k__BackingField

Order 1130, a Gold customer. One more round, sxi clr; g, stops on order 1141, another Gold customer, and the amount goes from 51 to 53. Then bc * and detach: the process resumes, and keeps logging failures.

##The report

The agent reads line 97 only now, with the evidence in hand:

C#
sealed class GoldCustomerRule(PromotionCatalog catalog) : IPricingRule
{
    public void Apply(Cart cart)
    {
        if (cart.Customer.Tier is not CustomerTier.Gold)
            return;

        var promotion = catalog.Find(cart.PromotionCode);
        if (promotion is null)
            return;

        // Gold customers get 2 more off any promotion
        promotion.Amount += 2m;
    }
}

The root cause: the rule meant to give Gold customers 2 more, and instead added 2 to the catalog's shared Promotion instance. Every Gold order with SPRING makes the promotion 2 bigger for everybody. After enough of them, the promotion is worth more than a small cart, and orders from any customer fail. That explains both the error and why it gets worse over time.

The evidence is two memory reads and one stack: Amount is 49 in the only Promotion object, and the data breakpoint on that field stops in GoldCustomerRule.Apply line 97, where the value goes from 49 to 51, for a Gold customer.

#The fix

The Gold bonus belongs to the cart, not to the catalog:

C#
 // Gold customers get 2 more off any promotion
promotion.Amount += 2m;
cart.Discount += 2m;

A deeper fix makes Promotion.Amount read only ({ get; } or init), so the compiler rejects this kind of bug. A shared object with a public setter is an invitation. Clamping the total to zero in Price would make the error disappear, and give Standard customers their orders for free. Rule 7 of the skill exists for that reason.

#Why not a breakpoint on the setter?

The natural first idea for "who writes this property" is a breakpoint on its setter, and !bpmd accepts it without complaint:

execute(command: "!bpmd PricingService.dll Promotion.set_Amount")

MethodDesc = 00007FFC773683D0
Setting breakpoint: bp 00007FFC7717B63C [Promotion.set_Amount(System.Decimal)]
Adding pending breakpoints...

Attached 8 seconds after startup, this breakpoint hits, and the stack shows GoldCustomerRule.Apply line 97. Attached after 60 seconds, the same command followed by g times out, and keeps timing out while orders go through.

Two effects of tiered compilation combine here. After about 30 calls, the runtime recompiles a method with full optimizations. The optimized GoldCustomerRule.Apply inlines the setter, so the setter's own code no longer runs. A breakpoint on the caller does not work either, and that one is more surprising. !dumpmd, in the same session, shows why:

execute(command: "!bpmd PricingService.dll GoldCustomerRule.Apply")

MethodDesc = 00007FFC773108D0
Setting breakpoint: bp 00007FFC77156504 [GoldCustomerRule.Apply(Cart)]
Adding pending breakpoints...

execute(command: "!dumpmd 00007FFC773108D0")

Current CodeAddr:     00007ffc77169a80
     CodeAddr:           00007ffc771609a0  (QuickJitted + Instrumented)
     CodeAddr:           00007ffc77169a80  (OptimizedTier1)
     CodeAddr:           00007ffc771564e8  (QuickJitted)

The method has three compiled versions. The breakpoint, at 00007FFC77156504, is 0x1c bytes into the first quick JIT-compiled one, which no longer runs. The process executes the OptimizedTier1 version at 00007ffc77169a80. A native breakpoint on the current code address works (this output comes from another run, hence the different addresses):

execute(command: "sxi clr; bp 00007ffc77199a80; g")
Breakpoint 0 hit

execute(command: "!clrstack")
00000015ABF7DCC0 00007FFC77199A80 GoldCustomerRule.Apply(Cart) [C:\demo\PricingService\Program.cs @ 89]

This is the kind of thing a model does not know, and would not guess: !bpmd printed a success message both times. Two lines of the skill cover it:

- `!bpmd` can succeed and never hit. A method that has been called many times is recompiled (tiered
  compilation) and `!bpmd` may bind to the old code. Run `!dumpmd <MethodDesc>`: if the breakpoint address is
  not in the `Current CodeAddr` version, clear it and use `bp <Current CodeAddr>` instead
- A small method, such as a property accessor, is often inlined in its optimized callers. No breakpoint on the
  method itself hits then: use a data breakpoint on the field, or a breakpoint on the caller

The data breakpoint does not care about any of this. It watches memory, not code, so it stops the process whether the write happens in a setter, in an inlined copy of it, or in code that was compiled after the breakpoint was set. It has limits of its own: 4 of them on x64 and only 2 on ARM64, 8 bytes each, and the address is only valid until the GC moves the object. The skill lists those too.

#A live debugger is a production incident

Everything the Dumps contain secrets section of the first post says applies here: dumpobj and dq print customer data into the model context. A live session adds two risks of its own.

  • Attaching freezes the process. Every thread stops, including the ones serving requests, until the agent types g. An agent that reads a long stack before resuming holds the process for that long. Load balancers, health checks and timeouts in callers will notice. Do this on a development machine or on a replica taken out of rotation, never on the instance serving traffic.
  • The agent can change the process. cdb can write memory, change registers and skip instructions. Nothing in the MCP server prevents eq (edit memory) or .kill. If that matters, restrict the commands in DebuggerSession.ExecuteAsync, or configure the agent to ask before each execute call, which Claude Code does by default for MCP tools.

#What the agent gets wrong, and how to fix it

Every mistake below has a fix, and it is always one of three things: a line in the skill, a better prompt, or one command you run yourself.

It sets a breakpoint that never hits, and waits. !bpmd prints a success message, and g times out again and again.

Fix: the two Known limits lines on tiered compilation and inlining, and a data breakpoint when the question is "who writes this".

It reuses addresses from a previous session. After a detach and a new attach, the objects may have moved, and the code certainly has.

Fix: a line in Running the tools: "Addresses change between sessions. Never reuse an address from a previous attach".

It trusts !dso too much. Stale references from previous loop iterations look like current objects. Here, an Invoice sat next to the cart whose pricing had just failed.

Fix: the Known limits line that says to prefer an object that !clrstack -a shows in a caller frame.

It loops on an ARM64 data breakpoint. Every g stops on the same instruction, and the value never changes, which looks like a hang to a model.

Fix: the Known limits line with bd <id>; t; be <id>.

It leaves the process stopped. An agent that ends its turn after attach, to report or to ask a question, leaves the application frozen until the next message.

Fix: rule 5 says to always detach, and the server detaches when the session ends. In the prompt, "then detach" at the end costs nothing.

It reads the source first. Given the question and the repository, the agent can find promotion.Amount += 2m without attaching anything, and it will be right in this sample.

Fix: rule 6, and a prompt about the running process. On a real application with forty rules, "which code writes this field" is a question for the debugger, not for grep. And a data breakpoint answers it in one command.

The six previous posts showed that an agent can read a dump as well as anybody, provided it runs the commands instead of imagining them. This one adds the other half of debugging: stopping a process at the right moment. The only extra piece is a process that holds the debugger between two tool calls. The rest is the same pattern: a skill that grows by one line every time a command surprises you, and a report that quotes every output it relies on.

#Additional resources

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?