Author Topic: How to add gcc option "-femit-class-debug-always" to a single cpp file in cbp  (Read 1493 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5931
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Hi, when debugging Code::Blocks's plugin, I always see "incomplete type" message when gdb try to inspect some variables.

Those variable types (such as a variable has the type wxCommandEvent) are defined in wxWidgets library, but the debugee is linking to the release version of the wxWidgets library.

The solution to this kinds of issue is to adding the g++ build option "-femit-class-debug-always" when building the project(cbp file).

But I don't want to every cpp files in the cbp file to have such option, because there are so many cpp files in the project, once this option is added, I need to rebuild the whole project.

What I need is to enable this option only on a single cpp file(I just debug this file). How can I do that?

Any ideas? It looks like I need to tweak the build option on the single cpp file. So, something in the cpp file's property dialog? See the image shot below.

Thanks.

There are some discussion about the  "-femit-class-debug-always" option:

1, [solved] Creating a gdb Pretty-Printer for wxIPV4address

2, GDB can not show the type info of wxCommandEvent
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5931
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
OK, I think I find the solution.

See below:

I just edit the cpp file 's build option dialog, check on the option: use the custom command to build this file.

Code
$compiler $options -femit-class-debug-always $includes -c $file -o $object

And now, I can see the variables contents now under GDB.

I think this is a nice feature which can help use to debug the client code which link to a release version of a third part library.


EDIT:

Oh, no, I see the problem still exists.



« Last Edit: March 02, 2024, 02:32:19 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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5931
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5931
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
FYI:

This problem is totally solved now.

See the solution here:

https://github.com/ssbssa/gdb/issues/9#issuecomment-1980016412

That actual change you need to do is to change the build option for a single cpp file to:

Code
$compiler $options -DNOPCH -femit-class-debug-always $includes -c $file -o $object

Happy coding and happy debugging.
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.