Question

In: Computer Science

Describe options for debugging applications and specifically how you can debug an application with Visual Studio...

Describe options for debugging applications and specifically how you can debug an application with Visual Studio Code.

Solutions

Expert Solution

Answer:-

Describe options for debugging applications

1. Observe: What are the symptoms? Subtle details are often important. Once, for example, the absence of an error message indicated to me that some piece of code was not being run (which implied that the bug was further up the stack).

BTW: I sometimes find that the process of describing a bug to someone else helps me to fix it. Verbalizing what I think is going on often helps me to think more clearly about the problem.

2. Propose a hypothesis: What explains the observations? Don't start blindly chaging things. Try to imagine what could be going wrong (even if it seems improbable at first). You may come up with multiple hypotheses (a pointer might be NULL because it was never set OR because it got clobbered); try to falsify as many hypotheses as you can (e.g., the pointer is clearly set here, so it must be getting clobbered later.)

You may not be able to come up with a full explanation right away. For example, sometimes I realize that a crash could happen if function B is called before function A, but I don't know how that sequence could happen. Test your hypothesis anyway: either way you've narrowed the problem space.

3. Design an experiment: To test your hypothesis, come up with a change that would indicate whether your hypothesis is right or wrong. This is where Pete Lamonica's advice about making only one change at a time is important.

Also, it never hurts to get as much data as possible. Once, to find a rare bug, I added some debug code that would print out the value of a variable when the bug occurred. Sure enough, the output confirmed what I suspected (that the variable was NULL) but I neglected to add other printfs that help me figure out why the variable was NULL. I should have had several guesses for why the variable was NULL and add enough printfs to prove/disprove as many as possible.

4. Understand the results: Finally, it is important to come to as full an understanding as possible. Sometimes you make a fix and the problem goes away. But unless you understand why the fix fixed it, you can't be sure that you addressed the full problem. For example, sometimes the real bug is a race-condition and any change "fixes" it by changing the timing slightly.

how you can debug an application with Visual Studio Code.

One of the key features of Visual Studio Code is its great debugging support. VS Code's built-in debugger helps accelerate your edit, compile and debug loop.

Debugger extensions#

VS Code has built-in debugging support for the Node.js runtime and can debug JavaScript, TypeScript, or any other language that gets transpiled to JavaScript.

For debugging other languages and runtimes (including PHP, Ruby, Go, C#, Python, C++, PowerShell and many others), look for Debuggers extensions in our VS Code Marketplace or select Install Additional Debuggers in the top-level Run menu.

Start debugging#

The following documentation is based on the built-in Node.js debugger, but most of the concepts and features are applicable to other debuggers as well.

It is helpful to first create a sample Node.js application before reading about debugging. You can follow the Node.js walkthrough to install Node.js and create a simple "Hello World" JavaScript application (app.js). Once you have a simple application set up, this page will take you through VS Code debugging features.

Run view#

To bring up the Run view, select the Run icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D.

The Run view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.

If running and debugging is not yet configured (no launch.json has been created) we show the Run start view.

Run menu#

The top-level Run menu has the most common run and debug commands:

Launch configurations#

To run or debug a simple app in VS Code, press F5 and VS Code will try to run your currently active file.

However, for most debugging scenarios, creating a launch configuration file is beneficial because it allows you to configure and save debugging setup details. VS Code keeps debugging configuration information in a launch.json file located in a .vscode folder in your workspace (project root folder) or in your user settings or workspace settings.

To create a launch.json file, open your project folder in VS Code (File > Open Folder) and then select the Configure gear icon on the Run view top bar.

VS Code will try to automatically detect your debug environment, but if this fails, you will have to choose it manually:

Here is the launch configuration generated for Node.js debugging:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${file}"
    }
  ]
}

If you go back to the File Explorer view (Ctrl+Shift+E), you'll see that VS Code has created a .vscode folder and added the launch.json file to your workspace.

Note: You can debug a simple application even if you don't have a folder open in VS Code, but it is not possible to manage launch configurations and set up advanced debugging. The VS Code Status Bar is purple if you do not have a folder open.

Note that the attributes available in launch configurations vary from debugger to debugger. You can use IntelliSense suggestions (Ctrl+Space) to find out which attributes exist for a specific debugger. Hover help is also available for all attributes.

Do not assume that an attribute that is available for one debugger automatically works for other debuggers too. If you see green squiggles in your launch configuration, hover over them to learn what the problem is and try to fix them before launching a debug session.

Review all automatically generated values and make sure that they make sense for your project and debugging environment.

Launch versus attach configurations#

In VS Code, there are two core debugging modes, Launch and Attach, which handle two different workflows and segments of developers. Depending on your workflow, it can be confusing to know what type of configuration is appropriate for your project.

If you come from a browser Developer Tools background, you might not be used to "launching from your tool," since your browser instance is already open. When you open DevTools, you are simply attaching DevTools to your open browser tab. On the other hand, if you come from a server or desktop background, it's quite normal to have your editor launch your process for you, and your editor automatically attaches its debugger to the newly launched process.

The best way to explain the difference between launch and attach is to think of a launch configuration as a recipe for how to start your app in debug mode before VS Code attaches to it, while an attach configuration is a recipe for how to connect VS Code's debugger to an app or process that's already running.

VS Code debuggers typically support launching a program in debug mode or attaching to an already running program in debug mode. Depending on the request (attach or launch), different attributes are required, and VS Code's launch.json validation and suggestions should help with that.

Add a new configuration#

To add a new configuration to an existing launch.json, use one of the following techniques:

  • Use IntelliSense if your cursor is located inside the configurations array.
  • Press the Add Configuration button to invoke snippet IntelliSense at the start of the array.
  • Choose Add Configuration option in the Run menu.

VS Code also supports compound launch configurations for starting multiple configurations at the same time; for more details, please read this section.

In order to start a debug session, first select the configuration named Launch Program using the Configuration drop-down in the Run view. Once you have your launch configuration set, start your debug session with F5.

Alternatively you can run your configuration through the Command Palette (Ctrl+Shift+P), by filtering on Debug: Select and Start Debugging or typing 'debug ', and selecting the configuration you want to debug.

As soon as a debugging session starts, the DEBUG CONSOLE panel is displayed and shows debugging output, and the Status Bar changes color (orange for default color themes):

In addition, the debug status appears in the Status Bar showing the active debug configuration. By selecting the debug status, a user can change the active launch configuration and start debugging without needing to open the Run view.

Debug actions#

Once a debug session starts, the Debug toolbar will appear on the top of the editor.

  • Continue / Pause F5
  • Step Over F10
  • Step Into F11
  • Step Out Shift+F11
  • Restart Ctrl+Shift+F5
  • Stop Shift+F5

Tip: Use the setting debug.toolBarLocation to control the location of the debug toolbar. It can either be the default floating, docked to the Run view or hidden. A floating debug toolbar can be dragged


Related Solutions

ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this part of the assignment, you are required to create a C# Console Application project. The project name should be A3<FirstName><LastName>P2. For example, a student with first name John and Last name Smith would name the project A1JohnSmithP2. Write a C# (console) program to calculate the number of shipping labels that can be printed on a sheet of paper. This program will use a menu...
Using Visual Studio in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
how can i make in visual studio a farm wide solution for SP 2013. a marquee...
how can i make in visual studio a farm wide solution for SP 2013. a marquee that conects to the announcement list amd shows this message in my whole farm (or similar). Thank You in advance
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select (...
C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select ( integer, string, date ) After selecting the desired dropdown option, user can input a list of inputs. For example; for integer: 2,5,7,9,1,3,4 And then , I have a 'sort' button Can you please help me with the code behind for sorting them( For integer, string, and date ) Thank you.
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You will be simulating an ATM machine as much as possible Pretend you have an initial deposit of 1000.00. You will Prompt the user with a Main menu: Enter 1 to deposit Enter 2 to Withdraw Enter 3 to Print Balance Enter 4 to quit When the user enters 1 in the main menu, your program will prompt the user to enter the deposit amount....
Visual Studio C# Create an application illustrating the following: Class definition Encapsulation Constructor Instantiation Inheritance Suggestions:...
Visual Studio C# Create an application illustrating the following: Class definition Encapsulation Constructor Instantiation Inheritance Suggestions: Simulation Calculation Interface apps
In this assessment, you will debug and fix a given Java console application that uses 2...
In this assessment, you will debug and fix a given Java console application that uses 2 dimensional arrays but the application does not compile nor execute. You can use either the Toolwire environment or your local Java development environment to complete this assignment.The application has four bugs. Your assignment is to find these bugs and fix them so that the application meets its stated requirements.The requirements of this application are as follows: The application is register students for courses in...
In this assessment, you will debug and fix a given Java console application that uses 2...
In this assessment, you will debug and fix a given Java console application that uses 2 dimensional arrays but the application does not compile nor execute. You can use either the Toolwire environment or your local Java development environment to complete this assignment.The application has four bugs. Your assignment is to find these bugs and fix them so that the application meets its stated requirements.The requirements of this application are as follows: The application is register students for courses in...
How do you the practical properties and visual applications of painting media influence our the selection...
How do you the practical properties and visual applications of painting media influence our the selection of process and medium? Might one media better suit the message an artist wants to communicate when they create their work then another? Explain. Printmaking is a process oriented medium. Many of the artist who work in this medium enjoy the step-by-step character of the process, and the stark graphic quality of prints. Why would an artist who wants an unlimited number of prints...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT