From: Ian Lance Taylor Date: Thu, 13 Mar 2008 01:46:17 +0000 (+0000) Subject: From Craig Silverstein: Implement --debug=files to track file opens, X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2285a61069d360fc56b6cf7371a6fe3ac4e240b7;p=binutils-gdb.git From Craig Silverstein: Implement --debug=files to track file opens, and implement --verbose as a synonym. --- diff --git a/gold/debug.h b/gold/debug.h index 143c7dfbf1d..69a0e292eb0 100644 --- a/gold/debug.h +++ b/gold/debug.h @@ -31,10 +31,11 @@ namespace gold // The different types of debugging we support. These are bitflags. -const int DEBUG_TASK = 1; -const int DEBUG_SCRIPT = 2; +const int DEBUG_TASK = 0x1; +const int DEBUG_SCRIPT = 0x2; +const int DEBUG_FILES = 0x4; -const int DEBUG_ALL = DEBUG_TASK | DEBUG_SCRIPT; +const int DEBUG_ALL = DEBUG_TASK | DEBUG_SCRIPT | DEBUG_FILES; // Convert a debug string to the appropriate enum. inline int @@ -45,6 +46,7 @@ debug_string_to_enum(const char* arg) { { "task", DEBUG_TASK }, { "script", DEBUG_SCRIPT }, + { "files", DEBUG_FILES }, { "all", DEBUG_ALL } }; diff --git a/gold/dirsearch.cc b/gold/dirsearch.cc index 960c8eb4e55..93808899d7c 100644 --- a/gold/dirsearch.cc +++ b/gold/dirsearch.cc @@ -27,6 +27,7 @@ #include #include +#include "debug.h" #include "gold-threads.h" #include "options.h" #include "workqueue.h" @@ -235,6 +236,9 @@ Dirsearch::initialize(Workqueue* workqueue, } } +// NOTE: we only log failed file-lookup attempts here. Successfully +// lookups will eventually get logged in File_read::open. + std::string Dirsearch::find(const std::string& n1, const std::string& n2, bool *is_in_sysroot) const @@ -253,10 +257,20 @@ Dirsearch::find(const std::string& n1, const std::string& n2, *is_in_sysroot = p->is_in_sysroot(); return p->name() + '/' + n1; } - if (!n2.empty() && pdc->find(n2)) - { - *is_in_sysroot = p->is_in_sysroot(); - return p->name() + '/' + n2; + else + gold_debug(DEBUG_FILES, "Attempt to open %s/%s failed", + p->name().c_str(), n1.c_str()); + + if (!n2.empty()) + { + if (pdc->find(n2)) + { + *is_in_sysroot = p->is_in_sysroot(); + return p->name() + '/' + n2; + } + else + gold_debug(DEBUG_FILES, "Attempt to open %s/%s failed", + p->name().c_str(), n2.c_str()); } } diff --git a/gold/fileread.cc b/gold/fileread.cc index 2931d433aa6..14d3b0d2697 100644 --- a/gold/fileread.cc +++ b/gold/fileread.cc @@ -30,6 +30,7 @@ #include #include "filenames.h" +#include "debug.h" #include "parameters.h" #include "options.h" #include "dirsearch.h" @@ -118,6 +119,8 @@ File_read::open(const Task* task, const std::string& name) gold_error(_("%s: fstat failed: %s"), this->name_.c_str(), strerror(errno)); this->size_ = s.st_size; + gold_debug(DEBUG_FILES, "Attempt to open %s succeeded", + this->name_.c_str()); } this->token_.add_writer(task); diff --git a/gold/options.h b/gold/options.h index 48cb28a4304..efe92e22fe4 100644 --- a/gold/options.h +++ b/gold/options.h @@ -458,7 +458,8 @@ class General_options N_("Alias for -d"), NULL); DEFINE_string(debug, options::TWO_DASHES, '\0', "", - N_("Turn on debugging"), N_("[task,script,all][,...]")); + N_("Turn on debugging"), + N_("[all,files,script,task][,...]")); DEFINE_special(defsym, options::TWO_DASHES, '\0', N_("Define a symbol"), N_("SYMBOL=EXPRESSION")); @@ -579,6 +580,9 @@ class General_options DEFINE_uint64(Ttext, options::ONE_DASH, '\0', -1U, N_("Set the address of the text segment"), N_("ADDRESS")); + DEFINE_bool(verbose, options::TWO_DASHES, '\0', false, + N_("Synonym for --debug=files"), NULL); + DEFINE_special(version_script, options::TWO_DASHES, '\0', N_("Read version script"), N_("FILE")); diff --git a/gold/parameters.cc b/gold/parameters.cc index 9c57ef322e1..2e8bab701aa 100644 --- a/gold/parameters.cc +++ b/gold/parameters.cc @@ -45,6 +45,9 @@ Parameters::set_options(const General_options* options) // For speed, we convert the options() debug var from a string to an // enum (from debug.h). this->debug_ = debug_string_to_enum(this->options().debug()); + // If --verbose is set, it acts as "--debug=files". + if (options->verbose()) + this->debug_ |= DEBUG_FILES; } void diff --git a/gold/parameters.h b/gold/parameters.h index 3b10228706f..f932f73a8ac 100644 --- a/gold/parameters.h +++ b/gold/parameters.h @@ -116,7 +116,9 @@ class Parameters int debug() const { - gold_assert(this->options_valid()); + // This can be called before the options are set up. + if (!this->options_valid()) + return 0; return debug_; }