Skip to content

Commit

Permalink
Merge pull request hyperledger-labs#130 from cmickeyb/mic.jan04.debug…
Browse files Browse the repository at this point in the history
…_build

Replace "DEBUG" with "PDO_DEBUG_BUILD" flag
  • Loading branch information
g2flyer authored Jan 8, 2019
2 parents 608e88c + 1e8e2cb commit eaed457
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 55 deletions.
2 changes: 1 addition & 1 deletion build/__tools__/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function becho () {
}

function yell () {
becho "$0: $*" >&2;
becho "$(basename $0): $*" >&2;
}

function die() {
Expand Down
4 changes: 2 additions & 2 deletions common/CMakeVariables.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
SET(PDO_TOP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../")


IF($ENV{DEBUG})
SET(DEBUG_FLAGS "-Og" "-g" "-DDEBUG")
IF($ENV{PDO_DEBUG_BUILD})
SET(DEBUG_FLAGS "-Og" "-g" "-DPDO_DEBUG_BUILD=1")
message(STATUS "Compiling in debug mode without optimizations (-Og -g)")
ELSE()
SET(DEBUG_FLAGS "-O2")
Expand Down
7 changes: 4 additions & 3 deletions common/interpreter/gipsy_scheme/GipsyInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,9 @@ void GipsyInterpreter::send_message_to_contract(
ByteArray v(intrinsic_state.begin(), intrinsic_state.end());
inoutContractState->PrivilegedPut(k, v);

#ifdef DEBUG
{//double check intrinsic state
#if PDO_DEBUG_BUILD
{
//double check intrinsic state
ByteArray k(intrinsic_state_key_.begin(), intrinsic_state_key_.end());
ByteArray v = inoutContractState->PrivilegedGet(k);
StringArray isvs = ByteArrayToStringArray(v);
Expand All @@ -562,7 +563,7 @@ void GipsyInterpreter::send_message_to_contract(
SAFE_LOG(PDO_LOG_DEBUG, "double check success");
}
}
#endif
#endif // PDO_DEBUG_BUILD
outStateChangedFlag = true;
}
else
Expand Down
14 changes: 8 additions & 6 deletions common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@

#pragma once

#ifndef DEBUG
#define SAFE_LOG(LEVEL, FMT, ...)
#define SAFE_LOGV(LEVEL, FMT, ...)
#endif /* DEBUG */

#if _UNTRUSTED_
#include "pdo_error.h"
Expand All @@ -40,19 +38,23 @@ namespace pdo
// up in the enclave. With debugging off all logging messages will be
// removed completely

#ifdef DEBUG
#if PDO_DEBUG_BUILD
#undef SAFE_LOG
#define SAFE_LOG(LEVEL, FMT, ...) pdo::logger::LogV(LEVEL, FMT, ##__VA_ARGS__)
#undef SAFE_LOG1
#define SAFE_LOG1(LEVEL, MSG) pdo::logger::Log(LEVEL, MSG)
#endif /* DEBUG */
#endif /* PDO_DEBUG_BUILD */

#else /* _UNTRUSTED_ */

// this will be implemented by the enclave
extern void Log(int level, const char* fmt, ...);

#ifdef DEBUG
#if PDO_DEBUG_BUILD
#undef SAFE_LOG
#define SAFE_LOG(LEVEL, FMT, ...) Log(LEVEL, FMT, ##__VA_ARGS__)
#undef SAFE_LOG1
#define SAFE_LOG1(LEVEL, MSG) Log(LEVEL, MSG)
#endif /* DEBUG */
#endif /* PDO_DEBUG_BUILD */

#endif /* _UNTRUSTED_ */
6 changes: 3 additions & 3 deletions common/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include <string>
#include <vector>

#include "pdo_error.h"
#include "log.h"
#include "pdo_error.h"

extern uint64_t GetTimer(void);

Expand Down Expand Up @@ -51,8 +51,8 @@ namespace pdo
}
}

#ifdef DEBUG
#if PDO_DEBUG_BUILD
#define __TIMEIT__() pdo::utility::Timer __ignore__(__FUNCTION__)
#else
#define __TIMEIT__() {}
#endif
#endif /* PDO_DEBUG_BUILD */
13 changes: 8 additions & 5 deletions eservice/lib/libpdo_enclave/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,21 @@ SOURCE_GROUP("Generated" FILES ${PROJECT_EDGE_SOURCES})
# you may get some undesirable errors.

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
IF($ENV{PDO_DEBUG_BUILD})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og")
ADD_DEFINITIONS(-DPDO_DEBUG_BUILD=1)
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
ADD_DEFINITIONS(-DPDO_DEBUG_BUILD=0)
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpie")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++")

IF($ENV{DEBUG})
ADD_DEFINITIONS(-D DEBUG)
ENDIF()

SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m64")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -O2")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
Expand Down
8 changes: 4 additions & 4 deletions eservice/lib/libpdo_enclave/contract_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ByteArray ContractResponse::SerializeForSigning(void) const
SAFE_LOG(PDO_LOG_DEBUG, "creator id: %s", creator_id_.c_str());
std::copy(creator_id_.begin(), creator_id_.end(), std::back_inserter(serialized));

#ifdef DEBUG
#if PDO_DEBUG_BUILD
std::string debug_contract_hash = ByteArrayToBase64EncodedString(contract_code_hash_);
SAFE_LOG(PDO_LOG_DEBUG, "contract_code_hash: %s", debug_contract_hash.c_str());
#endif
Expand All @@ -127,7 +127,7 @@ ByteArray ContractResponse::SerializeForSigning(void) const
contract_code_hash_.end(),
std::back_inserter(serialized));

#ifdef DEBUG
#if PDO_DEBUG_BUILD
std::string debug_message_hash = ByteArrayToBase64EncodedString(contract_message_hash_);
SAFE_LOG(PDO_LOG_DEBUG, "contract_message_hash: %s", debug_message_hash.c_str());
#endif
Expand All @@ -137,7 +137,7 @@ ByteArray ContractResponse::SerializeForSigning(void) const
contract_message_hash_.end(),
std::back_inserter(serialized));

#ifdef DEBUG
#if PDO_DEBUG_BUILD
std::string debug_state_hash = ByteArrayToBase64EncodedString(output_block_id_);
SAFE_LOG(PDO_LOG_DEBUG, "new state hash: %s", debug_state_hash.c_str());
#endif
Expand All @@ -160,7 +160,7 @@ ByteArray ContractResponse::SerializeForSigning(void) const
}
}

#ifdef DEBUG
#if PDO_DEBUG_BUILD
std::string debug_mhash = ByteArrayToBase64EncodedString(pdo::crypto::ComputeMessageHash(serialized));
SAFE_LOG(PDO_LOG_DEBUG, "serialized contract response message has length %d and hash %s",
serialized.size(), debug_mhash.c_str());
Expand Down
29 changes: 6 additions & 23 deletions eservice/lib/libpdo_enclave/enclave_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ void printf(const char* fmt, ...)
va_start(ap, fmt);
vsnprintf_s(buf, BUFSIZ, fmt, ap);
va_end(ap);
#ifdef DEBUG
#if PDO_DEBUG_BUILD
ocall_Print(buf);
#endif
#endif // PDO_DEBUG_BUILD
} // printf

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Expand All @@ -44,35 +44,18 @@ void Log(int level, const char* fmt, ...)
va_start(ap, fmt);
vsnprintf_s(buf, BUFSIZ, fmt, ap);
va_end(ap);
#ifdef DEBUG
#if PDO_DEBUG_BUILD
ocall_Log(level, buf);
#endif
#endif // PDO_DEBUG_BUILD
} // Log

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
uint64_t GetTimer(void)
{
uint64_t value = 0;
#ifdef ENCLAVE_DEBUG
#if PDO_DEBUG_BUILD
ocall_GetTimer(&value);
#endif
#endif // PDO_DEBUG_BUILD

return value;
} // GetTimer

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
namespace pdo
{
void Log(pdo_log_level_t level, const char* fmt, ...)
{
char buf[BUFSIZ] = {'\0'};
va_list ap;
va_start(ap, fmt);
vsnprintf_s(buf, BUFSIZ, fmt, ap);
va_end(ap);
#ifdef DEBUG
ocall_Log(level, buf);
#endif
} // Log

}
11 changes: 9 additions & 2 deletions eservice/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,25 @@
## -----------------------------------------------------------------
## set up the contract enclave
## -----------------------------------------------------------------
debug_flag = os.environ.get('PDO_DEBUG_BUILD',0)

module_path = 'pdo/eservice/enclave'
module_src_path = os.path.join(script_dir, module_path)

compile_args = [
'-std=c++11',
'-g',
'-Wno-switch',
'-Wno-unused-function',
'-Wno-unused-variable',
'-Wno-strict-prototypes',
]

# by default the extension class adds '-O2' to the compile
# flags, this lets us override since these are appended to
# the compilation switches
if debug_flag :
compile_args += ['-g']

include_dirs = [
module_src_path,
os.path.join(script_dir, 'build', module_path),
Expand Down Expand Up @@ -128,7 +135,7 @@
library_dirs = library_dirs,
define_macros = [
('_UNTRUSTED_', 1),
('DEBUG', None),
('PDO_DEBUG_BUILD', debug_flag),
('SGX_SIMULATOR', SGX_SIMULATOR_value)
],
undef_macros = ['NDEBUG', 'EDEBUG']
Expand Down
13 changes: 10 additions & 3 deletions pservice/lib/libpdo_enclave/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,23 @@ SOURCE_GROUP("Generated" FILES ${PROJECT_EDGE_SOURCES})
# you may get some undesirable errors.

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
IF($ENV{PDO_DEBUG_BUILD})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og")
ADD_DEFINITIONS(-DPDO_DEBUG_BUILD=1)
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
ADD_DEFINITIONS(-DPDO_DEBUG_BUILD=0)
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpie")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++")

IF($ENV{DEBUG})
ADD_DEFINITIONS(-D DEBUG)
IF($ENV{PDO_DEBUG_BUILD})
ADD_DEFINITIONS(-DPDO_DEBUG_BUILD=1)
ENDIF()

SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m64")
Expand Down
4 changes: 2 additions & 2 deletions pservice/lib/libpdo_enclave/enclave_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void printf(const char* fmt, ...)
va_start(ap, fmt);
vsnprintf_s(buf, BUFSIZ, fmt, ap);
va_end(ap);
#ifdef DEBUG
#if PDO_DEBUG_BUILD
ocall_Print(buf);
#endif
} // printf
Expand All @@ -44,7 +44,7 @@ void Log(int level, const char* fmt, ...)
va_start(ap, fmt);
vsnprintf_s(buf, BUFSIZ, fmt, ap);
va_end(ap);
#ifdef DEBUG
#if PDO_DEBUG_BUILD
ocall_Log(level, buf);
#endif
} // Log
2 changes: 1 addition & 1 deletion pservice/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
library_dirs = library_dirs,
define_macros = [
('_UNTRUSTED_', 1),
('DEBUG', None),
('PDO_DEBUG_BUILD', os.environ.get('PDO_DEBUG_BUILD',0)),
('SGX_SIMULATOR', SGX_SIMULATOR_value)
],
undef_macros = ['NDEBUG', 'EDEBUG']
Expand Down

0 comments on commit eaed457

Please sign in to comment.