Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Radek on November 03, 2012, 04:58:38 pm

Title: An annoying problem with debugger interface
Post by: Radek on November 03, 2012, 04:58:38 pm
The complaint is on debugging structures returned by value. For example:

Code
wxString func()
{
  wxString  rv;

  rv += wxT('a');
  rv += wxT('b');
  rv += wxT('c');

  return rv;
}

Let us try this with a debugger. You can set watch on rv, you can trace through building rv but the value of rv in the Watches window will not change. Nevertheless, the value is built and returned correctly. There seems to be no way of seeing value of rv nor of detecting changes made to rv. The same seems to happen with any structure returned by value.

Let us change the code a bit:

Code
wxString func()
{
  wxString  rv;
  wxString  zz;

  zz += wxT('a');
  zz += wxT('b');
  zz += wxT('c');

  rv = zz;

  return rv;
}

Now, you can watch building zz. All goes well until you reach the assignment statement rv = zz. The debugger crashes here(!) "DWARF-2 internal error". Code Blocks rev. 8500, 32-bit Debian 6.

Speaking the debugger, I also have one wishing. Allow preventing changes in the source files during debugging. A checkbox in the debugger options woud be appreciated. It is a bit boring undoing changes in the source file again and again when you wanted to manipulate the watches window but the cursor happened to be in the source code window...  :-\
Title: Re: An annoying problem with debugger interface
Post by: ollydbg on November 03, 2012, 05:38:33 pm
The complaint is on debugging structures returned by value. For example:

Code
wxString func()
{
  wxString  rv;

  rv += wxT('a');
  rv += wxT('b');
  rv += wxT('c');

  return rv;
}

Let us try this with a debugger. You can set watch on rv, you can trace through building rv but the value of rv in the Watches window will not change. Nevertheless, the value is built and returned correctly. There seems to be no way of seeing value of rv nor of detecting changes made to rv. The same seems to happen with any structure returned by value.

I just test your code under WinXP GCC 4.6.3 wxWidgets 2.8.12, GDB cvs 20121025, C::B nightly build.
I can see rv changes from "" to "abc".
So, I guess that your issue is related to GCC's optimization?


Quote
Speaking the debugger, I also have one wishing. Allow preventing changes in the source files during debugging. A checkbox in the debugger options woud be appreciated. It is a bit boring undoing changes in the source file again and again when you wanted to manipulate the watches window but the cursor happened to be in the source code window...  Undecided
Agreed, unless the gdb can support the debugging on-the-fly code(which I know visual c++ can), let the source code read only when debugging.
Title: Re: An annoying problem with debugger interface
Post by: p2rkw on November 03, 2012, 06:49:09 pm
This may be caused by Named Return Value Optimization. Disable all GCC's optimizations (in debug profile only), rebuild and try again.
Title: Re: An annoying problem with debugger interface
Post by: oBFusCATed on November 03, 2012, 07:43:23 pm
Agreed, unless the gdb can support the debugging on-the-fly code(which I know visual c++ can), let the source code read only when debugging.
I guess we won't see this ever supported in 64bit mode. Visual C++ has it only in 32bit mode, so I guess it is pretty hard or impossible to implement.
Title: Re: An annoying problem with debugger interface
Post by: Radek on November 04, 2012, 07:02:26 am
The only flag for the Debug target is "-g  produce debug symbols". All other flags are unchecked.