Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Main() is suspended upon debugging: Is this normal?(Program starts off suspended when Eclipse starts to debug it.)
icon5.gif  Main() is suspended upon debugging: Is this normal? [message #1738915] Tue, 26 July 2016 06:22 Go to next message
Taro Kyo is currently offline Taro KyoFriend
Messages: 8
Registered: July 2016
Junior Member
Here's a GIF of what's going on:

http://imgur.com/iXKZ1RJ.gif

As you can see, when running Eclipse, the program starts off being suspended. Weirdly, in the Debug tab, it said the program has been suspended due to a breakpoint, but there aren't any breakpoints in the Breakpoint tab.

Continuing the debugging process, after I pressed Enter to continue execution and to quit the program (caused by "system("pause")" in the main() method), the program exits with a SIGINT error. I should be expecting the program to say it has returned 0x0 or something.

I would like to know why this is happening, and how I should fix this if this is not normal.

Is it because of my code? Here's the source code:

#include <iostream>
#include <memory>
#include <vector>
#include <cstdlib>
using namespace std;
 
class Component {
public:
	virtual ~Component(){}
	virtual shared_ptr<Component> Clone() const = 0;
};
 
class Special : public Component {
	int someNumber;
	void* dangerousPointer;
public:
	Special(const Special& other) : someNumber{other.someNumber} {
		// TODO: clone dangerous pointer if such thing exists
	};
	Special(int someNumber) : someNumber{someNumber} {}
 
	int getSomeNumber() { return someNumber; }
	
	virtual shared_ptr<Component> Clone() const override {
		return make_shared<Special>(*this);
	}
};

class Holder {
public:
	vector<shared_ptr<Component>> components;
	
	Holder(){
		this->components.push_back(shared_ptr<Component>(new Special(40)));
		this->components.push_back(shared_ptr<Special>(new Special(30)));
	}
};
 
int main() {
	cout << "Running..." << endl;
	Holder holder;
	auto other = holder.components[0]->Clone();
	cout << dynamic_cast<Special*>(other.get())->getSomeNumber() << endl;
	system("pause");
	return 0;
}


Thank you for your help in advance.
Re: Main() is suspended upon debugging: Is this normal? [message #1738965 is a reply to message #1738915] Tue, 26 July 2016 11:10 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
A few things going on here that may help:

1) Breakpoint is inserted at main implicitly and automatically. If you want to disable that, go to the launch configuration an uncheck in the debug tab.
2) It looks like your code is compiled without debug information, e.g. you are using the Release configuration
3) Using system("pause") is unusual, how about just a printf/getc or similar instead of launching another program. On my machine (Windows64 with MSYS2) I have no pause available and the program exits fine, but there is an error message about the pause not being found.
Re: Main() is suspended upon debugging: Is this normal? [message #1738982 is a reply to message #1738965] Tue, 26 July 2016 14:16 Go to previous messageGo to next message
Marc Khouzam is currently offline Marc KhouzamFriend
Messages: 357
Registered: July 2009
Senior Member
This may help also:
https://wiki.eclipse.org/CDT/User/FAQ#How_do_I_prevent_the_debugger_from_stopping_on_the_first_line.3F

Marc
Re: Main() is suspended upon debugging: Is this normal? [message #1739098 is a reply to message #1738965] Wed, 27 July 2016 13:59 Go to previous messageGo to next message
Taro Kyo is currently offline Taro KyoFriend
Messages: 8
Registered: July 2016
Junior Member
Jonah Graham wrote on Tue, 26 July 2016 11:10
A few things going on here that may help:

1) Breakpoint is inserted at main implicitly and automatically. If you want to disable that, go to the launch configuration an uncheck in the debug tab.
2) It looks like your code is compiled without debug information, e.g. you are using the Release configuration
3) Using system("pause") is unusual, how about just a printf/getc or similar instead of launching another program. On my machine (Windows64 with MSYS2) I have no pause available and the program exits fine, but there is an error message about the pause not being found.


  1. Thanks for this, and thanks to Marc for the wiki link.
  2. I only have one configuration by default, and that is "Release". I thought in the past, they will have 2 configurations, "Debug" and "Release". Or I was wrong the entire time?
  3. I added "system("pause")" in, is for checking to see why it stops at the first line of main(), and was wondering if it was my code or not. But, it is all moot now that I have #1 answered.

Now the last thing was the output in the Console tab. Is it normal for it to show a red "QUIT (expect SIGINT when unpausing)" message?

[Updated on: Wed, 27 July 2016 14:05]

Report message to a moderator

Re: Main() is suspended upon debugging: Is this normal? [message #1739104 is a reply to message #1739098] Wed, 27 July 2016 14:25 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
Hi Taro,

Not sure why you have only one configuration, in the new project wizard you could have(?) unchecked the Debug configuration:

index.php/fa/26582/0/

You can edit the configurations in the project properties and you can change the current configuration by, Right-click on project, Choose Build Configurations, Set Active, Choose Debug/Release.


As for the error message, this is probably a side effect of the system call leaving the main program in a system sleep. On Windows interrupting child processes is difficult to say the least. (there was a discussion on this topic a few years ago https://dev.eclipse.org/mhonarc/lists/cdt-dev/msg17490.html). Do you get this error message all the time, or only around the system call?

Jonah

Re: Main() is suspended upon debugging: Is this normal? [message #1739338 is a reply to message #1739104] Sat, 30 July 2016 00:18 Go to previous message
Taro Kyo is currently offline Taro KyoFriend
Messages: 8
Registered: July 2016
Junior Member
Thank. The project is a Makefile project imported from somewhere else, so it could be the project may only have 1 configuration set.

I do get the error message around the system call.
Previous Topic:Indexer Problems openjdk8 / Ubuntu 16
Next Topic:conflicting types for ... by C project compilation
Goto Forum:
  


Current Time: Fri Apr 26 05:33:32 GMT 2024

Powered by FUDForum. Page generated in 0.03368 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top