1 /*
2 * Copyright 2011, The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #ifndef ELF_SECTION_STR_TAB_HXX
18 #define ELF_SECTION_STR_TAB_HXX
19
20 #include "utils/helper.h"
21 #include "utils/raw_ostream.h"
22
23 #include <llvm/ADT/OwningPtr.h>
24 #include <llvm/Support/Format.h>
25 #include <llvm/Support/raw_ostream.h>
26
27 template <unsigned Bitwidth>
28 template <typename Archiver>
29 ELFSectionStrTab<Bitwidth> *
read(Archiver & AR,ELFSectionHeaderTy const * sh)30 ELFSectionStrTab<Bitwidth>::read(Archiver &AR,
31 ELFSectionHeaderTy const *sh) {
32
33 llvm::OwningPtr<ELFSectionStrTab> st(new ELFSectionStrTab());
34 st->buf.resize(sh->getSize());
35
36 // Save section_header
37 st->section_header = sh;
38
39 AR.seek(sh->getOffset(), true);
40 AR.prologue(sh->getSize());
41 AR.readBytes(&*st->buf.begin(), sh->getSize());
42 AR.epilogue(sh->getSize());
43
44 if (!AR) {
45 // Unable to read the string table.
46 return 0;
47 }
48
49 return st.take();
50 }
51
52 template <unsigned Bitwidth>
print() const53 void ELFSectionStrTab<Bitwidth>::print() const {
54 using namespace llvm;
55
56 out() << '\n' << fillformat('=', 79) << '\n';
57 out().changeColor(raw_ostream::WHITE, true);
58 out() << "ELF String Table: " << this->section_header->getName() << '\n';
59 out().resetColor();
60 out() << fillformat('-', 79) << '\n';
61
62 dump_hex((unsigned char const *)&*buf.begin(), buf.size(), 0, buf.size());
63
64 out() << fillformat('=', 79) << '\n';
65 }
66
67 #endif // ELF_SECTION_STR_TAB_HXX
68