Solved

debug from command line

Posted on 2001-06-08
10
289 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

758 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

22 Experts available now in Live!

Get 1:1 Help Now