Skip to content

Commit b128131

Browse files
committed
Create new extension for save core to save a thread and N pointers deep
1 parent 5589096 commit b128131

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#extend lldb::SBSaveCoreOptions {
2+
#ifdef SWIGPYTHON
3+
%pythoncode% {
4+
'''Add a thread to the SaveCoreOptions thread list, and follow it's children N pointers deep, adding each memory region to the SaveCoreOptions Memory region list.'''
5+
def save_thread_with_heaps(self, thread, num_heaps_deep = 3):
6+
self.AddThread(thread)
7+
frame = thread.GetFrameAtIndex(0)
8+
process = thread.GetProcess()
9+
queue = []
10+
for var in frame.locals:
11+
if var.TypeIsPointerType():
12+
queue.append(var.Dereference())
13+
14+
while (num_heaps_deep > 0 and len(queue) > 0):
15+
queue_size = len(queue)
16+
for i in range(0, queue_size):
17+
var = queue.pop(0)
18+
memory_region = lldb.SBMemoryRegionInfo()
19+
process.GetMemoryRegionInfo(var.GetAddress().GetOffset(), memory_region)
20+
self.AddMemoryRegionToSave(memory_region)
21+
/*
22+
We only check for direct pointer children T*, should probably scan
23+
internal to the children themselves.
24+
*/
25+
for x in var.children:
26+
if x.TypeIsPointerType():
27+
queue.append(x.Dereference())
28+
29+
num_heaps_deep -= 1
30+
}
31+
#endif SWIGPYTHON

lldb/bindings/interfaces.swig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
%include "./interface/SBCommunicationDocstrings.i"
2727
%include "./interface/SBCompileUnitDocstrings.i"
2828
%include "./interface/SBSaveCoreOptionsDocstrings.i"
29+
#include "./interface/SBSaveCoreOptionsExtensions.i"
2930
%include "./interface/SBDataDocstrings.i"
3031
%include "./interface/SBDebuggerDocstrings.i"
3132
%include "./interface/SBDeclarationDocstrings.i"

lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import os
6+
67
import lldb
78
from lldbsuite.test.decorators import *
89
from lldbsuite.test.lldbtest import *
@@ -470,6 +471,27 @@ def save_core_with_region(self, process, region_index):
470471
if os.path.isfile(custom_file):
471472
os.unlink(custom_file)
472473

474+
def save_core_one_thread_one_heap(self, process, region_index):
475+
try:
476+
custom_file = self.getBuildArtifact("core.one_thread_one_heap.dmp")
477+
options = lldb.SBSaveCoreOptions()
478+
options.SetOutputFile(lldb.SBFileSpec(custom_file))
479+
options.SetPluginName("minidump")
480+
options.SetStyle(lldb.eSaveCoreCustomOnly)
481+
thread = process.GetThreadAtIndex(0)
482+
options.save_thread_with_heaps(thread)
483+
484+
error = process.SaveCore(options)
485+
self.assertTrue(error.Success())
486+
core_target = self.dbg.CreateTarget(None)
487+
core_proc = core_target.LoadCore(custom_file)
488+
# proc/pid maps prevent us from checking the number of regions, but
489+
# this is mostly a smoke test for the extension.
490+
self.assertEqual(core_proc.GetNumThreads(), 1)
491+
finally:
492+
if os.path.isfile(custom_file):
493+
os.unlink(custom_file)
494+
473495
@skipUnlessArch("x86_64")
474496
@skipUnlessPlatform(["linux"])
475497
def test_save_minidump_custom_save_style_duplicated_regions(self):

0 commit comments

Comments
 (0)