Add the ability to process save-core stack-memory-only corefiles
Add a field to the qMemoryRegionInfo packet where the remote stub can describe the type of memory -- heap, stack. Keep track of memory regions that are stack memory in lldb. Add a new "--style stack" to process save-core to request that only stack memory be included in the corefile. Differential Revision: https://reviews.llvm.org/D107625
This commit is contained in:
@@ -6342,13 +6342,17 @@ struct segment_vmaddr {
|
||||
// are some multiple passes over the image list while calculating
|
||||
// everything.
|
||||
|
||||
static offset_t
|
||||
CreateAllImageInfosPayload(const lldb::ProcessSP &process_sp,
|
||||
offset_t initial_file_offset,
|
||||
StreamString &all_image_infos_payload) {
|
||||
static offset_t CreateAllImageInfosPayload(
|
||||
const lldb::ProcessSP &process_sp, offset_t initial_file_offset,
|
||||
StreamString &all_image_infos_payload, SaveCoreStyle core_style) {
|
||||
Target &target = process_sp->GetTarget();
|
||||
const ModuleList &modules = target.GetImages();
|
||||
size_t modules_count = modules.GetSize();
|
||||
ModuleList modules = target.GetImages();
|
||||
|
||||
// stack-only corefiles have no reason to include binaries that
|
||||
// are not executing; we're trying to make the smallest corefile
|
||||
// we can, so leave the rest out.
|
||||
if (core_style == SaveCoreStyle::eSaveCoreStackOnly)
|
||||
modules.Clear();
|
||||
|
||||
std::set<std::string> executing_uuids;
|
||||
ThreadList &thread_list(process_sp->GetThreadList());
|
||||
@@ -6363,10 +6367,12 @@ CreateAllImageInfosPayload(const lldb::ProcessSP &process_sp,
|
||||
UUID uuid = module_sp->GetUUID();
|
||||
if (uuid.IsValid()) {
|
||||
executing_uuids.insert(uuid.GetAsString());
|
||||
modules.AppendIfNeeded(module_sp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
size_t modules_count = modules.GetSize();
|
||||
|
||||
struct all_image_infos_header infos;
|
||||
infos.version = 1;
|
||||
@@ -6508,12 +6514,9 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
|
||||
if (!process_sp)
|
||||
return false;
|
||||
|
||||
// For Mach-O, we can only create full corefiles or dirty-page-only
|
||||
// corefiles. The default is dirty-page-only.
|
||||
if (core_style != SaveCoreStyle::eSaveCoreFull) {
|
||||
// Default on macOS is to create a dirty-memory-only corefile.
|
||||
if (core_style == SaveCoreStyle::eSaveCoreUnspecified) {
|
||||
core_style = SaveCoreStyle::eSaveCoreDirtyOnly;
|
||||
} else {
|
||||
core_style = SaveCoreStyle::eSaveCoreFull;
|
||||
}
|
||||
|
||||
Target &target = process_sp->GetTarget();
|
||||
@@ -6568,13 +6571,23 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
|
||||
if (size == 0)
|
||||
break;
|
||||
|
||||
if (prot != 0) {
|
||||
bool include_this_region = true;
|
||||
bool dirty_pages_only = false;
|
||||
if (core_style == SaveCoreStyle::eSaveCoreStackOnly) {
|
||||
dirty_pages_only = true;
|
||||
if (range_info.IsStackMemory() != MemoryRegionInfo::eYes) {
|
||||
include_this_region = false;
|
||||
}
|
||||
}
|
||||
if (core_style == SaveCoreStyle::eSaveCoreDirtyOnly) {
|
||||
dirty_pages_only = true;
|
||||
}
|
||||
|
||||
if (prot != 0 && include_this_region) {
|
||||
addr_t pagesize = range_info.GetPageSize();
|
||||
const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
|
||||
range_info.GetDirtyPageList();
|
||||
if (core_style == SaveCoreStyle::eSaveCoreDirtyOnly &&
|
||||
dirty_page_list.hasValue()) {
|
||||
core_style = SaveCoreStyle::eSaveCoreDirtyOnly;
|
||||
if (dirty_pages_only && dirty_page_list.hasValue()) {
|
||||
for (addr_t dirtypage : dirty_page_list.getValue()) {
|
||||
page_object obj;
|
||||
obj.addr = dirtypage;
|
||||
@@ -6617,6 +6630,12 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
|
||||
last_obj = obj;
|
||||
}
|
||||
|
||||
// If we only ended up with one contiguous memory segment
|
||||
if (combined_page_objects.size() == 0 &&
|
||||
last_obj.addr != LLDB_INVALID_ADDRESS) {
|
||||
combined_page_objects.push_back(last_obj);
|
||||
}
|
||||
|
||||
for (page_object obj : combined_page_objects) {
|
||||
uint32_t cmd_type = LC_SEGMENT_64;
|
||||
uint32_t segment_size = sizeof(llvm::MachO::segment_command_64);
|
||||
@@ -6767,7 +6786,8 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
|
||||
all_image_infos_lcnote_up->name = "all image infos";
|
||||
all_image_infos_lcnote_up->payload_file_offset = file_offset;
|
||||
file_offset = CreateAllImageInfosPayload(
|
||||
process_sp, file_offset, all_image_infos_lcnote_up->payload);
|
||||
process_sp, file_offset, all_image_infos_lcnote_up->payload,
|
||||
core_style);
|
||||
lc_notes.push_back(std::move(all_image_infos_lcnote_up));
|
||||
|
||||
// Add LC_NOTE load commands
|
||||
|
||||
Reference in New Issue
Block a user