Skip to content
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
2 changes: 1 addition & 1 deletion src/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ auto sourceFiles()
"),
frontend: fileArray(env["D"], "
access.d aggregate.d aliasthis.d apply.d argtypes_x86.d argtypes_sysv_x64.d argtypes_aarch64.d arrayop.d
arraytypes.d astenums.d ast_node.d astcodegen.d asttypename.d attrib.d blockexit.d builtin.d canthrow.d chkformat.d
arraytypes.d astenums.d ast_node.d astcodegen.d asttypename.d attrib.d audit_log.d blockexit.d builtin.d canthrow.d chkformat.d
cli.d clone.d compiler.d cond.d constfold.d cppmangle.d cppmanglewin.d ctfeexpr.d
ctorflow.d dcast.d dclass.d declaration.d delegatize.d denum.d dimport.d
dinterpret.d dmacro.d dmangle.d dmodule.d doc.d dscope.d dstruct.d dsymbol.d dsymbolsem.d
Expand Down
1 change: 1 addition & 0 deletions src/dmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Note that these groups have no strict meaning, the category assignments are a bi
| [dimport.d](https://github.com/dlang/dmd/blob/master/src/dmd/dimport.d) | Renamed imports (`import aliasSymbol = pkg1.pkg2.symbol`) |
| [arrayop.d](https://github.com/dlang/dmd/blob/master/src/dmd/arrayop.d) | Array operations (`a[] = b[] + c[]`) |
| [typinf.d](https://github.com/dlang/dmd/blob/master/src/dmd/typinf.d) | Generate typeinfo for `typeid()` (as well as internals) |
| [audit_log](https://github.com/dlang/dmd/blob/master/src/dmd/audit_log.d) | Generates text files for debugging purposes |

| File | Purpose |
|-----------------------------------------------------------------------------|------------------------------------------------------------------------------------|
Expand Down
67 changes: 67 additions & 0 deletions src/dmd/audit_log.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Generate text files for assistance in frontend development.
*
* Copyright: Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved
* Authors: Alexander Heistermann
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/audit_log.d, _audit_log.d)
* Documentation: https://dlang.org/phobos/dmd_asttypename.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/audit_log.d
*/

module dmd.audit_log;
import core.stdc.stdlib;
import core.stdc.stdio;
import dmd.root.rootobject;
import dmd.globals;
import dmd.ast_node;
import dmd.hdrgen;
import dmd.expression;
import dmd.dsymbol;
import dmd.statement;
import dmd.mtype;
import dmd.init;
import dmd.dtemplate;
import dmd.common.outbuffer;

private FILE*[string] file;

void Log(ASTNode node, string functioncall = __FUNCTION__, string modulecall = __MODULE__)
{
debug(__dmd_debug)
{
bool Exist()
{
auto paramCalls = global.params.calls;
Copy link
Contributor

@RazvanN7 RazvanN7 Mar 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildkite fails because this variable is never used.

for (size_t i = 0; i < paramCalls.length; i++)
{
if (paramCalls[i].toString() == functioncall
|| paramCalls[i].toString() == modulecall)
return true;
}
return false;
}
if (!Exist())
return;
auto tmpstring = "debug/" ~ modulecall ~ "/" ~ functioncall ~ ".txt\0";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug is a common name, maybe we should use __dmd_debug to make sure we are not overwriting anything?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, why the \0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null terminated character as we are dealing with a c interface.

auto tmpfile = file.require(modulecall ~ " " ~ functioncall, fopen(tmpstring.ptr, "w+\0".ptr));
OutBuffer buf;
HdrGenState hgs;
static if (is(typeof(node) == Type))
toCBuffer(node, &buf, node.getTypeInfoIdent(), &hgs);
else
toCBuffer(node, &buf, &hgs);
fputs(buf.extractChars(), tmpfile);
}
}

void closeAll()
{
debug(__dmd_debug)
{
foreach (FILE* f; file)
{
fclose(f);
}
}
}
5 changes: 4 additions & 1 deletion src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ struct Param final
Array<const char* >* debugids;
uint32_t versionlevel;
Array<const char* >* versionids;
Array<const char* >* calls;
_d_dynamicArray< const char > defaultlibname;
_d_dynamicArray< const char > debuglibname;
_d_dynamicArray< const char > mscrtlib;
Expand Down Expand Up @@ -682,6 +683,7 @@ struct Param final
debugids(),
versionlevel(),
versionids(),
calls(),
defaultlibname(),
debuglibname(),
mscrtlib(),
Expand All @@ -704,7 +706,7 @@ struct Param final
mapfile()
{
}
Param(bool obj, bool link = true, bool dll = false, bool lib = false, bool multiobj = false, bool oneobj = false, bool trace = false, bool tracegc = false, bool verbose = false, bool vcg_ast = false, bool showColumns = false, bool vtls = false, bool vtemplates = false, bool vtemplatesListInstances = false, bool vgc = false, bool vfield = false, bool vcomplex = true, bool vin = false, uint8_t symdebug = 0u, bool symdebugref = false, bool optimize = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool stackstomp = false, bool useUnitTests = false, bool useInline = false, FeatureState useDIP25 = (FeatureState)-1, FeatureState useDIP1000 = (FeatureState)-1, bool useDIP1021 = false, bool release = false, bool preservePaths = false, DiagnosticReporting warnings = (DiagnosticReporting)2u, PIC pic = (PIC)0u, bool color = false, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool nofloat = false, bool ignoreUnsupportedPragmas = false, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool noSharedAccess = false, bool previewIn = false, bool shortenedMethods = false, bool betterC = false, bool addMain = false, bool allInst = false, bool fix16997 = true, bool fixAliasThis = false, bool inclusiveInContracts = false, bool ehnogc = false, FeatureState dtorFields = (FeatureState)-1, bool fieldwise = false, FeatureState rvalueRefParam = (FeatureState)-1, CppStdRevision cplusplus = (CppStdRevision)201103u, bool markdown = true, bool vmarkdown = false, bool showGaggedErrors = false, bool printErrorContext = false, bool manual = false, bool usage = false, bool mcpuUsage = false, bool transitionUsage = false, bool checkUsage = false, bool checkActionUsage = false, bool revertUsage = false, bool previewUsage = false, bool externStdUsage = false, bool hcUsage = false, bool logo = false, CHECKENABLE useInvariants = (CHECKENABLE)0u, CHECKENABLE useIn = (CHECKENABLE)0u, CHECKENABLE useOut = (CHECKENABLE)0u, CHECKENABLE useArrayBounds = (CHECKENABLE)0u, CHECKENABLE useAssert = (CHECKENABLE)0u, CHECKENABLE useSwitchError = (CHECKENABLE)0u, CHECKENABLE boundscheck = (CHECKENABLE)0u, CHECKACTION checkAction = (CHECKACTION)0u, uint32_t errorLimit = 20u, _d_dynamicArray< const char > argv0 = {}, Array<const char* > modFileAliasStrings = Array<const char* >(), Array<const char* >* imppath = nullptr, Array<const char* >* fileImppath = nullptr, _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, bool doDocComments = false, _d_dynamicArray< const char > docdir = {}, _d_dynamicArray< const char > docname = {}, Array<const char* > ddocfiles = Array<const char* >(), bool doHdrGeneration = false, _d_dynamicArray< const char > hdrdir = {}, _d_dynamicArray< const char > hdrname = {}, bool hdrStripPlainFunctions = true, CxxHeaderMode doCxxHdrGeneration = (CxxHeaderMode)0u, _d_dynamicArray< const char > cxxhdrdir = {}, _d_dynamicArray< const char > cxxhdrname = {}, bool doJsonGeneration = false, _d_dynamicArray< const char > jsonfilename = {}, JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, OutBuffer* mixinOut = nullptr, const char* mixinFile = nullptr, int32_t mixinLines = 0, uint32_t debuglevel = 0u, Array<const char* >* debugids = nullptr, uint32_t versionlevel = 0u, Array<const char* >* versionids = nullptr, _d_dynamicArray< const char > defaultlibname = {}, _d_dynamicArray< const char > debuglibname = {}, _d_dynamicArray< const char > mscrtlib = {}, _d_dynamicArray< const char > moduleDepsFile = {}, OutBuffer* moduleDeps = nullptr, bool emitMakeDeps = false, _d_dynamicArray< const char > makeDepsFile = {}, Array<const char* > makeDeps = Array<const char* >(), MessageStyle messageStyle = (MessageStyle)0u, bool run = false, Array<const char* > runargs = Array<const char* >(), Array<const char* > objfiles = Array<const char* >(), Array<const char* > linkswitches = Array<const char* >(), Array<bool > linkswitchIsForCC = Array<bool >(), Array<const char* > libfiles = Array<const char* >(), Array<const char* > dllfiles = Array<const char* >(), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}) :
Param(bool obj, bool link = true, bool dll = false, bool lib = false, bool multiobj = false, bool oneobj = false, bool trace = false, bool tracegc = false, bool verbose = false, bool vcg_ast = false, bool showColumns = false, bool vtls = false, bool vtemplates = false, bool vtemplatesListInstances = false, bool vgc = false, bool vfield = false, bool vcomplex = true, bool vin = false, uint8_t symdebug = 0u, bool symdebugref = false, bool optimize = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool stackstomp = false, bool useUnitTests = false, bool useInline = false, FeatureState useDIP25 = (FeatureState)-1, FeatureState useDIP1000 = (FeatureState)-1, bool useDIP1021 = false, bool release = false, bool preservePaths = false, DiagnosticReporting warnings = (DiagnosticReporting)2u, PIC pic = (PIC)0u, bool color = false, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool nofloat = false, bool ignoreUnsupportedPragmas = false, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool noSharedAccess = false, bool previewIn = false, bool shortenedMethods = false, bool betterC = false, bool addMain = false, bool allInst = false, bool fix16997 = true, bool fixAliasThis = false, bool inclusiveInContracts = false, bool ehnogc = false, FeatureState dtorFields = (FeatureState)-1, bool fieldwise = false, FeatureState rvalueRefParam = (FeatureState)-1, CppStdRevision cplusplus = (CppStdRevision)201103u, bool markdown = true, bool vmarkdown = false, bool showGaggedErrors = false, bool printErrorContext = false, bool manual = false, bool usage = false, bool mcpuUsage = false, bool transitionUsage = false, bool checkUsage = false, bool checkActionUsage = false, bool revertUsage = false, bool previewUsage = false, bool externStdUsage = false, bool hcUsage = false, bool logo = false, CHECKENABLE useInvariants = (CHECKENABLE)0u, CHECKENABLE useIn = (CHECKENABLE)0u, CHECKENABLE useOut = (CHECKENABLE)0u, CHECKENABLE useArrayBounds = (CHECKENABLE)0u, CHECKENABLE useAssert = (CHECKENABLE)0u, CHECKENABLE useSwitchError = (CHECKENABLE)0u, CHECKENABLE boundscheck = (CHECKENABLE)0u, CHECKACTION checkAction = (CHECKACTION)0u, uint32_t errorLimit = 20u, _d_dynamicArray< const char > argv0 = {}, Array<const char* > modFileAliasStrings = Array<const char* >(), Array<const char* >* imppath = nullptr, Array<const char* >* fileImppath = nullptr, _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, bool doDocComments = false, _d_dynamicArray< const char > docdir = {}, _d_dynamicArray< const char > docname = {}, Array<const char* > ddocfiles = Array<const char* >(), bool doHdrGeneration = false, _d_dynamicArray< const char > hdrdir = {}, _d_dynamicArray< const char > hdrname = {}, bool hdrStripPlainFunctions = true, CxxHeaderMode doCxxHdrGeneration = (CxxHeaderMode)0u, _d_dynamicArray< const char > cxxhdrdir = {}, _d_dynamicArray< const char > cxxhdrname = {}, bool doJsonGeneration = false, _d_dynamicArray< const char > jsonfilename = {}, JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, OutBuffer* mixinOut = nullptr, const char* mixinFile = nullptr, int32_t mixinLines = 0, uint32_t debuglevel = 0u, Array<const char* >* debugids = nullptr, uint32_t versionlevel = 0u, Array<const char* >* versionids = nullptr, Array<const char* >* calls = nullptr, _d_dynamicArray< const char > defaultlibname = {}, _d_dynamicArray< const char > debuglibname = {}, _d_dynamicArray< const char > mscrtlib = {}, _d_dynamicArray< const char > moduleDepsFile = {}, OutBuffer* moduleDeps = nullptr, bool emitMakeDeps = false, _d_dynamicArray< const char > makeDepsFile = {}, Array<const char* > makeDeps = Array<const char* >(), MessageStyle messageStyle = (MessageStyle)0u, bool run = false, Array<const char* > runargs = Array<const char* >(), Array<const char* > objfiles = Array<const char* >(), Array<const char* > linkswitches = Array<const char* >(), Array<bool > linkswitchIsForCC = Array<bool >(), Array<const char* > libfiles = Array<const char* >(), Array<const char* > dllfiles = Array<const char* >(), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}) :
obj(obj),
link(link),
dll(dll),
Expand Down Expand Up @@ -812,6 +814,7 @@ struct Param final
debugids(debugids),
versionlevel(versionlevel),
versionids(versionids),
calls(calls),
defaultlibname(defaultlibname),
debuglibname(debuglibname),
mscrtlib(mscrtlib),
Expand Down
2 changes: 2 additions & 0 deletions src/dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ extern (C++) struct Param
uint versionlevel; // version level
Array!(const(char)*)* versionids; // version identifiers

Array!(const(char)*)* calls; // list of calls that is being marked for logging

const(char)[] defaultlibname; // default library for non-debug builds
const(char)[] debuglibname; // default library for debug builds
const(char)[] mscrtlib; // MS C runtime library
Expand Down
1 change: 1 addition & 0 deletions src/dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ struct Param

unsigned versionlevel; // version level
Array<const char *> *versionids; // version identifiers
Array<const char *> *calls; // list of calls that is marked for logging

DString defaultlibname; // default library for non-debug builds
DString debuglibname; // default library for debug builds
Expand Down
18 changes: 18 additions & 0 deletions src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,24 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
else
goto Lerror;
}
else if (startsWith(p + 1, "LOG"))
{
//Parse:
// -LOG=identifier
if (p[4] == '=')
{
if (Identifier.isValidIdentifier(p + 5))
{
if (!params.calls)
params.calls = new Array!(const(char)*);
params.calls.push(p + 5);
}
else
goto Lerror;
}
else
goto Lerror;
}
else if (arg == "--b")
driverParams.debugb = true;
else if (arg == "--c")
Expand Down