I have made a compiler for a subset of C called the BabyC using the Bison and flex. My program consists of the following files:
ast.c,ast.h, linkedList.c, linkedList.h, BabyC.y, BabyC.l, main.c, symbolTable.c, symbolTable.h, codeGenerator.c, codeGenerator.h
and finally, a make file which is as follows:
CC = gccWARNFLAGS = -Wall -WextraDEBUGFLAGS = -g -O0all: bccOBJS := BabyC.tab.o BabyC.yy.o ast.o symbolTable.o codeGenerator.o linkedList.o main.obcc: $(OBJS) $(CC) $(WARNFLAGS) $(DEBUGFLAGS) $(OBJS) -o $@%.o: %.c $(CC) $(WARNFLAGS) $(DEBUGFLAGS) -c $<%.yy.c: %.l flex -o $@ $<%.tab.c: %.y bison -o $@ -d $<clean: rm -f *.o *.tab.* *.yy.* bcc bcc.out
My test case, which is a simple program in the BabyC language is of the extension ".bc"
With all of the files in a single directory, on my system, I type "make" which gives me the required ".o" files and also a bcc file based on the above makefile. My make command looks something like this:
akaidecember@DESKTOP-JCU5EAP://mnt/c/Users/akaid/Google Drive/src$ makebison -o BabyC.tab.c -d BabyC.ygcc -Wall -Wextra -g -O0 -c BabyC.tab.cIn file included from BabyC.y:2:0:ast.h:80:1: warning: useless storage class specifier in empty declaration }; ^flex -o BabyC.yy.c BabyC.lgcc -Wall -Wextra -g -O0 -c BabyC.yy.cIn file included from BabyC.l:2:0:ast.h:80:1: warning: useless storage class specifier in empty declaration }; ^BabyC.yy.c: In function ‘yy_get_next_buffer’:BabyC.yy.c:1239:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { ^gcc -Wall -Wextra -g -O0 -c ast.cIn file included from ast.c:3:0:ast.h:80:1: warning: useless storage class specifier in empty declaration }; ^ast.c: In function ‘free_ast’:ast.c:14:3: warning: enumeration value ‘AST_IDENT’ not handled in switch [-Wswitch] switch (node->type) { ^ast.c:14:3: warning: enumeration value ‘AST_NUM’ not handled in switch [-Wswitch]gcc -Wall -Wextra -g -O0 -c symbolTable.cgcc -Wall -Wextra -g -O0 -c codeGenerator.cIn file included from codeGenerator.h:5:0, from codeGenerator.c:3:ast.h:80:1: warning: useless storage class specifier in empty declaration }; ^gcc -Wall -Wextra -g -O0 -c linkedList.cgcc -Wall -Wextra -g -O0 -c main.cIn file included from main.c:5:0:ast.h:80:1: warning: useless storage class specifier in empty declaration }; ^gcc -Wall -Wextra -g -O0 BabyC.tab.o BabyC.yy.o ast.o symbolTable.o codeGenerator.o linkedList.o main.o -o bccrm BabyC.tab.c BabyC.yy.cakaidecember@DESKTOP-JCU5EAP://mnt/c/Users/akaid/Google Drive/src$
Now, a "bcc" file is created. I run the file with the command and the test case file as :
./bcc test1.bc
and this is my output:
akaidecember@DESKTOP-JCU5EAP://mnt/c/Users/akaid/Google Drive/src$ ./bcc test1.bcProcessing declaration of aSegmentation fault (core dumped)
Now, it is really hard for me to trace the segmentation fault manually. So I tried debugging the program using gdb, but I can't get it to work with my program. I tried running the program with gdb running and it tells me that it is an undefined command. I guess it will not run as a normal c ".o" file.
Could anyone help me with how to debug this program? I would like to debug this program and trace the segmentation fault.