Problem using '__asm int 3;' to issue breakpoint

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Problem using '__asm int 3;' to issue breakpoint

Postby Don Cross » 08 Dec 2009, 21:30

Hi everyone,

I am trying to use an old trick of mine to catch a bug while running my chess engine under WinBoard 4.4.0. In the past, I have often put the following line of code in a debug build of a C++ program running under Windows, and it triggers a breakpoint on that line that allows me to bring up the debugger (Microsoft Visual Studio):

Code: Select all
__asm int 3;


I also tried this, to no avail...

Code: Select all
#include <assert.h>
// ... blah blah blah
assert(false);


Either of these works great if I run my chess engine directly in a command prompt, but when hosted inside WinBoard, the above line of code just causes my engine to hang and stop responding. When I close WinBoard after that, the dialog box I was expecting all along suddenly appears and just as quickly vanishes. It is like WinBoard is somehow suppressing the debugger interrupt.

All I am trying to do is trap a very rare special case with a breakpoint so I can see the stack trace if/when it happens. It would be fine however I do it, so long as I can run it under WinBoard and not have to type in the correct sequence of WinBoard protocol commands manually.

Any advice would be greatly appreciated. Thanks in advance!

- Don
Author of Chenard - http://cosinekitty.com/chenard
User avatar
Don Cross
 
Posts: 29
Joined: 13 Nov 2008, 04:13
Location: Florida, USA

Re: Problem using '__asm int 3;' to issue breakpoint

Postby Teemu Pudas » 09 Dec 2009, 10:03

Does Debug menu->Attach to process work?
Teemu Pudas
 
Posts: 124
Joined: 16 Apr 2007, 14:03

Re: Problem using '__asm int 3;' to issue breakpoint

Postby Don Cross » 09 Dec 2009, 16:40

Thanks, Teemu, that is exactly what I needed! I knew "Attach to Process" was in there, but had forgotten about it.

For others reading this, after I opened the Debug / Attach To Process dialog box in Microsoft Visual Studio 2008, I had to check the box that enabled debuging "Native" code, otherwise I got an error when I tried to do Debug / Break All that said it wasn't the right kind of executable. Now can use the debugger and set breakpoints while running my engine hosted by WinBoard.
Author of Chenard - http://cosinekitty.com/chenard
User avatar
Don Cross
 
Posts: 29
Joined: 13 Nov 2008, 04:13
Location: Florida, USA

Re: Problem using '__asm int 3;' to issue breakpoint

Postby xcomponent » 10 Dec 2009, 14:27

It is only possible under 32-bit compile.
Besides, you have to try it that way:
_asm { int 3 }

intsead of:
__asm int 3;

Plus, you have to set your default debugger before that.
xcomponent
 
Posts: 10
Joined: 12 Apr 2009, 08:21

Re: Problem using '__asm int 3;' to issue breakpoint

Postby Aleks Peshkov » 11 Dec 2009, 06:55

Code: Select all
#if defined NDEBUG
#   define assert(test) ((void)0)
#elif defined _MSC_VER && defined ASSERT_DEBUG_BREAK
#   pragma intrinsic(__debugbreak)
#   if defined assert
#       undef assert
#   endif
#   define assert(test) (void)( (!!(test)) || (__debugbreak(), 0) )
#elif defined __GNUC__ && defined ASSERT_DEBUG_BREAK
#   define assert(test) do { if (!(test)) __asm__("int $3"); } while(0)
#else
#   include <cassert>
#endif
Aleks Peshkov
 
Posts: 27
Joined: 13 Jul 2007, 13:14


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 9 guests