Arduino IDE distribution contains complete set of compilers, libraries and tools to build any AVR firmware. For debugging purposes one can use this with powerful open source, cross platform, free C, C++ Code::Blocks IDE.
Let's consider setting up of development environment consisting of Code::Blocks IDE plus Arduino 1.6.12 release as example.
Major Linux distributions provide Code::Blocks via their repositories, so you only need do something like
sudo apt-get install codeblocks
Windows users can dounload Code::Blocks installer from its site.
Download an archive of Arduino 1.6.12 for your platform there and unpack into your home folder.
In Code::Blocks IDE under Settings/Compiler make a copy of "GNU AVR GCC Compiler" item
and name it "Debug Arduino 1.6.12 GNU AVR GCC Compiler",
then go to "Toolchain executables" tab and set "Compiler's installation directory"
to <your_home_dir>/arduino-1.6.12/hardware/tools/avr .
Add the folowing lines into "Additional Paths":
<your_home_dir>/arduino-1.6.12/hardware/tools/avr/libexec/gcc/avr/4.9.2
<your_home_dir>/arduino-1.6.12/hardware/tools/avr/libexec/gcc/avr/4.9.2/plugin
<your_home_dir>/arduino-1.6.12/hardware/tools/avr/libexec/gcc/avr/4.9.2/install-tools
<your_home_dir>/arduino-1.6.12/hardware/tools/avr/avr/bin
Also on the "Search directories" tab remove any directories listed under "Compiler" and "Linker".
Also on the "Other settings" tab press "Advanced options.." and ensure that
"command line macro" under "Link object files to executable" and "Link object files to console executable"
doesn't contain any -s -Os -O0 .. -O3 options.
Also on the "Compiler Flags" tab uncheck corresponding option flags.
You need to configure avr-gdb yet - look for more instructions here .
After that your Code::Blocks IDE is ready to build debuggable AVR firmware image
and run it under debugger with help of simavr/simutron.
Note: this way you can have several Arduino IDE/SDK versions and use it with different projects.
Just create separate Code::Blocks settings for each compiler/toolchain using the above procedure.
As template for your projects you can use LCD20x4Test example .
You can select compiler version for particular project using the Project/"Build options.." dialog.
Also remember to set ARDUINO_DIR variable value to <your_home_dir>/<arduino-version>
on the "Custom variables" tab.