Lab 8 - Vectors, and Debugging. Directions

Similar documents
Supplement: Visual C++ Debugging

A Tutorial for ECE 175

Debugging in Small Basic is the process of analysing a program to detect and fix errors or improve functionality in some way.

Programming Logic - Beginning

Lab 11 - Arrays, Searching and Sorting Directions

Intro to MS Visual C++ Debugging

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018

Computer Science II Lab 3 Testing and Debugging

ECE2049 Embedded Computing in Engineering Design. Lab #0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

First, let s just try to run the program. When we click the button we get the error message shown below:

Instructions PLEASE READ (notice bold and underlined phrases)

The NetBeans Debugger: A Brief Tutorial

Changing the Embedded World TM. Module 3: Getting Started Debugging

Debugging INTRODUCTION DEBUGGER WHAT IS VBA'S DEBUGGING ENVIRONMENT?

JCreator. Starting JCreator

7 The Integrated Debugger

CS 150 Lab 3 Arithmetic and the Debugger. Lab 3.0 We are going to begin using the Visual Studio 2017 debugger to aid with debugging programs.

Outline. Debugging. In Class Exercise Solution. Review If Else If. Immediate Program Errors. Function Test Example

Lab 9 - Classes and Objects Directions

Laboratory Assignment #4 Debugging in Eclipse CDT 1

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

Introduction to IntelliJ

After completing this appendix, you will be able to:

A Tour of the Scripting System. Contents

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Testing and Debugging

Code::Blocks Student Manual

Under the Debug menu, there are two menu items for executing your code: the Start (F5) option and the

Debugging. CSE 2231 Supplement A Annatala Wolf

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

Step through Your DATA Step: Introducing the DATA Step Debugger in SAS Enterprise Guide

1 Introduction to MARS

GETTING STARTED WITH ECLIPSE Caitrin Armstrong

1.2 - Introduction to the IAR Workbench IDE *

Flow of Control: Loops

Section 2: Developer tools and you. Alex Mariakakis (staff-wide)

Problem Set 1: Unix Commands 1

Install Visual Studio Community Version 2017

SECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing

EE 355 Lab 3 - Algorithms & Control Structures

Assignment 1: Port & Starboard

6L00IA - Introduction to Synergy Software Package Short Version (SSP v1.2.0) Renesas Synergy Family - S7 Series

Quick Start Guide for the Turbo upsd DK3300-ELCD Development Kit- RIDE

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

ME 142 Engineering Computation I. Debugging Techniques

Introduction to Computation and Problem Solving

Marten van Dijk, Syed Kamran Haider

hw6, BFS, debugging CSE 331 Section 5 10/25/12 Slides by Kellen Donohue

Code::Blocks Student Manual

We first learn one useful option of gcc. Copy the following C source file to your

Visual Studio.NET. Although it is possible to program.net using only the command OVERVIEW OF VISUAL STUDIO.NET

Lab 0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

Starting Embedded C Programming CM0506 Small Embedded Systems

Twitter Tag Cloud Documentation

ENCM 369 Winter 2017 Lab 3 for the Week of January 30

CS2: Debugging in Java

Comp Assignment 2: Object-Oriented Scanning for Numbers, Words, and Quoted Strings

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Debugging in AVR32 Studio

Introduction. Key features and lab exercises to familiarize new users to the Visual environment

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

HPCC - Hrothgar. Getting Started User Guide TotalView. High Performance Computing Center Texas Tech University

Laboratory 5: Implementing Loops and Loop Control Strategies

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.

Using the Xcode Debugger

BASICS OF THE RENESAS SYNERGY PLATFORM

C++ for Everyone, 2e, Cay Horstmann, Copyright 2012 John Wiley and Sons, Inc. All rights reserved. Using a Debugger WE5.

NEW CEIBO DEBUGGER. Menus and Commands

Programming Studio #9 ECE 190

I want to buy the book NOW!

Debugging and Handling Exceptions

Getting Started with Visual Studio

Debugging Abstract State Machine Specifications: An Extension of CoreASM

ENGR 40M Project 3c: Switch debouncing

HOW TO USE CODE::BLOCKS IDE FOR COMPUTER PROGRAMMING LABORATORY SESSIONS

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

Project Debugging with MDK-ARM

AVR Simulation with the ATMEL AVR Studio 4 Updated: 8/3/2005

IV-8Debugging. Chapter IV-8

We are built to make mistakes, coded for error. Lewis Thomas

Assembly Programming in Atmel Studio 7 Step by Step Tutorial

Integrated Software Environment. Part 2

CMSC 132: Object-Oriented Programming II. Administrivia

Your code must have been compiled with the -g compiler option. Example:

PRACTICE-LABS User Guide

Adafruit WebIDE. Created by Tyler Cooper. Last updated on :29:47 PM UTC

Exercise Session 6 Computer Architecture and Systems Programming

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

An Introduction to Komodo

IDE: Integrated Development Environment

COMP2121 Introductory Experiment

Introduction to C/C++ Programming

BasicScript 2.25 User s Guide. May 29, 1996

Lab Exercise 1 Using EGit and JUnit

SQL Server. Management Studio. Chapter 3. In This Chapter. Management Studio. c Introduction to SQL Server

LAB #8. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:

12/14/2016. Errors. Debugging and Error Handling. Run-Time Errors. Debugging in C# Debugging in C# (continued)

VB Net Debugging (Console)

ENGR 102 Engineering Lab I - Computation

Homework 4 Addressing Modes

How does breakpoints work in debuggers? Vineel Kumar Reddy Kovvuri

Transcription:

Lab 8 - Vectors, and Debugging. Directions The labs are marked based on attendance and effort. It is your responsibility to ensure the TA records your progress by the end of the lab. While completing these labs, you are encouraged to help your classmates and receive as much help as you like. Assignments, however, are individual work. You may not work on assignments during your lab time. 1. Collecting Phrase 1. Write a program which repeatedly reads in phrases (strings) from the user until the user enters a 0-length string. Phrases may have multiple words. What statement do you have to use to make it work? Store each phrase in a vector. Hint: You can find the length of a string using: string message = "Hello"; int dalength1 = message.size(); 2. Write a function which accepts the vector of phrases as a parameter and returns the shortest phrase: string findshortest(vector<string> data); Hint: You can find the length of the first element of the vector using: int dalength2 = data[0].size(); Have main() call findshortestphrase() and output the phrase. 3. Sample output: Enter a phrase: Hello world! Enter a phrase: To be, or not to be? Enter a phrase: if (b!b)... Enter a phrase: findshortest() returned: Hello world! 4. Test your program. Test with two elements Test with three or more elements 5. Understanding: How to create, write to, and read from vectors. How to pass a vector into a function. Generated Jul 11, 2011, 12:28 AM Page 1/6 Dr. B. Fraser

2. Debugger Visual C++ has a built in debugger. This tool is very very very helpful when tracking down why your program is doing something wrong. 1. Using your phrase-reading program from above, go to the findshortest() function. 2. Right click on the first line of the function and select Breakpoint --> Insert Breakpoint. You will see a red dot appear in the left margin of the code. You can also toggle the breakpoint by pressing F9 3. Run your program by selecting Debug --> Start debugging (or press F5). Enter in a few (about three) phrases and have the program find the shortest phrase. Your program will seem to pause; the debugger has taken over and interrupted your program so you can debug it. 4. In Visual Studios, you should now see a tool bar for debugging (near top of screen). On the tool bar there is a green arrow for Continue (F5). If you click this, it will let your program run until it hits another breakpoint. This is useful if you want to let your program keep running. The blue stop button completely stops your application and returns you to the normal coding setup within Visual Studios. This is useful if you have found the error or want to change something. The Step Over button executes the current line of code you are on and then pauses again on the next line: useful for slowly single-stepping through your code. Yes, this does actually execute the current line; it does not just skip it. The Step Into button is like Step Over, except it will trace into any (and all) functions. Often it is better to use Step Over so you don't inadvertently end up debugging some function in vectors or strings. 5. Click the Step Over button a couple times. You should see the yellow arrow on the left move to the next line of code each time you click Step Over (F10). Generated Jul 11, 2011, 12:28 AM Page 2/6 Dr. B. Fraser

6. Mouse over a variable in your function. You should see a little pop-up box that shows you the value of the variable your mouse is hovering over. Note that if your program has not yet created the variable, it may not have a valid value. 7. Notice the Autos view at the bottom shows some variables used by your code. Use this for watching what is happening. For example, you can trace calculations, or watch your loop iteration variable to see what element of a vector it will access. 8. Use Step Over to keep stepping through the function until it exits. Notice you can follow it back into main(). 9. Stop the debugger with the blue stop button. 10. Introduce a bug into your findshortest() function. Instead of looping up until your counter is < the size of the vector, loop until <= size of vector. Remove the breakpoint in findshortest(). Re-run the program and create two phrases, then let it continue to find the shortest. Your program should generate a run-time exception looking like the following. Select Retry to begin debugging the application. Generated Jul 11, 2011, 12:28 AM Page 3/6 Dr. B. Fraser

You should then see the following window. Select Break. You will now likely be looking at some complex code you did not write! This is some code inside the vectors. You need to change the stack frame. On the tool bar at the top, look for a drop-down named "Stack Frame:". Try selecting a couple different options. Find one to point to findshortest(), and another to main(). The stack frame is which level of the function calls you are debugging. See which line it is pointing to in findshortest(); it should be the line where you tried to access one too many elements. Stop the debugger, correct the code and re-run the program. 11. Understanding: Feel comfortable using the debugger to track down hard to understand bugs. If something is not working, trace it through and see what's going wrong. Generated Jul 11, 2011, 12:28 AM Page 4/6 Dr. B. Fraser

3. Finding Phrases with a Vector Continue the phrases program from above. Use the debugger when you encounter any errors! 1. Write a function which is passed the vector of phrases and returns the index of the shortest phrase: int findshortestidx(vector<string> data); Have main() call this function and output both the index of the element (an int), and the actual element (the phrase) itself. Hint: You get the index from the return value of the function call, and using that index you can look-up the phrase in the vector. 2. Write a function which returns the index of the longest phrase: int findlongestidx(vector<string> data); Have main() call this function and output both the index of the element (an int), and the actual element (the phrase) itself. 3. Write a function which accepts a vector of phrases (strings) and swaps the longest and shortest phrases in the vector. The function should change the actual vector you are passing in. How can you pass the vector in so that it can be changed? Use some of the functions you have defined above to simplify your task. Have main() call this function, and then repeat the calls to findshortestidx() and findlongestidx() and output the indices and elements as before. 4. Test your program. Test with two elements: they should swap. Test with three elements: the correct two should swap. Sample output: Enter a phrase: Hello world! Enter a phrase: To be, or not to be? Enter a phrase: if (b!b)... Enter a phrase: findshortest() returned: Hello world! Shortest idx = 0 = Hello world! Longest idx = 1 = To be, or not to be? Shortest idx = 1 = Hello world! Longest idx = 0 = To be, or not to be? 5. Understanding: How to pass a vector to a function. What is the difference between returning the element in a vector (in this case a string), and returning the index of an element (an int)? Generated Jul 11, 2011, 12:28 AM Page 5/6 Dr. B. Fraser

4. Challenges Make the phrases program to work when the user enters no phrases. Investigate the use of step into, step over, and continue with your program. Experiment with the vector version of the phrase program. How do vectors appear in the debugger? When you have the debugger "broken-into" a function call, experiment with the "Stack Frame" drop-down box on the tool-bar. It will allow you to select which function to look at in the debugger. It will show you the current function (current stack frame), or the calling function (previous stack-frame), and so on. This can be very helpful when your function was passed in a bad value (such as an invalid parameter value). 5. Skills and Understanding You should now be able to answer all the "understanding" questions in the previous sections. Complete the following to get credit for the lab: Show the TA the following: Your operational programs which complete all of the above tasks. The TA may ask you to explain any section of the lab, or answer any of the "Understanding" questions. Nothing is to be submitted electronically or in hard-copy for this lab. Generated Jul 11, 2011, 12:28 AM Page 6/6 Dr. B. Fraser