Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Strange behavior of Point in watches
Strange behavior of Point in watches [message #22890] Tue, 25 August 2009 09:42 Go to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hello,
I've encountered strange problem while debugging my code... Here is simplest possible testcase:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;

class win : public TopWindow{
public:
	typedef win CLASSNAME;
	virtual void LeftDown(Point p,dword flags){
		DUMP(p);
	}
};

GUI_APP_MAIN{
	win().Run();
}

I setup breakpoint in LeftDown() and run in debug mode. When the execution stops at the breakpoint, opening Quick watch window and entering "p" yields:
{
  <Upp::Moveable<Upp::Point_<int>, Upp::EmptyClass>> = {
    <Upp::EmptyClass> = {<No data fields>}, <No data fields>}, 
  members of Upp::Point_<int>: 
  x = -1078378568, 
  y = 8388608
}

Same values are shown if I add watch in the bottom panel of theide. But the most interesting (or puzzling) thing is, that the output in log file is correct, i.e. something like "p = [59, 138]".

At first, I thought that it is a problem in watches, but for something like "Point P(10,20);" watches show correct result. It can be very confusing, I was looking for bug almost an hour on absolutely wrong place, because of this...

Just in case this is compiler/platform specific: I use gcc 4.3 on ubuntu.

Regards,
Honza

PS: I'm not sure if this belongs here. If not, feel free to move this topic to some better place.
Re: Strange behavior of Point in watches [message #22891 is a reply to message #22890] Tue, 25 August 2009 10:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
dolik.rce wrote on Tue, 25 August 2009 03:42

Hello,
I've encountered strange problem while debugging my code... Here is simplest possible testcase:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;

class win : public TopWindow{
public:
	typedef win CLASSNAME;
	virtual void LeftDown(Point p,dword flags){
		DUMP(p);
	}
};

GUI_APP_MAIN{
	win().Run();
}

I setup breakpoint in LeftDown() and run in debug mode. When the execution stops at the breakpoint, opening Quick watch window and entering "p" yields:
{
  <Upp::Moveable<Upp::Point_<int>, Upp::EmptyClass>> = {
    <Upp::EmptyClass> = {<No data fields>}, <No data fields>}, 
  members of Upp::Point_<int>: 
  x = -1078378568, 
  y = 8388608
}

Same values are shown if I add watch in the bottom panel of theide. But the most interesting (or puzzling) thing is, that the output in log file is correct, i.e. something like "p = [59, 138]".

At first, I thought that it is a problem in watches, but for something like "Point P(10,20);" watches show correct result. It can be very confusing, I was looking for bug almost an hour on absolutely wrong place, because of this...

Just in case this is compiler/platform specific: I use gcc 4.3 on ubuntu.

Regards,
Honza

PS: I'm not sure if this belongs here. If not, feel free to move this topic to some better place.


It is because correct stack frame for the function is not yet established - gdb reads incorrect values.

If you step inside, you they get corrected.

This is dbg feature, there is nothing we can do about it...

Mirek
Re: Strange behavior of Point in watches [message #22897 is a reply to message #22891] Tue, 25 August 2009 20:44 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

luzr wrote on Tue, 25 August 2009 10:07

It is because correct stack frame for the function is not yet established - gdb reads incorrect values.

If you step inside, you they get corrected.

Thanks for reply. I think I understand what you mean - basically that I asked for the value before entering the function (or it's stack frame, more precisly). BUT: The same problem happens even when stepping inside. Let's take longer function, like:
	virtual void LeftDown(Point p,dword flags){
		DUMP(p);
		p.Offset(10,10);
		Point pt=p;
		DUMP(pt);
		p=pt;
	}

Then at any point in the function p watches yield nonsense. Watches for pt are correct (after it's assignment of course). Does that mean that watching any parameter passed to the function might be incorrect? That would be really confusing, especially for people who doesn't know about it, like me Smile

Honza
Re: Strange behavior of Point in watches [message #22900 is a reply to message #22897] Wed, 26 August 2009 09:00 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, what we get from gdb, we display...

Maybe you could try in gdb alone to see if anything is wrong in theide?

Mirek
Re: Strange behavior of Point in watches [message #22908 is a reply to message #22900] Thu, 27 August 2009 05:06 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Mirek,
Good news, theide is innocent Smile It's all gdb's fault. It's fine to know, I just wish I knew before and did not learning about it "the hard way".

Anyway, I ran following minimalistic program in gdb:
#include <Core/Core.h>
using namespace Upp;

void somefunction(Point p){
	Point pt=p;
	p=pt;
}

CONSOLE_APP_MAIN{
	Point p(10,20);
	somefunction(p);
}
And here is the gdb session:
Quote:

GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) break ConsoleMainFn_()
Breakpoint 1 at 0x804a662: file /media/other/opt/uppsvn/MyApps/test/main.cpp, line 10.
(gdb) break somefunction(Upp::Point_<int>)
Breakpoint 2 at 0x804a63a: file /media/other/opt/uppsvn/MyApps/test/main.cpp, line 5.
(gdb) run
Starting program: /tmp/ptest
[Thread debugging using libthread_db enabled]
[New Thread 0xb7d776d0 (LWP 31862)]
[Switching to Thread 0xb7d776d0 (LWP 31862)]

Breakpoint 1, ConsoleMainFn_ () at /media/other/opt/uppsvn/MyApps/test/main.cpp:10
10 Point p(10,20);
(gdb) next
11 somefunction(p);
(gdb) print p
$1 = {<Upp::Moveable<Upp::Point_<int>, Upp::EmptyClass>> = {<Upp::EmptyClass> = {<No data fields>}, <No data fields>}, x = 10, y = 20}
(gdb) print &p
$2 = (Point *) 0xbf85e0e0
(gdb) c
Continuing.

Breakpoint 2, somefunction (p=
{<Upp::Moveable<Upp::Point_<int>, Upp::EmptyClass>> = {<Upp::EmptyClass> = {<No data fields>}, <No data fields>}, x = -1081745192, y = -1081745184})
at /media/other/opt/uppsvn/MyApps/test/main.cpp:5
5 Point pt=p;
(gdb) print p
$3 = {<Upp::Moveable<Upp::Point_<int>, Upp::EmptyClass>> = {<Upp::EmptyClass> = {<No data fields>}, <No data fields>}, x = -1081745192, y = -1081745184}
(gdb) print &p
$4 = (Point *) 0xbf85e0c0
(gdb) print pt
$5 = {<Upp::Moveable<Upp::Point_<int>, Upp::EmptyClass>> = {<Upp::EmptyClass> = {<No data fields>}, <No data fields>}, x = -1081745192, y = 3683889}
(gdb) print &pt
$6 = (Point *) 0xbf85e0b0
(gdb) next
6 p=pt;
(gdb) next
7 }
(gdb) print p
$7 = {<Upp::Moveable<Upp::Point_<int>, Upp::EmptyClass>> = {<Upp::EmptyClass> = {<No data fields>}, <No data fields>}, x = -1081745192, y = -1081745184}
(gdb) print &p
$8 = (Point *) 0xbf85e0c0
(gdb) print pt
$9 = {<Upp::Moveable<Upp::Point_<int>, Upp::EmptyClass>> = {<Upp::EmptyClass> = {<No data fields>}, <No data fields>}, x = 10, y = 20}
(gdb) print &pt
$10 = (Point *) 0xbf85e0b0
(gdb) c
Continuing.

Program exited normally.
(gdb) quit

As you can see, gdb probably has no idea where is Point p stored in memory. One interesting thing is, that every time I tried, the offset between addresses of p in ConsoleMainFn_ and somefunction were always 0x20. That's probably not a coincdence, unfortunately I couldn't pinpoint yet, why is it happening. For simple types and simple structs it works correctly. I'll try to investigate this bit more and if I find something I post it here.

Regards,
Honza
Re: Strange behavior of Point in watches [message #22948 is a reply to message #22908] Wed, 02 September 2009 04:47 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Helo Mirek!

Sorry it took me so long, but I was busy at work.

I did a little investigation and finally found exact piece of code that causes problems in gdb. I'm not sure what is the real reason, but all the troubles are caused by following constructors:
	Point_(const Point_<int>& pt) : x((T)pt.x), y((T)pt.y) {}
	Point_(const Point_<short>& pt) : x((T)pt.x), y((T)pt.y) {}
	Point_(const Point_<double>& pt) : x((T)pt.x), y((T)pt.y) {}
	Point_(const Point_<int64>& pt) : x((T)pt.x), y((T)pt.y) {}

If you replace those four lines by
	template <class U>
	Point_(const Point_<U>& pt) : x((T)pt.x), y((T)pt.y) {}
watches show correct values. Do you think that this workaround is safe? To my best knowledge it should produce absolutely same results as original code and nobody should try passing there any non-scalar type, so it should not cause any harm... but I'm no expert when it comes to templates Rolling Eyes

Also, during the investigation I found that same problems apply to Size_ and Rect_. Since their anatomy is very similar, it should be possible to apply the same workaround.

Honza

[Updated on: Wed, 02 September 2009 04:49]

Report message to a moderator

Re: Strange behavior of Point in watches [message #22957 is a reply to message #22948] Wed, 02 September 2009 17:59 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
dolik.rce wrote on Tue, 01 September 2009 22:47

Helo Mirek!

Sorry it took me so long, but I was busy at work.

I did a little investigation and finally found exact piece of code that causes problems in gdb. I'm not sure what is the real reason, but all the troubles are caused by following constructors:
	Point_(const Point_<int>& pt) : x((T)pt.x), y((T)pt.y) {}
	Point_(const Point_<short>& pt) : x((T)pt.x), y((T)pt.y) {}
	Point_(const Point_<double>& pt) : x((T)pt.x), y((T)pt.y) {}
	Point_(const Point_<int64>& pt) : x((T)pt.x), y((T)pt.y) {}

If you replace those four lines by
	template <class U>
	Point_(const Point_<U>& pt) : x((T)pt.x), y((T)pt.y) {}
watches show correct values. Do you think that this workaround is safe? To my best knowledge it should produce absolutely same results as original code and nobody should try passing there any non-scalar type, so it should not cause any harm... but I'm no expert when it comes to templates Rolling Eyes

Also, during the investigation I found that same problems apply to Size_ and Rect_. Since their anatomy is very similar, it should be possible to apply the same workaround.

Honza


I do not know... I really hate such workarounds for debugger problems...

Mirek
Re: Strange behavior of Point in watches [message #22958 is a reply to message #22957] Wed, 02 September 2009 19:17 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

luzr wrote on Wed, 02 September 2009 17:59

I do not know... I really hate such workarounds for debugger problems...

Mirek


I fully understand that. The only proper solution is to fix it in gdb. I'll try to file it in their bugzilla and we'll see if they can fix it in few months/years Smile

Honza
Re: Strange behavior of Point in watches [message #22961 is a reply to message #22958] Wed, 02 September 2009 20:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
dolik.rce wrote on Wed, 02 September 2009 13:17

luzr wrote on Wed, 02 September 2009 17:59

I do not know... I really hate such workarounds for debugger problems...

Mirek


I fully understand that. The only proper solution is to fix it in gdb. I'll try to file it in their bugzilla and we'll see if they can fix it in few months/years Smile

Honza



Actually, the only proper solution is to develop own debugger. It is not THAT hard, once you have symbolic and line info - MSC++ in theide does just that. And there are libraries available to provide symbol info.... And, in fact, all we would need is to make generic platform independent debugging interface, rework MSC++ debugger into using it, then implement this for Posix..

But it quite a lot of work, unfortunately... Sad
Re: Strange behavior of Point in watches [message #22964 is a reply to message #22961] Thu, 03 September 2009 10:19 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

luzr wrote on Wed, 02 September 2009 20:43

Actually, the only proper solution is to develop own debugger. It is not THAT hard, once you have symbolic and line info - MSC++ in theide does just that. And there are libraries available to provide symbol info.... And, in fact, all we would need is to make generic platform independent debugging interface, rework MSC++ debugger into using it, then implement this for Posix..

But it quite a lot of work, unfortunately... Sad


Well, it sounds like a good idea, but that would need some volunteers to do it, which will be hard to find, because it's not anything critical...

Anyway, I've got (pretty quick) response to the bug report:
Quote:

This has been fixed somewhere since 6.8 (which is VERY old). If you desperately need to do this, I suggest grabbing/using a snapshot.


Just for your information, "VERY old" means released on March 27, 2008. That is quite long, but it is still listed everywhere on their website as current release. Version 7.0, which will probably behave correctly, should be released soon, but I think their schedule is bit slipping...

I believe that closes this topic (at least until someone decides to rewrite the debugging from scratch). As this is not critical problem (and I'm aware of it), I'll probably just wait till the new version propagates into ubuntu repositories.

Thanks for your patience,
Honza
Re: Strange behavior of Point in watches [message #22965 is a reply to message #22964] Thu, 03 September 2009 11:11 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
dolik.rce wrote on Thu, 03 September 2009 10:19

... I'll probably just wait till the new version propagates into ubuntu repositories.



So looking forward for Ubuntu 10.04 or 10.10? Smile
Re: Strange behavior of Point in watches [message #22974 is a reply to message #22965] Thu, 03 September 2009 19:00 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

mr_ped wrote on Thu, 03 September 2009 11:11

dolik.rce wrote on Thu, 03 September 2009 10:19

... I'll probably just wait till the new version propagates into ubuntu repositories.



So looking forward for Ubuntu 10.04 or 10.10? Smile


That's not very optimistic Laughing
If it takes so long to get into ubuntu, than I can always "steal" it from Debian unstable Smile
Re: Strange behavior of Point in watches [message #22978 is a reply to message #22890] Fri, 04 September 2009 08:32 Go to previous message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Well, the 9.10 is already quite frozen. Although this package will very likely reside in universe repository, so it may be frozen later, but I doubt gdb will release 7.0 soon enough.

At this point it's either 10.04 (in case they release it in next 1-2 months) or somebody putting it into PPA (personal repository at launchpad) for older Ubuntu and you finding it there + adding that PPA. Or 10.10 if they miss 10.04 freeze milestone.

Ubuntu is running ahead quite fast actually, so it's easy to miss the release with your SW, if you don't care and don't follow a good release schedule. Yet even at this frantic speed, when you *need* some SW, even fresh Ubuntu feels suddenly outdated. Weird, but that's how it works.
Previous Topic: tutorial Gui20c's defect
Next Topic: DropList + AddSeparator + mouse wheel problem
Goto Forum:
  


Current Time: Fri Mar 29 00:23:27 CET 2024

Total time taken to generate the page: 0.01316 seconds