Carnegie Mellon 1 Debugging 15-213: Introduction to Computer Systems Recitation 12: Monday, Nov. 9 th, 2013 Yixun Xu Section K.

Slides:



Advertisements
Similar presentations
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Advertisements

Programming Types of Testing.
1 Optimizing Malloc and Free Professor Jennifer Rexford COS 217 Reading: Section 8.7 in K&R book
Malloc Recitation Section K (Kevin Su) November 5 th, 2012.
Welcome to Florida International University Online J.O.B.S. Link Applicant Tutorial.
DEBUGGING IN THE REAL WORLD : Recitation 4.
18-213: Introduction to Computer Systems April 6, 2015
Lab 3: Malloc Lab. “What do we need to do?”  Due 11/26  One more assignment after this one  Partnering  Non-Honors students may work with one other.
Welcome to the Brookdale Community College Online Employment System Applicant Tutorial.
1 Optimizing Malloc and Free Professor Jennifer Rexford
1 Welcome to the Colgate University Online Employment System Applicant Tutorial.
Swami NatarajanJuly 14, 2015 RIT Software Engineering Reliability: Introduction.
Bug Session Two. Session description In this session the use of algorithms is reinforced to help pupils plan out what they will need to program on their.
Microsoft ® Office Word 2007 Training Mail Merge II: Use the Ribbon and perform a complex mail merge [Your company name] presents:
Welcome to the University of Florida Online Employment System Applicant Tutorial.
Welcome to the Alaska Statewide System Online Employment System Applicant Tutorial.
Welcome to the Southeastern Louisiana University’s Online Employment Site Applicant Tutorial!
L6: Malloc Lab Writing a Dynamic Storage Allocator October 30, 2006
Chocolate Bar! luqili. Milestone 3 Speed 11% of final mark 7%: path quality and speed –Some cleverness required for full marks –Implement some A* techniques.
Welcome to the University of West Florida Online Employment System Applicant Tutorial.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
Building a Real Workflow Thursday morning, 9:00 am Lauren Michael Research Computing Facilitator University of Wisconsin - Madison.
CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.
Carnegie Mellon 1 Debugging Malloc Lab : Introduction to Computer Systems Recitation 12: Monday, Nov. 11 th, 2013 Marjorie Carlson Section A.
Stack and Heap Memory Stack resident variables include:
ICS 145B -- L. Bic1 Project: Main Memory Management Textbook: pages ICS 145B L. Bic.
Problem of the Day  Why are manhole covers round?
Debugging and Profiling With some help from Software Carpentry resources.
Building a Real Workflow Thursday morning, 9:00 am Lauren Michael Research Computing Facilitator University of Wisconsin - Madison.
Agenda Attack Lab C Exercises C Conventions C Debugging
Debugging Computer Networks Sep. 26, 2007 Seunghwan Hong.
CSE 123 Discussion 10/05/2015 Updated from Anup and Narendran’s excellent notes.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Goal Setting Why Should You Use Goal Setting?. What is a Goal Anyway? Goal is: the end toward which effort is directed. Goals are not dreams and wants.
Developer Best Practices R.SANTHANA GOPALAN. Developer Best Practices What is Workspace ? The directory where the developer edit the source files, compile,
Debugging 1/6/2016. Debugging 1/6/2016 Debugging  Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a program.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 10 – C: the heap and manual memory management.
C++ 程序语言设计 Chapter 12: Dynamic Object Creation. Outline  Object creation process  Overloading new & delete.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Carnegie Mellon Dynamic Memory Allocation : Introduction to Computer Systems Monday March 30th,
1 Debugging (Part 2). “Programming in the Large” Steps Design & Implement Program & programming style (done) Common data structures and algorithms Modularity.
Malloc Lab : Introduction to Computer Systems Recitation 11: Nov. 4, 2013 Marjorie Carlson Recitation A.
CSE 351 Dynamic Memory Allocation 1. Dynamic Memory Dynamic memory is memory that is “requested” at run- time Solves two fundamental dilemmas: How can.
Carnegie Mellon 1 Malloc Lab : Introduction to Computer Systems Friday, July 10, 2015 Shen Chen Xu.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
Carnegie Mellon 1 Malloc Recitation Ben Spinelli Recitation 11: November 9, 2015.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
Introduction to Computing Systems and Programming Programming.
Debugging Malloc Lab Detecting Memory-Related Errors.
CSE 333 – SECTION 2 Memory Management. Questions, Comments, Concerns Do you have any? Exercises going ok? Lectures make sense? Homework 1 – START EARLY!
Text2PTO: Modernizing Patent Application Filing A Proposal for Submitting Text Applications to the USPTO.
Carnegie Mellon Dynamic Memory Allocation : Introduction to Computer Systems Recitation 11: Monday, Nov 3, 2014 SHAILIN DESAI SECTION L 1.
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Testing and Debugging.
Recitation 11: More Malloc Lab
Lab: ssh, scp, gdb, valgrind
Recitation: C Review TA’s 19 Feb 2018.
Recitation 11: More Malloc Lab
Recitation 10: Malloc Lab
Optimizing Malloc and Free
Lab: ssh, scp, gdb, valgrind
Terminos españoles de ingeneria de computacion.
Recitation 11: More Malloc Lab
CSCI 380: Operating Systems Lecture #11 Instructor: William Killian
Optimizing Dynamic Memory Management
CSCI 380: Operating Systems Instructor: William Killian
Malloc Lab CSCI 380: Operating Systems
Makefiles, GDB, Valgrind
Recitation 10: Malloc Lab
Presentation transcript:

Carnegie Mellon 1 Debugging : Introduction to Computer Systems Recitation 12: Monday, Nov. 9 th, 2013 Yixun Xu Section K

Carnegie Mellon 2 News Malloc Lab due Thursday Nov 14 th

Carnegie Mellon 3 Errors Some errors are identified by the driver The error message is straightforward in most cases  “garbled byte” means part of the payload returned to the user has been overwritten by your allocator  “out of memory” occurs when the memory is used very inefficiently, or there are lost blocks

Carnegie Mellon 4 Errors But most of the times… Do “gdb mdriver” and “run” to find out which line segfaults  Note that a segfault occurring at line 200 could actually be caused by a bug on line 70

Carnegie Mellon 5 Segfault To resolve a segfault, it is necessary to find the earliest time things went wrong. One way to do this is to print the whole heap before/after relevant functions  Scroll up from the point of segfault and find the earliest operation that makes the heap look wrong  Sometimes this gives too much information, not all of which are useful The heap checker can make this easier  Checks violation of invariants (corruption of the heap)

Carnegie Mellon 6 Heap Checker Once you’ve settled on a design, write the heap checker that checks all the invariants of the particular design The checking should be detailed enough that the heap check passes if and only if the heap is truly well-formed Call the heap checker before/after the major operations whenever the heap should be well-formed Define macros to enable/disable it conveniently  e.g.

Carnegie Mellon 7 Invariants (non-exhaustive) Block level:  Header and footer match  Payload area is aligned List level:  Next/prev pointers in consecutive free blocks are consistent  Free list contains no allocated blocks  All free blocks are in the free list  No contiguous free blocks in memory (unless you defer coalescing)  No cycles in the list (unless you use circular lists)  Segregated list contains only blocks that belong to the size class Heap level:  Prologue/Epilogue blocks are at specific locations (e.g. heap boundaries) and have special size/alloc fields  All blocks stay in between the heap boundaries And your own invariants (e.g. address order)

Carnegie Mellon 8 Hare and Tortoise Algorithm Detects cycles in linked lists Set two pointers “hare” and “tortoise” to the beginning of the list During each iteration, move the hare pointer forward two nodes and move the tortoise forward one node. If they are pointing to the same node after this, the list has a cycle. If the tortoise reaches the end of the list, there are no cycles.

Carnegie Mellon 9 Other things to watch for Uninitialized pointers and/or memory Make sure mm_init() initializes everything  It is called by the driver between each iteration of every trace  If something is overlooked, you might be able to pass every single trace file, but the complete driver test will fail

Carnegie Mellon 10 Useful Tools Valgrind  Illegal accesses, uninitialized values… GDB  watch, rwatch, awatch

Carnegie Mellon 11 Asking for help It can be hard for the TAs to debug your allocator, because this is a more open-ended lab Before asking for help, ask yourself some questions:  What part of which trace file triggers the error?  Around the point of the error, what sequence of events do you expect?  What part of the sequence already happened? If you can’t answer, it’s a good idea to gather more information…  How can you measure which step worked OK?  printf, breakpoints, watchpoints…

Carnegie Mellon 12 Asking for help Bring to us a detailed story, not just a “plot summary”  “Allocations of size blah corrupt my heap after coalescing the previous block at this line number...” is detailed  “It segfaults” is not Most importantly: don’t hesitate to come to office hours if you really need help

Carnegie Mellon 13 Beyond Debugging: Error prevention It is hard to write code that are completely correct the first time, but certain practices can make your code less error-prone Plan what each function does before writing code  Draw pictures when linked list is involved  Consider edge cases when the block is at start/end of list Write pseudocode first Document your code as you write it

Carnegie Mellon 14 Beyond Debugging: Version control “I had 60 util points just 5 minutes ago!” Save the allocator after each major progress Most basic: copy files around using the cp command Alternatively: keep different versions in separate c files, and use “ln –s mm-version-x.c mm.c” to start using a particular version Or use git/svn/cvs…  Make sure your repository is private if you use remote repos

Carnegie Mellon 15 Optimization To achieve better performance, sometimes you would want to tweak certain parameters.  Number of size classes, the separation of size classes, the amount by which the heap is extended (CHUNKSIZE)… It is better to write modular and encapsulated code so that changing the parameters only requires changing a few lines of code  Use macros wisely

Carnegie Mellon 16 Optimization When you hit a bottleneck, find which part is limiting your performance A profiler is good for this kind of job To use gprof:  Change the Makefile to add “-pg” to the compilation flag  Run the driver. This will generate a file called gmon.out  Run “gprof./mdriver” to see the result  Don’t forget to change the Makefile back

Carnegie Mellon 17 Final Words Start now, if not already Come to office hours early Write the heap checker well Be prepared to start over several times Before handing in, check:  Does the header comment contain a detailed description of your approach?  Is the indentation correct? Any line over 80 chars? (go to autolab to verify these)

Carnegie Mellon 18 Questions? Good luck!