[Lldb-commits] [PATCH] D151045: [lldb/crashlog] Remove tempfile prefix from inlined symbol object file

2023-05-22 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/examples/python/crashlog.py:1165-1168
+if os.path.isdir(obj_dir.name):
+for file in os.listdir(obj_dir.name):
+os.unlink(os.path.join(obj_dir.name, file))
+os.rmdir(obj_dir.name)

JDevlieghere wrote:
> Can you call `obj_dir.cleanup()`, or better, can you wrap this in a `with 
> tempfile.TemporaryDirectory() as obj_dir:`?
+1



Comment at: lldb/examples/python/symbolication.py:371
 
-def add_module(self, target):
+def add_module(self, target, obj_dir=tempfile.TemporaryDirectory()):
 '''Add the Image described in this object to "target" and load the 
sections if "load" is True.'''

JDevlieghere wrote:
> If the `obj_dir` is created this way, it will never be removed. Is anyone 
> relying on the default argument? If not I would make it `None` and change the 
> check on line 387 to `if obj_dir:`. 
+1 on this, we need to cleanup resources.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151045

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


[Lldb-commits] [PATCH] D150709: [lldb][NFCI] Change return type of Language::GetInstanceVariableName

2023-05-22 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGef73ea6cf691: [lldb][NFCI] Change return type of 
Language::GetInstanceVariableName (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150709

Files:
  lldb/include/lldb/Symbol/SymbolContext.h
  lldb/include/lldb/Target/Language.h
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
  lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
  lldb/source/Symbol/SymbolContext.cpp
  lldb/source/Target/StackFrame.cpp


Index: lldb/source/Target/StackFrame.cpp
===
--- lldb/source/Target/StackFrame.cpp
+++ lldb/source/Target/StackFrame.cpp
@@ -567,8 +567,9 @@
 // Check for direct ivars access which helps us with implicit access to
 // ivars using "this" or "self".
 GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock);
-if (auto instance_var_name = m_sc.GetInstanceVariableName()) {
-  var_sp = variable_list->FindVariable(instance_var_name);
+llvm::StringRef instance_var_name = m_sc.GetInstanceVariableName();
+if (!instance_var_name.empty()) {
+  var_sp = variable_list->FindVariable(ConstString(instance_var_name));
   if (var_sp) {
 separator_idx = 0;
 if (Type *var_type = var_sp->GetType())
Index: lldb/source/Symbol/SymbolContext.cpp
===
--- lldb/source/Symbol/SymbolContext.cpp
+++ lldb/source/Symbol/SymbolContext.cpp
@@ -541,7 +541,7 @@
   return nullptr;
 }
 
-ConstString SymbolContext::GetInstanceVariableName() {
+llvm::StringRef SymbolContext::GetInstanceVariableName() {
   LanguageType lang_type = eLanguageTypeUnknown;
 
   if (Block *function_block = GetFunctionBlock())
Index: lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
===
--- lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
+++ lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
@@ -40,7 +40,7 @@
 
   static lldb_private::Language *CreateInstance(lldb::LanguageType language);
 
-  ConstString GetInstanceVariableName() override { return ConstString("self"); 
}
+  llvm::StringRef GetInstanceVariableName() override { return "self"; }
 
   static llvm::StringRef GetPluginNameStatic() { return "objcplusplus"; }
 
Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
===
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
@@ -191,7 +191,7 @@
   return false;
   }
 
-  ConstString GetInstanceVariableName() override { return ConstString("self"); 
}
+  llvm::StringRef GetInstanceVariableName() override { return "self"; }
 
   // PluginInterface protocol
   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
===
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
@@ -165,7 +165,7 @@
   ConstString FindBestAlternateFunctionMangledName(
   const Mangled mangled, const SymbolContext _ctx) const override;
 
-  ConstString GetInstanceVariableName() override { return ConstString("this"); 
}
+  llvm::StringRef GetInstanceVariableName() override { return "this"; }
 
   // PluginInterface protocol
   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
Index: lldb/include/lldb/Target/Language.h
===
--- lldb/include/lldb/Target/Language.h
+++ lldb/include/lldb/Target/Language.h
@@ -326,7 +326,7 @@
 return ConstString();
   }
 
-  virtual ConstString GetInstanceVariableName() { return {}; }
+  virtual llvm::StringRef GetInstanceVariableName() { return {}; }
 
 protected:
   // Classes that inherit from Language can see and modify these
Index: lldb/include/lldb/Symbol/SymbolContext.h
===
--- lldb/include/lldb/Symbol/SymbolContext.h
+++ lldb/include/lldb/Symbol/SymbolContext.h
@@ -250,8 +250,8 @@
   /// For C++ the name is "this", for Objective-C the name is "self".
   ///
   /// \return
-  /// Returns a string for the name of the instance variable.
-  ConstString GetInstanceVariableName();
+  /// Returns a StringRef for the name of the instance variable.
+  llvm::StringRef GetInstanceVariableName();
 
   /// Sorts the types in TypeMap according to SymbolContext to TypeList
   ///


Index: lldb/source/Target/StackFrame.cpp
===
--- 

[Lldb-commits] [PATCH] D151120: [lldb][NFCI] Merge implementations of ObjectFileMachO::GetMinimumOSVersion and ObjectFileMachO::GetSDKVersion

2023-05-22 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: jasonmolenda, JDevlieghere.
Herald added a subscriber: tschuett.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

These functions do the exact same thing (even if they look slightly
different). I yanked the common implementation, cleaned it up, and
shoved it into its own function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151120

Files:
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5899,138 +5899,65 @@
 #endif
 }
 
-llvm::VersionTuple ObjectFileMachO::GetMinimumOSVersion() {
-  if (!m_min_os_version) {
-lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-for (uint32_t i = 0; i < m_header.ncmds; ++i) {
-  const lldb::offset_t load_cmd_offset = offset;
-
-  llvm::MachO::version_min_command lc = {};
-  if (m_data.GetU32(, , 2) == nullptr)
-break;
-  if (lc.cmd == llvm::MachO::LC_VERSION_MIN_MACOSX ||
-  lc.cmd == llvm::MachO::LC_VERSION_MIN_IPHONEOS ||
-  lc.cmd == llvm::MachO::LC_VERSION_MIN_TVOS ||
-  lc.cmd == llvm::MachO::LC_VERSION_MIN_WATCHOS) {
-if (m_data.GetU32(, ,
-  (sizeof(lc) / sizeof(uint32_t)) - 2)) {
-  const uint32_t  = lc.version >> 16;
-  const uint32_t yy = (lc.version >> 8) & 0xffu;
-  const uint32_t zz = lc.version & 0xffu;
-  if () {
-m_min_os_version = llvm::VersionTuple(, yy, zz);
-break;
-  }
-}
-  } else if (lc.cmd == llvm::MachO::LC_BUILD_VERSION) {
-// struct build_version_command {
-// uint32_tcmd;/* LC_BUILD_VERSION */
-// uint32_tcmdsize;/* sizeof(struct
-// build_version_command) plus */
-// /* ntools * sizeof(struct
-// build_tool_version) */
-// uint32_tplatform;   /* platform */
-// uint32_tminos;  /* X.Y.Z is encoded in nibbles
-// .yy.zz */ uint32_tsdk;/* X.Y.Z is encoded in
-// nibbles .yy.zz */ uint32_tntools; /* number of
-// tool entries following this */
-// };
-
-offset += 4; // skip platform
-uint32_t minos = m_data.GetU32();
-
-const uint32_t  = minos >> 16;
-const uint32_t yy = (minos >> 8) & 0xffu;
-const uint32_t zz = minos & 0xffu;
-if () {
-  m_min_os_version = llvm::VersionTuple(, yy, zz);
-  break;
-}
-  }
+static llvm::VersionTuple FindMinimumVersionInfo(DataExtractor ,
+ lldb::offset_t offset,
+ size_t ncmds) {
+  for (size_t i = 0; i < ncmds; i++) {
+const lldb::offset_t load_cmd_offset = offset;
+llvm::MachO::load_command lc = {};
+if (data.GetU32(, , 2) == nullptr)
+  break;
 
-  offset = load_cmd_offset + lc.cmdsize;
+uint32_t version = 0;
+if (lc.cmd == llvm::MachO::LC_VERSION_MIN_MACOSX ||
+lc.cmd == llvm::MachO::LC_VERSION_MIN_IPHONEOS ||
+lc.cmd == llvm::MachO::LC_VERSION_MIN_TVOS ||
+lc.cmd == llvm::MachO::LC_VERSION_MIN_WATCHOS) {
+  // struct version_min_command {
+  //   uint32_t cmd; // LC_VERSION_MIN_*
+  //   uint32_t cmdsize;
+  //   uint32_t version; // X.Y.Z encoded in nibbles .yy.zz
+  //   uint32_t sdk;
+  // };
+  // We want to read version.
+  version = data.GetU32();
+} else if (lc.cmd == llvm::MachO::LC_BUILD_VERSION) {
+  // struct build_version_command {
+  //   uint32_t cmd; // LC_BUILD_VERSION
+  //   uint32_t cmdsize;
+  //   uint32_t platform;
+  //   uint32_t minos; // X.Y.Z encoded in nibbles .yy.zz
+  //   uint32_t sdk;
+  //   uint32_t ntools;
+  // };
+  // We want to read minos.
+  offset += sizeof(uint32_t); // Skip over platform
+  version = data.GetU32(); // Extract minos
 }
 
-if (!m_min_os_version) {
-  // Set version to an empty value so we don't keep trying to
-  m_min_os_version = llvm::VersionTuple();
+if (version) {
+  const uint32_t  = version >> 16;
+  const uint32_t yy = (version >> 8) & 0xffu;
+  const uint32_t zz = version & 0xffu;
+  if ()
+return llvm::VersionTuple(, yy, zz);
 }
+offset = load_cmd_offset + lc.cmdsize;
   }
+  return llvm::VersionTuple();
+}
 
+llvm::VersionTuple 

[Lldb-commits] [PATCH] D146765: [lldb/crashlog] Load inlined symbol into interactive crashlog

2023-05-19 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

Ok, looks good to me now. Thanks!


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

https://reviews.llvm.org/D146765

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


[Lldb-commits] [PATCH] D151002: [lldb] Fix process pid parsing issue

2023-05-19 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

You probably encountered this somewhere, is there a simple test we could add 
here? The change looks fine to me nonetheless.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151002

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


[Lldb-commits] [PATCH] D146765: [lldb/crashlog] Load inlined symbol into interactive crashlog

2023-05-19 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

Looks good! A few minor comments.




Comment at: lldb/examples/python/crashlog.py:628-629
+description = ""
+# Since images are parsed after threads, we need to build a
+# map for every image with a list of all the symbols and addresses
+if frame_img_name and frame_addr and frame_symbol:

I think this comment better describes `parse_thread` rather than 
`parse_asi_backtrace` no?



Comment at: lldb/examples/python/crashlog.py:634-635
+description += " + " + frame_offset
+for image in self.images:
+if image.identifier == frame_img_name:
+image.symbols[frame_symbol] = {

Does it make sense for `self.images` to be a dictionary instead of a list? 
Something that maps `image_name -> image_info`. That way you could do something 
like `self.images[frame_img_name].symbols[frame_symbol] = { ... }` instead of 
iterating over every image (with appropriate error checking in the event that 
frame_img_name isn't in self.images yet).



Comment at: lldb/examples/python/crashlog.py:639
+"type": "code",
+"address": int(frame_addr, 0) - int(frame_offset)
+}

if `frame_offset` is `None`, you're doing `int(None)` which will give you a 
`TypeError`. Above you can do something like `frame_offset_value = 0` and in 
the `if frame_offset:` block you can do `frame_offset_value = 
int(frame_offset)`.



Comment at: lldb/examples/python/crashlog.py:708
+r'))(?: '# capture group garbage
+r'\('# source infor capture group
+r'([^\:]+)'  # file name

typo: `infor` -> `info`



Comment at: lldb/examples/python/crashlog.py:711
+r'\:(\d+)'   # line number
+r'(?:\:' # capture group garbage
+r'(\d+)' # column number

What does `garbage` mean in this case? I assume it's boilerplate of some kind.



Comment at: lldb/examples/python/crashlog.py:936
+description += " + " + frame_offset
+if not frame_img_name in self.symbols:
+self.symbols[frame_img_name] = list()





Comment at: lldb/examples/python/crashlog.py:940
+"name": frame_symbol,
+"address": int(frame_addr, 0) - int(frame_offset)
+})

Same situation here as above, `frame_offset` might be `None` and then you'll 
crash with a `TypeError`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146765

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


[Lldb-commits] [PATCH] D150954: [lldb][cmake] Allow specifying custom libcxx for tests in standalone builds

2023-05-19 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150954

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


[Lldb-commits] [PATCH] D150928: Two bug fixes for loading process save-core created core files, plus perf improvements

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

Bug fixes look good to me, the perf and code simplifications are also great to 
see. A few nits and I have one concern. Otherwise looks fine to me, I think.




Comment at: lldb/include/lldb/Target/DynamicLoader.h:270-273
+  LoadBinaryWithUUIDAndAddress(Process *process, llvm::StringRef name,
+   UUID uuid, lldb::addr_t value,
+   bool value_is_offset, bool force_symbol_search,
+   bool notify, bool set_address_in_target);

Just thinking aloud here, I wonder if we should construct some kind of 
"Options" struct to contain all of these bools?



Comment at: lldb/source/Core/DynamicLoader.cpp:216-218
+if (!module_sp || !module_sp->GetSymbolFileFileSpec()) {
+  Symbols::DownloadObjectAndSymbolFile(module_spec, error,
+   force_symbol_search);

I think this **technically** changes behavior and probably not in a desirable 
way. Specifically, we previously only called `DownloadObjectAndSymbolFile` if 
`force_symbol_search` was true. Now you're passing it through which makes sense 
looking at the interface of `DownloadObjectAndSymbolFile`. However, peeking at 
the beginning of that function we see this code block:
```
  // When dbgshell_command is empty, the user has not enabled the use of an
  // external program to find the symbols, don't run it for them.
  if (!force_lookup && dbgshell_command.empty())
return false;
```
This means that even if `force_lookup` is false (or `force_symbol_search` as 
it's written here), if `dbgshell_command` is non-empty we'll still perform the 
lookup (assuming all the other checks pass) which is probably not what we 
intended performance-wise. That condition in the block above should probably be 
something like `!force_lookup || dbgshell_command.empty()` instead of `&&`.



Comment at: lldb/source/Core/DynamicLoader.cpp:246-248
+  LLDB_LOGF(log,
+"DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
+"binary UUID %s at %s 0x%" PRIx64,

You could use `LLDB_LOG` instead of `LLDB_LOGF` here and you'll get the file + 
function without explicitly writing it, but you'd have to change the formatting 
a bit since it uses `Format` and not `Printf` under the hood. Just a suggestion 
though.



Comment at: lldb/source/Core/DynamicLoader.cpp:255-257
+  LLDB_LOGF(log,
+"DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
+"binary UUID %s at file address",

Same here



Comment at: lldb/source/Core/DynamicLoader.cpp:264-266
+LLDB_LOGF(log,
+  "DynamicLoader::LoadBinaryWithUUIDAndAddress Loading binary "
+  "UUID %s from memory at address 0x%" PRIx64,

Also here



Comment at: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:7021
 }
-const bool address_is_slide = true;
 bool changed = false;
+module_sp->SetLoadAddress(process.GetTarget(), value, value_is_offset,

nit: this can be const



Comment at: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp:1000
   this, "", standalone_uuid, standalone_value,
-  standalone_value_is_offset, force_symbol_search, notify);
+  standalone_value_is_offset, force_symbol_search, notify, true);
 }

nit: `, /* set_address_in_target */ true);` (or something like this)

Or you can create a `const bool` like above with `force_symbol_search` and 
`notify`.



Comment at: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp:1031
+  this, llvm::StringRef(), uuid, addr, value_is_slide,
+  force_symbol_search, notify, true);
 }

Same here



Comment at: lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp:262-264
   this, llvm::StringRef(), objfile_binary_uuid,
   objfile_binary_value, objfile_binary_value_is_offset,
+  force_symbol_search, notify, true)) {

Same here



Comment at: lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp:318
   this, llvm::StringRef(), ident_uuid, ident_binary_addr,
-  value_is_offset, force_symbol_search, notify)) {
+  value_is_offset, force_symbol_search, notify, true)) {
 found_main_binary_definitively = true;

Same here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150928

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


[Lldb-commits] [PATCH] D150914: [lldb][NFCI] Pre-allocate storage in ObjCLanguage::MethodName::GetFullNameWithoutCategory

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe8d3f061ba41: [lldb][NFCI] Pre-allocate storage in 
ObjCLanguage::MethodName… (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150914

Files:
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp


Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
===
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -152,7 +152,15 @@
 
   llvm::StringRef class_name = GetClassName();
   llvm::StringRef selector_name = GetSelector();
+
+  // Compute the total size to avoid reallocations
+  // class name + selector name + '[' + ' ' + ']'
+  size_t total_size = class_name.size() + selector_name.size() + 3;
+  if (m_type != eTypeUnspecified)
+total_size++; // For + or -
+
   std::string name_sans_category;
+  name_sans_category.reserve(total_size);
 
   if (m_type == eTypeClassMethod)
 name_sans_category += '+';


Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
===
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -152,7 +152,15 @@
 
   llvm::StringRef class_name = GetClassName();
   llvm::StringRef selector_name = GetSelector();
+
+  // Compute the total size to avoid reallocations
+  // class name + selector name + '[' + ' ' + ']'
+  size_t total_size = class_name.size() + selector_name.size() + 3;
+  if (m_type != eTypeUnspecified)
+total_size++; // For + or -
+
   std::string name_sans_category;
+  name_sans_category.reserve(total_size);
 
   if (m_type == eTypeClassMethod)
 name_sans_category += '+';
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
bulbazord marked an inline comment as done.
bulbazord added inline comments.



Comment at: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp:155
+  llvm::StringRef selector_name = GetSelector();
+  std::string name_sans_category;
+

bulbazord wrote:
> aprantl wrote:
> > bulbazord wrote:
> > > aprantl wrote:
> > > > Using an llvm string stream to construct the string might be faster 
> > > > here.
> > > I tested this and found that `llvm::SmallString<128>` performs about as 
> > > well as `std::string` on average. `llvm::SmallString<64>` was on average 
> > > slower though.
> > > 
> > > I think I'm going to land this with std::string, we can revisit later if 
> > > the difference actually is measurable.
> > Maybe we were talking past each other: I was thinking about 
> > https://www.llvm.org/doxygen/classllvm_1_1raw__string__ostream.html
> Oh, I totally misread what you said. I'll try that out and create a new PR if 
> I can improve this.
Turns out it can be improved, but it wasn't with raw_string_ostream! 
https://reviews.llvm.org/D150914


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149914

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


[Lldb-commits] [PATCH] D150914: [lldb][NFCI] Pre-allocate storage in ObjCLanguage::MethodName::GetFullNameWithoutCategory

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added a reviewer: aprantl.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The size of a full ObjC MethodName can vary somewhat, but it is
computable ahead of time.

Using a reasonably sized ObjC application, this actually improves the
time it takes to initialize symbol indexes for ObjC names ever so
slightly. Additionally, I found that the variability in time also was
improved considerably.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150914

Files:
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp


Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
===
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -152,7 +152,15 @@
 
   llvm::StringRef class_name = GetClassName();
   llvm::StringRef selector_name = GetSelector();
+
+  // Compute the total size to avoid reallocations
+  // class name + selector name + '[' + ' ' + ']'
+  size_t total_size = class_name.size() + selector_name.size() + 3;
+  if (m_type != eTypeUnspecified)
+total_size++; // For + or -
+
   std::string name_sans_category;
+  name_sans_category.reserve(total_size);
 
   if (m_type == eTypeClassMethod)
 name_sans_category += '+';


Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
===
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -152,7 +152,15 @@
 
   llvm::StringRef class_name = GetClassName();
   llvm::StringRef selector_name = GetSelector();
+
+  // Compute the total size to avoid reallocations
+  // class name + selector name + '[' + ' ' + ']'
+  size_t total_size = class_name.size() + selector_name.size() + 3;
+  if (m_type != eTypeUnspecified)
+total_size++; // For + or -
+
   std::string name_sans_category;
+  name_sans_category.reserve(total_size);
 
   if (m_type == eTypeClassMethod)
 name_sans_category += '+';
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D150804: [lldb] Guarantee the lifetimes of all strings returned from SBAPI

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG41714c959d65: [lldb] Guarantee the lifetimes of all strings 
returned from SBAPI (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150804

Files:
  lldb/docs/design/sbapi.rst
  lldb/source/API/SBAttachInfo.cpp
  lldb/source/API/SBBreakpoint.cpp
  lldb/source/API/SBBreakpointLocation.cpp
  lldb/source/API/SBBreakpointName.cpp
  lldb/source/API/SBCommandInterpreter.cpp
  lldb/source/API/SBData.cpp
  lldb/source/API/SBEvent.cpp
  lldb/source/API/SBExpressionOptions.cpp
  lldb/source/API/SBFrame.cpp
  lldb/source/API/SBFunction.cpp
  lldb/source/API/SBInstruction.cpp
  lldb/source/API/SBLaunchInfo.cpp
  lldb/source/API/SBModule.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/API/SBProcess.cpp
  lldb/source/API/SBProcessInfo.cpp
  lldb/source/API/SBQueue.cpp
  lldb/source/API/SBStream.cpp
  lldb/source/API/SBStringList.cpp
  lldb/source/API/SBTarget.cpp
  lldb/source/API/SBThread.cpp
  lldb/source/API/SBTrace.cpp
  lldb/source/API/SBTraceCursor.cpp
  lldb/source/API/SBType.cpp
  lldb/source/API/SBTypeCategory.cpp
  lldb/source/API/SBTypeFilter.cpp
  lldb/source/API/SBTypeNameSpecifier.cpp
  lldb/source/API/SBTypeSummary.cpp
  lldb/source/API/SBTypeSynthetic.cpp
  lldb/source/API/SBUnixSignals.cpp
  lldb/source/API/SBValue.cpp
  lldb/source/API/SBWatchpoint.cpp

Index: lldb/source/API/SBWatchpoint.cpp
===
--- lldb/source/API/SBWatchpoint.cpp
+++ lldb/source/API/SBWatchpoint.cpp
@@ -210,12 +210,12 @@
   LLDB_INSTRUMENT_VA(this);
 
   lldb::WatchpointSP watchpoint_sp(GetSP());
-  if (watchpoint_sp) {
-std::lock_guard guard(
-watchpoint_sp->GetTarget().GetAPIMutex());
-return watchpoint_sp->GetConditionText();
-  }
-  return nullptr;
+  if (!watchpoint_sp)
+return nullptr;
+
+  std::lock_guard guard(
+  watchpoint_sp->GetTarget().GetAPIMutex());
+  return ConstString(watchpoint_sp->GetConditionText()).GetCString();
 }
 
 void SBWatchpoint::SetCondition(const char *condition) {
@@ -323,16 +323,16 @@
   LLDB_INSTRUMENT_VA(this);
 
   lldb::WatchpointSP watchpoint_sp(GetSP());
-  if (watchpoint_sp) {
-std::lock_guard guard(
-watchpoint_sp->GetTarget().GetAPIMutex());
-// Store the result of `GetWatchSpec()` as a ConstString
-// so that the C string we return has a sufficiently long
-// lifetime. Note this a memory leak but should be fairly
-// low impact.
-return ConstString(watchpoint_sp->GetWatchSpec()).AsCString();
-  }
-  return nullptr;
+  if (!watchpoint_sp)
+return nullptr;
+
+  std::lock_guard guard(
+  watchpoint_sp->GetTarget().GetAPIMutex());
+  // Store the result of `GetWatchSpec()` as a ConstString
+  // so that the C string we return has a sufficiently long
+  // lifetime. Note this a memory leak but should be fairly
+  // low impact.
+  return ConstString(watchpoint_sp->GetWatchSpec()).AsCString();
 }
 
 bool SBWatchpoint::IsWatchingReads() {
Index: lldb/source/API/SBValue.cpp
===
--- lldb/source/API/SBValue.cpp
+++ lldb/source/API/SBValue.cpp
@@ -291,39 +291,34 @@
 const char *SBValue::GetName() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *name = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp)
-name = value_sp->GetName().GetCString();
+  if (!value_sp)
+return nullptr;
 
-  return name;
+  return value_sp->GetName().GetCString();
 }
 
 const char *SBValue::GetTypeName() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *name = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp) {
-name = value_sp->GetQualifiedTypeName().GetCString();
-  }
+  if (!value_sp)
+return nullptr;
 
-  return name;
+  return value_sp->GetQualifiedTypeName().GetCString();
 }
 
 const char *SBValue::GetDisplayTypeName() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *name = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp) {
-name = value_sp->GetDisplayTypeName().GetCString();
-  }
+  if (!value_sp)
+return nullptr;
 
-  return name;
+  return value_sp->GetDisplayTypeName().GetCString();
 }
 
 size_t SBValue::GetByteSize() {
@@ -357,14 +352,11 @@
 const char *SBValue::GetValue() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *cstr = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp) {
-cstr = value_sp->GetValueAsCString();
-  }
-
-  return cstr;
+  if (!value_sp)
+return nullptr;
+  return ConstString(value_sp->GetValueAsCString()).GetCString();
 }
 
 ValueType SBValue::GetValueType() {
@@ -382,14 +374,12 @@
 const char *SBValue::GetObjectDescription() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *cstr = nullptr;
   

[Lldb-commits] [PATCH] D150804: [lldb] Guarantee the lifetimes of all strings returned from SBAPI

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 523578.
bulbazord marked an inline comment as done.
bulbazord added a comment.

Update SBModule::GetUUIDString -- I slightly changed behavior. Now the behavior 
matches the previous implementation exactly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150804

Files:
  lldb/docs/design/sbapi.rst
  lldb/source/API/SBAttachInfo.cpp
  lldb/source/API/SBBreakpoint.cpp
  lldb/source/API/SBBreakpointLocation.cpp
  lldb/source/API/SBBreakpointName.cpp
  lldb/source/API/SBCommandInterpreter.cpp
  lldb/source/API/SBData.cpp
  lldb/source/API/SBEvent.cpp
  lldb/source/API/SBExpressionOptions.cpp
  lldb/source/API/SBFrame.cpp
  lldb/source/API/SBFunction.cpp
  lldb/source/API/SBInstruction.cpp
  lldb/source/API/SBLaunchInfo.cpp
  lldb/source/API/SBModule.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/API/SBProcess.cpp
  lldb/source/API/SBProcessInfo.cpp
  lldb/source/API/SBQueue.cpp
  lldb/source/API/SBStream.cpp
  lldb/source/API/SBStringList.cpp
  lldb/source/API/SBTarget.cpp
  lldb/source/API/SBThread.cpp
  lldb/source/API/SBTrace.cpp
  lldb/source/API/SBTraceCursor.cpp
  lldb/source/API/SBType.cpp
  lldb/source/API/SBTypeCategory.cpp
  lldb/source/API/SBTypeFilter.cpp
  lldb/source/API/SBTypeNameSpecifier.cpp
  lldb/source/API/SBTypeSummary.cpp
  lldb/source/API/SBTypeSynthetic.cpp
  lldb/source/API/SBUnixSignals.cpp
  lldb/source/API/SBValue.cpp
  lldb/source/API/SBWatchpoint.cpp

Index: lldb/source/API/SBWatchpoint.cpp
===
--- lldb/source/API/SBWatchpoint.cpp
+++ lldb/source/API/SBWatchpoint.cpp
@@ -210,12 +210,12 @@
   LLDB_INSTRUMENT_VA(this);
 
   lldb::WatchpointSP watchpoint_sp(GetSP());
-  if (watchpoint_sp) {
-std::lock_guard guard(
-watchpoint_sp->GetTarget().GetAPIMutex());
-return watchpoint_sp->GetConditionText();
-  }
-  return nullptr;
+  if (!watchpoint_sp)
+return nullptr;
+
+  std::lock_guard guard(
+  watchpoint_sp->GetTarget().GetAPIMutex());
+  return ConstString(watchpoint_sp->GetConditionText()).GetCString();
 }
 
 void SBWatchpoint::SetCondition(const char *condition) {
@@ -323,16 +323,16 @@
   LLDB_INSTRUMENT_VA(this);
 
   lldb::WatchpointSP watchpoint_sp(GetSP());
-  if (watchpoint_sp) {
-std::lock_guard guard(
-watchpoint_sp->GetTarget().GetAPIMutex());
-// Store the result of `GetWatchSpec()` as a ConstString
-// so that the C string we return has a sufficiently long
-// lifetime. Note this a memory leak but should be fairly
-// low impact.
-return ConstString(watchpoint_sp->GetWatchSpec()).AsCString();
-  }
-  return nullptr;
+  if (!watchpoint_sp)
+return nullptr;
+
+  std::lock_guard guard(
+  watchpoint_sp->GetTarget().GetAPIMutex());
+  // Store the result of `GetWatchSpec()` as a ConstString
+  // so that the C string we return has a sufficiently long
+  // lifetime. Note this a memory leak but should be fairly
+  // low impact.
+  return ConstString(watchpoint_sp->GetWatchSpec()).AsCString();
 }
 
 bool SBWatchpoint::IsWatchingReads() {
Index: lldb/source/API/SBValue.cpp
===
--- lldb/source/API/SBValue.cpp
+++ lldb/source/API/SBValue.cpp
@@ -291,39 +291,34 @@
 const char *SBValue::GetName() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *name = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp)
-name = value_sp->GetName().GetCString();
+  if (!value_sp)
+return nullptr;
 
-  return name;
+  return value_sp->GetName().GetCString();
 }
 
 const char *SBValue::GetTypeName() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *name = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp) {
-name = value_sp->GetQualifiedTypeName().GetCString();
-  }
+  if (!value_sp)
+return nullptr;
 
-  return name;
+  return value_sp->GetQualifiedTypeName().GetCString();
 }
 
 const char *SBValue::GetDisplayTypeName() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *name = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp) {
-name = value_sp->GetDisplayTypeName().GetCString();
-  }
+  if (!value_sp)
+return nullptr;
 
-  return name;
+  return value_sp->GetDisplayTypeName().GetCString();
 }
 
 size_t SBValue::GetByteSize() {
@@ -357,14 +352,11 @@
 const char *SBValue::GetValue() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *cstr = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp) {
-cstr = value_sp->GetValueAsCString();
-  }
-
-  return cstr;
+  if (!value_sp)
+return nullptr;
+  return ConstString(value_sp->GetValueAsCString()).GetCString();
 }
 
 ValueType SBValue::GetValueType() {
@@ -382,14 +374,12 @@
 const char *SBValue::GetObjectDescription() {
   

[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp:155
+  llvm::StringRef selector_name = GetSelector();
+  std::string name_sans_category;
+

aprantl wrote:
> bulbazord wrote:
> > aprantl wrote:
> > > Using an llvm string stream to construct the string might be faster here.
> > I tested this and found that `llvm::SmallString<128>` performs about as 
> > well as `std::string` on average. `llvm::SmallString<64>` was on average 
> > slower though.
> > 
> > I think I'm going to land this with std::string, we can revisit later if 
> > the difference actually is measurable.
> Maybe we were talking past each other: I was thinking about 
> https://www.llvm.org/doxygen/classllvm_1_1raw__string__ostream.html
Oh, I totally misread what you said. I'll try that out and create a new PR if I 
can improve this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149914

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


[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
bulbazord marked an inline comment as done.
Closed by commit rG915256388f86: [lldb] Refactor ObjCLanguage::MethodName 
(authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149914

Files:
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
  lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp

Index: lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
===
--- lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
+++ lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
@@ -42,53 +42,51 @@
 
   // First, be strict
   for (const auto  : strict_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ true);
-EXPECT_TRUE(method.IsValid(/*strict = */ true));
-EXPECT_EQ(
-test.full_name_sans_category,
-method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
-.GetStringRef());
-EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ true);
+EXPECT_TRUE(method.has_value());
+EXPECT_EQ(test.full_name_sans_category,
+  method->GetFullNameWithoutCategory());
+EXPECT_EQ(test.class_name, method->GetClassName());
 EXPECT_EQ(test.class_name_with_category,
-  method.GetClassNameWithCategory().GetStringRef());
-EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
-EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  method->GetClassNameWithCategory());
+EXPECT_EQ(test.category, method->GetCategory());
+EXPECT_EQ(test.selector, method->GetSelector());
   }
 
   // We should make sure strict parsing does not accept lax cases
   for (const auto  : lax_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ true);
-EXPECT_FALSE(method.IsValid(/*strict = */ true));
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ true);
+EXPECT_FALSE(method.has_value());
   }
 
   // All strict cases should work when not lax
   for (const auto  : strict_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ false);
-EXPECT_TRUE(method.IsValid(/*strict = */ false));
-EXPECT_EQ(
-test.full_name_sans_category,
-method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
-.GetStringRef());
-EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ false);
+EXPECT_TRUE(method.has_value());
+EXPECT_EQ(test.full_name_sans_category,
+  method->GetFullNameWithoutCategory());
+EXPECT_EQ(test.class_name, method->GetClassName());
 EXPECT_EQ(test.class_name_with_category,
-  method.GetClassNameWithCategory().GetStringRef());
-EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
-EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  method->GetClassNameWithCategory());
+EXPECT_EQ(test.category, method->GetCategory());
+EXPECT_EQ(test.selector, method->GetSelector());
   }
 
   // Make sure non-strict parsing works
   for (const auto  : lax_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ false);
-EXPECT_TRUE(method.IsValid(/*strict = */ false));
-EXPECT_EQ(
-test.full_name_sans_category,
-method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
-.GetStringRef());
-EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ false);
+EXPECT_TRUE(method.has_value());
+EXPECT_EQ(test.full_name_sans_category,
+  method->GetFullNameWithoutCategory());
+EXPECT_EQ(test.class_name, method->GetClassName());
 EXPECT_EQ(test.class_name_with_category,
-  method.GetClassNameWithCategory().GetStringRef());
-EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
-EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  method->GetClassNameWithCategory());
+EXPECT_EQ(test.category, method->GetCategory());
+EXPECT_EQ(test.selector, method->GetSelector());
   }
 }
 
@@ -105,10 +103,12 @@
   "[]"};
 
   for (const auto  : test_cases) {
-ObjCLanguage::MethodName strict_method(name, /*strict = */ true);
-EXPECT_FALSE(strict_method.IsValid(true));
+std::optional strict_method =
+

[Lldb-commits] [PATCH] D150804: [lldb] Guarantee the lifetimes of all strings returned from SBAPI

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
bulbazord marked an inline comment as done.
bulbazord added inline comments.



Comment at: lldb/source/API/SBFunction.cpp:181
+
+  return variable_sp->GetName().GetCString();
 }

mib wrote:
> nit: This threw me off, I thought you forgot to create a `ConsString` but it 
> seems that `ConstString` has both a `AsCString` and a `GetCString` method. It 
> would be good to stay consistent.
Yeah, maybe we should try to remove either `GetCString` or `AsCString` and be 
uniform everywhere. Let's plan on doing that later though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150804

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


[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
bulbazord marked an inline comment as done.
bulbazord added inline comments.



Comment at: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp:155
+  llvm::StringRef selector_name = GetSelector();
+  std::string name_sans_category;
+

aprantl wrote:
> Using an llvm string stream to construct the string might be faster here.
I tested this and found that `llvm::SmallString<128>` performs about as well as 
`std::string` on average. `llvm::SmallString<64>` was on average slower though.

I think I'm going to land this with std::string, we can revisit later if the 
difference actually is measurable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149914

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


[Lldb-commits] [PATCH] D150716: [lldb][NFCI] Switch to using llvm::DWARFAbbreviationDeclaration

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG16eb14806d1e: [lldb][NFCI] Switch to using 
llvm::DWARFAbbreviationDeclaration (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150716

Files:
  lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -15,7 +15,6 @@
 #include "llvm/Support/Path.h"
 
 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
-#include "Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h"
@@ -105,13 +104,13 @@
   EXPECT_EQ(abbrev_set.GetIndexOffset(), 1u);
 
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(1);
-  EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->HasChildren());
-  EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+  EXPECT_TRUE(abbrev1->hasChildren());
+  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
   auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(2);
-  EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->HasChildren());
-  EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+  EXPECT_FALSE(abbrev2->hasChildren());
+  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevOrder1Start5) {
@@ -150,13 +149,13 @@
   EXPECT_EQ(abbrev_set.GetIndexOffset(), 5u);
 
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(5);
-  EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->HasChildren());
-  EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+  EXPECT_TRUE(abbrev1->hasChildren());
+  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
   auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(6);
-  EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->HasChildren());
-  EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+  EXPECT_FALSE(abbrev2->hasChildren());
+  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevOutOfOrder) {
@@ -195,13 +194,13 @@
   EXPECT_EQ(abbrev_set.GetIndexOffset(), UINT32_MAX);
 
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(2);
-  EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->HasChildren());
-  EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+  EXPECT_TRUE(abbrev1->hasChildren());
+  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
   auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(1);
-  EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->HasChildren());
-  EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+  EXPECT_FALSE(abbrev2->hasChildren());
+  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevInvalidNULLTag) {
@@ -226,9 +225,8 @@
   llvm::Error error = abbrev_set.extract(data, _offset);
   // Verify we get an error
   EXPECT_TRUE(bool(error));
-  EXPECT_EQ("abbrev decl requires non-null tag.",
+  EXPECT_EQ("abbreviation declaration requires a non-null tag",
 llvm::toString(std::move(error)));
-
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevNullAttrValidForm) {
@@ -255,7 +253,8 @@
   llvm::Error error = abbrev_set.extract(data, _offset);
   // Verify we get an error
   EXPECT_TRUE(bool(error));
-  EXPECT_EQ("malformed abbreviation declaration attribute",
+  EXPECT_EQ("malformed abbreviation declaration attribute. Either the "
+"attribute or the form is zero while the other is not",
 llvm::toString(std::move(error)));
 }
 
@@ -283,7 +282,8 @@
   llvm::Error error = abbrev_set.extract(data, _offset);
   // Verify we get an error
   EXPECT_TRUE(bool(error));
-  EXPECT_EQ("malformed abbreviation declaration attribute",
+  EXPECT_EQ("malformed abbreviation declaration attribute. Either 

[Lldb-commits] [PATCH] D150716: [lldb][NFCI] Switch to using llvm::DWARFAbbreviationDeclaration

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 523500.
bulbazord marked 2 inline comments as done.
bulbazord added a comment.

Redo include order in DWARFDebugAbbrev.h to match project guidelines


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150716

Files:
  lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -15,7 +15,6 @@
 #include "llvm/Support/Path.h"
 
 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
-#include "Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h"
@@ -105,13 +104,13 @@
   EXPECT_EQ(abbrev_set.GetIndexOffset(), 1u);
 
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(1);
-  EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->HasChildren());
-  EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+  EXPECT_TRUE(abbrev1->hasChildren());
+  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
   auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(2);
-  EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->HasChildren());
-  EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+  EXPECT_FALSE(abbrev2->hasChildren());
+  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevOrder1Start5) {
@@ -150,13 +149,13 @@
   EXPECT_EQ(abbrev_set.GetIndexOffset(), 5u);
 
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(5);
-  EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->HasChildren());
-  EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+  EXPECT_TRUE(abbrev1->hasChildren());
+  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
   auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(6);
-  EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->HasChildren());
-  EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+  EXPECT_FALSE(abbrev2->hasChildren());
+  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevOutOfOrder) {
@@ -195,13 +194,13 @@
   EXPECT_EQ(abbrev_set.GetIndexOffset(), UINT32_MAX);
 
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(2);
-  EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->HasChildren());
-  EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+  EXPECT_TRUE(abbrev1->hasChildren());
+  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
   auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(1);
-  EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->HasChildren());
-  EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+  EXPECT_FALSE(abbrev2->hasChildren());
+  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevInvalidNULLTag) {
@@ -226,9 +225,8 @@
   llvm::Error error = abbrev_set.extract(data, _offset);
   // Verify we get an error
   EXPECT_TRUE(bool(error));
-  EXPECT_EQ("abbrev decl requires non-null tag.",
+  EXPECT_EQ("abbreviation declaration requires a non-null tag",
 llvm::toString(std::move(error)));
-
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevNullAttrValidForm) {
@@ -255,7 +253,8 @@
   llvm::Error error = abbrev_set.extract(data, _offset);
   // Verify we get an error
   EXPECT_TRUE(bool(error));
-  EXPECT_EQ("malformed abbreviation declaration attribute",
+  EXPECT_EQ("malformed abbreviation declaration attribute. Either the "
+"attribute or the form is zero while the other is not",
 llvm::toString(std::move(error)));
 }
 
@@ -283,7 +282,8 @@
   llvm::Error error = abbrev_set.extract(data, _offset);
   // Verify we get an error
   EXPECT_TRUE(bool(error));
-  EXPECT_EQ("malformed abbreviation declaration attribute",
+  EXPECT_EQ("malformed abbreviation declaration attribute. Either the "
+   

[Lldb-commits] [PATCH] D150716: [lldb][NFCI] Switch to using llvm::DWARFAbbreviationDeclaration

2023-05-18 Thread Alex Langford via Phabricator via lldb-commits
bulbazord marked 2 inline comments as done.
bulbazord added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp:27
  lldb::offset_t *offset_ptr) {
+  llvm::DataExtractor llvm_data = data.GetAsLLVM();
   const lldb::offset_t begin_offset = *offset_ptr;

aprantl wrote:
> Is this intentionally a copy or should this be a reference? I have no idea 
> how heavyweight this object is...
This isn't exactly a copy. `DataExtractor::GetAsLLVM` creates an entirely new 
object, it can't be a reference. Luckily it is fairly lightweight -- We just 
copy a few numbers and a pointer I believe.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp:56
   if (m_idx_offset == UINT32_MAX) {
-DWARFAbbreviationDeclarationCollConstIter pos;
-DWARFAbbreviationDeclarationCollConstIter end = m_decls.end();
-for (pos = m_decls.begin(); pos != end; ++pos) {
-  if (pos->Code() == abbrCode)
-return &(*pos);
+for (const auto  : m_decls) {
+  if (decl.getCode() == abbrCode)

aprantl wrote:
> would std::find_if be shorter or would it look worse?
```
for (const auto  : m_decls) {
  if (decl.getCode() == abbrCode)
return 
}
```
vs.
```
auto pos = std::find_if(
 m_decls.begin(), m_decls.end(),
 [abbrCode](const auto ) { return decl.getCode() == abbrCode; });
if (pos != m_decls.end())
  return &*pos;
```

I think it would look worse, personally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150716

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


[Lldb-commits] [PATCH] D150826: [lldb] Implement GetValueTypeFromAddressType

2023-05-17 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150826

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


[Lldb-commits] [PATCH] D150826: [lldb] Implement GetValueTypeFromAddressType

2023-05-17 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

Where do you plan on using this? Downstream I assume?




Comment at: lldb/source/Core/Value.cpp:134-135
+  return Value::ValueType::Invalid;
+  }
+}
+

This switch is exhaustive, could you add an `llvm_unreachable` somewhere to 
indicate this? After the switch or something. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150826

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


[Lldb-commits] [PATCH] D150804: [lldb] Guarantee the lifetimes of all strings returned from SBAPI

2023-05-17 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: jingham, mib.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

LLDB should guarantee that the strings returned by SBAPI methods
live forever. I went through every method that returns a string and made
sure that it was added to the ConstString StringPool before returning if
it wasn't obvious that it was already doing so.
I've also updated the docs to document this behavior.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150804

Files:
  lldb/docs/design/sbapi.rst
  lldb/source/API/SBAttachInfo.cpp
  lldb/source/API/SBBreakpoint.cpp
  lldb/source/API/SBBreakpointLocation.cpp
  lldb/source/API/SBBreakpointName.cpp
  lldb/source/API/SBCommandInterpreter.cpp
  lldb/source/API/SBData.cpp
  lldb/source/API/SBEvent.cpp
  lldb/source/API/SBExpressionOptions.cpp
  lldb/source/API/SBFrame.cpp
  lldb/source/API/SBFunction.cpp
  lldb/source/API/SBInstruction.cpp
  lldb/source/API/SBLaunchInfo.cpp
  lldb/source/API/SBModule.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/API/SBProcess.cpp
  lldb/source/API/SBProcessInfo.cpp
  lldb/source/API/SBQueue.cpp
  lldb/source/API/SBStream.cpp
  lldb/source/API/SBStringList.cpp
  lldb/source/API/SBTarget.cpp
  lldb/source/API/SBThread.cpp
  lldb/source/API/SBTrace.cpp
  lldb/source/API/SBTraceCursor.cpp
  lldb/source/API/SBType.cpp
  lldb/source/API/SBTypeCategory.cpp
  lldb/source/API/SBTypeFilter.cpp
  lldb/source/API/SBTypeNameSpecifier.cpp
  lldb/source/API/SBTypeSummary.cpp
  lldb/source/API/SBTypeSynthetic.cpp
  lldb/source/API/SBUnixSignals.cpp
  lldb/source/API/SBValue.cpp
  lldb/source/API/SBWatchpoint.cpp

Index: lldb/source/API/SBWatchpoint.cpp
===
--- lldb/source/API/SBWatchpoint.cpp
+++ lldb/source/API/SBWatchpoint.cpp
@@ -210,12 +210,12 @@
   LLDB_INSTRUMENT_VA(this);
 
   lldb::WatchpointSP watchpoint_sp(GetSP());
-  if (watchpoint_sp) {
-std::lock_guard guard(
-watchpoint_sp->GetTarget().GetAPIMutex());
-return watchpoint_sp->GetConditionText();
-  }
-  return nullptr;
+  if (!watchpoint_sp)
+return nullptr;
+
+  std::lock_guard guard(
+  watchpoint_sp->GetTarget().GetAPIMutex());
+  return ConstString(watchpoint_sp->GetConditionText()).GetCString();
 }
 
 void SBWatchpoint::SetCondition(const char *condition) {
@@ -323,16 +323,16 @@
   LLDB_INSTRUMENT_VA(this);
 
   lldb::WatchpointSP watchpoint_sp(GetSP());
-  if (watchpoint_sp) {
-std::lock_guard guard(
-watchpoint_sp->GetTarget().GetAPIMutex());
-// Store the result of `GetWatchSpec()` as a ConstString
-// so that the C string we return has a sufficiently long
-// lifetime. Note this a memory leak but should be fairly
-// low impact.
-return ConstString(watchpoint_sp->GetWatchSpec()).AsCString();
-  }
-  return nullptr;
+  if (!watchpoint_sp)
+return nullptr;
+
+  std::lock_guard guard(
+  watchpoint_sp->GetTarget().GetAPIMutex());
+  // Store the result of `GetWatchSpec()` as a ConstString
+  // so that the C string we return has a sufficiently long
+  // lifetime. Note this a memory leak but should be fairly
+  // low impact.
+  return ConstString(watchpoint_sp->GetWatchSpec()).AsCString();
 }
 
 bool SBWatchpoint::IsWatchingReads() {
Index: lldb/source/API/SBValue.cpp
===
--- lldb/source/API/SBValue.cpp
+++ lldb/source/API/SBValue.cpp
@@ -291,39 +291,34 @@
 const char *SBValue::GetName() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *name = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp)
-name = value_sp->GetName().GetCString();
+  if (!value_sp)
+return nullptr;
 
-  return name;
+  return value_sp->GetName().GetCString();
 }
 
 const char *SBValue::GetTypeName() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *name = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp) {
-name = value_sp->GetQualifiedTypeName().GetCString();
-  }
+  if (!value_sp)
+return nullptr;
 
-  return name;
+  return value_sp->GetQualifiedTypeName().GetCString();
 }
 
 const char *SBValue::GetDisplayTypeName() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *name = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp) {
-name = value_sp->GetDisplayTypeName().GetCString();
-  }
+  if (!value_sp)
+return nullptr;
 
-  return name;
+  return value_sp->GetDisplayTypeName().GetCString();
 }
 
 size_t SBValue::GetByteSize() {
@@ -357,14 +352,11 @@
 const char *SBValue::GetValue() {
   LLDB_INSTRUMENT_VA(this);
 
-  const char *cstr = nullptr;
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
-  if (value_sp) {
-cstr = value_sp->GetValueAsCString();
-  }
-
-  return cstr;
+  if (!value_sp)
+ 

[Lldb-commits] [PATCH] D150621: lldb PlatformDarwinKernel, delay local filesystem scan until needed

2023-05-16 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150621

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


[Lldb-commits] [PATCH] D150716: [lldb][NFCI] Switch to using llvm::DWARFAbbreviationDeclaration

2023-05-16 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: aprantl, JDevlieghere, fdeazeve, rastogishubham.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Both LLVM and LLDB implement DWARFAbbreviationDeclaration. As of
631ff46cbf51 
, llvm's 
implementation of
DWARFAbbreviationDeclaration::extract behaves the same as LLDB's
implementation, making it easier to merge the implementations.

The only major difference between LLDB's implementation and LLVM's
implementation is that LLVM's DWARFAbbreviationDeclaration is slightly
larger. Specifically, it has some metadata that keeps track of the size
of a declaration (if it has a fixed size) so that it can potentially
optimize extraction in some scenarios. I think this increase in size
should be acceptable and possibly useful on the LLDB side.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150716

Files:
  lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -15,7 +15,6 @@
 #include "llvm/Support/Path.h"
 
 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
-#include "Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h"
@@ -105,13 +104,13 @@
   EXPECT_EQ(abbrev_set.GetIndexOffset(), 1u);
 
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(1);
-  EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->HasChildren());
-  EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+  EXPECT_TRUE(abbrev1->hasChildren());
+  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
   auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(2);
-  EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->HasChildren());
-  EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+  EXPECT_FALSE(abbrev2->hasChildren());
+  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevOrder1Start5) {
@@ -150,13 +149,13 @@
   EXPECT_EQ(abbrev_set.GetIndexOffset(), 5u);
 
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(5);
-  EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->HasChildren());
-  EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+  EXPECT_TRUE(abbrev1->hasChildren());
+  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
   auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(6);
-  EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->HasChildren());
-  EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+  EXPECT_FALSE(abbrev2->hasChildren());
+  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevOutOfOrder) {
@@ -195,13 +194,13 @@
   EXPECT_EQ(abbrev_set.GetIndexOffset(), UINT32_MAX);
 
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(2);
-  EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
-  EXPECT_TRUE(abbrev1->HasChildren());
-  EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+  EXPECT_TRUE(abbrev1->hasChildren());
+  EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
   auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(1);
-  EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
-  EXPECT_FALSE(abbrev2->HasChildren());
-  EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+  EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+  EXPECT_FALSE(abbrev2->hasChildren());
+  EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
 }
 
 TEST_F(SymbolFileDWARFTests, TestAbbrevInvalidNULLTag) {
@@ -226,9 +225,8 @@
   llvm::Error error = abbrev_set.extract(data, _offset);
   // Verify we get an error
   EXPECT_TRUE(bool(error));
-  EXPECT_EQ("abbrev decl requires non-null tag.",
+  EXPECT_EQ("abbreviation declaration requires a non-null tag",
 llvm::toString(std::move(error)));
-
 }
 
 

[Lldb-commits] [PATCH] D150630: [lldb][docs] Update SB API design document

2023-05-16 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec388adbbcbf: [lldb][docs] Update SB API design document 
(authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150630

Files:
  lldb/docs/design/sbapi.rst


Index: lldb/docs/design/sbapi.rst
===
--- lldb/docs/design/sbapi.rst
+++ lldb/docs/design/sbapi.rst
@@ -7,6 +7,9 @@
 incompatibilities that C++ is so susceptible to. We've established a few rules
 to ensure that this happens.
 
+Extending the SB API
+
+
 The classes in the SB API's are all called SB, where SomeName is in
 CamelCase starting with an upper case letter. The method names are all
 CamelCase with initial capital letter as well.
@@ -45,14 +48,29 @@
 
 Another piece of the SB API infrastructure is the Python (or other script
 interpreter) customization. SWIG allows you to add property access, iterators
-and documentation to classes, but to do that you have to use a Swig interface
-file in place of the .h file. Those files have a different format than a
-straight C++ header file. These files are called SB.i, and live in
-"scripts/interface". They are constructed by starting with the associated .h
-file, and adding documentation and the Python decorations, etc. We do this in a
-decidedly low-tech way, by maintaining the two files in parallel. That
-simplifies the build process, but it does mean that if you add a method to the
-C++ API's for an SB class, you have to copy the interface to the .i file.
+and documentation to classes. We place the property accessors and iterators in
+a file dedicated to extensions to existing SB classes at
+"bindings/interface/SBExtensions.i". The documentation is similarly
+located at "bindings/interface/SBDocstrings.i". These two files, in
+addition to the actual header SB.h, forms the interface that lldb
+exposes to users through the scripting languages.
+
+There are some situations where you may want to add functionality to the SB API
+only for use in C++. To prevent SWIG from generating bindings to these
+functions, you can use a C macro guard, like so:
+
+::
+
+  #ifndef SWIG
+  int GetResourceCPPOnly() const;
+  #endif
+
+In this case, ``GetResourceCPPOnly`` will not be generated for Python or other
+scripting languages. If you wanted to add a resource specifically only for the
+SWIG case, you can invert the condition and use ``#ifdef SWIG`` instead. When
+building the LLDB framework for macOS, the headers are processed with
+``unifdef`` prior to being copied into the framework bundle to remove macros
+involving SWIG.
 
 API Instrumentation
 ---


Index: lldb/docs/design/sbapi.rst
===
--- lldb/docs/design/sbapi.rst
+++ lldb/docs/design/sbapi.rst
@@ -7,6 +7,9 @@
 incompatibilities that C++ is so susceptible to. We've established a few rules
 to ensure that this happens.
 
+Extending the SB API
+
+
 The classes in the SB API's are all called SB, where SomeName is in
 CamelCase starting with an upper case letter. The method names are all
 CamelCase with initial capital letter as well.
@@ -45,14 +48,29 @@
 
 Another piece of the SB API infrastructure is the Python (or other script
 interpreter) customization. SWIG allows you to add property access, iterators
-and documentation to classes, but to do that you have to use a Swig interface
-file in place of the .h file. Those files have a different format than a
-straight C++ header file. These files are called SB.i, and live in
-"scripts/interface". They are constructed by starting with the associated .h
-file, and adding documentation and the Python decorations, etc. We do this in a
-decidedly low-tech way, by maintaining the two files in parallel. That
-simplifies the build process, but it does mean that if you add a method to the
-C++ API's for an SB class, you have to copy the interface to the .i file.
+and documentation to classes. We place the property accessors and iterators in
+a file dedicated to extensions to existing SB classes at
+"bindings/interface/SBExtensions.i". The documentation is similarly
+located at "bindings/interface/SBDocstrings.i". These two files, in
+addition to the actual header SB.h, forms the interface that lldb
+exposes to users through the scripting languages.
+
+There are some situations where you may want to add functionality to the SB API
+only for use in C++. To prevent SWIG from generating bindings to these
+functions, you can use a C macro guard, like so:
+
+::
+
+  #ifndef SWIG
+  int GetResourceCPPOnly() const;
+  #endif
+
+In this case, ``GetResourceCPPOnly`` will not be generated for Python or other
+scripting languages. If you wanted to add a resource specifically only for the
+SWIG case, you can invert the condition and use ``#ifdef SWIG`` 

[Lldb-commits] [PATCH] D150709: [lldb][NFCI] Change return type of Language::GetInstanceVariableName

2023-05-16 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added a reviewer: kastiglione.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

I don't think this needs to be a ConstString.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150709

Files:
  lldb/include/lldb/Symbol/SymbolContext.h
  lldb/include/lldb/Target/Language.h
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
  lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
  lldb/source/Symbol/SymbolContext.cpp
  lldb/source/Target/StackFrame.cpp


Index: lldb/source/Target/StackFrame.cpp
===
--- lldb/source/Target/StackFrame.cpp
+++ lldb/source/Target/StackFrame.cpp
@@ -567,8 +567,9 @@
 // Check for direct ivars access which helps us with implicit access to
 // ivars using "this" or "self".
 GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock);
-if (auto instance_var_name = m_sc.GetInstanceVariableName()) {
-  var_sp = variable_list->FindVariable(instance_var_name);
+llvm::StringRef instance_var_name = m_sc.GetInstanceVariableName();
+if (!instance_var_name.empty()) {
+  var_sp = variable_list->FindVariable(ConstString(instance_var_name));
   if (var_sp) {
 separator_idx = 0;
 if (Type *var_type = var_sp->GetType())
Index: lldb/source/Symbol/SymbolContext.cpp
===
--- lldb/source/Symbol/SymbolContext.cpp
+++ lldb/source/Symbol/SymbolContext.cpp
@@ -541,7 +541,7 @@
   return nullptr;
 }
 
-ConstString SymbolContext::GetInstanceVariableName() {
+llvm::StringRef SymbolContext::GetInstanceVariableName() {
   LanguageType lang_type = eLanguageTypeUnknown;
 
   if (Block *function_block = GetFunctionBlock())
Index: lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
===
--- lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
+++ lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
@@ -40,7 +40,7 @@
 
   static lldb_private::Language *CreateInstance(lldb::LanguageType language);
 
-  ConstString GetInstanceVariableName() override { return ConstString("self"); 
}
+  llvm::StringRef GetInstanceVariableName() override { return "self"; }
 
   static llvm::StringRef GetPluginNameStatic() { return "objcplusplus"; }
 
Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
===
--- lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
+++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
@@ -155,7 +155,7 @@
   return false;
   }
 
-  ConstString GetInstanceVariableName() override { return ConstString("self"); 
}
+  llvm::StringRef GetInstanceVariableName() override { return "self"; }
 
   // PluginInterface protocol
   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
===
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
@@ -165,7 +165,7 @@
   ConstString FindBestAlternateFunctionMangledName(
   const Mangled mangled, const SymbolContext _ctx) const override;
 
-  ConstString GetInstanceVariableName() override { return ConstString("this"); 
}
+  llvm::StringRef GetInstanceVariableName() override { return "this"; }
 
   // PluginInterface protocol
   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
Index: lldb/include/lldb/Target/Language.h
===
--- lldb/include/lldb/Target/Language.h
+++ lldb/include/lldb/Target/Language.h
@@ -326,7 +326,7 @@
 return ConstString();
   }
 
-  virtual ConstString GetInstanceVariableName() { return {}; }
+  virtual llvm::StringRef GetInstanceVariableName() { return {}; }
 
 protected:
   // Classes that inherit from Language can see and modify these
Index: lldb/include/lldb/Symbol/SymbolContext.h
===
--- lldb/include/lldb/Symbol/SymbolContext.h
+++ lldb/include/lldb/Symbol/SymbolContext.h
@@ -250,8 +250,8 @@
   /// For C++ the name is "this", for Objective-C the name is "self".
   ///
   /// \return
-  /// Returns a string for the name of the instance variable.
-  ConstString GetInstanceVariableName();
+  /// Returns a StringRef for the name of the instance variable.
+  llvm::StringRef GetInstanceVariableName();
 
   /// Sorts the types in TypeMap according to SymbolContext to TypeList
   ///


Index: lldb/source/Target/StackFrame.cpp
===
--- 

[Lldb-commits] [PATCH] D150630: [lldb][docs] Update SB API design document

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, jingham, mib, kastiglione.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The documentation should have been updated in 662548c82683 
.
This updates it to be more accurate with the current design.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150630

Files:
  lldb/docs/design/sbapi.rst


Index: lldb/docs/design/sbapi.rst
===
--- lldb/docs/design/sbapi.rst
+++ lldb/docs/design/sbapi.rst
@@ -7,6 +7,9 @@
 incompatibilities that C++ is so susceptible to. We've established a few rules
 to ensure that this happens.
 
+Extending the SB API
+
+
 The classes in the SB API's are all called SB, where SomeName is in
 CamelCase starting with an upper case letter. The method names are all
 CamelCase with initial capital letter as well.
@@ -45,14 +48,29 @@
 
 Another piece of the SB API infrastructure is the Python (or other script
 interpreter) customization. SWIG allows you to add property access, iterators
-and documentation to classes, but to do that you have to use a Swig interface
-file in place of the .h file. Those files have a different format than a
-straight C++ header file. These files are called SB.i, and live in
-"scripts/interface". They are constructed by starting with the associated .h
-file, and adding documentation and the Python decorations, etc. We do this in a
-decidedly low-tech way, by maintaining the two files in parallel. That
-simplifies the build process, but it does mean that if you add a method to the
-C++ API's for an SB class, you have to copy the interface to the .i file.
+and documentation to classes. We place the property accessors and iterators in
+a file dedicated to extensions to existing SB classes at
+"bindings/interface/SBExtensions.i". The documentation is similarly
+located at "bindings/interface/SBDocstrings.i". These two files, in
+addition to the actual header SB.h, forms the interface that lldb
+exposes to users through the scripting languages.
+
+There are some situations where you may want to add functionality to the SB API
+only for use in C++. To prevent SWIG from generating bindings to these
+functions, you can use a C macro guard, like so:
+
+::
+
+  #ifndef SWIG
+  int GetResourceCPPOnly() const;
+  #endif
+
+In this case, ``GetResourceCPPOnly`` will not be generated for Python or other
+scripting languages. If you wanted to add a resource specifically only for the
+SWIG case, you can invert the condition and use ``#ifdef SWIG`` instead. When
+building the LLDB framework for macOS, the headers are processed with
+``unifdef`` prior to being copied into the framework bundle to remove macros
+involving SWIG.
 
 API Instrumentation
 ---


Index: lldb/docs/design/sbapi.rst
===
--- lldb/docs/design/sbapi.rst
+++ lldb/docs/design/sbapi.rst
@@ -7,6 +7,9 @@
 incompatibilities that C++ is so susceptible to. We've established a few rules
 to ensure that this happens.
 
+Extending the SB API
+
+
 The classes in the SB API's are all called SB, where SomeName is in
 CamelCase starting with an upper case letter. The method names are all
 CamelCase with initial capital letter as well.
@@ -45,14 +48,29 @@
 
 Another piece of the SB API infrastructure is the Python (or other script
 interpreter) customization. SWIG allows you to add property access, iterators
-and documentation to classes, but to do that you have to use a Swig interface
-file in place of the .h file. Those files have a different format than a
-straight C++ header file. These files are called SB.i, and live in
-"scripts/interface". They are constructed by starting with the associated .h
-file, and adding documentation and the Python decorations, etc. We do this in a
-decidedly low-tech way, by maintaining the two files in parallel. That
-simplifies the build process, but it does mean that if you add a method to the
-C++ API's for an SB class, you have to copy the interface to the .i file.
+and documentation to classes. We place the property accessors and iterators in
+a file dedicated to extensions to existing SB classes at
+"bindings/interface/SBExtensions.i". The documentation is similarly
+located at "bindings/interface/SBDocstrings.i". These two files, in
+addition to the actual header SB.h, forms the interface that lldb
+exposes to users through the scripting languages.
+
+There are some situations where you may want to add functionality to the SB API
+only for use in C++. To prevent SWIG from generating bindings to these
+functions, you can use a C macro guard, like so:
+
+::
+
+  #ifndef SWIG
+  int GetResourceCPPOnly() const;
+  #endif
+
+In this case, 

[Lldb-commits] [PATCH] D150621: lldb PlatformDarwinKernel, delay local filesystem scan until needed

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D150621#4344243 , @JDevlieghere 
wrote:

> You can do this simpler with a single `std::once_flag`.

+1

I like the idea of this patch a lot! LGTM otherwise.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150621

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


[Lldb-commits] [PATCH] D150624: [lldb] Fix lua build after 27b6a4e63afe

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG692ae97ae71d: [lldb] Fix lua build after 27b6a4e63afe 
(authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150624

Files:
  lldb/bindings/lua/lua-wrapper.swig
  lldb/include/lldb/API/SBBreakpointLocation.h
  lldb/include/lldb/API/SBFrame.h
  lldb/include/lldb/API/SBStructuredData.h
  lldb/include/lldb/API/SBWatchpoint.h
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h
  lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp

Index: lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
===
--- lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
+++ lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
@@ -14,14 +14,16 @@
 
 extern "C" int luaopen_lldb(lua_State *L) { return 0; }
 
-llvm::Expected lldb_private::LLDBSwigLuaBreakpointCallbackFunction(
+llvm::Expected
+lldb_private::lua::SWIGBridge::LLDBSwigLuaBreakpointCallbackFunction(
 lua_State *L, lldb::StackFrameSP stop_frame_sp,
 lldb::BreakpointLocationSP bp_loc_sp,
 const StructuredDataImpl _args_impl) {
   return false;
 }
 
-llvm::Expected lldb_private::LLDBSwigLuaWatchpointCallbackFunction(
+llvm::Expected
+lldb_private::lua::SWIGBridge::LLDBSwigLuaWatchpointCallbackFunction(
 lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp) {
   return false;
 }
Index: lldb/source/Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h
+++ lldb/source/Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h
@@ -15,13 +15,20 @@
 
 namespace lldb_private {
 
-llvm::Expected LLDBSwigLuaBreakpointCallbackFunction(
-lua_State *L, lldb::StackFrameSP stop_frame_sp,
-lldb::BreakpointLocationSP bp_loc_sp,
-const StructuredDataImpl _args_impl);
+namespace lua {
 
-llvm::Expected LLDBSwigLuaWatchpointCallbackFunction(
-lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp);
+class SWIGBridge {
+public:
+  static llvm::Expected LLDBSwigLuaBreakpointCallbackFunction(
+  lua_State *L, lldb::StackFrameSP stop_frame_sp,
+  lldb::BreakpointLocationSP bp_loc_sp,
+  const StructuredDataImpl _args_impl);
+
+  static llvm::Expected LLDBSwigLuaWatchpointCallbackFunction(
+  lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp);
+};
+
+} // namespace lua
 
 } // namespace lldb_private
 
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
@@ -83,8 +83,8 @@
   lua_pushlightuserdata(m_lua_state, baton);
   lua_gettable(m_lua_state, LUA_REGISTRYINDEX);
   StructuredDataImpl extra_args_impl(std::move(extra_args_sp));
-  return LLDBSwigLuaBreakpointCallbackFunction(m_lua_state, stop_frame_sp,
-   bp_loc_sp, extra_args_impl);
+  return lua::SWIGBridge::LLDBSwigLuaBreakpointCallbackFunction(
+  m_lua_state, stop_frame_sp, bp_loc_sp, extra_args_impl);
 }
 
 llvm::Error Lua::RegisterWatchpointCallback(void *baton, const char *body) {
@@ -109,8 +109,8 @@
 
   lua_pushlightuserdata(m_lua_state, baton);
   lua_gettable(m_lua_state, LUA_REGISTRYINDEX);
-  return LLDBSwigLuaWatchpointCallbackFunction(m_lua_state, stop_frame_sp,
-   wp_sp);
+  return lua::SWIGBridge::LLDBSwigLuaWatchpointCallbackFunction(
+  m_lua_state, stop_frame_sp, wp_sp);
 }
 
 llvm::Error Lua::CheckSyntax(llvm::StringRef buffer) {
Index: lldb/include/lldb/API/SBWatchpoint.h
===
--- lldb/include/lldb/API/SBWatchpoint.h
+++ lldb/include/lldb/API/SBWatchpoint.h
@@ -13,7 +13,10 @@
 #include "lldb/API/SBType.h"
 
 namespace lldb_private {
-namespace ptyhon {
+namespace python {
+class SWIGBridge;
+}
+namespace lua {
 class SWIGBridge;
 }
 } // namespace lldb_private
@@ -86,6 +89,7 @@
 
 protected:
   friend class lldb_private::python::SWIGBridge;
+  friend class lldb_private::lua::SWIGBridge;
 
   SBWatchpoint(const lldb::WatchpointSP _sp);
 
Index: lldb/include/lldb/API/SBStructuredData.h
===
--- lldb/include/lldb/API/SBStructuredData.h
+++ lldb/include/lldb/API/SBStructuredData.h
@@ -16,6 +16,9 @@
 namespace python {
 class SWIGBridge;
 }
+namespace lua {
+class SWIGBridge;
+}
 } // namespace lldb_private
 
 namespace lldb {
@@ -104,6 +107,7 @@
   friend class SBBreakpointName;
   friend class SBTrace;
   friend class lldb_private::python::SWIGBridge;
+  friend class lldb_private::lua::SWIGBridge;
 
   

[Lldb-commits] [PATCH] D150624: [lldb] Fix lua build after 27b6a4e63afe

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
bulbazord requested review of this revision.
bulbazord added a comment.

So, I agree that we should definitely unify this or else we end up doing this 
for **every** scripting language that we add support for. That being said, I 
think this is actually better than what we had before because now we're not 
exposing lldb private details in the public interface. There is a TODO comment 
in `SWIGPythonBridge.h` already for cleaning this up when we have a moment... I 
don't want to block this patch unless we're ok reverting the previous one, and 
I'd preferably not revert that one...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150624

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


[Lldb-commits] [PATCH] D150157: [lldb] Mark most SBAPI methods involving private types as protected or private

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

This broke Lua support, so I am fixing it in D150624 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150157

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


[Lldb-commits] [PATCH] D150624: [lldb] Fix lua build after 27b6a4e63afe

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: kparzysz, JDevlieghere, mib.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This applies the same trick for Lua that I did for python in
27b6a4e63afe 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150624

Files:
  lldb/bindings/lua/lua-wrapper.swig
  lldb/include/lldb/API/SBBreakpointLocation.h
  lldb/include/lldb/API/SBFrame.h
  lldb/include/lldb/API/SBStructuredData.h
  lldb/include/lldb/API/SBWatchpoint.h
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h
  lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp

Index: lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
===
--- lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
+++ lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
@@ -14,14 +14,16 @@
 
 extern "C" int luaopen_lldb(lua_State *L) { return 0; }
 
-llvm::Expected lldb_private::LLDBSwigLuaBreakpointCallbackFunction(
+llvm::Expected
+lldb_private::lua::SWIGBridge::LLDBSwigLuaBreakpointCallbackFunction(
 lua_State *L, lldb::StackFrameSP stop_frame_sp,
 lldb::BreakpointLocationSP bp_loc_sp,
 const StructuredDataImpl _args_impl) {
   return false;
 }
 
-llvm::Expected lldb_private::LLDBSwigLuaWatchpointCallbackFunction(
+llvm::Expected
+lldb_private::lua::SWIGBridge::LLDBSwigLuaWatchpointCallbackFunction(
 lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp) {
   return false;
 }
Index: lldb/source/Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h
+++ lldb/source/Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h
@@ -15,13 +15,20 @@
 
 namespace lldb_private {
 
-llvm::Expected LLDBSwigLuaBreakpointCallbackFunction(
-lua_State *L, lldb::StackFrameSP stop_frame_sp,
-lldb::BreakpointLocationSP bp_loc_sp,
-const StructuredDataImpl _args_impl);
+namespace lua {
 
-llvm::Expected LLDBSwigLuaWatchpointCallbackFunction(
-lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp);
+class SWIGBridge {
+public:
+  static llvm::Expected LLDBSwigLuaBreakpointCallbackFunction(
+  lua_State *L, lldb::StackFrameSP stop_frame_sp,
+  lldb::BreakpointLocationSP bp_loc_sp,
+  const StructuredDataImpl _args_impl);
+
+  static llvm::Expected LLDBSwigLuaWatchpointCallbackFunction(
+  lua_State *L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp);
+};
+
+} // namespace lua
 
 } // namespace lldb_private
 
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
@@ -83,8 +83,8 @@
   lua_pushlightuserdata(m_lua_state, baton);
   lua_gettable(m_lua_state, LUA_REGISTRYINDEX);
   StructuredDataImpl extra_args_impl(std::move(extra_args_sp));
-  return LLDBSwigLuaBreakpointCallbackFunction(m_lua_state, stop_frame_sp,
-   bp_loc_sp, extra_args_impl);
+  return lua::SWIGBridge::LLDBSwigLuaBreakpointCallbackFunction(
+  m_lua_state, stop_frame_sp, bp_loc_sp, extra_args_impl);
 }
 
 llvm::Error Lua::RegisterWatchpointCallback(void *baton, const char *body) {
@@ -109,8 +109,8 @@
 
   lua_pushlightuserdata(m_lua_state, baton);
   lua_gettable(m_lua_state, LUA_REGISTRYINDEX);
-  return LLDBSwigLuaWatchpointCallbackFunction(m_lua_state, stop_frame_sp,
-   wp_sp);
+  return lua::SWIGBridge::LLDBSwigLuaWatchpointCallbackFunction(
+  m_lua_state, stop_frame_sp, wp_sp);
 }
 
 llvm::Error Lua::CheckSyntax(llvm::StringRef buffer) {
Index: lldb/include/lldb/API/SBWatchpoint.h
===
--- lldb/include/lldb/API/SBWatchpoint.h
+++ lldb/include/lldb/API/SBWatchpoint.h
@@ -13,7 +13,10 @@
 #include "lldb/API/SBType.h"
 
 namespace lldb_private {
-namespace ptyhon {
+namespace python {
+class SWIGBridge;
+}
+namespace lua {
 class SWIGBridge;
 }
 } // namespace lldb_private
@@ -86,6 +89,7 @@
 
 protected:
   friend class lldb_private::python::SWIGBridge;
+  friend class lldb_private::lua::SWIGBridge;
 
   SBWatchpoint(const lldb::WatchpointSP _sp);
 
Index: lldb/include/lldb/API/SBStructuredData.h
===
--- lldb/include/lldb/API/SBStructuredData.h
+++ lldb/include/lldb/API/SBStructuredData.h
@@ -16,6 +16,9 @@
 namespace python {
 class SWIGBridge;
 }
+namespace lua {
+class SWIGBridge;
+}
 } // namespace lldb_private
 
 namespace lldb {
@@ -104,6 +107,7 @@
   friend class 

[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D149914#4335858 , @aprantl wrote:

> I'm not opposed to using this implementation, but have you considered using 
> something like the stdlib regex library to do the heavy lifting?

I talked to Jonas and did a little research. It seems like `` is quite 
slow and many supported compilers have buggy implementations. If I were to use 
regular expressions to rewrite this, I'd likely use whatever LLVM has 
implemented. That being said, I'm not too keen on holding up this patch because 
of that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149914

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


[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

Some more numbers:

  % hyperfine -w 3 -- "$lldb -x -b -o 'b main' -o 'r' -o 'c' -o 'b $Selector' 
-o 'b $NonExistentSelector' -o 'b $FullObjCName' $App"
  Benchmark 1: $lldb -x -b -o 'b main' -o 'r' -o 'c' -o 'b $Selector' -o 'b 
$NonExistentSelector' -o 'b $FullObjCName' $App
Time (mean ± σ):  6.323 s ±  0.069 s[User: 5.626 s, System: 0.301 s]
Range (min … max):6.224 s …  6.443 s10 runs
  
  % hyperfine -w 3 -- "$lldb -x -b -o 'b main' -o 'r' -o 'c' -o 'b $Selector' 
-o 'b $NonExistentSelector' -o 'b $FullObjCName' $App"
  Benchmark 1: $lldb -x -b -o 'b main' -o 'r' -o 'c' -o 'b $Selector' -o 'b 
$NonExistentSelector' -o 'b $FullObjCName' $App
Time (mean ± σ):  6.270 s ±  0.042 s[User: 5.557 s, System: 0.313 s]
Range (min … max):6.210 s …  6.338 s10 runs

I hope this is sufficient to show we're not regressing performance. I measured 
this a few times with and without my change and I observed that this is usually 
faster but they are usually within 100ms of each other.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149914

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


[Lldb-commits] [PATCH] D150235: [lldb] Change definition of DisassemblerCreateInstance

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf464b7c764bc: [lldb] Change definition of 
DisassemblerCreateInstance (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150235

Files:
  lldb/include/lldb/lldb-private-interfaces.h
  lldb/source/Core/Disassembler.cpp
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h


Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
@@ -34,8 +34,8 @@
 
   static llvm::StringRef GetPluginNameStatic() { return "llvm-mc"; }
 
-  static lldb_private::Disassembler *
-  CreateInstance(const lldb_private::ArchSpec , const char *flavor);
+  static lldb::DisassemblerSP CreateInstance(const lldb_private::ArchSpec 
,
+ const char *flavor);
 
   size_t DecodeInstructions(const lldb_private::Address _addr,
 const lldb_private::DataExtractor ,
Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -1572,16 +1572,14 @@
 
 DisassemblerLLVMC::~DisassemblerLLVMC() = default;
 
-Disassembler *DisassemblerLLVMC::CreateInstance(const ArchSpec ,
-const char *flavor) {
+lldb::DisassemblerSP DisassemblerLLVMC::CreateInstance(const ArchSpec ,
+   const char *flavor) {
   if (arch.GetTriple().getArch() != llvm::Triple::UnknownArch) {
-std::unique_ptr disasm_up(
-new DisassemblerLLVMC(arch, flavor));
-
-if (disasm_up.get() && disasm_up->IsValid())
-  return disasm_up.release();
+auto disasm_sp = std::make_shared(arch, flavor);
+if (disasm_sp && disasm_sp->IsValid())
+  return disasm_sp;
   }
-  return nullptr;
+  return lldb::DisassemblerSP();
 }
 
 size_t DisassemblerLLVMC::DecodeInstructions(const Address _addr,
Index: lldb/source/Core/Disassembler.cpp
===
--- lldb/source/Core/Disassembler.cpp
+++ lldb/source/Core/Disassembler.cpp
@@ -67,20 +67,16 @@
 create_callback =
 PluginManager::GetDisassemblerCreateCallbackForPluginName(plugin_name);
 if (create_callback) {
-  DisassemblerSP disassembler_sp(create_callback(arch, flavor));
-
-  if (disassembler_sp)
-return disassembler_sp;
+  if (auto disasm_sp = create_callback(arch, flavor))
+return disasm_sp;
 }
   } else {
 for (uint32_t idx = 0;
  (create_callback = 
PluginManager::GetDisassemblerCreateCallbackAtIndex(
   idx)) != nullptr;
  ++idx) {
-  DisassemblerSP disassembler_sp(create_callback(arch, flavor));
-
-  if (disassembler_sp)
-return disassembler_sp;
+  if (auto disasm_sp = create_callback(arch, flavor))
+return disasm_sp;
 }
   }
   return DisassemblerSP();
Index: lldb/include/lldb/lldb-private-interfaces.h
===
--- lldb/include/lldb/lldb-private-interfaces.h
+++ lldb/include/lldb/lldb-private-interfaces.h
@@ -30,8 +30,8 @@
  const ArchSpec );
 typedef std::unique_ptr (*ArchitectureCreateInstance)(
 const ArchSpec );
-typedef Disassembler *(*DisassemblerCreateInstance)(const ArchSpec ,
-const char *flavor);
+typedef lldb::DisassemblerSP (*DisassemblerCreateInstance)(const ArchSpec 
,
+   const char *flavor);
 typedef DynamicLoader *(*DynamicLoaderCreateInstance)(Process *process,
   bool force);
 typedef lldb::JITLoaderSP (*JITLoaderCreateInstance)(Process *process,


Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
@@ -34,8 +34,8 @@
 
   static llvm::StringRef GetPluginNameStatic() { return "llvm-mc"; }
 
-  static lldb_private::Disassembler *
-  CreateInstance(const lldb_private::ArchSpec , const char *flavor);
+  static lldb::DisassemblerSP CreateInstance(const lldb_private::ArchSpec ,
+ const char *flavor);
 
   size_t DecodeInstructions(const lldb_private::Address _addr,
 const 

[Lldb-commits] [PATCH] D149625: [lldb] Refactor SBFileSpec::GetDirectory

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

Ok, after looking at this more closely, it's a little clearer to me why 
`SBFileSpec::GetDirectory` was written this way to begin with. The method 
itself requires its return value to be denormalized (something not explicitly 
documented in the header nor the SWIG docstrings for this class/method). The 
only way to get the FileSpec's path in a denormalized form is by using 
`FileSpec::GetPath` and its variants... That's why we create a new FileSpec, 
remove its filename, and then get the path as a ConstString. I won't be 
addressing that in this patch because I view this as a flaw of the existing 
FileSpec implementation.

Thank you for finding and reverting this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149625

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


[Lldb-commits] [PATCH] D149625: [lldb] Refactor SBFileSpec::GetDirectory

2023-05-15 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

> AssertionError: 
> 'C:\\Users\\tcwg\\llvm-worker\\lldb-aarch64-windows\\build\\lldb-test-build.noindex\\functionalities\\process_save_core\\TestProcessSaveCore.test_save_windows_mini_dump_dwarf\\a.out'
>  not found in 
> ['C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/functionalities/process_save_core/TestProcessSaveCore.test_save_windows_mini_dump_dwarf\\a.out',
>  'C:/Windows/System32\\ntdll.dll', 'C:/Windows/System32\\kernel32.dll', 
> 'C:/Windows/System32\\KernelBase.dll']

Looks like a path normalization issue... `GetPathAsConstString()` has a bool 
parameter that defaults to true for normalizing paths. The right thing for this 
patch to do is actually return 
`m_opaque_up->GetPathAsConstString().GetCString()` then instead of invoking 
`GetDirectory()` directly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149625

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


[Lldb-commits] [PATCH] D150485: [lldb] Add support for negative integer to {SB, }StructuredData

2023-05-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

This is going to need some tests... And because you're adding templates to the 
SBAPI we'll need multiple tests -- Not just on the python side but I think we 
should add some actual C++ tests here in `test/API/api/`




Comment at: lldb/include/lldb/API/SBStructuredData.h:12-13
 
+#include "lldb/Core/StructuredDataImpl.h"
+
 #include "lldb/API/SBDefines.h"

You can't include a private header in a public header.



Comment at: lldb/include/lldb/API/SBStructuredData.h:70-77
+  template  T GetIntegerValue(T fail_value = {}) const {
+if constexpr (!std::is_integral_v)
+  return fail_value;
+
+return m_impl_up->GetType() == eStructuredDataTypeSignedInteger
+   ? m_impl_up->GetIntegerValue(static_cast(fail_value))
+   : m_impl_up->GetIntegerValue(static_cast(fail_value));

> All the SB API classes are non-virtual, single inheritance classes. They 
> should only include SBDefines.h or other SB headers as needed. **There should 
> be no inlined method implementations in the header files, they should all be 
> in the implementation files**. And there should be no direct ivar access.

Emphasis mine, from: https://lldb.llvm.org/design/sbapi.html

We should be able to move this into the implementation file.



Comment at: lldb/include/lldb/API/SBStructuredData.h:71-72
+  template  T GetIntegerValue(T fail_value = {}) const {
+if constexpr (!std::is_integral_v)
+  return fail_value;
+

This implementation allows us to generate `GetIntegerValue` for things like 
`const char *` and will just return a `fail_value` for those things. I think 
the interface would be better if it could give users feedback when they 
accidentally do something wrong with types instead of just giving them back 
whatever they want the failure value to be. Is there a way we can use SFINAE to 
**only** generate `GetIntegerValue` for things that are integral type? Would 
such a thing be compatible with SWIG?



Comment at: lldb/include/lldb/Core/StructuredDataImpl.h:131
 
   uint64_t GetIntegerValue(uint64_t fail_value = 0) const {
+return (m_data_sp ? m_data_sp->GetUnsignedIntegerValue(fail_value)

Not related to your change, we should probably move StructuredDataImpl to 
Utility :P



Comment at: lldb/include/lldb/Utility/StructuredData.h:308-309
+template  void AddIntegerItem(T value) {
+  static_assert(std::is_integral::value,
+"value type should be integral");
+  if constexpr (std::numeric_limits::is_signed)

Check for floating type here in addition, just like below.



Comment at: lldb/include/lldb/lldb-enumerations.h:816-817
   eStructuredDataTypeInteger,
+  eStructuredDataTypeUnsignedInteger = eStructuredDataTypeInteger,
+  eStructuredDataTypeSignedInteger,
   eStructuredDataTypeFloat,

Is it a good idea to insert these in the middle? Not that people should do 
this, but I assume some people hardcode these values in their script


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150485

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


[Lldb-commits] [PATCH] D150418: [lldb][NFCI] Replace use of DWARFAttribute in DWARFAbbreviationDecl

2023-05-12 Thread Alex Langford 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 rG050c09f0bed6: [lldb][NFCI] Replace use of DWARFAttribute in 
DWARFAbbreviationDecl (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150418

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h

Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
@@ -31,10 +31,6 @@
 form = m_form;
 val = m_value;
   }
-  typedef std::vector collection;
-  typedef collection::iterator iterator;
-  typedef collection::const_iterator const_iterator;
-
 protected:
   dw_attr_t m_attr;
   dw_form_t m_form;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
@@ -16,6 +16,29 @@
 
 class DWARFAbbreviationDeclaration {
 public:
+  struct AttributeSpec {
+AttributeSpec(dw_attr_t attr, dw_form_t form, int64_t value)
+: m_attr(attr), m_form(form), m_value(value) {}
+
+AttributeSpec(dw_attr_t attr, dw_form_t form)
+: m_attr(attr), m_form(form), m_value(0) {}
+
+bool IsImplicitConst() const {
+  return m_form == lldb_private::dwarf::DW_FORM_implicit_const;
+}
+
+int64_t GetImplicitConstValue() const { return m_value; }
+
+dw_attr_t GetAttribute() const { return m_attr; }
+
+dw_form_t GetForm() const { return m_form; }
+
+  private:
+dw_attr_t m_attr;
+dw_form_t m_form;
+int64_t m_value;
+  };
+
   enum { InvalidCode = 0 };
   DWARFAbbreviationDeclaration();
 
@@ -28,17 +51,21 @@
   bool HasChildren() const { return m_has_children; }
   size_t NumAttributes() const { return m_attributes.size(); }
   dw_form_t GetFormByIndex(uint32_t idx) const {
-return m_attributes.size() > idx ? m_attributes[idx].get_form()
+return m_attributes.size() > idx ? m_attributes[idx].GetForm()
  : dw_form_t(0);
   }
 
   // idx is assumed to be valid when calling GetAttrAndFormByIndex()
   void GetAttrAndFormValueByIndex(uint32_t idx, dw_attr_t ,
   DWARFFormValue _value) const {
-m_attributes[idx].get(attr, form_value.FormRef(), form_value.ValueRef());
+const AttributeSpec  = m_attributes[idx];
+attr = spec.GetAttribute();
+form_value.FormRef() = spec.GetForm();
+if (spec.IsImplicitConst())
+  form_value.SetSigned(spec.GetImplicitConstValue());
   }
   dw_form_t GetFormByIndexUnchecked(uint32_t idx) const {
-return m_attributes[idx].get_form();
+return m_attributes[idx].GetForm();
   }
   uint32_t FindAttributeIndex(dw_attr_t attr) const;
 
@@ -59,7 +86,7 @@
   uint32_t m_code = InvalidCode;
   dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
   uint8_t m_has_children = 0;
-  DWARFAttribute::collection m_attributes;
+  llvm::SmallVector m_attributes;
 };
 
 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -53,12 +53,13 @@
   return llvm::make_error(
   "malformed abbreviation declaration attribute");
 
-DWARFFormValue::ValueType val;
+if (form == DW_FORM_implicit_const) {
+  int64_t value = data.GetSLEB128(offset_ptr);
+  m_attributes.emplace_back(attr, form, value);
+  continue;
+}
 
-if (form == DW_FORM_implicit_const)
-  val.value.sval = data.GetSLEB128(offset_ptr);
-
-m_attributes.push_back(DWARFAttribute(attr, form, val));
+m_attributes.emplace_back(attr, form);
   }
 
   return llvm::make_error(
@@ -72,10 +73,8 @@
 
 uint32_t
 DWARFAbbreviationDeclaration::FindAttributeIndex(dw_attr_t attr) const {
-  uint32_t i;
-  const uint32_t kNumAttributes = m_attributes.size();
-  for (i = 0; i < kNumAttributes; ++i) {
-if (m_attributes[i].get_attr() == attr)
+  for (size_t i = 0; i < m_attributes.size(); ++i) {
+if (m_attributes[i].GetAttribute() == attr)
   return i;
   }
   return DW_INVALID_INDEX;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D150418: [lldb][NFCI] Replace use of DWARFAttribute in DWARFAbbreviationDecl

2023-05-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 521771.
bulbazord added a comment.

- Use emplace_back
- llvm::SmallVector size 8 -> 4


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150418

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h

Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
@@ -31,10 +31,6 @@
 form = m_form;
 val = m_value;
   }
-  typedef std::vector collection;
-  typedef collection::iterator iterator;
-  typedef collection::const_iterator const_iterator;
-
 protected:
   dw_attr_t m_attr;
   dw_form_t m_form;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
@@ -16,6 +16,29 @@
 
 class DWARFAbbreviationDeclaration {
 public:
+  struct AttributeSpec {
+AttributeSpec(dw_attr_t attr, dw_form_t form, int64_t value)
+: m_attr(attr), m_form(form), m_value(value) {}
+
+AttributeSpec(dw_attr_t attr, dw_form_t form)
+: m_attr(attr), m_form(form), m_value(0) {}
+
+bool IsImplicitConst() const {
+  return m_form == lldb_private::dwarf::DW_FORM_implicit_const;
+}
+
+int64_t GetImplicitConstValue() const { return m_value; }
+
+dw_attr_t GetAttribute() const { return m_attr; }
+
+dw_form_t GetForm() const { return m_form; }
+
+  private:
+dw_attr_t m_attr;
+dw_form_t m_form;
+int64_t m_value;
+  };
+
   enum { InvalidCode = 0 };
   DWARFAbbreviationDeclaration();
 
@@ -28,17 +51,21 @@
   bool HasChildren() const { return m_has_children; }
   size_t NumAttributes() const { return m_attributes.size(); }
   dw_form_t GetFormByIndex(uint32_t idx) const {
-return m_attributes.size() > idx ? m_attributes[idx].get_form()
+return m_attributes.size() > idx ? m_attributes[idx].GetForm()
  : dw_form_t(0);
   }
 
   // idx is assumed to be valid when calling GetAttrAndFormByIndex()
   void GetAttrAndFormValueByIndex(uint32_t idx, dw_attr_t ,
   DWARFFormValue _value) const {
-m_attributes[idx].get(attr, form_value.FormRef(), form_value.ValueRef());
+const AttributeSpec  = m_attributes[idx];
+attr = spec.GetAttribute();
+form_value.FormRef() = spec.GetForm();
+if (spec.IsImplicitConst())
+  form_value.SetSigned(spec.GetImplicitConstValue());
   }
   dw_form_t GetFormByIndexUnchecked(uint32_t idx) const {
-return m_attributes[idx].get_form();
+return m_attributes[idx].GetForm();
   }
   uint32_t FindAttributeIndex(dw_attr_t attr) const;
 
@@ -59,7 +86,7 @@
   uint32_t m_code = InvalidCode;
   dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
   uint8_t m_has_children = 0;
-  DWARFAttribute::collection m_attributes;
+  llvm::SmallVector m_attributes;
 };
 
 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -53,12 +53,13 @@
   return llvm::make_error(
   "malformed abbreviation declaration attribute");
 
-DWARFFormValue::ValueType val;
+if (form == DW_FORM_implicit_const) {
+  int64_t value = data.GetSLEB128(offset_ptr);
+  m_attributes.emplace_back(attr, form, value);
+  continue;
+}
 
-if (form == DW_FORM_implicit_const)
-  val.value.sval = data.GetSLEB128(offset_ptr);
-
-m_attributes.push_back(DWARFAttribute(attr, form, val));
+m_attributes.emplace_back(attr, form);
   }
 
   return llvm::make_error(
@@ -72,10 +73,8 @@
 
 uint32_t
 DWARFAbbreviationDeclaration::FindAttributeIndex(dw_attr_t attr) const {
-  uint32_t i;
-  const uint32_t kNumAttributes = m_attributes.size();
-  for (i = 0; i < kNumAttributes; ++i) {
-if (m_attributes[i].get_attr() == attr)
+  for (size_t i = 0; i < m_attributes.size(); ++i) {
+if (m_attributes[i].GetAttribute() == attr)
   return i;
   }
   return DW_INVALID_INDEX;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D150402: [lldb][NFCI] Change return type of DWARFDebugInfoEntry::GetAttributes

2023-05-12 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc909b491cb5f: [lldb][NFCI] Change return type of 
DWARFDebugInfoEntry::GetAttributes (authored by bulbazord).

Changed prior to commit:
  https://reviews.llvm.org/D150402?vs=521453=521757#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150402

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3285,8 +3285,7 @@
   (tag != DW_TAG_formal_parameter || !sc.function))
 return nullptr;
 
-  DWARFAttributes attributes;
-  const size_t num_attributes = die.GetAttributes(attributes);
+  DWARFAttributes attributes = die.GetAttributes();
   const char *name = nullptr;
   const char *mangled = nullptr;
   Declaration decl;
@@ -3297,7 +3296,7 @@
   DWARFFormValue const_value_form, location_form;
   Variable::RangeList scope_ranges;
 
-  for (size_t i = 0; i < num_attributes; ++i) {
+  for (size_t i = 0; i < attributes.Size(); ++i) {
 dw_attr_t attr = attributes.AttributeAtIndex(i);
 DWARFFormValue form_value;
 
@@ -3895,8 +3894,7 @@
 std::optional LocationInCallee;
 std::optional LocationInCaller;
 
-DWARFAttributes attributes;
-const size_t num_attributes = child.GetAttributes(attributes);
+DWARFAttributes attributes = child.GetAttributes();
 
 // Parse the location at index \p attr_index within this call site parameter
 // DIE, or return std::nullopt on failure.
@@ -3915,7 +3913,7 @@
   child.GetCU());
 };
 
-for (size_t i = 0; i < num_attributes; ++i) {
+for (size_t i = 0; i < attributes.Size(); ++i) {
   dw_attr_t attr = attributes.AttributeAtIndex(i);
   if (attr == DW_AT_location)
 LocationInCallee = parse_simple_location(i);
@@ -3966,10 +3964,8 @@
 // Second DW_AT_low_pc may come from DW_TAG_subprogram referenced by
 // DW_TAG_GNU_call_site's DW_AT_abstract_origin overwriting our 'low_pc'.
 // So do not inherit attributes from DW_AT_abstract_origin.
-DWARFAttributes attributes;
-const size_t num_attributes =
-child.GetAttributes(attributes, DWARFDIE::Recurse::no);
-for (size_t i = 0; i < num_attributes; ++i) {
+DWARFAttributes attributes = child.GetAttributes(DWARFDIE::Recurse::no);
+for (size_t i = 0; i < attributes.Size(); ++i) {
   DWARFFormValue form_value;
   if (!attributes.ExtractFormValueAtIndex(i, form_value)) {
 LLDB_LOG(log, "CollectCallEdges: Could not extract TAG_call_site form");
Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -223,62 +223,58 @@
   continue;
 }
 
-DWARFAttributes attributes;
 const char *name = nullptr;
 const char *mangled_cstr = nullptr;
 bool is_declaration = false;
-// bool is_artificial = false;
 bool has_address = false;
 bool has_location_or_const_value = false;
 bool is_global_or_static_variable = false;
 
 DWARFFormValue specification_die_form;
-const size_t num_attributes = die.GetAttributes(, attributes);
-if (num_attributes > 0) {
-  for (uint32_t i = 0; i < num_attributes; ++i) {
-dw_attr_t attr = attributes.AttributeAtIndex(i);
-DWARFFormValue form_value;
-switch (attr) {
-default:
-  break;
-case DW_AT_name:
-  if (attributes.ExtractFormValueAtIndex(i, form_value))
-name = form_value.AsCString();
-  break;
-
-case DW_AT_declaration:
-  if (attributes.ExtractFormValueAtIndex(i, form_value))
-is_declaration = form_value.Unsigned() != 0;
-  break;
-
-case DW_AT_MIPS_linkage_name:
-case DW_AT_linkage_name:
-  if (attributes.ExtractFormValueAtIndex(i, form_value))
-mangled_cstr = form_value.AsCString();
-  break;
-
-case DW_AT_low_pc:
-case DW_AT_high_pc:
-case DW_AT_ranges:
-  has_address = true;
-  break;
-
-case DW_AT_entry_pc:
-  has_address = true;
-   

[Lldb-commits] [PATCH] D150299: [lldb][NFCI] Redefine dw_attr_t typedef with llvm::dwarf::Attribute

2023-05-12 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG64f1fda29e2d: [lldb][NFCI] Redefine dw_attr_t typedef with 
llvm::dwarf::Attribute (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150299

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -239,6 +239,8 @@
 dw_attr_t attr = attributes.AttributeAtIndex(i);
 DWARFFormValue form_value;
 switch (attr) {
+default:
+  break;
 case DW_AT_name:
   if (attributes.ExtractFormValueAtIndex(i, form_value))
 name = form_value.AsCString();
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -391,6 +391,8 @@
 if (!attributes.ExtractFormValueAtIndex(i, form_value))
   continue;
 switch (attr) {
+default:
+  break;
 case DW_AT_loclists_base:
   SetLoclistsBase(form_value.Unsigned());
   break;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -40,7 +40,7 @@
   m_has_children = data.GetU8(offset_ptr);
 
   while (data.ValidOffset(*offset_ptr)) {
-dw_attr_t attr = data.GetULEB128(offset_ptr);
+auto attr = static_cast(data.GetULEB128(offset_ptr));
 auto form = static_cast(data.GetULEB128(offset_ptr));
 
 // This is the last attribute for this abbrev decl, but there may still be
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -274,6 +274,8 @@
 if (!attributes.ExtractFormValueAtIndex(i, form_value))
   continue;
 switch (attr) {
+default:
+  break;
 case DW_AT_abstract_origin:
   abstract_origin = form_value;
   break;
Index: lldb/include/lldb/Core/dwarf.h
===
--- lldb/include/lldb/Core/dwarf.h
+++ lldb/include/lldb/Core/dwarf.h
@@ -21,7 +21,7 @@
 }
 }
 
-typedef uint16_t dw_attr_t;
+typedef llvm::dwarf::Attribute dw_attr_t;
 typedef llvm::dwarf::Form dw_form_t;
 typedef llvm::dwarf::Tag dw_tag_t;
 typedef uint64_t dw_addr_t; // Dwarf address define that must be big enough for


Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -239,6 +239,8 @@
 dw_attr_t attr = attributes.AttributeAtIndex(i);
 DWARFFormValue form_value;
 switch (attr) {
+default:
+  break;
 case DW_AT_name:
   if (attributes.ExtractFormValueAtIndex(i, form_value))
 name = form_value.AsCString();
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -391,6 +391,8 @@
 if (!attributes.ExtractFormValueAtIndex(i, form_value))
   continue;
 switch (attr) {
+default:
+  break;
 case DW_AT_loclists_base:
   SetLoclistsBase(form_value.Unsigned());
   break;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -40,7 +40,7 @@
   m_has_children = data.GetU8(offset_ptr);
 
   while (data.ValidOffset(*offset_ptr)) {
-dw_attr_t attr = data.GetULEB128(offset_ptr);
+auto attr = static_cast(data.GetULEB128(offset_ptr));
 auto form = static_cast(data.GetULEB128(offset_ptr));
 
 // This is the last attribute for this abbrev decl, but there may still be
Index: 

[Lldb-commits] [PATCH] D150402: [lldb][NFCI] Change return type of DWARFDebugInfoEntry::GetAttributes

2023-05-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D150402#4337400 , @fdeazeve wrote:

> Thanks for doing this! In particular, all the early returns are very welcome 
> :)
>
> I suspect you already have this in your radar, but `ExtractFormValueAtIndex` 
> could probably return an `optional` to cleanup some code.

Yup, on the radar! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150402

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


[Lldb-commits] [PATCH] D150418: [lldb][NFCI] Replace use of DWARFAttribute in DWARFAbbreviationDecl

2023-05-12 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D150418#4337243 , @JDevlieghere 
wrote:

> Given the numbers I'm surprised you decided to stick with 8 rather than 4? 
> Unless I'm reading them wrong, it seems that despite the number of 
> allocations, it's about as fast and uses (a bit) less memory. Besides that 
> this LGTM.

Yeah, I just forgot to update this before I published. Will update the patch 
before landing. Thanks for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150418

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


[Lldb-commits] [PATCH] D150418: [lldb][NFCI] Replace use of DWARFAttribute in DWARFAbbreviationDecl

2023-05-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

I previously uploaded a similar patch that I've since abandoned. It contains 
valuable context so I'm linking it here for other contributors to read: D149214 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150418

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


[Lldb-commits] [PATCH] D149214: [lldb] Speed up DebugAbbrev parsing

2023-05-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord abandoned this revision.
bulbazord added a comment.

Thanks for the reviews and suggestions. I took a step back and looked at 
DWARFAbbreviationDeclaration and DWARFAttribute in more detail and I've decided 
I'm going to take this in a slightly different direction. I don't want to 
repurpose this diff because I'm making a different design decision, but I don't 
want people here to lose context so I'm going to link this review in the other 
one. I've added everyone here as reviewers (and more).

New patch: https://reviews.llvm.org/D150418


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149214

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


[Lldb-commits] [PATCH] D150418: [lldb][NFCI] Replace use of DWARFAttribute in DWARFAbbreviationDecl

2023-05-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, aprantl, mib, jingham, labath, 
kastiglione, rastogishubham, fdeazeve, clayborg.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

DWARFAttribute is used in 2 classes: DWARFAbbreviationDecl and
DWARFAttributes. The former stores a std::vector of them and the latter
has a small structure called AttributeValue that contains a
DWARFAttribute. DWARFAttributes maintains a llvm::SmallVector of
AttributeValues.

My end goal is to have `DWARFAttributes` have a llvm::SmallVector
specialized on DWARFAttribute. In order to do that, we'll have to move
the other elements of AttributeValue into DWARFAttribute itself. But we
don't want to do this while DWARFAbbreviationDecl is using
DWARFAttribute because it will needlessly increase the size of
DWARFAbbreviationDecl. So instead I will create a small type containing
only what DWARFAbbreviationDecl needs and call it `AttributeSpec`. This
is the exact same thing that LLVM does today.

I've elected to swap std::vector for llvm::SmallVector here with a pre-allocated
size of 8. I've collected time and memory measurements before this change and
after it as well. Using a c++ project with 10,000 object files and no dSYM, I
place a breakpoint by file + lineno and see how long it takes to resolve.

Before this patch:

  Time (mean ± σ): 13.577 s ±  0.024 s[User: 12.418 s, System: 1.247 s]

Total number of bytes allocated: 1.38 GiB
Total number of allocations: 6.47 million allocations

After this patch:

  Time (mean ± σ): 13.287 s ±  0.020 s[User: 12.128 s, System: 1.250 s]

Total number of bytes allocated: 1.59 GiB
Total number of allocations: 4.61 million allocations

So we consume more memory than before, but we actually make less allocations on
average.

I also measured with an llvm::SmallVector with a pre-allocated size of 4 instead
of 8 to measure how well it performs:

  Time (mean ± σ): 13.246 s ±  0.048 s[User: 12.074 s, System: 1.268 s]

Total memory consumption: 1.50 GiB
Total number of allocations: 5.74 million

Of course this data may look very different depending on the actual program
being debugged, but each of the object files had 100+ AbbreviationDeclarations
each with between 0 and 10 Attributes, so I feel this was a fair example to
consider.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150418

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h

Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
@@ -31,10 +31,6 @@
 form = m_form;
 val = m_value;
   }
-  typedef std::vector collection;
-  typedef collection::iterator iterator;
-  typedef collection::const_iterator const_iterator;
-
 protected:
   dw_attr_t m_attr;
   dw_form_t m_form;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
@@ -16,6 +16,29 @@
 
 class DWARFAbbreviationDeclaration {
 public:
+  struct AttributeSpec {
+AttributeSpec(dw_attr_t attr, dw_form_t form, int64_t value)
+: m_attr(attr), m_form(form), m_value(value) {}
+
+AttributeSpec(dw_attr_t attr, dw_form_t form)
+: m_attr(attr), m_form(form), m_value(0) {}
+
+bool IsImplicitConst() const {
+  return m_form == lldb_private::dwarf::DW_FORM_implicit_const;
+}
+
+int64_t GetImplicitConstValue() const { return m_value; }
+
+dw_attr_t GetAttribute() const { return m_attr; }
+
+dw_form_t GetForm() const { return m_form; }
+
+  private:
+dw_attr_t m_attr;
+dw_form_t m_form;
+int64_t m_value;
+  };
+
   enum { InvalidCode = 0 };
   DWARFAbbreviationDeclaration();
 
@@ -28,17 +51,21 @@
   bool HasChildren() const { return m_has_children; }
   size_t NumAttributes() const { return m_attributes.size(); }
   dw_form_t GetFormByIndex(uint32_t idx) const {
-return m_attributes.size() > idx ? m_attributes[idx].get_form()
+return m_attributes.size() > idx ? m_attributes[idx].GetForm()
  : dw_form_t(0);
   }
 
   // idx is assumed to be valid when calling GetAttrAndFormByIndex()
   void GetAttrAndFormValueByIndex(uint32_t idx, dw_attr_t ,
   DWARFFormValue _value) const {
-m_attributes[idx].get(attr, form_value.FormRef(), form_value.ValueRef());
+const AttributeSpec  = m_attributes[idx];
+attr = spec.GetAttribute();
+

[Lldb-commits] [PATCH] D150366: [lldb][NFCI] Use llvm's libDebugInfo for DebugRanges

2023-05-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

Ok, this looks like it's doing the same thing to me which is good. My 
understanding of this change is that you're changing 
`lldb::DWARFDebugRanges::Extract` to use `llvm::DWARFDebugRangeList` instead of 
`lldb::DWARFRangeList`.

Out of curiosity, do you have an idea of the change to performance (if any)? I 
wouldn't expect it to be very different if at all because I don't think the 
algorithms between lldb and llvm are different but it would be nice to make 
sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150366

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


[Lldb-commits] [PATCH] D150402: [lldb][NFCI] Change return type of DWARFDebugInfoEntry::GetAttributes

2023-05-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: aprantl, JDevlieghere, clayborg, jingham, 
rastogishubham, fdeazeve.
Herald added a subscriber: arphaman.
Herald added a reviewer: shafik.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The purpose of this method is to get the list of attributes of a
DebugInfoEntry. Prior to this change we were passing in a mutable
reference to a DWARFAttributes object and having the method fill it in
for us while returning the size of the filled out list. But
instead of doing that, we can just return a `DWARFAttributes` object
ourselves since every caller creates a new list before calling
GetAttributes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150402

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3285,8 +3285,7 @@
   (tag != DW_TAG_formal_parameter || !sc.function))
 return nullptr;
 
-  DWARFAttributes attributes;
-  const size_t num_attributes = die.GetAttributes(attributes);
+  DWARFAttributes attributes = die.GetAttributes();
   const char *name = nullptr;
   const char *mangled = nullptr;
   Declaration decl;
@@ -3297,7 +3296,7 @@
   DWARFFormValue const_value_form, location_form;
   Variable::RangeList scope_ranges;
 
-  for (size_t i = 0; i < num_attributes; ++i) {
+  for (size_t i = 0; i < attributes.Size(); ++i) {
 dw_attr_t attr = attributes.AttributeAtIndex(i);
 DWARFFormValue form_value;
 
@@ -3895,8 +3894,7 @@
 std::optional LocationInCallee;
 std::optional LocationInCaller;
 
-DWARFAttributes attributes;
-const size_t num_attributes = child.GetAttributes(attributes);
+DWARFAttributes attributes = child.GetAttributes();
 
 // Parse the location at index \p attr_index within this call site parameter
 // DIE, or return std::nullopt on failure.
@@ -3915,7 +3913,7 @@
   child.GetCU());
 };
 
-for (size_t i = 0; i < num_attributes; ++i) {
+for (size_t i = 0; i < attributes.Size(); ++i) {
   dw_attr_t attr = attributes.AttributeAtIndex(i);
   if (attr == DW_AT_location)
 LocationInCallee = parse_simple_location(i);
@@ -3966,10 +3964,8 @@
 // Second DW_AT_low_pc may come from DW_TAG_subprogram referenced by
 // DW_TAG_GNU_call_site's DW_AT_abstract_origin overwriting our 'low_pc'.
 // So do not inherit attributes from DW_AT_abstract_origin.
-DWARFAttributes attributes;
-const size_t num_attributes =
-child.GetAttributes(attributes, DWARFDIE::Recurse::no);
-for (size_t i = 0; i < num_attributes; ++i) {
+DWARFAttributes attributes = child.GetAttributes(DWARFDIE::Recurse::no);
+for (size_t i = 0; i < attributes.Size(); ++i) {
   DWARFFormValue form_value;
   if (!attributes.ExtractFormValueAtIndex(i, form_value)) {
 LLDB_LOG(log, "CollectCallEdges: Could not extract TAG_call_site form");
Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -223,60 +223,56 @@
   continue;
 }
 
-DWARFAttributes attributes;
 const char *name = nullptr;
 const char *mangled_cstr = nullptr;
 bool is_declaration = false;
-// bool is_artificial = false;
 bool has_address = false;
 bool has_location_or_const_value = false;
 bool is_global_or_static_variable = false;
 
 DWARFFormValue specification_die_form;
-const size_t num_attributes = die.GetAttributes(, attributes);
-if (num_attributes > 0) {
-  for (uint32_t i = 0; i < num_attributes; ++i) {
-dw_attr_t attr = attributes.AttributeAtIndex(i);
-DWARFFormValue form_value;
-switch (attr) {
-case DW_AT_name:
-  if (attributes.ExtractFormValueAtIndex(i, form_value))
-name = form_value.AsCString();
-  break;
-
-case DW_AT_declaration:
-  if (attributes.ExtractFormValueAtIndex(i, form_value))
-is_declaration = form_value.Unsigned() != 0;
-  break;
-
-case DW_AT_MIPS_linkage_name:
-

[Lldb-commits] [PATCH] D149214: [lldb] Speed up DebugAbbrev parsing

2023-05-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h:61
   uint8_t m_has_children = 0;
-  DWARFAttribute::collection m_attributes;
 };

kastiglione wrote:
> With this change, can the following be removed from` DWARFAttribute.h`?
> 
> ```
> typedef std::vector collection;
> typedef collection::iterator iterator;
> typedef collection::const_iterator const_iterator;
> ```
> 
Possibly? I sort of put this patch on the back burner... but it would be nice 
to get rid of those as well!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149214

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


[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D149914#4335858 , @aprantl wrote:

> I'm not opposed to using this implementation, but have you considered using 
> something like the stdlib regex library to do the heavy lifting?

I had not considered it actually... I don't have any experience using anything 
from ``. I know LLVM has its own regex engine, perhaps that might be 
appropriate? I know LLDB uses it in its `RegularExpression` class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149914

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


[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 521414.
bulbazord added a comment.

Update documentation for clarity


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149914

Files:
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
  lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp

Index: lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
===
--- lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
+++ lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
@@ -42,53 +42,51 @@
 
   // First, be strict
   for (const auto  : strict_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ true);
-EXPECT_TRUE(method.IsValid(/*strict = */ true));
-EXPECT_EQ(
-test.full_name_sans_category,
-method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
-.GetStringRef());
-EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ true);
+EXPECT_TRUE(method.has_value());
+EXPECT_EQ(test.full_name_sans_category,
+  method->GetFullNameWithoutCategory());
+EXPECT_EQ(test.class_name, method->GetClassName());
 EXPECT_EQ(test.class_name_with_category,
-  method.GetClassNameWithCategory().GetStringRef());
-EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
-EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  method->GetClassNameWithCategory());
+EXPECT_EQ(test.category, method->GetCategory());
+EXPECT_EQ(test.selector, method->GetSelector());
   }
 
   // We should make sure strict parsing does not accept lax cases
   for (const auto  : lax_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ true);
-EXPECT_FALSE(method.IsValid(/*strict = */ true));
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ true);
+EXPECT_FALSE(method.has_value());
   }
 
   // All strict cases should work when not lax
   for (const auto  : strict_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ false);
-EXPECT_TRUE(method.IsValid(/*strict = */ false));
-EXPECT_EQ(
-test.full_name_sans_category,
-method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
-.GetStringRef());
-EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ false);
+EXPECT_TRUE(method.has_value());
+EXPECT_EQ(test.full_name_sans_category,
+  method->GetFullNameWithoutCategory());
+EXPECT_EQ(test.class_name, method->GetClassName());
 EXPECT_EQ(test.class_name_with_category,
-  method.GetClassNameWithCategory().GetStringRef());
-EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
-EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  method->GetClassNameWithCategory());
+EXPECT_EQ(test.category, method->GetCategory());
+EXPECT_EQ(test.selector, method->GetSelector());
   }
 
   // Make sure non-strict parsing works
   for (const auto  : lax_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ false);
-EXPECT_TRUE(method.IsValid(/*strict = */ false));
-EXPECT_EQ(
-test.full_name_sans_category,
-method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
-.GetStringRef());
-EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ false);
+EXPECT_TRUE(method.has_value());
+EXPECT_EQ(test.full_name_sans_category,
+  method->GetFullNameWithoutCategory());
+EXPECT_EQ(test.class_name, method->GetClassName());
 EXPECT_EQ(test.class_name_with_category,
-  method.GetClassNameWithCategory().GetStringRef());
-EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
-EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  method->GetClassNameWithCategory());
+EXPECT_EQ(test.category, method->GetCategory());
+EXPECT_EQ(test.selector, method->GetSelector());
   }
 }
 
@@ -105,10 +103,12 @@
   "[]"};
 
   for (const auto  : test_cases) {
-ObjCLanguage::MethodName strict_method(name, /*strict = */ true);
-EXPECT_FALSE(strict_method.IsValid(true));
+std::optional strict_method =
+ObjCLanguage::MethodName::Create(name, /*strict = */ false);
+EXPECT_FALSE(strict_method.has_value());
 
-

[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

Ok, I'm back with actual data on this patch. I have a test ObjC app with some 
UI, it loads a couple hundred modules. I place a breakpoint on main, I run 
until we hit main, and then I continue. My app will stop at `-[NSBlockOperation 
main]` after loading all the required modules. Here is the data without this 
patch applied:

  % hyperfine -w 3 -- "$lldb -x -b -o 'b main' -o 'r' -o 'c' $App"
  Benchmark 1: $lldb -x -b -o 'b main' -o 'r' -o 'c' $App
Time (mean ± σ):  6.367 s ±  0.037 s[User: 5.688 s, System: 0.295 s]
Range (min … max):6.312 s …  6.417 s10 runs
  
  ...
  
"memory": {
  "strings": {
"bytesTotal": 133180053,
"bytesUnused": 52050681,
"bytesUsed": 81129372
  }
},

Now, with the patch applied:

  % hyperfine -w 3 -- "$lldb -x -b -o 'b main' -o 'r' -o 'c' $App"
  Benchmark 1: $lldb -x -b -o 'b main' -o 'r' -o 'c' $App
Time (mean ± σ):  6.209 s ±  0.046 s[User: 5.554 s, System: 0.282 s]
Range (min … max):6.159 s …  6.295 s10 runs
  
  ...
  
"memory": {
  "strings": {
"bytesTotal": 133175645,
"bytesUnused": 52115081,
"bytesUsed": 81060564
  }
},

From this we can see that my patch actually is _slightly_ faster, saving a 
little more than 100ms on average. I ran hyperfine a few times under the same 
conditions and this is quite repeatable.
As for memory consumption, the ConstString StringPool is slightly smaller. The 
amount of bytes actually used in the StringPool shrank by about 60kb, and the 
total size of the StringPool shrank by about 5kb -- meaning we stored a lot 
less strings and grew the StringPool slightly less than before.

Now we had some discussion about `ObjCLanguage::MethodName` using a 
`ConstString` instead of a `std::string` to back its `m_full` member. I 
gathered the numbers on that one too:

  % hyperfine -w 3 -- "$lldb -x -b -o 'b main' -o 'r' -o 'c' $App"
  Benchmark 1: $lldb -x -b -o 'b main' -o 'r' -o 'c' $App
Time (mean ± σ):  6.327 s ±  0.023 s[User: 5.653 s, System: 0.296 s]
Range (min … max):6.299 s …  6.361 s10 runs
  
  ...
  
"memory": {
  "strings": {
"bytesTotal": 133175645,
"bytesUnused": 52115081,
"bytesUsed": 81060564
  }
},

From this, it looks like this is probably ever so slightly faster than with no 
patch, but still not as fast as using `std::string`. The memory consumption 
numbers are the exact same as using `std::string`. The conclusion I'm drawing 
from all the data here is that: 1.) My patch does decrease the size of the 
ConstString StringPool regardless of whether or not `m_full` is a std::string 
or a ConstString, and 2.) the std::string implementation is slightly faster on 
average than the ConstString one. I'll probably stick to this implementation 
since it appears to be faster on average (at least on my machine), but I'll 
update this PR to fix the documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149914

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


[Lldb-commits] [PATCH] D150363: [lldb][nfc] Simplify DebugRanges class

2023-05-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.

LGTM! I know we have this pattern in many places in LLDB. It's good to see this 
work being done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150363

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


[Lldb-commits] [PATCH] D150303: [LLDB] Add some declarations related to REPL support for mojo

2023-05-10 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D150303#4333215 , @rriddle wrote:

> Could we switch the RTTI to use the llvm RTTI extension mechanism, instead of 
> enums? Other classes have started doing this, and it'd be really nice if 
> users can write REPLS without needing to touch upstream LLDB.

+1, LLVM's RTTI mechanism would make it easier to add new things without 
needing to change base classes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150303

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


[Lldb-commits] [PATCH] D150299: [lldb][NFCI] Redefine dw_attr_t typedef with llvm::dwarf::Attribute

2023-05-10 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: aprantl, jingham, clayborg, rastogishubham, fdeazeve.
Herald added a subscriber: arphaman.
Herald added a reviewer: shafik.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Similar to dw_form_t, dw_attr_t is typedef'd to be a uint16_t. LLVM
defines their type `llvm::dwarf::Attribute` as an enum backed by a
uint16_t. Switching to the LLVM type buys us type checking and the
requirement of explicit casts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150299

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -239,6 +239,8 @@
 dw_attr_t attr = attributes.AttributeAtIndex(i);
 DWARFFormValue form_value;
 switch (attr) {
+default:
+  break;
 case DW_AT_name:
   if (attributes.ExtractFormValueAtIndex(i, form_value))
 name = form_value.AsCString();
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -391,6 +391,8 @@
 if (!attributes.ExtractFormValueAtIndex(i, form_value))
   continue;
 switch (attr) {
+default:
+  break;
 case DW_AT_loclists_base:
   SetLoclistsBase(form_value.Unsigned());
   break;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -40,7 +40,7 @@
   m_has_children = data.GetU8(offset_ptr);
 
   while (data.ValidOffset(*offset_ptr)) {
-dw_attr_t attr = data.GetULEB128(offset_ptr);
+auto attr = static_cast(data.GetULEB128(offset_ptr));
 auto form = static_cast(data.GetULEB128(offset_ptr));
 
 // This is the last attribute for this abbrev decl, but there may still be
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -274,6 +274,8 @@
 if (!attributes.ExtractFormValueAtIndex(i, form_value))
   continue;
 switch (attr) {
+default:
+  break;
 case DW_AT_abstract_origin:
   abstract_origin = form_value;
   break;
Index: lldb/include/lldb/Core/dwarf.h
===
--- lldb/include/lldb/Core/dwarf.h
+++ lldb/include/lldb/Core/dwarf.h
@@ -21,7 +21,7 @@
 }
 }
 
-typedef uint16_t dw_attr_t;
+typedef llvm::dwarf::Attribute dw_attr_t;
 typedef llvm::dwarf::Form dw_form_t;
 typedef llvm::dwarf::Tag dw_tag_t;
 typedef uint64_t dw_addr_t; // Dwarf address define that must be big enough for


Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -239,6 +239,8 @@
 dw_attr_t attr = attributes.AttributeAtIndex(i);
 DWARFFormValue form_value;
 switch (attr) {
+default:
+  break;
 case DW_AT_name:
   if (attributes.ExtractFormValueAtIndex(i, form_value))
 name = form_value.AsCString();
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -391,6 +391,8 @@
 if (!attributes.ExtractFormValueAtIndex(i, form_value))
   continue;
 switch (attr) {
+default:
+  break;
 case DW_AT_loclists_base:
   SetLoclistsBase(form_value.Unsigned());
   break;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -40,7 +40,7 @@
   m_has_children = data.GetU8(offset_ptr);
 
   while (data.ValidOffset(*offset_ptr)) {
-

[Lldb-commits] [PATCH] D150228: [lldb][NFCI] Replace dw_form_t with llvm::dwarf::Form

2023-05-10 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2ec334dc7b73: [lldb][NFCI] Replace dw_form_t with 
llvm::dwarf::Form (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150228

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
@@ -158,6 +158,7 @@
   atoms.push_back({type, form});
   atom_mask |= 1u << type;
   switch (form) {
+  default:
   case DW_FORM_indirect:
   case DW_FORM_exprloc:
   case DW_FORM_flag_present:
@@ -227,7 +228,7 @@
   } else {
 for (uint32_t i = 0; i < atom_count; ++i) {
   AtomType type = (AtomType)data.GetU16();
-  dw_form_t form = (dw_form_t)data.GetU16();
+  auto form = static_cast(data.GetU16());
   AppendAtom(type, form);
 }
   }
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
@@ -45,7 +45,7 @@
   const DWARFUnit *GetUnit() const { return m_unit; }
   void SetUnit(const DWARFUnit *unit) { m_unit = unit; }
   dw_form_t Form() const { return m_form; }
-  dw_form_t& FormRef() { return m_form; }
+  dw_form_t () { return m_form; }
   void SetForm(dw_form_t form) { m_form = form; }
   const ValueType () const { return m_value; }
   ValueType () { return m_value; }
@@ -83,7 +83,7 @@
   // Compile unit where m_value was located.
   // It may be different from compile unit where m_value refers to.
   const DWARFUnit *m_unit = nullptr; // Unit for this form
-  dw_form_t m_form = 0;  // Form for this value
+  dw_form_t m_form = dw_form_t(0);   // Form for this value
   ValueType m_value;// Contains all data for the form
 };
 
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
@@ -25,7 +25,7 @@
 
 void DWARFFormValue::Clear() {
   m_unit = nullptr;
-  m_form = 0;
+  m_form = dw_form_t(0);
   m_value = ValueTypeTag();
 }
 
@@ -127,7 +127,7 @@
   m_value.value.uval = data.GetMaxU64(offset_ptr, ref_addr_size);
   break;
 case DW_FORM_indirect:
-  m_form = data.GetULEB128(offset_ptr);
+  m_form = static_cast(data.GetULEB128(offset_ptr));
   indirect = true;
   break;
 case DW_FORM_flag_present:
@@ -321,9 +321,10 @@
   return true;
 
   case DW_FORM_indirect: {
-dw_form_t indirect_form = debug_info_data.GetULEB128(offset_ptr);
-return DWARFFormValue::SkipValue(indirect_form, debug_info_data, offset_ptr,
- unit);
+  auto indirect_form =
+  static_cast(debug_info_data.GetULEB128(offset_ptr));
+  return DWARFFormValue::SkipValue(indirect_form, debug_info_data,
+   offset_ptr, unit);
   }
 
   default:
@@ -573,8 +574,10 @@
   case DW_FORM_block2:
   case DW_FORM_block4:
 return true;
+  default:
+return false;
   }
-  return false;
+  llvm_unreachable("All cases handled above!");
 }
 
 bool DWARFFormValue::IsDataForm(const dw_form_t form) {
@@ -586,8 +589,10 @@
   case DW_FORM_data4:
   case DW_FORM_data8:
 return true;
+  default:
+return false;
   }
-  return false;
+  llvm_unreachable("All cases handled above!");
 }
 
 bool DWARFFormValue::FormIsSupported(dw_form_t form) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -177,7 +177,7 @@
 
 case DW_FORM_indirect:
   form_is_indirect = true;
-  form = data.GetULEB128();
+  form = static_cast(data.GetULEB128());
   break;
 
 case DW_FORM_strp:
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
@@ 

[Lldb-commits] [PATCH] D150228: [lldb][NFCI] Replace dw_form_t with llvm::dwarf::Form

2023-05-10 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 521047.
bulbazord added a comment.

Fix a warning in HashedNameToDIE


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150228

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
@@ -158,6 +158,7 @@
   atoms.push_back({type, form});
   atom_mask |= 1u << type;
   switch (form) {
+  default:
   case DW_FORM_indirect:
   case DW_FORM_exprloc:
   case DW_FORM_flag_present:
@@ -227,7 +228,7 @@
   } else {
 for (uint32_t i = 0; i < atom_count; ++i) {
   AtomType type = (AtomType)data.GetU16();
-  dw_form_t form = (dw_form_t)data.GetU16();
+  auto form = static_cast(data.GetU16());
   AppendAtom(type, form);
 }
   }
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
@@ -45,7 +45,7 @@
   const DWARFUnit *GetUnit() const { return m_unit; }
   void SetUnit(const DWARFUnit *unit) { m_unit = unit; }
   dw_form_t Form() const { return m_form; }
-  dw_form_t& FormRef() { return m_form; }
+  dw_form_t () { return m_form; }
   void SetForm(dw_form_t form) { m_form = form; }
   const ValueType () const { return m_value; }
   ValueType () { return m_value; }
@@ -83,7 +83,7 @@
   // Compile unit where m_value was located.
   // It may be different from compile unit where m_value refers to.
   const DWARFUnit *m_unit = nullptr; // Unit for this form
-  dw_form_t m_form = 0;  // Form for this value
+  dw_form_t m_form = dw_form_t(0);   // Form for this value
   ValueType m_value;// Contains all data for the form
 };
 
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
@@ -25,7 +25,7 @@
 
 void DWARFFormValue::Clear() {
   m_unit = nullptr;
-  m_form = 0;
+  m_form = dw_form_t(0);
   m_value = ValueTypeTag();
 }
 
@@ -127,7 +127,7 @@
   m_value.value.uval = data.GetMaxU64(offset_ptr, ref_addr_size);
   break;
 case DW_FORM_indirect:
-  m_form = data.GetULEB128(offset_ptr);
+  m_form = static_cast(data.GetULEB128(offset_ptr));
   indirect = true;
   break;
 case DW_FORM_flag_present:
@@ -321,9 +321,10 @@
   return true;
 
   case DW_FORM_indirect: {
-dw_form_t indirect_form = debug_info_data.GetULEB128(offset_ptr);
-return DWARFFormValue::SkipValue(indirect_form, debug_info_data, offset_ptr,
- unit);
+  auto indirect_form =
+  static_cast(debug_info_data.GetULEB128(offset_ptr));
+  return DWARFFormValue::SkipValue(indirect_form, debug_info_data,
+   offset_ptr, unit);
   }
 
   default:
@@ -573,8 +574,10 @@
   case DW_FORM_block2:
   case DW_FORM_block4:
 return true;
+  default:
+return false;
   }
-  return false;
+  llvm_unreachable("All cases handled above!");
 }
 
 bool DWARFFormValue::IsDataForm(const dw_form_t form) {
@@ -586,8 +589,10 @@
   case DW_FORM_data4:
   case DW_FORM_data8:
 return true;
+  default:
+return false;
   }
-  return false;
+  llvm_unreachable("All cases handled above!");
 }
 
 bool DWARFFormValue::FormIsSupported(dw_form_t form) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -177,7 +177,7 @@
 
 case DW_FORM_indirect:
   form_is_indirect = true;
-  form = data.GetULEB128();
+  form = static_cast(data.GetULEB128());
   break;
 
 case DW_FORM_strp:
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
@@ -55,7 +55,7 @@
   dw_attr_t AttributeAtIndex(uint32_t i) const {
 return 

[Lldb-commits] [PATCH] D150228: [lldb][NFCI] Replace dw_form_t with llvm::dwarf::Form

2023-05-10 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D150228#4331943 , @fdeazeve wrote:

> Do you have plans to do something similar for the attribute typedef?

Yes I would like to do that too! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150228

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


[Lldb-commits] [PATCH] D150236: Thread::GetStackFrameCount should forestall interruption

2023-05-10 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/include/lldb/Target/StackFrameList.h:103-104
 
-  void GetFramesUpTo(uint32_t end_idx);
+  /// Gets frames up to end_idx (which can be greater than the actual number of
+  /// frames.)  Returns true if the function was interrupted, false otherwise.
+  bool GetFramesUpTo(uint32_t end_idx, bool allow_interrupt = true);

Is the range inclusive of `end_idx`? as in, is it [0, end_idx) or [0, end_idx]?



Comment at: lldb/source/Target/StackFrameList.cpp:89
 
-  GetFramesUpTo(0);
+  GetFramesUpTo(0, false);
   if (m_frames.empty())

nit:
```
GetFramesUpTo(/*end_idx = */0, /*allow_interrupt = */false);
```

Or something like this... A little easier to understand IMO.



Comment at: lldb/source/Target/StackFrameList.cpp:640-641
   if (can_create)
-GetFramesUpTo(UINT32_MAX);
+GetFramesUpTo(UINT32_MAX, false); // Don't allow interrupt or we might not
+  // return the correct count
 

Same here I think.



Comment at: lldb/source/Target/StackFrameList.cpp:683-684
   // there are that many.  If there weren't then you asked for too many frames.
-  GetFramesUpTo(idx);
+  bool interrupted = GetFramesUpTo(idx);
+  if (interrupted) {
+Log *log = GetLog(LLDBLog::Thread);

nit: Since `interrupted` isn't used anywhere else, you could do something like:
```
if (bool interrupted = GetFramesUpTo(idx)) {
 // Code here
}
```
You could also just do `if (GetFramesUpTo(idx))` but I think the name of the 
function isn't descriptive enough to do that and stay readable.



Comment at: 
lldb/test/API/functionalities/bt-interrupt/TestInterruptBacktrace.py:16
+def test_backtrace_interrupt(self):
+"""There can be many tests in a test case - describe this test here."""
+self.build()

I have a feeling this docstring was supposed to be different?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150236

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


[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D149914#4331048 , @jingham wrote:

> Most of this is fine.  I wonder about avoiding caching the full name and name 
> w/o category & selector name.  One of the main uses of this class is to take 
> incoming ObjC names from the ConstString pool, chop them up into full name, 
> name w/o category, and selectorName, which we then insert into the lookup 
> names tables for the modules they are found in.  All those lookup table names 
> will also exist in the ConstString pool.

The full name being a ConstString might make sense since we're usually getting 
them from debug info or similar sources. When we chop them up, we can decide if 
it's worth making ConstStrings out of them. At least that's the idea.
That being said, I'll look in more detail about how often we actually try to 
create `ObjCLanguage::MethodName` objects. If we do it in a hot loop then maybe 
ConstString is the right thing to do.

> The other instance where we get these names is when someone passes them to 
> break set.  In that case, we're going to break the name apart and then look 
> it and its parts up in the ConstString lookup tables to find a match.
>
> So it seems like this is a case where you aren't really getting savings in 
> the ConstString pool, you're just causing more copying from std::string to 
> ConstString.

What's the code path for this? I'm not 100% convinced we should be 
automatically storing portions of user input in the ConstString StringPool 
until we have a little more information about what they gave us.




Comment at: lldb/source/Plugins/Language/ObjC/ObjCLanguage.h:37
+///
+/// \return If the name did parse as a valid Objective-C method name,
+/// returns std::nullopt. Otherwise returns a const MethodName.

jingham wrote:
> 
Good catch, thanks!



Comment at: lldb/source/Plugins/Language/ObjC/ObjCLanguage.h:100
+///   will give you "my_additions"
+/// \return A StringRef to the category name of this method.
+llvm::StringRef GetCategory() const;

jingham wrote:
> What does this return if there's no category?
> 
> We have two behaviors above:
> 
> GetFullNameWithoutCategory - returns an empty string if the original class 
> had no category
> GetClassNameWithCategory - returns the original class name if it had no 
> category
> GetCategory - returns ??? if it had no category.
> 
> These seem a little skew somehow...
`GetCategory` will return an empty StringRef if there is no category. I will 
explicitly document that.

I agree that there's some skew here though. The way I think about it is 
`GetCategory` and `GetClassNameWithCategory` do what they say they will do. If 
there's no category, both of these will leave out the category. The former will 
therefore be empty and the latter will give you what you want without the 
category. Maybe it could be empty though? I haven't thought about it.





Comment at: lldb/source/Plugins/Language/ObjC/ObjCLanguage.h:117
 
-  protected:
-ConstString
-m_full; // Full name:   "+[NSString(my_additions) 
myStringWithCString:]"
-ConstString m_class; // Class name:  "NSString"
-ConstString
-m_class_category;   // Class with category: "NSString(my_additions)"
-ConstString m_category; // Category:"my_additions"
-ConstString m_selector; // Selector:"myStringWithCString:"
-Type m_type = eTypeUnspecified;
-bool m_category_is_valid = false;
+const std::string m_full;
+Type m_type;

jingham wrote:
> For the most part, we find ObjC method names either from debug info, from the 
> symbol table or from the runtime symbol vendor.  All of those are going to 
> store their names in the ConstString pool.
> 
> If we only make these MethodName entities one by one then we're just doing a 
> string copy every so often, and that shouldn't be noticeable.  But if we make 
> and hold a lot of these, we're doubling our storage requirements for a thing 
> that at least on Darwin there are a lot of...
> 
> This one seems a reasonable candidate to be a ConstString... 
Oh, I suppose that's true. I was looking at the call-sites and a lot of them 
were passing in `const char *`, but those likely come from `ConstString`s at 
some layer. In that case, making `m_full` be a ConstString is probably fine.

BTW, from what I can tell, we only do make these `ObjCLanguage::MethodName` 
entities one-by-one. They are never really stored anywhere, they're mostly used 
to chop up things we think may be ObjCLanguage method names and get the parts 
out we find useful. Aside from the input, I wanted to create an interface where 
the caller can decide if the output of its functions should be stored in a 
ConstString or not instead of preemptively putting it in the StringPool.


Repository:
  rG LLVM Github Monorepo

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


[Lldb-commits] [PATCH] D150235: [lldb] Change definition of DisassemblerCreateInstance

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: jingham, mib, JDevlieghere.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

DissassemblerCreateInstance is a function pointer whos return type is
`Disassembler *`. But Disassembler::FindPlugin always returns a
DisassemblerSP, so there's no reason why we can't just create a
DisassemblerSP in the first place.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150235

Files:
  lldb/include/lldb/lldb-private-interfaces.h
  lldb/source/Core/Disassembler.cpp
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h


Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
@@ -34,8 +34,8 @@
 
   static llvm::StringRef GetPluginNameStatic() { return "llvm-mc"; }
 
-  static lldb_private::Disassembler *
-  CreateInstance(const lldb_private::ArchSpec , const char *flavor);
+  static lldb::DisassemblerSP CreateInstance(const lldb_private::ArchSpec 
,
+ const char *flavor);
 
   size_t DecodeInstructions(const lldb_private::Address _addr,
 const lldb_private::DataExtractor ,
Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -1572,16 +1572,14 @@
 
 DisassemblerLLVMC::~DisassemblerLLVMC() = default;
 
-Disassembler *DisassemblerLLVMC::CreateInstance(const ArchSpec ,
-const char *flavor) {
+lldb::DisassemblerSP DisassemblerLLVMC::CreateInstance(const ArchSpec ,
+   const char *flavor) {
   if (arch.GetTriple().getArch() != llvm::Triple::UnknownArch) {
-std::unique_ptr disasm_up(
-new DisassemblerLLVMC(arch, flavor));
-
-if (disasm_up.get() && disasm_up->IsValid())
-  return disasm_up.release();
+auto disasm_sp = std::make_shared(arch, flavor);
+if (disasm_sp && disasm_sp->IsValid())
+  return disasm_sp;
   }
-  return nullptr;
+  return lldb::DisassemblerSP();
 }
 
 size_t DisassemblerLLVMC::DecodeInstructions(const Address _addr,
Index: lldb/source/Core/Disassembler.cpp
===
--- lldb/source/Core/Disassembler.cpp
+++ lldb/source/Core/Disassembler.cpp
@@ -67,20 +67,16 @@
 create_callback =
 PluginManager::GetDisassemblerCreateCallbackForPluginName(plugin_name);
 if (create_callback) {
-  DisassemblerSP disassembler_sp(create_callback(arch, flavor));
-
-  if (disassembler_sp)
-return disassembler_sp;
+  if (auto disasm_sp = create_callback(arch, flavor))
+return disasm_sp;
 }
   } else {
 for (uint32_t idx = 0;
  (create_callback = 
PluginManager::GetDisassemblerCreateCallbackAtIndex(
   idx)) != nullptr;
  ++idx) {
-  DisassemblerSP disassembler_sp(create_callback(arch, flavor));
-
-  if (disassembler_sp)
-return disassembler_sp;
+  if (auto disasm_sp = create_callback(arch, flavor))
+return disasm_sp;
 }
   }
   return DisassemblerSP();
Index: lldb/include/lldb/lldb-private-interfaces.h
===
--- lldb/include/lldb/lldb-private-interfaces.h
+++ lldb/include/lldb/lldb-private-interfaces.h
@@ -30,8 +30,8 @@
  const ArchSpec );
 typedef std::unique_ptr (*ArchitectureCreateInstance)(
 const ArchSpec );
-typedef Disassembler *(*DisassemblerCreateInstance)(const ArchSpec ,
-const char *flavor);
+typedef lldb::DisassemblerSP (*DisassemblerCreateInstance)(const ArchSpec 
,
+   const char *flavor);
 typedef DynamicLoader *(*DynamicLoaderCreateInstance)(Process *process,
   bool force);
 typedef lldb::JITLoaderSP (*JITLoaderCreateInstance)(Process *process,


Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h
@@ -34,8 +34,8 @@
 
   static llvm::StringRef GetPluginNameStatic() { return "llvm-mc"; }
 
-  static lldb_private::Disassembler *
-  CreateInstance(const lldb_private::ArchSpec , const char *flavor);
+  static lldb::DisassemblerSP 

[Lldb-commits] [PATCH] D150228: [lldb][NFCI] Replace dw_form_t with llvm::dwarf::Form

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 520854.
bulbazord added a comment.

Remove unused include in header


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150228

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
@@ -227,7 +227,7 @@
   } else {
 for (uint32_t i = 0; i < atom_count; ++i) {
   AtomType type = (AtomType)data.GetU16();
-  dw_form_t form = (dw_form_t)data.GetU16();
+  auto form = static_cast(data.GetU16());
   AppendAtom(type, form);
 }
   }
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
@@ -45,7 +45,7 @@
   const DWARFUnit *GetUnit() const { return m_unit; }
   void SetUnit(const DWARFUnit *unit) { m_unit = unit; }
   dw_form_t Form() const { return m_form; }
-  dw_form_t& FormRef() { return m_form; }
+  dw_form_t () { return m_form; }
   void SetForm(dw_form_t form) { m_form = form; }
   const ValueType () const { return m_value; }
   ValueType () { return m_value; }
@@ -83,7 +83,7 @@
   // Compile unit where m_value was located.
   // It may be different from compile unit where m_value refers to.
   const DWARFUnit *m_unit = nullptr; // Unit for this form
-  dw_form_t m_form = 0;  // Form for this value
+  dw_form_t m_form = dw_form_t(0);   // Form for this value
   ValueType m_value;// Contains all data for the form
 };
 
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
@@ -25,7 +25,7 @@
 
 void DWARFFormValue::Clear() {
   m_unit = nullptr;
-  m_form = 0;
+  m_form = dw_form_t(0);
   m_value = ValueTypeTag();
 }
 
@@ -127,7 +127,7 @@
   m_value.value.uval = data.GetMaxU64(offset_ptr, ref_addr_size);
   break;
 case DW_FORM_indirect:
-  m_form = data.GetULEB128(offset_ptr);
+  m_form = static_cast(data.GetULEB128(offset_ptr));
   indirect = true;
   break;
 case DW_FORM_flag_present:
@@ -321,9 +321,10 @@
   return true;
 
   case DW_FORM_indirect: {
-dw_form_t indirect_form = debug_info_data.GetULEB128(offset_ptr);
-return DWARFFormValue::SkipValue(indirect_form, debug_info_data, offset_ptr,
- unit);
+  auto indirect_form =
+  static_cast(debug_info_data.GetULEB128(offset_ptr));
+  return DWARFFormValue::SkipValue(indirect_form, debug_info_data,
+   offset_ptr, unit);
   }
 
   default:
@@ -573,8 +574,10 @@
   case DW_FORM_block2:
   case DW_FORM_block4:
 return true;
+  default:
+return false;
   }
-  return false;
+  llvm_unreachable("All cases handled above!");
 }
 
 bool DWARFFormValue::IsDataForm(const dw_form_t form) {
@@ -586,8 +589,10 @@
   case DW_FORM_data4:
   case DW_FORM_data8:
 return true;
+  default:
+return false;
   }
-  return false;
+  llvm_unreachable("All cases handled above!");
 }
 
 bool DWARFFormValue::FormIsSupported(dw_form_t form) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -177,7 +177,7 @@
 
 case DW_FORM_indirect:
   form_is_indirect = true;
-  form = data.GetULEB128();
+  form = static_cast(data.GetULEB128());
   break;
 
 case DW_FORM_strp:
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
@@ -55,7 +55,7 @@
   dw_attr_t AttributeAtIndex(uint32_t i) const {
 return m_infos[i].attr.get_attr();
   }
-  dw_attr_t FormAtIndex(uint32_t i) const { return m_infos[i].attr.get_form(); }
+  dw_form_t FormAtIndex(uint32_t i) const { return m_infos[i].attr.get_form(); }
 

[Lldb-commits] [PATCH] D150228: [lldb][NFCI] Replace dw_form_t with llvm::dwarf::Form

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 520853.
bulbazord added a comment.

Do a typedef in dwarf.h (like llvm::dwarf::Tag) instead of explicitly writing 
the type out everywhere


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150228

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
@@ -227,7 +227,7 @@
   } else {
 for (uint32_t i = 0; i < atom_count; ++i) {
   AtomType type = (AtomType)data.GetU16();
-  dw_form_t form = (dw_form_t)data.GetU16();
+  auto form = static_cast(data.GetU16());
   AppendAtom(type, form);
 }
   }
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
@@ -13,6 +13,8 @@
 #include 
 #include 
 
+#include "llvm/BinaryFormat/Dwarf.h"
+
 class DWARFUnit;
 class SymbolFileDWARF;
 class DWARFDIE;
@@ -45,7 +47,7 @@
   const DWARFUnit *GetUnit() const { return m_unit; }
   void SetUnit(const DWARFUnit *unit) { m_unit = unit; }
   dw_form_t Form() const { return m_form; }
-  dw_form_t& FormRef() { return m_form; }
+  dw_form_t () { return m_form; }
   void SetForm(dw_form_t form) { m_form = form; }
   const ValueType () const { return m_value; }
   ValueType () { return m_value; }
@@ -83,7 +85,7 @@
   // Compile unit where m_value was located.
   // It may be different from compile unit where m_value refers to.
   const DWARFUnit *m_unit = nullptr; // Unit for this form
-  dw_form_t m_form = 0;  // Form for this value
+  dw_form_t m_form = dw_form_t(0);   // Form for this value
   ValueType m_value;// Contains all data for the form
 };
 
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
@@ -25,7 +25,7 @@
 
 void DWARFFormValue::Clear() {
   m_unit = nullptr;
-  m_form = 0;
+  m_form = dw_form_t(0);
   m_value = ValueTypeTag();
 }
 
@@ -127,7 +127,7 @@
   m_value.value.uval = data.GetMaxU64(offset_ptr, ref_addr_size);
   break;
 case DW_FORM_indirect:
-  m_form = data.GetULEB128(offset_ptr);
+  m_form = static_cast(data.GetULEB128(offset_ptr));
   indirect = true;
   break;
 case DW_FORM_flag_present:
@@ -321,9 +321,10 @@
   return true;
 
   case DW_FORM_indirect: {
-dw_form_t indirect_form = debug_info_data.GetULEB128(offset_ptr);
-return DWARFFormValue::SkipValue(indirect_form, debug_info_data, offset_ptr,
- unit);
+  auto indirect_form =
+  static_cast(debug_info_data.GetULEB128(offset_ptr));
+  return DWARFFormValue::SkipValue(indirect_form, debug_info_data,
+   offset_ptr, unit);
   }
 
   default:
@@ -573,8 +574,10 @@
   case DW_FORM_block2:
   case DW_FORM_block4:
 return true;
+  default:
+return false;
   }
-  return false;
+  llvm_unreachable("All cases handled above!");
 }
 
 bool DWARFFormValue::IsDataForm(const dw_form_t form) {
@@ -586,8 +589,10 @@
   case DW_FORM_data4:
   case DW_FORM_data8:
 return true;
+  default:
+return false;
   }
-  return false;
+  llvm_unreachable("All cases handled above!");
 }
 
 bool DWARFFormValue::FormIsSupported(dw_form_t form) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -177,7 +177,7 @@
 
 case DW_FORM_indirect:
   form_is_indirect = true;
-  form = data.GetULEB128();
+  form = static_cast(data.GetULEB128());
   break;
 
 case DW_FORM_strp:
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
@@ -55,7 +55,7 @@
   dw_attr_t AttributeAtIndex(uint32_t i) const 

[Lldb-commits] [PATCH] D150228: [lldb][NFCI] Replace dw_form_t with llvm::dwarf::Form

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a reviewer: JDevlieghere.
bulbazord added a comment.

In D150228#4330798 , @jingham wrote:

> Apparently a similar change was made with dw_tag_t, in the line below your 
> first deletion I see:
>
> typedef llvm::dwarf::Tag dw_tag_t;
>
> It seems weird to have dw_tag_t but lvm::dwarf::Form.  If there's a good 
> reason to use the more verbose form, we should probably do the same with the 
> Tag for consistency.  Otherwise, you can just play the same re-typedef-ing as 
> was done for tag, right?

Yes, Jonas did that work in 7fa72881d4cbf. I intentionally chose to not typedef 
here as a matter of personal preference, I prefer the explicitness of the full 
type. I do agree that we should be consistent here though. I don't think it 
quite matters which solution we go with, but do you (or anybody else) have 
strong opinions about this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150228

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


[Lldb-commits] [PATCH] D150228: [lldb][NFCI] Replace dw_form_t with llvm::dwarf::Form

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: aprantl, rastogishubham, fdeazeve, clayborg.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

LLDB currently defines `dw_form_t` as a `uint16_t` which makes sense.
However, LLVM also defines a similar type `llvm::dwarf::Form` which is
an enum backed by a `uint16_t`. Switching to the llvm implementation
means that we can more easily interoperate with the LLVM DWARF code.

Additionally, we get some type checking out of this: I found that
DWARFAttribute had a method called `FormAtIndex` that returned a
`dw_attr_t`. Although `dw_attr_t` is also a `uint16_t` under the hood,
the type checking benefits here are undeniable: If this had returned a
something of different signedness/width, we could have had some bad
bugs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150228

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
  lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -542,7 +542,7 @@
 
   DWARFDebugAbbrev *abbrev = DebugAbbrev();
   if (abbrev) {
-std::set invalid_forms;
+std::set invalid_forms;
 abbrev->GetUnsupportedForms(invalid_forms);
 if (!invalid_forms.empty()) {
   StreamString error;
Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
@@ -71,7 +71,7 @@
 
   struct Atom {
 AtomType type;
-dw_form_t form;
+llvm::dwarf::Form form;
   };
 
   typedef std::vector DIEInfoArray;
@@ -87,7 +87,7 @@
 
 void Clear();
 
-void AppendAtom(AtomType type, dw_form_t form);
+void AppendAtom(AtomType type, llvm::dwarf::Form form);
 
 lldb::offset_t Read(const lldb_private::DataExtractor ,
 lldb::offset_t offset);
Index: lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
@@ -154,7 +154,8 @@
   ClearAtoms();
 }
 
-void DWARFMappedHash::Prologue::AppendAtom(AtomType type, dw_form_t form) {
+void DWARFMappedHash::Prologue::AppendAtom(AtomType type,
+   llvm::dwarf::Form form) {
   atoms.push_back({type, form});
   atom_mask |= 1u << type;
   switch (form) {
@@ -227,7 +228,7 @@
   } else {
 for (uint32_t i = 0; i < atom_count; ++i) {
   AtomType type = (AtomType)data.GetU16();
-  dw_form_t form = (dw_form_t)data.GetU16();
+  auto form = static_cast(data.GetU16());
   AppendAtom(type, form);
 }
   }
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
@@ -13,6 +13,8 @@
 #include 
 #include 
 
+#include "llvm/BinaryFormat/Dwarf.h"
+
 class DWARFUnit;
 class SymbolFileDWARF;
 class DWARFDIE;
@@ -40,13 +42,13 @@
 
   DWARFFormValue() = default;
   DWARFFormValue(const DWARFUnit *unit) : m_unit(unit) {}
-  DWARFFormValue(const DWARFUnit *unit, dw_form_t form)
+  DWARFFormValue(const DWARFUnit *unit, llvm::dwarf::Form form)
   : m_unit(unit), m_form(form) {}
   const DWARFUnit *GetUnit() const { return m_unit; }
   void SetUnit(const DWARFUnit *unit) { m_unit = unit; }
-  dw_form_t Form() const { return m_form; }
-  dw_form_t& FormRef() { return m_form; }
-  void SetForm(dw_form_t form) { m_form = form; }
+  llvm::dwarf::Form Form() const { return m_form; }
+  llvm::dwarf::Form () { return m_form; }
+  void SetForm(llvm::dwarf::Form form) { m_form = form; }
   const ValueType () const { return m_value; }
   ValueType () { return m_value; }
   void SetValue(const ValueType ) { m_value = val; }
@@ -55,7 +57,7 @@
   bool ExtractValue(const lldb_private::DWARFDataExtractor 

[Lldb-commits] [PATCH] D150157: [lldb] Mark most SBAPI methods involving private types as protected or private

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/unittests/API/SBCommandInterpreterTest.cpp:24
 SBDebugger::Initialize();
 m_dbg = SBDebugger::Create(/*source_init_files=*/false);
   }

jingham wrote:
> It isn't clear to me how the changes in this file fit in with your overall 
> goal?
I'm removing the `SBCommandInterpreter` member of this class because in order 
to construct an object of this class, `SBCommandInterpreter` would need to have 
an empty default constructor (which we do not have currently). I didn't want to 
add a constructor for SBCommandInterpreter just to avoid changing the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150157

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


[Lldb-commits] [PATCH] D150222: [lldb][NFCI] Remove custom dwarf LEB128 types

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb77e41f2886a: [lldb][NFCI] Remove custom dwarf LEB128 types 
(authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150222

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
@@ -216,22 +216,22 @@
   // in the .debug_info
   case DW_FORM_exprloc:
   case DW_FORM_block: {
-dw_uleb128_t size = debug_info_data.GetULEB128(offset_ptr);
+uint64_t size = debug_info_data.GetULEB128(offset_ptr);
 *offset_ptr += size;
   }
 return true;
   case DW_FORM_block1: {
-dw_uleb128_t size = debug_info_data.GetU8(offset_ptr);
+uint8_t size = debug_info_data.GetU8(offset_ptr);
 *offset_ptr += size;
   }
 return true;
   case DW_FORM_block2: {
-dw_uleb128_t size = debug_info_data.GetU16(offset_ptr);
+uint16_t size = debug_info_data.GetU16(offset_ptr);
 *offset_ptr += size;
   }
 return true;
   case DW_FORM_block4: {
-dw_uleb128_t size = debug_info_data.GetU32(offset_ptr);
+uint32_t size = debug_info_data.GetU32(offset_ptr);
 *offset_ptr += size;
   }
 return true;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
@@ -42,7 +42,7 @@
   void GetUnsupportedForms(std::set _forms) const;
 
   const DWARFAbbreviationDeclaration *
-  GetAbbreviationDeclaration(dw_uleb128_t abbrCode) const;
+  GetAbbreviationDeclaration(uint32_t abbrCode) const;
 
   /// Unit test accessor functions.
   /// @{
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
@@ -27,7 +27,7 @@
   m_offset = begin_offset;
   Clear();
   DWARFAbbreviationDeclaration abbrevDeclaration;
-  dw_uleb128_t prev_abbr_code = 0;
+  uint32_t prev_abbr_code = 0;
   while (true) {
 llvm::Expected es =
 abbrevDeclaration.extract(data, offset_ptr);
@@ -50,7 +50,7 @@
 // DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration()
 const DWARFAbbreviationDeclaration *
 DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration(
-dw_uleb128_t abbrCode) const {
+uint32_t abbrCode) const {
   if (m_idx_offset == UINT32_MAX) {
 DWARFAbbreviationDeclarationCollConstIter pos;
 DWARFAbbreviationDeclarationCollConstIter end = m_decls.end();
@@ -66,7 +66,6 @@
   return nullptr;
 }
 
-
 // DWARFAbbreviationDeclarationSet::GetUnsupportedForms()
 void DWARFAbbreviationDeclarationSet::GetUnsupportedForms(
 std::set _forms) const {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
@@ -22,8 +22,8 @@
   // For hand crafting an abbreviation declaration
   DWARFAbbreviationDeclaration(dw_tag_t tag, uint8_t has_children);
 
-  dw_uleb128_t Code() const { return m_code; }
-  void SetCode(dw_uleb128_t code) { m_code = code; }
+  uint32_t Code() const { return m_code; }
+  void SetCode(uint32_t code) { m_code = code; }
   dw_tag_t Tag() const { return m_tag; }
   bool HasChildren() const { return m_has_children; }
   size_t NumAttributes() const { return m_attributes.size(); }
@@ -55,7 +55,7 @@
   bool IsValid();
 
 protected:
-  dw_uleb128_t m_code = InvalidCode;
+  uint32_t m_code = InvalidCode;
   dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
   uint8_t m_has_children = 0;
   DWARFAttribute::collection m_attributes;
Index: lldb/include/lldb/Core/dwarf.h
===
--- lldb/include/lldb/Core/dwarf.h
+++ lldb/include/lldb/Core/dwarf.h
@@ -21,8 +21,6 @@
 }
 }
 
-typedef uint32_t dw_uleb128_t;
-typedef int32_t dw_sleb128_t;
 typedef uint16_t dw_attr_t;
 typedef uint16_t dw_form_t;
 typedef llvm::dwarf::Tag dw_tag_t;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D150157: [lldb] Mark most SBAPI methods involving private types as protected or private

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/include/lldb/API/SBBreakpoint.h:18-19
 class ScriptInterpreter;
+namespace python {
+class SWIGBridge;
 }

mib wrote:
> We've talked about this offline, but I think we should stay language agnostic 
> in the SBAPI, so exposing a python namespace here is bothering me a little 
> bit.
I agree, but we can refactor this later. Removing and/or changing forward 
declarations doesn't break ABI.



Comment at: lldb/source/API/SBCommandInterpreter.cpp:37
+namespace lldb_private {
 class CommandPluginInterfaceImplementation : public CommandObjectParsed {
 public:

mib wrote:
> I find it a bit odd to have this here ... May be we should move this class 
> out the the `API` directory ?
It's a little odd for sure, but it is an implementation detail so having it in 
the cpp file seems alright. Where would you put it?



Comment at: 
lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h:64-90
+class SWIGBridge {
+public:
+  static PythonObject ToSWIGWrapper(std::unique_ptr value_sb);
+  static PythonObject ToSWIGWrapper(lldb::ValueObjectSP value_sp);
+  static PythonObject ToSWIGWrapper(lldb::TargetSP target_sp);
+  static PythonObject ToSWIGWrapper(lldb::ProcessSP process_sp);
+  static PythonObject ToSWIGWrapper(lldb::ThreadPlanSP thread_plan_sp);

mib wrote:
> Although this is nested in the `python` namespace, I think `SWIGBridge` 
> should be a templated class defined in the `ScriptedInterpreter` header and 
> this class should be instead renamed as `SWIGPythonBridge` and be a 
> specialization of the `SWIGBridge` class. We can do that as a follow-up but a 
> `TODO` comment would be nice.
Sure, I can add the TODO. I'd rather not add the templates or subclass in this 
patch as it is complicated enough already.



Comment at: 
lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h:248-254
+void *LLDBSWIGPython_CastPyObjectToSBData(PyObject *data);
+void *LLDBSWIGPython_CastPyObjectToSBBreakpoint(PyObject *data);
+void *LLDBSWIGPython_CastPyObjectToSBAttachInfo(PyObject *data);
+void *LLDBSWIGPython_CastPyObjectToSBLaunchInfo(PyObject *data);
+void *LLDBSWIGPython_CastPyObjectToSBError(PyObject *data);
+void *LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data);
+void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data);

mib wrote:
> Can we move these in the `python` namespace as well ?
Sure


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150157

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


[Lldb-commits] [PATCH] D150222: [lldb][NFCI] Remove custom dwarf LEB128 types

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: aprantl, rastogishubham, fdeazeve, JDevlieghere, 
clayborg.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The LEB128 type defined by the DWARF standard is explicitly a variable-length
encoding of an integer. LLDB had defined `uleb128` and `sleb128` types
to be 32-bit  but in many places in both LLVM and LLDB we treat the maximum
width of LEB128 types to be 64, so let's remove these types and be
consistent.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150222

Files:
  lldb/include/lldb/Core/dwarf.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
@@ -216,22 +216,22 @@
   // in the .debug_info
   case DW_FORM_exprloc:
   case DW_FORM_block: {
-dw_uleb128_t size = debug_info_data.GetULEB128(offset_ptr);
+uint64_t size = debug_info_data.GetULEB128(offset_ptr);
 *offset_ptr += size;
   }
 return true;
   case DW_FORM_block1: {
-dw_uleb128_t size = debug_info_data.GetU8(offset_ptr);
+uint8_t size = debug_info_data.GetU8(offset_ptr);
 *offset_ptr += size;
   }
 return true;
   case DW_FORM_block2: {
-dw_uleb128_t size = debug_info_data.GetU16(offset_ptr);
+uint16_t size = debug_info_data.GetU16(offset_ptr);
 *offset_ptr += size;
   }
 return true;
   case DW_FORM_block4: {
-dw_uleb128_t size = debug_info_data.GetU32(offset_ptr);
+uint32_t size = debug_info_data.GetU32(offset_ptr);
 *offset_ptr += size;
   }
 return true;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
@@ -42,7 +42,7 @@
   void GetUnsupportedForms(std::set _forms) const;
 
   const DWARFAbbreviationDeclaration *
-  GetAbbreviationDeclaration(dw_uleb128_t abbrCode) const;
+  GetAbbreviationDeclaration(uint32_t abbrCode) const;
 
   /// Unit test accessor functions.
   /// @{
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
@@ -27,7 +27,7 @@
   m_offset = begin_offset;
   Clear();
   DWARFAbbreviationDeclaration abbrevDeclaration;
-  dw_uleb128_t prev_abbr_code = 0;
+  uint32_t prev_abbr_code = 0;
   while (true) {
 llvm::Expected es =
 abbrevDeclaration.extract(data, offset_ptr);
@@ -50,7 +50,7 @@
 // DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration()
 const DWARFAbbreviationDeclaration *
 DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration(
-dw_uleb128_t abbrCode) const {
+uint32_t abbrCode) const {
   if (m_idx_offset == UINT32_MAX) {
 DWARFAbbreviationDeclarationCollConstIter pos;
 DWARFAbbreviationDeclarationCollConstIter end = m_decls.end();
@@ -66,7 +66,6 @@
   return nullptr;
 }
 
-
 // DWARFAbbreviationDeclarationSet::GetUnsupportedForms()
 void DWARFAbbreviationDeclarationSet::GetUnsupportedForms(
 std::set _forms) const {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
@@ -22,8 +22,8 @@
   // For hand crafting an abbreviation declaration
   DWARFAbbreviationDeclaration(dw_tag_t tag, uint8_t has_children);
 
-  dw_uleb128_t Code() const { return m_code; }
-  void SetCode(dw_uleb128_t code) { m_code = code; }
+  uint32_t Code() const { return m_code; }
+  void SetCode(uint32_t code) { m_code = code; }
   dw_tag_t Tag() const { return m_tag; }
   bool HasChildren() const { return m_has_children; }
   size_t NumAttributes() const { return m_attributes.size(); }
@@ -55,7 +55,7 @@
   bool IsValid();
 
 protected:
-  dw_uleb128_t m_code = InvalidCode;
+  uint32_t m_code = InvalidCode;
   dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
   uint8_t m_has_children = 0;
   DWARFAttribute::collection m_attributes;
Index: lldb/include/lldb/Core/dwarf.h
===
--- lldb/include/lldb/Core/dwarf.h
+++ lldb/include/lldb/Core/dwarf.h
@@ -21,8 +21,6 @@
 }
 }
 
-typedef uint32_t dw_uleb128_t;
-typedef int32_t dw_sleb128_t;
 typedef 

[Lldb-commits] [PATCH] D150219: [lldb][NFCI] Remove n^2 loops and simplify iterator usage

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.

I like this. :)




Comment at: lldb/source/Utility/Broadcaster.cpp:392
 }
-m_event_map.erase(iter);
+iter = m_event_map.erase(iter);
   }

I don't think you need to actually capture the iterator here? std::map::erase 
doesn't invalidate existing iterators* (so `begin` and `end` are fine) and we 
redefine `iter` at the beginning of this loop.

*:https://en.cppreference.com/w/cpp/container/map/erase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150219

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


[Lldb-commits] [PATCH] D150168: [lldb] Simplify predicates of find_if in BroadcastManager

2023-05-09 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec77d1f3d9fc: [lldb] Simplify predicates of find_if in 
BroadcastManager (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150168

Files:
  lldb/include/lldb/Utility/Broadcaster.h
  lldb/source/Utility/Broadcaster.cpp

Index: lldb/source/Utility/Broadcaster.cpp
===
--- lldb/source/Utility/Broadcaster.cpp
+++ lldb/source/Utility/Broadcaster.cpp
@@ -336,10 +336,13 @@
   collection::iterator iter = m_event_map.begin(), end_iter = m_event_map.end();
   uint32_t available_bits = event_spec.GetEventBits();
 
+  auto class_matches = [_spec](const event_listener_key ) -> bool {
+return input.first.GetBroadcasterClass() ==
+   event_spec.GetBroadcasterClass();
+  };
+
   while (iter != end_iter &&
- (iter = find_if(iter, end_iter,
- BroadcasterClassMatches(
- event_spec.GetBroadcasterClass( != end_iter) {
+ (iter = find_if(iter, end_iter, class_matches)) != end_iter) {
 available_bits &= ~((*iter).first.GetEventBits());
 iter++;
   }
@@ -362,7 +365,13 @@
   if (m_listeners.erase(listener_sp) == 0)
 return false;
 
-  ListenerMatchesAndSharedBits predicate(event_spec, listener_sp);
+  auto listener_matches_and_shared_bits =
+  [_sp, _spec](const event_listener_key ) -> bool {
+return input.first.GetBroadcasterClass() ==
+   event_spec.GetBroadcasterClass() &&
+   (input.first.GetEventBits() & event_spec.GetEventBits()) != 0 &&
+   input.second == listener_sp;
+  };
   std::vector to_be_readded;
   uint32_t event_bits_to_remove = event_spec.GetEventBits();
 
@@ -370,7 +379,8 @@
   // matches that weren't exact to re-add:
   while (true) {
 collection::iterator iter, end_iter = m_event_map.end();
-iter = find_if(m_event_map.begin(), end_iter, predicate);
+iter = find_if(m_event_map.begin(), end_iter,
+   listener_matches_and_shared_bits);
 if (iter == end_iter) {
   break;
 }
@@ -397,9 +407,13 @@
 const BroadcastEventSpec _spec) const {
   std::lock_guard guard(m_manager_mutex);
 
+  auto event_spec_matches =
+  [_spec](const event_listener_key ) -> bool {
+return input.first.IsContainedIn(event_spec);
+  };
+
   collection::const_iterator iter, end_iter = m_event_map.end();
-  iter = find_if(m_event_map.begin(), end_iter,
- BroadcastEventSpecMatches(event_spec));
+  iter = find_if(m_event_map.begin(), end_iter, event_spec_matches);
   if (iter != end_iter)
 return (*iter).second;
 
@@ -408,17 +422,25 @@
 
 void BroadcasterManager::RemoveListener(Listener *listener) {
   std::lock_guard guard(m_manager_mutex);
-  ListenerMatchesPointer predicate(listener);
+  auto listeners_predicate =
+  [](const lldb::ListenerSP ) -> bool {
+return input.get() == listener;
+  };
+
   listener_collection::iterator iter = m_listeners.begin(),
 end_iter = m_listeners.end();
 
-  iter = std::find_if(iter, end_iter, predicate);
+  iter = std::find_if(iter, end_iter, listeners_predicate);
   if (iter != end_iter)
 m_listeners.erase(iter);
 
   while (true) {
+auto events_predicate =
+[](const event_listener_key ) -> bool {
+  return input.second.get() == listener;
+};
 collection::iterator iter, end_iter = m_event_map.end();
-iter = find_if(m_event_map.begin(), end_iter, predicate);
+iter = find_if(m_event_map.begin(), end_iter, events_predicate);
 if (iter == end_iter)
   break;
 
@@ -428,14 +450,18 @@
 
 void BroadcasterManager::RemoveListener(const lldb::ListenerSP _sp) {
   std::lock_guard guard(m_manager_mutex);
-  ListenerMatches predicate(listener_sp);
+
+  auto listener_matches =
+  [_sp](const event_listener_key ) -> bool {
+return input.second == listener_sp;
+  };
 
   if (m_listeners.erase(listener_sp) == 0)
 return;
 
   while (true) {
 collection::iterator iter, end_iter = m_event_map.end();
-iter = find_if(m_event_map.begin(), end_iter, predicate);
+iter = find_if(m_event_map.begin(), end_iter, listener_matches);
 if (iter == end_iter)
   break;
 
@@ -449,10 +475,13 @@
 
   collection::iterator iter = m_event_map.begin(), end_iter = m_event_map.end();
 
+  auto class_matches = [](const event_listener_key ) -> bool {
+return input.first.GetBroadcasterClass() ==
+   broadcaster.GetBroadcasterClass();
+  };
+
   while (iter != end_iter &&
- (iter = find_if(iter, end_iter,
- BroadcasterClassMatches(
- broadcaster.GetBroadcasterClass( != end_iter) {
+ (iter = find_if(iter, end_iter, class_matches)) != end_iter) {
 (*iter).second->StartListeningForEvents(,
 

[Lldb-commits] [PATCH] D150158: Add optional to debugserver's "tell me about all binaries in the process" packet, to limit it to just load addresses and names

2023-05-08 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

I have no problem with removing mod_date since you're only removing the 
requirement in the Darwin-specific code. Also, be sure to remove the portion of 
the commit message that says this introduces a regression since you've fixed 
the test now. It would be confusing for future code archeologists.

LGTM!




Comment at: lldb/tools/debugserver/source/MacOSX/MachProcess.mm:1141
 }
-return FormatDynamicLibrariesIntoJSON(image_infos);
+return FormatDynamicLibrariesIntoJSON(image_infos, true);
 }

nit: Could you add a comment specifying what the bool argument is for?
```
return FormatDynamicLibrariesIntoJSON(image_infos, /* report_load_commands = */ 
true);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150158

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


[Lldb-commits] [PATCH] D150168: [lldb] Simplify predicates of find_if in BroadcastManager

2023-05-08 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, jingham, mib.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

We had some custom classes that were used as the predicate for
`std::find_if`. It would be a lot simpler if we used lambdas instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150168

Files:
  lldb/include/lldb/Utility/Broadcaster.h
  lldb/source/Utility/Broadcaster.cpp

Index: lldb/source/Utility/Broadcaster.cpp
===
--- lldb/source/Utility/Broadcaster.cpp
+++ lldb/source/Utility/Broadcaster.cpp
@@ -336,10 +336,13 @@
   collection::iterator iter = m_event_map.begin(), end_iter = m_event_map.end();
   uint32_t available_bits = event_spec.GetEventBits();
 
+  auto class_matches = [_spec](const event_listener_key ) -> bool {
+return input.first.GetBroadcasterClass() ==
+   event_spec.GetBroadcasterClass();
+  };
+
   while (iter != end_iter &&
- (iter = find_if(iter, end_iter,
- BroadcasterClassMatches(
- event_spec.GetBroadcasterClass( != end_iter) {
+ (iter = find_if(iter, end_iter, class_matches)) != end_iter) {
 available_bits &= ~((*iter).first.GetEventBits());
 iter++;
   }
@@ -362,7 +365,13 @@
   if (m_listeners.erase(listener_sp) == 0)
 return false;
 
-  ListenerMatchesAndSharedBits predicate(event_spec, listener_sp);
+  auto listener_matches_and_shared_bits =
+  [_sp, _spec](const event_listener_key ) -> bool {
+return input.first.GetBroadcasterClass() ==
+   event_spec.GetBroadcasterClass() &&
+   (input.first.GetEventBits() & event_spec.GetEventBits()) != 0 &&
+   input.second == listener_sp;
+  };
   std::vector to_be_readded;
   uint32_t event_bits_to_remove = event_spec.GetEventBits();
 
@@ -370,7 +379,8 @@
   // matches that weren't exact to re-add:
   while (true) {
 collection::iterator iter, end_iter = m_event_map.end();
-iter = find_if(m_event_map.begin(), end_iter, predicate);
+iter = find_if(m_event_map.begin(), end_iter,
+   listener_matches_and_shared_bits);
 if (iter == end_iter) {
   break;
 }
@@ -397,9 +407,13 @@
 const BroadcastEventSpec _spec) const {
   std::lock_guard guard(m_manager_mutex);
 
+  auto event_spec_matches =
+  [_spec](const event_listener_key ) -> bool {
+return input.first.IsContainedIn(event_spec);
+  };
+
   collection::const_iterator iter, end_iter = m_event_map.end();
-  iter = find_if(m_event_map.begin(), end_iter,
- BroadcastEventSpecMatches(event_spec));
+  iter = find_if(m_event_map.begin(), end_iter, event_spec_matches);
   if (iter != end_iter)
 return (*iter).second;
 
@@ -408,17 +422,25 @@
 
 void BroadcasterManager::RemoveListener(Listener *listener) {
   std::lock_guard guard(m_manager_mutex);
-  ListenerMatchesPointer predicate(listener);
+  auto listeners_predicate =
+  [](const lldb::ListenerSP ) -> bool {
+return input.get() == listener;
+  };
+
   listener_collection::iterator iter = m_listeners.begin(),
 end_iter = m_listeners.end();
 
-  iter = std::find_if(iter, end_iter, predicate);
+  iter = std::find_if(iter, end_iter, listeners_predicate);
   if (iter != end_iter)
 m_listeners.erase(iter);
 
   while (true) {
+auto events_predicate =
+[](const event_listener_key ) -> bool {
+  return input.second.get() == listener;
+};
 collection::iterator iter, end_iter = m_event_map.end();
-iter = find_if(m_event_map.begin(), end_iter, predicate);
+iter = find_if(m_event_map.begin(), end_iter, events_predicate);
 if (iter == end_iter)
   break;
 
@@ -428,14 +450,18 @@
 
 void BroadcasterManager::RemoveListener(const lldb::ListenerSP _sp) {
   std::lock_guard guard(m_manager_mutex);
-  ListenerMatches predicate(listener_sp);
+
+  auto listener_matches =
+  [_sp](const event_listener_key ) -> bool {
+return input.second == listener_sp;
+  };
 
   if (m_listeners.erase(listener_sp) == 0)
 return;
 
   while (true) {
 collection::iterator iter, end_iter = m_event_map.end();
-iter = find_if(m_event_map.begin(), end_iter, predicate);
+iter = find_if(m_event_map.begin(), end_iter, listener_matches);
 if (iter == end_iter)
   break;
 
@@ -449,10 +475,13 @@
 
   collection::iterator iter = m_event_map.begin(), end_iter = m_event_map.end();
 
+  auto class_matches = [](const event_listener_key ) -> bool {
+return input.first.GetBroadcasterClass() ==
+   broadcaster.GetBroadcasterClass();
+  };
+
   while (iter != end_iter &&
- (iter = find_if(iter, end_iter,
- BroadcasterClassMatches(
- broadcaster.GetBroadcasterClass( != end_iter) {
+ (iter = 

[Lldb-commits] [PATCH] D150158: Add optional to debugserver's "tell me about all binaries in the process" packet, to limit it to just load addresses and names

2023-05-08 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

This looks good to me.

> This patch does have a regression on 
> API/macosx/unregistered-macho/TestUnregisteredMacho.py that I wrote last 
> summer; I have the patch generate JSON for a binary that it had an address 
> for, but could not read the mach-o headers. This test case is specifically 
> testing the address of something that is not a mach-o in memory and testing 
> that nothin is returned. I need to revisit why I wrote this before I fix it 
> by changing my patch or removing the test, but the reason for the test 
> failure is obvious, it's a minor revision either way.

I assume you plan on addressing this failure before landing this change or 
otherwise disabling the test?




Comment at: lldb/tools/debugserver/source/MacOSX/MachProcess.mm:930-931
+if (!image_infos[i].is_valid_mach_header) {
+  image_infos_array_sp->AddItem(image_info_dict_sp);
+  continue;
+}

Why do we still want to add information about this dylib if the mach header 
isn't valid? 



Comment at: lldb/tools/debugserver/source/RNBRemote.cpp:5932-5933
 //
 //  jGetLoadedDynamicLibrariesInfos:{"fetch_all_solibs":true}
-//  Use the new style (macOS 10.12, tvOS 10, iOS 10, watchOS 3) dyld SPI to
-//  get a list of all the
-//  libraries loaded
+//  Use the new dyld SPI to get a list of all the libraries loaded
 //

Should probably update this comment with `"report_load_commands":false` as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150158

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


[Lldb-commits] [PATCH] D150160: [lldb] Simplify Log::PutString (NFC)

2023-05-08 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: lldb/source/Utility/Log.cpp:135
-void Log::PutCString(const char *cstr) { Printf("%s", cstr); }
-void Log::PutString(llvm::StringRef str) { PutCString(str.str().c_str()); }
 

Amazing



Comment at: lldb/source/Utility/Log.cpp:151-154
 
 // All logging eventually boils down to this function call. If we have a
 // callback registered, then we call the logging callback. If we have a valid
 // file handle, we also log to the file.

We can probably update this comment as it's no longer true: `Log::PutCString` 
will skip `Printf` -> `VAPrintf` entirely now...



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150160

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


[Lldb-commits] [PATCH] D149702: [LLDB] Add minimal support for the new Mojo language

2023-05-05 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

Don't forget to come back and update it when you get an official designation!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149702

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


[Lldb-commits] [PATCH] D149987: ObjectFile: introduce a COFF object file plugin

2023-05-05 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149987

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


[Lldb-commits] [PATCH] D149987: ObjectFile: introduce a COFF object file plugin

2023-05-05 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp:103-104
+
+  return new ObjectFileCOFF(module_sp, data_sp, data_offset, file, file_offset,
+length);
+}

compnerd wrote:
> bulbazord wrote:
> > Reading the implementation of the constructor, it looks like the 
> > constructor can fail to initialize correctly (specifically `m_object` may 
> > not be correctly populated). What are callers supposed to do in the way of 
> > validation here? Maybe there is further validation we can do in this 
> > function so that the constructor is only invoked if we're absolutely sure 
> > it will work?
> There isn't much you can do IMO.  The `new` can fail just as well - at which 
> point, what do we do?  The constructor should only really fail if the return 
> type from libLLVMObject has suddenly changed into an invalid type.  That cast 
> really cannot fail in a way that we can recover from.
`createBinary` and the subsequent cast may not fail in a recoverable fashion 
but doing it in the constructor means that whatever is trying to create an 
object gets back an `ObjectFileCOFF` object even if it wasn't initialized 
correctly. If you did that work in `CreateInstance`, you could return `nullptr` 
if `createBinary` and that cast failed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149987

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


[Lldb-commits] [PATCH] D149987: ObjectFile: introduce a COFF object file plugin

2023-05-05 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

We're definitely going to want a test for this, either a shell test or a unit 
test.




Comment at: lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp:103-104
+
+  return new ObjectFileCOFF(module_sp, data_sp, data_offset, file, file_offset,
+length);
+}

Reading the implementation of the constructor, it looks like the constructor 
can fail to initialize correctly (specifically `m_object` may not be correctly 
populated). What are callers supposed to do in the way of validation here? 
Maybe there is further validation we can do in this function so that the 
constructor is only invoked if we're absolutely sure it will work?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149987

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


[Lldb-commits] [PATCH] D149900: [lldb] Expose a const iterator for SymbolContextList

2023-05-04 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

Looks like this may have broken the Debian buildbot: 
https://lab.llvm.org/buildbot/#/builders/68/builds/52162/steps/6/logs/stdio

I'm taking a look and will try to fix forward. If I can't figure it out 
quickly, I will revert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149900

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


[Lldb-commits] [PATCH] D149900: [lldb] Expose a const iterator for SymbolContextList

2023-05-04 Thread Alex Langford 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 rG04aa943be8ed: [lldb] Expose a const iterator for 
SymbolContextList (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149900

Files:
  lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
  lldb/include/lldb/Symbol/SymbolContext.h
  lldb/include/lldb/Symbol/UnwindTable.h
  lldb/source/API/SBThread.cpp
  lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
  lldb/source/Breakpoint/BreakpointResolverName.cpp
  lldb/source/Commands/CommandCompletions.cpp
  lldb/source/Commands/CommandObjectSource.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Core/AddressResolverFileLine.cpp
  lldb/source/Core/SourceManager.cpp
  lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Symbol/Symbol.cpp
  lldb/source/Symbol/SymbolContext.cpp
  lldb/source/Symbol/UnwindTable.cpp

Index: lldb/source/Symbol/UnwindTable.cpp
===
--- lldb/source/Symbol/UnwindTable.cpp
+++ lldb/source/Symbol/UnwindTable.cpp
@@ -86,8 +86,8 @@
 
 UnwindTable::~UnwindTable() = default;
 
-std::optional UnwindTable::GetAddressRange(const Address ,
- SymbolContext ) {
+std::optional
+UnwindTable::GetAddressRange(const Address , const SymbolContext ) {
   AddressRange range;
 
   // First check the unwind info from the object file plugin
@@ -150,9 +150,8 @@
 // don't add it to the UnwindTable.  This is intended for use by target modules
 // show-unwind where we want to create new UnwindPlans, not re-use existing
 // ones.
-FuncUnwindersSP
-UnwindTable::GetUncachedFuncUnwindersContainingAddress(const Address ,
-   SymbolContext ) {
+FuncUnwindersSP UnwindTable::GetUncachedFuncUnwindersContainingAddress(
+const Address , const SymbolContext ) {
   Initialize();
 
   auto range_or = GetAddressRange(addr, sc);
Index: lldb/source/Symbol/SymbolContext.cpp
===
--- lldb/source/Symbol/SymbolContext.cpp
+++ lldb/source/Symbol/SymbolContext.cpp
@@ -771,14 +771,11 @@
   Module *module = module_sp.get();
 
   auto ProcessMatches = [this, , ,
- module](SymbolContextList _list,
+ module](const SymbolContextList _list,
  Status ) -> const Symbol * {
 llvm::SmallVector external_symbols;
 llvm::SmallVector internal_symbols;
-const uint32_t matches = sc_list.GetSize();
-for (uint32_t i = 0; i < matches; ++i) {
-  SymbolContext sym_ctx;
-  sc_list.GetContextAtIndex(i, sym_ctx);
+for (const SymbolContext _ctx : sc_list) {
   if (sym_ctx.symbol) {
 const Symbol *symbol = sym_ctx.symbol;
 const Address sym_address = symbol->GetAddress();
Index: lldb/source/Symbol/Symbol.cpp
===
--- lldb/source/Symbol/Symbol.cpp
+++ lldb/source/Symbol/Symbol.cpp
@@ -488,15 +488,9 @@
 lldb_private::SymbolContextList sc_list;
 module_sp->FindSymbolsWithNameAndType(reexport_name, eSymbolTypeAny,
   sc_list);
-const size_t num_scs = sc_list.GetSize();
-if (num_scs > 0) {
-  for (size_t i = 0; i < num_scs; ++i) {
-lldb_private::SymbolContext sc;
-if (sc_list.GetContextAtIndex(i, sc)) {
-  if (sc.symbol->IsExternal())
-return sc.symbol;
-}
-  }
+for (const SymbolContext  : sc_list) {
+  if (sc.symbol->IsExternal())
+return sc.symbol;
 }
 // If we didn't find the symbol in this module, it may be because this
 // module re-exports some whole other library.  We have to search those as
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4028,52 +4028,45 @@
   lldb_private::SymbolContextList sc_list;
   process->GetTarget().GetImages().FindSymbolsWithNameAndType(
   ConstString(symbol_name), eSymbolTypeAny, sc_list);
-  if (!sc_list.IsEmpty()) {
-const size_t num_scs = 

[Lldb-commits] [PATCH] D149900: [lldb] Expose a const iterator for SymbolContextList

2023-05-04 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 519690.
bulbazord added a comment.

Explicitly write out type


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149900

Files:
  lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
  lldb/include/lldb/Symbol/SymbolContext.h
  lldb/include/lldb/Symbol/UnwindTable.h
  lldb/source/API/SBThread.cpp
  lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
  lldb/source/Breakpoint/BreakpointResolverName.cpp
  lldb/source/Commands/CommandCompletions.cpp
  lldb/source/Commands/CommandObjectSource.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Core/AddressResolverFileLine.cpp
  lldb/source/Core/SourceManager.cpp
  lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Symbol/Symbol.cpp
  lldb/source/Symbol/SymbolContext.cpp
  lldb/source/Symbol/UnwindTable.cpp

Index: lldb/source/Symbol/UnwindTable.cpp
===
--- lldb/source/Symbol/UnwindTable.cpp
+++ lldb/source/Symbol/UnwindTable.cpp
@@ -86,8 +86,8 @@
 
 UnwindTable::~UnwindTable() = default;
 
-std::optional UnwindTable::GetAddressRange(const Address ,
- SymbolContext ) {
+std::optional
+UnwindTable::GetAddressRange(const Address , const SymbolContext ) {
   AddressRange range;
 
   // First check the unwind info from the object file plugin
@@ -150,9 +150,8 @@
 // don't add it to the UnwindTable.  This is intended for use by target modules
 // show-unwind where we want to create new UnwindPlans, not re-use existing
 // ones.
-FuncUnwindersSP
-UnwindTable::GetUncachedFuncUnwindersContainingAddress(const Address ,
-   SymbolContext ) {
+FuncUnwindersSP UnwindTable::GetUncachedFuncUnwindersContainingAddress(
+const Address , const SymbolContext ) {
   Initialize();
 
   auto range_or = GetAddressRange(addr, sc);
Index: lldb/source/Symbol/SymbolContext.cpp
===
--- lldb/source/Symbol/SymbolContext.cpp
+++ lldb/source/Symbol/SymbolContext.cpp
@@ -771,14 +771,11 @@
   Module *module = module_sp.get();
 
   auto ProcessMatches = [this, , ,
- module](SymbolContextList _list,
+ module](const SymbolContextList _list,
  Status ) -> const Symbol * {
 llvm::SmallVector external_symbols;
 llvm::SmallVector internal_symbols;
-const uint32_t matches = sc_list.GetSize();
-for (uint32_t i = 0; i < matches; ++i) {
-  SymbolContext sym_ctx;
-  sc_list.GetContextAtIndex(i, sym_ctx);
+for (const SymbolContext _ctx : sc_list) {
   if (sym_ctx.symbol) {
 const Symbol *symbol = sym_ctx.symbol;
 const Address sym_address = symbol->GetAddress();
Index: lldb/source/Symbol/Symbol.cpp
===
--- lldb/source/Symbol/Symbol.cpp
+++ lldb/source/Symbol/Symbol.cpp
@@ -488,15 +488,9 @@
 lldb_private::SymbolContextList sc_list;
 module_sp->FindSymbolsWithNameAndType(reexport_name, eSymbolTypeAny,
   sc_list);
-const size_t num_scs = sc_list.GetSize();
-if (num_scs > 0) {
-  for (size_t i = 0; i < num_scs; ++i) {
-lldb_private::SymbolContext sc;
-if (sc_list.GetContextAtIndex(i, sc)) {
-  if (sc.symbol->IsExternal())
-return sc.symbol;
-}
-  }
+for (const SymbolContext  : sc_list) {
+  if (sc.symbol->IsExternal())
+return sc.symbol;
 }
 // If we didn't find the symbol in this module, it may be because this
 // module re-exports some whole other library.  We have to search those as
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4028,52 +4028,45 @@
   lldb_private::SymbolContextList sc_list;
   process->GetTarget().GetImages().FindSymbolsWithNameAndType(
   ConstString(symbol_name), eSymbolTypeAny, sc_list);
-  if (!sc_list.IsEmpty()) {
-const size_t num_scs = sc_list.GetSize();
-for (size_t sc_idx = 0;
- sc_idx < num_scs &&
- symbol_load_addr == 

[Lldb-commits] [PATCH] D149914: [lldb] Refactor ObjCLanguage::MethodName

2023-05-04 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, aprantl, mib, jingham, kastiglione.
Herald added a subscriber: arphaman.
Herald added a reviewer: shafik.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The goal of this patch is to make it easier to reason about the state of
ObjCLanguage::MethodName. I do that in several ways:

- Instead of using the constructor directly, you go through a factory method. 
It returns a std::optional so either you got an 
ObjCLanguage::MethodName or you didn't. No more checking if it's valid to know 
if you can use it or not.
- ObjCLanguage::MethodName is now immutable. You cannot change its internals 
once it is created.
- ObjCLanguage::MethodName::GetFullNameWithoutCategory previously had a 
parameter that let you get back an empty string if the method had no category. 
Every caller of this method was enabling this behavior so I dropped the 
parameter and made it the default behavior.
- No longer store all the various components of the method name as 
ConstStrings. The relevant `Get` methods now return llvm::StringRefs backed by 
the MethodName's internal storage. The lifetime of these StringRefs are tied to 
the MethodName itself, so if you need to persist these you need to create 
copies.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149914

Files:
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
  lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
  lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp

Index: lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
===
--- lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
+++ lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
@@ -42,53 +42,51 @@
 
   // First, be strict
   for (const auto  : strict_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ true);
-EXPECT_TRUE(method.IsValid(/*strict = */ true));
-EXPECT_EQ(
-test.full_name_sans_category,
-method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
-.GetStringRef());
-EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ true);
+EXPECT_TRUE(method.has_value());
+EXPECT_EQ(test.full_name_sans_category,
+  method->GetFullNameWithoutCategory());
+EXPECT_EQ(test.class_name, method->GetClassName());
 EXPECT_EQ(test.class_name_with_category,
-  method.GetClassNameWithCategory().GetStringRef());
-EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
-EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  method->GetClassNameWithCategory());
+EXPECT_EQ(test.category, method->GetCategory());
+EXPECT_EQ(test.selector, method->GetSelector());
   }
 
   // We should make sure strict parsing does not accept lax cases
   for (const auto  : lax_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ true);
-EXPECT_FALSE(method.IsValid(/*strict = */ true));
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ true);
+EXPECT_FALSE(method.has_value());
   }
 
   // All strict cases should work when not lax
   for (const auto  : strict_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ false);
-EXPECT_TRUE(method.IsValid(/*strict = */ false));
-EXPECT_EQ(
-test.full_name_sans_category,
-method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
-.GetStringRef());
-EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+std::optional method =
+ObjCLanguage::MethodName::Create(test.input, /*strict = */ false);
+EXPECT_TRUE(method.has_value());
+EXPECT_EQ(test.full_name_sans_category,
+  method->GetFullNameWithoutCategory());
+EXPECT_EQ(test.class_name, method->GetClassName());
 EXPECT_EQ(test.class_name_with_category,
-  method.GetClassNameWithCategory().GetStringRef());
-EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
-EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  method->GetClassNameWithCategory());
+EXPECT_EQ(test.category, method->GetCategory());
+EXPECT_EQ(test.selector, method->GetSelector());
   }
 
   // Make sure non-strict parsing works
   for (const auto  : lax_cases) {
-ObjCLanguage::MethodName method(test.input, /*strict = */ false);
-EXPECT_TRUE(method.IsValid(/*strict = */ false));
-EXPECT_EQ(
-test.full_name_sans_category,
-method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
-

[Lldb-commits] [PATCH] D149804: [lldb][NFCI] Add unittests for ObjCLanguage::MethodName

2023-05-04 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdc39d98c3faa: [lldb][NFCI] Add unittests for 
ObjCLanguage::MethodName (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149804

Files:
  lldb/unittests/Language/CMakeLists.txt
  lldb/unittests/Language/ObjC/CMakeLists.txt
  lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp

Index: lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
===
--- /dev/null
+++ lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
@@ -0,0 +1,114 @@
+//===-- ObjCLanguageTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Plugins/Language/ObjC/ObjCLanguage.h"
+#include "lldb/lldb-enumerations.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+#include "llvm/ADT/StringRef.h"
+
+using namespace lldb_private;
+
+TEST(ObjCLanguage, MethodNameParsing) {
+  struct TestCase {
+llvm::StringRef input;
+llvm::StringRef full_name_sans_category;
+llvm::StringRef class_name;
+llvm::StringRef class_name_with_category;
+llvm::StringRef category;
+llvm::StringRef selector;
+  };
+
+  TestCase strict_cases[] = {
+  {"-[MyClass mySelector:]", "", "MyClass", "MyClass", "", "mySelector:"},
+  {"+[MyClass mySelector:]", "", "MyClass", "MyClass", "", "mySelector:"},
+  {"-[MyClass(my_category) mySelector:]", "-[MyClass mySelector:]",
+   "MyClass", "MyClass(my_category)", "my_category", "mySelector:"},
+  {"+[MyClass(my_category) mySelector:]", "+[MyClass mySelector:]",
+   "MyClass", "MyClass(my_category)", "my_category", "mySelector:"},
+  };
+
+  TestCase lax_cases[] = {
+  {"[MyClass mySelector:]", "", "MyClass", "MyClass", "", "mySelector:"},
+  {"[MyClass(my_category) mySelector:]", "[MyClass mySelector:]", "MyClass",
+   "MyClass(my_category)", "my_category", "mySelector:"},
+  };
+
+  // First, be strict
+  for (const auto  : strict_cases) {
+ObjCLanguage::MethodName method(test.input, /*strict = */ true);
+EXPECT_TRUE(method.IsValid(/*strict = */ true));
+EXPECT_EQ(
+test.full_name_sans_category,
+method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
+.GetStringRef());
+EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+EXPECT_EQ(test.class_name_with_category,
+  method.GetClassNameWithCategory().GetStringRef());
+EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
+EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  }
+
+  // We should make sure strict parsing does not accept lax cases
+  for (const auto  : lax_cases) {
+ObjCLanguage::MethodName method(test.input, /*strict = */ true);
+EXPECT_FALSE(method.IsValid(/*strict = */ true));
+  }
+
+  // All strict cases should work when not lax
+  for (const auto  : strict_cases) {
+ObjCLanguage::MethodName method(test.input, /*strict = */ false);
+EXPECT_TRUE(method.IsValid(/*strict = */ false));
+EXPECT_EQ(
+test.full_name_sans_category,
+method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
+.GetStringRef());
+EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+EXPECT_EQ(test.class_name_with_category,
+  method.GetClassNameWithCategory().GetStringRef());
+EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
+EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  }
+
+  // Make sure non-strict parsing works
+  for (const auto  : lax_cases) {
+ObjCLanguage::MethodName method(test.input, /*strict = */ false);
+EXPECT_TRUE(method.IsValid(/*strict = */ false));
+EXPECT_EQ(
+test.full_name_sans_category,
+method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
+.GetStringRef());
+EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+EXPECT_EQ(test.class_name_with_category,
+  method.GetClassNameWithCategory().GetStringRef());
+EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
+EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  }
+}
+
+TEST(CPlusPlusLanguage, InvalidMethodNameParsing) {
+  // Tests that we correctly reject malformed function names
+
+  llvm::StringRef test_cases[] = {"+[Uh oh!",
+  "-[Definitely not...",
+  "[Nice try ] :)",
+  "+MaybeIfYouSquintYourEyes]",
+ 

[Lldb-commits] [PATCH] D149900: [lldb] Expose a const iterator for SymbolContextList

2023-05-04 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, jingham, mib, aprantl.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: lldb-commits, jplehr, sstefan1.
Herald added a project: LLDB.

There are many situations where we'll iterate over a SymbolContextList
with the pattern:

  SymbolContextList sc_list;
  // Fill in sc_list here
  for (auto i = 0; i < sc_list.GetSize(); i++) {
SymbolContext sc;
sc_list.GetSymbolAtContext(i, sc);
  
// Do work with sc
  }

Adding an iterator to iterate over the instances directly means we don't
have to do bounds checking or create a copy of every element of the
SymbolContextList.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149900

Files:
  lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
  lldb/include/lldb/Symbol/SymbolContext.h
  lldb/include/lldb/Symbol/UnwindTable.h
  lldb/source/API/SBThread.cpp
  lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
  lldb/source/Breakpoint/BreakpointResolverName.cpp
  lldb/source/Commands/CommandCompletions.cpp
  lldb/source/Commands/CommandObjectSource.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Core/AddressResolverFileLine.cpp
  lldb/source/Core/SourceManager.cpp
  lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Symbol/Symbol.cpp
  lldb/source/Symbol/SymbolContext.cpp
  lldb/source/Symbol/UnwindTable.cpp

Index: lldb/source/Symbol/UnwindTable.cpp
===
--- lldb/source/Symbol/UnwindTable.cpp
+++ lldb/source/Symbol/UnwindTable.cpp
@@ -86,8 +86,8 @@
 
 UnwindTable::~UnwindTable() = default;
 
-std::optional UnwindTable::GetAddressRange(const Address ,
- SymbolContext ) {
+std::optional
+UnwindTable::GetAddressRange(const Address , const SymbolContext ) {
   AddressRange range;
 
   // First check the unwind info from the object file plugin
@@ -150,9 +150,8 @@
 // don't add it to the UnwindTable.  This is intended for use by target modules
 // show-unwind where we want to create new UnwindPlans, not re-use existing
 // ones.
-FuncUnwindersSP
-UnwindTable::GetUncachedFuncUnwindersContainingAddress(const Address ,
-   SymbolContext ) {
+FuncUnwindersSP UnwindTable::GetUncachedFuncUnwindersContainingAddress(
+const Address , const SymbolContext ) {
   Initialize();
 
   auto range_or = GetAddressRange(addr, sc);
Index: lldb/source/Symbol/SymbolContext.cpp
===
--- lldb/source/Symbol/SymbolContext.cpp
+++ lldb/source/Symbol/SymbolContext.cpp
@@ -771,14 +771,11 @@
   Module *module = module_sp.get();
 
   auto ProcessMatches = [this, , ,
- module](SymbolContextList _list,
+ module](const SymbolContextList _list,
  Status ) -> const Symbol * {
 llvm::SmallVector external_symbols;
 llvm::SmallVector internal_symbols;
-const uint32_t matches = sc_list.GetSize();
-for (uint32_t i = 0; i < matches; ++i) {
-  SymbolContext sym_ctx;
-  sc_list.GetContextAtIndex(i, sym_ctx);
+for (const auto _ctx : sc_list) {
   if (sym_ctx.symbol) {
 const Symbol *symbol = sym_ctx.symbol;
 const Address sym_address = symbol->GetAddress();
Index: lldb/source/Symbol/Symbol.cpp
===
--- lldb/source/Symbol/Symbol.cpp
+++ lldb/source/Symbol/Symbol.cpp
@@ -488,15 +488,9 @@
 lldb_private::SymbolContextList sc_list;
 module_sp->FindSymbolsWithNameAndType(reexport_name, eSymbolTypeAny,
   sc_list);
-const size_t num_scs = sc_list.GetSize();
-if (num_scs > 0) {
-  for (size_t i = 0; i < num_scs; ++i) {
-lldb_private::SymbolContext sc;
-if (sc_list.GetContextAtIndex(i, sc)) {
-  if (sc.symbol->IsExternal())
-return sc.symbol;
-}
-  }
+for (const auto  : sc_list) {
+  if (sc.symbol->IsExternal())
+return sc.symbol;
 }
 // If we didn't find the symbol in this module, it may be because this
 // module re-exports some whole other library.  We have to search those as
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- 

[Lldb-commits] [PATCH] D149717: [lldb] Make some functions useful to REPLs public

2023-05-04 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149717

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


[Lldb-commits] [PATCH] D149719: [LLDB] Add a hook to notify REPLs that an expression was evaluated

2023-05-04 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/include/lldb/Expression/REPL.h:124
+const lldb::ValueObjectSP _valobj_sp,
+const Status ) {
+return llvm::Error::success();

Do you still need the `Status` parameter?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149719

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


[Lldb-commits] [PATCH] D149803: Use the `addressing_bits` kv in the stop packet from the remote stub, if present

2023-05-03 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

Makes sense to me!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149803

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


[Lldb-commits] [PATCH] D149804: [lldb][NFCI] Add unittests for ObjCLanguage::MethodName

2023-05-03 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, mib, Michael137, jingham.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

I have a patch to refactor this class and I'd like a unittest in place
to make sure I don't break anything.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149804

Files:
  lldb/unittests/Language/CMakeLists.txt
  lldb/unittests/Language/ObjC/CMakeLists.txt
  lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp

Index: lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
===
--- /dev/null
+++ lldb/unittests/Language/ObjC/ObjCLanguageTest.cpp
@@ -0,0 +1,114 @@
+//===-- ObjCLanguageTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Plugins/Language/ObjC/ObjCLanguage.h"
+#include "lldb/lldb-enumerations.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+#include "llvm/ADT/StringRef.h"
+
+using namespace lldb_private;
+
+TEST(ObjCLanguage, MethodNameParsing) {
+  struct TestCase {
+llvm::StringRef input;
+llvm::StringRef full_name_sans_category;
+llvm::StringRef class_name;
+llvm::StringRef class_name_with_category;
+llvm::StringRef category;
+llvm::StringRef selector;
+  };
+
+  TestCase strict_cases[] = {
+  {"-[MyClass mySelector:]", "", "MyClass", "MyClass", "", "mySelector:"},
+  {"+[MyClass mySelector:]", "", "MyClass", "MyClass", "", "mySelector:"},
+  {"-[MyClass(my_category) mySelector:]", "-[MyClass mySelector:]",
+   "MyClass", "MyClass(my_category)", "my_category", "mySelector:"},
+  {"+[MyClass(my_category) mySelector:]", "+[MyClass mySelector:]",
+   "MyClass", "MyClass(my_category)", "my_category", "mySelector:"},
+  };
+
+  TestCase lax_cases[] = {
+  {"[MyClass mySelector:]", "", "MyClass", "MyClass", "", "mySelector:"},
+  {"[MyClass(my_category) mySelector:]", "[MyClass mySelector:]", "MyClass",
+   "MyClass(my_category)", "my_category", "mySelector:"},
+  };
+
+  // First, be strict
+  for (const auto  : strict_cases) {
+ObjCLanguage::MethodName method(test.input, /*strict = */ true);
+EXPECT_TRUE(method.IsValid(/*strict = */ true));
+EXPECT_EQ(
+test.full_name_sans_category,
+method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
+.GetStringRef());
+EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+EXPECT_EQ(test.class_name_with_category,
+  method.GetClassNameWithCategory().GetStringRef());
+EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
+EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  }
+
+  // We should make sure strict parsing does not accept lax cases
+  for (const auto  : lax_cases) {
+ObjCLanguage::MethodName method(test.input, /*strict = */ true);
+EXPECT_FALSE(method.IsValid(/*strict = */ true));
+  }
+
+  // All strict cases should work when not lax
+  for (const auto  : strict_cases) {
+ObjCLanguage::MethodName method(test.input, /*strict = */ false);
+EXPECT_TRUE(method.IsValid(/*strict = */ false));
+EXPECT_EQ(
+test.full_name_sans_category,
+method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
+.GetStringRef());
+EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+EXPECT_EQ(test.class_name_with_category,
+  method.GetClassNameWithCategory().GetStringRef());
+EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
+EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  }
+
+  // Make sure non-strict parsing works
+  for (const auto  : lax_cases) {
+ObjCLanguage::MethodName method(test.input, /*strict = */ false);
+EXPECT_TRUE(method.IsValid(/*strict = */ false));
+EXPECT_EQ(
+test.full_name_sans_category,
+method.GetFullNameWithoutCategory(/*empty_if_no_category = */ true)
+.GetStringRef());
+EXPECT_EQ(test.class_name, method.GetClassName().GetStringRef());
+EXPECT_EQ(test.class_name_with_category,
+  method.GetClassNameWithCategory().GetStringRef());
+EXPECT_EQ(test.category, method.GetCategory().GetStringRef());
+EXPECT_EQ(test.selector, method.GetSelector().GetStringRef());
+  }
+}
+
+TEST(CPlusPlusLanguage, InvalidMethodNameParsing) {
+  // Tests that we correctly reject malformed function names
+
+  llvm::StringRef test_cases[] = {"+[Uh oh!",
+  "-[Definitely not...",
+  "[Nice try ] :)",

[Lldb-commits] [PATCH] D149774: [lldb] Use templates to simplify {Get, Set}PropertyAtIndex (NFC)

2023-05-03 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

I quite like the idea. Probably want to wait for others to look over it but I 
think it's good!




Comment at: lldb/source/Core/Debugger.cpp:394
   const uint32_t idx = ePropertyUseColor;
-  bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(idx, b);
+  // bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(idx, b);
+  bool ret = SetPropertyAtIndex(idx, b);

remove commented out line.


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

https://reviews.llvm.org/D149774

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


[Lldb-commits] [PATCH] D149697: [lldb] Remove distribution_id from ArchSpec

2023-05-03 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd05ffdbb2c3: [lldb] Remove distribution_id from ArchSpec 
(authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149697

Files:
  lldb/include/lldb/Host/HostInfoBase.h
  lldb/include/lldb/Utility/ArchSpec.h
  lldb/source/Host/linux/HostInfoLinux.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Utility/ArchSpec.cpp

Index: lldb/source/Utility/ArchSpec.cpp
===
--- lldb/source/Utility/ArchSpec.cpp
+++ lldb/source/Utility/ArchSpec.cpp
@@ -543,7 +543,6 @@
   m_triple = llvm::Triple();
   m_core = kCore_invalid;
   m_byte_order = eByteOrderInvalid;
-  m_distribution_id.Clear();
   m_flags = 0;
 }
 
@@ -689,14 +688,6 @@
   return llvm::Triple::UnknownArch;
 }
 
-ConstString ArchSpec::GetDistributionId() const {
-  return m_distribution_id;
-}
-
-void ArchSpec::SetDistributionId(const char *distribution_id) {
-  m_distribution_id.SetCString(distribution_id);
-}
-
 uint32_t ArchSpec::GetAddressByteSize() const {
   const CoreDefinition *core_def = FindCoreDefinition(m_core);
   if (core_def) {
@@ -979,8 +970,6 @@
 }
 
 bool ArchSpec::IsMatch(const ArchSpec , MatchType match) const {
-  // explicitly ignoring m_distribution_id in this method.
-
   if (GetByteOrder() != rhs.GetByteOrder() ||
   !cores_match(GetCore(), rhs.GetCore(), true, match == ExactMatch))
 return false;
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -187,8 +187,8 @@
   response.PutStringAsRawHex8(host_triple.getTriple());
   response.Printf(";ptrsize:%u;", host_arch.GetAddressByteSize());
 
-  const char *distribution_id = host_arch.GetDistributionId().AsCString();
-  if (distribution_id) {
+  llvm::StringRef distribution_id = HostInfo::GetDistributionId();
+  if (!distribution_id.empty()) {
 response.PutCString("distribution_id:");
 response.PutStringAsRawHex8(distribution_id);
 response.PutCString(";");
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -583,6 +583,7 @@
   uint32_t m_addressing_bits = 0;
 
   ArchSpec m_host_arch;
+  std::string m_host_distribution_id;
   ArchSpec m_process_arch;
   UUID m_process_standalone_uuid;
   lldb::addr_t m_process_standalone_value = LLDB_INVALID_ADDRESS;
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -69,10 +69,10 @@
   m_supports_vFileSize(true), m_supports_vFileMode(true),
   m_supports_vFileExists(true), m_supports_vRun(true),
 
-  m_host_arch(), m_process_arch(), m_os_build(), m_os_kernel(),
-  m_hostname(), m_gdb_server_name(), m_default_packet_timeout(0),
-  m_qSupported_response(), m_supported_async_json_packets_sp(),
-  m_qXfer_memory_map() {}
+  m_host_arch(), m_host_distribution_id(), m_process_arch(), m_os_build(),
+  m_os_kernel(), m_hostname(), m_gdb_server_name(),
+  m_default_packet_timeout(0), m_qSupported_response(),
+  m_supported_async_json_packets_sp(), m_qXfer_memory_map() {}
 
 // Destructor
 GDBRemoteCommunicationClient::~GDBRemoteCommunicationClient() {
@@ -307,6 +307,7 @@
 m_qSymbol_requests_done = false;
 m_supports_qModuleInfo = true;
 m_host_arch.Clear();
+m_host_distribution_id.clear();
 m_os_version = llvm::VersionTuple();
 m_os_build.clear();
 m_os_kernel.clear();
@@ -1206,7 +1207,6 @@
 std::string environment;
 std::string vendor_name;
 std::string triple;
-std::string distribution_id;
 uint32_t pointer_byte_size = 0;
 ByteOrder byte_order = eByteOrderInvalid;
 uint32_t num_keys_decoded = 0;
@@ -1228,7 +1228,7 @@
 ++num_keys_decoded;
   } else if (name.equals("distribution_id")) {
 StringExtractor extractor(value);
-extractor.GetHexByteString(distribution_id);
+extractor.GetHexByteString(m_host_distribution_id);
 ++num_keys_decoded;
   } else if 

[Lldb-commits] [PATCH] D149719: [LLDB] Add a hook to notify REPLs that an expression was evaluated

2023-05-03 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/include/lldb/Expression/REPL.h:115-120
+  virtual void
+  OnExpressionEvaluated(const ExecutionContext _ctx, llvm::StringRef code,
+const EvaluateExpressionOptions _options,
+lldb::ExpressionResults execution_results,
+const lldb::ValueObjectSP _valobj_sp,
+const Status ) {}

Why not return a `Status` object instead of having the return type be `void`? 
Or instead of `Status` you could use `llvm::Error` so we are forced to check it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149719

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


[Lldb-commits] [PATCH] D149717: [lldb] Make some functions useful to REPLs public

2023-05-03 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a reviewer: JDevlieghere.
bulbazord added inline comments.



Comment at: lldb/include/lldb/Core/Debugger.h:503-504
 
+  /// Manually start the global event handler thread. It should be used by
+  /// programs that use LLDB as a library.
+  bool StartEventHandlerThread();

There are program that use LLDB as a library but go through the SBAPI instead 
of lldb_private. Could you update this comment to be more specific about the 
intentions here? I assume you mean things like plugins.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149717

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


[Lldb-commits] [PATCH] D149663: [lldb] Remove FileSpec::GetLastPathComponent

2023-05-02 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4f3f5225df7: [lldb] Remove FileSpec::GetLastPathComponent 
(authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149663

Files:
  lldb/include/lldb/Utility/FileSpec.h
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Utility/FileSpec.cpp
  lldb/source/Utility/XcodeSDK.cpp

Index: lldb/source/Utility/XcodeSDK.cpp
===
--- lldb/source/Utility/XcodeSDK.cpp
+++ lldb/source/Utility/XcodeSDK.cpp
@@ -242,7 +242,7 @@
 
 bool XcodeSDK::SDKSupportsModules(XcodeSDK::Type desired_type,
   const FileSpec _path) {
-  ConstString last_path_component = sdk_path.GetLastPathComponent();
+  ConstString last_path_component = sdk_path.GetFilename();
 
   if (!last_path_component)
 return false;
Index: lldb/source/Utility/FileSpec.cpp
===
--- lldb/source/Utility/FileSpec.cpp
+++ lldb/source/Utility/FileSpec.cpp
@@ -429,12 +429,6 @@
   return *this;
 }
 
-ConstString FileSpec::GetLastPathComponent() const {
-  llvm::SmallString<64> current_path;
-  GetPath(current_path, false);
-  return ConstString(llvm::sys::path::filename(current_path, m_style));
-}
-
 void FileSpec::PrependPathComponent(llvm::StringRef component) {
   llvm::SmallString<64> new_path(component);
   llvm::SmallString<64> current_path;
Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -435,7 +435,7 @@
 // make the new directory and get in there
 FileSpec dst_dir = rc_baton->dst;
 if (!dst_dir.GetFilename())
-  dst_dir.SetFilename(src.GetLastPathComponent());
+  dst_dir.SetFilename(src.GetFilename());
 Status error = rc_baton->platform_ptr->MakeDirectory(
 dst_dir, lldb::eFilePermissionsDirectoryDefault);
 if (error.Fail()) {
Index: lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
===
--- lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
+++ lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
@@ -1268,7 +1268,7 @@
 
 auto _spec = module_sp->GetFileSpec();
 found_logging_support_module =
-(file_spec.GetLastPathComponent() == logging_module_name);
+(file_spec.GetFilename() == logging_module_name);
 if (found_logging_support_module)
   break;
   }
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1238,10 +1238,9 @@
 
 FileSpec platform_pull_upart(platform_file);
 std::vector path_parts;
-path_parts.push_back(
-platform_pull_upart.GetLastPathComponent().AsCString());
+path_parts.push_back(platform_pull_upart.GetFilename().AsCString());
 while (platform_pull_upart.RemoveLastPathComponent()) {
-  ConstString part = platform_pull_upart.GetLastPathComponent();
+  ConstString part = platform_pull_upart.GetFilename();
   path_parts.push_back(part.AsCString());
 }
 const size_t path_parts_size = path_parts.size();
Index: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
===
--- lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -166,7 +166,7 @@
 auto raw_data = coff_obj.getData();
 LLDB_SCOPED_TIMERF(
 "Calculating module crc32 %s with size %" PRIu64 " KiB",
-FileSpec(coff_obj.getFileName()).GetLastPathComponent().AsCString(),
+FileSpec(coff_obj.getFileName()).GetFilename().AsCString(),
 static_cast(raw_data.size()) / 1024);
 gnu_debuglink_crc = llvm::crc32(0, llvm::arrayRefFromStringRef(raw_data));
   }
@@ -295,7 +295,7 @@
   const auto *map = GetGlobalPluginProperties().ModuleABIMap();
   if (map->GetNumValues() > 0) {
 // Step 1: Try with the exact file name.
-auto name = file.GetLastPathComponent();
+auto name = file.GetFilename();
 module_env_option = map->GetValueForKey(name);
 if (!module_env_option) {
   // Step 2: Try with the file name in lowercase.
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- 

[Lldb-commits] [PATCH] D149671: [lldb] Minor cleanups at callsites of FileSpec::GetFileNameExtension

2023-05-02 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG50e79d725c10: [lldb] Minor cleanups at callsites of 
FileSpec::GetFileNameExtension (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149671

Files:
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp


Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
@@ -131,14 +131,13 @@
 }
 
 llvm::Error Lua::LoadModule(llvm::StringRef filename) {
-  FileSpec file(filename);
+  const FileSpec file(filename);
   if (!FileSystem::Instance().Exists(file)) {
 return llvm::make_error("invalid path",
llvm::inconvertibleErrorCode());
   }
 
-  llvm::StringRef module_extension = file.GetFileNameExtension();
-  if (module_extension != ".lua") {
+  if (file.GetFileNameExtension() != ".lua") {
 return llvm::make_error("invalid extension",
llvm::inconvertibleErrorCode());
   }
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
===
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
@@ -137,7 +137,8 @@
   // with the binary inside it ('.../foo.dSYM/Contents/Resources/DWARF/foo').
   // A dSYM bundle may have multiple DWARF binaries in them, so a vector
   // of matches is returned.
-  static std::vector GetDWARFBinaryInDSYMBundle(FileSpec 
dsym_bundle);
+  static std::vector
+  GetDWARFBinaryInDSYMBundle(const FileSpec _bundle);
 
   Status GetSharedModuleKext(const ModuleSpec _spec, Process *process,
  lldb::ModuleSP _sp,
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
===
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
@@ -421,7 +421,7 @@
   static constexpr llvm::StringLiteral g_kdk_suffix = ".kdk";
 
   PlatformDarwinKernel *thisp = (PlatformDarwinKernel *)baton;
-  FileSpec file_spec(path);
+  const FileSpec file_spec(path);
   if (ft == llvm::sys::fs::file_type::directory_file &&
   (file_spec.GetFileNameExtension() == g_sdk_suffix ||
file_spec.GetFileNameExtension() == g_kdk_suffix)) {
@@ -482,7 +482,7 @@
   static constexpr llvm::StringLiteral g_kext_suffix = ".kext";
   static constexpr llvm::StringLiteral g_dsym_suffix = ".dSYM";
 
-  FileSpec file_spec(path);
+  const FileSpec file_spec(path);
   llvm::StringRef file_spec_extension = file_spec.GetFileNameExtension();
 
   Log *log = GetLog(LLDBLog::Platform);
@@ -691,7 +691,7 @@
 // it should iterate over every binary in the DWARF subdir
 // and return them all.
 std::vector
-PlatformDarwinKernel::GetDWARFBinaryInDSYMBundle(FileSpec dsym_bundle) {
+PlatformDarwinKernel::GetDWARFBinaryInDSYMBundle(const FileSpec _bundle) {
   std::vector results;
   static constexpr llvm::StringLiteral g_dsym_suffix = ".dSYM";
   if (dsym_bundle.GetFileNameExtension() != g_dsym_suffix) {
Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -2161,7 +2161,7 @@
 }
 
 const char *pcm_path = command.GetArgumentAtIndex(0);
-FileSpec pcm_file{pcm_path};
+const FileSpec pcm_file{pcm_path};
 
 if (pcm_file.GetFileNameExtension() != ".pcm") {
   result.AppendError("file must have a .pcm extension");


Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
@@ -131,14 +131,13 @@
 }
 
 llvm::Error Lua::LoadModule(llvm::StringRef filename) {
-  FileSpec file(filename);
+  const FileSpec file(filename);
   if (!FileSystem::Instance().Exists(file)) {
 return llvm::make_error("invalid path",
llvm::inconvertibleErrorCode());
   }
 
-  llvm::StringRef module_extension = file.GetFileNameExtension();
-  if (module_extension != ".lua") {
+  if (file.GetFileNameExtension() != ".lua") {
 return llvm::make_error("invalid extension",
llvm::inconvertibleErrorCode());
   }
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h

[Lldb-commits] [PATCH] D149702: [DebugInfo] Add language code for the new Mojo language

2023-05-02 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/include/lldb/lldb-enumerations.h:493
   eLanguageTypeAda2012 = 0x002f,
+  eLanguageTypeMojo = 0x0030,
 

These values correspond to DWARF5's official language codes and `0x0030` is 
technically already taken. LLDB just hasn't been updated yet. I don't think 
this should necessarily block this patch but this value will need to be changed 
at some point.

See: https://dwarfstd.org/languages.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149702

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


[Lldb-commits] [PATCH] D149096: [lldb] Speed up looking for dSYM next to executable

2023-05-02 Thread Alex Langford via Phabricator via lldb-commits
bulbazord abandoned this revision.
bulbazord added a comment.

I'm going to see how we could potentially improve FileSpec's performance rather 
than go with this approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149096

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


[Lldb-commits] [PATCH] D149697: [lldb] Remove distribution_id from ArchSpec

2023-05-02 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: jasonmolenda, labath, DavidSpickett.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The qHostInfo packet in the gdb-remote communication protocol specifies
that distribution_id can be set, so lldb handles that. But we store that
in the ArchSpec representing the "Host" platform (whatever platform the
debug server is running on). This field is otherwise unused in ArchSpec,
so it would be a lot easier if we stored that information at the
gdb-remote communication layer.

Sidenote: The distribution_id field is currently unused but I did not
want to remove it in case some folks found it useful (e.g. in downstream
forks).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149697

Files:
  lldb/include/lldb/Host/HostInfoBase.h
  lldb/include/lldb/Utility/ArchSpec.h
  lldb/source/Host/linux/HostInfoLinux.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Utility/ArchSpec.cpp

Index: lldb/source/Utility/ArchSpec.cpp
===
--- lldb/source/Utility/ArchSpec.cpp
+++ lldb/source/Utility/ArchSpec.cpp
@@ -543,7 +543,6 @@
   m_triple = llvm::Triple();
   m_core = kCore_invalid;
   m_byte_order = eByteOrderInvalid;
-  m_distribution_id.Clear();
   m_flags = 0;
 }
 
@@ -689,14 +688,6 @@
   return llvm::Triple::UnknownArch;
 }
 
-ConstString ArchSpec::GetDistributionId() const {
-  return m_distribution_id;
-}
-
-void ArchSpec::SetDistributionId(const char *distribution_id) {
-  m_distribution_id.SetCString(distribution_id);
-}
-
 uint32_t ArchSpec::GetAddressByteSize() const {
   const CoreDefinition *core_def = FindCoreDefinition(m_core);
   if (core_def) {
@@ -979,8 +970,6 @@
 }
 
 bool ArchSpec::IsMatch(const ArchSpec , MatchType match) const {
-  // explicitly ignoring m_distribution_id in this method.
-
   if (GetByteOrder() != rhs.GetByteOrder() ||
   !cores_match(GetCore(), rhs.GetCore(), true, match == ExactMatch))
 return false;
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -187,8 +187,8 @@
   response.PutStringAsRawHex8(host_triple.getTriple());
   response.Printf(";ptrsize:%u;", host_arch.GetAddressByteSize());
 
-  const char *distribution_id = host_arch.GetDistributionId().AsCString();
-  if (distribution_id) {
+  llvm::StringRef distribution_id = HostInfo::GetDistributionId();
+  if (!distribution_id.empty()) {
 response.PutCString("distribution_id:");
 response.PutStringAsRawHex8(distribution_id);
 response.PutCString(";");
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -583,6 +583,7 @@
   uint32_t m_addressing_bits = 0;
 
   ArchSpec m_host_arch;
+  std::string m_host_distribution_id;
   ArchSpec m_process_arch;
   UUID m_process_standalone_uuid;
   lldb::addr_t m_process_standalone_value = LLDB_INVALID_ADDRESS;
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -69,10 +69,10 @@
   m_supports_vFileSize(true), m_supports_vFileMode(true),
   m_supports_vFileExists(true), m_supports_vRun(true),
 
-  m_host_arch(), m_process_arch(), m_os_build(), m_os_kernel(),
-  m_hostname(), m_gdb_server_name(), m_default_packet_timeout(0),
-  m_qSupported_response(), m_supported_async_json_packets_sp(),
-  m_qXfer_memory_map() {}
+  m_host_arch(), m_host_distribution_id(), m_process_arch(), m_os_build(),
+  m_os_kernel(), m_hostname(), m_gdb_server_name(),
+  m_default_packet_timeout(0), m_qSupported_response(),
+  m_supported_async_json_packets_sp(), m_qXfer_memory_map() {}
 
 // Destructor
 GDBRemoteCommunicationClient::~GDBRemoteCommunicationClient() {
@@ -307,6 +307,7 @@
 m_qSymbol_requests_done = false;
 m_supports_qModuleInfo = true;
 m_host_arch.Clear();
+m_host_distribution_id.clear();
 m_os_version = llvm::VersionTuple();
 m_os_build.clear();
 m_os_kernel.clear();
@@ -1206,7 +1207,6 @@
 std::string environment;
 std::string 

<    1   2   3   4   5   6   7   8   9   10   >