From 5e516cad9374161bc38369df8aa469c068cc6975 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Mon, 21 May 2018 13:26:04 -0700 Subject: [PATCH] Fix error messages handling. Test: Builds. Change-Id: I083ee4a51047e97e2ead78f40c82a21198f2b361 --- libunwindstack/tools/unwind_for_offline.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libunwindstack/tools/unwind_for_offline.cpp b/libunwindstack/tools/unwind_for_offline.cpp index 589731d0e..640992f62 100644 --- a/libunwindstack/tools/unwind_for_offline.cpp +++ b/libunwindstack/tools/unwind_for_offline.cpp @@ -69,7 +69,7 @@ static bool Attach(pid_t pid) { bool SaveRegs(unwindstack::Regs* regs) { std::unique_ptr fp(fopen("regs.txt", "w+"), &fclose); if (fp == nullptr) { - printf("Failed to create file regs.txt.\n"); + perror("Failed to create file regs.txt"); return false; } regs->IterateRegisters([&fp](const char* name, uint64_t value) { @@ -102,13 +102,14 @@ bool SaveStack(pid_t pid, const std::vector>& stac std::unique_ptr fp(fopen(file_name.c_str(), "w+"), &fclose); if (fp == nullptr) { - printf("Failed to create stack.data.\n"); + perror("Failed to create stack.data"); return false; } size_t bytes = fwrite(&sp_start, 1, sizeof(sp_start), fp.get()); if (bytes != sizeof(sp_start)) { - perror("Failed to write all data."); + printf("Failed to write sp_start data: sizeof(sp_start) %zu, written %zu\n", sizeof(sp_start), + bytes); return false; } @@ -141,7 +142,7 @@ bool CreateElfFromMemory(std::shared_ptr& memory, map_info_ std::unique_ptr output(fopen(cur_name.c_str(), "w+"), &fclose); if (output == nullptr) { - printf("Cannot create %s\n", cur_name.c_str()); + perror((std::string("Cannot create ") + cur_name).c_str()); return false; } @@ -160,13 +161,14 @@ bool CreateElfFromMemory(std::shared_ptr& memory, map_info_ bool CopyElfFromFile(map_info_t* info) { std::unique_ptr fp(fopen(info->name.c_str(), "r"), &fclose); if (fp == nullptr) { + perror((std::string("Cannot open ") + info->name).c_str()); return false; } std::string cur_name = basename(info->name.c_str()); std::unique_ptr output(fopen(cur_name.c_str(), "w+"), &fclose); if (output == nullptr) { - printf("Cannot create file %s\n", cur_name.c_str()); + perror((std::string("Cannot create file " + cur_name)).c_str()); return false; } std::vector buffer(10000); @@ -265,7 +267,7 @@ int SaveData(pid_t pid) { std::unique_ptr fp(fopen("maps.txt", "w+"), &fclose); if (fp == nullptr) { - printf("Failed to create maps.txt.\n"); + perror("Failed to create maps.txt"); return false; }