Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoint on enum creation

I have an enum, and I am trying to figure out what code is actually creating an instance of it. I have a whole lot of code, and I am fairly certain the code that I am looking for is in one of the many obscure projects that is not in my current solution, so find usages won't work.

I know there is no such thing as a constructor on an enum, but I would really like a way to break execution and examine the call stack anytime any code creates and uses this enum. I have tried putting breakpoints on individual enum values, but they never toggle, even when I know they are being used.

Is this possible, or am I going to need to take a different route to find what I am looking for.

like image 399
captncraig Avatar asked Mar 11 '26 14:03

captncraig


1 Answers

Well, it is technically possible, assuming you control the code of the enum itself:

  1. Rename YourEnum to YourEnumInternal
  2. Create class YourEnum and put a Property for each value in YourEnumInternal, with the same name, and return the respective member of YourEnumInternal.
  3. Put breakpoints in every property.

Also, if what you really want to do is look at the callstacks when members of this enum are added to a particular collection (as you said in a comment), why not find usages on the collection (which hopefuly has a smaller scope?) and put breakpoints (or better yet, TracePoints with the $CALLSTACK psuedovariable) wherever items are added to it?

like image 63
Omer Raviv Avatar answered Mar 14 '26 02:03

Omer Raviv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!