From 78bde661fcc4b9f37d1bb63e5cea062faeade58b Mon Sep 17 00:00:00 2001 From: Thomas Tendyck Date: Mon, 25 Jan 2021 18:02:16 +0100 Subject: [PATCH 1/2] AB#519 add oegdb as ego-gdb --- src/ego-gdb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 src/ego-gdb diff --git a/src/ego-gdb b/src/ego-gdb new file mode 100755 index 0000000..17e0866 --- /dev/null +++ b/src/ego-gdb @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# Copyright (c) Open Enclave SDK contributors. +# Licensed under the MIT License. + +# Get path of the oegdb script +# See https://mywiki.wooledge.org/BashFAQ/028 for complexities involved +# in determining location of a bash script. ${BASH_SOURCE}, though not perfect, +# is an acceptable solution for oegdb. +# readlink provides additional benefit in getting the absolute path +# to the script directory for systems where BASH_SOURCE is only relative. +OE_GDB_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") + +# Get the path to the debugger libraries relative to the oegdb path. +# Normalize the path by cd-ing and doing a pwd -P. +OE_GDB_LIB_DIR=$(cd "$OE_GDB_DIR/../lib/openenclave/debugger" || exit; pwd -P) + +OE_GDB_PLUGIN_DIR=$OE_GDB_LIB_DIR/gdb-sgx-plugin +OE_GDB_PTRACE_PATH=$OE_GDB_LIB_DIR/liboe_ptrace.so + +export PYTHONPATH=$OE_GDB_PLUGIN_DIR +LD_PRELOAD=$OE_GDB_PTRACE_PATH gdb -iex "directory $OE_GDB_PLUGIN_DIR" -iex "source $OE_GDB_PLUGIN_DIR/gdb_sgx_plugin.py" -iex "set environment LD_PRELOAD" -iex "add-auto-load-safe-path /usr/lib" "$@" From b94dd69b85c5eebb7c3a1a40421d6949ff362d06 Mon Sep 17 00:00:00 2001 From: Thomas Tendyck Date: Wed, 27 Jan 2021 10:42:35 +0100 Subject: [PATCH 2/2] AB#519 make 'ego-gdb ' work --- CMakeLists.txt | 2 ++ src/ego-gdb | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a227819..ed3d015 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ add_custom_target(egobuild ALL DEPENDS ego) install(TARGETS ego-enclave DESTINATION ${CMAKE_INSTALL_DATADIR}) install( PROGRAMS + src/ego-gdb src/ego-go ${CMAKE_BINARY_DIR}/ego DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -49,4 +50,5 @@ install( PROGRAMS ${OpenEnclave_DIR}/../../../bin/oesign RENAME ego-oesign DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(DIRECTORY ${OpenEnclave_DIR}/../debugger DESTINATION ${CMAKE_INSTALL_LIBDIR}/openenclave) install(DIRECTORY ertgo/ DESTINATION go USE_SOURCE_PERMISSIONS) diff --git a/src/ego-gdb b/src/ego-gdb index 17e0866..8c9eece 100755 --- a/src/ego-gdb +++ b/src/ego-gdb @@ -18,5 +18,33 @@ OE_GDB_LIB_DIR=$(cd "$OE_GDB_DIR/../lib/openenclave/debugger" || exit; pwd -P) OE_GDB_PLUGIN_DIR=$OE_GDB_LIB_DIR/gdb-sgx-plugin OE_GDB_PTRACE_PATH=$OE_GDB_LIB_DIR/liboe_ptrace.so +# get all args to gdb preceding the payload executable +while [ $1 ]; do + case $1 in + -ix | -ex | -iex) + # these flags are followed by an argument + ERT_GDB_ARGS+=($1) + shift + ;; + --args) + shift + break + ;; + -*) + # other flags are expected to have no argument + ;; + *) + # this is expected to be the executable + break + esac + ERT_GDB_ARGS+=("$1") + shift +done + +# get the executable and shift such that $@ will be the remaining args +ERT_PAYLOAD=$1 +shift + export PYTHONPATH=$OE_GDB_PLUGIN_DIR -LD_PRELOAD=$OE_GDB_PTRACE_PATH gdb -iex "directory $OE_GDB_PLUGIN_DIR" -iex "source $OE_GDB_PLUGIN_DIR/gdb_sgx_plugin.py" -iex "set environment LD_PRELOAD" -iex "add-auto-load-safe-path /usr/lib" "$@" +LD_PRELOAD=$OE_GDB_PTRACE_PATH gdb -iex "directory $OE_GDB_PLUGIN_DIR" -iex "source $OE_GDB_PLUGIN_DIR/gdb_sgx_plugin.py" -iex "set environment LD_PRELOAD" -iex "add-auto-load-safe-path /usr/lib" \ + "${ERT_GDB_ARGS[@]}" --args "$OE_GDB_DIR/ego-host" "$OE_GDB_DIR/../share/ego-enclave:$ERT_PAYLOAD" "$@"