How to debug a C script
Let's take the code in my Small scripts in C and save it csv.c.
The input data is the f.csv with this content:
Name,Age,City
Alice,30,New York
Bob,25,London
Charlie,12,Paris
David,40,Longueuil
David,35,Tokyo
Sheepy needs to be installed to be able to run csv.c.
Running csv.c gives:
./csv.c f.csv
[+] 25-06-14 20:20:58 Column Name: 4 distinct values
[+] 25-06-14 20:20:58 Column Age: 5 distinct values
[+] 25-06-14 20:20:58 Column City: 5 distinct values
The debugger is gdb, sheepy starts gdb with the arguments for csv.c:
sheepy -g ./csv.c f.csv
sheepy -g works after the program csv.c has run at least once or has been compiled with the command:
sheepy -c csv.c
Then on gdb prompt type:
# break in main
b main
# run
r
# next
n
n
n
# print file
p file
$1 = (smallJsont *) 0x55555572d2a0
# print file content
p otos(file)
$2 = 0x55555572f430 "[\"Name,Age,City\",\"Alice,30,New York\",\"Bob,25,London\",\"Charlie,12,Paris\",\"David,40,Longueuil\",\"David,35,Tokyo\"]"
p file shows only a pointer and p *file shows internal variables and a pointer to the content.
In libsheepy, there is the otos() function (otos is Object TO String) to print the content of objects in gdb.
toStringG converts objects to string but it is a C11 generic and is not availabe in gdb. toStringO is a #define and not available in gdb, so the otos has to be used in gdb to show an object content.
Hashtag: #programming