line_info.h
Go to the documentation of this file.
1 // Copyright 2016 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BLOATY_DWARF_LINE_INFO_H_
16 #define BLOATY_DWARF_LINE_INFO_H_
17 
18 #include <cstdint>
19 
20 #include "absl/strings/string_view.h"
21 #include "dwarf/debug_info.h"
22 
23 // Code to read the .line_info programs in a DWARF file. Currently we use this
24 // for the "inlines" data source, but I think we should probably use the
25 // inlining info in debug_info instead.
26 //
27 // Usage overview:
28 // dwarf::LineInfoReader reader(file);
29 //
30 // reader.SeekToOffset(ofs, cu.unit_sizes().address_size());
31 // while (reader->ReadLineInfo()) {
32 // const dwarf::LineInfo& info = reader->lineinfo();
33 // // ...
34 // }
35 
36 namespace bloaty {
37 namespace dwarf {
38 
40  public:
41  LineInfoReader(const File& file) : file_(file), info_(0) {}
42 
43  struct LineInfo {
44  LineInfo(bool default_is_stmt) : is_stmt(default_is_stmt) {}
50  bool end_sequence = false;
51  bool basic_block = false;
52  bool prologue_end = false;
53  bool epilogue_begin = false;
54  bool is_stmt;
56  uint8_t isa = 0;
57  };
58 
59  struct FileName {
64  };
65 
66  void SeekToOffset(uint64_t offset, uint8_t address_size);
67  bool ReadLineInfo();
68  const LineInfo& lineinfo() const { return info_; }
69  const FileName& filename(size_t i) const { return filenames_[i]; }
71  return include_directories_[i];
72  }
73 
74  const std::string& GetExpandedFilename(size_t index);
75 
76  private:
77  struct Params {
84  } params_;
85 
86  const File& file_;
87 
89  std::vector<absl::string_view> include_directories_;
90  std::vector<FileName> filenames_;
91  std::vector<uint8_t> standard_opcode_lengths_;
92  std::vector<std::string> expanded_filenames_;
93 
95 
96  // Whether we are in a "shadow" part of the bytecode program. Sometimes
97  // parts of the line info program make it into the final binary even though
98  // the corresponding code was stripped. We can tell when this happened by
99  // looking for DW_LNE_set_address ops where the operand is 0. This
100  // indicates that a relocation for that argument never got applied, which
101  // probably means that the code got stripped.
102  //
103  // While this is true, we don't yield any LineInfo entries, because the
104  // "address" value is garbage.
105  bool shadow_;
106 
108 
109  void DoAdvance(uint64_t advance, uint8_t max_per_instr);
110  void Advance(uint64_t amount);
113 };
114 
115 } // namespace dwarf
116 } // namespace bloaty
117 
118 #endif // BLOATY_DWARF_LINE_INFO_H_
bloaty::dwarf::LineInfoReader::Params::minimum_instruction_length
uint8_t minimum_instruction_length
Definition: line_info.h:78
bloaty::dwarf::LineInfoReader::params_
struct bloaty::dwarf::LineInfoReader::Params params_
bloaty::dwarf::LineInfoReader::expanded_filenames_
std::vector< std::string > expanded_filenames_
Definition: line_info.h:92
bloaty
Definition: bloaty.cc:69
bloaty::dwarf::LineInfoReader::Params::default_is_stmt
uint8_t default_is_stmt
Definition: line_info.h:80
bloaty::dwarf::LineInfoReader::AdjustedOpcode
uint8_t AdjustedOpcode(uint8_t op)
Definition: line_info.cc:72
bloaty::dwarf::LineInfoReader::ReadLineInfo
bool ReadLineInfo()
Definition: line_info.cc:150
bloaty::dwarf::LineInfoReader::FileName::directory_index
uint32_t directory_index
Definition: line_info.h:61
bloaty::dwarf::LineInfoReader::Params::line_base
int8_t line_base
Definition: line_info.h:81
bloaty::dwarf::LineInfoReader::LineInfo::isa
uint8_t isa
Definition: line_info.h:56
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
bloaty::dwarf::LineInfoReader::LineInfo::line
uint32_t line
Definition: line_info.h:47
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
bloaty::dwarf::LineInfoReader
Definition: line_info.h:39
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
bloaty::dwarf::LineInfoReader::FileName
Definition: line_info.h:59
bloaty::dwarf::LineInfoReader::sizes_
CompilationUnitSizes sizes_
Definition: line_info.h:88
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
bloaty::dwarf::LineInfoReader::DoAdvance
void DoAdvance(uint64_t advance, uint8_t max_per_instr)
Definition: line_info.cc:62
bloaty::dwarf::LineInfoReader::Advance
void Advance(uint64_t amount)
Definition: line_info.cc:52
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
bloaty::dwarf::LineInfoReader::lineinfo
const LineInfo & lineinfo() const
Definition: line_info.h:68
bloaty::dwarf::LineInfoReader::GetExpandedFilename
const std::string & GetExpandedFilename(size_t index)
Definition: line_info.cc:29
bloaty::dwarf::LineInfoReader::LineInfo::discriminator
uint32_t discriminator
Definition: line_info.h:49
bloaty::dwarf::LineInfoReader::include_directory
absl::string_view include_directory(size_t i) const
Definition: line_info.h:70
bloaty::dwarf::LineInfoReader::standard_opcode_lengths_
std::vector< uint8_t > standard_opcode_lengths_
Definition: line_info.h:91
bloaty::dwarf::LineInfoReader::Params
Definition: line_info.h:77
advance
static void advance(upb_pbdecoder *d, size_t len)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:6553
bloaty::dwarf::LineInfoReader::LineInfo::column
uint32_t column
Definition: line_info.h:48
bloaty::dwarf::LineInfoReader::LineInfo::basic_block
bool basic_block
Definition: line_info.h:51
bloaty::dwarf::LineInfoReader::FileName::file_size
uint64_t file_size
Definition: line_info.h:63
bloaty::dwarf::LineInfoReader::filenames_
std::vector< FileName > filenames_
Definition: line_info.h:90
bloaty::dwarf::LineInfoReader::LineInfo::prologue_end
bool prologue_end
Definition: line_info.h:52
bloaty::dwarf::CompilationUnitSizes
Definition: debug_info.h:88
bloaty::dwarf::LineInfoReader::FileName::modified_time
uint64_t modified_time
Definition: line_info.h:62
bloaty::dwarf::LineInfoReader::SpecialOpcodeAdvance
void SpecialOpcodeAdvance(uint8_t op)
Definition: line_info.cc:68
bloaty::dwarf::LineInfoReader::filename
const FileName & filename(size_t i) const
Definition: line_info.h:69
bloaty::dwarf::LineInfoReader::SeekToOffset
void SeekToOffset(uint64_t offset, uint8_t address_size)
Definition: line_info.cc:76
bloaty::dwarf::LineInfoReader::Params::maximum_operations_per_instruction
uint8_t maximum_operations_per_instruction
Definition: line_info.h:79
bloaty::dwarf::LineInfoReader::LineInfo::end_sequence
bool end_sequence
Definition: line_info.h:50
bloaty::dwarf::LineInfoReader::LineInfo::epilogue_begin
bool epilogue_begin
Definition: line_info.h:53
bloaty::dwarf::LineInfoReader::include_directories_
std::vector< absl::string_view > include_directories_
Definition: line_info.h:89
bloaty::dwarf::LineInfoReader::Params::opcode_base
uint8_t opcode_base
Definition: line_info.h:83
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
bloaty::dwarf::LineInfoReader::shadow_
bool shadow_
Definition: line_info.h:105
debug_info.h
bloaty::dwarf::LineInfoReader::file_
const File & file_
Definition: line_info.h:86
bloaty::dwarf::LineInfoReader::LineInfoReader
LineInfoReader(const File &file)
Definition: line_info.h:41
bloaty::dwarf::LineInfoReader::remaining_
absl::string_view remaining_
Definition: line_info.h:94
bloaty::dwarf::LineInfoReader::Params::line_range
uint8_t line_range
Definition: line_info.h:82
bloaty::dwarf::LineInfoReader::LineInfo::op_index
uint8_t op_index
Definition: line_info.h:55
bloaty::dwarf::LineInfoReader::LineInfo
Definition: line_info.h:43
bloaty::dwarf::LineInfoReader::LineInfo::LineInfo
LineInfo(bool default_is_stmt)
Definition: line_info.h:44
bloaty::dwarf::LineInfoReader::info_
LineInfo info_
Definition: line_info.h:107
int8_t
signed char int8_t
Definition: stdint-msvc2008.h:75
bloaty::dwarf::LineInfoReader::LineInfo::is_stmt
bool is_stmt
Definition: line_info.h:54
bloaty::dwarf::LineInfoReader::FileName::name
absl::string_view name
Definition: line_info.h:60
op
static grpc_op * op
Definition: test/core/fling/client.cc:47
bloaty::dwarf::File
Definition: debug_info.h:64
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
offset
voidpf uLong offset
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:142
bloaty::dwarf::LineInfoReader::LineInfo::address
uint64_t address
Definition: line_info.h:45


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:28