forked from qt-creator/qt-creator
Clang: Print command line args for debugging
...if qtc.clangbackend.verboselib=true. Change-Id: Ibba408db955892daf055b2050d810ce55b9d8913 Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
@@ -30,9 +30,12 @@
|
|||||||
|
|
||||||
#include "commandlinearguments.h"
|
#include "commandlinearguments.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
CommandLineArguments::CommandLineArguments(const std::vector<const char *> &projectPartArguments,
|
CommandLineArguments::CommandLineArguments(const char *filePath,
|
||||||
|
const std::vector<const char *> &projectPartArguments,
|
||||||
const Utf8StringVector &fileArguments,
|
const Utf8StringVector &fileArguments,
|
||||||
bool addVerboseOption)
|
bool addVerboseOption)
|
||||||
{
|
{
|
||||||
@@ -46,6 +49,7 @@ CommandLineArguments::CommandLineArguments(const std::vector<const char *> &proj
|
|||||||
m_arguments.push_back(argument.constData());
|
m_arguments.push_back(argument.constData());
|
||||||
if (addVerboseOption)
|
if (addVerboseOption)
|
||||||
m_arguments.push_back("-v");
|
m_arguments.push_back("-v");
|
||||||
|
m_arguments.push_back(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * const *CommandLineArguments::data() const
|
const char * const *CommandLineArguments::data() const
|
||||||
@@ -58,4 +62,19 @@ int CommandLineArguments::count() const
|
|||||||
return int(m_arguments.size());
|
return int(m_arguments.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *CommandLineArguments::at(int position) const
|
||||||
|
{
|
||||||
|
return m_arguments.at(uint(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandLineArguments::print() const
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
cerr << "Arguments to libclang:";
|
||||||
|
for (const auto &argument : m_arguments)
|
||||||
|
cerr << ' ' << argument;
|
||||||
|
cerr << endl;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
|||||||
@@ -40,12 +40,16 @@ namespace ClangBackEnd {
|
|||||||
class CommandLineArguments
|
class CommandLineArguments
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CommandLineArguments(const std::vector<const char *> &projectPartArguments,
|
CommandLineArguments(const char *filePath,
|
||||||
|
const std::vector<const char *> &projectPartArguments,
|
||||||
const Utf8StringVector &fileArguments,
|
const Utf8StringVector &fileArguments,
|
||||||
bool addVerboseOption);
|
bool addVerboseOption);
|
||||||
|
|
||||||
const char * const *data() const;
|
const char * const *data() const;
|
||||||
int count() const;
|
int count() const;
|
||||||
|
const char * at(int position) const;
|
||||||
|
|
||||||
|
void print() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<const char *> m_arguments;
|
std::vector<const char *> m_arguments;
|
||||||
|
|||||||
@@ -276,11 +276,12 @@ void TranslationUnit::createTranslationUnitIfNeeded() const
|
|||||||
if (!d->translationUnit) {
|
if (!d->translationUnit) {
|
||||||
d->translationUnit = CXTranslationUnit();
|
d->translationUnit = CXTranslationUnit();
|
||||||
|
|
||||||
const bool verboseMode = isVerboseModeEnabled();
|
const auto args = commandLineArguments();
|
||||||
const CommandLineArguments args(d->projectPart.arguments(), d->fileArguments, verboseMode);
|
if (isVerboseModeEnabled())
|
||||||
|
args.print();
|
||||||
|
|
||||||
CXErrorCode errorCode = clang_parseTranslationUnit2(index(),
|
CXErrorCode errorCode = clang_parseTranslationUnit2(index(),
|
||||||
d->filePath.constData(),
|
NULL,
|
||||||
args.data(),
|
args.data(),
|
||||||
args.count(),
|
args.count(),
|
||||||
unsavedFiles().cxUnsavedFiles(),
|
unsavedFiles().cxUnsavedFiles(),
|
||||||
@@ -292,7 +293,6 @@ void TranslationUnit::createTranslationUnitIfNeeded() const
|
|||||||
|
|
||||||
updateIncludeFilePaths();
|
updateIncludeFilePaths();
|
||||||
|
|
||||||
|
|
||||||
updateLastProjectPartChangeTimePoint();
|
updateLastProjectPartChangeTimePoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -356,6 +356,14 @@ void TranslationUnit::updateIncludeFilePaths() const
|
|||||||
d->translationUnits.addWatchedFiles(d->dependedFilePaths);
|
d->translationUnits.addWatchedFiles(d->dependedFilePaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommandLineArguments TranslationUnit::commandLineArguments() const
|
||||||
|
{
|
||||||
|
return CommandLineArguments(d->filePath.constData(),
|
||||||
|
d->projectPart.arguments(),
|
||||||
|
d->fileArguments,
|
||||||
|
isVerboseModeEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
uint TranslationUnit::defaultOptions()
|
uint TranslationUnit::defaultOptions()
|
||||||
{
|
{
|
||||||
return CXTranslationUnit_CacheCompletionResults
|
return CXTranslationUnit_CacheCompletionResults
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class ProjectPart;
|
|||||||
class DiagnosticSet;
|
class DiagnosticSet;
|
||||||
class FileContainer;
|
class FileContainer;
|
||||||
class TranslationUnits;
|
class TranslationUnits;
|
||||||
|
class CommandLineArguments;
|
||||||
|
|
||||||
using time_point = std::chrono::steady_clock::time_point;
|
using time_point = std::chrono::steady_clock::time_point;
|
||||||
|
|
||||||
@@ -106,6 +107,8 @@ public:
|
|||||||
|
|
||||||
void setDirtyIfDependencyIsMet(const Utf8String &filePath);
|
void setDirtyIfDependencyIsMet(const Utf8String &filePath);
|
||||||
|
|
||||||
|
CommandLineArguments commandLineArguments() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkIfNull() const;
|
void checkIfNull() const;
|
||||||
void checkIfFileExists() const;
|
void checkIfFileExists() const;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <commandlinearguments.h>
|
||||||
#include <diagnosticset.h>
|
#include <diagnosticset.h>
|
||||||
#include <filecontainer.h>
|
#include <filecontainer.h>
|
||||||
#include <projectpart.h>
|
#include <projectpart.h>
|
||||||
@@ -61,6 +62,7 @@ using ClangBackEnd::TranslationUnits;
|
|||||||
|
|
||||||
using testing::IsNull;
|
using testing::IsNull;
|
||||||
using testing::NotNull;
|
using testing::NotNull;
|
||||||
|
using testing::Eq;
|
||||||
using testing::Gt;
|
using testing::Gt;
|
||||||
using testing::Contains;
|
using testing::Contains;
|
||||||
using testing::EndsWith;
|
using testing::EndsWith;
|
||||||
@@ -148,6 +150,13 @@ TEST_F(TranslationUnit, ResetedTranslationUnitIsNull)
|
|||||||
ASSERT_TRUE(translationUnit.isNull());
|
ASSERT_TRUE(translationUnit.isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TranslationUnit, LastCommandLineArgumentIsFilePath)
|
||||||
|
{
|
||||||
|
const auto arguments = translationUnit.commandLineArguments();
|
||||||
|
|
||||||
|
ASSERT_THAT(arguments.at(arguments.count() - 1), Eq(translationUnitFilePath));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslationUnitIsGenerated)
|
TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslationUnitIsGenerated)
|
||||||
{
|
{
|
||||||
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
|
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
|
||||||
|
|||||||
Reference in New Issue
Block a user