Skip to content

Commit

Permalink
Use retdec::io interface for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Kubov committed Jul 20, 2020
1 parent 2cc59f3 commit fbbff34
Show file tree
Hide file tree
Showing 80 changed files with 472 additions and 518 deletions.
1 change: 0 additions & 1 deletion include/retdec/llvmir2hll/llvmir2hll.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
#include "retdec/llvmir2hll/var_name_gen/var_name_gens/num_var_name_gen.h"
#include "retdec/llvmir2hll/var_renamer/var_renamer.h"
#include "retdec/llvmir2hll/var_renamer/var_renamer_factory.h"
#include "retdec/llvm-support/diagnostics.h"
#include "retdec/utils/container.h"
#include "retdec/utils/conversion.h"
#include "retdec/utils/memory.h"
Expand Down
1 change: 0 additions & 1 deletion include/retdec/llvmir2hll/optimizer/optimizer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "retdec/llvmir2hll/optimizer/optimizer.h"
#include "retdec/llvmir2hll/support/smart_ptr.h"
#include "retdec/llvmir2hll/support/types.h"
#include "retdec/llvm-support/diagnostics.h"
#include "retdec/utils/non_copyable.h"

namespace retdec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <vector>

#include "retdec/llvmir2hll/pattern/pattern_finder_runner.h"
#include "retdec/utils/io/log.h"

namespace retdec {
namespace llvmir2hll {
Expand All @@ -23,7 +24,7 @@ namespace llvmir2hll {
*/
class CLIPatternFinderRunner: public PatternFinderRunner {
public:
CLIPatternFinderRunner(llvm::raw_ostream &os);
CLIPatternFinderRunner(utils::io::Logger &os);

private:
virtual void doActionsBeforePatternFinderRuns(ShPtr<PatternFinder> pf) override;
Expand All @@ -34,7 +35,7 @@ class CLIPatternFinderRunner: public PatternFinderRunner {

private:
/// Output stream, into which the patterns will be emitted.
llvm::raw_ostream &os;
utils::io::Logger &os;
};

} // namespace llvmir2hll
Expand Down
7 changes: 4 additions & 3 deletions include/retdec/llvmir2hll/validator/validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

#include "retdec/llvmir2hll/support/smart_ptr.h"
#include "retdec/llvmir2hll/support/visitors/ordered_all_visitor.h"
#include "retdec/llvm-support/diagnostics.h"
#include "retdec/utils/io/log.h"

using namespace retdec::utils::io;

namespace retdec {
namespace llvmir2hll {
Expand Down Expand Up @@ -49,8 +51,7 @@ class Validator: protected OrderedAllVisitor {
void validationError(const std::string &warningMessage, Args &&... args) {
moduleIsCorrect = false;
if (printMessageOnError) {
retdec::llvm_support::printWarningMessage(warningMessage,
std::forward<Args>(args)...);
Log::error() << Log::Warning << warningMessage << std::endl;
}
}

Expand Down
12 changes: 7 additions & 5 deletions include/retdec/unpacker/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
#ifndef RETDEC_UNPACKER_PLUGIN_H
#define RETDEC_UNPACKER_PLUGIN_H

#include <iostream>
#include <memory>
#include <sstream>
#include <string>

#include "retdec/utils/io/log.h"
#include "retdec/unpacker/unpacker_exception.h"

#define plugin(T) retdec::unpackertool::Plugin::instance<T>()

using namespace retdec::utils::io;

namespace retdec {
namespace unpackertool {

Expand Down Expand Up @@ -171,7 +173,7 @@ class Plugin
*/
template <typename... Args> void log(const Args&... args)
{
Plugin::logImpl(std::cout, "[", getInfo()->name, "] ", args...);
Plugin::logImpl(Log::info(), "[", getInfo()->name, "] ", args...);
}

/**
Expand All @@ -184,7 +186,7 @@ class Plugin
*/
template <typename... Args> void error(const Args&... args)
{
Plugin::logImpl(std::cerr, "[ERROR] [", getInfo()->name, "] ", args...);
Plugin::logImpl(Log::error(), "[ERROR] [", getInfo()->name, "] ", args...);
}

/**
Expand All @@ -211,13 +213,13 @@ class Plugin
private:
PluginExitCode _cachedExitCode; ///< Cached exit code of the plugin for the unpacked file.

template <typename T, typename... Args> static void logImpl(std::ostream& out, const T& data, const Args&... args)
template <typename T, typename... Args> static void logImpl(Logger& out, const T& data, const Args&... args)
{
out << data;
logImpl(out, args...);
}

static void logImpl(std::ostream& out)
static void logImpl(Logger& out)
{
out << std::endl;
}
Expand Down
18 changes: 9 additions & 9 deletions src/ar-extractortool/ar_extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>
#include <limits>
#include <vector>

#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>

#include "retdec/utils/filesystem_path.h"
#include "retdec/utils/io/log.h"
#include "retdec/ar-extractor/archive_wrapper.h"
#include "retdec/ar-extractor/detection.h"

using namespace retdec::utils;
using namespace retdec::utils::io;
using namespace retdec::ar_extractor;
using namespace rapidjson;

Expand Down Expand Up @@ -45,11 +46,10 @@ bool isJson = false;
*
* @param outputStream target stream
*/
void printUsage(
std::ostream &outputStream)
void printUsage(Logger& log)
{

outputStream << "Usage: ar_extractor [OPTIONS] FILE\n\n"
log << "Usage: ar_extractor [OPTIONS] FILE\n\n"
"Options:\n\n"
"--arch-magic\n"
" Check if file starts with archive magic constants.\n"
Expand Down Expand Up @@ -99,7 +99,7 @@ void printUsage(
void printErrorPlainText(
const std::string &message)
{
std::cerr << "Error: " << message << ".\n";
Log::error() << Log::Error << message << ".\n";
}

/**
Expand All @@ -120,7 +120,7 @@ void printErrorJson(
PrettyWriter<StringBuffer> writer(buffer);
errorFile.Accept(writer);

std::cerr << buffer.GetString() << "\n";
Log::error() << buffer.GetString() << "\n";
}

/**
Expand Down Expand Up @@ -163,7 +163,7 @@ int printTable(
}
}

std::cout << result;
Log::info() << result;
return 0;
}

Expand Down Expand Up @@ -213,7 +213,7 @@ int processArguments(
const auto &arg = args[i];

if (arg == "-h" || arg == "--help") {
printUsage(std::cout);
printUsage(Log::info());
return 0;
}
else if (arg == "-o" || arg == "--output") {
Expand Down Expand Up @@ -339,7 +339,7 @@ int processArguments(
return printTable(archive, fixNames, isNum);

case ACTION::OBJECT_COUNT:
std::cout << archive.getNumberOfObjects() << "\n";
Log::info() << archive.getNumberOfObjects() << "\n";
return 0;

case ACTION::EXTRACT_NAME:
Expand Down
2 changes: 0 additions & 2 deletions src/bin2llvmir/analyses/ctor_dtor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>

#include <llvm/IR/Constants.h>
#include <llvm/IR/Instruction.h>
#include <llvm/IR/Instructions.h>
Expand Down
1 change: 0 additions & 1 deletion src/bin2llvmir/analyses/reaching_definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

#include <iomanip>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
Expand Down
1 change: 0 additions & 1 deletion src/bin2llvmir/analyses/symbolic_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>
#include <ostream>
#include <sstream>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>

#include "retdec/bin2llvmir/optimizations/asm_inst_remover/asm_inst_remover.h"
#include "retdec/bin2llvmir/providers/asm_instruction.h"
#include "retdec/bin2llvmir/providers/names.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>

#include "retdec/bin2llvmir/utils/llvm.h"
#include "retdec/bin2llvmir/optimizations/class_hierarchy/hierarchy_analysis.h"
#include "retdec/bin2llvmir/utils/debug.h"
Expand Down
1 change: 0 additions & 1 deletion src/bin2llvmir/optimizations/constants/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <cassert>
#include <iomanip>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
Expand Down
4 changes: 3 additions & 1 deletion src/bin2llvmir/optimizations/decoder/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "retdec/utils/conversion.h"
#include "retdec/utils/string.h"
#include "retdec/utils/io/log.h"
#include "retdec/bin2llvmir/optimizations/decoder/decoder.h"
#include "retdec/bin2llvmir/utils/llvm.h"
#include "retdec/bin2llvmir/utils/capstone.h"
Expand All @@ -17,6 +18,7 @@ using namespace retdec::capstone2llvmir;
using namespace retdec::common;
using namespace retdec::bin2llvmir::st_match;
using namespace retdec::fileformat;
using namespace retdec::utils::io;

namespace retdec {
namespace bin2llvmir {
Expand Down Expand Up @@ -88,7 +90,7 @@ bool Decoder::runCatcher()
}
catch (const BaseError& e)
{
std::cerr << "[capstone2llvmir]: " << e.what() << std::endl;
Log::error() << "[capstone2llvmir]: " << e.what() << std::endl;
exit(1);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/bin2llvmir/optimizations/idioms/idioms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>

#include "retdec/bin2llvmir/optimizations/idioms/idioms.h"
#include "retdec/bin2llvmir/optimizations/idioms/idioms_borland.h"
#include "retdec/bin2llvmir/optimizations/idioms/idioms_common.h"
Expand Down
2 changes: 0 additions & 2 deletions src/bin2llvmir/optimizations/idioms/idioms_magicdivmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>

#include <llvm/IR/PatternMatch.h>

#include "retdec/bin2llvmir/optimizations/idioms/idioms_magicdivmod.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>
#include <functional>

#include <llvm/IR/InstIterator.h>
Expand Down
1 change: 0 additions & 1 deletion src/bin2llvmir/optimizations/param_return/param_return.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <cassert>
#include <iomanip>
#include <iostream>
#include <limits>

#include <llvm/IR/CFG.h>
Expand Down
5 changes: 3 additions & 2 deletions src/bin2llvmir/optimizations/provider_init/provider_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>
#include <regex>

#include <llvm/Support/CommandLine.h>

#include "retdec/utils/io/log.h"
#include "retdec/bin2llvmir/analyses/symbolic_tree.h"
#include "retdec/bin2llvmir/optimizations/provider_init/provider_init.h"
#include "retdec/bin2llvmir/providers/abi/abi.h"
Expand All @@ -24,6 +24,7 @@
#include "retdec/yaracpp/yara_detector.h"

using namespace llvm;
using namespace retdec::utils::io;

namespace retdec {
namespace bin2llvmir {
Expand Down Expand Up @@ -339,7 +340,7 @@ bool ProviderInitialization::runOnModule(Module& m)
{
if (l.bytecode)
{
std::cerr << "Warning: Detected " << l.name
Log::error() << Log::Warning << "Detected " << l.name
<< " bytecode, which cannot be decompiled by our "
"machine-code decompiler. "
"The decompilation result may be inaccurate.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

#include <iomanip>
#include <iostream>

#include <llvm/IR/Instruction.h>
#include <llvm/IR/Instructions.h>
Expand Down
1 change: 0 additions & 1 deletion src/bin2llvmir/optimizations/simple_types/simple_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <cassert>
#include <iomanip>
#include <iostream>

#include <llvm/IR/InstIterator.h>
#include <llvm/IR/Instruction.h>
Expand Down
2 changes: 0 additions & 2 deletions src/bin2llvmir/optimizations/syscalls/arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>

#include <llvm/IR/Constants.h>

#include "retdec/bin2llvmir/optimizations/syscalls/syscalls.h"
Expand Down
2 changes: 0 additions & 2 deletions src/bin2llvmir/optimizations/syscalls/mips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>

#include <llvm/IR/Constants.h>

#include "retdec/bin2llvmir/optimizations/syscalls/syscalls.h"
Expand Down
2 changes: 0 additions & 2 deletions src/bin2llvmir/optimizations/syscalls/x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#include <iostream>

#include <llvm/IR/Constants.h>

#include "retdec/bin2llvmir/optimizations/syscalls/syscalls.h"
Expand Down
Loading

0 comments on commit fbbff34

Please sign in to comment.