Archive

Archive for the ‘Tips’ Category

Be the Ocean! – Inspiring Incident quoted from Chetan Bhagat’s blog

November 3rd, 2009 Sarath Comments

In a recent blog post, Chetan Bhagath shared his updates on his new book “2 States”, new move “3 Idiots” based on his First and popular novel “Five Point Someone” and few more.

There was nothing quite surprising things as I am following him on twitter (@chetan_bhagat)and getting frequent updates. But the end of the post, it was just amazing. Here it is…

 

I want to end by sharing a small incident. The night before the release of 2 States, I was super tense. I went to the ISKCON temple in Chowpatty and met His Holiness Radhanath Swami, an American gentleman who moved to India several decades ago and devoted his life to serve God. I told him I couldn’t sleep because of the anxiety over the fact that there will be a million judgments on my work, both positive and negative, in the coming days. He told me this:

“Imagine there is a puddle. When it rains, the puddle is filled with water. When it doesn’t, the puddle dries up. Now compare that to the ocean. The ocean is so deep, it doesn’t matter if it rains above or it is dry weather. Your inner depth should be as much as the ocean, so you are not fazed by the external praise or criticism. For that, you must truly do work that is meaningful to you, have love in your heart for others and help people. And when you achieve inner depth, the external world’s rewards won’t matter to you as much.”

I don’t think I am as deep as the ocean yet. But I am trying. Meanwhile, I just felt I will share this with you, so you may apply it in some aspects of your life. Whatever happens outside, it doesn’t matter as much if there is a calm stillness in you.

Excellent! Hi books are always cool and I love to read it and moreover he inspires through this quick blog posts/writing like this! Great man. I respect you!

Visual Studio 2010 – Conditional breakpoints using String Comparison Functions (C/C++)

November 3rd, 2009 Sarath Comments

All we’re fond of conditional break points if we need to execute the program until some specific condition exists. We usually give numerical expressions to give conditional break points. If you don’t know about conditional break points, just have a look at MSDN documentation. or this one.

Now the C/C++ programmers are blessed with break with string conditions.

Just put a breakpoint in your source code and right click on that choose “Condition” to see the following window appear. You can give string comparison routines to set the break point.

image

Once you start debugging, you can see the break point hit on the condition you’ve given

image

Visual Studio Beta 2 currently supports the following functions (Taken from Habib Heydarian’s blog)

strlen, wcslen, _tcslen, strnlen, wcsnlen, _tcsnlen, strcmp, wcscmp, _tcscmp, stricmp, wcsicmp, _tcsicmp, strncmp, wcsncmp, _tcsncmp,strnicmp, wcsnicmp,_tcsnicmp,_stricmp, _wcsicmp, _strnicmp, _wcsnicmp

This may be changed or updated in the final release. Anyway enjoy your breakpoints!

Visual Studio 2010 – Code Metrics calculation

November 2nd, 2009 Sarath Comments

Visual Studio 2010 provides a new feature to calculate various the code metrics. Sadly this options are only available for Managed projects. Sorry native developers!

It allows to calculate the follow matrices of your project

  • Maintainability index
  • Cyclomatic Complexity
  • Depth of Inheritance
  • Class Coupling
  • Lines of code

Most of us mainly interested lines of code (LOC) as various other calculations in the project life cycle calculated based on this.

To calculate Code matrix, Right click on the Solution and choose “Calculate Code Metrics”

image

As you’re seeing above, you can see the information for the entire project and also for the individual items.

It’s possible to filter the results based on given criteria as you’re seeing below.

image

The coolest things is that, you can export these result to an excel sheet without any pain. Just right click on the item and “Open Selection in Microsoft Excel” as you’re seeing below

image

You can get it opened in the excel. See, the filters are automatically applied for header items!

image

To know more check MSDN website.

Firefox 3.6 exploiting the features of Windows 7

October 31st, 2009 Sarath Comments

Firefox has released the Firefox 3.6 beta 1 for developer preview. It Visually doesn’t feature any changes from version 3.5. But it features integration with Windows 7 Taskbar and also Windows 7 Style switching of tabs using Ctrl + Tab. Yes it’s able to display the tabs preview.

Download it here.

(Click on this, if you need a Direct link to Firefox 3.6 Beta 1 English for Windows)

Windows 7 Like Tab Preview

 

Firefox 3.6 ca now display tab previews like Windows 7(the very same way of Alt+Tab in Windows 7).

This feature is disabled by default in the beta version.

type about:config in your address bar and on the appearing page, search for browser.ctrlTabPreviews. Set this as true.

image

OK now you’re done. Start Exploring

You can select the required tabs using mouse as well by holiding down the Ctrl+Tab key.

image

What if you’ve too may tabs? Ctrl + Shift + Tab will show up all tabs in the firefox window. Alternatively you can do this by holding down Ctrl + Tab and Click on “Show All Tabs” displayed in the very same windows

image

This preview window display features a search box where you can quickly search for the required tab if too many tabs are open. As this Shift key assigned with Ctrl+Tab to show up whole tabs, I’m sadly missing shortcut I previously used to traverse back in order.

image

You can also close the tabs if necessary in this view.

 

Windows 7 Taskbar Integration

 

On hovering the taskbar icon of firefox, you can see the preview of tabs in the aero peek window. To enjoy this feature you will have to enable aero theme in you Windows 7.

image

On hovering the mouse over the windows displayed in the peek view, surely you can peek to see the window. It’s the real Windows 7 peek feature. You can also close the tabs if necessary in this view.

image

If you’ve too many tabs open, then it will be displayed as stacked list as your seeing above.

Cool eh! This is a quick post on my first look, if you find something really cool, please do share with me in twitter, facebook, or as a comment in this blog.

Visual Studio 2010 – Pin the watch box in source window

October 27th, 2009 Sarath Comments

To know the content of a particular variable during debugging, what we usually do is add it to the watch window or just hover the mouse over it and see the values as tool tip like window.

image

With Visual Studio 2010 You can pin this watch window in the source file like a notes. Whenever the data is changed, you can watch it instantly in the source file itself. Cool eh? See it here.

Start your Debugging

As you’re seeing above, hover the mouse on the required variable. Click on the pin button on the right end.

 

image

You can see close button to close the watch unpin button and expand button. You can also add the comments as you’re seeing above.

Once you step through debugging process, you can see this changing as below. if the data is updated, it will be displayed in red color.

image

 

It’s really cool when you’re watching the arrays.

image

You can selectively pin the array items and if necessary you can see the entire array as usual.

This can be moved from the current line of display. The blue color pin on the left side of the source window will move along and on hovering, it will display to which line this watch is attached with.

The interesting thing is that Visual Studio can remember your pins and can restore when you start over the debugging.

What the drawback I found in this, we can’t specify symbols for watch variables in this window. If it’s there, we do simple memory analysis and other handy display options easily.

This is a simple use case of this feature. It will be very handy in many critical debugging situations. For e.g. while working with multiple threads etc…

Visual Studio – Using wildcard characters in the symbol pattern for a breakpoint

October 26th, 2009 Sarath Comments

If you even came across WinDBG, you might have experienced using “bm” command for setting one more breakpoints based on the pattern we’re specifying.

For e.g if we put break point like bm Create*, the debugger will put the break points in the function with starts with Create.

The similar feature is available in Visual Studio as well. As an example, consider the following class ‘CPerson’

image

and suppose if we want to set the break points on all set function, we can do as do as follows.

Take New Break Point from Debug Menu

image

Give your wild characters to break at desired function

11

Once you start debugging you can see that break-points appears as specified…

image

Cool isn’t it?

How to enable DML support in WinDBG? (interactive debugger output with hyperlinks)

October 23rd, 2009 Sarath Comments

As everyone knows WinDBG is the most powerful debugger in Windows. But few people find it’s difficult because it’s not friendly like Visual Studio. Only raw text output in the debugger console. (of course thread,process,local watch windows etc. are available) but still its interesting if you can access few quick relevant information with a single click? WinDBG supports embedding hyperlinks in the command output with DML(Debugger Markup language).

As an example, if you faced some crash issues with some wrong version of DLL, probably you might be needed to check the version of the DLL loaded into process’s address space.

lm is the command used to display list the loaded modules. Ok just try with lmD

image

You can see that on clicking the hyperlink shdocvw windbg send the command hidden in that link (lmDvmshdocvw – lm (list modules) D(DML) m(pattern)module name) and displays details of the corresponding DLL. The behavior changes according to the context and implementation of commands. For e.g if kb displays the call stack and the frame numbers will be enabled with DML links.On clicking the frame numbers, it jumps to corresponding stack frame in the current call stack. You can see what’s the command going to be executed at status bar by hovering the mouse over the link.

Not all commands are implemented DML support. You can turn on/off DML support globally according to your convenience. Once the DML support enabled globally, WinDBG will automatically calls the DML version of the commands if available.

You can turn on DML support by – .prefer_dml 1

You can turn this feature off by – .prefer_dml 0

Once after you enable DML mode, if you give lm command, you will get the same output of lmD. Try it with other commands as well. Happy debugging!

Categories: Debugging, Tips Tags: , , , ,

An open letter to micromanagers – Another classic article from scott berkun

October 12th, 2009 Sarath Comments

In his recent article, Scott Berkun reloaded his shot gun against micromanagers. Here I am quoting some best part of his open letter to micromanagers. You may why should I post it here. Because I hate micromanagement, absolute waste of time, energy, full of desperation, de-motivation, unbalanced team, poor culture, more pressure… Even I’ve seen some managers spoiling good culture and harmony in the team by “pressurizing the team”. Nobody gains from this.

67295.strip[1]

Image courteously from dilbert.com

 

Owners of thoroughbreds never stop their horses during a race, every ten seconds, to remind  the horse and jockey how to run, where the finish line is, or that it’d be a good idea to finish first. Why? It would slow them down. Only an idiot would do this.

 

If you’re a manager, you must assume you have thoroughbreds working for you. Your job is to give them what they need to win their respective races, agreeing with them on the goal  and rewards, but then getting the hell out of the way. Until they start jumping fences or attacking other horses, you have to let them run their race.

Even if you are 30% better at a task than someone who works for you, the time it takes for you to check on them every few hours, and demand approvals over trivial decisions, costs more in lost morale, passion for work, and destruction of self-respect among your staff than the 30% you think you’re adding.  No one works well if they feel they are being treated like an idiot child. Having two people involved in work that should only require one wastes everyone’s time.

 

But if you are in fact a micromanager, you started over-managing the day you started. You have  no idea of the potential of the people who work for you

 

An easy test of micromanagement is to let your team know you are confident in their ability to do their job and offer, if they wish, that you will be less involved in their day to day work to give them more room to perform. Tell them you are available if they need you, but otherwise you will put some of your attention elsewhere. See what happens. Hold your tongue. Don’t demand to review that email. Don’t insist on regulating who can meet with who. Take one small step backward and see what happens.

Your best employees will be happier and more productive, giving you new energy to invest in the rest of your work or more afternoons where you can head home early. Some of your team might surprise you, and thrive with more autonomy. And for those who fail to improve or make mistakes, you’ve lost nothing, as you can step back in where it’s actually needed.

 

Perhaps you’re afraid to admit your people can function quite well without your approval or input on every stupid little thing. Or it could be you are proof of the peter principle, and would be happier and more useful if you stopped managing and worked solo.

 

Good managers are brave, and generous with trust in their people. The want them to mature in their judgment and grow in their skills, preferring to err on the side of trusting too much than trusting too little. They take pleasure in letting go and giving power away to their staff, accepting that when someone who works for them shines, they shine too.

And the best part

Hugs and kisses,

Signed,

The people you are micromanaging

How to Debug Child Process Using WinDBG/Visual Studio?

September 20th, 2009 Sarath Comments

Have you ever came across a situation where you need to debug a child process created by your application or external application?

Usually when we need to debug an application (process) usually we’ll be attaching the particular process to debugger by executing in debug mode from the debugger itself or use “Attach process” option provided by debugger.

image 

You can debug the processes where you’ve the right debug privileges. But suppose if you’re working in a system where your application is launched by someone else and you’re facing some catastrophic errors in some critical point of execution where you’ve no chance to attach it to debugger. (e.g during startup)

In this situation usually developers modify the source code if the want to debug and put some delay, or call “DebugBreak” API to debug the program. But in some situations this is also not practical. So what we’ve to do?

We’ve two debuggers that developers use in very common. Visual Studio Debugger is one of the most popular debugger in Windows. Okay before talking about Visual Studio I’d show how we could achieve this with WinDBG, the most powerful debugger under Windows. But it’s not that flexible like Visual Studio. It’s a beast! with all power to rule the process :)

WinDBG Way

I’ve created a small program which will be crashing in the startup itself. I am not going to write a launcher to create the process, I will do that from the command line. The steps to debug the child process are

1. Launch the parent application which is going to create the desired process.

2. Attach the parent process to WinDBG (Hope you’re all set with your symbol server and source file paths for better debugging)

3. Enable Child Process debugging by giving command “.childdebg 1”  (pass 0 if you want to disable it. See the documentation)

4. Resume the process by hitting “Go” and let the parent process to create the child process.

5. You can see that WinDBG will “Break In” when the new process is created.

6. Now you can start debugging by setting Break points, watch, etc…

Visual Studio Ways

The previous method was not at all painful no? But Visual Studio doesn’t  natively support debugging multiple process. According John Robbins, it requires a serious architectural change in Visual Studio. There’s no straight way to do this. There two known method to do this.

Using Image File Execution Option with Visual Studio

Setup:

   1. Run regedit.exe
   2. Goto HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
   3. Create a new key for your exe (example: foo.exe)
   4. Create a new string value under your exe. The name of the string value is ‘Debugger’, and the value is ‘vsjitdebugger.exe’

Here is a sample registry script to do this: (save as .reg file after changing sample.exe to your application’s name)

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sample.exe]
"Debugger"="vsjitdebugger.exe"

The above method is exploiting one of native debugging feature provided by Windows. Ensure that the modification at registry is reverted back once you finish with debugging. Otherwise whenever the application is started, it will automatically starts with Visual Studio Debugger. See this blog entry for more details

Google Chrome Debug Macros

The people at Google (or those who contributed) are so smart and they’ve created few Visual Studio Macros to enable you to debug the child process. They found in some situations the Image File Execution Option doesn’t work well. And they’ve written some efficient macros to debug the child processes using Visual Studio.

You can see the macros and how to debug article in Chrome website.

Happy Debugging!

Tools – Paint .NET is an professional Open source image and photo editor

September 7th, 2009 Sarath Comments

When people thinks about photo and image editing, only one name first comes to mind (at least for me), It’s Adobe Photoshop. But it’s heavy, pricey commercial product. What if you can get major of it’s functionality at free of cost under Windows? Cool eh? Here’s the solution Paint .NET written completely in Microsoft .NET

image

Paint.NET is free image and photo editing software for computers that run Windows. It features an intuitive and innovative user interface with support for layers, unlimited undo, special effects, and a wide variety of useful and powerful tools. An active and growing online community provides friendly help, tutorials, andplugins.

It started development as an undergraduate college senior design project mentored by Microsoft, and is currently being maintained by some of the alumni that originally worked on it. Originally intended as a free replacement for the Microsoft Paint software that comes with Windows, it has grown into a powerful yet simple image and photo editor tool. It has been compared to other digital photo editing software packages such as Adobe® Photoshop®, Corel®Paint Shop Pro®, Microsoft Photo Editor, and The GIMP.

 

It boasts these major features

  • Simple, intuitive, and innovative user interface
  • Layers
  • Active Online Community
  • Frequently Updated (updates every 4-8 weeks)
  • Special Effects
  • Powerful Tools – Splines, Curves, Bezier, magic wand, clone stamp, gradient etc…
  • Unlimited History
  • Free!
    Other variant you can try for free is The GIMP. It’s also an excellent photo editing tool.