tatyana-krasnukha created this revision.
tatyana-krasnukha added reviewers: spyffe, clayborg, zturner.
tatyana-krasnukha added a project: LLDB.
Herald added a subscriber: lldb-commits.

Slightly refactored typemaps to combine overloading with default arguments.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D52376

Files:
  include/lldb/API/SBTarget.h
  scripts/Python/python-typemaps.swig
  scripts/interface/SBTarget.i
  source/API/SBTarget.cpp

Index: source/API/SBTarget.cpp
===================================================================
--- source/API/SBTarget.cpp
+++ source/API/SBTarget.cpp
@@ -1967,11 +1967,6 @@
 }
 
 lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
-                                                   uint32_t count) {
-  return ReadInstructions(base_addr, count, NULL);
-}
-
-lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
                                                    uint32_t count,
                                                    const char *flavor_string) {
   SBInstructionList sb_instructions;
@@ -2000,15 +1995,8 @@
 }
 
 lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
-                                                  const void *buf,
-                                                  size_t size) {
-  return GetInstructionsWithFlavor(base_addr, NULL, buf, size);
-}
-
-lldb::SBInstructionList
-SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
-                                    const char *flavor_string, const void *buf,
-                                    size_t size) {
+                                                  const void *buf, size_t size,
+                                                  const char *flavor_string) {
   SBInstructionList sb_instructions;
 
   TargetSP target_sp(GetSP());
@@ -2029,18 +2017,10 @@
 }
 
 lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
-                                                  const void *buf,
-                                                  size_t size) {
-  return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), NULL, buf,
-                                   size);
-}
-
-lldb::SBInstructionList
-SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
-                                    const char *flavor_string, const void *buf,
-                                    size_t size) {
-  return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
-                                   buf, size);
+                                                  const void *buf, size_t size,
+                                                  const char *flavor_string) {
+  return GetInstructions(
+      ResolveLoadAddress(base_addr), buf, size, flavor_string);
 }
 
 SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
Index: scripts/interface/SBTarget.i
===================================================================
--- scripts/interface/SBTarget.i
+++ scripts/interface/SBTarget.i
@@ -976,33 +976,19 @@
     Returns an SBInstructionList.")
     ReadInstructions;
     lldb::SBInstructionList
-    ReadInstructions (lldb::SBAddress base_addr, uint32_t count);
-
-    lldb::SBInstructionList
-    ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string);
-
-    %feature("docstring", "
-    Disassemble the bytes in a buffer and return them in an SBInstructionList.
-    Parameters:
-       base_addr -- used for symbolicating the offsets in the byte stream when disassembling
-       buf       -- bytes to be disassembled
-       size      -- (C++) size of the buffer
-    Returns an SBInstructionList.")
-    GetInstructions;
-    lldb::SBInstructionList
-    GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
+    ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string = nullptr);
 
     %feature("docstring", "
     Disassemble the bytes in a buffer and return them in an SBInstructionList, with a supplied flavor.
     Parameters:
        base_addr -- used for symbolicating the offsets in the byte stream when disassembling
-       flavor    -- may be 'intel' or 'att' on x86 targets to specify that style of disassembly
        buf       -- bytes to be disassembled
        size      -- (C++) size of the buffer
-    Returns an SBInstructionList.")
-    GetInstructionsWithFlavor;
+       flavor    -- may be 'intel' or 'att' on x86 targets to specify that style of disassembly
+    Returns an SBInstructionList.") 
+    GetInstructions;
     lldb::SBInstructionList
-    GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size);
+    GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size, const char *flavor_string = nullptr);
 
     lldb::SBSymbolContextList
     FindSymbols (const char *name, lldb::SymbolType type = eSymbolTypeAny);
Index: scripts/Python/python-typemaps.swig
===================================================================
--- scripts/Python/python-typemaps.swig
+++ scripts/Python/python-typemaps.swig
@@ -139,30 +139,9 @@
 
 // typemap for an outgoing buffer
 // See also SBEvent::SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len).
-%typemap(in) (const char *cstr, uint32_t cstr_len) {
-   using namespace lldb_private;
-   if (PythonString::Check($input)) {
-      PythonString str(PyRefType::Borrowed, $input);
-      $1 = (char*)str.GetString().data();
-      $2 = str.GetSize();
-   }
-   else if(PythonByteArray::Check($input)) {
-      PythonByteArray bytearray(PyRefType::Borrowed, $input);
-      $1 = (char*)bytearray.GetBytes().data();
-      $2 = bytearray.GetSize();
-   }
-   else if (PythonBytes::Check($input)) {
-      PythonBytes bytes(PyRefType::Borrowed, $input);
-      $1 = (char*)bytes.GetBytes().data();
-      $2 = bytes.GetSize();
-   }
-   else {
-      PyErr_SetString(PyExc_ValueError, "Expecting a string");
-      return NULL;
-   }
-}
 // Ditto for SBProcess::PutSTDIN(const char *src, size_t src_len).
-%typemap(in) (const char *src, size_t src_len) {
+%typemap(in) (const char *cstr, uint32_t cstr_len),
+             (const char *src, size_t src_len) {
    using namespace lldb_private;
    if (PythonString::Check($input)) {
       PythonString str(PyRefType::Borrowed, $input);
@@ -184,8 +163,9 @@
       return NULL;
    }
 }
-// And SBProcess::WriteMemory.
-%typemap(in) (const void *buf, size_t size) {
+// For SBProcess::WriteMemory, SBTarget::GetInstructions and SBDebugger::DispatchInput.
+%typemap(in) (const void *buf, size_t size),
+             (const void *data, size_t data_len) {
    using namespace lldb_private;
    if (PythonString::Check($input)) {
       PythonString str(PyRefType::Borrowed, $input);
@@ -207,29 +187,10 @@
       return NULL;
    }
 }
-
-// For SBDebugger::DispatchInput
-%typemap(in) (const void *data, size_t data_len) {
-   using namespace lldb_private;
-   if (PythonString::Check($input)) {
-      PythonString str(PyRefType::Borrowed, $input);
-      $1 = (void*)str.GetString().data();
-      $2 = str.GetSize();
-   }
-   else if(PythonByteArray::Check($input)) {
-      PythonByteArray bytearray(PyRefType::Borrowed, $input);
-      $1 = (void*)bytearray.GetBytes().data();
-      $2 = bytearray.GetSize();
-   }
-   else if (PythonBytes::Check($input)) {
-      PythonBytes bytes(PyRefType::Borrowed, $input);
-      $1 = (void*)bytes.GetBytes().data();
-      $2 = bytes.GetSize();
-   }
-   else {
-      PyErr_SetString(PyExc_ValueError, "Expecting a buffer");
-      return NULL;
-   }
+// For SBTarget::GetInstructions.
+// Required when we have deal with overloaded functions.
+%typemap(typecheck) (const void *buf, size_t size) {
+    $1 = ($input == Py_None) ? 0 : 1;
 }
 
 // typemap for an incoming buffer
Index: include/lldb/API/SBTarget.h
===================================================================
--- include/lldb/API/SBTarget.h
+++ include/lldb/API/SBTarget.h
@@ -821,30 +821,16 @@
   SBSourceManager GetSourceManager();
 
   lldb::SBInstructionList ReadInstructions(lldb::SBAddress base_addr,
-                                           uint32_t count);
-
-  lldb::SBInstructionList ReadInstructions(lldb::SBAddress base_addr,
                                            uint32_t count,
-                                           const char *flavor_string);
+                                           const char *flavor_string = nullptr);
 
   lldb::SBInstructionList GetInstructions(lldb::SBAddress base_addr,
-                                          const void *buf, size_t size);
-
-  // The "WithFlavor" is necessary to keep SWIG from getting confused about
-  // overloaded arguments when using the buf + size -> Python Object magic.
-
-  lldb::SBInstructionList GetInstructionsWithFlavor(lldb::SBAddress base_addr,
-                                                    const char *flavor_string,
-                                                    const void *buf,
-                                                    size_t size);
+                                          const void *buf, size_t size,
+                                          const char *flavor_string = nullptr);
 
   lldb::SBInstructionList GetInstructions(lldb::addr_t base_addr,
-                                          const void *buf, size_t size);
-
-  lldb::SBInstructionList GetInstructionsWithFlavor(lldb::addr_t base_addr,
-                                                    const char *flavor_string,
-                                                    const void *buf,
-                                                    size_t size);
+                                          const void *buf, size_t size,
+                                          const char *flavor_string = nullptr);
 
   lldb::SBSymbolContextList FindSymbols(const char *name,
                                         lldb::SymbolType type = eSymbolTypeAny);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to