debugging applications for ms net and windows l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Debugging Applications for MS .Net and Windows PowerPoint Presentation
Download Presentation
Debugging Applications for MS .Net and Windows

Loading in 2 Seconds...

play fullscreen
1 / 49

Debugging Applications for MS .Net and Windows - PowerPoint PPT Presentation


  • 187 Views
  • Uploaded on

Debugging Applications for MS .Net and Windows. Ch.2 Getting Started Debugging. (this title intentionally left blank). Presentation for chapter 2 of John Robbins’ book “Debugging Applications for MS .Net and MS Windows” Part of the ongoing Testing Seminar meetings Coordinated by Dr. Fawcett.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Debugging Applications for MS .Net and Windows' - miron


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
debugging applications for ms net and windows

Debugging Applicationsfor MS .Net and Windows

Ch.2 Getting Started Debugging

this title intentionally left blank
(this title intentionally left blank)

Presentation for chapter 2 of John Robbins’ book “Debugging Applications for MS .Net and MS Windows”

Part of the ongoing Testing Seminar meetings

Coordinated by Dr. Fawcett.

Date: Friday, October 3, 2003

Presenter: Kanat Bolazar, kanat2@yahoo.com

Syracuse University, Syracuse, New York

track changes until you throw away the project
Track Changes Until You Throw Away the Project

Code evolves

  • Documentation updated?
    • Requirements specification document
    • Design (architecture) documents

Track changes:

  • Version control
  • Bug tracking, bug number

Advantages:

  • Bringing a new team member up to speed
  • Ability to build earlier deployed versions of code
  • ... (what else?)

Disadvantages?

what to put under version control
What To Put Under Version Control?
  • Source code
  • Design documents
  • End user manual
  • Test plans
  • Automated tests (harness & test cases)
  • External dependencies: libraries, tools
the importance of including unit tests
The Importance of Including Unit Tests

Test harness

  • Comparator

Test set

  • Test case
    • Oracle (expected output)

Functional / black box testing

Structural / white box / glass box testing

  • By developer

Junit, Nunit, etc (see links at www.junit.Org)

controlling changes
Controlling Changes

Size, change and stability

Allow none? Allow all?

  • Green time: Anyone can check in anything
  • Yellow time: Only bug fixes; review each.
  • Red time: Code freeze / key milestone / testing.

Is this bug critical?

  • Crash, data corruption: Yes!
  • Other:
    • How many people does it affect?
    • Is it at the core or periphery of the product?
    • How much retesting will be needed?
the importance of version labels
The Importance of Version Labels

Definition

Label all:

  • Milestones
  • Transitions from green to yellow to red times
  • Builds sent outside
  • Branching points in the development tree
  • Successful runs of daily build and smoke tests

Consistent naming

  • (eg. three-part <Project><Milestone/Reason><Date>)

QA tells developer the version label for bug

having trouble reproducing builds sent outside
Having Trouble Reproducing Builds Sent Outside?

Burn everything on CD/DVD for builds sent outside:

  • Source
  • Executables
  • Documentation
  • Intermediate files (object files, etc)
  • Installation kit
  • External libraries
  • [Build tools]
bug tracking systems
Bug Tracking Systems
  • Check bug tracking history:
    • Module with high bug frequency:
      • More error-prone
      • Do more review
      • Run more tests
  • Jot down reminders, notes, to-do items, in bug-tracking system as well.
    • Assign them to self
    • Set at lowest priority
    • Ignore these in bug metrics reports
levels of access to bug tracking systems
Levels of access to bug tracking systems
  • Developers
  • Sales engineers (technical experts who teach salespeople)
  • Sales and marketing people:
    • May enter bugs, but may not view them
    • Must be taught how to enter bugs
    • They'll run your program before & during demos to client
    • They'll hear complaints from the field:
      • From alpha and beta testers
      • From end users
choosing the right systems for you
Choosing the Right Systems For You

Small team? Small shop? Windows only?

High end requirements? Multi-platform?

Don't use home grown solutions

Use commercial or open source solutions

Evaluate well before committing to it

Tools should integrate well

Analogy:

Code: Lifeblood of development

Version control and bug-tracking systems: Arteries

They keep the lifeblood flowing in the right direction.

schedule time for building debugging systems
Schedule Time For Building Debugging Systems

Build (probably project-specific):

  • Crash handlers (ch. 13)
  • File data dumpers
  • Other tools to reproduce problems reported from the field

Error handling system

  • A product feature
  • Helps handle bugs proactively
error condition
Error condition

Handle consistently in code (pick one):

  • Return values
  • Exceptions (setjmp, longjmp in C)
  • Global error variable (as in C's "errno")

C#

  • System.Exception at root of exception hierarchy

(note: Users should inherit from ApplicationException)

  • Throw-catch vs. return values
    • Don't use exceptions for regular boundary cases
    • Throw fills stack trace, may be slow
c exceptions
C++ exceptions

Robbins: "Forget that C++ exceptions exist.“

  • Good in theory
  • Not so in practice
  • In COM: Can't cross apartment / process boundaries
  • Cause of many bugs

Dr. Fawcett disagrees: “Use C++ exceptions, but don’t use exception specifications.”

build all builds with debugging symbols
Build All Builds With Debugging Symbols

.PDB: Program database file

Build release code with debugging symbols as well.

  • Release code is often optimized
  • May be just-in-time(JIT)-compiled
  • May be compiled by native compiler
  • Hard to debug
  • Some code optimized out/shared: Debugger jumps around.
  • Optimized call stack: Can't trace stack as well.
  • Larger files (with debugging symbols)
c building with debugging symbols
C#: Building with debugging symbols
  • csc.exe /debug:full
  • Visual Studio:

Project properties

Configuration Properties

Build

Generate Debugging Information

c building with debugging symbols17
C++: Building With Debugging Symbols

Use /Zi switch

Visual Studio:

Debug Information Format : Program Database (PDB)

Also set:

/INCREMENTAL:NO /DEBUG /PDB

... (many more options; refer to book)

/OPT:REF -- Don't link functions not called: Vital for size

Robbins wrote tool SettingsMaster (ch. 9)

  • Simplifies changing these options
  • Defaults to his preferred settings for all these options
for managed code treat warnings as errors
For Managed Code, Treat Warnings As Errors

C#

Visual Studio .Net:

Visual Basic and Visual C#

Reference

Visual C# Language

C# Compiler Options

Compiler Errors CS0001 Through CS9999

Errors

Many more and tighter than C/C++

Warnings

Levels: 1 - 4

Code should compile cleanly, without any warnings!

treating warnings as errors in c
Treating Warnings As Errors in C#

/WARN:4 (on by default)

/WARNASERROR+ (off by default)

Visual Studio:

Project properties

Configuration Properties

Build

Errors and Warnings

Treat Errors As Warnings : True

when warnings get annoying
When Warnings Get Annoying

Ignore insignificant warnings?

A sea of warnings: Which are insignificant?

Fix code; avoid cause of warning

  • CS1573: Parameter 'parameter' has no matching param tag in XML comment (but other parameters do)
    • You were using the C# /DOC switch for XML documentation
    • A parameter to a function is undocumented
    • Document it!
when a warning kills your build
When A Warning Kills Your Build
  • CS1596: XML documentation not updated during this incremental rebuild; use /incremental- to update XML documentation.

Insignificant /DOC warning kills build!

A real problem.

Robbins suggests:

    • Debug builds: Build incrementally but without docs for
    • Release builds: Do full builds with docs
for native code treat warnings as errors mostly
For Native Code, Treat Warnings As Errors -- Mostly

C++:

/W4

/WX

Annoyed by warnings? Don't ignore; be pedantic.

Bertrand Myers once said:

If you think this is pedantic, remember that no one can be as pedantic as a machine running a code with a bug.

Solve the problem if you can:

C4100: 'identifier': Unreferenced formal parameter

int baad(int i ) { return 25; } // Warning: C4100

int good(int /* i */) { return 25; } // ok.

locally disabling warnings in native code
Locally Disabling Warnings in Native Code

If you can’t solve the problem, disable warning, temporarily, locally.

To change warning level temporarily:

#pragma warning ( push , 3 )

#include "DiesAtW4.h";

#pragma warning ( pop )

To disable one warning type temporarily:

#pragma warning ( disable : 4201 )

...

#pragma warning ( default : 4201 )

the stl supplied with visual studio net has issues
The STL Supplied With Visual Studio .Net Has "Issues"

C++ STL implementation that comes with Visual Studio:

    • Gives errors and warnings that are impossible to parse
    • Has lots of problems with its warnings
      • Critical with /WX (treat warnings as errors) switch
  • Solutions:
    • Include only precompiled headers
    • Use STLport instead:
      • www.stlport.org
      • Supports multithreading
      • Has extra support for debugging
      • Gives readable errors and warnings
      • May be used in commercial products
for native code know where your dlls load
For Native Code, Know Where Your DLLs Load

Program crashes at a known memory address

  • Which dynamically loaded library sits there?

DLLs don't have set addresses in memory

Solve problem proactively

Rebase your DLLs to know their addresses in memory

base addresses for managed module dlls
Base Addresses for Managed Module DLLs

CLR is very different from native code

It's all interpreted

There is no directly executable code

Still, Robbins recommends rebasing .Net DLLs as well

design a lightweight diagnostic system for release builds
Design a Lightweight Diagnostic System For Release Builds

One customer (out of many) has a problem

How to catch flow of execution? Log!

Level of detail in logging:

About to open file X

Did lseek(25) on file X

Read file X to buffer

Use consistent format

You can use Perl to easily extract the part you need

If XML, you can use XSLT

performance issues of logging
Performance Issues of Logging

Robbins recommends a "ready, fire, aim" approach:

  • Log everything that you feel you should
  • Profile the program
  • Find percentage of time spent on logging
  • Trim your logging calls in code, as needed
frequent builds are mandatory
Frequent Builds Are Mandatory

Build daily: Automated nightly build

But what if my project is large?

  • How large?
  • Larger than MS Win XP with 40 million lines of code?

Someone's code breaks the build

  • This is a serious crime, a major sin!
  • Punishment! (public flogging and donuts)
  • Humiliation! (public acknowledgement)
  • Slavery! (make him/her the builder)

Pull daily

  • Pull the binaries; don't recompile on each machine
smoke tests are mandatory
Smoke Tests Are Mandatory

Term comes from electronics:

    • Develop the circuit
    • Plug it in
    • Does it smoke?

These are pre-tests for software

  • First test: Start; stop; OK.
  • Next: Simple tests, one per feature
  • Performance benchmarks
regression testing tool
Regression Testing Tool
  • Automates UI testing
  • Logs user interactions with the system
  • Can replay them after user has left

Example: Tester (ch. 16)

    • Logs mouse and keyboard input
    • Saves them into a JScript / VBScript file
    • Allows playback
when to freeze updates to compiler and other tools
When to Freeze Updates to Compiler and Other Tools

Feature complete = Beta 1

Much testing went into the product (executable).

Don't try to fix it if doing so may break it.

Freeze tools; don't upgrade versions from now on.

build the installation program immediately
Build the Installation Program Immediately

First impressions

Build installation tool before anything else

Allow option to install release or debug version

Testing can start sooner

Managed applications:

  • Much easier
  • Database connections
  • Global assembly cache

COM:

  • Much harder
  • Much work in the registry
qa must test with debug builds
QA Must Test With Debug Builds

QA could use diagnostics in debug builds

But QA may use batch-mode testing

  • Turn off assertion outputs

Balance debug and release build testing:

  • Before alpha: Two-three days of debug build testing per week
  • Before beta 1: Two days per week
  • After beta 2: One day per week
  • After release candidate: Do only release build testing
crash dumps
Crash Dumps

minidumps (crash dumps)

  • Introduced by Microsoft
  • Is like core dumps
  • Can be loaded up in a debugger
  • You can inspect the point at which the program crashed

Issues:

  • Needs:
    • Symbols
    • Binaries
  • For:
    • Your code
    • OS code
version issues with operating system symbols and binaries
Version Issues with Operating System Symbols and Binaries

OS code symbols and binaries:

You must have the correct type/version of OS and service pack ...

... of the customer that sent the minidump

Your currently installed version and service pack may not match

Solution: Install all the OS symbols and binaries and set up a symbol store.

symbol server machine
Symbol Server Machine

Give name such as //SYMBOLS

Will hold OS binaries, OS symbols, your own symbols

Does not need too much horsepower

Needs much disk space: 40 - 80 GB or more

Create shared directories

  • OSSYMBOLS
  • PRODUCTSYMBOLS
download debugging tools for windows
Download "Debugging Tools for Windows"

www.microsoft.com/ddk/debugging

Get the latest version

Four key binaries (should have R/W access to server file system)

  • SYMSRV.DLL

Symbol server (also helps folks behind proxy servers)

  • DBGHELP.DLL
  • SYMCHK.EXE

Downloads OS symbols from Microsoft site

  • SYMSTORE.EXE

Downloads OS binaries from Microsoft site

Adds your (product) binaries and symbols to the symbol store

set master machine wide environment for symbol path
Set Master (Machine-Wide) Environment for SYMBOL PATH

My Computer (right-click) / Properties / Advanced / Environment Variables

_NT_SYMBOL_PATH

If not defined, define new.

Set its value to (all on one line):

SRV*\\Symbols\OSSymbols*http://msdl.microsoft.com/download/symbols;SRV*\\Symbols\ProductSymbols

If already defined, just add these before “;”, followed by old value.

loading os binaries and symbols
Loading OS Binaries and Symbols
  • May be loaded as needed from Microsoft site
  • From Windows NT 4 to Windows XP
  • May be preloaded
  • About 1 GB disk space needed:
    • Per OS
    • Per service pack
os binaries and symbols download automation ossyms js robbins
OS Binaries and Symbols Download Automation: OSSYMS.JS (Robbins)
  • Uses SYMCHK.EXE and SYMSTORE.EXE
  • Loads all OS symbols and OS binaries
  • Steps to get all symbols for all service packs and hot fixes:
    • Install OS without service packs or hot fixes
    • Run OSSYMS.JS
    • Apply each service pack and hot fix, one at a time
    • Rerun OSSYMS.JS once after applying each
adding your own product s binaries and symbols
Adding Your Own Product's Binaries and Symbols
  • Use SYMSTORE.EXE:

symstore add /r /f d:\build\*.* /s \\Symbols\ProductSymbols /t "MyApp" /v "Build 632" /c "01/22/03 Daily Build"

/r add files or directories recursively

/f File

/s Store

/t Product

/v Version

/c additional comment

which product binaries and symbols should we add
Which Product Binaries and Symbols Should We Add?
  • What to add:
    • Add EXE, DLL, PDB files
    • After each daily build
    • After each milestone
    • For any build sent outside
  • What not to add:
    • Developers' local builds
disk size issues with product symbols
Disk Size Issues with Product Symbols

OS symbols: Only public symbols

Your product's symbols: Includes private and local symbols

Your product's symbols take much space

Especially with daily builds

Clean up: Delete older product symbols, regularly

Delete daily builds older than four weeks

deleting from the symbol server
Deleting From the Symbol Server
  • Look at HISTORY.TXT in the 000admin special directory
  • Every item in history contains transaction number such as 0000000009
  • Use:

symsore del /i 0000000009 /s \\Symbols\ProductSymbols

  • Ignores errors silently, and gives no feedback!!
  • Check HISTORY.TXT: Deletion logged there?
review
Review
  • Track changes until you throw away the project
  • Schedule time for building debugging systems
  • Frequent builds and smoke tests are mandatory
  • QA must test with debug builds
  • Install the operating system symbols and set up a symbol store