Possible Ubuntu Arduino bug

I installed Arduino 11 on Ubuntu 8.04 and all went well. I used a make file for compilation. Some months passed, and when I came back to it it was necessary to re-install the ubuntu packages but not the arduino packages. (That is gcc-avr, avrdude, avr-libc) Recompiling the code it only half runs!!

After much investigation, it seems to come down to this:

void debugstop(long int x); void funtest (int y) {

long int jj; jj=220L * ( 1024L- y); debugstop(jj); } funtest(0);

gives the wrong result, 66813952

void debugstop(long int x); void funtest (int y) { int z=0; long int jj; jj=220L * ( 1024L- z); debugstop(jj); } funtest(0);

gives the correct result, 225200

Can anyone throw any light on this? Anyone help solve it? At present I can see no workaround to get the value from a parameter into the double length expression.

Debugstop halts the program and allows me to see the value of the parameter passed.

Type cast it inside the expression, e.g. jj = 220L * ( 1024L - [b](long int)[/b]y);

-j

No that doesnt help, or fix it. (I tried exactly what you put, as well as trying this before original post.)

Remember this is something that has changed between versions. and also it changes depending on weather the integer is a parameter or not. (weather you use y or z.)

Hard to say without knowing the parameter you are passing, what the rest of the code does, etc. Could be the classic running out of RAM problem. I don't think I have enough information to offer anything else.

My instinct is to doubt that the problem is ubuntu related, unless you have already moved to a different platform and verified the sketch works there.

-j

Would appreciate some pointers about how to investigate next. My feeling is to dive into the debugger. Or find exact compiler versions and trawl to see if the bug is reported already. The sketch worked perfectly with the older compiler, and I achived no results that were the slightest bit surprising. I dont have the chance to recompile under that set up now. Well maybe I have a backup in fact..... But thats not really the point, it did work then and it doesnt now. And the code is simple, you can see it should work.

Ok, I'm getting somewhere with this. Its clear that the default version of gcc-avr with ubuntu 8.10 is 4.3.0 and this has some severe optimisation issues, and is generally put down by all and sundry 4.3.2 is what is needed. There may be issues with installing this as well...

This bug seems relevant: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34916 also see http://www.nabble.com/GCC-4.3-20080215-snapshot-broken-for-AVR-td15522499.html

So the new version of the compiler is in the jaunty repositories. Add these lines temporarily to the file /etc/apt/sources.list:

deb http://archive.ubuntu.com/ubuntu/ jaunty main restricted universe multiverse

You can then use synaptic to upgrade to the 4.3.2 package. I then upgraded to arduino-0012 which seemed to be needed. All sorts of messages then about missing header files (Firmata).

It was a real slog, and eventually I was able to prove that my code did indeed work with the new compiler at least that one line of code did.

But losts of other stuff was curiously different. The board drives a colour graphics didplay and all sorts of things were just wrong.

I removed all the new line in sources.list. Changed all instances of intrepid to hardy and then re-installed the original versions.

Everything worked.

So what comes out of this. If you are doing Arduino on a fresh Ubuntu platform, everything is broken, and well, I wouldnt even bother. Revert back to the Hardy Herron versions and you may have more luck. Of course all that will be fine until you need one of the new features...

Mark, I bet this is related to the problem people have experienced with the broken random() and rand() functions in Ubuntu: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1227218077/31.

Mikal

Yes, it sounds likely although it might be more accurate to call it an optimisation bug because in reality it is not to do with the random number generator. (which I am not even using) In other words, if the explanation is correct you would expect to see problems in many areas of mis-optimised code, most of which havnt even been reported yet!

And indeed if you look at my code fragment, you really cant get very much simpler, it clearly must be some kind of optimisation fault if you believe anything I am saying.

Its a bit of a shame though, because in a commercial sofware environment there would be a range of tests that detect things like this and either use real hardware in a test harness which a host system communicates with, or an emulator to run regression tests against a large number of compiled c snippets. If the compiler is to be reliable, this has to be done, or everytime it is "improved" some trivial new bug that is not trivial to the end user will make it unusable. Its also true that something that "works a lot of the time" is far worse than something that is completly broken, from an end user perspective.

Its also a shame that Ubuntu users dont have a synaptic-point and go package as yet.

Arduino is a fantastic platform, and recent improvements can clearly make it even better, but this type of problem can really stand as an obstacle to newbies.

Perhaps I didnt make it clear above, the version of avr-gcc that I am now using that handles long ints correctly and doesnt seem to have other problems is 4.2.2

I'm having problems with 4.4.2 & the serial port on a Mega board. What't the newest version of gcc that actually works?

Hi,

I'm having problems with 4.4.2 & the serial port on a Mega board. What't the newest version of gcc that actually works?

The question doesn't seem to be related to the original problem of this thread, so you better start a new topic. Many people looking at the topic will only scan 2 or 3 answers to see if they are interested ...

And for all Linux related questions the chances of getting answers is increased if you tell us :

  • Your version of the Arduino-IDE
  • Your Linux distribution and version
  • and a bit more what the actual problem is.

Eberhard