-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[lldb] add javascript scripting support #165805
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
Draft
cs01
wants to merge
1
commit into
llvm:main
Choose a base branch
from
cs01:cs01/lldb-support-javascript
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,586
−4
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| add_custom_command( | ||
| OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapJavaScript.cpp | ||
| DEPENDS ${SWIG_SOURCES} | ||
| DEPENDS ${SWIG_INTERFACES} | ||
| DEPENDS ${SWIG_HEADERS} | ||
| DEPENDS lldb-sbapi-dwarf-enums | ||
| COMMAND ${SWIG_EXECUTABLE} | ||
| ${SWIG_COMMON_FLAGS} | ||
| -I${CMAKE_CURRENT_SOURCE_DIR} | ||
| -javascript | ||
| -v8 | ||
| -w503 | ||
| -outdir ${CMAKE_CURRENT_BINARY_DIR} | ||
| -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapJavaScript.cpp | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/javascript.swig | ||
| VERBATIM | ||
| COMMENT "Building LLDB JavaScript wrapper") | ||
|
|
||
| add_custom_target(swig_wrapper_javascript ALL DEPENDS | ||
| ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapJavaScript.cpp | ||
| ) | ||
|
|
||
| function(create_javascript_package swig_target working_dir pkg_dir) | ||
| cmake_parse_arguments(ARG "NOINIT" "" "FILES" ${ARGN}) | ||
| add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM | ||
| COMMAND ${CMAKE_COMMAND} -E make_directory ${pkg_dir} | ||
| WORKING_DIRECTORY ${working_dir}) | ||
| endfunction() | ||
|
|
||
| function(finish_swig_javascript swig_target lldb_javascript_bindings_dir lldb_javascript_target_dir) | ||
| add_custom_target(${swig_target} ALL VERBATIM | ||
| COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_javascript_target_dir} | ||
| DEPENDS swig_wrapper_javascript liblldb | ||
| COMMENT "LLDB JavaScript API") | ||
| if(LLDB_BUILD_FRAMEWORK) | ||
| set(LIBLLDB_SYMLINK_DEST "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/LLDB") | ||
| else() | ||
| set(LIBLLDB_SYMLINK_DEST "${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}") | ||
| endif() | ||
| if(WIN32) | ||
| set(LIBLLDB_SYMLINK_OUTPUT_FILE "lldb.dll") | ||
| else() | ||
| set(LIBLLDB_SYMLINK_OUTPUT_FILE "lldb.so") | ||
| endif() | ||
| create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST} | ||
| ${lldb_javascript_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE}) | ||
| set(lldb_javascript_library_target "${swig_target}-library") | ||
| add_custom_target(${lldb_javascript_library_target}) | ||
| add_dependencies(${lldb_javascript_library_target} ${swig_target}) | ||
|
|
||
| # Ensure we do the JavaScript post-build step when building lldb. | ||
| add_dependencies(lldb ${swig_target}) | ||
|
|
||
| if(LLDB_BUILD_FRAMEWORK) | ||
| set(LLDB_JAVASCRIPT_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/JavaScript) | ||
| else() | ||
| set(LLDB_JAVASCRIPT_INSTALL_PATH lib/javascript) | ||
| endif() | ||
| install(DIRECTORY ${lldb_javascript_target_dir}/ | ||
| DESTINATION ${LLDB_JAVASCRIPT_INSTALL_PATH} | ||
| COMPONENT ${lldb_javascript_library_target}) | ||
|
|
||
| set(lldb_javascript_library_install_target "install-${lldb_javascript_library_target}") | ||
| if (NOT LLVM_ENABLE_IDE) | ||
| add_llvm_install_targets(${lldb_javascript_library_install_target} | ||
| COMPONENT ${lldb_javascript_library_target} | ||
| DEPENDS ${lldb_javascript_library_target}) | ||
| endif() | ||
| endfunction() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /* | ||
| Safe casting for JavaScript SWIG bindings | ||
| */ | ||
|
|
||
| // This file provides safe type casting between LLDB types | ||
| // Similar to lua-swigsafecast.swig and python-swigsafecast.swig | ||
|
|
||
| // TODO: Implement safe casting functions as needed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| JavaScript-specific typemaps for LLDB | ||
| */ | ||
|
|
||
| %header %{ | ||
| #include <v8.h> | ||
| %} | ||
|
|
||
| // Typemap for char ** (string arrays) - used in LaunchSimple, Launch, etc. | ||
| // Converts JavaScript arrays to C string arrays | ||
| %typemap(in) char ** { | ||
| if ($input->IsArray()) { | ||
| v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast($input); | ||
| uint32_t length = array->Length(); | ||
| $1 = (char **)malloc((length + 1) * sizeof(char *)); | ||
|
|
||
| for (uint32_t i = 0; i < length; i++) { | ||
| v8::Local<v8::Value> element; | ||
| if (array->Get(SWIGV8_CURRENT_CONTEXT(), i).ToLocal(&element)) { | ||
| if (element->IsString()) { | ||
| v8::String::Utf8Value str(SWIGV8_CURRENT_CONTEXT()->GetIsolate(), element); | ||
| $1[i] = strdup(*str); | ||
| } else { | ||
| free($1); | ||
| SWIG_exception_fail(SWIG_TypeError, "Array elements must be strings"); | ||
| } | ||
| } | ||
| } | ||
| $1[length] = NULL; | ||
| } else if ($input->IsNull() || $input->IsUndefined()) { | ||
| $1 = NULL; | ||
| } else { | ||
| SWIG_exception_fail(SWIG_TypeError, "Expected array of strings or null"); | ||
| } | ||
| } | ||
|
|
||
| %typemap(freearg) char ** { | ||
| if ($1) { | ||
| for (int i = 0; $1[i] != NULL; i++) { | ||
| free($1[i]); | ||
| } | ||
| free($1); | ||
| } | ||
| } | ||
|
|
||
| %typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) char ** { | ||
| $1 = $input->IsArray() || $input->IsNull() || $input->IsUndefined(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /* | ||
| JavaScript-specific wrapper functions for LLDB | ||
| */ | ||
|
|
||
| // This file will contain JavaScript-specific wrapper code | ||
| // to bridge between LLDB's C++ API and JavaScript/V8 | ||
|
|
||
| // TODO: Add wrapper functions for: | ||
| // - Breakpoint callbacks | ||
| // - Watchpoint callbacks | ||
| // - Custom commands | ||
| // - Data formatters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| lldb.swig | ||
| This is the input file for SWIG, to create the appropriate C++ wrappers and | ||
| functions for JavaScript (V8/Node.js), to enable them to call the | ||
| liblldb Script Bridge functions. | ||
| */ | ||
|
|
||
| %module lldb | ||
|
|
||
| %include <std_string.i> | ||
| %include "javascript-typemaps.swig" | ||
| %include "macros.swig" | ||
| %include "headers.swig" | ||
|
|
||
| %{ | ||
| #include "llvm/Support/Error.h" | ||
| #include "llvm/Support/FormatVariadic.h" | ||
| #include "../bindings/javascript/javascript-swigsafecast.swig" | ||
| #include "../source/Plugins/ScriptInterpreter/JavaScript/SWIGJavaScriptBridge.h" | ||
|
|
||
| // required headers for typemaps | ||
| #include "lldb/Host/File.h" | ||
|
|
||
| using namespace lldb_private; | ||
| using namespace lldb; | ||
| %} | ||
|
|
||
| %include "interfaces.swig" | ||
| %include "javascript-wrapper.swig" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #.rst: | ||
| # FindV8 | ||
| # ------ | ||
| # | ||
| # Find V8 JavaScript engine | ||
| # | ||
| # This module will search for V8 in standard system locations, or use | ||
| # user-specified paths. Users can override the search by setting: | ||
| # -DV8_INCLUDE_DIR=/path/to/v8/include | ||
| # -DV8_LIBRARIES=/path/to/libv8.so (or libv8_monolith.a) | ||
| # | ||
| # The module defines: | ||
| # V8_FOUND - System has V8 | ||
| # V8_INCLUDE_DIR - V8 include directory | ||
| # V8_LIBRARIES - V8 libraries to link against | ||
|
|
||
| if(V8_LIBRARIES AND V8_INCLUDE_DIR) | ||
| set(V8_FOUND TRUE) | ||
| if(NOT V8_FIND_QUIETLY) | ||
| message(STATUS "Found V8: ${V8_INCLUDE_DIR}") | ||
| message(STATUS "Found V8 library: ${V8_LIBRARIES}") | ||
| set(V8_FIND_QUIETLY TRUE CACHE BOOL "Suppress repeated V8 find messages" FORCE) | ||
| endif() | ||
| else() | ||
| # Try to find system V8 | ||
| find_path(V8_INCLUDE_DIR | ||
| NAMES v8.h | ||
| PATHS | ||
| # Standard system locations | ||
| /usr/include | ||
| /usr/local/include | ||
| /opt/v8/include | ||
| # Homebrew on macOS | ||
| /opt/homebrew/include | ||
| /usr/local/opt/v8/include | ||
| PATH_SUFFIXES | ||
| v8 | ||
| DOC "V8 include directory" | ||
| ) | ||
|
|
||
| find_library(V8_LIBRARIES | ||
| NAMES v8_monolith v8 v8_libbase v8_libplatform | ||
| PATHS | ||
| # Standard system locations | ||
| /usr/lib | ||
| /usr/local/lib | ||
| /opt/v8/lib | ||
| # Homebrew on macOS | ||
| /opt/homebrew/lib | ||
| /usr/local/opt/v8/lib | ||
| DOC "V8 library" | ||
| ) | ||
|
|
||
| include(FindPackageHandleStandardArgs) | ||
| find_package_handle_standard_args(V8 | ||
| FOUND_VAR | ||
| V8_FOUND | ||
| REQUIRED_VARS | ||
| V8_INCLUDE_DIR | ||
| V8_LIBRARIES) | ||
|
|
||
| if(V8_FOUND) | ||
| mark_as_advanced(V8_LIBRARIES V8_INCLUDE_DIR) | ||
| message(STATUS "Found V8: ${V8_INCLUDE_DIR}") | ||
| if(V8_LIBRARIES) | ||
| message(STATUS "Found V8 library: ${V8_LIBRARIES}") | ||
| else() | ||
| message(STATUS "V8 headers found (library may need to be built or specified manually)") | ||
| endif() | ||
| endif() | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.