Overview of Previous Lesson(s) Over View  Assertions  assert() library function is declared in the cassert header to check logical conditions in native.

Slides:



Advertisements
Similar presentations
Program Verification Using the Spec# Programming System ETAPS Tutorial K. Rustan M. Leino, Microsoft Research, Redmond Rosemary Monahan, NUIM Maynooth.
Advertisements

11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Exception Handling The purpose of exception handling is to permit the program to catch and handle errors rather than letting the error occur and suffer.
 Both System.out and System.err are streams—a sequence of bytes.  System.out (the standard output stream) displays output  System.err (the standard.
Exception Handling Introduction Exception handling is a mechanism to handle exceptions. Exceptions are error like situations. It is difficult to decide.
Overview of Previous Lesson(s) Over View 3  Debugger  A computer program that is used to test and debug other programs.  Local Debugging  Debugging.
Chapter 15 Memory Management: Four main memory areas for a C++ program: Code: code for instructions, methods, etc. static data: Global variables (declared.
Tutorial 10 Programming with JavaScript
C++ data types. Structs vs. Classes C++ Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction.
CS 225 Lab #2 - Pointers, Copy Constructors, Destructors, and DDD.
More C++ Classes Systems Programming. Systems Programming: C++ Classes 2 Systems Programming: 2 C++ Classes  Preprocessor Wrapper  Time Class Case Study.
Lesson 6 Functions Also called Methods CS 1 Lesson 6 -- John Cole1.
Guide To UNIX Using Linux Third Edition
CS-2303 System Programming Concepts
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Review of C++ Programming Part II Sheng-Fang Huang.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
Pointer Data Type and Pointer Variables
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
More C++ Classes Systems Programming. C++ Classes  Preprocessor Wrapper  Time Class Case Study –Two versions (old and new)  Class Scope and Assessing.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
Copyright © 2012 Pearson Education, Inc. Chapter 6: Functions.
Chapter 6: User-Defined Functions
Copyright  Hannu Laine C++-programming Part 3 Hannu Laine.
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.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Introduction to Exception Handling and Defensive Programming.
Copyright  Hannu Laine C++-programming Part 1 Hannu Laine.
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
Decisions and Debugging Part06dbg --- if/else, switch, validating data, and enhanced MessageBoxes.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Overview of Previous Lesson(s) Over View .NET Framework is a software framework developed by Microsoft that runs primarily on Microsoft Windows.  It.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Chapter 9 Classes: A Deeper Look, Part I Part II.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 1.
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Introduction Purpose  This training course demonstrates the Project Generator function.
Overview of Previous Lesson(s) Over View VP is the methodology in which development allows the user to grab and use the desired tools like menus, buttons,
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
Error Handling – the Debug and Trace Classes
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter 13 - The Preprocessor
LESSON 20.
Chapter 9 Classes: A Deeper Look, Part 1
How to organize and document your classes
Classes: A Deeper Look, Part 1
Essential Class Operations
C++ data types.
More C++ Classes Systems Programming.
Corresponds with Chapter 5
SPL – PS3 C++ Classes.
Presentation transcript:

Overview of Previous Lesson(s)

Over View  Assertions  assert() library function is declared in the cassert header to check logical conditions in native C++ program that should always be true.  _DEBUG symbol  The preprocessor symbol DEBUG is automatically defined in the debug version of a native C++program. 3

Over View  Debugging code  Add our own debugging code by enclosing it between an #ifdef / #endif pair of directives testing for DEBUG.  crtdbg.h header  The crtdbg.h header supplies declarations for functions to provide debugging of free store operations. 4

Over View  _crtDbgFlag flag  By setting the crtDbgFlag appropriately enables automatic checking of program for memory leaks.  Debug output  To direct output messages from the free store debugging functions, we can call the CrtSetReportMode() and CrtSetReportFile() functions. 5

Over View...  Debugging Dynamic Memory  Allocating memory dynamically is a major source of bugs.  In this context most common bugs are memory leaks.  Sometimes, this can result in a tragic failure of the program when all available memory has been allocated. 6

Over View...  Problem diagnosed  Name class is allocating memory for its data members, and never releasing it.  The problem is that in implementing the class, we forgot the fundamental rules related to classes.  Solution  A destructor  A copy constructor  The assignment operator. 7

Contents  C++ / CLI Programming  Using the Debug and Trace Classes  Generating Output  Setting the Output Destination  Indenting the Output  Controlling Output  Assertions  Program 9

Debugging CLI Programs  Life is simpler with C++/CLI programming.  No complications of corrupted pointers or memory leaks arise in CLR programs, so this reduces the debugging problem substantially.  Breakpoints and tracepoints can be set exactly the same way. 10

Debugging CLI Programs..  We have a specific option that applies to C++/CLI code for preventing the debugger from stepping through library code. 11

Debug & Trace Classes  The Debug and Trace classes in the System::Diagnostics namespace are used for tracing.  Same capabilities with one exception.  Trace functions are compiled into release builds.  Debug functions are not complied into release builds. 12

Generating Output  Debug::WriteLine() and Debug::Write() functions are used to write messages to an output destination.  Same capabilities  Only difference is WriteLine() function writes a newline character after the output whereas the Write() function does not  They both come in four overloaded versions. 13

Generating Output.. 14

Generating Output…  Conditional versions are also available  WriteIf() and WriteLineIf() 15

Generating Output…  Debug::Print() function can also be used for outputs.  Comes in two overloaded versions: 16

Setting Output Destination  By default the output messages are sent to the Output window in the IDE, but it can be changed.  A listener is an object that directs debug and trace output to one or more destinations. 17

Setting Output Destination.. TextWriterTraceListener^ listener = gcnew TextWriterTraceListener( Console::Out);  It creates TextWriterTraceListener object that directs the output to the standard output stream, which is returned by the static property Out in the Console class. Debug::Listeners- > Add(listener);  The Listeners property in the Debug class returns a collection of listeners for debug output, so the statement adds the listener object to the collection. 18

Setting Output Destination...  We could also add a ConsoleTraceListener to direct output to the console screen ConsoleTraceListener^ myOutput = gcnew ConsoleTraceListener(); Debug::Listeners- > Add(myOutput);  Similarly other listeners can be used that additionally direct output elsewhere, i.e to a file. 19

Indenting the Output  Indenting of the debug and trace messages can be controlled.  Effective in situations where functions are called at various depths.  Indenting the output at the beginning of a function & removing the indent before leaving the function. 20

Indenting the Output..  To increase the current indent level for output by one. Debug::Indent(); // Increase indent level by 1  To reduce the current indent level by one. Debug::Unindent(); // Decrease indent level by 1  The current indent level is recorded in the static IndentLevel property in the Debug class, so we can get or set the current indent level. Debug::IndentLevel = 2*Debug::IndentLevel; 21

Indenting the Output…  The number of spaces in one indent unit is recorded in the static IndentSize property in the Debug class.  We can change it to a different value. Console::WriteLine(L"Current indent unit = {0}", Debug::IndentSize); Debug::IndentSize = 2; // Set indent unit to 2 spaces  The second statement sets it to a new value.  Subsequent calls to Indent() increases the current indentation by the new size, which is two spaces. 22

Controlling Output  Trace switches can made the debug or trace output on and off.  The BooleanSwitch reference class objects provides a way to switch segments of output on or off depending on the state of the switch.  The TraceSwitch reference class objects provides with a more sophisticated control mechanism because each TraceSwitch object has four properties that correspond to four control levels for output statements. 23

Controlling Output.. public ref class MyClass { private: static BooleanSwitch^ errors = gcnew BooleanSwitch(L"Error Switch", L"Controls error output"); public: void DoIt() { // Code... if(errors- > Enabled) Debug::WriteLine(L"Error in DoIt()"); // More code... } // Rest of the class... }; 24

Controlling Output…  Shows the errors object as a static member of MyClass.  The first argument to the BooleanSwitch constructor is the display name for the switch that is used to initialize the DisplayName property.  The second argument sets the value of the Description property for the switch.  There’s another constructor that accepts a third argument of type String^ that sets the Value property for the switch. 25

Controlling Output…  The Enabled property for a Boolean switch is of type bool.  It is false by default.  It can be set to ture. errors- > Enabled = true;  The DoIt() function in MyClass outputs the debug error message only when the errors switch is enabled. 26

Controlling Output…  The TraceSwitch reference class has two constructors that have the same parameters as the BooleanSwitch class constructors. TraceSwitch^ traceCtrl = gcnew TraceSwitch(L"Update", L"Traces update operations");  The first argument to the constructor sets the value of the DisplayName property.  The second argument sets the value of the Description property. 27

Controlling Output…  The Level property for a TraceSwitch object is an enum class type TraceLevel. traceCtrl- > Level = TraceLevel::Verbose; 28

Controlling Output…  We can determine whether a particular message should be issued by trace and debug code by testing the state of one of four properties of type bool for the TraceSwitch object. 29

Assertions  The Debug and Trace classes have static Assert() functions that provide a similar capability to the native C++ assert() function.  The Assert() function in the Debug class only works in debug builds.  The first argument to the Debug::Assert() function is a bool value or expression that causes the program to assert when the argument is false. 30

Assertions..  There are three courses of action after an assertion.  Abort  Clicking the Abort button ends the program immediately.  Ignore  Clicking the Ignore button allows the program to continue.  Retry  Clicking the Retry button gives the option of executing the program in debug mode. 31

Assertions...  The following four overloaded versions of the Assert() function are available: 32

Program  Lets try all this in example… 33

Thank You 34