Is there a way to debug with the visual studio command prompt? - c++

I've got a project that I need to get working with 3 compilers (Borland, gnu, and Microsoft). It works on 2/3 and now I just need to get it working with Microsofts. It seems to crash in places where it works fine with the other compilers, so I'm wondering if there is a way to debug with the command line, maybe to get a stack trace or get the line which caused the crash, something similar to gdb with gnu.

(Full disclosure: I work on the Visual Studio team)
If you're using the Microsoft C++ compiler, do you have Visual Studio installed already? If so, you can use the built-in debugger. If not, I would recommend trying Visual C++ 2010 Express for free. It has an excellent native debugger. You can break on first chance exceptions (C++, SEH, Win32 exceptions) and go right to the line where it happened along with the call stack, locals, etc.

Debugging Tools for Windows - an outstanding package of debugging tools that includes the cdb and ntsd console debugger (in addition to the GUI WinDBG debugger).
The package has fantastic docs, can easily be set up to be the 'just in time' debuggers that handle a crash, and works very very nicely with crash dumps.
These are the hardcore debugging tools that Microsoft uses for crash analysis (and more).
Note that Windows comes with a version of ntsd debugger (at least it used to - looks like it's not on my Win7 box outside of the tools package installation), but it's a great idea to get the package anyway so you have the latest tools - and like I said the docs are a wealth of great information.

Yes.
C++ : Building on the Command Line
C# : See Debug-Centric Options of csc.exe.

Well, you are having trouble with the one compiler that tries very hard to crash your program on purpose. It's called "Run-time error checks", the /RTC option compile option. You can turn it off to make it behave like those other ones. Or you could pursue the "something's wrong here" angle. It's well documented in the MSDN Library article for /RTC.

Codeview is an older product which does that, but there's no reason why you couldn't use visual studio to do the same thing.

Related

build toolchain with cmake, clang and llvm for visual studio

I googled a lot and didn't find an appropriate answer, so I'm asking here.
What steps do I need to take to develop a c++ project from existing code which shall be compiled using cmake and clang?
I also want to have all the nice features like auto-completion and debugging with breakpoints and step by step debugging.
See the recent LLVM snapshot page for Windows builds integrating with Visual Studio here. There is an installer and a code formatting plugin. You will not get auto-complete and Clang/LLVM has nothing to do with debugging in Visual Studio (except that it will probably not work if you compile with Clang).
See also this interesting blog post predicting much good for LLVM on Windows in the future, backed by companies with paid developers ;-)
Staying on top of what the clang guys are doing for Windows is a good idea. The last two releases 3.6 and 3.7 show a commitment to the product but still some holes: MSVC C++: /Z7 but not quite /Zi debug information, not quite compatible with MSVC C++ exceptions (but Windows SEH works) meaning this is more like an auxiliary build tool at the moment than something you can build any running product on. I concur with the problems with exceptions at the moment.
I haven't got the strakh to post more than two links but the intervening weekly notes, have lots of interesting snippets including the coming of lldb to Windows and (if you care for this sort of thing) a longer post on compiling for CLR on Windows. Either way, looking at blog.llvm.org regularly is a good idea to keep this answer current.

Debugger to Use with MSVC++ 2010 Compiler

Assuming I'm using not-Visual Studio, and building at the command line with cl.exe, what debugger should I use?
I tried using gdb.exe from MinGW but it doesn't seem compatible with the debugging symbols that cl.exe outputs (it reports "no debugging symbols found").
I feel like this is a kind of ridiculous question to be asking, but it seems to be literally impossible to find information on MSVC++ that isn't VS-specific.
Right now I'm using an install of Visual Studio 2010 Express just for access to cl.exe, but I do not use it as an IDE.
You should learn WinDBG, it can debug both user-mode and kernel-mode code. As you're referring to GDB, I assume the command line interface of WinDBG won't be a problem for you :)
By the way, WinDBG is the official debugger of the Windows developers, so you can expect it to be supported for a long time.
Use WinDbg. This is an excellent debugging tool, although it might get some time to get into. MinGW won't cut it, as it uses a different symbol format. WinDBG is also part of Windows SDK, that you likely have already installed, so just check if you have it already.
If you have Visual Studios (and I don't think you can get cl.exe
without it), you can still use its debugger. It's a bit wieldy, because
it will insist on creating all sorts of project and solution files
you'll have to delete later, but it does work.
What I've usually done in such cases in the past is to develop using g++
and gdb (preferably under Linux), then port the working code to Windows.
This means that you almost never need the VS debugger (and gdb is far
more powerful than the VS debugger).

Linux app using C++ and visual studio

I want to write an app in visual studio that will work in linux. It's main function will be to monitor multiple linux systems and provide health and status to the GUI... I.e disk usage, bad drives, network throughput, mysql reads/inserts, ect... Can I cross compile with visual studio 2010?
Should I even bother using visual studio? Or should I bail and use Java or C++ on linux?
Thanks for the help guys, looks like the inevitable is true! I was just looking at netbeans, so I guess I will use that. I don't normally write for Linux, so I will just have to plow through it :)
Thanks
If you like the VS IDE, you can certainly use it to write code that's portable to Linux, though actually compiling the code for Linux will be separate. In theory, you could probably configure VS to compile your code with gcc as a post-build step, for example, but it would probably be more work than it was worth.
At least IMO, if you're trying write code that's portable to Windows and Linux (e.g., using Qt for its UI), and you're comfortable with VS, it's probably worth using VS to do most of the work. If you prefer Linux tools or you're writing the code exclusively for Linux, then you're probably better off using Linux tools throughout.
No; Microsoft Visual Studio does not contain a cross compiler for Linux. Nothing says you cannot use the C++ you build in Visual Studio on Linux machines though; you would just need to compile to code there.
As Visual Studio does neither run on Linux natively nor can it produce native Linux code, I would recommend you use the target platform's native toolchain to build your software.
If your goal is to create a portable application that runs on both Windows and Linux, starting one Windows with Visual Studio and recompiling the code on the Linux system on a regular basis is probably a pretty decent approach.
It is possible to use Visual Studio to develop, but you can't create the Linux executable with it - for that you need to use the gcc compiler under Linux. You'll find a few differences between the compilers that will give you some grief, and unfortunately a lot of those differences will be in the areas you're targeting - O/S services. It's a judgement call which would be easier but in your case I'd bite the bullet and use the Linux tools exclusively.
Bail.
Maybe look into monodevelop which is much less nice than Visual Studio.
Netbeans and/or Eclipse for linux are nice though.
Bail, Visual Studio is definitively not the best tool for this particular job.
If you want to code C++ for GNU/Linux, there are a lot of good IDEs in there: Eclipse, NetBeans, KDevelop, Codeblocks...
Also, check the answers on this question: C++ IDE for Linux?, I think you'll find some useful stuff there.
For what it's worth I've used VS to write code that was supposed to work on Windows and *nix. I'd figure out a configuration method for *nix and as you go before every major commit try compiling the code with gcc. Visual Studio's Intellisense and VC++ debugger murder Eclipse+CDT+gdb in every way.
I'm fairly partial to Qt Creator for my x-platform C++ tasks.

Searching good Debugger for C++

i was wondering if there was a good debugger you can recommend for C++.
thanks for helping
Whats wrong with Visual studio unless you use linux.
ANyway my suggestion is Visual studio.
But this also depends on what sort of a c++ project you work with.
General answer: use whatever debugger comes with your IDE - something that knows about your project structure will help you immensely when navigating, setting breakpoints, inspecting variables, evaluating expressions, and possibly offering features like edit-and-continue instead of forcing a recompile. Personally, I find Visual Studio to have a pretty darn decent debugger.
If you don't use an IDE, your options are limited... especially if you want symbolic debugging. Your options will pretty much boil down to GDB (with or without frontends), or WinDBG on Windows.
i recommend emacs + gdb. best combination ever.
http://www.cs.cmu.edu/~gilpin/tutorial/
You basically have two choices :
the visual studio debugger if you're under Visual (just press F5)
GDB, and its various user interfaces (this goes from a harsh Emacs mode to QtCreator integration
For Linux you could also try Zero.
Intel has a debugger called idb which is nice and works rather well.
code blocks
Code::Blocks is a free C, C++ and Fortran IDE built to meet the most demanding needs of its users. It is designed to be very extensible and fully configurable.
Finally, an IDE with all the features you need, having a consistent look, feel and operation across platforms.
Built around a plugin framework, Code::Blocks can be extended with plugins. Any kind of functionality can be added by installing/coding a plugin. For instance, compiling and debugging functionality is already provided by plugins!
Special credits go to darmar for his great work on the FortranProject plugin, bundled since release 13.12.
We hope you enjoy using Code::Blocks!

How do you try out small/simple C or C++ source codes?

It is very easy on Linux to fire-up vi and write a 100-200 lines of code, compile and see the results: ie. Trying small simple examples of C/C++ code.
On windows however, I like Visual Studio but to use it you have create a new solution then a project which then creates a new folder, generates very large PDB and caching files and a small example of 100-200 LOC becomes a 20Mb large project(?!) after compilation.
So the question is how do you write this kind of small codes on Windows? Possibly Cygwin or Dev-C++ (which is not active since 2004?).
You can compile from the command line using cl.exe. See the MSDN article How to: Compile a Native C++ Program from the Command Line for detailed instructions.
When you installed Visual Studio it created an entry in your programs named something like "Visual Studio Command Prompt" (maybe in a group "Visual Studio Tools").
Execute that Command Prompt (it sets up some environment variables needed for the command line compiler) and use cl, the command line compiler.
> cl /?
Copyright (C) Microsoft Corporation. All rights reserved.
C/C++ COMPILER OPTIONS
-OPTIMIZATION-
/O1 minimize space /O2 maximize speed
/Ob<n> inline expansion (default n=0) /Od disable optimizations (default)
/Og enable global optimization /Oi[-] enable intrinsic functions
...
Edit -- copy from another answer :)
Microsoft Documentation: VS2005, VS2008
For the simplest examples codepad may be an option.
I think there's nothing wrong with firing up Visual Studio for some testing. You can delete the 20MB afterwards ;)
However, you can also just invoke the command line compiler on Windows. Just start a Windows SDK console (or Visual Studio console) and you're there. And you can even use vi (need to install it first, of course).
I always use MinGW (GCC for windows) for such tasks.
MinGW is a good solution if you're not using anything Visual Studio specific. If you are, in the start menu with Visual Studio, there should be a script that starts a "commandline" for visual studio.
Also, please keep in mind, even if you aren't going to use Visual Studio, if you use MinGW, you're going to run into issues even with things you might not expect (like...if you decide to try the Apple Bonjour SDK, in which case you're going to get nasty link errors) because GCC and MSVC++ libraries don't always play nice.
And if you don't have access to your local computer, or you are to lazy to look for command line compiler you can paste your code to on-line compiler. There are several of them on the net you can try one of them here. It's free, no registration needed. It has some flaws but for quick code check it's just fine.
You can also use some other languages, C, C++, D, Haskell, Lua, OCaml, PHP, Perl, Python, Ruby, Scheme, Tcl to be precise.
Maybe I'm just a *nix geek, but I went on over to http://consoletelnet.sourceforge.net/gccwin32.html and got gcc for win32. I then headed over to http://unxutils.sourceforge.net/ and go these command line tools. (I renamed their find.exe to gfind.exe to avoid conflict with windows find). I then use gvim for win32 to write code and make/gcc to compile it. Now I only have to learn one environment.
For small bits of code I want to test, such as code that I'm going to include in an SO answer, I always use the command line. My tools on Windows are:
the MSYS tools, particularly their bash shell
the vim editor
the MinGW GCC compiler (Twilight Dragon branch)
I haven't used any of them, but MinGW and lcc-win32 seem to be pretty lightweight, and people seem to like them in news:comp.lang.c. MinGW is a port of GNU Compiler Collection for Windows and is free, lcc-win32 is free for non-commercial use.
You can do the exact same thing for Windows -- fire up VI and run the output through gcc.
Either get MingGW/MSys, Cygwin, or native ports of each app (gnu tools, vi)
Just because you're using Windows, doesn't mean you're forced to use Visual Studio.
I've got a Visual Studio test project with a main file I just overwrite every time I want to test something new. The couple of MB taken up by the .ncb file really really really doesn't matter. A bigger issues is the need to create a project. But I get around that by reusing an old test project.
For small/simple C or C++ source codes I use Ideone. It supports over 40 programming languages.
I usually edit my code within notepad++ then compile it with gcc under cygwin or msys.
I have used Dev-C++ post 2004, and it still works quite well.
I even used projects coded in Dev-C++ for my practicals that had to run on machines using Linux. Just changed the make files.
I also use Visual Studio; for quick testing and prototyping, I have a file scratch.c on my desktop, which I just load up and test things out in.
I don't see opening Visual Studio, clicking the new document icon, writing code, pressing F5 then just accepting the defaults for everything as being too much effort :)
The other alternative I have (which I don't use for C, but do for Haskell) is to PuTTY into a Linux box I have access to, and do everything on there.
I have a Test.sln which has a Test.vcproj which has a Test.cpp. The solution has a few handy configurations (for maximum C++ std conformance and others). I just paste code into/from the Test.cpp file and compile it that way.
I use cl.exe and nmake.exe from Visual C++ Express to compile small groups of .c and .cpp files. Rolling your own simple Makefile for nmake.exe is easy.