From 888b34db00de04e6693156f345db08123ec0e2cd Mon Sep 17 00:00:00 2001 From: Sushan Jiang Date: Mon, 25 Nov 2024 18:05:39 -0800 Subject: [PATCH] better debug position for class merging default case Summary: We generate default block that's just invoke-super on common overriden method. But this code block don't have debug position and will cause merged class appear in stack frame that is causing confusion. Reviewed By: NTillmann Differential Revision: D66139527 fbshipit-source-id: 42ed11934676c7111e55a22d6e54cee1f18ae40e --- libredex/Creators.cpp | 14 ++++++++++++++ libredex/Creators.h | 4 ++++ service/switch-dispatch/SwitchDispatch.cpp | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/libredex/Creators.cpp b/libredex/Creators.cpp index 476feddf13e..1d3745f1f90 100644 --- a/libredex/Creators.cpp +++ b/libredex/Creators.cpp @@ -558,6 +558,10 @@ void MethodBlock::push_instruction(IRInstruction* insn) { curr = mc->push_instruction(curr, insn); } +void MethodBlock::push_position(std::unique_ptr pos) { + curr = mc->push_position(curr, std::move(pos)); +} + IRList::iterator MethodCreator::push_instruction(const IRList::iterator& curr, IRInstruction* insn) { if (curr == meth_code->end()) { @@ -568,6 +572,16 @@ IRList::iterator MethodCreator::push_instruction(const IRList::iterator& curr, } } +IRList::iterator MethodCreator::push_position( + const IRList::iterator& curr, std::unique_ptr pos) { + if (curr == meth_code->end()) { + meth_code->push_back(std::move(pos)); + return std::prev(meth_code->end()); + } else { + return meth_code->insert_after(curr, std::move(pos)); + } +} + MethodBlock* MethodBlock::make_if_block(IRInstruction* insn) { IRList::iterator false_block; curr = mc->make_if_block(curr, insn, &false_block); diff --git a/libredex/Creators.h b/libredex/Creators.h index 0111b2cb984..136d0e05674 100644 --- a/libredex/Creators.h +++ b/libredex/Creators.h @@ -357,6 +357,8 @@ struct MethodBlock { MethodBlock* switch_op(Location test, std::map& cases); + void push_position(std::unique_ptr pos); + private: MethodBlock(const IRList::iterator& iterator, MethodCreator* creator); @@ -483,6 +485,8 @@ struct MethodCreator { IRList::iterator push_instruction(const IRList::iterator& curr, IRInstruction* insn); + IRList::iterator push_position(const IRList::iterator& curr, + std::unique_ptr pos); IRList::iterator make_if_block(IRList::iterator curr, IRInstruction* insn, IRList::iterator* false_block); diff --git a/service/switch-dispatch/SwitchDispatch.cpp b/service/switch-dispatch/SwitchDispatch.cpp index 0f5959b81c5..a987b945554 100644 --- a/service/switch-dispatch/SwitchDispatch.cpp +++ b/service/switch-dispatch/SwitchDispatch.cpp @@ -126,6 +126,10 @@ void handle_default_block( SHOW(spec.overridden_meth)); // Note that the overridden can be an default interface or external default // interface method. + auto artificial_pos = std::make_unique( + DexString::make_string(show_deobfuscated(spec.overridden_meth)), + DexString::make_string("UnknownSource"), 0); + def_block->push_position(std::move(artificial_pos)); emit_call(spec, OPCODE_INVOKE_SUPER, args, ret_loc, spec.overridden_meth, def_block); } else if (!spec.proto->is_void()) {