diff options
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 |
commit | 221d9810aa8af1ceab4626620a81baf0fd8377d7 (patch) | |
tree | ae8e10655b727bb7a79607d9778dab6aee29c2ab /dexdump | |
parent | 8105dad6cb540f6521d25507ae3e70718bc7a264 (diff) | |
download | art-221d9810aa8af1ceab4626620a81baf0fd8377d7.tar.gz art-221d9810aa8af1ceab4626620a81baf0fd8377d7.tar.bz2 art-221d9810aa8af1ceab4626620a81baf0fd8377d7.zip |
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
Diffstat (limited to 'dexdump')
-rw-r--r-- | dexdump/dexdump.cc | 19 | ||||
-rw-r--r-- | dexdump/dexdump_main.cc | 37 |
2 files changed, 30 insertions, 26 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); } |