[Lldb-commits] [PATCH] D115033: [lldb-vscode] Report supportsModulesRequest=true

2021-12-03 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG049530129326: [lldb-vscode] Report 
supportsModulesRequest=true (authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115033

Files:
  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
@@ -1505,7 +1505,7 @@
   // is the behavior of LLDB CLI, that expects a TAB.
   body.try_emplace("supportsCompletionsRequest", false);
   // The debug adapter supports the modules request.
-  body.try_emplace("supportsModulesRequest", false);
+  body.try_emplace("supportsModulesRequest", true);
   // The set of additional module information exposed by the debug adapter.
   //   body.try_emplace("additionalModuleColumns"] = ColumnDescriptor
   // Checksum algorithms supported by the debug adapter.


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1505,7 +1505,7 @@
   // is the behavior of LLDB CLI, that expects a TAB.
   body.try_emplace("supportsCompletionsRequest", false);
   // The debug adapter supports the modules request.
-  body.try_emplace("supportsModulesRequest", false);
+  body.try_emplace("supportsModulesRequest", true);
   // The set of additional module information exposed by the debug adapter.
   //   body.try_emplace("additionalModuleColumns"] = ColumnDescriptor
   // Checksum algorithms supported by the debug adapter.
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2021-12-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2461
+  bool has_scope = !scope.IsEmpty();
+  llvm::StringRef sc(scope.GetStringRef());
+  std::string storage;

nit: maybe call it `scope_ref`?



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2470
+  const char *qn = die.GetQualifiedName(storage);
+  if (qn && !llvm::StringRef(qn).startswith(sc))
+return true;

`llvm::StringRef(storage)` is slightly more efficient here than 
`llvm::StringRef(qn)`. The latter uses strlen in the constructor to calculate 
the length of the source string.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

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


[Lldb-commits] [PATCH] D115110: [lldb][nfc] clang-format some files as preperation for https://reviews.llvm.org/D114627

2021-12-09 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2e2eece9aa8: [lldb][NFC] clang-format some files as 
preparation for https://reviews.llvm. (authored by lassefolger, committed by 
werat).

Changed prior to commit:
  https://reviews.llvm.org/D115110?vs=391895&id=393103#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115110

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

Index: lldb/source/Symbol/SymbolFile.cpp
===
--- lldb/source/Symbol/SymbolFile.cpp
+++ lldb/source/Symbol/SymbolFile.cpp
@@ -147,9 +147,11 @@
   // We assert that we have to module lock by trying to acquire the lock from a
   // different thread. Note that we must abort if the result is true to
   // guarantee correctness.
-  assert(std::async(std::launch::async,
-[this] { return this->GetModuleMutex().try_lock(); })
- .get() == false &&
+  assert(std::async(
+ std::launch::async,
+ [this] {
+   return this->GetModuleMutex().try_lock();
+ }).get() == false &&
  "Module is not locked");
 #endif
 }
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -253,8 +253,8 @@
   ExternalTypeModuleMap;
 
   /// Return the list of Clang modules imported by this SymbolFile.
-  const ExternalTypeModuleMap& getExternalTypeModules() const {
-  return m_external_type_modules;
+  const ExternalTypeModuleMap &getExternalTypeModules() const {
+return m_external_type_modules;
   }
 
   virtual DWARFDIE GetDIE(const DIERef &die_ref);
@@ -328,7 +328,6 @@
 return m_parse_time;
   }
 
-
 protected:
   typedef llvm::DenseMap
   DIEToTypePtr;
@@ -428,9 +427,10 @@
   virtual lldb::TypeSP
   FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
 
-  virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
-  const DWARFDIE &die, lldb_private::ConstString type_name,
-  bool must_be_implementation);
+  virtual lldb::TypeSP
+  FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die,
+   lldb_private::ConstString type_name,
+   bool must_be_implementation);
 
   lldb_private::Symbol *
   GetObjCClassSymbol(lldb_private::ConstString objc_class_name);
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1097,7 +1097,8 @@
   if (const char *include_path = module_die.GetAttributeValueAsString(
   DW_AT_LLVM_include_path, nullptr)) {
 FileSpec include_spec(include_path, dwarf_cu->GetPathStyle());
-MakeAbsoluteAndRemap(include_spec, *dwarf_cu, m_objfile_sp->GetModule());
+MakeAbsoluteAndRemap(include_spec, *dwarf_cu,
+ m_objfile_sp->GetModule());
 module.search_path = ConstString(include_spec.GetPath());
   }
   if (const char *sysroot = dwarf_cu->DIE().GetAttributeValueAsString(
@@ -1924,7 +1925,7 @@
   block_die = function_die.LookupDeepestBlock(file_vm_addr);
   }
 
-  if (!sc.function || ! lookup_block)
+  if (!sc.function || !lookup_block)
 return;
 
   Block &block = sc.function->GetBlock(true);
@@ -2319,7 +2320,8 @@
   if (log) {
 GetObjectFile()->GetModule()->LogMessage(
 log,
-"SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, sc_list)",
+"SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, "
+"sc_list)",
 name.GetCString(), name_type_mask);
   }
 
@@ -2352,8 +2354,7 @@
 log,
 "SymbolFileDWARF::FindFunctions (name=\"%s\", "
 "name_type_mask=0x%x, include_inlines=%d, sc_list) => %u",
-name.GetCString(), name_type_mask, include_inlines,
-num_matches);
+name.GetCString(), name_type_mask, include_inlines, num_matches);
   }
 }
 
Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -233,8 +233,8 @@
 Module::Module(const FileSpec &file_spec, const ArchSpec &arch,
const ConstString *object_name, lldb::offset_t object_offset,
const llvm::sys::TimePoint<> &object_mod_time)
-: m_mod_time(FileSystem::Instan

[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2022-02-04 Thread Andy Yankovsky via Phabricator via lldb-commits
werat accepted this revision.
werat added a comment.
This revision is now accepted and ready to land.

Looks good to me, I'm going to land it soon unless there are objections from 
other reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

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


[Lldb-commits] [PATCH] D119009: [Support] Ensure handlers are set up before printing the stacktrace

2022-02-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 406480.
werat added a comment.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Call `sys::PrintStackTraceOnErrorSignal()` in `SBDebugger::Initialize()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119009

Files:
  lldb/source/API/SystemInitializerFull.cpp
  llvm/lib/Support/Unix/Signals.inc
  llvm/lib/Support/Windows/Signals.inc


Index: llvm/lib/Support/Windows/Signals.inc
===
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -504,7 +504,11 @@
 /// process, print a stack trace and then exit.
 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // This function may get called multiple times and some of the calls might
+  // have empty (aka unknown) Argv0. Overwrite global ::Argv0 only if the
+  // provided value is non-empty.
+  if (!Argv0.empty())
+::Argv0 = Argv0;
 
   if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
 Process::PreventCoreFiles();
Index: llvm/lib/Support/Unix/Signals.inc
===
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -637,7 +637,11 @@
 /// process, print a stack trace and then exit.
 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
  bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // This function may get called multiple times and some of the calls might
+  // have empty (aka unknown) Argv0. Overwrite global ::Argv0 only if the
+  // provided value is non-empty.
+  if (!Argv0.empty())
+::Argv0 = Argv0;
 
   AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
 
Index: lldb/source/API/SystemInitializerFull.cpp
===
--- lldb/source/API/SystemInitializerFull.cpp
+++ lldb/source/API/SystemInitializerFull.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 
 #pragma clang diagnostic push
@@ -53,6 +54,12 @@
   if (error)
 return error;
 
+  // On Windows certain functions from Signals.h require that the global state
+  // is initialized. For LLDB driver the initialization happens in the `main`
+  // function via the `llvm::InitLLVM` helper, but for LLDB dynamic library
+  // (liblldb) that doesn't happen.
+  llvm::sys::PrintStackTraceOnErrorSignal(/*Argv0=*/{});
+
   // Initialize LLVM and Clang
   llvm::InitializeAllTargets();
   llvm::InitializeAllAsmPrinters();


Index: llvm/lib/Support/Windows/Signals.inc
===
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -504,7 +504,11 @@
 /// process, print a stack trace and then exit.
 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // This function may get called multiple times and some of the calls might
+  // have empty (aka unknown) Argv0. Overwrite global ::Argv0 only if the
+  // provided value is non-empty.
+  if (!Argv0.empty())
+::Argv0 = Argv0;
 
   if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
 Process::PreventCoreFiles();
Index: llvm/lib/Support/Unix/Signals.inc
===
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -637,7 +637,11 @@
 /// process, print a stack trace and then exit.
 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
  bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // This function may get called multiple times and some of the calls might
+  // have empty (aka unknown) Argv0. Overwrite global ::Argv0 only if the
+  // provided value is non-empty.
+  if (!Argv0.empty())
+::Argv0 = Argv0;
 
   AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
 
Index: lldb/source/API/SystemInitializerFull.cpp
===
--- lldb/source/API/SystemInitializerFull.cpp
+++ lldb/source/API/SystemInitializerFull.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 
 #pragma clang diagnostic push
@@ -53,6 +54,12 @@
   if (error)
 return error;
 
+  // On Windows certain functions from Signals.h require that the global state
+  // is initialized. For LLDB driver the initialization happens in the `main`
+ 

[Lldb-commits] [PATCH] D119009: [Support] Ensure handlers are set up before printing the stacktrace

2022-02-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 406483.
werat added a comment.
Herald added subscribers: JDevlieghere, mstorsjo.

Initialize signal handlers in `PrintStackTraceOnErrorSignal()` only once.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119009

Files:
  lldb/source/API/SystemInitializerFull.cpp
  llvm/lib/Support/Unix/Signals.inc
  llvm/lib/Support/Windows/Signals.inc

Index: llvm/lib/Support/Windows/Signals.inc
===
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -26,98 +26,99 @@
 #include "llvm/Support/Windows/WindowsSupport.h"
 
 #ifdef __MINGW32__
- #include 
+#include 
 #else
- #include 
- #include 
+#include 
+#include 
 #endif
 #include 
 
 #ifdef _MSC_VER
- #pragma comment(lib, "psapi.lib")
+#pragma comment(lib, "psapi.lib")
 #elif __MINGW32__
- // The version of g++ that comes with MinGW does *not* properly understand
- // the ll format specifier for printf. However, MinGW passes the format
- // specifiers on to the MSVCRT entirely, and the CRT understands the ll
- // specifier. So these warnings are spurious in this case. Since we compile
- // with -Wall, this will generate these warnings which should be ignored. So
- // we will turn off the warnings for this just file. However, MinGW also does
- // not support push and pop for diagnostics, so we have to manually turn it
- // back on at the end of the file.
- #pragma GCC diagnostic ignored "-Wformat"
- #pragma GCC diagnostic ignored "-Wformat-extra-args"
-
- #if !defined(__MINGW64_VERSION_MAJOR)
- // MinGW.org does not have updated support for the 64-bit versions of the
- // DebugHlp APIs. So we will have to load them manually. The structures and
- // method signatures were pulled from DbgHelp.h in the Windows Platform SDK,
- // and adjusted for brevity.
- typedef struct _IMAGEHLP_LINE64 {
-   DWORDSizeOfStruct;
-   PVOIDKey;
-   DWORDLineNumber;
-   PCHARFileName;
-   DWORD64  Address;
- } IMAGEHLP_LINE64, *PIMAGEHLP_LINE64;
-
- typedef struct _IMAGEHLP_SYMBOL64 {
-   DWORD   SizeOfStruct;
-   DWORD64 Address;
-   DWORD   Size;
-   DWORD   Flags;
-   DWORD   MaxNameLength;
-   CHARName[1];
- } IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64;
-
- typedef struct _tagADDRESS64 {
-   DWORD64   Offset;
-   WORD  Segment;
-   ADDRESS_MODE  Mode;
- } ADDRESS64, *LPADDRESS64;
-
- typedef struct _KDHELP64 {
-   DWORD64   Thread;
-   DWORD   ThCallbackStack;
-   DWORD   ThCallbackBStore;
-   DWORD   NextCallback;
-   DWORD   FramePointer;
-   DWORD64   KiCallUserMode;
-   DWORD64   KeUserCallbackDispatcher;
-   DWORD64   SystemRangeStart;
-   DWORD64   KiUserExceptionDispatcher;
-   DWORD64   StackBase;
-   DWORD64   StackLimit;
-   DWORD64   Reserved[5];
- } KDHELP64, *PKDHELP64;
-
- typedef struct _tagSTACKFRAME64 {
-   ADDRESS64   AddrPC;
-   ADDRESS64   AddrReturn;
-   ADDRESS64   AddrFrame;
-   ADDRESS64   AddrStack;
-   ADDRESS64   AddrBStore;
-   PVOID   FuncTableEntry;
-   DWORD64 Params[4];
-   BOOLFar;
-   BOOLVirtual;
-   DWORD64 Reserved[3];
-   KDHELP64KdHelp;
- } STACKFRAME64, *LPSTACKFRAME64;
- #endif // !defined(__MINGW64_VERSION_MAJOR)
+// The version of g++ that comes with MinGW does *not* properly understand
+// the ll format specifier for printf. However, MinGW passes the format
+// specifiers on to the MSVCRT entirely, and the CRT understands the ll
+// specifier. So these warnings are spurious in this case. Since we compile
+// with -Wall, this will generate these warnings which should be ignored. So
+// we will turn off the warnings for this just file. However, MinGW also does
+// not support push and pop for diagnostics, so we have to manually turn it
+// back on at the end of the file.
+#pragma GCC diagnostic ignored "-Wformat"
+#pragma GCC diagnostic ignored "-Wformat-extra-args"
+
+#if !defined(__MINGW64_VERSION_MAJOR)
+// MinGW.org does not have updated support for the 64-bit versions of the
+// DebugHlp APIs. So we will have to load them manually. The structures and
+// method signatures were pulled from DbgHelp.h in the Windows Platform SDK,
+// and adjusted for brevity.
+typedef struct _IMAGEHLP_LINE64 {
+  DWORD SizeOfStruct;
+  PVOID Key;
+  DWORD LineNumber;
+  PCHAR FileName;
+  DWORD64 Address;
+} IMAGEHLP_LINE64, *PIMAGEHLP_LINE64;
+
+typedef struct _IMAGEHLP_SYMBOL64 {
+  DWORD SizeOfStruct;
+  DWORD64 Address;
+  DWORD Size;
+  DWORD Flags;
+  DWORD MaxNameLength;
+  CHAR Name[1];
+} IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64;
+
+typedef struct _tagADDRESS64 {
+  DWORD64 Offset;
+  WORD Segment;
+  ADDRESS_MODE Mode;
+} ADDRESS64, *LPADDRESS64;
+
+typedef struct _KDHELP64 {
+  DWORD64 Thread;
+  DWORD ThCallbackStack;
+  DWORD ThCallbackBStore;
+  DWORD NextCallback;
+  DWORD FramePointer;
+  DWORD64 KiCallUserMode;
+  DWORD64 KeUserCallbackDispatcher;
+  DWORD64 SystemRangeStart;

[Lldb-commits] [PATCH] D119009: [Support] Ensure handlers are set up before printing the stacktrace

2022-02-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D119009#3297591 , @aganea wrote:

> I'm not sure it's a good idea to start loading DLLs when we get to this point.
> I would rather suggest calling `sys::PrintStackTraceOnErrorSignal({});` in 
> `SBDebugger::Initialize()`. "argv0" will be auto-detected if necessary, 
> otherwise if you can, change the `SBDebugger::Initialize()` API to pass it? 
> It's only there so that we can find `llvm-symbolizer` next to the running 
> executable.

Thanks for a quick review! I followed your adviced and added a call to 
`PrintStackTraceOnErrorSignal()` in `Debugger::Initialize()`. It's possible to 
change the API to accept `argv` is possible, but it we can't introduce breaking 
changes, so the old code will not have `argv`.

Given that now PrintStackTraceOnErrorSignal will be called twice in LLDB driver 
(and in general case `Initialize()` can be called many times), I modified the 
implementation of `PrintStackTraceOnErrorSignal` a little bit -- don't do 
anything if `::Argv0` is already set.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119009

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


[Lldb-commits] [PATCH] D119009: [Support] Ensure handlers are set up before printing the stacktrace

2022-02-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 406484.
werat added a comment.

Revert accidental formatting changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119009

Files:
  lldb/source/API/SystemInitializerFull.cpp
  llvm/lib/Support/Unix/Signals.inc
  llvm/lib/Support/Windows/Signals.inc


Index: llvm/lib/Support/Windows/Signals.inc
===
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -504,7 +504,10 @@
 /// process, print a stack trace and then exit.
 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
 
   if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
 Process::PreventCoreFiles();
@@ -554,7 +557,9 @@
 
 void llvm::sys::PrintStackTrace(raw_ostream &OS, int Depth) {
   // FIXME: Handle "Depth" parameter to print stack trace upto specified Depth
+  RegisterHandler();
   LocalPrintStackTrace(OS, nullptr);
+  LeaveCriticalSection(&CriticalSection);
 }
 
 void llvm::sys::SetInterruptFunction(void (*IF)()) {
Index: llvm/lib/Support/Unix/Signals.inc
===
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -637,7 +637,10 @@
 /// process, print a stack trace and then exit.
 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
  bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
 
   AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
 
Index: lldb/source/API/SystemInitializerFull.cpp
===
--- lldb/source/API/SystemInitializerFull.cpp
+++ lldb/source/API/SystemInitializerFull.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 
 #pragma clang diagnostic push
@@ -53,6 +54,12 @@
   if (error)
 return error;
 
+  // On Windows certain functions from Signals.h require that the global state
+  // is initialized. For LLDB driver the initialization happens in the `main`
+  // function via the `llvm::InitLLVM` helper, but for LLDB dynamic library
+  // (liblldb) that doesn't happen.
+  llvm::sys::PrintStackTraceOnErrorSignal(/*Argv0=*/{});
+
   // Initialize LLVM and Clang
   llvm::InitializeAllTargets();
   llvm::InitializeAllAsmPrinters();


Index: llvm/lib/Support/Windows/Signals.inc
===
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -504,7 +504,10 @@
 /// process, print a stack trace and then exit.
 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
 
   if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
 Process::PreventCoreFiles();
@@ -554,7 +557,9 @@
 
 void llvm::sys::PrintStackTrace(raw_ostream &OS, int Depth) {
   // FIXME: Handle "Depth" parameter to print stack trace upto specified Depth
+  RegisterHandler();
   LocalPrintStackTrace(OS, nullptr);
+  LeaveCriticalSection(&CriticalSection);
 }
 
 void llvm::sys::SetInterruptFunction(void (*IF)()) {
Index: llvm/lib/Support/Unix/Signals.inc
===
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -637,7 +637,10 @@
 /// process, print a stack trace and then exit.
 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
  bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
 
   AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
 
Index: lldb/source/API/SystemInitializerFull.cpp
===
--- lldb/source/API/SystemInitializerFull.cpp
+++ lldb/source/API/SystemInitializerFull.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
 #include "llvm/Support/CommandLine.

[Lldb-commits] [PATCH] D119009: [Support] Ensure handlers are set up before printing the stacktrace

2022-02-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 406485.
werat added a comment.

Remove accidental old code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119009

Files:
  lldb/source/API/SystemInitializerFull.cpp
  llvm/lib/Support/Unix/Signals.inc
  llvm/lib/Support/Windows/Signals.inc


Index: llvm/lib/Support/Windows/Signals.inc
===
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -504,7 +504,10 @@
 /// process, print a stack trace and then exit.
 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
 
   if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
 Process::PreventCoreFiles();
Index: llvm/lib/Support/Unix/Signals.inc
===
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -637,7 +637,10 @@
 /// process, print a stack trace and then exit.
 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
  bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
 
   AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
 
Index: lldb/source/API/SystemInitializerFull.cpp
===
--- lldb/source/API/SystemInitializerFull.cpp
+++ lldb/source/API/SystemInitializerFull.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 
 #pragma clang diagnostic push
@@ -53,6 +54,12 @@
   if (error)
 return error;
 
+  // On Windows certain functions from Signals.h require that the global state
+  // is initialized. For LLDB driver the initialization happens in the `main`
+  // function via the `llvm::InitLLVM` helper, but for LLDB dynamic library
+  // (liblldb) that doesn't happen.
+  llvm::sys::PrintStackTraceOnErrorSignal(/*Argv0=*/{});
+
   // Initialize LLVM and Clang
   llvm::InitializeAllTargets();
   llvm::InitializeAllAsmPrinters();


Index: llvm/lib/Support/Windows/Signals.inc
===
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -504,7 +504,10 @@
 /// process, print a stack trace and then exit.
 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
 
   if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
 Process::PreventCoreFiles();
Index: llvm/lib/Support/Unix/Signals.inc
===
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -637,7 +637,10 @@
 /// process, print a stack trace and then exit.
 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
  bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
 
   AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
 
Index: lldb/source/API/SystemInitializerFull.cpp
===
--- lldb/source/API/SystemInitializerFull.cpp
+++ lldb/source/API/SystemInitializerFull.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 
 #pragma clang diagnostic push
@@ -53,6 +54,12 @@
   if (error)
 return error;
 
+  // On Windows certain functions from Signals.h require that the global state
+  // is initialized. For LLDB driver the initialization happens in the `main`
+  // function via the `llvm::InitLLVM` helper, but for LLDB dynamic library
+  // (liblldb) that doesn't happen.
+  llvm::sys::PrintStackTraceOnErrorSignal(/*Argv0=*/{});
+
   // Initialize LLVM and Clang
   llvm::InitializeAllTargets();
   llvm::InitializeAllAsmPrinters();
___
lldb-commits mai

[Lldb-commits] [PATCH] D119009: [Support] Ensure handlers are set up before printing the stacktrace

2022-02-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 406487.
werat added a comment.

Restore accidentally removed code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119009

Files:
  lldb/source/API/SystemInitializerFull.cpp
  llvm/lib/Support/Unix/Signals.inc
  llvm/lib/Support/Windows/Signals.inc


Index: llvm/lib/Support/Windows/Signals.inc
===
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -504,6 +504,11 @@
 /// process, print a stack trace and then exit.
 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
bool DisableCrashReporting) {
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
+
   ::Argv0 = Argv0;
 
   if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
Index: llvm/lib/Support/Unix/Signals.inc
===
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -637,6 +637,11 @@
 /// process, print a stack trace and then exit.
 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
  bool DisableCrashReporting) {
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
+
   ::Argv0 = Argv0;
 
   AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
Index: lldb/source/API/SystemInitializerFull.cpp
===
--- lldb/source/API/SystemInitializerFull.cpp
+++ lldb/source/API/SystemInitializerFull.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 
 #pragma clang diagnostic push
@@ -53,6 +54,12 @@
   if (error)
 return error;
 
+  // On Windows certain functions from Signals.h require that the global state
+  // is initialized. For LLDB driver the initialization happens in the `main`
+  // function via the `llvm::InitLLVM` helper, but for LLDB dynamic library
+  // (liblldb) that doesn't happen.
+  llvm::sys::PrintStackTraceOnErrorSignal(/*Argv0=*/{});
+
   // Initialize LLVM and Clang
   llvm::InitializeAllTargets();
   llvm::InitializeAllAsmPrinters();


Index: llvm/lib/Support/Windows/Signals.inc
===
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -504,6 +504,11 @@
 /// process, print a stack trace and then exit.
 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
bool DisableCrashReporting) {
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
+
   ::Argv0 = Argv0;
 
   if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
Index: llvm/lib/Support/Unix/Signals.inc
===
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -637,6 +637,11 @@
 /// process, print a stack trace and then exit.
 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
  bool DisableCrashReporting) {
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+return;
+
   ::Argv0 = Argv0;
 
   AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
Index: lldb/source/API/SystemInitializerFull.cpp
===
--- lldb/source/API/SystemInitializerFull.cpp
+++ lldb/source/API/SystemInitializerFull.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 
 #pragma clang diagnostic push
@@ -53,6 +54,12 @@
   if (error)
 return error;
 
+  // On Windows certain functions from Signals.h require that the global state
+  // is initialized. For LLDB driver the initialization happens in the `main`
+  // function via the `llvm::InitLLVM` helper, but for LLDB dynamic library
+  // (liblldb) that doesn't happen.
+  llvm::sys::PrintStackTraceOnErrorSignal(/*Argv0=*/{});
+
   // Initialize LLVM and Clang
   llvm::InitializeAllTargets();
   llvm::InitializeAllAsmPrinters();
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.

[Lldb-commits] [PATCH] D119009: [Support] Ensure handlers are set up before printing the stacktrace

2022-02-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D119009#3302004 , @labath wrote:

> I don't think this is a good idea. I'm very much against libraries randomly 
> installing signal handlers, and I think that is the reason this function is 
> called from the main program in lldb (and elsewhere in llvm afaik). If 
> there's no way to get a backtrace without this on windows, then it'd be 
> better to disable the lldbassert functionality there.



In D119009#3302118 , @aganea wrote:

> In that case @werat can you get the caller application to call 
> `llvm::InitLLVM`? That plus the snippet in 
> https://reviews.llvm.org/D119009#3297591 should shield from crashes if the 
> handler isn't installed.

In my case the application doesn't link againt LLVM libraries, it only uses 
`liblldb.dll` (which doesn't export `llvm::InitLLVM` or 
`llvm::sys::PrintStackTraceOnErrorSignal`). 
It would be nice to have backtraces when using LLDB as a library, but I agree 
that only-main-program-install-signal-handlers policy makes a lot of sense.

I will change this patch to install a safeguard from 
https://reviews.llvm.org/D119009#3297591 then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119009

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


[Lldb-commits] [PATCH] D119009: [Support] Ensure handlers are set up before printing the stacktrace

2022-02-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D119009#3302354 , @JDevlieghere 
wrote:

> I believe it's generally considered bad practice to install signal handlers 
> in a library. This is why the initialization currently happens in the driver. 
> If you look at other tools in LLVM you'll notice they do the same thing.
>
> Can we address this issue by (1) making sure we don't crash in lldbassert 
> when calling `PrintStackTrace` without having initialized the signal handlers 
> and (2) providing the ability to install the signal handlers through the SB 
> API (if that doesn't already exist) if the user of libLLDB wants this 
> functionality?

I agree, this approach makes perfect sense to me. I've sent (1) as a separate 
patch -- https://reviews.llvm.org/D119181. Didn't want to modify this one 
further to preserve the discussion and the original commit message.
I will look into (2) a bit later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119009

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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2022-02-08 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

@JDevlieghere @shafik friendly ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2022-02-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D113498#3305973 , @shafik wrote:

> I believe this a program like this
>
>   int main() {
> int arr[2]{0};
>   
> return arr[1];
>   } 
>
> and an expression like this `expr arr[0]` will give us the constant 
> expression `getelementptr` at least my testing seems to show that.

This example produces the following code for me:

  %4 = load [2 x i32]*, [2 x i32]** %1, align 8
  %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
  store i32* %arrayidx, i32** %3, align 8
  br label %init.end

This is successfully interpreted via IRInterpreter with the current patch (i.e. 
all arguments seem to be `ConstantInt`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2022-02-09 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGafb446e8a61d: [lldb] Constant-resolve operands to 
`getelementptr` (authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

Files:
  lldb/source/Expression/IRInterpreter.cpp
  lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py


Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression 
involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org/show_bug.cgi?id=52449
+"""
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", 
lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... i64 ptrtoint (i32* @_ZN1A3s_cE to i64)) ...
+expr = "(int*)100 + (long long)(&A::s_c)"
+
+# The IR interpreter doesn't support non-const operands to the
+# `GetElementPtr` IR instruction, so verify that it correctly fails to
+# evaluate expression.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertTrue(value.GetError().Fail())
+self.assertIn(
+"Can't evaluate the expression without a running target",
+value.GetError().GetCString())
+
+# Evaluating the expression via JIT should work fine.
+value = self.target().EvaluateExpression(expr)
+self.assertSuccess(value.GetError())
Index: lldb/source/Expression/IRInterpreter.cpp
===
--- lldb/source/Expression/IRInterpreter.cpp
+++ lldb/source/Expression/IRInterpreter.cpp
@@ -285,9 +285,11 @@
 return true; // no offset to apply!
 
   SmallVector indices(op_cursor, op_end);
-
   Type *src_elem_ty =
   cast(constant_expr)->getSourceElementType();
+
+  // DataLayout::getIndexedOffsetInType assumes the indices are
+  // instances of ConstantInt.
   uint64_t offset =
   m_target_data.getIndexedOffsetInType(src_elem_ty, indices);
 
@@ -466,12 +468,20 @@
   case Instruction::BitCast:
 return CanResolveConstant(constant_expr->getOperand(0));
   case Instruction::GetElementPtr: {
+// Check that the base can be constant-resolved.
 ConstantExpr::const_op_iterator op_cursor = constant_expr->op_begin();
 Constant *base = dyn_cast(*op_cursor);
-if (!base)
+if (!base || !CanResolveConstant(base))
   return false;
 
-return CanResolveConstant(base);
+// Check that all other operands are just ConstantInt.
+for (Value *op : make_range(constant_expr->op_begin() + 1,
+constant_expr->op_end())) {
+  ConstantInt *constant_int = dyn_cast(op);
+  if (!constant_int)
+return false;
+}
+return true;
   }
   }
 } else {


Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org/show_bug.cgi?id=52449
+"""
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... i64 ptrtoint (i32* @_ZN1A3s_cE to i64)) ...
+expr = "(int*)100 + (long long)(&A::s_c)"
+
+# The IR interpreter doesn't support non-const operands to the
+# `GetElementPtr` IR instruction, so verify that it correctly fails to
+# evaluate expression.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, 

[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2022-02-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D113498#3308499 , 
@stella.stamenova wrote:

> It looks like the new test is failing on the Windows bot:
>
> https://lab.llvm.org/buildbot/#/builders/83/builds/15049

Whoops, static lookup seem to be broken on Windows (other tests in this file 
skip Windows altogether). I've disabled this test in 
https://github.com/llvm/llvm-project/commit/e0f2375b5262d0dd778ecaf0628f905d241da733
 for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2022-02-11 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D113498#3314729 , @shafik wrote:

> I was hoping you would add a positive test as well like the one I came up 
> with that covered the new code as well.

Oh, whoops, sorry, I don’t know how I missed your point :)
I will add a test, thanks for a code sample!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D119734: [lldb] Add a positive test for `getelementptr` constant args

2022-02-14 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat added a reviewer: shafik.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The IR interpreter supports const operands to the `GetElementPtr` IR
instruction, so it should be able to evaluate expression without JIT.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119734

Files:
  lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
  lldb/test/API/lang/cpp/static_members/main.cpp


Index: lldb/test/API/lang/cpp/static_members/main.cpp
===
--- lldb/test/API/lang/cpp/static_members/main.cpp
+++ lldb/test/API/lang/cpp/static_members/main.cpp
@@ -15,6 +15,8 @@
   A my_a;
   my_a.m_a = 1;
 
+  int arr[2]{0};
+
   my_a.access(); // stop in main
   return 0;
 }
Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -71,3 +71,20 @@
 # Evaluating the expression via JIT should work fine.
 value = self.target().EvaluateExpression(expr)
 self.assertSuccess(value.GetError())
+
+# We fail to lookup static members on Windows.
+@expectedFailureAll(oslist=["windows"])
+def test_IR_interpreter_can_handle_getelementptr_constants_args(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", 
lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
+expr = "arr[0]"
+
+# The IR interpreter supports const operands to the `GetElementPtr` IR
+# instruction, so it should be able to evaluate expression without JIT.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertSuccess(value.GetError())


Index: lldb/test/API/lang/cpp/static_members/main.cpp
===
--- lldb/test/API/lang/cpp/static_members/main.cpp
+++ lldb/test/API/lang/cpp/static_members/main.cpp
@@ -15,6 +15,8 @@
   A my_a;
   my_a.m_a = 1;
 
+  int arr[2]{0};
+
   my_a.access(); // stop in main
   return 0;
 }
Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -71,3 +71,20 @@
 # Evaluating the expression via JIT should work fine.
 value = self.target().EvaluateExpression(expr)
 self.assertSuccess(value.GetError())
+
+# We fail to lookup static members on Windows.
+@expectedFailureAll(oslist=["windows"])
+def test_IR_interpreter_can_handle_getelementptr_constants_args(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
+expr = "arr[0]"
+
+# The IR interpreter supports const operands to the `GetElementPtr` IR
+# instruction, so it should be able to evaluate expression without JIT.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertSuccess(value.GetError())
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D119734: [lldb] Add a positive test for `getelementptr` constant args

2022-02-14 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e0ef179d883: [lldb] Add a positive test for `getelementptr` 
constant args (authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119734

Files:
  lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
  lldb/test/API/lang/cpp/static_members/main.cpp


Index: lldb/test/API/lang/cpp/static_members/main.cpp
===
--- lldb/test/API/lang/cpp/static_members/main.cpp
+++ lldb/test/API/lang/cpp/static_members/main.cpp
@@ -15,6 +15,8 @@
   A my_a;
   my_a.m_a = 1;
 
+  int arr[2]{0};
+
   my_a.access(); // stop in main
   return 0;
 }
Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -71,3 +71,20 @@
 # Evaluating the expression via JIT should work fine.
 value = self.target().EvaluateExpression(expr)
 self.assertSuccess(value.GetError())
+
+# We fail to lookup static members on Windows.
+@expectedFailureAll(oslist=["windows"])
+def test_IR_interpreter_can_handle_getelementptr_constants_args(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", 
lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
+expr = "arr[0]"
+
+# The IR interpreter supports const operands to the `GetElementPtr` IR
+# instruction, so it should be able to evaluate expression without JIT.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertSuccess(value.GetError())


Index: lldb/test/API/lang/cpp/static_members/main.cpp
===
--- lldb/test/API/lang/cpp/static_members/main.cpp
+++ lldb/test/API/lang/cpp/static_members/main.cpp
@@ -15,6 +15,8 @@
   A my_a;
   my_a.m_a = 1;
 
+  int arr[2]{0};
+
   my_a.access(); // stop in main
   return 0;
 }
Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -71,3 +71,20 @@
 # Evaluating the expression via JIT should work fine.
 value = self.target().EvaluateExpression(expr)
 self.assertSuccess(value.GetError())
+
+# We fail to lookup static members on Windows.
+@expectedFailureAll(oslist=["windows"])
+def test_IR_interpreter_can_handle_getelementptr_constants_args(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
+expr = "arr[0]"
+
+# The IR interpreter supports const operands to the `GetElementPtr` IR
+# instruction, so it should be able to evaluate expression without JIT.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertSuccess(value.GetError())
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-04 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 442126.
werat added a comment.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

- Rebase on latest HEAD
- Address review comments
- Add a check for field being integer/enum


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81471

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/test/API/lang/cpp/const_static_integral_member/Makefile
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
  lldb/test/API/lang/cpp/const_static_integral_member_int128/Makefile
  
lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
  lldb/test/API/lang/cpp/const_static_integral_member_int128/main.cpp
  lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
  lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
@@ -273,3 +273,128 @@
   };
   ASSERT_EQ(found_function_types, expected_function_types);
 }
+
+struct ExtractIntFromFormValueTest : public testing::Test {
+  SubsystemRAII subsystems;
+  TypeSystemClang ts;
+  DWARFASTParserClang parser;
+  ExtractIntFromFormValueTest()
+  : ts("dummy ASTContext", HostInfoBase::GetTargetTriple()), parser(ts) {}
+
+  /// Takes the given integer value, stores it in a DWARFFormValue and then
+  /// tries to extract the value back via
+  /// DWARFASTParserClang::ExtractIntFromFormValue.
+  /// Returns the string representation of the extracted value or the error
+  /// that was returned from ExtractIntFromFormValue.
+  llvm::Expected Extract(clang::QualType qt, uint64_t value) {
+DWARFFormValue form_value;
+form_value.SetUnsigned(value);
+llvm::Expected result =
+parser.ExtractIntFromFormValue(ts.GetType(qt), form_value);
+if (!result)
+  return result.takeError();
+llvm::SmallString<16> result_str;
+result->toStringUnsigned(result_str);
+return std::string(result_str.str());
+  }
+
+  /// Same as ExtractIntFromFormValueTest::Extract but takes a signed integer
+  /// and treats the result as a signed integer.
+  llvm::Expected ExtractS(clang::QualType qt, int64_t value) {
+DWARFFormValue form_value;
+form_value.SetSigned(value);
+llvm::Expected result =
+parser.ExtractIntFromFormValue(ts.GetType(qt), form_value);
+if (!result)
+  return result.takeError();
+llvm::SmallString<16> result_str;
+result->toStringSigned(result_str);
+return std::string(result_str.str());
+  }
+};
+
+TEST_F(ExtractIntFromFormValueTest, TestBool) {
+  using namespace llvm;
+  clang::ASTContext &ast = ts.getASTContext();
+
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 0), HasValue("0"));
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 1), HasValue("1"));
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 2), Failed());
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 3), Failed());
+}
+
+TEST_F(ExtractIntFromFormValueTest, TestInt) {
+  using namespace llvm;
+
+  clang::ASTContext &ast = ts.getASTContext();
+
+  // Find the min/max values for 'int' on the current host target.
+  constexpr int64_t int_max = std::numeric_limits::max();
+  constexpr int64_t int_min = std::numeric_limits::min();
+
+  // Check that the bit width of int matches the int width in our type system.
+  ASSERT_EQ(sizeof(int) * 8, ast.getIntWidth(ast.IntTy));
+
+  // Check values around int_min.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min - 2), llvm::Failed());
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min - 1), llvm::Failed());
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min),
+   HasValue(std::to_string(int_min)));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min + 1),
+   HasValue(std::to_string(int_min + 1)));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min + 2),
+   HasValue(std::to_string(int_min + 2)));
+
+  // Check values around 0.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -128), HasValue("-128"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -10), HasValue("-10"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -1), HasValue("-1"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 0), HasValue("0"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 1), HasValue("1"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 10), HasValue("10"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 128), HasValue("128"));
+
+  // Check values around int_max.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_max - 2),
+

[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-04 Thread Andy Yankovsky via Phabricator via lldb-commits
werat marked an inline comment as done.
werat added a comment.

Reviving the patch and taking over.

@jankratochvil @shafik @labath can you please take another look? Thanks!




Comment at: lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp:172
+  // Find the min/max values for 'int' on the current host target.
+  const int64_t int_max = std::numeric_limits::max();
+  const int64_t int_min = std::numeric_limits::min();

shafik wrote:
> shafik wrote:
> > Why not use `int32_t` although this should never affect us `int` can be `64 
> > bit`, so `int32_t` is a better reflection of your intent.
> You can also use `constexpr` here since `numeric_limits` methods are all 
> `constexpr` as well.
The tests verify whether the value fits into the type, so the value itself 
needs to be large to fit things that can't be represented in int32

For example, this will pass if `int_min` is `int32_t`:
```
EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min - 2), llvm::Failed());
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81471

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


[Lldb-commits] [PATCH] D129327: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
Herald added a subscriber: mgorny.
Herald added a reviewer: shafik.
Herald added a project: All.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This adds support for using const static integral data members as described by 
C++11 [class.static.data]p3
to LLDB's expression evaluator.

So far LLDB treated these data members are normal static variables. They 
already work as intended when they are declared in the class definition and 
then defined in a namespace scope. However, if they are declared and 
initialised in the class definition but never defined in a namespace scope, all 
LLDB expressions that use them will fail to link when LLDB can't find the 
respective symbol for the variable.

The reason for this is that the data members which are only declared in the 
class are not emitted into any object file so LLDB can never resolve them. 
Expressions that use these variables are expected to directly use their 
constant value if possible. Clang can do this for us during codegen, but it 
requires that we add the constant value to the VarDecl we generate for these 
data members.

This patch implements this by:

- parsing the constant values from the debug info and adding it to variable 
declarations we encounter.
- ensuring that LLDB doesn't implicitly try to take the address of expressions 
that might be an lvalue that points to such a special data member.

The second change is caused by LLDB's way of storing lvalues in the expression 
parser. When LLDB parses an expression, it tries to keep the result around via 
two mechanisms:

1. For lvalues, LLDB generates a static pointer variable and stores the address 
of the last expression in it: `T *$__lldb_expr_result_ptr = &LastExpression`
2. For everything else, LLDB generates a static variable of the same type as 
the last expression and then direct initialises that variable: `T 
$__lldb_expr_result(LastExpression)`

If we try to print a special const static data member via something like `expr 
Class::Member`, then LLDB will try to take the address of this expression as 
it's an lvalue. This means LLDB will try to take the address of the variable 
which causes that Clang can't replace the use with the constant value. There 
isn't any good way to detect this case (as there a lot of different expressions 
that could yield an lvalue that points to such a data member), so this patch 
also changes that we only use the first way of capturing the result if the last 
expression does not have a type that could potentially indicate it's coming 
from such a special data member.

This change shouldn't break most workflows for users. The only observable side 
effect I could find is that the implicit persistent result variables for const 
int's now have their own memory address:

Before this change:

  (lldb) p i
  (const int) $0 = 123
  (lldb) p &$0
  (const int *) $1 = 0x7ffeefbff8e8
  (lldb) p &i
  (const int *) $2 = 0x7ffeefbff8e8

After this change we capture `i` by value so it has its own value.

  (lldb) p i
  (const int) $0 = 123
  (lldb) p &$0
  (const int *) $1 = 0x000100155320
  (lldb) p &i
  (const int *) $2 = 0x7ffeefbff8e8

Co-authored-by: Raphael Isemann 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129327

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/test/API/lang/cpp/const_static_integral_member/Makefile
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
  lldb/test/API/lang/cpp/const_static_integral_member_int128/Makefile
  
lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
  lldb/test/API/lang/cpp/const_static_integral_member_int128/main.cpp
  lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
  lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
@@ -273,3 +273,128 @@
   };
   ASSERT_EQ(found_function_types, expected_function_types);
 }
+
+struct ExtractIntFromFormValueTest : public testing::Test {
+  SubsystemRAII subsystems;
+  TypeSystemClang ts;
+  DWARFASTParserClang parser;
+  ExtractIntFromFormValueTest()
+  : ts("dummy ASTContext", HostInfoBase::GetTargetTriple()), parser(ts) {}
+
+  /// Takes the given integer value, stores it in a DWARFFormValue and then
+  /// tries to extract the value back via
+  /// DWARFASTParserClang::ExtractIntFromFormValue.
+  /// Returns the string representation of the extracted value or the error
+  /// that w

[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat marked 6 inline comments as done.
werat added a comment.

In D81471#3632297 , @labath wrote:

> I guess the condition we really want to express here is "does this expression 
> refer to a constexpr variable (ideally one without a location)"? And the 
> problem is that clang does not give us the means to detect that?
>
> Is that really the case? Would it maybe be possible to use some c++ magic to 
> get clang to do that for us. Write something like `if constexpr 
> (__builtin_constant_p(user_expression)) do_something_rvalue_like(); else 
> assume_regular_lvalue();` ?

I think you're right here, but I don't know a better way to express this. My 
clangfu is not good enough for this yet :)

As I understand it, we can't express it purely in the expression (via 
`__builtin_constant_p` or something), because we need to know the answer before 
executing the expression (it changes the way we do 
materialization/dematerialization).

Could this be something to improve in the future?




Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2689
+  // TODO: Support float/double static members as well.
+  if (!attrs.const_value_form && !ct.IsIntegerOrEnumerationType(unused))
+return;

Michael137 wrote:
> Should this be:
> 
> ```
> if (!attrs.const_value_form || !ct.IsIntegerOrEnumerationType(unused))
> ```
> ?
Whoops, yes, thanks!



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2696
+   "Failed to add const value to variable {1}: {0}",
+   v->getQualifiedNameAsString());
+return;

Michael137 wrote:
> Can `v` be `nullptr` here?
Honestly, not sure. Theoretically `AddVariableToRecordType` can return 
`nullptr`, but I've never seen such case. Maybe it only happens when the debug 
info is malformed? Would that be caught earlier at some stage?
I can add a safe guard here with a log message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81471

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


[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 443051.
werat marked 2 inline comments as done.
werat added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81471

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/test/API/lang/cpp/const_static_integral_member/Makefile
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
  lldb/test/API/lang/cpp/const_static_integral_member_int128/Makefile
  
lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
  lldb/test/API/lang/cpp/const_static_integral_member_int128/main.cpp
  lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
  lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
@@ -273,3 +273,128 @@
   };
   ASSERT_EQ(found_function_types, expected_function_types);
 }
+
+struct ExtractIntFromFormValueTest : public testing::Test {
+  SubsystemRAII subsystems;
+  TypeSystemClang ts;
+  DWARFASTParserClang parser;
+  ExtractIntFromFormValueTest()
+  : ts("dummy ASTContext", HostInfoBase::GetTargetTriple()), parser(ts) {}
+
+  /// Takes the given integer value, stores it in a DWARFFormValue and then
+  /// tries to extract the value back via
+  /// DWARFASTParserClang::ExtractIntFromFormValue.
+  /// Returns the string representation of the extracted value or the error
+  /// that was returned from ExtractIntFromFormValue.
+  llvm::Expected Extract(clang::QualType qt, uint64_t value) {
+DWARFFormValue form_value;
+form_value.SetUnsigned(value);
+llvm::Expected result =
+parser.ExtractIntFromFormValue(ts.GetType(qt), form_value);
+if (!result)
+  return result.takeError();
+llvm::SmallString<16> result_str;
+result->toStringUnsigned(result_str);
+return std::string(result_str.str());
+  }
+
+  /// Same as ExtractIntFromFormValueTest::Extract but takes a signed integer
+  /// and treats the result as a signed integer.
+  llvm::Expected ExtractS(clang::QualType qt, int64_t value) {
+DWARFFormValue form_value;
+form_value.SetSigned(value);
+llvm::Expected result =
+parser.ExtractIntFromFormValue(ts.GetType(qt), form_value);
+if (!result)
+  return result.takeError();
+llvm::SmallString<16> result_str;
+result->toStringSigned(result_str);
+return std::string(result_str.str());
+  }
+};
+
+TEST_F(ExtractIntFromFormValueTest, TestBool) {
+  using namespace llvm;
+  clang::ASTContext &ast = ts.getASTContext();
+
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 0), HasValue("0"));
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 1), HasValue("1"));
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 2), Failed());
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 3), Failed());
+}
+
+TEST_F(ExtractIntFromFormValueTest, TestInt) {
+  using namespace llvm;
+
+  clang::ASTContext &ast = ts.getASTContext();
+
+  // Find the min/max values for 'int' on the current host target.
+  constexpr int64_t int_max = std::numeric_limits::max();
+  constexpr int64_t int_min = std::numeric_limits::min();
+
+  // Check that the bit width of int matches the int width in our type system.
+  ASSERT_EQ(sizeof(int) * 8, ast.getIntWidth(ast.IntTy));
+
+  // Check values around int_min.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min - 2), llvm::Failed());
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min - 1), llvm::Failed());
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min),
+   HasValue(std::to_string(int_min)));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min + 1),
+   HasValue(std::to_string(int_min + 1)));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min + 2),
+   HasValue(std::to_string(int_min + 2)));
+
+  // Check values around 0.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -128), HasValue("-128"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -10), HasValue("-10"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -1), HasValue("-1"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 0), HasValue("0"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 1), HasValue("1"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 10), HasValue("10"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 128), HasValue("128"));
+
+  // Check values around int_max.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_max - 2),
+   HasValue(std::to_string(int_max - 2)));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_m

[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 443052.
werat added a comment.

Fix condition


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81471

Files:
  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
@@ -2690,7 +2690,7 @@
 
   bool unused;
   // TODO: Support float/double static members as well.
-  if (!attrs.const_value_form && !ct.IsIntegerOrEnumerationType(unused))
+  if (!attrs.const_value_form || !ct.IsIntegerOrEnumerationType(unused))
 return;
   llvm::Expected const_value_or_err =
   ExtractIntFromFormValue(ct, *attrs.const_value_form);


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2690,7 +2690,7 @@
 
   bool unused;
   // TODO: Support float/double static members as well.
-  if (!attrs.const_value_form && !ct.IsIntegerOrEnumerationType(unused))
+  if (!attrs.const_value_form || !ct.IsIntegerOrEnumerationType(unused))
 return;
   llvm::Expected const_value_or_err =
   ExtractIntFromFormValue(ct, *attrs.const_value_form);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-07 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 443053.
werat added a comment.

Fix condition


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81471

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/test/API/lang/cpp/const_static_integral_member/Makefile
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
  lldb/test/API/lang/cpp/const_static_integral_member_int128/Makefile
  
lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
  lldb/test/API/lang/cpp/const_static_integral_member_int128/main.cpp
  lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
  lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
@@ -273,3 +273,128 @@
   };
   ASSERT_EQ(found_function_types, expected_function_types);
 }
+
+struct ExtractIntFromFormValueTest : public testing::Test {
+  SubsystemRAII subsystems;
+  TypeSystemClang ts;
+  DWARFASTParserClang parser;
+  ExtractIntFromFormValueTest()
+  : ts("dummy ASTContext", HostInfoBase::GetTargetTriple()), parser(ts) {}
+
+  /// Takes the given integer value, stores it in a DWARFFormValue and then
+  /// tries to extract the value back via
+  /// DWARFASTParserClang::ExtractIntFromFormValue.
+  /// Returns the string representation of the extracted value or the error
+  /// that was returned from ExtractIntFromFormValue.
+  llvm::Expected Extract(clang::QualType qt, uint64_t value) {
+DWARFFormValue form_value;
+form_value.SetUnsigned(value);
+llvm::Expected result =
+parser.ExtractIntFromFormValue(ts.GetType(qt), form_value);
+if (!result)
+  return result.takeError();
+llvm::SmallString<16> result_str;
+result->toStringUnsigned(result_str);
+return std::string(result_str.str());
+  }
+
+  /// Same as ExtractIntFromFormValueTest::Extract but takes a signed integer
+  /// and treats the result as a signed integer.
+  llvm::Expected ExtractS(clang::QualType qt, int64_t value) {
+DWARFFormValue form_value;
+form_value.SetSigned(value);
+llvm::Expected result =
+parser.ExtractIntFromFormValue(ts.GetType(qt), form_value);
+if (!result)
+  return result.takeError();
+llvm::SmallString<16> result_str;
+result->toStringSigned(result_str);
+return std::string(result_str.str());
+  }
+};
+
+TEST_F(ExtractIntFromFormValueTest, TestBool) {
+  using namespace llvm;
+  clang::ASTContext &ast = ts.getASTContext();
+
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 0), HasValue("0"));
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 1), HasValue("1"));
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 2), Failed());
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 3), Failed());
+}
+
+TEST_F(ExtractIntFromFormValueTest, TestInt) {
+  using namespace llvm;
+
+  clang::ASTContext &ast = ts.getASTContext();
+
+  // Find the min/max values for 'int' on the current host target.
+  constexpr int64_t int_max = std::numeric_limits::max();
+  constexpr int64_t int_min = std::numeric_limits::min();
+
+  // Check that the bit width of int matches the int width in our type system.
+  ASSERT_EQ(sizeof(int) * 8, ast.getIntWidth(ast.IntTy));
+
+  // Check values around int_min.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min - 2), llvm::Failed());
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min - 1), llvm::Failed());
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min),
+   HasValue(std::to_string(int_min)));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min + 1),
+   HasValue(std::to_string(int_min + 1)));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min + 2),
+   HasValue(std::to_string(int_min + 2)));
+
+  // Check values around 0.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -128), HasValue("-128"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -10), HasValue("-10"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -1), HasValue("-1"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 0), HasValue("0"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 1), HasValue("1"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 10), HasValue("10"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 128), HasValue("128"));
+
+  // Check values around int_max.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_max - 2),
+   HasValue(std::to_string(int_max - 2)));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_max - 1),
+   HasValue(std::to_

[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-14 Thread Andy Yankovsky via Phabricator via lldb-commits
werat edited reviewers, added: Michael137; removed: jarin.
werat added a comment.

In D81471#3641915 , @labath wrote:

> So, if noone objects to this, then I think it's fine.

I guess nobody objects :)

@labath, @Michael137, can you accept/LGTM the revision?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81471

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


[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-14 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG486787210df5: [lldb] Add support for using integral const 
static data members in the… (authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81471

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/test/API/lang/cpp/const_static_integral_member/Makefile
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
  lldb/test/API/lang/cpp/const_static_integral_member_int128/Makefile
  
lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
  lldb/test/API/lang/cpp/const_static_integral_member_int128/main.cpp
  lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
  lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
@@ -273,3 +273,128 @@
   };
   ASSERT_EQ(found_function_types, expected_function_types);
 }
+
+struct ExtractIntFromFormValueTest : public testing::Test {
+  SubsystemRAII subsystems;
+  TypeSystemClang ts;
+  DWARFASTParserClang parser;
+  ExtractIntFromFormValueTest()
+  : ts("dummy ASTContext", HostInfoBase::GetTargetTriple()), parser(ts) {}
+
+  /// Takes the given integer value, stores it in a DWARFFormValue and then
+  /// tries to extract the value back via
+  /// DWARFASTParserClang::ExtractIntFromFormValue.
+  /// Returns the string representation of the extracted value or the error
+  /// that was returned from ExtractIntFromFormValue.
+  llvm::Expected Extract(clang::QualType qt, uint64_t value) {
+DWARFFormValue form_value;
+form_value.SetUnsigned(value);
+llvm::Expected result =
+parser.ExtractIntFromFormValue(ts.GetType(qt), form_value);
+if (!result)
+  return result.takeError();
+llvm::SmallString<16> result_str;
+result->toStringUnsigned(result_str);
+return std::string(result_str.str());
+  }
+
+  /// Same as ExtractIntFromFormValueTest::Extract but takes a signed integer
+  /// and treats the result as a signed integer.
+  llvm::Expected ExtractS(clang::QualType qt, int64_t value) {
+DWARFFormValue form_value;
+form_value.SetSigned(value);
+llvm::Expected result =
+parser.ExtractIntFromFormValue(ts.GetType(qt), form_value);
+if (!result)
+  return result.takeError();
+llvm::SmallString<16> result_str;
+result->toStringSigned(result_str);
+return std::string(result_str.str());
+  }
+};
+
+TEST_F(ExtractIntFromFormValueTest, TestBool) {
+  using namespace llvm;
+  clang::ASTContext &ast = ts.getASTContext();
+
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 0), HasValue("0"));
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 1), HasValue("1"));
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 2), Failed());
+  EXPECT_THAT_EXPECTED(Extract(ast.BoolTy, 3), Failed());
+}
+
+TEST_F(ExtractIntFromFormValueTest, TestInt) {
+  using namespace llvm;
+
+  clang::ASTContext &ast = ts.getASTContext();
+
+  // Find the min/max values for 'int' on the current host target.
+  constexpr int64_t int_max = std::numeric_limits::max();
+  constexpr int64_t int_min = std::numeric_limits::min();
+
+  // Check that the bit width of int matches the int width in our type system.
+  ASSERT_EQ(sizeof(int) * 8, ast.getIntWidth(ast.IntTy));
+
+  // Check values around int_min.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min - 2), llvm::Failed());
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min - 1), llvm::Failed());
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min),
+   HasValue(std::to_string(int_min)));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min + 1),
+   HasValue(std::to_string(int_min + 1)));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_min + 2),
+   HasValue(std::to_string(int_min + 2)));
+
+  // Check values around 0.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -128), HasValue("-128"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -10), HasValue("-10"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, -1), HasValue("-1"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 0), HasValue("0"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 1), HasValue("1"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 10), HasValue("10"));
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, 128), HasValue("128"));
+
+  // Check values around int_max.
+  EXPECT_THAT_EXPECTED(ExtractS(ast.IntTy, int_max - 2),
+   HasValue(std::to_stri

[Lldb-commits] [PATCH] D129783: [lldb] Skip tests using int128 on ARM

2022-07-14 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat added a reviewer: Michael137.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Follow-up fix for https://reviews.llvm.org/D81471.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129783

Files:
  
lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py


Index: 
lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
@@ -12,6 +12,8 @@
 
 mydir = TestBase.compute_mydir(__file__)
 
+# uint128_t not available on arm.
+@skipIf(archs=["arm", "aarch64"])
 def test_int128(self):
 self.build()
 lldbutil.run_to_source_breakpoint(self, "// break here",


Index: lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
+++ lldb/test/API/lang/cpp/const_static_integral_member_int128/TestConstStaticIntegralMemberInt128.py
@@ -12,6 +12,8 @@
 
 mydir = TestBase.compute_mydir(__file__)
 
+# uint128_t not available on arm.
+@skipIf(archs=["arm", "aarch64"])
 def test_int128(self):
 self.build()
 lldbutil.run_to_source_breakpoint(self, "// break here",
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D129783: [lldb] Skip tests using int128 on ARM

2022-07-15 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

I didn't see the test failure on AArch64, so you're both probably right. I've 
searched the code for other uses of int128 and found a similar place, which 
disabled the test for both 32-bit and 64-bit -- 
https://github.com/llvm/llvm-project/blob/30c2406e270cc5dab8da813ce5c54e4bb8c40e49/lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py#L25

I'll fix the patch and skip the test only for 32-bit ARM. Thank you the 
explanation!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129783

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


[Lldb-commits] [PATCH] D129783: [lldb] Skip tests using int128 on ARM

2022-07-15 Thread Andy Yankovsky via Phabricator via lldb-commits
werat abandoned this revision.
werat added a comment.

I have relanded the patch with the fixed tests here -- 
https://github.com/llvm/llvm-project/commit/7d297de95117e783bbfaecbba1f72fc55de05a30


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129783

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


[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-15 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

Relanded in 
https://github.com/llvm/llvm-project/commit/7d297de95117e783bbfaecbba1f72fc55de05a30


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81471

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


[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix initialization of static enum alias members

2022-07-21 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

I've tried reproducing the test case with `lldb` built from HEAD on my Linux 
machine and it seems to work without your patch:

  ❯ cat ~/src/cpp/const.cc 
  enum class ScopedEnum {
scoped_enum_case1 = 1,
scoped_enum_case2 = 2,
  };
  
  struct A {
using EnumAlias = ScopedEnum;
static constexpr EnumAlias e = ScopedEnum::scoped_enum_case2;
  };
  
  int main() {
  auto enum_alias_val = A::e;
  }
  
  ❯ bin/lldb ~/src/cpp/a.out
  (lldb) target create "/home/werat/src/cpp/a.out"
  Current executable set to '/home/werat/src/cpp/a.out' (x86_64).
  (lldb) b main
  Breakpoint 1: where = a.out`main + 4 at const.cc:12:10, address = 
0x00401114
  (lldb) r
  Process 2767509 launched: '/home/werat/src/cpp/a.out' (x86_64)
  Process 2767509 stopped
  * thread #1, name = 'a.out', stop reason = breakpoint 1.1
  frame #0: 0x00401114 a.out`main at const.cc:12:10
 9};
 10  
 11   int main() {
  -> 12   auto enum_alias_val = A::e;
 13   }
  (lldb) p A::e
  (const A::EnumAlias) $0 = scoped_enum_case2

Maybe the test case doesn't actually hit the problem you're trying to address?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130213

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


[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix initialization of static enum alias members

2022-07-21 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D130213#3668450 , @aprantl wrote:

> @werat did you build with assertions enabled?

Oh, no, I build in `RelWithDebInfo` out of habit. I've tried with assertions 
and then it fails.

However, when ignoring the asserts the result is correct, which makes me wonder 
whether the assert check is 100% correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130213

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


[Lldb-commits] [PATCH] D130285: [lldb] Handle jumping to the end in DW_OP_skip/DW_OP_bra

2022-07-21 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat added reviewers: labath, jingham, jasonmolenda.
Herald added a project: All.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

DW_OP_skip/DW_OP_bra can move offset to the end of the data, which means that 
this was the last instruction to execute and the interpreter should terminate.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130285

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


Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -131,6 +131,25 @@
   llvm::HasValue(0x010101010101));
 }
 
+TEST(DWARFExpression, DW_OP_skip) {
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const1u, 0x42, DW_OP_skip, 0x02, 0x00,
+ DW_OP_const1u, 0xff}),
+   llvm::HasValue(0x42));
+}
+
+TEST(DWARFExpression, DW_OP_bra) {
+  EXPECT_THAT_EXPECTED(
+  // clang-format off
+  Evaluate({
+DW_OP_const1u, 0x42, // push 0x42
+DW_OP_const1u, 0x1,  // push 0x1
+DW_OP_bra, 0x02, 0x00,   // if 0x1 > 0, then skip 0x0002 opcodes
+DW_OP_const1u, 0xff, // push 0xff
+  }),
+  // clang-format on
+  llvm::HasValue(0x42));
+}
+
 TEST(DWARFExpression, DW_OP_convert) {
   /// Auxiliary debug info.
   const char *yamldata = R"(
Index: lldb/source/Expression/DWARFExpression.cpp
===
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -1655,11 +1655,16 @@
 case DW_OP_skip: {
   int16_t skip_offset = (int16_t)opcodes.GetU16(&offset);
   lldb::offset_t new_offset = offset + skip_offset;
-  if (opcodes.ValidOffset(new_offset))
+  // New offset can point at the end of the data, in this case we should
+  // terminate the DWARF expression evaluation (will happen in the loop
+  // condition).
+  if (new_offset <= opcodes.GetByteSize())
 offset = new_offset;
   else {
 if (error_ptr)
-  error_ptr->SetErrorString("Invalid opcode offset in DW_OP_skip.");
+  error_ptr->SetErrorStringWithFormatv(
+  "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}", offset,
+  skip_offset, opcodes.GetByteSize());
 return false;
   }
 } break;
@@ -1684,11 +1689,16 @@
 Scalar zero(0);
 if (tmp.ResolveValue(exe_ctx) != zero) {
   lldb::offset_t new_offset = offset + bra_offset;
-  if (opcodes.ValidOffset(new_offset))
+  // New offset can point at the end of the data, in this case we 
should
+  // terminate the DWARF expression evaluation (will happen in the loop
+  // condition).
+  if (new_offset <= opcodes.GetByteSize())
 offset = new_offset;
   else {
 if (error_ptr)
-  error_ptr->SetErrorString("Invalid opcode offset in DW_OP_bra.");
+  error_ptr->SetErrorStringWithFormatv(
+  "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}", 
offset,
+  bra_offset, opcodes.GetByteSize());
 return false;
   }
 }


Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -131,6 +131,25 @@
   llvm::HasValue(0x010101010101));
 }
 
+TEST(DWARFExpression, DW_OP_skip) {
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const1u, 0x42, DW_OP_skip, 0x02, 0x00,
+ DW_OP_const1u, 0xff}),
+   llvm::HasValue(0x42));
+}
+
+TEST(DWARFExpression, DW_OP_bra) {
+  EXPECT_THAT_EXPECTED(
+  // clang-format off
+  Evaluate({
+DW_OP_const1u, 0x42, // push 0x42
+DW_OP_const1u, 0x1,  // push 0x1
+DW_OP_bra, 0x02, 0x00,   // if 0x1 > 0, then skip 0x0002 opcodes
+DW_OP_const1u, 0xff, // push 0xff
+  }),
+  // clang-format on
+  llvm::HasValue(0x42));
+}
+
 TEST(DWARFExpression, DW_OP_convert) {
   /// Auxiliary debug info.
   const char *yamldata = R"(
Index: lldb/source/Expression/DWARFExpression.cpp
===
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -1655,11 +1655,16 @@
 case DW_OP_skip: {
   int16_t skip_offset = (int16_t)opcodes.GetU16(&offset);
   lldb::offset_t new_offset = offset + skip_offset;
-  if (opcodes.ValidOffset(new_offset))
+  // New offset can point at the end of the data, in this case we should
+  // terminate 

[Lldb-commits] [PATCH] D130285: [lldb] Handle jumping to the end in DW_OP_skip/DW_OP_bra

2022-07-22 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5c39c31a9952: [lldb] Handle jumping to the end in 
DW_OP_skip/DW_OP_bra (authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130285

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


Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -131,6 +131,25 @@
   llvm::HasValue(0x010101010101));
 }
 
+TEST(DWARFExpression, DW_OP_skip) {
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const1u, 0x42, DW_OP_skip, 0x02, 0x00,
+ DW_OP_const1u, 0xff}),
+   llvm::HasValue(0x42));
+}
+
+TEST(DWARFExpression, DW_OP_bra) {
+  EXPECT_THAT_EXPECTED(
+  // clang-format off
+  Evaluate({
+DW_OP_const1u, 0x42, // push 0x42
+DW_OP_const1u, 0x1,  // push 0x1
+DW_OP_bra, 0x02, 0x00,   // if 0x1 > 0, then skip 0x0002 opcodes
+DW_OP_const1u, 0xff, // push 0xff
+  }),
+  // clang-format on
+  llvm::HasValue(0x42));
+}
+
 TEST(DWARFExpression, DW_OP_convert) {
   /// Auxiliary debug info.
   const char *yamldata = R"(
Index: lldb/source/Expression/DWARFExpression.cpp
===
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -1655,11 +1655,16 @@
 case DW_OP_skip: {
   int16_t skip_offset = (int16_t)opcodes.GetU16(&offset);
   lldb::offset_t new_offset = offset + skip_offset;
-  if (opcodes.ValidOffset(new_offset))
+  // New offset can point at the end of the data, in this case we should
+  // terminate the DWARF expression evaluation (will happen in the loop
+  // condition).
+  if (new_offset <= opcodes.GetByteSize())
 offset = new_offset;
   else {
 if (error_ptr)
-  error_ptr->SetErrorString("Invalid opcode offset in DW_OP_skip.");
+  error_ptr->SetErrorStringWithFormatv(
+  "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}", offset,
+  skip_offset, opcodes.GetByteSize());
 return false;
   }
 } break;
@@ -1684,11 +1689,16 @@
 Scalar zero(0);
 if (tmp.ResolveValue(exe_ctx) != zero) {
   lldb::offset_t new_offset = offset + bra_offset;
-  if (opcodes.ValidOffset(new_offset))
+  // New offset can point at the end of the data, in this case we 
should
+  // terminate the DWARF expression evaluation (will happen in the loop
+  // condition).
+  if (new_offset <= opcodes.GetByteSize())
 offset = new_offset;
   else {
 if (error_ptr)
-  error_ptr->SetErrorString("Invalid opcode offset in DW_OP_bra.");
+  error_ptr->SetErrorStringWithFormatv(
+  "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}", 
offset,
+  bra_offset, opcodes.GetByteSize());
 return false;
   }
 }


Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -131,6 +131,25 @@
   llvm::HasValue(0x010101010101));
 }
 
+TEST(DWARFExpression, DW_OP_skip) {
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const1u, 0x42, DW_OP_skip, 0x02, 0x00,
+ DW_OP_const1u, 0xff}),
+   llvm::HasValue(0x42));
+}
+
+TEST(DWARFExpression, DW_OP_bra) {
+  EXPECT_THAT_EXPECTED(
+  // clang-format off
+  Evaluate({
+DW_OP_const1u, 0x42, // push 0x42
+DW_OP_const1u, 0x1,  // push 0x1
+DW_OP_bra, 0x02, 0x00,   // if 0x1 > 0, then skip 0x0002 opcodes
+DW_OP_const1u, 0xff, // push 0xff
+  }),
+  // clang-format on
+  llvm::HasValue(0x42));
+}
+
 TEST(DWARFExpression, DW_OP_convert) {
   /// Auxiliary debug info.
   const char *yamldata = R"(
Index: lldb/source/Expression/DWARFExpression.cpp
===
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -1655,11 +1655,16 @@
 case DW_OP_skip: {
   int16_t skip_offset = (int16_t)opcodes.GetU16(&offset);
   lldb::offset_t new_offset = offset + skip_offset;
-  if (opcodes.ValidOffset(new_offset))
+  // New offset can point at the end of the data, in this case we should
+  // terminate the DWARF expression evaluation (will happen in the loop
+  // condition).
+  if (new_offset <= opcodes.GetByteSize())

[Lldb-commits] [PATCH] D111715: [WIP] [lldb] change name demangling to be consistent between windows and linx

2021-10-15 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

Thanks for improving this! Can you please add a few examples in the commit 
description like "before -> after", so it's more obvious what is changing here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111715

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


[Lldb-commits] [PATCH] D111934: [NFC] clang format change

2021-10-18 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee691fbc3de3: [lldb][NFC] clang format change (authored by 
lassefolger, committed by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111934

Files:
  lldb/source/Core/Mangled.cpp
  llvm/include/llvm/Demangle/Demangle.h


Index: llvm/include/llvm/Demangle/Demangle.h
===
--- llvm/include/llvm/Demangle/Demangle.h
+++ llvm/include/llvm/Demangle/Demangle.h
@@ -31,7 +31,6 @@
 char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
   int *status);
 
-
 enum MSDemangleFlags {
   MSDF_None = 0,
   MSDF_DumpBackrefs = 1 << 0,
@@ -53,9 +52,9 @@
 /// receives the size of the demangled string on output if n_buf is not 
nullptr.
 /// status receives one of the demangle_ enum entries above if it's not 
nullptr.
 /// Flags controls various details of the demangled representation.
-char *microsoftDemangle(const char *mangled_name, size_t *n_read,
-char *buf, size_t *n_buf,
-int *status, MSDemangleFlags Flags = MSDF_None);
+char *microsoftDemangle(const char *mangled_name, size_t *n_read, char *buf,
+size_t *n_buf, int *status,
+MSDemangleFlags Flags = MSDF_None);
 
 // Demangles a Rust v0 mangled symbol. The API follows that of __cxa_demangle.
 char *rustDemangle(const char *MangledName, char *Buf, size_t *N, int *Status);
@@ -120,6 +119,7 @@
   bool isSpecialName() const;
 
   ~ItaniumPartialDemangler();
+
 private:
   void *RootNode;
   void *Context;
Index: lldb/source/Core/Mangled.cpp
===
--- lldb/source/Core/Mangled.cpp
+++ lldb/source/Core/Mangled.cpp
@@ -260,7 +260,8 @@
   if (m_mangled && m_demangled.IsNull()) {
 // Don't bother running anything that isn't mangled
 const char *mangled_name = m_mangled.GetCString();
-ManglingScheme mangling_scheme = 
GetManglingScheme(m_mangled.GetStringRef());
+ManglingScheme mangling_scheme =
+GetManglingScheme(m_mangled.GetStringRef());
 if (mangling_scheme != eManglingSchemeNone &&
 !m_mangled.GetMangledCounterpart(m_demangled)) {
   // We didn't already mangle this name, demangle it and if all goes well
@@ -296,8 +297,7 @@
   return m_demangled;
 }
 
-ConstString
-Mangled::GetDisplayDemangledName() const {
+ConstString Mangled::GetDisplayDemangledName() const {
   return GetDemangledName();
 }
 


Index: llvm/include/llvm/Demangle/Demangle.h
===
--- llvm/include/llvm/Demangle/Demangle.h
+++ llvm/include/llvm/Demangle/Demangle.h
@@ -31,7 +31,6 @@
 char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n,
   int *status);
 
-
 enum MSDemangleFlags {
   MSDF_None = 0,
   MSDF_DumpBackrefs = 1 << 0,
@@ -53,9 +52,9 @@
 /// receives the size of the demangled string on output if n_buf is not nullptr.
 /// status receives one of the demangle_ enum entries above if it's not nullptr.
 /// Flags controls various details of the demangled representation.
-char *microsoftDemangle(const char *mangled_name, size_t *n_read,
-char *buf, size_t *n_buf,
-int *status, MSDemangleFlags Flags = MSDF_None);
+char *microsoftDemangle(const char *mangled_name, size_t *n_read, char *buf,
+size_t *n_buf, int *status,
+MSDemangleFlags Flags = MSDF_None);
 
 // Demangles a Rust v0 mangled symbol. The API follows that of __cxa_demangle.
 char *rustDemangle(const char *MangledName, char *Buf, size_t *N, int *Status);
@@ -120,6 +119,7 @@
   bool isSpecialName() const;
 
   ~ItaniumPartialDemangler();
+
 private:
   void *RootNode;
   void *Context;
Index: lldb/source/Core/Mangled.cpp
===
--- lldb/source/Core/Mangled.cpp
+++ lldb/source/Core/Mangled.cpp
@@ -260,7 +260,8 @@
   if (m_mangled && m_demangled.IsNull()) {
 // Don't bother running anything that isn't mangled
 const char *mangled_name = m_mangled.GetCString();
-ManglingScheme mangling_scheme = GetManglingScheme(m_mangled.GetStringRef());
+ManglingScheme mangling_scheme =
+GetManglingScheme(m_mangled.GetStringRef());
 if (mangling_scheme != eManglingSchemeNone &&
 !m_mangled.GetMangledCounterpart(m_demangled)) {
   // We didn't already mangle this name, demangle it and if all goes well
@@ -296,8 +297,7 @@
   return m_demangled;
 }
 
-ConstString
-Mangled::GetDisplayDemangledName() const {
+ConstString Mangled::GetDisplayDemangledName() const {
   return GetDemangledName();
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://li

[Lldb-commits] [PATCH] D111715: [WIP] [lldb] change name demangling to be consistent between windows and linx

2021-10-19 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG134e1817f62c: [lldb] change name demangling to be consistent 
between windows and linx (authored by lassefolger, committed by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111715

Files:
  lldb/source/Core/Mangled.cpp
  llvm/include/llvm/Demangle/Demangle.h
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-options.test
  llvm/tools/llvm-undname/llvm-undname.cpp

Index: llvm/tools/llvm-undname/llvm-undname.cpp
===
--- llvm/tools/llvm-undname/llvm-undname.cpp
+++ llvm/tools/llvm-undname/llvm-undname.cpp
@@ -46,6 +46,9 @@
 cl::opt NoMemberType("no-member-type", cl::Optional,
cl::desc("skip member types"), cl::Hidden,
cl::init(false), cl::cat(UndNameCategory));
+cl::opt NoVariableType("no-variable-type", cl::Optional,
+ cl::desc("skip variable types"), cl::Hidden,
+ cl::init(false), cl::cat(UndNameCategory));
 cl::opt RawFile("raw-file", cl::Optional,
  cl::desc("for fuzzer data"), cl::Hidden,
  cl::cat(UndNameCategory));
@@ -68,6 +71,8 @@
 Flags = MSDemangleFlags(Flags | MSDF_NoReturnType);
   if (NoMemberType)
 Flags = MSDemangleFlags(Flags | MSDF_NoMemberType);
+  if (NoVariableType)
+Flags = MSDemangleFlags(Flags | MSDF_NoVariableType);
 
   size_t NRead;
   char *ResultBuf =
Index: llvm/test/Demangle/ms-options.test
===
--- llvm/test/Demangle/ms-options.test
+++ llvm/test/Demangle/ms-options.test
@@ -1,14 +1,43 @@
-; RUN: llvm-undname < %s | FileCheck %s
-; RUN: llvm-undname --no-calling-convention < %s | FileCheck %s --check-prefix=CHECK-NO-CALLING-CONV
-; RUN: llvm-undname --no-return-type < %s | FileCheck %s --check-prefix=CHECK-NO-RETURN
-; RUN: llvm-undname --no-access-specifier < %s | FileCheck %s --check-prefix=CHECK-NO-ACCESS
-; RUN: llvm-undname --no-member-type < %s | FileCheck %s --check-prefix=CHECK-NO-MEMBER-TYPE
-; RUN: llvm-undname --no-calling-convention --no-return-type --no-access-specifier --no-member-type < %s | FileCheck %s --check-prefix=CHECK-NO-ALL
-
-?func@MyClass@@UEAAHHH@Z
-; CHECK: public: virtual int __cdecl MyClass::func(int, int)
-; CHECK-NO-CALLING-CONV: public: virtual int MyClass::func(int, int)
-; CHECK-NO-RETURN: public: virtual __cdecl MyClass::func(int, int)
-; CHECK-NO-ACCESS: {{^}}virtual int __cdecl MyClass::func(int, int)
-; CHECK-NO-MEMBER-TYPE: public: int __cdecl MyClass::func(int, int)
-; CHECK-NO-ALL: {{^}}MyClass::func(int, int)
+; RUN: llvm-undname < %s | FileCheck %s
+; RUN: llvm-undname --no-calling-convention < %s | FileCheck %s --check-prefix=CHECK-NO-CALLING-CONV
+; RUN: llvm-undname --no-return-type < %s | FileCheck %s --check-prefix=CHECK-NO-RETURN
+; RUN: llvm-undname --no-access-specifier < %s | FileCheck %s --check-prefix=CHECK-NO-ACCESS
+; RUN: llvm-undname --no-member-type < %s | FileCheck %s --check-prefix=CHECK-NO-MEMBER-TYPE
+; RUN: llvm-undname --no-variable-type < %s | FileCheck %s --check-prefix=CHECK-NO-VARIABLE-TYPE
+; RUN: llvm-undname --no-calling-convention --no-return-type --no-access-specifier --no-member-type --no-variable-type < %s | FileCheck %s --check-prefix=CHECK-NO-ALL
+
+?func@MyClass@@UEAAHHH@Z
+; CHECK: public: virtual int __cdecl MyClass::func(int, int)
+; CHECK-NO-CALLING-CONV: public: virtual int MyClass::func(int, int)
+; CHECK-NO-RETURN: public: virtual __cdecl MyClass::func(int, int)
+; CHECK-NO-ACCESS: {{^}}virtual int __cdecl MyClass::func(int, int)
+; CHECK-NO-MEMBER-TYPE: public: int __cdecl MyClass::func(int, int)
+; CHECK-NO-VARIABLE-TYPE: public: virtual int __cdecl MyClass::func(int, int)
+; CHECK-NO-ALL: {{^}}MyClass::func(int, int)
+
+?array2d@@3PAY09HA
+; CHECK: int (*array2d)[10]
+; CHECK-NO-CALLING-CONV: int (*array2d)[10]
+; CHECK-NO-RETURN: int (*array2d)[10]
+; CHECK-NO-ACCESS: int (*array2d)[10]
+; CHECK-NO-MEMBER-TYPE: int (*array2d)[10]
+; CHECK-NO-VARIABLE-TYPE: array2d
+; CHECK-NO-ALL: array2d
+
+?a@abc@@3PAY09HA
+; CHECK: int (*abc::a)[10]
+; CHECK-NO-CALLING-CONV: int (*abc::a)[10]
+; CHECK-NO-RETURN: int (*abc::a)[10]
+; CHECK-NO-ACCESS: int (*abc::a)[10]
+; CHECK-NO-MEMBER-TYPE: int (*abc::a)[10]
+; CHECK-NO-VARIABLE-TYPE: abc::a
+; CHECK-NO-ALL: abc::a
+
+?x@@3PEAEEA
+; CHECK: unsigned char *x
+; CHECK-NO-CALLING-CONV: unsigned char *x
+; CHECK-NO-RETURN: unsigned char *x
+; CHECK-NO-ACCESS: unsigned char *x
+; CHECK-NO-MEMBER-TYPE: unsigned char *x
+; CHECK-NO-VARIABLE-TYPE: x
+; CHECK-NO-ALL: x
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===

[Lldb-commits] [PATCH] D112147: [lldb] Fix lookup for global constants in namespaces

2021-10-22 Thread Andy Yankovsky via Phabricator via lldb-commits
werat accepted this revision.
werat added a comment.
This revision is now accepted and ready to land.

This looks reasonable to me.

@teemperor any thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112147

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


[Lldb-commits] [PATCH] D113400: [lldb-vscode] Add presentation hints for scopes

2021-11-08 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Scopes can have an optional hint for how to present this scope in the UI:
https://microsoft.github.io/debug-adapter-protocol/specification#Types_Scope

The IDEs can use the hint to present the data accordingly. For example,
Visual Studio has a separate Registers window, which is populated with the
data from the scope with `presentationHint: "registers"`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113400

Files:
  lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
  lldb/tools/lldb-vscode/JSONUtils.cpp


Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -175,6 +175,13 @@
 //   "type": "string",
 //   "description": "Name of the scope such as 'Arguments', 'Locals'."
 // },
+// "presentationHint": {
+//   "type": "string",
+//   "description": "An optional hint for how to present this scope in the
+//   UI. If this attribute is missing, the scope is shown
+//   with a generic UI.",
+//   "_enum": [ "arguments", "locals", "registers" ],
+// },
 // "variablesReference": {
 //   "type": "integer",
 //   "description": "The variables of this scope can be retrieved by
@@ -229,6 +236,15 @@
   int64_t namedVariables, bool expensive) {
   llvm::json::Object object;
   EmplaceSafeString(object, "name", name.str());
+
+  // TODO: Support "arguments" scope. At the moment lldb-vscode includes the
+  // arguments into the "locals" scope.
+  if (variablesReference == VARREF_LOCALS) {
+object.try_emplace("presentationHint", "locals");
+  } else if (variablesReference == VARREF_REGS) {
+object.try_emplace("presentationHint", "registers");
+  }
+
   object.try_emplace("variablesReference", variablesReference);
   object.try_emplace("expensive", expensive);
   object.try_emplace("namedVariables", namedVariables);
Index: lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
===
--- lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
+++ lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
@@ -394,3 +394,17 @@
 self.verify_variables(
 expandable_expression["children"], response["body"]["variables"]
 )
+
+# Test that frame scopes have corresponding presentation hints.
+frame_id = self.vscode.get_stackFrame()["id"]
+scopes = self.vscode.request_scopes(frame_id)["body"]["scopes"]
+
+scope_names = [scope["name"] for scope in scopes]
+self.assertIn("Locals", scope_names)
+self.assertIn("Registers", scope_names)
+
+for scope in scopes:
+if scope["name"] == "Locals":
+self.assertEquals(scope.get("presentationHint"), "locals")
+if scope["name"] == "Registers":
+self.assertEquals(scope.get("presentationHint"), "registers")


Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -175,6 +175,13 @@
 //   "type": "string",
 //   "description": "Name of the scope such as 'Arguments', 'Locals'."
 // },
+// "presentationHint": {
+//   "type": "string",
+//   "description": "An optional hint for how to present this scope in the
+//   UI. If this attribute is missing, the scope is shown
+//   with a generic UI.",
+//   "_enum": [ "arguments", "locals", "registers" ],
+// },
 // "variablesReference": {
 //   "type": "integer",
 //   "description": "The variables of this scope can be retrieved by
@@ -229,6 +236,15 @@
   int64_t namedVariables, bool expensive) {
   llvm::json::Object object;
   EmplaceSafeString(object, "name", name.str());
+
+  // TODO: Support "arguments" scope. At the moment lldb-vscode includes the
+  // arguments into the "locals" scope.
+  if (variablesReference == VARREF_LOCALS) {
+object.try_emplace("presentationHint", "locals");
+  } else if (variablesReference == VARREF_REGS) {
+object.try_emplace("presentationHint", "registers");
+  }
+
   object.try_emplace("variablesReference", variablesReference);
   object.try_emplace("expensive", expensive);
   object.try_emplace("namedVariables", namedVariables);
Index: lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
===
--- lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
+++ lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
@@ -394,

[Lldb-commits] [PATCH] D113400: [lldb-vscode] Add presentation hints for scopes

2021-11-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D113400#3117500 , @wallace wrote:

> could you share a screenshot of how this looks like?

Sure! Here are the screenshots of before/after in Visual Studio 2022.

Before everything is in one place (in Locals Window):
F20179455: visual-studio-before.png 
After, Registers Window (marked in red -- changed since previous step):
F20179456: registers-after.png 
After, Locals Window (locals are displayed directly, without "Locals" expand 
block):
F20179454: locals-after.png 

---

There are no visible changes in Visual Studio Code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113400

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


[Lldb-commits] [PATCH] D113400: [lldb-vscode] Add presentation hints for scopes

2021-11-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

Thanks! I have push permission, will land it myself in a bit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113400

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


[Lldb-commits] [PATCH] D113400: [lldb-vscode] Add presentation hints for scopes

2021-11-09 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdc8f0035ca99: [lldb-vscode] Add presentation hints for 
scopes (authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113400

Files:
  lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
  lldb/tools/lldb-vscode/JSONUtils.cpp


Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -175,6 +175,13 @@
 //   "type": "string",
 //   "description": "Name of the scope such as 'Arguments', 'Locals'."
 // },
+// "presentationHint": {
+//   "type": "string",
+//   "description": "An optional hint for how to present this scope in the
+//   UI. If this attribute is missing, the scope is shown
+//   with a generic UI.",
+//   "_enum": [ "arguments", "locals", "registers" ],
+// },
 // "variablesReference": {
 //   "type": "integer",
 //   "description": "The variables of this scope can be retrieved by
@@ -229,6 +236,15 @@
   int64_t namedVariables, bool expensive) {
   llvm::json::Object object;
   EmplaceSafeString(object, "name", name.str());
+
+  // TODO: Support "arguments" scope. At the moment lldb-vscode includes the
+  // arguments into the "locals" scope.
+  if (variablesReference == VARREF_LOCALS) {
+object.try_emplace("presentationHint", "locals");
+  } else if (variablesReference == VARREF_REGS) {
+object.try_emplace("presentationHint", "registers");
+  }
+
   object.try_emplace("variablesReference", variablesReference);
   object.try_emplace("expensive", expensive);
   object.try_emplace("namedVariables", namedVariables);
Index: lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
===
--- lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
+++ lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
@@ -394,3 +394,17 @@
 self.verify_variables(
 expandable_expression["children"], response["body"]["variables"]
 )
+
+# Test that frame scopes have corresponding presentation hints.
+frame_id = self.vscode.get_stackFrame()["id"]
+scopes = self.vscode.request_scopes(frame_id)["body"]["scopes"]
+
+scope_names = [scope["name"] for scope in scopes]
+self.assertIn("Locals", scope_names)
+self.assertIn("Registers", scope_names)
+
+for scope in scopes:
+if scope["name"] == "Locals":
+self.assertEquals(scope.get("presentationHint"), "locals")
+if scope["name"] == "Registers":
+self.assertEquals(scope.get("presentationHint"), "registers")


Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -175,6 +175,13 @@
 //   "type": "string",
 //   "description": "Name of the scope such as 'Arguments', 'Locals'."
 // },
+// "presentationHint": {
+//   "type": "string",
+//   "description": "An optional hint for how to present this scope in the
+//   UI. If this attribute is missing, the scope is shown
+//   with a generic UI.",
+//   "_enum": [ "arguments", "locals", "registers" ],
+// },
 // "variablesReference": {
 //   "type": "integer",
 //   "description": "The variables of this scope can be retrieved by
@@ -229,6 +236,15 @@
   int64_t namedVariables, bool expensive) {
   llvm::json::Object object;
   EmplaceSafeString(object, "name", name.str());
+
+  // TODO: Support "arguments" scope. At the moment lldb-vscode includes the
+  // arguments into the "locals" scope.
+  if (variablesReference == VARREF_LOCALS) {
+object.try_emplace("presentationHint", "locals");
+  } else if (variablesReference == VARREF_REGS) {
+object.try_emplace("presentationHint", "registers");
+  }
+
   object.try_emplace("variablesReference", variablesReference);
   object.try_emplace("expensive", expensive);
   object.try_emplace("namedVariables", namedVariables);
Index: lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
===
--- lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
+++ lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
@@ -394,3 +394,17 @@
 self.verify_variables(
 expandable_expression["children"], response["body"]["variables"]
 )
+
+# Test that frame scopes have corresponding presentation hints.
+frame_id = self.vscode.get_stackFrame(

[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2021-11-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Operands to `getelementptr` can be constants or constant expressions. Check
that all operands can be constant-resolved and resolve them during the
evaluation. If some operands can't be resolved as constants -- the expression
evaluation will fallback to JIT.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=52449


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113498

Files:
  lldb/source/Expression/IRInterpreter.cpp
  lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
  lldb/test/API/lang/cpp/static_members/main.cpp

Index: lldb/test/API/lang/cpp/static_members/main.cpp
===
--- lldb/test/API/lang/cpp/static_members/main.cpp
+++ lldb/test/API/lang/cpp/static_members/main.cpp
@@ -11,6 +11,14 @@
 long A::s_b = 2;
 int A::s_c = 3;
 
+// class Foo
+// {
+// public:
+// static int Bar;
+// };
+
+// int Foo::Bar = 10;
+
 int main() {
   A my_a;
   my_a.m_a = 1;
Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org/show_bug.cgi?id=52449
+"""
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... i64 ptrtoint (i32* @_ZN1A3s_cE to i64)) ...
+expr = "(int*)100 + (long long)(&A::s_c)"
+
+# The IR interpreter doesn't support non-const operands to the
+# `GetElementPtr` IR instruction, so verify that it correctly fails to
+# evaluate expression.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertTrue(value.GetError().Fail())
+self.assertIn(
+"Can't evaluate the expression without a running target",
+value.GetError().GetCString())
+
+# Evaluating the expression via JIT should work fine.
+value = self.target().EvaluateExpression(expr)
+self.assertTrue(value.GetError().Success())
Index: lldb/source/Expression/IRInterpreter.cpp
===
--- lldb/source/Expression/IRInterpreter.cpp
+++ lldb/source/Expression/IRInterpreter.cpp
@@ -283,11 +283,30 @@
 return true; // no offset to apply!
 
   SmallVector indices(op_cursor, op_end);
+  SmallVector const_indices;
+
+  for (Value *idx : indices) {
+Constant *constant_idx = dyn_cast(idx);
+if (!constant_idx)
+  return false;
+
+ConstantInt *constant_int = dyn_cast(constant_idx);
+if (!constant_int) {
+  APInt v;
+  if (!ResolveConstantValue(v, constant_idx))
+return false;
+
+  constant_int =
+  cast(ConstantInt::get(idx->getType(), v));
+}
+
+const_indices.push_back(constant_int);
+  }
 
   Type *src_elem_ty =
   cast(constant_expr)->getSourceElementType();
   uint64_t offset =
-  m_target_data.getIndexedOffsetInType(src_elem_ty, indices);
+  m_target_data.getIndexedOffsetInType(src_elem_ty, const_indices);
 
   const bool is_signed = true;
   value += APInt(value.getBitWidth(), offset, is_signed);
@@ -465,12 +484,18 @@
   case Instruction::BitCast:
 return CanResolveConstant(constant_expr->getOperand(0));
   case Instruction::GetElementPtr: {
-ConstantExpr::const_op_iterator op_cursor = constant_expr->op_begin();
-Constant *base = dyn_cast(*op_cursor);
-if (!base)
-  return false;
-
-return CanResolveConstant(base);
+// Check that all operands of `getelementptr` can be constant-resolved.
+SmallVector operands(constant_expr->op_begin(),
+ constant_expr->op_end());
+for (Value *op : operands) {
+  Constant *constant_op = dyn_cast(op);
+  if (!constant_op)
+return false;
+  if (!CanResolveConstant(constant_op)) {
+return false;
+  }
+}
+return true;
   }
   }
 } 

[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2021-11-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 385892.
werat added a comment.
Herald added a subscriber: JDevlieghere.

Remove accidental code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

Files:
  lldb/source/Expression/IRInterpreter.cpp
  lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py


Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression 
involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org/show_bug.cgi?id=52449
+"""
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", 
lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... i64 ptrtoint (i32* @_ZN1A3s_cE to i64)) ...
+expr = "(int*)100 + (long long)(&A::s_c)"
+
+# The IR interpreter doesn't support non-const operands to the
+# `GetElementPtr` IR instruction, so verify that it correctly fails to
+# evaluate expression.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertTrue(value.GetError().Fail())
+self.assertIn(
+"Can't evaluate the expression without a running target",
+value.GetError().GetCString())
+
+# Evaluating the expression via JIT should work fine.
+value = self.target().EvaluateExpression(expr)
+self.assertTrue(value.GetError().Success())
Index: lldb/source/Expression/IRInterpreter.cpp
===
--- lldb/source/Expression/IRInterpreter.cpp
+++ lldb/source/Expression/IRInterpreter.cpp
@@ -283,11 +283,30 @@
 return true; // no offset to apply!
 
   SmallVector indices(op_cursor, op_end);
+  SmallVector const_indices;
+
+  for (Value *idx : indices) {
+Constant *constant_idx = dyn_cast(idx);
+if (!constant_idx)
+  return false;
+
+ConstantInt *constant_int = dyn_cast(constant_idx);
+if (!constant_int) {
+  APInt v;
+  if (!ResolveConstantValue(v, constant_idx))
+return false;
+
+  constant_int =
+  cast(ConstantInt::get(idx->getType(), v));
+}
+
+const_indices.push_back(constant_int);
+  }
 
   Type *src_elem_ty =
   cast(constant_expr)->getSourceElementType();
   uint64_t offset =
-  m_target_data.getIndexedOffsetInType(src_elem_ty, indices);
+  m_target_data.getIndexedOffsetInType(src_elem_ty, const_indices);
 
   const bool is_signed = true;
   value += APInt(value.getBitWidth(), offset, is_signed);
@@ -465,12 +484,18 @@
   case Instruction::BitCast:
 return CanResolveConstant(constant_expr->getOperand(0));
   case Instruction::GetElementPtr: {
-ConstantExpr::const_op_iterator op_cursor = constant_expr->op_begin();
-Constant *base = dyn_cast(*op_cursor);
-if (!base)
-  return false;
-
-return CanResolveConstant(base);
+// Check that all operands of `getelementptr` can be constant-resolved.
+SmallVector operands(constant_expr->op_begin(),
+ constant_expr->op_end());
+for (Value *op : operands) {
+  Constant *constant_op = dyn_cast(op);
+  if (!constant_op)
+return false;
+  if (!CanResolveConstant(constant_op)) {
+return false;
+  }
+}
+return true;
   }
   }
 } else {


Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org

[Lldb-commits] [PATCH] D113673: [lldb] Unwrap the type when dereferencing the value

2021-11-11 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The value type can be a typedef of a reference (e.g. `typedef int& myint`).
In this case `GetQualType(type)` will return `clang::Typedef`, which cannot
be casted to `clang::ReferenceType`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113673

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
  lldb/test/API/lang/cpp/dereferencing_references/main.cpp


Index: lldb/test/API/lang/cpp/dereferencing_references/main.cpp
===
--- lldb/test/API/lang/cpp/dereferencing_references/main.cpp
+++ lldb/test/API/lang/cpp/dereferencing_references/main.cpp
@@ -1,8 +1,13 @@
 typedef int TTT;
+typedef int &td_int_ref;
 
 int main() {
   int i = 0;
+  // references to typedefs
   TTT &l_ref = i;
   TTT &&r_ref = static_cast(i);
+  // typedef of a reference
+  td_int_ref td = i;
+
   return l_ref; // break here
 }
Index: 
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
===
--- 
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
+++ 
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
@@ -21,3 +21,7 @@
 # Same as above for rvalue references.
 rref_val = self.expect_var_path("r_ref", type="TTT &&")
 self.assertEqual(rref_val.Dereference().GetType().GetName(), "TTT")
+
+# Typedef to a reference should dereference to the underlying type.
+td_val = self.expect_var_path("td", type="td_int_ref")
+self.assertEqual(td_val.Dereference().GetType().GetName(), "int")
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -6492,7 +6492,8 @@
   case clang::Type::RValueReference:
 if (idx_is_valid) {
   const clang::ReferenceType *reference_type =
-  llvm::cast(GetQualType(type).getTypePtr());
+  llvm::cast(
+  RemoveWrappingTypes(GetQualType(type)).getTypePtr());
   CompilerType pointee_clang_type =
   GetType(reference_type->getPointeeType());
   if (transparent_pointers && pointee_clang_type.IsAggregateType()) {


Index: lldb/test/API/lang/cpp/dereferencing_references/main.cpp
===
--- lldb/test/API/lang/cpp/dereferencing_references/main.cpp
+++ lldb/test/API/lang/cpp/dereferencing_references/main.cpp
@@ -1,8 +1,13 @@
 typedef int TTT;
+typedef int &td_int_ref;
 
 int main() {
   int i = 0;
+  // references to typedefs
   TTT &l_ref = i;
   TTT &&r_ref = static_cast(i);
+  // typedef of a reference
+  td_int_ref td = i;
+
   return l_ref; // break here
 }
Index: lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
===
--- lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
+++ lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
@@ -21,3 +21,7 @@
 # Same as above for rvalue references.
 rref_val = self.expect_var_path("r_ref", type="TTT &&")
 self.assertEqual(rref_val.Dereference().GetType().GetName(), "TTT")
+
+# Typedef to a reference should dereference to the underlying type.
+td_val = self.expect_var_path("td", type="td_int_ref")
+self.assertEqual(td_val.Dereference().GetType().GetName(), "int")
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -6492,7 +6492,8 @@
   case clang::Type::RValueReference:
 if (idx_is_valid) {
   const clang::ReferenceType *reference_type =
-  llvm::cast(GetQualType(type).getTypePtr());
+  llvm::cast(
+  RemoveWrappingTypes(GetQualType(type)).getTypePtr());
   CompilerType pointee_clang_type =
   GetType(reference_type->getPointeeType());
   if (transparent_pointers && pointee_clang_type.IsAggregateType()) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D113673: [lldb] Unwrap the type when dereferencing the value

2021-11-15 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 387213.
werat added a comment.

Update commit message, rename test variable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113673

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
  lldb/test/API/lang/cpp/dereferencing_references/main.cpp


Index: lldb/test/API/lang/cpp/dereferencing_references/main.cpp
===
--- lldb/test/API/lang/cpp/dereferencing_references/main.cpp
+++ lldb/test/API/lang/cpp/dereferencing_references/main.cpp
@@ -1,8 +1,13 @@
 typedef int TTT;
+typedef int &td_int_ref;
 
 int main() {
   int i = 0;
+  // references to typedefs
   TTT &l_ref = i;
   TTT &&r_ref = static_cast(i);
+  // typedef of a reference
+  td_int_ref td_to_ref_type = i;
+
   return l_ref; // break here
 }
Index: 
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
===
--- 
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
+++ 
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
@@ -21,3 +21,7 @@
 # Same as above for rvalue references.
 rref_val = self.expect_var_path("r_ref", type="TTT &&")
 self.assertEqual(rref_val.Dereference().GetType().GetName(), "TTT")
+
+# Typedef to a reference should dereference to the underlying type.
+td_val = self.expect_var_path("td_to_ref_type", type="td_int_ref")
+self.assertEqual(td_val.Dereference().GetType().GetName(), "int")
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -6492,7 +6492,8 @@
   case clang::Type::RValueReference:
 if (idx_is_valid) {
   const clang::ReferenceType *reference_type =
-  llvm::cast(GetQualType(type).getTypePtr());
+  llvm::cast(
+  RemoveWrappingTypes(GetQualType(type)).getTypePtr());
   CompilerType pointee_clang_type =
   GetType(reference_type->getPointeeType());
   if (transparent_pointers && pointee_clang_type.IsAggregateType()) {


Index: lldb/test/API/lang/cpp/dereferencing_references/main.cpp
===
--- lldb/test/API/lang/cpp/dereferencing_references/main.cpp
+++ lldb/test/API/lang/cpp/dereferencing_references/main.cpp
@@ -1,8 +1,13 @@
 typedef int TTT;
+typedef int &td_int_ref;
 
 int main() {
   int i = 0;
+  // references to typedefs
   TTT &l_ref = i;
   TTT &&r_ref = static_cast(i);
+  // typedef of a reference
+  td_int_ref td_to_ref_type = i;
+
   return l_ref; // break here
 }
Index: lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
===
--- lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
+++ lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
@@ -21,3 +21,7 @@
 # Same as above for rvalue references.
 rref_val = self.expect_var_path("r_ref", type="TTT &&")
 self.assertEqual(rref_val.Dereference().GetType().GetName(), "TTT")
+
+# Typedef to a reference should dereference to the underlying type.
+td_val = self.expect_var_path("td_to_ref_type", type="td_int_ref")
+self.assertEqual(td_val.Dereference().GetType().GetName(), "int")
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -6492,7 +6492,8 @@
   case clang::Type::RValueReference:
 if (idx_is_valid) {
   const clang::ReferenceType *reference_type =
-  llvm::cast(GetQualType(type).getTypePtr());
+  llvm::cast(
+  RemoveWrappingTypes(GetQualType(type)).getTypePtr());
   CompilerType pointee_clang_type =
   GetType(reference_type->getPointeeType());
   if (transparent_pointers && pointee_clang_type.IsAggregateType()) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D113673: [lldb] Unwrap the type when dereferencing the value

2021-11-15 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG95102b7dc3c1: [lldb] Unwrap the type when dereferencing the 
value (authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113673

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
  lldb/test/API/lang/cpp/dereferencing_references/main.cpp


Index: lldb/test/API/lang/cpp/dereferencing_references/main.cpp
===
--- lldb/test/API/lang/cpp/dereferencing_references/main.cpp
+++ lldb/test/API/lang/cpp/dereferencing_references/main.cpp
@@ -1,8 +1,13 @@
 typedef int TTT;
+typedef int &td_int_ref;
 
 int main() {
   int i = 0;
+  // references to typedefs
   TTT &l_ref = i;
   TTT &&r_ref = static_cast(i);
+  // typedef of a reference
+  td_int_ref td_to_ref_type = i;
+
   return l_ref; // break here
 }
Index: 
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
===
--- 
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
+++ 
lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
@@ -21,3 +21,7 @@
 # Same as above for rvalue references.
 rref_val = self.expect_var_path("r_ref", type="TTT &&")
 self.assertEqual(rref_val.Dereference().GetType().GetName(), "TTT")
+
+# Typedef to a reference should dereference to the underlying type.
+td_val = self.expect_var_path("td_to_ref_type", type="td_int_ref")
+self.assertEqual(td_val.Dereference().GetType().GetName(), "int")
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -6492,7 +6492,8 @@
   case clang::Type::RValueReference:
 if (idx_is_valid) {
   const clang::ReferenceType *reference_type =
-  llvm::cast(GetQualType(type).getTypePtr());
+  llvm::cast(
+  RemoveWrappingTypes(GetQualType(type)).getTypePtr());
   CompilerType pointee_clang_type =
   GetType(reference_type->getPointeeType());
   if (transparent_pointers && pointee_clang_type.IsAggregateType()) {


Index: lldb/test/API/lang/cpp/dereferencing_references/main.cpp
===
--- lldb/test/API/lang/cpp/dereferencing_references/main.cpp
+++ lldb/test/API/lang/cpp/dereferencing_references/main.cpp
@@ -1,8 +1,13 @@
 typedef int TTT;
+typedef int &td_int_ref;
 
 int main() {
   int i = 0;
+  // references to typedefs
   TTT &l_ref = i;
   TTT &&r_ref = static_cast(i);
+  // typedef of a reference
+  td_int_ref td_to_ref_type = i;
+
   return l_ref; // break here
 }
Index: lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
===
--- lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
+++ lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.py
@@ -21,3 +21,7 @@
 # Same as above for rvalue references.
 rref_val = self.expect_var_path("r_ref", type="TTT &&")
 self.assertEqual(rref_val.Dereference().GetType().GetName(), "TTT")
+
+# Typedef to a reference should dereference to the underlying type.
+td_val = self.expect_var_path("td_to_ref_type", type="td_int_ref")
+self.assertEqual(td_val.Dereference().GetType().GetName(), "int")
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -6492,7 +6492,8 @@
   case clang::Type::RValueReference:
 if (idx_is_valid) {
   const clang::ReferenceType *reference_type =
-  llvm::cast(GetQualType(type).getTypePtr());
+  llvm::cast(
+  RemoveWrappingTypes(GetQualType(type)).getTypePtr());
   CompilerType pointee_clang_type =
   GetType(reference_type->getPointeeType());
   if (transparent_pointers && pointee_clang_type.IsAggregateType()) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2021-11-15 Thread Andy Yankovsky via Phabricator via lldb-commits
werat marked 4 inline comments as done.
werat added a comment.

In D113498#3124525 , @teemperor wrote:

> I really like the solution, but I think by fixing the `CanInterpret` you also 
> made the test case no longer reach the actual changed interpreting logic?
>
> So, `CanInterpret` says "we can't interpret this" (which is correct), but 
> then the interpreter won't run it and your change to `ResolveConstantValue` 
> isn't actually tested. There is no other test that touches that logic from 
> what I can see. You could try throwing in some other expression at this that 
> tests that new code? Maybe some kind of pointer arithmetic on a variable 
> defined in your expression itself (so it can be constant evaluated).

I think you're right, the interpreter now doesn't get to evaluating the 
operands of `GetElementPtr`. However, I've failed to construct an expression 
that would have a constant expression with `getelementptr` instruction. So far 
I've only been able to reproduce it with the example from the test case (which 
is being rejected during `CanInterpret`). I've tried expressions like `const 
int x = 1; (int*)100 + (long long)(&x)` and similar (also with `x` being a 
global variable), but they're are being compiled in a way that `getelementptr` 
is not a constant expression anymore.

In D113498#3124525 , @teemperor wrote:

> We could also split out the interpreting change and then this is good to go.

I think the `Interpret` and `CanInterpret` should really be in-sync with each 
other, otherwise more bugs can follow. Given that we can't get an expression 
for the logic I've implemented, I can make the check more strict -- just verify 
that all indexes are `ConstantInt`. What do you think?




Comment at: lldb/source/Expression/IRInterpreter.cpp:490
+ constant_expr->op_end());
+for (Value *op : operands) {
+  Constant *constant_op = dyn_cast(op);

teemperor wrote:
> `for (Value *op : constant_expr->ops())` ?
`ConstantExpr` doesn't have `ops()` accessor, only `op_begin/op_end`. Am I 
missing something?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2021-11-15 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 387236.
werat added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

Files:
  lldb/source/Expression/IRInterpreter.cpp
  lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py


Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression 
involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org/show_bug.cgi?id=52449
+"""
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", 
lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... i64 ptrtoint (i32* @_ZN1A3s_cE to i64)) ...
+expr = "(int*)100 + (long long)(&A::s_c)"
+
+# The IR interpreter doesn't support non-const operands to the
+# `GetElementPtr` IR instruction, so verify that it correctly fails to
+# evaluate expression.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertTrue(value.GetError().Fail())
+self.assertIn(
+"Can't evaluate the expression without a running target",
+value.GetError().GetCString())
+
+# Evaluating the expression via JIT should work fine.
+value = self.target().EvaluateExpression(expr)
+self.assertSuccess(value.GetError())
Index: lldb/source/Expression/IRInterpreter.cpp
===
--- lldb/source/Expression/IRInterpreter.cpp
+++ lldb/source/Expression/IRInterpreter.cpp
@@ -282,12 +282,33 @@
   if (op_cursor == op_end)
 return true; // no offset to apply!
 
+  // DataLayout::getIndexedOffsetInType assumes the indices are
+  // instances of ConstantInt, so we need to resolve them.
   SmallVector indices(op_cursor, op_end);
+  SmallVector resolved_indices;
+
+  for (Value *idx : indices) {
+Constant *constant_idx = dyn_cast(idx);
+if (!constant_idx)
+  return false;
+
+ConstantInt *constant_int = dyn_cast(constant_idx);
+if (!constant_int) {
+  APInt v;
+  if (!ResolveConstantValue(v, constant_idx))
+return false;
+
+  constant_int =
+  cast(ConstantInt::get(idx->getType(), v));
+}
+
+resolved_indices.push_back(constant_int);
+  }
 
   Type *src_elem_ty =
   cast(constant_expr)->getSourceElementType();
-  uint64_t offset =
-  m_target_data.getIndexedOffsetInType(src_elem_ty, indices);
+  uint64_t offset = m_target_data.getIndexedOffsetInType(
+  src_elem_ty, resolved_indices);
 
   const bool is_signed = true;
   value += APInt(value.getBitWidth(), offset, is_signed);
@@ -465,12 +486,17 @@
   case Instruction::BitCast:
 return CanResolveConstant(constant_expr->getOperand(0));
   case Instruction::GetElementPtr: {
-ConstantExpr::const_op_iterator op_cursor = constant_expr->op_begin();
-Constant *base = dyn_cast(*op_cursor);
-if (!base)
-  return false;
-
-return CanResolveConstant(base);
+// Check that all operands of `getelementptr` can be constant-resolved.
+SmallVector operands(constant_expr->op_begin(),
+ constant_expr->op_end());
+for (Value *op : operands) {
+  Constant *constant_op = dyn_cast(op);
+  if (!constant_op)
+return false;
+  if (!CanResolveConstant(constant_op))
+return false;
+}
+return true;
   }
   }
 } else {


Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash o

[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2021-11-17 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

Btw, this crash in `llvm::DataLayout::getIndexedOffsetInType` was discovered by 
lldb-eval fuzzer a while ago -- 
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=36738


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2021-11-17 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 387911.
werat added a comment.

Make the check more strict, only verify that the indexes are ConstantInt.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

Files:
  lldb/source/Expression/IRInterpreter.cpp
  lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py


Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression 
involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org/show_bug.cgi?id=52449
+"""
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", 
lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... i64 ptrtoint (i32* @_ZN1A3s_cE to i64)) ...
+expr = "(int*)100 + (long long)(&A::s_c)"
+
+# The IR interpreter doesn't support non-const operands to the
+# `GetElementPtr` IR instruction, so verify that it correctly fails to
+# evaluate expression.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertTrue(value.GetError().Fail())
+self.assertIn(
+"Can't evaluate the expression without a running target",
+value.GetError().GetCString())
+
+# Evaluating the expression via JIT should work fine.
+value = self.target().EvaluateExpression(expr)
+self.assertSuccess(value.GetError())
Index: lldb/source/Expression/IRInterpreter.cpp
===
--- lldb/source/Expression/IRInterpreter.cpp
+++ lldb/source/Expression/IRInterpreter.cpp
@@ -283,9 +283,11 @@
 return true; // no offset to apply!
 
   SmallVector indices(op_cursor, op_end);
-
   Type *src_elem_ty =
   cast(constant_expr)->getSourceElementType();
+
+  // DataLayout::getIndexedOffsetInType assumes the indices are
+  // instances of ConstantInt.
   uint64_t offset =
   m_target_data.getIndexedOffsetInType(src_elem_ty, indices);
 
@@ -465,12 +467,20 @@
   case Instruction::BitCast:
 return CanResolveConstant(constant_expr->getOperand(0));
   case Instruction::GetElementPtr: {
+// Check that the base can be constant-resolved.
 ConstantExpr::const_op_iterator op_cursor = constant_expr->op_begin();
 Constant *base = dyn_cast(*op_cursor);
-if (!base)
+if (!base || !CanResolveConstant(base))
   return false;
 
-return CanResolveConstant(base);
+// Check that all other operands are just ConstantInt.
+for (Value *op : make_range(constant_expr->op_begin() + 1,
+constant_expr->op_end())) {
+  ConstantInt *constant_int = dyn_cast(op);
+  if (!constant_int)
+return false;
+}
+return true;
   }
   }
 } else {


Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org/show_bug.cgi?id=52449
+"""
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... i64 ptrtoint (i32* @_ZN1A3s_cE to i64)) ...
+expr = "(int*)100 + (long long)(&A::s_c)"
+
+# The IR interpreter doesn't support non-const operands to the
+# `GetElementPtr` IR instruction, so verify that it correctly fails to
+# evaluate expression.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertTrue(value.G

[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2021-11-17 Thread Andy Yankovsky via Phabricator via lldb-commits
werat marked 2 inline comments as done.
werat added a comment.

In D113498#3137196 , @teemperor wrote:

> Not sure how flexible your fuzzer setup is regarding downstream patches, but 
> did you try putting some kind of `assert("coverage" && false);` in that new 
> code and try fuzzing until you reach it?

It's not that flexible, it runs against the prebuilt version of LLVM 12 at the 
moment -- https://github.com/google/lldb-eval/releases/tag/oss-fuzz-ubuntu-20.04

> FWIW, I'm OOO for an undefined amount of time so I am not sure when I can 
> take a look at this again. Feel free to ping in case you don't find another 
> reviewer.

Sure, I'll try to find someone else for now. Will ping if nobody comes along :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2021-11-18 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D113498#3139112 , @shafik wrote:

> On the other hand this is a well-formed constant expression:
>
>   static const int x =0;
>   constexpr const int* ip1 = &x + 1;
>
> Does that get you the test case you need?

This expression seems to be similar to what I have in the test case now.

  (lldb) p static const int x = 0; constexpr const int* ip1 = &x + 1;
  ...
  ; Function Attrs: convergent noinline nounwind optnone
  define dso_local void @"?$__lldb_expr@@YAXPEAX@Z"(i8* %"$__lldb_arg") #0 {
  entry:
%"$__lldb_arg.addr" = alloca i8*, align 8, !clang.decl.ptr !9
%ip1 = alloca i32*, align 8, !clang.decl.ptr !10
store i8* %"$__lldb_arg", i8** %"$__lldb_arg.addr", align 8
store i32* bitcast (i8* getelementptr (i8, i8* bitcast (i32* 
@"?x@?1??$__lldb_expr@@YAXPEAX@Z@4HB" to i8*), i64 4) to i32*), i32** %ip1, 
align 8
ret void
  }

As far as I understand, `getelementptr (i8, i8* bitcast (i32* 
@"?x@?1??$__lldb_expr@@YAXPEAX@Z@4HB" to i8*), i64 4)` is a well-formed 
constant expression, however it has `GlobalVariableVal` as one of it's operand. 
Even though `GlobalVariableVal` is `Constant`, I think it's not always possible 
to resolve its value (please correct me if that's not true, not very familiar 
with IR). Even if there's a way, it's not currently implemented in the 
IRInterpreter -- `CanResolveConstant` will return false when it sees 
`GlobalVariableVal`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D112147: [lldb] Fix lookup for global constants in namespaces

2021-11-23 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf66b69a3925c: [lldb] Fix lookup for global constants in 
namespaces (authored by tonkosi, committed by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112147

Files:
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/test/API/lang/cpp/global_variables/TestCPPGlobalVariables.py
  lldb/test/API/lang/cpp/global_variables/main.cpp


Index: lldb/test/API/lang/cpp/global_variables/main.cpp
===
--- lldb/test/API/lang/cpp/global_variables/main.cpp
+++ lldb/test/API/lang/cpp/global_variables/main.cpp
@@ -1,10 +1,17 @@
 #include 
 
 namespace abc {
-   int g_file_global_int = 42;
+int g_file_global_int = 42;
+const int g_file_global_const_int = 1337;
+
+namespace {
+const int g_anon_namespace_const_int = 100;
+}
 }
 
 int main (int argc, char const *argv[])
 {
-return abc::g_file_global_int; // Set break point at this line.
+  int unused = abc::g_file_global_const_int;
+  int unused2 = abc::g_anon_namespace_const_int;
+  return abc::g_file_global_int; // Set break point at this line.
 }
Index: lldb/test/API/lang/cpp/global_variables/TestCPPGlobalVariables.py
===
--- lldb/test/API/lang/cpp/global_variables/TestCPPGlobalVariables.py
+++ lldb/test/API/lang/cpp/global_variables/TestCPPGlobalVariables.py
@@ -15,12 +15,11 @@
 TestBase.setUp(self)
 self.source = lldb.SBFileSpec('main.cpp')
 
-@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764")
 def test(self):
 self.build()
 
 (target, _, _, _) = lldbutil.run_to_source_breakpoint(self, "// Set 
break point at this line.", self.source)
-
+
 # Check that we can access g_file_global_int by its name
 self.expect("target variable g_file_global_int", 
VARIABLES_DISPLAYED_CORRECTLY,
 substrs=['42'])
@@ -29,6 +28,30 @@
 self.expect("target variable xyz::g_file_global_int", 
VARIABLES_DISPLAYED_CORRECTLY,
 error=True, substrs=['can\'t find global variable'])
 
+# Check that we can access g_file_global_const_int by its name
+self.expect("target variable g_file_global_const_int", 
VARIABLES_DISPLAYED_CORRECTLY,
+substrs=['1337'])
+self.expect("target variable abc::g_file_global_const_int", 
VARIABLES_DISPLAYED_CORRECTLY,
+substrs=['1337'])
+self.expect("target variable xyz::g_file_global_const_int", 
VARIABLES_DISPLAYED_CORRECTLY,
+error=True, substrs=['can\'t find global variable'])
+
+# Try accessing a global variable in anonymous namespace.
+self.expect("target variable g_anon_namespace_const_int", 
VARIABLES_DISPLAYED_CORRECTLY,
+substrs=['100'])
+self.expect("target variable abc::g_anon_namespace_const_int", 
VARIABLES_DISPLAYED_CORRECTLY,
+error=True, substrs=['can\'t find global variable'])
+var = target.FindFirstGlobalVariable("abc::(anonymous 
namespace)::g_anon_namespace_const_int")
+self.assertTrue(var.IsValid())
+self.assertEqual(var.GetName(), "abc::(anonymous 
namespace)::g_anon_namespace_const_int")
+self.assertEqual(var.GetValue(), "100")
+
+@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764")
+def test_access_by_mangled_name(self):
+self.build()
+
+(target, _, _, _) = lldbutil.run_to_source_breakpoint(self, "// Set 
break point at this line.", self.source)
+
 # Check that we can access g_file_global_int by its mangled name
 addr = 
target.EvaluateExpression("&abc::g_file_global_int").GetValueAsUnsigned()
 self.assertNotEqual(addr, 0)
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3271,15 +3271,14 @@
   }
 
   const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
-  const dw_tag_t parent_tag = die.GetParent().Tag();
+  const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
+  const dw_tag_t parent_tag = sc_parent_die.Tag();
   bool is_static_member = (parent_tag == DW_TAG_compile_unit ||
parent_tag == DW_TAG_partial_unit) &&
   (parent_context_die.Tag() == DW_TAG_class_type ||
parent_context_die.Tag() == DW_TAG_structure_type);
 
   ValueType scope = eValueTypeInvalid;
-
-  const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
   SymbolContextScope *symbol_context_scope = nullptr;
 
   bool has_explicit_mangled = mangled != nullptr;


Index:

[Lldb-commits] [PATCH] D114627: [lldb] add new overload for SymbolFile::FindTypes that accepts a scope

2021-11-26 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2464
 
+const char *qn = die.GetQualifiedName(s);
+if (strncmp(sc, qn, strlen(sc)))

Can `GetQualifiedName` return `NULL` string?



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2464-2465
 
+const char *qn = die.GetQualifiedName(s);
+if (strncmp(sc, qn, strlen(sc)))
+  return true;

werat wrote:
> Can `GetQualifiedName` return `NULL` string?
We can skip this check altogether if the `scope` is empty.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2465
+const char *qn = die.GetQualifiedName(s);
+if (strncmp(sc, qn, strlen(sc)))
+  return true;

There's no need to calculate length on every iteration.

Also you can make `sc` an `llvm::StringRef` and do something like 
`StringRef(s).startswith(sc)`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114627

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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2021-12-03 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

@shafik ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D115033: [lldb-vscode] Report supportsModulesRequest=true

2021-12-03 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The adapter does support `Modules` request, implemented in 39239f9 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115033

Files:
  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
@@ -1505,7 +1505,7 @@
   // is the behavior of LLDB CLI, that expects a TAB.
   body.try_emplace("supportsCompletionsRequest", false);
   // The debug adapter supports the modules request.
-  body.try_emplace("supportsModulesRequest", false);
+  body.try_emplace("supportsModulesRequest", true);
   // The set of additional module information exposed by the debug adapter.
   //   body.try_emplace("additionalModuleColumns"] = ColumnDescriptor
   // Checksum algorithms supported by the debug adapter.


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1505,7 +1505,7 @@
   // is the behavior of LLDB CLI, that expects a TAB.
   body.try_emplace("supportsCompletionsRequest", false);
   // The debug adapter supports the modules request.
-  body.try_emplace("supportsModulesRequest", false);
+  body.try_emplace("supportsModulesRequest", true);
   // The set of additional module information exposed by the debug adapter.
   //   body.try_emplace("additionalModuleColumns"] = ColumnDescriptor
   // Checksum algorithms supported by the debug adapter.
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D132734: [lldb] Fix member access in GetExpressionPath

2023-11-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D132734#3887018 , @JDevlieghere 
wrote:

> Thanks Will, let me apply this locally and see if that addresses the issue 
> for which I reverted the original patch.

Hy Jonas, sorry for bumping an old thread, but did you manage to check if the 
latest revision fixes the issue?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132734

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


[Lldb-commits] [PATCH] D132734: [lldb] Fix member access in GetExpressionPath

2022-09-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat accepted this revision.
werat added reviewers: clayborg, granata.enrico.
werat added a comment.
This revision is now accepted and ready to land.

Nice fix! It would be nice to remove redundant parenthesis, e.g. 
`(*(ptr)).member -> (*ptr).member`, but I see this is non-trivial with the 
current logic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132734

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


[Lldb-commits] [PATCH] D133689: [lldb] Add SBBreakpointLocation::SetCallback

2022-09-12 Thread Andy Yankovsky via Phabricator via lldb-commits
werat accepted this revision.
werat added a comment.
This revision is now accepted and ready to land.

Look good to me, but giving some time for others to take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133689

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


[Lldb-commits] [PATCH] D133689: [lldb] Add SBBreakpointLocation::SetCallback

2022-09-12 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f5d109fca23: [lldb] Add SBBreakpointLocation::SetCallback 
(authored by lauralcg, committed by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133689

Files:
  lldb/include/lldb/API/SBBreakpointLocation.h
  lldb/source/API/SBBreakpointLocation.cpp
  lldb/test/API/api/multithreaded/TestMultithreaded.py
  lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp.template

Index: lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp.template
===
--- /dev/null
+++ lldb/test/API/api/multithreaded/test_breakpoint_location_callback.cpp.template
@@ -0,0 +1,52 @@
+
+// LLDB C++ API Test: verify that the function registered with
+// SBBreakpoint.SetCallback() is invoked when a breakpoint is hit.
+
+#include 
+#include 
+#include 
+#include 
+
+%include_SB_APIs%
+
+#include "common.h"
+
+using namespace std;
+using namespace lldb;
+
+mutex g_mutex;
+condition_variable g_condition;
+int g_breakpoint_hit_count = 0;
+
+bool BPCallback (void *baton,
+ SBProcess &process,
+ SBThread &thread,
+ SBBreakpointLocation &location) {
+  lock_guard lock(g_mutex);
+  g_breakpoint_hit_count += 1;
+  g_condition.notify_all();
+  return true;
+}
+
+void test(SBDebugger &dbg, vector args) {
+  dbg.SetAsync(false);
+  SBTarget target = dbg.CreateTarget(args.at(0).c_str());
+  if (!target.IsValid()) throw Exception("invalid target");
+
+  SBBreakpoint breakpoint = target.BreakpointCreateByName("next");
+  if (!breakpoint.IsValid()) throw Exception("invalid breakpoint");
+
+  if(breakpoint.GetNumLocations() != 1) throw Exception("unexpected amount of breakpoint locations");
+  SBBreakpointLocation breakpoint_location = breakpoint.GetLocationAtIndex(0);
+  breakpoint_location.SetCallback(BPCallback, 0);
+
+  std::unique_ptr working_dir(get_working_dir());
+  SBProcess process = target.LaunchSimple (0, 0, working_dir.get());
+
+  {
+unique_lock lock(g_mutex);
+g_condition.wait_for(lock, chrono::seconds(5));
+if (g_breakpoint_hit_count != 1)
+  throw Exception("Breakpoint hit count expected to be 1");
+  }
+}
Index: lldb/test/API/api/multithreaded/TestMultithreaded.py
===
--- lldb/test/API/api/multithreaded/TestMultithreaded.py
+++ lldb/test/API/api/multithreaded/TestMultithreaded.py
@@ -18,6 +18,7 @@
 self.generateSource('driver.cpp')
 self.generateSource('listener_test.cpp')
 self.generateSource('test_breakpoint_callback.cpp')
+self.generateSource('test_breakpoint_location_callback.cpp')
 self.generateSource('test_listener_event_description.cpp')
 self.generateSource('test_listener_event_process_state.cpp')
 self.generateSource('test_listener_resume.cpp')
@@ -41,6 +42,15 @@
 self.build_and_test('driver.cpp test_breakpoint_callback.cpp',
 'test_breakpoint_callback')
 
+@skipIfRemote
+@skipIfNoSBHeaders
+# clang-cl does not support throw or catch (llvm.org/pr24538)
+@skipIfWindows
+def test_breakpoint_location_callback(self):
+"""Test the that SBBreakpointLocation callback is invoked when a breakpoint is hit. """
+self.build_and_test('driver.cpp test_breakpoint_location_callback.cpp',
+'test_breakpoint_location_callback')
+
 @skipIfRemote
 @skipIfNoSBHeaders
 # clang-cl does not support throw or catch (llvm.org/pr24538)
Index: lldb/source/API/SBBreakpointLocation.cpp
===
--- lldb/source/API/SBBreakpointLocation.cpp
+++ lldb/source/API/SBBreakpointLocation.cpp
@@ -28,6 +28,8 @@
 #include "lldb/lldb-defines.h"
 #include "lldb/lldb-types.h"
 
+#include "SBBreakpointOptionCommon.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -198,6 +200,21 @@
   return false;
 }
 
+void SBBreakpointLocation::SetCallback(SBBreakpointHitCallback callback,
+   void *baton) {
+  LLDB_INSTRUMENT_VA(this, callback, baton);
+
+  BreakpointLocationSP loc_sp = GetSP();
+
+  if (loc_sp) {
+std::lock_guard guard(
+loc_sp->GetTarget().GetAPIMutex());
+BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
+loc_sp->SetCallback(SBBreakpointCallbackBaton::PrivateBreakpointHitCallback,
+baton_sp, false);
+  }
+}
+
 void SBBreakpointLocation::SetScriptCallbackFunction(
   const char *callback_function_name) {
   LLDB_INSTRUMENT_VA(this, callback_function_name);
Index: lldb/include/lldb/API/SBBreakpointLocation.h
===
--- lldb/include/lldb/API/SBBreakpointLocation.h
+++ lldb/include/l

[Lldb-commits] [PATCH] D134493: [lldb][TypeSystemClang] Deduce lldb::eEncodingUint for unsigned enum types

2022-09-23 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

On a somewhat related note, is it expected that `GetValueAsUnsigned()` performs 
an overflow as `int32` if the type is smaller that `int64`?

  ❯ cat overflow.cc 
  #include 
  int main() {
int8_t i8 = -1;
int32_t i32 = -1;
int64_t i64 = -1;
return 0;
  }
  
  (lldb) script
  
  >>> lldb.frame.FindVariable("i8").GetValueAsUnsigned()
  4294967295
  >>> lldb.frame.FindVariable("i32").GetValueAsUnsigned()
  4294967295
  >>> lldb.frame.FindVariable("i64").GetValueAsUnsigned()
  18446744073709551615
  >>>




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134493

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


[Lldb-commits] [PATCH] D134493: [lldb][TypeSystemClang] Deduce lldb::eEncodingUint for unsigned enum types

2022-09-26 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D134493#3811253 , @labath wrote:

> lol, I knew about the last two parts (not that I agree with them, but I think 
> we have about an equal amount of code which relies on it, and that which 
> tries to work around it), but the first one is really weird. I think we have 
> invented a middle ground between sign- and zero-extension.

haha, so this mean no chance of fixing this? I have a workaround for this as 
well -- 
https://github.com/google/lldb-eval/blob/04a73616c012c3dac7fb11206511bd2a9fe16db4/lldb-eval/value.cc#L146
I can live with that, but current behaviour does look like a bug.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134493

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


[Lldb-commits] [PATCH] D134493: [lldb][TypeSystemClang] Deduce lldb::eEncodingUint for unsigned enum types

2022-09-28 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.



In D134493#3819710 , @shafik wrote:

> Note, in both C and C++ converting a `-1` to unsigned will always result in 
> the max unsigned value e.g.:

When you convert to "unsigned" then yeah, but here the API is `uint64_t 
GetAsUnsigned()`. I would expect this to be the equivalent of converting to 
`uint64_t`, not `unsigned`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134493

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


[Lldb-commits] [PATCH] D132734: [lldb] Fix member access in GetExpressionPath

2022-09-30 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG14642dc7405e: [lldb] Fix member access in GetExpressionPath 
(authored by tonkosi, committed by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132734

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/test/API/python_api/expression_path/Makefile
  lldb/test/API/python_api/expression_path/TestExpressionPath.py
  lldb/test/API/python_api/expression_path/main.cpp

Index: lldb/test/API/python_api/expression_path/main.cpp
===
--- /dev/null
+++ lldb/test/API/python_api/expression_path/main.cpp
@@ -0,0 +1,34 @@
+struct StructA {
+  int x;
+  int y;
+};
+
+struct StructB {
+  int x;
+  StructA &a_ref;
+  StructA *&a_ptr_ref;
+};
+
+struct StructC : public StructB {
+  int y;
+
+  StructC(int x, StructA &a_ref, StructA *&a_ref_ptr, int y)
+  : StructB{x, a_ref, a_ref_ptr}, y(y) {}
+};
+
+int main() {
+  StructA a{1, 2};
+  StructA *a_ptr = &a;
+
+  StructB b{3, a, a_ptr};
+  StructB *b_ptr = &b;
+  StructB &b_ref = b;
+  StructB *&b_ptr_ref = b_ptr;
+
+  StructC c(4, a, a_ptr, 5);
+  StructC *c_ptr = &c;
+  StructC &c_ref = c;
+  StructC *&c_ptr_ref = c_ptr;
+
+  return 0; // Set breakpoint here
+}
\ No newline at end of file
Index: lldb/test/API/python_api/expression_path/TestExpressionPath.py
===
--- /dev/null
+++ lldb/test/API/python_api/expression_path/TestExpressionPath.py
@@ -0,0 +1,119 @@
+"""Test that SBFrame::GetExpressionPath construct valid expressions"""
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class SBValueGetExpressionPathTest(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+def path(self, value):
+"""Constructs the expression path given the SBValue"""
+if not value:
+return None
+stream = lldb.SBStream()
+if not value.GetExpressionPath(stream):
+return None
+return stream.GetData()
+
+def test_expression_path(self):
+"""Test that SBFrame::GetExpressionPath construct valid expressions"""
+self.build()
+self.setTearDownCleanup()
+
+exe = self.getBuildArtifact("a.out")
+
+# Create the target
+target = self.dbg.CreateTarget(exe)
+self.assertTrue(target, VALID_TARGET)
+
+# Set the breakpoints
+breakpoint = target.BreakpointCreateBySourceRegex(
+'Set breakpoint here', lldb.SBFileSpec("main.cpp"))
+self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)
+
+# Launch the process, and do not stop at the entry point.
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory())
+
+self.assertTrue(process, PROCESS_IS_VALID)
+
+# Frame #0 should be at our breakpoint.
+threads = lldbutil.get_threads_stopped_at_breakpoint(
+process, breakpoint)
+
+self.assertEquals(len(threads), 1)
+self.thread = threads[0]
+self.frame = self.thread.frames[0]
+self.assertTrue(self.frame, "Frame 0 is valid.")
+
+# Find "b" variables in frame
+b = self.frame.FindVariable("b")
+bp = self.frame.FindVariable("b_ptr")
+br = self.frame.FindVariable("b_ref")
+bpr = self.frame.FindVariable("b_ptr_ref")
+# Check expression paths
+self.assertEqual(self.path(b), "b")
+self.assertEqual(self.path(bp), "b_ptr")
+self.assertEqual(self.path(br), "b_ref")
+self.assertEqual(self.path(bpr), "b_ptr_ref")
+
+# Dereference "b" pointers
+bp_deref = bp.Dereference()
+bpr_deref = bpr.Dereference()  # a pointer
+bpr_deref2 = bpr_deref.Dereference()  # two Dereference() calls to get object
+# Check expression paths
+self.assertEqual(self.path(bp_deref), "*(b_ptr)")
+self.assertEqual(self.path(bpr_deref), "b_ptr_ref")
+self.assertEqual(self.path(bpr_deref2), "*(b_ptr_ref)")
+
+# Access "b" members and check expression paths
+self.assertEqual(self.path(b.GetChildMemberWithName("x")), "b.x")
+self.assertEqual(self.path(bp.GetChildMemberWithName("x")), "b_ptr->x")
+self.assertEqual(self.path(br.GetChildMemberWithName("x")), "b_ref.x")
+self.assertEqual(self.path(bp_deref.GetChildMemberWithName("x")), "(*(b_ptr)).x")
+self.assertEqual(self.path(bpr_deref.GetChildMemberWithName("x")), "b_ptr_ref->x")
+self.assertEqual(self.path(bpr_deref2.GetChildMemberWithName("x")), "(*(b_ptr_ref)).x")
+# TODO: Uncomment once accessing members on pointer references is supported.
+# self.assertEqual(self.path(bpr.Ge

[Lldb-commits] [PATCH] D132734: [lldb] Fix member access in GetExpressionPath

2022-09-30 Thread Andy Yankovsky via Phabricator via lldb-commits
werat reopened this revision.
werat added a comment.
This revision is now accepted and ready to land.

In D132734#3827245 , @mib wrote:

> Let me know if you need help reproducing and fixing these issues, otherwise 
> I'll have to revert your patch.

Sorry for the breaking the tests. We won't be able to look into this until next 
week, I've reverted the change for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132734

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


[Lldb-commits] [PATCH] D132734: [lldb] Fix member access in GetExpressionPath

2022-10-12 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0205aa4a0257: [lldb] Fix member access in GetExpressionPath 
(authored by tonkosi, committed by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132734

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py
  lldb/test/API/python_api/expression_path/Makefile
  lldb/test/API/python_api/expression_path/TestExpressionPath.py
  lldb/test/API/python_api/expression_path/main.cpp

Index: lldb/test/API/python_api/expression_path/main.cpp
===
--- /dev/null
+++ lldb/test/API/python_api/expression_path/main.cpp
@@ -0,0 +1,34 @@
+struct StructA {
+  int x;
+  int y;
+};
+
+struct StructB {
+  int x;
+  StructA &a_ref;
+  StructA *&a_ptr_ref;
+};
+
+struct StructC : public StructB {
+  int y;
+
+  StructC(int x, StructA &a_ref, StructA *&a_ref_ptr, int y)
+  : StructB{x, a_ref, a_ref_ptr}, y(y) {}
+};
+
+int main() {
+  StructA a{1, 2};
+  StructA *a_ptr = &a;
+
+  StructB b{3, a, a_ptr};
+  StructB *b_ptr = &b;
+  StructB &b_ref = b;
+  StructB *&b_ptr_ref = b_ptr;
+
+  StructC c(4, a, a_ptr, 5);
+  StructC *c_ptr = &c;
+  StructC &c_ref = c;
+  StructC *&c_ptr_ref = c_ptr;
+
+  return 0; // Set breakpoint here
+}
\ No newline at end of file
Index: lldb/test/API/python_api/expression_path/TestExpressionPath.py
===
--- /dev/null
+++ lldb/test/API/python_api/expression_path/TestExpressionPath.py
@@ -0,0 +1,119 @@
+"""Test that SBFrame::GetExpressionPath construct valid expressions"""
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class SBValueGetExpressionPathTest(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+def path(self, value):
+"""Constructs the expression path given the SBValue"""
+if not value:
+return None
+stream = lldb.SBStream()
+if not value.GetExpressionPath(stream):
+return None
+return stream.GetData()
+
+def test_expression_path(self):
+"""Test that SBFrame::GetExpressionPath construct valid expressions"""
+self.build()
+self.setTearDownCleanup()
+
+exe = self.getBuildArtifact("a.out")
+
+# Create the target
+target = self.dbg.CreateTarget(exe)
+self.assertTrue(target, VALID_TARGET)
+
+# Set the breakpoints
+breakpoint = target.BreakpointCreateBySourceRegex(
+'Set breakpoint here', lldb.SBFileSpec("main.cpp"))
+self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)
+
+# Launch the process, and do not stop at the entry point.
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory())
+
+self.assertTrue(process, PROCESS_IS_VALID)
+
+# Frame #0 should be at our breakpoint.
+threads = lldbutil.get_threads_stopped_at_breakpoint(
+process, breakpoint)
+
+self.assertEquals(len(threads), 1)
+self.thread = threads[0]
+self.frame = self.thread.frames[0]
+self.assertTrue(self.frame, "Frame 0 is valid.")
+
+# Find "b" variables in frame
+b = self.frame.FindVariable("b")
+bp = self.frame.FindVariable("b_ptr")
+br = self.frame.FindVariable("b_ref")
+bpr = self.frame.FindVariable("b_ptr_ref")
+# Check expression paths
+self.assertEqual(self.path(b), "b")
+self.assertEqual(self.path(bp), "b_ptr")
+self.assertEqual(self.path(br), "b_ref")
+self.assertEqual(self.path(bpr), "b_ptr_ref")
+
+# Dereference "b" pointers
+bp_deref = bp.Dereference()
+bpr_deref = bpr.Dereference()  # a pointer
+bpr_deref2 = bpr_deref.Dereference()  # two Dereference() calls to get object
+# Check expression paths
+self.assertEqual(self.path(bp_deref), "*b_ptr")
+self.assertEqual(self.path(bpr_deref), "b_ptr_ref")
+self.assertEqual(self.path(bpr_deref2), "*b_ptr_ref")
+
+# Access "b" members and check expression paths
+self.assertEqual(self.path(b.GetChildMemberWithName("x")), "b.x")
+self.assertEqual(self.path(bp.GetChildMemberWithName("x")), "b_ptr->x")
+self.assertEqual(self.path(br.GetChildMemberWithName("x")), "b_ref.x")
+self.assertEqual(self.path(bp_deref.GetChildMemberWithName("x")), "(*b_ptr).x")
+self.assertEqual(self.path(bpr_deref.GetChildMemberWithName("x")), "b_ptr_ref->x")
+self.assertEqual(self.path(bpr_deref2.GetChildMemberWithName("x")), "(*b_ptr_ref).x")
+# TODO: Uncomment once accessing m

[Lldb-commits] [PATCH] D103454: [lldb][docs] Document SBType

2021-06-02 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

Is this code used for auto-generated docs? Could be have this documentation in 
C++ definitions (lldb/API/SBType.h) as well? I usually just read the C++ source 
code, but I can imagine having the same docs in two places might be not the 
best idea...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103454

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


[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

2021-07-06 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat added a reviewer: teemperor.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Children of ValueObject automatically update themselves when they detect
the state of the process has changed, which typically happens when the
parent value is updated. However, if in case of updating
ValueObjectConstResult the process state is unchanged and the children
remain stale.

Explicitly clear the children upon the parent update, so that they're
re-calculated afterwards.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105470

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
  lldb/test/API/python_api/value/change_values/main.c


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar *b1 = (struct bar *) malloc (sizeof (struct bar));
+  b1->value = 1;
+  struct bar *b2 = (struct bar *) malloc (sizeof (struct bar));
+  b2->value = 2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,23 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+b = frame0.EvaluateExpression("auto $b_0 = b1; $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(
+b.GetChildAtIndex(0, lldb.eNoDynamicValues, True).GetValue(),
+"1")
+
+b.SetValueFromCString(frame0.FindVariable("b2").GetValue())
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(
+b.GetChildAtIndex(0, lldb.eNoDynamicValues, True).GetValue(),
+"2")
+
 # gcc may set multiple locations for breakpoint
 breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -231,6 +231,10 @@
   // We have to clear the value string here so ConstResult children will notice
   // if their values are changed by hand (i.e. with SetValueAsCString).
   ClearUserVisibleData(eClearUserVisibleDataItemsValue);
+  // Children have to be re-computed after updating the parent value.
+  m_flags.m_children_count_valid = false;
+  m_children.Clear();
+  SetSyntheticChildren(lldb::SyntheticChildrenSP());
 }
 
 void ValueObject::ClearDynamicTypeInformation() {


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar *b1 = (struct bar *) malloc (sizeof (struct bar));
+  b1->value = 1;
+  struct bar *b2 = (struct bar *) malloc (sizeof (struct bar));
+  b2->value = 2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,23 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+b = frame0.EvaluateExpression("auto $b_0 = b1; $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(
+b.GetChildAtIndex(0, lldb.eNoDynamicValues, Tr

[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

2021-07-06 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 356663.
werat added a comment.
Herald added a subscriber: JDevlieghere.

Simplify the test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105470

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
  lldb/test/API/python_api/value/change_values/main.c


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar *b1 = (struct bar *) malloc (sizeof (struct bar));
+  b1->value = 1;
+  struct bar *b2 = (struct bar *) malloc (sizeof (struct bar));
+  b2->value = 2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,19 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+b = frame0.EvaluateExpression("auto $b_0 = b1; $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "1")
+
+b.SetValueFromCString(frame0.FindVariable("b2").GetValue())
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "2")
+
 # gcc may set multiple locations for breakpoint
 breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -231,6 +231,10 @@
   // We have to clear the value string here so ConstResult children will notice
   // if their values are changed by hand (i.e. with SetValueAsCString).
   ClearUserVisibleData(eClearUserVisibleDataItemsValue);
+  // Children have to be re-computed after updating the parent value.
+  m_flags.m_children_count_valid = false;
+  m_children.Clear();
+  SetSyntheticChildren(lldb::SyntheticChildrenSP());
 }
 
 void ValueObject::ClearDynamicTypeInformation() {


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar *b1 = (struct bar *) malloc (sizeof (struct bar));
+  b1->value = 1;
+  struct bar *b2 = (struct bar *) malloc (sizeof (struct bar));
+  b2->value = 2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,19 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+b = frame0.EvaluateExpression("auto $b_0 = b1; $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "1")
+
+b.SetValueFromCString(frame0.FindVariable("b2").GetValue())
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "2")
+
 # gcc may set multiple locations for breakpoint
 breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/

[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

2021-07-06 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 356677.
werat added a comment.

Use local variables in test
Assert for SetValueFromCString


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105470

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
  lldb/test/API/python_api/value/change_values/main.c


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct bar *b1 = &_b1;
+  struct bar *b2 = &_b2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,20 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+b = frame0.EvaluateExpression("auto $b_0 = b1; $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "1")
+
+result = b.SetValueFromCString(frame0.FindVariable("b2").GetValue())
+self.assertTrue(result, "Success setting $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "2")
+
 # gcc may set multiple locations for breakpoint
 breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -231,6 +231,10 @@
   // We have to clear the value string here so ConstResult children will notice
   // if their values are changed by hand (i.e. with SetValueAsCString).
   ClearUserVisibleData(eClearUserVisibleDataItemsValue);
+  // Children have to be re-computed after updating the parent value.
+  m_flags.m_children_count_valid = false;
+  m_children.Clear();
+  SetSyntheticChildren(lldb::SyntheticChildrenSP());
 }
 
 void ValueObject::ClearDynamicTypeInformation() {


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct bar *b1 = &_b1;
+  struct bar *b2 = &_b2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,20 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+b = frame0.EvaluateExpression("auto $b_0 = b1; $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "1")
+
+result = b.SetValueFromCString(frame0.FindVariable("b2").GetValue())
+self.assertTrue(result, "Success setting $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "2")
+
 # gcc may set multiple locations for breakpoint
 breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/so

[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

2021-07-08 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a reviewer: jingham.
werat added a comment.

Jim, can you take a look, please?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105470

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


[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

2021-07-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

Thanks for the prompt review!

> This change is wrong for ValueObjectConstResult's. The original point of 
> ValueObjectConstResult's was to store the results of expressions so that, 
> even if the process is not at the original stop point, you could still check 
> the value. It should have the value it had at the time the expression was 
> evaluated. Updating the value is exactly what you don't want to do. So I 
> think you need to make sure that we can't change their value after they are 
> created.

Looking at the current state of things and the available APIs, I don't think 
this principle holds anymore. `ValueObjectConstResult` is also used for values 
created via `SBTarget::CreateValueFromData`. As a user I don't see any reason 
why I shouldn't be allowed to modify the value of an object I created myself 
earlier. I would argue the same for the results of the expression evaluation. 
Why are some values different from others?

> Note, ExpressionResult variables are different from 
> ExpressionPersistentVariables. The former should not be updated, and after 
> the process moves on any children that weren't gathered become "unknown". But 
> ExpressionPersistentVariables should be able to be assigned to, and when the 
> reference target object, it should update them live. .

Please, correct me if I'm wrong. In my example `ExpressionResult` is a value 
returned by `EvaluateExpression` (i.e. `b`) and `ExpressionPersistentVariable` 
is variable created by the expression evaluator (i.e. `$b_0`), right? As far as 
I can tell, they're both `ValueObjectConstResult` and both have the problem 
outlined in this patch:

  frame0.EvaluateExpression("auto $b_0 = b1")
  b = frame0.FindValue("$b_0", lldb.eValueTypeConstResult)
  ...
  # Same problem, updating the value of `b` doesn't invalidate children.



> The other thing to check about this patch is whether it defeats detecting 
> changed values in child elements.

This patch invalidates children only in `ValueObject::SetNeedsUpdate()` which 
is called only from `SetData/SetValueFromCString` as far as I understand. If 
you have a `ValueObjectVariable` which tracks some variable that can be 
modified by the process, then it will continue to work fine. 
`TestValueVarUpdate.py` passes successfully, but I didn't look to0 closely yet 
whether it actually tests the scenario you described.

---

Looking at this from the user perspective, I would prefer to be able to update 
any value, regardless of which API it came from. In my use case I rely on this 
heavily -- 
https://werat.dev/blog/blazing-fast-expression-evaluation-for-c-in-lldb/#maintaning-state.
I could potentially live with the results of `EvaluateExpression` being 
immutable, but being able to modify values created by `CreateValueFromData` or 
persistent values like `$b_0` is necessary for me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105470

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


[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

2021-07-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 357477.
werat added a comment.

Add a test for a value created via `SBTarget::CreateValueFromData`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105470

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
  lldb/test/API/python_api/value/change_values/main.c


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct bar *b1 = &_b1;
+  struct bar *b2 = &_b2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,20 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+b = frame0.EvaluateExpression("auto $b_0 = b1; $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "1")
+
+result = b.SetValueFromCString(frame0.FindVariable("b2").GetValue())
+self.assertTrue(result, "Success setting $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "2")
+
 # gcc may set multiple locations for breakpoint
 breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -231,6 +231,10 @@
   // We have to clear the value string here so ConstResult children will notice
   // if their values are changed by hand (i.e. with SetValueAsCString).
   ClearUserVisibleData(eClearUserVisibleDataItemsValue);
+  // Children have to be re-computed after updating the parent value.
+  m_flags.m_children_count_valid = false;
+  m_children.Clear();
+  SetSyntheticChildren(lldb::SyntheticChildrenSP());
 }
 
 void ValueObject::ClearDynamicTypeInformation() {


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct bar *b1 = &_b1;
+  struct bar *b2 = &_b2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,20 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+b = frame0.EvaluateExpression("auto $b_0 = b1; $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "1")
+
+result = b.SetValueFromCString(frame0.FindVariable("b2").GetValue())
+self.assertTrue(result, "Success setting $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "2")
+
 # gcc may set multiple locations for breakpoint
 breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===
--

[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

2021-07-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 357478.
werat added a comment.

Add a test for a value created via `SBTarget::CreateValueFromData`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105470

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
  lldb/test/API/python_api/value/change_values/main.c


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct bar *b1 = &_b1;
+  struct bar *b2 = &_b2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,44 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+
+# Test for 'b' -- value created by the expression evaluator.
+b = frame0.EvaluateExpression("auto $b_0 = b1; $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "1")
+
+result = b.SetValueFromCString(frame0.FindVariable("b2").GetValue())
+self.assertTrue(result, "Success setting $b_0")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "2")
+
+# Test for 'b' -- value created by SBTarget::CreateValueFromData.
+b1 = frame0.FindVariable("b1")
+b1_addr_bytes = b1.GetValueAsUnsigned().to_bytes(
+b1.GetByteSize(),
+'little' if process.GetByteOrder() == lldb.eByteOrderLittle else 
'big')
+error = lldb.SBError()
+data = lldb.SBData()
+data.SetData(
+error, b1_addr_bytes, process.GetByteOrder(), b1.GetByteSize())
+b = target.CreateValueFromData("b", data, b1.GetType())
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "1")
+
+result = b.SetValueFromCString(frame0.FindVariable("b2").GetValue())
+self.assertTrue(result, "Success setting b")
+self.assertEquals(
+b.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(b.GetChildAtIndex(0).GetValue(), "2")
+
 # gcc may set multiple locations for breakpoint
 breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -231,6 +231,10 @@
   // We have to clear the value string here so ConstResult children will notice
   // if their values are changed by hand (i.e. with SetValueAsCString).
   ClearUserVisibleData(eClearUserVisibleDataItemsValue);
+  // Children have to be re-computed after updating the parent value.
+  m_flags.m_children_count_valid = false;
+  m_children.Clear();
+  SetSyntheticChildren(lldb::SyntheticChildrenSP());
 }
 
 void ValueObject::ClearDynamicTypeInformation() {


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct bar *b1 = &_b1;
+  struct bar *b2 = &_b2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_va

[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

2021-07-10 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 357710.
werat added a comment.

Add more test cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105470

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
  lldb/test/API/python_api/value/change_values/main.c


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct bar *b1 = &_b1;
+  struct bar *b2 = &_b2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,41 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+def test_update_parent_value(parent):
+self.assertEquals(
+parent.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(parent.GetChildAtIndex(0).GetValue(), "1")
+
+result = parent.SetValueFromCString(
+frame0.FindVariable("b2").GetValue())
+self.assertTrue(result, "Success setting {}".format(parent.name))
+self.assertEquals(
+parent.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(parent.GetChildAtIndex(0).GetValue(), "2")
+
+# Test for value returned by SBFrame::EvaluateExpression.
+test_update_parent_value(
+frame0.EvaluateExpression("auto $b_0 = b1; $b_0"))
+
+# Test for value _created_ by SBFrame::EvaluateExpression.
+frame0.EvaluateExpression("auto $b_0 = b1")
+test_update_parent_value(
+frame0.FindValue('$b_0', lldb.eValueTypeConstResult))
+
+# Test for value created by SBTarget::CreateValueFromData.
+b1 = frame0.FindVariable("b1")
+b1_size = b1.GetByteSize()
+b1_value = b1.GetValueAsUnsigned()
+b1_addr_bytes = b1_value.to_bytes(b1_size, 'little')
+error = lldb.SBError()
+data = lldb.SBData()
+data.SetData(error, b1_addr_bytes, lldb.eByteOrderLittle, b1_size)
+test_update_parent_value(
+target.CreateValueFromData("b", data, b1.GetType()))
+
 # gcc may set multiple locations for breakpoint
 breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -231,6 +231,10 @@
   // We have to clear the value string here so ConstResult children will notice
   // if their values are changed by hand (i.e. with SetValueAsCString).
   ClearUserVisibleData(eClearUserVisibleDataItemsValue);
+  // Children have to be re-computed after updating the parent value.
+  m_flags.m_children_count_valid = false;
+  m_children.Clear();
+  SetSyntheticChildren(lldb::SyntheticChildrenSP());
 }
 
 void ValueObject::ClearDynamicTypeInformation() {


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct bar *b1 = &_b1;
+  struct bar *b2 = &_b2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,41 @@
 self.assertEquals(a

[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

2021-07-10 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

Thanks for the explanation! But at this point I feel I'm a bit confused about 
how it all _supposed_ to work in the current design :)

If I understand correctly, there are four "types" of values from the user (API) 
perspective:

1. `ExpressionResult` -- value returned by `SBFrame::EvaluateExpression()`
2. `ExpressionPersistentVariable` -- value created by the expression via `auto 
$name = ...` syntax. Can be obtained by `SBFrame::FindValue("$name", 
lldb::eValueTypeConstResult)`.
3. "Const value" -- value created by `SBTarget::CreateValueFromData()` or 
`SBTarget::CreateValueFromAddress`
4. "Variable reference" -- value returned by `SBFrame::FindVariable()`

For which of these value the following test is supposed to work?

  struct Foo { int x; };
  Foo* f1 = { .x = 1}
  Foo* f2 = { .x = 2}  # pseudo-C for simplicity
  
  f1_ref = ...  # Get a value that holds the value of `f1` using one of the 
four methods described above
  print(f1_ref.GetChild(0))  # '1'
  f1_ref.SetValueFromCString(frame.FindVariable('f2').value)
  print(f1_ref.GetChild(0))  # '2'

My experiments show that it works for "variable references" and "const values" 
created by `CreateValueFromAddress` (but _not_ `CreateValueFromData`).
If I understand your comment correctly, you're saying it should work only for 
`ExpressionPersistentVariable` values (#2). Is that right?

I don't have the full picture about the internal implementation and all the use 
cases, but as a user I would expect it to work for at least #2, #3 and #4. 
Afaik there's no API to fully distinguish between these kinds of values, so I 
find it confusing why `SBValue::SetData()` would be allowed for some values and 
not allowed for others. If I can create a value using `CreateValueFromData` and 
then there's a method `SetValueFromCString`, then I don't see why it should not 
be allowed (apart from implementation complexity/consistency reasons).

What do you think? How should we proceed with this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105470

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


[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

2021-07-26 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 361649.
werat added a comment.

[clang-tidy] Always open files using UTF-8 encoding

The encoding used for opening files depends on the OS and might be different
from UTF-8 (e.g. on Windows it can be CP-1252). The documentation files use
UTF-8 and might be incompatible with other encodings. For example, right now
`clang-tools-extra/docs/clang-tidy/checks/abseil-no-internal-dependencies.rst`
has non-ASCII quotes and running `add_new_check.py` fails on Windows, because
it tries to read the file with incompatible encoding.

Use `io.open` for compatibility with both Python 2 and Python 3.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105470

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
  lldb/test/API/python_api/value/change_values/main.c


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct bar *b1 = &_b1;
+  struct bar *b2 = &_b2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
   mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,41 @@
 self.assertEquals(actual_value, 98765,
 "Got the right changed value from ptr->second_val")
 
+# Test updating the children after updating the parent value.
+def test_update_parent_value(parent):
+self.assertEquals(
+parent.GetValue(),
+frame0.FindVariable("b1").GetValue())
+self.assertEquals(parent.GetChildAtIndex(0).GetValue(), "1")
+
+result = parent.SetValueFromCString(
+frame0.FindVariable("b2").GetValue())
+self.assertTrue(result, "Success setting {}".format(parent.name))
+self.assertEquals(
+parent.GetValue(),
+frame0.FindVariable("b2").GetValue())
+self.assertEquals(parent.GetChildAtIndex(0).GetValue(), "2")
+
+# Test for value returned by SBFrame::EvaluateExpression.
+test_update_parent_value(
+frame0.EvaluateExpression("auto $b_0 = b1; $b_0"))
+
+# Test for value _created_ by SBFrame::EvaluateExpression.
+frame0.EvaluateExpression("auto $b_0 = b1")
+test_update_parent_value(
+frame0.FindValue('$b_0', lldb.eValueTypeConstResult))
+
+# Test for value created by SBTarget::CreateValueFromData.
+b1 = frame0.FindVariable("b1")
+b1_size = b1.GetByteSize()
+b1_value = b1.GetValueAsUnsigned()
+b1_addr_bytes = b1_value.to_bytes(b1_size, 'little')
+error = lldb.SBError()
+data = lldb.SBData()
+data.SetData(error, b1_addr_bytes, lldb.eByteOrderLittle, b1_size)
+test_update_parent_value(
+target.CreateValueFromData("b", data, b1.GetType()))
+
 # gcc may set multiple locations for breakpoint
 breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -231,6 +231,10 @@
   // We have to clear the value string here so ConstResult children will notice
   // if their values are changed by hand (i.e. with SetValueAsCString).
   ClearUserVisibleData(eClearUserVisibleDataItemsValue);
+  // Children have to be re-computed after updating the parent value.
+  m_flags.m_children_count_valid = false;
+  m_children.Clear();
+  SetSyntheticChildren(lldb::SyntheticChildrenSP());
 }
 
 void ValueObject::ClearDynamicTypeInformation() {


Index: lldb/test/API/python_api/value/change_values/main.c
===
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = ;
   ptr->third_val = ;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct

[Lldb-commits] [PATCH] D108233: WIP: Add minidump save-core functionality to ELF object files

2021-08-31 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaafa05e03d62: [lldb] Add minidump save-core functionality to 
ELF object files (authored by Aj0SK, committed by werat).

Changed prior to commit:
  https://reviews.llvm.org/D108233?vs=369410&id=369673#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108233

Files:
  lldb/include/lldb/Core/PluginManager.h
  lldb/source/API/SBProcess.cpp
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Commands/Options.td
  lldb/source/Core/PluginManager.cpp
  lldb/source/Plugins/ObjectFile/CMakeLists.txt
  lldb/source/Plugins/ObjectFile/Minidump/CMakeLists.txt
  lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
  lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
  lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
  lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h
  lldb/test/API/functionalities/process_save_core_minidump/Makefile
  
lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
  lldb/test/API/functionalities/process_save_core_minidump/main.cpp

Index: lldb/test/API/functionalities/process_save_core_minidump/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/process_save_core_minidump/main.cpp
@@ -0,0 +1,30 @@
+#include 
+#include 
+#include 
+
+using namespace std;
+
+void g() { assert(false); }
+
+void f() { g(); }
+
+size_t h() {
+  size_t sum = 0;
+  for (size_t i = 0; i < 100; ++i)
+for (size_t j = 0; j < 100; ++j)
+  if ((i * j) % 2 == 0) {
+sum += 1;
+  }
+  return sum;
+}
+
+int main() {
+  thread t1(f);
+
+  size_t x = h();
+
+  t1.join();
+
+  cout << "X is " << x << "\n";
+  return 0;
+}
\ No newline at end of file
Index: lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
===
--- /dev/null
+++ lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
@@ -0,0 +1,78 @@
+"""
+Test saving a mini dump.
+"""
+
+
+import os
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ProcessSaveCoreMinidumpTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipUnlessPlatform(['linux'])
+def test_save_linux_mini_dump(self):
+"""Test that we can save a Linux mini dump."""
+self.build()
+exe = self.getBuildArtifact("a.out")
+core = self.getBuildArtifact("core.dmp")
+try:
+target = self.dbg.CreateTarget(exe)
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory())
+self.assertEqual(process.GetState(), lldb.eStateStopped)
+
+# get neccessary data for the verification phase
+process_info = process.GetProcessInfo()
+expected_pid = process_info.GetProcessID() if process_info.IsValid() else -1
+expected_number_of_modules = target.GetNumModules()
+expected_modules = target.modules
+expected_number_of_threads = process.GetNumThreads()
+expected_threads = []
+
+for thread_idx in range(process.GetNumThreads()):
+thread = process.GetThreadAtIndex(thread_idx)
+thread_id = thread.GetThreadID()
+expected_threads.append(thread_id)
+
+# save core and, kill process and verify corefile existence
+self.runCmd("process save-core --plugin-name=minidump --style=stack " + core)
+self.assertTrue(os.path.isfile(core))
+self.assertTrue(process.Kill().Success())
+
+# To verify, we'll launch with the mini dump
+target = self.dbg.CreateTarget(None)
+process = target.LoadCore(core)
+
+# check if the core is in desired state
+self.assertTrue(process, PROCESS_IS_VALID)
+self.assertTrue(process.GetProcessInfo().IsValid())
+self.assertEqual(process.GetProcessInfo().GetProcessID(), expected_pid)
+self.assertTrue(target.GetTriple().find("linux") != -1)
+self.assertTrue(target.GetNumModules(), expected_number_of_modules)
+self.assertEqual(process.GetNumThreads(), expected_number_of_threads)
+
+for module, expected in zip(target.modules, expected_modules):
+self.assertTrue(module.IsValid())
+module_file_name = module.GetFileSpec().GetFilename()
+expected_file_name = expected.GetFileSpec().GetFilename()
+# skip kernel virtual dynamic shared objects
+if "vdso" in expected_file_n

[Lldb-commits] [PATCH] D108233: WIP: Add minidump save-core functionality to ELF object files

2021-09-01 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeee687a66d76: [lldb] Add minidump save-core functionality to 
ELF object files (authored by Aj0SK, committed by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108233

Files:
  lldb/include/lldb/Core/PluginManager.h
  lldb/source/API/SBProcess.cpp
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Commands/Options.td
  lldb/source/Core/PluginManager.cpp
  lldb/source/Plugins/ObjectFile/CMakeLists.txt
  lldb/source/Plugins/ObjectFile/Minidump/CMakeLists.txt
  lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
  lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
  lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
  lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h
  lldb/test/API/functionalities/process_save_core_minidump/Makefile
  
lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
  lldb/test/API/functionalities/process_save_core_minidump/main.cpp

Index: lldb/test/API/functionalities/process_save_core_minidump/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/process_save_core_minidump/main.cpp
@@ -0,0 +1,30 @@
+#include 
+#include 
+#include 
+
+using namespace std;
+
+void g() { assert(false); }
+
+void f() { g(); }
+
+size_t h() {
+  size_t sum = 0;
+  for (size_t i = 0; i < 100; ++i)
+for (size_t j = 0; j < 100; ++j)
+  if ((i * j) % 2 == 0) {
+sum += 1;
+  }
+  return sum;
+}
+
+int main() {
+  thread t1(f);
+
+  size_t x = h();
+
+  t1.join();
+
+  cout << "X is " << x << "\n";
+  return 0;
+}
\ No newline at end of file
Index: lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
===
--- /dev/null
+++ lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
@@ -0,0 +1,79 @@
+"""
+Test saving a mini dump.
+"""
+
+
+import os
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ProcessSaveCoreMinidumpTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipUnlessArch("x86_64")
+@skipUnlessPlatform(["linux"])
+def test_save_linux_mini_dump(self):
+"""Test that we can save a Linux mini dump."""
+self.build()
+exe = self.getBuildArtifact("a.out")
+core = self.getBuildArtifact("core.dmp")
+try:
+target = self.dbg.CreateTarget(exe)
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory())
+self.assertEqual(process.GetState(), lldb.eStateStopped)
+
+# get neccessary data for the verification phase
+process_info = process.GetProcessInfo()
+expected_pid = process_info.GetProcessID() if process_info.IsValid() else -1
+expected_number_of_modules = target.GetNumModules()
+expected_modules = target.modules
+expected_number_of_threads = process.GetNumThreads()
+expected_threads = []
+
+for thread_idx in range(process.GetNumThreads()):
+thread = process.GetThreadAtIndex(thread_idx)
+thread_id = thread.GetThreadID()
+expected_threads.append(thread_id)
+
+# save core and, kill process and verify corefile existence
+self.runCmd("process save-core --plugin-name=minidump --style=stack " + core)
+self.assertTrue(os.path.isfile(core))
+self.assertTrue(process.Kill().Success())
+
+# To verify, we'll launch with the mini dump
+target = self.dbg.CreateTarget(None)
+process = target.LoadCore(core)
+
+# check if the core is in desired state
+self.assertTrue(process, PROCESS_IS_VALID)
+self.assertTrue(process.GetProcessInfo().IsValid())
+self.assertEqual(process.GetProcessInfo().GetProcessID(), expected_pid)
+self.assertTrue(target.GetTriple().find("linux") != -1)
+self.assertTrue(target.GetNumModules(), expected_number_of_modules)
+self.assertEqual(process.GetNumThreads(), expected_number_of_threads)
+
+for module, expected in zip(target.modules, expected_modules):
+self.assertTrue(module.IsValid())
+module_file_name = module.GetFileSpec().GetFilename()
+expected_file_name = expected.GetFileSpec().GetFilename()
+# skip kernel virtual dynamic shared objects
+if "vdso" in expected_file_name:
+continue
+se

[Lldb-commits] [PATCH] D96778: [lldb] Fix handling of `DW_AT_decl_file` according to D91014

2021-02-16 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat added a reviewer: jankratochvil.
Herald added a reviewer: shafik.
werat requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: lldb-commits, sstefan1.
Herald added a project: LLDB.

Apply changes from https://reviews.llvm.org/D91014 to other places where DWARF 
entries are being processed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96778

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3126,8 +3126,8 @@
   continue;
 switch (attr) {
 case DW_AT_decl_file:
-  decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(
-  form_value.Unsigned()));
+  decl.SetFile(
+  attributes.CompileUnitAtIndex(i)->GetFile(form_value.Unsigned()));
   break;
 case DW_AT_decl_line:
   decl.SetLine(form_value.Unsigned());
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2201,7 +2201,8 @@
 case DW_AT_description:
 default:
 case DW_AT_decl_file:
-  decl.SetFile(die.GetCU()->GetFile(form_value.Unsigned()));
+  decl.SetFile(attributes.CompileUnitAtIndex(i)->GetFile(
+  form_value.Unsigned()));
   break;
 case DW_AT_decl_line:
   decl.SetLine(form_value.Unsigned());


Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3126,8 +3126,8 @@
   continue;
 switch (attr) {
 case DW_AT_decl_file:
-  decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(
-  form_value.Unsigned()));
+  decl.SetFile(
+  attributes.CompileUnitAtIndex(i)->GetFile(form_value.Unsigned()));
   break;
 case DW_AT_decl_line:
   decl.SetLine(form_value.Unsigned());
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2201,7 +2201,8 @@
 case DW_AT_description:
 default:
 case DW_AT_decl_file:
-  decl.SetFile(die.GetCU()->GetFile(form_value.Unsigned()));
+  decl.SetFile(attributes.CompileUnitAtIndex(i)->GetFile(
+  form_value.Unsigned()));
   break;
 case DW_AT_decl_line:
   decl.SetLine(form_value.Unsigned());
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96778: [lldb] Fix handling of `DW_AT_decl_file` according to D91014

2021-02-16 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.
Herald added a subscriber: JDevlieghere.

Hi @jankratochvil, can you take a look at this, please?

I can't claim I fully understand what's the difference here, but this aligns 
with your comment at https://reviews.llvm.org/D92643#inline-900717 :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96778

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


[Lldb-commits] [PATCH] D96778: [lldb] Fix handling of `DW_AT_decl_file` according to D91014

2021-02-17 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

To be honest, I'm not sure how to reproduce this kind of debug info. I've tried 
a few examples (e.g. force inline the function from another CU) , but it didn't 
work.

Should be postpone this patch until someone can figure out the test case then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96778

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


[Lldb-commits] [PATCH] D96778: [lldb] Fix handling of `DW_AT_decl_file` according to D91014

2021-02-22 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 325415.
werat added a comment.

Added the test cases provided by jankratochvil@


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96778

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  
lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
  
lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s

Index: lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
@@ -0,0 +1,160 @@
+	.text
+	.file	"inlinevar2.c"
+	.globl	other   # -- Begin function other
+	.type	other,@function
+other:  # @other
+.Lfunc_begin0:
+	.file	1 "" "inlinevar2.c"
+	.loc	1 3 0   # inlinevar2.c:3:0
+.Ltmp0:
+	.file	2 "" "./inlinevar.h"
+	.loc	2 2 16 prologue_end # ./inlinevar.h:2:16
+	movl	$42, %eax
+	.loc	2 3 10  # ./inlinevar.h:3:10
+	.loc	1 3 41  # inlinevar2.c:3:41
+	retq
+.Ltmp1:
+.Ltmp2:
+.Lfunc_end0:
+	.size	other, .Lfunc_end0-other
+# -- End function
+	.section	.debug_abbrev,"",@progbits
+	.byte	1   # Abbreviation Code
+	.byte	17  # DW_TAG_compile_unit
+	.byte	1   # DW_CHILDREN_yes
+	.byte	37  # DW_AT_producer
+	.byte	14  # DW_FORM_strp
+	.byte	19  # DW_AT_language
+	.byte	5   # DW_FORM_data2
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	16  # DW_AT_stmt_list
+	.byte	23  # DW_FORM_sec_offset
+	.byte	27  # DW_AT_comp_dir
+	.byte	14  # DW_FORM_strp
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	4   # Abbreviation Code
+	.byte	36  # DW_TAG_base_type
+	.byte	0   # DW_CHILDREN_no
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	62  # DW_AT_encoding
+	.byte	11  # DW_FORM_data1
+	.byte	11  # DW_AT_byte_size
+	.byte	11  # DW_FORM_data1
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	6   # Abbreviation Code
+	.byte	46  # DW_TAG_subprogram
+	.byte	1   # DW_CHILDREN_yes
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	64  # DW_AT_frame_base
+	.byte	24  # DW_FORM_exprloc
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	58  # DW_AT_decl_file
+	.byte	11  # DW_FORM_data1
+	.byte	59  # DW_AT_decl_line
+	.byte	11  # DW_FORM_data1
+	.byte	73  # DW_AT_type
+	.byte	19  # DW_FORM_ref4
+	.byte	63  # DW_AT_external
+	.byte	25  # DW_FORM_flag_present
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	7   # Abbreviation Code
+	.byte	29  # DW_TAG_inlined_subroutine
+	.byte	1   # DW_CHILDREN_yes
+	.byte	49  # DW_AT_abstract_origin
+	.byte	0x10# DW_FORM_ref_addr
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	88 

[Lldb-commits] [PATCH] D96778: [lldb] Fix handling of `DW_AT_decl_file` according to D91014

2021-03-01 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7ec7876feda4: [lldb] Fix handling of `DW_AT_decl_file` 
according to D91014 (authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96778

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  
lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
  
lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s

Index: lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
@@ -0,0 +1,160 @@
+	.text
+	.file	"inlinevar2.c"
+	.globl	other   # -- Begin function other
+	.type	other,@function
+other:  # @other
+.Lfunc_begin0:
+	.file	1 "" "inlinevar2.c"
+	.loc	1 3 0   # inlinevar2.c:3:0
+.Ltmp0:
+	.file	2 "" "./inlinevar.h"
+	.loc	2 2 16 prologue_end # ./inlinevar.h:2:16
+	movl	$42, %eax
+	.loc	2 3 10  # ./inlinevar.h:3:10
+	.loc	1 3 41  # inlinevar2.c:3:41
+	retq
+.Ltmp1:
+.Ltmp2:
+.Lfunc_end0:
+	.size	other, .Lfunc_end0-other
+# -- End function
+	.section	.debug_abbrev,"",@progbits
+	.byte	1   # Abbreviation Code
+	.byte	17  # DW_TAG_compile_unit
+	.byte	1   # DW_CHILDREN_yes
+	.byte	37  # DW_AT_producer
+	.byte	14  # DW_FORM_strp
+	.byte	19  # DW_AT_language
+	.byte	5   # DW_FORM_data2
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	16  # DW_AT_stmt_list
+	.byte	23  # DW_FORM_sec_offset
+	.byte	27  # DW_AT_comp_dir
+	.byte	14  # DW_FORM_strp
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	4   # Abbreviation Code
+	.byte	36  # DW_TAG_base_type
+	.byte	0   # DW_CHILDREN_no
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	62  # DW_AT_encoding
+	.byte	11  # DW_FORM_data1
+	.byte	11  # DW_AT_byte_size
+	.byte	11  # DW_FORM_data1
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	6   # Abbreviation Code
+	.byte	46  # DW_TAG_subprogram
+	.byte	1   # DW_CHILDREN_yes
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	64  # DW_AT_frame_base
+	.byte	24  # DW_FORM_exprloc
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	58  # DW_AT_decl_file
+	.byte	11  # DW_FORM_data1
+	.byte	59  # DW_AT_decl_line
+	.byte	11  # DW_FORM_data1
+	.byte	73  # DW_AT_type
+	.byte	19  # DW_FORM_ref4
+	.byte	63  # DW_AT_external
+	.byte	25  # DW_FORM_flag_present
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	7   # Abbreviation Code
+	.byte	29  # DW_TAG_inlined_subroutine
+	.byte	1   # DW_CHILDREN_yes
+	.byte	49  # DW_AT_abstract_origin
+	.byte	0x10# DW_FORM_ref_addr
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18

[Lldb-commits] [PATCH] D96778: [lldb] Fix handling of `DW_AT_decl_file` according to D91014

2021-03-01 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

The test was also executed on `lldb-aarch64-ubuntu` -- 
https://lab.llvm.org/buildbot/#/changes/13868
But we have `REQUIRES: x86`, shouldn't it exclude ARM?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96778

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


[Lldb-commits] [PATCH] D97696: [lldb] Enable cross CU decl file test only for x64 Linux

2021-03-01 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat added reviewers: jankratochvil, teemperor.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Fix tests after https://reviews.llvm.org/D96778


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97696

Files:
  
lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s


Index: 
lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
===
--- 
lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
+++ 
lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
@@ -11,7 +11,7 @@
 # file_names[  1]: name: "inlinevar2.c"
 # file_names[  2]: name: "inlinevar.h"
 
-# REQUIRES: x86
+# REQUIRES: x86_64-linux
 
 // RUN: %clang -o %t --target=x86_64-pc-linux %s \
 // RUN:   
%S/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s


Index: lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
===
--- lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
+++ lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
@@ -11,7 +11,7 @@
 # file_names[  1]: name: "inlinevar2.c"
 # file_names[  2]: name: "inlinevar.h"
 
-# REQUIRES: x86
+# REQUIRES: x86_64-linux
 
 // RUN: %clang -o %t --target=x86_64-pc-linux %s \
 // RUN:   %S/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D97765: [lldb] Fix handling of `DW_AT_decl_file` according to D91014 (attempt #2)

2021-03-02 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat added reviewers: JDevlieghere, labath, jankratochvil.
Herald added a reviewer: shafik.
werat requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: lldb-commits, sstefan1.
Herald added a project: LLDB.

Apply changes from https://reviews.llvm.org/D91014 to other places where DWARF 
entries are being processed.

Test case is provided by @jankratochvil.
The test is marked to run only on x64 and exclude Windows and Darwin, because 
the assembly is not OS-independent.

(First attempt https://reviews.llvm.org/D96778 broke the build bots)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97765

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  
lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
  
lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s

Index: lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
@@ -0,0 +1,160 @@
+	.text
+	.file	"inlinevar2.c"
+	.globl	other   # -- Begin function other
+	.type	other,@function
+other:  # @other
+.Lfunc_begin0:
+	.file	1 "" "inlinevar2.c"
+	.loc	1 3 0   # inlinevar2.c:3:0
+.Ltmp0:
+	.file	2 "" "./inlinevar.h"
+	.loc	2 2 16 prologue_end # ./inlinevar.h:2:16
+	movl	$42, %eax
+	.loc	2 3 10  # ./inlinevar.h:3:10
+	.loc	1 3 41  # inlinevar2.c:3:41
+	retq
+.Ltmp1:
+.Ltmp2:
+.Lfunc_end0:
+	.size	other, .Lfunc_end0-other
+# -- End function
+	.section	.debug_abbrev,"",@progbits
+	.byte	1   # Abbreviation Code
+	.byte	17  # DW_TAG_compile_unit
+	.byte	1   # DW_CHILDREN_yes
+	.byte	37  # DW_AT_producer
+	.byte	14  # DW_FORM_strp
+	.byte	19  # DW_AT_language
+	.byte	5   # DW_FORM_data2
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	16  # DW_AT_stmt_list
+	.byte	23  # DW_FORM_sec_offset
+	.byte	27  # DW_AT_comp_dir
+	.byte	14  # DW_FORM_strp
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	4   # Abbreviation Code
+	.byte	36  # DW_TAG_base_type
+	.byte	0   # DW_CHILDREN_no
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	62  # DW_AT_encoding
+	.byte	11  # DW_FORM_data1
+	.byte	11  # DW_AT_byte_size
+	.byte	11  # DW_FORM_data1
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	6   # Abbreviation Code
+	.byte	46  # DW_TAG_subprogram
+	.byte	1   # DW_CHILDREN_yes
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	64  # DW_AT_frame_base
+	.byte	24  # DW_FORM_exprloc
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	58  # DW_AT_decl_file
+	.byte	11  # DW_FORM_data1
+	.byte	59  # DW_AT_decl_line
+	.byte	11  # DW_FORM_data1
+	.byte	73  # DW_AT_type
+	.byte	19  # DW_FORM_ref4
+	.byte	63  # DW_AT_external
+	.byte	25  # DW_FORM_flag_present
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	7   # Abbreviation Code
+	.byte	29  # DW_TAG_inlined_subroutine

[Lldb-commits] [PATCH] D97696: [lldb] Enable cross CU decl file test only for x64 Linux

2021-03-02 Thread Andy Yankovsky via Phabricator via lldb-commits
werat abandoned this revision.
werat added a comment.

The original commit was reverted, abandon in favor of 
https://reviews.llvm.org/D97765


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97696

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


[Lldb-commits] [PATCH] D97765: [lldb] Fix handling of `DW_AT_decl_file` according to D91014 (attempt #2)

2021-03-02 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 327469.
werat added a comment.

Use `clang_host` instead of `clang`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97765

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  
lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
  
lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s

Index: lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
@@ -0,0 +1,160 @@
+	.text
+	.file	"inlinevar2.c"
+	.globl	other   # -- Begin function other
+	.type	other,@function
+other:  # @other
+.Lfunc_begin0:
+	.file	1 "" "inlinevar2.c"
+	.loc	1 3 0   # inlinevar2.c:3:0
+.Ltmp0:
+	.file	2 "" "./inlinevar.h"
+	.loc	2 2 16 prologue_end # ./inlinevar.h:2:16
+	movl	$42, %eax
+	.loc	2 3 10  # ./inlinevar.h:3:10
+	.loc	1 3 41  # inlinevar2.c:3:41
+	retq
+.Ltmp1:
+.Ltmp2:
+.Lfunc_end0:
+	.size	other, .Lfunc_end0-other
+# -- End function
+	.section	.debug_abbrev,"",@progbits
+	.byte	1   # Abbreviation Code
+	.byte	17  # DW_TAG_compile_unit
+	.byte	1   # DW_CHILDREN_yes
+	.byte	37  # DW_AT_producer
+	.byte	14  # DW_FORM_strp
+	.byte	19  # DW_AT_language
+	.byte	5   # DW_FORM_data2
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	16  # DW_AT_stmt_list
+	.byte	23  # DW_FORM_sec_offset
+	.byte	27  # DW_AT_comp_dir
+	.byte	14  # DW_FORM_strp
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	4   # Abbreviation Code
+	.byte	36  # DW_TAG_base_type
+	.byte	0   # DW_CHILDREN_no
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	62  # DW_AT_encoding
+	.byte	11  # DW_FORM_data1
+	.byte	11  # DW_AT_byte_size
+	.byte	11  # DW_FORM_data1
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	6   # Abbreviation Code
+	.byte	46  # DW_TAG_subprogram
+	.byte	1   # DW_CHILDREN_yes
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	64  # DW_AT_frame_base
+	.byte	24  # DW_FORM_exprloc
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	58  # DW_AT_decl_file
+	.byte	11  # DW_FORM_data1
+	.byte	59  # DW_AT_decl_line
+	.byte	11  # DW_FORM_data1
+	.byte	73  # DW_AT_type
+	.byte	19  # DW_FORM_ref4
+	.byte	63  # DW_AT_external
+	.byte	25  # DW_FORM_flag_present
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	7   # Abbreviation Code
+	.byte	29  # DW_TAG_inlined_subroutine
+	.byte	1   # DW_CHILDREN_yes
+	.byte	49  # DW_AT_abstract_origin
+	.byte	0x10# DW_FORM_ref_addr
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	88  # D

[Lldb-commits] [PATCH] D97765: [lldb] Fix handling of `DW_AT_decl_file` according to D91014 (attempt #2)

2021-03-03 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3b47bd32f9df: [lldb] Fix handling of `DW_AT_decl_file` 
according to D91014 (attempt #2) (authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97765

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  
lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
  
lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s

Index: lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
@@ -0,0 +1,160 @@
+	.text
+	.file	"inlinevar2.c"
+	.globl	other   # -- Begin function other
+	.type	other,@function
+other:  # @other
+.Lfunc_begin0:
+	.file	1 "" "inlinevar2.c"
+	.loc	1 3 0   # inlinevar2.c:3:0
+.Ltmp0:
+	.file	2 "" "./inlinevar.h"
+	.loc	2 2 16 prologue_end # ./inlinevar.h:2:16
+	movl	$42, %eax
+	.loc	2 3 10  # ./inlinevar.h:3:10
+	.loc	1 3 41  # inlinevar2.c:3:41
+	retq
+.Ltmp1:
+.Ltmp2:
+.Lfunc_end0:
+	.size	other, .Lfunc_end0-other
+# -- End function
+	.section	.debug_abbrev,"",@progbits
+	.byte	1   # Abbreviation Code
+	.byte	17  # DW_TAG_compile_unit
+	.byte	1   # DW_CHILDREN_yes
+	.byte	37  # DW_AT_producer
+	.byte	14  # DW_FORM_strp
+	.byte	19  # DW_AT_language
+	.byte	5   # DW_FORM_data2
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	16  # DW_AT_stmt_list
+	.byte	23  # DW_FORM_sec_offset
+	.byte	27  # DW_AT_comp_dir
+	.byte	14  # DW_FORM_strp
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	4   # Abbreviation Code
+	.byte	36  # DW_TAG_base_type
+	.byte	0   # DW_CHILDREN_no
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	62  # DW_AT_encoding
+	.byte	11  # DW_FORM_data1
+	.byte	11  # DW_AT_byte_size
+	.byte	11  # DW_FORM_data1
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	6   # Abbreviation Code
+	.byte	46  # DW_TAG_subprogram
+	.byte	1   # DW_CHILDREN_yes
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+	.byte	18  # DW_AT_high_pc
+	.byte	6   # DW_FORM_data4
+	.byte	64  # DW_AT_frame_base
+	.byte	24  # DW_FORM_exprloc
+	.byte	3   # DW_AT_name
+	.byte	14  # DW_FORM_strp
+	.byte	58  # DW_AT_decl_file
+	.byte	11  # DW_FORM_data1
+	.byte	59  # DW_AT_decl_line
+	.byte	11  # DW_FORM_data1
+	.byte	73  # DW_AT_type
+	.byte	19  # DW_FORM_ref4
+	.byte	63  # DW_AT_external
+	.byte	25  # DW_FORM_flag_present
+	.byte	0   # EOM(1)
+	.byte	0   # EOM(2)
+	.byte	7   # Abbreviation Code
+	.byte	29  # DW_TAG_inlined_subroutine
+	.byte	1   # DW_CHILDREN_yes
+	.byte	49  # DW_AT_abstract_origin
+	.byte	0x10# DW_FORM_ref_addr
+	.byte	17  # DW_AT_low_pc
+	.byte	1   # DW_FORM_addr
+

[Lldb-commits] [PATCH] D98170: [lldb] Fix error message in IRInterpreter

2021-03-08 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat added reviewers: teemperor, spyffe.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

`memory_read_error` -> `memory_write_error`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98170

Files:
  lldb/source/Expression/IRInterpreter.cpp


Index: lldb/source/Expression/IRInterpreter.cpp
===
--- lldb/source/Expression/IRInterpreter.cpp
+++ lldb/source/Expression/IRInterpreter.cpp
@@ -1241,7 +1241,7 @@
   if (!write_error.Success()) {
 LLDB_LOGF(log, "Couldn't write to a region on behalf of a LoadInst");
 error.SetErrorToGenericError();
-error.SetErrorString(memory_read_error);
+error.SetErrorString(memory_write_error);
 return false;
   }
 


Index: lldb/source/Expression/IRInterpreter.cpp
===
--- lldb/source/Expression/IRInterpreter.cpp
+++ lldb/source/Expression/IRInterpreter.cpp
@@ -1241,7 +1241,7 @@
   if (!write_error.Success()) {
 LLDB_LOGF(log, "Couldn't write to a region on behalf of a LoadInst");
 error.SetErrorToGenericError();
-error.SetErrorString(memory_read_error);
+error.SetErrorString(memory_write_error);
 return false;
   }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D98170: [lldb] Fix error message in IRInterpreter

2021-03-08 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

I was looking into the issue with `SBValue::Persist` 
(https://discord.com/channels/636084430946959380/636732809708306432/817370459284832297)
 and the logs and errors eventually led me here to `IRInterpreter`. And the 
incorrect error message I noticed just by accident :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98170

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


[Lldb-commits] [PATCH] D98170: [lldb] Fix error message in IRInterpreter

2021-03-08 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1b7e5d461aee: [lldb] Fix error message in IRInterpreter 
(authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98170

Files:
  lldb/source/Expression/IRInterpreter.cpp


Index: lldb/source/Expression/IRInterpreter.cpp
===
--- lldb/source/Expression/IRInterpreter.cpp
+++ lldb/source/Expression/IRInterpreter.cpp
@@ -1241,7 +1241,7 @@
   if (!write_error.Success()) {
 LLDB_LOGF(log, "Couldn't write to a region on behalf of a LoadInst");
 error.SetErrorToGenericError();
-error.SetErrorString(memory_read_error);
+error.SetErrorString(memory_write_error);
 return false;
   }
 


Index: lldb/source/Expression/IRInterpreter.cpp
===
--- lldb/source/Expression/IRInterpreter.cpp
+++ lldb/source/Expression/IRInterpreter.cpp
@@ -1241,7 +1241,7 @@
   if (!write_error.Success()) {
 LLDB_LOGF(log, "Couldn't write to a region on behalf of a LoadInst");
 error.SetErrorToGenericError();
-error.SetErrorString(memory_read_error);
+error.SetErrorString(memory_write_error);
 return false;
   }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D98370: [lldb] Fix SBValue::Persist() for constant values

2021-03-10 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
werat added a reviewer: teemperor.
werat requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Right now `SBValue::Persist()` works properly only for values that refere to 
variables (refer to unit-tests for an example). Constant values (e.g. values 
created by `EvaluateExpression` or `CreateValueFromData`) can be persisted, but 
using them in the expressions leads to an error:

  >>> v = lldb.frame.EvaluateExpression("1+2")
  >>> vp = v.Persist()
  >>> vp.GetName()
  '$1'
  >>> v = lldb.frame.EvaluateExpression("$1")
  >>> v.GetValue()
  '3'
  >>> v = lldb.frame.EvaluateExpression("$1+1")
  >>> v.GetError().GetCString()
  "error: supposed to interpret, but failed: Interpreter couldn't read from 
memory\n"

In this patch we mark constant values as "required materialization" and fix up 
the dematerialization logic to apply side-effects.

Also move Windows-failing use cases to a separate test, so that other tests can 
be executed on Windows too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98370

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/source/Expression/Materializer.cpp
  lldb/test/API/python_api/sbvalue_persist/TestSBValuePersist.py
  lldb/test/API/python_api/sbvalue_persist/main.cpp

Index: lldb/test/API/python_api/sbvalue_persist/main.cpp
===
--- lldb/test/API/python_api/sbvalue_persist/main.cpp
+++ lldb/test/API/python_api/sbvalue_persist/main.cpp
@@ -1,14 +1,21 @@
-#include 
 #include 
+#include 
 
 void f() {}
 
+struct P {
+  int x;
+  float y;
+} _p;
+
 int main() {
-int foo = 10;
-int *bar = new int(4);
-std::string baz = "85";
-
-f(); // break here
-f(); // break here
-return 0;
+  int foo = 10;
+  int *bar = new int(4);
+  std::string baz = "85";
+
+  int mem[] = {1, 0x3fc0}; // P { x = 1, y = 1.5 }
+
+  f(); // break here
+  f(); // break here
+  return 0;
 }
Index: lldb/test/API/python_api/sbvalue_persist/TestSBValuePersist.py
===
--- lldb/test/API/python_api/sbvalue_persist/TestSBValuePersist.py
+++ lldb/test/API/python_api/sbvalue_persist/TestSBValuePersist.py
@@ -1,7 +1,5 @@
 """Test SBValue::Persist"""
 
-
-
 import lldb
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
@@ -13,9 +11,7 @@
 mydir = TestBase.compute_mydir(__file__)
 NO_DEBUG_INFO_TESTCASE = True
 
-@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24772")
-def test(self):
-"""Test SBValue::Persist"""
+def _setup(self):
 self.build()
 self.setTearDownCleanup()
 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
@@ -40,42 +36,103 @@
 # Execute the cleanup function during test case tear down.
 self.addTearDownHook(cleanup)
 
+@add_test_categories(['pyapi'])
+@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24772")
+def test_std_string(self):
+"""Test SBValue::Persist for a variable of type std::string"""
+self._setup()
+
+baz = self.frame().FindVariable("baz")
+self.assertTrue(baz.IsValid(), "baz is not valid")
+
+bazPersist = baz.Persist()
+self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")
+self.assertEqual(bazPersist.GetSummary(), '"85"')
+
+self.runCmd("continue")
+
+self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")
+self.assertEqual(bazPersist.GetSummary(), '"85"')
+
+@add_test_categories(['pyapi'])
+def test(self):
+"""Test SBValue::Persist"""
+self._setup()
+
 foo = self.frame().FindVariable("foo")
 bar = self.frame().FindVariable("bar")
-baz = self.frame().FindVariable("baz")
 
 self.assertTrue(foo.IsValid(), "foo is not valid")
 self.assertTrue(bar.IsValid(), "bar is not valid")
-self.assertTrue(baz.IsValid(), "baz is not valid")
 
 fooPersist = foo.Persist()
 barPersist = bar.Persist()
-bazPersist = baz.Persist()
 
 self.assertTrue(fooPersist.IsValid(), "fooPersist is not valid")
 self.assertTrue(barPersist.IsValid(), "barPersist is not valid")
-self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")
 
-self.assertEqual(
-fooPersist.GetValueAsUnsigned(0), 10,
-"fooPersist != 10")
-self.assertEqual(
-barPersist.GetPointeeData().sint32[0], 4,
-"barPersist != 4")
-self.assertEquals(bazPersist.GetSummary(), '"85"', "bazPersist != 85")
+self.assertEqual(fooPersist.GetValueAsUnsigned(0), 10)
+self.assertEqual(barPersist.GetPointeeData().sint32[0], 4)
 
 self.runCmd("continue")
 
 self.assertTrue(fooPersist.IsValid(), "fooPersist is not valid")
 self.assertT

[Lldb-commits] [PATCH] D98370: [lldb] Fix SBValue::Persist() for constant values

2021-03-10 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.
Herald added a subscriber: JDevlieghere.

Hi @teemperor , here's an attempt to fix `SBValue::Persist` method. I've 
highlighted a few moments in the patch I'm not so sure about, please let me 
know what you think. Thanks!




Comment at: lldb/source/Expression/Materializer.cpp:301
 
-m_persistent_variable_sp->m_flags &=
-~ExpressionVariable::EVNeedsFreezeDry;
+m_persistent_variable_sp->m_frozen_sp = ValueObjectConstResult::Create(
+map.GetBestExecutionContextScope(),

Writing data directly to `m_persistent_variable_sp->GetValueBytes()` is not 
enough, because the underlying `ValueObject` also stores the data in `m_value` 
and I didn't find a way to update that one too. Overall there seems to be an 
assumption that `ValueObjectConstResult` doesn't change (which makes sense), so 
creating a new one here seems more in line with the design.



Comment at: lldb/source/Expression/Materializer.cpp:303-304
 
-m_persistent_variable_sp->m_flags &=
-~ExpressionVariable::EVNeedsFreezeDry;
   }

I am not sure how to deal with this. "ConstResult" variables needs to be 
dematerialized every time, so they should either have `EVNeedsFreezeDry` flag, 
or the check should be different. Removing this flag doesn't seem to break 
anything though...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98370

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


[Lldb-commits] [PATCH] D92643: [lldb] Lookup static const members in FindGlobalVariables

2021-03-13 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 330445.
werat added a comment.

Address review comments:

- Don't create expensive `ConstString` objects
- Merge `ParseStaticConstMemberDIE` into `ParseVariableDIE`
- Add more test cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92643

Files:
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/test/API/python_api/target/globals/Makefile
  lldb/test/API/python_api/target/globals/TestTargetGlobals.py
  lldb/test/API/python_api/target/globals/main.cpp

Index: lldb/test/API/python_api/target/globals/main.cpp
===
--- /dev/null
+++ lldb/test/API/python_api/target/globals/main.cpp
@@ -0,0 +1,30 @@
+namespace ns1 {
+class Klass {
+public:
+  inline static int x = 1;
+};
+} // namespace ns1
+
+namespace ns2 {
+class Klass {
+public:
+  inline static int x = 2;
+};
+} // namespace ns2
+
+class Vars {
+public:
+  inline static double inline_static = 1.5;
+  static constexpr int static_constexpr = 2;
+  static const int static_const_out_out_class;
+};
+
+const int Vars::static_const_out_out_class = 3;
+
+char global_var_of_char_type = 'X';
+
+int main() {
+  ns1::Klass ns1;
+  ns2::Klass ns2;
+  Vars v;
+}
Index: lldb/test/API/python_api/target/globals/TestTargetGlobals.py
===
--- /dev/null
+++ lldb/test/API/python_api/target/globals/TestTargetGlobals.py
@@ -0,0 +1,54 @@
+"""
+Test SBTarget::FindGlobalVariables API.
+"""
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+class TargetAPITestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@add_test_categories(['pyapi'])
+def test_find_global_variables(self):
+"""Exercise SBTarget.FindGlobalVariables() API."""
+self.build()
+
+# Don't need to launch a process, since we're only interested in
+# looking up global variables.
+target = self.dbg.CreateTarget(self.getBuildArtifact())
+
+def test_global_var(query, name, type_name, value):
+value_list = target.FindGlobalVariables(query, 100500)
+self.assertEqual(value_list.GetSize(), 1)
+var = value_list.GetValueAtIndex(0)
+self.DebugSBValue(var)
+self.assertTrue(var)
+self.assertEqual(var.GetName(), name)
+self.assertEqual(var.GetTypeName(), type_name)
+self.assertEqual(var.GetValue(), value)
+
+test_global_var(
+"Vars::inline_static",
+"Vars::inline_static", "double", "1.5")
+test_global_var(
+"Vars::static_constexpr",
+"Vars::static_constexpr", "const int", "2")
+test_global_var(
+"Vars::static_const_out_out_class",
+"Vars::static_const_out_out_class", "const int", "3")
+test_global_var(
+"global_var_of_char_type",
+"::global_var_of_char_type", "char", "'X'")
+
+# Looking for a specific scope should find the variable from that scope.
+test_global_var("ns1::Klass::x", "ns1::Klass::x", "int", "1")
+test_global_var("ns2::Klass::x", "ns2::Klass::x", "int", "2")
+
+# However the query for `Klass::x` should return both variables:
+# `ns1::Klass::x` and `ns2::Klass::x`.
+values = target.FindGlobalVariables("Klass::x", 100500)
+self.assertEqual(values.GetSize(), 2)
+self.assertEqual(
+{values[0].GetName(), values[1].GetName()}, 
+{"ns1::Klass::x", "ns2::Klass::x"})
Index: lldb/test/API/python_api/target/globals/Makefile
===
--- /dev/null
+++ lldb/test/API/python_api/target/globals/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2147,6 +2147,46 @@
 return variables.GetSize() - original_size < max_matches;
   });
 
+  // If we don't have enough matches and the variable context is not empty, try
+  // to resolve the context as a type and look for static const members.
+  if (variables.GetSize() - original_size < max_matches && !context.empty()) {
+llvm::StringRef type_scope;
+llvm::StringRef type_name;
+TypeClass type_class;
+if (!Type::GetTypeScopeAndBasename(context, type_scope, type_name,
+   type_class))
+  type_name = context;
+
+m_index->GetTypes(ConstString(type_name), [&](DWARFDIE parent) {
+  DWARFDeclContext dwarf_decl_ctx = GetDWARFDeclContext(parent);
+  llvm::StringRef parent_type_name = dwarf_decl_ctx.GetQualifiedName();
+
+

[Lldb-commits] [PATCH] D92643: [lldb] Lookup static const members in FindGlobalVariables

2021-03-13 Thread Andy Yankovsky via Phabricator via lldb-commits
werat marked 4 inline comments as done.
werat added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:2162
 
 void SymbolFileDWARF::FindGlobalVariables(const RegularExpression ®ex,
   uint32_t max_matches,

jankratochvil wrote:
> jankratochvil wrote:
> > ConstString here is needlessly expensive to construct and it is then used 
> > only once. Use plain `const char *` or `std::string` is also much cheaper.
> This function also needs to be patched (with a testcase) as this command 
> works:
> ```
> (lldb) target variable Vars::inline_static
> (double) Vars::inline_static = 1.5
> ```
> But this one does not (and it should work):
> ```
> (lldb) target variable -r Vars::inline_static
> error: can't find global variable 'Vars::inline_static'
> ```
With the current approach implementing a search by regexp would mean 
enumerating ALL types and looking at ALL their static members for a potential 
match. This sounds way to expensive (and a significant degradation compared to 
the current logic). On the other hand I agree that's very confusing that 
`target variable` works, but `target variable -r` doesn't. What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92643

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


  1   2   >