Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
core,chakracore,chakrashim: TTD updates
Browse files Browse the repository at this point in the history
* Merge TTD changes to node-chakracore xplat.
* Expanding TTD support for Node API's.
* Improved TTD flags and usage/documentation.
* Integrated trace writing with signal/assert/exit/console.error/console.warn

PR-URL: #180
Reviewed-By: Hitesh Kanwathirtha <[email protected]>
  • Loading branch information
mrkmarron authored and kunalspathak committed Mar 8, 2017
1 parent fd355ed commit c51a730
Show file tree
Hide file tree
Showing 37 changed files with 1,103 additions and 476 deletions.
148 changes: 101 additions & 47 deletions TTD-README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,109 @@
# Time Travel Debugging with Node-ChakraCore

Stepping forward after hitting a breakpoint is a familiar experience but what
if you could step back in time? Frequently developers find themselves hunting
for failure clues (e.g. error text) in the log files and then searching for
that in the code. Once the log statement is found in the source code, the
developer is left to re-construct the context for the error.

Not anymore! Time-Travel debugging (TTD) allows developers to look at the
faulting code within the full fidelity of the debugger with all the runtime
context preserved. TTD works on the record and playback principle, the record
mode creates a trace file during execution which can then be played back
allowing developers to deeply inspect the code as it was during the original
execution.

TTD functionality is being added to Node-ChakraCore and is supported by [VSCode](https://aka.ms/vscode-insider).
We are developing in the open and want to share our progress to get feedback,
bug reports, functionality requests, and pull-requests from the community.

## What's New
* TTD reaches Beta milestone on Windows
* Added new feature **"Reverse Continue"**
* Improved performance and reliability

* TTD preview available on macOS and Ubuntu 16.04
* Added TTD support on experimental Node-ChakraCore cross-platform builds

![VSCode showing TTD with step back and reverse continue](https://aka.ms/nodettd-reversecontinue.gif)
### How to get started
To get started with TTD you will need the following:

- Install [VSCode Insider build](https://aka.ms/vscode-insider)
- Install [Node-ChakraCore](https://github.com/nodejs/node-chakracore/releases)
# Diagnostic Tracing and Time Travel Debugging with Node-ChakraCore
In post-mortem debugging scenarios, developers frequently find themselves
hunting for failure clues (e.g. error text) in the log files and then searching
for those clues in their code. Once the log statement is found in the source code,
the developer is often left to re-construct the context of the error.

The cutting edge diagnostic capabilities in Node-ChakraCore allows developers to
look at the faulting code within the full fidelity of the debugger with all the
runtime context preserved, enabling them to deeply inspect the code as it was during
the original execution. Node-Chakracore has been extended with a suite of such features
to support tracing and reproducing program executions and a range of updates to improve
the time-travel debugging experience.

This project is being developed in the open and we are always happy to get feedback, bug reports,
functionality requests, and pull-requests from the community.

## Diagnostic Tracing
Reproducing issues that depend on a specific interleaving of callbacks, specifics of
a server configuration or users system, or transient network/file-system behavior can be
challenging. To help simplify the process we have updated Node-ChakraCore with a suite
of **diagnostic tracing** features. These features allow you to record an application
execution using the `--record` flag and, then when any of the conditions listed below
occur, a diagnostic trace is written out to disk (with the location printed to
`stderr`).

Default trace emit events:
- Unhandled exceptions *always* emit a trace.
- Exit with a non-zero exit code *always* emits a trace.
- Failed `asserts` *probabilistically* emit a trace with a backoff to prevent overloading.
- Calls to `console.error` and `console.warn` *probabilistically* emit a trace with a backoff to prevent overloading.
- A `SIGINT` signal will *always* emit a trace.

When we run with our remote-file server [demo](https://github.com/mrkmarron/RFSDemoJS) with the record flag and
hit a bug in the file I/O code (followed by crtl-c on the command line) we get the output shown below.

![Running node with --record flag and two trace output events.](doc\ttd_assets\TraceSnap.png)

### Record TTD trace
To record a trace for debugging run the TTD enabled build of node with the record flag:
```node.exe -TTRecord:<Location to save Trace> <app script>```
Where the location of the saved trace is a **relative path** from the current working directory.
Once written to disk these trace directories can be used locally or copied to another machine
for later analysis and debugging. To reproduce the execution trace in `dir` with a debugger
simply invoke node using `--no-lazy --debug-brk=port --replay-debug=dir` and attach the debugger.

### Replay a TTD Trace on the command line:
```node.exe -TTReplay:<Location of saved Trace>```
The animation below shows us launching the trace execution on the command line and attaching the debugger.
When the trace hits the point where it emitted the `emitOnLogWarn` trace it will break into the debugger
allowing us to inspect local variables, the call stack and, set a breakpoint where the callback that received
the I/O error was registered. Then we reverse-execute back-in-time to this callback registration and can
inspect local variables as well as the full call stack as they existed then.

![Replay debugging with the --replay-debug flag and TTD.](doc\ttd_assets\TTDTrace.gif)

If desired we can single step-back through other statements as well or execute forward again, seeing the
exact set of statements and variable values that existed during the original execution, until we have
all the information we need to understand the problem.

## Time-Travel Debugging

TTD functionality is available in Node-ChakraCore and is supported by
[VSCode](https://code.visualstudio.com/). As shown previously you can use
node to re-execute from the trace with debugging support, using the `--replay-debug`
flag, and then attaching the (VSCode) debugger. However, it is also possible to
initiate time-travel debugging directly from VSCode. This is done by:
- Creating an empty `dummy.js` file in the trace directory.
- Ensure Node-ChakraCore is on your path.
- Adding the following configuration into your `.vscode\launch.json` configuration file.
```
{
"name": "TTDebug",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/dummy.js",
"stopOnEntry": true,
"cwd": "${workspaceRoot}",
"runtimeArgs": [
"--nolazy",
"--replay-debug=./"
]
}
```

## How to get started
To get started with diagnostic tracing and TTD you will need the following:

- Install [Node-ChakraCore](https://github.com/nodejs/node-chakracore/releases)
- (Recommended) install [NVS](https://github.com/jasongin/nvs/blob/master/doc/SETUP.md) which is a cross-platform tool for switching between different versions and forks of Node.js and will allow you to easily switch between Node-ChakraCore and other Node.js versions. Once NVS is installed simply enter the following commands in the console:
```
nvs remote chakracore https://github.com/nodejs/node-chakracore/releases
nvs add chakracore/latest
nvs use chakracore
```
- (Manual) Download the build for your platform/architecture and manually add the location of the binaries to your path.
- Install [VSCode](https://code.visualstudio.com/) using the latest installer.

### Debug a TTD Trace with VSCode
Make the following additions to the launch.json configuration in the VSCode project:
- Add the following to ```runtimeArgs``` ```["-TTDebug:<Location of saved Trace>", "-TTBreakFirst"]```.
- Set the runtime executable and cwd paths as needed for the TTD enabled build of node.js and location of the saved trace.
## Sample Program
The code for the Remote File System sample demo'ed at NodeInteractive is available
[here](https://github.com/mrkmarron/RFSDemoJS).

### Sample Program
The code for the Remote File System sample demo'ed at NodeInteractive is available [here](http://research.microsoft.com/en-us/um/people/marron/samples/RFSDemo.zip).
You can clone the repo to a location of your choice and `npm install` the dependencies. Once
you launch the application it will serve up the contents of the folder `testdata` on port 3000. The
application is designed to intermittently rename the files `hello_world.js <-> helloWorld.js`
in the background. So, as shown in the screenshot above, a warn trace can be triggered by interacting
with the application and clicking on this file at various times. You can always trigger a sigint
trace via crtl-c at the command line.

(Note: This demo requires TypeScript)
Once this trace is written it can be replay debugged in VSCode using `--replay-debug=dir` as described
above and shown in the gif.

## Feedback
Please let us know on our [issues page](https://github.com/nodejs/node-chakracore/issues) if you have any question or comment.
Please let us know on our [issues page](https://github.com/nodejs/node-chakracore/issues) if
you have any question or comment.

6 changes: 3 additions & 3 deletions deps/chakrashim/chakracore.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
['OS in "linux android"', {
'chakracore_input': '<(chakra_dir)/build.sh',
'chakracore_binaries': [
'<(chakra_libs_absolute)/bin/ChakraCore/libChakraCoreStatic.a',
'<(chakra_libs_absolute)/lib/libChakraCoreStatic.a',
],
'linker_start_group': '-Wl,--start-group',
'linker_end_group': [
Expand All @@ -81,7 +81,7 @@
['OS=="mac"', {
'chakracore_input': '<(chakra_dir)/build.sh',
'chakracore_binaries': [
'<(chakra_libs_absolute)/bin/ChakraCore/libChakraCoreStatic.a',
'<(chakra_libs_absolute)/lib/libChakraCoreStatic.a',
],
'icu_args': '--icu=<(icu_include_path)',
'linker_start_group': '-Wl,-force_load',
Expand Down Expand Up @@ -156,7 +156,7 @@
'libraries': [
'-Wl,-undefined,error',
'<@(linker_start_group)',
'<(chakra_libs_absolute)/bin/ChakraCore/libChakraCoreStatic.a ' # keep this single space.
'<(chakra_libs_absolute)/lib/libChakraCoreStatic.a ' # keep this single space.
'<@(linker_end_group)', # gpy fails to patch with list
],
}],
Expand Down
Empty file modified deps/chakrashim/core/build.sh
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/jenkins/check_copyright.sh
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/jenkins/check_eol.sh
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/jenkins/check_file_eol.sh
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/jenkins/get_system_info.sh
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/test/AsmJs/vardeclnorhs.baseline
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/test/AsmJs/vardeclnorhs.js
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/test/Bugs/b208.js
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/test/Bugs/b208_asmjs.js
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/test/Bugs/testSimdManyVars.js
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/test/SIMD.bool8x16.asmjs/bug824.js
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/test/native-tests/test_native.sh
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/test/runtests.py
100755 → 100644
Empty file.
Empty file modified deps/chakrashim/core/test/runtests.sh
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions deps/chakrashim/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -2274,9 +2274,9 @@ class V8_EXPORT Isolate {
kMinorGarbageCollection
};

static Isolate* NewWithTTDSupport(const CreateParams& params, const char* uri,
static Isolate* NewWithTTDSupport(const CreateParams& params,
size_t optReplayUriLength, const char* optReplayUri,
bool doRecord, bool doReplay, bool doDebug,
bool useRelocatedSrc,
uint32_t snapInterval,
uint32_t snapHistoryLength);
static Isolate* New(const CreateParams& params);
Expand Down
2 changes: 0 additions & 2 deletions deps/chakrashim/src/jsrtdebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class MessageQueue {
JsValueRef processDebugEventFn;
JsValueRef processShouldContinueFn;
uv_sem_t newMsgSem;
uv_cond_t cond;
uv_mutex_t mutex;
uv_mutex_t msgMutex;
};

Expand Down
Loading

0 comments on commit c51a730

Please sign in to comment.