[Lldb-commits] [lldb] [lldb] Refactor string manipulation in Debugger.cpp (#91209) (PR #92565)

2024-05-21 Thread Augusto Noronha via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] UpdateFormatsIfNeeded should respect the dynamic value type (PR #93262)

2024-05-23 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/93262

UpdateFormatsIfNeeded has hardcoded the call to GetFormat with no dynamic 
values. GetFormat will try to find the synthetic children of the ValueObject, 
and passing the wrong one can fail, which can be bad for performance but should 
not be user visible. Fix the performace bug by passing the dynamic value type 
of the ValueObject.

rdar://122506593

>From d698ba1ce41d04526dfc2d8abe69c673d524afa4 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Thu, 23 May 2024 17:30:47 -0700
Subject: [PATCH] [lldb] UpdateFormatsIfNeeded should respect the dynamic value
 type

UpdateFormatsIfNeeded has hardcoded the call to GetFormat with no
dynamic values. GetFormat will try to find the synthetic children of the
ValueObject, and passing the wrong one can fail, which can be bad for
performance but should not be user visible. Fix the performace bug by
passing the dynamic value type of the ValueObject.

rdar://122506593
---
 lldb/source/Core/ValueObject.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 1443d9dfc3280..c5c434a941b34 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -216,7 +216,7 @@ bool ValueObject::UpdateFormatsIfNeeded() {
 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
 any_change = true;
 
-SetValueFormat(DataVisualization::GetFormat(*this, eNoDynamicValues));
+SetValueFormat(DataVisualization::GetFormat(*this, GetDynamicValueType()));
 SetSummaryFormat(
 DataVisualization::GetSummaryFormat(*this, GetDynamicValueType()));
 SetSyntheticChildren(

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


[Lldb-commits] [lldb] [lldb] Use packaging module instead of pkg_resources (PR #93712)

2024-05-29 Thread Augusto Noronha via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] UpdateFormatsIfNeeded should respect the dynamic value type (PR #93262)

2024-06-05 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-12 Thread Augusto Noronha via lldb-commits

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

I think overall this looks good! Just some small things to fix.

Could you run `ninja check-lldb` from your build folder to make sure this 
change doesn't break anything?

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-12 Thread Augusto Noronha via lldb-commits


@@ -799,20 +803,21 @@ IRExecutionUnit::FindInSymbols(const 
std::vector &names,
   sc_list);
   if (auto load_addr = resolver.Resolve(sc_list))
 return *load_addr;
-}
 
-if (sc.target_sp) {
-  SymbolContextList sc_list;
-  sc.target_sp->GetImages().FindFunctions(name, 
lldb::eFunctionNameTypeFull,
-  function_options, sc_list);
+  sc.module_sp->FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
+   sc_list);
   if (auto load_addr = resolver.Resolve(sc_list))
 return *load_addr;
 }
 
-if (sc.target_sp) {
+{

augusto2112 wrote:

Since you removed the check here, you can remove the parenthesis as well.

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-12 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-12 Thread Augusto Noronha via lldb-commits


@@ -785,6 +785,10 @@ IRExecutionUnit::FindInSymbols(const 
std::vector &names,
 return LLDB_INVALID_ADDRESS;
   }
 
+  ModuleList images = target->GetImages();

augusto2112 wrote:

Check if `target` is null before accessing it.

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-12 Thread Augusto Noronha via lldb-commits


@@ -785,6 +785,10 @@ IRExecutionUnit::FindInSymbols(const 
std::vector &names,
 return LLDB_INVALID_ADDRESS;
   }
 
+  ModuleList images = target->GetImages();

augusto2112 wrote:

Oh, looks like target is already checked right before this, disregard this 
comment

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-12 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

@DmT021  I think you can update this patch and set it ready for review then :)

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-12 Thread Augusto Noronha via lldb-commits

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


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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-12 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

I agree that passing some sort of "hint" object to prioritize the search would 
be a more complete solution, but since this is @DmT021's first contribution to 
LLVM I think we should merge this change if there are no concerns with the 
current implementation, and if @DmT021 wants to expand on a more general 
solution for the `Find...` family of functions he could work on that on a 
separate patch.

@clayborg I can see how a module could be used as a hint, but I'm not sure how 
we'd prioritize lookups using functions or compile unit. The code in 
`SymTab.cpp` does a binary search to find the symbol, how could we restrict 
this further by passing a function hint, for example?

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-13 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

> > @clayborg I can see how a module could be used as a hint, but I'm not sure 
> > how we'd prioritize lookups using functions or compile unit. The code in 
> > `SymTab.cpp` does a binary search to find the symbol, how could we restrict 
> > this further by passing a function hint, for example?
> 
> For symbol lookups, we would only check the Module. If there is not module, 
> we would just search through the target's image list. If there was a module, 
> then we search it first, and avoid that module if we search the module list 
> just by checking the pointer of the module when iterating over the target's 
> module list. The full symbol context isn't required, but it would be nice to 
> set the precedent that others can duplicate when doing lookups of other kinds.

If that's the case, personally I think that it would make more sense if 
`FindFunctions` and `FindSymbolsWithNameAndType` took in a module because it 
wouldn't be possible to pass in something that doesn't make sense to those 
functions (like a symbol context with only a compile unit set, for example).

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-13 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

> Oh, wait a sec. I actually changed the behavior of the 
> `IRExecutionUnit::FindInSymbols`. It used to exit early if the function was 
> found in `module_sp`, but now we will always scan through the whole 
> ModuleList. And we can't change the behavior of the 
> `ModuleList::FindFunctions` to return after the first match, because it might 
> be not what we want in general case. Maybe I should add more generic versions 
> of these functions taking a callback to invoke on each match instead of 
> SymbolContextList? Something like
> 
> ```
> void ModuleList::FindSymbolsWithNameAndType(
>   ConstString name,
>   lldb::SymbolType symbol_type,
>   const SymbolContext *search_hint,
>   llvm::function_ref callback
>   )
> ```
> 
> where the result of `callback` indicates whether the search should be 
> continued or not.

I think it'd be fine to return early if the type if found with the 
`search_hint`, as long as this is clearly documented in the API. My impression 
is that this would be a more useful behavior than just reordering the search 
results so the `search_hint` results are first, and I don't think we need the 
extra flexibility provided by that callback at the moment. I don't touch this 
code very often though so if @clayborg or @Michael137 disagree I'd defer to 
them.

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-13 Thread Augusto Noronha via lldb-commits


@@ -441,14 +441,20 @@ ModuleSP ModuleList::GetModuleAtIndexUnlocked(size_t idx) 
const {
 void ModuleList::FindFunctions(ConstString name,
FunctionNameType name_type_mask,
const ModuleFunctionSearchOptions &options,
+   const SymbolContext &sc,
SymbolContextList &sc_list) const {
   const size_t old_size = sc_list.GetSize();
 
   if (name_type_mask & eFunctionNameTypeAuto) {
 Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
 
 std::lock_guard guard(m_modules_mutex);
+if (sc.module_sp)

augusto2112 wrote:

Should we assert that the module_sp belongs to the module list?

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-13 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

> > > > Oh, wait a sec. I actually changed the behavior of the 
> > > > `IRExecutionUnit::FindInSymbols`. It used to exit early if the function 
> > > > was found in `module_sp`, but now we will always scan through the whole 
> > > > ModuleList. And we can't change the behavior of the 
> > > > `ModuleList::FindFunctions` to return after the first match, because it 
> > > > might be not what we want in general case. Maybe I should add more 
> > > > generic versions of these functions taking a callback to invoke on each 
> > > > match instead of SymbolContextList? Something like
> > > > ```
> > > > void ModuleList::FindSymbolsWithNameAndType(
> > > >   ConstString name,
> > > >   lldb::SymbolType symbol_type,
> > > >   const SymbolContext *search_hint,
> > > >   llvm::function_ref callback
> > > >   )
> > > > ```
> > > > 
> > > > 
> > > > 
> > > >   
> > > > 
> > > > 
> > > >   
> > > > 
> > > > 
> > > > 
> > > >   
> > > > where the result of `callback` indicates whether the search should be 
> > > > continued or not.
> > > 
> > > 
> > > I think it'd be fine to return early if the type if found with the 
> > > `search_hint`, as long as this is clearly documented in the API. My 
> > > impression is that this would be a more useful behavior than just 
> > > reordering the search results so the `search_hint` results are first, and 
> > > I don't think we need the extra flexibility provided by that callback at 
> > > the moment. I don't touch this code very often though so if @clayborg or 
> > > @Michael137 disagree I'd defer to them.
> > 
> > 
> > Probably fine returning early unconditionally tbh, but only if the 
> > `search_hint` is specified. It shouldn't break anything?
> 
> It wouldn't be that good API then, because the function takes an optional 
> argument that changes the behavior significantly:
> 
> * when it's provided the function returns a single result(which means we 
> don't really need `SymbolContextList`)
> * when it's NULL, the function will find all the matches



> > > > Oh, wait a sec. I actually changed the behavior of the 
> > > > `IRExecutionUnit::FindInSymbols`. It used to exit early if the function 
> > > > was found in `module_sp`, but now we will always scan through the whole 
> > > > ModuleList. And we can't change the behavior of the 
> > > > `ModuleList::FindFunctions` to return after the first match, because it 
> > > > might be not what we want in general case. Maybe I should add more 
> > > > generic versions of these functions taking a callback to invoke on each 
> > > > match instead of SymbolContextList? Something like
> > > > ```
> > > > void ModuleList::FindSymbolsWithNameAndType(
> > > >   ConstString name,
> > > >   lldb::SymbolType symbol_type,
> > > >   const SymbolContext *search_hint,
> > > >   llvm::function_ref callback
> > > >   )
> > > > ```
> > > > 
> > > > 
> > > > 
> > > >   
> > > > 
> > > > 
> > > >   
> > > > 
> > > > 
> > > > 
> > > >   
> > > > where the result of `callback` indicates whether the search should be 
> > > > continued or not.
> > > 
> > > 
> > > I think it'd be fine to return early if the type if found with the 
> > > `search_hint`, as long as this is clearly documented in the API. My 
> > > impression is that this would be a more useful behavior than just 
> > > reordering the search results so the `search_hint` results are first, and 
> > > I don't think we need the extra flexibility provided by that callback at 
> > > the moment. I don't touch this code very often though so if @clayborg or 
> > > @Michael137 disagree I'd defer to them.
> > 
> > 
> > Probably fine returning early unconditionally tbh, but only if the 
> > `search_hint` is specified. It shouldn't break anything?
> 
> It wouldn't be that good API then, because the function takes an optional 
> argument that changes the behavior significantly:
> 
> * when it's provided the function returns a single result(which means we 
> don't really need `SymbolContextList`)
> * when it's NULL, the function will find all the matches

Then you probably want to implement something similar to `FindTypes` which 
takes in a `TypeQuery`, like @Michael137 said.

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


[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

2024-08-21 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

I agree with Michael, I think just adding the search hint and clearly 
documenting it would already be a great improvement and would make implementing 
this patch a lot simpler.

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


[Lldb-commits] [lldb] Add logs for SymbolFileDWARF::FindTypes (PR #106030)

2024-08-26 Thread Augusto Noronha via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Implement DiagnosticManager::Consume (PR #74011)

2023-11-30 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/74011

In some situations it may be useful to have a separate DiagnosticManager 
instance, and then later of move the contents of that instance back to the 
"main" DiagnosticManager. For example, when silently retrying some operation 
with different parameters, depending on whether the retry succeeded or failed, 
LLDB may want to present a different set of diagnostics to the user (the ones 
generated on the first try vs the retry). Implement DiagnosticManager::Consume 
to allow for this use case.

>From 7fdc9832d3a0c9024d867f8cdc35706d0a8b643e Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Wed, 29 Nov 2023 17:30:12 -0800
Subject: [PATCH] [NFC][lldb] Implement DiagnosticManager::Consume

In some situations it may be useful to have a separate DiagnosticManager
instance, and then later of move the contents of that instance back to
the "main" DiagnosticManager. For example, when silently retrying some
operation with different parameters, depending on whether the retry
succeeded or failed, LLDB may want to present a different set of
diagnostics to the user (the ones generated on the first try vs the
retry). Implement DiagnosticManager::Consume to allow for this use case.
---
 lldb/include/lldb/Expression/DiagnosticManager.h | 9 +
 1 file changed, 9 insertions(+)

diff --git a/lldb/include/lldb/Expression/DiagnosticManager.h 
b/lldb/include/lldb/Expression/DiagnosticManager.h
index df9ba3b245f51e8..06bf1d115f15419 100644
--- a/lldb/include/lldb/Expression/DiagnosticManager.h
+++ b/lldb/include/lldb/Expression/DiagnosticManager.h
@@ -118,6 +118,15 @@ class DiagnosticManager {
   m_diagnostics.push_back(std::move(diagnostic));
   }
 
+  /// Moves over the contents of a second diagnostic manager over. Leaves other
+  /// diagnostic manager in an empty state.
+  void Consume(DiagnosticManager &&other) {
+std::move(other.m_diagnostics.begin(), other.m_diagnostics.end(),
+  std::back_inserter(m_diagnostics));
+m_fixed_expression = std::move(other.m_fixed_expression);
+other.Clear();
+  }
+
   size_t Printf(DiagnosticSeverity severity, const char *format, ...)
   __attribute__((format(printf, 3, 4)));
   void PutString(DiagnosticSeverity severity, llvm::StringRef str);

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


[Lldb-commits] [lldb] [NFC][lldb] Implement DiagnosticManager::Consume (PR #74011)

2023-11-30 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [NFC][lldb] Implement DiagnosticManager::Consume (PR #74011)

2023-12-05 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Disable new TestLocationListLookup when clang version is <= 11 (PR #75102)

2023-12-11 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/75102

The newly introduced LocationListLookupTestCase.test_loclist_expr test fails 
with older clangs.

>From 0ec0f8ddf505ad30f8684e9452ebc4524f50a4b4 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Mon, 11 Dec 2023 13:29:25 -0800
Subject: [PATCH] [lldb] Disable new TestLocationListLookup when clang version
 is <= 11

The newly introduced LocationListLookupTestCase.test_loclist_expr test
fails with older clangs.
---
 .../location-list-lookup/TestLocationListLookup.py   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
index ccee3bfde3f5d..aeb32fcea4c06 100644
--- 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
+++ 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
@@ -43,6 +43,7 @@ def test_loclist_frame_var(self):
 self.build()
 self.check_local_vars(self.launch(), check_expr=False)
 
+@skipIf(compiler="clang", compiler_version=['<=', '11.0'])
 @skipUnlessDarwin
 def test_loclist_expr(self):
 self.build()

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


[Lldb-commits] [lldb] [lldb] Disable new TestLocationListLookup when clang version is <= 11 (PR #75102)

2023-12-11 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 updated 
https://github.com/llvm/llvm-project/pull/75102

>From be91ba6b5b411e2fc6b9a7b49324ef5b20c9e2ed Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Mon, 11 Dec 2023 13:38:04 -0800
Subject: [PATCH] [lldb] Disable new TestLocationListLookup when clang version
 is <= 11

The newly introduced LocationListLookupTestCase.test_loclist_expr test fails 
with older clangs.
---
 .../location-list-lookup/TestLocationListLookup.py   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
index ccee3bfde3f5de..feea14ff355e82 100644
--- 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
+++ 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
@@ -43,6 +43,7 @@ def test_loclist_frame_var(self):
 self.build()
 self.check_local_vars(self.launch(), check_expr=False)
 
+@skipIf(compiler="clang", compiler_version=["<=", "11.0"])
 @skipUnlessDarwin
 def test_loclist_expr(self):
 self.build()

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


[Lldb-commits] [lldb] [lldb] Disable new TestLocationListLookup when clang version is <= 11 (PR #75102)

2023-12-11 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Skip 2 newly introduced tests from running on DWARF2 and clang 11 (PR #75406)

2023-12-13 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/75406

None

>From 2cb9a284a924442c2f9ab8d639268b8154af22a6 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Wed, 13 Dec 2023 15:53:37 -0800
Subject: [PATCH] [lldb] Skip 2 newly introduced tests from running on DWARF2
 and clang 11

---
 .../data-formatter/builtin-formats/TestBuiltinFormats.py   | 1 +
 .../location-list-lookup/TestLocationListLookup.py | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git 
a/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
 
b/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
index 4e0f14d039a743..8c3bdabeaac1ba 100644
--- 
a/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
+++ 
b/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
@@ -19,6 +19,7 @@ def getFormatted(self, format, expr):
 self.assertTrue(result.Succeeded(), result.GetError())
 return result.GetOutput()
 
+@skipIf(dwarf_version=["<", "3"])
 @no_debug_info_test
 @skipIfWindows
 def testAllPlatforms(self):
diff --git 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
index feea14ff355e82..c5f4a7c6dedc19 100644
--- 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
+++ 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
@@ -43,7 +43,8 @@ def test_loclist_frame_var(self):
 self.build()
 self.check_local_vars(self.launch(), check_expr=False)
 
-@skipIf(compiler="clang", compiler_version=["<=", "11.0"])
+@skipIf(dwarf_version=["<", "3"])
+@skipIf(compiler="clang", compiler_version=["<", "12.0"])
 @skipUnlessDarwin
 def test_loclist_expr(self):
 self.build()

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


[Lldb-commits] [lldb] 5f45a87 - [lldb] Print hint if object description is requested but not implemented

2023-08-02 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-08-02T15:33:32-07:00
New Revision: 5f45a87bf029cc4b9815f5f819906198b07e00d1

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

LOG: [lldb] Print hint if object description is requested but not implemented

Lots of users use "po" as their default print command. If the type
doesn't implement the description function the output is often not what
the user wants. Print a hint telling the user that they might prefer
using "p" instead.

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

Added: 
lldb/test/API/lang/objc/objc-po-hint/Makefile
lldb/test/API/lang/objc/objc-po-hint/TestObjcPoHint.py
lldb/test/API/lang/objc/objc-po-hint/main.m

Modified: 
lldb/include/lldb/Core/Debugger.h
lldb/source/Commands/CommandObjectDWIMPrint.cpp
lldb/source/Core/CoreProperties.td
lldb/source/Core/Debugger.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index 239429b75c4260..be16e742a72099 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -321,6 +321,8 @@ class Debugger : public 
std::enable_shared_from_this,
 
   llvm::StringRef GetAutosuggestionAnsiSuffix() const;
 
+  bool GetShowDontUsePoHint() const;
+
   bool GetUseSourceCache() const;
 
   bool SetUseSourceCache(bool use_source_cache);

diff  --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index b2b7f201a5add1..7b168eab9e02d4 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -25,6 +25,8 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FormatVariadic.h"
 
+#include 
+
 using namespace llvm;
 using namespace lldb;
 using namespace lldb_private;
@@ -95,8 +97,46 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command,
   m_expr_options.m_verbosity, m_format_options.GetFormat());
   dump_options.SetHideRootName(suppress_result);
 
+  bool is_po = m_varobj_options.use_objc;
+
   StackFrame *frame = m_exe_ctx.GetFramePtr();
 
+  // Either Swift was explicitly specified, or the frame is Swift.
+  lldb::LanguageType language = m_expr_options.language;
+  if (language == lldb::eLanguageTypeUnknown && frame)
+language = frame->GuessLanguage();
+
+  // Add a hint if object description was requested, but no description
+  // function was implemented.
+  auto maybe_add_hint = [&](llvm::StringRef output) {
+// Identify the default output of object description for Swift and
+// Objective-C
+// ". The regex is:
+// - Start with "<".
+// - Followed by 1 or more non-whitespace characters.
+// - Followed by ": 0x".
+// - Followed by 5 or more hex digits.
+// - Followed by ">".
+// - End with zero or more whitespace characters.
+const std::regex swift_class_regex("^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
+
+if (GetDebugger().GetShowDontUsePoHint() && target_ptr &&
+(language == lldb::eLanguageTypeSwift ||
+ language == lldb::eLanguageTypeObjC) &&
+std::regex_match(output.data(), swift_class_regex)) {
+
+  static bool note_shown = false;
+  if (note_shown)
+return;
+
+  result.GetOutputStream()
+  << "note: object description requested, but type doesn't implement "
+ "a custom object description. Consider using \"p\" instead of "
+ "\"po\" (this note will only be shown once per debug session).\n";
+  note_shown = true;
+}
+  };
+
   // First, try `expr` as the name of a frame variable.
   if (frame) {
 auto valobj_sp = frame->FindVariable(ConstString(expr));
@@ -114,7 +154,15 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command,
 flags, expr);
   }
 
-  valobj_sp->Dump(result.GetOutputStream(), dump_options);
+  if (is_po) {
+StreamString temp_result_stream;
+valobj_sp->Dump(temp_result_stream, dump_options);
+llvm::StringRef output = temp_result_stream.GetString();
+maybe_add_hint(output);
+result.GetOutputStream() << output;
+  } else {
+valobj_sp->Dump(result.GetOutputStream(), dump_options);
+  }
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return true;
 }
@@ -135,8 +183,17 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command,
 expr);
   }
 
-  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
-valobj_sp->Dump(result.GetOutputStream(), dump_options);
+  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) {
+if (is_po) {
+  StreamString temp_result_stream;
+  valobj_sp->Dump(temp_r

[Lldb-commits] [lldb] 318f600 - [lldb] Protect OptionValue accesses from data races

2023-08-04 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-08-04T15:33:46-07:00
New Revision: 318f600722e3cc6745317bb68309f82656c97b27

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

LOG: [lldb] Protect OptionValue accesses from data races

Thread sanitizer is catching data races in OptionValue, protect accesses
to OptionValue with a mutex.

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

Added: 


Modified: 
lldb/include/lldb/Interpreter/OptionValue.h
lldb/source/Interpreter/OptionValue.cpp

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/OptionValue.h 
b/lldb/include/lldb/Interpreter/OptionValue.h
index 4fa0b23042669d..bfbdbead72c66d 100644
--- a/lldb/include/lldb/Interpreter/OptionValue.h
+++ b/lldb/include/lldb/Interpreter/OptionValue.h
@@ -23,6 +23,7 @@
 #include "lldb/lldb-private-enumerations.h"
 #include "lldb/lldb-private-interfaces.h"
 #include "llvm/Support/JSON.h"
+#include 
 
 namespace lldb_private {
 
@@ -70,6 +71,10 @@ class OptionValue {
 
   virtual ~OptionValue() = default;
 
+  OptionValue(const OptionValue &other);
+  
+  OptionValue& operator=(const OptionValue &other);
+
   // Subclasses should override these functions
   virtual Type GetType() const = 0;
 
@@ -382,6 +387,8 @@ class OptionValue {
 
   const FormatEntity::Entry *GetFormatEntity() const;
   const RegularExpression *GetRegexValue() const;
+  
+  mutable std::mutex m_mutex;
 };
 
 } // namespace lldb_private

diff  --git a/lldb/source/Interpreter/OptionValue.cpp 
b/lldb/source/Interpreter/OptionValue.cpp
index 8d429b6bc9cf21..5ff7e3c3208980 100644
--- a/lldb/source/Interpreter/OptionValue.cpp
+++ b/lldb/source/Interpreter/OptionValue.cpp
@@ -15,6 +15,25 @@
 using namespace lldb;
 using namespace lldb_private;
 
+OptionValue::OptionValue(const OptionValue &other) {
+  std::lock_guard lock(other.m_mutex);
+
+  m_parent_wp = other.m_parent_wp;
+  m_callback = other.m_callback;
+  m_value_was_set = other.m_value_was_set;
+
+}
+
+OptionValue& OptionValue::operator=(const OptionValue &other) {
+  std::scoped_lock lock(m_mutex, other.m_mutex);
+
+  m_parent_wp = other.m_parent_wp;
+  m_callback = other.m_callback;
+  m_value_was_set = other.m_value_was_set;
+
+  return *this;
+}
+
 Status OptionValue::SetSubValue(const ExecutionContext *exe_ctx,
 VarSetOperationType op, llvm::StringRef name,
 llvm::StringRef value) {
@@ -252,12 +271,14 @@ const OptionValueUUID *OptionValue::GetAsUUID() const {
 }
 
 std::optional OptionValue::GetBooleanValue() const {
+  std::lock_guard lock(m_mutex);
   if (const OptionValueBoolean *option_value = GetAsBoolean())
 return option_value->GetCurrentValue();
   return {};
 }
 
 bool OptionValue::SetBooleanValue(bool new_value) {
+  std::lock_guard lock(m_mutex);
   if (OptionValueBoolean *option_value = GetAsBoolean()) {
 option_value->SetCurrentValue(new_value);
 return true;
@@ -266,12 +287,14 @@ bool OptionValue::SetBooleanValue(bool new_value) {
 }
 
 std::optional OptionValue::GetCharValue() const {
+  std::lock_guard lock(m_mutex);
   if (const OptionValueChar *option_value = GetAsChar())
 return option_value->GetCurrentValue();
   return {};
 }
 
 bool OptionValue::SetCharValue(char new_value) {
+  std::lock_guard lock(m_mutex);
   if (OptionValueChar *option_value = GetAsChar()) {
 option_value->SetCurrentValue(new_value);
 return true;
@@ -280,12 +303,14 @@ bool OptionValue::SetCharValue(char new_value) {
 }
 
 std::optional OptionValue::GetEnumerationValue() const {
+  std::lock_guard lock(m_mutex);
   if (const OptionValueEnumeration *option_value = GetAsEnumeration())
 return option_value->GetCurrentValue();
   return {};
 }
 
 bool OptionValue::SetEnumerationValue(int64_t value) {
+  std::lock_guard lock(m_mutex);
   if (OptionValueEnumeration *option_value = GetAsEnumeration()) {
 option_value->SetCurrentValue(value);
 return true;
@@ -294,12 +319,14 @@ bool OptionValue::SetEnumerationValue(int64_t value) {
 }
 
 std::optional OptionValue::GetFileSpecValue() const {
+  std::lock_guard lock(m_mutex);
   if (const OptionValueFileSpec *option_value = GetAsFileSpec())
 return option_value->GetCurrentValue();
   return {};
 }
 
 bool OptionValue::SetFileSpecValue(FileSpec file_spec) {
+  std::lock_guard lock(m_mutex);
   if (OptionValueFileSpec *option_value = GetAsFileSpec()) {
 option_value->SetCurrentValue(file_spec, false);
 return true;
@@ -308,6 +335,7 @@ bool OptionValue::SetFileSpecValue(FileSpec file_spec) {
 }
 
 bool OptionValue::AppendFileSpecValue(FileSpec file_spec) {
+  std::lock_guard lock(m_mutex);
   if (OptionValueFileSpecList *option_value = GetAsFileSpecList()) {
 option_value->AppendCurrentValue(file_spec);
 return true;

[Lldb-commits] [lldb] d75dc9a - [lldb] Fix ThreadList::Update not locking the rhs's mutex

2023-08-04 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-08-04T16:01:20-07:00
New Revision: d75dc9a8a86c4f69408dcab3a21416729d14652e

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

LOG: [lldb] Fix ThreadList::Update not locking the rhs's mutex

ThreadList::Update is being caught by thread sanitizer. There's even a
comment on the function that both mutexes should be lock (even though
only the "this" mutex was actually being locked). Fix this by locking
both mutexes.

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

Added: 


Modified: 
lldb/source/Target/ThreadList.cpp

Removed: 




diff  --git a/lldb/source/Target/ThreadList.cpp 
b/lldb/source/Target/ThreadList.cpp
index 006c8648be524a..c5c3f667c90471 100644
--- a/lldb/source/Target/ThreadList.cpp
+++ b/lldb/source/Target/ThreadList.cpp
@@ -736,7 +736,7 @@ void ThreadList::Update(ThreadList &rhs) {
   if (this != &rhs) {
 // Lock both mutexes to make sure neither side changes anyone on us while
 // the assignment occurs
-std::lock_guard guard(GetMutex());
+std::scoped_lock guard(GetMutex(), rhs.GetMutex());
 
 m_process = rhs.m_process;
 m_stop_id = rhs.m_stop_id;



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


[Lldb-commits] [lldb] 4a390a5 - [lldb] Implement ModuleList::Swap

2023-08-15 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-08-15T11:33:34-07:00
New Revision: 4a390a56aeeb521d0eca1fa4cef6837157ea64ab

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

LOG: [lldb] Implement ModuleList::Swap

Added: 


Modified: 
lldb/include/lldb/Core/ModuleList.h
lldb/source/Core/ModuleList.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/ModuleList.h 
b/lldb/include/lldb/Core/ModuleList.h
index 28c1945c83c478..9826dd09e91d71 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -480,6 +480,9 @@ class ModuleList {
   bool AnyOf(
   std::function const &callback) const;
 
+  /// Atomically swaps the contents of this module list with \a other.
+  void Swap(ModuleList &other);
+
 protected:
   // Class typedefs.
   typedef std::vector

diff  --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index d0d0b2050e181c..6cb086f9f55d2c 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -1079,3 +1079,10 @@ bool ModuleList::AnyOf(
 
   return false;
 }
+
+
+void ModuleList::Swap(ModuleList &other) {
+  // scoped_lock locks both mutexes at once.
+  std::scoped_lock lock(m_modules_mutex, other.m_modules_mutex);
+  m_modules.swap(other.m_modules);
+}



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


[Lldb-commits] [lldb] 2241364 - [lldb] Fix data race in PipePosix

2023-08-15 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-08-15T11:30:35-07:00
New Revision: 22413641e236ebee7485ce8bc5880e8d1e41573f

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

LOG: [lldb] Fix data race in PipePosix

Thread sanitizer reports the following data race:

```
WARNING: ThreadSanitizer: data race (pid=43201)
  Write of size 4 at 0x00010520c474 by thread T1 (mutexes: write M0, write M1):
#0 lldb_private::PipePosix::CloseWriteFileDescriptor() PipePosix.cpp:242 
(liblldb.18.0.0git.dylib:arm64+0x414700) (BuildId: 
2983976beb2637b5943bff32fd12eb89320021000e00)
#1 lldb_private::PipePosix::Close() PipePosix.cpp:217 
(liblldb.18.0.0git.dylib:arm64+0x4144e8) (BuildId: 
2983976beb2637b5943bff32fd12eb89320021000e00)
#2 
lldb_private::ConnectionFileDescriptor::Disconnect(lldb_private::Status*) 
ConnectionFileDescriptorPosix.cpp:239 (liblldb.18.0.0git.dylib:arm64+0x40a620) 
(BuildId: 2983976beb2637b5943bff32fd12eb89320021000e00)
#3 lldb_private::Communication::Disconnect(lldb_private::Status*) 
Communication.cpp:61 (liblldb.18.0.0git.dylib:arm64+0x2a9318) (BuildId: 
2983976beb2637b5943bff32fd12eb89320021000e00)
#4 lldb_private::process_gdb_remote::ProcessGDBRemote::DidExit() 
ProcessGDBRemote.cpp:1167 (liblldb.18.0.0git.dylib:arm64+0x8ed984) (BuildId: 
2983976beb2637b5943bff32fd12eb89320021000e00)

  Previous read of size 4 at 0x00010520c474 by main thread (mutexes: write M2, 
write M3):
#0 lldb_private::PipePosix::CanWrite() const PipePosix.cpp:229 
(liblldb.18.0.0git.dylib:arm64+0x4145e4) (BuildId: 
2983976beb2637b5943bff32fd12eb89320021000e00)
#1 
lldb_private::ConnectionFileDescriptor::Disconnect(lldb_private::Status*) 
ConnectionFileDescriptorPosix.cpp:212 (liblldb.18.0.0git.dylib:arm64+0x40a4a8) 
(BuildId: 2983976beb2637b5943bff32fd12eb89320021000e00)
#2 lldb_private::Communication::Disconnect(lldb_private::Status*) 
Communication.cpp:61 (liblldb.18.0.0git.dylib:arm64+0x2a9318) (BuildId: 
2983976beb2637b5943bff32fd12eb89320021000e00)
#3 
lldb_private::process_gdb_remote::GDBRemoteCommunication::WaitForPacketNoLock(StringExtractorGDBRemote&,
 lldb_private::Timeout>, bool) 
GDBRemoteCommunication.cpp:373 (liblldb.18.0.0git.dylib:arm64+0x8b9c48) 
(BuildId: 2983976beb2637b5943bff32fd12eb89320021000e00)
#4 
lldb_private::process_gdb_remote::GDBRemoteCommunication::WaitForPacketNoLock(StringExtractorGDBRemote&,
 lldb_private::Timeout>, bool) 
GDBRemoteCommunication.cpp:243 (liblldb.18.0.0git.dylib:arm64+0x8b9904) 
(BuildId: 2983976beb2637b5943bff32fd12eb89320021000e00)
```

Fix this by adding a mutex to PipePosix.

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

Added: 


Modified: 
lldb/include/lldb/Host/posix/PipePosix.h
lldb/source/Host/posix/PipePosix.cpp

Removed: 




diff  --git a/lldb/include/lldb/Host/posix/PipePosix.h 
b/lldb/include/lldb/Host/posix/PipePosix.h
index 3bdb7431d8c770..ec4c752a24e94c 100644
--- a/lldb/include/lldb/Host/posix/PipePosix.h
+++ b/lldb/include/lldb/Host/posix/PipePosix.h
@@ -8,8 +8,8 @@
 
 #ifndef LLDB_HOST_POSIX_PIPEPOSIX_H
 #define LLDB_HOST_POSIX_PIPEPOSIX_H
-
 #include "lldb/Host/PipeBase.h"
+#include 
 
 namespace lldb_private {
 
@@ -70,7 +70,22 @@ class PipePosix : public PipeBase {
  size_t &bytes_read) override;
 
 private:
+  bool CanReadUnlocked() const;
+  bool CanWriteUnlocked() const;
+
+  int GetReadFileDescriptorUnlocked() const;
+  int GetWriteFileDescriptorUnlocked() const;
+  int ReleaseReadFileDescriptorUnlocked();
+  int ReleaseWriteFileDescriptorUnlocked();
+  void CloseReadFileDescriptorUnlocked();
+  void CloseWriteFileDescriptorUnlocked();
+  void CloseUnlocked();
+
   int m_fds[2];
+
+  /// Mutexes for m_fds;
+  mutable std::mutex m_read_mutex;
+  mutable std::mutex m_write_mutex;
 };
 
 } // namespace lldb_private

diff  --git a/lldb/source/Host/posix/PipePosix.cpp 
b/lldb/source/Host/posix/PipePosix.cpp
index 5e4e8618fa4f14..0050731acb3fcb 100644
--- a/lldb/source/Host/posix/PipePosix.cpp
+++ b/lldb/source/Host/posix/PipePosix.cpp
@@ -65,16 +65,20 @@ PipePosix::PipePosix(PipePosix &&pipe_posix)
 pipe_posix.ReleaseWriteFileDescriptor()} {}
 
 PipePosix &PipePosix::operator=(PipePosix &&pipe_posix) {
+  std::scoped_lock guard(m_read_mutex, m_write_mutex, pipe_posix.m_read_mutex,
+ pipe_posix.m_write_mutex);
+
   PipeBase::operator=(std::move(pipe_posix));
-  m_fds[READ] = pipe_posix.ReleaseReadFileDescriptor();
-  m_fds[WRITE] = pipe_posix.ReleaseWriteFileDescriptor();
+  m_fds[READ] = pipe_posix.ReleaseReadFileDescriptorUnlocke

[Lldb-commits] [lldb] 5d16957 - [lldb] Properly protect the Communication class with reader/writer lock

2023-08-15 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-08-15T15:43:36-07:00
New Revision: 5d16957207ce1bd1a2091f3677e176012009c59a

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

LOG: [lldb] Properly protect the Communication class with reader/writer lock

This patch picks up where https://reviews.llvm.org/D157159 left of, but
allows for concurrent reads/writes, but protects setting up and tearing
down the underlying Connection object.

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

Added: 


Modified: 
lldb/include/lldb/Core/Communication.h
lldb/include/lldb/Core/ThreadedCommunication.h
lldb/source/Core/Communication.cpp
lldb/source/Core/ThreadedCommunication.cpp
lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Communication.h 
b/lldb/include/lldb/Core/Communication.h
index f5f636816cb4f9..7e4ce362acf9a6 100644
--- a/lldb/include/lldb/Core/Communication.h
+++ b/lldb/include/lldb/Core/Communication.h
@@ -16,6 +16,7 @@
 #include "lldb/lldb-types.h"
 
 #include 
+#include 
 #include 
 
 namespace lldb_private {
@@ -46,8 +47,6 @@ class Communication {
   /// The destructor is virtual since this class gets subclassed.
   virtual ~Communication();
 
-  virtual void Clear();
-
   /// Connect using the current connection by passing \a url to its connect
   /// function. string.
   ///
@@ -84,7 +83,10 @@ class Communication {
 
   bool HasConnection() const;
 
-  lldb_private::Connection *GetConnection() { return m_connection_sp.get(); }
+  lldb_private::Connection *GetConnection() {
+std::shared_lock guard(m_connection_mutex);
+return m_connection_sp.get();
+  }
 
   /// Read bytes from the current connection.
   ///
@@ -169,13 +171,24 @@ class Communication {
   ///by this communications class.
   std::mutex
   m_write_mutex; ///< Don't let multiple threads write at the same time...
+  mutable std::shared_mutex m_connection_mutex;
   bool m_close_on_eof;
 
+  /// Same as read but with m_connection_mutex unlocked.
+  size_t ReadUnlocked(void *dst, size_t dst_len,
+  const Timeout &timeout,
+  lldb::ConnectionStatus &status, Status *error_ptr);
+
   size_t ReadFromConnection(void *dst, size_t dst_len,
 const Timeout &timeout,
 lldb::ConnectionStatus &status, Status *error_ptr);
 
 private:
+  /// Same as Disconnect but with with m_connection_mutex unlocked.
+  lldb::ConnectionStatus DisconnectUnlocked(Status *error_ptr = nullptr);
+  /// Same as Write but with both m_write_mutex and m_connection_mutex 
unlocked.
+  size_t WriteUnlocked(const void *src, size_t src_len,
+   lldb::ConnectionStatus &status, Status *error_ptr);
   Communication(const Communication &) = delete;
   const Communication &operator=(const Communication &) = delete;
 };

diff  --git a/lldb/include/lldb/Core/ThreadedCommunication.h 
b/lldb/include/lldb/Core/ThreadedCommunication.h
index 7ebb77beb77f3d..170fd2dfcb555d 100644
--- a/lldb/include/lldb/Core/ThreadedCommunication.h
+++ b/lldb/include/lldb/Core/ThreadedCommunication.h
@@ -97,8 +97,6 @@ class ThreadedCommunication : public Communication, public 
Broadcaster {
   /// The destructor is virtual since this class gets subclassed.
   ~ThreadedCommunication() override;
 
-  void Clear() override;
-
   /// Disconnect the communications connection if one is currently connected.
   ///
   /// \return

diff  --git a/lldb/source/Core/Communication.cpp 
b/lldb/source/Core/Communication.cpp
index 5d890632ccc6a9..e2ba461a02329a 100644
--- a/lldb/source/Core/Communication.cpp
+++ b/lldb/source/Core/Communication.cpp
@@ -27,110 +27,110 @@ using namespace lldb;
 using namespace lldb_private;
 
 Communication::Communication()
-: m_connection_sp(), m_write_mutex(), m_close_on_eof(true) {
-}
-
-Communication::~Communication() {
-  Clear();
-}
+: m_connection_sp(), m_connection_mutex(), m_close_on_eof(true) {}
 
-void Communication::Clear() {
-  Disconnect(nullptr);
-}
+Communication::~Communication() { Disconnect(nullptr); }
 
 ConnectionStatus Communication::Connect(const char *url, Status *error_ptr) {
-  Clear();
+  std::unique_lock guard(m_connection_mutex);
 
   LLDB_LOG(GetLog(LLDBLog::Communication),
"{0} Communication::Connect (url = {1})", this, url);
 
-  lldb::ConnectionSP connection_sp(m_connection_sp);
-  if (connection_sp)
-return connection_sp->Connect(url, error_ptr);
+  DisconnectUnlocked();
+
+  if (m_connection_sp)
+return m_connection_sp->Connect(url, error_ptr);
   if (error_ptr)
 error_ptr->SetErrorString("Invalid connection.");
   return eConnectionStatusNoConnection;
 }
 
 ConnectionStatus Comm

[Lldb-commits] [lldb] 3b91957 - Revert "[lldb] Properly protect the Communication class with reader/writer lock"

2023-08-15 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-08-15T16:03:28-07:00
New Revision: 3b919570f2f08581987de7851f3673352afb1578

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

LOG: Revert "[lldb] Properly protect the Communication class with reader/writer 
lock"

This reverts commit 5d16957207ce1bd1a2091f3677e176012009c59a.

Added: 


Modified: 
lldb/include/lldb/Core/Communication.h
lldb/include/lldb/Core/ThreadedCommunication.h
lldb/source/Core/Communication.cpp
lldb/source/Core/ThreadedCommunication.cpp
lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Communication.h 
b/lldb/include/lldb/Core/Communication.h
index 7e4ce362acf9a6..f5f636816cb4f9 100644
--- a/lldb/include/lldb/Core/Communication.h
+++ b/lldb/include/lldb/Core/Communication.h
@@ -16,7 +16,6 @@
 #include "lldb/lldb-types.h"
 
 #include 
-#include 
 #include 
 
 namespace lldb_private {
@@ -47,6 +46,8 @@ class Communication {
   /// The destructor is virtual since this class gets subclassed.
   virtual ~Communication();
 
+  virtual void Clear();
+
   /// Connect using the current connection by passing \a url to its connect
   /// function. string.
   ///
@@ -83,10 +84,7 @@ class Communication {
 
   bool HasConnection() const;
 
-  lldb_private::Connection *GetConnection() {
-std::shared_lock guard(m_connection_mutex);
-return m_connection_sp.get();
-  }
+  lldb_private::Connection *GetConnection() { return m_connection_sp.get(); }
 
   /// Read bytes from the current connection.
   ///
@@ -171,24 +169,13 @@ class Communication {
   ///by this communications class.
   std::mutex
   m_write_mutex; ///< Don't let multiple threads write at the same time...
-  mutable std::shared_mutex m_connection_mutex;
   bool m_close_on_eof;
 
-  /// Same as read but with m_connection_mutex unlocked.
-  size_t ReadUnlocked(void *dst, size_t dst_len,
-  const Timeout &timeout,
-  lldb::ConnectionStatus &status, Status *error_ptr);
-
   size_t ReadFromConnection(void *dst, size_t dst_len,
 const Timeout &timeout,
 lldb::ConnectionStatus &status, Status *error_ptr);
 
 private:
-  /// Same as Disconnect but with with m_connection_mutex unlocked.
-  lldb::ConnectionStatus DisconnectUnlocked(Status *error_ptr = nullptr);
-  /// Same as Write but with both m_write_mutex and m_connection_mutex 
unlocked.
-  size_t WriteUnlocked(const void *src, size_t src_len,
-   lldb::ConnectionStatus &status, Status *error_ptr);
   Communication(const Communication &) = delete;
   const Communication &operator=(const Communication &) = delete;
 };

diff  --git a/lldb/include/lldb/Core/ThreadedCommunication.h 
b/lldb/include/lldb/Core/ThreadedCommunication.h
index 170fd2dfcb555d..7ebb77beb77f3d 100644
--- a/lldb/include/lldb/Core/ThreadedCommunication.h
+++ b/lldb/include/lldb/Core/ThreadedCommunication.h
@@ -97,6 +97,8 @@ class ThreadedCommunication : public Communication, public 
Broadcaster {
   /// The destructor is virtual since this class gets subclassed.
   ~ThreadedCommunication() override;
 
+  void Clear() override;
+
   /// Disconnect the communications connection if one is currently connected.
   ///
   /// \return

diff  --git a/lldb/source/Core/Communication.cpp 
b/lldb/source/Core/Communication.cpp
index e2ba461a02329a..5d890632ccc6a9 100644
--- a/lldb/source/Core/Communication.cpp
+++ b/lldb/source/Core/Communication.cpp
@@ -27,110 +27,110 @@ using namespace lldb;
 using namespace lldb_private;
 
 Communication::Communication()
-: m_connection_sp(), m_connection_mutex(), m_close_on_eof(true) {}
+: m_connection_sp(), m_write_mutex(), m_close_on_eof(true) {
+}
+
+Communication::~Communication() {
+  Clear();
+}
 
-Communication::~Communication() { Disconnect(nullptr); }
+void Communication::Clear() {
+  Disconnect(nullptr);
+}
 
 ConnectionStatus Communication::Connect(const char *url, Status *error_ptr) {
-  std::unique_lock guard(m_connection_mutex);
+  Clear();
 
   LLDB_LOG(GetLog(LLDBLog::Communication),
"{0} Communication::Connect (url = {1})", this, url);
 
-  DisconnectUnlocked();
-
-  if (m_connection_sp)
-return m_connection_sp->Connect(url, error_ptr);
+  lldb::ConnectionSP connection_sp(m_connection_sp);
+  if (connection_sp)
+return connection_sp->Connect(url, error_ptr);
   if (error_ptr)
 error_ptr->SetErrorString("Invalid connection.");
   return eConnectionStatusNoConnection;
 }
 
 ConnectionStatus Communication::Disconnect(Status *error_ptr) {
-  std::unique_lock guard(m_connection_mutex);
-  return DisconnectUnlocked(error_ptr);
-}
-
-ConnectionStatus Communication:

[Lldb-commits] [lldb] bb90063 - [lldb] Fix data race in ThreadList

2023-08-18 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-08-18T16:53:26-07:00
New Revision: bb90063249707e3ae081bfbd8e3512566abb7df6

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

LOG: [lldb] Fix data race in ThreadList

ThreadSanitizer reports the following issue:

```
  Write of size 8 at 0x00010a70abb0 by thread T3 (mutexes: write M0):
#0 lldb_private::ThreadList::Update(lldb_private::ThreadList&) 
ThreadList.cpp:741 (liblldb.18.0.0git.dylib:arm64+0x5dedf4) (BuildId: 
9bced2aafa373580ae9d750d9cf79a8f320021000e00)
#1 lldb_private::Process::UpdateThreadListIfNeeded() Process.cpp:1212 
(liblldb.18.0.0git.dylib:arm64+0x53bbec) (BuildId: 
9bced2aafa373580ae9d750d9cf79a8f320021000e00)

  Previous read of size 8 at 0x00010a70abb0 by main thread (mutexes: write M1):
#0 lldb_private::ThreadList::GetMutex() const ThreadList.cpp:785 
(liblldb.18.0.0git.dylib:arm64+0x5df138) (BuildId: 
9bced2aafa373580ae9d750d9cf79a8f320021000e00)
#1 lldb_private::ThreadList::DidResume() ThreadList.cpp:656 
(liblldb.18.0.0git.dylib:arm64+0x5de5c0) (BuildId: 
9bced2aafa373580ae9d750d9cf79a8f320021000e00)
#2 lldb_private::Process::PrivateResume() Process.cpp:3130 
(liblldb.18.0.0git.dylib:arm64+0x53cd7c) (BuildId: 
9bced2aafa373580ae9d750d9cf79a8f320021000e00)
```

Fix this by only using the mutex in ThreadList and removing the one in
process entirely.

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

Added: 


Modified: 
lldb/include/lldb/Target/Process.h
lldb/include/lldb/Target/ThreadCollection.h
lldb/include/lldb/Target/ThreadList.h
lldb/source/Target/Process.cpp
lldb/source/Target/ThreadList.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 2186eea7ef5054..2e1bce561526df 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2970,7 +2970,6 @@ void PruneThreadPlans();
   std::string m_exit_string; ///< A textual description of why a process 
exited.
   std::mutex m_exit_status_mutex; ///< Mutex so m_exit_status m_exit_string can
   ///be safely accessed from multiple threads
-  std::recursive_mutex m_thread_mutex;
   ThreadList m_thread_list_real; ///< The threads for this process as are known
  ///to the protocol we are debugging with
   ThreadList m_thread_list; ///< The threads for this process as the user will

diff  --git a/lldb/include/lldb/Target/ThreadCollection.h 
b/lldb/include/lldb/Target/ThreadCollection.h
index 29f5103e7eec7c..dc7d8f13eee037 100644
--- a/lldb/include/lldb/Target/ThreadCollection.h
+++ b/lldb/include/lldb/Target/ThreadCollection.h
@@ -47,7 +47,7 @@ class ThreadCollection {
 return ThreadIterable(m_threads, GetMutex());
   }
 
-  virtual std::recursive_mutex &GetMutex() const { return m_mutex; }
+  std::recursive_mutex &GetMutex() const { return m_mutex; }
 
 protected:
   collection m_threads;

diff  --git a/lldb/include/lldb/Target/ThreadList.h 
b/lldb/include/lldb/Target/ThreadList.h
index 6af04f8ffc3767..8aaff6e4cba0d4 100644
--- a/lldb/include/lldb/Target/ThreadList.h
+++ b/lldb/include/lldb/Target/ThreadList.h
@@ -133,8 +133,6 @@ class ThreadList : public ThreadCollection {
 
   void SetStopID(uint32_t stop_id);
 
-  std::recursive_mutex &GetMutex() const override;
-
   void Update(ThreadList &rhs);
 
 protected:

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index fc08cce096103f..4a33d8980c2782 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -435,7 +435,7 @@ Process::Process(lldb::TargetSP target_sp, ListenerSP 
listener_sp,
   Listener::MakeListener("lldb.process.internal_state_listener")),
   m_mod_id(), m_process_unique_id(0), m_thread_index_id(0),
   m_thread_id_to_index_id_map(), m_exit_status(-1), m_exit_string(),
-  m_exit_status_mutex(), m_thread_mutex(), m_thread_list_real(this),
+  m_exit_status_mutex(), m_thread_list_real(this),
   m_thread_list(this), m_thread_plans(*this), m_extended_thread_list(this),
   m_extended_thread_stop_id(0), m_queue_list(this), 
m_queue_list_stop_id(0),
   m_notifications(), m_image_tokens(),
@@ -2456,7 +2456,7 @@ Process::WaitForProcessStopPrivate(EventSP &event_sp,
 }
 
 void Process::LoadOperatingSystemPlugin(bool flush) {
-  std::lock_guard guard(m_thread_mutex);
+  std::lock_guard guard(GetThreadList().GetMutex());
   if (flush)
 m_thread_list.Clear();
   m_os_up.reset(OperatingSystem::FindPlugin(this, nullptr));

diff  --git a/lldb/source/Target/ThreadList.cpp 
b/lldb/source/Target/ThreadList.cpp
index 1ba0c435b993d3..fc6cbd48cf

[Lldb-commits] [lldb] 79a8e00 - [lldb] Fix data race in Process

2023-08-18 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-08-18T16:55:37-07:00
New Revision: 79a8e006dbc4ea281e9ec5933f484e476db3d9ab

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

LOG: [lldb] Fix data race in Process

Thread sanitizer reports a data race in Process.cpp in the usage of
m_process_input_reader. Fix this data race by introducing a mutex
guarding the access to this variable.

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

Added: 


Modified: 
lldb/include/lldb/Target/Process.h
lldb/source/Target/Process.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 2e1bce561526df..8e75ed85229429 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -3007,6 +3007,7 @@ void PruneThreadPlans();
   m_unix_signals_sp; /// This is the current signal set for this process.
   lldb::ABISP m_abi_sp;
   lldb::IOHandlerSP m_process_input_reader;
+  mutable std::mutex m_process_input_reader_mutex;
   ThreadedCommunication m_stdio_communication;
   std::recursive_mutex m_stdio_communication_mutex;
   bool m_stdin_forward; /// Remember if stdin must be forwarded to remote debug
@@ -3132,6 +3133,7 @@ void PruneThreadPlans();
   bool ProcessIOHandlerIsActive();
 
   bool ProcessIOHandlerExists() const {
+std::lock_guard guard(m_process_input_reader_mutex);
 return static_cast(m_process_input_reader);
   }
 

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 4a33d8980c2782..d76db377d3e900 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -629,6 +629,7 @@ void Process::SyncIOHandler(uint32_t iohandler_id,
 const Timeout &timeout) {
   // don't sync (potentially context switch) in case where there is no process
   // IO
+  std::lock_guard guard(m_process_input_reader_mutex);
   if (!m_process_input_reader)
 return;
 
@@ -2504,7 +2505,11 @@ Status Process::LaunchPrivate(ProcessLaunchInfo 
&launch_info, StateType &state,
   m_jit_loaders_up.reset();
   m_system_runtime_up.reset();
   m_os_up.reset();
-  m_process_input_reader.reset();
+
+  {
+std::lock_guard guard(m_process_input_reader_mutex);
+m_process_input_reader.reset();
+  }
 
   Module *exe_module = GetTarget().GetExecutableModulePointer();
 
@@ -2802,7 +2807,10 @@ Status Process::WillAttachToProcessWithName(const char 
*process_name,
 
 Status Process::Attach(ProcessAttachInfo &attach_info) {
   m_abi_sp.reset();
-  m_process_input_reader.reset();
+  {
+std::lock_guard guard(m_process_input_reader_mutex);
+m_process_input_reader.reset();
+  }
   m_dyld_up.reset();
   m_jit_loaders_up.reset();
   m_system_runtime_up.reset();
@@ -3053,7 +3061,10 @@ void Process::CompleteAttach() {
 
 Status Process::ConnectRemote(llvm::StringRef remote_url) {
   m_abi_sp.reset();
-  m_process_input_reader.reset();
+  {
+std::lock_guard guard(m_process_input_reader_mutex);
+m_process_input_reader.reset();
+  }
 
   // Find the process and its architecture.  Make sure it matches the
   // architecture of the current Target, and if not adjust it.
@@ -3341,10 +3352,13 @@ Status Process::DestroyImpl(bool force_kill) {
 m_stdio_communication.Disconnect();
 m_stdin_forward = false;
 
-if (m_process_input_reader) {
-  m_process_input_reader->SetIsDone(true);
-  m_process_input_reader->Cancel();
-  m_process_input_reader.reset();
+{
+  std::lock_guard guard(m_process_input_reader_mutex);
+  if (m_process_input_reader) {
+m_process_input_reader->SetIsDone(true);
+m_process_input_reader->Cancel();
+m_process_input_reader.reset();
+  }
 }
 
 // If we exited when we were waiting for a process to stop, then forward
@@ -4522,20 +4536,25 @@ void Process::SetSTDIOFileDescriptor(int fd) {
 m_stdio_communication.StartReadThread();
 
 // Now read thread is set up, set up input reader.
-
-if (!m_process_input_reader)
-  m_process_input_reader =
-  std::make_shared(this, fd);
+{
+  std::lock_guard guard(m_process_input_reader_mutex);
+  if (!m_process_input_reader)
+m_process_input_reader =
+std::make_shared(this, fd);
+}
   }
 }
 
 bool Process::ProcessIOHandlerIsActive() {
+  std::lock_guard guard(m_process_input_reader_mutex);
   IOHandlerSP io_handler_sp(m_process_input_reader);
   if (io_handler_sp)
 return GetTarget().GetDebugger().IsTopIOHandler(io_handler_sp);
   return false;
 }
+
 bool Process::PushProcessIOHandler() {
+  std::lock_guard guard(m_process_input_reader_mutex);
   IOHandlerSP io_handler_sp(m_process_input_reader);
   if (io_handler_sp) {
 Log *log = GetLog(LLDBLog::Process);
@@ -4555,6 +4574,7 @

[Lldb-commits] [lldb] fef609d - Revert "[lldb] Fix data race in ThreadList"

2023-08-22 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-08-22T11:14:04-07:00
New Revision: fef609d2d1da573150121a6ee897e1d90f235eb1

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

LOG: Revert "[lldb] Fix data race in ThreadList"

This reverts commit bb90063249707e3ae081bfbd8e3512566abb7df6.

Added: 


Modified: 
lldb/include/lldb/Target/Process.h
lldb/include/lldb/Target/ThreadCollection.h
lldb/include/lldb/Target/ThreadList.h
lldb/source/Target/Process.cpp
lldb/source/Target/ThreadList.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 8e75ed85229429..44cda6d2ce1aad 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2970,6 +2970,7 @@ void PruneThreadPlans();
   std::string m_exit_string; ///< A textual description of why a process 
exited.
   std::mutex m_exit_status_mutex; ///< Mutex so m_exit_status m_exit_string can
   ///be safely accessed from multiple threads
+  std::recursive_mutex m_thread_mutex;
   ThreadList m_thread_list_real; ///< The threads for this process as are known
  ///to the protocol we are debugging with
   ThreadList m_thread_list; ///< The threads for this process as the user will

diff  --git a/lldb/include/lldb/Target/ThreadCollection.h 
b/lldb/include/lldb/Target/ThreadCollection.h
index dc7d8f13eee037..29f5103e7eec7c 100644
--- a/lldb/include/lldb/Target/ThreadCollection.h
+++ b/lldb/include/lldb/Target/ThreadCollection.h
@@ -47,7 +47,7 @@ class ThreadCollection {
 return ThreadIterable(m_threads, GetMutex());
   }
 
-  std::recursive_mutex &GetMutex() const { return m_mutex; }
+  virtual std::recursive_mutex &GetMutex() const { return m_mutex; }
 
 protected:
   collection m_threads;

diff  --git a/lldb/include/lldb/Target/ThreadList.h 
b/lldb/include/lldb/Target/ThreadList.h
index 8aaff6e4cba0d4..6af04f8ffc3767 100644
--- a/lldb/include/lldb/Target/ThreadList.h
+++ b/lldb/include/lldb/Target/ThreadList.h
@@ -133,6 +133,8 @@ class ThreadList : public ThreadCollection {
 
   void SetStopID(uint32_t stop_id);
 
+  std::recursive_mutex &GetMutex() const override;
+
   void Update(ThreadList &rhs);
 
 protected:

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 57864a8a5da922..85ca0f6ab8d153 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -435,7 +435,7 @@ Process::Process(lldb::TargetSP target_sp, ListenerSP 
listener_sp,
   Listener::MakeListener("lldb.process.internal_state_listener")),
   m_mod_id(), m_process_unique_id(0), m_thread_index_id(0),
   m_thread_id_to_index_id_map(), m_exit_status(-1), m_exit_string(),
-  m_exit_status_mutex(), m_thread_list_real(this),
+  m_exit_status_mutex(), m_thread_mutex(), m_thread_list_real(this),
   m_thread_list(this), m_thread_plans(*this), m_extended_thread_list(this),
   m_extended_thread_stop_id(0), m_queue_list(this), 
m_queue_list_stop_id(0),
   m_notifications(), m_image_tokens(),
@@ -2455,7 +2455,7 @@ Process::WaitForProcessStopPrivate(EventSP &event_sp,
 }
 
 void Process::LoadOperatingSystemPlugin(bool flush) {
-  std::lock_guard guard(GetThreadList().GetMutex());
+  std::lock_guard guard(m_thread_mutex);
   if (flush)
 m_thread_list.Clear();
   m_os_up.reset(OperatingSystem::FindPlugin(this, nullptr));

diff  --git a/lldb/source/Target/ThreadList.cpp 
b/lldb/source/Target/ThreadList.cpp
index fc6cbd48cf8653..1ba0c435b993d3 100644
--- a/lldb/source/Target/ThreadList.cpp
+++ b/lldb/source/Target/ThreadList.cpp
@@ -736,8 +736,7 @@ void ThreadList::Update(ThreadList &rhs) {
   if (this != &rhs) {
 // Lock both mutexes to make sure neither side changes anyone on us while
 // the assignment occurs
-std::scoped_lock guard(
-GetMutex(), rhs.GetMutex());
+std::scoped_lock 
guard(GetMutex(), rhs.GetMutex());
 
 m_process = rhs.m_process;
 m_stop_id = rhs.m_stop_id;
@@ -782,6 +781,10 @@ void ThreadList::Flush() {
 (*pos)->Flush();
 }
 
+std::recursive_mutex &ThreadList::GetMutex() const {
+  return m_process->m_thread_mutex;
+}
+
 ThreadList::ExpressionExecutionThreadPusher::ExpressionExecutionThreadPusher(
 lldb::ThreadSP thread_sp)
 : m_thread_list(nullptr), m_tid(LLDB_INVALID_THREAD_ID) {



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


[Lldb-commits] [lldb] [lldb] Accept optional module in Value::ResolveValue (PR #66286)

2023-09-13 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/66286:

Value::ResolveValue calls Value::GetValueAsData as part of its implementation. 
The latter can receive an optional Module pointer, which is always null when 
called from the former. Allow threading in the Module in Value::ResolveValue.

rdar://115021869

>From 092e93e4c339bc8daa0bdb0d282430fb58bbda93 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Wed, 13 Sep 2023 13:17:47 -0700
Subject: [PATCH] [lldb] Accept optional module in Value::ResolveValue

Value::ResolveValue calls Value::GetValueAsData as part of its
implementation. The latter can receive an optional Module pointer, which
is always null when called from the former. Allow threading in the
Module in Value::ResolveValue.

rdar://115021869
---
 lldb/include/lldb/Core/Value.h   | 2 +-
 lldb/source/Core/Value.cpp   | 4 ++--
 lldb/source/Core/ValueObject.cpp | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lldb/include/lldb/Core/Value.h b/lldb/include/lldb/Core/Value.h
index ead23acc6f9b1a2..d0c338ffec0cd3d 100644
--- a/lldb/include/lldb/Core/Value.h
+++ b/lldb/include/lldb/Core/Value.h
@@ -107,7 +107,7 @@ class Value {
 
   Type *GetType();
 
-  Scalar &ResolveValue(ExecutionContext *exe_ctx);
+  Scalar &ResolveValue(ExecutionContext *exe_ctx, Module *module = nullptr);
 
   const Scalar &GetScalar() const { return m_value; }
 
diff --git a/lldb/source/Core/Value.cpp b/lldb/source/Core/Value.cpp
index 5a2631ca501f6c7..8efcfd3b4a1adac 100644
--- a/lldb/source/Core/Value.cpp
+++ b/lldb/source/Core/Value.cpp
@@ -572,7 +572,7 @@ Status Value::GetValueAsData(ExecutionContext *exe_ctx, 
DataExtractor &data,
   return error;
 }
 
-Scalar &Value::ResolveValue(ExecutionContext *exe_ctx) {
+Scalar &Value::ResolveValue(ExecutionContext *exe_ctx, Module *module) {
   const CompilerType &compiler_type = GetCompilerType();
   if (compiler_type.IsValid()) {
 switch (m_value_type) {
@@ -587,7 +587,7 @@ Scalar &Value::ResolveValue(ExecutionContext *exe_ctx) {
 {
   DataExtractor data;
   lldb::addr_t addr = m_value.ULongLong(LLDB_INVALID_ADDRESS);
-  Status error(GetValueAsData(exe_ctx, data, nullptr));
+  Status error(GetValueAsData(exe_ctx, data, module));
   if (error.Success()) {
 Scalar scalar;
 if (compiler_type.GetValueAsScalar(
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 3e9116f2d922933..ebfc1cf4d6fe9e1 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -334,7 +334,7 @@ bool ValueObject::ResolveValue(Scalar &scalar) {
   {
 ExecutionContext exe_ctx(GetExecutionContextRef());
 Value tmp_value(m_value);
-scalar = tmp_value.ResolveValue(&exe_ctx);
+scalar = tmp_value.ResolveValue(&exe_ctx, GetModule().get());
 if (scalar.IsValid()) {
   const uint32_t bitfield_bit_size = GetBitfieldBitSize();
   if (bitfield_bit_size)

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


[Lldb-commits] [lldb] [lldb] Accept optional module in Value::ResolveValue (PR #66286)

2023-09-13 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Accept optional module in Value::ResolveValue (PR #66286)

2023-09-13 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Accept optional module in Value::ResolveValue (PR #66286)

2023-09-13 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Accept optional module in Value::ResolveValue (PR #66286)

2023-09-14 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

@clayborg as Adrian said, this fixes a test failure downstream. I don't there's 
any visible change in behavior to test in main, unfortunately.

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


[Lldb-commits] [lldb] [lldb] Accept optional module in Value::ResolveValue (PR #66286)

2023-09-14 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

> > @clayborg as Adrian said, this fixes a test failure downstream. I don't 
> > there's any visible change in behavior to test in main, unfortunately.
> 
> Gotcha. Let me guess: Swift? :-)

Exactly :)

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


[Lldb-commits] [lldb] [lldb] Add interface to check if UserExpression::Parse() is cacheable (PR #66826)

2023-09-19 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/66826

When setting conditional breakpoints, we currently assume that a call to 
UserExpression::Parse() can be cached and resued multiple times. This may not 
be true for every user expression. Add a new method so subclasses of 
UserExpression can customize if they are parseable or not.

>From 5593f33bea5ebf0362b69d4b4a70a65edd77ca9d Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Tue, 19 Sep 2023 13:27:41 -0700
Subject: [PATCH] [lldb] Add interface to check if UserExpression::Parse() is
 cacheable

When setting conditional breakpoints, we currently assume that a call to
UserExpression::Parse() can be cached and resued multiple times. This
may not be true for every user expression. Add a new method so
subclasses of UserExpression can customize if they are parseable or not.
---
 lldb/include/lldb/Expression/UserExpression.h | 2 ++
 lldb/source/Breakpoint/BreakpointLocation.cpp | 1 +
 2 files changed, 3 insertions(+)

diff --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index 2d62fa37a24c2c4..03aa5e87c4cd579 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -192,6 +192,8 @@ class UserExpression : public Expression {
   /// expression.  Text() should contain the definition of this function.
   const char *FunctionName() override { return "$__lldb_expr"; }
 
+  /// Returns whether the call to Parse on this user expression is cacheable.
+  virtual bool IsParseCacheable() { return true; }
   /// Return the language that should be used when parsing.  To use the
   /// default, return eLanguageTypeUnknown.
   lldb::LanguageType Language() const override { return m_language; }
diff --git a/lldb/source/Breakpoint/BreakpointLocation.cpp 
b/lldb/source/Breakpoint/BreakpointLocation.cpp
index 0fcefe5c63be749..2d2e00883f32ef7 100644
--- a/lldb/source/Breakpoint/BreakpointLocation.cpp
+++ b/lldb/source/Breakpoint/BreakpointLocation.cpp
@@ -250,6 +250,7 @@ bool BreakpointLocation::ConditionSaysStop(ExecutionContext 
&exe_ctx,
   DiagnosticManager diagnostics;
 
   if (condition_hash != m_condition_hash || !m_user_expression_sp ||
+  !m_user_expression_sp->IsParseCacheable() ||
   !m_user_expression_sp->MatchesContext(exe_ctx)) {
 LanguageType language = eLanguageTypeUnknown;
 // See if we can figure out the language from the frame, otherwise use the

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


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-22 Thread Augusto Noronha via lldb-commits


@@ -0,0 +1,770 @@
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/OperatingSystem.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanRunToAddress.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+
+#include "DynamicLoaderFreeBSDKernel.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(DynamicLoaderFreeBSDKernel)
+
+void DynamicLoaderFreeBSDKernel::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+GetPluginDescriptionStatic(), CreateInstance,
+DebuggerInit);
+}
+
+void DynamicLoaderFreeBSDKernel::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+llvm::StringRef DynamicLoaderFreeBSDKernel::GetPluginDescriptionStatic() {
+  return "The Dynamic Loader Plugin For FreeBSD Kernel";
+}
+
+static bool is_kernel(Module *module) {

augusto2112 wrote:

Nit: LLDB style would be `IsKernel`

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


[Lldb-commits] [lldb] 962ef99 - [lldb] Protect RNBRemote from a data race

2023-09-25 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-09-25T11:17:42-07:00
New Revision: 962ef991da2836775191435fb732fc61ec07d5e6

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

LOG: [lldb] Protect RNBRemote from a data race

Summary:
Thread sanitizer reports the following data race:

```
  Write of size 8 at 0x000103303e70 by thread T1 (mutexes: write M0):
#0 RNBRemote::CommDataReceived(std::__1::basic_string, std::__1::allocator> const&) 
RNBRemote.cpp:1075 (debugserver:arm64+0x100038db8) (BuildId: 
f130b34f693c4f3eba96139104af2b71320021000e00)
#1 RNBRemote::ThreadFunctionReadRemoteData(void*) RNBRemote.cpp:1180 
(debugserver:arm64+0x1000391dc) (BuildId: 
f130b34f693c4f3eba96139104af2b71320021000e00)

  Previous read of size 8 at 0x000103303e70 by main thread:
#0 RNBRemote::GetPacketPayload(std::__1::basic_string, std::__1::allocator>&) RNBRemote.cpp:797 
(debugserver:arm64+0x100037c5c) (BuildId: 
f130b34f693c4f3eba96139104af2b71320021000e00)
#1 RNBRemote::GetPacket(std::__1::basic_string, std::__1::allocator>&, RNBRemote::Packet&, 
bool) RNBRemote.cpp:907 (debugserver:arm64+0x1000378cc) (BuildId: 
f130b34f693c4f3eba96139104af2b71320021000e00)
```

RNBRemote already has a mutex, extend its usage to protect the read of
m_rx_packets.

Reviewers: jdevlieghere, bulbazord, jingham

Subscribers:

Added: 


Modified: 
lldb/tools/debugserver/source/RNBRemote.cpp

Removed: 




diff  --git a/lldb/tools/debugserver/source/RNBRemote.cpp 
b/lldb/tools/debugserver/source/RNBRemote.cpp
index ea039101bb541b0..4e9086b0411f2d7 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -777,26 +777,28 @@ rnb_err_t RNBRemote::GetPacketPayload(std::string 
&return_packet) {
   // DNBLogThreadedIf (LOG_RNB_MAX, "%8u RNBRemote::%s called",
   // (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
 
-  PThreadMutex::Locker locker(m_mutex);
-  if (m_rx_packets.empty()) {
-// Only reset the remote command available event if we have no more packets
-m_ctx.Events().ResetEvents(RNBContext::event_read_packet_available);
-// DNBLogThreadedIf (LOG_RNB_MAX, "%8u RNBRemote::%s error: no packets
-// available...", (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true),
-// __FUNCTION__);
-return rnb_err;
-  }
+  {
+PThreadMutex::Locker locker(m_mutex);
+if (m_rx_packets.empty()) {
+  // Only reset the remote command available event if we have no more
+  // packets
+  m_ctx.Events().ResetEvents(RNBContext::event_read_packet_available);
+  // DNBLogThreadedIf (LOG_RNB_MAX, "%8u RNBRemote::%s error: no packets
+  // available...", (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true),
+  // __FUNCTION__);
+  return rnb_err;
+}
 
-  // DNBLogThreadedIf (LOG_RNB_MAX, "%8u RNBRemote::%s has %u queued packets",
-  // (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__,
-  // m_rx_packets.size());
-  return_packet.swap(m_rx_packets.front());
-  m_rx_packets.pop_front();
-  locker.Reset(); // Release our lock on the mutex
-
-  if (m_rx_packets.empty()) {
-// Reset the remote command available event if we have no more packets
-m_ctx.Events().ResetEvents(RNBContext::event_read_packet_available);
+// DNBLogThreadedIf (LOG_RNB_MAX, "%8u RNBRemote::%s has %u queued 
packets",
+// (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__,
+// m_rx_packets.size());
+return_packet.swap(m_rx_packets.front());
+m_rx_packets.pop_front();
+
+if (m_rx_packets.empty()) {
+  // Reset the remote command available event if we have no more packets
+  m_ctx.Events().ResetEvents(RNBContext::event_read_packet_available);
+}
   }
 
   // DNBLogThreadedIf (LOG_RNB_MEDIUM, "%8u RNBRemote::%s: '%s'",



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


[Lldb-commits] [lldb] b414954 - [lldb] Make ReadCStringFromMemory default to read from the file-cache.

2022-01-28 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-01-28T13:08:30-03:00
New Revision: b414954a5f1c2f8f6adecf20e5a433dfbc320cc2

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

LOG: [lldb] Make ReadCStringFromMemory default to read from the file-cache.

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

Added: 


Modified: 
lldb/include/lldb/Target/Target.h
lldb/source/Target/Target.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index 2c8b36d1e3d9c..42a641f6d52ab 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1019,10 +1019,11 @@ class Target : public 
std::enable_shared_from_this,
 lldb::addr_t *load_addr_ptr = nullptr);
 
   size_t ReadCStringFromMemory(const Address &addr, std::string &out_str,
-   Status &error);
+   Status &error, bool force_live_memory = false);
 
   size_t ReadCStringFromMemory(const Address &addr, char *dst,
-   size_t dst_max_len, Status &result_error);
+   size_t dst_max_len, Status &result_error,
+   bool force_live_memory = false);
 
   /// Read a NULL terminated string from memory
   ///

diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 01e51c0577aae..6d33db6554d2e 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -1829,13 +1829,14 @@ size_t Target::ReadMemory(const Address &addr, void 
*dst, size_t dst_len,
 }
 
 size_t Target::ReadCStringFromMemory(const Address &addr, std::string &out_str,
- Status &error) {
+ Status &error, bool force_live_memory) {
   char buf[256];
   out_str.clear();
   addr_t curr_addr = addr.GetLoadAddress(this);
   Address address(addr);
   while (true) {
-size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error);
+size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error,
+  force_live_memory);
 if (length == 0)
   break;
 out_str.append(buf, length);
@@ -1851,7 +1852,8 @@ size_t Target::ReadCStringFromMemory(const Address &addr, 
std::string &out_str,
 }
 
 size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
- size_t dst_max_len, Status &result_error) 
{
+ size_t dst_max_len, Status &result_error,
+ bool force_live_memory) {
   size_t total_cstr_len = 0;
   if (dst && dst_max_len) {
 result_error.Clear();
@@ -1874,8 +1876,8 @@ size_t Target::ReadCStringFromMemory(const Address &addr, 
char *dst,
   cache_line_size - (curr_addr % cache_line_size);
   addr_t bytes_to_read =
   std::min(bytes_left, cache_line_bytes_left);
-  size_t bytes_read =
-  ReadMemory(address, curr_dst, bytes_to_read, error, true);
+  size_t bytes_read = ReadMemory(address, curr_dst, bytes_to_read, error,
+ force_live_memory);
 
   if (bytes_read == 0) {
 result_error = error;



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


[Lldb-commits] [lldb] 5ade38c - [lldb] Add comments to describe m_memory_addr and IsInMemory

2022-07-07 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-07-07T13:11:50-07:00
New Revision: 5ade38c28573b92b8b0bfd1fe7feef2fbea76ddf

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

LOG: [lldb] Add comments to describe m_memory_addr and IsInMemory

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

Added: 


Modified: 
lldb/include/lldb/Symbol/ObjectFile.h

Removed: 




diff  --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index c61e3c138944..e51d50592c90 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -673,6 +673,7 @@ class ObjectFile : public 
std::enable_shared_from_this,
   virtual size_t ReadSectionData(Section *section,
  DataExtractor §ion_data);
 
+  /// Returns true if the object file exists only in memory.
   bool IsInMemory() const { return m_memory_addr != LLDB_INVALID_ADDRESS; }
 
   // Strip linker annotations (such as @@VERSION) from symbol names.
@@ -736,6 +737,7 @@ class ObjectFile : public 
std::enable_shared_from_this,
   DataExtractor
   m_data; ///< The data for this object file so things can be parsed 
lazily.
   lldb::ProcessWP m_process_wp;
+  /// Set if the object file only exists in memory.
   const lldb::addr_t m_memory_addr;
   std::unique_ptr m_sections_up;
   std::unique_ptr m_symtab_up;



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


[Lldb-commits] [lldb] 3b8a1cc - [lldb] Disable TestGuiExpandThreadsTree

2022-07-22 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-07-22T16:00:51-07:00
New Revision: 3b8a1cc38ab72afe6889f3c1fff7c3deb8ac26ec

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

LOG: [lldb] Disable TestGuiExpandThreadsTree

Added: 


Modified: 
lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py

Removed: 




diff  --git 
a/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py 
b/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
index 099bf3bb2ac1a..00a5d2673bfc3 100644
--- a/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
+++ b/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
@@ -16,39 +16,60 @@ class TestGuiExpandThreadsTree(PExpectTest):
 @skipIfAsan
 @skipIfCursesSupportMissing
 @skipIf(oslist=["linux"], archs=["arm", "aarch64"])
+@skipIf(bugnumber="rdar://97460266")
 def test_gui(self):
 self.build()
 
+print(1)
 self.launch(executable=self.getBuildArtifact("a.out"), 
dimensions=(100,500))
+print(2)
 self.expect("breakpoint set -n break_here", substrs=["Breakpoint 1", 
"address ="])
+print(3)
 self.expect("run", substrs=["stop reason ="])
 
 escape_key = chr(27).encode()
 
 # Start the GUI and close the welcome window.
+print(4)
 self.child.sendline("gui")
+print(5)
 self.child.send(escape_key)
+print(6)
 self.child.expect_exact("Threads")
 
 # The thread running thread_start_routine should be expanded.
+
+print(7)
 self.child.expect_exact("#0: break_here")
 
 # Exit GUI.
+
+print(8)
 self.child.send(escape_key)
+print(9)
 self.expect_prompt()
 
 # Select the main thread.
+print(10)
 self.child.sendline("thread select 1")
 
 # Start the GUI.
+print(11)
 self.child.sendline("gui")
+print(12)
 self.child.expect_exact("Threads")
 
 # The main thread should be expanded.
+
+print(13)
 self.child.expect("#\d+: main")
 
 # Quit the GUI
+print(14)
 self.child.send(escape_key)
 
+print(15)
 self.expect_prompt()
+
+print(16)
 self.quit()



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


[Lldb-commits] [lldb] c18304e - [lldb] Remote accidental logs left in TestGuiExpandThreadsTree

2022-07-22 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-07-22T16:06:49-07:00
New Revision: c18304e60067b904941fbcfb3ca1649798b242f6

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

LOG: [lldb] Remote accidental logs left in TestGuiExpandThreadsTree

Added: 


Modified: 
lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py

Removed: 




diff  --git 
a/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py 
b/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
index 00a5d2673bfc..2dfdd6865cd9 100644
--- a/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
+++ b/lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py
@@ -20,56 +20,36 @@ class TestGuiExpandThreadsTree(PExpectTest):
 def test_gui(self):
 self.build()
 
-print(1)
 self.launch(executable=self.getBuildArtifact("a.out"), 
dimensions=(100,500))
-print(2)
 self.expect("breakpoint set -n break_here", substrs=["Breakpoint 1", 
"address ="])
-print(3)
 self.expect("run", substrs=["stop reason ="])
 
 escape_key = chr(27).encode()
 
 # Start the GUI and close the welcome window.
-print(4)
 self.child.sendline("gui")
-print(5)
 self.child.send(escape_key)
-print(6)
 self.child.expect_exact("Threads")
 
 # The thread running thread_start_routine should be expanded.
-
-print(7)
 self.child.expect_exact("#0: break_here")
 
 # Exit GUI.
-
-print(8)
 self.child.send(escape_key)
-print(9)
 self.expect_prompt()
 
 # Select the main thread.
-print(10)
 self.child.sendline("thread select 1")
 
 # Start the GUI.
-print(11)
 self.child.sendline("gui")
-print(12)
 self.child.expect_exact("Threads")
 
 # The main thread should be expanded.
-
-print(13)
 self.child.expect("#\d+: main")
 
 # Quit the GUI
-print(14)
 self.child.send(escape_key)
 
-print(15)
 self.expect_prompt()
-
-print(16)
 self.quit()



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


[Lldb-commits] [lldb] 2622c5e - [lldb] Adapt lldb tests to changes in 71cdb8c6f144

2022-07-23 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-07-23T15:37:26-07:00
New Revision: 2622c5e212646d1c8d6a43444d7c5b551f0221ad

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

LOG: [lldb] Adapt lldb tests to changes in 71cdb8c6f144

Added: 


Modified: 
lldb/test/API/functionalities/dlopen_other_executable/main.c
lldb/test/API/macosx/ignore_exceptions/main.c

Removed: 




diff  --git a/lldb/test/API/functionalities/dlopen_other_executable/main.c 
b/lldb/test/API/functionalities/dlopen_other_executable/main.c
index 8f21e862a2b58..f48f6177e7db0 100644
--- a/lldb/test/API/functionalities/dlopen_other_executable/main.c
+++ b/lldb/test/API/functionalities/dlopen_other_executable/main.c
@@ -4,7 +4,7 @@
 int main() {
   int i = 0; // break here
   // dlopen the 'other' test executable.
-  int h = dlopen("other", RTLD_LAZY);
+  int h = (int) dlopen("other", RTLD_LAZY);
   assert(h && "dlopen failed?");
   return i; // break after dlopen
 }

diff  --git a/lldb/test/API/macosx/ignore_exceptions/main.c 
b/lldb/test/API/macosx/ignore_exceptions/main.c
index 682c5f23627e0..b9513aa35b3ed 100644
--- a/lldb/test/API/macosx/ignore_exceptions/main.c
+++ b/lldb/test/API/macosx/ignore_exceptions/main.c
@@ -13,7 +13,7 @@ void
 saction_handler(int signo, siginfo_t info, void *baton) {
   printf("Got into handler.\n");   // stop here in the signal handler
   kern_return_t success
-  = mach_vm_protect(mach_task_self(), g_int_ptr,
+  = mach_vm_protect(mach_task_self(), (mach_vm_address_t) g_int_ptr,
 g_size, 0, VM_PROT_READ|VM_PROT_WRITE);
   g_int_ptr[1] = 20;
 }
@@ -24,7 +24,7 @@ main()
   for (int i = 0; i < 10; i++)
 g_int_ptr[i] = i * 10;
   
-  vm_result = mach_vm_protect(mach_task_self(), g_int_ptr, g_size, 0, 
VM_PROT_NONE);
+  vm_result = mach_vm_protect(mach_task_self(), (mach_vm_address_t) g_int_ptr, 
g_size, 0, VM_PROT_NONE);
   struct sigaction my_action;
   sigemptyset(&my_action.sa_mask);
   my_action.sa_handler = (void (*)(int)) saction_handler;



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


[Lldb-commits] [lldb] 5ee910f - [lldb] Disable TestStackFromStdModule.py

2022-07-26 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-07-26T13:02:51-07:00
New Revision: 5ee910fef52448c141d0cd2507cee29432541cda

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

LOG: [lldb] Disable TestStackFromStdModule.py

TestStackFromStdModule.py started failing due to f4fb72e6d4ce
(https://reviews.llvm.org/D128146), with a clang assertion failure:
assert(isa(Decl->TypeForDecl))

Added: 


Modified: 

lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py

Removed: 




diff  --git 
a/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py
index ab3b0c7a2392a..0c37df6b3a740 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py
@@ -11,6 +11,7 @@ class TestStack(TestBase):
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIfLinux # Declaration in some Linux headers causes LLDB to crash.
+@skipIf(bugnumber="rdar://97622854")
 def test(self):
 self.build()
 



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


[Lldb-commits] [lldb] 3aef968 - [lldb] Allow SymbolTable regex search functions to match mangled name

2022-08-03 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-08-03T10:55:32-07:00
New Revision: 3aef968ec3faada22319aaa3530776974082d2d5

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

LOG: [lldb] Allow SymbolTable regex search functions to match mangled name

It may be useful to search symbol table entries by mangled instead
of demangled names. Add this optional functionality in the SymbolTable
functions.

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

Added: 
lldb/test/Shell/Symtab/Inputs/symbols.yaml
lldb/test/Shell/Symtab/symtab-regex-demangled.test
lldb/test/Shell/Symtab/symtab-regex-mangled.test

Modified: 
lldb/include/lldb/Core/Module.h
lldb/include/lldb/Symbol/Symtab.h
lldb/source/Core/Module.cpp
lldb/source/Symbol/Symtab.cpp
lldb/tools/lldb-test/lldb-test.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
index cc3edbb3f1bbe..117b14c586cf3 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -261,9 +261,10 @@ class Module : public std::enable_shared_from_this,
   lldb::SymbolType symbol_type,
   SymbolContextList &sc_list);
 
-  void FindSymbolsMatchingRegExAndType(const RegularExpression ®ex,
-   lldb::SymbolType symbol_type,
-   SymbolContextList &sc_list);
+  void FindSymbolsMatchingRegExAndType(
+  const RegularExpression ®ex, lldb::SymbolType symbol_type,
+  SymbolContextList &sc_list,
+  Mangled::NamePreference mangling_preference = Mangled::ePreferDemangled);
 
   /// Find a function symbols in the object file's symbol table.
   ///

diff  --git a/lldb/include/lldb/Symbol/Symtab.h 
b/lldb/include/lldb/Symbol/Symtab.h
index 504b49c026742..57627d2dde7d2 100644
--- a/lldb/include/lldb/Symbol/Symtab.h
+++ b/lldb/include/lldb/Symbol/Symtab.h
@@ -89,14 +89,16 @@ class Symtab {
   Debug symbol_debug_type,
   Visibility symbol_visibility,
   std::vector &matches);
-  uint32_t
-  AppendSymbolIndexesMatchingRegExAndType(const RegularExpression ®ex,
-  lldb::SymbolType symbol_type,
-  std::vector &indexes);
+  uint32_t AppendSymbolIndexesMatchingRegExAndType(
+  const RegularExpression ®ex, lldb::SymbolType symbol_type,
+  std::vector &indexes,
+  Mangled::NamePreference name_preference = Mangled::ePreferDemangled);
   uint32_t AppendSymbolIndexesMatchingRegExAndType(
   const RegularExpression ®ex, lldb::SymbolType symbol_type,
   Debug symbol_debug_type, Visibility symbol_visibility,
-  std::vector &indexes);
+  std::vector &indexes,
+  Mangled::NamePreference name_preference =
+  Mangled::NamePreference::ePreferDemangled);
   void FindAllSymbolsWithNameAndType(ConstString name,
  lldb::SymbolType symbol_type,
  std::vector &symbol_indexes);
@@ -108,7 +110,8 @@ class Symtab {
   void FindAllSymbolsMatchingRexExAndType(
   const RegularExpression ®ex, lldb::SymbolType symbol_type,
   Debug symbol_debug_type, Visibility symbol_visibility,
-  std::vector &symbol_indexes);
+  std::vector &symbol_indexes,
+  Mangled::NamePreference name_preference = Mangled::ePreferDemangled);
   Symbol *FindFirstSymbolWithNameAndType(ConstString name,
  lldb::SymbolType symbol_type,
  Debug symbol_debug_type,

diff  --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 893e208371243..0d4466a13d254 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1367,9 +1367,9 @@ void Module::FindSymbolsWithNameAndType(ConstString name,
   }
 }
 
-void Module::FindSymbolsMatchingRegExAndType(const RegularExpression ®ex,
- SymbolType symbol_type,
- SymbolContextList &sc_list) {
+void Module::FindSymbolsMatchingRegExAndType(
+const RegularExpression ®ex, SymbolType symbol_type,
+SymbolContextList &sc_list, Mangled::NamePreference mangling_preference) {
   // No need to protect this call using m_mutex all other method calls are
   // already thread safe.
   LLDB_SCOPED_TIMERF(
@@ -1379,7 +1379,7 @@ void Module::FindSymbolsMatchingRegExAndType(const 
RegularExpression ®ex,
 std::vector symbol_indexes;
 symtab->FindAllSymbolsMatchingRexExAndType(
 regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibility

[Lldb-commits] [lldb] 1f64f8b - [lldb] Fix 'FileCheck' spelling on symtab regex tests

2022-08-03 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-08-03T11:57:33-07:00
New Revision: 1f64f8bcabb65c9622386d7458e42ee33b2eb7dc

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

LOG: [lldb] Fix 'FileCheck' spelling on symtab regex tests

Added: 


Modified: 
lldb/test/Shell/Symtab/symtab-regex-demangled.test
lldb/test/Shell/Symtab/symtab-regex-mangled.test

Removed: 




diff  --git a/lldb/test/Shell/Symtab/symtab-regex-demangled.test 
b/lldb/test/Shell/Symtab/symtab-regex-demangled.test
index 46cbc0d7ed86..9e7354456f17 100644
--- a/lldb/test/Shell/Symtab/symtab-regex-demangled.test
+++ b/lldb/test/Shell/Symtab/symtab-regex-demangled.test
@@ -1,7 +1,6 @@
 # RUN: yaml2obj %S/Inputs/symbols.yaml -o %t
-#
 
-# RUN: lldb-test symtab --find-symbols-by-regex='.*some.*' 
--mangling-preference=demangled %t | Filecheck %s
+# RUN: lldb-test symtab --find-symbols-by-regex='.*some.*' 
--mangling-preference=demangled %t | FileCheck %s
 # CHECK: someFunc(int, int, int)
 # CHECK: someFunc(char, int)
 # CHECK: someOtherFunc()

diff  --git a/lldb/test/Shell/Symtab/symtab-regex-mangled.test 
b/lldb/test/Shell/Symtab/symtab-regex-mangled.test
index d93091a59560..ce9530e5111c 100644
--- a/lldb/test/Shell/Symtab/symtab-regex-mangled.test
+++ b/lldb/test/Shell/Symtab/symtab-regex-mangled.test
@@ -1,7 +1,6 @@
 # RUN: yaml2obj %S/Inputs/symbols.yaml -o %t
-#
 
-# RUN: lldb-test symtab --find-symbols-by-regex='.*some.*' 
--mangling-preference=mangled %t | Filecheck %s
+# RUN: lldb-test symtab --find-symbols-by-regex='.*some.*' 
--mangling-preference=mangled %t | FileCheck %s
 # CHECK: _Z8someFunciii
 # CHECK: _Z8someFuncci
 # CHECK: _Z13someOtherFuncv



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


[Lldb-commits] [lldb] c6c5944 - [lldb] Allow DataFileCache to be constructed with a different policy

2022-08-11 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-08-11T09:28:30-07:00
New Revision: c6c5944d05e81b5c7f48abea22a98389b1204a33

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

LOG: [lldb] Allow DataFileCache to be constructed with a different policy

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

Added: 


Modified: 
lldb/include/lldb/Core/DataFileCache.h
lldb/source/Core/DataFileCache.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/DataFileCache.h 
b/lldb/include/lldb/Core/DataFileCache.h
index 2dc69f6ce6b09..300c4842d9d22 100644
--- a/lldb/include/lldb/Core/DataFileCache.h
+++ b/lldb/include/lldb/Core/DataFileCache.h
@@ -14,6 +14,7 @@
 #include "lldb/Utility/UUID.h"
 #include "lldb/lldb-forward.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/CachePruning.h"
 #include "llvm/Support/Caching.h"
 #include 
 
@@ -40,11 +41,18 @@ namespace lldb_private {
 
 class DataFileCache {
 public:
-  /// Create a data file cache in the directory path that is specified.
+  /// Create a data file cache in the directory path that is specified, using
+  /// the specified policy.
   ///
   /// Data will be cached in files created in this directory when clients call
   /// DataFileCache::SetCacheData.
-  DataFileCache(llvm::StringRef path);
+  DataFileCache(llvm::StringRef path,
+llvm::CachePruningPolicy policy =
+DataFileCache::GetLLDBIndexCachePolicy());
+
+  /// Gets the default LLDB index cache policy, which is controlled by the
+  /// "LLDBIndexCache" family of settings.
+  static llvm::CachePruningPolicy GetLLDBIndexCachePolicy();
 
   /// Get cached data from the cache directory for the specified key.
   ///

diff  --git a/lldb/source/Core/DataFileCache.cpp 
b/lldb/source/Core/DataFileCache.cpp
index b38adfda169aa..07c6839f01494 100644
--- a/lldb/source/Core/DataFileCache.cpp
+++ b/lldb/source/Core/DataFileCache.cpp
@@ -19,26 +19,34 @@
 
 using namespace lldb_private;
 
-DataFileCache::DataFileCache(llvm::StringRef path) {
-  m_cache_dir.SetPath(path);
 
-  // Prune the cache based off of the LLDB settings each time we create a cache
-  // object.
-  ModuleListProperties &properties =
-  ModuleList::GetGlobalModuleListProperties();
-  llvm::CachePruningPolicy policy;
-  // Only scan once an hour. If we have lots of debug sessions we don't want
-  // to scan this directory too often. A timestamp file is written to the
-  // directory to ensure 
diff erent processes don't scan the directory too often.
-  // This setting doesn't mean that a thread will continually scan the cache
-  // directory within this process.
-  policy.Interval = std::chrono::hours(1);
-  // Get the user settings for pruning.
-  policy.MaxSizeBytes = properties.GetLLDBIndexCacheMaxByteSize();
-  policy.MaxSizePercentageOfAvailableSpace =
-  properties.GetLLDBIndexCacheMaxPercent();
-  policy.Expiration =
-  std::chrono::hours(properties.GetLLDBIndexCacheExpirationDays() * 24);
+llvm::CachePruningPolicy DataFileCache::GetLLDBIndexCachePolicy() {
+  static llvm::CachePruningPolicy policy;
+  static llvm::once_flag once_flag;
+
+  llvm::call_once(once_flag, []() {
+// Prune the cache based off of the LLDB settings each time we create a
+// cache object.
+ModuleListProperties &properties =
+ModuleList::GetGlobalModuleListProperties();
+// Only scan once an hour. If we have lots of debug sessions we don't want
+// to scan this directory too often. A timestamp file is written to the
+// directory to ensure 
diff erent processes don't scan the directory too
+// often. This setting doesn't mean that a thread will continually scan the
+// cache directory within this process.
+policy.Interval = std::chrono::hours(1);
+// Get the user settings for pruning.
+policy.MaxSizeBytes = properties.GetLLDBIndexCacheMaxByteSize();
+policy.MaxSizePercentageOfAvailableSpace =
+properties.GetLLDBIndexCacheMaxPercent();
+policy.Expiration =
+std::chrono::hours(properties.GetLLDBIndexCacheExpirationDays() * 24);
+  });
+  return policy;
+}
+
+DataFileCache::DataFileCache(llvm::StringRef path, llvm::CachePruningPolicy 
policy) {
+  m_cache_dir.SetPath(path);
   pruneCache(path, policy);
 
   // This lambda will get called when the data is gotten from the cache and
@@ -311,3 +319,4 @@ llvm::StringRef StringTableReader::Get(uint32_t offset) 
const {
 return llvm::StringRef();
   return llvm::StringRef(m_data.data() + offset);
 }
+



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


[Lldb-commits] [lldb] f85cc60 - [lldb] Add LTO dependency to lldb test suite

2022-12-22 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-12-22T10:15:20-08:00
New Revision: f85cc6009aa790dd9970981408401072702ea886

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

LOG: [lldb] Add LTO dependency to lldb test suite

Make the lldb test target depend on LTO, since TestFullLtoStepping
needs it (prior to this patch, running "ninja check-lldb" would not
build libLTO).

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

Added: 


Modified: 
lldb/test/CMakeLists.txt

Removed: 




diff  --git a/lldb/test/CMakeLists.txt b/lldb/test/CMakeLists.txt
index dc1dff8681c51..0b0a9e9065257 100644
--- a/lldb/test/CMakeLists.txt
+++ b/lldb/test/CMakeLists.txt
@@ -95,6 +95,9 @@ endif()
 if(TARGET clang)
   add_lldb_test_dependency(clang)
 
+  # TestFullLtoStepping depends on LTO, and only runs when the compiler is 
clang.
+  add_lldb_test_dependency(LTO)
+
   if (TARGET libcxx OR ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES))
 set(LLDB_HAS_LIBCXX ON)
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)



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


[Lldb-commits] [lldb] 1d6243d - [lldb] Fix symbol table use after free

2023-01-09 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-01-09T10:27:18-08:00
New Revision: 1d6243db90b09c61d78a14268bb88a73792b63ab

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

LOG: [lldb] Fix symbol table use after free

The symbol file stores a raw pointer to the main object file's symbol
table. This pointer, however, can be freed, if ObjectFile::ClearSymtab
is ever called. This patch makes sure out pointer to the symbol file
is valid before using it.

Added: 


Modified: 
lldb/include/lldb/Symbol/SymbolFile.h
lldb/source/Symbol/SymbolFile.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/SymbolFile.h 
b/lldb/include/lldb/Symbol/SymbolFile.h
index d5fe0331fe5a8..4b5499304664b 100644
--- a/lldb/include/lldb/Symbol/SymbolFile.h
+++ b/lldb/include/lldb/Symbol/SymbolFile.h
@@ -504,7 +504,6 @@ class SymbolFileCommon : public SymbolFile {
// file)
   std::optional> m_compile_units;
   TypeList m_type_list;
-  Symtab *m_symtab = nullptr;
   uint32_t m_abilities = 0;
   bool m_calculated_abilities = false;
   bool m_index_was_loaded_from_cache = false;
@@ -517,6 +516,10 @@ class SymbolFileCommon : public SymbolFile {
 private:
   SymbolFileCommon(const SymbolFileCommon &) = delete;
   const SymbolFileCommon &operator=(const SymbolFileCommon &) = delete;
+
+  /// Do not use m_symtab directly, as it may be freed. Use GetSymtab()
+  /// to access it instead.
+  Symtab *m_symtab = nullptr;
 };
 
 } // namespace lldb_private

diff  --git a/lldb/source/Symbol/SymbolFile.cpp 
b/lldb/source/Symbol/SymbolFile.cpp
index c7af908543e88..b271efd07bfe3 100644
--- a/lldb/source/Symbol/SymbolFile.cpp
+++ b/lldb/source/Symbol/SymbolFile.cpp
@@ -164,16 +164,15 @@ SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() 
= default;
 
 Symtab *SymbolFileCommon::GetSymtab() {
   std::lock_guard guard(GetModuleMutex());
-  if (m_symtab)
-return m_symtab;
-
   // Fetch the symtab from the main object file.
-  m_symtab = GetMainObjectFile()->GetSymtab();
-
-  // Then add our symbols to it.
-  if (m_symtab)
-AddSymbols(*m_symtab);
+  auto *symtab = GetMainObjectFile()->GetSymtab();
+  if (m_symtab != symtab) {
+m_symtab = symtab;
 
+// Then add our symbols to it.
+if (m_symtab)
+  AddSymbols(*m_symtab);
+  }
   return m_symtab;
 }
 
@@ -186,8 +185,8 @@ void SymbolFileCommon::SectionFileAddressesChanged() {
   ObjectFile *symfile_objfile = GetObjectFile();
   if (symfile_objfile != module_objfile)
 symfile_objfile->SectionFileAddressesChanged();
-  if (m_symtab)
-m_symtab->SectionFileAddressesChanged();
+  if (auto *symtab = GetSymtab())
+symtab->SectionFileAddressesChanged();
 }
 
 uint32_t SymbolFileCommon::GetNumCompileUnits() {



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


[Lldb-commits] [lldb] 7ef075a - [lldb] Only allow SymbolFiles to construct Types

2023-01-17 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-01-17T10:30:29-08:00
New Revision: 7ef075a6d7a2bccbeedb9b5a1689e8545d5753e9

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

LOG: [lldb] Only allow SymbolFiles to construct Types

SymbolFiles should own Types by keeping them in their TypeList. This
patch privates the Type constructor to guarantee that every created Type
is kept in the SymbolFile's type list.

Added: 


Modified: 
lldb/include/lldb/Symbol/SymbolFile.h
lldb/include/lldb/Symbol/SymbolFileOnDemand.h
lldb/include/lldb/Symbol/Type.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
lldb/unittests/Symbol/TestTypeSystemClang.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/SymbolFile.h 
b/lldb/include/lldb/Symbol/SymbolFile.h
index 4b5499304664b..1be3323f715be 100644
--- a/lldb/include/lldb/Symbol/SymbolFile.h
+++ b/lldb/include/lldb/Symbol/SymbolFile.h
@@ -412,6 +412,15 @@ class SymbolFile : public PluginInterface {
   virtual bool GetDebugInfoHadFrameVariableErrors() const = 0;
   virtual void SetDebugInfoHadFrameVariableErrors() = 0;
 
+  virtual lldb::TypeSP
+  MakeType(lldb::user_id_t uid, ConstString name,
+   std::optional byte_size, SymbolContextScope *context,
+   lldb::user_id_t encoding_uid,
+   Type::EncodingDataType encoding_uid_type, const Declaration &decl,
+   const CompilerType &compiler_qual_type,
+   Type::ResolveState compiler_type_resolve_state,
+   uint32_t opaque_payload = 0) = 0;
+
 protected:
   void AssertModuleLock();
 
@@ -492,6 +501,26 @@ class SymbolFileCommon : public SymbolFile {
  m_debug_info_had_variable_errors = true;
   }
 
+  /// This function is used to create types that belong to a SymbolFile. The
+  /// symbol file will own a strong reference to the type in an internal type
+  /// list.
+  lldb::TypeSP MakeType(lldb::user_id_t uid, ConstString name,
+std::optional byte_size,
+SymbolContextScope *context,
+lldb::user_id_t encoding_uid,
+Type::EncodingDataType encoding_uid_type,
+const Declaration &decl,
+const CompilerType &compiler_qual_type,
+Type::ResolveState compiler_type_resolve_state,
+uint32_t opaque_payload = 0) override {
+ lldb::TypeSP type_sp (new Type(
+ uid, this, name, byte_size, context, encoding_uid,
+ encoding_uid_type, decl, compiler_qual_type,
+ compiler_type_resolve_state, opaque_payload));
+ m_type_list.Insert(type_sp);
+ return type_sp;
+  }
+
 protected:
   virtual uint32_t CalculateNumCompileUnits() = 0;
   virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t idx) = 0;

diff  --git a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h 
b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h
index 1f5b0c0902b3c..b615356246c64 100644
--- a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h
+++ b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h
@@ -227,6 +227,20 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile 
{
 return m_sym_file_impl->SetDebugInfoHadFrameVariableErrors();
   }
 
+  lldb::TypeSP MakeType(lldb::user_id_t uid, ConstString name,
+std::optional byte_size,
+SymbolContextScope *context,
+lldb::user_id_t encoding_uid,
+Type::EncodingDataType encoding_uid_type,
+const Declaration &decl,
+const CompilerType &compiler_qual_type,
+Type::ResolveState compiler_type_resolve_state,
+uint32_t opaque_payload = 0) override {
+return m_sym_file_impl->MakeType(
+uid, name, byte_size, context, encoding_uid, encoding_uid_type, decl,
+compiler_qual_type, compiler_type_resolve_state, opaque_payload);
+  }
+
 private:
   Log *GetLog() const { return ::lldb_private::GetLog(LLDBLog::OnDemand); }
 

diff  --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index d04a0fecd421f..fa494172219c9 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -22,6 +22,7 @@
 #include 
 
 namespace lldb_private {
+class SymbolFileCommon;
 
 /// CompilerContext allows an array of these items to be passed to perform
 /// detailed lookups in SymbolVendor and SymbolFile functions.
@@ -101,16 +102,6 @@ class Type : public std::enable_shared_fro

[Lldb-commits] [lldb] 901ba0f - [lldb] Implement SymbolFile::CopyType

2023-01-20 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-01-20T13:02:04-08:00
New Revision: 901ba0fcae3651c81051fd8da2695bbc2bcb3c91

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

LOG: [lldb] Implement SymbolFile::CopyType

SymbolFiles should be the only point of creation of Types to ensure
that they aren't destroyed prematurely by keeping them in the
SymbolFile's TypeList. This patch hides the copy constructor of Types,
and adds a new CopyType function to SymbolFile, so Types can still be
copied safely.

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

Added: 


Modified: 
lldb/include/lldb/Symbol/SymbolFile.h
lldb/include/lldb/Symbol/SymbolFileOnDemand.h
lldb/include/lldb/Symbol/Type.h

Removed: 




diff  --git a/lldb/include/lldb/Symbol/SymbolFile.h 
b/lldb/include/lldb/Symbol/SymbolFile.h
index 1be3323f715be..8548973bad3ff 100644
--- a/lldb/include/lldb/Symbol/SymbolFile.h
+++ b/lldb/include/lldb/Symbol/SymbolFile.h
@@ -421,6 +421,8 @@ class SymbolFile : public PluginInterface {
Type::ResolveState compiler_type_resolve_state,
uint32_t opaque_payload = 0) = 0;
 
+  virtual lldb::TypeSP CopyType(const lldb::TypeSP &other_type) = 0;
+
 protected:
   void AssertModuleLock();
 
@@ -521,6 +523,15 @@ class SymbolFileCommon : public SymbolFile {
  return type_sp;
   }
 
+  lldb::TypeSP CopyType(const lldb::TypeSP &other_type) override {
+ // Make sure the real symbol file matches when copying types.
+ if (GetBackingSymbolFile() != other_type->GetSymbolFile())
+  return lldb::TypeSP();
+ lldb::TypeSP type_sp(new Type(*other_type));
+ m_type_list.Insert(type_sp);
+ return type_sp;
+  }
+
 protected:
   virtual uint32_t CalculateNumCompileUnits() = 0;
   virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t idx) = 0;

diff  --git a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h 
b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h
index b615356246c64..825fba755e990 100644
--- a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h
+++ b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h
@@ -241,6 +241,10 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile 
{
 compiler_qual_type, compiler_type_resolve_state, opaque_payload);
   }
 
+  lldb::TypeSP CopyType(const lldb::TypeSP &other_type) override {
+return m_sym_file_impl->CopyType(other_type);
+  }
+
 private:
   Log *GetLog() const { return ::lldb_private::GetLog(LLDBLog::OnDemand); }
 

diff  --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index fa494172219c9..046501931d211 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -241,6 +241,14 @@ class Type : public std::enable_shared_from_this, 
public UserID {
   // This makes an invalid type.  Used for functions that return a Type when
   // they get an error.
   Type();
+
+  Type(Type &t) = default;
+
+  Type(Type &&t) = default;
+
+  Type &operator=(const Type &t) = default;
+
+  Type &operator=(Type &&t) = default;
 };
 
 // the two classes here are used by the public API as a backend to the SBType



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


[Lldb-commits] [lldb] 294ca12 - Adapt TestCustomShell and TestMultipleDebuggers to run under ASAN

2023-02-10 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-02-10T17:19:21-08:00
New Revision: 294ca122956f78aef3ab4e81108b69518e353b07

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

LOG: Adapt TestCustomShell and TestMultipleDebuggers to run under ASAN

In situations where only LLDB is ASANified, a false positive occurs
unless ASAN_OPTIONS=detect_container_overflow=0 is set in the
environment.

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

Added: 


Modified: 
lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py
lldb/test/Shell/Host/TestCustomShell.test

Removed: 




diff  --git a/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py 
b/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py
index da7445f27eac..07e668c5115e 100644
--- a/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py
+++ b/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py
@@ -15,7 +15,9 @@ class TestMultipleSimultaneousDebuggers(TestBase):
 @skipIfNoSBHeaders
 @skipIfWindows
 def test_multiple_debuggers(self):
-env = {self.dylibPath: self.getLLDBLibraryEnvVal()}
+env = {self.dylibPath: self.getLLDBLibraryEnvVal(),
+  # We need this in order to run under ASAN, in case only LLDB is 
ASANified.
+  'ASAN_OPTIONS': os.getenv('ASAN_OPTIONS', None)}
 
 self.driver_exe = self.getBuildArtifact("multi-process-driver")
 self.buildDriver('multi-process-driver.cpp', self.driver_exe)

diff  --git a/lldb/test/Shell/Host/TestCustomShell.test 
b/lldb/test/Shell/Host/TestCustomShell.test
index 61094ec67bc2..0e948a1b1f7f 100644
--- a/lldb/test/Shell/Host/TestCustomShell.test
+++ b/lldb/test/Shell/Host/TestCustomShell.test
@@ -7,7 +7,7 @@
 
 # RUN: %clang_host %S/Inputs/simple.c -g -o %t.out
 # RUN: SHELL=bogus not %lldb %t.out -b -o 'process launch -X 1 --' 2>&1 | 
FileCheck %s --check-prefix ERROR
-# RUN: env -i %lldb %t.out -b -o 'process launch -X 1 --' 2>&1 | FileCheck %s
+# RUN: env -i ASAN_OPTIONS='detect_container_overflow=0' %lldb %t.out -b -o 
'process launch -X 1 --' 2>&1 | FileCheck %s
 
 # ERROR: error: shell expansion failed
 # CHECK-NOT: error: shell expansion failed



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


[Lldb-commits] [lldb] 29fa21e - [lldb] Fix passing None as an env variable in TestMultipleDebuggers

2023-02-10 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-02-10T17:32:48-08:00
New Revision: 29fa21eb61293e677a8de4bacd843ef57192b60b

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

LOG: [lldb] Fix passing None as an env variable in TestMultipleDebuggers

Added: 


Modified: 
lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py

Removed: 




diff  --git a/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py 
b/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py
index 07e668c5115e..64ee1a682307 100644
--- a/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py
+++ b/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py
@@ -15,9 +15,12 @@ class TestMultipleSimultaneousDebuggers(TestBase):
 @skipIfNoSBHeaders
 @skipIfWindows
 def test_multiple_debuggers(self):
-env = {self.dylibPath: self.getLLDBLibraryEnvVal(),
-  # We need this in order to run under ASAN, in case only LLDB is 
ASANified.
-  'ASAN_OPTIONS': os.getenv('ASAN_OPTIONS', None)}
+env = {self.dylibPath: self.getLLDBLibraryEnvVal()}
+
+# We need this in order to run under ASAN, in case only LLDB is 
ASANified.
+asan_options = os.getenv('ASAN_OPTIONS', None)
+if (asan_options is not None):
+env['ASAN_OPTIONS'] = asan_options
 
 self.driver_exe = self.getBuildArtifact("multi-process-driver")
 self.buildDriver('multi-process-driver.cpp', self.driver_exe)



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


[Lldb-commits] [lldb] 581ac50 - [lldb] Only replace valobj with persisted one if not null in DWIMPrint

2023-03-08 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-03-08T14:18:40-08:00
New Revision: 581ac50d58b99a37244e9d4e0d8d12c9c810f472

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

LOG: [lldb] Only replace valobj with persisted one if not null in DWIMPrint

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

Added: 


Modified: 
lldb/source/Commands/CommandObjectDWIMPrint.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index e2e6f6706dee0..d8bc7a1e89696 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -88,8 +88,10 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command,
   if (StackFrame *frame = m_exe_ctx.GetFramePtr()) {
 auto valobj_sp = frame->FindVariable(ConstString(expr));
 if (valobj_sp && valobj_sp->GetError().Success()) {
-  if (!eval_options.GetSuppressPersistentResult())
-valobj_sp = valobj_sp->Persist();
+  if (!eval_options.GetSuppressPersistentResult()) {
+if (auto persisted_valobj = valobj_sp->Persist())
+  valobj_sp = persisted_valobj;
+  }
 
   if (verbosity == eDWIMPrintVerbosityFull) {
 StringRef flags;



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


[Lldb-commits] [lldb] f03cd76 - [lldb] Introduce SymbolFile::ParseAllLanguages

2023-03-18 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-03-18T10:33:14-07:00
New Revision: f03cd763384bbb67ddfa12957859ed58841d4b34

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

LOG: [lldb] Introduce SymbolFile::ParseAllLanguages

SymbolFile::ParseAllLanguages allows collecting the languages of the
extra compile units a SymbolFileDWARFDebugMap may have, which can't
be accessed otherwise. For every other symbol file type, it should
behave exactly the same as ParseLanguage.

rdar://97610458

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

Added: 


Modified: 
lldb/include/lldb/Symbol/SymbolFile.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Removed: 




diff  --git a/lldb/include/lldb/Symbol/SymbolFile.h 
b/lldb/include/lldb/Symbol/SymbolFile.h
index 8548973bad3ff..d3e3166ab27ff 100644
--- a/lldb/include/lldb/Symbol/SymbolFile.h
+++ b/lldb/include/lldb/Symbol/SymbolFile.h
@@ -25,6 +25,7 @@
 #include "lldb/Utility/XcodeSDK.h"
 #include "lldb/lldb-private.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/Errc.h"
 
 #include 
@@ -146,6 +147,17 @@ class SymbolFile : public PluginInterface {
   virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0;
   /// Return the Xcode SDK comp_unit was compiled against.
   virtual XcodeSDK ParseXcodeSDK(CompileUnit &comp_unit) { return {}; }
+
+  /// This function exists because SymbolFileDWARFDebugMap may extra compile
+  /// units which aren't exposed as "real" compile units. In every other
+  /// case this function should behave identically as ParseLanguage.
+  virtual llvm::SmallSet
+  ParseAllLanguages(CompileUnit &comp_unit) {
+llvm::SmallSet langs;
+langs.insert(ParseLanguage(comp_unit));
+return langs;
+  }
+
   virtual size_t ParseFunctions(CompileUnit &comp_unit) = 0;
   virtual bool ParseLineTable(CompileUnit &comp_unit) = 0;
   virtual bool ParseDebugMacros(CompileUnit &comp_unit) = 0;

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
index c8140f0f9148e..9b22b1b94aae4 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -683,6 +683,17 @@ XcodeSDK 
SymbolFileDWARFDebugMap::ParseXcodeSDK(CompileUnit &comp_unit) {
   return {};
 }
 
+llvm::SmallSet
+SymbolFileDWARFDebugMap::ParseAllLanguages(
+lldb_private::CompileUnit &comp_unit) {
+  llvm::SmallSet langs;
+  auto *info = GetCompUnitInfo(comp_unit);
+  for (auto &comp_unit : info->compile_units_sps) {
+langs.insert(comp_unit->GetLanguage());
+  }
+  return langs;
+}
+
 size_t SymbolFileDWARFDebugMap::ParseFunctions(CompileUnit &comp_unit) {
   std::lock_guard guard(GetModuleMutex());
   SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
index 485fb5b8f908d..84f78d87d64ca 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -62,6 +62,8 @@ class SymbolFileDWARFDebugMap : public 
lldb_private::SymbolFileCommon {
   ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
   lldb_private::XcodeSDK
   ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
+  llvm::SmallSet
+  ParseAllLanguages(lldb_private::CompileUnit &comp_unit) override;
   size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
   bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
   bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;



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


[Lldb-commits] [lldb] 19d969e - [lldb] Implement SymbolFile::GetCompileOptions

2023-04-10 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-04-10T10:13:06-07:00
New Revision: 19d969e340c9e1b5a83ad5220ba0875393df71e2

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

LOG: [lldb] Implement SymbolFile::GetCompileOptions

Implement SymbolFile::GetCompileOptions, which returns a map from
compilation units to compilation arguments associated with that unit.

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

Added: 


Modified: 
lldb/include/lldb/Symbol/SymbolFile.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Removed: 




diff  --git a/lldb/include/lldb/Symbol/SymbolFile.h 
b/lldb/include/lldb/Symbol/SymbolFile.h
index d3e3166ab27ff..90162b7827d3a 100644
--- a/lldb/include/lldb/Symbol/SymbolFile.h
+++ b/lldb/include/lldb/Symbol/SymbolFile.h
@@ -30,6 +30,7 @@
 
 #include 
 #include 
+#include 
 
 #if defined(LLDB_CONFIGURATION_DEBUG)
 #define ASSERT_MODULE_LOCK(expr) (expr->AssertModuleLock())
@@ -435,9 +436,20 @@ class SymbolFile : public PluginInterface {
 
   virtual lldb::TypeSP CopyType(const lldb::TypeSP &other_type) = 0;
 
+  /// Returns a map of compilation unit to the compile option arguments
+  /// associated with that compilation unit.
+  std::unordered_map GetCompileOptions() {
+std::unordered_map args;
+GetCompileOptions(args);
+return args;
+  }
+
 protected:
   void AssertModuleLock();
 
+  virtual void GetCompileOptions(
+  std::unordered_map &args) {}
+
 private:
   SymbolFile(const SymbolFile &) = delete;
   const SymbolFile &operator=(const SymbolFile &) = delete;

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index c6873a5b7a09a..837d87cdebbb3 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -4255,3 +4255,30 @@ Status 
SymbolFileDWARF::CalculateFrameVariableError(StackFrame &frame) {
   return Status("no variable information is available in debug info for this "
 "compile unit");
 }
+
+void SymbolFileDWARF::GetCompileOptions(
+std::unordered_map &args) {
+
+  const uint32_t num_compile_units = GetNumCompileUnits();
+
+  for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
+lldb::CompUnitSP comp_unit = GetCompileUnitAtIndex(cu_idx);
+if (!comp_unit)
+  continue;
+
+DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit.get());
+if (!dwarf_cu)
+  continue;
+
+const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
+if (!die)
+  continue;
+
+const char *flags = die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL);
+
+if (!flags)
+  continue;
+args.insert({comp_unit, Args(flags)});
+  }
+}
+

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
index 09787d5072aa4..0616846d8dc62 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -523,6 +523,9 @@ class SymbolFileDWARF : public 
lldb_private::SymbolFileCommon {
 
   void InitializeFirstCodeAddress();
 
+  void GetCompileOptions(
+  std::unordered_map &args) override;
+
   lldb::ModuleWP m_debug_map_module_wp;
   SymbolFileDWARFDebugMap *m_debug_map_symfile;
 

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
index 9b22b1b94aae4..a07807241deba 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -1549,3 +1549,12 @@ Status 
SymbolFileDWARFDebugMap::CalculateFrameVariableError(StackFrame &frame) {
   }
   return Status();
 }
+
+void SymbolFileDWARFDebugMap::GetCompileOptions(
+std::unordered_map &args) {
+
+  ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
+oso_dwarf->GetCompileOptions(args);
+return false;
+  });
+}

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
index 84f78d87d64ca..0313063119c78 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -153,6 +153,9 @@ class SymbolFileDWARFDebugMap : public 
lldb_private::SymbolFileCommon {
   // Statistics overrides.
   lldb_private::ModuleList GetDebugInfoModules() override;
 
+  void GetCompileOptions(
+  std::unordered_map &args) ov

[Lldb-commits] [lldb] 8fe9718 - [lldb] Implement GetValueTypeFromAddressType

2023-05-18 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-05-18T10:29:15-07:00
New Revision: 8fe9718dd5f27168fc282c6420bfae0eb7ee6819

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

LOG: [lldb] Implement GetValueTypeFromAddressType

Value::ValueType is a superset of AddressType. Add a function to
convert an AddressType into a Value::ValueType.

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

Added: 


Modified: 
lldb/include/lldb/Core/Value.h
lldb/source/Core/Value.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Value.h b/lldb/include/lldb/Core/Value.h
index fdda9f1db491a..ead23acc6f9b1 100644
--- a/lldb/include/lldb/Core/Value.h
+++ b/lldb/include/lldb/Core/Value.h
@@ -145,6 +145,8 @@ class Value {
 
   void Clear();
 
+  static ValueType GetValueTypeFromAddressType(AddressType address_type);
+
 protected:
   Scalar m_value;
   CompilerType m_compiler_type;

diff  --git a/lldb/source/Core/Value.cpp b/lldb/source/Core/Value.cpp
index ccd36096b5456..5a2631ca501f6 100644
--- a/lldb/source/Core/Value.cpp
+++ b/lldb/source/Core/Value.cpp
@@ -121,6 +121,20 @@ AddressType Value::GetValueAddressType() const {
   return eAddressTypeInvalid;
 }
 
+Value::ValueType Value::GetValueTypeFromAddressType(AddressType address_type) {
+  switch (address_type) {
+case eAddressTypeFile:
+  return Value::ValueType::FileAddress;
+case eAddressTypeLoad:
+  return Value::ValueType::LoadAddress;
+case eAddressTypeHost:
+  return Value::ValueType::HostAddress;
+case eAddressTypeInvalid:
+  return Value::ValueType::Invalid;
+  }
+  llvm_unreachable("Unexpected address type!");
+}
+
 RegisterInfo *Value::GetRegisterInfo() const {
   if (m_context_type == ContextType::RegisterInfo)
 return static_cast(m_context);



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


[Lldb-commits] [lldb] b1ebfc5 - [lldb] Unconditionally increment depth when printing children

2023-06-08 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-06-08T13:30:30-07:00
New Revision: b1ebfc5de34ef4c91aa6f163989de600fb5227f8

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

LOG: [lldb] Unconditionally increment depth when printing children

The `target.max-children-depth` setting and `--depth` flag would be
ignored if treating pointer as arrays, fix that by always incrementing
the current depth when printing a new child.

rdar://109855463

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

Added: 
lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/Makefile

lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/main.cpp

Modified: 
lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
lldb/source/DataFormatters/ValueObjectPrinter.cpp

Removed: 




diff  --git a/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h 
b/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
index b622c34ec3e0f..c7f8116c4 100644
--- a/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
+++ b/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
@@ -25,7 +25,7 @@ class DumpValueObjectOptions {
 enum class Mode { Always, Default, Never } m_mode;
 uint32_t m_count;
 
-PointerDepth operator--() const {
+PointerDepth Decremented() const {
   if (m_count > 0)
 return PointerDepth{m_mode, m_count - 1};
   return PointerDepth{m_mode, m_count};

diff  --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp 
b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
index fac319f67c805..16aeff13791c5 100644
--- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp
+++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
@@ -590,7 +590,7 @@ void ValueObjectPrinter::PrintChildrenPreamble(bool 
value_printed,
 void ValueObjectPrinter::PrintChild(
 ValueObjectSP child_sp,
 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
-  const uint32_t consumed_depth = (!m_options.m_pointer_as_array) ? 1 : 0;
+  const uint32_t consumed_summary_depth = m_options.m_pointer_as_array ? 0 : 1;
   const bool does_consume_ptr_depth =
   ((IsPtr() && !m_options.m_pointer_as_array) || IsRef());
 
@@ -603,15 +603,18 @@ void ValueObjectPrinter::PrintChild(
   .SetHideValue(m_options.m_hide_value)
   .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1
? child_options.m_omit_summary_depth -
- consumed_depth
+ consumed_summary_depth
: 0)
   .SetElementCount(0);
 
   if (child_sp.get()) {
-ValueObjectPrinter child_printer(
-child_sp.get(), m_stream, child_options,
-does_consume_ptr_depth ? --curr_ptr_depth : curr_ptr_depth,
-m_curr_depth + consumed_depth, m_printed_instance_pointers);
+auto ptr_depth = curr_ptr_depth;
+if (does_consume_ptr_depth)
+  ptr_depth = curr_ptr_depth.Decremented();
+
+ValueObjectPrinter child_printer(child_sp.get(), m_stream, child_options,
+ ptr_depth, m_curr_depth + 1,
+ m_printed_instance_pointers);
 child_printer.PrintValueObject();
   }
 }

diff  --git a/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/Makefile 
b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/Makefile
new file mode 100644
index 0..8b20bcb05
--- /dev/null
+++ b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules

diff  --git 
a/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
 
b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
new file mode 100644
index 0..e8fa95ef6469a
--- /dev/null
+++ 
b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
@@ -0,0 +1,27 @@
+"""
+Tests that frame variable --depth and --element-count options work correctly
+together
+"""
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class TestFrameVarDepthAndElemCount(TestBase):
+def test(self):
+"""Test that bool types work in the expression parser"""
+self.build()
+lldbutil.run_to_source_breakpoint(
+self, "// break here", lldb.SBFileSpec("main.cpp")
+)
+
+# Check that we print 5 elements but only 2 levels deep.
+self.expect('frame var --depth 2 --element-count 5 -- c', 
+substrs=[
+'[0] = {\nb ={...}\n  }',
+'[1] = {\nb ={...}\n  }',
+'[2] = {

[Lldb-commits] [lldb] f94c7ff - [lldb] Never print children if the max depth has been reached

2023-06-13 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2023-06-13T11:03:04-07:00
New Revision: f94c7ffe46400559740e7f81d7c60d8c0fe7df82

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

LOG: [lldb] Never print children if the max depth has been reached

When formatting a variable, the max depth would potentially be ignored
if the current value object failed to print itself. Change that to
always respect the max depth, even if failure occurs.

rdar://109855463

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

Added: 


Modified: 
lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
lldb/source/DataFormatters/ValueObjectPrinter.cpp

lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/main.cpp

Removed: 




diff  --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h 
b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
index a4946a20591a5..2b3936eaa707f 100644
--- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
+++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
@@ -91,8 +91,7 @@ class ValueObjectPrinter {
   bool PrintObjectDescriptionIfNeeded(bool value_printed, bool 
summary_printed);
 
   bool
-  ShouldPrintChildren(bool is_failed_description,
-  DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
+  ShouldPrintChildren(DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
 
   bool ShouldExpandEmptyAggregates();
 

diff  --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp 
b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
index 16aeff13791c5..8e89b0bd4797e 100644
--- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp
+++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
@@ -502,7 +502,6 @@ bool 
DumpValueObjectOptions::PointerDepth::CanAllowExpansion() const {
 }
 
 bool ValueObjectPrinter::ShouldPrintChildren(
-bool is_failed_description,
 DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
   const bool is_ref = IsRef();
   const bool is_ptr = IsPtr();
@@ -511,6 +510,10 @@ bool ValueObjectPrinter::ShouldPrintChildren(
   if (is_uninit)
 return false;
 
+  // If we have reached the maximum depth we shouldn't print any more children.
+  if (HasReachedMaximumDepth())
+return false;
+
   // if the user has specified an element count, always print children as it is
   // explicit user demand being honored
   if (m_options.m_pointer_as_array)
@@ -523,37 +526,34 @@ bool ValueObjectPrinter::ShouldPrintChildren(
   if (TypeSummaryImpl *type_summary = GetSummaryFormatter())
 print_children = type_summary->DoesPrintChildren(m_valobj);
 
-  if (is_failed_description || !HasReachedMaximumDepth()) {
-// We will show children for all concrete types. We won't show pointer
-// contents unless a pointer depth has been specified. We won't reference
-// contents unless the reference is the root object (depth of zero).
+  // We will show children for all concrete types. We won't show pointer
+  // contents unless a pointer depth has been specified. We won't reference
+  // contents unless the reference is the root object (depth of zero).
 
-// Use a new temporary pointer depth in case we override the current
-// pointer depth below...
+  // Use a new temporary pointer depth in case we override the current
+  // pointer depth below...
 
-if (is_ptr || is_ref) {
-  // We have a pointer or reference whose value is an address. Make sure
-  // that address is not NULL
-  AddressType ptr_address_type;
-  if (m_valobj->GetPointerValue(&ptr_address_type) == 0)
-return false;
+  if (is_ptr || is_ref) {
+// We have a pointer or reference whose value is an address. Make sure
+// that address is not NULL
+AddressType ptr_address_type;
+if (m_valobj->GetPointerValue(&ptr_address_type) == 0)
+  return false;
 
-  const bool is_root_level = m_curr_depth == 0;
+const bool is_root_level = m_curr_depth == 0;
 
-  if (is_ref && is_root_level && print_children) {
-// If this is the root object (depth is zero) that we are showing and
-// it is a reference, and no pointer depth has been supplied print out
-// what it references. Don't do this at deeper depths otherwise we can
-// end up with infinite recursion...
-return true;
-  }
-
-  return curr_ptr_depth.CanAllowExpansion();
+if (is_ref && is_root_level && print_children) {
+  // If this is the root object (depth is zero) that we are showing and
+  // it is a reference, and no pointer depth has been supplied print out
+  // what it references. Don't do this at deeper depths otherwise we can
+  // end up with infinite recursion...
+  return true

[Lldb-commits] [lldb] 47dd1f6 - [lldb] Skip TestAppleSimulatorOSType if json parsing fails

2021-09-16 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2021-09-16T16:38:20-03:00
New Revision: 47dd1f642846d476e3d789f4aa941699dc0ed3fe

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

LOG: [lldb] Skip TestAppleSimulatorOSType if json parsing fails

xcodebuild, which is invoked by the apple_simulator_test decorator, may
may return a successful status even if it was unable to run due to the
authorization agent denying it. This causes the TestAppleSimulatorOSType
to run when it shouldn't, and throw an excpection when parsing the JSON
that lists the simulators available. Wrap the json parsing in a
try/except block and if it fails, skip the ttest.

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

Added: 


Modified: 
lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py

Removed: 




diff  --git a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py 
b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
index 01942344e0e10..1230af95a9a33 100644
--- a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
+++ b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
@@ -20,7 +20,16 @@ def check_simulator_ostype(self, sdk, platform_name, 
arch=platform.machine()):
 cmd = ['xcrun', 'simctl', 'list', '-j', 'devices']
 self.trace(' '.join(cmd))
 sim_devices_str = subprocess.check_output(cmd).decode("utf-8")
-sim_devices = json.loads(sim_devices_str)['devices']
+
+# xcodebuild, which is invoked by the apple_simulator_test decorator,
+# may return a successful status even if it was unable to run due to 
+# the authorization agent denying it. Try to parse the json that lists 
+# the simulators but if that fails skip the test.
+try:
+sim_devices = json.loads(sim_devices_str)['devices']
+except json.decoder.JSONDecodeError:
+self.skipTest("Could not parse JSON of simulators available")
+
 # Find an available simulator for the requested platform
 deviceUDID = None
 deviceRuntime = None



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


[Lldb-commits] [lldb] 8fb8601 - Revert "[lldb] Skip TestAppleSimulatorOSType if json parsing fails"

2021-09-16 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2021-09-16T17:49:59-03:00
New Revision: 8fb86011026c56204e54a2806d598249c6297d08

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

LOG: Revert "[lldb] Skip TestAppleSimulatorOSType if json parsing fails"

This reverts commit 47dd1f642846d476e3d789f4aa941699dc0ed3fe.
After discussing with Jim Ingham, we agreed to leave the test as-is
so we can catch any CI problems instead of silently skipping the test.

Added: 


Modified: 
lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py

Removed: 




diff  --git a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py 
b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
index 1230af95a9a33..01942344e0e10 100644
--- a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
+++ b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
@@ -20,16 +20,7 @@ def check_simulator_ostype(self, sdk, platform_name, 
arch=platform.machine()):
 cmd = ['xcrun', 'simctl', 'list', '-j', 'devices']
 self.trace(' '.join(cmd))
 sim_devices_str = subprocess.check_output(cmd).decode("utf-8")
-
-# xcodebuild, which is invoked by the apple_simulator_test decorator,
-# may return a successful status even if it was unable to run due to 
-# the authorization agent denying it. Try to parse the json that lists 
-# the simulators but if that fails skip the test.
-try:
-sim_devices = json.loads(sim_devices_str)['devices']
-except json.decoder.JSONDecodeError:
-self.skipTest("Could not parse JSON of simulators available")
-
+sim_devices = json.loads(sim_devices_str)['devices']
 # Find an available simulator for the requested platform
 deviceUDID = None
 deviceRuntime = None



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


[Lldb-commits] [lldb] fbaf367 - [lldb] Show fix-it applied even if expression didn't evaluate succesfully

2021-09-23 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2021-09-23T16:45:04-03:00
New Revision: fbaf36721783c3bcbd45f81294e6980eaef165e4

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

LOG: [lldb] Show fix-it applied even if expression didn't evaluate succesfully

If we applied a fix-it before evaluating an expression and that
expression didn't evaluate correctly, we should still tell users about
the fix-it we applied since that may be the reason why it didn't work
correctly.

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

Added: 


Modified: 
lldb/source/Commands/CommandObjectExpression.cpp
lldb/test/API/commands/expression/fixits/TestFixIts.py
lldb/test/API/commands/expression/fixits/main.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectExpression.cpp 
b/lldb/source/Commands/CommandObjectExpression.cpp
index bf62f3f297cc..a93cc15b0ff3 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -421,9 +421,8 @@ bool 
CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
   // We only tell you about the FixIt if we applied it.  The compiler errors
   // will suggest the FixIt if it parsed.
   if (!m_fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) {
-if (success == eExpressionCompleted)
-  error_stream.Printf("  Fix-it applied, fixed expression was: \n%s\n",
-  m_fixed_expression.c_str());
+error_stream.Printf("  Fix-it applied, fixed expression was: \n%s\n",
+m_fixed_expression.c_str());
   }
 
   if (result_valobj_sp) {

diff  --git a/lldb/test/API/commands/expression/fixits/TestFixIts.py 
b/lldb/test/API/commands/expression/fixits/TestFixIts.py
index a2e4564f7078..686f56ad7974 100644
--- a/lldb/test/API/commands/expression/fixits/TestFixIts.py
+++ b/lldb/test/API/commands/expression/fixits/TestFixIts.py
@@ -82,6 +82,22 @@ def test_with_target(self):
 error_string.find("my_pointer->second.a") != -1,
 "Fix was right")
 
+def test_with_target_error_applies_fixit(self):
+""" Check that applying a Fix-it which fails to execute correctly 
still 
+ prints that the Fix-it was applied. """
+self.build()
+(target, process, self.thread, bkpt) = 
lldbutil.run_to_source_breakpoint(self,
+'Stop here to evaluate expressions',
+ lldb.SBFileSpec("main.cpp"))
+# Enable fix-its as they were intentionally disabled by TestBase.setUp.
+self.runCmd("settings set target.auto-apply-fixits true")
+ret_val = lldb.SBCommandReturnObject()
+result = self.dbg.GetCommandInterpreter().HandleCommand("expression 
null_pointer.first", ret_val)
+self.assertEqual(result, lldb.eReturnStatusFailed, ret_val.GetError())
+
+self.assertIn("Fix-it applied, fixed expression was:", 
ret_val.GetError())
+self.assertIn("null_pointer->first", ret_val.GetError())
+
 # The final function call runs into SIGILL on aarch64-linux.
 @expectedFailureAll(archs=["aarch64"], oslist=["freebsd", "linux"],
 bugnumber="llvm.org/pr49407")

diff  --git a/lldb/test/API/commands/expression/fixits/main.cpp 
b/lldb/test/API/commands/expression/fixits/main.cpp
index 371d8333763b..0162ed24bd84 100644
--- a/lldb/test/API/commands/expression/fixits/main.cpp
+++ b/lldb/test/API/commands/expression/fixits/main.cpp
@@ -17,6 +17,7 @@ main()
 {
   struct MyStruct my_struct = {10, {20, 30}};
   struct MyStruct *my_pointer = &my_struct;
+  struct MyStruct *null_pointer = nullptr;
   printf ("Stop here to evaluate expressions: %d %d %p\n", my_pointer->first, 
my_pointer->second.a, my_pointer);
   return 0;
 }



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


[Lldb-commits] [lldb] [lldb][NFC] Implement llvm-style RTTI for DWARFASTParser (PR #69762)

2023-10-20 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/69762

None

>From 2cc3dc43d5ef705a016b8b7b3c23d99d5f01a5d8 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Fri, 20 Oct 2023 12:42:52 -0700
Subject: [PATCH] [lldb][NFC] Implement llvm-style RTTI for DWARFASTParser

---
 lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h | 8 
 .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp  | 3 ++-
 .../source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h | 4 
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index eaafbe169cc8cfc..99527fb83f1fa0a 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -29,6 +29,9 @@ class SymbolFileDWARF;
 
 class DWARFASTParser {
 public:
+  enum class Kind { DWARFASTParserClang, DWARFASTParserSwift };
+  DWARFASTParser(Kind kind) : m_kind(kind) {}
+
   virtual ~DWARFASTParser() = default;
 
   virtual lldb::TypeSP ParseTypeFromDWARF(const SymbolContext &sc,
@@ -62,6 +65,11 @@ class DWARFASTParser {
   const ExecutionContext *exe_ctx = nullptr);
 
   static lldb::AccessType GetAccessTypeFromDWARF(uint32_t dwarf_accessibility);
+
+  Kind GetKind() const { return m_kind; }
+
+private:
+  const Kind m_kind;
 };
 } // namespace dwarf
 } // namespace lldb_private::plugin
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 545a5dcc7d0fd09..5d107ce63b8bc25 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -63,7 +63,8 @@ using namespace lldb_private::dwarf;
 using namespace lldb_private::plugin::dwarf;
 
 DWARFASTParserClang::DWARFASTParserClang(TypeSystemClang &ast)
-: m_ast(ast), m_die_to_decl_ctx(), m_decl_ctx_to_die() {}
+: DWARFASTParser(Kind::DWARFASTParserClang), m_ast(ast),
+  m_die_to_decl_ctx(), m_decl_ctx_to_die() {}
 
 DWARFASTParserClang::~DWARFASTParserClang() = default;
 
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 3d6912cf56c1779..d58fcf4a64dab3b 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -248,6 +248,10 @@ class DWARFASTParserClang : public 
lldb_private::plugin::dwarf::DWARFASTParser {
   lldb::ModuleSP
   GetModuleForType(const lldb_private::plugin::dwarf::DWARFDIE &die);
 
+  static bool classof(const DWARFASTParser *Parser) {
+return Parser->GetKind() == Kind::DWARFASTParserClang;
+  }
+
 private:
   struct FieldInfo {
 uint64_t bit_size = 0;

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


[Lldb-commits] [lldb] [lldb][NFC] Move GetTypeForDIE from to DWARFASTParser (PR #69764)

2023-10-20 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/69764

None

>From c97e0b62a2df5309db707861b5f1fd2c223ac50b Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Fri, 20 Oct 2023 12:59:00 -0700
Subject: [PATCH] [lldb][NFC] Move GetTypeForDIE from to DWARFASTParser

---
 .../SymbolFile/DWARF/DWARFASTParser.cpp   | 26 +++
 .../Plugins/SymbolFile/DWARF/DWARFASTParser.h |  3 +++
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 24 -
 .../SymbolFile/DWARF/DWARFASTParserClang.h|  3 ---
 4 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
index 1fe0cadecc9e70e..30c0659f00efe92 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
@@ -9,6 +9,7 @@
 #include "DWARFASTParser.h"
 #include "DWARFAttribute.h"
 #include "DWARFDIE.h"
+#include "SymbolFileDWARF.h"
 
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Symbol/SymbolFile.h"
@@ -100,6 +101,31 @@ DWARFASTParser::ParseChildArrayInfo(const DWARFDIE 
&parent_die,
   return array_info;
 }
 
+
+Type *DWARFASTParser::GetTypeForDIE(const DWARFDIE &die) {
+  if (!die)
+return nullptr;
+
+  SymbolFileDWARF *dwarf = die.GetDWARF();
+  if (!dwarf)
+return nullptr;
+
+  DWARFAttributes attributes = die.GetAttributes();
+  if (attributes.Size() == 0)
+return nullptr;
+
+  DWARFFormValue type_die_form;
+  for (size_t i = 0; i < attributes.Size(); ++i) {
+dw_attr_t attr = attributes.AttributeAtIndex(i);
+DWARFFormValue form_value;
+
+if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, 
form_value))
+  return dwarf->ResolveTypeUID(form_value.Reference(), true);
+  }
+
+  return nullptr;
+}
+
 AccessType
 DWARFASTParser::GetAccessTypeFromDWARF(uint32_t dwarf_accessibility) {
   switch (dwarf_accessibility) {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index eaafbe169cc8cfc..19dcee508d59377 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -61,6 +61,9 @@ class DWARFASTParser {
   ParseChildArrayInfo(const DWARFDIE &parent_die,
   const ExecutionContext *exe_ctx = nullptr);
 
+  lldb_private::Type *
+  GetTypeForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
+
   static lldb::AccessType GetAccessTypeFromDWARF(uint32_t dwarf_accessibility);
 };
 } // namespace dwarf
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 545a5dcc7d0fd09..72670b9a83f001c 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3292,30 +3292,6 @@ size_t DWARFASTParserClang::ParseChildParameters(
   return arg_idx;
 }
 
-Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) {
-  if (!die)
-return nullptr;
-
-  SymbolFileDWARF *dwarf = die.GetDWARF();
-  if (!dwarf)
-return nullptr;
-
-  DWARFAttributes attributes = die.GetAttributes();
-  if (attributes.Size() == 0)
-return nullptr;
-
-  DWARFFormValue type_die_form;
-  for (size_t i = 0; i < attributes.Size(); ++i) {
-dw_attr_t attr = attributes.AttributeAtIndex(i);
-DWARFFormValue form_value;
-
-if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, 
form_value))
-  return dwarf->ResolveTypeUID(form_value.Reference(), true);
-  }
-
-  return nullptr;
-}
-
 clang::Decl *DWARFASTParserClang::GetClangDeclForDIE(const DWARFDIE &die) {
   if (!die)
 return nullptr;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 3d6912cf56c1779..f70868b793e7098 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -199,9 +199,6 @@ class DWARFASTParserClang : public 
lldb_private::plugin::dwarf::DWARFASTParser {
 const lldb_private::plugin::dwarf::DWARFDIE &die,
 ParsedDWARFTypeAttributes &attrs);
 
-  lldb_private::Type *
-  GetTypeForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
-
   clang::Decl *
   GetClangDeclForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
 

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


[Lldb-commits] [lldb] [lldb][test] Turn ObjC string literals to C-style literals (NFC) (PR #69793)

2023-10-20 Thread Augusto Noronha via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb][NFC] Implement llvm-style RTTI for DWARFASTParser (PR #69762)

2023-10-23 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [lldb][NFC] Move GetTypeForDIE from to DWARFASTParser (PR #69764)

2023-10-23 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 updated 
https://github.com/llvm/llvm-project/pull/69764

>From d84b4b293a97b75a34e4208c914988a2e5231d66 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Fri, 20 Oct 2023 12:59:00 -0700
Subject: [PATCH] [lldb][NFC] Move GetTypeForDIE from to DWARFASTParser

---
 .../SymbolFile/DWARF/DWARFASTParser.cpp   | 25 +++
 .../Plugins/SymbolFile/DWARF/DWARFASTParser.h |  3 +++
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 24 --
 .../SymbolFile/DWARF/DWARFASTParserClang.h|  3 ---
 4 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
index 1fe0cadecc9e70e..409e9bb37ab28b9 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
@@ -9,6 +9,7 @@
 #include "DWARFASTParser.h"
 #include "DWARFAttribute.h"
 #include "DWARFDIE.h"
+#include "SymbolFileDWARF.h"
 
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Symbol/SymbolFile.h"
@@ -100,6 +101,30 @@ DWARFASTParser::ParseChildArrayInfo(const DWARFDIE 
&parent_die,
   return array_info;
 }
 
+Type *DWARFASTParser::GetTypeForDIE(const DWARFDIE &die) {
+  if (!die)
+return nullptr;
+
+  SymbolFileDWARF *dwarf = die.GetDWARF();
+  if (!dwarf)
+return nullptr;
+
+  DWARFAttributes attributes = die.GetAttributes();
+  if (attributes.Size() == 0)
+return nullptr;
+
+  DWARFFormValue type_die_form;
+  for (size_t i = 0; i < attributes.Size(); ++i) {
+dw_attr_t attr = attributes.AttributeAtIndex(i);
+DWARFFormValue form_value;
+
+if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, 
form_value))
+  return dwarf->ResolveTypeUID(form_value.Reference(), true);
+  }
+
+  return nullptr;
+}
+
 AccessType
 DWARFASTParser::GetAccessTypeFromDWARF(uint32_t dwarf_accessibility) {
   switch (dwarf_accessibility) {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index eaafbe169cc8cfc..19dcee508d59377 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -61,6 +61,9 @@ class DWARFASTParser {
   ParseChildArrayInfo(const DWARFDIE &parent_die,
   const ExecutionContext *exe_ctx = nullptr);
 
+  lldb_private::Type *
+  GetTypeForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
+
   static lldb::AccessType GetAccessTypeFromDWARF(uint32_t dwarf_accessibility);
 };
 } // namespace dwarf
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 545a5dcc7d0fd09..72670b9a83f001c 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3292,30 +3292,6 @@ size_t DWARFASTParserClang::ParseChildParameters(
   return arg_idx;
 }
 
-Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) {
-  if (!die)
-return nullptr;
-
-  SymbolFileDWARF *dwarf = die.GetDWARF();
-  if (!dwarf)
-return nullptr;
-
-  DWARFAttributes attributes = die.GetAttributes();
-  if (attributes.Size() == 0)
-return nullptr;
-
-  DWARFFormValue type_die_form;
-  for (size_t i = 0; i < attributes.Size(); ++i) {
-dw_attr_t attr = attributes.AttributeAtIndex(i);
-DWARFFormValue form_value;
-
-if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, 
form_value))
-  return dwarf->ResolveTypeUID(form_value.Reference(), true);
-  }
-
-  return nullptr;
-}
-
 clang::Decl *DWARFASTParserClang::GetClangDeclForDIE(const DWARFDIE &die) {
   if (!die)
 return nullptr;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 3d6912cf56c1779..f70868b793e7098 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -199,9 +199,6 @@ class DWARFASTParserClang : public 
lldb_private::plugin::dwarf::DWARFASTParser {
 const lldb_private::plugin::dwarf::DWARFDIE &die,
 ParsedDWARFTypeAttributes &attrs);
 
-  lldb_private::Type *
-  GetTypeForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
-
   clang::Decl *
   GetClangDeclForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
 

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


[Lldb-commits] [lldb] [lldb][NFC] Remote reference to Swift in DWARFASTParser::Kind enum (PR #69984)

2023-10-23 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/69984

None

>From 2500e7fadc72c56a887b27d5f271bea5af70ccab Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Mon, 23 Oct 2023 16:35:24 -0700
Subject: [PATCH] [lldb][NFC] Remote reference to Swift in DWARFASTParser::Kind
 enum

---
 lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index 99527fb83f1fa0a..1efe0ff347d9c8f 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -29,7 +29,7 @@ class SymbolFileDWARF;
 
 class DWARFASTParser {
 public:
-  enum class Kind { DWARFASTParserClang, DWARFASTParserSwift };
+  enum class Kind { DWARFASTParserClang };
   DWARFASTParser(Kind kind) : m_kind(kind) {}
 
   virtual ~DWARFASTParser() = default;

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


[Lldb-commits] [lldb] [lldb][NFC] Remote reference to Swift in DWARFASTParser::Kind enum (PR #69984)

2023-10-23 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [lldb][NFC] Move GetTypeForDIE from to DWARFASTParser (PR #69764)

2023-10-23 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 updated 
https://github.com/llvm/llvm-project/pull/69764

>From 040c4f4d98f3306e068521e3c218bdbc170f81f3 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Fri, 20 Oct 2023 12:59:00 -0700
Subject: [PATCH] [lldb][NFC] Move DWARFASTParserClang::GetTypeForDIE to
 DWARFASTParser

---
 .../SymbolFile/DWARF/DWARFASTParser.cpp   | 25 +++
 .../Plugins/SymbolFile/DWARF/DWARFASTParser.h |  3 +++
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 24 --
 .../SymbolFile/DWARF/DWARFASTParserClang.h|  3 ---
 4 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
index 1fe0cadecc9e70e..409e9bb37ab28b9 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
@@ -9,6 +9,7 @@
 #include "DWARFASTParser.h"
 #include "DWARFAttribute.h"
 #include "DWARFDIE.h"
+#include "SymbolFileDWARF.h"
 
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Symbol/SymbolFile.h"
@@ -100,6 +101,30 @@ DWARFASTParser::ParseChildArrayInfo(const DWARFDIE 
&parent_die,
   return array_info;
 }
 
+Type *DWARFASTParser::GetTypeForDIE(const DWARFDIE &die) {
+  if (!die)
+return nullptr;
+
+  SymbolFileDWARF *dwarf = die.GetDWARF();
+  if (!dwarf)
+return nullptr;
+
+  DWARFAttributes attributes = die.GetAttributes();
+  if (attributes.Size() == 0)
+return nullptr;
+
+  DWARFFormValue type_die_form;
+  for (size_t i = 0; i < attributes.Size(); ++i) {
+dw_attr_t attr = attributes.AttributeAtIndex(i);
+DWARFFormValue form_value;
+
+if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, 
form_value))
+  return dwarf->ResolveTypeUID(form_value.Reference(), true);
+  }
+
+  return nullptr;
+}
+
 AccessType
 DWARFASTParser::GetAccessTypeFromDWARF(uint32_t dwarf_accessibility) {
   switch (dwarf_accessibility) {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index eaafbe169cc8cfc..19dcee508d59377 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -61,6 +61,9 @@ class DWARFASTParser {
   ParseChildArrayInfo(const DWARFDIE &parent_die,
   const ExecutionContext *exe_ctx = nullptr);
 
+  lldb_private::Type *
+  GetTypeForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
+
   static lldb::AccessType GetAccessTypeFromDWARF(uint32_t dwarf_accessibility);
 };
 } // namespace dwarf
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 545a5dcc7d0fd09..72670b9a83f001c 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3292,30 +3292,6 @@ size_t DWARFASTParserClang::ParseChildParameters(
   return arg_idx;
 }
 
-Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) {
-  if (!die)
-return nullptr;
-
-  SymbolFileDWARF *dwarf = die.GetDWARF();
-  if (!dwarf)
-return nullptr;
-
-  DWARFAttributes attributes = die.GetAttributes();
-  if (attributes.Size() == 0)
-return nullptr;
-
-  DWARFFormValue type_die_form;
-  for (size_t i = 0; i < attributes.Size(); ++i) {
-dw_attr_t attr = attributes.AttributeAtIndex(i);
-DWARFFormValue form_value;
-
-if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, 
form_value))
-  return dwarf->ResolveTypeUID(form_value.Reference(), true);
-  }
-
-  return nullptr;
-}
-
 clang::Decl *DWARFASTParserClang::GetClangDeclForDIE(const DWARFDIE &die) {
   if (!die)
 return nullptr;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 3d6912cf56c1779..f70868b793e7098 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -199,9 +199,6 @@ class DWARFASTParserClang : public 
lldb_private::plugin::dwarf::DWARFASTParser {
 const lldb_private::plugin::dwarf::DWARFDIE &die,
 ParsedDWARFTypeAttributes &attrs);
 
-  lldb_private::Type *
-  GetTypeForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
-
   clang::Decl *
   GetClangDeclForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
 

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


[Lldb-commits] [lldb] [lldb][NFC] Move DWARFASTParserClang::GetTypeForDIE to DWARFASTParser (PR #69764)

2023-10-23 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [lldb][NFC] Move DWARFASTParserClang::GetTypeForDIE to DWARFASTParser (PR #69764)

2023-10-23 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] Reintroduce accidentally deleted "protected" keyword in SymbolFileDWARF (PR #69990)

2023-10-23 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/69990

The "protected" was accidentally removed during refactoring of SymbolFileDWARF. 
Reintroduce it and also make DWARFASTParser a friend class since 
040c4f4d98f3306e068521e3c218bdbc170f81f3 was merged and won't build without it, 
as it dependeds on a method which was made public by accident.

>From db9023eab76b8b6d5a53c96083aabdb16423f1b5 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Mon, 23 Oct 2023 17:35:26 -0700
Subject: [PATCH] Reintroduce accidentally deleted "protected" keyword in
 SymbolFileDWARF

The "protected" was accidentally removed during refactoring of
SymbolFileDWARF. Reintroduce it and also make DWARFASTParser a friend
class since 040c4f4d98f3306e068521e3c218bdbc170f81f3 was merged and
won't build without it, as it dependeds on a method which was made
public by accident.
---
 lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
index 646d5d9a471c41c..0818ee206fe06f6 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -82,6 +82,7 @@ class SymbolFileDWARF : public SymbolFileCommon {
   friend class DebugMapModule;
   friend class DWARFCompileUnit;
   friend class DWARFDIE;
+  friend class DWARFASTParser;
   friend class ::DWARFASTParserClang;
 
   // Static Functions
@@ -321,6 +322,7 @@ class SymbolFileDWARF : public SymbolFileCommon {
 m_file_index = file_index;
   }
 
+protected:
   typedef llvm::DenseMap DIEToTypePtr;
   typedef llvm::DenseMap
   DIEToVariableSP;

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


[Lldb-commits] [lldb] Reintroduce accidentally deleted "protected" keyword in SymbolFileDWARF (PR #69990)

2023-10-23 Thread Augusto Noronha via lldb-commits


@@ -321,6 +322,7 @@ class SymbolFileDWARF : public SymbolFileCommon {
 m_file_index = file_index;
   }
 
+protected:

augusto2112 wrote:

Can't we merge it and then you can open your isolated patch with the methods 
you want to expose? Right now everything is public, including ivars.

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


[Lldb-commits] [lldb] Reintroduce accidentally deleted "protected" keyword in SymbolFileDWARF (PR #69990)

2023-10-23 Thread Augusto Noronha via lldb-commits


@@ -321,6 +322,7 @@ class SymbolFileDWARF : public SymbolFileCommon {
 m_file_index = file_index;
   }
 
+protected:

augusto2112 wrote:

I think the big issue on keeping everything public is that will will use those 
methods without realizing they were supposed to be private (like I did), and 
then it'll be a bigger problem to disentangle that later on.

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


[Lldb-commits] [lldb] Reintroduce accidentally deleted "protected" keyword in SymbolFileDWARF (PR #69990)

2023-10-24 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [lldb][gardening] Remove full name of "DWARFDIE" type in GetTypeForDIE (PR #70062)

2023-10-24 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 created 
https://github.com/llvm/llvm-project/pull/70062

When moving the GetTypeForDIE function from DWARFASTParserClang to 
DWARFASTParser, I kept the signature as-is. To match the rest of the function 
signatures in DWARFASTParser, remove the full name 
(lldb_private::plugin::dwarf::DWARFDIE -> DWARFDIE) in the signature of 
DWARFASTParser::GetTypeForDIE.

>From 3c6b7d07b088c50bb4efc05c9ffac484fd6d30a6 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Tue, 24 Oct 2023 09:44:19 -0700
Subject: [PATCH] [lldb][gardening] Remove full name of "DWARFDIE" type in
 GetTypeForDIE

When moving the GetTypeForDIE function from DWARFASTParserClang to
DWARFASTParser, I kept the signature as-is. To match the rest of the
function signatures in DWARFASTParser, remove the full name
(lldb_private::plugin::dwarf::DWARFDIE -> DWARFDIE) in the signature
of DWARFASTParser::GetTypeForDIE.
---
 lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index 6749cb0e5db17a6..66db396279e0630 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -64,8 +64,7 @@ class DWARFASTParser {
   ParseChildArrayInfo(const DWARFDIE &parent_die,
   const ExecutionContext *exe_ctx = nullptr);
 
-  lldb_private::Type *
-  GetTypeForDIE(const lldb_private::plugin::dwarf::DWARFDIE &die);
+  lldb_private::Type *GetTypeForDIE(const DWARFDIE &die);
 
   static lldb::AccessType GetAccessTypeFromDWARF(uint32_t dwarf_accessibility);
 

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


[Lldb-commits] [lldb] [lldb][gardening] Remove full name of "DWARFDIE" type in GetTypeForDIE (PR #70062)

2023-10-24 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [LLDB][NFC] Remove DWARFASTParserClang as friend from SymbolFileDWARF (PR #70157)

2023-10-25 Thread Augusto Noronha via lldb-commits

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


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


[Lldb-commits] [llvm] [lldb] Fix size in bytes of type DIEs when size in bits is not a multiple of 8 (PR #69741)

2023-11-09 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 updated 
https://github.com/llvm/llvm-project/pull/69741

>From b34b8f1786a6fb274710c5e4318bad83b04b0480 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Fri, 20 Oct 2023 10:18:03 -0700
Subject: [PATCH] Fix size in bytes of type DIEs when size in bits is not a
 multiple of 8

The existing code will always round down the size in bits when
calculating the size in bytes (for example, a types with 1-7 bits will
be emitted as 0 bytes long). Fix this by emitting the size in bits if
the size is not aligned to a byte.
---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 27 ++--
 llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 31 ++---
 .../AArch64/non_standard_bit_sizes.ll | 69 +++
 3 files changed, 114 insertions(+), 13 deletions(-)
 create mode 100644 llvm/test/DebugInfo/AArch64/non_standard_bit_sizes.ll

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 3174c18c97d888c..ddbec7292eb68d6 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -298,6 +298,12 @@ ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const 
DWARFDIE &die) {
   byte_size = form_value.Unsigned();
   break;
 
+case DW_AT_bit_size:
+  // Convert the bit size to byte size, and round it up to the minimum 
about
+  // of bytes that will fit the bits.
+  byte_size = (form_value.Unsigned() + 7) / 8;
+  break;
+
 case DW_AT_byte_stride:
   byte_stride = form_value.Unsigned();
   break;
@@ -2210,9 +2216,16 @@ bool DWARFASTParserClang::CompleteRecordType(const 
DWARFDIE &die,
   !layout_info.vbase_offsets.empty()) {
 if (type)
   layout_info.bit_size = type->GetByteSize(nullptr).value_or(0) * 8;
-if (layout_info.bit_size == 0)
-  layout_info.bit_size =
-  die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
+if (layout_info.bit_size == 0) {
+  auto byte_size =
+  die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
+
+  if (byte_size != UINT64_MAX)
+layout_info.bit_size = byte_size;
+  else
+layout_info.bit_size =
+die.GetAttributeValueAsUnsigned(DW_AT_bit_size, 0);
+}
 
 clang::CXXRecordDecl *record_decl =
 m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
@@ -2866,8 +2879,12 @@ void DWARFASTParserClang::ParseSingleMember(
   // Get the parent byte size so we can verify any members will fit
   const uint64_t parent_byte_size =
   parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
-  const uint64_t parent_bit_size =
-  parent_byte_size == UINT64_MAX ? UINT64_MAX : parent_byte_size * 8;
+  uint64_t parent_bit_size;
+  if (parent_byte_size != UINT64_MAX)
+parent_bit_size = parent_byte_size * 8;
+  else
+parent_bit_size =
+parent_die.GetAttributeValueAsUnsigned(DW_AT_bit_size, UINT64_MAX);
 
   // FIXME: Remove the workarounds below and make this const.
   MemberAttributes attrs(die, parent_die, module_sp);
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp 
b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index a5960a5d4a09a17..aab1dc218973365 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -687,6 +687,17 @@ std::string DwarfUnit::getParentContextString(const 
DIScope *Context) const {
   return CS;
 }
 
+/// Returns the most appropriate dwarf size attribute (bits or bytes) and size
+/// to be used with it, given the input size in bits.
+static std::pair
+getMostAppropriateRepresentationAndSize(uint64_t SizeInBits) {
+  if (SizeInBits % 8 == 0) {
+return {dwarf::DW_AT_byte_size, SizeInBits / 8};
+  }
+  return {dwarf::DW_AT_bit_size, SizeInBits};
+}
+
+
 void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIBasicType *BTy) {
   // Get core information.
   StringRef Name = BTy->getName();
@@ -702,8 +713,9 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const 
DIBasicType *BTy) {
 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
 BTy->getEncoding());
 
-  uint64_t Size = BTy->getSizeInBits() >> 3;
-  addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
+  auto [SizeAttribute, Size] =
+  getMostAppropriateRepresentationAndSize(BTy->getSizeInBits());
+  addUInt(Buffer, SizeAttribute, std::nullopt, Size);
 
   if (BTy->isBigEndian())
 addUInt(Buffer, dwarf::DW_AT_endianity, std::nullopt, dwarf::DW_END_big);
@@ -731,8 +743,9 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const 
DIStringType *STy) {
 DwarfExpr.addExpression(Expr);
 addBlock(Buffer, dwarf::DW_AT_string_length, DwarfExpr.finalize());
   } else {
-uint64_t Size = STy->getSizeInBits() >> 3;
-addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
+auto [SizeAttributte, Size] =
+getMostAppropriateRepresentationAnd

[Lldb-commits] [llvm] [lldb] Fix size in bytes of type DIEs when size in bits is not a multiple of 8 (PR #69741)

2023-11-09 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [llvm] [lldb] Fix size in bytes of type DIEs when size in bits is not a multiple of 8 (PR #69741)

2023-11-09 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

@dwblaikie I talked with Adrian, his idea is to emit the size in bits whenever 
it does not cleanly fit in a byte. His point (and I agree) is that there may be 
tools that can use this bit size, and if we always round up when emitting the 
DWARF we will lose this information, with no way to recover it. I updated the 
patch to implement this behavior.

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


[Lldb-commits] [llvm] [lldb] Fix size in bytes of type DIEs when size in bits is not a multiple of 8 (PR #69741)

2023-11-10 Thread Augusto Noronha via lldb-commits


@@ -2210,9 +2216,16 @@ bool DWARFASTParserClang::CompleteRecordType(const 
DWARFDIE &die,
   !layout_info.vbase_offsets.empty()) {
 if (type)
   layout_info.bit_size = type->GetByteSize(nullptr).value_or(0) * 8;
-if (layout_info.bit_size == 0)
-  layout_info.bit_size =
-  die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
+if (layout_info.bit_size == 0) {
+  auto byte_size =
+  die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
+
+  if (byte_size != UINT64_MAX)
+layout_info.bit_size = byte_size;

augusto2112 wrote:

Thanks for catching this.

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


[Lldb-commits] [llvm] [lldb] Fix size in bytes of type DIEs when size in bits is not a multiple of 8 (PR #69741)

2023-11-10 Thread Augusto Noronha via lldb-commits


@@ -2866,8 +2879,12 @@ void DWARFASTParserClang::ParseSingleMember(
   // Get the parent byte size so we can verify any members will fit
   const uint64_t parent_byte_size =
   parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
-  const uint64_t parent_bit_size =
-  parent_byte_size == UINT64_MAX ? UINT64_MAX : parent_byte_size * 8;
+  uint64_t parent_bit_size;
+  if (parent_byte_size != UINT64_MAX)
+parent_bit_size = parent_byte_size * 8;
+  else
+parent_bit_size =
+parent_die.GetAttributeValueAsUnsigned(DW_AT_bit_size, UINT64_MAX);

augusto2112 wrote:

Hmm, I'll definitely have a downstream test that exercises this behavior, but I 
don't think on the clang side this would be easy to test, do you have any 
suggestions on how to do that?

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


[Lldb-commits] [llvm] [lldb] Fix size in bytes of type DIEs when size in bits is not a multiple of 8 (PR #69741)

2023-11-10 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 updated 
https://github.com/llvm/llvm-project/pull/69741

>From 997da625fda1efebde43ec965c23c1a8ef9c0132 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Fri, 10 Nov 2023 10:40:05 -0800
Subject: [PATCH] Emit DIE's size in bits when size is not a multiple of 8

The existing code will always round down the size in bits when
calculating the size in bytes (for example, a types with 1-7 bits will
be emitted as 0 bytes long). Fix this by emitting the size in bits if
the size is not aligned to a byte.
---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 25 +--
 llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 30 +---
 .../AArch64/non_standard_bit_sizes.ll | 69 +++
 3 files changed, 110 insertions(+), 14 deletions(-)
 create mode 100644 llvm/test/DebugInfo/AArch64/non_standard_bit_sizes.ll

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 3174c18c97d888c..928033ea48e890c 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -298,6 +298,12 @@ ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const 
DWARFDIE &die) {
   byte_size = form_value.Unsigned();
   break;
 
+case DW_AT_bit_size:
+  // Convert the bit size to byte size, and round it up to the minimum
+  // amount of bytes that will fit the bits.
+  byte_size = (form_value.Unsigned() + 7) / 8;
+  break;
+
 case DW_AT_byte_stride:
   byte_stride = form_value.Unsigned();
   break;
@@ -2134,6 +2140,16 @@ bool DWARFASTParserClang::ParseTemplateParameterInfos(
  template_param_infos.hasParameterPack();
 }
 
+/// Reads the bit size from a die, by trying both the byte size and bit size
+/// attributes.
+static uint64_t GetSizeInBitsFromDie(const DWARFDIE &die) {
+  const uint64_t byte_size =
+  die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
+  if (byte_size != UINT64_MAX)
+return byte_size * 8;
+  return die.GetAttributeValueAsUnsigned(DW_AT_bit_size, UINT64_MAX);
+}
+
 bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die,
  lldb_private::Type *type,
  CompilerType &clang_type) {
@@ -2211,8 +2227,7 @@ bool DWARFASTParserClang::CompleteRecordType(const 
DWARFDIE &die,
 if (type)
   layout_info.bit_size = type->GetByteSize(nullptr).value_or(0) * 8;
 if (layout_info.bit_size == 0)
-  layout_info.bit_size =
-  die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
+  layout_info.bit_size = GetSizeInBitsFromDie(die);
 
 clang::CXXRecordDecl *record_decl =
 m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
@@ -2864,10 +2879,8 @@ void DWARFASTParserClang::ParseSingleMember(
   ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
   const dw_tag_t tag = die.Tag();
   // Get the parent byte size so we can verify any members will fit
-  const uint64_t parent_byte_size =
-  parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
-  const uint64_t parent_bit_size =
-  parent_byte_size == UINT64_MAX ? UINT64_MAX : parent_byte_size * 8;
+  uint64_t parent_bit_size = GetSizeInBitsFromDie(parent_die);
+  ;
 
   // FIXME: Remove the workarounds below and make this const.
   MemberAttributes attrs(die, parent_die, module_sp);
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp 
b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index a5960a5d4a09a17..9633e3b19ec0d63 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -687,6 +687,16 @@ std::string DwarfUnit::getParentContextString(const 
DIScope *Context) const {
   return CS;
 }
 
+/// Returns the most appropriate dwarf size attribute (bits or bytes) and size
+/// to be used with it, given the input size in bits.
+static std::pair
+getMostAppropriateRepresentationAndSize(uint64_t SizeInBits) {
+  if (SizeInBits % 8 == 0) {
+return {dwarf::DW_AT_byte_size, SizeInBits / 8};
+  }
+  return {dwarf::DW_AT_bit_size, SizeInBits};
+}
+
 void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIBasicType *BTy) {
   // Get core information.
   StringRef Name = BTy->getName();
@@ -702,8 +712,9 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const 
DIBasicType *BTy) {
 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
 BTy->getEncoding());
 
-  uint64_t Size = BTy->getSizeInBits() >> 3;
-  addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
+  auto [SizeAttribute, Size] =
+  getMostAppropriateRepresentationAndSize(BTy->getSizeInBits());
+  addUInt(Buffer, SizeAttribute, std::nullopt, Size);
 
   if (BTy->isBigEndian())
 addUInt(Buffer, dwarf::DW_AT_endianity, std::nullopt, dwarf::DW_END_big);
@@ -731,8 +742,9 @@ void DwarfUnit::constructTypeDIE

[Lldb-commits] [llvm] [lldb] Emit DIE's size in bits when size is not a multiple of 8 (PR #69741)

2023-11-10 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] [llvm] Emit DIE's size in bits when size is not a multiple of 8 (PR #69741)

2023-11-14 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

> I guess one question that might be relevant - does Swift have something like 
> sizeof and what result does it give for these sort of types with bits to 
> spare?

You can't actually use that with these types as these are special compiler 
builtin types which aren't actually accessible in source code.

> But like I said - it seems like structs with tail padding are similar to this 
> situation - we still describe the whole size of the struct, because that's 
> used for creating arrays of instances, ABI passing, etc. But the tail padding 
> can still be used, in certain circumstances, when laying out a derived class. 
> We encode this as the POD-ness of the type, and so if you wanted to create a 
> class that derived from one described in DWARF you could do so & would know 
> whether or not to put the derived class's members into the tail padding of 
> the base or not.

I understand the rationale of basing this on precedent, but in this case in 
this case we should break from it for two reasons:

- DW_AT_BIT_SIZE is already a standardized attribute in Dwarf that fits this 
use case.
- Round up to the nearest byte would lose information, which can be kept with 
fairly minimal downsides in my opinion.

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


[Lldb-commits] [lldb] [lldb] Add interface to check if UserExpression::Parse() is cacheable (PR #66826)

2023-11-16 Thread Augusto Noronha via lldb-commits

augusto2112 wrote:

@DavidSpickett thanks for reminding me. I'll add a comment describing the 
situation. 

Right now, for conditional breakpoints, we assume that the condition expression 
is cacheable, since it's being run over and over again in the exact same 
context. This works for C/C++, but not for Swift, because Swift generics aren't 
monomorphized (the same problem would happen for other languages where generics 
aren't monomorphized either, so a more general escape hatch seemed appropriate 
to me).

To illustrate what I mean, a function such as  the following (in C++ syntax but 
Swift semantics):

```
template 
void use(T t) {}

// In main
use(5);
use(std::string())
```

Is lowered only once as a truly generic function (unlike C++ which will 
generate one version per instantiation), so it isn't safe to cache the 
expression parse, as the argument type may be different in every invocation.

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


[Lldb-commits] [lldb] [lldb] Add interface to check if UserExpression::Parse() is cacheable (PR #66826)

2023-11-16 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 updated 
https://github.com/llvm/llvm-project/pull/66826

>From fcc27c3b81a8f2c0566af801e623d23f748fb04a Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Tue, 19 Sep 2023 13:27:41 -0700
Subject: [PATCH] [lldb] Add interface to check if UserExpression::Parse() is
 cacheable

When setting conditional breakpoints, we currently assume that a call to
UserExpression::Parse() can be cached and resued multiple times. This
may not be true for every user expression. Add a new method so
subclasses of UserExpression can customize if they are parseable or not.
---
 lldb/include/lldb/Expression/UserExpression.h | 8 
 lldb/source/Breakpoint/BreakpointLocation.cpp | 1 +
 2 files changed, 9 insertions(+)

diff --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index df7a76664f6d5b6..b6cfeec7e899330 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -192,6 +192,14 @@ class UserExpression : public Expression {
   /// expression.  Text() should contain the definition of this function.
   const char *FunctionName() override { return "$__lldb_expr"; }
 
+  /// Returns whether the call to Parse on this user expression is cacheable.
+  /// This function exists to provide an escape hatch for supporting languages
+  /// where parsing an expression in the exact same context is unsafe. For
+  /// example, languages where generic functions aren't monomorphized, but
+  /// implement some other mechanism to represent generic values, may be unsafe
+  /// to cache, as the concrete type substitution may be different in every
+  /// expression evaluation.
+  virtual bool IsParseCacheable() { return true; }
   /// Return the language that should be used when parsing.  To use the
   /// default, return eLanguageTypeUnknown.
   lldb::LanguageType Language() const override { return m_language; }
diff --git a/lldb/source/Breakpoint/BreakpointLocation.cpp 
b/lldb/source/Breakpoint/BreakpointLocation.cpp
index 0fcefe5c63be749..2d2e00883f32ef7 100644
--- a/lldb/source/Breakpoint/BreakpointLocation.cpp
+++ b/lldb/source/Breakpoint/BreakpointLocation.cpp
@@ -250,6 +250,7 @@ bool BreakpointLocation::ConditionSaysStop(ExecutionContext 
&exe_ctx,
   DiagnosticManager diagnostics;
 
   if (condition_hash != m_condition_hash || !m_user_expression_sp ||
+  !m_user_expression_sp->IsParseCacheable() ||
   !m_user_expression_sp->MatchesContext(exe_ctx)) {
 LanguageType language = eLanguageTypeUnknown;
 // See if we can figure out the language from the frame, otherwise use the

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


[Lldb-commits] [lldb] [lldb] Add interface to check if UserExpression::Parse() is cacheable (PR #66826)

2023-11-16 Thread Augusto Noronha via lldb-commits

https://github.com/augusto2112 updated 
https://github.com/llvm/llvm-project/pull/66826

>From 5323ac957268e469207aae340e15f6809b53bf53 Mon Sep 17 00:00:00 2001
From: Augusto Noronha 
Date: Thu, 16 Nov 2023 11:31:55 -0800
Subject: [PATCH] [lldb] Add interface to check if UserExpression::Parse() is
 cacheable

When setting conditional breakpoints, we currently assume that a call to
UserExpression::Parse() can be cached and resued multiple times. This
may not be true for every user expression. Add a new method so
subclasses of UserExpression can customize if they are parseable or not.
---
 lldb/include/lldb/Expression/UserExpression.h | 8 
 lldb/source/Breakpoint/BreakpointLocation.cpp | 1 +
 2 files changed, 9 insertions(+)

diff --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index df7a76664f6d5b6..b6cfeec7e899330 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -192,6 +192,14 @@ class UserExpression : public Expression {
   /// expression.  Text() should contain the definition of this function.
   const char *FunctionName() override { return "$__lldb_expr"; }
 
+  /// Returns whether the call to Parse on this user expression is cacheable.
+  /// This function exists to provide an escape hatch for supporting languages
+  /// where parsing an expression in the exact same context is unsafe. For
+  /// example, languages where generic functions aren't monomorphized, but
+  /// implement some other mechanism to represent generic values, may be unsafe
+  /// to cache, as the concrete type substitution may be different in every
+  /// expression evaluation.
+  virtual bool IsParseCacheable() { return true; }
   /// Return the language that should be used when parsing.  To use the
   /// default, return eLanguageTypeUnknown.
   lldb::LanguageType Language() const override { return m_language; }
diff --git a/lldb/source/Breakpoint/BreakpointLocation.cpp 
b/lldb/source/Breakpoint/BreakpointLocation.cpp
index 27dc7458dc26f70..931e1ad4b2d9339 100644
--- a/lldb/source/Breakpoint/BreakpointLocation.cpp
+++ b/lldb/source/Breakpoint/BreakpointLocation.cpp
@@ -250,6 +250,7 @@ bool BreakpointLocation::ConditionSaysStop(ExecutionContext 
&exe_ctx,
   DiagnosticManager diagnostics;
 
   if (condition_hash != m_condition_hash || !m_user_expression_sp ||
+  !m_user_expression_sp->IsParseCacheable() ||
   !m_user_expression_sp->MatchesContext(exe_ctx)) {
 LanguageType language = eLanguageTypeUnknown;
 // See if we can figure out the language from the frame, otherwise use the

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


[Lldb-commits] [lldb] [lldb] Add interface to check if UserExpression::Parse() is cacheable (PR #66826)

2023-11-16 Thread Augusto Noronha via lldb-commits

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


[Lldb-commits] [lldb] 6f2423c - [lldb] Allow SymbolFileDWARFDebugMap to register multiple compile units

2022-10-19 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-10-19T13:49:40-07:00
New Revision: 6f2423c6fe97bec77da66d87a7a997917f6b489e

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

LOG: [lldb] Allow SymbolFileDWARFDebugMap to register multiple compile units

Currently, SymbolFileDWARFDebugMap works on the assumption that there is
only one compile unit per object file. This patch documents this
limitation (when using the general SymbolFile API), and allows users of
the concrete SymbolFileDWARFDebugMap class to find out about these extra
compile units.

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

Added: 
lldb/test/API/lang/c/full_lto_stepping/Makefile
lldb/test/API/lang/c/full_lto_stepping/TestFullLtoStepping.py
lldb/test/API/lang/c/full_lto_stepping/foo.c
lldb/test/API/lang/c/full_lto_stepping/foo.h
lldb/test/API/lang/c/full_lto_stepping/main.c

Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
index 9ca160b474fc9..ced03752aadc2 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
@@ -53,28 +53,21 @@ void DWARFCompileUnit::BuildAddressRangeTable(
   }
 
   if (debug_aranges->GetNumRanges() == num_debug_aranges) {
-// We got nothing from the debug info, maybe we have a line tables only
-// situation. Check the line tables and build the arange table from this.
+// We got nothing from the debug info, try to build the arange table from
+// the debug map OSO aranges.
 SymbolContext sc;
 sc.comp_unit = m_dwarf.GetCompUnitForDWARFCompUnit(*this);
 if (sc.comp_unit) {
   SymbolFileDWARFDebugMap *debug_map_sym_file =
   m_dwarf.GetDebugMapSymfile();
-  if (debug_map_sym_file == nullptr) {
-if (LineTable *line_table = sc.comp_unit->GetLineTable()) {
-  LineTable::FileAddressRanges file_ranges;
-  const bool append = true;
-  const size_t num_ranges =
-  line_table->GetContiguousFileAddressRanges(file_ranges, append);
-  for (uint32_t idx = 0; idx < num_ranges; ++idx) {
-const LineTable::FileAddressRanges::Entry &range =
-file_ranges.GetEntryRef(idx);
-debug_aranges->AppendRange(cu_offset, range.GetRangeBase(),
-   range.GetRangeEnd());
-  }
-}
-  } else
-debug_map_sym_file->AddOSOARanges(&m_dwarf, debug_aranges);
+  if (debug_map_sym_file) {
+auto *cu_info =
+debug_map_sym_file->GetCompileUnitInfo(&GetSymbolFileDWARF());
+// If there are extra compile units the OSO entries aren't a reliable
+// source of information.
+if (cu_info->compile_units_sps.empty())
+  debug_map_sym_file->AddOSOARanges(&m_dwarf, debug_aranges);
+  }
 }
   }
 

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index d029e4da86175..42a0302351dd6 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -702,9 +702,9 @@ lldb::CompUnitSP 
SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) {
 // We already parsed this compile unit, had out a shared pointer to it
 cu_sp = comp_unit->shared_from_this();
   } else {
-if (dwarf_cu.GetOffset() == 0 && GetDebugMapSymfile()) {
+if (GetDebugMapSymfile()) {
   // Let the debug map create the compile unit
-  cu_sp = m_debug_map_symfile->GetCompileUnit(this);
+  cu_sp = m_debug_map_symfile->GetCompileUnit(this, dwarf_cu);
   dwarf_cu.SetUserData(cu_sp.get());
 } else {
   ModuleSP module_sp(m_objfile_sp->GetModule());

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
index 97140704ad33e..015633727f18d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -7,7 +7,9 @@
 
//===--===//
 
 #include "SymbolFileDWARFDebugMap.h"
+#include "DWARFCompileUnit.h"
 #include "DWARFDebugAranges.h"
+#include "DWARFDebugInfo.h"
 
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
@@ -17,6 +19,7 @@
 #include "lld

[Lldb-commits] [lldb] 7590776 - [lldb] Skip TestFullLtoStepping in older clangs

2022-10-24 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-10-24T12:12:36-07:00
New Revision: 7590776b852f28ba8d569e17d989060f33d0e7a3

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

LOG: [lldb] Skip TestFullLtoStepping in older clangs

Added: 


Modified: 
lldb/test/API/lang/c/full_lto_stepping/TestFullLtoStepping.py

Removed: 




diff  --git a/lldb/test/API/lang/c/full_lto_stepping/TestFullLtoStepping.py 
b/lldb/test/API/lang/c/full_lto_stepping/TestFullLtoStepping.py
index e697a53103b31..9a553e8afff6e 100644
--- a/lldb/test/API/lang/c/full_lto_stepping/TestFullLtoStepping.py
+++ b/lldb/test/API/lang/c/full_lto_stepping/TestFullLtoStepping.py
@@ -9,6 +9,7 @@
 class TestFullLtoStepping(TestBase):
 
 @skipIf(compiler=no_match("clang"))
+@skipIf(compiler="clang", compiler_version=['<', '13.0'])
 @skipUnlessDarwin
 def test(self):
 self.build()



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


[Lldb-commits] [lldb] b3b517d - [lldb] Explicitly open file to write with utf-8 encoding in crashlog.py

2022-10-28 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-10-28T15:04:24-07:00
New Revision: b3b517d572391d9799d1f29bddd66e2bad1acb54

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

LOG: [lldb] Explicitly open file to write with utf-8 encoding in crashlog.py

The python "open" function will use the default encoding for the
locale (the result of "locale.getpreferredencoding()"). Explicitly set
the locale to utf-8 when opening the crashlog for writing, as there may
be non-ascii symbols in there (for example, Swift uses "τ" to indicate
generic parameters).

rdar://101402755

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

Added: 


Modified: 
lldb/examples/python/crashlog.py

Removed: 




diff  --git a/lldb/examples/python/crashlog.py 
b/lldb/examples/python/crashlog.py
index eb43e07d27f4..e80ecd91579a 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -449,7 +449,7 @@ def parse_json(buffer):
 head, _, tail = buffer.partition('\n')
 return json.loads(tail)
 
-with open(path, 'r') as f:
+with open(path, 'r', encoding='utf-8') as f:
 buffer = f.read()
 try:
 return parse_json(buffer)
@@ -644,7 +644,7 @@ def __init__(self, debugger, path, verbose):
 }
 
 def parse(self):
-with open(self.path,'r') as f:
+with open(self.path,'r', encoding='utf-8') as f:
 lines = f.read().splitlines()
 
 for line in lines:
@@ -865,7 +865,7 @@ def save_crashlog(debugger, command, exe_ctx, result, dict):
 result.PutCString(
 "error: invalid arguments, a single output file is the only valid 
argument")
 return
-out_file = open(args[0], 'w')
+out_file = open(args[0], 'w', encoding='utf-8')
 if not out_file:
 result.PutCString(
 "error: failed to open file '%s' for writing...",



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


  1   2   >