Skip to content

Commit

Permalink
better debug position for class merging default case
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ssj933 authored and facebook-github-bot committed Nov 26, 2024
1 parent e02b5a9 commit 888b34d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libredex/Creators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,10 @@ void MethodBlock::push_instruction(IRInstruction* insn) {
curr = mc->push_instruction(curr, insn);
}

void MethodBlock::push_position(std::unique_ptr<DexPosition> 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()) {
Expand All @@ -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<DexPosition> 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);
Expand Down
4 changes: 4 additions & 0 deletions libredex/Creators.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ struct MethodBlock {
MethodBlock* switch_op(Location test,
std::map<SwitchIndices, MethodBlock*>& cases);

void push_position(std::unique_ptr<DexPosition> pos);

private:
MethodBlock(const IRList::iterator& iterator, MethodCreator* creator);

Expand Down Expand Up @@ -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<DexPosition> pos);
IRList::iterator make_if_block(IRList::iterator curr,
IRInstruction* insn,
IRList::iterator* false_block);
Expand Down
4 changes: 4 additions & 0 deletions service/switch-dispatch/SwitchDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DexPosition>(
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()) {
Expand Down

0 comments on commit 888b34d

Please sign in to comment.