Important alert: (current site time 7/16/2013 2:58:13 AM EDT)
 

winzip icon

VB+ASM - How to break into the Visual Studio debugger.

Email
Submitted on: 10/4/2003 9:04:28 AM
By: Paul Caton 
Level: Advanced
User Rating: By 30 Users
Compatibility: VB 5.0, VB 6.0
Views: 23190
 
     The included cDebug.cls class allows the user to break their application (or the VB IDE if run from there, not recommended) into the Visual Studio debugger. Make the sample project, run the executable, click the 'Break into debugger' button, a dialog will be displayed, click the Cancel button to enter the Visual Studio debugger, dismiss the message box and then press F10 twice to step thru the software interupt and the return statements and you'll be back in the VB calling routine. Provided you haven't run the program from the IDE, you should now see the Visual Basic statements interspersed with their implementing assembler codes. To ensure that you can view the VB source with your own programs.... make sure that the following options are set on the Project/Project Properties/Compile dialog... Compile to Native Code, Create Symbolic Debug Info. Also, before running the application to be debugged, be certain that the source code files on disk are up to date by selecting File/Save Project. I should stress that this submission is a shameless VB+ASM promotion, as the same trick can be achieved with an API call, as is demonstrated in the sample.
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 13 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

10/4/2003 9:11:45 AMPaul Caton

I wrote this to investigate how VB dealt with currency variables (64 bit) if you are developing assembler routines in VB, then the easiest way to hit the Visual Studio debugger is to include an 'int 3' code in the asm, but you knew that right?
(If this comment was disrespectful, please report it.)

 
10/4/2003 10:20:13 AMCoding Genius

As always Paul, impressive work with integrating assembly code into VB. Seems like that guy who gave you a poor rating is a 13 year old script kiddie wannabe who can't code and can't take anybody being better than him. So here's a well deserved 5 to pull up the rating a bit and I'm sure plenty of other people will too. Keep up the good work.
(If this comment was disrespectful, please report it.)

 
10/4/2003 2:02:54 PMRay Hildenbrand

Paul,
You are absolutely amazing! I have needed this for a problem I am having that only occurs when running compiled under xp. This ought to do the trick!
5 stars, eh!
(If this comment was disrespectful, please report it.)

 
10/5/2003 1:42:03 AMRobert Rayment

No I didn't know that. Clever stuff *****. Not sure if my message box is as you say. I have Close Debug & Details buttons, Debug takes me to VC++, then F10 steps through also showing VB code - fascinating! Eventually I get 'Can't trace into system DLLs' and have to close VC++.

(If this comment was disrespectful, please report it.)

 
10/5/2003 10:41:12 AMLight Templer

Hi Paul! Once more: Really fine stuff! 5 from me and regards! Light Templer
(If this comment was disrespectful, please report it.)

 
10/5/2003 10:58:29 AMkooki

my pc hang twice, trying your code.
(If this comment was disrespectful, please report it.)

 
10/5/2003 12:21:47 PMPaul Caton

Kooki - I marked this code as advanced... do you have the VC++/debugger installed?
(If this comment was disrespectful, please report it.)

 
10/5/2003 6:41:41 PMThushan Fernando

very nice work and a very interesting... so little ASM code! (Still learning ASM) 5gs in da house:D
(If this comment was disrespectful, please report it.)

 
10/5/2003 6:48:12 PMThushan Fernando

wow, this is so helpful like you wouldnt believe! I can now debug some of those exceptions easily now... thourhoughly impressed(see i cant even spell thoroughly)...
(If this comment was disrespectful, please report it.)

 
10/5/2003 6:51:37 PMThushan Fernando

just a question, whats the reason for the loop (i 1 to four)? (and a side note for those who have XP/Server 2003, you press the DEBUG button when it crashes)
(If this comment was disrespectful, please report it.)

 
10/5/2003 8:51:03 PMPaul Caton

Thushnan, no real reason apart from having some VB statements interspersed in the assembler after returning from the software interrupt. I also thought that people might interested to see the great wodges of assembler related to some simple VB... that should improve some if you select fast or small optimizations instead of none.
(If this comment was disrespectful, please report it.)

 
10/5/2003 11:47:05 PMAlexandru Ionescu

I don't get what the point of this is (great code though Paul)... if I want to debug my VB app with the VC++ debugger I simply compile it with Debug Info and then load the .bas or .frm inside VC++ and set my breakpoints where I want them. Why require advanced ASM tricks to do this? 5 globes though.
(If this comment was disrespectful, please report it.)

 
10/6/2003 2:11:05 AMkooki

What do think. If I have VB6 sure I have
VC++.
I like the idea of intergrating ASM to VB.Sorry for my comment and vote erlier I will change it to 4 globes.
One challenge to you as as ASM anb VB programmer. Can you code a Parallel port(send to printer port a btye if you know, what i mean) program without using a *.dll file in VB. If you do that you're the best of the best.
(If this comment was disrespectful, please report it.)

 
10/6/2003 2:19:48 AMkooki

BTW... It work for me now.
(If this comment was disrespectful, please report it.)

 
10/6/2003 4:28:44 AMSahir

excellent !!!!!!!!
5 ***** from me
(If this comment was disrespectful, please report it.)

 
10/6/2003 9:26:39 AMPaul Caton

Alexandru, the point is that many experienced VB programmers, especially those who don't use VC++, wouldn't have ever come across the VC++ debugger and what it can do for you. Even Robert, who's submitted loads of assembler here, wasn't aware that he could chuck an 'int 3' into the asm and get chucked into the debugger. The advantage, I suppose, of doing it via code is that you can go into the debugger on demand, plus, possibly combine it with features such as conditional compilation and exception handling. My main purpose here was to introduce a lot of experienced VB coders to the VC++ debugger, if I'd written a tutorial hardly anyone would of noticed... this way they run the exe, see the VC++ debugger (many, probably for the first time), and then wonder that they can see their VB statements AND the implementing machine code, step thru the code etc.
(If this comment was disrespectful, please report it.)

 
10/6/2003 9:27:52 AMPaul Caton

More hints people... View the cpu registers Alt+5, Modify the cpu registers Shift+F9 and enter something like eax=0 - View memory Alt+6 - Enjoy :-)
(If this comment was disrespectful, please report it.)

 
10/6/2003 11:13:35 AMJohnB

I wonder if you can do this in .NET...?
(If this comment was disrespectful, please report it.)

 
11/4/2003 12:56:45 PMOR13

Well, Paul, I have only one thing to say:
You are a genius !!! I knew that you can open any .exe file in Visual Studio Debug, but the thing with the project properties in VB, well, I never tried to deal with them (I wish I had tried...). Thanks!
(If this comment was disrespectful, please report it.)

 
11/16/2003 7:39:21 AMLam Ri Hui

congratulation Paul, you are chosen as contest winner.
(If this comment was disrespectful, please report it.)

 
11/28/2003 11:02:29 AM


(If this comment was disrespectful, please report it.)

 
12/26/2003 11:20:08 AM

I noticed all your asm is in masm... microsoft doesnt give any suport for masm and i feel like its under devaloped.

Maybe you should try flatassembler?

It has a very good macro system and raw binary output (no code trimming needed).

Also could you maybe make a tutorial on how you make theses class's?

Maybe you could make a template class or asm toolkit?

Some examples of self modifying code would be awsome too..
I am asking to much i know.. but still. :|D
(If this comment was disrespectful, please report it.)

 
1/10/2004 11:02:40 PMAlpha Binary

it crashes, and i don't see any 'debug' button either. sounds great anyway, wish i could try it.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.