blob: 90db7eb41a2e9d6387728feeb11e243314a1ec40 [file] [log] [blame]
David Srbecky3b9d57a2015-04-10 00:22:14 +01001/*
2 * Copyright (C) 2015 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#include "elf_writer_debug.h"
18
David Srbecky626a1662015-04-12 13:12:26 +010019#include <unordered_set>
20
Andreas Gampee3d623e2015-05-01 16:11:04 -070021#include "base/casts.h"
David Srbecky3b9d57a2015-04-10 00:22:14 +010022#include "compiled_method.h"
23#include "driver/compiler_driver.h"
24#include "dex_file-inl.h"
25#include "dwarf/headers.h"
26#include "dwarf/register.h"
David Srbecky6d8c8f02015-10-26 10:57:09 +000027#include "elf_builder.h"
David Srbecky3b9d57a2015-04-10 00:22:14 +010028#include "oat_writer.h"
Vladimir Marko80afd022015-05-19 18:08:00 +010029#include "utils.h"
David Srbecky3b9d57a2015-04-10 00:22:14 +010030
31namespace art {
32namespace dwarf {
33
David Srbecky6d8c8f02015-10-26 10:57:09 +000034static void WriteCIE(InstructionSet isa,
35 CFIFormat format,
36 std::vector<uint8_t>* buffer) {
David Srbecky3b9d57a2015-04-10 00:22:14 +010037 // Scratch registers should be marked as undefined. This tells the
38 // debugger that its value in the previous frame is not recoverable.
39 bool is64bit = Is64BitInstructionSet(isa);
40 switch (isa) {
41 case kArm:
42 case kThumb2: {
43 DebugFrameOpCodeWriter<> opcodes;
44 opcodes.DefCFA(Reg::ArmCore(13), 0); // R13(SP).
45 // core registers.
46 for (int reg = 0; reg < 13; reg++) {
47 if (reg < 4 || reg == 12) {
48 opcodes.Undefined(Reg::ArmCore(reg));
49 } else {
50 opcodes.SameValue(Reg::ArmCore(reg));
51 }
52 }
53 // fp registers.
54 for (int reg = 0; reg < 32; reg++) {
55 if (reg < 16) {
56 opcodes.Undefined(Reg::ArmFp(reg));
57 } else {
58 opcodes.SameValue(Reg::ArmFp(reg));
59 }
60 }
David Srbecky527c9c72015-04-17 21:14:10 +010061 auto return_reg = Reg::ArmCore(14); // R14(LR).
David Srbecky6d8c8f02015-10-26 10:57:09 +000062 WriteCIE(is64bit, return_reg, opcodes, format, buffer);
David Srbecky3b9d57a2015-04-10 00:22:14 +010063 return;
64 }
65 case kArm64: {
66 DebugFrameOpCodeWriter<> opcodes;
67 opcodes.DefCFA(Reg::Arm64Core(31), 0); // R31(SP).
68 // core registers.
69 for (int reg = 0; reg < 30; reg++) {
70 if (reg < 8 || reg == 16 || reg == 17) {
71 opcodes.Undefined(Reg::Arm64Core(reg));
72 } else {
73 opcodes.SameValue(Reg::Arm64Core(reg));
74 }
75 }
76 // fp registers.
77 for (int reg = 0; reg < 32; reg++) {
78 if (reg < 8 || reg >= 16) {
79 opcodes.Undefined(Reg::Arm64Fp(reg));
80 } else {
81 opcodes.SameValue(Reg::Arm64Fp(reg));
82 }
83 }
David Srbecky527c9c72015-04-17 21:14:10 +010084 auto return_reg = Reg::Arm64Core(30); // R30(LR).
David Srbecky6d8c8f02015-10-26 10:57:09 +000085 WriteCIE(is64bit, return_reg, opcodes, format, buffer);
David Srbecky3b9d57a2015-04-10 00:22:14 +010086 return;
87 }
88 case kMips:
89 case kMips64: {
90 DebugFrameOpCodeWriter<> opcodes;
91 opcodes.DefCFA(Reg::MipsCore(29), 0); // R29(SP).
92 // core registers.
93 for (int reg = 1; reg < 26; reg++) {
94 if (reg < 16 || reg == 24 || reg == 25) { // AT, V*, A*, T*.
95 opcodes.Undefined(Reg::MipsCore(reg));
96 } else {
97 opcodes.SameValue(Reg::MipsCore(reg));
98 }
99 }
David Srbecky527c9c72015-04-17 21:14:10 +0100100 auto return_reg = Reg::MipsCore(31); // R31(RA).
David Srbecky6d8c8f02015-10-26 10:57:09 +0000101 WriteCIE(is64bit, return_reg, opcodes, format, buffer);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100102 return;
103 }
104 case kX86: {
David Srbecky8a813f72015-04-20 16:43:52 +0100105 // FIXME: Add fp registers once libunwind adds support for them. Bug: 20491296
106 constexpr bool generate_opcodes_for_x86_fp = false;
David Srbecky3b9d57a2015-04-10 00:22:14 +0100107 DebugFrameOpCodeWriter<> opcodes;
108 opcodes.DefCFA(Reg::X86Core(4), 4); // R4(ESP).
109 opcodes.Offset(Reg::X86Core(8), -4); // R8(EIP).
110 // core registers.
111 for (int reg = 0; reg < 8; reg++) {
112 if (reg <= 3) {
113 opcodes.Undefined(Reg::X86Core(reg));
114 } else if (reg == 4) {
115 // Stack pointer.
116 } else {
117 opcodes.SameValue(Reg::X86Core(reg));
118 }
119 }
120 // fp registers.
David Srbecky8a813f72015-04-20 16:43:52 +0100121 if (generate_opcodes_for_x86_fp) {
122 for (int reg = 0; reg < 8; reg++) {
123 opcodes.Undefined(Reg::X86Fp(reg));
124 }
David Srbecky3b9d57a2015-04-10 00:22:14 +0100125 }
David Srbecky527c9c72015-04-17 21:14:10 +0100126 auto return_reg = Reg::X86Core(8); // R8(EIP).
David Srbecky6d8c8f02015-10-26 10:57:09 +0000127 WriteCIE(is64bit, return_reg, opcodes, format, buffer);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100128 return;
129 }
130 case kX86_64: {
131 DebugFrameOpCodeWriter<> opcodes;
132 opcodes.DefCFA(Reg::X86_64Core(4), 8); // R4(RSP).
133 opcodes.Offset(Reg::X86_64Core(16), -8); // R16(RIP).
134 // core registers.
135 for (int reg = 0; reg < 16; reg++) {
136 if (reg == 4) {
137 // Stack pointer.
138 } else if (reg < 12 && reg != 3 && reg != 5) { // except EBX and EBP.
139 opcodes.Undefined(Reg::X86_64Core(reg));
140 } else {
141 opcodes.SameValue(Reg::X86_64Core(reg));
142 }
143 }
144 // fp registers.
145 for (int reg = 0; reg < 16; reg++) {
146 if (reg < 12) {
147 opcodes.Undefined(Reg::X86_64Fp(reg));
148 } else {
149 opcodes.SameValue(Reg::X86_64Fp(reg));
150 }
151 }
David Srbecky527c9c72015-04-17 21:14:10 +0100152 auto return_reg = Reg::X86_64Core(16); // R16(RIP).
David Srbecky6d8c8f02015-10-26 10:57:09 +0000153 WriteCIE(is64bit, return_reg, opcodes, format, buffer);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100154 return;
155 }
156 case kNone:
157 break;
158 }
159 LOG(FATAL) << "Can not write CIE frame for ISA " << isa;
160 UNREACHABLE();
161}
162
David Srbecky6d8c8f02015-10-26 10:57:09 +0000163template<typename ElfTypes>
164void WriteCFISection(ElfBuilder<ElfTypes>* builder,
165 const std::vector<OatWriter::DebugInfo>& method_infos,
166 CFIFormat format) {
167 CHECK(format == dwarf::DW_DEBUG_FRAME_FORMAT ||
168 format == dwarf::DW_EH_FRAME_FORMAT);
169 typedef typename ElfTypes::Addr Elf_Addr;
170
171 std::vector<uint32_t> binary_search_table;
172 std::vector<uintptr_t> patch_locations;
173 if (format == DW_EH_FRAME_FORMAT) {
174 binary_search_table.reserve(2 * method_infos.size());
175 } else {
176 patch_locations.reserve(method_infos.size());
177 }
David Srbecky527c9c72015-04-17 21:14:10 +0100178
David Srbeckyad5fa8c2015-05-06 18:27:35 +0100179 // Write .eh_frame/.debug_frame section.
David Srbecky6d8c8f02015-10-26 10:57:09 +0000180 auto* cfi_section = (format == dwarf::DW_DEBUG_FRAME_FORMAT
181 ? builder->GetDebugFrame()
182 : builder->GetEhFrame());
183 {
184 cfi_section->Start();
185 const bool is64bit = Is64BitInstructionSet(builder->GetIsa());
186 const Elf_Addr text_address = builder->GetText()->GetAddress();
187 const Elf_Addr cfi_address = cfi_section->GetAddress();
188 const Elf_Addr cie_address = cfi_address;
189 Elf_Addr buffer_address = cfi_address;
190 std::vector<uint8_t> buffer; // Small temporary buffer.
191 WriteCIE(builder->GetIsa(), format, &buffer);
192 cfi_section->WriteFully(buffer.data(), buffer.size());
193 buffer_address += buffer.size();
194 buffer.clear();
195 for (const OatWriter::DebugInfo& mi : method_infos) {
196 if (!mi.deduped_) { // Only one FDE per unique address.
197 ArrayRef<const uint8_t> opcodes = mi.compiled_method_->GetCFIInfo();
198 if (!opcodes.empty()) {
199 const Elf_Addr code_address = text_address + mi.low_pc_;
200 if (format == DW_EH_FRAME_FORMAT) {
201 binary_search_table.push_back(
202 dchecked_integral_cast<uint32_t>(code_address));
203 binary_search_table.push_back(
204 dchecked_integral_cast<uint32_t>(buffer_address));
205 }
206 WriteFDE(is64bit, cfi_address, cie_address,
207 code_address, mi.high_pc_ - mi.low_pc_,
208 opcodes, format, buffer_address, &buffer,
209 &patch_locations);
210 cfi_section->WriteFully(buffer.data(), buffer.size());
211 buffer_address += buffer.size();
212 buffer.clear();
213 }
David Srbecky6d73c9d2015-05-01 15:00:40 +0100214 }
David Srbecky8dc73242015-04-12 11:40:39 +0100215 }
David Srbecky6d8c8f02015-10-26 10:57:09 +0000216 cfi_section->End();
David Srbecky8dc73242015-04-12 11:40:39 +0100217 }
David Srbecky527c9c72015-04-17 21:14:10 +0100218
David Srbeckyad5fa8c2015-05-06 18:27:35 +0100219 if (format == DW_EH_FRAME_FORMAT) {
David Srbecky6d8c8f02015-10-26 10:57:09 +0000220 auto* header_section = builder->GetEhFrameHdr();
221 header_section->Start();
222 uint32_t header_address = dchecked_integral_cast<int32_t>(header_section->GetAddress());
David Srbeckyad5fa8c2015-05-06 18:27:35 +0100223 // Write .eh_frame_hdr section.
David Srbecky6d8c8f02015-10-26 10:57:09 +0000224 std::vector<uint8_t> buffer;
225 Writer<> header(&buffer);
David Srbeckyad5fa8c2015-05-06 18:27:35 +0100226 header.PushUint8(1); // Version.
227 // Encoding of .eh_frame pointer - libunwind does not honor datarel here,
228 // so we have to use pcrel which means relative to the pointer's location.
229 header.PushUint8(DW_EH_PE_pcrel | DW_EH_PE_sdata4);
230 // Encoding of binary search table size.
231 header.PushUint8(DW_EH_PE_udata4);
232 // Encoding of binary search table addresses - libunwind supports only this
233 // specific combination, which means relative to the start of .eh_frame_hdr.
234 header.PushUint8(DW_EH_PE_datarel | DW_EH_PE_sdata4);
David Srbecky6d8c8f02015-10-26 10:57:09 +0000235 // .eh_frame pointer
236 header.PushInt32(cfi_section->GetAddress() - (header_address + 4u));
David Srbeckyad5fa8c2015-05-06 18:27:35 +0100237 // Binary search table size (number of entries).
David Srbecky6d8c8f02015-10-26 10:57:09 +0000238 header.PushUint32(dchecked_integral_cast<uint32_t>(binary_search_table.size()/2));
239 header_section->WriteFully(buffer.data(), buffer.size());
David Srbeckyad5fa8c2015-05-06 18:27:35 +0100240 // Binary search table.
David Srbecky6d8c8f02015-10-26 10:57:09 +0000241 for (size_t i = 0; i < binary_search_table.size(); i++) {
242 // Make addresses section-relative since we know the header address now.
243 binary_search_table[i] -= header_address;
David Srbeckyad5fa8c2015-05-06 18:27:35 +0100244 }
David Srbecky6d8c8f02015-10-26 10:57:09 +0000245 header_section->WriteFully(binary_search_table.data(), binary_search_table.size());
246 header_section->End();
247 } else {
248 builder->WritePatches(".debug_frame.oat_patches", &patch_locations);
David Srbecky033d7452015-04-30 19:57:35 +0100249 }
David Srbecky8dc73242015-04-12 11:40:39 +0100250}
251
David Srbecky6d8c8f02015-10-26 10:57:09 +0000252template<typename ElfTypes>
253void WriteDebugSections(ElfBuilder<ElfTypes>* builder,
254 const std::vector<OatWriter::DebugInfo>& method_infos) {
255 typedef typename ElfTypes::Addr Elf_Addr;
256 const bool is64bit = Is64BitInstructionSet(builder->GetIsa());
257 Elf_Addr text_address = builder->GetText()->GetAddress();
David Srbecky3b9d57a2015-04-10 00:22:14 +0100258
David Srbecky626a1662015-04-12 13:12:26 +0100259 // Find all addresses (low_pc) which contain deduped methods.
260 // The first instance of method is not marked deduped_, but the rest is.
261 std::unordered_set<uint32_t> deduped_addresses;
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100262 for (const OatWriter::DebugInfo& mi : method_infos) {
263 if (mi.deduped_) {
264 deduped_addresses.insert(mi.low_pc_);
David Srbecky626a1662015-04-12 13:12:26 +0100265 }
266 }
267
David Srbecky799b8c42015-04-14 01:57:43 +0100268 // Group the methods into compilation units based on source file.
269 std::vector<std::vector<const OatWriter::DebugInfo*>> compilation_units;
270 const char* last_source_file = nullptr;
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100271 for (const OatWriter::DebugInfo& mi : method_infos) {
David Srbecky799b8c42015-04-14 01:57:43 +0100272 // Attribute given instruction range only to single method.
273 // Otherwise the debugger might get really confused.
274 if (!mi.deduped_) {
275 auto& dex_class_def = mi.dex_file_->GetClassDef(mi.class_def_index_);
276 const char* source_file = mi.dex_file_->GetSourceFile(dex_class_def);
277 if (compilation_units.empty() || source_file != last_source_file) {
278 compilation_units.push_back(std::vector<const OatWriter::DebugInfo*>());
279 }
280 compilation_units.back().push_back(&mi);
281 last_source_file = source_file;
282 }
283 }
284
David Srbecky3b9d57a2015-04-10 00:22:14 +0100285 // Write .debug_info section.
David Srbecky6d8c8f02015-10-26 10:57:09 +0000286 std::vector<uint8_t> debug_info;
287 std::vector<uintptr_t> debug_info_patches;
288 std::vector<uint8_t> debug_abbrev;
289 std::vector<uint8_t> debug_str;
290 std::vector<uint8_t> debug_line;
291 std::vector<uintptr_t> debug_line_patches;
David Srbecky799b8c42015-04-14 01:57:43 +0100292 for (const auto& compilation_unit : compilation_units) {
293 uint32_t cunit_low_pc = 0xFFFFFFFFU;
294 uint32_t cunit_high_pc = 0;
295 for (auto method_info : compilation_unit) {
296 cunit_low_pc = std::min(cunit_low_pc, method_info->low_pc_);
297 cunit_high_pc = std::max(cunit_high_pc, method_info->high_pc_);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100298 }
299
David Srbecky6d8c8f02015-10-26 10:57:09 +0000300 size_t debug_abbrev_offset = debug_abbrev.size();
301 DebugInfoEntryWriter<> info(is64bit, &debug_abbrev);
David Srbecky799b8c42015-04-14 01:57:43 +0100302 info.StartTag(DW_TAG_compile_unit, DW_CHILDREN_yes);
David Srbecky6d8c8f02015-10-26 10:57:09 +0000303 info.WriteStrp(DW_AT_producer, "Android dex2oat", &debug_str);
David Srbecky799b8c42015-04-14 01:57:43 +0100304 info.WriteData1(DW_AT_language, DW_LANG_Java);
David Srbecky6d8c8f02015-10-26 10:57:09 +0000305 info.WriteAddr(DW_AT_low_pc, text_address + cunit_low_pc);
306 info.WriteAddr(DW_AT_high_pc, text_address + cunit_high_pc);
307 info.WriteData4(DW_AT_stmt_list, debug_line.size());
David Srbecky799b8c42015-04-14 01:57:43 +0100308 for (auto method_info : compilation_unit) {
309 std::string method_name = PrettyMethod(method_info->dex_method_index_,
310 *method_info->dex_file_, true);
311 if (deduped_addresses.find(method_info->low_pc_) != deduped_addresses.end()) {
312 method_name += " [DEDUPED]";
David Srbecky3b9d57a2015-04-10 00:22:14 +0100313 }
David Srbecky799b8c42015-04-14 01:57:43 +0100314 info.StartTag(DW_TAG_subprogram, DW_CHILDREN_no);
David Srbecky6d8c8f02015-10-26 10:57:09 +0000315 info.WriteStrp(DW_AT_name, method_name.data(), &debug_str);
316 info.WriteAddr(DW_AT_low_pc, text_address + method_info->low_pc_);
317 info.WriteAddr(DW_AT_high_pc, text_address + method_info->high_pc_);
David Srbecky799b8c42015-04-14 01:57:43 +0100318 info.EndTag(); // DW_TAG_subprogram
David Srbecky3b9d57a2015-04-10 00:22:14 +0100319 }
David Srbecky799b8c42015-04-14 01:57:43 +0100320 info.EndTag(); // DW_TAG_compile_unit
David Srbecky6d8c8f02015-10-26 10:57:09 +0000321 WriteDebugInfoCU(debug_abbrev_offset, info, &debug_info, &debug_info_patches);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100322
David Srbecky799b8c42015-04-14 01:57:43 +0100323 // Write .debug_line section.
324 std::vector<FileEntry> files;
325 std::unordered_map<std::string, size_t> files_map;
326 std::vector<std::string> directories;
327 std::unordered_map<std::string, size_t> directories_map;
328 int code_factor_bits_ = 0;
329 int dwarf_isa = -1;
David Srbecky6d8c8f02015-10-26 10:57:09 +0000330 switch (builder->GetIsa()) {
David Srbecky799b8c42015-04-14 01:57:43 +0100331 case kArm: // arm actually means thumb2.
332 case kThumb2:
333 code_factor_bits_ = 1; // 16-bit instuctions
334 dwarf_isa = 1; // DW_ISA_ARM_thumb.
335 break;
336 case kArm64:
337 case kMips:
338 case kMips64:
339 code_factor_bits_ = 2; // 32-bit instructions
340 break;
341 case kNone:
342 case kX86:
343 case kX86_64:
344 break;
345 }
David Srbecky297ed222015-04-15 01:18:12 +0100346 DebugLineOpCodeWriter<> opcodes(is64bit, code_factor_bits_);
David Srbecky6d8c8f02015-10-26 10:57:09 +0000347 opcodes.SetAddress(text_address + cunit_low_pc);
David Srbecky799b8c42015-04-14 01:57:43 +0100348 if (dwarf_isa != -1) {
349 opcodes.SetISA(dwarf_isa);
350 }
351 for (const OatWriter::DebugInfo* mi : compilation_unit) {
352 struct DebugInfoCallbacks {
353 static bool NewPosition(void* ctx, uint32_t address, uint32_t line) {
354 auto* context = reinterpret_cast<DebugInfoCallbacks*>(ctx);
355 context->dex2line_.push_back({address, static_cast<int32_t>(line)});
356 return false;
David Srbecky3b9d57a2015-04-10 00:22:14 +0100357 }
David Srbecky799b8c42015-04-14 01:57:43 +0100358 DefaultSrcMap dex2line_;
359 } debug_info_callbacks;
360
David Srbecky6d8c8f02015-10-26 10:57:09 +0000361 Elf_Addr method_address = text_address + mi->low_pc_;
362
David Srbecky799b8c42015-04-14 01:57:43 +0100363 const DexFile* dex = mi->dex_file_;
364 if (mi->code_item_ != nullptr) {
365 dex->DecodeDebugInfo(mi->code_item_,
366 (mi->access_flags_ & kAccStatic) != 0,
367 mi->dex_method_index_,
368 DebugInfoCallbacks::NewPosition,
369 nullptr,
370 &debug_info_callbacks);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100371 }
372
David Srbecky799b8c42015-04-14 01:57:43 +0100373 // Get and deduplicate directory and filename.
374 int file_index = 0; // 0 - primary source file of the compilation.
375 auto& dex_class_def = dex->GetClassDef(mi->class_def_index_);
376 const char* source_file = dex->GetSourceFile(dex_class_def);
377 if (source_file != nullptr) {
378 std::string file_name(source_file);
379 size_t file_name_slash = file_name.find_last_of('/');
380 std::string class_name(dex->GetClassDescriptor(dex_class_def));
381 size_t class_name_slash = class_name.find_last_of('/');
382 std::string full_path(file_name);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100383
David Srbecky799b8c42015-04-14 01:57:43 +0100384 // Guess directory from package name.
385 int directory_index = 0; // 0 - current directory of the compilation.
386 if (file_name_slash == std::string::npos && // Just filename.
387 class_name.front() == 'L' && // Type descriptor for a class.
388 class_name_slash != std::string::npos) { // Has package name.
389 std::string package_name = class_name.substr(1, class_name_slash - 1);
390 auto it = directories_map.find(package_name);
391 if (it == directories_map.end()) {
392 directory_index = 1 + directories.size();
393 directories_map.emplace(package_name, directory_index);
394 directories.push_back(package_name);
395 } else {
396 directory_index = it->second;
397 }
398 full_path = package_name + "/" + file_name;
399 }
400
401 // Add file entry.
402 auto it2 = files_map.find(full_path);
403 if (it2 == files_map.end()) {
404 file_index = 1 + files.size();
405 files_map.emplace(full_path, file_index);
406 files.push_back(FileEntry {
407 file_name,
408 directory_index,
409 0, // Modification time - NA.
410 0, // File size - NA.
411 });
412 } else {
413 file_index = it2->second;
414 }
415 }
416 opcodes.SetFile(file_index);
417
418 // Generate mapping opcodes from PC to Java lines.
419 const DefaultSrcMap& dex2line_map = debug_info_callbacks.dex2line_;
David Srbecky799b8c42015-04-14 01:57:43 +0100420 if (file_index != 0 && !dex2line_map.empty()) {
421 bool first = true;
422 for (SrcMapElem pc2dex : mi->compiled_method_->GetSrcMappingTable()) {
423 uint32_t pc = pc2dex.from_;
424 int dex_pc = pc2dex.to_;
425 auto dex2line = dex2line_map.Find(static_cast<uint32_t>(dex_pc));
426 if (dex2line.first) {
427 int line = dex2line.second;
428 if (first) {
429 first = false;
430 if (pc > 0) {
431 // Assume that any preceding code is prologue.
432 int first_line = dex2line_map.front().to_;
433 // Prologue is not a sensible place for a breakpoint.
434 opcodes.NegateStmt();
David Srbecky6d8c8f02015-10-26 10:57:09 +0000435 opcodes.AddRow(method_address, first_line);
David Srbecky799b8c42015-04-14 01:57:43 +0100436 opcodes.NegateStmt();
437 opcodes.SetPrologueEnd();
438 }
David Srbecky6d8c8f02015-10-26 10:57:09 +0000439 opcodes.AddRow(method_address + pc, line);
David Srbecky799b8c42015-04-14 01:57:43 +0100440 } else if (line != opcodes.CurrentLine()) {
David Srbecky6d8c8f02015-10-26 10:57:09 +0000441 opcodes.AddRow(method_address + pc, line);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100442 }
David Srbecky3b9d57a2015-04-10 00:22:14 +0100443 }
444 }
David Srbecky799b8c42015-04-14 01:57:43 +0100445 } else {
446 // line 0 - instruction cannot be attributed to any source line.
David Srbecky6d8c8f02015-10-26 10:57:09 +0000447 opcodes.AddRow(method_address, 0);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100448 }
David Srbecky3b9d57a2015-04-10 00:22:14 +0100449 }
David Srbecky6d8c8f02015-10-26 10:57:09 +0000450 opcodes.AdvancePC(text_address + cunit_high_pc);
David Srbecky799b8c42015-04-14 01:57:43 +0100451 opcodes.EndSequence();
David Srbecky6d8c8f02015-10-26 10:57:09 +0000452 WriteDebugLineTable(directories, files, opcodes, &debug_line, &debug_line_patches);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100453 }
David Srbecky6d8c8f02015-10-26 10:57:09 +0000454 builder->WriteSection(".debug_info", &debug_info);
455 builder->WritePatches(".debug_info.oat_patches", &debug_info_patches);
456 builder->WriteSection(".debug_abbrev", &debug_abbrev);
457 builder->WriteSection(".debug_str", &debug_str);
458 builder->WriteSection(".debug_line", &debug_line);
459 builder->WritePatches(".debug_line.oat_patches", &debug_line_patches);
David Srbecky3b9d57a2015-04-10 00:22:14 +0100460}
461
David Srbecky6d8c8f02015-10-26 10:57:09 +0000462// Explicit instantiations
463template void WriteCFISection<ElfTypes32>(
464 ElfBuilder<ElfTypes32>* builder,
465 const std::vector<OatWriter::DebugInfo>& method_infos,
466 CFIFormat format);
467template void WriteCFISection<ElfTypes64>(
468 ElfBuilder<ElfTypes64>* builder,
469 const std::vector<OatWriter::DebugInfo>& method_infos,
470 CFIFormat format);
471template void WriteDebugSections<ElfTypes32>(
472 ElfBuilder<ElfTypes32>* builder,
473 const std::vector<OatWriter::DebugInfo>& method_infos);
474template void WriteDebugSections<ElfTypes64>(
475 ElfBuilder<ElfTypes64>* builder,
476 const std::vector<OatWriter::DebugInfo>& method_infos);
477
David Srbecky3b9d57a2015-04-10 00:22:14 +0100478} // namespace dwarf
479} // namespace art