Skip to content

Commit

Permalink
Add test for Gsym inlined function lookup
Browse files Browse the repository at this point in the history
This change adds a test for the Gsym inlined function lookup logic.

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o committed Sep 12, 2023
1 parent 52cb828 commit a7b4c22
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
17 changes: 17 additions & 0 deletions data/test-stable-addresses.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ factorial_wrapper() {
factorial(5);
}

__attribute__((always_inline)) static void
factorial_2nd_layer_inline_wrapper() {
factorial(6);
}

__attribute__((always_inline)) static void
factorial_inline_wrapper() {
factorial_2nd_layer_inline_wrapper();
}

__attribute__((section(".text.inline")))
__attribute__((noinline)) static void
factorial_inline_test() {
factorial_inline_wrapper();
}

// A dummy function that should not actually be called. It just contains a bunch
// of signature bytes that we use for offset verification later on.
asm(
Expand All @@ -33,6 +49,7 @@ extern void dummy(void);
__attribute__((section(".text.main"))) int
main(int argc, const char *argv[]) {
factorial_wrapper();
factorial_inline_test();
foo();
dummy();
return 0;
Expand Down
2 changes: 2 additions & 0 deletions data/test-stable-addresses.ld
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ SECTIONS {
*(.text)
. = ABSOLUTE(0x2000100);
*(.text.factorial)
. = ABSOLUTE(0x2000200);
*(.text.inline)
}
.data : {
*(.data)
Expand Down
30 changes: 29 additions & 1 deletion src/gsym/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,41 @@ mod tests {
// `main` resides at address 0x2000000, and it's located at the given
// line.
let info = resolver.find_line_info(0x2000000).unwrap().unwrap();
assert_eq!(info.direct.line, Some(34));
assert_eq!(info.direct.line, Some(50));
assert_eq!(info.direct.file, "test-stable-addresses.c");
assert_eq!(info.inlined, Vec::new());

// `factorial` resides at address 0x2000100, and it's located at the
// given line.
let info = resolver.find_line_info(0x2000100).unwrap().unwrap();
assert_eq!(info.direct.line, Some(8));
assert_eq!(info.direct.file, "test-stable-addresses.c");
assert_eq!(info.inlined, Vec::new());

// Address is hopefully sufficiently far into `factorial_inline_test` to
// always fall into the inlined region, no matter toolchain. If not, add
// padding bytes/dummy instructions and adjust some more.
let addr = 0x200020a;
let syms = resolver.find_syms(addr).unwrap();
assert_eq!(syms.len(), 1);
let sym = &syms[0];
assert_eq!(sym.name, "factorial_inline_test");

let info = resolver.find_line_info(addr).unwrap().unwrap();
assert_eq!(info.direct.line, Some(21));
assert_eq!(info.direct.file, "test-stable-addresses.c");
assert_eq!(info.inlined.len(), 2);

let name = &info.inlined[0].0;
assert_eq!(*name, "factorial_inline_wrapper");
let frame = info.inlined[0].1.as_ref().unwrap();
assert_eq!(frame.file, "test-stable-addresses.c");
assert_eq!(frame.line, Some(32));

let name = &info.inlined[1].0;
assert_eq!(*name, "factorial_2nd_layer_inline_wrapper");
let frame = info.inlined[1].1.as_ref().unwrap();
assert_eq!(frame.file, "test-stable-addresses.c");
assert_eq!(frame.line, Some(26));
}
}
2 changes: 2 additions & 0 deletions src/symbolize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ pub use symbolizer::Sym;
pub use symbolizer::Symbolizer;


#[derive(Debug, PartialEq)]
pub(crate) struct FrameCodeInfo<'src> {
pub dir: &'src Path,
pub file: &'src OsStr,
pub line: Option<u32>,
pub column: Option<u16>,
}

#[derive(Debug, PartialEq)]
pub(crate) struct AddrCodeInfo<'src> {
/// Source information about the top-level frame belonging to an address.
pub direct: FrameCodeInfo<'src>,
Expand Down

0 comments on commit a7b4c22

Please sign in to comment.