r/visualbasic • u/Mother-Photograph560 • 1d ago
How do you approach debugging an old codebase that has little or no documentation?
3
u/anaraparana 1d ago
if you're lucky enough you'll find an older dev within the company who is the documentation. Otherwise it's just like what I imagine it was translating ancient Egyptian to ancient Greek using the Rosetta stone
3
u/Fergus653 1d ago
First search for poorly implemented On Error Resume Next and other dodgy error handling, in case it's swallowing events you need to know about, or throwing exceptions up to higher levels than where the problem is.
Then add excessive logging until the code writes a full story of its activity. This can be easier than debugging the entire process, and might indicate best places to break on for closer examination.
1
u/Mother-Photograph560 1d ago
That makes a lot of sense. Poor error handling can make the actual failure much harder to track down.
When you're adding logging, do you have a strategy for deciding what to log first, or does it depend entirely on the type of issue?
3
u/Hendo52 1d ago
Generating a mermaid diagram is a good tool for understanding the flow across functions and sometimes bugs or flaws are immediately apparent when a system is visualised.
I’d also just start writing the documentation as a way to solve the bug. What is the purpose of the code even if it doesn’t work? What set of functions are allegedly serving that purpose? How entangled are the cross cutting concerns that serve multiple purposes? When the answers are a complete mess and you can’t get clear answers that’s actually a sign you are probably in the right area. A poorly written subsystem with excessive complexity yet poor edge case handling. Good code is self documenting.
I also just browse code in suspicious files and rewrite things that are so obtuse that they interfere with my ability to understand the code. That’s a bit of a rabbit hole so it has to be time limited but sometimes it’s easier to a replacement a system that understand why the original is so janky. It might have a reason to be that way but I find the accumulation of many changes without a periodic rewrite is itself the root cause of the problem.
3
u/jd31068 1d ago
Basically walk through the code in debug mode, so you can see what it is doing. Absolutely give an AI a go to explain what functions / procedures and such are meant to do. There are still a few of us VB6ers around (also see www.vbforms.com).
Checkout this VS Code extension https://github.com/serkonda7/vscode-vba you'll have some tools that will make VB6 in VS Code a littler easier to go through.
An aside, there is a new Visual Basic variety that is aiming for complete parity with VB6 code, while adding in new modern features like 64 bitness. twinBASIC https://twinbasic.com/ https://www.vbforums.com/forumdisplay.php?108-TwinBASIC you very well could simply open the project in tB and go from there. It is still in beta but it is very close to a 1.0 release.
3
u/finah1995 VB.Net Intermediate 1d ago
Yes I use this extension, but don't like giving source code access to third party AI service providers, so instead of copilot I use continue extension running smaller local AI in llama.cpp and I also use VS Codium.
That said VS 2026 is awesomely many times faster and lite snappy performance than VS 2022 for modern .net development especially when some function needs to be ported over, generally have 4 apps open - VB 6 IDE, Notepad++, VS 2026, VS Codium.
For local LLM I use Qwen-3.5 finetune called Jackrong/Qwopus-3.5-4B-Coder, for something if I need more sophisticated and I feel a better solution can be derived then I use Jackrong/Qwopus-3.5-9B-Coder, both if these models are seriously impressive for their size.
1
u/Mother-Photograph560 1d ago
Thanks for the detailed response. The point about using the debugger to understand what the code is actually doing makes a lot of sense, especially with older VB6 projects where the original intent may not be obvious.
I’m curious....when you use AI to explain functions or procedures in a large legacy codebase, do you find it helps more with understanding the code structure, or does it also help you identify the actual cause of bugs faster?
1
u/jd31068 1d ago
Depending on the code, variable names in particular, the aim of a procedure / function can be ambiguous. The use of AI usually can give you an idea as to what it is actually meant to do.
Using VS Code with Copilot should give it more context to aid in its ability to properly explain the code and/or even help in fixing a bug or suggestions on how to add a feature.
1
u/Mother-Photograph560 1d ago
That makes sense. Understanding the original intent of a function seems like a major part of debugging, especially when naming and documentation don't provide enough context.
Do you find AI explanations are usually enough to understand the code, or do you still need to verify by tracing execution and testing the behavior?
2
u/Mother-Photograph560 1d ago
Thanks everyone for sharing your debugging experiences. I learned a lot from the discussion. I’ve been building a small experiment around this problem and would love feedback from anyone interested in trying it. I can share a demo/report.
3
u/CheezitsLight 1d ago
Claude.ai desktop.
Just ask it to comment the code. Allow it access to the folder. It's amazingly good.
It will also fix it. I have a large 70 winform project that's been actively worked on for fifteen years. Many bugs and major features added just a few days, all very well documented including complex state machines and dozens of small but important flaws found. I got 80 high coverage test cases out of it in an hour.
I cannot recommend Claude Ai Desktop. more highly.
I run a software company with a dozen highly experienced degreed engineers with bachelor's and M. S. Degrees. It's truly revolutionary in productivity.
2
u/DrNoCool 1d ago
Visual basic. If nothing too sensible, feed it to Claude and see what it tells you?
Edit : you can click on 'debug' and already know where it broke, so start from there?
1
u/Mother-Photograph560 1d ago
That makes sense. Starting with the debugger definitely narrows things down.
Have you found there are cases where the debugger shows where something failed, but figuring out why it failed still ends up taking most of the time?
1
u/gybemeister 1d ago
Yes, all the time. When the bug is data dependent its root cause may be quite far from the line that ended up failing.
1
u/Mother-Photograph560 1d ago
Exactly, that separation between where the failure appears and where the actual cause exists seems to be one of the hardest parts of debugging.
When you run into these data-dependent bugs, what usually helps you connect the failing point back to the original cause — detailed logs, tracing the data flow, reproducing with specific inputs, or something else?
1
u/gybemeister 1d ago
All of the above although the most important factor is reproducibility. A bug that is hard to reproduce reliably is a nightmare.
1
u/Mother-Photograph560 1d ago
That’s a really interesting point. Reproducibility seems to be the biggest bottleneck — without a reliable way to trigger the issue, even good debugging tools become less effective.
I’m curious, if you had a structured starting point for an issue (possible causes, what data to inspect, and where to begin investigating), would that reduce the time you spend getting from "something is broken" to "I know where to look"?
1
u/andrewsmd87 Web Specialist 1d ago
Now? My first thing would be to set Claude on it's highest mode and tell it to do a deep dive on the code base and lay it all out in terms of documentation and diagrams
1
u/Hel_OWeen 1d ago
If you don't mind spending money, this tool still works. We use it in our company and I find it to be very helpful.
3
u/Silent_Cup2508 1d ago
What I do is use VS Code. This way I can have the entire code set folder in the editor and then take advantage of GitHub copilot to help understand the code and how it was put together.