Skip to content

Instantly share code, notes, and snippets.

@lucaswerkmeister
Last active December 29, 2015 10:29
Show Gist options
  • Save lucaswerkmeister/7657641 to your computer and use it in GitHub Desktop.
Save lucaswerkmeister/7657641 to your computer and use it in GitHub Desktop.
A test script for reading input in cgdb
#!/bin/sh
cd /tmp
cat > tmp.c <<EOF
#include <stdio.h>
int main() {
char str[4096];
fgets(str, 4096, stdin);
printf("%s\n", str);
return 0;
}
EOF
gcc -ggdb tmp.c
echo 'enter "run", then some text, then "quit"'
echo '========================================'
gdb a.out
echo '========================================'
echo 'now try the same in cgdb - if it hangs, you can exit cgdb with ESC-:q'
sleep 5 # give the user time to read the message
cgdb a.out
echo '========================================'
echo 'Lets try another example with readline'
[ -f /usr/include/readline/readline.h ] || {
echo "whoops, you don't have the readline library headers installed."
exit
}
cat > tmp.c <<EOF
#include <stdio.h>
#include <readline/readline.h>
int main() {
char* str = readline("> ");
printf("%s\n", str);
return 0;
}
EOF
gcc -ggdb -lreadline tmp.c
echo 'enter "run", then some text, then "quit"'
echo '========================================'
gdb a.out
echo '========================================'
echo 'now try the same in cgdb - if it hangs, you can exit cgdb with ESC-:q'
sleep 5 # give the user time to read the message
cgdb a.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment