[Lldb-commits] [PATCH] D108078: [lldb] Support gdbserver signals [WIP]

2021-08-15 Thread Michał Górny via Phabricator via lldb-commits
mgorny updated this revision to Diff 366487.
mgorny edited the summary of this revision.
mgorny added a comment.

Added client tests for GDB and LLDB signal variants. Moved signal init into 
`DidLaunchOrAttach`, in order to have normalized target triple already (needed 
for correct os-name in test).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108078/new/

https://reviews.llvm.org/D108078

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
  lldb/source/Plugins/Process/Utility/GDBRemoteSignals.cpp
  lldb/source/Plugins/Process/Utility/GDBRemoteSignals.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py

Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
===
--- lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
@@ -351,3 +351,49 @@
   "QEnvironmentHexEncoded:4e45454453454e43343d6623726f62",
   "QEnvironmentHexEncoded:455155414c533d666f6f3d626172",
 ])
+
+def test_signal_gdb(self):
+class MyResponder(MockGDBServerResponder):
+def qSupported(self, client_supported):
+return "PacketSize=3fff;QStartNoAckMode+"
+
+def haltReason(self):
+return "S0a"
+
+def cont(self):
+return self.haltReason()
+
+self.server.responder = MyResponder()
+
+target = self.createTarget("a.yaml")
+process = self.connect(target)
+
+self.assertEqual(process.threads[0].GetStopReason(),
+ lldb.eStopReasonSignal)
+self.assertEqual(process.threads[0].GetStopDescription(100),
+ 'signal SIGBUS')
+
+def test_signal_lldb(self):
+class MyResponder(MockGDBServerResponder):
+def qSupported(self, client_supported):
+return "PacketSize=3fff;QStartNoAckMode+;native-signals+"
+
+def qHostInfo(self):
+return "triple:61726d76372d756e6b6e6f776e2d6c696e75782d676e75;"
+
+def haltReason(self):
+return "S0a"
+
+def cont(self):
+return self.haltReason()
+
+self.server.responder = MyResponder()
+
+target = self.createTarget("a.yaml")
+process = self.connect(target)
+
+self.assertEqual(process.threads[0].GetStopReason(),
+ lldb.eStopReasonSignal)
+# NB: this may need adjusting per current platform
+self.assertEqual(process.threads[0].GetStopDescription(100),
+ 'signal SIGUSR1')
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -719,14 +719,6 @@
 __FUNCTION__, GetID(),
 GetTarget().GetArchitecture().GetTriple().getTriple().c_str());
 
-  if (error.Success()) {
-PlatformSP platform_sp = GetTarget().GetPlatform();
-if (platform_sp && platform_sp->IsConnected())
-  SetUnixSignals(platform_sp->GetUnixSignals());
-else
-  SetUnixSignals(UnixSignals::Create(GetTarget().GetArchitecture()));
-  }
-
   return error;
 }
 
@@ -,6 +1103,18 @@
   if (StructuredData::Array *supported_packets =
   m_gdb_comm.GetSupportedStructuredDataPlugins())
 MapSupportedStructuredDataPlugins(*supported_packets);
+
+  // If connected to LLDB ("native-signals+"), use signal defs for
+  // the remote platform.  If connected to GDB, just use the standard set.
+  if (!m_gdb_comm.UsesNativeSignals()) {
+SetUnixSignals(std::make_shared());
+  } else {
+PlatformSP platform_sp = GetTarget().GetPlatform();
+if (platform_sp && platform_sp->IsConnected())
+  SetUnixSignals(platform_sp->GetUnixSignals());
+else
+  SetUnixSignals(UnixSignals::Create(GetTarget().GetArchitecture()));
+  }
 }
 
 void ProcessGDBRemote::MaybeLoadExecutableModule() {
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -1341,5 +1341,6 @@
   llvm::formatv("PacketSize={0}", max_packet_size),
   "QStartNoAckMode+",
   "qEcho+",
+  "native-signals+",
   };
 }
Index: lldb/source/Plugins/Process/gdb-remote/GD

[Lldb-commits] [PATCH] D104281: [lldb][docs] Add reference docs for Lua scripting

2021-08-15 Thread Siger Young via Phabricator via lldb-commits
siger-young updated this revision to Diff 366494.
siger-young added a comment.

This update marks features that are only supported by Python, and adds Lua
example code for using LLDB module.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104281/new/

https://reviews.llvm.org/D104281

Files:
  lldb/docs/conf.py
  lldb/docs/index.rst
  lldb/docs/use/python-reference.rst
  lldb/docs/use/python.rst
  lldb/docs/use/scripting-example.rst
  lldb/docs/use/scripting-reference.rst

Index: lldb/docs/use/scripting-reference.rst
===
--- lldb/docs/use/scripting-reference.rst
+++ lldb/docs/use/scripting-reference.rst
@@ -1,23 +1,32 @@
-Python Reference
-
+Scripting Reference
+===
 
-The entire LLDB API is available as Python functions through a script bridging
-interface. This means the LLDB API's can be used directly from python either
-interactively or to build python apps that provide debugger features.
-
-Additionally, Python can be used as a programmatic interface within the lldb
-command interpreter (we refer to this for brevity as the embedded interpreter).
+Python can be used as a programmatic interface within the LLDB command
+interpreter (we refer to this for brevity as the embedded interpreter).
 Of course, in this context it has full access to the LLDB API - with some
 additional conveniences we will call out in the FAQ.
 
+Additionally, the entire LLDB API is available as Python functions through
+a script bridging interface. This means the LLDB API's can be used directly
+from Python either interactively or to build Python apps that provide debugger
+features.
+
+At present, Lua is experimentally available as an embedded interpreter in LLDB.
+Moreover, LLDB API is also visible to standalone Lua. Since some scripting
+features are still unavailable in Lua, there is no language switch tab on code
+blocks of unsupported features.
+
+If you want to use Lua interpreter, you should ensure that your LLDB is compiled
+with Lua support. See :doc:`Building ` for instructions. 
+
 .. contents::
:local:
 
-Documentation
---
+Built-in Documentation
+--
 
-The LLDB API is contained in a python module named lldb. A useful resource when
-writing Python extensions is the lldb Python classes reference guide.
+The LLDB API is contained in a Python module named ``lldb``. A useful resource
+when writing Python extensions is the `lldb` Python classes reference guide.
 
 The documentation is also accessible in an interactive debugger session with
 the following command:
@@ -54,7 +63,8 @@
   |
...
 
-Or you can get help using any python object, here we use the lldb.process
+
+Or you can get help using any Python object, here we use the lldb.process
 object which is a global variable in the lldb module which represents the
 currently selected process:
 
@@ -74,25 +84,53 @@
   |
...
 
-Embedded Python Interpreter
+Embedded Script Interpreter
 ---
 
-The embedded python interpreter can be accessed in a variety of ways from
-within LLDB. The easiest way is to use the lldb command script with no
-arguments at the lldb command prompt:
+The embedded script interpreter can be accessed in a variety of ways from
+within LLDB. The easiest way is to use the LLDB command ``script`` with no
+arguments at the LLDB command prompt.
+
+By default, the embedded script interpreter is Python. To choose the language
+you prefer, you can specify default language via ``--script-language`` options
+when launching LLDB:
+
+::
+
+   $ lldb --script-language lua
+
+or pass a parameter to LLDB command ``script``.
 
 ::
 
-   (lldb) script
-   Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
-   >>> 2+3
-   5
-   >>> hex(12345)
-   '0x3039'
-   >>>
+   (lldb) script -l lua --
+
+Language features are all available in the embedded script interpreter:
+
+.. tabs::
+   .. code-tab:: python
+
+  (lldb) script
+  Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
+  >>> 2+3
+  5
+  >>> hex(12345)
+  '0x3039'
+  >>>
+
+   .. code-tab:: lua
+  :emphasize-lines: 1
 
-This drops you into the embedded python interpreter. When running under the
-script command, lldb sets some convenience variables that give you quick access
+  (lldb) script -l lua --
+  >>> t = { 1, 2, 3 }
+  >>> print(t[1])
+  1
+  >>> print(t[1] + t[2])
+  3
+  >>>
+
+This drops you into the embedded script interpreter. When running under the
+script command, LLDB sets some convenience variables that give you quick access
 to the currently selected entities that characterize the program and debugger
 state. In each case, if there is no currently selected entity of the
 appropriate type, the variable's IsValid method will return false. These
@@ -138,60 +176,84 @@
 
 Moreover, t

[Lldb-commits] [PATCH] D108088: [lldb] Avoid unhandled Error in TypeSystemMap::GetTypeSystemForLanguage

2021-08-15 Thread Dimitry Andric via Phabricator via lldb-commits
dim created this revision.
dim added reviewers: aprantl, emaste, JDevlieghere, teemperor.
Herald added subscribers: krytarowski, arichardson.
dim requested review of this revision.
Herald added a project: LLDB.

When assertions are turned off, the `llvm::Error` value created at the
start of this function is overwritten using the move-assignment
operator, but the success value is never checked. Whenever a TypeSystem
cannot be found or created, this can lead to lldb core dumping with:

  Program aborted due to an unhandled Error:
  Error value was Success. (Note: Success values must still be checked prior to 
being destroyed).

Fix this by not creating a `llvm::Error` value in advance, and directly
returning the result of `llvm::make_error` instead, whenever an error is
encountered.

See also: https://bugs.freebsd.org/253881 and
https://bugs.freebsd.org/257829.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108088

Files:
  lldb/source/Symbol/TypeSystem.cpp

Index: lldb/source/Symbol/TypeSystem.cpp
===
--- lldb/source/Symbol/TypeSystem.cpp
+++ lldb/source/Symbol/TypeSystem.cpp
@@ -223,62 +223,32 @@
 llvm::Expected TypeSystemMap::GetTypeSystemForLanguage(
 lldb::LanguageType language,
 llvm::Optional create_callback) {
-  llvm::Error error = llvm::Error::success();
-  assert(!error); // Check the success value when assertions are enabled
   std::lock_guard guard(m_mutex);
-  if (m_clear_in_progress) {
-error = llvm::make_error(
+  if (m_clear_in_progress)
+return llvm::make_error(
 "Unable to get TypeSystem because TypeSystemMap is being cleared",
 llvm::inconvertibleErrorCode());
-  } else {
-collection::iterator pos = m_map.find(language);
-if (pos != m_map.end()) {
-  auto *type_system = pos->second.get();
-  if (type_system) {
-llvm::consumeError(std::move(error));
-return *type_system;
-  }
-  error = llvm::make_error(
-  "TypeSystem for language " +
-  llvm::StringRef(Language::GetNameForLanguageType(language)) +
-  " doesn't exist",
-  llvm::inconvertibleErrorCode());
-  return std::move(error);
-}
 
-for (const auto &pair : m_map) {
-  if (pair.second && pair.second->SupportsLanguage(language)) {
-// Add a new mapping for "language" to point to an already existing
-// TypeSystem that supports this language
-m_map[language] = pair.second;
-if (pair.second.get()) {
-  llvm::consumeError(std::move(error));
-  return *pair.second.get();
-}
-error = llvm::make_error(
-"TypeSystem for language " +
-llvm::StringRef(Language::GetNameForLanguageType(language)) +
-" doesn't exist",
-llvm::inconvertibleErrorCode());
-return std::move(error);
-  }
-}
+  collection::iterator pos = m_map.find(language);
+  if (pos != m_map.end()) {
+auto *type_system = pos->second.get();
+if (type_system)
+  return *type_system;
+return llvm::make_error(
+"TypeSystem for language " +
+llvm::StringRef(Language::GetNameForLanguageType(language)) +
+" doesn't exist",
+llvm::inconvertibleErrorCode());
+  }
 
-if (!create_callback) {
-  error = llvm::make_error(
-  "Unable to find type system for language " +
-  llvm::StringRef(Language::GetNameForLanguageType(language)),
-  llvm::inconvertibleErrorCode());
-} else {
-  // Cache even if we get a shared pointer that contains a null type system
-  // back
-  TypeSystemSP type_system_sp = (*create_callback)();
-  m_map[language] = type_system_sp;
-  if (type_system_sp.get()) {
-llvm::consumeError(std::move(error));
-return *type_system_sp.get();
-  }
-  error = llvm::make_error(
+  for (const auto &pair : m_map) {
+if (pair.second && pair.second->SupportsLanguage(language)) {
+  // Add a new mapping for "language" to point to an already existing
+  // TypeSystem that supports this language
+  m_map[language] = pair.second;
+  if (pair.second.get())
+return *pair.second.get();
+  return llvm::make_error(
   "TypeSystem for language " +
   llvm::StringRef(Language::GetNameForLanguageType(language)) +
   " doesn't exist",
@@ -286,7 +256,23 @@
 }
   }
 
-  return std::move(error);
+  if (!create_callback)
+return llvm::make_error(
+"Unable to find type system for language " +
+llvm::StringRef(Language::GetNameForLanguageType(language)),
+llvm::inconvertibleErrorCode());
+
+  // Cache even if we get a shared pointer that contains a null type system
+  // back
+  TypeSystemSP type_system_sp = (*create_callback)();
+  m_map[language] = type_system_sp;
+  if (type_system_sp.get())
+return *type_system_sp.get();
+  re

[Lldb-commits] [PATCH] D108090: [lldb/lua] Supplement typemaps for Lua bindings

2021-08-15 Thread Siger Young via Phabricator via lldb-commits
siger-young created this revision.
Herald added a subscriber: mgorny.
siger-young requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Add necessary typemaps for Lua bindings.

Signed-off-by: Siger Yang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108090

Files:
  lldb/CMakeLists.txt
  lldb/bindings/lua/CMakeLists.txt
  lldb/bindings/lua/lua-typemaps.swig
  lldb/bindings/lua/lua-wrapper.swig
  lldb/bindings/lua/lua.swig
  lldb/source/API/liblldb-private.exports
  lldb/source/API/liblldb.exports

Index: lldb/source/API/liblldb.exports
===
--- lldb/source/API/liblldb.exports
+++ lldb/source/API/liblldb.exports
@@ -2,3 +2,4 @@
 _ZNK4lldb*
 init_lld*
 PyInit__lldb*
+luaopen_lldb*
Index: lldb/source/API/liblldb-private.exports
===
--- lldb/source/API/liblldb-private.exports
+++ lldb/source/API/liblldb-private.exports
@@ -4,3 +4,4 @@
 _ZNK12lldb_private*
 init_lld*
 PyInit__lldb*
+luaopen_lldb*
Index: lldb/bindings/lua/lua.swig
===
--- lldb/bindings/lua/lua.swig
+++ lldb/bindings/lua/lua.swig
@@ -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;
 %}
Index: lldb/bindings/lua/lua-wrapper.swig
===
--- lldb/bindings/lua/lua-wrapper.swig
+++ lldb/bindings/lua/lua-wrapper.swig
@@ -6,6 +6,19 @@
 
 %}
 
+%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
@@ -88,5 +101,20 @@
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.");
+}
 
 %}
Index: lldb/bindings/lua/lua-typemaps.swig
===
--- lldb/bindings/lua/lua-typemaps.swig
+++ lldb/bindings/lua/lua-typemaps.swig
@@ -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
@@ -54,6 +54,7 @@
 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 & };
@@ -77,7 +78,7 @@
 %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);
 }
@@ -86,6 +87,9 @@
 // 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
@@ -102,4 +106,178 @@
 // 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:

[Lldb-commits] [PATCH] D108090: [lldb/lua] Supplement typemaps for Lua bindings

2021-08-15 Thread Siger Young via Phabricator via lldb-commits
siger-young updated this revision to Diff 366520.
siger-young added a comment.

Using `lua_newuserdata` instead of `lua_newuserdatauv` to support Lua 5.3


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108090/new/

https://reviews.llvm.org/D108090

Files:
  lldb/CMakeLists.txt
  lldb/bindings/lua/CMakeLists.txt
  lldb/bindings/lua/lua-typemaps.swig
  lldb/bindings/lua/lua-wrapper.swig
  lldb/bindings/lua/lua.swig
  lldb/source/API/liblldb-private.exports
  lldb/source/API/liblldb.exports

Index: lldb/source/API/liblldb.exports
===
--- lldb/source/API/liblldb.exports
+++ lldb/source/API/liblldb.exports
@@ -2,3 +2,4 @@
 _ZNK4lldb*
 init_lld*
 PyInit__lldb*
+luaopen_lldb*
Index: lldb/source/API/liblldb-private.exports
===
--- lldb/source/API/liblldb-private.exports
+++ lldb/source/API/liblldb-private.exports
@@ -4,3 +4,4 @@
 _ZNK12lldb_private*
 init_lld*
 PyInit__lldb*
+luaopen_lldb*
Index: lldb/bindings/lua/lua.swig
===
--- lldb/bindings/lua/lua.swig
+++ lldb/bindings/lua/lua.swig
@@ -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;
 %}
Index: lldb/bindings/lua/lua-wrapper.swig
===
--- lldb/bindings/lua/lua-wrapper.swig
+++ lldb/bindings/lua/lua-wrapper.swig
@@ -6,6 +6,19 @@
 
 %}
 
+%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
@@ -88,5 +101,20 @@
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.");
+}
 
 %}
Index: lldb/bindings/lua/lua-typemaps.swig
===
--- lldb/bindings/lua/lua-typemaps.swig
+++ lldb/bindings/lua/lua-typemaps.swig
@@ -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
@@ -54,6 +54,7 @@
 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 & };
@@ -77,7 +78,7 @@
 %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);
 }
@@ -86,6 +87,9 @@
 // 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
@@ -102,4 +106,178 @@
 // 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