Re: Question about splitting debug information

"Andrew C. Morrow" <[email protected]>
Newsgroups gmane.comp.programming.tools.scons.user
Message-ID <CA+Acj4eS8B=ts05kv6w8cy53WwV_nVMZBtmxohaQ7srXViHX5A@mail.gmail.com>
In the broader build system where I'm using this, we wil indeed have a top
level command line Option called --enable-split-debug, which defaults to
false, and this tool is only loaded if it is set. So it is opt-in. For most
developers doing a compile/test/debug/edit loop, separate debug information
isn't useful, necessary, or worth the additional time. But great for
releases!

On Thu, Oct 25, 2018 at 4:31 PM Jason Kenny <[email protected]> wrote:

> The only suggestion I would have is that you might want a variable to
> control the separation should happen or not.
> The base of the imple used in Parts is here https://tinyurl.com/y7dnvx5c
> as an example
>
> it provided the ability to not make the debug information via an variable
> that can be set in the environment or the command line ( ie IGNORE_PDB =
> True | False)
>
> The form used in Parts extends the env["PDB"]="debug file" used with the
> windows compilers. The one tweak I would make in the Parts version would be
> to tweak the logic to auto add extension such as .pdb or .debug, etc (
> which you do nicely in your version)
>
> Jason
> ------------------------------
> *From:* Scons-users <[email protected]> on behalf of Andrew
> C. Morrow <[email protected]>
> *Sent:* Thursday, October 25, 2018 1:55 PM
> *To:* SCons users mailing list
> *Subject:* Re: [Scons-users] Question about splitting debug information
>
>
> 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
> <https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.apache.org%2Flicenses%2FLICENSE-2.0&data=02%7C01%7C%7Cffd583f52a654331732a08d63aab87fc%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636760905722827894&sdata=4dYg4%2FTcUbUg%2BTR8iq0oi%2ByaZJ1QU22VLWc9sk2M9TI%3D&reserved=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 <[email protected]>
> 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 <[email protected]
> > <mailto:[email protected]>> 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
> <https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsourceware.org%2Fgdb%2Fonlinedocs%2Fgdb%2FSeparate-Debug-Files.html&data=02%7C01%7C%7Cffd583f52a654331732a08d63aab87fc%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636760905722827894&sdata=8gt5UHMPO%2BkiRHZQnKt8KXPgWw5wSgF18mVSYwMPpHo%3D&reserved=0>
> >
> >     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
> >     [email protected] <mailto:[email protected]>
> >     https://pairlist4.pair.net/mailman/listinfo/scons-users
> <https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpairlist4.pair.net%2Fmailman%2Flistinfo%2Fscons-users&data=02%7C01%7C%7Cffd583f52a654331732a08d63aab87fc%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636760905722984404&sdata=XTLh0arwb6AqwkxRduVT3TP01EPQiu5jJMPAcvLbA%2Bw%3D&reserved=0>
> >
> >
> >
> > --
> > Gary
> >
> > _______________________________________________
> > Scons-users mailing list
> > [email protected]
> > https://pairlist4.pair.net/mailman/listinfo/scons-users
> <https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpairlist4.pair.net%2Fmailman%2Flistinfo%2Fscons-users&data=02%7C01%7C%7Cffd583f52a654331732a08d63aab87fc%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636760905722984404&sdata=XTLh0arwb6AqwkxRduVT3TP01EPQiu5jJMPAcvLbA%2Bw%3D&reserved=0>
> >
>
> --
> 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
> [email protected]
> https://pairlist4.pair.net/mailman/listinfo/scons-users
> <https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpairlist4.pair.net%2Fmailman%2Flistinfo%2Fscons-users&data=02%7C01%7C%7Cffd583f52a654331732a08d63aab87fc%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636760905722984404&sdata=XTLh0arwb6AqwkxRduVT3TP01EPQiu5jJMPAcvLbA%2Bw%3D&reserved=0>
>
>

_______________________________________________
Scons-users mailing list
[email protected]
https://pairlist4.pair.net/mailman/listinfo/scons-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.