Diffing a Watched Var/Object?
August 13, 2023 10:29 AM   Subscribe

I have some code that I try to step and debug with in Python/VSCode .It's a really deeply nested graph, and there's issues with the backtracking. To see where the issue is I want to observe the 2 places this state is changed/not changed and see why it works one place and not the other. I thought it would be cool to somehow "diff" these vars as you step... Somehow take a snapshot of objects/vars at each step with a history saved of the state changes, and then be able to take 2 of them and side by side compare through the steps and any inputs that may have influenced that.

The closest thing I found is something called rr (for deterministic debugging)

But AFAIK it doesn't take snapshots of objects in themselves and diff between them? Also it's C/C++. I did see something similar for python, but not sure any of these would work.
posted by symbioid to Technology (6 answers total) 1 user marked this as a favorite
 
Response by poster: I guess the actual question then is: Is there a tool to do something like this with any arbitrary python code? VSCode integration is nice, but anything would work even if it was a vim plugin or something.
posted by symbioid at 10:41 AM on August 13, 2023


If you have any kind of debugging framework, you should be able to put in non-breaking breakpoints, and have those trigger instead of a break, a dump of your state data. But, I know nothing about python.
posted by Windopaene at 11:03 AM on August 13, 2023


You probably want pdb.
posted by so fucking future at 11:24 AM on August 13, 2023


Response by poster: Thanks for the answers so far. I think my question was more specifically about a side-by-side diff (I did say rr, which seems to match the pdb thing I think on quick glance - but I'm not sure that does the diff thing or even if there's a tool that will do that))

I'm throwing this here, because it seems related to the idea, even if not quite what I'm looking for either and I found while still searching for something.

https://marketplace.visualstudio.com/items?itemName=CodeValueLtd.OzCode
posted by symbioid at 2:21 PM on August 13, 2023


can ya just dump values to stdio?
posted by j_curiouser at 9:24 PM on August 13, 2023


I've found DeepDiff useful for this sort of thing. It doesn't automatically watch for changes, but it is very useful when trying to compare deeply nested objects.
posted by alikins at 3:00 PM on August 16, 2023 [1 favorite]


« Older What is this bright light in Kazakhstan   |   Seeking Android alarm clock app with a specific... Newer »

You are not logged in, either login or create an account to post comments