Solved

debug from command line

Posted on 2001-06-08
10
306 Views
Last Modified: 2010-04-02
I'm using VC++6.  One of my classes is throwing an exception, but only if I run the program from the command line, not if I run it from the IDE.  

How do I debug when I'm running the program from the command line?
0
Comment
Question by:codeghost
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6168283
The easiest way it to hard-code an 'EXCEPTION_BREAKPOINT', which will make the debugger attach to your program when executed. Just insert

__asm { int 3};

at an appropriate line...
0
 
LVL 30

Expert Comment

by:Axter
ID: 6168674
Are you testing it in NT or Win9x?
0
 
LVL 30

Expert Comment

by:Axter
ID: 6168709
If you're using NT, you can try changing your "Executable for Debug Session" to "C:\WINNT\system32\cmd.exe"

The cmd.exe program will launch the Dos window.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:codeghost
ID: 6169875
I am running on Windows 98.

jkr, can you give me an example here of how to use

                     __asm { int 3};

                     at an appropriate line...

What should I expect to see as that code is executed?
0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6169940
>jkr, can you give me an example here of how to use

Well, it's an example itself :o)

No, to be serious, you could just place that statement at any place in your code that is executed before the exception takes place.

>>What should I expect to see as that code is executed?

Your application will be loaded into the debugger the way it is, and you can just examine that app in 'real life' along with e.g. setting breakpoints and watches.
0
 

Expert Comment

by:robertmitchell_99
ID: 6171647
Hi Codeghost,

You've got a number of options.

1. The simplest and easiest way is to set up your program as a debug executable.
 - Got to Project->Settings->Debug via the main menu.
 - Enter the whole path for your executable in the
     "Executable for debug session" box

 - If you have command line parameters pass them to  
      your exe by putting them in the Program Arguments    
       box.

 - place a breakpoint in your program as usual and hit f5

2. If for any other reason you can't do this then you need to put a DebugBreak(); or __asm { int 3}; in your code at the point from which you wish to begin debugging.

You must compile the program in Debug, invoke your exe  and the program will run, then stop and produce a message box at the point of your DebugBreak();

You can then either press the cancel option which will start an instance of visual studio to debug into your code, or you can attach to the executable while it is stopped from the main menu: Press Build->Start Debug->Attach To Process.

I hope you manage to attach to it okay.  The alternatives to DebugBreak() are ATLASSERT, ASSERTE_ or just put in a MessageBox();

This is just to stop execution at the correct place so you can attach to process.

Best of luck

Robert.


 
0
 
LVL 86

Expert Comment

by:jkr
ID: 6171742
>>Enter the whole path for your executable in the
>>    "Executable for debug session" box


>>2. If for any other reason you can't do this then you
>>need to put a DebugBreak(); or __asm { int 3};
>>in your code at the point from which you wish to begin
>>debugging.

robertmitchell_99, all that has already been proposed. You should definitely take time to read a question's history before posting an answer. You should also spend a few seconds to scroll to the bottom of this page, where the 'Tips on Comments and Answers' are listed...



0
 

Author Comment

by:codeghost
ID: 6172094
I had already tried jkr's solution and it worked for me.
0
 

Author Comment

by:codeghost
ID: 6172096
I had already tried jkr's solution and it worked for me.
0
 

Author Comment

by:codeghost
ID: 6172101
having trouble with the site.... getting a Java error.  Hopefully this will go through this time.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question