2022-06-10 08:22:31 +00:00
|
|
|
#if defined(__ELF__) && !defined(OS_FREEBSD)
|
2022-01-08 12:21:39 +00:00
|
|
|
|
|
|
|
#include <Common/Dwarf.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <Columns/ColumnArray.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypeArray.h>
|
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <IO/WriteBufferFromArena.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <Access/Common/AccessFlags.h>
|
|
|
|
|
2022-01-25 16:20:19 +00:00
|
|
|
#include <Functions/addressToLine.h>
|
2022-01-08 12:21:39 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2022-01-25 16:20:19 +00:00
|
|
|
class FunctionAddressToLineWithInlines: public FunctionAddressToLineBase<StringRefs, Dwarf::LocationInfoMode::FULL_WITH_INLINE>
|
2022-01-08 12:21:39 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "addressToLineWithInlines";
|
2022-01-25 16:30:27 +00:00
|
|
|
String getName() const override { return name; }
|
2022-01-08 12:21:39 +00:00
|
|
|
static FunctionPtr create(ContextPtr context)
|
|
|
|
{
|
|
|
|
context->checkAccess(AccessType::addressToLineWithInlines);
|
|
|
|
return std::make_shared<FunctionAddressToLineWithInlines>();
|
|
|
|
}
|
|
|
|
|
2022-01-25 16:20:19 +00:00
|
|
|
protected:
|
|
|
|
DataTypePtr getDataType() const override
|
2022-01-08 12:21:39 +00:00
|
|
|
{
|
|
|
|
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>());
|
|
|
|
}
|
|
|
|
|
2022-01-25 16:20:19 +00:00
|
|
|
ColumnPtr getResultColumn(const typename ColumnVector<UInt64>::Container & data, size_t input_rows_count) const override
|
2022-01-08 12:21:39 +00:00
|
|
|
{
|
|
|
|
auto result_column = ColumnArray::create(ColumnString::create());
|
|
|
|
ColumnString & result_strings = typeid_cast<ColumnString &>(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;
|
|
|
|
}
|
|
|
|
|
2022-01-25 16:20:19 +00:00
|
|
|
void setResult(StringRefs & result, const Dwarf::LocationInfo & location, const std::vector<Dwarf::SymbolizedFrame> & inline_frames) const override
|
2022-01-08 12:21:39 +00:00
|
|
|
{
|
2022-01-25 16:20:19 +00:00
|
|
|
appendLocationToResult(result, location, nullptr);
|
|
|
|
for (const auto & inline_frame : inline_frames)
|
|
|
|
appendLocationToResult(result, inline_frame.location, &inline_frame);
|
|
|
|
}
|
2022-01-08 12:21:39 +00:00
|
|
|
|
2023-06-25 06:31:02 +00:00
|
|
|
private:
|
|
|
|
void appendLocationToResult(StringRefs & result, const Dwarf::LocationInfo & location, const Dwarf::SymbolizedFrame * frame) const
|
2022-01-08 12:21:39 +00:00
|
|
|
{
|
|
|
|
const char * arena_begin = nullptr;
|
|
|
|
WriteBufferFromArena out(cache.arena, arena_begin);
|
|
|
|
|
|
|
|
writeString(location.file.toString(), out);
|
|
|
|
writeChar(':', out);
|
|
|
|
writeIntText(location.line, out);
|
|
|
|
|
2022-03-18 16:07:54 +00:00
|
|
|
if (frame && frame->name != nullptr)
|
2022-01-08 12:21:39 +00:00
|
|
|
{
|
|
|
|
writeChar(':', out);
|
|
|
|
int status = 0;
|
|
|
|
writeString(demangle(frame->name, status), out);
|
|
|
|
}
|
|
|
|
|
|
|
|
result.emplace_back(out.complete());
|
2023-06-25 06:31:02 +00:00
|
|
|
out.finalize();
|
2022-01-08 12:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(AddressToLineWithInlines)
|
2022-01-08 12:21:39 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionAddressToLineWithInlines>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|