Dev Tip: Debugging optimized code without a clobber – Rebuilding a module without optimization

Sometimes you have an optimized build for whatever reason (say you’re doing a lot of profiling) but optimizations make non trivial debugging impossible. You don’t have an up to date build without optimization so you whine, start a non optimize build and start looking at bugzilla for 20 mins.

Frankenstein optimized/non optimized build to the rescue! Simply add:

MOZ_OPTIMIZE_FLAGS += -O0 -g
CXXFLAGS += -O0 -g

or for moz.build use:

MOZ_OPTIMIZE_FLAGS += ['-O0', '-g']

or for MSVC:

MOZ_OPTIMIZE_FLAGS += ['-Od']

to the Makefile for the module(s) you’re interested in debugging, for me it was gfx/layers/Makefile.in.

How does this work? Well optimizations are done at the object level and each object file are built to follow the ABI. As long as the ABI is followed, and it really really should, then you can expect this to work without any problems.

Disclaimer: This isn’t supported! If you have problems then do a clobber build.

Advertisements

3 thoughts on “Dev Tip: Debugging optimized code without a clobber – Rebuilding a module without optimization

  1. Looks like we need a few clarifications here.

    In moz.build, use CXXFLAGS. In Makefile.in, use MOZ_OPTIMIZE_FLAGS.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s