@shijitht

October 20, 2010

Valgrind

Filed under: C, Commands, GNU/Linux, Tools — Tags: , , , , — shijitht @ 1:18 pm

Valgrind is a collection of tools to check the correctness of a program. The main tool in it is memcheck. It reports memory leak, out of bound writes, improperly initialized variables etc. This provides a report which pin points the correct location of the error. So this is a good tool to debug programs with unpredictable behavior and crash.

Using

Inorder to see the exact line number of error, compile the code with -g option and reports could be misleading if optimization above level 1 are used(-O1). The -g option compiles the code with debugging symbols enabled, this helps valgrind to locate line number.
Use this program prog.c

prog.c
-------
void fun()
{
    char *a = (char *)malloc(10 * sizeof(char));
    a[10] = 'a';
}
main()
{
    fun();
    return 0;
}

prog.c has two major errors,
1. a[10]  = ‘a’;
a[10]  is out of the allocated region. Writing to this region could produce mysterious behavior. This is called heap block overrun.
2. 10 byte block pointed by a is never freed. So on return to main, that block remains inaccessible and unusable. This is a serious memory leak.

Lets use valgrind to detect these errors,
Compile the code with -g option

$ cc -g prog.c

Generate report

$ valgrind –leak-check=yes   ./a.out
can use 2>&1 to redirect report to a file( $ valgrind –leak-check=yes  ./a.out > report   2>&1 )

Analyzing report

Various error messages and summaries can be found. error messages are generated in case of out of bound writes, here a[10].
The corresponding report is
==4836== Invalid write of size 4
==4836==    at 0x80483FF: fun(prog.c:6)
==4836==    by 0x8048411: main (prog.c:11)
==4836==  Address 0x419a050 is 0 bytes after a block of size 40 alloc’d
==4836==    at 0x4024F20: malloc (vg_replace_malloc.c:236)
==4836==    by 0x80483F5: fun(prog.c:5)
==4836==    by 0x8048411: main (prog.c:11)
4836 is the process id. First line shows, error is due to an invalid write of size 4. Below it is a complete stack trace. The error happened at line 6 of  prog.c. Read stack trace from bottom to up. Started from main, then a function call to fun, malloc and error at last. Error shows the address we tried to write is beyond the allocated 40 byte block. This information is quite useful to make the code correct.

The Leak summery show the memory leaks.
Here,
==4836== LEAK SUMMARY:
==4836==    definitely lost: 40 bytes in 1 blocks
==4836==    indirectly lost: 0 bytes in 0 blocks
==4836==      possibly lost: 0 bytes in 0 blocks
==4836==    still reachable: 0 bytes in 0 blocks
==4836==         suppressed: 0 bytes in 0 blocks
Second line shows the 40 byte block lost in function fun. Report includes other types of leaks also.

Valgrind checks these errors and leaks in runtime like a virtual machine executing each instruction of a code. So it is time consuming for large code. But the report generated is very much useful and can be used to correct mistakes which are otherwise very difficult to detect.

Advertisements

August 26, 2010

Pidgin invisibility cloak

Filed under: Tools — Tags: , , , , — shijitht @ 1:54 pm

Go Invisible option in pidgin is an option only. It will set status to busy. But there is a solution for it.

Go online.
Enable the XMPP console in Tools > Plugins.
Now select Tools->XMMP Console->XMMP Console.
Check your gmail account is selected in the console.
Put these code in the second box and hit enter.
Don’t mind the trail of code in the monitor, but a hacker could find it pretty useful.

{{{
<presence>
<priority>5</priority>
</presence>
<presence type="unavailable">
<priority>5</priority>
</presence>
}}}

Now go invisible.
To reset change unavailable to available and put it in the console.
For more go to http://www.madhusudancs.info/invisible.

August 22, 2010

Brief note about using Git

Filed under: Commands, Tools — Tags: , , — shijitht @ 7:51 pm

This is a short note including everyday commands. You can find more details like installing git and more commands at http://help.github.com/.
Don’t forget $ man git.

Create a repo graphically and do the following to get started.

The first section is to set up your name and email as a committer.

“git commit” allows to commit locally with  comment specified using -m option.
Here $ git commit -m “first commit” will make your local repo a step ahead of remote repo.
Check status using $ git status .
At first we need to connect to the remote repo. Origin is the remote repo-name used here, I suggest github or whatever name say your real repo name.
Now push using git push. Here master branch pushed to origin(remote repo-name).
To start tracking/add a new file → $ git add <file name> .
To commit to the remote repo → $ git push <repo name>  <branch name>.

Default branch choice is master.
To see branches → $ git branch .
Add -a option if you wish to see remote branches also.
To add a new branch for parallel developing → $ git branch <branch name> .
Move to the new branch → $ git checkout <branch name> .
To push a new branch →
$ git push <remote repo name>  <local branch name> :<remote branch name>.

If you use both branch names same, the ” <local branch name>: ” is optional.
To delete a branch locally → $ git branch -d .
To delete remote branch → $ git push <repo name>   :<remote branch name> .
i.e. nothing pushed( local section blank ).
To add a tag → $ git tag <tag name>
To update remote repo → $ git push   – – tags
To remove tags → $ git push <repo name>  :<tag name> .
Creating a folder demands adding files under it and use git rm in case of file deletion. So better keep file names distinct.
Use git clone/fetch to create a local copy of a repo.
To remove a repo do it graphically.

Useful links :
http://www.gitready.com/
http://scottr.org/presentations/git-in-5-minutes/

August 7, 2010

BloGTK WordPress setup

Filed under: Tools, WordPress — Tags: , , , , , , , — shijitht @ 6:39 pm

BloGTK is an application for blogging. We can use it for posting new articles, instead of browser. It has everything offered by word press editor. Install the software first.
DEB family type “apt-get install blogtk” and RPM group type “yum install blogtk” as root in the terminal. After installing, select it from Application/Internet/BloGTK Webblog Client. If it is not starting, take terminal. Type blogtk to start it. It might show an error like “no module named gtkhtml2”. Then you should install python-gtkhtml2. If apt-get or yum fails to find such a package, you can get it here, python-gtkhtml2. Select appropriate package from the liked site and double-click to install. If installed correctly, blogtk would run.
The settings are, go to Edit/Account and Settings and set

Server URL : http://you.wordpress.com/xmlrpc.php
Username : username
Password : password
Blogging System: Movable type
Press OK and select Connect in File.

Now you are ready to post. Select the desired Blog and Category to start writing new posts. You can see 3 tabs. Edit Post for normal editing, Advanced for tags etc and Preview shows preview. The demerits are no text formatting, HTML editor, grammar checking etc. This my first post using BloGTK. I finished it early but I don’t have the usual satisfaction using Word Press. I think you can use it as an offline tool for blogging. It is good tool for a blogger having limited Internet access.
Thanks to this..

August 6, 2010

Malayalam font

Filed under: Tools — Tags: , , — shijitht @ 12:44 am

We could hardly understand words of a Malayalam site. The problem is lack of correct font. For example go to manoramaonline. At the first look, you will close it. As many of our doubts, googling resolves it. But many consider it a huge effort, I don’t know why ?.

You get a Malayalam font, double-click and press install. Manorama.ttf is at the bottom. If fails or something unexpected happens, go ahead with following commands. As root

# mkdir /usr/share/fonts/manorama
# cp  Manorama.ttf /usr/share/fonts/manorama
# fc-cache  -fv

First we created a folder manorama in font directory(/usr/share/fonts/). Then copied Manorama.ttf font to that. The third command updated font information cache files. Restart your browser to start reading in mother-tang.

Click to download Manorama.ttf 

August 3, 2010

IRC > Forms

Filed under: Tools — Tags: , , , — shijitht @ 12:10 pm

Joining an IRC channel can solve doubts more quickly than posting at linux forms. IRC named ##linux would be filled with more than 850 users every time. And I never waited more than 10 sec for a question. At least 3 answer pops up in that time. I have never seen such an active channel elsewhere. If you have any doubts (after googling), I strongly suggest you put that in ##linux. For joining an IRC channel, you should have

* A client say Pidgin

* Add an account specifying IRC as protocol

* On receiving a prompt or chat window type /join ##linux

* Use a nick name,  /nick <name>  is enough. Registering that nick if you are a regular visitor.

* For more details you can google IRC/freenode.

Here is a fine link for clients you might like

July 29, 2010

Open System Sounds : Installing and Configuring

Filed under: Tools — Tags: , — shijitht @ 10:01 pm

* install oss from the file obtained from its site

* osstest will test available sound devises in the system.

* /use/lib/oss/ -> a useful folder containing configuration mixer.oss etc.

* oss will add the detected devices in /dev/oss

* when we have configured the device, passed osstest and still having the problem we can configure the softwares(vlc etc).

* we need to select oss instead of alsa or whatever for the audio functioning of the software and this will demand an audio device path.As stated above the device will be in /dev/oss most likely by the name pcm0.

* ossxmix will allow us to adjust volume properties graphically

* ossdetect -v will show the detected devices

* soundon and soundoff could be used to load and unload oss.

* /etc/init.d/oss {start | stop | restart} could be used to manage oss service

* remove /usr/lib/oss/starting if insisted

* vmix is virtual mixing. This will allow us to adjust the volume of each application separate. Vlc would be added to vmix when the above conf done.

Create a free website or blog at WordPress.com.