Tuesday, June 19, 2018

build_and_debug_v8_on_windows

This artical refers to https://medium.com/dailyjs/how-to-build-v8-on-windows-and-not-go-mad-6347c69aacd4

Setting up environment

/*
VS2013 Requirements:
  • at least 8.5 GB disk space;If your windows has been updated to October 2013, you can delete some not used files in winsxs to free up disk space: apply "Clean up system files" button from windows disk cleanup utility(to run it with system adiminister, view its path through windows task mgr, then right click it and select run as admin).
  • for the express installer, select the installer for Windows Desktop instead of Windows(the later can be used to create windows store app).
  • To install vs2013 express, I make my win7 genenuine first by input the product key W4TGB-8HFJV-QB794-P6MDG-XWGF6 found in my disk packer and machine sticker
  • VS 2013 will use dnet 4.5.1 first, so better remove your old install(to check version of installed dnet, check HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP)
*/
VS2017 Requirements:
  • at least 30 GB disk space

Install git(if has no installation in your system)

From https://git-scm.com/downloads download and install git.

Install VS /*2015|*/2017(if has no installation in your system)

Depending on the system, may needing to install dnet 4.6 first.
Install VS(do not change default install path for VS), making sure the installer has installed Debug Interface Access (DIA) SDK(msdia*.dll), vcvarsall.bat, (and the Universal CRT?).

Install and config depot_tools

V8 uses part of a toolchain named depot_tools for Chromium project, Download depot_tools.zip and extract it(to C:\Chromium\depot_tools), then adds it to PATH. At the same time, add two new env var into your system:
DEPOT_TOOLS_WIN_TOOLCHAIN=0 //If you are a non-googler you need to set DEPOT_TOOLS_WIN_TOOLCHAIN=0
GYP_MSVS_VERSION=2017 //windows is not using GN but GYP for Ninja?
From a cmd.exe shell, run the command `gclient`, it will install all the bits needed to work with the code, including msysgit and python; After running gclient, open a new command prompt and type "where python" and confirm that python.bat comes ahead of python.exe (adjust PATH to let python.bat being searched first).

Install windows sdk

Windows sdk must be installed at default dir; and Debugging Tools For Windows must be selected(building v8 requires windows sdk, so if you only installed `Debugging Tools For Windows`, remove it)
After installing, windbg may be found at following locations:
C:\Program Files (ia32)\Windows Kits // C:\Program Files (x86)\Windows Kits
C:\Program Files (ia32)\Microsoft SDKs\Windows Kits

Building and use V8

Get source code

Go into the directory where you want to download the V8 source into and execute the following in your terminal/shell:
  • cd /d C:\Chromium\debug_v8_02
  • fetch v8
    Running: 'C:\depot_tools\win_tools-2_7_6_bin\python\bin\python.exe' 'C:\depot_tools\gclient.py' root
    Running: 'C:\depot_tools\win_tools-2_7_6_bin\python\bin\python.exe' 'C:\depot_tools\gclient.py' config --spec 'solutions = [
      {
        "url": "https://chromium.googlesource.com/v8/v8.git",
        "managed": False,
        "name": "v8",
        "deps_file": "DEPS",
        "custom_deps": {},
      },
    ]
    '
    C:\Chromium\depot_tools\win_tools-2_7_6_bin\python\bin\python.exe C:\Chromium\depot_tools\gclient.py sync --with_branch_heads
    ...

build debug_v8_02

prepare build file for ninja: cd /d C:\Chromium\debug_v8_02\v8 && python tools/dev/v8gen.py ia32.debug
modify config file C:\Chromium\debug_v8_02\v8\out.gn\ia32.debug\args.gn :
#ia32.debug x64.release ...
is_debug = true
target_cpu = "x86"
v8_enable_backtrace = true
v8_enable_slow_dchecks = true
v8_optimized_debug = false
" ninja -C out.gn/ia32.debug " and produce the product d8.
check if v8 works: C:\Chromium\debug_v8_02\v8\out.gn\ia32.debug\d8.exe C:\Chromium\debug_v8_02\instance01\1.js
debug d8:
  • windbg with C:\Chromium\debug_v8_02\v8\out.gn\ia32.debug\d8.exe C:\Chromium\debug_v8_02\instance01\1.js
  • set symbols: .sympath+ C:\Chromium\debug_v8_02\v8\out.gn\ia32.debug\
  • set srcpath: .srcpath C:\Chromium\debug_v8_02\v8\src
  • bp d8_exe!main
  • let windbg run and break
  • db poi(poi(argv))
    0068501c  43 3a 5c 43 68 72 6f 6d-69 75 6d 5c 64 65 62 75  C:\Chromium\debu
    0068502c  67 5f 76 38 5f 30 32 5c-76 38 5c 6f 75 74 2e 67  g_v8_02\v8\out.g
    0068503c  6e 5c 69 61 33 32 2e 64-65 62 75 67 5c 64 38 2e  n\ia32.debug\d8.
    
  • db poi(poi(argv)+4)
    00685050  43 3a 5c 43 68 72 6f 6d-69 75 6d 5c 64 65 62 75  C:\Chromium\debu
    00685060  67 5f 76 38 5f 30 32 5c-69 6e 73 74 61 6e 63 65  g_v8_02\instance
    00685070  30 31 5c 31 2e 6a 73 00-fd fd fd fd ab ab ab ab  01\1.js.........
    

















No comments:

Post a Comment