diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 3eef554a0585b8df88a0280bd9e05d090e3dc4fe..4d9691cdeb08351ee400229db41d4dd52718fde6 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -306,6 +306,8 @@ bool Options::Parse(int argc, const char **argv) "Check the AST structure after transform"); panda::PandArg opRecordSource("record-source", false, "Record all functions' source codes to support the "\ "using of [function].toString()"); + panda::PandArg opRecordDebugSource("record-debug-source", false, "Record source code to support "\ + "multi-platform debugger & detailed backtrace in debug mode"); // compiler panda::PandArg opEnableAbcInput("enable-abc-input", false, "Allow abc file as input"); @@ -400,6 +402,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opDumpTransformedAst); argparser_->Add(&opCheckTransformedAstStructure); argparser_->Add(&opRecordSource); + argparser_->Add(&opRecordDebugSource); argparser_->Add(&opParseOnly); argparser_->Add(&opEnableTypeCheck); argparser_->Add(&opEnableAbcInput); @@ -611,6 +614,7 @@ bool Options::Parse(int argc, const char **argv) } compilerOptions_.recordSource = opRecordSource.GetValue(); + compilerOptions_.recordDebugSource = opRecordDebugSource.GetValue(); compilerOptions_.enableAbcInput = opEnableAbcInput.GetValue(); compilerOptions_.dumpAsmProgram = opDumpAsmProgram.GetValue(); compilerOptions_.dumpNormalizedAsmProgram = opDumpNormalizedAsmProgram.GetValue(); diff --git a/es2panda/compiler/core/compilerContext.cpp b/es2panda/compiler/core/compilerContext.cpp index fcc08384b60aaec2af48032abd61c7aa7a9bf56b..517d80b07a6be075b2e610a564233c4844d57b4d 100644 --- a/es2panda/compiler/core/compilerContext.cpp +++ b/es2panda/compiler/core/compilerContext.cpp @@ -20,12 +20,12 @@ namespace panda::es2panda::compiler { CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, - bool isMergeAbc, bool isJsonInputFile, - bool isRecordSource, const std::string &sourceFile, const std::string &pkgName, + bool isMergeAbc, bool isJsonInputFile, bool isRecordSource, + bool isRecordDebugSource, const std::string &sourceFile, const std::string &pkgName, util::StringView recordName, util::PatchFix *patchFixHelper) : binder_(binder), isDebug_(isDebug), isDebuggerEvaluateExpressionMode_(isDebuggerEvaluateExpressionMode), - isMergeAbc_(isMergeAbc), isJsonInputFile_(isJsonInputFile), - isRecordSource_(isRecordSource), sourceFile_(sourceFile), pkgName_(pkgName), recordName_(recordName), + isMergeAbc_(isMergeAbc), isJsonInputFile_(isJsonInputFile), isRecordSource_(isRecordSource), + isRecordDebugSource_(isRecordDebugSource), sourceFile_(sourceFile), pkgName_(pkgName), recordName_(recordName), patchFixHelper_(patchFixHelper), emitter_(std::make_unique(this)) { } diff --git a/es2panda/compiler/core/compilerContext.h b/es2panda/compiler/core/compilerContext.h index 08dfca099cf98d7a642e81764a7372437a5186be..0b185a3470a9e3f91d9c51dac7f5c9704b24db72 100644 --- a/es2panda/compiler/core/compilerContext.h +++ b/es2panda/compiler/core/compilerContext.h @@ -39,7 +39,7 @@ class Emitter; class CompilerContext { public: CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, - bool isMergeAbc, bool isJsonInputFile, bool isRecordSource, + bool isMergeAbc, bool isJsonInputFile, bool isRecordSource, bool isRecordDebugSource, const std::string &sourceFile, const std::string &pkgName, util::StringView recordName, util::PatchFix *patchFixHelper); @@ -118,6 +118,11 @@ public: return isRecordSource_; } + bool IsRecordDebugSource() const + { + return isRecordDebugSource_; + } + private: binder::Binder *binder_; int32_t literalBufferIdx_ {0}; @@ -128,6 +133,7 @@ private: // true when input file is json file bool isJsonInputFile_; bool isRecordSource_; + bool isRecordDebugSource_; std::string sourceFile_; std::string pkgName_; util::StringView recordName_; diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index 2aa6a4600aaee08c18b97254370be39e3bedef03..539e2890fb92beb7d9ec0b40162cdd1d661adeac 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -40,8 +40,8 @@ panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const e const std::string &debugInfoSourceFile, const std::string &pkgName) { CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode, - options.mergeAbc, false, options.recordSource, debugInfoSourceFile, - pkgName, program->RecordName(), patchFixHelper_); + options.mergeAbc, false, options.recordSource, options.recordDebugSource, + debugInfoSourceFile, pkgName, program->RecordName(), patchFixHelper_); ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 2d843f5619130979fce22ab09de8902eefb1c6db..f07617f2742e90766241974eb7e5d5bb8dcc90ce 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -256,7 +256,11 @@ void FunctionEmitter::GenSourceFileDebugInfo() } if (pg_->RootNode()->IsProgram()) { - func_->source_code = SourceCode().Mutf8(); + if (pg_->Context()->IsRecordDebugSource()) { + func_->source_code = SourceCode().Mutf8(); + } else { + func_->source_code = "not supported"; + } } } diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 4b4c0580d7adb1cd8edab5a742f27cf4a0fad49a..0ad663ea0efced600d9f8fa20ba85ae241a1b4ee 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -54,7 +54,7 @@ Compiler::~Compiler() panda::pandasm::Program *CreateJsonContentProgram(std::string src, std::string rname, util::PatchFix *patchFixHelper) { - panda::es2panda::compiler::CompilerContext context(nullptr, false, false, false, true, false, + panda::es2panda::compiler::CompilerContext context(nullptr, false, false, false, true, false, false, src, "", util::StringView(rname), patchFixHelper); context.GetEmitter()->GenRecordNameInfo(); return context.GetEmitter()->Finalize(false, nullptr); diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 56d8c0810ee58da99233091a6e65e735a8f76589..7f46dc5b68ea6acbaa0c4d5c142243ad3e0cdf9e 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -97,6 +97,7 @@ struct CompilerOptions { bool typeExtractor {false}; bool typeDtsBuiltin {false}; bool recordSource {false}; + bool recordDebugSource {false}; int fileThreadCount {0}; int functionThreadCount {0}; int abcClassThreadCount {0};