Application Note C++ Debugging

Similar documents
Short Notes of CS201

CS201 - Introduction to Programming Glossary By

Training Simulator and Demo Software

Integration for CodeBlocks

Introduction to Programming Using Java (98-388)

Debugging NMF Applications with TRACE32

Outline. Computer programming. Debugging. What is it. Debugging. Hints. Debugging

TRACE32 Debugger Getting Started... ICD Tutorial About the Tutorial... 2

COIMBATORE EDUCATIONAL DISTRICT

Object Oriented Programming. Solved MCQs - Part 2

EL2310 Scientific Programming

COMP322 - Introduction to C++

Object Oriented Programming with c++ Question Bank

What are the characteristics of Object Oriented programming language?

API for Auxiliary Processing Unit

Inheritance, Polymorphism and the Object Memory Model

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Pointers and References


Object-Oriented Principles and Practice / C++

COMP322 - Introduction to C++ Lecture 09 - Inheritance continued

Method Resolution Approaches. Dynamic Dispatch

Time : 3 hours. Full Marks : 75. Own words as far as practicable. The questions are of equal value. Answer any five questions.

News in RSA-RTE 10.2 updated for sprint Mattias Mohlin, May 2018

BasicScript 2.25 User s Guide. May 29, 1996

C++_ MARKS 40 MIN

ARM Application Note for MXC Chips

The Procedure Abstraction

Chapter 3 Function Overloading

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

Procedure and Object- Oriented Abstraction

Chapter 12 Visual Program Debugger

EMBEDDED SYSTEMS PROGRAMMING Language Basics

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Separate Compilation and Namespaces Week Fall. Computer Programming for Engineers

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Codewarrior for ColdFire (Eclipse) 10.0 Setup

Data Structures (list, dictionary, tuples, sets, strings)

Chapter 1: Object-Oriented Programming Using C++

Absolute C++ Walter Savitch

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

Storage class and Scope:

ARM Assembler Workbook. CS160 Computer Organization Version 1.1 October 27 th, 2002 Revised Fall 2005

Expressions and Casting

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

Professor Terje Haukaas University of British Columbia, Vancouver C++ Programming

Introducing C++ David Chisnall. March 15, 2011

Separate Compilation Model

Visual Profiler. User Guide

Ministry of Higher Education Colleges of Applied Sciences Final Exam Academic Year 2009/2010. Student s Name

Implementing Interfaces. Marwan Burelle. July 20, 2012

Chapter 6 Introduction to Defining Classes

Object-Oriented Programming

News in RSA-RTE 10.1 updated for sprint Mattias Mohlin, March 2017

Parallel Debugging. ª Objective. ª Contents. ª Learn the basics of debugging parallel programs

Code::Blocks Student Manual

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21

Chapter 1 Getting Started

News in RSA-RTE 10.0 updated for sprint Mattias Mohlin/Anders Ek, June 2016

Object Oriented Design

Sri Vidya College of Engineering & Technology

Introduction. This tutorial introduces the following SingleStep features:

CMPSCI 250: Introduction to Computation. Lecture #14: Induction and Recursion (Still More Induction) David Mix Barrington 14 March 2013

Fast Introduction to Object Oriented Programming and C++

The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured

Debugging Nios II Systems with the SignalTap II Logic Analyzer

GETTING STARTED WITH ECLIPSE Caitrin Armstrong

PART - I 75 x 1 = The building blocks of C++ program are (a) functions (b) classes (c) statements (d) operations

- HALF YEARLY EXAM ANSWER KEY DEC-2016 COMPUTER SCIENCE ENGLISH MEDIUM

C++ Important Questions with Answers

Should you know scanf and printf?

QUIZ Friends class Y;

Programmiersprachen (Programming Languages)

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

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

Polymorphism. Arizona State University 1

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

C++ for System Developers with Design Pattern

Object Oriented Programming in C++ Basics of OOP

Supporting Class / C++ Lecture Notes

News in RSA-RTE 10.1 updated for sprint Mattias Mohlin, March 2017

Zend Studio 3.0. Quick Start Guide

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

Trace Getting Started V8.02

1 Terminology. 2 Environments and Static Scoping. P. N. Hilfinger. Fall Static Analysis: Scope and Types

Ch. 11: References & the Copy-Constructor. - continued -

Integration for Rhapsody in C/C++

Binding and Variables

Pointers as Arguments

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Enterprise Architect. User Guide Series. Testpoints. Author: Sparx Systems. Date: 30/06/2017. Version: 1.0 CREATED WITH

Introduction to C++ Introduction to C++ 1


Heap Arrays. Steven R. Bagley


CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!

CPE 323: Laboratory Assignment #1 Getting Started with the MSP430 IAR Embedded Workbench

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

Programming in C and C++

Transcription:

Application Note C++ Debugging TRACE32 Online Help TRACE32 Directory TRACE32 Index TRACE32 Documents... High-Level Language Debugging... Application Note C++ Debugging... 1 Sample Code used by This Application Note... 2 Gathering Information of Objects... 3 Display Options Dedicated to Objects 3 Most Derived Class 5 Lifetime of the this Pointer 5 Class Conversions 6 Gathering Information of Classes... 7 C++ Overloading and Symbol Mangling... 8 Demangling 8 Ambiguous Symbols 8 Other Command Line Hints 9 ELF Loader Options... 10 Debugging in C++ Code... 11 Target Order / Source Order 11 Breakpoints 12 Application Note C++ Debugging 1

Application Note C++ Debugging Version 06-Nov-2017 This application note describes dedicated TRACE32 PowerView commands and approaches that can be helpful when C++ applications are analyzed. Sample Code used by This Application Note Further chapters will contain pictures, commands and source code that are based to a small sample. This sample code implements two classes A and B, where B is derived from A. Class A class A { public: int na1; int na2; A(){na1 = 1; na2 = 2;} A(int a1, int a2){na1 = a1; na2 = a2;} virtual int Sum() { return na1 + na2; } virtual ~A(){;} }; UML Class Diagram A na1 : int na1 : int A ( ) A (a 1 : in t, a 2 : in t) S u m () : in t ~ A ( ) B nb1 : int nb2 : int B ( ) S u m ( ) : in t ~ B ( ) Class B class B: public A { public: int nb1; int nb2; B(){nb1 = 3; nb2 = 4;} virtual int Sum() { return A::Sum()+nb1+nb2; } virtual ~B(){;} }; Application Note C++ Debugging 2

Gathering Information of Objects Display Options Dedicated to Objects The Var.Watch or Var.View command can show the content of instances of structures or classes. The command SETUP.Var or the context menu entry Format will open a dialog with various display settings. The Inherited check box controls whether anything is displayed from the base classes. To show all known methods of the class, the Methods check box must be turned on. The integer number after a method indicates the index of that method within the Virtual Function Table. Application Note C++ Debugging 3

The Hidden check box controls whether artificially created symbols are visible. V-Table By the context menu commands Indirect Dump and Indirect List it is possible to navigate to the virtual function in order to check if the values match the debug information. Application Note C++ Debugging 4

Most Derived Class Generic algorithms use the polymorphic nature of classes they work with. These algorithms will handle pointers to objects that fulfill an interface or are derived from a certain parent class. The Most Derived Class is the class type that was used to create a particular instance. By default, the Var.Watch window will treat these pointers with the type that is used in the current context. The Derived option can be turned on for a certain entry of the Var.Watch window by double-clicking the tree node icon or using the context menu. void TestMostDerivedClass() { B* pb = new B(); A* pa = pb; //view content of pa here... pa = NULL; delete pb; }; or Double click here Context menu To automate the Most Derived Class feature, the [] operator can be used in PRACTICE: ; set nb1 to 1 Var.Set (*[pa]).nb1 = 1 ; display most derived class of pa Var.View *[pa] Lifetime of the this Pointer When a none-static method of a class is called, the object instance is transferred by the call, too. Within the method a symbol named this will be valid once the stack frame start code has finished. When a method is implemented into a single line of source code, it is necessary to do assembler steps until this is alive before any other class member can be observed correctly. The this symbol can be used to show the members of the instance: Var.View this Application Note C++ Debugging 5

Class Conversions The () operator can be used to cast an object to another class. ;cast this pointer to class B and display it Var.View (B*)this ;cast object at address 0x00114710 to class B and display it Var.View (B*)0x00114710 Application Note C++ Debugging 6

Gathering Information of Classes There are two ways to gather information about classes: the class browser and the symbol browser. The class browser lists all known classes in the type column. Righ-clicking a class opens a context menu. The context menu, for example, provides access to the class hierarchy diagram (Select the View Class Hierarchy option). Parent Via the context menu, it is also possible to view the details of a class (Select the View Details option). Size Offset Mangled Name The symbol browser can show things that are dedicated to one class by using its capabilities to filter names. Application Note C++ Debugging 7

C++ Overloading and Symbol Mangling Demangling In contrast to C, multiple functions can have the same name by using the overloading technique. The functions must then differ in their parameter signatures. In C++ object files, therefore an exported symbol is encoded using function name and parameter signature into one mangled name. The mangling can be different for different compilers. TRACE32 demangles the names controlled by symbol.demangle. The first parameter set whether the Demangler is turned on. The second parameter controls if the parameter signature is concatenated to the symbol name. Symbol of A::A(int,int) symbol.demangle OFF Demangler switched off ct 1AFiT1 symbol.demangle ON ON Demangler switched on A::A(int,int) symbol.demangle ON OFF Demangler switched on, but does not concatenate parameters A::A Ambiguous Symbols Due to the overloading technique of C++, the debug information contains ambiguous short symbol names. Resolving these symbols will result in an error message: This behavior can be controlled by the symbol.match setting: symbol.match Exact symbol.match Best symbol.match Choose Release error message when ambiguous symbol is resolved Take the first matching symbol Open a symbol browser to select the right symbol Application Note C++ Debugging 8

Other Command Line Hints C++ symbols are often very long. Therefore use the TAB key to select and automatically complete the input of a symbol. Symbols containing brackets must be enclosed in apostrophes to distinguish them from other parser functions that use brackets. The symbol browser opens and the symbol matching the passed pattern can be chosen when an input symbol contains an asterisk character. Application Note C++ Debugging 9

ELF Loader Options The Data.LOAD.Elf command has additional parameters to tune the loader for formats or circumstances it cannot detect correctly. Option /CPP /CFRONT /NoInclude /SingleLine /SingleLineAdjacent Behavior Used for ELF/STABS format if symbols are loaded correctly. Load additional symbol information for CFront based compilers that translate C++ code to C code. Ignore debug information that is related to code in header files. One source line is assigned to multiple target code parts. Therefore the source lines are multiplied, too. In the Source Order view of the Data.List window, these lines are merged behind a + symbol. When this option is passed, the debugger doesn t multiply the source lines. The source line is assigned to the first code part. The option is similar to /SingleLine, but only takes effect if the code parts are concatenated. Application Note C++ Debugging 10

Debugging in C++ Code Target Order / Source Order Due to the usage of inline code, one source line can match multiple code sections. When a memory section is displayed, it can be source order or target order. Source Order Source order mixes the code sections to the order inside the source file: Target Order mode is active for HLL debugging by default. Both calls of the inline function malloc2 will create one code piece each. Due to source order these code pieces are displayed above the MultiLineTest2 function. When the function is executed by Step.Over commands, the windows selected source line will jump to the matching code lines. This can be confusing some times. Target Order Target Order displays the code in the order of ascending addresses of the code behind: In this case it is more obvious that the compile has inlined the code from the malloc2 template. The execution of the routine by Step.Over will work without any confusing jump to other source lines. Target Order display is the default in Mixed mode debugging. Application Note C++ Debugging 11

Breakpoints symbol.foreach Sets breakpoints to every function and symbol. symbol.foreach "Break.Set *" A::* Sometimes it is necessary to break at a method for a certain object. This can be achieved by a breakpoint containing a condition that checks the passed this pointer of the instance. For example, the this pointer is passed by register R3 and the object has the address 0x0114710 the breakpoint for the function A::Sum would be set by: Break.Set A::Sum /CONDition Register(R3)==0114710 Application Note C++ Debugging 12