Reputation: 5161
I launch my program in C#, which then calls some unmanaged C++.
When I break on a line in the unmanaged C++, the 'New Data Breakpoint' menu item is grayed out.
Is there anyway around this?
Upvotes: 22
Views: 13669
Reputation: 21936
Another way is attaching to the process.
Build and run your software normally without debugger.
Then in Visual Studio, “Debug / Attach to Process” in the top menu, find the process, select it in the list. Then, to the right of “Attach to” panel, click “Select…” button, click the “Debug these code types” radio button, uncheck everything except Native, click OK, click Attach.
Then either break execution with Debug / Break All command, or hit a normal breakpoint somewhere in C++ parts of the app. You’ll then be able to use data breakpoints.
Upvotes: 1
Reputation: 8736
A very useful trick which works everywhere is to call breakpoints from code in special conditions:
If (Condition)
System.Diagnostics.Debugger.Break()
Upvotes: 2
Reputation: 76
The suggested solution doesn't work all the time. Even when debugging in Native mode, with the program broken in Native piece of code, when trying to set a 'New Data Breakpoint' I get a popup "The breakpoint cannot be set. Data breakpoints are not supported in the Common Language Runtime"
The alternative is to add data breakpoints from code directly. See the article here.
This works well in mixed-mode, it only requires Native debugging mode to be active (as suggested above)
Upvotes: 4
Reputation: 5161
So to do this I had to:
yech
Upvotes: 32
Reputation: 11638
To set a data breakpoint in the native portion of a mixed mode process, see the answer posted by jyoung.
Visual Studio disables data breakpoints when running anything but pure, native code. See this post for a partial explanation why from a VS Program Manager.
Upvotes: 16