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

gdb: handle missing struct pthread definition when finding async stack traces

Summary:
Depending on the environment, the type definition for `struct pthread`
(pthread implementation detail for `pthread_t`) may not be available in gdb.
If this happens, use a predefined offset for linux x86_64 to find the `specific`
field inside `struct pthread` that holds the thread-local storage values.

Reviewed By: yfeldblum

Differential Revision: D27112799

fbshipit-source-id: 38c88210c3cd2a6b06918de33167d862f59a676e
parent dd71878e
...@@ -175,12 +175,36 @@ def get_async_stack_root_addr() -> gdb.Value: ...@@ -175,12 +175,36 @@ def get_async_stack_root_addr() -> gdb.Value:
return nullptr() return nullptr()
# get the stack root pointer from thread-local storage # get the stack root pointer from thread-local storage
try:
# Note: "struct pthread" is the implementation type for "pthread_t".
# Its symbol information may not be available, depending if pthread
# debug symbols are available.
async_stack_root_holder_addr = gdb.parse_and_eval( async_stack_root_holder_addr = gdb.parse_and_eval(
f"((struct pthread*){to_hex(pthread_addr)})->specific" f"((struct pthread*){to_hex(pthread_addr)})->specific"
f"[(int){ASYNC_STACK_ROOT_TLS_KEY}/32]" f"[(int){to_hex(tls_key)}/32]"
f"[(int){ASYNC_STACK_ROOT_TLS_KEY}%32]" f"[(int){to_hex(tls_key)}%32]"
".data" ".data"
) )
except gdb.error as e:
if "No struct type named pthread" not in str(e):
raise e
# If "struct pthread" isn't defined, use the precalculated offset.
# Note: The offset is specific to linux x86_64.
specific_offset = 1296
pthread_key_data_addr = gdb.parse_and_eval(
f"&(((uintptr_t[2]**)({to_hex(pthread_addr)}+{specific_offset}))"
f"[(int){to_hex(tls_key)}/32]"
f"[(int){to_hex(tls_key)}%32])"
)
# Extract the "data" field from pthread_key_data, which has the
# following definition:
# struct pthread_key_data {
# uintptr_t seq;
# void *data;
# }
async_stack_root_holder_addr = get_field(pthread_key_data_addr, 1)
if int(async_stack_root_holder_addr) == 0: if int(async_stack_root_holder_addr) == 0:
return nullptr() return nullptr()
async_stack_root_holder = AsyncStackRootHolder.from_addr( async_stack_root_holder = AsyncStackRootHolder.from_addr(
......
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