[Lldb-commits] [PATCH] D26757: Fix broken escaping of commands in the build

2016-11-29 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm added a subscriber: lldb-commits.
ldrumm updated this revision to Diff 79578.
ldrumm added a comment.

Addressed some unwanted whitespace changes as suggested by @bryant; use 
`os.dir.curdir` as instead of `.`


https://reviews.llvm.org/D26757

Files:
  CMakeLists.txt
  scripts/CMakeLists.txt
  scripts/Python/prepare_binding_Python.py

Index: scripts/Python/prepare_binding_Python.py
===
--- scripts/Python/prepare_binding_Python.py
+++ scripts/Python/prepare_binding_Python.py
@@ -196,34 +196,37 @@
 temp_dep_file_path = dependency_file + ".tmp"
 
 # Build the SWIG args list
-command = [
-options.swig_executable,
-"-c++",
-"-shadow",
-"-python",
-"-threads",
-"-I\"%s\"" % os.path.normcase(
-os.path.join(options.src_root, "include")),
-"-I\"%s\"" % os.path.normcase("./."),
-"-D__STDC_LIMIT_MACROS",
-"-D__STDC_CONSTANT_MACROS"]
-if options.target_platform == "Darwin":
-command.append("-D__APPLE__")
-if options.generate_dependency_file:
-command.append("-MMD -MF \"%s\"" % temp_dep_file_path)
-command.extend([
-"-outdir", "\"%s\"" % config_build_dir,
-"-o", "\"%s\"" % settings.output_file,
-"\"%s\"" % settings.input_file
-])
-logging.info("running swig with: %s", command)
+is_darwin = options.target_platform == "Darwin"
+gen_deps = options.generate_dependency_file
+darwin_extras = ["-D__APPLE__"] if is_darwin else []
+deps_args = ["-MMD", "-MF", temp_dep_file_path] if gen_deps else []
+command = ([
+options.swig_executable,
+"-c++",
+"-shadow",
+"-python",
+"-threads",
+"-I" + os.path.normpath(os.path.join(options.src_root, "include")),
+"-I" + os.path.curdir,
+"-D__STDC_LIMIT_MACROS",
+"-D__STDC_CONSTANT_MACROS"
+]
++ darwin_extras
++ deps_args
++ [
+"-outdir", config_build_dir,
+"-o", settings.output_file,
+settings.input_file
+]
+)
+logging.info("running swig with: %r", command)
 
 # Execute swig
 process = subprocess.Popen(
-' '.join(command),
+command,
 stdout=subprocess.PIPE,
 stderr=subprocess.PIPE,
-shell=True)
+)
 # Wait for SWIG process to terminate
 swig_stdout, swig_stderr = process.communicate()
 return_code = process.returncode
@@ -265,15 +268,14 @@
 the command line arguments to pass to it.
 """
 command = [sys.executable] + script_and_args
-command_line = " ".join(command)
-process = subprocess.Popen(command, shell=False)
+process = subprocess.Popen(command)
 script_stdout, script_stderr = process.communicate()
 return_code = process.returncode
 if return_code != 0:
-logging.error("failed to run '%s': %s", command_line, script_stderr)
+logging.error("failed to run %r: %r", command, script_stderr)
 sys.exit(return_code)
 else:
-logging.info("ran script '%s'", command_line)
+logging.info("ran script %r'", command)
 if script_stdout is not None:
 logging.info("output: %s", script_stdout)
 
Index: scripts/CMakeLists.txt
===
--- scripts/CMakeLists.txt
+++ scripts/CMakeLists.txt
@@ -35,12 +35,13 @@
   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Python/prepare_binding_Python.py
   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Python/modify-python-lldb.py
   COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/prepare_bindings.py
-  ${framework_arg}
-  "--srcRoot=${LLDB_SOURCE_DIR}"
-  "--targetDir=${LLDB_PYTHON_TARGET_DIR}"
-  "--cfgBldDir=${CMAKE_CURRENT_BINARY_DIR}"
-  "--prefix=${CMAKE_BINARY_DIR}"
-  "--swigExecutable=${SWIG_EXECUTABLE}"
+  ${framework_arg}
+  --srcRoot=${LLDB_SOURCE_DIR}
+  --targetDir=${LLDB_PYTHON_TARGET_DIR}
+  --cfgBldDir=${CMAKE_CURRENT_BINARY_DIR}
+  --prefix=${CMAKE_BINARY_DIR}
+  --swigExecutable=${SWIG_EXECUTABLE}
+  VERBATIM
   COMMENT "Python script building LLDB Python wrapper")
 set_source_files_properties(${LLDB_WRAP_PYTHON} PROPERTIES GENERATED 1)
 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lldb.py PROPERTIES GENERATED 1)
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -39,15 +39,19 @@
 add_subdirectory(lit)
 
 if (NOT LLDB_DISABLE_PYTHON)
-# Add a Post-Build Event to copy over Python files and create the symlink to liblldb.so for the Python API(hardlink on Windows)
-add_custom_target( finish_swig ALL
-COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py
-"--srcRoot=${LLDB_SOURCE_DIR}"
-"

[Lldb-commits] [PATCH] D27223: Expression evaluation for overloaded C functions (redux)

2016-11-29 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm created this revision.
ldrumm added reviewers: spyffe, clayborg.
ldrumm added a subscriber: LLDB.
Herald added a subscriber: aemerson.

This is a redux of Ewan's patch  , refactored 
to properly substitute primitive  types using a hook in the itanium demangler, 
and updated after the previous patch went stale

The new `SubsPrimitiveParmItanium` function takes a symbol name and replacement 
primitive type parameter as before but parses it using the FastDemangler, which 
has been modified to be able to notify clients of parse events (primitive types 
at this point).

Additionally, we now use a `set` of `ConstStrings` instead of a `vector` so 
that we try and resolve the same invalid candidate multiple times.

I'd particularly welcome feedback on whether there is a better way of doing the 
hook from the demangler. In the present implementation, the time tradeoff is a 
single `nullptr` check in the hot path, which was the least invasive change of 
a few I prototyped.


https://reviews.llvm.org/D27223

Files:
  include/lldb/Core/FastDemangle.h
  
packages/Python/lldbsuite/test/expression_command/call-overloaded-c-fuction/Makefile
  
packages/Python/lldbsuite/test/expression_command/call-overloaded-c-fuction/TestCallOverloadedCFunction.py
  
packages/Python/lldbsuite/test/expression_command/call-overloaded-c-fuction/main.c
  source/Core/FastDemangle.cpp
  source/Expression/IRExecutionUnit.cpp
  source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h

Index: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
===
--- source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
+++ source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
@@ -12,6 +12,7 @@
 
 // C Includes
 // C++ Includes
+#include 
 #include 
 
 // Other libraries and framework includes
@@ -93,7 +94,6 @@
   }
 
   std::unique_ptr GetTypeScavenger() override;
-  
   lldb::TypeCategoryImplSP GetFormatters() override;
 
   HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override;
@@ -142,6 +142,12 @@
   static uint32_t FindEquivalentNames(ConstString type_name,
   std::vector &equivalents);
 
+  // Given a mangled function name, calculates some alternative manglings since
+  // the compiler mangling may not line up with the symbol we are expecting
+  static uint32_t
+  FindAlternateFunctionManglings(const ConstString mangled,
+ std::set &candidates);
+
   //--
   // PluginInterface protocol
   //--
Index: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -10,17 +10,22 @@
 #include "CPlusPlusLanguage.h"
 
 // C Includes
-// C++ Includes
 #include 
 #include 
+
+// C++ Includes
 #include 
+#include 
 #include 
+#include 
 
 // Other libraries and framework includes
 #include "llvm/ADT/StringRef.h"
 
 // Project includes
 #include "lldb/Core/ConstString.h"
+#include "lldb/Core/FastDemangle.h"
+#include "lldb/Core/Log.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/RegularExpression.h"
 #include "lldb/Core/UniqueCStringMap.h"
@@ -440,6 +445,112 @@
   return count;
 }
 
+/// Given a mangled function `mangled`, replace all the primitive function type
+/// arguments of `mangled` with type `replace`.
+static ConstString SubsPrimitiveParmItanium(const char *mangled,
+const char *search,
+const char *replace) {
+  Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE);
+  assert(mangled && search && replace);
+
+  const size_t search_len = ::strlen(search);
+  const size_t replace_len = ::strlen(replace);
+  const size_t mangled_len = ::strlen(mangled);
+  const size_t max_len =
+  mangled_len + llvm::StringRef(mangled).count(search) * replace_len + 1;
+
+  // Make a temporary buffer to fix up the mangled parameter types
+  // and copy the original there
+  std::unique_ptr output_buf(new char[max_len]);
+  ::memset(output_buf.get(), '\0', max_len);
+  ::strncpy(output_buf.get(), mangled, max_len - 1);
+
+  size_t avail_sz = max_len - 1;
+  ptrdiff_t replaced_offset = 0;
+
+  auto swap_parms_hook = [&](const char *s) {
+if (!s || !*s)
+  return;
+
+// Check whether we've found a substitutee
+if (::strncmp(s, search, search_len) == 0) {
+  // account for the case where a replacement is of a different length
+  // to the original
+  replaced_offset += replace_len - search_len;
+
+  ptrdiff_t replace_idx 

[Lldb-commits] [PATCH] D17957: Expression evaluation for overloaded C functions

2016-11-29 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm added a comment.

New candidate is here 


Repository:
  rL LLVM

https://reviews.llvm.org/D17957



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D26757: Fix broken escaping of commands in the build

2016-12-15 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm marked 2 inline comments as done.
ldrumm added a comment.

ping


https://reviews.llvm.org/D26757



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D27223: Expression evaluation for overloaded C functions (redux)

2016-12-16 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm added inline comments.



Comment at: include/lldb/Core/FastDemangle.h:22
+char *
+FastDemangle(const char *mangled_name, size_t mangled_name_length,
+ std::function primitive_type_hook = nullptr);

alexshap wrote:
> some thoughts: 
> (also i assume i might be mistaken / missing smth) 
> in ./source/Core/Mangled.cpp at least 3 demanglers are used:
> FastDemangle, itaniumDemangle, abi::__cxa_demangle .
> Adding primitive_type_hook to FastDemangle makes  the interface 
> more complicated & inconsistent (although yes, it's not particularly 
> consistent right now). 
You're right there are a bunch of manglers in use, and this is suboptimal. 
There is recent traction in LLVM to switch to using LLDB's FastDemangler once 
it supports everything; in terms of making the interface messy - you're again 
spot-on. None of the 4-or-so manglers visible to lldb have a symmetric API to 
support things like demangle -> remangle, so this is the least intrusive way I 
could come up with that didn't involve adding a new demangler to the list. I 
did think of several other possible approaches, including using the llvm 
demangler (which has no real public API apart from `llvm::itaniumDemangle` 
where the internal datastructure  (`struct Db`) is not exposed, and modifying 
the llvm demangler to fix a problem in LLDB is going to be a much harder sell.



Comment at: 
packages/Python/lldbsuite/test/expression_command/call-overloaded-c-fuction/main.c:17
+return 0; // break here
+}

alexshap wrote:
> does this patch work when the functions come from a shared library ? 
> (i mean if we have libFoo.so which contains the implementations of 
> get_arg_type(float), get_arg_type(int), and then in lldb we want to call "p 
> get_arg_type(0.12f)")
Yes. The only thing that matters to the current implementation is that we know 
the mangled symbol name.



Comment at: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:449
+/// Given a mangled function `mangled`, replace all the primitive function type
+/// arguments of `mangled` with type `replace`.
+static ConstString SubsPrimitiveParmItanium(const char *mangled,

clayborg wrote:
> Don't you mean `search` instead of `mangled` above?
I did. That was a silly mistake.



Comment at: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:465-466
+  std::unique_ptr output_buf(new char[max_len]);
+  ::memset(output_buf.get(), '\0', max_len);
+  ::strncpy(output_buf.get(), mangled, max_len - 1);
+

clayborg wrote:
> Remove both lines above if you use a std::string. Also, why zero it first and 
> then copy the string over it?
The reason I set it to zero first was that I didn't know how many replacements 
would be made or how many times `swap_parms_hook` would be called, so this case 
guarantees it's always NUL-terminated. I've switched to std::string as you 
suggested, which conveniently sidesteps the issue :)



Comment at: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:471
+
+  auto swap_parms_hook = [&](const char *s) {
+if (!s || !*s)

clayborg wrote:
> Does this only get called with parameters? Or does it get called for 
> everything?
I'm not sure I follow; `s` should always be a valid pointer if that's what you 
mean?



Comment at: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:476
+// Check whether we've found a substitutee
+if (::strncmp(s, search, search_len) == 0) {
+  // account for the case where a replacement is of a different length

clayborg wrote:
> Use starts_with StringRef function.
> 
> You also need to verify that there is a word boundary at the end of this. If 
> you are searching for "F", and replacing it with "E" and you get "Foo, Bar) 
> const" in `s` then this will match you will change it to "Eoo, Bar) const" 
> right? So you need to check `s[search.size]` and make sure it is a non 
> identifier character. Unless this function only gets called with identifier 
> boundaries. From my quick look at the FastDemangle changes, it seems that 
> this will get called with the entire remaining part of the string.
This function only gets called when the demangler is trying to resolve a 
builtin type, so it only get called in a context where it's encoding a type, 
not an identifier. I could be wrong, but as far as I can tell, from reading the 
spec for itanium demangling 
(https://mentorembedded.github.io/cxx-abi/abi.html#mangle.builtin-type), and 
the code for the FastDemangler, this should be safe in the case you mentioned.


https://reviews.llvm.org/D27223



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D27223: Expression evaluation for overloaded C functions (redux)

2016-12-16 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm updated this revision to Diff 81753.
ldrumm marked 6 inline comments as done.
ldrumm added a comment.

updated to use StringRef-based parser rather than char pointers


https://reviews.llvm.org/D27223

Files:
  include/lldb/Core/FastDemangle.h
  
packages/Python/lldbsuite/test/expression_command/call-overloaded-c-fuction/Makefile
  
packages/Python/lldbsuite/test/expression_command/call-overloaded-c-fuction/TestCallOverloadedCFunction.py
  
packages/Python/lldbsuite/test/expression_command/call-overloaded-c-fuction/main.c
  source/Core/FastDemangle.cpp
  source/Expression/IRExecutionUnit.cpp
  source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h

Index: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
===
--- source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
+++ source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
@@ -12,6 +12,7 @@
 
 // C Includes
 // C++ Includes
+#include 
 #include 
 
 // Other libraries and framework includes
@@ -93,7 +94,6 @@
   }
 
   std::unique_ptr GetTypeScavenger() override;
-  
   lldb::TypeCategoryImplSP GetFormatters() override;
 
   HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override;
@@ -142,6 +142,12 @@
   static uint32_t FindEquivalentNames(ConstString type_name,
   std::vector &equivalents);
 
+  // Given a mangled function name, calculates some alternative manglings since
+  // the compiler mangling may not line up with the symbol we are expecting
+  static uint32_t
+  FindAlternateFunctionManglings(const ConstString mangled,
+ std::set &candidates);
+
   //--
   // PluginInterface protocol
   //--
Index: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -10,17 +10,22 @@
 #include "CPlusPlusLanguage.h"
 
 // C Includes
-// C++ Includes
 #include 
 #include 
+
+// C++ Includes
 #include 
+#include 
 #include 
+#include 
 
 // Other libraries and framework includes
 #include "llvm/ADT/StringRef.h"
 
 // Project includes
 #include "lldb/Core/ConstString.h"
+#include "lldb/Core/FastDemangle.h"
+#include "lldb/Core/Log.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/RegularExpression.h"
 #include "lldb/Core/UniqueCStringMap.h"
@@ -440,6 +445,101 @@
   return count;
 }
 
+/// Given a mangled function `mangled`, replace all the primitive function type
+/// arguments of `search` with type `replace`.
+static ConstString SubsPrimitiveParmItanium(llvm::StringRef mangled,
+llvm::StringRef search,
+llvm::StringRef replace) {
+  Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE);
+
+  const size_t max_len =
+  mangled.size() + mangled.count(search) * replace.size() + 1;
+
+  // Make a temporary buffer to fix up the mangled parameter types and copy the
+  // original there
+  std::string output_buf;
+  output_buf.reserve(max_len);
+  output_buf.insert(0, mangled.str());
+  ptrdiff_t replaced_offset = 0;
+
+  auto swap_parms_hook = [&](const char *parsee) {
+if (!parsee || !*parsee)
+  return;
+
+// Check whether we've found a substitutee
+llvm::StringRef s(parsee);
+if (s.startswith(search)) {
+  // account for the case where a replacement is of a different length to
+  // the original
+  replaced_offset += replace.size() - search.size();
+
+  ptrdiff_t replace_idx = (mangled.size() - s.size()) + replaced_offset;
+  output_buf.erase(replace_idx, search.size());
+  output_buf.insert(replace_idx, replace.str());
+}
+  };
+
+  // FastDemangle will call our hook for each instance of a primitive type,
+  // allowing us to perform substitution
+  const char *const demangled =
+  FastDemangle(mangled.str().c_str(), mangled.size(), swap_parms_hook);
+
+  if (log)
+log->Printf("substituted mangling for %s:{%s} %s:{%s}\n",
+mangled.str().c_str(), demangled, output_buf.c_str(),
+FastDemangle(output_buf.c_str()));
+
+  return output_buf == mangled ? ConstString() : ConstString(output_buf);
+}
+
+uint32_t CPlusPlusLanguage::FindAlternateFunctionManglings(
+const ConstString mangled_name, std::set &alternates) {
+  const auto start_size = alternates.size();
+  /// Get a basic set of alternative manglings for the given symbol `name`, by
+  /// making a few basic possible substitutions on basic types, storage duration
+  /// and `const`ness for the given symbol. The output parameter `al

[Lldb-commits] [PATCH] D26757: Fix broken escaping of commands in the build

2016-12-16 Thread Luke Drummond via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289956: Fix broken escaping of commands in the build 
(authored by ldrumm).

Changed prior to commit:
  https://reviews.llvm.org/D26757?vs=79578&id=81761#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26757

Files:
  lldb/trunk/CMakeLists.txt
  lldb/trunk/scripts/CMakeLists.txt
  lldb/trunk/scripts/Python/prepare_binding_Python.py

Index: lldb/trunk/scripts/Python/prepare_binding_Python.py
===
--- lldb/trunk/scripts/Python/prepare_binding_Python.py
+++ lldb/trunk/scripts/Python/prepare_binding_Python.py
@@ -196,34 +196,37 @@
 temp_dep_file_path = dependency_file + ".tmp"
 
 # Build the SWIG args list
-command = [
-options.swig_executable,
-"-c++",
-"-shadow",
-"-python",
-"-threads",
-"-I\"%s\"" % os.path.normcase(
-os.path.join(options.src_root, "include")),
-"-I\"%s\"" % os.path.normcase("./."),
-"-D__STDC_LIMIT_MACROS",
-"-D__STDC_CONSTANT_MACROS"]
-if options.target_platform == "Darwin":
-command.append("-D__APPLE__")
-if options.generate_dependency_file:
-command.append("-MMD -MF \"%s\"" % temp_dep_file_path)
-command.extend([
-"-outdir", "\"%s\"" % config_build_dir,
-"-o", "\"%s\"" % settings.output_file,
-"\"%s\"" % settings.input_file
-])
-logging.info("running swig with: %s", command)
+is_darwin = options.target_platform == "Darwin"
+gen_deps = options.generate_dependency_file
+darwin_extras = ["-D__APPLE__"] if is_darwin else []
+deps_args = ["-MMD", "-MF", temp_dep_file_path] if gen_deps else []
+command = ([
+options.swig_executable,
+"-c++",
+"-shadow",
+"-python",
+"-threads",
+"-I" + os.path.normpath(os.path.join(options.src_root, "include")),
+"-I" + os.path.curdir,
+"-D__STDC_LIMIT_MACROS",
+"-D__STDC_CONSTANT_MACROS"
+]
++ darwin_extras
++ deps_args
++ [
+"-outdir", config_build_dir,
+"-o", settings.output_file,
+settings.input_file
+]
+)
+logging.info("running swig with: %r", command)
 
 # Execute swig
 process = subprocess.Popen(
-' '.join(command),
+command,
 stdout=subprocess.PIPE,
 stderr=subprocess.PIPE,
-shell=True)
+)
 # Wait for SWIG process to terminate
 swig_stdout, swig_stderr = process.communicate()
 return_code = process.returncode
@@ -265,15 +268,14 @@
 the command line arguments to pass to it.
 """
 command = [sys.executable] + script_and_args
-command_line = " ".join(command)
-process = subprocess.Popen(command, shell=False)
+process = subprocess.Popen(command)
 script_stdout, script_stderr = process.communicate()
 return_code = process.returncode
 if return_code != 0:
-logging.error("failed to run '%s': %s", command_line, script_stderr)
+logging.error("failed to run %r: %r", command, script_stderr)
 sys.exit(return_code)
 else:
-logging.info("ran script '%s'", command_line)
+logging.info("ran script %r'", command)
 if script_stdout is not None:
 logging.info("output: %s", script_stdout)
 
Index: lldb/trunk/scripts/CMakeLists.txt
===
--- lldb/trunk/scripts/CMakeLists.txt
+++ lldb/trunk/scripts/CMakeLists.txt
@@ -35,12 +35,13 @@
   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Python/prepare_binding_Python.py
   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Python/modify-python-lldb.py
   COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/prepare_bindings.py
-  ${framework_arg}
-  "--srcRoot=${LLDB_SOURCE_DIR}"
-  "--targetDir=${LLDB_PYTHON_TARGET_DIR}"
-  "--cfgBldDir=${CMAKE_CURRENT_BINARY_DIR}"
-  "--prefix=${CMAKE_BINARY_DIR}"
-  "--swigExecutable=${SWIG_EXECUTABLE}"
+  ${framework_arg}
+  --srcRoot=${LLDB_SOURCE_DIR}
+  --targetDir=${LLDB_PYTHON_TARGET_DIR}
+  --cfgBldDir=${CMAKE_CURRENT_BINARY_DIR}
+  --prefix=${CMAKE_BINARY_DIR}
+  --swigExecutable=${SWIG_EXECUTABLE}
+  VERBATIM
   COMMENT "Python script building LLDB Python wrapper")
 set_source_files_properties(${LLDB_WRAP_PYTHON} PROPERTIES GENERATED 1)
 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lldb.py PROPERTIES GENERATED 1)
Index: lldb/trunk/CMakeLists.txt
===
--- lldb/trunk/CMakeLists.txt
+++ lldb/trunk/CMakeLists.txt
@@ -39,15 +39,19 @@
 add_subdirectory(lit)
 
 if (NOT LLDB_DISABLE_PYTHON)
-# Add a Post-Build Event to copy over Python files and create the symlink to liblldb.so for the Python API(hardlink on Windows)
-   

[Lldb-commits] [PATCH] D27223: Expression evaluation for overloaded C functions (redux)

2016-12-19 Thread Luke Drummond via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290117: Expression evaluation for overloaded C functions 
(redux) (authored by ldrumm).

Changed prior to commit:
  https://reviews.llvm.org/D27223?vs=81753&id=81967#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27223

Files:
  lldb/trunk/include/lldb/Core/FastDemangle.h
  lldb/trunk/source/Core/FastDemangle.cpp
  lldb/trunk/source/Expression/IRExecutionUnit.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h

Index: lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
===
--- lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
@@ -12,6 +12,7 @@
 
 // C Includes
 // C++ Includes
+#include 
 #include 
 
 // Other libraries and framework includes
@@ -93,7 +94,6 @@
   }
 
   std::unique_ptr GetTypeScavenger() override;
-  
   lldb::TypeCategoryImplSP GetFormatters() override;
 
   HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override;
@@ -142,6 +142,12 @@
   static uint32_t FindEquivalentNames(ConstString type_name,
   std::vector &equivalents);
 
+  // Given a mangled function name, calculates some alternative manglings since
+  // the compiler mangling may not line up with the symbol we are expecting
+  static uint32_t
+  FindAlternateFunctionManglings(const ConstString mangled,
+ std::set &candidates);
+
   //--
   // PluginInterface protocol
   //--
Index: lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -10,17 +10,22 @@
 #include "CPlusPlusLanguage.h"
 
 // C Includes
-// C++ Includes
 #include 
 #include 
+
+// C++ Includes
 #include 
+#include 
 #include 
+#include 
 
 // Other libraries and framework includes
 #include "llvm/ADT/StringRef.h"
 
 // Project includes
 #include "lldb/Core/ConstString.h"
+#include "lldb/Core/FastDemangle.h"
+#include "lldb/Core/Log.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/RegularExpression.h"
 #include "lldb/Core/UniqueCStringMap.h"
@@ -440,6 +445,101 @@
   return count;
 }
 
+/// Given a mangled function `mangled`, replace all the primitive function type
+/// arguments of `search` with type `replace`.
+static ConstString SubsPrimitiveParmItanium(llvm::StringRef mangled,
+llvm::StringRef search,
+llvm::StringRef replace) {
+  Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE);
+
+  const size_t max_len =
+  mangled.size() + mangled.count(search) * replace.size() + 1;
+
+  // Make a temporary buffer to fix up the mangled parameter types and copy the
+  // original there
+  std::string output_buf;
+  output_buf.reserve(max_len);
+  output_buf.insert(0, mangled.str());
+  ptrdiff_t replaced_offset = 0;
+
+  auto swap_parms_hook = [&](const char *parsee) {
+if (!parsee || !*parsee)
+  return;
+
+// Check whether we've found a substitutee
+llvm::StringRef s(parsee);
+if (s.startswith(search)) {
+  // account for the case where a replacement is of a different length to
+  // the original
+  replaced_offset += replace.size() - search.size();
+
+  ptrdiff_t replace_idx = (mangled.size() - s.size()) + replaced_offset;
+  output_buf.erase(replace_idx, search.size());
+  output_buf.insert(replace_idx, replace.str());
+}
+  };
+
+  // FastDemangle will call our hook for each instance of a primitive type,
+  // allowing us to perform substitution
+  const char *const demangled =
+  FastDemangle(mangled.str().c_str(), mangled.size(), swap_parms_hook);
+
+  if (log)
+log->Printf("substituted mangling for %s:{%s} %s:{%s}\n",
+mangled.str().c_str(), demangled, output_buf.c_str(),
+FastDemangle(output_buf.c_str()));
+
+  return output_buf == mangled ? ConstString() : ConstString(output_buf);
+}
+
+uint32_t CPlusPlusLanguage::FindAlternateFunctionManglings(
+const ConstString mangled_name, std::set &alternates) {
+  const auto start_size = alternates.size();
+  /// Get a basic set of alternative manglings for the given symbol `name`, by
+  /// making a few basic possible substitutions on basic types, storage duration
+  /// and `const`ness for the given symbol. The output parameter `alternates`
+  /// is filled with a best-gu

[Lldb-commits] [PATCH] D17719: Track expression language from one place in ClangExpressionParser

2016-12-21 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm reopened this revision.
ldrumm added a comment.

This patch was committed back in March https://reviews.llvm.org/rL263099 and 
then reverted 2 hours later in https://reviews.llvm.org/rL263107 due to a  
testing failure on greendragon related to ObjC. Unfortunately, I no longer have 
access to Apple hardware (and at the time the testsuite passed on my local 
mac), so I'm unable to find out exactly what went wrong.

This patch is still needed for RenderScript to handle JIT expressions 
correctly, so I'd really appreciate it if someone more familiar with OS X would 
be able to take a look at this, and point out what I'm doing wrong that causes 
the Objective C tests to blow up.

Any help is - as always - very-much appreciated!


Repository:
  rL LLVM

https://reviews.llvm.org/D17719



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D17719: Track expression language from one place in ClangExpressionParser

2016-12-21 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm added a subscriber: LLDB.
ldrumm removed rL LLVM as the repository for this revision.
ldrumm updated this revision to Diff 82251.
ldrumm added a comment.

This patch was committed back in March https://reviews.llvm.org/rL263099 and 
then reverted 2 hours later in https://reviews.llvm.org/rL263107 due to a  
testing failure on greendragon related to ObjC. Unfortunately, I no longer have 
access to Apple hardware (and at the time the testsuite passed on my local 
mac), so I'm unable to find out exactly what went wrong.

This patch is still needed for RenderScript to handle JIT expressions 
correctly, so I'd really appreciate it if someone more familiar with OS X would 
be able to take a look at this, and point out what I'm doing wrong that causes 
the Objective C tests to blow up.

Any help is - as always - very-much appreciated!


https://reviews.llvm.org/D17719

Files:
  source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h


Index: source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
===
--- source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
@@ -158,8 +158,10 @@
 
   class LLDBPreprocessorCallbacks;
   LLDBPreprocessorCallbacks *m_pp_callbacks; ///< Called when the preprocessor
- ///encounters module imports
+ /// encounters module imports
   std::unique_ptr m_ast_context;
+  lldb::LanguageType m_language; ///< The source language of the expression
+ /// which may be explicitly set or inferred.
 };
 }
 
Index: source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===
--- source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -253,8 +253,7 @@
 
   // 1. Create a new compiler instance.
   m_compiler.reset(new CompilerInstance());
-  lldb::LanguageType frame_lang =
-  expr.Language(); // defaults to lldb::eLanguageTypeUnknown
+  m_language = expr.Language(); // defaults to lldb::eLanguageTypeUnknown
   bool overridden_target_opts = false;
   lldb_private::LanguageRuntime *lang_rt = nullptr;
 
@@ -272,14 +271,14 @@
 
   // Make sure the user hasn't provided a preferred execution language
   // with `expression --language X -- ...`
-  if (frame_sp && frame_lang == lldb::eLanguageTypeUnknown)
-frame_lang = frame_sp->GetLanguage();
+  if (frame_sp && m_language == lldb::eLanguageTypeUnknown)
+m_language = frame_sp->GetLanguage();
 
-  if (process_sp && frame_lang != lldb::eLanguageTypeUnknown) {
-lang_rt = process_sp->GetLanguageRuntime(frame_lang);
+  if (process_sp && m_language != lldb::eLanguageTypeUnknown) {
+lang_rt = process_sp->GetLanguageRuntime(m_language);
 if (log)
   log->Printf("Frame has language of type %s",
-  Language::GetNameForLanguageType(frame_lang));
+  Language::GetNameForLanguageType(m_language));
   }
 
   // 2. Configure the compiler with a set of default options that are
@@ -372,9 +371,7 @@
   assert(m_compiler->hasTarget());
 
   // 5. Set language options.
-  lldb::LanguageType language = expr.Language();
-
-  switch (language) {
+  switch (m_language) {
   case lldb::eLanguageTypeC:
   case lldb::eLanguageTypeC89:
   case lldb::eLanguageTypeC99:
@@ -804,13 +801,12 @@
 
   LLVMUserExpression::IRPasses custom_passes;
   {
-auto lang = m_expr.Language();
 if (log)
   log->Printf("%s - Currrent expression language is %s\n", __FUNCTION__,
-  Language::GetNameForLanguageType(lang));
+  Language::GetNameForLanguageType(m_language));
 lldb::ProcessSP process_sp = exe_ctx.GetProcessSP();
-if (process_sp && lang != lldb::eLanguageTypeUnknown) {
-  auto runtime = process_sp->GetLanguageRuntime(lang);
+if (process_sp && m_language != lldb::eLanguageTypeUnknown) {
+  auto runtime = process_sp->GetLanguageRuntime(m_language);
   if (runtime)
 runtime->GetIRPasses(custom_passes);
 }


Index: source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
===
--- source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
@@ -158,8 +158,10 @@
 
   class LLDBPreprocessorCallbacks;
   LLDBPreprocessorCallbacks *m_pp_callbacks; ///< Called when the preprocessor
- ///encounters module imports
+ /// encounters module imports
   std::unique_ptr m_ast_context;
+  lldb::LanguageType m_language; ///< The source language of the expression
+ 

[Lldb-commits] [PATCH] D28028: Fix a couple of incorrect format strings

2016-12-21 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm created this revision.
ldrumm added reviewers: zturner, clayborg.
ldrumm added a subscriber: LLDB.

This patch fixes use of incorrect `%zi` to format a plain `int`, and switches 
from using "%llu" to format a uint64_t to using the exact width specifier 
PRIu64 from inttypes.h


https://reviews.llvm.org/D28028

Files:
  source/Interpreter/Args.cpp
  source/Plugins/ExpressionParser/Clang/IRForTarget.cpp


Index: source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
===
--- source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
+++ source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
@@ -38,6 +38,7 @@
 #include "lldb/Symbol/ClangUtil.h"
 #include "lldb/Symbol/CompilerType.h"
 
+#include 
 #include 
 
 using namespace llvm;
@@ -514,7 +515,7 @@
encoding_flags = 0x0600; /* fall back to 0x0600, kCFStringEncodingASCII */
if (log) {
  log->Printf("Encountered an Objective-C constant string with unusual "
- "element size %llu",
+ "element size %" PRIu64,
  string_array->getElementByteSize());
}
  }
Index: source/Interpreter/Args.cpp
===
--- source/Interpreter/Args.cpp
+++ source/Interpreter/Args.cpp
@@ -213,10 +213,10 @@
   int i = 0;
   for (auto &entry : m_entries) {
 s.Indent();
-s.Printf("%s[%zi]=\"%*s\"\n", label_name, i++, int(entry.ref.size()),
+s.Printf("%s[%d]=\"%*s\"\n", label_name, i++, int(entry.ref.size()),
  entry.ref.data());
   }
-  s.Printf("%s[%zi]=NULL\n", label_name, i);
+  s.Printf("%s[%d]=NULL\n", label_name, i);
   s.EOL();
 }
 


Index: source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
===
--- source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
+++ source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
@@ -38,6 +38,7 @@
 #include "lldb/Symbol/ClangUtil.h"
 #include "lldb/Symbol/CompilerType.h"
 
+#include 
 #include 
 
 using namespace llvm;
@@ -514,7 +515,7 @@
encoding_flags = 0x0600; /* fall back to 0x0600, kCFStringEncodingASCII */
if (log) {
  log->Printf("Encountered an Objective-C constant string with unusual "
- "element size %llu",
+ "element size %" PRIu64,
  string_array->getElementByteSize());
}
  }
Index: source/Interpreter/Args.cpp
===
--- source/Interpreter/Args.cpp
+++ source/Interpreter/Args.cpp
@@ -213,10 +213,10 @@
   int i = 0;
   for (auto &entry : m_entries) {
 s.Indent();
-s.Printf("%s[%zi]=\"%*s\"\n", label_name, i++, int(entry.ref.size()),
+s.Printf("%s[%d]=\"%*s\"\n", label_name, i++, int(entry.ref.size()),
  entry.ref.data());
   }
-  s.Printf("%s[%zi]=NULL\n", label_name, i);
+  s.Printf("%s[%d]=NULL\n", label_name, i);
   s.EOL();
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D28028: Fix a couple of incorrect format strings

2016-12-22 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm updated this revision to Diff 82334.
ldrumm added a comment.

switched to the new llvm::Format API


https://reviews.llvm.org/D28028

Files:
  source/Interpreter/Args.cpp
  source/Plugins/ExpressionParser/Clang/IRForTarget.cpp


Index: source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
===
--- source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
+++ source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
@@ -513,8 +513,8 @@
  default:
encoding_flags = 0x0600; /* fall back to 0x0600, kCFStringEncodingASCII */
if (log) {
- log->Printf("Encountered an Objective-C constant string with unusual "
- "element size %llu",
+ log->Format("Encountered an Objective-C constant string with unusual "
+ "element size {0}",
  string_array->getElementByteSize());
}
  }
Index: source/Interpreter/Args.cpp
===
--- source/Interpreter/Args.cpp
+++ source/Interpreter/Args.cpp
@@ -213,10 +213,9 @@
   int i = 0;
   for (auto &entry : m_entries) {
 s.Indent();
-s.Printf("%s[%zi]=\"%*s\"\n", label_name, i++, int(entry.ref.size()),
- entry.ref.data());
+s.Format("{0}[{1}]=\"{2}\"\n", label_name, i++, entry.ref);
   }
-  s.Printf("%s[%zi]=NULL\n", label_name, i);
+  s.Format("{0}[{1}]=NULL\n", label_name, i);
   s.EOL();
 }
 


Index: source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
===
--- source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
+++ source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
@@ -513,8 +513,8 @@
  default:
encoding_flags = 0x0600; /* fall back to 0x0600, kCFStringEncodingASCII */
if (log) {
- log->Printf("Encountered an Objective-C constant string with unusual "
- "element size %llu",
+ log->Format("Encountered an Objective-C constant string with unusual "
+ "element size {0}",
  string_array->getElementByteSize());
}
  }
Index: source/Interpreter/Args.cpp
===
--- source/Interpreter/Args.cpp
+++ source/Interpreter/Args.cpp
@@ -213,10 +213,9 @@
   int i = 0;
   for (auto &entry : m_entries) {
 s.Indent();
-s.Printf("%s[%zi]=\"%*s\"\n", label_name, i++, int(entry.ref.size()),
- entry.ref.data());
+s.Format("{0}[{1}]=\"{2}\"\n", label_name, i++, entry.ref);
   }
-  s.Printf("%s[%zi]=NULL\n", label_name, i);
+  s.Format("{0}[{1}]=NULL\n", label_name, i);
   s.EOL();
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D28028: Fix a couple of incorrect format strings

2016-12-22 Thread Luke Drummond via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290359: Fix a couple of incorrect format string warnings 
(authored by ldrumm).

Changed prior to commit:
  https://reviews.llvm.org/D28028?vs=82334&id=82354#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28028

Files:
  lldb/trunk/source/Interpreter/Args.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp


Index: lldb/trunk/source/Interpreter/Args.cpp
===
--- lldb/trunk/source/Interpreter/Args.cpp
+++ lldb/trunk/source/Interpreter/Args.cpp
@@ -213,10 +213,9 @@
   int i = 0;
   for (auto &entry : m_entries) {
 s.Indent();
-s.Printf("%s[%zi]=\"%*s\"\n", label_name, i++, int(entry.ref.size()),
- entry.ref.data());
+s.Format("{0}[{1}]=\"{2}\"\n", label_name, i++, entry.ref);
   }
-  s.Printf("%s[%zi]=NULL\n", label_name, i);
+  s.Format("{0}[{1}]=NULL\n", label_name, i);
   s.EOL();
 }
 
Index: lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
===
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
@@ -513,8 +513,8 @@
  default:
encoding_flags = 0x0600; /* fall back to 0x0600, kCFStringEncodingASCII */
if (log) {
- log->Printf("Encountered an Objective-C constant string with unusual "
- "element size %llu",
+ log->Format("Encountered an Objective-C constant string with unusual "
+ "element size {0}",
  string_array->getElementByteSize());
}
  }


Index: lldb/trunk/source/Interpreter/Args.cpp
===
--- lldb/trunk/source/Interpreter/Args.cpp
+++ lldb/trunk/source/Interpreter/Args.cpp
@@ -213,10 +213,9 @@
   int i = 0;
   for (auto &entry : m_entries) {
 s.Indent();
-s.Printf("%s[%zi]=\"%*s\"\n", label_name, i++, int(entry.ref.size()),
- entry.ref.data());
+s.Format("{0}[{1}]=\"{2}\"\n", label_name, i++, entry.ref);
   }
-  s.Printf("%s[%zi]=NULL\n", label_name, i);
+  s.Format("{0}[{1}]=NULL\n", label_name, i);
   s.EOL();
 }
 
Index: lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
===
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
@@ -513,8 +513,8 @@
  default:
encoding_flags = 0x0600; /* fall back to 0x0600, kCFStringEncodingASCII */
if (log) {
- log->Printf("Encountered an Objective-C constant string with unusual "
- "element size %llu",
+ log->Format("Encountered an Objective-C constant string with unusual "
+ "element size {0}",
  string_array->getElementByteSize());
}
  }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D75925: [lldb] reject `.debug_arange` sections with nonzero segment size

2020-03-10 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm created this revision.
ldrumm added reviewers: clayborg, jasonmolenda.
ldrumm added a project: LLDB.

  If a producer emits a nonzero segment size, `lldb` will silently read
  incorrect values and crash, or do something worse later, as the tuple
  size is expected to be 2, rather than 3.
  
  Neither LLVM, nor GCC produce segmented aranges, but this dangerous case
  should still be checked and handled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75925

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
@@ -63,7 +63,8 @@
   // 1 - the version looks good
   // 2 - the address byte size looks plausible
   // 3 - the length seems to make sense
-  // size looks plausible
+  // 4 - size looks plausible
+  // 5 - the arange tuples do not contain a segment field
   if (m_header.version < 2 || m_header.version > 5)
 return llvm::make_error(
 "Invalid arange header version");
@@ -81,6 +82,10 @@
 return llvm::make_error(
 "Invalid arange header length");
 
+  if (m_header.seg_size)
+return llvm::make_error(
+"segmented arange entries are not supported");
+
   // The first tuple following the header in each set begins at an offset
   // that is a multiple of the size of a single tuple (that is, twice the
   // size of an address). The header is padded, if necessary, to the


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
@@ -63,7 +63,8 @@
   // 1 - the version looks good
   // 2 - the address byte size looks plausible
   // 3 - the length seems to make sense
-  // size looks plausible
+  // 4 - size looks plausible
+  // 5 - the arange tuples do not contain a segment field
   if (m_header.version < 2 || m_header.version > 5)
 return llvm::make_error(
 "Invalid arange header version");
@@ -81,6 +82,10 @@
 return llvm::make_error(
 "Invalid arange header length");
 
+  if (m_header.seg_size)
+return llvm::make_error(
+"segmented arange entries are not supported");
+
   // The first tuple following the header in each set begins at an offset
   // that is a multiple of the size of a single tuple (that is, twice the
   // size of an address). The header is padded, if necessary, to the
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D75925: [lldb] reject `.debug_arange` sections with nonzero segment size

2020-03-11 Thread Luke Drummond via Phabricator via lldb-commits
ldrumm updated this revision to Diff 249663.
ldrumm added a comment.

I found similar unittests for other DWARF entries which allow me to check more 
about the parser state, so I went with Pavel's suggestion for the testcase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75925

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp


Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -18,6 +18,7 @@
 #include "Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h"
 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
 #include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
@@ -310,3 +311,34 @@
   EXPECT_EQ("abbreviation declaration attribute list not terminated with a "
 "null entry", llvm::toString(std::move(error)));
 }
+
+TEST_F(SymbolFileDWARFTests, ParseArangesNonzeroSegmentSize) {
+  // This `.debug_aranges` table header is a valid 32bit big-endian section
+  // according to the DWARFv5 spec:6.2.1, but contains segment selectors which
+  // are not supported by lldb, and should be gracefully rejected
+  const unsigned char binary_data[] = {
+0, 0, 0, 41, // unit_length (length field not including this field itself)
+0, 2, // DWARF version number (half)
+0, 0, 0, 0, // offset into the .debug_info_table (ignored for the purposes 
of this test
+4, // address size
+1, // segment size
+// alignment for the first tuple which "begins at an offset that is a
+// multiple of the size of a single tuple". Tuples are nine bytes in this 
example.
+0, 0, 0, 0, 0, 0,
+// BEGIN TUPLES
+1, 0, 0, 0, 4, 0, 0, 0, 1, // a 1byte object starting at address 4 in 
segment 1
+0, 0, 0, 0, 4, 0, 0, 0, 1, // a 1byte object starting at address 4 in 
segment 0
+// END TUPLES
+0, 0, 0, 0, 0, 0, 0, 0, 0 // terminator
+  };
+  DWARFDataExtractor data;
+  data.SetData(static_cast(binary_data), sizeof binary_data,
+   lldb::ByteOrder::eByteOrderBig);
+  DWARFDebugArangeSet debug_aranges;
+  offset_t off = 0;
+  llvm::Error error = debug_aranges.extract(data, &off);
+  EXPECT_TRUE(bool(error));
+  EXPECT_EQ("segmented arange entries are not supported",
+llvm::toString(std::move(error)));
+  EXPECT_EQ(off, 12); // Parser should read no further than the segment size
+}
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
@@ -63,7 +63,8 @@
   // 1 - the version looks good
   // 2 - the address byte size looks plausible
   // 3 - the length seems to make sense
-  // size looks plausible
+  // 4 - size looks plausible
+  // 5 - the arange tuples do not contain a segment field
   if (m_header.version < 2 || m_header.version > 5)
 return llvm::make_error(
 "Invalid arange header version");
@@ -81,6 +82,10 @@
 return llvm::make_error(
 "Invalid arange header length");
 
+  if (m_header.seg_size)
+return llvm::make_error(
+"segmented arange entries are not supported");
+
   // The first tuple following the header in each set begins at an offset
   // that is a multiple of the size of a single tuple (that is, twice the
   // size of an address). The header is padded, if necessary, to the


Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -18,6 +18,7 @@
 #include "Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h"
 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
 #include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
@@ -310,3 +311,34 @@
   EXPECT_EQ("abbreviation declaration attribute list not terminated with a "
 "null entry", llvm::toString(std::move(error)));
 }
+
+TEST_F(SymbolFileDWARFTests, ParseArangesNonzeroSegmentSize) {
+  // This `.debug_aranges` table header is a valid 32bit big-endian section
+  // according to the DWARFv5 spec:6.2.1, but contains segment selectors which
+  // ar

[Lldb-commits] [PATCH] D75925: [lldb] reject `.debug_arange` sections with nonzero segment size

2020-03-12 Thread Luke Drummond via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0fa3320931e9: [lldb] reject `.debug_arange` sections with 
nonzero segment size (authored by ldrumm).

Changed prior to commit:
  https://reviews.llvm.org/D75925?vs=249663&id=249913#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75925

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp


Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -18,6 +18,7 @@
 #include "Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h"
 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
 #include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
@@ -310,3 +311,38 @@
   EXPECT_EQ("abbreviation declaration attribute list not terminated with a "
 "null entry", llvm::toString(std::move(error)));
 }
+
+TEST_F(SymbolFileDWARFTests, ParseArangesNonzeroSegmentSize) {
+  // This `.debug_aranges` table header is a valid 32bit big-endian section
+  // according to the DWARFv5 spec:6.2.1, but contains segment selectors which
+  // are not supported by lldb, and should be gracefully rejected
+  const unsigned char binary_data[] = {
+  0, 0, 0, 41, // unit_length (length field not including this field 
itself)
+  0, 2,// DWARF version number (half)
+  0, 0, 0, 0, // offset into the .debug_info_table (ignored for the 
purposes
+  // of this test
+  4,  // address size
+  1,  // segment size
+  // alignment for the first tuple which "begins at an offset that is a
+  // multiple of the size of a single tuple". Tuples are nine bytes in this
+  // example.
+  0, 0, 0, 0, 0, 0,
+  // BEGIN TUPLES
+  1, 0, 0, 0, 4, 0, 0, 0,
+  1, // a 1byte object starting at address 4 in segment 1
+  0, 0, 0, 0, 4, 0, 0, 0,
+  1, // a 1byte object starting at address 4 in segment 0
+  // END TUPLES
+  0, 0, 0, 0, 0, 0, 0, 0, 0 // terminator
+  };
+  DWARFDataExtractor data;
+  data.SetData(static_cast(binary_data), sizeof binary_data,
+   lldb::ByteOrder::eByteOrderBig);
+  DWARFDebugArangeSet debug_aranges;
+  offset_t off = 0;
+  llvm::Error error = debug_aranges.extract(data, &off);
+  EXPECT_TRUE(bool(error));
+  EXPECT_EQ("segmented arange entries are not supported",
+llvm::toString(std::move(error)));
+  EXPECT_EQ(off, 12); // Parser should read no further than the segment size
+}
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
@@ -63,7 +63,8 @@
   // 1 - the version looks good
   // 2 - the address byte size looks plausible
   // 3 - the length seems to make sense
-  // size looks plausible
+  // 4 - size looks plausible
+  // 5 - the arange tuples do not contain a segment field
   if (m_header.version < 2 || m_header.version > 5)
 return llvm::make_error(
 "Invalid arange header version");
@@ -81,6 +82,10 @@
 return llvm::make_error(
 "Invalid arange header length");
 
+  if (m_header.seg_size)
+return llvm::make_error(
+"segmented arange entries are not supported");
+
   // The first tuple following the header in each set begins at an offset
   // that is a multiple of the size of a single tuple (that is, twice the
   // size of an address). The header is padded, if necessary, to the


Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -18,6 +18,7 @@
 #include "Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h"
 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
 #include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
@@ -310,3 +311,38 @@
   EXPECT_EQ("abbreviation declaration attribute list not terminated with a "
 "null entry", llvm::toString(std::move(error)));
 }
+
+TEST_F(SymbolFileDWARFTests, ParseArangesNonzeroSegmentSize) {
+  // This `.debu