[Lldb-commits] [lldb] Add 'FindFirstSymbolWithNameAndType()' to ModuleList. (PR #117777)

2024-11-28 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

> > I'm only using it in an internal branch
> 
> 
> 
> Not sure what the protocol is for this (CC @JDevlieghere @labath). At the 
> very least we should have some coverage for it in the test-suite. There's 
> precedent for this, e.g., APIs that only get exercised on the Swift branch, 
> but at least those are on a public fork and tested on public build-bots.

+1, give that the SBAPI needs to remain stable we try to avoid hoisting APIs 
from (downstream) forks unless there's a use for them upstream.

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


[Lldb-commits] [lldb] [lldb] Include `` for `system_clock` (PR #118059)

2024-11-28 Thread via lldb-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[Lldb-commits] [lldb] [lldb] Include `` for `system_clock` (PR #118059)

2024-11-28 Thread Lily Wang via lldb-commits

https://github.com/LilyWangLL created 
https://github.com/llvm/llvm-project/pull/118059

I am a member of Microsoft vcpkg, due to there are new changes merged by 
microsoft/STL#5105, which revealed a conformance issue in `llvm`. It must add 
include `` to fix this error.

Compiler error with this STL change:
```
D:\b\llvm\src\org-18.1.6-e754cb1d0b.clean\lldb\tools\lldb-dap\ProgressEvent.h(79):
 error C2039: 'system_clock': is not a member of 'std::chrono'
D:\b\llvm\src\org-18.1.6-e754cb1d0b.clean\lldb\tools\lldb-dap\ProgressEvent.cpp(134):
 error C2039: 'now': is not a member of 'std::chrono'
```


>From ba57c78dbc302cc877cc9e2a0d3e91f77e73920c Mon Sep 17 00:00:00 2001
From: LilyWangLL <494550...@qq.com>
Date: Thu, 28 Nov 2024 23:31:32 -0800
Subject: [PATCH] Include `` for `system_clock`

---
 lldb/tools/lldb-dap/ProgressEvent.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/tools/lldb-dap/ProgressEvent.h 
b/lldb/tools/lldb-dap/ProgressEvent.h
index dac21977add2d0..72317b879c803a 100644
--- a/lldb/tools/lldb-dap/ProgressEvent.h
+++ b/lldb/tools/lldb-dap/ProgressEvent.h
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include 
+#include 
 #include 
 #include 
 #include 

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


[Lldb-commits] [lldb] [lldb] Include `` for `system_clock` (PR #118059)

2024-11-28 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Lily Wang (LilyWangLL)


Changes

I am a member of Microsoft vcpkg, due to there are new changes merged by 
microsoft/STL#5105, which revealed a conformance issue in `llvm`. It 
must add include `` to fix this error.

Compiler error with this STL change:
```
D:\b\llvm\src\org-18.1.6-e754cb1d0b.clean\lldb\tools\lldb-dap\ProgressEvent.h(79):
 error C2039: 'system_clock': is not a member of 'std::chrono'
D:\b\llvm\src\org-18.1.6-e754cb1d0b.clean\lldb\tools\lldb-dap\ProgressEvent.cpp(134):
 error C2039: 'now': is not a member of 'std::chrono'
```


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


1 Files Affected:

- (modified) lldb/tools/lldb-dap/ProgressEvent.h (+1) 


``diff
diff --git a/lldb/tools/lldb-dap/ProgressEvent.h 
b/lldb/tools/lldb-dap/ProgressEvent.h
index dac21977add2d0..72317b879c803a 100644
--- a/lldb/tools/lldb-dap/ProgressEvent.h
+++ b/lldb/tools/lldb-dap/ProgressEvent.h
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include 
+#include 
 #include 
 #include 
 #include 

``




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


[Lldb-commits] [lldb] [lldb][Docs] Add Guarded Control Stack to AArch64 Linux page (PR #117860)

2024-11-28 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Will keep this in review until the code changes land. I might not reflect 
reality if changes are made along the way.

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


[Lldb-commits] [lldb] [LLDB] Fix crash in TypeSystemClang::GetIndexofChildMemberWithName. (PR #117808)

2024-11-28 Thread Michael Buch via lldb-commits

Michael137 wrote:

> Here's the test case I used: $ cat main.cpp struct A { struct { int x = 1; }; 
> int y = 2;6 } a;
> 
> struct B { // Anonymous struct inherits another struct. struct : public A { 
> int z = 3; }; int w = 4; A a; } b;
> 
> return 0; // Set a breakpoint here } $ clang++ -g -O0 main.cpp $ lldb a.out
> 
> Break at 'main' and step to the return statement. Then (lldb) frame var b.x 
> LLDB crashes, trying to pop the empty vector.

Thanks! Agree with Pavel, lets turn this into a test-case as part of this PR.

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


[Lldb-commits] [lldb] [LLDB] Fix crash in TypeSystemClang::GetIndexofChildMemberWithName. (PR #117808)

2024-11-28 Thread Michael Buch via lldb-commits


@@ -6754,12 +6754,12 @@ size_t TypeSystemClang::GetIndexOfChildMemberWithName(
   llvm::StringRef field_name = field->getName();
   if (field_name.empty()) {
 CompilerType field_type = GetType(field->getType());
+std::vector save_indices = child_indexes;

Michael137 wrote:

An alternative to this would be *not* clearing the vector inside of 
`TypeSystemClang::GetIndexForRecordChild` on failure. And instead it could 
return an `llvm::Expected`. So then `GetIndexOfChildMemberWithName` 
can bail out on failure. That feels easier to reason about. Wdyt?

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


[Lldb-commits] [lldb] [LLDB] Fix crash in TypeSystemClang::GetIndexofChildMemberWithName. (PR #117808)

2024-11-28 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [LLDB] Fix crash in TypeSystemClang::GetIndexofChildMemberWithName. (PR #117808)

2024-11-28 Thread Michael Buch via lldb-commits


@@ -6754,12 +6754,12 @@ size_t TypeSystemClang::GetIndexOfChildMemberWithName(
   llvm::StringRef field_name = field->getName();
   if (field_name.empty()) {
 CompilerType field_type = GetType(field->getType());
+std::vector save_indices = child_indexes;

Michael137 wrote:

Hmm nevermind. IIUC the reason it's clearing the indices is that it is trying 
to backtrack if we failed to find the member after searching through a certain 
path.

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


[Lldb-commits] [lldb] [lldb] Use the function block as a source for function ranges (PR #117996)

2024-11-28 Thread Pavel Labath via lldb-commits

https://github.com/labath created 
https://github.com/llvm/llvm-project/pull/117996

This is a follow-up/reimplementation of #115730. While working on that patch, I 
did not realize that the correct (discontinuous) set of ranges is already 
stored in the block representing the whole function. The catch -- ranges for 
this block are only set later, when parsing all of the blocks of the function.

This patch changes that by populating the function block ranges eagerly -- from 
within the Function constructor. This also necessitates a corresponding change 
in all of the symbol files -- so that they stop populating the ranges of that 
block. This allows us to avoid some unnecessary work (not parsing the function 
DW_AT_ranges twice) and also results in some simplification of the parsing code.

>From 78b8dabf1ada3d567d3f1a193fdf0cc0f159cb37 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Wed, 27 Nov 2024 17:05:23 +0100
Subject: [PATCH] [lldb] Use the function block as a source for function ranges

This is a follow-up/reimplementation of #115730. While working on that
patch, I did not realize that the correct (discontinuous) set of ranges
is already stored in the block representing the whole function. The
catch -- ranges for this block are only set later, when parsing all of
the blocks of the function.

This patch changes that by populating the function block ranges eagerly
-- from within the Function constructor. This also necessitates a
corresponding change in all of the symbol files -- so that they stop
populating the ranges of that block. This allows us to avoid some
unnecessary work (not parsing the function DW_AT_ranges twice) and also
results in some simplification of the parsing code.
---
 lldb/include/lldb/Symbol/Function.h   |   3 -
 .../Breakpad/SymbolFileBreakpad.cpp   |   4 +-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  | 180 +++---
 .../SymbolFile/DWARF/SymbolFileDWARF.h|   3 +-
 .../NativePDB/SymbolFileNativePDB.cpp |  12 +-
 .../Plugins/SymbolFile/PDB/SymbolFilePDB.cpp  |  53 ++
 lldb/source/Symbol/Function.cpp   |  16 +-
 .../DWARF/x86/discontinuous-function.s|   2 +-
 .../SymbolFile/PDB/function-nested-block.test |   1 -
 9 files changed, 111 insertions(+), 163 deletions(-)

diff --git a/lldb/include/lldb/Symbol/Function.h 
b/lldb/include/lldb/Symbol/Function.h
index 70f51a846f8d96..e71dc2348b1734 100644
--- a/lldb/include/lldb/Symbol/Function.h
+++ b/lldb/include/lldb/Symbol/Function.h
@@ -650,9 +650,6 @@ class Function : public UserID, public SymbolContextScope {
   /// All lexical blocks contained in this function.
   Block m_block;
 
-  /// List of address ranges belonging to the function.
-  AddressRanges m_ranges;
-
   /// The function address range that covers the widest range needed to contain
   /// all blocks. DEPRECATED: do not use this field in new code as the range 
may
   /// include addresses belonging to other functions.
diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp 
b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
index df3bf157278daf..bc886259d6fa5f 100644
--- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
+++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
@@ -299,9 +299,7 @@ size_t SymbolFileBreakpad::ParseBlocksRecursive(Function 
&func) {
   // "INLINE 0 ...", the current level is 0 and its parent block is the
   // function block at index 0.
   std::vector blocks;
-  Block &block = func.GetBlock(false);
-  block.AddRange(Block::Range(0, func.GetAddressRange().GetByteSize()));
-  blocks.push_back(&block);
+  blocks.push_back(&func.GetBlock(false));
 
   size_t blocks_added = 0;
   addr_t func_base = func.GetAddressRange().GetBaseAddress().GetOffset();
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index fe711c56958c44..d814b635f2e5cd 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1305,121 +1305,76 @@ bool SymbolFileDWARF::ParseDebugMacros(CompileUnit 
&comp_unit) {
   return true;
 }
 
-size_t SymbolFileDWARF::ParseBlocksRecursive(
-lldb_private::CompileUnit &comp_unit, Block *parent_block,
-const DWARFDIE &orig_die, addr_t subprogram_low_pc, uint32_t depth) {
+size_t SymbolFileDWARF::ParseBlocksRecursive(CompileUnit &comp_unit,
+ Block *parent_block, DWARFDIE die,
+ addr_t subprogram_low_pc) {
   size_t blocks_added = 0;
-  DWARFDIE die = orig_die;
-  while (die) {
+  for (; die; die = die.GetSibling()) {
 dw_tag_t tag = die.Tag();
 
-switch (tag) {
-case DW_TAG_inlined_subroutine:
-case DW_TAG_subprogram:
-case DW_TAG_lexical_block: {
-  Block *block = nullptr;
-  if (tag == DW_TAG_subprogram) {
-// Skip any DW_TAG_sub

[Lldb-commits] [lldb] [lldb] Use the function block as a source for function ranges (PR #117996)

2024-11-28 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

This is a follow-up/reimplementation of #115730. While working on that 
patch, I did not realize that the correct (discontinuous) set of ranges is 
already stored in the block representing the whole function. The catch -- 
ranges for this block are only set later, when parsing all of the blocks of the 
function.

This patch changes that by populating the function block ranges eagerly -- from 
within the Function constructor. This also necessitates a corresponding change 
in all of the symbol files -- so that they stop populating the ranges of that 
block. This allows us to avoid some unnecessary work (not parsing the function 
DW_AT_ranges twice) and also results in some simplification of the parsing code.

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


9 Files Affected:

- (modified) lldb/include/lldb/Symbol/Function.h (-3) 
- (modified) lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp 
(+1-3) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+72-108) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (+1-2) 
- (modified) lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp 
(+3-9) 
- (modified) lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp (+21-32) 
- (modified) lldb/source/Symbol/Function.cpp (+12-4) 
- (modified) lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s 
(+1-1) 
- (modified) lldb/test/Shell/SymbolFile/PDB/function-nested-block.test (-1) 


``diff
diff --git a/lldb/include/lldb/Symbol/Function.h 
b/lldb/include/lldb/Symbol/Function.h
index 70f51a846f8d96..e71dc2348b1734 100644
--- a/lldb/include/lldb/Symbol/Function.h
+++ b/lldb/include/lldb/Symbol/Function.h
@@ -650,9 +650,6 @@ class Function : public UserID, public SymbolContextScope {
   /// All lexical blocks contained in this function.
   Block m_block;
 
-  /// List of address ranges belonging to the function.
-  AddressRanges m_ranges;
-
   /// The function address range that covers the widest range needed to contain
   /// all blocks. DEPRECATED: do not use this field in new code as the range 
may
   /// include addresses belonging to other functions.
diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp 
b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
index df3bf157278daf..bc886259d6fa5f 100644
--- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
+++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
@@ -299,9 +299,7 @@ size_t SymbolFileBreakpad::ParseBlocksRecursive(Function 
&func) {
   // "INLINE 0 ...", the current level is 0 and its parent block is the
   // function block at index 0.
   std::vector blocks;
-  Block &block = func.GetBlock(false);
-  block.AddRange(Block::Range(0, func.GetAddressRange().GetByteSize()));
-  blocks.push_back(&block);
+  blocks.push_back(&func.GetBlock(false));
 
   size_t blocks_added = 0;
   addr_t func_base = func.GetAddressRange().GetBaseAddress().GetOffset();
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index fe711c56958c44..d814b635f2e5cd 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1305,121 +1305,76 @@ bool SymbolFileDWARF::ParseDebugMacros(CompileUnit 
&comp_unit) {
   return true;
 }
 
-size_t SymbolFileDWARF::ParseBlocksRecursive(
-lldb_private::CompileUnit &comp_unit, Block *parent_block,
-const DWARFDIE &orig_die, addr_t subprogram_low_pc, uint32_t depth) {
+size_t SymbolFileDWARF::ParseBlocksRecursive(CompileUnit &comp_unit,
+ Block *parent_block, DWARFDIE die,
+ addr_t subprogram_low_pc) {
   size_t blocks_added = 0;
-  DWARFDIE die = orig_die;
-  while (die) {
+  for (; die; die = die.GetSibling()) {
 dw_tag_t tag = die.Tag();
 
-switch (tag) {
-case DW_TAG_inlined_subroutine:
-case DW_TAG_subprogram:
-case DW_TAG_lexical_block: {
-  Block *block = nullptr;
-  if (tag == DW_TAG_subprogram) {
-// Skip any DW_TAG_subprogram DIEs that are inside of a normal or
-// inlined functions. These will be parsed on their own as separate
-// entities.
-
-if (depth > 0)
-  break;
+if (tag != DW_TAG_inlined_subroutine && tag != DW_TAG_lexical_block)
+  continue;
 
-block = parent_block;
-  } else {
-block = parent_block->CreateChild(die.GetID()).get();
-  }
-  DWARFRangeList ranges;
-  const char *name = nullptr;
-  const char *mangled_name = nullptr;
-
-  std::optional decl_file;
-  std::optional decl_line;
-  std::optional decl_column;
-  std::optional call_file;
-  std::optional call_line;
-  std::optional call_column;
-  if

[Lldb-commits] [lldb] [lldb] Use the function block as a source for function ranges (PR #117996)

2024-11-28 Thread Pavel Labath via lldb-commits


@@ -10,7 +10,7 @@
 
 # CHECK: 1 match found in {{.*}}
 # CHECK: Summary: {{.*}}`foo
-# CHECK: Function: id = {{.*}}, name = "foo", ranges = 
[0x-0x0007)[0x0007-0x000e)[0x0014-0x001b)[0x001b-0x001c)
+# CHECK: Function: id = {{.*}}, name = "foo", ranges = 
[0x-0x000e)[0x0014-0x001c)

labath wrote:

Because the block ranges get automatically coalesced (which is a good thing, I 
guess).

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


[Lldb-commits] [lldb] [lldb] Use the function block as a source for function ranges (PR #117996)

2024-11-28 Thread Pavel Labath via lldb-commits


@@ -3240,8 +3195,17 @@ size_t SymbolFileDWARF::ParseBlocksRecursive(Function 
&func) {
   DWARFDIE function_die =
   dwarf_cu->GetNonSkeletonUnit().GetDIE(function_die_offset);
   if (function_die) {
-ParseBlocksRecursive(*comp_unit, &func.GetBlock(false), function_die,
- LLDB_INVALID_ADDRESS, 0);
+// We can't use the file address from the Function object as (in the OSO

labath wrote:

Filing a complaint about the complete lack of test coverage for this code path 
on non-mac hosts. :P

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


[Lldb-commits] [lldb] [lldb] Use the function block as a source for function ranges (PR #117996)

2024-11-28 Thread Pavel Labath via lldb-commits


@@ -2,7 +2,6 @@ REQUIRES: system-windows, lld
 RUN: %build --compiler=clang-cl --nodefaultlib --output=%t.exe 
%S/Inputs/FunctionNestedBlockTest.cpp
 RUN: lldb-test symbols -find=function -file FunctionNestedBlockTest.cpp -line 
4 %t.exe | FileCheck --check-prefix=CHECK-FUNCTION %s
 RUN: lldb-test symbols -find=block -file FunctionNestedBlockTest.cpp -line 4 
%t.exe | FileCheck --check-prefix=CHECK-BLOCK %s
-XFAIL: *

labath wrote:

This isn't directly related to what this patch is trying to do, but it looks 
like my refactor fixed the bug. :D

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


[Lldb-commits] [lldb] [lldb] Use the function block as a source for function ranges (PR #117996)

2024-11-28 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/117996

>From 78b8dabf1ada3d567d3f1a193fdf0cc0f159cb37 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Wed, 27 Nov 2024 17:05:23 +0100
Subject: [PATCH 1/2] [lldb] Use the function block as a source for function
 ranges

This is a follow-up/reimplementation of #115730. While working on that
patch, I did not realize that the correct (discontinuous) set of ranges
is already stored in the block representing the whole function. The
catch -- ranges for this block are only set later, when parsing all of
the blocks of the function.

This patch changes that by populating the function block ranges eagerly
-- from within the Function constructor. This also necessitates a
corresponding change in all of the symbol files -- so that they stop
populating the ranges of that block. This allows us to avoid some
unnecessary work (not parsing the function DW_AT_ranges twice) and also
results in some simplification of the parsing code.
---
 lldb/include/lldb/Symbol/Function.h   |   3 -
 .../Breakpad/SymbolFileBreakpad.cpp   |   4 +-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  | 180 +++---
 .../SymbolFile/DWARF/SymbolFileDWARF.h|   3 +-
 .../NativePDB/SymbolFileNativePDB.cpp |  12 +-
 .../Plugins/SymbolFile/PDB/SymbolFilePDB.cpp  |  53 ++
 lldb/source/Symbol/Function.cpp   |  16 +-
 .../DWARF/x86/discontinuous-function.s|   2 +-
 .../SymbolFile/PDB/function-nested-block.test |   1 -
 9 files changed, 111 insertions(+), 163 deletions(-)

diff --git a/lldb/include/lldb/Symbol/Function.h 
b/lldb/include/lldb/Symbol/Function.h
index 70f51a846f8d96..e71dc2348b1734 100644
--- a/lldb/include/lldb/Symbol/Function.h
+++ b/lldb/include/lldb/Symbol/Function.h
@@ -650,9 +650,6 @@ class Function : public UserID, public SymbolContextScope {
   /// All lexical blocks contained in this function.
   Block m_block;
 
-  /// List of address ranges belonging to the function.
-  AddressRanges m_ranges;
-
   /// The function address range that covers the widest range needed to contain
   /// all blocks. DEPRECATED: do not use this field in new code as the range 
may
   /// include addresses belonging to other functions.
diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp 
b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
index df3bf157278daf..bc886259d6fa5f 100644
--- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
+++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
@@ -299,9 +299,7 @@ size_t SymbolFileBreakpad::ParseBlocksRecursive(Function 
&func) {
   // "INLINE 0 ...", the current level is 0 and its parent block is the
   // function block at index 0.
   std::vector blocks;
-  Block &block = func.GetBlock(false);
-  block.AddRange(Block::Range(0, func.GetAddressRange().GetByteSize()));
-  blocks.push_back(&block);
+  blocks.push_back(&func.GetBlock(false));
 
   size_t blocks_added = 0;
   addr_t func_base = func.GetAddressRange().GetBaseAddress().GetOffset();
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index fe711c56958c44..d814b635f2e5cd 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1305,121 +1305,76 @@ bool SymbolFileDWARF::ParseDebugMacros(CompileUnit 
&comp_unit) {
   return true;
 }
 
-size_t SymbolFileDWARF::ParseBlocksRecursive(
-lldb_private::CompileUnit &comp_unit, Block *parent_block,
-const DWARFDIE &orig_die, addr_t subprogram_low_pc, uint32_t depth) {
+size_t SymbolFileDWARF::ParseBlocksRecursive(CompileUnit &comp_unit,
+ Block *parent_block, DWARFDIE die,
+ addr_t subprogram_low_pc) {
   size_t blocks_added = 0;
-  DWARFDIE die = orig_die;
-  while (die) {
+  for (; die; die = die.GetSibling()) {
 dw_tag_t tag = die.Tag();
 
-switch (tag) {
-case DW_TAG_inlined_subroutine:
-case DW_TAG_subprogram:
-case DW_TAG_lexical_block: {
-  Block *block = nullptr;
-  if (tag == DW_TAG_subprogram) {
-// Skip any DW_TAG_subprogram DIEs that are inside of a normal or
-// inlined functions. These will be parsed on their own as separate
-// entities.
-
-if (depth > 0)
-  break;
+if (tag != DW_TAG_inlined_subroutine && tag != DW_TAG_lexical_block)
+  continue;
 
-block = parent_block;
-  } else {
-block = parent_block->CreateChild(die.GetID()).get();
-  }
-  DWARFRangeList ranges;
-  const char *name = nullptr;
-  const char *mangled_name = nullptr;
-
-  std::optional decl_file;
-  std::optional decl_line;
-  std::optional decl_column;
-  std::optional call_file;
-  std::optional call_line;
-  std::optional call_column;
- 

[Lldb-commits] [lldb] [lldb] Use the function block as a source for function ranges (PR #117996)

2024-11-28 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 871e3dc8d8717bbcf5e3ad44331a21c3417c2639 
78b8dabf1ada3d567d3f1a193fdf0cc0f159cb37 --extensions cpp,h -- 
lldb/include/lldb/Symbol/Function.h 
lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp 
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h 
lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp 
lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp 
lldb/source/Symbol/Function.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index d814b635f2..6f19b264eb 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3197,10 +3197,9 @@ size_t SymbolFileDWARF::ParseBlocksRecursive(Function 
&func) {
   if (function_die) {
 // We can't use the file address from the Function object as (in the OSO
 // case) it will already be remapped to the main module.
-DWARFRangeList ranges =
-function_die.GetDIE()->GetAttributeAddressRanges(
-function_die.GetCU(),
-/*check_hi_lo_pc=*/true);
+DWARFRangeList ranges = function_die.GetDIE()->GetAttributeAddressRanges(
+function_die.GetCU(),
+/*check_hi_lo_pc=*/true);
 lldb::addr_t function_file_addr =
 ranges.GetMinRangeBase(LLDB_INVALID_ADDRESS);
 if (function_file_addr != LLDB_INVALID_ADDRESS)
diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp 
b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
index 952c1eb35c..b7854c05d3 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -420,15 +420,14 @@ static size_t ParseFunctionBlocksForPDBSymbol(
 block->AddRange(Block::Range(
 raw_sym.getVirtualAddress() - func_file_vm_addr, raw_sym.getLength()));
 block->FinalizeRanges();
-
   }
   auto results_up = pdb_symbol->findAllChildren();
   if (!results_up)
 return num_added;
 
   while (auto symbol_up = results_up->getNext()) {
-num_added += ParseFunctionBlocksForPDBSymbol(func_file_vm_addr,
- symbol_up.get(), 
parent_block, false);
+num_added += ParseFunctionBlocksForPDBSymbol(
+func_file_vm_addr, symbol_up.get(), parent_block, false);
   }
   return num_added;
 }
diff --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp
index 0c067a0126..4f07b94635 100644
--- a/lldb/source/Symbol/Function.cpp
+++ b/lldb/source/Symbol/Function.cpp
@@ -282,7 +282,7 @@ Function::Function(CompileUnit *comp_unit, lldb::user_id_t 
func_uid,
   m_range(CollapseRanges(ranges)), m_prologue_byte_size(0) {
   assert(comp_unit != nullptr);
   lldb::addr_t base_file_addr = m_range.GetBaseAddress().GetFileAddress();
-  for (const AddressRange &range: ranges)
+  for (const AddressRange &range : ranges)
 m_block.AddRange(
 Block::Range(range.GetBaseAddress().GetFileAddress() - base_file_addr,
  range.GetByteSize()));

``




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


[Lldb-commits] [lldb] 871e3dc - [lldb] Fixup #117699 for windows builds

2024-11-28 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2024-11-28T11:13:29+01:00
New Revision: 871e3dc8d8717bbcf5e3ad44331a21c3417c2639

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

LOG: [lldb] Fixup #117699 for windows builds

Added: 


Modified: 
lldb/tools/lldb-server/lldb-gdbserver.cpp

Removed: 




diff  --git a/lldb/tools/lldb-server/lldb-gdbserver.cpp 
b/lldb/tools/lldb-server/lldb-gdbserver.cpp
index bc93c837a107bd..ed10c161b6b2f6 100644
--- a/lldb/tools/lldb-server/lldb-gdbserver.cpp
+++ b/lldb/tools/lldb-server/lldb-gdbserver.cpp
@@ -210,9 +210,8 @@ void ConnectToRemote(MainLoop &mainloop,
 error.AsCString());
   exit(-1);
 }
-connection_up =
-std::unique_ptr(new ConnectionFileDescriptor(new TCPSocket(
-sockfd, /*should_close=*/true, 
/*child_processes_inherit=*/false)));
+connection_up = std::unique_ptr(new ConnectionFileDescriptor(
+new TCPSocket(sockfd, /*should_close=*/true)));
 #else
 url = llvm::formatv("fd://{0}", connection_fd).str();
 



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


[Lldb-commits] [lldb] [LLDB] Fix crash in TypeSystemClang::GetIndexofChildMemberWithName. (PR #117808)

2024-11-28 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [LLDB] Fix crash in TypeSystemClang::GetIndexofChildMemberWithName. (PR #117808)

2024-11-28 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [LLDB] Fix crash in TypeSystemClang::GetIndexofChildMemberWithName. (PR #117808)

2024-11-28 Thread Michael Buch via lldb-commits

Michael137 wrote:

This is quite an interesting case. Basically the issue arises only because we 
have an `anonymous` struct in `B` with a base class that has an "indirect 
field" called `x`:
```
IndirectFieldDecl 0x104145868 <>  implicit x 'int'  
|-Field 0x104145758 '' 'A::(anonymous struct)'
`-Field 0x104145700 'x' 'int'   
  
```

It's important that the nested structure in `B` is `anonymous` (not `unnamed`) 
because that's what [causes us to 
recurse](https://github.com/llvm/llvm-project/blob/cf47898453c83c977f92155c03e9cf205bfb2b19/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp#L6755)).
 Clang creates a `FieldDecl` with an empty name for that anonymous structure.

The lookup into base class `A` for name `x` works fine from Clang's 
perspective. But then we try to `GetIndexForRecordChild` to find the index of 
`x` in `A`, but that fails [because `RecordDecl::field_begin` doesn't iterate 
over 
`IndirectFieldDecl`s](https://github.com/llvm/llvm-project/blob/cf47898453c83c977f92155c03e9cf205bfb2b19/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp#L6688).

So even if we fix the crash, we still wouldn't be able to access `x`. I think 
we can address that separately from the crash, but I think we should not be 
clearing the vector in `TypeSystemClang::GetIndexofChildMemberWithName` and 
instead propagate errors properly.

Separately (outside the scope of this PR) we should make 
`GetIndexForRecordChild` account for fields of anonymous structures. E.g., we 
might want to do another lookup for `x` into the anonymous structure.

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


[Lldb-commits] [lldb] [LLDB] Fix crash in TypeSystemClang::GetIndexofChildMemberWithName. (PR #117808)

2024-11-28 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] Add 'FindFirstSymbolWithNameAndType()' to ModuleList. (PR #117777)

2024-11-28 Thread Michael Buch via lldb-commits

Michael137 wrote:

> Reference in

Not sure what the protocol is for this (CC @JDevlieghere @labath). At the very 
least we should have some coverage for it in the test-suite. There's precedent 
for this, e.g., APIs that only get exercised on the Swift branch, but at least 
those are on a public fork and tested on public build-bots.

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


[Lldb-commits] [lldb] [LLDB] Fix crash in TypeSystemClang::GetIndexofChildMemberWithName. (PR #117808)

2024-11-28 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [lldb][Process/Linux] Introduce LoongArch64 hw break/watchpoint support (PR #118043)

2024-11-28 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: wanglei (wangleiat)


Changes

This patch adds support for setting/clearing hardware watchpoints and
breakpoints on LoongArch 64-bit hardware.

Refer to the following document for the hw break/watchpoint:
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#control-and-status-registers-related-to-watchpoints

Fix Failed Tests:
  lldb-shell :: Subprocess/clone-follow-child-wp.test
  lldb-shell :: Subprocess/clone-follow-parent-wp.test
  lldb-shell :: Subprocess/fork-follow-child-wp.test
  lldb-shell :: Subprocess/fork-follow-parent-wp.test
  lldb-shell :: Subprocess/vfork-follow-child-wp.test
  lldb-shell :: Subprocess/vfork-follow-parent-wp.test
  lldb-shell :: Watchpoint/ExpressionLanguage.test


---

Patch is 20.24 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/118043.diff


4 Files Affected:

- (modified) 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp 
(+484) 
- (modified) 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.h 
(+60) 
- (modified) 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp 
(+2-1) 
- (modified) lldb/source/Target/Process.cpp (+2-1) 


``diff
diff --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
index f4d1bb297049da..1f73bd0467962d 100644
--- 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
+++ 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
@@ -11,7 +11,9 @@
 #include "NativeRegisterContextLinux_loongarch64.h"
 
 #include "lldb/Host/HostInfo.h"
+#include "lldb/Host/linux/Ptrace.h"
 #include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/RegisterValue.h"
 #include "lldb/Utility/Status.h"
@@ -32,6 +34,19 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::process_linux;
 
+// CTRL_PLV3_ENABLE, used to enable breakpoint/watchpoint
+constexpr uint32_t g_enable_bit = 0x10;
+
+// Returns appropriate control register bits for the specified size
+// size encoded:
+// case 1 : 0b11
+// case 2 : 0b10
+// case 4 : 0b01
+// case 8 : 0b00
+static inline uint64_t GetSizeBits(int size) {
+  return (3 - llvm::Log2_32(size)) << 10;
+}
+
 std::unique_ptr
 NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
 const ArchSpec &target_arch, NativeThreadLinux &native_thread) {
@@ -61,6 +76,8 @@ 
NativeRegisterContextLinux_loongarch64::NativeRegisterContextLinux_loongarch64(
   NativeRegisterContextLinux(native_thread) {
   ::memset(&m_fpr, 0, sizeof(m_fpr));
   ::memset(&m_gpr, 0, sizeof(m_gpr));
+  ::memset(&m_hwp_regs, 0, sizeof(m_hwp_regs));
+  ::memset(&m_hbp_regs, 0, sizeof(m_hbp_regs));
 
   m_gpr_is_valid = false;
   m_fpu_is_valid = false;
@@ -337,4 +354,471 @@ 
NativeRegisterContextLinux_loongarch64::GetExpeditedRegisters(
   return expedited_reg_nums;
 }
 
+uint32_t
+NativeRegisterContextLinux_loongarch64::NumSupportedHardwareBreakpoints() {
+  Log *log = GetLog(LLDBLog::Breakpoints);
+
+  // Read hardware breakpoint and watchpoint information.
+  Status error = ReadHardwareDebugInfo();
+
+  if (error.Fail()) {
+LLDB_LOG(log, "failed to read debug registers");
+return 0;
+  }
+
+  LLDB_LOG(log, "{0}", m_max_hbp_supported);
+  return m_max_hbp_supported;
+}
+
+uint32_t
+NativeRegisterContextLinux_loongarch64::SetHardwareBreakpoint(lldb::addr_t 
addr,
+  size_t size) {
+  Log *log = GetLog(LLDBLog::Breakpoints);
+  LLDB_LOG(log, "addr: {0:x}, size: {1:x}", addr, size);
+
+  // Read hardware breakpoint and watchpoint information.
+  Status error = ReadHardwareDebugInfo();
+  if (error.Fail()) {
+LLDB_LOG(log, "unable to set breakpoint: failed to read debug registers");
+return LLDB_INVALID_INDEX32;
+  }
+
+  uint32_t bp_index = 0;
+
+  // Check if size has a valid hardware breakpoint length.
+  if (size != 4)
+return LLDB_INVALID_INDEX32; // Invalid size for a LoongArch hardware
+ // breakpoint
+
+  // Check 4-byte alignment for hardware breakpoint target address.
+  if (addr & 0x03)
+return LLDB_INVALID_INDEX32; // Invalid address, should be 4-byte aligned.
+
+  // Iterate over stored breakpoints and find a free bp_index
+  bp_index = LLDB_INVALID_INDEX32;
+  for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
+if (!BreakpointIsEnabled(i))
+  bp_index = i; // Mark last free slot
+else if (m_hbp_regs[i].address == addr)
+  return LLDB_INVALID_INDEX32; // We do not support duplicate breakpoints.
+  }
+
+  if (bp_index == LLDB_INVALID_INDEX32)
+return LLDB_INVALID_INDEX32;
+
+  // Update breakpoint in local cache
+  m_hbp_regs[bp_index].address = addr;

[Lldb-commits] [lldb] [lldb][Process/Linux] Introduce LoongArch64 hw break/watchpoint support (PR #118043)

2024-11-28 Thread via lldb-commits

https://github.com/wangleiat created 
https://github.com/llvm/llvm-project/pull/118043

This patch adds support for setting/clearing hardware watchpoints and
breakpoints on LoongArch 64-bit hardware.

Refer to the following document for the hw break/watchpoint:
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#control-and-status-registers-related-to-watchpoints

Fix Failed Tests:
  lldb-shell :: Subprocess/clone-follow-child-wp.test
  lldb-shell :: Subprocess/clone-follow-parent-wp.test
  lldb-shell :: Subprocess/fork-follow-child-wp.test
  lldb-shell :: Subprocess/fork-follow-parent-wp.test
  lldb-shell :: Subprocess/vfork-follow-child-wp.test
  lldb-shell :: Subprocess/vfork-follow-parent-wp.test
  lldb-shell :: Watchpoint/ExpressionLanguage.test


>From a7cba7ef089a6f2004b1879d30675652729370e5 Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Fri, 29 Nov 2024 10:43:31 +0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 ...NativeRegisterContextLinux_loongarch64.cpp | 484 ++
 .../NativeRegisterContextLinux_loongarch64.h  |  60 +++
 .../GDBRemoteCommunicationServerCommon.cpp|   3 +-
 lldb/source/Target/Process.cpp|   3 +-
 4 files changed, 548 insertions(+), 2 deletions(-)

diff --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
index f4d1bb297049da..1f73bd0467962d 100644
--- 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
+++ 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
@@ -11,7 +11,9 @@
 #include "NativeRegisterContextLinux_loongarch64.h"
 
 #include "lldb/Host/HostInfo.h"
+#include "lldb/Host/linux/Ptrace.h"
 #include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/RegisterValue.h"
 #include "lldb/Utility/Status.h"
@@ -32,6 +34,19 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::process_linux;
 
+// CTRL_PLV3_ENABLE, used to enable breakpoint/watchpoint
+constexpr uint32_t g_enable_bit = 0x10;
+
+// Returns appropriate control register bits for the specified size
+// size encoded:
+// case 1 : 0b11
+// case 2 : 0b10
+// case 4 : 0b01
+// case 8 : 0b00
+static inline uint64_t GetSizeBits(int size) {
+  return (3 - llvm::Log2_32(size)) << 10;
+}
+
 std::unique_ptr
 NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
 const ArchSpec &target_arch, NativeThreadLinux &native_thread) {
@@ -61,6 +76,8 @@ 
NativeRegisterContextLinux_loongarch64::NativeRegisterContextLinux_loongarch64(
   NativeRegisterContextLinux(native_thread) {
   ::memset(&m_fpr, 0, sizeof(m_fpr));
   ::memset(&m_gpr, 0, sizeof(m_gpr));
+  ::memset(&m_hwp_regs, 0, sizeof(m_hwp_regs));
+  ::memset(&m_hbp_regs, 0, sizeof(m_hbp_regs));
 
   m_gpr_is_valid = false;
   m_fpu_is_valid = false;
@@ -337,4 +354,471 @@ 
NativeRegisterContextLinux_loongarch64::GetExpeditedRegisters(
   return expedited_reg_nums;
 }
 
+uint32_t
+NativeRegisterContextLinux_loongarch64::NumSupportedHardwareBreakpoints() {
+  Log *log = GetLog(LLDBLog::Breakpoints);
+
+  // Read hardware breakpoint and watchpoint information.
+  Status error = ReadHardwareDebugInfo();
+
+  if (error.Fail()) {
+LLDB_LOG(log, "failed to read debug registers");
+return 0;
+  }
+
+  LLDB_LOG(log, "{0}", m_max_hbp_supported);
+  return m_max_hbp_supported;
+}
+
+uint32_t
+NativeRegisterContextLinux_loongarch64::SetHardwareBreakpoint(lldb::addr_t 
addr,
+  size_t size) {
+  Log *log = GetLog(LLDBLog::Breakpoints);
+  LLDB_LOG(log, "addr: {0:x}, size: {1:x}", addr, size);
+
+  // Read hardware breakpoint and watchpoint information.
+  Status error = ReadHardwareDebugInfo();
+  if (error.Fail()) {
+LLDB_LOG(log, "unable to set breakpoint: failed to read debug registers");
+return LLDB_INVALID_INDEX32;
+  }
+
+  uint32_t bp_index = 0;
+
+  // Check if size has a valid hardware breakpoint length.
+  if (size != 4)
+return LLDB_INVALID_INDEX32; // Invalid size for a LoongArch hardware
+ // breakpoint
+
+  // Check 4-byte alignment for hardware breakpoint target address.
+  if (addr & 0x03)
+return LLDB_INVALID_INDEX32; // Invalid address, should be 4-byte aligned.
+
+  // Iterate over stored breakpoints and find a free bp_index
+  bp_index = LLDB_INVALID_INDEX32;
+  for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
+if (!BreakpointIsEnabled(i))
+  bp_index = i; // Mark last free slot
+else if (m_hbp_regs[i].address == addr)
+  return LLDB_INVALID_INDEX32; // We do not support duplicate breakpoints.
+  }
+
+  if (bp_index =

[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)

2024-11-28 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,43 @@
+//===-- HostInfoAIX.h -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_HOST_AIX_HOSTINFOAIX_H_
+#define LLDB_HOST_AIX_HOSTINFOAIX_H_
+
+#include "lldb/Host/posix/HostInfoPosix.h"
+#include "lldb/Utility/FileSpec.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VersionTuple.h"
+
+#include 
+#include 

DhruvSrivastavaX wrote:

Ok sure

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


[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)

2024-11-28 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,213 @@
+//===-- HostInfoAIX.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Host/aix/HostInfoAIX.h"
+#include "lldb/Host/Config.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+
+#include "llvm/Support/Threading.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+
+namespace {
+struct HostInfoAIXFields {
+  llvm::once_flag m_distribution_once_flag;
+  std::string m_distribution_id;
+  llvm::once_flag m_os_version_once_flag;
+  llvm::VersionTuple m_os_version;
+};
+} // namespace
+
+static HostInfoAIXFields *g_fields = nullptr;
+
+void HostInfoAIX::Initialize(SharedLibraryDirectoryHelper *helper) {
+  HostInfoPosix::Initialize(helper);
+
+  g_fields = new HostInfoAIXFields();
+}
+
+void HostInfoAIX::Terminate() {
+  assert(g_fields && "Missing call to Initialize?");
+  delete g_fields;
+  g_fields = nullptr;
+  HostInfoBase::Terminate();
+}
+
+llvm::VersionTuple HostInfoAIX::GetOSVersion() {
+  assert(g_fields && "Missing call to Initialize?");
+  llvm::call_once(g_fields->m_os_version_once_flag, []() {
+struct utsname un;
+if (uname(&un) != 0)
+  return;
+
+llvm::StringRef release = un.release;
+// The kernel release string can include a lot of stuff (e.g.
+// 4.9.0-6-amd64). We're only interested in the numbered prefix.
+release = release.substr(0, release.find_first_not_of("0123456789."));
+g_fields->m_os_version.tryParse(release);
+  });
+
+  return g_fields->m_os_version;
+}
+
+std::optional HostInfoAIX::GetOSBuildString() {
+  struct utsname un;
+  ::memset(&un, 0, sizeof(utsname));
+
+  if (uname(&un) < 0)
+return std::nullopt;
+
+  return std::string(un.release);
+}
+
+llvm::StringRef HostInfoAIX::GetDistributionId() {

DhruvSrivastavaX wrote:

Since this file is a linux copy so we didnt selectively remove anything. We can 
take care of that while merging into posix.

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


[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)

2024-11-28 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,213 @@
+//===-- HostInfoAIX.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Host/aix/HostInfoAIX.h"
+#include "lldb/Host/Config.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+
+#include "llvm/Support/Threading.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+
+namespace {
+struct HostInfoAIXFields {
+  llvm::once_flag m_distribution_once_flag;
+  std::string m_distribution_id;
+  llvm::once_flag m_os_version_once_flag;
+  llvm::VersionTuple m_os_version;
+};
+} // namespace
+
+static HostInfoAIXFields *g_fields = nullptr;
+
+void HostInfoAIX::Initialize(SharedLibraryDirectoryHelper *helper) {
+  HostInfoPosix::Initialize(helper);
+
+  g_fields = new HostInfoAIXFields();
+}
+
+void HostInfoAIX::Terminate() {
+  assert(g_fields && "Missing call to Initialize?");
+  delete g_fields;
+  g_fields = nullptr;
+  HostInfoBase::Terminate();
+}
+
+llvm::VersionTuple HostInfoAIX::GetOSVersion() {
+  assert(g_fields && "Missing call to Initialize?");
+  llvm::call_once(g_fields->m_os_version_once_flag, []() {
+struct utsname un;
+if (uname(&un) != 0)
+  return;
+
+llvm::StringRef release = un.release;
+// The kernel release string can include a lot of stuff (e.g.
+// 4.9.0-6-amd64). We're only interested in the numbered prefix.
+release = release.substr(0, release.find_first_not_of("0123456789."));
+g_fields->m_os_version.tryParse(release);
+  });
+
+  return g_fields->m_os_version;
+}
+
+std::optional HostInfoAIX::GetOSBuildString() {
+  struct utsname un;
+  ::memset(&un, 0, sizeof(utsname));
+
+  if (uname(&un) < 0)
+return std::nullopt;
+
+  return std::string(un.release);
+}

DhruvSrivastavaX wrote:

Yes, I can work on that. I'll update a template for review soon.

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


[Lldb-commits] [lldb] [lldb] Update dwim-print to show expanded objc instances (PR #117500)

2024-11-28 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] 448ac7d - [lldb][Mach-O] Handle shared cache binaries correctly (#117832)

2024-11-28 Thread via lldb-commits

Author: Jason Molenda
Date: 2024-11-28T10:31:57-08:00
New Revision: 448ac7d3418a31d35b462440c8bf644287efac8a

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

LOG: [lldb][Mach-O] Handle shared cache binaries correctly (#117832)

The Mach-O load commands have an LC_SYMTAB / struct symtab_command which
represents the offset of the symbol table (nlist records) and string
table for this binary. In a mach-o binary on disk, these are file
offsets. If a mach-o binary is loaded in memory with all segments
consecutive, the `symoff` and `stroff` are the offsets from the TEXT
segment (aka the mach-o header) virtual address to the virtual address
of the start of these tables.

However, if a Mach-O binary is a part of the shared cache, then the
segments will be separated -- they will have different slide values. And
it is possible for the LINKEDIT segment to be greater than 4GB away from
the TEXT segment in the virtual address space, so these 32-bit offsets
cannot express the offset from TEXT segment to these tables.

Create separate uint64_t variables to track the offset to the symbol
table and string table, instead of reusing the 32-bit ones in the
symtab_command structure.

rdar://140432279

Added: 


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

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 079fd905037d45..4aa85a99edf01e 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -2235,11 +2235,11 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
   LLDB_LOG(log, "Parsing symbol table for {0}", file_name);
   Progress progress("Parsing symbol table", file_name);
 
-  llvm::MachO::symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0};
   llvm::MachO::linkedit_data_command function_starts_load_command = {0, 0, 0, 
0};
   llvm::MachO::linkedit_data_command exports_trie_load_command = {0, 0, 0, 0};
   llvm::MachO::dyld_info_command dyld_info = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0};
   llvm::MachO::dysymtab_command dysymtab = m_dysymtab;
+  SymtabCommandLargeOffsets symtab_load_command;
   // The data element of type bool indicates that this entry is thumb
   // code.
   typedef AddressDataArray FunctionStarts;
@@ -2276,12 +2276,20 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 // Watch for the symbol table load command
 switch (lc.cmd) {
 case LC_SYMTAB:
+  // struct symtab_command {
+  //   uint32_tcmd;/* LC_SYMTAB */
+  //   uint32_tcmdsize;/* sizeof(struct symtab_command) */
+  //   uint32_tsymoff; /* symbol table offset */
+  //   uint32_tnsyms;  /* number of symbol table entries */
+  //   uint32_tstroff; /* string table offset */
+  //   uint32_tstrsize;/* string table size in bytes */
+  // };
   symtab_load_command.cmd = lc.cmd;
   symtab_load_command.cmdsize = lc.cmdsize;
-  // Read in the rest of the symtab load command
-  if (m_data.GetU32(&offset, &symtab_load_command.symoff, 4) ==
-  nullptr) // fill in symoff, nsyms, stroff, strsize fields
-return;
+  symtab_load_command.symoff = m_data.GetU32(&offset);
+  symtab_load_command.nsyms = m_data.GetU32(&offset);
+  symtab_load_command.stroff = m_data.GetU32(&offset);
+  symtab_load_command.strsize = m_data.GetU32(&offset);
   break;
 
 case LC_DYLD_INFO:

diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
index be87112df7d898..27b2078b5a3fcd 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
@@ -256,6 +256,19 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
 bool IsValid() { return all_image_infos.size() > 0; }
   };
 
+  // The LC_SYMTAB's symtab_command structure uses 32-bit file offsets
+  // for two fields, but ObjectFileMachO needs to calculate the offsets
+  // in virtual address layout from the start of the TEXT segment, and
+  // that span may be larger than 4GB.
+  struct SymtabCommandLargeOffsets {
+uint32_t cmd = 0;  /* LC_SYMTAB */
+uint32_t cmdsize = 0;  /* sizeof(struct symtab_command) */
+lldb::offset_t symoff = 0; /* symbol table offset */
+uint32_t nsyms = 0;/* number of symbol table entries */
+lldb::offset_t stroff = 0; /* string table offset */
+uint32_t strsize = 0;  /* string table size in bytes */
+  };
+
   /// Get

[Lldb-commits] [lldb] [lldb][Mach-O] Handle shared cache binaries correctly (PR #117832)

2024-11-28 Thread Jason Molenda via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Update dwim-print to show expanded objc instances (PR #117500)

2024-11-28 Thread Michael Buch via lldb-commits


@@ -87,7 +87,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 
   DumpValueObjectOptions dump_options = m_varobj_options.GetAsDumpOptions(
   m_expr_options.m_verbosity, m_format_options.GetFormat());
-  dump_options.SetHideRootName(suppress_result);
+  dump_options.SetHideRootName(suppress_result)
+  .SetExpandPointerTypeFlags(lldb::eTypeIsObjC);

Michael137 wrote:

I'm not actually sure what I'd prefer for C++. Usually when I print a pointer I 
only what to see the pointer value. But maybe that's because I've gotten used 
to the LLDB CLI and the way `frame var` works.

This thread here might be relevant: 
https://github.com/llvm/llvm-project/pull/117755#pullrequestreview-2462584459

Limiting this change to ObjC for now seems fine to me. But yea, asking a wider 
audience might be a good idea.

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


[Lldb-commits] [lldb] [lldb][Mach-O] Handle shared cache binaries correctly (PR #117832)

2024-11-28 Thread Jonas Devlieghere via lldb-commits

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

I like @Michael137's suggestion and the name makes it obvious what's going on. 
LGTM. 

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


[Lldb-commits] [lldb] [lldb][Mach-O] Handle shared cache binaries correctly (PR #117832)

2024-11-28 Thread Dave Lee via lldb-commits

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


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