Skip to content
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

[pull] main from MaxMood96:main #148

Merged
merged 102 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
e76689e
Add self to .mailmap
zmodem Oct 12, 2021
564e082
[PowerPC] Allow MMA built-ins to accept restrict and volatile qualifi…
Sep 13, 2021
40546cb
Remove 'IgnoreDestructors = true' from cppcoreguidelines-explicit-vir…
carlosgalvezp Oct 12, 2021
67f94e5
[lldb/lua] Supplement Lua bindings for lldb module
ttyS0 Oct 12, 2021
97d67f7
[mlir][linalg] Add vector transfer lowering patters to codegen strategy.
Oct 12, 2021
444ec09
[clang] p0388 array list initialization overloads
urnathan May 21, 2021
a76cfc2
[clang-tidy] Update documentation of check bugprone-unused-return-val…
balazske Oct 12, 2021
dcd7471
[clang] p0388 conversion to incomplete array
urnathan May 20, 2021
2eb42e3
[AArch64][SVE] Add fixed type lowering for EXTRACT_SUBVECTOR
brads55 Oct 5, 2021
c8faeb1
[mlir][linalg] Add switch to disable/enable vector transfer lowering.
Oct 12, 2021
838b4a5
[DebugInfo][NFC] Move LiveDebugValues class to header
jmorse Oct 12, 2021
66e13c7
[AMDGPU] Enable load clustering in the post-RA scheduler
jayfoad Oct 12, 2021
f7ee21a
[TwoAddressInstruction] Remove ad hoc machine verification
jayfoad Oct 12, 2021
66ce101
Revert "[AMDGPU] Enable load clustering in the post-RA scheduler"
jayfoad Oct 12, 2021
6cac17e
[libcxx] [test] Make windows triples in XFAILs less specific
mstorsjo Aug 27, 2021
a76e698
[libc++] Update atomic synopsis and tests.
mordante Jun 6, 2021
55e76c7
[mlir] Limit Python dependency to Development.Module when possible.
mikeurbach Oct 11, 2021
519b350
[mlir][vector] Add folder for no-op InsertStridedSliceOp
antiagainst Oct 12, 2021
9fc35c3
[mlir][sparse] add action enum, group enums together, few asserts
aartbik Oct 12, 2021
1112b7b
[libcxx][AIX] Explicitly include localedef.h in locale.cpp
daltenty Oct 12, 2021
d9fa186
Scatter NDEBUG to fix after 838b4a533e6
jmorse Oct 12, 2021
968e273
[libc++] Use addressof to fix debug tests.
mordante Oct 10, 2021
f565488
[Clang][clang-nvlink-wrapper] Pass nvlink path to the wrapper
saiislam Oct 9, 2021
aefaf16
[TableGen] Fix both sides of '&&' are same
topperc Oct 12, 2021
57b40b5
[AST, CodeGen, Driver] Use llvm::is_contained (NFC)
kazutakahirata Oct 12, 2021
f05c95f
[flang] More work on SYSTEM_CLOCK runtime API and implementation
klausler Oct 6, 2021
098a0d8
[CSSPGO] Unblock optimizations with pseudo probe instrumentation part 3.
htyu Sep 30, 2021
fe2d053
Added OpenMP 5.0 specification based semantic checks for CRITICAL con…
NimishMishra Oct 12, 2021
7964c3e
[X86] `detectAVGPattern()`: small preparatory NFC refactor
LebedevRI Oct 12, 2021
5f4f5da
[X86] `detectAVGPattern()`: support basic case of PAVG chaining (PR52…
LebedevRI Oct 12, 2021
fae7d68
[InstCombine] add tests with nsw/nuw for mul-of-select; NFC
rotateright Oct 12, 2021
7a29496
[InstCombine] propagate no-wrap flag through select-of-mul fold
rotateright Oct 12, 2021
9cf995b
[AMDGPU] Promote generic pointer kernel arguments into global
rampitec Oct 8, 2021
f67d57c
[mlir][Shape] Add a pattern to turn extract from shape_of into tensor…
d0k Oct 12, 2021
a1d57f7
[NFC][X86] `detectAVGPattern()`: rely on `AVGSplitter()` to perform t…
LebedevRI Oct 12, 2021
bbc2fc5
[Support][ORC] Add an explicit release operation to OwningMemoryBlock.
lhames Oct 12, 2021
0902451
[NFC][X86] Add another test case for PR52131
LebedevRI Oct 12, 2021
958da65
[X86] `detectAVGPattern()`: don't require zext in the with-constant case
LebedevRI Oct 12, 2021
2cc4275
[clang/CFG] Don't explicitly add AttributedStmtClass to AlwaysAddList
nico Oct 11, 2021
532d71c
[gn build] (manually) port 67f94e5a9745
nico Oct 12, 2021
e9119a7
[gn build] Port 838b4a533e68
llvmgnsyncbot Oct 12, 2021
27bc1e6
[gn build] Port 9cf995be6bb7
llvmgnsyncbot Oct 12, 2021
f3ec9d8
[analyzer] Fix non-obvious analyzer warning: Use of zero-allocated me…
haoNoQ Oct 12, 2021
ea4a6c8
[Inline] Make sure the InlineAdvisor is correctly cleared.
mtrofin Oct 11, 2021
bdf6ba2
[FPEnv][InstSimplify] Precommit tests: Enable more folds for constrai…
kpneal Oct 12, 2021
86a4a93
[docs] [NFC] Clarify the datalayout documentation
woodruffw Oct 12, 2021
b4db2a5
[sanitizer] Fix StackDepotPrintAll
vitalybuka Oct 12, 2021
63638ed
[mlir][linalg] Enable the vector transfer lowering by default.
Oct 12, 2021
9e9803b
[libc] Add strncat and fix strcat
michaelrj-google Oct 11, 2021
2682733
Remove checks for old gcc versions for LLVM_ATTRIBUTE_*
aeubanks Oct 11, 2021
5abce56
[GlobalISel] Add support for constant vector folding of binops in CSE…
aemerson Oct 11, 2021
15692fd
[LV] Fix 2nd crash for reverse interleaved groups under mask/fold-tail.
azaks Aug 29, 2021
357b8d7
[tests] Add coverage for cases we can drop flags to propagate freeze …
preames Oct 12, 2021
04d76d3
[mlir][python] Add nameloc getter
jpienaar Oct 12, 2021
f7858e7
[flang] Fix build on FreeBSD (need size_t)
klausler Oct 12, 2021
dfa8d33
DebugInfo: Update ranges_always.ll to include more details about how …
dwblaikie Oct 11, 2021
d7e766c
DebugInfo: Add test coverage for non-zero addrx in DW_FORM_LLVM_addrx…
dwblaikie Oct 12, 2021
95e4b71
[mlir][tosa] Fix tosa average_pool2d to linalg type issue
rsuderman Oct 12, 2021
28e648b
[PowerPC] Simplify PPC codegen test pre-inc-disable.ll
RolandF77 Oct 12, 2021
0e0d3b3
[sanitizer] Fix typo in test
vitalybuka Oct 12, 2021
336e886
[sanitizer] Fix test on Windows
vitalybuka Oct 12, 2021
c24b2ad
Add extra tests for D111675
preames Oct 12, 2021
9939e56
[NFC][sanitizer] Refactor Maps into templates
vitalybuka Oct 11, 2021
2815ed5
[ORC] Shut down dispatcher in ExecutorProcessControl implementations.
lhames Oct 12, 2021
b4b9f9b
[PowerPC] Emit dcbt and dcbtst in place of their extended mnemonics o…
Conanap Oct 12, 2021
884d290
[sanitizer] Remove SpinMutexLock from stat function
vitalybuka Oct 10, 2021
6f34839
[instcombine] propagate freeze through single use poison producing fl…
preames Oct 12, 2021
38f121c
[sanitizer] Switch StackDepot to TwoLevelMap
vitalybuka Oct 11, 2021
d80a5d5
[NFC][sanitizer] Move consts into on top of the class
vitalybuka Oct 12, 2021
68d6923
[fir] Add cfg conversion pass
jeanPerier Oct 12, 2021
f09dce5
[lld] fix typos to cycle bots
nico Oct 12, 2021
5c1d356
[mlir][Linalg] Enable vectorization of explicit broadcasts
dcaballe Oct 12, 2021
eeb09fd
[mlir][Linalg] Enable vectorization of 'mul', 'and', 'or' and 'xor' r…
dcaballe Oct 12, 2021
67905bc
[sanitizer] Re-enable test on Windows
vitalybuka Oct 12, 2021
d402fb0
[NFC][sanitizer] Clang-format a line
vitalybuka Oct 12, 2021
2cadef6
[clang] Teardown new PM data structures before running codegen pipeline
aeubanks Oct 11, 2021
19b4e3c
[ORC] Call ExecutionSession::endSession in unit tests.
lhames Oct 12, 2021
f526ee5
[CUDA] Provide address space conversion builtins.
Artem-B Oct 12, 2021
adf55ac
[ORC] Call ExecutorProcessControl::disconnect in unit tests that requ…
lhames Oct 12, 2021
3ec4d4d
[NFC][sanitizer] Add a few consts
vitalybuka Oct 12, 2021
f815c2c
[sanitizer] Fix test on Windows
vitalybuka Oct 12, 2021
b6a8c69
[NFC] Rename EmitAssemblyHelper new/legacy PM methods
aeubanks Oct 12, 2021
7c97e32
[mlir][linalg] Fix generic reduction vectorization
ThomasRaoux Oct 12, 2021
ce7f8c8
[sanitizer] Remove id and replace link with u32
vitalybuka Oct 12, 2021
ca0036d
[sanitizer] Remove StackDepotReverseMap
vitalybuka Oct 12, 2021
49142dd
[flang][NFC] Address warnings from Windows build
klausler Oct 12, 2021
6ee2aa1
[flang][NFC] Document extension: scalars are trivially contiguous
klausler Oct 12, 2021
f65f830
[flang] runtime: fix output B/O/Z editing of "negative" values
klausler Oct 11, 2021
aa71f48
[mlir] update new linalg vectorization tests after vectorization fix
ThomasRaoux Oct 12, 2021
1b81581
[lldb][test] Remove Intel MPX tests
MaskRay Oct 12, 2021
c2d4fe5
[X86] Remove little support we had for MPX
MaskRay Oct 12, 2021
a6ddb7c
[mlir][linalg][bufferize][NFC] Reduce code duplication around bufferi…
matthias-springer Oct 13, 2021
02410df
[flang] Fix Windows build
klausler Oct 13, 2021
fd31620
[mlir][linalg][bufferize][NFC] Conflict detection funcs take OpOperan…
matthias-springer Oct 13, 2021
7c3a810
[mlir][linalg][bufferize] Put buffer copying in separate function
matthias-springer Oct 13, 2021
0292236
[mlir][linalg][bufferize][NFC] Simplify allocateBuffersForResults
matthias-springer Oct 13, 2021
bc1a0c2
[flang] Fix "latest-clang" build warnings
klausler Oct 13, 2021
0ee5323
[mlir][linalg][bufferize][NFC] Simplify getAliasingOpOperand signature
matthias-springer Oct 13, 2021
441485c
[mlir][linalg][bufferize][NFC] Remove InSpaceSpec from bufferizesToMe…
matthias-springer Oct 13, 2021
787eeb8
[RISCV] Optimize immediate materialisation with BCLRI
benshi001 Oct 11, 2021
ecc7f8a
[flang] Fix Windows build (take 2)
klausler Oct 13, 2021
9a70eb9
[profile] Remove emitting symbolizer markup
gulfemsavrun Oct 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[lldb/lua] Supplement Lua bindings for lldb module
Add necessary typemaps for Lua bindings, together with some other files.

Signed-off-by: Siger Yang <sigeryeung@gmail.com>

Reviewed By: tammela

Differential Revision: https://reviews.llvm.org/D108090
  • Loading branch information
ttyS0 committed Oct 12, 2021
commit 67f94e5a9745665dd62550c75cb16569fbb0059d
17 changes: 17 additions & 0 deletions lldb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ if (LLDB_ENABLE_PYTHON)
CACHE STRING "Path where Python modules are installed, relative to install prefix")
endif ()

if (LLDB_ENABLE_LUA)
find_program(Lua_EXECUTABLE lua5.3)
set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/5.3")
set(LLDB_LUA_RELATIVE_PATH ${LLDB_LUA_DEFAULT_RELATIVE_PATH}
CACHE STRING "Path where Lua modules are installed, relative to install prefix")
endif ()

if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA)
add_subdirectory(bindings)
endif ()
Expand Down Expand Up @@ -94,6 +101,16 @@ if (LLDB_ENABLE_PYTHON)
finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")
endif()

if (LLDB_ENABLE_LUA)
if(LLDB_BUILD_FRAMEWORK)
set(lldb_lua_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
else()
set(lldb_lua_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
endif()
get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR)
finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${lldb_lua_target_dir}")
endif()

option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
if(LLDB_INCLUDE_TESTS)
add_subdirectory(test)
Expand Down
52 changes: 52 additions & 0 deletions lldb/bindings/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,55 @@ add_custom_command(
add_custom_target(swig_wrapper_lua ALL DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp
)

function(create_lua_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_lua swig_target lldb_lua_bindings_dir lldb_lua_target_dir)
add_custom_target(${swig_target} ALL VERBATIM
COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_lua_target_dir}
DEPENDS swig_wrapper_lua
COMMENT "LLDB Lua 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)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd")
else()
set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd")
endif()
else()
set(LIBLLDB_SYMLINK_OUTPUT_FILE "lldb.so")
endif()
create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
${lldb_lua_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE})
set(lldb_lua_library_target "${swig_target}-library")
add_custom_target(${lldb_lua_library_target})
add_dependencies(${lldb_lua_library_target} ${swig_target})

# Ensure we do the Lua post-build step when building lldb.
add_dependencies(lldb ${swig_target})

if(LLDB_BUILD_FRAMEWORK)
set(LLDB_LUA_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/Python)
else()
set(LLDB_LUA_INSTALL_PATH ${LLDB_LUA_RELATIVE_PATH})
endif()
install(DIRECTORY ${lldb_lua_target_dir}/
DESTINATION ${LLDB_LUA_INSTALL_PATH}
COMPONENT ${lldb_lua_library_target})

set(lldb_lua_library_install_target "install-${lldb_lua_library_target}")
if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(${lldb_lua_library_install_target}
COMPONENT ${lldb_lua_library_target}
DEPENDS ${lldb_lua_library_target})
endif()
endfunction()
215 changes: 213 additions & 2 deletions lldb/bindings/lua/lua-typemaps.swig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Primitive integer mapping
%typemap(in,checkfn="lua_isinteger") TYPE
%{ $1 = (TYPE)lua_tointeger(L, $input); %}
%{ $1 = ($type)lua_tointeger(L, $input); %}
%typemap(in,checkfn="lua_isinteger") const TYPE&($basetype temp)
%{ temp=($basetype)lua_tointeger(L,$input); $1=&temp;%}
%typemap(out) TYPE
Expand Down Expand Up @@ -54,6 +54,7 @@ LLDB_NUMBER_TYPEMAP(signed long);
LLDB_NUMBER_TYPEMAP(long long);
LLDB_NUMBER_TYPEMAP(unsigned long long);
LLDB_NUMBER_TYPEMAP(signed long long);
LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);

%apply unsigned long { size_t };
%apply const unsigned long & { const size_t & };
Expand All @@ -77,7 +78,7 @@ LLDB_NUMBER_TYPEMAP(signed long long);
%typemap(in) (char *dst, size_t dst_len) {
$2 = luaL_checkinteger(L, $input);
if ($2 <= 0) {
return luaL_error(L, "Positive integer expected");
return luaL_error(L, "Positive integer expected");
}
$1 = (char *) malloc($2);
}
Expand All @@ -86,6 +87,9 @@ LLDB_NUMBER_TYPEMAP(signed long long);
// as char data instead of byte data.
%typemap(in) (void *char_buf, size_t size) = (char *dst, size_t dst_len);

// Also SBProcess::ReadMemory.
%typemap(in) (void *buf, size_t size) = (char *dst, size_t dst_len);

// Return the char buffer. Discarding any previous return result
%typemap(argout) (char *dst, size_t dst_len) {
lua_pop(L, 1); // Blow away the previous result
Expand All @@ -102,4 +106,211 @@ LLDB_NUMBER_TYPEMAP(signed long long);
// as char data instead of byte data.
%typemap(argout) (void *char_buf, size_t size) = (char *dst, size_t dst_len);

// Also SBProcess::ReadMemory.
%typemap(argout) (void *buf, size_t size) = (char *dst, size_t dst_len);

//===----------------------------------------------------------------------===//

// Typemap for handling a snprintf-like API like SBThread::GetStopDescription.

%typemap(in) (char *dst_or_null, size_t dst_len) {
$2 = luaL_checkinteger(L, $input);
if ($2 <= 0) {
return luaL_error(L, "Positive integer expected");
}
$1 = (char *)malloc($2);
}

%typemap(argout) (char *dst_or_null, size_t dst_len) {
lua_pop(L, 1); // Blow away the previous result
lua_pushlstring(L, (const char *)$1, $result);
free($1);
// SWIG_arg was already incremented
}

//===----------------------------------------------------------------------===//

// Typemap for handling SBModule::GetVersion

%typemap(in) (uint32_t *versions, uint32_t num_versions) {
$2 = 99;
$1 = (uint32_t *)malloc(sizeof(uint32_t) * $2);
}

%typemap(argout) (uint32_t *versions, uint32_t num_versions) {
uint32_t count = result;
if (count >= $2)
count = $2;
lua_newtable(L);
int i = 0;
while (i++ < count) {
lua_pushinteger(L, $1[i - 1]);
lua_seti(L, -2, i);
}
SWIG_arg++;
free($1);
}

//===----------------------------------------------------------------------===//

// Typemap for handling SBDebugger::SetLoggingCallback

%typemap(in) (lldb::LogOutputCallback log_callback, void *baton) {
$1 = LLDBSwigLuaCallLuaLogOutputCallback;
$2 = (void *)L;

luaL_checktype(L, 2, LUA_TFUNCTION);
lua_settop(L, 2);

lua_pushlightuserdata(L, (void *)&LLDBSwigLuaCallLuaLogOutputCallback);
lua_insert(L, 2);
lua_settable(L, LUA_REGISTRYINDEX);
}

//===----------------------------------------------------------------------===//

// Typemap for handling SBEvent::SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len)

%typemap(in) (const char *cstr, uint32_t cstr_len) {
$1 = (char *)luaL_checklstring(L, $input, (size_t *)&$2);
}

// Typemap for handling SBProcess::PutSTDIN

%typemap(in) (const char *src, size_t src_len) {
$1 = (char *)luaL_checklstring(L, $input, &$2);
}

// Typemap for handling SBProcess::WriteMemory, SBTarget::GetInstructions...

%typemap(in) (const void *buf, size_t size),
(const void *data, size_t data_len) {
$1 = (void *)luaL_checklstring(L, $input, &$2);
}

//===----------------------------------------------------------------------===//

// Typemap for handling char ** in SBTarget::LaunchSimple, SBTarget::Launch...

// It should accept a Lua table of strings, for stuff like "argv" and "envp".

%typemap(in) char ** {
if (lua_istable(L, $input)) {
size_t size = lua_rawlen(L, $input);
$1 = (char **)malloc((size + 1) * sizeof(char *));
int i = 0, j = 0;
while (i++ < size) {
lua_rawgeti(L, $input, i);
if (!lua_isstring(L, -1)) {
// if current element cannot be converted to string, raise an error
lua_pop(L, 1);
return luaL_error(L, "List should only contain strings");
}
$1[j++] = (char *)lua_tostring(L, -1);
lua_pop(L, 1);
}
$1[j] = 0;
} else if (lua_isnil(L, $input)) {
// "nil" is also acceptable, equivalent as an empty table
$1 = NULL;
} else {
return luaL_error(L, "A list of strings expected");
}
}

%typemap(freearg) char ** {
free((char *) $1);
}

%typecheck(SWIG_TYPECHECK_STRING_ARRAY) char ** {
$1 = (lua_istable(L, $input) || lua_isnil(L, $input));
}

//===----------------------------------------------------------------------===//

// Typemap for file handles (e.g. used in SBDebugger::SetOutputFile)

%typemap(in) lldb::FileSP {
luaL_Stream *p = (luaL_Stream *)luaL_checkudata(L, $input, LUA_FILEHANDLE);
lldb::FileSP file_sp;
file_sp = std::make_shared<lldb_private::NativeFile>(p->f, false);
if (!file_sp->IsValid())
return luaL_error(L, "Invalid file");
$1 = file_sp;
}

%typecheck(SWIG_TYPECHECK_POINTER) lldb::FileSP {
$1 = (lua_isuserdata(L, $input)) &&
(luaL_testudata(L, $input, LUA_FILEHANDLE) != nullptr);
}

// Typemap for file handles (e.g. used in SBDebugger::GetOutputFileHandle)

%typemap(out) lldb::FileSP {
lldb::FileSP &sp = $1;
if (sp && sp->IsValid()) {
luaL_Stream *p = (luaL_Stream *)lua_newuserdata(L, sizeof(luaL_Stream));
p->closef = &LLDBSwigLuaCloseFileHandle;
p->f = sp->GetStream();
luaL_setmetatable(L, LUA_FILEHANDLE);
SWIG_arg++;
}
}

//===----------------------------------------------------------------------===//

// Typemap for SBData::CreateDataFromUInt64Array, SBData::SetDataFromUInt64Array ...

%typemap(in) (uint64_t* array, size_t array_len),
(uint32_t* array, size_t array_len),
(int64_t* array, size_t array_len),
(int32_t* array, size_t array_len),
(double* array, size_t array_len) {
if (lua_istable(L, $input)) {
// It should accept a table of numbers.
$2 = lua_rawlen(L, $input);
$1 = ($1_ltype)malloc(($2) * sizeof($*1_type));
int i = 0, j = 0;
while (i++ < $2) {
lua_rawgeti(L, $input, i);
if (!lua_isnumber(L, -1)) {
// if current element cannot be converted to number, raise an error
lua_pop(L, 1);
return luaL_error(L, "List should only contain numbers");
}
$1[j++] = ($*1_ltype)lua_tonumber(L, -1);
lua_pop(L, 1);
}
} else if (lua_isnil(L, $input)) {
// "nil" is also acceptable, equivalent as an empty table
$1 = NULL;
$2 = 0;
} else {
// else raise an error
return luaL_error(L, "A list of numbers expected.");
}
}

%typemap(freearg) (uint64_t* array, size_t array_len),
(uint32_t* array, size_t array_len),
(int64_t* array, size_t array_len),
(int32_t* array, size_t array_len),
(double* array, size_t array_len) {
free($1);
}

//===----------------------------------------------------------------------===//

// Typemap for SBCommandReturnObject::PutCString

%typemap(in) (const char *string, int len) {
if (lua_isnil(L, $input)) {
$1 = NULL;
$2 = 0;
}
else {
$1 = (char *)luaL_checklstring(L, $input, (size_t *)&$2);
}
}

//===----------------------------------------------------------------------===//
28 changes: 28 additions & 0 deletions lldb/bindings/lua/lua-wrapper.swig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ PushSBClass(lua_State* L, T* obj);

%}

%runtime %{
#ifdef __cplusplus
extern "C" {
#endif

void LLDBSwigLuaCallLuaLogOutputCallback(const char *str, void *baton);
int LLDBSwigLuaCloseFileHandle(lua_State *L);

#ifdef __cplusplus
}
#endif
%}

%wrapper %{

// This function is called from Lua::CallBreakpointCallback
Expand Down Expand Up @@ -88,5 +101,20 @@ LLDBSwigLuaWatchpointCallbackFunction
return stop;
}

SWIGEXPORT void
LLDBSwigLuaCallLuaLogOutputCallback(const char *str, void *baton) {
lua_State *L = (lua_State *)baton;

lua_pushlightuserdata(L, (void *)&LLDBSwigLuaCallLuaLogOutputCallback);
lua_gettable(L, LUA_REGISTRYINDEX);

// FIXME: There's no way to report errors back to the user
lua_pushstring(L, str);
lua_pcall(L, 1, 0, 0);
}

int LLDBSwigLuaCloseFileHandle(lua_State *L) {
return luaL_error(L, "You cannot close a file handle used by lldb.");
}

%}
4 changes: 4 additions & 0 deletions lldb/bindings/lua/lua.swig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
#include "../bindings/lua/lua-swigsafecast.swig"

// required headers for typemaps
#include "lldb/Host/File.h"

using namespace lldb_private;
using namespace lldb;
%}
Expand Down
1 change: 1 addition & 0 deletions lldb/source/API/liblldb-private.exports
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ _ZN12lldb_private*
_ZNK12lldb_private*
init_lld*
PyInit__lldb*
luaopen_lldb*
1 change: 1 addition & 0 deletions lldb/source/API/liblldb.exports
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ _ZN4lldb*
_ZNK4lldb*
init_lld*
PyInit__lldb*
luaopen_lldb*
Loading