summaryrefslogtreecommitdiff
path: root/openjdkjvmti/ti_extension.cc
diff options
context:
space:
mode:
author Alex Light <allight@google.com> 2018-10-18 15:49:56 -0700
committer Alex Light <allight@google.com> 2018-10-19 09:11:20 -0700
commitae45cbb288ddcaab3fd518cd00b9e6c1604ec4e1 (patch)
tree34e961fd7fc6a2342920712b0041442b2128f19a /openjdkjvmti/ti_extension.cc
parent7b97f75673301b8d59eb4388dc3f2f1adde05c30 (diff)
Add a get_last_error_message JVMTI extension.
This adds a com.android.art.misc.get_last_error_message and com.android.art.misc.clear_last_error_message extension functions. These allow one to get some error messages that were previously only exposed through logcat. Not all error messages are exposed. Only exposes error messages associated with the exact jvmtiEnv used. Errors must be cleared manually. Not all error conditions will update the saved error-message. Bug: 117234143 Test: ./test.py --host Change-Id: I75b6de9029791035f56c0c63d8958edea500715d
Diffstat (limited to 'openjdkjvmti/ti_extension.cc')
-rw-r--r--openjdkjvmti/ti_extension.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/openjdkjvmti/ti_extension.cc b/openjdkjvmti/ti_extension.cc
index c628a325eb..5d398844b2 100644
--- a/openjdkjvmti/ti_extension.cc
+++ b/openjdkjvmti/ti_extension.cc
@@ -39,7 +39,9 @@
#include "ti_class.h"
#include "ti_ddms.h"
#include "ti_heap.h"
+#include "ti_logging.h"
#include "ti_monitor.h"
+
#include "thread-inl.h"
namespace openjdkjvmti {
@@ -272,6 +274,44 @@ jvmtiError ExtensionUtil::GetExtensionFunctions(jvmtiEnv* env,
if (error != ERR(NONE)) {
return error;
}
+
+ // GetLastError extension
+ error = add_extension(
+ reinterpret_cast<jvmtiExtensionFunction>(LogUtil::GetLastError),
+ "com.android.art.misc.get_last_error_message",
+ "In some cases the jvmti plugin will log data about errors to the android logcat. These can"
+ " be useful to tools so we make (some) of the messages available here as well. This will"
+ " fill the given 'msg' buffer with the last non-fatal message associated with this"
+ " jvmti-env. Note this is best-effort only, not all log messages will be accessible through"
+ " this API. This will return the last error-message from all threads. Care should be taken"
+ " interpreting the return value when used with a multi-threaded program. The error message"
+ " will only be cleared by a call to 'com.android.art.misc.clear_last_error_message' and will"
+ " not be cleared by intervening successful calls. If no (tracked) error message has been"
+ " sent since the last call to clear_last_error_message this API will return"
+ " JVMTI_ERROR_ABSENT_INFORMATION. Not all failures will cause an error message to be"
+ " recorded.",
+ {
+ { "msg", JVMTI_KIND_ALLOC_BUF, JVMTI_TYPE_CCHAR, false },
+ },
+ {
+ ERR(NULL_POINTER),
+ ERR(ABSENT_INFORMATION),
+ });
+ if (error != ERR(NONE)) {
+ return error;
+ }
+
+ // ClearLastError extension
+ error = add_extension(
+ reinterpret_cast<jvmtiExtensionFunction>(LogUtil::ClearLastError),
+ "com.android.art.misc.clear_last_error_message",
+ "Clears the error message returned by 'com.android.art.misc.get_last_error_message'.",
+ { },
+ { });
+ if (error != ERR(NONE)) {
+ return error;
+ }
+
// Copy into output buffer.
*extension_count_ptr = ext_vector.size();