Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find what variable a value is assigned to?

I'm debugging on an old C# application. There is a screen where I can click to run a query against a server and get a list of results.

The problem is that I'm having trouble figuring out how the results are computed. Each result has a floating-point number associated with it that is displayed on the screen. Suppose, for the sake of discussion, that the number next to the first result is 123.45.

I would guess that the number 123.45 must be assigned to a floating-point variable at some point, but if there are millions of lines of code, I have a lot of digging to do!

Therefore, I was wondering that if I'm certain that the number 123.45 is assigned to a variable at some point, is there some convenient way to find where it happens and what variable it is assigned to? Is there a debugging tool that does this?

Edit: The commenters here are correct to point out that I don't know for sure that the number is assigned to a variable; I'm just guessing that it likely is. Also, I'm familiar with setting conditions on breakpoints, but that won't help here because to set a breakpoint, you have to know what line the assignment occurs on.

My question here is whether or not there is a way to detect a particular value being assigned in an unknown place in the code to an unknown variable. I want to find where the assignment occurs, and which variable it is assigned to.

Second Edit: Let's compare this to using the SQL profiler. If I know that the value 123.45 is being inserted into a table or passed as a parameter to a stored procedure, I can use the SQL profiler and filter the command text for commands that contain the string "123.45". That would likely find the exact command used to send 123.45 to the SQL server. Is there something similar I can do if I'm looking for the value to be assigned to a C# variable, but I don't know which one?

I think that the answer is probably "no", but I thought someone here might be able to shed some light on this.

like image 328
Vivian River Avatar asked Jan 01 '26 02:01

Vivian River


1 Answers

If you can narrow it down to the different UI dispatchers that update your screen, you can add a condition that checks for that particular value, like this:

enter image description here

enter image description here

enter image description here

enter image description here

like image 94
Jeroen Vannevel Avatar answered Jan 02 '26 16:01

Jeroen Vannevel



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!