Archive for September, 2009

How to Debug Child Process Using WinDBG/Visual Studio?

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

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.

Tools: Notepad++ is the powerful text editor you need

Fed up with with the normal notepad of Windows? Or are you want some good flexible and powerful text editor? Here it’s Notepad++. The features are truly amazing @ free of cost.

Besides the excellent editing features( just check it’s menu, you will get amazed) Notepad++ features are

Syntax Highlighting and Syntax Folding

WYSIWYG

If you have a colour printer, print your source code (or whatever you want) in colour.
User Defined Syntax Highlighting

It allows user to define his own language : not only the syntax highlighting keywords, but also the syntax folding keywords, comment keywords and the operators.
Auto-completion

For most supported languages, user can make his/her own API list (or download the api files from dowload section). Once the api file is ready, type Ctrl+Space to launch this action (see screenshot).
Multi-Document
Multi-View
Regular Expression Search/Replace supported

Full Drag ‘N’ Drop supported

You can open a document by drag & drop. You can also move your document from a position (or even a view) to another by drag & drop.
Dynamic position of Views

The user can set the position of the views dynamically (only in 2 views mode : the splitter can be set in horizontal or in vertical)

File Status Auto-detection

Zoom in and zoom out

Multi-Language environment supported

Bookmark

Brace and Indent guideline Highlighting

When the caret stay beside of one of those symbol { } [ ] ( ) , the symbol beside of caret and its symmetric opposite symbol will be highlighted, as well as the indent guideline (if any) in order to locate the block more easily.

Macro recording and playback

You can save several macros and edit their keyboard shorcuts for the next use.

image

Another hidden gem in this editor is the build in (Okay, a built in extension) command window. Which is replica of window cmd.exe. This was one of the most helpful one for me when I was working with clearcase server. I was encountering with make files and C++ source code all there was no Visual Studio project file to build. either I’ve to create a dummy project and add these files to Visual Studio and create build commands as the “External tools” option in Visual Studio. But I was truly comfortable with the folder view (I could not see it in the latest version) to manage my files as solution explorer and use the command line to build the project. It was simply awesome and comfortable. Also I don’t need to pay too much memory for Visual Studio as I can do same things here with a lightweight tool. Also it’s integrated with Context menu to easily open the required documents.

It supports plugins and some handy plugins like compare , FTP synchronize etc.

Have a try – Download it here

Some other powerful text editors you can try but I feel this is really comfortable.

“Like this” – Faces severe criticisms. Just think before use it

Friendfeed is a cool aggregation service which took aggregates many social media websites. They’ve introduced the service with a cool new feature called “Like this”. You can press the like button to mark your emotions towards the shared content. Finally the number of people liked the story and comments give every author a good satisfaction and inspiration to share more! Of course believe me.

image

Facebook also introduced the “Like” option to the shared contents inspired from friendfeed. but recently I’ve noticed that, lot of good, bad news are happening around but without having any common sense or understanding people are “Liking Stories” (even myself accidently liked a sad story, which I never supposed to").

This came to my attention when Barack Obama’s page posted the Passing Away for Senator Kennedy. You can see 38,847 people like this story so far.

image 

It surely doesn’t make any sense. It’s a great loss for a nation. People may clicking the like button for showing the interest to the stories or may be just because the news was shared by a “The President” who’s a celebrity on the same platform. It’s method to convey your feeling towards what’s he shared.

Another story is shared by the Indian Army. It’s again the feelings of a nation, a sad news shared by the protectors of great India. But still lot of people liked this story (I accidently clicked by misunderstanding the trooper with trespasser. Anyway I unlike it quickly) .

image

I think facebook (or any other service providing this feature) should provide an option to control this by the author itself. Because social networks are not simply automated robots. Ultimately it aims people and Sharing their thoughts and information. The services should be flexible and apt to make good sense and value to their users stories and emotions.

Tools: Camstudio is a freeware to capture your screen

Here’s the another one in the tools series. Suppose if you’re preparing for a hands-on demo on your product, or want to prepare some cool tutorials like this guy because you just luv2help.  What’s the easiest and cost effective way to capture high resolution vide of your desktop? Camstudio is a free screen recording (capturing) Software. Don’t think about paying some bucks to get the license, it’s absolutely free and Open Source software.

CamStudio is able to record all screen and audio activity on your computer and create industry-standard AVI video files and using its built-in SWF Producer can turn those AVIs into lean, mean, bandwidth-friendly Streaming Flash videos (SWFs)

image 

CamStudio can also add high-quality, anti-aliased (no jagged edges) screen captions to your recordings in seconds and with the unique Video Annotation feature you can even personalise your videos by including a webcam movie of yourself "picture-in-picture" over your desktop.

And if all that wasn’t enough, CamStudio also comes with its own Lossless Codec that produces crystal clear results with a much smaller filesize compared with other more popular codecs, like Microsoft Video 1.

You have total control over the output of your video: you can choose to use custom cursors, to record the whole screen or just a section of it and can reduce or increase the quality of the recording depending on if you want smaller videos (for emailing to people, for instance) or you can have "best quality" ones for burning onto CD/DVD.

Enjoy the cool tools :)