Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1241)

Unified Diff: src/tools/linux/symupload/sym_upload.cc

Issue 1842113002: Refactor sym_upload in tools to extract code into common/linux, and minor fixes (Closed) Base URL: https://chromium.googlesource.com/breakpad/breakpad.git@master
Patch Set: one more fix indent Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/common/linux/symbol_upload.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/tools/linux/symupload/sym_upload.cc
diff --git a/src/tools/linux/symupload/sym_upload.cc b/src/tools/linux/symupload/sym_upload.cc
index 2f9a73c39f8b6e2e8866e6462de264bb88c7605a..9eeb2d447e327e18170720087e256cf23de7d45e 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;
}
« no previous file with comments | « src/common/linux/symbol_upload.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698