SlideShare une entreprise Scribd logo
1  sur  76
Oct 11, 2007 Handling Exceptions in C++ Dr. Partha Pratim Das Interra Systems (India) Pvt. Ltd.   PART B
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PART B
Exceptions Instrumentations in C++ How compilers manage Exceptional Flow
Exception Handling : Issues ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Function Call : Instrumentations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Function Call : Items ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Function Call Items : Stack Frame ,[object Object],[object Object],[object Object],[object Object],[object Object]
Function Call Items : Context ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Function Call Items : Finalization ,[object Object],[object Object],[object Object],[object Object],[object Object]
Function Call : Normal Flow ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Function Call Items : Stack Frame
Function Call Items : EH Frame
Function Call : Stack Cutting ,[object Object],#define _JBLEN  16 #define _JBTYPE int // Define jump buffer layout for x86 setjmp/longjmp. typedef struct __JUMP_BUFFER {      unsigned long Ebp;      unsigned long Ebx;      unsigned long Edi;      unsigned long Esi;      unsigned long Esp;      unsigned long Eip;      unsigned long Registration;      unsigned long TryLevel;      unsigned long Cookie;      unsigned long UnwindFunc;      unsigned long UnwindData[6]; } _JUMP_BUFFER; typedef _JBTYPE jmp_buf[_JBLEN];
Function Call : Stack Cutting ,[object Object],[object Object],[object Object],[object Object],[object Object]
Function Call Items : Stack Frame
Function Call Items : Thunk ,[object Object],[object Object],[object Object]
Function Call Items : EH Handler
Function Call : Stack Unwinding ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Function Call : Stack Unwinding ,[object Object],[object Object],[object Object],[object Object]
Function Call : Stack Unwinding ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exception Handling : Trade Off
Designing with Exceptions in C++ Glimpses of Design Issues
Designing with Exceptions : Goals ,[object Object],[object Object],[object Object],[object Object]
Designing with Exceptions : Goals ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],No Safety Minimal Safety Basic Safety Strong Safety No-Throw Safety
Exception Safety : Levels ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exception Safety : Levels ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Designing with Exceptions : Scope ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Designing with Exceptions : Scope ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C++ Ground Rules : Lifetime ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C++ Ground Rules : Lifetime ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Anatomy of a Function ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exceptional Design Rules Meyers’ Recommendations on Basic Exception Safety
Exception Safety :  Meyers Guidelines ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Poly Quad Tri
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],class Poly { public:  virtual void plotPoly() = 0;  ... };  class Quad: public Poly { public:  virtual void plotPoly();  ... };  class Tri: public Poly { public:  virtual void plotPoly();  ... };
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],plotPoly() throws    *pPoly leaks
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Code Duplication
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],pPoly->plotPoly();  means   (pPoly.operator->())->plotPoly();
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [9] :  Use destructors to prevent resource leaks ,[object Object],[object Object],[object Object]
More Questions   ,[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [10] :  Prevent resource leaks in constructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],// Destructor A::~A() { }
Meyers [10] :  Prevent resource leaks in constructors ,[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [11] :  Prevent exceptions from leaving destructors   ,[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [11] :  Prevent exceptions from leaving destructors   ,[object Object],[object Object],[object Object]
Meyers [11] :  Prevent exceptions from leaving destructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [11] :  Prevent exceptions from leaving destructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [11] :  Prevent exceptions from leaving destructors   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [11] :  Prevent exceptions from leaving destructors   ,[object Object],[object Object],[object Object],[object Object]
Meyers [12] :  Throwing an exception differs from passing a parameter or calling a virtual function  ,[object Object],[object Object],[object Object],[object Object],[object Object]
Meyers [13] :  Catch exceptions by reference
Meyers [14] :    Use exception specifications judiciously
Meyers [15] :    Understand the costs of exception handling
Handling Exceptions in  C & C++ References & Credits
References ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Credits / Acknowledgements
Thank You

Contenu connexe

Tendances

C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)Olve Maudal
 
Insecure coding in C (and C++)
Insecure coding in C (and C++)Insecure coding in C (and C++)
Insecure coding in C (and C++)Olve Maudal
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programmingRiccardo Cardin
 
Exceptions and Exception Handling in C++
Exceptions and Exception Handling in C++Exceptions and Exception Handling in C++
Exceptions and Exception Handling in C++IRJET Journal
 
Checking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioChecking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioPVS-Studio
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language samt7
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerAndrey Karpov
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhtsBéo Tú
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignmentSaket Pathak
 
Oop10 6
Oop10 6Oop10 6
Oop10 6schwaa
 

Tendances (19)

C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 
Insecure coding in C (and C++)
Insecure coding in C (and C++)Insecure coding in C (and C++)
Insecure coding in C (and C++)
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
Exceptions and Exception Handling in C++
Exceptions and Exception Handling in C++Exceptions and Exception Handling in C++
Exceptions and Exception Handling in C++
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
Checking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioChecking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-Studio
 
report
reportreport
report
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 
F6dc1 session6 c++
F6dc1 session6 c++F6dc1 session6 c++
F6dc1 session6 c++
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzer
 
RAII and ScopeGuard
RAII and ScopeGuardRAII and ScopeGuard
RAII and ScopeGuard
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
 
C++ lab assignment
C++ lab assignmentC++ lab assignment
C++ lab assignment
 
2 debugging-c
2 debugging-c2 debugging-c
2 debugging-c
 
Oop10 6
Oop10 6Oop10 6
Oop10 6
 
C++ boot camp part 1/2
C++ boot camp part 1/2C++ boot camp part 1/2
C++ boot camp part 1/2
 

En vedette

Exception handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaException handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaManoj_vasava
 
Exception Handling
Exception HandlingException Handling
Exception HandlingReddhi Basu
 
Chp3(pointers ref)
Chp3(pointers ref)Chp3(pointers ref)
Chp3(pointers ref)Mohd Effandi
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++ Samsil Arefin
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++Fahim Adil
 
Exception Handling in C++
Exception Handling in C++Exception Handling in C++
Exception Handling in C++Deepak Tathe
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templatesfarhan amjad
 

En vedette (14)

Exception handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaException handling in c++ by manoj vasava
Exception handling in c++ by manoj vasava
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Handling
HandlingHandling
Handling
 
Chp3(pointers ref)
Chp3(pointers ref)Chp3(pointers ref)
Chp3(pointers ref)
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++
 
Exception Handling in C++
Exception Handling in C++Exception Handling in C++
Exception Handling in C++
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
 
Strings
StringsStrings
Strings
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
Exception handling
Exception handlingException handling
Exception handling
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 

Similaire à Handling Exceptions In C & C++ [Part B] Ver 2

2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2Leonid Maslov
 
.Net Garbage Collector 101
.Net Garbage Collector 101.Net Garbage Collector 101
.Net Garbage Collector 101Woody Pewitt
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CanSecWest
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plusSayed Ahmed
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Sayed Ahmed
 
C++tutorial
C++tutorialC++tutorial
C++tutorialdips17
 
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...corehard_by
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisFastly
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answerssheibansari
 
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia KazakovaC++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakovacorehard_by
 

Similaire à Handling Exceptions In C & C++ [Part B] Ver 2 (20)

2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
Day 1
Day 1Day 1
Day 1
 
.Net Garbage Collector 101
.Net Garbage Collector 101.Net Garbage Collector 101
.Net Garbage Collector 101
 
C# 6.0 Preview
C# 6.0 PreviewC# 6.0 Preview
C# 6.0 Preview
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
 
Scope Stack Allocation
Scope Stack AllocationScope Stack Allocation
Scope Stack Allocation
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plus
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)
 
C++tutorial
C++tutorialC++tutorial
C++tutorial
 
Memory management in c++
Memory management in c++Memory management in c++
Memory management in c++
 
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
 
Lec05 buffers basic_examples
Lec05 buffers basic_examplesLec05 buffers basic_examples
Lec05 buffers basic_examples
 
C++ Core Guidelines
C++ Core GuidelinesC++ Core Guidelines
C++ Core Guidelines
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
C++ Training
C++ TrainingC++ Training
C++ Training
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answers
 
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia KazakovaC++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
 
Valgrind
ValgrindValgrind
Valgrind
 

Plus de ppd1961

Land of Pyramids, Petra, and Prayers - Egypt, Jordan, and Israel Tour
Land of Pyramids, Petra, and Prayers - Egypt, Jordan, and Israel TourLand of Pyramids, Petra, and Prayers - Egypt, Jordan, and Israel Tour
Land of Pyramids, Petra, and Prayers - Egypt, Jordan, and Israel Tourppd1961
 
Science & Culture Article with Editorial & Cover
Science & Culture Article with Editorial & CoverScience & Culture Article with Editorial & Cover
Science & Culture Article with Editorial & Coverppd1961
 
NDL @ YOJANA
NDL @ YOJANANDL @ YOJANA
NDL @ YOJANAppd1961
 
Unified Modeling Language (UML)
Unified Modeling Language (UML)Unified Modeling Language (UML)
Unified Modeling Language (UML)ppd1961
 
OOP in C++
OOP in C++OOP in C++
OOP in C++ppd1961
 
Digital geometry - An introduction
Digital geometry  - An introductionDigital geometry  - An introduction
Digital geometry - An introductionppd1961
 
Innovation in technology
Innovation in technologyInnovation in technology
Innovation in technologyppd1961
 
Kinectic vision looking deep into depth
Kinectic vision   looking deep into depthKinectic vision   looking deep into depth
Kinectic vision looking deep into depthppd1961
 
Function Call Optimization
Function Call OptimizationFunction Call Optimization
Function Call Optimizationppd1961
 
How To Define An Integer Constant In C
How To Define An Integer Constant In CHow To Define An Integer Constant In C
How To Define An Integer Constant In Cppd1961
 
Stl Containers
Stl ContainersStl Containers
Stl Containersppd1961
 
Object Lifetime In C C++
Object Lifetime In C C++Object Lifetime In C C++
Object Lifetime In C C++ppd1961
 
Technical Documentation By Techies
Technical Documentation By TechiesTechnical Documentation By Techies
Technical Documentation By Techiesppd1961
 
Vlsi Education In India
Vlsi Education In IndiaVlsi Education In India
Vlsi Education In Indiappd1961
 
Reconfigurable Computing
Reconfigurable ComputingReconfigurable Computing
Reconfigurable Computingppd1961
 
Women In Engineering Panel Discussion
Women In Engineering   Panel DiscussionWomen In Engineering   Panel Discussion
Women In Engineering Panel Discussionppd1961
 
Dimensions of Offshore Technology Services
Dimensions of Offshore Technology ServicesDimensions of Offshore Technology Services
Dimensions of Offshore Technology Servicesppd1961
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languagesppd1961
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0xppd1961
 

Plus de ppd1961 (20)

Land of Pyramids, Petra, and Prayers - Egypt, Jordan, and Israel Tour
Land of Pyramids, Petra, and Prayers - Egypt, Jordan, and Israel TourLand of Pyramids, Petra, and Prayers - Egypt, Jordan, and Israel Tour
Land of Pyramids, Petra, and Prayers - Egypt, Jordan, and Israel Tour
 
Science & Culture Article with Editorial & Cover
Science & Culture Article with Editorial & CoverScience & Culture Article with Editorial & Cover
Science & Culture Article with Editorial & Cover
 
NDL @ YOJANA
NDL @ YOJANANDL @ YOJANA
NDL @ YOJANA
 
Unified Modeling Language (UML)
Unified Modeling Language (UML)Unified Modeling Language (UML)
Unified Modeling Language (UML)
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Digital geometry - An introduction
Digital geometry  - An introductionDigital geometry  - An introduction
Digital geometry - An introduction
 
Innovation in technology
Innovation in technologyInnovation in technology
Innovation in technology
 
Kinectic vision looking deep into depth
Kinectic vision   looking deep into depthKinectic vision   looking deep into depth
Kinectic vision looking deep into depth
 
C++11
C++11C++11
C++11
 
Function Call Optimization
Function Call OptimizationFunction Call Optimization
Function Call Optimization
 
How To Define An Integer Constant In C
How To Define An Integer Constant In CHow To Define An Integer Constant In C
How To Define An Integer Constant In C
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
 
Object Lifetime In C C++
Object Lifetime In C C++Object Lifetime In C C++
Object Lifetime In C C++
 
Technical Documentation By Techies
Technical Documentation By TechiesTechnical Documentation By Techies
Technical Documentation By Techies
 
Vlsi Education In India
Vlsi Education In IndiaVlsi Education In India
Vlsi Education In India
 
Reconfigurable Computing
Reconfigurable ComputingReconfigurable Computing
Reconfigurable Computing
 
Women In Engineering Panel Discussion
Women In Engineering   Panel DiscussionWomen In Engineering   Panel Discussion
Women In Engineering Panel Discussion
 
Dimensions of Offshore Technology Services
Dimensions of Offshore Technology ServicesDimensions of Offshore Technology Services
Dimensions of Offshore Technology Services
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languages
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
 

Handling Exceptions In C & C++ [Part B] Ver 2

Notes de l'éditeur

  1. We should outline the various Instrumentations needed for handling Function Calls depending on the kind of exception handling being supported: Normal Flow return Exceptional Flow with Stack Cutting setjmp / longjmp Exceptional Flow with Stack Unwinding try-catch-throw Naturally, keeping with the code separation / code organization motivations in mind, we do not need to refer to any of the local (goto’s) or global (errno / exit() etc) options here. We need to highlight, as we move from #1 to #3, how we are doing in terms of the basic issues (objectives) we have started off with. This will be more a philosophical introduction.
  2. These are the items needed for the discussion on Instrumentation. We’ll elaborate them in the following slides. We need to collect information on: How the calling order for finalizers decided? In normal flow and in exceptional flow. What exactly does the EH Handler do to achieve stack unwinding? How a sample EH Frame is laid out.
  3. We discuss the stack frame structure here. Function parameters Function return address Frame pointer Local Objects Callee save registers We’ll take a small example and show the stack frame on x86. Good resource is: http://www.unixwiz.net/techtips/win32-callconv-asm.html
  4. We discuss the context of a call here. Register PC / Return Address (eip on x86) Register SP / Stack Pointer (esp on x86) Register FP / Frame Pointer or Base Pointer (ebp on x86) With respect to the example, we’ll show the context on x86. Good resources is: http://www.unixwiz.net/techtips/win32-callconv-asm.html
  5. We discuss the finalization of a call here. How are the right destructors called in the right order? This is tricky once the function has a multiple return statements before / after a number of local object constructions. We can frame a small example and illustrate.
  6. We outline the normal flow in a function call: Caller prepares the Parameters Caller calls the Callee Callee saves the Context (Function Prologue) Callee does the job Callee restores the Context (Function Epilogue) Callee returns Caller cleans up the Parameters Caller uses the return value We can use the stack frame example for illustration. Good resource is: http://www.unixwiz.net/techtips/win32-callconv-asm.html
  7. We discuss the enhanced stack frame structure with (bold item). Function parameters Function return address Frame pointer Exception Handler frame Local Objects Callee save registers
  8. We need to discuss how EH Frame is maintained. Need more information on this. A good resource is: http://www.osronline.com/custom.cfm?name=articlePrint.cfm&id=469
  9. This is the case of handling in C for setjmp / longjmp. Our discussion should follow as: Recap of the setjmp / longjmp with an example. Explanation of the jmp_buf structure for x86-32. This is from the setjmp.h header. With reference to stack frame and context, we need to explain how the information set for the buffer has been chosen. Explanation of the behavior of setjmp – low level steps. Assembly code of setjmp can says that. Explanation of the behavior of longjmp – low level steps. Assembly code of longjmp can says that. Justify why this is ‘stack cutting’ – that is finalizers are not invoked. We use the above example to illustrate. Good resource is: CS360 Lecture notes – Setjmp : http://www.cs.utk.edu/~plank/plank/classes/cs360/360/notes/Setjmp/lecture.html
  10. This is the case of handling in C for setjmp / longjmp. Our discussion should follow as: Recap of the setjmp / longjmp with an example. Explanation of the jmp_buf structure for x86-32. This is from the setjmp.h header. With reference to stack frame and context, we need to explain how the information set for the buffer has been chosen. Explanation of the behavior of setjmp – low level steps. Assembly code of setjmp can says that. Explanation of the behavior of longjmp – low level steps. Assembly code of longjmp can says that. Justify why this is ‘stack cutting’ – that is finalizers are not invoked. We use the above example to illustrate. Good resource is: CS360 Lecture notes – Setjmp : http://www.cs.utk.edu/~plank/plank/classes/cs360/360/notes/Setjmp/lecture.html
  11. We discuss the additional information that a stack frame structure may need to keep for C++ exceptions. We need to identify them beyond the following. Function parameters Function return address Frame pointer Exception Handler frame Local Objects Callee save registers
  12. What is a thunk? The word thunk has two meanings in computer science: a delayed computation (as in functional programming) a mapping of machine data from one system-specific form to another, usually for compatibility reasons. For example, running a 16-bit program on a 32-bit operating system may require a thunk from 16-bit addresses to 32-bit. Thunk in this sense may also refer to mappings from one calling convention to another or from one version of a library to another. This meaning is similar to the first—the "delayed computation" can be thought of as the "update" from the old format to the new. http://en.wikipedia.org/wiki/Thunk Why do we need a destructor thunk for the Exception object? How is it used? Good resource is: Intel presentation on: “C++ Exception Handling for IA-64 Unix”
  13. We need to discuss how the EH hook is maintained.
  14. This is the case of handling in C++ for try-catch-throw. Our discussion should follow as: Recap of the try-catch-throw with an example. It will be good to use the same example as setjmp / longjmp case. Introduce the basic notions of stack unwinding: Creation of Exception object Placement of destructor thunk for Exception object Wrapping up of the stack frame. Calling of Finalizers Matching for Handler (catch handlers are statically overloaded but dynamically dispatched). Explain why this will need RTTI. Invocation of the right handler. Exit from the handler Invocation of the thunk if no rethrow has been done. Flow / flowchart of the unwind logic. Role of the C++ Runtime system. Outline the data structures required. Stack Frame – modified RUNTIME_FUNCTION UNWIND_INFO TRY_REGION_TABLE CLEANUP_TABLE We use the example to illustrate. Good resources are: Intel presentation on: “C++ Exception Handling for IA-64 Unix” Exceptional Behavior - x64 Structured Exception Handling: http://www.osronline.com/custom.cfm?name=articlePrint.cfm&id=469
  15. This is the case of handling in C++ for try-catch-throw. Our discussion should follow as: Recap of the try-catch-throw with an example. It will be good to use the same example as setjmp / longjmp case. Introduce the basic notions of stack unwinding: Creation of Exception object Placement of destructor thunk for Exception object Wrapping up of the stack frame. Calling of Finalizers Matching for Handler (catch handlers are statically overloaded but dynamically dispatched). Explain why this will need RTTI. Invocation of the right handler. Exit from the handler Invocation of the thunk if no rethrow has been done. Flow / flowchart of the unwind logic. Role of the C++ Runtime system. Outline the data structures required. Stack Frame – modified RUNTIME_FUNCTION UNWIND_INFO TRY_REGION_TABLE CLEANUP_TABLE We use the example to illustrate. Good resources are: Intel presentation on: “C++ Exception Handling for IA-64 Unix” Exceptional Behavior - x64 Structured Exception Handling: http://www.osronline.com/custom.cfm?name=articlePrint.cfm&id=469
  16. This is the case of handling in C++ for try-catch-throw. Our discussion should follow as: Recap of the try-catch-throw with an example. It will be good to use the same example as setjmp / longjmp case. Introduce the basic notions of stack unwinding: Creation of Exception object Placement of destructor thunk for Exception object Wrapping up of the stack frame. Calling of Finalizers Matching for Handler (catch handlers are statically overloaded but dynamically dispatched). Explain why this will need RTTI. Invocation of the right handler. Exit from the handler Invocation of the thunk if no rethrow has been done. Flow / flowchart of the unwind logic. Role of the C++ Runtime system. Outline the data structures required. Stack Frame – modified RUNTIME_FUNCTION UNWIND_INFO TRY_REGION_TABLE CLEANUP_TABLE We use the example to illustrate. Good resources are: Intel presentation on: “C++ Exception Handling for IA-64 Unix” Exceptional Behavior - x64 Structured Exception Handling: http://www.osronline.com/custom.cfm?name=articlePrint.cfm&id=469
  17. Nothing in life comes for free. While Exception support in C++ makes life much easier for the designer, coder and debugger; it makes life tough for the compiler writer. The main two costs are: Overhead during a non-exception flow Loss of Optimization options for the compiler. Good resource is: How much does Exception Handling cost, really? : http://www.nwcpp.org/Downloads/2006/ehc.ppt From this presentation, we can lift a couple of slides (we’ll exclude all references to SEH).