Scientific Programming in C IX. Debugging
|
|
- Justin Hines
- 5 years ago
- Views:
Transcription
1 Scientific Programming in C IX. Debugging Susi Lehtola 13 November 2012
2 Debugging Quite often you spend an hour to write a code, and then two hours debugging why it doesn t work properly. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 2/24
3 Debugging Quite often you spend an hour to write a code, and then two hours debugging why it doesn t work properly. Worst case scenario: spend many weeks finding a trivial bug, e.g., in the unit conversions. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 3/24
4 Debugging Quite often you spend an hour to write a code, and then two hours debugging why it doesn t work properly. Worst case scenario: spend many weeks finding a trivial bug, e.g., in the unit conversions. Break your problem into simple pieces and test them separately. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 4/24
5 Debugging, cont d You can always use manual debugging to figure out what goes out in the program, i.e. insert lots of printf statements. Another option is to use debugging tools such as gdb and valgrind. To use the debugging tools you need to use the -g flag when compiling. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 5/24
6 Debugging, cont d Perhaps the most common problem a beginning C programmer encounters is $. / a. out Segmentation f a u l t ( c o r e dumped ) In these cases you often just want to know where the segfault happens. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 6/24
7 Example program #i n c l u d e <s t d i o. h> i n t main ( v o i d ) { c o n s t i n t N=100; i n t a r r [N ] ; i n t i ; c o n s t i n t l =7; p r i n t f ( l=%i. \ n, l ) ; / E r r o r i s h e r e upper l i m i t s h o u l d be N, not 2 N / f o r ( i =0; i <2 N; i ++) a r r [ i ]= i ; p r i n t f ( l=%i. \ n, l ) ; } r e t u r n 0 ; Scientific Programming in C, fall 2012 Susi Lehtola Debugging 7/24
8 Using GDB Let s use the GNU Debugger gdb to see what happens in the program when it is run. $ gcc g s e g f a u l t. c $ gdb. / a. out GNU gdb (GDB) Fedora ( f c 1 7 ) Copyright (C) 2012 Free Software Foundation, Inc. L i c e n s e GPLv3+: GNU GPL v e r s i o n 3 o r l a t e r <h t t p : / / gnu. org / l i c e n s e s / g p l. html> This i s f r e e s o f t w a r e : you a r e f r e e to change and r e d i s t r i b u t e i t. There i s NO WARRANTY, to the extent permitted by law. Type show copying and show w a r r a n t y f o r d e t a i l s. This GDB was configured as x86 64 redhat linux gnu. For bug r e p o r t i n g i n s t r u c t i o n s, p l e a s e s e e : <http : / /www. gnu. org / software /gdb/ bugs / >... Reading symbols from /tmp/a. out... done. ( gdb ) r S t a r t i n g program : /tmp/a. out l =7. Program r e c e i v e d s i g n a l SIGSEGV, Segmentation f a u l t. 0 x i n main ( ) a t s e g f a u l t. c : a r r [ i ]= i ; ( gdb ) Scientific Programming in C, fall 2012 Susi Lehtola Debugging 8/24
9 Here GDB tells you straight away where the problem lies, i.e., at line 9 of segfault.c. You can also check what the value of i is when the assignment failed ( gdb ) d i s p i 1 : i = 111 As you can see, this is significantly larger than the size of the array. Buffer overruns aren t always detected by gdb. Changing the upper limit from 2N to 111 the code works seemingly normally. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 9/24
10 ... but as a result you are touching memory that you re not supposed to touch. As the result, the values of variables that haven t been touched in the code change. $. / a. out l =7. l =109. From this you see that the constant integer is placed in the memory location arr+109. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 10/24
11 It is often useful to monitor how variables change during the runtime of the code. First, let s set a breakpoint from where we want to start monitoring what happens. ( gdb ) b r e a k 10 B r e a k p o i n t 1 a t 0 x40054a : f i l e s e g f a u l t. c, l i n e 1 0. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 11/24
12 It is often useful to monitor how variables change during the runtime of the code. First, let s set a breakpoint from where we want to start monitoring what happens. ( gdb ) b r e a k 10 B r e a k p o i n t 1 a t 0 x40054a : f i l e s e g f a u l t. c, l i n e 1 0. If you have multiple translation units linked into the same program, you can define the unit with, e.g. ( gdb ) b r e a k s e g f a u l t. c : 1 0 B r e a k p o i n t 1 a t 0 x40054a : f i l e s e g f a u l t. c, l i n e 1 0. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 12/24
13 Now we run the code with r for run. ( gdb ) r S t a r t i n g program : /tmp/a. out l =7. B r e a k p o i n t 1, main ( ) a t s e g f a u l t. c : f o r ( i =0; i <111; i ++) { The execution of the program has halted at line 10. Let s look at how i and l change. Turn on the display of i and l with ( gdb ) d i s p i 1 : i = 0 ( gdb ) d i s p l 2 : l = 7 Scientific Programming in C, fall 2012 Susi Lehtola Debugging 13/24
14 and continue the execution onto the next line. ( gdb ) n e x t 11 a r r [ i ]= i ; 2 : l = 7 1 : i = 0 ( gdb ) 10 f o r ( i =0; i <111; i ++) { 2 : l = 7 1 : i = 0 ( gdb ) 11 a r r [ i ]= i ; 2 : l = 7 1 : i = 1 ( gdb ) 10 f o r ( i =0; i <111; i ++) { 2 : l = 7 1 : i = 1 ( gdb ) 11 a r r [ i ]= i ; 2 : l = 7 1 : i = 2 ( gdb ) Scientific Programming in C, fall 2012 Susi Lehtola Debugging 14/24
15 Hitting ENTER will just repeat the same command as seen above. From the output you see how the program runs. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 15/24
16 Hitting ENTER will just repeat the same command as seen above. From the output you see how the program runs. When the program enters the loop i=0 and l=7 and it has been checked that i<111. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 16/24
17 Hitting ENTER will just repeat the same command as seen above. From the output you see how the program runs. When the program enters the loop i=0 and l=7 and it has been checked that i<111. Next, arr[0] is set to 0. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 17/24
18 Hitting ENTER will just repeat the same command as seen above. From the output you see how the program runs. When the program enters the loop i=0 and l=7 and it has been checked that i<111. Next, arr[0] is set to 0. The for loop has been completed, i is incremented and it is once again checked that i<111. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 18/24
19 Hitting ENTER will just repeat the same command as seen above. From the output you see how the program runs. When the program enters the loop i=0 and l=7 and it has been checked that i<111. Next, arr[0] is set to 0. The for loop has been completed, i is incremented and it is once again checked that i<111. arr[1] is set to 1. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 19/24
20 Hitting ENTER will just repeat the same command as seen above. From the output you see how the program runs. When the program enters the loop i=0 and l=7 and it has been checked that i<111. Next, arr[0] is set to 0. The for loop has been completed, i is incremented and it is once again checked that i<111. arr[1] is set to 1. i is incremented and checked that i<111. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 20/24
21 Hitting ENTER will just repeat the same command as seen above. From the output you see how the program runs. When the program enters the loop i=0 and l=7 and it has been checked that i<111. Next, arr[0] is set to 0. The for loop has been completed, i is incremented and it is once again checked that i<111. arr[1] is set to 1. i is incremented and checked that i<111. arr[2] is set to 2. Scientific Programming in C, fall 2012 Susi Lehtola Debugging 21/24
22 The next command skips over any function calls; if you want to follow into them use the step command instead. The continue command continues running until the next breakpoint is encountered. ( gdb ) c C o n t i n u i n g. l =109. [ I n f e r i o r 1 ( p r o c e s s 12499) e x i t e d n o r m a l l y ] Scientific Programming in C, fall 2012 Susi Lehtola Debugging 22/24
23 Valgrind The use of the debugger doesn t tell you if you have errors in the memory management. These you can find with memory debuggers such as Valgrind. It is especially useful with dynamic memory allocation, as it also checks for leaked memory (memory that is malloc d but not free d). Scientific Programming in C, fall 2012 Susi Lehtola Debugging 23/24
24 Valgrind, cont d $ v a l g r i n d. / a. out ==13294== Memcheck, a memory e r r o r detector ==13294== Copyright (C) , and GNU GPL d, by J u l i a n Seward et a l. ==13294== Using Valgrind and LibVEX ; rerun with h f o r copyright i n f o ==13294== Command :. / a. out ==13294== l =7. ==13294== I n v a l i d w r i t e o f s i z e 4 ==13294== a t 0 x : main ( s e g f a u l t. c : 1 1 ) ==13294== A d d r e s s 0 x a i s not s t a c k d, malloc d o r ( r e c e n t l y ) f r e e d ==13294== ==13294== ==13294== P r o c e s s t e r m i n a t i n g w i t h d e f a u l t a c t i o n o f s i g n a l 11 ( SIGSEGV ) ==13294== A c c e s s not w i t h i n mapped r e g i o n a t a d d r e s s 0 x a ==13294== a t 0 x : main ( s e g f a u l t. c : 1 2 ) ==13294== I f you b e l i e v e t h i s happened as a r e s u l t o f a s t a c k ==13294== overflow in your program s main thread ( u n l i k e l y but ==13294== p o s s i b l e ), you can t r y to i n c r e a s e t h e s i z e o f t h e ==13294== main t h r e a d s t a c k u s i n g t h e main s t a c k s i z e= f l a g. ==13294== The main thread stack s i z e used in t h i s run was ==13294== ==13294== HEAP SUMMARY: ==13294== in use at e x i t : 0 bytes in 0 blocks ==13294== t o t a l heap usage : 0 a l l o c s, 0 f r e e s, 0 b y t e s a l l o c a t e d ==13294== ==13294== A l l heap b l o c k s were f r e e d no l e a k s a r e p o s s i b l e ==13294== ==13294== For counts of de t ec t ed and s u p p r e s s e d e r r o r s, rerun with : v ==13294== ERROR SUMMARY: 1 e r r o r s from 1 contexts ( suppressed : 2 from 2) Segmentation f a u l t ( c o r e dumped ) Scientific Programming in C, fall 2012 Susi Lehtola Debugging 24/24
Scientific Programming in C IV. Pointers
Scientific Programming in C IV. Pointers Susi Lehtola 1 November 2012 Pointers The feature at the heart of C are pointers, which are simply pointers to memory addresses. Scientific Programming in C, fall
More informationECE/ME/EMA/CS 759 High Performance Computing for Engineering Applications
ECE/ME/EMA/CS 759 High Performance Computing for Engineering Applications Elements of Program Debugging Dan Negrut, 2017 ECE/ME/EMA/CS 759 UW-Madison Debugging on Euler [with gdb] Slides on gdb include
More information12. Debugging. Overview. COMP1917: Computing 1. Developing Programs. The Programming Cycle. Programming cycle. Do-it-yourself debugging
COMP1917 12s2 Debugging 1 COMP1917: Computing 1 12. Debugging Overview Programming cycle Do-it-yourself debugging Debugging withgdb Nastier bugs Memory leaks COMP1917 12s2 Debugging 2 Developing Programs
More informationProgramming Tips for CS758/858
Programming Tips for CS758/858 January 28, 2016 1 Introduction The programming assignments for CS758/858 will all be done in C. If you are not very familiar with the C programming language we recommend
More informationScientific Programming in C VI. Common errors
Scientific Programming in C VI. Common errors Susi Lehtola 6 November 2012 Beginner errors If you re a beginning C programmer, you might often make off-by one errors when you use arrays: #i n c l u de
More informationCS2141 Software Development using C/C++ Debugging
CS2141 Software Development using C/C++ Debugging Debugging Tips Examine the most recent change Error likely in, or exposed by, code most recently added Developing code incrementally and testing along
More informationPerformance Measurement
ECPE 170 Jeff Shafer University of the Pacific Performance Measurement 2 Lab Schedule Activities Today / Thursday Background discussion Lab 5 Performance Measurement Next Week Lab 6 Performance Optimization
More informationThe Valgrind Memory Checker. (i.e., Your best friend.)
The Valgrind Memory Checker. (i.e., Your best friend.) Dept of Computing Science University of Alberta modifications by Stef Nychka October 24, 2007 Attribution. Introduction Some of the material in this
More informationCMPSC 311- Introduction to Systems Programming Module: Debugging
CMPSC 311- Introduction to Systems Programming Module: Debugging Professor Patrick McDaniel Fall 2016 Debugging Often the most complicated and time-consuming part of developing a program is debugging.
More informationDebugging (Part 2) 1
Debugging (Part 2) 1 Programming in the Large Steps Design & Implement Program & programming style (done) Common data structures and algorithms Modularity Building techniques & tools (done) Test Testing
More informationCSCI-1200 Data Structures Spring 2016 Lecture 6 Pointers & Dynamic Memory
Announcements CSCI-1200 Data Structures Spring 2016 Lecture 6 Pointers & Dynamic Memory There will be no lecture on Tuesday, Feb. 16. Prof. Thompson s office hours are canceled for Monday, Feb. 15. Prof.
More informationCMPSC 311- Introduction to Systems Programming Module: Debugging
CMPSC 311- Introduction to Systems Programming Module: Debugging Professor Patrick McDaniel Fall 2014 Debugging Often the most complicated and time-consuming part of developing a program is debugging.
More informationMemory Analysis tools
Memory Analysis tools PURIFY The Necessity TOOL Application behaviour: Crashes intermittently Uses too much memory Runs too slowly Isn t well tested Is about to ship You need something See what your code
More informationCSE 351. GDB Introduction
CSE 351 GDB Introduction Lab 2 Out either tonight or tomorrow Due April 27 th (you have ~12 days) Reading and understanding x86_64 assembly Debugging and disassembling programs Today: General debugging
More informationThe Valgrind Memory Checker. (i.e., Your best friend.)
The Valgrind Memory Checker. (i.e., Your best friend.) Dept of Computing Science University of Alberta Small modifications by Stef Nychka, Mar. 2006 5th March 2006 Attribution. Introduction Some of the
More informationPraktische Aspekte der Informatik
Praktische Aspekte der Informatik Moritz Mühlhausen Prof. Marcus Magnor Optimization valgrind, gprof, and callgrind Further Reading Warning! The following slides are meant to give you a very superficial
More informationCS/COE 0449 term 2174 Lab 5: gdb
CS/COE 0449 term 2174 Lab 5: gdb What is a debugger? A debugger is a program that helps you find logical mistakes in your programs by running them in a controlled way. Undoubtedly by this point in your
More informationUse Dynamic Analysis Tools on Linux
Use Dynamic Analysis Tools on Linux FTF-SDS-F0407 Gene Fortanely Freescale Software Engineer Catalin Udma A P R. 2 0 1 4 Software Engineer, Digital Networking TM External Use Session Introduction This
More informationKey C Topics: Tutorial Pointers, Dynamic Memory allocation, Valgrind and Makefile CS370
Key C Topics: Tutorial Pointers, Dynamic Memory allocation, Valgrind and Makefile CS370 Outline Pointers in C & and * operators Pointers with Arrays and Strings Dynamic memory allocation malloc() and free()
More informationDebugging. Marcelo Ponce SciNet HPC Consortium University of Toronto. July 15, /41 Ontario HPC Summerschool 2016 Central Edition: Toronto
Debugging Marcelo Ponce SciNet HPC Consortium University of Toronto July 15, 2016 1/41 Ontario HPC Summerschool 2016 Central Edition: Toronto Outline Debugging Basics Debugging with the command line: GDB
More informationDEBUGGING: DYNAMIC PROGRAM ANALYSIS
DEBUGGING: DYNAMIC PROGRAM ANALYSIS WS 2017/2018 Martina Seidl Institute for Formal Models and Verification System Invariants properties of a program must hold over the entire run: integrity of data no
More informationCSE 410: Systems Programming
CSE 410: Systems Programming Recitation 4: Introduction to gdb Introduction The GNU Debugger, or gdb, is a powerful symbolic debugger. Symbolic debuggers are available for many languages and platforms,
More informationICHEC. Using Valgrind. Using Valgrind :: detecting memory errors. Introduction. Program Compilation TECHNICAL REPORT
ICHEC TECHNICAL REPORT Mr. Ivan Girotto ICHEC Computational Scientist Stoney Compute Node Bull Novascale R422-E2 Using Valgrind :: detecting memory errors Valgrind is a suite of command line tools both
More informationComputer Systems and Networks
LECTURE 7: PERFORMANCE MEASUREMENT Computer Systems and Networks Dr. Pallipuram (vpallipuramkrishnamani@pacific.edu) University of the Pacific Lab Schedule Today Lab 5 Performance Measurement is open Work
More informationData and File Structures Laboratory
Tools: GDB, Valgrind Assistant Professor Machine Intelligence Unit Indian Statistical Institute, Kolkata August, 2018 1 GDB 2 Valgrind A programmer s experience Case I int x = 10, y = 25; x = x++ + y++;
More informationThe Dynamic Debugger gdb
Introduction The Dynamic Debugger gdb This handout introduces the basics of using gdb, a very powerful dynamic debugging tool. No-one always writes programs that execute perfectly every time, and while
More informationCS354 gdb Tutorial Written by Chris Feilbach
CS354 gdb Tutorial Written by Chris Feilbach Purpose This tutorial aims to show you the basics of using gdb to debug C programs. gdb is the GNU debugger, and is provided on systems that
More informationPrinceton University Computer Science 217: Introduction to Programming Systems. Data Structures
Princeton University Computer Science 217: Introduction to Programming Systems Data Structures 1 Goals of this Lecture Help you learn (or refresh your memory) about: Common data structures: linked lists
More informationIntro to Segmentation Fault Handling in Linux. By Khanh Ngo-Duy
Intro to Segmentation Fault Handling in Linux By Khanh Ngo-Duy Khanhnd@elarion.com Seminar What is Segmentation Fault (Segfault) Examples and Screenshots Tips to get Segfault information What is Segmentation
More informationProgram Design: Using the Debugger
rogram Design, February 2, 2004 1 Program Design: Using the Debugger A debugger is an alternative to putting print (printf in C) statements in your program, recompiling and trying to find out what values
More information6.S096: Introduction to C/C++
6.S096: Introduction to C/C++ Frank Li, Tom Lieber, Kyle Murray Lecture 4: Data Structures and Debugging! January 17, 2012 Today Memory Leaks and Valgrind Tool Structs and Unions Opaque Types Enum and
More informationDebugging. ICS312 Machine-Level and Systems Programming. Henri Casanova
Debugging ICS312 Machine-Level and Systems Programming Henri Casanova (henric@hawaii.edu) Debugging Even when written in high-level languages, programs have bugs Recall the thought that when moving away
More informationProgramming Studio #9 ECE 190
Programming Studio #9 ECE 190 Programming Studio #9 Concepts: Functions review 2D Arrays GDB Announcements EXAM 3 CONFLICT REQUESTS, ON COMPASS, DUE THIS MONDAY 5PM. NO EXTENSIONS, NO EXCEPTIONS. Functions
More informationDAY 4. CS3600, Northeastern University. Alan Mislove
C BOOTCAMP DAY 4 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh and the CS240 course at Purdue C Debugging 2 Debugging with gdb GDB is a debugger
More informationCSE 374 Final Exam 3/15/17. Name UW ID#
Name UW ID# There are 10 questions worth a total of 110 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationvalgrind overview: runtime memory checker and a bit more What can we do with it?
Valgrind overview: Runtime memory checker and a bit more... What can we do with it? MLUG Mar 30, 2013 The problem When do we start thinking of weird bug in a program? The problem When do we start thinking
More informationCSE 160 Discussion Section. Winter 2017 Week 3
CSE 160 Discussion Section Winter 2017 Week 3 Homework 1 - Recap & a few points ComputeMandelbrotPoint func() in smdb.cpp does the job serially. You will have to do the same task in parallel manner in
More informationUsing gdb to find the point of failure
gdb 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 g++, this is accomplished using the -g option,
More informationLecture 14 Notes. Brent Edmunds
Lecture 14 Notes Brent Edmunds October 5, 2012 Table of Contents 1 Sins of Coding 3 1.1 Accessing Undeclared Variables and Pointers...................... 3 1.2 Playing With What Isn t Yours..............................
More informationCS 270 Systems Programming. Debugging Tools. CS 270: Systems Programming. Instructor: Raphael Finkel
Debugging Tools CS 270: Systems Programming Instructor: Raphael Finkel Gdb: The Gnu debugger It runs on most computers and operating systems. It allows you to examine a running executable program. It does
More informationdbx90: Fortran debugger March 9, 2009
dbx90: Fortran debugger March 9, 2009 1 Name dbx90 a Fortran 90/95 debugger for use with the NAG Fortran compiler. 2 Usage dbx90 [option]... executable-file 3 Description dbx90 is a Fortran 90/95 debugger
More information1. Allowed you to see the value of one or more variables, or 2. Indicated where you were in the execution of a program
CS0449 GDB Lab What is a debugger? A debugger is a program that helps you find logical mistakes in your programs by running them in a controlled way. Undoubtedly by this point in your programming life,
More informationMemory Allocation in C C Programming and Software Tools. N.C. State Department of Computer Science
Memory Allocation in C C Programming and Software Tools N.C. State Department of Computer Science The Easy Way Java (JVM) automatically allocates and reclaims memory for you, e.g... Removed object is implicitly
More informationThe assignment requires solving a matrix access problem using only pointers to access the array elements, and introduces the use of struct data types.
C Programming Simple Array Processing The assignment requires solving a matrix access problem using only pointers to access the array elements, and introduces the use of struct data types. Both parts center
More informationBoth parts center on the concept of a "mesa", and make use of the following data type:
C Programming Simple Array Processing This assignment consists of two parts. The first part focuses on array read accesses and computational logic. The second part requires solving the same problem using
More informationCSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 11 gdb and Debugging (Thanks to Hal Perkins)
CSE 374 Programming Concepts & Tools Brandon Myers Winter 2015 Lecture 11 gdb and Debugging (Thanks to Hal Perkins) Hacker tool of the week (tags) Problem: I want to find the definition of a function or
More informationClass Information ANNOUCEMENTS
Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to
More informationPointers and Memory Management
Pointers and Memory Management Timo Karvi 2013 Timo Karvi () Pointers and Memory Management 2013 1 / 58 Memory and C I In most modern computers, main memory is divided into bytes, with each byte capable
More informationCS 103 Lab The Files are *In* the Computer
CS 103 Lab The Files are *In* the Computer 1 Introduction In this lab you will modify a word scramble game so that instead of using a hardcoded word list, it selects a word from a file. You will learn
More informationBinghamton University. CS-220 Spring C Debugging Basics. No relevant text
C Debugging Basics No relevant text First Computer Bug 2 The printf debugger Insert printf statements to print debug information Build/Run Modify to print new information Advantages Simple Complete Available
More informationCSci 4061 Introduction to Operating Systems. Programs in C/Unix
CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,
More informationReviewing gcc, make, gdb, and Linux Editors 1
Reviewing gcc, make, gdb, and Linux Editors 1 Colin Gordon csgordon@cs.washington.edu University of Washington CSE333 Section 1, 3/31/11 1 Lots of material borrowed from 351/303 slides Colin Gordon (University
More informationCSE 374 Final Exam 3/15/17 Sample Solution. Question 1. (8 points) Suppose we have the following two statements in a C program:
Question 1. (8 points) Suppose we have the following two statements in a C program: int *x = malloc(sizeof(int)); int *y = malloc(sizeof(int)); For each of the following expressions, write true if the
More informationmp2 Warmup Instructions (Updated 1/25/2016 by Ron Cheung for using VMs)
mp2 Warmup Instructions (Updated 1/25/2016 by Ron Cheung for using VMs) Study the lecture notes on the tools and instruction set. Then follow along with this document. Make sure everything works for you
More informationArrays and Pointers. CSC209: Software Tools and Systems Programming (Winter 2019) Furkan Alaca & Paul Vrbik. University of Toronto Mississauga
Arrays and Pointers CSC209: Software Tools and Systems Programming (Winter 2019) Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 2 Alaca & Vrbik (UTM)
More informationPerformance Measurement
ECPE 170 Jeff Shafer University of the Pacific Performance Measurement 2 Lab Schedule Ac?vi?es Today Background discussion Lab 5 Performance Measurement Wednesday Lab 5 Performance Measurement Friday Lab
More informationProject 0: Implementing a Hash Table
Project : Implementing a Hash Table CS, Big Data Systems, Spring Goal and Motivation. The goal of Project is to help you refresh basic skills at designing and implementing data structures and algorithms.
More informationCSE 124 Discussion (10/3) C/C++ Basics
CSE 124 Discussion (10/3) C/C++ Basics Topics - main() function - Compiling with gcc/makefile - Primitives - Structs/Enums - Function calls/loops - C++ Classes/stdtl - Pointers/Arrays - Memory allocation/freeing
More informationECE 3210 Laboratory 1: Develop an Assembly Program
ECE 3210 Laboratory 1: Develop an Assembly Program Spring 2018 1 Objective To become familiar with the development system s software: screen editor, assembler, linker, and debugger. After finishing this
More informationGDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial
A Walkthrough with Examples CMSC 212 - Spring 2009 Last modified March 22, 2009 What is gdb? GNU Debugger A debugger for several languages, including C and C++ It allows you to inspect what the program
More informationLab 10: Introduction to x86 Assembly
CS342 Computer Security Handout # 8 Prof. Lyn Turbak Wednesday, Nov. 07, 2012 Wellesley College Revised Nov. 09, 2012 Lab 10: Introduction to x86 Assembly Revisions: Nov. 9 The sos O3.s file on p. 10 was
More informationDebugging with gdb and valgrind
Debugging with gdb and valgrind Dr. Axel Kohlmeyer Associate Dean for Scientific Computing, CST Associate Director, Institute for Computational Science Assistant Vice President for High-Performance Computing
More informationLaboratory Assignment #4 Debugging in Eclipse CDT 1
Lab 4 (10 points) November 20, 2013 CS-2301, System Programming for Non-majors, B-term 2013 Objective Laboratory Assignment #4 Debugging in Eclipse CDT 1 Due: at 11:59 pm on the day of your lab session
More informationComputer Systems and Networks
University of the Pacific LECTURE 7: PERFORMANCE MEASUREMENT 13 TH FEB, 2018 Computer Systems and Networks Dr. Pallipuram (vpallipuramkrishnamani@pacific.edu) Lab Schedule Today Lab 5 Performance Measurement
More informationBlue Gene/Q User Workshop. Debugging
Blue Gene/Q User Workshop Debugging Topics GDB Core Files Coreprocessor 2 GNU Debugger (GDB) The GNU Debugger (GDB) The Blue Gene/Q system includes support for running GDB with applications that run on
More informationCS 553 Compiler Construction Fall 2006 Project #4 Garbage Collection Due November 27, 2005
CS 553 Compiler Construction Fall 2006 Project #4 Garbage Collection Due November 27, 2005 In this assignment you will implement garbage collection for the MiniJava compiler. The project includes the two
More informationWelcome. HRSK Practical on Debugging, Zellescher Weg 12 Willers-Bau A106 Tel
Center for Information Services and High Performance Computing (ZIH) Welcome HRSK Practical on Debugging, 03.04.2009 Zellescher Weg 12 Willers-Bau A106 Tel. +49 351-463 - 31945 Matthias Lieber (matthias.lieber@tu-dresden.de)
More informationEE355 Lab 5 - The Files Are *In* the Computer
1 Introduction In this lab you will modify a working word scramble game that selects a word from a predefined word bank to support a user-defined word bank that is read in from a file. This is a peer evaluated
More information{C} Tools of the Trade
{C} Tools of the Trade make Building Software 3 gcc is our compiler Turns C code into machine code ar is our librarian Gathers machine code files into groups called libraries But calling these over and
More informationCNIT 127: Exploit Development. Ch 2: Stack Overflows in Linux
CNIT 127: Exploit Development Ch 2: Stack Overflows in Linux Stack-based Buffer Overflows Most popular and best understood exploitation method Aleph One's "Smashing the Stack for Fun and Profit" (1996)
More informationA Capacity: 10 Usage: 4 Data:
Creating a Data Type in C Integer Set For this assignment, you will use the struct mechanism in C to implement a data type that represents sets of integers. A set can be modeled using the C struct: struct
More informationCSE 333 Midterm Exam Sample Solution 7/28/14
Question 1. (20 points) C programming. For this question implement a C function contains that returns 1 (true) if a given C string appears as a substring of another C string starting at a given position.
More information18-600: Recitation #3
18-600: Recitation #3 Bomb Lab & GDB Overview September 12th, 2017 1 Today X86-64 Overview Bomb Lab Introduction GDB Tutorial 2 3 x86-64: Register Conventions Arguments passed in registers: %rdi, %rsi,
More informationCSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.
CSCI0330 Intro Computer Systems Doeppner Lab 02 - Tools Lab Due: Sunday, September 23, 2018 at 6:00 PM 1 Introduction 0 2 Assignment 0 3 gdb 1 3.1 Setting a Breakpoint 2 3.2 Setting a Watchpoint on Local
More informationCSCI-1200 Data Structures Fall 2015 Lecture 6 Pointers & Dynamic Memory
CSCI-1200 Data Structures Fall 2015 Lecture 6 Pointers & Dynamic Memory Announcements: Test 1 Information Test 1 will be held Monday, September 21st, 2015 from 6-:50pm. Students have been randomly assigned
More informationAnalysis of MS Multiple Excel Vulnerabilities
Analysis of MS-07-036 Multiple Excel Vulnerabilities I. Introduction This research was conducted using the Office 2003 Excel Viewer application and the corresponding security patch for MS-07-036 - Vulnerabilities
More informationEE 355 Lab 3 - Algorithms & Control Structures
1 Introduction In this lab you will gain experience writing C/C++ programs that utilize loops and conditional structures. This assignment should be performed INDIVIDUALLY. This is a peer evaluated lab
More informationTI2725-C, C programming lab, course
Valgrind tutorial Valgrind is a tool which can find memory leaks in your programs, such as buffer overflows and bad memory management. This document will show per example how Valgrind responds to buggy
More informationPointers. Héctor Menéndez 1. November 28, AIDA Research Group Computer Science Department Universidad Autónoma de Madrid.
Pointers Héctor Menéndez 1 AIDA Research Group Computer Science Department Universidad Autónoma de Madrid November 28, 2013 1 based on the original slides of the subject Index 1 Dynamic Memory 2 Arrays
More informationDebugging. John Lockman Texas Advanced Computing Center
Debugging John Lockman Texas Advanced Computing Center Debugging Outline GDB Basic use Attaching to a running job DDT Identify MPI problems using Message Queues Catch memory errors PTP For the extremely
More informationChapter - 17 Debugging and Optimization. Practical C++ Programming Copyright 2003 O'Reilly and Associates Page 1
Chapter - 17 Debugging and Optimization Practical C++ Programming Copyright 2003 O'Reilly and Associates Page 1 Debugging Techniques Divide and conquer Debug only code Debug Command Line Switch Note: Use
More informationCSE 565 Computer Security Fall 2018
CSE 565 Computer Security Fall 2018 Lecture 14: Software Security Department of Computer Science and Engineering University at Buffalo 1 Software Security Exploiting software vulnerabilities is paramount
More informationCSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 11 gdb and Debugging 1 Administrivia HW4 out now, due next Thursday, Oct. 26, 11 pm: C code and libraries. Some tools: gdb (debugger)
More informationCOSC 6374 Parallel Computation. Debugging MPI applications. Edgar Gabriel. Spring 2008
COSC 6374 Parallel Computation Debugging MPI applications Spring 2008 How to use a cluster A cluster usually consists of a front-end node and compute nodes Name of the front-end node: shark.cs.uh.edu You
More informationCS 11 C track: lecture 6
CS 11 C track: lecture 6 Last week: pointer arithmetic This week: The gdb program struct typedef linked lists gdb for debugging (1) gdb: the Gnu DeBugger http://courses.cms.caltech.edu/cs11/material /c/mike/misc/gdb.html
More informationDebugging and Profiling
Debugging and Profiling Dr. Axel Kohlmeyer Senior Scientific Computing Expert Information and Telecommunication Section The Abdus Salam International Centre for Theoretical Physics http://sites.google.com/site/akohlmey/
More informationBasic functions of a debugger
UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS61B Spring 1998 P. N. Hilfinger Simple Use of GDB A debugger is a program that runs other
More informationProject 0: Implementing a Hash Table
CS: DATA SYSTEMS Project : Implementing a Hash Table CS, Data Systems, Fall Goal and Motivation. The goal of Project is to help you develop (or refresh) basic skills at designing and implementing data
More informationCptS 360 (System Programming) Unit 4: Debugging
CptS 360 (System Programming) Unit 4: Debugging Bob Lewis School of Engineering and Applied Sciences Washington State University Spring, 2018 Motivation You re probably going to spend most of your code
More informationCS61 Lecture II: Data Representation! with Ruth Fong, Stephen Turban and Evan Gastman! Abstract Machines vs. Real Machines!
CS61 Lecture II: Data Representation with Ruth Fong, Stephen Turban and Evan Gastman Abstract Machines vs. Real Machines Abstract machine refers to the meaning of a program in a high level language (i.e.
More informationA Tutorial for ECE 175
Debugging in Microsoft Visual Studio 2010 A Tutorial for ECE 175 1. Introduction Debugging refers to the process of discovering defects (bugs) in software and correcting them. This process is invoked when
More informationProjet 0 - Correc,on. Structures de données et algorithmes
Projet 0 - Correc,on Structures de données et algorithmes Code de base #include #define uint unsigned int #define N 101 int f(int m, int M, uint* s) *s ^= (uint)(*s
More informationProgramming in C S c o t t S c h r e m m e r
Programming in C S c o t t S c h r e m m e r Outline Introduction Data Types and structures Pointers, arrays and dynamic memory allocation Functions and prototypes input/output comparisons compiling/makefiles/debugging
More informationUnited States Naval Academy Electrical and Computer Engineering Department EC312-6 Week Midterm Spring 2016
United States Naval Academy Electrical and Computer Engineering Department EC312-6 Week Midterm Spring 2016 1. Do a page check: you should have 7 pages including this cover sheet. 2. You have 50 minutes
More informationGDB Linux GNU Linux Distribution. gdb gcc g++ -g gdb EB_01.cpp
B Linux GDB GDB Linux GNU GPL Linux Distribution Linux E-B.1 gcc g++ -g EB_01.cpp EB_01.cpp E/EB/EB_01.cpp 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 /**** :EB_01.cpp : *****/ #include
More informationPerformance Metrics (I)
COSC 6374 Parallel Computation Parallel Metrics and Debugging MPI application Edgar Gabriel Fall 2014 Performance Metrics (I) Strong Scaling: how much faster does a problem run on p processors compared
More informationJackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 5
Jackson State University Department of Computer Science CSC 439-01/539-02 Advanced Information Security Spring 2013 Lab Project # 5 Use of GNU Debugger (GDB) for Reverse Engineering of C Programs in a
More informationDevelopment in code_aster Debugging a code_aster execution
Development in code_aster Debugging a code_aster execution Code_Aster, Salome-Meca course material GNU FDL licence (http://www.gnu.org/copyleft/fdl.html) How to debug a code_aster execution? Requirements
More informationCOSC 6374 Parallel Computation. Analytical Modeling of Parallel Programs (I) Edgar Gabriel Fall Execution Time
COSC 6374 Parallel Computation Analytical Modeling of Parallel Programs (I) Edgar Gabriel Fall 2015 Execution Time Serial runtime T s : time elapsed between beginning and the end of the execution of a
More informationLab6 GDB debugging. Conventions. Department of Computer Science and Information Engineering National Taiwan University
Lab6 GDB debugging 1 / 15 Learn how to perform source-level debugging with GDB. 2 / 15 Host Machine OS: Windows Target Machine Raspberry Pi (2 or 3) Build Machine A computer with a SD card slot OS: Ubuntu
More information