Skip to content

Commit

Permalink
Use base location of runtime source files, not compiled location (#319)
Browse files Browse the repository at this point in the history
When debugging in GDB, it can be helpful to use tools such as `layout
src` in order to use the source files for a specific runtime. However,
the embedded debugging information points to the copied source directory
in the build directory rather than the canonical source under
`runtime/`. This PR adds a compile flag, `-fdebug-prefix-map`, which
embeds debugging information that points to the canonical runtime
source. This is useful in exotic (but seen!) debugging configurations
where the runtime build directory may have moved or no longer exists.
  • Loading branch information
grg-haas committed Mar 23, 2023
1 parent 747e6a1 commit 9089593
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ rt_option(ENV_SETUP "Set up stack environments like glibc expects" OFF)
rt_option(INTERNAL_STRACE "Debug syscalls" OFF)
rt_option(DEBUG "Enable debugging" OFF)

if(DEFINED EYRIE_SRCDIR)
add_compile_options(-fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=${EYRIE_SRCDIR})
endif()

include_directories($ENV{KEYSTONE_SDK_DIR}/include/edge)
include_directories(tmplib)
include_directories(include)
Expand Down
22 changes: 13 additions & 9 deletions sdk/macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ macro(add_files FILE_LIST DIRWORK)
endforeach()
endmacro()

macro(get_runtime_dir var)
get_filename_component(SRCDIR ${CMAKE_SOURCE_DIR} NAME)
if(${SRCDIR} STREQUAL "sdk")
get_filename_component(${var} ../runtime REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
elseif(${SRCDIR} STREQUAL "keystone")
get_filename_component(${var} ./runtime REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
else()
message(FATAL_ERROR "Don't know how to find runtime from current directory" ${SRCDIR})
endif()
endmacro()

# CMake macro for Eyrie runtime and Keystone Package
macro(add_eyrie_runtime target_name plugins) # the files are passed via ${ARGN}
set(runtime_prefix runtime)
Expand All @@ -95,19 +106,12 @@ macro(add_eyrie_runtime target_name plugins) # the files are passed via ${ARGN}
list(APPEND PLUGIN_FLAGS "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
list(APPEND PLUGIN_FLAGS "-DCMAKE_OBJCOPY=${CMAKE_OBJCOPY}")

get_filename_component(SRCDIR ${CMAKE_SOURCE_DIR} NAME)
if(${SRCDIR} STREQUAL "sdk")
set(EYRIE_SRCDIR ${CMAKE_SOURCE_DIR}/../runtime)
elseif(${SRCDIR} STREQUAL "keystone")
set(EYRIE_SRCDIR ${CMAKE_SOURCE_DIR}/runtime)
else()
message(FATAL_ERROR "Don't know how to find runtime from current directory" ${SRCDIR})
endif()
get_runtime_dir(EYRIE_SRCDIR)

ExternalProject_Add(eyrie-${target_name}
PREFIX ${runtime_prefix}
DOWNLOAD_COMMAND rm -rf ${eyrie_src} && cp -ar ${EYRIE_SRCDIR} ${eyrie_src}
CMAKE_ARGS "${PLUGIN_FLAGS}"
CMAKE_ARGS "${PLUGIN_FLAGS}" -DEYRIE_SRCDIR=${EYRIE_SRCDIR}
BUILD_IN_SOURCE TRUE
BUILD_BYPRODUCTS ${eyrie_src}/eyrie-rt ${eyrie_src}/.options_log
INSTALL_COMMAND "")
Expand Down

0 comments on commit 9089593

Please sign in to comment.