170 likes | 286 Vues
This document covers essential GDB commands and binary conversion techniques crucial for debugging in programming. Learn how to use commands like "break," "continue," and "watch" to manage your program's execution effectively. Additionally, find step-by-step methods to convert decimal to binary, binary to hexadecimal, and octal. Understand pointers and their manipulation in C, including dereferencing pointers and what it means to have pointers pointing to pointers. This comprehensive guide is designed for students and programmers looking to sharpen their skills.
E N D
Homework 1 grades: available online • Homework 2: due Feb. 26th • Office hours: • 9-11, Thursdays • By appointment Announcements
gcc –g filename.c • Useful commands • “break”: inserts a breakpoint • break filename.c: 34 • break func_name • “continue”, “step”, “next”: control progress through the program after a breakpoint • “where”, “up”, “down”:provides information about location of stopping point • “watch”, “disp”: used to track variable values • watch var_one (sets a “watchpoint” on var_one” • dispvar_one (shows the value and type of var_one” GDB basics
http://web.cecs.pdx.edu/~jrb/cs201/lectures/handouts/gdbcomm.txt (command examples) • http://www.stanford.edu/class/cs107/other/gdbrefcard.pdf (cheat sheet!) • http://www.yolinux.com/TUTORIALS/GDB-Commands.html • Links courtesy of Becky Gagnon Useful GDB resources
Fantastic tools for testing! • Things to remember: • #!/bin/csh goes at the top • To be able to run the script, type “chmod 700” Scripts
Decimal to binary: • 15610 to 100111002 • 156/2= 78 R 0 • 78/2=39 R 0 • 39/2=19 R 1 • 19/2=9 R 1 • 9/2=4 R 1 • 4/2=2 R 0 • 2/2=1 R 0 • 1/2= 0 R 1 Binary Conversions
1B16 to 110112 • Convert 1B16 to a decimal value: • 16*101+11*100=2710 • Convert 2710 to 110112 • 27/2= 13 R 1 • 13/2= 6 R 1 • 6/2= 3 R 0 • 3/2=1 R 1 • 1/2=0 R 1 • For Hex, you can go straight to decimal! • 1B: 1=0001, B=1011 : 00011011 Binary Conversions
Easy conversion from binary to octal and hex: • 11010101102: • 001101010110 1 5 2 6 15268 • 001101010110 3 5 6 35616 • For binary to hex, group the binary in groups of four from right to left. • For binary to octal, group the binary in groups of three from right to left. Binary Conversions
Pointers can be declared on the same line as other variables of the same variable type: • intnum_var=1, *num_pointer; • char letter=‘T’, *letter_pointer; • num_pointer=&num_var; • letter_pointer=&letter; • What about a pointer to a pointer? Pointer initialization
Use “ * “ before the pointer name to access its value. • Question: Are pointers a two way street? int Jay=63, int *tonight_show_host, *Jimmy; tonight_show_host=&Jay; printf(“The age of the last Tonight Show host is %i”, *tonight_show_host); Jimmy=tonight_show_host; *tonight_show_host=39; printf(“Jimmy Fallon’s age is %i, Jay Leno’s is %i, The Tonight Show host’s age is %i. \n”, *Jimmy, Jay, *tonight_show_host); Dereferencing Pointers
By the end of the code, • Jimmy=39 • tonight_show_host=39 • Jay=39 • That’s something important to consider when you modify pointers!! If you modify the value the pointer is pointing to, you also modify the variable that the pointer points to!! Dereferencing Pointers
So what about that pointer to a pointer? int number, *point, **still_pointing; number=900; point=&number; still_pointing=&point; • What does **still_pointing equal? &still_pointing? *still_pointing? More Pointers
**still_pointing=900 • *still_pointing= address of “point” • still_pointing= address of “still_pointing” • How would this be useful? More Pointers