llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: David Spickett (DavidSpickett) <details> <summary>Changes</summary> "memory region" can be given an address once and then when repeated, it will try to find a region just beyond the last one it printed. This continues until the end of the address space. Then it gives you an error showing the usage, which is odd because you just saw a bunch of "memory region" with no options work. So I've improved the error a bit to imply its to do with the repetition. Then described the repeating behaviour in the help text. --- Full diff: https://github.com/llvm/llvm-project/pull/177559.diff 4 Files Affected: - (modified) lldb/source/Commands/CommandObjectMemory.cpp (+33-18) - (modified) lldb/test/API/functionalities/memory-region/TestMemoryRegion.py (+1-1) - (modified) lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py (+6-1) - (added) lldb/test/Shell/Commands/command-memory-region.test (+10) ``````````diff diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 5786e757ef7ea..ef9452b63d11e 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -1651,12 +1651,18 @@ class CommandObjectMemoryRegion : public CommandObjectParsed { }; CommandObjectMemoryRegion(CommandInterpreter &interpreter) - : CommandObjectParsed(interpreter, "memory region", - "Get information on the memory region containing " - "an address in the current target process.", - "memory region <address-expression> (or --all)", - eCommandRequiresProcess | eCommandTryTargetAPILock | - eCommandProcessMustBeLaunched) { + : CommandObjectParsed( + interpreter, "memory region", + "Get information on the memory region containing " + "an address in the current target process.\n" + "If this command is given an <address-expression> once " + "and then repeated without options, it will try to print " + "the memory region that follows the previously printed " + "region. The command can be repeated until the end of " + "the address range is reached.", + "memory region <address-expression> (or --all)", + eCommandRequiresProcess | eCommandTryTargetAPILock | + eCommandProcessMustBeLaunched) { // Address in option set 1. m_arguments.push_back(CommandArgumentEntry{CommandArgumentData( eArgTypeAddressOrExpression, eArgRepeatPlain, LLDB_OPT_SET_1)}); @@ -1735,7 +1741,25 @@ class CommandObjectMemoryRegion : public CommandObjectParsed { const size_t argc = command.GetArgumentCount(); const lldb::ABISP &abi = process_sp->GetABI(); - if (argc == 1) { + if (argc == 0) { + if (!m_memory_region_options.m_all) { + if ( // When we're repeating the command, the previous end + // address is used for load_addr. If that was 0xF...F then + // we must have reached the end of memory. + (load_addr == LLDB_INVALID_ADDRESS) || + // If the target has non-address bits (tags, limited virtual + // address size, etc.), the end of mappable memory will be + // lower than that. So if we find any non-address bit set, + // we must be at the end of the mappable range. + (abi && (abi->FixAnyAddress(load_addr) != load_addr))) { + result.AppendErrorWithFormat( + "No next region address set, one address expression argument or " + "\"--all\" option required:\nUsage: %s\n", + m_cmd_syntax.c_str()); + return; + } + } + } else if (argc == 1) { if (m_memory_region_options.m_all) { result.AppendError( "The \"--all\" option cannot be used when an address " @@ -1751,17 +1775,8 @@ class CommandObjectMemoryRegion : public CommandObjectParsed { command[0].c_str(), error.AsCString()); return; } - } else if (argc > 1 || - // When we're repeating the command, the previous end address is - // used for load_addr. If that was 0xF...F then we must have - // reached the end of memory. - (argc == 0 && !m_memory_region_options.m_all && - load_addr == LLDB_INVALID_ADDRESS) || - // If the target has non-address bits (tags, limited virtual - // address size, etc.), the end of mappable memory will be lower - // than that. So if we find any non-address bit set, we must be - // at the end of the mappable range. - (abi && (abi->FixAnyAddress(load_addr) != load_addr))) { + } else { + // argc > 1 result.AppendErrorWithFormat( "'%s' takes one argument or \"--all\" option:\nUsage: %s\n", m_cmd_name.c_str(), m_cmd_syntax.c_str()); diff --git a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py index 50182e72e498c..6b0e82c26b49d 100644 --- a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py +++ b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py @@ -54,7 +54,7 @@ def test_command(self): self.assertFalse(result.Succeeded()) self.assertEqual( result.GetError(), - "error: 'memory region' takes one argument or \"--all\" option:\n" + 'error: No next region address set, one address expression argument or "--all" option required:\n' "Usage: memory region <address-expression> (or --all)\n", ) diff --git a/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py b/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py index 1792ff9953efe..2e6fc40588d3e 100644 --- a/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py +++ b/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py @@ -86,7 +86,12 @@ def test_command_completions(self): { "text": "region", "label": "region", - "detail": "Get information on the memory region containing an address in the current target process.", + "detail": "Get information on the memory region containing an address " + "in the current target process.\nIf this command is given an " + "<address-expression> once and then repeated without options, " + "it will try to print the memory region that follows the " + "previously printed region. The command can be repeated " + "until the end of the address range is reached.", }, ], ) diff --git a/lldb/test/Shell/Commands/command-memory-region.test b/lldb/test/Shell/Commands/command-memory-region.test new file mode 100644 index 0000000000000..35fb7b08cb666 --- /dev/null +++ b/lldb/test/Shell/Commands/command-memory-region.test @@ -0,0 +1,10 @@ +## --all should be able to be used many times in a row. As it is not +## repeatable and starts fresh each time. + +# RUN: %clang_host -g -O0 %S/Inputs/main.c -o %t.out +# RUN: %lldb %t.out -b -o 'b main' -o 'run' -o 'memory region --all' \ +# RUN: -o 'memory region --all' | FileCheck %s +# CHECK-LABEL: memory region --all +# CHECK-NEXT: [0x{{[0-9a-f]+}}-0x{{[0-9a-f]+}}) +# CHECK-LABEL: memory region --all +# CHECK-NEXT: [0x{{[0-9a-f]+}}-0x{{[0-9a-f]+}}) `````````` </details> https://github.com/llvm/llvm-project/pull/177559 _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
