add more debug info in error

This commit is contained in:
Jean-Marie 'Histausse' Mineau 2025-03-03 13:48:08 +01:00
parent fe0dd2d6c8
commit d906c4d3d2
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2

View file

@ -503,9 +503,14 @@ impl DexWriter {
// for context // for context
} }
Instruction::Goto { label } => { Instruction::Goto { label } => {
let (min_addr, max_addr) = label_min_max_addrs let (min_addr, max_addr) = label_min_max_addrs.get(label).ok_or(anyhow!(
.get(label) "Label {label} not found in label estimation map, known labels are {}",
.ok_or(anyhow!("Label {label} not found in label estimation map"))?; label_min_max_addrs
.keys()
.map(|string| string.as_str())
.collect::<Vec<_>>()
.join(", ")
))?;
let size = Instruction::goto_size_from_branch_offset_interval( let size = Instruction::goto_size_from_branch_offset_interval(
addr, *min_addr, *max_addr, addr, *min_addr, *max_addr,
)?; )?;
@ -948,7 +953,8 @@ impl DexWriter {
// No if let because ownership gunfooterie // No if let because ownership gunfooterie
let code_off = if class.direct_methods.get(id).unwrap().code.is_some() { let code_off = if class.direct_methods.get(id).unwrap().code.is_some() {
let code_off = self.section_manager.get_aligned_size(Section::CodeItem); let code_off = self.section_manager.get_aligned_size(Section::CodeItem);
self.insert_code_item(id.clone(), true)?; self.insert_code_item(id.clone(), true)
.with_context(|| format!("Failed to serialize code of {}", id.__str__()))?;
Uleb128(code_off + 1) Uleb128(code_off + 1)
} else { } else {
Uleb128(0) Uleb128(0)
@ -983,7 +989,8 @@ impl DexWriter {
// No if let because ownership gunfooterie // No if let because ownership gunfooterie
let code_off = if class.virtual_methods.get(id).unwrap().code.is_some() { let code_off = if class.virtual_methods.get(id).unwrap().code.is_some() {
let code_off = self.section_manager.get_aligned_size(Section::CodeItem); let code_off = self.section_manager.get_aligned_size(Section::CodeItem);
self.insert_code_item(id.clone(), false)?; self.insert_code_item(id.clone(), false)
.with_context(|| format!("Failed to serialize code of {}", id.__str__()))?;
Uleb128(code_off + 1) Uleb128(code_off + 1)
} else { } else {
Uleb128(0) Uleb128(0)