From 32fe5d20af0bed268c4991f6095f25ee54bf82cf Mon Sep 17 00:00:00 2001 From: Milan Rossa Date: Tue, 9 Oct 2018 14:35:52 +0200 Subject: [PATCH] unix: emulator debug build options --- SConscript.unix | 10 +++++++++- docs/build.md | 12 ++++++++++++ embed/trezorhal/touch.h | 6 +++--- emu.sh | 11 ++++++++--- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/SConscript.unix b/SConscript.unix index 1e9a22686..f630b8838 100644 --- a/SConscript.unix +++ b/SConscript.unix @@ -246,11 +246,19 @@ env.Replace( STRIP='strip', OBJCOPY='objcopy', ) +if env.get('ENV').get('DEBUG_BUILD', 0): + import platform + platsys = platform.system() + env.Replace( + OPTIMIZE='-O0', + LINKFLAGS='-Wl,-no_pie' if platsys == "Darwin" else '-Wl,-no-pie' + ) + env.Replace( TREZOR_MODEL=env.get('ENV').get('TREZOR_MODEL', 'T'), ) env.Replace( - COPT=env.get('ENV').get('OPTIMIZE', '-Os'), + COPT=env.get('OPTIMIZE', env.get('ENV').get('OPTIMIZE', '-Os')), CCFLAGS='$COPT ' '-g3 ' '-std=gnu99 -Wall -Werror -Wuninitialized ' diff --git a/docs/build.md b/docs/build.md index 84b7961ec..bc68668e5 100644 --- a/docs/build.md +++ b/docs/build.md @@ -98,3 +98,15 @@ Use `make upload` to upload the firmware to a production device (with a bootload For flashing firmware to blank device (without bootloader) use `make flash`, or `make flash STLINK_VER=v2-1` if using a ST-LINK/V2.1 interface. You need to have OpenOCD installed. + + +## Building for debugging and hacking in Emulator (Unix port) + +Build the debuggable unix binary so you can attach the gdb or lldb. +This removes optimizations and reduces address space randomizaiton. +Beware that this will significantly bloat the final binary +and the firmware runtime memory limit HEAPSIZE may have to be increased. + +```sh +DEBUG_BUILD=1 make build_unix +``` diff --git a/embed/trezorhal/touch.h b/embed/trezorhal/touch.h index 8e61d14ed..2ea6aa55b 100644 --- a/embed/trezorhal/touch.h +++ b/embed/trezorhal/touch.h @@ -32,8 +32,8 @@ void touch_power_off(void); uint32_t touch_read(void); uint32_t touch_click(void); uint32_t touch_is_detected(void); -inline uint16_t touch_unpack_x(uint32_t evt) { return (evt >> 12) & 0xFFF; } -inline uint16_t touch_unpack_y(uint32_t evt) { return (evt >> 0) & 0xFFF; } -inline uint32_t touch_pack_xy(uint16_t x, uint16_t y) { return ((x & 0xFFF) << 12) | (y & 0xFFF); } +static inline uint16_t touch_unpack_x(uint32_t evt) { return (evt >> 12) & 0xFFF; } +static inline uint16_t touch_unpack_y(uint32_t evt) { return (evt >> 0) & 0xFFF; } +static inline uint32_t touch_pack_xy(uint16_t x, uint16_t y) { return ((x & 0xFFF) << 12) | (y & 0xFFF); } #endif diff --git a/emu.sh b/emu.sh index 0eab3568e..d6fca1ee4 100755 --- a/emu.sh +++ b/emu.sh @@ -4,9 +4,9 @@ source emu.config 2>/dev/null EXE=build/unix/micropython PYOPT="${PYOPT:-1}" -MAIN="${MAIN:-main.py}" +MAIN="${MAIN:-${PWD}/src/main.py}" BROWSER="${BROWSER:-chromium}" -HEAPSIZE="${HEAPSIZE:-800K}" +HEAPSIZE="${HEAPSIZE:-50M}" SOURCE_PY_DIR="${SOURCE_PY_DIR:-src}" ARGS="-O${PYOPT} -X heapsize=${HEAPSIZE}" @@ -16,7 +16,12 @@ cd `dirname $0`/$SOURCE_PY_DIR case "$1" in "-d") shift - gdb --args ../$EXE $ARGS $* $MAIN + OPERATING_SYSTEM=$(uname) + if [ $OPERATING_SYSTEM == "Darwin" ]; then + PATH=/usr/bin /usr/bin/lldb -f ../$EXE -- $ARGS $* $MAIN + else + gdb --args ../$EXE $ARGS $* $MAIN + fi ;; "-r") shift