Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
fix(test): improve base variable scope level
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Henriksen committed Sep 15, 2019
1 parent 8e8c16e commit 8778e42
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 24 deletions.
38 changes: 25 additions & 13 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ function absoluteFilename(root: string, filename: string): string {
return join(root, filename);
}

export class perlDebuggerConnection extends EventEmitter {
export class PerlDebuggerConnection extends EventEmitter {
public debug: boolean = false;
public perlDebugger: DebugSession;
public debuggee?: DebugSession;

public streamCatcher: StreamCatcher;
public perlVersion: PerlVersion;
public padwalkerVersion: string;
public scopeBaseLevel: number = -1;
public develVscodeVersion?: string;
public hostname?: string;
public commandRunning: string = '';
Expand Down Expand Up @@ -883,6 +884,14 @@ export class perlDebuggerConnection extends EventEmitter {
// inform the user of a missing dependency install of PadWalker
}

if (this.padwalkerVersion.length > 0) {
try {
this.scopeBaseLevel = await this.getVariableBaseLevel();
} catch (ignore) {
// ignore the error
}
}

await this.installSubroutines();

return this.parseResponse(data);
Expand Down Expand Up @@ -987,24 +996,13 @@ export class perlDebuggerConnection extends EventEmitter {
return res.data.pop();
}

private fixLevel(level: number) {
// xxx: There seem to be an issue in perl debug or PadWalker in/outside these versions on linux
// The issue is due to differences between perl5db.pl versions, we should use that as a reference instead of
// using perl/os
const isBrokenPerl = (this.perlVersion.version >= '5.022000' || this.perlVersion.version < '5.018000');
const isBrokenLinux = platform() === 'linux' && isBrokenPerl;
const isBrokenWindows = platform() === "win32" && isBrokenPerl;
const fix = isBrokenLinux || isBrokenWindows;
return fix ? level - 1 : level;
}

/**
* Prints out a nice indent formatted list of variables with
* array references resolved.
*/
async requestVariableOutput(level: number) {
const variables: Variable[] = [];
const res = await this.request(`y ${this.fixLevel(level)}`);
const res = await this.request(`y ${level + this.scopeBaseLevel - 1}`);
const result = [];

if (/^Not nested deeply enough/.test(res.data[0])) {
Expand Down Expand Up @@ -1144,6 +1142,20 @@ export class perlDebuggerConnection extends EventEmitter {
return JSON.stringify(res.data);
}

async getVariableBaseLevel() {
const limitOfScope = /^Not nested deeply enough/;
const {data: [level1]} = await this.request('y 1'); // 5.22
const {data: [level2]} = await this.request('y 2'); // 5.20
if (limitOfScope.test(level1)) {
return 0;
}
if (limitOfScope.test(level2)) {
return 1;
}
// apparently we didn't find the base level?
return -1;
}

async getDebuggerPid(): Promise<number> {
const res = await this.request(
'p $$'
Expand Down
6 changes: 3 additions & 3 deletions src/perlDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {readFileSync} from 'fs';
import {basename, dirname, join} from 'path';
import {spawn, ChildProcess} from 'child_process';
const { Subject } = require('await-notify');
import { perlDebuggerConnection, RequestResponse } from './adapter';
import { PerlDebuggerConnection, RequestResponse } from './adapter';
import { variableType, ParsedVariable, ParsedVariableScope, resolveVariable } from './variableParser';

/**
Expand Down Expand Up @@ -64,12 +64,12 @@ export class PerlDebugSession extends LoggingDebugSession {

public dcSupportsRunInTerminal: boolean = false;

private adapter: perlDebuggerConnection;
private adapter: PerlDebuggerConnection;

public constructor() {
super('perl_debugger.log');

this.adapter = new perlDebuggerConnection();
this.adapter = new PerlDebuggerConnection();

this.setDebuggerLinesStartAt1(false);
this.setDebuggerColumnsStartAt1(false);
Expand Down
15 changes: 11 additions & 4 deletions src/tests/connection.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert = require('assert');
import asyncAssert from './asyncAssert';
import * as Path from 'path';
import { perlDebuggerConnection, RequestResponse } from '../adapter';
import { PerlDebuggerConnection, RequestResponse } from '../adapter';
import { LocalSession } from '../localSession';
import { LaunchRequestArguments } from '../perlDebug';
import { convertToPerlPath } from "../filepath";
Expand All @@ -21,7 +21,7 @@ const FILE_PRINT_ARGUMENTS = 'print_arguments.pl';
const FILE_FAST_TEST_PL = 'fast_test.pl';

async function testLaunch(
conn: perlDebuggerConnection,
conn: PerlDebuggerConnection,
filename: string,
cwd: string,
args: string[] = [],
Expand All @@ -48,10 +48,10 @@ async function testLaunch(

describe('Perl debugger connection', () => {

let conn: perlDebuggerConnection;
let conn: PerlDebuggerConnection;

beforeEach(async () => {
conn = new perlDebuggerConnection();
conn = new PerlDebuggerConnection();
await conn.initializeRequest();
});

Expand All @@ -74,6 +74,13 @@ describe('Perl debugger connection', () => {
});
});

describe('scopeBaseLevel', () => {
it('should be found', async () => {
const res = await testLaunch(conn, FILE_TEST_PL, DATA_ROOT, []);
expect(conn.scopeBaseLevel).toBeGreaterThanOrEqual(0);
});
});

describe('launchRequest', () => {
it('Should be able to connect and launch ' + FILE_TEST_PL, async () => {
const res = await testLaunch(conn, FILE_TEST_PL, DATA_ROOT, []);
Expand Down
8 changes: 4 additions & 4 deletions src/tests/remote.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert = require('assert');
import * as Path from 'path';
import { perlDebuggerConnection, RequestResponse } from '../adapter';
import { PerlDebuggerConnection, RequestResponse } from '../adapter';
import { LocalSession } from '../localSession';
import { LaunchRequestArguments } from '../perlDebug';

Expand All @@ -11,11 +11,11 @@ const FILE_TEST_PL = 'slow_test.pl';

describe('Perl debugger connection', () => {

let conn: perlDebuggerConnection;
let conn: PerlDebuggerConnection;
const trackedSessions: LocalSession[] = [];

beforeEach(async () => {
conn = new perlDebuggerConnection();
conn = new PerlDebuggerConnection();
await conn.initializeRequest();
});

Expand All @@ -30,7 +30,7 @@ describe('Perl debugger connection', () => {
});

function setupDebugger(
conn: perlDebuggerConnection,
conn: PerlDebuggerConnection,
file: string,
cwd: string,
args: string[],
Expand Down
182 changes: 182 additions & 0 deletions src/tests/variableScopeOutput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// Result of:
// perl -d slow_test.pl
// f Module.pm
// b 23
// c
// y 0

export const perl5_22_4 = `(
$bar = 'bar'
$hello = HASH(0x7fa39615edc8)
'bar' => 12
'foo' => 'bar'
'really' => 'true'
$i = 12
$obj = HASH(0x7fa396148a80)
8 => 9
'bar' => HASH(0x7fa39615edc8)
'bar' => 12
'foo' => 'bar'
'really' => 'true'
'foo' => 'bar'
'list' => ARRAY(0x7fa39615ed20)
0 'a'
1 '\'b'
2 'c'
'ownObj' => HASH(0x7fa396947d40)
'ownFoo' => 'own?'
'ownlist' => 7
@list1 = (
0 'a'
1 '\'b'
2 'c'
)
@list2 = (
0 1
1 2
2 3
)
@list3 = (
0 'a'
1 '\'b'
2 'c'
3 1
4 2
5 3
)`.split("\n");

export const perl5_20_3 = `(
'-' => HASH(0x7f8c5f01cb58)
't' => 'm'
'v' => '_handle_dash_command'
'.' => HASH(0x7f8c5e13ec18)
't' => 's'
'v' => CODE(0x7f8c5e0c7be0)
-> &DB::_DB__handle_dot_command in 0
'=' => HASH(0x7f8c5e11d138)
't' => 'm'
'v' => '_handle_equal_sign_command'
'A' => HASH(0x7f8c5e973e10)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'B' => HASH(0x7f8c5e973f00)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'E' => HASH(0x7f8c5e973ff0)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'H' => HASH(0x7f8c5e1293e0)
't' => 'm'
'v' => '_handle_H_command'
'L' => HASH(0x7f8c5e9741d0)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'M' => HASH(0x7f8c5e974248)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'O' => HASH(0x7f8c5e974338)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'R' => HASH(0x7f8c5e973b88)
't' => 's'
'v' => CODE(0x7f8c5e0d2198)
-> &DB::_DB__handle_restart_and_rerun_commands in 0
'S' => HASH(0x7f8c5e129368)
't' => 'm'
'v' => '_handle_S_command'
'T' => HASH(0x7f8c5e11d1c8)
't' => 'm'
'v' => '_handle_T_command'
'V' => HASH(0x7f8c5e96ee88)
't' => 'm'
'v' => '_handle_V_command_and_X_command'
'W' => HASH(0x7f8c5e9744a0)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'X' => HASH(0x7f8c5e96e840)
't' => 'm'
'v' => '_handle_V_command_and_X_command'
'a' => HASH(0x7f8c5e96f5c0)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'b' => HASH(0x7f8c5e973e88)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'c' => HASH(0x7f8c5e108048)
't' => 's'
'v' => CODE(0x7f8c5e0c8000)
-> &DB::_DB__handle_c_command in 0
'disable' => HASH(0x7f8c5e96f548)
't' => 'm'
'v' => '_handle_enable_disable_commands'
'e' => HASH(0x7f8c5e973f78)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'enable' => HASH(0x7f8c5e96f2f0)
't' => 'm'
'v' => '_handle_enable_disable_commands'
'f' => HASH(0x7f8c5e114e40)
't' => 's'
'v' => CODE(0x7f8c5e0c7448)
-> &DB::_DB__handle_f_command in 0
'h' => HASH(0x7f8c5e974068)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'i' => HASH(0x7f8c5e9740e0)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'l' => HASH(0x7f8c5e974158)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'm' => HASH(0x7f8c5e1080c0)
't' => 's'
'v' => CODE(0x7f8c5e0d2918)
-> &DB::_DB__handle_m_command in 0
'n' => HASH(0x7f8c5e0ec118)
't' => 'm'
'v' => '_handle_n_command'
'o' => HASH(0x7f8c5e9742c0)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'p' => HASH(0x7f8c5e0f1310)
't' => 'm'
'v' => '_handle_p_command'
'q' => HASH(0x7f8c5e95ebc0)
't' => 'm'
'v' => '_handle_q_command'
'r' => HASH(0x7f8c5e95e710)
't' => 'm'
'v' => '_handle_r_command'
'rerun' => HASH(0x7f8c5f1ef320)
't' => 's'
'v' => CODE(0x7f8c5e0d2198)
-> REUSED_ADDRESS
's' => HASH(0x7f8c5e95e5a8)
't' => 'm'
'v' => '_handle_s_command'
'save' => HASH(0x7f8c5e95e380)
't' => 'm'
'v' => '_handle_save_command'
'source' => HASH(0x7f8c5e95e320)
't' => 'm'
'v' => '_handle_source_command'
't' => HASH(0x7f8c5e95e290)
't' => 'm'
'v' => '_handle_t_command'
'v' => HASH(0x7f8c5e9743b0)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'w' => HASH(0x7f8c5e974428)
't' => 'm'
'v' => '_handle_cmd_wrapper_commands'
'x' => HASH(0x7f8c5e926d08)
't' => 'm'
'v' => '_handle_x_command'
'y' => HASH(0x7f8c5e95e5f0)
't' => 's'
'v' => CODE(0x7f8c5e0c7aa8)
-> &DB::_DB__handle_y_command in 0
)`.split("\n");
const perl5_18_4 = ``;
const perl5_16_3 = ``;
const perl5_14_4 = ``;

0 comments on commit 8778e42

Please sign in to comment.