From 86ea554601d4938e9a6707c8b277f81fa469ba3d Mon Sep 17 00:00:00 2001 From: Leonard Grey Date: Tue, 26 Jul 2022 14:23:54 -0400 Subject: [PATCH] Mac dump_syms: Fix -a on arm64 - Resets `selected_object_file_` when a new file is read. This was a dangling pointer previously. - When `-a` is provided, ensures that both parts of a split module use the given architecture. Bug: None Change-Id: I581d41b0eee4ec2b0d598fb80b9065e7ebde0e0d Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3788222 Reviewed-by: Mark Mentovai --- src/common/mac/dump_syms.cc | 1 + src/tools/mac/dump_syms/dump_syms_tool.cc | 61 +++++++++++++---------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/common/mac/dump_syms.cc b/src/common/mac/dump_syms.cc index c62caed2..ed5e65f9 100644 --- a/src/common/mac/dump_syms.cc +++ b/src/common/mac/dump_syms.cc @@ -121,6 +121,7 @@ vector list_directory(const string& directory) { namespace google_breakpad { bool DumpSymbols::Read(const string& filename) { + selected_object_file_ = nullptr; struct stat st; if (stat(filename.c_str(), &st) == -1) { fprintf(stderr, "Could not access object file %s: %s\n", diff --git a/src/tools/mac/dump_syms/dump_syms_tool.cc b/src/tools/mac/dump_syms/dump_syms_tool.cc index 9ff5140b..0f43d163 100644 --- a/src/tools/mac/dump_syms/dump_syms_tool.cc +++ b/src/tools/mac/dump_syms/dump_syms_tool.cc @@ -107,6 +107,35 @@ static void CopyCFIDataBetweenModules(Module* to_module, } } +static bool SetArchitecture(DumpSymbols& dump_symbols, + const NXArchInfo* arch, + const std::string& filename) { + if (!dump_symbols.SetArchitecture(arch->cputype, arch->cpusubtype)) { + fprintf(stderr, "%s: no architecture '%s' is present in file.\n", + filename.c_str(), arch->name); + size_t available_size; + const SuperFatArch* available = + dump_symbols.AvailableArchitectures(&available_size); + if (available_size == 1) + fprintf(stderr, "the file's architecture is: "); + else + fprintf(stderr, "architectures present in the file are:\n"); + for (size_t i = 0; i < available_size; i++) { + const SuperFatArch* arch = &available[i]; + const NXArchInfo* arch_info = + google_breakpad::BreakpadGetArchInfoFromCpuType(arch->cputype, + arch->cpusubtype); + if (arch_info) + fprintf(stderr, "%s (%s)\n", arch_info->name, arch_info->description); + else + fprintf(stderr, "unrecognized cpu type 0x%x, subtype 0x%x\n", + arch->cputype, arch->cpusubtype); + } + return false; + } + return true; +} + static bool Start(const Options& options) { SymbolData symbol_data = (options.handle_inlines ? INLINES : NO_DATA) | @@ -129,31 +158,9 @@ static bool Start(const Options& options) { if (!dump_symbols.Read(primary_file)) return false; - if (options.arch) { - if (!dump_symbols.SetArchitecture(options.arch->cputype, - options.arch->cpusubtype)) { - fprintf(stderr, "%s: no architecture '%s' is present in file.\n", - primary_file.c_str(), options.arch->name); - size_t available_size; - const SuperFatArch *available = - dump_symbols.AvailableArchitectures(&available_size); - if (available_size == 1) - fprintf(stderr, "the file's architecture is: "); - else - fprintf(stderr, "architectures present in the file are:\n"); - for (size_t i = 0; i < available_size; i++) { - const SuperFatArch *arch = &available[i]; - const NXArchInfo *arch_info = - google_breakpad::BreakpadGetArchInfoFromCpuType( - arch->cputype, arch->cpusubtype); - if (arch_info) - fprintf(stderr, "%s (%s)\n", arch_info->name, arch_info->description); - else - fprintf(stderr, "unrecognized cpu type 0x%x, subtype 0x%x\n", - arch->cputype, arch->cpusubtype); - } - return false; - } + if (options.arch && + !SetArchitecture(dump_symbols, options.arch, primary_file)) { + return false; } if (options.header_only) @@ -171,6 +178,10 @@ static bool Start(const Options& options) { if (!dump_symbols.Read(options.srcPath)) return false; + if (options.arch && + !SetArchitecture(dump_symbols, options.arch, options.srcPath)) { + return false; + } Module* cfi_module = NULL; if (!dump_symbols.ReadSymbolData(&cfi_module)) return false;