Commit dd71878e authored by Kenny Yu's avatar Kenny Yu Committed by Facebook GitHub Bot

gdb: handle uninitialized folly_async_stack_root_tls_key

Summary:
This fixes the gdb script to handle folly_async_stack_root_tls_key being uninitialized --
this means that no async operation has run on this thread previously.

This also catches any errors raised by the `co_bt` command to help with debugging the
script itself, and to allow `thread apply all co_bt` to process all threads, even
if one thread has an error.

Reviewed By: yfeldblum

Differential Revision: D27180105

fbshipit-source-id: d6b36bdbc11b94a2f956862fc7651376e1d28af0
parent 8a82e909
......@@ -14,6 +14,8 @@
# limitations under the License.
import re
import sys
import traceback
from dataclasses import dataclass
from typing import List, Tuple
......@@ -167,6 +169,11 @@ def get_async_stack_root_addr() -> gdb.Value:
if int(pthread_addr) == 0:
return nullptr()
# Check if the tls key is initialized
tls_key = gdb.parse_and_eval(f"(int){ASYNC_STACK_ROOT_TLS_KEY}")
if (int(tls_key) % (2 ** 32)) == ((2 ** 32) - 1):
return nullptr()
# get the stack root pointer from thread-local storage
async_stack_root_holder_addr = gdb.parse_and_eval(
f"((struct pthread*){to_hex(pthread_addr)})->specific"
......@@ -293,6 +300,7 @@ class CoroBacktraceCommand(gdb.Command):
super(CoroBacktraceCommand, self).__init__("co_bt", gdb.COMMAND_USER)
def invoke(self, arg: str, from_tty: bool):
try:
addrs: List[gdb.Value] = []
if arg:
async_stack_root_addr = gdb.parse_and_eval(arg)
......@@ -304,6 +312,9 @@ class CoroBacktraceCommand(gdb.Command):
else:
addrs = get_async_stack_addrs()
print_async_stack_addrs(addrs)
except Exception:
print("Error collecting async stack trace:")
traceback.print_exception(*sys.exc_info())
class CoroAsyncStackRootsCommand(gdb.Command):
......@@ -331,3 +342,7 @@ def load() -> None:
CoroBacktraceCommand()
CoroAsyncStackRootsCommand()
print(info())
if __name__ == "__main__":
load()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment