blob: 4e62929e2d779bccf1a48954c6c7b1e03b1fcce7 [file] [log] [blame]
diff --git a/src/compat/compat/compat.cc b/src/compat/compat/compat.cc
new file mode 100644
index 0000000..7a671e0
--- /dev/null
+++ b/src/compat/compat/compat.cc
@@ -0,0 +1,14 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string.h>
+
+const char* compat_basename(const char* file) {
+ // Implementation based off of the one in <android-base/logging.cpp>.
+ const char* last_slash = strrchr(file, '/');
+ if (last_slash != nullptr) {
+ return last_slash + 1;
+ }
+ return file;
+}
diff --git a/src/compat/compat/compat.h b/src/compat/compat/compat.h
new file mode 100644
index 0000000..7fbc5d1
--- /dev/null
+++ b/src/compat/compat/compat.h
@@ -0,0 +1,19 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPAT_COMPAT_H_
+#define COMPAT_COMPAT_H_
+
+// Provides functions that are available in libunwindstack's normal build
+// environment (platform/system/core, built at Android ToT) but unavailable in
+// libunwindstack's build environment within Chrome (currenty built at Android
+// NDK 16).
+
+// Replicates the non-modifying GNU basename() function available in <string.h>
+// that was introduced in Android NDK 23: https://bit.ly/31Gkyl9. We rename the
+// function to avoid colliding with any existing basename() functions defined at
+// the global scope.
+const char* compat_basename(const char* file);
+
+#endif // COMPAT_COMPAT_H_
diff --git a/src/libunwindstack/Global.cpp b/src/libunwindstack/Global.cpp
index a20be00..a1fbfc4 100644
--- a/src/libunwindstack/Global.cpp
+++ b/src/libunwindstack/Global.cpp
@@ -21,6 +21,7 @@
#include <string>
#include <vector>
+#include <compat/compat.h>
#include <unwindstack/Global.h>
#include <unwindstack/MapInfo.h>
#include <unwindstack/Maps.h>
@@ -42,7 +43,7 @@ void Global::SetArch(ArchEnum arch) {
uint64_t Global::GetVariableOffset(MapInfo* info, const std::string& variable) {
if (!search_libs_.empty()) {
bool found = false;
- const char* lib = basename(info->name.c_str());
+ const char* lib = compat_basename(info->name.c_str());
for (const std::string& name : search_libs_) {
if (name == lib) {
found = true;
diff --git a/src/libunwindstack/Unwinder.cpp b/src/libunwindstack/Unwinder.cpp
index 3f2e1c1..be70b8a 100644
--- a/src/libunwindstack/Unwinder.cpp
+++ b/src/libunwindstack/Unwinder.cpp
@@ -28,6 +28,7 @@
#include <demangle.h>
+#include <compat/compat.h>
#include <unwindstack/Elf.h>
#include <unwindstack/JitDebug.h>
#include <unwindstack/MapInfo.h>
@@ -196,7 +197,7 @@ void Unwinder::Unwind(const std::vector<std::string>* initial_map_names_to_skip,
if (map_info == nullptr || initial_map_names_to_skip == nullptr ||
std::find(initial_map_names_to_skip->begin(), initial_map_names_to_skip->end(),
- basename(map_info->name.c_str())) == initial_map_names_to_skip->end()) {
+ compat_basename(map_info->name.c_str())) == initial_map_names_to_skip->end()) {
if (regs_->dex_pc() != 0) {
// Add a frame to represent the dex file.
FillInDexFrame();