Skip to content
Merged
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
47 changes: 24 additions & 23 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'data> ProguardCache<'data> {
class: frame.class,
method: frame.method,
file,
line: frame.line,
line: Some(frame.line.unwrap_or(0)),
parameters: frame.parameters,
method_synthesized: false,
}
Expand Down Expand Up @@ -389,9 +389,9 @@ impl<'data> ProguardCache<'data> {
if prepared_frame.parameters.is_none() {
for member in mapping_entries {
// Check if this member would produce a frame (line matching)
let pf_line = prepared_frame.line.unwrap_or(0);
if member.endline == 0
|| (prepared_frame.line >= member.startline as usize
&& prepared_frame.line <= member.endline as usize)
|| (pf_line >= member.startline as usize && pf_line <= member.endline as usize)
{
had_mappings = true;
rewrite_rules.extend(self.decode_rewrite_rules(member));
Expand Down Expand Up @@ -477,7 +477,7 @@ impl<'data> ProguardCache<'data> {
'r: 'data,
{
if self.is_outline_frame(frame.class, frame.method) {
*carried_outline_pos = Some(frame.line);
*carried_outline_pos = Some(frame.line.unwrap_or(0));
return None;
}

Expand Down Expand Up @@ -678,11 +678,11 @@ impl<'data> ProguardCache<'data> {
if let Some(mapped) = self.map_outline_position(
effective.class,
effective.method,
effective.line,
effective.line.unwrap_or(0),
pos,
effective.parameters,
) {
effective.line = mapped;
effective.line = Some(mapped);
}
}

Expand Down Expand Up @@ -903,7 +903,7 @@ impl<'r, 'data> RemappedFrameIter<'r, 'data> {
let out = if frame.parameters.is_none() {
// If we have no line number, treat it as unknown. If there are base (no-line) mappings
// present, prefer those over line-mapped entries.
if frame.line == 0 {
if frame.line.unwrap_or(0) == 0 {
let selection = select_no_line_members(members.as_slice())?;
let mapped = match selection {
NoLineSelection::Single(member) => {
Expand Down Expand Up @@ -983,9 +983,10 @@ fn iterate_with_lines<'a>(
outer_source_file: Option<&str>,
has_line_info: bool,
) -> Option<StackFrame<'a>> {
let frame_line = frame.line.unwrap_or(0);
for member in members {
// If this method has line mappings, skip base (no-line) entries when we have a concrete line.
if has_line_info && frame.line > 0 && member.endline == 0 {
if has_line_info && frame_line > 0 && member.endline == 0 {
continue;
}
// If the mapping entry has no line range, preserve the input line number (if any).
Expand All @@ -994,7 +995,7 @@ fn iterate_with_lines<'a>(
}
// skip any members which do not match our frames line
if member.endline > 0
&& (frame.line < member.startline as usize || frame.line > member.endline as usize)
&& (frame_line < member.startline as usize || frame_line > member.endline as usize)
{
continue;
}
Expand All @@ -1005,7 +1006,7 @@ fn iterate_with_lines<'a>(
{
member.original_startline as usize
} else {
member.original_startline as usize + frame.line - member.startline as usize
member.original_startline as usize + frame_line - member.startline as usize
};

let class = cache
Expand Down Expand Up @@ -1035,7 +1036,7 @@ fn iterate_with_lines<'a>(
class,
method,
file,
line,
line: Some(line),
parameters: frame.parameters,
method_synthesized: member.is_synthesized(),
});
Expand Down Expand Up @@ -1105,12 +1106,12 @@ fn map_member_without_lines<'a>(
class,
method,
file,
line: resolve_no_line_output_line(
frame.line,
line: Some(resolve_no_line_output_line(
frame.line.unwrap_or(0),
original_startline,
member.startline as usize,
member.endline as usize,
),
)),
parameters: frame.parameters,
method_synthesized: member.is_synthesized(),
})
Expand Down Expand Up @@ -1142,12 +1143,12 @@ fn iterate_without_lines<'a>(
class,
method,
file,
line: resolve_no_line_output_line(
frame.line,
line: Some(resolve_no_line_output_line(
frame.line.unwrap_or(0),
original_startline,
member.startline as usize,
member.endline as usize,
),
)),
parameters: frame.parameters,
method_synthesized: member.is_synthesized(),
})
Expand Down Expand Up @@ -1207,15 +1208,15 @@ com.example.MainFragment$onActivityCreated$4 -> com.example.MainFragment$g:
StackFrame {
class: "com.example.MainFragment$g",
method: "onClick",
line: 2,
line: Some(2),
file: Some(Cow::Borrowed("SourceFile")),
parameters: None,
method_synthesized: false,
},
StackFrame {
class: "android.view.View",
method: "performClick",
line: 7393,
line: Some(7393),
file: Some(Cow::Borrowed("View.java")),
parameters: None,
method_synthesized: false,
Expand All @@ -1229,7 +1230,7 @@ com.example.MainFragment$onActivityCreated$4 -> com.example.MainFragment$g:
frames: vec![StackFrame {
class: "com.example.MainFragment$g",
method: "onClick",
line: 1,
line: Some(1),
file: Some(Cow::Borrowed("SourceFile")),
parameters: None,
method_synthesized: false,
Expand Down Expand Up @@ -1421,15 +1422,15 @@ some.Other -> b:
StackFrame {
class: "a",
method: "call",
line: 4,
line: Some(4),
file: Some(Cow::Borrowed("SourceFile")),
parameters: None,
method_synthesized: false,
},
StackFrame {
class: "b",
method: "run",
line: 5,
line: Some(5),
file: Some(Cow::Borrowed("SourceFile")),
parameters: None,
method_synthesized: false,
Expand All @@ -1445,6 +1446,6 @@ some.Other -> b:
assert_eq!(remapped.frames.len(), 1);
assert_eq!(remapped.frames[0].class, "some.Other");
assert_eq!(remapped.frames[0].method, "method");
assert_eq!(remapped.frames[0].line, 30);
assert_eq!(remapped.frames[0].line, Some(30));
}
}
42 changes: 22 additions & 20 deletions src/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ fn map_member_with_lines<'a>(
frame: &StackFrame<'a>,
member: &MemberMapping<'a>,
) -> Option<StackFrame<'a>> {
if member.endline > 0 && (frame.line < member.startline || frame.line > member.endline) {
let frame_line = frame.line.unwrap_or(0);
if member.endline > 0 && (frame_line < member.startline || frame_line > member.endline) {
return None;
}

Expand All @@ -151,7 +152,7 @@ fn map_member_with_lines<'a>(
{
member.original_startline
} else {
member.original_startline + frame.line - member.startline
member.original_startline + frame_line - member.startline
};

let class = member.original_class.unwrap_or(frame.class);
Expand All @@ -172,7 +173,7 @@ fn map_member_with_lines<'a>(
class,
method: member.original,
file,
line,
line: Some(line),
parameters: frame.parameters,
method_synthesized: member.is_synthesized,
})
Expand All @@ -191,7 +192,7 @@ fn map_member_without_lines<'a>(
None
};
let line = resolve_no_line_output_line(
frame.line,
frame.line.unwrap_or(0),
original_startline,
member.startline,
member.endline,
Expand All @@ -202,7 +203,7 @@ fn map_member_without_lines<'a>(
file,
// Preserve input line if present (e.g. "Unknown Source:7") when the mapping itself
// has no line information. This matches R8 retrace behavior.
line,
line: Some(line),
parameters: frame.parameters,
method_synthesized: member.is_synthesized,
}
Expand All @@ -214,7 +215,7 @@ fn remap_class_only<'a>(frame: &StackFrame<'a>, reference_file: Option<&str>) ->
class: frame.class,
method: frame.method,
file,
line: frame.line,
line: Some(frame.line.unwrap_or(0)),
parameters: frame.parameters,
method_synthesized: false,
}
Expand Down Expand Up @@ -295,9 +296,10 @@ fn iterate_with_lines<'a>(
members: &mut core::slice::Iter<'_, MemberMapping<'a>>,
has_line_info: bool,
) -> Option<StackFrame<'a>> {
let frame_line = frame.line.unwrap_or(0);
for member in members {
// If this method has line mappings, skip base (no-line) entries when we have a concrete line.
if has_line_info && frame.line > 0 && member.endline == 0 {
if has_line_info && frame_line > 0 && member.endline == 0 {
continue;
}
// If the mapping entry has no line range, preserve the input line number (if any).
Expand Down Expand Up @@ -522,11 +524,11 @@ impl<'s> ProguardMapper<'s> {
if let Some(mapped) = self.map_outline_position(
effective.class,
effective.method,
effective.line,
effective.line.unwrap_or(0),
pos,
effective.parameters,
) {
effective.line = mapped;
effective.line = Some(mapped);
}
}

Expand Down Expand Up @@ -584,7 +586,7 @@ impl<'s> ProguardMapper<'s> {

// If the stacktrace has no line number, treat it as unknown and remap without
// applying line filters. If there are base (no-line) mappings present, prefer those.
if frame.line == 0 {
if frame.line.unwrap_or(0) == 0 {
let selection = select_no_line_members(mapping_entries, has_line_info);
match selection {
Some(NoLineSelection::Single(member)) => {
Expand Down Expand Up @@ -744,7 +746,7 @@ impl<'s> ProguardMapper<'s> {

if let Some(frame) = stacktrace::parse_frame(line) {
if self.is_outline_frame(frame.class, frame.method) {
carried_outline_pos = Some(frame.line);
carried_outline_pos = Some(frame.line.unwrap_or(0));
continue;
}

Expand Down Expand Up @@ -810,7 +812,7 @@ impl<'s> ProguardMapper<'s> {
let mut next_frame_can_rewrite = exception_descriptor.is_some();
for f in trace.frames.iter() {
if self.is_outline_frame(f.class, f.method) {
carried_outline_pos = Some(f.line);
carried_outline_pos = Some(f.line.unwrap_or(0));
continue;
}

Expand Down Expand Up @@ -913,15 +915,15 @@ com.example.MainFragment$onActivityCreated$4 -> com.example.MainFragment$g:
StackFrame {
class: "com.example.MainFragment$g",
method: "onClick",
line: 2,
line: Some(2),
file: Some(Cow::Borrowed("SourceFile")),
parameters: None,
method_synthesized: false,
},
StackFrame {
class: "android.view.View",
method: "performClick",
line: 7393,
line: Some(7393),
file: Some(Cow::Borrowed("View.java")),
parameters: None,
method_synthesized: false,
Expand All @@ -935,7 +937,7 @@ com.example.MainFragment$onActivityCreated$4 -> com.example.MainFragment$g:
frames: vec![StackFrame {
class: "com.example.MainFragment$g",
method: "onClick",
line: 1,
line: Some(1),
file: Some(Cow::Borrowed("SourceFile")),
parameters: None,
method_synthesized: false,
Expand Down Expand Up @@ -1055,7 +1057,7 @@ some.Class -> a:
frames: vec![StackFrame {
class: "a",
method: "a",
line: 4,
line: Some(4),
file: Some(Cow::Borrowed("SourceFile")),
parameters: None,
method_synthesized: false,
Expand All @@ -1069,7 +1071,7 @@ some.Class -> a:
assert_eq!(remapped.frames.len(), 1);
assert_eq!(remapped.frames[0].class, "some.Class");
assert_eq!(remapped.frames[0].method, "caller");
assert_eq!(remapped.frames[0].line, 7);
assert_eq!(remapped.frames[0].line, Some(7));
}

#[test]
Expand Down Expand Up @@ -1176,15 +1178,15 @@ some.Other -> b:
StackFrame {
class: "a",
method: "call",
line: 4,
line: Some(4),
file: Some(Cow::Borrowed("SourceFile")),
parameters: None,
method_synthesized: false,
},
StackFrame {
class: "b",
method: "run",
line: 5,
line: Some(5),
file: Some(Cow::Borrowed("SourceFile")),
parameters: None,
method_synthesized: false,
Expand All @@ -1200,6 +1202,6 @@ some.Other -> b:
assert_eq!(remapped.frames.len(), 1);
assert_eq!(remapped.frames[0].class, "some.Other");
assert_eq!(remapped.frames[0].method, "method");
assert_eq!(remapped.frames[0].line, 30);
assert_eq!(remapped.frames[0].line, Some(30));
}
}
Loading
Loading