Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow verbose output to be directed to a file #7746

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/verbose-to-file.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Allow verbose output to be redirected to a file

Enhanced the "-v" option to accept a filename to redirect verbose output to a file, i.e.
---
dmd -v=info.txt ...
---
This is useful for tools that invoke the compiler and use the verbose output but want do not want to redirect stdout/stderr so that error messages and other information can still get to the user.
4 changes: 2 additions & 2 deletions src/dmd/cli.d
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ struct Usage
Option("unittest",
"compile in unit tests"
),
Option("v",
"verbose"
Option("v[=file]",
"verbose with option to output to a file (defaults to stdout)"
),
Option("vcolumns",
"print character (column) numbers in diagnostics"
Expand Down
6 changes: 3 additions & 3 deletions src/dmd/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,16 @@ extern (C++) final class Module : Package
return null;
if (global.params.verbose)
{
fprintf(global.stdmsg, "import ");
fprintf(global.params.verbose, "import ");
if (packages)
{
for (size_t i = 0; i < packages.dim; i++)
{
Identifier pid = (*packages)[i];
fprintf(global.stdmsg, "%s.", pid.toChars());
fprintf(global.params.verbose, "%s.", pid.toChars());
}
}
fprintf(global.stdmsg, "%s\t(%s)\n", ident.toChars(), m.srcfile.toChars());
fprintf(global.params.verbose, "%s\t(%s)\n", ident.toChars(), m.srcfile.toChars());
}
m = m.parse();

Expand Down
2 changes: 1 addition & 1 deletion src/dmd/dmsc.d
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void backend_init()
exe,
false, //params.trace,
params.nofloat,
params.verbose,
params.verbose ? true : false,
params.optimize,
params.symdebug,
params.alwaysframe,
Expand Down
14 changes: 7 additions & 7 deletions src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
memcpy(name, se.string, se.len);
name[se.len] = 0;
if (global.params.verbose)
fprintf(global.stdmsg, "library %s\n", name);
fprintf(global.params.verbose, "library %s\n", name);
if (global.params.moduleDeps && !global.params.moduleDepsFile)
{
OutBuffer* ob = global.params.moduleDeps;
Expand Down Expand Up @@ -1475,7 +1475,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
{
/* Print unrecognized pragmas
*/
fprintf(global.stdmsg, "pragma %s", pd.ident.toChars());
fprintf(global.params.verbose, "pragma %s", pd.ident.toChars());
if (pd.args)
{
for (size_t i = 0; i < pd.args.dim; i++)
Expand All @@ -1487,15 +1487,15 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
sc = sc.endCTFE();
e = e.ctfeInterpret();
if (i == 0)
fprintf(global.stdmsg, " (");
fprintf(global.params.verbose, " (");
else
fprintf(global.stdmsg, ",");
fprintf(global.stdmsg, "%s", e.toChars());
fprintf(global.params.verbose, ",");
fprintf(global.params.verbose, "%s", e.toChars());
}
if (pd.args.dim)
fprintf(global.stdmsg, ")");
fprintf(global.params.verbose, ")");
}
fprintf(global.stdmsg, "\n");
fprintf(global.params.verbose, "\n");
}
goto Lnodecl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4276,7 +4276,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
}

if (global.params.verbose)
fprintf(global.stdmsg, "file %.*s\t(%s)\n", cast(int)se.len, se.string, name);
fprintf(global.params.verbose, "file %.*s\t(%s)\n", cast(int)se.len, se.string, name);
if (global.params.moduleDeps !is null)
{
OutBuffer* ob = global.params.moduleDeps;
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct Param
bool oneobj; // write one object file instead of multiple ones
bool trace; // insert profiling hooks
bool tracegc; // instrument calls to 'new'
bool verbose; // verbose compile
FILE* verbose; // verbose compile
bool vcg_ast; // write-out codegen-ast
bool showColumns; // print character (column) numbers in diagnostics
bool vtls; // identify thread local variables
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct Param
bool oneobj; // write one object file instead of multiple ones
bool trace; // insert profiling hooks
bool tracegc; // instrument calls to 'new'
bool verbose; // verbose compile
FILE* verbose; // verbose compile
bool vcg_ast; // write-out codegen-ast
bool showColumns; // print character (column) numbers in diagnostics
bool vtls; // identify thread local variables
Expand Down
6 changes: 3 additions & 3 deletions src/dmd/glue.d
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ void genObjFile(Module m, bool multiobj)

if (m.ident == Id.entrypoint)
{
bool v = global.params.verbose;
global.params.verbose = false;
auto v = global.params.verbose;
global.params.verbose = null;

for (size_t i = 0; i < m.members.dim; i++)
{
Expand Down Expand Up @@ -807,7 +807,7 @@ void FuncDeclaration_toObjFile(FuncDeclaration fd, bool multiobj)
fd.semanticRun = PASS.obj;

if (global.params.verbose)
fprintf(global.stdmsg, "function %s\n", fd.toPrettyChars());
fprintf(global.params.verbose, "function %s\n", fd.toPrettyChars());

Symbol *s = toSymbol(fd);
func_t *f = s.Sfunc;
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/inline.d
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ public:
return;

if (global.params.verbose && (eresult || sresult))
fprintf(global.stdmsg, "inlined %s =>\n %s\n", fd.toPrettyChars(), parent.toPrettyChars());
fprintf(global.params.verbose, "inlined %s =>\n %s\n", fd.toPrettyChars(), parent.toPrettyChars());

if (eresult && e.type.ty != Type.Kind.void_)
{
Expand Down Expand Up @@ -1706,7 +1706,7 @@ public void inlineScanModule(Module m)
{
Dsymbol s = (*m.members)[i];
//if (global.params.verbose)
// fprintf(global.stdmsg, "inline scan symbol %s\n", s.toChars());
// fprintf(global.params.verbose, "inline scan symbol %s\n", s.toChars());
scope InlineScanVisitor v = new InlineScanVisitor();
s.accept(v);
}
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ extern (C++) void json_generate(OutBuffer* buf, Modules* modules)
{
Module m = (*modules)[i];
if (global.params.verbose)
fprintf(global.stdmsg, "json gen %s\n", m.toChars());
fprintf(global.params.verbose, "json gen %s\n", m.toChars());
m.accept(json);
}
json.arrayEnd();
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/lib.d
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Library
final void write()
{
if (global.params.verbose)
fprintf(global.stdmsg, "library %s\n", loc.filename);
fprintf(global.params.verbose, "library %s\n", loc.filename);

OutBuffer libbuf;
WriteLibToBuffer(&libbuf);
Expand Down
14 changes: 7 additions & 7 deletions src/dmd/link.d
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ public int runLINK()
{
// Print it
for (size_t i = 0; i < argv.dim; i++)
fprintf(global.stdmsg, "%s ", argv[i]);
fprintf(global.stdmsg, "\n");
fprintf(global.params.verbose, "%s ", argv[i]);
fprintf(global.params.verbose, "\n");
}
argv.push(null);
// set up pipes
Expand Down Expand Up @@ -745,7 +745,7 @@ version (Windows)
int status;
size_t len;
if (global.params.verbose)
fprintf(global.stdmsg, "%s %s\n", cmd, args);
fprintf(global.params.verbose, "%s %s\n", cmd, args);
if (!global.params.mscoff)
{
if ((len = strlen(args)) > 255)
Expand Down Expand Up @@ -808,7 +808,7 @@ version (Windows)
}
}
//if (global.params.verbose)
// fprintf(global.stdmsg, "\n");
// fprintf(global.params.verbose, "\n");
if (status)
{
if (status == -1)
Expand Down Expand Up @@ -853,10 +853,10 @@ public int runProgram()
//printf("runProgram()\n");
if (global.params.verbose)
{
fprintf(global.stdmsg, "%s", global.params.exefile);
fprintf(global.params.verbose, "%s", global.params.exefile);
for (size_t i = 0; i < global.params.runargs.dim; ++i)
fprintf(global.stdmsg, " %s", global.params.runargs[i]);
fprintf(global.stdmsg, "\n");
fprintf(global.params.verbose, " %s", global.params.runargs[i]);
fprintf(global.params.verbose, "\n");
}
// Build argv[]
Strings argv;
Expand Down
62 changes: 38 additions & 24 deletions src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ extern (C++) void genCmain(Scope* sc)
m.members = p.parseModule();
assert(p.token.value == TOK.endOfFile);
assert(!p.errors); // shouldn't have failed to parse it
bool v = global.params.verbose;
global.params.verbose = false;
auto v = global.params.verbose;
global.params.verbose = null;
m.importedFrom = m;
m.importAll(null);
m.dsymbolSemantic(null);
Expand Down Expand Up @@ -474,9 +474,9 @@ private int tryMain(size_t argc, const(char)** argv)

if (global.params.verbose)
{
fprintf(global.stdmsg, "binary %s\n", global.params.argv0);
fprintf(global.stdmsg, "version %s\n", global._version);
fprintf(global.stdmsg, "config %s\n", global.inifilename ? global.inifilename : "(none)");
fprintf(global.params.verbose, "binary %s\n", global.params.argv0);
fprintf(global.params.verbose, "version %s\n", global._version);
fprintf(global.params.verbose, "config %s\n", global.inifilename ? global.inifilename : "(none)");
}
//printf("%d source files\n",files.dim);

Expand Down Expand Up @@ -668,7 +668,7 @@ private int tryMain(size_t argc, const(char)** argv)
{
Module m = modules[modi];
if (global.params.verbose)
fprintf(global.stdmsg, "parse %s\n", m.toChars());
fprintf(global.params.verbose, "parse %s\n", m.toChars());
if (!Module.rootModule)
Module.rootModule = m;
m.importedFrom = m; // m.isRoot() == true
Expand Down Expand Up @@ -725,7 +725,7 @@ private int tryMain(size_t argc, const(char)** argv)
foreach (m; modules)
{
if (global.params.verbose)
fprintf(global.stdmsg, "import %s\n", m.toChars());
fprintf(global.params.verbose, "import %s\n", m.toChars());
genhdrfile(m);
}
}
Expand All @@ -736,7 +736,7 @@ private int tryMain(size_t argc, const(char)** argv)
foreach (m; modules)
{
if (global.params.verbose)
fprintf(global.stdmsg, "importall %s\n", m.toChars());
fprintf(global.params.verbose, "importall %s\n", m.toChars());
m.importAll(null);
}
if (global.errors)
Expand All @@ -748,7 +748,7 @@ private int tryMain(size_t argc, const(char)** argv)
foreach (m; modules)
{
if (global.params.verbose)
fprintf(global.stdmsg, "semantic %s\n", m.toChars());
fprintf(global.params.verbose, "semantic %s\n", m.toChars());
m.dsymbolSemantic(null);
}
//if (global.errors)
Expand All @@ -769,7 +769,7 @@ private int tryMain(size_t argc, const(char)** argv)
foreach (m; modules)
{
if (global.params.verbose)
fprintf(global.stdmsg, "semantic2 %s\n", m.toChars());
fprintf(global.params.verbose, "semantic2 %s\n", m.toChars());
m.semantic2(null);
}
Module.runDeferredSemantic2();
Expand All @@ -780,19 +780,19 @@ private int tryMain(size_t argc, const(char)** argv)
foreach (m; modules)
{
if (global.params.verbose)
fprintf(global.stdmsg, "semantic3 %s\n", m.toChars());
fprintf(global.params.verbose, "semantic3 %s\n", m.toChars());
m.semantic3(null);
}
if (includeImports)
{
// Note: DO NOT USE foreach here because Module.amodules.dim can
// Note: DO NOT USE foreach here because compiledImports.dim can
// change on each iteration of the loop
for (size_t i = 0; i < compiledImports.dim; i++)
{
auto m = compiledImports[i];
assert(m.isRoot);
if (global.params.verbose)
fprintf(global.stdmsg, "semantic3 %s\n", m.toChars());
fprintf(global.params.verbose, "semantic3 %s\n", m.toChars());
m.semantic3(null);
modules.push(m);
}
Expand All @@ -807,7 +807,7 @@ private int tryMain(size_t argc, const(char)** argv)
foreach (m; modules)
{
if (global.params.verbose)
fprintf(global.stdmsg, "inline scan %s\n", m.toChars());
fprintf(global.params.verbose, "inline scan %s\n", m.toChars());
inlineScanModule(m);
}
}
Expand Down Expand Up @@ -926,7 +926,7 @@ private int tryMain(size_t argc, const(char)** argv)
foreach (m; modules)
{
if (global.params.verbose)
fprintf(global.stdmsg, "code %s\n", m.toChars());
fprintf(global.params.verbose, "code %s\n", m.toChars());
genObjFile(m, false);
if (entrypoint && m == rootHasMain)
genObjFile(entrypoint, false);
Expand All @@ -941,7 +941,7 @@ private int tryMain(size_t argc, const(char)** argv)
foreach (m; modules)
{
if (global.params.verbose)
fprintf(global.stdmsg, "code %s\n", m.toChars());
fprintf(global.params.verbose, "code %s\n", m.toChars());
obj_start(cast(char*)m.srcfile.toChars());
genObjFile(m, global.params.multiobj);
if (entrypoint && m == rootHasMain)
Expand Down Expand Up @@ -1339,11 +1339,11 @@ private void printPredefinedVersions()
{
if (global.params.verbose && global.versionids)
{
fprintf(global.stdmsg, "predefs ");
fprintf(global.params.verbose, "predefs ");
foreach (const str; *global.versionids)
fprintf(global.stdmsg, " %s", str.toChars);
fprintf(global.params.verbose, " %s", str.toChars);

fprintf(global.stdmsg, "\n");
fprintf(global.params.verbose, "\n");
}
}

Expand Down Expand Up @@ -1415,9 +1415,9 @@ private bool parseCommandLine(const ref Strings arguments, const size_t argc, re
{
bool errors;

void error(const(char)* format, const(char*) arg = null)
void error(T...)(const(char)* format, T args)
{
dmd.errors.error(Loc(), format, arg);
dmd.errors.error(Loc(), format, args);
errors = true;
}

Expand Down Expand Up @@ -1630,8 +1630,22 @@ private bool parseCommandLine(const ref Strings arguments, const size_t argc, re
else
params.trace = true;
}
else if (arg == "-v") // https://dlang.org/dmd.html#switch-v
params.verbose = true;
else if (p[1] == 'v' && (p[2] == '=' || p[2] == '\0')) // https://dlang.org/dmd.html#switch-v
{
if (p[2] == '\0')
params.verbose = stdout;
else
{
auto filename = p + 3;
params.verbose = fopen(filename, "w");
if (!params.verbose)
{
import core.stdc.errno : errno;
import core.stdc.string : strerror;
error("failed to open verbose output file '%s' (errno %d: %s)", filename, errno, strerror(errno));
}
}
}
else if (arg == "-vcg-ast")
params.vcg_ast = true;
else if (arg == "-vtls") // https://dlang.org/dmd.html#switch-vtls
Expand Down Expand Up @@ -2175,7 +2189,7 @@ private extern(C++) bool marsOnImport(Module m)
(m.md && m.md.packages) ? m.md.packages : &empty, m.ident, m.isPackageFile)))
{
if (global.params.verbose)
fprintf(global.stdmsg, "compileimport (%s)\n", m.srcfile.toChars);
fprintf(global.params.verbose, "compileimport (%s)\n", m.srcfile.toChars);
compiledImports.push(m);
return true; // this import will be compiled
}
Expand Down
Loading