Skip to content

Commit

Permalink
fix stack parser
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaiu committed May 8, 2018
1 parent e30f21d commit 9e687ff
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 82 deletions.
4 changes: 2 additions & 2 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"tests"
],
"dependencies": {
"dub": "~>1.8.0",
"dub": "~>1.9.0",
"fluent-asserts": ">=0.11.4",
"libdparse": {
"version": ">=0.8.0",
Expand Down Expand Up @@ -124,7 +124,7 @@
"views"
],
"dependencies": {
"dub": "~>1.8.0",
"dub": "~>1.9.0",
"vibe-d:http": "~>0.8.2",
"vibe-d:data": "~>0.8.2",
"libdparse": "~master"
Expand Down
8 changes: 4 additions & 4 deletions dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"botan-math": "1.0.3",
"ddmp": "0.0.1-0.dev.3",
"diet-ng": "1.4.5",
"dub": "1.8.0",
"dub": "1.9.0",
"eventcore": "0.8.34",
"fluent-asserts": "0.11.3",
"fluent-asserts": "0.11.4",
"libasync": "0.8.3",
"libdparse": "~master",
"libdparse": "0.8.3",
"libevent": "2.0.2+2.0.16",
"memutils": "0.4.10",
"openssl": "1.1.6+1.0.1g",
"razer-d": "0.2.0",
"stdx-allocator": "2.77.0",
"stdx-allocator": "2.77.1",
"taggedalgebraic": "0.10.11",
"trial-razer": "0.1.1",
"vibe-core": "1.4.0",
Expand Down
154 changes: 78 additions & 76 deletions lifecycle/trial/stackresult.d
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,17 @@ struct Frame
///
int line = -1;

///
bool invalid = true;

///
string raw;

string toString() const @safe {
if(raw != "") {
return raw;
}

string result;

if(index >= 0) {
Expand Down Expand Up @@ -393,6 +403,12 @@ struct Frame
version(Have_fluent_asserts_core) {
void print(ResultPrinter printer) @safe
{
if(raw != "") {
printer.primary(raw);

return;
}

if(index >= 0) {
printer.info(leftJustifier(index.to!string, 4).to!string);
}
Expand Down Expand Up @@ -591,6 +607,11 @@ Frame toDarwinFrame(string line)

auto matched = matchFirst(line, darwinPattern);

if(matched.length < 5) {
return frame;
}

frame.invalid = false;
frame.index = matched["index"].to!int;
frame.moduleName = matched["module"];
frame.address = matched["address"];
Expand All @@ -608,14 +629,16 @@ Frame toWindows1Frame(string line)
auto matched = matchFirst(line,
address ~ `(\s+)in(\s+)` ~ name ~ `(\s+)at(\s+)` ~ file ~ `\(` ~ linePattern ~ `\)`); // ~ );

if(matched.length < 4) {
return frame;
}

frame.address = matched["address"];
frame.name = matched["name"];
frame.file = matched["file"];
frame.line = matched["line"].to!int;

enforce(frame.address != "", "address not found");
enforce(frame.name != "", "name not found");
enforce(frame.file != "", "file not found");

frame.invalid = frame.address == "" || frame.name == "" || frame.file == "";

return frame;
}
Expand All @@ -626,11 +649,15 @@ Frame toWindows2Frame(string line)
Frame frame;

auto matched = matchFirst(line, address ~ `(\s+)in(\s+)` ~ name);

if(matched.length < 2) {
return frame;
}

frame.address = matched["address"];
frame.name = matched["name"];

enforce(frame.address != "", "address not found");
enforce(frame.name != "", "name not found");
frame.invalid = frame.address == "" || frame.name == "";

return frame;
}
Expand All @@ -642,6 +669,10 @@ Frame toGLibCFrame(string line)

auto matched = matchFirst(line, moduleName ~ `\(` ~ name ~ `\)\s+\[` ~ address ~ `\]`);

if(matched.length < 3) {
return frame;
}

frame.address = matched["address"];
frame.name = matched["name"];
frame.moduleName = matched["module"];
Expand All @@ -654,10 +685,8 @@ Frame toGLibCFrame(string line)
frame.name = frame.name[0 .. plusSign];
}

enforce(frame.address != "", "address not found");
enforce(frame.name != "", "name not found");
enforce(frame.name.indexOf("(") == -1, "name should not contain `(`");
enforce(frame.moduleName != "", "module not found");
frame.invalid = frame.address == "" || frame.name == "" || frame.moduleName == "" ||
frame.name.indexOf("(") >= 0;

return frame;
}
Expand All @@ -669,15 +698,16 @@ Frame toNetBsdFrame(string line)

auto matched = matchFirst(line, address ~ `\s+<` ~ name ~ `\+` ~ offset ~ `>\s+at\s+` ~ moduleName);

if(matched.length < 4) {
return frame;
}

frame.address = matched["address"];
frame.name = matched["name"];
frame.moduleName = matched["module"];
frame.offset = matched["offset"];

enforce(frame.address != "", "address not found");
enforce(frame.name != "", "name not found");
enforce(frame.moduleName != "", "module not found");
enforce(frame.offset != "", "offset not found");
frame.invalid = frame.address == "" || frame.name == "" || frame.moduleName == "" || frame.offset == "";

return frame;
}
Expand All @@ -688,15 +718,16 @@ Frame toLinuxFrame(string line) {

auto matched = matchFirst(line, file ~ `:` ~ linePattern ~ `\s+` ~ name ~ `\s+\[` ~ address ~ `\]`);

if(matched.length < 4) {
return frame;
}

frame.file = matched["file"];
frame.name = matched["name"];
frame.address = matched["address"];
frame.line = matched["line"].to!int;

enforce(frame.address != "", "address not found");
enforce(frame.name != "", "name not found");
enforce(frame.file != "", "file not found");
enforce(frame.line > 0, "line not found");
frame.invalid = frame.address == "" || frame.name == "" || frame.file == "" || frame.line == 0;

return frame;
}
Expand All @@ -707,11 +738,14 @@ Frame toMissingInfoLinuxFrame(string line) {

auto matched = matchFirst(line, `\?\?:\?\s+` ~ name ~ `\s+\[` ~ address ~ `\]`);

if(matched.length < 2) {
return frame;
}

frame.name = matched["name"];
frame.address = matched["address"];

enforce(frame.address != "", "address not found");
enforce(frame.name != "", "name not found");
frame.invalid = frame.address == "" || frame.name == "";

return frame;
}
Expand All @@ -720,64 +754,21 @@ Frame toMissingInfoLinuxFrame(string line) {
Frame toFrame(string line)
{
Frame frame;
frame.raw = line;
frame.invalid = false;

try
{
return line.toDarwinFrame;
}
catch (Exception e)
{
}
auto frames = [
line.toDarwinFrame,
line.toWindows1Frame,
line.toWindows2Frame,
line.toGLibCFrame,
line.toNetBsdFrame,
line.toLinuxFrame,
line.toMissingInfoLinuxFrame,
frame
];

try
{
return line.toWindows1Frame;
}
catch (Exception e)
{
}

try
{
return line.toWindows2Frame;
}
catch (Exception e)
{
}

try
{
return line.toGLibCFrame;
}
catch (Exception e)
{
}

try
{
return line.toNetBsdFrame;
}
catch (Exception e)
{
}

try
{
return line.toLinuxFrame;
}
catch (Exception e)
{
}

try
{
return line.toMissingInfoLinuxFrame;
}
catch (Exception e)
{
}

return frame;
return frames.filter!(a => !a.invalid).front;
}

@("Get frame info from Darwin platform format")
Expand All @@ -786,6 +777,7 @@ unittest
auto line = "1 ???fluent-asserts 0x00abcdef000000 D6module4funcAFZv + 0";

auto frame = line.toFrame;
frame.invalid.should.equal(false);
frame.index.should.equal(1);
frame.moduleName.should.equal("???fluent-asserts");
frame.address.should.equal("0x00abcdef000000");
Expand All @@ -799,6 +791,7 @@ unittest
auto line = "0x779CAB5A in RtlInitializeExceptionChain";

auto frame = line.toFrame;
frame.invalid.should.equal(false);
frame.index.should.equal(-1);
frame.moduleName.should.equal("");
frame.address.should.equal("0x779CAB5A");
Expand All @@ -812,6 +805,7 @@ unittest
auto line = `0x00402669 in void app.__unitestL82_8() at D:\tidynumbers\source\app.d(84)`;

auto frame = line.toFrame;
frame.invalid.should.equal(false);
frame.index.should.equal(-1);
frame.moduleName.should.equal("");
frame.address.should.equal("0x00402669");
Expand All @@ -828,6 +822,7 @@ unittest

auto frame = line.toFrame;

frame.invalid.should.equal(false);
frame.moduleName.should.equal("module");
frame.name.should.equal("_D6module4funcAFZv");
frame.address.should.equal("0x00000000");
Expand All @@ -842,6 +837,7 @@ unittest

auto frame = line.toFrame;

frame.invalid.should.equal(false);
frame.moduleName.should.equal("module");
frame.name.should.equal("_D6module4funcAFZv");
frame.address.should.equal("0x00000000");
Expand All @@ -856,6 +852,7 @@ unittest

auto frame = line.toFrame;

frame.invalid.should.equal(false);
frame.moduleName.should.equal("module");
frame.name.should.equal("_D6module4funcAFZv");
frame.address.should.equal("0x00000000");
Expand All @@ -869,6 +866,7 @@ unittest {

auto frame = line.toFrame;

frame.invalid.should.equal(false);
frame.moduleName.should.equal("");
frame.file.should.equal("generated.d");
frame.line.should.equal(45);
Expand All @@ -883,6 +881,7 @@ unittest {
auto line = `lifecycle/trial/runner.d:106 trial.interfaces.SuiteResult[] trial.runner.runTests(const(trial.interfaces.TestCase)[], immutable(char)[]) [0x8b0ec1]`;
auto frame = line.toFrame;

frame.invalid.should.equal(false);
frame.moduleName.should.equal("");
frame.file.should.equal("lifecycle/trial/runner.d");
frame.line.should.equal(106);
Expand All @@ -897,6 +896,7 @@ unittest {
auto line = `../../.dub/packages/fluent-asserts-0.6.6/fluent-asserts/core/fluentasserts/core/base.d:39 void fluentasserts.core.base.Result.perform() [0x8f4b47]`;
auto frame = line.toFrame;

frame.invalid.should.equal(false);
frame.moduleName.should.equal("");
frame.file.should.equal("../../.dub/packages/fluent-asserts-0.6.6/fluent-asserts/core/fluentasserts/core/base.d");
frame.line.should.equal(39);
Expand All @@ -911,6 +911,7 @@ unittest {
auto line = `lifecycle/trial/discovery/unit.d:268 _D5trial9discovery4unit17UnitTestDiscovery231__T12addTestCasesVAyaa62_2f686f6d652f626f737a2f776f726b73706163652f64746573742f6c6966656379636c652f747269616c2f6578656375746f722f706172616c6c656c2e64VAyaa23_747269616c2e6578656375746f722e706172616c6c656cS245trial8executor8parallelZ12addTestCasesMFZ9__lambda4FZv [0x872000]`;
auto frame = line.toFrame;

frame.invalid.should.equal(false);
frame.moduleName.should.equal("");
frame.file.should.equal("lifecycle/trial/discovery/unit.d");
frame.line.should.equal(268);
Expand All @@ -925,6 +926,7 @@ unittest {
auto line = `??:? __libc_start_main [0x174bbf44]`;
auto frame = line.toFrame;

frame.invalid.should.equal(false);
frame.moduleName.should.equal("");
frame.file.should.equal("");
frame.line.should.equal(-1);
Expand Down

0 comments on commit 9e687ff

Please sign in to comment.