Some Basics && GDB overview Ram Sheshadri –

Slides:



Advertisements
Similar presentations
Recitation By yzhuang, sseshadr. Agenda Debugging practices – GDB – Valgrind – Strace Errors and Wrappers – System call return values and wrappers – Uninitialization.
Advertisements

Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Introduction to the Omega Server CSE Overview Intro to Omega Basic Unix Command Files Directories Printing C and C++ compilers GNU Debugger.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Utilizing the GDB debugger to analyze programs Background and application.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Pointer, malloc and realloc 1. Name entered was 6 char, not enough space to put null terminator 2 Array of char.
Spring 2005, Gülcihan Özdemir Dağ Lecture 12, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 12 Outline 12.1Introduction.
DEBUGGING IN THE REAL WORLD : Recitation 4.
Informática II Prof. Dr. Gustavo Patiño MJ
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
1 1 Lecture 4 Structure – Array, Records and Alignment Memory- How to allocate memory to speed up operation Structure – Array, Records and Alignment Memory-
Memory Arrangement Memory is arrange in a sequence of addressable units (usually bytes) –sizeof( ) return the number of units it takes to store a type.
Declaring Arrays Declare an array of 10 elements: int nums[10]; Best practice: #define SIZE 10 int nums[SIZE]; // cannot be int[SIZE] nums; C99: int nums[someVariable]
Unix Process Environment. main Function A C program starts execution with a function called main. The prototype for the main function is: int main (int.
CSE 451 Section 4 Project 2 Design Considerations.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
Arrays, Strings, and Pointers CSE 2451 Rong Shi. Arrays Store many values of the same type in adjacent memory locations Declaration [ ] Examples: – int.
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Debugger Presented by 李明璋 2012/05/08. The Definition of Bug –Part of the code which would result in an error, fault or malfunctioning of the program.
Pointers CSE 2451 Rong Shi.
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.
Homework Reading Programming Assignments
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
CS50 SECTION: WEEK 4 Kenny Yu. Announcements  Problem Set 4 Walkthrough online  Problem Set 2 Feedback has been sent out  CORRECTION: Expect all future.
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.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
1 C - Memory Simple Types Arrays Pointers Pointer to Pointer Multi-dimensional Arrays Dynamic Memory Allocation.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
Dynamic Memory Allocation. Domain A subset of the total domain name space. A domain represents a level of the hierarchy in the Domain Name Space, and.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
19&20-2 Know how to declare pointer variables. Understand the & (address) and *(indirection) operators. Dynamic Memory Allocation Related Chapter: ABC.
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.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
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.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
CSE 333 – SECTION 1 C, Introduction to and Working with.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
1 Chapter 7 Pointers and C-Strings. 2 Objectives  To describe what a pointer is (§7.1).  To learn how to declare a pointer and assign a value to it.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
Hank Childs, University of Oregon April 6 th, 2015 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.
Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.
CSCI 4061 Recitation 2 1.
DEBUG.
Memory allocation & parameter passing
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Lecture 8 String 1. Concept of strings String and pointers
Checking Memory Management
gdb gdb is the GNU debugger on our CS machines.
Arrays in C.
Recitation: C Review TA’s 19 Feb 2018.
Pointers, Dynamic Data, and Reference Types
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
Homework Reading Programming Assignments Finish K&R Chapter 1
Pass-by-Pointer Pointers are also used in C to enable a function to modify a variable held by the caller: void findExtrema(const int *pA, int Sz, int *pMin,
Debugging.
Dynamic Memory – A Review
Pointers, Dynamic Data, and Reference Types
Corresponds with Chapter 5
Presentation transcript:

Some Basics && GDB overview Ram Sheshadri –

CSE 489/589: Modern Networking Concepts Instructor: Dr. Chunming Qiao – Office: 312 Davis Hall – qiao[at] computer.org – Office Hours  Tuesday: 3:30 - 5:00 PM  Thursday: :00 PM TA: Ram Sheshadri Couse website: 2

CSE489 – Recitation Hours Rec1 - Monday –> 6 – 6.50PM (Cooke127B) Rec2 – Wednesday -> 8 – 8.50 AM (Norton 216) I will be teaching the same material in both recitations.

My Office Hours Ram Sheshadri Office: 302 Davis Hall/300 Davis Hall Student Lounge Office Hours: Friday 12:00 - 1:00 PM ramanuja [at] buffalo.edu 4

Outline Part1: Some Basics Part2: GDB Overview 5

Login to CSE Servers Some other useful commands: A) Copy locally – cp B) Copy across servers – scp Basic questions: Can we use putty on PC – Yes Can we login using Mac – Yes Can we write our code in local machines – Don’t take chances – use CSE servers.

CSE servers you will use Timberlake Highgate Euston Embankment Underground

How to compile? For C programs - use gcc - e.g., gcc hello_world.c –o hello-world For C++ programs - use g++ - e.g., g++ hello_world.cpp –o hello-world For a 32 bit machine – Use “-m 32” option - e.g., gcc –m32 hello_world.c –o hello-world

Endianess ● Concerned with storing multi-byte data types in memory

C Strings ● No actual data-type named string ● Sequence of characters placed next to each other constitutes a string ● Null termination is needed for almost all functions dealing with strings

C Strings ● Two primary ways to work with strings o String Literals o Char arrays ● String Literals ARE null terminated ● Char arrays are automatically NOT null terminated ● Char arrays equated to string literals ARE null terminated

String literals ● Generally stored in read-only area ● Not a good idea to modify them ● Avoid passing them to functions char *string = “CSE489”; //null terminated string[3] = ‘5’; //Undefined behavior

Char arrays ● Sequence of char literals ● It is OK to modify them ● It is OK to pass them to functions char a[7]; //NOT null terminated char a[7] = “CSE489”; //null terminated char a[ ] = “CSE489”; //null terminated char a[6] = “CSE489”; //NOT null terminated

Functions dealing with strings ● Some return a null terminated string, some DO NOT (e.g. fgets) ● Always consult man page before using them ● Same goes for their arguments

Pointers and Function Arguments int x = 2, y = 1; swap_x_y( x, y ); // wrong version of swap function // void swap_x_y (int a, int b) { int temp; temp = a; a = b; b = temp; }

Pointers and Function Arguments int x = 2, y = 1; swap_x_y( &x, &y ); // Correct version of swap function // void swap_x_y (int &a, int &b) { int temp; temp = *a; *a = *b; *b = temp; }

Malloc() & Memcpy() Malloc() – Allocate requested memory Syntax - void *malloc(size_t size) e.g., - char *str = (char *) malloc(15); Memcpy() – Copies ‘n bytes’ from one memory to another. Syntax - void *memcpy(void *str1, const void *str2, size_t n) str1 -- This is pointer to the destination array str2 -- This is pointer to the source n -- This is the number of bytes to be copied.

GDB What is GDB? It is a debugging tool developed by GNU Why to use GDB? Allows you to stop the program in the middle of execution. Check the status of the program – internal variables. Find the exact location where your program is crashing.

GDB ● Supports multiple languages including C/C++ ● Comes handy with seg. Faults ● To use gdb o compile program with the -g flag ● To run with gdb o gdb

A few useful GDB commands CommandDescription helpList gdb command topics. break funtion-name break line-number Suspend program at specified function of line number. Clear clear function clear line-number Delete breakpoints as identified by command option. Delete all breakpoints in function Delete breakpoints at a given line delete breakpoint-number delete range Delete the breakpoints, watchpoints, or catchpoints of the breakpoint ranges specified as arguments. step s Step to next line of code. Will step into a function. next n Execute next line of code. Will not enter functions. run r run command-line-arguments run outfile Start program execution from the beginning of the program. The command break main will get you started. Also allows basic I/O redirection. continue c Continue execution to next break point. quit q Exit GDB debugger.