Make oatdump work on the host by not defaulting --host-prefix if it is explictly set
Change-Id: I188dda58c86c374f50492461814204313a72605e
diff --git a/Android.mk b/Android.mk
index 5e9012e..ec3e4b2 100644
--- a/Android.mk
+++ b/Android.mk
@@ -183,12 +183,20 @@
dump-oat: dump-oat-core dump-oat-boot dump-oat-Calculator
.PHONY: dump-oat-core
-dump-oat-core: $(TARGET_CORE_OAT_OUT) $(OATDUMP)
- $(OATDUMP) --image=$(TARGET_CORE_IMG_OUT) --output=/tmp/core.oatdump.txt
- @echo Output in /tmp/core.oatdump.txt
+dump-oat-core: dump-oat-core-host dump-oat-core-target
+
+.PHONY: dump-oat-core-host
+dump-oat-core-host: $(HOST_CORE_IMG_OUT) $(OATDUMP)
+ $(OATDUMP) --image=$(HOST_CORE_IMG_OUT) --output=/tmp/core.host.oatdump.txt --host-prefix=""
+ @echo Output in /tmp/core.host.oatdump.txt
+
+.PHONY: dump-oat-core-target
+dump-oat-core-target: $(TARGET_CORE_IMG_OUT) $(OATDUMP)
+ $(OATDUMP) --image=$(TARGET_CORE_IMG_OUT) --output=/tmp/core.target.oatdump.txt
+ @echo Output in /tmp/core.target.oatdump.txt
.PHONY: dump-oat-boot
-dump-oat-boot: $(TARGET_BOOT_OAT_OUT) $(OATDUMP)
+dump-oat-boot: $(TARGET_BOOT_IMG_OUT) $(OATDUMP)
$(OATDUMP) --image=$(TARGET_BOOT_IMG_OUT) --output=/tmp/boot.oatdump.txt
@echo Output in /tmp/boot.oatdump.txt
diff --git a/src/oatdump.cc b/src/oatdump.cc
index ae0ad57..f38f878 100644
--- a/src/oatdump.cc
+++ b/src/oatdump.cc
@@ -1086,7 +1086,7 @@
const char* oat_filename = NULL;
const char* image_filename = NULL;
const char* boot_image_filename = NULL;
- std::string host_prefix;
+ UniquePtr<std::string> host_prefix;
std::ostream* os = &std::cout;
UniquePtr<std::ofstream> out;
@@ -1099,7 +1099,7 @@
} else if (option.starts_with("--boot-image=")) {
boot_image_filename = option.substr(strlen("--boot-image=")).data();
} else if (option.starts_with("--host-prefix=")) {
- host_prefix = option.substr(strlen("--host-prefix=")).data();
+ host_prefix.reset(new std::string(option.substr(strlen("--host-prefix=")).data()));
} else if (option.starts_with("--output=")) {
const char* filename = option.substr(strlen("--output=")).data();
out.reset(new std::ofstream(filename));
@@ -1124,10 +1124,12 @@
return EXIT_FAILURE;
}
- if (host_prefix.empty()) {
+ if (host_prefix.get() == NULL) {
const char* android_product_out = getenv("ANDROID_PRODUCT_OUT");
if (android_product_out != NULL) {
- host_prefix = android_product_out;
+ host_prefix.reset(new std::string(android_product_out));
+ } else {
+ host_prefix.reset(new std::string(""));
}
}
@@ -1137,7 +1139,7 @@
fprintf(stderr, "Failed to open oat file from %s\n", oat_filename);
return EXIT_FAILURE;
}
- OatDumper oat_dumper(host_prefix, *oat_file);
+ OatDumper oat_dumper(*host_prefix.get(), *oat_file);
oat_dumper.Dump(*os);
return EXIT_SUCCESS;
}
@@ -1158,8 +1160,8 @@
options.push_back(std::make_pair(image_option.c_str(), reinterpret_cast<void*>(NULL)));
}
- if (!host_prefix.empty()) {
- options.push_back(std::make_pair("host-prefix", host_prefix.c_str()));
+ if (!host_prefix->empty()) {
+ options.push_back(std::make_pair("host-prefix", host_prefix->c_str()));
}
UniquePtr<Runtime> runtime(Runtime::Create(options, false));
@@ -1176,7 +1178,7 @@
fprintf(stderr, "Invalid image header %s\n", image_filename);
return EXIT_FAILURE;
}
- ImageDumper image_dumper(*os, image_filename, host_prefix, *image_space, image_header);
+ ImageDumper image_dumper(*os, image_filename, *host_prefix.get(), *image_space, image_header);
image_dumper.Dump();
return EXIT_SUCCESS;
}