Re-make showmap host supported
Also fix bugs that made it not compile on host. Motivation is to be
able to analyze smaps files easily on the host.
Test: showmap -f maps.txt
Bug: 137034556
Change-Id: I7b8ca1237ce1ec17d02cd5217c73b62ee978cb05
diff --git a/libmeminfo/Android.bp b/libmeminfo/Android.bp
index fc022bd..8eb41b9 100644
--- a/libmeminfo/Android.bp
+++ b/libmeminfo/Android.bp
@@ -30,6 +30,7 @@
cc_library {
name: "libmeminfo",
+ host_supported: true,
defaults: ["libmeminfo_defaults"],
export_include_dirs: ["include"],
export_shared_lib_headers: ["libbase"],
diff --git a/libmeminfo/tools/Android.bp b/libmeminfo/tools/Android.bp
index 2e89c41..a592a25 100644
--- a/libmeminfo/tools/Android.bp
+++ b/libmeminfo/tools/Android.bp
@@ -56,6 +56,7 @@
cc_binary {
name: "showmap",
+ host_supported: true,
cflags: [
"-Wall",
"-Werror",
diff --git a/libmeminfo/tools/showmap.cpp b/libmeminfo/tools/showmap.cpp
index a80fa76..8ea2108 100644
--- a/libmeminfo/tools/showmap.cpp
+++ b/libmeminfo/tools/showmap.cpp
@@ -18,6 +18,7 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/signal.h>
#include <sys/types.h>
#include <unistd.h>
@@ -56,7 +57,7 @@
static VmaInfo g_total;
static std::vector<VmaInfo> g_vmas;
-[[noreturn]] static void usage(int exit_status) {
+[[noreturn]] static void usage(const char* progname, int exit_status) {
fprintf(stderr,
"%s [-aqtv] [-f FILE] PID\n"
"-a\taddresses (show virtual memory map)\n"
@@ -64,7 +65,7 @@
"-t\tterse (show only items with private pages)\n"
"-v\tverbose (don't coalesce maps with the same name)\n"
"-f\tFILE (read from input from FILE instead of PID)\n",
- getprogname());
+ progname);
exit(exit_status);
}
@@ -239,22 +240,22 @@
g_filename = optarg;
break;
case 'h':
- usage(EXIT_SUCCESS);
+ usage(argv[0], EXIT_SUCCESS);
default:
- usage(EXIT_FAILURE);
+ usage(argv[0], EXIT_FAILURE);
}
}
if (g_filename.empty()) {
if ((argc - 1) < optind) {
fprintf(stderr, "Invalid arguments: Must provide <pid> at the end\n");
- usage(EXIT_FAILURE);
+ usage(argv[0], EXIT_FAILURE);
}
g_pid = atoi(argv[optind]);
if (g_pid <= 0) {
fprintf(stderr, "Invalid process id %s\n", argv[optind]);
- usage(EXIT_FAILURE);
+ usage(argv[0], EXIT_FAILURE);
}
g_filename = ::android::base::StringPrintf("/proc/%d/smaps", g_pid);