c o d i n g f r o g s

croaking about programming, programming languages, software engineering, and the business of software

8Apr/100

Hard Coded Breakpoints

This little line of code totally saved me this week:

__asm int 3;

I'm writing a plugin to an existing Windows application and I could not, for the life of me, figure out if my plugin was even being loaded or if it was executing properly.  All I knew was that I wasn't seeing the behavior from my plugin I expected.  I needed to step through my plugin with a debugger, but since it loads as part of another app I didn't know how to get the debugger to break.  Setting breakpoints in Visual Studio wasn't working.

Fortunately for me I have smart teammates, and one of them taught me this little trick to programmatically insert a hard coded breakpoint into your code.  If I add this line, when my code runs the breakpoint is triggered and the application stops executing, with a dialog giving me the option to debug it in Visual Studio.  When I get in there, behold:  The cursor is pointing at that line of code and I can step through my plugin.

Since then I've done a bit more research and found out that, in truth,

__asm int 3;

is really only meant for x86 architectures.  A more portable way to do this for Windows is:

__debugbreak();

which invokes the correct assembly interrupt for the current architecture.

On Linux, apparently you can do this:

__asm__("int $0x03");

although I haven't tried it. It looks enough like the x86-only version for Windows that it makes me wonder if it would work on x64 architectures; I'd love to hear back if anyone knows for sure.

Also, interested to know how to do this on OS X. Comment or mail if you know.

12Nov/090

Go – Programming Language Nirvana?

The Go Gopher

The Go Gopher

Earlier this week Google announced their new programming language, called Go.

Usually I don't get too worked up about programming languages.  I already feel like I know more languages than I should need to know, and often a new language seems to me like "Hey, check this out!  Here's a more complex or non-intuitive way to accomplish a task you already know how to accomplish, but in a language you will never use professionally!"

I know, I'm disappointing you.

But Go!  Oh my, this seems different.  From the blog post:

Go combines the development speed of working in a dynamic language like Python with the performance and safety of a compiled language like C or C++. Typical...

Wait!  Hold on there — my heart just skipped a beat and it freaked me out.  Can you please repeat that again?

...a dynamic language like Python with the performance and safety of a compiled language like C or C++.

Ooh baby.  Someone help me — I'm shaking with anticipation.  A systems programming language that combines Python and C++?  Can it really be?  It seems too good to be true!  My two favorite programming languages combined in one:  It's like true programming nirvana!