summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2018-01-22 17:48:56 -0800
committer Andreas Gampe <agampe@google.com> 2018-01-22 17:48:56 -0800
commit221d9810aa8af1ceab4626620a81baf0fd8377d7 (patch)
treeae8e10655b727bb7a79607d9778dab6aee29c2ab
parent8105dad6cb540f6521d25507ae3e70718bc7a264 (diff)
ART: Use libbase for logging in command-line tools
Use LOG for logging, and StderrLogger to redirect all logging to the terminal. This only applies to tools used only on the command-line. Test: m test-art-host Change-Id: Ia3a6363a06c6a849eb1068213962d686c4495e29
-rw-r--r--dexdump/dexdump.cc19
-rw-r--r--dexdump/dexdump_main.cc37
-rw-r--r--dexlayout/dex_visualize.cc4
-rw-r--r--dexlayout/dexlayout.cc13
-rw-r--r--dexlayout/dexlayout_main.cc52
-rw-r--r--dexlist/dexlist.cc23
-rw-r--r--oatdump/oatdump.cc14
7 files changed, 89 insertions, 73 deletions
diff --git a/dexdump/dexdump.cc b/dexdump/dexdump.cc
index 16cb302a84..24f41aba2e 100644
--- a/dexdump/dexdump.cc
+++ b/dexdump/dexdump.cc
@@ -47,6 +47,7 @@
#include <sstream>
#include <vector>
+#include "android-base/logging.h"
#include "android-base/stringprintf.h"
#include "dex/code_item_accessors-no_art-inl.h"
@@ -1179,7 +1180,7 @@ static void dumpBytecodes(const DexFile* pDexFile, u4 idx,
const Instruction* instruction = &pair.Inst();
const u4 insnWidth = instruction->SizeInCodeUnits();
if (insnWidth == 0) {
- fprintf(stderr, "GLITCH: zero-width instruction at idx=0x%04x\n", pair.DexPc());
+ LOG(WARNING) << "GLITCH: zero-width instruction at idx=0x" << std::hex << pair.DexPc();
break;
}
dumpInstruction(pDexFile, pCode, codeOffset, pair.DexPc(), insnWidth, instruction);
@@ -1259,7 +1260,7 @@ static void dumpMethod(const DexFile* pDexFile, u4 idx, u4 flags,
fprintf(gOutFile, "<method name=\"%s\"\n", name);
const char* returnType = strrchr(typeDescriptor, ')');
if (returnType == nullptr) {
- fprintf(stderr, "bad method type descriptor '%s'\n", typeDescriptor);
+ LOG(ERROR) << "bad method type descriptor '" << typeDescriptor << "'";
goto bail;
}
std::unique_ptr<char[]> dot(descriptorToDot(returnType + 1));
@@ -1278,7 +1279,7 @@ static void dumpMethod(const DexFile* pDexFile, u4 idx, u4 flags,
// Parameters.
if (typeDescriptor[0] != '(') {
- fprintf(stderr, "ERROR: bad descriptor '%s'\n", typeDescriptor);
+ LOG(ERROR) << "ERROR: bad descriptor '" << typeDescriptor << "'";
goto bail;
}
char* tmpBuf = reinterpret_cast<char*>(malloc(strlen(typeDescriptor) + 1));
@@ -1297,7 +1298,7 @@ static void dumpMethod(const DexFile* pDexFile, u4 idx, u4 flags,
} else {
// Primitive char, copy it.
if (strchr("ZBCSIFJD", *base) == nullptr) {
- fprintf(stderr, "ERROR: bad method signature '%s'\n", base);
+ LOG(ERROR) << "ERROR: bad method signature '" << base << "'";
break; // while
}
*cp++ = *base++;
@@ -1444,7 +1445,7 @@ static void dumpClass(const DexFile* pDexFile, int idx, char** pLastPackage) {
if (!(classDescriptor[0] == 'L' &&
classDescriptor[strlen(classDescriptor)-1] == ';')) {
// Arrays and primitives should not be defined explicitly. Keep going?
- fprintf(stderr, "Malformed class name '%s'\n", classDescriptor);
+ LOG(WARNING) << "Malformed class name '" << classDescriptor << "'";
} else if (gOptions.outputFormat == OUTPUT_XML) {
char* mangle = strdup(classDescriptor + 1);
mangle[strlen(mangle)-1] = '\0';
@@ -1694,7 +1695,7 @@ static void dumpCallSite(const DexFile* pDexFile, u4 idx) {
const DexFile::CallSiteIdItem& call_site_id = pDexFile->GetCallSiteId(idx);
CallSiteArrayValueIterator it(*pDexFile, call_site_id);
if (it.Size() < 3) {
- fprintf(stderr, "ERROR: Call site %u has too few values.\n", idx);
+ LOG(ERROR) << "ERROR: Call site " << idx << " has too few values.";
return;
}
@@ -1915,8 +1916,7 @@ int processFile(const char* fileName) {
size_t size = 0;
std::string error_msg;
if (!openAndMapFile(fileName, &base, &size, &error_msg)) {
- fputs(error_msg.c_str(), stderr);
- fputc('\n', stderr);
+ LOG(ERROR) << error_msg;
return -1;
}
const DexFileLoader dex_file_loader;
@@ -1925,8 +1925,7 @@ int processFile(const char* fileName) {
base, size, fileName, /*verify*/ true, kVerifyChecksum, &error_msg, &dex_files)) {
// Display returned error message to user. Note that this error behavior
// differs from the error messages shown by the original Dalvik dexdump.
- fputs(error_msg.c_str(), stderr);
- fputc('\n', stderr);
+ LOG(ERROR) << error_msg;
return -1;
}
diff --git a/dexdump/dexdump_main.cc b/dexdump/dexdump_main.cc
index 2247e7a7e6..3c16fbe008 100644
--- a/dexdump/dexdump_main.cc
+++ b/dexdump/dexdump_main.cc
@@ -28,6 +28,8 @@
#include <string.h>
#include <unistd.h>
+#include <android-base/logging.h>
+
namespace art {
static const char* gProgName = "dexdump";
@@ -36,19 +38,19 @@ static const char* gProgName = "dexdump";
* Shows usage.
*/
static void usage(void) {
- fprintf(stderr, "Copyright (C) 2007 The Android Open Source Project\n\n");
- fprintf(stderr, "%s: [-a] [-c] [-d] [-e] [-f] [-h] [-i] [-l layout] [-o outfile]"
- " dexfile...\n\n", gProgName);
- fprintf(stderr, " -a : display annotations\n");
- fprintf(stderr, " -c : verify checksum and exit\n");
- fprintf(stderr, " -d : disassemble code sections\n");
- fprintf(stderr, " -e : display exported items only\n");
- fprintf(stderr, " -f : display summary information from file header\n");
- fprintf(stderr, " -g : display CFG for dex\n");
- fprintf(stderr, " -h : display file header details\n");
- fprintf(stderr, " -i : ignore checksum failures\n");
- fprintf(stderr, " -l : output layout, either 'plain' or 'xml'\n");
- fprintf(stderr, " -o : output file name (defaults to stdout)\n");
+ LOG(ERROR) << "Copyright (C) 2007 The Android Open Source Project\n";
+ LOG(ERROR) << gProgName << ": [-a] [-c] [-d] [-e] [-f] [-h] [-i] [-l layout] [-o outfile]"
+ " dexfile...\n";
+ LOG(ERROR) << " -a : display annotations";
+ LOG(ERROR) << " -c : verify checksum and exit";
+ LOG(ERROR) << " -d : disassemble code sections";
+ LOG(ERROR) << " -e : display exported items only";
+ LOG(ERROR) << " -f : display summary information from file header";
+ LOG(ERROR) << " -g : display CFG for dex";
+ LOG(ERROR) << " -h : display file header details";
+ LOG(ERROR) << " -i : ignore checksum failures";
+ LOG(ERROR) << " -l : output layout, either 'plain' or 'xml'";
+ LOG(ERROR) << " -o : output file name (defaults to stdout)";
}
/*
@@ -112,11 +114,11 @@ int dexdumpDriver(int argc, char** argv) {
// Detect early problems.
if (optind == argc) {
- fprintf(stderr, "%s: no file specified\n", gProgName);
+ LOG(ERROR) << "No file specified";
wantUsage = true;
}
if (gOptions.checksumOnly && gOptions.ignoreBadChecksum) {
- fprintf(stderr, "Can't specify both -c and -i\n");
+ LOG(ERROR) << "Can't specify both -c and -i";
wantUsage = true;
}
if (wantUsage) {
@@ -128,7 +130,7 @@ int dexdumpDriver(int argc, char** argv) {
if (gOptions.outputFileName) {
gOutFile = fopen(gOptions.outputFileName, "w");
if (!gOutFile) {
- fprintf(stderr, "Can't open %s\n", gOptions.outputFileName);
+ PLOG(ERROR) << "Can't open " << gOptions.outputFileName;
return 1;
}
}
@@ -144,5 +146,8 @@ int dexdumpDriver(int argc, char** argv) {
} // namespace art
int main(int argc, char** argv) {
+ // Output all logging to stderr.
+ android::base::SetLogger(android::base::StderrLogger);
+
return art::dexdumpDriver(argc, argv);
}
diff --git a/dexlayout/dex_visualize.cc b/dexlayout/dex_visualize.cc
index e4ed69b8d2..516a3382fd 100644
--- a/dexlayout/dex_visualize.cc
+++ b/dexlayout/dex_visualize.cc
@@ -29,6 +29,8 @@
#include <memory>
#include <vector>
+#include <android-base/logging.h>
+
#include "dex_ir.h"
#include "dexlayout.h"
#include "jit/profile_compilation_info.h"
@@ -246,7 +248,7 @@ void VisualizeDexLayout(dex_ir::Header* header,
ProfileCompilationInfo* profile_info) {
std::unique_ptr<Dumper> dumper(new Dumper(header));
if (!dumper->OpenAndPrintHeader(dex_file_index)) {
- fprintf(stderr, "Could not open output file.\n");
+ LOG(ERROR) << "Could not open output file.";
return;
}
diff --git a/dexlayout/dexlayout.cc b/dexlayout/dexlayout.cc
index 3d3b121190..6dc9fb5715 100644
--- a/dexlayout/dexlayout.cc
+++ b/dexlayout/dexlayout.cc
@@ -1052,7 +1052,7 @@ void DexLayout::DumpBytecodes(uint32_t idx, const dex_ir::CodeItem* code, uint32
for (const DexInstructionPcPair& inst : code->Instructions()) {
const uint32_t insn_width = inst->SizeInCodeUnits();
if (insn_width == 0) {
- fprintf(stderr, "GLITCH: zero-width instruction at idx=0x%04x\n", inst.DexPc());
+ LOG(WARNING) << "GLITCH: zero-width instruction at idx=0x" << std::hex << inst.DexPc();
break;
}
DumpInstruction(code, code_offset, inst.DexPc(), insn_width, &inst.Inst());
@@ -1220,7 +1220,7 @@ void DexLayout::DumpMethod(uint32_t idx, uint32_t flags, const dex_ir::CodeItem*
fprintf(out_file_, "<method name=\"%s\"\n", name);
const char* return_type = strrchr(type_descriptor, ')');
if (return_type == nullptr) {
- fprintf(stderr, "bad method type descriptor '%s'\n", type_descriptor);
+ LOG(ERROR) << "bad method type descriptor '" << type_descriptor << "'";
goto bail;
}
std::string dot(DescriptorToDotWrapper(return_type + 1));
@@ -1239,7 +1239,7 @@ void DexLayout::DumpMethod(uint32_t idx, uint32_t flags, const dex_ir::CodeItem*
// Parameters.
if (type_descriptor[0] != '(') {
- fprintf(stderr, "ERROR: bad descriptor '%s'\n", type_descriptor);
+ LOG(ERROR) << "ERROR: bad descriptor '" << type_descriptor << "'";
goto bail;
}
char* tmp_buf = reinterpret_cast<char*>(malloc(strlen(type_descriptor) + 1));
@@ -1258,7 +1258,7 @@ void DexLayout::DumpMethod(uint32_t idx, uint32_t flags, const dex_ir::CodeItem*
} else {
// Primitive char, copy it.
if (strchr("ZBCSIFJD", *base) == nullptr) {
- fprintf(stderr, "ERROR: bad method signature '%s'\n", base);
+ LOG(ERROR) << "ERROR: bad method signature '" << base << "'";
break; // while
}
*cp++ = *base++;
@@ -1368,7 +1368,7 @@ void DexLayout::DumpClass(int idx, char** last_package) {
if (!(class_descriptor[0] == 'L' &&
class_descriptor[strlen(class_descriptor)-1] == ';')) {
// Arrays and primitives should not be defined explicitly. Keep going?
- fprintf(stderr, "Malformed class name '%s'\n", class_descriptor);
+ LOG(ERROR) << "Malformed class name '" << class_descriptor << "'";
} else if (options_.output_format_ == kOutputXml) {
char* mangle = strdup(class_descriptor + 1);
mangle[strlen(mangle)-1] = '\0';
@@ -1977,8 +1977,7 @@ int DexLayout::ProcessFile(const char* file_name) {
file_name, file_name, /* verify */ true, verify_checksum, &error_msg, &dex_files)) {
// Display returned error message to user. Note that this error behavior
// differs from the error messages shown by the original Dalvik dexdump.
- fputs(error_msg.c_str(), stderr);
- fputc('\n', stderr);
+ LOG(ERROR) << error_msg;
return -1;
}
diff --git a/dexlayout/dexlayout_main.cc b/dexlayout/dexlayout_main.cc
index 83fb99a734..87820fb3ee 100644
--- a/dexlayout/dexlayout_main.cc
+++ b/dexlayout/dexlayout_main.cc
@@ -44,25 +44,26 @@ static const char* kProgramName = "dexlayout";
* Shows usage.
*/
static void Usage(void) {
- fprintf(stderr, "Copyright (C) 2016 The Android Open Source Project\n\n");
- fprintf(stderr, "%s: [-a] [-c] [-d] [-e] [-f] [-h] [-i] [-l layout] [-o outfile] [-p profile]"
- " [-s] [-t] [-v] [-w directory] dexfile...\n\n", kProgramName);
- fprintf(stderr, " -a : display annotations\n");
- fprintf(stderr, " -b : build dex_ir\n");
- fprintf(stderr, " -c : verify checksum and exit\n");
- fprintf(stderr, " -d : disassemble code sections\n");
- fprintf(stderr, " -e : display exported items only\n");
- fprintf(stderr, " -f : display summary information from file header\n");
- fprintf(stderr, " -h : display file header details\n");
- fprintf(stderr, " -i : ignore checksum failures\n");
- fprintf(stderr, " -l : output layout, either 'plain' or 'xml'\n");
- fprintf(stderr, " -o : output file name (defaults to stdout)\n");
- fprintf(stderr, " -p : profile file name (defaults to no profile)\n");
- fprintf(stderr, " -s : visualize reference pattern\n");
- fprintf(stderr, " -t : display file section sizes\n");
- fprintf(stderr, " -v : verify output file is canonical to input (IR level comparison)\n");
- fprintf(stderr, " -w : output dex directory \n");
- fprintf(stderr, " -x : compact dex generation level, either 'none' or 'fast'\n");
+ LOG(ERROR) << "Copyright (C) 2016 The Android Open Source Project\n";
+ LOG(ERROR) << kProgramName
+ << ": [-a] [-c] [-d] [-e] [-f] [-h] [-i] [-l layout] [-o outfile] [-p profile]"
+ " [-s] [-t] [-v] [-w directory] dexfile...\n";
+ LOG(ERROR) << " -a : display annotations";
+ LOG(ERROR) << " -b : build dex_ir";
+ LOG(ERROR) << " -c : verify checksum and exit";
+ LOG(ERROR) << " -d : disassemble code sections";
+ LOG(ERROR) << " -e : display exported items only";
+ LOG(ERROR) << " -f : display summary information from file header";
+ LOG(ERROR) << " -h : display file header details";
+ LOG(ERROR) << " -i : ignore checksum failures";
+ LOG(ERROR) << " -l : output layout, either 'plain' or 'xml'";
+ LOG(ERROR) << " -o : output file name (defaults to stdout)";
+ LOG(ERROR) << " -p : profile file name (defaults to no profile)";
+ LOG(ERROR) << " -s : visualize reference pattern";
+ LOG(ERROR) << " -t : display file section sizes";
+ LOG(ERROR) << " -v : verify output file is canonical to input (IR level comparison)";
+ LOG(ERROR) << " -w : output dex directory";
+ LOG(ERROR) << " -x : compact dex generation level, either 'none' or 'fast'";
}
/*
@@ -159,11 +160,11 @@ int DexlayoutDriver(int argc, char** argv) {
// Detect early problems.
if (optind == argc) {
- fprintf(stderr, "%s: no file specified\n", kProgramName);
+ LOG(ERROR) << "no file specified";
want_usage = true;
}
if (options.checksum_only_ && options.ignore_bad_checksum_) {
- fprintf(stderr, "Can't specify both -c and -i\n");
+ LOG(ERROR) << "Can't specify both -c and -i";
want_usage = true;
}
if (want_usage) {
@@ -176,7 +177,7 @@ int DexlayoutDriver(int argc, char** argv) {
if (options.output_file_name_) {
out_file = fopen(options.output_file_name_, "w");
if (!out_file) {
- fprintf(stderr, "Can't open %s\n", options.output_file_name_);
+ PLOG(ERROR) << "Can't open " << options.output_file_name_;
return 1;
}
}
@@ -186,12 +187,12 @@ int DexlayoutDriver(int argc, char** argv) {
if (options.profile_file_name_) {
int profile_fd = open(options.profile_file_name_, O_RDONLY);
if (profile_fd < 0) {
- fprintf(stderr, "Can't open %s\n", options.profile_file_name_);
+ PLOG(ERROR) << "Can't open " << options.profile_file_name_;
return 1;
}
profile_info.reset(new ProfileCompilationInfo());
if (!profile_info->Load(profile_fd)) {
- fprintf(stderr, "Can't read profile info from %s\n", options.profile_file_name_);
+ LOG(ERROR) << "Can't read profile info from " << options.profile_file_name_;
return 1;
}
}
@@ -216,5 +217,8 @@ int DexlayoutDriver(int argc, char** argv) {
} // namespace art
int main(int argc, char** argv) {
+ // Output all logging to stderr.
+ android::base::SetLogger(android::base::StderrLogger);
+
return art::DexlayoutDriver(argc, argv);
}
diff --git a/dexlist/dexlist.cc b/dexlist/dexlist.cc
index 8daaef19dc..ca02052299 100644
--- a/dexlist/dexlist.cc
+++ b/dexlist/dexlist.cc
@@ -32,6 +32,8 @@
#include <sys/stat.h>
#include <unistd.h>
+#include <android-base/logging.h>
+
#include "dex/code_item_accessors-no_art-inl.h"
#include "dex/dex_file-inl.h"
#include "dex/dex_file_loader.h"
@@ -207,16 +209,14 @@ static int processFile(const char* fileName) {
size_t size = 0;
std::string error_msg;
if (!openAndMapFile(fileName, &base, &size, &error_msg)) {
- fputs(error_msg.c_str(), stderr);
- fputc('\n', stderr);
+ LOG(ERROR) << error_msg;
return -1;
}
std::vector<std::unique_ptr<const DexFile>> dex_files;
const DexFileLoader dex_file_loader;
if (!dex_file_loader.OpenAll(
base, size, fileName, /*verify*/ true, kVerifyChecksum, &error_msg, &dex_files)) {
- fputs(error_msg.c_str(), stderr);
- fputc('\n', stderr);
+ LOG(ERROR) << error_msg;
return -1;
}
@@ -237,9 +237,9 @@ static int processFile(const char* fileName) {
* Shows usage.
*/
static void usage(void) {
- fprintf(stderr, "Copyright (C) 2007 The Android Open Source Project\n\n");
- fprintf(stderr, "%s: [-m p.c.m] [-o outfile] dexfile...\n", gProgName);
- fprintf(stderr, "\n");
+ LOG(ERROR) << "Copyright (C) 2007 The Android Open Source Project\n";
+ LOG(ERROR) << gProgName << ": [-m p.c.m] [-o outfile] dexfile...";
+ LOG(ERROR) << "";
}
/*
@@ -268,7 +268,7 @@ int dexlistDriver(int argc, char** argv) {
gOptions.argCopy = strdup(optarg);
char* meth = strrchr(gOptions.argCopy, '.');
if (meth == nullptr) {
- fprintf(stderr, "Expected: package.Class.method\n");
+ LOG(ERROR) << "Expected: package.Class.method";
wantUsage = true;
} else {
*meth = '\0';
@@ -285,7 +285,7 @@ int dexlistDriver(int argc, char** argv) {
// Detect early problems.
if (optind == argc) {
- fprintf(stderr, "%s: no file specified\n", gProgName);
+ LOG(ERROR) << "No file specified";
wantUsage = true;
}
if (wantUsage) {
@@ -298,7 +298,7 @@ int dexlistDriver(int argc, char** argv) {
if (gOptions.outputFileName) {
gOutFile = fopen(gOptions.outputFileName, "w");
if (!gOutFile) {
- fprintf(stderr, "Can't open %s\n", gOptions.outputFileName);
+ PLOG(ERROR) << "Can't open " << gOptions.outputFileName;
free(gOptions.argCopy);
return 1;
}
@@ -318,6 +318,9 @@ int dexlistDriver(int argc, char** argv) {
} // namespace art
int main(int argc, char** argv) {
+ // Output all logging to stderr.
+ android::base::SetLogger(android::base::StderrLogger);
+
return art::dexlistDriver(argc, argv);
}
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index fcbf2f1c0a..e0e8d7ccbd 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -26,6 +26,7 @@
#include <unordered_set>
#include <vector>
+#include "android-base/logging.h"
#include "android-base/stringprintf.h"
#include "android-base/strings.h"
@@ -2907,7 +2908,7 @@ static int DumpImage(gc::space::ImageSpace* image_space,
std::ostream* os) REQUIRES_SHARED(Locks::mutator_lock_) {
const ImageHeader& image_header = image_space->GetImageHeader();
if (!image_header.IsValid()) {
- fprintf(stderr, "Invalid image header %s\n", image_space->GetImageLocation().c_str());
+ LOG(ERROR) << "Invalid image header " << image_space->GetImageLocation();
return EXIT_FAILURE;
}
ImageDumper image_dumper(os, *image_space, image_header, options);
@@ -3053,7 +3054,7 @@ static int DumpOat(Runtime* runtime, const char* oat_filename, OatDumperOptions*
nullptr,
&error_msg));
if (oat_file == nullptr) {
- fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str());
+ LOG(ERROR) << "Failed to open oat file from '" << oat_filename << "': " << error_msg;
return EXIT_FAILURE;
}
@@ -3075,7 +3076,7 @@ static int SymbolizeOat(const char* oat_filename, std::string& output_name, bool
nullptr,
&error_msg));
if (oat_file == nullptr) {
- fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str());
+ LOG(ERROR) << "Failed to open oat file from '" << oat_filename << "': " << error_msg;
return EXIT_FAILURE;
}
@@ -3090,7 +3091,7 @@ static int SymbolizeOat(const char* oat_filename, std::string& output_name, bool
result = oat_symbolizer.Symbolize();
}
if (!result) {
- fprintf(stderr, "Failed to symbolize\n");
+ LOG(ERROR) << "Failed to symbolize";
return EXIT_FAILURE;
}
@@ -3121,7 +3122,7 @@ class IMTDumper {
nullptr,
&error_msg));
if (oat_file == nullptr) {
- fprintf(stderr, "Failed to open oat file from '%s': %s\n", oat_filename, error_msg.c_str());
+ LOG(ERROR) << "Failed to open oat file from '" << oat_filename << "': " << error_msg;
return false;
}
@@ -3799,6 +3800,9 @@ struct OatdumpMain : public CmdlineMain<OatdumpArgs> {
} // namespace art
int main(int argc, char** argv) {
+ // Output all logging to stderr.
+ android::base::SetLogger(android::base::StderrLogger);
+
art::OatdumpMain main;
return main.Main(argc, argv);
}