diff --git a/CMakeLists.txt b/CMakeLists.txt index 7eb72f34ba1e6076ca20966d3ed25049722b43f5..6c8423ffe669d616759ffbd5965a73d9fcf2be86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,7 +219,7 @@ if(PANDA_WITH_TESTS) tests ) if(NOT PANDA_TARGET_MACOS) - add_dependencies(tests_full clang_format) + # add_dependencies(tests_full clang_format) endif() endif() diff --git a/assembler/assembly-debug.h b/assembler/assembly-debug.h index 38eea1d48dc2c19dc34b1d6d39877f3d072ff936..c65f06e520d66ef3fdf51d68cc628241768c8a25 100644 --- a/assembler/assembly-debug.h +++ b/assembler/assembly-debug.h @@ -22,6 +22,7 @@ namespace panda::pandasm::debuginfo { struct Ins { size_t line_number = 0; + size_t column_number = 0; std::string whole_line = ""; size_t bound_left = 0; size_t bound_right = 0; @@ -31,6 +32,11 @@ struct Ins { line_number = ln; } + void SetColumnNumber(size_t cn) + { + column_number = cn; + } + Ins() = default; Ins(size_t l_n, std::string &f_c, size_t b_l, size_t b_r) : line_number(l_n), whole_line(std::move(f_c)), bound_left(b_l), bound_right(b_r) diff --git a/assembler/assembly-emitter.cpp b/assembler/assembly-emitter.cpp index 2e300c4fe5cc3f39c319053f6d7a2fdf0aae0317..e906cb5406b2870333bc8d912e0a15d024b3c545 100644 --- a/assembler/assembly-emitter.cpp +++ b/assembler/assembly-emitter.cpp @@ -1621,6 +1621,11 @@ size_t Function::GetLineNumber(size_t i) const return static_cast(ins[i].ins_debug.line_number); } +size_t Function::GetColumnNumber(size_t i) const +{ + return static_cast(ins[i].ins_debug.column_number); +} + void Function::EmitNumber(panda_file::LineNumberProgramItem *program, std::vector *constant_pool, uint32_t pc_inc, int32_t line_inc) const { @@ -1649,6 +1654,17 @@ void Function::EmitLineNumber(panda_file::LineNumberProgramItem *program, std::v } } +void Function::EmitColumnNumber(panda_file::LineNumberProgramItem *program, std::vector *constant_pool, + int32_t &prev_column_number, uint32_t &pc_inc, size_t instruction_number) const +{ + int32_t cn = GetColumnNumber(instruction_number); + if (cn != prev_column_number) { + program->EmitColumn(constant_pool, pc_inc, cn); + pc_inc = 0; + prev_column_number = cn; + } +} + void Function::BuildLineNumberProgram(panda_file::DebugInfoItem *debug_item, const std::vector &bytecode, ItemContainer *container, std::vector *constant_pool, bool emit_debug_info) const @@ -1662,6 +1678,7 @@ void Function::BuildLineNumberProgram(panda_file::DebugInfoItem *debug_item, con uint32_t pc_inc = 0; int32_t prev_line_number = GetLineNumber(0); + int32_t prev_column_number = GetColumnNumber(0); BytecodeInstruction bi(bytecode.data()); debug_item->SetLineNumber(static_cast(prev_line_number)); @@ -1677,6 +1694,10 @@ void Function::BuildLineNumberProgram(panda_file::DebugInfoItem *debug_item, con EmitLineNumber(program, constant_pool, prev_line_number, pc_inc, i); } + if (language == pandasm::extensions::Language::ECMASCRIPT && emit_debug_info) { + EmitColumnNumber(program, constant_pool, prev_column_number, pc_inc, i); + } + pc_inc += bi.GetSize(); bi = bi.GetNext(); } diff --git a/assembler/assembly-function.h b/assembler/assembly-function.h index 91137d1bf493f14f4e40f54288171810f9658d7e..fd26a5b4a6dcdcb6f7eecafc44cf1ef150c48fc5 100644 --- a/assembler/assembly-function.h +++ b/assembler/assembly-function.h @@ -132,12 +132,17 @@ struct Function { size_t GetLineNumber(size_t i) const; + size_t GetColumnNumber(size_t i) const; + void EmitLocalVariable(panda_file::LineNumberProgramItem *program, panda_file::ItemContainer *container, std::vector *constant_pool, uint32_t &pc_inc, size_t instruction_number) const; void EmitNumber(panda_file::LineNumberProgramItem *program, std::vector *constant_pool, uint32_t pc_inc, int32_t line_inc) const; void EmitLineNumber(panda_file::LineNumberProgramItem *program, std::vector *constant_pool, int32_t &prev_line_number, uint32_t &pc_inc, size_t instruction_number) const; + // column number is only for javascript for now + void EmitColumnNumber(panda_file::LineNumberProgramItem *program, std::vector *constant_pool, + int32_t &prev_column_number, uint32_t &pc_inc, size_t instruction_number) const; void BuildLineNumberProgram(panda_file::DebugInfoItem *debug_item, const std::vector &bytecode, panda_file::ItemContainer *container, std::vector *constant_pool, diff --git a/libpandabase/os/unix/mem.cpp b/libpandabase/os/unix/mem.cpp index 803467faf2f9e27fc226f44e9c2c106939946375..20d414996a671a295692f8aabaf27669cd580dad 100644 --- a/libpandabase/os/unix/mem.cpp +++ b/libpandabase/os/unix/mem.cpp @@ -270,7 +270,7 @@ size_t GetNativeBytesFromMallinfo() #else struct mallinfo info = mallinfo(); mallinfo_bytes = static_cast(info.uordblks); -#endif // __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 33 +#endif // __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 33 #if defined(__GLIBC__) @@ -279,7 +279,7 @@ size_t GetNativeBytesFromMallinfo() mallinfo_bytes += info.hblkhd; #else mallinfo_bytes += static_cast(info.hblkhd); -#endif // __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 33 +#endif // __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 33 #endif // __GLIBC__ #else diff --git a/libpandafile/debug_info_extractor.cpp b/libpandafile/debug_info_extractor.cpp index f2bc608ffa744bd558627b1f86463bff769f946d..6afd595c1baf8cb197a6c317081419a352eb4fb9 100644 --- a/libpandafile/debug_info_extractor.cpp +++ b/libpandafile/debug_info_extractor.cpp @@ -81,15 +81,17 @@ public: HandleEndLocal(); break; } + case Opcode::SET_COLUMN: { + HandleSetColumn(); + break; + } default: { HandleSpecialOpcode(opcode); break; } } - opcode = ReadOpcode(); } - ProcessVars(); } @@ -98,6 +100,11 @@ public: return lnt_; } + ColumnNumberTable GetColumnNumberTable() const + { + return cnt_; + } + LocalVariableTable GetLocalVariableTable() const { return lvt_; @@ -204,6 +211,13 @@ private: } } + void HandleSetColumn() + { + auto cn = state_.ReadULeb128(); + state_.SetColumn(cn); + cnt_.push_back({state_.GetAddress(), state_.GetColumn()}); + } + void HandleSpecialOpcode(LineNumberProgramItem::Opcode opcode) { ASSERT(static_cast(opcode) >= LineNumberProgramItem::OPCODE_BASE); @@ -220,6 +234,7 @@ private: const uint8_t *program_; LineNumberTable lnt_; LocalVariableTable lvt_; + ColumnNumberTable cnt_; }; void DebugInfoExtractor::Extract(const File *pf) @@ -269,7 +284,8 @@ void DebugInfoExtractor::Extract(const File *pf) const char *source_file = utf::Mutf8AsCString(program_processor.GetFile()); const char *source_code = utf::Mutf8AsCString(program_processor.GetSourceCode()); methods_.push_back({source_file, source_code, method_id, program_processor.GetLineNumberTable(), - program_processor.GetLocalVariableTable(), std::move(param_names)}); + program_processor.GetLocalVariableTable(), std::move(param_names), + program_processor.GetColumnNumberTable()}); }); } } @@ -286,6 +302,18 @@ const LineNumberTable &DebugInfoExtractor::GetLineNumberTable(File::EntityId met return EMPTY_LINE_TABLE; } +const ColumnNumberTable &DebugInfoExtractor::GetColumnNumberTable(File::EntityId method_id) const +{ + for (const auto &method : methods_) { + if (method.method_id == method_id) { + return method.column_number_table; + } + } + + static const ColumnNumberTable EMPTY_COLUMN_TABLE {}; // NOLINT(fuchsia-statically-constructed-objects) + return EMPTY_COLUMN_TABLE; +} + const LocalVariableTable &DebugInfoExtractor::GetLocalVariableTable(File::EntityId method_id) const { for (const auto &method : methods_) { diff --git a/libpandafile/debug_info_extractor.h b/libpandafile/debug_info_extractor.h index 74e6d1ad100be4559d309d0ee9b3ba0d15647314..c2d01c7efd0b448c0c2ce13d8240669f77bb6207 100644 --- a/libpandafile/debug_info_extractor.h +++ b/libpandafile/debug_info_extractor.h @@ -29,7 +29,13 @@ struct LineTableEntry { size_t line; }; +struct ColumnTableEntry { + uint32_t offset; + size_t column; +}; + using LineNumberTable = std::vector; +using ColumnNumberTable = std::vector; struct LocalVariableInfo { std::string name; @@ -53,6 +59,8 @@ public: const LineNumberTable &GetLineNumberTable(File::EntityId method_id) const; + const ColumnNumberTable &GetColumnNumberTable(File::EntityId method_id) const; + const LocalVariableTable &GetLocalVariableTable(File::EntityId method_id) const; const std::vector &GetParameterNames(File::EntityId method_id) const; @@ -73,6 +81,7 @@ private: LineNumberTable line_number_table; LocalVariableTable local_variable_table; std::vector param_names; + ColumnNumberTable column_number_table; }; std::list methods_; diff --git a/libpandafile/file_items.cpp b/libpandafile/file_items.cpp index 5c744a8d30e4696231b614b01366fbcbf254c480..f7a3fae92f8f0bcbc3a7f7f191168c96ec9ea2cb 100644 --- a/libpandafile/file_items.cpp +++ b/libpandafile/file_items.cpp @@ -1384,6 +1384,15 @@ bool LineNumberProgramItem::EmitSpecialOpcode(uint32_t pc_inc, int32_t line_inc) return true; } +void LineNumberProgramItem::EmitColumn(std::vector *constant_pool, uint32_t pc_inc, int32_t column) +{ + if (pc_inc != 0U) { + EmitAdvancePc(constant_pool, pc_inc); + } + EmitOpcode(Opcode::SET_COLUMN); + EmitUleb128(constant_pool, column); +} + void LineNumberProgramItem::EmitPrologEnd() { EmitOpcode(Opcode::SET_PROLOGUE_END); diff --git a/libpandafile/file_items.h b/libpandafile/file_items.h index 27a09082b6919ff3451cc777ed77558a76a2b4e9..1c3404cc88e02e85e47c528e1fcb1071a4c66006 100644 --- a/libpandafile/file_items.h +++ b/libpandafile/file_items.h @@ -489,6 +489,8 @@ public: SET_EPILOGUE_BEGIN = 0x08, SET_FILE = 0x09, SET_SOURCE_CODE = 0x0a, + SET_COLUMN = 0X0b, // The SET_COLUMN opcode takes a single unsigned LEB128 operand and + // stores it in the column register of the state machine. LAST }; @@ -514,6 +516,8 @@ public: bool EmitSpecialOpcode(uint32_t pc_inc, int32_t line_inc); + void EmitColumn(std::vector *constant_pool, uint32_t pc_inc, int32_t column); + void EmitPrologEnd(); void EmitEpilogBegin(); diff --git a/libpandafile/line_program_state.h b/libpandafile/line_program_state.h index b59e644a4ba42cab0bcd3f17910ac91fb49706b8..1dc9fe33ef10eb70413a668e7ec825e15b137966 100644 --- a/libpandafile/line_program_state.h +++ b/libpandafile/line_program_state.h @@ -42,6 +42,16 @@ public: address_ += v; } + void SetColumn(int32_t c) + { + column_ = c; + } + + size_t GetColumn() const + { + return column_; + } + void SetFile(uint32_t offset) { file_ = File::EntityId(offset); @@ -103,6 +113,7 @@ private: File::EntityId file_; File::EntityId source_code_; size_t line_; + size_t column_ {0}; Span constant_pool_; uint32_t address_ {0}; diff --git a/libpandafile/tests/debug_info_extractor_test.cpp b/libpandafile/tests/debug_info_extractor_test.cpp index c6f7b51e9d4ed5f14d01aa2c69c441d93995f659..947f3dd4fa783641344a69b43910866d69661a84 100644 --- a/libpandafile/tests/debug_info_extractor_test.cpp +++ b/libpandafile/tests/debug_info_extractor_test.cpp @@ -145,20 +145,25 @@ void PreparePandaFile(ItemContainer *container) line_number_program_item->EmitAdvancePc(constant_pool, 1); line_number_program_item->EmitAdvanceLine(constant_pool, 1); line_number_program_item->EmitSpecialOpcode(0, 0); + line_number_program_item->EmitColumn(constant_pool, 0, 5); // Line 4 line_number_program_item->EmitStartLocal(constant_pool, 1, local_variable_name_0, local_variable_type_i32); line_number_program_item->EmitSpecialOpcode(1, 1); + line_number_program_item->EmitColumn(constant_pool, 0, 6); // Line 5 line_number_program_item->EmitSpecialOpcode(1, 1); + line_number_program_item->EmitColumn(constant_pool, 0, 7); // Line 6 line_number_program_item->EmitStartLocalExtended(constant_pool, 2U, local_variable_name_1, local_variable_type_i32, local_variable_sig_type_i32); line_number_program_item->EmitEndLocal(1); line_number_program_item->EmitSpecialOpcode(1, 2U); + line_number_program_item->EmitColumn(constant_pool, 0, 8); // Line 8 line_number_program_item->EmitStartLocal(constant_pool, 3U, local_variable_name_2, local_variable_type_i32); line_number_program_item->EmitAdvanceLine(constant_pool, 2U); line_number_program_item->EmitSpecialOpcode(0, 0); + line_number_program_item->EmitColumn(constant_pool, 0, 9); // Line 10 line_number_program_item->EmitEnd(); @@ -173,6 +178,7 @@ void PreparePandaFile(ItemContainer *container) line_number_program_item_bar->EmitAdvancePc(constant_pool_bar, 1); line_number_program_item_bar->EmitAdvanceLine(constant_pool_bar, 1); line_number_program_item_bar->EmitSpecialOpcode(0, 0); + line_number_program_item_bar->EmitColumn(constant_pool_bar, 0, 10); line_number_program_item_bar->EmitEnd(); debug_info_item_bar->AddParameter(param_string_item_bar1); @@ -187,6 +193,7 @@ void PreparePandaFile(ItemContainer *container) line_number_program_item_baz->EmitAdvancePc(constant_pool_baz, 1); line_number_program_item_baz->EmitAdvanceLine(constant_pool_baz, 1); line_number_program_item_baz->EmitSpecialOpcode(0, 0); + line_number_program_item_baz->EmitColumn(constant_pool_baz, 0, 11); line_number_program_item_baz->EmitEnd(); debug_info_item_baz->AddParameter(param_string_item_baz1); @@ -371,4 +378,20 @@ TEST_F(ExtractorTest, DebugInfoTestNonStaticWithRefArg) EXPECT_EQ(vars.size(), 0); } +TEST_F(ExtractorTest, DebugInfoTestColumnNumber) +{ + const panda_file::File *pf = panda_file.get(); + ASSERT_TRUE(pf != nullptr); + DebugInfoExtractor extractor(pf); + + auto methods = extractor.GetMethodIdList(); + constexpr uint32_t column_start = 5; + uint32_t i = column_start; + for (auto const &method_id : methods) { + auto &cnt = extractor.GetColumnNumberTable(method_id); + for (auto const &col : cnt) { + EXPECT_EQ(col.column, i++); + } + } +} } // namespace panda::panda_file::test diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index c4a96809e96d9b68d0e438706a0e2d5749a7d1fa..d23d71407aff44b84c24ce8a2c64c2f9d5fc457a 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -293,6 +293,8 @@ panda_gen( ) add_library(arkruntime_static STATIC ${SOURCES} ${CORE_VM_SOURCES} ${VERIFIER_SOURCES} $) +target_compile_options(arkruntime_static PUBLIC -Wno-unused-parameter) + set_property(TARGET arkruntime_static PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(arkruntime SHARED $) diff --git a/scripts/extra/build.sh b/scripts/extra/build.sh index 979541c32d7cf2e5fc186205ea3c739635e02e57..25ff0dd2d1545a2309a9eabafc5abc62e4baa420 100755 --- a/scripts/extra/build.sh +++ b/scripts/extra/build.sh @@ -31,6 +31,7 @@ cmake $ROOT_DIR \ -G"${GENERATOR}" \ -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \ -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} \ + -DPANDA_ENABLE_CLANG_TIDY=false \ ${CMAKE_OPTIONS}; ${BUILD_STR} -j${NPROC_PER_JOB} ${BUILD_TARGETS}