CSE 361S Intro to Systems Software Lab #2

Similar documents
These tasks can now be performed by a special program called FTP clients.

INSTALLING CCRQINVOICE

Assignment #5: Rootkit. ECE 650 Fall 2018

Project 4: System Calls 1

McGill University School of Computer Science COMP-206. Software Systems. Due: September 29, 2008 on WEB CT at 23:55.

Municode Website Instructions

Upgrading Kaltura MediaSpace TM Enterprise 1.0 to Kaltura MediaSpace TM Enterprise 2.0

Arduino Basics Intro to ArduBlocks

Installing Photran with Eclipse (MinGW or Cygwin)

Lab 0: Compiling, Running, and Debugging

Systems & Operating Systems

RxAXIS Security Module 09/25/2013

I. Introduction: About Firmware Files, Naming, Versions, and Formats

Getting Started with the Web Designer Suite

Guidance for Submitting an application or Nomination in AAS Ishango Online System

Guidance for Applicants: Submitting an application in AAS Ishango Grants Management

I. Introduction: About Firmware Files, Naming, Versions, and Formats

Enabling Your Personal Web Page on the SacLink

APPLY PAGE: LOGON PAGE:

Preparation: Follow the instructions on the course website to install Java JDK and jgrasp on your laptop.

Backup your Data files before you begin your cleanup! Delete General Ledger Account History. Page 1

Renewal Reminder. User Guide. Copyright 2009 Data Springs Inc. All rights reserved.

STIDistrict AL Rollover Procedures

Delete General Ledger Account History

Create Your Own Report Connector

Exporting and Importing the Blackboard Vista Grade Book

Xilinx Answer Xilinx PCI Express DMA Drivers and Software Guide

BI Publisher TEMPLATE Tutorial

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

istartsmart 3.5 Upgrade - Installation Instructions

Your New Service Request Process: Technical Support Reference Guide for Cisco Customer Journey Platform

1 Getting and Extracting the Upgrader

Using the Swiftpage Connect List Manager

STANLEY Healthcare University Training & Certification Portal. Quick Reference Guide

Quick Tips

HPE LoadRunner Best Practices Series. LoadRunner Upgrade Best Practices

Proper Document Usage and Document Distribution. TIP! How to Use the Guide. Managing the News Page

1 Getting and Extracting the Upgrader

FedVTE Training Advisor Guide

Re-Flashing Your CDM-760 Advanced High-Speed Trunking Modem

Kaltura MediaSpace TM Enterprise 2.0 Requirements and Installation

TUTORIAL --- Learning About Your efolio Space

Getting Started with the SDAccel Environment on Nimbix Cloud

Reading and writing data in files

OASIS SUBMISSIONS FOR FLORIDA: SYSTEM FUNCTIONS

Lab 4. Name: Checked: Objectives:

Reviewer Information Sheet for Committee Members

Introduction to Eclipse

Entering an NSERC CCV: Step by Step

Secure File Transfer Protocol (SFTP) Interface for Data Intake User Guide

Step- by- Step Instructions for Adding a HotPot Activity 1. Click the Turn editing on button on the course home page.

Using UB Stream and UBlearns

MyUni Adding Content. Date: 29 May 2014 TRIM Reference: D2013/ Version: 1

Frequently Asked Questions Read and follow all instructions for success!

Stealing passwords via browser refresh

TRAINING GUIDE. Overview of Lucity Spatial

SmartPass User Guide Page 1 of 50

Using the Swiftpage Connect List Manager

Date: October User guide. Integration through ONVIF driver. Partner Self-test. Prepared By: Devices & Integrations Team, Milestone Systems

Cookies: enable, disable or delete cookies

Please contact technical support if you have questions about the directory that your organization uses for user management.

1 Getting and Extracting the Upgrader

Oracle Universal Records Management Oracle Universal Records Manager Adapter for Documentum Installation Guide

Lab 1 - Calculator. K&R All of Chapter 1, 7.4, and Appendix B1.2

State Assessment Program Indiana Released Items Repository Quick Guide

WorldShip PRE-INSTALLATION INSTRUCTIONS: INSTALLATION INSTRUCTIONS: Window (if available) Install on a Single or Workgroup Workstation

Procurement Contract Portal. User Guide

ClassFlow Administrator User Guide

User Guide. ACE Data Source. OnCommand Workflow Automation (WFA) Abstract PROFESSIONAL SERVICES

Qualtrics Instructions

Scroll down to New and another menu will appear. Select Folder and a new

You may receive a total of two GSA graduate student grants in your entire academic career, regardless of what program you are currently enrolled in.

University Facilities

Tips For Customising Configuration Wizards

Using CppSim to Generate Neural Network Modules in Simulink using the simulink_neural_net_gen command

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

BANNER BASICS. What is Banner? Banner Environment. My Banner. Pages. What is it? What form do you use? Steps to create a personal menu

UPGRADING TO DISCOVERY 2005

USER GUIDE. Thanks for purchasing the igate! You ll need to follow these five Configuration Steps to get your igate up and running:

WebEx Web Conferencing Quick Start Guide

Test Pilot User Guide

Medtech Evolution. Installation Guide

Element Creator for Enterprise Architect

Laboratory Exercise 3 Using the PIC18

Frequently Asked Questions Read and follow all instructions for success!

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture2 Functions

Campuses that access the SFS nvision Windows-based client need to allow outbound traffic to:

Introduction to InfoSec Recitation 2. Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)

Working With Audacity

Technical Paper. Installing and Configuring SAS Environment Manager in a SAS Grid Environment

OATS Registration and User Entitlement Guide

CS510 Concurrent Systems Class 2. A Lock-Free Multiprocessor OS Kernel

Model WM100. Product Manual

Adverse Action Letters

Information on using ChurchApp

Managing Your Access To The Open Banking Directory How To Guide

Extended Vendors lets you: Maintain vendors across multiple Sage 300 companies using the Copy Vendors functionality. o

Technical Paper. Installing and Configuring SAS Environment Manager in a SAS Grid Environment with a Shared Configuration Directory

Online Banking for Business USER GUIDE

Manual for installation and usage of the module Secure-Connect

Transcription:

Due: Thursday, September 22, 2011 CSE 361S Intr t Systems Sftware Lab #2 Intrductin This lab will intrduce yu t the GNU tls in the Linux prgramming envirnment we will be using fr CSE 361S this semester, which includes gcc, as, and gdb. Yu will learn hw t cmpile, assemble, execute, and debug C and assembly language prgrams. Assembling and Executing 1. Lgin and pen a terminal windw. Lgin using yur cec accunt. If yu are in the Windws lab (Lpata 401), bt the Linux virtual machine (VM). Lgin t the VM, again using yur cec accunt. After yu are lgged in t Linux, click n Applicatins > System Tls > Terminal t pen a new terminal shell windw. The terminal windw will default t the hme directry fr yur cec accunt. If yu wish, use the mkdir {name} cmmand t create a sub-directry with the name f yur class (e.g. use the cmmand: mkdir cse361s). Then switch t this directry using the cd {name} cmmand (e.g. cd cse361s). 2. Dwnlad files fr Lab 2. Dwnlad the files needed fr Lab 2 int the current directry (either yur hme directry r the directry yu just created) by ging t the class webpage and rightclicking n the link labeled cse361s_lab2.tar and selecting "Save Link Target As..."). Unpack the files using the Linux cmmand tar xf cse361s_lab2.tar. This will create a directry named lab2 in yur directry. This directry cntains the C and assembly files needed fr this lab. 3. Cmpile/Assemble the Lab 2 prgrams. After untarring the Lab 2 files, use the cd lab2 cmmand t switch t the lab2/ directry. Then cmpile and assemble the prgrams fr Lab 2 using either the make r the make all cmmand (make and make all amunt t the same cmmand since typing make by itself defaults t make all). Nte: make -n will shw yu which 1

cmmands make will execute, withut actually executing them. This can be quite helpful at times. In the prcess f "making" the prgrams, yu will see a listing f the cmmands used t cmpile and assemble the C and assembly prgrams using gcc and as. It is recmmended that yu try executing each ne f these cmmands n yur wn and use ls t check what files are generated as a result f each cmmand. Be sure t use the make clean cmmand t delete all the executables and. files befre executing the "make" cmmands n yur wn. Yu may als want t use the less Makefile cmmand t see hw the Makefile perfrms the cmpilatin/assembly prcess. 4. Execute the C and assembly executables. After "making" the prgrams, try running the C and assembly prgrams using the lab2_cprg and lab2_asmprg executables, respectively. T execute a prgram that resides in the current directry, yu need t tell the shell t lk in the current directry. The current directry is dented with a dt,., s lab2_cprg is executed with the cmmand:./lab2_cprg 5. Debug the C executable, lab2_cprg. T begin debugging the C executable using the gdb debugger, execute the cmmand: gdb lab2_cprg. We will start ff by intrducing a few simple debugging cmmands in gdb. First f all, start running the prgram in gdb. T begin debugging, yu must first begin executing the prgram within gdb. When gdb starts up, the prgram is merely laded; it is nt yet executing. Befre running the prgram, use the break main cmmand t set a break pint at the first instructin in main(). Then type run (r r) t begin running the prgram. Yu will nte that the prgram breaks immediately at the entrance t main(). Use the stepi (r si) cmmand t trace int instructins. The stepi (r si) cmmand traces int each instructin. Effectively, this means that it executes the next single machine/assembly instructin. Fr prcedure r interrupt calls, this means that it executes nly the instructin that transfers cntrl t the prcedure, causing it t jump int that prcedure/interrupt (i.e. it steps 'int' the prcedure/interrupt). 2

Use the si cmmand a cuple times t watch the prgram's prgress as yu step thrugh the cde. When yu get t the functin call fr get_number(), ntice that yu actually "step int" the prcedure s that yu can watch the executin f each individual statement in that prcedure. If yu ever want t re-start frm the beginning f the prgram, simply use the run (r) cmmand again, which will re-start executin f the prgram frm the beginning, stpping immediately at the first breakpint (at main()). Use the nexti (r ni) cmmand t trace ver instructins. The nexti (r ni) cmmand traces ver each instructin. Effectively, this means that it executes the next single instructin in the active prcedure. Fr prcedure r interrupt calls, this means that it executes the full prcedure r interrupt (i.e. it steps 'ver' the prcedure/interrupt). Try stepping thrugh the prgram again, but this time use the ni cmmand instead. Ntice that this time, yu dn't jump int the get_number() functin. Stepping "ver" this functin simply causes it t execute "behind the scenes", s that yu dn't have t watch all the gry details if yu dn't want/need t. Use the step and next cmmands and cmpare them t stepi and nexti. Use the nline help (h) facility t learn abut step and next. Cmpare them with stepi and nexti. Yu will likely find these tw cmmands mre cnvenient when wrking with C cde. Watching variables. Smetimes it is desirable t watch hw the value f a variable changes as yu trace thrugh the prgram. It is pssible t watch variables in this fashin using the display {variable name} cmmand. Fr example, re-start executin frm the beginning f the prgram again, but this time use the cmmand display n t watch the value f variable "n" as yu step thrugh the beginning f the prgram. T see a full listing f all the variables that are currently being watched, use the inf display cmmand. Likewise, if yu want t delete a variable frm being watched, yu can use the cmmand delete display {variable number}. Display memry. Often, yu will want t watch a whle blck f memry as ppsed t a small set f variables. There's n way yu can autmatically have a blck f memry displayed after each step like yu can with variables, but yu can still easily display the cntents f memry with a single cmmand after each step. The cmmand x/{number f byes} {start address} will display the specified number f bytes starting at the specified 3

address (e.g. x/32 0x7f3e9a10 will shw the cntents f memry between addresses 0x7f3e9a10 and 0x7f3e9a2f), inclusive. Furthermre, t prevent yu frm having t retype this cmmand after each step, yu can simply use the up and dwn arrws t scrll thrugh the list f cmmands recently executed in gdb. The primary prblem in displaying memry is that yu must knw the address(es) f the memry lcatins yu which t view. Frtunately, the memry addresses f variables can be easily determined in gdb using the print &{variable name} cmmand (e.g. print &n will give the address fr variable "n"). Display registers. It is als ften useful (mres with assembly debugging than C debugging) t view the values in the register file. Use the inf registers cmmand t d this. View (lcal) prgram cde. While the si and ni cmmands display the next instructin t execute, yu may ften want t see mre cmplete sectins f cde. Yu can display the 10 lines f cde arund the next statement t execute in the debugger using the list (r l) cmmand. Or if yu want t display the 10 lines f cde arund a functin declaratin, yu can use the list {functin name} cmmand (e.g. l main). View assembly cde. An alternate way t view the assembly cde (r when debugging in C and needing t view the equivalent assembly), use the disassemble {label/functin name} (r disas {label/functin name}) cmmand (e.g. disas main). Other debugging functins: Exit the debugger using the quit (r q) cmmand. Cntinue executing a prgram using the cntinue (r c) cmmand. Executin will nly stp after reaching a breakpint, the end f the prgram, r a similar end-f-prgram prcedure/interrupt call. This functin is particularly useful in cnjunctin with breakpints. Als feel free t experiment with ther debugging functins. Yu can use the help (r h) cmmand t find directins fr using ther debugging utilities. Cntinue t trace thrugh lab2_cprg in gdb and examine what each instructin des. Be sure t use si and ni as needed. 6. Debug the assembly executable, lab2_asmprg. 4

T begin debugging the assembly executable using the gdb debugger, execute the cmmand: gdb lab2_asmprg. Prceed t trace thrugh the lab2_asmprg executable just like yu did with the C prgram -- first start by setting a break pint at the main functin, run the prgram, and then prceed t step thrugh fllwing the break pint. Nte that in assembly, any label in the surce cde (e.g. main:, i_lp:, exit_i_lp:, print_lp, etc.) is treated as a functin name, s it wrks best t use si when stepping thrugh the cde, but making sure t use ni n thse assembly functin calls t external functins (e.g. get_number and printf). 7. Questins: Try t answer the fllwing questins. Put yur answers in a file using the same naming cnventin as befre: <lastname><firstinitial>_lab2.txt, and uplad yur file t telesis fr submissin. 1. What number series is prduced by the C prgram? By the assembly prgram? Are the tw prgrams equivalent? 2. What happens when the user enters a value nt in the allwable range? 3. What d the CMP and JAE instructins d? What des JMP d? Hw are they similar? Hw are they different? 4. What are the #define preprcessing directives fr in the C prgram? Is there an equivalent in the assembly prgram (and if s, what)? 5. Yu likely fund the experiences f debugging in C versus debugging in assembly bth smewhat similar and smewhat different. What debugging cmmands did yu find mre useful fr debugging C? Fr debugging assembly? 6. Hw culd yu change the C cde s that it printed ut every 2nd dd number, starting frm 1 (i.e. 1, 5, 9, 13, etc.)? Hw culd yu similarly change the assembly cde (Nte: this is a bit tugher t figure ut...)? 7. Challenge Questin: Hw might yu g abut changing the C cde s that it requested tw numbers, n and x, s that the prgram wuld print ut n numbers including every xth number starting frm 1? Hw abut in the assembly cde (Nte: this is the really tricky part...)? 5