mirror of
https://git.suyu.dev/suyu/breakpad.git
synced 2026-01-10 00:18:27 +01:00
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 .
This commit is contained in:
parent
d091e5103f
commit
c77c51fae6
8 changed files with 314 additions and 211 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue