Johnny [Life & Code]

July 7, 2009

GDB Scripting : A short article for a internal magazine

Filed under: CODE, GNOME, Linux Fun, Programming, Tech, Thoughts, suse — Johnny @ 8:56 am

I wrote a small article for a internal magazine and few of my friends wanted me to post it to this blog.

This is for people who are new to GDB and still exploring itz features. So if you’ve used GDB for more than few weeks please ignore and skip :)

GDB – Scripting

A good majority of novice programmers tend to use printf functions to trace function calls and to printout the debug data. This forces you to change the code and compile again and again. To eliminate these superfluous tasks from your day-to-day work, use GDB. The GDB has facilities for scripting and helps in saving plenty of your time.

Tracing Function Calls

If you want to know whether a function is called or not, create a break point and write a simple script.

<code>

#Set the breakpoint

(gdb) b mapi_sync

Breakpoint 1 at 0×7fffd75f36e2: file camel-mapi-folder.c, line 741

#Tell GDB what to do when the breakpoint is reached

(gdb) commands

Type commands for when breakpoint 1 is hit, one per line.

End with a line saying just “end”.

> continue

> end

(gdb)

</code>

continue – Come out of break and continue

end – terminate command list

Run the program now. The GDB prints the function name when the breakpoint is hit and automatically continues running the program.

Breakpoint 1, mapi_sync (folder=0xc9c1a0, expunge=0, ex=0xf3a0c0) at camel-mapi-folder.c:741

741             CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (folder->parent_store);

Using the GDB Scripts for Analyzing the Data

Suppose that you have a singly-linked list that has strings in it. At some point, you might want to know the contents of the list. To do this, use the GDB scripting instead of adding the debug statements in your code.

<code>

#Example for gslist traversal.

define p_gslist_str

set $list = ($arg0)

while ((GSList *)$list->next != 0)

p (char *)(GSList *)$list->data

set $list = (GSList *)$list->next

end

end

document p_gslist_str

p_gslist_str <list>: Dumps the strings in a GSList

end

</code>

Add the above snippet into a file and load it into the GDB as follows:

<code>

(gdb) source /home/jjohnny/scripts/gdb/gslist.gdb

</code>

Now, anywhere you want to take a look in the GSList, simply break and

<code>

(gdb) p_gslist_str server_uid_list

$17 = 0×7fffd81101b0 “7666BC1E000000015870BD1E00000001″

$18 = 0×7fffd810e330 “7666BC1E000000015970BD1E00000001″

$19 = 0×7fffd810cbe0 “7666BC1E000000015C70BD1E00000001″

</code>

Simple scripts thus can save you a lot of time from adding or removing the debugging statements from your code. Now go ahead and create a suite of scripts to aid the library you are writing.

More cool developer tricks later. Have fun !

— End —

Thanks to Radhika for editing the article.

Btw when is Archer branch  (Python scripting) getting into GDB ? I’ve been using it a bit .

GDB

- Scripting

A good majority of novice programmers tend to use printf functions to trace function calls and to printout the debug data. This forces you to change the code and compile again and again. To eliminate these superfluous tasks from your day-to-day work, use GDB, the GNU Project Debugger. The GDB has facilities for scripting and helps in saving plenty of your time.
Tracing Function Calls
If you want to know whether a function is called or not, create a break point and write a simple script.
<code>
#Set the breakpoint
(gdb) b mapi_sync
Breakpoint 1 at 0×7fffd75f36e2: file camel-mapi-folder.c, line 741
#Tell GDB what to do when the breakpoint is reached
(gdb) commands
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just “end”.
> continue
> end
(gdb)
</code>
continue – Come out of break and continue
end – terminate command list
Run the program now. The GDB prints the function name when the breakpoint is hit and automatically continues running the program.
Breakpoint 1, mapi_sync (folder=0xc9c1a0, expunge=0, ex=0xf3a0c0) at camel-mapi-folder.c:741
741             CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (folder->parent_store);
Using the GDB Scripts for Analyzing the Data
Suppose that you have a singly-linked list that has strings in it. At some point, you might want to know the contents of the list. To do this, use the GDB scripting instead of adding the debug statements in your code to print out the data.
</code>
#Example for gslist traversal.
define p_gslist_str
set $list = ($arg0)
while ((GSList *)$list->next != 0)
p (char *)(GSList *)$list->data
set $list = (GSList *)$list->next
end
end
document p_gslist_str
p_gslist_str <list>: Dumps the strings in a GSList
end
</code>
Add the above snippet into a file and load it into the GDB as follows:
<code>
(gdb) source /home/jjohnny/scripts/gdb/gslist.gdb
</code>
Now, anywhere you want to take a look in the GSList, simply break
<code>
(gdb) p_gslist_str server_uid_list
$17 = 0×7fffd81101b0 “7666BC1E000000015870BD1E00000001″
$18 = 0×7fffd810e330 “7666BC1E000000015970BD1E00000001″
$19 = 0×7fffd810cbe0 “7666BC1E000000015C70BD1E00000001″
</code>
Simple scripts thus can save you a lot of time from adding or removing the debugging statements from your code.
Now go ahead and create a suite of scripts to aid the library you are writing.
More cool developer tricks later. Have fun !

April 7, 2009

Makespace – Plugin for GNOME Evolution

Filed under: CODE, GNOME, Programming, Tech, suse — Johnny @ 3:59 pm

I’ve written (incomplete) simple plugin for Evolution which provides a combo box + menu for switching folders. Now you can hide the sidebar. This really helps in freeing up some space in your screen and can have good vertical view layout. This would help computers with smaller screen size.

Screenshots :

makespace-thumbSidebar hidden. Small combo box in top left corner

makespace-expanded-thumb1

Switching folders

To try out this plugin / For more information :   http://www.johnnyjacob.org/makespace.html .

One other feature that I would like to have is simple folder bookmarks. Bookmarked folders would appear in the top of the menu (You don’t have to navigate all the way down in the menus)

Let me know what you think and if you would like to have any features put it down in the comments. :)

July 11, 2008

Evolution Exchange 2007 (MAPI) Provider : Changes in schedule and more.

Filed under: CODE, Evolution, GNOME, Programming, Thoughts, Work — Johnny @ 11:47 am

Code :

We have moved away from libmapi 0.7 to libmapi trunk (0.8 development) , so we can take advantage of the new APIs.

We will be constantly updating our code base to libmapi trunk.

http://www.go-evolution.org/MAPIProvider#Feature_Status

Currently :

Suman is busy in integrating meetings into evolution. (few more tasks left)

I’m currently working on finishing (completing) off the basic features in mailer and will move to optimizing the sync & more.

Schedules :

Sadly, we won’t be able to make it to Evolution 2.24 as we are late (details here). :( Meanwhile we will continue to provide pluggable packages and this will be available as a pluggable provider. 2.26 will have this.

Licensing :

Yay ! Very exciting day. Evolution licence change was announced by Michael Meeks in my talk this morning (Exchange, MAPI and Evolution) . Announce mail here!! .

Update 1 : GUADEC Talk available here

June 25, 2008

Got my openSUSE 11 boxed edition !

Filed under: Evolution, LIFE, Linux Fun, Programming, Work — Johnny @ 1:16 pm

:D . yay!



Cool !!

October 30, 2007

GIT – The `cool thing` in a developer’s toolbox

Filed under: CODE, Evolution, GNOME, Linux Fun, Programming, Tech, Work — Johnny @ 8:40 pm

I wish i had known GIT a few months back. It would have saved me form a lot of trouble (loosing half done work ..). Well this post is _not_ a (yet another) GIT tutorial.

Some of the workflows i like (and use) is something like this :

Interrupted workflow (taken from git-reset man page)
Suppose you are interrupted by an urgent fix request while you are in the middle of a large change. The files in your working tree are not in any shape to be committed yet, but you need to get to the other branch for a quick bugfix.
$ git checkout feature ;# you were working in "feature" branch and
$ work work work       ;# got interrupted
$ git commit -a -m 'snapshot WIP'                 (1)
$ git checkout master
$ fix fix fix
$ git commit ;# commit with real log
$ git checkout feature
$ git reset --soft HEAD^ ;# go back to WIP state  (2)
$ git reset                                       (3)

Isn’t that wonderful ! I was trying out svn + quilt. But very hard to manage.

Some resources :

My GIT Ref Card :

# Initialize a repo (like git init):
git-svn init http://svn.foo.org/project/trunk
# Fetch remote revisions:
git-svn fetch
# Create your own branch to hack on:
git checkout -b my-branch remotes/git-svn
# Merging in master.
git merge --squash foo-branch-name
# Do some work, and then commit your new changes to SVN, as well as
# automatically updating your working HEAD:
git-svn dcommit
# Something is committed to SVN, rebase the latest into your branch:
git-svn fetch && git rebase remotes/git-svn

GIT is fast (super fast) ! and git-svn helps you if you are _stuck_ with svn !

Now GIT has moved out of my ’staging area’ to everyday use. Yay!! I use it for GNOME/Evolution (and GNOME just moved to SVN a few months back ;-) )

September 24, 2007

In the NEWS : Attachment Reminder E-Plugin (Evolution Plugin)

Filed under: CODE, Evolution, GNOME, Linux Fun, Programming, Tech, Thoughts, Work — Johnny @ 12:53 pm

Note : Writing this post so that i don’t forget. ppl know very well about my memory. ;-)

After OpenSuSE’s HackWeek , Attachment Reminder made it to evolution/trunk and made it to Evolution 2.12.

People appreciated that and somebody (on irc) promised to send me some chocolates and bear (didn’t get it though!) :-) .. Even though code wise itz simple to write. Anyway … it made it to Novell Open Audio (PodCast) , OpenSuSE News :-) and GNOME 2.20 Release notes.

Links :

Now gotta improve that code. I Love working on GNOME !! :-)

July 11, 2007

CopyFS – Your personal file versioning system

Filed under: Linux Fun, Programming, Tech — Johnny @ 7:15 pm

There were times when you edit code or a document and wish that you could go back to the previous version. Yep ! Thatz one of my serious issues. So I take cron’d back up diffs which is not so straight forward. Even when doing that you could miss some versions. Revision Control System (svn , cvs , bzr … ) may be the solution, but again you have to manually write / save it to the repository (commit). So i was little frustrated and planned to write my own simple versioning filesystem using FUSE.

Googling led me to CopyFS. Its a filesystem in userland using FUSE. I’m currently running OpenSuSE 10.2 and it took a few minutes to download and get it running.

Quoting from CopyFs HomePage :

CopyFS aims to solve a common problem : given a directory, especially one
full of configuration files, or other files that one can modify, and which
can affect the functionning of a system, or of programs, that may be important
to other users (or to the user himself), how to be sure that a person
modifying the files will do a backup of the working version first ?

This filesystem solves the problem by making the whole process transparent,
automatically keeping versionned copies of all the changes done to file under
its control.

It also allows a user to select an old version of the files, for example to
repair a mistake, and allows him/her to continue edition from this point.

CopyFS is distributed under the terms of the GNU GPL.

Project page : http://freshmeat.net/projects/copyfs/

Home Page : http://n0x.org/copyfs/

There is a HowTo / Usage document on the CopyFS home page

There is a catch here . Currently When you save a file it maintains a full copy for each version. So diskspace will become a issue here. But I guess it’ll be fixed to maintain diffs ( deltas ) in which only the changes are saved and maintained.

Currently I dont have any data on performance. But I created test mount point and tried it out. So we have some storage data. Following are the data on-disk (copy-fs-storage-area) and copyfs (copy-fs-mounted )

jjohnny@trantor:~> du -h copy-fs-mounted/
18K

jjohnny@trantor:~/copy-fs-mounted> ll
total 16
-rwxr-xr-x 1 root root 9504 2007-07-11 23:32 a.out
-rw-r–r– 1 root root 85 2007-07-11 23:33 main.c
-rw-r–r– 1 root root 0 2007-07-11 23:30 test.txt

jjohnny@trantor:~/copy-fs-mounted> copyfs-fversion main.c
File main.c (‘*’ is active) :
v1.0 : -rw-r–r– root root 43 Wed 11 Jul 2007 11:31:51 PM IST
v2.0 : -rw-r–r– root root 73 Wed 11 Jul 2007 11:32:15 PM IST
v3.0 : -rw-r–r– root root 85 Wed 11 Jul 2007 11:33:35 PM IST [*]

jjohnny@trantor:~> du -h copy-fs-storage-area/
134K

jjohnny@trantor:~/copy-fs-storage-area> ls
00000001.4913 00000001..main.c.swp 00000002.4913 00000002.test.txt 00000003.test.txt metadata.4913 metadata..main.c.swp
00000001.a.out 00000001..main.c.swx 00000002.a.out 00000002.test.txt~ 00000004.4913 metadata.a.out metadata..main.c.swx
00000001..command-line.swp 00000001.test.txt 00000002..command-line.swp 00000002..test.txt.swp 00000004.a.out metadata..command-line.swp metadata.test.txt
00000001..command-line.swpx 00000001.test.txt~ 00000002.main.c 00000003.4913 00000004.test.txt metadata..command-line.swpx metadata.test.txt~
00000001.main.c 00000001..test.txt.swp 00000002.main.c~ 00000003.a.out dfl-meta.a.out metadata.main.c metadata..test.txt.swp
00000001.main.c~ 00000001..test.txt.swx 00000002..main.c.swp 00000003.main.c metadata. metadata.main.c~ metadata..test.txt.swx

Too many files !!. There is a modifed version of CopyFS available here : http://mattwork.potsdam.edu/projects/wiki/index.php/CopyFS

Still no diffs. Sounds like a good project to contribute to .. :-)

June 30, 2007

OpenSuSE HackWeek : Day 5 – Grammar Check Service for Desktop Apps

Filed under: Evolution, GNOME, Inspired, Programming, Tech, Work — Johnny @ 3:33 am

Awesome .. Had lot of fun (hacking). Learned a lot !!

This week I wrote more lines of code than ever :-D .. . The idea that i worked on wasn’t so big .. .. but they were fun to work with … Ate lot of junk food !!

I managed to get the grammar check service running (DBus Interface).. Got a plugin working for Evolution (partially .. the UI part is yet to be completed )

Idea @ http://idea.opensuse.org/content/ideas/grammar-check-serverservice-for-desktop-applications

I wish everyday is like this .. :-D

June 28, 2007

openSuSE HackWeek : Day 3 – Evolution Attachment Reminder

Filed under: Evolution, GNOME, Linux Fun, Programming, Tech, Work — Johnny @ 7:19 am

HackWeek Day 3 Update :

Idea is @ Evolution Plugin : Attachment Reminder

NOW : Working on Grammar check service for desktop applications

Yeeha !!

June 25, 2007

Novell unleashes hundreds of developers for SUSE Hack Week

Filed under: Evolution, GNOME, Linux Fun, Mono, Programming, Thoughts, Work — Johnny @ 10:21 am

Novell is setting its entire Linux engineering team loose to hack on whatever Linux or open source projects
interest them for the week of June 25 – 29. To make it easier for hackers to find and publicize their projects,
we’ve created an Idea Pool web site — http://idea.opensuse.org — where our ideas are shared and where we’ll post updates.

read more | digg story

Update :

Bangalore Hackers | Day – 1 Intro Video

January 27, 2007

/me stupid – listen to that little voice !!

Filed under: Linux Fun, Programming, Thoughts, iFolder — Johnny @ 12:39 pm

( Well … That little voice told me to check with POBox .. But i kept ignoring it. Anyway …)

I was Stuck with this weird Bug. I was not able to reproduce it consistently. But whenever the testing team tries it out, they get it in the first attempt. I knew that it had to be in the POBox code. but someow i never listened to that little voice. So i kept investigating the iFolderListStore HashTables. Got a lot of info abt the behaviour of the client from there.

Totally frusturated abt this bug ( one of the reason for no posts for 16 days). Anyway … this is how i solved the Bug ..

I created the StackTrace object and printed it out. within 60 seconds , the bug was located and killed.

StackTrace st = new StrackTrace();

Console.WriteLine (st.ToString());

/me relieved.

Well now kill some more bugzzz … the hunt is on ..

December 15, 2006

Bug in December because of Missing May

Filed under: Linux Fun, Programming, Tech — Johnny @ 5:50 pm

I came across this funny bug. Therez a simple mapping function in which the Month number (int) is converted to Month Name (string) . In the array “May” was missing. So this bug was exposed only in december as the mapping function tries to get a element that was not there ..
Because of this a thread went crazy and overloaded the system and causing timouts on other threads.

Fixed simple bugs today ..Had fun asusual.. But more work to be done in discovery.

Older Posts »

Blog at WordPress.com.