Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion agent/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions agent/crates/trace-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ regex.workspace = true
rustc-demangle = "0.1"
semver = "1.0"
thiserror = "1.0"
iced-x86 = { version = "1.21", default-features = false, features = ["std", "decoder"] }

[build-dependencies]
cc = "1.0"
Expand Down
4 changes: 3 additions & 1 deletion agent/crates/trace-utils/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ include = [
"LuaUnwindInfo",
"LuaUnwindTable",
"LuaOfs",
"LjOfs"
"LjOfs",
"TSDInfo"
]
exclude = [
"bpf_update_elem",
Expand All @@ -80,6 +81,7 @@ ProcessShardList = "process_shard_list_t"
UnwindEntry = "unwind_entry_t"
UnwindEntryShard = "unwind_entry_shard_t"
UnwindTable = "unwind_table_t"
TSDInfo = "tsd_info_t"
PyCframe = "py_cframe_t"
PyCodeObject = "py_code_object_t"
PyFrameObject = "py_frame_object_t"
Expand Down
2 changes: 2 additions & 0 deletions agent/crates/trace-utils/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub enum Error {
InvalidPointer(u64),
#[error("Invalid or corrupted data")]
InvalidData,
#[error("{0}")]
Msg(String),
}

pub type Result<T> = std::result::Result<T, Error>;
2 changes: 1 addition & 1 deletion agent/crates/trace-utils/src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::path::PathBuf;

use log::trace;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct MemoryArea {
pub m_start: u64,
pub mx_start: u64, // start address of executable section
Expand Down
41 changes: 40 additions & 1 deletion agent/crates/trace-utils/src/trace_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,41 @@ typedef struct {
} unwind_entry_shard_t;

typedef struct {
uint64_t thread_state_address;
/**
* Offset from thread pointer base (TPBASE) to TSD storage
*/
int16_t offset;
/**
* TSD key multiplier (glibc=16, musl=8)
*/
uint8_t multiplier;
/**
* Whether indirect addressing is needed (musl=1, glibc=0)
*/
uint8_t indirect;
} tsd_info_t;

typedef struct {
/**
* Address of autoTLSkey variable in Python runtime
*/
uint64_t auto_tls_key_addr;
/**
* Python version encoded as 0xMMmm (e.g., 0x030A for 3.10)
*/
uint16_t version;
/**
* Thread Specific Data info for multi-threading support
*/
tsd_info_t tsd_info;
/**
* ID for looking up python_offsets in the offsets map
*/
uint8_t offsets_id;
/**
* Padding for alignment
*/
uint8_t _padding[5];
} python_unwind_info_t;

typedef struct {
Expand Down Expand Up @@ -396,6 +429,12 @@ void v8_unwind_table_unload(v8_unwind_table_t *table, uint32_t pid);

int32_t read_offset_of_stack_in_task_struct(void);

/**
* Read TPBASE offset from kernel functions
* Returns the offset of fsbase/tpidr in task_struct, or -1 on failure
*/
int64_t read_tpbase_offset(void);

int rustc_demangle(const char *mangled, char *out, size_t out_size);

unwind_table_t *unwind_table_create(int32_t process_shard_list_map_fd,
Expand Down
2 changes: 2 additions & 0 deletions agent/crates/trace-utils/src/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub mod elf_utils;
pub mod lua;
pub mod php;
pub mod python;
pub mod tpbase;
pub mod tsd;
pub mod v8;

use std::alloc::{alloc, dealloc, handle_alloc_error, Layout};
Expand Down
Loading