Debugging with gdb

Comments | 590 views
December 12th, 2008 Programming, Tutorials

GDB is the GNU project debugger which can be very helpful when you’re trying to figure out what goes wrong in the application you’re developing. With gdb, you can start a program, specify points or conditions where the program’s execution will be stopped so that you can examine its current condition, and experiment correcting values to discover bugs that maybe lurking in your code. gdb’s online documentation can be found here.

To use gdb, you need to compile your program with the -g option to include debugging information. For instance, using gcc, you can compile program myprog.c as follows:

[user] gcc -g myprog.c

To start gdb, run gdb program in the command prompt, where program is the name of your executable file. For instance,

[user] gdb a.out

First, this will display gdb’s front material describing its copyright and non-warranty, among other information. Then you will be put in gdb prompt (gdb).

Start the program by issuing the command run in the (gdb) prompt. If you have not yet issued any break points, the program will continue running until it finishes or it encounters fatal error. To quit gdb, just issue the quit command.

The main purpose of gdb is to allow programmers to stop the program before it terminates so that its current condition can be examined and potential sources of trouble can be known. This is where breakpoints, catchpoints, and watchpoints become handy. A breakpoint makes your program stops whenever a certain point is reached. On the other hand, a watchpoint is a special breakpoint that stops the program when the value of an expression changes. A catchpoint is another kind of breakpoint that stops the program when a certain kind of event occurs.

To setup a breakpoint, use the break command followed by the location. The location can be a function name, a line number, or an address of an instruction. For example,

(gdb) break 10

will set a breakpoint at line number 10, and

(gdb) break myfunc

will set a breakpoint at the start of function myfunc.

To examine your source file within gdb, you can use the list command. list prints 10 lines by default from the source file. It also prints the line numbers which you can use in the break command. Some of the useful list options are as follows:

(gdb) list linenum

will print lines centered around linenum.

(gdb) list startline, numlines

will print numlines starting from startline in the current source file.

(gdb) list function

will print lines centered around the beginning of function

(gdb) list

will print the next 10 lines.

After a break, you can continue the program execution using the continue or c command. You can also run the program until the next line is reached with the step or s command. To step by machine execution instead of source line, use the stepi or si command. The next or n command will execute the next line including any function call. To execute just the next machine instruction, use nexti or ni.

The above commands should keep you started. If you need help, just type help in the (gdb) prompt. You can further refine help by appending any command after help, such as

(gdb) help break

That’s it! And happy debugging.

All about SVN

Comments | 728 views
September 15th, 2008 Howto

Subversion (or SVN) is an open source version control system that can be used to maintain several versions of files such as program source codes, webpages, and other documentation. It has several features including most CVS features, versioned copy, delete, renames, etc. Most Linux installations already include SVN so that you can use it immediately if you like. 

I started using SVN only recently to track changes I made to the source codes of programs I have written, and hence this note. SVN is quite handy as it allows you to access your source code from any computer which can access your repository. You can commit changes you made to the code in one workstation, and when you work on those codes in another workstation,  you can just update the local copy to reflect the changes you made. In the following, I’ll assume that SVN is already installed.

1. Creating an SVN Repository

   1: [user@mycomp] cd
   2: [user@mycomp] mkdir Repos
   3: [user@mycomp] svnadmin create Repos

First, create a directory which will serve as the SVN repository. In the example above, a directory called Repos/ is created in the user’s home directory (line 2). To tell SVN to use this as the repos, use svnadmin create command passing the directory name as the target (line 3).  After executing this command, SVN will place several directories and files in this directory. You can check the contents of Repos/ by running ls -al Repos.

2. Storing codes into the repository

   1: [user@mycomp] mkdir appwebcam
   2: [user@mycomp] mkdir appwebcam/trunk
   3: [user@mycomp] mkdir appwebcam/logs
   4: [user@mycomp] mkdir appwebcam/branches
   5: [user@mycomp] mkdir appwebcam/trunk/SRC
   6: [user@mycomp] mkdir appwebcam/trunk/bin

Now that you have your repository setup, it is time to add some data into it. You can structure the data within the repository any way you like. But usually, you’ll have a main directory for a project (say, appwebcam/), then within this, you have subdirectories for trunk/, logs/, and branches/. Within the trunk/ subdirectory, you can have SRC/ subdirectory to hold your source codes, bin/ subdirectory for the binaries, etc. Lines 1-6 simply create this directory structure. 

3. Import your codes to the repository

   1: [user@mycomp] svn import ./appwebcam file:///home/user/Repos/appwebcam -m "Initial import"
   2: Adding appwebcam/trunk
   3: Adding appwebcam/trunk/SRC
   4: Adding appwebcam/trunk/bin
   5: Adding appwebcam/logs
   6: Adding appwebcam/branches

To import the created directory structure into the repository, use svn import as shown in line 1 giving the directory you want to import (./appwebcam), the location of the repository (file:///home/user/Repos/appwebcam), and an import comment option (-m "Initial import") as parameters. This will create an "invisible" directory appwebcam/ under the Repos/ directory.

4. Checking out codes from the repository

   1: [user@mycomp] svn co file:///home/user/Repos/appwebcam/trunk appwebcam
   2: A    appwebcam/SRC
   3: A    appwebcam/bin
   4: Checked out revision 1.

Finally, if you want to checkout a certain portion of your repository, use svn checkout (or svn co). In the above example, only the contents of the trunk/ subdirectory under appwebcam/ are being checkout into the appwebcam/ directory in the user’s current directory. After the checkout, appwebcam/ will contain the SRC/ and bin/ subdirectories.

Generating self-signed certificate using ADT to sign AIR applications

2 Comments | 1,717 views
September 5th, 2008 Howto

To package an Adobe AIR application using ADT (AIR Developer Tool), a certificate is needed. Digitally signing your application with a certificate from a recognized certificate authority identifies you as the publisher. It also provides assurance to users that your application has not been accidentally or maliciously altered. For these purposes, you can get a certificate from known certificate providers such as VeriSign or Thawte. But if you’re just developing an application for personal or friends’ use, you can use a self-signed certificate, which can be generated using ADT. You can then use this certificate to sign your personal AIR applications :-).

To generate the certificate, run the following command:

adt -certificate -cn name [-ou org_unit][-o org_name][-c country] key_type pfx_file password

where -cn name is the common name that will be used for the generated certificate, -ou org_unit refers to the organizational unit issuing the certificate, -o org_name is the name of the organization issuing the certificate, -c country is a two-letter ISO-3166 country code, key_type can either be "1024-RSA" or "2048-RSA" pfx_file is the name of the file where the certificate will be stored, and password is the certificate’s password. The parameters inside square brackets are optional.

As an example, the actual command may look like this:

   1: adt -certificate -cn "My Certificate" -ou bagarinao.com -o "ABK Co" -c US 2048-RSA myCert.p12 sd#$wd23

   2: adt -certificate -cn "AIR App" 1024-RSA MyCert.p12 sd#$wd23

The first line illustrates how to generate a certificate specifying all the possible parameters. On the other hand, the second line only uses the required parameters in generating the certificate. Both will generate a new certificate and will store it in a file called myCert.p12 with password sd#$wd23.

To use the generated certificate to sign an AIR application, use adt using the -package option instead of the -certificate option. Use -storetype pkcs12, -keystore myCert.p12, and -keypass sd#$wd23 to specify the certificate that will be used to sign the application. The command is something like

adt -package -storetype pkcs12 -keystore myCert.p12 -keypass sd#$wd23 <airfile> <app-desc> other-files ..

where <airfile> is the name of your package, <app-desc> specifies the XML application descriptor file, and other-files are the files and directories that you want to package with your air application.

Installing NinfG version 5

1 Comment | 725 views
August 26th, 2008 Howto

NinfG is an open source grid middleware which provides a programming framework for grid-based remote procedure calls (GridRPC). It is a reference implementation of the GridRPC API (application programming interface), allowing programmers to create applications that can call procedures/executables installed on remote computers. In particular, it provides client library APIs that can be used to control the execution of remote executables, running these executables remotely when necessary.

NinfG 5.0 is the latest version of NinfG. Unlike previous versions where the Globus Toolkit is required, NinfG 5.0 can now work with non-Globus grid environment. One of its new features is the ability to use SSH to do remote procedure calls via the invoke server mechanism. This is very handy since most Linux systems have already SSH in the default installation, so there is no need to install additional packages to use NinfG. The following paragraphs outline the installation of NinfG on a system running Linux.

Read the rest of this entry »

Using SSH for Passwordless Remote Login

1 Comment | 1,001 views
August 19th, 2008 Howto, Tutorials

Secure Shell or SSH is a network protocol allowing secure data exchanges between two networked devices. It is designed to replace Telnet, which sends information over the network in plain text making it susceptible to interception or eavesdropping. SSH, on the other hand, provides secure communication by encrypting the data sent over the network. It is typically used to login to a remote computer and to execute commands remotely. Aside from this, SSH can also be used to securely transfer files using scp or sftp, forward TCP ports, SSH tunneling, among others.

The following is my outline on how to use SSH for passwordless remote login. Of course, this is far from being complete and some of the things below may not work perfectly with your setup. There are many howtos regarding this topic and you should be able to find the one that is appropriate for your system.

Read the rest of this entry »

Trying Shindig, an OpenSocial and Google Gadgets container

2 Comments | 2,635 views
June 13th, 2008 Applications, Howto

Shindig is an open source reference implementation of Google’s OpenSocial and gadgets specifications. With Shindig, you will be able to host Google gadgets and OpenSocial applications in your own web site relatively quickly as it already contains code that you can easily plug into your server infrastructure to start hosting these applications.

Interested with OpenSocial, I tried installing Shindig in my home server. Currently, Shindig’s PHP implementation is far from being complete, so my interest is just to have a feel on how it works. To install Shindig, check its web site and follow the instructions there. The project does not yet support automated build infrastructure so you need to get Shindig from its SVN repository. For this, you need an SVN client. Fortunately, I have Cygwin installed in my Windows XP machine, so I only had to install subversion in Cygwin. This can be done by running the Cygwin installer, then locate the subversion package, select it, and install. After the installation, run a bash shell and you are ready to export Shindig.

Read the rest of this entry »

Migrating phpWebsite 0.10.2 to PHP version 5

2 Comments | 1,240 views
May 12th, 2008 Howto, solutions

After changing my web hosting provider, I am faced with the task of migrating a couple of web sites to the new server. A couple of these web sites are phpWebsite-based. Unfortunately, the new server is using a version of PHP higher than 5, which is known to cause some problems with the version of phpWebsite (v 0.10.2) I am currently using. Left with no choice, I searched Google for available solutions. Luckily, the search results did come up with some possible solutions, although I could not find an official migration guide. So in this post, I will describe the problems I’ve encountered in migrating my phpWebsite 0.10.2 installation to a server running a PHP version higher than 5.

The first thing I did was to transfer all files and databases to the new server. After uploading everything, I also changed the configuration file (conf/config.php) to reflect the new server setup. This included changing the database and source directory settings. Then, the debugging part.

Read the rest of this entry »

My blog as my OpenID identity

Comments | 1,890 views
April 15th, 2008 Howto

To understand openID, you only need to consider the number of Internet accounts you currently maintain. Maybe you have one email account in Yahoo or Google, another account in Flickr for your photos, an account in YouTube for videos, another one in Friendster, Facebook, or MySpace for your social network, and many many more. For each of this site, you need to have a username and a password in order to use the provided services. As your online presence expands, keeping tab of all these accounts becomes more difficult. I have several so I know how difficult it is to remember all username-password combinations. This is the issue openID is trying to solve.

According to their website, "OpenID is a free and easy way to use a single digital identity across the Internet." Ideally, with one OpenID you can login to all your favorite sites eliminating the need to maintain several usernames and passwords. Imagine the convenience of using a single username-password combination for all websites you would like to visit. Well, this is still ideal since not all websites have already adopted OpenID. Surprisingly, you may already have one without knowing it. If you have an account in wordpress.com, your OpenID is simply username.wordpress.com, or if you have one in flickr.com, your OpenID is www.flickr.com/photos/username, and several others. Check this site on how to get one. The interesting thing is that you can use your own website or blog as your OpenID identity. How? Read on.

Read the rest of this entry »

My First Silverlight Video Player Application

1 Comment | 3,345 views
March 24th, 2008 Applications, Tutorials

I always wanted to create my own web-based video player to share vacation videos with relatives and friends back home. But I didn’t have an idea where to start. I initially considered Adobe Flash but it’s not free and I didn’t have a license for it. Of course it is easier to just store the video files in YouTube and it will be immediately accessible to everyone. But I don’t like splitting each video into 10-min segments, 10 minutes being the current maximum length of video clips allowed in YouTube. 

Then I came across Silverlight, Microsoft’s cross-browser and cross-platform plug-in for delivering rich interactive applications on the web. I read about it several months ago. And the first thing that came to mind was whether it could be used to create a self-hosted video player for sharing videos on the Internet. Last weekend, I finally had the time to try it out. I visited Silverlight’s web site and looked for some introductory materials to work on. Fortunately, I found a tutorial on how to use Silverlight for video playback. I tried it and it worked!

So here is an outline of my first Silverlight video player application. This is based on the tutorial from Silverlight.net. The brief explanation is based on my understanding of the original tutorial.

Read the rest of this entry »

Migrating from Serendipity to Wordpress Using Windows Live Writer

4 Comments | 2,698 views
March 12th, 2008 Applications, Howto, solutions

After months of inactivity, myGUIDE is now back with a new look and running on a different weblog platform. Yes, you read it right, I changed my blog platform from Serendipity to WordPress. This means that although I have migrated all my previous posts to WordPress, previous links will no longer work since Serendipity and WordPress have different link structure. Now if you’re looking for a particular post, you can still find it here. Just use the search box to locate it.

How did I do it? It was quite easy. Thanks to Windows Live Writer (WLW). But before taking this approach, be warned that this may not be appropriate for your case. This worked for me because myGUIDE is relatively new and has only a small number of blog entries and I’ve been using WLW to post entries to this blog. A Serendipity importer plugin is already available for WordPress. So maybe you’re better off using the plugin. But if you want an alternative approach, you can try this one.

The first thing to do is to create a weblog account in WLW to access your Serendipity-based blog, if you have not done it yet. Then setup another account in WLW to access your WordPress blog. After doing this, you’re ready to go. Simply read your blog entries, one at a time, from your old blog using WLW, then switch to your new blog, and click the Publish button to publish the entry you just retrieved. It is that easy! You can also use WLW to create the relevant categories in your new blog. You can even set the published date so that you can keep the original date of your posts.

But there are limitations to this approach. First, you will lose all your comments. WLW will not read the comments associated to each post.  Second, WLW sometimes will not download the images in the post. Instead it will just get the link of the image from your original blog and use this link in the new one. Thus if you’ll remove your old blog, the images will also disappear. Finally, if you have many entries, transferring all of them can take some time since you have to manually repeat the process of reading your previous posts from Serendipity then publishing it to WordPress. Luckily for me, I have only 15 entries so this was not an issue. ;-)

And that’s it!