[Lldb-commits] [lldb] 254a312 - [lldb][NFC] Use MCInstrAnalysis when available in the disassembler plugin

2023-08-13 Thread Venkata Ramanaiah Nalamothu via lldb-commits

Author: Venkata Ramanaiah Nalamothu
Date: 2023-08-14T08:37:41+05:30
New Revision: 254a31273a27728bb7937b27417eba083781f7eb

URL: 
https://github.com/llvm/llvm-project/commit/254a31273a27728bb7937b27417eba083781f7eb
DIFF: 
https://github.com/llvm/llvm-project/commit/254a31273a27728bb7937b27417eba083781f7eb.diff

LOG: [lldb][NFC] Use MCInstrAnalysis when available in the disassembler plugin

Since the info in MCInstrDesc is based on opcodes only, it is often quite
inaccurate. The MCInstrAnalysis has been added so that targets can provide
accurate info, which is based on registers used by the instruction, through
the own versions of MCInstrDesc functions.

The RISCVMCInstrAnalysis, which needs to refine several MCInstrDesc methods,
is a good example for this.

Given the llvm-objdump also uses MCInstrAnalysis, I think this change is in
the right direction.

The default implementation of MCInstrAnalysis methods forward the query to
MCInstrDesc functions. Hence, no functional change is intended/expected.

To avoid bloating up MCInstrAnalysis, only the methods provided by it and
the ones used by disassembler plugin are changed to use MCInstrAnalysis when
available.

Though I am not sure if it will be useful, making MCInstrAnalysis available
in the disassembler plugin would allow enabling symbolize operands (D84191)
feature in lldb's disassembler as well.

Reviewed By: jasonmolenda

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

Added: 
lldb/unittests/Disassembler/RISCV/CMakeLists.txt
lldb/unittests/Disassembler/RISCV/TestMCDisasmInstanceRISCV.cpp

Modified: 
lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
lldb/unittests/Disassembler/CMakeLists.txt
lldb/unittests/Disassembler/x86/TestGetControlFlowKindx86.cpp
llvm/include/llvm/MC/MCInstrAnalysis.h

Removed: 




diff  --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp 
b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
index 09115cc670da78..b4fdcbd783570a 100644
--- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -18,6 +18,7 @@
 #include "llvm/MC/MCDisassembler/MCRelocationInfo.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCInstPrinter.h"
+#include "llvm/MC/MCInstrAnalysis.h"
 #include "llvm/MC/MCInstrInfo.h"
 #include "llvm/MC/MCRegisterInfo.h"
 #include "llvm/MC/MCSubtargetInfo.h"
@@ -75,7 +76,8 @@ class DisassemblerLLVMC::MCDisasmInstance {
std::unique_ptr &&asm_info_up,
std::unique_ptr &&context_up,
std::unique_ptr &&disasm_up,
-   std::unique_ptr &&instr_printer_up);
+   std::unique_ptr &&instr_printer_up,
+   std::unique_ptr &&instr_analysis_up);
 
   std::unique_ptr m_instr_info_up;
   std::unique_ptr m_reg_info_up;
@@ -84,6 +86,7 @@ class DisassemblerLLVMC::MCDisasmInstance {
   std::unique_ptr m_context_up;
   std::unique_ptr m_disasm_up;
   std::unique_ptr m_instr_printer_up;
+  std::unique_ptr m_instr_analysis_up;
 };
 
 namespace x86 {
@@ -1287,11 +1290,15 @@ DisassemblerLLVMC::MCDisasmInstance::Create(const char 
*triple, const char *cpu,
   if (!instr_printer_up)
 return Instance();
 
-  return Instance(
-  new MCDisasmInstance(std::move(instr_info_up), std::move(reg_info_up),
-   std::move(subtarget_info_up), 
std::move(asm_info_up),
-   std::move(context_up), std::move(disasm_up),
-   std::move(instr_printer_up)));
+  // Not all targets may have registered createMCInstrAnalysis().
+  std::unique_ptr instr_analysis_up(
+  curr_target->createMCInstrAnalysis(instr_info_up.get()));
+
+  return Instance(new MCDisasmInstance(
+  std::move(instr_info_up), std::move(reg_info_up),
+  std::move(subtarget_info_up), std::move(asm_info_up),
+  std::move(context_up), std::move(disasm_up), std::move(instr_printer_up),
+  std::move(instr_analysis_up)));
 }
 
 DisassemblerLLVMC::MCDisasmInstance::MCDisasmInstance(
@@ -1301,13 +1308,15 @@ DisassemblerLLVMC::MCDisasmInstance::MCDisasmInstance(
 std::unique_ptr &&asm_info_up,
 std::unique_ptr &&context_up,
 std::unique_ptr &&disasm_up,
-std::unique_ptr &&instr_printer_up)
+std::unique_ptr &&instr_printer_up,
+std::unique_ptr &&instr_analysis_up)
 : m_instr_info_up(std::move(instr_info_up)),
   m_reg_info_up(std::move(reg_info_up)),
   m_subtarget_info_up(std::move(subtarget_info_up)),
   m_asm_info_up(std::move(asm_info_up)),
   m_context_up(std::move(context_up)), m_disasm_up(std::move(disasm_up)),
-  m_instr_printer_up(std::move(instr_printer_up)) {
+  m_instr_printer_up(std::move(instr_printer_up)),
+  m_instr_analysis_up(std::move(instr_analysis_up)) {
   assert(m_instr_info_up && m_reg_info_up && m_subtarg

[Lldb-commits] [lldb] dfa8a15 - [lldb][NFC] Put disassembler test classes and methods in anonymous namespace

2023-08-31 Thread Venkata Ramanaiah Nalamothu via lldb-commits

Author: Venkata Ramanaiah Nalamothu
Date: 2023-09-01T11:49:54+05:30
New Revision: dfa8a15d7886f34de9d3175611a2844c921ef5b6

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

LOG: [lldb][NFC] Put disassembler test classes and methods in anonymous 
namespace

Reviewed By: DavidSpickett, MaskRay

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

Added: 


Modified: 
lldb/unittests/Disassembler/ARM/TestArm64Disassembly.cpp
lldb/unittests/Disassembler/ARM/TestArmv7Disassembly.cpp
lldb/unittests/Disassembler/RISCV/TestMCDisasmInstanceRISCV.cpp
lldb/unittests/Disassembler/x86/TestGetControlFlowKindx86.cpp

Removed: 




diff  --git a/lldb/unittests/Disassembler/ARM/TestArm64Disassembly.cpp 
b/lldb/unittests/Disassembler/ARM/TestArm64Disassembly.cpp
index 12975683397943..f89a918e3e54fa 100644
--- a/lldb/unittests/Disassembler/ARM/TestArm64Disassembly.cpp
+++ b/lldb/unittests/Disassembler/ARM/TestArm64Disassembly.cpp
@@ -20,6 +20,7 @@
 using namespace lldb;
 using namespace lldb_private;
 
+namespace {
 class TestArm64Disassembly : public testing::Test {
 public:
   static void SetUpTestCase();
@@ -42,6 +43,7 @@ void TestArm64Disassembly::SetUpTestCase() {
 void TestArm64Disassembly::TearDownTestCase() {
   DisassemblerLLVMC::Terminate();
 }
+} // namespace
 
 TEST_F(TestArm64Disassembly, TestArmv81Instruction) {
   ArchSpec arch("arm64-apple-ios");

diff  --git a/lldb/unittests/Disassembler/ARM/TestArmv7Disassembly.cpp 
b/lldb/unittests/Disassembler/ARM/TestArmv7Disassembly.cpp
index 92b6d07f48eeca..047cba1db40821 100644
--- a/lldb/unittests/Disassembler/ARM/TestArmv7Disassembly.cpp
+++ b/lldb/unittests/Disassembler/ARM/TestArmv7Disassembly.cpp
@@ -20,6 +20,7 @@
 using namespace lldb;
 using namespace lldb_private;
 
+namespace {
 class TestArmv7Disassembly : public testing::Test {
 public:
   static void SetUpTestCase();
@@ -42,6 +43,7 @@ void TestArmv7Disassembly::SetUpTestCase() {
 void TestArmv7Disassembly::TearDownTestCase() {
   DisassemblerLLVMC::Terminate();
 }
+} // namespace
 
 TEST_F(TestArmv7Disassembly, TestCortexFPDisass) {
   ArchSpec arch("armv7em--");

diff  --git a/lldb/unittests/Disassembler/RISCV/TestMCDisasmInstanceRISCV.cpp 
b/lldb/unittests/Disassembler/RISCV/TestMCDisasmInstanceRISCV.cpp
index 5534a66f6f3447..2f2585a23d7624 100644
--- a/lldb/unittests/Disassembler/RISCV/TestMCDisasmInstanceRISCV.cpp
+++ b/lldb/unittests/Disassembler/RISCV/TestMCDisasmInstanceRISCV.cpp
@@ -20,6 +20,7 @@
 using namespace lldb;
 using namespace lldb_private;
 
+namespace {
 class TestMCDisasmInstanceRISCV : public testing::Test {
 public:
   static void SetUpTestCase();
@@ -39,6 +40,7 @@ void TestMCDisasmInstanceRISCV::SetUpTestCase() {
 void TestMCDisasmInstanceRISCV::TearDownTestCase() {
   DisassemblerLLVMC::Terminate();
 }
+} // namespace
 
 TEST_F(TestMCDisasmInstanceRISCV, TestRISCV32Instruction) {
   ArchSpec arch("riscv32-*-linux");

diff  --git a/lldb/unittests/Disassembler/x86/TestGetControlFlowKindx86.cpp 
b/lldb/unittests/Disassembler/x86/TestGetControlFlowKindx86.cpp
index 54433e6c8493da..56fb4bda875430 100644
--- a/lldb/unittests/Disassembler/x86/TestGetControlFlowKindx86.cpp
+++ b/lldb/unittests/Disassembler/x86/TestGetControlFlowKindx86.cpp
@@ -20,6 +20,7 @@
 using namespace lldb;
 using namespace lldb_private;
 
+namespace {
 class TestGetControlFlowKindx86 : public testing::Test {
 public:
   static void SetUpTestCase();
@@ -39,6 +40,7 @@ void TestGetControlFlowKindx86::SetUpTestCase() {
 void TestGetControlFlowKindx86::TearDownTestCase() {
   DisassemblerLLVMC::Terminate();
 }
+} // namespace
 
 TEST_F(TestGetControlFlowKindx86, TestX86_64Instruction) {
   ArchSpec arch("x86_64-*-linux");



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


[Lldb-commits] [lldb] a57b62d - [lldb] Fix thread step until to not set breakpoint(s) on incorrect line numbers

2022-06-24 Thread Venkata Ramanaiah Nalamothu via lldb-commits

Author: Venkata Ramanaiah Nalamothu
Date: 2022-06-25T00:01:04+05:30
New Revision: a57b62deef37c7f2ec31bca3bf9173a6206bfb9b

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

LOG: [lldb] Fix thread step until to not set breakpoint(s) on incorrect line 
numbers

The requirements for "thread until " are:

a) If any code contributed by  or the nearest subsequent of  is executed before leaving the function, stop
b) If you end up leaving the function w/o triggering (a), then stop

In case of (a), since the  may have multiple entries in the line 
table and the compiler might have scheduled/moved the relevant code across, and 
the lldb does not know the control flow, set breakpoints on all the line table 
entries of best match of  i.e. exact or the nearest subsequent 
line.

Along with the above, currently, CommandObjectThreadUntil is also setting the 
breakpoints on all the subsequent line numbers after the best match and this 
latter part is wrong.

This issue is discussed at 
http://lists.llvm.org/pipermail/lldb-dev/2018-August/013979.html.

In fact, currently `TestStepUntil.py` is not actually testing step until 
scenarios and `test_missing_one` test fails without this patch if tests are 
made to run. Fixed the test as well.

Reviewed By: jingham

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

Added: 


Modified: 
lldb/source/Commands/CommandObjectThread.cpp
lldb/test/API/functionalities/thread/step_until/TestStepUntil.py

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectThread.cpp 
b/lldb/source/Commands/CommandObjectThread.cpp
index 037bbafdf8940..9396c36154979 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -1033,11 +1033,21 @@ class CommandObjectThreadUntil : public 
CommandObjectParsed {
 line_table->FindLineEntryByAddress(fun_end_addr, function_start,
&end_ptr);
 
+// Since not all source lines will contribute code, check if we are
+// setting the breakpoint on the exact line number or the nearest
+// subsequent line number and set breakpoints at all the line table
+// entries of the chosen line number (exact or nearest subsequent).
 for (uint32_t line_number : line_numbers) {
+  LineEntry line_entry;
+  bool exact = false;
   uint32_t start_idx_ptr = index_ptr;
+  start_idx_ptr = sc.comp_unit->FindLineEntry(
+  index_ptr, line_number, nullptr, exact, &line_entry);
+  if (start_idx_ptr != UINT32_MAX)
+line_number = line_entry.line;
+  exact = true;
+  start_idx_ptr = index_ptr;
   while (start_idx_ptr <= end_ptr) {
-LineEntry line_entry;
-const bool exact = false;
 start_idx_ptr = sc.comp_unit->FindLineEntry(
 start_idx_ptr, line_number, nullptr, exact, &line_entry);
 if (start_idx_ptr == UINT32_MAX)

diff  --git a/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py 
b/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py
index 0145b34f31de5..ee25d1343735f 100644
--- a/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py
+++ b/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py
@@ -19,7 +19,7 @@ def setUp(self):
 self.greater_than_two = line_number('main.c', 'Greater than or equal 
to 2.')
 self.back_out_in_main = line_number('main.c', 'Back out in main')
 
-def do_until (self, args, until_lines, expected_linenum):
+def common_setup (self, args):
 self.build()
 exe = self.getBuildArtifact("a.out")
 
@@ -48,7 +48,8 @@ def do_until (self, args, until_lines, expected_linenum):
 thread = threads[0]
 return thread
 
-thread = self.common_setup(None)
+def do_until (self, args, until_lines, expected_linenum):
+thread = self.common_setup(args)
 
 cmd_interp = self.dbg.GetCommandInterpreter()
 ret_obj = lldb.SBCommandReturnObject()
@@ -77,7 +78,7 @@ def test_targetting_two_hitting_second (self):
 self.do_until(None, [self.less_than_two, self.greater_than_two], 
self.less_than_two)
 
 def test_missing_one (self):
-"""Test thread step until - targeting one line and missing it."""
+"""Test thread step until - targeting one line and missing it by 
stepping out to call site"""
 self.do_until(["foo", "bar", "baz"], [self.less_than_two], 
self.back_out_in_main)
 
 



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


[Lldb-commits] [lldb] 419cc0a - [lldb] Fix thread step until to not set breakpoint(s) on incorrect line numbers

2022-07-11 Thread Venkata Ramanaiah Nalamothu via lldb-commits

Author: Venkata Ramanaiah Nalamothu
Date: 2022-07-11T18:45:37+05:30
New Revision: 419cc0a0b2ab7306dd721c337e7ce6ed31dc7287

URL: 
https://github.com/llvm/llvm-project/commit/419cc0a0b2ab7306dd721c337e7ce6ed31dc7287
DIFF: 
https://github.com/llvm/llvm-project/commit/419cc0a0b2ab7306dd721c337e7ce6ed31dc7287.diff

LOG: [lldb] Fix thread step until to not set breakpoint(s) on incorrect line 
numbers

The requirements for "thread until " are:

a) If any code contributed by  or the nearest subsequent of  is executed before leaving the function, stop
b) If you end up leaving the function w/o triggering (a), then stop

In case of (a), since the  may have multiple entries in the line 
table and the compiler might have scheduled/moved the relevant code across, and 
the lldb does not know the control flow, set breakpoints on all the line table 
entries of best match of  i.e. exact or the nearest subsequent 
line.

Along with the above, currently, CommandObjectThreadUntil is also setting the 
breakpoints on all the subsequent line numbers after the best match and this 
latter part is wrong.

This issue is discussed at 
http://lists.llvm.org/pipermail/lldb-dev/2018-August/013979.html.

In fact, currently `TestStepUntil.py` is not actually testing step until 
scenarios and `test_missing_one` test fails without this patch if tests are 
made to run. Fixed the test as well.

Reviewed By: jingham

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

Added: 


Modified: 
lldb/source/Commands/CommandObjectThread.cpp
lldb/test/API/functionalities/thread/step_until/TestStepUntil.py
lldb/test/API/functionalities/thread/step_until/main.c

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectThread.cpp 
b/lldb/source/Commands/CommandObjectThread.cpp
index 993523e06736..9211480fa9f8 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -1033,11 +1033,21 @@ class CommandObjectThreadUntil : public 
CommandObjectParsed {
 line_table->FindLineEntryByAddress(fun_end_addr, function_start,
&end_ptr);
 
+// Since not all source lines will contribute code, check if we are
+// setting the breakpoint on the exact line number or the nearest
+// subsequent line number and set breakpoints at all the line table
+// entries of the chosen line number (exact or nearest subsequent).
 for (uint32_t line_number : line_numbers) {
+  LineEntry line_entry;
+  bool exact = false;
   uint32_t start_idx_ptr = index_ptr;
+  start_idx_ptr = sc.comp_unit->FindLineEntry(
+  index_ptr, line_number, nullptr, exact, &line_entry);
+  if (start_idx_ptr != UINT32_MAX)
+line_number = line_entry.line;
+  exact = true;
+  start_idx_ptr = index_ptr;
   while (start_idx_ptr <= end_ptr) {
-LineEntry line_entry;
-const bool exact = false;
 start_idx_ptr = sc.comp_unit->FindLineEntry(
 start_idx_ptr, line_number, nullptr, exact, &line_entry);
 if (start_idx_ptr == UINT32_MAX)

diff  --git a/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py 
b/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py
index 0145b34f31de..ee25d1343735 100644
--- a/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py
+++ b/lldb/test/API/functionalities/thread/step_until/TestStepUntil.py
@@ -19,7 +19,7 @@ def setUp(self):
 self.greater_than_two = line_number('main.c', 'Greater than or equal 
to 2.')
 self.back_out_in_main = line_number('main.c', 'Back out in main')
 
-def do_until (self, args, until_lines, expected_linenum):
+def common_setup (self, args):
 self.build()
 exe = self.getBuildArtifact("a.out")
 
@@ -48,7 +48,8 @@ def do_until (self, args, until_lines, expected_linenum):
 thread = threads[0]
 return thread
 
-thread = self.common_setup(None)
+def do_until (self, args, until_lines, expected_linenum):
+thread = self.common_setup(args)
 
 cmd_interp = self.dbg.GetCommandInterpreter()
 ret_obj = lldb.SBCommandReturnObject()
@@ -77,7 +78,7 @@ def test_targetting_two_hitting_second (self):
 self.do_until(None, [self.less_than_two, self.greater_than_two], 
self.less_than_two)
 
 def test_missing_one (self):
-"""Test thread step until - targeting one line and missing it."""
+"""Test thread step until - targeting one line and missing it by 
stepping out to call site"""
 self.do_until(["foo", "bar", "baz"], [self.less_than_two], 
self.back_out_in_main)
 
 

diff  --git a/lldb/test/API/functionalities/thread/step_until/main.c 
b/lldb/test/API/functionalities/thread/step_until/main.c
index e0b4d8ab951e..bb866079cf5f 100644
--- a/l

[Lldb-commits] [lldb] c6ad690 - [lldb, test] Fix typos in the lldb tests

2022-06-02 Thread Venkata Ramanaiah Nalamothu via lldb-commits

Author: Venkata Ramanaiah Nalamothu
Date: 2022-06-02T12:45:57+05:30
New Revision: c6ad6901734f8fa7c1ecd3aeb7de651b07ab21a6

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

LOG: [lldb, test]  Fix typos in the lldb tests

Reviewed By: JDevlieghere

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

Added: 


Modified: 
lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py
lldb/test/API/commands/frame/language/TestGuessLanguage.py
lldb/test/API/commands/frame/var/TestFrameVar.py
lldb/test/API/commands/target/stop-hooks/TestStopHookScripted.py
lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
lldb/test/API/functionalities/history/TestHistoryRecall.py

lldb/test/API/functionalities/tail_call_frames/thread_step_out_or_return/TestSteppingOutWithArtificialFrames.py
lldb/test/API/functionalities/var_path/TestVarPath.py
lldb/test/API/lang/c/find_struct_type/TestFindStructTypes.py

lldb/test/API/lang/cpp/dynamic-value-same-basename/TestDynamicValueSameBase.py
lldb/test/API/macosx/save_crashlog/TestSaveCrashlog.py
lldb/test/API/macosx/version_zero/TestGetVersionZeroVersion.py
lldb/test/API/sample_test/TestSampleTest.py

Removed: 




diff  --git a/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py 
b/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py
index 7bba9c8d2c8d7..bd62e30b7fc19 100644
--- a/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py
+++ b/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py
@@ -13,7 +13,7 @@ class TestAllowJIT(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
-# If your test case doesn't stress debug info, the
+# If your test case doesn't stress debug info, then
 # set this to true.  That way it won't be run once for
 # each debug info format.
 NO_DEBUG_INFO_TESTCASE = True

diff  --git a/lldb/test/API/commands/frame/language/TestGuessLanguage.py 
b/lldb/test/API/commands/frame/language/TestGuessLanguage.py
index 1adab53a4ebc1..231f1d4238c6c 100644
--- a/lldb/test/API/commands/frame/language/TestGuessLanguage.py
+++ b/lldb/test/API/commands/frame/language/TestGuessLanguage.py
@@ -14,7 +14,7 @@ class TestFrameGuessLanguage(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
-# If your test case doesn't stress debug info, the
+# If your test case doesn't stress debug info, then
 # set this to true.  That way it won't be run once for
 # each debug info format.
 NO_DEBUG_INFO_TESTCASE = True

diff  --git a/lldb/test/API/commands/frame/var/TestFrameVar.py 
b/lldb/test/API/commands/frame/var/TestFrameVar.py
index c325c65ca155e..d142e356f28e1 100644
--- a/lldb/test/API/commands/frame/var/TestFrameVar.py
+++ b/lldb/test/API/commands/frame/var/TestFrameVar.py
@@ -13,7 +13,7 @@ class TestFrameVar(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
-# If your test case doesn't stress debug info, the
+# If your test case doesn't stress debug info, then
 # set this to true.  That way it won't be run once for
 # each debug info format.
 NO_DEBUG_INFO_TESTCASE = True

diff  --git a/lldb/test/API/commands/target/stop-hooks/TestStopHookScripted.py 
b/lldb/test/API/commands/target/stop-hooks/TestStopHookScripted.py
index 53c2c2e07a332..017aee982207b 100644
--- a/lldb/test/API/commands/target/stop-hooks/TestStopHookScripted.py
+++ b/lldb/test/API/commands/target/stop-hooks/TestStopHookScripted.py
@@ -13,7 +13,7 @@ class TestStopHooks(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
-# If your test case doesn't stress debug info, the
+# If your test case doesn't stress debug info, then
 # set this to true.  That way it won't be run once for
 # each debug info format.
 NO_DEBUG_INFO_TESTCASE = True

diff  --git a/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py 
b/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
index 6f5df860db57c..b9a6e5348614e 100644
--- a/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
+++ b/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
@@ -13,7 +13,7 @@ class TestStopHooks(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
-# If your test case doesn't stress debug info, the
+# If your test case doesn't stress debug info, then
 # set this to true.  That way it won't be run once for
 # each debug info format.
 NO_DEBUG_INFO_TESTCASE = True

diff  --git a/lldb/test/API/functionalities/history/TestHistoryRecall.py 
b/lldb/test/API/functionalities/history/TestHistoryRecall.py
index 4be4bdd6d9a15..b3a012dd7bbae 100644
--- a/lldb/test/API/functionalities/history/TestHistoryRecall.py
+++ b/lldb/test/API/functionalities/history/TestHistoryRecall.py
@@ -

[Lldb-commits] [lldb] ab7fcf2 - [LLDB] CommandObjectThreadUntil::DoExecute() sets the wrong selected thread ID

2022-06-14 Thread Venkata Ramanaiah Nalamothu via lldb-commits

Author: Venkata Ramanaiah Nalamothu
Date: 2022-06-15T08:52:29+05:30
New Revision: ab7fcf24849d9365785dc981613e761e388e560d

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

LOG: [LLDB] CommandObjectThreadUntil::DoExecute() sets the wrong selected 
thread ID

For the 'thread until' command, the selected thread ID, to perform the 
operation on, could be of the current thread or the specified thread.

Reviewed By: jingham

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

Added: 


Modified: 
lldb/source/Commands/CommandObjectThread.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectThread.cpp 
b/lldb/source/Commands/CommandObjectThread.cpp
index 95a8301a318a3..11affe8a7c13e 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -984,8 +984,8 @@ class CommandObjectThreadUntil : public CommandObjectParsed 
{
   thread->GetStackFrameAtIndex(m_options.m_frame_idx).get();
   if (frame == nullptr) {
 result.AppendErrorWithFormat(
-"Frame index %u is out of range for thread %u.\n",
-m_options.m_frame_idx, m_options.m_thread_idx);
+"Frame index %u is out of range for thread id %" PRIu64 ".\n",
+m_options.m_frame_idx, thread->GetID());
 return false;
   }
 
@@ -1002,9 +1002,8 @@ class CommandObjectThreadUntil : public 
CommandObjectParsed {
 
 if (line_table == nullptr) {
   result.AppendErrorWithFormat("Failed to resolve the line table for "
-   "frame %u of thread index %u.\n",
-   m_options.m_frame_idx,
-   m_options.m_thread_idx);
+   "frame %u of thread id %" PRIu64 ".\n",
+   m_options.m_frame_idx, thread->GetID());
   return false;
 }
 
@@ -1090,13 +1089,18 @@ class CommandObjectThreadUntil : public 
CommandObjectParsed {
   return false;
 }
   } else {
-result.AppendErrorWithFormat(
-"Frame index %u of thread %u has no debug information.\n",
-m_options.m_frame_idx, m_options.m_thread_idx);
+result.AppendErrorWithFormat("Frame index %u of thread id %" PRIu64
+ " has no debug information.\n",
+ m_options.m_frame_idx, thread->GetID());
 return false;
   }
 
-  process->GetThreadList().SetSelectedThreadByID(m_options.m_thread_idx);
+  if (!process->GetThreadList().SetSelectedThreadByID(thread->GetID())) {
+result.AppendErrorWithFormat(
+"Failed to set the selected thread to thread id %" PRIu64 ".\n",
+thread->GetID());
+return false;
+  }
 
   StreamString stream;
   Status error;



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


[Lldb-commits] [lldb] 94038c5 - [lldb] Fix 'memory write' to not allow specifying values when writing file contents

2021-11-26 Thread Venkata Ramanaiah Nalamothu via lldb-commits

Author: Venkata Ramanaiah Nalamothu
Date: 2021-11-26T15:50:36+05:30
New Revision: 94038c570fbc991c03fe68793c576314c231d4ee

URL: 
https://github.com/llvm/llvm-project/commit/94038c570fbc991c03fe68793c576314c231d4ee
DIFF: 
https://github.com/llvm/llvm-project/commit/94038c570fbc991c03fe68793c576314c231d4ee.diff

LOG: [lldb] Fix 'memory write' to not allow specifying values when writing file 
contents

Currently the 'memory write' command allows specifying the values when
writing the file contents to memory but the values are actually ignored. This
patch fixes that by erroring out when values are specified in such cases.

Reviewed By: DavidSpickett

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

Added: 
lldb/test/API/commands/memory/write/Makefile
lldb/test/API/commands/memory/write/TestMemoryWrite.py
lldb/test/API/commands/memory/write/file.txt
lldb/test/API/commands/memory/write/main.c

Modified: 
lldb/source/Commands/CommandObjectMemory.cpp
lldb/source/Interpreter/CommandObject.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectMemory.cpp 
b/lldb/source/Commands/CommandObjectMemory.cpp
index f27d4bd7e4b26..ff508a939f0be 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1240,6 +1240,7 @@ class CommandObjectMemoryWrite : public 
CommandObjectParsed {
 // Define the first (and only) variant of this arg.
 value_arg.arg_type = eArgTypeValue;
 value_arg.arg_repetition = eArgRepeatPlus;
+value_arg.arg_opt_set_association = LLDB_OPT_SET_1;
 
 // There is only one variant this argument could be; put it into the
 // argument entry.
@@ -1278,6 +1279,12 @@ class CommandObjectMemoryWrite : public 
CommandObjectParsed {
 m_cmd_name.c_str());
 return false;
   }
+  if (argc > 1) {
+result.AppendErrorWithFormat(
+"%s takes only a destination address when writing file 
contents.\n",
+m_cmd_name.c_str());
+return false;
+  }
 } else if (argc < 2) {
   result.AppendErrorWithFormat(
   "%s takes a destination address and at least one value.\n",

diff  --git a/lldb/source/Interpreter/CommandObject.cpp 
b/lldb/source/Interpreter/CommandObject.cpp
index 64b23d04abea3..dcae27ff54790 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -454,6 +454,9 @@ void CommandObject::GetFormattedCommandArguments(Stream 
&str,
 opt_set_mask == LLDB_OPT_SET_ALL
 ? m_arguments[i]
 : OptSetFiltered(opt_set_mask, m_arguments[i]);
+// This argument is not associated with the current option set, so skip it.
+if (arg_entry.empty())
+  continue;
 int num_alternatives = arg_entry.size();
 
 if ((num_alternatives == 2) && IsPairType(arg_entry[0].arg_repetition)) {

diff  --git a/lldb/test/API/commands/memory/write/Makefile 
b/lldb/test/API/commands/memory/write/Makefile
new file mode 100644
index 0..695335e068c0c
--- /dev/null
+++ b/lldb/test/API/commands/memory/write/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+CFLAGS_EXTRAS := -std=c99
+
+include Makefile.rules

diff  --git a/lldb/test/API/commands/memory/write/TestMemoryWrite.py 
b/lldb/test/API/commands/memory/write/TestMemoryWrite.py
new file mode 100644
index 0..852edf95079f7
--- /dev/null
+++ b/lldb/test/API/commands/memory/write/TestMemoryWrite.py
@@ -0,0 +1,83 @@
+"""
+Test the 'memory write' command.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class MemoryWriteTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Find the line number to break inside main().
+self.line = line_number('main.c', '// Set break point at this line.')
+
+def build_run_stop(self):
+self.build()
+exe = self.getBuildArtifact("a.out")
+self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+# Break in main() after the variables are assigned values.
+lldbutil.run_break_set_by_file_and_line(self,
+"main.c",
+self.line,
+num_expected_locations=1,
+loc_exact=True)
+
+self.runCmd("run", RUN_SUCCEEDED)
+
+# The stop reason of the thread should be breakpoint.
+self.expect("thread list",
+STOPPED_DUE_TO_BREAKPOINT,
+substrs=['stopped', 'stop reason = breakpoint'])
+
+# The breakpoint should have a hit count of 1.
+lldbutil.check_breakpoint(self, bpno = 1, expected_h

[Lldb-commits] [lldb] 7f05ff8 - [Bug 49018][lldb] Fix incorrect help text for 'memory write' command

2021-11-26 Thread Venkata Ramanaiah Nalamothu via lldb-commits

Author: Venkata Ramanaiah Nalamothu
Date: 2021-11-26T19:14:26+05:30
New Revision: 7f05ff8be481f6db23615c028280fd92c2080f5f

URL: 
https://github.com/llvm/llvm-project/commit/7f05ff8be481f6db23615c028280fd92c2080f5f
DIFF: 
https://github.com/llvm/llvm-project/commit/7f05ff8be481f6db23615c028280fd92c2080f5f.diff

LOG: [Bug 49018][lldb] Fix incorrect help text for 'memory write' command

Certain commands like 'memory write', 'register read' etc all use
the OptionGroupFormat options but the help usage text for those
options is not customized to those commands.

One such example is:

  (lldb) help memory read
   -s  ( --size  )
   The size in bytes to use when displaying with the selected 
format.
  (lldb) help memory write
   -s  ( --size  )
   The size in bytes to use when displaying with the selected 
format.

This patch allows such commands to overwrite the help text for the options
in the OptionGroupFormat group as needed and fixes help text of memory write.

llvm.org/pr49018.

Reviewed By: DavidSpickett

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

Added: 


Modified: 
lldb/include/lldb/Interpreter/OptionGroupFormat.h
lldb/source/Commands/CommandObjectMemory.cpp
lldb/source/Interpreter/OptionGroupFormat.cpp
lldb/test/API/commands/help/TestHelp.py

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/OptionGroupFormat.h 
b/lldb/include/lldb/Interpreter/OptionGroupFormat.h
index 2d445b8a6c20a..551688b0d25f1 100644
--- a/lldb/include/lldb/Interpreter/OptionGroupFormat.h
+++ b/lldb/include/lldb/Interpreter/OptionGroupFormat.h
@@ -16,6 +16,9 @@
 
 namespace lldb_private {
 
+typedef std::vector>
+OptionGroupFormatUsageTextVector;
+
 // OptionGroupFormat
 
 class OptionGroupFormat : public OptionGroup {
@@ -30,7 +33,10 @@ class OptionGroupFormat : public OptionGroup {
   uint64_t default_byte_size =
   UINT64_MAX, // Pass UINT64_MAX to disable the "--size" option
   uint64_t default_count =
-  UINT64_MAX); // Pass UINT64_MAX to disable the "--count" option
+  UINT64_MAX, // Pass UINT64_MAX to disable the "--count" option
+  OptionGroupFormatUsageTextVector usage_text_vector = {}
+  // Use to override default option usage text with the command specific 
one
+  );
 
   ~OptionGroupFormat() override = default;
 
@@ -73,6 +79,7 @@ class OptionGroupFormat : public OptionGroup {
   char m_prev_gdb_format;
   char m_prev_gdb_size;
   bool m_has_gdb_format;
+  OptionDefinition m_option_definitions[4];
 };
 
 } // namespace lldb_private

diff  --git a/lldb/source/Commands/CommandObjectMemory.cpp 
b/lldb/source/Commands/CommandObjectMemory.cpp
index ff508a939f0be..094ce6f8558fe 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1222,7 +1222,15 @@ class CommandObjectMemoryWrite : public 
CommandObjectParsed {
 interpreter, "memory write",
 "Write to the memory of the current target process.", nullptr,
 eCommandRequiresProcess | eCommandProcessMustBeLaunched),
-m_option_group(), m_format_options(eFormatBytes, 1, UINT64_MAX),
+m_option_group(),
+m_format_options(
+eFormatBytes, 1, UINT64_MAX,
+{std::make_tuple(
+ eArgTypeFormat,
+ "The format to use for each of the value to be written."),
+ std::make_tuple(
+ eArgTypeByteSize,
+ "The size in bytes to write from input file or each 
value.")}),
 m_memory_options() {
 CommandArgumentEntry arg1;
 CommandArgumentEntry arg2;

diff  --git a/lldb/source/Interpreter/OptionGroupFormat.cpp 
b/lldb/source/Interpreter/OptionGroupFormat.cpp
index 1cc5e70282c1a..a2ca9ff398189 100644
--- a/lldb/source/Interpreter/OptionGroupFormat.cpp
+++ b/lldb/source/Interpreter/OptionGroupFormat.cpp
@@ -16,15 +16,7 @@
 using namespace lldb;
 using namespace lldb_private;
 
-OptionGroupFormat::OptionGroupFormat(lldb::Format default_format,
- uint64_t default_byte_size,
- uint64_t default_count)
-: m_format(default_format, default_format),
-  m_byte_size(default_byte_size, default_byte_size),
-  m_count(default_count, default_count), m_prev_gdb_format('x'),
-  m_prev_gdb_size('w') {}
-
-static constexpr OptionDefinition g_option_table[] = {
+static constexpr OptionDefinition g_default_option_definitions[] = {
 {LLDB_OPT_SET_1, false, "format", 'f', OptionParser::eRequiredArgument,
  nullptr, {}, 0, eArgTypeFormat,
  "Specify a format to be used for display."},
@@ -39,8 +31,34 @@ static constexpr OptionDefinition g_option_table[] = {
  "The number of total items to display."},
 };
 
+OptionGroupFormat::OptionGroupFormat(
+lldb::Format default_format, uint64_t defau