Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lldb] Remove limit on max memory read size #105765

Merged

Conversation

jasonmolenda
Copy link
Collaborator

memory read will return an error if you try to read more than 1k bytes in a single command, instructing you to set
target.max-memory-read-size or use --force if you intended to read more than that. This is a safeguard for a command where people are being explicit about how much memory they would like lldb to read (either to display, or save to a file) and is an annoyance every time you need to read more than a small amount. If someone confuses the --count argument with the start address, lldb may begin dumping gigabytes of data but I'd rather that behavior than requiring everyone to special-case their way around a common use case.

I don't want to remove the setting because many people have added (much larger) default max read sizes to their ~/.lldbinit files after hitting this behavior. Another option would be to stop reading/using the value in Target.cpp, but I see no harm in leaving the setting if someone really does prefer to have a small cap on their memory read size.

`memory read` will return an error if you try to read more than 1k
bytes in a single command, instructing you to set
`target.max-memory-read-size` or use `--force` if you intended to
read more than that.  This is a safeguard for a command where people
are being explicit about how much memory they would like lldb to
read (either to display, or save to a file) and is an annoyance
every time you need to read more than a small amount.  If someone
confuses the --count argument with the start address, lldb may begin
dumping gigabytes of data but I'd rather that behavior than requiring
everyone to special-case their way around a common use case.
@llvmbot
Copy link
Member

llvmbot commented Aug 23, 2024

@llvm/pr-subscribers-lldb

Author: Jason Molenda (jasonmolenda)

Changes

memory read will return an error if you try to read more than 1k bytes in a single command, instructing you to set
target.max-memory-read-size or use --force if you intended to read more than that. This is a safeguard for a command where people are being explicit about how much memory they would like lldb to read (either to display, or save to a file) and is an annoyance every time you need to read more than a small amount. If someone confuses the --count argument with the start address, lldb may begin dumping gigabytes of data but I'd rather that behavior than requiring everyone to special-case their way around a common use case.

I don't want to remove the setting because many people have added (much larger) default max read sizes to their ~/.lldbinit files after hitting this behavior. Another option would be to stop reading/using the value in Target.cpp, but I see no harm in leaving the setting if someone really does prefer to have a small cap on their memory read size.


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

1 Files Affected:

  • (modified) lldb/source/Target/TargetProperties.td (+1-1)
diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td
index 7bb5bd53688b14..f553d92f7c64f6 100644
--- a/lldb/source/Target/TargetProperties.td
+++ b/lldb/source/Target/TargetProperties.td
@@ -102,7 +102,7 @@ let Definition = "target" in {
     DefaultUnsignedValue<1024>,
     Desc<"Maximum number of characters to show when using %s in summary strings.">;
   def MaxMemReadSize: Property<"max-memory-read-size", "UInt64">,
-    DefaultUnsignedValue<1024>,
+    DefaultUnsignedValue<4294967295>,
     Desc<"Maximum number of bytes that 'memory read' will fetch before --force must be specified.">;
   def BreakpointUseAvoidList: Property<"breakpoints-use-platform-avoid-list", "Boolean">,
     DefaultTrue,

@jasonmolenda
Copy link
Collaborator Author

(the setting is a UInt64, but Target.cpp reads it and returns a uint32_t, so I only did UINT32_MAX value)

@jasonmolenda
Copy link
Collaborator Author

lol my hubris is on display, the PR testing hit a test failure in ... TestMemoryReadMaximumSize.py which I wrote & merged earlier today, and assumes there is a limit of 1024. ;)

@@ -102,7 +102,7 @@ let Definition = "target" in {
DefaultUnsignedValue<1024>,
Desc<"Maximum number of characters to show when using %s in summary strings.">;
def MaxMemReadSize: Property<"max-memory-read-size", "UInt64">,
DefaultUnsignedValue<1024>,
DefaultUnsignedValue<4294967295>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Either make it hex, or instead of providing a default value here, initialize the CommandOption to UINT32_MAX

@jasonmolenda
Copy link
Collaborator Author

Updated patch to a hex constant in the .td file as per Ismail's suggestion, fixed the new TestMemoryReadMaximumSize.py test to work with the new default.

Copy link
Member

@medismailben medismailben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jasonmolenda
Copy link
Collaborator Author

both of the linux PR tests failed in Unwind/trap_frame_sym_ctx.test, I could have sworn the only test failure I had before was in TestMemoryReadMaximumSize.py, I don't see how this PR breaks that test case. Hmm.

@medismailben
Copy link
Member

both of the linux PR tests failed in Unwind/trap_frame_sym_ctx.test, I could have sworn the only test failure I had before was in TestMemoryReadMaximumSize.py, I don't see how this PR breaks that test case. Hmm.

I believe that failure is unrelated to your PR since another user have the exact same issue in theirs: #105757. The issue seems to be resolved by #105695.

@jasonmolenda
Copy link
Collaborator Author

both of the linux PR tests failed in Unwind/trap_frame_sym_ctx.test, I could have sworn the only test failure I had before was in TestMemoryReadMaximumSize.py, I don't see how this PR breaks that test case. Hmm.

I believe that failure is unrelated to your PR since another user have the exact same issue in theirs: #105757. The issue seems to be resolved by #105695.

thanks! I want to leave this PR open until next week in case @clayborg has an opinion (this is def his orig code), but I won't look into that fail any further.

@jasonmolenda
Copy link
Collaborator Author

@clayborg what do you think about removing the memory limit from memory read? I know this is code you originally wrote, and I might not be thinking of a way for someone to do a huge memory read unintentionally. But it seems like this cap just gets in people's way more than anything else.

(I have complaints about our other safety limits like the 1024 byte c-string formatter cap which is really easy to hit with long strings, but those are more debatable ;)

@jasonmolenda jasonmolenda merged commit b076f66 into llvm:main Sep 3, 2024
7 checks passed
@jasonmolenda jasonmolenda deleted the remove-memory-read-default-1024 branch September 3, 2024 23:45
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 3, 2024

LLVM Buildbot has detected a new failure on builder lldb-aarch64-ubuntu running on linaro-lldb-aarch64-ubuntu while building lldb at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/4279

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
UNSUPPORTED: lldb-api :: benchmarks/libcxxmap/TestBenchmarkLibcxxMap.py (15 of 2020)
UNSUPPORTED: lldb-api :: benchmarks/startup/TestStartupDelays.py (16 of 2020)
UNSUPPORTED: lldb-api :: benchmarks/stepping/TestSteppingSpeed.py (17 of 2020)
UNSUPPORTED: lldb-api :: benchmarks/turnaround/TestCompileRunToBreakpointTurnaround.py (18 of 2020)
UNSUPPORTED: lldb-api :: commands/add-dsym/uuid/TestAddDsymCommand.py (19 of 2020)
PASS: lldb-api :: commands/apropos/basic/TestApropos.py (20 of 2020)
PASS: lldb-api :: commands/breakpoint/command/list/TestBreakpointCommandList.py (21 of 2020)
PASS: lldb-api :: clear-sbvalue-nonaddressable-bits/TestClearSBValueNonAddressableBits.py (22 of 2020)
PASS: lldb-api :: commands/breakpoint/set/func-regex/TestBreakpointRegexError.py (23 of 2020)
UNRESOLVED: lldb-api :: api/multiple-debuggers/TestMultipleDebuggers.py (24 of 2020)
******************** TEST 'lldb-api :: api/multiple-debuggers/TestMultipleDebuggers.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env ARCHIVER=/usr/local/bin/llvm-ar --env OBJCOPY=/usr/bin/llvm-objcopy --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --arch aarch64 --build-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/api/multiple-debuggers -p TestMultipleDebuggers.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision b076f6640e3c2781410588f4a8e4ccfeed8eb606)
  clang revision b076f6640e3c2781410588f4a8e4ccfeed8eb606
  llvm revision b076f6640e3c2781410588f4a8e4ccfeed8eb606
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
free(): double free detected in tcache 2
FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test_multiple_debuggers (TestMultipleDebuggers.TestMultipleSimultaneousDebuggers)
======================================================================
ERROR: test_multiple_debuggers (TestMultipleDebuggers.TestMultipleSimultaneousDebuggers)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py", line 148, in wrapper
    return func(*args, **kwargs)
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py", line 148, in wrapper
    return func(*args, **kwargs)
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py", line 35, in test_multiple_debuggers
    subprocess.check_call([self.driver_exe, self.inferior_exe])
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/api/multiple-debuggers/TestMultipleDebuggers.test_multiple_debuggers/multi-process-driver', '/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/api/multiple-debuggers/TestMultipleDebuggers.test_multiple_debuggers/testprog']' died with <Signals.SIGABRT: 6>.
Config=aarch64-/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang
----------------------------------------------------------------------
Ran 1 test in 1.649s

FAILED (errors=1)

--

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants