Hank Childs, University of Oregon May 27 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / /

Slides:



Advertisements
Similar presentations
Hank Childs, University of Oregon April 17 th, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
Advertisements

Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Introduction to C. A Brief History Created by Dennis Ritchie at AT&T Labs in 1972 Originally created to design and support the Unix operating system.
Gdb is the GNU debugger on our CS machines. gdb is most effective when it is debugging a program that has debugging symbols linked in to it. With gcc and.
Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / /
Homework Reading Programming Assignments
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
Hank Childs, University of Oregon April 24 th, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
1 A Simple but Realistic Assembly Language for a Course in Computer Organization Eric Larson Moon Ok Kim Seattle University October 25, 2008.
Hank Childs, University of Oregon May 15th, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __.
Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Developing C/C++ applications with the Eclipse CDT David Gallardo.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Hank Childs, University of Oregon May 8th, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __.
CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.
ENEE150 – 0102 ANDREW GOFFIN Testing and Debugging.
Hank Childs, University of Oregon May 13th, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __.
Hank Childs, University of Oregon May 19 th & 21st, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ /
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
C++ crash course Class 9 flight times program, using gdb.
Hank Childs, University of Oregon April 15th, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / /
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 2.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Minimal standard C program int main(void) { return 0 ; }
Unit - V. Debugging GNU Debugger helps you in getting information about the following: 1.If a core dump happened, then what statement or expression did.
CMSC 104, Version 8/061L14AssignmentOps.ppt Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips Reading Section.
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
Hank Childs, University of Oregon May 6th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __.
Hank Childs, University of Oregon May 20th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __.
Hank Childs, University of Oregon May 13th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __.
Hank Childs, University of Oregon May 11th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __.
Hank Childs, University of Oregon April 22 nd, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
Hank Childs, University of Oregon April 6 th, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / /
Lecture 5 Page 1 CS 111 Online Process Creation Processes get created (and destroyed) all the time in a typical computer Some by explicit user command.
Hank Childs, University of Oregon May 18th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __.
Hank Childs, University of Oregon April 15 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
Hank Childs, University of Oregon April 13 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Hank Childs, University of Oregon May 25 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / /
DEBUG.
Hank Childs, University of Oregon
Hank Childs, University of Oregon
C ++ MULTIPLE CHOICE QUESTION
Hank Childs, University of Oregon
Hank Childs, University of Oregon
Hank Childs, University of Oregon
Hank Childs, University of Oregon
Hank Childs, University of Oregon
Hank Childs, University of Oregon
Debugging with gdb gdb is the GNU debugger on our CS machines.
Process Creation Processes get created (and destroyed) all the time in a typical computer Some by explicit user command Some by invocation from other running.
CSE 351 Section 1: HW 0 + Intro to C
gdb gdb is the GNU debugger on our CS machines.
Lab: ssh, scp, gdb, valgrind
Computer Architecture “Bomb Lab Hints”
Hank Childs, University of Oregon
Hank Childs, University of Oregon
Lab: ssh, scp, gdb, valgrind
Hank Childs, University of Oregon
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Hank Childs, University of Oregon
Homework Reading Programming Assignments Finish K&R Chapter 1
Hank Childs, University of Oregon
Program Execution in Linux
CSE 303 Concepts and Tools for Software Development
Debugging.
Makefiles, GDB, Valgrind
Presentation transcript:

Hank Childs, University of Oregon May 27 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __ \/ / |/_/ / __ `/ __ \/ __ / / / _/_// / __/ /___/ /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / /____/_/ / /__/_ __/_ __/ \____/_/ /_/_/_/|_| \__,_/_/ /_/\__,_/ \____/_/ \____//_/ /_/ Lecture 18: templates and STL

Announcements Weekend OH? Extra Credit 3H, 4B, 4C posted

Announcements: Rest of Term 3G: assigned Monday (two days ago), due Monday (5 days from now) 3H, 4B, 4C: assigned today, nominally due on Friday June 3 rd – But: you can take until the Final to get them (3H, 4A, 4B) wrapped up (& they will not be late)

3H Will look at this together at the end of lecture

4B

4C

Live Code: Weds June 1st Disclaimer: don’t be discouraged Will go thru ~3E, definitely not past 3F Who can attend? – Anyone who has completed the project – Anyone who has not completed the project, but is getting 50% credit Who can not attend? – Anyone who has extenuating circumstances and expects full credit for late work

Review

gettimeofday (there are lots of Unix system calls, which do lots of different things)

gettimeofday example

Debugging

Pitfall #2: millions of print statements This will result in millions of print statements … hard to debug.

Reducing print statements

Debugging: Debuggers

Debuggers Allow you to set breakpoints Allow you to inspect variables Show you where a program crashed

Debuggers gdb: – GNU debugger – goes with gcc/g++ lldb: – CLANG debugger

Debugging Symbols Object files: – by default, are compact and contain minimal information that connects to your original program – optionally, can be instructed to contain increased linkage what line of code did these instructions come from? what variable name is in this register? You enable debugging symbols by adding “-g” to compile line “gcc –c file.C”  “gcc –g –c file.C” You enable debugging symbols by adding “-g” to compile line “gcc –c file.C”  “gcc –g –c file.C”

Running with gdb

Arguments You are running “./proj3A 3A_input.pnm 3A_output.pnm” In gdb, you would do: % gdb proj3A (gdb) run 3A_input.pnm 3A_output.pnm

“core” files When a program crashes, it can create a “core” file – This file contains the state of memory when it crashes – It is very large, and can fill up filesystems So system administrators often disable its generation – “ulimit –c 0”  “ulimit –c ” – You can run a debugger on a program using a core file (tells you where it crashed) gdb a.out core

Valgrind: a memory checker

Valgrind and GDB Valgrind and gdb are available on ix – Older versions of Mac are possible, newer are not – Linux is easy You will have an assignment to have a memory error-free and memory leak-free program with valgrind.

Templates

Motivation

First Template

Will now do an example to compare templates and virtual functions Will take some buildup…

Money Class

License Plate Class

Sorting With Templates

Doing the same with inheritance

Templates vs Virtual Functions Virtual functions: – Had to affect inheritance hierarchy – Overhead in function call (virtual function table) Templates: – Did not need to affect inheritance hierarchy, although function names had to coincide – No additional overhead (resolved at compile time)

Standard Template Library

Standard Template Library: STL Many, many templated types Can ease your programming burden Can also hide significant performance issues – And you use C/C++ for performance My recommendation: use with caution for code that needs to be performant

Vector

std::vector Always has the amount of memory you need Many STL algorithms work on it Memory allocation: – If you don’t have enough, double it (can be a big overestimation) Overhead in access – Maybe not a big deal if data-intensive?

STL: map

Outline Announcements Special Topics Review Potpourri from Lec 17 Templates Standard Template Library C++ Strings Bonus Slides

(not a template thing): String C++ string class is very useful Great implementation of a class that encapsulates a string

String methods

Bonus Topics

Upcasting and Downcasting Upcast: treat an object as the base type – We do this all the time! – Treat a Rectangle as a Shape Downcast: treat a base type as its derived type – We don’t do this one often – Treat a Shape as a Rectangle You better know that Shape really is a Rectangle!!

Upcasting and Downcasting what do we get?

Upcasting and Downcasting C++ has a built in facility to assist with downcasting: dynamic_cast I personally haven’t used it a lot, but it is used in practice Ties in to std::exception

Default Arguments default arguments: compiler pushes values on the stack for you if you choose not to enter them

Booleans New simple data type: bool (Boolean) New keywords: true and false

Backgrounding “&”: tell shell to run a job in the background – Background means that the shell acts as normal, but the command you invoke is running at the same time. “sleep 60” vs “sleep 60 &” When would backgrounding be useful?

Suspending Jobs You can suspend a job that is running Press “Ctrl-Z” The OS will then stop job from running and not schedule it to run. You can then: – make the job run in the background. Type “bg” – make the job run in the foreground. Type “fg” – like you never suspended it at all!!

printf Print to stdout – printf(“hello world\n”); – printf(“Integers are like this %d\n”, 6); – printf(“Two floats: %f, %f”, 3.5, 7.0); Have you ever wondered how printf takes a variable number of arguments?

Variable-Length Argument Lists Adapted from Kernigan & Ritchie C book

3H Will look at this together now

Stress Test Project (3H) We will have ~60 stress tests We can’t check in 60 baseline images and difference them all – Will slow ix to a grind Solution: – We commit “essence of the solution” – We also complement that all images posted if needed.

Checksums From Wikipedia Most useful when input is very large and checksum is very small