summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorPhilip P. Moltmann <moltmann@google.com>2017-11-06 20:58:48 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-11-06 20:58:48 +0000
commitb567ea9ddad6a6486b585f6ed27317561425f2e8 (patch)
tree0421226f7e1b9482190e08035d09a903260c5e27 /core/java/android
parent051d6b369bcdde0358bf324d140463663733aabd (diff)
parent491058e08968a4deb7b7b04c5af15d3538e032cd (diff)
Merge "Allow to attach jvmti agents from inside of process" am: faffb072a4
am: 491058e089 Change-Id: Ib636dd1ebcee0bfbd57e12e632137561bb661d3e
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/os/Debug.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 2e62eb6a5f97..2acf36fed85f 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -16,11 +16,14 @@
package android.os;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.app.AppGlobals;
import android.content.Context;
import android.util.Log;
import com.android.internal.util.FastPrintWriter;
+import com.android.internal.util.Preconditions;
import com.android.internal.util.TypedProperties;
import dalvik.system.VMDebug;
@@ -2347,4 +2350,24 @@ public final class Debug
public static String getCaller() {
return getCaller(Thread.currentThread().getStackTrace(), 0);
}
+
+ /**
+ * Attach a library as a jvmti agent to the current runtime.
+ *
+ * @param library library containing the agent
+ * @param options options passed to the agent
+ *
+ * @throws IOException If the agent could not be attached
+ */
+ public static void attachJvmtiAgent(@NonNull String library, @Nullable String options)
+ throws IOException {
+ Preconditions.checkNotNull(library);
+ Preconditions.checkArgument(!library.contains("="));
+
+ if (options == null) {
+ VMDebug.attachAgent(library);
+ } else {
+ VMDebug.attachAgent(library + "=" + options);
+ }
+ }
}