David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1 | /* |
| 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 Srbecky | 5e974a6 | 2016-01-22 14:25:03 +0000 | [diff] [blame] | 19 | #include <algorithm> |
David Srbecky | 626a166 | 2015-04-12 13:12:26 +0100 | [diff] [blame] | 20 | #include <unordered_set> |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 21 | #include <vector> |
David Srbecky | 9b3607d | 2016-01-14 18:15:54 +0000 | [diff] [blame] | 22 | #include <cstdio> |
David Srbecky | 626a166 | 2015-04-12 13:12:26 +0100 | [diff] [blame] | 23 | |
Andreas Gampe | e3d623e | 2015-05-01 16:11:04 -0700 | [diff] [blame] | 24 | #include "base/casts.h" |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 25 | #include "base/stl_util.h" |
David Srbecky | 9b3607d | 2016-01-14 18:15:54 +0000 | [diff] [blame] | 26 | #include "linear_alloc.h" |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 27 | #include "compiled_method.h" |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 28 | #include "dex_file-inl.h" |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 29 | #include "driver/compiler_driver.h" |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 30 | #include "dwarf/dedup_vector.h" |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 31 | #include "dwarf/expression.h" |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 32 | #include "dwarf/headers.h" |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 33 | #include "dwarf/method_debug_info.h" |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 34 | #include "dwarf/register.h" |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 35 | #include "elf_builder.h" |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 36 | #include "linker/vector_output_stream.h" |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 37 | #include "mirror/array.h" |
| 38 | #include "mirror/class-inl.h" |
| 39 | #include "mirror/class.h" |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 40 | #include "oat_writer.h" |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 41 | #include "stack_map.h" |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 42 | #include "utils.h" |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 43 | |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame] | 44 | // liblzma. |
| 45 | #include "XzEnc.h" |
| 46 | #include "7zCrc.h" |
| 47 | #include "XzCrc64.h" |
| 48 | |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 49 | namespace art { |
| 50 | namespace dwarf { |
| 51 | |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 52 | // The ARM specification defines three special mapping symbols |
| 53 | // $a, $t and $d which mark ARM, Thumb and data ranges respectively. |
| 54 | // These symbols can be used by tools, for example, to pretty |
| 55 | // print instructions correctly. Objdump will use them if they |
| 56 | // exist, but it will still work well without them. |
| 57 | // However, these extra symbols take space, so let's just generate |
| 58 | // one symbol which marks the whole .text section as code. |
| 59 | constexpr bool kGenerateSingleArmMappingSymbol = true; |
| 60 | |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 61 | static Reg GetDwarfCoreReg(InstructionSet isa, int machine_reg) { |
| 62 | switch (isa) { |
| 63 | case kArm: |
| 64 | case kThumb2: |
| 65 | return Reg::ArmCore(machine_reg); |
| 66 | case kArm64: |
| 67 | return Reg::Arm64Core(machine_reg); |
| 68 | case kX86: |
| 69 | return Reg::X86Core(machine_reg); |
| 70 | case kX86_64: |
| 71 | return Reg::X86_64Core(machine_reg); |
| 72 | case kMips: |
| 73 | return Reg::MipsCore(machine_reg); |
| 74 | case kMips64: |
| 75 | return Reg::Mips64Core(machine_reg); |
| 76 | default: |
| 77 | LOG(FATAL) << "Unknown instruction set: " << isa; |
| 78 | UNREACHABLE(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static Reg GetDwarfFpReg(InstructionSet isa, int machine_reg) { |
| 83 | switch (isa) { |
| 84 | case kArm: |
| 85 | case kThumb2: |
| 86 | return Reg::ArmFp(machine_reg); |
| 87 | case kArm64: |
| 88 | return Reg::Arm64Fp(machine_reg); |
| 89 | case kX86: |
| 90 | return Reg::X86Fp(machine_reg); |
| 91 | case kX86_64: |
| 92 | return Reg::X86_64Fp(machine_reg); |
| 93 | default: |
| 94 | LOG(FATAL) << "Unknown instruction set: " << isa; |
| 95 | UNREACHABLE(); |
| 96 | } |
| 97 | } |
| 98 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 99 | static void WriteCIE(InstructionSet isa, |
| 100 | CFIFormat format, |
| 101 | std::vector<uint8_t>* buffer) { |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 102 | // Scratch registers should be marked as undefined. This tells the |
| 103 | // debugger that its value in the previous frame is not recoverable. |
| 104 | bool is64bit = Is64BitInstructionSet(isa); |
| 105 | switch (isa) { |
| 106 | case kArm: |
| 107 | case kThumb2: { |
| 108 | DebugFrameOpCodeWriter<> opcodes; |
| 109 | opcodes.DefCFA(Reg::ArmCore(13), 0); // R13(SP). |
| 110 | // core registers. |
| 111 | for (int reg = 0; reg < 13; reg++) { |
| 112 | if (reg < 4 || reg == 12) { |
| 113 | opcodes.Undefined(Reg::ArmCore(reg)); |
| 114 | } else { |
| 115 | opcodes.SameValue(Reg::ArmCore(reg)); |
| 116 | } |
| 117 | } |
| 118 | // fp registers. |
| 119 | for (int reg = 0; reg < 32; reg++) { |
| 120 | if (reg < 16) { |
| 121 | opcodes.Undefined(Reg::ArmFp(reg)); |
| 122 | } else { |
| 123 | opcodes.SameValue(Reg::ArmFp(reg)); |
| 124 | } |
| 125 | } |
David Srbecky | 527c9c7 | 2015-04-17 21:14:10 +0100 | [diff] [blame] | 126 | auto return_reg = Reg::ArmCore(14); // R14(LR). |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 127 | WriteCIE(is64bit, return_reg, opcodes, format, buffer); |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 128 | return; |
| 129 | } |
| 130 | case kArm64: { |
| 131 | DebugFrameOpCodeWriter<> opcodes; |
| 132 | opcodes.DefCFA(Reg::Arm64Core(31), 0); // R31(SP). |
| 133 | // core registers. |
| 134 | for (int reg = 0; reg < 30; reg++) { |
| 135 | if (reg < 8 || reg == 16 || reg == 17) { |
| 136 | opcodes.Undefined(Reg::Arm64Core(reg)); |
| 137 | } else { |
| 138 | opcodes.SameValue(Reg::Arm64Core(reg)); |
| 139 | } |
| 140 | } |
| 141 | // fp registers. |
| 142 | for (int reg = 0; reg < 32; reg++) { |
| 143 | if (reg < 8 || reg >= 16) { |
| 144 | opcodes.Undefined(Reg::Arm64Fp(reg)); |
| 145 | } else { |
| 146 | opcodes.SameValue(Reg::Arm64Fp(reg)); |
| 147 | } |
| 148 | } |
David Srbecky | 527c9c7 | 2015-04-17 21:14:10 +0100 | [diff] [blame] | 149 | auto return_reg = Reg::Arm64Core(30); // R30(LR). |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 150 | WriteCIE(is64bit, return_reg, opcodes, format, buffer); |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 151 | return; |
| 152 | } |
| 153 | case kMips: |
| 154 | case kMips64: { |
| 155 | DebugFrameOpCodeWriter<> opcodes; |
| 156 | opcodes.DefCFA(Reg::MipsCore(29), 0); // R29(SP). |
| 157 | // core registers. |
| 158 | for (int reg = 1; reg < 26; reg++) { |
| 159 | if (reg < 16 || reg == 24 || reg == 25) { // AT, V*, A*, T*. |
| 160 | opcodes.Undefined(Reg::MipsCore(reg)); |
| 161 | } else { |
| 162 | opcodes.SameValue(Reg::MipsCore(reg)); |
| 163 | } |
| 164 | } |
David Srbecky | 527c9c7 | 2015-04-17 21:14:10 +0100 | [diff] [blame] | 165 | auto return_reg = Reg::MipsCore(31); // R31(RA). |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 166 | WriteCIE(is64bit, return_reg, opcodes, format, buffer); |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 167 | return; |
| 168 | } |
| 169 | case kX86: { |
David Srbecky | 8a813f7 | 2015-04-20 16:43:52 +0100 | [diff] [blame] | 170 | // FIXME: Add fp registers once libunwind adds support for them. Bug: 20491296 |
| 171 | constexpr bool generate_opcodes_for_x86_fp = false; |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 172 | DebugFrameOpCodeWriter<> opcodes; |
| 173 | opcodes.DefCFA(Reg::X86Core(4), 4); // R4(ESP). |
| 174 | opcodes.Offset(Reg::X86Core(8), -4); // R8(EIP). |
| 175 | // core registers. |
| 176 | for (int reg = 0; reg < 8; reg++) { |
| 177 | if (reg <= 3) { |
| 178 | opcodes.Undefined(Reg::X86Core(reg)); |
| 179 | } else if (reg == 4) { |
| 180 | // Stack pointer. |
| 181 | } else { |
| 182 | opcodes.SameValue(Reg::X86Core(reg)); |
| 183 | } |
| 184 | } |
| 185 | // fp registers. |
David Srbecky | 8a813f7 | 2015-04-20 16:43:52 +0100 | [diff] [blame] | 186 | if (generate_opcodes_for_x86_fp) { |
| 187 | for (int reg = 0; reg < 8; reg++) { |
| 188 | opcodes.Undefined(Reg::X86Fp(reg)); |
| 189 | } |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 190 | } |
David Srbecky | 527c9c7 | 2015-04-17 21:14:10 +0100 | [diff] [blame] | 191 | auto return_reg = Reg::X86Core(8); // R8(EIP). |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 192 | WriteCIE(is64bit, return_reg, opcodes, format, buffer); |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 193 | return; |
| 194 | } |
| 195 | case kX86_64: { |
| 196 | DebugFrameOpCodeWriter<> opcodes; |
| 197 | opcodes.DefCFA(Reg::X86_64Core(4), 8); // R4(RSP). |
| 198 | opcodes.Offset(Reg::X86_64Core(16), -8); // R16(RIP). |
| 199 | // core registers. |
| 200 | for (int reg = 0; reg < 16; reg++) { |
| 201 | if (reg == 4) { |
| 202 | // Stack pointer. |
| 203 | } else if (reg < 12 && reg != 3 && reg != 5) { // except EBX and EBP. |
| 204 | opcodes.Undefined(Reg::X86_64Core(reg)); |
| 205 | } else { |
| 206 | opcodes.SameValue(Reg::X86_64Core(reg)); |
| 207 | } |
| 208 | } |
| 209 | // fp registers. |
| 210 | for (int reg = 0; reg < 16; reg++) { |
| 211 | if (reg < 12) { |
| 212 | opcodes.Undefined(Reg::X86_64Fp(reg)); |
| 213 | } else { |
| 214 | opcodes.SameValue(Reg::X86_64Fp(reg)); |
| 215 | } |
| 216 | } |
David Srbecky | 527c9c7 | 2015-04-17 21:14:10 +0100 | [diff] [blame] | 217 | auto return_reg = Reg::X86_64Core(16); // R16(RIP). |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 218 | WriteCIE(is64bit, return_reg, opcodes, format, buffer); |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 219 | return; |
| 220 | } |
| 221 | case kNone: |
| 222 | break; |
| 223 | } |
Roland Levillain | 91d65e0 | 2016-01-19 15:59:16 +0000 | [diff] [blame] | 224 | LOG(FATAL) << "Cannot write CIE frame for ISA " << isa; |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 225 | UNREACHABLE(); |
| 226 | } |
| 227 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 228 | template<typename ElfTypes> |
| 229 | void WriteCFISection(ElfBuilder<ElfTypes>* builder, |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 230 | const ArrayRef<const MethodDebugInfo>& method_infos, |
David Srbecky | 5e974a6 | 2016-01-22 14:25:03 +0000 | [diff] [blame] | 231 | CFIFormat format, |
| 232 | bool write_oat_patches) { |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 233 | CHECK(format == DW_DEBUG_FRAME_FORMAT || format == DW_EH_FRAME_FORMAT); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 234 | typedef typename ElfTypes::Addr Elf_Addr; |
| 235 | |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 236 | if (method_infos.empty()) { |
| 237 | return; |
| 238 | } |
| 239 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 240 | std::vector<uint32_t> binary_search_table; |
| 241 | std::vector<uintptr_t> patch_locations; |
| 242 | if (format == DW_EH_FRAME_FORMAT) { |
| 243 | binary_search_table.reserve(2 * method_infos.size()); |
| 244 | } else { |
| 245 | patch_locations.reserve(method_infos.size()); |
| 246 | } |
David Srbecky | 527c9c7 | 2015-04-17 21:14:10 +0100 | [diff] [blame] | 247 | |
David Srbecky | 5e974a6 | 2016-01-22 14:25:03 +0000 | [diff] [blame] | 248 | // The methods can be written any order. |
| 249 | // Let's therefore sort them in the lexicographical order of the opcodes. |
| 250 | // This has no effect on its own. However, if the final .debug_frame section is |
| 251 | // compressed it reduces the size since similar opcodes sequences are grouped. |
| 252 | std::vector<const MethodDebugInfo*> sorted_method_infos; |
| 253 | sorted_method_infos.reserve(method_infos.size()); |
| 254 | for (size_t i = 0; i < method_infos.size(); i++) { |
| 255 | sorted_method_infos.push_back(&method_infos[i]); |
| 256 | } |
| 257 | std::sort( |
| 258 | sorted_method_infos.begin(), |
| 259 | sorted_method_infos.end(), |
| 260 | [](const MethodDebugInfo* lhs, const MethodDebugInfo* rhs) { |
| 261 | ArrayRef<const uint8_t> l = lhs->compiled_method_->GetCFIInfo(); |
| 262 | ArrayRef<const uint8_t> r = rhs->compiled_method_->GetCFIInfo(); |
| 263 | return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end()); |
| 264 | }); |
| 265 | |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 266 | // Write .eh_frame/.debug_frame section. |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 267 | auto* cfi_section = (format == DW_DEBUG_FRAME_FORMAT |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 268 | ? builder->GetDebugFrame() |
| 269 | : builder->GetEhFrame()); |
| 270 | { |
| 271 | cfi_section->Start(); |
| 272 | const bool is64bit = Is64BitInstructionSet(builder->GetIsa()); |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 273 | const Elf_Addr text_address = builder->GetText()->Exists() |
| 274 | ? builder->GetText()->GetAddress() |
| 275 | : 0; |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 276 | const Elf_Addr cfi_address = cfi_section->GetAddress(); |
| 277 | const Elf_Addr cie_address = cfi_address; |
| 278 | Elf_Addr buffer_address = cfi_address; |
| 279 | std::vector<uint8_t> buffer; // Small temporary buffer. |
| 280 | WriteCIE(builder->GetIsa(), format, &buffer); |
| 281 | cfi_section->WriteFully(buffer.data(), buffer.size()); |
| 282 | buffer_address += buffer.size(); |
| 283 | buffer.clear(); |
David Srbecky | 5e974a6 | 2016-01-22 14:25:03 +0000 | [diff] [blame] | 284 | for (const MethodDebugInfo* mi : sorted_method_infos) { |
| 285 | if (!mi->deduped_) { // Only one FDE per unique address. |
| 286 | ArrayRef<const uint8_t> opcodes = mi->compiled_method_->GetCFIInfo(); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 287 | if (!opcodes.empty()) { |
David Srbecky | 5e974a6 | 2016-01-22 14:25:03 +0000 | [diff] [blame] | 288 | const Elf_Addr code_address = text_address + mi->low_pc_; |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 289 | if (format == DW_EH_FRAME_FORMAT) { |
| 290 | binary_search_table.push_back( |
| 291 | dchecked_integral_cast<uint32_t>(code_address)); |
| 292 | binary_search_table.push_back( |
| 293 | dchecked_integral_cast<uint32_t>(buffer_address)); |
| 294 | } |
| 295 | WriteFDE(is64bit, cfi_address, cie_address, |
David Srbecky | 5e974a6 | 2016-01-22 14:25:03 +0000 | [diff] [blame] | 296 | code_address, mi->high_pc_ - mi->low_pc_, |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 297 | opcodes, format, buffer_address, &buffer, |
| 298 | &patch_locations); |
| 299 | cfi_section->WriteFully(buffer.data(), buffer.size()); |
| 300 | buffer_address += buffer.size(); |
| 301 | buffer.clear(); |
| 302 | } |
David Srbecky | 6d73c9d | 2015-05-01 15:00:40 +0100 | [diff] [blame] | 303 | } |
David Srbecky | 8dc7324 | 2015-04-12 11:40:39 +0100 | [diff] [blame] | 304 | } |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 305 | cfi_section->End(); |
David Srbecky | 8dc7324 | 2015-04-12 11:40:39 +0100 | [diff] [blame] | 306 | } |
David Srbecky | 527c9c7 | 2015-04-17 21:14:10 +0100 | [diff] [blame] | 307 | |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 308 | if (format == DW_EH_FRAME_FORMAT) { |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 309 | auto* header_section = builder->GetEhFrameHdr(); |
| 310 | header_section->Start(); |
| 311 | uint32_t header_address = dchecked_integral_cast<int32_t>(header_section->GetAddress()); |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 312 | // Write .eh_frame_hdr section. |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 313 | std::vector<uint8_t> buffer; |
| 314 | Writer<> header(&buffer); |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 315 | header.PushUint8(1); // Version. |
| 316 | // Encoding of .eh_frame pointer - libunwind does not honor datarel here, |
| 317 | // so we have to use pcrel which means relative to the pointer's location. |
| 318 | header.PushUint8(DW_EH_PE_pcrel | DW_EH_PE_sdata4); |
| 319 | // Encoding of binary search table size. |
| 320 | header.PushUint8(DW_EH_PE_udata4); |
| 321 | // Encoding of binary search table addresses - libunwind supports only this |
| 322 | // specific combination, which means relative to the start of .eh_frame_hdr. |
| 323 | header.PushUint8(DW_EH_PE_datarel | DW_EH_PE_sdata4); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 324 | // .eh_frame pointer |
| 325 | header.PushInt32(cfi_section->GetAddress() - (header_address + 4u)); |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 326 | // Binary search table size (number of entries). |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 327 | header.PushUint32(dchecked_integral_cast<uint32_t>(binary_search_table.size()/2)); |
| 328 | header_section->WriteFully(buffer.data(), buffer.size()); |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 329 | // Binary search table. |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 330 | for (size_t i = 0; i < binary_search_table.size(); i++) { |
| 331 | // Make addresses section-relative since we know the header address now. |
| 332 | binary_search_table[i] -= header_address; |
David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 333 | } |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 334 | header_section->WriteFully(binary_search_table.data(), binary_search_table.size()); |
| 335 | header_section->End(); |
| 336 | } else { |
David Srbecky | 5e974a6 | 2016-01-22 14:25:03 +0000 | [diff] [blame] | 337 | if (write_oat_patches) { |
| 338 | builder->WritePatches(".debug_frame.oat_patches", |
| 339 | ArrayRef<const uintptr_t>(patch_locations)); |
| 340 | } |
David Srbecky | 033d745 | 2015-04-30 19:57:35 +0100 | [diff] [blame] | 341 | } |
David Srbecky | 8dc7324 | 2015-04-12 11:40:39 +0100 | [diff] [blame] | 342 | } |
| 343 | |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 344 | namespace { |
| 345 | struct CompilationUnit { |
| 346 | std::vector<const MethodDebugInfo*> methods_; |
| 347 | size_t debug_line_offset_ = 0; |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 348 | uintptr_t low_pc_ = std::numeric_limits<uintptr_t>::max(); |
| 349 | uintptr_t high_pc_ = 0; |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 350 | }; |
| 351 | |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 352 | typedef std::vector<DexFile::LocalInfo> LocalInfos; |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 353 | |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 354 | void LocalInfoCallback(void* ctx, const DexFile::LocalInfo& entry) { |
| 355 | static_cast<LocalInfos*>(ctx)->push_back(entry); |
| 356 | } |
| 357 | |
| 358 | typedef std::vector<DexFile::PositionInfo> PositionInfos; |
| 359 | |
| 360 | bool PositionInfoCallback(void* ctx, const DexFile::PositionInfo& entry) { |
| 361 | static_cast<PositionInfos*>(ctx)->push_back(entry); |
| 362 | return false; |
| 363 | } |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 364 | |
| 365 | std::vector<const char*> GetParamNames(const MethodDebugInfo* mi) { |
| 366 | std::vector<const char*> names; |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 367 | if (mi->code_item_ != nullptr) { |
| 368 | const uint8_t* stream = mi->dex_file_->GetDebugInfoStream(mi->code_item_); |
| 369 | if (stream != nullptr) { |
| 370 | DecodeUnsignedLeb128(&stream); // line. |
| 371 | uint32_t parameters_size = DecodeUnsignedLeb128(&stream); |
| 372 | for (uint32_t i = 0; i < parameters_size; ++i) { |
| 373 | uint32_t id = DecodeUnsignedLeb128P1(&stream); |
| 374 | names.push_back(mi->dex_file_->StringDataByIdx(id)); |
| 375 | } |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | return names; |
| 379 | } |
| 380 | |
| 381 | struct VariableLocation { |
| 382 | uint32_t low_pc; |
| 383 | uint32_t high_pc; |
| 384 | DexRegisterLocation reg_lo; // May be None if the location is unknown. |
| 385 | DexRegisterLocation reg_hi; // Most significant bits of 64-bit value. |
| 386 | }; |
| 387 | |
| 388 | // Get the location of given dex register (e.g. stack or machine register). |
| 389 | // Note that the location might be different based on the current pc. |
| 390 | // The result will cover all ranges where the variable is in scope. |
| 391 | std::vector<VariableLocation> GetVariableLocations(const MethodDebugInfo* method_info, |
| 392 | uint16_t vreg, |
| 393 | bool is64bitValue, |
| 394 | uint32_t dex_pc_low, |
| 395 | uint32_t dex_pc_high) { |
| 396 | std::vector<VariableLocation> variable_locations; |
| 397 | |
| 398 | // Get stack maps sorted by pc (they might not be sorted internally). |
| 399 | const CodeInfo code_info(method_info->compiled_method_->GetVmapTable().data()); |
| 400 | const StackMapEncoding encoding = code_info.ExtractEncoding(); |
| 401 | std::map<uint32_t, StackMap> stack_maps; |
| 402 | for (uint32_t s = 0; s < code_info.GetNumberOfStackMaps(); s++) { |
| 403 | StackMap stack_map = code_info.GetStackMapAt(s, encoding); |
| 404 | DCHECK(stack_map.IsValid()); |
| 405 | const uint32_t low_pc = method_info->low_pc_ + stack_map.GetNativePcOffset(encoding); |
| 406 | DCHECK_LE(low_pc, method_info->high_pc_); |
| 407 | stack_maps.emplace(low_pc, stack_map); |
| 408 | } |
| 409 | |
| 410 | // Create entries for the requested register based on stack map data. |
| 411 | for (auto it = stack_maps.begin(); it != stack_maps.end(); it++) { |
| 412 | const StackMap& stack_map = it->second; |
| 413 | const uint32_t low_pc = it->first; |
| 414 | auto next_it = it; |
| 415 | next_it++; |
| 416 | const uint32_t high_pc = next_it != stack_maps.end() ? next_it->first |
| 417 | : method_info->high_pc_; |
| 418 | DCHECK_LE(low_pc, high_pc); |
| 419 | if (low_pc == high_pc) { |
| 420 | continue; // Ignore if the address range is empty. |
| 421 | } |
| 422 | |
| 423 | // Check that the stack map is in the requested range. |
| 424 | uint32_t dex_pc = stack_map.GetDexPc(encoding); |
| 425 | if (!(dex_pc_low <= dex_pc && dex_pc < dex_pc_high)) { |
| 426 | continue; |
| 427 | } |
| 428 | |
| 429 | // Find the location of the dex register. |
| 430 | DexRegisterLocation reg_lo = DexRegisterLocation::None(); |
| 431 | DexRegisterLocation reg_hi = DexRegisterLocation::None(); |
| 432 | if (stack_map.HasDexRegisterMap(encoding)) { |
| 433 | DexRegisterMap dex_register_map = code_info.GetDexRegisterMapOf( |
| 434 | stack_map, encoding, method_info->code_item_->registers_size_); |
| 435 | reg_lo = dex_register_map.GetDexRegisterLocation( |
| 436 | vreg, method_info->code_item_->registers_size_, code_info, encoding); |
| 437 | if (is64bitValue) { |
| 438 | reg_hi = dex_register_map.GetDexRegisterLocation( |
| 439 | vreg + 1, method_info->code_item_->registers_size_, code_info, encoding); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | // Add location entry for this address range. |
| 444 | if (!variable_locations.empty() && |
| 445 | variable_locations.back().reg_lo == reg_lo && |
| 446 | variable_locations.back().reg_hi == reg_hi && |
| 447 | variable_locations.back().high_pc == low_pc) { |
| 448 | // Merge with the previous entry (extend its range). |
| 449 | variable_locations.back().high_pc = high_pc; |
| 450 | } else { |
| 451 | variable_locations.push_back({low_pc, high_pc, reg_lo, reg_hi}); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | return variable_locations; |
| 456 | } |
David Srbecky | f71b3ad | 2015-12-08 15:05:08 +0000 | [diff] [blame] | 457 | |
| 458 | bool IsFromOptimizingCompiler(const MethodDebugInfo* method_info) { |
| 459 | return method_info->compiled_method_->GetQuickCode().size() > 0 && |
| 460 | method_info->compiled_method_->GetVmapTable().size() > 0 && |
| 461 | method_info->compiled_method_->GetGcMap().size() == 0 && |
| 462 | method_info->code_item_ != nullptr; |
| 463 | } |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 464 | } // namespace |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 465 | |
| 466 | // Helper class to write .debug_info and its supporting sections. |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 467 | template<typename ElfTypes> |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 468 | class DebugInfoWriter { |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 469 | typedef typename ElfTypes::Addr Elf_Addr; |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 470 | |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 471 | // Helper class to write one compilation unit. |
| 472 | // It holds helper methods and temporary state. |
| 473 | class CompilationUnitWriter { |
| 474 | public: |
| 475 | explicit CompilationUnitWriter(DebugInfoWriter* owner) |
| 476 | : owner_(owner), |
| 477 | info_(Is64BitInstructionSet(owner_->builder_->GetIsa()), &debug_abbrev_) { |
| 478 | } |
| 479 | |
| 480 | void Write(const CompilationUnit& compilation_unit) { |
| 481 | CHECK(!compilation_unit.methods_.empty()); |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 482 | const Elf_Addr text_address = owner_->builder_->GetText()->Exists() |
| 483 | ? owner_->builder_->GetText()->GetAddress() |
| 484 | : 0; |
| 485 | const uintptr_t cu_size = compilation_unit.high_pc_ - compilation_unit.low_pc_; |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 486 | |
| 487 | info_.StartTag(DW_TAG_compile_unit); |
| 488 | info_.WriteStrp(DW_AT_producer, owner_->WriteString("Android dex2oat")); |
| 489 | info_.WriteData1(DW_AT_language, DW_LANG_Java); |
Tamas Berghammer | 8c55712 | 2015-12-10 15:06:25 +0000 | [diff] [blame] | 490 | info_.WriteStrp(DW_AT_comp_dir, owner_->WriteString("$JAVA_SRC_ROOT")); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 491 | info_.WriteAddr(DW_AT_low_pc, text_address + compilation_unit.low_pc_); |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 492 | info_.WriteUdata(DW_AT_high_pc, dchecked_integral_cast<uint32_t>(cu_size)); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 493 | info_.WriteSecOffset(DW_AT_stmt_list, compilation_unit.debug_line_offset_); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 494 | |
| 495 | const char* last_dex_class_desc = nullptr; |
| 496 | for (auto mi : compilation_unit.methods_) { |
| 497 | const DexFile* dex = mi->dex_file_; |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 498 | const DexFile::CodeItem* dex_code = mi->code_item_; |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 499 | const DexFile::MethodId& dex_method = dex->GetMethodId(mi->dex_method_index_); |
| 500 | const DexFile::ProtoId& dex_proto = dex->GetMethodPrototype(dex_method); |
| 501 | const DexFile::TypeList* dex_params = dex->GetProtoParameters(dex_proto); |
| 502 | const char* dex_class_desc = dex->GetMethodDeclaringClassDescriptor(dex_method); |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 503 | const bool is_static = (mi->access_flags_ & kAccStatic) != 0; |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 504 | |
| 505 | // Enclose the method in correct class definition. |
| 506 | if (last_dex_class_desc != dex_class_desc) { |
| 507 | if (last_dex_class_desc != nullptr) { |
| 508 | EndClassTag(last_dex_class_desc); |
| 509 | } |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 510 | // Write reference tag for the class we are about to declare. |
| 511 | size_t reference_tag_offset = info_.StartTag(DW_TAG_reference_type); |
| 512 | type_cache_.emplace(std::string(dex_class_desc), reference_tag_offset); |
| 513 | size_t type_attrib_offset = info_.size(); |
| 514 | info_.WriteRef4(DW_AT_type, 0); |
| 515 | info_.EndTag(); |
| 516 | // Declare the class that owns this method. |
| 517 | size_t class_offset = StartClassTag(dex_class_desc); |
| 518 | info_.UpdateUint32(type_attrib_offset, class_offset); |
| 519 | info_.WriteFlag(DW_AT_declaration, true); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 520 | // Check that each class is defined only once. |
| 521 | bool unique = owner_->defined_dex_classes_.insert(dex_class_desc).second; |
| 522 | CHECK(unique) << "Redefinition of " << dex_class_desc; |
| 523 | last_dex_class_desc = dex_class_desc; |
| 524 | } |
| 525 | |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 526 | int start_depth = info_.Depth(); |
| 527 | info_.StartTag(DW_TAG_subprogram); |
| 528 | WriteName(dex->GetMethodName(dex_method)); |
| 529 | info_.WriteAddr(DW_AT_low_pc, text_address + mi->low_pc_); |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 530 | info_.WriteUdata(DW_AT_high_pc, dchecked_integral_cast<uint32_t>(mi->high_pc_-mi->low_pc_)); |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 531 | std::vector<uint8_t> expr_buffer; |
| 532 | Expression expr(&expr_buffer); |
| 533 | expr.WriteOpCallFrameCfa(); |
| 534 | info_.WriteExprLoc(DW_AT_frame_base, expr); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 535 | WriteLazyType(dex->GetReturnTypeDescriptor(dex_proto)); |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 536 | |
| 537 | // Write parameters. DecodeDebugLocalInfo returns them as well, but it does not |
| 538 | // guarantee order or uniqueness so it is safer to iterate over them manually. |
| 539 | // DecodeDebugLocalInfo might not also be available if there is no debug info. |
| 540 | std::vector<const char*> param_names = GetParamNames(mi); |
| 541 | uint32_t arg_reg = 0; |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 542 | if (!is_static) { |
| 543 | info_.StartTag(DW_TAG_formal_parameter); |
| 544 | WriteName("this"); |
| 545 | info_.WriteFlag(DW_AT_artificial, true); |
| 546 | WriteLazyType(dex_class_desc); |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 547 | if (dex_code != nullptr) { |
| 548 | // Write the stack location of the parameter. |
| 549 | const uint32_t vreg = dex_code->registers_size_ - dex_code->ins_size_ + arg_reg; |
| 550 | const bool is64bitValue = false; |
| 551 | WriteRegLocation(mi, vreg, is64bitValue, compilation_unit.low_pc_); |
| 552 | } |
| 553 | arg_reg++; |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 554 | info_.EndTag(); |
| 555 | } |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 556 | if (dex_params != nullptr) { |
| 557 | for (uint32_t i = 0; i < dex_params->Size(); ++i) { |
| 558 | info_.StartTag(DW_TAG_formal_parameter); |
| 559 | // Parameter names may not be always available. |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 560 | if (i < param_names.size()) { |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 561 | WriteName(param_names[i]); |
| 562 | } |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 563 | // Write the type. |
| 564 | const char* type_desc = dex->StringByTypeIdx(dex_params->GetTypeItem(i).type_idx_); |
| 565 | WriteLazyType(type_desc); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 566 | const bool is64bitValue = type_desc[0] == 'D' || type_desc[0] == 'J'; |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 567 | if (dex_code != nullptr) { |
| 568 | // Write the stack location of the parameter. |
| 569 | const uint32_t vreg = dex_code->registers_size_ - dex_code->ins_size_ + arg_reg; |
| 570 | WriteRegLocation(mi, vreg, is64bitValue, compilation_unit.low_pc_); |
| 571 | } |
| 572 | arg_reg += is64bitValue ? 2 : 1; |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 573 | info_.EndTag(); |
| 574 | } |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 575 | if (dex_code != nullptr) { |
| 576 | DCHECK_EQ(arg_reg, dex_code->ins_size_); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 577 | } |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 578 | } |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 579 | |
| 580 | // Write local variables. |
| 581 | LocalInfos local_infos; |
| 582 | if (dex->DecodeDebugLocalInfo(dex_code, |
| 583 | is_static, |
| 584 | mi->dex_method_index_, |
| 585 | LocalInfoCallback, |
| 586 | &local_infos)) { |
| 587 | for (const DexFile::LocalInfo& var : local_infos) { |
| 588 | if (var.reg_ < dex_code->registers_size_ - dex_code->ins_size_) { |
| 589 | info_.StartTag(DW_TAG_variable); |
| 590 | WriteName(var.name_); |
| 591 | WriteLazyType(var.descriptor_); |
| 592 | bool is64bitValue = var.descriptor_[0] == 'D' || var.descriptor_[0] == 'J'; |
| 593 | WriteRegLocation(mi, var.reg_, is64bitValue, compilation_unit.low_pc_, |
| 594 | var.start_address_, var.end_address_); |
| 595 | info_.EndTag(); |
| 596 | } |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 597 | } |
| 598 | } |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 599 | |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 600 | info_.EndTag(); |
| 601 | CHECK_EQ(info_.Depth(), start_depth); // Balanced start/end. |
| 602 | } |
| 603 | if (last_dex_class_desc != nullptr) { |
| 604 | EndClassTag(last_dex_class_desc); |
| 605 | } |
| 606 | CHECK_EQ(info_.Depth(), 1); |
| 607 | FinishLazyTypes(); |
| 608 | info_.EndTag(); // DW_TAG_compile_unit |
| 609 | std::vector<uint8_t> buffer; |
| 610 | buffer.reserve(info_.data()->size() + KB); |
| 611 | const size_t offset = owner_->builder_->GetDebugInfo()->GetSize(); |
| 612 | const size_t debug_abbrev_offset = |
| 613 | owner_->debug_abbrev_.Insert(debug_abbrev_.data(), debug_abbrev_.size()); |
| 614 | WriteDebugInfoCU(debug_abbrev_offset, info_, offset, &buffer, &owner_->debug_info_patches_); |
| 615 | owner_->builder_->GetDebugInfo()->WriteFully(buffer.data(), buffer.size()); |
| 616 | } |
| 617 | |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 618 | void Write(const ArrayRef<mirror::Class*>& types) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 619 | info_.StartTag(DW_TAG_compile_unit); |
| 620 | info_.WriteStrp(DW_AT_producer, owner_->WriteString("Android dex2oat")); |
| 621 | info_.WriteData1(DW_AT_language, DW_LANG_Java); |
| 622 | |
David Srbecky | 9b3607d | 2016-01-14 18:15:54 +0000 | [diff] [blame] | 623 | std::vector<uint8_t> expr_buffer; |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 624 | for (mirror::Class* type : types) { |
| 625 | if (type->IsPrimitive()) { |
| 626 | // For primitive types the definition and the declaration is the same. |
| 627 | if (type->GetPrimitiveType() != Primitive::kPrimVoid) { |
| 628 | WriteTypeDeclaration(type->GetDescriptor(nullptr)); |
| 629 | } |
| 630 | } else if (type->IsArrayClass()) { |
| 631 | mirror::Class* element_type = type->GetComponentType(); |
| 632 | uint32_t component_size = type->GetComponentSize(); |
| 633 | uint32_t data_offset = mirror::Array::DataOffset(component_size).Uint32Value(); |
| 634 | uint32_t length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 635 | |
| 636 | info_.StartTag(DW_TAG_array_type); |
| 637 | std::string descriptor_string; |
| 638 | WriteLazyType(element_type->GetDescriptor(&descriptor_string)); |
David Srbecky | 9b3607d | 2016-01-14 18:15:54 +0000 | [diff] [blame] | 639 | WriteLinkageName(type); |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 640 | info_.WriteUdata(DW_AT_data_member_location, data_offset); |
| 641 | info_.StartTag(DW_TAG_subrange_type); |
David Srbecky | 9b3607d | 2016-01-14 18:15:54 +0000 | [diff] [blame] | 642 | Expression count_expr(&expr_buffer); |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 643 | count_expr.WriteOpPushObjectAddress(); |
| 644 | count_expr.WriteOpPlusUconst(length_offset); |
| 645 | count_expr.WriteOpDerefSize(4); // Array length is always 32-bit wide. |
| 646 | info_.WriteExprLoc(DW_AT_count, count_expr); |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 647 | info_.EndTag(); // DW_TAG_subrange_type. |
| 648 | info_.EndTag(); // DW_TAG_array_type. |
David Srbecky | 9b3607d | 2016-01-14 18:15:54 +0000 | [diff] [blame] | 649 | } else if (type->IsInterface()) { |
| 650 | // Skip. Variables cannot have an interface as a dynamic type. |
| 651 | // We do not expose the interface information to the debugger in any way. |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 652 | } else { |
David Srbecky | 9b3607d | 2016-01-14 18:15:54 +0000 | [diff] [blame] | 653 | // Declare base class. We can not use the standard WriteLazyType |
| 654 | // since we want to avoid the DW_TAG_reference_tag wrapping. |
| 655 | mirror::Class* base_class = type->GetSuperClass(); |
| 656 | size_t base_class_declaration_offset = 0; |
| 657 | if (base_class != nullptr) { |
| 658 | std::string tmp_storage; |
| 659 | const char* base_class_desc = base_class->GetDescriptor(&tmp_storage); |
| 660 | base_class_declaration_offset = StartClassTag(base_class_desc); |
| 661 | info_.WriteFlag(DW_AT_declaration, true); |
| 662 | WriteLinkageName(base_class); |
| 663 | EndClassTag(base_class_desc); |
| 664 | } |
| 665 | |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 666 | std::string descriptor_string; |
| 667 | const char* desc = type->GetDescriptor(&descriptor_string); |
| 668 | StartClassTag(desc); |
| 669 | |
| 670 | if (!type->IsVariableSize()) { |
| 671 | info_.WriteUdata(DW_AT_byte_size, type->GetObjectSize()); |
| 672 | } |
| 673 | |
David Srbecky | 9b3607d | 2016-01-14 18:15:54 +0000 | [diff] [blame] | 674 | WriteLinkageName(type); |
| 675 | |
| 676 | if (type->IsObjectClass()) { |
| 677 | // Generate artificial member which is used to get the dynamic type of variable. |
| 678 | // The run-time value of this field will correspond to linkage name of some type. |
| 679 | // We need to do it only once in j.l.Object since all other types inherit it. |
| 680 | info_.StartTag(DW_TAG_member); |
| 681 | WriteName(".dynamic_type"); |
| 682 | WriteLazyType(sizeof(uintptr_t) == 8 ? "J" : "I"); |
| 683 | info_.WriteFlag(DW_AT_artificial, true); |
| 684 | // Create DWARF expression to get the value of the methods_ field. |
| 685 | Expression expr(&expr_buffer); |
| 686 | // The address of the object has been implicitly pushed on the stack. |
| 687 | // Dereference the klass_ field of Object (32-bit; possibly poisoned). |
| 688 | DCHECK_EQ(type->ClassOffset().Uint32Value(), 0u); |
| 689 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Class>), 4u); |
| 690 | expr.WriteOpDerefSize(4); |
| 691 | if (kPoisonHeapReferences) { |
| 692 | expr.WriteOpNeg(); |
| 693 | // DWARF stack is pointer sized. Ensure that the high bits are clear. |
| 694 | expr.WriteOpConstu(0xFFFFFFFF); |
| 695 | expr.WriteOpAnd(); |
| 696 | } |
| 697 | // Add offset to the methods_ field. |
| 698 | expr.WriteOpPlusUconst(mirror::Class::MethodsOffset().Uint32Value()); |
| 699 | // Top of stack holds the location of the field now. |
| 700 | info_.WriteExprLoc(DW_AT_data_member_location, expr); |
| 701 | info_.EndTag(); // DW_TAG_member. |
| 702 | } |
| 703 | |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 704 | // Base class. |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 705 | if (base_class != nullptr) { |
| 706 | info_.StartTag(DW_TAG_inheritance); |
David Srbecky | 9b3607d | 2016-01-14 18:15:54 +0000 | [diff] [blame] | 707 | info_.WriteRef4(DW_AT_type, base_class_declaration_offset); |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 708 | info_.WriteUdata(DW_AT_data_member_location, 0); |
| 709 | info_.WriteSdata(DW_AT_accessibility, DW_ACCESS_public); |
| 710 | info_.EndTag(); // DW_TAG_inheritance. |
| 711 | } |
| 712 | |
| 713 | // Member variables. |
| 714 | for (uint32_t i = 0, count = type->NumInstanceFields(); i < count; ++i) { |
| 715 | ArtField* field = type->GetInstanceField(i); |
| 716 | info_.StartTag(DW_TAG_member); |
| 717 | WriteName(field->GetName()); |
| 718 | WriteLazyType(field->GetTypeDescriptor()); |
| 719 | info_.WriteUdata(DW_AT_data_member_location, field->GetOffset().Uint32Value()); |
| 720 | uint32_t access_flags = field->GetAccessFlags(); |
| 721 | if (access_flags & kAccPublic) { |
| 722 | info_.WriteSdata(DW_AT_accessibility, DW_ACCESS_public); |
| 723 | } else if (access_flags & kAccProtected) { |
| 724 | info_.WriteSdata(DW_AT_accessibility, DW_ACCESS_protected); |
| 725 | } else if (access_flags & kAccPrivate) { |
| 726 | info_.WriteSdata(DW_AT_accessibility, DW_ACCESS_private); |
| 727 | } |
| 728 | info_.EndTag(); // DW_TAG_member. |
| 729 | } |
| 730 | |
Tamas Berghammer | 03c941f | 2016-01-15 13:39:57 +0000 | [diff] [blame] | 731 | if (type->IsStringClass()) { |
| 732 | // Emit debug info about an artifical class member for java.lang.String which represents |
| 733 | // the first element of the data stored in a string instance. Consumers of the debug |
| 734 | // info will be able to read the content of java.lang.String based on the count (real |
| 735 | // field) and based on the location of this data member. |
| 736 | info_.StartTag(DW_TAG_member); |
| 737 | WriteName("value"); |
| 738 | // We don't support fields with C like array types so we just say its type is java char. |
| 739 | WriteLazyType("C"); // char. |
| 740 | info_.WriteUdata(DW_AT_data_member_location, |
| 741 | mirror::String::ValueOffset().Uint32Value()); |
| 742 | info_.WriteSdata(DW_AT_accessibility, DW_ACCESS_private); |
| 743 | info_.EndTag(); // DW_TAG_member. |
| 744 | } |
| 745 | |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 746 | EndClassTag(desc); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | CHECK_EQ(info_.Depth(), 1); |
| 751 | FinishLazyTypes(); |
| 752 | info_.EndTag(); // DW_TAG_compile_unit. |
| 753 | std::vector<uint8_t> buffer; |
| 754 | buffer.reserve(info_.data()->size() + KB); |
| 755 | const size_t offset = owner_->builder_->GetDebugInfo()->GetSize(); |
| 756 | const size_t debug_abbrev_offset = |
| 757 | owner_->debug_abbrev_.Insert(debug_abbrev_.data(), debug_abbrev_.size()); |
| 758 | WriteDebugInfoCU(debug_abbrev_offset, info_, offset, &buffer, &owner_->debug_info_patches_); |
| 759 | owner_->builder_->GetDebugInfo()->WriteFully(buffer.data(), buffer.size()); |
| 760 | } |
| 761 | |
David Srbecky | 9b3607d | 2016-01-14 18:15:54 +0000 | [diff] [blame] | 762 | // Linkage name uniquely identifies type. |
| 763 | // It is used to determine the dynamic type of objects. |
| 764 | // We use the methods_ field of class since it is unique and it is not moved by the GC. |
| 765 | void WriteLinkageName(mirror::Class* type) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 766 | auto* methods_ptr = type->GetMethodsPtr(); |
| 767 | if (methods_ptr == nullptr) { |
| 768 | // Some types might have no methods. Allocate empty array instead. |
| 769 | LinearAlloc* allocator = Runtime::Current()->GetLinearAlloc(); |
| 770 | void* storage = allocator->Alloc(Thread::Current(), sizeof(LengthPrefixedArray<ArtMethod>)); |
| 771 | methods_ptr = new (storage) LengthPrefixedArray<ArtMethod>(0); |
| 772 | type->SetMethodsPtr(methods_ptr, 0, 0); |
| 773 | DCHECK(type->GetMethodsPtr() != nullptr); |
| 774 | } |
| 775 | char name[32]; |
| 776 | snprintf(name, sizeof(name), "0x%" PRIXPTR, reinterpret_cast<uintptr_t>(methods_ptr)); |
| 777 | info_.WriteString(DW_AT_linkage_name, name); |
| 778 | } |
| 779 | |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 780 | // Write table into .debug_loc which describes location of dex register. |
| 781 | // The dex register might be valid only at some points and it might |
| 782 | // move between machine registers and stack. |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 783 | void WriteRegLocation(const MethodDebugInfo* method_info, |
| 784 | uint16_t vreg, |
| 785 | bool is64bitValue, |
| 786 | uint32_t compilation_unit_low_pc, |
| 787 | uint32_t dex_pc_low = 0, |
| 788 | uint32_t dex_pc_high = 0xFFFFFFFF) { |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 789 | using Kind = DexRegisterLocation::Kind; |
David Srbecky | f71b3ad | 2015-12-08 15:05:08 +0000 | [diff] [blame] | 790 | if (!IsFromOptimizingCompiler(method_info)) { |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 791 | return; |
| 792 | } |
| 793 | |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 794 | Writer<> debug_loc(&owner_->debug_loc_); |
| 795 | Writer<> debug_ranges(&owner_->debug_ranges_); |
| 796 | info_.WriteSecOffset(DW_AT_location, debug_loc.size()); |
| 797 | info_.WriteSecOffset(DW_AT_start_scope, debug_ranges.size()); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 798 | |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 799 | std::vector<VariableLocation> variable_locations = GetVariableLocations( |
| 800 | method_info, |
| 801 | vreg, |
| 802 | is64bitValue, |
| 803 | dex_pc_low, |
| 804 | dex_pc_high); |
| 805 | |
| 806 | // Write .debug_loc entries. |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 807 | const InstructionSet isa = owner_->builder_->GetIsa(); |
| 808 | const bool is64bit = Is64BitInstructionSet(isa); |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 809 | std::vector<uint8_t> expr_buffer; |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 810 | for (const VariableLocation& variable_location : variable_locations) { |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 811 | // Translate dex register location to DWARF expression. |
| 812 | // Note that 64-bit value might be split to two distinct locations. |
| 813 | // (for example, two 32-bit machine registers, or even stack and register) |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 814 | Expression expr(&expr_buffer); |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 815 | DexRegisterLocation reg_lo = variable_location.reg_lo; |
| 816 | DexRegisterLocation reg_hi = variable_location.reg_hi; |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 817 | for (int piece = 0; piece < (is64bitValue ? 2 : 1); piece++) { |
| 818 | DexRegisterLocation reg_loc = (piece == 0 ? reg_lo : reg_hi); |
| 819 | const Kind kind = reg_loc.GetKind(); |
| 820 | const int32_t value = reg_loc.GetValue(); |
| 821 | if (kind == Kind::kInStack) { |
| 822 | const size_t frame_size = method_info->compiled_method_->GetFrameSizeInBytes(); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 823 | // The stack offset is relative to SP. Make it relative to CFA. |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 824 | expr.WriteOpFbreg(value - frame_size); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 825 | if (piece == 0 && reg_hi.GetKind() == Kind::kInStack && |
| 826 | reg_hi.GetValue() == value + 4) { |
| 827 | break; // the high word is correctly implied by the low word. |
| 828 | } |
| 829 | } else if (kind == Kind::kInRegister) { |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 830 | expr.WriteOpReg(GetDwarfCoreReg(isa, value).num()); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 831 | if (piece == 0 && reg_hi.GetKind() == Kind::kInRegisterHigh && |
| 832 | reg_hi.GetValue() == value) { |
| 833 | break; // the high word is correctly implied by the low word. |
| 834 | } |
| 835 | } else if (kind == Kind::kInFpuRegister) { |
| 836 | if ((isa == kArm || isa == kThumb2) && |
| 837 | piece == 0 && reg_hi.GetKind() == Kind::kInFpuRegister && |
| 838 | reg_hi.GetValue() == value + 1 && value % 2 == 0) { |
| 839 | // Translate S register pair to D register (e.g. S4+S5 to D2). |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 840 | expr.WriteOpReg(Reg::ArmDp(value / 2).num()); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 841 | break; |
| 842 | } |
David Srbecky | 3dd7e5a | 2015-11-27 13:31:16 +0000 | [diff] [blame] | 843 | if (isa == kMips || isa == kMips64) { |
| 844 | // TODO: Find what the DWARF floating point register numbers are on MIPS. |
| 845 | break; |
| 846 | } |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 847 | expr.WriteOpReg(GetDwarfFpReg(isa, value).num()); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 848 | if (piece == 0 && reg_hi.GetKind() == Kind::kInFpuRegisterHigh && |
| 849 | reg_hi.GetValue() == reg_lo.GetValue()) { |
| 850 | break; // the high word is correctly implied by the low word. |
| 851 | } |
| 852 | } else if (kind == Kind::kConstant) { |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 853 | expr.WriteOpConsts(value); |
| 854 | expr.WriteOpStackValue(); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 855 | } else if (kind == Kind::kNone) { |
| 856 | break; |
| 857 | } else { |
| 858 | // kInStackLargeOffset and kConstantLargeValue are hidden by GetKind(). |
| 859 | // kInRegisterHigh and kInFpuRegisterHigh should be handled by |
| 860 | // the special cases above and they should not occur alone. |
| 861 | LOG(ERROR) << "Unexpected register location kind: " |
| 862 | << DexRegisterLocation::PrettyDescriptor(kind); |
| 863 | break; |
| 864 | } |
| 865 | if (is64bitValue) { |
| 866 | // Write the marker which is needed by split 64-bit values. |
| 867 | // This code is skipped by the special cases. |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 868 | expr.WriteOpPiece(4); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 872 | if (expr.size() > 0) { |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 873 | if (is64bit) { |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 874 | debug_loc.PushUint64(variable_location.low_pc - compilation_unit_low_pc); |
| 875 | debug_loc.PushUint64(variable_location.high_pc - compilation_unit_low_pc); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 876 | } else { |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 877 | debug_loc.PushUint32(variable_location.low_pc - compilation_unit_low_pc); |
| 878 | debug_loc.PushUint32(variable_location.high_pc - compilation_unit_low_pc); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 879 | } |
| 880 | // Write the expression. |
David Srbecky | 91cb54e | 2016-01-15 13:47:59 +0000 | [diff] [blame] | 881 | debug_loc.PushUint16(expr.size()); |
| 882 | debug_loc.PushData(expr.data()); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 883 | } else { |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 884 | // Do not generate .debug_loc if the location is not known. |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | // Write end-of-list entry. |
| 888 | if (is64bit) { |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 889 | debug_loc.PushUint64(0); |
| 890 | debug_loc.PushUint64(0); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 891 | } else { |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 892 | debug_loc.PushUint32(0); |
| 893 | debug_loc.PushUint32(0); |
| 894 | } |
| 895 | |
| 896 | // Write .debug_ranges entries. |
| 897 | // This includes ranges where the variable is in scope but the location is not known. |
| 898 | for (size_t i = 0; i < variable_locations.size(); i++) { |
| 899 | uint32_t low_pc = variable_locations[i].low_pc; |
| 900 | uint32_t high_pc = variable_locations[i].high_pc; |
| 901 | while (i + 1 < variable_locations.size() && variable_locations[i+1].low_pc == high_pc) { |
| 902 | // Merge address range with the next entry. |
| 903 | high_pc = variable_locations[++i].high_pc; |
| 904 | } |
| 905 | if (is64bit) { |
| 906 | debug_ranges.PushUint64(low_pc - compilation_unit_low_pc); |
| 907 | debug_ranges.PushUint64(high_pc - compilation_unit_low_pc); |
| 908 | } else { |
| 909 | debug_ranges.PushUint32(low_pc - compilation_unit_low_pc); |
| 910 | debug_ranges.PushUint32(high_pc - compilation_unit_low_pc); |
| 911 | } |
| 912 | } |
| 913 | // Write end-of-list entry. |
| 914 | if (is64bit) { |
| 915 | debug_ranges.PushUint64(0); |
| 916 | debug_ranges.PushUint64(0); |
| 917 | } else { |
| 918 | debug_ranges.PushUint32(0); |
| 919 | debug_ranges.PushUint32(0); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 920 | } |
| 921 | } |
| 922 | |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 923 | // Some types are difficult to define as we go since they need |
| 924 | // to be enclosed in the right set of namespaces. Therefore we |
| 925 | // just define all types lazily at the end of compilation unit. |
| 926 | void WriteLazyType(const char* type_descriptor) { |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 927 | if (type_descriptor != nullptr && type_descriptor[0] != 'V') { |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 928 | lazy_types_.emplace(std::string(type_descriptor), info_.size()); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 929 | info_.WriteRef4(DW_AT_type, 0); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | void FinishLazyTypes() { |
| 934 | for (const auto& lazy_type : lazy_types_) { |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 935 | info_.UpdateUint32(lazy_type.second, WriteTypeDeclaration(lazy_type.first)); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 936 | } |
| 937 | lazy_types_.clear(); |
| 938 | } |
| 939 | |
| 940 | private: |
| 941 | void WriteName(const char* name) { |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 942 | if (name != nullptr) { |
| 943 | info_.WriteStrp(DW_AT_name, owner_->WriteString(name)); |
| 944 | } |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | // Convert dex type descriptor to DWARF. |
| 948 | // Returns offset in the compilation unit. |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 949 | size_t WriteTypeDeclaration(const std::string& desc) { |
| 950 | DCHECK(!desc.empty()); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 951 | const auto& it = type_cache_.find(desc); |
| 952 | if (it != type_cache_.end()) { |
| 953 | return it->second; |
| 954 | } |
| 955 | |
| 956 | size_t offset; |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 957 | if (desc[0] == 'L') { |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 958 | // Class type. For example: Lpackage/name; |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 959 | size_t class_offset = StartClassTag(desc.c_str()); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 960 | info_.WriteFlag(DW_AT_declaration, true); |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 961 | EndClassTag(desc.c_str()); |
| 962 | // Reference to the class type. |
| 963 | offset = info_.StartTag(DW_TAG_reference_type); |
| 964 | info_.WriteRef(DW_AT_type, class_offset); |
| 965 | info_.EndTag(); |
| 966 | } else if (desc[0] == '[') { |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 967 | // Array type. |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 968 | size_t element_type = WriteTypeDeclaration(desc.substr(1)); |
| 969 | size_t array_type = info_.StartTag(DW_TAG_array_type); |
| 970 | info_.WriteFlag(DW_AT_declaration, true); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 971 | info_.WriteRef(DW_AT_type, element_type); |
| 972 | info_.EndTag(); |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 973 | offset = info_.StartTag(DW_TAG_reference_type); |
| 974 | info_.WriteRef4(DW_AT_type, array_type); |
| 975 | info_.EndTag(); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 976 | } else { |
| 977 | // Primitive types. |
Tamas Berghammer | 03c941f | 2016-01-15 13:39:57 +0000 | [diff] [blame] | 978 | DCHECK_EQ(desc.size(), 1u); |
| 979 | |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 980 | const char* name; |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 981 | uint32_t encoding; |
| 982 | uint32_t byte_size; |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 983 | switch (desc[0]) { |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 984 | case 'B': |
| 985 | name = "byte"; |
| 986 | encoding = DW_ATE_signed; |
| 987 | byte_size = 1; |
| 988 | break; |
| 989 | case 'C': |
| 990 | name = "char"; |
| 991 | encoding = DW_ATE_UTF; |
| 992 | byte_size = 2; |
| 993 | break; |
| 994 | case 'D': |
| 995 | name = "double"; |
| 996 | encoding = DW_ATE_float; |
| 997 | byte_size = 8; |
| 998 | break; |
| 999 | case 'F': |
| 1000 | name = "float"; |
| 1001 | encoding = DW_ATE_float; |
| 1002 | byte_size = 4; |
| 1003 | break; |
| 1004 | case 'I': |
| 1005 | name = "int"; |
| 1006 | encoding = DW_ATE_signed; |
| 1007 | byte_size = 4; |
| 1008 | break; |
| 1009 | case 'J': |
| 1010 | name = "long"; |
| 1011 | encoding = DW_ATE_signed; |
| 1012 | byte_size = 8; |
| 1013 | break; |
| 1014 | case 'S': |
| 1015 | name = "short"; |
| 1016 | encoding = DW_ATE_signed; |
| 1017 | byte_size = 2; |
| 1018 | break; |
| 1019 | case 'Z': |
| 1020 | name = "boolean"; |
| 1021 | encoding = DW_ATE_boolean; |
| 1022 | byte_size = 1; |
| 1023 | break; |
| 1024 | case 'V': |
| 1025 | LOG(FATAL) << "Void type should not be encoded"; |
| 1026 | UNREACHABLE(); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1027 | default: |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1028 | LOG(FATAL) << "Unknown dex type descriptor: \"" << desc << "\""; |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1029 | UNREACHABLE(); |
| 1030 | } |
| 1031 | offset = info_.StartTag(DW_TAG_base_type); |
| 1032 | WriteName(name); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 1033 | info_.WriteData1(DW_AT_encoding, encoding); |
| 1034 | info_.WriteData1(DW_AT_byte_size, byte_size); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1035 | info_.EndTag(); |
| 1036 | } |
| 1037 | |
| 1038 | type_cache_.emplace(desc, offset); |
| 1039 | return offset; |
| 1040 | } |
| 1041 | |
| 1042 | // Start DW_TAG_class_type tag nested in DW_TAG_namespace tags. |
| 1043 | // Returns offset of the class tag in the compilation unit. |
| 1044 | size_t StartClassTag(const char* desc) { |
| 1045 | DCHECK(desc != nullptr && desc[0] == 'L'); |
| 1046 | // Enclose the type in namespace tags. |
| 1047 | const char* end; |
| 1048 | for (desc = desc + 1; (end = strchr(desc, '/')) != nullptr; desc = end + 1) { |
| 1049 | info_.StartTag(DW_TAG_namespace); |
| 1050 | WriteName(std::string(desc, end - desc).c_str()); |
| 1051 | } |
| 1052 | // Start the class tag. |
| 1053 | size_t offset = info_.StartTag(DW_TAG_class_type); |
| 1054 | end = strchr(desc, ';'); |
| 1055 | CHECK(end != nullptr); |
| 1056 | WriteName(std::string(desc, end - desc).c_str()); |
| 1057 | return offset; |
| 1058 | } |
| 1059 | |
| 1060 | void EndClassTag(const char* desc) { |
| 1061 | DCHECK(desc != nullptr && desc[0] == 'L'); |
| 1062 | // End the class tag. |
| 1063 | info_.EndTag(); |
| 1064 | // Close namespace tags. |
| 1065 | const char* end; |
| 1066 | for (desc = desc + 1; (end = strchr(desc, '/')) != nullptr; desc = end + 1) { |
| 1067 | info_.EndTag(); |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | // For access to the ELF sections. |
| 1072 | DebugInfoWriter<ElfTypes>* owner_; |
| 1073 | // Debug abbrevs for this compilation unit only. |
| 1074 | std::vector<uint8_t> debug_abbrev_; |
| 1075 | // Temporary buffer to create and store the entries. |
| 1076 | DebugInfoEntryWriter<> info_; |
| 1077 | // Cache of already translated type descriptors. |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1078 | std::map<std::string, size_t> type_cache_; // type_desc -> definition_offset. |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1079 | // 32-bit references which need to be resolved to a type later. |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1080 | // Given type may be used multiple times. Therefore we need a multimap. |
| 1081 | std::multimap<std::string, size_t> lazy_types_; // type_desc -> patch_offset. |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1082 | }; |
| 1083 | |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1084 | public: |
| 1085 | explicit DebugInfoWriter(ElfBuilder<ElfTypes>* builder) : builder_(builder) { |
David Srbecky | 626a166 | 2015-04-12 13:12:26 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1088 | void Start() { |
| 1089 | builder_->GetDebugInfo()->Start(); |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1090 | } |
| 1091 | |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1092 | void WriteCompilationUnit(const CompilationUnit& compilation_unit) { |
| 1093 | CompilationUnitWriter writer(this); |
| 1094 | writer.Write(compilation_unit); |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1095 | } |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1096 | |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1097 | void WriteTypes(const ArrayRef<mirror::Class*>& types) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1098 | CompilationUnitWriter writer(this); |
| 1099 | writer.Write(types); |
| 1100 | } |
| 1101 | |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1102 | void End() { |
| 1103 | builder_->GetDebugInfo()->End(); |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 1104 | builder_->WritePatches(".debug_info.oat_patches", |
| 1105 | ArrayRef<const uintptr_t>(debug_info_patches_)); |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1106 | builder_->WriteSection(".debug_abbrev", &debug_abbrev_.Data()); |
| 1107 | builder_->WriteSection(".debug_str", &debug_str_.Data()); |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 1108 | builder_->WriteSection(".debug_loc", &debug_loc_); |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 1109 | builder_->WriteSection(".debug_ranges", &debug_ranges_); |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | private: |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1113 | size_t WriteString(const char* str) { |
| 1114 | return debug_str_.Insert(reinterpret_cast<const uint8_t*>(str), strlen(str) + 1); |
| 1115 | } |
| 1116 | |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1117 | ElfBuilder<ElfTypes>* builder_; |
| 1118 | std::vector<uintptr_t> debug_info_patches_; |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1119 | DedupVector debug_abbrev_; |
| 1120 | DedupVector debug_str_; |
David Srbecky | 0fd295f | 2015-11-16 16:39:10 +0000 | [diff] [blame] | 1121 | std::vector<uint8_t> debug_loc_; |
David Srbecky | 996ed0b | 2015-11-27 10:27:11 +0000 | [diff] [blame] | 1122 | std::vector<uint8_t> debug_ranges_; |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1123 | |
| 1124 | std::unordered_set<const char*> defined_dex_classes_; // For CHECKs only. |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1125 | }; |
| 1126 | |
| 1127 | template<typename ElfTypes> |
| 1128 | class DebugLineWriter { |
| 1129 | typedef typename ElfTypes::Addr Elf_Addr; |
| 1130 | |
| 1131 | public: |
| 1132 | explicit DebugLineWriter(ElfBuilder<ElfTypes>* builder) : builder_(builder) { |
| 1133 | } |
| 1134 | |
| 1135 | void Start() { |
| 1136 | builder_->GetDebugLine()->Start(); |
| 1137 | } |
| 1138 | |
| 1139 | // Write line table for given set of methods. |
| 1140 | // Returns the number of bytes written. |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1141 | size_t WriteCompilationUnit(CompilationUnit& compilation_unit) { |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1142 | const bool is64bit = Is64BitInstructionSet(builder_->GetIsa()); |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 1143 | const Elf_Addr text_address = builder_->GetText()->Exists() |
| 1144 | ? builder_->GetText()->GetAddress() |
| 1145 | : 0; |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1146 | |
| 1147 | compilation_unit.debug_line_offset_ = builder_->GetDebugLine()->GetSize(); |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1148 | |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1149 | std::vector<FileEntry> files; |
| 1150 | std::unordered_map<std::string, size_t> files_map; |
| 1151 | std::vector<std::string> directories; |
| 1152 | std::unordered_map<std::string, size_t> directories_map; |
| 1153 | int code_factor_bits_ = 0; |
| 1154 | int dwarf_isa = -1; |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1155 | switch (builder_->GetIsa()) { |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1156 | case kArm: // arm actually means thumb2. |
| 1157 | case kThumb2: |
| 1158 | code_factor_bits_ = 1; // 16-bit instuctions |
| 1159 | dwarf_isa = 1; // DW_ISA_ARM_thumb. |
| 1160 | break; |
| 1161 | case kArm64: |
| 1162 | case kMips: |
| 1163 | case kMips64: |
| 1164 | code_factor_bits_ = 2; // 32-bit instructions |
| 1165 | break; |
| 1166 | case kNone: |
| 1167 | case kX86: |
| 1168 | case kX86_64: |
| 1169 | break; |
| 1170 | } |
David Srbecky | 297ed22 | 2015-04-15 01:18:12 +0100 | [diff] [blame] | 1171 | DebugLineOpCodeWriter<> opcodes(is64bit, code_factor_bits_); |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 1172 | for (const MethodDebugInfo* mi : compilation_unit.methods_) { |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1173 | // Ignore function if we have already generated line table for the same address. |
| 1174 | // It would confuse the debugger and the DWARF specification forbids it. |
| 1175 | if (mi->deduped_) { |
| 1176 | continue; |
| 1177 | } |
| 1178 | |
David Srbecky | f71b3ad | 2015-12-08 15:05:08 +0000 | [diff] [blame] | 1179 | ArrayRef<const SrcMapElem> src_mapping_table; |
| 1180 | std::vector<SrcMapElem> src_mapping_table_from_stack_maps; |
| 1181 | if (IsFromOptimizingCompiler(mi)) { |
| 1182 | // Use stack maps to create mapping table from pc to dex. |
| 1183 | const CodeInfo code_info(mi->compiled_method_->GetVmapTable().data()); |
| 1184 | const StackMapEncoding encoding = code_info.ExtractEncoding(); |
| 1185 | for (uint32_t s = 0; s < code_info.GetNumberOfStackMaps(); s++) { |
| 1186 | StackMap stack_map = code_info.GetStackMapAt(s, encoding); |
| 1187 | DCHECK(stack_map.IsValid()); |
David Srbecky | 4f50ee2 | 2016-01-25 17:00:24 +0000 | [diff] [blame] | 1188 | // Emit only locations where we have local-variable information. |
| 1189 | // In particular, skip mappings inside the prologue. |
| 1190 | if (stack_map.HasDexRegisterMap(encoding)) { |
| 1191 | const uint32_t pc = stack_map.GetNativePcOffset(encoding); |
| 1192 | const int32_t dex = stack_map.GetDexPc(encoding); |
| 1193 | src_mapping_table_from_stack_maps.push_back({pc, dex}); |
| 1194 | } |
David Srbecky | f71b3ad | 2015-12-08 15:05:08 +0000 | [diff] [blame] | 1195 | } |
| 1196 | std::sort(src_mapping_table_from_stack_maps.begin(), |
| 1197 | src_mapping_table_from_stack_maps.end()); |
| 1198 | src_mapping_table = ArrayRef<const SrcMapElem>(src_mapping_table_from_stack_maps); |
| 1199 | } else { |
| 1200 | // Use the mapping table provided by the quick compiler. |
| 1201 | src_mapping_table = mi->compiled_method_->GetSrcMappingTable(); |
| 1202 | } |
| 1203 | |
| 1204 | if (src_mapping_table.empty()) { |
| 1205 | continue; |
| 1206 | } |
| 1207 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 1208 | Elf_Addr method_address = text_address + mi->low_pc_; |
| 1209 | |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1210 | PositionInfos position_infos; |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1211 | const DexFile* dex = mi->dex_file_; |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1212 | if (!dex->DecodeDebugPositionInfo(mi->code_item_, PositionInfoCallback, &position_infos)) { |
| 1213 | continue; |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1214 | } |
| 1215 | |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1216 | if (position_infos.empty()) { |
David Srbecky | f71b3ad | 2015-12-08 15:05:08 +0000 | [diff] [blame] | 1217 | continue; |
| 1218 | } |
| 1219 | |
| 1220 | opcodes.SetAddress(method_address); |
| 1221 | if (dwarf_isa != -1) { |
| 1222 | opcodes.SetISA(dwarf_isa); |
| 1223 | } |
| 1224 | |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1225 | // Get and deduplicate directory and filename. |
| 1226 | int file_index = 0; // 0 - primary source file of the compilation. |
| 1227 | auto& dex_class_def = dex->GetClassDef(mi->class_def_index_); |
| 1228 | const char* source_file = dex->GetSourceFile(dex_class_def); |
| 1229 | if (source_file != nullptr) { |
| 1230 | std::string file_name(source_file); |
| 1231 | size_t file_name_slash = file_name.find_last_of('/'); |
| 1232 | std::string class_name(dex->GetClassDescriptor(dex_class_def)); |
| 1233 | size_t class_name_slash = class_name.find_last_of('/'); |
| 1234 | std::string full_path(file_name); |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1235 | |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1236 | // Guess directory from package name. |
| 1237 | int directory_index = 0; // 0 - current directory of the compilation. |
| 1238 | if (file_name_slash == std::string::npos && // Just filename. |
| 1239 | class_name.front() == 'L' && // Type descriptor for a class. |
| 1240 | class_name_slash != std::string::npos) { // Has package name. |
| 1241 | std::string package_name = class_name.substr(1, class_name_slash - 1); |
| 1242 | auto it = directories_map.find(package_name); |
| 1243 | if (it == directories_map.end()) { |
| 1244 | directory_index = 1 + directories.size(); |
| 1245 | directories_map.emplace(package_name, directory_index); |
| 1246 | directories.push_back(package_name); |
| 1247 | } else { |
| 1248 | directory_index = it->second; |
| 1249 | } |
| 1250 | full_path = package_name + "/" + file_name; |
| 1251 | } |
| 1252 | |
| 1253 | // Add file entry. |
| 1254 | auto it2 = files_map.find(full_path); |
| 1255 | if (it2 == files_map.end()) { |
| 1256 | file_index = 1 + files.size(); |
| 1257 | files_map.emplace(full_path, file_index); |
| 1258 | files.push_back(FileEntry { |
| 1259 | file_name, |
| 1260 | directory_index, |
| 1261 | 0, // Modification time - NA. |
| 1262 | 0, // File size - NA. |
| 1263 | }); |
| 1264 | } else { |
| 1265 | file_index = it2->second; |
| 1266 | } |
| 1267 | } |
| 1268 | opcodes.SetFile(file_index); |
| 1269 | |
| 1270 | // Generate mapping opcodes from PC to Java lines. |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1271 | if (file_index != 0) { |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1272 | bool first = true; |
David Srbecky | f71b3ad | 2015-12-08 15:05:08 +0000 | [diff] [blame] | 1273 | for (SrcMapElem pc2dex : src_mapping_table) { |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1274 | uint32_t pc = pc2dex.from_; |
| 1275 | int dex_pc = pc2dex.to_; |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1276 | // Find mapping with address with is greater than our dex pc; then go back one step. |
| 1277 | auto ub = std::upper_bound(position_infos.begin(), position_infos.end(), dex_pc, |
| 1278 | [](uint32_t address, const DexFile::PositionInfo& entry) { |
| 1279 | return address < entry.address_; |
| 1280 | }); |
| 1281 | if (ub != position_infos.begin()) { |
| 1282 | int line = (--ub)->line_; |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1283 | if (first) { |
| 1284 | first = false; |
| 1285 | if (pc > 0) { |
| 1286 | // Assume that any preceding code is prologue. |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1287 | int first_line = position_infos.front().line_; |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1288 | // Prologue is not a sensible place for a breakpoint. |
| 1289 | opcodes.NegateStmt(); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 1290 | opcodes.AddRow(method_address, first_line); |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1291 | opcodes.NegateStmt(); |
| 1292 | opcodes.SetPrologueEnd(); |
| 1293 | } |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 1294 | opcodes.AddRow(method_address + pc, line); |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1295 | } else if (line != opcodes.CurrentLine()) { |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 1296 | opcodes.AddRow(method_address + pc, line); |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1297 | } |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1298 | } |
| 1299 | } |
David Srbecky | 799b8c4 | 2015-04-14 01:57:43 +0100 | [diff] [blame] | 1300 | } else { |
| 1301 | // line 0 - instruction cannot be attributed to any source line. |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 1302 | opcodes.AddRow(method_address, 0); |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1303 | } |
David Srbecky | f71b3ad | 2015-12-08 15:05:08 +0000 | [diff] [blame] | 1304 | |
| 1305 | opcodes.AdvancePC(text_address + mi->high_pc_); |
| 1306 | opcodes.EndSequence(); |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1307 | } |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1308 | std::vector<uint8_t> buffer; |
| 1309 | buffer.reserve(opcodes.data()->size() + KB); |
| 1310 | size_t offset = builder_->GetDebugLine()->GetSize(); |
| 1311 | WriteDebugLineTable(directories, files, opcodes, offset, &buffer, &debug_line_patches); |
| 1312 | builder_->GetDebugLine()->WriteFully(buffer.data(), buffer.size()); |
| 1313 | return buffer.size(); |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1314 | } |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1315 | |
| 1316 | void End() { |
| 1317 | builder_->GetDebugLine()->End(); |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 1318 | builder_->WritePatches(".debug_line.oat_patches", |
| 1319 | ArrayRef<const uintptr_t>(debug_line_patches)); |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | private: |
| 1323 | ElfBuilder<ElfTypes>* builder_; |
| 1324 | std::vector<uintptr_t> debug_line_patches; |
| 1325 | }; |
| 1326 | |
| 1327 | template<typename ElfTypes> |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1328 | static void WriteDebugSections(ElfBuilder<ElfTypes>* builder, |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1329 | const ArrayRef<const MethodDebugInfo>& method_infos) { |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1330 | // Group the methods into compilation units based on source file. |
| 1331 | std::vector<CompilationUnit> compilation_units; |
| 1332 | const char* last_source_file = nullptr; |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 1333 | for (const MethodDebugInfo& mi : method_infos) { |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1334 | auto& dex_class_def = mi.dex_file_->GetClassDef(mi.class_def_index_); |
| 1335 | const char* source_file = mi.dex_file_->GetSourceFile(dex_class_def); |
| 1336 | if (compilation_units.empty() || source_file != last_source_file) { |
| 1337 | compilation_units.push_back(CompilationUnit()); |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1338 | } |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1339 | CompilationUnit& cu = compilation_units.back(); |
| 1340 | cu.methods_.push_back(&mi); |
| 1341 | cu.low_pc_ = std::min(cu.low_pc_, mi.low_pc_); |
| 1342 | cu.high_pc_ = std::max(cu.high_pc_, mi.high_pc_); |
| 1343 | last_source_file = source_file; |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | // Write .debug_line section. |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1347 | if (!compilation_units.empty()) { |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1348 | DebugLineWriter<ElfTypes> line_writer(builder); |
| 1349 | line_writer.Start(); |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1350 | for (auto& compilation_unit : compilation_units) { |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1351 | line_writer.WriteCompilationUnit(compilation_unit); |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1352 | } |
| 1353 | line_writer.End(); |
| 1354 | } |
| 1355 | |
| 1356 | // Write .debug_info section. |
Tamas Berghammer | fffbee4 | 2016-01-15 13:09:34 +0000 | [diff] [blame] | 1357 | if (!compilation_units.empty()) { |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1358 | DebugInfoWriter<ElfTypes> info_writer(builder); |
| 1359 | info_writer.Start(); |
| 1360 | for (const auto& compilation_unit : compilation_units) { |
David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 1361 | info_writer.WriteCompilationUnit(compilation_unit); |
David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 1362 | } |
| 1363 | info_writer.End(); |
| 1364 | } |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1365 | } |
| 1366 | |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1367 | template <typename ElfTypes> |
David Srbecky | 5288611 | 2016-01-22 13:56:47 +0000 | [diff] [blame] | 1368 | static void WriteDebugSymbols(ElfBuilder<ElfTypes>* builder, |
| 1369 | const ArrayRef<const MethodDebugInfo>& method_infos, |
| 1370 | bool with_signature) { |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1371 | bool generated_mapping_symbol = false; |
| 1372 | auto* strtab = builder->GetStrTab(); |
| 1373 | auto* symtab = builder->GetSymTab(); |
| 1374 | |
| 1375 | if (method_infos.empty()) { |
| 1376 | return; |
| 1377 | } |
| 1378 | |
| 1379 | // Find all addresses (low_pc) which contain deduped methods. |
| 1380 | // The first instance of method is not marked deduped_, but the rest is. |
| 1381 | std::unordered_set<uint32_t> deduped_addresses; |
| 1382 | for (const MethodDebugInfo& info : method_infos) { |
| 1383 | if (info.deduped_) { |
| 1384 | deduped_addresses.insert(info.low_pc_); |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | strtab->Start(); |
| 1389 | strtab->Write(""); // strtab should start with empty string. |
David Srbecky | 5288611 | 2016-01-22 13:56:47 +0000 | [diff] [blame] | 1390 | std::string last_name; |
| 1391 | size_t last_name_offset = 0; |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1392 | for (const MethodDebugInfo& info : method_infos) { |
| 1393 | if (info.deduped_) { |
| 1394 | continue; // Add symbol only for the first instance. |
| 1395 | } |
David Srbecky | 5288611 | 2016-01-22 13:56:47 +0000 | [diff] [blame] | 1396 | std::string name = PrettyMethod(info.dex_method_index_, *info.dex_file_, with_signature); |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1397 | if (deduped_addresses.find(info.low_pc_) != deduped_addresses.end()) { |
| 1398 | name += " [DEDUPED]"; |
| 1399 | } |
David Srbecky | 5288611 | 2016-01-22 13:56:47 +0000 | [diff] [blame] | 1400 | // If we write method names without signature, we might see the same name multiple times. |
| 1401 | size_t name_offset = (name == last_name ? last_name_offset : strtab->Write(name)); |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1402 | |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 1403 | const auto* text = builder->GetText()->Exists() ? builder->GetText() : nullptr; |
| 1404 | const bool is_relative = (text != nullptr); |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1405 | uint32_t low_pc = info.low_pc_; |
| 1406 | // Add in code delta, e.g., thumb bit 0 for Thumb2 code. |
| 1407 | low_pc += info.compiled_method_->CodeDelta(); |
David Srbecky | 5288611 | 2016-01-22 13:56:47 +0000 | [diff] [blame] | 1408 | symtab->Add(name_offset, |
| 1409 | text, |
| 1410 | low_pc, |
| 1411 | is_relative, |
| 1412 | info.high_pc_ - info.low_pc_, |
| 1413 | STB_GLOBAL, |
| 1414 | STT_FUNC); |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1415 | |
| 1416 | // Conforming to aaelf, add $t mapping symbol to indicate start of a sequence of thumb2 |
| 1417 | // instructions, so that disassembler tools can correctly disassemble. |
| 1418 | // Note that even if we generate just a single mapping symbol, ARM's Streamline |
| 1419 | // requires it to match function symbol. Just address 0 does not work. |
| 1420 | if (info.compiled_method_->GetInstructionSet() == kThumb2) { |
| 1421 | if (!generated_mapping_symbol || !kGenerateSingleArmMappingSymbol) { |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 1422 | symtab->Add(strtab->Write("$t"), text, info.low_pc_ & ~1, |
| 1423 | is_relative, 0, STB_LOCAL, STT_NOTYPE); |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1424 | generated_mapping_symbol = true; |
| 1425 | } |
| 1426 | } |
David Srbecky | 5288611 | 2016-01-22 13:56:47 +0000 | [diff] [blame] | 1427 | |
| 1428 | last_name = std::move(name); |
| 1429 | last_name_offset = name_offset; |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1430 | } |
| 1431 | strtab->End(); |
| 1432 | |
| 1433 | // Symbols are buffered and written after names (because they are smaller). |
| 1434 | // We could also do two passes in this function to avoid the buffering. |
| 1435 | symtab->Start(); |
| 1436 | symtab->Write(); |
| 1437 | symtab->End(); |
| 1438 | } |
| 1439 | |
| 1440 | template <typename ElfTypes> |
| 1441 | void WriteDebugInfo(ElfBuilder<ElfTypes>* builder, |
| 1442 | const ArrayRef<const MethodDebugInfo>& method_infos, |
| 1443 | CFIFormat cfi_format) { |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1444 | // Add methods to .symtab. |
David Srbecky | 5288611 | 2016-01-22 13:56:47 +0000 | [diff] [blame] | 1445 | WriteDebugSymbols(builder, method_infos, true /* with_signature */); |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1446 | // Generate CFI (stack unwinding information). |
David Srbecky | 5e974a6 | 2016-01-22 14:25:03 +0000 | [diff] [blame] | 1447 | WriteCFISection(builder, method_infos, cfi_format, true /* write_oat_patches */); |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1448 | // Write DWARF .debug_* sections. |
Tamas Berghammer | fffbee4 | 2016-01-15 13:09:34 +0000 | [diff] [blame] | 1449 | WriteDebugSections(builder, method_infos); |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame] | 1452 | static void XzCompress(const std::vector<uint8_t>* src, std::vector<uint8_t>* dst) { |
| 1453 | // Configure the compression library. |
| 1454 | CrcGenerateTable(); |
| 1455 | Crc64GenerateTable(); |
| 1456 | CLzma2EncProps lzma2Props; |
| 1457 | Lzma2EncProps_Init(&lzma2Props); |
| 1458 | lzma2Props.lzmaProps.level = 1; // Fast compression. |
| 1459 | Lzma2EncProps_Normalize(&lzma2Props); |
| 1460 | CXzProps props; |
| 1461 | XzProps_Init(&props); |
| 1462 | props.lzma2Props = &lzma2Props; |
| 1463 | // Implement the required interface for communication (written in C so no virtual methods). |
| 1464 | struct XzCallbacks : public ISeqInStream, public ISeqOutStream, public ICompressProgress { |
| 1465 | static SRes ReadImpl(void* p, void* buf, size_t* size) { |
| 1466 | auto* ctx = static_cast<XzCallbacks*>(reinterpret_cast<ISeqInStream*>(p)); |
| 1467 | *size = std::min(*size, ctx->src_->size() - ctx->src_pos_); |
| 1468 | memcpy(buf, ctx->src_->data() + ctx->src_pos_, *size); |
| 1469 | ctx->src_pos_ += *size; |
| 1470 | return SZ_OK; |
| 1471 | } |
| 1472 | static size_t WriteImpl(void* p, const void* buf, size_t size) { |
| 1473 | auto* ctx = static_cast<XzCallbacks*>(reinterpret_cast<ISeqOutStream*>(p)); |
| 1474 | const uint8_t* buffer = reinterpret_cast<const uint8_t*>(buf); |
| 1475 | ctx->dst_->insert(ctx->dst_->end(), buffer, buffer + size); |
| 1476 | return size; |
| 1477 | } |
| 1478 | static SRes ProgressImpl(void* , UInt64, UInt64) { |
| 1479 | return SZ_OK; |
| 1480 | } |
| 1481 | size_t src_pos_; |
| 1482 | const std::vector<uint8_t>* src_; |
| 1483 | std::vector<uint8_t>* dst_; |
| 1484 | }; |
| 1485 | XzCallbacks callbacks; |
| 1486 | callbacks.Read = XzCallbacks::ReadImpl; |
| 1487 | callbacks.Write = XzCallbacks::WriteImpl; |
| 1488 | callbacks.Progress = XzCallbacks::ProgressImpl; |
| 1489 | callbacks.src_pos_ = 0; |
| 1490 | callbacks.src_ = src; |
| 1491 | callbacks.dst_ = dst; |
| 1492 | // Compress. |
| 1493 | SRes res = Xz_Encode(&callbacks, &callbacks, &props, &callbacks); |
| 1494 | CHECK_EQ(res, SZ_OK); |
| 1495 | } |
| 1496 | |
| 1497 | template <typename ElfTypes> |
| 1498 | void WriteMiniDebugInfo(ElfBuilder<ElfTypes>* parent_builder, |
| 1499 | const ArrayRef<const MethodDebugInfo>& method_infos) { |
| 1500 | const InstructionSet isa = parent_builder->GetIsa(); |
| 1501 | std::vector<uint8_t> buffer; |
| 1502 | buffer.reserve(KB); |
| 1503 | VectorOutputStream out("Mini-debug-info ELF file", &buffer); |
| 1504 | std::unique_ptr<ElfBuilder<ElfTypes>> builder(new ElfBuilder<ElfTypes>(isa, &out)); |
| 1505 | builder->Start(); |
| 1506 | // Write .rodata and .text as NOBITS sections. |
| 1507 | // This allows tools to detect virtual address relocation of the parent ELF file. |
| 1508 | builder->SetVirtualAddress(parent_builder->GetRoData()->GetAddress()); |
| 1509 | builder->GetRoData()->WriteNoBitsSection(parent_builder->GetRoData()->GetSize()); |
| 1510 | builder->SetVirtualAddress(parent_builder->GetText()->GetAddress()); |
| 1511 | builder->GetText()->WriteNoBitsSection(parent_builder->GetText()->GetSize()); |
David Srbecky | 5288611 | 2016-01-22 13:56:47 +0000 | [diff] [blame] | 1512 | WriteDebugSymbols(builder.get(), method_infos, false /* with_signature */); |
David Srbecky | 5e974a6 | 2016-01-22 14:25:03 +0000 | [diff] [blame] | 1513 | WriteCFISection(builder.get(), method_infos, DW_DEBUG_FRAME_FORMAT, false /* write_oat_paches */); |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame] | 1514 | builder->End(); |
| 1515 | CHECK(builder->Good()); |
| 1516 | std::vector<uint8_t> compressed_buffer; |
| 1517 | compressed_buffer.reserve(buffer.size() / 4); |
| 1518 | XzCompress(&buffer, &compressed_buffer); |
| 1519 | parent_builder->WriteSection(".gnu_debugdata", &compressed_buffer); |
| 1520 | } |
| 1521 | |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 1522 | template <typename ElfTypes> |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1523 | static ArrayRef<const uint8_t> WriteDebugElfFileForMethodInternal( |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 1524 | const dwarf::MethodDebugInfo& method_info) { |
| 1525 | const InstructionSet isa = method_info.compiled_method_->GetInstructionSet(); |
| 1526 | std::vector<uint8_t> buffer; |
| 1527 | buffer.reserve(KB); |
| 1528 | VectorOutputStream out("Debug ELF file", &buffer); |
| 1529 | std::unique_ptr<ElfBuilder<ElfTypes>> builder(new ElfBuilder<ElfTypes>(isa, &out)); |
| 1530 | builder->Start(); |
| 1531 | WriteDebugInfo(builder.get(), |
| 1532 | ArrayRef<const MethodDebugInfo>(&method_info, 1), |
| 1533 | DW_DEBUG_FRAME_FORMAT); |
| 1534 | builder->End(); |
| 1535 | CHECK(builder->Good()); |
| 1536 | // Make a copy of the buffer. We want to shrink it anyway. |
| 1537 | uint8_t* result = new uint8_t[buffer.size()]; |
| 1538 | CHECK(result != nullptr); |
| 1539 | memcpy(result, buffer.data(), buffer.size()); |
| 1540 | return ArrayRef<const uint8_t>(result, buffer.size()); |
| 1541 | } |
| 1542 | |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1543 | ArrayRef<const uint8_t> WriteDebugElfFileForMethod(const dwarf::MethodDebugInfo& method_info) { |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 1544 | const InstructionSet isa = method_info.compiled_method_->GetInstructionSet(); |
| 1545 | if (Is64BitInstructionSet(isa)) { |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1546 | return WriteDebugElfFileForMethodInternal<ElfTypes64>(method_info); |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 1547 | } else { |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1548 | return WriteDebugElfFileForMethodInternal<ElfTypes32>(method_info); |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | template <typename ElfTypes> |
Tamas Berghammer | fffbee4 | 2016-01-15 13:09:34 +0000 | [diff] [blame] | 1553 | static ArrayRef<const uint8_t> WriteDebugElfFileForClassesInternal( |
| 1554 | const InstructionSet isa, const ArrayRef<mirror::Class*>& types) |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1555 | SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1556 | std::vector<uint8_t> buffer; |
| 1557 | buffer.reserve(KB); |
| 1558 | VectorOutputStream out("Debug ELF file", &buffer); |
| 1559 | std::unique_ptr<ElfBuilder<ElfTypes>> builder(new ElfBuilder<ElfTypes>(isa, &out)); |
| 1560 | builder->Start(); |
| 1561 | |
| 1562 | DebugInfoWriter<ElfTypes> info_writer(builder.get()); |
| 1563 | info_writer.Start(); |
Tamas Berghammer | fffbee4 | 2016-01-15 13:09:34 +0000 | [diff] [blame] | 1564 | info_writer.WriteTypes(types); |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1565 | info_writer.End(); |
| 1566 | |
| 1567 | builder->End(); |
| 1568 | CHECK(builder->Good()); |
| 1569 | // Make a copy of the buffer. We want to shrink it anyway. |
| 1570 | uint8_t* result = new uint8_t[buffer.size()]; |
| 1571 | CHECK(result != nullptr); |
| 1572 | memcpy(result, buffer.data(), buffer.size()); |
| 1573 | return ArrayRef<const uint8_t>(result, buffer.size()); |
| 1574 | } |
| 1575 | |
Tamas Berghammer | fffbee4 | 2016-01-15 13:09:34 +0000 | [diff] [blame] | 1576 | ArrayRef<const uint8_t> WriteDebugElfFileForClasses(const InstructionSet isa, |
| 1577 | const ArrayRef<mirror::Class*>& types) { |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1578 | if (Is64BitInstructionSet(isa)) { |
Tamas Berghammer | fffbee4 | 2016-01-15 13:09:34 +0000 | [diff] [blame] | 1579 | return WriteDebugElfFileForClassesInternal<ElfTypes64>(isa, types); |
Tamas Berghammer | 86e4278 | 2016-01-05 14:29:02 +0000 | [diff] [blame] | 1580 | } else { |
Tamas Berghammer | fffbee4 | 2016-01-15 13:09:34 +0000 | [diff] [blame] | 1581 | return WriteDebugElfFileForClassesInternal<ElfTypes32>(isa, types); |
David Srbecky | 5cc349f | 2015-12-18 15:04:48 +0000 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 1585 | // Explicit instantiations |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1586 | template void WriteDebugInfo<ElfTypes32>( |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 1587 | ElfBuilder<ElfTypes32>* builder, |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 1588 | const ArrayRef<const MethodDebugInfo>& method_infos, |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1589 | CFIFormat cfi_format); |
| 1590 | template void WriteDebugInfo<ElfTypes64>( |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 1591 | ElfBuilder<ElfTypes64>* builder, |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 1592 | const ArrayRef<const MethodDebugInfo>& method_infos, |
David Srbecky | e0febdf | 2015-12-17 20:53:07 +0000 | [diff] [blame] | 1593 | CFIFormat cfi_format); |
David Srbecky | 5b1c2ca | 2016-01-25 17:32:41 +0000 | [diff] [blame] | 1594 | template void WriteMiniDebugInfo<ElfTypes32>( |
| 1595 | ElfBuilder<ElfTypes32>* builder, |
| 1596 | const ArrayRef<const MethodDebugInfo>& method_infos); |
| 1597 | template void WriteMiniDebugInfo<ElfTypes64>( |
| 1598 | ElfBuilder<ElfTypes64>* builder, |
| 1599 | const ArrayRef<const MethodDebugInfo>& method_infos); |
David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 1600 | |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 1601 | } // namespace dwarf |
| 1602 | } // namespace art |