Wednesday, August 06, 2008

Getting assembly listing embedded with C/C++ Source Code using GCC

I was planning to look at some odd behavior of C++ typedefs and assembly output in the case of GCC/G++ compiler suite for MIPS, especially when O2 optimizations were used.

For most of the compiler suites (Borland, GCC) one can generate the assembly listing by using -S option.

For e.g., if you have file called foo.cpp, then you can see the assembly equivalent by passing -S as an argument to the compiler (Remember that it will not produce the .o / .exe output as usual)
c:\Sriram:\> bcc -S foo.cpp
c:\Sriram:\> mips-elf-gcc.exe -S foo.cpp
This would produce a foo.asm or foo.s output containing the assembly listing in the same folder.

However, I wanted to embed the C/C++ source code for mips-elf-gcc along with the assembly output for easier debug. After looking at many compiler options and googling, I found the mix I need:
c:\Sriram:\> mips-elf-gcc.exe -c -g -Wa,-a,-ad foo.cpp
You might note that I did not include the -S option!

The options are as follows:
-c : Compile only (dont proceed to link - This is because foo.cpp did not have a 'main' or equivalent.
-g :Include debug informaiton
-Wa : Pass the following options (comma seperated to the assembler)
-a : Include high-level, assembly, and symbols listing
-ad : Omit debugging pseudo-ops from the listing

Please look at GCC Documentation and a GNU Assembler Documentation for more information.

Saturday, August 02, 2008

Ruby! (sqlite3 and Ruby on Rails)

I have been programming in Python for a while - To say 'programming' is a bit staid - I love python and I keep writing scripts just for the heck of it.

Of late, thanks to popularity of Ruby on Rails, I thought I'd learn Ruby - I started Ruby a week ago, and thanks to my super work-schedule, I haven't been able to spend a lot of time. But, since I already know python, it might be easier to learn Ruby.

I'll write more on how I feel Ruby is, and how it compares with Python as time goes.

To warm up on Rails, I got the book "Ruby on Rails - Up and Running" - I installed RoR using gems
c:\Sriram:\>gem install rails

Then when I started the server, and created the first controller (Greeting in the book) mentioned in the first chapter, I got the following error:

"no such file to load -- sqlite3"

[This error message appears in the web-page when I tried to load "http://localhost:3000/greeting"]

It has been a while since I did some web-programming. I panicked for a moment, but reassured myself that this problem should be trivial, and it was :-) (Yad Bhavam, Tad Bhavati [As you think so will it become])

I realised that I need to install sqlite - The database that was default in RoR. So, I went to sqlite download page , and downloaded the command line and the dll. (make sure the versions of the dll and the command line match to avoid surprises later) - I downloaded sqlite-3_5_9.zip and sqlitedll-3_5_9.zip. I unzipped the dll and copied it to c:\windows\system32

Then I also installed sqlite3-ruby
c:\Sriram\Rails:\>gems install -r sqlite3-ruby

I then restarted the WEBrick server and voila! I could see the rendering of the text in index function of the controller in the web-page.

FYI, I am running on a quad-core PC with Windows Vista. Ruby 1.86. RoR 2.1

Btw, I downloaded the 'Instant Rails Package' - I have been trying to unzip the package for the past few hours. Looks like it is easier to get going with the gems installation of RoR and manual install of sqlite3 (Instant Rails may be more useful for a bigger project, but to get your hands wet, the above steps should do...)