| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [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 "dwarf_test.h" |
| 18 | |
| David Srbecky | 4fda4eb | 2016-02-05 13:34:46 +0000 | [diff] [blame] | 19 | #include "debug/dwarf/debug_frame_opcode_writer.h" |
| 20 | #include "debug/dwarf/debug_info_entry_writer.h" |
| 21 | #include "debug/dwarf/debug_line_opcode_writer.h" |
| 22 | #include "debug/dwarf/dwarf_constants.h" |
| 23 | #include "debug/dwarf/headers.h" |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 24 | #include "gtest/gtest.h" |
| 25 | |
| 26 | namespace art { |
| 27 | namespace dwarf { |
| 28 | |
| 29 | // Run the tests only on host since we need objdump. |
| Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame] | 30 | #ifndef ART_TARGET_ANDROID |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 31 | |
| 32 | TEST_F(DwarfTest, DebugFrame) { |
| 33 | const bool is64bit = false; |
| 34 | |
| 35 | // Pick offset value which would catch Uleb vs Sleb errors. |
| 36 | const int offset = 40000; |
| 37 | ASSERT_EQ(UnsignedLeb128Size(offset / 4), 2u); |
| 38 | ASSERT_EQ(SignedLeb128Size(offset / 4), 3u); |
| 39 | DW_CHECK("Data alignment factor: -4"); |
| 40 | const Reg reg(6); |
| 41 | |
| 42 | // Test the opcodes in the order mentioned in the spec. |
| 43 | // There are usually several encoding variations of each opcode. |
| 44 | DebugFrameOpCodeWriter<> opcodes; |
| 45 | DW_CHECK("FDE"); |
| 46 | int pc = 0; |
| 47 | for (int i : {0, 1, 0x3F, 0x40, 0xFF, 0x100, 0xFFFF, 0x10000}) { |
| 48 | pc += i; |
| 49 | opcodes.AdvancePC(pc); |
| 50 | } |
| 51 | DW_CHECK_NEXT("DW_CFA_advance_loc: 1 to 01000001"); |
| 52 | DW_CHECK_NEXT("DW_CFA_advance_loc: 63 to 01000040"); |
| 53 | DW_CHECK_NEXT("DW_CFA_advance_loc1: 64 to 01000080"); |
| 54 | DW_CHECK_NEXT("DW_CFA_advance_loc1: 255 to 0100017f"); |
| 55 | DW_CHECK_NEXT("DW_CFA_advance_loc2: 256 to 0100027f"); |
| 56 | DW_CHECK_NEXT("DW_CFA_advance_loc2: 65535 to 0101027e"); |
| 57 | DW_CHECK_NEXT("DW_CFA_advance_loc4: 65536 to 0102027e"); |
| 58 | opcodes.DefCFA(reg, offset); |
| 59 | DW_CHECK_NEXT("DW_CFA_def_cfa: r6 (esi) ofs 40000"); |
| 60 | opcodes.DefCFA(reg, -offset); |
| 61 | DW_CHECK_NEXT("DW_CFA_def_cfa_sf: r6 (esi) ofs -40000"); |
| 62 | opcodes.DefCFARegister(reg); |
| 63 | DW_CHECK_NEXT("DW_CFA_def_cfa_register: r6 (esi)"); |
| 64 | opcodes.DefCFAOffset(offset); |
| 65 | DW_CHECK_NEXT("DW_CFA_def_cfa_offset: 40000"); |
| 66 | opcodes.DefCFAOffset(-offset); |
| 67 | DW_CHECK_NEXT("DW_CFA_def_cfa_offset_sf: -40000"); |
| 68 | uint8_t expr[] = { 0 }; |
| 69 | opcodes.DefCFAExpression(expr, arraysize(expr)); |
| 70 | DW_CHECK_NEXT("DW_CFA_def_cfa_expression"); |
| 71 | opcodes.Undefined(reg); |
| 72 | DW_CHECK_NEXT("DW_CFA_undefined: r6 (esi)"); |
| 73 | opcodes.SameValue(reg); |
| 74 | DW_CHECK_NEXT("DW_CFA_same_value: r6 (esi)"); |
| 75 | opcodes.Offset(Reg(0x3F), -offset); |
| 76 | // Bad register likely means that it does not exist on x86, |
| 77 | // but we want to test high register numbers anyway. |
| 78 | DW_CHECK_NEXT("DW_CFA_offset: bad register: r63 at cfa-40000"); |
| 79 | opcodes.Offset(Reg(0x40), -offset); |
| 80 | DW_CHECK_NEXT("DW_CFA_offset_extended: bad register: r64 at cfa-40000"); |
| 81 | opcodes.Offset(Reg(0x40), offset); |
| 82 | DW_CHECK_NEXT("DW_CFA_offset_extended_sf: bad register: r64 at cfa+40000"); |
| 83 | opcodes.ValOffset(reg, -offset); |
| 84 | DW_CHECK_NEXT("DW_CFA_val_offset: r6 (esi) at cfa-40000"); |
| 85 | opcodes.ValOffset(reg, offset); |
| 86 | DW_CHECK_NEXT("DW_CFA_val_offset_sf: r6 (esi) at cfa+40000"); |
| 87 | opcodes.Register(reg, Reg(1)); |
| 88 | DW_CHECK_NEXT("DW_CFA_register: r6 (esi) in r1 (ecx)"); |
| 89 | opcodes.Expression(reg, expr, arraysize(expr)); |
| 90 | DW_CHECK_NEXT("DW_CFA_expression: r6 (esi)"); |
| 91 | opcodes.ValExpression(reg, expr, arraysize(expr)); |
| 92 | DW_CHECK_NEXT("DW_CFA_val_expression: r6 (esi)"); |
| 93 | opcodes.Restore(Reg(0x3F)); |
| 94 | DW_CHECK_NEXT("DW_CFA_restore: bad register: r63"); |
| 95 | opcodes.Restore(Reg(0x40)); |
| 96 | DW_CHECK_NEXT("DW_CFA_restore_extended: bad register: r64"); |
| 97 | opcodes.Restore(reg); |
| 98 | DW_CHECK_NEXT("DW_CFA_restore: r6 (esi)"); |
| 99 | opcodes.RememberState(); |
| 100 | DW_CHECK_NEXT("DW_CFA_remember_state"); |
| 101 | opcodes.RestoreState(); |
| 102 | DW_CHECK_NEXT("DW_CFA_restore_state"); |
| 103 | opcodes.Nop(); |
| 104 | DW_CHECK_NEXT("DW_CFA_nop"); |
| 105 | |
| 106 | // Also test helpers. |
| 107 | opcodes.DefCFA(Reg(4), 100); // ESP |
| 108 | DW_CHECK_NEXT("DW_CFA_def_cfa: r4 (esp) ofs 100"); |
| 109 | opcodes.AdjustCFAOffset(8); |
| 110 | DW_CHECK_NEXT("DW_CFA_def_cfa_offset: 108"); |
| 111 | opcodes.RelOffset(Reg(0), 0); // push R0 |
| 112 | DW_CHECK_NEXT("DW_CFA_offset: r0 (eax) at cfa-108"); |
| 113 | opcodes.RelOffset(Reg(1), 4); // push R1 |
| 114 | DW_CHECK_NEXT("DW_CFA_offset: r1 (ecx) at cfa-104"); |
| 115 | opcodes.RelOffsetForMany(Reg(2), 8, 1 | (1 << 3), 4); // push R2 and R5 |
| 116 | DW_CHECK_NEXT("DW_CFA_offset: r2 (edx) at cfa-100"); |
| 117 | DW_CHECK_NEXT("DW_CFA_offset: r5 (ebp) at cfa-96"); |
| 118 | opcodes.RestoreMany(Reg(2), 1 | (1 << 3)); // pop R2 and R5 |
| 119 | DW_CHECK_NEXT("DW_CFA_restore: r2 (edx)"); |
| 120 | DW_CHECK_NEXT("DW_CFA_restore: r5 (ebp)"); |
| 121 | |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 122 | DebugFrameOpCodeWriter<> initial_opcodes; |
| David Srbecky | 91b2900 | 2019-02-08 15:51:31 +0000 | [diff] [blame^] | 123 | WriteCIE(is64bit, Reg(is64bit ? 16 : 8), initial_opcodes, &debug_frame_data_); |
| David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 124 | std::vector<uintptr_t> debug_frame_patches; |
| Igor Murashkin | 5573c37 | 2017-11-16 13:34:30 -0800 | [diff] [blame] | 125 | std::vector<uintptr_t> expected_patches = { 28 }; |
| David Srbecky | 91b2900 | 2019-02-08 15:51:31 +0000 | [diff] [blame^] | 126 | WriteFDE(is64bit, |
| 127 | 0, |
| 128 | 0, |
| 129 | 0x01000000, |
| 130 | 0x01000000, |
| 131 | ArrayRef<const uint8_t>(*opcodes.data()), |
| 132 | 0, |
| 133 | &debug_frame_data_, |
| 134 | &debug_frame_patches); |
| David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 135 | |
| David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 136 | EXPECT_EQ(expected_patches, debug_frame_patches); |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 137 | CheckObjdumpOutput(is64bit, "-W"); |
| 138 | } |
| 139 | |
| David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 140 | TEST_F(DwarfTest, DebugFrame64) { |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 141 | constexpr bool is64bit = true; |
| 142 | DebugFrameOpCodeWriter<> initial_opcodes; |
| David Srbecky | 91b2900 | 2019-02-08 15:51:31 +0000 | [diff] [blame^] | 143 | WriteCIE(is64bit, Reg(16), initial_opcodes, &debug_frame_data_); |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 144 | DebugFrameOpCodeWriter<> opcodes; |
| David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 145 | std::vector<uintptr_t> debug_frame_patches; |
| Igor Murashkin | 5573c37 | 2017-11-16 13:34:30 -0800 | [diff] [blame] | 146 | std::vector<uintptr_t> expected_patches = { 32 }; |
| David Srbecky | 91b2900 | 2019-02-08 15:51:31 +0000 | [diff] [blame^] | 147 | WriteFDE(is64bit, |
| 148 | 0, |
| 149 | 0, |
| 150 | 0x0100000000000000, |
| 151 | 0x0200000000000000, |
| David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 152 | ArrayRef<const uint8_t>(*opcodes.data()), |
| David Srbecky | 91b2900 | 2019-02-08 15:51:31 +0000 | [diff] [blame^] | 153 | 0, |
| 154 | &debug_frame_data_, |
| 155 | &debug_frame_patches); |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 156 | DW_CHECK("FDE cie=00000000 pc=100000000000000..300000000000000"); |
| David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 157 | |
| David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 158 | EXPECT_EQ(expected_patches, debug_frame_patches); |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 159 | CheckObjdumpOutput(is64bit, "-W"); |
| 160 | } |
| 161 | |
| David Srbecky | c2055cf | 2015-04-12 14:58:39 +0100 | [diff] [blame] | 162 | // Test x86_64 register mapping. It is the only non-trivial architecture. |
| 163 | // ARM, X86, and Mips have: dwarf_reg = art_reg + constant. |
| 164 | TEST_F(DwarfTest, x86_64_RegisterMapping) { |
| 165 | constexpr bool is64bit = true; |
| 166 | DebugFrameOpCodeWriter<> opcodes; |
| 167 | for (int i = 0; i < 16; i++) { |
| 168 | opcodes.RelOffset(Reg::X86_64Core(i), 0); |
| 169 | } |
| 170 | DW_CHECK("FDE"); |
| 171 | DW_CHECK_NEXT("DW_CFA_offset: r0 (rax)"); |
| 172 | DW_CHECK_NEXT("DW_CFA_offset: r2 (rcx)"); |
| 173 | DW_CHECK_NEXT("DW_CFA_offset: r1 (rdx)"); |
| 174 | DW_CHECK_NEXT("DW_CFA_offset: r3 (rbx)"); |
| 175 | DW_CHECK_NEXT("DW_CFA_offset: r7 (rsp)"); |
| 176 | DW_CHECK_NEXT("DW_CFA_offset: r6 (rbp)"); |
| 177 | DW_CHECK_NEXT("DW_CFA_offset: r4 (rsi)"); |
| 178 | DW_CHECK_NEXT("DW_CFA_offset: r5 (rdi)"); |
| 179 | DW_CHECK_NEXT("DW_CFA_offset: r8 (r8)"); |
| 180 | DW_CHECK_NEXT("DW_CFA_offset: r9 (r9)"); |
| 181 | DW_CHECK_NEXT("DW_CFA_offset: r10 (r10)"); |
| 182 | DW_CHECK_NEXT("DW_CFA_offset: r11 (r11)"); |
| 183 | DW_CHECK_NEXT("DW_CFA_offset: r12 (r12)"); |
| 184 | DW_CHECK_NEXT("DW_CFA_offset: r13 (r13)"); |
| 185 | DW_CHECK_NEXT("DW_CFA_offset: r14 (r14)"); |
| 186 | DW_CHECK_NEXT("DW_CFA_offset: r15 (r15)"); |
| 187 | DebugFrameOpCodeWriter<> initial_opcodes; |
| David Srbecky | 91b2900 | 2019-02-08 15:51:31 +0000 | [diff] [blame^] | 188 | WriteCIE(is64bit, Reg(16), initial_opcodes, &debug_frame_data_); |
| David Srbecky | ad5fa8c | 2015-05-06 18:27:35 +0100 | [diff] [blame] | 189 | std::vector<uintptr_t> debug_frame_patches; |
| David Srbecky | 91b2900 | 2019-02-08 15:51:31 +0000 | [diff] [blame^] | 190 | WriteFDE(is64bit, |
| 191 | 0, |
| 192 | 0, |
| 193 | 0x0100000000000000, |
| 194 | 0x0200000000000000, |
| David Srbecky | 6d8c8f0 | 2015-10-26 10:57:09 +0000 | [diff] [blame] | 195 | ArrayRef<const uint8_t>(*opcodes.data()), |
| David Srbecky | 91b2900 | 2019-02-08 15:51:31 +0000 | [diff] [blame^] | 196 | 0, |
| 197 | &debug_frame_data_, |
| 198 | &debug_frame_patches); |
| David Srbecky | c2055cf | 2015-04-12 14:58:39 +0100 | [diff] [blame] | 199 | |
| 200 | CheckObjdumpOutput(is64bit, "-W"); |
| 201 | } |
| 202 | |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 203 | TEST_F(DwarfTest, DebugLine) { |
| 204 | const bool is64bit = false; |
| 205 | const int code_factor_bits = 1; |
| 206 | DebugLineOpCodeWriter<> opcodes(is64bit, code_factor_bits); |
| 207 | |
| 208 | std::vector<std::string> include_directories; |
| 209 | include_directories.push_back("/path/to/source"); |
| 210 | DW_CHECK("/path/to/source"); |
| 211 | |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 212 | std::vector<FileEntry> files { |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 213 | { "file0.c", 0, 1000, 2000 }, |
| 214 | { "file1.c", 1, 1000, 2000 }, |
| 215 | { "file2.c", 1, 1000, 2000 }, |
| 216 | }; |
| 217 | DW_CHECK("1\t0\t1000\t2000\tfile0.c"); |
| 218 | DW_CHECK_NEXT("2\t1\t1000\t2000\tfile1.c"); |
| 219 | DW_CHECK_NEXT("3\t1\t1000\t2000\tfile2.c"); |
| 220 | |
| 221 | DW_CHECK("Line Number Statements"); |
| 222 | opcodes.SetAddress(0x01000000); |
| 223 | DW_CHECK_NEXT("Extended opcode 2: set Address to 0x1000000"); |
| 224 | opcodes.AddRow(); |
| 225 | DW_CHECK_NEXT("Copy"); |
| 226 | opcodes.AdvancePC(0x01000100); |
| 227 | DW_CHECK_NEXT("Advance PC by 256 to 0x1000100"); |
| 228 | opcodes.SetFile(2); |
| 229 | DW_CHECK_NEXT("Set File Name to entry 2 in the File Name Table"); |
| 230 | opcodes.AdvanceLine(3); |
| 231 | DW_CHECK_NEXT("Advance Line by 2 to 3"); |
| 232 | opcodes.SetColumn(4); |
| 233 | DW_CHECK_NEXT("Set column to 4"); |
| David Srbecky | 91cc06c | 2016-03-07 16:13:58 +0000 | [diff] [blame] | 234 | opcodes.SetIsStmt(true); |
| 235 | DW_CHECK_NEXT("Set is_stmt to 1"); |
| 236 | opcodes.SetIsStmt(false); |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 237 | DW_CHECK_NEXT("Set is_stmt to 0"); |
| 238 | opcodes.SetBasicBlock(); |
| 239 | DW_CHECK_NEXT("Set basic block"); |
| 240 | opcodes.SetPrologueEnd(); |
| 241 | DW_CHECK_NEXT("Set prologue_end to true"); |
| 242 | opcodes.SetEpilogueBegin(); |
| 243 | DW_CHECK_NEXT("Set epilogue_begin to true"); |
| 244 | opcodes.SetISA(5); |
| 245 | DW_CHECK_NEXT("Set ISA to 5"); |
| 246 | opcodes.EndSequence(); |
| 247 | DW_CHECK_NEXT("Extended opcode 1: End of Sequence"); |
| 248 | opcodes.DefineFile("file.c", 0, 1000, 2000); |
| 249 | DW_CHECK_NEXT("Extended opcode 3: define new File Table entry"); |
| 250 | DW_CHECK_NEXT("Entry\tDir\tTime\tSize\tName"); |
| 251 | DW_CHECK_NEXT("1\t0\t1000\t2000\tfile.c"); |
| 252 | |
| David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 253 | std::vector<uintptr_t> debug_line_patches; |
| Igor Murashkin | 5573c37 | 2017-11-16 13:34:30 -0800 | [diff] [blame] | 254 | std::vector<uintptr_t> expected_patches = { 87 }; |
| David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 255 | WriteDebugLineTable(include_directories, files, opcodes, |
| David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 256 | 0, &debug_line_data_, &debug_line_patches); |
| David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 257 | |
| 258 | EXPECT_EQ(expected_patches, debug_line_patches); |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 259 | CheckObjdumpOutput(is64bit, "-W"); |
| 260 | } |
| 261 | |
| 262 | // DWARF has special one byte codes which advance PC and line at the same time. |
| 263 | TEST_F(DwarfTest, DebugLineSpecialOpcodes) { |
| 264 | const bool is64bit = false; |
| 265 | const int code_factor_bits = 1; |
| 266 | uint32_t pc = 0x01000000; |
| 267 | int line = 1; |
| 268 | DebugLineOpCodeWriter<> opcodes(is64bit, code_factor_bits); |
| 269 | opcodes.SetAddress(pc); |
| 270 | size_t num_rows = 0; |
| 271 | DW_CHECK("Line Number Statements:"); |
| 272 | DW_CHECK("Special opcode"); |
| 273 | DW_CHECK("Advance PC by constant"); |
| 274 | DW_CHECK("Decoded dump of debug contents of section .debug_line:"); |
| 275 | DW_CHECK("Line number Starting address"); |
| 276 | for (int addr_delta = 0; addr_delta < 80; addr_delta += 2) { |
| 277 | for (int line_delta = 16; line_delta >= -16; --line_delta) { |
| 278 | pc += addr_delta; |
| 279 | line += line_delta; |
| 280 | opcodes.AddRow(pc, line); |
| 281 | num_rows++; |
| 282 | ASSERT_EQ(opcodes.CurrentAddress(), pc); |
| 283 | ASSERT_EQ(opcodes.CurrentLine(), line); |
| 284 | char expected[1024]; |
| 285 | sprintf(expected, "%i 0x%x", line, pc); |
| 286 | DW_CHECK_NEXT(expected); |
| 287 | } |
| 288 | } |
| 289 | EXPECT_LT(opcodes.data()->size(), num_rows * 3); |
| 290 | |
| 291 | std::vector<std::string> directories; |
| Igor Murashkin | 5573c37 | 2017-11-16 13:34:30 -0800 | [diff] [blame] | 292 | std::vector<FileEntry> files = { { "file.c", 0, 1000, 2000 } }; |
| David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 293 | std::vector<uintptr_t> debug_line_patches; |
| 294 | WriteDebugLineTable(directories, files, opcodes, |
| David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 295 | 0, &debug_line_data_, &debug_line_patches); |
| David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 296 | |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 297 | CheckObjdumpOutput(is64bit, "-W -WL"); |
| 298 | } |
| 299 | |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 300 | TEST_F(DwarfTest, DebugInfo) { |
| 301 | constexpr bool is64bit = false; |
| David Srbecky | 24868a1 | 2016-01-29 18:59:56 +0000 | [diff] [blame] | 302 | DebugAbbrevWriter<> debug_abbrev(&debug_abbrev_data_); |
| 303 | DebugInfoEntryWriter<> info(is64bit, &debug_abbrev); |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 304 | DW_CHECK("Contents of the .debug_info section:"); |
| David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 305 | info.StartTag(dwarf::DW_TAG_compile_unit); |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 306 | DW_CHECK("Abbrev Number: 1 (DW_TAG_compile_unit)"); |
| 307 | info.WriteStrp(dwarf::DW_AT_producer, "Compiler name", &debug_str_data_); |
| 308 | DW_CHECK_NEXT("DW_AT_producer : (indirect string, offset: 0x0): Compiler name"); |
| 309 | info.WriteAddr(dwarf::DW_AT_low_pc, 0x01000000); |
| 310 | DW_CHECK_NEXT("DW_AT_low_pc : 0x1000000"); |
| 311 | info.WriteAddr(dwarf::DW_AT_high_pc, 0x02000000); |
| 312 | DW_CHECK_NEXT("DW_AT_high_pc : 0x2000000"); |
| David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 313 | info.StartTag(dwarf::DW_TAG_subprogram); |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 314 | DW_CHECK("Abbrev Number: 2 (DW_TAG_subprogram)"); |
| 315 | info.WriteStrp(dwarf::DW_AT_name, "Foo", &debug_str_data_); |
| 316 | DW_CHECK_NEXT("DW_AT_name : (indirect string, offset: 0xe): Foo"); |
| 317 | info.WriteAddr(dwarf::DW_AT_low_pc, 0x01010000); |
| 318 | DW_CHECK_NEXT("DW_AT_low_pc : 0x1010000"); |
| 319 | info.WriteAddr(dwarf::DW_AT_high_pc, 0x01020000); |
| 320 | DW_CHECK_NEXT("DW_AT_high_pc : 0x1020000"); |
| 321 | info.EndTag(); // DW_TAG_subprogram |
| David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 322 | info.StartTag(dwarf::DW_TAG_subprogram); |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 323 | DW_CHECK("Abbrev Number: 2 (DW_TAG_subprogram)"); |
| 324 | info.WriteStrp(dwarf::DW_AT_name, "Bar", &debug_str_data_); |
| 325 | DW_CHECK_NEXT("DW_AT_name : (indirect string, offset: 0x12): Bar"); |
| 326 | info.WriteAddr(dwarf::DW_AT_low_pc, 0x01020000); |
| 327 | DW_CHECK_NEXT("DW_AT_low_pc : 0x1020000"); |
| 328 | info.WriteAddr(dwarf::DW_AT_high_pc, 0x01030000); |
| 329 | DW_CHECK_NEXT("DW_AT_high_pc : 0x1030000"); |
| 330 | info.EndTag(); // DW_TAG_subprogram |
| 331 | info.EndTag(); // DW_TAG_compile_unit |
| 332 | // Test that previous list was properly terminated and empty children. |
| David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 333 | info.StartTag(dwarf::DW_TAG_compile_unit); |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 334 | info.EndTag(); // DW_TAG_compile_unit |
| 335 | |
| 336 | // The abbrev table is just side product, but check it as well. |
| 337 | DW_CHECK("Abbrev Number: 3 (DW_TAG_compile_unit)"); |
| 338 | DW_CHECK("Contents of the .debug_abbrev section:"); |
| 339 | DW_CHECK("1 DW_TAG_compile_unit [has children]"); |
| 340 | DW_CHECK_NEXT("DW_AT_producer DW_FORM_strp"); |
| 341 | DW_CHECK_NEXT("DW_AT_low_pc DW_FORM_addr"); |
| 342 | DW_CHECK_NEXT("DW_AT_high_pc DW_FORM_addr"); |
| 343 | DW_CHECK("2 DW_TAG_subprogram [no children]"); |
| 344 | DW_CHECK_NEXT("DW_AT_name DW_FORM_strp"); |
| 345 | DW_CHECK_NEXT("DW_AT_low_pc DW_FORM_addr"); |
| 346 | DW_CHECK_NEXT("DW_AT_high_pc DW_FORM_addr"); |
| David Srbecky | 04b0526 | 2015-11-09 18:05:48 +0000 | [diff] [blame] | 347 | DW_CHECK("3 DW_TAG_compile_unit [no children]"); |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 348 | |
| David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 349 | std::vector<uintptr_t> debug_info_patches; |
| Igor Murashkin | 5573c37 | 2017-11-16 13:34:30 -0800 | [diff] [blame] | 350 | std::vector<uintptr_t> expected_patches = { 16, 20, 29, 33, 42, 46 }; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 351 | dwarf::WriteDebugInfoCU(/* debug_abbrev_offset= */ 0, info, |
| David Srbecky | b851b49 | 2015-11-11 20:19:38 +0000 | [diff] [blame] | 352 | 0, &debug_info_data_, &debug_info_patches); |
| David Srbecky | 2f6cdb0 | 2015-04-11 00:17:53 +0100 | [diff] [blame] | 353 | |
| 354 | EXPECT_EQ(expected_patches, debug_info_patches); |
| David Srbecky | b536247 | 2015-04-08 19:37:39 +0100 | [diff] [blame] | 355 | CheckObjdumpOutput(is64bit, "-W"); |
| 356 | } |
| 357 | |
| Bilyan Borisov | bb661c0 | 2016-04-04 16:27:32 +0100 | [diff] [blame] | 358 | #endif // ART_TARGET_ANDROID |
| David Srbecky | 15c1975 | 2015-03-31 14:53:55 +0000 | [diff] [blame] | 359 | |
| 360 | } // namespace dwarf |
| 361 | } // namespace art |