Remove mirror:: and ArtMethod deps in utils.{h,cc}
The latest chapter in the ongoing saga of attempting to dump a DEX
file without having to start a whole runtime instance. This episode
finds us removing references to ArtMethod/ArtField/mirror.
One aspect of this change that I would like to call out specfically
is that the utils versions of the "Pretty*" functions all were written
to accept nullptr as an argument. I have split these functions up as
follows:
1) an instance method, such as PrettyClass that obviously requires
this != nullptr.
2) a static method, that behaves the same way as the util method, but
calls the instance method if p != nullptr.
This requires using a full class qualifier for the static methods,
which isn't exactly beautiful. I have tried to remove as many cases
as possible where it was clear p != nullptr.
Bug: 22322814
Test: test-art-host
Change-Id: I21adee3614aa697aa580cd1b86b72d9206e1cb24
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index 0af086c..b3317a5 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -933,7 +933,7 @@
}
if (i != parameters_size || it.HasNext()) {
LOG(ERROR) << "invalid stream - problem with parameter iterator in " << GetLocation()
- << " for method " << PrettyMethod(method_idx, *this);
+ << " for method " << this->PrettyMethod(method_idx);
return false;
}
@@ -1197,6 +1197,50 @@
return val;
}
+std::string DexFile::PrettyMethod(uint32_t method_idx, bool with_signature) const {
+ if (method_idx >= NumMethodIds()) {
+ return StringPrintf("<<invalid-method-idx-%d>>", method_idx);
+ }
+ const DexFile::MethodId& method_id = GetMethodId(method_idx);
+ std::string result(PrettyDescriptor(GetMethodDeclaringClassDescriptor(method_id)));
+ result += '.';
+ result += GetMethodName(method_id);
+ if (with_signature) {
+ const Signature signature = GetMethodSignature(method_id);
+ std::string sig_as_string(signature.ToString());
+ if (signature == Signature::NoSignature()) {
+ return result + sig_as_string;
+ }
+ result = PrettyReturnType(sig_as_string.c_str()) + " " + result +
+ PrettyArguments(sig_as_string.c_str());
+ }
+ return result;
+}
+
+std::string DexFile::PrettyField(uint32_t field_idx, bool with_type) const {
+ if (field_idx >= NumFieldIds()) {
+ return StringPrintf("<<invalid-field-idx-%d>>", field_idx);
+ }
+ const DexFile::FieldId& field_id = GetFieldId(field_idx);
+ std::string result;
+ if (with_type) {
+ result += GetFieldTypeDescriptor(field_id);
+ result += ' ';
+ }
+ result += PrettyDescriptor(GetFieldDeclaringClassDescriptor(field_id));
+ result += '.';
+ result += GetFieldName(field_id);
+ return result;
+}
+
+std::string DexFile::PrettyType(uint32_t type_idx) const {
+ if (type_idx >= NumTypeIds()) {
+ return StringPrintf("<<invalid-type-idx-%d>>", type_idx);
+ }
+ const DexFile::TypeId& type_id = GetTypeId(type_idx);
+ return PrettyDescriptor(GetTypeDescriptor(type_id));
+}
+
// Checks that visibility is as expected. Includes special behavior for M and
// before to allow runtime and build visibility when expecting runtime.
std::ostream& operator<<(std::ostream& os, const DexFile& dex_file) {