Chakracore: How can I debug JS code running in an app which embeds ChakraCore?

Created on 13 Jul 2016  路  10Comments  路  Source: chakra-core/ChakraCore

Hi!

We are developing an application for Windows 10 where we are using Chakra engine. In this application the end-user can write JavaScript code which we run inside our app.

We like to deliver the users some kind of possibility to debug their code. But I couldn't find any way yet as to how can I debug the code which I run on Chakra.

Now, we have a sample app about this, where I simply create a Js Runtime and Context, then I set up CurrentContext, then I simply have the JS Code in a string which I running on Chakra with JSRunScript.

I tried to call JsStartDebugging which should enable us to debug the code with Visual studio, but it didn't helped altough the call returns with NoError.

Could you give me some info about this? Is this even possible somehow?

Question

Most helpful comment

Will VS support be scheduled in the future?

All 10 comments

// FYI @agarwal-sandeep

Hi @monutam91 and thanks for reaching out to us! First just to make sure, I'm assuming that we are talking about Chakra - the system component on Windows 10, not ChakraCore as there is a difference when it comes to debugging. In the sample case you mentioned, once you call JsStartDebugging, Chakra should be in debug mode and VS will break at any unhandled exception or debugger statement or breakpoint in scripts. Can you check whether you selected the "script" debugging option in VS? This is really easy to forget.

@monutam91 and if you're comfortable with sharing the sample or a small repo with me, that'd also be fantastic and help me understand your scenario and setting better.

@monutam91 when you do JsStartDebugging it will put the script code in the debug mode. That means you still need to attach the VS to the app to further debug the script. However as @liminzhu mentioned while attach you need to select the 'script' debugging option.

Hi,
Yes, I'm talking about the Chakra and not the ChakraCore. I'm familiar with the Script option and I set it up, in debug time I can see the Script Documents part in the Solution Explorer, but there aren't any Script files in it, only the root of the Application exe can be seen, which I can't open.

@monutam91 we have a UWP sample where debugging is all set up and working. The hosting part in the sample is fairly minimal and commented, and as in the sample, enabling debugging should be as simple as calling JsStartDebugging once before running any scripts with JsRunScript. Can you try and see if the sample works for you and it can help you? To do that with VS2015 (similarly in VS2013),

  1. Download/clone the sample.
  2. Open JsRT_UWP_Sample.sln with Visual Studio, select the build flavor of your choose
  3. Make sure "Script" option is selected for debugging - select "Properties" in the solution explorer, navigate to the "Debug" tab, and at the bottom make sure "Script" is selected as the debugger type.
  4. Build and deploy. And then close VS.
  5. In your start menu, find "JSRT_UWP_Sample" and open it. Type some valid scripts in the opened window and hit "Execute" a couple of times to execute the scripts so that you can expect to see some scripts later in the Solution Explorer. Your customers typically have two ways to debug scripts - launching VS debugger from the app or attach the process in VS. You can try out both.
  6. [Launch debugger] Type "debugger" in the window (this statement triggers a breakpoint), and hit "Execute". A prompt will open to ask you to launch VS and debug. Click yes to open VS and all the scripts you executed should be under the Scripts Documents in the Solution Explorer. OR,
  7. [Attach process] Open VS (don't open any project). Navigate to Debug > Attach to Process. In the opened "Attach to Process" prompt, select "Script code" as the "Attach to" option, Select "JSRT_UWP_Samples.exe" in "Available Processes" and hit "Attach". All the scripts you executed should be under the Scripts Documents in the Solution Explorer.

Updated the issue title to make it easier for others to find this information in the future.

Closing question as answered, but feel free to comment if you'd like to discuss further.

So how to debug ChakraCore embedded in my own C++ project? I have tried choosing different debug mode and using code like:

  • JsDiagStartDebugging()
  • enable flag ForceDiagnosticsMode
  • WScript.Attach(func)

however Visual Studio does not hit the breakpoint.

ChakraCore provides just the debugging APIs and doesn't implement a debugger. We have implement debugging support in Node-ChakraCore which can be used to debug using VSCode as frontend.

Will VS support be scheduled in the future?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tommyZZM picture tommyZZM  路  5Comments

luxiao6620217 picture luxiao6620217  路  6Comments

ross-weir picture ross-weir  路  4Comments

crdumoul picture crdumoul  路  4Comments

jdalton picture jdalton  路  4Comments