1 / 14

T UTORIAL L ESSON Debugging

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

lauren
Download Presentation

T UTORIAL L ESSON Debugging

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Institute of Parallel and Distributed Systems (iPads) Shanghai Jiao Tong University Rong Chen rongchen@sjtu.edu.cn TUTORIAL LESSONDebugging

  2. OUTLINE Pre-requisite Debugging

  3. Pre-requisite Debugging

  4. GCC Tools • Install GCC Tools • apt-get install build-essential Institute of Parallel and Distributed Systems (iPads), SJTU

  5. Pre-requisite Debugging • bug & warning debugging examples

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

  7. Pre-requisite Debugging bug & warning • debugging examples

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

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

  10. Pre-requisite Debugging Bug & Warning Debugging • Examples

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

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

  13. 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; • }

  14. Thanks Institute of Parallel and Distributed Systems (iPads), SJTU

More Related