blob: df262f525a15ea915314ca471dc34b0de1d03197 [file] [log] [blame]
Christopher Ferrisc3d79f72017-11-28 19:14:54 -08001/*
2 * Copyright (C) 2017 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 <inttypes.h>
18#include <stdint.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <unistd.h>
22
23#include <gtest/gtest.h>
24
25#include <string>
Christopher Ferrise37e2d02018-02-09 15:57:39 -080026#include <unordered_map>
Christopher Ferrisc3d79f72017-11-28 19:14:54 -080027#include <vector>
28
Christopher Ferrise37e2d02018-02-09 15:57:39 -080029#include <android-base/file.h>
30
Christopher Ferris150db122017-12-20 18:49:01 -080031#include <unwindstack/JitDebug.h>
Christopher Ferris53914162018-02-08 19:27:47 -080032#include <unwindstack/MachineArm.h>
33#include <unwindstack/MachineArm64.h>
34#include <unwindstack/MachineX86.h>
Christopher Ferrise37e2d02018-02-09 15:57:39 -080035#include <unwindstack/MachineX86_64.h>
Christopher Ferrisc3d79f72017-11-28 19:14:54 -080036#include <unwindstack/Maps.h>
37#include <unwindstack/Memory.h>
Christopher Ferrisd06001d2017-11-30 18:56:01 -080038#include <unwindstack/RegsArm.h>
39#include <unwindstack/RegsArm64.h>
Christopher Ferris150db122017-12-20 18:49:01 -080040#include <unwindstack/RegsX86.h>
Christopher Ferrise37e2d02018-02-09 15:57:39 -080041#include <unwindstack/RegsX86_64.h>
Christopher Ferrisc3d79f72017-11-28 19:14:54 -080042#include <unwindstack/Unwinder.h>
43
Christopher Ferrisc3d79f72017-11-28 19:14:54 -080044#include "ElfTestUtils.h"
45
46namespace unwindstack {
47
Christopher Ferrise37e2d02018-02-09 15:57:39 -080048class UnwindOfflineTest : public ::testing::Test {
49 protected:
50 void TearDown() override {
51 if (cwd_ != nullptr) {
52 ASSERT_EQ(0, chdir(cwd_));
53 }
54 free(cwd_);
55 }
56
57 void Init(const char* file_dir, ArchEnum arch) {
58 dir_ = TestGetFileDirectory() + "offline/" + file_dir;
59
60 std::string data;
61 ASSERT_TRUE(android::base::ReadFileToString((dir_ + "maps.txt"), &data));
62
63 maps_.reset(new BufferMaps(data.c_str()));
64 ASSERT_TRUE(maps_->Parse());
65
66 std::unique_ptr<MemoryOffline> stack_memory(new MemoryOffline);
67 ASSERT_TRUE(stack_memory->Init((dir_ + "stack.data").c_str(), 0));
68 process_memory_.reset(stack_memory.release());
69
70 switch (arch) {
71 case ARCH_ARM: {
72 RegsArm* regs = new RegsArm;
73 regs_.reset(regs);
74 ReadRegs<uint32_t>(regs, arm_regs_);
75 break;
76 }
77 case ARCH_ARM64: {
78 RegsArm64* regs = new RegsArm64;
79 regs_.reset(regs);
80 ReadRegs<uint64_t>(regs, arm64_regs_);
81 break;
82 }
83 case ARCH_X86: {
84 RegsX86* regs = new RegsX86;
85 regs_.reset(regs);
86 ReadRegs<uint32_t>(regs, x86_regs_);
87 break;
88 }
89 case ARCH_X86_64: {
90 RegsX86_64* regs = new RegsX86_64;
91 regs_.reset(regs);
92 ReadRegs<uint64_t>(regs, x86_64_regs_);
93 break;
94 }
95 default:
96 ASSERT_TRUE(false) << "Unknown arch " << std::to_string(arch);
97 }
98 cwd_ = getcwd(nullptr, 0);
99 // Make dir_ an absolute directory.
100 if (dir_.empty() || dir_[0] != '/') {
101 dir_ = std::string(cwd_) + '/' + dir_;
102 }
103 ASSERT_EQ(0, chdir(dir_.c_str()));
104 }
105
106 template <typename AddressType>
107 void ReadRegs(RegsImpl<AddressType>* regs,
108 const std::unordered_map<std::string, uint32_t>& name_to_reg) {
109 FILE* fp = fopen((dir_ + "regs.txt").c_str(), "r");
110 ASSERT_TRUE(fp != nullptr);
111 while (!feof(fp)) {
112 uint64_t value;
113 char reg_name[100];
114 ASSERT_EQ(2, fscanf(fp, "%s %" SCNx64 "\n", reg_name, &value));
115 std::string name(reg_name);
116 if (!name.empty()) {
117 // Remove the : from the end.
118 name.resize(name.size() - 1);
119 }
120 auto entry = name_to_reg.find(name);
121 ASSERT_TRUE(entry != name_to_reg.end()) << "Unknown register named " << name;
122 (*regs)[entry->second] = value;
123 }
124 fclose(fp);
125 regs->SetFromRaw();
126 }
127
128 static std::unordered_map<std::string, uint32_t> arm_regs_;
129 static std::unordered_map<std::string, uint32_t> arm64_regs_;
130 static std::unordered_map<std::string, uint32_t> x86_regs_;
131 static std::unordered_map<std::string, uint32_t> x86_64_regs_;
132
133 char* cwd_ = nullptr;
134 std::string dir_;
135 std::unique_ptr<Regs> regs_;
136 std::unique_ptr<Maps> maps_;
137 std::shared_ptr<Memory> process_memory_;
138};
139
140std::unordered_map<std::string, uint32_t> UnwindOfflineTest::arm_regs_ = {
141 {"r0", ARM_REG_R0}, {"r1", ARM_REG_R1}, {"r2", ARM_REG_R2}, {"r3", ARM_REG_R3},
142 {"r4", ARM_REG_R4}, {"r5", ARM_REG_R5}, {"r6", ARM_REG_R6}, {"r7", ARM_REG_R7},
143 {"r8", ARM_REG_R8}, {"r9", ARM_REG_R9}, {"r10", ARM_REG_R10}, {"r11", ARM_REG_R11},
144 {"ip", ARM_REG_R12}, {"sp", ARM_REG_SP}, {"lr", ARM_REG_LR}, {"pc", ARM_REG_PC},
145};
146
147std::unordered_map<std::string, uint32_t> UnwindOfflineTest::arm64_regs_ = {
148 {"x0", ARM64_REG_R0}, {"x1", ARM64_REG_R1}, {"x2", ARM64_REG_R2}, {"x3", ARM64_REG_R3},
149 {"x4", ARM64_REG_R4}, {"x5", ARM64_REG_R5}, {"x6", ARM64_REG_R6}, {"x7", ARM64_REG_R7},
150 {"x8", ARM64_REG_R8}, {"x9", ARM64_REG_R9}, {"x10", ARM64_REG_R10}, {"x11", ARM64_REG_R11},
151 {"x12", ARM64_REG_R12}, {"x13", ARM64_REG_R13}, {"x14", ARM64_REG_R14}, {"x15", ARM64_REG_R15},
152 {"x16", ARM64_REG_R16}, {"x17", ARM64_REG_R17}, {"x18", ARM64_REG_R18}, {"x19", ARM64_REG_R19},
153 {"x20", ARM64_REG_R20}, {"x21", ARM64_REG_R21}, {"x22", ARM64_REG_R22}, {"x23", ARM64_REG_R23},
154 {"x24", ARM64_REG_R24}, {"x25", ARM64_REG_R25}, {"x26", ARM64_REG_R26}, {"x27", ARM64_REG_R27},
155 {"x28", ARM64_REG_R28}, {"x29", ARM64_REG_R29}, {"sp", ARM64_REG_SP}, {"lr", ARM64_REG_LR},
156 {"pc", ARM64_REG_PC},
157};
158
159std::unordered_map<std::string, uint32_t> UnwindOfflineTest::x86_regs_ = {
160 {"eax", X86_REG_EAX}, {"ebx", X86_REG_EBX}, {"ecx", X86_REG_ECX},
161 {"edx", X86_REG_EDX}, {"ebp", X86_REG_EBP}, {"edi", X86_REG_EDI},
162 {"esi", X86_REG_ESI}, {"esp", X86_REG_ESP}, {"eip", X86_REG_EIP},
163};
164
165std::unordered_map<std::string, uint32_t> UnwindOfflineTest::x86_64_regs_ = {
166 {"rax", X86_64_REG_RAX}, {"rbx", X86_64_REG_RBX}, {"rcx", X86_64_REG_RCX},
167 {"rdx", X86_64_REG_RDX}, {"r8", X86_64_REG_R8}, {"r9", X86_64_REG_R9},
168 {"r10", X86_64_REG_R10}, {"r11", X86_64_REG_R11}, {"r12", X86_64_REG_R12},
169 {"r13", X86_64_REG_R13}, {"r14", X86_64_REG_R14}, {"r15", X86_64_REG_R15},
170 {"rdi", X86_64_REG_RDI}, {"rsi", X86_64_REG_RSI}, {"rbp", X86_64_REG_RBP},
171 {"rsp", X86_64_REG_RSP}, {"rip", X86_64_REG_RIP},
172};
173
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800174static std::string DumpFrames(Unwinder& unwinder) {
175 std::string str;
176 for (size_t i = 0; i < unwinder.NumFrames(); i++) {
177 str += unwinder.FormatFrame(i) + "\n";
178 }
179 return str;
180}
181
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800182TEST_F(UnwindOfflineTest, pc_straddle_arm) {
183 Init("straddle_arm/", ARCH_ARM);
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800184
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800185 Unwinder unwinder(128, maps_.get(), regs_.get(), process_memory_);
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800186 unwinder.Unwind();
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800187
188 std::string frame_info(DumpFrames(unwinder));
189 ASSERT_EQ(4U, unwinder.NumFrames()) << "Unwind:\n" << frame_info;
190 EXPECT_EQ(
191 " #00 pc 0001a9f8 libc.so (abort+63)\n"
192 " #01 pc 00006a1b libbase.so (_ZN7android4base14DefaultAborterEPKc+6)\n"
193 " #02 pc 00007441 libbase.so (_ZN7android4base10LogMessageD2Ev+748)\n"
Christopher Ferris150db122017-12-20 18:49:01 -0800194 " #03 pc 00015147 /does/not/exist/libhidlbase.so\n",
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800195 frame_info);
196}
197
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800198TEST_F(UnwindOfflineTest, pc_in_gnu_debugdata_arm) {
199 Init("gnu_debugdata_arm/", ARCH_ARM);
Christopher Ferrise7b66242017-12-15 11:17:45 -0800200
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800201 Unwinder unwinder(128, maps_.get(), regs_.get(), process_memory_);
Christopher Ferrise7b66242017-12-15 11:17:45 -0800202 unwinder.Unwind();
Christopher Ferrise7b66242017-12-15 11:17:45 -0800203
204 std::string frame_info(DumpFrames(unwinder));
205 ASSERT_EQ(2U, unwinder.NumFrames()) << "Unwind:\n" << frame_info;
206 EXPECT_EQ(
207 " #00 pc 0006dc49 libandroid_runtime.so "
208 "(_ZN7android14AndroidRuntime15javaThreadShellEPv+80)\n"
209 " #01 pc 0006dce5 libandroid_runtime.so "
210 "(_ZN7android14AndroidRuntime19javaCreateThreadEtcEPFiPvES1_PKcijPS1_)\n",
211 frame_info);
212}
213
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800214TEST_F(UnwindOfflineTest, pc_straddle_arm64) {
215 Init("straddle_arm64/", ARCH_ARM64);
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800216
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800217 Unwinder unwinder(128, maps_.get(), regs_.get(), process_memory_);
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800218 unwinder.Unwind();
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800219
220 std::string frame_info(DumpFrames(unwinder));
221 ASSERT_EQ(6U, unwinder.NumFrames()) << "Unwind:\n" << frame_info;
222 EXPECT_EQ(
223 " #00 pc 0000000000429fd8 libunwindstack_test (SignalInnerFunction+24)\n"
224 " #01 pc 000000000042a078 libunwindstack_test (SignalMiddleFunction+8)\n"
225 " #02 pc 000000000042a08c libunwindstack_test (SignalOuterFunction+8)\n"
226 " #03 pc 000000000042d8fc libunwindstack_test "
227 "(_ZN11unwindstackL19RemoteThroughSignalEij+20)\n"
228 " #04 pc 000000000042d8d8 libunwindstack_test "
229 "(_ZN11unwindstack37UnwindTest_remote_through_signal_Test8TestBodyEv+32)\n"
230 " #05 pc 0000000000455d70 libunwindstack_test (_ZN7testing4Test3RunEv+392)\n",
231 frame_info);
232}
233
Christopher Ferris150db122017-12-20 18:49:01 -0800234static void AddMemory(std::string file_name, MemoryOfflineParts* parts) {
235 MemoryOffline* memory = new MemoryOffline;
236 ASSERT_TRUE(memory->Init(file_name.c_str(), 0));
237 parts->Add(memory);
238}
239
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800240TEST_F(UnwindOfflineTest, jit_debug_x86) {
241 Init("jit_debug_x86/", ARCH_X86);
Christopher Ferris150db122017-12-20 18:49:01 -0800242
243 MemoryOfflineParts* memory = new MemoryOfflineParts;
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800244 AddMemory(dir_ + "descriptor.data", memory);
245 AddMemory(dir_ + "stack.data", memory);
Christopher Ferris150db122017-12-20 18:49:01 -0800246 for (size_t i = 0; i < 7; i++) {
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800247 AddMemory(dir_ + "entry" + std::to_string(i) + ".data", memory);
248 AddMemory(dir_ + "jit" + std::to_string(i) + ".data", memory);
Christopher Ferris150db122017-12-20 18:49:01 -0800249 }
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800250 process_memory_.reset(memory);
Christopher Ferris150db122017-12-20 18:49:01 -0800251
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800252 JitDebug jit_debug(process_memory_);
253 Unwinder unwinder(128, maps_.get(), regs_.get(), process_memory_);
254 unwinder.SetJitDebug(&jit_debug, regs_->Arch());
Christopher Ferris150db122017-12-20 18:49:01 -0800255 unwinder.Unwind();
Christopher Ferris150db122017-12-20 18:49:01 -0800256
257 std::string frame_info(DumpFrames(unwinder));
258 ASSERT_EQ(69U, unwinder.NumFrames()) << "Unwind:\n" << frame_info;
259 EXPECT_EQ(
260 " #00 pc 00068fb8 libarttestd.so (_ZN3artL13CauseSegfaultEv+72)\n"
261 " #01 pc 00067f00 libarttestd.so (Java_Main_unwindInProcess+10032)\n"
262 " #02 pc 000021a8 (offset 0x2000) 137-cfi.odex (boolean Main.unwindInProcess(boolean, int, "
263 "boolean)+136)\n"
264 " #03 pc 0000fe81 anonymous:ee74c000 (boolean Main.bar(boolean)+65)\n"
265 " #04 pc 006ad4d2 libartd.so (art_quick_invoke_stub+338)\n"
266 " #05 pc 00146ab5 libartd.so "
267 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+885)\n"
268 " #06 pc 0039cf0d libartd.so "
269 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
270 "11ShadowFrameEtPNS_6JValueE+653)\n"
271 " #07 pc 00392552 libartd.so "
272 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
273 "6JValueEb+354)\n"
274 " #08 pc 0039399a libartd.so "
275 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
276 "20CodeItemDataAccessorEPNS_11ShadowFrameE+234)\n"
277 " #09 pc 00684362 libartd.so (artQuickToInterpreterBridge+1058)\n"
278 " #10 pc 006b35bd libartd.so (art_quick_to_interpreter_bridge+77)\n"
279 " #11 pc 0000fe04 anonymous:ee74c000 (int Main.compare(Main, Main)+52)\n"
280 " #12 pc 006ad4d2 libartd.so (art_quick_invoke_stub+338)\n"
281 " #13 pc 00146ab5 libartd.so "
282 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+885)\n"
283 " #14 pc 0039cf0d libartd.so "
284 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
285 "11ShadowFrameEtPNS_6JValueE+653)\n"
286 " #15 pc 00392552 libartd.so "
287 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
288 "6JValueEb+354)\n"
289 " #16 pc 0039399a libartd.so "
290 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
291 "20CodeItemDataAccessorEPNS_11ShadowFrameE+234)\n"
292 " #17 pc 00684362 libartd.so (artQuickToInterpreterBridge+1058)\n"
293 " #18 pc 006b35bd libartd.so (art_quick_to_interpreter_bridge+77)\n"
294 " #19 pc 0000fd3c anonymous:ee74c000 (int Main.compare(java.lang.Object, "
295 "java.lang.Object)+108)\n"
296 " #20 pc 006ad4d2 libartd.so (art_quick_invoke_stub+338)\n"
297 " #21 pc 00146ab5 libartd.so "
298 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+885)\n"
299 " #22 pc 0039cf0d libartd.so "
300 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
301 "11ShadowFrameEtPNS_6JValueE+653)\n"
302 " #23 pc 00392552 libartd.so "
303 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
304 "6JValueEb+354)\n"
305 " #24 pc 0039399a libartd.so "
306 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
307 "20CodeItemDataAccessorEPNS_11ShadowFrameE+234)\n"
308 " #25 pc 00684362 libartd.so (artQuickToInterpreterBridge+1058)\n"
309 " #26 pc 006b35bd libartd.so (art_quick_to_interpreter_bridge+77)\n"
310 " #27 pc 0000fbdc anonymous:ee74c000 (int "
311 "java.util.Arrays.binarySearch0(java.lang.Object[], int, int, java.lang.Object, "
312 "java.util.Comparator)+332)\n"
313 " #28 pc 006ad6a2 libartd.so (art_quick_invoke_static_stub+418)\n"
314 " #29 pc 00146acb libartd.so "
315 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+907)\n"
316 " #30 pc 0039cf0d libartd.so "
317 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
318 "11ShadowFrameEtPNS_6JValueE+653)\n"
319 " #31 pc 00392552 libartd.so "
320 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
321 "6JValueEb+354)\n"
322 " #32 pc 0039399a libartd.so "
323 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
324 "20CodeItemDataAccessorEPNS_11ShadowFrameE+234)\n"
325 " #33 pc 00684362 libartd.so (artQuickToInterpreterBridge+1058)\n"
326 " #34 pc 006b35bd libartd.so (art_quick_to_interpreter_bridge+77)\n"
327 " #35 pc 0000f625 anonymous:ee74c000 (boolean Main.foo()+165)\n"
328 " #36 pc 006ad4d2 libartd.so (art_quick_invoke_stub+338)\n"
329 " #37 pc 00146ab5 libartd.so "
330 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+885)\n"
331 " #38 pc 0039cf0d libartd.so "
332 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
333 "11ShadowFrameEtPNS_6JValueE+653)\n"
334 " #39 pc 00392552 libartd.so "
335 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
336 "6JValueEb+354)\n"
337 " #40 pc 0039399a libartd.so "
338 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
339 "20CodeItemDataAccessorEPNS_11ShadowFrameE+234)\n"
340 " #41 pc 00684362 libartd.so (artQuickToInterpreterBridge+1058)\n"
341 " #42 pc 006b35bd libartd.so (art_quick_to_interpreter_bridge+77)\n"
342 " #43 pc 0000eedc anonymous:ee74c000 (void Main.runPrimary()+60)\n"
343 " #44 pc 006ad4d2 libartd.so (art_quick_invoke_stub+338)\n"
344 " #45 pc 00146ab5 libartd.so "
345 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+885)\n"
346 " #46 pc 0039cf0d libartd.so "
347 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
348 "11ShadowFrameEtPNS_6JValueE+653)\n"
349 " #47 pc 00392552 libartd.so "
350 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
351 "6JValueEb+354)\n"
352 " #48 pc 0039399a libartd.so "
353 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
354 "20CodeItemDataAccessorEPNS_11ShadowFrameE+234)\n"
355 " #49 pc 00684362 libartd.so (artQuickToInterpreterBridge+1058)\n"
356 " #50 pc 006b35bd libartd.so (art_quick_to_interpreter_bridge+77)\n"
357 " #51 pc 0000ac22 anonymous:ee74c000 (void Main.main(java.lang.String[])+98)\n"
358 " #52 pc 006ad6a2 libartd.so (art_quick_invoke_static_stub+418)\n"
359 " #53 pc 00146acb libartd.so "
360 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+907)\n"
361 " #54 pc 0039cf0d libartd.so "
362 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
363 "11ShadowFrameEtPNS_6JValueE+653)\n"
364 " #55 pc 00392552 libartd.so "
365 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
366 "6JValueEb+354)\n"
367 " #56 pc 0039399a libartd.so "
368 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
369 "20CodeItemDataAccessorEPNS_11ShadowFrameE+234)\n"
370 " #57 pc 00684362 libartd.so (artQuickToInterpreterBridge+1058)\n"
371 " #58 pc 006b35bd libartd.so (art_quick_to_interpreter_bridge+77)\n"
372 " #59 pc 006ad6a2 libartd.so (art_quick_invoke_static_stub+418)\n"
373 " #60 pc 00146acb libartd.so "
374 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+907)\n"
375 " #61 pc 005aac95 libartd.so "
376 "(_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectAccessAlreadyRunnableEPNS_9ArtMethodEPNS_"
377 "8ArgArrayEPNS_6JValueEPKc+85)\n"
378 " #62 pc 005aab5a libartd.so "
379 "(_ZN3art17InvokeWithVarArgsERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_"
380 "jmethodIDPc+362)\n"
381 " #63 pc 0048a3dd libartd.so "
382 "(_ZN3art3JNI21CallStaticVoidMethodVEP7_JNIEnvP7_jclassP10_jmethodIDPc+125)\n"
383 " #64 pc 0018448c libartd.so "
384 "(_ZN3art8CheckJNI11CallMethodVEPKcP7_JNIEnvP8_jobjectP7_jclassP10_jmethodIDPcNS_"
385 "9Primitive4TypeENS_10InvokeTypeE+1964)\n"
386 " #65 pc 0017cf06 libartd.so "
387 "(_ZN3art8CheckJNI21CallStaticVoidMethodVEP7_JNIEnvP7_jclassP10_jmethodIDPc+70)\n"
388 " #66 pc 00001d8c dalvikvm32 "
389 "(_ZN7_JNIEnv20CallStaticVoidMethodEP7_jclassP10_jmethodIDz+60)\n"
390 " #67 pc 00001a80 dalvikvm32 (main+1312)\n"
391 " #68 pc 00018275 libc.so\n",
392 frame_info);
393}
394
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800395TEST_F(UnwindOfflineTest, jit_debug_arm) {
396 Init("jit_debug_arm/", ARCH_ARM);
Christopher Ferrised37aca2018-01-12 15:53:19 -0800397
398 MemoryOfflineParts* memory = new MemoryOfflineParts;
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800399 AddMemory(dir_ + "descriptor.data", memory);
400 AddMemory(dir_ + "descriptor1.data", memory);
401 AddMemory(dir_ + "stack.data", memory);
Christopher Ferrised37aca2018-01-12 15:53:19 -0800402 for (size_t i = 0; i < 7; i++) {
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800403 AddMemory(dir_ + "entry" + std::to_string(i) + ".data", memory);
404 AddMemory(dir_ + "jit" + std::to_string(i) + ".data", memory);
Christopher Ferrised37aca2018-01-12 15:53:19 -0800405 }
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800406 process_memory_.reset(memory);
Christopher Ferrised37aca2018-01-12 15:53:19 -0800407
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800408 JitDebug jit_debug(process_memory_);
409 Unwinder unwinder(128, maps_.get(), regs_.get(), process_memory_);
410 unwinder.SetJitDebug(&jit_debug, regs_->Arch());
Christopher Ferrised37aca2018-01-12 15:53:19 -0800411 unwinder.Unwind();
Christopher Ferrised37aca2018-01-12 15:53:19 -0800412
413 std::string frame_info(DumpFrames(unwinder));
414 ASSERT_EQ(76U, unwinder.NumFrames()) << "Unwind:\n" << frame_info;
415 EXPECT_EQ(
416 " #00 pc 00018a5e libarttestd.so (Java_Main_unwindInProcess+865)\n"
417 " #01 pc 0000212d (offset 0x2000) 137-cfi.odex (boolean Main.unwindInProcess(boolean, int, "
418 "boolean)+92)\n"
419 " #02 pc 00011cb1 anonymous:e2796000 (boolean Main.bar(boolean)+72)\n"
420 " #03 pc 00462175 libartd.so (art_quick_invoke_stub_internal+68)\n"
421 " #04 pc 00467129 libartd.so (art_quick_invoke_stub+228)\n"
422 " #05 pc 000bf7a9 libartd.so "
423 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+864)\n"
424 " #06 pc 00247833 libartd.so "
425 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
426 "11ShadowFrameEtPNS_6JValueE+382)\n"
427 " #07 pc 0022e935 libartd.so "
428 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
429 "6JValueEb+244)\n"
430 " #08 pc 0022f71d libartd.so "
431 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
432 "20CodeItemDataAccessorEPNS_11ShadowFrameE+128)\n"
433 " #09 pc 00442865 libartd.so (artQuickToInterpreterBridge+796)\n"
434 " #10 pc 004666ff libartd.so (art_quick_to_interpreter_bridge+30)\n"
435 " #11 pc 00011c31 anonymous:e2796000 (int Main.compare(Main, Main)+64)\n"
436 " #12 pc 00462175 libartd.so (art_quick_invoke_stub_internal+68)\n"
437 " #13 pc 00467129 libartd.so (art_quick_invoke_stub+228)\n"
438 " #14 pc 000bf7a9 libartd.so "
439 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+864)\n"
440 " #15 pc 00247833 libartd.so "
441 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
442 "11ShadowFrameEtPNS_6JValueE+382)\n"
443 " #16 pc 0022e935 libartd.so "
444 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
445 "6JValueEb+244)\n"
446 " #17 pc 0022f71d libartd.so "
447 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
448 "20CodeItemDataAccessorEPNS_11ShadowFrameE+128)\n"
449 " #18 pc 00442865 libartd.so (artQuickToInterpreterBridge+796)\n"
450 " #19 pc 004666ff libartd.so (art_quick_to_interpreter_bridge+30)\n"
451 " #20 pc 00011b77 anonymous:e2796000 (int Main.compare(java.lang.Object, "
452 "java.lang.Object)+118)\n"
453 " #21 pc 00462175 libartd.so (art_quick_invoke_stub_internal+68)\n"
454 " #22 pc 00467129 libartd.so (art_quick_invoke_stub+228)\n"
455 " #23 pc 000bf7a9 libartd.so "
456 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+864)\n"
457 " #24 pc 00247833 libartd.so "
458 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
459 "11ShadowFrameEtPNS_6JValueE+382)\n"
460 " #25 pc 0022e935 libartd.so "
461 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
462 "6JValueEb+244)\n"
463 " #26 pc 0022f71d libartd.so "
464 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
465 "20CodeItemDataAccessorEPNS_11ShadowFrameE+128)\n"
466 " #27 pc 00442865 libartd.so (artQuickToInterpreterBridge+796)\n"
467 " #28 pc 004666ff libartd.so (art_quick_to_interpreter_bridge+30)\n"
468 " #29 pc 00011a29 anonymous:e2796000 (int "
469 "java.util.Arrays.binarySearch0(java.lang.Object[], int, int, java.lang.Object, "
470 "java.util.Comparator)+304)\n"
471 " #30 pc 00462175 libartd.so (art_quick_invoke_stub_internal+68)\n"
472 " #31 pc 0046722f libartd.so (art_quick_invoke_static_stub+226)\n"
473 " #32 pc 000bf7bb libartd.so "
474 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+882)\n"
475 " #33 pc 00247833 libartd.so "
476 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
477 "11ShadowFrameEtPNS_6JValueE+382)\n"
478 " #34 pc 0022e935 libartd.so "
479 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
480 "6JValueEb+244)\n"
481 " #35 pc 0022f71d libartd.so "
482 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
483 "20CodeItemDataAccessorEPNS_11ShadowFrameE+128)\n"
484 " #36 pc 00442865 libartd.so (artQuickToInterpreterBridge+796)\n"
485 " #37 pc 004666ff libartd.so (art_quick_to_interpreter_bridge+30)\n"
486 " #38 pc 0001139b anonymous:e2796000 (boolean Main.foo()+178)\n"
487 " #39 pc 00462175 libartd.so (art_quick_invoke_stub_internal+68)\n"
488 " #40 pc 00467129 libartd.so (art_quick_invoke_stub+228)\n"
489 " #41 pc 000bf7a9 libartd.so "
490 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+864)\n"
491 " #42 pc 00247833 libartd.so "
492 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
493 "11ShadowFrameEtPNS_6JValueE+382)\n"
494 " #43 pc 0022e935 libartd.so "
495 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
496 "6JValueEb+244)\n"
497 " #44 pc 0022f71d libartd.so "
498 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
499 "20CodeItemDataAccessorEPNS_11ShadowFrameE+128)\n"
500 " #45 pc 00442865 libartd.so (artQuickToInterpreterBridge+796)\n"
501 " #46 pc 004666ff libartd.so (art_quick_to_interpreter_bridge+30)\n"
502 " #47 pc 00010aa7 anonymous:e2796000 (void Main.runPrimary()+70)\n"
503 " #48 pc 00462175 libartd.so (art_quick_invoke_stub_internal+68)\n"
504 " #49 pc 00467129 libartd.so (art_quick_invoke_stub+228)\n"
505 " #50 pc 000bf7a9 libartd.so "
506 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+864)\n"
507 " #51 pc 00247833 libartd.so "
508 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
509 "11ShadowFrameEtPNS_6JValueE+382)\n"
510 " #52 pc 0022e935 libartd.so "
511 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
512 "6JValueEb+244)\n"
513 " #53 pc 0022f71d libartd.so "
514 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
515 "20CodeItemDataAccessorEPNS_11ShadowFrameE+128)\n"
516 " #54 pc 00442865 libartd.so (artQuickToInterpreterBridge+796)\n"
517 " #55 pc 004666ff libartd.so (art_quick_to_interpreter_bridge+30)\n"
518 " #56 pc 0000ba99 anonymous:e2796000 (void Main.main(java.lang.String[])+144)\n"
519 " #57 pc 00462175 libartd.so (art_quick_invoke_stub_internal+68)\n"
520 " #58 pc 0046722f libartd.so (art_quick_invoke_static_stub+226)\n"
521 " #59 pc 000bf7bb libartd.so "
522 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+882)\n"
523 " #60 pc 00247833 libartd.so "
524 "(_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPNS_"
525 "11ShadowFrameEtPNS_6JValueE+382)\n"
526 " #61 pc 0022e935 libartd.so "
527 "(_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_"
528 "6JValueEb+244)\n"
529 " #62 pc 0022f71d libartd.so "
530 "(_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadERKNS_"
531 "20CodeItemDataAccessorEPNS_11ShadowFrameE+128)\n"
532 " #63 pc 00442865 libartd.so (artQuickToInterpreterBridge+796)\n"
533 " #64 pc 004666ff libartd.so (art_quick_to_interpreter_bridge+30)\n"
534 " #65 pc 00462175 libartd.so (art_quick_invoke_stub_internal+68)\n"
535 " #66 pc 0046722f libartd.so (art_quick_invoke_static_stub+226)\n"
536 " #67 pc 000bf7bb libartd.so "
537 "(_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+882)\n"
538 " #68 pc 003b292d libartd.so "
539 "(_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectAccessAlreadyRunnableEPNS_9ArtMethodEPNS_"
540 "8ArgArrayEPNS_6JValueEPKc+52)\n"
541 " #69 pc 003b26c3 libartd.so "
542 "(_ZN3art17InvokeWithVarArgsERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_"
543 "jmethodIDSt9__va_list+210)\n"
544 " #70 pc 00308411 libartd.so "
545 "(_ZN3art3JNI21CallStaticVoidMethodVEP7_JNIEnvP7_jclassP10_jmethodIDSt9__va_list+76)\n"
546 " #71 pc 000e6a9f libartd.so "
547 "(_ZN3art8CheckJNI11CallMethodVEPKcP7_JNIEnvP8_jobjectP7_jclassP10_jmethodIDSt9__va_listNS_"
548 "9Primitive4TypeENS_10InvokeTypeE+1486)\n"
549 " #72 pc 000e19b9 libartd.so "
550 "(_ZN3art8CheckJNI21CallStaticVoidMethodVEP7_JNIEnvP7_jclassP10_jmethodIDSt9__va_list+40)\n"
551 " #73 pc 0000159f dalvikvm32 "
552 "(_ZN7_JNIEnv20CallStaticVoidMethodEP7_jclassP10_jmethodIDz+30)\n"
553 " #74 pc 00001349 dalvikvm32 (main+896)\n"
554 " #75 pc 000850c9 libc.so\n",
555 frame_info);
556}
557
Christopher Ferris1a141a02018-01-24 08:52:47 -0800558// The eh_frame_hdr data is present but set to zero fdes. This should
559// fallback to iterating over the cies/fdes and ignore the eh_frame_hdr.
560// No .gnu_debugdata section in the elf file, so no symbols.
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800561TEST_F(UnwindOfflineTest, bad_eh_frame_hdr_arm64) {
562 Init("bad_eh_frame_hdr_arm64/", ARCH_ARM64);
Christopher Ferris1a141a02018-01-24 08:52:47 -0800563
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800564 Unwinder unwinder(128, maps_.get(), regs_.get(), process_memory_);
Christopher Ferris1a141a02018-01-24 08:52:47 -0800565 unwinder.Unwind();
Christopher Ferris1a141a02018-01-24 08:52:47 -0800566
567 std::string frame_info(DumpFrames(unwinder));
568 ASSERT_EQ(5U, unwinder.NumFrames()) << "Unwind:\n" << frame_info;
569 EXPECT_EQ(
570 " #00 pc 0000000000000550 waiter64\n"
571 " #01 pc 0000000000000568 waiter64\n"
572 " #02 pc 000000000000057c waiter64\n"
573 " #03 pc 0000000000000590 waiter64\n"
574 " #04 pc 00000000000a8e98 libc.so (__libc_init+88)\n",
575 frame_info);
576}
577
578// The elf has bad eh_frame unwind information for the pcs. If eh_frame
579// is used first, the unwind will not match the expected output.
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800580TEST_F(UnwindOfflineTest, debug_frame_first_x86) {
581 Init("debug_frame_first_x86/", ARCH_X86);
Christopher Ferris1a141a02018-01-24 08:52:47 -0800582
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800583 Unwinder unwinder(128, maps_.get(), regs_.get(), process_memory_);
Christopher Ferris1a141a02018-01-24 08:52:47 -0800584 unwinder.Unwind();
Christopher Ferris1a141a02018-01-24 08:52:47 -0800585
586 std::string frame_info(DumpFrames(unwinder));
587 ASSERT_EQ(5U, unwinder.NumFrames()) << "Unwind:\n" << frame_info;
588 EXPECT_EQ(
589 " #00 pc 00000685 waiter (call_level3+53)\n"
590 " #01 pc 000006b7 waiter (call_level2+23)\n"
591 " #02 pc 000006d7 waiter (call_level1+23)\n"
592 " #03 pc 000006f7 waiter (main+23)\n"
593 " #04 pc 00018275 libc.so\n",
594 frame_info);
595}
596
Christopher Ferrise37e2d02018-02-09 15:57:39 -0800597// Make sure that a pc that is at the beginning of an fde unwinds correctly.
598TEST_F(UnwindOfflineTest, eh_frame_hdr_begin_x86_64) {
599 Init("eh_frame_hdr_begin_x86_64/", ARCH_X86_64);
600
601 Unwinder unwinder(128, maps_.get(), regs_.get(), process_memory_);
602 unwinder.Unwind();
603
604 std::string frame_info(DumpFrames(unwinder));
605 ASSERT_EQ(5U, unwinder.NumFrames()) << "Unwind:\n" << frame_info;
606 EXPECT_EQ(
607 " #00 pc 0000000000000a80 unwind_test64 (calling3)\n"
608 " #01 pc 0000000000000dd9 unwind_test64 (calling2+633)\n"
609 " #02 pc 000000000000121e unwind_test64 (calling1+638)\n"
610 " #03 pc 00000000000013ed unwind_test64 (main+13)\n"
611 " #04 pc 00000000000202b0 libc.so\n",
612 frame_info);
613}
614
Christopher Ferrisc3d79f72017-11-28 19:14:54 -0800615} // namespace unwindstack