?
Solved

debug from command line

Posted on 2001-06-08
10
Medium Priority
?
321 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 200 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

762 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