How to determine problem code? (Arduino Mega 2560 compile issue)

So, I'm coding for an Arduino Mega 2560, I just modified a few minor sections of the code for cleanup, and the compiled code will no longer upload to the unit.

Searching around, (and searching the compiled code itself) I find that the compiler has decided to be "nice" to me and stick three !'s in a row. At 115200 this apparently dumps the Mega into a monitor which avrdude cannot escape from, and so the system "hangs".

Now, to be clear, my code does not contain three !'s in a row anywhere, and grep'ing through the source trees and libraries also has nothing like that, in fact to be safe, I just went and pulled all !'s from my strings.

Is there any way (other than starting from scratch, or randomly modifying code) in which I can figure out what code is causing the three !'s to be generated in a row?

If not, and I'm SoL, then shrug I'll have to start randomly changing code. Just hoping to actually have this upload properly as written. Just a little annoyed this only shows up in the elf binary that is used to generate the hex dump to load onto the unit.... I would have preferred to find out it was me somewhere... grin

Post your problem code. If you have it, can you upload the previous version successfully? Wouldn't hurt to post that version too if so.

I do not believe it to be a specific piece of my code, more with how the compiler has compiled the code.

My code is a few hundred lines of code in multiple files (around 20k just in my own code), and I don't have a prior version (yeah yeah, I know I should be SCC'ing it, but I was just trying to prototype it). I won't bombard the list with the entire source code tree.

I was more wondering if there was a way to show how the compiler arrived at a specific patch of elf binary, as this (I'm sure) will wind up happening to me frequently given that the compiler does not seem to avoid the use of more than two exclamation marks in a row.

I think there is supposed to be a bootloader that fixes that. But you can take the .elf file and do this to it:

avr-objdump -S foo.elf > bar.txt

Then edit the resulting bar.txt file. Inside you’ll find your code with the line numbers and C code in it. Search for the three !!! symbols and you should see what they belong to.

Thanks Nick! This is exactly what I needed.

And of course, given that, I wound up slowly going through the code and doing other cleanup, and it was fixed by moving one line of code from one location to another.

That being said, that command line is perfect for when this happens again.