1
COMP 1402
Winter 2008 Tutorial #6 Arrays Part 2, Structures, Debugger
Overview of Tutorial #6
- Arrays revisited, array indexing
- Memory allocation
- Freeing memory
- Basic Data structures
- Debugger revisited
- Exercises
COMP 1402 Winter 2008 Tutorial #6 Arrays Part 2, Structures, - - PDF document
COMP 1402 Winter 2008 Tutorial #6 Arrays Part 2, Structures, Debugger Overview of Tutorial #6 Arrays revisited, array indexing Memory allocation Freeing memory Basic Data structures Debugger revisited Exercises 1
a[0] a[1] a[2] a[3] a[4]
*a *(a+1) *(a+2) *(a+3) *(a+4)
BOX: Width Height Length Weight
– break place: this will add a breakpoint at a certain place. For example break main will put a breakpoint at the first line of main(). You could also do break 10 which will add a breakpoint to the 10th line of your code (according to the line numbers given by list) – info break: this will list all of your breakpoints. – delete N: will delete the breakpoint number N.
#include <stdio.h> int main() { int a,b; a=10; b=6; a++; b--; a = a-b; } hello.c 1 2 3 4 5 6 7 8 9 10 Line #
gcc –g –o hello hello.c gdb hello (gdb) (gdb) break main Breakpoint 1 at 0x8048365: file hello.c, line 5. (gdb) run Breakpoint 1, main () at hello.c:5 5 a=10;
Compile with –g flag Start gdb with program name gdb command prompt Add breakpoint at the start of main gdb adds breakpoint to main (line 5) Start running the program Reaches first breakpoint (stops before executing line 5)
(gdb) display a 1: a = 7528436 (gdb) display b 2: b = 10363856 (gdb) step 6 b=6; 2: b = 10363856 1: a = 10 (gdb) step 7 a++; 2: b = 6 1: a = 10
Add a and b to the list of displayed variables (notice the uninitialized values) Take one step (execute line 5) Take one step (execute line 6) Next line to be executed Current values of a and b And so on until the end…