summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes2018-02-15 11:18:21 -0600
committerElliott Hughes2018-02-15 18:28:50 -0600
commite1415a5c3b3e279fd6cfb6a7ee73ddc98bbec2ae (patch)
tree93490451128e77d8f3a6fd3dcfb01c84975ef31d /debuggerd
parent73a2508dc4b2b6644e4904f013a6df5fff5e4569 (diff)
downloadplatform-system-core-e1415a5c3b3e279fd6cfb6a7ee73ddc98bbec2ae.tar.gz
platform-system-core-e1415a5c3b3e279fd6cfb6a7ee73ddc98bbec2ae.tar.xz
platform-system-core-e1415a5c3b3e279fd6cfb6a7ee73ddc98bbec2ae.zip
Include the map name when dumping memory around a register.
Bug: http://b/19590178 Test: ran tests, ran crasher Change-Id: Ib9afa34c860d8732ef1943eb4decd0b7c8fb55fd
Diffstat (limited to 'debuggerd')
-rw-r--r--debuggerd/libdebuggerd/include/libdebuggerd/utility.h2
-rw-r--r--debuggerd/libdebuggerd/test/dump_memory_test.cpp46
-rw-r--r--debuggerd/libdebuggerd/tombstone.cpp22
-rw-r--r--debuggerd/libdebuggerd/utility.cpp10
4 files changed, 42 insertions, 38 deletions
diff --git a/debuggerd/libdebuggerd/include/libdebuggerd/utility.h b/debuggerd/libdebuggerd/include/libdebuggerd/utility.h
index 0f049fd25..7b04e7192 100644
--- a/debuggerd/libdebuggerd/include/libdebuggerd/utility.h
+++ b/debuggerd/libdebuggerd/include/libdebuggerd/utility.h
@@ -68,7 +68,7 @@ namespace unwindstack {
68class Memory; 68class Memory;
69} 69}
70 70
71void dump_memory(log_t* log, unwindstack::Memory* backtrace, uint64_t addr, const char* fmt, ...); 71void dump_memory(log_t* log, unwindstack::Memory* backtrace, uint64_t addr, const std::string&);
72 72
73void read_with_default(const char* path, char* buf, size_t len, const char* default_value); 73void read_with_default(const char* path, char* buf, size_t len, const char* default_value);
74 74
diff --git a/debuggerd/libdebuggerd/test/dump_memory_test.cpp b/debuggerd/libdebuggerd/test/dump_memory_test.cpp
index 7c8a0ea14..be395824b 100644
--- a/debuggerd/libdebuggerd/test/dump_memory_test.cpp
+++ b/debuggerd/libdebuggerd/test/dump_memory_test.cpp
@@ -201,7 +201,7 @@ TEST_F(DumpMemoryTest, aligned_addr) {
201 } 201 }
202 memory_mock_->SetReadData(buffer, sizeof(buffer)); 202 memory_mock_->SetReadData(buffer, sizeof(buffer));
203 203
204 dump_memory(&log_, memory_mock_.get(), 0x12345678, "memory near %.2s:", "r1"); 204 dump_memory(&log_, memory_mock_.get(), 0x12345678, "memory near r1");
205 205
206 std::string tombstone_contents; 206 std::string tombstone_contents;
207 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 207 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -221,7 +221,7 @@ TEST_F(DumpMemoryTest, partial_read) {
221 memory_mock_->SetReadData(buffer, sizeof(buffer)); 221 memory_mock_->SetReadData(buffer, sizeof(buffer));
222 memory_mock_->SetPartialReadAmount(96); 222 memory_mock_->SetPartialReadAmount(96);
223 223
224 dump_memory(&log_, memory_mock_.get(), 0x12345679, "memory near %.2s:", "r1"); 224 dump_memory(&log_, memory_mock_.get(), 0x12345679, "memory near r1");
225 225
226 std::string tombstone_contents; 226 std::string tombstone_contents;
227 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 227 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -240,7 +240,7 @@ TEST_F(DumpMemoryTest, unaligned_addr) {
240 } 240 }
241 memory_mock_->SetReadData(buffer, sizeof(buffer)); 241 memory_mock_->SetReadData(buffer, sizeof(buffer));
242 242
243 dump_memory(&log_, memory_mock_.get(), 0x12345679, "memory near %.2s:", "r1"); 243 dump_memory(&log_, memory_mock_.get(), 0x12345679, "memory near r1");
244 244
245 std::string tombstone_contents; 245 std::string tombstone_contents;
246 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 246 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -253,7 +253,7 @@ TEST_F(DumpMemoryTest, unaligned_addr) {
253} 253}
254 254
255TEST_F(DumpMemoryTest, memory_unreadable) { 255TEST_F(DumpMemoryTest, memory_unreadable) {
256 dump_memory(&log_, memory_mock_.get(), 0xa2345678, "memory near pc:"); 256 dump_memory(&log_, memory_mock_.get(), 0xa2345678, "memory near pc");
257 257
258 std::string tombstone_contents; 258 std::string tombstone_contents;
259 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 259 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -309,7 +309,7 @@ TEST_F(DumpMemoryTest, memory_partially_unreadable) {
309 } 309 }
310 memory_mock_->SetReadData(buffer, sizeof(buffer)); 310 memory_mock_->SetReadData(buffer, sizeof(buffer));
311 311
312 dump_memory(&log_, memory_mock_.get(), 0x12345600, "memory near pc:"); 312 dump_memory(&log_, memory_mock_.get(), 0x12345600, "memory near pc");
313 313
314 std::string tombstone_contents; 314 std::string tombstone_contents;
315 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 315 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -329,7 +329,7 @@ TEST_F(DumpMemoryTest, memory_partially_unreadable_unaligned_return) {
329 memory_mock_->SetReadData(buffer, sizeof(buffer)); 329 memory_mock_->SetReadData(buffer, sizeof(buffer));
330 memory_mock_->SetPartialReadAmount(102); 330 memory_mock_->SetPartialReadAmount(102);
331 331
332 dump_memory(&log_, memory_mock_.get(), 0x12345600, "memory near pc:"); 332 dump_memory(&log_, memory_mock_.get(), 0x12345600, "memory near pc");
333 333
334 std::string tombstone_contents; 334 std::string tombstone_contents;
335 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 335 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -354,7 +354,7 @@ TEST_F(DumpMemoryTest, memory_partially_unreadable_two_unaligned_reads) {
354 memory_mock_->SetReadData(buffer, sizeof(buffer)); 354 memory_mock_->SetReadData(buffer, sizeof(buffer));
355 memory_mock_->SetPartialReadAmount(45); 355 memory_mock_->SetPartialReadAmount(45);
356 356
357 dump_memory(&log_, memory_mock_.get(), 0x12345600, "memory near pc:"); 357 dump_memory(&log_, memory_mock_.get(), 0x12345600, "memory near pc");
358 358
359 std::string tombstone_contents; 359 std::string tombstone_contents;
360 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 360 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -380,7 +380,7 @@ TEST_F(DumpMemoryTest, address_low_fence) {
380 memset(buffer, 0, sizeof(buffer)); 380 memset(buffer, 0, sizeof(buffer));
381 memory_mock_->SetReadData(buffer, sizeof(buffer)); 381 memory_mock_->SetReadData(buffer, sizeof(buffer));
382 382
383 dump_memory(&log_, memory_mock_.get(), 0x1000, "memory near %.2s:", "r1"); 383 dump_memory(&log_, memory_mock_.get(), 0x1000, "memory near r1");
384 384
385 std::string tombstone_contents; 385 std::string tombstone_contents;
386 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 386 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -434,7 +434,7 @@ TEST_F(DumpMemoryTest, memory_address_too_low) {
434 memset(buffer, 0, sizeof(buffer)); 434 memset(buffer, 0, sizeof(buffer));
435 memory_mock_->SetReadData(buffer, sizeof(buffer)); 435 memory_mock_->SetReadData(buffer, sizeof(buffer));
436 436
437 dump_memory(&log_, memory_mock_.get(), 0, "memory near %.2s:", "r1"); 437 dump_memory(&log_, memory_mock_.get(), 0, "memory near r1");
438 438
439 std::string tombstone_contents; 439 std::string tombstone_contents;
440 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 440 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -452,13 +452,13 @@ TEST_F(DumpMemoryTest, memory_address_too_high) {
452 memory_mock_->SetReadData(buffer, sizeof(buffer)); 452 memory_mock_->SetReadData(buffer, sizeof(buffer));
453 453
454#if defined(__LP64__) 454#if defined(__LP64__)
455 dump_memory(&log_, memory_mock_.get(), 0x4000000000000000UL, "memory near %.2s:", "r1"); 455 dump_memory(&log_, memory_mock_.get(), 0x4000000000000000UL, "memory near r1");
456 dump_memory(&log_, memory_mock_.get(), 0x4000000000000000UL - 32, "memory near %.2s:", "r1"); 456 dump_memory(&log_, memory_mock_.get(), 0x4000000000000000UL - 32, "memory near r1");
457 dump_memory(&log_, memory_mock_.get(), 0x4000000000000000UL - 216, "memory near %.2s:", "r1"); 457 dump_memory(&log_, memory_mock_.get(), 0x4000000000000000UL - 216, "memory near r1");
458#else 458#else
459 dump_memory(&log_, memory_mock_.get(), 0xffff0000, "memory near %.2s:", "r1"); 459 dump_memory(&log_, memory_mock_.get(), 0xffff0000, "memory near r1");
460 dump_memory(&log_, memory_mock_.get(), 0xffff0000 - 32, "memory near %.2s:", "r1"); 460 dump_memory(&log_, memory_mock_.get(), 0xffff0000 - 32, "memory near r1");
461 dump_memory(&log_, memory_mock_.get(), 0xffff0000 - 220, "memory near %.2s:", "r1"); 461 dump_memory(&log_, memory_mock_.get(), 0xffff0000 - 220, "memory near r1");
462#endif 462#endif
463 463
464 std::string tombstone_contents; 464 std::string tombstone_contents;
@@ -477,9 +477,9 @@ TEST_F(DumpMemoryTest, memory_address_would_overflow) {
477 memory_mock_->SetReadData(buffer, sizeof(buffer)); 477 memory_mock_->SetReadData(buffer, sizeof(buffer));
478 478
479#if defined(__LP64__) 479#if defined(__LP64__)
480 dump_memory(&log_, memory_mock_.get(), 0xfffffffffffffff0, "memory near %.2s:", "r1"); 480 dump_memory(&log_, memory_mock_.get(), 0xfffffffffffffff0, "memory near r1");
481#else 481#else
482 dump_memory(&log_, memory_mock_.get(), 0xfffffff0, "memory near %.2s:", "r1"); 482 dump_memory(&log_, memory_mock_.get(), 0xfffffff0, "memory near r1");
483#endif 483#endif
484 484
485 std::string tombstone_contents; 485 std::string tombstone_contents;
@@ -500,9 +500,9 @@ TEST_F(DumpMemoryTest, memory_address_nearly_too_high) {
500 memory_mock_->SetReadData(buffer, sizeof(buffer)); 500 memory_mock_->SetReadData(buffer, sizeof(buffer));
501 501
502#if defined(__LP64__) 502#if defined(__LP64__)
503 dump_memory(&log_, memory_mock_.get(), 0x4000000000000000UL - 224, "memory near %.2s:", "r4"); 503 dump_memory(&log_, memory_mock_.get(), 0x4000000000000000UL - 224, "memory near r4");
504#else 504#else
505 dump_memory(&log_, memory_mock_.get(), 0xffff0000 - 224, "memory near %.2s:", "r4"); 505 dump_memory(&log_, memory_mock_.get(), 0xffff0000 - 224, "memory near r4");
506#endif 506#endif
507 507
508 std::string tombstone_contents; 508 std::string tombstone_contents;
@@ -562,7 +562,7 @@ TEST_F(DumpMemoryTest, first_read_empty) {
562 562
563 size_t page_size = sysconf(_SC_PAGE_SIZE); 563 size_t page_size = sysconf(_SC_PAGE_SIZE);
564 uintptr_t addr = 0x10000020 + page_size - 120; 564 uintptr_t addr = 0x10000020 + page_size - 120;
565 dump_memory(&log_, memory_mock_.get(), addr, "memory near %.2s:", "r4"); 565 dump_memory(&log_, memory_mock_.get(), addr, "memory near r4");
566 566
567 std::string tombstone_contents; 567 std::string tombstone_contents;
568 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 568 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -621,7 +621,7 @@ TEST_F(DumpMemoryTest, first_read_empty_second_read_stops) {
621 621
622 size_t page_size = sysconf(_SC_PAGE_SIZE); 622 size_t page_size = sysconf(_SC_PAGE_SIZE);
623 uintptr_t addr = 0x10000020 + page_size - 192; 623 uintptr_t addr = 0x10000020 + page_size - 192;
624 dump_memory(&log_, memory_mock_.get(), addr, "memory near %.2s:", "r4"); 624 dump_memory(&log_, memory_mock_.get(), addr, "memory near r4");
625 625
626 std::string tombstone_contents; 626 std::string tombstone_contents;
627 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 627 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -679,7 +679,7 @@ TEST_F(DumpMemoryTest, first_read_empty_next_page_out_of_range) {
679 memory_mock_->SetPartialReadAmount(0); 679 memory_mock_->SetPartialReadAmount(0);
680 680
681 uintptr_t addr = 0x10000020; 681 uintptr_t addr = 0x10000020;
682 dump_memory(&log_, memory_mock_.get(), addr, "memory near %.2s:", "r4"); 682 dump_memory(&log_, memory_mock_.get(), addr, "memory near r4");
683 683
684 std::string tombstone_contents; 684 std::string tombstone_contents;
685 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 685 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
@@ -739,7 +739,7 @@ TEST_F(DumpMemoryTest, first_read_empty_next_page_out_of_range_fence_post) {
739 size_t page_size = sysconf(_SC_PAGE_SIZE); 739 size_t page_size = sysconf(_SC_PAGE_SIZE);
740 uintptr_t addr = 0x10000020 + page_size - 256; 740 uintptr_t addr = 0x10000020 + page_size - 256;
741 741
742 dump_memory(&log_, memory_mock_.get(), addr, "memory near %.2s:", "r4"); 742 dump_memory(&log_, memory_mock_.get(), addr, "memory near r4");
743 743
744 std::string tombstone_contents; 744 std::string tombstone_contents;
745 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0); 745 ASSERT_TRUE(lseek(log_.tfd, 0, SEEK_SET) == 0);
diff --git a/debuggerd/libdebuggerd/tombstone.cpp b/debuggerd/libdebuggerd/tombstone.cpp
index 7d8560213..140ef6d23 100644
--- a/debuggerd/libdebuggerd/tombstone.cpp
+++ b/debuggerd/libdebuggerd/tombstone.cpp
@@ -65,6 +65,8 @@ using android::base::unique_fd;
65using unwindstack::Memory; 65using unwindstack::Memory;
66using unwindstack::Regs; 66using unwindstack::Regs;
67 67
68using namespace std::literals::string_literals;
69
68#define STACK_WORDS 16 70#define STACK_WORDS 16
69 71
70static void dump_header_info(log_t* log) { 72static void dump_header_info(log_t* log) {
@@ -148,8 +150,9 @@ static void dump_stack_segment(log_t* log, BacktraceMap* backtrace_map, Memory*
148 150
149 backtrace_map_t map; 151 backtrace_map_t map;
150 backtrace_map->FillIn(stack_data[i], &map); 152 backtrace_map->FillIn(stack_data[i], &map);
151 if (BacktraceMap::IsValid(map) && !map.name.empty()) { 153 std::string map_name{map.Name()};
152 line += " " + map.name; 154 if (BacktraceMap::IsValid(map) && !map_name.empty()) {
155 line += " " + map_name;
153 uint64_t offset = 0; 156 uint64_t offset = 0;
154 std::string func_name = backtrace_map->GetFunctionName(stack_data[i], &offset); 157 std::string func_name = backtrace_map->GetFunctionName(stack_data[i], &offset);
155 if (!func_name.empty()) { 158 if (!func_name.empty()) {
@@ -382,9 +385,16 @@ void dump_registers(log_t* log, Regs* regs) {
382 print_register_row(log, special_row); 385 print_register_row(log, special_row);
383} 386}
384 387
385void dump_memory_and_code(log_t* log, Memory* memory, Regs* regs) { 388void dump_memory_and_code(log_t* log, BacktraceMap* map, Memory* memory, Regs* regs) {
386 regs->IterateRegisters([log, memory](const char* name, uint64_t value) { 389 regs->IterateRegisters([log, map, memory](const char* reg_name, uint64_t reg_value) {
387 dump_memory(log, memory, value, "memory near %s:", name); 390 std::string label{"memory near "s + reg_name};
391 if (map) {
392 backtrace_map_t map_info;
393 map->FillIn(reg_value, &map_info);
394 std::string map_name{map_info.Name()};
395 if (!map_name.empty()) label += " (" + map_info.Name() + ")";
396 }
397 dump_memory(log, memory, reg_value, label);
388 }); 398 });
389} 399}
390 400
@@ -423,7 +433,7 @@ static bool dump_thread(log_t* log, BacktraceMap* map, Memory* process_memory,
423 } 433 }
424 434
425 if (primary_thread) { 435 if (primary_thread) {
426 dump_memory_and_code(log, process_memory, thread_info.registers.get()); 436 dump_memory_and_code(log, map, process_memory, thread_info.registers.get());
427 if (map) { 437 if (map) {
428 uint64_t addr = 0; 438 uint64_t addr = 0;
429 siginfo_t* si = thread_info.siginfo; 439 siginfo_t* si = thread_info.siginfo;
diff --git a/debuggerd/libdebuggerd/utility.cpp b/debuggerd/libdebuggerd/utility.cpp
index 3ac98f58f..d1538653d 100644
--- a/debuggerd/libdebuggerd/utility.cpp
+++ b/debuggerd/libdebuggerd/utility.cpp
@@ -124,13 +124,7 @@ void _LOG(log_t* log, enum logtype ltype, const char* fmt, ...) {
124#define MEMORY_BYTES_TO_DUMP 256 124#define MEMORY_BYTES_TO_DUMP 256
125#define MEMORY_BYTES_PER_LINE 16 125#define MEMORY_BYTES_PER_LINE 16
126 126
127void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const char* fmt, ...) { 127void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const std::string& label) {
128 std::string log_msg;
129 va_list ap;
130 va_start(ap, fmt);
131 android::base::StringAppendV(&log_msg, fmt, ap);
132 va_end(ap);
133
134 // Align the address to sizeof(long) and start 32 bytes before the address. 128 // Align the address to sizeof(long) and start 32 bytes before the address.
135 addr &= ~(sizeof(long) - 1); 129 addr &= ~(sizeof(long) - 1);
136 if (addr >= 4128) { 130 if (addr >= 4128) {
@@ -147,7 +141,7 @@ void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const c
147 return; 141 return;
148 } 142 }
149 143
150 _LOG(log, logtype::MEMORY, "\n%s\n", log_msg.c_str()); 144 _LOG(log, logtype::MEMORY, "\n%s:\n", label.c_str());
151 145
152 // Dump 256 bytes 146 // Dump 256 bytes
153 uintptr_t data[MEMORY_BYTES_TO_DUMP/sizeof(uintptr_t)]; 147 uintptr_t data[MEMORY_BYTES_TO_DUMP/sizeof(uintptr_t)];