Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Display Debugger (DDD)

Similar presentations


Presentation on theme: "Data Display Debugger (DDD)"— Presentation transcript:

1 Data Display Debugger (DDD)
Debugging Data Display Debugger (DDD)

2 References Project Homepage Manual URL
Manual URL

3 Debugger Computer program Capabilities Difficulty
Run a program step by step Stopping at some kind of event Tracking the values of some variables Modify the state of the program while it’s running. Difficulty Track down runtime problems in complex multi-threaded or distributed systems. Changes the internal timing of a software program.

4 Data Display Debugger (DDD)
A graphical user interface (GUI) for command-line debuggers. Under the GUI, you can use following debuggers GDB, DBX, Ladebug, or XDB: debug executable binaries JDB: debug Java byte code programs PYDB: debug Python programs Perl debugger: debug Perl programs BASHDB: debug Bash programs

5 A sample DDD session static void shell_sort(int a[], int size) {
int i, j; int h = 1; do { h = h * 3 + 1; } while (h <= size); h /= 3; for (i = h; i < size; i++) int v = a[i]; for (j = i; j >= h && a[j - h] > v; j -= h) a[j] = a[j - h]; if (i != j) a[j] = v; } } while (h != 1); int main(int argc, char *argv[]) int *a; int i; a = (int *)malloc((argc - 1) * sizeof(int)); for (i = 0; i < argc - 1; i++) a[i] = atoi(argv[i + 1]); shell_sort(a, argc-1); printf("%d ", a[i]); printf("\n"); free(a); return 0;

6 A sample DDD session $ gcc -o sample sample.c $ ./sample 8 7 5 4 1 3
$ ./sample

7 Compiling for debugging
Need to generate debugging information when compile a program. Stored in the object file Debugging information Describes the data type of each variable or function and the correspondence between source line numbers and addresses in the executable code. Specify ‘-g’ option when compiling For our case: gcc -g -o sample sample.c

8 Launching: ddd sample

9 Breakpoint Makes your program stop whenever a certain point in the program is reached. Typically, breakpoints are set before running the program. Put the cursor on the left of the source line, and click on the ‘Break’ button.

10 Run the program Select menu ‘Program->Run’.
In ‘Run with Arguments’ dialog, enter arguments for the program to be executed.

11 Command Tools ‘Run’: Run the program without argument / Run the program again with the same arguments. ‘Interrupt’: Interrupt the running program. ‘Step’: Step into a subroutine/sub-function which has debugging information. ‘Stepi’: Similar with ‘Step’, but it executes one machine instruction. ‘Next’: Execute a source line without stepping into the subroutine. ‘Nexti’: Similar with ‘Next’, also executes one machine instruction.

12 Command Tools ‘Until’: Continue until a greater line in the current function is reached This is useful to avoid single stepping through a loop more than once. ‘Finish’: Continue running until the current function returns. ‘Continue’: Resume execution. ‘Kill’: Kill the process of the debugged program.

13 Command Tools ‘Up’: Select the function stack frame that called this one. ‘Down’: Select the function stack frame that was called by this one. ‘Undo’: Undo the most recent action. ‘Redo’: Redo the most recently undone. ‘Edit’: Edit the source code by a test editor, by default it is VIM. ‘Make’: Recompile the source code. Needs ‘Makefile’

14 ‘Makefile’ for sample.c
sample: sample.o gcc -o sample sample.o sample.o: sample.c gcc -g -c sample.c clean: rm sample sample.o

15 Examine data To examine a simple variable To examine an entire array
Move the mouse pointer on its name. Enter variable name to argument field, and click on the ‘Print’ button. Show once Enter variable name to argument field, and click on the ‘Display’ button. The value will be shown in the Data Window To examine an entire array Enter - 1)’ to argument field, and print or display

16 Assignment to variables
Change the values of arbitrary variables during program execution. Select the variable in the source window, and click on the ‘Set’ button. Enter the variable name in the argument field, and click on the ‘Set’ button. If the variable is on the Data window, just select the variable, and click on the ‘Set’ button, or right click on the variable and select ‘Set Value…’.

17 Makefile

18 Reference Project Homepage Manual URL
Manual URL

19 Why we need a makefile Make enables the end user to build and install/deinstall your package without knowing the details of how that is done. Make figures out automatically which files it needs to update, based on which source files have changed. Make is not limited to any particular language. Make can do anything else you want to do often enough to make it worth while writing down how to do it. Makefile tells make what to do. Tells make how to compile and link a program.

20 How to use ‘Makefile’ $ make ‘make’ is system program
‘make’ will automatically search ‘Makefile’ or ‘makefile’ in the current directory ‘make’ will interpret it and execute it.

21 Simple Makefile A simple makefile consists of "rules" with the following shape: targets : prerequisites commands target: usually the name of a file that is generated by a program. the name of an action to carry out, such as `clean‘. prerequisite: a file that is used as input to create the target. commands: an action that make carries out.

22 Simplest Makefile for sample
sample: sample.c gcc -g -o sample.c clean: rm sample Rule Rule

23 How ‘make’ Processes a Makefile
By default, ‘make’ starts with the first target. ‘sample’ Before processing the rule ‘sample’, ‘make’ will process on the prerequisites first. ‘make’ will recompile ‘edit’ if one or more its prerequisites are newer than ‘sample’. no ‘sample’ file exists. If you want to process a specific rule, such as ‘clean’ ‘make clean’

24 Makefile for sample #Simplest Makefile for sample.
#sample.o is intermediate file. sample: sample.o gcc -o sample.o sample.o: sample.c gcc -g -c sample.c Why we need the intermediate file, which is ‘sample.o’?

25 Simple Makefile edit: main.c kbd.c command.c display.c
gcc -o main.c kbd.c command.c display.c clean: rm edit

26 Simple Makefile edit : main.o kbd.o command.o display.o gcc -o edit main.o kbd.o command.o display.o main.o : main.c defs.h gcc -c main.c kbd.o : kbd.c defs.h command.h gcc -c kbd.c command.o : command.c defs.h command.h gcc -c command.c display.o : display.c defs.h buffer.h gcc -c display.c clean : rm edit main.o kbd.o command.o display.o

27 Variable edit : main.o kbd.o command.o display.o cc -o edit main.o kbd.o command.o display.o A name defined in a makefile to represent a string of text, called the variable's value. Use ‘=’ to assign a value to a variable. objects = main.o kbd.o command.o display.o\ insert.o search.o files.o utils.o Usage: $(var_name) $(objects)

28 Simple Makefile objects = main.o kbd.o command.o display.o
edit : $(objects) gcc -o edit $(objects) main.o : main.c defs.h gcc -c main.c kbd.o : kbd.c defs.h command.h gcc -c kbd.c command.o : command.c defs.h command.h gcc -c command.c display.o : display.c defs.h buffer.h gcc -c display.c clean : rm edit $(objects)

29 Implicit Rule If you either write a rule with no command lines, or don't write a rule at all ‘make’ will figure out which implicit rule to use based on which kind of source file exists or can be made. For example foo: foo.o gcc -o foo foo.o foo.o: foo.h ‘name.o’ is made automatically from ‘name.c’ with a command of the form ‘$(CC) -c $(CPPFLAGS) $(CFLAGS)’ in C programs In our case, we should set ‘CFLAGS = -g’, such that can be used for debugging.

30 Implicit Rule (Example)
sample: sample.o gcc -o sample.o sample.o: sample.c gcc -g -c sample.c CC = gcc CFLAGS = -g sample: sample.o gcc -o sample.o

31 Simple Makefile objects = main.o kbd.o command.o display.o CFLAGS = -g
CC = gcc edit : $(objects) $(CC) -o edit $(objects) main.o : defs.h kbd.o : defs.h command.h command.o : defs.h command.h display.o : defs.h buffer.h clean : rm edit $(objects)

32 Simple Makefile objects = main.o kbd.o command.o display.o CFLAGS = -g
CC = gcc edit : $(objects) $(CC) -o edit $(objects) $(objects) : defs.h kbd.o command.o files.o : command.h display.o insert.o search.o files.o : buffer.h

33 Lab Exercise Debug the quick sorting program.
Extract the file using ‘tar -xvf sorting.tar’. Make a ‘Makefile’ to compile the source files. The algorithm is some kind of quick sort algorithm, but it does not work correctly. Find the bug!


Download ppt "Data Display Debugger (DDD)"

Similar presentations


Ads by Google