Skip to content

Commit 45ffb40

Browse files
generatedunixname89002005287564facebook-github-bot
authored andcommitted
folly
Reviewed By: jermenkoo Differential Revision: D63823242 fbshipit-source-id: 5295a04d03d31d2a5d1c86fe5d10b2cba3ed0822
1 parent 46d56b8 commit 45ffb40

File tree

5 files changed

+63
-75
lines changed

5 files changed

+63
-75
lines changed

folly/coro/scripts/co_bt.py

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def to_hex(self) -> str:
9898
pass
9999

100100
@abc.abstractmethod
101-
def get_file_name_and_line(self) -> Optional[Tuple[str, int]]:
101+
def get_file_name_and_line(self) -> tuple[str, int] | None:
102102
"""
103103
Returns the file name and line number of the value.
104104
Assumes the value is a pointer to an instruction.
@@ -107,7 +107,7 @@ def get_file_name_and_line(self) -> Optional[Tuple[str, int]]:
107107
pass
108108

109109
@abc.abstractmethod
110-
def get_func_name(self) -> Optional[str]:
110+
def get_func_name(self) -> str | None:
111111
"""
112112
Returns the function name of the value. Returns None if the name could
113113
not be found
@@ -206,7 +206,7 @@ def from_addr(addr: DebuggerValue) -> "StackFrame":
206206

207207

208208
def get_async_stack_root_addr(
209-
debugger_value_class: Type[DebuggerValue],
209+
debugger_value_class: type[DebuggerValue],
210210
) -> DebuggerValue:
211211
"""
212212
Returns a pointer to the top-most async stack root, or a nullptr if none
@@ -259,7 +259,7 @@ def get_async_stack_root_addr(
259259
return async_stack_root_holder.value
260260

261261

262-
def print_async_stack_addrs(addrs: List[DebuggerValue]) -> None:
262+
def print_async_stack_addrs(addrs: list[DebuggerValue]) -> None:
263263
if len(addrs) == 0:
264264
print("No async operation detected")
265265
return
@@ -282,11 +282,11 @@ def print_async_stack_addrs(addrs: List[DebuggerValue]) -> None:
282282

283283
def get_async_stack_addrs_from_initial_frame(
284284
async_stack_frame_addr: DebuggerValue,
285-
) -> List[DebuggerValue]:
285+
) -> list[DebuggerValue]:
286286
"""
287287
Gets the list of async stack frames rooted at the current frame
288288
"""
289-
addrs: List[DebuggerValue] = []
289+
addrs: list[DebuggerValue] = []
290290
while not async_stack_frame_addr.is_nullptr():
291291
async_stack_frame = AsyncStackFrame.from_addr(async_stack_frame_addr)
292292
addrs.append(async_stack_frame.instruction_pointer)
@@ -297,12 +297,12 @@ def get_async_stack_addrs_from_initial_frame(
297297
def walk_normal_stack(
298298
normal_stack_frame_addr: DebuggerValue,
299299
normal_stack_frame_stop_addr: DebuggerValue,
300-
) -> List[DebuggerValue]:
300+
) -> list[DebuggerValue]:
301301
"""
302302
Returns the list of return addresses in the normal stack.
303303
Does not include stop_addr
304304
"""
305-
addrs: List[DebuggerValue] = []
305+
addrs: list[DebuggerValue] = []
306306
while not normal_stack_frame_addr.is_nullptr():
307307
normal_stack_frame = StackFrame.from_addr(normal_stack_frame_addr)
308308
if (
@@ -320,7 +320,7 @@ def walk_normal_stack(
320320

321321
@dataclass
322322
class WalkAsyncStackResult:
323-
addrs: List[DebuggerValue]
323+
addrs: list[DebuggerValue]
324324
# Normal stack frame to start the next normal stack walk
325325
normal_stack_frame_addr: DebuggerValue
326326
normal_stack_frame_stop_addr: DebuggerValue
@@ -330,14 +330,14 @@ class WalkAsyncStackResult:
330330

331331

332332
def walk_async_stack(
333-
debugger_value_class: Type[DebuggerValue],
333+
debugger_value_class: type[DebuggerValue],
334334
async_stack_frame_addr: DebuggerValue,
335335
) -> WalkAsyncStackResult:
336336
"""
337337
Walks the async stack and returns the next normal stack and async stack
338338
addresses to walk.
339339
"""
340-
addrs: List[DebuggerValue] = []
340+
addrs: list[DebuggerValue] = []
341341
normal_stack_frame_addr = debugger_value_class.nullptr()
342342
normal_stack_frame_stop_addr = debugger_value_class.nullptr()
343343
async_stack_frame_next_addr = debugger_value_class.nullptr()
@@ -390,8 +390,8 @@ def walk_async_stack(
390390

391391

392392
def get_async_stack_addrs(
393-
debugger_value_class: Type[DebuggerValue],
394-
) -> List[DebuggerValue]:
393+
debugger_value_class: type[DebuggerValue],
394+
) -> list[DebuggerValue]:
395395
"""
396396
Gets the async stack trace, including normal stack frames with async
397397
stack frames.
@@ -414,7 +414,7 @@ def get_async_stack_addrs(
414414
async_stack_root = AsyncStackRoot.from_addr(async_stack_root_addr)
415415
normal_stack_frame_addr = debugger_value_class.get_register("rbp")
416416
normal_stack_frame_stop_addr = async_stack_root.stack_frame_ptr
417-
addrs: List[DebuggerValue] = []
417+
addrs: list[DebuggerValue] = []
418418
addrs.append(debugger_value_class.get_register("pc"))
419419
async_stack_frame_addr = async_stack_root.top_frame
420420

@@ -437,7 +437,7 @@ def get_async_stack_addrs(
437437
return addrs
438438

439439

440-
def print_async_stack_root_addrs(addrs: List[DebuggerValue]) -> None:
440+
def print_async_stack_root_addrs(addrs: list[DebuggerValue]) -> None:
441441
if len(addrs) == 0:
442442
print("No async stack roots detected")
443443
return
@@ -468,12 +468,12 @@ def print_async_stack_root_addrs(addrs: List[DebuggerValue]) -> None:
468468

469469

470470
def get_async_stack_root_addrs(
471-
debugger_value_class: Type[DebuggerValue],
472-
) -> List[DebuggerValue]:
471+
debugger_value_class: type[DebuggerValue],
472+
) -> list[DebuggerValue]:
473473
"""
474474
Gets all the async stack roots that exist for the current thread.
475475
"""
476-
addrs: List[DebuggerValue] = []
476+
addrs: list[DebuggerValue] = []
477477
async_stack_root_addr = get_async_stack_root_addr(debugger_value_class)
478478
while not async_stack_root_addr.is_nullptr():
479479
addrs.append(async_stack_root_addr)
@@ -483,11 +483,11 @@ def get_async_stack_root_addrs(
483483

484484

485485
def backtrace_command(
486-
debugger_value_class: Type[DebuggerValue],
487-
stack_root: Optional[str],
486+
debugger_value_class: type[DebuggerValue],
487+
stack_root: str | None,
488488
) -> None:
489489
try:
490-
addrs: List[DebuggerValue] = []
490+
addrs: list[DebuggerValue] = []
491491
if stack_root:
492492
async_stack_root_addr = debugger_value_class.parse_and_eval(stack_root)
493493
if not async_stack_root_addr.is_nullptr():
@@ -503,7 +503,7 @@ def backtrace_command(
503503
traceback.print_exception(*sys.exc_info())
504504

505505

506-
def async_stack_roots_command(debugger_value_class: Type[DebuggerValue]) -> None:
506+
def async_stack_roots_command(debugger_value_class: type[DebuggerValue]) -> None:
507507
addrs = get_async_stack_root_addrs(debugger_value_class)
508508
print_async_stack_root_addrs(addrs)
509509

@@ -529,7 +529,7 @@ class DebuggerType(enum.Enum):
529529
LLDB = 1
530530

531531

532-
debugger_type: Optional[DebuggerType] = None
532+
debugger_type: DebuggerType | None = None
533533
if debugger_type is None: # noqa: C901
534534
try:
535535
import gdb
@@ -592,7 +592,7 @@ def int_value(self) -> int:
592592
def to_hex(self) -> str:
593593
return f"{int(self.value):#0{18}x}"
594594

595-
def get_file_name_and_line(self) -> Optional[Tuple[str, int]]:
595+
def get_file_name_and_line(self) -> tuple[str, int] | None:
596596
regex = re.compile(r"Line (\d+) of (.*) starts at.*")
597597
output = GdbValue.execute(
598598
f"info line *{self.to_hex()}",
@@ -606,7 +606,7 @@ def get_file_name_and_line(self) -> Optional[Tuple[str, int]]:
606606
else None
607607
)
608608

609-
def get_func_name(self) -> Optional[str]:
609+
def get_func_name(self) -> str | None:
610610
regex = re.compile(r"(.*) \+ \d+ in section.* of .*")
611611
output = GdbValue.execute(
612612
f"info symbol {self.to_hex()}",
@@ -622,17 +622,15 @@ def __eq__(self, other) -> bool:
622622
class GdbCoroBacktraceCommand(gdb.Command):
623623
def __init__(self):
624624
print(co_bt_info())
625-
super(GdbCoroBacktraceCommand, self).__init__("co_bt", gdb.COMMAND_USER)
625+
super().__init__("co_bt", gdb.COMMAND_USER)
626626

627627
def invoke(self, arg: str, from_tty: bool):
628628
backtrace_command(GdbValue, arg)
629629

630630
class GdbCoroAsyncStackRootsCommand(gdb.Command):
631631
def __init__(self):
632632
print(co_async_stack_root_info())
633-
super(GdbCoroAsyncStackRootsCommand, self).__init__(
634-
"co_async_stack_roots", gdb.COMMAND_USER
635-
)
633+
super().__init__("co_async_stack_roots", gdb.COMMAND_USER)
636634

637635
def invoke(self, arg: str, from_tty: bool):
638636
async_stack_roots_command(GdbValue)
@@ -650,7 +648,7 @@ class LldbValue(DebuggerValue):
650648
LLDB implementation of a debugger value
651649
"""
652650

653-
exe_ctx: ClassVar[Optional[lldb.SBExecutionContext]] = None
651+
exe_ctx: ClassVar[lldb.SBExecutionContext | None] = None
654652
next_name_num: ClassVar[int] = 0
655653
value: lldb.SBValue
656654

@@ -752,15 +750,15 @@ def _get_symbol_context(self) -> "lldb.SBSymbolContext":
752750
address, lldb.eSymbolContextEverything
753751
)
754752

755-
def get_file_name_and_line(self) -> Optional[Tuple[str, int]]:
753+
def get_file_name_and_line(self) -> tuple[str, int] | None:
756754
symbol_context = self._get_symbol_context()
757755
line_entry = symbol_context.GetLineEntry()
758756
path = line_entry.GetFileSpec().fullpath
759757
if path:
760758
return (path, line_entry.GetLine())
761759
return None
762760

763-
def get_func_name(self) -> Optional[str]:
761+
def get_func_name(self) -> str | None:
764762
symbol_context = self._get_symbol_context()
765763
if symbol_context.GetFunction().IsValid():
766764
return symbol_context.GetFunction().GetDisplayName()

0 commit comments

Comments
 (0)