C++ NetBeans Run-Configuration passing arguments-issue - c++

When i want to run a program with arguments out of the IDE i do this:
ProjectProperties→Run→Arguments and type my arguments in there.
But if I want to Debug, NetBeans ignores these arguments given there.
So how can I debug a project with command-line-arguments given?

I had the same issue.. My NetBeans C project don't take command line arguments in debug mode.., but only with run (F6)..
..
What I've done (NetBeans/MinGW):
uninstall mingw-get
run mingw-get-inst-20100909.exe (this has gdb 7.1).
http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get-inst/mingw-get-inst-20100909/
This is a temporarry solution until binary NetBeans 6.9.2 release will be available..
Hope this help someone..

I had the same issue with Netbeans 6.9 but not 6.8, and found that the solution was to update Netbeans.
http://forums.netbeans.org/topic36082.html

I have the same issue, and there is a way to get around it.
First, you need to enable GDB console within NetBeans, by setting this options on your netbeans config file (you will have to close NetBeans for it to work)
-J-Dgdb.console.window=true
Next, on NetBeans and before you start your program, set a break point right at the start of your main(). Once execution breaks there, use the "set args [arguments]" gdb command followed by "run" to restart your debugged program, now with the arguments set.
You do not need to close the debug session when you rebuild your project, as GDB will detect it and reload the new binary when you issue the "run" command again; this way you wont have to set the arguments again.

Related

Running custom commands with VS Code and CMake Tools

I am using VS Code with the CMake Tools extension, and I would like to run a simple MPI program. Everything compiles just fine, and I can run my code in the terminal using
mpiexec -n 6 "path-to-my-workspace\build\my-executable.exe"
However, I would like to set things up so that this gets executed automatically when I press Control + Shift + P > "CMake: Run Without Debugging" (or Shift F5).
I read in the CMake Tools documentation that I could create new launch targets in a launch.json file. However, the VS Code documentation states that
The launch.json file is used to configure the debugger in Visual Studio Code.
I want this for debug, but also for release. Should I still use a launch.json file? I had the same problem in the past when I needed to pass arguments to my main function. What is the right way to do that in VS Code with CMake Tools?
This sounds like two cases of terminology-related confusion.
In VS Code, there are actions to "Run Code" and "Run Without Debugging". You can find more about the distinction between the two in this question. In a nutshell, "Run Code" runs the program inside a debugger program (like gdb), and and "Run Without Debugging" also runs the program, but doesn' run it inside a debugger program.
The two most common build modes are "debug" and "release", where debug includes debugging symbols that enable running in a debugger, and release does not and instead is built with more optimizations. VS Code can run both types of builds without debugging, and can run debug builds in a debugger. For release builds, it can only run outside a debugger.
You specify that you only care to run outside a debugger.
To answer your question "Should I still use a launch.json file?", yes, you can still use a launch.json file.
Also, note:
Tip: The Run action is always available, but not all debugger extensions support 'Run'. In this case, 'Run' will be the same as 'Debug'.
Another note: If the program you wanted to run wasn't a build output of your project, then you would instead probably want to be using tasks.json.

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]

Eclipse debug: "Error in final sequence - Failed to execute MI command"

I'm running Eclipse on win7. I want to make console applications that can run on either windows or linux. I followed the guide here on how to setup the compiler
I'm trying to compile and run a simple hello world program. It compiles fine, but when I try to debug I get the following error:
'launching test' has encountered a problem.
Error in final launch sequence.
Clicking details reveals the following information.
Error in final launch sequence
Failed to execute MI command:
-exec-run
Error message from debugger back end:
Don't know how to run. Try "help target".
Don't know how to run. Try "help target".
My gdb debugger path is C:\codesourcery\bin\arm-none-eabi-gdb.exe
I'm not exactly sure how to proceed.
If you're creating a windows console then I would think you would need gdb found in c:\minGW or wherever you have your Windows 7 gcc toolchain.
To change your debugger on Eclipse Kepler go to:
Run->Debug Configurations. Select Debugger tab and in the "GDB debugger:" field, enter the path of your Windows gdb.exe file (c:\MinGW\bin\gdb.exe if you're using minGW)
I realize this is an old question, but hoping it will help someone. In my case, there was a breakpoint set with only a memory address (no file name associated with it). Not sure how I got into this situation... Once I removed the breakpoint, I was able to launch my program with debugger. Note, I am using Eclipse Luna CDT (SR2)

Eclipse c++ never run when build has errors

When programming in eclipse (c++), I would like to just hit f5 (run) and have the project I'm working on save, build and (if there are no errors) run. If there are errors I want it to show the problems window and stop.
This all works at the moment except for the part where it shouldn't run when there are errors.
Is there a way to make eclipse never run the project when there are errors? Perhaps with an addon?
EDIT: Forgot to mention the prompt... The prompt does show but I want it to not show at all. If you look at the preference window you'll see that there's no 'never' option, there is one for all the other options but not for the 'launch if project contains errors'.
By default, Eclipse CDT does not run code with build errors, but maybe you have checked the option Always launch without asking checkbox.
You should go to Windows menu->Preferences->Run/Debug->Launching->Continue launch if project contains errors and check Prompt option instead of Always. Using this, Eclipse CDT will prompt you if errors exists during building or launch your binary if it has been compiled without errors.

Eclipse CDT Console output not showing up in debug with path and not showing up in run without path

I'm trying to get Eclipse CDT (64 bit eclipse) working on Windows 7 with GCC. When I first got GDB working (that was a challenge in itself), running the program in debug mode was the only way I got output. Running it normally didn't give any console output. After hours of googling, I figured out that if I added C:/cygwin/bin to my environment path in eclipse, I could get output when running the program normally. Then I ran it in debug mode and there was no output. I tested this a couple of times to make sure it was the addition of the path causing the problem. This is the program I was running,
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
So how can I get both normal and debug modes working, and why did I have to include that path in the first place (it's already in my cygwin path and why does CDT need it?) ? Also, why is it that if I add a path to my Run configurations it will also be added to my Debug configurations?
From wiki eclipse:
In Eclipse CDT on Windows, standard output of the program being run or debugged is fully buffered, because it is not connected to a Windows console, but to a pipe. See bug 173732 for more details. Either add flush calls after every printf or add the following lines at the start of the main function:
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
I don't think I can answer everything but I use exactly the same set-up as you and I've had to deal with quite a few issues like this (I'm wondering if you had trouble how to juggle using the 32-bit/64-bit JVM and Internet browsing)!
The cygwin/bin path must be specified because that is where gcc, gdb and all the other cygwin tools and dlls are located (I'll assume you're using cygwin flavour of gcc rather than MinGW flavour). I believe you must specify it in the Windows environment (using a win32 file path) because Eclipse is running using the Windows JVM and therefore deals with win32 paths. Consequently, it doesn't matter that cygwin/bin is added to the PATH variable in the cygwin environment. CDT is looking for cygwin using Eclipse, and Eclipse needs to find cygwin1.dll from Windows.
I might be totally wrong, but if I had to guess I would say that you need to make absolutely sure you have properly set the PATH environment variable correctly for both configurations.
One thing to note is that in Eclipse there is no difference between a configuration shown in the Debug Configurations window and one with the same name in the Run Configurations window. The only difference between the two windows is that one will run the program without using a debugger and has tabs for setting debug settings. Therefore it's no surprise that changing settings in one will also affect the other.
As you may know, for many projects the build system is set up to produce two (sometimes more) sets of binaries: one with debugging info/symbols (DEBUG) and one without (RELEASE). In this case, you normally have two configurations in Eclipse: one to run the DEBUG binary and one to run the RELEASE binary. Both of these will show up in both the Debug Configurations window and in the Run Configurations window. The point is that you can run DEBUG either with or without gdb, but RELEASE cannot be used by gdb.
That said, I'm not sure why adding the correct path to the run configuration would stop the DEBUG binary from outputting to the console. I suspect something else is going on here, perhaps a mismatch of debug info and debugger.
To (hopefully) answer your question as to how to get both configurations working, go the whole-hog and just add C:\cygwin\bin; to the Windows PATH environment variable. I'm guessing that will allow both to work. I'll assume you know how to do that but please post a comment if not.
The other thing to try would be to compile and run the program from a cygwin shell. If it works there it's probably a safe bet that your PATH environment variable is not set correctly when using eclipse.
Hope that helps!
Adding the Path was correct before gdb 7.3. Now when I add the path I can no longer use breakpoints as it cannot find the dll files as they are no longer part of the path. To fix this you can easily add the entire path from the environment by following these instructions.
left click the project
enter the RUN/DEBUG settings for the project
select the executable
click edit
select Environment Tab
click Select...
scroll down to Path (Case sensitive)
check mark Path
press OK
press OK
press OK
You can see the dll problem as it appears in the gdb console
error,msg="During startup program exited with code 0xc00000be."
or
error,msg="During startup program exited with code 0x00000135."
and you may get an error window pop up saying it could not clear the breakpoint
You need to set up linker
I am using MinGW.
Follow below steps.
Goto Project > Properties > C/C++ Build > Settings > Tool Settings (Tab) > MinGW C++ Linker (Option) > Add Command (g++ -static-libgcc -static-libstdc++) (default command is only g++)
Don't debug or run C or C++ applications from inside Eclipse if they target Cygwin. TK link to "you're gonna have a bad time" meme.
There are problems with Cygwin stdout/stderr that don't show up if you run the programs from the normal Cygwin console (where you would be running bash), but they do show up in pretty much every other way you can run them.
The normal way that programs run other programs in Linux and other posix-supporting environments is to reroute the i/o to a pty. Cygwin can't support pty's 100% in Windows.
Some of the problems can be ameliorated by the setvbuf calls in #infoartenovo's answer.
A flip side of this problem is that applications written to use Windows' Console API don't work well in ptys.
We are all collateral damage in an unwinnable war.
http://cygwin.com/ml/cygwin/2011-12/msg00236.html
https://code.google.com/p/mintty/issues/detail?id=56