https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/177176
>From 04eb9b855e41962e33887f11b85e20bd24e160cb Mon Sep 17 00:00:00 2001 From: David Spickett <[email protected]> Date: Wed, 21 Jan 2026 14:09:57 +0000 Subject: [PATCH 1/2] [lldb] Fix error when running "memory region --all" repeatedly Due to some faulty logic, if you ran "memory region --all" twice, the second time lldb would try to repeat the command. There's nothing to repeat, so it failed with an error. I've fixed the logic so that we treat each --all use as its own command starting from scratch. For reasons unknown, I could not reproduce this issue using the API test TestMemoryRegion.py. So I have added a shell test that I confirmed does fail without this fix. --- lldb/source/Commands/CommandObjectMemory.cpp | 21 ++++++++++--------- .../Shell/Commands/command-memory-region.test | 10 +++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 lldb/test/Shell/Commands/command-memory-region.test diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 5786e757ef7ea..cbfd7180f99f6 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -1752,16 +1752,17 @@ class CommandObjectMemoryRegion : public CommandObjectParsed { 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))) { + (!m_memory_region_options.m_all && + ( + // 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 && 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( "'%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/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]+}}) >From 43677c2d516fc1397f5b0ac4fbf834614622cbf1 Mon Sep 17 00:00:00 2001 From: David Spickett <[email protected]> Date: Thu, 22 Jan 2026 11:44:08 +0000 Subject: [PATCH 2/2] cleanup validation logic --- lldb/source/Commands/CommandObjectMemory.cpp | 33 ++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index cbfd7180f99f6..eabe2fb4c4483 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -1735,7 +1735,24 @@ 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( + "'%s' takes one argument or \"--all\" option:\nUsage: %s\n", + m_cmd_name.c_str(), 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,18 +1768,8 @@ class CommandObjectMemoryRegion : public CommandObjectParsed { command[0].c_str(), error.AsCString()); return; } - } else if (argc > 1 || - (!m_memory_region_options.m_all && - ( - // 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 && 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()); _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
