Skip to content

Commit af4df81

Browse files
committed
[third-party/py-spy/0.3.14] Align virtual address base
Summary: This fixes a bug where we were calculating incorrect address offsets. This tool now works on our Python binaries. Test Plan: ``` $ buck2 run fbsource//third-party/py-spy/0.3.14:py-spy -- dump -p 1245593 ``` Reviewers: bmaurer, itamaro, lisroach Reviewed By: bmaurer Subscribers: mzlee Differential Revision: https://phabricator.intern.facebook.com/D50649635
1 parent 593d6d8 commit af4df81

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ lru = "0.10"
3131
num-traits = "0.2"
3232
regex = ">=1.6.0"
3333
tempfile = "3.6.0"
34+
page_size = "0.6.0"
3435
proc-maps = "0.4.0"
3536
memmap2 = "0.9.4"
3637
cpp_demangle = "0.4"

src/binary_parser.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
150150
)
151151
})?;
152152

153-
// p_vaddr may be larger than the map address in case when the header has an offset and
154-
// the map address is relatively small. In this case we can default to 0.
155-
let offset = offset.saturating_sub(program_header.p_vaddr);
153+
// Align the virtual address offset, then subtract it from the offset
154+
// to get real offset for symbol addresses in the file.
155+
let aligned_vaddr =
156+
program_header.p_vaddr - (program_header.p_vaddr % page_size::get() as u64);
157+
let offset = offset - aligned_vaddr;
156158

157159
let mut bss_addr = 0;
158160
let mut bss_size = 0;

0 commit comments

Comments
 (0)