[Lldb-commits] [lldb] 2ad771c - [lldb] Change some pointers to refs in register printing code

2023-04-17 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-04-17T07:40:13Z
New Revision: 2ad771cf7bae513da6e54772e4e50e0e049af9ac

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

LOG: [lldb] Change some pointers to refs in register printing code

No one was passing nullptr for these.

Reviewed By: JDevlieghere

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

Added: 


Modified: 
lldb/include/lldb/Core/DumpRegisterValue.h
lldb/source/Commands/CommandObjectRegister.cpp
lldb/source/Core/DumpRegisterValue.cpp
lldb/source/Core/EmulateInstruction.cpp
lldb/source/Core/FormatEntity.cpp

lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
lldb/source/Target/ThreadPlanCallFunction.cpp
lldb/source/Target/ThreadPlanTracer.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/DumpRegisterValue.h 
b/lldb/include/lldb/Core/DumpRegisterValue.h
index 9dc579dddc975..b89b35ac0b4ab 100644
--- a/lldb/include/lldb/Core/DumpRegisterValue.h
+++ b/lldb/include/lldb/Core/DumpRegisterValue.h
@@ -24,8 +24,8 @@ class Stream;
 // all.
 // Set print_flags to true to print register fields if they are available.
 // If you do so, target_sp must be non-null for it to work.
-void DumpRegisterValue(const RegisterValue ®_val, Stream *s,
-   const RegisterInfo *reg_info, bool prefix_with_name,
+void DumpRegisterValue(const RegisterValue ®_val, Stream &s,
+   const RegisterInfo ®_info, bool prefix_with_name,
bool prefix_with_alt_name, lldb::Format format,
uint32_t reg_name_right_align_at = 0,
ExecutionContextScope *exe_scope = nullptr,

diff  --git a/lldb/source/Commands/CommandObjectRegister.cpp 
b/lldb/source/Commands/CommandObjectRegister.cpp
index 4b0d455d90dae..8784b8b9977a8 100644
--- a/lldb/source/Commands/CommandObjectRegister.cpp
+++ b/lldb/source/Commands/CommandObjectRegister.cpp
@@ -84,42 +84,38 @@ class CommandObjectRegisterRead : public 
CommandObjectParsed {
   Options *GetOptions() override { return &m_option_group; }
 
   bool DumpRegister(const ExecutionContext &exe_ctx, Stream &strm,
-RegisterContext *reg_ctx, const RegisterInfo *reg_info,
+RegisterContext ®_ctx, const RegisterInfo ®_info,
 bool print_flags) {
-if (reg_info) {
-  RegisterValue reg_value;
-
-  if (reg_ctx->ReadRegister(reg_info, reg_value)) {
-strm.Indent();
-
-bool prefix_with_altname = (bool)m_command_options.alternate_name;
-bool prefix_with_name = !prefix_with_altname;
-DumpRegisterValue(reg_value, &strm, reg_info, prefix_with_name,
-  prefix_with_altname, m_format_options.GetFormat(), 8,
-  exe_ctx.GetBestExecutionContextScope(), print_flags,
-  exe_ctx.GetTargetSP());
-if ((reg_info->encoding == eEncodingUint) ||
-(reg_info->encoding == eEncodingSint)) {
-  Process *process = exe_ctx.GetProcessPtr();
-  if (process && reg_info->byte_size == process->GetAddressByteSize()) 
{
-addr_t reg_addr = reg_value.GetAsUInt64(LLDB_INVALID_ADDRESS);
-if (reg_addr != LLDB_INVALID_ADDRESS) {
-  Address so_reg_addr;
-  if (exe_ctx.GetTargetRef()
-  .GetSectionLoadList()
-  .ResolveLoadAddress(reg_addr, so_reg_addr)) {
-strm.PutCString("  ");
-so_reg_addr.Dump(&strm, exe_ctx.GetBestExecutionContextScope(),
- Address::DumpStyleResolvedDescription);
-  }
-}
+RegisterValue reg_value;
+if (!reg_ctx.ReadRegister(®_info, reg_value))
+  return false;
+
+strm.Indent();
+
+bool prefix_with_altname = (bool)m_command_options.alternate_name;
+bool prefix_with_name = !prefix_with_altname;
+DumpRegisterValue(reg_value, strm, reg_info, prefix_with_name,
+  prefix_with_altname, m_format_options.GetFormat(), 8,
+  exe_ctx.GetBestExecutionContextScope(), print_flags,
+  exe_ctx.GetTargetSP());
+if ((reg_info.encoding == eEncodingUint) ||
+(reg_info.encoding == eEncodingSint)) {
+  Process *process = exe_ctx.GetProcessPtr();
+  if (process && reg_info.byte_size == process->GetAddressByteSize()) {
+addr_t reg_addr = reg_value.GetAsUInt64(LLDB_INVALID_ADDRESS);
+if (reg_addr != LLDB_INVALID_ADDRESS) {
+  Address so_reg_addr;
+  if (exe_ctx.GetTargetRef().GetSectionLoadList().ResolveLoadAddress(
+  reg_addr, so_reg_addr)) {
+strm.PutCString("  ");
+so_re

[Lldb-commits] [PATCH] D148228: [lldb] Change some pointers to refs in register printing code

2023-04-17 Thread David Spickett via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2ad771cf7bae: [lldb] Change some pointers to refs in 
register printing code (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148228

Files:
  lldb/include/lldb/Core/DumpRegisterValue.h
  lldb/source/Commands/CommandObjectRegister.cpp
  lldb/source/Core/DumpRegisterValue.cpp
  lldb/source/Core/EmulateInstruction.cpp
  lldb/source/Core/FormatEntity.cpp
  
lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
  lldb/source/Target/ThreadPlanCallFunction.cpp
  lldb/source/Target/ThreadPlanTracer.cpp

Index: lldb/source/Target/ThreadPlanTracer.cpp
===
--- lldb/source/Target/ThreadPlanTracer.cpp
+++ lldb/source/Target/ThreadPlanTracer.cpp
@@ -223,7 +223,7 @@
   reg_value != m_register_values[reg_num]) {
 if (reg_value.GetType() != RegisterValue::eTypeInvalid) {
   stream->PutCString("\n\t");
-  DumpRegisterValue(reg_value, stream, reg_info, true, false,
+  DumpRegisterValue(reg_value, *stream, *reg_info, true, false,
 eFormatDefault);
 }
   }
Index: lldb/source/Target/ThreadPlanCallFunction.cpp
===
--- lldb/source/Target/ThreadPlanCallFunction.cpp
+++ lldb/source/Target/ThreadPlanCallFunction.cpp
@@ -163,7 +163,7 @@
  reg_idx < num_registers; ++reg_idx) {
   const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
   if (reg_ctx->ReadRegister(reg_info, reg_value)) {
-DumpRegisterValue(reg_value, &strm, reg_info, true, false,
+DumpRegisterValue(reg_value, strm, *reg_info, true, false,
   eFormatDefault);
 strm.EOL();
   }
Index: lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
===
--- lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
+++ lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
@@ -500,7 +500,7 @@
 strm.Printf("UnwindAssemblyInstEmulation::ReadRegister  (name = \"%s\") => "
 "synthetic_value = %i, value = ",
 reg_info->name, synthetic);
-DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault);
+DumpRegisterValue(reg_value, strm, *reg_info, false, false, eFormatDefault);
 log->PutString(strm.GetString());
   }
   return true;
@@ -526,7 +526,7 @@
 strm.Printf(
 "UnwindAssemblyInstEmulation::WriteRegister (name = \"%s\", value = ",
 reg_info->name);
-DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault);
+DumpRegisterValue(reg_value, strm, *reg_info, false, false, eFormatDefault);
 strm.PutCString(", context = ");
 context.Dump(strm, instruction);
 log->PutString(strm.GetString());
Index: lldb/source/Core/FormatEntity.cpp
===
--- lldb/source/Core/FormatEntity.cpp
+++ lldb/source/Core/FormatEntity.cpp
@@ -605,7 +605,7 @@
 if (reg_info) {
   RegisterValue reg_value;
   if (reg_ctx->ReadRegister(reg_info, reg_value)) {
-DumpRegisterValue(reg_value, &s, reg_info, false, false, format);
+DumpRegisterValue(reg_value, s, *reg_info, false, false, format);
 return true;
   }
 }
@@ -985,7 +985,7 @@
   if (reg_info) {
 RegisterValue reg_value;
 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
-  DumpRegisterValue(reg_value, &s, reg_info, false, false, format);
+  DumpRegisterValue(reg_value, s, *reg_info, false, false, format);
   return true;
 }
   }
Index: lldb/source/Core/EmulateInstruction.cpp
===
--- lldb/source/Core/EmulateInstruction.cpp
+++ lldb/source/Core/EmulateInstruction.cpp
@@ -363,7 +363,7 @@
   const RegisterValue ®_value) {
   StreamFile strm(stdout, false);
   strm.Printf("Write to Register (name = %s, value = ", reg_info->name);
-  DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault);
+  DumpRegisterValue(reg_value, strm, *reg_info, false, false, eFormatDefault);
   strm.PutCString(", context = ");
   context.Dump(strm, instruction);
   strm.EOL();
Index: lldb/source/Core/DumpRegisterValue.cpp
===
--- lldb/source/Core/DumpRegisterValue.cpp
+++ lldb/source/Core/DumpRegisterValue.cpp
@@ -59,8 +59,8 @@
   vobj_sp->Dump(strm, dump_options);
 }
 
-void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream *

[Lldb-commits] [PATCH] D148531: [lldb][DataFormatter] Fix libcxx std::deque formatter for references and pointers

2023-04-17 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, jingham.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

(Addresses GH#62153)

The `SBType` APIs to retrieve details about template arguments,
such as `GetTemplateArgumentType` or `GetTemplateArgumentKind`
don't "desugar" LValueReferences/RValueReferences or pointers.
So when we try to format a `std::deque&`, the python call to
`GetTemplateArgumentType` fails to get a type, leading to
an `element_size` of `0` and a division-by-zero python exception
(which gets caught by the summary provider silently). This leads
to the contents of such `std::deque&` to be printed incorrectly.

This patch dereferences the reference/pointer before calling
into the above SBAPIs.

**Testing**

- Add API test


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148531

Files:
  lldb/examples/synthetic/libcxx.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/main.cpp
@@ -0,0 +1,30 @@
+#include 
+#include 
+typedef std::deque int_deq;
+
+void by_ref_and_ptr(std::deque &ref, std::deque *ptr) {
+  printf("stop here");
+  return;
+}
+
+int main() {
+  int_deq numbers;
+  printf("break here");
+
+  (numbers.push_back(1));
+  printf("break here");
+
+  (numbers.push_back(12));
+  (numbers.push_back(123));
+  (numbers.push_back(1234));
+  (numbers.push_back(12345));
+  (numbers.push_back(123456));
+  (numbers.push_back(1234567));
+  by_ref_and_ptr(numbers, &numbers);
+  printf("break here");
+
+  numbers.clear();
+  printf("break here");
+
+  return 0;
+}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
@@ -0,0 +1,75 @@
+"""
+Test LLDB's data formatter for libcxx's std::deque.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class LibcxxDequeDataFormatterTestCase(TestBase):
+
+def check_numbers(self, var_name):
+self.expect("frame variable " + var_name,
+substrs=[var_name + ' = size=7',
+ '[0] = 1',
+ '[1] = 12',
+ '[2] = 123',
+ '[3] = 1234',
+ '[4] = 12345',
+ '[5] = 123456',
+ '[6] = 1234567',
+ '}'])
+
+self.expect_expr(var_name, result_summary="size=7", result_children=[
+ValueCheck(value="1"),
+ValueCheck(value="12"),
+ValueCheck(value="123"),
+ValueCheck(value="1234"),
+ValueCheck(value="12345"),
+ValueCheck(value="123456"),
+ValueCheck(value="1234567"),
+])
+
+@add_test_categories(["libc++"])
+def test_with_run_command(self):
+"""Test basic formatting of std::deque"""
+self.build()
+(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, "break here", lldb.SBFileSpec("main.cpp", False))
+
+self.expect("frame variable numbers",
+substrs=['numbers = size=0'])
+
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+# first value added
+self.expect("frame variable numbers",
+substrs=['numbers = size=1',
+ '[0] = 1',
+ '}'])
+
+# add remaining values
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+self.check_numbers("numbers")
+
+# clear out the deque
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+self.expect("frame variable numbers",
+substrs=['numbers = size=0'])
+
+@add_test_categories(["libc++"])
+def test_ref_and_ptr(self):
+"""Test formatting of std::deque& and std::deque*"""
+self.build()
+(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, "stop here", lldb.SBFileSpec("main.cpp", False))
+
+# The reference should display the same was as the value did
+self.check_numbers("ref")
+
+# The pointer should

[Lldb-commits] [lldb] d87cd45 - PECOFF: consume errors properly

2023-04-17 Thread Saleem Abdulrasool via lldb-commits

Author: Saleem Abdulrasool
Date: 2023-04-17T07:53:54-07:00
New Revision: d87cd45e4d855b57aed76dbd72c270ed152542ff

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

LOG: PECOFF: consume errors properly

We would not ensure that the error is consumed in the case that logging
is disabled. Ensure that we properly drop the error on the floor or we
would re-trigger the checked failure.

Differential Revision: https://reviews.llvm.org/D147669
Reviewed By: sgraenitz

Added: 


Modified: 
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp 
b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
index 95c37d4202b51..1d11caf155ec1 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -863,10 +863,14 @@ ObjectFilePECOFF::AppendFromExportTable(SectionList 
*sect_list,
   for (const auto &entry : m_binary->export_directories()) {
 llvm::StringRef sym_name;
 if (auto err = entry.getSymbolName(sym_name)) {
-  LLDB_LOG(log,
-   "ObjectFilePECOFF::AppendFromExportTable - failed to get export 
"
-   "table entry name: {0}",
-   llvm::fmt_consume(std::move(err)));
+  if (log)
+log->Format(
+__FILE__, __func__,
+"ObjectFilePECOFF::AppendFromExportTable - failed to get export "
+"table entry name: {0}",
+llvm::fmt_consume(std::move(err)));
+  else
+llvm::consumeError(std::move(err));
   continue;
 }
 Symbol symbol;
@@ -884,10 +888,13 @@ ObjectFilePECOFF::AppendFromExportTable(SectionList 
*sect_list,
   // it in symtab and make a note using the symbol name.
   llvm::StringRef forwarder_name;
   if (auto err = entry.getForwardTo(forwarder_name)) {
-LLDB_LOG(log,
- "ObjectFilePECOFF::AppendFromExportTable - failed to get "
- "forwarder name of forwarder export '{0}': {1}",
- sym_name, llvm::fmt_consume(std::move(err)));
+if (log)
+  log->Format(__FILE__, __func__,
+  "ObjectFilePECOFF::AppendFromExportTable - failed to get 
"
+  "forwarder name of forwarder export '{0}': {1}",
+  sym_name, llvm::fmt_consume(std::move(err)));
+else
+  llvm::consumeError(std::move(err));
 continue;
   }
   llvm::SmallString<256> new_name = 
{symbol.GetDisplayName().GetStringRef(),
@@ -899,10 +906,13 @@ ObjectFilePECOFF::AppendFromExportTable(SectionList 
*sect_list,
 
 uint32_t function_rva;
 if (auto err = entry.getExportRVA(function_rva)) {
-  LLDB_LOG(log,
-   "ObjectFilePECOFF::AppendFromExportTable - failed to get "
-   "address of export entry '{0}': {1}",
-   sym_name, llvm::fmt_consume(std::move(err)));
+  if (log)
+log->Format(__FILE__, __func__,
+"ObjectFilePECOFF::AppendFromExportTable - failed to get "
+"address of export entry '{0}': {1}",
+sym_name, llvm::fmt_consume(std::move(err)));
+  else
+llvm::consumeError(std::move(err));
   continue;
 }
 // Skip the symbol if it doesn't look valid.



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


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

2023-04-17 Thread Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd87cd45e4d85: PECOFF: consume errors properly (authored by 
Saleem Abdulrasool ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147669

Files:
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp


Index: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
===
--- lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -863,10 +863,14 @@
   for (const auto &entry : m_binary->export_directories()) {
 llvm::StringRef sym_name;
 if (auto err = entry.getSymbolName(sym_name)) {
-  LLDB_LOG(log,
-   "ObjectFilePECOFF::AppendFromExportTable - failed to get export 
"
-   "table entry name: {0}",
-   llvm::fmt_consume(std::move(err)));
+  if (log)
+log->Format(
+__FILE__, __func__,
+"ObjectFilePECOFF::AppendFromExportTable - failed to get export "
+"table entry name: {0}",
+llvm::fmt_consume(std::move(err)));
+  else
+llvm::consumeError(std::move(err));
   continue;
 }
 Symbol symbol;
@@ -884,10 +888,13 @@
   // it in symtab and make a note using the symbol name.
   llvm::StringRef forwarder_name;
   if (auto err = entry.getForwardTo(forwarder_name)) {
-LLDB_LOG(log,
- "ObjectFilePECOFF::AppendFromExportTable - failed to get "
- "forwarder name of forwarder export '{0}': {1}",
- sym_name, llvm::fmt_consume(std::move(err)));
+if (log)
+  log->Format(__FILE__, __func__,
+  "ObjectFilePECOFF::AppendFromExportTable - failed to get 
"
+  "forwarder name of forwarder export '{0}': {1}",
+  sym_name, llvm::fmt_consume(std::move(err)));
+else
+  llvm::consumeError(std::move(err));
 continue;
   }
   llvm::SmallString<256> new_name = 
{symbol.GetDisplayName().GetStringRef(),
@@ -899,10 +906,13 @@
 
 uint32_t function_rva;
 if (auto err = entry.getExportRVA(function_rva)) {
-  LLDB_LOG(log,
-   "ObjectFilePECOFF::AppendFromExportTable - failed to get "
-   "address of export entry '{0}': {1}",
-   sym_name, llvm::fmt_consume(std::move(err)));
+  if (log)
+log->Format(__FILE__, __func__,
+"ObjectFilePECOFF::AppendFromExportTable - failed to get "
+"address of export entry '{0}': {1}",
+sym_name, llvm::fmt_consume(std::move(err)));
+  else
+llvm::consumeError(std::move(err));
   continue;
 }
 // Skip the symbol if it doesn't look valid.


Index: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
===
--- lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -863,10 +863,14 @@
   for (const auto &entry : m_binary->export_directories()) {
 llvm::StringRef sym_name;
 if (auto err = entry.getSymbolName(sym_name)) {
-  LLDB_LOG(log,
-   "ObjectFilePECOFF::AppendFromExportTable - failed to get export "
-   "table entry name: {0}",
-   llvm::fmt_consume(std::move(err)));
+  if (log)
+log->Format(
+__FILE__, __func__,
+"ObjectFilePECOFF::AppendFromExportTable - failed to get export "
+"table entry name: {0}",
+llvm::fmt_consume(std::move(err)));
+  else
+llvm::consumeError(std::move(err));
   continue;
 }
 Symbol symbol;
@@ -884,10 +888,13 @@
   // it in symtab and make a note using the symbol name.
   llvm::StringRef forwarder_name;
   if (auto err = entry.getForwardTo(forwarder_name)) {
-LLDB_LOG(log,
- "ObjectFilePECOFF::AppendFromExportTable - failed to get "
- "forwarder name of forwarder export '{0}': {1}",
- sym_name, llvm::fmt_consume(std::move(err)));
+if (log)
+  log->Format(__FILE__, __func__,
+  "ObjectFilePECOFF::AppendFromExportTable - failed to get "
+  "forwarder name of forwarder export '{0}': {1}",
+  sym_name, llvm::fmt_consume(std::move(err)));
+else
+  llvm::consumeError(std::move(err));
 continue;
   }
   llvm::SmallString<256> new_name = {symbol.GetDisplayName().GetStringRef(),
@@ -899,10 +906,13 @@
 
 uint32_t function_rva;
 if (auto err = entry.getExportRVA(function_rva)) {
-  LLDB_LOG(log,
-   "ObjectFilePECOFF::AppendFromExportTable - failed to get "

[Lldb-commits] [PATCH] D146965: [lldb] Add support for MSP430 in LLDB.

2023-04-17 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.
This revision is now accepted and ready to land.

I'm sure there's something missing but LGTM.

@bulbazord ?


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

https://reviews.llvm.org/D146965

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


[Lldb-commits] [PATCH] D148062: [lldb] Make ObjectFileJSON loadable as a module

2023-04-17 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added subscribers: omjavaid, DavidSpickett.
DavidSpickett added a comment.

FYI this test is failing on our Windows on Arm bot due to not finding `strip`: 
https://lab.llvm.org/buildbot/#/builders/219/builds/2164/steps/6/logs/stdio

I see other uses so not sure why this one isn't working. Maybe it can use 
llvm-strip instead? @omjavaid


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148062

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


[Lldb-commits] [PATCH] D148541: [lldb] fix build issue on MSVC because of missing byte-swap builtins

2023-04-17 Thread Ashay Rane via Phabricator via lldb-commits
ashay-github created this revision.
ashay-github added reviewers: DavidSpickett, jasonmolenda, bulbazord.
Herald added a project: All.
ashay-github requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The `__builtin_bswap{32,64}()` builtins (introduced in commit e07a421d 
)
are missing from MSVC, which causes build errors when compiling LLDB on
Windows (tested with MSVC 19.34.31943.0).  This patch replaces the
builtins with either MSVC's `_byteswap_u{long,64}()` or the
`bswap_{32,64}()` functions from byteswap.h, which is part of libc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148541

Files:
  lldb/source/Core/DumpRegisterValue.cpp


Index: lldb/source/Core/DumpRegisterValue.cpp
===
--- lldb/source/Core/DumpRegisterValue.cpp
+++ lldb/source/Core/DumpRegisterValue.cpp
@@ -18,10 +18,17 @@
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private-types.h"
 
+#ifdef _MSC_VER
+#define bswap_32(x) _byteswap_ulong(x)
+#define bswap_64(x) _byteswap_uint64(x)
+#else
+#include 
+#endif
+
 using namespace lldb;
 
-static uint32_t swap_value(uint32_t v) { return __builtin_bswap32(v); }
-static uint64_t swap_value(uint64_t v) { return __builtin_bswap64(v); }
+static uint32_t swap_value(uint32_t v) { return bswap_32(v); }
+static uint64_t swap_value(uint64_t v) { return bswap_64(v); }
 
 template 
 static void dump_type_value(lldb_private::CompilerType &fields_type, T value,


Index: lldb/source/Core/DumpRegisterValue.cpp
===
--- lldb/source/Core/DumpRegisterValue.cpp
+++ lldb/source/Core/DumpRegisterValue.cpp
@@ -18,10 +18,17 @@
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private-types.h"
 
+#ifdef _MSC_VER
+#define bswap_32(x) _byteswap_ulong(x)
+#define bswap_64(x) _byteswap_uint64(x)
+#else
+#include 
+#endif
+
 using namespace lldb;
 
-static uint32_t swap_value(uint32_t v) { return __builtin_bswap32(v); }
-static uint64_t swap_value(uint64_t v) { return __builtin_bswap64(v); }
+static uint32_t swap_value(uint32_t v) { return bswap_32(v); }
+static uint64_t swap_value(uint64_t v) { return bswap_64(v); }
 
 template 
 static void dump_type_value(lldb_private::CompilerType &fields_type, T value,
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D148399: [lldb] Improve logging for process state change (NFC)

2023-04-17 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

I think a lot of this can be simplified by using `LLDB_LOG` instead of 
`LLDB_LOGF`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148399

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


[Lldb-commits] [PATCH] D148384: [Demangle] replace use of llvm::StringView w/ std::string_view

2023-04-17 Thread Nick Desaulniers via Phabricator via lldb-commits
nickdesaulniers added a comment.

In D148384#4270505 , @dhoekwater 
wrote:

> It looks like this breaks the build: 
> https://lab.llvm.org/buildbot#builders/119/builds/12865 
> https://lab.llvm.org/buildbot#builders/123/builds/18388 
> https://lab.llvm.org/buildbot#builders/60/builds/11628

Ah, I see what happened.  Those 3 builds had my follow up commit 
https://reviews.llvm.org/D148392, BUT the initial broken builds stopped 
producing diagnostics after the initial set of diagnostics that I fixed; kind 
of like how clang stops emitting diagnostics after the first 20. You can fix 
the 20, but there might be more to fix. That's what happened here.  
Specifically, I see 3 new diagnostics that weren't addressed in 
https://reviews.llvm.org/D148392:

1. llvm\lib\Demangle\MicrosoftDemangle.cpp(809)
2. llvm\include\llvm/Demangle/ItaniumDemangle.h(2334)
3. llvm\include\llvm/Demangle/ItaniumDemangle.h(2335)

I'll reopen this with https://reviews.llvm.org/D148392 squashed, plus the above 
three issues fixed, then get a colleague with a windows machine to help verify.

In D148384#4270554 , @MaskRay wrote:

> I am unsure about the Windows issue and find it difficult to repair...   I'm 
> testing a revert commit to not leave issues to the weekend.

That was the right thing to do, thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148384

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


[Lldb-commits] [PATCH] D148384: [Demangle] replace use of llvm::StringView w/ std::string_view

2023-04-17 Thread Nick Desaulniers via Phabricator via lldb-commits
nickdesaulniers added inline comments.



Comment at: llvm/include/llvm/Demangle/ItaniumDemangle.h:19
 
+#include 
+

MaskRay wrote:
> chapuni wrote:
> > Odd layering...
> Good catch. LLVMDemangle cannot depend on other LLVM libraries.
If these are inline function definitions, then there is no linkage between the 
libraries?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148384

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


[Lldb-commits] [PATCH] D148384: [Demangle] replace use of llvm::StringView w/ std::string_view

2023-04-17 Thread Nick Desaulniers via Phabricator via lldb-commits
nickdesaulniers updated this revision to Diff 514306.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.

- reopen with D148392  folded in, and 3 
additional fixes for windows as reported by buildbots


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

https://reviews.llvm.org/D148384

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  llvm/include/llvm/Demangle/ItaniumDemangle.h
  llvm/include/llvm/Demangle/MicrosoftDemangle.h
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/include/llvm/Demangle/Utility.h
  llvm/lib/Demangle/DLangDemangle.cpp
  llvm/lib/Demangle/ItaniumDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/lib/Demangle/RustDemangle.cpp
  llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
  llvm/unittests/Demangle/ItaniumDemangleTest.cpp
  llvm/unittests/Demangle/OutputBufferTest.cpp

Index: llvm/unittests/Demangle/OutputBufferTest.cpp
===
--- llvm/unittests/Demangle/OutputBufferTest.cpp
+++ llvm/unittests/Demangle/OutputBufferTest.cpp
@@ -10,12 +10,13 @@
 #include "llvm/Demangle/Utility.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 
 using namespace llvm;
 using llvm::itanium_demangle::OutputBuffer;
 
 static std::string toString(OutputBuffer &OB) {
-  StringView SV = OB;
+  std::string_view SV = OB;
   return {SV.begin(), SV.end()};
 }
 
Index: llvm/unittests/Demangle/ItaniumDemangleTest.cpp
===
--- llvm/unittests/Demangle/ItaniumDemangleTest.cpp
+++ llvm/unittests/Demangle/ItaniumDemangleTest.cpp
@@ -11,6 +11,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 
 using namespace llvm;
@@ -83,7 +84,7 @@
 }
 
 static std::string toString(OutputBuffer &OB) {
-  StringView SV = OB;
+  std::string_view SV = OB;
   return {SV.begin(), SV.end()};
 }
 
@@ -98,7 +99,7 @@
   OutputBuffer OB;
   Node *N = AbstractManglingParser::parseType();
   N->printLeft(OB);
-  StringView Name = N->getBaseName();
+  std::string_view Name = N->getBaseName();
   if (!Name.empty())
 Types.push_back(std::string(Name.begin(), Name.end()));
   else
Index: llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
===
--- llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
+++ llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
@@ -17,13 +17,12 @@
 using llvm::itanium_demangle::ForwardTemplateReference;
 using llvm::itanium_demangle::Node;
 using llvm::itanium_demangle::NodeKind;
-using llvm::itanium_demangle::StringView;
 
 namespace {
 struct FoldingSetNodeIDBuilder {
   llvm::FoldingSetNodeID &ID;
   void operator()(const Node *P) { ID.AddPointer(P); }
-  void operator()(StringView Str) {
+  void operator()(std::string_view Str) {
 ID.AddString(llvm::StringRef(Str.begin(), Str.size()));
   }
   template 
@@ -292,7 +291,7 @@
 N = Demangler.parse();
   else
 N = Demangler.make(
-StringView(Mangling.data(), Mangling.size()));
+std::string_view(Mangling.data(), Mangling.size()));
   return reinterpret_cast(N);
 }
 
Index: llvm/lib/Demangle/RustDemangle.cpp
===
--- llvm/lib/Demangle/RustDemangle.cpp
+++ llvm/lib/Demangle/RustDemangle.cpp
@@ -11,8 +11,8 @@
 //
 //===--===//
 
+#include "llvm/ADT/StringViewExtras.h"
 #include "llvm/Demangle/Demangle.h"
-#include "llvm/Demangle/StringView.h"
 #include "llvm/Demangle/Utility.h"
 
 #include 
@@ -25,12 +25,11 @@
 
 using llvm::itanium_demangle::OutputBuffer;
 using llvm::itanium_demangle::ScopedOverride;
-using llvm::itanium_demangle::StringView;
 
 namespace {
 
 struct Identifier {
-  StringView Name;
+  std::string_view Name;
   bool Punycode;
 
   bool empty() const { return Name.empty(); }
@@ -77,7 +76,7 @@
   size_t RecursionLevel;
   size_t BoundLifetimes;
   // Input string that is being demangled with "_R" prefix removed.
-  StringView Input;
+  std::string_view Input;
   // Position in the input string.
   size_t Position;
   // When true, print methods append the output to the stream.
@@ -92,7 +91,7 @@
 
   Demangler(size_t MaxRecursionLevel = 500);
 
-  bool demangle(StringView MangledName);
+  bool demangle(std::string_view MangledName);
 
 private:
   bool demanglePath(IsInType Type,
@@ -128,10 +127,10 @@
   uint64_t parseOptionalBase62Number(char Tag);
   uint64_t parseBase62Number();
   uint64_t parseDecimalNumber();
-  uint64_t parseHexNumber(StringView &HexDigits);
+  uint64_t parseHexNumber(std::string_view &HexDigits);
 
   void print(char C);
-  void print(StringView S);
+  void print(std::string_v

[Lldb-commits] [PATCH] D148546: Reland: [Demangle] replace use of llvm::StringView w/ std::string_view

2023-04-17 Thread Nick Desaulniers via Phabricator via lldb-commits
nickdesaulniers created this revision.
nickdesaulniers added reviewers: MaskRay, erichkeane.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

This reverts commit d81cdb49d74064e88843733e7da92db865943509 
.

This refactoring was waiting on converting LLVM to C++17.

Leave StringView.h and cleanup around for subsequent cleanup.

Additional fixes for missing std::string_view conversions for MSVC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148546

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  llvm/include/llvm/Demangle/ItaniumDemangle.h
  llvm/include/llvm/Demangle/MicrosoftDemangle.h
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/include/llvm/Demangle/Utility.h
  llvm/lib/Demangle/DLangDemangle.cpp
  llvm/lib/Demangle/ItaniumDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/lib/Demangle/RustDemangle.cpp
  llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
  llvm/unittests/Demangle/ItaniumDemangleTest.cpp
  llvm/unittests/Demangle/OutputBufferTest.cpp

Index: llvm/unittests/Demangle/OutputBufferTest.cpp
===
--- llvm/unittests/Demangle/OutputBufferTest.cpp
+++ llvm/unittests/Demangle/OutputBufferTest.cpp
@@ -10,12 +10,13 @@
 #include "llvm/Demangle/Utility.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 
 using namespace llvm;
 using llvm::itanium_demangle::OutputBuffer;
 
 static std::string toString(OutputBuffer &OB) {
-  StringView SV = OB;
+  std::string_view SV = OB;
   return {SV.begin(), SV.end()};
 }
 
Index: llvm/unittests/Demangle/ItaniumDemangleTest.cpp
===
--- llvm/unittests/Demangle/ItaniumDemangleTest.cpp
+++ llvm/unittests/Demangle/ItaniumDemangleTest.cpp
@@ -11,6 +11,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 
 using namespace llvm;
@@ -83,7 +84,7 @@
 }
 
 static std::string toString(OutputBuffer &OB) {
-  StringView SV = OB;
+  std::string_view SV = OB;
   return {SV.begin(), SV.end()};
 }
 
@@ -98,7 +99,7 @@
   OutputBuffer OB;
   Node *N = AbstractManglingParser::parseType();
   N->printLeft(OB);
-  StringView Name = N->getBaseName();
+  std::string_view Name = N->getBaseName();
   if (!Name.empty())
 Types.push_back(std::string(Name.begin(), Name.end()));
   else
Index: llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
===
--- llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
+++ llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
@@ -17,13 +17,12 @@
 using llvm::itanium_demangle::ForwardTemplateReference;
 using llvm::itanium_demangle::Node;
 using llvm::itanium_demangle::NodeKind;
-using llvm::itanium_demangle::StringView;
 
 namespace {
 struct FoldingSetNodeIDBuilder {
   llvm::FoldingSetNodeID &ID;
   void operator()(const Node *P) { ID.AddPointer(P); }
-  void operator()(StringView Str) {
+  void operator()(std::string_view Str) {
 ID.AddString(llvm::StringRef(Str.begin(), Str.size()));
   }
   template 
@@ -292,7 +291,7 @@
 N = Demangler.parse();
   else
 N = Demangler.make(
-StringView(Mangling.data(), Mangling.size()));
+std::string_view(Mangling.data(), Mangling.size()));
   return reinterpret_cast(N);
 }
 
Index: llvm/lib/Demangle/RustDemangle.cpp
===
--- llvm/lib/Demangle/RustDemangle.cpp
+++ llvm/lib/Demangle/RustDemangle.cpp
@@ -11,8 +11,8 @@
 //
 //===--===//
 
+#include "llvm/ADT/StringViewExtras.h"
 #include "llvm/Demangle/Demangle.h"
-#include "llvm/Demangle/StringView.h"
 #include "llvm/Demangle/Utility.h"
 
 #include 
@@ -25,12 +25,11 @@
 
 using llvm::itanium_demangle::OutputBuffer;
 using llvm::itanium_demangle::ScopedOverride;
-using llvm::itanium_demangle::StringView;
 
 namespace {
 
 struct Identifier {
-  StringView Name;
+  std::string_view Name;
   bool Punycode;
 
   bool empty() const { return Name.empty(); }
@@ -77,7 +76,7 @@
   size_t RecursionLevel;
   size_t BoundLifetimes;
   // Input string that is being demangled with "_R" prefix removed.
-  StringView Input;
+  std::string_view Input;
   // Position in the input string.
   size_t Position;
   // When true, print methods append the output to the stream.
@@ -92,7 +91,7 @@
 
   Demangler(size_t MaxRecursionLevel = 500);
 
-  bool demangle(StringView MangledName);
+  bool demangle(std::string_view MangledName);
 
 private:
   bool demanglePath(IsInType Ty

[Lldb-commits] [PATCH] D148384: [Demangle] replace use of llvm::StringView w/ std::string_view

2023-04-17 Thread Nick Desaulniers via Phabricator via lldb-commits
nickdesaulniers closed this revision.
nickdesaulniers added a comment.

Creating https://reviews.llvm.org/D148546 instead; `arcanist` really doesn't 
like how I've reopened this review.


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

https://reviews.llvm.org/D148384

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


[Lldb-commits] [PATCH] D146965: [lldb] Add support for MSP430 in LLDB.

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

In D146965#4274274 , @DavidSpickett 
wrote:

> I'm sure there's something missing but LGTM.
>
> @bulbazord ?

I'm satisfied with this since there are tests. I'm not sure what might be 
missing but I'm sure we'll find it in time.


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

https://reviews.llvm.org/D146965

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


[Lldb-commits] [PATCH] D148546: Reland: [Demangle] replace use of llvm::StringView w/ std::string_view

2023-04-17 Thread Nick Desaulniers via Phabricator via lldb-commits
nickdesaulniers planned changes to this revision.
nickdesaulniers added inline comments.
Herald added a subscriber: JDevlieghere.



Comment at: llvm/include/llvm/Demangle/ItaniumDemangle.h:19
 
+#include 
+

I'll probably revert https://reviews.llvm.org/D148367 for now then rebase this 
on top.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148546

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


[Lldb-commits] [PATCH] D146965: [lldb] Add support for MSP430 in LLDB.

2023-04-17 Thread Anton Korobeynikov via Phabricator via lldb-commits
asl added a comment.

Thanks @bulbazord @DavidSpickett !


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

https://reviews.llvm.org/D146965

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


[Lldb-commits] [lldb] 82c02b7 - [lldb] Add support for MSP430 in LLDB.

2023-04-17 Thread Anton Korobeynikov via lldb-commits

Author: Anton Korobeynikov
Date: 2023-04-17T11:05:09-07:00
New Revision: 82c02b733c7736507a41a26bebd37d3f8e88bd4e

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

LOG: [lldb] Add support for MSP430 in LLDB.

Add MSP430 to the list of available targets, implement MSP430 ABI, add support 
for debugging targets with 16-bit address size.

The update is intended for use with MSPDebug, a GDB server implementation for 
MSP430.

Reviewed By: bulbazord, DavidSpickett

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

Added: 
lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp
lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.h
lldb/source/Plugins/ABI/MSP430/CMakeLists.txt
lldb/test/API/functionalities/gdb_remote_client/TestMSP430MSPDebug.py
lldb/test/API/functionalities/gdb_remote_client/msp430.yaml

Modified: 
lldb/include/lldb/Utility/ArchSpec.h
lldb/include/lldb/Utility/DataExtractor.h
lldb/source/Expression/IRMemoryMap.cpp
lldb/source/Expression/LLVMUserExpression.cpp
lldb/source/Host/common/NativeProcessProtocol.cpp
lldb/source/Plugins/ABI/CMakeLists.txt
lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterFallback.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/source/Target/Platform.cpp
lldb/source/Utility/ArchSpec.cpp
lldb/unittests/Utility/ArchSpecTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Utility/ArchSpec.h 
b/lldb/include/lldb/Utility/ArchSpec.h
index 444d427c1bd44..2de517d765b2a 100644
--- a/lldb/include/lldb/Utility/ArchSpec.h
+++ b/lldb/include/lldb/Utility/ArchSpec.h
@@ -172,6 +172,8 @@ class ArchSpec {
 eCore_mips64r5el,
 eCore_mips64r6el,
 
+eCore_msp430,
+
 eCore_ppc_generic,
 eCore_ppc_ppc601,
 eCore_ppc_ppc602,

diff  --git a/lldb/include/lldb/Utility/DataExtractor.h 
b/lldb/include/lldb/Utility/DataExtractor.h
index dbf0bce8c8d0d..0b7e771ed4f86 100644
--- a/lldb/include/lldb/Utility/DataExtractor.h
+++ b/lldb/include/lldb/Utility/DataExtractor.h
@@ -843,9 +843,7 @@ class DataExtractor {
   /// \param[in] addr_size
   /// The size in bytes to use when extracting addresses.
   void SetAddressByteSize(uint32_t addr_size) {
-#ifdef LLDB_CONFIGURATION_DEBUG
-assert(addr_size == 4 || addr_size == 8);
-#endif
+assert(addr_size == 2 || addr_size == 4 || addr_size == 8);
 m_addr_size = addr_size;
   }
 

diff  --git a/lldb/source/Expression/IRMemoryMap.cpp 
b/lldb/source/Expression/IRMemoryMap.cpp
index 3c102dd4eaef1..951444db86a87 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -96,12 +96,21 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
   // regions, walk forward through memory until a region is found that has
   // adequate space for our allocation.
   if (process_is_alive) {
-const uint64_t end_of_memory = process_sp->GetAddressByteSize() == 8
-   ? 0xull
-   : 0xull;
-
-lldbassert(process_sp->GetAddressByteSize() == 4 ||
-   end_of_memory != 0xull);
+uint64_t end_of_memory;
+switch (process_sp->GetAddressByteSize()) {
+case 2:
+  end_of_memory = 0xull;
+  break;
+case 4:
+  end_of_memory = 0xull;
+  break;
+case 8:
+  end_of_memory = 0xull;
+  break;
+default:
+  lldbassert(false && "Invalid address size.");
+  return LLDB_INVALID_ADDRESS;
+}
 
 MemoryRegionInfo region_info;
 Status err = process_sp->GetMemoryRegionInfo(ret, region_info);
@@ -137,26 +146,31 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
   // We've tried our algorithm, and it didn't work.  Now we have to reset back
   // to the end of the allocations we've already reported, or use a 'sensible'
   // default if this is our first allocation.
-
   if (m_allocations.empty()) {
 uint32_t address_byte_size = GetAddressByteSize();
 if (address_byte_size != UINT32_MAX) {
   switch (address_byte_size) {
-  case 8:
-ret = 0xdead0fffull;
+  case 2:
+ret = 0x8000ull;
 break;
   case 4:
 ret = 0xee00ull;
 break;
-  default:
+  case 8:
+ret = 0xdead0fffull;
 break;
+  default:
+lldbassert(false && "Invalid address size.");
+return LLDB_INVALID_ADDRESS;
   }
 }
   } else {
 auto back = m_allocations.rbegin();
 lldb::addr_t addr = back->first;
 size_t alloc_size = back->second.m_size;
-ret = llvm::alignTo(addr + alloc_size, 4096);
+auto arch 

[Lldb-commits] [PATCH] D146965: [lldb] Add support for MSP430 in LLDB.

2023-04-17 Thread Anton Korobeynikov via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG82c02b733c77: [lldb] Add support for MSP430 in LLDB. 
(authored by asl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146965

Files:
  lldb/include/lldb/Utility/ArchSpec.h
  lldb/include/lldb/Utility/DataExtractor.h
  lldb/source/Expression/IRMemoryMap.cpp
  lldb/source/Expression/LLVMUserExpression.cpp
  lldb/source/Host/common/NativeProcessProtocol.cpp
  lldb/source/Plugins/ABI/CMakeLists.txt
  lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp
  lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.h
  lldb/source/Plugins/ABI/MSP430/CMakeLists.txt
  lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterFallback.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Utility/ArchSpec.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestMSP430MSPDebug.py
  lldb/test/API/functionalities/gdb_remote_client/msp430.yaml
  lldb/unittests/Utility/ArchSpecTest.cpp

Index: lldb/unittests/Utility/ArchSpecTest.cpp
===
--- lldb/unittests/Utility/ArchSpecTest.cpp
+++ lldb/unittests/Utility/ArchSpecTest.cpp
@@ -123,6 +123,12 @@
   EXPECT_STREQ("i686", AS.GetArchitectureName());
   EXPECT_EQ(ArchSpec::eCore_x86_32_i686, AS.GetCore());
 
+  AS = ArchSpec();
+  EXPECT_TRUE(AS.SetTriple("msp430---elf"));
+  EXPECT_EQ(llvm::Triple::msp430, AS.GetTriple().getArch());
+  EXPECT_STREQ("msp430", AS.GetArchitectureName());
+  EXPECT_EQ(ArchSpec::eCore_msp430, AS.GetCore());
+
   // Various flavors of invalid triples.
   AS = ArchSpec();
   EXPECT_FALSE(AS.SetTriple("unknown-unknown-unknown"));
Index: lldb/test/API/functionalities/gdb_remote_client/msp430.yaml
===
--- /dev/null
+++ lldb/test/API/functionalities/gdb_remote_client/msp430.yaml
@@ -0,0 +1,426 @@
+# File test.c, compiled with flags "-O0 -g"
+# Source code:
+#
+# int foo = 0;
+#
+# int func() {
+# foo = 1234;
+# return foo;
+# }
+#
+# int main() {
+# return func();
+# }
+#
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  OSABI:   ELFOSABI_STANDALONE
+  Type:ET_EXEC
+  Machine: EM_MSP430
+  Flags:   [  ]
+  Entry:   0x500
+ProgramHeaders:
+  - Type:PT_LOAD
+Flags:   [ PF_X, PF_R ]
+FirstSec:.text
+LastSec: .bss
+VAddr:   0x46C
+Align:   0x4
+  - Type:PT_LOAD
+Flags:   [ PF_W, PF_R ]
+FirstSec:.data
+LastSec: .bss
+VAddr:   0x53C
+Align:   0x4
+  - Type:PT_LOAD
+Flags:   [ PF_R ]
+FirstSec:__interrupt_vector_31
+LastSec: __interrupt_vector_31
+VAddr:   0xFFFE
+Align:   0x4
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x500
+AddressAlign:0x4
+Content: 3140C0FF0C43B0121C05B0128101B240D2043C051C423C053041318002008143B01210053150020030411C4330413C402A0030410C433041
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x53C
+AddressAlign:0x1
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x53C
+AddressAlign:0x2
+Size:0x2
+  - Name:__interrupt_vector_31
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC ]
+Address: 0xFFFE
+AddressAlign:0x1
+Offset:  0xD2
+Content: '0005'
+  - Name:.rodata
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x500
+AddressAlign:0x1
+  - Name:.rodata2
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE ]
+Address: 0x500
+AddressAlign:0x1
+  - Name:.noinit
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE ]
+Address: 0x53E
+AddressAlign:0x1
+  - Name:.persistent
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE ]
+Address: 0x53E
+AddressAlign:0x1
+  - Name:.MSP430.attributes
+Type:SHT_MSP430_ATTRIBUTES
+AddressAlign:0x1
+Content: 4116006D737061626900010B00040106010801
+  - Name:.comment
+Type:SHT_PROGBITS
+Flags:   [ SHF_MERGE, SHF_STRINGS ]
+AddressAlign:0x1
+E

[Lldb-commits] [PATCH] D148548: [lldb] Improve breakpoint management for interactive scripted process

2023-04-17 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added reviewers: jingham, JDevlieghere, bulbazord.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch improves breakpoint management when doing interactive
scripted process debugging.

In other to know which process set a breakpoint, we need to do some book
keeping on the multiplexer scripted process. When initializing the
multiplexer, we will first copy breakpoints that are already set on the
driving target.

Everytime we launch or resume, we should copy breakpoints from the
multiplexer to the driving process.

When creating a breakpoint from a child process, it needs to be set both
on the multiplexer and on the driving process. We also tag the created
breakpoint with the name and pid of the originator process.

This patch also implements all the requirement to achieve proper
breakpoint management. That involves:

- Adding python interator for breakpoints and watchpoints in SBTarget
- Add a new `ScriptedProcess.create_breakpoint` python method

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148548

Files:
  lldb/bindings/interface/SBTargetExtensions.i
  lldb/bindings/python/python-wrapper.swig
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/API/SBBreakpoint.h
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
  
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
  
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Index: lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
===
--- lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -139,6 +139,10 @@
   return nullptr;
 }
 
+void *lldb_private::LLDBSWIGPython_CastPyObjectToSBBreakpoint(PyObject *data) {
+  return nullptr;
+}
+
 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBAttachInfo(PyObject *data) {
   return nullptr;
 }
Index: lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
===
--- lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
+++ lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
@@ -6,8 +6,7 @@
 #   -o "create_sub" \
 #   -o "br set -p 'also break here'" -o 'continue'
 
-import os,json,struct,signal
-import time
+import os,json,struct,signal,tempfile
 
 from threading import Thread
 from typing import Any, Dict
@@ -128,6 +127,11 @@
 # Update the filtered thread class from PassthruScriptedThread to MultiplexedScriptedThread
 return dict(map(lambda pair: (pair[0], MultiplexedScriptedThread(pair[1])), filtered_threads.items()))
 
+def create_breakpoint(self, addr, error, pid=None):
+if not self.multiplexer:
+error.SetErrorString("Multiplexer is not set.")
+return self.multiplexer.create_breakpoint(addr, error, self.get_process_id())
+
 def get_scripted_thread_plugin(self):
 return MultiplexedScriptedThread.__module__ + "." + MultiplexedScriptedThread.__name__
 
@@ -260,10 +264,33 @@
 self.listener = lldb.SBListener("lldb.listener.multiplexer-scripted-process")
 self.multiplexed_processes = {}
 
+# Copy breakpoints from real target to passthrough
+with tempfile.NamedTemporaryFile() as tf:
+bkpt_file = lldb.SBFileSpec(tf.name)
+error = self.driving_target.BreakpointsWriteToFile(bkpt_file)
+if error.Fail():
+log("Failed to save breakpoints from driving target (%s)"
+% error.GetCString())
+bkpts_list = lldb.SBBreakpointList(self.target)
+error = self.target.BreakpointsCreateFromFile(bkpt_file, bkpts_list)
+if error.Fail():
+log("Failed create breakpoints from driving target \
+(bkpt file: %s)" % tf.name)
+
+# Copy breakpoint from passthrough to real target
+if error.Success():
+self.driving_target.DeleteAllBr

[Lldb-commits] [PATCH] D148548: [lldb] Improve breakpoint management for interactive scripted process

2023-04-17 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 514326.
mib added a comment.

Re-format


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

https://reviews.llvm.org/D148548

Files:
  lldb/bindings/interface/SBTargetExtensions.i
  lldb/bindings/python/python-wrapper.swig
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/API/SBBreakpoint.h
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
  
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
  
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Index: lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
===
--- lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -139,6 +139,10 @@
   return nullptr;
 }
 
+void *lldb_private::LLDBSWIGPython_CastPyObjectToSBBreakpoint(PyObject *data) {
+  return nullptr;
+}
+
 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBAttachInfo(PyObject *data) {
   return nullptr;
 }
Index: lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
===
--- lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
+++ lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
@@ -6,8 +6,7 @@
 #   -o "create_sub" \
 #   -o "br set -p 'also break here'" -o 'continue'
 
-import os,json,struct,signal
-import time
+import os,json,struct,signal,tempfile
 
 from threading import Thread
 from typing import Any, Dict
@@ -128,6 +127,11 @@
 # Update the filtered thread class from PassthruScriptedThread to MultiplexedScriptedThread
 return dict(map(lambda pair: (pair[0], MultiplexedScriptedThread(pair[1])), filtered_threads.items()))
 
+def create_breakpoint(self, addr, error, pid=None):
+if not self.multiplexer:
+error.SetErrorString("Multiplexer is not set.")
+return self.multiplexer.create_breakpoint(addr, error, self.get_process_id())
+
 def get_scripted_thread_plugin(self):
 return MultiplexedScriptedThread.__module__ + "." + MultiplexedScriptedThread.__name__
 
@@ -260,10 +264,33 @@
 self.listener = lldb.SBListener("lldb.listener.multiplexer-scripted-process")
 self.multiplexed_processes = {}
 
+# Copy breakpoints from real target to passthrough
+with tempfile.NamedTemporaryFile() as tf:
+bkpt_file = lldb.SBFileSpec(tf.name)
+error = self.driving_target.BreakpointsWriteToFile(bkpt_file)
+if error.Fail():
+log("Failed to save breakpoints from driving target (%s)"
+% error.GetCString())
+bkpts_list = lldb.SBBreakpointList(self.target)
+error = self.target.BreakpointsCreateFromFile(bkpt_file, bkpts_list)
+if error.Fail():
+log("Failed create breakpoints from driving target \
+(bkpt file: %s)" % tf.name)
+
+# Copy breakpoint from passthrough to real target
+if error.Success():
+self.driving_target.DeleteAllBreakpoints()
+for bkpt in self.target.breakpoints:
+if bkpt.IsValid():
+for bl in bkpt:
+real_bpkt = self.driving_target.BreakpointCreateBySBAddress(bl.GetAddress())
+if not real_bpkt.IsValid():
+log("Failed to set breakpoint at address %s in \
+driving target" % hex(bl.GetLoadAddress()))
+
 self.listener_thread = Thread(target=self.wait_for_driving_process_to_stop, daemon=True)
 self.listener_thread.start()
 
-
 def launch(self, should_stop=True):
 if not self.driving_target:
 return lldb.SBError("%s.resume: Invalid driving target." %
@@ -318,6 +345,41 @@
 parity = pid % 2
 return dict(filter(lambda pair: pair[0] % 2 == parity, self.threads.items()))
 
+def create_breakpoint(self, addr, error, pid=None):
+if not self.driving_target:
+error

[Lldb-commits] [PATCH] D148541: [lldb] fix build issue on MSVC because of missing byte-swap builtins

2023-04-17 Thread Alex Langford via Phabricator via lldb-commits
bulbazord requested changes to this revision.
bulbazord added a comment.
This revision now requires changes to proceed.

Instead of not using `__builtin_bswap{32,64}` entirely, we should check if 
they're available.

You can use the clang feature-checking macro `__has_builtin` (and if it doesn't 
exist you can define it). So you could amend this patch like so:

  #if !defined(__has_builtin)
  #define __has_builtin(x) 0
  #endif
  
  #if __has_builtin(__builtin_bswap32)
  #define bswap_32(x) __builtin_bswap32(x)
  #elif _MSC_VER
  #define bswap_32(x) _byteswap_ulong(x)
  #else
  #include 
  #endif




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148541

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


[Lldb-commits] [lldb] 8456120 - Revert "[lldb] Add support for MSP430 in LLDB."

2023-04-17 Thread Anton Korobeynikov via lldb-commits

Author: Anton Korobeynikov
Date: 2023-04-17T11:30:27-07:00
New Revision: 845612062389e3defbe073119b481a5472e9fc36

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

LOG: Revert "[lldb] Add support for MSP430 in LLDB."

This reverts commit 82c02b733c7736507a41a26bebd37d3f8e88bd4e.

Apparently, the original patch was not rebased onto `main

Added: 


Modified: 
lldb/include/lldb/Utility/ArchSpec.h
lldb/include/lldb/Utility/DataExtractor.h
lldb/source/Expression/IRMemoryMap.cpp
lldb/source/Expression/LLVMUserExpression.cpp
lldb/source/Host/common/NativeProcessProtocol.cpp
lldb/source/Plugins/ABI/CMakeLists.txt
lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterFallback.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/source/Target/Platform.cpp
lldb/source/Utility/ArchSpec.cpp
lldb/unittests/Utility/ArchSpecTest.cpp

Removed: 
lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp
lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.h
lldb/source/Plugins/ABI/MSP430/CMakeLists.txt
lldb/test/API/functionalities/gdb_remote_client/TestMSP430MSPDebug.py
lldb/test/API/functionalities/gdb_remote_client/msp430.yaml



diff  --git a/lldb/include/lldb/Utility/ArchSpec.h 
b/lldb/include/lldb/Utility/ArchSpec.h
index 2de517d765b2a..444d427c1bd44 100644
--- a/lldb/include/lldb/Utility/ArchSpec.h
+++ b/lldb/include/lldb/Utility/ArchSpec.h
@@ -172,8 +172,6 @@ class ArchSpec {
 eCore_mips64r5el,
 eCore_mips64r6el,
 
-eCore_msp430,
-
 eCore_ppc_generic,
 eCore_ppc_ppc601,
 eCore_ppc_ppc602,

diff  --git a/lldb/include/lldb/Utility/DataExtractor.h 
b/lldb/include/lldb/Utility/DataExtractor.h
index 0b7e771ed4f86..dbf0bce8c8d0d 100644
--- a/lldb/include/lldb/Utility/DataExtractor.h
+++ b/lldb/include/lldb/Utility/DataExtractor.h
@@ -843,7 +843,9 @@ class DataExtractor {
   /// \param[in] addr_size
   /// The size in bytes to use when extracting addresses.
   void SetAddressByteSize(uint32_t addr_size) {
-assert(addr_size == 2 || addr_size == 4 || addr_size == 8);
+#ifdef LLDB_CONFIGURATION_DEBUG
+assert(addr_size == 4 || addr_size == 8);
+#endif
 m_addr_size = addr_size;
   }
 

diff  --git a/lldb/source/Expression/IRMemoryMap.cpp 
b/lldb/source/Expression/IRMemoryMap.cpp
index 951444db86a87..3c102dd4eaef1 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -96,21 +96,12 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
   // regions, walk forward through memory until a region is found that has
   // adequate space for our allocation.
   if (process_is_alive) {
-uint64_t end_of_memory;
-switch (process_sp->GetAddressByteSize()) {
-case 2:
-  end_of_memory = 0xull;
-  break;
-case 4:
-  end_of_memory = 0xull;
-  break;
-case 8:
-  end_of_memory = 0xull;
-  break;
-default:
-  lldbassert(false && "Invalid address size.");
-  return LLDB_INVALID_ADDRESS;
-}
+const uint64_t end_of_memory = process_sp->GetAddressByteSize() == 8
+   ? 0xull
+   : 0xull;
+
+lldbassert(process_sp->GetAddressByteSize() == 4 ||
+   end_of_memory != 0xull);
 
 MemoryRegionInfo region_info;
 Status err = process_sp->GetMemoryRegionInfo(ret, region_info);
@@ -146,31 +137,26 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
   // We've tried our algorithm, and it didn't work.  Now we have to reset back
   // to the end of the allocations we've already reported, or use a 'sensible'
   // default if this is our first allocation.
+
   if (m_allocations.empty()) {
 uint32_t address_byte_size = GetAddressByteSize();
 if (address_byte_size != UINT32_MAX) {
   switch (address_byte_size) {
-  case 2:
-ret = 0x8000ull;
+  case 8:
+ret = 0xdead0fffull;
 break;
   case 4:
 ret = 0xee00ull;
 break;
-  case 8:
-ret = 0xdead0fffull;
-break;
   default:
-lldbassert(false && "Invalid address size.");
-return LLDB_INVALID_ADDRESS;
+break;
   }
 }
   } else {
 auto back = m_allocations.rbegin();
 lldb::addr_t addr = back->first;
 size_t alloc_size = back->second.m_size;
-auto arch = target_sp->GetArchitecture().GetTriple().getArch();
-auto align = arch == llvm::Triple::msp430 ? 512 : 4096;
-ret = llvm::alignTo(addr + alloc_size, align);
+ret = llvm::alignTo(addr + alloc_size, 4096);
   }
 
   retur

[Lldb-commits] [PATCH] D146965: [lldb] Add support for MSP430 in LLDB.

2023-04-17 Thread Anton Korobeynikov via Phabricator via lldb-commits
asl added a comment.

@kuilpd

Please ensure that the patch is rebased into top of `main` and builds w/o 
errors / warnings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146965

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


[Lldb-commits] [PATCH] D148062: [lldb] Make ObjectFileJSON loadable as a module

2023-04-17 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

I didn't see this until now. I'll update the test. We shouldn't need strip for 
this test but we're sharing the Makefile for `SymbolFileJSON`. I'll see if it 
makes more sense to split up the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148062

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


[Lldb-commits] [PATCH] D148541: [lldb] fix build issue on MSVC because of missing byte-swap builtins

2023-04-17 Thread Ashay Rane via Phabricator via lldb-commits
ashay-github updated this revision to Diff 514341.
ashay-github added a comment.

Updated to check for builtins and use them, if available.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148541

Files:
  lldb/source/Core/DumpRegisterValue.cpp


Index: lldb/source/Core/DumpRegisterValue.cpp
===
--- lldb/source/Core/DumpRegisterValue.cpp
+++ lldb/source/Core/DumpRegisterValue.cpp
@@ -18,10 +18,24 @@
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private-types.h"
 
+#if !defined(__has_builtin)
+#define __has_builtin(x) 0
+#endif
+
+#if __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
+#define bswap_32(x) __builtin_bswap32(x)
+#define bswap_64(x) __builtin_bswap64(x)
+#elif defined(_MSC_VER)
+#define bswap_32(x) _byteswap_ulong(x)
+#define bswap_64(x) _byteswap_uint64(x)
+#else
+#include 
+#endif
+
 using namespace lldb;
 
-static uint32_t swap_value(uint32_t v) { return __builtin_bswap32(v); }
-static uint64_t swap_value(uint64_t v) { return __builtin_bswap64(v); }
+static uint32_t swap_value(uint32_t v) { return bswap_32(v); }
+static uint64_t swap_value(uint64_t v) { return bswap_64(v); }
 
 template 
 static void dump_type_value(lldb_private::CompilerType &fields_type, T value,


Index: lldb/source/Core/DumpRegisterValue.cpp
===
--- lldb/source/Core/DumpRegisterValue.cpp
+++ lldb/source/Core/DumpRegisterValue.cpp
@@ -18,10 +18,24 @@
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private-types.h"
 
+#if !defined(__has_builtin)
+#define __has_builtin(x) 0
+#endif
+
+#if __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
+#define bswap_32(x) __builtin_bswap32(x)
+#define bswap_64(x) __builtin_bswap64(x)
+#elif defined(_MSC_VER)
+#define bswap_32(x) _byteswap_ulong(x)
+#define bswap_64(x) _byteswap_uint64(x)
+#else
+#include 
+#endif
+
 using namespace lldb;
 
-static uint32_t swap_value(uint32_t v) { return __builtin_bswap32(v); }
-static uint64_t swap_value(uint64_t v) { return __builtin_bswap64(v); }
+static uint32_t swap_value(uint32_t v) { return bswap_32(v); }
+static uint64_t swap_value(uint64_t v) { return bswap_64(v); }
 
 template 
 static void dump_type_value(lldb_private::CompilerType &fields_type, T value,
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] f40ed1f - [lldb] Fix TestObjectFileJSON and TestSymbolFileJSON

2023-04-17 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2023-04-17T12:01:24-07:00
New Revision: f40ed1f619046e98d08b092b1afb835ed5156f52

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

LOG: [lldb] Fix TestObjectFileJSON and TestSymbolFileJSON

 - Separate the two test and only have TestSymbolFileJSON rely on strip.
 - Use different file names to make sure LLDB reloads the module.

This should address all the post commit review from D148062.

Added: 
lldb/test/API/functionalities/json/object-file/Makefile
lldb/test/API/functionalities/json/object-file/TestObjectFileJSON.py
lldb/test/API/functionalities/json/object-file/main.c
lldb/test/API/functionalities/json/symbol-file/Makefile
lldb/test/API/functionalities/json/symbol-file/TestSymbolFileJSON.py
lldb/test/API/functionalities/json/symbol-file/main.c

Modified: 


Removed: 
lldb/test/API/macosx/symbols/Makefile
lldb/test/API/macosx/symbols/TestObjectFileJSON.py
lldb/test/API/macosx/symbols/TestSymbolFileJSON.py
lldb/test/API/macosx/symbols/main.c



diff  --git a/lldb/test/API/functionalities/json/object-file/Makefile 
b/lldb/test/API/functionalities/json/object-file/Makefile
new file mode 100644
index 0..d78e8056f823e
--- /dev/null
+++ b/lldb/test/API/functionalities/json/object-file/Makefile
@@ -0,0 +1,5 @@
+C_SOURCES := main.c
+
+all: a.out
+
+include Makefile.rules

diff  --git a/lldb/test/API/macosx/symbols/TestObjectFileJSON.py 
b/lldb/test/API/functionalities/json/object-file/TestObjectFileJSON.py
similarity index 88%
rename from lldb/test/API/macosx/symbols/TestObjectFileJSON.py
rename to lldb/test/API/functionalities/json/object-file/TestObjectFileJSON.py
index 67d9f8e3c5d02..efb1aa2c3ad8a 100644
--- a/lldb/test/API/macosx/symbols/TestObjectFileJSON.py
+++ b/lldb/test/API/functionalities/json/object-file/TestObjectFileJSON.py
@@ -19,8 +19,7 @@ def setUp(self):
 
 def emitJSON(self, data, path):
 json_object = json.dumps(data, indent=4)
-json_object_file = self.getBuildArtifact("a.json")
-with open(json_object_file, "w") as outfile:
+with open(path, "w") as outfile:
 outfile.write(json_object)
 
 def toModuleSpec(self, path):
@@ -55,10 +54,10 @@ def test_module(self):
 "uuid": str(uuid.uuid4()),
 }
 
-json_object_file = self.getBuildArtifact("a.json")
-self.emitJSON(data, json_object_file)
+json_object_file_b = self.getBuildArtifact("b.json")
+self.emitJSON(data, json_object_file_b)
 
-module = target.AddModule(self.toModuleSpec(json_object_file))
+module = target.AddModule(self.toModuleSpec(json_object_file_b))
 self.assertFalse(module.IsValid())
 
 data = {
@@ -82,11 +81,10 @@ def test_module(self):
 ],
 }
 
-# Sleep to ensure the new file has a 
diff erent timestamp
-time.sleep(2)
-self.emitJSON(data, json_object_file)
+json_object_file_c = self.getBuildArtifact("c.json")
+self.emitJSON(data, json_object_file_c)
 
-module = target.AddModule(self.toModuleSpec(json_object_file))
+module = target.AddModule(self.toModuleSpec(json_object_file_c))
 self.assertTrue(module.IsValid())
 
 section = module.GetSectionAtIndex(0)

diff  --git a/lldb/test/API/macosx/symbols/main.c 
b/lldb/test/API/functionalities/json/object-file/main.c
similarity index 100%
rename from lldb/test/API/macosx/symbols/main.c
rename to lldb/test/API/functionalities/json/object-file/main.c

diff  --git a/lldb/test/API/macosx/symbols/Makefile 
b/lldb/test/API/functionalities/json/symbol-file/Makefile
similarity index 100%
rename from lldb/test/API/macosx/symbols/Makefile
rename to lldb/test/API/functionalities/json/symbol-file/Makefile

diff  --git a/lldb/test/API/macosx/symbols/TestSymbolFileJSON.py 
b/lldb/test/API/functionalities/json/symbol-file/TestSymbolFileJSON.py
similarity index 100%
rename from lldb/test/API/macosx/symbols/TestSymbolFileJSON.py
rename to lldb/test/API/functionalities/json/symbol-file/TestSymbolFileJSON.py

diff  --git a/lldb/test/API/functionalities/json/symbol-file/main.c 
b/lldb/test/API/functionalities/json/symbol-file/main.c
new file mode 100644
index 0..88653f66d7153
--- /dev/null
+++ b/lldb/test/API/functionalities/json/symbol-file/main.c
@@ -0,0 +1,2 @@
+int foo() { return 1; }
+int main() { return foo(); }



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


[Lldb-commits] [PATCH] D148541: [lldb] fix build issue on MSVC because of missing byte-swap builtins

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148541

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


[Lldb-commits] [lldb] 7978abd - [lldb] fix build issue on MSVC because of missing byte-swap builtins

2023-04-17 Thread Ashay Rane via lldb-commits

Author: Ashay Rane
Date: 2023-04-17T14:39:00-05:00
New Revision: 7978abd5aef1ba84d7a1cefbc3443245acff2c48

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

LOG: [lldb] fix build issue on MSVC because of missing byte-swap builtins

The `__builtin_bswap{32,64}()` builtins (introduced in commit e07a421d)
are missing from MSVC, which causes build errors when compiling LLDB on
Windows (tested with MSVC 19.34.31943.0).  This patch replaces the
builtins with either MSVC's `_byteswap_u{long,64}()` or the original
builtins, or the `bswap_{32,64}()` functions from byteswap.h, depending
on which ones are available.

Reviewed By: bulbazord

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

Added: 


Modified: 
lldb/source/Core/DumpRegisterValue.cpp

Removed: 




diff  --git a/lldb/source/Core/DumpRegisterValue.cpp 
b/lldb/source/Core/DumpRegisterValue.cpp
index 0e85e8e9ea893..3e59fb13b8cad 100644
--- a/lldb/source/Core/DumpRegisterValue.cpp
+++ b/lldb/source/Core/DumpRegisterValue.cpp
@@ -18,10 +18,24 @@
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private-types.h"
 
+#if !defined(__has_builtin)
+#define __has_builtin(x) 0
+#endif
+
+#if __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
+#define bswap_32(x) __builtin_bswap32(x)
+#define bswap_64(x) __builtin_bswap64(x)
+#elif defined(_MSC_VER)
+#define bswap_32(x) _byteswap_ulong(x)
+#define bswap_64(x) _byteswap_uint64(x)
+#else
+#include 
+#endif
+
 using namespace lldb;
 
-static uint32_t swap_value(uint32_t v) { return __builtin_bswap32(v); }
-static uint64_t swap_value(uint64_t v) { return __builtin_bswap64(v); }
+static uint32_t swap_value(uint32_t v) { return bswap_32(v); }
+static uint64_t swap_value(uint64_t v) { return bswap_64(v); }
 
 template 
 static void dump_type_value(lldb_private::CompilerType &fields_type, T value,



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


[Lldb-commits] [PATCH] D148541: [lldb] fix build issue on MSVC because of missing byte-swap builtins

2023-04-17 Thread Ashay Rane via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7978abd5aef1: [lldb] fix build issue on MSVC because of 
missing byte-swap builtins (authored by ashay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148541

Files:
  lldb/source/Core/DumpRegisterValue.cpp


Index: lldb/source/Core/DumpRegisterValue.cpp
===
--- lldb/source/Core/DumpRegisterValue.cpp
+++ lldb/source/Core/DumpRegisterValue.cpp
@@ -18,10 +18,24 @@
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private-types.h"
 
+#if !defined(__has_builtin)
+#define __has_builtin(x) 0
+#endif
+
+#if __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
+#define bswap_32(x) __builtin_bswap32(x)
+#define bswap_64(x) __builtin_bswap64(x)
+#elif defined(_MSC_VER)
+#define bswap_32(x) _byteswap_ulong(x)
+#define bswap_64(x) _byteswap_uint64(x)
+#else
+#include 
+#endif
+
 using namespace lldb;
 
-static uint32_t swap_value(uint32_t v) { return __builtin_bswap32(v); }
-static uint64_t swap_value(uint64_t v) { return __builtin_bswap64(v); }
+static uint32_t swap_value(uint32_t v) { return bswap_32(v); }
+static uint64_t swap_value(uint64_t v) { return bswap_64(v); }
 
 template 
 static void dump_type_value(lldb_private::CompilerType &fields_type, T value,


Index: lldb/source/Core/DumpRegisterValue.cpp
===
--- lldb/source/Core/DumpRegisterValue.cpp
+++ lldb/source/Core/DumpRegisterValue.cpp
@@ -18,10 +18,24 @@
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private-types.h"
 
+#if !defined(__has_builtin)
+#define __has_builtin(x) 0
+#endif
+
+#if __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
+#define bswap_32(x) __builtin_bswap32(x)
+#define bswap_64(x) __builtin_bswap64(x)
+#elif defined(_MSC_VER)
+#define bswap_32(x) _byteswap_ulong(x)
+#define bswap_64(x) _byteswap_uint64(x)
+#else
+#include 
+#endif
+
 using namespace lldb;
 
-static uint32_t swap_value(uint32_t v) { return __builtin_bswap32(v); }
-static uint64_t swap_value(uint64_t v) { return __builtin_bswap64(v); }
+static uint32_t swap_value(uint32_t v) { return bswap_32(v); }
+static uint64_t swap_value(uint64_t v) { return bswap_64(v); }
 
 template 
 static void dump_type_value(lldb_private::CompilerType &fields_type, T value,
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D148397: [lldb/Utility] Add opt-in passthrough mode to event listeners

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



Comment at: lldb/include/lldb/Utility/Broadcaster.h:520-522
+/// A optional listener that all private events get also broadcasted to,
+/// on top the hijacked / default listeners.
+lldb::ListenerSP m_passthrough_listener = nullptr;

It looks like Broadcaster can have multiple listeners. Do we want multiple 
passthrough listeners as well? If not, why only one?



Comment at: lldb/source/API/SBAttachInfo.cpp:260
+
+  return SBListener(m_opaque_sp->GetPassthroughListener());
+}

`GetPassthroughListener` can return `nullptr`. I think you want to take 
advantage of the protected `SBListener(const ListenerSP &)` constructor here 
but I think that if `GetPassthroughListener` returns `nullptr` you'll end up 
calling the constructor `SBListener(const char *)`. I don't think this is what 
you want.



Comment at: lldb/source/API/SBLaunchInfo.cpp:395
+
+  return SBListener(m_opaque_sp->GetPassthroughListener());
+}

Same issue as `SBAttachInfo::GetPassthroughListener`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148397

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


[Lldb-commits] [PATCH] D148399: [lldb] Improve logging for process state change (NFC)

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

+1 to what Jonas said. `LLDB_LOG` would greatly simplify this since it puts 
`__FILE__` and `__func__` in each message, which is what these are doing 
manually.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148399

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


[Lldb-commits] [PATCH] D148400: [lldb] Fix bug to update process public run lock with process state

2023-04-17 Thread Alex Langford via Phabricator via lldb-commits
bulbazord requested changes to this revision.
bulbazord added a comment.
This revision now requires changes to proceed.

Idea is good, few concerns about the implementation.




Comment at: lldb/source/Target/Process.cpp:404-419
+llvm::StringRef Process::GetAttachSynchronousHijackListenerName() {
+  static ConstString class_name(
+  "lldb.internal.Process.AttachSynchronous.hijack");
+  return class_name.GetCString();
+}
+
+llvm::StringRef Process::GetLaunchSynchronousHijackListenerName() {

Do these need to be ConstStrings? They will live in the string pool forever, 
and it looks like in the code below you're just manipulating `const char *` 
anyway.

Could be something like:
```
llvm::StringRef Process::GetAttachSynchronousHijackListenerName() {
  return "lldb.internal.Process.AttachSynchronous.hijack";
}
```



Comment at: lldb/source/Target/Process.cpp:1427
 if (hijacking_name &&
-strcmp(hijacking_name, g_resume_sync_name))
+strstr(hijacking_name, "lldb.internal") != hijacking_name)
   return true;

Instead of using the `strstr` function directly, I would at least do `strnstr` 
to ensure that we're not touching memory we don't have. Especially if we could 
get `hijacking_name` to be shorter than `"lldb.internal"` somehow...

We could also change this to use StringRefs and use the 
`starts_with`/`startswith` methods instead.



Comment at: lldb/source/Target/Process.cpp:1437-1438
 if (hijacking_name &&
-strcmp(hijacking_name, g_resume_sync_name) == 0)
+strcmp(hijacking_name,
+   GetResumeSynchronousHijackListenerName().data()) == 0)
   return true;

First, I would probably avoid `strcmp` directly and use `strncmp` instead. We 
know the length of the HijackListener name, that would be a good choice for `n` 
here.

But you could probably simplify this even further. You can compare 
`GetResumeSynchronousHijackListenerName` to `hijacking_name` with StringRef's 
operator==. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148400

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


[Lldb-commits] [PATCH] D145296: [lldb/Plugin] Add breakpoint setting support to ScriptedProcesses.

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

Seems ok to me, one small thought. Shouldn't hold this patch up though.




Comment at: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp:270-271
 
+Status ScriptedProcess::EnableBreakpointSite(BreakpointSite *bp_site) {
+  assert(bp_site != nullptr);
+

I like the assert, but I can't help but wonder if we should change the 
signature of this method? Something like `EnableBreakpointSite(BreakpointSite 
&bp_site)` or something like this... Seems like the other overrides assume that 
it is not nullptr before using it and all the callsites verify it before 
calling it too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145296

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


[Lldb-commits] [PATCH] D148401: [lldb/API] Add convenience constructor for SBError (NFC)

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

I like this! Reading through the call stack, it looks like we shouldn't hit any 
issues if `message` is `nullptr`. Could you add a small test to 
`TestSBError.py` constructing an error with a message directly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148401

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


[Lldb-commits] [PATCH] D148401: [lldb/API] Add convenience constructor for SBError (NFC)

2023-04-17 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

In D148401#4275398 , @bulbazord wrote:

> I like this! Reading through the call stack, it looks like we shouldn't hit 
> any issues if `message` is `nullptr`. Could you add a small test to 
> `TestSBError.py` constructing an error with a message directly?

Yep, we create the underlying status object if the opaque ptr is null. Will add 
a test case :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148401

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


[Lldb-commits] [PATCH] D148546: Reland: [Demangle] replace use of llvm::StringView w/ std::string_view

2023-04-17 Thread Nick Desaulniers via Phabricator via lldb-commits
nickdesaulniers updated this revision to Diff 514386.
nickdesaulniers added a comment.

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148546

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  llvm/include/llvm/Demangle/ItaniumDemangle.h
  llvm/include/llvm/Demangle/MicrosoftDemangle.h
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/include/llvm/Demangle/Utility.h
  llvm/lib/Demangle/DLangDemangle.cpp
  llvm/lib/Demangle/ItaniumDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/lib/Demangle/RustDemangle.cpp
  llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
  llvm/unittests/Demangle/ItaniumDemangleTest.cpp
  llvm/unittests/Demangle/OutputBufferTest.cpp

Index: llvm/unittests/Demangle/OutputBufferTest.cpp
===
--- llvm/unittests/Demangle/OutputBufferTest.cpp
+++ llvm/unittests/Demangle/OutputBufferTest.cpp
@@ -10,12 +10,13 @@
 #include "llvm/Demangle/Utility.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 
 using namespace llvm;
 using llvm::itanium_demangle::OutputBuffer;
 
 static std::string toString(OutputBuffer &OB) {
-  StringView SV = OB;
+  std::string_view SV = OB;
   return {SV.begin(), SV.end()};
 }
 
Index: llvm/unittests/Demangle/ItaniumDemangleTest.cpp
===
--- llvm/unittests/Demangle/ItaniumDemangleTest.cpp
+++ llvm/unittests/Demangle/ItaniumDemangleTest.cpp
@@ -11,6 +11,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 
 using namespace llvm;
@@ -83,7 +84,7 @@
 }
 
 static std::string toString(OutputBuffer &OB) {
-  StringView SV = OB;
+  std::string_view SV = OB;
   return {SV.begin(), SV.end()};
 }
 
@@ -98,7 +99,7 @@
   OutputBuffer OB;
   Node *N = AbstractManglingParser::parseType();
   N->printLeft(OB);
-  StringView Name = N->getBaseName();
+  std::string_view Name = N->getBaseName();
   if (!Name.empty())
 Types.push_back(std::string(Name.begin(), Name.end()));
   else
Index: llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
===
--- llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
+++ llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
@@ -17,13 +17,12 @@
 using llvm::itanium_demangle::ForwardTemplateReference;
 using llvm::itanium_demangle::Node;
 using llvm::itanium_demangle::NodeKind;
-using llvm::itanium_demangle::StringView;
 
 namespace {
 struct FoldingSetNodeIDBuilder {
   llvm::FoldingSetNodeID &ID;
   void operator()(const Node *P) { ID.AddPointer(P); }
-  void operator()(StringView Str) {
+  void operator()(std::string_view Str) {
 ID.AddString(llvm::StringRef(Str.begin(), Str.size()));
   }
   template 
@@ -292,7 +291,7 @@
 N = Demangler.parse();
   else
 N = Demangler.make(
-StringView(Mangling.data(), Mangling.size()));
+std::string_view(Mangling.data(), Mangling.size()));
   return reinterpret_cast(N);
 }
 
Index: llvm/lib/Demangle/RustDemangle.cpp
===
--- llvm/lib/Demangle/RustDemangle.cpp
+++ llvm/lib/Demangle/RustDemangle.cpp
@@ -12,7 +12,7 @@
 //===--===//
 
 #include "llvm/Demangle/Demangle.h"
-#include "llvm/Demangle/StringView.h"
+#include "llvm/Demangle/StringViewExtras.h"
 #include "llvm/Demangle/Utility.h"
 
 #include 
@@ -25,12 +25,11 @@
 
 using llvm::itanium_demangle::OutputBuffer;
 using llvm::itanium_demangle::ScopedOverride;
-using llvm::itanium_demangle::StringView;
 
 namespace {
 
 struct Identifier {
-  StringView Name;
+  std::string_view Name;
   bool Punycode;
 
   bool empty() const { return Name.empty(); }
@@ -77,7 +76,7 @@
   size_t RecursionLevel;
   size_t BoundLifetimes;
   // Input string that is being demangled with "_R" prefix removed.
-  StringView Input;
+  std::string_view Input;
   // Position in the input string.
   size_t Position;
   // When true, print methods append the output to the stream.
@@ -92,7 +91,7 @@
 
   Demangler(size_t MaxRecursionLevel = 500);
 
-  bool demangle(StringView MangledName);
+  bool demangle(std::string_view MangledName);
 
 private:
   bool demanglePath(IsInType Type,
@@ -128,10 +127,10 @@
   uint64_t parseOptionalBase62Number(char Tag);
   uint64_t parseBase62Number();
   uint64_t parseDecimalNumber();
-  uint64_t parseHexNumber(StringView &HexDigits);
+  uint64_t parseHexNumber(std::string_view &HexDigits);
 
   void print(char C);
-  void print(StringView S);
+  void print(std::string_view S);
   void printDecimalNumber(uint64_t N);
   void printBasicType(BasicType);
   void printLifetime(uint64_t Index);
@@ -152

[Lldb-commits] [lldb] 1414a5b - [lldb][DataFormatter] Fix libcxx std::deque formatter for references and pointers

2023-04-17 Thread Michael Buch via lldb-commits

Author: Michael Buch
Date: 2023-04-17T21:31:30+01:00
New Revision: 1414a5bdfeff3dbbbaae9816ef4017c81112c3c0

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

LOG: [lldb][DataFormatter] Fix libcxx std::deque formatter for references and 
pointers

(Addresses GH#62153)

The `SBType` APIs to retrieve details about template arguments,
such as `GetTemplateArgumentType` or `GetTemplateArgumentKind`
don't "desugar" LValueReferences/RValueReferences or pointers.
So when we try to format a `std::deque&`, the python call to
`GetTemplateArgumentType` fails to get a type, leading to
an `element_size` of `0` and a division-by-zero python exception
(which gets caught by the summary provider silently). This leads
to the contents of such `std::deque&` to be printed incorrectly.

This patch dereferences the reference/pointer before calling
into the above SBAPIs.

**Testing**

* Add API test

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

Added: 

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/Makefile

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/main.cpp

Modified: 
lldb/examples/synthetic/libcxx.py

Removed: 




diff  --git a/lldb/examples/synthetic/libcxx.py 
b/lldb/examples/synthetic/libcxx.py
index 531d26784afc2..eb26829e2ed02 100644
--- a/lldb/examples/synthetic/libcxx.py
+++ b/lldb/examples/synthetic/libcxx.py
@@ -649,7 +649,12 @@ def __init__(self, valobj, d):
 def find_block_size(self):
 # in order to use the deque we must have the block size, or else
 # it's impossible to know what memory addresses are valid
-self.element_type = self.valobj.GetType().GetTemplateArgumentType(0)
+obj_type = self.valobj.GetType()
+if obj_type.IsReferenceType():
+obj_type = obj_type.GetDereferencedType()
+elif obj_type.IsPointerType():
+obj_type = obj_type.GetPointeeType()
+self.element_type = obj_type.GetTemplateArgumentType(0)
 self.element_size = self.element_type.GetByteSize()
 # The code says this, but there must be a better way:
 # template 

diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/Makefile
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/Makefile
new file mode 100644
index 0..c5ac05605bdcb
--- /dev/null
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/Makefile
@@ -0,0 +1,4 @@
+USE_LIBCPP := 1
+CXX_SOURCES := main.cpp
+
+include Makefile.rules

diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
new file mode 100644
index 0..9d4c25e44ca95
--- /dev/null
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
@@ -0,0 +1,75 @@
+"""
+Test LLDB's data formatter for libcxx's std::deque.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class LibcxxDequeDataFormatterTestCase(TestBase):
+
+def check_numbers(self, var_name):
+self.expect("frame variable " + var_name,
+substrs=[var_name + ' = size=7',
+ '[0] = 1',
+ '[1] = 12',
+ '[2] = 123',
+ '[3] = 1234',
+ '[4] = 12345',
+ '[5] = 123456',
+ '[6] = 1234567',
+ '}'])
+
+self.expect_expr(var_name, result_summary="size=7", result_children=[
+ValueCheck(value="1"),
+ValueCheck(value="12"),
+ValueCheck(value="123"),
+ValueCheck(value="1234"),
+ValueCheck(value="12345"),
+ValueCheck(value="123456"),
+ValueCheck(value="1234567"),
+])
+
+@add_test_categories(["libc++"])
+def test_with_run_command(self):
+"""Test basic formatting of std::deque"""
+self.build()
+(self.target, process, thread, bkpt) = 
lldbutil.run_to_source_breakpoint(
+self, "break here", lldb.SBFileSpec("main.cpp", False))
+
+self.expect("frame variable numbers",
+substrs=['numbers = size=0'])
+
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+# first value added
+self.expect("frame variabl

[Lldb-commits] [PATCH] D148531: [lldb][DataFormatter] Fix libcxx std::deque formatter for references and pointers

2023-04-17 Thread Michael Buch via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1414a5bdfeff: [lldb][DataFormatter] Fix libcxx std::deque 
formatter for references and… (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148531

Files:
  lldb/examples/synthetic/libcxx.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/main.cpp

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/main.cpp
@@ -0,0 +1,30 @@
+#include 
+#include 
+typedef std::deque int_deq;
+
+void by_ref_and_ptr(std::deque &ref, std::deque *ptr) {
+  printf("stop here");
+  return;
+}
+
+int main() {
+  int_deq numbers;
+  printf("break here");
+
+  (numbers.push_back(1));
+  printf("break here");
+
+  (numbers.push_back(12));
+  (numbers.push_back(123));
+  (numbers.push_back(1234));
+  (numbers.push_back(12345));
+  (numbers.push_back(123456));
+  (numbers.push_back(1234567));
+  by_ref_and_ptr(numbers, &numbers);
+  printf("break here");
+
+  numbers.clear();
+  printf("break here");
+
+  return 0;
+}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py
@@ -0,0 +1,75 @@
+"""
+Test LLDB's data formatter for libcxx's std::deque.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class LibcxxDequeDataFormatterTestCase(TestBase):
+
+def check_numbers(self, var_name):
+self.expect("frame variable " + var_name,
+substrs=[var_name + ' = size=7',
+ '[0] = 1',
+ '[1] = 12',
+ '[2] = 123',
+ '[3] = 1234',
+ '[4] = 12345',
+ '[5] = 123456',
+ '[6] = 1234567',
+ '}'])
+
+self.expect_expr(var_name, result_summary="size=7", result_children=[
+ValueCheck(value="1"),
+ValueCheck(value="12"),
+ValueCheck(value="123"),
+ValueCheck(value="1234"),
+ValueCheck(value="12345"),
+ValueCheck(value="123456"),
+ValueCheck(value="1234567"),
+])
+
+@add_test_categories(["libc++"])
+def test_with_run_command(self):
+"""Test basic formatting of std::deque"""
+self.build()
+(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, "break here", lldb.SBFileSpec("main.cpp", False))
+
+self.expect("frame variable numbers",
+substrs=['numbers = size=0'])
+
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+# first value added
+self.expect("frame variable numbers",
+substrs=['numbers = size=1',
+ '[0] = 1',
+ '}'])
+
+# add remaining values
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+self.check_numbers("numbers")
+
+# clear out the deque
+lldbutil.continue_to_breakpoint(process, bkpt)
+
+self.expect("frame variable numbers",
+substrs=['numbers = size=0'])
+
+@add_test_categories(["libc++"])
+def test_ref_and_ptr(self):
+"""Test formatting of std::deque& and std::deque*"""
+self.build()
+(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, "stop here", lldb.SBFileSpec("main.cpp", False))
+
+# The reference should display the same was as the value did
+self.check_numbers("ref")
+
+# The pointer should just show the right number of elements:
+self.expect("frame variable ptr", substrs=['ptr =', ' size=7'])
+self.expect("expression ptr", substrs=['$', 'size=7'])
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/Makefile
@@ -0,0 +1,4 @@
+USE_LIBCPP := 1
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/examples/synthetic/libcxx.py
=

[Lldb-commits] [PATCH] D148384: [Demangle] replace use of llvm::StringView w/ std::string_view

2023-04-17 Thread Nick Desaulniers via Phabricator via lldb-commits
nickdesaulniers closed this revision.
nickdesaulniers added a comment.

Let's use D148546  as the reland (sorry, 
couldn't get arcanist to work to reuse this instance of code review reopened).


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

https://reviews.llvm.org/D148384

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


[Lldb-commits] [PATCH] D145296: [lldb/Plugin] Add breakpoint setting support to ScriptedProcesses.

2023-04-17 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp:270-271
 
+Status ScriptedProcess::EnableBreakpointSite(BreakpointSite *bp_site) {
+  assert(bp_site != nullptr);
+

bulbazord wrote:
> I like the assert, but I can't help but wonder if we should change the 
> signature of this method? Something like `EnableBreakpointSite(BreakpointSite 
> &bp_site)` or something like this... Seems like the other overrides assume 
> that it is not nullptr before using it and all the callsites verify it before 
> calling it too.
+1. I wondered the same thing when looking at the header. 



Comment at: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp:281
+
+  return EnableSoftwareBreakpoint(bp_site);
+}

The same applies to `Process::EnableSoftwareBreakpoint` as well. It also has an 
assert and seems like it should just be checked in the caller and enforced by 
using a reference. 



Comment at: lldb/source/Plugins/Process/scripted/ScriptedProcess.h:75
 
+  Status EnableBreakpointSite(BreakpointSite *bp_site) override;
+

Should this take a reference instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145296

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


[Lldb-commits] [PATCH] D148401: [lldb/API] Add convenience constructor for SBError (NFC)

2023-04-17 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/include/lldb/API/SBError.h:26
 
+  SBError(const char *message);
+

Why not a StringRef?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148401

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


[Lldb-commits] [PATCH] D148401: [lldb/API] Add convenience constructor for SBError (NFC)

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



Comment at: lldb/include/lldb/API/SBError.h:26
 
+  SBError(const char *message);
+

JDevlieghere wrote:
> Why not a StringRef?
I'm not sure we have `StringRef` type map in swig? We would have to create one 
for swig to pick up on it correctly, no?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148401

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


[Lldb-commits] [PATCH] D148401: [lldb/API] Add convenience constructor for SBError (NFC)

2023-04-17 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added inline comments.



Comment at: lldb/include/lldb/API/SBError.h:26
 
+  SBError(const char *message);
+

bulbazord wrote:
> JDevlieghere wrote:
> > Why not a StringRef?
> I'm not sure we have `StringRef` type map in swig? We would have to create 
> one for swig to pick up on it correctly, no?
+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148401

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


[Lldb-commits] [PATCH] D145297: [lldb] Add an example of interactive scripted process debugging

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

A few high-level comments:

- You're doing a lot of type-annotations in python which is good, but you're 
not being very consistent about it. It would be tremendously helpful if you 
could add type annotations everywhere.
- I would recommend using f-strings over `%` and `.format` for string 
interpolation. They are available as of python 3.6 and the minimum version to 
use `lit` is 3.6 (if LLVM's CMakeLists.txt is to be believed).






Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py:2
+"""
+Test the functionality of scripted processes
+"""

nit



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py:8
+from lldbsuite.test.lldbtest import *
+import os
+

nit: import json



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py:54
+
+mux_class = self.script_module + "." + "MultiplexerScriptedProcess"
+script_dict = {'driving_target_idx' : real_target_id}





Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py:60-61
+
+self.runCmd("log enable lldb state -f /tmp/state.log")
+# self.runCmd("log enable lldb event -f /tmp/event.log")
+self.dbg.SetAsync(True)

Remove these log lines, I don't think they're needed for the test.



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py:89
+self.assertEqual(len(real_process.threads), len(mux_process.threads), 
"Same number of threads")
+for id in range(0, len(real_process.threads)):
+real_pc = real_process.threads[id].frame[0].pc

Defaults to 0 if you don't specify a start.



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py:102-103
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), 
lldb.eStateRunning)
+event = lldbutil.fetch_next_event(self, mux_process_listener, 
mux_process.GetBroadcaster())
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), 
lldb.eStateStopped)
+

Did you mean to get info from the `mux_process_listener` twice? Was one of 
these supposed to be for the real process?



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:9
+
+import os,json,struct,signal
+import time

nit: import these all on different lines



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:74-89
+def write_memory_at_address(self, addr, data, error):
+return self.driving_process.WriteMemory(addr,
+bytearray(data.uint8.all()),
+error)
+
+def get_loaded_images(self):
+return self.loaded_images

Some functions have their parameter types and return types annotated but others 
don't. Can you add all the annotations to be consistent?



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:89
+def get_scripted_thread_plugin(self):
+return PassthruScriptedThread.__module__ + "." + 
PassthruScriptedThread.__name__
+





Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:132
+def get_scripted_thread_plugin(self):
+return MultiplexedScriptedThread.__module__ + "." + 
MultiplexedScriptedThread.__name__
+





Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:165
+def get_name(self) -> str:
+return PassthruScriptedThread.__name__ + ".thread-" + str(self.idx)
+





Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:168
+def get_stop_reason(self) -> Dict[str, Any]:
+stop_reason = { "type": lldb.eStopReasonInvalid, "data": {  }}
+





Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:204
+
+return struct.pack("{}Q".format(len(self.register_ctx)), 
*self.register_ctx.values())
+





Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:209
+parity = "Odd" if self.scripted_process.parity % 2 else "Even"
+return parity + MultiplexedScriptedThread.__name__ + ".thread-" + 
str(self.idx)
+




=

[Lldb-commits] [PATCH] D148548: [lldb] Improve breakpoint management for interactive scripted process

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

Seems okay to me, but it's a little messy that we're having to manage 
breakpoints like this.




Comment at: lldb/bindings/interface/SBTargetExtensions.i:144-171
+class watchpoints_access(object):
+'''A helper object that will lazily hand out watchpoints for a 
target when supplied an index.'''
+def __init__(self, sbtarget):
+self.sbtarget = sbtarget
+
+def __len__(self):
+if self.sbtarget:

Are these used at all?



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:269-278
+bkpt_file = lldb.SBFileSpec(tf.name)
+error = self.driving_target.BreakpointsWriteToFile(bkpt_file)
+if error.Fail():
+log("Failed to save breakpoints from driving target (%s)"
+% error.GetCString())
+bkpts_list = lldb.SBBreakpointList(self.target)
+error = self.target.BreakpointsCreateFromFile(bkpt_file, 
bkpts_list)

It's interesting that we dump to a file. It'd be cool if we could dump it to a 
StructuredData or something instead of a file.



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:282
+if error.Success():
+self.driving_target.DeleteAllBreakpoints()
+for bkpt in self.target.breakpoints:

Why do we delete all of the breakpoints just to re-set them afterwards? Is 
there a difference between what we set and what was there before?


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

https://reviews.llvm.org/D148548

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


[Lldb-commits] [PATCH] D148548: [lldb] Improve breakpoint management for interactive scripted process

2023-04-17 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

In D148548#4275567 , @bulbazord wrote:

> Seems okay to me, but it's a little messy that we're having to manage 
> breakpoints like this.

I don't think there is a better way to do this, as breakpoint are managed per 
target but we're actually trying to copy them from one target to another. Let 
me know if you can think of another of doing it


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

https://reviews.llvm.org/D148548

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


[Lldb-commits] [PATCH] D148548: [lldb] Improve breakpoint management for interactive scripted process

2023-04-17 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked 3 inline comments as done.
mib added inline comments.



Comment at: lldb/bindings/interface/SBTargetExtensions.i:144-171
+class watchpoints_access(object):
+'''A helper object that will lazily hand out watchpoints for a 
target when supplied an index.'''
+def __init__(self, sbtarget):
+self.sbtarget = sbtarget
+
+def __len__(self):
+if self.sbtarget:

bulbazord wrote:
> Are these used at all?
Not in this patch but I feel like it should be implemented already and this 
goes along with the breakpoint accessors and iterator.



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:269-278
+bkpt_file = lldb.SBFileSpec(tf.name)
+error = self.driving_target.BreakpointsWriteToFile(bkpt_file)
+if error.Fail():
+log("Failed to save breakpoints from driving target (%s)"
+% error.GetCString())
+bkpts_list = lldb.SBBreakpointList(self.target)
+error = self.target.BreakpointsCreateFromFile(bkpt_file, 
bkpts_list)

bulbazord wrote:
> It's interesting that we dump to a file. It'd be cool if we could dump it to 
> a StructuredData or something instead of a file.
100% agree, I'll do that as a followup.



Comment at: 
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py:282
+if error.Success():
+self.driving_target.DeleteAllBreakpoints()
+for bkpt in self.target.breakpoints:

bulbazord wrote:
> Why do we delete all of the breakpoints just to re-set them afterwards? Is 
> there a difference between what we set and what was there before?
There could be: Let's say the user set a breakpoint on the driving target (A) 
and a different one on the multiplexer target (B). We need first to copy all 
the driving target breakpoints to the multiplexer target, delete them and copy 
back all the multiplexer target breakpoints (A + B) to the driving target, to 
keep them in sync.


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

https://reviews.llvm.org/D148548

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


[Lldb-commits] [PATCH] D148401: [lldb/API] Add convenience constructor for SBError (NFC)

2023-04-17 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added inline comments.



Comment at: lldb/include/lldb/API/SBError.h:26
 
+  SBError(const char *message);
+

mib wrote:
> bulbazord wrote:
> > JDevlieghere wrote:
> > > Why not a StringRef?
> > I'm not sure we have `StringRef` type map in swig? We would have to create 
> > one for swig to pick up on it correctly, no?
> +1
Yeah nvm, I got Status and SBError confused. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148401

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


[Lldb-commits] [lldb] 43ac269 - [lldb] Lock accesses to PathMappingLists's internals

2023-04-17 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-04-17T14:48:16-07:00
New Revision: 43ac269bdd00d709005f8f3550db6b657b2bf940

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

LOG: [lldb] Lock accesses to PathMappingLists's internals

This class is not safe in multithreaded code. It's possible for one
thread to modify a PathMappingList's `m_pair` vector while another
thread is iterating over it, effectively invalidating the iterator and
potentially leading to crashes or other difficult-to-diagnose bugs.

rdar://107695786

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

Added: 


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

Removed: 




diff  --git a/lldb/include/lldb/Target/PathMappingList.h 
b/lldb/include/lldb/Target/PathMappingList.h
index 447fb43f4d6dc..283452288734e 100644
--- a/lldb/include/lldb/Target/PathMappingList.h
+++ b/lldb/include/lldb/Target/PathMappingList.h
@@ -13,6 +13,7 @@
 #include "lldb/Utility/Status.h"
 #include "llvm/Support/JSON.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -50,9 +51,15 @@ class PathMappingList {
 
   llvm::json::Value ToJSON();
 
-  bool IsEmpty() const { return m_pairs.empty(); }
+  bool IsEmpty() const {
+std::lock_guard lock(m_mutex);
+return m_pairs.empty();
+  }
 
-  size_t GetSize() const { return m_pairs.size(); }
+  size_t GetSize() const {
+std::lock_guard lock(m_mutex);
+return m_pairs.size();
+  }
 
   bool GetPathsAtIndex(uint32_t idx, ConstString &path,
ConstString &new_path) const;
@@ -128,9 +135,13 @@ class PathMappingList {
 
   uint32_t FindIndexForPath(llvm::StringRef path) const;
 
-  uint32_t GetModificationID() const { return m_mod_id; }
+  uint32_t GetModificationID() const {
+std::lock_guard lock(m_mutex);
+return m_mod_id;
+  }
 
 protected:
+  mutable std::recursive_mutex m_mutex;
   typedef std::pair pair;
   typedef std::vector collection;
   typedef collection::iterator iterator;

diff  --git a/lldb/source/Target/PathMappingList.cpp 
b/lldb/source/Target/PathMappingList.cpp
index 13bb50b362c6f..4efc0bf16c6d2 100644
--- a/lldb/source/Target/PathMappingList.cpp
+++ b/lldb/source/Target/PathMappingList.cpp
@@ -48,6 +48,7 @@ PathMappingList::PathMappingList(const PathMappingList &rhs)
 
 const PathMappingList &PathMappingList::operator=(const PathMappingList &rhs) {
   if (this != &rhs) {
+std::scoped_lock locks(m_mutex, rhs.m_mutex);
 m_pairs = rhs.m_pairs;
 m_callback = nullptr;
 m_callback_baton = nullptr;
@@ -60,6 +61,7 @@ PathMappingList::~PathMappingList() = default;
 
 void PathMappingList::Append(llvm::StringRef path, llvm::StringRef replacement,
  bool notify) {
+  std::lock_guard lock(m_mutex);
   ++m_mod_id;
   m_pairs.emplace_back(pair(NormalizePath(path), NormalizePath(replacement)));
   if (notify && m_callback)
@@ -67,6 +69,7 @@ void PathMappingList::Append(llvm::StringRef path, 
llvm::StringRef replacement,
 }
 
 void PathMappingList::Append(const PathMappingList &rhs, bool notify) {
+  std::scoped_lock locks(m_mutex, rhs.m_mutex);
   ++m_mod_id;
   if (!rhs.m_pairs.empty()) {
 const_iterator pos, end = rhs.m_pairs.end();
@@ -81,6 +84,7 @@ bool PathMappingList::AppendUnique(llvm::StringRef path,
llvm::StringRef replacement, bool notify) {
   auto normalized_path = NormalizePath(path);
   auto normalized_replacement = NormalizePath(replacement);
+  std::lock_guard lock(m_mutex);
   for (const auto &pair : m_pairs) {
 if (pair.first.GetStringRef().equals(normalized_path) &&
 pair.second.GetStringRef().equals(normalized_replacement))
@@ -92,6 +96,7 @@ bool PathMappingList::AppendUnique(llvm::StringRef path,
 
 void PathMappingList::Insert(llvm::StringRef path, llvm::StringRef replacement,
  uint32_t index, bool notify) {
+  std::lock_guard lock(m_mutex);
   ++m_mod_id;
   iterator insert_iter;
   if (index >= m_pairs.size())
@@ -106,6 +111,7 @@ void PathMappingList::Insert(llvm::StringRef path, 
llvm::StringRef replacement,
 
 bool PathMappingList::Replace(llvm::StringRef path, llvm::StringRef 
replacement,
   uint32_t index, bool notify) {
+  std::lock_guard lock(m_mutex);
   if (index >= m_pairs.size())
 return false;
   ++m_mod_id;
@@ -116,6 +122,7 @@ bool PathMappingList::Replace(llvm::StringRef path, 
llvm::StringRef replacement,
 }
 
 bool PathMappingList::Remove(size_t index, bool notify) {
+  std::lock_guard lock(m_mutex);
   if (index >= m_pairs.size())
 return false;
 
@@ -130,6 +137,7 @@ bool PathMappingList::Remove(size_t index, bool notify) {
 // For clients which do not need the pair index dumped, pass a pair_index >= 0
 // to onl

[Lldb-commits] [PATCH] D148380: [lldb] Lock accesses to PathMappingLists's internals

2023-04-17 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG43ac269bdd00: [lldb] Lock accesses to 
PathMappingLists's internals (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148380

Files:
  lldb/include/lldb/Target/PathMappingList.h
  lldb/source/Target/PathMappingList.cpp

Index: lldb/source/Target/PathMappingList.cpp
===
--- lldb/source/Target/PathMappingList.cpp
+++ lldb/source/Target/PathMappingList.cpp
@@ -48,6 +48,7 @@
 
 const PathMappingList &PathMappingList::operator=(const PathMappingList &rhs) {
   if (this != &rhs) {
+std::scoped_lock locks(m_mutex, rhs.m_mutex);
 m_pairs = rhs.m_pairs;
 m_callback = nullptr;
 m_callback_baton = nullptr;
@@ -60,6 +61,7 @@
 
 void PathMappingList::Append(llvm::StringRef path, llvm::StringRef replacement,
  bool notify) {
+  std::lock_guard lock(m_mutex);
   ++m_mod_id;
   m_pairs.emplace_back(pair(NormalizePath(path), NormalizePath(replacement)));
   if (notify && m_callback)
@@ -67,6 +69,7 @@
 }
 
 void PathMappingList::Append(const PathMappingList &rhs, bool notify) {
+  std::scoped_lock locks(m_mutex, rhs.m_mutex);
   ++m_mod_id;
   if (!rhs.m_pairs.empty()) {
 const_iterator pos, end = rhs.m_pairs.end();
@@ -81,6 +84,7 @@
llvm::StringRef replacement, bool notify) {
   auto normalized_path = NormalizePath(path);
   auto normalized_replacement = NormalizePath(replacement);
+  std::lock_guard lock(m_mutex);
   for (const auto &pair : m_pairs) {
 if (pair.first.GetStringRef().equals(normalized_path) &&
 pair.second.GetStringRef().equals(normalized_replacement))
@@ -92,6 +96,7 @@
 
 void PathMappingList::Insert(llvm::StringRef path, llvm::StringRef replacement,
  uint32_t index, bool notify) {
+  std::lock_guard lock(m_mutex);
   ++m_mod_id;
   iterator insert_iter;
   if (index >= m_pairs.size())
@@ -106,6 +111,7 @@
 
 bool PathMappingList::Replace(llvm::StringRef path, llvm::StringRef replacement,
   uint32_t index, bool notify) {
+  std::lock_guard lock(m_mutex);
   if (index >= m_pairs.size())
 return false;
   ++m_mod_id;
@@ -116,6 +122,7 @@
 }
 
 bool PathMappingList::Remove(size_t index, bool notify) {
+  std::lock_guard lock(m_mutex);
   if (index >= m_pairs.size())
 return false;
 
@@ -130,6 +137,7 @@
 // For clients which do not need the pair index dumped, pass a pair_index >= 0
 // to only dump the indicated pair.
 void PathMappingList::Dump(Stream *s, int pair_index) {
+  std::lock_guard lock(m_mutex);
   unsigned int numPairs = m_pairs.size();
 
   if (pair_index < 0) {
@@ -147,6 +155,7 @@
 
 llvm::json::Value PathMappingList::ToJSON() {
   llvm::json::Array entries;
+  std::lock_guard lock(m_mutex);
   for (const auto &pair : m_pairs) {
 llvm::json::Array entry{pair.first.GetStringRef().str(),
 pair.second.GetStringRef().str()};
@@ -156,6 +165,7 @@
 }
 
 void PathMappingList::Clear(bool notify) {
+  std::lock_guard lock(m_mutex);
   if (!m_pairs.empty())
 ++m_mod_id;
   m_pairs.clear();
@@ -186,6 +196,7 @@
 
 std::optional PathMappingList::RemapPath(llvm::StringRef mapping_path,
bool only_if_exists) const {
+  std::lock_guard lock(m_mutex);
   if (m_pairs.empty() || mapping_path.empty())
 return {};
   LazyBool path_is_relative = eLazyBoolCalculate;
@@ -224,6 +235,7 @@
 PathMappingList::ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const {
   std::string path = file.GetPath();
   llvm::StringRef path_ref(path);
+  std::lock_guard lock(m_mutex);
   for (const auto &it : m_pairs) {
 llvm::StringRef removed_prefix = it.second.GetStringRef();
 if (!path_ref.consume_front(it.second.GetStringRef()))
@@ -252,6 +264,7 @@
 
 bool PathMappingList::Replace(llvm::StringRef path, llvm::StringRef new_path,
   bool notify) {
+  std::lock_guard lock(m_mutex);
   uint32_t idx = FindIndexForPath(path);
   if (idx < m_pairs.size()) {
 ++m_mod_id;
@@ -264,6 +277,7 @@
 }
 
 bool PathMappingList::Remove(ConstString path, bool notify) {
+  std::lock_guard lock(m_mutex);
   iterator pos = FindIteratorForPath(path);
   if (pos != m_pairs.end()) {
 ++m_mod_id;
@@ -277,6 +291,7 @@
 
 PathMappingList::const_iterator
 PathMappingList::FindIteratorForPath(ConstString path) const {
+  std::lock_guard lock(m_mutex);
   const_iterator pos;
   const_iterator begin = m_pairs.begin();
   const_iterator end = m_pairs.end();
@@ -290,6 +305,7 @@
 
 PathMappingList::iterator
 PathMappingList::FindIteratorForPath(ConstString path) {
+  std::lock_guard lock(m_mutex);
   iterator pos;
   iterator begin = m_pairs.begin();
   iterator end = m_pairs.end();
@@ -303,6 +319,7 @@
 
 bool Path

[Lldb-commits] [PATCH] D148397: [lldb/Utility] Add opt-in passthrough mode to event listeners

2023-04-17 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

I find "passthrough" somewhat confusing in this context. When using a listener 
in this new mode, where does the event go after it has pass trough this event 
listener? Maybe my understanding of how the event listeners is incomplete, but 
I was under the impression that normally there's a single listener for a 
certain kind of event. IIUC, in this new mode, you can have multiple listeners, 
where you can set one (or as Alex pointed out, possibly more) listeners that 
can observe events but not necessary deal with them. If that's an accurate 
description of the interactions, then it seems like there's more of a 
one-to-many relationship between events and listeners rather than what 
passthrough implies. I think a better name would be something like "passive 
listener" or "non-handling" listener or something.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148397

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


[Lldb-commits] [PATCH] D146965: [lldb] Add support for MSP430 in LLDB.

2023-04-17 Thread Ilia Kuklin via Phabricator via lldb-commits
kuilpd updated this revision to Diff 514435.
kuilpd added a comment.

Fixed Triple.h include.


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

https://reviews.llvm.org/D146965

Files:
  lldb/include/lldb/Utility/ArchSpec.h
  lldb/include/lldb/Utility/DataExtractor.h
  lldb/source/Expression/IRMemoryMap.cpp
  lldb/source/Expression/LLVMUserExpression.cpp
  lldb/source/Host/common/NativeProcessProtocol.cpp
  lldb/source/Plugins/ABI/CMakeLists.txt
  lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp
  lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.h
  lldb/source/Plugins/ABI/MSP430/CMakeLists.txt
  lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterFallback.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Utility/ArchSpec.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestMSP430MSPDebug.py
  lldb/test/API/functionalities/gdb_remote_client/msp430.yaml
  lldb/unittests/Utility/ArchSpecTest.cpp

Index: lldb/unittests/Utility/ArchSpecTest.cpp
===
--- lldb/unittests/Utility/ArchSpecTest.cpp
+++ lldb/unittests/Utility/ArchSpecTest.cpp
@@ -123,6 +123,12 @@
   EXPECT_STREQ("i686", AS.GetArchitectureName());
   EXPECT_EQ(ArchSpec::eCore_x86_32_i686, AS.GetCore());
 
+  AS = ArchSpec();
+  EXPECT_TRUE(AS.SetTriple("msp430---elf"));
+  EXPECT_EQ(llvm::Triple::msp430, AS.GetTriple().getArch());
+  EXPECT_STREQ("msp430", AS.GetArchitectureName());
+  EXPECT_EQ(ArchSpec::eCore_msp430, AS.GetCore());
+
   // Various flavors of invalid triples.
   AS = ArchSpec();
   EXPECT_FALSE(AS.SetTriple("unknown-unknown-unknown"));
Index: lldb/test/API/functionalities/gdb_remote_client/msp430.yaml
===
--- /dev/null
+++ lldb/test/API/functionalities/gdb_remote_client/msp430.yaml
@@ -0,0 +1,426 @@
+# File test.c, compiled with flags "-O0 -g"
+# Source code:
+#
+# int foo = 0;
+#
+# int func() {
+# foo = 1234;
+# return foo;
+# }
+#
+# int main() {
+# return func();
+# }
+#
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  OSABI:   ELFOSABI_STANDALONE
+  Type:ET_EXEC
+  Machine: EM_MSP430
+  Flags:   [  ]
+  Entry:   0x500
+ProgramHeaders:
+  - Type:PT_LOAD
+Flags:   [ PF_X, PF_R ]
+FirstSec:.text
+LastSec: .bss
+VAddr:   0x46C
+Align:   0x4
+  - Type:PT_LOAD
+Flags:   [ PF_W, PF_R ]
+FirstSec:.data
+LastSec: .bss
+VAddr:   0x53C
+Align:   0x4
+  - Type:PT_LOAD
+Flags:   [ PF_R ]
+FirstSec:__interrupt_vector_31
+LastSec: __interrupt_vector_31
+VAddr:   0xFFFE
+Align:   0x4
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x500
+AddressAlign:0x4
+Content: 3140C0FF0C43B0121C05B0128101B240D2043C051C423C053041318002008143B01210053150020030411C4330413C402A0030410C433041
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x53C
+AddressAlign:0x1
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x53C
+AddressAlign:0x2
+Size:0x2
+  - Name:__interrupt_vector_31
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC ]
+Address: 0xFFFE
+AddressAlign:0x1
+Offset:  0xD2
+Content: '0005'
+  - Name:.rodata
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x500
+AddressAlign:0x1
+  - Name:.rodata2
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE ]
+Address: 0x500
+AddressAlign:0x1
+  - Name:.noinit
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE ]
+Address: 0x53E
+AddressAlign:0x1
+  - Name:.persistent
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE ]
+Address: 0x53E
+AddressAlign:0x1
+  - Name:.MSP430.attributes
+Type:SHT_MSP430_ATTRIBUTES
+AddressAlign:0x1
+Content: 4116006D737061626900010B00040106010801
+  - Name:.comment
+Type:SHT_PROGBITS
+Flags:   [ SHF_MERGE, SHF_STRINGS ]
+AddressAlign:0x1
+EntSize: 0x1
+Content: 4743433A20284D6974746F2053797374656D73204C696D69746564202D206D737034

[Lldb-commits] [lldb] c8bb7c2 - [lldb] Remove use of ConstString from Args::GetShellSafeArgument

2023-04-17 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-04-17T15:15:36-07:00
New Revision: c8bb7c234c6814b80e2be27eba9718de7ab1ad79

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

LOG: [lldb] Remove use of ConstString from Args::GetShellSafeArgument

Having the names of various shells in ConstString's StringPool is not
really necessary, especially if they are otherwise not going to be there
in the first place. For example, if the person debugging uses bash on
their system, the `shell` parameter will have its `m_filename` set to a
ConstString containing "bash". However, fish, tcsh, zsh, and sh will
probably never be used and are just taking up space in the StringPool.

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

Added: 


Modified: 
lldb/source/Utility/Args.cpp

Removed: 




diff  --git a/lldb/source/Utility/Args.cpp b/lldb/source/Utility/Args.cpp
index 2d50b43bc2413..d34433996021e 100644
--- a/lldb/source/Utility/Args.cpp
+++ b/lldb/source/Utility/Args.cpp
@@ -7,7 +7,6 @@
 
//===--===//
 
 #include "lldb/Utility/Args.h"
-#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/StringList.h"
@@ -385,20 +384,21 @@ void Args::Clear() {
 std::string Args::GetShellSafeArgument(const FileSpec &shell,
llvm::StringRef unsafe_arg) {
   struct ShellDescriptor {
-ConstString m_basename;
+llvm::StringRef m_basename;
 llvm::StringRef m_escapables;
   };
 
-  static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&;"},
-   {ConstString("fish"), " '\"<>()&\\|;"},
-   {ConstString("tcsh"), " '\"<>()&;"},
-   {ConstString("zsh"), " '\"<>()&;\\|"},
-   {ConstString("sh"), " '\"<>()&;"}};
+  static ShellDescriptor g_Shells[] = {{"bash", " '\"<>()&;"},
+   {"fish", " '\"<>()&\\|;"},
+   {"tcsh", " '\"<>()&;"},
+   {"zsh", " '\"<>()&;\\|"},
+   {"sh", " '\"<>()&;"}};
 
   // safe minimal set
   llvm::StringRef escapables = " '\"";
 
-  if (auto basename = shell.GetFilename()) {
+  auto basename = shell.GetFilename().GetStringRef();
+  if (!basename.empty()) {
 for (const auto &Shell : g_Shells) {
   if (Shell.m_basename == basename) {
 escapables = Shell.m_escapables;



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


[Lldb-commits] [PATCH] D148402: [lldb] Remove use of ConstString from Args::GetShellSafeArgument

2023-04-17 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc8bb7c234c68: [lldb] Remove use of ConstString from 
Args::GetShellSafeArgument (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148402

Files:
  lldb/source/Utility/Args.cpp


Index: lldb/source/Utility/Args.cpp
===
--- lldb/source/Utility/Args.cpp
+++ lldb/source/Utility/Args.cpp
@@ -7,7 +7,6 @@
 
//===--===//
 
 #include "lldb/Utility/Args.h"
-#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/StringList.h"
@@ -385,20 +384,21 @@
 std::string Args::GetShellSafeArgument(const FileSpec &shell,
llvm::StringRef unsafe_arg) {
   struct ShellDescriptor {
-ConstString m_basename;
+llvm::StringRef m_basename;
 llvm::StringRef m_escapables;
   };
 
-  static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&;"},
-   {ConstString("fish"), " '\"<>()&\\|;"},
-   {ConstString("tcsh"), " '\"<>()&;"},
-   {ConstString("zsh"), " '\"<>()&;\\|"},
-   {ConstString("sh"), " '\"<>()&;"}};
+  static ShellDescriptor g_Shells[] = {{"bash", " '\"<>()&;"},
+   {"fish", " '\"<>()&\\|;"},
+   {"tcsh", " '\"<>()&;"},
+   {"zsh", " '\"<>()&;\\|"},
+   {"sh", " '\"<>()&;"}};
 
   // safe minimal set
   llvm::StringRef escapables = " '\"";
 
-  if (auto basename = shell.GetFilename()) {
+  auto basename = shell.GetFilename().GetStringRef();
+  if (!basename.empty()) {
 for (const auto &Shell : g_Shells) {
   if (Shell.m_basename == basename) {
 escapables = Shell.m_escapables;


Index: lldb/source/Utility/Args.cpp
===
--- lldb/source/Utility/Args.cpp
+++ lldb/source/Utility/Args.cpp
@@ -7,7 +7,6 @@
 //===--===//
 
 #include "lldb/Utility/Args.h"
-#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/StringList.h"
@@ -385,20 +384,21 @@
 std::string Args::GetShellSafeArgument(const FileSpec &shell,
llvm::StringRef unsafe_arg) {
   struct ShellDescriptor {
-ConstString m_basename;
+llvm::StringRef m_basename;
 llvm::StringRef m_escapables;
   };
 
-  static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&;"},
-   {ConstString("fish"), " '\"<>()&\\|;"},
-   {ConstString("tcsh"), " '\"<>()&;"},
-   {ConstString("zsh"), " '\"<>()&;\\|"},
-   {ConstString("sh"), " '\"<>()&;"}};
+  static ShellDescriptor g_Shells[] = {{"bash", " '\"<>()&;"},
+   {"fish", " '\"<>()&\\|;"},
+   {"tcsh", " '\"<>()&;"},
+   {"zsh", " '\"<>()&;\\|"},
+   {"sh", " '\"<>()&;"}};
 
   // safe minimal set
   llvm::StringRef escapables = " '\"";
 
-  if (auto basename = shell.GetFilename()) {
+  auto basename = shell.GetFilename().GetStringRef();
+  if (!basename.empty()) {
 for (const auto &Shell : g_Shells) {
   if (Shell.m_basename == basename) {
 escapables = Shell.m_escapables;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 81beb15 - [lldb] Add support for MSP430 in LLDB.

2023-04-17 Thread Anton Korobeynikov via lldb-commits

Author: Ilya Kuklin
Date: 2023-04-17T16:03:35-07:00
New Revision: 81beb15d7e54b16f4beba0bafd982d56c6b95222

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

LOG: [lldb] Add support for MSP430 in LLDB.

Add MSP430 to the list of available targets, implement MSP430 ABI, add support 
for debugging targets with 16-bit address size.

The update is intended for use with MSPDebug, a GDB server implementation for 
MSP430.

Reviewed By: bulbazord, DavidSpickett

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

Added: 
lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp
lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.h
lldb/source/Plugins/ABI/MSP430/CMakeLists.txt
lldb/test/API/functionalities/gdb_remote_client/TestMSP430MSPDebug.py
lldb/test/API/functionalities/gdb_remote_client/msp430.yaml

Modified: 
lldb/include/lldb/Utility/ArchSpec.h
lldb/include/lldb/Utility/DataExtractor.h
lldb/source/Expression/IRMemoryMap.cpp
lldb/source/Expression/LLVMUserExpression.cpp
lldb/source/Host/common/NativeProcessProtocol.cpp
lldb/source/Plugins/ABI/CMakeLists.txt
lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterFallback.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/source/Target/Platform.cpp
lldb/source/Utility/ArchSpec.cpp
lldb/unittests/Utility/ArchSpecTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Utility/ArchSpec.h 
b/lldb/include/lldb/Utility/ArchSpec.h
index 444d427c1bd44..2de517d765b2a 100644
--- a/lldb/include/lldb/Utility/ArchSpec.h
+++ b/lldb/include/lldb/Utility/ArchSpec.h
@@ -172,6 +172,8 @@ class ArchSpec {
 eCore_mips64r5el,
 eCore_mips64r6el,
 
+eCore_msp430,
+
 eCore_ppc_generic,
 eCore_ppc_ppc601,
 eCore_ppc_ppc602,

diff  --git a/lldb/include/lldb/Utility/DataExtractor.h 
b/lldb/include/lldb/Utility/DataExtractor.h
index dbf0bce8c8d0d..0b7e771ed4f86 100644
--- a/lldb/include/lldb/Utility/DataExtractor.h
+++ b/lldb/include/lldb/Utility/DataExtractor.h
@@ -843,9 +843,7 @@ class DataExtractor {
   /// \param[in] addr_size
   /// The size in bytes to use when extracting addresses.
   void SetAddressByteSize(uint32_t addr_size) {
-#ifdef LLDB_CONFIGURATION_DEBUG
-assert(addr_size == 4 || addr_size == 8);
-#endif
+assert(addr_size == 2 || addr_size == 4 || addr_size == 8);
 m_addr_size = addr_size;
   }
 

diff  --git a/lldb/source/Expression/IRMemoryMap.cpp 
b/lldb/source/Expression/IRMemoryMap.cpp
index 3c102dd4eaef1..951444db86a87 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -96,12 +96,21 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
   // regions, walk forward through memory until a region is found that has
   // adequate space for our allocation.
   if (process_is_alive) {
-const uint64_t end_of_memory = process_sp->GetAddressByteSize() == 8
-   ? 0xull
-   : 0xull;
-
-lldbassert(process_sp->GetAddressByteSize() == 4 ||
-   end_of_memory != 0xull);
+uint64_t end_of_memory;
+switch (process_sp->GetAddressByteSize()) {
+case 2:
+  end_of_memory = 0xull;
+  break;
+case 4:
+  end_of_memory = 0xull;
+  break;
+case 8:
+  end_of_memory = 0xull;
+  break;
+default:
+  lldbassert(false && "Invalid address size.");
+  return LLDB_INVALID_ADDRESS;
+}
 
 MemoryRegionInfo region_info;
 Status err = process_sp->GetMemoryRegionInfo(ret, region_info);
@@ -137,26 +146,31 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
   // We've tried our algorithm, and it didn't work.  Now we have to reset back
   // to the end of the allocations we've already reported, or use a 'sensible'
   // default if this is our first allocation.
-
   if (m_allocations.empty()) {
 uint32_t address_byte_size = GetAddressByteSize();
 if (address_byte_size != UINT32_MAX) {
   switch (address_byte_size) {
-  case 8:
-ret = 0xdead0fffull;
+  case 2:
+ret = 0x8000ull;
 break;
   case 4:
 ret = 0xee00ull;
 break;
-  default:
+  case 8:
+ret = 0xdead0fffull;
 break;
+  default:
+lldbassert(false && "Invalid address size.");
+return LLDB_INVALID_ADDRESS;
   }
 }
   } else {
 auto back = m_allocations.rbegin();
 lldb::addr_t addr = back->first;
 size_t alloc_size = back->second.m_size;
-ret = llvm::alignTo(addr + alloc_size, 4096);
+auto arch = targe

[Lldb-commits] [PATCH] D148579: [lldb] Change parameter type of StructuredData::ParseJSON

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

Instead of taking a `const std::string &` we can take an
`llvm::StringRef`. The motivation for this change is that many of the
callers of `ParseJSON` end up creating a temporary `std::string` from an 
existing
`StringRef` or `const char *` in order to satisfy the API. There's no
reason we need to do this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148579

Files:
  lldb/include/lldb/Utility/StructuredData.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBStructuredData.cpp
  lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Utility/StructuredData.cpp
  lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
  lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp

Index: lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp
===
--- lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp
+++ lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp
@@ -96,8 +96,7 @@
 ArrayRef RegInfos) {
   JThreadsInfo jthreads_info;
 
-  StructuredData::ObjectSP json =
-  StructuredData::ParseJSON(std::string(Response));
+  StructuredData::ObjectSP json = StructuredData::ParseJSON(Response);
   StructuredData::Array *array = json->GetAsArray();
   if (!array)
 return make_parsing_error("JThreadsInfo: JSON array");
Index: lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
===
--- lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
+++ lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
@@ -287,7 +287,7 @@
   server_thread.join();
 
   GTEST_LOG_(INFO) << "Formatted output: " << ss.GetData();
-  auto object_sp = StructuredData::ParseJSON(std::string(ss.GetString()));
+  auto object_sp = StructuredData::ParseJSON(ss.GetString());
   ASSERT_TRUE(bool(object_sp));
   auto dict_sp = object_sp->GetAsDictionary();
   ASSERT_TRUE(bool(dict_sp));
Index: lldb/source/Utility/StructuredData.cpp
===
--- lldb/source/Utility/StructuredData.cpp
+++ lldb/source/Utility/StructuredData.cpp
@@ -21,8 +21,7 @@
 static StructuredData::ObjectSP ParseJSONObject(json::Object *object);
 static StructuredData::ObjectSP ParseJSONArray(json::Array *array);
 
-StructuredData::ObjectSP
-StructuredData::ParseJSON(const std::string &json_text) {
+StructuredData::ObjectSP StructuredData::ParseJSON(llvm::StringRef json_text) {
   llvm::Expected value = json::parse(json_text);
   if (!value) {
 llvm::consumeError(value.takeError());
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -3781,8 +3781,7 @@
   response.GetResponseType();
   if (response_type == StringExtractorGDBRemote::eResponse) {
 if (!response.Empty()) {
-  object_sp =
-  StructuredData::ParseJSON(std::string(response.GetStringRef()));
+  object_sp = StructuredData::ParseJSON(response.GetStringRef());
 }
   }
 }
@@ -3853,8 +3852,7 @@
   response.GetResponseType();
   if (response_type == StringExtractorGDBRemote::eResponse) {
 if (!response.Empty()) {
-  object_sp =
-  StructuredData::ParseJSON(std::string(response.GetStringRef()));
+  object_sp = StructuredData::ParseJSON(response.GetStringRef());
 }
   }
 }
@@ -3876,8 +3874,7 @@
   response.GetResponseType();
   if (response_type == StringExtractorGDBRemote::eResponse) {
 if (!response.Empty()) {
-  object_sp =
-  StructuredData::ParseJSON(std::string(response.GetStringRef()));
+  object_sp = StructuredData::ParseJSON(response.GetStringRef());
 }
   }
 }
@@ -3909,8 +3906,7 @@
   response.GetResponseType();
   if (response_type == StringExtractorGDBRemote::eResponse) {
 if (!response.Empty()) {
-  object_sp =
-  StructuredData::ParseJSON(std::string(response.GetStringRef()));
+  object_sp = StructuredData::ParseJSON(response.GetStringRef());
 }
   }
 }
@@ -5087,8 +5083,7 @@
   }
 
   // This is an asynchronous JSON packet, destined for a StructuredDataPlugin.
-  StructuredData::ObjectSP json_sp =
-  StructuredData::ParseJSON(std::st

[Lldb-commits] [PATCH] D148579: [lldb] Change parameter type of StructuredData::ParseJSON

2023-04-17 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib accepted this revision.
mib added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148579

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


[Lldb-commits] [PATCH] D148582: [lldb] Build libcxx unique_ptr and shared_ptr test programs with -glldb.

2023-04-17 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
jgorbe created this revision.
jgorbe added reviewers: Michael137, dblaikie, aprantl.
jgorbe added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
jgorbe requested review of this revision.

The functionality added by https://reviews.llvm.org/D145803 is gated by
lldb tuning, so we need to build the test programs with `-glldb` to make
these tests print the expected preferred name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148582

Files:
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile


Index: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
===
--- 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
+++ 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
@@ -2,5 +2,7 @@
 
 USE_LIBCPP := 1
 
-CXXFLAGS_EXTRAS := -std=c++14
+# We need debug info tuning for lldb in order to emit the preferred name for
+# std::string. See https://reviews.llvm.org/D145803.
+CXXFLAGS_EXTRAS := -std=c++14 -glldb
 include Makefile.rules
Index: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
===
--- 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
+++ 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
@@ -2,5 +2,7 @@
 
 USE_LIBCPP := 1
 
-CXXFLAGS_EXTRAS := -std=c++14
+# We need debug info tuning for lldb in order to emit the preferred name for
+# std::string. See https://reviews.llvm.org/D145803.
+CXXFLAGS_EXTRAS := -std=c++14 -glldb
 include Makefile.rules


Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
@@ -2,5 +2,7 @@
 
 USE_LIBCPP := 1
 
-CXXFLAGS_EXTRAS := -std=c++14
+# We need debug info tuning for lldb in order to emit the preferred name for
+# std::string. See https://reviews.llvm.org/D145803.
+CXXFLAGS_EXTRAS := -std=c++14 -glldb
 include Makefile.rules
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
@@ -2,5 +2,7 @@
 
 USE_LIBCPP := 1
 
-CXXFLAGS_EXTRAS := -std=c++14
+# We need debug info tuning for lldb in order to emit the preferred name for
+# std::string. See https://reviews.llvm.org/D145803.
+CXXFLAGS_EXTRAS := -std=c++14 -glldb
 include Makefile.rules
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 3c91d01 - [lldb] Build libcxx unique_ptr and shared_ptr test programs with -glldb.

2023-04-17 Thread Jorge Gorbe Moya via lldb-commits

Author: Jorge Gorbe Moya
Date: 2023-04-17T17:03:29-07:00
New Revision: 3c91d016349a5189691cf788da84608cae68bc13

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

LOG: [lldb] Build libcxx unique_ptr and shared_ptr test programs with -glldb.

The functionality added by https://reviews.llvm.org/D145803 is gated by
lldb tuning, so we need to build the test programs with `-glldb` to make
these tests print the expected preferred name.

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

Added: 


Modified: 

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile

Removed: 




diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
index 7e57f13aea55a..c1c8b4a2a0a53 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
@@ -2,5 +2,7 @@ CXX_SOURCES := main.cpp
 
 USE_LIBCPP := 1
 
-CXXFLAGS_EXTRAS := -std=c++14
+# We need debug info tuning for lldb in order to emit the preferred name for
+# std::string. See https://reviews.llvm.org/D145803.
+CXXFLAGS_EXTRAS := -std=c++14 -glldb
 include Makefile.rules

diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
index 7e57f13aea55a..c1c8b4a2a0a53 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
@@ -2,5 +2,7 @@ CXX_SOURCES := main.cpp
 
 USE_LIBCPP := 1
 
-CXXFLAGS_EXTRAS := -std=c++14
+# We need debug info tuning for lldb in order to emit the preferred name for
+# std::string. See https://reviews.llvm.org/D145803.
+CXXFLAGS_EXTRAS := -std=c++14 -glldb
 include Makefile.rules



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


[Lldb-commits] [PATCH] D148582: [lldb] Build libcxx unique_ptr and shared_ptr test programs with -glldb.

2023-04-17 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3c91d016349a: [lldb] Build libcxx unique_ptr and shared_ptr 
test programs with -glldb. (authored by jgorbe).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148582

Files:
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile


Index: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
===
--- 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
+++ 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
@@ -2,5 +2,7 @@
 
 USE_LIBCPP := 1
 
-CXXFLAGS_EXTRAS := -std=c++14
+# We need debug info tuning for lldb in order to emit the preferred name for
+# std::string. See https://reviews.llvm.org/D145803.
+CXXFLAGS_EXTRAS := -std=c++14 -glldb
 include Makefile.rules
Index: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
===
--- 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
+++ 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
@@ -2,5 +2,7 @@
 
 USE_LIBCPP := 1
 
-CXXFLAGS_EXTRAS := -std=c++14
+# We need debug info tuning for lldb in order to emit the preferred name for
+# std::string. See https://reviews.llvm.org/D145803.
+CXXFLAGS_EXTRAS := -std=c++14 -glldb
 include Makefile.rules


Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/Makefile
@@ -2,5 +2,7 @@
 
 USE_LIBCPP := 1
 
-CXXFLAGS_EXTRAS := -std=c++14
+# We need debug info tuning for lldb in order to emit the preferred name for
+# std::string. See https://reviews.llvm.org/D145803.
+CXXFLAGS_EXTRAS := -std=c++14 -glldb
 include Makefile.rules
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
@@ -2,5 +2,7 @@
 
 USE_LIBCPP := 1
 
-CXXFLAGS_EXTRAS := -std=c++14
+# We need debug info tuning for lldb in order to emit the preferred name for
+# std::string. See https://reviews.llvm.org/D145803.
+CXXFLAGS_EXTRAS := -std=c++14 -glldb
 include Makefile.rules
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D148588: [lldb] Add more asserts to TestExec

2023-04-17 Thread Dave Lee via Phabricator via lldb-commits
kastiglione created this revision.
kastiglione added reviewers: augusto2112, jingham, mib, JDevlieghere.
Herald added a project: All.
kastiglione requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

If this test fails, the error message isn't helpful:

  self.assertEqual(len(threads), 1,
  AssertionError: 0 != 1 : Stopped at breakpoint in exec'ed process

This change adds asserts to verify that:

1. The process is stopped
2. For each thread, that the stop reason is None, or Breakpoint

The latter will indicate if execution has stopped for some other reason, and if 
so what
that reason is.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148588

Files:
  lldb/test/API/functionalities/exec/TestExec.py


Index: lldb/test/API/functionalities/exec/TestExec.py
===
--- lldb/test/API/functionalities/exec/TestExec.py
+++ lldb/test/API/functionalities/exec/TestExec.py
@@ -102,13 +102,18 @@
 # Run and we should stop at breakpoint in main after exec
 process.Continue()
 
+self.assertState(process.GetState(), lldb.eStateStopped)
+for t in process.threads:
+if t.stop_reason != lldb.eStopReasonNone:
+self.assertStopReason(t.stop_reason, 
lldb.eStopReasonBreakpoint,
+"Unexpected stop reason")
+if self.TraceOn():
+print(t)
+if t.stop_reason != lldb.eStopReasonBreakpoint:
+self.runCmd("bt")
+
 threads = lldbutil.get_threads_stopped_at_breakpoint(
 process, breakpoint2)
-if self.TraceOn():
-for t in process.threads:
-print(t)
-if t.GetStopReason() != lldb.eStopReasonBreakpoint:
-self.runCmd("bt")
 self.assertEqual(len(threads), 1,
 "Stopped at breakpoint in exec'ed process.")
 


Index: lldb/test/API/functionalities/exec/TestExec.py
===
--- lldb/test/API/functionalities/exec/TestExec.py
+++ lldb/test/API/functionalities/exec/TestExec.py
@@ -102,13 +102,18 @@
 # Run and we should stop at breakpoint in main after exec
 process.Continue()
 
+self.assertState(process.GetState(), lldb.eStateStopped)
+for t in process.threads:
+if t.stop_reason != lldb.eStopReasonNone:
+self.assertStopReason(t.stop_reason, lldb.eStopReasonBreakpoint,
+"Unexpected stop reason")
+if self.TraceOn():
+print(t)
+if t.stop_reason != lldb.eStopReasonBreakpoint:
+self.runCmd("bt")
+
 threads = lldbutil.get_threads_stopped_at_breakpoint(
 process, breakpoint2)
-if self.TraceOn():
-for t in process.threads:
-print(t)
-if t.GetStopReason() != lldb.eStopReasonBreakpoint:
-self.runCmd("bt")
 self.assertEqual(len(threads), 1,
 "Stopped at breakpoint in exec'ed process.")
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 8bddb13 - [lldb] Change parameter type of StructuredData::ParseJSON

2023-04-17 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-04-17T17:25:05-07:00
New Revision: 8bddb13c2470b95651955c61913627b31e9c99d6

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

LOG: [lldb] Change parameter type of StructuredData::ParseJSON

Instead of taking a `const std::string &` we can take an
`llvm::StringRef`. The motivation for this change is that many of the
callers of `ParseJSON` end up creating a temporary `std::string` from an 
existing
`StringRef` or `const char *` in order to satisfy the API. There's no
reason we need to do this.

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

Added: 


Modified: 
lldb/include/lldb/Utility/StructuredData.h
lldb/source/API/SBDebugger.cpp
lldb/source/API/SBStructuredData.cpp
lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/source/Utility/StructuredData.cpp
lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp

Removed: 




diff  --git a/lldb/include/lldb/Utility/StructuredData.h 
b/lldb/include/lldb/Utility/StructuredData.h
index 5420c0dcf8d5a..8bc44315210b6 100644
--- a/lldb/include/lldb/Utility/StructuredData.h
+++ b/lldb/include/lldb/Utility/StructuredData.h
@@ -579,7 +579,7 @@ class StructuredData {
 void *m_object;
   };
 
-  static ObjectSP ParseJSON(const std::string &json_text);
+  static ObjectSP ParseJSON(llvm::StringRef json_text);
   static ObjectSP ParseJSONFromFile(const FileSpec &file, Status &error);
   static bool IsRecordType(const ObjectSP object_sp);
 };

diff  --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 2e7f06c7bb1b7..4f9c2fa1b223a 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -481,8 +481,7 @@ lldb::SBStructuredData SBDebugger::GetSetting(const char 
*setting) {
 m_opaque_sp->DumpAllPropertyValues(&exe_ctx, json_strm, /*dump_mask*/ 0,
/*is_json*/ true);
 
-  data.m_impl_up->SetObjectSP(
-  StructuredData::ParseJSON(json_strm.GetString().str()));
+  
data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_strm.GetString()));
   return data;
 }
 

diff  --git a/lldb/source/API/SBStructuredData.cpp 
b/lldb/source/API/SBStructuredData.cpp
index 498bcdd39e448..445ed81105407 100644
--- a/lldb/source/API/SBStructuredData.cpp
+++ b/lldb/source/API/SBStructuredData.cpp
@@ -57,9 +57,9 @@ lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream 
&stream) {
   LLDB_INSTRUMENT_VA(this, stream);
 
   lldb::SBError error;
-  std::string json_str(stream.GetData());
 
-  StructuredData::ObjectSP json_obj = StructuredData::ParseJSON(json_str);
+  StructuredData::ObjectSP json_obj =
+  StructuredData::ParseJSON(stream.GetData());
   m_impl_up->SetObjectSP(json_obj);
 
   if (!json_obj || json_obj->GetType() != eStructuredDataTypeDictionary)

diff  --git 
a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp 
b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 0858a2a8d3c8b..446776519dd24 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -699,8 +699,7 @@ const UnixSignalsSP 
&PlatformRemoteGDBServer::GetRemoteUnixSignals() {
   response.GetResponseType() != response.eResponse)
 return m_remote_signals_sp;
 
-  auto object_sp =
-  StructuredData::ParseJSON(std::string(response.GetStringRef()));
+  auto object_sp = StructuredData::ParseJSON(response.GetStringRef());
   if (!object_sp || !object_sp->IsValid())
 return m_remote_signals_sp;
 

diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index a1c1aa5e0f29f..18552ea66b029 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -549,8 +549,7 @@ StructuredData::ObjectSP 
GDBRemoteCommunicationClient::GetThreadsInfo() {
   if (response.IsUnsupportedResponse()) {
 m_supports_jThreadsInfo = false;
   } else if (!response.Empty()) {
-object_sp =
-StructuredData::ParseJSON(std::string(response.GetStringRef()));
+object_sp = StructuredData::ParseJSON(response.GetStringRef());
   }
 }
   }
@@ -2620,7 +2619,7 @@ size_t GDBRemoteCommunicationClient::QueryGDBServer(
 return 0;
 
   StructuredData::ObjectSP data =
-  StructuredData::ParseJSON(std::string(response.GetStringRef()

[Lldb-commits] [PATCH] D148579: [lldb] Change parameter type of StructuredData::ParseJSON

2023-04-17 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8bddb13c2470: [lldb] Change parameter type of 
StructuredData::ParseJSON (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148579

Files:
  lldb/include/lldb/Utility/StructuredData.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBStructuredData.cpp
  lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Utility/StructuredData.cpp
  lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
  lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp

Index: lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp
===
--- lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp
+++ lldb/unittests/tools/lldb-server/tests/MessageObjects.cpp
@@ -96,8 +96,7 @@
 ArrayRef RegInfos) {
   JThreadsInfo jthreads_info;
 
-  StructuredData::ObjectSP json =
-  StructuredData::ParseJSON(std::string(Response));
+  StructuredData::ObjectSP json = StructuredData::ParseJSON(Response);
   StructuredData::Array *array = json->GetAsArray();
   if (!array)
 return make_parsing_error("JThreadsInfo: JSON array");
Index: lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
===
--- lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
+++ lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
@@ -287,7 +287,7 @@
   server_thread.join();
 
   GTEST_LOG_(INFO) << "Formatted output: " << ss.GetData();
-  auto object_sp = StructuredData::ParseJSON(std::string(ss.GetString()));
+  auto object_sp = StructuredData::ParseJSON(ss.GetString());
   ASSERT_TRUE(bool(object_sp));
   auto dict_sp = object_sp->GetAsDictionary();
   ASSERT_TRUE(bool(dict_sp));
Index: lldb/source/Utility/StructuredData.cpp
===
--- lldb/source/Utility/StructuredData.cpp
+++ lldb/source/Utility/StructuredData.cpp
@@ -21,8 +21,7 @@
 static StructuredData::ObjectSP ParseJSONObject(json::Object *object);
 static StructuredData::ObjectSP ParseJSONArray(json::Array *array);
 
-StructuredData::ObjectSP
-StructuredData::ParseJSON(const std::string &json_text) {
+StructuredData::ObjectSP StructuredData::ParseJSON(llvm::StringRef json_text) {
   llvm::Expected value = json::parse(json_text);
   if (!value) {
 llvm::consumeError(value.takeError());
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -3781,8 +3781,7 @@
   response.GetResponseType();
   if (response_type == StringExtractorGDBRemote::eResponse) {
 if (!response.Empty()) {
-  object_sp =
-  StructuredData::ParseJSON(std::string(response.GetStringRef()));
+  object_sp = StructuredData::ParseJSON(response.GetStringRef());
 }
   }
 }
@@ -3853,8 +3852,7 @@
   response.GetResponseType();
   if (response_type == StringExtractorGDBRemote::eResponse) {
 if (!response.Empty()) {
-  object_sp =
-  StructuredData::ParseJSON(std::string(response.GetStringRef()));
+  object_sp = StructuredData::ParseJSON(response.GetStringRef());
 }
   }
 }
@@ -3876,8 +3874,7 @@
   response.GetResponseType();
   if (response_type == StringExtractorGDBRemote::eResponse) {
 if (!response.Empty()) {
-  object_sp =
-  StructuredData::ParseJSON(std::string(response.GetStringRef()));
+  object_sp = StructuredData::ParseJSON(response.GetStringRef());
 }
   }
 }
@@ -3909,8 +3906,7 @@
   response.GetResponseType();
   if (response_type == StringExtractorGDBRemote::eResponse) {
 if (!response.Empty()) {
-  object_sp =
-  StructuredData::ParseJSON(std::string(response.GetStringRef()));
+  object_sp = StructuredData::ParseJSON(response.GetStringRef());
 }
   }
 }
@@ -5087,8 +5083,7 @@
   }
 
   // This is an asynchronous JSON packet, destined for a StructuredDataPlugin.
-  StructuredData::ObjectSP json_sp =
-  StructuredData::ParseJSON(std::string(packet));
+  StructuredData::ObjectSP json_sp = StructuredData::ParseJSON(packet);
   if (log) {
 if (json_sp) {
   StreamString json_str;
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
=

[Lldb-commits] [PATCH] D148588: [lldb] Add more asserts to TestExec

2023-04-17 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148588

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


[Lldb-commits] [lldb] 773d9c3 - [lldb] Add more asserts to TestExec

2023-04-17 Thread Dave Lee via lldb-commits

Author: Dave Lee
Date: 2023-04-17T18:43:42-07:00
New Revision: 773d9c36043204c284324bc37a1de769a7575034

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

LOG: [lldb] Add more asserts to TestExec

If this test fails, the error message isn't helpful:

```
self.assertEqual(len(threads), 1,
AssertionError: 0 != 1 : Stopped at breakpoint in exec'ed process
```

This change adds asserts to verify that:
1. The process is stopped
2. For each thread, that the stop reason is None, or Breakpoint

The latter will indicate if execution has stopped for some other reason, and if 
so what
that reason is.

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

Added: 


Modified: 
lldb/test/API/functionalities/exec/TestExec.py

Removed: 




diff  --git a/lldb/test/API/functionalities/exec/TestExec.py 
b/lldb/test/API/functionalities/exec/TestExec.py
index 864abb6533aef..ed7cc2f4f5b85 100644
--- a/lldb/test/API/functionalities/exec/TestExec.py
+++ b/lldb/test/API/functionalities/exec/TestExec.py
@@ -102,13 +102,18 @@ def cleanup():
 # Run and we should stop at breakpoint in main after exec
 process.Continue()
 
+self.assertState(process.GetState(), lldb.eStateStopped)
+for t in process.threads:
+if t.stop_reason != lldb.eStopReasonNone:
+self.assertStopReason(t.stop_reason, 
lldb.eStopReasonBreakpoint,
+"Unexpected stop reason")
+if self.TraceOn():
+print(t)
+if t.stop_reason != lldb.eStopReasonBreakpoint:
+self.runCmd("bt")
+
 threads = lldbutil.get_threads_stopped_at_breakpoint(
 process, breakpoint2)
-if self.TraceOn():
-for t in process.threads:
-print(t)
-if t.GetStopReason() != lldb.eStopReasonBreakpoint:
-self.runCmd("bt")
 self.assertEqual(len(threads), 1,
 "Stopped at breakpoint in exec'ed process.")
 



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


[Lldb-commits] [PATCH] D148588: [lldb] Add more asserts to TestExec

2023-04-17 Thread Dave Lee via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG773d9c360432: [lldb] Add more asserts to TestExec (authored 
by kastiglione).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148588

Files:
  lldb/test/API/functionalities/exec/TestExec.py


Index: lldb/test/API/functionalities/exec/TestExec.py
===
--- lldb/test/API/functionalities/exec/TestExec.py
+++ lldb/test/API/functionalities/exec/TestExec.py
@@ -102,13 +102,18 @@
 # Run and we should stop at breakpoint in main after exec
 process.Continue()
 
+self.assertState(process.GetState(), lldb.eStateStopped)
+for t in process.threads:
+if t.stop_reason != lldb.eStopReasonNone:
+self.assertStopReason(t.stop_reason, 
lldb.eStopReasonBreakpoint,
+"Unexpected stop reason")
+if self.TraceOn():
+print(t)
+if t.stop_reason != lldb.eStopReasonBreakpoint:
+self.runCmd("bt")
+
 threads = lldbutil.get_threads_stopped_at_breakpoint(
 process, breakpoint2)
-if self.TraceOn():
-for t in process.threads:
-print(t)
-if t.GetStopReason() != lldb.eStopReasonBreakpoint:
-self.runCmd("bt")
 self.assertEqual(len(threads), 1,
 "Stopped at breakpoint in exec'ed process.")
 


Index: lldb/test/API/functionalities/exec/TestExec.py
===
--- lldb/test/API/functionalities/exec/TestExec.py
+++ lldb/test/API/functionalities/exec/TestExec.py
@@ -102,13 +102,18 @@
 # Run and we should stop at breakpoint in main after exec
 process.Continue()
 
+self.assertState(process.GetState(), lldb.eStateStopped)
+for t in process.threads:
+if t.stop_reason != lldb.eStopReasonNone:
+self.assertStopReason(t.stop_reason, lldb.eStopReasonBreakpoint,
+"Unexpected stop reason")
+if self.TraceOn():
+print(t)
+if t.stop_reason != lldb.eStopReasonBreakpoint:
+self.runCmd("bt")
+
 threads = lldbutil.get_threads_stopped_at_breakpoint(
 process, breakpoint2)
-if self.TraceOn():
-for t in process.threads:
-print(t)
-if t.GetStopReason() != lldb.eStopReasonBreakpoint:
-self.runCmd("bt")
 self.assertEqual(len(threads), 1,
 "Stopped at breakpoint in exec'ed process.")
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D148603: Remove hardcoding of addressing bits in ABIMacOSX_arm64

2023-04-17 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda created this revision.
jasonmolenda added a reviewer: JDevlieghere.
jasonmolenda added a project: LLDB.
Herald added subscribers: kristof.beyls, arichardson.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

Early in the adoption of pointer authentication on Darwin systems, we had most 
environments running with the same number of addressing bits in use on AArch64 
systems, and didn't prioritize fetching that value dynamically. Our 
environments have grown so there is no correct fixed value, and the correct 
value is determined dynamically in most scenarios; the hardcoding of one value 
can cause problems when running on a larger address space environment that may 
set its value later.

Change ABIMacOSX_arm64 to mask off the top byte unconditionally when we have no 
dynamic information about the number of addressing bits, instead of hardcoding 
the old addressable bits value.

I had a test which created a corefile with no LC_NOTE markup for the number of 
addressable bits, and tested against that to confirm the hardcoded default 
value was in effect.  Remove that test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148603

Files:
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
  lldb/test/API/macosx/corefile-default-ptrauth/Makefile
  lldb/test/API/macosx/corefile-default-ptrauth/TestCorefileDefaultPtrauth.py
  lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
  lldb/test/API/macosx/corefile-default-ptrauth/main.c

Index: lldb/test/API/macosx/corefile-default-ptrauth/main.c
===
--- lldb/test/API/macosx/corefile-default-ptrauth/main.c
+++ /dev/null
@@ -1,6 +0,0 @@
-int main();
-int (*fmain)() = main;
-int main () {
-  return fmain();
-}
-
Index: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
===
--- lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
+++ /dev/null
@@ -1,189 +0,0 @@
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-// Given an executable binary with 
-//   "fmain" (a function pointer to main)
-//   "main"
-// symbols, create a fake arm64e corefile that
-// contains a memory segment for the fmain 
-// function pointer, with the value of the 
-// address of main() with ptrauth bits masked on.
-//
-// The corefile does not include the "addrable bits"
-// LC_NOTE, so lldb will need to fall back on its 
-// default value from the Darwin arm64 ABI.
-
-int main(int argc, char **argv)
-{
-  if (argc != 3) {
-fprintf (stderr, "usage: %s executable-binary output-file\n", argv[0]);
-exit(1);
-  }
-  FILE *exe = fopen(argv[1], "r");
-  if (!exe) {
-fprintf (stderr, "Unable to open executable %s for reading\n", argv[1]);
-exit(1);
-  }
-  FILE *out = fopen(argv[2], "w");
-  if (!out) {
-fprintf (stderr, "Unable to open %s for writing\n", argv[2]);
-exit(1);
-  }
-
-  char buf[PATH_MAX + 6];
-  sprintf (buf, "nm '%s'", argv[1]);
-  FILE *nm = popen(buf, "r");
-  if (!nm) {
-fprintf (stderr, "Unable to run nm on '%s'", argv[1]);
-exit (1);
-  }
-  uint64_t main_addr = 0;
-  uint64_t fmain_addr = 0;
-  while (fgets (buf, sizeof(buf), nm)) {
-if (strstr (buf, "_fmain")) {
-  fmain_addr = strtoul (buf, NULL, 16);
-}
-if (strstr (buf, "_main")) {
-  main_addr = strtoul (buf, NULL, 16);
-}
-  }
-  pclose (nm);
-
-  sprintf (buf, "dwarfdump -u '%s'", argv[1]);
-  FILE *dwarfdump = popen(buf, "r");
-  if (!dwarfdump) {
-fprintf (stderr, "Unable to run dwarfdump -u on '%s'\n", argv[1]);
-exit (1);
-  }
-  uuid_t uuid;
-  uuid_clear (uuid);
-  while (fgets (buf, sizeof(buf), dwarfdump)) {
-if (strncmp (buf, "UUID: ", 6) == 0) {
-  buf[6 + 36] = '\0';
-  if (uuid_parse (buf + 6, uuid) != 0) {
-fprintf (stderr, "Unable to parse UUID in '%s'\n", buf);
-exit (1);
-  }
-}
-  }
-  if (uuid_is_null(uuid)) {
-fprintf (stderr, "Got a null uuid for the binary\n");
-exit (1);
-  }
-
-  if (main_addr == 0 || fmain_addr == 0) {
-fprintf(stderr, "Unable to find address of main or fmain in %s.\n",
-argv[1]);
-exit (1);
-  }
-
-  // Write out a corefile with contents in this order:
-  //1. mach header
-  //2. LC_THREAD load command
-  //3. LC_SEGMENT_64 load command
-  //4. LC_NOTE load command
-  //5. memory segment contents
-  //6. "load binary" note contents
-
-  // struct thread_command {
-  //   uint32_tcmd;
-  //   uint32_tcmdsize;
-  //   uint32_t flavor  
-  //   uint32_t count   
-  //   struct XXX_thread_state state
-  int size_of_thread_cmd = 4 + 4 + 4 + 4 + sizeof (arm_thread_state64_t);
-
-  struct mach_header_64 mh;
-  mh.magic = 0xfeedfacf;
-  mh.cputype = CPU_TYPE_ARM64;
-  mh.cpusubtype = CPU_SUBT