140 likes | 277 Views
Institute of Parallel and Distributed Systems (iPads) Shanghai Jiao Tong University Rong Chen rongchen @ sjtu.edu.cn. T UTORIAL L ESSON Debugging. OUTLINE. Pre-requisite Debugging. Pre-requisite Debugging . GCC Tools. Install GCC Tools apt-get install build-essential. Pre-requisite
E N D
Institute of Parallel and Distributed Systems (iPads) Shanghai Jiao Tong University Rong Chen rongchen@sjtu.edu.cn TUTORIAL LESSONDebugging
OUTLINE Pre-requisite Debugging
Pre-requisite Debugging
GCC Tools • Install GCC Tools • apt-get install build-essential Institute of Parallel and Distributed Systems (iPads), SJTU
Pre-requisite Debugging • bug & warning debugging examples
Bug & Warning • Bug • Grammar • int a b; • Semantics • int a[2]; a[2]=2; • Warning • int a; b=a; int a, b; a[0]=2; int a=0; b=a; Institute of Parallel and Distributed Systems (iPads), SJTU
Pre-requisite Debugging bug & warning • debugging examples
Debugging • Debugging = Find + Fix Core Competency ! • Compiling (HINTS: don’t miss warning) • gcc–Wall –o test test.c • Debugging (HINTS: code review first) • + printf • gdbtest Institute of Parallel and Distributed Systems (iPads), SJTU
Debugging • Debugging = Find + Fix + Experience • example#1: “Segmentation fault” • example#2: test.c:6: error: expected ‘,’ or ‘;’ before ‘struct’ test.c:9: warning: data definition has no type or storage class test.c:9: warning: type defaults to ‘int’ in ... test.c:16: warning: (near initialization for ‘s’) test.c:16: error: storage size of ‘s’ isn’t known test.c:21: error: request for member ‘a’ in something not a structure or union test.c:16: warning: unused variable ‘s’ Institute of Parallel and Distributed Systems (iPads), SJTU
Pre-requisite Debugging Bug & Warning Debugging • Examples
Example#1 • test.c: In function ‘main’: • test.c:18: warning: implicit declaration of function ‘malloc’ • Example#2 • test.c:6: error: expected ‘,’ or ‘;’ before ‘struct’ • Example#3 • test.c:18: error: ‘j’ undeclared (first use in this function) • Example#4 • test.c:18: error: expected ‘;’ before ‘)’ token • test.c:18: error: expected statement before ‘)’ token • Example#5 • test.c:27: error: conflicting types for ‘test’ • test.c:4: note: previous declaration of ‘test’ was here
Example#1 • test.c:22: warning: ‘x’ is used uninitialized in this function • Example#2 • test.c:16: warning: unused variable ‘s’ • Example#3 • test.c:19: warning: too few arguments for format • test.c:22: warning: ‘x’ is used uninitialized in this function • Example#4 • test.c: In function ‘main’: • test.c:24: warning: control reaches end of non-void function • Example#5 • test.c: In function ‘test’: • test.c:30: warning: assignment makes pointer from integer without a cast
It’s a joke ^o^ • It’s a “Hello world!” • intmain(void) { • printf(“hello world!\n”); • return 0; • } • How about this code? • int main(void) { • printf(“hello world!\n”); • http://ipads.se.sjtu.edu.cn/courses/ics • return 0; • }
Thanks Institute of Parallel and Distributed Systems (iPads), SJTU