Skip to content

Commit 535b09c

Browse files
authored
GH-126910: Allow most native profilers and debuggers to unwind through JIT frames (GH-143548)
1 parent 1887a95 commit 535b09c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Set frame pointers in ``x86_64-unknown-linux-gnu`` JIT code, allowing
2+
most native profilers and debuggers to unwind through them.

Tools/jit/_targets.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class _Target(typing.Generic[_S, _R]):
5151
debug: bool = False
5252
verbose: bool = False
5353
cflags: str = ""
54+
frame_pointers: bool = False
5455
llvm_version: str = _llvm._LLVM_VERSION
5556
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
5657
pyconfig_dir: pathlib.Path = pathlib.Path.cwd().resolve()
@@ -174,10 +175,13 @@ async def _compile(
174175
"-o",
175176
f"{s}",
176177
f"{c}",
177-
*self.args,
178-
# Allow user-provided CFLAGS to override any defaults
179-
*shlex.split(self.cflags),
180178
]
179+
if self.frame_pointers:
180+
frame_pointer = "all" if opname == "shim" else "reserved"
181+
args_s += ["-Xclang", f"-mframe-pointer={frame_pointer}"]
182+
args_s += self.args
183+
# Allow user-provided CFLAGS to override any defaults
184+
args_s += shlex.split(self.cflags)
181185
await _llvm.run(
182186
"clang", args_s, echo=self.verbose, llvm_version=self.llvm_version
183187
)
@@ -615,7 +619,9 @@ def get_target(host: str) -> _COFF32 | _COFF64 | _ELF | _MachO:
615619
condition = "defined(__x86_64__) && defined(__linux__)"
616620
args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0", "-fno-plt"]
617621
optimizer = _optimizers.OptimizerX86
618-
target = _ELF(host, condition, args=args, optimizer=optimizer)
622+
target = _ELF(
623+
host, condition, args=args, optimizer=optimizer, frame_pointers=True
624+
)
619625
else:
620626
raise ValueError(host)
621627
return target

0 commit comments

Comments
 (0)