myGUIDE

|

random notes, random thoughts

Archive for the ‘Tutorials’ Category

Debugging with gdb

Friday, December 12th, 2008

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.

Using SSH for Passwordless Remote Login

Tuesday, August 19th, 2008

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.

(more…)

My First Silverlight Video Player Application

Monday, March 24th, 2008

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.

(more…)

Creating Articles Using the Article Manager Module in Phpwebsite (Simplified Version)

Sunday, December 9th, 2007

I have a couple of websites running phpwebsite. In these websites, I used the Article Manager module to handle article submission. I came up with a guide to help users of these sites. I am reposting the article here, which initially appeared at the Philippines Today website. The article is as follows:

To submit an article in this website, you need to have a username. If you already have one, you can login using the Log In box, which can be found in the left column of this page. If you don’t have an account yet, you can get one by signing up here. You only need a valid email address where your login credentials will be emailed.

After logging in, click here or the Submit An Article link from the Main menu box. A page containing an empty article will be displayed. See images below. Enter the necessary information, such as the article’s title, summary, and content, and click the Save Article button at the bottom of the page to post your article. The home page will be automatically updated with the summary of your article posted at the top of the Recent Article… section. It is that easy!

(more…)