Table of Contents
Document The Debugger
Folder Music_data
in your
Subversion shared space.
There is a local copy here.
The my_music.c
program stores
information about a collection of disks as it is shown in the following
figure:
The global vairables rap
,
rock
, and rumba
are structures of type
Category
with the number
of disks stored as a linked list. Each disk is a structure with the
number of songs, an array of information about each song and the pointer
to the next disk. For each song, its duration and a pointer to its title
is stored.
The program (see main
function)
first prints the number of disks for each
category, then the duration of all songs in a category (with the function
Duration
), and finally the title of the last song of each
disk in each category with the function
print_title_last_track_in_each_disk
.
You may ignore the static functions in the file. They are correctly implemented and they only load and unload the data structures.
Compile and execute the program
my_music.c
(remember compile it with
option -g
). It has three errors. Due to them, the messages printed on the
screen are incorrect. For example, the duration of the disks in the
“rap” category is incorrect, and the messages showing the
title of the last track of every disk are also incorrect.
Using the debugger, analyze its execution and fix it
(maybe it is convenient for you to copy the program file to keep also the original one).
For that, you can locate the three global variables and the two functions
Duration
and
print_title_last_track_in_each_disk
. Execute the programa with the debugger
until the point where the duration of the rap category is
printed; at this point, execute step by step this calculation. Repeat the procedure
for the first call to the function
print_title_last_track_in_each_disk
.
Remember the static functions in the file are correctly implemented and they only load and unload the data structures.
The way to know if the execution is correct is because the program output must be (pay attention to the last line):
--- Welcome to the Music Statistics program --- Analyzing your music collection... 2 disks in the rumba category 2 disks in the rock category 1 disks in the rap category Duration of rumba songs: 6019 Duration of rock songs: 7044 Duration of rap songs: 4639 Duration of all songs: 17702 Title of last track in rumba disks: Disk 1: vestido de flores Disk 2: nina Title of last track in rock disks: Disk 1: god save the queen Disk 2: now im here Title of last track in rap disks: Disk 1: curtains close skit --- PROGRAM IS FIXED! COMMIT YOUR CHANGES ---
Optionally, upload the code to the SVN and show it to your instructor. It is recommended for you to note down the steps you have given during the exercise. Later, you will be able to explain your instructor those steps and how the debugger has helped you to find the solution. Your instructor also may check if you understood the use of the debugger with some questions.
In this activity, you will execute files with errors, with
Valgrind. These files are under your repository in the
Valgrind_errors
directory. There is a local copy
here.
For each of the following
files, compile it with the -g directive (that is
gcc -Wall -g yourfile.c -o yourexecutable), execute it
with Valgrind (valgrind --leak-check=yes
./yourexecutable), and fix the reported errors, explaining in the
same file (with a comment of 1-2 lines) the reason for the error:
File strcpy_exercise.c
: copies one
string over a second one.
File printing_exercise.c
: copies an
integer to a pointer and prints its address and the value just
copied.
Opcionalmente, upload the modified files to your repository and show the modifications to the teacher to be evaluated.
Program implementing a menu with several options.
To self-checking your code, you can use:
test_menu_operations_array_pointer_en.sh
Using the program with options to show information of wireless networks, mentioned functions, make the following modifications:
Change the definition of the array that stores the wireless networks in
the main
function. Each element of the array should be a pointer to
a data of type struct ap_scan_info
.
Adapt the functions of the program (array_load
and others) to
support the new type of the elements in the array.
Optionally, upload the file to the repository with
svn commit
.
Now, it is time for enhacing functionality you have in your Wifi menu with two additional functionalities:
Function number [5] in charge of showing best Wifis. This menu function will show Wifis in increasing quality order.
[6] Delete function in charge of deleting a Wifi record. After setting an Wifi as not available, it will never show up again.