[Lldb-commits] [PATCH] D95602: [lldb][AArch64] Add MTE memory tag reading for lldb

2021-02-12 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
omjavaid added a comment.

For anyone reviewing this:

Orignal RFC with all the required documentation insight into Arm Memory Tagging 
Extension can be found here:

https://lists.llvm.org/pipermail/lldb-dev/2020-August/016402.html

@DavidSpickett this calls for some documentation update in a future patch to 
have some MTE/Tags read/write commands related information to go into 
lldb.llvm.org as well may be here https://lldb.llvm.org/use/map.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95602

___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96556: [lldb] Let TestPExpectTest test the right test class

2021-02-12 Thread Raphael Isemann via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0c118831a37a: [lldb] Let TestPExpectTest test the right test 
class (authored by teemperor).
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96556

Files:
  lldb/packages/Python/lldbsuite/test/lldbpexpect.py
  lldb/test/API/test_utils/TestPExpectTest.py


Index: lldb/test/API/test_utils/TestPExpectTest.py
===
--- lldb/test/API/test_utils/TestPExpectTest.py
+++ lldb/test/API/test_utils/TestPExpectTest.py
@@ -2,14 +2,9 @@
 Test the PExpectTest test functions.
 """
 
+from lldbsuite.test.lldbpexpect import *
 
-import lldb
-import lldbsuite.test.lldbutil as lldbutil
-from lldbsuite.test.lldbtest import *
-from textwrap import dedent
-
-
-class TestPExpectTestCase(TestBase):
+class TestPExpectTestCase(PExpectTest):
 
 mydir = TestBase.compute_mydir(__file__)
 NO_DEBUG_INFO_TESTCASE = True
Index: lldb/packages/Python/lldbsuite/test/lldbpexpect.py
===
--- lldb/packages/Python/lldbsuite/test/lldbpexpect.py
+++ lldb/packages/Python/lldbsuite/test/lldbpexpect.py
@@ -53,11 +53,12 @@
 
 def expect(self, cmd, substrs=None):
 self.assertNotIn('\n', cmd)
-self.child.sendline(cmd)
 # If 'substrs' is a string then this code would just check that every
 # character of the string is in the output.
 assert not isinstance(substrs, six.string_types), \
 "substrs must be a collection of strings"
+
+self.child.sendline(cmd)
 if substrs is not None:
 for s in substrs:
 self.child.expect_exact(s)


Index: lldb/test/API/test_utils/TestPExpectTest.py
===
--- lldb/test/API/test_utils/TestPExpectTest.py
+++ lldb/test/API/test_utils/TestPExpectTest.py
@@ -2,14 +2,9 @@
 Test the PExpectTest test functions.
 """
 
+from lldbsuite.test.lldbpexpect import *
 
-import lldb
-import lldbsuite.test.lldbutil as lldbutil
-from lldbsuite.test.lldbtest import *
-from textwrap import dedent
-
-
-class TestPExpectTestCase(TestBase):
+class TestPExpectTestCase(PExpectTest):
 
 mydir = TestBase.compute_mydir(__file__)
 NO_DEBUG_INFO_TESTCASE = True
Index: lldb/packages/Python/lldbsuite/test/lldbpexpect.py
===
--- lldb/packages/Python/lldbsuite/test/lldbpexpect.py
+++ lldb/packages/Python/lldbsuite/test/lldbpexpect.py
@@ -53,11 +53,12 @@
 
 def expect(self, cmd, substrs=None):
 self.assertNotIn('\n', cmd)
-self.child.sendline(cmd)
 # If 'substrs' is a string then this code would just check that every
 # character of the string is in the output.
 assert not isinstance(substrs, six.string_types), \
 "substrs must be a collection of strings"
+
+self.child.sendline(cmd)
 if substrs is not None:
 for s in substrs:
 self.child.expect_exact(s)
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 0c11883 - [lldb] Let TestPExpectTest test the right test class

2021-02-12 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2021-02-12T09:56:43+01:00
New Revision: 0c118831a37a058f5ff196a4be3c4d5b1cf25e63

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

LOG: [lldb] Let TestPExpectTest test the right test class

This test supposed to check the test base we are using for pexpect tests, but 
instead it used the normal TestBase
class we use for all other tests. TestBase already had the substrs type check 
since D88792 so this
test was passing because of that.

This just changes the test base of the test to the pexpect one so that the 
`expect` calls find their intended
target function. Also moves the check to the very start so that we can check 
the argument without
actually having to start a terminal and all that jazz.

(I found this by accident as D88792 got somehow reverted in a downstream branch 
so this test started
failing).

Reviewed By: JDevlieghere

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

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/lldbpexpect.py
lldb/test/API/test_utils/TestPExpectTest.py

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py 
b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
index 1a6c32094ba8..388e91892888 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
@@ -53,11 +53,12 @@ def launch(self, executable=None, extra_args=None, 
timeout=30, dimensions=None):
 
 def expect(self, cmd, substrs=None):
 self.assertNotIn('\n', cmd)
-self.child.sendline(cmd)
 # If 'substrs' is a string then this code would just check that every
 # character of the string is in the output.
 assert not isinstance(substrs, six.string_types), \
 "substrs must be a collection of strings"
+
+self.child.sendline(cmd)
 if substrs is not None:
 for s in substrs:
 self.child.expect_exact(s)

diff  --git a/lldb/test/API/test_utils/TestPExpectTest.py 
b/lldb/test/API/test_utils/TestPExpectTest.py
index c754f1faa7ec..6e96b1d0108d 100644
--- a/lldb/test/API/test_utils/TestPExpectTest.py
+++ b/lldb/test/API/test_utils/TestPExpectTest.py
@@ -2,14 +2,9 @@
 Test the PExpectTest test functions.
 """
 
+from lldbsuite.test.lldbpexpect import *
 
-import lldb
-import lldbsuite.test.lldbutil as lldbutil
-from lldbsuite.test.lldbtest import *
-from textwrap import dedent
-
-
-class TestPExpectTestCase(TestBase):
+class TestPExpectTestCase(PExpectTest):
 
 mydir = TestBase.compute_mydir(__file__)
 NO_DEBUG_INFO_TESTCASE = True



___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D95683: [lldb] Fix fallout caused by D89156 on 11.0.1 for MacOS

2021-02-12 Thread Andi via Phabricator via lldb-commits
Abpostelnicu abandoned this revision.
Abpostelnicu added a comment.

This has landed and trunk is already fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95683

___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96550: Fix LLDB_LOG calls to use correct formatting

2021-02-12 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor accepted this revision.
teemperor added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


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

https://reviews.llvm.org/D96550

___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D95711: [lldb/Interpreter] Add ScriptInterpreter Wrapper for ScriptedProcess

2021-02-12 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision as: JDevlieghere.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

A few small nits, but overall this LGTM.




Comment at: lldb/include/lldb/API/SBData.h:16
+class ScriptInterpreter;
+}
+

The linter is right. Did you clang-format your patch? It should add it 
automatically. 



Comment at: lldb/source/Interpreter/ScriptInterpreter.cpp:31
+Debugger &debugger, lldb::ScriptLanguage script_lang,
+lldb::ScriptedProcessInterfaceSP scripted_process_interface_sp)
+: m_debugger(debugger), m_script_lang(script_lang),

If you gave the scripted_process_interface_sp a default value 
(`scripted_process_interface_sp = {}`), you could skip the overload, unless 
that prevents you from forward declaring the interface in the header?



Comment at: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp:94
+
+  // right now we know this function exists and is callable..
+  PythonObject py_return(

I know you copied this code but let's turn this and the other comments in this 
file into full sentences. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95711

___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96550: Fix LLDB_LOG calls to use correct formatting

2021-02-12 Thread Shafik Yaghmour via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9f175998debc: [LLDB] Fix LLDB_LOG calls to use correct 
formatting (authored by shafik).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96550

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -350,7 +350,7 @@
   if (!var)
 return false;
 
-  LLDB_LOG(log, "Adding value for (NamedDecl*)%p [%s - %s] to the structure",
+  LLDB_LOG(log, "Adding value for (NamedDecl*){0} [{1} - {2}] to the 
structure",
decl, name, var->GetName());
 
   // We know entity->m_parser_vars is valid because we used a parser variable
@@ -752,7 +752,7 @@
 MaybeRegisterFunctionBody(parser_function_decl);
   }
 
-  LLDB_LOG(log, "  CEDM::FEVD Found persistent decl %s", name);
+  LLDB_LOG(log, "  CEDM::FEVD Found persistent decl {0}", name);
 
   context.AddNamedDecl(parser_named_decl);
 }
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -1570,10 +1570,10 @@
 
   if (log) {
 LLDB_LOG(log, "LRT returned:");
-LLDB_LOG(log, "LRT   Original = (RecordDecl*)%p",
+LLDB_LOG(log, "LRT   Original = (RecordDecl*){0}",
  static_cast(origin_record.decl));
-LLDB_LOG(log, "LRT   Size = %" PRId64, size);
-LLDB_LOG(log, "LRT   Alignment = %" PRId64, alignment);
+LLDB_LOG(log, "LRT   Size = {0}", size);
+LLDB_LOG(log, "LRT   Alignment = {0}", alignment);
 LLDB_LOG(log, "LRT   Fields:");
 for (RecordDecl::field_iterator fi = record->field_begin(),
 fe = record->field_end();


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -350,7 +350,7 @@
   if (!var)
 return false;
 
-  LLDB_LOG(log, "Adding value for (NamedDecl*)%p [%s - %s] to the structure",
+  LLDB_LOG(log, "Adding value for (NamedDecl*){0} [{1} - {2}] to the structure",
decl, name, var->GetName());
 
   // We know entity->m_parser_vars is valid because we used a parser variable
@@ -752,7 +752,7 @@
 MaybeRegisterFunctionBody(parser_function_decl);
   }
 
-  LLDB_LOG(log, "  CEDM::FEVD Found persistent decl %s", name);
+  LLDB_LOG(log, "  CEDM::FEVD Found persistent decl {0}", name);
 
   context.AddNamedDecl(parser_named_decl);
 }
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -1570,10 +1570,10 @@
 
   if (log) {
 LLDB_LOG(log, "LRT returned:");
-LLDB_LOG(log, "LRT   Original = (RecordDecl*)%p",
+LLDB_LOG(log, "LRT   Original = (RecordDecl*){0}",
  static_cast(origin_record.decl));
-LLDB_LOG(log, "LRT   Size = %" PRId64, size);
-LLDB_LOG(log, "LRT   Alignment = %" PRId64, alignment);
+LLDB_LOG(log, "LRT   Size = {0}", size);
+LLDB_LOG(log, "LRT   Alignment = {0}", alignment);
 LLDB_LOG(log, "LRT   Fields:");
 for (RecordDecl::field_iterator fi = record->field_begin(),
 fe = record->field_end();
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 9f17599 - [LLDB] Fix LLDB_LOG calls to use correct formatting

2021-02-12 Thread Shafik Yaghmour via lldb-commits

Author: Shafik Yaghmour
Date: 2021-02-12T11:09:39-08:00
New Revision: 9f175998debcbb14e95d7e94ca5fee26f4acc63b

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

LOG: [LLDB] Fix LLDB_LOG calls to use correct formatting

It looks like a previous change switched these from LLDB_LOGF but did not 
update the format strings.

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

Added: 


Modified: 
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

Removed: 




diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 0f34c48c7e82..19031af400ea 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -1570,10 +1570,10 @@ bool ClangASTSource::layoutRecordType(const RecordDecl 
*record, uint64_t &size,
 
   if (log) {
 LLDB_LOG(log, "LRT returned:");
-LLDB_LOG(log, "LRT   Original = (RecordDecl*)%p",
+LLDB_LOG(log, "LRT   Original = (RecordDecl*){0}",
  static_cast(origin_record.decl));
-LLDB_LOG(log, "LRT   Size = %" PRId64, size);
-LLDB_LOG(log, "LRT   Alignment = %" PRId64, alignment);
+LLDB_LOG(log, "LRT   Size = {0}", size);
+LLDB_LOG(log, "LRT   Alignment = {0}", alignment);
 LLDB_LOG(log, "LRT   Fields:");
 for (RecordDecl::field_iterator fi = record->field_begin(),
 fe = record->field_end();

diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 852ce3bbd3db..04d72ce4f021 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -350,7 +350,7 @@ bool ClangExpressionDeclMap::AddValueToStruct(const 
NamedDecl *decl,
   if (!var)
 return false;
 
-  LLDB_LOG(log, "Adding value for (NamedDecl*)%p [%s - %s] to the structure",
+  LLDB_LOG(log, "Adding value for (NamedDecl*){0} [{1} - {2}] to the 
structure",
decl, name, var->GetName());
 
   // We know entity->m_parser_vars is valid because we used a parser variable
@@ -752,7 +752,7 @@ void 
ClangExpressionDeclMap::SearchPersistenDecls(NameSearchContext &context,
 MaybeRegisterFunctionBody(parser_function_decl);
   }
 
-  LLDB_LOG(log, "  CEDM::FEVD Found persistent decl %s", name);
+  LLDB_LOG(log, "  CEDM::FEVD Found persistent decl {0}", name);
 
   context.AddNamedDecl(parser_named_decl);
 }



___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96623: [lldb-vscode] Fix lldb init file stdout issue

2021-02-12 Thread jeffrey tan via Phabricator via lldb-commits
yinghuitan created this revision.
yinghuitan added reviewers: clayborg, aadsm.
yinghuitan requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

VScode DAP client uses stdout to receive protocol message. This means any 
stdout/stderr from debugger would be treated as DAP packet. This means any lldb 
commands in init file can generate random output and break DAP client.
This diff fixes the issue by explicitly sourcing lldbinit file after 
stdout/stderr is redirected to dev_null instead of relying on 
SBDebugger::Create().
There is another issue that SBDebugger::Create() only sources the lldbinit file 
from home directory not debugger's cwd. This diverages from what lldb does. 
This diff explicitly sources init file from cwd as well.
An integration test is added.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96623

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/launch/.lldbinit
  lldb/test/API/tools/lldb-vscode/launch/TestVSCode_launch.py
  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
@@ -1274,6 +1274,93 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
 
+static void GetHomeInitFile(llvm::SmallString<128> &init_file,
+llvm::StringRef suffix = {}) {
+  std::string init_file_name = ".lldbinit";
+  if (!suffix.empty()) {
+init_file_name.append("-");
+init_file_name.append(suffix.str());
+  }
+  if (!llvm::sys::path::home_directory(init_file)) {
+g_vsc.SendOutput(OutputType::Stderr,
+ llvm::StringRef("Failed to get home directory"));
+return;
+  }
+  llvm::sys::path::append(init_file, init_file_name);
+
+  llvm::SmallString<128> init_file_real_path;
+  if (std::error_code error = llvm::sys::fs::real_path(
+  init_file.c_str(), init_file_real_path, /*expand_tilde*/ true)) {
+auto err_msg = std::string("Failed to expand path: ") + error.message();
+g_vsc.SendOutput(OutputType::Stderr, llvm::StringRef(err_msg.c_str()));
+return;
+  }
+  init_file.assign(init_file_real_path);
+}
+
+/**
+ * Find and return the init file in user's home directory in \p init_file.
+ * It searches .lldbinit- first, then fall back to .lldbinit.
+ */
+static void GetInitFilePathHomeDirectory(llvm::SmallString<128> &init_file) {
+  llvm::StringRef program_name =
+  lldb::SBHostOS::GetProgramFileSpec().GetFilename();
+  GetHomeInitFile(init_file, program_name);
+  if (!llvm::sys::fs::exists(init_file.c_str())) {
+init_file.clear();
+GetHomeInitFile(init_file);
+  }
+}
+
+/**
+ * Source the local init file in debugger's current working directory in \p
+ * init_file.
+ */
+static void
+GetInitFilePathCurrentWorkingDirectory(llvm::SmallString<128> &init_file) {
+  if (std::error_code error = llvm::sys::fs::current_path(init_file)) {
+auto err_msg = std::string("Failed to get current working directory: ") +
+   error.message();
+g_vsc.SendOutput(OutputType::Stderr, llvm::StringRef(err_msg.c_str()));
+return;
+  }
+  llvm::sys::path::append(init_file, ".lldbinit");
+
+  llvm::SmallString<128> init_file_real_path;
+  if (std::error_code error = llvm::sys::fs::real_path(
+  init_file.c_str(), init_file_real_path, /*expand_tilde*/ true)) {
+auto err_msg = std::string("Failed to expand path: ") + error.message();
+g_vsc.SendOutput(OutputType::Stderr, llvm::StringRef(err_msg.c_str()));
+return;
+  }
+  init_file.assign(init_file_real_path);
+}
+
+static void SourceCommandFile(const char *command_file) {
+  if (llvm::sys::fs::exists(command_file)) {
+lldb::SBCommandReturnObject result;
+
+std::string source_file_cmd = "command source ";
+source_file_cmd.append(command_file);
+g_vsc.debugger.GetCommandInterpreter().HandleCommand(
+source_file_cmd.c_str(), result, /*add_to_history*/ false);
+  }
+}
+
+/**
+ * Source .lldbinit files in user's home and debugger's cwd directories.
+ * This is similar to what Driver.cpp does.
+ */
+static void SourceInitFile() {
+  llvm::SmallString<128> init_file;
+  GetInitFilePathHomeDirectory(init_file);
+  SourceCommandFile(init_file.c_str());
+
+  init_file.clear();
+  GetInitFilePathCurrentWorkingDirectory(init_file);
+  SourceCommandFile(init_file.c_str());
+}
+
 // "InitializeRequest": {
 //   "allOf": [ { "$ref": "#/definitions/Request" }, {
 // "type": "object",
@@ -1351,7 +1438,11 @@
 //   }]
 // }
 void request_initialize(const llvm::json::Object &request) {
-  g_vsc.debugger = lldb::SBDebugger::Create(true /*source_init_files*/);
+  // Can't source_init_files during SBDebugger::Create because the commands in
+  // the init file

[Lldb-commits] [PATCH] D96537: Make the error condition in Value::ValueType explicit (NFC)

2021-02-12 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl updated this revision to Diff 323467.
aprantl marked 9 inline comments as done.
aprantl added a comment.

Address review feedback!


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

https://reviews.llvm.org/D96537

Files:
  lldb/include/lldb/Core/Value.h
  lldb/include/lldb/Expression/ExpressionVariable.h
  lldb/source/Core/Value.cpp
  lldb/source/Core/ValueObject.cpp
  lldb/source/Core/ValueObjectChild.cpp
  lldb/source/Core/ValueObjectConstResult.cpp
  lldb/source/Core/ValueObjectConstResultImpl.cpp
  lldb/source/Core/ValueObjectMemory.cpp
  lldb/source/Core/ValueObjectRegister.cpp
  lldb/source/Core/ValueObjectVariable.cpp
  lldb/source/DataFormatters/TypeFormat.cpp
  lldb/source/Expression/DWARFExpression.cpp
  lldb/source/Expression/FunctionCaller.cpp
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
  lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
  lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp
  lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
  lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  
lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
  lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
  lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
  lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
  lldb/source/Target/ABI.cpp
  lldb/source/Target/RegisterContextUnwind.cpp
  lldb/source/Target/ThreadPlanTracer.cpp
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -34,9 +34,9 @@
 return status.ToError();
 
   switch (result.GetValueType()) {
-  case Value::eValueTypeScalar:
+  case Value::ValueType::Scalar:
 return result.GetScalar();
-  case Value::eValueTypeHostAddress: {
+  case Value::ValueType::HostAddress: {
 // Convert small buffers to scalars to simplify the tests.
 DataBufferHeap &buf = result.GetBuffer();
 if (buf.GetByteSize() <= 8) {
Index: lldb/source/Target/ThreadPlanTracer.cpp
===
--- lldb/source/Target/ThreadPlanTracer.cpp
+++ lldb/source/Target/ThreadPlanTracer.cpp
@@ -191,7 +191,7 @@
 
 for (int arg_index = 0; arg_index < num_args; ++arg_index) {
   Value value;
-  value.SetValueType(Value::eValueTypeScalar);
+  value.SetValueType(Value::ValueType::Scalar);
   value.SetCompilerType(intptr_type);
   value_list.PushValue(value);
 }
Index: lldb/source/Target/RegisterContextUnwind.cpp
===
--- lldb/source/Target/RegisterContextUnwind.cpp
+++ lldb/source/Target/RegisterContextUnwind.cpp
@@ -1521,7 +1521,7 @@
 DWARFExpression dwarfexpr(opcode_ctx, dwarfdata, nullptr);
 dwarfexpr.SetRegisterKind(unwindplan_registerkind);
 Value cfa_val = Scalar(m_cfa);
-cfa_val.SetValueType(Value::eValueTypeLoadAddress);
+cfa_val.SetValueType(Value::ValueType::LoadAddress);
 Value result;
 Status error;
 if (dwarfexpr.Evaluate(&exe_ctx, this, 0, &cfa_val, nullptr, result,
Index: lldb/source/Target/ABI.cpp
===
--- lldb/source/Target/ABI.cpp
+++ lldb/source/Target/ABI.cpp
@@ -120,11 +120,13 @@
 const Value &result_value = live_valobj_sp->GetValue();
 
 switch (result_value.GetValueType()) {
-case Value::eValueTypeHostAddress:
-case Value::eValueTypeFileAddress:
-  // we don't do anything with these for now
+case Value::ValueType::Invalid:
+  return {};
+case Value::ValueType::HostAddress:
+case Value::ValueType::FileAddress:
+  // we odon't do anything with these for now
   break;
-case Value::eValueTypeScalar:
+case Value::ValueType::Scalar:
   expr_variable_sp->m_flags |=
   ExpressionVariable::EVIsFreezeDried;
   expr_variable_sp->m_flags |=
@@ -132,7 +134,7 @@
   expr_variable_sp->m_flags |=
   ExpressionVariable::EVNeedsAllocation;
   break;
-case Value::eValueTypeLoadAddress:
+case Value::ValueType::LoadAddress:
   expr_variabl

[Lldb-commits] [PATCH] D96634: [lldb][JITLoaderGDB] Test debug support in llvm-jitlink

2021-02-12 Thread Stefan Gränitz via Phabricator via lldb-commits
sgraenitz created this revision.
sgraenitz added reviewers: labath, teemperor, JDevlieghere, lhames.
sgraenitz requested review of this revision.
Herald added a project: LLDB.

LLVM OrcJIT is shifting from RuntimeDyld to JITLink. Starting with D96627 
 I am planning to add debug support. It would 
be great to have test coverage for it in LLDB early on.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96634

Files:
  lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
  lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
  lldb/test/Shell/Breakpoint/jitbp_elf.test


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -5,7 +5,7 @@
 # RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
-o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run -jit-kind=mcjit {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,11 +1,11 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll 
%p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
-o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
+# RUN: %clang -c -g -fPIC --target=x86_64-unknown-unknown-elf -o %t.o 
%p/Inputs/jitbp.cpp
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' 
-o 'run %t.o' llvm-jitlink | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }


Index: lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test
@@ -5,7 +5,7 @@
 # RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' -o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run -jit-kind=mcjit {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }
Index: lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
===
--- lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
+++ lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test
@@ -1,11 +1,11 @@
 # REQUIRES: target-x86_64
 # XFAIL: system-windows
 
-# RUN: %clang -g -S -emit-llvm --target=x86_64-unknown-unknown-elf -o %t.ll %p/Inputs/jitbp.cpp
-# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' -o 'run -jit-kind=mcjit %t.ll' lli | FileCheck %s
+# RUN: %clang -c -g -fPIC --target=x86_64-unknown-unknown-elf -o %t.o %p/Inputs/jitbp.cpp
+# RUN: %lldb -b -o 'settings set plugin.jit-loader.gdb.enable on' -o 'b jitbp' -o 'run %t.o' llvm-jitlink | FileCheck %s
 
 # CHECK: Breakpoint 1: no locations (pending).
-# CHECK: (lldb) run -jit-kind=mcjit {{.*}}/jitbp_elf.test.tmp.ll
+# CHECK: (lldb) run {{.*}}
 # CHECK: Process {{.*}} stopped
 # CHECK: JIT(0x{{.*}})`jitbp() at jitbp.cpp:1:15
 # CHECK: -> 1int jitbp() { return 0; }
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96537: Make the error condition in Value::ValueType explicit (NFC)

2021-02-12 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D96537

___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D95711: [lldb/Interpreter] Add ScriptInterpreter Wrapper for ScriptedProcess

2021-02-12 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 323481.
mib marked 3 inline comments as done.
mib added a comment.

Address @JDevlieghere comments:

- Fix namespace closing comment in `SBData.h`
- Remove `ScriptInterpreter` overload by making the `ScriptedProcessInterface` 
a default argument.
- Replace inline comments with error messages.

Also, since `TestScriptInterpreterPython` inherits from 
`ScriptInterpreterPythonImpl` it needed some symbol definitions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95711

Files:
  lldb/bindings/python/python-wrapper.swig
  lldb/include/lldb/API/SBData.h
  lldb/include/lldb/API/SBThreadPlan.h
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Interpreter/CMakeLists.txt
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Interpreter/ScriptedProcessInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/unittests/ScriptInterpreter/Python/CMakeLists.txt
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Index: lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
===
--- lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -12,6 +12,7 @@
 
 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h"
+#include "lldb/API/SBError.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
 
@@ -153,6 +154,14 @@
   return 0;
 }
 
+extern "C" void *LLDBSWIGPython_CastPyObjectToSBData(void *data) {
+  return nullptr;
+}
+
+extern "C" void *LLDBSWIGPython_CastPyObjectToSBError(void *data) {
+  return nullptr;
+}
+
 extern "C" void *LLDBSWIGPython_CastPyObjectToSBValue(void *data) {
   return nullptr;
 }
@@ -207,6 +216,13 @@
   return nullptr;
 }
 
+extern "C" void *LLDBSwigPythonCreateScriptedProcess(
+const char *python_class_name, const char *session_dictionary_name,
+const lldb::TargetSP &target_sp, StructuredDataImpl *args_impl,
+std::string &error_string) {
+  return nullptr;
+}
+
 extern "C" void *
 LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name,
  const char *session_dictionary_name) {
Index: lldb/unittests/ScriptInterpreter/Python/CMakeLists.txt
===
--- lldb/unittests/ScriptInterpreter/Python/CMakeLists.txt
+++ lldb/unittests/ScriptInterpreter/Python/CMakeLists.txt
@@ -3,6 +3,7 @@
   PythonTestSuite.cpp
 
   LINK_LIBS
+liblldb
 lldbHost
 lldbPluginScriptInterpreterPython
 LLVMTestingSupport
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -0,0 +1,63 @@
+//===-- ScriptedProcessPythonInterface.h *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPROCESSPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPROCESSPYTHONINTERFACE_H
+
+#include "lldb/Host/Config.h"
+
+#if LLDB_ENABLE_PYTHON
+
+#include "lldb/Interpreter/ScriptedProcessInterface.h"
+
+namespace lldb_private {
+class ScriptInterpreterPythonImpl;
+class ScriptedProcessPythonInterface : public ScriptedProcessInterface {
+public:
+  ScriptedProcessPythonInterface(ScriptInterpreterPythonImpl &interpreter)
+  : ScriptedProcessInterface(), m_interpreter(interpreter) {}
+
+  StructuredData::GenericSP
+  CreatePluginObject(const llvm::StringRef class_name, lldb::TargetSP target_sp,
+ StructuredData::DictionarySP args_sp) override;
+
+  Status Launch() override;
+
+  size_t GetNumMemoryRegions() override;
+
+  lldb::MemoryRegionInfoSP GetMemoryRegionAtIndex(size_t index) override;
+
+  size_t GetNumThreads() override;
+
+  l

[Lldb-commits] [PATCH] D96637: Make sure the interpreter module was loaded before making checks against it

2021-02-12 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: mgorny, labath, emaste.
aadsm requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This issue was introduced in https://reviews.llvm.org/D92187.
The guard I'm changing were is supposed to act when linux is loading the linker 
for the second time (due to differences in paths like symlinks).
This is done by checking `module_sp != m_interpreter_module.lock()` however 
this will be true when `m_interpreter_module` wasn't initialized, making linux 
unload the linker module (the most visible result here is that lldb will stop 
getting notified about new modules loaded by the process, because it can't set 
the rendezvous breakpoint again after the stepping over it once).
The `m_interpreter_module` is not getting initialize when it goes through this 
path: 
https://github.com/llvm/llvm-project/blob/dbfdb139f75470a9abc78e7c9faf743fdd963c2d/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp#L332,
 which happens when lldb was able to read the address from the dynamic section 
of the executable.

What I'm not sure about though, is if when we go through this path if we still 
load the linker twice on linux. If that's the case then it means we need to 
somehow set the m_interpreter_module instead of the fix I provide here. I've 
only tested this on Android.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96637

Files:
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp


Index: lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
===
--- lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -441,6 +441,7 @@
   if (module_sp.get()) {
 if (module_sp->GetObjectFile()->GetBaseAddress().GetLoadAddress(
 &m_process->GetTarget()) == m_interpreter_base &&
+m_interpreter_module.lock() &&
 module_sp != m_interpreter_module.lock()) {
   // If this is a duplicate instance of ld.so, unload it.  We may end 
up
   // with it if we load it via a different path than before (symlink


Index: lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
===
--- lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -441,6 +441,7 @@
   if (module_sp.get()) {
 if (module_sp->GetObjectFile()->GetBaseAddress().GetLoadAddress(
 &m_process->GetTarget()) == m_interpreter_base &&
+m_interpreter_module.lock() &&
 module_sp != m_interpreter_module.lock()) {
   // If this is a duplicate instance of ld.so, unload it.  We may end up
   // with it if we load it via a different path than before (symlink
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D95712: [lldb/bindings] Add Python ScriptedProcess base class to lldb module

2021-02-12 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 323484.
mib marked 3 inline comments as done.
mib edited the summary of this revision.
mib added a comment.
Herald added a subscriber: mgorny.

Address @JDevlieghere comments:

- Instead of having the ScriptedProcess python base class in a SWIG file, I 
moved it to a python file in the example folder. There is a post-build event 
that copies it to the python lldb module under to `lldb.plugins` package.
- Added pydoc documentation to the ScriptedProcess base class.
- Removed all the typing hints that prevented the feature to be compatible with 
Python 2. I, however, kept them in the `MyScriptProcess` example.

I also added a first test that checks that the base class exists in the lldb 
python module.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95712

Files:
  lldb/bindings/python/CMakeLists.txt
  lldb/examples/python/scripted_process/my_scripted_process.py
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/test/API/functionalities/scripted_process/Makefile
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/main.c

Index: lldb/test/API/functionalities/scripted_process/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/main.c
@@ -0,0 +1,5 @@
+#include 
+
+int main() {
+  return 0; // break here
+}
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -0,0 +1,45 @@
+"""
+Test python scripted process in lldb
+"""
+
+import os
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbtest
+
+
+class PlatformProcessCrashInfoTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+TestBase.setUp(self)
+self.source = "main.c"
+
+def tearDown(self):
+TestBase.tearDown(self)
+
+@skipUnlessDarwin
+def test_python_plugin_package(self):
+"""Test that the lldb python module has a `plugins.scripted_process`
+package."""
+self.expect('script import lldb.plugins',
+patterns=["^((?!ModuleNotFoundError: No module named \'lldb\.plugins\').)*$"])
+
+self.expect('script dir(lldb.plugins)',
+patterns=["scripted_process"])
+
+self.expect('script import lldb.plugins.scripted_process',
+patterns=["^((?!ModuleNotFoundError: No module named \'lldb\.plugins\.scripted_process\').)*$"])
+
+self.expect('script dir(lldb.plugins.scripted_process)',
+patterns=["ScriptedProcess"])
+
+self.expect('script from lldb.plugins.scripted_process import ScriptedProcess',
+patterns=["^((?!ImportError: cannot import name \'ScriptedProcess\' from \'lldb.plugins\.scripted_process\').)*$"])
+
+self.expect('script dir(ScriptedProcess)',
+patterns=["launch"])
Index: lldb/test/API/functionalities/scripted_process/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+
+include Makefile.rules
+
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- /dev/null
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -0,0 +1,206 @@
+from abc import ABCMeta, abstractmethod
+import six
+
+import lldb
+
[email protected]_metaclass(ABCMeta)
+class ScriptedProcess:
+
+"""
+The base class for a scripted process.
+
+Most of the base class methods are `@abstractmethod` that need to be
+overwritten by the inheriting class.
+
+Attributes:
+args (lldb.SBStructuredData): Dictionary holding arbitrary values
+loaded_images (list): List of the scripted process loaded images.
+memory_regions (list): List of the current memory regions.
+process_id (int): Scripted process identifier.
+stops (list): List of public stops.
+target (lldb.SBTarget): Target launching the scripted process.
+threads (list): List of the scripted process threads.
+
+Methods:
+get_num_memory_regions() -> int:
+Get the number of memory regions for the scripted process.
+
+get_memory_region_at_index(idx: int) -> lldb.SBMemoryRegionInfo:
+Get the memory regions for the scripted process, at index idx.
+
+get_num_threads() -> int:
+Get the number of threads for the scripted process.
+
+get_thread_at_index(idx: int) -> Dict:
+

[Lldb-commits] [PATCH] D96549: Support dereferencing a DWARF scalar stack value

2021-02-12 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl updated this revision to Diff 323488.
aprantl added a comment.
Herald added a subscriber: mgorny.

That took me a little to get right, but here you go! Mock process.


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

https://reviews.llvm.org/D96549

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/unittests/Expression/CMakeLists.txt
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -7,11 +7,15 @@
 //===--===//
 
 #include "lldb/Expression/DWARFExpression.h"
+#include "Plugins/Platform/Linux/PlatformLinux.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Value.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/dwarf.h"
+#include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Testing/Support/Error.h"
@@ -21,16 +25,17 @@
 
 static llvm::Expected Evaluate(llvm::ArrayRef expr,
lldb::ModuleSP module_sp = {},
-   DWARFUnit *unit = nullptr) {
+   DWARFUnit *unit = nullptr,
+   ExecutionContext *exe_ctx = nullptr) {
   DataExtractor extractor(expr.data(), expr.size(), lldb::eByteOrderLittle,
   /*addr_size*/ 4);
   Value result;
   Status status;
-  if (!DWARFExpression::Evaluate(
-  /*exe_ctx*/ nullptr, /*reg_ctx*/ nullptr, module_sp, extractor, unit,
-  lldb::eRegisterKindLLDB,
-  /*initial_value_ptr*/ nullptr,
-  /*object_address_ptr*/ nullptr, result, &status))
+  if (!DWARFExpression::Evaluate(exe_ctx, /*reg_ctx*/ nullptr, module_sp,
+ extractor, unit, lldb::eRegisterKindLLDB,
+ /*initial_value_ptr*/ nullptr,
+ /*object_address_ptr*/ nullptr, result,
+ &status))
 return status.ToError();
 
   switch (result.GetValueType()) {
@@ -66,6 +71,23 @@
   return scalar;
 }
 
+/// This is needed for the tests that use a mock process.
+class DWARFExpressionMockProcessTest : public ::testing::Test {
+public:
+  void SetUp() override {
+llvm::cantFail(repro::Reproducer::Initialize(repro::ReproducerMode::Off, {}));
+FileSystem::Initialize();
+HostInfo::Initialize();
+platform_linux::PlatformLinux::Initialize();
+  }
+  void TearDown() override {
+platform_linux::PlatformLinux::Terminate();
+HostInfo::Terminate();
+FileSystem::Terminate();
+repro::Reproducer::Terminate();
+  }
+};
+
 TEST(DWARFExpression, DW_OP_pick) {
   EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit1, DW_OP_lit0, DW_OP_pick, 0}),
llvm::HasValue(0));
@@ -277,6 +299,59 @@
   "Unhandled opcode DW_OP_unknown_ff in DWARFExpression"));
 }
 
-TEST(DWARFExpression, DW_OP_deref) {
+TEST_F(DWARFExpressionMockProcessTest, DW_OP_deref) {
   EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit0, DW_OP_deref}), llvm::Failed());
+
+  struct MockProcess : Process {
+using Process::Process;
+ConstString GetPluginName() override { return ConstString("mock process"); }
+uint32_t GetPluginVersion() override { return 0; }
+bool CanDebug(lldb::TargetSP target,
+  bool plugin_specified_by_name) override {
+  return false;
+};
+Status DoDestroy() override { return {}; }
+void RefreshStateAfterStop() override {}
+bool DoUpdateThreadList(ThreadList &old_thread_list,
+ThreadList &new_thread_list) override {
+  return false;
+};
+size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
+Status &error) override {
+  constexpr size_t bufsize = 512;
+  uint8_t memory[bufsize];
+  for (unsigned i = 0; i < bufsize; ++i)
+memory[i] = i & 0xff;
+  if (vm_addr >= bufsize) {
+error.SetErrorString("invalid address");
+return 0;
+  }
+  size_t nbytes = (vm_addr + size < bufsize) ? size : (bufsize - vm_addr);
+  memcpy(buf, memory+vm_addr, nbytes);
+  error.Clear();
+  return nbytes;
+}
+  };
+
+  // Set up a mock process.
+  ArchSpec arch("i386-pc-linux");
+  Platform::SetHostPlatform(
+  platform_linux::PlatformLinux::CreateInstance(true, &arch));
+  lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+  lldb::TargetSP target_sp;
+  lldb::PlatformSP platform_sp;
+  debugger_sp->GetTargetList().CreateTarget(
+  *debugger_sp, "", 

[Lldb-commits] [PATCH] D96549: Support dereferencing a DWARF scalar stack value

2021-02-12 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl updated this revision to Diff 323489.
aprantl added a comment.

There's actually no reason to fill a second memory buffer. Replaced all of 
DoReadMemory with a single for loop.


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

https://reviews.llvm.org/D96549

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/unittests/Expression/CMakeLists.txt
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -7,11 +7,15 @@
 //===--===//
 
 #include "lldb/Expression/DWARFExpression.h"
+#include "Plugins/Platform/Linux/PlatformLinux.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Value.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/dwarf.h"
+#include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Testing/Support/Error.h"
@@ -21,16 +25,17 @@
 
 static llvm::Expected Evaluate(llvm::ArrayRef expr,
lldb::ModuleSP module_sp = {},
-   DWARFUnit *unit = nullptr) {
+   DWARFUnit *unit = nullptr,
+   ExecutionContext *exe_ctx = nullptr) {
   DataExtractor extractor(expr.data(), expr.size(), lldb::eByteOrderLittle,
   /*addr_size*/ 4);
   Value result;
   Status status;
-  if (!DWARFExpression::Evaluate(
-  /*exe_ctx*/ nullptr, /*reg_ctx*/ nullptr, module_sp, extractor, unit,
-  lldb::eRegisterKindLLDB,
-  /*initial_value_ptr*/ nullptr,
-  /*object_address_ptr*/ nullptr, result, &status))
+  if (!DWARFExpression::Evaluate(exe_ctx, /*reg_ctx*/ nullptr, module_sp,
+ extractor, unit, lldb::eRegisterKindLLDB,
+ /*initial_value_ptr*/ nullptr,
+ /*object_address_ptr*/ nullptr, result,
+ &status))
 return status.ToError();
 
   switch (result.GetValueType()) {
@@ -66,6 +71,23 @@
   return scalar;
 }
 
+/// This is needed for the tests that use a mock process.
+class DWARFExpressionMockProcessTest : public ::testing::Test {
+public:
+  void SetUp() override {
+llvm::cantFail(repro::Reproducer::Initialize(repro::ReproducerMode::Off, {}));
+FileSystem::Initialize();
+HostInfo::Initialize();
+platform_linux::PlatformLinux::Initialize();
+  }
+  void TearDown() override {
+platform_linux::PlatformLinux::Terminate();
+HostInfo::Terminate();
+FileSystem::Terminate();
+repro::Reproducer::Terminate();
+  }
+};
+
 TEST(DWARFExpression, DW_OP_pick) {
   EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit1, DW_OP_lit0, DW_OP_pick, 0}),
llvm::HasValue(0));
@@ -277,6 +299,51 @@
   "Unhandled opcode DW_OP_unknown_ff in DWARFExpression"));
 }
 
-TEST(DWARFExpression, DW_OP_deref) {
+TEST_F(DWARFExpressionMockProcessTest, DW_OP_deref) {
   EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit0, DW_OP_deref}), llvm::Failed());
+
+  struct MockProcess : Process {
+using Process::Process;
+ConstString GetPluginName() override { return ConstString("mock process"); }
+uint32_t GetPluginVersion() override { return 0; }
+bool CanDebug(lldb::TargetSP target,
+  bool plugin_specified_by_name) override {
+  return false;
+};
+Status DoDestroy() override { return {}; }
+void RefreshStateAfterStop() override {}
+bool DoUpdateThreadList(ThreadList &old_thread_list,
+ThreadList &new_thread_list) override {
+  return false;
+};
+size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
+Status &error) override {
+  for (size_t i = 0; i < size; ++i)
+((char *)buf)[i] = (vm_addr + i) & 0xff;
+  error.Clear();
+  return size;
+}
+  };
+
+  // Set up a mock process.
+  ArchSpec arch("i386-pc-linux");
+  Platform::SetHostPlatform(
+  platform_linux::PlatformLinux::CreateInstance(true, &arch));
+  lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+  lldb::TargetSP target_sp;
+  lldb::PlatformSP platform_sp;
+  debugger_sp->GetTargetList().CreateTarget(
+  *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
+  ASSERT_TRUE(target_sp);
+  ASSERT_TRUE(target_sp->GetArchitecture().IsValid());
+  ASSERT_TRUE(platform_sp);
+  lldb::ListenerSP listener_sp(Listener::MakeListener("dummy"));
+  lldb::ProcessSP process_sp =
+  std::make_shared

[Lldb-commits] [PATCH] D96549: Support dereferencing a DWARF scalar stack value

2021-02-12 Thread Vedant Kumar via Phabricator via lldb-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

Thanks, lgtm.




Comment at: lldb/unittests/Expression/DWARFExpressionTest.cpp:347
+  ExecutionContext exe_ctx(process_sp);
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit4, DW_OP_deref}, {}, {}, &exe_ctx),
+   llvm::HasValue(GetScalar(32, 0x07060504, false)));

Neat, so lit4 is the address and the read pulls out [4, 5, 6, 7].


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

https://reviews.llvm.org/D96549

___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96549: Support dereferencing a DWARF scalar stack value

2021-02-12 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: lldb/unittests/Expression/DWARFExpressionTest.cpp:347
+  ExecutionContext exe_ctx(process_sp);
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit4, DW_OP_deref}, {}, {}, &exe_ctx),
+   llvm::HasValue(GetScalar(32, 0x07060504, false)));

vsk wrote:
> Neat, so lit4 is the address and the read pulls out [4, 5, 6, 7].
Yeah that's the lowest sensible address without dereferencing a nullptr :-)


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

https://reviews.llvm.org/D96549

___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96549: Support dereferencing a DWARF scalar stack value

2021-02-12 Thread Adrian Prantl via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG188b0747c166: Support dereferencing a DWARF scalar stack 
value (authored by aprantl).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D96549?vs=323489&id=323496#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96549

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/unittests/Expression/CMakeLists.txt
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -7,11 +7,15 @@
 //===--===//
 
 #include "lldb/Expression/DWARFExpression.h"
+#include "Plugins/Platform/Linux/PlatformLinux.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Value.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/dwarf.h"
+#include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Testing/Support/Error.h"
@@ -21,16 +25,17 @@
 
 static llvm::Expected Evaluate(llvm::ArrayRef expr,
lldb::ModuleSP module_sp = {},
-   DWARFUnit *unit = nullptr) {
+   DWARFUnit *unit = nullptr,
+   ExecutionContext *exe_ctx = nullptr) {
   DataExtractor extractor(expr.data(), expr.size(), lldb::eByteOrderLittle,
   /*addr_size*/ 4);
   Value result;
   Status status;
-  if (!DWARFExpression::Evaluate(
-  /*exe_ctx*/ nullptr, /*reg_ctx*/ nullptr, module_sp, extractor, unit,
-  lldb::eRegisterKindLLDB,
-  /*initial_value_ptr*/ nullptr,
-  /*object_address_ptr*/ nullptr, result, &status))
+  if (!DWARFExpression::Evaluate(exe_ctx, /*reg_ctx*/ nullptr, module_sp,
+ extractor, unit, lldb::eRegisterKindLLDB,
+ /*initial_value_ptr*/ nullptr,
+ /*object_address_ptr*/ nullptr, result,
+ &status))
 return status.ToError();
 
   switch (result.GetValueType()) {
@@ -66,6 +71,23 @@
   return scalar;
 }
 
+/// This is needed for the tests that use a mock process.
+class DWARFExpressionMockProcessTest : public ::testing::Test {
+public:
+  void SetUp() override {
+llvm::cantFail(repro::Reproducer::Initialize(repro::ReproducerMode::Off, {}));
+FileSystem::Initialize();
+HostInfo::Initialize();
+platform_linux::PlatformLinux::Initialize();
+  }
+  void TearDown() override {
+platform_linux::PlatformLinux::Terminate();
+HostInfo::Terminate();
+FileSystem::Terminate();
+repro::Reproducer::Terminate();
+  }
+};
+
 TEST(DWARFExpression, DW_OP_pick) {
   EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit1, DW_OP_lit0, DW_OP_pick, 0}),
llvm::HasValue(0));
@@ -277,6 +299,51 @@
   "Unhandled opcode DW_OP_unknown_ff in DWARFExpression"));
 }
 
-TEST(DWARFExpression, DW_OP_deref) {
+TEST_F(DWARFExpressionMockProcessTest, DW_OP_deref) {
   EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit0, DW_OP_deref}), llvm::Failed());
+
+  struct MockProcess : Process {
+using Process::Process;
+ConstString GetPluginName() override { return ConstString("mock process"); }
+uint32_t GetPluginVersion() override { return 0; }
+bool CanDebug(lldb::TargetSP target,
+  bool plugin_specified_by_name) override {
+  return false;
+};
+Status DoDestroy() override { return {}; }
+void RefreshStateAfterStop() override {}
+bool DoUpdateThreadList(ThreadList &old_thread_list,
+ThreadList &new_thread_list) override {
+  return false;
+};
+size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
+Status &error) override {
+  for (size_t i = 0; i < size; ++i)
+((char *)buf)[i] = (vm_addr + i) & 0xff;
+  error.Clear();
+  return size;
+}
+  };
+
+  // Set up a mock process.
+  ArchSpec arch("i386-pc-linux");
+  Platform::SetHostPlatform(
+  platform_linux::PlatformLinux::CreateInstance(true, &arch));
+  lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+  lldb::TargetSP target_sp;
+  lldb::PlatformSP platform_sp;
+  debugger_sp->GetTargetList().CreateTarget(
+  *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
+  ASSERT_TRUE(target_sp);
+  ASSERT_TRUE(target_sp->GetArchitecture().IsValid());
+  

[Lldb-commits] [lldb] 188b074 - Support dereferencing a DWARF scalar stack value

2021-02-12 Thread Adrian Prantl via lldb-commits

Author: Adrian Prantl
Date: 2021-02-12T16:12:32-08:00
New Revision: 188b0747c1664d962e94f00b5e3caac529fa1e26

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

LOG: Support dereferencing a DWARF scalar stack value

Swift async functions receive function arguments inside a
heap-allocated data structure, similar to how ObjC block captures or
C++ coroutine arguments are implement. In DWARF they are described
relative to an entry value that produces a pointer into that heap
object. At typical location looks like

DW_OP_entry_value [ DW_OP_reg14 ] DW_OP_deref DW_OP_plus_uconst 32 DW_OP_deref

This allows the unwinder (which has special ABI knowledge to restore
the contents of r14) to push the base address onto the stack thus
allowing the deref/offset operations to continue. The result of the
entry value is a scalar, because DW_OP_reg14 is a register location —
as it should be since we want to restore the pointer value contained
in r14 at the beginning of the function and not the historical memory
contents it was pointing to. The entry value should restore the
address, which is still valid, not the contents at function entry.

To make this work, we need to allow LLDB to dereference Scalar stack
results like load addresses, which is what this patch
does. Unfortunately it is difficult to test this in isolation, since
the DWARFExpression unit test doesn't have a process.

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

Added: 


Modified: 
lldb/source/Expression/DWARFExpression.cpp
lldb/unittests/Expression/CMakeLists.txt
lldb/unittests/Expression/DWARFExpressionTest.cpp

Removed: 




diff  --git a/lldb/source/Expression/DWARFExpression.cpp 
b/lldb/source/Expression/DWARFExpression.cpp
index 08dd1e2c929c..6e78b9aa841a 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -1067,6 +1067,7 @@ bool DWARFExpression::Evaluate(
 stack.back().SetValueType(Value::ValueType::LoadAddress);
 // Fall through to load address code below...
   } LLVM_FALLTHROUGH;
+  case Value::ValueType::Scalar:
   case Value::ValueType::LoadAddress:
 if (exe_ctx) {
   if (process) {
@@ -1099,7 +1100,6 @@ bool DWARFExpression::Evaluate(
 }
 break;
 
-  case Value::ValueType::Scalar:
   case Value::ValueType::Invalid:
 if (error_ptr)
   error_ptr->SetErrorString("Invalid value type for DW_OP_deref.\n");
@@ -1170,6 +1170,7 @@ bool DWARFExpression::Evaluate(
 stack.back().GetScalar() = ptr;
 stack.back().ClearContext();
   } break;
+  case Value::ValueType::Scalar:
   case Value::ValueType::LoadAddress:
 if (exe_ctx) {
   if (process) {
@@ -1221,7 +1222,6 @@ bool DWARFExpression::Evaluate(
 }
 break;
 
-  case Value::ValueType::Scalar:
   case Value::ValueType::FileAddress:
   case Value::ValueType::Invalid:
 if (error_ptr)

diff  --git a/lldb/unittests/Expression/CMakeLists.txt 
b/lldb/unittests/Expression/CMakeLists.txt
index 0e8230d19bad..185b19f84cae 100644
--- a/lldb/unittests/Expression/CMakeLists.txt
+++ b/lldb/unittests/Expression/CMakeLists.txt
@@ -7,6 +7,8 @@ add_lldb_unittest(ExpressionTests
 
   LINK_LIBS
 lldbCore
+lldbPluginObjectFileELF
+lldbPluginPlatformLinux
 lldbPluginExpressionParserClang
 lldbPluginTypeSystemClang
 lldbUtility

diff  --git a/lldb/unittests/Expression/DWARFExpressionTest.cpp 
b/lldb/unittests/Expression/DWARFExpressionTest.cpp
index ef89749ba7f8..ad56207659d2 100644
--- a/lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ b/lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -7,11 +7,15 @@
 
//===--===//
 
 #include "lldb/Expression/DWARFExpression.h"
+#include "Plugins/Platform/Linux/PlatformLinux.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Value.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/dwarf.h"
+#include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Testing/Support/Error.h"
@@ -21,16 +25,17 @@ using namespace lldb_private;
 
 static llvm::Expected Evaluate(llvm::ArrayRef expr,
lldb::ModuleSP module_sp = {},
-   DWARFUnit *unit = nullptr) {
+   DWARFUnit *unit = nullptr,
+   ExecutionContext *exe_ctx = nullptr) {
   DataExtractor extractor(expr.data(), expr.size(), lldb::

[Lldb-commits] [lldb] 057efa9 - Make the error condition in Value::ValueType explicit (NFC)

2021-02-12 Thread Adrian Prantl via lldb-commits

Author: Adrian Prantl
Date: 2021-02-12T16:12:31-08:00
New Revision: 057efa9916cdc354ef4653bcd128a578cc43125e

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

LOG: Make the error condition in Value::ValueType explicit (NFC)

The comment for ValueType claims that all values <1 are errors, but
not all switch statements take this into account. This patch
introduces an explicit Error case and deletes all default: cases, so
we get warned about incomplete switch coverage.

https://reviews.llvm.org/D96537

Added: 


Modified: 
lldb/include/lldb/Core/Value.h
lldb/include/lldb/Expression/ExpressionVariable.h
lldb/source/Core/Value.cpp
lldb/source/Core/ValueObject.cpp
lldb/source/Core/ValueObjectChild.cpp
lldb/source/Core/ValueObjectConstResult.cpp
lldb/source/Core/ValueObjectConstResultImpl.cpp
lldb/source/Core/ValueObjectMemory.cpp
lldb/source/Core/ValueObjectRegister.cpp
lldb/source/Core/ValueObjectVariable.cpp
lldb/source/DataFormatters/TypeFormat.cpp
lldb/source/Expression/DWARFExpression.cpp
lldb/source/Expression/FunctionCaller.cpp
lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp
lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

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

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
lldb/source/Target/ABI.cpp
lldb/source/Target/RegisterContextUnwind.cpp
lldb/source/Target/ThreadPlanTracer.cpp
lldb/unittests/Expression/DWARFExpressionTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Value.h b/lldb/include/lldb/Core/Value.h
index 0ff773e59911..bc0cbeae51cf 100644
--- a/lldb/include/lldb/Core/Value.h
+++ b/lldb/include/lldb/Core/Value.h
@@ -37,27 +37,32 @@ namespace lldb_private {
 
 class Value {
 public:
-  // Values Less than zero are an error, greater than or equal to zero returns
-  // what the Scalar result is.
-  enum ValueType {
-// m_value contains...
-// 
-eValueTypeScalar,  // raw scalar value
-eValueTypeFileAddress, // file address value
-eValueTypeLoadAddress, // load address value
-eValueTypeHostAddress  // host address value (for memory in the process 
that
-   // is using liblldb)
+  /// Type that describes Value::m_value.
+  enum class ValueType {
+Invalid = -1,
+// m_value contains:
+/// A raw scalar value.
+Scalar = 0,
+/// A file address value.
+FileAddress,
+/// A load address value.
+LoadAddress,
+/// A host address value (for memory in the process that < A is
+/// using liblldb).
+HostAddress
   };
 
-  enum ContextType // Type that describes Value::m_context
-  {
-// m_context contains...
-// 
-eContextTypeInvalid,  // undefined
-eContextTypeRegisterInfo, // RegisterInfo * (can be a scalar or a vector
-  // register)
-eContextTypeLLDBType, // lldb_private::Type *
-eContextTypeVariable  // lldb_private::Variable *
+  /// Type that describes Value::m_context.
+  enum class ContextType {
+// m_context contains:
+/// Undefined.
+Invalid = -1,
+/// RegisterInfo * (can be a scalar or a vector register).
+RegisterInfo = 0,
+/// lldb_private::Type *.
+LLDBType,
+/// lldb_private::Variable *.
+Variable
   };
 
   Value();
@@ -85,16 +90,16 @@ class Value {
 
   void ClearContext() {
 m_context = nullptr;
-m_context_type = eContextTypeInvalid;
+m_context_type = ContextType::Invalid;
   }
 
   void SetContext(ContextType context_type, void *p) {
 m_context_type = context_type;
 m_context = p;
-if (m_context_type == eContextTypeRegisterInfo) {
+  

[Lldb-commits] [PATCH] D96537: Make the error condition in Value::ValueType explicit (NFC)

2021-02-12 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

> (Btw, if you intend to cherry-pick this into swift/main for some reason then 
> please let me know as this probably will cause a bunch of conflicts with the 
> temporarily reverted patch from Pavel).

I don't //need// to cherry-pick it, so I won't for now.




Comment at: lldb/source/Core/Value.cpp:574
 switch (m_value_type) {
-case eValueTypeScalar: // raw scalar value
+case ValueType::Invalid:
+case ValueType::Scalar: // raw scalar value

shafik wrote:
> In the invalid case does `m_value` have some initial value i.e. it is not 
> uninitialized. 
I don't understand what you are asking here?



Comment at: lldb/source/Core/ValueObjectConstResult.cpp:148
   m_value.GetScalar().GetData(m_data, addr_byte_size);
-  // m_value.SetValueType(Value::eValueTypeHostAddress);
+  // m_value.SetValueType(Value::ValueType::HostAddress);
   switch (address_type) {

shafik wrote:
> dead code?
Yes, but I'm not going to touch this in this commit.


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

https://reviews.llvm.org/D96537

___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 2dbe88d - [lldb] Fix up SysV ABI implementations after 057efa9916cdc354ef4653bcd128a578cc43125e

2021-02-12 Thread Benjamin Kramer via lldb-commits

Author: Benjamin Kramer
Date: 2021-02-13T01:34:00+01:00
New Revision: 2dbe88db5804f32c6dfc1aa474881c3cb7a61d03

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

LOG: [lldb] Fix up SysV ABI implementations after 
057efa9916cdc354ef4653bcd128a578cc43125e

Added: 


Modified: 
lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp

Removed: 




diff  --git a/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp 
b/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
index be8586722d8f..60cdbc534113 100644
--- a/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
+++ b/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
@@ -466,7 +466,7 @@ ABISysV_arc::GetReturnValueObjectSimple(Thread &thread,
 if (!SetSizedInteger(value.GetScalar(), raw_value, byte_size, is_signed))
   return ValueObjectSP();
 
-value.SetValueType(Value::eValueTypeScalar);
+value.SetValueType(Value::ValueType::Scalar);
   }
   // Pointer return type.
   else if (type_flags & eTypeIsPointer) {
@@ -474,7 +474,7 @@ ABISysV_arc::GetReturnValueObjectSimple(Thread &thread,
 LLDB_REGNUM_GENERIC_ARG1);
 value.GetScalar() = reg_ctx->ReadRegisterAsUnsigned(reg_info_r0, 0);
 
-value.SetValueType(Value::eValueTypeScalar);
+value.SetValueType(Value::ValueType::Scalar);
   }
   // Floating point return type.
   else if (type_flags & eTypeIsFloat) {
@@ -537,7 +537,7 @@ ValueObjectSP ABISysV_arc::GetReturnValueObjectImpl(Thread 
&thread,
 auto reg_info_r0 = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
 LLDB_REGNUM_GENERIC_ARG1);
 value.GetScalar() = reg_ctx->ReadRegisterAsUnsigned(reg_info_r0, 0);
-value.SetValueType(Value::eValueTypeScalar);
+value.SetValueType(Value::ValueType::Scalar);
   }
   // Floating point return type.
   else if (retType.isFloatingPointTy()) {

diff  --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp 
b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
index 751555722dac..5e72af076f66 100644
--- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
+++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
@@ -764,7 +764,7 @@ ValueObjectSP ABISysV_mips64::GetReturnValueObjectImpl(
   const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
 
   if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
-value.SetValueType(Value::eValueTypeScalar);
+value.SetValueType(Value::ValueType::Scalar);
 
 bool success = false;
 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {

diff  --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp 
b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
index 91d2e59ed632..d5605642d623 100644
--- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
+++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
@@ -520,7 +520,7 @@ ValueObjectSP ABISysV_ppc::GetReturnValueObjectSimple(
 
   const uint32_t type_flags = return_compiler_type.GetTypeInfo();
   if (type_flags & eTypeIsScalar) {
-value.SetValueType(Value::eValueTypeScalar);
+value.SetValueType(Value::ValueType::Scalar);
 
 bool success = false;
 if (type_flags & eTypeIsInteger) {
@@ -603,7 +603,7 @@ ValueObjectSP ABISysV_ppc::GetReturnValueObjectSimple(
 reg_ctx->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
 value.GetScalar() =
 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 
0);
-value.SetValueType(Value::eValueTypeScalar);
+value.SetValueType(Value::ValueType::Scalar);
 return_valobj_sp = ValueObjectConstResult::Create(
 thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
   } else if (type_flags & eTypeIsVector) {

diff  --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp 
b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
index c7cb7736df9f..603143190dc5 100644
--- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
+++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
@@ -577,7 +577,7 @@ class ReturnValueExtractor {
   ValueSP NewScalarValue(CompilerType &type) {
 ValueSP value_sp(new Value);
 value_sp->SetCompilerType(type);
-value_sp->SetValueType(Value::eValueTypeScalar);
+value_sp->SetValueType(Value::ValueType::Scalar);
 return value_sp;
   }
 

diff  --git a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp 
b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp
index 22a64170017b..88e85111d871 100644
--- a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp
+++ b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp
@@ -487,7 +487,7 @@ ValueObjectSP 

Re: [Lldb-commits] [lldb] 2dbe88d - [lldb] Fix up SysV ABI implementations after 057efa9916cdc354ef4653bcd128a578cc43125e

2021-02-12 Thread Adrian Prantl via lldb-commits
Thanks!

-- adrian

> On Feb 12, 2021, at 4:34 PM, Benjamin Kramer via lldb-commits 
>  wrote:
> 
> 
> Author: Benjamin Kramer
> Date: 2021-02-13T01:34:00+01:00
> New Revision: 2dbe88db5804f32c6dfc1aa474881c3cb7a61d03
> 
> URL: 
> https://github.com/llvm/llvm-project/commit/2dbe88db5804f32c6dfc1aa474881c3cb7a61d03
> DIFF: 
> https://github.com/llvm/llvm-project/commit/2dbe88db5804f32c6dfc1aa474881c3cb7a61d03.diff
> 
> LOG: [lldb] Fix up SysV ABI implementations after 
> 057efa9916cdc354ef4653bcd128a578cc43125e
> 
> Added: 
> 
> 
> Modified: 
>lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
>lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
>lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
>lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
>lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp
> 
> Removed: 
> 
> 
> 
> 
> diff  --git a/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp 
> b/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
> index be8586722d8f..60cdbc534113 100644
> --- a/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
> +++ b/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp
> @@ -466,7 +466,7 @@ ABISysV_arc::GetReturnValueObjectSimple(Thread &thread,
> if (!SetSizedInteger(value.GetScalar(), raw_value, byte_size, is_signed))
>   return ValueObjectSP();
> 
> -value.SetValueType(Value::eValueTypeScalar);
> +value.SetValueType(Value::ValueType::Scalar);
>   }
>   // Pointer return type.
>   else if (type_flags & eTypeIsPointer) {
> @@ -474,7 +474,7 @@ ABISysV_arc::GetReturnValueObjectSimple(Thread &thread,
> LLDB_REGNUM_GENERIC_ARG1);
> value.GetScalar() = reg_ctx->ReadRegisterAsUnsigned(reg_info_r0, 0);
> 
> -value.SetValueType(Value::eValueTypeScalar);
> +value.SetValueType(Value::ValueType::Scalar);
>   }
>   // Floating point return type.
>   else if (type_flags & eTypeIsFloat) {
> @@ -537,7 +537,7 @@ ValueObjectSP 
> ABISysV_arc::GetReturnValueObjectImpl(Thread &thread,
> auto reg_info_r0 = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
> LLDB_REGNUM_GENERIC_ARG1);
> value.GetScalar() = reg_ctx->ReadRegisterAsUnsigned(reg_info_r0, 0);
> -value.SetValueType(Value::eValueTypeScalar);
> +value.SetValueType(Value::ValueType::Scalar);
>   }
>   // Floating point return type.
>   else if (retType.isFloatingPointTy()) {
> 
> diff  --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp 
> b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
> index 751555722dac..5e72af076f66 100644
> --- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
> +++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
> @@ -764,7 +764,7 @@ ValueObjectSP ABISysV_mips64::GetReturnValueObjectImpl(
>   const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
> 
>   if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
> -value.SetValueType(Value::eValueTypeScalar);
> +value.SetValueType(Value::ValueType::Scalar);
> 
> bool success = false;
> if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
> 
> diff  --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp 
> b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
> index 91d2e59ed632..d5605642d623 100644
> --- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
> +++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
> @@ -520,7 +520,7 @@ ValueObjectSP ABISysV_ppc::GetReturnValueObjectSimple(
> 
>   const uint32_t type_flags = return_compiler_type.GetTypeInfo();
>   if (type_flags & eTypeIsScalar) {
> -value.SetValueType(Value::eValueTypeScalar);
> +value.SetValueType(Value::ValueType::Scalar);
> 
> bool success = false;
> if (type_flags & eTypeIsInteger) {
> @@ -603,7 +603,7 @@ ValueObjectSP ABISysV_ppc::GetReturnValueObjectSimple(
> reg_ctx->GetRegisterInfoByName("r3", 0)->kinds[eRegisterKindLLDB];
> value.GetScalar() =
> (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 
> 0);
> -value.SetValueType(Value::eValueTypeScalar);
> +value.SetValueType(Value::ValueType::Scalar);
> return_valobj_sp = ValueObjectConstResult::Create(
> thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
>   } else if (type_flags & eTypeIsVector) {
> 
> diff  --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp 
> b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
> index c7cb7736df9f..603143190dc5 100644
> --- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
> +++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
> @@ -577,7 +577,7 @@ class ReturnValueExtractor {
>   ValueSP NewScalarValue(CompilerType &type) {
> ValueSP value_sp(new Value);
> value_sp->SetCompilerType(type);
> -value_sp->SetValueType(Value::eValueTypeScalar);
> +value_sp->SetValueType(Value::ValueType::Scalar);
> return value_sp;
>   }
> 
> 
> diff  --git a/lldb/sourc

[Lldb-commits] [PATCH] D96537: Make the error condition in Value::ValueType explicit (NFC)

2021-02-12 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik added inline comments.



Comment at: lldb/source/Core/Value.cpp:574
 switch (m_value_type) {
-case eValueTypeScalar: // raw scalar value
+case ValueType::Invalid:
+case ValueType::Scalar: // raw scalar value

aprantl wrote:
> shafik wrote:
> > In the invalid case does `m_value` have some initial value i.e. it is not 
> > uninitialized. 
> I don't understand what you are asking here?
The other cases initialize `m_value` or call `Clear` on it and `m_value` is 
return at the end and I was asking is it is properly initialized.


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

https://reviews.llvm.org/D96537

___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits