[Scons-users] Question about splitting debug information

Andrew C. Morrow andrew.c.morrow at gmail.com
Thu Oct 25 14:55:51 EDT 2018


Here is my current state for this. Hasn't yet gone through code review so
may change. I've also pulled out some unnecessary pieces that relate to
some other future projects, so it is possible I've slightly broken it in
the editing of this email:

# Copyright 2018 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import SCons

def _update_builder(env, builder, bitcode):

    base_action = builder.action
    if not isinstance(base_action, SCons.Action.ListAction):
        base_action = SCons.Action.ListAction([base_action])

    # TODO: Make variables for dsymutil and strip, and for the action
strings
    if env.TargetOSIs('darwin'):
        base_action.list.append(
            SCons.Action.Action(
                "dsymutil $TARGET -o ${TARGET}.dSYM",
                "Generating debug info for $TARGET into ${TARGET}.dSYM"
            )
        )
        base_action.list.append(
            SCons.Action.Action(
                "strip -S ${TARGET}",
                "Stripping ${TARGET}"
            )
        )
    elif env.TargetOSIs('posix'):
        base_action.list.extend([
            SCons.Action.Action(
                "${OBJCOPY} --only-keep-debug $TARGET ${TARGET}.debug",
                "Generating debug info for $TARGET into ${TARGET}.debug"
            ),
            SCons.Action.Action(
                "${OBJCOPY} --strip-debug --add-gnu-debuglink
${TARGET}.debug ${TARGET}",
                "Stripping debug info from ${TARGET} and adding
.gnu.debuglink to ${TARGET}.debug"
            ),
        ])
    else:
        pass

    base_emitter = builder.emitter
    def new_emitter(target, source, env):

        if env.TargetOSIs('darwin'):
            debug_file = env.Dir(str(target[0]) + ".dSYM")
        elif env.TargetOSIs('posix'):
            debug_file = env.File(str(target[0]) + ".debug")
        else:
            pass

        target.append(debug_file)

        return (target, source)

    new_emitter = SCons.Builder.ListEmitter([base_emitter, new_emitter])
    builder.emitter = new_emitter

def generate(env):
    if not exists(env):
        return

    for builder in ['Program', 'SharedLibrary', 'LoadableModule']:
        _update_builder(env, env['BUILDERS'][builder])

def exists(env):
    return True

The general idea is to update the relevant builders with emitters that
describe the separate debug files, and additional actions that produce
them. By doing it this way, the debug files can move into and be retrieved
from the cache.

There are some TODOs here. Among the parts that I stripped out as not ready
to show is an improvement that automatically makes it so that if dynamic
library A depends on dynamic library B, then the installation (not shown
here) of the debug information for A depends on the the installation of the
debug info for library B (as does the installation of A depend on the
installation of B).

Suggestions welcome. The more complete version of this code is likely to
land on MongoDB master tomorrow or early next week.

Thanks,
Andrew


On Wed, Oct 24, 2018 at 11:01 AM Martin Ritter <martin.ritter at lmu.de> wrote:

> Hi Gary,
>
> thank you, I overlooked AddPostAction. I now have something which does
> what I want but I'm looking forward to compare that with Andrews
> implementation.
>
> Best Regards,
>
> Martin
>
> On 24/10/2018 15:18, Gary Oberbrunner wrote:
> > The standard approach for this is to use AddPostAction to do your
> > post-build steps, rather than a separate builder. Those operate on the
> > target before its signature is stored.
> >
> > -- Gary
> >
> > On Wed, Oct 24, 2018 at 4:48 AM Martin Ritter <martin.ritter at lmu.de
> > <mailto:martin.ritter at lmu.de>> wrote:
> >
> >     Hi,
> >
> >     I have a question regarding splitting debug information from binaries
> >     and libraries with SCons: What we want to do is to split the debug
> >     information from libraries and executables and put them into separate
> >     files following
> >     https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
> >
> >     So we wrote a simple builder which does just that:
> >
> >     strip_debug = Builder(
> >           action='objcopy --only-keep-debug $SOURCE $TARGET && '
> >           'strip --strip-debug --strip-unneeded $SOURCE && '
> >           'objcopy --add-gnu-debuglink=$TARGET $SOURCE',
> >           suffix='.debug', prefix=".debug/")
> >
> >     but obviously this modifies the original $SOURCE. So when running
> scons
> >     again it will notice that the libraries are not up to date and
> >     relink them.
> >
> >     One solution is to first link the library into the build directory
> and
> >     then copy and strip the files to their final destination. But I was
> >     wondering if there is a way to do this without a temporary copy of
> the
> >     binaries (which is quite some disk space in our project)
> >
> >     Best Regards,
> >
> >     Martin
> >
> >
> >     --
> >     Dr. Martin Ritter
> >
> >     LMU München, Excellence Cluster Universe
> >     Boltzmannstrasse 2, 85748 Garching
> >
> >     Tel: (+49) 89 35831-7152
> >     Fax: (+49) 89 3299-4002
> >
> >     _______________________________________________
> >     Scons-users mailing list
> >     Scons-users at scons.org <mailto:Scons-users at scons.org>
> >     https://pairlist4.pair.net/mailman/listinfo/scons-users
> >
> >
> >
> > --
> > Gary
> >
> > _______________________________________________
> > Scons-users mailing list
> > Scons-users at scons.org
> > https://pairlist4.pair.net/mailman/listinfo/scons-users
> >
>
> --
> Dr. Martin Ritter
>
> LMU München, Excellence Cluster Universe
> Boltzmannstrasse 2, 85748 Garching
>
> Tel: (+49) 89 35831-7152
> Fax: (+49) 89 3299-4002
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20181025/c5efea4f/attachment.html>


More information about the Scons-users mailing list