Please help with bash, clang, and gdb
leeoliveshackelford at surewest.net
leeoliveshackelford at surewest.net
Mon Sep 15 18:11:43 UTC 2014
Greetings dear FreeBSD enthusiast. I have written a character mode
c-language program that is supposed to read data from a text file on a
floppy disk, perform calculations on that data, then write the result to
another text file on the same floppy disk. The operating system is
FreeBSD 9.1. The computer is a Hewlett-Packard xw4400 workstation
equipped with a Pentium D microprocessor. The D processor has only a
single core.
I insert the floppy disk, then type as follows:
mount -t msdosfs -w /dev/fd0 /mnt
clang -x c -g /mnt/ProgName.c > mnt/CompOut.txt 2>&1
I do not understand the syntax of the last four characters of the second
line, but they somehow cause bash to redirect the output of clang
orginially directed to the monitor screen to the specified file. The
output file from clang is generated. It contains one warning, and no
errors. If I then type at the prompt
/root/a.out /mnt/BmIn0001.txt
the a.out program prints to the monitor screen instructions to the user,
which are followed immediatedly by the prompt symbol. The source-code
line to open the input file is as follows:
if ((InpFileHand = fopen (argv[1], "rb"))==NULL)
{
printf ("nCould not open file %s.", argv [1]);
exit (11);
}
The source-code line to open the output file is as follows:
if ((OutpFileHand = fopen (OutpFileName, "wt")) == NULL)
{
printf ("nCould not open file %s", OutpFileName);
fcloseall();
exit (25);
}
where OutpFileName is an array of char read from the input file. If I
enter the following
wait $!
echo $?
the exit code of 0 is displayed. An exit code of 0 is generated by the
last line of the program. If the program failed to open either file, an
error code of either 11 or 25 should have been produced. Even though the
a.out program exitted normally as far as the operating system is
concerned, the indicator on the floppy drive never lights, causing me to
believe that the program failed to read the input file. When I enter
cd /mnt
ls
the expected output file is shown to be absent. How did my program get
all of the way from beginning to end without opening the files, yet not
exit with expected codes of 11 or 25? Attempting to answer this
question, I then enter at the prompt
gdb /root/a.out
then, at the gdb prompt, enter
set args /mnt/BmIn0001.txt
gdb fails with an error code of 0177. I research this error code with
the aid of Google, and am informed that it indicates that, under
p-threads, the libraries were loaded in an incorrect order. My program
is intended to be a c language, not c++ language program, with all
libraries loaded with the executable and linked statically. The only
libraries referenced in the program are stdio, stdlib, math, and time.
The only library functions called are printf(), fprintf(), fopen(),
fcloseall(), fgetc(), ungetc(), fwrite(), sqrtr(), time(), and ctime().
What do any of these have to do with p-threads?
I realize that this is a long message, and that programmers may have
more important responsibilities than helping newbies. Is there a FreeBSD
developer who is familiar with these three programs who might be willing
to identify my error(s)? Any and all suggestions are appreciated.
Sincerely, Newby Lee
More information about the freebsd-questions
mailing list