GDB Scripting : A short article for a internal magazine
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 0x7fffd75f36e2: 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 = 0x7fffd81101b0 “7666BC1E000000015870BD1E00000001”
$18 = 0x7fffd810e330 “7666BC1E000000015970BD1E00000001”
$19 = 0x7fffd810cbe0 “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
On wlan and browser authenticated internet
Nowadays more and more organisations will use an intercepting proxy to give you access to internet. Last week I had the pleasure to use again such a system. To use is an exaggeration as my opensuse 11.1 box with kde4.3 rc1 connected to the wireless network (network manager) but refused to give me access to the authentication page in the browser.
I did all the decent tests that my brain and time allowed me. Checked the ip, checked gateway and checked dns. They seemed ok.
To make frustration even bigger I was able to connect to th very same network with a kde4.3 beta1.
openSUSE 11.1 on PS3
Woohoo ! After a long delays and issues (in the last few days) I’ve managed to install openSUSE 11.1 in my PS3. Running a full blown desktop is very sluggish. Reminds me of my first computer (amdk6 500mhz). Some screenies :
Now onto get the Cell SDK running … Synergetic Processing Elements (SPE) here i come !
Update
Two main goals fulfilled:
- Met and talked to the Redhat security folks, who I had never met before in RL. All the Opensource security guys cooperate and work together friendly, it was nice meeting them.
- Hold another talk on Wine in front of a full hall again. Should have shown demos perhaps. Thanks for listening! me in front and the audience. Also on Flickr (follow stream right).
Otherwise lots of work and business as usual, just more of it ... tiring.
Also saw my newborn niece for the first time 2 weeks ago while visiting parents. And yummy strawberry pie.
Otherwise I rewrote the libgphoto2 object handling on the trainride and committed it. It allows greater flexibility in dynamic loading of the objectinformation from the cameras, on-demand loading, and features binary search. Still not happy with some of the datastructures.
See you in Gran Canaria!
- Brad set up a Snowy mailing list, and a Snowy product in GNOME bugzilla.
- Og Maciel has begun work on a virtual appliance for Snowy, and in the process of doing so has helped to unearth some bugs (our first mailing list activity). Thanks Og!
- Ryan Paul of Ars Technica fame as written a great article about the current state of Snowy.
- Rodrigo Moya and Stuart Langridge have continued to help us refine our REST API, as they work on implementing it for Ubuntu One. Stuart contributed patches to upgrade our authentication from HTTP basic to OAuth, and I finally pushed it upstream, along with corresponding support in Tomboy (based on some handy dandy code from Bojan Rajkovic). I am really grateful for their help!
- We have our first localization! Thanks to Viatcheslav Ivanov for diving in.
- The Midgard project has implemented our REST API as well, and intends to add support to Conboy (Tomboy ported to C on Maemo) as well.
.NET/Mono Code Camp in Tarragona, Spain

It's official: there will be a .NET/Mono Code Camp in Spain in October. The proposal was made some months ago by CatDotNet, a local .NET user group. Several other .NET user groups quickly joined. The initial idea was to do a traditional Microsoft.NET Code Camp, but I though it would be a good chance of putting together .NET and Mono developers, since after all we have a lot to share. Everybody thought this was an awesome idea.
This will be a good chance for learning and sharing knowledge about .NET and Mono, but I'd also like it to be a meeting point for the Spanish Mono community. I'll be there giving some talks, and I hope other Mono hackers can come too. If you want to propose a talk, or you want to contribute please join the official forum.
More info about the Code Camp in the official web site: www.codecamp.es.
BEEP, BEEP, BEEP
On Brasero we introduced a couple of nice features (from Philippe) what will be available on 2.28.x stable releases such as:
-
Use Brasero as a single instance application using libunique
- Split burning backend into a new library called libbrasero-burn
- Split some utilities into a new library called libbrasero-utils
- Data spanning
- Added NetBSD support to libbrasero-media
- New UI to show a more intuitive disc space- Lot's and lot's of bug fixes.
Brasero is also on GSOC but i'll leave it to our student Alexey to blog and show his progress on his great work!
QJson at Gran Canaria Desktop Summit
Now that I have booked both the flights and the hotel it’s official: I’ll attend the Gran Canaria Desktop Summit.
On Thursday 9th July I’ll give a BoF about QJson.
During the talk I will show:
- the advantages brought by QJson.
- the usage of QJson.
- some real programs using QJson.
See you soon!

Bulk conversion
Before continuing the “API saga” I needed to have an infrastructure to be able to load a bulk of documents and save them using a certain filter. For me the reason was mainly for testing purposes, however its very convenient for “bulk conversion” too.
The syntax is:
./soffice.bin -bulk [targetDir]/[filterName].[targetExt] [dir] ... [dir]
E.g. the following call will convert all *.odt documents from /home/freuter/tmp/ to “/home/freuter/tmp/out/*.doc” documents using the “MS Word 97” filter:
./soffice.bin -bulk "/home/freuter/tmp/out/MS Word 97.doc" /home/freuter/tmp/*.odt
This command will convert all ~/tmp/*.doc documents to ~/tmp/out/*.odt using the ODF converter:
./soffice.bin -bulk ~/tmp/out/writer8.odt ~/tmp/*.doc
And finally this call will convert all ~/tmp/*.doc document to ~/tmp/out/*.pdf PDF document using the “ writer_pdf_Export” filter:
./soffice.bin -bulk ~/tmp/out/writer_pdf_Export.pdf ~/tmp/*.doc
The patch is here. I additionally fixed a bug in the m_nRequestCount logic and I enabled it in the [Experimental] section.
WikiHome has been setup
Again thanks to my mentor, Stephen Shaw for the final push yesterday. The wiki is minimal now, but I hope it'll grow like all Wiki do :)
The changelog is on its way too.
Btw two good news-
1. Netbeans 6.7 has released which promises some good collaborative features.
2. I've set up Google Analytic for the http://code.google.com/p/vaani
