summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--simpleperf/Android.bp4
-rw-r--r--simpleperf/environment.cpp7
-rw-r--r--simpleperf/environment.h3
-rw-r--r--simpleperf/environment_test.cpp14
-rw-r--r--simpleperf/read_elf.h2
-rw-r--r--simpleperf/testdata/sysfs/module/fake_kernel_module/notes/note.gnu.build-idbin0 -> 24 bytes
6 files changed, 25 insertions, 5 deletions
diff --git a/simpleperf/Android.bp b/simpleperf/Android.bp
index 2671d96e..6ec2f942 100644
--- a/simpleperf/Android.bp
+++ b/simpleperf/Android.bp
@@ -156,6 +156,7 @@ cc_defaults {
"libcutils",
"libprocinfo",
"libevent",
+ "libc++fs",
],
},
android: {
@@ -198,6 +199,9 @@ cc_defaults {
"libprocinfo",
"libunwindstack",
],
+ static_libs: [
+ "libc++fs",
+ ],
},
host: {
static_libs: [
diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp
index da49f71e..b779aba1 100644
--- a/simpleperf/environment.cpp
+++ b/simpleperf/environment.cpp
@@ -251,9 +251,10 @@ bool GetKernelBuildId(BuildId* build_id) {
return result == ElfStatus::NO_ERROR;
}
-bool GetModuleBuildId(const std::string& module_name, BuildId* build_id) {
- std::string notefile = "/sys/module/" + module_name + "/notes/.note.gnu.build-id";
- return GetBuildIdFromNoteFile(notefile, build_id);
+bool GetModuleBuildId(const std::string& module_name, BuildId* build_id,
+ const std::string& sysfs_dir) {
+ std::string notefile = sysfs_dir + "/module/" + module_name + "/notes/.note.gnu.build-id";
+ return GetBuildIdFromNoteFile(notefile, build_id) == ElfStatus::NO_ERROR;
}
bool GetValidThreadsFromThreadString(const std::string& tid_str, std::set<pid_t>* tid_set) {
diff --git a/simpleperf/environment.h b/simpleperf/environment.h
index afd8bf81..91d72836 100644
--- a/simpleperf/environment.h
+++ b/simpleperf/environment.h
@@ -62,7 +62,8 @@ bool GetThreadMmapsInProcess(pid_t pid, std::vector<ThreadMmap>* thread_mmaps);
constexpr char DEFAULT_KERNEL_FILENAME_FOR_BUILD_ID[] = "[kernel.kallsyms]";
bool GetKernelBuildId(BuildId* build_id);
-bool GetModuleBuildId(const std::string& module_name, BuildId* build_id);
+bool GetModuleBuildId(const std::string& module_name, BuildId* build_id,
+ const std::string& sysfs_dir = "/sys");
bool IsThreadAlive(pid_t tid);
std::vector<pid_t> GetAllProcesses();
diff --git a/simpleperf/environment_test.cpp b/simpleperf/environment_test.cpp
index e6fcffbd..076293e7 100644
--- a/simpleperf/environment_test.cpp
+++ b/simpleperf/environment_test.cpp
@@ -16,10 +16,15 @@
#include <gtest/gtest.h>
+#include <filesystem>
+
#include <android-base/file.h>
#include "dso.h"
#include "environment.h"
+#include "get_test_data.h"
+
+namespace fs = std::filesystem;
TEST(environment, PrepareVdsoFile) {
std::string content;
@@ -96,3 +101,12 @@ TEST(environment, GetKernelVersion) {
int minor;
ASSERT_TRUE(GetKernelVersion(&major, &minor));
}
+
+TEST(environment, GetModuleBuildId) {
+ BuildId build_id;
+ fs::path dir(GetTestData("sysfs/module/fake_kernel_module/notes"));
+ ASSERT_TRUE(fs::copy_file(dir / "note.gnu.build-id", dir / ".note.gnu.build-id",
+ fs::copy_options::overwrite_existing));
+ ASSERT_TRUE(GetModuleBuildId("fake_kernel_module", &build_id, GetTestData("sysfs")));
+ ASSERT_EQ(build_id, BuildId("3e0ba155286f3454"));
+}
diff --git a/simpleperf/read_elf.h b/simpleperf/read_elf.h
index b4283664..d649ce98 100644
--- a/simpleperf/read_elf.h
+++ b/simpleperf/read_elf.h
@@ -26,7 +26,7 @@
// decide whether to report error or not. So read ELF functions don't report
// error when something wrong happens, instead they return ElfStatus, which
// identifies different errors met while reading elf file.
-enum ElfStatus {
+enum class ElfStatus {
NO_ERROR,
FILE_NOT_FOUND,
READ_FAILED,
diff --git a/simpleperf/testdata/sysfs/module/fake_kernel_module/notes/note.gnu.build-id b/simpleperf/testdata/sysfs/module/fake_kernel_module/notes/note.gnu.build-id
new file mode 100644
index 00000000..5a4109cc
--- /dev/null
+++ b/simpleperf/testdata/sysfs/module/fake_kernel_module/notes/note.gnu.build-id
Binary files differ