Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspector support #4484

Merged
merged 42 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
22166f8
WIP
ry Mar 24, 2020
672fce7
WIP
ry Mar 24, 2020
6e181c0
Session and Channel should not move, so put them in a Box
piscisaureus Mar 25, 2020
da1ca22
Support real UUIDs, handle multiple inspectors
ry Mar 25, 2020
04232fb
wip
piscisaureus Mar 25, 2020
007ca99
wip
piscisaureus Mar 25, 2020
ed964cd
Provide IsolateHandle to ws server
ry Mar 25, 2020
e1aafdf
Add strong reminder that InspectorServer::drop is broken
ry Mar 25, 2020
50e17f2
send connection message
ry Mar 25, 2020
9eb4c2f
cleanup
ry Mar 25, 2020
8042c1f
add InspectorInfo, cleanups
ry Mar 25, 2020
b29a1d1
x
ry Mar 25, 2020
0d5e1b8
cleanup
ry Mar 25, 2020
05e091f
remove websocket_debugger_url2
ry Mar 25, 2020
88b7f85
session_id creation
ry Mar 25, 2020
be5a33f
Messages are being sent back and forth
ry Mar 25, 2020
f58fa37
Undo DenoInspectorInner
ry Mar 25, 2020
a139def
add some hints from node
ry Mar 26, 2020
42243e4
clean up
ry Mar 26, 2020
ee61cdc
clippy
ry Mar 26, 2020
333fca0
cleanup
ry Mar 26, 2020
885f0d4
wip
ry Mar 26, 2020
877b6d1
fix pause button
piscisaureus Mar 26, 2020
1cea957
Make interrupts work
piscisaureus Mar 26, 2020
50500f0
WIP
piscisaureus Mar 27, 2020
ed4c7d3
inspector1 test working
ry Mar 27, 2020
5af0c64
clippy
ry Mar 27, 2020
6bd8c59
use --inspect flag instead of --debug
ry Mar 27, 2020
3251003
debug
ry Mar 27, 2020
ff21fa7
remove debug output
ry Mar 27, 2020
4527708
try another port
ry Mar 27, 2020
124d0c5
roll back
piscisaureus Mar 27, 2020
00936d1
try to fix CI
ry Mar 27, 2020
8d56388
try to fix ci
ry Mar 27, 2020
f4250cc
fix
ry Mar 27, 2020
04787a6
works a lot better now
piscisaureus Mar 27, 2020
b723982
Merge remote-tracking branch 'origin/inspector4' into inspector4
piscisaureus Mar 27, 2020
5c2c9f0
clean up
piscisaureus Mar 27, 2020
dec35db
cleanup
ry Mar 27, 2020
f98ce25
use info! instead of eprintln!
ry Mar 27, 2020
d63a00e
Add inspector_pause test
ry Mar 27, 2020
11f4ef4
run inspector tests on different ports
ry Mar 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
390 changes: 363 additions & 27 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ utime = "0.2.1"
webpki = "0.21.2"
webpki-roots = "0.19.0"
walkdir = "2.3.1"
warp = "0.2.2"
semver-parser = "0.9.0"
uuid = { version = "0.8", features = ["v4"] }


[target.'cfg(windows)'.dependencies]
winapi = "0.3.8"
Expand All @@ -72,6 +75,8 @@ nix = "0.14" # rustyline depends on 0.14, to avoid duplicates we do too.

[dev-dependencies]
os_pipe = "0.9.1"
# Used for testing inspector. Keep in-sync with warp.
tokio-tungstenite = { version = "0.10", features = ["connect"] }

[target.'cfg(unix)'.dev-dependencies]
pty = "0.2.2"
88 changes: 87 additions & 1 deletion cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub struct Flags {
pub no_prompts: bool,
pub no_remote: bool,
pub cached_only: bool,
pub inspect: Option<String>,
pub inspect_brk: Option<String>,
pub seed: Option<u64>,
pub v8_flags: Option<Vec<String>>,

Expand Down Expand Up @@ -474,6 +476,7 @@ fn run_test_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
no_remote_arg_parse(flags, matches);
permission_args_parse(flags, matches);
ca_file_arg_parse(flags, matches);
inspect_arg_parse(flags, matches);

if matches.is_present("cached-only") {
flags.cached_only = true;
Expand Down Expand Up @@ -825,7 +828,7 @@ fn permission_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
}

fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
permission_args(app)
permission_args(inspect_args(app))
.arg(importmap_arg())
.arg(reload_arg())
.arg(config_arg())
Expand Down Expand Up @@ -956,6 +959,54 @@ fn ca_file_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.ca_file = matches.value_of("cert").map(ToOwned::to_owned);
}

fn inspect_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
app
.arg(
Arg::with_name("inspect")
.long("inspect")
.value_name("HOST:PORT")
.help("activate inspector on host:port (default: 127.0.0.1:9229)")
.min_values(0)
.max_values(1)
.require_equals(true)
.takes_value(true),
)
.arg(
Arg::with_name("inspect-brk")
.long("inspect-brk")
.value_name("HOST:PORT")
.help(
"activate inspector on host:port and break at start of user script",
)
.min_values(0)
.max_values(1)
.require_equals(true)
.takes_value(true),
)
}

fn inspect_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
const DEFAULT: &str = "127.0.0.1:9229";
flags.inspect = if matches.is_present("inspect") {
if let Some(host) = matches.value_of("inspect") {
Some(host.to_string())
} else {
Some(DEFAULT.to_string())
}
} else {
None
};
flags.inspect_brk = if matches.is_present("inspect-brk") {
if let Some(host) = matches.value_of("inspect-brk") {
Some(host.to_string())
} else {
Some(DEFAULT.to_string())
}
} else {
None
};
}

fn reload_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("reload")
.short("r")
Expand Down Expand Up @@ -2327,3 +2378,38 @@ fn repl_with_cafile() {
}
);
}

#[test]
fn inspect_default_host() {
let r = flags_from_vec_safe(svec!["deno", "run", "--inspect", "foo.js"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Run {
script: "foo.js".to_string(),
},
inspect: Some("127.0.0.1:9229".to_string()),
..Flags::default()
}
);
}

#[test]
fn inspect_custom_host() {
let r = flags_from_vec_safe(svec![
"deno",
"run",
"--inspect=deno.land:80",
"foo.js"
]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Run {
script: "foo.js".to_string(),
},
inspect: Some("deno.land:80".to_string()),
..Flags::default()
}
);
}
11 changes: 11 additions & 0 deletions cli/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::deno_dir;
use crate::file_fetcher::SourceFileFetcher;
use crate::flags;
use crate::http_cache;
use crate::inspector::InspectorServer;
use crate::lockfile::Lockfile;
use crate::msg;
use crate::permissions::DenoPermissions;
Expand Down Expand Up @@ -42,6 +43,7 @@ pub struct GlobalStateInner {
pub wasm_compiler: WasmCompiler,
pub lockfile: Option<Mutex<Lockfile>>,
pub compiler_starts: AtomicUsize,
pub inspector_server: Option<InspectorServer>,
compile_lock: AsyncMutex<()>,
}

Expand Down Expand Up @@ -82,7 +84,16 @@ impl GlobalState {
None
};

let inspector_server = if let Some(ref host) = flags.inspect {
Some(InspectorServer::new(host, false))
} else if let Some(ref host) = flags.inspect_brk {
Some(InspectorServer::new(host, true))
} else {
None
};

let inner = GlobalStateInner {
inspector_server,
dir,
permissions: DenoPermissions::from_flags(&flags),
flags,
Expand Down
Loading