[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread David Spickett via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.
+
+There are example commands in the lldb testsuite at:
+
+llvm-project/lldb/test/API/commands/command/script/add/test_commands.py
+"""
+import inspect
+import lldb
+import sys
+from abc import abstractmethod
+
+class LLDBOVParser:
+def __init__(self):
+# This is a dictionary of dictionaries.  The key is the long option
+# name, and the value is the rest of the definition.
+self.options_dict = {}
+self.args_array = []
+
+# Some methods to translate common value types.  Should return a
+# tuple of the value and an error value (True => error) if the
+# type can't be converted.
+# FIXME: Need a way to push the conversion error string back to lldb.
+@staticmethod
+def to_bool(in_value):
+error = True
+value = False
+if type(in_value) != str or len(in_value) == 0:
+return (value, error)
+
+low_in = in_value.lower()
+if low_in == "y" or low_in == "yes" or low_in == "t" or low_in == 
"true" or low_in == "1":
+value = True
+error = False
+
+if not value and low_in == "n" or low_in == "no" or low_in == "f" or 
low_in == "false" or low_in == "0":
+value = False
+error = False
+
+return (value, error)
+
+@staticmethod
+def to_int(in_value):
+#FIXME: Not doing errors yet...
+return (int(in_value), False)
+
+@staticmethod
+def to_unsigned(in_value):
+# FIXME: find an unsigned converter...
+# And handle errors.
+return (int(in_value), False)
+
+translators = {
+lldb.eArgTypeBoolean : to_bool,
+lldb.eArgTypeBreakpointID : to_unsigned,
+lldb.eArgTypeByteSize : to_unsigned,
+lldb.eArgTypeCount : to_unsigned,
+lldb.eArgTypeFrameIndex : to_unsigned,
+lldb.eArgTypeIndex : to_unsigned,
+lldb.eArgTypeLineNum : to_unsigned,
+lldb.eArgTypeNumLines : to_unsigned,
+lldb.eArgTypeNumberPerLine : to_unsigned,
+lldb.eArgTypeOffset : to_int,
+lldb.eArgTypeThreadIndex : to_unsigned,
+lldb.eArgTypeUnsignedInteger : to_unsigned,
+lldb.eArgTypeWatchpointID : to_unsigned,
+lldb.eArgTypeColumnNum : to_unsigned,
+lldb.eArgTypeRecognizerID : to_unsigned,
+lldb.eArgTypeTargetID : to_unsigned,
+lldb.eArgTypeStopHookID : to_unsigned
+}
+
+@classmethod
+def translate_value(cls, value_type, value):
+try:
+return cls.translators[value_type](value)
+except KeyError:
+# If we don't have a translator, return the string value.
+return (value, False)
+
+# FIXME: would this be better done on the C++ side?
+# The common completers are missing some useful ones.
+# For instance there really should be a common Type completer
+# And an "lldb command name" completer.
+completion_table = {
+lldb.eArgTypeAddressOrExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeArchitecture : lldb.eArchitectureCompletion,
+lldb.eArgTypeBreakpointID : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointIDRange : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointName : lldb.eBreakpointNameCompletion,
+lldb.eArgTypeClassName : lldb.eSymbolCompletion,
+lldb.eArgTypeDirectoryName : lldb.eDiskDirectoryCompletion,
+lldb.eArgTypeExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeExpressionPath : lldb.eVariablePathCompletion,
+lldb.eArgTypeFilename : lldb.eDiskFileCompletion,
+lldb.eArgTypeFrameIndex : lldb.eFrameIndex

[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread David Spickett via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.
+
+There are example commands in the lldb testsuite at:
+
+llvm-project/lldb/test/API/commands/command/script/add/test_commands.py
+"""
+import inspect
+import lldb
+import sys
+from abc import abstractmethod
+
+class LLDBOVParser:
+def __init__(self):
+# This is a dictionary of dictionaries.  The key is the long option
+# name, and the value is the rest of the definition.
+self.options_dict = {}
+self.args_array = []
+
+# Some methods to translate common value types.  Should return a
+# tuple of the value and an error value (True => error) if the
+# type can't be converted.
+# FIXME: Need a way to push the conversion error string back to lldb.
+@staticmethod
+def to_bool(in_value):
+error = True
+value = False
+if type(in_value) != str or len(in_value) == 0:
+return (value, error)
+
+low_in = in_value.lower()
+if low_in == "y" or low_in == "yes" or low_in == "t" or low_in == 
"true" or low_in == "1":
+value = True
+error = False
+
+if not value and low_in == "n" or low_in == "no" or low_in == "f" or 
low_in == "false" or low_in == "0":
+value = False
+error = False
+
+return (value, error)
+
+@staticmethod
+def to_int(in_value):
+#FIXME: Not doing errors yet...
+return (int(in_value), False)
+
+@staticmethod
+def to_unsigned(in_value):
+# FIXME: find an unsigned converter...
+# And handle errors.
+return (int(in_value), False)
+
+translators = {
+lldb.eArgTypeBoolean : to_bool,
+lldb.eArgTypeBreakpointID : to_unsigned,
+lldb.eArgTypeByteSize : to_unsigned,
+lldb.eArgTypeCount : to_unsigned,
+lldb.eArgTypeFrameIndex : to_unsigned,
+lldb.eArgTypeIndex : to_unsigned,
+lldb.eArgTypeLineNum : to_unsigned,
+lldb.eArgTypeNumLines : to_unsigned,
+lldb.eArgTypeNumberPerLine : to_unsigned,
+lldb.eArgTypeOffset : to_int,
+lldb.eArgTypeThreadIndex : to_unsigned,
+lldb.eArgTypeUnsignedInteger : to_unsigned,
+lldb.eArgTypeWatchpointID : to_unsigned,
+lldb.eArgTypeColumnNum : to_unsigned,
+lldb.eArgTypeRecognizerID : to_unsigned,
+lldb.eArgTypeTargetID : to_unsigned,
+lldb.eArgTypeStopHookID : to_unsigned
+}
+
+@classmethod
+def translate_value(cls, value_type, value):
+try:
+return cls.translators[value_type](value)
+except KeyError:
+# If we don't have a translator, return the string value.
+return (value, False)
+
+# FIXME: would this be better done on the C++ side?
+# The common completers are missing some useful ones.
+# For instance there really should be a common Type completer
+# And an "lldb command name" completer.
+completion_table = {
+lldb.eArgTypeAddressOrExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeArchitecture : lldb.eArchitectureCompletion,
+lldb.eArgTypeBreakpointID : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointIDRange : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointName : lldb.eBreakpointNameCompletion,
+lldb.eArgTypeClassName : lldb.eSymbolCompletion,
+lldb.eArgTypeDirectoryName : lldb.eDiskDirectoryCompletion,
+lldb.eArgTypeExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeExpressionPath : lldb.eVariablePathCompletion,
+lldb.eArgTypeFilename : lldb.eDiskFileCompletion,
+lldb.eArgTypeFrameIndex : lldb.eFrameIndex

[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread David Spickett via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.
+
+There are example commands in the lldb testsuite at:
+
+llvm-project/lldb/test/API/commands/command/script/add/test_commands.py
+"""
+import inspect
+import lldb
+import sys
+from abc import abstractmethod
+
+class LLDBOVParser:
+def __init__(self):
+# This is a dictionary of dictionaries.  The key is the long option
+# name, and the value is the rest of the definition.
+self.options_dict = {}
+self.args_array = []
+
+# Some methods to translate common value types.  Should return a
+# tuple of the value and an error value (True => error) if the
+# type can't be converted.
+# FIXME: Need a way to push the conversion error string back to lldb.
+@staticmethod
+def to_bool(in_value):
+error = True
+value = False
+if type(in_value) != str or len(in_value) == 0:
+return (value, error)
+
+low_in = in_value.lower()
+if low_in == "y" or low_in == "yes" or low_in == "t" or low_in == 
"true" or low_in == "1":
+value = True
+error = False
+
+if not value and low_in == "n" or low_in == "no" or low_in == "f" or 
low_in == "false" or low_in == "0":
+value = False
+error = False
+
+return (value, error)
+
+@staticmethod
+def to_int(in_value):
+#FIXME: Not doing errors yet...
+return (int(in_value), False)
+
+@staticmethod
+def to_unsigned(in_value):
+# FIXME: find an unsigned converter...
+# And handle errors.
+return (int(in_value), False)
+
+translators = {
+lldb.eArgTypeBoolean : to_bool,
+lldb.eArgTypeBreakpointID : to_unsigned,
+lldb.eArgTypeByteSize : to_unsigned,
+lldb.eArgTypeCount : to_unsigned,
+lldb.eArgTypeFrameIndex : to_unsigned,
+lldb.eArgTypeIndex : to_unsigned,
+lldb.eArgTypeLineNum : to_unsigned,
+lldb.eArgTypeNumLines : to_unsigned,
+lldb.eArgTypeNumberPerLine : to_unsigned,
+lldb.eArgTypeOffset : to_int,
+lldb.eArgTypeThreadIndex : to_unsigned,
+lldb.eArgTypeUnsignedInteger : to_unsigned,
+lldb.eArgTypeWatchpointID : to_unsigned,
+lldb.eArgTypeColumnNum : to_unsigned,
+lldb.eArgTypeRecognizerID : to_unsigned,
+lldb.eArgTypeTargetID : to_unsigned,
+lldb.eArgTypeStopHookID : to_unsigned
+}
+
+@classmethod
+def translate_value(cls, value_type, value):
+try:
+return cls.translators[value_type](value)
+except KeyError:
+# If we don't have a translator, return the string value.
+return (value, False)
+
+# FIXME: would this be better done on the C++ side?
+# The common completers are missing some useful ones.
+# For instance there really should be a common Type completer
+# And an "lldb command name" completer.
+completion_table = {
+lldb.eArgTypeAddressOrExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeArchitecture : lldb.eArchitectureCompletion,
+lldb.eArgTypeBreakpointID : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointIDRange : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointName : lldb.eBreakpointNameCompletion,
+lldb.eArgTypeClassName : lldb.eSymbolCompletion,
+lldb.eArgTypeDirectoryName : lldb.eDiskDirectoryCompletion,
+lldb.eArgTypeExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeExpressionPath : lldb.eVariablePathCompletion,
+lldb.eArgTypeFilename : lldb.eDiskFileCompletion,
+lldb.eArgTypeFrameIndex : lldb.eFrameIndex

[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread David Spickett via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.
+
+There are example commands in the lldb testsuite at:
+
+llvm-project/lldb/test/API/commands/command/script/add/test_commands.py
+"""
+import inspect
+import lldb
+import sys
+from abc import abstractmethod
+
+class LLDBOVParser:
+def __init__(self):
+# This is a dictionary of dictionaries.  The key is the long option
+# name, and the value is the rest of the definition.
+self.options_dict = {}
+self.args_array = []
+
+# Some methods to translate common value types.  Should return a
+# tuple of the value and an error value (True => error) if the
+# type can't be converted.
+# FIXME: Need a way to push the conversion error string back to lldb.
+@staticmethod
+def to_bool(in_value):
+error = True
+value = False
+if type(in_value) != str or len(in_value) == 0:
+return (value, error)
+
+low_in = in_value.lower()
+if low_in == "y" or low_in == "yes" or low_in == "t" or low_in == 
"true" or low_in == "1":
+value = True
+error = False
+
+if not value and low_in == "n" or low_in == "no" or low_in == "f" or 
low_in == "false" or low_in == "0":
+value = False
+error = False
+
+return (value, error)
+
+@staticmethod
+def to_int(in_value):
+#FIXME: Not doing errors yet...
+return (int(in_value), False)
+
+@staticmethod
+def to_unsigned(in_value):
+# FIXME: find an unsigned converter...
+# And handle errors.
+return (int(in_value), False)
+
+translators = {
+lldb.eArgTypeBoolean : to_bool,
+lldb.eArgTypeBreakpointID : to_unsigned,
+lldb.eArgTypeByteSize : to_unsigned,
+lldb.eArgTypeCount : to_unsigned,
+lldb.eArgTypeFrameIndex : to_unsigned,
+lldb.eArgTypeIndex : to_unsigned,
+lldb.eArgTypeLineNum : to_unsigned,
+lldb.eArgTypeNumLines : to_unsigned,
+lldb.eArgTypeNumberPerLine : to_unsigned,
+lldb.eArgTypeOffset : to_int,
+lldb.eArgTypeThreadIndex : to_unsigned,
+lldb.eArgTypeUnsignedInteger : to_unsigned,
+lldb.eArgTypeWatchpointID : to_unsigned,
+lldb.eArgTypeColumnNum : to_unsigned,
+lldb.eArgTypeRecognizerID : to_unsigned,
+lldb.eArgTypeTargetID : to_unsigned,
+lldb.eArgTypeStopHookID : to_unsigned
+}
+
+@classmethod
+def translate_value(cls, value_type, value):
+try:
+return cls.translators[value_type](value)
+except KeyError:
+# If we don't have a translator, return the string value.
+return (value, False)
+
+# FIXME: would this be better done on the C++ side?
+# The common completers are missing some useful ones.
+# For instance there really should be a common Type completer
+# And an "lldb command name" completer.
+completion_table = {
+lldb.eArgTypeAddressOrExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeArchitecture : lldb.eArchitectureCompletion,
+lldb.eArgTypeBreakpointID : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointIDRange : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointName : lldb.eBreakpointNameCompletion,
+lldb.eArgTypeClassName : lldb.eSymbolCompletion,
+lldb.eArgTypeDirectoryName : lldb.eDiskDirectoryCompletion,
+lldb.eArgTypeExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeExpressionPath : lldb.eVariablePathCompletion,
+lldb.eArgTypeFilename : lldb.eDiskFileCompletion,
+lldb.eArgTypeFrameIndex : lldb.eFrameIndex

[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread David Spickett via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.
+
+There are example commands in the lldb testsuite at:
+
+llvm-project/lldb/test/API/commands/command/script/add/test_commands.py
+"""
+import inspect
+import lldb
+import sys
+from abc import abstractmethod
+
+class LLDBOVParser:

DavidSpickett wrote:

`self.ov_parser` is fine as a variable name since any IDE helper will show this 
type name for it.

https://github.com/llvm/llvm-project/pull/70734
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [compiler-rt] [flang] [libcxx] [llvm] [lldb] [clang] [mlir] [lld] [clang] Fix unexpected `-Wconstant-logical-operand` in C23 (PR #80724)

2024-02-06 Thread Mariya Podchishchaeva via lldb-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/80724

>From dd81e1aa3de2c38be91140b57d2c277a56e899bf Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Mon, 5 Feb 2024 10:43:56 -0800
Subject: [PATCH 1/2] [clang] Fix unexpected `-Wconstant-logical-operand` in
 C23

C23 has bool, but logical operators still return int. Double check that
we're not in C23 to avoid false-positive -Wconstant-logical-operand.

Fixes https://github.com/llvm/llvm-project/issues/64356
---
 clang/lib/Sema/SemaExpr.cpp|  3 ++-
 clang/test/Sema/warn-int-in-bool-context.c | 11 +++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index d15278bce5a6ba..f65b3abe5eaa24 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14073,7 +14073,8 @@ inline QualType Sema::CheckLogicalOperands(ExprResult 
&LHS, ExprResult &RHS,
 Expr::EvalResult EVResult;
 if (RHS.get()->EvaluateAsInt(EVResult, Context)) {
   llvm::APSInt Result = EVResult.Val.getInt();
-  if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType() &&
+  if ((getLangOpts().Bool && !getLangOpts().C23 &&
+   !RHS.get()->getType()->isBooleanType() &&
!RHS.get()->getExprLoc().isMacroID()) ||
   (Result != 0 && Result != 1)) {
 Diag(Loc, diag::warn_logical_instead_of_bitwise)
diff --git a/clang/test/Sema/warn-int-in-bool-context.c 
b/clang/test/Sema/warn-int-in-bool-context.c
index a6890161b5af89..c111a5af23f577 100644
--- a/clang/test/Sema/warn-int-in-bool-context.c
+++ b/clang/test/Sema/warn-int-in-bool-context.c
@@ -79,3 +79,14 @@ int test(int a, unsigned b, enum num n) {
   // Don't warn in macros.
   return SHIFT(1, a);
 }
+
+int GH64356(int arg) {
+  if ((arg == 1) && (1 == 1)) return 1;
+return 0;
+
+  if ((64 > 32) && (32 < 64))
+return 2;
+
+  if ((1 == 1) && (arg == 1)) return 1;
+return 0;
+}

>From 980e24e8c08c3d5a3b25cda69e329c3c0329dd25 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 6 Feb 2024 02:03:59 -0800
Subject: [PATCH 2/2] Check another lang option, add a release note

---
 clang/docs/ReleaseNotes.rst | 4 
 clang/lib/Sema/SemaExpr.cpp | 3 +--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4d57ea4fd55b8c..802c44b6c86080 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -164,6 +164,10 @@ Bug Fixes in This Version
 - Clang now accepts qualified partial/explicit specializations of variable 
templates that
   are not nominable in the lookup context of the specialization.
 
+- Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
+  for logical operators in C23.
+  Fixes (`#64356 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f65b3abe5eaa24..4049ab3bf6cafb 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14073,8 +14073,7 @@ inline QualType Sema::CheckLogicalOperands(ExprResult 
&LHS, ExprResult &RHS,
 Expr::EvalResult EVResult;
 if (RHS.get()->EvaluateAsInt(EVResult, Context)) {
   llvm::APSInt Result = EVResult.Val.getInt();
-  if ((getLangOpts().Bool && !getLangOpts().C23 &&
-   !RHS.get()->getType()->isBooleanType() &&
+  if ((getLangOpts().CPlusPlus && !RHS.get()->getType()->isBooleanType() &&
!RHS.get()->getExprLoc().isMacroID()) ||
   (Result != 0 && Result != 1)) {
 Diag(Loc, diag::warn_logical_instead_of_bitwise)

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


[Lldb-commits] [clang-tools-extra] [llvm] [lld] [lldb] [clang] [compiler-rt] [libcxxabi] [libc] [flang] [libcxx] Implement MCDCTVIdxBuilder and MCDCTestVectorBuilder (LLVM side) (PR #80676)

2024-02-06 Thread NAKAMURA Takumi via lldb-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/80676

>From d168e0cb85eb150caa7ab241f136c5a23f79ba38 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Mon, 5 Feb 2024 00:33:40 +0900
Subject: [PATCH 1/4] Implement MCDCTVIdxBuilder and MCDCTestVectorBuilder
 (LLVM side)

This accept current version of profdata. The output might be different.

See also
https://discourse.llvm.org/t/rfc-coverage-new-algorithm-and-file-format-for-mc-dc/76798
---
 .../ProfileData/Coverage/CoverageMapping.h|  24 ++
 .../ProfileData/Coverage/CoverageMapping.cpp  | 226 +-
 llvm/test/tools/llvm-cov/mcdc-const.test  |  28 +--
 llvm/test/tools/llvm-cov/mcdc-general.test|  16 +-
 4 files changed, 214 insertions(+), 80 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index 88ec60c7aa33c..62867275a8524 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -32,6 +32,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -557,6 +558,29 @@ struct MCDCRecord {
   }
 };
 
+class MCDCTVIdxBuilder {
+public:
+  struct MCDCNode {
+int InCount = 0;
+unsigned Width;
+struct {
+  int ID;
+  int Idx;
+} Conds[2];
+  };
+
+  SmallVector Nodes;
+  unsigned NumTestVectors;
+
+public:
+  using NodeIDs = std::tuple;
+
+  MCDCTVIdxBuilder(std::function Fetcher);
+};
+
 /// A Counter mapping context is used to connect the counters, expressions
 /// and the obtained counter values.
 class CounterMappingContext {
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 39e43f86eab5e..d3a60c664b9e9 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -223,6 +223,171 @@ Expected CounterMappingContext::evaluate(const 
Counter &C) const {
   return LastPoppedValue;
 }
 
+MCDCTVIdxBuilder::MCDCTVIdxBuilder(
+std::function Fetcher) {
+  // Build Nodes and set up each InCount
+  int MaxID = -1;
+  Nodes.resize(std::get<0>(Fetcher(true)));
+  while (true) {
+auto [ID1, FalseID1, TrueID1] = Fetcher(false);
+if (ID1 == 0)
+  break;
+if (Nodes.size() < ID1)
+  Nodes.resize(ID1);
+int ID = ID1 - 1;
+MaxID = std::max(MaxID, ID);
+auto &Node = Nodes[ID];
+Node.Conds[0].ID = FalseID1 - 1;
+Node.Conds[1].ID = TrueID1 - 1;
+for (unsigned I = 0; I < 2; ++I) {
+  int NextID = Node.Conds[I].ID;
+  if (NextID >= 0)
+++Nodes[NextID].InCount;
+}
+  }
+
+  if (MaxID < 0)
+return;
+
+  // Sort key ordered by <-Width, Ord>
+  SmallVector>
+  Decisions;
+
+  // Traverse Nodes to assign Idx
+  SmallVector Q;
+  assert(Nodes[0].InCount == 0);
+  Nodes[0].Width = 1;
+  Q.push_back(0);
+
+  unsigned Ord = 0;
+  while (!Q.empty()) {
+int ID = *Q.begin();
+Q.erase(Q.begin());
+auto &Node = Nodes[ID];
+assert(Node.Width > 0);
+
+for (unsigned I = 0; I < 2; ++I) {
+  int NextID = Node.Conds[I].ID;
+  assert(NextID != 0);
+  if (NextID < 0) {
+Decisions.emplace_back(-Node.Width, Ord++, ID, I);
+assert(Ord == Decisions.size());
+continue;
+  }
+
+  auto &NextNode = Nodes[NextID];
+  assert(NextNode.InCount > 0);
+  Node.Conds[I].Idx = NextNode.Width; // ???
+  NextNode.Width += Node.Width;
+  if (--NextNode.InCount == 0)
+Q.push_back(NextID);
+}
+  }
+
+  std::sort(Decisions.begin(), Decisions.end());
+
+  // Assign TestVector Index
+  unsigned CurIdx = 0;
+  for (auto [NegWidth, Ord, ID, C] : Decisions) {
+unsigned Width = -NegWidth;
+auto &Node = Nodes[ID];
+assert(Node.Width == Width);
+assert(Node.Conds[C].Idx == 0);
+assert(Node.Conds[C].ID < 0);
+Node.Conds[C].Idx = CurIdx;
+CurIdx += Width;
+  }
+  NumTestVectors = CurIdx;
+}
+
+namespace {
+
+class MCDCTestVectorBuilder : public MCDCTVIdxBuilder {
+  MCDCRecord::TestVectors TestVectors;
+  const BitVector &Bitmap;
+  unsigned BitmapIdx;
+#ifndef NDEBUG
+  DenseSet TVIDs;
+#endif
+
+  class BranchProvider {
+ArrayRef Branches;
+unsigned BranchIdx = 0;
+
+  public:
+BranchProvider(ArrayRef Branches)
+: Branches(Branches) {}
+
+std::function getFetcher() {
+  return [this](bool TellSize) {
+if (TellSize)
+  return NodeIDs(Branches.size(), 0, 0);
+if (BranchIdx >= Branches.size())
+  return NodeIDs(0, 0, 0);
+const auto *B = Branches[BranchIdx++];
+return NodeIDs(B->MCDCParams.ID, B->MCDCParams.FalseID,
+   B->MCDCParams.TrueID);
+  };
+}
+  };
+
+public:
+  MCDCTestVectorBuilder(ArrayRef Branches,
+const BitVector &Bitmap, unsigned BitmapIdx)
+  : MCDCTVIdxBuilder(Branch

[Lldb-commits] [clang-tools-extra] [llvm] [lld] [lldb] [clang] [compiler-rt] [libcxxabi] [libc] [flang] [libcxx] Implement MCDCTVIdxBuilder and MCDCTestVectorBuilder (LLVM side) (PR #80676)

2024-02-06 Thread NAKAMURA Takumi via lldb-commits

chapuni wrote:

I reworked to align the current implementation.

https://github.com/llvm/llvm-project/pull/80676
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [llvm] [lld] [lldb] [clang] [compiler-rt] [libcxxabi] [libc] [flang] [libcxx] Implement MCDCTVIdxBuilder and MCDCTestVectorBuilder (LLVM side) (PR #80676)

2024-02-06 Thread NAKAMURA Takumi via lldb-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/80676
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [llvm] [lld] [lldb] [clang] [compiler-rt] [libcxxabi] [libc] [flang] [libcxx] Implement MCDCTVIdxBuilder (LLVM side) (PR #80676)

2024-02-06 Thread NAKAMURA Takumi via lldb-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/80676
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [llvm] [lld] [lldb] [clang] [compiler-rt] [libcxxabi] [libc] [flang] [libcxx] Implement MCDCTVIdxBuilder (LLVM side) (PR #80676)

2024-02-06 Thread NAKAMURA Takumi via lldb-commits

https://github.com/chapuni ready_for_review 
https://github.com/llvm/llvm-project/pull/80676
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [libc] [openmp] [clang-tools-extra] [compiler-rt] [mlir] [lldb] [lld] [llvm] [flang] [libcxx] [Driver] Report invalid target triple versions for all environment types. (PR #7865

2024-02-06 Thread Cheng Shao via lldb-commits

TerrorJack wrote:

FYI this change breaks `wasi-sdk`/`wasi-libc` build with:

```
clang: error: version 'preview2' in target triple 
'wasm32-unknown-wasi-preview2' is invalid
```

https://github.com/llvm/llvm-project/pull/78655
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -200,8 +201,19 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  ModuleSP memory_module_sp = process->ReadModuleFromMemory(
+  FileSpec("temp_freebsd_kernel"), addr, header.e_shoff);
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {

DavidSpickett wrote:

Does this not happen for 32 bit kernels?

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -218,10 +230,16 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+
+  if (memory_module_sp->GetUUID() !=
+  process->GetTarget().GetExecutableModule()->GetUUID()) {
+LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress "

DavidSpickett wrote:

Could we log more specific failure reasons before the other `return` statements 
above and then make this more specific "coredump build-id did not match binary"?

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 

DavidSpickett wrote:

Exactly why does this change? I don't see a need for it in this PR.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits


@@ -200,8 +201,19 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  ModuleSP memory_module_sp = process->ReadModuleFromMemory(
+  FileSpec("temp_freebsd_kernel"), addr, header.e_shoff);
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {

aokblast wrote:

```c++
ModuleSP memory_module_sp = process->ReadModuleFromMemory(
  FileSpec("temp_freebsd_kernel"), addr, header.e_shoff);
```

This code segment is already handle the 32bit case as the original header 
structure is the 32bit ELF Ehdr. I just check if the ELF is 64bit version and 
replace it with the correct 64bit ELF Ehdr.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits


@@ -218,10 +230,16 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+
+  if (memory_module_sp->GetUUID() !=
+  process->GetTarget().GetExecutableModule()->GetUUID()) {
+LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress "

aokblast wrote:

Does this message ".note.gnu.build-id mismatched. Maybe you are using 
incompatible coredump with kernel binary?" like this is good?

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits


@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 

aokblast wrote:

The need is in here:
```c++
llvm::ELF::Elf64_Ehdr header;
if (!ReadELFHeader(process, addr, header)) {
  *read_error = true;
  return UUID();
}
```

In this case the header is Elf64 instead of Elf32. So I try to use generic to 
handle different version of Elf

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast edited 
https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast edited 
https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -200,8 +201,19 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  ModuleSP memory_module_sp = process->ReadModuleFromMemory(
+  FileSpec("temp_freebsd_kernel"), addr, header.e_shoff);
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {

DavidSpickett wrote:

Ok, so we're relying on the first few fields of the header being the same for 
32 and 64 bit. Which is fine.

However I would like to see it as much as possible written as:
```
if 64 bit:
64 bit stuff
else:
   32 bit stuff
```
Even if it means repeating a couple of things, because the program flow here is 
getting confusing.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett edited 
https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -218,10 +230,16 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+
+  if (memory_module_sp->GetUUID() !=
+  process->GetTarget().GetExecutableModule()->GetUUID()) {
+LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress "

DavidSpickett wrote:

Yes that sounds good.

"Cannot match" to me reads as many possible reasons like we couldn't read the 
ID from one of the files, it was in the wrong format, whatever. So I prefer 
what you've suggested.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [clang] [clang-tools-extra] [llvm] [libc] [libcxx] [lld] [flang] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-06 Thread Matt Arsenault via lldb-commits

https://github.com/arsenm approved this pull request.


https://github.com/llvm/llvm-project/pull/67104
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [clang] [libc] [libcxxabi] [lldb] [clang-tools-extra] [lld] [flang] [llvm] [compiler-rt] Implement MCDCTVIdxBuilder (LLVM side) (PR #80676)

2024-02-06 Thread NAKAMURA Takumi via lldb-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/80676

>From d168e0cb85eb150caa7ab241f136c5a23f79ba38 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Mon, 5 Feb 2024 00:33:40 +0900
Subject: [PATCH 1/5] Implement MCDCTVIdxBuilder and MCDCTestVectorBuilder
 (LLVM side)

This accept current version of profdata. The output might be different.

See also
https://discourse.llvm.org/t/rfc-coverage-new-algorithm-and-file-format-for-mc-dc/76798
---
 .../ProfileData/Coverage/CoverageMapping.h|  24 ++
 .../ProfileData/Coverage/CoverageMapping.cpp  | 226 +-
 llvm/test/tools/llvm-cov/mcdc-const.test  |  28 +--
 llvm/test/tools/llvm-cov/mcdc-general.test|  16 +-
 4 files changed, 214 insertions(+), 80 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h 
b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index 88ec60c7aa33c..62867275a8524 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -32,6 +32,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -557,6 +558,29 @@ struct MCDCRecord {
   }
 };
 
+class MCDCTVIdxBuilder {
+public:
+  struct MCDCNode {
+int InCount = 0;
+unsigned Width;
+struct {
+  int ID;
+  int Idx;
+} Conds[2];
+  };
+
+  SmallVector Nodes;
+  unsigned NumTestVectors;
+
+public:
+  using NodeIDs = std::tuple;
+
+  MCDCTVIdxBuilder(std::function Fetcher);
+};
+
 /// A Counter mapping context is used to connect the counters, expressions
 /// and the obtained counter values.
 class CounterMappingContext {
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 39e43f86eab5e..d3a60c664b9e9 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -223,6 +223,171 @@ Expected CounterMappingContext::evaluate(const 
Counter &C) const {
   return LastPoppedValue;
 }
 
+MCDCTVIdxBuilder::MCDCTVIdxBuilder(
+std::function Fetcher) {
+  // Build Nodes and set up each InCount
+  int MaxID = -1;
+  Nodes.resize(std::get<0>(Fetcher(true)));
+  while (true) {
+auto [ID1, FalseID1, TrueID1] = Fetcher(false);
+if (ID1 == 0)
+  break;
+if (Nodes.size() < ID1)
+  Nodes.resize(ID1);
+int ID = ID1 - 1;
+MaxID = std::max(MaxID, ID);
+auto &Node = Nodes[ID];
+Node.Conds[0].ID = FalseID1 - 1;
+Node.Conds[1].ID = TrueID1 - 1;
+for (unsigned I = 0; I < 2; ++I) {
+  int NextID = Node.Conds[I].ID;
+  if (NextID >= 0)
+++Nodes[NextID].InCount;
+}
+  }
+
+  if (MaxID < 0)
+return;
+
+  // Sort key ordered by <-Width, Ord>
+  SmallVector>
+  Decisions;
+
+  // Traverse Nodes to assign Idx
+  SmallVector Q;
+  assert(Nodes[0].InCount == 0);
+  Nodes[0].Width = 1;
+  Q.push_back(0);
+
+  unsigned Ord = 0;
+  while (!Q.empty()) {
+int ID = *Q.begin();
+Q.erase(Q.begin());
+auto &Node = Nodes[ID];
+assert(Node.Width > 0);
+
+for (unsigned I = 0; I < 2; ++I) {
+  int NextID = Node.Conds[I].ID;
+  assert(NextID != 0);
+  if (NextID < 0) {
+Decisions.emplace_back(-Node.Width, Ord++, ID, I);
+assert(Ord == Decisions.size());
+continue;
+  }
+
+  auto &NextNode = Nodes[NextID];
+  assert(NextNode.InCount > 0);
+  Node.Conds[I].Idx = NextNode.Width; // ???
+  NextNode.Width += Node.Width;
+  if (--NextNode.InCount == 0)
+Q.push_back(NextID);
+}
+  }
+
+  std::sort(Decisions.begin(), Decisions.end());
+
+  // Assign TestVector Index
+  unsigned CurIdx = 0;
+  for (auto [NegWidth, Ord, ID, C] : Decisions) {
+unsigned Width = -NegWidth;
+auto &Node = Nodes[ID];
+assert(Node.Width == Width);
+assert(Node.Conds[C].Idx == 0);
+assert(Node.Conds[C].ID < 0);
+Node.Conds[C].Idx = CurIdx;
+CurIdx += Width;
+  }
+  NumTestVectors = CurIdx;
+}
+
+namespace {
+
+class MCDCTestVectorBuilder : public MCDCTVIdxBuilder {
+  MCDCRecord::TestVectors TestVectors;
+  const BitVector &Bitmap;
+  unsigned BitmapIdx;
+#ifndef NDEBUG
+  DenseSet TVIDs;
+#endif
+
+  class BranchProvider {
+ArrayRef Branches;
+unsigned BranchIdx = 0;
+
+  public:
+BranchProvider(ArrayRef Branches)
+: Branches(Branches) {}
+
+std::function getFetcher() {
+  return [this](bool TellSize) {
+if (TellSize)
+  return NodeIDs(Branches.size(), 0, 0);
+if (BranchIdx >= Branches.size())
+  return NodeIDs(0, 0, 0);
+const auto *B = Branches[BranchIdx++];
+return NodeIDs(B->MCDCParams.ID, B->MCDCParams.FalseID,
+   B->MCDCParams.TrueID);
+  };
+}
+  };
+
+public:
+  MCDCTestVectorBuilder(ArrayRef Branches,
+const BitVector &Bitmap, unsigned BitmapIdx)
+  : MCDCTVIdxBuilder(Branch

[Lldb-commits] [libcxx] [clang] [lldb] [lld] [mlir] [flang] [llvm] [compiler-rt] [clang] Fix unexpected `-Wconstant-logical-operand` in C23 (PR #80724)

2024-02-06 Thread Aaron Ballman via lldb-commits

https://github.com/AaronBallman approved this pull request.

LGTM, thank you!

https://github.com/llvm/llvm-project/pull/80724
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [flang] [lld] [mlir] [llvm] [libcxx] [lldb] [compiler-rt] [clang] [clang] Fix unexpected `-Wconstant-logical-operand` in C23 (PR #80724)

2024-02-06 Thread Mariya Podchishchaeva via lldb-commits

Fznamznon wrote:

Windows failure in CI seems unrelated.

https://github.com/llvm/llvm-project/pull/80724
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [clang] [lldb] [lld] [mlir] [flang] [llvm] [compiler-rt] [clang] Fix unexpected `-Wconstant-logical-operand` in C23 (PR #80724)

2024-02-06 Thread Mariya Podchishchaeva via lldb-commits

https://github.com/Fznamznon closed 
https://github.com/llvm/llvm-project/pull/80724
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/80785

>From 5f9eac19a45cd4b71afe48643fc0cf8b4b4ab6be Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 10:18:34 +0800
Subject: [PATCH 1/2] [LLDB] Fetch UUID from note section in coredump

---
 .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp  | 29 +++
 .../Plugins/ObjectFile/ELF/ObjectFileELF.h|  3 ++
 2 files changed, 32 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 0d95a1c12bde3..3b047e3d5c759 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -795,6 +795,32 @@ bool ObjectFileELF::ParseHeader() {
   return m_header.Parse(m_data, &offset);
 }
 
+UUID ObjectFileELF::GetUUIDByNoteSection() {
+  if (!ParseProgramHeaders())
+return UUID();
+  for (const ELFProgramHeader &H : m_program_headers) {
+if (H.p_type == llvm::ELF::PT_NOTE) {
+  const elf_off ph_offset = H.p_offset;
+  const size_t ph_size = H.p_filesz;
+
+  DataExtractor segment_data;
+  if (segment_data.SetData(m_data, ph_offset, ph_size) != ph_size) {
+// The ELF program header contained incorrect data, probably corefile
+// is incomplete or corrupted.
+break;
+  }
+
+  UUID uuid;
+  ArchSpec arch;
+
+  if (RefineModuleDetailsFromNote(segment_data, arch, uuid).Success())
+return uuid;
+}
+  }
+
+  return UUID();
+}
+
 UUID ObjectFileELF::GetUUID() {
   // Need to parse the section list to get the UUIDs, so make sure that's been
   // done.
@@ -809,6 +835,9 @@ UUID ObjectFileELF::GetUUID() {
   if (!ParseProgramHeaders())
 return UUID();
 
+  if ((m_uuid = GetUUIDByNoteSection()).IsValid())
+return m_uuid;
+
   core_notes_crc =
   CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index bc8e34981a9d8..6954bd96b753a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -272,6 +272,9 @@ class ObjectFileELF : public lldb_private::ObjectFile {
  uint32_t &gnu_debuglink_crc,
  lldb_private::ArchSpec &arch_spec);
 
+  // Use Note Section to get uuid.
+  lldb_private::UUID GetUUIDByNoteSection();
+
   /// Scans the dynamic section and locates all dependent modules (shared
   /// libraries) populating m_filespec_up.  This method will compute the
   /// dependent module list only once.  Returns the number of dependent

>From deb85785cd28e2f2975a84e839b243a7b583b264 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 21:15:55 +0800
Subject: [PATCH 2/2] Add match check between binary and coredump of FreeBSD
 kernel

---
 .../DynamicLoaderFreeBSDKernel.cpp| 37 +++
 .../DynamicLoaderFreeBSDKernel.h  |  3 +-
 2 files changed, 32 insertions(+), 8 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index e504e6cbf6921..b77e089ce2fe6 100644
--- 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 
 bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
lldb::addr_t addr,
-   llvm::ELF::Elf32_Ehdr &header,
+   Elf_Ehdr &header,
bool *read_error) {
   Status error;
   if (read_error)
@@ -200,8 +201,23 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  // If the memory module is 64bit, we should use the Elf64_Ehdr or the e_shoff
+  // would be wrong
+  ModuleSP memory_module_sp;
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {
+llvm::ELF::Elf64_Ehdr elf64_header;
+if (!ReadELFHeader(process, addr, elf64_header)) {
+  *read_error = true;
+  return UUID();
+}
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, elf64_header.e_shoff);
+  } else {
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpe

[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

aokblast wrote:

All of the problem is fixed.

However, FreeBSD doesn't load PT_NOTE segment originally and I add it yesterday 
in [this](https://reviews.freebsd.org/D43757) patch with this LLDB patch at the 
same time. Currently, FreeBSD phabricator has no any response yet. I think we 
should land the patch in FreeBSD first or the LLDB will failed in the UUID 
check. 

Maybe I can tag some guys in FreeBSD like @emaste to check if the patch in 
FreeBSD make senses?

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Thanks, the logic is clearer now.

Should this check be limited to only when a uuid is actually found? This would 
allow debugging of older FreeBSDs with a newer lldb.



https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

aokblast wrote:

Oh, yes, you are right. I am just thinking the same things. XD

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/80785

>From 5f9eac19a45cd4b71afe48643fc0cf8b4b4ab6be Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 10:18:34 +0800
Subject: [PATCH 1/2] [LLDB] Fetch UUID from note section in coredump

---
 .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp  | 29 +++
 .../Plugins/ObjectFile/ELF/ObjectFileELF.h|  3 ++
 2 files changed, 32 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 0d95a1c12bde3..3b047e3d5c759 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -795,6 +795,32 @@ bool ObjectFileELF::ParseHeader() {
   return m_header.Parse(m_data, &offset);
 }
 
+UUID ObjectFileELF::GetUUIDByNoteSection() {
+  if (!ParseProgramHeaders())
+return UUID();
+  for (const ELFProgramHeader &H : m_program_headers) {
+if (H.p_type == llvm::ELF::PT_NOTE) {
+  const elf_off ph_offset = H.p_offset;
+  const size_t ph_size = H.p_filesz;
+
+  DataExtractor segment_data;
+  if (segment_data.SetData(m_data, ph_offset, ph_size) != ph_size) {
+// The ELF program header contained incorrect data, probably corefile
+// is incomplete or corrupted.
+break;
+  }
+
+  UUID uuid;
+  ArchSpec arch;
+
+  if (RefineModuleDetailsFromNote(segment_data, arch, uuid).Success())
+return uuid;
+}
+  }
+
+  return UUID();
+}
+
 UUID ObjectFileELF::GetUUID() {
   // Need to parse the section list to get the UUIDs, so make sure that's been
   // done.
@@ -809,6 +835,9 @@ UUID ObjectFileELF::GetUUID() {
   if (!ParseProgramHeaders())
 return UUID();
 
+  if ((m_uuid = GetUUIDByNoteSection()).IsValid())
+return m_uuid;
+
   core_notes_crc =
   CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index bc8e34981a9d8..6954bd96b753a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -272,6 +272,9 @@ class ObjectFileELF : public lldb_private::ObjectFile {
  uint32_t &gnu_debuglink_crc,
  lldb_private::ArchSpec &arch_spec);
 
+  // Use Note Section to get uuid.
+  lldb_private::UUID GetUUIDByNoteSection();
+
   /// Scans the dynamic section and locates all dependent modules (shared
   /// libraries) populating m_filespec_up.  This method will compute the
   /// dependent module list only once.  Returns the number of dependent

>From ebcee01c88b9064b1b9da8fdca0561a569bb6271 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 21:56:24 +0800
Subject: [PATCH 2/2] Add match check between binary and coredump of FreeBSD
 kernel

---
 .../DynamicLoaderFreeBSDKernel.cpp| 38 +++
 .../DynamicLoaderFreeBSDKernel.h  |  3 +-
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index e504e6cbf6921..5ac629552de7c 100644
--- 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 
 bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
lldb::addr_t addr,
-   llvm::ELF::Elf32_Ehdr &header,
+   Elf_Ehdr &header,
bool *read_error) {
   Status error;
   if (read_error)
@@ -200,8 +201,23 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  // If the memory module is 64bit, we should use the Elf64_Ehdr or the e_shoff
+  // would be wrong
+  ModuleSP memory_module_sp;
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {
+llvm::ELF::Elf64_Ehdr elf64_header;
+if (!ReadELFHeader(process, addr, elf64_header)) {
+  *read_error = true;
+  return UUID();
+}
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, elf64_header.e_shoff);
+  } else {
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpe

[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -218,10 +234,18 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+  UUID memory_module_uuid = memory_module_sp->GetUUID();
+  if (memory_module_uuid.IsValid() &&

DavidSpickett wrote:

Add a comment here like "// FreeBSD did not always include the  in core dumps, only check if present.".

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/80785

>From 5f9eac19a45cd4b71afe48643fc0cf8b4b4ab6be Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 10:18:34 +0800
Subject: [PATCH 1/2] [LLDB] Fetch UUID from note section in coredump

---
 .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp  | 29 +++
 .../Plugins/ObjectFile/ELF/ObjectFileELF.h|  3 ++
 2 files changed, 32 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 0d95a1c12bde3..3b047e3d5c759 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -795,6 +795,32 @@ bool ObjectFileELF::ParseHeader() {
   return m_header.Parse(m_data, &offset);
 }
 
+UUID ObjectFileELF::GetUUIDByNoteSection() {
+  if (!ParseProgramHeaders())
+return UUID();
+  for (const ELFProgramHeader &H : m_program_headers) {
+if (H.p_type == llvm::ELF::PT_NOTE) {
+  const elf_off ph_offset = H.p_offset;
+  const size_t ph_size = H.p_filesz;
+
+  DataExtractor segment_data;
+  if (segment_data.SetData(m_data, ph_offset, ph_size) != ph_size) {
+// The ELF program header contained incorrect data, probably corefile
+// is incomplete or corrupted.
+break;
+  }
+
+  UUID uuid;
+  ArchSpec arch;
+
+  if (RefineModuleDetailsFromNote(segment_data, arch, uuid).Success())
+return uuid;
+}
+  }
+
+  return UUID();
+}
+
 UUID ObjectFileELF::GetUUID() {
   // Need to parse the section list to get the UUIDs, so make sure that's been
   // done.
@@ -809,6 +835,9 @@ UUID ObjectFileELF::GetUUID() {
   if (!ParseProgramHeaders())
 return UUID();
 
+  if ((m_uuid = GetUUIDByNoteSection()).IsValid())
+return m_uuid;
+
   core_notes_crc =
   CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index bc8e34981a9d8..6954bd96b753a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -272,6 +272,9 @@ class ObjectFileELF : public lldb_private::ObjectFile {
  uint32_t &gnu_debuglink_crc,
  lldb_private::ArchSpec &arch_spec);
 
+  // Use Note Section to get uuid.
+  lldb_private::UUID GetUUIDByNoteSection();
+
   /// Scans the dynamic section and locates all dependent modules (shared
   /// libraries) populating m_filespec_up.  This method will compute the
   /// dependent module list only once.  Returns the number of dependent

>From aeeb32888f0137fd72fe067d9d7a03a5e1299cc6 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 22:06:08 +0800
Subject: [PATCH 2/2] Add match check between binary and coredump of FreeBSD
 kernel

---
 .../DynamicLoaderFreeBSDKernel.cpp| 40 +++
 .../DynamicLoaderFreeBSDKernel.h  |  3 +-
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index e504e6cbf6921..ddebe87999fdb 100644
--- 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 
 bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
lldb::addr_t addr,
-   llvm::ELF::Elf32_Ehdr &header,
+   Elf_Ehdr &header,
bool *read_error) {
   Status error;
   if (read_error)
@@ -200,8 +201,23 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  // If the memory module is 64bit, we should use the Elf64_Ehdr or the e_shoff
+  // would be wrong
+  ModuleSP memory_module_sp;
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {
+llvm::ELF::Elf64_Ehdr elf64_header;
+if (!ReadELFHeader(process, addr, elf64_header)) {
+  *read_error = true;
+  return UUID();
+}
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, elf64_header.e_shoff);
+  } else {
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpe

[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits


@@ -218,10 +234,18 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+  UUID memory_module_uuid = memory_module_sp->GetUUID();
+  if (memory_module_uuid.IsValid() &&

aokblast wrote:

Fix it

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -218,10 +234,18 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+  UUID memory_module_uuid = memory_module_sp->GetUUID();
+  if (memory_module_uuid.IsValid() &&

DavidSpickett wrote:

Sorry, Github ate the `<>` in my comment. It was meant to say `include the 
 in core dumps`.

Replace with the actual name, `.note.gnu.build-id` I presume.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/80785

>From 5f9eac19a45cd4b71afe48643fc0cf8b4b4ab6be Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 10:18:34 +0800
Subject: [PATCH 1/2] [LLDB] Fetch UUID from note section in coredump

---
 .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp  | 29 +++
 .../Plugins/ObjectFile/ELF/ObjectFileELF.h|  3 ++
 2 files changed, 32 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 0d95a1c12bde3..3b047e3d5c759 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -795,6 +795,32 @@ bool ObjectFileELF::ParseHeader() {
   return m_header.Parse(m_data, &offset);
 }
 
+UUID ObjectFileELF::GetUUIDByNoteSection() {
+  if (!ParseProgramHeaders())
+return UUID();
+  for (const ELFProgramHeader &H : m_program_headers) {
+if (H.p_type == llvm::ELF::PT_NOTE) {
+  const elf_off ph_offset = H.p_offset;
+  const size_t ph_size = H.p_filesz;
+
+  DataExtractor segment_data;
+  if (segment_data.SetData(m_data, ph_offset, ph_size) != ph_size) {
+// The ELF program header contained incorrect data, probably corefile
+// is incomplete or corrupted.
+break;
+  }
+
+  UUID uuid;
+  ArchSpec arch;
+
+  if (RefineModuleDetailsFromNote(segment_data, arch, uuid).Success())
+return uuid;
+}
+  }
+
+  return UUID();
+}
+
 UUID ObjectFileELF::GetUUID() {
   // Need to parse the section list to get the UUIDs, so make sure that's been
   // done.
@@ -809,6 +835,9 @@ UUID ObjectFileELF::GetUUID() {
   if (!ParseProgramHeaders())
 return UUID();
 
+  if ((m_uuid = GetUUIDByNoteSection()).IsValid())
+return m_uuid;
+
   core_notes_crc =
   CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index bc8e34981a9d8..6954bd96b753a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -272,6 +272,9 @@ class ObjectFileELF : public lldb_private::ObjectFile {
  uint32_t &gnu_debuglink_crc,
  lldb_private::ArchSpec &arch_spec);
 
+  // Use Note Section to get uuid.
+  lldb_private::UUID GetUUIDByNoteSection();
+
   /// Scans the dynamic section and locates all dependent modules (shared
   /// libraries) populating m_filespec_up.  This method will compute the
   /// dependent module list only once.  Returns the number of dependent

>From 9df99033e10650d2afc68d5438f658bfbcdc0a29 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 22:38:57 +0800
Subject: [PATCH 2/2] Add match check between binary and coredump of FreeBSD
 kernel

---
 .../DynamicLoaderFreeBSDKernel.cpp| 41 +++
 .../DynamicLoaderFreeBSDKernel.h  |  3 +-
 2 files changed, 36 insertions(+), 8 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index e504e6cbf6921..c134f1d46c275 100644
--- 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 
 bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
lldb::addr_t addr,
-   llvm::ELF::Elf32_Ehdr &header,
+   Elf_Ehdr &header,
bool *read_error) {
   Status error;
   if (read_error)
@@ -200,8 +201,23 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  // If the memory module is 64bit, we should use the Elf64_Ehdr or the e_shoff
+  // would be wrong
+  ModuleSP memory_module_sp;
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {
+llvm::ELF::Elf64_Ehdr elf64_header;
+if (!ReadELFHeader(process, addr, elf64_header)) {
+  *read_error = true;
+  return UUID();
+}
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, elf64_header.e_shoff);
+  } else {
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpe

[Lldb-commits] [clang] [lld] [libcxx] [clang-tools-extra] [lldb] [mlir] [openmp] [libc] [llvm] [flang] [SLP]Add support for strided loads. (PR #80310)

2024-02-06 Thread Alexey Bataev via lldb-commits

https://github.com/alexey-bataev updated 
https://github.com/llvm/llvm-project/pull/80310

>From 92950afd39034c0184a3c807f8062e0053eead5c Mon Sep 17 00:00:00 2001
From: Alexey Bataev 
Date: Thu, 1 Feb 2024 17:22:34 +
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 .../llvm/Analysis/TargetTransformInfo.h   |  34 ++
 .../llvm/Analysis/TargetTransformInfoImpl.h   |  13 +
 llvm/lib/Analysis/TargetTransformInfo.cpp |  14 +
 .../Target/RISCV/RISCVTargetTransformInfo.cpp |  23 +
 .../Target/RISCV/RISCVTargetTransformInfo.h   |  23 +
 .../Transforms/Vectorize/SLPVectorizer.cpp| 397 --
 .../SLPVectorizer/RISCV/complex-loads.ll  | 132 +++---
 .../RISCV/strided-loads-vectorized.ll | 209 +
 .../strided-loads-with-external-use-ptr.ll|   4 +-
 .../SLPVectorizer/RISCV/strided-loads.ll  |  13 +-
 .../X86/gep-nodes-with-non-gep-inst.ll|   2 +-
 .../X86/remark_gather-load-redux-cost.ll  |   2 +-
 12 files changed, 478 insertions(+), 388 deletions(-)

diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h 
b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index 3b615bc700bbb..b0b6dab03fa38 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -781,6 +781,9 @@ class TargetTransformInfo {
   /// Return true if the target supports masked expand load.
   bool isLegalMaskedExpandLoad(Type *DataType) const;
 
+  /// Return true if the target supports strided load.
+  bool isLegalStridedLoad(Type *DataType, Align Alignment) const;
+
   /// Return true if this is an alternating opcode pattern that can be lowered
   /// to a single instruction on the target. In X86 this is for the addsub
   /// instruction which corrsponds to a Shuffle + Fadd + FSub pattern in IR.
@@ -1412,6 +1415,20 @@ class TargetTransformInfo {
   Align Alignment, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
   const Instruction *I = nullptr) const;
 
+  /// \return The cost of strided memory operations.
+  /// \p Opcode - is a type of memory access Load or Store
+  /// \p DataTy - a vector type of the data to be loaded or stored
+  /// \p Ptr - pointer [or vector of pointers] - address[es] in memory
+  /// \p VariableMask - true when the memory access is predicated with a mask
+  ///   that is not a compile-time constant
+  /// \p Alignment - alignment of single element
+  /// \p I - the optional original context instruction, if one exists, e.g. the
+  ///load/store to transform or the call to the gather/scatter 
intrinsic
+  InstructionCost getStridedMemoryOpCost(
+  unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask,
+  Align Alignment, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
+  const Instruction *I = nullptr) const;
+
   /// \return The cost of the interleaved memory operation.
   /// \p Opcode is the memory operation code
   /// \p VecTy is the vector type of the interleaved access.
@@ -1848,6 +1865,7 @@ class TargetTransformInfo::Concept {
Align Alignment) = 0;
   virtual bool isLegalMaskedCompressStore(Type *DataType) = 0;
   virtual bool isLegalMaskedExpandLoad(Type *DataType) = 0;
+  virtual bool isLegalStridedLoad(Type *DataType, Align Alignment) = 0;
   virtual bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0,
unsigned Opcode1,
const SmallBitVector &OpcodeMask) const = 0;
@@ -2023,6 +2041,11 @@ class TargetTransformInfo::Concept {
  bool VariableMask, Align Alignment,
  TTI::TargetCostKind CostKind,
  const Instruction *I = nullptr) = 0;
+  virtual InstructionCost
+  getStridedMemoryOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr,
+ bool VariableMask, Align Alignment,
+ TTI::TargetCostKind CostKind,
+ const Instruction *I = nullptr) = 0;
 
   virtual InstructionCost getInterleavedMemoryOpCost(
   unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef 
Indices,
@@ -2341,6 +2364,9 @@ class TargetTransformInfo::Model final : public 
TargetTransformInfo::Concept {
   bool isLegalMaskedExpandLoad(Type *DataType) override {
 return Impl.isLegalMaskedExpandLoad(DataType);
   }
+  bool isLegalStridedLoad(Type *DataType, Align Alignment) override {
+return Impl.isLegalStridedLoad(DataType, Alignment);
+  }
   bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
const SmallBitVector &OpcodeMask) const override {
 return Impl.isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask);
@@ -2671,6 +2697,14 @@ class TargetTransformInfo::Model

[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits


@@ -218,10 +234,18 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+  UUID memory_module_uuid = memory_module_sp->GetUUID();
+  if (memory_module_uuid.IsValid() &&

aokblast wrote:

Sorry, I don't notice that. I fixed it.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Fix expressions that involve nested structs/classes/unions. (PR #77029)

2024-02-06 Thread Michael Buch via lldb-commits

Michael137 wrote:

> So we never get a query again to find anything inside of this class. That 
> being said, I am not sure anything ever was doing another external AST lookup 
> in this class after we completed it. But if we are able to add debugger 
> specific support into the external AST virtual interface, we might be able to 
> gets asked "withing this 'class A' please find me a contained type" and then 
> modify the compiler to use the external AST source when a lookup in a class 
> decl context fails.

Right, what we want is for the `DeclContext::lookup` 
[here](https://github.com/llvm/llvm-project/blob/c6b5ea339d9f257b64f4ca468e447f0e29a909a4/clang/lib/Sema/SemaLookup.cpp#L1123-L1130)
 to consult LLDB, but it doesn't because the containing type was already marked 
as not having external storage. Haven't had the chance yet to look at what it 
would mean for us to drop the `setHasExternalLexicalStorage` calls with the 
current type-completion infrastructure, but 
[D101950](https://reviews.llvm.org/D101950) which we're trying to revive (where 
we pull definitions in more eagerly) gets rid of them

https://github.com/llvm/llvm-project/pull/77029
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [lld] [clang-tools-extra] [clang] [flang] [libcxx] [libc] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-06 Thread David Stuttard via lldb-commits

https://github.com/dstutt closed https://github.com/llvm/llvm-project/pull/67104
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][unittest] Add call_once flag to initialize debugger (PR #80786)

2024-02-06 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova updated 
https://github.com/llvm/llvm-project/pull/80786

>From 0d56057bc9904b2079324b21b3625def7e15b6c2 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova 
Date: Mon, 5 Feb 2024 18:41:14 -0800
Subject: [PATCH] [lldb][unittest] Add call_once flag to initialize debugger

I tried adding a new unit test to the core test
suite (https://github.com/llvm/llvm-project/pull/79533) but it broke the
test suite on AArch64 Linux due to hitting an assertion for calling
`Debugger::Initialize` more than once. When the unit test suite is
invoked as a standalone binary the test suite state is shared, and
`Debugger::Initialize` gets called in `DiagnosticEventTest.cpp` before
being called in `ProgressReportTest.cpp`.

`DiagnosticEventTest.cpp` uses a call_once flag to initialize the
debugger but it's local to that test. This commit adds a once_flag to
`TestUtilities` so that `Debugger::Initialize` can be called once by the
tests that use it.
---
 lldb/unittests/TestingSupport/TestUtilities.cpp | 1 +
 lldb/unittests/TestingSupport/TestUtilities.h   | 7 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lldb/unittests/TestingSupport/TestUtilities.cpp 
b/lldb/unittests/TestingSupport/TestUtilities.cpp
index 9e5523e487547..efdc6c5eb234a 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -19,6 +19,7 @@ using namespace lldb_private;
 
 extern const char *TestMainArgv0;
 
+std::once_flag TestUtilities::g_debugger_initialize_flag;
 std::string lldb_private::GetInputFilePath(const llvm::Twine &name) {
   llvm::SmallString<128> result = llvm::sys::path::parent_path(TestMainArgv0);
   llvm::sys::fs::make_absolute(result);
diff --git a/lldb/unittests/TestingSupport/TestUtilities.h 
b/lldb/unittests/TestingSupport/TestUtilities.h
index 811c4c1521269..7d040d64db8d8 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.h
+++ b/lldb/unittests/TestingSupport/TestUtilities.h
@@ -31,6 +31,11 @@
 namespace lldb_private {
 std::string GetInputFilePath(const llvm::Twine &name);
 
+class TestUtilities {
+public:
+  static std::once_flag g_debugger_initialize_flag;
+};
+
 class TestFile {
 public:
   static llvm::Expected fromYaml(llvm::StringRef Yaml);
@@ -51,6 +56,6 @@ class TestFile {
 
   std::string Buffer;
 };
-}
+} // namespace lldb_private
 
 #endif

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


[Lldb-commits] [lldb] 3885483 - [lldb][unittest] Add call_once flag to initialize debugger (#80786)

2024-02-06 Thread via lldb-commits

Author: Chelsea Cassanova
Date: 2024-02-06T08:17:23-08:00
New Revision: 388548359f5049b88a9738d8a9e67691503fbdef

URL: 
https://github.com/llvm/llvm-project/commit/388548359f5049b88a9738d8a9e67691503fbdef
DIFF: 
https://github.com/llvm/llvm-project/commit/388548359f5049b88a9738d8a9e67691503fbdef.diff

LOG: [lldb][unittest] Add call_once flag to initialize debugger (#80786)

I tried adding a new unit test to the core test
suite (https://github.com/llvm/llvm-project/pull/79533) but it broke the
test suite on AArch64 Linux due to hitting an assertion for calling
`Debugger::Initialize` more than once. When the unit test suite is
invoked as a standalone binary the test suite state is shared, and
`Debugger::Initialize` gets called in `DiagnosticEventTest.cpp` before
being called in `ProgressReportTest.cpp`.

`DiagnosticEventTest.cpp` uses a call_once flag to initialize the
debugger but it's local to that test. This commit adds a once_flag to
`TestUtilities` so that `Debugger::Initialize` can be called once by the
tests that use it.

Added: 


Modified: 
lldb/unittests/TestingSupport/TestUtilities.cpp
lldb/unittests/TestingSupport/TestUtilities.h

Removed: 




diff  --git a/lldb/unittests/TestingSupport/TestUtilities.cpp 
b/lldb/unittests/TestingSupport/TestUtilities.cpp
index 9e5523e487547..efdc6c5eb234a 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -19,6 +19,7 @@ using namespace lldb_private;
 
 extern const char *TestMainArgv0;
 
+std::once_flag TestUtilities::g_debugger_initialize_flag;
 std::string lldb_private::GetInputFilePath(const llvm::Twine &name) {
   llvm::SmallString<128> result = llvm::sys::path::parent_path(TestMainArgv0);
   llvm::sys::fs::make_absolute(result);

diff  --git a/lldb/unittests/TestingSupport/TestUtilities.h 
b/lldb/unittests/TestingSupport/TestUtilities.h
index 811c4c1521269..7d040d64db8d8 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.h
+++ b/lldb/unittests/TestingSupport/TestUtilities.h
@@ -31,6 +31,11 @@
 namespace lldb_private {
 std::string GetInputFilePath(const llvm::Twine &name);
 
+class TestUtilities {
+public:
+  static std::once_flag g_debugger_initialize_flag;
+};
+
 class TestFile {
 public:
   static llvm::Expected fromYaml(llvm::StringRef Yaml);
@@ -51,6 +56,6 @@ class TestFile {
 
   std::string Buffer;
 };
-}
+} // namespace lldb_private
 
 #endif



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


[Lldb-commits] [lldb] [lldb][unittest] Add call_once flag to initialize debugger (PR #80786)

2024-02-06 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova closed 
https://github.com/llvm/llvm-project/pull/80786
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Reland "[lldb][progress][NFC] Add unit test for progress reports" (PR #80791)

2024-02-06 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova updated 
https://github.com/llvm/llvm-project/pull/80791

>From 16e468b938ade09c57fd1eb7ea3db7b673836cb0 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova 
Date: Mon, 5 Feb 2024 19:00:52 -0800
Subject: [PATCH] Reland "[lldb][progress][NFC] Add unit test for progress
 reports"

This file was previously approved and merged from this PR:
https://github.com/llvm/llvm-project/pull/79533 but caused a test
failure on the Linux AArch64 bots due to hitting an assertion that
`Debugger::Initialize` was already called.

To fix this, this commit uses the
changes made here: https://github.com/llvm/llvm-project/pull/80786 to
use a shared call_once flag to initialize the debugger.
---
 lldb/unittests/Core/ProgressReportTest.cpp | 128 +
 1 file changed, 128 insertions(+)
 create mode 100644 lldb/unittests/Core/ProgressReportTest.cpp

diff --git a/lldb/unittests/Core/ProgressReportTest.cpp 
b/lldb/unittests/Core/ProgressReportTest.cpp
new file mode 100644
index 0..559f3ef1ae46b
--- /dev/null
+++ b/lldb/unittests/Core/ProgressReportTest.cpp
@@ -0,0 +1,128 @@
+//===-- ProgressReportTest.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/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/Listener.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+class ProgressReportTest : public ::testing::Test {
+  SubsystemRAII subsystems;
+
+  // The debugger's initialization function can't be called with no arguments
+  // so calling it using SubsystemRAII will cause the test build to fail as
+  // SubsystemRAII will call Initialize with no arguments. As such we set it up
+  // here the usual way.
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+  };
+};
+
+TEST_F(ProgressReportTest, TestReportCreation) {
+  std::chrono::milliseconds timeout(100);
+
+  // Set up the debugger, make sure that was done properly.
+  ArchSpec arch("x86_64-apple-macosx-");
+  Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+  DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+
+  // Get the debugger's broadcaster.
+  Broadcaster &broadcaster = debugger_sp->GetBroadcaster();
+
+  // Create a listener, make sure it can receive events and that it's
+  // listening to the correct broadcast bit.
+  ListenerSP listener_sp = Listener::MakeListener("progress-listener");
+
+  listener_sp->StartListeningForEvents(&broadcaster,
+   Debugger::eBroadcastBitProgress);
+  EXPECT_TRUE(
+  broadcaster.EventTypeHasListeners(Debugger::eBroadcastBitProgress));
+
+  EventSP event_sp;
+  const ProgressEventData *data;
+
+  // Scope this for RAII on the progress objects.
+  // Create progress reports and check that their respective events for having
+  // started and ended are broadcasted.
+  {
+Progress progress1("Progress report 1", "Starting report 1");
+Progress progress2("Progress report 2", "Starting report 2");
+Progress progress3("Progress report 3", "Starting report 3");
+  }
+
+  // Start popping events from the queue, they should have been recevied
+  // in this order:
+  // Starting progress: 1, 2, 3
+  // Ending progress: 3, 2, 1
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+
+  ASSERT_EQ(data->GetDetails(), "Starting report 1");
+  ASSERT_FALSE(data->IsFinite());
+  ASSERT_FALSE(data->GetCompleted());
+  ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
+  ASSERT_EQ(data->GetMessage(), "Progress report 1: Starting report 1");
+
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+
+  ASSERT_EQ(data->GetDetails(), "Starting report 2");
+  ASSERT_FALSE(data->IsFinite());
+  ASSERT_FALSE(data->GetCompleted());
+  ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
+  ASSERT_EQ(data->GetMessage(), "Progress report 2: Starting report 2");
+
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+  ASSERT_EQ(data->GetDetails(), "Starting report 3");
+  ASSERT_FALSE(data->IsFinite());
+  ASSERT_FALSE

[Lldb-commits] [lldb] 5690027 - [lldb][unittest] Use shared once_flag in DiagnosticEventTest (#80788)

2024-02-06 Thread via lldb-commits

Author: Chelsea Cassanova
Date: 2024-02-06T08:36:00-08:00
New Revision: 56900278b578b4f7beedb8ac1e52c541d347f401

URL: 
https://github.com/llvm/llvm-project/commit/56900278b578b4f7beedb8ac1e52c541d347f401
DIFF: 
https://github.com/llvm/llvm-project/commit/56900278b578b4f7beedb8ac1e52c541d347f401.diff

LOG: [lldb][unittest] Use shared once_flag in DiagnosticEventTest (#80788)

Incorporates the changes from
https://github.com/llvm/llvm-project/pull/80786 to use a once_flag from
`TestUtilities` instead of a local flag in order to prevent hitting an
assertion that the debugger was initialized again in another test.

Added: 


Modified: 
lldb/unittests/Core/DiagnosticEventTest.cpp

Removed: 




diff  --git a/lldb/unittests/Core/DiagnosticEventTest.cpp 
b/lldb/unittests/Core/DiagnosticEventTest.cpp
index bca8f3789955ab..d06f164e87e70c 100644
--- a/lldb/unittests/Core/DiagnosticEventTest.cpp
+++ b/lldb/unittests/Core/DiagnosticEventTest.cpp
@@ -11,6 +11,7 @@
 #include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
 #include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
 #include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/DebuggerEvents.h"
 #include "lldb/Host/FileSystem.h"
@@ -26,8 +27,6 @@ using namespace lldb_private::repro;
 static const constexpr std::chrono::seconds TIMEOUT(0);
 static const constexpr size_t DEBUGGERS = 3;
 
-static std::once_flag debugger_initialize_flag;
-
 namespace {
 class DiagnosticEventTest : public ::testing::Test {
 public:
@@ -35,7 +34,7 @@ class DiagnosticEventTest : public ::testing::Test {
 FileSystem::Initialize();
 HostInfo::Initialize();
 PlatformMacOSX::Initialize();
-std::call_once(debugger_initialize_flag,
+std::call_once(TestUtilities::g_debugger_initialize_flag,
[]() { Debugger::Initialize(nullptr); });
 ArchSpec arch("x86_64-apple-macosx-");
 Platform::SetHostPlatform(



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


[Lldb-commits] [lldb] [lldb][unittest] Use shared once_flag in DiagnosticEventTest (PR #80788)

2024-02-06 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova closed 
https://github.com/llvm/llvm-project/pull/80788
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [clang-tools-extra] [libcxx] [libc] [compiler-rt] [llvm] [mlir] [flang] [lldb] [lld] fix vulnerabilities (PR #79697)

2024-02-06 Thread via lldb-commits

https://github.com/gitworkflows updated 
https://github.com/llvm/llvm-project/pull/79697

>From f7b4f61db6016a1a02d775efc1e921fac785e823 Mon Sep 17 00:00:00 2001
From: snyk-bot 
Date: Fri, 19 Jan 2024 07:12:22 +
Subject: [PATCH 1/6] feat: upgrade vscode-languageclient from 8.0.2-next.5 to
 9.0.1

Snyk has created this PR to upgrade vscode-languageclient from 8.0.2-next.5 to 
9.0.1.

See this package in npm:
https://www.npmjs.com/package/vscode-languageclient

See this project in Snyk:
https://app.snyk.io/org/gitaction-log4j/project/a71a1b94-9555-4c53-b459-4ef6c4d3545e?utm_source=github&utm_medium=referral&page=upgrade-pr
---
 mlir/utils/vscode/package-lock.json | 117 +++-
 mlir/utils/vscode/package.json  |   2 +-
 2 files changed, 80 insertions(+), 39 deletions(-)

diff --git a/mlir/utils/vscode/package-lock.json 
b/mlir/utils/vscode/package-lock.json
index c93f6167c80a1..7d573b63fcca1 100644
--- a/mlir/utils/vscode/package-lock.json
+++ b/mlir/utils/vscode/package-lock.json
@@ -10,7 +10,7 @@
   "dependencies": {
 "base64-js": "^1.5.1",
 "chokidar": "3.5.2",
-"vscode-languageclient": "^8.0.2-next.5"
+"vscode-languageclient": "^9.0.1"
   },
   "devDependencies": {
 "@types/mocha": "^7.0.2",
@@ -279,6 +279,7 @@
   "version": "1.1.11",
   "resolved": 
"https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz";,
   "integrity": 
"sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
+  "dev": true,
   "dependencies": {
 "balanced-match": "^1.0.0",
 "concat-map": "0.0.1"
@@ -509,7 +510,8 @@
 "node_modules/concat-map": {
   "version": "0.0.1",
   "resolved": 
"https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz";,
-  "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
+  "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
+  "dev": true
 },
 "node_modules/console-control-strings": {
   "version": "1.1.0",
@@ -1198,6 +1200,7 @@
   "version": "3.0.4",
   "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz";,
   "integrity": 
"sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
+  "dev": true,
   "dependencies": {
 "brace-expansion": "^1.1.7"
   },
@@ -1881,24 +1884,43 @@
   "dev": true
 },
 "node_modules/vscode-jsonrpc": {
-  "version": "8.0.2-next.1",
-  "resolved": 
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.2-next.1.tgz";,
-  "integrity": 
"sha512-sbbvGSWja7NVBLHPGawtgezc8DHYJaP4qfr/AaJiyDapWcSFtHyPtm18+LnYMLTmB7bhOUW/lf5PeeuLpP6bKA==",
+  "version": "8.2.0",
+  "resolved": 
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.2.0.tgz";,
+  "integrity": 
"sha512-C+r0eKJUIfiDIfwJhria30+TYWPtuHJXHtI7J0YlOmKAo7ogxP20T0zxB7HZQIFhIyvoBPwWskjxrvAtfjyZfA==",
   "engines": {
 "node": ">=14.0.0"
   }
 },
 "node_modules/vscode-languageclient": {
-  "version": "8.0.2-next.5",
-  "resolved": 
"https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.2-next.5.tgz";,
-  "integrity": 
"sha512-g87RJLHz0XlRyk6DOTbAk4JHcj8CKggXy4JiFL7OlhETkcYzTOR8d+Qdb4GqZr37PDs1Cl21omtTNK5LyR/RQg==",
+  "version": "9.0.1",
+  "resolved": 
"https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-9.0.1.tgz";,
+  "integrity": 
"sha512-JZiimVdvimEuHh5olxhxkht09m3JzUGwggb5eRUkzzJhZ2KjCN0nh55VfiED9oez9DyF8/fz1g1iBV3h+0Z2EA==",
   "dependencies": {
-"minimatch": "^3.0.4",
-"semver": "^7.3.5",
-"vscode-languageserver-protocol": "3.17.2-next.6"
+"minimatch": "^5.1.0",
+"semver": "^7.3.7",
+"vscode-languageserver-protocol": "3.17.5"
   },
   "engines": {
-"vscode": "^1.67.0"
+"vscode": "^1.82.0"
+  }
+},
+"node_modules/vscode-languageclient/node_modules/brace-expansion": {
+  "version": "2.0.1",
+  "resolved": 
"https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz";,
+  "integrity": 
"sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
+  "dependencies": {
+"balanced-match": "^1.0.0"
+  }
+},
+"node_modules/vscode-languageclient/node_modules/minimatch": {
+  "version": "5.1.6",
+  "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz";,
+  "integrity": 
"sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
+  "dependencies": {
+"brace-expansion": "^2.0.1"
+  },
+  "engines": {
+"node": ">=10"
   }
 },
 "node_modules/vscode-languageclient/node_modules/semver": {
@@ -1916,18 +1938,18 @@
   }
 },
 "node_modules/vscode-languageserver-protocol": {
-  "version": "3.17.2-next.6",
-  "

[Lldb-commits] [clang] [clang-tools-extra] [libcxx] [libc] [compiler-rt] [llvm] [mlir] [flang] [lldb] [lld] fix vulnerabilities (PR #79697)

2024-02-06 Thread via lldb-commits

https://github.com/gitworkflows updated 
https://github.com/llvm/llvm-project/pull/79697

>From f7b4f61db6016a1a02d775efc1e921fac785e823 Mon Sep 17 00:00:00 2001
From: snyk-bot 
Date: Fri, 19 Jan 2024 07:12:22 +
Subject: [PATCH 1/7] feat: upgrade vscode-languageclient from 8.0.2-next.5 to
 9.0.1

Snyk has created this PR to upgrade vscode-languageclient from 8.0.2-next.5 to 
9.0.1.

See this package in npm:
https://www.npmjs.com/package/vscode-languageclient

See this project in Snyk:
https://app.snyk.io/org/gitaction-log4j/project/a71a1b94-9555-4c53-b459-4ef6c4d3545e?utm_source=github&utm_medium=referral&page=upgrade-pr
---
 mlir/utils/vscode/package-lock.json | 117 +++-
 mlir/utils/vscode/package.json  |   2 +-
 2 files changed, 80 insertions(+), 39 deletions(-)

diff --git a/mlir/utils/vscode/package-lock.json 
b/mlir/utils/vscode/package-lock.json
index c93f6167c80a1..7d573b63fcca1 100644
--- a/mlir/utils/vscode/package-lock.json
+++ b/mlir/utils/vscode/package-lock.json
@@ -10,7 +10,7 @@
   "dependencies": {
 "base64-js": "^1.5.1",
 "chokidar": "3.5.2",
-"vscode-languageclient": "^8.0.2-next.5"
+"vscode-languageclient": "^9.0.1"
   },
   "devDependencies": {
 "@types/mocha": "^7.0.2",
@@ -279,6 +279,7 @@
   "version": "1.1.11",
   "resolved": 
"https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz";,
   "integrity": 
"sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
+  "dev": true,
   "dependencies": {
 "balanced-match": "^1.0.0",
 "concat-map": "0.0.1"
@@ -509,7 +510,8 @@
 "node_modules/concat-map": {
   "version": "0.0.1",
   "resolved": 
"https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz";,
-  "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
+  "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
+  "dev": true
 },
 "node_modules/console-control-strings": {
   "version": "1.1.0",
@@ -1198,6 +1200,7 @@
   "version": "3.0.4",
   "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz";,
   "integrity": 
"sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
+  "dev": true,
   "dependencies": {
 "brace-expansion": "^1.1.7"
   },
@@ -1881,24 +1884,43 @@
   "dev": true
 },
 "node_modules/vscode-jsonrpc": {
-  "version": "8.0.2-next.1",
-  "resolved": 
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.2-next.1.tgz";,
-  "integrity": 
"sha512-sbbvGSWja7NVBLHPGawtgezc8DHYJaP4qfr/AaJiyDapWcSFtHyPtm18+LnYMLTmB7bhOUW/lf5PeeuLpP6bKA==",
+  "version": "8.2.0",
+  "resolved": 
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.2.0.tgz";,
+  "integrity": 
"sha512-C+r0eKJUIfiDIfwJhria30+TYWPtuHJXHtI7J0YlOmKAo7ogxP20T0zxB7HZQIFhIyvoBPwWskjxrvAtfjyZfA==",
   "engines": {
 "node": ">=14.0.0"
   }
 },
 "node_modules/vscode-languageclient": {
-  "version": "8.0.2-next.5",
-  "resolved": 
"https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.2-next.5.tgz";,
-  "integrity": 
"sha512-g87RJLHz0XlRyk6DOTbAk4JHcj8CKggXy4JiFL7OlhETkcYzTOR8d+Qdb4GqZr37PDs1Cl21omtTNK5LyR/RQg==",
+  "version": "9.0.1",
+  "resolved": 
"https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-9.0.1.tgz";,
+  "integrity": 
"sha512-JZiimVdvimEuHh5olxhxkht09m3JzUGwggb5eRUkzzJhZ2KjCN0nh55VfiED9oez9DyF8/fz1g1iBV3h+0Z2EA==",
   "dependencies": {
-"minimatch": "^3.0.4",
-"semver": "^7.3.5",
-"vscode-languageserver-protocol": "3.17.2-next.6"
+"minimatch": "^5.1.0",
+"semver": "^7.3.7",
+"vscode-languageserver-protocol": "3.17.5"
   },
   "engines": {
-"vscode": "^1.67.0"
+"vscode": "^1.82.0"
+  }
+},
+"node_modules/vscode-languageclient/node_modules/brace-expansion": {
+  "version": "2.0.1",
+  "resolved": 
"https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz";,
+  "integrity": 
"sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
+  "dependencies": {
+"balanced-match": "^1.0.0"
+  }
+},
+"node_modules/vscode-languageclient/node_modules/minimatch": {
+  "version": "5.1.6",
+  "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz";,
+  "integrity": 
"sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
+  "dependencies": {
+"brace-expansion": "^2.0.1"
+  },
+  "engines": {
+"node": ">=10"
   }
 },
 "node_modules/vscode-languageclient/node_modules/semver": {
@@ -1916,18 +1938,18 @@
   }
 },
 "node_modules/vscode-languageserver-protocol": {
-  "version": "3.17.2-next.6",
-  "

[Lldb-commits] [clang-tools-extra] [lldb] [libc] [clang] [flang] [libcxx] [llvm] [compiler-rt] [mlir] [lld] fix vulnerabilities (PR #79697)

2024-02-06 Thread via lldb-commits

https://github.com/gitworkflows updated 
https://github.com/llvm/llvm-project/pull/79697

>From f7b4f61db6016a1a02d775efc1e921fac785e823 Mon Sep 17 00:00:00 2001
From: snyk-bot 
Date: Fri, 19 Jan 2024 07:12:22 +
Subject: [PATCH 1/8] feat: upgrade vscode-languageclient from 8.0.2-next.5 to
 9.0.1

Snyk has created this PR to upgrade vscode-languageclient from 8.0.2-next.5 to 
9.0.1.

See this package in npm:
https://www.npmjs.com/package/vscode-languageclient

See this project in Snyk:
https://app.snyk.io/org/gitaction-log4j/project/a71a1b94-9555-4c53-b459-4ef6c4d3545e?utm_source=github&utm_medium=referral&page=upgrade-pr
---
 mlir/utils/vscode/package-lock.json | 117 +++-
 mlir/utils/vscode/package.json  |   2 +-
 2 files changed, 80 insertions(+), 39 deletions(-)

diff --git a/mlir/utils/vscode/package-lock.json 
b/mlir/utils/vscode/package-lock.json
index c93f6167c80a1..7d573b63fcca1 100644
--- a/mlir/utils/vscode/package-lock.json
+++ b/mlir/utils/vscode/package-lock.json
@@ -10,7 +10,7 @@
   "dependencies": {
 "base64-js": "^1.5.1",
 "chokidar": "3.5.2",
-"vscode-languageclient": "^8.0.2-next.5"
+"vscode-languageclient": "^9.0.1"
   },
   "devDependencies": {
 "@types/mocha": "^7.0.2",
@@ -279,6 +279,7 @@
   "version": "1.1.11",
   "resolved": 
"https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz";,
   "integrity": 
"sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
+  "dev": true,
   "dependencies": {
 "balanced-match": "^1.0.0",
 "concat-map": "0.0.1"
@@ -509,7 +510,8 @@
 "node_modules/concat-map": {
   "version": "0.0.1",
   "resolved": 
"https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz";,
-  "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
+  "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
+  "dev": true
 },
 "node_modules/console-control-strings": {
   "version": "1.1.0",
@@ -1198,6 +1200,7 @@
   "version": "3.0.4",
   "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz";,
   "integrity": 
"sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
+  "dev": true,
   "dependencies": {
 "brace-expansion": "^1.1.7"
   },
@@ -1881,24 +1884,43 @@
   "dev": true
 },
 "node_modules/vscode-jsonrpc": {
-  "version": "8.0.2-next.1",
-  "resolved": 
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.2-next.1.tgz";,
-  "integrity": 
"sha512-sbbvGSWja7NVBLHPGawtgezc8DHYJaP4qfr/AaJiyDapWcSFtHyPtm18+LnYMLTmB7bhOUW/lf5PeeuLpP6bKA==",
+  "version": "8.2.0",
+  "resolved": 
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.2.0.tgz";,
+  "integrity": 
"sha512-C+r0eKJUIfiDIfwJhria30+TYWPtuHJXHtI7J0YlOmKAo7ogxP20T0zxB7HZQIFhIyvoBPwWskjxrvAtfjyZfA==",
   "engines": {
 "node": ">=14.0.0"
   }
 },
 "node_modules/vscode-languageclient": {
-  "version": "8.0.2-next.5",
-  "resolved": 
"https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.2-next.5.tgz";,
-  "integrity": 
"sha512-g87RJLHz0XlRyk6DOTbAk4JHcj8CKggXy4JiFL7OlhETkcYzTOR8d+Qdb4GqZr37PDs1Cl21omtTNK5LyR/RQg==",
+  "version": "9.0.1",
+  "resolved": 
"https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-9.0.1.tgz";,
+  "integrity": 
"sha512-JZiimVdvimEuHh5olxhxkht09m3JzUGwggb5eRUkzzJhZ2KjCN0nh55VfiED9oez9DyF8/fz1g1iBV3h+0Z2EA==",
   "dependencies": {
-"minimatch": "^3.0.4",
-"semver": "^7.3.5",
-"vscode-languageserver-protocol": "3.17.2-next.6"
+"minimatch": "^5.1.0",
+"semver": "^7.3.7",
+"vscode-languageserver-protocol": "3.17.5"
   },
   "engines": {
-"vscode": "^1.67.0"
+"vscode": "^1.82.0"
+  }
+},
+"node_modules/vscode-languageclient/node_modules/brace-expansion": {
+  "version": "2.0.1",
+  "resolved": 
"https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz";,
+  "integrity": 
"sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
+  "dependencies": {
+"balanced-match": "^1.0.0"
+  }
+},
+"node_modules/vscode-languageclient/node_modules/minimatch": {
+  "version": "5.1.6",
+  "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz";,
+  "integrity": 
"sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
+  "dependencies": {
+"brace-expansion": "^2.0.1"
+  },
+  "engines": {
+"node": ">=10"
   }
 },
 "node_modules/vscode-languageclient/node_modules/semver": {
@@ -1916,18 +1938,18 @@
   }
 },
 "node_modules/vscode-languageserver-protocol": {
-  "version": "3.17.2-next.6",
-  "

[Lldb-commits] [clang-tools-extra] [lldb] [libc] [clang] [flang] [libcxx] [llvm] [compiler-rt] [mlir] [lld] fix vulnerabilities (PR #79697)

2024-02-06 Thread via lldb-commits

https://github.com/gitworkflows updated 
https://github.com/llvm/llvm-project/pull/79697

>From f7b4f61db6016a1a02d775efc1e921fac785e823 Mon Sep 17 00:00:00 2001
From: snyk-bot 
Date: Fri, 19 Jan 2024 07:12:22 +
Subject: [PATCH 1/9] feat: upgrade vscode-languageclient from 8.0.2-next.5 to
 9.0.1

Snyk has created this PR to upgrade vscode-languageclient from 8.0.2-next.5 to 
9.0.1.

See this package in npm:
https://www.npmjs.com/package/vscode-languageclient

See this project in Snyk:
https://app.snyk.io/org/gitaction-log4j/project/a71a1b94-9555-4c53-b459-4ef6c4d3545e?utm_source=github&utm_medium=referral&page=upgrade-pr
---
 mlir/utils/vscode/package-lock.json | 117 +++-
 mlir/utils/vscode/package.json  |   2 +-
 2 files changed, 80 insertions(+), 39 deletions(-)

diff --git a/mlir/utils/vscode/package-lock.json 
b/mlir/utils/vscode/package-lock.json
index c93f6167c80a1..7d573b63fcca1 100644
--- a/mlir/utils/vscode/package-lock.json
+++ b/mlir/utils/vscode/package-lock.json
@@ -10,7 +10,7 @@
   "dependencies": {
 "base64-js": "^1.5.1",
 "chokidar": "3.5.2",
-"vscode-languageclient": "^8.0.2-next.5"
+"vscode-languageclient": "^9.0.1"
   },
   "devDependencies": {
 "@types/mocha": "^7.0.2",
@@ -279,6 +279,7 @@
   "version": "1.1.11",
   "resolved": 
"https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz";,
   "integrity": 
"sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
+  "dev": true,
   "dependencies": {
 "balanced-match": "^1.0.0",
 "concat-map": "0.0.1"
@@ -509,7 +510,8 @@
 "node_modules/concat-map": {
   "version": "0.0.1",
   "resolved": 
"https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz";,
-  "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
+  "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
+  "dev": true
 },
 "node_modules/console-control-strings": {
   "version": "1.1.0",
@@ -1198,6 +1200,7 @@
   "version": "3.0.4",
   "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz";,
   "integrity": 
"sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
+  "dev": true,
   "dependencies": {
 "brace-expansion": "^1.1.7"
   },
@@ -1881,24 +1884,43 @@
   "dev": true
 },
 "node_modules/vscode-jsonrpc": {
-  "version": "8.0.2-next.1",
-  "resolved": 
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.2-next.1.tgz";,
-  "integrity": 
"sha512-sbbvGSWja7NVBLHPGawtgezc8DHYJaP4qfr/AaJiyDapWcSFtHyPtm18+LnYMLTmB7bhOUW/lf5PeeuLpP6bKA==",
+  "version": "8.2.0",
+  "resolved": 
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.2.0.tgz";,
+  "integrity": 
"sha512-C+r0eKJUIfiDIfwJhria30+TYWPtuHJXHtI7J0YlOmKAo7ogxP20T0zxB7HZQIFhIyvoBPwWskjxrvAtfjyZfA==",
   "engines": {
 "node": ">=14.0.0"
   }
 },
 "node_modules/vscode-languageclient": {
-  "version": "8.0.2-next.5",
-  "resolved": 
"https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.2-next.5.tgz";,
-  "integrity": 
"sha512-g87RJLHz0XlRyk6DOTbAk4JHcj8CKggXy4JiFL7OlhETkcYzTOR8d+Qdb4GqZr37PDs1Cl21omtTNK5LyR/RQg==",
+  "version": "9.0.1",
+  "resolved": 
"https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-9.0.1.tgz";,
+  "integrity": 
"sha512-JZiimVdvimEuHh5olxhxkht09m3JzUGwggb5eRUkzzJhZ2KjCN0nh55VfiED9oez9DyF8/fz1g1iBV3h+0Z2EA==",
   "dependencies": {
-"minimatch": "^3.0.4",
-"semver": "^7.3.5",
-"vscode-languageserver-protocol": "3.17.2-next.6"
+"minimatch": "^5.1.0",
+"semver": "^7.3.7",
+"vscode-languageserver-protocol": "3.17.5"
   },
   "engines": {
-"vscode": "^1.67.0"
+"vscode": "^1.82.0"
+  }
+},
+"node_modules/vscode-languageclient/node_modules/brace-expansion": {
+  "version": "2.0.1",
+  "resolved": 
"https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz";,
+  "integrity": 
"sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
+  "dependencies": {
+"balanced-match": "^1.0.0"
+  }
+},
+"node_modules/vscode-languageclient/node_modules/minimatch": {
+  "version": "5.1.6",
+  "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz";,
+  "integrity": 
"sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
+  "dependencies": {
+"brace-expansion": "^2.0.1"
+  },
+  "engines": {
+"node": ">=10"
   }
 },
 "node_modules/vscode-languageclient/node_modules/semver": {
@@ -1916,18 +1938,18 @@
   }
 },
 "node_modules/vscode-languageserver-protocol": {
-  "version": "3.17.2-next.6",
-  "

[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread via lldb-commits

https://github.com/kusmour updated 
https://github.com/llvm/llvm-project/pull/80745

>From 4e06a3ebcf12de413f0906b1f4f6aaca40bedcff Mon Sep 17 00:00:00 2001
From: Wanyi Ye 
Date: Fri, 2 Feb 2024 15:42:01 -0800
Subject: [PATCH 1/4] Support statistics dump summary only mode

Summary:
Added a new --summary option to statistics dump command so that it is much 
light weight than the full version.
With this change, statistics dump --summary can now be included in lldb command 
line telemetry without slowing down lldb exiting.
---
 lldb/include/lldb/API/SBTarget.h  |   8 +-
 lldb/include/lldb/Target/Statistics.h |   9 +-
 lldb/include/lldb/Target/Target.h |   2 +-
 lldb/source/API/SBTarget.cpp  |   9 +-
 lldb/source/Commands/CommandObjectStats.cpp   |   8 +-
 lldb/source/Commands/Options.td   |   3 +
 lldb/source/Target/Statistics.cpp | 194 +++---
 lldb/source/Target/Target.cpp |   4 +-
 .../stats_api/TestStatisticsAPI.py|  15 ++
 9 files changed, 164 insertions(+), 88 deletions(-)

diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 83087623088c5..7fd888cf7014e 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -86,9 +86,13 @@ class LLDB_API SBTarget {
 
   /// Returns a dump of the collected statistics.
   ///
+  /// \param[in] summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// A SBStructuredData with the statistics collected.
-  lldb::SBStructuredData GetStatistics();
+  lldb::SBStructuredData GetStatistics(bool summary_only = false);
 
   /// Return the platform object associated with the target.
   ///
@@ -326,7 +330,7 @@ class LLDB_API SBTarget {
   uint32_t GetAddressByteSize();
 
   const char *GetTriple();
-  
+
   const char *GetABIName();
 
   const char *GetLabel() const;
diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index f672786f58f84..98658ba0cac31 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,7 +133,7 @@ struct ConstStringStats {
 /// A class that represents statistics for a since lldb_private::Target.
 class TargetStats {
 public:
-  llvm::json::Value ToJSON(Target &target);
+  llvm::json::Value ToJSON(Target &target, bool summary_only = false);
 
   void SetLaunchOrAttachTime();
   void SetFirstPrivateStopTime();
@@ -171,9 +171,14 @@ class DebuggerStats {
   ///   The single target to emit statistics for if non NULL, otherwise dump
   ///   statistics only for the specified target.
   ///
+  /// \param summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  static llvm::json::Value ReportStatistics(Debugger &debugger, Target 
*target);
+  static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target,
+bool summary_only = false);
 
 protected:
   // Collecting stats can be set to true to collect stats that are expensive
diff --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index c37682e2a0385..4bf6c123dc1dd 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1599,7 +1599,7 @@ class Target : public 
std::enable_shared_from_this,
   ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  llvm::json::Value ReportStatistics();
+  llvm::json::Value ReportStatistics(bool summary_only = false);
 
   TargetStats &GetStatistics() { return m_stats; }
 
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 8e616afbcb4e8..615a00ceeaee1 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -197,7 +197,7 @@ SBDebugger SBTarget::GetDebugger() const {
   return debugger;
 }
 
-SBStructuredData SBTarget::GetStatistics() {
+SBStructuredData SBTarget::GetStatistics(bool summary_only) {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData data;
@@ -205,9 +205,10 @@ SBStructuredData SBTarget::GetStatistics() {
   if (!target_sp)
 return data;
   std::string json_str =
-  llvm::formatv("{0:2}",
-  DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
-  target_sp.get())).str();
+  llvm::formatv(
+  "{0:2}", DebuggerStats::ReportStatistics(
+   target_sp->GetDebugger(), target_sp.get(), 
summary_only))
+  .str();
   data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
   return data;
 }
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 262de0bda144a..781b90794dc37 100644
--- a/lldb/so

[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread via lldb-commits

https://github.com/kusmour updated 
https://github.com/llvm/llvm-project/pull/80745

>From be36537cfc647735a823b685ab89ca68d1ae9803 Mon Sep 17 00:00:00 2001
From: Wanyi Ye 
Date: Fri, 2 Feb 2024 15:42:01 -0800
Subject: [PATCH 1/4] Support statistics dump summary only mode

Summary:
Added a new --summary option to statistics dump command so that it is much 
light weight than the full version.
With this change, statistics dump --summary can now be included in lldb command 
line telemetry without slowing down lldb exiting.
---
 lldb/include/lldb/API/SBTarget.h  |   6 +-
 lldb/include/lldb/Target/Statistics.h |   9 +-
 lldb/include/lldb/Target/Target.h |   2 +-
 lldb/source/API/SBTarget.cpp  |   9 +-
 lldb/source/Commands/CommandObjectStats.cpp   |   8 +-
 lldb/source/Commands/Options.td   |   3 +
 lldb/source/Target/Statistics.cpp | 194 +++---
 lldb/source/Target/Target.cpp |   4 +-
 .../stats_api/TestStatisticsAPI.py|  15 ++
 9 files changed, 163 insertions(+), 87 deletions(-)

diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 83087623088c5..72b8997afd270 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -86,9 +86,13 @@ class LLDB_API SBTarget {
 
   /// Returns a dump of the collected statistics.
   ///
+  /// \param[in] summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// A SBStructuredData with the statistics collected.
-  lldb::SBStructuredData GetStatistics();
+  lldb::SBStructuredData GetStatistics(bool summary_only = false);
 
   /// Return the platform object associated with the target.
   ///
diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index f672786f58f84..98658ba0cac31 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,7 +133,7 @@ struct ConstStringStats {
 /// A class that represents statistics for a since lldb_private::Target.
 class TargetStats {
 public:
-  llvm::json::Value ToJSON(Target &target);
+  llvm::json::Value ToJSON(Target &target, bool summary_only = false);
 
   void SetLaunchOrAttachTime();
   void SetFirstPrivateStopTime();
@@ -171,9 +171,14 @@ class DebuggerStats {
   ///   The single target to emit statistics for if non NULL, otherwise dump
   ///   statistics only for the specified target.
   ///
+  /// \param summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  static llvm::json::Value ReportStatistics(Debugger &debugger, Target 
*target);
+  static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target,
+bool summary_only = false);
 
 protected:
   // Collecting stats can be set to true to collect stats that are expensive
diff --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index c37682e2a0385..4bf6c123dc1dd 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1599,7 +1599,7 @@ class Target : public 
std::enable_shared_from_this,
   ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  llvm::json::Value ReportStatistics();
+  llvm::json::Value ReportStatistics(bool summary_only = false);
 
   TargetStats &GetStatistics() { return m_stats; }
 
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 8e616afbcb4e8..615a00ceeaee1 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -197,7 +197,7 @@ SBDebugger SBTarget::GetDebugger() const {
   return debugger;
 }
 
-SBStructuredData SBTarget::GetStatistics() {
+SBStructuredData SBTarget::GetStatistics(bool summary_only) {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData data;
@@ -205,9 +205,10 @@ SBStructuredData SBTarget::GetStatistics() {
   if (!target_sp)
 return data;
   std::string json_str =
-  llvm::formatv("{0:2}",
-  DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
-  target_sp.get())).str();
+  llvm::formatv(
+  "{0:2}", DebuggerStats::ReportStatistics(
+   target_sp->GetDebugger(), target_sp.get(), 
summary_only))
+  .str();
   data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
   return data;
 }
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 262de0bda144a..781b90794dc37 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -75,6 +75,9 @@ class CommandObjectStatsDump : public CommandObjectParsed {
   case 'a'

[Lldb-commits] [libcxx] [compiler-rt] [llvm] [libc] [lldb] [lld] [flang] [mlir] [clang] [mlir][sparse] Implement parsing n out of m (PR #79935)

2024-02-06 Thread Yinying Li via lldb-commits

https://github.com/yinying-lisa-li updated 
https://github.com/llvm/llvm-project/pull/79935

>From b4610de041d1fd9c362a4155ee50325c738eebda Mon Sep 17 00:00:00 2001
From: Yinying Li 
Date: Tue, 30 Jan 2024 01:01:52 +
Subject: [PATCH 01/13] [mlir][sparse] Expand LevelType to 64 bit and implement
 n out of m

---
 mlir/include/mlir-c/Dialect/SparseTensor.h|  28 +--
 .../mlir/Dialect/SparseTensor/IR/Enums.h  | 209 +++---
 .../SparseTensor/IR/SparseTensorAttrDefs.td   |   4 +-
 .../SparseTensor/IR/SparseTensorType.h|   2 +-
 .../mlir/Dialect/SparseTensor/Utils/Merger.h  |   2 +-
 .../ExecutionEngine/SparseTensor/Storage.h|  14 +-
 .../Bindings/Python/DialectSparseTensor.cpp   |   2 +-
 mlir/lib/CAPI/Dialect/SparseTensor.cpp|  49 ++--
 .../IR/Detail/DimLvlMapParser.cpp |   2 +
 .../SparseTensor/IR/Detail/LvlTypeParser.cpp  |  55 -
 .../SparseTensor/IR/Detail/LvlTypeParser.h|   6 +-
 .../Transforms/SparseGPUCodegen.cpp   |   2 +-
 .../Transforms/SparseTensorCodegen.cpp|   6 +-
 .../Transforms/Sparsification.cpp |   2 +-
 .../Transforms/Utils/SparseTensorLevel.cpp|   2 +-
 .../lib/Dialect/SparseTensor/Utils/Merger.cpp |   4 +-
 .../ExecutionEngine/SparseTensor/Storage.cpp  |   2 +-
 mlir/test/CAPI/sparse_tensor.c|   6 +-
 .../SparseTensor/GPU/gpu_matmul24_lib.mlir|   2 +-
 .../SparseTensor/roundtrip_encoding.mlir  |  12 +-
 .../SparseTensor/sparse_fill_zero.mlir|   2 +-
 .../SparseTensor/CPU/sparse_block_matmul.mlir |   2 +-
 .../Dialect/SparseTensor/CPU/sparse_ds.mlir   |   2 +-
 .../CUDA/sm80-lt/sparse-matmul-2-4-lib.mlir   |   2 +-
 .../CUDA/sm80-lt/sparse-matmul-2-4-prune.mlir |   2 +-
 .../python/dialects/sparse_tensor/dialect.py  | 106 -
 26 files changed, 316 insertions(+), 211 deletions(-)

diff --git a/mlir/include/mlir-c/Dialect/SparseTensor.h 
b/mlir/include/mlir-c/Dialect/SparseTensor.h
index 42d8400cb5e95..947a746b60a65 100644
--- a/mlir/include/mlir-c/Dialect/SparseTensor.h
+++ b/mlir/include/mlir-c/Dialect/SparseTensor.h
@@ -28,20 +28,20 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(SparseTensor, 
sparse_tensor);
 typedef uint64_t MlirSparseTensorLevelType;
 
 enum MlirBaseSparseTensorLevelType {
-  MLIR_SPARSE_TENSOR_LEVEL_DENSE = 4,   // 0b1_00
-  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED = 8,  // 0b00010_00
-  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU = 9,   // 0b00010_01
-  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NO = 10,  // 0b00010_10
-  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU_NO = 11,   // 0b00010_11
-  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON = 16,  // 0b00100_00
-  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU = 17,   // 0b00100_01
-  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NO = 18,   // 0b00100_10
-  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU_NO = 19,// 0b00100_11
-  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED = 32,   // 0b01000_00
-  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU = 33,// 0b01000_01
-  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NO = 34,// 0b01000_10
-  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU_NO = 35, // 0b01000_11
-  MLIR_SPARSE_TENSOR_LEVEL_TWO_OUT_OF_FOUR = 64,// 0b1_00
+  MLIR_SPARSE_TENSOR_LEVEL_DENSE = 65536,   // 
0x00_00_0001_
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED = 131072, // 
0x00_00_0002_
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU = 131073,  // 
0x00_00_0002_0001
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NO = 131074,  // 
0x00_00_0002_0002
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU_NO = 131075,   // 
0x00_00_0002_0003
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON = 262144,  // 
0x00_00_0004_
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU = 262145,   // 
0x00_00_0004_0001
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NO = 262146,   // 
0x00_00_0004_0002
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU_NO = 262147,// 
0x00_00_0004_0003
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED = 524288,   // 
0x00_00_0008_
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU = 524289,// 
0x00_00_0008_0001
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NO = 524290,// 
0x00_00_0008_0002
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU_NO = 524291, // 
0x00_00_0008_0003
+  MLIR_SPARSE_TENSOR_LEVEL_N_OUT_OF_M = 1048576,// 
0x00_00_0010_
 };
 
 
//===--===//
diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h 
b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
index 1f662e2042304..b70ac57dfd00a 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
@@ -154,9 +154,10 @@ enum class Action : uint32_t {
 
 /// This enum defines all the sparse representations supportable by
 /// the SparseTensor dialect. We use a lightweight encoding to encode
-/// both the "

[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/80890

LLDB has a setting (symbols.enable-background-lookup) that calls dsymForUUID on 
a background thread for images as they appear in the current backtrace. 
Originally, the laziness of only looking up symbols for images in the backtrace 
only existed to bring the number of dsymForUUID calls down to a manageable 
number.

Users have requesting the same functionality but blocking. This gives them the 
same user experience as enabling dsymForUUID globally, but without the massive 
upfront cost of having to download all the images, the majority of which 
they'll likely not need.

This patch renames the setting to have a more generic name 
(symbols.lazy-lookup) and changes its values from a boolean to an enum. Users 
can now specify lazy-lookup as "off", "background" and "foreground". The 
default remains "off" although I'll probably change that in the near future.

>From 3b1818b83c18e50e1ad3f0db06089349b8525f6c Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 6 Feb 2024 10:07:12 -0800
Subject: [PATCH] [lldb] Expand background symbol lookup

LLDB has a setting (symbols.enable-background-lookup) that calls dsymForUUID on
a background thread for images as they appear in the current backtrace.
Originally, the laziness of only looking up symbols for images in the
backtrace only existed to bring the number of dsymForUUID calls down to
a manageable number.

Users have requesting the same functionality but blocking. This gives
them the same user experience as enabling dsymForUUID globally, but
without the massive upfront cost of having to download all the images,
the majority of which they'll likely not need.

This patch renames the setting to have a more generic name
(symbols.lazy-lookup) and changes its values from a boolean to an enum.
Users can now specify lazy-lookup as "off", "background" and
"foreground". The default remains "off" although I'll probably change
that in the near future.
---
 lldb/include/lldb/Core/ModuleList.h   | 23 ++-
 lldb/include/lldb/lldb-enumerations.h |  6 ++
 lldb/source/Core/CoreProperties.td|  7 ---
 lldb/source/Core/ModuleList.cpp   |  9 +
 lldb/source/Symbol/SymbolLocator.cpp  | 19 ++-
 5 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/lldb/include/lldb/Core/ModuleList.h 
b/lldb/include/lldb/Core/ModuleList.h
index d78f7c5ef3f706..5c19cbc1e799c7 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -47,6 +47,26 @@ class UUID;
 class VariableList;
 struct ModuleFunctionSearchOptions;
 
+static constexpr OptionEnumValueElement g_lazy_lookup_enum_values[] = {
+{
+lldb::eLazyLookupOff,
+"off",
+"Disable lazy symbol lookup.",
+},
+{
+lldb::eLazyLookupBackground,
+"background",
+"Lazily look up symbols in the background without blocking the "
+"debugger.",
+},
+{
+lldb::eLazyLookupForeground,
+"foreground",
+"Lazily look up symbols in the foreground and block the debugger until 
"
+"they're found.",
+},
+};
+
 class ModuleListProperties : public Properties {
   mutable llvm::sys::RWMutex m_symlink_paths_mutex;
   PathMappingList m_symlink_paths;
@@ -60,7 +80,6 @@ class ModuleListProperties : public Properties {
   bool SetClangModulesCachePath(const FileSpec &path);
   bool GetEnableExternalLookup() const;
   bool SetEnableExternalLookup(bool new_value);
-  bool GetEnableBackgroundLookup() const;
   bool GetEnableLLDBIndexCache() const;
   bool SetEnableLLDBIndexCache(bool new_value);
   uint64_t GetLLDBIndexCacheMaxByteSize();
@@ -71,6 +90,8 @@ class ModuleListProperties : public Properties {
 
   bool GetLoadSymbolOnDemand();
 
+  lldb::LazySymbolLookup GetLazySymbolLookup() const;
+
   PathMappingList GetSymlinkMappings() const;
 };
 
diff --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index 392d333c23a447..c1f9fab5244997 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -1305,6 +1305,12 @@ enum CompletionType {
   eTerminatorCompletion = (1ul << 27)
 };
 
+enum LazySymbolLookup {
+  eLazyLookupOff = 0,
+  eLazyLookupBackground = 1,
+  eLazyLookupForeground = 2,
+};
+
 } // namespace lldb
 
 #endif // LLDB_LLDB_ENUMERATIONS_H
diff --git a/lldb/source/Core/CoreProperties.td 
b/lldb/source/Core/CoreProperties.td
index 8d81967bdb50a4..fcf89bd412b844 100644
--- a/lldb/source/Core/CoreProperties.td
+++ b/lldb/source/Core/CoreProperties.td
@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
 Global,
 DefaultTrue,
 Desc<"Control the use of external tools and repositories to locate symbol 
files. Directories listed in target.debug-file-search-paths and directory of 
the executable are always checked first for separate debug info files. Then 
depending on this setting: On mac

[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

LLDB has a setting (symbols.enable-background-lookup) that calls dsymForUUID on 
a background thread for images as they appear in the current backtrace. 
Originally, the laziness of only looking up symbols for images in the backtrace 
only existed to bring the number of dsymForUUID calls down to a manageable 
number.

Users have requesting the same functionality but blocking. This gives them the 
same user experience as enabling dsymForUUID globally, but without the massive 
upfront cost of having to download all the images, the majority of which 
they'll likely not need.

This patch renames the setting to have a more generic name 
(symbols.lazy-lookup) and changes its values from a boolean to an enum. Users 
can now specify lazy-lookup as "off", "background" and "foreground". The 
default remains "off" although I'll probably change that in the near future.

---
Full diff: https://github.com/llvm/llvm-project/pull/80890.diff


5 Files Affected:

- (modified) lldb/include/lldb/Core/ModuleList.h (+22-1) 
- (modified) lldb/include/lldb/lldb-enumerations.h (+6) 
- (modified) lldb/source/Core/CoreProperties.td (+4-3) 
- (modified) lldb/source/Core/ModuleList.cpp (+5-4) 
- (modified) lldb/source/Symbol/SymbolLocator.cpp (+14-5) 


``diff
diff --git a/lldb/include/lldb/Core/ModuleList.h 
b/lldb/include/lldb/Core/ModuleList.h
index d78f7c5ef3f70..5c19cbc1e799c 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -47,6 +47,26 @@ class UUID;
 class VariableList;
 struct ModuleFunctionSearchOptions;
 
+static constexpr OptionEnumValueElement g_lazy_lookup_enum_values[] = {
+{
+lldb::eLazyLookupOff,
+"off",
+"Disable lazy symbol lookup.",
+},
+{
+lldb::eLazyLookupBackground,
+"background",
+"Lazily look up symbols in the background without blocking the "
+"debugger.",
+},
+{
+lldb::eLazyLookupForeground,
+"foreground",
+"Lazily look up symbols in the foreground and block the debugger until 
"
+"they're found.",
+},
+};
+
 class ModuleListProperties : public Properties {
   mutable llvm::sys::RWMutex m_symlink_paths_mutex;
   PathMappingList m_symlink_paths;
@@ -60,7 +80,6 @@ class ModuleListProperties : public Properties {
   bool SetClangModulesCachePath(const FileSpec &path);
   bool GetEnableExternalLookup() const;
   bool SetEnableExternalLookup(bool new_value);
-  bool GetEnableBackgroundLookup() const;
   bool GetEnableLLDBIndexCache() const;
   bool SetEnableLLDBIndexCache(bool new_value);
   uint64_t GetLLDBIndexCacheMaxByteSize();
@@ -71,6 +90,8 @@ class ModuleListProperties : public Properties {
 
   bool GetLoadSymbolOnDemand();
 
+  lldb::LazySymbolLookup GetLazySymbolLookup() const;
+
   PathMappingList GetSymlinkMappings() const;
 };
 
diff --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index 392d333c23a44..c1f9fab524499 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -1305,6 +1305,12 @@ enum CompletionType {
   eTerminatorCompletion = (1ul << 27)
 };
 
+enum LazySymbolLookup {
+  eLazyLookupOff = 0,
+  eLazyLookupBackground = 1,
+  eLazyLookupForeground = 2,
+};
+
 } // namespace lldb
 
 #endif // LLDB_LLDB_ENUMERATIONS_H
diff --git a/lldb/source/Core/CoreProperties.td 
b/lldb/source/Core/CoreProperties.td
index 8d81967bdb50a..fcf89bd412b84 100644
--- a/lldb/source/Core/CoreProperties.td
+++ b/lldb/source/Core/CoreProperties.td
@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
 Global,
 DefaultTrue,
 Desc<"Control the use of external tools and repositories to locate symbol 
files. Directories listed in target.debug-file-search-paths and directory of 
the executable are always checked first for separate debug info files. Then 
depending on this setting: On macOS, Spotlight would be also used to locate a 
matching .dSYM bundle based on the UUID of the executable. On NetBSD, directory 
/usr/libdata/debug would be also searched. On platforms other than NetBSD 
directory /usr/lib/debug would be also searched. If all other methods fail 
there may be symbol-locator plugins that, if configured properly, will also 
attempt to acquire symbols. The debuginfod plugin defaults to the 
DEGUFINFOD_URLS environment variable which is configurable through the 
'plugin.symbol-locator.debuginfod.server_urls' setting.">;
-  def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
+  def LazySymbolLookup: Property<"lazy-lookup", "Enum">,
 Global,
-DefaultFalse,
-Desc<"On macOS, enable calling dsymForUUID (or an equivalent 
script/binary) in the background to locate symbol files that weren't found.">;
+DefaultEnumValue<"eLazyLookupOff">,
+EnumValues<"OptionEnumValues(g_lazy_lookup_enum_values)">,
+Desc<"On macOS, lazily look

[Lldb-commits] [lldb] Fix a crasher when using the public API. (PR #80508)

2024-02-06 Thread via lldb-commits

https://github.com/kusmour requested changes to this pull request.

revert whitespace changes and we're good to go!

https://github.com/llvm/llvm-project/pull/80508
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Reland "[lldb][progress][NFC] Add unit test for progress reports" (PR #80791)

2024-02-06 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere approved this pull request.


https://github.com/llvm/llvm-project/pull/80791
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Reland "[lldb][progress][NFC] Add unit test for progress reports" (PR #80791)

2024-02-06 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova updated 
https://github.com/llvm/llvm-project/pull/80791

>From 4760c7ca48790f5f87de8e6ba2a5a3eea002 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova 
Date: Mon, 5 Feb 2024 19:00:52 -0800
Subject: [PATCH] Reland "[lldb][progress][NFC] Add unit test for progress
 reports"

This file was previously approved and merged from this PR:
https://github.com/llvm/llvm-project/pull/79533 but caused a test
failure on the Linux AArch64 bots due to hitting an assertion that
`Debugger::Initialize` was already called.

To fix this, this commit uses the
changes made here: https://github.com/llvm/llvm-project/pull/80786 to
use a shared call_once flag to initialize the debugger.
---
 lldb/unittests/Core/CMakeLists.txt |   1 +
 lldb/unittests/Core/ProgressReportTest.cpp | 128 +
 2 files changed, 129 insertions(+)
 create mode 100644 lldb/unittests/Core/ProgressReportTest.cpp

diff --git a/lldb/unittests/Core/CMakeLists.txt 
b/lldb/unittests/Core/CMakeLists.txt
index b3cddd150635b..d40c357e3f463 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -7,6 +7,7 @@ add_lldb_unittest(LLDBCoreTests
   FormatEntityTest.cpp
   MangledTest.cpp
   ModuleSpecTest.cpp
+  ProgressReportTest.cpp
   RichManglingContextTest.cpp
   SourceLocationSpecTest.cpp
   SourceManagerTest.cpp
diff --git a/lldb/unittests/Core/ProgressReportTest.cpp 
b/lldb/unittests/Core/ProgressReportTest.cpp
new file mode 100644
index 0..559f3ef1ae46b
--- /dev/null
+++ b/lldb/unittests/Core/ProgressReportTest.cpp
@@ -0,0 +1,128 @@
+//===-- ProgressReportTest.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/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/Listener.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+class ProgressReportTest : public ::testing::Test {
+  SubsystemRAII subsystems;
+
+  // The debugger's initialization function can't be called with no arguments
+  // so calling it using SubsystemRAII will cause the test build to fail as
+  // SubsystemRAII will call Initialize with no arguments. As such we set it up
+  // here the usual way.
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+  };
+};
+
+TEST_F(ProgressReportTest, TestReportCreation) {
+  std::chrono::milliseconds timeout(100);
+
+  // Set up the debugger, make sure that was done properly.
+  ArchSpec arch("x86_64-apple-macosx-");
+  Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+  DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+
+  // Get the debugger's broadcaster.
+  Broadcaster &broadcaster = debugger_sp->GetBroadcaster();
+
+  // Create a listener, make sure it can receive events and that it's
+  // listening to the correct broadcast bit.
+  ListenerSP listener_sp = Listener::MakeListener("progress-listener");
+
+  listener_sp->StartListeningForEvents(&broadcaster,
+   Debugger::eBroadcastBitProgress);
+  EXPECT_TRUE(
+  broadcaster.EventTypeHasListeners(Debugger::eBroadcastBitProgress));
+
+  EventSP event_sp;
+  const ProgressEventData *data;
+
+  // Scope this for RAII on the progress objects.
+  // Create progress reports and check that their respective events for having
+  // started and ended are broadcasted.
+  {
+Progress progress1("Progress report 1", "Starting report 1");
+Progress progress2("Progress report 2", "Starting report 2");
+Progress progress3("Progress report 3", "Starting report 3");
+  }
+
+  // Start popping events from the queue, they should have been recevied
+  // in this order:
+  // Starting progress: 1, 2, 3
+  // Ending progress: 3, 2, 1
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+
+  ASSERT_EQ(data->GetDetails(), "Starting report 1");
+  ASSERT_FALSE(data->IsFinite());
+  ASSERT_FALSE(data->GetCompleted());
+  ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
+  ASSERT_EQ(data->GetMessage(), "Progress report 1: Starting report 1");
+
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+
+  ASSERT_EQ(d

[Lldb-commits] [lldb] a8ab830 - Reland "[lldb][progress][NFC] Add unit test for progress reports" (#80791)

2024-02-06 Thread via lldb-commits

Author: Chelsea Cassanova
Date: 2024-02-06T10:56:41-08:00
New Revision: a8ab8306069e8e53b5148ceec7624d7d36ffb459

URL: 
https://github.com/llvm/llvm-project/commit/a8ab8306069e8e53b5148ceec7624d7d36ffb459
DIFF: 
https://github.com/llvm/llvm-project/commit/a8ab8306069e8e53b5148ceec7624d7d36ffb459.diff

LOG: Reland "[lldb][progress][NFC] Add unit test for progress reports" (#80791)

This file was previously approved and merged from this PR:
https://github.com/llvm/llvm-project/pull/79533 but caused a test
failure on the Linux AArch64 bots due to hitting an assertion that
`Debugger::Initialize` was already called.

To fix this, this commit uses the
changes made here: https://github.com/llvm/llvm-project/pull/80786 to
use a shared call_once flag to initialize the debugger.

Added: 
lldb/unittests/Core/ProgressReportTest.cpp

Modified: 
lldb/unittests/Core/CMakeLists.txt

Removed: 




diff  --git a/lldb/unittests/Core/CMakeLists.txt 
b/lldb/unittests/Core/CMakeLists.txt
index b3cddd150635b..d40c357e3f463 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -7,6 +7,7 @@ add_lldb_unittest(LLDBCoreTests
   FormatEntityTest.cpp
   MangledTest.cpp
   ModuleSpecTest.cpp
+  ProgressReportTest.cpp
   RichManglingContextTest.cpp
   SourceLocationSpecTest.cpp
   SourceManagerTest.cpp

diff  --git a/lldb/unittests/Core/ProgressReportTest.cpp 
b/lldb/unittests/Core/ProgressReportTest.cpp
new file mode 100644
index 0..559f3ef1ae46b
--- /dev/null
+++ b/lldb/unittests/Core/ProgressReportTest.cpp
@@ -0,0 +1,128 @@
+//===-- ProgressReportTest.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/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/Listener.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+class ProgressReportTest : public ::testing::Test {
+  SubsystemRAII subsystems;
+
+  // The debugger's initialization function can't be called with no arguments
+  // so calling it using SubsystemRAII will cause the test build to fail as
+  // SubsystemRAII will call Initialize with no arguments. As such we set it up
+  // here the usual way.
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+  };
+};
+
+TEST_F(ProgressReportTest, TestReportCreation) {
+  std::chrono::milliseconds timeout(100);
+
+  // Set up the debugger, make sure that was done properly.
+  ArchSpec arch("x86_64-apple-macosx-");
+  Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+  DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+
+  // Get the debugger's broadcaster.
+  Broadcaster &broadcaster = debugger_sp->GetBroadcaster();
+
+  // Create a listener, make sure it can receive events and that it's
+  // listening to the correct broadcast bit.
+  ListenerSP listener_sp = Listener::MakeListener("progress-listener");
+
+  listener_sp->StartListeningForEvents(&broadcaster,
+   Debugger::eBroadcastBitProgress);
+  EXPECT_TRUE(
+  broadcaster.EventTypeHasListeners(Debugger::eBroadcastBitProgress));
+
+  EventSP event_sp;
+  const ProgressEventData *data;
+
+  // Scope this for RAII on the progress objects.
+  // Create progress reports and check that their respective events for having
+  // started and ended are broadcasted.
+  {
+Progress progress1("Progress report 1", "Starting report 1");
+Progress progress2("Progress report 2", "Starting report 2");
+Progress progress3("Progress report 3", "Starting report 3");
+  }
+
+  // Start popping events from the queue, they should have been recevied
+  // in this order:
+  // Starting progress: 1, 2, 3
+  // Ending progress: 3, 2, 1
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+
+  ASSERT_EQ(data->GetDetails(), "Starting report 1");
+  ASSERT_FALSE(data->IsFinite());
+  ASSERT_FALSE(data->GetCompleted());
+  ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
+  ASSERT_EQ(data->GetMessage(), "Progress report 1: Starting report 1");
+
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::

[Lldb-commits] [lldb] Reland "[lldb][progress][NFC] Add unit test for progress reports" (PR #80791)

2024-02-06 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova closed 
https://github.com/llvm/llvm-project/pull/80791
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Alex Langford via lldb-commits


@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
 Global,
 DefaultTrue,
 Desc<"Control the use of external tools and repositories to locate symbol 
files. Directories listed in target.debug-file-search-paths and directory of 
the executable are always checked first for separate debug info files. Then 
depending on this setting: On macOS, Spotlight would be also used to locate a 
matching .dSYM bundle based on the UUID of the executable. On NetBSD, directory 
/usr/libdata/debug would be also searched. On platforms other than NetBSD 
directory /usr/lib/debug would be also searched. If all other methods fail 
there may be symbol-locator plugins that, if configured properly, will also 
attempt to acquire symbols. The debuginfod plugin defaults to the 
DEGUFINFOD_URLS environment variable which is configurable through the 
'plugin.symbol-locator.debuginfod.server_urls' setting.">;
-  def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
+  def LazySymbolLookup: Property<"lazy-lookup", "Enum">,

bulbazord wrote:

I think the name should probably be different. "LazySymbolLookup" being set to 
off makes me think it will look things up eagerly. Looking up the possible 
values of "off", "background", and "foreground" also don't really illustrate 
what they mean either.

I would propose the setting name "external-symbol-load-behavior" with the 
enumeration values "off", "background", and "blocking" or something to this 
effect.

https://github.com/llvm/llvm-project/pull/80890
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lld] [libc] [llvm] [compiler-rt] [clang] [flang] [Driver] Check the environment version except wasm case. (PR #80783)

2024-02-06 Thread via lldb-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/80783

>From 84506beecc20a064a5c895cf5c04135118da6606 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Tue, 6 Feb 2024 01:58:58 +
Subject: [PATCH] [Driver] Check the environment version except wasm case.

---
 clang/lib/Driver/Driver.cpp | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 29db9543f36553..04d02ea500d19f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1443,16 +1443,18 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain &TC = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  // Check if the environment version is valid.
-  llvm::Triple Triple = TC.getTriple();
-  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-  StringRef TripleObjectFormat =
-  Triple.getObjectFormatTypeName(Triple.getObjectFormat());
-  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
-  TripleVersionName != TripleObjectFormat) {
-Diags.Report(diag::err_drv_triple_version_invalid)
-<< TripleVersionName << TC.getTripleString();
-ContainsError = true;
+  // Check if the environment version is valid except wasm case.
+  if (!TC.getTriple().isWasm()) {
+llvm::Triple Triple = TC.getTriple();
+StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+StringRef TripleObjectFormat =
+Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
+TripleVersionName != TripleObjectFormat) {
+  Diags.Report(diag::err_drv_triple_version_invalid)
+  << TripleVersionName << TC.getTripleString();
+  ContainsError = true;
+}
   }
 
   // Report warning when arm64EC option is overridden by specified target

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


[Lldb-commits] [lldb] [lld] [libc] [llvm] [compiler-rt] [clang] [flang] [Driver] Check the environment version except wasm case. (PR #80783)

2024-02-06 Thread via lldb-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/80783

>From 84506beecc20a064a5c895cf5c04135118da6606 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Tue, 6 Feb 2024 01:58:58 +
Subject: [PATCH 1/2] [Driver] Check the environment version except wasm case.

---
 clang/lib/Driver/Driver.cpp | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 29db9543f3655..04d02ea500d19 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1443,16 +1443,18 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain &TC = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  // Check if the environment version is valid.
-  llvm::Triple Triple = TC.getTriple();
-  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-  StringRef TripleObjectFormat =
-  Triple.getObjectFormatTypeName(Triple.getObjectFormat());
-  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
-  TripleVersionName != TripleObjectFormat) {
-Diags.Report(diag::err_drv_triple_version_invalid)
-<< TripleVersionName << TC.getTripleString();
-ContainsError = true;
+  // Check if the environment version is valid except wasm case.
+  if (!TC.getTriple().isWasm()) {
+llvm::Triple Triple = TC.getTriple();
+StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+StringRef TripleObjectFormat =
+Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "" &&
+TripleVersionName != TripleObjectFormat) {
+  Diags.Report(diag::err_drv_triple_version_invalid)
+  << TripleVersionName << TC.getTripleString();
+  ContainsError = true;
+}
   }
 
   // Report warning when arm64EC option is overridden by specified target

>From 33372e3d875948de91a12316cc07e5ca6222d669 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Tue, 6 Feb 2024 01:58:58 +
Subject: [PATCH 2/2] [Driver] Check the environment version except wasm case.

---
 .../{android-version.cpp => invalid-version.cpp}  | 15 +++
 1 file changed, 15 insertions(+)
 rename clang/test/Driver/{android-version.cpp => invalid-version.cpp} (54%)

diff --git a/clang/test/Driver/android-version.cpp 
b/clang/test/Driver/invalid-version.cpp
similarity index 54%
rename from clang/test/Driver/android-version.cpp
rename to clang/test/Driver/invalid-version.cpp
index d365b701c0223..01bcbf277aee0 100644
--- a/clang/test/Driver/android-version.cpp
+++ b/clang/test/Driver/invalid-version.cpp
@@ -14,3 +14,18 @@
 // RUN:   FileCheck --check-prefix=CHECK-TARGET %s
 
 // CHECK-TARGET: "aarch64-unknown-linux-android31"
+
+// RUN: not %clang --target=armv7-linux-gnuS -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-ERROR2 %s
+
+// CHECK-ERROR2: error: version 'S' in target triple 
'armv7-unknown-linux-gnuS' is invalid
+
+// RUN: %clang --target=wasm32-unknown-wasi-preview2 -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-TARGET1 %s
+
+// CHECK-TARGET1: "wasm32-unknown-wasi-preview2"
+
+// RUN: %clang --target=wasm32-wasi-pthread -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-TARGET2 %s
+
+// CHECK-TARGET2: "wasm32-unknown-wasi-pthread"

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


[Lldb-commits] [lld] [clang] [libc] [flang] [compiler-rt] [llvm] [lldb] [Driver] Check the environment version except wasm case. (PR #80783)

2024-02-06 Thread via lldb-commits

ZijunZhaoCCK wrote:

> Add a test?

Done. Add several tests.

https://github.com/llvm/llvm-project/pull/80783
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread via lldb-commits

https://github.com/kusmour updated 
https://github.com/llvm/llvm-project/pull/80745

>From c79b3daa3e2a5ed2a571d93871bc527b651c0403 Mon Sep 17 00:00:00 2001
From: Wanyi Ye 
Date: Fri, 2 Feb 2024 15:42:01 -0800
Subject: [PATCH 1/4] Support statistics dump summary only mode

Summary:
Added a new --summary option to statistics dump command so that it is much 
light weight than the full version.
With this change, statistics dump --summary can now be included in lldb command 
line telemetry without slowing down lldb exiting.
---
 lldb/include/lldb/API/SBTarget.h  |   6 +-
 lldb/include/lldb/Target/Statistics.h |   9 +-
 lldb/include/lldb/Target/Target.h |   2 +-
 lldb/source/API/SBTarget.cpp  |   9 +-
 lldb/source/Commands/CommandObjectStats.cpp   |   8 +-
 lldb/source/Commands/Options.td   |   3 +
 lldb/source/Target/Statistics.cpp | 194 +++---
 lldb/source/Target/Target.cpp |   4 +-
 .../stats_api/TestStatisticsAPI.py|  15 ++
 9 files changed, 163 insertions(+), 87 deletions(-)

diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 83087623088c5b..72b8997afd2704 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -86,9 +86,13 @@ class LLDB_API SBTarget {
 
   /// Returns a dump of the collected statistics.
   ///
+  /// \param[in] summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// A SBStructuredData with the statistics collected.
-  lldb::SBStructuredData GetStatistics();
+  lldb::SBStructuredData GetStatistics(bool summary_only = false);
 
   /// Return the platform object associated with the target.
   ///
diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index f672786f58f84d..98658ba0cac317 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,7 +133,7 @@ struct ConstStringStats {
 /// A class that represents statistics for a since lldb_private::Target.
 class TargetStats {
 public:
-  llvm::json::Value ToJSON(Target &target);
+  llvm::json::Value ToJSON(Target &target, bool summary_only = false);
 
   void SetLaunchOrAttachTime();
   void SetFirstPrivateStopTime();
@@ -171,9 +171,14 @@ class DebuggerStats {
   ///   The single target to emit statistics for if non NULL, otherwise dump
   ///   statistics only for the specified target.
   ///
+  /// \param summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  static llvm::json::Value ReportStatistics(Debugger &debugger, Target 
*target);
+  static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target,
+bool summary_only = false);
 
 protected:
   // Collecting stats can be set to true to collect stats that are expensive
diff --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index c37682e2a03859..4bf6c123dc1ddc 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1599,7 +1599,7 @@ class Target : public 
std::enable_shared_from_this,
   ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  llvm::json::Value ReportStatistics();
+  llvm::json::Value ReportStatistics(bool summary_only = false);
 
   TargetStats &GetStatistics() { return m_stats; }
 
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 8e616afbcb4e8d..615a00ceeaee16 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -197,7 +197,7 @@ SBDebugger SBTarget::GetDebugger() const {
   return debugger;
 }
 
-SBStructuredData SBTarget::GetStatistics() {
+SBStructuredData SBTarget::GetStatistics(bool summary_only) {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData data;
@@ -205,9 +205,10 @@ SBStructuredData SBTarget::GetStatistics() {
   if (!target_sp)
 return data;
   std::string json_str =
-  llvm::formatv("{0:2}",
-  DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
-  target_sp.get())).str();
+  llvm::formatv(
+  "{0:2}", DebuggerStats::ReportStatistics(
+   target_sp->GetDebugger(), target_sp.get(), 
summary_only))
+  .str();
   data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
   return data;
 }
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 262de0bda144a6..781b90794dc377 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -75,6 +75,9 @@ class CommandObjectStatsDump : public CommandObjectParsed {
 

[Lldb-commits] [lldb] Fix a crasher when using the public API. (PR #80508)

2024-02-06 Thread Greg Clayton via lldb-commits

https://github.com/clayborg updated 
https://github.com/llvm/llvm-project/pull/80508

>From c416b6f4c0a00684057947782413b66af4c197f3 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Fri, 2 Feb 2024 15:30:40 -0800
Subject: [PATCH] Fix a crasher when using the public API.

A user found a crash when they would do code like:
(lldb) script
>>> target = lldb.SBTarget()
>>> lldb.debugger.SetSelectedTarget(target)

We were not checking if the target was valid in 
SBDebugger::SetSelectedTarget(...).
---
 lldb/source/API/SBDebugger.cpp   | 14 +++---
 lldb/test/API/python_api/target/TestTargetAPI.py |  6 ++
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index fbcf30e67fc1cd..12cbe25a540eba 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1089,9 +1089,9 @@ void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
   Log *log = GetLog(LLDBLog::API);
 
   TargetSP target_sp(sb_target.GetSP());
-  if (m_opaque_sp) {
+  if (m_opaque_sp && target_sp)
 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp);
-  }
+
   if (log) {
 SBStream sstr;
 sb_target.GetDescription(sstr, eDescriptionLevelBrief);
@@ -1704,20 +1704,20 @@ SBDebugger::LoadTraceFromFile(SBError &error,
 
 void SBDebugger::RequestInterrupt() {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
-m_opaque_sp->RequestInterrupt();  
+m_opaque_sp->RequestInterrupt();
 }
 void SBDebugger::CancelInterruptRequest()  {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
-m_opaque_sp->CancelInterruptRequest();  
+m_opaque_sp->CancelInterruptRequest();
 }
 
 bool SBDebugger::InterruptRequested()   {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
 return m_opaque_sp->InterruptRequested();
   return false;
diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py 
b/lldb/test/API/python_api/target/TestTargetAPI.py
index c8e1904428c8aa..63d34340a8836e 100644
--- a/lldb/test/API/python_api/target/TestTargetAPI.py
+++ b/lldb/test/API/python_api/target/TestTargetAPI.py
@@ -526,3 +526,9 @@ def test_is_loaded(self):
 target.IsLoaded(module),
 "Running the target should " "have loaded its modules.",
 )
+
+@no_debug_info_test
+def test_setting_selected_target_with_invalid_target(self):
+"""Make sure we don't crash when trying to select invalid target."""
+target = lldb.SBTarget()
+self.dbg.SetSelectedTarget(target)

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


[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Jonas Devlieghere via lldb-commits


@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
 Global,
 DefaultTrue,
 Desc<"Control the use of external tools and repositories to locate symbol 
files. Directories listed in target.debug-file-search-paths and directory of 
the executable are always checked first for separate debug info files. Then 
depending on this setting: On macOS, Spotlight would be also used to locate a 
matching .dSYM bundle based on the UUID of the executable. On NetBSD, directory 
/usr/libdata/debug would be also searched. On platforms other than NetBSD 
directory /usr/lib/debug would be also searched. If all other methods fail 
there may be symbol-locator plugins that, if configured properly, will also 
attempt to acquire symbols. The debuginfod plugin defaults to the 
DEGUFINFOD_URLS environment variable which is configurable through the 
'plugin.symbol-locator.debuginfod.server_urls' setting.">;
-  def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
+  def LazySymbolLookup: Property<"lazy-lookup", "Enum">,

JDevlieghere wrote:

This is entirely orthogonal to the usual external symbol lookup. The latter 
uses DebugSymbols/Spotlight which may or may not use dsymForUUID under the 
hood. I considered on-demand but that's already taken by SymbolFileOnDemand. 
I'm open to other names but I don't have a better idea :-) 

https://github.com/llvm/llvm-project/pull/80890
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Fix a crasher when using the public API. (PR #80508)

2024-02-06 Thread Greg Clayton via lldb-commits

https://github.com/clayborg updated 
https://github.com/llvm/llvm-project/pull/80508

>From c416b6f4c0a00684057947782413b66af4c197f3 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Fri, 2 Feb 2024 15:30:40 -0800
Subject: [PATCH 1/2] Fix a crasher when using the public API.

A user found a crash when they would do code like:
(lldb) script
>>> target = lldb.SBTarget()
>>> lldb.debugger.SetSelectedTarget(target)

We were not checking if the target was valid in 
SBDebugger::SetSelectedTarget(...).
---
 lldb/source/API/SBDebugger.cpp   | 14 +++---
 lldb/test/API/python_api/target/TestTargetAPI.py |  6 ++
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index fbcf30e67fc1c..12cbe25a540eb 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1089,9 +1089,9 @@ void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
   Log *log = GetLog(LLDBLog::API);
 
   TargetSP target_sp(sb_target.GetSP());
-  if (m_opaque_sp) {
+  if (m_opaque_sp && target_sp)
 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp);
-  }
+
   if (log) {
 SBStream sstr;
 sb_target.GetDescription(sstr, eDescriptionLevelBrief);
@@ -1704,20 +1704,20 @@ SBDebugger::LoadTraceFromFile(SBError &error,
 
 void SBDebugger::RequestInterrupt() {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
-m_opaque_sp->RequestInterrupt();  
+m_opaque_sp->RequestInterrupt();
 }
 void SBDebugger::CancelInterruptRequest()  {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
-m_opaque_sp->CancelInterruptRequest();  
+m_opaque_sp->CancelInterruptRequest();
 }
 
 bool SBDebugger::InterruptRequested()   {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
 return m_opaque_sp->InterruptRequested();
   return false;
diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py 
b/lldb/test/API/python_api/target/TestTargetAPI.py
index c8e1904428c8a..63d34340a8836 100644
--- a/lldb/test/API/python_api/target/TestTargetAPI.py
+++ b/lldb/test/API/python_api/target/TestTargetAPI.py
@@ -526,3 +526,9 @@ def test_is_loaded(self):
 target.IsLoaded(module),
 "Running the target should " "have loaded its modules.",
 )
+
+@no_debug_info_test
+def test_setting_selected_target_with_invalid_target(self):
+"""Make sure we don't crash when trying to select invalid target."""
+target = lldb.SBTarget()
+self.dbg.SetSelectedTarget(target)

>From 1473e88ff82ea45a76e1ab65ef471c78c0bc4f70 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Tue, 6 Feb 2024 12:27:58 -0800
Subject: [PATCH 2/2] Do the target check in TargetList::SetSelectedTarget()
 and also check if the target is valid.

---
 lldb/source/API/SBDebugger.cpp|  2 +-
 lldb/source/Target/TargetList.cpp | 16 ++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 12cbe25a540eb..6a204228cb440 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1089,7 +1089,7 @@ void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
   Log *log = GetLog(LLDBLog::API);
 
   TargetSP target_sp(sb_target.GetSP());
-  if (m_opaque_sp && target_sp)
+  if (m_opaque_sp)
 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp);
 
   if (log) {
diff --git a/lldb/source/Target/TargetList.cpp 
b/lldb/source/Target/TargetList.cpp
index 121b6253d2a59..bfab46b7ea61f 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -532,9 +532,13 @@ void TargetList::SetSelectedTarget(uint32_t index) {
 }
 
 void TargetList::SetSelectedTarget(const TargetSP &target_sp) {
-  std::lock_guard guard(m_target_list_mutex);
-  auto it = llvm::find(m_target_list, target_sp);
-  SetSelectedTargetInternal(std::distance(m_target_list.begin(), it));
+  // Don't allow an invalid target shared pointer or a target that has been
+  // destroyed to become the selected target.
+  if (target_sp && target_sp->IsValid()) {
+std::lock_guard guard(m_target_list_mutex);
+auto it = llvm::find(m_target_list, target_sp);
+SetSelectedTargetInternal(std::distance(m_target_list.begin(), it));
+  }
 }
 
 lldb::TargetSP TargetList::GetSelectedTarget() {
@@ -564,15 +568,15 @@ bool TargetList::AnyTargetContainsModule(Module &module) {
 m_in_process_target_list.insert(target_sp);
 assert(was_added && "Target pointer was left in the in-process map");
   }
-  
+
   void TargetList::UnregisterInProcessTarget(TargetSP target_sp) {
 std::lock_guard guard(m_target_list_mutex);
 [[maybe_unused]] bool was_present =
 m_in_process_target_list.erase(target_sp);
 assert(was_present && "Target pointer being removed was not registered");
   }
-  
+
   bool TargetList::IsTargetInProcess(TargetSP target_sp) {
 std::lock_guard guard(m_target_list_mute

[Lldb-commits] [lldb] Fix a crasher when using the public API. (PR #80508)

2024-02-06 Thread Greg Clayton via lldb-commits

https://github.com/clayborg updated 
https://github.com/llvm/llvm-project/pull/80508

>From c416b6f4c0a00684057947782413b66af4c197f3 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Fri, 2 Feb 2024 15:30:40 -0800
Subject: [PATCH 1/3] Fix a crasher when using the public API.

A user found a crash when they would do code like:
(lldb) script
>>> target = lldb.SBTarget()
>>> lldb.debugger.SetSelectedTarget(target)

We were not checking if the target was valid in 
SBDebugger::SetSelectedTarget(...).
---
 lldb/source/API/SBDebugger.cpp   | 14 +++---
 lldb/test/API/python_api/target/TestTargetAPI.py |  6 ++
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index fbcf30e67fc1c..12cbe25a540eb 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1089,9 +1089,9 @@ void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
   Log *log = GetLog(LLDBLog::API);
 
   TargetSP target_sp(sb_target.GetSP());
-  if (m_opaque_sp) {
+  if (m_opaque_sp && target_sp)
 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp);
-  }
+
   if (log) {
 SBStream sstr;
 sb_target.GetDescription(sstr, eDescriptionLevelBrief);
@@ -1704,20 +1704,20 @@ SBDebugger::LoadTraceFromFile(SBError &error,
 
 void SBDebugger::RequestInterrupt() {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
-m_opaque_sp->RequestInterrupt();  
+m_opaque_sp->RequestInterrupt();
 }
 void SBDebugger::CancelInterruptRequest()  {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
-m_opaque_sp->CancelInterruptRequest();  
+m_opaque_sp->CancelInterruptRequest();
 }
 
 bool SBDebugger::InterruptRequested()   {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
 return m_opaque_sp->InterruptRequested();
   return false;
diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py 
b/lldb/test/API/python_api/target/TestTargetAPI.py
index c8e1904428c8a..63d34340a8836 100644
--- a/lldb/test/API/python_api/target/TestTargetAPI.py
+++ b/lldb/test/API/python_api/target/TestTargetAPI.py
@@ -526,3 +526,9 @@ def test_is_loaded(self):
 target.IsLoaded(module),
 "Running the target should " "have loaded its modules.",
 )
+
+@no_debug_info_test
+def test_setting_selected_target_with_invalid_target(self):
+"""Make sure we don't crash when trying to select invalid target."""
+target = lldb.SBTarget()
+self.dbg.SetSelectedTarget(target)

>From 1473e88ff82ea45a76e1ab65ef471c78c0bc4f70 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Tue, 6 Feb 2024 12:27:58 -0800
Subject: [PATCH 2/3] Do the target check in TargetList::SetSelectedTarget()
 and also check if the target is valid.

---
 lldb/source/API/SBDebugger.cpp|  2 +-
 lldb/source/Target/TargetList.cpp | 16 ++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 12cbe25a540eb..6a204228cb440 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1089,7 +1089,7 @@ void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
   Log *log = GetLog(LLDBLog::API);
 
   TargetSP target_sp(sb_target.GetSP());
-  if (m_opaque_sp && target_sp)
+  if (m_opaque_sp)
 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp);
 
   if (log) {
diff --git a/lldb/source/Target/TargetList.cpp 
b/lldb/source/Target/TargetList.cpp
index 121b6253d2a59..bfab46b7ea61f 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -532,9 +532,13 @@ void TargetList::SetSelectedTarget(uint32_t index) {
 }
 
 void TargetList::SetSelectedTarget(const TargetSP &target_sp) {
-  std::lock_guard guard(m_target_list_mutex);
-  auto it = llvm::find(m_target_list, target_sp);
-  SetSelectedTargetInternal(std::distance(m_target_list.begin(), it));
+  // Don't allow an invalid target shared pointer or a target that has been
+  // destroyed to become the selected target.
+  if (target_sp && target_sp->IsValid()) {
+std::lock_guard guard(m_target_list_mutex);
+auto it = llvm::find(m_target_list, target_sp);
+SetSelectedTargetInternal(std::distance(m_target_list.begin(), it));
+  }
 }
 
 lldb::TargetSP TargetList::GetSelectedTarget() {
@@ -564,15 +568,15 @@ bool TargetList::AnyTargetContainsModule(Module &module) {
 m_in_process_target_list.insert(target_sp);
 assert(was_added && "Target pointer was left in the in-process map");
   }
-  
+
   void TargetList::UnregisterInProcessTarget(TargetSP target_sp) {
 std::lock_guard guard(m_target_list_mutex);
 [[maybe_unused]] bool was_present =
 m_in_process_target_list.erase(target_sp);
 assert(was_present && "Target pointer being removed was not registered");
   }
-  
+
   bool TargetList::IsTargetInProcess(TargetSP target_sp) {
 std::lock_guard guard(m_target_list_mute

[Lldb-commits] [lldb] Fix a crasher when using the public API. (PR #80508)

2024-02-06 Thread Greg Clayton via lldb-commits

https://github.com/clayborg updated 
https://github.com/llvm/llvm-project/pull/80508

>From c416b6f4c0a00684057947782413b66af4c197f3 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Fri, 2 Feb 2024 15:30:40 -0800
Subject: [PATCH 1/4] Fix a crasher when using the public API.

A user found a crash when they would do code like:
(lldb) script
>>> target = lldb.SBTarget()
>>> lldb.debugger.SetSelectedTarget(target)

We were not checking if the target was valid in 
SBDebugger::SetSelectedTarget(...).
---
 lldb/source/API/SBDebugger.cpp   | 14 +++---
 lldb/test/API/python_api/target/TestTargetAPI.py |  6 ++
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index fbcf30e67fc1cd..12cbe25a540eba 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1089,9 +1089,9 @@ void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
   Log *log = GetLog(LLDBLog::API);
 
   TargetSP target_sp(sb_target.GetSP());
-  if (m_opaque_sp) {
+  if (m_opaque_sp && target_sp)
 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp);
-  }
+
   if (log) {
 SBStream sstr;
 sb_target.GetDescription(sstr, eDescriptionLevelBrief);
@@ -1704,20 +1704,20 @@ SBDebugger::LoadTraceFromFile(SBError &error,
 
 void SBDebugger::RequestInterrupt() {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
-m_opaque_sp->RequestInterrupt();  
+m_opaque_sp->RequestInterrupt();
 }
 void SBDebugger::CancelInterruptRequest()  {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
-m_opaque_sp->CancelInterruptRequest();  
+m_opaque_sp->CancelInterruptRequest();
 }
 
 bool SBDebugger::InterruptRequested()   {
   LLDB_INSTRUMENT_VA(this);
-  
+
   if (m_opaque_sp)
 return m_opaque_sp->InterruptRequested();
   return false;
diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py 
b/lldb/test/API/python_api/target/TestTargetAPI.py
index c8e1904428c8aa..63d34340a8836e 100644
--- a/lldb/test/API/python_api/target/TestTargetAPI.py
+++ b/lldb/test/API/python_api/target/TestTargetAPI.py
@@ -526,3 +526,9 @@ def test_is_loaded(self):
 target.IsLoaded(module),
 "Running the target should " "have loaded its modules.",
 )
+
+@no_debug_info_test
+def test_setting_selected_target_with_invalid_target(self):
+"""Make sure we don't crash when trying to select invalid target."""
+target = lldb.SBTarget()
+self.dbg.SetSelectedTarget(target)

>From 1473e88ff82ea45a76e1ab65ef471c78c0bc4f70 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Tue, 6 Feb 2024 12:27:58 -0800
Subject: [PATCH 2/4] Do the target check in TargetList::SetSelectedTarget()
 and also check if the target is valid.

---
 lldb/source/API/SBDebugger.cpp|  2 +-
 lldb/source/Target/TargetList.cpp | 16 ++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 12cbe25a540eba..6a204228cb440e 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1089,7 +1089,7 @@ void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
   Log *log = GetLog(LLDBLog::API);
 
   TargetSP target_sp(sb_target.GetSP());
-  if (m_opaque_sp && target_sp)
+  if (m_opaque_sp)
 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp);
 
   if (log) {
diff --git a/lldb/source/Target/TargetList.cpp 
b/lldb/source/Target/TargetList.cpp
index 121b6253d2a59d..bfab46b7ea61fe 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -532,9 +532,13 @@ void TargetList::SetSelectedTarget(uint32_t index) {
 }
 
 void TargetList::SetSelectedTarget(const TargetSP &target_sp) {
-  std::lock_guard guard(m_target_list_mutex);
-  auto it = llvm::find(m_target_list, target_sp);
-  SetSelectedTargetInternal(std::distance(m_target_list.begin(), it));
+  // Don't allow an invalid target shared pointer or a target that has been
+  // destroyed to become the selected target.
+  if (target_sp && target_sp->IsValid()) {
+std::lock_guard guard(m_target_list_mutex);
+auto it = llvm::find(m_target_list, target_sp);
+SetSelectedTargetInternal(std::distance(m_target_list.begin(), it));
+  }
 }
 
 lldb::TargetSP TargetList::GetSelectedTarget() {
@@ -564,15 +568,15 @@ bool TargetList::AnyTargetContainsModule(Module &module) {
 m_in_process_target_list.insert(target_sp);
 assert(was_added && "Target pointer was left in the in-process map");
   }
-  
+
   void TargetList::UnregisterInProcessTarget(TargetSP target_sp) {
 std::lock_guard guard(m_target_list_mutex);
 [[maybe_unused]] bool was_present =
 m_in_process_target_list.erase(target_sp);
 assert(was_present && "Target pointer being removed was not registered");
   }
-  
+
   bool TargetList::IsTargetInProcess(TargetSP target_sp) {
 std::lock_guard guard(m_target_l

[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.

jimingham wrote:

Yes, it's a part of the ov_parser API.  I added examples.

https://github.com/llvm/llvm-project/pull/70734
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.
+
+There are example commands in the lldb testsuite at:
+
+llvm-project/lldb/test/API/commands/command/script/add/test_commands.py
+"""
+import inspect
+import lldb
+import sys
+from abc import abstractmethod
+
+class LLDBOVParser:

jimingham wrote:

Yes, I agree, nobody will ever type this one because that's not even the class 
you override.  So there's no reason for it to have a mysterious name.

https://github.com/llvm/llvm-project/pull/70734
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [lldb-dap][NFC] Add Breakpoint struct to share common logic. (PR #80753)

2024-02-06 Thread Zequan Wu via lldb-commits

https://github.com/ZequanWu updated 
https://github.com/llvm/llvm-project/pull/80753

>From c4b767909a9ffc2a3015dc9021e4c265da0d877d Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Mon, 5 Feb 2024 17:26:48 -0500
Subject: [PATCH 1/2] [lldb-dap][NFC] Add Breakpoint struct to share common
 logic.

---
 lldb/tools/lldb-dap/Breakpoint.cpp| 182 ++
 lldb/tools/lldb-dap/Breakpoint.h  |  34 
 lldb/tools/lldb-dap/BreakpointBase.cpp| 113 ---
 lldb/tools/lldb-dap/BreakpointBase.h  |  12 +-
 lldb/tools/lldb-dap/CMakeLists.txt|   1 +
 lldb/tools/lldb-dap/FunctionBreakpoint.cpp|  12 +-
 lldb/tools/lldb-dap/FunctionBreakpoint.h  |   4 +-
 lldb/tools/lldb-dap/JSONUtils.cpp |  46 +
 lldb/tools/lldb-dap/JSONUtils.h   |   5 +-
 lldb/tools/lldb-dap/SourceBreakpoint.cpp  |  12 +-
 lldb/tools/lldb-dap/SourceBreakpoint.h|   6 +-
 lldb/tools/lldb-dap/lldb-dap.cpp  |  17 +-
 .../gn/secondary/lldb/tools/lldb-dap/BUILD.gn |   1 +
 13 files changed, 248 insertions(+), 197 deletions(-)
 create mode 100644 lldb/tools/lldb-dap/Breakpoint.cpp
 create mode 100644 lldb/tools/lldb-dap/Breakpoint.h

diff --git a/lldb/tools/lldb-dap/Breakpoint.cpp 
b/lldb/tools/lldb-dap/Breakpoint.cpp
new file mode 100644
index 0..4ccf353b06ccc
--- /dev/null
+++ b/lldb/tools/lldb-dap/Breakpoint.cpp
@@ -0,0 +1,182 @@
+//===-- Breakpoint.cpp --*- C++ 
-*-===//
+//
+// 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 "Breakpoint.h"
+#include "DAP.h"
+#include "JSONUtils.h"
+#include "llvm/ADT/StringExtras.h"
+
+using namespace lldb_dap;
+
+void Breakpoint::SetCondition() { bp.SetCondition(condition.c_str()); }
+
+void Breakpoint::SetHitCondition() {
+  uint64_t hitCount = 0;
+  if (llvm::to_integer(hitCondition, hitCount))
+bp.SetIgnoreCount(hitCount - 1);
+}
+
+// logMessage will be divided into array of LogMessagePart as two kinds:
+// 1. raw print text message, and
+// 2. interpolated expression for evaluation which is inside matching curly
+//braces.
+//
+// The function tries to parse logMessage into a list of LogMessageParts
+// for easy later access in BreakpointHitCallback.
+void Breakpoint::SetLogMessage() {
+  logMessageParts.clear();
+
+  // Contains unmatched open curly braces indices.
+  std::vector unmatched_curly_braces;
+
+  // Contains all matched curly braces in logMessage.
+  // Loop invariant: matched_curly_braces_ranges are sorted by start index in
+  // ascending order without any overlap between them.
+  std::vector> matched_curly_braces_ranges;
+
+  lldb::SBError error;
+  // Part1 - parse matched_curly_braces_ranges.
+  // locating all curly braced expression ranges in logMessage.
+  // The algorithm takes care of nested and imbalanced curly braces.
+  for (size_t i = 0; i < logMessage.size(); ++i) {
+if (logMessage[i] == '{') {
+  unmatched_curly_braces.push_back(i);
+} else if (logMessage[i] == '}') {
+  if (unmatched_curly_braces.empty())
+// Nothing to match.
+continue;
+
+  int last_unmatched_index = unmatched_curly_braces.back();
+  unmatched_curly_braces.pop_back();
+
+  // Erase any matched ranges included in the new match.
+  while (!matched_curly_braces_ranges.empty()) {
+assert(matched_curly_braces_ranges.back().first !=
+   last_unmatched_index &&
+   "How can a curley brace be matched twice?");
+if (matched_curly_braces_ranges.back().first < last_unmatched_index)
+  break;
+
+// This is a nested range let's earse it.
+assert((size_t)matched_curly_braces_ranges.back().second < i);
+matched_curly_braces_ranges.pop_back();
+  }
+
+  // Assert invariant.
+  assert(matched_curly_braces_ranges.empty() ||
+ matched_curly_braces_ranges.back().first < last_unmatched_index);
+  matched_curly_braces_ranges.emplace_back(last_unmatched_index, i);
+}
+  }
+
+  // Part2 - parse raw text and expresions parts.
+  // All expression ranges have been parsed in matched_curly_braces_ranges.
+  // The code below uses matched_curly_braces_ranges to divide logMessage
+  // into raw text parts and expression parts.
+  int last_raw_text_start = 0;
+  for (const std::pair &curly_braces_range :
+   matched_curly_braces_ranges) {
+// Raw text before open curly brace.
+assert(curly_braces_range.first >= last_raw_text_start);
+size_t raw_text_len = curly_braces_range.first - last_raw_text_start;
+if (raw_text_len > 0) {
+  error = AppendLogMessagePart(
+  llvm::StringRef(logMessage.c_str() + last_raw_text_start,
+ 

[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Alex Langford via lldb-commits


@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
 Global,
 DefaultTrue,
 Desc<"Control the use of external tools and repositories to locate symbol 
files. Directories listed in target.debug-file-search-paths and directory of 
the executable are always checked first for separate debug info files. Then 
depending on this setting: On macOS, Spotlight would be also used to locate a 
matching .dSYM bundle based on the UUID of the executable. On NetBSD, directory 
/usr/libdata/debug would be also searched. On platforms other than NetBSD 
directory /usr/lib/debug would be also searched. If all other methods fail 
there may be symbol-locator plugins that, if configured properly, will also 
attempt to acquire symbols. The debuginfod plugin defaults to the 
DEGUFINFOD_URLS environment variable which is configurable through the 
'plugin.symbol-locator.debuginfod.server_urls' setting.">;
-  def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
+  def LazySymbolLookup: Property<"lazy-lookup", "Enum">,

bulbazord wrote:

`symbol-loading-behavior`? `symbol-lookup-strategy`? 😄 

https://github.com/llvm/llvm-project/pull/80890
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 1dd9162 - [lldb] Fix a crasher when using the public API. (#80508)

2024-02-06 Thread via lldb-commits

Author: Greg Clayton
Date: 2024-02-06T13:53:29-08:00
New Revision: 1dd9162b95d29367635f32c7be24779b1ddaa7e5

URL: 
https://github.com/llvm/llvm-project/commit/1dd9162b95d29367635f32c7be24779b1ddaa7e5
DIFF: 
https://github.com/llvm/llvm-project/commit/1dd9162b95d29367635f32c7be24779b1ddaa7e5.diff

LOG: [lldb] Fix a crasher when using the public API. (#80508)

A user found a crash when they would do code like:
```
(lldb) script
>>> target = lldb.SBTarget()
>>> lldb.debugger.SetSelectedTarget(target)
```

We were not checking if the target was valid in and it caused a crash..

Added: 


Modified: 
lldb/source/Target/TargetList.cpp
lldb/test/API/python_api/target/TestTargetAPI.py

Removed: 




diff  --git a/lldb/source/Target/TargetList.cpp 
b/lldb/source/Target/TargetList.cpp
index 121b6253d2a59d..b5d308739d0fac 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -532,9 +532,13 @@ void TargetList::SetSelectedTarget(uint32_t index) {
 }
 
 void TargetList::SetSelectedTarget(const TargetSP &target_sp) {
-  std::lock_guard guard(m_target_list_mutex);
-  auto it = llvm::find(m_target_list, target_sp);
-  SetSelectedTargetInternal(std::distance(m_target_list.begin(), it));
+  // Don't allow an invalid target shared pointer or a target that has been
+  // destroyed to become the selected target.
+  if (target_sp && target_sp->IsValid()) {
+std::lock_guard guard(m_target_list_mutex);
+auto it = llvm::find(m_target_list, target_sp);
+SetSelectedTargetInternal(std::distance(m_target_list.begin(), it));
+  }
 }
 
 lldb::TargetSP TargetList::GetSelectedTarget() {

diff  --git a/lldb/test/API/python_api/target/TestTargetAPI.py 
b/lldb/test/API/python_api/target/TestTargetAPI.py
index c8e1904428c8aa..63d34340a8836e 100644
--- a/lldb/test/API/python_api/target/TestTargetAPI.py
+++ b/lldb/test/API/python_api/target/TestTargetAPI.py
@@ -526,3 +526,9 @@ def test_is_loaded(self):
 target.IsLoaded(module),
 "Running the target should " "have loaded its modules.",
 )
+
+@no_debug_info_test
+def test_setting_selected_target_with_invalid_target(self):
+"""Make sure we don't crash when trying to select invalid target."""
+target = lldb.SBTarget()
+self.dbg.SetSelectedTarget(target)



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


[Lldb-commits] [lldb] Fix a crasher when using the public API. (PR #80508)

2024-02-06 Thread Greg Clayton via lldb-commits

https://github.com/clayborg closed 
https://github.com/llvm/llvm-project/pull/80508
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.
+
+There are example commands in the lldb testsuite at:
+
+llvm-project/lldb/test/API/commands/command/script/add/test_commands.py
+"""
+import inspect
+import lldb
+import sys
+from abc import abstractmethod
+
+class LLDBOVParser:
+def __init__(self):
+# This is a dictionary of dictionaries.  The key is the long option
+# name, and the value is the rest of the definition.
+self.options_dict = {}
+self.args_array = []
+
+# Some methods to translate common value types.  Should return a
+# tuple of the value and an error value (True => error) if the
+# type can't be converted.
+# FIXME: Need a way to push the conversion error string back to lldb.
+@staticmethod
+def to_bool(in_value):
+error = True
+value = False
+if type(in_value) != str or len(in_value) == 0:
+return (value, error)
+
+low_in = in_value.lower()
+if low_in == "y" or low_in == "yes" or low_in == "t" or low_in == 
"true" or low_in == "1":
+value = True
+error = False
+
+if not value and low_in == "n" or low_in == "no" or low_in == "f" or 
low_in == "false" or low_in == "0":

jimingham wrote:

string in array of strings is definitely easier to read, thanks!

I don't think the second comment is right, however.  Not all input values will 
make it into either of those if statements, for instance "low_in = 
definitely_not_a_boolean" will be rejected by both if's and so "error" will be 
left at True.

All of this conversion code should actually go away, because it's silly to have 
two versions of OptionArgParser::ToBool, one in C++ and one here in Python.  
This is just a shortcut for now because this patch was already getting somewhat 
unwieldily.

https://github.com/llvm/llvm-project/pull/70734
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.
+
+There are example commands in the lldb testsuite at:
+
+llvm-project/lldb/test/API/commands/command/script/add/test_commands.py
+"""
+import inspect
+import lldb
+import sys
+from abc import abstractmethod
+
+class LLDBOVParser:
+def __init__(self):
+# This is a dictionary of dictionaries.  The key is the long option
+# name, and the value is the rest of the definition.
+self.options_dict = {}
+self.args_array = []
+
+# Some methods to translate common value types.  Should return a
+# tuple of the value and an error value (True => error) if the
+# type can't be converted.
+# FIXME: Need a way to push the conversion error string back to lldb.
+@staticmethod
+def to_bool(in_value):
+error = True
+value = False
+if type(in_value) != str or len(in_value) == 0:
+return (value, error)
+
+low_in = in_value.lower()
+if low_in == "y" or low_in == "yes" or low_in == "t" or low_in == 
"true" or low_in == "1":
+value = True
+error = False
+
+if not value and low_in == "n" or low_in == "no" or low_in == "f" or 
low_in == "false" or low_in == "0":
+value = False
+error = False
+
+return (value, error)
+
+@staticmethod
+def to_int(in_value):
+#FIXME: Not doing errors yet...
+return (int(in_value), False)
+
+@staticmethod
+def to_unsigned(in_value):
+# FIXME: find an unsigned converter...
+# And handle errors.
+return (int(in_value), False)
+
+translators = {
+lldb.eArgTypeBoolean : to_bool,
+lldb.eArgTypeBreakpointID : to_unsigned,
+lldb.eArgTypeByteSize : to_unsigned,
+lldb.eArgTypeCount : to_unsigned,
+lldb.eArgTypeFrameIndex : to_unsigned,
+lldb.eArgTypeIndex : to_unsigned,
+lldb.eArgTypeLineNum : to_unsigned,
+lldb.eArgTypeNumLines : to_unsigned,
+lldb.eArgTypeNumberPerLine : to_unsigned,
+lldb.eArgTypeOffset : to_int,
+lldb.eArgTypeThreadIndex : to_unsigned,
+lldb.eArgTypeUnsignedInteger : to_unsigned,
+lldb.eArgTypeWatchpointID : to_unsigned,
+lldb.eArgTypeColumnNum : to_unsigned,
+lldb.eArgTypeRecognizerID : to_unsigned,
+lldb.eArgTypeTargetID : to_unsigned,
+lldb.eArgTypeStopHookID : to_unsigned
+}
+
+@classmethod
+def translate_value(cls, value_type, value):
+try:
+return cls.translators[value_type](value)
+except KeyError:
+# If we don't have a translator, return the string value.
+return (value, False)
+
+# FIXME: would this be better done on the C++ side?
+# The common completers are missing some useful ones.
+# For instance there really should be a common Type completer
+# And an "lldb command name" completer.
+completion_table = {
+lldb.eArgTypeAddressOrExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeArchitecture : lldb.eArchitectureCompletion,
+lldb.eArgTypeBreakpointID : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointIDRange : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointName : lldb.eBreakpointNameCompletion,
+lldb.eArgTypeClassName : lldb.eSymbolCompletion,
+lldb.eArgTypeDirectoryName : lldb.eDiskDirectoryCompletion,
+lldb.eArgTypeExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeExpressionPath : lldb.eVariablePathCompletion,
+lldb.eArgTypeFilename : lldb.eDiskFileCompletion,
+lldb.eArgTypeFrameIndex : lldb.eFrameIndex

[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread via lldb-commits

https://github.com/kusmour updated 
https://github.com/llvm/llvm-project/pull/80745

>From e5902abd4cd401f5e6a132d1fa5d0b2197512494 Mon Sep 17 00:00:00 2001
From: Wanyi Ye 
Date: Fri, 2 Feb 2024 15:42:01 -0800
Subject: [PATCH 1/5] Support statistics dump summary only mode

Summary:
Added a new --summary option to statistics dump command so that it is much 
light weight than the full version.
With this change, statistics dump --summary can now be included in lldb command 
line telemetry without slowing down lldb exiting.
---
 lldb/include/lldb/API/SBTarget.h  |   6 +-
 lldb/include/lldb/Target/Statistics.h |   9 +-
 lldb/include/lldb/Target/Target.h |   2 +-
 lldb/source/API/SBTarget.cpp  |   9 +-
 lldb/source/Commands/CommandObjectStats.cpp   |   8 +-
 lldb/source/Commands/Options.td   |   3 +
 lldb/source/Target/Statistics.cpp | 194 +++---
 lldb/source/Target/Target.cpp |   4 +-
 .../stats_api/TestStatisticsAPI.py|  15 ++
 9 files changed, 163 insertions(+), 87 deletions(-)

diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 83087623088c5b..72b8997afd2704 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -86,9 +86,13 @@ class LLDB_API SBTarget {
 
   /// Returns a dump of the collected statistics.
   ///
+  /// \param[in] summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// A SBStructuredData with the statistics collected.
-  lldb::SBStructuredData GetStatistics();
+  lldb::SBStructuredData GetStatistics(bool summary_only = false);
 
   /// Return the platform object associated with the target.
   ///
diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index f672786f58f84d..98658ba0cac317 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,7 +133,7 @@ struct ConstStringStats {
 /// A class that represents statistics for a since lldb_private::Target.
 class TargetStats {
 public:
-  llvm::json::Value ToJSON(Target &target);
+  llvm::json::Value ToJSON(Target &target, bool summary_only = false);
 
   void SetLaunchOrAttachTime();
   void SetFirstPrivateStopTime();
@@ -171,9 +171,14 @@ class DebuggerStats {
   ///   The single target to emit statistics for if non NULL, otherwise dump
   ///   statistics only for the specified target.
   ///
+  /// \param summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  static llvm::json::Value ReportStatistics(Debugger &debugger, Target 
*target);
+  static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target,
+bool summary_only = false);
 
 protected:
   // Collecting stats can be set to true to collect stats that are expensive
diff --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index c37682e2a03859..4bf6c123dc1ddc 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1599,7 +1599,7 @@ class Target : public 
std::enable_shared_from_this,
   ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  llvm::json::Value ReportStatistics();
+  llvm::json::Value ReportStatistics(bool summary_only = false);
 
   TargetStats &GetStatistics() { return m_stats; }
 
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 8e616afbcb4e8d..615a00ceeaee16 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -197,7 +197,7 @@ SBDebugger SBTarget::GetDebugger() const {
   return debugger;
 }
 
-SBStructuredData SBTarget::GetStatistics() {
+SBStructuredData SBTarget::GetStatistics(bool summary_only) {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData data;
@@ -205,9 +205,10 @@ SBStructuredData SBTarget::GetStatistics() {
   if (!target_sp)
 return data;
   std::string json_str =
-  llvm::formatv("{0:2}",
-  DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
-  target_sp.get())).str();
+  llvm::formatv(
+  "{0:2}", DebuggerStats::ReportStatistics(
+   target_sp->GetDebugger(), target_sp.get(), 
summary_only))
+  .str();
   data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
   return data;
 }
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 262de0bda144a6..781b90794dc377 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -75,6 +75,9 @@ class CommandObjectStatsDump : public CommandObjectParsed {
 

[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.
+
+There are example commands in the lldb testsuite at:
+
+llvm-project/lldb/test/API/commands/command/script/add/test_commands.py
+"""
+import inspect
+import lldb
+import sys
+from abc import abstractmethod
+
+class LLDBOVParser:
+def __init__(self):
+# This is a dictionary of dictionaries.  The key is the long option
+# name, and the value is the rest of the definition.
+self.options_dict = {}
+self.args_array = []
+
+# Some methods to translate common value types.  Should return a
+# tuple of the value and an error value (True => error) if the
+# type can't be converted.
+# FIXME: Need a way to push the conversion error string back to lldb.
+@staticmethod
+def to_bool(in_value):
+error = True
+value = False
+if type(in_value) != str or len(in_value) == 0:
+return (value, error)
+
+low_in = in_value.lower()
+if low_in == "y" or low_in == "yes" or low_in == "t" or low_in == 
"true" or low_in == "1":
+value = True
+error = False
+
+if not value and low_in == "n" or low_in == "no" or low_in == "f" or 
low_in == "false" or low_in == "0":
+value = False
+error = False
+
+return (value, error)
+
+@staticmethod
+def to_int(in_value):
+#FIXME: Not doing errors yet...
+return (int(in_value), False)
+
+@staticmethod
+def to_unsigned(in_value):
+# FIXME: find an unsigned converter...
+# And handle errors.
+return (int(in_value), False)
+
+translators = {
+lldb.eArgTypeBoolean : to_bool,
+lldb.eArgTypeBreakpointID : to_unsigned,
+lldb.eArgTypeByteSize : to_unsigned,
+lldb.eArgTypeCount : to_unsigned,
+lldb.eArgTypeFrameIndex : to_unsigned,
+lldb.eArgTypeIndex : to_unsigned,
+lldb.eArgTypeLineNum : to_unsigned,
+lldb.eArgTypeNumLines : to_unsigned,
+lldb.eArgTypeNumberPerLine : to_unsigned,
+lldb.eArgTypeOffset : to_int,
+lldb.eArgTypeThreadIndex : to_unsigned,
+lldb.eArgTypeUnsignedInteger : to_unsigned,
+lldb.eArgTypeWatchpointID : to_unsigned,
+lldb.eArgTypeColumnNum : to_unsigned,
+lldb.eArgTypeRecognizerID : to_unsigned,
+lldb.eArgTypeTargetID : to_unsigned,
+lldb.eArgTypeStopHookID : to_unsigned
+}
+
+@classmethod
+def translate_value(cls, value_type, value):
+try:
+return cls.translators[value_type](value)
+except KeyError:
+# If we don't have a translator, return the string value.
+return (value, False)
+
+# FIXME: would this be better done on the C++ side?
+# The common completers are missing some useful ones.
+# For instance there really should be a common Type completer
+# And an "lldb command name" completer.
+completion_table = {
+lldb.eArgTypeAddressOrExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeArchitecture : lldb.eArchitectureCompletion,
+lldb.eArgTypeBreakpointID : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointIDRange : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointName : lldb.eBreakpointNameCompletion,
+lldb.eArgTypeClassName : lldb.eSymbolCompletion,
+lldb.eArgTypeDirectoryName : lldb.eDiskDirectoryCompletion,
+lldb.eArgTypeExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeExpressionPath : lldb.eVariablePathCompletion,
+lldb.eArgTypeFilename : lldb.eDiskFileCompletion,
+lldb.eArgTypeFrameIndex : lldb.eFrameIndex

[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread via lldb-commits

https://github.com/kusmour updated 
https://github.com/llvm/llvm-project/pull/80745

>From e5902abd4cd401f5e6a132d1fa5d0b2197512494 Mon Sep 17 00:00:00 2001
From: Wanyi Ye 
Date: Fri, 2 Feb 2024 15:42:01 -0800
Subject: [PATCH 1/5] Support statistics dump summary only mode

Summary:
Added a new --summary option to statistics dump command so that it is much 
light weight than the full version.
With this change, statistics dump --summary can now be included in lldb command 
line telemetry without slowing down lldb exiting.
---
 lldb/include/lldb/API/SBTarget.h  |   6 +-
 lldb/include/lldb/Target/Statistics.h |   9 +-
 lldb/include/lldb/Target/Target.h |   2 +-
 lldb/source/API/SBTarget.cpp  |   9 +-
 lldb/source/Commands/CommandObjectStats.cpp   |   8 +-
 lldb/source/Commands/Options.td   |   3 +
 lldb/source/Target/Statistics.cpp | 194 +++---
 lldb/source/Target/Target.cpp |   4 +-
 .../stats_api/TestStatisticsAPI.py|  15 ++
 9 files changed, 163 insertions(+), 87 deletions(-)

diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 83087623088c5b..72b8997afd2704 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -86,9 +86,13 @@ class LLDB_API SBTarget {
 
   /// Returns a dump of the collected statistics.
   ///
+  /// \param[in] summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// A SBStructuredData with the statistics collected.
-  lldb::SBStructuredData GetStatistics();
+  lldb::SBStructuredData GetStatistics(bool summary_only = false);
 
   /// Return the platform object associated with the target.
   ///
diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index f672786f58f84d..98658ba0cac317 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,7 +133,7 @@ struct ConstStringStats {
 /// A class that represents statistics for a since lldb_private::Target.
 class TargetStats {
 public:
-  llvm::json::Value ToJSON(Target &target);
+  llvm::json::Value ToJSON(Target &target, bool summary_only = false);
 
   void SetLaunchOrAttachTime();
   void SetFirstPrivateStopTime();
@@ -171,9 +171,14 @@ class DebuggerStats {
   ///   The single target to emit statistics for if non NULL, otherwise dump
   ///   statistics only for the specified target.
   ///
+  /// \param summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  static llvm::json::Value ReportStatistics(Debugger &debugger, Target 
*target);
+  static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target,
+bool summary_only = false);
 
 protected:
   // Collecting stats can be set to true to collect stats that are expensive
diff --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index c37682e2a03859..4bf6c123dc1ddc 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1599,7 +1599,7 @@ class Target : public 
std::enable_shared_from_this,
   ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  llvm::json::Value ReportStatistics();
+  llvm::json::Value ReportStatistics(bool summary_only = false);
 
   TargetStats &GetStatistics() { return m_stats; }
 
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 8e616afbcb4e8d..615a00ceeaee16 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -197,7 +197,7 @@ SBDebugger SBTarget::GetDebugger() const {
   return debugger;
 }
 
-SBStructuredData SBTarget::GetStatistics() {
+SBStructuredData SBTarget::GetStatistics(bool summary_only) {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData data;
@@ -205,9 +205,10 @@ SBStructuredData SBTarget::GetStatistics() {
   if (!target_sp)
 return data;
   std::string json_str =
-  llvm::formatv("{0:2}",
-  DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
-  target_sp.get())).str();
+  llvm::formatv(
+  "{0:2}", DebuggerStats::ReportStatistics(
+   target_sp->GetDebugger(), target_sp.get(), 
summary_only))
+  .str();
   data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
   return data;
 }
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 262de0bda144a6..781b90794dc377 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -75,6 +75,9 @@ class CommandObjectStatsDump : public CommandObjectParsed {
 

[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread via lldb-commits


@@ -0,0 +1,313 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for your command that inherits from 
ParsedCommandBase.
+That will make an LLDBOVParser which you will use for your
+option definition, and to fetch option values for the current invocation
+of your command.  Access to the OV parser is through:
+
+ParsedCommandBase.get_parser()
+
+Next, implement setup_command_definition() in your new command class, and call:
+
+  self.get_parser().add_option()
+
+to add all your options.  The order doesn't matter for options, lldb will sort 
them
+alphabetically for you when it prints help.
+
+Similarly you can define the arguments with:
+
+  self.get_parser().add_argument()
+
+At present, lldb doesn't do as much work as it should verifying arguments, it
+only checks that commands that take no arguments don't get passed arguments.
+
+Then implement the execute function for your command as:
+
+def __call__(self, debugger, args_list, exe_ctx, result):
+
+The arguments will be a list of strings.  
+
+You can access the option values using the 'dest' string you passed in when 
defining the option.
+
+If you need to know whether a given option was set by the user or not, you can
+use the was_set API.
+
+There are example commands in the lldb testsuite at:
+
+llvm-project/lldb/test/API/commands/command/script/add/test_commands.py
+"""
+import inspect
+import lldb
+import sys
+from abc import abstractmethod
+
+class LLDBOVParser:
+def __init__(self):
+# This is a dictionary of dictionaries.  The key is the long option
+# name, and the value is the rest of the definition.
+self.options_dict = {}
+self.args_array = []
+
+# Some methods to translate common value types.  Should return a
+# tuple of the value and an error value (True => error) if the
+# type can't be converted.
+# FIXME: Need a way to push the conversion error string back to lldb.
+@staticmethod
+def to_bool(in_value):
+error = True
+value = False
+if type(in_value) != str or len(in_value) == 0:
+return (value, error)
+
+low_in = in_value.lower()
+if low_in == "y" or low_in == "yes" or low_in == "t" or low_in == 
"true" or low_in == "1":
+value = True
+error = False
+
+if not value and low_in == "n" or low_in == "no" or low_in == "f" or 
low_in == "false" or low_in == "0":
+value = False
+error = False
+
+return (value, error)
+
+@staticmethod
+def to_int(in_value):
+#FIXME: Not doing errors yet...
+return (int(in_value), False)
+
+@staticmethod
+def to_unsigned(in_value):
+# FIXME: find an unsigned converter...
+# And handle errors.
+return (int(in_value), False)
+
+translators = {
+lldb.eArgTypeBoolean : to_bool,
+lldb.eArgTypeBreakpointID : to_unsigned,
+lldb.eArgTypeByteSize : to_unsigned,
+lldb.eArgTypeCount : to_unsigned,
+lldb.eArgTypeFrameIndex : to_unsigned,
+lldb.eArgTypeIndex : to_unsigned,
+lldb.eArgTypeLineNum : to_unsigned,
+lldb.eArgTypeNumLines : to_unsigned,
+lldb.eArgTypeNumberPerLine : to_unsigned,
+lldb.eArgTypeOffset : to_int,
+lldb.eArgTypeThreadIndex : to_unsigned,
+lldb.eArgTypeUnsignedInteger : to_unsigned,
+lldb.eArgTypeWatchpointID : to_unsigned,
+lldb.eArgTypeColumnNum : to_unsigned,
+lldb.eArgTypeRecognizerID : to_unsigned,
+lldb.eArgTypeTargetID : to_unsigned,
+lldb.eArgTypeStopHookID : to_unsigned
+}
+
+@classmethod
+def translate_value(cls, value_type, value):
+try:
+return cls.translators[value_type](value)
+except KeyError:
+# If we don't have a translator, return the string value.
+return (value, False)
+
+# FIXME: would this be better done on the C++ side?
+# The common completers are missing some useful ones.
+# For instance there really should be a common Type completer
+# And an "lldb command name" completer.
+completion_table = {
+lldb.eArgTypeAddressOrExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeArchitecture : lldb.eArchitectureCompletion,
+lldb.eArgTypeBreakpointID : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointIDRange : lldb.eBreakpointCompletion,
+lldb.eArgTypeBreakpointName : lldb.eBreakpointNameCompletion,
+lldb.eArgTypeClassName : lldb.eSymbolCompletion,
+lldb.eArgTypeDirectoryName : lldb.eDiskDirectoryCompletion,
+lldb.eArgTypeExpression : lldb.eVariablePathCompletion,
+lldb.eArgTypeExpressionPath : lldb.eVariablePathCompletion,
+lldb.eArgTypeFilename : lldb.eDiskFileCompletion,
+lldb.eArgTypeFrameIndex : lldb.eFrameIndex

[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread via lldb-commits


@@ -831,6 +831,37 @@ bool 
lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject(
   return true;
 }
 
+bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject(
+PyObject *implementor, lldb::DebuggerSP debugger, 
lldb_private::StructuredDataImpl &args_impl,

jimingham wrote:

Note, whoever spelt this originally was sure implementor was what they wanted 
to use, the C++ files use the same spelling.

https://github.com/llvm/llvm-project/pull/70734
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define a Python based command that uses CommandObjectParsed (PR #70734)

2024-02-06 Thread via lldb-commits


@@ -0,0 +1,315 @@
+"""
+This module implements a couple of utility classes to make writing
+lldb parsed commands more Pythonic.
+The way to use it is to make a class for you command that inherits from 
ParsedCommandBase.

jimingham wrote:

I converted the lldb/examples/python/cmdtemplate.py to the new form in the 
latest patch, if you want to get a sense of what you have to do to convert from 
one form to the other.  I think this is pretty straightforward.  But it also 
can't be a straight translation because you need to be able to specify the 
lldb.eArgType... .  Anyway, have a look at the diff between the two, and if you 
can think of anything to make this easier, I'm happy for suggestions (maybe as 
a follow-on patch, if this looks roughly okay, however...)

https://github.com/llvm/llvm-project/pull/70734
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread via lldb-commits


@@ -2687,7 +2687,7 @@ uint64_t SymbolFileDWARF::GetDebugInfoSize() {
 if (cu == nullptr)
   continue;
 
-SymbolFileDWARFDwo *dwo = cu->GetDwoSymbolFile();
+SymbolFileDWARFDwo *dwo = cu->GetDwoSymbolFile(false);

kusmour wrote:

In that case I will leave this commit out of this PR and start a separate one :)

https://github.com/llvm/llvm-project/pull/80745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread via lldb-commits

https://github.com/kusmour updated 
https://github.com/llvm/llvm-project/pull/80745

>From e5902abd4cd401f5e6a132d1fa5d0b2197512494 Mon Sep 17 00:00:00 2001
From: Wanyi Ye 
Date: Fri, 2 Feb 2024 15:42:01 -0800
Subject: [PATCH 1/4] Support statistics dump summary only mode

Summary:
Added a new --summary option to statistics dump command so that it is much 
light weight than the full version.
With this change, statistics dump --summary can now be included in lldb command 
line telemetry without slowing down lldb exiting.
---
 lldb/include/lldb/API/SBTarget.h  |   6 +-
 lldb/include/lldb/Target/Statistics.h |   9 +-
 lldb/include/lldb/Target/Target.h |   2 +-
 lldb/source/API/SBTarget.cpp  |   9 +-
 lldb/source/Commands/CommandObjectStats.cpp   |   8 +-
 lldb/source/Commands/Options.td   |   3 +
 lldb/source/Target/Statistics.cpp | 194 +++---
 lldb/source/Target/Target.cpp |   4 +-
 .../stats_api/TestStatisticsAPI.py|  15 ++
 9 files changed, 163 insertions(+), 87 deletions(-)

diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 83087623088c5b..72b8997afd2704 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -86,9 +86,13 @@ class LLDB_API SBTarget {
 
   /// Returns a dump of the collected statistics.
   ///
+  /// \param[in] summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// A SBStructuredData with the statistics collected.
-  lldb::SBStructuredData GetStatistics();
+  lldb::SBStructuredData GetStatistics(bool summary_only = false);
 
   /// Return the platform object associated with the target.
   ///
diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index f672786f58f84d..98658ba0cac317 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,7 +133,7 @@ struct ConstStringStats {
 /// A class that represents statistics for a since lldb_private::Target.
 class TargetStats {
 public:
-  llvm::json::Value ToJSON(Target &target);
+  llvm::json::Value ToJSON(Target &target, bool summary_only = false);
 
   void SetLaunchOrAttachTime();
   void SetFirstPrivateStopTime();
@@ -171,9 +171,14 @@ class DebuggerStats {
   ///   The single target to emit statistics for if non NULL, otherwise dump
   ///   statistics only for the specified target.
   ///
+  /// \param summary_only
+  ///   If true, only report high level summary statistics without
+  ///   targets/modules/breakpoints etc.. details.
+  ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  static llvm::json::Value ReportStatistics(Debugger &debugger, Target 
*target);
+  static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target,
+bool summary_only = false);
 
 protected:
   // Collecting stats can be set to true to collect stats that are expensive
diff --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index c37682e2a03859..4bf6c123dc1ddc 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1599,7 +1599,7 @@ class Target : public 
std::enable_shared_from_this,
   ///
   /// \return
   /// Returns a JSON value that contains all target metrics.
-  llvm::json::Value ReportStatistics();
+  llvm::json::Value ReportStatistics(bool summary_only = false);
 
   TargetStats &GetStatistics() { return m_stats; }
 
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 8e616afbcb4e8d..615a00ceeaee16 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -197,7 +197,7 @@ SBDebugger SBTarget::GetDebugger() const {
   return debugger;
 }
 
-SBStructuredData SBTarget::GetStatistics() {
+SBStructuredData SBTarget::GetStatistics(bool summary_only) {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData data;
@@ -205,9 +205,10 @@ SBStructuredData SBTarget::GetStatistics() {
   if (!target_sp)
 return data;
   std::string json_str =
-  llvm::formatv("{0:2}",
-  DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
-  target_sp.get())).str();
+  llvm::formatv(
+  "{0:2}", DebuggerStats::ReportStatistics(
+   target_sp->GetDebugger(), target_sp.get(), 
summary_only))
+  .str();
   data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
   return data;
 }
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 262de0bda144a6..781b90794dc377 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -75,6 +75,9 @@ class CommandObjectStatsDump : public CommandObjectParsed {
 

[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Jason Molenda via lldb-commits


@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
 Global,
 DefaultTrue,
 Desc<"Control the use of external tools and repositories to locate symbol 
files. Directories listed in target.debug-file-search-paths and directory of 
the executable are always checked first for separate debug info files. Then 
depending on this setting: On macOS, Spotlight would be also used to locate a 
matching .dSYM bundle based on the UUID of the executable. On NetBSD, directory 
/usr/libdata/debug would be also searched. On platforms other than NetBSD 
directory /usr/lib/debug would be also searched. If all other methods fail 
there may be symbol-locator plugins that, if configured properly, will also 
attempt to acquire symbols. The debuginfod plugin defaults to the 
DEGUFINFOD_URLS environment variable which is configurable through the 
'plugin.symbol-locator.debuginfod.server_urls' setting.">;
-  def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
+  def LazySymbolLookup: Property<"lazy-lookup", "Enum">,

jasonmolenda wrote:

I keep coming back to synonyms for "on demand" but not clear why they are 
different, like "as-needed-symbol-lookup".  Or 
"backtrace-driven-symbol-lookup".  

I don't know if there's any really clear name that could help a first-time user 
to distinguish between the different mechanisms.  We have the existing 
`symbols.load-on-demand` which is really avoiding loading the DWARF for any 
binaries until criteria are met (if I'm reading the docs/use/ondemand.rst 
correctly).  In this case, lldb *has* the DWARF for the binaries locally, it's 
just not reading it until the debug info is needed (with a few caveats like 
"breakpoints by name on inlined functions won't work").

This mechanism is instead "Download the DWARF (dSYM) and executable (if 
possible) from an external server, and load it immediately in to lldb".  For 
instance, you connect to a process on a remote system and none of the binaries 
running on the remote system, e.g. libsystem_c.dylib, exist on the host 
computer.  lldb can use this mechanism to download the correct 
libsystem_c.dylib and libsystem_c.dylib.dSYM to the host computer and load them 
in to lldb.  Instead of doing that for *all* binaries on connect, this allows 
us to avoid hitting the external servers until specific binaries are needed.

I might try to work 'symbol-download' into the setting name, that is a real 
difference between the two.

https://github.com/llvm/llvm-project/pull/80890
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Jonas Devlieghere via lldb-commits


@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
 Global,
 DefaultTrue,
 Desc<"Control the use of external tools and repositories to locate symbol 
files. Directories listed in target.debug-file-search-paths and directory of 
the executable are always checked first for separate debug info files. Then 
depending on this setting: On macOS, Spotlight would be also used to locate a 
matching .dSYM bundle based on the UUID of the executable. On NetBSD, directory 
/usr/libdata/debug would be also searched. On platforms other than NetBSD 
directory /usr/lib/debug would be also searched. If all other methods fail 
there may be symbol-locator plugins that, if configured properly, will also 
attempt to acquire symbols. The debuginfod plugin defaults to the 
DEGUFINFOD_URLS environment variable which is configurable through the 
'plugin.symbol-locator.debuginfod.server_urls' setting.">;
-  def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
+  def LazySymbolLookup: Property<"lazy-lookup", "Enum">,

JDevlieghere wrote:

I like your suggestion. @bulbazord How do you feel about `symbol-download={off, 
background,foreground}`? 

https://github.com/llvm/llvm-project/pull/80890
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere edited 
https://github.com/llvm/llvm-project/pull/80890
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Jason Molenda via lldb-commits

jasonmolenda wrote:

I like this change, this will be a very handy capability for people debugging 
corefiles & live sessions on remote computers when they have a mechanism to 
find the binaries and/or debug info for those processes, without needing to 
download all of them. One change I would also roll in in  
`SymbolLocator::DownloadSymbolFileAsync()` is to request `copy_executable=true` 
here,

```
if (!PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
/*force_lookup=*/true,
/*copy_executable=*/false))
```

So we download both the dSYM and binary for situations where we don't have a 
local binary.

https://github.com/llvm/llvm-project/pull/80890
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Jason Molenda via lldb-commits


@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
 Global,
 DefaultTrue,
 Desc<"Control the use of external tools and repositories to locate symbol 
files. Directories listed in target.debug-file-search-paths and directory of 
the executable are always checked first for separate debug info files. Then 
depending on this setting: On macOS, Spotlight would be also used to locate a 
matching .dSYM bundle based on the UUID of the executable. On NetBSD, directory 
/usr/libdata/debug would be also searched. On platforms other than NetBSD 
directory /usr/lib/debug would be also searched. If all other methods fail 
there may be symbol-locator plugins that, if configured properly, will also 
attempt to acquire symbols. The debuginfod plugin defaults to the 
DEGUFINFOD_URLS environment variable which is configurable through the 
'plugin.symbol-locator.debuginfod.server_urls' setting.">;
-  def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
+  def LazySymbolLookup: Property<"lazy-lookup", "Enum">,

jasonmolenda wrote:

`symbols.download-on-demand` lol it's actually accurate but probably too overly 
clever compared to `symbols.load-on-demand`.

https://github.com/llvm/llvm-project/pull/80890
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread Greg Clayton via lldb-commits

https://github.com/clayborg approved this pull request.

A few nits you can fix if you want to.

https://github.com/llvm/llvm-project/pull/80745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread Greg Clayton via lldb-commits

https://github.com/clayborg edited 
https://github.com/llvm/llvm-project/pull/80745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread Greg Clayton via lldb-commits


@@ -83,13 +86,17 @@ class CommandObjectStatsDump : public CommandObjectParsed {
 
 void OptionParsingStarting(ExecutionContext *execution_context) override {
   m_all_targets = false;
+  m_stats_options = StatisticsOptions();
 }
 
 llvm::ArrayRef GetDefinitions() override {
   return llvm::ArrayRef(g_statistics_dump_options);
 }
 
+StatisticsOptions GetStatisticsOptions() { return m_stats_options; }

clayborg wrote:

return a `const StatisticsOptions&` if you want to. The struct isn't big now, 
so no big deal.

https://github.com/llvm/llvm-project/pull/80745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread Greg Clayton via lldb-commits


@@ -100,60 +101,94 @@ llvm::json::Value ConstStringStats::ToJSON() const {
   return obj;
 }
 
-json::Value TargetStats::ToJSON(Target &target) {
-  CollectStats(target);
+json::Value
+TargetStats::ToJSON(Target &target,
+const lldb_private::StatisticsOptions &options) {
+  json::Object target_metrics_json;
+  ProcessSP process_sp = target.GetProcessSP();
+  bool summary_only = options.summary_only;

clayborg wrote:

`const bool ...`

https://github.com/llvm/llvm-project/pull/80745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Support statistics dump summary only mode (PR #80745)

2024-02-06 Thread Greg Clayton via lldb-commits


@@ -184,8 +219,12 @@ void TargetStats::IncreaseSourceMapDeduceCount() {
 
 bool DebuggerStats::g_collecting_stats = false;
 
-llvm::json::Value DebuggerStats::ReportStatistics(Debugger &debugger,
-  Target *target) {
+llvm::json::Value DebuggerStats::ReportStatistics(
+Debugger &debugger, Target *target,
+const lldb_private::StatisticsOptions &options) {
+
+  bool summary_only = options.summary_only;

clayborg wrote:

`const bool ...`

https://github.com/llvm/llvm-project/pull/80745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/80890

>From d0696a22e07678e8b7a0dd78df0c873aa89deacb Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 6 Feb 2024 16:25:37 -0800
Subject: [PATCH] [lldb] Expand background symbol lookup

LLDB has a setting (symbols.enable-background-lookup) that calls
dsymForUUID on a background thread for images as they appear in the
current backtrace. Originally, the laziness of only looking up symbols
for images in the backtrace only existed to bring the number of
dsymForUUID calls down to a manageable number.

Users have requesting the same functionality but blocking. This gives
them the same user experience as enabling dsymForUUID globally, but
without the massive upfront cost of having to download all the images,
the majority of which they'll likely not need.

This patch renames the setting to have a more generic name
(symbols.download) and changes its values from a boolean to an enum.
Users can now specify "off", "background" and "foreground". The default
remains "off" although I'll probably change that in the near future.
---
 lldb/include/lldb/Core/ModuleList.h   | 23 ++-
 lldb/include/lldb/lldb-enumerations.h |  6 ++
 lldb/source/Core/CoreProperties.td|  7 ---
 lldb/source/Core/ModuleList.cpp   |  9 +
 lldb/source/Host/common/Host.cpp  |  2 ++
 lldb/source/Symbol/SymbolLocator.cpp  | 22 --
 6 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/lldb/include/lldb/Core/ModuleList.h 
b/lldb/include/lldb/Core/ModuleList.h
index d78f7c5ef3f70..6e8f840e157bc 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -47,6 +47,26 @@ class UUID;
 class VariableList;
 struct ModuleFunctionSearchOptions;
 
+static constexpr OptionEnumValueElement g_download_enum_values[] = {
+{
+lldb::eSymbolDownloadOff,
+"off",
+"Disable downloading symbols.",
+},
+{
+lldb::eSymbolDownloadBackground,
+"background",
+"Download symbols in the background for images as they appear in the "
+"backtrace.",
+},
+{
+lldb::eSymbolDownloadForeground,
+"foreground",
+"Download symbols in the foreground for images as they appear in the "
+"backtrace.",
+},
+};
+
 class ModuleListProperties : public Properties {
   mutable llvm::sys::RWMutex m_symlink_paths_mutex;
   PathMappingList m_symlink_paths;
@@ -60,7 +80,6 @@ class ModuleListProperties : public Properties {
   bool SetClangModulesCachePath(const FileSpec &path);
   bool GetEnableExternalLookup() const;
   bool SetEnableExternalLookup(bool new_value);
-  bool GetEnableBackgroundLookup() const;
   bool GetEnableLLDBIndexCache() const;
   bool SetEnableLLDBIndexCache(bool new_value);
   uint64_t GetLLDBIndexCacheMaxByteSize();
@@ -71,6 +90,8 @@ class ModuleListProperties : public Properties {
 
   bool GetLoadSymbolOnDemand();
 
+  lldb::SymbolDownload GetSymbolDownload() const;
+
   PathMappingList GetSymlinkMappings() const;
 };
 
diff --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index 392d333c23a44..da5cfc5d9b6cb 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -1305,6 +1305,12 @@ enum CompletionType {
   eTerminatorCompletion = (1ul << 27)
 };
 
+enum SymbolDownload {
+  eSymbolDownloadOff = 0,
+  eSymbolDownloadBackground = 1,
+  eSymbolDownloadForeground = 2,
+};
+
 } // namespace lldb
 
 #endif // LLDB_LLDB_ENUMERATIONS_H
diff --git a/lldb/source/Core/CoreProperties.td 
b/lldb/source/Core/CoreProperties.td
index 8d81967bdb50a..fa308d8c522fd 100644
--- a/lldb/source/Core/CoreProperties.td
+++ b/lldb/source/Core/CoreProperties.td
@@ -5,10 +5,11 @@ let Definition = "modulelist" in {
 Global,
 DefaultTrue,
 Desc<"Control the use of external tools and repositories to locate symbol 
files. Directories listed in target.debug-file-search-paths and directory of 
the executable are always checked first for separate debug info files. Then 
depending on this setting: On macOS, Spotlight would be also used to locate a 
matching .dSYM bundle based on the UUID of the executable. On NetBSD, directory 
/usr/libdata/debug would be also searched. On platforms other than NetBSD 
directory /usr/lib/debug would be also searched. If all other methods fail 
there may be symbol-locator plugins that, if configured properly, will also 
attempt to acquire symbols. The debuginfod plugin defaults to the 
DEGUFINFOD_URLS environment variable which is configurable through the 
'plugin.symbol-locator.debuginfod.server_urls' setting.">;
-  def EnableBackgroundLookup: Property<"enable-background-lookup", "Boolean">,
+  def Download: Property<"download", "Enum">,
 Global,
-DefaultFalse,
-Desc<"On macOS, enable calling dsymForUUID (or an equivalent 
script/binary) in the background to locate symbol 

[Lldb-commits] [lldb] [lldb] Expand background symbol lookup (PR #80890)

2024-02-06 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere edited 
https://github.com/llvm/llvm-project/pull/80890
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


  1   2   >