Debugging Building Rock-Solid Software Software University Technical Trainers SoftUni Team.

Slides:



Advertisements
Similar presentations
© by Pearson Education, Inc. All Rights Reserved.
Advertisements

Debugging CPSC 315 – Programming Studio Fall 2008.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Microsoft ® Official Course Monitoring and Troubleshooting Custom SharePoint Solutions SharePoint Practice Microsoft SharePoint 2013.
JavaScript Basics Course Introduction SoftUni Team Technical Trainers Software University
Software Quality Assurance QA Engineering, Testing, Bug Tracking, Test Automation Software University Technical Trainers SoftUni Team.
Introduction to Programming
Debugging applications, using properties Jim Warren – COMPSCI 280 S Enterprise Software Development.
 Dimitar Ivanov Introduction to programming with microcontrollers.
AngularJS Routing Routes, Route Parameters, Templates, Location, Navigation SoftUni Team Technical Trainers Software University
AngularJS Services Built-in and Custom Services SoftUni Team Technical Trainers Software University
PHP Basics Course Introduction SoftUni Team Technical Trainers Software University
Fundamentals SoftUni Welcome to Software University SoftUni Team Technical Trainers Software University
Advanced JavaScript Course Introduction SoftUni Team Technical Trainers Software University
Project Tracking Tools Trello, Asana, Basecamp, GitHub Issue Tracker, TRAC SoftUni Team Technical Trainers Software University
Testing, Bug Fixing and Debugging the Code Yordan Dimitrov Telerik Corporation
AngularJS Directives Defining Custom Directives SoftUni Team Technical Trainers Software University
Software Testing Lifecycle Exit Criteria Evaluation, Continuous Integration Ivan Yonkov Technical Trainer Software University.
Design Patterns: Structural Design Patterns
High-Quality Programming Code Code Correctness, Readability, Maintainability, Testability, Etc. SoftUni Team Technical Trainers Software University
JavaScript Design Patterns Private Fields, Module, Revealing Module, Revealing Prototype, … Software University Technical Trainers SoftUni.
NoSQL Databases NoSQL Concepts SoftUni Team Technical Trainers Software University
Redis Key-Value Database: Practical Introduction
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Entity Framework Performance SoftUni Team Technical Trainers Software University
Microsoft Azure SoftUni Team Technical Trainers Software University
Svetlin Nakov Technical Trainer Software University
Build Processes and Continuous Integration Automating Build Processes Software University Technical Trainers SoftUni Team.
Chapter 22 Developer testing Peter J. Lane. Testing can be difficult for developers to follow  Testing’s goal runs counter to the goals of the other.
Processing Redis with.NET How to Operate with Redis Databases SoftUni Team Technical Trainers Software University
Project Tracking Tools Trello, Asana, Basecamp, GitHub Issue Tracker, TRAC Angel Georgiev Part-time Trainer Software University
Test-Driven Development Learn the "Test First" Approach to Coding SoftUni Team Technical Trainers Software University
JavaScript Basics Course Introduction Svetlin Nakov Technical Trainer Software University
Debugging Xin Tong. GDB GNU Project debugger Allows you to see what is going on `inside' another program while it executes or crashed. (Faster than printing.
Controllers and Markup Controllers, $scope, Markup, Directives, Expressions, Binding, Filters, Validation SoftUni Team Technical Trainers Software University.
AMD and RequireJS Splitting JavaScript Code into Dependent Modules Software University Technical Trainers SoftUni Team.
Asynchronous Web Services Writing Asynchronous Web Services SoftUni Team Technical Trainers Software University
Web Fundamentals (HTML and CSS) Course Introduction SoftUni Team Technical Trainers Software University
Jekyll Static Site Generator Template-Based Site Generation Svetlin Nakov Technical Trainer Software University
Forms Overview, Query string, Submitting arrays, PHP & HTML, Input types, Redirecting the user Mario Peshev Technical Trainer Software.
JavaScript Modules and Patterns Private Fields, Module, Revealing Module, Revealing Prototype, … Software University Technical Trainers.
Web Development Tools Tools for Front-End Developers Writing HTML and CSS Code SoftUni Team Technical Trainers Software University
Building Rock-Solid Software Nikolay Kostov Telerik Software Academy academy.telerik.com Senior Software Developer and Technical Trainer
High-Quality Programming Code Code Correctness, Readability, Maintainability Svetlin Nakov Technical Trainer Software University
High-Quality Code: Course Introduction Course Introduction SoftUni Team Technical Trainers Software University
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
Advanced C# Course Introduction SoftUni Team Technical Trainers Software University
Events Event Handling in JavaScript SoftUni Team Technical Trainers Software University
Mocking with Moq Tools for Easier Unit Testing SoftUni Team Technical Trainers Software University
CSC 1201 LAB RULES Nouf Aljaffan (C) CSC 1201 Course at KSU.
Mocking with Moq Mocking tools for easier unit testing Svetlin Nakov Technical Trainer Software University
JavaScript Tools Tools for Writing / Editing / Debugging JavaScript Code Svetlin Nakov Technical Trainer Software University
1 Advanced.Net Debugging Using Visual Studio, R# and OzCode IT Week, Summer 2015.
Test-Driven Development Learn the "Test First" Approach to Coding Svetlin Nakov Technical Trainer Software University
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Sets, Dictionaries SoftUni Team Technical Trainers Software University
Creating Content Defining Topic, Creating Technical Training Materials SoftUni Team Technical Trainers Software University
High-Quality Code: Course Introduction Course Introduction SoftUni Team Technical Trainers Software University
What's New in Visual Studio 2010 Debugging Brian Peek Senior Consultant, ASPSOFT, Inc. Microsoft MVP - C#
Doctrine The PHP ORM SoftUni Team Technical Trainers Software University
Creating Content Defining Topic, Creating Technical Training Materials SoftUni Team Technical Trainers Software University
ASP.NET MVC Course Program, Trainers, Evaluation, Exams, Resources SoftUni Team Technical Trainers Software University
Stacks and Queues Processing Sequences of Elements SoftUni Team Technical Trainers Software University
Generics SoftUni Team Technical Trainers Software University
Asynchronous Programming Writing Asynchronous Code in Java SoftUni Team Technical Trainers Software University
High-Quality Programming Code Code Correctness, Readability, Maintainability, Testability, Etc. SoftUni Team Technical Trainers Software University
Debugging and Troubleshooting Code
Using Visual Studio with C#
Presentation transcript:

Debugging Building Rock-Solid Software Software University Technical Trainers SoftUni Team

Table of Contents  Introduction to Debugging  Visual Studio Debugger  Breakpoints  Data Inspection  Finding a Defect 2

Introduction to Debugging

 The process of locating and fixing or bypassing bugs (errors) in computer program code  To debug a program:  Start with a problem  Isolate the source of the problem  Fix it  Debugging tools (called debuggers) help identify coding errors at various development stages What is Debugging?

5  Testing  A means of initial detection of errors  Debugging  A means of diagnosing and correcting the root causes of errors that have already been detected Debugging vs. Testing

6  $60 Billion per year in economic losses due to software defects  Perfect code is an illusion  There are factors that are out of our control  Legacy code  You should be able to debug code that is written years ago  Deeper understanding of system as a whole Importance of Debugging

7  Debugging can viewed as one big decision tree  Individual nodes represent theories  Leaf nodes represent possible root causes  Traversal of tree boils down to process state inspection  Minimizing time to resolution is key  Careful traversal of the decision tree  Pattern recognition  Visualization and ease of use helps minimize time to resolution Debugging Philosophy

8 Example Debugging - Decision Tree OutOfMemoryException Native Heaps? Virtual?.NET Heaps?.NET Types? Native? Native Heaps? Long references?

Visual Studio Debugger

 Visual Studio IDE gives us a lot of tools to debug your application  Adding breakpoints  Visualize the program flow  Control the flow of execution  Data tips  Watch variables  Debugging multithreaded programs  and many more… Visual Studio Debugger

11  Starting a process under the Visual Studio debugger  Attaching to an already running process  Without a solution loaded you can still debug  Useful when solution isn't readily available  Debug menu -> Attach to Process How To Debug a Process

12  Debug menu, Start Debugging item  F5 is a shortcut  Easier access to the source code and symbols since its loaded in the solution  Certain differences exist in comparison to debugging an already running process  Hosting for ASP.NET application  VS uses a replacement of the real IIS Debugging a Solution

 Debug Windows are the means to introspect on the state of a process  Opens a new window with the selected information in it  Window categories  Data inspection  Threading  Accessible from menu  Debug -> Windows Debug Windows

14  Convenient shortcut to common debugging tasks  Step into  Step over  Continue  Break  Breakpoints  Customizable to fit your needs  Add / Remove buttons Debugging Toolbar

15  By default, an app will run uninterrupted (and stop on exception or breakpoint)  Debugging is all about looking at the state of the process  Controlling execution allows:  Pausing execution  Resuming execution  Stepping through the application in smaller chunks  In the case of IntelliTrace (recording steps), allows backward and forward stepping Controlling Execution

16  IntelliTrace operates in the background, records what you are doing during debugging  You can easily get a past state of your application from IntelliTrace  You can navigate through your code and see what's happened  To navigate, just click any of the events that you want to explore IntelliTrace

17  Visual Studio offers quite a few knobs and tweaks in the debugging experience  Options and settings is available via Debug -> Options and Settings  Examples of Options and Settings  Enable just my code (ignore other code)  Enable.NET framework source stepping  Source server support  Symbols (line numbers, variable names)  Much more… Options and Settings

Breakpoints

 Ability to stop execution based on certain criteria is key when debugging  When a function is hit  When data changes  When a specific thread hits a function  Much more…  Visual Studio's debugger has a huge feature set when it comes to breakpoints Breakpoints

20  Stops execution at a specific instruction (line of code)  Can be set using Debug->Toggle breakpoint  F9 shortcut  Clicking on the left most side of the source code window  By default, the breakpoint will hit every time execution reaches the line of the code  Additional capabilities: condition, hit count, value changed, when hit, filters Visual Studio Breakpoints

21  Managed in the breakpoint window  Adding breakpoints  Removing or disabling breakpoints  Labeling or grouping breakpoints  Export/import breakpoints Managing Breakpoints

22  Allows you to excerpt even more control of when a breakpoint hits  Examples of customization  Machine name  Process ID  Process name  Thread ID  Thread name  Multiple can be combined using &, ||, ! Breakpoint Filters

Data Inspection

 Debugging is all about data inspection  What are the local variables?  What is in memory?  What is the code flow?  In general - What is the state of the process right now and how did it get there?  As such, the ease of data inspection is key to quick resolution of problems Data Inspection

25  Visual Studio offers great data inspection features  Watch windows  Autos and Locals  Memory and Registers  Data Tips  Immediate window Visual Studio Data Inspection

26  Allows you to inspect various states of your application  Several different kinds of "predefined" watch windows  Autos  Locals  "Custom" watch windows also possible  Contains only variables that you choose to add  Right click on the variable and select "Add to Watch" Watch Window

27  Locals watch window contains the local variables for the specific stack frame  Debug -> Windows -> Locals  Displays: name of the variable, value and type  Allows drill down into objects by clicking on the + sign in the tree control  Autos lets the debugger decide which variables to show in the window  Loosely based on the current and previous statement Autos and Locals

28  Memory window can be used to inspect process wide memory  Address field can be a raw pointer or an expression  Drag and drop a variable from the source window  Number of columns displayed can be configured  Data format can be configured  Registers window can be used to inspect processor registers Memory and Registers

29  Provides information about variables  Variables must be within scope of current execution  Place mouse pointer over any variable  Variables can be expanded by using the + sign  Pinning the data tip causes it to always stay open  Comments can be added to data tips  Data tips support drag and drop  Importing and exporting data tips Data Tips

30  Useful when debugging due to the expansive expressions that can be executed  To output the value of a variable  To set values, use =  To call a method, use. (arguments)  Similar to regular code  Supports IntelliSense Immediate Window

Threads and Stacks

32  Fundamental units of code execution  Commonly, programs use more than one thread  In.NET, there is always more than one thread  Each thread has a memory area associated with it known as a stack  Stores local variables  Stores frame specific information  Memory area employs last in first out semantics Threads

33  Contains an overview of thread activity in the process  Includes basic information in a per thread basis  Thread ID's  Category  Name  Location  Priority Threads Window

34  A threads stack is commonly referred to as a callstack  Visual Studio shows the elements of a callstack  Local variables  Method frames Callstacks

Finding a Defect

36 1.Stabilize the error 2.Locate the source of the error a)Gather the data b)Analyze the data and form hypothesis c)Determine how to prove or disprove the hypothesis d)Prove or disprove the hypothesis by 2c) 3.Fix the defect 4.Test the fix 5.Look for similar errors Finding a Defect

37  Use all available data  Refine the test cases  Check unit tests  Use available tools  Reproduce the error several different ways  Generate more data to generate more hypotheses  Use the results of negative tests  Brainstorm for possible hypotheses Tips for Finding Defects

38  Narrow the suspicious region of the code  Be suspicious of classes and routines that have had defects before  Check code that's changed recently  Expand the suspicious region of the code  Integrate incrementally  Check for common defects  Talk to someone else about the problem  Take a break from the problem Tips for Finding Defects (2)

39  Understand the problem before you fix it  Understand the program, not just the problem  Confirm the defect diagnosis  Relax  Save the original source code  Fix the problem, not the symptom  Make one change at a time  Add a unit test that expose the defect  Look for similar defects Fixing a Defect Source:

40  Your ego tells you that your code is good and doesn't have a defect even when you've seen that it has.  How "Psychological Set" Contributes to Debugging Blindness Psychological Considerations

? ? ? ? ? ? ? ? ? Code Refactoring

License  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" licenseCreative Commons Attribution- NonCommercial-ShareAlike 4.0 International 42  Attribution: this work may contain portions from  "High Quality Code" course by Telerik Academy under CC-BY-NC-SA licenseHigh Quality CodeCC-BY-NC-SA

Free Software University  Software University Foundation – softuni.orgsoftuni.org  Software University – High-Quality Education, Profession and Job for Software Developers  softuni.bg softuni.bg  Software Facebook  facebook.com/SoftwareUniversity facebook.com/SoftwareUniversity  Software YouTube  youtube.com/SoftwareUniversity youtube.com/SoftwareUniversity  Software University Forums – forum.softuni.bgforum.softuni.bg