DOC PREVIEW
CMU 15441 Computer Networking - Lecture

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Systems Dev. Tutorial IV:Debugging: Tips and Tools15-441 RecitationWednesday, Sept 27th, 2006OverviewWhat is debugging? Strategies to live (or at least code) by.Tools of the trade gdb smart logging electric fence ethereal/tcpdump What is debugging?You tell me! Everybody writes codes with bugs.What debugging have you needed to do already on the IRC project? Things to think about:- What caused the bug?- How did you end up finding it?- How could you have avoided the bug in the first-place? Debugging PhilosophyGuiding Steps:1) Think about why you believe the program should produce the output you expected.2) Make assertions until you understand how your view differs from the computer’s.Coder: code will produce output X …Computer:code will produce Z….Requirements for DebuggingWHAT program behavior to look for?Sometimes this is nearly free.... (e.g., compiler error, or segfault)Sometimes it is the hardest part.... (e.g., logic bugs, race conditions)How to easily expose information to test hypothesis?gdb, logging, strace, ethereal....Strategies to Live By...Debugging is part art, part science.You’ll improve with experience….… but we can try to give you a jump-start!2Strategy #1:Debug with PurposeDon't just change code and “hope” you'll fix the problem!Instead, make the bug reproducible, then use methodical “Hypothesis Testing”:While(bug) {Ask, what is the simplest input that produces the bug?Identify assumptions that you made about program operation that could be false.Ask yourself “How does the outcome of this test/change guide me toward finding the problem?”Use pen & paper to stay organized!}Strategy #2:Explain it to Someone ElseOften explaining the bug to “someone” unfamiliar with the program forces you to look at the problem in a different way. Before you actually email the TA’s:Write an email to convince them that you have eliminated all possible explanations....Strategy #3:Focus on Recent ChangesIf you find a NEW bug, ask: what code did I change recently?This favors:- writing and testing code incrementally-using 'svn diff' to see recent changes -regression testing (making sure new changes don't break old code). strategy #4:When in doubt, dump stateIn complex programs, reasoning about wherethe bug is can be hard, and stepping through ina debugger time-consuming. Sometimes its easier to just “dump state” and scan through for what seems “odd” to zero in on the problem. Example: Dumping all packets using tcpdump.Strategy #5: Get some distance...Sometimes, you can be TOO CLOSE to the code to see the problem. Go for a run, take a shower, whatever relaxes you but let's your mind continue to spin in the background. strategy #6:Let others work for you!Sometimes, error detecting tools make certain bugs easy to find. We just have to use them.Electric Fence or Valgrind: runtime tools to detect memory errorsExtra GCC flags to statically catch errors:-Wall, -Wextra, -Wshadow, -Wunreachable-code3Strategy #7:Think AheadBugs often represent your misunderstanding of a software interface.Once you've fixed a bug:1) Smile and do a little victory dance....2) Think about if the bug you fixed might manifest itself elsewhere in your code (a quick grep can help).3) Think about how to avoid this bug in the future (maybe coding 36 straight hours before the deadline isn't the most efficient approach....)Tools of the TradeDifferent bugs require different tools:1) Program crashes with segfault -> gdb2) Hard to reproduce or highly complex bugs-> logging & analysis3) Program hangs waiting for network traffic -> tcpdump / etherealGDB: Learn to Love itRun a program, see where it crashes, or stop it in the middle of running to examine program state. Two ways to run:gdb binary(to run binary inside of gdb)gdb binary core-file(to debug crashed program)GDB CommandsControlling Executionrun <cmd-line args>break <func>step nextcontrol-c Getting Infobacktraceprint <expr>info localslistup/downGDB Tricks & TipsSee handout for detailed explanations, and abbreviationsRemember: always compile with -g, and no optimizations. If your not getting core files, type: ‘unlimit coredumpsize’ You can use GDB in emacs! (see slides at end)Smart LoggingUse a debug macro that you can easily turn off to suppress output just by changing one line.(example posted online) Often smart to create generic log functions like dumpIRCMessage() or dumpRoutingPacket()A tool like 'strace' or 'ktrace' may be able to log easily read information for free!4Electric FenceAdds run-time checks to your program to find errors related to malloc.e.g.: writing out of bounds, use after free...just compile your programs using -lefence Alternative: Valgrind finds more memory errors, but is VERY slow. tcpdump & etherealHelps you understand what is happening “below” your networking code.Benefits Often will automatically parse well known protocols for you! (like, say... IRC) Accept filters to ignore unimportant packetsDownsides Need root accessThat’s It!Questions? Feedback from Checkpoint 2?Using GDB in EmacsThe commands/keystrokes to make it happen:1. Compile with -g and *NO* -O2 or -O32. build with a "make"3. emacs sircd.c (or any other source file)4. CTRL+x and then '3' (open a right frame)5. CTRL+x and then 'o' (switch cursor to right frame)6. ESC+x and then "gdb" and hit enter7. Type in the name of your binary *only*, like "sircd" and hit enter8. Set any break points you want, then type "run params ...", forexample "run 1 node1.conf" and hit enter9. Use GDB with your code!! (next, step, print, display...)GDB in EmacsNote the arrow in the left source file window shows the line being


View Full Document

CMU 15441 Computer Networking - Lecture

Documents in this Course
Lecture

Lecture

14 pages

Lecture

Lecture

19 pages

Lecture

Lecture

14 pages

Lecture

Lecture

78 pages

Lecture

Lecture

35 pages

Lecture

Lecture

4 pages

Lecture

Lecture

29 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

38 pages

Lecture

Lecture

40 pages

Lecture

Lecture

13 pages

Lecture

Lecture

47 pages

Lecture

Lecture

49 pages

Lecture

Lecture

7 pages

Lecture

Lecture

18 pages

Lecture

Lecture

15 pages

Lecture

Lecture

74 pages

Lecture

Lecture

35 pages

Lecture

Lecture

17 pages

lecture

lecture

13 pages

Lecture

Lecture

21 pages

Lecture

Lecture

14 pages

Lecture

Lecture

53 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

20 pages

Lecture

Lecture

39 pages

Lecture

Lecture

10 pages

Lecture

Lecture

40 pages

Lecture

Lecture

25 pages

lecture

lecture

11 pages

lecture

lecture

7 pages

Lecture

Lecture

10 pages

lecture

lecture

46 pages

lecture

lecture

7 pages

Lecture

Lecture

8 pages

lecture

lecture

55 pages

lecture

lecture

45 pages

lecture

lecture

47 pages

lecture

lecture

39 pages

lecture

lecture

33 pages

lecture

lecture

38 pages

lecture

lecture

9 pages

midterm

midterm

16 pages

Lecture

Lecture

39 pages

Lecture

Lecture

14 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

41 pages

Lecture

Lecture

38 pages

Lecture

Lecture

9 pages

Lab

Lab

3 pages

Lecture

Lecture

53 pages

Lecture

Lecture

51 pages

Lecture

Lecture

38 pages

Lecture

Lecture

42 pages

Lecture

Lecture

49 pages

Lecture

Lecture

63 pages

Lecture

Lecture

7 pages

Lecture

Lecture

51 pages

Lecture

Lecture

35 pages

Lecture

Lecture

29 pages

Lecture

Lecture

65 pages

Lecture

Lecture

47 pages

Lecture

Lecture

41 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

35 pages

Lecture

Lecture

15 pages

Lecture

Lecture

52 pages

Lecture

Lecture

16 pages

Lecture

Lecture

4 pages

lecture

lecture

27 pages

lecture04

lecture04

46 pages

Lecture

Lecture

46 pages

Lecture

Lecture

13 pages

lecture

lecture

41 pages

lecture

lecture

38 pages

Lecture

Lecture

40 pages

Lecture

Lecture

25 pages

Lecture

Lecture

38 pages

lecture

lecture

11 pages

Lecture

Lecture

42 pages

Lecture

Lecture

12 pages

Lecture

Lecture

36 pages

Lecture

Lecture

46 pages

Lecture

Lecture

35 pages

Lecture

Lecture

34 pages

Lecture

Lecture

9 pages

lecture

lecture

49 pages

class03

class03

39 pages

Lecture

Lecture

8 pages

Lecture 8

Lecture 8

42 pages

Lecture

Lecture

20 pages

lecture

lecture

29 pages

Lecture

Lecture

9 pages

lecture

lecture

46 pages

Lecture

Lecture

12 pages

Lecture

Lecture

24 pages

Lecture

Lecture

41 pages

Lecture

Lecture

37 pages

lecture

lecture

59 pages

Lecture

Lecture

47 pages

Lecture

Lecture

34 pages

Lecture

Lecture

38 pages

Lecture

Lecture

28 pages

Exam

Exam

17 pages

Lecture

Lecture

21 pages

Lecture

Lecture

15 pages

Lecture

Lecture

9 pages

Project

Project

20 pages

Lecture

Lecture

40 pages

L13b_Exam

L13b_Exam

17 pages

Lecture

Lecture

48 pages

Lecture

Lecture

10 pages

Lecture

Lecture

52 pages

21-p2p

21-p2p

16 pages

lecture

lecture

77 pages

Lecture

Lecture

18 pages

Lecture

Lecture

62 pages

Lecture

Lecture

25 pages

Lecture

Lecture

24 pages

Project

Project

20 pages

Lecture

Lecture

47 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Roundup

Roundup

45 pages

Lecture

Lecture

47 pages

Lecture

Lecture

39 pages

Lecture

Lecture

13 pages

Midterm

Midterm

22 pages

Project

Project

26 pages

Lecture

Lecture

11 pages

Project

Project

27 pages

Lecture

Lecture

10 pages

Lecture

Lecture

50 pages

Lab

Lab

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

6 pages

r05-ruby

r05-ruby

27 pages

Lecture

Lecture

8 pages

Lecture

Lecture

28 pages

Lecture

Lecture

30 pages

Project

Project

13 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

48 pages

Lecture

Lecture

55 pages

Lecture

Lecture

36 pages

Lecture

Lecture

17 pages

Load more
Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?