aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/python_api
diff options
context:
space:
mode:
authorJacob Lalonde <jalalonde@fb.com>2025-05-09 15:49:54 -0700
committerGitHub <noreply@github.com>2025-05-09 15:49:54 -0700
commit7517a1bb486f397d45a776e127445596e00c55eb (patch)
treeb7dbc2f13383d87d184d6c534c7a4ca764da02f0 /lldb/test/API/python_api
parent0eae457be346d1e7380f4aebbbc333c146c41885 (diff)
downloadllvm-7517a1bb486f397d45a776e127445596e00c55eb.zip
llvm-7517a1bb486f397d45a776e127445596e00c55eb.tar.gz
llvm-7517a1bb486f397d45a776e127445596e00c55eb.tar.bz2
[LLDB][SBSaveCoreOptions] Add new API to expose the expected core size in bytes (#138169)
My current internal work requires some sensitivity to IO usage. I had a work around to calculate the expected size of a Minidump, but I've added this PR so an automated system could look at the expected size of an LLDB generated Minidump and then choose if it has the space or wants to generate it. There are some prerequisites to calculating the correct size, so I have the API take a reference for an SBError, I originally tried to return an SBError and instead take a uint64_t reference, but this made the API very difficult to use in python. Added a test case as well.
Diffstat (limited to 'lldb/test/API/python_api')
-rw-r--r--lldb/test/API/python_api/sbsavecoreoptions/TestSBSaveCoreOptions.py60
-rw-r--r--lldb/test/API/python_api/sbsavecoreoptions/basic_minidump.yaml8
2 files changed, 68 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/sbsavecoreoptions/TestSBSaveCoreOptions.py b/lldb/test/API/python_api/sbsavecoreoptions/TestSBSaveCoreOptions.py
index ace84e8..31e35e0 100644
--- a/lldb/test/API/python_api/sbsavecoreoptions/TestSBSaveCoreOptions.py
+++ b/lldb/test/API/python_api/sbsavecoreoptions/TestSBSaveCoreOptions.py
@@ -104,3 +104,63 @@ class SBSaveCoreOptionsAPICase(TestBase):
thread_collection = options.GetThreadsToSave()
self.assertEqual(thread_collection.GetSize(), 3)
self.assertIn(middle_thread, thread_collection)
+
+ def test_get_current_size_in_bytes(self):
+ """
+ Tests that ensures GetCurrentSizeInBytes properly returns an error without a process,
+ and the readable regions with a process.
+ """
+
+ options = lldb.SBSaveCoreOptions()
+ options.SetStyle(lldb.eSaveCoreCustomOnly)
+ process = self.get_basic_process()
+ memory_range = lldb.SBMemoryRegionInfo()
+
+ # Add the memory range of 0x1000-0x1100
+ process.GetMemoryRegionInfo(0x1000, memory_range)
+ options.AddMemoryRegionToSave(memory_range)
+
+ # Check that we fail when we have no process set
+ # even though we added a memory region.
+ error = lldb.SBError()
+ total = options.GetCurrentSizeInBytes(error)
+ self.assertTrue(error.Fail(), error.GetCString())
+
+ # Check that we don't get an error now that we've added a process
+ options.SetProcess(process)
+ total = options.GetCurrentSizeInBytes(error)
+ self.assertTrue(error.Success(), error.GetCString())
+
+ # Validate the size returned is the same size as the single region we added.
+ expected_size = memory_range.GetRegionEnd() - memory_range.GetRegionBase()
+ self.assertEqual(total, expected_size)
+
+ def test_get_total_in_bytes_missing_requirements(self):
+ """
+ Tests the matrix of error responses that GetCurrentSizeInBytes
+ """
+
+ options = lldb.SBSaveCoreOptions()
+
+ # No process, no style returns an error.
+ error = lldb.SBError()
+ total = options.GetCurrentSizeInBytes(error)
+ self.assertTrue(error.Fail(), error.GetCString())
+
+ # No process returns an error
+ options.SetStyle(lldb.eSaveCoreCustomOnly)
+ total = options.GetCurrentSizeInBytes(error)
+ self.assertTrue(error.Fail(), error.GetCString())
+
+ options.Clear()
+
+ # No style returns an error
+ process = self.get_basic_process()
+ options.SetProcess(process)
+ total = options.GetCurrentSizeInBytes(error)
+ self.assertTrue(error.Fail(), error.GetCString())
+
+ # Options that result in no valid data returns an error.
+ options.SetStyle(lldb.eSaveCoreCustomOnly)
+ total = options.GetCurrentSizeInBytes(error)
+ self.assertTrue(error.Fail(), error.GetCString())
diff --git a/lldb/test/API/python_api/sbsavecoreoptions/basic_minidump.yaml b/lldb/test/API/python_api/sbsavecoreoptions/basic_minidump.yaml
index 96302fb..e79262b 100644
--- a/lldb/test/API/python_api/sbsavecoreoptions/basic_minidump.yaml
+++ b/lldb/test/API/python_api/sbsavecoreoptions/basic_minidump.yaml
@@ -34,3 +34,11 @@ Streams:
Stack:
Start of Memory Range: 0x00007FFFC8DFF000
Content: 'BAADBEEF'
+ - Type: Memory64List
+ Memory Ranges:
+ - Start of Memory Range: 0x1000
+ Data Size: 0x100
+ Content : ''
+ - Start of Memory Range: 0x2000
+ Data Size: 0x200
+ Content : ''