CS3210: Tutorial Session 2. Kyuhong Park-- edited by Kyle Harrigan

Similar documents
CS 270 Systems Programming. Debugging Tools. CS 270: Systems Programming. Instructor: Raphael Finkel

Lecture 2. Xiaoguang Wang. January 16th, 2014 STAT 598W. (STAT 598W) Lecture 2 1 / 41

Programming Studio #9 ECE 190

Today s presentation. Git gdb Project 1

Mechatronics and Microcontrollers. Szilárd Aradi PhD Refresh of C

GDB cheatsheet - page 1

GDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32

A flow chart is a graphical or symbolic representation of a process.

CSE 351 Section 4 GDB and x86-64 Assembly Hi there! Welcome back to section, we re happy that you re here

Lecture 3: C Programm

Debug for GDB Users. Action Description Debug GDB $debug <program> <args> >create <program> <args>

Pointers. 10/5/07 Pointers 1

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

CS113: Lecture 5. Topics: Pointers. Pointers and Activation Records

CS240: Programming in C

SU 2017 May 18/23 LAB 3 Bitwise operations, Program structures, Functions (pass-by-value), local vs. global variables. Debuggers

Source level debugging. October 18, 2016

CS240: Programming in C

A Fast Review of C Essentials Part I

CS Programming In C

Problem Set 1: Unix Commands 1

Pointers (1A) Young Won Lim 3/5/18

18-600: Recitation #3

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21

SISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

Learning C Language. For BEGINNERS. Remember! Practice will make you perfect!!! :D. The 6 th week / May 24 th, Su-Jin Oh

Pointers (1A) Young Won Lim 1/9/18

Pointers (1A) Young Won Lim 1/5/18

Computer Organization & Systems Exam I Example Questions

C - Basics, Bitwise Operator. Zhaoguo Wang

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Know your tools. For the GNU/Linux game developer GDB is the BFG. emacs. "a bad workman blames his tools", Cambridge Idioms Dictionary

Lecture 03 Bits, Bytes and Data Types

Page 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10?

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

Using gdb to find the point of failure

CSE 351. GDB Introduction

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

SISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

BLM2031 Structured Programming. Zeyneb KURT

Class Information ANNOUCEMENTS

Programming Tools. Venkatanatha Sarma Y. Lecture delivered by: Assistant Professor MSRSAS-Bangalore

SISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

Lecture 13 Bit Operations

Review Topics. Midterm Exam Review Slides

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

Lecture 2: C Programm

Computer Programming Lecture 12 Pointers

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 5

A Shotgun Introduction to C

CS 107 Lecture 2: Bits and Bytes (continued)

Lab6 GDB debugging. Conventions. Department of Computer Science and Information Engineering National Taiwan University

Lecture 02 C FUNDAMENTALS

Section 1: Tools. Kaifei Chen, Luca Zuccarini. January 23, Make Motivation How... 2

GDB QUICK REFERENCE GDB Version 4

CS201 Lecture 2 GDB, The C Library

Lab1 tutorial CS

CS 11 C track: lecture 8

CS 241 Data Organization Binary

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...

1. Allowed you to see the value of one or more variables, or 2. Indicated where you were in the execution of a program

Princeton University COS 217: Introduction to Programming Systems GDB Tutorial and Reference for x86-64 Assembly Language

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 11 gdb and Debugging (Thanks to Hal Perkins)

Programming in C - Part 2

Contents. Preface. Introduction. Introduction to C Programming

C Programming Review CSC 4320/6320

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

Beginning C Programming for Engineers

Incoming Exam. CS 201 Introduction to Pointers. What is a Pointer? Pointers and Addresses. High Speed Memory (RAM) Size of Variable Types.

PRINCIPLES OF OPERATING SYSTEMS

Come and join us at WebLyceum

[0569] p 0318 garbage

Simple C Program. Assembly Ouput. Using GCC to produce Assembly. Assembly produced by GCC is easy to recognize:

Binary Representation. Decimal Representation. Hexadecimal Representation. Binary to Hexadecimal

Decimal Representation

Do not start the test until instructed to do so!

GDB Tutorial. Young W. Lim Thr. Young W. Lim GDB Tutorial Thr 1 / 24

Work relative to other classes

Software Development With Emacs: The Edit-Compile-Debug Cycle

COMP s1 Lecture 1

LAB A Translating Data to Binary

CS 314 Principles of Programming Languages. Lecture 9

THREADS: (abstract CPUs)

Tutorial 5. Overflow. Data Types. Structures. Call stack. Stack frames. Debugging Tips. CS 136 Winter 2019 Tutorial 5 1

Recitation: Bomb Lab. September 17 th 2018

Processes. Johan Montelius KTH

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

CSC 211 Intermediate Programming. Pointers

CMPT 300. Operating Systems. Brief Intro to UNIX and C

Introduction to Programming (Java) 2/12

Bits and Bytes. Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions

JAVA OPERATORS GENERAL

A process. the stack

Transcription:

1 CS3210: Tutorial Session 2 Kyuhong Park-- edited by Kyle Harrigan

2 Overview Goal: Understand C and GDB Part1: C Programming Part2: GDB Part3: In-class Exercises

3 Revised Tutorial Format Recommended by Dr. Andersen to modify tutorial format after feedback from first session Will attempt this modified format 30 minutes lecture 10-20 minutes demo / walkthrough 30 minutes group / individual exercises

4 Part 1: C Programming Review Part 1: C Programming Review Bitwise Operations Pointers Review of the prep quiz

5 Features of C Few keywords Structure, unions Macro preprocessor Pointers - memory, arrays External standard library - I/O, etc.. Lacks (directly) Exceptions, garbage-collection, OOP, polymorphism

6 Bitwise Operators in C & --- bitwise AND --- bitwise inclusive OR ^ --- bitwise exclusive OR << --- left shift >> --- right shift ~ --- one's complement(unary)

Bitwise XOR 7

Bitwise shift (left and right) 8

9 Bitwise Operations - Example unsigned getbits(unsigned x, int p, int n) { return (x >> (p+1-n)) & ~(~0 << n); } Let's say x=3210, p=10, n=4 p+1-n 10+1-4 = 7 1100 1000 1010 >> 7 0000 0001 1001 2 ~(~0 << 4) ~(1111 1111 1111) 0000 0000 1111 0000 0001 1001 & 0000 0000 1111 0000 0000 1001 9

10 Pointers Pointers are variables that contain memory addresses as their values A variable name directly references a value A pointer indirectly references a value Referencing a value through a pointer is called indirection A pointer variable must be declared before it can be used

11 Concept of address and pointers Memory can be conceptualized as a linear set of data locations Variables reference the contents of these locations Pointers have a value of the address of a given location

12 How to read a declaration Definition Code 1. p is a variable const int* p; 2. p is a pointer variable const int* p; 3. p is a pointer variable to an integer const int* p; 4. p is a pointer variable to a constant integer const int* p;

13 Example (1) int main(){ int n1 = 5; int n2 = 10; swap(&n1, &n2); return 0; } What should swap() look like?

14 Example (1) - Answer and Result int swap(int* pnum1, int* pnum2){ int tmp; tmp = *pnum1; *pnum1 = *pnum2; *pnum2 = tmp; }

15 Function pointer declaration // Example int (*f1)(double); // passed a double, returns an int void (*f2)(char*); // passed a pointer to char and returns void

16 Example (2) int add(int num1, int num2){ return num1 + num2; } int subtract(int num1, int num2){ return num1 num2; } int (*fptroperation)(int,int); int compute(fptroperation op, int num1, int num2){ return op(num1, num2); } //usage printf( %d\n, compute(add,5,6); printf( %d\n, compute(sub,5,6);

17 Part 2: GDB Introduction of GDB How GDB works How GDB interact with QEMU

18 Introduction to GDB GDB is the GNU program debugger GDB allows you set a breakpoint in your program at any given point examine the program state when stopped change things in your program

19 GDB structure User interface Several actual interfaces, plus supporting code Symbol side Object file readers, debugging info interpreters, symbol table management, etc. Target side Execution control, stack frame analysis, and physical target manipulation

20 GDB debugger Kernel support Debugger support has to be part of the OS kernel Kernel able to read and write memory that belongs to each and every process Debugger-debuggee synchronization Signal Hardware Breakpoint -Built-in debugging feature Software Breakpoint

GDB interaction with QEMU 21

22 Example: make qemu-gdb Open cs3210-lab/lab/makefile.gdbinit target remote localhost:26000

23 Basic commands of GDB run / r / r arg1 arg2 arg3 Start program execution from the beginning of the program continue / c Continue execution to next break point Kill Stop program execution quit / q Exit gdb

24 GDB: break execution break function-name/line-#/classname::functionname break filename:function/filename:line-# break *address break line-# if condition clear function/line-# delete br-# enable br-# disable br-#

25 GDB: line and instruction execution step / s / si / s # / si # Step into next / n / ni / n # / ni # Do not enter functions (step over) Until / until line-# Continue processing until you reach a specified line number Where Show current line number and which function you are in Disassemble 0x[start] 0x[end]

26 GDB: examine variables x 0xaddress x/nfu 0xaddress print variable-name p/x, p/d, p/u, p/o Hex, signed integer, unsigned integer, octal p/t variable, x/b address Binary p/a, x/w Hex address, 4 bytes of memory pointed by address

27 Part3: In-class exercises git clone git://tc.gtisc.gatech.edu/cs3210-pub or git pull in your cs3210-pub directory cd cs3210-pub/tut/tut2 Open README and follow all the steps Have a fun :-)