Skip to content

Debugging and Profiling

Christian Priebe edited this page May 31, 2019 · 1 revision

sgx-lkl can be used with gdb to trace both the kernel part and running the applications. This is described in the README.md

Tracing

There are also a number of environment variables that can be set to log additional information:

  • SGXLKL_TRACE_LKL_SYSCALL
  • SGXLKL_TRACE_INTERNAL_SYSCALL
  • SGXLKL_TRACE_HOST_SYSCALL
  • SGXLKL_TRACE_MMAP

SGXLKL_TRACE_LKL_SYSCALL

When SGXLKL_TRACE_LKL_SYSCALL is set SGX-LKL will print all system calls issued by the application like this:

[  LKL SYSCALL ] [tid=1  ] sethostname  161     (140734608148320, 3, 0, 0, 0, 0) = 0
[  LKL SYSCALL ] [tid=1  ] open 1024    (/bin/iperf, 0, 0, 0) = 3
[  LKL SYSCALL ] [tid=1  ] read 63      (3, 211798384, 960, 0, 0, 0) = 960
[  LKL SYSCALL ] [tid=1  ] lseek        62      (3, 0, 0, 0, 0, 0) = 0
[  LKL SYSCALL ] [tid=1  ] read 63      (3, 4194304, 8192, 0, 0, 0) = 8192
[  LKL SYSCALL ] [tid=1  ] lseek        62      (3, 4096, 0, 0, 0, 0) = 4096
[  LKL SYSCALL ] [tid=1  ] read 63      (3, 6295552, 8192, 0, 0, 0) = 8192
[  LKL SYSCALL ] [tid=1  ] close        57      (3, 0, 0, 0, 0, 0) = 0
[  LKL SYSCALL ] [tid=1  ] open 1024    (/lib/libiperf.so.0, 524288, 0, 0) = 3
[  LKL SYSCALL ] [tid=1  ] fcntl        25      (3, 2, 1, 0, 0, 0) = 0
[  LKL SYSCALL ] [tid=1  ] fstat        80      (3, 211798224, 0, 0, 0, 0) = 0
[  LKL SYSCALL ] [tid=1  ] read 63      (3, 211797056, 960, 0, 0, 0) = 960
[  LKL SYSCALL ] [tid=1  ] lseek        62      (3, 0, 0, 0, 0, 0) = 0

Profiling

Support for profiling SGX-LKL with perf is currently limited to simulation mode. By default, only SGX-LKL symbols but no symbols of the application or its dependencies are available to perf due to the in-enclave linking/loading and the fact that perf has no access to the executables and libraries within the disk image. By mounting the disk image and setting SGXLKL_DEBUGMOUNT to the path of the mount point, perf can be enabled to resolve these symbols. The following shows a simple example of how to use SGXLKL_DEBUGMOUNT with perf.

mkdir mnt_debug
mount -o loop ./sgxlkl-disk.img ./mnt_debug
SGXLKL_DEBUGMOUNT=${PWD}/mnt_debug perf <perf options>... <sgx-lkl>/build/sgx-lkl-run ./sgxlkl-disk.img <executable>
umount ./mnt_debug

Note: This requires SGX-LKL to be built with DEBUG=true and without RELEASE=true.