-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pass to insert artificial debug info when the method miss it
Reviewed By: NTillmann Differential Revision: D66043130 fbshipit-source-id: 6d07d03399b5c75e0e86291a61feb30e5ffdf070
- Loading branch information
1 parent
888b34d
commit 92634c4
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "InsertDebugInfoPass.h" | ||
|
||
#include "ControlFlow.h" | ||
#include "PassManager.h" | ||
#include "Show.h" | ||
#include "Walkers.h" | ||
|
||
void InsertDebugInfoPass::run_pass(DexStoresVector& stores, | ||
ConfigFiles& conf, | ||
PassManager& mgr) { | ||
std::atomic<uint32_t> patched_method = 0; | ||
walk::parallel::code( | ||
build_class_scope(stores), [&](DexMethod* method, IRCode& code) { | ||
always_assert(code.editable_cfg_built()); | ||
bool has_position = false; | ||
auto& cfg = code.cfg(); | ||
for (auto* block : cfg.blocks()) { | ||
for (auto it = block->begin(); it != block->end(); it++) { | ||
if (it->type == MFLOW_POSITION) { | ||
has_position = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (has_position) { | ||
return; | ||
} | ||
patched_method++; | ||
always_assert_log(!code.get_debug_item(), | ||
"%s has no DexPosition, but has a DexDebugItem %s", | ||
SHOW(method), | ||
SHOW(code.cfg())); | ||
code.set_debug_item(std::make_unique<DexDebugItem>()); | ||
auto* block = cfg.entry_block(); | ||
auto last_param = block->get_last_param_loading_insn(); | ||
auto artificial_pos = std::make_unique<DexPosition>( | ||
DexString::make_string(show_deobfuscated(method)), | ||
DexString::make_string("UnknownSource"), 0); | ||
if (last_param == block->end()) { | ||
cfg.insert_before(block->to_cfg_instruction_iterator( | ||
block->get_first_non_param_loading_insn()), | ||
std::move(artificial_pos)); | ||
} else { | ||
cfg.insert_after(block->to_cfg_instruction_iterator( | ||
block->get_last_param_loading_insn()), | ||
std::move(artificial_pos)); | ||
} | ||
}); | ||
|
||
mgr.set_metric("patched_method", patched_method); | ||
} | ||
|
||
static InsertDebugInfoPass s_pass; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Pass.h" | ||
|
||
class InsertDebugInfoPass : public Pass { | ||
public: | ||
InsertDebugInfoPass() : Pass("InsertDebugInfoPass") {} | ||
|
||
redex_properties::PropertyInteractions get_property_interactions() | ||
const override { | ||
using namespace redex_properties::interactions; | ||
using namespace redex_properties::names; | ||
return { | ||
{DexLimitsObeyed, Preserves}, | ||
{UltralightCodePatterns, Preserves}, | ||
}; | ||
} | ||
|
||
void run_pass(DexStoresVector&, ConfigFiles&, PassManager&) override; | ||
}; |