Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sgx: gdb: fix syntax warning in python 3.12+ #691

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

phlip9
Copy link

@phlip9 phlip9 commented Feb 5, 2025

Python 3.12 recently changed how it parses string escapes, so it now warns on unrecognized escape codes. Trying to source intel-sgx/scripts/gdb.py in a recent gdb install results in these error messages:

$ nix shell github:NixOS/nixpkgs/release-24.11#gdb
$ gdb
GNU gdb (GDB) 15.2
(gdb) python-interactive
>>> import sys
>>> sys.version
'3.12.8 (main, Dec  3 2024, 18:42:41) [GCC 13.3.0]'
>>> ^D
(gdb) source intel-sgx/scripts/gdb.py
intel-sgx/scripts/gdb.py:72: SyntaxWarning: invalid escape sequence '\s'
  m = re.match("^(?:\s*0x[0-9a-fA-F]+\s){4}", l)
intel-sgx/scripts/gdb.py:100: SyntaxWarning: invalid escape sequence '\s'
  m=re.match('^\s+\[\s*(\d+)\]\s+(\.text)\s+(\S+)\s+([0-9a-fA-F]+)\s', line)
(gdb)

With an older gdb+python:

$ nix shell github:NixOS/nixpkgs/release-24.05#gdb
$ gdb
GNU gdb (GDB) 14.2
(gdb) python-interactive
>>> import sys
>>> sys.version
'3.11.10 (main, Sep  7 2024, 01:03:31) [GCC 13.2.0]'
>>> ^D
(gdb) source intel-sgx/scripts/gdb.py
(gdb)

This PR fixes the issue by using "raw" strings for all regexes in gdb.py, which prevents python from trying to expand any escape codes. The fix is backwards compatible -- the older python versions sources also interpret it correctly.

Testing everything still works:

$ gdb
GNU gdb (GDB) 15.2
(gdb) attach 37391
(gdb) thread apply all bt
Thread 3 (Thread 0x7fa9a32946c0 (LWP 37392) "run-sgx"):
#0  0x00007ffeddbe8f5e in __vdso_sgx_enter_enclave ()
#1  0x0000564b02b7147b in coenter<enclave_runner::loader::ErasedTcs> () at src/tcs.rs:139
#2  0x0000564b345ad960 in ?? ()
#3  0x0000564b345a95b0 in ?? ()
#4  0x0000564b02b7108e in enclave_runner::tcs::Usercall<T>::coreturn () at src/tcs.rs:43
#5  0x0000564b02ba6ee8 in enclave_runner::usercalls::Work::do_work () at src/usercalls/mod.rs:685
...

(gdb) thread 3
(gdb) source ../rust-sgx/intel-sgx/scripts/gdb.py
(gdb) sgxstate auto target/debug/sgx-test
add symbol table from file "target/debug/sgx-test" at
        .text_addr = 0x7fa998a75b40
Saving original register state

(gdb) bt
#0  compiler_builtins::mem::impls::rep_param () at src/mem/x86_64.rs:310
#1  compiler_builtins::mem::impls::copy_forward () at src/mem/x86_64.rs:39
#2  compiler_builtins::mem::memcpy () at src/mem/mod.rs:25
#3  compiler_builtins::mem::memcpy::memcpy () at src/macros.rs:480
#4  0x00007fc323eccf0d in libunwind::CFI_Parser<libunwind::LocalAddressSpace>::parseCIE(libunwind::LocalAddressSpace&, unsigned long, libunwind::CFI_Parser<libunwind::LocalAddressSpace>::CIE_Info*) ()
...

@Taowyoo Taowyoo self-requested a review February 6, 2025 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants