Skip to content

Commit

Permalink
Merge pull request #5176 from keithc-ca/debuginfo
Browse files Browse the repository at this point in the history
  • Loading branch information
rwy7 authored May 14, 2020
2 parents d399187 + c12c7cb commit 99d7e52
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 23 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2014, 2019 IBM Corp. and others
# Copyright (c) 2014, 2020 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -112,13 +112,12 @@ Testing/
*.lo
*.o
*.obj
*.dbg
*.debuginfo

# Compiled Dynamic libraries
*.so
*.so.dbg
*.dylib
*.dylib.dbg
*.dSYM
*.def
*.dll
*.exp
Expand Down
6 changes: 2 additions & 4 deletions cmake/modules/OmrTargetSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ include(OmrUtility)
# and split debug info are handled
function(omr_add_library name)
set(options SHARED STATIC OBJECT INTERFACE)
set(oneValueArgs )
set(multiValueArgs )
set(oneValueArgs)
set(multiValueArgs)

foreach(var IN LISTS options oneValueArgs multiValueArgs)
set(opt_${var} "")
endforeach()
cmake_parse_arguments(opt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})


omr_count_true(num_types VARIABLES opt_SHARED opt_STATIC opt_OBJECT opt_INTERFACE)
omr_assert(TEST num_types LESS 2 MESSAGE "Only one of STATIC | SHARED | OBJECT | INTERFACE may be given")

Expand Down Expand Up @@ -75,7 +74,6 @@ function(omr_add_library name)
endif()
endfunction()


# omr_add_executable(name <sources> ...)
# At present, a thin wrapper around add_executable, but it ensures that
# split debug info is handled
Expand Down
48 changes: 44 additions & 4 deletions cmake/modules/OmrUtility.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ endmacro(omr_list_contains)
# processes a template file by first expanding variable references, and then
# evaluating generator expressions. @ONLY and ESCAPE_QUOTES are treated as
# they are for configure_file().
# NOTE: like file(GENERATE ) output is not written until the end cmake evaluation
# NOTE: like file(GENERATE) output is not written until the end of cmake evaluation
function(omr_process_template input output)

set(opts @ONLY ESCAPE_QUOTES)
cmake_parse_arguments(opt "${opts}" "" "" ${ARGN})

Expand All @@ -118,7 +117,7 @@ function(omr_process_template input output)
file(READ "${input_abs}" template)
string(CONFIGURE "${template}" configured_template ${configure_args})
file(GENERATE OUTPUT "${output}" CONTENT "${configured_template}")
endfunction()
endfunction(omr_process_template)

# omr_count_true(<out_var> [<values>...] [VARIABLES <variables>...])
# count the nuber of <values> and <variables> which evaluate to true
Expand All @@ -138,4 +137,45 @@ function(omr_count_true out)
endforeach()
math(EXPR result "${result}")
set("${out}" "${result}" PARENT_SCOPE)
endfunction()
endfunction(omr_count_true)

# return the path of the target ${tgt} in VAR
# (only executable and shared library targets are currently supported)
function(omr_get_target_path VAR tgt)
get_target_property(target_type ${tgt} TYPE)
if(target_type STREQUAL "EXECUTABLE")
get_target_property(target_directory ${tgt} RUNTIME_OUTPUT_DIRECTORY)
get_target_property(target_name ${tgt} RUNTIME_OUTPUT_NAME)
if(NOT target_name)
set(target_name "${tgt}${CMAKE_EXECUTABLE_SUFFIX}")
endif()
elseif(target_type STREQUAL "SHARED_LIBRARY")
get_target_property(target_directory ${tgt} LIBRARY_OUTPUT_DIRECTORY)
get_target_property(target_name ${tgt} LIBRARY_OUTPUT_NAME)
if(NOT target_name)
set(target_name "lib${tgt}${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()
else()
message(FATAL_ERROR "omr_get_target_path: ${tgt} type is ${target_type}")
endif()
set(${VAR} "${target_directory}/${target_name}" PARENT_SCOPE)
endfunction(omr_get_target_path)

# replace the suffix of ${input} with ${new_suffix}
#
# The suffix is defined here as the portion string
# starting with the last "." in the last path segment.
# This is consistent with:
# get_filename_component(suffix ${input} LAST_EXT)
# without requiring cmake version 3.14.
function(omr_replace_suffix VAR input new_suffix)
string(FIND "${input}" "/" slash_index REVERSE)
string(FIND "${input}" "." dot_index REVERSE)
if(dot_index GREATER slash_index)
string(SUBSTRING "${input}" 0 ${dot_index} base)
set(result "${base}${new_suffix}")
else()
set(result "${input}${new_suffix}")
endif()
set(${VAR} "${result}" PARENT_SCOPE)
endfunction(omr_replace_suffix)
8 changes: 5 additions & 3 deletions cmake/modules/platform/toolcfg/gnu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,22 @@ endif()

function(_omr_toolchain_separate_debug_symbols tgt)
set(exe_file "$<TARGET_FILE:${tgt}>")
set(dbg_file "$<TARGET_FILE:${tgt}>.dbg")
if(OMR_OS_OSX)
set(dbg_file "${exe_file}.dSYM")
add_custom_command(
TARGET "${tgt}"
POST_BUILD
COMMAND dsymutil -f ${exe_file} -o ${dbg_file}
COMMAND dsymutil -o "${dbg_file}" "${exe_file}"
)
else()
omr_get_target_path(target_path ${tgt})
omr_replace_suffix(dbg_file "${target_path}" ".debuginfo")
add_custom_command(
TARGET "${tgt}"
POST_BUILD
COMMAND "${CMAKE_OBJCOPY}" --only-keep-debug "${exe_file}" "${dbg_file}"
COMMAND "${CMAKE_OBJCOPY}" --strip-debug "${exe_file}"
COMMAND "${CMAKE_OBJCOPY}" "--add-gnu-debuglink=${dbg_file}" "${exe_file}"
COMMAND "${CMAKE_OBJCOPY}" --add-gnu-debuglink="${dbg_file}" "${exe_file}"
)
endif()
set_target_properties(${tgt} PROPERTIES OMR_DEBUG_FILE "${dbg_file}")
Expand Down
9 changes: 5 additions & 4 deletions cmake/modules/platform/toolcfg/xlc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ if(OMR_OS_ZOS)
endif()
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND "${CMAKE_COMMAND}"
"-DLIBRARY_FILE_NAME=$<TARGET_FILE_NAME:${TARGET_NAME}>"
"-DLIBRARY_FOLDER=$<TARGET_FILE_DIR:${TARGET_NAME}>"
-P "${omr_SOURCE_DIR}/cmake/modules/platform/toolcfg/zos_rename_exports.cmake"
"-DLIBRARY_FILE_NAME=$<TARGET_FILE_NAME:${TARGET_NAME}>"
"-DLIBRARY_FOLDER=$<TARGET_FILE_DIR:${TARGET_NAME}>"
-P "${omr_SOURCE_DIR}/cmake/modules/platform/toolcfg/zos_rename_exports.cmake"
)
endfunction()
else()
Expand All @@ -212,7 +212,8 @@ else()

function(_omr_toolchain_separate_debug_symbols tgt)
set(exe_file "$<TARGET_FILE:${tgt}>")
set(dbg_file "$<TARGET_FILE:${tgt}>.dbg")
omr_get_target_path(target_path ${tgt})
omr_replace_suffix(dbg_file "${target_path}" ".debuginfo")
add_custom_command(
TARGET "${tgt}"
POST_BUILD
Expand Down
8 changes: 4 additions & 4 deletions doc/ddr.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2016, 2018 IBM Corp. and others
Copyright (c) 2016, 2020 IBM Corp. and others
This program and the accompanying materials are made available under
the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -62,8 +62,8 @@ Make sure that OMR was configured to output debug information (Enabled by
default, or pass --enable-debug as above)

```sh
find -name "*.dbg" >filelist
make -f ddr_artifacts.mk TOP_SRCDIR=. DBG_FILE_LIST=./filelist
find -name "*.debuginfo" >filelist
make -f ddr_artifacts.mk TOP_SRCDIR=. DBG_FILE_LIST=filelist
```

## Using DDR for other projects
Expand All @@ -75,5 +75,5 @@ other artifacts, such as libraries, you will need to add them as well.
You need to call a special makefile, which will run ddrgen on your project.

```sh
make -f omr/ddr_artifacts.mk TOP_SRCDIR=. DBG_FILE_LIST=./<filelist>
make -f omr/ddr_artifacts.mk TOP_SRCDIR=. DBG_FILE_LIST=filelist
```

0 comments on commit 99d7e52

Please sign in to comment.