[Lldb-commits] [PATCH] D114668: [lldb] Move generic DWARFASTParser code out of Clang-specific code

2021-11-27 Thread Luís Ferreira via Phabricator via lldb-commits
ljmf00 created this revision.
ljmf00 added a project: LLDB.
Herald added subscribers: JDevlieghere, mgorny.
Herald added a reviewer: shafik.
ljmf00 requested review of this revision.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114668

Files:
  lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3074,99 +3074,6 @@
   return arg_idx;
 }
 
-llvm::Optional
-DWARFASTParser::ParseChildArrayInfo(const DWARFDIE &parent_die,
-const ExecutionContext *exe_ctx) {
-  SymbolFile::ArrayInfo array_info;
-  if (!parent_die)
-return llvm::None;
-
-  for (DWARFDIE die : parent_die.children()) {
-const dw_tag_t tag = die.Tag();
-if (tag != DW_TAG_subrange_type)
-  continue;
-
-DWARFAttributes attributes;
-const size_t num_child_attributes = die.GetAttributes(attributes);
-if (num_child_attributes > 0) {
-  uint64_t num_elements = 0;
-  uint64_t lower_bound = 0;
-  uint64_t upper_bound = 0;
-  bool upper_bound_valid = false;
-  uint32_t i;
-  for (i = 0; i < num_child_attributes; ++i) {
-const dw_attr_t attr = attributes.AttributeAtIndex(i);
-DWARFFormValue form_value;
-if (attributes.ExtractFormValueAtIndex(i, form_value)) {
-  switch (attr) {
-  case DW_AT_name:
-break;
-
-  case DW_AT_count:
-if (DWARFDIE var_die = die.GetReferencedDIE(DW_AT_count)) {
-  if (var_die.Tag() == DW_TAG_variable)
-if (exe_ctx) {
-  if (auto frame = exe_ctx->GetFrameSP()) {
-Status error;
-lldb::VariableSP var_sp;
-auto valobj_sp = frame->GetValueForVariableExpressionPath(
-var_die.GetName(), eNoDynamicValues, 0, var_sp,
-error);
-if (valobj_sp) {
-  num_elements = valobj_sp->GetValueAsUnsigned(0);
-  break;
-}
-  }
-}
-} else
-  num_elements = form_value.Unsigned();
-break;
-
-  case DW_AT_bit_stride:
-array_info.bit_stride = form_value.Unsigned();
-break;
-
-  case DW_AT_byte_stride:
-array_info.byte_stride = form_value.Unsigned();
-break;
-
-  case DW_AT_lower_bound:
-lower_bound = form_value.Unsigned();
-break;
-
-  case DW_AT_upper_bound:
-upper_bound_valid = true;
-upper_bound = form_value.Unsigned();
-break;
-
-  default:
-  case DW_AT_abstract_origin:
-  case DW_AT_accessibility:
-  case DW_AT_allocated:
-  case DW_AT_associated:
-  case DW_AT_data_location:
-  case DW_AT_declaration:
-  case DW_AT_description:
-  case DW_AT_sibling:
-  case DW_AT_threads_scaled:
-  case DW_AT_type:
-  case DW_AT_visibility:
-break;
-  }
-}
-  }
-
-  if (num_elements == 0) {
-if (upper_bound_valid && upper_bound >= lower_bound)
-  num_elements = upper_bound - lower_bound + 1;
-  }
-
-  array_info.element_orders.push_back(num_elements);
-}
-  }
-  return array_info;
-}
-
 Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) {
   if (die) {
 SymbolFileDWARF *dwarf = die.GetDWARF();
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
===
--- /dev/null
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp
@@ -0,0 +1,102 @@
+#include "DWARFASTParser.h"
+#include "DWARFAttribute.h"
+#include "DWARFDIE.h"
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/SymbolFile.h"
+#include "lldb/Target/StackFrame.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+llvm::Optional
+DWARFASTParser::ParseChildArrayInfo(const DWARFDIE &parent_die,
+const ExecutionContext *exe_ctx) {
+  SymbolFile::ArrayInfo array_info;
+  if (!parent_die)
+return llvm::None;
+
+  for (DWARFDIE die : parent_die.children()) {
+const dw_tag_t tag = die.Tag();
+if (tag != DW_TAG_subrange_type)
+  continue;
+
+DWARFAttributes attributes;
+const size_t num_child_attributes = die.GetAttributes(attributes);
+if (num_child_attributes > 0) {
+  uint64_t num_elements = 0;
+  uint64_t lower_bound = 0;
+  uint64_t upper_bound = 0

[Lldb-commits] [PATCH] D94997: [lldb][lldb-vscode] Updated implementation of 'launch' and 'attach' requests to not create auxiliary target in case "launchCommands" and "attachCommands" are provided.

2021-11-27 Thread Serhiy Redko via Phabricator via lldb-commits
serhiy.redko updated this revision to Diff 390182.
serhiy.redko edited the summary of this revision.
serhiy.redko added a comment.

As requested DAP now reports an error in case debug configuration contains 
unused target related keys 
("program", "coreFile" etc)  along with  "launchCommands" or "attachCommands" 
that must create target.


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

https://reviews.llvm.org/D94997

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
  lldb/test/API/tools/lldb-vscode/attach/TestVSCode_attach.py
  lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py
  lldb/tools/lldb-vscode/lldb-vscode.cpp
  lldb/tools/lldb-vscode/package.json

Index: lldb/tools/lldb-vscode/package.json
===
--- lldb/tools/lldb-vscode/package.json
+++ lldb/tools/lldb-vscode/package.json
@@ -215,7 +215,7 @@
 			},
 			"launchCommands": {
 "type": "array",
-"description": "Custom commands that are executed instead of launching a process. A target will be created with the launch arguments prior to executing these commands. The commands may optionally create a new target and must perform a launch. A valid process must exist after these commands complete or the \"launch\" will fail.",
+"description": "Custom commands that are executed instead of launching a process. The commands must create a target and must perform a launch. A valid process must exist after these commands complete or the \"launch\" will fail. The following settings will be ignored if provided: \"program\", \"cwd\", \"args\", \"env\", \"disableASLR\", \"disableSTDIO\", \"shellExpandArguments\", \"detachOnError\", \"runInTerminal\", \"targetTriple\", \"platformName\"",
 "default": []
 			},
 			"stopCommands": {
@@ -276,7 +276,7 @@
 			},
 			"attachCommands": {
 "type": "array",
-"description": "Custom commands that are executed instead of attaching to a process ID or to a process by name. These commands may optionally create a new target and must perform an attach. A valid process must exist after these commands complete or the \"attach\" will fail.",
+"description": "Custom commands that are executed instead of attaching to a process ID or to a process by name. These commands must create a target and must perform an attach. A valid process must exist after these commands complete or the \"attach\" will fail. The following settings will be ignored if provided: \"program\", \"pid\", \"waitFor\", \"coreFile\", \"targetTriple\", \"platformName\"",
 "default": []
 			},
 			"initCommands": {
Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -618,28 +618,67 @@
 
   SetSourceMapFromArguments(*arguments);
 
-  lldb::SBError status;
-  g_vsc.SetTarget(g_vsc.CreateTargetFromArguments(*arguments, status));
-  if (status.Fail()) {
-response["success"] = llvm::json::Value(false);
-EmplaceSafeString(response, "message", status.GetCString());
-g_vsc.SendJSON(llvm::json::Value(std::move(response)));
-return;
-  }
+  if (!attachCommands.empty()) {
+// We have "attachCommands" that are a set of commands that are expected
+// to execute the commands after which a process should be created. If there
+// is no valid process after running these commands, we have failed.
 
-  // Run any pre run LLDB commands the user specified in the launch.json
-  g_vsc.RunPreRunCommands();
+std::vector incompatible_fields;
+for (llvm::StringRef arg : {"program", "pid", "waitFor", "coreFile",
+"targetTriple", "platformName"}) {
+  if (arguments->get(arg) != nullptr) {
+incompatible_fields.push_back(arg);
+  }
+}
 
-  if (pid == LLDB_INVALID_PROCESS_ID && wait_for) {
-char attach_msg[256];
-auto attach_msg_len = snprintf(attach_msg, sizeof(attach_msg),
-   "Waiting to attach to \"%s\"...",
-   g_vsc.target.GetExecutable().GetFilename());
-g_vsc.SendOutput(OutputType::Console,
- llvm::StringRef(attach_msg, attach_msg_len));
+if (!incompatible_fields.empty()) {
+  std::string str;
+  llvm::raw_string_ostream strm(str);
+  strm << "Incorrect debug configuration: " <<
+"'attachCommands' is not compatible with ";
+  for (llvm::StringRef field : incompatible_fields) {
+strm << " '" << field << "' ";
+  }
+  response["success"] = llvm::json::Value(false);
+  EmplaceSafeString(response, "message", strm.str());
+  g_vsc.SendJSON(llvm::json::Value(std::move(response)));
+  return;
+}
+
+// Run any pre run LLDB command