diff options
author | 2022-09-29 14:40:10 +0100 | |
---|---|---|
committer | 2022-09-30 16:03:54 +0000 | |
commit | 6940a814d9d5724ee715bb9b8d61351fd1923b2b (patch) | |
tree | f98d2803dc31cf03d3fe7b3008779d552390916c | |
parent | 94d89030ca27dc45ffc7b2689cb7754b78db3a28 (diff) |
ANR: Improve parameter removal
Support removing multiple parameters since functions can
be defined inside function (lambdas are very common case).
Bug: 189881220
Test: manual ANR
Change-Id: I9c4ad139bcee09811cb7356ee48199b16483d971
-rw-r--r-- | runtime/Android.bp | 11 | ||||
-rw-r--r-- | runtime/native_stack_dump.cc | 18 | ||||
-rw-r--r-- | runtime/native_stack_dump.h | 4 | ||||
-rw-r--r-- | runtime/native_stack_dump_test.cc | 39 |
4 files changed, 58 insertions, 14 deletions
diff --git a/runtime/Android.bp b/runtime/Android.bp index 2acf8f4fe2..6a9c6b7b76 100644 --- a/runtime/Android.bp +++ b/runtime/Android.bp @@ -779,11 +779,11 @@ art_cc_defaults { srcs: [ "app_info_test.cc", "arch/arch_test.cc", + "arch/arm/instruction_set_features_arm_test.cc", + "arch/arm64/instruction_set_features_arm64_test.cc", "arch/instruction_set_features_test.cc", "arch/memcmp16_test.cc", "arch/stub_test.cc", - "arch/arm/instruction_set_features_arm_test.cc", - "arch/arm64/instruction_set_features_arm64_test.cc", "arch/x86/instruction_set_features_x86_test.cc", "arch/x86_64/instruction_set_features_x86_64_test.cc", "barrier_test.cc", @@ -805,12 +805,12 @@ art_cc_defaults { "gc/heap_test.cc", "gc/heap_verification_test.cc", "gc/reference_queue_test.cc", - "gc/space/dlmalloc_space_static_test.cc", "gc/space/dlmalloc_space_random_test.cc", + "gc/space/dlmalloc_space_static_test.cc", "gc/space/image_space_test.cc", "gc/space/large_object_space_test.cc", - "gc/space/rosalloc_space_static_test.cc", "gc/space/rosalloc_space_random_test.cc", + "gc/space/rosalloc_space_static_test.cc", "gc/space/space_create_test.cc", "gc/system_weak_test.cc", "gc/task_processor_test.cc", @@ -837,8 +837,9 @@ art_cc_defaults { "mirror/var_handle_test.cc", "monitor_pool_test.cc", "monitor_test.cc", - "oat_file_test.cc", + "native_stack_dump_test.cc", "oat_file_assistant_test.cc", + "oat_file_test.cc", "parsed_options_test.cc", "prebuilt_tools_test.cc", "proxy_test.cc", diff --git a/runtime/native_stack_dump.cc b/runtime/native_stack_dump.cc index 0dd13b7b6d..00f61066bb 100644 --- a/runtime/native_stack_dump.cc +++ b/runtime/native_stack_dump.cc @@ -322,17 +322,17 @@ static bool PcIsWithinQuickCode(ArtMethod* method, uintptr_t pc) NO_THREAD_SAFET return code <= pc && pc <= (code + code_size); } -// Remove method parameters by finding matching parenthesis and removing that substring. -std::string_view StripParameters(std::string_view name) { - if (name.empty() || *name.rbegin() != ')') { - return name; - } +// Remove method parameters by finding matching top-level parenthesis and removing them. +// Since functions can be defined inside functions, this can remove multiple substrings. +std::string StripParameters(std::string name) { + size_t end = name.size(); int nesting = 0; for (ssize_t i = name.size() - 1; i > 0; i--) { - if (name[i] == ')') { - nesting++; - } else if (name[i] == '(' && --nesting == 0) { - return name.substr(0, i); + if (name[i] == ')' && nesting++ == 0) { + end = i + 1; + } + if (name[i] == '(' && --nesting == 0) { + name = name.erase(i, end - i); } } return name; diff --git a/runtime/native_stack_dump.h b/runtime/native_stack_dump.h index 99fb59c76a..86a8ce2cab 100644 --- a/runtime/native_stack_dump.h +++ b/runtime/native_stack_dump.h @@ -31,6 +31,10 @@ namespace art { class ArtMethod; +// Remove method parameters by finding matching top-level parenthesis and removing them. +// Since functions can be defined inside functions, this can remove multiple substrings. +std::string StripParameters(std::string name); + // Dumps the native stack for thread 'tid' to 'os'. void DumpNativeStack(std::ostream& os, pid_t tid, diff --git a/runtime/native_stack_dump_test.cc b/runtime/native_stack_dump_test.cc new file mode 100644 index 0000000000..4446495ede --- /dev/null +++ b/runtime/native_stack_dump_test.cc @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "native_stack_dump.h" + +#include <gtest/gtest.h> + +namespace art { + +TEST(StripParametersTest, ValidInput) { + EXPECT_EQ(StripParameters("foo(int)"), "foo"); + EXPECT_EQ(StripParameters("foo(int, std::string)"), "foo"); + EXPECT_EQ(StripParameters("foo(int) const"), "foo const"); + EXPECT_EQ(StripParameters("foo(int)::bar(int)"), "foo::bar"); + EXPECT_EQ(StripParameters("foo<int>(int)"), "foo<int>"); +} + +TEST(StripParametersTest, InvalidInput) { + EXPECT_EQ(StripParameters("foo(int?"), "foo(int?"); + EXPECT_EQ(StripParameters("foo?int)"), "foo?int)"); + EXPECT_EQ(StripParameters("(foo(int)"), "(foo"); + EXPECT_EQ(StripParameters(")foo(int)"), ")foo"); + EXPECT_EQ(StripParameters("foo(((int)))"), "foo"); +} + +} // namespace art |