0

I'm debugging a massive legacy code containing huge file size, bad encapsulation, mixing inheritance, etc.

For example, there is class with _age field:

public class User
{
    private int _age;
    
    //...
}

There are many execution paths that change _age: via Property, base class, protected methods, so on.

How I can suspend execution once this _age has been changed to examine stack trace? IDE does not allow putting breakpoint on this field declaration line. I'm wondering whether Rider IDE has an option for this goal? Or maybe there is some practice/workaround to achieve it.

Adam Shakhabov
  • 1,194
  • 2
  • 14
  • 35

2 Answers2

2

What you are looking for is called a data breakpoint. You can find instructions on how to use them here.

Sohaib Jundi
  • 1,576
  • 2
  • 7
  • 15
  • It would be better if you outlined the details in your answer instead of just linking. Jetbrains have a habit of rearranging their websites every now and then and then your answer will no longer work. – Lasse V. Karlsen Jan 08 '22 at 19:11
  • Yes, this is what I need! I tested on .NET 5 target, and it works. But my project has .NET Framework 4.8. As stated in the article, it requires .NET 3.0 Core+ on Windows. However, the option "Set Data Breakpoint" is also presented while debugging .NET Framework 4.8, but does not affect. – Adam Shakhabov Jan 09 '22 at 08:19
1

Apparently, Rider supports data breakpoints (see the other answer), but if they're not available (e.g. VS, older versions of .NET), you can always temporarily change the field into a property like:

private int _age 
{ 
     get; 
     set;
};

then you can set breakpoints as usual (on set, get or both).

Your statement "... via base class, protected methods, so on." confuses me a bit. How can a private field be accessed via a derived class' base?

PMF
  • 14,535
  • 3
  • 23
  • 49
  • "How can a private field be accessed via a derived class' base?": for example, when base class has protected method `M1()` which changes private field, derived class has public method `M2()` which call `M1()`. – Adam Shakhabov Jan 09 '22 at 08:00
  • You don't have to care about those, because they'll end up in the same private property/field. – PMF Jan 10 '22 at 10:24