Presentation is loading. Please wait.

Presentation is loading. Please wait.

Some Basics && GDB overview Ram Sheshadri –

Similar presentations


Presentation on theme: "Some Basics && GDB overview Ram Sheshadri –"— Presentation transcript:

1 Some Basics && GDB overview Ram Sheshadri Email – ramanuja@buffalo.edu

2 CSE 489/589: Modern Networking Concepts Instructor: Dr. Chunming Qiao – Office: 312 Davis Hall – Email: qiao[at] computer.org – Office Hours  Tuesday: 3:30 - 5:00 PM  Thursday: 3.30 - 5:00 PM TA: Ram Sheshadri Couse website: http://www.cse.buffalo.edu/faculty/qiao/cse489/index.html 2

3 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.

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

5 Outline Part1: Some Basics Part2: GDB Overview 5

6 Login to CSE Servers ssh @timberlake.cse.buffalo.edu 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.

7 CSE servers you will use Timberlake Highgate Euston Embankment Underground

8 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

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

10 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

11 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

12 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

13 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

14 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

15 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; }

16 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; }

17 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.

18 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.

19 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

20 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.


Download ppt "Some Basics && GDB overview Ram Sheshadri –"

Similar presentations


Ads by Google