diff --git a/2019/endoh/.gitignore b/2019/endoh/.gitignore index f63f9f19d..31ac2bf7a 100644 --- a/2019/endoh/.gitignore +++ b/2019/endoh/.gitignore @@ -1,6 +1,7 @@ # # sort with: sort -d -u *.dSYM +ascii indent indent.c indent.o diff --git a/2019/endoh/Makefile b/2019/endoh/Makefile index dd5a64307..473de4155 100644 --- a/2019/endoh/Makefile +++ b/2019/endoh/Makefile @@ -111,7 +111,7 @@ PROG= prog OBJ= ${PROG}.o CSRC= ${PROG}.o DATA= -TARGET= ${PROG} +TARGET= ${PROG} ascii # ALT_OBJ= ALT_TARGET= @@ -132,6 +132,9 @@ all: data ${TARGET} ${PROG}: ${PROG}.c ${CC} ${CFLAGS} -g $< -o $@ ${LDFLAGS} +ascii: ascii.c + ${CC} $< -o $@ + # alternative executable # alt: data ${ALT_TARGET} diff --git a/2019/endoh/README.md b/2019/endoh/README.md index 2130710bf..b4ce509d8 100644 --- a/2019/endoh/README.md +++ b/2019/endoh/README.md @@ -25,10 +25,24 @@ For more detailed information see [2019 endoh in bugs.md](/bugs.md#2019-endoh). ### Try: +If you have `gdb(1)` installed: + +```sh +./try.sh +``` + +Note that in macOS installing `gdb(1)` takes multiple steps - it's not just a +matter of installing `gdb(1)` and that's that. The [try.sh](try.sh) script has +only been tested with linux. + +You might also wish to try: + ```sh gdb ./prog || lldb ./prog ``` +and then type in `r` (to run program) and then `bt` (for backtrace). + ## Judges' remarks: @@ -38,6 +52,7 @@ ascii` when debugging it to reveal its purpose. ## Author's remarks: + ### backtrace quine: Compile prog.c with no optimization. diff --git a/2019/endoh/ascii.c b/2019/endoh/ascii.c new file mode 100644 index 000000000..f09ba521f --- /dev/null +++ b/2019/endoh/ascii.c @@ -0,0 +1,19 @@ +/* + * ascii.c - simple program that shows the character value of ASCII values, if + * isascii() is true, to help demonstrate IOCCC winner 2019/endoh. + * + * Will not do anything if no args specified. Use xargs(1) to pass args to + * program if it's a lot of characters. + */ +#include +#include +#include +int main(int argc, char **argv) +{ + int i; + for (argc = 1; argv[argc]; ++argc) + { + i=atoi(argc[argv]); + if (isascii(i)) printf("%c", i); + } +} diff --git a/2019/endoh/try.sh b/2019/endoh/try.sh new file mode 100755 index 000000000..764447e0e --- /dev/null +++ b/2019/endoh/try.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2019/endoh +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +# Before we do anything we have to make sure we have GDB available +# +GDB="$(type -P gdb)" + +if [[ -z "$GDB" ]]; then + echo "No gdb found, install gdb and try again." 1>&2 + exit 1 +fi + +make CC="$CC" all >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +echo "$ $GDB -q -x prog.c ./prog | head -n 25" 1>&2 +read -r -n 1 -p "Press any key to use source code as GDB command file (first 25 lines): " +echo >&2 +"$GDB" -q -x prog.c ./prog | head -n 25 + +echo "$ $GDB -q -x prog.c ./prog | cat | grep : | cut -f 2 -d:|xargs ./ascii" +read -r -n 1 -p "Press any key to use the backtrace to reconstruct prog.c (space = next page, q = quit): " +echo 1>&2 +"$GDB" -q -x prog.c ./prog | cat | grep : | cut -f 2 -d: | xargs ./ascii | less -rEXF +echo 1>&2 + +read -r -n 1 -p "Press any key to compare reconstructed code with original: " +echo 1>&2 +echo "$ "$GDB" -q -x prog.c ./prog | cat | grep : | cut -f 2 -d: | xargs ./ascii > prog2.c" 1>&2 +"$GDB" -q -x prog.c ./prog | cat | grep : | cut -f 2 -d: | xargs ./ascii > prog2.c +echo "$ diff -s prog.c prog2.c" 1>&2 +diff -s prog.c prog2.c diff --git a/thanks-for-help.md b/thanks-for-help.md index ffe0b7e9f..a111c8f0b 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -4214,6 +4214,12 @@ As this is a backtrace quine having the optimiser enabled is not a good idea so compilation as debugging symbols might just be useful for an entry that's supposed to segfault :-) +Cody also added the simple [ascii.c](/2019/endoh/ascii.c) that (while it has an +arg) prints out the character of the ASCII value (uses `isascii(3)` first). This +combined with the [try.sh](/2019/endoh/try.sh) script that he added allows one +to easily reconstruct the source code through GDB by the fact it's a backtrace +quine. + ## [2019/karns](/2019/karns/prog.c) ([README.md](/2019/karns/README.md]))