Click here to Skip to main content
13,252,933 members (50,642 online)
Click here to Skip to main content
Add your own
alternative version

Stats

3.2K views
1 bookmarked
Posted 19 Mar 2017

Using "Run To Cursor" from the Call-stack Window

, 20 Mar 2017
Rate this:
Please Sign up or sign in to vote.
Quickly move from one method to another during debugging session

Almost all software developers using Visual Studio are well aware of the most common debugging functions provided in Visual Studio. For example, functionality like “Step Into”, “Step Over” and “Step Out” as shown in figure 1 are few tasks that developers perform quite frequently during their day to day job.

However, with the advent of use of Fluent APIs and method chaining techniques (heavily used in frameworks like Linq), some of these tasks can become quite repetitive and cumbersome. Let’s say, you have extended the FileInfo class using Extension methods as follows:

public static class FileInfoExtension
{
    public static IEnumerable<FileInfo>
    IsAcceptableFileType(this IEnumerable<FileInfo> files)
    {
        foreach (FileInfo file in files)
        {
            if (file.Extension == ".jpg" || file.Extension == ".png" )
                yield return file;
        }
    }

    public static IEnumerable<FileInfo>
    IsAcceptableFileSize(this IEnumerable<FileInfo> files)
    {
        foreach (FileInfo file in files)
        {
            if ( file.Length < 1024*2024)
                yield return file;
        }
    }

    public static IEnumerable<FileInfo>
    IsAcceptableFileName(this IEnumerable<FileInfo> files)
    {
        foreach (FileInfo file in files)
        {
            if (file.Name.StartsWith("Figure"))
                yield return file;
        }
    }
}

Nothing as a rocket science in this code, just filtering a List of FileInfo class instances based on file type, file size and file name. Here is an example of how these extension methods are used in the code.

class Program
{
    static void Main(string[] args)
    {
        string path = @"C:\my\CallstackRelatedDemo";
        DirectoryInfo di = new DirectoryInfo(path);
        if (di.Exists)
        {
            var results = di.GetFiles()
                            .ToList()
                            .IsAcceptableFileType()
                            .IsAcceptableFileSize()
                            .IsAcceptableFileName()
                            .Select( x => new
                                {
                                    FileName = x.Name,
                                    Extension = x.Extension,
                                    SizeInKB = x.Length/1024
                                })
                            .ToList();

        }
    }
}

Let’s say during the debugging session, developer steps into the IsAcceptableFileType method. At this point, call-stack will look as follows:

If developer wants to continue troubleshooting in IsAcceptableFileName method, she can certainly use “Step Into” and “Step Over” functions but this could be a longer route to get to that method. An easier way is to use “Run To Cursor” approach available within the call-stack window. Right clicking in the call-stack window on the IsAcceptableFileName, a context menu will be displayed as shown in figure 3 below.

Choosing “Run To Cursor” item from this context menu will take the developer directly to IsAcceptableFileName method as shown below:

This way, you don’t have to click F10/F11/Ctrl+F11 keys multiple times and with just one click, you can start troubleshooting in the method you desire.

Until next, happy debugging.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Kamran Bilgrami
Architect
Canada Canada
Kamran Bilgrami is a seasoned software developer with background in designing mission critical applications for carrier grade telecom networks. More recently he is involved in design & development of real-time biometric based security solutions. His areas of interest include .NET, software security, mathematical modeling and patterns.

He blogs regularly at http://WindowsDebugging.Wordpress.com

You may also be interested in...

Pro
Pro

Comments and Discussions

 
Questionlast image is missing Pin
Tridip Bhattacharjee19-Mar-17 23:26
professionalTridip Bhattacharjee19-Mar-17 23:26 
AnswerRe: last image is missing Pin
Kamran Bilgrami20-Mar-17 5:59
memberKamran Bilgrami20-Mar-17 5:59 
PraiseNice topic Pin
Nirav Prabtani19-Mar-17 22:55
professionalNirav Prabtani19-Mar-17 22:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 20 Mar 2017
Article Copyright 2017 by Kamran Bilgrami
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid