diff options
author | Christopher Ferris | 2018-05-21 15:26:04 -0500 |
---|---|---|
committer | Christopher Ferris | 2018-05-21 15:26:58 -0500 |
commit | 5e516cad9374161bc38369df8aa469c068cc6975 (patch) | |
tree | 5ad93d44472cbb8ae1f4c60c29367359423195f6 /libunwindstack | |
parent | e0a52774b4236f8dab6e1f0f246c6021ec0df698 (diff) | |
download | platform-system-core-5e516cad9374161bc38369df8aa469c068cc6975.tar.gz platform-system-core-5e516cad9374161bc38369df8aa469c068cc6975.tar.xz platform-system-core-5e516cad9374161bc38369df8aa469c068cc6975.zip |
Fix error messages handling.
Test: Builds.
Change-Id: I083ee4a51047e97e2ead78f40c82a21198f2b361
Diffstat (limited to 'libunwindstack')
-rw-r--r-- | libunwindstack/tools/unwind_for_offline.cpp | 14 |
1 files 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) { | |||
69 | bool SaveRegs(unwindstack::Regs* regs) { | 69 | bool SaveRegs(unwindstack::Regs* regs) { |
70 | std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("regs.txt", "w+"), &fclose); | 70 | std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("regs.txt", "w+"), &fclose); |
71 | if (fp == nullptr) { | 71 | if (fp == nullptr) { |
72 | printf("Failed to create file regs.txt.\n"); | 72 | perror("Failed to create file regs.txt"); |
73 | return false; | 73 | return false; |
74 | } | 74 | } |
75 | regs->IterateRegisters([&fp](const char* name, uint64_t value) { | 75 | regs->IterateRegisters([&fp](const char* name, uint64_t value) { |
@@ -102,13 +102,14 @@ bool SaveStack(pid_t pid, const std::vector<std::pair<uint64_t, uint64_t>>& stac | |||
102 | 102 | ||
103 | std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(file_name.c_str(), "w+"), &fclose); | 103 | std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(file_name.c_str(), "w+"), &fclose); |
104 | if (fp == nullptr) { | 104 | if (fp == nullptr) { |
105 | printf("Failed to create stack.data.\n"); | 105 | perror("Failed to create stack.data"); |
106 | return false; | 106 | return false; |
107 | } | 107 | } |
108 | 108 | ||
109 | size_t bytes = fwrite(&sp_start, 1, sizeof(sp_start), fp.get()); | 109 | size_t bytes = fwrite(&sp_start, 1, sizeof(sp_start), fp.get()); |
110 | if (bytes != sizeof(sp_start)) { | 110 | if (bytes != sizeof(sp_start)) { |
111 | perror("Failed to write all data."); | 111 | printf("Failed to write sp_start data: sizeof(sp_start) %zu, written %zu\n", sizeof(sp_start), |
112 | bytes); | ||
112 | return false; | 113 | return false; |
113 | } | 114 | } |
114 | 115 | ||
@@ -141,7 +142,7 @@ bool CreateElfFromMemory(std::shared_ptr<unwindstack::Memory>& memory, map_info_ | |||
141 | 142 | ||
142 | std::unique_ptr<FILE, decltype(&fclose)> output(fopen(cur_name.c_str(), "w+"), &fclose); | 143 | std::unique_ptr<FILE, decltype(&fclose)> output(fopen(cur_name.c_str(), "w+"), &fclose); |
143 | if (output == nullptr) { | 144 | if (output == nullptr) { |
144 | printf("Cannot create %s\n", cur_name.c_str()); | 145 | perror((std::string("Cannot create ") + cur_name).c_str()); |
145 | return false; | 146 | return false; |
146 | } | 147 | } |
147 | 148 | ||
@@ -160,13 +161,14 @@ bool CreateElfFromMemory(std::shared_ptr<unwindstack::Memory>& memory, map_info_ | |||
160 | bool CopyElfFromFile(map_info_t* info) { | 161 | bool CopyElfFromFile(map_info_t* info) { |
161 | std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(info->name.c_str(), "r"), &fclose); | 162 | std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(info->name.c_str(), "r"), &fclose); |
162 | if (fp == nullptr) { | 163 | if (fp == nullptr) { |
164 | perror((std::string("Cannot open ") + info->name).c_str()); | ||
163 | return false; | 165 | return false; |
164 | } | 166 | } |
165 | 167 | ||
166 | std::string cur_name = basename(info->name.c_str()); | 168 | std::string cur_name = basename(info->name.c_str()); |
167 | std::unique_ptr<FILE, decltype(&fclose)> output(fopen(cur_name.c_str(), "w+"), &fclose); | 169 | std::unique_ptr<FILE, decltype(&fclose)> output(fopen(cur_name.c_str(), "w+"), &fclose); |
168 | if (output == nullptr) { | 170 | if (output == nullptr) { |
169 | printf("Cannot create file %s\n", cur_name.c_str()); | 171 | perror((std::string("Cannot create file " + cur_name)).c_str()); |
170 | return false; | 172 | return false; |
171 | } | 173 | } |
172 | std::vector<uint8_t> buffer(10000); | 174 | std::vector<uint8_t> buffer(10000); |
@@ -265,7 +267,7 @@ int SaveData(pid_t pid) { | |||
265 | 267 | ||
266 | std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("maps.txt", "w+"), &fclose); | 268 | std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("maps.txt", "w+"), &fclose); |
267 | if (fp == nullptr) { | 269 | if (fp == nullptr) { |
268 | printf("Failed to create maps.txt.\n"); | 270 | perror("Failed to create maps.txt"); |
269 | return false; | 271 | return false; |
270 | } | 272 | } |
271 | 273 | ||