[Edit, Aug 2010:] About a year after this trial-and-error-ish investigation, I accidently found this hidden bit of documentation which pretty much sums it up.
The context operator is technically documented, although barely so. Seemed to me the reason is that it’s mostly broken – but turns out you can in fact get some value out of it.
The documented syntax template is:
{[function],[source],[module] } location
(it is one of 3 different templates, but that’s the one that’s useful to me). Apparently these names have different meaning in different contexts.
Broken, Official Syntax
Here ‘function’ seems to mean function name, ‘source’ means source file, ‘location’ means line number in source file. Some of the documented examples prefix it with ‘@’, others with ‘.’. (edit: this is explicitly acknowledged elsewhere, but never explained). From brief experimenting, however, none of these are working and this feature seems all but completely broken.
{,MySource.cpp,}@20
can get you to break at random locations in the file, or refuse to parse altogether.
{MyFunc, MyApp.cpp,}@3
May actually work. May also set the break location at a different line in the function. If the specified line is out of the function range, it may either set a break at a seemingly random source location or fail to parse.
etc. etc. Documentation hasn’t changed between VS2003 and VS2010, and it seems these issues aren’t going anywhere anytime soon.
Working, Not-Really-Official Syntax
Turns out if you interpret ‘location’ as a function name, you may actually get some work done. This is mentioned as a single-line example in the VC6 documentation, and also sporadically on the web. For example:
{,,}MyFunc
Actually works.
With slight modifications (that Gregg does not mention), this can be used to break into functions with no source code: (a) include the module (i.e., exe/dll name) and (b) use decorated function names (this is said to be redundant since VS2008). Needless to say, if you intend to break in MS functions (Win32, CRT or other), you’d need to obtain public MS symbols – maybe more on that in a future post.
For example,
{,,}OutputDebugStringW
would fail to parse,
{,,}_OutputDebugStringW@4
would parse successfully but will not set a break, and finally –
{,,kernel32.dll}_OutputDebugStringW@4
would get the job done.
Getting decorated names can be much easier than stated before, since most interesting MS functions are C functions: the decorated name (and module) can be viewed in the call-stack window, by stepping into the function (in disassembly):