Document The Debugger
File strings_in_table.c
in subfolder
Debugger
in your shared folder.
The program strings_in_table.c
inserts N strings in
a table of M entries, and N >> M. The technique to accommodate
this is to keep a linked list of strings in each entry of the
table. Function main
first inserts N strings, deletes some
of them, and finally prints the table content on the screen.
The program contains four errors. One of them produces a segmentation fault. Two of them allow the program to terminate, but printing incorrect results on the screen. Also, the fourth error make the program use more memory than required (580 bytes) and produces several memory leaks.
Using the debugger, modify the code to obtain a correct version that prints the table elements correctly, has no memory leaks and uses only 580 memory bytes.
In the debugging session for the previous program, see the effect when the print command is executed and its argument is a function call, for example print():
(gdb) p print(table, 5)
In the debugging session for the previous program, when all elements have been inserted in the table, select one entry and using the print command show on the screen all the strings stored in the linked list.