Author Topic: An annoying problem with debugger interface  (Read 8455 times)

Offline Radek

  • Multiple posting newcomer
  • *
  • Posts: 104
An annoying problem with debugger interface
« 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...  :-\

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: An annoying problem with debugger interface
« Reply #1 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.
« Last Edit: November 03, 2012, 05:40:55 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: An annoying problem with debugger interface
« Reply #2 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: An annoying problem with debugger interface
« Reply #3 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Radek

  • Multiple posting newcomer
  • *
  • Posts: 104
Re: An annoying problem with debugger interface
« Reply #4 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.