From 57f0630cc52fdafe6848274eac316669c6c39b10 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Fri, 25 May 2012 17:05:55 +0000 Subject: [PATCH] Reading memory from a file when the section is encrypted doesn't show an error. No we do. llvm-svn: 157484 --- lldb/include/lldb/Core/Disassembler.h | 3 ++- lldb/source/Commands/CommandObjectMemory.cpp | 11 +++++++++-- lldb/source/Core/Disassembler.cpp | 19 ++++++++++++++++--- lldb/source/Target/Target.cpp | 1 + 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lldb/include/lldb/Core/Disassembler.h b/lldb/include/lldb/Core/Disassembler.h index f735840..6f0735a 100644 --- a/lldb/include/lldb/Core/Disassembler.h +++ b/lldb/include/lldb/Core/Disassembler.h @@ -338,7 +338,8 @@ public: size_t ParseInstructions (const ExecutionContext *exe_ctx, - const AddressRange &range); + const AddressRange &range, + Stream *error_strm_ptr); size_t ParseInstructions (const ExecutionContext *exe_ctx, diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index c312816..6b495ac 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -613,8 +613,15 @@ public: bytes_read = target->ReadMemory(address, false, data_sp->GetBytes (), data_sp->GetByteSize(), error); if (bytes_read == 0) { - result.AppendWarningWithFormat("Read from 0x%llx failed.\n", addr); - result.AppendError(error.AsCString()); + const char *error_cstr = error.AsCString(); + if (error_cstr && error_cstr[0]) + { + result.AppendError(error_cstr); + } + else + { + result.AppendErrorWithFormat("failed to read memory from 0x%llx.\n", addr); + } result.SetStatus(eReturnStatusFailed); return false; } diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp index ab375c9..cb5b14f 100644 --- a/lldb/source/Core/Disassembler.cpp +++ b/lldb/source/Core/Disassembler.cpp @@ -225,7 +225,7 @@ Disassembler::DisassembleRange if (disasm_sp) { - size_t bytes_disassembled = disasm_sp->ParseInstructions (&exe_ctx, range); + size_t bytes_disassembled = disasm_sp->ParseInstructions (&exe_ctx, range, NULL); if (bytes_disassembled == 0) disasm_sp.reset(); } @@ -290,7 +290,7 @@ Disassembler::Disassemble ResolveAddress (exe_ctx, disasm_range.GetBaseAddress(), range.GetBaseAddress()); range.SetByteSize (disasm_range.GetByteSize()); - size_t bytes_disassembled = disasm_ap->ParseInstructions (&exe_ctx, range); + size_t bytes_disassembled = disasm_ap->ParseInstructions (&exe_ctx, range, &strm); if (bytes_disassembled == 0) return false; @@ -1010,7 +1010,8 @@ size_t Disassembler::ParseInstructions ( const ExecutionContext *exe_ctx, - const AddressRange &range + const AddressRange &range, + Stream *error_strm_ptr ) { if (exe_ctx) @@ -1040,6 +1041,18 @@ Disassembler::ParseInstructions m_arch.GetAddressByteSize()); return DecodeInstructions (range.GetBaseAddress(), data, 0, UINT32_MAX, false); } + else if (error_strm_ptr) + { + const char *error_cstr = error.AsCString(); + if (error_cstr) + { + error_strm_ptr->Printf("error: %s\n", error_cstr); + } + } + } + else if (error_strm_ptr) + { + error_strm_ptr->PutCString("error: invalid execution context\n"); } return 0; } diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 442c08e..25d18aa 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1062,6 +1062,7 @@ Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, // If the contents of this section are encrypted, the on-disk file is unusuable. Read only from live memory. if (section_sp->IsEncrypted()) { + error.SetErrorString("section is encrypted"); return 0; } ModuleSP module_sp (section_sp->GetModule()); -- 2.7.4