2 * Copyright 2013 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #ifndef FOLLY_EXPERIMENTAL_SYMBOLIZER_ELF_H_
19 # error This file must be included from Elf.h
23 namespace symbolizer {
26 const ElfW(Shdr)* ElfFile::iterateSections(Fn fn) const {
27 const ElfW(Shdr)* ptr = &at<ElfW(Shdr)>(elfHeader().e_shoff);
28 for (size_t i = 0; i < elfHeader().e_shnum; i++, ptr++) {
38 const ElfW(Shdr)* ElfFile::iterateSectionsWithType(uint32_t type, Fn fn)
40 return iterateSections(
41 [&](const ElfW(Shdr)& sh) {
42 return sh.sh_type == type && fn(sh);
47 const char* ElfFile::iterateStrings(const ElfW(Shdr)& stringTable, Fn fn)
49 validateStringTable(stringTable);
51 const char* start = file_ + stringTable.sh_offset;
52 const char* end = start + stringTable.sh_size;
54 const char* ptr = start;
55 while (ptr != end && !fn(ptr)) {
56 ptr += strlen(ptr) + 1;
59 return ptr != end ? ptr : nullptr;
63 } // namespace symbolizer