c/c++ tools & methodology demonstration he zongjian [email protected] school of software...

37
C/C++ Tools & C/C++ Tools & Methodology Methodology demonstration demonstration He Zongjian He Zongjian ceoxp ceoxp @yahoo.com @yahoo.com School of Software Engineering School of Software Engineering Tongji University Tongji University

Upload: joshua-weaver

Post on 12-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

C/C++ Tools & Methodology C/C++ Tools & Methodology demonstrationdemonstration

He ZongjianHe Zongjian

[email protected]@yahoo.com

School of Software EngineeringSchool of Software Engineering

Tongji UniversityTongji University

Page 2: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

AgendaAgenda

Project management in Visual StudioProject management in Visual Studio Develop Resource lookupDevelop Resource lookup Debugging with Visual StudioDebugging with Visual Studio Introduction to Windows GUI AppsIntroduction to Windows GUI Apps Sample application of C++ projectSample application of C++ project ReferencesReferences DiscussionDiscussion

Page 3: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Project management in Project management in Visual StudioVisual Studio

Page 4: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Common Bad HabitCommon Bad Habit

Create a *.c / *.cpp fileCreate a *.c / *.cpp file Open it with Visual StudioOpen it with Visual Studio CompileCompile

Page 5: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Bad EffectBad Effect

NO Intelligent SenseNO Intelligent Sense Class View / File View disabledClass View / File View disabled Can NOT debuggingCan NOT debugging Can NOT locate definitionsCan NOT locate definitions

An Expensive NotepadAn Expensive Notepad

Page 6: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

What is Workspace & ProjectWhat is Workspace & Project

Configuration files that help us managing thConfiguration files that help us managing the projecte project

A workspace can have multiple projectA workspace can have multiple project Workspaces have the .dsw extensionWorkspaces have the .dsw extension Projects have the .dsp extensionProjects have the .dsp extension Double click the workspace can auto launch Double click the workspace can auto launch

the Developer studiothe Developer studio

Page 7: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Other files used by devenvOther files used by devenv

.ncb : Visual C++ IntelliSense Database.ncb : Visual C++ IntelliSense Database .rc : Resource template.rc : Resource template .pch : Precompiled header.pch : Precompiled header .obj : Intermediate file.obj : Intermediate file .pdb : Program debugging database.pdb : Program debugging database .bsc : Browse information.bsc : Browse information .clw : Class wizard file (MFC only).clw : Class wizard file (MFC only)

Page 8: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Using File View & Class ViewUsing File View & Class View

File View :File View :– Add new fileAdd new file– Delete fileDelete file

Class View :Class View :– Locate functions & variablesLocate functions & variables– Add new classAdd new class– Add member functions and member variablesAdd member functions and member variables

Page 9: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Project configurationProject configuration

Debug version VS Release VersionDebug version VS Release Version Enable RTTIEnable RTTI Command line argumentsCommand line arguments

Page 10: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Useful TipsUseful Tips

Code auto formatting (Alt + F8)Code auto formatting (Alt + F8) Go to definitionGo to definition Go to referenceGo to reference Find in filesFind in files Open documentOpen document

Page 11: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

New features in VS.NETNew features in VS.NET

.dsw -> .sln.dsw -> .sln Integrated IDEIntegrated IDE Measure up to C++ standardMeasure up to C++ standard …………

Page 12: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Develop Resource lookupDevelop Resource lookup

Page 13: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Microsoft Developer NetworkMicrosoft Developer Network(MSDN)(MSDN)

All develop related resourcesAll develop related resources Online Version:Online Version:

– http://http://msdnmsdn..microsoftmicrosoft.com.com– Released every 4 monthsReleased every 4 months

Visual Studio 6.0 Version (.chm)Visual Studio 6.0 Version (.chm)– VB 6, VC 6, VFP 6, VJ 6, VID 6, Platform SDKVB 6, VC 6, VFP 6, VJ 6, VID 6, Platform SDK

After Jan 2002, Visual Studio.NET VersionAfter Jan 2002, Visual Studio.NET Version– .NET framework.NET framework

Page 14: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Demo : Demo : How to use MSDNHow to use MSDN

Page 15: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Other ResourcesOther Resources

Knowledge BaseKnowledge Base– http://support.http://support.microsoftmicrosoft.com.com

TechNetTechNet– http://http://technettechnet..microsoftmicrosoft.com.com

Developer Works (IBM)Developer Works (IBM)– http://www.ibm.com/developerworks/http://www.ibm.com/developerworks/

Page 16: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Debugging with Visual StudioDebugging with Visual Studio

Page 17: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

What is debugging?What is debugging?

A process for identifying the root cause of a A process for identifying the root cause of a problem by tracing program execution flow problem by tracing program execution flow and underneath memory status.and underneath memory status.

Beneficial after performing general Beneficial after performing general troubleshooting steps.troubleshooting steps.

Page 18: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Basic debugging knowledgeBasic debugging knowledge

Symbols : The PDB files generated with youSymbols : The PDB files generated with your binaries by VSr binaries by VS

Debugging toolsDebugging tools– Visual StudioVisual Studio– Windbg / CDB ( For Windows )Windbg / CDB ( For Windows )– Debug ( For MS-DOS )Debug ( For MS-DOS )– Gdb ( For Linux / Unix / AIX )Gdb ( For Linux / Unix / AIX )

Page 19: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Common Debug ScenarioCommon Debug Scenario

Logic ErrorLogic Error Memory LeakMemory Leak Access Violation (AV)Access Violation (AV)

Page 20: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Basic MethodologyBasic Methodology

Set break pointSet break point Step into / Step over / Step outStep into / Step over / Step out Variables monitor (Local / Watch / Auto)Variables monitor (Local / Watch / Auto) Call stackCall stack MemoryMemory RegisterRegister DisassemblyDisassembly

Page 21: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Demo :Demo :How to use Visual Studio.NET How to use Visual Studio.NET

to debuggingto debugging

Page 22: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Advanced MethodologyAdvanced Methodology

Conditional BreakpointConditional Breakpoint Remote debugging (GDI / Kernel)Remote debugging (GDI / Kernel) JIT debuggingJIT debugging Debugging running processDebugging running process Debugging crash dumpDebugging crash dump Multithread debuggingMultithread debugging

Page 23: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Demo :Demo :Conditional BreakpointConditional Breakpoint

Attach to a processAttach to a process

Page 24: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Solving Access ViolationSolving Access Violation

Buffer Overflow / UnderflowBuffer Overflow / Underflow– Heap CorruptionHeap Corruption– Stack CorruptionStack Corruption

Memory Access DeniedMemory Access Denied– Raw PointerRaw Pointer– Double FreeDouble Free

Page 25: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

The HintThe Hint

Debuggers are just toolsDebuggers are just tools We must also :We must also :

– Know the productKnow the product– Know the languages and their implications Know the languages and their implications

(compiler implementation)(compiler implementation)– Know the operating systemKnow the operating system– Know the CPUKnow the CPU– Know the toolsKnow the tools

Page 26: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Introduction to Windows GUI Introduction to Windows GUI ApplicationsApplications

Page 27: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

What does GUI App ContainsWhat does GUI App Contains

Entry Point : WinMainEntry Point : WinMain Register a window classRegister a window class Create and Show a WindowCreate and Show a Window Message LoopsMessage Loops Windows Procedure (WinProc)Windows Procedure (WinProc) Resource TemplateResource Template

Page 28: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Demo : Demo : Create and analyze a GUI Create and analyze a GUI

applicationapplication

Page 29: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Sample application Sample application of C++ projectof C++ project

Page 30: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Demo :Demo :Text Miner 1.0Text Miner 1.0

Cheat Killer 0.02 Cheat Killer 0.02

Page 31: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

ReferencesReferences

Page 32: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

C / C++ referencesC / C++ references

Thinking in C++ 2nd Edition Thinking in C++ 2nd Edition Bruce EckelBruce Eckel

C++ Primer C++ Primer Stanley B.LippmanStanley B.Lippman

The C++ Programming Language 3rd EditionThe C++ Programming Language 3rd Edition

Bjarne StroustrupBjarne Stroustrup

Page 33: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

C / C++ references (Cont’d)C / C++ references (Cont’d)

The C++ Standard Library The C++ Standard Library 侯捷 译侯捷 译

STLSTL 源代码剖析 源代码剖析 侯捷 著侯捷 著

The C++ template The C++ template David VandevoordeDavid Vandevoorde

Inside C++ Object Model Inside C++ Object Model Stanley B.LippmanStanley B.Lippman

Page 34: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

GUI ProgrammingGUI Programming

Programming Windows 4Programming Windows 4thth Edition Edition

Charles PetzoldCharles Petzold MFC Windows MFC Windows 程序设计 程序设计 22ndnd Edition Edition

Jeff ProsiseJeff Prosise Programming Microsoft Visual C++Programming Microsoft Visual C++

David J. KruglinskiDavid J. Kruglinski

Page 35: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

Debugging ReferencesDebugging References

Debugging Application Debugging Application John RobbinsJohn Robbins

Debugging Applications for Microsoft .NET aDebugging Applications for Microsoft .NET and Microsoft Windows nd Microsoft Windows John RobbinsJohn Robbins

Debugging Windows ProgramsDebugging Windows Programs

Everett N. McKayEverett N. McKay

Page 36: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

DiscussionDiscussion

Page 37: C/C++ Tools & Methodology demonstration He Zongjian ceoxp@yahoo.com School of Software Engineering Tongji University

© 2003 Tongji University. All rights reserved.© 2003 Tongji University. All rights reserved.This presentation is for informational purposes only. TJSSE MAKES NO WARRANTIEThis presentation is for informational purposes only. TJSSE MAKES NO WARRANTIE

S, EXPRESS OR IMPLIED, IN THIS SUMMARY.S, EXPRESS OR IMPLIED, IN THIS SUMMARY.

Thanks!

Question?