mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-07 12:16:24 +00:00

Update the `addr2line` script so that: - line info is printed in a more convenient format, e.g. ``` 0: c at wasm-micro-runtime/test-tools/addr2line/trap.c:5:1 1: b at wasm-micro-runtime/test-tools/addr2line/trap.c:11:12 2: a at wasm-micro-runtime/test-tools/addr2line/trap.c:17:12 ``` similar to how Rust prints stack traces when there's a panic. In an IDE, the user can conveniently click on the printed path and be redirected to the file line. - a new `--no-addr` argument can be provided to the script It can be used in fast interpreter mode (that is not supported by the script otherwise) or with older wamr versions (where the stack trace only had the function index info and not the function address). In that case, `wasm-objdump` is used to get the function name from the index and `llvm-dwarfdump` to obtain the location info (where the line refers to the start of the function).
91 lines
2.6 KiB
CMake
91 lines
2.6 KiB
CMake
# Copyright (C) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
if (APPLE)
|
|
set (HAVE_FLAG_SEARCH_PATHS_FIRST 0)
|
|
set (CMAKE_C_LINK_FLAGS "")
|
|
set (CMAKE_CXX_LINK_FLAGS "")
|
|
endif ()
|
|
|
|
if (NOT DEFINED WASI_SDK_DIR)
|
|
set (WASI_SDK_DIR "/opt/wasi-sdk")
|
|
endif ()
|
|
|
|
if (DEFINED WASI_SYSROOT)
|
|
set (CMAKE_SYSROOT "${WASI_SYSROOT}")
|
|
endif ()
|
|
|
|
set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang")
|
|
set (CMAKE_ASM_COMPILER "${WASI_SDK_DIR}/bin/clang")
|
|
set (CMAKE_EXE_LINKER_FLAGS "-target wasm32-wasi")
|
|
|
|
################ wabt and wamrc dependencies ################
|
|
message(CHECK_START "Detecting WABT")
|
|
if(NOT (DEFINED WABT_DIR OR DEFINED CACHE{WABT_DIR}))
|
|
find_path(WABT_DIR
|
|
wabt
|
|
PATHS /opt
|
|
NO_DEFAULT_PATH
|
|
NO_CMAKE_FIND_ROOT_PATH
|
|
)
|
|
if(DEFINED WABT_DIR)
|
|
set(WABT_DIR ${WABT_DIR}/wabt)
|
|
endif()
|
|
endif()
|
|
if(WABT_DIR)
|
|
message(CHECK_PASS "found")
|
|
else()
|
|
message(CHECK_FAIL "not found")
|
|
endif()
|
|
|
|
message(CHECK_START "Detecting WASM_OBJDUMP at ${WABT_DIR}")
|
|
find_program(WASM_OBJDUMP
|
|
wasm-objdump
|
|
PATHS "${WABT_DIR}/bin"
|
|
NO_DEFAULT_PATH
|
|
NO_CMAKE_FIND_ROOT_PATH
|
|
)
|
|
if(WASM_OBJDUMP)
|
|
message(CHECK_PASS "found")
|
|
else()
|
|
message(CHECK_FAIL "not found")
|
|
endif()
|
|
if((NOT EXISTS ${WASM_OBJDUMP}) )
|
|
message(FATAL_ERROR "Please make sure to have wasm-objdump under the path=${WABT_DIR}/bin ")
|
|
endif()
|
|
|
|
set(WAMR_COMPILER_DIR ${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build)
|
|
message(CHECK_START "Detecting WAMR_COMPILER at ${WAMR_COMPILER_DIR}")
|
|
find_file(WAMR_COMPILER
|
|
wamrc
|
|
PATHS "${CMAKE_CURRENT_LIST_DIR}/../../../wamr-compiler/build"
|
|
NO_DEFAULT_PATH
|
|
NO_CMAKE_FIND_ROOT_PATH
|
|
)
|
|
if(WAMR_COMPILER)
|
|
message(CHECK_PASS "found")
|
|
else()
|
|
message(CHECK_FAIL "not found")
|
|
endif()
|
|
if((NOT EXISTS ${WAMR_COMPILER}) )
|
|
message(FATAL_ERROR "Please build wamrc under the path=${WAMR_ROOT_DIR}/wamr-compiler/")
|
|
endif()
|
|
|
|
################ wasm and aot compilation ################
|
|
function (compile_sample SOURCE_FILE)
|
|
get_filename_component (FILE_NAME ${SOURCE_FILE} NAME_WLE)
|
|
set (WASM_MODULE ${FILE_NAME}.wasm)
|
|
add_executable (${WASM_MODULE} ${SOURCE_FILE})
|
|
|
|
add_custom_target(
|
|
wasm_to_aot
|
|
ALL
|
|
DEPENDS ${WAMR_COMPILER} ${WASM_MODULE}
|
|
# Use --enable-dump-call-stack to generate stack trace (addr2line)
|
|
COMMAND ${WAMR_COMPILER} --size-level=0 --enable-dump-call-stack -o wasm-apps/trap.aot wasm-apps/trap.wasm
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
)
|
|
endfunction ()
|
|
|
|
set(CMAKE_BUILD_TYPE Debug) # Otherwise no debug symbols (addr2line)
|
|
compile_sample(trap.c) |