Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Step Return does not work properly(Debugging, Step Return)
Step Return does not work properly [message #1805367] Fri, 12 April 2019 16:44 Go to next message
Ahmad Shahba is currently offline Ahmad ShahbaFriend
Messages: 2
Registered: April 2019
Junior Member
I have written a very simple C++ project that I am trying to debug. I am seeing a strange behavior from Step Return in debug mode. Here is the code:

main.cpp file
#include <iostream>
#include "Foo_bar.h"
#include "Point.h"

using namespace std;

int main(){

	Point p1(1, 2);
	p1.printPointInfo(cout);

	Point p2 = Foo_bar(p1);
	p2.printPointInfo(cout);

	cout << "we are done " << endl;
}



Point.h file
#ifndef POINT_H_
#define POINT_H_

#include <iostream>

class Point{

public:

	// counter
	static std::size_t counter;

	// Default constructor
	Point() = default;

	// Regular constructor
	Point(const double &x_, const double &y_) : x(x_), y(y_) {};

	// Copy-constructor
	Point(const Point &rhs);

	// Print contents of the Point
	void printPointInfo(std::ostream &os) const;

private:
	double x = 0, y = 0;
};
#endif /* POINT_H_ */


Point.cpp file
#include "Point.h"

std::size_t Point::counter = 0;

Point::Point(const Point &rhs){

	std::cout << "copy-constructor is called:" << (++counter) << std::endl;
	x = rhs.x;
	y = rhs.y;

}

void Point::printPointInfo(std::ostream &os) const {

	os << x << " " << y << std::endl;

}



Foo_bar.h file
#ifndef FOO_BAR_H_
#define FOO_BAR_H_
#include "Point.h"
Point Foo_bar(Point arg);
#endif /* FOO_BAR_H_ */



Foo_bar.cpp file
#include "Foo_bar.h"
Point Foo_bar(Point arg)
{
    Point local = arg;
    return local;
}



As you can see, Foo_bar is called by main. I set a breakpoint at the first line of Foo_bar. The code stops on this line. When I hit Step Return, Eclipse exits Foo_bar and continues to execute the rest of the code. I expected a different behavior. I expected Eclipse to exit Foo_bar and goes to the "main" and wait when Step Return is performed.

Please let me know if I am missing anything here. BTW, I am using Eclipse IDE for C/C++ Developers, Version: 2019-03 (4.11.0)
  • Attachment: Foo_bar.h
    (Size: 0.12KB, Downloaded 55 times)
  • Attachment: Foo_bar.cpp
    (Size: 0.10KB, Downloaded 72 times)
  • Attachment: main.cpp
    (Size: 0.24KB, Downloaded 75 times)
  • Attachment: Point.cpp
    (Size: 0.29KB, Downloaded 56 times)
  • Attachment: Point.h
    (Size: 0.46KB, Downloaded 80 times)
Re: Step Return does not work properly [message #1805384 is a reply to message #1805367] Sat, 13 April 2019 01:41 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
I tried it with 2018-12 and it works as expected..
Are you sure the rest of the code is being executed and the program isn't terminating before/during the return?

Try placing a breakpoint on the line following the return.
Does it stop there?

I'm pretty sure that the Step Return is a GDB function and not something in Eclipse/CDT

I could be wrong and you may have encountered a bug.
If you can't resolve this you should submit a bug report.
https://bugzilla.redhat.com/bugzilla

Re: Step Return does not work properly [message #1805387 is a reply to message #1805384] Sat, 13 April 2019 02:30 Go to previous message
Ahmad Shahba is currently offline Ahmad ShahbaFriend
Messages: 2
Registered: April 2019
Junior Member
Thanks David. Your guess is correct. I put a breakpoint in the , right after Foo_bar is called. When I hit Step Return inside Foo_bar, execution fails and it never returns to the main. I should emphasize that if I go through this program line by line using Step Over, the debugger behaves as expected. I will report this bug on bugzilla
Previous Topic:Indexer is not ignoring header file as it should
Next Topic:Debugger issue
Goto Forum:
  


Current Time: Thu Apr 25 07:18:33 GMT 2024

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

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

Back to the top