Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#15436 closed defect (not_a_bug)

CONFIG_DEBUG is broken

Reported by: Henning Owned by: developers
Priority: normal Milestone: Barrier Breaker 14.07
Component: packages Version: Trunk
Keywords: Cc:


CONFIG_DEBUG is described as the flag you need to debug an OpenWRT package, but it doesn't work correctly. I noticed three problems with the flags.

1.) include/ always compiles packages with build type "release", it should use type "debug" when CONFIG_DEBUG=y (see patch for possible solution)

2.) scripts/ always strips all binaries, it should not do this with CONFIG_DEBUG=y (see patch for possible solution)

3.) include/ always adds -O2 or -Os (depending on architecture), it should not do so with CONFIG_DEBUG=y. I think this changed from Attitude Adjustment to Trunk, now -Os is always used.

I have yet to find a good solution for 3.) because CONFIG_DEBUG seems to be not available in the context of this file which makes switching harder. Using gdbserver on binaries that have been stripped and/or optimized is a pain, because some lines differ and some variables are just not available anymore.

Fixing these issues would allow to build debug versions of OpenWRT packages with

make package/<name>/compile CONFIG_DEBUG=y

Attachments (2)

rstrip.patch (374 bytes) - added by Henning 4 years ago.
Patch for Attitude Adjustment scripts/
cmake.patch (1.2 KB) - added by Henning 4 years ago.
Patch for Attitude Adjustment include/

Download all attachments as: .zip

Change History (8)

Changed 4 years ago by Henning

Patch for Attitude Adjustment scripts/

Changed 4 years ago by Henning

Patch for Attitude Adjustment include/

comment:1 Changed 4 years ago by nbd

  • Resolution set to not_a_bug
  • Status changed from new to closed

1) what is the advantage of changing the build type?

2) that's intentional. stripping is controlled separately.
It's useful to have the binaries with debug symbols on the host and without debug symbols on the target (for use with gdbserver).

3) i think that should also be controlled separately. for many cases of debugging stuff, it's useful to have the generated binaries on the device stay the same as without CONFIG_DEBUG, but also to have some extra debug info available on the host.

feel free to propose patches to add extra options for the things that you want, but please send them to the list instead of opening tickets, as described in

comment:2 Changed 4 years ago by Henning

As far as I understand CMake the buildtype is the normal way to tell cmake what you want... Debug, Release (and two more options that trigger size-optimizations). Using the Release-Type might make the CMake script to include optimizations you don't want for debugging.

About the "CONFIG_DEBUG" thing, I just followed this description:

It says that "CONFIG_DEBUG" is the switch you should use to remotely debug OpenWRT executables, which is broken at the moment because you get optimization (-Obla) AND stripping even with this switch.

Ever tried to use (remote)gdb on an executable compiled with "-O2" ?

comment:3 Changed 4 years ago by nbd

I regularly use gdb on executables compiled with -O2 or -Os. Sometimes a bit of context is missing, but I can usually find what I need.
What I usually do for debugging is switching from sstrip to strip. The images are still reasonably small, debug info does not make it to the device, but gdb has everything it needs on the host.
You usually never need unstripped binaries on the target system.

As for optimization: the CFLAGS are controlled by the OpenWrt build system already, so I don't see what difference the build type will make.

comment:4 Changed 4 years ago by Henning

For me -O2 (the default for x86 builds) made sure that gdb was even unable to step properly from line to line... and some variables were just missing because they had been optimized away. That is an unnecessary headache that could easily be avoided with a switch that turns off optimization.

As for Cmake build type, you have no guarantee that the build-type only changes the compiler settings. I think it would be a cleaner solution to set the build-type (and both release/debug compiler flags).

comment:5 Changed 4 years ago by jow

You can try

make package/foo/{clean,compile} V=sc CONFIG_TARGET_OPTIMIZATION="-O0"

to override the optimizer flag selectively for one package only.

comment:6 Changed 4 years ago by jow

  • Milestone changed from Attitude Adjustment 12.09 to Barrier Breaker 14.07

Milestone Attitude Adjustment 12.09 deleted

Add Comment

Modify Ticket

as closed .
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.