Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio breakpoints -- break on specific file access

Is there any way of having a VS debug session break when a specific file is read from or written to?

In this case I'd want to use it as an exploratory tool -- assume I don't know where in a large codebase this file is being accessed from, or where the filename is being set -- it might be picked up from deep in some large scale config.

like image 307
Tim Barrass Avatar asked Dec 15 '10 14:12

Tim Barrass


People also ask

How do I add a conditional breakpoint in Visual Studio?

Right-click the breakpoint symbol and select Conditions (or press Alt + F9, C). Or hover over the breakpoint symbol, select the Settings icon, and then select Conditions in the Breakpoint Settings window.

What is a conditional breakpoint?

Conditional breakpoints allow you to break inside a code block when a defined expression evaluates to true. Conditional breakpoints highlight as orange instead of blue. Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression.

How do I skip a breakpoint in Visual Studio?

You can disable all breakpoints in one of the following ways: On the Debug menu, click Disable All Breakpoints. On the toolbar of the Breakpoints window, click the Disable All Breakpoints button.


1 Answers

What I would do is just quickly hack up a static class that uses the FileSystemWatcher class to listen to file create/changed events, and put a breakpoint in the event callback, or put a call to System.Diagnostics.Debugger.Break there.

Then, when it breaks, switch to the Threads window and try to locate the thread and the piece of code that did the actual file-access.

If you need to use this a lot, have this class maintain a list of specific file names you want to break on, and expose two public static methods: to Start and Stop listening to changes in a specific file.

Also, if you have VS2010 Ultimate you could simply search through the list of File Created events in the IntelliTrace events log.

like image 117
Omer Raviv Avatar answered Sep 21 '22 05:09

Omer Raviv