[Lldb-commits] [PATCH] D158205: [lldb] Fix performance regression after adding GNUstep ObjC runtime

2023-08-18 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Backport for 17.x release: https://github.com/llvm/llvm-project/issues/64800


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158205

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


[Lldb-commits] [PATCH] D158205: [lldb] Fix performance regression after adding GNUstep ObjC runtime

2023-08-18 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf2eb838309d: [lldb] Fix performance regression after adding 
GNUstep ObjC runtime (authored by sgraenitz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158205

Files:
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp


Index: 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
===
--- 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
+++ 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
@@ -37,6 +37,33 @@
   PluginManager::UnregisterPlugin(CreateInstance);
 }
 
+static bool CanModuleBeGNUstepObjCLibrary(const ModuleSP &module_sp,
+  const llvm::Triple &TT) {
+  if (!module_sp)
+return false;
+  const FileSpec &module_file_spec = module_sp->GetFileSpec();
+  if (!module_file_spec)
+return false;
+  llvm::StringRef filename = module_file_spec.GetFilename().GetStringRef();
+  if (TT.isOSBinFormatELF())
+return filename.starts_with("libobjc.so");
+  if (TT.isOSWindows())
+return filename == "objc.dll";
+  return false;
+}
+
+static bool ScanForGNUstepObjCLibraryCandidate(const ModuleList &modules,
+   const llvm::Triple &TT) {
+  std::lock_guard guard(modules.GetMutex());
+  size_t num_modules = modules.GetSize();
+  for (size_t i = 0; i < num_modules; i++) {
+auto mod = modules.GetModuleAtIndex(i);
+if (CanModuleBeGNUstepObjCLibrary(mod, TT))
+  return true;
+  }
+  return false;
+}
+
 LanguageRuntime *GNUstepObjCRuntime::CreateInstance(Process *process,
 LanguageType language) {
   if (language != eLanguageTypeObjC)
@@ -50,6 +77,9 @@
 return nullptr;
 
   const ModuleList &images = target.GetImages();
+  if (!ScanForGNUstepObjCLibraryCandidate(images, TT))
+return nullptr;
+
   if (TT.isOSBinFormatELF()) {
 SymbolContextList eh_pers;
 RegularExpression regex("__gnustep_objc[x]*_personality_v[0-9]+");
@@ -176,18 +206,8 @@
 }
 
 bool GNUstepObjCRuntime::IsModuleObjCLibrary(const ModuleSP &module_sp) {
-  if (!module_sp)
-return false;
-  const FileSpec &module_file_spec = module_sp->GetFileSpec();
-  if (!module_file_spec)
-return false;
-  llvm::StringRef filename = module_file_spec.GetFilename().GetStringRef();
   const llvm::Triple &TT = GetTargetRef().GetArchitecture().GetTriple();
-  if (TT.isOSBinFormatELF())
-return filename.starts_with("libobjc.so");
-  if (TT.isOSWindows())
-return filename == "objc.dll";
-  return false;
+  return CanModuleBeGNUstepObjCLibrary(module_sp, TT);
 }
 
 bool GNUstepObjCRuntime::ReadObjCLibrary(const ModuleSP &module_sp) {


Index: lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
@@ -37,6 +37,33 @@
   PluginManager::UnregisterPlugin(CreateInstance);
 }
 
+static bool CanModuleBeGNUstepObjCLibrary(const ModuleSP &module_sp,
+  const llvm::Triple &TT) {
+  if (!module_sp)
+return false;
+  const FileSpec &module_file_spec = module_sp->GetFileSpec();
+  if (!module_file_spec)
+return false;
+  llvm::StringRef filename = module_file_spec.GetFilename().GetStringRef();
+  if (TT.isOSBinFormatELF())
+return filename.starts_with("libobjc.so");
+  if (TT.isOSWindows())
+return filename == "objc.dll";
+  return false;
+}
+
+static bool ScanForGNUstepObjCLibraryCandidate(const ModuleList &modules,
+   const llvm::Triple &TT) {
+  std::lock_guard guard(modules.GetMutex());
+  size_t num_modules = modules.GetSize();
+  for (size_t i = 0; i < num_modules; i++) {
+auto mod = modules.GetModuleAtIndex(i);
+if (CanModuleBeGNUstepObjCLibrary(mod, TT))
+  return true;
+  }
+  return false;
+}
+
 LanguageRuntime *GNUstepObjCRuntime::CreateInstance(Process *process,
 LanguageType language) {
   if (language != eLanguageTypeObjC)
@@ -50,6 +77,9 @@
 return nullptr;
 
   const ModuleList &images = target.GetImages();
+  if (!ScanForGNUstepObjCLibraryCandidate(images, TT))
+return nullptr;
+
   if (TT.isOSBinFormatELF()) {
 SymbolContextList eh_pers;
 RegularExpression regex("__gnustep_objc[x]*_personality_v[0-9]+");
@@ -176,18 +206,8 @@
 }
 
 bool GNUstepObjCRuntime::IsModuleObjCLibrary(const ModuleSP &module_sp) {
-  if (!module_sp)
-return false;
-  const FileSpec &module_file_

[Lldb-commits] [PATCH] D158205: [lldb] Fix performance regression after adding GNUstep ObjC runtime

2023-08-18 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Thanks for your quick feedback everyone!

> Did you have the chance to verify that it improves performance of non-objc 
> inferiors on Linux?

Nope, but the author of the bug report confirmed that this fixes the issue for 
them. Since I will be on vacation starting tomorrow, I propose to land this as 
is.

> We'll also probably want to make sure this gets back ported into llvm-17.

Yes, let me check.




Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp:49
+  if (TT.isOSBinFormatELF())
+return filename.starts_with("libobjc.so");
+  if (TT.isOSWindows())

jingham wrote:
> bulbazord wrote:
> > jasonmolenda wrote:
> > > theraven wrote:
> > > > This is a bit unfortunate.  I know some downstream users that link the 
> > > > Objective-C runtime components into another .so, so we can't really 
> > > > rely on the name.  It would be nice if there were some mechanism for 
> > > > the user to specify the name of the runtime if they're using something 
> > > > non-standard.
> > > If the runtime was merged in to a library with a known name, we could 
> > > search for a name in the runtime (if it were the Darwin runtime, 
> > > objc_msgSend would be a good candidate) in the list of libraries that 
> > > might have the runtime in them.  Doing a "search for a symbol name in any 
> > > binary that is added" is expensive, doing "search these three solibs for 
> > > a symbol if they're loaded" is much less expensive, doing "is a solib 
> > > with this name loaded" is free.
> > That would be a nice follow-up!
> If we can't know up front what library contains the runtime, we could also 
> add a setting for the library name, so we don't have to guess.
Thanks for the note. Sounds reasonable. However, this is out of scope for the 
regression fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158205

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


[Lldb-commits] [PATCH] D158205: [lldb] Fix performance regression after adding GNUstep ObjC runtime

2023-08-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.
Herald added a subscriber: JDevlieghere.

The issue was reported in https://github.com/llvm/llvm-project/issues/64582


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158205

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


[Lldb-commits] [PATCH] D158205: [lldb] Fix performance regression after adding GNUstep ObjC runtime

2023-08-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: jasonmolenda, jingham, bulbazord, aprantl.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

We added support for the GNUstep ObjC runtime in 0b6264738f3d 
. In order 
to check if the target process uses
GNUstep we run an expensive symbol lookup in `CreateInstance()`. This turned 
out to cause a heavy performance
regression for non-GNUstep inferiors.

This patch puts a cheaper check in front, so that the vast majority of requests 
should return early. This
should fix the symptom for the moment. The conceptual question is why 
`LanguageRuntime::FindPlugin` invokes 
`create_callback` for each available runtime unconditionally in every 
`Process::ModulesDidLoad`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158205

Files:
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp


Index: 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
===
--- 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
+++ 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
@@ -37,6 +37,33 @@
   PluginManager::UnregisterPlugin(CreateInstance);
 }
 
+static bool CanModuleBeGNUstepObjCLibrary(const ModuleSP &module_sp,
+  const llvm::Triple &TT) {
+  if (!module_sp)
+return false;
+  const FileSpec &module_file_spec = module_sp->GetFileSpec();
+  if (!module_file_spec)
+return false;
+  llvm::StringRef filename = module_file_spec.GetFilename().GetStringRef();
+  if (TT.isOSBinFormatELF())
+return filename.starts_with("libobjc.so");
+  if (TT.isOSWindows())
+return filename == "objc.dll";
+  return false;
+}
+
+static bool ScanForGNUstepObjCLibraryCandidate(const ModuleList &modules,
+   const llvm::Triple &TT) {
+  std::lock_guard guard(modules.GetMutex());
+  size_t num_modules = modules.GetSize();
+  for (size_t i = 0; i < num_modules; i++) {
+auto mod = modules.GetModuleAtIndex(i);
+if (CanModuleBeGNUstepObjCLibrary(mod, TT))
+  return true;
+  }
+  return false;
+}
+
 LanguageRuntime *GNUstepObjCRuntime::CreateInstance(Process *process,
 LanguageType language) {
   if (language != eLanguageTypeObjC)
@@ -50,6 +77,9 @@
 return nullptr;
 
   const ModuleList &images = target.GetImages();
+  if (!ScanForGNUstepObjCLibraryCandidate(images, TT))
+return nullptr;
+
   if (TT.isOSBinFormatELF()) {
 SymbolContextList eh_pers;
 RegularExpression regex("__gnustep_objc[x]*_personality_v[0-9]+");
@@ -176,18 +206,8 @@
 }
 
 bool GNUstepObjCRuntime::IsModuleObjCLibrary(const ModuleSP &module_sp) {
-  if (!module_sp)
-return false;
-  const FileSpec &module_file_spec = module_sp->GetFileSpec();
-  if (!module_file_spec)
-return false;
-  llvm::StringRef filename = module_file_spec.GetFilename().GetStringRef();
   const llvm::Triple &TT = GetTargetRef().GetArchitecture().GetTriple();
-  if (TT.isOSBinFormatELF())
-return filename.starts_with("libobjc.so");
-  if (TT.isOSWindows())
-return filename == "objc.dll";
-  return false;
+  return CanModuleBeGNUstepObjCLibrary(module_sp, TT);
 }
 
 bool GNUstepObjCRuntime::ReadObjCLibrary(const ModuleSP &module_sp) {


Index: lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
@@ -37,6 +37,33 @@
   PluginManager::UnregisterPlugin(CreateInstance);
 }
 
+static bool CanModuleBeGNUstepObjCLibrary(const ModuleSP &module_sp,
+  const llvm::Triple &TT) {
+  if (!module_sp)
+return false;
+  const FileSpec &module_file_spec = module_sp->GetFileSpec();
+  if (!module_file_spec)
+return false;
+  llvm::StringRef filename = module_file_spec.GetFilename().GetStringRef();
+  if (TT.isOSBinFormatELF())
+return filename.starts_with("libobjc.so");
+  if (TT.isOSWindows())
+return filename == "objc.dll";
+  return false;
+}
+
+static bool ScanForGNUstepObjCLibraryCandidate(const ModuleList &modules,
+   const llvm::Triple &TT) {
+  std::lock_guard guard(modules.GetMutex());
+  size_t num_modules = modules.GetSize();
+  for (size_t i = 0; i < num_modules; i++) {
+auto mod = modules.GetModuleAtIndex(i);
+if (CanModuleBeGNUstepObjCLibrary(mod, TT))
+  return true;
+  }
+  return false;
+}
+
 LanguageRuntime *GNUstepObjCRuntime

[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-05-17 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0b6264738f3d: [lldb][gnustep] Add minimal GNUstepObjCRuntime 
plugin for LanguageTypeObjC on… (authored by sgraenitz).

Changed prior to commit:
  https://reviews.llvm.org/D146154?vs=522951&id=523004#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/CMakeLists.txt
  lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/CMakeLists.txt
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
  lldb/test/Shell/Expr/objc-gnustep-print.m

Index: lldb/test/Shell/Expr/objc-gnustep-print.m
===
--- lldb/test/Shell/Expr/objc-gnustep-print.m
+++ lldb/test/Shell/Expr/objc-gnustep-print.m
@@ -27,23 +27,39 @@
 }
 @end
 
-@interface TestObj : NSObject {}
-- (int)ok;
+@interface TestObj : NSObject {
+  int _int;
+  float _float;
+  char _char;
+  void *_ptr_void;
+  NSObject *_ptr_nsobject;
+  id _id_objc;
+}
+- (void)check_ivars_zeroed;
+- (void)set_ivars;
 @end
 @implementation TestObj
-- (int)ok {
-  return self ? 0 : 1;
+- (void)check_ivars_zeroed {
+  ;
+}
+- (void)set_ivars {
+  _int = 1;
+  _float = 2.0f;
+  _char = '\3';
+  _ptr_void = (void*)4;
+  _ptr_nsobject = (NSObject*)5;
+  _id_objc = (id)6;
 }
 @end
 
-// RUN: %lldb -b -o "b objc-gnustep-print.m:35" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
+// RUN: %lldb -b -o "b objc-gnustep-print.m:43" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
 //
-// SELF: (lldb) b objc-gnustep-print.m:35
+// SELF: (lldb) b objc-gnustep-print.m:43
 // SELF: Breakpoint {{.*}} at objc-gnustep-print.m
 //
 // SELF: (lldb) run
 // SELF: Process {{[0-9]+}} stopped
-// SELF: -[TestObj ok](self=[[SELF_PTR:0x[0-9a-f]+]]{{.*}}) at objc-gnustep-print.m:35
+// SELF: -[TestObj check_ivars_zeroed](self=[[SELF_PTR:0x[0-9a-f]+]]{{.*}}) at objc-gnustep-print.m
 //
 // SELF: (lldb) p self
 // SELF: (TestObj *) [[SELF_PTR]]
@@ -54,9 +70,38 @@
 // SELF: isa
 // SELF: refcount
 // SELF:   }
+// SELF:   _int = 0
+// SELF:   _float = 0
+// SELF:   _char = '\0'
+// SELF:   _ptr_void = 0x{{0*}}
+// SELF:   _ptr_nsobject = nil
+// SELF:   _id_objc = nil
 // SELF: }
 
+// RUN: %lldb -b -o "b objc-gnustep-print.m:106" -o "run" -o "p t->_int" -o "p t->_float" -o "p t->_char" \
+// RUN:  -o "p t->_ptr_void" -o "p t->_ptr_nsobject" -o "p t->_id_objc" -- %t | FileCheck %s --check-prefix=IVARS_SET
+//
+// IVARS_SET: (lldb) p t->_int
+// IVARS_SET: (int) 1
+//
+// IVARS_SET: (lldb) p t->_float
+// IVARS_SET: (float) 2
+//
+// IVARS_SET: (lldb) p t->_char
+// IVARS_SET: (char) '\x03'
+//
+// IVARS_SET: (lldb) p t->_ptr_void
+// IVARS_SET: (void *) 0x{{0*}}4
+//
+// IVARS_SET: (lldb) p t->_ptr_nsobject
+// IVARS_SET: (NSObject *) 0x{{0*}}5
+//
+// IVARS_SET: (lldb) p t->_id_objc
+// IVARS_SET: (id) 0x{{0*}}6
+
 int main() {
   TestObj *t = [TestObj new];
-  return [t ok];
+  [t check_ivars_zeroed];
+  [t set_ivars];
+  return 0;
 }
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -38,7 +38,8 @@
   enum class ObjCRuntimeVersions {
 eObjC_VersionUnknown = 0,
 eAppleObjC_V1 = 1,
-eAppleObjC_V2 = 2
+eAppleObjC_V2 = 2,
+eGNUstep_libobjc2 = 3,
   };
 
   typedef lldb::addr_t ObjCISA;
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
@@ -235,6 +235,22 @@
   m_isa_to_descriptor.begin(), m_isa_to_descriptor.end());
 }
 
+void ObjCLanguageRuntime::ReadObjCLibraryIfNeeded(
+const ModuleList &module_list) {
+  if (!HasReadObjCLibrary()) {
+std::lock_guard guard(module_list.GetMutex());
+
+size_t num_modules = module_list.GetSize();
+for (size_t i = 0; i < num_modules; i++) {
+  auto mod = module_list.GetModuleAtIndex(i);
+  if (IsModuleObjCLibrary(mod)) {
+ReadObjCLibrary(mod);
+break;
+  }
+}
+  }
+}
+
 ObjCLanguageRuntime::ObjCISA
 ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) {
   ClassDescriptorSP objc_class_sp(GetClassDescriptorFromISA(isa));
Index: lldb/source/Plugins/LanguageRuntime/ObjC/GNUst

[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-05-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 522951.
sgraenitz added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/CMakeLists.txt
  lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/CMakeLists.txt
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
  lldb/test/Shell/Expr/objc-gnustep-print.m

Index: lldb/test/Shell/Expr/objc-gnustep-print.m
===
--- lldb/test/Shell/Expr/objc-gnustep-print.m
+++ lldb/test/Shell/Expr/objc-gnustep-print.m
@@ -27,23 +27,39 @@
 }
 @end
 
-@interface TestObj : NSObject {}
-- (int)ok;
+@interface TestObj : NSObject {
+  int _int;
+  float _float;
+  char _char;
+  void *_ptr_void;
+  NSObject *_ptr_nsobject;
+  id _id_objc;
+}
+- (void)check_ivars_zeroed;
+- (void)set_ivars;
 @end
 @implementation TestObj
-- (int)ok {
-  return self ? 0 : 1;
+- (void)check_ivars_zeroed {
+  ;
+}
+- (void)set_ivars {
+  _int = 1;
+  _float = 2.0f;
+  _char = '\3';
+  _ptr_void = (void*)4;
+  _ptr_nsobject = (NSObject*)5;
+  _id_objc = (id)6;
 }
 @end
 
-// RUN: %lldb -b -o "b objc-gnustep-print.m:35" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
+// RUN: %lldb -b -o "b objc-gnustep-print.m:43" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
 //
-// SELF: (lldb) b objc-gnustep-print.m:35
+// SELF: (lldb) b objc-gnustep-print.m:43
 // SELF: Breakpoint {{.*}} at objc-gnustep-print.m
 //
 // SELF: (lldb) run
 // SELF: Process {{[0-9]+}} stopped
-// SELF: -[TestObj ok](self=[[SELF_PTR:0x[0-9a-f]+]]{{.*}}) at objc-gnustep-print.m:35
+// SELF: -[TestObj check_ivars_zeroed](self=[[SELF_PTR:0x[0-9a-f]+]]{{.*}}) at objc-gnustep-print.m
 //
 // SELF: (lldb) p self
 // SELF: (TestObj *) [[SELF_PTR]]
@@ -54,9 +70,38 @@
 // SELF: isa
 // SELF: refcount
 // SELF:   }
+// SELF:   _int = 0
+// SELF:   _float = 0
+// SELF:   _char = '\0'
+// SELF:   _ptr_void = 0x{{0*}}
+// SELF:   _ptr_nsobject = nil
+// SELF:   _id_objc = nil
 // SELF: }
 
+// RUN: %lldb -b -o "b objc-gnustep-print.m:106" -o "run" -o "p t->_int" -o "p t->_float" -o "p t->_char" \
+// RUN:  -o "p t->_ptr_void" -o "p t->_ptr_nsobject" -o "p t->_id_objc" -- %t | FileCheck %s --check-prefix=IVARS_SET
+//
+// IVARS_SET: (lldb) p t->_int
+// IVARS_SET: (int) $0 = 1
+//
+// IVARS_SET: (lldb) p t->_float
+// IVARS_SET: (float) $1 = 2
+//
+// IVARS_SET: (lldb) p t->_char
+// IVARS_SET: (char) $2 = '\x03'
+//
+// IVARS_SET: (lldb) p t->_ptr_void
+// IVARS_SET: (void *) $3 = 0x{{0*}}4
+//
+// IVARS_SET: (lldb) p t->_ptr_nsobject
+// IVARS_SET: (NSObject *) $4 = 0x{{0*}}5
+//
+// IVARS_SET: (lldb) p t->_id_objc
+// IVARS_SET: (id) $5 = 0x{{0*}}6
+
 int main() {
   TestObj *t = [TestObj new];
-  return [t ok];
+  [t check_ivars_zeroed];
+  [t set_ivars];
+  return 0;
 }
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -38,7 +38,8 @@
   enum class ObjCRuntimeVersions {
 eObjC_VersionUnknown = 0,
 eAppleObjC_V1 = 1,
-eAppleObjC_V2 = 2
+eAppleObjC_V2 = 2,
+eGNUstep_libobjc2 = 3,
   };
 
   typedef lldb::addr_t ObjCISA;
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
@@ -235,6 +235,22 @@
   m_isa_to_descriptor.begin(), m_isa_to_descriptor.end());
 }
 
+void ObjCLanguageRuntime::ReadObjCLibraryIfNeeded(
+const ModuleList &module_list) {
+  if (!HasReadObjCLibrary()) {
+std::lock_guard guard(module_list.GetMutex());
+
+size_t num_modules = module_list.GetSize();
+for (size_t i = 0; i < num_modules; i++) {
+  auto mod = module_list.GetModuleAtIndex(i);
+  if (IsModuleObjCLibrary(mod)) {
+ReadObjCLibrary(mod);
+break;
+  }
+}
+  }
+}
+
 ObjCLanguageRuntime::ObjCISA
 ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) {
   ClassDescriptorSP objc_class_sp(GetClassDescriptorFromISA(isa));
Index: lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
===
--- /dev/null
+++ lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GN

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-05-17 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4241ac542d69: [lldb][gnustep] Add basic test and 
infrastructure for GNUstep ObjC runtime (authored by sgraenitz).

Changed prior to commit:
  https://reviews.llvm.org/D146058?vs=522582&id=522944#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

Files:
  lldb/cmake/modules/FindGNUstepObjC.cmake
  lldb/test/CMakeLists.txt
  lldb/test/Shell/Expr/objc-gnustep-print.m
  lldb/test/Shell/helper/build.py
  lldb/test/Shell/helper/toolchain.py
  lldb/test/Shell/lit.cfg.py
  lldb/test/Shell/lit.site.cfg.py.in

Index: lldb/test/Shell/lit.site.cfg.py.in
===
--- lldb/test/Shell/lit.site.cfg.py.in
+++ lldb/test/Shell/lit.site.cfg.py.in
@@ -16,6 +16,7 @@
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.objc_gnustep_dir = "@LLDB_TEST_OBJC_GNUSTEP_DIR@"
 config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
Index: lldb/test/Shell/lit.cfg.py
===
--- lldb/test/Shell/lit.cfg.py
+++ lldb/test/Shell/lit.cfg.py
@@ -24,7 +24,7 @@
 
 # suffixes: A list of file extensions to treat as test files. This is overriden
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
 # subdirectories contain auxiliary inputs for various tests in their parent
@@ -135,6 +135,14 @@
 if config.have_lldb_server:
 config.available_features.add('lldb-server')
 
+if config.objc_gnustep_dir:
+config.available_features.add('objc-gnustep')
+if platform.system() == 'Windows':
+# objc.dll must be in PATH since Windows has no rpath
+config.environment['PATH'] = os.path.pathsep.join((
+os.path.join(config.objc_gnustep_dir, 'lib'),
+config.environment.get('PATH','')))
+
 # NetBSD permits setting dbregs either if one is root
 # or if user_set_dbregs is enabled
 can_set_dbregs = True
Index: lldb/test/Shell/helper/toolchain.py
===
--- lldb/test/Shell/helper/toolchain.py
+++ lldb/test/Shell/helper/toolchain.py
@@ -42,6 +42,8 @@
 build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
 if config.llvm_libs_dir:
 build_script_args.append('--libs-dir={0}'.format(config.llvm_libs_dir))
+if config.objc_gnustep_dir:
+build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 
 lldb_init = _get_lldb_init_path(config)
 
Index: lldb/test/Shell/helper/build.py
===
--- lldb/test/Shell/helper/build.py
+++ lldb/test/Shell/helper/build.py
@@ -49,6 +49,18 @@
 action='append',
 help='If specified, a path to search in addition to PATH when --compiler is not an exact path')
 
+parser.add_argument('--objc-gnustep-dir',
+metavar='directory',
+dest='objc_gnustep_dir',
+required=False,
+help='If specified, a path to GNUstep libobjc2 runtime for use on Windows and Linux')
+
+parser.add_argument('--objc-gnustep',
+dest='objc_gnustep',
+action='store_true',
+default=False,
+help='Include and link GNUstep libobjc2 (Windows and Linux only)')
+
 if sys.platform == 'darwin':
 parser.add_argument('--apple-sdk',
 metavar='apple_sdk',
@@ -238,6 +250,10 @@
 self.obj_ext = obj_ext
 self.lib_paths = args.libs_dir
 self.std = args.std
+assert not args.objc_gnustep or args.objc_gnustep_dir, \
+   "--objc-gnustep specified without path to libobjc2"
+self.objc_gnustep_inc = os.path.join(args.objc_gnustep_dir, 'include') if args.objc_gnustep_dir else None
+self.objc_gnustep_lib = os.path.join(args.objc_gnustep_dir, 'lib') if args.objc_gnustep_dir else None
 
 def _exe_file_name(self):
 assert self.mode != 'compile'
@@ -656,15 +672,20 @@
 args.append('-static')
 args.append('-c')
 
-args.extend(['-o', obj])
-args.append(source)
-
 if sys.platform == 'darwin':
 args.extend(['-isysroot', self.apple_sdk])
+elif self.objc_gnustep_inc:
+if source.endswith('.m') or source.endswith('

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-05-16 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 522582.
sgraenitz added a comment.

Rebase and re-run pre-merge checks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

Files:
  lldb/cmake/modules/FindGNUstepObjC.cmake
  lldb/test/CMakeLists.txt
  lldb/test/Shell/Expr/objc-gnustep-print.m
  lldb/test/Shell/helper/build.py
  lldb/test/Shell/helper/toolchain.py
  lldb/test/Shell/lit.cfg.py
  lldb/test/Shell/lit.site.cfg.py.in

Index: lldb/test/Shell/lit.site.cfg.py.in
===
--- lldb/test/Shell/lit.site.cfg.py.in
+++ lldb/test/Shell/lit.site.cfg.py.in
@@ -16,6 +16,7 @@
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.objc_gnustep_dir = "@LLDB_TEST_OBJC_GNUSTEP_DIR@"
 config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
Index: lldb/test/Shell/lit.cfg.py
===
--- lldb/test/Shell/lit.cfg.py
+++ lldb/test/Shell/lit.cfg.py
@@ -24,7 +24,7 @@
 
 # suffixes: A list of file extensions to treat as test files. This is overriden
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
 # subdirectories contain auxiliary inputs for various tests in their parent
@@ -135,6 +135,14 @@
 if config.have_lldb_server:
 config.available_features.add('lldb-server')
 
+if config.objc_gnustep_dir:
+config.available_features.add('objc-gnustep')
+if platform.system() == 'Windows':
+# objc.dll must be in PATH since Windows has no rpath
+config.environment['PATH'] = os.path.pathsep.join((
+os.path.join(config.objc_gnustep_dir, 'lib'),
+config.environment.get('PATH','')))
+
 # NetBSD permits setting dbregs either if one is root
 # or if user_set_dbregs is enabled
 can_set_dbregs = True
Index: lldb/test/Shell/helper/toolchain.py
===
--- lldb/test/Shell/helper/toolchain.py
+++ lldb/test/Shell/helper/toolchain.py
@@ -42,6 +42,8 @@
 build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
 if config.llvm_libs_dir:
 build_script_args.append('--libs-dir={0}'.format(config.llvm_libs_dir))
+if config.objc_gnustep_dir:
+build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 
 lldb_init = _get_lldb_init_path(config)
 
Index: lldb/test/Shell/helper/build.py
===
--- lldb/test/Shell/helper/build.py
+++ lldb/test/Shell/helper/build.py
@@ -49,6 +49,18 @@
 action='append',
 help='If specified, a path to search in addition to PATH when --compiler is not an exact path')
 
+parser.add_argument('--objc-gnustep-dir',
+metavar='directory',
+dest='objc_gnustep_dir',
+required=False,
+help='If specified, a path to GNUstep libobjc2 runtime for use on Windows and Linux')
+
+parser.add_argument('--objc-gnustep',
+dest='objc_gnustep',
+action='store_true',
+default=False,
+help='Include and link GNUstep libobjc2 (Windows and Linux only)')
+
 if sys.platform == 'darwin':
 parser.add_argument('--apple-sdk',
 metavar='apple_sdk',
@@ -238,6 +250,10 @@
 self.obj_ext = obj_ext
 self.lib_paths = args.libs_dir
 self.std = args.std
+assert not args.objc_gnustep or args.objc_gnustep_dir, \
+   "--objc-gnustep specified without path to libobjc2"
+self.objc_gnustep_inc = os.path.join(args.objc_gnustep_dir, 'include') if args.objc_gnustep_dir else None
+self.objc_gnustep_lib = os.path.join(args.objc_gnustep_dir, 'lib') if args.objc_gnustep_dir else None
 
 def _exe_file_name(self):
 assert self.mode != 'compile'
@@ -656,15 +672,20 @@
 args.append('-static')
 args.append('-c')
 
-args.extend(['-o', obj])
-args.append(source)
-
 if sys.platform == 'darwin':
 args.extend(['-isysroot', self.apple_sdk])
+elif self.objc_gnustep_inc:
+if source.endswith('.m') or source.endswith('.mm'):
+args.extend(['-fobjc-runtime=gnustep-2.0', '-I', self.objc_gnustep_inc])
+if sys.platform == "win32":
+args.extend(['-Xclang', '-gcodeview', '-Xclang', '--dependent-lib=msvcrtd'])
 
 if self.std:
 args.append('-std={0}'.format(self.std))
 

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-05-14 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

This patch adds test coverage for existing functionality. It was ready to land 
6 weeks ago. There was plenty of opportunity to raise concerns and discuss 
details over the last 2 months of review. I assume the topic is just too niche 
to attract a lot of attention.

I am planning to land this patch tomorrow and D146154 
 soon after, since I have some time on 
Tuesday and Wednesday to cope with build bot reports. I am happy to answer any 
questions in the remaining time. Otherwise, don't hesitate to follow up 
post-commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-04-29 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 518169.
sgraenitz edited the summary of this revision.
sgraenitz added a comment.

Rebase and double-check default config: GNUstep disabled, objc-gnustep-print 
test unsupported


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

Files:
  lldb/cmake/modules/FindGNUstepObjC.cmake
  lldb/test/CMakeLists.txt
  lldb/test/Shell/Expr/objc-gnustep-print.m
  lldb/test/Shell/helper/build.py
  lldb/test/Shell/helper/toolchain.py
  lldb/test/Shell/lit.cfg.py
  lldb/test/Shell/lit.site.cfg.py.in

Index: lldb/test/Shell/lit.site.cfg.py.in
===
--- lldb/test/Shell/lit.site.cfg.py.in
+++ lldb/test/Shell/lit.site.cfg.py.in
@@ -16,6 +16,7 @@
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.objc_gnustep_dir = "@LLDB_TEST_OBJC_GNUSTEP_DIR@"
 config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
Index: lldb/test/Shell/lit.cfg.py
===
--- lldb/test/Shell/lit.cfg.py
+++ lldb/test/Shell/lit.cfg.py
@@ -24,7 +24,7 @@
 
 # suffixes: A list of file extensions to treat as test files. This is overriden
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
 # subdirectories contain auxiliary inputs for various tests in their parent
@@ -135,6 +135,14 @@
 if config.have_lldb_server:
 config.available_features.add('lldb-server')
 
+if config.objc_gnustep_dir:
+config.available_features.add('objc-gnustep')
+if platform.system() == 'Windows':
+# objc.dll must be in PATH since Windows has no rpath
+config.environment['PATH'] = os.path.pathsep.join((
+os.path.join(config.objc_gnustep_dir, 'lib'),
+config.environment.get('PATH','')))
+
 # NetBSD permits setting dbregs either if one is root
 # or if user_set_dbregs is enabled
 can_set_dbregs = True
Index: lldb/test/Shell/helper/toolchain.py
===
--- lldb/test/Shell/helper/toolchain.py
+++ lldb/test/Shell/helper/toolchain.py
@@ -42,6 +42,8 @@
 build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
 if config.llvm_libs_dir:
 build_script_args.append('--libs-dir={0}'.format(config.llvm_libs_dir))
+if config.objc_gnustep_dir:
+build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 
 lldb_init = _get_lldb_init_path(config)
 
Index: lldb/test/Shell/helper/build.py
===
--- lldb/test/Shell/helper/build.py
+++ lldb/test/Shell/helper/build.py
@@ -49,6 +49,18 @@
 action='append',
 help='If specified, a path to search in addition to PATH when --compiler is not an exact path')
 
+parser.add_argument('--objc-gnustep-dir',
+metavar='directory',
+dest='objc_gnustep_dir',
+required=False,
+help='If specified, a path to GNUstep libobjc2 runtime for use on Windows and Linux')
+
+parser.add_argument('--objc-gnustep',
+dest='objc_gnustep',
+action='store_true',
+default=False,
+help='Include and link GNUstep libobjc2 (Windows and Linux only)')
+
 if sys.platform == 'darwin':
 parser.add_argument('--apple-sdk',
 metavar='apple_sdk',
@@ -238,6 +250,10 @@
 self.obj_ext = obj_ext
 self.lib_paths = args.libs_dir
 self.std = args.std
+assert not args.objc_gnustep or args.objc_gnustep_dir, \
+   "--objc-gnustep specified without path to libobjc2"
+self.objc_gnustep_inc = os.path.join(args.objc_gnustep_dir, 'include') if args.objc_gnustep_dir else None
+self.objc_gnustep_lib = os.path.join(args.objc_gnustep_dir, 'lib') if args.objc_gnustep_dir else None
 
 def _exe_file_name(self):
 assert self.mode != 'compile'
@@ -656,15 +672,20 @@
 args.append('-static')
 args.append('-c')
 
-args.extend(['-o', obj])
-args.append(source)
-
 if sys.platform == 'darwin':
 args.extend(['-isysroot', self.apple_sdk])
+elif self.objc_gnustep_inc:
+if source.endswith('.m') or source.endswith('.mm'):
+args.extend(['-fobjc-runtime=gnustep-2.0', '-I', self.objc_gnustep_inc])
+if sys.platform == "win32":
+args.extend(['-Xclang', '-gcodeview', '-Xclang', '

[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-29 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG64a2520bacb5: [lldb][ObjectFileELF] Support AArch32 in 
ApplyRelocations (authored by sgraenitz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147642

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml

Index: lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
===
--- /dev/null
+++ lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
@@ -0,0 +1,62 @@
+# RUN: yaml2obj %s -o %t
+# RUN: lldb-test object-file -contents %t | FileCheck %s
+
+## Test that R_ARM_ABS32 relocations are resolved in .debug_info sections on aarch32.
+## REL-type relocations store implicit addend as signed values inline.
+## We relocate the symbol foo with 4 different addends and bar once in the .debug_info section.
+## Results that exceed the 32-bit range or overflow are logged and ignored.
+
+# CHECK:  Name: .debug_info
+# CHECK:  Data:  (
+#
+#  Addends: Zero Positive Negative Overflow Out-of-range
+#    04030201 D6FF D5FF FF7F
+# CHECK-NEXT: : 2A00 2E030201  D5FF FF7F
+# CHECK-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_REL
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+  - Name:.debug_info
+Type:SHT_PROGBITS
+Content: 04030201D6FFD57F
+  - Name:.rel.debug_info
+Type:SHT_REL
+Info:.debug_info
+Relocations:
+  - Offset:  0x0
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x4
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x8
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0xC
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x10
+Symbol:  bar
+Type:R_ARM_ABS32
+Symbols:
+  - Name:.debug_info
+Type:STT_SECTION
+Section: .debug_info
+  - Name:foo
+Type:STT_FUNC
+Section: .debug_info
+Value:   0x002A
+  - Name:bar
+Type:STT_FUNC
+Section: .debug_info
+Value:   0xFF00
+...
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2637,6 +2637,44 @@
   }
 }
 
+static void ApplyELF32ABS32RelRelocation(Symtab *symtab, ELFRelocation &rel,
+ DataExtractor &debug_data,
+ Section *rel_section) {
+  Log *log = GetLog(LLDBLog::Modules);
+  Symbol *symbol = symtab->FindSymbolByID(ELFRelocation::RelocSymbol32(rel));
+  if (symbol) {
+addr_t value = symbol->GetAddressRef().GetFileAddress();
+if (value == LLDB_INVALID_ADDRESS) {
+  const char *name = symbol->GetName().GetCString();
+  LLDB_LOGF(log, "Debug info symbol invalid: %s", name);
+  return;
+}
+assert(llvm::isUInt<32>(value) && "Valid addresses are 32-bit");
+DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+WritableDataBuffer *data_buffer =
+llvm::cast(data_buffer_sp.get());
+uint8_t *dst = data_buffer->GetBytes() + rel_section->GetFileOffset() +
+   ELFRelocation::RelocOffset32(rel);
+// Implicit addend is stored inline as a signed value.
+int32_t addend;
+memcpy(&addend, dst, sizeof(int32_t));
+// The sum must be positive. This extra check prevents UB from overflow in
+// the actual range check below.
+if (addend < 0 && static_cast(-addend) > value) {
+  LLDB_LOGF(log, "Debug info relocation overflow: 0x%" PRIx64,
+static_cast(value) + addend);
+  return;
+}
+if (!llvm::isUInt<32>(value + addend)) {
+  LLDB_LOGF(log, "Debug info relocation out of range: 0x%" PRIx64, value);
+  return;
+}
+uint32_t addr = value + addend;
+memcpy(dst, &addr, sizeof(uint32_t));
+  }
+}
+
 unsigned ObjectFileELF::ApplyRelocations(
 Symtab *symtab, const ELFHeader *hdr, const ELFSectionHeader *rel_hdr,
 const ELFSectionHeader *symtab_hdr, const ELFSect

[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-29 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 518167.
sgraenitz marked an inline comment as done.
sgraenitz added a comment.

Address feedback and rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147642

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml

Index: lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
===
--- /dev/null
+++ lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
@@ -0,0 +1,62 @@
+# RUN: yaml2obj %s -o %t
+# RUN: lldb-test object-file -contents %t | FileCheck %s
+
+## Test that R_ARM_ABS32 relocations are resolved in .debug_info sections on aarch32.
+## REL-type relocations store implicit addend as signed values inline.
+## We relocate the symbol foo with 4 different addends and bar once in the .debug_info section.
+## Results that exceed the 32-bit range or overflow are logged and ignored.
+
+# CHECK:  Name: .debug_info
+# CHECK:  Data:  (
+#
+#  Addends: Zero Positive Negative Overflow Out-of-range
+#    04030201 D6FF D5FF FF7F
+# CHECK-NEXT: : 2A00 2E030201  D5FF FF7F
+# CHECK-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_REL
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+  - Name:.debug_info
+Type:SHT_PROGBITS
+Content: 04030201D6FFD57F
+  - Name:.rel.debug_info
+Type:SHT_REL
+Info:.debug_info
+Relocations:
+  - Offset:  0x0
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x4
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x8
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0xC
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x10
+Symbol:  bar
+Type:R_ARM_ABS32
+Symbols:
+  - Name:.debug_info
+Type:STT_SECTION
+Section: .debug_info
+  - Name:foo
+Type:STT_FUNC
+Section: .debug_info
+Value:   0x002A
+  - Name:bar
+Type:STT_FUNC
+Section: .debug_info
+Value:   0xFF00
+...
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2637,6 +2637,44 @@
   }
 }
 
+static void ApplyELF32ABS32RelRelocation(Symtab *symtab, ELFRelocation &rel,
+ DataExtractor &debug_data,
+ Section *rel_section) {
+  Log *log = GetLog(LLDBLog::Modules);
+  Symbol *symbol = symtab->FindSymbolByID(ELFRelocation::RelocSymbol32(rel));
+  if (symbol) {
+addr_t value = symbol->GetAddressRef().GetFileAddress();
+if (value == LLDB_INVALID_ADDRESS) {
+  const char *name = symbol->GetName().GetCString();
+  LLDB_LOGF(log, "Debug info symbol invalid: %s", name);
+  return;
+}
+assert(llvm::isUInt<32>(value) && "Valid addresses are 32-bit");
+DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+WritableDataBuffer *data_buffer =
+llvm::cast(data_buffer_sp.get());
+uint8_t *dst = data_buffer->GetBytes() + rel_section->GetFileOffset() +
+   ELFRelocation::RelocOffset32(rel);
+// Implicit addend is stored inline as a signed value.
+int32_t addend;
+memcpy(&addend, dst, sizeof(int32_t));
+// The sum must be positive. This extra check prevents UB from overflow in
+// the actual range check below.
+if (addend < 0 && static_cast(-addend) > value) {
+  LLDB_LOGF(log, "Debug info relocation overflow: 0x%" PRIx64,
+static_cast(value) + addend);
+  return;
+}
+if (!llvm::isUInt<32>(value + addend)) {
+  LLDB_LOGF(log, "Debug info relocation out of range: 0x%" PRIx64, value);
+  return;
+}
+uint32_t addr = value + addend;
+memcpy(dst, &addr, sizeof(uint32_t));
+  }
+}
+
 unsigned ObjectFileELF::ApplyRelocations(
 Symtab *symtab, const ELFHeader *hdr, const ELFSectionHeader *rel_hdr,
 const ELFSectionHeader *symtab_hdr, const ELFSectionHeader *debug_hdr,
@@ -2667,6 +2705,21 @@
 
 if (hdr->Is32Bit()) {
   switch (hdr->e_ma

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-04-29 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

In D146058#4305046 , @labath wrote:

> That's not entirely what I was referring to. What I fear is the following 
> situation. A random developer makes a random patch that happens to break 
> gnustep support. That developer cannot debug that issue locally (cannot or 
> doesn't know how to build gnustep from source), so someone has to help him 
> figure out the problem. I don't want to be the person doing that. :)

Yes, that's reasonable. In my last patch, I already changed the default to 
`Off`.




Comment at: lldb/test/CMakeLists.txt:29
+# Windows and Linux have no built-in ObjC runtime. Turn this on in order to 
run tests with GNUstep.
+option(LLDB_TEST_OBJC_GNUSTEP "Enable ObjC tests with GNUstep libobjc2 on 
non-Apple platforms" Off)
+set(LLDB_TEST_OBJC_GNUSTEP_DIR "" CACHE PATH "Custom path to the GNUstep 
shared library")

See here, `Off` by default


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-28 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147642

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


[Lldb-commits] [PATCH] D147669: PECOFF: consume errors properly

2023-04-14 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz accepted this revision.
sgraenitz added a comment.
This revision is now accepted and ready to land.

Great. Thanks!


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

https://reviews.llvm.org/D147669

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


[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-14 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Double-checked and found source locations on Raspberry Pi 3b with this patch 
applied 
https://github.com/llvm/llvm-project/issues/61948#issuecomment-1508305542
Is there more feedback on this? It would be nice to land it soon, i.e. before 
EuroLLVM =)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147642

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


[Lldb-commits] [PATCH] D147669: PECOFF: consume errors properly

2023-04-13 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

I think it's a very good practice that objects in moved-from state will only 
ever get destroyed. While the move ctor itself has no preconditions and thus 
might be fine to call again, the implementation of `consumeError()` does 
inspect the object. This adds an unnecessary risk for UB. Please simply check 
the log state and call either `fmt_consume()` or `consumeError()`. Thanks.


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

https://reviews.llvm.org/D147669

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


[Lldb-commits] [PATCH] D147627: [lldb][ObjectFileELF] Improve error output for unsupported arch/relocations

2023-04-13 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
sgraenitz marked an inline comment as done.
Closed by commit rGcc6ab268d89b: [lldb][ObjectFileELF] Improve error output for 
unsupported arch/relocations (authored by sgraenitz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147627

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp


Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2666,38 +2666,49 @@
 Symbol *symbol = nullptr;
 
 if (hdr->Is32Bit()) {
-  switch (reloc_type(rel)) {
-  case R_386_32:
-symbol = symtab->FindSymbolByID(reloc_symbol(rel));
-if (symbol) {
-  addr_t f_offset =
-  rel_section->GetFileOffset() + ELFRelocation::RelocOffset32(rel);
-  DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
-  // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
-  WritableDataBuffer *data_buffer =
-  llvm::cast(data_buffer_sp.get());
-  uint32_t *dst = reinterpret_cast(
-  data_buffer->GetBytes() + f_offset);
-
-  addr_t value = symbol->GetAddressRef().GetFileAddress();
-  if (rel.IsRela()) {
-value += ELFRelocation::RelocAddend32(rel);
+  switch (hdr->e_machine) {
+  case llvm::ELF::EM_386:
+switch (reloc_type(rel)) {
+case R_386_32:
+  symbol = symtab->FindSymbolByID(reloc_symbol(rel));
+  if (symbol) {
+addr_t f_offset =
+rel_section->GetFileOffset() + 
ELFRelocation::RelocOffset32(rel);
+DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+WritableDataBuffer *data_buffer =
+llvm::cast(data_buffer_sp.get());
+uint32_t *dst = reinterpret_cast(
+data_buffer->GetBytes() + f_offset);
+
+addr_t value = symbol->GetAddressRef().GetFileAddress();
+if (rel.IsRela()) {
+  value += ELFRelocation::RelocAddend32(rel);
+} else {
+  value += *dst;
+}
+*dst = value;
   } else {
-value += *dst;
+GetModule()->ReportError(".rel{0}[{1}] unknown symbol id: {2:d}",
+rel_section->GetName().AsCString(), i,
+reloc_symbol(rel));
   }
-  *dst = value;
-} else {
-  GetModule()->ReportError(".rel{0}[{1}] unknown symbol id: {2:d}",
+  break;
+case R_386_NONE:
+case R_386_PC32:
+  GetModule()->ReportError("unsupported i386 relocation:"
+   " .rel{0}[{1}], type {2}",
rel_section->GetName().AsCString(), i,
-   reloc_symbol(rel));
+   reloc_type(rel));
+  break;
+default:
+  assert(false && "unexpected relocation type");
+  break;
 }
 break;
-  case R_386_PC32:
   default:
-GetModule()->ReportError("unsupported 32-bit relocation:"
- " .rel{0}[{1}], type {2}",
- rel_section->GetName().AsCString(), i,
- reloc_type(rel));
+GetModule()->ReportError("unsupported 32-bit ELF machine arch: {0}", 
hdr->e_machine);
+break;
   }
 } else {
   switch (hdr->e_machine) {
@@ -2743,7 +2754,8 @@
 }
 break;
   default:
-assert(false && "unsupported machine");
+GetModule()->ReportError("unsupported 64-bit ELF machine arch: {0}", 
hdr->e_machine);
+break;
   }
 }
   }


Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2666,38 +2666,49 @@
 Symbol *symbol = nullptr;
 
 if (hdr->Is32Bit()) {
-  switch (reloc_type(rel)) {
-  case R_386_32:
-symbol = symtab->FindSymbolByID(reloc_symbol(rel));
-if (symbol) {
-  addr_t f_offset =
-  rel_section->GetFileOffset() + ELFRelocation::RelocOffset32(rel);
-  DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
-  // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
-  WritableDataBuffer *data_buffer =
-  llvm::cast(data_buffer_sp.get());
-  uint32_t *dst = reinterpret_cast(
-  data_buffer->Ge

[Lldb-commits] [PATCH] D147627: [lldb][ObjectFileELF] Improve error output for unsupported arch/relocations

2023-04-13 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz marked an inline comment as done.
sgraenitz added a comment.

Thanks for your feedback




Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2704
+default:
+  assert(false && "unexpected relocation type");
+  break;

DavidSpickett wrote:
> Should this report error also? Given that you want it to not crash.
> 
> Though it did that already, you must have had reason to change it.
I think the relocation types that can occur in debug sections are considered an 
invariant. If we see other relocation types, we got on a wrong track long 
before. The relocation resolver that exists in LLVM nowadays follows a 
support/resolve approach, which gives it a cleaner structure, but it comes down 
to the same behavior eventually: 
https://github.com/llvm/llvm-project/blob/release/16.x/llvm/lib/Object/RelocationResolver.cpp#L287-L299

I think it's best to keep this as is: Bail out with the assertion in 
development builds and ignore it silently in release builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147627

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


[Lldb-commits] [PATCH] D147627: [lldb][ObjectFileELF] Improve error output for unsupported arch/relocations

2023-04-13 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 513187.
sgraenitz added a comment.

Include `R_386_NONE` for error reporting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147627

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp


Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2666,38 +2666,49 @@
 Symbol *symbol = nullptr;
 
 if (hdr->Is32Bit()) {
-  switch (reloc_type(rel)) {
-  case R_386_32:
-symbol = symtab->FindSymbolByID(reloc_symbol(rel));
-if (symbol) {
-  addr_t f_offset =
-  rel_section->GetFileOffset() + ELFRelocation::RelocOffset32(rel);
-  DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
-  // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
-  WritableDataBuffer *data_buffer =
-  llvm::cast(data_buffer_sp.get());
-  uint32_t *dst = reinterpret_cast(
-  data_buffer->GetBytes() + f_offset);
-
-  addr_t value = symbol->GetAddressRef().GetFileAddress();
-  if (rel.IsRela()) {
-value += ELFRelocation::RelocAddend32(rel);
+  switch (hdr->e_machine) {
+  case llvm::ELF::EM_386:
+switch (reloc_type(rel)) {
+case R_386_32:
+  symbol = symtab->FindSymbolByID(reloc_symbol(rel));
+  if (symbol) {
+addr_t f_offset =
+rel_section->GetFileOffset() + 
ELFRelocation::RelocOffset32(rel);
+DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+WritableDataBuffer *data_buffer =
+llvm::cast(data_buffer_sp.get());
+uint32_t *dst = reinterpret_cast(
+data_buffer->GetBytes() + f_offset);
+
+addr_t value = symbol->GetAddressRef().GetFileAddress();
+if (rel.IsRela()) {
+  value += ELFRelocation::RelocAddend32(rel);
+} else {
+  value += *dst;
+}
+*dst = value;
   } else {
-value += *dst;
+GetModule()->ReportError(".rel{0}[{1}] unknown symbol id: {2:d}",
+rel_section->GetName().AsCString(), i,
+reloc_symbol(rel));
   }
-  *dst = value;
-} else {
-  GetModule()->ReportError(".rel{0}[{1}] unknown symbol id: {2:d}",
+  break;
+case R_386_NONE:
+case R_386_PC32:
+  GetModule()->ReportError("unsupported i386 relocation:"
+   " .rel{0}[{1}], type {2}",
rel_section->GetName().AsCString(), i,
-   reloc_symbol(rel));
+   reloc_type(rel));
+  break;
+default:
+  assert(false && "unexpected relocation type");
+  break;
 }
 break;
-  case R_386_PC32:
   default:
-GetModule()->ReportError("unsupported 32-bit relocation:"
- " .rel{0}[{1}], type {2}",
- rel_section->GetName().AsCString(), i,
- reloc_type(rel));
+GetModule()->ReportError("unsupported 32-bit ELF machine arch: {0}", 
hdr->e_machine);
+break;
   }
 } else {
   switch (hdr->e_machine) {
@@ -2743,7 +2754,8 @@
 }
 break;
   default:
-assert(false && "unsupported machine");
+GetModule()->ReportError("unsupported 64-bit ELF machine arch: {0}", 
hdr->e_machine);
+break;
   }
 }
   }


Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2666,38 +2666,49 @@
 Symbol *symbol = nullptr;
 
 if (hdr->Is32Bit()) {
-  switch (reloc_type(rel)) {
-  case R_386_32:
-symbol = symtab->FindSymbolByID(reloc_symbol(rel));
-if (symbol) {
-  addr_t f_offset =
-  rel_section->GetFileOffset() + ELFRelocation::RelocOffset32(rel);
-  DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
-  // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
-  WritableDataBuffer *data_buffer =
-  llvm::cast(data_buffer_sp.get());
-  uint32_t *dst = reinterpret_cast(
-  data_buffer->GetBytes() + f_offset);
-
-  addr_t value = symbol->GetAddressRef().GetFileAddress();
-  if (rel.IsRela()) {
-   

[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-13 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Addressed feedback and added handling for `R_ARM_REL32`. I didn't see a 
real-world case for it yet. Hope it's ok to have the error reported for the 
time being.




Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2640
 
+static void ApplyELF32ABS32Relocation(Symtab *symtab, ELFRelocation &rel,
+  DataExtractor &debug_data,

peter.smith wrote:
> IIUC the  largest difference between this and ApplyELF64ABS32Relocation is 
> the use of REL rather than RELA relocations. Perhaps worth naming it as 
> `ApplyELF32ABS32RelRelocation` 
Thanks, very good point. Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147642

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


[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-13 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 513179.
sgraenitz added a comment.

Add error reporting for `R_ARM_REL32` relocations


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147642

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml

Index: lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
===
--- /dev/null
+++ lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
@@ -0,0 +1,62 @@
+# RUN: yaml2obj %s -o %t
+# RUN: lldb-test object-file -contents %t | FileCheck %s
+
+## Test that R_ARM_ABS32 relocations are resolved in .debug_info sections on aarch32.
+## REL-type relocations store implicit addend as signed values inline.
+## We relocate the symbol foo with 4 different addends and bar once in the .debug_info section.
+## Results that exceed the 32-bit range or overflow are logged and ignored.
+
+# CHECK:  Name: .debug_info
+# CHECK:  Data:  (
+#
+#  Addends: Zero Positive Negative Overflow Out-of-range
+#    04030201 D6FF D5FF FF7F
+# CHECK-NEXT: : 2A00 2E030201  D5FF FF7F
+# CHECK-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_REL
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+  - Name:.debug_info
+Type:SHT_PROGBITS
+Content: 04030201D6FFD57F
+  - Name:.rel.debug_info
+Type:SHT_REL
+Info:.debug_info
+Relocations:
+  - Offset:  0x0
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x4
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x8
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0xC
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x10
+Symbol:  bar
+Type:R_ARM_ABS32
+Symbols:
+  - Name:.debug_info
+Type:STT_SECTION
+Section: .debug_info
+  - Name:foo
+Type:STT_FUNC
+Section: .debug_info
+Value:   0x002A
+  - Name:bar
+Type:STT_FUNC
+Section: .debug_info
+Value:   0xFF00
+...
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2637,6 +2637,43 @@
   }
 }
 
+static void ApplyELF32ABS32RelRelocation(Symtab *symtab, ELFRelocation &rel,
+ DataExtractor &debug_data,
+ Section *rel_section) {
+  Log *log = GetLog(LLDBLog::Modules);
+  Symbol *symbol = symtab->FindSymbolByID(ELFRelocation::RelocSymbol32(rel));
+  if (symbol) {
+addr_t value = symbol->GetAddressRef().GetFileAddress();
+if (value == LLDB_INVALID_ADDRESS) {
+  const char *name = symbol->GetName().GetCString();
+  LLDB_LOGF(log, "Debug info symbol invalid: %s", name);
+  return;
+}
+assert(llvm::isUInt<32>(value) && "Valid addresses are 32-bit");
+DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+WritableDataBuffer *data_buffer =
+llvm::cast(data_buffer_sp.get());
+uint8_t *dst = data_buffer->GetBytes() + rel_section->GetFileOffset() +
+   ELFRelocation::RelocOffset32(rel);
+// Implicit addend is stored inline as a signed value.
+int32_t addend = *reinterpret_cast(dst);
+// The sum must be positive. This extra check prevents UB from overflow in
+// the actual range check below.
+if (addend < 0 && static_cast(std::abs(addend)) > value) {
+  LLDB_LOGF(log, "Debug info relocation overflow: 0x%" PRIx64,
+static_cast(value) + addend);
+  return;
+}
+if (!llvm::isUInt<32>(value + addend)) {
+  LLDB_LOGF(log, "Debug info relocation out of range: 0x%" PRIx64, value);
+  return;
+}
+uint32_t addr = value + addend;
+memcpy(dst, &addr, sizeof(uint32_t));
+  }
+}
+
 unsigned ObjectFileELF::ApplyRelocations(
 Symtab *symtab, const ELFHeader *hdr, const ELFSectionHeader *rel_hdr,
 const ELFSectionHeader *symtab_hdr, const ELFSectionHeader *debug_hdr,
@@ -2667,6 +2704,21 @@
 
 if (hdr->Is32Bit()) {
   switch (hdr->e_machine) {
+  case llvm::ELF::

[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-13 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 513178.
sgraenitz marked an inline comment as done.
sgraenitz added a comment.

Rename new function to `ApplyELF32ABS32RelRelocation()`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147642

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml

Index: lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
===
--- /dev/null
+++ lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
@@ -0,0 +1,62 @@
+# RUN: yaml2obj %s -o %t
+# RUN: lldb-test object-file -contents %t | FileCheck %s
+
+## Test that R_ARM_ABS32 relocations are resolved in .debug_info sections on aarch32.
+## REL-type relocations store implicit addend as signed values inline.
+## We relocate the symbol foo with 4 different addends and bar once in the .debug_info section.
+## Results that exceed the 32-bit range or overflow are logged and ignored.
+
+# CHECK:  Name: .debug_info
+# CHECK:  Data:  (
+#
+#  Addends: Zero Positive Negative Overflow Out-of-range
+#    04030201 D6FF D5FF FF7F
+# CHECK-NEXT: : 2A00 2E030201  D5FF FF7F
+# CHECK-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_REL
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+  - Name:.debug_info
+Type:SHT_PROGBITS
+Content: 04030201D6FFD57F
+  - Name:.rel.debug_info
+Type:SHT_REL
+Info:.debug_info
+Relocations:
+  - Offset:  0x0
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x4
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x8
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0xC
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x10
+Symbol:  bar
+Type:R_ARM_ABS32
+Symbols:
+  - Name:.debug_info
+Type:STT_SECTION
+Section: .debug_info
+  - Name:foo
+Type:STT_FUNC
+Section: .debug_info
+Value:   0x002A
+  - Name:bar
+Type:STT_FUNC
+Section: .debug_info
+Value:   0xFF00
+...
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2637,6 +2637,43 @@
   }
 }
 
+static void ApplyELF32ABS32RelRelocation(Symtab *symtab, ELFRelocation &rel,
+ DataExtractor &debug_data,
+ Section *rel_section) {
+  Log *log = GetLog(LLDBLog::Modules);
+  Symbol *symbol = symtab->FindSymbolByID(ELFRelocation::RelocSymbol32(rel));
+  if (symbol) {
+addr_t value = symbol->GetAddressRef().GetFileAddress();
+if (value == LLDB_INVALID_ADDRESS) {
+  const char *name = symbol->GetName().GetCString();
+  LLDB_LOGF(log, "Debug info symbol invalid: %s", name);
+  return;
+}
+assert(llvm::isUInt<32>(value) && "Valid addresses are 32-bit");
+DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+WritableDataBuffer *data_buffer =
+llvm::cast(data_buffer_sp.get());
+uint8_t *dst = data_buffer->GetBytes() + rel_section->GetFileOffset() +
+   ELFRelocation::RelocOffset32(rel);
+// Implicit addend is stored inline as a signed value.
+int32_t addend = *reinterpret_cast(dst);
+// The sum must be positive. This extra check prevents UB from overflow in
+// the actual range check below.
+if (addend < 0 && static_cast(std::abs(addend)) > value) {
+  LLDB_LOGF(log, "Debug info relocation overflow: 0x%" PRIx64,
+static_cast(value) + addend);
+  return;
+}
+if (!llvm::isUInt<32>(value + addend)) {
+  LLDB_LOGF(log, "Debug info relocation out of range: 0x%" PRIx64, value);
+  return;
+}
+uint32_t addr = value + addend;
+memcpy(dst, &addr, sizeof(uint32_t));
+  }
+}
+
 unsigned ObjectFileELF::ApplyRelocations(
 Symtab *symtab, const ELFHeader *hdr, const ELFSectionHeader *rel_hdr,
 const ELFSectionHeader *symtab_hdr, const ELFSectionHeader *debug_hdr,
@@ -2667,6 +2704,15 @@
 
 if (hdr->Is32Bit()) {
  

[Lldb-commits] [PATCH] D147669: PECOFF: enforce move semantics and consume errors properly

2023-04-06 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz requested changes to this revision.
sgraenitz added a comment.
This revision now requires changes to proceed.

First of all, yes the existing code is incorrect. Thanks for looking into this. 
However, I am afraid this isn't the right solution.

In the `if` body you can not `std::move()` from `err` twice. I guess we have to 
do something like:

  if (log)
LLDB_LOG(...)
  else
consumeError(...)



> which resulted in a check failure under LLVM_ENABLE_ABI_BREAKING_CHANGES

You probably mean `LLVM_ENABLE_ABI_BREAKING_CHECKS`? For `Error` this enables 
logic to make sure the error was checked: 
https://github.com/llvm/llvm-project/blob/release/16.x/llvm/include/llvm/Support/Error.h#L724
 I think your observation is a side effect of the issue you look at and has 
nothing to do with compiler optimizations like NRVO. If logging is off, the 
error isn't consumed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147669

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


[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-05 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 511155.
sgraenitz added a comment.

Second try for the out-of-range test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147642

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml

Index: lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
===
--- /dev/null
+++ lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
@@ -0,0 +1,62 @@
+# RUN: yaml2obj %s -o %t
+# RUN: lldb-test object-file -contents %t | FileCheck %s
+
+## Test that R_ARM_ABS32 relocations are resolved in .debug_info sections on aarch32.
+## REL-type relocations store implicit addend as signed values inline.
+## We relocate the symbol foo with 4 different addends and bar once in the .debug_info section.
+## Results that exceed the 32-bit range or overflow are logged and ignored.
+
+# CHECK:  Name: .debug_info
+# CHECK:  Data:  (
+#
+#  Addends: Zero Positive Negative Overflow Out-of-range
+#    04030201 D6FF D5FF FF7F
+# CHECK-NEXT: : 2A00 2E030201  D5FF FF7F
+# CHECK-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_REL
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+  - Name:.debug_info
+Type:SHT_PROGBITS
+Content: 04030201D6FFD57F
+  - Name:.rel.debug_info
+Type:SHT_REL
+Info:.debug_info
+Relocations:
+  - Offset:  0x0
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x4
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x8
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0xC
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x10
+Symbol:  bar
+Type:R_ARM_ABS32
+Symbols:
+  - Name:.debug_info
+Type:STT_SECTION
+Section: .debug_info
+  - Name:foo
+Type:STT_FUNC
+Section: .debug_info
+Value:   0x002A
+  - Name:bar
+Type:STT_FUNC
+Section: .debug_info
+Value:   0xFF00
+...
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2637,6 +2637,43 @@
   }
 }
 
+static void ApplyELF32ABS32Relocation(Symtab *symtab, ELFRelocation &rel,
+  DataExtractor &debug_data,
+  Section *rel_section) {
+  Log *log = GetLog(LLDBLog::Modules);
+  Symbol *symbol = symtab->FindSymbolByID(ELFRelocation::RelocSymbol32(rel));
+  if (symbol) {
+addr_t value = symbol->GetAddressRef().GetFileAddress();
+if (value == LLDB_INVALID_ADDRESS) {
+  const char *name = symbol->GetName().GetCString();
+  LLDB_LOGF(log, "Debug info symbol invalid: %s", name);
+  return;
+}
+assert(llvm::isUInt<32>(value) && "Valid addresses are 32-bit");
+DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+WritableDataBuffer *data_buffer =
+llvm::cast(data_buffer_sp.get());
+uint8_t *dst = data_buffer->GetBytes() + rel_section->GetFileOffset() +
+   ELFRelocation::RelocOffset32(rel);
+// Implicit addend is stored inline as a signed value.
+int32_t addend = *reinterpret_cast(dst);
+// The sum must be positive. This extra check prevents UB from overflow in
+// the actual range check below.
+if (addend < 0 && static_cast(std::abs(addend)) > value) {
+  LLDB_LOGF(log, "Debug info relocation overflow: 0x%" PRIx64,
+static_cast(value) + addend);
+  return;
+}
+if (!llvm::isUInt<32>(value + addend)) {
+  LLDB_LOGF(log, "Debug info relocation out of range: 0x%" PRIx64, value);
+  return;
+}
+uint32_t addr = value + addend;
+memcpy(dst, &addr, sizeof(uint32_t));
+  }
+}
+
 unsigned ObjectFileELF::ApplyRelocations(
 Symtab *symtab, const ELFHeader *hdr, const ELFSectionHeader *rel_hdr,
 const ELFSectionHeader *symtab_hdr, const ELFSectionHeader *debug_hdr,
@@ -2667,6 +2704,15 @@
 
 if (hdr->Is32Bit()) {
   switch (hdr->e_machine) {
+  case llvm::ELF::EM_ARM:
+switc

[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-05 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 511151.
sgraenitz added a comment.

Add the missing 5th relocation to the test that exercises the out-of-range case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147642

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml

Index: lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
===
--- /dev/null
+++ lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
@@ -0,0 +1,58 @@
+# RUN: yaml2obj %s -o %t
+# RUN: lldb-test object-file -contents %t | FileCheck %s
+
+## Test that R_ARM_ABS32 relocations are resolved in .debug_info sections on aarch32.
+## We relocate the symbol foo with 5 different addends in the .debug_info section.
+## REL-type relocations store implicit addend as signed values inline.
+## Results that exceed the 32-bit range or overflow are logged and ignored.
+
+# CHECK:  Name: .debug_info
+# CHECK:  Data:  (
+#
+#  Addends: Zero Positive Negative Overflow Out-of-range
+#    04030201 D6FF D5FF FF7F
+# CHECK-NEXT: : 2A00 2E030201  D5FF FF7F
+# CHECK-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_REL
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+  - Name:.debug_info
+Type:SHT_PROGBITS
+Content: 04030201D6FFD57F
+  - Name:.rel.debug_info
+Type:SHT_REL
+Info:.debug_info
+Relocations:
+  - Offset:  0x0
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x4
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x8
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0xC
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x10
+Symbol:  foo
+Type:R_ARM_ABS32
+Symbols:
+  - Name:.debug_info
+Type:STT_SECTION
+Section: .debug_info
+  - Name:foo
+Type:STT_FUNC
+Section: .debug_info
+Value:   0x002A
+...
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2637,6 +2637,43 @@
   }
 }
 
+static void ApplyELF32ABS32Relocation(Symtab *symtab, ELFRelocation &rel,
+  DataExtractor &debug_data,
+  Section *rel_section) {
+  Log *log = GetLog(LLDBLog::Modules);
+  Symbol *symbol = symtab->FindSymbolByID(ELFRelocation::RelocSymbol32(rel));
+  if (symbol) {
+addr_t value = symbol->GetAddressRef().GetFileAddress();
+if (value == LLDB_INVALID_ADDRESS) {
+  const char *name = symbol->GetName().GetCString();
+  LLDB_LOGF(log, "Debug info symbol invalid: %s", name);
+  return;
+}
+assert(llvm::isUInt<32>(value) && "Valid addresses are 32-bit");
+DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+WritableDataBuffer *data_buffer =
+llvm::cast(data_buffer_sp.get());
+uint8_t *dst = data_buffer->GetBytes() + rel_section->GetFileOffset() +
+   ELFRelocation::RelocOffset32(rel);
+// Implicit addend is stored inline as a signed value.
+int32_t addend = *reinterpret_cast(dst);
+// The sum must be positive. This extra check prevents UB from overflow in
+// the actual range check below.
+if (addend < 0 && static_cast(std::abs(addend)) > value) {
+  LLDB_LOGF(log, "Debug info relocation overflow: 0x%" PRIx64,
+static_cast(value) + addend);
+  return;
+}
+if (!llvm::isUInt<32>(value + addend)) {
+  LLDB_LOGF(log, "Debug info relocation out of range: 0x%" PRIx64, value);
+  return;
+}
+uint32_t addr = value + addend;
+memcpy(dst, &addr, sizeof(uint32_t));
+  }
+}
+
 unsigned ObjectFileELF::ApplyRelocations(
 Symtab *symtab, const ELFHeader *hdr, const ELFSectionHeader *rel_hdr,
 const ELFSectionHeader *symtab_hdr, const ELFSectionHeader *debug_hdr,
@@ -2667,6 +2704,15 @@
 
 if (hdr->Is32Bit()) {
   switch (hdr->e_machine) {
+  case llvm::ELF::EM_ARM:
+switch (reloc_type(rel)) {
+case R_ARM_ABS32:
+  ApplyELF32ABS32Relocation(symtab, 

[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-05 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Adding an abstraction for reading implicit addend or somehow integrate it into 
`ELFRelocation::RelocAddend32()` might be more confusing for the reader than 
keeping it in the function inline. What do you think?




Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2660
+// Implicit addend is stored inline as a signed value.
+int32_t addend = *reinterpret_cast(dst);
+// The sum must be positive. This extra check prevents UB from overflow in

IIUC we'd want to account for an endianness difference between debugger and 
target (in theory). However, non of the other cases seems to do it, so I didn't 
start with it either.



Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2711
+  ApplyELF32ABS32Relocation(symtab, rel, debug_data, rel_section);
+  break;
+default:

In think debug info relocations have been `R_ARM_ABS32` in all  ARM/Thumb, 
pic/non-pic variations I tried. @peter.smith Does that hold in general? 
Otherwise, I'd like to report errors for the other cases and not let them run 
into the assert(false) below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147642

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


[Lldb-commits] [PATCH] D147627: [lldb][ObjectFileELF] Improve error output for unsupported arch/relocations

2023-04-05 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

This would be good to land in preparation for D147642 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147627

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


[Lldb-commits] [PATCH] D147642: [lldb][ObjectFileELF] Support AArch32 in ApplyRelocations

2023-04-05 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: DavidSpickett, peter.smith, labath, davide.
Herald added subscribers: omjavaid, kristof.beyls, emaste.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLDB.

Allow the ObjectFileELF plugin to resolve R_ARM_ABS32 relocations from AArch32 
object files. This fixes https://github.com/llvm/llvm-project/issues/61948

The existing architectures work with RELA-type relocation records that read 
addend from the relocation entry. REL-type relocations in AArch32 store addend 
in-place.
The new function doesn't re-use ELFRelocation::RelocAddend32(), because the 
interface doesn't match: in addition to the relocation entry we need the actual 
target section memory.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147642

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml

Index: lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
===
--- /dev/null
+++ lldb/test/Shell/ObjectFile/ELF/aarch32-relocations.yaml
@@ -0,0 +1,55 @@
+# RUN: yaml2obj %s -o %t
+# RUN: lldb-test object-file -contents %t | FileCheck %s
+
+## Test that R_ARM_ABS32 relocations are resolved in .debug_info sections on aarch32.
+## We relocate the symbol foo with 4 different addends in the .debug_info section.
+## REL-type relocations store implicit addend as signed values inline.
+## Results that exceed the 32-bit range or overflow are logged and ignored.
+
+# CHECK:  Name: .debug_info
+# CHECK:  Data:  (
+#
+#  Addends: Zero Positive Negative Overflow Out-of-range
+#    04030201 D6FF D5FF FF7F
+# CHECK-NEXT: : 2A00 2E030201  D5FF FF7F
+# CHECK-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_REL
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+  - Name:.debug_info
+Type:SHT_PROGBITS
+Content: 04030201D6FFD57F
+  - Name:.rel.debug_info
+Type:SHT_REL
+Info:.debug_info
+Relocations:
+  - Offset:  0x0
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x4
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0x8
+Symbol:  foo
+Type:R_ARM_ABS32
+  - Offset:  0xC
+Symbol:  foo
+Type:R_ARM_ABS32
+Symbols:
+  - Name:.debug_info
+Type:STT_SECTION
+Section: .debug_info
+  - Name:foo
+Type:STT_FUNC
+Section: .debug_info
+Value:   0x002A
+...
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2637,6 +2637,43 @@
   }
 }
 
+static void ApplyELF32ABS32Relocation(Symtab *symtab, ELFRelocation &rel,
+  DataExtractor &debug_data,
+  Section *rel_section) {
+  Log *log = GetLog(LLDBLog::Modules);
+  Symbol *symbol = symtab->FindSymbolByID(ELFRelocation::RelocSymbol32(rel));
+  if (symbol) {
+addr_t value = symbol->GetAddressRef().GetFileAddress();
+if (value == LLDB_INVALID_ADDRESS) {
+  const char *name = symbol->GetName().GetCString();
+  LLDB_LOGF(log, "Debug info symbol invalid: %s", name);
+  return;
+}
+assert(llvm::isUInt<32>(value) && "Valid addresses are 32-bit");
+DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+WritableDataBuffer *data_buffer =
+llvm::cast(data_buffer_sp.get());
+uint8_t *dst = data_buffer->GetBytes() + rel_section->GetFileOffset() +
+   ELFRelocation::RelocOffset32(rel);
+// Implicit addend is stored inline as a signed value.
+int32_t addend = *reinterpret_cast(dst);
+// The sum must be positive. This extra check prevents UB from overflow in
+// the actual range check below.
+if (addend < 0 && static_cast(std::abs(addend)) > value) {
+  LLDB_LOGF(log, "Debug info relocation overflow: 0x%" PRIx64,
+static_cast(value) + addend);
+  return;
+}
+if (!llvm::isUInt<32>(value + addend)) {
+  LLDB_LOGF(log, "Debug info relocation out of range: 0x%" PRIx64, value);
+  return;
+}
+uint32_t addr = va

[Lldb-commits] [PATCH] D147627: [lldb][ObjectFileELF] Improve error output for unsupported arch/relocations

2023-04-05 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: DavidSpickett, SixWeining.
Herald added a subscriber: emaste.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLDB.

ObjectFileELF::ApplyRelocations() considered all 32-bit input objects to be 
i386 and didn't provide good error messages for AArch32 objects. Please find an 
example in https://github.com/llvm/llvm-project/issues/61948
While we are here, let' improve the situation for unsupported architectures as 
well. I think we should report the error here too and not silently fail (or 
crash with assertions enabled).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147627

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp


Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2666,38 +2666,48 @@
 Symbol *symbol = nullptr;
 
 if (hdr->Is32Bit()) {
-  switch (reloc_type(rel)) {
-  case R_386_32:
-symbol = symtab->FindSymbolByID(reloc_symbol(rel));
-if (symbol) {
-  addr_t f_offset =
-  rel_section->GetFileOffset() + ELFRelocation::RelocOffset32(rel);
-  DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
-  // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
-  WritableDataBuffer *data_buffer =
-  llvm::cast(data_buffer_sp.get());
-  uint32_t *dst = reinterpret_cast(
-  data_buffer->GetBytes() + f_offset);
-
-  addr_t value = symbol->GetAddressRef().GetFileAddress();
-  if (rel.IsRela()) {
-value += ELFRelocation::RelocAddend32(rel);
+  switch (hdr->e_machine) {
+  case llvm::ELF::EM_386:
+switch (reloc_type(rel)) {
+case R_386_32:
+  symbol = symtab->FindSymbolByID(reloc_symbol(rel));
+  if (symbol) {
+addr_t f_offset =
+rel_section->GetFileOffset() + 
ELFRelocation::RelocOffset32(rel);
+DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
+// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
+WritableDataBuffer *data_buffer =
+llvm::cast(data_buffer_sp.get());
+uint32_t *dst = reinterpret_cast(
+data_buffer->GetBytes() + f_offset);
+
+addr_t value = symbol->GetAddressRef().GetFileAddress();
+if (rel.IsRela()) {
+  value += ELFRelocation::RelocAddend32(rel);
+} else {
+  value += *dst;
+}
+*dst = value;
   } else {
-value += *dst;
+GetModule()->ReportError(".rel{0}[{1}] unknown symbol id: {2:d}",
+rel_section->GetName().AsCString(), i,
+reloc_symbol(rel));
   }
-  *dst = value;
-} else {
-  GetModule()->ReportError(".rel{0}[{1}] unknown symbol id: {2:d}",
+  break;
+case R_386_PC32:
+  GetModule()->ReportError("unsupported i386 relocation:"
+   " .rel{0}[{1}], type {2}",
rel_section->GetName().AsCString(), i,
-   reloc_symbol(rel));
+   reloc_type(rel));
+  break;
+default:
+  assert(false && "unexpected relocation type");
+  break;
 }
 break;
-  case R_386_PC32:
   default:
-GetModule()->ReportError("unsupported 32-bit relocation:"
- " .rel{0}[{1}], type {2}",
- rel_section->GetName().AsCString(), i,
- reloc_type(rel));
+GetModule()->ReportError("unsupported 32-bit ELF machine arch: {0}", 
hdr->e_machine);
+break;
   }
 } else {
   switch (hdr->e_machine) {
@@ -2743,7 +2753,8 @@
 }
 break;
   default:
-assert(false && "unsupported machine");
+GetModule()->ReportError("unsupported 64-bit ELF machine arch: {0}", 
hdr->e_machine);
+break;
   }
 }
   }


Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2666,38 +2666,48 @@
 Symbol *symbol = nullptr;
 
 if (hdr->Is32Bit()) {
-  switch (reloc_type(rel)) {
-  case R_386_32:
-symbol = symtab->FindSymbolByID(reloc_symbol(rel));
-if (symbol) {
-  addr_t f_offset =
-  rel_section->GetFileOffset() + ELFRelocation::RelocOffset32(r

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-04-04 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

The modified proposal keeps GNUstep support off by default (even if installed). 
It must be enabled explicitly by passing `-DLLDB_TEST_OBJC_GNUSTEP=On` and it 
can be disabled easily by passing `-DLLDB_TEST_OBJC_GNUSTEP=Off` to CMake. A 
custom install location `/path/to/lib/libobjc.so` can be specified with 
`-DLLDB_TEST_OBJC_GNUSTEP_DIR=/path/to`. Since it involves some extra logic, I 
moved the standard bits into `FindGNUstepObjC.cmake` which should follow 
regular CMake naming conventions (`GNUstepObjC_DIR`, `GNUstepObjC_FOUND`, 
etc.). This might be the foundation for a future GNUstep standard package file.

This version aims to cause minimal friction while allowing to test with GNUstep 
for those who wish. Please find setup instructions in my previous comment 
. If you have any more questions, 
please let me know.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-04-04 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 510732.
sgraenitz added a comment.

Split config in two parts: On/Off and DIR
Move standard find library logic into FindGNUstepObjC.cmake


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

Files:
  lldb/cmake/modules/FindGNUstepObjC.cmake
  lldb/test/CMakeLists.txt
  lldb/test/Shell/Expr/objc-gnustep-print.m
  lldb/test/Shell/helper/build.py
  lldb/test/Shell/helper/toolchain.py
  lldb/test/Shell/lit.cfg.py
  lldb/test/Shell/lit.site.cfg.py.in

Index: lldb/test/Shell/lit.site.cfg.py.in
===
--- lldb/test/Shell/lit.site.cfg.py.in
+++ lldb/test/Shell/lit.site.cfg.py.in
@@ -16,6 +16,7 @@
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.objc_gnustep_dir = "@LLDB_TEST_OBJC_GNUSTEP_DIR@"
 config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
Index: lldb/test/Shell/lit.cfg.py
===
--- lldb/test/Shell/lit.cfg.py
+++ lldb/test/Shell/lit.cfg.py
@@ -24,7 +24,7 @@
 
 # suffixes: A list of file extensions to treat as test files. This is overriden
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
 # subdirectories contain auxiliary inputs for various tests in their parent
@@ -135,6 +135,14 @@
 if config.have_lldb_server:
 config.available_features.add('lldb-server')
 
+if config.objc_gnustep_dir:
+config.available_features.add('objc-gnustep')
+if platform.system() == 'Windows':
+# objc.dll must be in PATH since Windows has no rpath
+config.environment['PATH'] = os.path.pathsep.join((
+os.path.join(config.objc_gnustep_dir, 'lib'),
+config.environment.get('PATH','')))
+
 # NetBSD permits setting dbregs either if one is root
 # or if user_set_dbregs is enabled
 can_set_dbregs = True
Index: lldb/test/Shell/helper/toolchain.py
===
--- lldb/test/Shell/helper/toolchain.py
+++ lldb/test/Shell/helper/toolchain.py
@@ -42,6 +42,8 @@
 build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
 if config.llvm_libs_dir:
 build_script_args.append('--libs-dir={0}'.format(config.llvm_libs_dir))
+if config.objc_gnustep_dir:
+build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 
 lldb_init = _get_lldb_init_path(config)
 
Index: lldb/test/Shell/helper/build.py
===
--- lldb/test/Shell/helper/build.py
+++ lldb/test/Shell/helper/build.py
@@ -49,6 +49,18 @@
 action='append',
 help='If specified, a path to search in addition to PATH when --compiler is not an exact path')
 
+parser.add_argument('--objc-gnustep-dir',
+metavar='directory',
+dest='objc_gnustep_dir',
+required=False,
+help='If specified, a path to GNUstep libobjc2 runtime for use on Windows and Linux')
+
+parser.add_argument('--objc-gnustep',
+dest='objc_gnustep',
+action='store_true',
+default=False,
+help='Include and link GNUstep libobjc2 (Windows and Linux only)')
+
 if sys.platform == 'darwin':
 parser.add_argument('--apple-sdk',
 metavar='apple_sdk',
@@ -238,6 +250,10 @@
 self.obj_ext = obj_ext
 self.lib_paths = args.libs_dir
 self.std = args.std
+assert not args.objc_gnustep or args.objc_gnustep_dir, \
+   "--objc-gnustep specified without path to libobjc2"
+self.objc_gnustep_inc = os.path.join(args.objc_gnustep_dir, 'include') if args.objc_gnustep_dir else None
+self.objc_gnustep_lib = os.path.join(args.objc_gnustep_dir, 'lib') if args.objc_gnustep_dir else None
 
 def _exe_file_name(self):
 assert self.mode != 'compile'
@@ -656,15 +672,20 @@
 args.append('-static')
 args.append('-c')
 
-args.extend(['-o', obj])
-args.append(source)
-
 if sys.platform == 'darwin':
 args.extend(['-isysroot', self.apple_sdk])
+elif self.objc_gnustep_inc:
+if source.endswith('.m') or source.endswith('.mm'):
+args.extend(['-fobjc-runtime=gnustep-2.0', '-I', self.objc_gnustep_inc])
+if sys.platform == "win32":
+args.extend(['-Xclang', '-gcodeview', '-Xclang', '--dependent-lib=msvcrtd'])
 
 if

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-27 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

In D146058#4223575 , @labath wrote:

> What kind of setup is necessary to make that work? If it's not too 
> complicated, I think we could make something work.

Thanks, that'd be awesome!

The last official release is from 2020, so for the time being it seems best to 
build and install from TOT once -- @theraven please correct me if I am wrong:

  > git clone https://github.com/gnustep/libobjc2
  > cd libobjc2
  > git submodule init && git submodule update
  > CC=clang-15 CXX=clang++-15 cmake -Bbuild -GNinja -DTESTS=On .
  > cd build
  > ninja
  ...
  > ctest
  ...
  100% tests passed, 0 tests failed out of 198
  > ninja install
  ...
  -- Installing: /usr/local/lib/libobjc.so.4.6
  -- Installing: /usr/local/lib/libobjc.so
  ...

Then apply this patch and re-run CMake. The new test should popup and pass:

  > arc patch D146058
  > cd build && cmake .
  ...
  -- Found GNUstep ObjC runtime: /usr/local/lib/libobjc.so
  ...
  > bin/llvm-lit --filter=objc-gnustep -vv tools/lldb/test
  -- Testing: 1 of 1979 tests, 1 workers --
  PASS: lldb-shell :: Expr/objc-gnustep-print.m (1 of 1)
  
  Testing Time: 2.06s
Excluded: 1583
Passed  :1



> Speaking generally, my only concern with that is the that the bot doesn't 
> remain broken (or even worse -- flaky!) for long stretches of time. I don't 
> have time to debug objc failures, and reverting other people's changes 
> because they break something that might be an "experimental" feature for 
> quite some time could be problematic.

Absolutely. What do you think is the best way to prevent that?

Right now, the `gnustep` test would run whenever `libobjc.so` was found. A lit 
config reset like this would make it `UNSUPPORTED` (but it gets wiped with the 
next CMake run):

  > grep objc_gnustep_dir build/tools/lldb/test/Shell/lit.site.cfg.py 
  config.objc_gnustep_dir = ""

How can I change this to support the well-behaved bot? Add 
`-DLLDB_TEST_OBJC_GNUSTEP=Off`? Or should it be off by default and enabled on 
demand?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-23 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Is there any more feedback on this patch? After all, this adds test coverage 
for existing functionality (with the new GNUstep runtime plugin from D146154 
 that is ready to land).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146536: SymbolFile: ensure that we have a value before invoking `getBitWidth`

2023-03-22 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz accepted this revision.
sgraenitz added a comment.
This revision is now accepted and ready to land.

Perfect, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146536

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


[Lldb-commits] [PATCH] D146541: [lldb][expr] Propagate ClangDynamicCheckerFunctions::Install() errors to caller

2023-03-21 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG32baf5c1c29b: [lldb][expr] Propagate 
ClangDynamicCheckerFunctions::Install() errors to caller (authored by 
sgraenitz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146541

Files:
  lldb/include/lldb/Expression/DynamicCheckerFunctions.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
  lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h

Index: lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h
===
--- lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h
+++ lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h
@@ -46,10 +46,10 @@
   /// The execution context to install the functions into.
   ///
   /// \return
-  /// True on success; false on failure, or if the functions have
-  /// already been installed.
-  bool Install(DiagnosticManager &diagnostic_manager,
-   ExecutionContext &exe_ctx) override;
+  /// Either llvm::ErrorSuccess or Error with llvm::ErrorInfo
+  ///
+  llvm::Error Install(DiagnosticManager &diagnostic_manager,
+  ExecutionContext &exe_ctx) override;
 
   bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message) override;
 
Index: lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
@@ -47,33 +47,30 @@
 
 ClangDynamicCheckerFunctions::~ClangDynamicCheckerFunctions() = default;
 
-bool ClangDynamicCheckerFunctions::Install(
+llvm::Error ClangDynamicCheckerFunctions::Install(
 DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) {
-  auto utility_fn_or_error = exe_ctx.GetTargetRef().CreateUtilityFunction(
-  g_valid_pointer_check_text, VALID_POINTER_CHECK_NAME,
-  lldb::eLanguageTypeC, exe_ctx);
-  if (!utility_fn_or_error) {
-llvm::consumeError(utility_fn_or_error.takeError());
-return false;
-  }
-  m_valid_pointer_check = std::move(*utility_fn_or_error);
+  Expected> utility_fn =
+  exe_ctx.GetTargetRef().CreateUtilityFunction(
+  g_valid_pointer_check_text, VALID_POINTER_CHECK_NAME,
+  lldb::eLanguageTypeC, exe_ctx);
+  if (!utility_fn)
+return utility_fn.takeError();
+  m_valid_pointer_check = std::move(*utility_fn);
 
   if (Process *process = exe_ctx.GetProcessPtr()) {
 ObjCLanguageRuntime *objc_language_runtime =
 ObjCLanguageRuntime::Get(*process);
 
 if (objc_language_runtime) {
-  auto utility_fn_or_error = objc_language_runtime->CreateObjectChecker(
-  VALID_OBJC_OBJECT_CHECK_NAME, exe_ctx);
-  if (!utility_fn_or_error) {
-llvm::consumeError(utility_fn_or_error.takeError());
-return false;
-  }
-  m_objc_object_check = std::move(*utility_fn_or_error);
+  Expected> checker_fn =
+  objc_language_runtime->CreateObjectChecker(VALID_OBJC_OBJECT_CHECK_NAME, exe_ctx);
+  if (!checker_fn)
+return checker_fn.takeError();
+  m_objc_object_check = std::move(*checker_fn);
 }
   }
 
-  return true;
+  return Error::success();
 }
 
 bool ClangDynamicCheckerFunctions::DoCheckersExplainStop(lldb::addr_t addr,
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -1403,14 +1403,12 @@
   ClangDynamicCheckerFunctions *dynamic_checkers =
   new ClangDynamicCheckerFunctions();
 
-  DiagnosticManager install_diagnostics;
-
-  if (!dynamic_checkers->Install(install_diagnostics, exe_ctx)) {
-if (install_diagnostics.Diagnostics().size())
-  err.SetErrorString(install_diagnostics.GetString().c_str());
-else
-  err.SetErrorString("couldn't install checkers, unknown error");
-
+  DiagnosticManager install_diags;
+  if (Error Err = dynamic_checkers->Install(install_diags, exe_ctx)) {
+std::string ErrMsg = "couldn't install checkers: " + toString(std::move(Err));
+if (install_diags.Diagnostics().size())
+  ErrMsg = ErrMsg + "\n" + install_diags.GetString().c_str();
+err.SetErrorString(ErrMsg);
 return err;
   }
 
Index: lldb/include/lldb/Expression/DynamicCheckerFunctions.h
===
--- lldb/include/lldb/Expression/DynamicCheckerFunctions.h
+++ lldb/include/lldb/Expression/DynamicChecke

[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-03-21 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Thanks for reviewing! I will land this as soon as the previous review is ready.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

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


[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-03-21 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 507054.
sgraenitz marked an inline comment as done.
sgraenitz added a comment.

Make shared library name checks OS-dependent


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/CMakeLists.txt
  lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/CMakeLists.txt
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
  lldb/test/Shell/Expr/objc-gnustep-print.m

Index: lldb/test/Shell/Expr/objc-gnustep-print.m
===
--- lldb/test/Shell/Expr/objc-gnustep-print.m
+++ lldb/test/Shell/Expr/objc-gnustep-print.m
@@ -27,23 +27,39 @@
 }
 @end
 
-@interface TestObj : NSObject {}
-- (int)ok;
+@interface TestObj : NSObject {
+  int _int;
+  float _float;
+  char _char;
+  void *_ptr_void;
+  NSObject *_ptr_nsobject;
+  id _id_objc;
+}
+- (void)check_ivars_zeroed;
+- (void)set_ivars;
 @end
 @implementation TestObj
-- (int)ok {
-  return self ? 0 : 1;
+- (void)check_ivars_zeroed {
+  ;
+}
+- (void)set_ivars {
+  _int = 1;
+  _float = 2.0f;
+  _char = '\3';
+  _ptr_void = (void*)4;
+  _ptr_nsobject = (NSObject*)5;
+  _id_objc = (id)6;
 }
 @end
 
-// RUN: %lldb -b -o "b objc-gnustep-print.m:35" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
+// RUN: %lldb -b -o "b objc-gnustep-print.m:43" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
 //
-// SELF: (lldb) b objc-gnustep-print.m:35
+// SELF: (lldb) b objc-gnustep-print.m:43
 // SELF: Breakpoint {{.*}} at objc-gnustep-print.m
 //
 // SELF: (lldb) run
 // SELF: Process {{[0-9]+}} stopped
-// SELF: -[TestObj ok](self=[[SELF_PTR:0x[0-9]+]]{{.*}}) at objc-gnustep-print.m:35
+// SELF: -[TestObj check_ivars_zeroed](self=[[SELF_PTR:0x[0-9]+]]{{.*}}) at objc-gnustep-print.m
 //
 // SELF: (lldb) p self
 // SELF: (TestObj *) $0 = [[SELF_PTR]]
@@ -54,9 +70,38 @@
 // SELF: isa
 // SELF: refcount
 // SELF:   }
+// SELF:   _int = 0
+// SELF:   _float = 0
+// SELF:   _char = '\0'
+// SELF:   _ptr_void = 0x{{0*}}
+// SELF:   _ptr_nsobject = nil
+// SELF:   _id_objc = nil
 // SELF: }
 
+// RUN: %lldb -b -o "b objc-gnustep-print.m:106" -o "run" -o "p t->_int" -o "p t->_float" -o "p t->_char" \
+// RUN:  -o "p t->_ptr_void" -o "p t->_ptr_nsobject" -o "p t->_id_objc" -- %t | FileCheck %s --check-prefix=IVARS_SET
+//
+// IVARS_SET: (lldb) p t->_int
+// IVARS_SET: (int) $0 = 1
+//
+// IVARS_SET: (lldb) p t->_float
+// IVARS_SET: (float) $1 = 2
+//
+// IVARS_SET: (lldb) p t->_char
+// IVARS_SET: (char) $2 = '\x03'
+//
+// IVARS_SET: (lldb) p t->_ptr_void
+// IVARS_SET: (void *) $3 = 0x{{0*}}4
+//
+// IVARS_SET: (lldb) p t->_ptr_nsobject
+// IVARS_SET: (NSObject *) $4 = 0x{{0*}}5
+//
+// IVARS_SET: (lldb) p t->_id_objc
+// IVARS_SET: (id) $5 = 0x{{0*}}6
+
 int main() {
   TestObj *t = [TestObj new];
-  return [t ok];
+  [t check_ivars_zeroed];
+  [t set_ivars];
+  return 0;
 }
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -38,7 +38,8 @@
   enum class ObjCRuntimeVersions {
 eObjC_VersionUnknown = 0,
 eAppleObjC_V1 = 1,
-eAppleObjC_V2 = 2
+eAppleObjC_V2 = 2,
+eGNUstep_libobjc2 = 3,
   };
 
   typedef lldb::addr_t ObjCISA;
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
@@ -235,6 +235,22 @@
   m_isa_to_descriptor.begin(), m_isa_to_descriptor.end());
 }
 
+void ObjCLanguageRuntime::ReadObjCLibraryIfNeeded(
+const ModuleList &module_list) {
+  if (!HasReadObjCLibrary()) {
+std::lock_guard guard(module_list.GetMutex());
+
+size_t num_modules = module_list.GetSize();
+for (size_t i = 0; i < num_modules; i++) {
+  auto mod = module_list.GetModuleAtIndex(i);
+  if (IsModuleObjCLibrary(mod)) {
+ReadObjCLibrary(mod);
+break;
+  }
+}
+  }
+}
+
 ObjCLanguageRuntime::ObjCISA
 ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) {
   ClassDescriptorSP objc_class_sp(GetClassDescriptorFromISA(isa));
Index: lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
===

[Lldb-commits] [PATCH] D146541: [lldb][expr] Propagate ClangDynamicCheckerFunctions::Install() errors to caller

2023-03-21 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Thanks for the quick replies!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146541

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


[Lldb-commits] [PATCH] D146547: [lldb][gnustep][PDB] Add special handling for ObjC built-in types eBasicTypeObjCID and eBasicTypeObjCSel

2023-03-21 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: aleksandr.urakov, rnk, teemperor, DavidSpickett, 
aprantl, zturner, jdoerfert.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a project: LLDB.

Let the PDB parser recognize special ObjC type names like `objc_object` for the 
id type and `objc_selector` for selectors. With this change, ObjC support for 
PDB on Windows is on par with the Linux baseline test proposed in D146058 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146547

Files:
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
  lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
  lldb/test/Shell/Expr/objc-gnustep-print.m

Index: lldb/test/Shell/Expr/objc-gnustep-print.m
===
--- lldb/test/Shell/Expr/objc-gnustep-print.m
+++ lldb/test/Shell/Expr/objc-gnustep-print.m
@@ -1,5 +1,4 @@
 // REQUIRES: objc-gnustep
-// XFAIL: system-windows
 //
 // RUN: %build %s --compiler=clang --objc-gnustep --output=%t
 
Index: lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
===
--- lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
+++ /dev/null
@@ -1,73 +0,0 @@
-// REQUIRES: objc-gnustep && system-windows
-//
-// RUN: %build %s --compiler=clang --objc-gnustep --output=%t
-
-#import "objc/runtime.h"
-
-@protocol NSCoding
-@end
-
-#ifdef __has_attribute
-#if __has_attribute(objc_root_class)
-__attribute__((objc_root_class))
-#endif
-#endif
-@interface NSObject {
-  id isa;
-  int refcount;
-}
-@end
-@implementation NSObject
-- (id)class {
-  return object_getClass(self);
-}
-+ (id)new {
-  return class_createInstance(self, 0);
-}
-@end
-@interface TestObj : NSObject {
-  int _int;
-  float _float;
-  char _char;
-  void *_ptr_void;
-  NSObject *_ptr_nsobject;
-  id _id_objc;
-}
-- (int)ok;
-@end
-@implementation TestObj
-- (int)ok {
-  return self ? 0 : 1;
-}
-@end
-
-// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:72" -o "run" -o "p ptr" -o "p *ptr" -- %t | FileCheck %s
-//
-// CHECK: (lldb) b objc-gnustep-print-pdb.m:72
-// CHECK: Breakpoint {{.*}} at objc-gnustep-print-pdb.m:72
-//
-// CHECK: (lldb) run
-// CHECK: Process {{[0-9]+}} stopped
-// CHECK: frame #0: {{.*}}`main  at objc-gnustep-print-pdb.m:72
-//
-// CHECK: (lldb) p ptr
-// CHECK: (TestObj *) $0 = 0x{{[0-9]+}}
-//
-// CHECK: (lldb) p *ptr
-// CHECK: (TestObj) $1 = {
-// CHECK:   NSObject = {
-// CHECK: isa = 0x{{[0-9]+}}
-// CHECK: refcount
-// CHECK:   }
-// CHECK:   _int = 0
-// CHECK:   _float = 0
-// CHECK:   _char = '\0'
-// CHECK:   _ptr_void = 0x{{0+}}
-// CHECK:   _ptr_nsobject = nil
-// CHECK:   _id_objc = nil
-// CHECK: }
-
-int main() {
-  TestObj *ptr = [TestObj new];
-  return [ptr ok];
-}
Index: lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
===
--- lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
+++ lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
@@ -170,6 +170,8 @@
   void DumpClangAST(lldb_private::Stream &s) override;
 
   bool IsaNSObjectOrNSProxy(const llvm::pdb::PDBSymbolTypeUDT &udt) const;
+  bool IsObjCBuiltinTypeId(lldb::user_id_t sym_uid) const;
+  bool IsObjCBuiltinTypeSel(lldb::user_id_t sym_uid) const;
 
 private:
   struct SecContribInfo {
Index: lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
===
--- lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -2097,3 +2097,31 @@
   auto *pdb_base_udt = llvm::dyn_cast(pdb_base_raw_up.get());
   return IsaNSObjectOrNSProxy(*pdb_base_udt);
 }
+
+bool SymbolFilePDB::IsObjCBuiltinTypeId(user_id_t sym_uid) const {
+  std::unique_ptr pdb_sym_up = m_session_up->getSymbolById(sym_uid);
+  if (pdb_sym_up->getSymTag() != PDB_SymType::UDT)
+return false;
+
+  auto *pdb_sym_udt = llvm::dyn_cast(pdb_sym_up.get());
+  if (pdb_sym_udt->getName() != "id" &&
+  pdb_sym_udt->getName() != "objc_object")
+return false;
+
+  return true;
+}
+
+bool SymbolFilePDB::IsObjCBuiltinTypeSel(user_id_t sym_uid) const {
+  std::unique_ptr pdb_sym_up = m_session_up->getSymbolById(sym_uid);
+  if (pdb_sym_up->getSymTag() != PDB_SymType::UDT)
+return false;
+
+  auto *pdb_sym_udt = llvm::dyn_cast(pdb_sym_up.get());
+  if (pdb_sym_udt->getName() != "objc_selector")
+return false;
+
+  // TODO: ObjC selectors exist only for ObjC functions and they never occur
+  // freestanding. Thus, we know that all instances of this UDT are defined
+  // within ObjCInterfaceDecls. Can we add a check for that?
+  return true;
+}
Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===
--- lldb/source/Plugins/

[Lldb-commits] [PATCH] D146541: [lldb][expr] Propagate ClangDynamicCheckerFunctions::Install() errors to caller

2023-03-21 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: teemperor, bulbazord, JDevlieghere.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: LLDB.

I came accross this, because a lot of regression tests were saying:

  (lldb) p argc
  error: expression failed to parse:
  error: couldn't install checkers, unknown error

With this change, error messages provide more detail:

  (lldb) p argc
  error: expression failed to parse:
  error: couldn't install checkers:
  error: Couldn't lookup symbols:
__objc_load

I didn't find a case where `Diagnostics()` is not empty. Also it looks like 
this isn't covered in any test (yet).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146541

Files:
  lldb/include/lldb/Expression/DynamicCheckerFunctions.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
  lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h

Index: lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h
===
--- lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h
+++ lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h
@@ -46,10 +46,10 @@
   /// The execution context to install the functions into.
   ///
   /// \return
-  /// True on success; false on failure, or if the functions have
-  /// already been installed.
-  bool Install(DiagnosticManager &diagnostic_manager,
-   ExecutionContext &exe_ctx) override;
+  /// Either llvm::ErrorSuccess or Error with llvm::ErrorInfo
+  ///
+  llvm::Error Install(DiagnosticManager &diagnostic_manager,
+  ExecutionContext &exe_ctx) override;
 
   bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message) override;
 
Index: lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
@@ -47,33 +47,30 @@
 
 ClangDynamicCheckerFunctions::~ClangDynamicCheckerFunctions() = default;
 
-bool ClangDynamicCheckerFunctions::Install(
+llvm::Error ClangDynamicCheckerFunctions::Install(
 DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) {
-  auto utility_fn_or_error = exe_ctx.GetTargetRef().CreateUtilityFunction(
-  g_valid_pointer_check_text, VALID_POINTER_CHECK_NAME,
-  lldb::eLanguageTypeC, exe_ctx);
-  if (!utility_fn_or_error) {
-llvm::consumeError(utility_fn_or_error.takeError());
-return false;
-  }
-  m_valid_pointer_check = std::move(*utility_fn_or_error);
+  Expected> utility_fn =
+  exe_ctx.GetTargetRef().CreateUtilityFunction(
+  g_valid_pointer_check_text, VALID_POINTER_CHECK_NAME,
+  lldb::eLanguageTypeC, exe_ctx);
+  if (!utility_fn)
+return utility_fn.takeError();
+  m_valid_pointer_check = std::move(*utility_fn);
 
   if (Process *process = exe_ctx.GetProcessPtr()) {
 ObjCLanguageRuntime *objc_language_runtime =
 ObjCLanguageRuntime::Get(*process);
 
 if (objc_language_runtime) {
-  auto utility_fn_or_error = objc_language_runtime->CreateObjectChecker(
-  VALID_OBJC_OBJECT_CHECK_NAME, exe_ctx);
-  if (!utility_fn_or_error) {
-llvm::consumeError(utility_fn_or_error.takeError());
-return false;
-  }
-  m_objc_object_check = std::move(*utility_fn_or_error);
+  Expected> checker_fn =
+  objc_language_runtime->CreateObjectChecker(VALID_OBJC_OBJECT_CHECK_NAME, exe_ctx);
+  if (!checker_fn)
+return checker_fn.takeError();
+  m_objc_object_check = std::move(*checker_fn);
 }
   }
 
-  return true;
+  return Error::success();
 }
 
 bool ClangDynamicCheckerFunctions::DoCheckersExplainStop(lldb::addr_t addr,
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -1410,14 +1410,12 @@
   ClangDynamicCheckerFunctions *dynamic_checkers =
   new ClangDynamicCheckerFunctions();
 
-  DiagnosticManager install_diagnostics;
-
-  if (!dynamic_checkers->Install(install_diagnostics, exe_ctx)) {
-if (install_diagnostics.Diagnostics().size())
-  err.SetErrorString(install_diagnostics.GetString().c_str());
-else
-  err.SetErrorString("couldn't install checkers, unknown error");
-
+  DiagnosticManager install_diags;
+  if (Error Err = dynamic_checkers->Install(install_diags, exe_ctx)) {
+std::string ErrMsg = "c

[Lldb-commits] [PATCH] D146536: SymbolFile: ensure that we have a value before invoking `getBitWidth`

2023-03-21 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Thanks for tackling this! Yes, I hit it as well during development and wondered 
what is the right thing to do. The effect of the proposed change will be log 
messages like this right?

  ... which resolves to a constant value of mismatched width (-1 bits). 
Ignoring constant.

I think it would be great to log the actual issue (constant width not 
accessible) and bail out if `value.Type == llvm::pdb::Empty`. Even before 
requesting `qual_type`. What do you think?




Comment at: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp:1307
+unsigned constant_width =
+value.Type == llvm::pdb::Empty ? - 1 : value.getBitWidth();
 

Is the `-1` intended to express an invalid value? Maybe this should become a 
signed `int` then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146536

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


[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-03-21 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

In D146154#4203277 , @aprantl wrote:

> Here is an example of how the Swift Runtime plugin detects both itself and 
> whether ObjC interop is enabled. Basically all I'm asking is to not 
> accidentally break this mechanism.

Thanks for the link! I think Swift is doing the exact right thing here: it 
requests the Apple ObjC V2 runtime explicitly in 
https://github.com/apple/llvm-project/blob/fcf8f57c74defcc0c422331cb90a3b9dd8d7b476/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp#L102-L106

Anyway, I updated my patch to do the symbol lookup, because the pure presence 
of an ObjC runtime makes for some interesting regressions in the test suite. 
E.g. here we enable ObjC in C++ code 

 if the runtime exists:

  lang_opts.ObjC =
  process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC) != nullptr;




Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp:62
+images.FindSymbolsWithNameAndType(ConstString("__objc_load"),
+  eSymbolTypeCode, objc_mandatory);
+if (objc_mandatory.GetSize() == 0)

There is no EH personality on Windows so I am checking for a core ObjC runtime 
symbol. Hope that's ok?
I put a list with all DLL symbols here: 
https://gist.github.com/weliveindetail/0c57135741b314d2952236bcffae0ab1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

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


[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-03-21 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 506989.
sgraenitz added a comment.

Check for GNUstep EH personality in ELF targets and `__objc_load` on native 
Windows


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/CMakeLists.txt
  lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/CMakeLists.txt
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
  lldb/test/Shell/Expr/objc-gnustep-print.m

Index: lldb/test/Shell/Expr/objc-gnustep-print.m
===
--- lldb/test/Shell/Expr/objc-gnustep-print.m
+++ lldb/test/Shell/Expr/objc-gnustep-print.m
@@ -27,23 +27,39 @@
 }
 @end
 
-@interface TestObj : NSObject {}
-- (int)ok;
+@interface TestObj : NSObject {
+  int _int;
+  float _float;
+  char _char;
+  void *_ptr_void;
+  NSObject *_ptr_nsobject;
+  id _id_objc;
+}
+- (void)check_ivars_zeroed;
+- (void)set_ivars;
 @end
 @implementation TestObj
-- (int)ok {
-  return self ? 0 : 1;
+- (void)check_ivars_zeroed {
+  ;
+}
+- (void)set_ivars {
+  _int = 1;
+  _float = 2.0f;
+  _char = '\3';
+  _ptr_void = (void*)4;
+  _ptr_nsobject = (NSObject*)5;
+  _id_objc = (id)6;
 }
 @end
 
-// RUN: %lldb -b -o "b objc-gnustep-print.m:35" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
+// RUN: %lldb -b -o "b objc-gnustep-print.m:43" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
 //
-// SELF: (lldb) b objc-gnustep-print.m:35
+// SELF: (lldb) b objc-gnustep-print.m:43
 // SELF: Breakpoint {{.*}} at objc-gnustep-print.m
 //
 // SELF: (lldb) run
 // SELF: Process {{[0-9]+}} stopped
-// SELF: -[TestObj ok](self=[[SELF_PTR:0x[0-9]+]]{{.*}}) at objc-gnustep-print.m:35
+// SELF: -[TestObj check_ivars_zeroed](self=[[SELF_PTR:0x[0-9]+]]{{.*}}) at objc-gnustep-print.m
 //
 // SELF: (lldb) p self
 // SELF: (TestObj *) $0 = [[SELF_PTR]]
@@ -54,9 +70,38 @@
 // SELF: isa
 // SELF: refcount
 // SELF:   }
+// SELF:   _int = 0
+// SELF:   _float = 0
+// SELF:   _char = '\0'
+// SELF:   _ptr_void = 0x{{0*}}
+// SELF:   _ptr_nsobject = nil
+// SELF:   _id_objc = nil
 // SELF: }
 
+// RUN: %lldb -b -o "b objc-gnustep-print.m:106" -o "run" -o "p t->_int" -o "p t->_float" -o "p t->_char" \
+// RUN:  -o "p t->_ptr_void" -o "p t->_ptr_nsobject" -o "p t->_id_objc" -- %t | FileCheck %s --check-prefix=IVARS_SET
+//
+// IVARS_SET: (lldb) p t->_int
+// IVARS_SET: (int) $0 = 1
+//
+// IVARS_SET: (lldb) p t->_float
+// IVARS_SET: (float) $1 = 2
+//
+// IVARS_SET: (lldb) p t->_char
+// IVARS_SET: (char) $2 = '\x03'
+//
+// IVARS_SET: (lldb) p t->_ptr_void
+// IVARS_SET: (void *) $3 = 0x{{0*}}4
+//
+// IVARS_SET: (lldb) p t->_ptr_nsobject
+// IVARS_SET: (NSObject *) $4 = 0x{{0*}}5
+//
+// IVARS_SET: (lldb) p t->_id_objc
+// IVARS_SET: (id) $5 = 0x{{0*}}6
+
 int main() {
   TestObj *t = [TestObj new];
-  return [t ok];
+  [t check_ivars_zeroed];
+  [t set_ivars];
+  return 0;
 }
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -38,7 +38,8 @@
   enum class ObjCRuntimeVersions {
 eObjC_VersionUnknown = 0,
 eAppleObjC_V1 = 1,
-eAppleObjC_V2 = 2
+eAppleObjC_V2 = 2,
+eGNUstep_libobjc2 = 3,
   };
 
   typedef lldb::addr_t ObjCISA;
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
@@ -235,6 +235,22 @@
   m_isa_to_descriptor.begin(), m_isa_to_descriptor.end());
 }
 
+void ObjCLanguageRuntime::ReadObjCLibraryIfNeeded(
+const ModuleList &module_list) {
+  if (!HasReadObjCLibrary()) {
+std::lock_guard guard(module_list.GetMutex());
+
+size_t num_modules = module_list.GetSize();
+for (size_t i = 0; i < num_modules; i++) {
+  auto mod = module_list.GetModuleAtIndex(i);
+  if (IsModuleObjCLibrary(mod)) {
+ReadObjCLibrary(mod);
+break;
+  }
+}
+  }
+}
+
 ObjCLanguageRuntime::ObjCISA
 ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) {
   ClassDescriptorSP objc_class_sp(GetClassDescriptorFromISA(isa));
Index: lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
===
---

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-21 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

I think this is ready to land, but I will leave it here for a few more days to 
allow for further questions.




Comment at: lldb/test/Shell/helper/toolchain.py:46
+if config.objc_gnustep_dir:
+
build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 

bulbazord wrote:
> sgraenitz wrote:
> > bulbazord wrote:
> > > Why does {0} need quotes around it but the args above it don't?
> > Good catch! That's due to spaces in Windows paths...
> In that case, do we also need to add quotes around the other paths? Seems 
> like we're assuming that on windows those directories cannot have spaces in 
> them. (Not suggesting you need to do that here and now, just wondering for 
> the future)
I'd like to keep it as proposed here: I added the quotes since the default 
install path for gnustep libobjc2 was under `Program Files` for me. The other 
paths refer to subfolders in the build directory and apparently it hasn't been 
a problem. I guess no-one selects a path with spaces to build LLDB. That makes 
sense to me.

I wouldn't propose to add precautionary quotes around these paths. If you wish 
to do that, please post a review and discuss it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146221: [CodeView] Add source languages ObjC and ObjC++

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGef006eb0bc5e: [CodeView] Add source languages ObjC and 
ObjC++ (authored by sgraenitz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146221

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  llvm/include/llvm/DebugInfo/CodeView/CodeView.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/DebugInfo/CodeView/EnumTables.cpp
  llvm/lib/DebugInfo/PDB/PDBExtras.cpp
  llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp
  llvm/test/DebugInfo/COFF/language.ll
  llvm/test/DebugInfo/COFF/objc.ll
  llvm/test/DebugInfo/COFF/objcpp.ll
  llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp

Index: llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
===
--- llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
+++ llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
@@ -210,6 +210,8 @@
 RETURN_CASE(SourceLanguage, D, "d");
 RETURN_CASE(SourceLanguage, Swift, "swift");
 RETURN_CASE(SourceLanguage, Rust, "rust");
+RETURN_CASE(SourceLanguage, ObjC, "objc");
+RETURN_CASE(SourceLanguage, ObjCpp, "objc++");
   }
   return formatUnknownEnum(Lang);
 }
Index: llvm/test/DebugInfo/COFF/objcpp.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/objcpp.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=ASM
+; RUN: llc -filetype=obj < %s | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
+
+; ASM:  .short  4412# Record kind: S_COMPILE3
+; ASM-NEXT: .long   18  # Flags and language
+
+; OBJ:   Kind: S_COMPILE3 (0x113C)
+; OBJ-NEXT:  Language: ObjCpp (0x12)
+
+; ModuleID = 'objcpp.mm'
+source_filename = "objcpp.mm"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; Function Attrs: uwtable
+define void @"?f@@YAXXZ"() #0 !dbg !5 {
+entry:
+  ret void, !dbg !9
+}
+
+attributes #0 = { uwtable "target-cpu"="x86-64" }
+
+!llvm.module.flags = !{!0, !1, !2}
+!llvm.dbg.cu = !{!3}
+
+!0 = !{i32 8, !"PIC Level", i32 2}
+!1 = !{i32 2, !"CodeView", i32 1}
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = distinct !DICompileUnit(language: DW_LANG_ObjC_plus_plus, file: !4, producer: "clang version 17.0.0 (https://github.com/llvm/llvm-project a8e9beca6bee1f248ef4be7892802c4d091b7fcb)", isOptimized: false, runtimeVersion: 1, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!4 = !DIFile(filename: "objcpp.mm", directory: "src", checksumkind: CSK_MD5, checksum: "e6ab1d5b7f82464c963a8522037dfa72")
+!5 = distinct !DISubprogram(name: "f", linkageName: "?f@@YAXXZ", scope: !4, file: !4, line: 1, type: !6, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !3, retainedNodes: !8)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = !{}
+!9 = !DILocation(line: 1, scope: !5)
Index: llvm/test/DebugInfo/COFF/objc.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/objc.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=ASM
+; RUN: llc -filetype=obj < %s | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
+
+; ASM:  .short  4412# Record kind: S_COMPILE3
+; ASM-NEXT: .long   17  # Flags and language
+
+; OBJ:   Kind: S_COMPILE3 (0x113C)
+; OBJ-NEXT:  Language: ObjC (0x11)
+
+; ModuleID = 'objc.m'
+source_filename = "objc.m"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; Function Attrs: uwtable
+define void @f() unnamed_addr #0 !dbg !5 {
+entry:
+  ret void, !dbg !9
+}
+
+attributes #0 = { uwtable "target-cpu"="x86-64" }
+
+!llvm.module.flags = !{!0, !1, !2}
+!llvm.dbg.cu = !{!3}
+
+!0 = !{i32 8, !"PIC Level", i32 2}
+!1 = !{i32 2, !"CodeView", i32 1}
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !4, producer: "clang version 17.0.0 (https://github.com/llvm/llvm-project a8e9beca6bee1f248ef4be7892802c4d091b7fcb)", isOptimized: false, runtimeVersion: 1, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!4 = !DIFile(filename: "objc.m", directory: "src", checksumkind: CSK_MD5, checksum: "e6ab1d5b7f82464c963a8522037dfa72")
+!5 = distinct !DISubprogram(name: "f", scope: !4, file: !4, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !3, retainedNodes: !8)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = !{}
+!9 = !DILocation(line: 1, scope: !5)
Index: llvm/test/DebugInfo/COFF/language.ll
=

[Lldb-commits] [PATCH] D146221: [CodeView] Add source languages ObjC and ObjC++

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added inline comments.



Comment at: llvm/test/DebugInfo/COFF/objc.ll:4-6
+; ASM:  .short  4412# Record kind: S_COMPILE3
+; ASM-NEXT: .long   17  # Flags and language
+; ASM-NEXT: .short  208 # CPUType

DavidSpickett wrote:
> DavidSpickett wrote:
> > sgraenitz wrote:
> > > DavidSpickett wrote:
> > > > Are these checked, should they be?
> > > Thanks for taking a look! What we check here is the `17` in language 
> > > flags. The rest is just to make sure we get the right context. (Same for 
> > > the others.) Is that your question?
> > Right but I don't know what that adds once you get beyond the Language 
> > line. It's a small thing, so that the test doesn't fail if a new key is 
> > added.
> Ignore the previous comment, wrong line.
> 
> So yes you can check these, but no one actually does. If you look at the 
> filecheck line it only does OBJ.
> 
> Same for the rust change you linked. Unless there is some implicit behaviour 
> here. One way to find out, put a bogus value in there and it should fail.
The first RUN line will exercise the ASM checks:
```
; RUN: llc < %s | FileCheck %s --check-prefix=ASM
```



Comment at: llvm/test/DebugInfo/COFF/objc.ll:11-17
+; OBJ-NEXT:Flags [ (0x0)
+; OBJ-NEXT:]
+; OBJ-NEXT:Machine: X64 (0xD0)
+; OBJ-NEXT:FrontendVersion: {{[0-9\.]*}}
+; OBJ-NEXT:BackendVersion: {{[0-9\.]*}}
+; OBJ-NEXT:VersionName: clang version 17.0.0 
(https://github.com/llvm/llvm-project a8e9beca6bee1f248ef4be7892802c4d091b7fcb)
+; OBJ-NEXT:  }

DavidSpickett wrote:
> DavidSpickett wrote:
> > Do we need to check for these lines? Just the first few should be fine.
> So here it's fine to check up to language, mostly, but after that what does 
> it matter? If someone adds a new key the test breaks.
> 
> (and granted, it won't happen often if at all but the general principle holds)
Ok, fair enough. Cut it down.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146221

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


[Lldb-commits] [PATCH] D146221: [CodeView] Add source languages ObjC and ObjC++

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 506100.
sgraenitz marked 7 inline comments as done.
sgraenitz added a comment.

Cut down check-lines


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146221

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  llvm/include/llvm/DebugInfo/CodeView/CodeView.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/DebugInfo/CodeView/EnumTables.cpp
  llvm/lib/DebugInfo/PDB/PDBExtras.cpp
  llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp
  llvm/test/DebugInfo/COFF/language.ll
  llvm/test/DebugInfo/COFF/objc.ll
  llvm/test/DebugInfo/COFF/objcpp.ll
  llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp

Index: llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
===
--- llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
+++ llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
@@ -210,6 +210,8 @@
 RETURN_CASE(SourceLanguage, D, "d");
 RETURN_CASE(SourceLanguage, Swift, "swift");
 RETURN_CASE(SourceLanguage, Rust, "rust");
+RETURN_CASE(SourceLanguage, ObjC, "objc");
+RETURN_CASE(SourceLanguage, ObjCpp, "objc++");
   }
   return formatUnknownEnum(Lang);
 }
Index: llvm/test/DebugInfo/COFF/objcpp.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/objcpp.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=ASM
+; RUN: llc -filetype=obj < %s | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
+
+; ASM:  .short  4412# Record kind: S_COMPILE3
+; ASM-NEXT: .long   18  # Flags and language
+
+; OBJ:   Kind: S_COMPILE3 (0x113C)
+; OBJ-NEXT:  Language: ObjCpp (0x12)
+
+; ModuleID = 'objcpp.mm'
+source_filename = "objcpp.mm"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; Function Attrs: uwtable
+define void @"?f@@YAXXZ"() #0 !dbg !5 {
+entry:
+  ret void, !dbg !9
+}
+
+attributes #0 = { uwtable "target-cpu"="x86-64" }
+
+!llvm.module.flags = !{!0, !1, !2}
+!llvm.dbg.cu = !{!3}
+
+!0 = !{i32 8, !"PIC Level", i32 2}
+!1 = !{i32 2, !"CodeView", i32 1}
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = distinct !DICompileUnit(language: DW_LANG_ObjC_plus_plus, file: !4, producer: "clang version 17.0.0 (https://github.com/llvm/llvm-project a8e9beca6bee1f248ef4be7892802c4d091b7fcb)", isOptimized: false, runtimeVersion: 1, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!4 = !DIFile(filename: "objcpp.mm", directory: "src", checksumkind: CSK_MD5, checksum: "e6ab1d5b7f82464c963a8522037dfa72")
+!5 = distinct !DISubprogram(name: "f", linkageName: "?f@@YAXXZ", scope: !4, file: !4, line: 1, type: !6, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !3, retainedNodes: !8)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = !{}
+!9 = !DILocation(line: 1, scope: !5)
Index: llvm/test/DebugInfo/COFF/objc.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/objc.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=ASM
+; RUN: llc -filetype=obj < %s | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
+
+; ASM:  .short  4412# Record kind: S_COMPILE3
+; ASM-NEXT: .long   17  # Flags and language
+
+; OBJ:   Kind: S_COMPILE3 (0x113C)
+; OBJ-NEXT:  Language: ObjC (0x11)
+
+; ModuleID = 'objc.m'
+source_filename = "objc.m"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; Function Attrs: uwtable
+define void @f() unnamed_addr #0 !dbg !5 {
+entry:
+  ret void, !dbg !9
+}
+
+attributes #0 = { uwtable "target-cpu"="x86-64" }
+
+!llvm.module.flags = !{!0, !1, !2}
+!llvm.dbg.cu = !{!3}
+
+!0 = !{i32 8, !"PIC Level", i32 2}
+!1 = !{i32 2, !"CodeView", i32 1}
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !4, producer: "clang version 17.0.0 (https://github.com/llvm/llvm-project a8e9beca6bee1f248ef4be7892802c4d091b7fcb)", isOptimized: false, runtimeVersion: 1, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!4 = !DIFile(filename: "objc.m", directory: "src", checksumkind: CSK_MD5, checksum: "e6ab1d5b7f82464c963a8522037dfa72")
+!5 = distinct !DISubprogram(name: "f", scope: !4, file: !4, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !3, retainedNodes: !8)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = !{}
+!9 = !DILocation(line: 1, scope: !5)
Index: llvm/test/DebugInfo/COFF/language.ll
===
--- llvm/test/DebugInfo/COFF/languag

[Lldb-commits] [PATCH] D146297: [lldb][gnustep][PDB] Parse ObjC base classes and recognize NSObject type

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

In D146297#4202172 , @DavidSpickett 
wrote:

> I don't know anything about Objective C internals, perhaps you can provide 
> some reference that talks about this?

Honestly, I am mostly looking what the DWARF parser does and try to mimic it in 
PDB. I haven't done much research for a formal reference. My impression is that 
the implementation is the reference here. (Please correct me if I am wrong!)

Yeah, let's wait and see if I get feedback from ObjC and PDB maintainers.




Comment at: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp:349
+static bool IsSpecialNameObjC(llvm::StringRef name) {
+  return name == "objc_object" || name == "objc_class";
+}

Maybe this is ok without a dedicated language type check? IIUC the worst thing 
that could happen, in case we really have zero-length types with such names in 
C++ code, is a small performance drop.

BTW the reference for this seems to be: 
https://github.com/llvm/llvm-project/blob/release/16.x/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp#L709-L710
 😄



Comment at: lldb/test/Shell/Expr/objc-gnustep-print-pdb.m:44
 
-// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:67" -o "run" -o "p ptr" -o "p 
*ptr" -- %t | FileCheck %s
+// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:72" -o "run" -o "p ptr" -o "p 
*ptr" -- %t | FileCheck %s
 //

DavidSpickett wrote:
> Could you use label in the source so you don't have to update this line 
> number each each time?
> 
> I forget if labels are included in the debug info. In the python tests we 
> have this more heavyweight thing that searches for a particular comment to 
> find the line.
It's a minor effort on my side to update the line number and it's solid. We 
cannot break on `ok`, since the function name doesn't get parsed with a correct 
basename yet. Main would work, but it doesn't seem more readable:
```
-o "b main" -o "n" -o "n"
```

> In the python tests we have this more heavyweight thing that searches for a 
> particular comment to find the line.

If possible I'd like to stay away from the Python tests. I don't think we need 
their advanced features. lit is a lot easier for me (and more widespread in 
LLVM).



Comment at: lldb/test/Shell/Expr/objc-gnustep-print-pdb.m:68
+// CHECK:   _id_objc = nil
 // CHECK: }
 

With this change we get base class and the member offsets right (all are 
zero-initialized).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146297

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


[Lldb-commits] [PATCH] D146221: [CodeView] Add source languages ObjC and ObjC++

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Maybe I should have noted immediately, that this is mostly following the change 
for Rust from https://reviews.llvm.org/D115300




Comment at: llvm/include/llvm/DebugInfo/CodeView/CodeView.h:142
+/// These values correspond to the CV_CFL_LANG enumeration in the Microsoft
+/// Debug Interface Access SDK
 enum SourceLanguage : uint8_t {

DavidSpickett wrote:
> Could put the same link from the commit message, here. 
I though about it, but such links will inevitably break again one day and/or 
lead to outdated information. The old link was very unfortunate. Web search for 
`CV_CFL_LANG Microsoft Debug Interface Access SDK` seems more stable. What do 
you think?



Comment at: llvm/test/DebugInfo/COFF/objc.ll:4-6
+; ASM:  .short  4412# Record kind: S_COMPILE3
+; ASM-NEXT: .long   17  # Flags and language
+; ASM-NEXT: .short  208 # CPUType

DavidSpickett wrote:
> Are these checked, should they be?
Thanks for taking a look! What we check here is the `17` in language flags. The 
rest is just to make sure we get the right context. (Same for the others.) Is 
that your question?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146221

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


[Lldb-commits] [PATCH] D146297: [lldb][gnustep][PDB] Parse ObjC base classes and recognize NSObject type

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: aleksandr.urakov, rnk, teemperor, DavidSpickett, 
aprantl, zturner.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: jplehr, sstefan1.
Herald added a project: LLDB.

While C++ base classes are registered with CreateBaseClassSpecifier(), we have 
to use SetObjCSuperClass() for ObjC. The isa member of NSObject is a 
zero-length UDT. Special handling for ObjC id type will be added in one of the 
next patches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146297

Files:
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/test/Shell/Expr/objc-gnustep-print-pdb.m


Index: lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
===
--- lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
+++ lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
@@ -41,26 +41,30 @@
 }
 @end
 
-// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:67" -o "run" -o "p ptr" -o "p 
*ptr" -- %t | FileCheck %s
+// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:72" -o "run" -o "p ptr" -o "p 
*ptr" -- %t | FileCheck %s
 //
-// CHECK: (lldb) b objc-gnustep-print-pdb.m:67
-// CHECK: Breakpoint {{.*}} at objc-gnustep-print-pdb.m:67
+// CHECK: (lldb) b objc-gnustep-print-pdb.m:72
+// CHECK: Breakpoint {{.*}} at objc-gnustep-print-pdb.m:72
 //
 // CHECK: (lldb) run
 // CHECK: Process {{[0-9]+}} stopped
-// CHECK: frame #0: {{.*}}`main  at objc-gnustep-print-pdb.m:67
+// CHECK: frame #0: {{.*}}`main  at objc-gnustep-print-pdb.m:72
 //
 // CHECK: (lldb) p ptr
 // CHECK: (TestObj *) $0 = 0x{{[0-9]+}}
 //
 // CHECK: (lldb) p *ptr
 // CHECK: (TestObj) $1 = {
-// CHECK:   _int
-// CHECK:   _float
-// CHECK:   _char
-// CHECK:   _ptr_void
-// CHECK:   _ptr_nsobject
-// CHECK:   _id_objc
+// CHECK:   NSObject = {
+// CHECK: isa = 0x{{[0-9]+}}
+// CHECK: refcount
+// CHECK:   }
+// CHECK:   _int = 0
+// CHECK:   _float = 0
+// CHECK:   _char = '\0'
+// CHECK:   _ptr_void = 0x{{0+}}
+// CHECK:   _ptr_nsobject = nil
+// CHECK:   _id_objc = nil
 // CHECK: }
 
 int main() {
Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===
--- lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -345,6 +345,10 @@
   return name == "`anonymous namespace'" || name == "`anonymous-namespace'";
 }
 
+static bool IsSpecialNameObjC(llvm::StringRef name) {
+  return name == "objc_object" || name == "objc_class";
+}
+
 static clang::CallingConv TranslateCallingConvention(PDB_CallingConv pdb_cc) {
   switch (pdb_cc) {
   case llvm::codeview::CallingConvention::NearC:
@@ -393,16 +397,16 @@
 //union Union { short Row; short Col; }
 // Such symbols will be handled here.
 
-// Some UDT with trival ctor has zero length. Just ignore.
-if (udt->getLength() == 0)
-  return nullptr;
-
 // Ignore unnamed-tag UDTs.
 std::string name =
 std::string(MSVCUndecoratedNameParser::DropScope(udt->getName()));
 if (name.empty())
   return nullptr;
 
+// Some UDT with trival ctor has zero length. Just ignore.
+if (udt->getLength() == 0 && !IsSpecialNameObjC(name))
+  return nullptr;
+
 auto decl_context = GetDeclContextContainingSymbol(type);
 
 // PDB has no attribute to encode the language per symbol. We assume
@@ -1406,6 +1410,12 @@
 TypeSystemClang::CompleteTagDeclarationDefinition(base_comp_type);
 }
 
+if (TypeSystemClang::IsObjCObjectOrInterfaceType(base_comp_type)) {
+  m_ast.SetObjCSuperClass(record_type, base_comp_type);
+  assert(bases_enum.getNext() == nullptr && "Single inheritance only");
+  return;
+}
+
 auto access = TranslateMemberAccess(base->getAccess());
 
 auto is_virtual = base->isVirtualBaseClass();


Index: lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
===
--- lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
+++ lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
@@ -41,26 +41,30 @@
 }
 @end
 
-// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:67" -o "run" -o "p ptr" -o "p *ptr" -- %t | FileCheck %s
+// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:72" -o "run" -o "p ptr" -o "p *ptr" -- %t | FileCheck %s
 //
-// CHECK: (lldb) b objc-gnustep-print-pdb.m:67
-// CHECK: Breakpoint {{.*}} at objc-gnustep-print-pdb.m:67
+// CHECK: (lldb) b objc-gnustep-print-pdb.m:72
+// CHECK: Breakpoint {{.*}} at objc-gnustep-print-pdb.m:72
 //
 // CHECK: (lldb) run
 // CHECK: Process {{[0-9]+}} stopped
-// CHECK: frame #0: {{.*}}`main  at objc-gnustep-print-pdb.m:67
+// CHECK: frame #0: {{.*}}`main  at objc-gnustep-print-pdb.m:72
 //
 // CHECK: (lldb) p ptr
 // CHECK: (TestObj *) $0 = 0x{{[0-9]+}}
 //
 // CHECK: (lldb) p *ptr
 // CHECK: (TestObj) $1 = {
-// CHECK:   _int
-// CHECK:   _float
-// CHEC

[Lldb-commits] [PATCH] D146286: [lldb][PDB] Rename GetDeclarationForSymbol() -> AddSourceInfoToDecl()

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc9987f0ac81a: [lldb][PDB] Rename GetDeclarationForSymbol() 
-> AddSourceInfoToDecl() (authored by sgraenitz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146286

Files:
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp


Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===
--- lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -190,8 +190,7 @@
   return compiler_type.GetTypeName();
 }
 
-static bool GetDeclarationForSymbol(const PDBSymbol &symbol,
-Declaration &decl) {
+static bool AddSourceInfoToDecl(const PDBSymbol &symbol, Declaration &decl) {
   auto &raw_sym = symbol.getRawSymbol();
   auto first_line_up = raw_sym.getSrcLineOnTypeDefn();
 
@@ -464,7 +463,7 @@
 if (udt->isVolatileType())
   clang_type = clang_type.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), udt->getLength(), nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, clang_type,
@@ -533,7 +532,7 @@
 if (enum_type->isVolatileType())
   ast_enum = ast_enum.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), bytes, nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, ast_enum,
@@ -579,7 +578,7 @@
 if (type_def->isVolatileType())
   ast_typedef = ast_typedef.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 std::optional size;
 if (type_def->getLength())
   size = type_def->getLength();
@@ -659,7 +658,7 @@
 m_ast.CreateFunctionType(return_ast_type, arg_list.data(),
  arg_list.size(), is_variadic, type_quals, cc);
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), std::nullopt, nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,


Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===
--- lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -190,8 +190,7 @@
   return compiler_type.GetTypeName();
 }
 
-static bool GetDeclarationForSymbol(const PDBSymbol &symbol,
-Declaration &decl) {
+static bool AddSourceInfoToDecl(const PDBSymbol &symbol, Declaration &decl) {
   auto &raw_sym = symbol.getRawSymbol();
   auto first_line_up = raw_sym.getSrcLineOnTypeDefn();
 
@@ -464,7 +463,7 @@
 if (udt->isVolatileType())
   clang_type = clang_type.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), udt->getLength(), nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, clang_type,
@@ -533,7 +532,7 @@
 if (enum_type->isVolatileType())
   ast_enum = ast_enum.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), bytes, nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, ast_enum,
@@ -579,7 +578,7 @@
 if (type_def->isVolatileType())
   ast_typedef = ast_typedef.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 std::optional size;
 if (type_def->getLength())
   size = type_def->getLength();
@@ -659,7 +658,7 @@
 m_ast.CreateFunctionType(return_ast_type, arg_list.data(),
  arg_list.size(), is_variadic, type_quals, cc);
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), std::nullopt, nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D146286: [lldb][PDB] Rename GetDeclarationForSymbol() -> AddSourceInfoToDecl()

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Thanks for the quick response!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146286

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


[Lldb-commits] [PATCH] D146293: [lldb][gnustep][PDB] Recognize ObjC classes and start definition only once the complete type is requested

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

In order to run the test yourself locally, you also need to apply D146058 
, D146154  
and D146221  first (right now they are still 
in review).




Comment at: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp:414
+  lang = eLanguageTypeObjC;
+
 // Check if such an UDT already exists in the current context.

I am not an ObjC expert, but from those who are I know that in practice this 
should holds for all common scenarios. So far it works reliably.

Right now I'd like to avoid patching the PDB contents from the compiler side. 
Would be great to see how far we get without. If there's a better way to do the 
same based on current PDB info, please let me know.



Comment at: lldb/test/Shell/Expr/objc-gnustep-print-pdb.m:1
+// REQUIRES: objc-gnustep && system-windows
+//

This test is supposed to demonstrate what works with this patch. I will remove 
it once we match the features in the Linux/DWARF baseline proposed in: D146154 
test objc-gnustep-print.m


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146293

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


[Lldb-commits] [PATCH] D146293: [lldb][gnustep][PDB] Recognize ObjC classes and start definition only once the complete type is requested

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: aleksandr.urakov, rnk, aprantl, DavidSpickett, 
omjavaid, zturner, asmith.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a project: LLDB.

This patch allows the PDB parser to recognize UDT symbols as ObjCInterfaceDecls 
and delay the definition process until we resolve the complete compiler type. 
This corresponds to the approach in the DWARF parser: 
https://github.com/llvm/llvm-project/blob/release/16.x/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp#L1869-L1871

In order to cache forward declarations for both, CXXRecordDecl and 
ObjCInterfaceDecl, the map type is changed to store NamedDecls now (first 
common base). The test shows that we get the names of type and members for a 
simple ObjC class now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146293

Files:
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.h
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
  lldb/test/Shell/Expr/objc-gnustep-print-pdb.m

Index: lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
===
--- /dev/null
+++ lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
@@ -0,0 +1,69 @@
+// REQUIRES: objc-gnustep && system-windows
+//
+// RUN: %build %s --compiler=clang --objc-gnustep --output=%t
+
+#import "objc/runtime.h"
+
+@protocol NSCoding
+@end
+
+#ifdef __has_attribute
+#if __has_attribute(objc_root_class)
+__attribute__((objc_root_class))
+#endif
+#endif
+@interface NSObject {
+  id isa;
+  int refcount;
+}
+@end
+@implementation NSObject
+- (id)class {
+  return object_getClass(self);
+}
++ (id)new {
+  return class_createInstance(self, 0);
+}
+@end
+@interface TestObj : NSObject {
+  int _int;
+  float _float;
+  char _char;
+  void *_ptr_void;
+  NSObject *_ptr_nsobject;
+  id _id_objc;
+}
+- (int)ok;
+@end
+@implementation TestObj
+- (int)ok {
+  return self ? 0 : 1;
+}
+@end
+
+// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:67" -o "run" -o "p ptr" -o "p *ptr" -- %t | FileCheck %s
+//
+// CHECK: (lldb) b objc-gnustep-print-pdb.m:67
+// CHECK: Breakpoint {{.*}} at objc-gnustep-print-pdb.m:67
+//
+// CHECK: (lldb) run
+// CHECK: Process {{[0-9]+}} stopped
+// CHECK: frame #0: {{.*}}`main  at objc-gnustep-print-pdb.m:67
+//
+// CHECK: (lldb) p ptr
+// CHECK: (TestObj *) $0 = 0x{{[0-9]+}}
+//
+// CHECK: (lldb) p *ptr
+// CHECK: (TestObj) $1 = {
+// CHECK:   _int
+// CHECK:   _float
+// CHECK:   _char
+// CHECK:   _ptr_void
+// CHECK:   _ptr_nsobject
+// CHECK:   _id_objc
+// CHECK: }
+
+int main() {
+  TestObj *ptr = [TestObj new];
+  return [ptr ok];
+}
Index: lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
===
--- lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
+++ lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
@@ -169,6 +169,8 @@
 
   void DumpClangAST(lldb_private::Stream &s) override;
 
+  bool IsaNSObjectOrNSProxy(const llvm::pdb::PDBSymbolTypeUDT &udt) const;
+
 private:
   struct SecContribInfo {
 uint32_t Offset;
Index: lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
===
--- lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -46,6 +46,7 @@
 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
+#include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
@@ -2070,3 +2071,29 @@
 
   return 0;
 }
+
+bool SymbolFilePDB::IsaNSObjectOrNSProxy(
+const PDBSymbolTypeUDT &pdb_udt) const {
+  if (pdb_udt.getName() == "NSObject")
+return true;
+  if (pdb_udt.getName() == "NSProxy")
+return true;
+
+  auto bases_up = pdb_udt.findAllChildren();
+  std::unique_ptr pdb_base_up =
+  bases_up->getNext();
+  if (!pdb_base_up)
+return false; // No further bases classes (we assume it's C/C++)
+
+  if (bases_up->getNext())
+return false; // ObjC has single inheritance only (this must be C/C++)
+
+  user_id_t base_uid = pdb_base_up->getRawSymbol().getTypeId();
+  std::unique_ptr pdb_base_raw_up =
+  m_session_up->getSymbolById(base_uid);
+  if (pdb_base_raw_up->getSymTag() != PDB_SymType::UDT)
+return false; // Error: base class is not a user-defined type
+
+  auto *pdb_base_udt = llvm::dyn_cast(pdb_base_raw_up.get());
+  return IsaNSObjectOrNSProxy(*pdb_base_udt);
+}
Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.h
===
--- lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.h

[Lldb-commits] [PATCH] D146286: [lldb][PDB] Rename GetDeclarationForSymbol() -> AddSourceInfoToDecl()

2023-03-17 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: aleksandr.urakov, labath, rnk, asmith, zturner.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a project: LLDB.

The old name of this function was confusing for me, when I started working on 
the PDB parser. The new name clearifies that the function adds file, line and 
column (typically referred as source info) and indicates that the information 
is stored in the provided decl parameter.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146286

Files:
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp


Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===
--- lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -190,8 +190,7 @@
   return compiler_type.GetTypeName();
 }
 
-static bool GetDeclarationForSymbol(const PDBSymbol &symbol,
-Declaration &decl) {
+static bool AddSourceInfoToDecl(const PDBSymbol &symbol, Declaration &decl) {
   auto &raw_sym = symbol.getRawSymbol();
   auto first_line_up = raw_sym.getSrcLineOnTypeDefn();
 
@@ -464,7 +463,7 @@
 if (udt->isVolatileType())
   clang_type = clang_type.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), udt->getLength(), nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, clang_type,
@@ -533,7 +532,7 @@
 if (enum_type->isVolatileType())
   ast_enum = ast_enum.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), bytes, nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, ast_enum,
@@ -579,7 +578,7 @@
 if (type_def->isVolatileType())
   ast_typedef = ast_typedef.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 std::optional size;
 if (type_def->getLength())
   size = type_def->getLength();
@@ -659,7 +658,7 @@
 m_ast.CreateFunctionType(return_ast_type, arg_list.data(),
  arg_list.size(), is_variadic, type_quals, cc);
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), std::nullopt, nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,


Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===
--- lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -190,8 +190,7 @@
   return compiler_type.GetTypeName();
 }
 
-static bool GetDeclarationForSymbol(const PDBSymbol &symbol,
-Declaration &decl) {
+static bool AddSourceInfoToDecl(const PDBSymbol &symbol, Declaration &decl) {
   auto &raw_sym = symbol.getRawSymbol();
   auto first_line_up = raw_sym.getSrcLineOnTypeDefn();
 
@@ -464,7 +463,7 @@
 if (udt->isVolatileType())
   clang_type = clang_type.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), udt->getLength(), nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, clang_type,
@@ -533,7 +532,7 @@
 if (enum_type->isVolatileType())
   ast_enum = ast_enum.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), bytes, nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, ast_enum,
@@ -579,7 +578,7 @@
 if (type_def->isVolatileType())
   ast_typedef = ast_typedef.AddVolatileModifier();
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 std::optional size;
 if (type_def->getLength())
   size = type_def->getLength();
@@ -659,7 +658,7 @@
 m_ast.CreateFunctionType(return_ast_type, arg_list.data(),
  arg_list.size(), is_variadic, type_quals, cc);
 
-GetDeclarationForSymbol(type, decl);
+AddSourceInfoToDecl(type, decl);
 return m_ast.GetSymbolFile()->MakeType(
 type.getSymIndexId(), ConstString(name), std::nullopt, nullptr,
 LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D146221: [CodeView] Add source languages ObjC and ObjC++

2023-03-16 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: rnk, zturner, compnerd, aleksandr.urakov.
Herald added a subscriber: hiraditya.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added a subscriber: lldb-commits.

This patch adds llvm::codeview::SourceLanguage entries, DWARF translations, and 
PDB source file extensions in LLVM and allow LLDB's PDB parsers to recognize 
them correctly.

The CV_CFL_LANG enum in the Visual Studio 2022 documentation 
https://learn.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/cv-cfl-lang
 defines:

  CV_CFL_OBJC = 0x11,
  CV_CFL_OBJCXX   = 0x12,

Since the initial commit in D24317 , ObjC was 
emitted as C language and ObjC++ as Masm.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146221

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  llvm/include/llvm/DebugInfo/CodeView/CodeView.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/DebugInfo/CodeView/EnumTables.cpp
  llvm/lib/DebugInfo/PDB/PDBExtras.cpp
  llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp
  llvm/test/DebugInfo/COFF/language.ll
  llvm/test/DebugInfo/COFF/objc.ll
  llvm/test/DebugInfo/COFF/objcpp.ll
  llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp

Index: llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
===
--- llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
+++ llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
@@ -210,6 +210,8 @@
 RETURN_CASE(SourceLanguage, D, "d");
 RETURN_CASE(SourceLanguage, Swift, "swift");
 RETURN_CASE(SourceLanguage, Rust, "rust");
+RETURN_CASE(SourceLanguage, ObjC, "objc");
+RETURN_CASE(SourceLanguage, ObjCpp, "objc++");
   }
   return formatUnknownEnum(Lang);
 }
Index: llvm/test/DebugInfo/COFF/objcpp.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/objcpp.ll
@@ -0,0 +1,44 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=ASM
+; RUN: llc -filetype=obj < %s | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
+
+; ASM:  .short  4412# Record kind: S_COMPILE3
+; ASM-NEXT: .long   18  # Flags and language
+; ASM-NEXT: .short  208 # CPUType
+
+; OBJ-LABEL: Compile3Sym {
+; OBJ-NEXT:Kind: S_COMPILE3 (0x113C)
+; OBJ-NEXT:Language: ObjCpp (0x12)
+; OBJ-NEXT:Flags [ (0x0)
+; OBJ-NEXT:]
+; OBJ-NEXT:Machine: X64 (0xD0)
+; OBJ-NEXT:FrontendVersion: {{[0-9\.]*}}
+; OBJ-NEXT:BackendVersion: {{[0-9\.]*}}
+; OBJ-NEXT:VersionName: clang version 17.0.0 (https://github.com/llvm/llvm-project a8e9beca6bee1f248ef4be7892802c4d091b7fcb)
+; OBJ-NEXT:  }
+
+; ModuleID = 'objcpp.mm'
+source_filename = "objcpp.mm"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; Function Attrs: uwtable
+define void @"?f@@YAXXZ"() #0 !dbg !5 {
+entry:
+  ret void, !dbg !9
+}
+
+attributes #0 = { uwtable "target-cpu"="x86-64" }
+
+!llvm.module.flags = !{!0, !1, !2}
+!llvm.dbg.cu = !{!3}
+
+!0 = !{i32 8, !"PIC Level", i32 2}
+!1 = !{i32 2, !"CodeView", i32 1}
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = distinct !DICompileUnit(language: DW_LANG_ObjC_plus_plus, file: !4, producer: "clang version 17.0.0 (https://github.com/llvm/llvm-project a8e9beca6bee1f248ef4be7892802c4d091b7fcb)", isOptimized: false, runtimeVersion: 1, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!4 = !DIFile(filename: "objcpp.mm", directory: "src", checksumkind: CSK_MD5, checksum: "e6ab1d5b7f82464c963a8522037dfa72")
+!5 = distinct !DISubprogram(name: "f", linkageName: "?f@@YAXXZ", scope: !4, file: !4, line: 1, type: !6, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !3, retainedNodes: !8)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = !{}
+!9 = !DILocation(line: 1, scope: !5)
Index: llvm/test/DebugInfo/COFF/objc.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/objc.ll
@@ -0,0 +1,44 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=ASM
+; RUN: llc -filetype=obj < %s | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
+
+; ASM:  .short  4412# Record kind: S_COMPILE3
+; ASM-NEXT: .long   17  # Flags and language
+; ASM-NEXT: .short  208 # CPUType
+
+; OBJ-LABEL: Compile3Sym {
+; OBJ-NEXT:Kind: S_COMPILE3 (0x113C)
+; OBJ-NEXT:Language: ObjC (0x11)
+; OBJ-NEXT:Flags [ (0x0)
+; OBJ-NEXT:]
+; OBJ-NEXT:Machine: X64 (0xD0)
+; OBJ-NEXT:FrontendVersion: {{[0-9\.]*}}
+; OBJ-NEXT:BackendVersion: {{[0-9\.]*}}
+; OBJ-NEXT:VersionName: clang version 17.0.0 (https://github

[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-03-16 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added inline comments.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp:131
+ExecutionContext &exe_ctx) {
+  // TODO: This function is supposed to check whether an ObjC selector is
+  // present for an object. Might be implemented similar as in the Apple V2

theraven wrote:
> sgraenitz wrote:
> > theraven wrote:
> > > I'm not sure how this is meant to work.  I'd expect this to call one of 
> > > the runtime's introspection functions.  I believe the Apple version has 
> > > variants of these that run without acquiring locks, which can be used in 
> > > the debugger.  We can add these quite easily if necessary.
> > The Apple V2 runtime has two ways to do it: 
> > https://github.com/llvm/llvm-project/blob/release/16.x/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp#L1179
> >  I experimented with the one that doesn't require `void 
> > *gdb_class_getClass(void*)` from the runtime library, but the JIT kept on 
> > crashing. So, for this first version I opted for a minimal implementation 
> > that doesn't do any selector checks. Let's look at it in another review.
> Can you open bugs against the runtime for the gdb_* symbols that we need?  I 
> will add them.
> 
> The other method will crash on small objects because they don't have an isa 
> pointer, their isa is in the low 1-3 bits of the object pointer, indexing 
> into a table in the runtime.
Sure https://github.com/gnustep/libobjc2/issues/244



Comment at: lldb/test/Shell/Expr/objc-gnustep-print.m:68
+//
+// MEMBERS_OUTSIDE: (lldb) p t->_int
+// MEMBERS_OUTSIDE: (int) $0 = 0

theraven wrote:
> sgraenitz wrote:
> > theraven wrote:
> > > It's not clear from this test if it's correctly computing the offsets.  I 
> > > suspect that it isn't, since I don't see any reference to the ivar offset 
> > > variables.
> > What exactly would you expect to see in the output?
> If the offsets are all wrong, this will still work if it happens to land 
> within zeroed memory, which is quite likely.  It would be good to have a 
> method that set all of the ivars to something and then check for those values 
> explicitly.  Or check for `(char*)t->{ivar} - (char*)t` and make sure that 
> this is the right value (this will change between 32/64/128-bit platforms).
Ok, updated the test. I only checked on 64-bit, but it should support arbitrary 
pointer widths. Can we skip the test for ivar offset distance? I'd like to 
avoid testing the actual memory layout here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

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


[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-03-16 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 505760.
sgraenitz marked 3 inline comments as done.
sgraenitz added a comment.

Extend the test to check both, zero initialization and assigned ivars


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/CMakeLists.txt
  lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/CMakeLists.txt
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
  lldb/test/Shell/Expr/objc-gnustep-print.m

Index: lldb/test/Shell/Expr/objc-gnustep-print.m
===
--- lldb/test/Shell/Expr/objc-gnustep-print.m
+++ lldb/test/Shell/Expr/objc-gnustep-print.m
@@ -27,23 +27,39 @@
 }
 @end
 
-@interface TestObj : NSObject {}
-- (int)ok;
+@interface TestObj : NSObject {
+  int _int;
+  float _float;
+  char _char;
+  void *_ptr_void;
+  NSObject *_ptr_nsobject;
+  id _id_objc;
+}
+- (void)check_ivars_zeroed;
+- (void)set_ivars;
 @end
 @implementation TestObj
-- (int)ok {
-  return self ? 0 : 1;
+- (void)check_ivars_zeroed {
+  ;
+}
+- (void)set_ivars {
+  _int = 1;
+  _float = 2.0f;
+  _char = '\3';
+  _ptr_void = (void*)4;
+  _ptr_nsobject = (NSObject*)5;
+  _id_objc = (id)6;
 }
 @end
 
-// RUN: %lldb -b -o "b objc-gnustep-print.m:35" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
+// RUN: %lldb -b -o "b objc-gnustep-print.m:43" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
 //
-// SELF: (lldb) b objc-gnustep-print.m:35
+// SELF: (lldb) b objc-gnustep-print.m:43
 // SELF: Breakpoint {{.*}} at objc-gnustep-print.m
 //
 // SELF: (lldb) run
 // SELF: Process {{[0-9]+}} stopped
-// SELF: -[TestObj ok](self=[[SELF_PTR:0x[0-9]+]]{{.*}}) at objc-gnustep-print.m:35
+// SELF: -[TestObj check_ivars_zeroed](self=[[SELF_PTR:0x[0-9]+]]{{.*}}) at objc-gnustep-print.m
 //
 // SELF: (lldb) p self
 // SELF: (TestObj *) $0 = [[SELF_PTR]]
@@ -54,9 +70,38 @@
 // SELF: isa
 // SELF: refcount
 // SELF:   }
+// SELF:   _int = 0
+// SELF:   _float = 0
+// SELF:   _char = '\0'
+// SELF:   _ptr_void = 0x{{0*}}
+// SELF:   _ptr_nsobject = nil
+// SELF:   _id_objc = nil
 // SELF: }
 
+// RUN: %lldb -b -o "b objc-gnustep-print.m:106" -o "run" -o "p t->_int" -o "p t->_float" -o "p t->_char" \
+// RUN:  -o "p t->_ptr_void" -o "p t->_ptr_nsobject" -o "p t->_id_objc" -- %t | FileCheck %s --check-prefix=IVARS_SET
+//
+// IVARS_SET: (lldb) p t->_int
+// IVARS_SET: (int) $0 = 1
+//
+// IVARS_SET: (lldb) p t->_float
+// IVARS_SET: (float) $1 = 2
+//
+// IVARS_SET: (lldb) p t->_char
+// IVARS_SET: (char) $2 = '\x03'
+//
+// IVARS_SET: (lldb) p t->_ptr_void
+// IVARS_SET: (void *) $3 = 0x{{0*}}4
+//
+// IVARS_SET: (lldb) p t->_ptr_nsobject
+// IVARS_SET: (NSObject *) $4 = 0x{{0*}}5
+//
+// IVARS_SET: (lldb) p t->_id_objc
+// IVARS_SET: (id) $5 = 0x{{0*}}6
+
 int main() {
   TestObj *t = [TestObj new];
-  return [t ok];
+  [t check_ivars_zeroed];
+  [t set_ivars];
+  return 0;
 }
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -38,7 +38,8 @@
   enum class ObjCRuntimeVersions {
 eObjC_VersionUnknown = 0,
 eAppleObjC_V1 = 1,
-eAppleObjC_V2 = 2
+eAppleObjC_V2 = 2,
+eGNUstep_libobjc2 = 3,
   };
 
   typedef lldb::addr_t ObjCISA;
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
@@ -235,6 +235,22 @@
   m_isa_to_descriptor.begin(), m_isa_to_descriptor.end());
 }
 
+void ObjCLanguageRuntime::ReadObjCLibraryIfNeeded(
+const ModuleList &module_list) {
+  if (!HasReadObjCLibrary()) {
+std::lock_guard guard(module_list.GetMutex());
+
+size_t num_modules = module_list.GetSize();
+for (size_t i = 0; i < num_modules; i++) {
+  auto mod = module_list.GetModuleAtIndex(i);
+  if (IsModuleObjCLibrary(mod)) {
+ReadObjCLibrary(mod);
+break;
+  }
+}
+  }
+}
+
 ObjCLanguageRuntime::ObjCISA
 ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) {
   ClassDescriptorSP objc_class_sp(GetClassDescriptorFromISA(isa));
Index: lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
==

[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-03-16 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz marked 3 inline comments as done.
sgraenitz added a comment.

In D146154#4197454 , @aprantl wrote:

> One thing I just realized — we need to make sure that we don't accidentally 
> create a GNUstep ObjC runtime in a Swift process that was built without ObjC 
> support on Linux.

Yes, thanks for bringing this up. The goal definitely is to avoid any 
accidental conflicts with existing use cases that don't need or expect a 
GNUstep runtime. I really want to get my focus to the Windows side and PDB 
parsing. It's useful to have Linux working as well, so that we have a testable 
feature set to match. Otherwise, we don't want to invest a lot of effort here 
yet.

> How can we ensure this works for both cases?

Shouldn't the Swift processes report `eLanguageTypeSwift`? Then 
`GNUstepObjCRuntime::CreateInstance()` rejects it reliably.

> I.e., can you detect based on the presence of a symbol or shared object that 
> an GNUstep runtime is present?

Are there existing cases that follow such an approach? Looking at the order of 
events here, it appears that we have to wait for `ModulesDidLoad()` to report 
the shared library before we can inspect its symbols. How would we proceed if 
we want to create the language runtime first? I.e. here 
https://github.com/llvm/llvm-project/blob/release/16.x/lldb/source/Target/Process.cpp#L5727-L5732

The shared library has a GNUstep-specific EH personality for example, would 
that do?

  > llvm-nm libobjc2/build/libobjc.so | grep gnustep_objc
  000264c0 T __gnustep_objc_personality_v0
  00026500 T __gnustep_objcxx_personality_v0


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

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


[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-03-15 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz marked 3 inline comments as done.
sgraenitz added a comment.

Hi David, thanks for your notes. Please find responses inline.




Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp:42
+LanguageType language) {
+  if (language != eLanguageTypeObjC)
+return nullptr;

theraven wrote:
> I'm not familiar with lldb internals, will this exclude ObjC++?
Good question. There is also `eLanguageTypeObjC_plus_plus`, but the plugin 
scanner e.g. seems to use `eLanguageTypeObjC` for both. I'd like to keep it 
like that until I actually start testing ObjC++.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp:47
+  const llvm::Triple &TT = process->GetTarget().GetArchitecture().GetTriple();
+  if (TT.getVendor() == llvm::Triple::VendorType::Apple)
+return nullptr;

theraven wrote:
> I never finished the v2 ABI support for Mach-O, but v1 works on Apple 
> platforms and v2 will eventually.  We definitely shouldn't be the default 
> here, but it would be nice not to prevent it working on macOS.
For the moment it would be nice to stay away from potential conflicts, since 
they won't make reviews easier. We can still add this later on if there is 
demand.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp:131
+ExecutionContext &exe_ctx) {
+  // TODO: This function is supposed to check whether an ObjC selector is
+  // present for an object. Might be implemented similar as in the Apple V2

theraven wrote:
> I'm not sure how this is meant to work.  I'd expect this to call one of the 
> runtime's introspection functions.  I believe the Apple version has variants 
> of these that run without acquiring locks, which can be used in the debugger. 
>  We can add these quite easily if necessary.
The Apple V2 runtime has two ways to do it: 
https://github.com/llvm/llvm-project/blob/release/16.x/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp#L1179
 I experimented with the one that doesn't require `void 
*gdb_class_getClass(void*)` from the runtime library, but the JIT kept on 
crashing. So, for this first version I opted for a minimal implementation that 
doesn't do any selector checks. Let's look at it in another review.



Comment at: lldb/test/Shell/Expr/objc-gnustep-print.m:68
+//
+// MEMBERS_OUTSIDE: (lldb) p t->_int
+// MEMBERS_OUTSIDE: (int) $0 = 0

theraven wrote:
> It's not clear from this test if it's correctly computing the offsets.  I 
> suspect that it isn't, since I don't see any reference to the ivar offset 
> variables.
What exactly would you expect to see in the output?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

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


[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-03-15 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added inline comments.



Comment at: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp:253
+}
+
 ObjCLanguageRuntime::ObjCISA

This was always declared in the header, but never implemented. Instead, 
AppleObjCRuntime had its own implementation -- I could make a follow-up patch 
to reuse it there as well:
https://github.com/llvm/llvm-project/blob/release/16.x/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp#L609-L622



Comment at: lldb/test/Shell/Expr/objc-gnustep-print.m:62
 // SELF: refcount
 // SELF:   }
 // SELF: }

This is missing the newly added members. I will fix it in the course of this 
review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146154

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


[Lldb-commits] [PATCH] D146154: [lldb][gnustep] Add minimal GNUstepObjCRuntime plugin for LanguageTypeObjC on non-Apple platforms

2023-03-15 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: DavidSpickett, theraven, teemperor, bulbazord, 
labath.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This is the next patch after D146058 . We can 
now parse expressions to print instance variables from ObjC classes. Until now 
the expression parser would bail out with an error like this:

  error: expression failed to parse:
  error: Error [IRForTarget]: Couldn't find Objective-C indirect ivar symbol 
OBJC_IVAR_$_TestObj._int


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146154

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/CMakeLists.txt
  lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/CMakeLists.txt
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
  lldb/test/Shell/Expr/objc-gnustep-print.m

Index: lldb/test/Shell/Expr/objc-gnustep-print.m
===
--- lldb/test/Shell/Expr/objc-gnustep-print.m
+++ lldb/test/Shell/Expr/objc-gnustep-print.m
@@ -26,8 +26,14 @@
   return class_createInstance(self, 0);
 }
 @end
-
-@interface TestObj : NSObject {}
+@interface TestObj : NSObject {
+  int _int;
+  float _float;
+  char _char;
+  void *_ptr_void;
+  NSObject *_ptr_nsobject;
+  id _id_objc;
+}
 - (int)ok;
 @end
 @implementation TestObj
@@ -36,14 +42,14 @@
 }
 @end
 
-// RUN: %lldb -b -o "b objc-gnustep-print.m:35" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
+// RUN: %lldb -b -o "b objc-gnustep-print.m:41" -o "run" -o "p self" -o "p *self" -- %t | FileCheck %s --check-prefix=SELF
 //
-// SELF: (lldb) b objc-gnustep-print.m:35
+// SELF: (lldb) b objc-gnustep-print.m:41
 // SELF: Breakpoint {{.*}} at objc-gnustep-print.m
 //
 // SELF: (lldb) run
 // SELF: Process {{[0-9]+}} stopped
-// SELF: -[TestObj ok](self=[[SELF_PTR:0x[0-9]+]]{{.*}}) at objc-gnustep-print.m:35
+// SELF: -[TestObj ok](self=[[SELF_PTR:0x[0-9]+]]{{.*}}) at objc-gnustep-print.m:41
 //
 // SELF: (lldb) p self
 // SELF: (TestObj *) $0 = [[SELF_PTR]]
@@ -56,6 +62,27 @@
 // SELF:   }
 // SELF: }
 
+// RUN: %lldb -b -o "b objc-gnustep-print.m:88" -o "run" -o "p t->_int" -o "p t->_float" -o "p t->_char" \
+// RUN:  -o "p t->_ptr_void" -o "p t->_ptr_nsobject" -o "p t->_id_objc" -- %t | FileCheck %s --check-prefix=MEMBERS_OUTSIDE
+//
+// MEMBERS_OUTSIDE: (lldb) p t->_int
+// MEMBERS_OUTSIDE: (int) $0 = 0
+//
+// MEMBERS_OUTSIDE: (lldb) p t->_float
+// MEMBERS_OUTSIDE: (float) $1 = 0
+//
+// MEMBERS_OUTSIDE: (lldb) p t->_char
+// MEMBERS_OUTSIDE: (char) $2 = '\0'
+//
+// MEMBERS_OUTSIDE: (lldb) p t->_ptr_void
+// MEMBERS_OUTSIDE: (void *) $3 = 0x
+//
+// MEMBERS_OUTSIDE: (lldb) p t->_ptr_nsobject
+// MEMBERS_OUTSIDE: (NSObject *) $4 = nil
+//
+// MEMBERS_OUTSIDE: (lldb) p t->_id_objc
+// MEMBERS_OUTSIDE: (id) $5 = nil
+
 int main() {
   TestObj *t = [TestObj new];
   return [t ok];
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -38,7 +38,8 @@
   enum class ObjCRuntimeVersions {
 eObjC_VersionUnknown = 0,
 eAppleObjC_V1 = 1,
-eAppleObjC_V2 = 2
+eAppleObjC_V2 = 2,
+eGNUstep_libobjc2 = 3,
   };
 
   typedef lldb::addr_t ObjCISA;
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
@@ -235,6 +235,22 @@
   m_isa_to_descriptor.begin(), m_isa_to_descriptor.end());
 }
 
+void ObjCLanguageRuntime::ReadObjCLibraryIfNeeded(
+const ModuleList &module_list) {
+  if (!HasReadObjCLibrary()) {
+std::lock_guard guard(module_list.GetMutex());
+
+size_t num_modules = module_list.GetSize();
+for (size_t i = 0; i < num_modules; i++) {
+  auto mod = module_list.GetModuleAtIndex(i);
+  if (IsModuleObjCLibrary(mod)) {
+ReadObjCLibrary(mod);
+break;
+  }
+}
+  }
+}
+
 ObjCLanguageRuntime::ObjCISA
 ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) {
   ClassDescriptorSP objc_class_sp(GetClassDescriptorFromISA(isa));
Index: lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
===
--- /dev/null
+++ lld

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-15 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added inline comments.



Comment at: lldb/test/CMakeLists.txt:39
+if (LLDB_TEST_OBJC_GNUSTEP_DIR)
+  message(STATUS "Found GNUstep ObjC runtime: 
${LLDB_TEST_OBJC_GNUSTEP_DIR}/${gnustep_info}")
+endif()

sgraenitz wrote:
> theraven wrote:
> > DavidSpickett wrote:
> > > sgraenitz wrote:
> > > > Might be worth a `FindGNUstep.cmake` at some point? (Or is there one 
> > > > somewhere?)
> > > > 
> > > > Windows default install dir:
> > > > ```
> > > > -- Found GNUstep ObjC runtime: C:/Program Files 
> > > > (x86)/libobjc/lib/objc.dll
> > > > ```
> > > > 
> > > > Linux default install dir:
> > > > ```
> > > > -- Found GNUstep ObjC runtime: /usr/local/lib/libobjc.so
> > > > ```
> > > I think we generally use UPPERCASE names for cmake variables.
> > This is somewhat complicated.  If `gnustep-config` exists, the runtime 
> > supports installing itself into a location defined by the gnustep-make 
> > install, which supports NeXT, Apple, and FHS-style layouts.  It's probably 
> > not worth trying to autodetect the general case.
> > This is somewhat complicated.
> > It's probably not worth trying to autodetect the general case.
> 
> Configuring with cmake and running the install target gives me these paths. 
> Do you mean I should remove them and just let the user set 
> `LLDB_TEST_OBJC_GNUSTEP_DIR`?
> 
> > If gnustep-config exists, the runtime supports installing itself into a 
> > location defined by the gnustep-make install, which supports NeXT, Apple, 
> > and FHS-style layouts.
> 
> Right now, I am assuming to find the shared library in the `lib` subdirectory 
> and headers in `include`. Is that different in the other layouts? Do we need 
> to support that?
> 
> > I think we generally use UPPERCASE names for cmake variables.
> 
> I  think the convention is: UPPERCASE for global variables, lowercase for 
> local variables
@theraven I installed `gnustep-config` locally, but I don't see how to get the 
libobjc2 install dir from it. So far, I always built from source and (for me) 
this works well with the current CMake code. Should we keep it like this or can 
you give me advice on how to improve it? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-15 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 505529.
sgraenitz added a comment.

Make the test more extensible


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

Files:
  lldb/test/CMakeLists.txt
  lldb/test/Shell/Expr/objc-gnustep-print.m
  lldb/test/Shell/helper/build.py
  lldb/test/Shell/helper/toolchain.py
  lldb/test/Shell/lit.cfg.py
  lldb/test/Shell/lit.site.cfg.py.in

Index: lldb/test/Shell/lit.site.cfg.py.in
===
--- lldb/test/Shell/lit.site.cfg.py.in
+++ lldb/test/Shell/lit.site.cfg.py.in
@@ -16,6 +16,7 @@
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.objc_gnustep_dir = "@LLDB_TEST_OBJC_GNUSTEP_DIR@"
 config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
Index: lldb/test/Shell/lit.cfg.py
===
--- lldb/test/Shell/lit.cfg.py
+++ lldb/test/Shell/lit.cfg.py
@@ -24,7 +24,7 @@
 
 # suffixes: A list of file extensions to treat as test files. This is overriden
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
 # subdirectories contain auxiliary inputs for various tests in their parent
@@ -135,6 +135,14 @@
 if config.have_lldb_server:
 config.available_features.add('lldb-server')
 
+if config.objc_gnustep_dir:
+config.available_features.add('objc-gnustep')
+if platform.system() == 'Windows':
+# objc.dll must be in PATH since Windows has no rpath
+config.environment['PATH'] = os.path.pathsep.join((
+os.path.join(config.objc_gnustep_dir, 'lib'),
+config.environment.get('PATH','')))
+
 # NetBSD permits setting dbregs either if one is root
 # or if user_set_dbregs is enabled
 can_set_dbregs = True
Index: lldb/test/Shell/helper/toolchain.py
===
--- lldb/test/Shell/helper/toolchain.py
+++ lldb/test/Shell/helper/toolchain.py
@@ -42,6 +42,8 @@
 build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
 if config.llvm_libs_dir:
 build_script_args.append('--libs-dir={0}'.format(config.llvm_libs_dir))
+if config.objc_gnustep_dir:
+build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 
 lldb_init = _get_lldb_init_path(config)
 
Index: lldb/test/Shell/helper/build.py
===
--- lldb/test/Shell/helper/build.py
+++ lldb/test/Shell/helper/build.py
@@ -49,6 +49,18 @@
 action='append',
 help='If specified, a path to search in addition to PATH when --compiler is not an exact path')
 
+parser.add_argument('--objc-gnustep-dir',
+metavar='directory',
+dest='objc_gnustep_dir',
+required=False,
+help='If specified, a path to GNUstep libobjc2 runtime for use on Windows and Linux')
+
+parser.add_argument('--objc-gnustep',
+dest='objc_gnustep',
+action='store_true',
+default=False,
+help='Include and link GNUstep libobjc2 (Windows and Linux only)')
+
 if sys.platform == 'darwin':
 parser.add_argument('--apple-sdk',
 metavar='apple_sdk',
@@ -238,6 +250,10 @@
 self.obj_ext = obj_ext
 self.lib_paths = args.libs_dir
 self.std = args.std
+assert not args.objc_gnustep or args.objc_gnustep_dir, \
+   "--objc-gnustep specified without path to libobjc2"
+self.objc_gnustep_inc = os.path.join(args.objc_gnustep_dir, 'include') if args.objc_gnustep_dir else None
+self.objc_gnustep_lib = os.path.join(args.objc_gnustep_dir, 'lib') if args.objc_gnustep_dir else None
 
 def _exe_file_name(self):
 assert self.mode != 'compile'
@@ -656,15 +672,20 @@
 args.append('-static')
 args.append('-c')
 
-args.extend(['-o', obj])
-args.append(source)
-
 if sys.platform == 'darwin':
 args.extend(['-isysroot', self.apple_sdk])
+elif self.objc_gnustep_inc:
+if source.endswith('.m') or source.endswith('.mm'):
+args.extend(['-fobjc-runtime=gnustep-2.0', '-I', self.objc_gnustep_inc])
+if sys.platform == "win32":
+args.extend(['-Xclang', '-gcodeview', '-Xclang', '--dependent-lib=msvcrtd'])
 
 if self.std:
 args.append('-std={0}'.format(self.std))
 
+args.extend(['-o', obj])
+args.

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-15 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

In D146058#4196060 , @DavidSpickett 
wrote:

> If I run the test without the runtime installed I get these run lines [...]

Oh, excellent catch. Thanks! Now, with my last patch, given that:

  > grep GNUSTEP CMakeCache.txt
  LLDB_TEST_OBJC_GNUSTEP_DIR:PATH=

The test says:

  > bin/llvm-lit --filter=gnustep -a tools/lldb/test
  -- Testing: 1 of 1979 tests, 1 workers --
  UNSUPPORTED: lldb-shell :: Expr/objc-gnustep-print.m (1 of 1)
  Test requires the following unavailable features: objc-gnustep


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-15 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 505528.
sgraenitz marked an inline comment as done.
sgraenitz added a comment.

Fix CMakeLists.txt and build.py for the case that GNUstep is not installed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

Files:
  lldb/test/CMakeLists.txt
  lldb/test/Shell/Expr/objc-gnustep-print.m
  lldb/test/Shell/helper/build.py
  lldb/test/Shell/helper/toolchain.py
  lldb/test/Shell/lit.cfg.py
  lldb/test/Shell/lit.site.cfg.py.in

Index: lldb/test/Shell/lit.site.cfg.py.in
===
--- lldb/test/Shell/lit.site.cfg.py.in
+++ lldb/test/Shell/lit.site.cfg.py.in
@@ -16,6 +16,7 @@
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.objc_gnustep_dir = "@LLDB_TEST_OBJC_GNUSTEP_DIR@"
 config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
Index: lldb/test/Shell/lit.cfg.py
===
--- lldb/test/Shell/lit.cfg.py
+++ lldb/test/Shell/lit.cfg.py
@@ -24,7 +24,7 @@
 
 # suffixes: A list of file extensions to treat as test files. This is overriden
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
 # subdirectories contain auxiliary inputs for various tests in their parent
@@ -135,6 +135,14 @@
 if config.have_lldb_server:
 config.available_features.add('lldb-server')
 
+if config.objc_gnustep_dir:
+config.available_features.add('objc-gnustep')
+if platform.system() == 'Windows':
+# objc.dll must be in PATH since Windows has no rpath
+config.environment['PATH'] = os.path.pathsep.join((
+os.path.join(config.objc_gnustep_dir, 'lib'),
+config.environment.get('PATH','')))
+
 # NetBSD permits setting dbregs either if one is root
 # or if user_set_dbregs is enabled
 can_set_dbregs = True
Index: lldb/test/Shell/helper/toolchain.py
===
--- lldb/test/Shell/helper/toolchain.py
+++ lldb/test/Shell/helper/toolchain.py
@@ -42,6 +42,8 @@
 build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
 if config.llvm_libs_dir:
 build_script_args.append('--libs-dir={0}'.format(config.llvm_libs_dir))
+if config.objc_gnustep_dir:
+build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 
 lldb_init = _get_lldb_init_path(config)
 
Index: lldb/test/Shell/helper/build.py
===
--- lldb/test/Shell/helper/build.py
+++ lldb/test/Shell/helper/build.py
@@ -49,6 +49,18 @@
 action='append',
 help='If specified, a path to search in addition to PATH when --compiler is not an exact path')
 
+parser.add_argument('--objc-gnustep-dir',
+metavar='directory',
+dest='objc_gnustep_dir',
+required=False,
+help='If specified, a path to GNUstep libobjc2 runtime for use on Windows and Linux')
+
+parser.add_argument('--objc-gnustep',
+dest='objc_gnustep',
+action='store_true',
+default=False,
+help='Include and link GNUstep libobjc2 (Windows and Linux only)')
+
 if sys.platform == 'darwin':
 parser.add_argument('--apple-sdk',
 metavar='apple_sdk',
@@ -238,6 +250,10 @@
 self.obj_ext = obj_ext
 self.lib_paths = args.libs_dir
 self.std = args.std
+assert not args.objc_gnustep or args.objc_gnustep_dir, \
+   "--objc-gnustep specified without path to libobjc2"
+self.objc_gnustep_inc = os.path.join(args.objc_gnustep_dir, 'include') if args.objc_gnustep_dir else None
+self.objc_gnustep_lib = os.path.join(args.objc_gnustep_dir, 'lib') if args.objc_gnustep_dir else None
 
 def _exe_file_name(self):
 assert self.mode != 'compile'
@@ -656,15 +672,20 @@
 args.append('-static')
 args.append('-c')
 
-args.extend(['-o', obj])
-args.append(source)
-
 if sys.platform == 'darwin':
 args.extend(['-isysroot', self.apple_sdk])
+elif self.objc_gnustep_inc:
+if source.endswith('.m') or source.endswith('.mm'):
+args.extend(['-fobjc-runtime=gnustep-2.0', '-I', self.objc_gnustep_inc])
+if sys.platform == "win32":
+args.extend(['-Xclang', '-gcodeview', '-Xclang', '--dependent-lib=msvcrtd'])
 
 if self.std:
 ar

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-14 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz marked 2 inline comments as done.
sgraenitz added a comment.

Soo, @DavidSpickett

In D146058#4193446 , @DavidSpickett 
wrote:

> I am not familiar with Objective C, especially beyond Apple platforms. Are 
> you aiming to run all the existing Objective C test cases with this different 
> runtime or will it be mainly new tests?
> (would be very neat if you got all the existing stuff for free)

It would be great to get all the existing Objective C test coverage for free, 
but I guess it'd take a while to support all of the Apple runtime features. 
Literally all existing ObjC tests are API tests and when running locally, they 
are all `UNSUPPORTED` for me on Linux and Windows. I didn't manage to get them 
running quickly and thus, I went for a Shell test here. My impression was that 
API tests are LLDB legacy and new tests would usually be Shell. It might still 
be worth getting (some of) the API tests to work with GNUstep as well, but I 
might need some advice on how to do that.

In D146058#4193470 , @DavidSpickett 
wrote:

> Myself and Omair both work on Linaro's bots. We run lldb checks on linux 
> arm/aarch64 and Windows on Arm. We could look at installing it.

I suspect `lldb-arm-ubuntu` means 32-bit ARM. This should work, but it's not a 
priority for us right now. We could still give it a try and see if it works 
out-of-the-box!

As a side-note: Could the AArch64 bot 
https://lab.llvm.org/buildbot/#/builders/219 pass `LLVM_LIT_ARGS="-v"` as well 
so the log tells us which tests actually ran? That would be great!




Comment at: lldb/test/CMakeLists.txt:32
+  set(gnustep_info lib/libobjc.so)
+elseif (WIN32 AND EXISTS "C:/Program Files (x86)/libobjc/lib/objc.dll"
+  AND EXISTS "C:/Program Files 
(x86)/libobjc/include/objc/runtime.h")

DavidSpickett wrote:
> Does this library work on Windows on Arm (AArch64 Windows)?
> 
> Fine not to handle that in this change, just curious. We (Linaro) do have an 
> lldb bot for it, so it could be added at some point.
Not yet: https://github.com/gnustep/libobjc2/issues/227



Comment at: lldb/test/Shell/lit.cfg.py:27
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 

sgraenitz wrote:
> DavidSpickett wrote:
> > There are a couple of .m files in the Shell dir already, I assume the 
> > related tests still pass for those?
> Interesting, it's exactly one .m and one .mm outside `Input` directories 
> right? Let me double-check that.
> ```
> SymbolFile/DWARF/clang-ast-from-dwarf-objc-property.m
> SymbolFile/DWARF/x86/module-ownership.mm
> ```
These have been running ever since, because 
https://github.com/llvm/llvm-project/blob/release/16.x/lldb/test/Shell/SymbolFile/DWARF/lit.local.cfg
 Anyway, thanks for your note!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-14 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

In D146058#4193795 , 
@stella.stamenova wrote:

> The one I was referring to is https://lab.llvm.org/buildbot/#/builders/219.

Ok, thanks for the update. Then we are lacking a Windows x86 build bot for LLDB 
now!

> Also, the one that was removed was not x86 either, it was x64.

Yes, the naming can be confusing. I think the x86 we talked about mainly means 
64-bit (often called x64 on Windows) and includes the 32-bit legacy. Like the 
`X86` target backend in LLVM.




Comment at: lldb/test/Shell/helper/build.py:254
+if args.objc_gnustep:
+assert args.objc_gnustep_dir, "GNUstep libobjc2 runtime for Linux 
and Windows"
+self.objc_gnustep_inc = os.path.join(args.objc_gnustep_dir, 
'include')

bulbazord wrote:
> The assertion message here is not tremendously helpful. Maybe something like 
> "--objc-gnustep specified without path to libobjc2. Use --objc-gnustep-dir to 
> specify said path."
None of the other `assert`s have messages at all, but ok :)



Comment at: lldb/test/Shell/helper/toolchain.py:46
+if config.objc_gnustep_dir:
+
build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 

bulbazord wrote:
> Why does {0} need quotes around it but the args above it don't?
Good catch! That's due to spaces in Windows paths...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-14 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 505189.
sgraenitz marked 2 inline comments as done.
sgraenitz added a comment.

Polish assertion message in build.py


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

Files:
  lldb/test/CMakeLists.txt
  lldb/test/Shell/Expr/objc-gnustep-print.m
  lldb/test/Shell/helper/build.py
  lldb/test/Shell/helper/toolchain.py
  lldb/test/Shell/lit.cfg.py
  lldb/test/Shell/lit.site.cfg.py.in

Index: lldb/test/Shell/lit.site.cfg.py.in
===
--- lldb/test/Shell/lit.site.cfg.py.in
+++ lldb/test/Shell/lit.site.cfg.py.in
@@ -16,6 +16,7 @@
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.objc_gnustep_dir = "@LLDB_TEST_OBJC_GNUSTEP_DIR@"
 config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
Index: lldb/test/Shell/lit.cfg.py
===
--- lldb/test/Shell/lit.cfg.py
+++ lldb/test/Shell/lit.cfg.py
@@ -24,7 +24,7 @@
 
 # suffixes: A list of file extensions to treat as test files. This is overriden
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
 # subdirectories contain auxiliary inputs for various tests in their parent
@@ -135,6 +135,14 @@
 if config.have_lldb_server:
 config.available_features.add('lldb-server')
 
+if config.objc_gnustep_dir:
+config.available_features.add('objc-gnustep')
+if platform.system() == 'Windows':
+# objc.dll must be in PATH since Windows has no rpath
+config.environment['PATH'] = os.path.pathsep.join((
+os.path.join(config.objc_gnustep_dir, 'lib'),
+config.environment.get('PATH','')))
+
 # NetBSD permits setting dbregs either if one is root
 # or if user_set_dbregs is enabled
 can_set_dbregs = True
Index: lldb/test/Shell/helper/toolchain.py
===
--- lldb/test/Shell/helper/toolchain.py
+++ lldb/test/Shell/helper/toolchain.py
@@ -42,6 +42,8 @@
 build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
 if config.llvm_libs_dir:
 build_script_args.append('--libs-dir={0}'.format(config.llvm_libs_dir))
+if config.objc_gnustep_dir:
+build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 
 lldb_init = _get_lldb_init_path(config)
 
Index: lldb/test/Shell/helper/build.py
===
--- lldb/test/Shell/helper/build.py
+++ lldb/test/Shell/helper/build.py
@@ -49,6 +49,18 @@
 action='append',
 help='If specified, a path to search in addition to PATH when --compiler is not an exact path')
 
+parser.add_argument('--objc-gnustep-dir',
+metavar='directory',
+dest='objc_gnustep_dir',
+required=False,
+help='If specified, a path to GNUstep libobjc2 runtime for use on Windows and Linux')
+
+parser.add_argument('--objc-gnustep',
+dest='objc_gnustep',
+action='store_true',
+default=False,
+help='Include and link GNUstep libobjc2 (Windows and Linux only)')
+
 if sys.platform == 'darwin':
 parser.add_argument('--apple-sdk',
 metavar='apple_sdk',
@@ -238,6 +250,10 @@
 self.obj_ext = obj_ext
 self.lib_paths = args.libs_dir
 self.std = args.std
+if args.objc_gnustep:
+assert args.objc_gnustep_dir, "--objc-gnustep specified without path to libobjc2"
+self.objc_gnustep_inc = os.path.join(args.objc_gnustep_dir, 'include')
+self.objc_gnustep_lib = os.path.join(args.objc_gnustep_dir, 'lib')
 
 def _exe_file_name(self):
 assert self.mode != 'compile'
@@ -656,15 +672,20 @@
 args.append('-static')
 args.append('-c')
 
-args.extend(['-o', obj])
-args.append(source)
-
 if sys.platform == 'darwin':
 args.extend(['-isysroot', self.apple_sdk])
+elif self.objc_gnustep_inc:
+if source.endswith('.m') or source.endswith('.mm'):
+args.extend(['-fobjc-runtime=gnustep-2.0', '-I', self.objc_gnustep_inc])
+if sys.platform == "win32":
+args.extend(['-Xclang', '-gcodeview', '-Xclang', '--dependent-lib=msvcrtd'])
 
 if self.std:
 args.append('-std={0}'.format(self.std))
 
+args.extend(['-o', obj])
+args.append(source)
+
  

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-14 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a subscriber: stella.stamenova.
sgraenitz added a comment.

In D146058#4193470 , @DavidSpickett 
wrote:

> Myself and Omair both work on Linaro's bots. We run lldb checks on linux 
> arm/aarch64 and Windows on Arm. We could look at installing it.

Right now, my focus is x86 Windows and Linux, but thanks for the offer! So, 
this would be https://lab.llvm.org/buildbot/#/builders/219 (Windows AArch64) 
and https://lab.llvm.org/buildbot/#/builders/17 (Linux AArch32)? Let me discuss 
this internally and come back to you soon.

> Pavel runs the x86 debian bot and I think the x86 Windows bot may have been 
> retired, or at least is offline at the moment 
> (https://lab.llvm.org/buildbot/#/builders/83)

Yes, that would be cool. @labath What do you think?

In D146058#4193471 , @DavidSpickett 
wrote:

> The Windows x86 bot has in fact been removed: 
> https://github.com/llvm/llvm-zorg/commit/acb6223670a41a7fe5d9846075e6b92bd157d78f

Oh I still saw that one running a few days back! @stella.stamenova in the 
review you mention a second windows lldb bot, is it x86 as well? I don't see it 
in https://lab.llvm.org/buildbot/#/console




Comment at: lldb/test/CMakeLists.txt:39
+if (LLDB_TEST_OBJC_GNUSTEP_DIR)
+  message(STATUS "Found GNUstep ObjC runtime: 
${LLDB_TEST_OBJC_GNUSTEP_DIR}/${gnustep_info}")
+endif()

theraven wrote:
> DavidSpickett wrote:
> > sgraenitz wrote:
> > > Might be worth a `FindGNUstep.cmake` at some point? (Or is there one 
> > > somewhere?)
> > > 
> > > Windows default install dir:
> > > ```
> > > -- Found GNUstep ObjC runtime: C:/Program Files (x86)/libobjc/lib/objc.dll
> > > ```
> > > 
> > > Linux default install dir:
> > > ```
> > > -- Found GNUstep ObjC runtime: /usr/local/lib/libobjc.so
> > > ```
> > I think we generally use UPPERCASE names for cmake variables.
> This is somewhat complicated.  If `gnustep-config` exists, the runtime 
> supports installing itself into a location defined by the gnustep-make 
> install, which supports NeXT, Apple, and FHS-style layouts.  It's probably 
> not worth trying to autodetect the general case.
> This is somewhat complicated.
> It's probably not worth trying to autodetect the general case.

Configuring with cmake and running the install target gives me these paths. Do 
you mean I should remove them and just let the user set 
`LLDB_TEST_OBJC_GNUSTEP_DIR`?

> If gnustep-config exists, the runtime supports installing itself into a 
> location defined by the gnustep-make install, which supports NeXT, Apple, and 
> FHS-style layouts.

Right now, I am assuming to find the shared library in the `lib` subdirectory 
and headers in `include`. Is that different in the other layouts? Do we need to 
support that?

> I think we generally use UPPERCASE names for cmake variables.

I  think the convention is: UPPERCASE for global variables, lowercase for local 
variables



Comment at: lldb/test/Shell/helper/build.py:687
+args.extend(['-o', obj])
+args.append(source)
+

DavidSpickett wrote:
> Why did these 2 need to move?
The flags wouldn't apply for previous source files otherwise. I opted to move 
them both in order to keep them close in the resulting command.



Comment at: lldb/test/Shell/lit.cfg.py:27
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 

DavidSpickett wrote:
> There are a couple of .m files in the Shell dir already, I assume the related 
> tests still pass for those?
Interesting, it's exactly one .m and one .mm outside `Input` directories right? 
Let me double-check that.
```
SymbolFile/DWARF/clang-ast-from-dwarf-objc-property.m
SymbolFile/DWARF/x86/module-ownership.mm
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-14 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 505149.
sgraenitz marked 3 inline comments as done.
sgraenitz added a comment.

Improve help text for the build.py --objc-gnustep option


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

Files:
  lldb/test/CMakeLists.txt
  lldb/test/Shell/Expr/objc-gnustep-print.m
  lldb/test/Shell/helper/build.py
  lldb/test/Shell/helper/toolchain.py
  lldb/test/Shell/lit.cfg.py
  lldb/test/Shell/lit.site.cfg.py.in

Index: lldb/test/Shell/lit.site.cfg.py.in
===
--- lldb/test/Shell/lit.site.cfg.py.in
+++ lldb/test/Shell/lit.site.cfg.py.in
@@ -16,6 +16,7 @@
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.objc_gnustep_dir = "@LLDB_TEST_OBJC_GNUSTEP_DIR@"
 config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
Index: lldb/test/Shell/lit.cfg.py
===
--- lldb/test/Shell/lit.cfg.py
+++ lldb/test/Shell/lit.cfg.py
@@ -24,7 +24,7 @@
 
 # suffixes: A list of file extensions to treat as test files. This is overriden
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
 # subdirectories contain auxiliary inputs for various tests in their parent
@@ -135,6 +135,14 @@
 if config.have_lldb_server:
 config.available_features.add('lldb-server')
 
+if config.objc_gnustep_dir:
+config.available_features.add('objc-gnustep')
+if platform.system() == 'Windows':
+# objc.dll must be in PATH since Windows has no rpath
+config.environment['PATH'] = os.path.pathsep.join((
+os.path.join(config.objc_gnustep_dir, 'lib'),
+config.environment.get('PATH','')))
+
 # NetBSD permits setting dbregs either if one is root
 # or if user_set_dbregs is enabled
 can_set_dbregs = True
Index: lldb/test/Shell/helper/toolchain.py
===
--- lldb/test/Shell/helper/toolchain.py
+++ lldb/test/Shell/helper/toolchain.py
@@ -42,6 +42,8 @@
 build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
 if config.llvm_libs_dir:
 build_script_args.append('--libs-dir={0}'.format(config.llvm_libs_dir))
+if config.objc_gnustep_dir:
+build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 
 lldb_init = _get_lldb_init_path(config)
 
Index: lldb/test/Shell/helper/build.py
===
--- lldb/test/Shell/helper/build.py
+++ lldb/test/Shell/helper/build.py
@@ -49,6 +49,18 @@
 action='append',
 help='If specified, a path to search in addition to PATH when --compiler is not an exact path')
 
+parser.add_argument('--objc-gnustep-dir',
+metavar='directory',
+dest='objc_gnustep_dir',
+required=False,
+help='If specified, a path to GNUstep libobjc2 runtime for use on Windows and Linux')
+
+parser.add_argument('--objc-gnustep',
+dest='objc_gnustep',
+action='store_true',
+default=False,
+help='Include and link GNUstep libobjc2 (Windows and Linux only)')
+
 if sys.platform == 'darwin':
 parser.add_argument('--apple-sdk',
 metavar='apple_sdk',
@@ -238,6 +250,10 @@
 self.obj_ext = obj_ext
 self.lib_paths = args.libs_dir
 self.std = args.std
+if args.objc_gnustep:
+assert args.objc_gnustep_dir, "GNUstep libobjc2 runtime for Linux and Windows"
+self.objc_gnustep_inc = os.path.join(args.objc_gnustep_dir, 'include')
+self.objc_gnustep_lib = os.path.join(args.objc_gnustep_dir, 'lib')
 
 def _exe_file_name(self):
 assert self.mode != 'compile'
@@ -656,15 +672,20 @@
 args.append('-static')
 args.append('-c')
 
-args.extend(['-o', obj])
-args.append(source)
-
 if sys.platform == 'darwin':
 args.extend(['-isysroot', self.apple_sdk])
+elif self.objc_gnustep_inc:
+if source.endswith('.m') or source.endswith('.mm'):
+args.extend(['-fobjc-runtime=gnustep-2.0', '-I', self.objc_gnustep_inc])
+if sys.platform == "win32":
+args.extend(['-Xclang', '-gcodeview', '-Xclang', '--dependent-lib=msvcrtd'])
 
 if self.std:
 args.append('-std={0}'.format(self.std))
 
+args.extend(['-o', obj])
+args.ap

[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-14 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

I am not in touch with any of the build bot maintainers for Windows/Linux LLDB. 
Do you think it's worth asking for mainline test support? They'd basically need 
to build and install libobjc2 once. It's a few hundred kilobytes.

For me the test expectedly fails on Windows 10 and passes on Ubuntu 22.04 LTS 
right now:

  > bin/llvm-lit --filter=objc-gnustep -v tools/lldb/test
  -- Testing: 1 of 1979 tests, 1 workers --
  PASS: lldb-shell :: Expr/objc-gnustep-print.m (1 of 1)
  
  Testing Time: 1.26s
Excluded: 1583
Passed  :1




Comment at: lldb/test/CMakeLists.txt:39
+if (LLDB_TEST_OBJC_GNUSTEP_DIR)
+  message(STATUS "Found GNUstep ObjC runtime: 
${LLDB_TEST_OBJC_GNUSTEP_DIR}/${gnustep_info}")
+endif()

Might be worth a `FindGNUstep.cmake` at some point? (Or is there one somewhere?)

Windows default install dir:
```
-- Found GNUstep ObjC runtime: C:/Program Files (x86)/libobjc/lib/objc.dll
```

Linux default install dir:
```
-- Found GNUstep ObjC runtime: /usr/local/lib/libobjc.so
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146058

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


[Lldb-commits] [PATCH] D146058: [lldb][gnustep] Add basic test and infrastructure for GNUstep ObjC runtime

2023-03-14 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: theraven, triplef, mgorny, labath, omjavaid, 
xiaobai, aleksandr.urakov, zturner.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a project: LLDB.

We are planning to add basic ObjC debug support for the GNUstep ObjC runtime on 
Linux and Windows: https://github.com/gnustep/libobjc2 On Linux much of the 
desired functionality is there already. It seems accidental in parts, but it's 
a good early baseline. On Windows nothing works yet.

In this first patch I want to add the necessary test infrastructure to utilize 
the GNUstep runtime in the LLDB test suite. The minimal test demonstrates that 
it works on Linux. The next goal is to extend the PDB parser and get Windows to 
this baseline as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146058

Files:
  lldb/test/CMakeLists.txt
  lldb/test/Shell/Expr/objc-gnustep-print.m
  lldb/test/Shell/helper/build.py
  lldb/test/Shell/helper/toolchain.py
  lldb/test/Shell/lit.cfg.py
  lldb/test/Shell/lit.site.cfg.py.in

Index: lldb/test/Shell/lit.site.cfg.py.in
===
--- lldb/test/Shell/lit.site.cfg.py.in
+++ lldb/test/Shell/lit.site.cfg.py.in
@@ -16,6 +16,7 @@
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.objc_gnustep_dir = "@LLDB_TEST_OBJC_GNUSTEP_DIR@"
 config.lldb_enable_lzma = @LLDB_ENABLE_LZMA@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.lldb_bitness = 64 if @LLDB_IS_64_BITS@ else 32
Index: lldb/test/Shell/lit.cfg.py
===
--- lldb/test/Shell/lit.cfg.py
+++ lldb/test/Shell/lit.cfg.py
@@ -24,7 +24,7 @@
 
 # suffixes: A list of file extensions to treat as test files. This is overriden
 # by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = ['.test', '.cpp', '.s']
+config.suffixes = ['.test', '.cpp', '.s', '.m']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
 # subdirectories contain auxiliary inputs for various tests in their parent
@@ -135,6 +135,14 @@
 if config.have_lldb_server:
 config.available_features.add('lldb-server')
 
+if config.objc_gnustep_dir:
+config.available_features.add('objc-gnustep')
+if platform.system() == 'Windows':
+# objc.dll must be in PATH since Windows has no rpath
+config.environment['PATH'] = os.path.pathsep.join((
+os.path.join(config.objc_gnustep_dir, 'lib'),
+config.environment.get('PATH','')))
+
 # NetBSD permits setting dbregs either if one is root
 # or if user_set_dbregs is enabled
 can_set_dbregs = True
Index: lldb/test/Shell/helper/toolchain.py
===
--- lldb/test/Shell/helper/toolchain.py
+++ lldb/test/Shell/helper/toolchain.py
@@ -42,6 +42,8 @@
 build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
 if config.llvm_libs_dir:
 build_script_args.append('--libs-dir={0}'.format(config.llvm_libs_dir))
+if config.objc_gnustep_dir:
+build_script_args.append('--objc-gnustep-dir="{0}"'.format(config.objc_gnustep_dir))
 
 lldb_init = _get_lldb_init_path(config)
 
Index: lldb/test/Shell/helper/build.py
===
--- lldb/test/Shell/helper/build.py
+++ lldb/test/Shell/helper/build.py
@@ -49,6 +49,18 @@
 action='append',
 help='If specified, a path to search in addition to PATH when --compiler is not an exact path')
 
+parser.add_argument('--objc-gnustep-dir',
+metavar='directory',
+dest='objc_gnustep_dir',
+required=False,
+help='If specified, a path to GNUstep libobjc2 runtime for use on Windows and Linux')
+
+parser.add_argument('--objc-gnustep',
+dest='objc_gnustep',
+action='store_true',
+default=False,
+help='Windows and Linux include/link GNUstep libobjc2 for this build')
+
 if sys.platform == 'darwin':
 parser.add_argument('--apple-sdk',
 metavar='apple_sdk',
@@ -238,6 +250,10 @@
 self.obj_ext = obj_ext
 self.lib_paths = args.libs_dir
 self.std = args.std
+if args.objc_gnustep:
+assert args.objc_gnustep_dir, "GNUstep libobjc2 runtime for Linux and Windows"
+self.objc_gnustep_inc = os.path.join(args.objc_gnustep_dir, 'include')
+self.objc_gnustep_lib = os.path.join(args.objc_gnustep_dir, 'lib')
 
 def _exe_file_name(self):
 assert self.mode != 'compile'
@@ -656,15 +672,20 @@
 args.append('-static')
 args.append('-c')
 
-args.extend(['-o', obj])
-args.append(source

[Lldb-commits] [PATCH] D138750: [lldb][JITLoaderGDB] Resolve __jit_debug_register_code as eSymbolTypeCode

2022-11-27 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc1a419c6cf6d: [lldb][JITLoaderGDB] Resolve 
__jit_debug_register_code as eSymbolTypeCode (authored by sgraenitz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138750

Files:
  lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
  lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
  lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -1,6 +1,4 @@
 # REQUIRES: target-x86_64
-# https://github.com/llvm/llvm-project/issues/56085
-# XFAIL: system-freebsd
 # XFAIL: system-windows
 
 # RuntimeDyld can be used to link and load emitted code for both, MCJIT and 
Orc.
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,6 +1,4 @@
 # REQUIRES: target-x86_64
-# https://github.com/llvm/llvm-project/issues/56085
-# XFAIL: system-freebsd
 # XFAIL: system-windows
 
 # JITLink is the Orc-specific JIT linker implementation.
Index: lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
===
--- lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
+++ lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
@@ -190,7 +190,7 @@
 __FUNCTION__);
 
   addr_t jit_addr = GetSymbolAddress(
-  module_list, ConstString("__jit_debug_register_code"), eSymbolTypeAny);
+  module_list, ConstString("__jit_debug_register_code"), eSymbolTypeCode);
   if (jit_addr == LLDB_INVALID_ADDRESS)
 return;
 


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -1,6 +1,4 @@
 # REQUIRES: target-x86_64
-# https://github.com/llvm/llvm-project/issues/56085
-# XFAIL: system-freebsd
 # XFAIL: system-windows
 
 # RuntimeDyld can be used to link and load emitted code for both, MCJIT and Orc.
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,6 +1,4 @@
 # REQUIRES: target-x86_64
-# https://github.com/llvm/llvm-project/issues/56085
-# XFAIL: system-freebsd
 # XFAIL: system-windows
 
 # JITLink is the Orc-specific JIT linker implementation.
Index: lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
===
--- lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
+++ lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
@@ -190,7 +190,7 @@
 __FUNCTION__);
 
   addr_t jit_addr = GetSymbolAddress(
-  module_list, ConstString("__jit_debug_register_code"), eSymbolTypeAny);
+  module_list, ConstString("__jit_debug_register_code"), eSymbolTypeCode);
   if (jit_addr == LLDB_INVALID_ADDRESS)
 return;
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D138750: [lldb][JITLoaderGDB] Resolve __jit_debug_register_code as eSymbolTypeCode

2022-11-26 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: mgorny, labath.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a project: LLDB.

Fix failling jit-loader tests in SHARED_LIBS build as discussed in 
https://github.com/llvm/llvm-project/issues/56085


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138750

Files:
  lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
  lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
  lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -1,6 +1,4 @@
 # REQUIRES: target-x86_64
-# https://github.com/llvm/llvm-project/issues/56085
-# XFAIL: system-freebsd
 # XFAIL: system-windows
 
 # RuntimeDyld can be used to link and load emitted code for both, MCJIT and 
Orc.
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,6 +1,4 @@
 # REQUIRES: target-x86_64
-# https://github.com/llvm/llvm-project/issues/56085
-# XFAIL: system-freebsd
 # XFAIL: system-windows
 
 # JITLink is the Orc-specific JIT linker implementation.
Index: lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
===
--- lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
+++ lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
@@ -190,7 +190,7 @@
 __FUNCTION__);
 
   addr_t jit_addr = GetSymbolAddress(
-  module_list, ConstString("__jit_debug_register_code"), eSymbolTypeAny);
+  module_list, ConstString("__jit_debug_register_code"), eSymbolTypeCode);
   if (jit_addr == LLDB_INVALID_ADDRESS)
 return;
 


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -1,6 +1,4 @@
 # REQUIRES: target-x86_64
-# https://github.com/llvm/llvm-project/issues/56085
-# XFAIL: system-freebsd
 # XFAIL: system-windows
 
 # RuntimeDyld can be used to link and load emitted code for both, MCJIT and Orc.
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,6 +1,4 @@
 # REQUIRES: target-x86_64
-# https://github.com/llvm/llvm-project/issues/56085
-# XFAIL: system-freebsd
 # XFAIL: system-windows
 
 # JITLink is the Orc-specific JIT linker implementation.
Index: lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
===
--- lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
+++ lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
@@ -190,7 +190,7 @@
 __FUNCTION__);
 
   addr_t jit_addr = GetSymbolAddress(
-  module_list, ConstString("__jit_debug_register_code"), eSymbolTypeAny);
+  module_list, ConstString("__jit_debug_register_code"), eSymbolTypeCode);
   if (jit_addr == LLDB_INVALID_ADDRESS)
 return;
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96634: [lldb][JITLoaderGDB] Test debug support in llvm-jitlink

2021-03-09 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2ff533cba18a: [lldb][JITLoaderGDB] Test debug support in 
JITLink (authored by sgraenitz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96634

Files:
  lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
  lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
  lldb/test/Shell/Breakpoint/jitbp_elf.test


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -1,11 +1,21 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll 
%p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
-o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
+# RuntimeDyld can be used to link and load emitted code for both, MCJIT and 
Orc.
+#
+# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf \
+# RUN:-o %t.ll %p/Inputs/jitbp.cpp
+#
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
\
+# RUN:  -o 'run --jit-kind=mcjit %t.ll' \
+# RUN:  lli | FileCheck %s
+#
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
\
+# RUN:  -o 'run --jit-kind=orc-lazy --per-module-lazy 
--jit-linker=rtdyld %t.ll' \
+# RUN:  lli | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,11 +1,16 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll 
%p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
-o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
+# JITLink is the Orc-specific JIT linker implementation.
+#
+# RUN: %clang -g -S -emit-llvm -fPIC --target=x86_64-unknown-unknown-elf \
+# RUN:-o %t.ll %p/Inputs/jitbp.cpp
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
\
+# RUN:  -o 'run --jit-kind=orc-lazy --per-module-lazy 
--jit-linker=jitlink %t.ll' \
+# RUN:  lli | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -1,11 +1,21 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll %p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' -o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
+# RuntimeDyld can be used to link and load emitted code for both, MCJIT and Orc.
+#
+# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf \
+# RUN:-o %t.ll %p/Inputs/jitbp.cpp
+#
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' \
+# RUN:  -o 'run --jit-kind=mcjit %t.ll' \
+# RUN:  lli | FileCheck %s
+#
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' \
+# RUN:  -o 'run --jit-kind=orc-lazy --per-module-lazy --jit-linker=rtdyld %t.ll' \
+# RUN:  lli | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,11 +1,16 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll %p/Inputs/jitbp.cpp
-# RUN: %lldb -b 

[Lldb-commits] [PATCH] D96634: [lldb][JITLoaderGDB] Test debug support in llvm-jitlink

2021-03-09 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 329301.
sgraenitz added a comment.

For the entry point, prefer lli over llvm-jitlink. D97339 
 added debug support for JITLink in lli.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96634

Files:
  lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
  lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
  lldb/test/Shell/Breakpoint/jitbp_elf.test


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -1,11 +1,21 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll 
%p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
-o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
+# RuntimeDyld can be used to link and load emitted code for both, MCJIT and 
Orc.
+#
+# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf \
+# RUN:-o %t.ll %p/Inputs/jitbp.cpp
+#
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
\
+# RUN:  -o 'run --jit-kind=mcjit %t.ll' \
+# RUN:  lli | FileCheck %s
+#
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
\
+# RUN:  -o 'run --jit-kind=orc-lazy --per-module-lazy 
--jit-linker=rtdyld %t.ll' \
+# RUN:  lli | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,11 +1,16 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll 
%p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
-o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
+# JITLink is the Orc-specific JIT linker implementation.
+#
+# RUN: %clang -g -S -emit-llvm -fPIC --target=x86_64-unknown-unknown-elf \
+# RUN:-o %t.ll %p/Inputs/jitbp.cpp
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
\
+# RUN:  -o 'run --jit-kind=orc-lazy --per-module-lazy 
--jit-linker=jitlink %t.ll' \
+# RUN:  lli | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -1,11 +1,21 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll %p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' -o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
+# RuntimeDyld can be used to link and load emitted code for both, MCJIT and Orc.
+#
+# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf \
+# RUN:-o %t.ll %p/Inputs/jitbp.cpp
+#
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' \
+# RUN:  -o 'run --jit-kind=mcjit %t.ll' \
+# RUN:  lli | FileCheck %s
+#
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' \
+# RUN:  -o 'run --jit-kind=orc-lazy --per-module-lazy --jit-linker=rtdyld %t.ll' \
+# RUN:  lli | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,11 +1,16 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll %p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-lo

[Lldb-commits] [PATCH] D96634: [lldb][JITLoaderGDB] Test debug support in llvm-jitlink

2021-02-16 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Thanks for taking a look. Planning to to give this a try as soon as JITLink 
support landed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96634

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


[Lldb-commits] [PATCH] D96634: [lldb][JITLoaderGDB] Test debug support in llvm-jitlink

2021-02-12 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: labath, teemperor, JDevlieghere, lhames.
sgraenitz requested review of this revision.
Herald added a project: LLDB.

LLVM OrcJIT is shifting from RuntimeDyld to JITLink. Starting with D96627 
 I am planning to add debug support. It would 
be great to have test coverage for it in LLDB early on.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96634

Files:
  lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
  lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
  lldb/test/Shell/Breakpoint/jitbp_elf.test


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -5,7 +5,7 @@
 # RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
-o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run -jit-kind=mcjit {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,11 +1,11 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll 
%p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
-o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
+# RUN: %clang -c -g -fPIC --target=x86_64-unknown-unknown-elf -o %t.o 
%p/Inputs/jitbp.cpp
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
-o 'run %t.o' llvm-jitlink | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -5,7 +5,7 @@
 # RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' -o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run -jit-kind=mcjit {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,11 +1,11 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll %p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' -o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
+# RUN: %clang -c -g -fPIC --target=x86_64-unknown-unknown-elf -o %t.o %p/Inputs/jitbp.cpp
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' -o 'run %t.o' llvm-jitlink | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D90789: [docs] Update DebuggingJITedCode page after fix in LLDB

2021-01-27 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Thanks! Eventually, I closed https://llvm.org/PR36209


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90789

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


[Lldb-commits] [PATCH] D90789: [docs] Update DebuggingJITedCode page after fix in LLDB

2021-01-27 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG332e220ef42b: [docs] Update DebuggingJITedCode page after 
fix in LLDB (authored by sgraenitz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90789

Files:
  llvm/docs/DebuggingJITedCode.rst

Index: llvm/docs/DebuggingJITedCode.rst
===
--- llvm/docs/DebuggingJITedCode.rst
+++ llvm/docs/DebuggingJITedCode.rst
@@ -1,35 +1,48 @@
-==
-Debugging JIT-ed Code With GDB
-==
+=
+Debugging JIT-ed Code
+=
 
 Background
 ==
 
-Without special runtime support, debugging dynamically generated code with
-GDB (as well as most debuggers) can be quite painful.  Debuggers generally
-read debug information from the object file of the code, but for JITed
-code, there is no such file to look for.
-
-In order to communicate the necessary debug info to GDB, an interface for
-registering JITed code with debuggers has been designed and implemented for
-GDB and LLVM MCJIT.  At a high level, whenever MCJIT generates new machine code,
-it does so in an in-memory object file that contains the debug information in
-DWARF format.  MCJIT then adds this in-memory object file to a global list of
-dynamically generated object files and calls a special function
-(``__jit_debug_register_code``) marked noinline that GDB knows about.  When
-GDB attaches to a process, it puts a breakpoint in this function and loads all
-of the object files in the global list.  When MCJIT calls the registration
-function, GDB catches the breakpoint signal, loads the new object file from
-the inferior's memory, and resumes the execution.  In this way, GDB can get the
-necessary debug information.
+Without special runtime support, debugging dynamically generated code can be
+quite painful.  Debuggers generally read debug information from object files on
+disk, but for JITed code there is no such file to look for.
+
+In order to hand over the necessary debug info, `GDB established an
+interface `_
+for registering JITed code with debuggers. LLDB implements it in the
+JITLoaderGDB plugin.  On the JIT side, LLVM MCJIT does implement the interface
+for ELF object files.
+
+At a high level, whenever MCJIT generates new machine code, it does so in an
+in-memory object file that contains the debug information in DWARF format.
+MCJIT then adds this in-memory object file to a global list of dynamically
+generated object files and calls a special function
+``__jit_debug_register_code`` that the debugger knows about. When the debugger
+attaches to a process, it puts a breakpoint in this function and associates a
+special handler with it.  Once MCJIT calls the registration function, the
+debugger catches the breakpoint signal, loads the new object file from the
+inferior's memory and resumes execution.  This way it can obtain debug
+information for pure in-memory object files.
+
 
 GDB Version
 ===
 
 In order to debug code JIT-ed by LLVM, you need GDB 7.0 or newer, which is
 available on most modern distributions of Linux.  The version of GDB that
-Apple ships with Xcode has been frozen at 6.3 for a while.  LLDB may be a
-better option for debugging JIT-ed code on macOS.
+Apple ships with Xcode has been frozen at 6.3 for a while.
+
+
+LLDB Version
+
+
+Due to a regression in release 6.0, LLDB didn't support JITed code debugging for
+a while.  The bug was fixed in mainline recently, so that debugging JITed ELF
+objects should be possible again from the upcoming release 12.0 on. On macOS the
+feature must be enabled explicitly using the ``plugin.jit-loader.gdb.enable``
+setting.
 
 
 Debugging MCJIT-ed code
@@ -39,8 +52,8 @@
 GDB.  This is due to MCJIT's ability to use the MC emitter to provide full
 DWARF debugging information to GDB.
 
-Note that lli has to be passed the ``-jit-kind=mcjit`` flag to JIT the code with
-MCJIT instead of the old JIT.
+Note that lli has to be passed the ``--jit-kind=mcjit`` flag to JIT the code
+with MCJIT instead of the newer ORC JIT.
 
 Example
 ---
@@ -81,63 +94,89 @@
22  }
 
 Here is a sample command line session that shows how to build and run this
-code via ``lli`` inside GDB:
+code via ``lli`` inside LLDB:
 
 .. code-block:: bash
 
-   $ $BINPATH/clang -cc1 -O0 -g -emit-llvm showdebug.c
-   $ gdb --quiet --args $BINPATH/lli -jit-kind=mcjit showdebug.ll 5
-   Reading symbols from $BINPATH/lli...done.
-   (gdb) b showdebug.c:6
-   No source file named showdebug.c.
-   Make breakpoint pending on future shared library load? (y or [n]) y
-   Breakpoint 1 (showdebug.c:6) pending.
-   (gdb) r
-   Starting program: $BINPATH/lli -jit-kind=mcjit showdebug.ll 5

[Lldb-commits] [PATCH] D90789: [docs] Update DebuggingJITedCode page after fix in LLDB

2021-01-13 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

I'd like to land this before release 12 branches. If you have any objections, 
please speak up before the end of the week. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90789

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


[Lldb-commits] [PATCH] D90789: [docs] Update DebuggingJITedCode page after fix in LLDB

2020-12-03 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Does anyone have objections to this documentation update? Preview is here still:
https://weliveindetail.github.io/docs-pub/html/DebuggingJITedCode.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90789

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


[Lldb-commits] [PATCH] D90789: [docs] Update DebuggingJITedCode page after fix in LLDB

2020-11-16 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

One issue with the `orc-lazy` JIT will be symbol renaming for lazy reexports: 
Upfront we only emit stubs for our function symbols and they trigger 
compilation of the actual code in a separate logical unit once they are called. 
The debug object we hand over to LLDB doesn't take that into account. (Maybe we 
are just inserting the wrong load address? Don't know.) Additionally, I am not 
sure how debug data is handled in the partitioning logic of the 
CompileOnDemandLayer.

If we had a `orc-greedy`mode in lli, we could easily demonstrate debugging here 
(for RTDyld-based platforms) and we could also port quite a number of tests to 
OrcV2. Might be worth thinking about, but so far we have MCJIT for that and it 
still works.

Not sure any of this is worth noting in the docs?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90789

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


[Lldb-commits] [PATCH] D90789: [docs] Update DebuggingJITedCode page after fix in LLDB

2020-11-16 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Thanks for having a look.

That's right and it's on my wishlist. However, the example doesn't actually 
work with `--jit-kind=orc-lazy` (yet). On Linux it should use 
RTDyldObjectLinkingLayer and so it should notify LLDB when new code is loaded, 
but somehow it doesn't:

  (lldb) run --jit-kind=orc-lazy showdebug.ll 5
  Process 25021 launched: '/usr/bin/lli' (x86_64)
  Process 25021 exited with status = 120 (0x0078) 

So far I haven't analyzed it in detail. My plan was to finish the ongoing work, 
update the docs, close PR36209  
(finally) and schedule follow-up tasks once I find the time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90789

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


[Lldb-commits] [PATCH] D90769: [lldb][ObjectFile] Relocate sections for in-memory objects (e.g. received via JITLoaderGDB)

2020-11-10 Thread Stefan Gränitz via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG203b4774b883: [lldb][ObjectFile] Relocate sections for 
in-memory objects (e.g. received via… (authored by sgraenitz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90769

Files:
  lldb/source/Symbol/ObjectFile.cpp
  lldb/test/Shell/Breakpoint/jitbp_elf.test


Index: lldb/test/Shell/Breakpoint/jitbp_elf.test
===
--- lldb/test/Shell/Breakpoint/jitbp_elf.test
+++ lldb/test/Shell/Breakpoint/jitbp_elf.test
@@ -7,5 +7,8 @@
 # CHECK: Breakpoint 1: no locations (pending).
 # CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
 # CHECK: Process {{.*}} stopped
-# CHECK: JIT(0x{{.*}})`jitbp:
+# CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
+# CHECK: -> 1int jitbp() { return 0; }
+# CHECK:   ^
+# CHECK:2int main() { return jitbp(); }
 # CHECK: Process {{.*}} launched: {{.*}}
Index: lldb/source/Symbol/ObjectFile.cpp
===
--- lldb/source/Symbol/ObjectFile.cpp
+++ lldb/source/Symbol/ObjectFile.cpp
@@ -503,6 +503,9 @@
 return section->GetObjectFile()->ReadSectionData(section, section_offset,
  dst, dst_len);
 
+  if (!section->IsRelocated())
+RelocateSection(section);
+
   if (IsInMemory()) {
 ProcessSP process_sp(m_process_wp.lock());
 if (process_sp) {
@@ -514,9 +517,6 @@
   dst_len, error);
 }
   } else {
-if (!section->IsRelocated())
-  RelocateSection(section);
-
 const lldb::offset_t section_file_size = section->GetFileSize();
 if (section_offset < section_file_size) {
   const size_t section_bytes_left = section_file_size - section_offset;
@@ -547,6 +547,9 @@
   if (section->GetObjectFile() != this)
 return section->GetObjectFile()->ReadSectionData(section, section_data);
 
+  if (!section->IsRelocated())
+RelocateSection(section);
+
   if (IsInMemory()) {
 ProcessSP process_sp(m_process_wp.lock());
 if (process_sp) {
@@ -563,17 +566,12 @@
 }
   }
 }
-return GetData(section->GetFileOffset(), section->GetFileSize(),
-   section_data);
-  } else {
-// The object file now contains a full mmap'ed copy of the object file
-// data, so just use this
-if (!section->IsRelocated())
-  RelocateSection(section);
-
-return GetData(section->GetFileOffset(), section->GetFileSize(),
-   section_data);
   }
+
+  // The object file now contains a full mmap'ed copy of the object file
+  // data, so just use this
+  return GetData(section->GetFileOffset(), section->GetFileSize(),
+  section_data);
 }
 
 bool ObjectFile::SplitArchivePathWithObject(llvm::StringRef path_with_object,


Index: lldb/test/Shell/Breakpoint/jitbp_elf.test
===
--- lldb/test/Shell/Breakpoint/jitbp_elf.test
+++ lldb/test/Shell/Breakpoint/jitbp_elf.test
@@ -7,5 +7,8 @@
 # CHECK: Breakpoint 1: no locations (pending).
 # CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
 # CHECK: Process {{.*}} stopped
-# CHECK: JIT(0x{{.*}})`jitbp:
+# CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
+# CHECK: -> 1int jitbp() { return 0; }
+# CHECK:   ^
+# CHECK:2int main() { return jitbp(); }
 # CHECK: Process {{.*}} launched: {{.*}}
Index: lldb/source/Symbol/ObjectFile.cpp
===
--- lldb/source/Symbol/ObjectFile.cpp
+++ lldb/source/Symbol/ObjectFile.cpp
@@ -503,6 +503,9 @@
 return section->GetObjectFile()->ReadSectionData(section, section_offset,
  dst, dst_len);
 
+  if (!section->IsRelocated())
+RelocateSection(section);
+
   if (IsInMemory()) {
 ProcessSP process_sp(m_process_wp.lock());
 if (process_sp) {
@@ -514,9 +517,6 @@
   dst_len, error);
 }
   } else {
-if (!section->IsRelocated())
-  RelocateSection(section);
-
 const lldb::offset_t section_file_size = section->GetFileSize();
 if (section_offset < section_file_size) {
   const size_t section_bytes_left = section_file_size - section_offset;
@@ -547,6 +547,9 @@
   if (section->GetObjectFile() != this)
 return section->GetObjectFile()->ReadSectionData(section, section_data);
 
+  if (!section->IsRelocated())
+RelocateSection(section);
+
   if (IsInMemory()) {
 ProcessSP process_sp(m_process_wp.lock());
 if (process_sp) {
@@ -563,17 +566,12 @@
 }
   }
 }
-return GetData(section->GetFileOffset(), section->GetFileSize(),
-   section_data);
-  } else {
-   

[Lldb-commits] [PATCH] D90769: [lldb][ObjectFile] Relocate sections for in-memory objects (e.g. received via JITLoaderGDB)

2020-11-06 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

That's right, but I don't see how even the static ones could be resolved. 
Wouldn't it hard-wire the objects together? In the next session we want to load 
some object files from cache while others have changed.. Maybe one day I should 
check how ccache and the likes handle it.

IIRC OSO entries in MachO files point to the object file on disk, which allows 
LLDB to load them lazily? The DWARF parsing for ELF should follow the same 
laziness: each section is only relocated once we need it. It's just not loading 
the object lazily right? However, we couldn't do that even with OSO-style 
entries, because there is no "pull mechanism" in JITLoaderGDB :) Well, for now 
it just works.

I will leave the review here for another day or so, in case there's more 
feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90769

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


[Lldb-commits] [PATCH] D90769: [lldb][ObjectFile] Relocate sections for in-memory objects (e.g. received via JITLoaderGDB)

2020-11-05 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Thanks for having a look!

The JIT implementations in LLVM operate on relocatable object files, so someone 
needs to resolve them. MCJIT has a flag `ProcessAllSections` to control which 
sections will be loaded and relocated. As it is off by default, it will usually 
ignore sections that it doesn't need for execution. LLDB does it the other way 
around in ObjectFileELF::RelocateSection(), it only processes sections with the 
".debug" prefix. This seems to be a reasonable distribution of tasks. In 
general, relocations are resolved in place, so it doesn't rise memory 
consumption.

> I do wonder though if the jit could be changed to avoid relocation.

Well, I don't think we are anywhere close to optimizations like this, but it 
would be nice indeed. If we compile from bitcode on the JIT side, we could 
lookup external symbols at compile-time and don't produce relocations for them 
in the first place. I guess it would heavily reduce the number of relocations 
and potentially save time. On the other hand, thinking about concurrent compile 
jobs and cross-dependencies.. I can imagine it gets hairy quickly. Plus: the 
way it is now, we can cache the object files and reuse them thanks to 
position-independent code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90769

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


[Lldb-commits] [PATCH] D90789: [docs] Update DebuggingJITedCode page after fix in LLDB

2020-11-04 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

LLDB regression https://bugs.llvm.org/show_bug.cgi?id=36209 fixed with D61611 
 and D90769 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90789

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


[Lldb-commits] [PATCH] D90789: [docs] Update DebuggingJITedCode page after fix in LLDB

2020-11-04 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

Preview for the update: 
https://weliveindetail.github.io/docs-pub/html/DebuggingJITedCode.html (well I 
hope styles and scripts will pop up at some point).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90789

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


[Lldb-commits] [PATCH] D90789: [docs] Update DebuggingJITedCode page after fix in LLDB

2020-11-04 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: rnk, eliben.
Herald added a project: LLVM.
sgraenitz requested review of this revision.

Generalize the documentation to include both, GDB and LLDB. Add a link to the 
interface
definition. Make a note on MCJIT's restriction to ELF. Mention the regression 
and bugfix
in LLDB as well as the jit-loader setting for macOS. Update the command line 
session to
use LLDB instead of GDB.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90789

Files:
  llvm/docs/DebuggingJITedCode.rst

Index: llvm/docs/DebuggingJITedCode.rst
===
--- llvm/docs/DebuggingJITedCode.rst
+++ llvm/docs/DebuggingJITedCode.rst
@@ -1,35 +1,48 @@
-==
-Debugging JIT-ed Code With GDB
-==
+=
+Debugging JIT-ed Code
+=
 
 Background
 ==
 
-Without special runtime support, debugging dynamically generated code with
-GDB (as well as most debuggers) can be quite painful.  Debuggers generally
-read debug information from the object file of the code, but for JITed
-code, there is no such file to look for.
-
-In order to communicate the necessary debug info to GDB, an interface for
-registering JITed code with debuggers has been designed and implemented for
-GDB and LLVM MCJIT.  At a high level, whenever MCJIT generates new machine code,
-it does so in an in-memory object file that contains the debug information in
-DWARF format.  MCJIT then adds this in-memory object file to a global list of
-dynamically generated object files and calls a special function
-(``__jit_debug_register_code``) marked noinline that GDB knows about.  When
-GDB attaches to a process, it puts a breakpoint in this function and loads all
-of the object files in the global list.  When MCJIT calls the registration
-function, GDB catches the breakpoint signal, loads the new object file from
-the inferior's memory, and resumes the execution.  In this way, GDB can get the
-necessary debug information.
+Without special runtime support, debugging dynamically generated code can be
+quite painful.  Debuggers generally read debug information from object files on
+disk, but for JITed code there is no such file to look for.
+
+In order to hand over the necessary debug info, `GDB established an
+interface `_
+for registering JITed code with debuggers. LLDB implements it in the
+JITLoaderGDB plugin.  On the JIT side, LLVM MCJIT does implement the interface
+for ELF object files.
+
+At a high level, whenever MCJIT generates new machine code, it does so in an
+in-memory object file that contains the debug information in DWARF format.
+MCJIT then adds this in-memory object file to a global list of dynamically
+generated object files and calls a special function
+``__jit_debug_register_code`` that the debugger knows about. When the debugger
+attaches to a process, it puts a breakpoint in this function and associates a
+special handler with it.  Once MCJIT calls the registration function, the
+debugger catches the breakpoint signal, loads the new object file from the
+inferior's memory and resumes execution.  This way it can obtain debug
+information for pure in-memory object files.
+
 
 GDB Version
 ===
 
 In order to debug code JIT-ed by LLVM, you need GDB 7.0 or newer, which is
 available on most modern distributions of Linux.  The version of GDB that
-Apple ships with Xcode has been frozen at 6.3 for a while.  LLDB may be a
-better option for debugging JIT-ed code on macOS.
+Apple ships with Xcode has been frozen at 6.3 for a while.
+
+
+LLDB Version
+
+
+Due to a regression in release 6.0, LLDB didn't support JITed code debugging for
+a while.  The bug was fixed in mainline recently, so that debugging JITed ELF
+objects should be possible again from the upcoming release 12.0 on. On macOS the
+feature must be enabled explicitly using the ``plugin.jit-loader.gdb.enable``
+setting.
 
 
 Debugging MCJIT-ed code
@@ -39,8 +52,8 @@
 GDB.  This is due to MCJIT's ability to use the MC emitter to provide full
 DWARF debugging information to GDB.
 
-Note that lli has to be passed the ``-jit-kind=mcjit`` flag to JIT the code with
-MCJIT instead of the old JIT.
+Note that lli has to be passed the ``--jit-kind=mcjit`` flag to JIT the code
+with MCJIT instead of the newer ORC JIT.
 
 Example
 ---
@@ -81,63 +94,89 @@
22  }
 
 Here is a sample command line session that shows how to build and run this
-code via ``lli`` inside GDB:
+code via ``lli`` inside LLDB:
 
 .. code-block:: bash
 
-   $ $BINPATH/clang -cc1 -O0 -g -emit-llvm showdebug.c
-   $ gdb --quiet --args $BINPATH/lli -jit-kind=mcjit showdebug.ll 5
-   Reading symbols from $BINPATH/lli...done.
-   (gdb) b showdebug.c:6
-   No source file named showdebug.c.
-   Make breakpoint pending on future shared library load? (

[Lldb-commits] [PATCH] D90769: [lldb][ObjectFile] Relocate sections for in-memory objects (e.g. received via JITLoaderGDB)

2020-11-04 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: labath, clayborg, bkoropoff, loladiro, lhames.
Herald added a project: LLDB.
sgraenitz requested review of this revision.
Herald added a subscriber: JDevlieghere.

Part 2 of a fix for JITed code debugging. This has been a regression from 5.0 
to 6.0 and it's still reproducible on current master: 
https://bugs.llvm.org/show_bug.cgi?id=36209 Part 1 was D61611 
 a while ago.

The in-memory object files we obtain from JITLoaderGDB are not yet relocated. 
It looks like this used to happen on the LLDB side and my guess is that it 
broke with D38142 . (However, it's hard to 
tell because the whole thing was broken already due to the bug in part 1.) The 
patch moved relocation resolution to a later point in time and didn't apply it 
to in-memory objects. I am not aware of any reason why we wouldn't resolve 
relocations per-se, so I made it unconditional here. On Debian, it fixes the 
bug for me and all tests in `check-lldb` are still fine.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90769

Files:
  lldb/source/Symbol/ObjectFile.cpp
  lldb/test/Shell/Breakpoint/jitbp_elf.test


Index: lldb/test/Shell/Breakpoint/jitbp_elf.test
===
--- lldb/test/Shell/Breakpoint/jitbp_elf.test
+++ lldb/test/Shell/Breakpoint/jitbp_elf.test
@@ -7,5 +7,8 @@
 # CHECK: Breakpoint 1: no locations (pending).
 # CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
 # CHECK: Process {{.*}} stopped
-# CHECK: JIT(0x{{.*}})`jitbp:
+# CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
+# CHECK: -> 1int jitbp() { return 0; }
+# CHECK:   ^
+# CHECK:2int main() { return jitbp(); }
 # CHECK: Process {{.*}} launched: {{.*}}
Index: lldb/source/Symbol/ObjectFile.cpp
===
--- lldb/source/Symbol/ObjectFile.cpp
+++ lldb/source/Symbol/ObjectFile.cpp
@@ -503,6 +503,9 @@
 return section->GetObjectFile()->ReadSectionData(section, section_offset,
  dst, dst_len);
 
+  if (!section->IsRelocated())
+RelocateSection(section);
+
   if (IsInMemory()) {
 ProcessSP process_sp(m_process_wp.lock());
 if (process_sp) {
@@ -514,9 +517,6 @@
   dst_len, error);
 }
   } else {
-if (!section->IsRelocated())
-  RelocateSection(section);
-
 const lldb::offset_t section_file_size = section->GetFileSize();
 if (section_offset < section_file_size) {
   const size_t section_bytes_left = section_file_size - section_offset;
@@ -547,6 +547,9 @@
   if (section->GetObjectFile() != this)
 return section->GetObjectFile()->ReadSectionData(section, section_data);
 
+  if (!section->IsRelocated())
+RelocateSection(section);
+
   if (IsInMemory()) {
 ProcessSP process_sp(m_process_wp.lock());
 if (process_sp) {
@@ -563,17 +566,12 @@
 }
   }
 }
-return GetData(section->GetFileOffset(), section->GetFileSize(),
-   section_data);
-  } else {
-// The object file now contains a full mmap'ed copy of the object file
-// data, so just use this
-if (!section->IsRelocated())
-  RelocateSection(section);
-
-return GetData(section->GetFileOffset(), section->GetFileSize(),
-   section_data);
   }
+
+  // The object file now contains a full mmap'ed copy of the object file
+  // data, so just use this
+  return GetData(section->GetFileOffset(), section->GetFileSize(),
+  section_data);
 }
 
 bool ObjectFile::SplitArchivePathWithObject(llvm::StringRef path_with_object,


Index: lldb/test/Shell/Breakpoint/jitbp_elf.test
===
--- lldb/test/Shell/Breakpoint/jitbp_elf.test
+++ lldb/test/Shell/Breakpoint/jitbp_elf.test
@@ -7,5 +7,8 @@
 # CHECK: Breakpoint 1: no locations (pending).
 # CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
 # CHECK: Process {{.*}} stopped
-# CHECK: JIT(0x{{.*}})`jitbp:
+# CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
+# CHECK: -> 1int jitbp() { return 0; }
+# CHECK:   ^
+# CHECK:2int main() { return jitbp(); }
 # CHECK: Process {{.*}} launched: {{.*}}
Index: lldb/source/Symbol/ObjectFile.cpp
===
--- lldb/source/Symbol/ObjectFile.cpp
+++ lldb/source/Symbol/ObjectFile.cpp
@@ -503,6 +503,9 @@
 return section->GetObjectFile()->ReadSectionData(section, section_offset,
  dst, dst_len);
 
+  if (!section->IsRelocated())
+RelocateSection(section);
+
   if (IsInMemory()) {
 ProcessSP process_sp(m_process_wp.lock());
 if (process_sp) {
@@ -514,9 +517,6 @@
   dst_len, error);
 }
   } e

[Lldb-commits] [PATCH] D69589: [lldb] Refactor all POST_BUILD commands into targets

2019-12-04 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added a comment.

I'd recommend to be careful when making a change of this size. There are a lot 
of possible configurations.
If you split it up into a few smaller and more dedicated commits, you will make 
your life easier. Otherwise someone might just revert everything if this 
happens to break a bot.

In D69589#1736299 , @aadsm wrote:

> Yeah, weird. I wonder if this is something cmake does implicitly when the 
> target is defined as `FRAMEWORK`: 
> https://cmake.org/cmake/help/latest/prop_tgt/FRAMEWORK.html


This is correct. There is a comment mentioning it here:
https://github.com/llvm/llvm-project/blob/276a5b2d5f1f/lldb/cmake/modules/LLDBFramework.cmake#L44




Comment at: lldb/CMakeLists.txt:204
 
-  function(create_relative_symlink target dest_file output_dir output_name)
+  function(add_relative_symlink_target name dest_file output_dir output_name)
 get_filename_component(dest_file ${dest_file} ABSOLUTE)

This change e.g. is reasonable, but unrelated. It could go into a separate NFC 
commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69589



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


[Lldb-commits] [PATCH] D65798: [lldb][CMake] Infer `Clang_DIR` if not passed explicitly

2019-08-08 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz updated this revision to Diff 214139.
sgraenitz added a comment.

Achieve the same via extra `HINT` to `find_package(Clang ...)`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65798

Files:
  lldb/cmake/modules/LLDBStandalone.cmake
  lldb/docs/resources/build.rst


Index: lldb/docs/resources/build.rst
===
--- lldb/docs/resources/build.rst
+++ lldb/docs/resources/build.rst
@@ -120,10 +120,11 @@
 *
 
 This is another way to build LLDB. We can use the same source-tree as we
-checked out above, but now we will have two build-trees:
+checked out above, but now we will have multiple build-trees:
 
 * the main build-tree for LLDB in ``/path/to/lldb-build``
-* a provided build-tree for LLVM and Clang in ``/path/to/llvm-build``
+* one or more provided build-trees for LLVM and Clang; for simplicity we use a
+  single one in ``/path/to/llvm-build``
 
 Run CMake with ``-B`` pointing to a new directory for the provided
 build-tree\ :sup:`1` and the positional argument pointing to the ``llvm``
@@ -139,15 +140,15 @@
 
 Now run CMake a second time with ``-B`` pointing to a new directory for the
 main build-tree and the positional argument pointing to the ``lldb`` directory
-in the source-tree. In order to find the provided build-tree, the build-system
-needs the options ``LLVM_DIR`` and ``Clang_DIR`` (CMake variables are
-case-sensitive!):
+in the source-tree. In order to find the provided build-tree, the build system
+looks for the path to its CMake modules in ``LLVM_DIR``. If you use a separate
+build directory for Clang, remember to pass its module path via ``Clang_DIR``
+(CMake variables are case-sensitive!):
 
 ::
 
   > cmake -B /path/to/lldb-build -G Ninja \
   -DLLVM_DIR=/path/to/llvm-build/lib/cmake/llvm \
-  -DClang_DIR=/path/to/llvm-build/lib/cmake/clang \
   [] /path/to/llvm-project/lldb
   > ninja lldb
 
@@ -323,7 +324,6 @@
   > cmake -B /path/to/lldb-build \
   -C /path/to/llvm-project/lldb/cmake/caches/Apple-lldb-Xcode.cmake \
   -DLLVM_DIR=/path/to/llvm-build/lib/cmake/llvm \
-  -DClang_DIR=/path/to/llvm-build/lib/cmake/clang \
   llvm-project/lldb
   > open lldb.xcodeproj
   > cmake --build /path/to/lldb-build --target check-lldb
Index: lldb/cmake/modules/LLDBStandalone.cmake
===
--- lldb/cmake/modules/LLDBStandalone.cmake
+++ lldb/cmake/modules/LLDBStandalone.cmake
@@ -1,7 +1,7 @@
 option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 
'install' target." OFF)
 
-find_package(LLVM REQUIRED CONFIG HINTS "${LLVM_DIR}" NO_CMAKE_FIND_ROOT_PATH)
-find_package(Clang REQUIRED CONFIG HINTS "${Clang_DIR}" 
NO_CMAKE_FIND_ROOT_PATH)
+find_package(LLVM REQUIRED CONFIG HINTS ${LLVM_DIR} NO_CMAKE_FIND_ROOT_PATH)
+find_package(Clang REQUIRED CONFIG HINTS ${Clang_DIR} ${LLVM_DIR}/../clang 
NO_CMAKE_FIND_ROOT_PATH)
 
 # We set LLVM_CMAKE_PATH so that GetSVN.cmake is found correctly when building 
SVNVersion.inc
 set(LLVM_CMAKE_PATH ${LLVM_CMAKE_DIR} CACHE PATH "Path to LLVM CMake modules")


Index: lldb/docs/resources/build.rst
===
--- lldb/docs/resources/build.rst
+++ lldb/docs/resources/build.rst
@@ -120,10 +120,11 @@
 *
 
 This is another way to build LLDB. We can use the same source-tree as we
-checked out above, but now we will have two build-trees:
+checked out above, but now we will have multiple build-trees:
 
 * the main build-tree for LLDB in ``/path/to/lldb-build``
-* a provided build-tree for LLVM and Clang in ``/path/to/llvm-build``
+* one or more provided build-trees for LLVM and Clang; for simplicity we use a
+  single one in ``/path/to/llvm-build``
 
 Run CMake with ``-B`` pointing to a new directory for the provided
 build-tree\ :sup:`1` and the positional argument pointing to the ``llvm``
@@ -139,15 +140,15 @@
 
 Now run CMake a second time with ``-B`` pointing to a new directory for the
 main build-tree and the positional argument pointing to the ``lldb`` directory
-in the source-tree. In order to find the provided build-tree, the build-system
-needs the options ``LLVM_DIR`` and ``Clang_DIR`` (CMake variables are
-case-sensitive!):
+in the source-tree. In order to find the provided build-tree, the build system
+looks for the path to its CMake modules in ``LLVM_DIR``. If you use a separate
+build directory for Clang, remember to pass its module path via ``Clang_DIR``
+(CMake variables are case-sensitive!):
 
 ::
 
   > cmake -B /path/to/lldb-build -G Ninja \
   -DLLVM_DIR=/path/to/llvm-build/lib/cmake/llvm \
-  -DClang_DIR=/path/to/llvm-build/lib/cmake/clang \
   [] /path/to/llvm-project/lldb
   > ninja lldb
 
@@ -323,7 +324,6 @@
   > cmake -B /path/to/lldb-build \
   -C /path/to/llvm-p

[Lldb-commits] [PATCH] D65939: [lldb][CMake] Add LLDB_ENABLE_WERROR option

2019-08-08 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz abandoned this revision.
sgraenitz added a comment.

In D65939#1620780 , @labath wrote:

> So, why doesn't LLVM_ENABLE_WERROR suffice? It looks like that ought to work 
> even in standalone builds...


LLVM_ENABLE_WERROR affects the entire build tree. If another subproject causes 
a warning the build fails. In a way, you are right that this is sufficient, 
because the no-warnings policy seems to work well upstream.
The issue I was trying to solve is, that we can't use the setting with some 
external subprojects, because they are not strictly warning free. But then it 
may be better to have downstream. I agree.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65939



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


[Lldb-commits] [PATCH] D65939: [lldb][CMake] Add LLDB_ENABLE_WERROR option

2019-08-08 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz added inline comments.



Comment at: lldb/cmake/modules/LLDBConfig.cmake:318
+  if(MSVC)
+set(flag_werror "/WX")
+  endif()

I copied the flag from LLVM. Is it the right one for MSVC?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65939



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


[Lldb-commits] [PATCH] D65939: [lldb][CMake] Add LLDB_ENABLE_WERROR option

2019-08-08 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: teemperor, JDevlieghere, davide, labath, 
stella.stamenova.
Herald added a subscriber: mgorny.
Herald added a project: LLDB.

Treat warnings as errors all over LLDB when enabled. Defaults to `OFF`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65939

Files:
  lldb/cmake/caches/Apple-lldb-macOS.cmake
  lldb/cmake/modules/LLDBConfig.cmake


Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -51,6 +51,7 @@
 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
 option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in 
binaries" OFF)
 option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing 
(Darwin only)." OFF)
+option(LLDB_ENABLE_WERROR "Fail and stop if a warning is triggered." 
${LLVM_ENABLE_WERROR})
 
 if(LLDB_BUILD_FRAMEWORK)
   if(NOT APPLE)
@@ -311,6 +312,16 @@
   )
 endif()
 
+if(LLDB_ENABLE_WERROR)
+  set(flag_werror "-Werror")
+  if(MSVC)
+set(flag_werror "/WX")
+  endif()
+
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag_werror}")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag_werror}")
+endif()
+
 # Use the Unicode (UTF-16) APIs by default on Win32
 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
 add_definitions( -D_UNICODE -DUNICODE )
Index: lldb/cmake/caches/Apple-lldb-macOS.cmake
===
--- lldb/cmake/caches/Apple-lldb-macOS.cmake
+++ lldb/cmake/caches/Apple-lldb-macOS.cmake
@@ -2,6 +2,7 @@
 
 set(LLDB_BUILD_FRAMEWORK ON CACHE BOOL "")
 set(LLDB_NO_INSTALL_DEFAULT_RPATH ON CACHE BOOL "")
+set(LLDB_ENABLE_WERROR ON CACHE BOOL "")
 set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11 CACHE STRING "")
 
 # Default install location on the enduser machine. On the build machine, use 
the


Index: lldb/cmake/modules/LLDBConfig.cmake
===
--- lldb/cmake/modules/LLDBConfig.cmake
+++ lldb/cmake/modules/LLDBConfig.cmake
@@ -51,6 +51,7 @@
 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
 option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF)
 option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing (Darwin only)." OFF)
+option(LLDB_ENABLE_WERROR "Fail and stop if a warning is triggered." ${LLVM_ENABLE_WERROR})
 
 if(LLDB_BUILD_FRAMEWORK)
   if(NOT APPLE)
@@ -311,6 +312,16 @@
   )
 endif()
 
+if(LLDB_ENABLE_WERROR)
+  set(flag_werror "-Werror")
+  if(MSVC)
+set(flag_werror "/WX")
+  endif()
+
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag_werror}")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag_werror}")
+endif()
+
 # Use the Unicode (UTF-16) APIs by default on Win32
 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
 add_definitions( -D_UNICODE -DUNICODE )
Index: lldb/cmake/caches/Apple-lldb-macOS.cmake
===
--- lldb/cmake/caches/Apple-lldb-macOS.cmake
+++ lldb/cmake/caches/Apple-lldb-macOS.cmake
@@ -2,6 +2,7 @@
 
 set(LLDB_BUILD_FRAMEWORK ON CACHE BOOL "")
 set(LLDB_NO_INSTALL_DEFAULT_RPATH ON CACHE BOOL "")
+set(LLDB_ENABLE_WERROR ON CACHE BOOL "")
 set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11 CACHE STRING "")
 
 # Default install location on the enduser machine. On the build machine, use the
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D65874: [lldb][CMake] Disable modules in Xcode projects

2019-08-07 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: aprantl, jingham, davide, teemperor.
Herald added a subscriber: mgorny.
Herald added a project: LLDB.

Apparently, module-enabled builds clash with Xcode's analysis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65874

Files:
  lldb/cmake/caches/Apple-lldb-Xcode.cmake


Index: lldb/cmake/caches/Apple-lldb-Xcode.cmake
===
--- lldb/cmake/caches/Apple-lldb-Xcode.cmake
+++ lldb/cmake/caches/Apple-lldb-Xcode.cmake
@@ -6,6 +6,9 @@
 
 set(LLDB_BUILD_FRAMEWORK ON CACHE BOOL "")
 
+# Apparently, module-enabled builds clash with Xcode's analysis.
+set(LLVM_ENABLE_MODULES OFF CACHE BOOL "" FORCE)
+
 # Print a warning with instructions, if we
 # build with Xcode and didn't use this cache.
 set(LLDB_EXPLICIT_XCODE_CACHE_USED ON CACHE INTERNAL "")


Index: lldb/cmake/caches/Apple-lldb-Xcode.cmake
===
--- lldb/cmake/caches/Apple-lldb-Xcode.cmake
+++ lldb/cmake/caches/Apple-lldb-Xcode.cmake
@@ -6,6 +6,9 @@
 
 set(LLDB_BUILD_FRAMEWORK ON CACHE BOOL "")
 
+# Apparently, module-enabled builds clash with Xcode's analysis.
+set(LLVM_ENABLE_MODULES OFF CACHE BOOL "" FORCE)
+
 # Print a warning with instructions, if we
 # build with Xcode and didn't use this cache.
 set(LLDB_EXPLICIT_XCODE_CACHE_USED ON CACHE INTERNAL "")
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


  1   2   3   4   5   6   >