core: add build target for debug unix build

pull/794/head
Milan Rossa 5 years ago committed by Pavol Rusnak
parent 75ddedb0b0
commit 42f1af3aa4
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -123,6 +123,9 @@ build_unix: res ## build unix port
build_unix_frozen: res build_cross ## build unix port with frozen modules
$(SCONS) CFLAGS="$(CFLAGS)" $(UNIX_BUILD_DIR)/micropython $(UNIX_PORT_OPTS) PYOPT="$(PYOPT)" BITCOIN_ONLY="$(BITCOIN_ONLY)" TREZOR_EMULATOR_FROZEN=1
build_unix_debug: res ## build unix port
$(SCONS) --max-drift=1 CFLAGS="$(CFLAGS)" $(UNIX_BUILD_DIR)/micropython $(UNIX_PORT_OPTS) TREZOR_EMULATOR_ASAN=1 TREZOR_EMULATOR_DEBUGGABLE=1
build_cross: ## build mpy-cross port
$(MAKE) -C vendor/micropython/mpy-cross $(CROSS_PORT_OPTS)

@ -314,21 +314,31 @@ env.Replace(
LINK='ld',
SIZE='size',
STRIP='strip',
OBJCOPY='objcopy', )
OBJCOPY='objcopy',
COPT=os.getenv('OPTIMIZE', '-Os'), )
if ARGUMENTS.get('TREZOR_EMULATOR_ASAN', 0):
asan_flags=(
' -fsanitize=address'+
' -fsanitize-blacklist=asan_blacklist.txt'+
' -fno-omit-frame-pointer'+
' -fno-optimize-sibling-calls'
)
env.Replace(
CC=os.getenv('CC') or 'clang',
LINK=os.getenv('LINK') or 'clang',
CFLAGS=asan_flags,
LINKFLAGS=' -Wl,-no_pie' + asan_flags, )
if env.get('ENV').get('DEBUG_BUILD', 0):
import platform
platsys = platform.system()
if ARGUMENTS.get('TREZOR_EMULATOR_DEBUGGABLE', 0):
env.Replace(
OPTIMIZE='-O0',
LINKFLAGS='-Wl,-no_pie' if platsys == "Darwin" else '-Wl,-no-pie'
)
COPT=' -O0 -ggdb',
STRIP='true', )
env.Replace(
TREZOR_MODEL=env.get('ENV').get('TREZOR_MODEL', 'T'), )
env.Replace(
COPT=env.get('OPTIMIZE', env.get('ENV').get('OPTIMIZE', '-Os')),
CCFLAGS='$COPT '
'-g3 '
'-std=gnu99 -Wall -Werror -Wuninitialized -Wno-missing-braces '

@ -73,3 +73,21 @@ You must not use both on the same test.
[pytest-random-order]: https://pypi.org/project/pytest-random-order/
[REGISTERED_MARKERS]: ../REGISTERED_MARKERS
## Extended testing and debugging
### Building for debugging (Emulator only)
Build the debuggable unix binary so you can attach the gdb or lldb.
This removes optimizations and reduces address space randomizaiton.
```sh
make build_unix_debug
```
The final executable is significantly slower due to ASAN(Address Sanitizer) integration.
If you wan't to catch some memory errors use this.
```sh
time ASAN_OPTIONS=verbosity=1:detect_invalid_pointer_pairs=1:strict_init_order=true:strict_string_checks=true TREZOR_PROFILE="" pipenv run make test_emu
```

Loading…
Cancel
Save