From 783cd7fc259b885d25b5ad07bbf523cd5f5054f3 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 2 Oct 2024 19:39:00 +0000 Subject: [PATCH] [vm] Include version information in DW_AT_producer. This follows gcc and clang's behavior. TEST=readelf Change-Id: Ic009d9439d1e233afda035d0dfd2592c590c0ce2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387821 Reviewed-by: Tess Strickland Commit-Queue: Ryan Macnak --- runtime/vm/dwarf.cc | 6 ++++-- runtime/vm/image_snapshot.cc | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/runtime/vm/dwarf.cc b/runtime/vm/dwarf.cc index 76dd781879a3..0aa736fcd18c 100644 --- a/runtime/vm/dwarf.cc +++ b/runtime/vm/dwarf.cc @@ -9,6 +9,7 @@ #include "vm/elf.h" #include "vm/image_snapshot.h" #include "vm/object_store.h" +#include "vm/version.h" namespace dart { @@ -277,8 +278,9 @@ void Dwarf::WriteDebugInfo(DwarfWriteStream* stream) { zone_, IsolateGroup::Current()->object_store()->root_library()); const String& root_uri = String::Handle(zone_, root_library.url()); stream->string(root_uri.ToCString()); // DW_AT_name - stream->string("Dart VM"); // DW_AT_producer - stream->string(""); // DW_AT_comp_dir + const char* producer = zone_->PrintToString("Dart %s\n", Version::String()); + stream->string(producer); // DW_AT_producer + stream->string(""); // DW_AT_comp_dir // DW_AT_low_pc // The lowest instruction address in this object file that is part of our diff --git a/runtime/vm/image_snapshot.cc b/runtime/vm/image_snapshot.cc index 050f1401aafb..72101c3f8770 100644 --- a/runtime/vm/image_snapshot.cc +++ b/runtime/vm/image_snapshot.cc @@ -1029,8 +1029,22 @@ class DwarfAssemblyStream : public DwarfWriteStream { void u8(uint64_t value) { stream_->Printf("%s %" Pu64 "\n", kSizeDirectives[kInt64SizeLog2], value); } - void string(const char* cstr) { // NOLINT - stream_->Printf(".string \"%s\"\n", cstr); // NOLINT + void string(const char* cstr) { // NOLINT + stream_->WriteString(".string \""); // NOLINT + while (char c = *cstr++) { + if (c == '"') { + stream_->WriteString("\\\""); + } else if (c == '\\') { + stream_->WriteString("\\\\"); + } else if (c == '\n') { + stream_->WriteString("\\n"); + } else if (c == '\r') { + stream_->WriteString("\\r"); + } else { + stream_->WriteByte(c); + } + } + stream_->WriteString("\"\n"); } void WritePrefixedLength(const char* prefix, std::function body) { ASSERT(prefix != nullptr);