DebuggerVisualizers – Boost C++ Libraries has nice introduction to custom Visual Studio debugger visualizers.
Archive for the 'Debugging' Category
Security: Banned C Functions
memcpy() Is Going to Be Banned article at InfoQ talks about dangers of memcpy (and other memory/string related functions). Microsoft has more in-depth explanations as well as the list of Security Development Lifecycle (SDL) Banned Function Calls at MSDN. Also available from Microsoft is banned.h header file that, once included, will produce warnings for all the banned functions. Alternatively one can use the /W4-C4996 compiler option.
How to Debug Crashes and Hangs
How to Debug Crashes and Hangs article by Kirill Osenkov [MSFT] summarizes useful things about debugging in Visual Studio.
SciTech .NET Memory Profiler
Schitech .NET Memory Profiler has plenty of features that will make your life easier when you try to fight memory-related problems in your .NET applications. Nice touch – it is able to track unmanaged resource usage (e.g. HWND, HBITMAP and unmanaged memory) and present it together with the .NET memory information. Just this single feature alone saved my day when I had to find unmanaged memory leak in the mixed-mode .NET app (C# and C++), and all other profilers just $@% badly – I had the bug fixed in less than one hour after I downloaded the trial version of the tool (that 1 our included “learning curve” as well!!!). Recommend!
Crack.NET
Crack.NET is a runtime debugging and scripting tool that gives you access to the internals of a WPF or Windows Forms application running on your computer. It nicely rounds the Snoop and Mole for Visual Studio group, as it allows you to “walk” the managed heap of another .NET application, and inspect all values on all objects and types. In addition, you are able to write and execute IronPython scripts that run inside the target application.
Josh Smith is the author, and has a nice introductory page for the tool.
Microsoft DevLabs
On the DevLabs site you read: “Any truly remarkable software innovation that introduces a paradigm shift is based on solid inventive ideas. But it also needs discussion, trial, collaboration, and a critical eye. Explore the projects that we are experimenting with in our labs, and let us know if they inspire you.”
Currently there are four projects there:
- Popfly, a “fun, easy way to build and share mashups, gadgets, games, Web pages, and applications”
- Small Basic, a “simple and easy programming language with a friendly environment that provides a cool and fun way of learning programming”
- Pex, an “intelligent assistant to the programmer”
- CHESS, a “concurrency testing tool for finding and reproducing concurrency Heisenbugs in your code. CHESS can find assertion violations, deadlocks, livelocks, data-races, and memory-model errors. CHESS works both for managed and for unmanaged code”
Found this trick in the Jeffrey Richter’s Windows via C/C++ book (in Chapter 1). Visual Studio debugger has a very useful feature – it can monitor the thread’s last error code. You can display this error code together with its text description in the Watch window by typing $err,hr. In case some API call fails, the Watch window will show the error code (the one that would be returned by the GetLastError function). Thanks to the ,hr qualifier, the Watch window shows the error description as well (the string mentioned in the WinError.h header file for the occured error code).
Debugging Attributes
Improve your debugging: Debugging Attributes to make your life easier post talkes about several interesting attributes that make debugging easier - DebuggerStepThroughAttribute, DebuggerNonUserCodeAttrbute, DebuggerDisplayAttribute, and DebuggerBrowsableAttribute. Really nice.
ACorns.Debugging – The .Net Deadlock Detector is able to detect and report a deadlock inside a running .Net process in a production environment (without a debugging tool like Visual Studio) or even out of a memory dump.
Mocking Frameworks
Today was Sunday and I took a “day-off” from the project :) and decided to look into the world of mocking… Before I start, I should admit, that while I understand (or at least I hope so) principles and benefits of Test Driven Development (TDD) and mocking, I have never used them in my work. There are a few reasons for this:
- Currently I am developing a digital TV feature and infrastructure for an advanced set-top box (running on Windows XP Embedded), and simply do not get how I can use TDD and mocking with needs like processing 25-40+ megabit transport streams and doing something useful with them. The code that I would be able to test using TDD and mocking is way too simple for this, and the code I perhaps would be interested in testing automatically, is not really “testable” for the abovementioned reasons.
- Unit testing and mocking frameworks for C++ and C++/CLI, the two languages I use 80% of my time nowadays, are quite “anemic” at best, and it is really no fun to use anything like those frameworks.
- On top of that, to be honest, I never felt the need to use TDD and mocking in my own practice. Retrospectively thinking, I do not remember any project where TDD or mocking would substantially improve the quality of my code and/or reduce the number of defects (although I definitely know cases where it would not harm to use TDD and mocking) – I am not “boosting” myself, but there is an order of magnitude difference in performance among developers, and even bigger difference in quality of the code they write. In fact, I think TDD and mocks were invented to somehow compensate for this difference.
- I somehow have a weird feeling about adding to my project as much testing/mocking code as there is “normal” code. And then, I am definitely not “purist” but rather “pragmatic” – I agree that it might be wise to have unit testing/mocking in some parts of the system, but definitely not everywhere.
So, now that I explained my background, I am ready to continue. After spending quite much time on Google and other development-related sites I managed to narrow the list of available .NET mocking frameworks down to three: Typemock Isolator, Rhino Mocks, and Moq. All frameworks support .NET 3.5 (Rhino has it in version 3.5 RC).
Typemock is definitely the most powerful of these frameworks, but this property of Typemock is often mentioned in the cons section. The argument is, that while allowing mocking everything and everywhere, Typemock is not really helping developers to design loosely coupled code – for example, you do not have to “resort” to Inversion of Control (IoC) principle to use Typemock. I think Typemock is as its best when you try to introduce TDD and mocking into legacy project to get better understanding of that code and to have easier time modifying it. The framework has a free version, but to get e.g. its Natural Mocks feature (allowing to define expectations by recording them in a type-safe manner) you will have to cash out 349€ for Professional or 449€ for Enterprise editions.
Rhino Mocks is likely the most used .NET mocking framework. The framework looks quite powerful, is type-safe, supports generics, and is actively developed.
Then, there is Moq – a newcomer to the scene. Some people criticize it for being too simple. Some accuse it of not being “pure”. From what I have seen today, I should say that I liked it most (second being Rhino). It has rather elegant type-safe API built around lambda expressions. This API allows writing shorter and more concise code than Rhino does. What sets Moq apart from other mocking frameworks is that it is not using the record/playback model.
I will definitely give TDD and mocking a try on my next project. On the other hand, my C++ part of our current project is much smaller than our C#/.NET 3.5/WPF code-base, so I might introduce mocking into our current project if there will be not too big “opposition” from the development team and other project stakeholders – we are under heavy time pressure now, and adding some new concepts at this moment will probably introduce significant delays. I think that the framework of choice will be Moq, although it is just a gut-feeling at this moment.
And here is the list of interesting blogs/sites about the mocking:
- TDD : Introduction to Moq by Stephen Walther
- Moq: Linq, Lambdas and Predicates applied to Mock Objects by Scott Hanselman
- kzu Weblog by Daniel Cazzulino, the author of Moq
- Comparing Moq to Rhino Mocks by Phil Haack
- Ayende @ Rahien blog by Oren Eini, the author of Rhino
- Inversion of Control Containers and the Dependency Injection Pattern by Martin Fowler
- Mock Objects – Steve Freeman and Nat Pryce are writing a book, let’s call it “Growing Object-Oriented Software, Guided by Tests”. So far two chapters are available online.
By accident found Google Testing Blog. Not bad.
One of the articles is called How to Write 3v1L, Untestable Code – a must-read for newbie (and not newbie too!) programmers. Not on this blog, but nevertheless related article is How To Write Unmaintainable Code by Roedy Green – very serious collection of bad things despite it is very funny to read.
Hardware Breakpoints
Toggle hardware data/read/execute breakpoints programmatically and Hardware breakpoints articles show how to use hardware breakpoints. Source code is available from both places.
Wintellect’s John Robbins’ Blog
Related to my previous Wintellect post: Wintellect’s John Robbins has an excellent blog filled with… well, a bit of everything, including Debugger Settings Visual Studio Add In, Visual Studio tips, info about interesting tools, etc.
.NET Mass Downloader
.NET Mass Downloader allows to download .NET Framework source code in batch mode enabling offline debugging of .NET Framework in VisualStudio (both 2005 and 2008). Usage is explained in the article on CodeProject.
Debuggers and Disassemblers
SmidgeonSoft provides free Windows programming utilities, e.g. PEBrowse Professional Interactive (native and managed code debugger), PEBrowse Professional (PE file viewer/disassembler), PEBrowse Crash-Dump Analyzer, TopToBottomNT (component manager/system explorer), NTDevices (driver/device object explorer), NTObjects (kernel/executive object explorer).
OllyDbg – free (shareware, but can be used for free) 32-bit assembler level analysing debugger for Windows. List of features is really impressive.
Memory Leaks in WPF
Finding Memory Leaks in WPF-based applications and Memory Leaks in WPF based applications – Blog Update articles from the WPF Performance blog.
Well, not really WPF related, but still…
- 2008.01.07 Mole For Visual Studio – a really cool Visual Studio visualizer provided by Mole Team (including source code) and allowing developers to view data and drill to properties of that data as well as editing those. Targets primarily WPF/XAML, but other project types are supported too. MUST!
- Windows Server 2003 Resource Kit Tools (including robocopy and many others)
- Robocopy GUI
- AppDev: Something You Should Know [Irena Kennedy - MSFT] – plenty of cool things about .Net, SQL, etc.
- SpyBot – quite a nice tool
- Nice list of cool tools (for development and not only): Scott Hanselman’s 2006 Ultimate Developer and Power Users Tool List for Windows
- Microsoft PowerShell has been finally released (in a somewhat quiet way, I should say). The official PowerShell blog has lots of interesting info about it.
Debugging .Net2 and WPF
A Tracing Primer by Mike Rousos [MSFT] introduces .Net tracing
Trace sources in WPF from Mike Hillberg’s Blog on WPF (Avalon) [MSFT]
