#if defined(__ELF__) && !defined(OS_FREEBSD) #include #include #include #include #include #include #include #include #include #include #include namespace DB { namespace { class FunctionAddressToLineWithInlines: public FunctionAddressToLineBase { public: static constexpr auto name = "addressToLineWithInlines"; String getName() const override { return name; } static FunctionPtr create(ContextPtr context) { context->checkAccess(AccessType::addressToLineWithInlines); return std::make_shared(); } protected: DataTypePtr getDataType() const override { return std::make_shared(std::make_shared()); } ColumnPtr getResultColumn(const typename ColumnVector::Container & data, size_t input_rows_count) const override { auto result_column = ColumnArray::create(ColumnString::create()); ColumnString & result_strings = typeid_cast(result_column->getData()); ColumnArray::Offsets & result_offsets = result_column->getOffsets(); ColumnArray::Offset current_offset = 0; for (size_t i = 0; i < input_rows_count; ++i) { StringRefs res = implCached(data[i]); for (auto & r : res) result_strings.insertData(r.data, r.size); current_offset += res.size(); result_offsets.push_back(current_offset); } return result_column; } void setResult(StringRefs & result, const Dwarf::LocationInfo & location, const std::vector & inline_frames) const override { appendLocationToResult(result, location, nullptr); for (const auto & inline_frame : inline_frames) appendLocationToResult(result, inline_frame.location, &inline_frame); } private: void appendLocationToResult(StringRefs & result, const Dwarf::LocationInfo & location, const Dwarf::SymbolizedFrame * frame) const { const char * arena_begin = nullptr; WriteBufferFromArena out(cache.arena, arena_begin); writeString(location.file.toString(), out); writeChar(':', out); writeIntText(location.line, out); if (frame && frame->name != nullptr) { writeChar(':', out); int status = 0; writeString(demangle(frame->name, status), out); } result.emplace_back(out.complete()); out.finalize(); } }; } REGISTER_FUNCTION(AddressToLineWithInlines) { factory.registerFunction(); } } #endif