How do I set a Data Breakpoint in mixed( C#/C++ ) debugging?
Asked Answered
B

5

22

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?

Brigantine answered 28/10, 2008 at 13:39 Comment(0)
T
16

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.

Toady answered 28/10, 2008 at 14:27 Comment(1)
"partial explanation" = the team never wrote code for this.Momentous
B
32

So to do this I had to:

  • set the unmanaged dll as the startup project
  • set the managed program as the startup command
  • set debug mode as Native
  • "break execution" or hit a breakpoint so that you are in the "debugging" state

yech

Brigantine answered 28/10, 2008 at 15:3 Comment(4)
Quick note: As you mentioned in your question, your program must be in a "break" state for the menu option to become available.Tycoon
I can never upvote this answer enough. Thanks again for this detailed procedure.Ulphia
I wish this had worked for me...instead I get this on startup: An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll Additional information: 'The invocation of the constructor on type 'ATMapExec2WPF.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'. Obviously, there's nothing wrong with my XAML file...it works otherwise. This is not your fault, though...this is an ongoing nightmare with WPF debugging.Witchy
The steps 2 and 3 are set on the Properties Window of the native project, Debug tab.Butterball
T
16

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.

Toady answered 28/10, 2008 at 14:27 Comment(1)
"partial explanation" = the team never wrote code for this.Momentous
S
4

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)

Siblee answered 7/5, 2013 at 22:55 Comment(0)
H
2

A very useful trick which works everywhere is to call breakpoints from code in special conditions:

If (Condition)
    System.Diagnostics.Debugger.Break()
Haleigh answered 10/1, 2016 at 17:27 Comment(0)
L
1

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.

enter image description here

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.

Lancinate answered 15/2, 2022 at 1:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.