user15180: I am using https://github.com/sudar/Arduino-Makefile project with https://github.com/ladislas/Bare-Arduino-Project to compile my Arduino projects from Linux command line. I put as much as possible functionality to libraries for reuse (and use the same libraries from many projects too).
Now I had run to some problems and I am not sure, if I am using the language (C/wiring/...) properly, as a lot of #define macros are used. I think, that seeing the resulting code would help me greeatly in finding, wheather some specific lines are compiled into what I want them to be compiled. I am interested mainly in the library code, even if it would mean to dump full program together with all used standard libraries. (I can find my way in large files.)
I would prefere intermediate files, as I suppose they could contain more info than just dissassembled .HEX file, but if this assumption is not correct, and I can get the same from .HEX, than I can use that way as well. 
Question: How to get intermediate files (Ideally both "plain C" after preprocessing all macros AND "plain ASM" after compiling the code) ideally with corresponding lines of original code as comments inside.
Subquestion: In the above, how to disable optimalisation as much as possible, to get the code more verbatim similar to original C (I know, that it would hurt both speed and size and I do not care - I just want to be sure compiler does undertand my code the same way as I myself and if not, then see, where I made mistakes)
Thanks for all suggestions :)

user3917: One method I've used for creating assembly listings for Arduino sketches when using the Arduino IDE is as follows:
• Click Verify to compile the sketch
• Locate the the temporary build directory
• Use avr-objdump with -CSI... switches to decode the ELF file 
Here are some commands you can put into a shell file to automate that procedure, on a Linux system:
item=*.ino
[ -z "$item" ] && echo ino file not found && exit
BDIR=/tmp/$(ls -t /tmp | egrep -m1 build.*tmp)
BASE=$(basename $item .ino)
avr-objdump -CSI$PWD $BDIR/$BASE.cpp.elf > $BASE.ino.asm

The above assumes the current working directory (ie, $PWD) is the directory with the sketch in it; variable item is the sketch name; variable BASE is the basename of the sketch, with .ino stripped off; $BDIR is the most-recently-used temporary build directory (which, on Ubuntu Linux systems, has a path that starts with /tmp/build); and the resulting deassembly is placed in $BASE.ino.asm for viewing.
To try this manually, as you may need to do on systems where the above shell commands don't work, say 
avr-objdump -CSIddd bbb/sss.cpp.elf > sss.ino.asm

in a shell or at a command console, replacing ddd with the sketch's source directory name; bbb with the temporary build directory's name; and sss with the sketch's name.

Edit 2: Using Sudar's Arduino Makefile probably is the best starting point for looking at source code that has been pre-processed, or that has been compiled (into assembly language).  This makefile system is fairly easy to install and use.
When you have the makefile system  installed and working, you can generate  pre-processed code (code that's been run through the pre-processor to incorporate #include files and to expand macros) by adding the following line within a makefile:
CPPFLAGS += -E

The -E switch tells avr-gcc to stop after preprocessing.  According to man gcc its effect is:

Stop after the preprocessing stage; do not run the compiler proper.  The            output is in the form of preprocessed source code, which is sent to the            standard output.

To generate assembly language, add the following line within a makefile:
CPPFLAGS += -S

The -S switch tells avr-gcc to stop after compiling.  According to man gcc its effect is:

Stop after the stage of compilation proper; do not assemble.  The output is in the form of an assembler code file for each non-assembler input file specified. ... By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s.

If you are skilled at makefile writing, it may be possible to add a target with rules to generate assembly or pre-processed code for inspection.  Actually, Sudar's Arduino Makefile appears to have assembly-listing targets and rules already (as below for .pde; others for .ino and .cpp) although I haven't gotten them to work:
# generated assembly
$(OBJDIR)/%.s: %.pde $(COMMON_DEPS) | $(OBJDIR)
        @$(MKDIR) $(dir $@)
        $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -S -fverbose-asm $(CPPFLAGS) $(CXXFLAGS) $< -o $@

[I now see that Edgar Bonet has mentioned this too.]

user7508: You can get the generated assembly by passing the -S option to
avr-g++. The makefile you are using has a rule for that, so you would
just type
make build-*/my_file.s

to get the assembly for my_file.cpp.
For the pre-processed C++, you use the -E option. There is no rule for
that in the makefile, so you will have to write yo own, or manually
invoke the compiler. At a minimum:
avr-g++ -mmcu=my_mcu -E my_file.cpp > my_file.i

You may want to add -DF_CPU=... -DARDUINO=... just like the makefile
does when compiling the same file.

15180: <p>I am using <a href="https://github.com/sudar/Arduino-Makefile" rel="nofollow noreferrer">https://github.com/sudar/Arduino-Makefile</a> project with <a href="https://github.com/ladislas/Bare-Arduino-Project" rel="nofollow noreferrer">https://github.com/ladislas/Bare-Arduino-Project</a> to compile my Arduino projects from Linux command line. I put as much as possible functionality to libraries for reuse (and use the same libraries from many projects too).</p>

<p>Now I had run to some problems and I am not sure, if I am using the language (C/wiring/...) properly, as a lot of <code>#define</code> macros are used. I think, that seeing the resulting code would help me greeatly in finding, wheather some specific lines are compiled into what I want them to be compiled. I am interested mainly in the <strong>library</strong> code, even if it would mean to dump full program together with all used standard libraries. (I can find my way in large files.)</p>

<p>I would prefere intermediate files, as I suppose they could contain more info than just dissassembled .HEX file, but if this assumption is not correct, and I can get the same from .HEX, than I can use that way as well. </p>

<p><strong>Question</strong>: How to get intermediate files (Ideally both "plain C" after preprocessing all macros AND "plain ASM" after compiling the code) ideally with corresponding lines of original code as comments inside.</p>

<p><strong>Subquestion</strong>: In the above, how to disable optimalisation as much as possible, to get the code more verbatim similar to original C (I know, that it would hurt both speed and size and I do not care - I just want to be sure compiler does undertand my code the same way as I myself and if not, then see, where I made mistakes)</p>

<p>Thanks for all suggestions :)</p>
 3917: <p>One method I've used for creating assembly listings for Arduino sketches when using the Arduino IDE is as follows:<br>
• Click Verify to compile the sketch<br>
• Locate the the temporary build directory<br>
• Use <code>avr-objdump</code> with <code>-CSI...</code> switches to decode the ELF file </p>

<p>Here are some commands you can put into a shell file to automate that procedure, on a Linux system:</p>

<pre><code>item=*.ino
[ -z "$item" ] &amp;&amp; echo ino file not found &amp;&amp; exit
BDIR=/tmp/$(ls -t /tmp | egrep -m1 build.*tmp)
BASE=$(basename $item .ino)
avr-objdump -CSI$PWD $BDIR/$BASE.cpp.elf &gt; $BASE.ino.asm
</code></pre>

<p>The above assumes the current working directory (ie, <code>$PWD</code>) is the directory with the sketch in it; variable <code>item</code> is the sketch name; variable <code>BASE</code> is the basename of the sketch, with <code>.ino</code> stripped off; <code>$BDIR</code> is the most-recently-used temporary build directory (which, on Ubuntu Linux systems, has a path that starts with <code>/tmp/build</code>); and the resulting deassembly is placed in <code>$BASE.ino.asm</code> for viewing.</p>

<p>To try this manually, as you may need to do on systems where the above shell commands don't work, say </p>

<pre><code>avr-objdump -CSIddd bbb/sss.cpp.elf &gt; sss.ino.asm
</code></pre>

<p>in a shell or at a command console, replacing <code>ddd</code> with the sketch's source directory name; <code>bbb</code> with the temporary build directory's name; and <code>sss</code> with the sketch's name.</p>

<hr>

<p><em>Edit 2:</em> Using <a href="https://github.com/sudar/Arduino-Makefile" rel="nofollow noreferrer">Sudar's Arduino Makefile</a> probably is the best starting point for looking at source code that has been pre-processed, or that has been compiled (into assembly language).  This makefile system is fairly easy to install and use.</p>

<p>When you have the makefile system  installed and working, you can generate  pre-processed code (code that's been run through the pre-processor to incorporate <code>#include</code> files and to expand macros) by adding the following line within a makefile:</p>

<pre><code>CPPFLAGS += -E
</code></pre>

<p>The <code>-E</code> switch tells avr-gcc to stop after preprocessing.  According to <code>man gcc</code> its effect is:</p>

<blockquote>
  <p>Stop after the preprocessing stage; do not run the compiler proper.  The            output is in the form of preprocessed source code, which is sent to the            standard output.</p>
</blockquote>

<p>To generate assembly language, add the following line within a makefile:</p>

<pre><code>CPPFLAGS += -S
</code></pre>

<p>The <code>-S</code> switch tells avr-gcc to stop after compiling.  According to <code>man gcc</code> its effect is:</p>

<blockquote>
  <p>Stop after the stage of compilation proper; do not assemble.  The output is in the form of an assembler code file for each non-assembler input file specified. ... By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s.</p>
</blockquote>

<p>If you are skilled at makefile writing, it may be possible to add a target with rules to generate assembly or pre-processed code for inspection.  Actually, Sudar's Arduino Makefile appears to have assembly-listing targets and rules already (as below for .pde; others for .ino and .cpp) although I haven't gotten them to work:</p>

<pre><code># generated assembly
$(OBJDIR)/%.s: %.pde $(COMMON_DEPS) | $(OBJDIR)
        @$(MKDIR) $(dir $@)
        $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -S -fverbose-asm $(CPPFLAGS) $(CXXFLAGS) $&lt; -o $@
</code></pre>

<p>[I now see that Edgar Bonet has mentioned this too.]</p>
 7508: <p>You can get the generated assembly by passing the <code>-S</code> option to
avr-g++. The makefile you are using has a rule for that, so you would
just type</p>

<pre><code>make build-*/my_file.s
</code></pre>

<p>to get the assembly for <code>my_file.cpp</code>.</p>

<p>For the pre-processed C++, you use the <code>-E</code> option. There is no rule for
that in the makefile, so you will have to write yo own, or manually
invoke the compiler. At a minimum:</p>

<pre><code>avr-g++ -mmcu=my_mcu -E my_file.cpp &gt; my_file.i
</code></pre>

<p>You may want to add <code>-DF_CPU=... -DARDUINO=...</code> just like the makefile
does when compiling the same file.</p>
