aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorLi Yan <lyan@chromium.org>2016-03-30 13:46:21 -0700
committerLi Yan <lyan@chromium.org>2016-03-30 13:46:21 -0700
commitc77c51fae6796fbe86ecafd6136ef9503251c035 (patch)
tree14a97e8013432c3aad82d7c95c35d96c592488cc /src/tools
parentMake EXC_BAD_ACCESS / EXC_I386_GPFLT print nicely in the processor (diff)
downloadbreakpad-c77c51fae6796fbe86ecafd6136ef9503251c035.tar.xz
Refactor sym_upload in tools to extract code into common/linux, and minor fixes
to code calling libcurl. This change may be used to build a tool to dump and upload symbols with multi-thread. BUG= R=mmandlis@chromium.org CC=google-breakpad-dev@googlegroups.com Review URL: https://codereview.chromium.org/1842113002 .
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/linux/symupload/sym_upload.cc131
1 files changed, 3 insertions, 128 deletions
diff --git a/src/tools/linux/symupload/sym_upload.cc b/src/tools/linux/symupload/sym_upload.cc
index 2f9a73c3..9eeb2d44 100644
--- a/src/tools/linux/symupload/sym_upload.cc
+++ b/src/tools/linux/symupload/sym_upload.cc
@@ -39,138 +39,13 @@
// cpu: the CPU that the module was built for
// symbol_file: the contents of the breakpad-format symbol file
-#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <functional>
-#include <iostream>
-#include <string>
-#include <vector>
+#include "common/linux/symbol_upload.h"
-#include "common/linux/http_upload.h"
-#include "common/using_std_string.h"
-
-using google_breakpad::HTTPUpload;
-
-typedef struct {
- string symbolsPath;
- string uploadURLStr;
- string proxy;
- string proxy_user_pwd;
- string version;
- bool success;
-} Options;
-
-static void TokenizeByChar(const string &source_string,
- int c, std::vector<string> *results) {
- assert(results);
- string::size_type cur_pos = 0, next_pos = 0;
- while ((next_pos = source_string.find(c, cur_pos)) != string::npos) {
- if (next_pos != cur_pos)
- results->push_back(source_string.substr(cur_pos, next_pos - cur_pos));
- cur_pos = next_pos + 1;
- }
- if (cur_pos < source_string.size() && next_pos != cur_pos)
- results->push_back(source_string.substr(cur_pos));
-}
-
-//=============================================================================
-// Parse out the module line which have 5 parts.
-// MODULE <os> <cpu> <uuid> <module-name>
-static bool ModuleDataForSymbolFile(const string &file,
- std::vector<string> *module_parts) {
- assert(module_parts);
- const size_t kModulePartNumber = 5;
- FILE* fp = fopen(file.c_str(), "r");
- if (fp) {
- char buffer[1024];
- if (fgets(buffer, sizeof(buffer), fp)) {
- string line(buffer);
- string::size_type line_break_pos = line.find_first_of('\n');
- if (line_break_pos == string::npos) {
- assert(0 && "The file is invalid!");
- fclose(fp);
- return false;
- }
- line.resize(line_break_pos);
- const char kDelimiter = ' ';
- TokenizeByChar(line, kDelimiter, module_parts);
- if (module_parts->size() != kModulePartNumber)
- module_parts->clear();
- }
- fclose(fp);
- }
-
- return module_parts->size() == kModulePartNumber;
-}
-
-//=============================================================================
-static string CompactIdentifier(const string &uuid) {
- std::vector<string> components;
- TokenizeByChar(uuid, '-', &components);
- string result;
- for (size_t i = 0; i < components.size(); ++i)
- result += components[i];
- return result;
-}
-
-//=============================================================================
-static void Start(Options *options) {
- std::map<string, string> parameters;
- options->success = false;
- std::vector<string> module_parts;
- if (!ModuleDataForSymbolFile(options->symbolsPath, &module_parts)) {
- fprintf(stderr, "Failed to parse symbol file!\n");
- return;
- }
-
- string compacted_id = CompactIdentifier(module_parts[3]);
-
- // Add parameters
- if (!options->version.empty())
- parameters["version"] = options->version;
-
- // MODULE <os> <cpu> <uuid> <module-name>
- // 0 1 2 3 4
- parameters["os"] = module_parts[1];
- parameters["cpu"] = module_parts[2];
- parameters["debug_file"] = module_parts[4];
- parameters["code_file"] = module_parts[4];
- parameters["debug_identifier"] = compacted_id;
-
- std::map<string, string> files;
- files["symbol_file"] = options->symbolsPath;
-
- string response, error;
- long response_code;
- bool success = HTTPUpload::SendRequest(options->uploadURLStr,
- parameters,
- files,
- options->proxy,
- options->proxy_user_pwd,
- "",
- &response,
- &response_code,
- &error);
-
- if (!success) {
- printf("Failed to send symbol file: %s\n", error.c_str());
- printf("Response code: %ld\n", response_code);
- printf("Response:\n");
- printf("%s\n", response.c_str());
- } else if (response_code == 0) {
- printf("Failed to send symbol file: No response code\n");
- } else if (response_code != 200) {
- printf("Failed to send symbol file: Response code %ld\n", response_code);
- printf("Response:\n");
- printf("%s\n", response.c_str());
- } else {
- printf("Successfully sent the symbol file.\n");
- }
- options->success = success;
-}
+using google_breakpad::sym_upload::Options;
//=============================================================================
static void
@@ -232,6 +107,6 @@ SetupOptions(int argc, const char *argv[], Options *options) {
int main(int argc, const char* argv[]) {
Options options;
SetupOptions(argc, argv, &options);
- Start(&options);
+ google_breakpad::sym_upload::Start(&options);
return options.success ? 0 : 1;
}