[Lldb-commits] [PATCH] D153489: [lldb] Print hint if object description is requested but not implemented

2023-06-21 Thread Augusto Noronha via Phabricator via lldb-commits
augusto2112 added a comment.
Herald added subscribers: Michael137, JDevlieghere.

@kastiglione I wonder if we should hint in all 3 command objects (expr, frame 
var and DWIM)  or if we should limit this to DWIM instead (since DWIM is the 
one aliased to p and po and I don't think `vo` or `expr -O` are often used 
unintentionally).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153489

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


[Lldb-commits] [PATCH] D153489: [lldb] Print hint if object description is requested but not implemented

2023-06-21 Thread Augusto Noronha via Phabricator via lldb-commits
augusto2112 created this revision.
augusto2112 added reviewers: kastiglione, jingham.
Herald added a project: All.
augusto2112 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153489

Files:
  lldb/source/Commands/CommandObjectDWIMPrint.cpp
  lldb/source/Commands/CommandObjectDWIMPrint.h
  lldb/source/Commands/CommandObjectExpression.cpp
  lldb/source/Commands/CommandObjectFrame.cpp

Index: lldb/source/Commands/CommandObjectFrame.cpp
===
--- lldb/source/Commands/CommandObjectFrame.cpp
+++ lldb/source/Commands/CommandObjectFrame.cpp
@@ -6,6 +6,8 @@
 //
 //===--===//
 #include "CommandObjectFrame.h"
+
+#include "CommandObjectDWIMPrint.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/ValueObject.h"
 #include "lldb/DataFormatters/DataVisualization.h"
@@ -513,6 +515,9 @@
 if (sym_ctx.function && sym_ctx.function->IsTopLevelFunction())
   m_option_variable.show_globals = true;
 
+bool is_po = m_varobj_options.use_objc;
+auto language = frame->GuessLanguage();
+
 if (variable_list) {
   const Format format = m_option_format.GetFormat();
   options.SetFormat(format);
@@ -556,7 +561,10 @@
 show_module))
   s.PutCString(": ");
   }
-  valobj_sp->Dump(result.GetOutputStream(), options);
+
+  CommandObjectDWIMPrint::MaybeAddPoHintAndDump(
+  *valobj_sp.get(), options, language, is_po,
+  result.GetOutputStream());
 }
   }
 }
@@ -604,7 +612,8 @@
   Stream &output_stream = result.GetOutputStream();
   options.SetRootValueObjectName(
   valobj_sp->GetParent() ? entry.c_str() : nullptr);
-  valobj_sp->Dump(output_stream, options);
+  CommandObjectDWIMPrint::MaybeAddPoHintAndDump(
+  *valobj_sp.get(), options, language, is_po, output_stream);
 } else {
   if (auto error_cstr = error.AsCString(nullptr))
 result.AppendError(error_cstr);
@@ -674,7 +683,9 @@
 valobj_sp->GetPreferredDisplayLanguage());
 options.SetRootValueObjectName(
 var_sp ? var_sp->GetName().AsCString() : nullptr);
-valobj_sp->Dump(result.GetOutputStream(), options);
+CommandObjectDWIMPrint::MaybeAddPoHintAndDump(
+*valobj_sp.get(), options, language, is_po,
+result.GetOutputStream());
   }
 }
   }
@@ -694,8 +705,11 @@
 options.SetFormat(m_option_format.GetFormat());
 options.SetVariableFormatDisplayLanguage(
 rec_value_sp->GetPreferredDisplayLanguage());
+rec_value_sp->GetPreferredDisplayLanguage();
 options.SetRootValueObjectName(rec_value_sp->GetName().AsCString());
-rec_value_sp->Dump(result.GetOutputStream(), options);
+CommandObjectDWIMPrint::MaybeAddPoHintAndDump(
+*rec_value_sp.get(), options, language, is_po,
+result.GetOutputStream());
   }
 }
   }
Index: lldb/source/Commands/CommandObjectExpression.cpp
===
--- lldb/source/Commands/CommandObjectExpression.cpp
+++ lldb/source/Commands/CommandObjectExpression.cpp
@@ -9,6 +9,8 @@
 #include "llvm/ADT/StringRef.h"
 
 #include "CommandObjectExpression.h"
+
+#include "CommandObjectDWIMPrint.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Expression/ExpressionVariable.h"
 #include "lldb/Expression/REPL.h"
@@ -473,7 +475,13 @@
 options.SetVariableFormatDisplayLanguage(
 result_valobj_sp->GetPreferredDisplayLanguage());
 
-result_valobj_sp->Dump(output_stream, options);
+bool is_po = m_varobj_options.use_objc;
+lldb::LanguageType language = m_command_options.language;
+if (language == lldb::eLanguageTypeUnknown && frame)
+  language = frame->GuessLanguage();
+CommandObjectDWIMPrint::MaybeAddPoHintAndDump(*result_valobj_sp.get(),
+  options, language, is_po,
+  result.GetOutputStream());
 
 if (suppress_result)
   if (auto result_var_sp =
Index: lldb/source/Commands/CommandObjectDWIMPrint.h
=

[Lldb-commits] [PATCH] D153447: Creating a startDebugging reverse DAP request handler in lldb-vscode.

2023-06-21 Thread John Harrison via Phabricator via lldb-commits
ashgti added a comment.

In D153447#4439359 , @wallace wrote:

> Please write an entry about this in the documentation of lldb-vscode

Updated with some additional documentation in the lldb-vscode/README.md


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153447

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


[Lldb-commits] [PATCH] D153447: Creating a startDebugging reverse DAP request handler in lldb-vscode.

2023-06-21 Thread John Harrison via Phabricator via lldb-commits
ashgti updated this revision to Diff 533440.
ashgti marked 3 inline comments as done.
ashgti added a comment.

Adding documentation to the lldb-vscode/README.md.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153447

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
  lldb/test/API/tools/lldb-vscode/startDebugging/Makefile
  lldb/test/API/tools/lldb-vscode/startDebugging/TestVSCode_startDebugging.py
  lldb/test/API/tools/lldb-vscode/startDebugging/main.c
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/README.md
  lldb/tools/lldb-vscode/VSCode.cpp
  lldb/tools/lldb-vscode/VSCode.h
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1471,6 +1471,13 @@
 
   g_vsc.debugger =
   lldb::SBDebugger::Create(source_init_file, log_cb, nullptr);
+  auto cmd = g_vsc.debugger.GetCommandInterpreter().AddMultiwordCommand(
+  "lldb-vscode", nullptr);
+  cmd.AddCommand(
+  "startDebugging", &g_vsc.start_debugging_request_handler,
+  "Sends a startDebugging request from the debug adapter to the client to "
+  "start a child debug session of the same type as the caller.");
+
   g_vsc.progress_event_thread = std::thread(ProgressEventThreadFunction);
 
   // Start our event thread so we can receive events from the debugger, target,
@@ -1564,7 +1571,8 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
 
-llvm::Error request_runInTerminal(const llvm::json::Object &launch_request) {
+llvm::Error request_runInTerminal(const llvm::json::Object &launch_request,
+  const uint64_t timeout_seconds) {
   g_vsc.is_attach = true;
   lldb::SBAttachInfo attach_info;
 
@@ -1582,10 +1590,10 @@
 #endif
   llvm::json::Object reverse_request = CreateRunInTerminalReverseRequest(
   launch_request, g_vsc.debug_adaptor_path, comm_file.m_path, debugger_pid);
-  llvm::json::Object reverse_response;
-  lldb_vscode::PacketStatus status =
-  g_vsc.SendReverseRequest(reverse_request, reverse_response);
-  if (status != lldb_vscode::PacketStatus::Success)
+  auto sent =
+  g_vsc.SendReverseRequest("runInTerminal", std::move(reverse_request));
+  if (std::future_status::ready !=
+  sent.wait_for(std::chrono::seconds(timeout_seconds)))
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Process cannot be launched by the IDE. %s",
comm_channel.GetLauncherError().c_str());
@@ -1676,7 +1684,7 @@
   const uint64_t timeout_seconds = GetUnsigned(arguments, "timeout", 30);
 
   if (GetBoolean(arguments, "runInTerminal", false)) {
-if (llvm::Error err = request_runInTerminal(request))
+if (llvm::Error err = request_runInTerminal(request, timeout_seconds))
   error.SetErrorString(llvm::toString(std::move(err)).c_str());
   } else if (launchCommands.empty()) {
 // Disable async events so the launch will be successful when we return from
@@ -3464,17 +3472,13 @@
 g_vsc.output.descriptor = StreamDescriptor::from_file(new_stdout_fd, false);
   }
 
-  while (!g_vsc.sent_terminated_event) {
-llvm::json::Object object;
-lldb_vscode::PacketStatus status = g_vsc.GetNextObject(object);
-if (status == lldb_vscode::PacketStatus::EndOfFile)
-  break;
-if (status != lldb_vscode::PacketStatus::Success)
-  return 1; // Fatal error
-
-if (!g_vsc.HandleObject(object))
-  return 1;
+  bool CleanExit = true;
+  if (auto Err = g_vsc.Loop()) {
+if (g_vsc.log)
+  *g_vsc.log << "Transport Error: " << llvm::toString(std::move(Err))
+ << "\n";
+CleanExit = false;
   }
 
-  return EXIT_SUCCESS;
+  return CleanExit ? EXIT_SUCCESS : EXIT_FAILURE;
 }
Index: lldb/tools/lldb-vscode/VSCode.h
===
--- lldb/tools/lldb-vscode/VSCode.h
+++ lldb/tools/lldb-vscode/VSCode.h
@@ -11,8 +11,10 @@
 
 #include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -121,6 +123,11 @@
   void Clear();
 };
 
+struct StartDebuggingRequestHandler : public lldb::SBCommandPluginInterface {
+  bool DoExecute(lldb::SBDebugger debugger, char **command,
+ lldb::SBCommandReturnObject &result) override;
+};
+
 struct VSCode {
   std::string debug_adaptor_path;
   InputStream input;
@@ -146,7 +153,7 @@
   // arguments if we get a RestartRequest.
   std::optional last_launch_or_attach_request;
   lldb::tid_t focus_tid;
-  bool sent_terminated_event;
+  std::atomic sent_terminated_event;
   bool stop_at_entry;
   bool is_attach;
   // The process event thread normally responds to process exited events by
@@ -154,13 +16

[Lldb-commits] [PATCH] D153482: [lldb][NFCI] Remove use of ConstString from StructuredDataPlugin

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

The use of ConstString in StructuredDataPlugin is unneccessary as fast
comparisons are not neeeded for StructuredDataPlugins.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153482

Files:
  lldb/include/lldb/Target/Process.h
  lldb/include/lldb/Target/StructuredDataPlugin.h
  lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
  lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h
  lldb/source/Target/Process.cpp
  lldb/source/Target/StructuredDataPlugin.cpp

Index: lldb/source/Target/StructuredDataPlugin.cpp
===
--- lldb/source/Target/StructuredDataPlugin.cpp
+++ lldb/source/Target/StructuredDataPlugin.cpp
@@ -32,7 +32,7 @@
 
 StructuredDataPlugin::~StructuredDataPlugin() = default;
 
-bool StructuredDataPlugin::GetEnabled(ConstString type_name) const {
+bool StructuredDataPlugin::GetEnabled(llvm::StringRef type_name) const {
   // By default, plugins are always enabled.  Plugin authors should override
   // this if there is an enabled/disabled state for their plugin.
   return true;
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -6070,7 +6070,7 @@
 // For any of the remaining type names, map any that this plugin supports.
 std::vector names_to_remove;
 for (llvm::StringRef type_name : type_names) {
-  if (plugin_sp->SupportsStructuredDataType(ConstString(type_name))) {
+  if (plugin_sp->SupportsStructuredDataType(type_name)) {
 m_structured_data_plugin_map.insert(
 std::make_pair(type_name, plugin_sp));
 names_to_remove.push_back(type_name);
@@ -6110,8 +6110,7 @@
   }
 
   // Route the structured data to the plugin.
-  find_it->second->HandleArrivalOfStructuredData(*this, ConstString(type_name),
- object_sp);
+  find_it->second->HandleArrivalOfStructuredData(*this, type_name, object_sp);
   return true;
 }
 
Index: lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h
===
--- lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h
+++ lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h
@@ -50,16 +50,16 @@
 
   // StructuredDataPlugin API
 
-  bool SupportsStructuredDataType(ConstString type_name) override;
+  bool SupportsStructuredDataType(llvm::StringRef type_name) override;
 
   void HandleArrivalOfStructuredData(
-  Process &process, ConstString type_name,
+  Process &process, llvm::StringRef type_name,
   const StructuredData::ObjectSP &object_sp) override;
 
   Status GetDescription(const StructuredData::ObjectSP &object_sp,
 lldb_private::Stream &stream) override;
 
-  bool GetEnabled(ConstString type_name) const override;
+  bool GetEnabled(llvm::StringRef type_name) const override;
 
   void ModulesDidLoad(Process &process, ModuleList &module_list) override;
 
Index: lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
===
--- lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
+++ lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
@@ -875,9 +875,10 @@
   process_sp->GetStructuredDataPlugin(GetDarwinLogTypeName());
   stream.Printf("Availability: %s\n",
 plugin_sp ? "available" : "unavailable");
-  llvm::StringRef plugin_name = StructuredDataDarwinLog::GetStaticPluginName();
   const bool enabled =
-  plugin_sp ? plugin_sp->GetEnabled(ConstString(plugin_name)) : false;
+  plugin_sp ? plugin_sp->GetEnabled(
+  StructuredDataDarwinLog::GetStaticPluginName())
+: false;
   stream.Printf("Enabled: %s\n", enabled ? "true" : "false");
 }
 
@@ -1057,12 +1058,12 @@
 // StructuredDataPlugin API
 
 bool StructuredDataDarwinLog::SupportsStructuredDataType(
-ConstString type_name) {
+llvm::StringRef type_name) {
   return type_name == GetDarwinLogTypeName();
 }
 
 void StructuredDataDarwinLog::HandleArrivalOfStructuredData(
-Process &process, ConstString type_name,
+Process &process, llvm::StringRef type_name,
 const StructuredData::ObjectSP &object_sp) {
   Log *log = GetLog(LLDBLog::Process);
   if (log) {
@@ -1086,11 +1087,9 @@
 
   // Ignore any data that isn't for us.
   if (type_name != GetDarwinLogTypeName()) {
-LLDB_LOGF(log,
-  "StructuredDataDarwinLog::%s() StructuredData type "
-  "expect

[Lldb-commits] [PATCH] D153447: Creating a startDebugging reverse DAP request handler in lldb-vscode.

2023-06-21 Thread walter erquinigo via Phabricator via lldb-commits
wallace requested changes to this revision.
wallace added a comment.
This revision now requires changes to proceed.

Please write an entry about this in the documentation of lldb-vscode


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153447

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


[Lldb-commits] [PATCH] D153447: Creating a startDebugging reverse DAP request handler in lldb-vscode.

2023-06-21 Thread walter erquinigo via Phabricator via lldb-commits
wallace accepted this revision.
wallace added a comment.
This revision is now accepted and ready to land.

pretty nice! Just a few nits, but other than that it's good to go




Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1475
+  auto cmd = g_vsc.debugger.GetCommandInterpreter().AddMultiwordCommand(
+  "dap", nullptr);
+  cmd.AddCommand(

call it lldb-vscode instead of dap to have the same nomenclature all across



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1478
+  "startDebugging", &g_vsc.start_debugging_request_handler,
+  "Sends a startDebugging from the debug adapter to the client to start "
+  "child debug session of the same type as the caller.");





Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1479
+  "Sends a startDebugging from the debug adapter to the client to start "
+  "child debug session of the same type as the caller.");
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153447

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


[Lldb-commits] [lldb] 3858e9d - Add two new entitlements when debugserver is built by Apple

2023-06-21 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2023-06-21T14:56:11-07:00
New Revision: 3858e9d6c5136e5a491795c1dcb720361c525526

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

LOG: Add two new entitlements when debugserver is built by Apple

Two new entitlements, com.apple.private.thread-set-state and
com.apple.private.set-exception-port should be included in the
debugserver entitlement plist when built internally at Apple.
The desktop builds of debugserver don't need these entitlements;
don't add them to debugserver-macosx-entitlements.plist.

rdar://108912676
rdar://103032208

Added: 


Modified: 
lldb/tools/debugserver/resources/debugserver-entitlements.plist

lldb/tools/debugserver/resources/debugserver-macosx-private-entitlements.plist

Removed: 




diff  --git a/lldb/tools/debugserver/resources/debugserver-entitlements.plist 
b/lldb/tools/debugserver/resources/debugserver-entitlements.plist
index 1798610305d9e..a5d471ea6a3b0 100644
--- a/lldb/tools/debugserver/resources/debugserver-entitlements.plist
+++ b/lldb/tools/debugserver/resources/debugserver-entitlements.plist
@@ -26,5 +26,9 @@
 
 com.apple.private.cs.debugger
 
+com.apple.private.thread-set-state
+
+com.apple.private.set-exception-port
+
 
 

diff  --git 
a/lldb/tools/debugserver/resources/debugserver-macosx-private-entitlements.plist
 
b/lldb/tools/debugserver/resources/debugserver-macosx-private-entitlements.plist
index d09bd924bf2c8..83243c816ceba 100644
--- 
a/lldb/tools/debugserver/resources/debugserver-macosx-private-entitlements.plist
+++ 
b/lldb/tools/debugserver/resources/debugserver-macosx-private-entitlements.plist
@@ -6,5 +6,9 @@
 
 com.apple.private.cs.debugger
 
+com.apple.private.thread-set-state
+
+com.apple.private.set-exception-port
+
 
 



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


[Lldb-commits] [PATCH] D153447: Creating a startDebugging reverse DAP request handler in lldb-vscode.

2023-06-21 Thread John Harrison via Phabricator via lldb-commits
ashgti created this revision.
Herald added a project: All.
ashgti updated this revision to Diff 533349.
ashgti added a comment.
ashgti published this revision for review.
ashgti added reviewers: wallace, ivanhernandez13.
ashgti added a project: LLDB.
Herald added subscribers: lldb-commits, JDevlieghere.

Corrected a makefile reference.


Adds support for a reverse DAP request to startDebugging. The new request can 
be used to launch child processes from lldb scripts, for example it would be 
start forward to configure a debug configuration for a server and a client 
allowing you to launch both processes with a single debug configuraiton.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153447

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
  lldb/test/API/tools/lldb-vscode/startDebugging/Makefile
  lldb/test/API/tools/lldb-vscode/startDebugging/TestVSCode_startDebugging.py
  lldb/test/API/tools/lldb-vscode/startDebugging/main.c
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/VSCode.cpp
  lldb/tools/lldb-vscode/VSCode.h
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1471,6 +1471,13 @@
 
   g_vsc.debugger =
   lldb::SBDebugger::Create(source_init_file, log_cb, nullptr);
+  auto cmd = g_vsc.debugger.GetCommandInterpreter().AddMultiwordCommand(
+  "dap", nullptr);
+  cmd.AddCommand(
+  "startDebugging", &g_vsc.start_debugging_request_handler,
+  "Sends a startDebugging from the debug adapter to the client to start "
+  "child debug session of the same type as the caller.");
+
   g_vsc.progress_event_thread = std::thread(ProgressEventThreadFunction);
 
   // Start our event thread so we can receive events from the debugger, target,
@@ -1564,7 +1571,8 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
 
-llvm::Error request_runInTerminal(const llvm::json::Object &launch_request) {
+llvm::Error request_runInTerminal(const llvm::json::Object &launch_request,
+  const uint64_t timeout_seconds) {
   g_vsc.is_attach = true;
   lldb::SBAttachInfo attach_info;
 
@@ -1582,10 +1590,10 @@
 #endif
   llvm::json::Object reverse_request = CreateRunInTerminalReverseRequest(
   launch_request, g_vsc.debug_adaptor_path, comm_file.m_path, debugger_pid);
-  llvm::json::Object reverse_response;
-  lldb_vscode::PacketStatus status =
-  g_vsc.SendReverseRequest(reverse_request, reverse_response);
-  if (status != lldb_vscode::PacketStatus::Success)
+  auto sent =
+  g_vsc.SendReverseRequest("runInTerminal", std::move(reverse_request));
+  if (std::future_status::ready !=
+  sent.wait_for(std::chrono::seconds(timeout_seconds)))
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Process cannot be launched by the IDE. %s",
comm_channel.GetLauncherError().c_str());
@@ -1676,7 +1684,7 @@
   const uint64_t timeout_seconds = GetUnsigned(arguments, "timeout", 30);
 
   if (GetBoolean(arguments, "runInTerminal", false)) {
-if (llvm::Error err = request_runInTerminal(request))
+if (llvm::Error err = request_runInTerminal(request, timeout_seconds))
   error.SetErrorString(llvm::toString(std::move(err)).c_str());
   } else if (launchCommands.empty()) {
 // Disable async events so the launch will be successful when we return from
@@ -3464,17 +3472,13 @@
 g_vsc.output.descriptor = StreamDescriptor::from_file(new_stdout_fd, false);
   }
 
-  while (!g_vsc.sent_terminated_event) {
-llvm::json::Object object;
-lldb_vscode::PacketStatus status = g_vsc.GetNextObject(object);
-if (status == lldb_vscode::PacketStatus::EndOfFile)
-  break;
-if (status != lldb_vscode::PacketStatus::Success)
-  return 1; // Fatal error
-
-if (!g_vsc.HandleObject(object))
-  return 1;
+  bool CleanExit = true;
+  if (auto Err = g_vsc.Loop()) {
+if (g_vsc.log)
+  *g_vsc.log << "Transport Error: " << llvm::toString(std::move(Err))
+ << "\n";
+CleanExit = false;
   }
 
-  return EXIT_SUCCESS;
+  return CleanExit ? EXIT_SUCCESS : EXIT_FAILURE;
 }
Index: lldb/tools/lldb-vscode/VSCode.h
===
--- lldb/tools/lldb-vscode/VSCode.h
+++ lldb/tools/lldb-vscode/VSCode.h
@@ -11,8 +11,10 @@
 
 #include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -121,6 +123,11 @@
   void Clear();
 };
 
+struct StartDebuggingRequestHandler : public lldb::SBCommandPluginInterface {
+  bool DoExecute(lldb::SBDebugger debugger, char **command,
+ lldb::SBCommandReturnObject &result) override;
+};
+
 struct VSCode {
   std::string debug_adaptor_path

[Lldb-commits] [lldb] d10a61c - [lldb/test] Disable TestStackCoreScriptedProcess.py

2023-06-21 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-06-21T14:05:55-07:00
New Revision: d10a61c8d2666a00ad483c71e72b49412a57c2bd

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

LOG: [lldb/test] Disable TestStackCoreScriptedProcess.py

This patch disables TestStackCoreScriptedProcess.py since it times out
non deterministicly.

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 

lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
 
b/lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
index 28f8630ba8611..bf9681ad678b6 100644
--- 
a/lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
+++ 
b/lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
@@ -35,6 +35,7 @@ def get_module_with_name(self, target, name):
 @skipIfOutOfTreeDebugserver
 @skipIfRemote
 @skipIfAsan  # On ASAN builds, this test times-out (rdar://98678134)
+@skipIfDarwin
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
 line, check its process ID and read string from memory."""



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


[Lldb-commits] [PATCH] D152848: [lldb] Fix failure in TestStackCoreScriptedProcess on x86_64

2023-06-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0c5b6320716b: [lldb] Fix failure in 
TestStackCoreScriptedProcess on x86_64 (authored by mib).

Changed prior to commit:
  https://reviews.llvm.org/D152848?vs=531017&id=57#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152848

Files:
  lldb/include/lldb/Utility/StructuredData.h
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py


Index: 
lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
===
--- 
lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
+++ 
lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
@@ -35,7 +35,6 @@
 @skipIfOutOfTreeDebugserver
 @skipIfRemote
 @skipIfAsan  # On ASAN builds, this test times-out (rdar://98678134)
-@skipIfDarwin
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
 line, check its process ID and read string from memory."""
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -250,10 +250,12 @@
 StopInfo::CreateStopReasonWithBreakpointSiteID(*this, break_id);
   } break;
   case lldb::eStopReasonSignal: {
-int signal;
+uint32_t signal;
 llvm::StringRef description;
-data_dict->GetValueForKeyAsInteger("signal", signal,
-   LLDB_INVALID_SIGNAL_NUMBER);
+if (!data_dict->GetValueForKeyAsInteger("signal", signal)) {
+signal = LLDB_INVALID_SIGNAL_NUMBER;
+return false;
+}
 data_dict->GetValueForKeyAsString("desc", description);
 stop_info_sp =
 StopInfo::CreateStopReasonWithSignal(*this, signal, 
description.data());
Index: lldb/include/lldb/Utility/StructuredData.h
===
--- lldb/include/lldb/Utility/StructuredData.h
+++ lldb/include/lldb/Utility/StructuredData.h
@@ -484,6 +484,7 @@
   }
   return success;
 }
+  
 template 
 bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const {
   ObjectSP value_sp = GetValueForKey(key);


Index: lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
@@ -35,7 +35,6 @@
 @skipIfOutOfTreeDebugserver
 @skipIfRemote
 @skipIfAsan  # On ASAN builds, this test times-out (rdar://98678134)
-@skipIfDarwin
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
 line, check its process ID and read string from memory."""
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -250,10 +250,12 @@
 StopInfo::CreateStopReasonWithBreakpointSiteID(*this, break_id);
   } break;
   case lldb::eStopReasonSignal: {
-int signal;
+uint32_t signal;
 llvm::StringRef description;
-data_dict->GetValueForKeyAsInteger("signal", signal,
-   LLDB_INVALID_SIGNAL_NUMBER);
+if (!data_dict->GetValueForKeyAsInteger("signal", signal)) {
+signal = LLDB_INVALID_SIGNAL_NUMBER;
+return false;
+}
 data_dict->GetValueForKeyAsString("desc", description);
 stop_info_sp =
 StopInfo::CreateStopReasonWithSignal(*this, signal, description.data());
Index: lldb/include/lldb/Utility/StructuredData.h
===
--- lldb/include/lldb/Utility/StructuredData.h
+++ lldb/include/lldb/Utility/StructuredData.h
@@ -484,6 +484,7 @@
   }
   return success;
 }
+  
 template 
 bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const {
   ObjectSP value_sp = GetValueForKey(key);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 0c5b632 - [lldb] Fix failure in TestStackCoreScriptedProcess on x86_64

2023-06-21 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-06-21T10:57:13-07:00
New Revision: 0c5b6320716b4761f2c4307bc95197be5717d132

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

LOG: [lldb] Fix failure in TestStackCoreScriptedProcess on x86_64

This patch should address the failure of TestStackCoreScriptedProcess
that is happening specifically on x86_64.

It turns out that in 1370a1cb5b97, I changed the way we extract integers
from a `StructuredData::Dictionary` and in order to get a stop info from
the scripted process, we call a method that returns a `SBStructuredData`
containing the stop reason data.

TestStackCoreScriptedProcess` was failing specifically on x86_64 because
the stop info dictionary contains the signal number, that the `Scripted
Thread` was trying to extract as a signed integer where it was actually
parsed as an unsigned integer. That caused `GetValueForKeyAsInteger` to
return the default value parameter, `LLDB_INVALID_SIGNAL_NUMBER`.

This patch address the issue by extracting the signal number with the
appropriate type and re-enables the test.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/Utility/StructuredData.h
lldb/source/Plugins/Process/scripted/ScriptedThread.cpp

lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py

Removed: 




diff  --git a/lldb/include/lldb/Utility/StructuredData.h 
b/lldb/include/lldb/Utility/StructuredData.h
index 28c71a8ca827a..3d30641934043 100644
--- a/lldb/include/lldb/Utility/StructuredData.h
+++ b/lldb/include/lldb/Utility/StructuredData.h
@@ -484,6 +484,7 @@ class StructuredData {
   }
   return success;
 }
+  
 template 
 bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const {
   ObjectSP value_sp = GetValueForKey(key);

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index fa2ee723e093b..684375957d247 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -250,10 +250,12 @@ bool ScriptedThread::CalculateStopInfo() {
 StopInfo::CreateStopReasonWithBreakpointSiteID(*this, break_id);
   } break;
   case lldb::eStopReasonSignal: {
-int signal;
+uint32_t signal;
 llvm::StringRef description;
-data_dict->GetValueForKeyAsInteger("signal", signal,
-   LLDB_INVALID_SIGNAL_NUMBER);
+if (!data_dict->GetValueForKeyAsInteger("signal", signal)) {
+signal = LLDB_INVALID_SIGNAL_NUMBER;
+return false;
+}
 data_dict->GetValueForKeyAsString("desc", description);
 stop_info_sp =
 StopInfo::CreateStopReasonWithSignal(*this, signal, 
description.data());

diff  --git 
a/lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
 
b/lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
index bf9681ad678b6..28f8630ba8611 100644
--- 
a/lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
+++ 
b/lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
@@ -35,7 +35,6 @@ def get_module_with_name(self, target, name):
 @skipIfOutOfTreeDebugserver
 @skipIfRemote
 @skipIfAsan  # On ASAN builds, this test times-out (rdar://98678134)
-@skipIfDarwin
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
 line, check its process ID and read string from memory."""



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


[Lldb-commits] [PATCH] D153433: [lldb][MachO] Fix section type recognition for new DWARF 5 sections

2023-06-21 Thread Felipe de Azevedo Piovezan via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1704c8d1047d: [lldb][MachO] Fix section type recognition for 
new DWARF 5 sections (authored by fdeazeve).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153433

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


Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1439,19 +1439,32 @@
   static ConstString g_sect_name_cfstring("__cfstring");
 
   static ConstString g_sect_name_dwarf_debug_abbrev("__debug_abbrev");
+  static ConstString g_sect_name_dwarf_debug_abbrev_dwo("__debug_abbrev.dwo");
+  static ConstString g_sect_name_dwarf_debug_addr("__debug_addr");
   static ConstString g_sect_name_dwarf_debug_aranges("__debug_aranges");
+  static ConstString g_sect_name_dwarf_debug_cu_index("__debug_cu_index");
   static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
   static ConstString g_sect_name_dwarf_debug_info("__debug_info");
+  static ConstString g_sect_name_dwarf_debug_info_dwo("__debug_info.dwo");
   static ConstString g_sect_name_dwarf_debug_line("__debug_line");
+  static ConstString g_sect_name_dwarf_debug_line_dwo("__debug_line.dwo");
   static ConstString g_sect_name_dwarf_debug_line_str("__debug_line_str");
   static ConstString g_sect_name_dwarf_debug_loc("__debug_loc");
   static ConstString g_sect_name_dwarf_debug_loclists("__debug_loclists");
+  static ConstString 
g_sect_name_dwarf_debug_loclists_dwo("__debug_loclists.dwo");
   static ConstString g_sect_name_dwarf_debug_macinfo("__debug_macinfo");
+  static ConstString g_sect_name_dwarf_debug_macro("__debug_macro");
+  static ConstString g_sect_name_dwarf_debug_macro_dwo("__debug_macro.dwo");
   static ConstString g_sect_name_dwarf_debug_names("__debug_names");
   static ConstString g_sect_name_dwarf_debug_pubnames("__debug_pubnames");
   static ConstString g_sect_name_dwarf_debug_pubtypes("__debug_pubtypes");
   static ConstString g_sect_name_dwarf_debug_ranges("__debug_ranges");
+  static ConstString g_sect_name_dwarf_debug_rnglists("__debug_rnglists");
   static ConstString g_sect_name_dwarf_debug_str("__debug_str");
+  static ConstString g_sect_name_dwarf_debug_str_dwo("__debug_str.dwo");
+  static ConstString g_sect_name_dwarf_debug_str_offs("__debug_str_offs");
+  static ConstString 
g_sect_name_dwarf_debug_str_offs_dwo("__debug_str_offs.dwo");
+  static ConstString g_sect_name_dwarf_debug_tu_index("__debug_tu_index");
   static ConstString g_sect_name_dwarf_debug_types("__debug_types");
   static ConstString g_sect_name_dwarf_apple_names("__apple_names");
   static ConstString g_sect_name_dwarf_apple_types("__apple_types");
@@ -1465,22 +1478,38 @@
 
   if (section_name == g_sect_name_dwarf_debug_abbrev)
 return eSectionTypeDWARFDebugAbbrev;
+  if (section_name == g_sect_name_dwarf_debug_abbrev_dwo)
+return eSectionTypeDWARFDebugAbbrevDwo;
+  if (section_name == g_sect_name_dwarf_debug_addr)
+return eSectionTypeDWARFDebugAddr;
   if (section_name == g_sect_name_dwarf_debug_aranges)
 return eSectionTypeDWARFDebugAranges;
+  if (section_name == g_sect_name_dwarf_debug_cu_index)
+return eSectionTypeDWARFDebugCuIndex;
   if (section_name == g_sect_name_dwarf_debug_frame)
 return eSectionTypeDWARFDebugFrame;
   if (section_name == g_sect_name_dwarf_debug_info)
 return eSectionTypeDWARFDebugInfo;
+  if (section_name == g_sect_name_dwarf_debug_info_dwo)
+return eSectionTypeDWARFDebugInfoDwo;
   if (section_name == g_sect_name_dwarf_debug_line)
 return eSectionTypeDWARFDebugLine;
+  if (section_name == g_sect_name_dwarf_debug_line_dwo)
+return eSectionTypeDWARFDebugLine; // Same as debug_line.
   if (section_name == g_sect_name_dwarf_debug_line_str)
 return eSectionTypeDWARFDebugLineStr;
   if (section_name == g_sect_name_dwarf_debug_loc)
 return eSectionTypeDWARFDebugLoc;
   if (section_name == g_sect_name_dwarf_debug_loclists)
 return eSectionTypeDWARFDebugLocLists;
+  if (section_name == g_sect_name_dwarf_debug_loclists_dwo)
+return eSectionTypeDWARFDebugLocListsDwo;
   if (section_name == g_sect_name_dwarf_debug_macinfo)
 return eSectionTypeDWARFDebugMacInfo;
+  if (section_name == g_sect_name_dwarf_debug_macro)
+return eSectionTypeDWARFDebugMacro;
+  if (section_name == g_sect_name_dwarf_debug_macro_dwo)
+return eSectionTypeDWARFDebugMacInfo; // Same as debug_macro.
   if (section_name == g_sect_name_dwarf_debug_names)
 return eSectionTypeDWARFDebugNames;
   if (section_name == g_sect_name_dwarf_debug_pubnames)
@@ -1489,8 +1518,18 @@
 return eSectionTypeDWARFDebugPubTypes;
   if (section_name == g_sect_name_dwarf_debug_ranges)
 return eSectionTypeD

[Lldb-commits] [lldb] 1704c8d - [lldb][MachO] Fix section type recognition for new DWARF 5 sections

2023-06-21 Thread Felipe de Azevedo Piovezan via lldb-commits

Author: Felipe de Azevedo Piovezan
Date: 2023-06-21T13:25:10-04:00
New Revision: 1704c8d1047d75e0f17736de146281d68fe7b203

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

LOG: [lldb][MachO] Fix section type recognition for new DWARF 5 sections

When LLDB needs to access a debug section, it generally calls
SectionList::FindSectionByType with the corresponding type (we have one type for
each DWARF section). However, the missing entries made some sections be
classified as "eSectionTypeOther", which makes all calls to `FindSectionByType`
fail.

With this patch, a check-lldb build with
`-DLLDB_TEST_USER_ARGS=--dwarf-version=5` reports a much lower number of
failures:

  Unsupported  :  327
  Passed   : 2423
  Expectedly Failed:   16
  Unresolved   :2
  Failed   :   52

This is down from previously 400~ failures.

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

Added: 


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

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 5fddb4e6eadd0..ce904b0a9c7a0 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1439,19 +1439,32 @@ static lldb::SectionType GetSectionType(uint32_t flags,
   static ConstString g_sect_name_cfstring("__cfstring");
 
   static ConstString g_sect_name_dwarf_debug_abbrev("__debug_abbrev");
+  static ConstString g_sect_name_dwarf_debug_abbrev_dwo("__debug_abbrev.dwo");
+  static ConstString g_sect_name_dwarf_debug_addr("__debug_addr");
   static ConstString g_sect_name_dwarf_debug_aranges("__debug_aranges");
+  static ConstString g_sect_name_dwarf_debug_cu_index("__debug_cu_index");
   static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
   static ConstString g_sect_name_dwarf_debug_info("__debug_info");
+  static ConstString g_sect_name_dwarf_debug_info_dwo("__debug_info.dwo");
   static ConstString g_sect_name_dwarf_debug_line("__debug_line");
+  static ConstString g_sect_name_dwarf_debug_line_dwo("__debug_line.dwo");
   static ConstString g_sect_name_dwarf_debug_line_str("__debug_line_str");
   static ConstString g_sect_name_dwarf_debug_loc("__debug_loc");
   static ConstString g_sect_name_dwarf_debug_loclists("__debug_loclists");
+  static ConstString 
g_sect_name_dwarf_debug_loclists_dwo("__debug_loclists.dwo");
   static ConstString g_sect_name_dwarf_debug_macinfo("__debug_macinfo");
+  static ConstString g_sect_name_dwarf_debug_macro("__debug_macro");
+  static ConstString g_sect_name_dwarf_debug_macro_dwo("__debug_macro.dwo");
   static ConstString g_sect_name_dwarf_debug_names("__debug_names");
   static ConstString g_sect_name_dwarf_debug_pubnames("__debug_pubnames");
   static ConstString g_sect_name_dwarf_debug_pubtypes("__debug_pubtypes");
   static ConstString g_sect_name_dwarf_debug_ranges("__debug_ranges");
+  static ConstString g_sect_name_dwarf_debug_rnglists("__debug_rnglists");
   static ConstString g_sect_name_dwarf_debug_str("__debug_str");
+  static ConstString g_sect_name_dwarf_debug_str_dwo("__debug_str.dwo");
+  static ConstString g_sect_name_dwarf_debug_str_offs("__debug_str_offs");
+  static ConstString 
g_sect_name_dwarf_debug_str_offs_dwo("__debug_str_offs.dwo");
+  static ConstString g_sect_name_dwarf_debug_tu_index("__debug_tu_index");
   static ConstString g_sect_name_dwarf_debug_types("__debug_types");
   static ConstString g_sect_name_dwarf_apple_names("__apple_names");
   static ConstString g_sect_name_dwarf_apple_types("__apple_types");
@@ -1465,22 +1478,38 @@ static lldb::SectionType GetSectionType(uint32_t flags,
 
   if (section_name == g_sect_name_dwarf_debug_abbrev)
 return eSectionTypeDWARFDebugAbbrev;
+  if (section_name == g_sect_name_dwarf_debug_abbrev_dwo)
+return eSectionTypeDWARFDebugAbbrevDwo;
+  if (section_name == g_sect_name_dwarf_debug_addr)
+return eSectionTypeDWARFDebugAddr;
   if (section_name == g_sect_name_dwarf_debug_aranges)
 return eSectionTypeDWARFDebugAranges;
+  if (section_name == g_sect_name_dwarf_debug_cu_index)
+return eSectionTypeDWARFDebugCuIndex;
   if (section_name == g_sect_name_dwarf_debug_frame)
 return eSectionTypeDWARFDebugFrame;
   if (section_name == g_sect_name_dwarf_debug_info)
 return eSectionTypeDWARFDebugInfo;
+  if (section_name == g_sect_name_dwarf_debug_info_dwo)
+return eSectionTypeDWARFDebugInfoDwo;
   if (section_name == g_sect_name_dwarf_debug_line)
 return eSectionTypeDWARFDebugLine;
+  if (section_name == g_sect_name_dwarf_debug_line_dwo)
+return eSectionTypeDWARFDebugLine; // Same as debug_line.
   if (section_name == g_sect_name_dw

[Lldb-commits] [PATCH] D153177: [lldb][NFCI] Remove ConstString from GDBRemoteCommunicationClient::ConfigureRemoteStructuredData

2023-06-21 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb4827a3c0a7e: [lldb][NFCI] Remove ConstString from 
GDBRemoteCommunicationClient… (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153177

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -492,7 +492,7 @@
   ///
   /// \see \b Process::ConfigureStructuredData(...) for details.
   Status
-  ConfigureRemoteStructuredData(ConstString type_name,
+  ConfigureRemoteStructuredData(llvm::StringRef type_name,
 const StructuredData::ObjectSP &config_sp);
 
   llvm::Expected
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4171,10 +4171,10 @@
 }
 
 Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
-ConstString type_name, const StructuredData::ObjectSP &config_sp) {
+llvm::StringRef type_name, const StructuredData::ObjectSP &config_sp) {
   Status error;
 
-  if (type_name.GetLength() == 0) {
+  if (type_name.empty()) {
 error.SetErrorString("invalid type_name argument");
 return error;
   }
@@ -4182,7 +4182,7 @@
   // Build command: Configure{type_name}: serialized config data.
   StreamGDBRemote stream;
   stream.PutCString("QConfigure");
-  stream.PutCString(type_name.GetStringRef());
+  stream.PutCString(type_name);
   stream.PutChar(':');
   if (config_sp) {
 // Gather the plain-text version of the configuration data.
@@ -4201,21 +4201,20 @@
   auto result = SendPacketAndWaitForResponse(stream.GetString(), response);
   if (result == PacketResult::Success) {
 // We failed if the config result comes back other than OK.
-if (strcmp(response.GetStringRef().data(), "OK") == 0) {
+if (response.GetStringRef() == "OK") {
   // Okay!
   error.Clear();
 } else {
-  error.SetErrorStringWithFormat("configuring StructuredData feature "
- "%s failed with error %s",
- type_name.AsCString(),
- response.GetStringRef().data());
+  error.SetErrorStringWithFormatv(
+  "configuring StructuredData feature {0} failed with error {1}",
+  type_name, response.GetStringRef());
 }
   } else {
 // Can we get more data here on the failure?
-error.SetErrorStringWithFormat("configuring StructuredData feature %s "
-   "failed when sending packet: "
-   "PacketResult=%d",
-   type_name.AsCString(), (int)result);
+error.SetErrorStringWithFormatv(
+"configuring StructuredData feature {0} failed when sending packet: "
+"PacketResult={1}",
+type_name, (int)result);
   }
   return error;
 }


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -492,7 +492,7 @@
   ///
   /// \see \b Process::ConfigureStructuredData(...) for details.
   Status
-  ConfigureRemoteStructuredData(ConstString type_name,
+  ConfigureRemoteStructuredData(llvm::StringRef type_name,
 const StructuredData::ObjectSP &config_sp);
 
   llvm::Expected
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4171,10 +4171,10 @@
 }
 
 Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
-ConstString type_name, const StructuredData::ObjectSP &config_sp) {
+llvm::StringRef type_name, const StructuredData::ObjectSP &config_sp) {
   Status error;
 
-  if (type_name.GetLength() == 0) {
+  if (type_name.empty()) {
 error.SetErrorString("invalid type_name argument");
 return error;
   }
@@ -4182,7 +4182,7 @@
   // Build command: Configure{type_name}: serialized config data.
   StreamGDBRemote stream;
   stream.PutCString("QConfigure");
-  stream.PutCStr

[Lldb-commits] [lldb] b4827a3 - [lldb][NFCI] Remove ConstString from GDBRemoteCommunicationClient::ConfigureRemoteStructuredData

2023-06-21 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-06-21T10:17:24-07:00
New Revision: b4827a3c0a7ef121ca376713e115b04eff0f5194

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

LOG: [lldb][NFCI] Remove ConstString from 
GDBRemoteCommunicationClient::ConfigureRemoteStructuredData

ConstString's benefits are not being utilized here, StringRef is
sufficient.

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

Added: 


Modified: 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index d97e3a7cf8f96..18aa98bc04649 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4171,10 +4171,10 @@ Status 
GDBRemoteCommunicationClient::SendSignalsToIgnore(
 }
 
 Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
-ConstString type_name, const StructuredData::ObjectSP &config_sp) {
+llvm::StringRef type_name, const StructuredData::ObjectSP &config_sp) {
   Status error;
 
-  if (type_name.GetLength() == 0) {
+  if (type_name.empty()) {
 error.SetErrorString("invalid type_name argument");
 return error;
   }
@@ -4182,7 +4182,7 @@ Status 
GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
   // Build command: Configure{type_name}: serialized config data.
   StreamGDBRemote stream;
   stream.PutCString("QConfigure");
-  stream.PutCString(type_name.GetStringRef());
+  stream.PutCString(type_name);
   stream.PutChar(':');
   if (config_sp) {
 // Gather the plain-text version of the configuration data.
@@ -4201,21 +4201,20 @@ Status 
GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
   auto result = SendPacketAndWaitForResponse(stream.GetString(), response);
   if (result == PacketResult::Success) {
 // We failed if the config result comes back other than OK.
-if (strcmp(response.GetStringRef().data(), "OK") == 0) {
+if (response.GetStringRef() == "OK") {
   // Okay!
   error.Clear();
 } else {
-  error.SetErrorStringWithFormat("configuring StructuredData feature "
- "%s failed with error %s",
- type_name.AsCString(),
- response.GetStringRef().data());
+  error.SetErrorStringWithFormatv(
+  "configuring StructuredData feature {0} failed with error {1}",
+  type_name, response.GetStringRef());
 }
   } else {
 // Can we get more data here on the failure?
-error.SetErrorStringWithFormat("configuring StructuredData feature %s "
-   "failed when sending packet: "
-   "PacketResult=%d",
-   type_name.AsCString(), (int)result);
+error.SetErrorStringWithFormatv(
+"configuring StructuredData feature {0} failed when sending packet: "
+"PacketResult={1}",
+type_name, (int)result);
   }
   return error;
 }

diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
index 02185cf52e33e..6cf5de68911be 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -492,7 +492,7 @@ class GDBRemoteCommunicationClient : public 
GDBRemoteClientBase {
   ///
   /// \see \b Process::ConfigureStructuredData(...) for details.
   Status
-  ConfigureRemoteStructuredData(ConstString type_name,
+  ConfigureRemoteStructuredData(llvm::StringRef type_name,
 const StructuredData::ObjectSP &config_sp);
 
   llvm::Expected



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


[Lldb-commits] [PATCH] D153433: [lldb][MachO] Fix section type recognition for new DWARF 5 sections

2023-06-21 Thread Felipe de Azevedo Piovezan via Phabricator via lldb-commits
fdeazeve updated this revision to Diff 533320.
fdeazeve added a comment.

Add missing dwo sections


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153433

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


Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1439,19 +1439,32 @@
   static ConstString g_sect_name_cfstring("__cfstring");
 
   static ConstString g_sect_name_dwarf_debug_abbrev("__debug_abbrev");
+  static ConstString g_sect_name_dwarf_debug_abbrev_dwo("__debug_abbrev.dwo");
+  static ConstString g_sect_name_dwarf_debug_addr("__debug_addr");
   static ConstString g_sect_name_dwarf_debug_aranges("__debug_aranges");
+  static ConstString g_sect_name_dwarf_debug_cu_index("__debug_cu_index");
   static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
   static ConstString g_sect_name_dwarf_debug_info("__debug_info");
+  static ConstString g_sect_name_dwarf_debug_info_dwo("__debug_info.dwo");
   static ConstString g_sect_name_dwarf_debug_line("__debug_line");
+  static ConstString g_sect_name_dwarf_debug_line_dwo("__debug_line.dwo");
   static ConstString g_sect_name_dwarf_debug_line_str("__debug_line_str");
   static ConstString g_sect_name_dwarf_debug_loc("__debug_loc");
   static ConstString g_sect_name_dwarf_debug_loclists("__debug_loclists");
+  static ConstString 
g_sect_name_dwarf_debug_loclists_dwo("__debug_loclists.dwo");
   static ConstString g_sect_name_dwarf_debug_macinfo("__debug_macinfo");
+  static ConstString g_sect_name_dwarf_debug_macro("__debug_macro");
+  static ConstString g_sect_name_dwarf_debug_macro_dwo("__debug_macro.dwo");
   static ConstString g_sect_name_dwarf_debug_names("__debug_names");
   static ConstString g_sect_name_dwarf_debug_pubnames("__debug_pubnames");
   static ConstString g_sect_name_dwarf_debug_pubtypes("__debug_pubtypes");
   static ConstString g_sect_name_dwarf_debug_ranges("__debug_ranges");
+  static ConstString g_sect_name_dwarf_debug_rnglists("__debug_rnglists");
   static ConstString g_sect_name_dwarf_debug_str("__debug_str");
+  static ConstString g_sect_name_dwarf_debug_str_dwo("__debug_str.dwo");
+  static ConstString g_sect_name_dwarf_debug_str_offs("__debug_str_offs");
+  static ConstString 
g_sect_name_dwarf_debug_str_offs_dwo("__debug_str_offs.dwo");
+  static ConstString g_sect_name_dwarf_debug_tu_index("__debug_tu_index");
   static ConstString g_sect_name_dwarf_debug_types("__debug_types");
   static ConstString g_sect_name_dwarf_apple_names("__apple_names");
   static ConstString g_sect_name_dwarf_apple_types("__apple_types");
@@ -1465,22 +1478,38 @@
 
   if (section_name == g_sect_name_dwarf_debug_abbrev)
 return eSectionTypeDWARFDebugAbbrev;
+  if (section_name == g_sect_name_dwarf_debug_abbrev_dwo)
+return eSectionTypeDWARFDebugAbbrevDwo;
+  if (section_name == g_sect_name_dwarf_debug_addr)
+return eSectionTypeDWARFDebugAddr;
   if (section_name == g_sect_name_dwarf_debug_aranges)
 return eSectionTypeDWARFDebugAranges;
+  if (section_name == g_sect_name_dwarf_debug_cu_index)
+return eSectionTypeDWARFDebugCuIndex;
   if (section_name == g_sect_name_dwarf_debug_frame)
 return eSectionTypeDWARFDebugFrame;
   if (section_name == g_sect_name_dwarf_debug_info)
 return eSectionTypeDWARFDebugInfo;
+  if (section_name == g_sect_name_dwarf_debug_info_dwo)
+return eSectionTypeDWARFDebugInfoDwo;
   if (section_name == g_sect_name_dwarf_debug_line)
 return eSectionTypeDWARFDebugLine;
+  if (section_name == g_sect_name_dwarf_debug_line_dwo)
+return eSectionTypeDWARFDebugLine; // Same as debug_line.
   if (section_name == g_sect_name_dwarf_debug_line_str)
 return eSectionTypeDWARFDebugLineStr;
   if (section_name == g_sect_name_dwarf_debug_loc)
 return eSectionTypeDWARFDebugLoc;
   if (section_name == g_sect_name_dwarf_debug_loclists)
 return eSectionTypeDWARFDebugLocLists;
+  if (section_name == g_sect_name_dwarf_debug_loclists_dwo)
+return eSectionTypeDWARFDebugLocListsDwo;
   if (section_name == g_sect_name_dwarf_debug_macinfo)
 return eSectionTypeDWARFDebugMacInfo;
+  if (section_name == g_sect_name_dwarf_debug_macro)
+return eSectionTypeDWARFDebugMacro;
+  if (section_name == g_sect_name_dwarf_debug_macro_dwo)
+return eSectionTypeDWARFDebugMacInfo; // Same as debug_macro.
   if (section_name == g_sect_name_dwarf_debug_names)
 return eSectionTypeDWARFDebugNames;
   if (section_name == g_sect_name_dwarf_debug_pubnames)
@@ -1489,8 +1518,18 @@
 return eSectionTypeDWARFDebugPubTypes;
   if (section_name == g_sect_name_dwarf_debug_ranges)
 return eSectionTypeDWARFDebugRanges;
+  if (section_name == g_sect_name_dwarf_debug_rnglists)
+return eSectionTypeDW

[Lldb-commits] [PATCH] D153433: [lldb][MachO] Fix section type recognition for new DWARF 5 sections

2023-06-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere 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/D153433/new/

https://reviews.llvm.org/D153433

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


[Lldb-commits] [PATCH] D153433: [lldb][MachO] Fix section type recognition for new DWARF 5 sections

2023-06-21 Thread Felipe de Azevedo Piovezan via Phabricator via lldb-commits
fdeazeve updated this revision to Diff 533281.
fdeazeve added a comment.

Add missing debug_cu_index and debug_tu_index sections


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153433

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


Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1439,7 +1439,9 @@
   static ConstString g_sect_name_cfstring("__cfstring");
 
   static ConstString g_sect_name_dwarf_debug_abbrev("__debug_abbrev");
+  static ConstString g_sect_name_dwarf_debug_addr("__debug_addr");
   static ConstString g_sect_name_dwarf_debug_aranges("__debug_aranges");
+  static ConstString g_sect_name_dwarf_debug_cu_index("__debug_cu_index");
   static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
   static ConstString g_sect_name_dwarf_debug_info("__debug_info");
   static ConstString g_sect_name_dwarf_debug_line("__debug_line");
@@ -1451,7 +1453,10 @@
   static ConstString g_sect_name_dwarf_debug_pubnames("__debug_pubnames");
   static ConstString g_sect_name_dwarf_debug_pubtypes("__debug_pubtypes");
   static ConstString g_sect_name_dwarf_debug_ranges("__debug_ranges");
+  static ConstString g_sect_name_dwarf_debug_rnglists("__debug_rnglists");
   static ConstString g_sect_name_dwarf_debug_str("__debug_str");
+  static ConstString g_sect_name_dwarf_debug_str_offs("__debug_str_offs");
+  static ConstString g_sect_name_dwarf_debug_tu_index("__debug_tu_index");
   static ConstString g_sect_name_dwarf_debug_types("__debug_types");
   static ConstString g_sect_name_dwarf_apple_names("__apple_names");
   static ConstString g_sect_name_dwarf_apple_types("__apple_types");
@@ -1465,8 +1470,12 @@
 
   if (section_name == g_sect_name_dwarf_debug_abbrev)
 return eSectionTypeDWARFDebugAbbrev;
+  if (section_name == g_sect_name_dwarf_debug_addr)
+return eSectionTypeDWARFDebugAddr;
   if (section_name == g_sect_name_dwarf_debug_aranges)
 return eSectionTypeDWARFDebugAranges;
+  if (section_name == g_sect_name_dwarf_debug_cu_index)
+return eSectionTypeDWARFDebugCuIndex;
   if (section_name == g_sect_name_dwarf_debug_frame)
 return eSectionTypeDWARFDebugFrame;
   if (section_name == g_sect_name_dwarf_debug_info)
@@ -1489,8 +1498,14 @@
 return eSectionTypeDWARFDebugPubTypes;
   if (section_name == g_sect_name_dwarf_debug_ranges)
 return eSectionTypeDWARFDebugRanges;
+  if (section_name == g_sect_name_dwarf_debug_rnglists)
+return eSectionTypeDWARFDebugRngLists;
   if (section_name == g_sect_name_dwarf_debug_str)
 return eSectionTypeDWARFDebugStr;
+  if (section_name == g_sect_name_dwarf_debug_str_offs)
+return eSectionTypeDWARFDebugStrOffsets;
+  if (section_name == g_sect_name_dwarf_debug_tu_index)
+return eSectionTypeDWARFDebugTuIndex;
   if (section_name == g_sect_name_dwarf_debug_types)
 return eSectionTypeDWARFDebugTypes;
   if (section_name == g_sect_name_dwarf_apple_names)


Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1439,7 +1439,9 @@
   static ConstString g_sect_name_cfstring("__cfstring");
 
   static ConstString g_sect_name_dwarf_debug_abbrev("__debug_abbrev");
+  static ConstString g_sect_name_dwarf_debug_addr("__debug_addr");
   static ConstString g_sect_name_dwarf_debug_aranges("__debug_aranges");
+  static ConstString g_sect_name_dwarf_debug_cu_index("__debug_cu_index");
   static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
   static ConstString g_sect_name_dwarf_debug_info("__debug_info");
   static ConstString g_sect_name_dwarf_debug_line("__debug_line");
@@ -1451,7 +1453,10 @@
   static ConstString g_sect_name_dwarf_debug_pubnames("__debug_pubnames");
   static ConstString g_sect_name_dwarf_debug_pubtypes("__debug_pubtypes");
   static ConstString g_sect_name_dwarf_debug_ranges("__debug_ranges");
+  static ConstString g_sect_name_dwarf_debug_rnglists("__debug_rnglists");
   static ConstString g_sect_name_dwarf_debug_str("__debug_str");
+  static ConstString g_sect_name_dwarf_debug_str_offs("__debug_str_offs");
+  static ConstString g_sect_name_dwarf_debug_tu_index("__debug_tu_index");
   static ConstString g_sect_name_dwarf_debug_types("__debug_types");
   static ConstString g_sect_name_dwarf_apple_names("__apple_names");
   static ConstString g_sect_name_dwarf_apple_types("__apple_types");
@@ -1465,8 +1470,12 @@
 
   if (section_name == g_sect_name_dwarf_debug_abbrev)
 return eSectionTypeDWARFDebugAbbrev;
+  if (section_name == g_sect_name_dwarf_debug_addr)
+return eSectionTypeDWARFDebugAddr;

[Lldb-commits] [PATCH] D153433: [lldb][MachO] Fix section type recognition for new DWARF 5 sections

2023-06-21 Thread Felipe de Azevedo Piovezan via Phabricator via lldb-commits
fdeazeve created this revision.
fdeazeve added a reviewer: aprantl.
Herald added a project: All.
fdeazeve requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

When LLDB needs to access a debug section, it generally calls
SectionList::FindSectionByType with the corresponding type (we have one type for
each DWARF section). However, the missing entries made some sections be
classified as "eSectionTypeOther", which makes all calls to `FindSectionByType`
fail.

With this patch, a check-lldb build with
`-DLLDB_TEST_USER_ARGS=--dwarf-version=5` reports a much lower number of
failures:

  Unsupported  :  327
  Passed   : 2423
  Expectedly Failed:   16
  Unresolved   :2
  Failed   :   52

This is down from previously 400~ failures.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153433

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


Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1439,6 +1439,7 @@
   static ConstString g_sect_name_cfstring("__cfstring");
 
   static ConstString g_sect_name_dwarf_debug_abbrev("__debug_abbrev");
+  static ConstString g_sect_name_dwarf_debug_addr("__debug_addr");
   static ConstString g_sect_name_dwarf_debug_aranges("__debug_aranges");
   static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
   static ConstString g_sect_name_dwarf_debug_info("__debug_info");
@@ -1451,7 +1452,9 @@
   static ConstString g_sect_name_dwarf_debug_pubnames("__debug_pubnames");
   static ConstString g_sect_name_dwarf_debug_pubtypes("__debug_pubtypes");
   static ConstString g_sect_name_dwarf_debug_ranges("__debug_ranges");
+  static ConstString g_sect_name_dwarf_debug_rnglists("__debug_rnglists");
   static ConstString g_sect_name_dwarf_debug_str("__debug_str");
+  static ConstString g_sect_name_dwarf_debug_str_offs("__debug_str_offs");
   static ConstString g_sect_name_dwarf_debug_types("__debug_types");
   static ConstString g_sect_name_dwarf_apple_names("__apple_names");
   static ConstString g_sect_name_dwarf_apple_types("__apple_types");
@@ -1465,6 +1468,8 @@
 
   if (section_name == g_sect_name_dwarf_debug_abbrev)
 return eSectionTypeDWARFDebugAbbrev;
+  if (section_name == g_sect_name_dwarf_debug_addr)
+return eSectionTypeDWARFDebugAddr;
   if (section_name == g_sect_name_dwarf_debug_aranges)
 return eSectionTypeDWARFDebugAranges;
   if (section_name == g_sect_name_dwarf_debug_frame)
@@ -1489,8 +1494,12 @@
 return eSectionTypeDWARFDebugPubTypes;
   if (section_name == g_sect_name_dwarf_debug_ranges)
 return eSectionTypeDWARFDebugRanges;
+  if (section_name == g_sect_name_dwarf_debug_rnglists)
+return eSectionTypeDWARFDebugRngLists;
   if (section_name == g_sect_name_dwarf_debug_str)
 return eSectionTypeDWARFDebugStr;
+  if (section_name == g_sect_name_dwarf_debug_str_offs)
+return eSectionTypeDWARFDebugStrOffsets;
   if (section_name == g_sect_name_dwarf_debug_types)
 return eSectionTypeDWARFDebugTypes;
   if (section_name == g_sect_name_dwarf_apple_names)


Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1439,6 +1439,7 @@
   static ConstString g_sect_name_cfstring("__cfstring");
 
   static ConstString g_sect_name_dwarf_debug_abbrev("__debug_abbrev");
+  static ConstString g_sect_name_dwarf_debug_addr("__debug_addr");
   static ConstString g_sect_name_dwarf_debug_aranges("__debug_aranges");
   static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
   static ConstString g_sect_name_dwarf_debug_info("__debug_info");
@@ -1451,7 +1452,9 @@
   static ConstString g_sect_name_dwarf_debug_pubnames("__debug_pubnames");
   static ConstString g_sect_name_dwarf_debug_pubtypes("__debug_pubtypes");
   static ConstString g_sect_name_dwarf_debug_ranges("__debug_ranges");
+  static ConstString g_sect_name_dwarf_debug_rnglists("__debug_rnglists");
   static ConstString g_sect_name_dwarf_debug_str("__debug_str");
+  static ConstString g_sect_name_dwarf_debug_str_offs("__debug_str_offs");
   static ConstString g_sect_name_dwarf_debug_types("__debug_types");
   static ConstString g_sect_name_dwarf_apple_names("__apple_names");
   static ConstString g_sect_name_dwarf_apple_types("__apple_types");
@@ -1465,6 +1468,8 @@
 
   if (section_name == g_sect_name_dwarf_debug_abbrev)
 return eSectionTypeDWARFDebugAbbrev;
+  if (section_name == g_sect_name_dwarf_debug_addr)
+return eSectionTypeDWARFDebugAddr;
   if (section_name == g_sect_name_dwarf_debug_aranges)
 return eSectionTypeDWARFDebugAranges;
   if (section_name 

[Lldb-commits] [PATCH] D152918: [lldb] Add register field tables to the "register info" command

2023-06-21 Thread David Spickett via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbcfe5a52a39d: [lldb] Add register field tables to the 
"register info" command (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152918

Files:
  lldb/include/lldb/Core/DumpRegisterInfo.h
  lldb/source/Commands/CommandObjectRegister.cpp
  lldb/source/Core/DumpRegisterInfo.cpp
  lldb/test/API/commands/register/register/register_command/TestRegisters.py
  lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py
  lldb/unittests/Core/DumpRegisterInfoTest.cpp

Index: lldb/unittests/Core/DumpRegisterInfoTest.cpp
===
--- lldb/unittests/Core/DumpRegisterInfoTest.cpp
+++ lldb/unittests/Core/DumpRegisterInfoTest.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "lldb/Core/DumpRegisterInfo.h"
+#include "lldb/Target/RegisterFlags.h"
 #include "lldb/Utility/StreamString.h"
 #include "gtest/gtest.h"
 
@@ -14,27 +15,28 @@
 
 TEST(DoDumpRegisterInfoTest, MinimumInfo) {
   StreamString strm;
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {}, nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)");
 }
 
 TEST(DoDumpRegisterInfoTest, AltName) {
   StreamString strm;
-  DoDumpRegisterInfo(strm, "foo", "bar", 4, {}, {}, {});
+  DoDumpRegisterInfo(strm, "foo", "bar", 4, {}, {}, {}, nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo (bar)\n"
   "   Size: 4 bytes (32 bits)");
 }
 
 TEST(DoDumpRegisterInfoTest, Invalidates) {
   StreamString strm;
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2"}, {}, {});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2"}, {}, {}, nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "Invalidates: foo2");
 
   strm.Clear();
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3", "foo4"}, {}, {});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3", "foo4"}, {}, {},
+ nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "Invalidates: foo2, foo3, foo4");
@@ -42,13 +44,14 @@
 
 TEST(DoDumpRegisterInfoTest, ReadFrom) {
   StreamString strm;
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1"}, {});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1"}, {}, nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "  Read from: foo1");
 
   strm.Clear();
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1", "foo2", "foo3"}, {});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1", "foo2", "foo3"}, {},
+ nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "  Read from: foo1, foo2, foo3");
@@ -56,14 +59,15 @@
 
 TEST(DoDumpRegisterInfoTest, InSets) {
   StreamString strm;
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {{"set1", 101}});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {{"set1", 101}}, nullptr,
+ 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "In sets: set1 (index 101)");
 
   strm.Clear();
   DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {},
- {{"set1", 0}, {"set2", 1}, {"set3", 2}});
+ {{"set1", 0}, {"set2", 1}, {"set3", 2}}, nullptr, 0);
   ASSERT_EQ(strm.GetString(),
 "   Name: foo\n"
 "   Size: 4 bytes (32 bits)\n"
@@ -73,10 +77,28 @@
 TEST(DoDumpRegisterInfoTest, MaxInfo) {
   StreamString strm;
   DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3"},
- {"foo3", "foo4"}, {{"set1", 1}, {"set2", 2}});
+ {"foo3", "foo4"}, {{"set1", 1}, {"set2", 2}}, nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "Invalidates: foo2, foo3\n"
   "  Read from: foo3, foo4\n"
   "In sets: set1 (index 1), set2 (index 2)");
 }
+
+TEST(DoDumpRegisterInfoTest, FieldsTable) {
+  // This is thoroughly tested in RegisterFlags itself, only checking the
+  // integration here.
+  StreamString strm;
+  RegisterFlags flags(
+  "", 4,
+  {

[Lldb-commits] [lldb] bcfe5a5 - [lldb] Add register field tables to the "register info" command

2023-06-21 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-06-21T10:50:31Z
New Revision: bcfe5a52a39dee6d50d5e2410863fc555d2f50a8

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

LOG: [lldb] Add register field tables to the "register info" command

This teaches DumpRegisterInfo to generate a table from the register
flags type. It just calls a method on RegisterFlags.

As such, the extra tests are minimal and only show that the intergration
works. Exhaustive formatting tests are done with RegisterFlags itself.

Example:
```
(lldb) register info cpsr
   Name: cpsr
   Size: 4 bytes (32 bits)
In sets: general (index 0)

| 31 | 30 | 29 | 28 | 27-26 | 25  | 24  | 23  | 22  | 21 | 20 | 19-13 |  12  | 
11-10 | 9 | 8 | 7 | 6 | 5 |  4  | 3-2 | 1 | 0  |
|||||---|-|-|-|-|||---|--|---|---|---|---|---|---|-|-|---||
| N  | Z  | C  | V  |   | TCO | DIT | UAO | PAN | SS | IL |   | SSBS |  
 | D | A | I | F |   | nRW | EL  |   | SP |
```

LLDB limits the max terminal width to 80 chars by default.
So to get that full width output you will need to change the "term-width"
setting to something higher.

Reviewed By: jasonmolenda

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

Added: 


Modified: 
lldb/include/lldb/Core/DumpRegisterInfo.h
lldb/source/Commands/CommandObjectRegister.cpp
lldb/source/Core/DumpRegisterInfo.cpp
lldb/test/API/commands/register/register/register_command/TestRegisters.py
lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py
lldb/unittests/Core/DumpRegisterInfoTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/DumpRegisterInfo.h 
b/lldb/include/lldb/Core/DumpRegisterInfo.h
index e257581864b5a..bceabcacd836e 100644
--- a/lldb/include/lldb/Core/DumpRegisterInfo.h
+++ b/lldb/include/lldb/Core/DumpRegisterInfo.h
@@ -18,16 +18,18 @@ namespace lldb_private {
 class Stream;
 class RegisterContext;
 struct RegisterInfo;
+class RegisterFlags;
 
 void DumpRegisterInfo(Stream &strm, RegisterContext &ctx,
-  const RegisterInfo &info);
+  const RegisterInfo &info, uint32_t terminal_width);
 
 // For testing only. Use DumpRegisterInfo instead.
 void DoDumpRegisterInfo(
 Stream &strm, const char *name, const char *alt_name, uint32_t byte_size,
 const std::vector &invalidates,
 const std::vector &read_from,
-const std::vector> &in_sets);
+const std::vector> &in_sets,
+const RegisterFlags *flags_type, uint32_t terminal_width);
 
 } // namespace lldb_private
 

diff  --git a/lldb/source/Commands/CommandObjectRegister.cpp 
b/lldb/source/Commands/CommandObjectRegister.cpp
index 814219d186186..a0e88f6ab4ba2 100644
--- a/lldb/source/Commands/CommandObjectRegister.cpp
+++ b/lldb/source/Commands/CommandObjectRegister.cpp
@@ -11,6 +11,7 @@
 #include "lldb/Core/DumpRegisterInfo.h"
 #include "lldb/Core/DumpRegisterValue.h"
 #include "lldb/Host/OptionParser.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandOptionArgumentTable.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Interpreter/OptionGroupFormat.h"
@@ -418,6 +419,8 @@ Read from   (*)  The registers that the value of this 
register is constructed
  read from the wider register.
 In sets (*)  The register sets that contain this register. For example the
  PC will be in the "General Purpose Register" set.
+Fields  (*)  A table of the names and bit positions of the values contained
+ in this register.
 
 Fields marked with (*) may not always be present. Some information may be
 
diff erent for the same register when connected to 
diff erent debug servers.)");
@@ -453,7 +456,9 @@ 
diff erent for the same register when connected to 
diff erent debug servers.)");
 RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext();
 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(reg_name);
 if (reg_info) {
-  DumpRegisterInfo(result.GetOutputStream(), *reg_ctx, *reg_info);
+  DumpRegisterInfo(
+  result.GetOutputStream(), *reg_ctx, *reg_info,
+  GetCommandInterpreter().GetDebugger().GetTerminalWidth());
   result.SetStatus(eReturnStatusSuccessFinishResult);
 } else
   result.AppendErrorWithFormat("No register found with name '%s'.\n",

diff  --git a/lldb/source/Core/DumpRegisterInfo.cpp 
b/lldb/source/Core/DumpRegisterInfo.cpp
index e7083e5938f52..8334795416902 100644
--- a/lldb/source/Core/DumpRegisterInfo.cpp
+++ b/lldb/source/Core/DumpRegisterInfo.cpp
@@ -8,6 +8,7 @@
 
 #include "lldb/Core/DumpRegisterInfo.h"
 #include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/RegisterFlags.h"
 #include 

[Lldb-commits] [PATCH] D152917: [LLDB] Add table formatting for register fields

2023-06-21 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett marked 2 inline comments as done.
DavidSpickett added a comment.

Sorry I missed the comments before landing, I've addressed those in 
https://github.com/llvm/llvm-project/commit/c7759df03825f63f8334d88c9525d655acfab685.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152917

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


[Lldb-commits] [lldb] c7759df - [lldb] Correct spelling in RegisterFlags comments

2023-06-21 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-06-21T09:34:22Z
New Revision: c7759df03825f63f8334d88c9525d655acfab685

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

LOG: [lldb] Correct spelling in RegisterFlags comments

I missed these review comments on https://reviews.llvm.org/D152917
before landing it.

Added: 


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

Removed: 




diff  --git a/lldb/include/lldb/Target/RegisterFlags.h 
b/lldb/include/lldb/Target/RegisterFlags.h
index 0b9961e3d7a3f..8137fd27e99c2 100644
--- a/lldb/include/lldb/Target/RegisterFlags.h
+++ b/lldb/include/lldb/Target/RegisterFlags.h
@@ -93,7 +93,7 @@ class RegisterFlags {
   unsigned GetSize() const { return m_size; }
   void log(Log *log) const;
 
-  /// Produce a text table showing the layout of all the fields. Unamed/padding
+  /// Produce a text table showing the layout of all the fields. 
Unnamed/padding
   /// fields will be included, with only their positions shown.
   /// max_width will be the width in characters of the terminal you are
   /// going to print the table to. If the table would exceed this width, it 
will

diff  --git a/lldb/source/Target/RegisterFlags.cpp 
b/lldb/source/Target/RegisterFlags.cpp
index 9b12815fa59a9..06fb45d777ec3 100644
--- a/lldb/source/Target/RegisterFlags.cpp
+++ b/lldb/source/Target/RegisterFlags.cpp
@@ -146,7 +146,7 @@ std::string RegisterFlags::AsTable(uint32_t max_width) 
const {
 // one column, put out what we have and move to a new table on the next 
line
 // (+1 here because we need to cap the ends with '|'). If this is the first
 // column, just let it overflow and we'll wrap next time around. There's 
not
-// mich we can do with a very small terminal.
+// much we can do with a very small terminal.
 if (current_width && ((current_width + column_width + 1) >= max_width)) {
   EmitTable(table, lines);
   // Blank line between each.



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


[Lldb-commits] [PATCH] D152917: [LLDB] Add table formatting for register fields

2023-06-21 Thread David Spickett via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8b73a2e82191: [LLDB] Add table formatting for register 
fields (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152917

Files:
  lldb/include/lldb/Target/RegisterFlags.h
  lldb/source/Target/RegisterFlags.cpp
  lldb/unittests/Target/RegisterFlagsTest.cpp

Index: lldb/unittests/Target/RegisterFlagsTest.cpp
===
--- lldb/unittests/Target/RegisterFlagsTest.cpp
+++ lldb/unittests/Target/RegisterFlagsTest.cpp
@@ -137,3 +137,121 @@
  make_field(28, 28)});
   ASSERT_EQ(0x0005ULL, rf3.ReverseFieldOrder(0xA000));
 }
+
+TEST(RegisterFlagsTest, AsTable) {
+  // Anonymous fields are shown with an empty name cell,
+  // whether they are known up front or added during construction.
+  RegisterFlags anon_field("", 4, {make_field(0, 31)});
+  ASSERT_EQ("| 31-0 |\n"
+"|--|\n"
+"|  |",
+anon_field.AsTable(100));
+
+  RegisterFlags anon_with_pad("", 4, {make_field(16, 31)});
+  ASSERT_EQ("| 31-16 | 15-0 |\n"
+"|---|--|\n"
+"|   |  |",
+anon_with_pad.AsTable(100));
+
+  // Use the wider of position and name to set the column width.
+  RegisterFlags name_wider("", 4, {RegisterFlags::Field("aardvark", 0, 31)});
+  ASSERT_EQ("|   31-0   |\n"
+"|--|\n"
+"| aardvark |",
+name_wider.AsTable(100));
+  // When the padding is an odd number, put the remaining 1 on the right.
+  RegisterFlags pos_wider("", 4, {RegisterFlags::Field("?", 0, 31)});
+  ASSERT_EQ("| 31-0 |\n"
+"|--|\n"
+"|  ?   |",
+pos_wider.AsTable(100));
+
+  // Single bit fields don't need to show start and end, just one of them.
+  RegisterFlags single_bit("", 4, {make_field(31, 31)});
+  ASSERT_EQ("| 31 | 30-0 |\n"
+"||--|\n"
+"||  |",
+single_bit.AsTable(100));
+
+  // Columns are printed horizontally if max width allows.
+  RegisterFlags many_fields("", 4,
+{RegisterFlags::Field("cat", 28, 31),
+ RegisterFlags::Field("pigeon", 20, 23),
+ RegisterFlags::Field("wolf", 12, 12),
+ RegisterFlags::Field("x", 0, 4)});
+  ASSERT_EQ("| 31-28 | 27-24 | 23-20  | 19-13 |  12  | 11-5 | 4-0 |\n"
+"|---|---||---|--|--|-|\n"
+"|  cat  |   | pigeon |   | wolf |  |  x  |",
+many_fields.AsTable(100));
+
+  // max_width tells us when we need to split into further tables.
+  // Here no split is needed.
+  RegisterFlags exact_max_single_col("", 4, {RegisterFlags::Field("?", 0, 31)});
+  ASSERT_EQ("| 31-0 |\n"
+"|--|\n"
+"|  ?   |",
+exact_max_single_col.AsTable(9));
+  RegisterFlags exact_max_two_col(
+  "", 4,
+  {RegisterFlags::Field("?", 16, 31), RegisterFlags::Field("#", 0, 15)});
+  ASSERT_EQ("| 31-16 | 15-0 |\n"
+"|---|--|\n"
+"|   ?   |  #   |",
+exact_max_two_col.AsTable(16));
+
+  // If max is less than a single column, just print the single column. The user
+  // will have to put up with some wrapping in this niche case.
+  RegisterFlags zero_max_single_col("", 4, {RegisterFlags::Field("?", 0, 31)});
+  ASSERT_EQ("| 31-0 |\n"
+"|--|\n"
+"|  ?   |",
+zero_max_single_col.AsTable(0));
+  // Same logic for any following columns. Effectively making a "vertical"
+  // table, just with more grid lines.
+  RegisterFlags zero_max_two_col(
+  "", 4,
+  {RegisterFlags::Field("?", 16, 31), RegisterFlags::Field("#", 0, 15)});
+  ASSERT_EQ("| 31-16 |\n"
+"|---|\n"
+"|   ?   |\n"
+"\n"
+"| 15-0 |\n"
+"|--|\n"
+"|  #   |",
+zero_max_two_col.AsTable(0));
+
+  RegisterFlags max_less_than_single_col("", 4,
+ {RegisterFlags::Field("?", 0, 31)});
+  ASSERT_EQ("| 31-0 |\n"
+"|--|\n"
+"|  ?   |",
+max_less_than_single_col.AsTable(3));
+  RegisterFlags max_less_than_two_col(
+  "", 4,
+  {RegisterFlags::Field("?", 16, 31), RegisterFlags::Field("#", 0, 15)});
+  ASSERT_EQ("| 31-16 |\n"
+"|---|\n"
+"|   ?   |\n"
+"\n"
+"| 15-0 |\n"
+"|--|\n"
+"|  #   |",
+max_less_than_two_col.AsTable(9));
+  RegisterFlags max_many_columns(
+  "", 4,
+  {RegisterFlags::Field("A", 24, 31), RegisterFlags::Field("B", 16, 23),
+   RegisterFlags::Field("C", 8, 15),
+   RegisterFlags::Field("really l

[Lldb-commits] [lldb] 8b73a2e - [LLDB] Add table formatting for register fields

2023-06-21 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-06-21T09:28:48Z
New Revision: 8b73a2e8219127b707280b689edb20753849bd4c

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

LOG: [LLDB] Add table formatting for register fields

This will be used by the "register info" command to show
the layout of register contents. For example if we have
these fields coming in from XML:
```




```
We get:
```
| 31-24 | 23-16 | 15-8 | 7-0 |
|---|---|--|-|
|   A   |   B   |  C   |  D  |
```
Note that this is only the layout, not the values.
For values, use "register read".

The tables' columns are center padded (left bias
if there's an odd padding) and will wrap if the terminal width
is too low.

```
| 31-24 | 23-16 |
|---|---|
|   A   |   B   |

| 15-8 | 7-0 |
|--|-|
|  C   |  D  |
```

This means we match the horizontal format seen in many architecture
manuals but don't spam the user with lots of misaligned text when the
output gets very long.

Reviewed By: jasonmolenda

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

Added: 


Modified: 
lldb/include/lldb/Target/RegisterFlags.h
lldb/source/Target/RegisterFlags.cpp
lldb/unittests/Target/RegisterFlagsTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/RegisterFlags.h 
b/lldb/include/lldb/Target/RegisterFlags.h
index 2dd20f9ad5fbf..0b9961e3d7a3f 100644
--- a/lldb/include/lldb/Target/RegisterFlags.h
+++ b/lldb/include/lldb/Target/RegisterFlags.h
@@ -93,6 +93,13 @@ class RegisterFlags {
   unsigned GetSize() const { return m_size; }
   void log(Log *log) const;
 
+  /// Produce a text table showing the layout of all the fields. Unamed/padding
+  /// fields will be included, with only their positions shown.
+  /// max_width will be the width in characters of the terminal you are
+  /// going to print the table to. If the table would exceed this width, it 
will
+  /// be split into many tables as needed.
+  std::string AsTable(uint32_t max_width) const;
+
 private:
   const std::string m_id;
   /// Size in bytes

diff  --git a/lldb/source/Target/RegisterFlags.cpp 
b/lldb/source/Target/RegisterFlags.cpp
index 8bdcb61b05b23..9b12815fa59a9 100644
--- a/lldb/source/Target/RegisterFlags.cpp
+++ b/lldb/source/Target/RegisterFlags.cpp
@@ -7,7 +7,9 @@
 
//===--===//
 
 #include "lldb/Target/RegisterFlags.h"
+#include "lldb/Utility/StreamString.h"
 
+#include 
 #include 
 
 using namespace lldb_private;
@@ -91,3 +93,85 @@ void RegisterFlags::log(Log *log) const {
   for (const Field &field : m_fields)
 field.log(log);
 }
+
+static StreamString FormatCell(const StreamString &content,
+   unsigned column_width) {
+  unsigned pad = column_width - content.GetString().size();
+  std::string pad_l;
+  std::string pad_r;
+  if (pad) {
+pad_l = std::string(pad / 2, ' ');
+pad_r = std::string((pad / 2) + (pad % 2), ' ');
+  }
+
+  StreamString aligned;
+  aligned.Printf("|%s%s%s", pad_l.c_str(), content.GetString().data(),
+ pad_r.c_str());
+  return aligned;
+}
+
+static void EmitTable(std::string &out, std::array &table) {
+  // Close the table.
+  for (std::string &line : table)
+line += '|';
+
+  out += std::accumulate(table.begin() + 1, table.end(), table.front(),
+ [](std::string lhs, const auto &rhs) {
+   return std::move(lhs) + "\n" + rhs;
+ });
+}
+
+std::string RegisterFlags::AsTable(uint32_t max_width) const {
+  std::string table;
+  // position / gridline / name
+  std::array lines;
+  uint32_t current_width = 0;
+
+  for (const RegisterFlags::Field &field : m_fields) {
+StreamString position;
+if (field.GetEnd() == field.GetStart())
+  position.Printf(" %d ", field.GetEnd());
+else
+  position.Printf(" %d-%d ", field.GetEnd(), field.GetStart());
+
+StreamString name;
+name.Printf(" %s ", field.GetName().c_str());
+
+unsigned column_width = position.GetString().size();
+unsigned name_width = name.GetString().size();
+if (name_width > column_width)
+  column_width = name_width;
+
+// If the next column would overflow and we have already formatted at least
+// one column, put out what we have and move to a new table on the next 
line
+// (+1 here because we need to cap the ends with '|'). If this is the first
+// column, just let it overflow and we'll wrap next time around. There's 
not
+// mich we can do with a very small terminal.
+if (current_width && ((current_width + column_width + 1) >= max_width)) {
+  EmitTable(table, lines);
+  // Blank line between each.
+  table += "\n\n";
+
+  for (std::string &line : lines)
+line.c

[Lldb-commits] [PATCH] D152916: [lldb] Add "register info" command

2023-06-21 Thread David Spickett via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGba85f206fe6f: [lldb] Add "register info" command 
(authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152916

Files:
  lldb/include/lldb/Core/DumpRegisterInfo.h
  lldb/source/Commands/CommandObjectRegister.cpp
  lldb/source/Core/CMakeLists.txt
  lldb/source/Core/DumpRegisterInfo.cpp
  lldb/test/API/commands/register/register/register_command/TestRegisters.py
  lldb/unittests/Core/CMakeLists.txt
  lldb/unittests/Core/DumpRegisterInfoTest.cpp

Index: lldb/unittests/Core/DumpRegisterInfoTest.cpp
===
--- /dev/null
+++ lldb/unittests/Core/DumpRegisterInfoTest.cpp
@@ -0,0 +1,82 @@
+//===-- DumpRegisterInfoTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Core/DumpRegisterInfo.h"
+#include "lldb/Utility/StreamString.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+
+TEST(DoDumpRegisterInfoTest, MinimumInfo) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)");
+}
+
+TEST(DoDumpRegisterInfoTest, AltName) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", "bar", 4, {}, {}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo (bar)\n"
+  "   Size: 4 bytes (32 bits)");
+}
+
+TEST(DoDumpRegisterInfoTest, Invalidates) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2"}, {}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "Invalidates: foo2");
+
+  strm.Clear();
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3", "foo4"}, {}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "Invalidates: foo2, foo3, foo4");
+}
+
+TEST(DoDumpRegisterInfoTest, ReadFrom) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1"}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "  Read from: foo1");
+
+  strm.Clear();
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1", "foo2", "foo3"}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "  Read from: foo1, foo2, foo3");
+}
+
+TEST(DoDumpRegisterInfoTest, InSets) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {{"set1", 101}});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "In sets: set1 (index 101)");
+
+  strm.Clear();
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {},
+ {{"set1", 0}, {"set2", 1}, {"set3", 2}});
+  ASSERT_EQ(strm.GetString(),
+"   Name: foo\n"
+"   Size: 4 bytes (32 bits)\n"
+"In sets: set1 (index 0), set2 (index 1), set3 (index 2)");
+}
+
+TEST(DoDumpRegisterInfoTest, MaxInfo) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3"},
+ {"foo3", "foo4"}, {{"set1", 1}, {"set2", 2}});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "Invalidates: foo2, foo3\n"
+  "  Read from: foo3, foo4\n"
+  "In sets: set1 (index 1), set2 (index 2)");
+}
Index: lldb/unittests/Core/CMakeLists.txt
===
--- lldb/unittests/Core/CMakeLists.txt
+++ lldb/unittests/Core/CMakeLists.txt
@@ -2,6 +2,7 @@
   CommunicationTest.cpp
   DiagnosticEventTest.cpp
   DumpDataExtractorTest.cpp
+  DumpRegisterInfoTest.cpp
   FileSpecListTest.cpp
   FormatEntityTest.cpp
   MangledTest.cpp
Index: lldb/test/API/commands/register/register/register_command/TestRegisters.py
===
--- lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -567,3 +567,41 @@
 error=True,
 substrs=["error: Register not foun

[Lldb-commits] [lldb] ba85f20 - [lldb] Add "register info" command

2023-06-21 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-06-21T08:48:18Z
New Revision: ba85f206fe6f2fec9dd5fee55bf2a1e966fc37aa

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

LOG: [lldb] Add "register info" command

This adds a new command that will show all the information lldb
knows about a register.
```
(lldb) register info s0
   Name: s0
   Size: 4 bytes (32 bits)
Invalidates: v0, d0
  Read from: v0
In sets: Floating Point Registers (index 1)
```

Currently it only allows a single register, and we get the
information from the RegisterInfo structure.

For those of us who know the architecture well, this information
is all pretty obvious. For those who don't, it's nice to have it
at a glance without leaving the debugger.

I hope to have more in depth information to show here in the future,
which will be of wider use.

Reviewed By: jasonmolenda

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

Added: 
lldb/include/lldb/Core/DumpRegisterInfo.h
lldb/source/Core/DumpRegisterInfo.cpp
lldb/unittests/Core/DumpRegisterInfoTest.cpp

Modified: 
lldb/source/Commands/CommandObjectRegister.cpp
lldb/source/Core/CMakeLists.txt
lldb/test/API/commands/register/register/register_command/TestRegisters.py
lldb/unittests/Core/CMakeLists.txt

Removed: 




diff  --git a/lldb/include/lldb/Core/DumpRegisterInfo.h 
b/lldb/include/lldb/Core/DumpRegisterInfo.h
new file mode 100644
index 0..e257581864b5a
--- /dev/null
+++ b/lldb/include/lldb/Core/DumpRegisterInfo.h
@@ -0,0 +1,34 @@
+//===-- DumpRegisterInfo.h --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_CORE_DUMPREGISTERINFO_H
+#define LLDB_CORE_DUMPREGISTERINFO_H
+
+#include 
+#include 
+#include 
+
+namespace lldb_private {
+
+class Stream;
+class RegisterContext;
+struct RegisterInfo;
+
+void DumpRegisterInfo(Stream &strm, RegisterContext &ctx,
+  const RegisterInfo &info);
+
+// For testing only. Use DumpRegisterInfo instead.
+void DoDumpRegisterInfo(
+Stream &strm, const char *name, const char *alt_name, uint32_t byte_size,
+const std::vector &invalidates,
+const std::vector &read_from,
+const std::vector> &in_sets);
+
+} // namespace lldb_private
+
+#endif // LLDB_CORE_DUMPREGISTERINFO_H

diff  --git a/lldb/source/Commands/CommandObjectRegister.cpp 
b/lldb/source/Commands/CommandObjectRegister.cpp
index c288dbef33499..814219d186186 100644
--- a/lldb/source/Commands/CommandObjectRegister.cpp
+++ b/lldb/source/Commands/CommandObjectRegister.cpp
@@ -8,6 +8,7 @@
 
 #include "CommandObjectRegister.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/DumpRegisterInfo.h"
 #include "lldb/Core/DumpRegisterValue.h"
 #include "lldb/Host/OptionParser.h"
 #include "lldb/Interpreter/CommandOptionArgumentTable.h"
@@ -398,16 +399,82 @@ class CommandObjectRegisterWrite : public 
CommandObjectParsed {
   }
 };
 
+// "register info"
+class CommandObjectRegisterInfo : public CommandObjectParsed {
+public:
+  CommandObjectRegisterInfo(CommandInterpreter &interpreter)
+  : CommandObjectParsed(interpreter, "register info",
+"View information about a register.", nullptr,
+eCommandRequiresRegContext |
+eCommandProcessMustBeLaunched) {
+SetHelpLong(R"(
+Name The name lldb uses for the register, optionally with an alias.
+Size The size of the register in bytes and again in bits.
+Invalidates (*)  The registers that would be changed if you wrote this
+ register. For example, writing to a narrower alias of a wider
+ register would change the value of the wider register.
+Read from   (*)  The registers that the value of this register is constructed
+ from. For example, a narrower alias of a wider register will 
be
+ read from the wider register.
+In sets (*)  The register sets that contain this register. For example the
+ PC will be in the "General Purpose Register" set.
+
+Fields marked with (*) may not always be present. Some information may be
+
diff erent for the same register when connected to 
diff erent debug servers.)");
+
+CommandArgumentData register_arg;
+register_arg.arg_type = eArgTypeRegisterName;
+register_arg.arg_repetition = eArgRepeatPlain;
+
+CommandArgumentEntry arg1;
+arg1.push_back(register_arg);
+m_arguments.push_back(arg1);
+  }
+
+  ~CommandOb