[Lldb-commits] [lldb] [llvm] LLDB Debuginfod usage tests (with fixes) (PR #79181)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei closed 
https://github.com/llvm/llvm-project/pull/79181
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Jonas Devlieghere via lldb-commits


@@ -4377,26 +4377,40 @@ const std::shared_ptr 
::GetDwpSymbolFile() {
 FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
 ModuleSpec module_spec;
 module_spec.GetFileSpec() = m_objfile_sp->GetFileSpec();
+FileSpec dwp_filespec;
 for (const auto  : symfiles.files()) {
   module_spec.GetSymbolFileSpec() =
   FileSpec(symfile.GetPath() + ".dwp", symfile.GetPathStyle());
   LLDB_LOG(log, "Searching for DWP using: \"{0}\"",
module_spec.GetSymbolFileSpec());
-  FileSpec dwp_filespec =
+  dwp_filespec =
   PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
   if (FileSystem::Instance().Exists(dwp_filespec)) {
-LLDB_LOG(log, "Found DWP file: \"{0}\"", dwp_filespec);
-DataBufferSP dwp_file_data_sp;
-lldb::offset_t dwp_file_data_offset = 0;
-ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
-GetObjectFile()->GetModule(), _filespec, 0,
-FileSystem::Instance().GetByteSize(dwp_filespec), dwp_file_data_sp,
-dwp_file_data_offset);
-if (dwp_obj_file) {
-  m_dwp_symfile = std::make_shared(
-  *this, dwp_obj_file, DIERef::k_file_index_mask);
-  break;
-}
+break;
+  }
+}
+if (!FileSystem::Instance().Exists(dwp_filespec)) {
+  LLDB_LOG(log, "No DWP file found locally");
+  // Fill in the UUID for the module we're trying to match for, so we can
+  // find the correct DWP file, as the Debuginfod plugin uses *only* this
+  // data to correctly match the DWP file with the binary.
+  module_spec.GetUUID() = m_objfile_sp->GetUUID();
+  dwp_filespec =
+  PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
+  // Set it back so it's not outliving the m_objfile_sp shared pointer.
+  module_spec.GetUUID() = {};

JDevlieghere wrote:

On line 4397 you've copied the UUID into the ModuleSpec so I don't think 
there's an issue with it outliving the `m_objfile_sp` as it has been copied. If 
there's another reason you need to undo setting the UUID, you probably want to 
remember what it was set to originally and put that back rather than just 
clearing it?

https://github.com/llvm/llvm-project/pull/85693
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Jonas Devlieghere via lldb-commits


@@ -44,6 +44,27 @@ llvm::StringRef 
SymbolVendorELF::GetPluginDescriptionStatic() {
  "executables.";
 }
 
+// If this is needed elsewhere, it can be exported/moved.
+static bool IsDwpSymbolFile(const lldb::ModuleSP _sp,
+const FileSpec _spec) {
+  DataBufferSP dwp_file_data_sp;
+  lldb::offset_t dwp_file_data_offset = 0;
+  // Try to create an ObjectFile from the file_spec.
+  ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
+  module_sp, _spec, 0, FileSystem::Instance().GetByteSize(file_spec),
+  dwp_file_data_sp, dwp_file_data_offset);
+  if (!ObjectFileELF::classof(dwp_obj_file.get()))
+return false;
+  // The presence of a debug_cu_index section is the key identifying feature of
+  // a DWP file. Make sure we don't fill in the section list on dwp_obj_file
+  // (by calling GetSectionList(false)) as this is invoked before we may have
+  // all the symbol files collected and available.
+  if (!dwp_obj_file || !dwp_obj_file->GetSectionList(false)->FindSectionByType(
+   eSectionTypeDWARFDebugCuIndex, false))
+return false;
+  return true;

JDevlieghere wrote:

```
return dwp_obj_file && 
dwp_obj_file->GetSectionList(false)->FindSectionByType(eSectionTypeDWARFDebugCuIndex,
 false));
```

https://github.com/llvm/llvm-project/pull/85693
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add register lookup as another fallback computation for address-expressions (PR #85492)

2024-03-18 Thread via lldb-commits

https://github.com/jimingham updated 
https://github.com/llvm/llvm-project/pull/85492

>From 59320299f5aa3f9e03695e762c9fec237362c460 Mon Sep 17 00:00:00 2001
From: Jim Ingham 
Date: Fri, 15 Mar 2024 17:56:20 -0700
Subject: [PATCH 1/2] Add register lookup as another fallback computation for
 address-expressions

The idea behind the address-expression is that it handles all the common
expressions that produce addresses.  It handles actual valid expressions
that return a scalar, and it handles useful cases that the various source 
languages
don't support.  At present, the fallback handles:

{+-}

which isn't valid C but is very handy.

This patch adds handling of:

$

and

${+-}

That's kind of pointless in C because the C expression parser handles
that expression already.  But some languages don't have a straightforward
way to represent register values like this (swift) so having this fallback
is quite a quality of life improvement.

I added a test which tests that I didn't mess up either of these fallbacks,
though it doesn't test the actually handling of registers that I added, since
the expression parser for C succeeds in that case and returns before this code
gets run.

I will add a test on the swift fork for that checks that this works the same
way for a swift frame after this check.
---
 lldb/source/Interpreter/OptionArgParser.cpp   | 49 ---
 .../commands/target/modules/lookup/Makefile   |  4 ++
 .../lookup/TestImageLookupPCExpression.py | 27 ++
 .../API/commands/target/modules/lookup/main.c | 15 ++
 4 files changed, 88 insertions(+), 7 deletions(-)
 create mode 100644 lldb/test/API/commands/target/modules/lookup/Makefile
 create mode 100644 
lldb/test/API/commands/target/modules/lookup/TestImageLookupPCExpression.py
 create mode 100644 lldb/test/API/commands/target/modules/lookup/main.c

diff --git a/lldb/source/Interpreter/OptionArgParser.cpp 
b/lldb/source/Interpreter/OptionArgParser.cpp
index 75ccad87467e95..dd914138fe0e6b 100644
--- a/lldb/source/Interpreter/OptionArgParser.cpp
+++ b/lldb/source/Interpreter/OptionArgParser.cpp
@@ -9,7 +9,9 @@
 #include "lldb/Interpreter/OptionArgParser.h"
 #include "lldb/DataFormatters/FormatManager.h"
 #include "lldb/Target/ABI.h"
+#include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/Target.h"
+#include "lldb/Utility/RegisterValue.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StreamString.h"
 
@@ -233,24 +235,57 @@ OptionArgParser::DoToAddress(const ExecutionContext 
*exe_ctx, llvm::StringRef s,
   // Since the compiler can't handle things like "main + 12" we should try to
   // do this for now. The compiler doesn't like adding offsets to function
   // pointer types.
+  // Some languages also don't have a natural representation for register
+  // values (e.g. swift) so handle simple uses of them here as well.
   static RegularExpression g_symbol_plus_offset_regex(
-  "^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
+  "^(\\$[^ +-]+)|(([^ 
+-]+)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*)$");
 
   llvm::SmallVector matches;
   if (g_symbol_plus_offset_regex.Execute(sref, )) {
 uint64_t offset = 0;
-llvm::StringRef name = matches[1];
-llvm::StringRef sign = matches[2];
-llvm::StringRef str_offset = matches[3];
-if (!str_offset.getAsInteger(0, offset)) {
+llvm::StringRef name;
+if (!matches[1].empty())
+  name = matches[1];
+else
+  name = matches[3];
+
+llvm::StringRef sign = matches[4];
+llvm::StringRef str_offset = matches[5];
+std::optional register_value;
+StackFrame *frame = exe_ctx->GetFramePtr();
+if (frame && !name.empty() && name[0] == '$') {
+  // Some languages don't have a natural type for register values, but it
+  // is still useful to look them up here:
+  RegisterContextSP reg_ctx_sp = frame->GetRegisterContext();
+  if (reg_ctx_sp) {
+llvm::StringRef base_name = name.substr(1);
+const RegisterInfo *reg_info = 
reg_ctx_sp->GetRegisterInfoByName(base_name);
+if (reg_info) {
+  RegisterValue reg_val;
+  bool success = reg_ctx_sp->ReadRegister(reg_info, reg_val);
+  if (success && reg_val.GetType() != RegisterValue::eTypeInvalid) {
+register_value = reg_val.GetAsUInt64(0, );
+if (!success)
+  register_value.reset();
+  }
+}
+  } 
+}
+if (!str_offset.empty() && !str_offset.getAsInteger(0, offset)) {
   Status error;
-  addr = ToAddress(exe_ctx, name, LLDB_INVALID_ADDRESS, );
+  if (register_value)
+addr = register_value.value();
+  else
+addr = ToAddress(exe_ctx, name, LLDB_INVALID_ADDRESS, );
   if (addr != LLDB_INVALID_ADDRESS) {
 if (sign[0] == '+')
   return addr + offset;
 return addr - offset;
   }
-}
+} else if (register_value)
+  // In the case of register values, someone might just want to 

[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei ready_for_review 
https://github.com/llvm/llvm-project/pull/85693
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei edited 
https://github.com/llvm/llvm-project/pull/85693
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei edited 
https://github.com/llvm/llvm-project/pull/85693
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei updated 
https://github.com/llvm/llvm-project/pull/85693

>From 9713607cd4839ad355c7fd2e786ae7eb5a96f637 Mon Sep 17 00:00:00 2001
From: Kevin Frei 
Date: Fri, 15 Mar 2024 08:54:04 -0700
Subject: [PATCH 1/4] Tests (w/fixes) for initial DebugInfoD LLDB integration

Summary:
While adding tests for DebugInfoD integration, there were a couple issues that 
came up:
DWP from /debuginfo for a stripped binary needs to return symbols from 
/executable

Test Plan: Added some API tests

Reviewers: gclayton, hyubo

Subscribers:

Tasks: T179375937

Tags: debuginfod

Differential Revision: https://phabricator.intern.facebook.com/D54953389
---
 .../Python/lldbsuite/test/make/Makefile.rules |  33 +++-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  |  40 +++--
 .../Plugins/SymbolLocator/CMakeLists.txt  |   7 +-
 .../SymbolVendor/ELF/SymbolVendorELF.cpp  |  32 +++-
 lldb/test/API/debuginfod/Normal/Makefile  |  25 +++
 .../API/debuginfod/Normal/TestDebuginfod.py   | 159 +
 lldb/test/API/debuginfod/Normal/main.c|   7 +
 lldb/test/API/debuginfod/SplitDWARF/Makefile  |  29 +++
 .../SplitDWARF/TestDebuginfodDWP.py   | 167 ++
 lldb/test/API/debuginfod/SplitDWARF/main.c|   7 +
 10 files changed, 489 insertions(+), 17 deletions(-)
 create mode 100644 lldb/test/API/debuginfod/Normal/Makefile
 create mode 100644 lldb/test/API/debuginfod/Normal/TestDebuginfod.py
 create mode 100644 lldb/test/API/debuginfod/Normal/main.c
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/Makefile
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/main.c

diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index bfd249ccd43f2e..b33c087357a79b 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -51,7 +51,7 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
 #
 # GNUWin32 uname gives "windows32" or "server version windows32" while
 # some versions of MSYS uname return "MSYS_NT*", but most environments
-# standardize on "Windows_NT", so we'll make it consistent here. 
+# standardize on "Windows_NT", so we'll make it consistent here.
 # When running tests from Visual Studio, the environment variable isn't
 # inherited all the way down to the process spawned for make.
 #--
@@ -210,6 +210,12 @@ else
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
DSYM = $(EXE).debug
endif
+
+   ifeq "$(MERGE_DWOS)" "YES"
+   MAKE_DWO := YES
+   DWP_NAME = $(EXE).dwp
+   DYLIB_DWP_NAME = $(DYLIB_NAME).dwp
+   endif
 endif
 
 LIMIT_DEBUG_INFO_FLAGS =
@@ -357,6 +363,7 @@ ifneq "$(OS)" "Darwin"
 
OBJCOPY ?= $(call replace_cc_with,objcopy)
ARCHIVER ?= $(call replace_cc_with,ar)
+   DWP ?= $(call replace_cc_with,dwp)
override AR = $(ARCHIVER)
 endif
 
@@ -527,6 +534,10 @@ ifneq "$(CXX)" ""
endif
 endif
 
+ifeq "$(GEN_GNU_BUILD_ID)" "YES"
+   LDFLAGS += -Wl,--build-id
+endif
+
 #--
 # DYLIB_ONLY variable can be used to skip the building of a.out.
 # See the sections below regarding dSYM file as well as the building of
@@ -565,11 +576,25 @@ else
 endif
 else
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(EXE)" "$(EXE).full"
+endif
$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o "$(DWP_NAME)" $(DWOS)
+endif
 endif
 
+
+#--
+# Support emitting the context of the GNU build-id into a file
+# This needs to be used in conjunction with GEN_GNU_BUILD_ID := YES
+#--
+$(EXE).uuid : $(EXE)
+   $(OBJCOPY) --dump-section=.note.gnu.build-id=$@ $<
+
 #--
 # Make the dylib
 #--
@@ -610,9 +635,15 @@ endif
 else
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+   ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).full"
+   endif
$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" 
"$(DYLIB_FILENAME).debug"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" 
"$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o $(DYLIB_DWP_FILE) $(DYLIB_DWOS)
+endif
 endif
 
 

[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei updated 
https://github.com/llvm/llvm-project/pull/85693

>From 9713607cd4839ad355c7fd2e786ae7eb5a96f637 Mon Sep 17 00:00:00 2001
From: Kevin Frei 
Date: Fri, 15 Mar 2024 08:54:04 -0700
Subject: [PATCH 1/4] Tests (w/fixes) for initial DebugInfoD LLDB integration

Summary:
While adding tests for DebugInfoD integration, there were a couple issues that 
came up:
DWP from /debuginfo for a stripped binary needs to return symbols from 
/executable

Test Plan: Added some API tests

Reviewers: gclayton, hyubo

Subscribers:

Tasks: T179375937

Tags: debuginfod

Differential Revision: https://phabricator.intern.facebook.com/D54953389
---
 .../Python/lldbsuite/test/make/Makefile.rules |  33 +++-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  |  40 +++--
 .../Plugins/SymbolLocator/CMakeLists.txt  |   7 +-
 .../SymbolVendor/ELF/SymbolVendorELF.cpp  |  32 +++-
 lldb/test/API/debuginfod/Normal/Makefile  |  25 +++
 .../API/debuginfod/Normal/TestDebuginfod.py   | 159 +
 lldb/test/API/debuginfod/Normal/main.c|   7 +
 lldb/test/API/debuginfod/SplitDWARF/Makefile  |  29 +++
 .../SplitDWARF/TestDebuginfodDWP.py   | 167 ++
 lldb/test/API/debuginfod/SplitDWARF/main.c|   7 +
 10 files changed, 489 insertions(+), 17 deletions(-)
 create mode 100644 lldb/test/API/debuginfod/Normal/Makefile
 create mode 100644 lldb/test/API/debuginfod/Normal/TestDebuginfod.py
 create mode 100644 lldb/test/API/debuginfod/Normal/main.c
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/Makefile
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/main.c

diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index bfd249ccd43f2e..b33c087357a79b 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -51,7 +51,7 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
 #
 # GNUWin32 uname gives "windows32" or "server version windows32" while
 # some versions of MSYS uname return "MSYS_NT*", but most environments
-# standardize on "Windows_NT", so we'll make it consistent here. 
+# standardize on "Windows_NT", so we'll make it consistent here.
 # When running tests from Visual Studio, the environment variable isn't
 # inherited all the way down to the process spawned for make.
 #--
@@ -210,6 +210,12 @@ else
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
DSYM = $(EXE).debug
endif
+
+   ifeq "$(MERGE_DWOS)" "YES"
+   MAKE_DWO := YES
+   DWP_NAME = $(EXE).dwp
+   DYLIB_DWP_NAME = $(DYLIB_NAME).dwp
+   endif
 endif
 
 LIMIT_DEBUG_INFO_FLAGS =
@@ -357,6 +363,7 @@ ifneq "$(OS)" "Darwin"
 
OBJCOPY ?= $(call replace_cc_with,objcopy)
ARCHIVER ?= $(call replace_cc_with,ar)
+   DWP ?= $(call replace_cc_with,dwp)
override AR = $(ARCHIVER)
 endif
 
@@ -527,6 +534,10 @@ ifneq "$(CXX)" ""
endif
 endif
 
+ifeq "$(GEN_GNU_BUILD_ID)" "YES"
+   LDFLAGS += -Wl,--build-id
+endif
+
 #--
 # DYLIB_ONLY variable can be used to skip the building of a.out.
 # See the sections below regarding dSYM file as well as the building of
@@ -565,11 +576,25 @@ else
 endif
 else
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(EXE)" "$(EXE).full"
+endif
$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o "$(DWP_NAME)" $(DWOS)
+endif
 endif
 
+
+#--
+# Support emitting the context of the GNU build-id into a file
+# This needs to be used in conjunction with GEN_GNU_BUILD_ID := YES
+#--
+$(EXE).uuid : $(EXE)
+   $(OBJCOPY) --dump-section=.note.gnu.build-id=$@ $<
+
 #--
 # Make the dylib
 #--
@@ -610,9 +635,15 @@ endif
 else
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+   ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).full"
+   endif
$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" 
"$(DYLIB_FILENAME).debug"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" 
"$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o $(DYLIB_DWP_FILE) $(DYLIB_DWOS)
+endif
 endif
 
 

[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan closed 
https://github.com/llvm/llvm-project/pull/85669
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 65d444b - [lldb][nfc] Factor out repeated code in DWIM Print (#85669)

2024-03-18 Thread via lldb-commits

Author: Felipe de Azevedo Piovezan
Date: 2024-03-18T14:34:08-07:00
New Revision: 65d444b9edb895443754c13d9c008af180eb5c71

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

LOG: [lldb][nfc] Factor out repeated code in DWIM Print (#85669)

The code that prints ValueObjects is duplicated across two different
cases of the dwim-print command, and a subsequent commit will add a
third case. As such, this commit factors out the common code into a
lambda. A free function was considered, but there is too much
function-local context required in that.

We also reword some of the comments so that they stop counting cases,
making it easier to add other cases later.

Added: 


Modified: 
lldb/source/Commands/CommandObjectDWIMPrint.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index a88da986bb384f..e1255f37d9bc58 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -129,6 +129,19 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 }
   };
 
+  // Dump `valobj` according to whether `po` was requested or not.
+  auto dump_val_object = [&](ValueObject ) {
+if (is_po) {
+  StreamString temp_result_stream;
+  valobj.Dump(temp_result_stream, dump_options);
+  llvm::StringRef output = temp_result_stream.GetString();
+  maybe_add_hint(output);
+  result.GetOutputStream() << output;
+} else {
+  valobj.Dump(result.GetOutputStream(), dump_options);
+}
+  };
+
   // First, try `expr` as the name of a frame variable.
   if (frame) {
 auto valobj_sp = frame->FindVariable(ConstString(expr));
@@ -146,15 +159,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 flags, expr);
   }
 
-  if (is_po) {
-StreamString temp_result_stream;
-valobj_sp->Dump(temp_result_stream, dump_options);
-llvm::StringRef output = temp_result_stream.GetString();
-maybe_add_hint(output);
-result.GetOutputStream() << output;
-  } else {
-valobj_sp->Dump(result.GetOutputStream(), dump_options);
-  }
+  dump_val_object(*valobj_sp);
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return;
 }
@@ -165,7 +170,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 if (auto *state = target.GetPersistentExpressionStateForLanguage(language))
   if (auto var_sp = state->GetVariable(expr))
 if (auto valobj_sp = var_sp->GetValueObject()) {
-  valobj_sp->Dump(result.GetOutputStream(), dump_options);
+  dump_val_object(*valobj_sp);
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return;
 }
@@ -196,17 +201,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 expr);
   }
 
-  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) {
-if (is_po) {
-  StreamString temp_result_stream;
-  valobj_sp->Dump(temp_result_stream, dump_options);
-  llvm::StringRef output = temp_result_stream.GetString();
-  maybe_add_hint(output);
-  result.GetOutputStream() << output;
-} else {
-  valobj_sp->Dump(result.GetOutputStream(), dump_options);
-}
-  }
+  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
+dump_val_object(*valobj_sp);
 
   if (suppress_result)
 if (auto result_var_sp =



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


[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei edited 
https://github.com/llvm/llvm-project/pull/85693
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan updated 
https://github.com/llvm/llvm-project/pull/85669

>From baa85a25548546679bf2b54fb723b51a2fb50e82 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Mon, 18 Mar 2024 10:14:49 -0700
Subject: [PATCH 1/2] [lldb][nfc] Factor out repeated code in DWIM Print

The code that prints ValueObjects is duplicated across two different cases of
the dwim-print command, and a subsequent commit will add a third case. As such,
this commit factors out the common code into a lambda. A free function was
considered, but there is too much function-local context required in that.

We also reword some of the comments so that they stop counting cases, making it
easier to add other cases later.
---
 .../Commands/CommandObjectDWIMPrint.cpp   | 36 +--
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index a88da986bb384f..933e5af3b69ff7 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -129,6 +129,19 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 }
   };
 
+  // Dump `valobj` according to whether `po` was requested or not.
+  auto dump_val_object = [&](ValueObject ) {
+if (is_po) {
+  StreamString temp_result_stream;
+  valobj.Dump(temp_result_stream, dump_options);
+  llvm::StringRef output = temp_result_stream.GetString();
+  maybe_add_hint(output);
+  result.GetOutputStream() << output;
+} else {
+  valobj.Dump(result.GetOutputStream(), dump_options);
+}
+  };
+
   // First, try `expr` as the name of a frame variable.
   if (frame) {
 auto valobj_sp = frame->FindVariable(ConstString(expr));
@@ -146,15 +159,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 flags, expr);
   }
 
-  if (is_po) {
-StreamString temp_result_stream;
-valobj_sp->Dump(temp_result_stream, dump_options);
-llvm::StringRef output = temp_result_stream.GetString();
-maybe_add_hint(output);
-result.GetOutputStream() << output;
-  } else {
-valobj_sp->Dump(result.GetOutputStream(), dump_options);
-  }
+  dump_val_object(*valobj_sp);
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return;
 }
@@ -196,17 +201,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 expr);
   }
 
-  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) {
-if (is_po) {
-  StreamString temp_result_stream;
-  valobj_sp->Dump(temp_result_stream, dump_options);
-  llvm::StringRef output = temp_result_stream.GetString();
-  maybe_add_hint(output);
-  result.GetOutputStream() << output;
-} else {
-  valobj_sp->Dump(result.GetOutputStream(), dump_options);
-}
-  }
+  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
+dump_val_object(*valobj_sp);
 
   if (suppress_result)
 if (auto result_var_sp =

>From d6d212093f58324c1778b73360456738944c2773 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Mon, 18 Mar 2024 14:08:04 -0700
Subject: [PATCH 2/2] fixup! also use new lambda on persisent variable case

---
 lldb/source/Commands/CommandObjectDWIMPrint.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 933e5af3b69ff7..e1255f37d9bc58 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -170,7 +170,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 if (auto *state = target.GetPersistentExpressionStateForLanguage(language))
   if (auto var_sp = state->GetVariable(expr))
 if (auto valobj_sp = var_sp->GetValueObject()) {
-  valobj_sp->Dump(result.GetOutputStream(), dump_options);
+  dump_val_object(*valobj_sp);
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return;
 }

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


[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread Dave Lee via lldb-commits

https://github.com/kastiglione approved this pull request.

one request, and then looks good, thanks.

https://github.com/llvm/llvm-project/pull/85669
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread Dave Lee via lldb-commits

https://github.com/kastiglione edited 
https://github.com/llvm/llvm-project/pull/85669
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread Dave Lee via lldb-commits


@@ -129,6 +129,19 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 }
   };
 
+  // Dump `valobj` according to whether `po` was requested or not.
+  auto dump_val_object = [&](ValueObject ) {

kastiglione wrote:

Would you mind also applying this function to the block that handles persistent 
variables (I just added it in #85152). Thanks.

https://github.com/llvm/llvm-project/pull/85669
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Kevin Frei (kevinfrei)


Changes

Finally getting back to Debuginfod tests, I've migrated my tests from shell to 
API (at @JDevlieghere's suggestion) and addressed a couple issues that 
came about during testing.

---

Patch is 24.53 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/85693.diff


10 Files Affected:

- (modified) lldb/packages/Python/lldbsuite/test/make/Makefile.rules (+31) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+27-13) 
- (modified) lldb/source/Plugins/SymbolLocator/CMakeLists.txt (+6-1) 
- (modified) lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp (+30-2) 
- (added) lldb/test/API/debuginfod/Normal/Makefile (+25) 
- (added) lldb/test/API/debuginfod/Normal/TestDebuginfod.py (+161) 
- (added) lldb/test/API/debuginfod/Normal/main.c (+7) 
- (added) lldb/test/API/debuginfod/SplitDWARF/Makefile (+29) 
- (added) lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py (+169) 
- (added) lldb/test/API/debuginfod/SplitDWARF/main.c (+7) 


``diff
diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index bfd249ccd43f2e..370db60ab7f7d6 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -210,6 +210,12 @@ else
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
DSYM = $(EXE).debug
endif
+
+   ifeq "$(MERGE_DWOS)" "YES"
+   MAKE_DWO := YES
+   DWP_NAME = $(EXE).dwp
+   DYLIB_DWP_NAME = $(DYLIB_NAME).dwp
+   endif
 endif
 
 LIMIT_DEBUG_INFO_FLAGS =
@@ -357,6 +363,7 @@ ifneq "$(OS)" "Darwin"
 
OBJCOPY ?= $(call replace_cc_with,objcopy)
ARCHIVER ?= $(call replace_cc_with,ar)
+   DWP ?= $(call replace_cc_with,dwp)
override AR = $(ARCHIVER)
 endif
 
@@ -527,6 +534,10 @@ ifneq "$(CXX)" ""
endif
 endif
 
+ifeq "$(GEN_GNU_BUILD_ID)" "YES"
+   LDFLAGS += -Wl,--build-id
+endif
+
 #--
 # DYLIB_ONLY variable can be used to skip the building of a.out.
 # See the sections below regarding dSYM file as well as the building of
@@ -565,11 +576,25 @@ else
 endif
 else
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(EXE)" "$(EXE).full"
+endif
$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o "$(DWP_NAME)" $(DWOS)
+endif
 endif
 
+
+#--
+# Support emitting the content of the GNU build-id into a file
+# This needs to be used in conjunction with GEN_GNU_BUILD_ID := YES
+#--
+$(EXE).uuid : $(EXE)
+   $(OBJCOPY) --dump-section=.note.gnu.build-id=$@ $<
+
 #--
 # Make the dylib
 #--
@@ -610,9 +635,15 @@ endif
 else
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+   ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).full"
+   endif
$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" 
"$(DYLIB_FILENAME).debug"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" 
"$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o $(DYLIB_DWP_FILE) $(DYLIB_DWOS)
+endif
 endif
 
 #--
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 5f67658f86ea96..0b7e86743f9f9f 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -4377,26 +4377,40 @@ const std::shared_ptr 
::GetDwpSymbolFile() {
 FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
 ModuleSpec module_spec;
 module_spec.GetFileSpec() = m_objfile_sp->GetFileSpec();
+FileSpec dwp_filespec;
 for (const auto  : symfiles.files()) {
   module_spec.GetSymbolFileSpec() =
   FileSpec(symfile.GetPath() + ".dwp", symfile.GetPathStyle());
   LLDB_LOG(log, "Searching for DWP using: \"{0}\"",
module_spec.GetSymbolFileSpec());
-  FileSpec dwp_filespec =
+  dwp_filespec =
   PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
   if (FileSystem::Instance().Exists(dwp_filespec)) {
-LLDB_LOG(log, "Found DWP file: \"{0}\"", dwp_filespec);
-DataBufferSP dwp_file_data_sp;
-

[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei converted_to_draft 
https://github.com/llvm/llvm-project/pull/85693
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei ready_for_review 
https://github.com/llvm/llvm-project/pull/85693
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
18da51b2b227bcaee0efd13c4bc9ba408ea6b6e6...2998d958d242210601678e40606720520259ecd7
 lldb/test/API/debuginfod/Normal/TestDebuginfod.py 
lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py
``





View the diff from darker here.


``diff
--- Normal/TestDebuginfod.py2024-03-18 20:24:00.00 +
+++ Normal/TestDebuginfod.py2024-03-18 20:30:18.700337 +
@@ -20,11 +20,11 @@
 return None
 header = struct.unpack_from("<4I", data)
 if len(header) != 4:
 return None
 # 4 element 'prefix', 20 bytes of uuid, 3 byte long string: 'GNU':
-if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 
0x554e47:
+if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 
0x554E47:
 return None
 return data[16:].hex()
 
 
 """
@@ -33,10 +33,12 @@
 
 For no-split-dwarf scenarios, there are 2 variations:
 1 - A stripped binary with it's corresponding unstripped binary:
 2 - A stripped binary with a corresponding --only-keep-debug symbols file
 """
+
+
 @skipUnlessPlatform(["linux", "freebsd"])
 class DebugInfodTests(TestBase):
 # No need to try every flavor of debug inf.
 NO_DEBUG_INFO_TESTCASE = True
 
@@ -97,18 +99,25 @@
 loc = bp.GetLocationAtIndex(0)
 self.assertTrue(loc and loc.IsValid(), "Location is valid")
 addr = loc.GetAddress()
 self.assertTrue(addr and addr.IsValid(), "Loc address is valid")
 line_entry = addr.GetLineEntry()
-self.assertEqual(should_have_loc, line_entry != None and 
line_entry.IsValid(), "Loc line entry is valid")
+self.assertEqual(
+should_have_loc,
+line_entry != None and line_entry.IsValid(),
+"Loc line entry is valid",
+)
 if should_have_loc:
 self.assertEqual(line_entry.GetLine(), 4)
-self.assertEqual(line_entry.GetFileSpec().GetFilename(), 
self.main_source_file.GetFilename())
+self.assertEqual(
+line_entry.GetFileSpec().GetFilename(),
+self.main_source_file.GetFilename(),
+)
 self.dbg.DeleteTarget(target)
 shutil.rmtree(self.tmp_dir)
 
-def config_test(self, local_files, debuginfo = None, executable = None):
+def config_test(self, local_files, debuginfo=None, executable=None):
 """
 Set up a test with local_files[] copied to a different location
 so that we control which files are, or are not, found in the file 
system.
 Also, create a stand-alone file-system 'hosted' debuginfod server with 
the
 provided debuginfo and executable files (if they exist)
@@ -136,26 +145,41 @@
 self.aout = ""
 # Copy the files used by the test:
 for f in local_files:
 shutil.copy(self.getBuildArtifact(f), test_dir)
 # The first item is the binary to be used for the test
-if (self.aout == ""):
+if self.aout == "":
 self.aout = os.path.join(test_dir, f)
 
 use_debuginfod = debuginfo != None or executable != None
 
 # Populated the 'file://... mocked' Debuginfod server:
 if use_debuginfod:
 os.makedirs(os.path.join(self.tmp_dir, "cache"))
 uuid_dir = os.path.join(self.tmp_dir, "buildid", uuid)
 os.makedirs(uuid_dir)
 if debuginfo:
-shutil.copy(self.getBuildArtifact(debuginfo), 
os.path.join(uuid_dir, "debuginfo"))
+shutil.copy(
+self.getBuildArtifact(debuginfo),
+os.path.join(uuid_dir, "debuginfo"),
+)
 if executable:
-shutil.copy(self.getBuildArtifact(executable), 
os.path.join(uuid_dir, "executable"))
+shutil.copy(
+self.getBuildArtifact(executable),
+os.path.join(uuid_dir, "executable"),
+)
 
 # Configure LLDB for the test:
-self.runCmd("settings set symbols.enable-external-lookup %s" % 
str(use_debuginfod).lower())
+self.runCmd(
+"settings set symbols.enable-external-lookup %s"
+% str(use_debuginfod).lower()
+)
 self.runCmd("settings clear 
plugin.symbol-locator.debuginfod.server-urls")
 if use_debuginfod:
-self.runCmd("settings set 
plugin.symbol-locator.debuginfod.cache-path %s/cache" % self.tmp_dir)
-self.runCmd("settings insert-before 
plugin.symbol-locator.debuginfod.server-urls 0 file://%s" % self.tmp_dir)
+self.runCmd(
+"settings set plugin.symbol-locator.debuginfod.cache-path 
%s/cache"
+% self.tmp_dir
+)
+ 

[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei updated 
https://github.com/llvm/llvm-project/pull/85693

>From 9713607cd4839ad355c7fd2e786ae7eb5a96f637 Mon Sep 17 00:00:00 2001
From: Kevin Frei 
Date: Fri, 15 Mar 2024 08:54:04 -0700
Subject: [PATCH 1/3] Tests (w/fixes) for initial DebugInfoD LLDB integration

Summary:
While adding tests for DebugInfoD integration, there were a couple issues that 
came up:
DWP from /debuginfo for a stripped binary needs to return symbols from 
/executable

Test Plan: Added some API tests

Reviewers: gclayton, hyubo

Subscribers:

Tasks: T179375937

Tags: debuginfod

Differential Revision: https://phabricator.intern.facebook.com/D54953389
---
 .../Python/lldbsuite/test/make/Makefile.rules |  33 +++-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  |  40 +++--
 .../Plugins/SymbolLocator/CMakeLists.txt  |   7 +-
 .../SymbolVendor/ELF/SymbolVendorELF.cpp  |  32 +++-
 lldb/test/API/debuginfod/Normal/Makefile  |  25 +++
 .../API/debuginfod/Normal/TestDebuginfod.py   | 159 +
 lldb/test/API/debuginfod/Normal/main.c|   7 +
 lldb/test/API/debuginfod/SplitDWARF/Makefile  |  29 +++
 .../SplitDWARF/TestDebuginfodDWP.py   | 167 ++
 lldb/test/API/debuginfod/SplitDWARF/main.c|   7 +
 10 files changed, 489 insertions(+), 17 deletions(-)
 create mode 100644 lldb/test/API/debuginfod/Normal/Makefile
 create mode 100644 lldb/test/API/debuginfod/Normal/TestDebuginfod.py
 create mode 100644 lldb/test/API/debuginfod/Normal/main.c
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/Makefile
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/main.c

diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index bfd249ccd43f2e..b33c087357a79b 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -51,7 +51,7 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
 #
 # GNUWin32 uname gives "windows32" or "server version windows32" while
 # some versions of MSYS uname return "MSYS_NT*", but most environments
-# standardize on "Windows_NT", so we'll make it consistent here. 
+# standardize on "Windows_NT", so we'll make it consistent here.
 # When running tests from Visual Studio, the environment variable isn't
 # inherited all the way down to the process spawned for make.
 #--
@@ -210,6 +210,12 @@ else
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
DSYM = $(EXE).debug
endif
+
+   ifeq "$(MERGE_DWOS)" "YES"
+   MAKE_DWO := YES
+   DWP_NAME = $(EXE).dwp
+   DYLIB_DWP_NAME = $(DYLIB_NAME).dwp
+   endif
 endif
 
 LIMIT_DEBUG_INFO_FLAGS =
@@ -357,6 +363,7 @@ ifneq "$(OS)" "Darwin"
 
OBJCOPY ?= $(call replace_cc_with,objcopy)
ARCHIVER ?= $(call replace_cc_with,ar)
+   DWP ?= $(call replace_cc_with,dwp)
override AR = $(ARCHIVER)
 endif
 
@@ -527,6 +534,10 @@ ifneq "$(CXX)" ""
endif
 endif
 
+ifeq "$(GEN_GNU_BUILD_ID)" "YES"
+   LDFLAGS += -Wl,--build-id
+endif
+
 #--
 # DYLIB_ONLY variable can be used to skip the building of a.out.
 # See the sections below regarding dSYM file as well as the building of
@@ -565,11 +576,25 @@ else
 endif
 else
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(EXE)" "$(EXE).full"
+endif
$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o "$(DWP_NAME)" $(DWOS)
+endif
 endif
 
+
+#--
+# Support emitting the context of the GNU build-id into a file
+# This needs to be used in conjunction with GEN_GNU_BUILD_ID := YES
+#--
+$(EXE).uuid : $(EXE)
+   $(OBJCOPY) --dump-section=.note.gnu.build-id=$@ $<
+
 #--
 # Make the dylib
 #--
@@ -610,9 +635,15 @@ endif
 else
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+   ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).full"
+   endif
$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" 
"$(DYLIB_FILENAME).debug"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" 
"$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o $(DYLIB_DWP_FILE) $(DYLIB_DWOS)
+endif
 endif
 
 

[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei updated 
https://github.com/llvm/llvm-project/pull/85693

>From 9713607cd4839ad355c7fd2e786ae7eb5a96f637 Mon Sep 17 00:00:00 2001
From: Kevin Frei 
Date: Fri, 15 Mar 2024 08:54:04 -0700
Subject: [PATCH 1/3] Tests (w/fixes) for initial DebugInfoD LLDB integration

Summary:
While adding tests for DebugInfoD integration, there were a couple issues that 
came up:
DWP from /debuginfo for a stripped binary needs to return symbols from 
/executable

Test Plan: Added some API tests

Reviewers: gclayton, hyubo

Subscribers:

Tasks: T179375937

Tags: debuginfod

Differential Revision: https://phabricator.intern.facebook.com/D54953389
---
 .../Python/lldbsuite/test/make/Makefile.rules |  33 +++-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  |  40 +++--
 .../Plugins/SymbolLocator/CMakeLists.txt  |   7 +-
 .../SymbolVendor/ELF/SymbolVendorELF.cpp  |  32 +++-
 lldb/test/API/debuginfod/Normal/Makefile  |  25 +++
 .../API/debuginfod/Normal/TestDebuginfod.py   | 159 +
 lldb/test/API/debuginfod/Normal/main.c|   7 +
 lldb/test/API/debuginfod/SplitDWARF/Makefile  |  29 +++
 .../SplitDWARF/TestDebuginfodDWP.py   | 167 ++
 lldb/test/API/debuginfod/SplitDWARF/main.c|   7 +
 10 files changed, 489 insertions(+), 17 deletions(-)
 create mode 100644 lldb/test/API/debuginfod/Normal/Makefile
 create mode 100644 lldb/test/API/debuginfod/Normal/TestDebuginfod.py
 create mode 100644 lldb/test/API/debuginfod/Normal/main.c
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/Makefile
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/main.c

diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index bfd249ccd43f2e..b33c087357a79b 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -51,7 +51,7 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
 #
 # GNUWin32 uname gives "windows32" or "server version windows32" while
 # some versions of MSYS uname return "MSYS_NT*", but most environments
-# standardize on "Windows_NT", so we'll make it consistent here. 
+# standardize on "Windows_NT", so we'll make it consistent here.
 # When running tests from Visual Studio, the environment variable isn't
 # inherited all the way down to the process spawned for make.
 #--
@@ -210,6 +210,12 @@ else
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
DSYM = $(EXE).debug
endif
+
+   ifeq "$(MERGE_DWOS)" "YES"
+   MAKE_DWO := YES
+   DWP_NAME = $(EXE).dwp
+   DYLIB_DWP_NAME = $(DYLIB_NAME).dwp
+   endif
 endif
 
 LIMIT_DEBUG_INFO_FLAGS =
@@ -357,6 +363,7 @@ ifneq "$(OS)" "Darwin"
 
OBJCOPY ?= $(call replace_cc_with,objcopy)
ARCHIVER ?= $(call replace_cc_with,ar)
+   DWP ?= $(call replace_cc_with,dwp)
override AR = $(ARCHIVER)
 endif
 
@@ -527,6 +534,10 @@ ifneq "$(CXX)" ""
endif
 endif
 
+ifeq "$(GEN_GNU_BUILD_ID)" "YES"
+   LDFLAGS += -Wl,--build-id
+endif
+
 #--
 # DYLIB_ONLY variable can be used to skip the building of a.out.
 # See the sections below regarding dSYM file as well as the building of
@@ -565,11 +576,25 @@ else
 endif
 else
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(EXE)" "$(EXE).full"
+endif
$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o "$(DWP_NAME)" $(DWOS)
+endif
 endif
 
+
+#--
+# Support emitting the context of the GNU build-id into a file
+# This needs to be used in conjunction with GEN_GNU_BUILD_ID := YES
+#--
+$(EXE).uuid : $(EXE)
+   $(OBJCOPY) --dump-section=.note.gnu.build-id=$@ $<
+
 #--
 # Make the dylib
 #--
@@ -610,9 +635,15 @@ endif
 else
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+   ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).full"
+   endif
$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" 
"$(DYLIB_FILENAME).debug"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" 
"$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o $(DYLIB_DWP_FILE) $(DYLIB_DWOS)
+endif
 endif
 
 

[Lldb-commits] [lldb] DebugInfoD tests + fixing issues exposed by tests (PR #85693)

2024-03-18 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei created 
https://github.com/llvm/llvm-project/pull/85693

Finally getting back to Debuginfod tests, I've migrated my tests from shell to 
API (at @JDevlieghere's suggestion) and addressed a couple issues that came 
about during testing.

>From 9713607cd4839ad355c7fd2e786ae7eb5a96f637 Mon Sep 17 00:00:00 2001
From: Kevin Frei 
Date: Fri, 15 Mar 2024 08:54:04 -0700
Subject: [PATCH 1/2] Tests (w/fixes) for initial DebugInfoD LLDB integration

Summary:
While adding tests for DebugInfoD integration, there were a couple issues that 
came up:
DWP from /debuginfo for a stripped binary needs to return symbols from 
/executable

Test Plan: Added some API tests

Reviewers: gclayton, hyubo

Subscribers:

Tasks: T179375937

Tags: debuginfod

Differential Revision: https://phabricator.intern.facebook.com/D54953389
---
 .../Python/lldbsuite/test/make/Makefile.rules |  33 +++-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  |  40 +++--
 .../Plugins/SymbolLocator/CMakeLists.txt  |   7 +-
 .../SymbolVendor/ELF/SymbolVendorELF.cpp  |  32 +++-
 lldb/test/API/debuginfod/Normal/Makefile  |  25 +++
 .../API/debuginfod/Normal/TestDebuginfod.py   | 159 +
 lldb/test/API/debuginfod/Normal/main.c|   7 +
 lldb/test/API/debuginfod/SplitDWARF/Makefile  |  29 +++
 .../SplitDWARF/TestDebuginfodDWP.py   | 167 ++
 lldb/test/API/debuginfod/SplitDWARF/main.c|   7 +
 10 files changed, 489 insertions(+), 17 deletions(-)
 create mode 100644 lldb/test/API/debuginfod/Normal/Makefile
 create mode 100644 lldb/test/API/debuginfod/Normal/TestDebuginfod.py
 create mode 100644 lldb/test/API/debuginfod/Normal/main.c
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/Makefile
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/main.c

diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules 
b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index bfd249ccd43f2e..b33c087357a79b 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -51,7 +51,7 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
 #
 # GNUWin32 uname gives "windows32" or "server version windows32" while
 # some versions of MSYS uname return "MSYS_NT*", but most environments
-# standardize on "Windows_NT", so we'll make it consistent here. 
+# standardize on "Windows_NT", so we'll make it consistent here.
 # When running tests from Visual Studio, the environment variable isn't
 # inherited all the way down to the process spawned for make.
 #--
@@ -210,6 +210,12 @@ else
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
DSYM = $(EXE).debug
endif
+
+   ifeq "$(MERGE_DWOS)" "YES"
+   MAKE_DWO := YES
+   DWP_NAME = $(EXE).dwp
+   DYLIB_DWP_NAME = $(DYLIB_NAME).dwp
+   endif
 endif
 
 LIMIT_DEBUG_INFO_FLAGS =
@@ -357,6 +363,7 @@ ifneq "$(OS)" "Darwin"
 
OBJCOPY ?= $(call replace_cc_with,objcopy)
ARCHIVER ?= $(call replace_cc_with,ar)
+   DWP ?= $(call replace_cc_with,dwp)
override AR = $(ARCHIVER)
 endif
 
@@ -527,6 +534,10 @@ ifneq "$(CXX)" ""
endif
 endif
 
+ifeq "$(GEN_GNU_BUILD_ID)" "YES"
+   LDFLAGS += -Wl,--build-id
+endif
+
 #--
 # DYLIB_ONLY variable can be used to skip the building of a.out.
 # See the sections below regarding dSYM file as well as the building of
@@ -565,11 +576,25 @@ else
 endif
 else
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(EXE)" "$(EXE).full"
+endif
$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
 endif
+ifeq "$(MERGE_DWOS)" "YES"
+   $(DWP) -o "$(DWP_NAME)" $(DWOS)
+endif
 endif
 
+
+#--
+# Support emitting the context of the GNU build-id into a file
+# This needs to be used in conjunction with GEN_GNU_BUILD_ID := YES
+#--
+$(EXE).uuid : $(EXE)
+   $(OBJCOPY) --dump-section=.note.gnu.build-id=$@ $<
+
 #--
 # Make the dylib
 #--
@@ -610,9 +635,15 @@ endif
 else
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+   ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
+   cp "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).full"
+   endif
$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" 
"$(DYLIB_FILENAME).debug"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" 

[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread Felipe de Azevedo Piovezan via lldb-commits

felipepiovezan wrote:

Rebased, address review comments

https://github.com/llvm/llvm-project/pull/85669
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan updated 
https://github.com/llvm/llvm-project/pull/85669

>From baa85a25548546679bf2b54fb723b51a2fb50e82 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Mon, 18 Mar 2024 10:14:49 -0700
Subject: [PATCH] [lldb][nfc] Factor out repeated code in DWIM Print

The code that prints ValueObjects is duplicated across two different cases of
the dwim-print command, and a subsequent commit will add a third case. As such,
this commit factors out the common code into a lambda. A free function was
considered, but there is too much function-local context required in that.

We also reword some of the comments so that they stop counting cases, making it
easier to add other cases later.
---
 .../Commands/CommandObjectDWIMPrint.cpp   | 36 +--
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index a88da986bb384f..933e5af3b69ff7 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -129,6 +129,19 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 }
   };
 
+  // Dump `valobj` according to whether `po` was requested or not.
+  auto dump_val_object = [&](ValueObject ) {
+if (is_po) {
+  StreamString temp_result_stream;
+  valobj.Dump(temp_result_stream, dump_options);
+  llvm::StringRef output = temp_result_stream.GetString();
+  maybe_add_hint(output);
+  result.GetOutputStream() << output;
+} else {
+  valobj.Dump(result.GetOutputStream(), dump_options);
+}
+  };
+
   // First, try `expr` as the name of a frame variable.
   if (frame) {
 auto valobj_sp = frame->FindVariable(ConstString(expr));
@@ -146,15 +159,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 flags, expr);
   }
 
-  if (is_po) {
-StreamString temp_result_stream;
-valobj_sp->Dump(temp_result_stream, dump_options);
-llvm::StringRef output = temp_result_stream.GetString();
-maybe_add_hint(output);
-result.GetOutputStream() << output;
-  } else {
-valobj_sp->Dump(result.GetOutputStream(), dump_options);
-  }
+  dump_val_object(*valobj_sp);
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return;
 }
@@ -196,17 +201,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 expr);
   }
 
-  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) {
-if (is_po) {
-  StreamString temp_result_stream;
-  valobj_sp->Dump(temp_result_stream, dump_options);
-  llvm::StringRef output = temp_result_stream.GetString();
-  maybe_add_hint(output);
-  result.GetOutputStream() << output;
-} else {
-  valobj_sp->Dump(result.GetOutputStream(), dump_options);
-}
-  }
+  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
+dump_val_object(*valobj_sp);
 
   if (suppress_result)
 if (auto result_var_sp =

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


[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan updated 
https://github.com/llvm/llvm-project/pull/85669

>From ddc9c22765623f88051ce1f2407603a9065c7cd1 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Mon, 18 Mar 2024 10:14:49 -0700
Subject: [PATCH] [lldb][nfc] Factor out repeated code in DWIM Print

The code that prints ValueObjects is duplicated across two different cases of
the dwim-print command, and a subsequent commit will add a third case. As such,
this commit factors out the common code into a lambda. A free function was
considered, but there is too much function-local context required in that.

We also reword some of the comments so that they stop counting cases, making it
easier to add other cases later.
---
 .../Commands/CommandObjectDWIMPrint.cpp   | 37 +--
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index a88da986bb384f..3ed54a0f43615d 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -129,6 +129,19 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 }
   };
 
+  // Dump `valobj` according to whether `po` was requested or not.
+  auto dump_val_object = [&](ValueObject ) {
+if (is_po) {
+  StreamString temp_result_stream;
+  valobj.Dump(temp_result_stream, dump_options);
+  llvm::StringRef output = temp_result_stream.GetString();
+  maybe_add_hint(output);
+  result.GetOutputStream() << output;
+} else {
+  valobj.Dump(result.GetOutputStream(), dump_options);
+}
+  };
+
   // First, try `expr` as the name of a frame variable.
   if (frame) {
 auto valobj_sp = frame->FindVariable(ConstString(expr));
@@ -146,15 +159,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 flags, expr);
   }
 
-  if (is_po) {
-StreamString temp_result_stream;
-valobj_sp->Dump(temp_result_stream, dump_options);
-llvm::StringRef output = temp_result_stream.GetString();
-maybe_add_hint(output);
-result.GetOutputStream() << output;
-  } else {
-valobj_sp->Dump(result.GetOutputStream(), dump_options);
-  }
+  dump_val_object(*valobj_sp);
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return;
 }
@@ -170,6 +175,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
   return;
 }
 
+
   // Third, and lastly, try `expr` as a source expression to evaluate.
   {
 auto *exe_scope = m_exe_ctx.GetBestExecutionContextScope();
@@ -196,17 +202,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 expr);
   }
 
-  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) {
-if (is_po) {
-  StreamString temp_result_stream;
-  valobj_sp->Dump(temp_result_stream, dump_options);
-  llvm::StringRef output = temp_result_stream.GetString();
-  maybe_add_hint(output);
-  result.GetOutputStream() << output;
-} else {
-  valobj_sp->Dump(result.GetOutputStream(), dump_options);
-}
-  }
+  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
+dump_val_object(*valobj_sp);
 
   if (suppress_result)
 if (auto result_var_sp =

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


[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread Dave Lee via lldb-commits


@@ -130,7 +130,20 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 }
   };
 
-  // First, try `expr` as the name of a frame variable.

kastiglione wrote:

1. I'd prefer to leave the "first", "second", "third" comments. I want to be 
explicit that there's an order of attempts.
2. You'll need to rebase, I made a change last week that introduce some 
comments and code that you may need to incorporate.

https://github.com/llvm/llvm-project/pull/85669
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)


Changes

The code that prints ValueObjects is duplicated across two different cases of 
the dwim-print command, and a subsequent commit will add a third case. As such, 
this commit factors out the common code into a lambda. A free function was 
considered, but there is too much function-local context required in that.

We also reword some of the comments so that they stop counting cases, making it 
easier to add other cases later.

---
Full diff: https://github.com/llvm/llvm-project/pull/85669.diff


1 Files Affected:

- (modified) lldb/source/Commands/CommandObjectDWIMPrint.cpp (+18-22) 


``diff
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index b183cb423111fb..300647a98b6b95 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -130,7 +130,20 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 }
   };
 
-  // First, try `expr` as the name of a frame variable.
+  // Dump `valobj` according to whether `po` was requested or not.
+  auto dump_val_object = [&](ValueObject ) {
+if (is_po) {
+  StreamString temp_result_stream;
+  valobj.Dump(temp_result_stream, dump_options);
+  llvm::StringRef output = temp_result_stream.GetString();
+  maybe_add_hint(output);
+  result.GetOutputStream() << output;
+} else {
+  valobj.Dump(result.GetOutputStream(), dump_options);
+}
+  };
+
+  // Try `expr` as the name of a frame variable.
   if (frame) {
 auto valobj_sp = frame->FindVariable(ConstString(expr));
 if (valobj_sp && valobj_sp->GetError().Success()) {
@@ -147,21 +160,13 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 flags, expr);
   }
 
-  if (is_po) {
-StreamString temp_result_stream;
-valobj_sp->Dump(temp_result_stream, dump_options);
-llvm::StringRef output = temp_result_stream.GetString();
-maybe_add_hint(output);
-result.GetOutputStream() << output;
-  } else {
-valobj_sp->Dump(result.GetOutputStream(), dump_options);
-  }
+  dump_val_object(*valobj_sp);
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return;
 }
   }
 
-  // Second, also lastly, try `expr` as a source expression to evaluate.
+  // Try `expr` as a source expression to evaluate.
   {
 auto *exe_scope = m_exe_ctx.GetBestExecutionContextScope();
 ValueObjectSP valobj_sp;
@@ -187,17 +192,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 expr);
   }
 
-  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) {
-if (is_po) {
-  StreamString temp_result_stream;
-  valobj_sp->Dump(temp_result_stream, dump_options);
-  llvm::StringRef output = temp_result_stream.GetString();
-  maybe_add_hint(output);
-  result.GetOutputStream() << output;
-} else {
-  valobj_sp->Dump(result.GetOutputStream(), dump_options);
-}
-  }
+  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
+dump_val_object(*valobj_sp);
 
   if (suppress_result)
 if (auto result_var_sp =

``




https://github.com/llvm/llvm-project/pull/85669
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][nfc] Factor out repeated code in DWIM Print (PR #85669)

2024-03-18 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan created 
https://github.com/llvm/llvm-project/pull/85669

The code that prints ValueObjects is duplicated across two different cases of 
the dwim-print command, and a subsequent commit will add a third case. As such, 
this commit factors out the common code into a lambda. A free function was 
considered, but there is too much function-local context required in that.

We also reword some of the comments so that they stop counting cases, making it 
easier to add other cases later.

>From 0480765c0c1feef6c93e6ba90f8367d30fec33bf Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Mon, 18 Mar 2024 10:14:49 -0700
Subject: [PATCH] [lldb][nfc] Factor out repeated code in DWIM Print

The code that prints ValueObjects is duplicated across two different cases of
the dwim-print command, and a subsequent commit will add a third case. As such,
this commit factors out the common code into a lambda. A free function was
considered, but there is too much function-local context required in that.

We also reword some of the comments so that they stop counting cases, making it
easier to add other cases later.
---
 .../Commands/CommandObjectDWIMPrint.cpp   | 40 +--
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index b183cb423111fb..300647a98b6b95 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -130,7 +130,20 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 }
   };
 
-  // First, try `expr` as the name of a frame variable.
+  // Dump `valobj` according to whether `po` was requested or not.
+  auto dump_val_object = [&](ValueObject ) {
+if (is_po) {
+  StreamString temp_result_stream;
+  valobj.Dump(temp_result_stream, dump_options);
+  llvm::StringRef output = temp_result_stream.GetString();
+  maybe_add_hint(output);
+  result.GetOutputStream() << output;
+} else {
+  valobj.Dump(result.GetOutputStream(), dump_options);
+}
+  };
+
+  // Try `expr` as the name of a frame variable.
   if (frame) {
 auto valobj_sp = frame->FindVariable(ConstString(expr));
 if (valobj_sp && valobj_sp->GetError().Success()) {
@@ -147,21 +160,13 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 flags, expr);
   }
 
-  if (is_po) {
-StreamString temp_result_stream;
-valobj_sp->Dump(temp_result_stream, dump_options);
-llvm::StringRef output = temp_result_stream.GetString();
-maybe_add_hint(output);
-result.GetOutputStream() << output;
-  } else {
-valobj_sp->Dump(result.GetOutputStream(), dump_options);
-  }
+  dump_val_object(*valobj_sp);
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return;
 }
   }
 
-  // Second, also lastly, try `expr` as a source expression to evaluate.
+  // Try `expr` as a source expression to evaluate.
   {
 auto *exe_scope = m_exe_ctx.GetBestExecutionContextScope();
 ValueObjectSP valobj_sp;
@@ -187,17 +192,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 expr);
   }
 
-  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult) {
-if (is_po) {
-  StreamString temp_result_stream;
-  valobj_sp->Dump(temp_result_stream, dump_options);
-  llvm::StringRef output = temp_result_stream.GetString();
-  maybe_add_hint(output);
-  result.GetOutputStream() << output;
-} else {
-  valobj_sp->Dump(result.GetOutputStream(), dump_options);
-}
-  }
+  if (valobj_sp->GetError().GetError() != UserExpression::kNoResult)
+dump_val_object(*valobj_sp);
 
   if (suppress_result)
 if (auto result_var_sp =

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