[Lldb-commits] [lldb] r314225 - [Expression Parser] Inhibit global lookups for symbols in the IR dynamic checks

2017-09-26 Thread Sean Callanan via lldb-commits
Author: spyffe
Date: Tue Sep 26 10:25:34 2017
New Revision: 314225

URL: http://llvm.org/viewvc/llvm-project?rev=314225&view=rev
Log:
[Expression Parser] Inhibit global lookups for symbols in the IR dynamic checks

The IR dynamic checks are self-contained functions whose job is to

- verify that pointers referenced in an expression are valid at runtime; and
- verify that selectors sent to Objective-C objects by an expression are
  actually supported by that object.

These dynamic checks forward-declare all the functions they use and should not
require any external debug information. The way they ensure this is by marking
all the names they use with a dollar sign ($). The expression parser recognizes
such symbols and perform no lookups for them.

This patch fixes three issues surrounding the use of the dollar sign:

- to fix a MIPS issue, the name of the pointer checker was changed from
  starting with $ to starting with _$, but this was not properly ignored; and
- the Objective-C object checker used a temporary variable that did not start
  with $.
- the Objective-C object checker used an externally-defined struct (struct
  objc_selector) but didn't need to.

The patch also implements some cleanup in the area:

- it reformats the string containing the Objective-C object checker,
  which was mangled horribly when the code was transformed to a uniform width
  of 80 columns, and
- it factors out the logic for ignoring global $-symbols into common code
  shared between ClangASTSource and ClangExpressionDeclMap.

Differential Revision: https://reviews.llvm.org/D38153

Modified:
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp?rev=314225&r1=314224&r2=314225&view=diff
==
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
(original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp Tue Sep 
26 10:25:34 2017
@@ -623,6 +623,25 @@ void ClangASTSource::FindExternalVisible
   }
 }
 
+bool ClangASTSource::IgnoreName(const ConstString name,
+bool ignore_all_dollar_names) {
+  static const ConstString id_name("id");
+  static const ConstString Class_name("Class");
+
+  if (name == id_name || name == Class_name)
+return true;
+
+  StringRef name_string_ref = name.GetStringRef();
+
+  // The ClangASTSource is not responsible for finding $-names.
+  if (name_string_ref.empty() ||
+  (ignore_all_dollar_names && name_string_ref.startswith("$")) ||
+  name_string_ref.startswith("_$"))
+return true;
+
+  return false;
+}
+
 void ClangASTSource::FindExternalVisibleDecls(
 NameSearchContext &context, lldb::ModuleSP module_sp,
 CompilerDeclContext &namespace_decl, unsigned int current_id) {
@@ -633,20 +652,7 @@ void ClangASTSource::FindExternalVisible
   SymbolContextList sc_list;
 
   const ConstString name(context.m_decl_name.getAsString().c_str());
-
-  const char *name_unique_cstr = name.GetCString();
-
-  static ConstString id_name("id");
-  static ConstString Class_name("Class");
-
-  if (name == id_name || name == Class_name)
-return;
-
-  if (name_unique_cstr == NULL)
-return;
-
-  // The ClangASTSource is not responsible for finding $-names.
-  if (name_unique_cstr[0] == '$')
+  if (IgnoreName(name, true))
 return;
 
   if (module_sp && namespace_decl) {

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.h?rev=314225&r1=314224&r2=314225&view=diff
==
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.h Tue Sep 
26 10:25:34 2017
@@ -376,6 +376,22 @@ protected:
   //--
   CompilerType GuardedCopyType(const CompilerType &src_type);
 
+  
+  //--
+  /// Returns true if a name should be ignored by name lookup.
+  ///
+  /// @param[in] name
+  /// The name to be considered.
+  ///
+  /// @param[in] ignore_all_dollar_nmmes
+  /// True if $-names of all sorts should be ignored.
+  ///
+  /// @return
+  /// True if the name is one of a class of names that are ignored by
+  /// global lookup for performance reasons.
+  //--

[Lldb-commits] [PATCH] D38153: Inhibit global lookups for symbols in the IR dynamic checks

2017-09-26 Thread Sean Callanan via Phabricator via lldb-commits
spyffe abandoned this revision.
spyffe added a comment.

Committed as LLDB r314225


Repository:
  rL LLVM

https://reviews.llvm.org/D38153



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


[Lldb-commits] [PATCH] D38153: Inhibit global lookups for symbols in the IR dynamic checks

2017-09-26 Thread Sean Callanan via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314225: [Expression Parser] Inhibit global lookups for 
symbols in the IR dynamic checks (authored by spyffe).

Changed prior to commit:
  https://reviews.llvm.org/D38153?vs=116444&id=116727#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38153

Files:
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
  lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

Index: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -811,85 +811,43 @@
 
   int len = 0;
   if (m_has_object_getClass) {
-len = ::snprintf(check_function_code, sizeof(check_function_code),
- "extern \"C\" void *gdb_object_getClass(void *);  "
- "\n"
- "extern \"C\"  int printf(const char *format, ...);   "
- "\n"
- "extern \"C\" void"
- "\n"
- "%s(void *$__lldb_arg_obj, void *$__lldb_arg_selector)"
- "\n"
- "{"
- "\n"
- "   if ($__lldb_arg_obj == (void *)0) "
- "\n"
- "   return; // nil is ok  "
- "\n"
- "   if (!gdb_object_getClass($__lldb_arg_obj))"
- "\n"
- "   *((volatile int *)0) = 'ocgc';"
- "\n"
- "   else if ($__lldb_arg_selector != (void *)0)   "
- "\n"
- "   { "
- "\n"
- "signed char responds = (signed char) [(id) "
- "$__lldb_arg_obj   \n"
- ""
- "respondsToSelector:  \n"
- "   (struct "
- "objc_selector *) $__lldb_arg_selector];   \n"
- "   if (responds == (signed char) 0)  "
- "\n"
- "   *((volatile int *)0) = 'ocgc';"
- "\n"
- "   } "
- "\n"
- "}"
- "\n",
- name);
+len = ::snprintf(check_function_code, sizeof(check_function_code), R"(
+ extern "C" void *gdb_object_getClass(void *);
+ extern "C" int printf(const char *format, ...);
+ extern "C" void
+ %s(void *$__lldb_arg_obj, void *$__lldb_arg_selector) {
+   if ($__lldb_arg_obj == (void *)0)
+ return; // nil is ok
+   if (!gdb_object_getClass($__lldb_arg_obj)) {
+ *((volatile int *)0) = 'ocgc';
+   } else if ($__lldb_arg_selector != (void *)0) {
+ signed char $responds = (signed char)
+ [(id)$__lldb_arg_obj respondsToSelector:
+ (void *) $__lldb_arg_selector];
+ if ($responds == (signed char) 0)
+   *((volatile int *)0) = 'ocgc';
+   }
+ })", name);
   } else {
-len = ::snprintf(check_function_code, sizeof(check_function_code),
- "extern \"C\" void *gdb_class_getClass(void *);   "
- "\n"
- "extern \"C\"  int print

[Lldb-commits] [lldb] r314265 - Update ABIMacOSX_arm::PrepareTrivialCall to correctly align the

2017-09-26 Thread Jason Molenda via lldb-commits
Author: jmolenda
Date: Tue Sep 26 19:49:18 2017
New Revision: 314265

URL: http://llvm.org/viewvc/llvm-project?rev=314265&view=rev
Log:
Update ABIMacOSX_arm::PrepareTrivialCall to correctly align the
stack pointer for apple's armv7 ABI.  When in a frameless function
or in a prologue/epilogue where sp wasn't properly aligned, we could
try to make function calls with an unaligned sp; the expression
would crash.

Modified:
lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp

Modified: lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp?rev=314265&r1=314264&r2=314265&view=diff
==
--- lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp Tue Sep 26 
19:49:18 2017
@@ -1413,10 +1413,6 @@ bool ABIMacOSX_arm::PrepareTrivialCall(T
   if (!reg_ctx->WriteRegisterFromUnsigned(ra_reg_num, return_addr))
 return false;
 
-  // Set "sp" to the requested value
-  if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_num, sp))
-return false;
-
   // If bit zero or 1 is set, this must be a thumb function, no need to figure
   // this out from the symbols.
   so_addr.SetLoadAddress(function_addr, target_sp.get());
@@ -1441,6 +1437,11 @@ bool ABIMacOSX_arm::PrepareTrivialCall(T
   function_addr &=
   ~1ull; // clear bit zero since the CPSR will take care of the mode for us
 
+  // Update the sp - stack pointer - to be aligned to 16-bytes
+  sp &= ~(0xfull);
+  if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_num, sp))
+return false;
+
   // Set "pc" to the address requested
   if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_num, function_addr))
 return false;


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