Systems software design. Software build configurations; Debugging, profiling & Quality Assurance tools

Similar documents
Debugging and Profiling

An Introduction to Runtime Analysis with Rational PurifyPlus

1.1 For Fun and Profit. 1.2 Common Techniques. My Preferred Techniques

Systems software design. Processes, threads and operating system resources

Debugging with gdb and valgrind

DNWSH - Version: 2.3..NET Performance and Debugging Workshop

Systems software design

Oracle Developer Studio Code Analyzer

Integrated Software Environment. Part 2

CS266 Software Reverse Engineering (SRE) Reversing and Patching Wintel Machine Code

CS2141 Software Development using C/C++ Debugging

Intro to Segmentation Fault Handling in Linux. By Khanh Ngo-Duy

Chapter 2. Operating-System Structures

12. Debugging. Overview. COMP1917: Computing 1. Developing Programs. The Programming Cycle. Programming cycle. Do-it-yourself debugging

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Chapter 2: Operating-System Structures

CHAPTER 2: SYSTEM STRUCTURES. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Using Intel VTune Amplifier XE and Inspector XE in.net environment

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edition

Debugging with GDB and DDT

CptS 360 (System Programming) Unit 4: Debugging

Chapter 2: Operating-System Structures

Intel System Studio 2014 Overview

Memory & Thread Debugger

Introduction to Concurrent Software Systems. CSCI 5828: Foundations of Software Engineering Lecture 08 09/17/2015

Introduction to Concurrent Software Systems. CSCI 5828: Foundations of Software Engineering Lecture 12 09/29/2016

Profiling & Optimization

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

Heap Management. Heap Allocation

Debugging on Intel Platforms

Jackson Marusarz Software Technical Consulting Engineer

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

Honours/Master/PhD Thesis Projects Supervised by Dr. Yulei Sui

Performance Profiling

Eliminate Memory Errors to Improve Program Stability

Keil uvision development story (Adapted from (Valvano, 2014a))

Laboratory Assignment #4 Debugging in Eclipse CDT 1

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Bootstrap, Memory Management and Troubleshooting. LS 12, TU Dortmund

Chapter 2: System Structures. Operating System Concepts 9 th Edition

Enterprise Architect. User Guide Series. Profiling

Enterprise Architect. User Guide Series. Profiling. Author: Sparx Systems. Date: 10/05/2018. Version: 1.0 CREATED WITH

Debugging. Erwan Demairy Dream

Risk Management. I.T. Mock Interview Correction

Profiling & Optimization

Deallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection

Using a debugger. Segmentation fault? GDB to the rescue!

What s New in Platform Builder 7

Eliminate Threading Errors to Improve Program Stability

EW The Source Browser might fail to start data collection properly in large projects until the Source Browser window is opened manually.

Performance Improvement. The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 7

Coding Tools. (Lectures on High-performance Computing for Economists VI) Jesús Fernández-Villaverde 1 and Pablo Guerrón 2 March 25, 2018

Advanced Programming & C++ Language

QNX MOMENTICS ACCELERATE YOUR DEVELOPMENT WITH QNX MOMENTICS KNOCK WEEKS, EVEN MONTHS, OFF YOUR DEVELOPMENT SCHEDULE WITH THE

Embedded Software TI2726 B. 3. C tools. Koen Langendoen. Embedded Software Group

Using Static Code Analysis to Find Bugs Before They Become Failures

Welcome. HRSK Practical on Debugging, Zellescher Weg 12 Willers-Bau A106 Tel

Debugging with TotalView

Chapter 2: Operating-System Structures. Operating System Concepts Essentials 8 th Edition

CUDA Development Using NVIDIA Nsight, Eclipse Edition. David Goodwin

Intel Parallel Studio XE 2015

CSE 351. GDB Introduction

Debugging with GDB and DDT

Chapter 2: Operating-System

KOTLIN/NATIVE + CLANG, TRAVEL NOTES NIKOLAY IGOTTI, JETBRAINS

This guide will show you how to use Intel Inspector XE to identify and fix resource leak errors in your programs before they start causing problems.

Optimize Data Structures and Memory Access Patterns to Improve Data Locality

April 4-7, 2016 Silicon Valley

valgrind overview: runtime memory checker and a bit more What can we do with it?

Older geometric based addressing is called CHS for cylinder-head-sector. This triple value uniquely identifies every sector.

Example: intmath lib

Enhanced Debugging with Traces

International Journal of Current Research and Modern Education (IJCRME) ISSN (Online): ( Volume I, Issue II, 2016

Martin Kruliš, v

Computer Science II Lab 3 Testing and Debugging

Lecture 4 Processes. Dynamic Analysis. GDB

Xcode Tricks. ios App Development Fall 2010 Lecture 13

CSE 4/521 Introduction to Operating Systems

Quality Assurance: Test Development & Execution. Ian S. King Test Development Lead Windows CE Base OS Team Microsoft Corporation

Exercise Session 6 Computer Architecture and Systems Programming

Oracle Developer Studio 12.6

Robust Memory Management Schemes

What's New in CDT 7.0? dominique dot toupin at ericsson dot com

J2EE Development Best Practices: Improving Code Quality

Intel Parallel Studio 2011

Garbage Collection. Steven R. Bagley

Debugging uclinux on Coldfire

Run-Time Environments/Garbage Collection

CSCI-1200 Data Structures Spring 2016 Lecture 6 Pointers & Dynamic Memory

Scientific Programming in C IX. Debugging

Vector and Free Store (Pointers and Memory Allocation)

System Wide Tracing User Need

Scalable Post-Mortem Debugging Abel Mathew. CEO -

Chapter 2: Operating-System Structures

Chapter 2: System Structures. Operating System Concepts 9 th Edition

CMSC 330: Organization of Programming Languages

Profilers and Debuggers. Introductory Material. One-Slide Summary

Chapter 2: Operating-System Structures

Intel C++ Compiler Professional Edition 11.1 for Mac OS* X. In-Depth

Binding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Transcription:

Systems software design Software build configurations; Debugging, profiling & Quality Assurance tools

Who are we? Krzysztof Kąkol Software Developer Jarosław Świniarski Software Developer Presentation based on materials prepared by Andrzej Ciarkowski, M.Sc., Eng. 2

outline Build configurations Debugging tools Debugger features Remote debugging Post-mortem analysis The tools Profiling tools Program code hotspots The tools Quality assurance Coverage tracking Tracing memory allocation issues The tools

build configurations When creating a new project, most modern IDEs will create two build configurations: Debug and Release As the names suggest, the purpose of Debug configuration is to perform the debugging (an actually the most of the development) and the Release is what you ship to the customers Watch out for subtle bugs, which occur only in Release build! Debugging such build is painfully hard, but sometimes unavoidable That s why most non-trivial software system rely not only on debugging but also implement some kind of execution logging

build configurations Debug Release Compiler-introduced optimizations are turned off Code inlining is turned off Debugging macros & functions do work (like e.g. assertions) Debugging symbols are present in the code Code runs much much slower g++ -g O0 source.cpp Optimizations are turned on and make the debugging unpredictable: code is reordered, variables are optimized out, stack frames are being omitted Debugging macros are undefined or do nothing Debugging symbols are stripped (or moved to a separate files) Code runs at full speed g++ -O2 DNDEBUG source.cpp

compiler optimization Example (inlining) 10.04.2017 6

assertions Conditions the developer assumes will be always met Introduced through the use of assert macro (C/C++), function or keyword In Release mode the assertions resolve to nothing In Debug mode, assertions will cause the program to be stopped with some debugging message, abort function will be called causing the SIGABRT (Unix) and core dump for post-mortem debugger Use assertions for verifying pre- and post-conditions, not for regular runtime error handling!

switching build configurations

debugging One of the firsts computers - Mark II One of the firsts bugs 10.04.2017 9

debugging The debugger is a tool for dynamic analysis of other programs used for finding and identifying programming errors Most IDEs include integrated debugger, either own or using GDB (GNU Debugger)

typical debugger features Step-by-step execution Execute program code either line-by-line, or instruction-by-instruction, examining the results of each call Modes: step over, step into, step out, continue to line Setting program breakpoints Suspend program execution when a specific source code line is executed or some other condition occurs Call stack Show the stack of function calls allowing to visualize How we got here?

typical debugger features Locals/watches Examine value of local variables at any point of time or watch the specific variable how its value changes Modify value of variables while program is being run Threads Examine state of program s threads, switch between them, show each thread s call stack, diagnose deadlocks Memory Examine & modify contents of program s address space

typical debugger features Disassembly Show the program code as assemblylevel mnemonics Step through the assembly code Useful for spotting very hard to find/ mysterious bugs Assembly code is interleaved with the actual programming language code nice way to learn some assembly ;>

typical debugger features Remote debugging Install debugging stub on another computer Connect your local debugger (master) to the remote stub using network or serial port connection Debug remote program as it was running on the local machine Useful for: Debugging low-level programs, e.g. OS kernel, device drivers Debugging programs running in constrained environments, e.g. mobile phone, embedded system Debugging User Interface problems, when interacting with the UI makes it impossible to spot the problem

typical debugger features Attaching debugger to running process Useful for debugging programs running in specific environments, e.g. operating systems services/daemons, COM objects, code running in application servers Debugging shared libraries loaded by other programs Modify program execution path by messing with its internal state, discover security vulnerabilities, design & spread viruses!

typical debugger features Post-mortem debugging Examining the state of crashed application at the moment of the crash On Unix examining the core dump core file On Windows possible through dbghelp.dll library, program must be explicitly written to support dumping of minidump file Usually the sole glance at the call stack at the time of the crash (what instruction was being executed & its context) is enough to trace back the reason of the crash This information is invaluable! Just load the dump file into the debugger and run it like normal code Force core dump by calling abort() inserting failed assertion

tips The Debugger is probably the single important reason for using your IDE of choice instead of some manual build system & generic text editors Learn & use keyboard shortcuts of your IDE s debugger; that ll boost your productivity enormously The only reason for the great success of MS VisualStudio is that their visual debugger was freaking awesome, as the compiler always was obsolete & nonstandard Most (all?) non-ms IDEs for C/C++ rely upon GDB which is very powerful but also generally hard to use (command-line driven)

the tools Microsoft Visual Studio integrated debugger, probably the best one ever GDB the standard debugger for Linux/Unix, but also usable on Windows; command-line interface Eclipse quite nice GUI interface to GDB, closing the gap between MSVC; builtin powerful debugger for Java; also usable for remote debugging Android apps Xcode Apple s own IDE with debugger; runs on Mac and allows to remotely debug ios apps WinDbg Microsoft s debugger for kernel-level remote debugging (device drivers etc.) DDD, Insight a front ends for GDB, better than nothing cgdb terminal-based GUI for GDB

Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%. Donald Knuth

program code profiling & optimization Profiling dynamic analysis of program, measuring the execution time, memory use etc. Most naive/ad hoc approach use explicit timing calls to measure the execution time of a code fragment Systematic approach use profiler to perform various kinds of measurements, like: Instrumentation inserting timing calls invisible for the developer into binary code on each or chosen instructions Sampling use processor hardware features to sample the call stack of the program with specified frequency

hot spots Proper use of profiler allows to identify hot spots in the program code Hot spot is a fragment of code, which is executed often/the program spends most of its execution time within it There s no sense in hand-optimizing the fragments of code which are not hotspots: their influence on the actual execution time is marginal Optimizing the code of hotspots can substantially improve program s performance The decision on performing optimizations is senseless without knowing the actual hotspots

profiling other measurements Profilers may be used also to measure Memory use through special functions replacing standard memory allocation features or code instrumentation I/O performance using e.g. operating system services (counters) Some languages have built-in support for these measurements e.g. C#, Java

profiler drawbacks The instrumentation/process of taking of measurements performed by the profiler may falsify the gathered data Too fine-grained instrumentation will cause the profiling code to become the actual hotspot Profiling in the real world is the subject to uncertainty principle (less true with sampling, more with instrumentation)!

profiling tools Microsoft Visual Studio built-in profiler based on CPU sampling or instruction instrumentation, also profiling memory use in.net applications Intel VTune Intel s powerful profiler with features for optimizing multithreaded code (thread contention, deadlock detection) gprof GNU Profiler, based on compiler-assisted instrumentation, use with gcov for checking code coverage Valgrind profiler detecting also memory leaks & measuring memory usage

quality assurance tools Statical or dynamic analysis of code in order to find problems beyond these typically detected by the compiler Examples Detecting memory leaks at runtime Checking code coverage, detecting dead/unreachable code

memory leak detection Memory leaks is a common problem with languages lacking Garbage Collector (C/C++) each allocated memory chunk must be freed manually, otherwise the memory is lost Long running leaking code will eventually eat up all virtual memory causing performance drop, and finally crash Memory leak detection tools perform instrumentation of memory allocation functions to trace each chunk of memory and indicate which chunks were leaked Actually, memory leaks are also possible with Garbage-Collected languages but it s much harder to do ;>

memory leak detection tools Visual Leak Detector library for Visual C++ which replaces standard allocation functions with its own Valgrind memory leak detection tool for Unix (also a profiler) but also use smart pointers for managing lifetime of heapallocated objects!

code analysis & coverage tools Detect unreachable code unreachable (dead) code is often a symptom of programming mistake Code coverage is a measure describing how much of the source code is covered by a test suite Code which is never tested can never be sure to be working right Tools: Profilers (MSVC, VTune) gcov Also detect numerous other problems

Questions? 10.04.2017 29

Krzysiek Jarek kkakol@pgs-soft.com jswiniarski@pgs-soft.com www.pgs-soft.com