[Lldb-commits] [lldb] 728101f - Reland "[LLDB] Fix the use of "platform process launch" with no extra arguments"

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

Author: David Spickett
Date: 2023-06-29T08:21:42Z
New Revision: 728101f97286c1665814e74686c083a4d5ff208c

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

LOG: Reland "[LLDB] Fix the use of "platform process launch" with no extra 
arguments"

This reverts commit 3254623d73fb7252385817d8057640c9d5d5ffd1.

One test has been updated to add the "-s" flag which along with
86fd957af981f146a306831608d7ad2de65b9560 should fix the tests on MacOS.

An assert on hijack listener added in that patch was removed, it seems
to be correct on MacOS but not on Linux.

Added: 
lldb/test/API/commands/platform/process/launch/Makefile
lldb/test/API/commands/platform/process/launch/TestPlatformProcessLaunch.py
lldb/test/API/commands/platform/process/launch/main.c

Modified: 
lldb/source/Commands/CommandObjectPlatform.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectPlatform.cpp 
b/lldb/source/Commands/CommandObjectPlatform.cpp
index e44a8975cf291c..54115b51be78e4 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1208,8 +1208,12 @@ class CommandObjectPlatformProcessLaunch : public 
CommandObjectParsed {
   if (m_options.launch_info.GetExecutableFile()) {
 Debugger &debugger = GetDebugger();
 
-if (argc == 0)
-  target->GetRunArguments(m_options.launch_info.GetArguments());
+if (argc == 0) {
+  // If no arguments were given to the command, use target.run-args.
+  Args target_run_args;
+  target->GetRunArguments(target_run_args);
+  
m_options.launch_info.GetArguments().AppendArguments(target_run_args);
+}
 
 ProcessSP process_sp(platform_sp->DebugProcess(
 m_options.launch_info, debugger, *target, error));
@@ -1229,8 +1233,6 @@ class CommandObjectPlatformProcessLaunch : public 
CommandObjectParsed {
 !synchronous_execution &&
 launch_info.GetFlags().Test(eLaunchFlagStopAtEntry);
 
-assert(launch_info.GetHijackListener());
-
 EventSP first_stop_event_sp;
 StateType state = process_sp->WaitForProcessToStop(
 std::nullopt, &first_stop_event_sp, rebroadcast_first_stop,

diff  --git a/lldb/test/API/commands/platform/process/launch/Makefile 
b/lldb/test/API/commands/platform/process/launch/Makefile
new file mode 100644
index 00..10495940055b63
--- /dev/null
+++ b/lldb/test/API/commands/platform/process/launch/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules

diff  --git 
a/lldb/test/API/commands/platform/process/launch/TestPlatformProcessLaunch.py 
b/lldb/test/API/commands/platform/process/launch/TestPlatformProcessLaunch.py
new file mode 100644
index 00..3312cb04832ab7
--- /dev/null
+++ 
b/lldb/test/API/commands/platform/process/launch/TestPlatformProcessLaunch.py
@@ -0,0 +1,59 @@
+"""
+Test platform process launch.
+"""
+
+from textwrap import dedent
+from lldbsuite.test.lldbtest import TestBase
+
+
+class ProcessLaunchTestCase(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+def setup(self):
+self.build()
+exe = self.getBuildArtifact("a.out")
+self.runCmd("file " + exe)
+return (exe, self.getBuildArtifact("stdio.log"))
+
+def test_process_launch_no_args(self):
+# When there are no extra arguments we just have 0, the program name.
+exe, outfile = self.setup()
+self.runCmd("platform process launch --stdout {} -s".format(outfile))
+self.runCmd("continue")
+
+with open(outfile) as f:
+   self.assertEqual(dedent("""\
+Got 1 argument(s).
+[0]: {}
+""".format(exe)), f.read())
+
+def test_process_launch_command_args(self):
+exe, outfile = self.setup()
+# Arguments given via the command override those in the settings.
+self.runCmd("settings set target.run-args D E")
+self.runCmd("platform process launch --stdout {} -s -- A B 
C".format(outfile))
+self.runCmd("continue")
+
+with open(outfile) as f:
+   self.assertEqual(dedent("""\
+Got 4 argument(s).
+[0]: {}
+[1]: A
+[2]: B
+[3]: C
+""".format(exe)), f.read())
+
+def test_process_launch_target_args(self):
+exe, outfile = self.setup()
+# When no arguments are passed via the command, use the setting.
+self.runCmd("settings set target.run-args D E")
+self.runCmd("platform process launch --stdout {} -s".format(outfile))
+self.runCmd("continue")
+
+with open(outfile) as f:
+   self.assertEqual(dedent("""\
+Got 3 argume

[Lldb-commits] [PATCH] D153636: [LLDB] Fix the use of "platform process launch" with no extra arguments

2023-06-29 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

Relanded as 
https://github.com/llvm/llvm-project/commit/728101f97286c1665814e74686c083a4d5ff208c.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153636

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


[Lldb-commits] [PATCH] D153513: [lldb] Check that qLaunchGDBServer packet does not return an error

2023-06-29 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a reviewer: labath.
DavidSpickett added a comment.

ping!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153513

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


[Lldb-commits] [PATCH] D151567: [LLVM][Support] Report EISDIR when opening a directory on AIX

2023-06-29 Thread Alison Zhang via Phabricator via lldb-commits
azhan92 marked 3 inline comments as done.
azhan92 added a comment.

@hubert.reinterpretcast I have the call stack on AIX:

  #0  0x0904304c in read () from /usr/lib/libc.a(shr_64.o)
  #1  0x000100d5f044 in llvm::sys::RetryAfterSignal(int const&, long ( const&)(int, 
void*, unsigned long), int const&, char* const&, unsigned long const&) (
  Fail=@0xfff92e4: -1, F=@0x9001000a0083ec0: {long (int, void *, 
unsigned long)} 0x9001000a0083ec0 <_$STATIC+22000>, As=@0xfff92f0: 
16384, As=@0xfff92f0: 16384, As=@0xfff92f0: 16384)
  at 
/home/alisonz/llvm/dev/llvm-project/llvm/include/llvm/Support/Errno.h:37
  #2  0x000100d5973c in llvm::sys::fs::readNativeFile (FD=3, Buf=...) at 
/home/alisonz/llvm/dev/llvm-project/llvm/lib/Support/Unix/Path.inc:1186
  #3  0x000100d59404 in llvm::sys::fs::readNativeFileToEOF (FileHandle=3, 
Buffer=..., ChunkSize=16384) at 
/home/alisonz/llvm/dev/llvm-project/llvm/lib/Support/Path.cpp:1183
  #4  0x0001010973e0 in getMemoryBufferForStream (FD=3, BufferName=...) at 
/home/alisonz/llvm/dev/llvm-project/llvm/lib/Support/MemoryBuffer.cpp:247
  #5  0x000101096df0 in getOpenFileImpl (FD=3, 
Filename=..., FileSize=18446744073709551615, MapSize=18446744073709551615, 
Offset=0, RequiresNullTerminator=true, IsVolatile=false, Alignment=...)
  at 
/home/alisonz/llvm/dev/llvm-project/llvm/lib/Support/MemoryBuffer.cpp:474
  #6  0x000101096be8 in llvm::MemoryBuffer::getOpenFile (FD=3, 
Filename=..., FileSize=18446744073709551615, RequiresNullTerminator=true, 
IsVolatile=false, Alignment=...)
  at 
/home/alisonz/llvm/dev/llvm-project/llvm/lib/Support/MemoryBuffer.cpp:527
  #7  0x0001015940a0 in (anonymous namespace)::RealFile::getBuffer 
(this=0x1105f6610, Name=..., FileSize=-1, RequiresNullTerminator=true, 
IsVolatile=false) at 
/home/alisonz/llvm/dev/llvm-project/llvm/lib/Support/VirtualFileSystem.cpp:229
  #8  0x000101570cb8 in llvm::vfs::FileSystem::getBufferForFile 
(this=0x1105f6210, Name=..., FileSize=-1, RequiresNullTerminator=true, 
IsVolatile=false) at 
/home/alisonz/llvm/dev/llvm-project/llvm/lib/Support/VirtualFileSystem.cpp:124
  #9  0x00010020b058 in llvm::cl::ExpansionContext::expandResponseFile 
(this=0xfffea58, FName=..., NewArgv=...) at 
/home/alisonz/llvm/dev/llvm-project/llvm/lib/Support/CommandLine.cpp:1157
  #10 0x00010020dd44 in llvm::cl::ExpansionContext::expandResponseFiles 
(this=0xfffea58, Argv=...) at 
/home/alisonz/llvm/dev/llvm-project/llvm/lib/Support/CommandLine.cpp:1332
  #11 0x000100210d78 in llvm::cl::ExpandResponseFiles (Saver=..., 
Tokenizer=@0x1104acfe0: 0x100208890 
&, bool)>, Argv=...)
  at 
/home/alisonz/llvm/dev/llvm-project/llvm/lib/Support/CommandLine.cpp:1381
  #12 0x00010017b7cc in (anonymous 
namespace)::CommandLineTest_BadResponseFile_Test::TestBody (this=0x1105da090) 
at 
/home/alisonz/llvm/dev/llvm-project/llvm/unittests/Support/CommandLineTest.cpp:1066

By lower level do you mean in llvm/include/llvm/Support/Errno.h?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151567

___
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-29 Thread Ivan Hernandez via Phabricator via lldb-commits
ivanhernandez13 added inline comments.



Comment at: lldb/tools/lldb-vscode/VSCode.h:251-252
   /// \return
-  ///   A \a PacketStatus object indicating the sucess or failure of the
-  ///   request.
-  PacketStatus SendReverseRequest(llvm::json::Object request,
-  llvm::json::Object &response);
+  ///   A future that resolves to the response object indicating the sucess or
+  ///   failure of the request.
+  void SendReverseRequest(llvm::StringRef command, llvm::json::Value arguments,

nit: Could you update this comment that is no longer accurate


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-29 Thread John Harrison via Phabricator via lldb-commits
ashgti updated this revision to Diff 535864.
ashgti added a comment.

Fixing stale comment.


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/runInTerminal/TestVSCode_runInTerminal.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,13 +1590,15 @@
 #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)
-return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "Process cannot be launched by the IDE. %s",
-   comm_channel.GetLauncherError().c_str());
+  g_vsc.SendReverseRequest("runInTerminal", std::move(reverse_request),
+   [](llvm::Expected value) {
+ if (!value) {
+   llvm::Error err = value.takeError();
+   llvm::errs()
+   << "runInTerminal request failed: "
+   << llvm::toString(std::move(err)) << "\n";
+ }
+   });
 
   if (llvm::Expected pid = comm_channel.GetLauncherPid())
 attach_info.SetProcessID(*pid);
@@ -1676,7 +1686,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 +3474,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 
@@ -73,6 +75,7 @@
 };
 
 typedef void (*RequestCallback)(const llvm::json::Object &command);
+typedef void (*ResponseCallback)(llvm::Expected value);
 
 enum class PacketStatus {
   Success = 0,
@@ -121,6 +124,11 @@
   void Clear();
 };
 
+struct StartDe

[Lldb-commits] [PATCH] D154030: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

2023-06-29 Thread John Harrison via Phabricator via lldb-commits
ashgti updated this revision to Diff 535911.
ashgti added a comment.

Adding ` as an escape hatch in auto mode to ensure lldb commands can always be 
run directly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154030

Files:
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/JSONUtils.h
  lldb/tools/lldb-vscode/Options.td
  lldb/tools/lldb-vscode/README.md
  lldb/tools/lldb-vscode/SourceBreakpoint.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
@@ -252,7 +252,7 @@
 }
   }
 
-  // We will have cleared g_vsc.focus_tid if he focus thread doesn't have
+  // We will have cleared g_vsc.focus_tid if the focus thread doesn't have
   // a stop reason, so if it was cleared, or wasn't set, or doesn't exist,
   // then set the focus thread to the first thread with a stop reason.
   if (!focus_thread_exists || g_vsc.focus_tid == LLDB_INVALID_THREAD_ID)
@@ -1065,50 +1065,62 @@
   FillResponse(request, response);
   llvm::json::Object body;
   auto arguments = request.getObject("arguments");
+
+  // If we have a frame, try to set the context for variable completions.
+  lldb::SBFrame frame = g_vsc.GetLLDBFrame(*arguments);
+  if (frame.IsValid()) {
+frame.GetThread().GetProcess().SetSelectedThread(frame.GetThread());
+frame.GetThread().SetSelectedFrame(frame.GetFrameID());
+  }
+
   std::string text = std::string(GetString(arguments, "text"));
   auto original_column = GetSigned(arguments, "column", text.size());
-  auto actual_column = original_column - 1;
+  auto original_line = GetSigned(arguments, "line", 1);
+  auto offset = original_column - 1;
+  if (original_line > 1) {
+llvm::StringRef text_ref{text};
+::llvm::SmallVector<::llvm::StringRef, 2> lines;
+text_ref.split(lines, '\n');
+for (int i = 0; i < original_line - 1; i++) {
+  offset += lines[i].size();
+}
+  }
   llvm::json::Array targets;
-  // NOTE: the 'line' argument is not needed, as multiline expressions
-  // work well already
-  // TODO: support frameID. Currently
-  // g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions
-  // is frame-unaware.
-
-  if (!text.empty() && text[0] == '`') {
-text = text.substr(1);
-actual_column--;
-  } else {
-char command[] = "expression -- ";
+
+  if (g_vsc.DetectExpressionContext(text) == ExpressionContext::Variable) {
+char command[] = "frame variable ";
 text = command + text;
-actual_column += strlen(command);
+offset += strlen(command);
   }
   lldb::SBStringList matches;
   lldb::SBStringList descriptions;
-  g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions(
-  text.c_str(), actual_column, 0, -1, matches, descriptions);
-  size_t count = std::min((uint32_t)100, matches.GetSize());
-  targets.reserve(count);
-  for (size_t i = 0; i < count; i++) {
-std::string match = matches.GetStringAtIndex(i);
-std::string description = descriptions.GetStringAtIndex(i);
-
-llvm::json::Object item;
-
-llvm::StringRef match_ref = match;
-for (llvm::StringRef commit_point : {".", "->"}) {
-  if (match_ref.contains(commit_point)) {
-match_ref = match_ref.rsplit(commit_point).second;
+
+  if (g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions(
+  text.c_str(), offset, 0, 100, matches, descriptions)) {
+// The first element is the common substring after the cursor position for
+// all the matches. The rest of the elements are the matches.
+targets.reserve(matches.GetSize() - 1);
+std::string common_pattern = matches.GetStringAtIndex(0);
+for (size_t i = 1; i < matches.GetSize(); i++) {
+  std::string match = matches.GetStringAtIndex(i);
+  std::string description = descriptions.GetStringAtIndex(i);
+
+  llvm::json::Object item;
+  llvm::StringRef match_ref = match;
+  for (llvm::StringRef commit_point : {".", "->"}) {
+if (match_ref.contains(commit_point)) {
+  match_ref = match_ref.rsplit(commit_point).second;
+}
   }
-}
-EmplaceSafeString(item, "text", match_ref);
+  EmplaceSafeString(item, "text", match_ref);
 
-if (description.empty())
-  EmplaceSafeString(item, "label", match);
-else
-  EmplaceSafeString(item, "label", match + " -- " + description);
+  if (description.empty())
+EmplaceSafeString(item, "label", match);
+  else
+EmplaceSafeString(item, "label", match + " -- " + description);
 
-targets.emplace_back(std::move(item));
+  targets.emplace_back(std::move(item));
+}
   }
 
   body.try_emplace("targets", std::move(targets));
@@ -122

[Lldb-commits] [PATCH] D154128: [lldb] Add log indicating which kind of data formatter

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

The `formatter` logs include a function name, but these functions are mostly 
templates
and the template type parameter is not printed, which is useful context.

This change adds a new log which is printed upon entry of `FormatManager::Get`, 
which
shows the formatter context as either `format`, `summary`, or `synthetic`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154128

Files:
  lldb/source/DataFormatters/FormatManager.cpp


Index: lldb/source/DataFormatters/FormatManager.cpp
===
--- lldb/source/DataFormatters/FormatManager.cpp
+++ lldb/source/DataFormatters/FormatManager.cpp
@@ -596,15 +596,24 @@
   return retval_sp;
 }
 
+namespace {
+template  const char *FormatterKind;
+template <> const char *FormatterKind = "format";
+template <> const char *FormatterKind = "summary";
+template <> const char *FormatterKind = "synthetic";
+} // namespace
+
 template 
 ImplSP FormatManager::Get(ValueObject &valobj,
   lldb::DynamicValueType use_dynamic) {
+  Log *log = GetLog(LLDBLog::DataFormatters);
+  LLDB_LOGF(log, "\n\n[%s] Begin %s lookup.", __FUNCTION__,
+FormatterKind);
+
   FormattersMatchData match_data(valobj, use_dynamic);
   if (ImplSP retval_sp = GetCached(match_data))
 return retval_sp;
 
-  Log *log = GetLog(LLDBLog::DataFormatters);
-
   LLDB_LOGF(log, "[%s] Search failed. Giving language a chance.", 
__FUNCTION__);
   for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) {
 if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) {
@@ -628,7 +637,7 @@
   ImplSP retval_sp;
   Log *log = GetLog(LLDBLog::DataFormatters);
   if (match_data.GetTypeForCache()) {
-LLDB_LOGF(log, "\n\n[%s] Looking into cache for type %s", __FUNCTION__,
+LLDB_LOGF(log, "[%s] Looking into cache for type %s", __FUNCTION__,
   match_data.GetTypeForCache().AsCString(""));
 if (m_format_cache.Get(match_data.GetTypeForCache(), retval_sp)) {
   if (log) {


Index: lldb/source/DataFormatters/FormatManager.cpp
===
--- lldb/source/DataFormatters/FormatManager.cpp
+++ lldb/source/DataFormatters/FormatManager.cpp
@@ -596,15 +596,24 @@
   return retval_sp;
 }
 
+namespace {
+template  const char *FormatterKind;
+template <> const char *FormatterKind = "format";
+template <> const char *FormatterKind = "summary";
+template <> const char *FormatterKind = "synthetic";
+} // namespace
+
 template 
 ImplSP FormatManager::Get(ValueObject &valobj,
   lldb::DynamicValueType use_dynamic) {
+  Log *log = GetLog(LLDBLog::DataFormatters);
+  LLDB_LOGF(log, "\n\n[%s] Begin %s lookup.", __FUNCTION__,
+FormatterKind);
+
   FormattersMatchData match_data(valobj, use_dynamic);
   if (ImplSP retval_sp = GetCached(match_data))
 return retval_sp;
 
-  Log *log = GetLog(LLDBLog::DataFormatters);
-
   LLDB_LOGF(log, "[%s] Search failed. Giving language a chance.", __FUNCTION__);
   for (lldb::LanguageType lang_type : match_data.GetCandidateLanguages()) {
 if (LanguageCategory *lang_category = GetCategoryForLanguage(lang_type)) {
@@ -628,7 +637,7 @@
   ImplSP retval_sp;
   Log *log = GetLog(LLDBLog::DataFormatters);
   if (match_data.GetTypeForCache()) {
-LLDB_LOGF(log, "\n\n[%s] Looking into cache for type %s", __FUNCTION__,
+LLDB_LOGF(log, "[%s] Looking into cache for type %s", __FUNCTION__,
   match_data.GetTypeForCache().AsCString(""));
 if (m_format_cache.Get(match_data.GetTypeForCache(), retval_sp)) {
   if (log) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D154128: [lldb] Add log indicating which kind of data formatter

2023-06-29 Thread Augusto Noronha via Phabricator via lldb-commits
augusto2112 accepted this revision.
augusto2112 added a comment.
This revision is now accepted and ready to land.

I've bumped into this problem before, so really like this change. It's a bit 
sad that you'll only print the kind of data formatter once though, so someone 
reading the logs might have to jump back and forth to understand what kind of 
formatter they're dealing with. There's also `__PRETTY_FUNCTION__`, which shows 
the generic type parameters by default, but I think it's not a standard macro 
(although it's implemented by both clang and gcc). What do you think of having 
a macro like:

  #ifndef __PRETTY_FUNCTION__
 #define __PRETTY_FUNCTION__ __FUNCTION__
  #endif

And replacing `__FUNCTION__` with `__PRETTY_FUNCTION__`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154128

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


[Lldb-commits] [lldb] 227b218 - Creating a startDebugging reverse DAP request handler in lldb-vscode.

2023-06-29 Thread David Goldman via lldb-commits

Author: John Harrison
Date: 2023-06-29T14:45:57-04:00
New Revision: 227b2180eb2be94986d63c75c144f88be13fc52f

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

LOG: Creating a startDebugging reverse DAP request handler in lldb-vscode.

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.

Reviewed By: wallace, ivanhernandez13

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

Added: 
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

Modified: 
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
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

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
index 236e26c6b9313f..1c77fabeb4afe8 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -126,6 +126,7 @@ def __init__(self, recv, send, init_commands, 
log_file=None):
 self.thread_stop_reasons = {}
 self.breakpoint_events = []
 self.progress_events = []
+self.reverse_requests = []
 self.sequence = 1
 self.threads = None
 self.recv_thread.start()
@@ -324,6 +325,7 @@ def send_recv(self, command):
 self.validate_response(command, response_or_request)
 return response_or_request
 else:
+self.reverse_requests.append(response_or_request)
 if response_or_request["command"] == "runInTerminal":
 subprocess.Popen(
 response_or_request["arguments"]["args"],
@@ -340,8 +342,20 @@ def send_recv(self, command):
 },
 set_sequence=False,
 )
+elif response_or_request["command"] == "startDebugging":
+self.send_packet(
+{
+"type": "response",
+"seq": -1,
+"request_seq": response_or_request["seq"],
+"success": True,
+"command": "startDebugging",
+"body": {},
+},
+set_sequence=False,
+)
 else:
-desc = 'unkonwn reverse request "%s"' % (
+desc = 'unknown reverse request "%s"' % (
 response_or_request["command"]
 )
 raise ValueError(desc)

diff  --git 
a/lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py 
b/lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
index a9a9c252908616..bd349a6e5eeead 100644
--- a/lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
+++ b/lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
@@ -59,6 +59,18 @@ def test_runInTerminal(self):
 program, runInTerminal=True, args=["foobar"], env=["FOO=bar"]
 )
 
+self.assertEqual(
+len(self.vscode.reverse_requests), 
+1, 
+"make sure we got a reverse request"
+)
+
+request = self.vscode.reverse_requests[0]
+self.assertIn(self.lldbVSCodeExec, request["arguments"]["args"])
+self.assertIn(program, request["arguments"]["args"])
+self.assertIn("foobar", request["arguments"]["args"])
+self.assertIn("FOO", request["arguments"]["env"])
+
 breakpoint_line = line_number(source, "// breakpoint")
 
 self.set_source_breakpoints(source, [breakpoint_line])

diff  --git a/lldb/test/API/tools/lldb-vscode/startDebugging/Makefile 
b/lldb/test/API/tools/lldb-vscode/startDebugging/Makefile
new file mode 100644
index 00..10495940055b63
--- /dev/null
+++ b/lldb/test/API/tools/lldb-vscode/startDebugging/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules

diff  --git 
a/lldb/test/API/tools/lldb-vscode/startDebugging/TestVSCode_startDebugging.py 

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

2023-06-29 Thread David Goldman via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG227b2180eb2b: Creating a startDebugging reverse DAP request 
handler in lldb-vscode. (authored by ashgti, committed by dgoldman).

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/runInTerminal/TestVSCode_runInTerminal.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,13 +1590,15 @@
 #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)
-return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "Process cannot be launched by the IDE. %s",
-   comm_channel.GetLauncherError().c_str());
+  g_vsc.SendReverseRequest("runInTerminal", std::move(reverse_request),
+   [](llvm::Expected value) {
+ if (!value) {
+   llvm::Error err = value.takeError();
+   llvm::errs()
+   << "runInTerminal request failed: "
+   << llvm::toString(std::move(err)) << "\n";
+ }
+   });
 
   if (llvm::Expected pid = comm_channel.GetLauncherPid())
 attach_info.SetProcessID(*pid);
@@ -1676,7 +1686,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 +3474,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 
@@ -73,6 +75,7 @@
 };
 
 typedef void (*RequestCallback)(const llvm::json::Object &command);
+typedef void (*ResponseCallbac

[Lldb-commits] [PATCH] D154028: [lldb-vscode] Prior to running the launchCommands during a launch request set the launch info so the configured launch information is accessible by the launch commands.

2023-06-29 Thread David Goldman via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfc52f8dc6ce2: [lldb-vscode] Prior to running the 
launchCommands during a launch request set… (authored by ashgti, committed by 
dgoldman).

Changed prior to commit:
  https://reviews.llvm.org/D154028?vs=535576&id=535943#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154028

Files:
  lldb/tools/lldb-vscode/README.md
  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
@@ -1695,6 +1695,9 @@
 g_vsc.target.Launch(launch_info, error);
 g_vsc.debugger.SetAsync(true);
   } else {
+// Set the launch info so that run commands can access the configured
+// launch details.
+g_vsc.target.SetLaunchInfo(launch_info);
 g_vsc.RunLLDBCommands("Running launchCommands:", launchCommands);
 // The custom commands might have created a new target so we should use the
 // selected target after these commands are run.
Index: lldb/tools/lldb-vscode/README.md
===
--- lldb/tools/lldb-vscode/README.md
+++ lldb/tools/lldb-vscode/README.md
@@ -95,6 +95,7 @@
 |**initCommands**   |[string]| | LLDB commands executed upon debugger startup 
prior to creating the LLDB target. Commands and command output will be sent to 
the debugger console when they are executed.
 |**preRunCommands** |[string]| | LLDB commands executed just before launching 
after the LLDB target has been created. Commands and command output will be 
sent to the debugger console when they are executed.
 |**stopCommands**   |[string]| | LLDB commands executed just after each stop. 
Commands and command output will be sent to the debugger console when they are 
executed.
+|**launchCommands** |[string]| | LLDB commands executed to launch the program. 
Commands and command output will be sent to the debugger console when they are 
executed.
 |**exitCommands**   |[string]| | LLDB commands executed when the program 
exits. Commands and command output will be sent to the debugger console when 
they are executed.
 |**terminateCommands** |[string]| | LLDB commands executed when the debugging 
session ends. Commands and command output will be sent to the debugger console 
when they are executed.
 |**sourceMap**  |[string[2]]| | Specify an array of path re-mappings. Each 
element in the array must be a two element array containing a source and 
destination pathname.


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1695,6 +1695,9 @@
 g_vsc.target.Launch(launch_info, error);
 g_vsc.debugger.SetAsync(true);
   } else {
+// Set the launch info so that run commands can access the configured
+// launch details.
+g_vsc.target.SetLaunchInfo(launch_info);
 g_vsc.RunLLDBCommands("Running launchCommands:", launchCommands);
 // The custom commands might have created a new target so we should use the
 // selected target after these commands are run.
Index: lldb/tools/lldb-vscode/README.md
===
--- lldb/tools/lldb-vscode/README.md
+++ lldb/tools/lldb-vscode/README.md
@@ -95,6 +95,7 @@
 |**initCommands**   |[string]| | LLDB commands executed upon debugger startup prior to creating the LLDB target. Commands and command output will be sent to the debugger console when they are executed.
 |**preRunCommands** |[string]| | LLDB commands executed just before launching after the LLDB target has been created. Commands and command output will be sent to the debugger console when they are executed.
 |**stopCommands**   |[string]| | LLDB commands executed just after each stop. Commands and command output will be sent to the debugger console when they are executed.
+|**launchCommands** |[string]| | LLDB commands executed to launch the program. Commands and command output will be sent to the debugger console when they are executed.
 |**exitCommands**   |[string]| | LLDB commands executed when the program exits. Commands and command output will be sent to the debugger console when they are executed.
 |**terminateCommands** |[string]| | LLDB commands executed when the debugging session ends. Commands and command output will be sent to the debugger console when they are executed.
 |**sourceMap**  |[string[2]]| | Specify an array of path re-mappings. Each element in the array must be a two element array containing a source and destination pathname.
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-

[Lldb-commits] [lldb] fc52f8d - [lldb-vscode] Prior to running the launchCommands during a launch request set the launch info so the configured launch information is accessible by the launch commands.

2023-06-29 Thread David Goldman via lldb-commits

Author: John Harrison
Date: 2023-06-29T14:50:19-04:00
New Revision: fc52f8dc6ce2ddd19b7b0f5ffdc9598c3abe105f

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

LOG: [lldb-vscode] Prior to running the launchCommands during a launch request 
set the launch info so the configured launch information is accessible by the 
launch commands.

Reviewed By: wallace

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

Added: 


Modified: 
lldb/tools/lldb-vscode/README.md
lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 




diff  --git a/lldb/tools/lldb-vscode/README.md 
b/lldb/tools/lldb-vscode/README.md
index 67dfa54ed4519..cd249ed2fac7c 100644
--- a/lldb/tools/lldb-vscode/README.md
+++ b/lldb/tools/lldb-vscode/README.md
@@ -95,6 +95,7 @@ file that defines how your program will be run. The JSON 
configuration file can
 |**initCommands**   |[string]| | LLDB commands executed upon debugger startup 
prior to creating the LLDB target. Commands and command output will be sent to 
the debugger console when they are executed.
 |**preRunCommands** |[string]| | LLDB commands executed just before launching 
after the LLDB target has been created. Commands and command output will be 
sent to the debugger console when they are executed.
 |**stopCommands**   |[string]| | LLDB commands executed just after each stop. 
Commands and command output will be sent to the debugger console when they are 
executed.
+|**launchCommands** |[string]| | LLDB commands executed to launch the program. 
Commands and command output will be sent to the debugger console when they are 
executed.
 |**exitCommands**   |[string]| | LLDB commands executed when the program 
exits. Commands and command output will be sent to the debugger console when 
they are executed.
 |**terminateCommands** |[string]| | LLDB commands executed when the debugging 
session ends. Commands and command output will be sent to the debugger console 
when they are executed.
 |**sourceMap**  |[string[2]]| | Specify an array of path re-mappings. Each 
element in the array must be a two element array containing a source and 
destination pathname.

diff  --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp 
b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index b9757d166958b..5815b0d22506b 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1695,6 +1695,9 @@ lldb::SBError LaunchProcess(const llvm::json::Object 
&request) {
 g_vsc.target.Launch(launch_info, error);
 g_vsc.debugger.SetAsync(true);
   } else {
+// Set the launch info so that run commands can access the configured
+// launch details.
+g_vsc.target.SetLaunchInfo(launch_info);
 g_vsc.RunLLDBCommands("Running launchCommands:", launchCommands);
 // The custom commands might have created a new target so we should use the
 // selected target after these commands are run.



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


[Lldb-commits] [lldb] b9b0ab3 - [lldb-vscode] Adjusting CreateSource to detect compiler generated frames.

2023-06-29 Thread David Goldman via lldb-commits

Author: John Harrison
Date: 2023-06-29T15:31:08-04:00
New Revision: b9b0ab32f9d0a40ee225b2dc71bdf2f66b7127e8

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

LOG: [lldb-vscode] Adjusting CreateSource to detect compiler generated frames.

Reviewed By: wallace

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

Added: 


Modified: 
lldb/tools/lldb-vscode/JSONUtils.cpp

Removed: 




diff  --git a/lldb/tools/lldb-vscode/JSONUtils.cpp 
b/lldb/tools/lldb-vscode/JSONUtils.cpp
index bf7f766a58e3d..2c54f1a4e271b 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ b/lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -613,7 +613,9 @@ llvm::json::Value CreateSource(llvm::StringRef source_path) 
{
 llvm::json::Value CreateSource(lldb::SBFrame &frame, int64_t &disasm_line) {
   disasm_line = 0;
   auto line_entry = frame.GetLineEntry();
-  if (line_entry.GetFileSpec().IsValid())
+  // A line entry of 0 indicates the line is compiler generated i.e. no source
+  // file so don't return early with the line entry.
+  if (line_entry.GetFileSpec().IsValid() && line_entry.GetLine() != 0)
 return CreateSource(line_entry);
 
   llvm::json::Object object;
@@ -650,7 +652,11 @@ llvm::json::Value CreateSource(lldb::SBFrame &frame, 
int64_t &disasm_line) {
   }
   const auto num_insts = insts.GetSize();
   if (low_pc != LLDB_INVALID_ADDRESS && num_insts > 0) {
-EmplaceSafeString(object, "name", frame.GetFunctionName());
+if (line_entry.GetLine() == 0) {
+  EmplaceSafeString(object, "name", "");
+} else {
+  EmplaceSafeString(object, "name", frame.GetDisplayFunctionName());
+}
 SourceReference source;
 llvm::raw_string_ostream src_strm(source.content);
 std::string line;



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


[Lldb-commits] [PATCH] D154026: [lldb-vscode] Adjusting CreateSource to detect compiler generated frames.

2023-06-29 Thread David Goldman via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb9b0ab32f9d0: [lldb-vscode] Adjusting CreateSource to detect 
compiler generated frames. (authored by ashgti, committed by dgoldman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154026

Files:
  lldb/tools/lldb-vscode/JSONUtils.cpp


Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -613,7 +613,9 @@
 llvm::json::Value CreateSource(lldb::SBFrame &frame, int64_t &disasm_line) {
   disasm_line = 0;
   auto line_entry = frame.GetLineEntry();
-  if (line_entry.GetFileSpec().IsValid())
+  // A line entry of 0 indicates the line is compiler generated i.e. no source
+  // file so don't return early with the line entry.
+  if (line_entry.GetFileSpec().IsValid() && line_entry.GetLine() != 0)
 return CreateSource(line_entry);
 
   llvm::json::Object object;
@@ -650,7 +652,11 @@
   }
   const auto num_insts = insts.GetSize();
   if (low_pc != LLDB_INVALID_ADDRESS && num_insts > 0) {
-EmplaceSafeString(object, "name", frame.GetFunctionName());
+if (line_entry.GetLine() == 0) {
+  EmplaceSafeString(object, "name", "");
+} else {
+  EmplaceSafeString(object, "name", frame.GetDisplayFunctionName());
+}
 SourceReference source;
 llvm::raw_string_ostream src_strm(source.content);
 std::string line;


Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -613,7 +613,9 @@
 llvm::json::Value CreateSource(lldb::SBFrame &frame, int64_t &disasm_line) {
   disasm_line = 0;
   auto line_entry = frame.GetLineEntry();
-  if (line_entry.GetFileSpec().IsValid())
+  // A line entry of 0 indicates the line is compiler generated i.e. no source
+  // file so don't return early with the line entry.
+  if (line_entry.GetFileSpec().IsValid() && line_entry.GetLine() != 0)
 return CreateSource(line_entry);
 
   llvm::json::Object object;
@@ -650,7 +652,11 @@
   }
   const auto num_insts = insts.GetSize();
   if (low_pc != LLDB_INVALID_ADDRESS && num_insts > 0) {
-EmplaceSafeString(object, "name", frame.GetFunctionName());
+if (line_entry.GetLine() == 0) {
+  EmplaceSafeString(object, "name", "");
+} else {
+  EmplaceSafeString(object, "name", frame.GetDisplayFunctionName());
+}
 SourceReference source;
 llvm::raw_string_ostream src_strm(source.content);
 std::string line;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D154128: [lldb] Add log indicating which kind of data formatter

2023-06-29 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added a comment.

I just test gave `__PRETTY_FUNCTION__` a test drive, and it's a bit 
verbose/noisy: For example:

  [ImplSP lldb_private::FormatManager::Get(lldb_private::ValueObject &, 
lldb::DynamicValueType) [ImplSP = 
std::shared_ptr]] Begin synthetic lookup.

Here's an example of the formatter logs with my change. Note that these logs 
are output in "blocks", that is the first line is prefixed with two newlines 
(`\n\n`):

  [Get] Begin summary lookup.
   [GetCached] Looking into cache for type Swift.Optional
   [GetCached] Cache search failed. Going normal route
   [Get] candidate match = Swift.Optional no-strip-pointers 
no-strip-reference no-strip-typedef
   [Get] candidate match = main.Item? no-strip-pointers no-strip-reference 
no-strip-typedef
   [Get] candidate match = Swift.Optional no-strip-pointers 
no-strip-reference no-strip-typedef
   [Get] candidate match = Swift.Optional no-strip-pointers 
no-strip-reference no-strip-typedef
   [Get] candidate match = main.Item? no-strip-pointers no-strip-reference 
no-strip-typedef
   [Get] candidate match = Swift.Optional no-strip-pointers 
no-strip-reference no-strip-typedef
   [Get] Trying to use category default
   [Get] Trying to use category llvm
   [Get] Trying to use category VectorTypes
   [Get] Trying to use category runtime-synthetics
   [Get] Trying to use category system
   [Get] nothing found - returning empty SP
   [GetCached] Caching 0x0 for type Swift.Optional
   [Get] Search failed. Giving language a chance.
   [Get] Language search success. Returning.

At the beginning of the lines, those names in square brackets are the 
`__FUNCTION__` macro. If they were replaced with `__PRETTY_FUNCTION__`, I think 
it would be too noisy.

> someone reading the logs might have to jump back and forth to understand what 
> kind of formatter they're dealing with

I agree that this isn't ideal, As mentioned above, there are two newlines used 
to group and separate related log statements. This is why I put the new log at 
the top. Someone reading these logs can look at the first line in the block to 
know what kind of formatter is active. It's hard to strike a balance: if every 
line says the formatter kind, it's both convenient but also redundant/noisy.

In summary:

- I think `__PRETTY_FUNCTION__` is too noisy to be useful
- If we want each log statement to include the formatter kind, I am ok with 
that (but personally I can work with having it be mentioned at the top of each 
block)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154128

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


[Lldb-commits] [PATCH] D154128: [lldb] Add log indicating which kind of data formatter

2023-06-29 Thread Augusto Noronha via Phabricator via lldb-commits
augusto2112 added a comment.

Personally I vote for the formatter kind on every line, so we don't need to 
jump around the logs when reading them, up to you though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154128

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


[Lldb-commits] [PATCH] D153513: [lldb] Check that qLaunchGDBServer packet does not return an error

2023-06-29 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda accepted this revision.
jasonmolenda added a comment.
This revision is now accepted and ready to land.

Ah, sorry for not getting back to this one!  Nice job coming up with a test.  
LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153513

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


[Lldb-commits] [PATCH] D154030: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

2023-06-29 Thread John Harrison via Phabricator via lldb-commits
ashgti updated this revision to Diff 536031.
ashgti added a comment.

Pull + Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154030

Files:
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/JSONUtils.h
  lldb/tools/lldb-vscode/Options.td
  lldb/tools/lldb-vscode/README.md
  lldb/tools/lldb-vscode/SourceBreakpoint.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
@@ -252,7 +252,7 @@
 }
   }
 
-  // We will have cleared g_vsc.focus_tid if he focus thread doesn't have
+  // We will have cleared g_vsc.focus_tid if the focus thread doesn't have
   // a stop reason, so if it was cleared, or wasn't set, or doesn't exist,
   // then set the focus thread to the first thread with a stop reason.
   if (!focus_thread_exists || g_vsc.focus_tid == LLDB_INVALID_THREAD_ID)
@@ -1065,50 +1065,62 @@
   FillResponse(request, response);
   llvm::json::Object body;
   auto arguments = request.getObject("arguments");
+
+  // If we have a frame, try to set the context for variable completions.
+  lldb::SBFrame frame = g_vsc.GetLLDBFrame(*arguments);
+  if (frame.IsValid()) {
+frame.GetThread().GetProcess().SetSelectedThread(frame.GetThread());
+frame.GetThread().SetSelectedFrame(frame.GetFrameID());
+  }
+
   std::string text = std::string(GetString(arguments, "text"));
   auto original_column = GetSigned(arguments, "column", text.size());
-  auto actual_column = original_column - 1;
+  auto original_line = GetSigned(arguments, "line", 1);
+  auto offset = original_column - 1;
+  if (original_line > 1) {
+llvm::StringRef text_ref{text};
+::llvm::SmallVector<::llvm::StringRef, 2> lines;
+text_ref.split(lines, '\n');
+for (int i = 0; i < original_line - 1; i++) {
+  offset += lines[i].size();
+}
+  }
   llvm::json::Array targets;
-  // NOTE: the 'line' argument is not needed, as multiline expressions
-  // work well already
-  // TODO: support frameID. Currently
-  // g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions
-  // is frame-unaware.
-
-  if (!text.empty() && text[0] == '`') {
-text = text.substr(1);
-actual_column--;
-  } else {
-char command[] = "expression -- ";
+
+  if (g_vsc.DetectExpressionContext(text) == ExpressionContext::Variable) {
+char command[] = "frame variable ";
 text = command + text;
-actual_column += strlen(command);
+offset += strlen(command);
   }
   lldb::SBStringList matches;
   lldb::SBStringList descriptions;
-  g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions(
-  text.c_str(), actual_column, 0, -1, matches, descriptions);
-  size_t count = std::min((uint32_t)100, matches.GetSize());
-  targets.reserve(count);
-  for (size_t i = 0; i < count; i++) {
-std::string match = matches.GetStringAtIndex(i);
-std::string description = descriptions.GetStringAtIndex(i);
-
-llvm::json::Object item;
-
-llvm::StringRef match_ref = match;
-for (llvm::StringRef commit_point : {".", "->"}) {
-  if (match_ref.contains(commit_point)) {
-match_ref = match_ref.rsplit(commit_point).second;
+
+  if (g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions(
+  text.c_str(), offset, 0, 100, matches, descriptions)) {
+// The first element is the common substring after the cursor position for
+// all the matches. The rest of the elements are the matches.
+targets.reserve(matches.GetSize() - 1);
+std::string common_pattern = matches.GetStringAtIndex(0);
+for (size_t i = 1; i < matches.GetSize(); i++) {
+  std::string match = matches.GetStringAtIndex(i);
+  std::string description = descriptions.GetStringAtIndex(i);
+
+  llvm::json::Object item;
+  llvm::StringRef match_ref = match;
+  for (llvm::StringRef commit_point : {".", "->"}) {
+if (match_ref.contains(commit_point)) {
+  match_ref = match_ref.rsplit(commit_point).second;
+}
   }
-}
-EmplaceSafeString(item, "text", match_ref);
+  EmplaceSafeString(item, "text", match_ref);
 
-if (description.empty())
-  EmplaceSafeString(item, "label", match);
-else
-  EmplaceSafeString(item, "label", match + " -- " + description);
+  if (description.empty())
+EmplaceSafeString(item, "label", match);
+  else
+EmplaceSafeString(item, "label", match + " -- " + description);
 
-targets.emplace_back(std::move(item));
+  targets.emplace_back(std::move(item));
+}
   }
 
   body.try_emplace("targets", std::move(targets));
@@ -1223,12 +1235,17 @@
   llvm::json::Object body;
   auto arguments = request.getObj

[Lldb-commits] [PATCH] D154030: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

2023-06-29 Thread John Harrison via Phabricator via lldb-commits
ashgti added a reviewer: wallace.
ashgti added a comment.

Hi wallace,

I created to improve the repl behavior of lldb-vscode allowing users to more 
easily run lldb commands. I started 
https://discourse.llvm.org/t/rfc-lldb-vscode-evaluate-repl-behavior-and-improvements/71667
 as well to outline some of behaviors from this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154030

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


[Lldb-commits] [PATCH] D154169: add a target dump section-load-list command for inspecting the Target's SectionLoadList

2023-06-29 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda created this revision.
jasonmolenda added a reviewer: mib.
jasonmolenda added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

When debugging possible issues with the Target's SectionLoadList table, it 
would be helpful to have a way to dump all of the entries.  Add that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154169

Files:
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Target/SectionLoadList.cpp


Index: lldb/source/Target/SectionLoadList.cpp
===
--- lldb/source/Target/SectionLoadList.cpp
+++ lldb/source/Target/SectionLoadList.cpp
@@ -262,8 +262,7 @@
   addr_to_sect_collection::const_iterator pos, end;
   for (pos = m_addr_to_sect.begin(), end = m_addr_to_sect.end(); pos != end;
++pos) {
-s.Printf("addr = 0x%16.16" PRIx64 ", section = %p: ", pos->first,
- static_cast(pos->second.get()));
+s.Printf("addr = 0x%16.16" PRIx64 " ", pos->first);
 pos->second->Dump(s.AsRawOstream(), s.GetIndentLevel(), target, 0);
   }
 }
Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -5123,6 +5123,30 @@
   }
 };
 
+#pragma mark CommandObjectTargetDumpSectionLoadList
+
+/// Dumps the SectionLoadList of the selected Target.
+class CommandObjectTargetDumpSectionLoadList : public CommandObjectParsed {
+public:
+  CommandObjectTargetDumpSectionLoadList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "target dump section-load-list",
+"Dump the state of the target's internal section load list. "
+"Intended to be used for debugging LLDB itself.",
+nullptr, eCommandRequiresTarget) {}
+
+  ~CommandObjectTargetDumpSectionLoadList() override = default;
+
+protected:
+  bool DoExecute(Args &command, CommandReturnObject &result) override {
+Target &target = GetSelectedTarget();
+target.GetSectionLoadList().Dump(result.GetOutputStream(), &target);
+result.SetStatus(eReturnStatusSuccessFinishResult);
+return result.Succeeded();
+  }
+};
+
+
 #pragma mark CommandObjectTargetDump
 
 /// Multi-word command for 'target dump'.
@@ -5133,10 +5157,13 @@
   : CommandObjectMultiword(
 interpreter, "target dump",
 "Commands for dumping information about the target.",
-"target dump [typesystem]") {
+"target dump [typesystem|section-load-list]") {
 LoadSubCommand(
 "typesystem",
 CommandObjectSP(new CommandObjectTargetDumpTypesystem(interpreter)));
+LoadSubCommand(
+"section-load-list",
+CommandObjectSP(new 
CommandObjectTargetDumpSectionLoadList(interpreter)));
   }
 
   ~CommandObjectTargetDump() override = default;


Index: lldb/source/Target/SectionLoadList.cpp
===
--- lldb/source/Target/SectionLoadList.cpp
+++ lldb/source/Target/SectionLoadList.cpp
@@ -262,8 +262,7 @@
   addr_to_sect_collection::const_iterator pos, end;
   for (pos = m_addr_to_sect.begin(), end = m_addr_to_sect.end(); pos != end;
++pos) {
-s.Printf("addr = 0x%16.16" PRIx64 ", section = %p: ", pos->first,
- static_cast(pos->second.get()));
+s.Printf("addr = 0x%16.16" PRIx64 " ", pos->first);
 pos->second->Dump(s.AsRawOstream(), s.GetIndentLevel(), target, 0);
   }
 }
Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -5123,6 +5123,30 @@
   }
 };
 
+#pragma mark CommandObjectTargetDumpSectionLoadList
+
+/// Dumps the SectionLoadList of the selected Target.
+class CommandObjectTargetDumpSectionLoadList : public CommandObjectParsed {
+public:
+  CommandObjectTargetDumpSectionLoadList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "target dump section-load-list",
+"Dump the state of the target's internal section load list. "
+"Intended to be used for debugging LLDB itself.",
+nullptr, eCommandRequiresTarget) {}
+
+  ~CommandObjectTargetDumpSectionLoadList() override = default;
+
+protected:
+  bool DoExecute(Args &command, CommandReturnObject &result) override {
+Target &target = GetSelectedTarget();
+target.GetSectionLoadList().Dump(result.GetOutputStream(), &target);
+result.SetStatus(eReturnStatusSuccessFinishResult);
+return result.Succeeded();
+  }
+};
+
+
 #pragma mark CommandObjectTargetDump
 
 /// Multi-word command for 'target dump'.
@@ -5133,10 +5157,13 @@
   : CommandObjectMultiword(
   

[Lldb-commits] [PATCH] D154169: add a target dump section-load-list command for inspecting the Target's SectionLoadList

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

That's indeed very helpful! LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154169

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


[Lldb-commits] [PATCH] D154169: add a target dump section-load-list command for inspecting the Target's SectionLoadList

2023-06-29 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added inline comments.



Comment at: lldb/source/Target/SectionLoadList.cpp:265-266
++pos) {
-s.Printf("addr = 0x%16.16" PRIx64 ", section = %p: ", pos->first,
- static_cast(pos->second.get()));
 pos->second->Dump(s.AsRawOstream(), s.GetIndentLevel(), target, 0);

Out of curiosity, why did you remove the section part ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154169

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


[Lldb-commits] [PATCH] D154169: add a target dump section-load-list command for inspecting the Target's SectionLoadList

2023-06-29 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added inline comments.



Comment at: lldb/source/Target/SectionLoadList.cpp:265-266
++pos) {
-s.Printf("addr = 0x%16.16" PRIx64 ", section = %p: ", pos->first,
- static_cast(pos->second.get()));
 pos->second->Dump(s.AsRawOstream(), s.GetIndentLevel(), target, 0);

mib wrote:
> Out of curiosity, why did you remove the section part ?
I was being grumpy when I saw all the fields SectionLoadList::Dump was 
outputting and removed one of them to make me feel better, but I have to 
acknowledge that seeing the actual Section* value for the section may be 
helpful when debugging lldb.  I'll remove this part of the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154169

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


[Lldb-commits] [lldb] ad45114 - Add 'target dump section-load-list' for lldb debugging

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

Author: Jason Molenda
Date: 2023-06-29T17:02:54-07:00
New Revision: ad451146e8f59de76e393094d3aafc97a854c40b

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

LOG: Add 'target dump section-load-list' for lldb debugging

A command to dump the Target's SectionLoadList, to debug
possible issues with the table.

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

Added: 


Modified: 
lldb/source/Commands/CommandObjectTarget.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp
index 81a2fe4c9f2baa..22045948f88ba9 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -5123,6 +5123,29 @@ class CommandObjectTargetDumpTypesystem : public 
CommandObjectParsed {
   }
 };
 
+#pragma mark CommandObjectTargetDumpSectionLoadList
+
+/// Dumps the SectionLoadList of the selected Target.
+class CommandObjectTargetDumpSectionLoadList : public CommandObjectParsed {
+public:
+  CommandObjectTargetDumpSectionLoadList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "target dump section-load-list",
+"Dump the state of the target's internal section load list. "
+"Intended to be used for debugging LLDB itself.",
+nullptr, eCommandRequiresTarget) {}
+
+  ~CommandObjectTargetDumpSectionLoadList() override = default;
+
+protected:
+  bool DoExecute(Args &command, CommandReturnObject &result) override {
+Target &target = GetSelectedTarget();
+target.GetSectionLoadList().Dump(result.GetOutputStream(), &target);
+result.SetStatus(eReturnStatusSuccessFinishResult);
+return result.Succeeded();
+  }
+};
+
 #pragma mark CommandObjectTargetDump
 
 /// Multi-word command for 'target dump'.
@@ -5133,10 +5156,13 @@ class CommandObjectTargetDump : public 
CommandObjectMultiword {
   : CommandObjectMultiword(
 interpreter, "target dump",
 "Commands for dumping information about the target.",
-"target dump [typesystem]") {
+"target dump [typesystem|section-load-list]") {
 LoadSubCommand(
 "typesystem",
 CommandObjectSP(new CommandObjectTargetDumpTypesystem(interpreter)));
+LoadSubCommand("section-load-list",
+   CommandObjectSP(new CommandObjectTargetDumpSectionLoadList(
+   interpreter)));
   }
 
   ~CommandObjectTargetDump() override = default;



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


[Lldb-commits] [PATCH] D154169: add a target dump section-load-list command for inspecting the Target's SectionLoadList

2023-06-29 Thread Jason Molenda via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGad451146e8f5: Add 'target dump section-load-list' 
for lldb debugging (authored by jasonmolenda).

Changed prior to commit:
  https://reviews.llvm.org/D154169?vs=536049&id=536057#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154169

Files:
  lldb/source/Commands/CommandObjectTarget.cpp


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -5123,6 +5123,29 @@
   }
 };
 
+#pragma mark CommandObjectTargetDumpSectionLoadList
+
+/// Dumps the SectionLoadList of the selected Target.
+class CommandObjectTargetDumpSectionLoadList : public CommandObjectParsed {
+public:
+  CommandObjectTargetDumpSectionLoadList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "target dump section-load-list",
+"Dump the state of the target's internal section load list. "
+"Intended to be used for debugging LLDB itself.",
+nullptr, eCommandRequiresTarget) {}
+
+  ~CommandObjectTargetDumpSectionLoadList() override = default;
+
+protected:
+  bool DoExecute(Args &command, CommandReturnObject &result) override {
+Target &target = GetSelectedTarget();
+target.GetSectionLoadList().Dump(result.GetOutputStream(), &target);
+result.SetStatus(eReturnStatusSuccessFinishResult);
+return result.Succeeded();
+  }
+};
+
 #pragma mark CommandObjectTargetDump
 
 /// Multi-word command for 'target dump'.
@@ -5133,10 +5156,13 @@
   : CommandObjectMultiword(
 interpreter, "target dump",
 "Commands for dumping information about the target.",
-"target dump [typesystem]") {
+"target dump [typesystem|section-load-list]") {
 LoadSubCommand(
 "typesystem",
 CommandObjectSP(new CommandObjectTargetDumpTypesystem(interpreter)));
+LoadSubCommand("section-load-list",
+   CommandObjectSP(new CommandObjectTargetDumpSectionLoadList(
+   interpreter)));
   }
 
   ~CommandObjectTargetDump() override = default;


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -5123,6 +5123,29 @@
   }
 };
 
+#pragma mark CommandObjectTargetDumpSectionLoadList
+
+/// Dumps the SectionLoadList of the selected Target.
+class CommandObjectTargetDumpSectionLoadList : public CommandObjectParsed {
+public:
+  CommandObjectTargetDumpSectionLoadList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "target dump section-load-list",
+"Dump the state of the target's internal section load list. "
+"Intended to be used for debugging LLDB itself.",
+nullptr, eCommandRequiresTarget) {}
+
+  ~CommandObjectTargetDumpSectionLoadList() override = default;
+
+protected:
+  bool DoExecute(Args &command, CommandReturnObject &result) override {
+Target &target = GetSelectedTarget();
+target.GetSectionLoadList().Dump(result.GetOutputStream(), &target);
+result.SetStatus(eReturnStatusSuccessFinishResult);
+return result.Succeeded();
+  }
+};
+
 #pragma mark CommandObjectTargetDump
 
 /// Multi-word command for 'target dump'.
@@ -5133,10 +5156,13 @@
   : CommandObjectMultiword(
 interpreter, "target dump",
 "Commands for dumping information about the target.",
-"target dump [typesystem]") {
+"target dump [typesystem|section-load-list]") {
 LoadSubCommand(
 "typesystem",
 CommandObjectSP(new CommandObjectTargetDumpTypesystem(interpreter)));
+LoadSubCommand("section-load-list",
+   CommandObjectSP(new CommandObjectTargetDumpSectionLoadList(
+   interpreter)));
   }
 
   ~CommandObjectTargetDump() override = default;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D154037: Recognize BSS-only DATA segments as sections that need to be slid/loaded at addresses

2023-06-29 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/D154037/new/

https://reviews.llvm.org/D154037

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


[Lldb-commits] [lldb] 623e845 - Recognize BSS-only DATA segments as sections that need to be slid

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

Author: Jason Molenda
Date: 2023-06-29T17:51:41-07:00
New Revision: 623e8455919af69b039fe7450118ba953423a027

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

LOG: Recognize BSS-only DATA segments as sections that need to be slid

ObjectFileMachO::SetLoadAddress() should allow for a DATA segment
that has no file content to be slid in the vmaddr, it is valid
to have such a section.

Differential Revision: https://reviews.llvm.org/D154037
rdar://99744343

Added: 
lldb/test/API/macosx/bss-only-data-section-sliding/Makefile

lldb/test/API/macosx/bss-only-data-section-sliding/TestBSSOnlyDataSectionSliding.py
lldb/test/API/macosx/bss-only-data-section-sliding/main.c

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 ce904b0a9c7a00..cab93f5b471f26 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6048,7 +6048,8 @@ bool ObjectFileMachO::SectionIsLoadable(const Section 
*section) {
   if (!section)
 return false;
   const bool is_dsym = (m_header.filetype == MH_DSYM);
-  if (section->GetFileSize() == 0 && !is_dsym)
+  if (section->GetFileSize() == 0 && !is_dsym &&
+  section->GetName() != GetSegmentNameDATA())
 return false;
   if (section->IsThreadSpecific())
 return false;

diff  --git a/lldb/test/API/macosx/bss-only-data-section-sliding/Makefile 
b/lldb/test/API/macosx/bss-only-data-section-sliding/Makefile
new file mode 100644
index 00..10495940055b63
--- /dev/null
+++ b/lldb/test/API/macosx/bss-only-data-section-sliding/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules

diff  --git 
a/lldb/test/API/macosx/bss-only-data-section-sliding/TestBSSOnlyDataSectionSliding.py
 
b/lldb/test/API/macosx/bss-only-data-section-sliding/TestBSSOnlyDataSectionSliding.py
new file mode 100644
index 00..bc7d69a592e3da
--- /dev/null
+++ 
b/lldb/test/API/macosx/bss-only-data-section-sliding/TestBSSOnlyDataSectionSliding.py
@@ -0,0 +1,27 @@
+"""Test that we a BSS-data only DATA segment is slid with other segments."""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestBSSOnlyDataSectionSliding(TestBase):
+@skipUnlessDarwin
+def test_with_python_api(self):
+"""Test that we get thread names when interrupting a process."""
+self.build()
+exe = self.getBuildArtifact("a.out")
+
+target = self.dbg.CreateTarget(exe, "", "", False, lldb.SBError())
+self.assertTrue(target, VALID_TARGET)
+
+module = target.modules[0]
+self.assertTrue(module.IsValid())
+data_sect = module.section["__DATA"]
+self.assertTrue(data_sect.IsValid())
+
+target.SetModuleLoadAddress(module, 0x17000)
+self.assertEqual(
+data_sect.GetFileAddress() + 0x17000, 
data_sect.GetLoadAddress(target)
+)

diff  --git a/lldb/test/API/macosx/bss-only-data-section-sliding/main.c 
b/lldb/test/API/macosx/bss-only-data-section-sliding/main.c
new file mode 100644
index 00..14cf307c684e11
--- /dev/null
+++ b/lldb/test/API/macosx/bss-only-data-section-sliding/main.c
@@ -0,0 +1,2 @@
+int glob = 0;
+int main() { return glob; }



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


[Lldb-commits] [PATCH] D154037: Recognize BSS-only DATA segments as sections that need to be slid/loaded at addresses

2023-06-29 Thread Jason Molenda via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG623e8455919a: Recognize BSS-only DATA segments as sections 
that need to be slid (authored by jasonmolenda).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154037

Files:
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/test/API/macosx/bss-only-data-section-sliding/Makefile
  
lldb/test/API/macosx/bss-only-data-section-sliding/TestBSSOnlyDataSectionSliding.py
  lldb/test/API/macosx/bss-only-data-section-sliding/main.c


Index: lldb/test/API/macosx/bss-only-data-section-sliding/main.c
===
--- /dev/null
+++ lldb/test/API/macosx/bss-only-data-section-sliding/main.c
@@ -0,0 +1,2 @@
+int glob = 0;
+int main() { return glob; }
Index: 
lldb/test/API/macosx/bss-only-data-section-sliding/TestBSSOnlyDataSectionSliding.py
===
--- /dev/null
+++ 
lldb/test/API/macosx/bss-only-data-section-sliding/TestBSSOnlyDataSectionSliding.py
@@ -0,0 +1,27 @@
+"""Test that we a BSS-data only DATA segment is slid with other segments."""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestBSSOnlyDataSectionSliding(TestBase):
+@skipUnlessDarwin
+def test_with_python_api(self):
+"""Test that we get thread names when interrupting a process."""
+self.build()
+exe = self.getBuildArtifact("a.out")
+
+target = self.dbg.CreateTarget(exe, "", "", False, lldb.SBError())
+self.assertTrue(target, VALID_TARGET)
+
+module = target.modules[0]
+self.assertTrue(module.IsValid())
+data_sect = module.section["__DATA"]
+self.assertTrue(data_sect.IsValid())
+
+target.SetModuleLoadAddress(module, 0x17000)
+self.assertEqual(
+data_sect.GetFileAddress() + 0x17000, 
data_sect.GetLoadAddress(target)
+)
Index: lldb/test/API/macosx/bss-only-data-section-sliding/Makefile
===
--- /dev/null
+++ lldb/test/API/macosx/bss-only-data-section-sliding/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
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
@@ -6048,7 +6048,8 @@
   if (!section)
 return false;
   const bool is_dsym = (m_header.filetype == MH_DSYM);
-  if (section->GetFileSize() == 0 && !is_dsym)
+  if (section->GetFileSize() == 0 && !is_dsym &&
+  section->GetName() != GetSegmentNameDATA())
 return false;
   if (section->IsThreadSpecific())
 return false;


Index: lldb/test/API/macosx/bss-only-data-section-sliding/main.c
===
--- /dev/null
+++ lldb/test/API/macosx/bss-only-data-section-sliding/main.c
@@ -0,0 +1,2 @@
+int glob = 0;
+int main() { return glob; }
Index: lldb/test/API/macosx/bss-only-data-section-sliding/TestBSSOnlyDataSectionSliding.py
===
--- /dev/null
+++ lldb/test/API/macosx/bss-only-data-section-sliding/TestBSSOnlyDataSectionSliding.py
@@ -0,0 +1,27 @@
+"""Test that we a BSS-data only DATA segment is slid with other segments."""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestBSSOnlyDataSectionSliding(TestBase):
+@skipUnlessDarwin
+def test_with_python_api(self):
+"""Test that we get thread names when interrupting a process."""
+self.build()
+exe = self.getBuildArtifact("a.out")
+
+target = self.dbg.CreateTarget(exe, "", "", False, lldb.SBError())
+self.assertTrue(target, VALID_TARGET)
+
+module = target.modules[0]
+self.assertTrue(module.IsValid())
+data_sect = module.section["__DATA"]
+self.assertTrue(data_sect.IsValid())
+
+target.SetModuleLoadAddress(module, 0x17000)
+self.assertEqual(
+data_sect.GetFileAddress() + 0x17000, data_sect.GetLoadAddress(target)
+)
Index: lldb/test/API/macosx/bss-only-data-section-sliding/Makefile
===
--- /dev/null
+++ lldb/test/API/macosx/bss-only-data-section-sliding/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/

[Lldb-commits] [lldb] 37d11e9 - "fp" -> "flags" typeo in description of generic registers

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

Author: Jason Molenda
Date: 2023-06-29T18:22:58-07:00
New Revision: 37d11e94a4eb5452158f0ae73ed7752136e41439

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

LOG: "fp" -> "flags" typeo in description of generic registers

the list of generic registers is meant to include
LLDB_REGNUM_GENERIC_FLAGS but it copy & pasted the
name "fp".

rdar://100857252

Added: 


Modified: 
lldb/docs/lldb-gdb-remote.txt

Removed: 




diff  --git a/lldb/docs/lldb-gdb-remote.txt b/lldb/docs/lldb-gdb-remote.txt
index 28180df714e004..27adaa33d14045 100644
--- a/lldb/docs/lldb-gdb-remote.txt
+++ b/lldb/docs/lldb-gdb-remote.txt
@@ -806,7 +806,7 @@ generic If the register is a generic register that most 
CPUs have, classify
ABI) would include a "generic=fp;" key value pair)
  ra  (a return address register. for example "name=lr;" (32 bit 
ARM)
   would include a "generic=ra;" key value pair)
- fp  (a CPU flags register. for example "name=eflags;" (i386),
+ flags  (a CPU flags register. for example "name=eflags;" (i386),
   "name=rflags;" (x86_64), "name=cpsr;" (32 bit ARM)
   would include a "generic=flags;" key value pair)
  arg1 - arg8 (specified for registers that contain function



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