Debugging on Linux for Windows Developer - c++

Primarily I've done basic (novice level) software development on a Windows machine, but I've always had MS Visual Studio to help me step through the process of debugging.
Now, however, it looks like I will be on Linux, so in order to get ready for the jump I want to make sure I have a tool/tools lined up to help me step through the code and debug.
Unfortunately when I've verbally asked folks how they go about debugging on Linux, I typically get the following answer, "Oh, I just put a bunch of print statements." OMG! No way you say, but yes that is their answer.
Since it is on Linux, and will be working with C++ code on the CentOS 32-bit OS, I am hoping here is a preferred OpenSource solution. So, I guess I asking for the preferred OpenSource IDE for C++ code on CentOS Linux.
Thanks for any insight and suggestions.

Good question, of course, but its been
done before:
https://stackoverflow.com/questions/408418/what-editor-ide-do-you-use-for-c-programming-on-linux-and-why-closed
https://stackoverflow.com/questions/86676/is-there-a-good-and-free-ide-for-c-c-in-linux
https://stackoverflow.com/questions/149321/what-ide-would-be-good-for-linux-kernel-driver-development
Lightweight IDE for Linux
Simple GUI IDE?
(from: https://stackoverflow.com/questions/579219/best-unix-linux-c-debuger-ide-closed)

A few years ago I made the move from VS to an emacs/make type environment and I have never looked back.
The idea is to use a makefile to handle the project management side of an IDE and I use emacs+gdb for editing and debugging. It will take you a while to get used to emacs but if you stick at it it's well worth the effort. Once you've started emacs, press "Ctrl+H" followed by "t" and this will bring you to the tutorial page.
After you've mastered the basics, you can debug a program in a similar way to any IDE/debugger interface. I must admit that even after all this time, I still use a set of VS key mappings that I setup when I first moved to emacs!
(global-set-key [f7] 'compile) ;; Run the compile command
(global-set-key [f4] 'next-error) ;; The next compile error
(global-set-key [S-f4] 'previous-error) ;; The previous compile error
(global-set-key [f5] 'gdb) ;; Start the debugger
The following sets the "VS" key mappings to the different GDB commands which you might use:
(add-hook 'gud-mode-hook
'(lambda ()
(define-key (current-local-map)
[f10]
'gud-next)
(define-key (current-local-map)
[f11]
'gud-step)
(define-key (current-local-map)
[\S-f11]
'gud-finish)
(define-key (current-local-map)
[f5]
'gud-cont)
))
With the above keymappings, I press 'f5' which prompts me to run gdb (and to this command I add the binary I wish to debug). Once gdb is loaded, you press 'f5' to continue, 'f10' to step-over, 'f11' to step-into and 'shirt+f11' to step-out.
Finally, every time you start 'gdb', it will read a file called '.gdbinit' in your home directory. A different StackOverflow question had this answer which brought stl-views to my attention. stl-views is a set of helper functions for gdb that show you the contents of the different types of STL containers. The instructions for how to use it can be found at the top of the link.

I would suggest using Eclipse
Eclipse is a mature IDE with plenty of support available.
There is also Code::Blocks if you want to try something different

Eclipse
NetBeans
KDevelop

There is always GDB. XCode for OSX uses GDB internally for debugging.

Valgrind, its your friend and may save you from having to suffer though GDB.

Mostly, for an IDE similar (?) to VS - use Eclipse.
See moving Microsoft VS projects to Eclipse C/C++ Development Toolkit - a brief step-by-step procedure for migrating Microsoft Visual Studio C/C++ (MSVC) projects to Eclipse. It compares and contrasts the benefits of MSVC and Eclipse CDT.

Anjuta is a really great IDE for GNOME. For debugging it uses GDB internally.

If you just want a good debugger, check out DDD.

I use a combination of gdb and cscope when debugging on linux.

Related

VSCode c++ configuring for vc toolchain

I'm trying to start a work in vscode , latest C++ plugin version supports ms debugger, so as I'm mostly working under windows it was a signal to try this.
c++ tools plugin from MS and cmake tools were installed.
my test project was however not built . the problem is clear , but I need an advice from experienced vscode users how to solve this right.
cmake doesn't see vc compiler.
(after using QtCreator) I expected that vscode could detect vc installation... however that's not so. ok, I have a two ways:
fill environment variables INCLUDE/LIB/PATH with a headers, libs and binaries
just run vcvarsall.bat x64
Second way is a simple and reliable. so final question is:
how to run .bat at the begining of vscode start?
(I don't mean write another bat/cmd, prepare the environment and run vscode inside the same script after that)
Although the question is fairly old, I'll try to give a useful answer, in case others stumble across, just like I did.
I believe what you are trying to achieve is not possible. Code inherits the environment it was started with. If you did not launch it from a developer command prompt, you will not be able build and debug. (Building might be possible if every task first starts the vcvarsall.bat, but that slows things down by a lot. Debugging I think will still not work.)
If you are willing to, you can check out vector-of-bools CMake Tools extension which does build automation as well as automatic MSVC detection. It builds using CMake (thus you need to write your build scripts using CMake), but it will take care of building just by pressing F7, like what most VS users are familiar with.

Can I use Eclipse CDT to debug a prebuilt C++ executable?

On Linux, I have some C++ programs built with my own makefiles, and I'm looking for some GUI debuggers to debug them at source level.
Previously I use KDbg(2.5.2) on openSUSE(12.3). It works but with some very annoying limitation, e.g., I cannot set a breakpoint when the debugged program is not trapped by Kdbg -- I mean, in order to set a new breakpoint, I have to set it before the program is launched or the program pauses on hitting an already set breakpoint.
Now I try to use Eclipse CDT. I got eclipse-cpp-juno-SR2-linux-gtk.tar.gz but find that I don't know how to load my executable so to start debugging.
I googled with words like 『eclipse debug pre-built C binary』, but few seems to care about this feature.
Can Eclipse CDT really do that? If Eclipse CDT can't, is there any better alternatives to KDbg? Please help.
According to hint from this answer, https://stackoverflow.com/a/248119/151453 , I finally figure out how to do it.
The key point is: In the Eclipse CDT project, create/edit a Launch Configuration so to tell the debugger what executable to load.
Now I have to admit, Eclipse CDT does quite well in C++ code debugging far better than KDbg.
Some screen shot below, on openSUSE 12.3 .
Now we can Run -> Debug (F11)
Debugger automatically pauses the program at main()'s first statement.
The Stand-alone Debugger is an Eclipse application which packages the Eclipse plug-ins from the CDT (C/C++ Development Tools) project into an application that can be started from a command-line script:
bash /path/scripts/cdtdebug.sh -e executable [args]

How to configure Qt debugger and what is needed for it to work

Ok so Im really confused here, I got the same erroe as Martin.kv who started this thread How to configure CDB in Qt Creator?
which said "The preferred debugger engine for debugging binaries of type 'x86-windows-msvc2010-pe-32bit' is not available....Details: There is no CDB binary available for binaries in format 'x86-windows-msvc2010-pe-32bit"
I assume I have to download some stuff to fix this, so I went here http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx and I have Windows 7 on a 32-bit system so I went under this title "Install the Windows 7 Version of Debugging Tools for Windows" and went here http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=8279 to download the Debugging tools for windows.
From all the stuff I've read, on the thread I referenced and a few others, what I downloaded seemed to be the right thing.
I admit I screwed up a little because I forgot to check where it was putting the Debugger Tools because while it started downloading I was still searching for what to do after the download. But I'm pretty sure it is in "C:\Program Files\Microsoft Windows Performance Toolkit" but I dont have anything called Windows Kits, which everyone else is saying theirs is in, and I still dont seem to have a cdb.exe..
did I download the wrong thing? What do I need to do/download instead? and also where can I get the Symbol Server that the Qt site and many other people suggest??
Sorry I'm new to Qt and some what to programming in general and my program for my internship is due at the end of the day and last night it stopped working so I'm kind of freaking out a little but I figure the debugger could help because it doesnt really make sense why it stopped working.
There should be a place in the Qt Creator settings where you can point it to the cdb.exe that comes with the Debugging tools for Windows.
See here: http://doc.qt.nokia.com/qtcreator-2.5/creator-debugger-engines.html
I got cdb working with QtCreator only after the following steps:
1) Download & install Debugging Tools for Windows
2) QtCreator->Tools->Options->Build & Run->Tool Chains
3) Copy autodetected MS compiler to the "manual" section
4) Set the path to cdb.exe
5) Use the "manual" MS compiler.
Perhaps there's some way to avoid steps 3-5 (playing around with environment variables maybe) but the described scheme works fine so I don't mind.

Tool for debugging Borland & Visual Studio applications

sometimes I have to debug an application that was written with Borland C++ Builder. This application loads dlls compiled with Visual C++. Is there a debugger that can debug both parts of the application? Currently I have to decide - either I can easily set break points and see the source in Visual Studio or I have to start Borland C++, but I can't work with the source from the Visual-Studio compiled dll.
thank you for your help,
Tobias
You could try OllyDbg - version 1.x does not seem to support the latest Win version but there is also the 2.0 although it's still in alpha state(haven't tried myself that one yet).
EDIT - clarification:
Source debugging OllyDbg reads debugging information in Borland and
Microsoft formats. This information includes source code and names of
functions, labels, global and static variables. Support for dynamical
(stack) variables and structures is very limited.
The above is take from here.
UPDATE:
I'm not familiar with the Borland C++ Builder but at this link you can find some articles explaining how to deal with some interoperability issues between Borland and MS that might be of help.
if both parts built using ulink linker and have debug info you could try cdb32 debugger (from the ulink linker author)
cdb32 is still in its alpha stage though and I personally never tried such "mixed" debugging
Have you tried loading the DLL code in VS, loading the app code in BCB, and having both debuggers attached to the same running process at the same time? Not sure if Windows will allow that, but it might be worth a try.
I suspect there is no perfect answer to your question, you are going to have to compromise in some way, as I'm sure you are already doing.
I have a similar problem to yours at work. The applications that I work on are written in Python instead of Borland C++, but like your situation, these apps rely on a rather large Visual Studio compiled DLL for some functions.
My method of debugging these applications involves a combination of two debugging strategies: the use of an interactive debugger and the so called "printf" debugging technique.
What I basically do is pick one of the two areas as my main debug focus, and that determines my debugging approach:
If for a given situation I decide that I need to debug the DLL with greater detail, then I work with the VS debugger. I set the executable to run in the DLL project as my python script and that enables full debugging of the DLL code. If I need debugging support from the Python side, then I add print statements. If I need a breakpoint on the Python side to inspect some values, I just print all those values and immediately after call a C++ function that does nothing, but that has a breakpoint set in VS.
When I need to concentrate more on the Python side more I use a Python interactive debugger, but I have VS with the DLL project loaded on the side so that I can quickly add any necessary printfs on the DLL and recompile, so essentially the reverse of the above.
I know it's not the answer you expect, but it is a decent solution in my opinion.
It looks that it is possible to convert the debugging information generated by C++ Builder to a format understood by WinDbg (link to discussion). If so you could use it to debug both parts of your application (I haven't tried this though).
you can convert the .map files to Microsoft's debug file format
http://code.google.com/p/map2dbg/
now you can use Windebug; there is also a tool mentioned to convert to pdb format, so you could try the vc++ debugger

How to do remote debugging with Eclipse CDT without gdbserver?

We're using the Eclipse CDT 5 C++ IDE on Windows to develop a C++ application on a remote AIX host.
Eclipse CDT has the ability to perform remote debugging using gdbserver. Unfortunately, gdbserver is not supported on AIX.
Is anyone familiar with a way to debug remotely using Eclipse CDT without gdbserver? Perhaps using an SSH shell connection to gdb?
finally I got gdb run remotly anyhow now. At the Bug-symbol on the taskbar I took Debug Configurations - GDB Hardware Debugging.
In Main C/C++ Applications I set the full path on the Samba share of the executable (X:\abin\vlmi9506). I also set a linked folder on X:\abin in the project. Then I modified my batch-script in GDB Setup. It's not directly calling gdb in the plink-session but a unix-shell-script, which opens gdb. By this I have the possibility to set some unix environment-variables for the program before doing debug. The call in my batch:
plink.exe prevoax1 -l suttera -pw XXXXX -i /proj/user/dev/suttera/vl/9506/test/vlmi9506ddd.run 20155 dev o m
In the unix script I started gdb with the command line params from eclipse, that I found in my former tryals. The call in the shell command looks like this:
gdb -nw -i mi -cd=$LVarPathExec $LVarPathExec/vlmi9506
Then IBM just gives gdb 6.0 for AIX. I found version 6.8 in the net at http://www.perzl.org/aix/index.php?n=Main.Gdb. Our Admin installed it.
I can now step through the program and watch variables. I even can write gdb-commands directly in the console-view. yabadabadooooooo
Hope that helps to others as well. Can not tell, what was really the winner-action.
But each answer gives more new questions. Now I got 3 of them.
When I start the debug config I have to click restart in the toolbar to come really in the main procedure. Is it possible to come directly in main without restarting?
On AIX our programs are first preprocessed for embedded sql. The preprocessed c-source is put in another directory. When I duble-click the line to set a breakpoint, I get the warning "unresolved breakpoint" and in the gdb-console I see, that the break is set to the preprocessed source which is wrong. Is it possible to set the breakpoints on the right source?
We are using CICS on AIX. With the xldb-Debugger and the CDCN-command of CICS we manage that debugging is started, when we come in our programs. Is it possible to get that remotely (in plink) with gdb-eclipse as well?
I wouldn't normally take a shot in the dark on a question I can't really test the answer to, but since this one has sat around for a day, I'll give it a shot. It seems from looking at:
http://wiki.eclipse.org/TM_and_RSE_FAQ#How_can_I_do_Remote_Debugging_with_CDT.3F
...that even if the CDT has changed since that wiki page was made, you should still be able to change the debug command to:
ssh remotehost gdb
instead of using TM which uses gdbserver. This will probably be slightly slower than the TM remote debugging since that actually uses a local gdb, but on the other hand this way you won't have to NFS or SMB mount your source code to make it available to the local debugger (and if you're on a LAN it probably won't matter anyhow).
There's also a reference TCF implementation for linux, which you may or may not have any luck recompiling for AIX, but it allows for remote debugging if gdbserver is otherwise not available:
http://wiki.eclipse.org/DSDP/TM/TCF_FAQ
tried also to remotly debug an aix-appl with windows eclipse-cdt-gdb.
Got blocked at the end with unix/windows path-problems. Maybe my result can help u a little further - maybe you already got it work. I'm interested in your comment. asked on eclipse news portal- following the answer of martin oberhuber (thanks again) tried dsp dd (also blocked with path problem) and set an request in eclipse bugzilla.
here the link to news:
http://www.eclipse.org/newsportal/article.php?id=406&group=eclipse.dsdp.tm
Here my bugzilla:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=252758
At the moment we still debug localy with xldb but I am trying ddd-gdb at the moment. At least locally gdb is running.