mirror of
https://github.com/yuzu-emu/breakpad.git
synced 2025-01-03 21:05:30 +00:00
Cleanup strncmp and use string_view in elf_reader.cc.
Change-Id: I74c755f1ade80bb4313e4fd14e5dc6bab419a0a6 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/4099505 Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
parent
6b7e8a80ba
commit
63af0cd752
|
@ -39,9 +39,9 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
// TODO(saugustine): Add support for compressed debug.
|
// TODO(saugustine): Add support for compressed debug.
|
||||||
// Also need to add configure tests for zlib.
|
// Also need to add configure tests for zlib.
|
||||||
|
@ -107,6 +107,12 @@ const int kAARCH64PLT0Size = 0x20;
|
||||||
// Suffix for PLT functions when it needs to be explicitly identified as such.
|
// Suffix for PLT functions when it needs to be explicitly identified as such.
|
||||||
const char kPLTFunctionSuffix[] = "@plt";
|
const char kPLTFunctionSuffix[] = "@plt";
|
||||||
|
|
||||||
|
// Replace callsites of this function to std::string_view::starts_with after
|
||||||
|
// adopting C++20.
|
||||||
|
bool StringViewStartsWith(std::string_view sv, std::string_view prefix) {
|
||||||
|
return sv.compare(0, prefix.size(), prefix) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace google_breakpad {
|
namespace google_breakpad {
|
||||||
|
@ -215,7 +221,7 @@ class ElfSectionReader {
|
||||||
(header_.sh_offset - offset_aligned);
|
(header_.sh_offset - offset_aligned);
|
||||||
|
|
||||||
// Check for and handle any compressed contents.
|
// Check for and handle any compressed contents.
|
||||||
//if (name == ".zdebug_")
|
//if (StringViewStartsWith(name, ".zdebug_"))
|
||||||
// DecompressZlibContents();
|
// DecompressZlibContents();
|
||||||
// TODO(saugustine): Add support for proposed elf-section flag
|
// TODO(saugustine): Add support for proposed elf-section flag
|
||||||
// "SHF_COMPRESS".
|
// "SHF_COMPRESS".
|
||||||
|
@ -359,8 +365,8 @@ class ElfReaderImpl {
|
||||||
// "opd_section_" must always be checked for NULL before use.
|
// "opd_section_" must always be checked for NULL before use.
|
||||||
opd_section_ = GetSectionInfoByName(".opd", &opd_info_);
|
opd_section_ = GetSectionInfoByName(".opd", &opd_info_);
|
||||||
for (unsigned int k = 0u; k < GetNumSections(); ++k) {
|
for (unsigned int k = 0u; k < GetNumSections(); ++k) {
|
||||||
const char* name = GetSectionName(section_headers_[k].sh_name);
|
std::string_view name{GetSectionName(section_headers_[k].sh_name)};
|
||||||
if (strncmp(name, ".text", strlen(".text")) == 0) {
|
if (StringViewStartsWith(name, ".text")) {
|
||||||
base_for_text_ =
|
base_for_text_ =
|
||||||
section_headers_[k].sh_addr - section_headers_[k].sh_offset;
|
section_headers_[k].sh_addr - section_headers_[k].sh_offset;
|
||||||
break;
|
break;
|
||||||
|
@ -809,9 +815,11 @@ class ElfReaderImpl {
|
||||||
// Debug sections are likely to be near the end, so reverse the
|
// Debug sections are likely to be near the end, so reverse the
|
||||||
// direction of iteration.
|
// direction of iteration.
|
||||||
for (int k = GetNumSections() - 1; k >= 0; --k) {
|
for (int k = GetNumSections() - 1; k >= 0; --k) {
|
||||||
const char* name = GetSectionName(section_headers_[k].sh_name);
|
std::string_view name{GetSectionName(section_headers_[k].sh_name)};
|
||||||
if (strncmp(name, ".debug", strlen(".debug")) == 0) return true;
|
if (StringViewStartsWith(name, ".debug") ||
|
||||||
if (strncmp(name, ".zdebug", strlen(".zdebug")) == 0) return true;
|
StringViewStartsWith(name, ".zdebug")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1213,11 +1221,15 @@ const char* ElfReader::GetSectionInfoByName(const string& section_name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ElfReader::SectionNamesMatch(const string& name, const string& sh_name) {
|
bool ElfReader::SectionNamesMatch(std::string_view name,
|
||||||
if ((name.find(".debug_", 0) == 0) && (sh_name.find(".zdebug_", 0) == 0)) {
|
std::string_view sh_name) {
|
||||||
const string name_suffix(name, strlen(".debug_"));
|
std::string_view debug_prefix{".debug_"};
|
||||||
const string sh_name_suffix(sh_name, strlen(".zdebug_"));
|
std::string_view zdebug_prefix{".zdebug_"};
|
||||||
return name_suffix == sh_name_suffix;
|
if (StringViewStartsWith(name, debug_prefix) &&
|
||||||
|
StringViewStartsWith(sh_name, zdebug_prefix)) {
|
||||||
|
name.remove_prefix(debug_prefix.length());
|
||||||
|
sh_name.remove_prefix(zdebug_prefix.length());
|
||||||
|
return name == sh_name;
|
||||||
}
|
}
|
||||||
return name == sh_name;
|
return name == sh_name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#define COMMON_DWARF_ELF_READER_H__
|
#define COMMON_DWARF_ELF_READER_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "common/dwarf/types.h"
|
#include "common/dwarf/types.h"
|
||||||
|
@ -145,7 +146,8 @@ class ElfReader {
|
||||||
// appears in the elf-file, adjusting for compressed debug section
|
// appears in the elf-file, adjusting for compressed debug section
|
||||||
// names. For example, returns true if name == ".debug_abbrev" and
|
// names. For example, returns true if name == ".debug_abbrev" and
|
||||||
// sh_name == ".zdebug_abbrev"
|
// sh_name == ".zdebug_abbrev"
|
||||||
static bool SectionNamesMatch(const string& name, const string& sh_name);
|
static bool SectionNamesMatch(std::string_view name,
|
||||||
|
std::string_view sh_name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Lazily initialize impl32_ and return it.
|
// Lazily initialize impl32_ and return it.
|
||||||
|
|
Loading…
Reference in a new issue