Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

[Export] Check debug IDs when exporting with debug symbols.

Pāvels Nadtočajevsf07fe5727b82
diff --git a/core/os/os.cpp b/core/os/os.cpp
index c722e0fa4e2..fabf9345bd9 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -824,6 +824,284 @@ void OS::benchmark_dump() {
#endif
}
+Vector<String> OS::_read_elf_debug_id(const Ref<FileAccess> &p_f) const {
+ // Read program architecture bits from class field.
+ int bits = p_f->get_8() * 32;
+
+ // Get info about the section header table.
+ int64_t section_table_pos;
+ int64_t section_header_size;
+ if (bits == 32) {
+ section_header_size = 40;
+ p_f->seek(0x20);
+ section_table_pos = p_f->get_32();
+ p_f->seek(0x30);
+ } else { // 64
+ section_header_size = 64;
+ p_f->seek(0x28);
+ section_table_pos = p_f->get_64();
+ p_f->seek(0x3c);
+ }
+ int num_sections = p_f->get_16();
+ int string_section_idx = p_f->get_16();
+
+ // Load the strings table.
+ uint8_t *strings;
+ {
+ // Jump to the strings section header.
+ p_f->seek(section_table_pos + string_section_idx * section_header_size);
+
+ // Read strings data size and offset.
+ int64_t string_data_pos;
+ int64_t string_data_size;
+ if (bits == 32) {
+ p_f->seek(p_f->get_position() + 0x10);
+ string_data_pos = p_f->get_32();
+ string_data_size = p_f->get_32();
+ } else { // 64
+ p_f->seek(p_f->get_position() + 0x18);
+ string_data_pos = p_f->get_64();
+ string_data_size = p_f->get_64();
+ }
+ ERR_FAIL_COND_V(string_data_pos == 0 || string_data_size == 0, Vector<String>());
+
+ // Read strings data.
+ p_f->seek(string_data_pos);
+ strings = (uint8_t *)memalloc(string_data_size);
+ ERR_FAIL_NULL_V(strings, Vector<String>());
+ p_f->get_buffer(strings, string_data_size);
+ }
+
+ Vector<String> ids;
+ // Search for the ".note.gnu.build-id" section.
+ for (int i = 0; i < num_sections; ++i) {
+ int64_t section_header_pos = section_table_pos + i * section_header_size;
+ p_f->seek(section_header_pos);
+
+ uint32_t name_offset = p_f->get_32();
+ if (strcmp((char *)strings + name_offset, ".note.gnu.build-id") == 0) {
+ // ".note.gnu.build-id" section found.
+
+ int64_t link_start = 0;
+ if (bits == 32) {
+ p_f->seek(section_header_pos + 0x10);
+ link_start = p_f->get_32();
+ } else { // 64
+ p_f->seek(section_header_pos + 0x18);
+ link_start = p_f->get_64();
+ }
+ p_f->seek(link_start);
+
+ uint32_t name_size = p_f->get_32();
+ uint32_t data_size = p_f->get_32();
+ p_f->get_32(); // Type, skip.
+ if (data_size == 0) {
+ continue;
+ }
+ p_f->seek(p_f->get_position() + name_size);
+ // 160-bit SHA-1.
+ PackedByteArray id = p_f->get_buffer(data_size);
+ ids.push_back(String::hex_encode_buffer(id.ptr(), id.size()));
+ break;
+ }
+ }
+
+ memfree(strings);
+ return ids;
+}
+
+Vector<String> OS::_read_pe_debug_id(const Ref<FileAccess> &p_f) const {
+ // Jump to the PE header and check the magic number.
+ {
+ p_f->seek(0x3c);
+ uint32_t pe_pos = p_f->get_32();
+
+ p_f->seek(pe_pos);
+ uint32_t magic = p_f->get_32();
+ ERR_FAIL_COND_V(magic != 0x00004550, Vector<String>());
+ }
+
+ // Process header.
+ int num_sections = 0;
+
+ int64_t header_pos = p_f->get_position();
+ int64_t opt_header_pos = 0;
+ {
+ p_f->seek(header_pos + 2);
+ num_sections = p_f->get_16();
+ p_f->seek(header_pos + 16);
+ uint16_t opt_header_size = p_f->get_16();
+ opt_header_pos = p_f->get_position() + 2;
+ // Skip rest of header + optional header to go to the section headers.
+ p_f->seek(opt_header_pos + opt_header_size);
+ }
+
+ // Search for the ".buildid" section.
+ int64_t dbg_off = 0;
+ int64_t dbg_size = 0;
+ int64_t section_table_pos = p_f->get_position();
+ for (int i = 0; i < num_sections; i++) {
+ int64_t section_header_pos = section_table_pos + i * 40;
+ p_f->seek(section_header_pos);
+
+ uint8_t section_name[9];
+ p_f->get_buffer(section_name, 8);
+ section_name[8] = 0x00;
+ if (strcmp((char *)section_name, ".buildid") == 0) {
+ p_f->seek(section_table_pos + i * 40 + 16);
+ dbg_size = p_f->get_32();
+ p_f->seek(section_table_pos + i * 40 + 20);
+ dbg_off = p_f->get_32();
+ break;
+ }
+ }
+
+ Vector<String> ids;
+ for (uint32_t pos = dbg_off; pos < dbg_off + dbg_size; pos += 28) {
+ p_f->seek(pos + 12);
+ uint32_t rec_type = p_f->get_32();
+ uint32_t rec_size = p_f->get_32();
+ p_f->get_32();
+ uint32_t rec_offset = p_f->get_32();
+ if (rec_type == 0x00000002) {
+ // TYPE_CODEVIEW
+ p_f->seek(rec_offset);
+ uint32_t cv_signature = p_f->get_32();
+ uint32_t cv_size = 0;
+ if (cv_signature == 0x53445352) {
+ // RSDS
+ cv_size = rec_size - 4;
+ } else {
+ continue;
+ }
+ if (cv_size == 21) {
+ // UUID + 1
+ uint32_t uuid_1 = p_f->get_32();
+ uint16_t uuid_2 = p_f->get_16();
+ uint16_t uuid_3 = p_f->get_16();
+ uint16_t uuid_4 = p_f->get_16();
+ PackedByteArray uuid_5 = p_f->get_buffer(6);
+ uint32_t uuid_6 = p_f->get_32();
+ ids.push_back(vformat("%08x-%04x-%04x-%04x-%s-%x", uuid_1, uuid_2, uuid_3, uuid_4, String::hex_encode_buffer(uuid_5.ptr(), uuid_5.size()), uuid_6));
+ } else {
+ // Unknown ID type, read as is.
+ PackedByteArray id = p_f->get_buffer(cv_size);
+ ids.push_back(String::hex_encode_buffer(id.ptr(), id.size()));
+ }
+ break;
+ }
+ }
+
+ p_f->close();
+ return ids;
+}
+
+Vector<String> OS::_read_macho_debug_id(const Ref<FileAccess> &p_f) const {
+ Vector<uint64_t> offsets;
+ Vector<String> ids;
+
+ p_f->seek(0);
+ uint32_t magic = p_f->get_32();
+ if (magic == 0xbebafeca || magic == 0xcafebabe || magic == 0xbfbafeca || magic == 0xcafebabf) {
+ // LipO.
+ bool swap = (magic == 0xbebafeca || magic == 0xbfbafeca);
+ bool is64 = (magic == 0xbfbafeca || magic == 0xcafebabf);
+ uint32_t fat_archs = p_f->get_32();
+ if (swap) {
+ fat_archs = BSWAP32(fat_archs);
+ }
+ for (uint32_t i = 0; i < fat_archs; i++) {
+ p_f->seek(p_f->get_position() + 2 * 4);
+ if (is64) {
+ uint64_t fat_offset = p_f->get_64();
+ if (swap) {
+ fat_offset = BSWAP64(fat_offset);
+ }
+ offsets.push_back(fat_offset);
+ p_f->seek(p_f->get_position() + 4 * 4);
+ } else {
+ uint32_t fat_offset = p_f->get_32();
+ if (swap) {
+ fat_offset = BSWAP32(fat_offset);
+ }
+ offsets.push_back(fat_offset);
+ p_f->seek(p_f->get_position() + 2 * 4);
+ }
+ }
+ } else {
+ offsets.push_back(0);
+ }
+ for (uint32_t i = 0; i < offsets.size(); i++) {
+ // MachO.
+ p_f->seek(offsets[i]);
+ magic = p_f->get_32();
+ if (magic != 0xcefaedfe && magic != 0xfeedface && magic != 0xcffaedfe && magic != 0xfeedfacf) {
+ continue;
+ }
+
+ // Read MachO header.
+ bool swap = (magic == 0xcffaedfe || magic == 0xcefaedfe);
+ bool is64 = (magic == 0xcffaedfe || magic == 0xfeedfacf);
+ p_f->seek(offsets[i] + 4 * 4);
+ uint32_t num_cmd = p_f->get_32();
+ if (swap) {
+ num_cmd = BSWAP32(num_cmd);
+ }
+ if (is64) { // Skip rest of header.
+ p_f->seek(offsets[i] + 8 * 4);
+ } else {
+ p_f->seek(offsets[i] + 7 * 4);
+ }
+
+ // Read load commands.
+ for (uint32_t j = 0; j < num_cmd; j++) {
+ uint64_t ps = p_f->get_position();
+ uint32_t cmd = p_f->get_32();
+ uint32_t cmdsize = p_f->get_32();
+ if (swap) {
+ cmd = BSWAP32(cmd);
+ cmdsize = BSWAP32(cmdsize);
+ }
+ if (cmd == 0x0000001b) {
+ // LC_UUID.
+ if (cmdsize == 24) {
+ // UUID.
+ uint32_t uuid_1 = BSWAP32(p_f->get_32());
+ uint16_t uuid_2 = BSWAP16(p_f->get_16());
+ uint16_t uuid_3 = BSWAP16(p_f->get_16());
+ uint16_t uuid_4 = BSWAP16(p_f->get_16());
+ PackedByteArray uuid_5 = p_f->get_buffer(6);
+ ids.push_back(vformat("%08x-%04x-%04x-%04x-%s", uuid_1, uuid_2, uuid_3, uuid_4, String::hex_encode_buffer(uuid_5.ptr(), uuid_5.size())));
+ } else {
+ // Unknown ID type, read as is.
+ PackedByteArray id = p_f->get_buffer(cmdsize - 8);
+ ids.push_back(String::hex_encode_buffer(id.ptr(), id.size()));
+ }
+ break;
+ }
+ p_f->seek(ps + cmdsize);
+ }
+ }
+
+ return ids;
+}
+
+Vector<String> OS::get_debug_build_id(const String &p_path) const {
+ Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
+ ERR_FAIL_COND_V(f.is_null(), Vector<String>());
+
+ uint32_t magic = f->get_32();
+ if (magic == 0x464c457f) {
+ return _read_elf_debug_id(f);
+ } else if ((magic & 0xffff) == 0x5a4d) {
+ return _read_pe_debug_id(f);
+ } else if (magic == 0xcefaedfe || magic == 0xfeedface || magic == 0xcffaedfe || magic == 0xfeedfacf || magic == 0xbebafeca || magic == 0xcafebabe || magic == 0xbfbafeca || magic == 0xcafebabf) {
+ return _read_macho_debug_id(f);
+ } else {
+ ERR_FAIL_V_MSG(Vector<String>(), "Unsupported executable format.");
+ }
+}
+
OS::OS() {
singleton = this;
diff --git a/core/os/os.h b/core/os/os.h
index 0a8342fae92..2f0ac97f344 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -116,6 +116,10 @@ private:
HashMap<Pair<String, String>, uint64_t> benchmark_marks_from;
HashMap<Pair<String, String>, double> benchmark_marks_final;
+ Vector<String> _read_elf_debug_id(const Ref<FileAccess> &p_f) const;
+ Vector<String> _read_pe_debug_id(const Ref<FileAccess> &p_f) const;
+ Vector<String> _read_macho_debug_id(const Ref<FileAccess> &p_f) const;
+
protected:
void _set_logger(CompositeLogger *p_logger);
@@ -247,6 +251,8 @@ public:
bool is_layered_allowed() const { return _allow_layered; }
bool is_hidpi_allowed() const { return _allow_hidpi; }
+ Vector<String> get_debug_build_id(const String &p_path) const;
+
void ensure_user_data_dir();
// NOTE: MainLoop is forward-declared in OS and should be included to use this.
diff --git a/editor/export/editor_export_platform_pc.cpp b/editor/export/editor_export_platform_pc.cpp
index fcdc059353b..399daf74e44 100644
--- a/editor/export/editor_export_platform_pc.cpp
+++ b/editor/export/editor_export_platform_pc.cpp
@@ -36,6 +36,7 @@
#include "core/io/zip_io.h"
#include "core/os/os.h"
#include "core/os/shared_object.h"
+#include "core/version.h"
#include "scene/resources/image_texture.h" // IWYU pragma: keep. Misdetection of `logo`.
void EditorExportPlatformPC::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
@@ -232,15 +233,27 @@ Error EditorExportPlatformPC::_unzip_debugsymbols(Ref<DirAccess> &p_da, const St
bool EditorExportPlatformPC::_copy_debugsymbols(Ref<DirAccess> &p_da, const String &p_path, const String &p_symbols_path, Error &r_err) {
r_err = OK;
- // TODO: Consider other zip files as needed for official templates.
+ String sym_path = p_symbols_path + ".debugsymbols";
+ String zip_path = p_symbols_path + ".debugsymbols.zip";
+ String zip_path_full = p_symbols_path.get_base_dir().simplify_path().path_join(vformat("Godot_v%s-%s_debugsymbols_%s", GODOT_VERSION_NUMBER, GODOT_VERSION_STATUS, p_symbols_path.get_file())) + ".zip";
- if (FileAccess::exists(p_symbols_path)) {
- r_err = p_da->copy(p_symbols_path, p_path + ".debugsymbols");
- } else if (FileAccess::exists(p_symbols_path + ".zip")) {
- r_err = _unzip_debugsymbols(p_da, p_path + ".debugsymbols", p_symbols_path.get_file(), p_symbols_path + ".zip");
+ if (FileAccess::exists(sym_path)) {
+ r_err = p_da->copy(sym_path, p_path + ".debugsymbols");
+ } else if (FileAccess::exists(zip_path)) {
+ r_err = _unzip_debugsymbols(p_da, p_path + ".debugsymbols", p_symbols_path.get_file() + ".debugsymbols", p_symbols_path + ".debugsymbols.zip");
+ } else if (FileAccess::exists(zip_path_full)) {
+ r_err = _unzip_debugsymbols(p_da, p_path + ".debugsymbols", p_symbols_path.get_file() + ".debugsymbols", zip_path_full);
} else {
return false;
}
+ Vector<String> exec_debug_ids = OS::get_singleton()->get_debug_build_id(p_path);
+ Vector<String> symb_debug_ids = OS::get_singleton()->get_debug_build_id(p_path + ".debugsymbols");
+ print_line("Executable debug IDs: ", exec_debug_ids);
+ print_line("Symbols debug IDs: ", symb_debug_ids);
+ if (exec_debug_ids != symb_debug_ids) {
+ add_message(EXPORT_MESSAGE_WARNING, TTR("Prepare Templates"), vformat(TTR("Executable and symbols debug ID mismatch: %s != %s."), exec_debug_ids, symb_debug_ids));
+ return false;
+ }
if (r_err == OK) {
r_err = fixup_debug_symbol_link(p_path, p_path.get_file() + ".debugsymbols");
}
@@ -299,7 +312,7 @@ Error EditorExportPlatformPC::prepare_template(const Ref<EditorExportPreset> &p_
}
if (err == OK && copy_debug_symbols) {
// We don't copy symbols for the wrapper as they are trivial.
- _copy_debugsymbols(da, p_path, template_path + ".debugsymbols", err);
+ _copy_debugsymbols(da, p_path, template_path, err);
}
if (err != OK) {
add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Template"), TTR("Failed to copy export template."));
diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp
index ecadaff50aa..51963abf738 100644
--- a/platform/macos/export/export_plugin.cpp
+++ b/platform/macos/export/export_plugin.cpp
@@ -40,6 +40,7 @@
#include "core/object/class_db.h"
#include "core/os/os.h"
#include "core/string/translation_server.h"
+#include "core/version.h"
#include "drivers/png/png_driver_common.h"
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
@@ -1803,7 +1804,7 @@ Error EditorExportPlatformMacOS::_export_debug_script(const Ref<EditorExportPres
return OK;
}
-Error EditorExportPlatformMacOS::_unzip_debugsymbols(Ref<DirAccess> &p_da, const String &p_path, const String &p_zip_path, const String &p_app_name, bool p_debug) {
+Error EditorExportPlatformMacOS::_unzip_debugsymbols(Ref<DirAccess> &p_da, const String &p_path, const String &p_zip_path, const String &p_app_name, const String &p_arch, bool p_debug, const Vector<String> &p_exec_ids, Vector<String> *r_symb_ids) {
Ref<FileAccess> io_fa;
zlib_filefunc_def io = zipio_create_io(&io_fa);
@@ -1813,7 +1814,9 @@ Error EditorExportPlatformMacOS::_unzip_debugsymbols(Ref<DirAccess> &p_da, const
return ERR_FILE_NOT_FOUND;
}
- String template_name = p_debug ? "template_debug" : "template_release";
+ print_verbose(vformat("Exporting debug symbols from %s, for architecture %s.", p_zip_path, p_arch));
+
+ String template_name = p_debug ? "debug" : "release";
int ret = unzGoToFirstFile(src_pkg_zip);
while (ret == UNZ_OK) {
// Get filename.
@@ -1824,10 +1827,9 @@ Error EditorExportPlatformMacOS::_unzip_debugsymbols(Ref<DirAccess> &p_da, const
break;
}
String file = String::utf8(fname);
- file = file.trim_prefix("out/macos/templates/");
- if (file.begins_with(vformat("godot.macos.%s.universal.dSYM/", template_name))) {
- file = file.trim_prefix(vformat("godot.macos.%s.universal.dSYM/", template_name));
- file = file.replace(vformat("godot.macos.%s.universal", template_name), p_app_name);
+ if (file.begins_with(vformat("godot_macos_%s.%s.dSYM/", template_name, p_arch))) {
+ file = file.trim_prefix(vformat("godot_macos_%s.%s.dSYM/", template_name, p_arch));
+ file = file.replace(vformat("godot_macos_%s.%s", template_name, p_arch), p_app_name);
Vector<uint8_t> data;
data.resize(info.uncompressed_size);
@@ -1860,14 +1862,38 @@ Error EditorExportPlatformMacOS::_unzip_debugsymbols(Ref<DirAccess> &p_da, const
ret = unzGoToNextFile(src_pkg_zip);
}
-
// We're done with our source zip.
unzClose(src_pkg_zip);
+ Vector<String> symb_debug_ids = OS::get_singleton()->get_debug_build_id(p_path.path_join("Contents").path_join("Resources").path_join("DWARF").path_join(p_app_name));
+ if (!symb_debug_ids.is_empty()) {
+ int id_match = 0;
+ for (const String &E : symb_debug_ids) {
+ if (p_exec_ids.has(E)) {
+ r_symb_ids->push_back(E);
+ id_match++;
+ }
+ }
+ if (id_match == 0) {
+ print_verbose(vformat("No matching symbols found in %s (%s found, %s expected).", p_zip_path, symb_debug_ids, p_exec_ids));
+ if (DirAccess::exists(p_path)) {
+ Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(p_path);
+ if (tmp_app_dir.is_null()) {
+ add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory: \"%s\"."), p_path));
+ }
+ if (tmp_app_dir->change_dir(p_path) == OK) {
+ tmp_app_dir->erase_contents_recursive();
+ tmp_app_dir->change_dir("..");
+ tmp_app_dir->remove(p_path.get_file());
+ }
+ }
+ }
+ }
+
return OK;
}
-Error EditorExportPlatformMacOS::_copy_debugsymbols_recursively(Ref<DirAccess> &p_da, const String &p_path, const String &p_src_path, const String &p_app_name, bool p_debug) {
+Error EditorExportPlatformMacOS::_copy_debugsymbols_recursively(Ref<DirAccess> &p_da, const String &p_path, const String &p_src_path, const String &p_app_name, const String &p_arch, bool p_debug) {
List<String> dirs;
Ref<DirAccess> src_da = DirAccess::create_for_path(p_src_path);
@@ -1885,7 +1911,7 @@ Error EditorExportPlatformMacOS::_copy_debugsymbols_recursively(Ref<DirAccess> &
return err;
}
- String template_name = p_debug ? "template_debug" : "template_release";
+ String template_name = p_debug ? "debug" : "release";
src_da->list_dir_begin();
String n = src_da->get_next();
while (!n.is_empty()) {
@@ -1893,7 +1919,7 @@ Error EditorExportPlatformMacOS::_copy_debugsymbols_recursively(Ref<DirAccess> &
if (src_da->current_is_dir()) {
dirs.push_back(n);
} else {
- const String &rel_path = n.replace(vformat("godot.macos.%s.universal", template_name), p_app_name);
+ const String &rel_path = n.replace(vformat("godot_macos_%s.%s", template_name, p_arch), p_app_name);
if (!n.is_relative_path()) {
src_da->list_dir_end();
if (err != OK) {
@@ -1920,7 +1946,7 @@ Error EditorExportPlatformMacOS::_copy_debugsymbols_recursively(Ref<DirAccess> &
src_da->list_dir_end();
for (const String &rel_path : dirs) {
- err = _copy_debugsymbols_recursively(p_da, p_path.path_join(rel_path), p_src_path.path_join(rel_path), p_app_name, p_debug);
+ err = _copy_debugsymbols_recursively(p_da, p_path.path_join(rel_path), p_src_path.path_join(rel_path), p_app_name, p_arch, p_debug);
if (err != OK) {
return err;
}
@@ -1929,11 +1955,34 @@ Error EditorExportPlatformMacOS::_copy_debugsymbols_recursively(Ref<DirAccess> &
return OK;
}
-bool EditorExportPlatformMacOS::_copy_debugsymbols(Ref<DirAccess> &p_da, const String &p_path, const String &p_symbols_path, const String &p_app_name, bool p_debug, Error &r_err) {
- if (DirAccess::exists(p_symbols_path.get_basename() + ".dSYM")) {
- r_err = _copy_debugsymbols_recursively(p_da, p_path.simplify_path(), p_symbols_path.simplify_path().get_basename() + ".dSYM", p_app_name, p_debug);
- } else if (FileAccess::exists(p_symbols_path.get_basename() + ".dSYM.zip")) {
- r_err = _unzip_debugsymbols(p_da, p_path.simplify_path(), p_symbols_path.simplify_path().get_basename() + ".dSYM.zip", p_app_name, p_debug);
+bool EditorExportPlatformMacOS::_copy_debugsymbols(Ref<DirAccess> &p_da, const String &p_path, const String &p_symbols_path, const String &p_app_name, const String &p_arch, bool p_debug, const Vector<String> &p_exec_ids, Vector<String> *r_symb_ids, Error &r_err) {
+ String sym_path = p_symbols_path.simplify_path().path_join(vformat("godot_macos_%s.%s", p_debug ? "debug" : "release", p_arch)) + ".dSYM";
+ String zip_path = p_symbols_path.simplify_path().path_join(vformat("macos_%s.%s", p_debug ? "debug" : "release", p_arch)) + ".debugsymbols.zip";
+ String zip_path_full = p_symbols_path.simplify_path().path_join(vformat("Godot_v%s-%s_debugsymbols_macos_%s.%s", GODOT_VERSION_NUMBER, GODOT_VERSION_STATUS, p_debug ? "debug" : "release", p_arch)) + ".zip";
+
+ if (DirAccess::exists(sym_path)) {
+ print_verbose(vformat("Exporting debug symbols from %s, for architecture %s.", sym_path, p_arch));
+ Vector<String> symb_debug_ids = OS::get_singleton()->get_debug_build_id(sym_path.path_join("Contents").path_join("Resources").path_join("DWARF").path_join(vformat("godot_macos_%s.%s", p_debug ? "debug" : "release", p_arch)));
+ if (!symb_debug_ids.is_empty()) {
+ int id_match = 0;
+ for (const String &E : symb_debug_ids) {
+ if (p_exec_ids.has(E)) {
+ r_symb_ids->push_back(E);
+ id_match++;
+ }
+ }
+ if (id_match > 0) {
+ r_err = _copy_debugsymbols_recursively(p_da, p_path.simplify_path(), sym_path, p_app_name, p_arch, p_debug);
+ } else {
+ print_verbose(vformat("No matching symbols found in %s (%s found, %s expected).", sym_path, symb_debug_ids, p_exec_ids));
+ r_err = ERR_FILE_NOT_FOUND;
+ return false;
+ }
+ }
+ } else if (FileAccess::exists(zip_path)) {
+ r_err = _unzip_debugsymbols(p_da, p_path.simplify_path(), zip_path, p_app_name, p_arch, p_debug, p_exec_ids, r_symb_ids);
+ } else if (FileAccess::exists(zip_path_full)) {
+ r_err = _unzip_debugsymbols(p_da, p_path.simplify_path(), zip_path_full, p_app_name, p_arch, p_debug, p_exec_ids, r_symb_ids);
} else {
return false;
}
@@ -2017,17 +2066,14 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
String tmp_base_path_name;
String tmp_app_path_name;
String scr_path;
- String dbg_name;
if (export_format == "app") {
tmp_base_path_name = p_path.get_base_dir();
tmp_app_path_name = p_path;
scr_path = p_path.get_basename() + ".command";
- dbg_name = p_path.get_file().get_basename();
} else {
tmp_base_path_name = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);
tmp_app_path_name = tmp_base_path_name.path_join(tmp_app_dir_name);
scr_path = tmp_base_path_name.path_join(pkg_name + ".command");
- dbg_name = pkg_name;
}
print_verbose("Exporting to " + tmp_app_path_name);
@@ -2054,11 +2100,6 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
int debug_symbols_mode = p_preset->get("debug/export_debug_symbols");
bool copy_debug_symbols = (debug_symbols_mode == 1 && p_debug) || (debug_symbols_mode == 2);
- if (copy_debug_symbols) {
- print_verbose("Exporting debug symbols to " + tmp_app_path_name + ".dSYM");
- _copy_debugsymbols(tmp_app_dir, tmp_app_path_name + ".dSYM", src_pkg_name, dbg_name, p_debug, err);
- }
-
Array helpers = p_preset->get("codesign/entitlements/app_sandbox/helper_executables");
// Create our folder structure.
@@ -2079,7 +2120,7 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
}
if ((err == OK) && helpers.size() > 0) {
- print_line("Creating " + tmp_app_path_name + "/Contents/Helpers");
+ print_verbose("Creating " + tmp_app_path_name + "/Contents/Helpers");
err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Helpers");
if (err != OK) {
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Helpers"));
@@ -2452,6 +2493,36 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
err = ERR_FILE_NOT_FOUND;
}
+ // Copy debug symbols.
+ if (copy_debug_symbols) {
+ print_verbose("Exporting debug symbols to " + tmp_app_path_name + ".dSYM");
+ Vector<String> exec_debug_ids = OS::get_singleton()->get_debug_build_id(tmp_app_path_name.path_join("Contents").path_join("MacOS").path_join(pkg_name));
+ Vector<String> symb_debug_ids;
+ if (architecture == "universal") {
+ bool found = _copy_debugsymbols(tmp_app_dir, tmp_app_path_name + ".dSYM", src_pkg_name.get_base_dir(), pkg_name, "universal", p_debug, exec_debug_ids, &symb_debug_ids, err);
+ if (!found) {
+ _copy_debugsymbols(tmp_app_dir, tmp_app_path_name + ".arm64.dSYM", src_pkg_name.get_base_dir(), pkg_name, "arm64", p_debug, exec_debug_ids, &symb_debug_ids, err);
+ _copy_debugsymbols(tmp_app_dir, tmp_app_path_name + ".x86_64.dSYM", src_pkg_name.get_base_dir(), pkg_name, "x86_64", p_debug, exec_debug_ids, &symb_debug_ids, err);
+ }
+ } else {
+ bool found = _copy_debugsymbols(tmp_app_dir, tmp_app_path_name + ".dSYM", src_pkg_name.get_base_dir(), pkg_name, architecture, p_debug, exec_debug_ids, &symb_debug_ids, err);
+ if (!found) {
+ _copy_debugsymbols(tmp_app_dir, tmp_app_path_name + ".dSYM", src_pkg_name.get_base_dir(), pkg_name, "universal", p_debug, exec_debug_ids, &symb_debug_ids, err);
+ }
+ }
+ print_line("Executable debug IDs: ", exec_debug_ids);
+ print_line("Symbols debug IDs: ", symb_debug_ids);
+ int id_match = 0;
+ for (const String &E : exec_debug_ids) {
+ if (symb_debug_ids.has(E)) {
+ id_match++;
+ }
+ }
+ if (id_match != exec_debug_ids.size()) { // Note: When exporting single architecture binary with universal symbols, `symb_debug_ids` can include extra IDs.
+ add_message(EXPORT_MESSAGE_WARNING, TTR("Prepare Templates"), vformat(TTR("Executable and symbols debug ID mismatch: %s != %s."), exec_debug_ids, symb_debug_ids));
+ }
+ }
+
// Save console wrapper.
if (err == OK) {
int con_scr = p_preset->get("debug/export_console_wrapper");
diff --git a/platform/macos/export/export_plugin.h b/platform/macos/export/export_plugin.h
index 9ccc2bada51..c6619c029c4 100644
--- a/platform/macos/export/export_plugin.h
+++ b/platform/macos/export/export_plugin.h
@@ -84,9 +84,9 @@ class EditorExportPlatformMacOS : public EditorExportPlatform {
void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary, bool p_lg_icon_exported, const String &p_lg_icon);
void _make_icon(const Ref<EditorExportPreset> &p_preset, const Ref<Image> &p_icon, Vector<uint8_t> &p_data);
- Error _unzip_debugsymbols(Ref<DirAccess> &p_da, const String &p_path, const String &p_zip_path, const String &p_app_name, bool p_debug);
- Error _copy_debugsymbols_recursively(Ref<DirAccess> &p_da, const String &p_path, const String &p_src_path, const String &p_app_name, bool p_debug);
- bool _copy_debugsymbols(Ref<DirAccess> &p_da, const String &p_path, const String &p_symbols_path, const String &p_app_name, bool p_debug, Error &r_err);
+ Error _unzip_debugsymbols(Ref<DirAccess> &p_da, const String &p_path, const String &p_zip_path, const String &p_app_name, const String &p_arch, bool p_debug, const Vector<String> &p_exec_ids, Vector<String> *r_symb_ids);
+ Error _copy_debugsymbols_recursively(Ref<DirAccess> &p_da, const String &p_path, const String &p_src_path, const String &p_app_name, const String &p_arch, bool p_debug);
+ bool _copy_debugsymbols(Ref<DirAccess> &p_da, const String &p_path, const String &p_symbols_path, const String &p_app_name, const String &p_arch, bool p_debug, const Vector<String> &p_exec_ids, Vector<String> *r_symb_ids, Error &r_err);
Error _export_liquid_glass_icon(const Ref<EditorExportPreset> &p_preset, const String &p_app_path, const String &p_icon_path);
Error _notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path);