2

I am trying to port gcc to a new target. The target is a new processor we designed our self with a full instruction set. We want to be able to compile c code in gcc for our new processor. To be able to accomplish that we need to port gcc for this specific target. I have read some gcc documents how to do it. So far I have edited/hacked an existing target of gcc and adopted it for our target, meaning gcc will generate assembly code for our specific processor. So I am using gcc to compile gcc for this new target. gcc will then generate a compiler myprocessor-gcc. This compiler will be able to generate assembly code for our target. by using my compiler a feed it with the following:

myprocessor-gcc test.c 

test.c looks like:

void __main(void); void main(void) { return; } void __main(void) { int i = 0; int i2 = 1; int i3 = 2; i = i2+i3; return; } 

gcc was able to compiled this code and generated the correct assembly language I was expected.

So I elaborated my test function to:

void __main(void) { int i = 0; int i2 = 1; int i3 = 2; int i4 = 3; i = i2+i3+i4; return; } 

After that gcc gives me a segmentation fault. I want to debug this segmentation fault, I need all the debug prints gcc can give me. So when I type:

myprocessor-gcc test.c -g 

I want to see some debug prints so that I can debug gcc internally. Sorry if I am not clear, I will elaborate if this is still unclear.

4
  • Show us some code? It's your personally designed compiler? Can we see your CFG? Commented Jun 19, 2014 at 12:18
  • I am trying to port gcc to my 8-bit processor by means of machine descriptors, I am actually hacking a existing machine descriptor. I was able to produce some assembly code, but it is by no means completed. If I could see some debug prints it would be very helpful, ../../configure --target=ag --prefix=location_for_my_compiler --enable-languages="c". ag is the name of my port. Commented Jun 19, 2014 at 12:31
  • I'm really curious what chip this compiler is for and what company you work for. Commented Jun 19, 2014 at 16:00
  • @DavidGrayson It is a chip me and my colleagues design as a hobby project. We are simulating the chip in Logisim. The objective is to build a full functional processor with a c compiler. It is hard to get gcc to accept the fact that the processor is only 8-bits and has only one general register (accumulator). If it is ok with my colleagues we will maybe post this project online, processor + gcc compiler. Not sure if there are many chip+compiler enthusiast out there. Commented Jun 19, 2014 at 17:45

1 Answer 1

2

You would need to make sure your cross-compiler itself was compiled with the -g option so it has debugging symbols in it. Then run gdb myprocessor-gcc test.c to see where the segmentation fault is happening in your compiler. You will have to learn some gdb commands like run and where.

Sign up to request clarification or add additional context in comments.

4 Comments

I am running it all in cygwin should I download gdb then? How do I use -g option building the cross compiler. I am using configure..., make and then make install. None of them seems to accept the -g switch
I have no idea how to download gdb in cygwin but I am sure you can figure it out, or you could do your development in a virtual Linux machine with a distribution/package manager that you are familiar with. The few GNU projects I have looked at enable the -g option by default so it might already be enabled, but if not then do something like ./configure --help and look for any option related to "debug". I just mainly wanted to point out the error in your approach, which is that you were trying to use -g to compile the embedded program, when in fact you actually need to debug the compiler.
The -g is an option that needs to be passed to gcc when you are compiling the cross-compiler; it is not an option to make or configure but there probably is a configure flag related to it.
I could not found any flag, but I suspected it is enable by default, I also added a macro to myprocessor.h file which is part of my gcc port. This macro is suppose to enable debugging not sure if it would work. I downloaded gdb for cygwin and found this great article that would help with debugging debugging-gcc-with-gdb

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.