diff options
author | Alex Light <allight@google.com> | 2018-06-12 12:59:27 -0700 |
---|---|---|
committer | Alex Light <allight@google.com> | 2018-06-12 12:59:27 -0700 |
commit | 5abbdd323c9720d6fd89f10d682df2b9c20fe507 (patch) | |
tree | 9c00c7378cc6cec495c65cd6c90875e00561a5eb | |
parent | 74f2ccc9fad3cfd8e04d24aceba1c58ce08884dc (diff) |
Make ti-fast agent fallback to kArtTiVersion
It is useful to try and use tifast on userdebug devices with
non-debuggable applications.
Test: adb shell am start-activity -S \
--attach-agent /data/local/tmp/libtifast.so=log,MethodEntry \
<some non-debuggable apk>
Change-Id: Ic39d99aae1e986e66ac370e078a3b4540087cbbe
-rw-r--r-- | tools/ti-fast/tifast.cc | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/tools/ti-fast/tifast.cc b/tools/ti-fast/tifast.cc index 428304e517..b147addfd5 100644 --- a/tools/ti-fast/tifast.cc +++ b/tools/ti-fast/tifast.cc @@ -32,6 +32,10 @@ namespace tifast { namespace { +// Special art ti-version number. We will use this as a fallback if we cannot get a regular JVMTI +// env. +static constexpr jint kArtTiVersion = JVMTI_VERSION_1_2 | 0x40000000; + static void AddCapsForEvent(jvmtiEvent event, jvmtiCapabilities* caps) { switch (event) { #define DO_CASE(name, cap_name) \ @@ -135,6 +139,17 @@ static std::vector<jvmtiEvent> GetRequestedEventList(const std::string& args) { return res; } +static jint SetupJvmtiEnv(JavaVM* vm, jvmtiEnv** jvmti) { + jint res = 0; + res = vm->GetEnv(reinterpret_cast<void**>(jvmti), JVMTI_VERSION_1_1); + + if (res != JNI_OK || *jvmti == nullptr) { + LOG(ERROR) << "Unable to access JVMTI, error code " << res; + return vm->GetEnv(reinterpret_cast<void**>(jvmti), kArtTiVersion); + } + return res; +} + } // namespace static jint AgentStart(JavaVM* vm, @@ -142,14 +157,9 @@ static jint AgentStart(JavaVM* vm, void* reserved ATTRIBUTE_UNUSED) { jvmtiEnv* jvmti = nullptr; jvmtiError error = JVMTI_ERROR_NONE; - { - jint res = 0; - res = vm->GetEnv(reinterpret_cast<void**>(&jvmti), JVMTI_VERSION_1_1); - - if (res != JNI_OK || jvmti == nullptr) { - LOG(ERROR) << "Unable to access JVMTI, error code " << res; - return JNI_ERR; - } + if (SetupJvmtiEnv(vm, &jvmti) != JNI_OK) { + LOG(ERROR) << "Could not get JVMTI env or ArtTiEnv!"; + return JNI_ERR; } std::string args(options); bool is_log = false; |