#!/bin/bash


set -e
set -u


cd /home/deseessm/obj/build-qhello-Desktop-Debug

month=$(date +"%m")
day=$(date +"%d")
year=$(date +"%y")


echo -n "Please enter Serial number in hex (e.g. 0x123): "
read serial

echo << EOF > gdb.txt

br loop
run
call (flash)(10,\"mmm\")
clear loop
c
EOF


cat << EOF >gdb.txt

br main:loop
run
set var \$new = (SMyStruct *)malloc(sizeof(struct SMyStruct))
set var \$new.version = 1
set var \$new.name="Script"
set var \$new.day=$day
set var \$new.month=$month
set var \$new.year=$year
set var \$new.serial=$serial
call (flashP)(\$new)

# target reset run

set logging file serial.txt
set logging overwrite
set logging on
print/x myStruct.serial
set logging off

EOF

gdb qhello -x gdb.txt -batch-silent -q

echo -e "\n\n\n"

echo "Serial: "
a=$(cat serial.txt)
echo ${a##* = }



#cat << EOF > gdb.txt
#br main:loop
#run
#set logging file serial.txt
#set logging overwrite
#set logging on
#print/x myStruct.serial
#set logging off
#clear loop
#EOF
#gdb qhello -x gdb.txt -batch-silent -q



#---fin------------------------------------------------------------------------
