Solved

debug from command line

Posted on 2001-06-08
10
293 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now