2008-11-10 3 views

답변

1

당신은 올바른 길을 가고 있다고 생각합니다.

Script Generator (codegen * .cc 및 .h)로 연결되는 Script :: Compile to Compiler :: Compile에서 필요한 것 같습니다.

이 모든 것은 codegen-ia32.cc를보고, 빌드 할 때 ENABLE_DISASSEMBLER 을 정의하면 해체가 인쇄되어야한다고 생각합니다.

물론이 모든 것은 내가 가지고있는 소스의 이전 사본을 빠르게 찾아 본 것일 뿐이므로 YMMV가 올바르게 작동해야한다고 생각합니다.

(다시 게시판을 보면서 어셈블러가 아니라 기계어를 찾고 있음을 알 수 있습니다. 그러나 조립 된 코드 출력을 원한다면 로직을 수정해야 할 수도 있습니다. 그것의 해체)

11

C++ 코드에서 디스어셈블러를 호출하는 방법을 모르지만 쉘에서 디스 어셈블리를 가져 오는 빠르고 쉬운 방법이 있습니다.

첫째, 디스어셈블러 지원 V8을 컴파일 :

./shell --print_code hello.js 

은 다음과 같이 당신에게 무언가를 제공해야합니다 :

scons [your v8 build options here] disassembler=on sample=shell 

는 이제 "--print_code"옵션을 사용하여 쉘을 호출 할 수 있습니다

--- Raw source --- 
print("hello world"); 

--- Code --- 
kind = FUNCTION 
Instructions (size = 134) 
0x2ad0a77ceea0  0 55    push rbp 
0x2ad0a77ceea1  1 488bec   REX.W movq rbp,rsp 
0x2ad0a77ceea4  4 56    push rsi 
0x2ad0a77ceea5  5 57    push rdi 
0x2ad0a77ceea6  6 49ba59c13da9d02a0000 REX.W movq r10,0x2ad0a93dc159 ;; object: 0xa93dc159 <undefined> 
0x2ad0a77ceeb0 16 4952   REX.W push r10 
0x2ad0a77ceeb2 18 49ba688b700000000000 REX.W movq r10,0x708b68 
0x2ad0a77ceebc 28 493b22   REX.W cmpq rsp,[r10] 
0x2ad0a77ceebf 31 0f824e000000 jc 115 (0x2ad0a77cef13) 
0x2ad0a77ceec5 37 488b462f  REX.W movq rax,[rsi+0x2f] 
0x2ad0a77ceec9 41 4883ec18  REX.W subq rsp,0xlx 
0x2ad0a77ceecd 45 49ba094b3ea9d02a0000 REX.W movq r10,0x2ad0a93e4b09 ;; object: 0xa93e4b09 <String[5]: print> 
0x2ad0a77ceed7 55 4c8955e0  REX.W movq [rbp-0x20],r10 
0x2ad0a77ceedb 59 488945d8  REX.W movq [rbp-0x28],rax 
0x2ad0a77ceedf 63 49ba014d3ea9d02a0000 REX.W movq r10,0x2ad0a93e4d01 ;; object: 0xa93e4d01 <String[11]: hello world> 
0x2ad0a77ceee9 73 4c8955d0  REX.W movq [rbp-0x30],r10 
0x2ad0a77ceeed 77 49baa06c7ba7d02a0000 REX.W movq r10,0x2ad0a77b6ca0 ;; debug: statement 0 
           ;; code: contextual, CALL_IC, UNINITIALIZED, argc = 1 
0x2ad0a77ceef7 87 49ffd2   REX.W call r10 
0x2ad0a77ceefa 90 488b75f8  REX.W movq rsi,[rbp-0x8] 
0x2ad0a77ceefe 94 4883c408  REX.W addq rsp,0xlx 
0x2ad0a77cef02 98 488945e8  REX.W movq [rbp-0x18],rax 
0x2ad0a77cef06 102 488be5   REX.W movq rsp,rbp  ;; js return 
0x2ad0a77cef09 105 5d    pop rbp 
0x2ad0a77cef0a 106 c20800   ret 0x8 
0x2ad0a77cef0d 109 cc    int3 
0x2ad0a77cef0e 110 cc    int3 
0x2ad0a77cef0f 111 cc    int3 
0x2ad0a77cef10 112 cc    int3 
0x2ad0a77cef11 113 cc    int3 
0x2ad0a77cef12 114 cc    int3 
0x2ad0a77cef13 115 49ba60657ba7d02a0000 REX.W movq r10,0x2ad0a77b6560 ;; code: STUB, StackCheck, minor: 0 
0x2ad0a77cef1d 125 49ffd2   REX.W call r10 
0x2ad0a77cef20 128 488b7df0  REX.W movq rdi,[rbp-0x10] 
0x2ad0a77cef24 132 eb9f   jmp 37 (0x2ad0a77ceec5) 

RelocInfo (size = 10) 
0x2ad0a77ceea8 embedded object (0xa93dc159 <undefined>) 
0x2ad0a77ceecf embedded object (0xa93e4b09 <String[5]: print>) 
0x2ad0a77ceee1 embedded object (0xa93e4d01 <String[11]: hello world>) 
0x2ad0a77ceeed statement position (0) 
0x2ad0a77ceeef code target (context) (CALL_IC) (0x2ad0a77b6ca0) 
0x2ad0a77cef06 js return 
0x2ad0a77cef15 code target (STUB) (0x2ad0a77b6560) 

hello world 

출력은 다양합니다. 위의 내용은 Linux x64 용으로 컴파일 된 v8 트렁크에서 가져온 것입니다.

6

디스어셈블러 지원을 사용하여 v8을 빌드해야합니다.

v8 소스 코드 다운로드.

git clone https://chromium.googlesource.com/v8/v8.git 

디스어셈블러 지원으로 빌드하십시오.

make dependencies 
make ia32.release objectprint=on disassembler=on 

원하는 플래그에 따라 d8 (v8 쉘)을 호출하십시오. 참고로

out/ia32.release/d8 --code-comments --print-code <app.js> 

:

  • --code-의견은 : 코드 주석이 포함되어 있습니다.
  • - 인쇄 - 코드 : stdout으로 코드를 인쇄합니다.
  • --print-code-stubs : 코드 스텁을 인쇄합니다.
  • --print-opt-code : 최적화 된 코드를 인쇄합니다.
  • --trace-hydrogen : IR (intermediate representation) 코드를 hydrogen.cfg에 인쇄합니다. 이 파일은 Java's C1Visualizer으로 열 수 있습니다.
0

을 보면 V8 용 디스어셈블러 관련 기능과 기타 많은 컴파일 타임 기능 스위치를 찾을 수 있습니다. NodeJS 또는 크롬

0

시도 :

  1. -print-opt-code : 코드 컴파일러 최적화에 의해 생성.
  2. -print-bytecode : 인터프리터에서 생성 한 바이트 코드.
  3. -trace-opt-trace-depot : 어떤 기능이 (최적화되지 않은) 최적화되어 있습니다.

확인 @Franziska Hinkelmann하여이 문서 :

https://medium.com/dailyjs/understanding-v8s-bytecode-317d46c94775

는 또한 당신은 또한

D8 시도 할 수 있습니다 : 그것은 당신이 V8를 컴파일 할 수 있도록 자바 스크립트에서 생성 된 어셈블리 코드를 볼 수 있습니다. 사용 및 자세한 내용은

:

http://www.mattzeunert.com/2015/08/19/viewing-assembly-code-generated-by-v8.html