← Back to team overview

kicad-developers team mailing list archive

Re: Separated debug symbols

 

On 10/27/18 11:36 AM, Maciej Suminski wrote:
>> The GNU toolchain also has build IDs, which allows keeping multiple
>> versions of debug information, and
>>
>>
>> https://stackoverflow.com/questions/32861480/cmake-save-stripped-debug-information
>>
>> has a nice fragment for that, although the build ID needs to be
>> generated somewhere (and distros need a way to pass them in for
>> reproducible builds). The ID would be accessible from the About dialog
>> as well so you know which debug package to download.
> 
> Build-IDs seem even better. I will explore this method, thank you for
> the tip.

I have just tested build-IDs. The attribute itself is useful to match
binaries with debug information, but it does not substitute
gnu-debuglink well enough. When only build-IDs are in play, one has to
place the debug information in .build-id/xx/yy...y.debug file where xx
and yy..y are parts of the build-id. It also requires setting
debug-symbol-dir in gdb, making it not very convenient. Another problem
is that the attribute is ELF specific, so it does not work with Windows.

All in all, I have kept gnu-debuglink enabled and added build-ID to
match debug files on Linux. The attached patch also has
KICAD_SPLIT_DEBUG turned on by default.

Cheers,
Orson
From d227ae2b9249050c2ad6b3fbdd33f80c20a97299 Mon Sep 17 00:00:00 2001
From: Maciej Suminski <maciej.suminski@xxxxxxx>
Date: Thu, 25 Oct 2018 20:51:32 +0200
Subject: [PATCH] Added KICAD_SPLIT_DEBUG CMake flag to store debug symbols as
 a separate file

---
 CMakeLists.txt                   | 12 ++++++++++++
 CMakeModules/SplitDebug.cmake    | 32 ++++++++++++++++++++++++++++++++
 cvpcb/CMakeLists.txt             |  4 ++++
 eeschema/CMakeLists.txt          |  5 +++++
 gerbview/CMakeLists.txt          |  5 +++++
 pagelayout_editor/CMakeLists.txt |  5 +++++
 pcb_calculator/CMakeLists.txt    |  5 +++++
 pcbnew/CMakeLists.txt            |  5 +++++
 8 files changed, 73 insertions(+)
 create mode 100644 CMakeModules/SplitDebug.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 41bbe9a03..622374321 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -102,6 +102,10 @@ option( KICAD_INSTALL_DEMOS
     "Install KiCad demos and examples (default ON)"
     ON )
 
+option( KICAD_SPLIT_DEBUG
+    "Saves debugging data to a separate file (default ON)"
+    ON )
+
 # when option KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES is enabled:
 # PYTHON_EXECUTABLE can be defined when invoking cmake
 # ( use -DPYTHON_EXECUTABLE=<python path>/python.exe or python2 )
@@ -120,6 +124,14 @@ if ( KICAD_SCRIPTING_ACTION_MENU AND NOT KICAD_SCRIPTING )
     set ( KICAD_SCRIPTING ON )
 endif()
 
+if( KICAD_SPLIT_DEBUG )
+    if( NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
+        message( WARNING "KICAD_SPLIT_DEBUG makes sense only for debug builds" )
+    endif()
+
+    include( SplitDebug )
+endif()
+
 option( BUILD_GITHUB_PLUGIN "Build the GITHUB_PLUGIN for pcbnew." ON )
 
 option( KICAD_SPICE "Build KiCad with internal Spice simulator." ON )
diff --git a/CMakeModules/SplitDebug.cmake b/CMakeModules/SplitDebug.cmake
new file mode 100644
index 000000000..dd4e56947
--- /dev/null
+++ b/CMakeModules/SplitDebug.cmake
@@ -0,0 +1,32 @@
+# Copyright (C) 2018 CERN
+# @author Maciej Suminski <maciej.suminski@xxxxxxx>
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# SplitDebug() separates debug information to another file, leaving the #
+# original binary stripped and compact. It also sets randomly generated BuildID
+# attribute for both binaries.
+function( SplitDebug target filename )
+    # Generate BuildID
+    string( RANDOM LENGTH 40 ALPHABET "0123456789abcdef" BUILD_ID )
+    message( STATUS "${filename} BuildID = 0x${BUILD_ID}" )
+    set_target_properties( ${target} PROPERTIES LINK_FLAGS "-Wl,--build-id=0x${BUILD_ID}" )
+
+    add_custom_command( TARGET ${target} POST_BUILD
+        COMMAND objcopy --only-keep-debug ${filename} ${filename}.debug
+        COMMAND strip --strip-debug --strip-unneeded ${filename}
+        COMMAND objcopy --add-gnu-debuglink="${filename}.debug" ${filename}
+        COMMENT "Creating a debug information file for '${filename}'"
+    )
+endfunction()
diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt
index eb77f6b68..9c7b55509 100644
--- a/cvpcb/CMakeLists.txt
+++ b/cvpcb/CMakeLists.txt
@@ -193,6 +193,10 @@ if( MAKE_LINK_MAPS )
         LINK_FLAGS "${TO_LINKER},-cref ${TO_LINKER},-Map=_cvpcb.kiface.map" )
 endif()
 
+if( KICAD_SPLIT_DEBUG ) # create a debug info file and strip the output binary
+    SplitDebug( cvpcb_kiface _cvpcb.kiface )
+endif()
+
 # these 2 binaries are a matched set, keep them together:
 if( APPLE )
     # puts binaries into the *.app bundle while linking
diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt
index e56f3c849..491b2e2c2 100644
--- a/eeschema/CMakeLists.txt
+++ b/eeschema/CMakeLists.txt
@@ -376,6 +376,11 @@ set_source_files_properties( eeschema.cpp PROPERTIES
 # if building eeschema, then also build eeschema_kiface if out of date.
 add_dependencies( eeschema eeschema_kiface )
 
+if( KICAD_SPLIT_DEBUG ) # create a debug info file and strip the output binary
+    SplitDebug( eeschema_kiface _eeschema.kiface )
+    SplitDebug( eeschema "eeschema${CMAKE_EXECUTABLE_SUFFIX}" )
+endif()
+
 if( MAKE_LINK_MAPS )
     # generate link map with cross reference
     set_target_properties( eeschema_kiface PROPERTIES
diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt
index 9f76f86a7..27a40f276 100644
--- a/gerbview/CMakeLists.txt
+++ b/gerbview/CMakeLists.txt
@@ -174,6 +174,11 @@ endif()
 # if building gerbview, then also build gerbview_kiface if out of date.
 add_dependencies( gerbview gerbview_kiface )
 
+if( KICAD_SPLIT_DEBUG ) # create a debug info file and strip the output binary
+    SplitDebug( gerbview_kiface _gerbview.kiface )
+    SplitDebug( gerbview "gerbview${CMAKE_EXECUTABLE_SUFFIX}" )
+endif()
+
 # these 2 binaries are a matched set, keep them together
 if( APPLE )
     set_target_properties( gerbview PROPERTIES
diff --git a/pagelayout_editor/CMakeLists.txt b/pagelayout_editor/CMakeLists.txt
index 4e82fab7d..2070f0888 100644
--- a/pagelayout_editor/CMakeLists.txt
+++ b/pagelayout_editor/CMakeLists.txt
@@ -148,6 +148,11 @@ endif()
 # if building pl_editor, then also build pl_editor_kiface if out of date.
 add_dependencies( pl_editor pl_editor_kiface )
 
+if( KICAD_SPLIT_DEBUG ) # create a debug info file and strip the output binary
+    SplitDebug( pl_editor_kiface _pl_editor.kiface )
+    SplitDebug( pl_editor "pl_editor${CMAKE_EXECUTABLE_SUFFIX}" )
+endif()
+
 # these 2 binaries are a matched set, keep them together:
 if( APPLE )
     set_target_properties( pl_editor PROPERTIES
diff --git a/pcb_calculator/CMakeLists.txt b/pcb_calculator/CMakeLists.txt
index 94d6ce469..9ead4402d 100644
--- a/pcb_calculator/CMakeLists.txt
+++ b/pcb_calculator/CMakeLists.txt
@@ -106,6 +106,11 @@ endif()
 # if building pcb_calculator, then also build pcb_calculator_kiface if out of date.
 add_dependencies( pcb_calculator pcb_calculator_kiface )
 
+if( KICAD_SPLIT_DEBUG ) # create a debug info file and strip the output binary
+    SplitDebug( pcb_calculator_kiface _pcb_calculator.kiface )
+    SplitDebug( pcb_calculator "pcb_calculator${CMAKE_EXECUTABLE_SUFFIX}" )
+endif()
+
 # these 2 binaries are a matched set, keep them together
 if( APPLE )
     set_target_properties( pcb_calculator PROPERTIES
diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt
index efe36a5fe..03e4715d2 100644
--- a/pcbnew/CMakeLists.txt
+++ b/pcbnew/CMakeLists.txt
@@ -700,6 +700,11 @@ add_dependencies( pcbnew pcbnew_kiface )
 # generation of autogenerated file
 add_dependencies( pcbnew_kiface_objects specctra_lexer_source_files )
 
+if( KICAD_SPLIT_DEBUG ) # create a debug info file and strip the output binary
+    SplitDebug( pcbnew_kiface "_pcbnew.kiface" )
+    SplitDebug( pcbnew "pcbnew${CMAKE_EXECUTABLE_SUFFIX}" )
+endif()
+
 # these 2 binaries are a matched set, keep them together:
 if( APPLE )
     set_target_properties( pcbnew PROPERTIES
-- 
2.18.0

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups

References