Skip to content

Commit 267e4c6

Browse files
committed
Change test location, and go back to region based instead of object based
1 parent 17c7b2d commit 267e4c6

File tree

7 files changed

+77
-56
lines changed

7 files changed

+77
-56
lines changed

lldb/bindings/interface/SBSaveCoreOptionsExtensions.i

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%pythoncode%{
55
'''Add a thread to the SaveCoreOptions thread list, and follow its children N pointers deep, adding each memory region to the SaveCoreOptions Memory region list.'''
66
def save_thread_with_heaps(self, thread, num_pointers_deep = 3):
7+
import lldb
78
self.AddThread(thread)
89
frame = thread.GetFrameAtIndex(0)
910
process = thread.GetProcess()
@@ -19,9 +20,14 @@
1920
var = queue.pop(0)
2021
var_type = var.GetType()
2122
addr = var.GetAddress().GetOffset()
22-
memory_region = lldb.SBMemoryRegionInfo(None, addr, addr + var_type.GetByteSize(), False)
23+
if addr == 0 or addr == None:
24+
continue
25+
memory_region = lldb.SBMemoryRegionInfo()
26+
err = process.GetMemoryRegionInfo(addr, memory_region)
27+
if err.Fail():
28+
continue
2329
self.AddMemoryRegionToSave(memory_region)
24-
# We only check for direct pointer children T*, should probably scan
30+
# We only check for direct pointer children T*, should probably xscan
2531
# internal to the children themselves.
2632
for x in var.children:
2733
if x.TypeIsPointerType():

lldb/test/API/functionalities/process_save_core_minidump/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ CXX_SOURCES := main.cpp
33
CFLAGS_EXTRAS := -lpthread
44

55
include Makefile.rules
6-

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -471,55 +471,6 @@ def save_core_with_region(self, process, region_index):
471471
if os.path.isfile(custom_file):
472472
os.unlink(custom_file)
473473

474-
@skipUnlessArch("x86_64")
475-
@skipUnlessPlatform(["linux"])
476-
def test_save_core_one_thread_one_heap(self):
477-
self.build()
478-
exe = self.getBuildArtifact("a.out")
479-
custom_file = self.getBuildArtifact("core.custom.dmp")
480-
try:
481-
target = self.dbg.CreateTarget(exe)
482-
process = target.LaunchSimple(
483-
None, None, self.get_process_working_directory()
484-
)
485-
self.assertState(process.GetState(), lldb.eStateStopped)
486-
custom_file = self.getBuildArtifact("core.one_thread_one_heap.dmp")
487-
options = lldb.SBSaveCoreOptions()
488-
options.SetOutputFile(lldb.SBFileSpec(custom_file))
489-
options.SetPluginName("minidump")
490-
options.SetStyle(lldb.eSaveCoreCustomOnly)
491-
thread = process.GetThreadAtIndex(0)
492-
options.save_thread_with_heaps(thread, 1)
493-
494-
error = process.SaveCore(options)
495-
self.assertTrue(error.Success())
496-
core_target = self.dbg.CreateTarget(None)
497-
core_proc = core_target.LoadCore(custom_file)
498-
# proc/pid maps prevent us from checking the number of regions, but
499-
# this is mostly a smoke test for the extension.
500-
self.assertEqual(core_proc.GetNumThreads(), 1)
501-
addr = (
502-
process.GetThreadAtIndex(0)
503-
.GetFrameAtIndex(0)
504-
.FindVariable("str")
505-
.Dereference()
506-
.GetAddress()
507-
.GetOffset()
508-
)
509-
core_addr = (
510-
core_proc.GetThreadAtIndex(0)
511-
.GetFrameAtIndex(0)
512-
.FindVariable("str")
513-
.Dereference()
514-
.GetAddress()
515-
.GetOffset()
516-
)
517-
self.assertEqual(addr, core_addr)
518-
519-
finally:
520-
if os.path.isfile(custom_file):
521-
os.unlink(custom_file)
522-
523474
@skipUnlessArch("x86_64")
524475
@skipUnlessPlatform(["linux"])
525476
def test_save_minidump_custom_save_style_duplicated_regions(self):

lldb/test/API/functionalities/process_save_core_minidump/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ size_t h() {
1818

1919
int main() {
2020
std::thread t1(f);
21-
char *str = new char[10];
21+
2222
size_t x = h();
2323

2424
t1.join();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules

lldb/test/API/python_api/sbsavecoreoptions/TestSBSaveCoreOptions.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
from lldbsuite.test.decorators import *
55
from lldbsuite.test.lldbtest import *
66

7+
78
class SBSaveCoreOptionsAPICase(TestBase):
89
basic_minidump = "basic_minidump.yaml"
910
basic_minidump_different_pid = "basic_minidump_different_pid.yaml"
1011

1112
def get_process_from_yaml(self, yaml_file):
1213
minidump_path = self.getBuildArtifact(os.path.basename(yaml_file) + ".dmp")
13-
print ("minidump_path: " + minidump_path)
14+
print("minidump_path: " + minidump_path)
1415
self.yaml2obj(yaml_file, minidump_path)
15-
self.assertTrue(os.path.exists(minidump_path), "yaml2obj did not emit a minidump file")
16+
self.assertTrue(
17+
os.path.exists(minidump_path), "yaml2obj did not emit a minidump file"
18+
)
1619
target = self.dbg.CreateTarget(None)
1720
process = target.LoadCore(minidump_path)
1821
self.assertTrue(process.IsValid(), "Process is not valid")
@@ -59,7 +62,6 @@ def test_adding_and_removing_thread(self):
5962
removed_success = options.RemoveThread(thread)
6063
self.assertFalse(removed_success)
6164

62-
6365
def test_adding_thread_different_process(self):
6466
"""Test adding and removing a thread from save core options."""
6567
options = lldb.SBSaveCoreOptions()
@@ -79,3 +81,43 @@ def test_adding_thread_different_process(self):
7981
self.assertTrue(error.Fail())
8082
error = options.AddThread(thread)
8183
self.assertTrue(error.Success())
84+
85+
def verify_linked_list(self, node, depth, max_depth):
86+
if depth > max_depth:
87+
return
88+
89+
x_val = node.GetChildMemberWithName("x").GetValueAsUnsigned(0)
90+
self.assertEqual(x_val, depth)
91+
next_node = node.GetChildMemberWithName("next").Dereference()
92+
self.verify_linked_list(next_node, depth + 1, max_depth)
93+
94+
@skipIfWindows
95+
def test_thread_and_heaps_extension(self):
96+
"""Test the thread and heap extension for save core options."""
97+
options = lldb.SBSaveCoreOptions()
98+
self.build()
99+
(target, process, t, bp) = lldbutil.run_to_source_breakpoint(
100+
self, "break here", lldb.SBFileSpec("a.out")
101+
)
102+
main_thread = None
103+
for thread_idx in range(process.GetNumThreads()):
104+
thread = process.GetThreadAtIndex(thread_idx)
105+
frame = thread.GetFrameAtIndex(0)
106+
if "main" in frame.name:
107+
main_thread = thread
108+
break
109+
self.assertTrue(main_thread != None)
110+
options.save_thread_with_heaps(main_thread, 3)
111+
core_file = self.getBuildArtifact("core.one_thread_and_heap.dmp")
112+
spec = lldb.SBFileSpec(core_file)
113+
options.SetOutputFile(spec)
114+
options.SetPluginName("minidump")
115+
options.SetStyle(lldb.eSaveCoreCustomOnly)
116+
error = process.SaveCore(options)
117+
self.assertTrue(error.Success())
118+
core_proc = target.LoadCore(core_file)
119+
self.assertTrue(core_proc.IsValid())
120+
self.assertEqual(core_proc.GetNumThreads(), 1)
121+
frame = core_proc.GetThreadAtIndex(0).GetFrameAtIndex(0)
122+
head = frame.FindVariable("head")
123+
self.verify_linked_list(head.Dereference(), 0, 3)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <cstddef>
2+
3+
struct Node {
4+
Node *next;
5+
int x;
6+
};
7+
8+
int main() {
9+
Node *head = new Node();
10+
Node *current = head;
11+
head->x = 0;
12+
for (size_t i = 0; i < 10; i++) {
13+
Node *next = new Node();
14+
next->x = current->x + 1;
15+
current->next = next;
16+
current = next;
17+
}
18+
19+
return 0; // break here
20+
}

0 commit comments

Comments
 (0)