diff options
| author | Philip P. Moltmann <moltmann@google.com> | 2017-11-01 15:22:02 -0700 |
|---|---|---|
| committer | Philip P. Moltmann <moltmann@google.com> | 2017-11-03 10:33:21 -0700 |
| commit | fd8ed85adb84b2822eb2a15550b17976758e44dd (patch) | |
| tree | 411fa238fcfe61cfb93f4da129124ce1853bd023 /core/java/android/os/Debug.java | |
| parent | 9009eabbfefdc685f176419001bc2aeff4790089 (diff) | |
Allow to attach jvmti agents from inside of process
Test: cts-tradefed run singleCommand cts-dev -m CtsJvmtiAttachingTestCases
Bug: 65016018
Change-Id: I6d445afa288c6fec1d860150159fa05ed63cf517
Diffstat (limited to 'core/java/android/os/Debug.java')
| -rw-r--r-- | core/java/android/os/Debug.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java index 75fea5253674..12932956a7b9 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.bytecode.OpcodeInfo; @@ -2371,4 +2374,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); + } + } } |
