[Lldb-commits] [PATCH] D147831: [lldb-vscode] Implement RestartRequest

2023-04-10 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
jgorbe marked 2 inline comments as done.
jgorbe added inline comments.



Comment at: lldb/tools/lldb-vscode/VSCode.h:146
+  // arguments if we get a RestartRequest.
+  llvm::json::Object last_launch_or_attach_request;
   lldb::tid_t focus_tid;

rupprecht wrote:
> std::optional? And then we can raise an error if the 
> client calls restart and this is std::nullopt.
Done, thanks!



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:602
 // }
 void request_attach(const llvm::json::Object ) {
   g_vsc.is_attach = true;

rupprecht wrote:
> Should we also set `last_launch_or_attach_request` here?
> 
> If the user runs:
> 1) Launch
> 2) Attach
> 3) Restart
> 
> I would expect that should fail because of the reasons restarting an attach 
> will fail. But if we don't set `last_launch_or_attach_request`, it will pass, 
> because we set it in (1).
Yup, I missed that one, thanks for catching it! :)


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

https://reviews.llvm.org/D147831

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


[Lldb-commits] [PATCH] D147831: [lldb-vscode] Implement RestartRequest

2023-04-10 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
jgorbe updated this revision to Diff 512305.
jgorbe added a comment.

Addressed review comments.

- Changed `last_launch_or_attach_request` to be a 
`std::optional` so we can check if it has been set. Also 
check for `nullopt` in request_restart.
- Made `request_attach` also set `last_launch_or_attach_request`.


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

https://reviews.llvm.org/D147831

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
  lldb/source/API/SBProcess.cpp
  lldb/test/API/tools/lldb-vscode/restart/Makefile
  lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart.py
  lldb/test/API/tools/lldb-vscode/restart/TestVSCode_restart_runInTerminal.py
  lldb/test/API/tools/lldb-vscode/restart/main.c
  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
@@ -458,7 +458,8 @@
 // manually send a stopped event in request_configurationDone(...)
 // so don't send any before then.
 if (g_vsc.configuration_done_sent) {
-  // Only report a stopped event if the process was not restarted.
+  // Only report a stopped event if the process was not
+  // automatically restarted.
   if (!lldb::SBProcess::GetRestartedFromEvent(event)) {
 SendStdOutStdErr(process);
 SendThreadStoppedEvent();
@@ -468,14 +469,22 @@
   case lldb::eStateRunning:
 g_vsc.WillContinue();
 break;
-  case lldb::eStateExited: {
-// Run any exit LLDB commands the user specified in the
-// launch.json
-g_vsc.RunExitCommands();
-SendProcessExitedEvent(process);
-SendTerminatedEvent();
-done = true;
-  } break;
+  case lldb::eStateExited:
+// When restarting, we can get an "exited" event for the process we
+// just killed with the old PID, or even with no PID. In that case
+// we don't have to terminate the session.
+if (process.GetProcessID() == LLDB_INVALID_PROCESS_ID ||
+process.GetProcessID() == g_vsc.restarting_process_id) {
+  g_vsc.restarting_process_id = LLDB_INVALID_PROCESS_ID;
+} else {
+  // Run any exit LLDB commands the user specified in the
+  // launch.json
+  g_vsc.RunExitCommands();
+  SendProcessExitedEvent(process);
+  SendTerminatedEvent();
+  done = true;
+}
+break;
   }
 } else if ((event_mask & lldb::SBProcess::eBroadcastBitSTDOUT) ||
(event_mask & lldb::SBProcess::eBroadcastBitSTDERR)) {
@@ -592,6 +601,7 @@
 // }
 void request_attach(const llvm::json::Object ) {
   g_vsc.is_attach = true;
+  g_vsc.last_launch_or_attach_request = request;
   llvm::json::Object response;
   lldb::SBError error;
   FillResponse(request, response);
@@ -1527,7 +1537,7 @@
   // The debug adapter supports the RestartRequest. In this case a client
   // should not implement 'restart' by terminating and relaunching the adapter
   // but by calling the RestartRequest.
-  body.try_emplace("supportsRestartRequest", false);
+  body.try_emplace("supportsRestartRequest", true);
   // The debug adapter supports 'exceptionOptions' on the
   // setExceptionBreakpoints request.
   body.try_emplace("supportsExceptionOptions", true);
@@ -1622,6 +1632,71 @@
  error.GetCString());
 }
 
+// Takes a LaunchRequest object and launches the process, also handling
+// runInTerminal if applicable. It doesn't do any of the additional
+// initialization and bookkeeping stuff that is needed for `request_launch`.
+// This way we can reuse the process launching logic for RestartRequest too.
+lldb::SBError LaunchProcess(const llvm::json::Object ) {
+  lldb::SBError error;
+  auto arguments = request.getObject("arguments");
+  auto launchCommands = GetStrings(arguments, "launchCommands");
+
+  // Instantiate a launch info instance for the target.
+  auto launch_info = g_vsc.target.GetLaunchInfo();
+
+  // Grab the current working directory if there is one and set it in the
+  // launch info.
+  const auto cwd = GetString(arguments, "cwd");
+  if (!cwd.empty())
+launch_info.SetWorkingDirectory(cwd.data());
+
+  // Extract any extra arguments and append them to our program arguments for
+  // when we launch
+  auto args = GetStrings(arguments, "args");
+  if (!args.empty())
+launch_info.SetArguments(MakeArgv(args).data(), true);
+
+  // Pass any environment variables along that the user specified.
+  auto envs = GetStrings(arguments, "env");
+  if (!envs.empty())
+

[Lldb-commits] [PATCH] D147805: [lldb-vscode] Fix two issues with runInTerminal test.

2023-04-10 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG53aa22cd9ac4: [lldb-vscode] Fix two issues with 
runInTerminal test. (authored by jgorbe).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147805

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
  lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/JSONUtils.h
  lldb/tools/lldb-vscode/Options.td
  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
@@ -32,6 +32,10 @@
 #include 
 #endif
 
+#if defined(__linux__)
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -1562,8 +1566,12 @@
 
   RunInTerminalDebugAdapterCommChannel comm_channel(comm_file.m_path);
 
+  lldb::pid_t debugger_pid = LLDB_INVALID_PROCESS_ID;
+#if !defined(_WIN32)
+  debugger_pid = getpid();
+#endif
   llvm::json::Object reverse_request = CreateRunInTerminalReverseRequest(
-  launch_request, g_vsc.debug_adaptor_path, comm_file.m_path);
+  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);
@@ -3141,11 +3149,21 @@
 // In case of errors launching the target, a suitable error message will be
 // emitted to the debug adaptor.
 void LaunchRunInTerminalTarget(llvm::opt::Arg _arg,
-   llvm::StringRef comm_file, char *argv[]) {
+   llvm::StringRef comm_file,
+   lldb::pid_t debugger_pid, char *argv[]) {
 #if defined(_WIN32)
   llvm::errs() << "runInTerminal is only supported on POSIX systems\n";
   exit(EXIT_FAILURE);
 #else
+
+  // On Linux with the Yama security module enabled, a process can only attach
+  // to its descendants by default. In the runInTerminal case the target
+  // process is launched by the client so we need to allow tracing explicitly.
+#if defined(__linux__)
+  if (debugger_pid != LLDB_INVALID_PROCESS_ID)
+(void)prctl(PR_SET_PTRACER, debugger_pid, 0, 0, 0);
+#endif
+
   RunInTerminalLauncherCommChannel comm_channel(comm_file);
   if (llvm::Error err = comm_channel.NotifyPid()) {
 llvm::errs() << llvm::toString(std::move(err)) << "\n";
@@ -3238,13 +3256,23 @@
 
   if (llvm::opt::Arg *target_arg = input_args.getLastArg(OPT_launch_target)) {
 if (llvm::opt::Arg *comm_file = input_args.getLastArg(OPT_comm_file)) {
+  lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  llvm::opt::Arg *debugger_pid = input_args.getLastArg(OPT_debugger_pid);
+  if (debugger_pid) {
+llvm::StringRef debugger_pid_value = debugger_pid->getValue();
+if (debugger_pid_value.getAsInteger(10, pid)) {
+  llvm::errs() << "'" << debugger_pid_value << "' is not a valid "
+  "PID\n";
+  return EXIT_FAILURE;
+}
+  }
   int target_args_pos = argc;
   for (int i = 0; i < argc; i++)
 if (strcmp(argv[i], "--launch-target") == 0) {
   target_args_pos = i + 1;
   break;
 }
-  LaunchRunInTerminalTarget(*target_arg, comm_file->getValue(),
+  LaunchRunInTerminalTarget(*target_arg, comm_file->getValue(), pid,
 argv + target_args_pos);
 } else {
   llvm::errs() << "\"--launch-target\" requires \"--comm-file\" to be "
Index: lldb/tools/lldb-vscode/Options.td
===
--- lldb/tools/lldb-vscode/Options.td
+++ lldb/tools/lldb-vscode/Options.td
@@ -28,9 +28,14 @@
   MetaVarName<"">,
   HelpText<"Launch a target for the launchInTerminal request. Any argument "
 "provided after this one will be passed to the target. The parameter "
-"--comm-files-prefix must also be specified.">;
+"--comm-file must also be specified.">;
 
 def comm_file: Separate<["--", "-"], "comm-file">,
   MetaVarName<"">,
-  HelpText<"The fifo file used to communicate the with the debug adaptor"
+  HelpText<"The fifo file used to communicate the with the debug adaptor "
 "when using --launch-target.">;
+
+def debugger_pid: Separate<["--", "-"], "debugger-pid">,
+  MetaVarName<"">,
+  HelpText<"The PID of the lldb-vscode instance that sent the launchInTerminal "
+"request when using --launch-target.">;
Index: lldb/tools/lldb-vscode/JSONUtils.h
===
--- lldb/tools/lldb-vscode/JSONUtils.h
+++ lldb/tools/lldb-vscode/JSONUtils.h
@@ -479,13 +479,19 @@
 /// \param[in] comm_file
 /// The fifo file used to communicate the with the target launcher.
 ///
+/// 

[Lldb-commits] [lldb] 53aa22c - [lldb-vscode] Fix two issues with runInTerminal test.

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

Author: Jorge Gorbe Moya
Date: 2023-04-10T18:18:05-07:00
New Revision: 53aa22cd9ac4a779208cf9907354cc6d4211e783

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

LOG: [lldb-vscode] Fix two issues with runInTerminal test.

With ptrace_scope = 1 the kernel only allows tracing descendants of a
process. When using runInTerminal, the target process is not launched
by the debugger, so we need to modify LaunchRunInTerminal to explicitly
allow tracing. This should fix a problem reported in
https://reviews.llvm.org/D84974#3903716

In order to allow only the main lldb-vscode process to attach to the
target, this change introduces a new `--debugger-pid` flag that needs
to be passed with `--launch-target` and `--comm-file`.

Also, remove a special case from the launch method in the
lldbvscode_testcase test harness. The existing test was using
stopOnEntry, so the first stop didn't happen at the expected breakpoint
unless the harness did configurationDone first.

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

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
lldb/tools/lldb-vscode/JSONUtils.cpp
lldb/tools/lldb-vscode/JSONUtils.h
lldb/tools/lldb-vscode/Options.td
lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 




diff  --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
index a91f3b2b8feff..d87c95b152a55 100644
--- 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
+++ 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
@@ -331,10 +331,6 @@ def cleanup():
 if not (response and response['success']):
 self.assertTrue(response['success'],
 'launch failed (%s)' % (response['message']))
-# We need to trigger a request_configurationDone after we've 
successfully
-# attached a runInTerminal process to finish initialization.
-if runInTerminal:
-self.vscode.request_configurationDone()
 return response
 
 

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 0cf590fa25251..ca219616ec3b2 100644
--- a/lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
+++ b/lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
@@ -57,8 +57,7 @@ def test_runInTerminal(self):
 program = self.getBuildArtifact("a.out")
 source = 'main.c'
 self.build_and_launch(
-program, stopOnEntry=True, runInTerminal=True, args=["foobar"],
-env=["FOO=bar"])
+program, runInTerminal=True, args=["foobar"], env=["FOO=bar"])
 
 breakpoint_line = line_number(source, '// breakpoint')
 
@@ -88,7 +87,7 @@ def test_runInTerminalInvalidTarget(self):
 return
 self.build_and_create_debug_adaptor()
 response = self.launch(
-"INVALIDPROGRAM", stopOnEntry=True, runInTerminal=True, 
args=["foobar"], env=["FOO=bar"], expectFailure=True)
+"INVALIDPROGRAM", runInTerminal=True, args=["foobar"], 
env=["FOO=bar"], expectFailure=True)
 self.assertFalse(response['success'])
 self.assertIn("Could not create a target for a program 
'INVALIDPROGRAM': unable to find executable",
 response['message'])

diff  --git a/lldb/tools/lldb-vscode/JSONUtils.cpp 
b/lldb/tools/lldb-vscode/JSONUtils.cpp
index 8ec38a4957773..67455abb9916b 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ b/lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -1102,7 +1102,8 @@ llvm::json::Value CreateCompileUnit(lldb::SBCompileUnit 
unit) {
 llvm::json::Object
 CreateRunInTerminalReverseRequest(const llvm::json::Object _request,
   llvm::StringRef debug_adaptor_path,
-  llvm::StringRef comm_file) {
+  llvm::StringRef comm_file,
+  lldb::pid_t debugger_pid) {
   llvm::json::Object reverse_request;
   reverse_request.try_emplace("type", "request");
   reverse_request.try_emplace("command", "runInTerminal");
@@ -1115,8 +1116,13 @@ CreateRunInTerminalReverseRequest(const 
llvm::json::Object _request,
   auto launch_request_arguments = launch_request.getObject("arguments");
   // The program path must be the first entry in the "args" field
   std::vector args = {
-  debug_adaptor_path.str(), "--comm-file", comm_file.str(),
-  "--launch-target", 

[Lldb-commits] [PATCH] D147805: [lldb-vscode] Fix two issues with runInTerminal test.

2023-04-10 Thread Jordan Rupprecht via Phabricator via lldb-commits
rupprecht accepted this revision.
rupprecht added a comment.
This revision is now accepted and ready to land.

Thanks!


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

https://reviews.llvm.org/D147805

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


[Lldb-commits] [PATCH] D147805: [lldb-vscode] Fix two issues with runInTerminal test.

2023-04-10 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
jgorbe added inline comments.



Comment at: lldb/tools/lldb-vscode/JSONUtils.cpp:1120
   debug_adaptor_path.str(), "--comm-file", comm_file.str(),
+  "--debugger-pid", std::to_string(debugger_pid),
   "--launch-target", GetString(launch_request_arguments, "program").str()};

rupprecht wrote:
> Only pass this if != 0
> 
> (or get fancy and use a std::optional or whatever)
Done. Given that I've changed the `debugger_pid` argument to an `lldb::pid_t` 
I'm using `LLDB_INVALID_PROCESS_ID` as a sentinel value.



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:3163
+#if defined(__linux__)
+  (void)prctl(PR_SET_PTRACER, debugger_pid, 0, 0, 0);
+#endif

rupprecht wrote:
> Only invoke this if debugger_pid != 0
Done.



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:3261
+  char *remainder;
+  unsigned long pid = strtoul(debugger_pid->getValue(), , 0);
+  if (remainder == debugger_pid->getValue() || *remainder != '\0') {

rupprecht wrote:
> `StringRef` is usually used for parsing strings as numbers, something like:
> 
> ```
> unsigned long pid = 0;
>   llvm::StringRef debugger_pid_value = debugger_pid->getValue())
>   if (debugger_pid_value.getAsInteger(10, pid)) {
> llvm::errs() << ...
>   }
> }
> ```
Thanks! Once this patch lands we should consider changing how the `port` flag 
is parsed (just a few lines after this block) to match this style.


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

https://reviews.llvm.org/D147805

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


[Lldb-commits] [PATCH] D147805: [lldb-vscode] Fix two issues with runInTerminal test.

2023-04-10 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
jgorbe updated this revision to Diff 512272.
jgorbe marked 3 inline comments as done.
jgorbe added a comment.

Addressed review comments.

- Use `lldb::pid_t` instead of unsigned long, and `LLDB_INVALID_PROCESS_ID` 
instead of `0` in the cases where the PID is missing.
- Only pass the `--debugger-pid` flag if we're on Linux and we have a debugger 
PID. I don't think we need to be particularly lenient with flag parsing, 
because IIUC the command lines for the launcher should only ever be built by 
lldb-vscode itself and not by hand, but it can be confusing for users in other 
platforms to see `--debugger-pid 0` in the command line on the terminal.
- Changed parsing of the `--debugger-pid` numeric value to use 
`llvm::StringRef`.


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

https://reviews.llvm.org/D147805

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
  lldb/test/API/tools/lldb-vscode/runInTerminal/TestVSCode_runInTerminal.py
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/JSONUtils.h
  lldb/tools/lldb-vscode/Options.td
  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
@@ -32,6 +32,10 @@
 #include 
 #endif
 
+#if defined(__linux__)
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -1562,8 +1566,12 @@
 
   RunInTerminalDebugAdapterCommChannel comm_channel(comm_file.m_path);
 
+  lldb::pid_t debugger_pid = LLDB_INVALID_PROCESS_ID;
+#if !defined(_WIN32)
+  debugger_pid = getpid();
+#endif
   llvm::json::Object reverse_request = CreateRunInTerminalReverseRequest(
-  launch_request, g_vsc.debug_adaptor_path, comm_file.m_path);
+  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);
@@ -3141,11 +3149,21 @@
 // In case of errors launching the target, a suitable error message will be
 // emitted to the debug adaptor.
 void LaunchRunInTerminalTarget(llvm::opt::Arg _arg,
-   llvm::StringRef comm_file, char *argv[]) {
+   llvm::StringRef comm_file,
+   lldb::pid_t debugger_pid, char *argv[]) {
 #if defined(_WIN32)
   llvm::errs() << "runInTerminal is only supported on POSIX systems\n";
   exit(EXIT_FAILURE);
 #else
+
+  // On Linux with the Yama security module enabled, a process can only attach
+  // to its descendants by default. In the runInTerminal case the target
+  // process is launched by the client so we need to allow tracing explicitly.
+#if defined(__linux__)
+  if (debugger_pid != LLDB_INVALID_PROCESS_ID)
+(void)prctl(PR_SET_PTRACER, debugger_pid, 0, 0, 0);
+#endif
+
   RunInTerminalLauncherCommChannel comm_channel(comm_file);
   if (llvm::Error err = comm_channel.NotifyPid()) {
 llvm::errs() << llvm::toString(std::move(err)) << "\n";
@@ -3238,13 +3256,23 @@
 
   if (llvm::opt::Arg *target_arg = input_args.getLastArg(OPT_launch_target)) {
 if (llvm::opt::Arg *comm_file = input_args.getLastArg(OPT_comm_file)) {
+  lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  llvm::opt::Arg *debugger_pid = input_args.getLastArg(OPT_debugger_pid);
+  if (debugger_pid) {
+llvm::StringRef debugger_pid_value = debugger_pid->getValue();
+if (debugger_pid_value.getAsInteger(10, pid)) {
+  llvm::errs() << "'" << debugger_pid_value << "' is not a valid "
+  "PID\n";
+  return EXIT_FAILURE;
+}
+  }
   int target_args_pos = argc;
   for (int i = 0; i < argc; i++)
 if (strcmp(argv[i], "--launch-target") == 0) {
   target_args_pos = i + 1;
   break;
 }
-  LaunchRunInTerminalTarget(*target_arg, comm_file->getValue(),
+  LaunchRunInTerminalTarget(*target_arg, comm_file->getValue(), pid,
 argv + target_args_pos);
 } else {
   llvm::errs() << "\"--launch-target\" requires \"--comm-file\" to be "
Index: lldb/tools/lldb-vscode/Options.td
===
--- lldb/tools/lldb-vscode/Options.td
+++ lldb/tools/lldb-vscode/Options.td
@@ -28,9 +28,14 @@
   MetaVarName<"">,
   HelpText<"Launch a target for the launchInTerminal request. Any argument "
 "provided after this one will be passed to the target. The parameter "
-"--comm-files-prefix must also be specified.">;
+"--comm-file must also be specified.">;
 
 def comm_file: Separate<["--", "-"], "comm-file">,
   MetaVarName<"">,
-  HelpText<"The fifo file used to communicate the with the debug adaptor"
+  HelpText<"The fifo file used to communicate the with the debug adaptor "
 "when using --launch-target.">;
+
+def 

[Lldb-commits] [PATCH] D147292: [lldb] Add support for the DW_AT_trampoline attribute with a boolean

2023-04-10 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: lldb/include/lldb/Symbol/Function.h:439
   /// The section offset based address for this function.
+  /// \param[in] generic_trampoline
+  /// If this function is a generic trampoline. A generic trampoline 

Is the "generic" qualifier necessary here? If we later add support for 
trampolines with a jump target maybe, but without that this seems to just 
create opportunity for confusion, particularly for Swift where the word 
"generic" has very different connotations.



Comment at: lldb/source/Target/ThreadPlanStepThroughGenericTrampoline.cpp:2
+//===-- ThreadPlanStepThroughGenericTrampoline.cpp
+//-===//
+//

formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147292

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


[Lldb-commits] [PATCH] D147820: debugserver: move AArch64 watchpoint traps within a watchpointed region, parse ESR flags and send them to lldb

2023-04-10 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added inline comments.



Comment at: lldb/tools/debugserver/source/MacOSX/MachException.cpp:162-169
+  if (exc_type == EXC_BREAKPOINT && exc_data[0] == EXC_ARM_DA_DEBUG &&
+  exc_data.size() > 1) {
+stop_info->reason = eStopTypeWatchpoint;
+stop_info->details.watchpoint.mach_exception_addr = exc_data[1];
+stop_info->details.watchpoint.addr = INVALID_NUB_ADDRESS;
+if (exc_data.size() >= 3) {
+  stop_info->details.watchpoint.hw_idx = exc_data[2];

jasonmolenda wrote:
> JDevlieghere wrote:
> > Interesting that you picked `> 1` on line 163 and `>= 3` on line 168. 
> Yeah I should check for `> 2` in the first conditional expression, because 
> I"m going to access `exc_data[1]`.  The third element (`exc_data[2]`) with 
> the watchpoint number is optional and may not be provided in the mach 
> exception.
(urk I meant to write `>= 2`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147820

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


[Lldb-commits] [PATCH] D147820: debugserver: move AArch64 watchpoint traps within a watchpointed region, parse ESR flags and send them to lldb

2023-04-10 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

Thanks for the review.  Will update the patch.




Comment at: lldb/tools/debugserver/source/MacOSX/MachException.cpp:162-169
+  if (exc_type == EXC_BREAKPOINT && exc_data[0] == EXC_ARM_DA_DEBUG &&
+  exc_data.size() > 1) {
+stop_info->reason = eStopTypeWatchpoint;
+stop_info->details.watchpoint.mach_exception_addr = exc_data[1];
+stop_info->details.watchpoint.addr = INVALID_NUB_ADDRESS;
+if (exc_data.size() >= 3) {
+  stop_info->details.watchpoint.hw_idx = exc_data[2];

JDevlieghere wrote:
> Interesting that you picked `> 1` on line 163 and `>= 3` on line 168. 
Yeah I should check for `> 2` in the first conditional expression, because I"m 
going to access `exc_data[1]`.  The third element (`exc_data[2]`) with the 
watchpoint number is optional and may not be provided in the mach exception.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147820

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


[Lldb-commits] [PATCH] D147820: debugserver: move AArch64 watchpoint traps within a watchpointed region, parse ESR flags and send them to lldb

2023-04-10 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.

I didn't double check the spec so I'm assuming those bitfield indexes are 
correct. Everything else makes sense to me. LGTM.




Comment at: lldb/tools/debugserver/source/DNBBreakpoint.cpp:114-125
+  if (addr < start_addr) {
+uint32_t delta = start_addr - addr;
+if (delta < best_match) {
+  closest = 
+  best_match = delta;
+} else {
+  uint32_t delta = addr - end_addr;

You could simplify this with the ternary operator: 

```
uint32_t delta = addr < start_addr ? start_addr - addr : addr - end_addr;
if (delta < best_match) {
  closest = 
  best_match = delta;
}
```



Comment at: lldb/tools/debugserver/source/DNBDefs.h:284-297
+  bool esr_fields_set;
+  struct {
+uint32_t
+iss; // "ISS encoding for an exception from a Watchpoint exception"
+uint32_t wpt;  // Watchpoint number
+bool wptv; // Watchpoint number Valid
+bool wpf;  // Watchpoint might be false-positive

Instead of a boolean and a field, you could make it a 
`std::optional`. 



Comment at: lldb/tools/debugserver/source/MacOSX/MachException.cpp:162-169
+  if (exc_type == EXC_BREAKPOINT && exc_data[0] == EXC_ARM_DA_DEBUG &&
+  exc_data.size() > 1) {
+stop_info->reason = eStopTypeWatchpoint;
+stop_info->details.watchpoint.mach_exception_addr = exc_data[1];
+stop_info->details.watchpoint.addr = INVALID_NUB_ADDRESS;
+if (exc_data.size() >= 3) {
+  stop_info->details.watchpoint.hw_idx = exc_data[2];

Interesting that you picked `> 1` on line 163 and `>= 3` on line 168. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147820

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


[Lldb-commits] [PATCH] D147841: [lldb][NFC] Update syntax description for language cplusplus demangle

2023-04-10 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG469bdbd62ce2: [lldb][NFC] Update syntax description for 
language cplusplus demangle (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147841

Files:
  
lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
  lldb/test/Shell/Commands/command-language-cplusplus-demangle.test


Index: lldb/test/Shell/Commands/command-language-cplusplus-demangle.test
===
--- /dev/null
+++ lldb/test/Shell/Commands/command-language-cplusplus-demangle.test
@@ -0,0 +1,22 @@
+# RUN: %lldb -b -o "language cplusplus demangle __ZN3Foo7DoThingEv" \
+# RUN:   | FileCheck --check-prefix=DOUBLE-UNDERSCORE %s
+# RUN: %lldb -b -o "language cplusplus demangle _ZN3Foo7DoThingEv" \
+# RUN:   | FileCheck --check-prefix=SINGLE-UNDERSCORE %s
+# RUN: not %lldb -b -o "language cplusplus demangle foo" 2>&1 \
+# RUN:   | FileCheck --check-prefix=NOT-MANGLED %s
+# RUN: not %lldb -b -o "language cplusplus demangle _ZN3Foo7DoThingEv foo" 
2>&1 \
+# RUN:   | FileCheck --check-prefix=MULTI-ARG %s
+# RUN: %lldb -b -o "help language cplusplus demangle" \
+# RUN:   | FileCheck --check-prefix=HELP-MESSAGE %s
+
+# DOUBLE-UNDERSCORE: __ZN3Foo7DoThingEv ---> Foo::DoThing()
+
+# SINGLE-UNDERSCORE: _ZN3Foo7DoThingEv ---> Foo::DoThing()
+
+# NOT-MANGLED: error: foo is not a valid C++ mangled name
+
+# MULTI-ARG: _ZN3Foo7DoThingEv ---> Foo::DoThing()
+# MULTI-ARG: error: foo is not a valid C++ mangled name
+
+# HELP-MESSAGE: Demangle a C++ mangled name.
+# HELP-MESSAGE: Syntax: language cplusplus demangle [ ...] 
Index: 
lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
===
--- 
lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
+++ 
lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
@@ -318,9 +318,9 @@
 class CommandObjectMultiwordItaniumABI_Demangle : public CommandObjectParsed {
 public:
   CommandObjectMultiwordItaniumABI_Demangle(CommandInterpreter )
-  : CommandObjectParsed(interpreter, "demangle",
-"Demangle a C++ mangled name.",
-"language cplusplus demangle") {
+  : CommandObjectParsed(
+interpreter, "demangle", "Demangle a C++ mangled name.",
+"language cplusplus demangle [ ...]") {
 CommandArgumentEntry arg;
 CommandArgumentData index_arg;
 


Index: lldb/test/Shell/Commands/command-language-cplusplus-demangle.test
===
--- /dev/null
+++ lldb/test/Shell/Commands/command-language-cplusplus-demangle.test
@@ -0,0 +1,22 @@
+# RUN: %lldb -b -o "language cplusplus demangle __ZN3Foo7DoThingEv" \
+# RUN:   | FileCheck --check-prefix=DOUBLE-UNDERSCORE %s
+# RUN: %lldb -b -o "language cplusplus demangle _ZN3Foo7DoThingEv" \
+# RUN:   | FileCheck --check-prefix=SINGLE-UNDERSCORE %s
+# RUN: not %lldb -b -o "language cplusplus demangle foo" 2>&1 \
+# RUN:   | FileCheck --check-prefix=NOT-MANGLED %s
+# RUN: not %lldb -b -o "language cplusplus demangle _ZN3Foo7DoThingEv foo" 2>&1 \
+# RUN:   | FileCheck --check-prefix=MULTI-ARG %s
+# RUN: %lldb -b -o "help language cplusplus demangle" \
+# RUN:   | FileCheck --check-prefix=HELP-MESSAGE %s
+
+# DOUBLE-UNDERSCORE: __ZN3Foo7DoThingEv ---> Foo::DoThing()
+
+# SINGLE-UNDERSCORE: _ZN3Foo7DoThingEv ---> Foo::DoThing()
+
+# NOT-MANGLED: error: foo is not a valid C++ mangled name
+
+# MULTI-ARG: _ZN3Foo7DoThingEv ---> Foo::DoThing()
+# MULTI-ARG: error: foo is not a valid C++ mangled name
+
+# HELP-MESSAGE: Demangle a C++ mangled name.
+# HELP-MESSAGE: Syntax: language cplusplus demangle [ ...] 
Index: lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
===
--- lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
@@ -318,9 +318,9 @@
 class CommandObjectMultiwordItaniumABI_Demangle : public CommandObjectParsed {
 public:
   CommandObjectMultiwordItaniumABI_Demangle(CommandInterpreter )
-  : CommandObjectParsed(interpreter, "demangle",
-"Demangle a C++ mangled name.",
-"language cplusplus demangle") {
+  : CommandObjectParsed(
+interpreter, "demangle", "Demangle a C++ mangled name.",
+"language cplusplus demangle [ ...]") {
 CommandArgumentEntry arg;
 CommandArgumentData index_arg;
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org

[Lldb-commits] [lldb] 469bdbd - [lldb][NFC] Update syntax description for language cplusplus demangle

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

Author: Alex Langford
Date: 2023-04-10T13:59:44-07:00
New Revision: 469bdbd62ce2d1dcaef15a8209130547eb614ca6

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

LOG: [lldb][NFC] Update syntax description for language cplusplus demangle

Also added some tests because this is completely untested.

rdar://107780577

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

Added: 
lldb/test/Shell/Commands/command-language-cplusplus-demangle.test

Modified: 

lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
 
b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
index 2879aa64fd7c3..711a696ff9b4d 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
@@ -318,9 +318,9 @@ ItaniumABILanguageRuntime::CreateInstance(Process *process,
 class CommandObjectMultiwordItaniumABI_Demangle : public CommandObjectParsed {
 public:
   CommandObjectMultiwordItaniumABI_Demangle(CommandInterpreter )
-  : CommandObjectParsed(interpreter, "demangle",
-"Demangle a C++ mangled name.",
-"language cplusplus demangle") {
+  : CommandObjectParsed(
+interpreter, "demangle", "Demangle a C++ mangled name.",
+"language cplusplus demangle [ ...]") {
 CommandArgumentEntry arg;
 CommandArgumentData index_arg;
 

diff  --git a/lldb/test/Shell/Commands/command-language-cplusplus-demangle.test 
b/lldb/test/Shell/Commands/command-language-cplusplus-demangle.test
new file mode 100644
index 0..105531023814d
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-language-cplusplus-demangle.test
@@ -0,0 +1,22 @@
+# RUN: %lldb -b -o "language cplusplus demangle __ZN3Foo7DoThingEv" \
+# RUN:   | FileCheck --check-prefix=DOUBLE-UNDERSCORE %s
+# RUN: %lldb -b -o "language cplusplus demangle _ZN3Foo7DoThingEv" \
+# RUN:   | FileCheck --check-prefix=SINGLE-UNDERSCORE %s
+# RUN: not %lldb -b -o "language cplusplus demangle foo" 2>&1 \
+# RUN:   | FileCheck --check-prefix=NOT-MANGLED %s
+# RUN: not %lldb -b -o "language cplusplus demangle _ZN3Foo7DoThingEv foo" 
2>&1 \
+# RUN:   | FileCheck --check-prefix=MULTI-ARG %s
+# RUN: %lldb -b -o "help language cplusplus demangle" \
+# RUN:   | FileCheck --check-prefix=HELP-MESSAGE %s
+
+# DOUBLE-UNDERSCORE: __ZN3Foo7DoThingEv ---> Foo::DoThing()
+
+# SINGLE-UNDERSCORE: _ZN3Foo7DoThingEv ---> Foo::DoThing()
+
+# NOT-MANGLED: error: foo is not a valid C++ mangled name
+
+# MULTI-ARG: _ZN3Foo7DoThingEv ---> Foo::DoThing()
+# MULTI-ARG: error: foo is not a valid C++ mangled name
+
+# HELP-MESSAGE: Demangle a C++ mangled name.
+# HELP-MESSAGE: Syntax: language cplusplus demangle [ ...] 



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


[Lldb-commits] [PATCH] D147831: [lldb-vscode] Implement RestartRequest

2023-04-10 Thread Jordan Rupprecht via Phabricator via lldb-commits
rupprecht added inline comments.



Comment at: lldb/tools/lldb-vscode/VSCode.h:146
+  // arguments if we get a RestartRequest.
+  llvm::json::Object last_launch_or_attach_request;
   lldb::tid_t focus_tid;

std::optional? And then we can raise an error if the client 
calls restart and this is std::nullopt.



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:602
 // }
 void request_attach(const llvm::json::Object ) {
   g_vsc.is_attach = true;

Should we also set `last_launch_or_attach_request` here?

If the user runs:
1) Launch
2) Attach
3) Restart

I would expect that should fail because of the reasons restarting an attach 
will fail. But if we don't set `last_launch_or_attach_request`, it will pass, 
because we set it in (1).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147831

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


[Lldb-commits] [PATCH] D147748: [lldb] Implement SymbolFile::GetCompileOptions

2023-04-10 Thread Augusto Noronha via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG19d969e340c9: [lldb] Implement SymbolFile::GetCompileOptions 
(authored by augusto2112).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147748

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

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -153,6 +153,9 @@
   // Statistics overrides.
   lldb_private::ModuleList GetDebugInfoModules() override;
 
+  void GetCompileOptions(
+  std::unordered_map ) override;
+
 protected:
   enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
 
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -1549,3 +1549,12 @@
   }
   return Status();
 }
+
+void SymbolFileDWARFDebugMap::GetCompileOptions(
+std::unordered_map ) {
+
+  ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
+oso_dwarf->GetCompileOptions(args);
+return false;
+  });
+}
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -523,6 +523,9 @@
 
   void InitializeFirstCodeAddress();
 
+  void GetCompileOptions(
+  std::unordered_map ) override;
+
   lldb::ModuleWP m_debug_map_module_wp;
   SymbolFileDWARFDebugMap *m_debug_map_symfile;
 
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -4255,3 +4255,30 @@
   return Status("no variable information is available in debug info for this "
 "compile unit");
 }
+
+void SymbolFileDWARF::GetCompileOptions(
+std::unordered_map ) {
+
+  const uint32_t num_compile_units = GetNumCompileUnits();
+
+  for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
+lldb::CompUnitSP comp_unit = GetCompileUnitAtIndex(cu_idx);
+if (!comp_unit)
+  continue;
+
+DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit.get());
+if (!dwarf_cu)
+  continue;
+
+const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
+if (!die)
+  continue;
+
+const char *flags = die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL);
+
+if (!flags)
+  continue;
+args.insert({comp_unit, Args(flags)});
+  }
+}
+
Index: lldb/include/lldb/Symbol/SymbolFile.h
===
--- lldb/include/lldb/Symbol/SymbolFile.h
+++ lldb/include/lldb/Symbol/SymbolFile.h
@@ -30,6 +30,7 @@
 
 #include 
 #include 
+#include 
 
 #if defined(LLDB_CONFIGURATION_DEBUG)
 #define ASSERT_MODULE_LOCK(expr) (expr->AssertModuleLock())
@@ -435,9 +436,20 @@
 
   virtual lldb::TypeSP CopyType(const lldb::TypeSP _type) = 0;
 
+  /// Returns a map of compilation unit to the compile option arguments
+  /// associated with that compilation unit.
+  std::unordered_map GetCompileOptions() {
+std::unordered_map args;
+GetCompileOptions(args);
+return args;
+  }
+
 protected:
   void AssertModuleLock();
 
+  virtual void GetCompileOptions(
+  std::unordered_map ) {}
+
 private:
   SymbolFile(const SymbolFile &) = delete;
   const SymbolFile =(const SymbolFile &) = delete;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

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

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

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

LOG: [lldb] Implement SymbolFile::GetCompileOptions

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

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

Added: 


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

Removed: 




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

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

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

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

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

[Lldb-commits] [PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-10 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a subscriber: Jake-Egan.
Michael137 added a comment.

Oh looks like @Jake-Egan already did


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[Lldb-commits] [PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-10 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Looks like `gmodules` isn't supported on AIX (based on other tests that use 
`-dwarf-ext-refs`. So I'll just disable the new tests

Thanks for notifying @aaron.ballman , email notifications got lost in the inbox


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[Lldb-commits] [PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-10 Thread Aaron Ballman via Phabricator via lldb-commits
aaron.ballman added a comment.

The changes in this patch seem to have caused 
https://lab.llvm.org/buildbot/#/builders/clang-ppc64-aix to go down for the 
past 4 days -- can you revert and investigate?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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