[Lldb-commits] [lldb] r138282 - in /lldb/trunk/source/Plugins: DynamicLoader/Darwin-Kernel/ DynamicLoader/MacOSX-Kernel/ OperatingSystem/Darwin-Kernel/ OperatingSystem/MacOSX-Kernel/
Greg Clayton
gclayton at apple.com
Mon Aug 22 15:23:48 PDT 2011
Author: gclayton
Date: Mon Aug 22 17:23:48 2011
New Revision: 138282
URL: http://llvm.org/viewvc/llvm-project?rev=138282&view=rev
Log:
Renaming "MacOSX-Kernel" to "Darwin-Kernel". The file contents and project
commit will come shortly after this commit.
Added:
lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/
- copied from r138280, lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/
lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
- copied unchanged from r138280, lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp
lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h
- copied unchanged from r138280, lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.h
lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/
- copied from r138280, lldb/trunk/source/Plugins/OperatingSystem/MacOSX-Kernel/
lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemDarwinKernel.cpp
- copied unchanged from r138280, lldb/trunk/source/Plugins/OperatingSystem/MacOSX-Kernel/OperatingSystemMacOSXKernel.cpp
lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemDarwinKernel.h
- copied unchanged from r138280, lldb/trunk/source/Plugins/OperatingSystem/MacOSX-Kernel/OperatingSystemMacOSXKernel.h
Removed:
lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderMacOSXKernel.cpp
lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderMacOSXKernel.h
lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/
lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemMacOSXKernel.cpp
lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemMacOSXKernel.h
lldb/trunk/source/Plugins/OperatingSystem/MacOSX-Kernel/
Modified:
lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/Makefile
Removed: lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderMacOSXKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.cpp?rev=138280&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderMacOSXKernel.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderMacOSXKernel.cpp (removed)
@@ -1,1096 +0,0 @@
-//===-- DynamicLoaderMacOSXKernel.cpp -----------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Breakpoint/StoppointCallbackContext.h"
-#include "lldb/Core/DataBuffer.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/Debugger.h"
-#include "lldb/Core/Log.h"
-#include "lldb/Core/Module.h"
-#include "lldb/Core/PluginManager.h"
-#include "lldb/Core/State.h"
-#include "lldb/Symbol/ObjectFile.h"
-#include "lldb/Target/ObjCLanguageRuntime.h"
-#include "lldb/Target/RegisterContext.h"
-#include "lldb/Target/Target.h"
-#include "lldb/Target/Thread.h"
-#include "lldb/Target/ThreadPlanRunToAddress.h"
-#include "lldb/Target/StackFrame.h"
-
-#include "DynamicLoaderMacOSXKernel.h"
-
-//#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
-#ifdef ENABLE_DEBUG_PRINTF
-#include <stdio.h>
-#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
-#else
-#define DEBUG_PRINTF(fmt, ...)
-#endif
-
-using namespace lldb;
-using namespace lldb_private;
-
-/// FIXME - The ObjC Runtime trampoline handler doesn't really belong here.
-/// I am putting it here so I can invoke it in the Trampoline code here, but
-/// it should be moved to the ObjC Runtime support when it is set up.
-
-
-//----------------------------------------------------------------------
-// Create an instance of this class. This function is filled into
-// the plugin info class that gets handed out by the plugin factory and
-// allows the lldb to instantiate an instance of this class.
-//----------------------------------------------------------------------
-DynamicLoader *
-DynamicLoaderMacOSXKernel::CreateInstance (Process* process, bool force)
-{
- bool create = force;
- if (!create)
- {
- Module* exe_module = process->GetTarget().GetExecutableModulePointer();
- if (exe_module)
- {
- ObjectFile *object_file = exe_module->GetObjectFile();
- if (object_file)
- {
- SectionList *section_list = object_file->GetSectionList();
- if (section_list)
- {
- static ConstString g_kld_section_name ("__KLD");
- if (section_list->FindSectionByName (g_kld_section_name))
- {
- create = true;
- }
- }
- }
- }
-
- if (create)
- {
- const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
- create = triple_ref.getOS() == llvm::Triple::Darwin && triple_ref.getVendor() == llvm::Triple::Apple;
- }
- }
-
- if (create)
- return new DynamicLoaderMacOSXKernel (process);
- return NULL;
-}
-
-//----------------------------------------------------------------------
-// Constructor
-//----------------------------------------------------------------------
-DynamicLoaderMacOSXKernel::DynamicLoaderMacOSXKernel (Process* process) :
- DynamicLoader(process),
- m_kernel(),
- m_kext_summary_header_ptr_addr (),
- m_kext_summary_header_addr (),
- m_kext_summary_header (),
- m_break_id (LLDB_INVALID_BREAK_ID),
- m_kext_summaries(),
- m_mutex(Mutex::eMutexTypeRecursive)
-{
-}
-
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-DynamicLoaderMacOSXKernel::~DynamicLoaderMacOSXKernel()
-{
- Clear(true);
-}
-
-void
-DynamicLoaderMacOSXKernel::UpdateIfNeeded()
-{
- LoadKernelModuleIfNeeded();
- SetNotificationBreakpointIfNeeded ();
-}
-//------------------------------------------------------------------
-/// Called after attaching a process.
-///
-/// Allow DynamicLoader plug-ins to execute some code after
-/// attaching to a process.
-//------------------------------------------------------------------
-void
-DynamicLoaderMacOSXKernel::DidAttach ()
-{
- PrivateInitialize(m_process);
- UpdateIfNeeded();
-}
-
-//------------------------------------------------------------------
-/// Called after attaching a process.
-///
-/// Allow DynamicLoader plug-ins to execute some code after
-/// attaching to a process.
-//------------------------------------------------------------------
-void
-DynamicLoaderMacOSXKernel::DidLaunch ()
-{
- PrivateInitialize(m_process);
- UpdateIfNeeded();
-}
-
-
-//----------------------------------------------------------------------
-// Clear out the state of this class.
-//----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXKernel::Clear (bool clear_process)
-{
- Mutex::Locker locker(m_mutex);
-
- if (m_process->IsAlive() && LLDB_BREAK_ID_IS_VALID(m_break_id))
- m_process->ClearBreakpointSiteByID(m_break_id);
-
- if (clear_process)
- m_process = NULL;
- m_kernel.Clear(false);
- m_kext_summary_header_ptr_addr.Clear();
- m_kext_summary_header_addr.Clear();
- m_kext_summaries.clear();
- m_break_id = LLDB_INVALID_BREAK_ID;
-}
-
-
-//----------------------------------------------------------------------
-// Load the kernel module and initialize the "m_kernel" member. Return
-// true _only_ if the kernel is loaded the first time through (subsequent
-// calls to this function should return false after the kernel has been
-// already loaded).
-//----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXKernel::LoadKernelModuleIfNeeded()
-{
- if (!m_kext_summary_header_ptr_addr.IsValid())
- {
- m_kernel.Clear(false);
- m_kernel.module_sp = m_process->GetTarget().GetExecutableModule();
- if (m_kernel.module_sp)
- {
- static ConstString mach_header_name ("_mh_execute_header");
- static ConstString kext_summary_symbol ("gLoadedKextSummaries");
- const Symbol *symbol = NULL;
- symbol = m_kernel.module_sp->FindFirstSymbolWithNameAndType (kext_summary_symbol, eSymbolTypeData);
- if (symbol)
- m_kext_summary_header_ptr_addr = symbol->GetValue();
-
- symbol = m_kernel.module_sp->FindFirstSymbolWithNameAndType (mach_header_name, eSymbolTypeAbsolute);
- if (symbol)
- {
- // The "_mh_execute_header" symbol is absolute and not a section based
- // symbol that will have a valid address, so we need to resolve it...
- m_process->GetTarget().GetImages().ResolveFileAddress (symbol->GetValue().GetFileAddress(), m_kernel.so_address);
- DataExtractor data; // Load command data
- if (ReadMachHeader (m_kernel, &data))
- {
- if (m_kernel.header.filetype == llvm::MachO::HeaderFileTypeExecutable)
- {
- if (ParseLoadCommands (data, m_kernel))
- UpdateImageLoadAddress (m_kernel);
-
- // Update all image infos
- ReadAllKextSummaries ();
- }
- }
- else
- {
- m_kernel.Clear(false);
- }
- }
- }
- }
-}
-
-bool
-DynamicLoaderMacOSXKernel::FindTargetModule (OSKextLoadedKextSummary &image_info, bool can_create, bool *did_create_ptr)
-{
- if (did_create_ptr)
- *did_create_ptr = false;
-
- const bool image_info_uuid_is_valid = image_info.uuid.IsValid();
-
- if (image_info.module_sp)
- {
- if (image_info_uuid_is_valid)
- {
- if (image_info.module_sp->GetUUID() == image_info.uuid)
- return true;
- else
- image_info.module_sp.reset();
- }
- else
- return true;
- }
-
- ModuleList &target_images = m_process->GetTarget().GetImages();
- if (image_info_uuid_is_valid)
- image_info.module_sp = target_images.FindModule(image_info.uuid);
-
- if (image_info.module_sp)
- return true;
-
- ArchSpec arch (image_info.GetArchitecture ());
- if (can_create)
- {
- if (image_info_uuid_is_valid)
- {
- image_info.module_sp = m_process->GetTarget().GetSharedModule (FileSpec(),
- arch,
- &image_info.uuid);
- if (did_create_ptr)
- *did_create_ptr = image_info.module_sp;
- }
- }
- return image_info.module_sp;
-}
-
-bool
-DynamicLoaderMacOSXKernel::UpdateCommPageLoadAddress(Module *module)
-{
- bool changed = false;
- if (module)
- {
- ObjectFile *image_object_file = module->GetObjectFile();
- if (image_object_file)
- {
- SectionList *section_list = image_object_file->GetSectionList ();
- if (section_list)
- {
- uint32_t num_sections = section_list->GetSize();
- for (uint32_t i=0; i<num_sections; ++i)
- {
- Section* section = section_list->GetSectionAtIndex (i).get();
- if (section)
- {
- const addr_t new_section_load_addr = section->GetFileAddress ();
- const addr_t old_section_load_addr = m_process->GetTarget().GetSectionLoadList().GetSectionLoadAddress (section);
- if (old_section_load_addr == LLDB_INVALID_ADDRESS ||
- old_section_load_addr != new_section_load_addr)
- {
- if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section, section->GetFileAddress ()))
- changed = true;
- }
- }
- }
- }
- }
- }
- return changed;
-}
-
-//----------------------------------------------------------------------
-// Update the load addresses for all segments in MODULE using the
-// updated INFO that is passed in.
-//----------------------------------------------------------------------
-bool
-DynamicLoaderMacOSXKernel::UpdateImageLoadAddress (OSKextLoadedKextSummary& info)
-{
- Module *module = info.module_sp.get();
- bool changed = false;
- if (module)
- {
- ObjectFile *image_object_file = module->GetObjectFile();
- if (image_object_file)
- {
- SectionList *section_list = image_object_file->GetSectionList ();
- if (section_list)
- {
- // We now know the slide amount, so go through all sections
- // and update the load addresses with the correct values.
- uint32_t num_segments = info.segments.size();
- for (uint32_t i=0; i<num_segments; ++i)
- {
- const addr_t new_section_load_addr = info.segments[i].vmaddr;
- if (section_list->FindSectionByName(info.segments[i].name))
- {
- SectionSP section_sp(section_list->FindSectionByName(info.segments[i].name));
- if (section_sp)
- {
- const addr_t old_section_load_addr = m_process->GetTarget().GetSectionLoadList().GetSectionLoadAddress (section_sp.get());
- if (old_section_load_addr == LLDB_INVALID_ADDRESS ||
- old_section_load_addr != new_section_load_addr)
- {
- if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), new_section_load_addr))
- changed = true;
- }
- }
- else
- {
- fprintf (stderr,
- "warning: unable to find and load segment named '%s' at 0x%llx in '%s/%s' in macosx dynamic loader plug-in.\n",
- info.segments[i].name.AsCString("<invalid>"),
- (uint64_t)new_section_load_addr,
- image_object_file->GetFileSpec().GetDirectory().AsCString(),
- image_object_file->GetFileSpec().GetFilename().AsCString());
- }
- }
- else
- {
- // The segment name is empty which means this is a .o file.
- // Object files in LLDB end up getting reorganized so that
- // the segment name that is in the section is promoted into
- // an actual segment, so we just need to go through all sections
- // and slide them by a single amount.
-
- uint32_t num_sections = section_list->GetSize();
- for (uint32_t i=0; i<num_sections; ++i)
- {
- Section* section = section_list->GetSectionAtIndex (i).get();
- if (section)
- {
- if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section, section->GetFileAddress() + new_section_load_addr))
- changed = true;
- }
- }
- }
- }
- }
- }
- }
- return changed;
-}
-
-//----------------------------------------------------------------------
-// Update the load addresses for all segments in MODULE using the
-// updated INFO that is passed in.
-//----------------------------------------------------------------------
-bool
-DynamicLoaderMacOSXKernel::UnloadImageLoadAddress (OSKextLoadedKextSummary& info)
-{
- Module *module = info.module_sp.get();
- bool changed = false;
- if (module)
- {
- ObjectFile *image_object_file = module->GetObjectFile();
- if (image_object_file)
- {
- SectionList *section_list = image_object_file->GetSectionList ();
- if (section_list)
- {
- uint32_t num_segments = info.segments.size();
- for (uint32_t i=0; i<num_segments; ++i)
- {
- SectionSP section_sp(section_list->FindSectionByName(info.segments[i].name));
- if (section_sp)
- {
- const addr_t old_section_load_addr = info.segments[i].vmaddr;
- if (m_process->GetTarget().GetSectionLoadList().SetSectionUnloaded (section_sp.get(), old_section_load_addr))
- changed = true;
- }
- else
- {
- fprintf (stderr,
- "warning: unable to find and unload segment named '%s' in '%s/%s' in macosx dynamic loader plug-in.\n",
- info.segments[i].name.AsCString("<invalid>"),
- image_object_file->GetFileSpec().GetDirectory().AsCString(),
- image_object_file->GetFileSpec().GetFilename().AsCString());
- }
- }
- }
- }
- }
- return changed;
-}
-
-
-//----------------------------------------------------------------------
-// Static callback function that gets called when our DYLD notification
-// breakpoint gets hit. We update all of our image infos and then
-// let our super class DynamicLoader class decide if we should stop
-// or not (based on global preference).
-//----------------------------------------------------------------------
-bool
-DynamicLoaderMacOSXKernel::BreakpointHitCallback (void *baton,
- StoppointCallbackContext *context,
- user_id_t break_id,
- user_id_t break_loc_id)
-{
- return static_cast<DynamicLoaderMacOSXKernel*>(baton)->BreakpointHit (context, break_id, break_loc_id);
-}
-
-bool
-DynamicLoaderMacOSXKernel::BreakpointHit (StoppointCallbackContext *context,
- user_id_t break_id,
- user_id_t break_loc_id)
-{
- LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- if (log)
- log->Printf ("DynamicLoaderMacOSXKernel::BreakpointHit (...)\n");
-
- ReadAllKextSummaries ();
-
- if (log)
- PutToLog(log.get());
-
- return GetStopWhenImagesChange();
-}
-
-
-bool
-DynamicLoaderMacOSXKernel::ReadKextSummaryHeader ()
-{
- Mutex::Locker locker(m_mutex);
-
- // the all image infos is already valid for this process stop ID
-
- m_kext_summaries.clear();
- if (m_kext_summary_header_ptr_addr.IsValid())
- {
- const uint32_t addr_size = m_kernel.GetAddressByteSize ();
- const ByteOrder byte_order = m_kernel.GetByteOrder();
- Error error;
- // Read enough bytes for a "OSKextLoadedKextSummaryHeader" structure
- // which is currenty 4 uint32_t and a pointer.
- uint8_t buf[24];
- DataExtractor data (buf, sizeof(buf), byte_order, addr_size);
- const size_t count = 4 * sizeof(uint32_t) + addr_size;
- const bool prefer_file_cache = false;
- if (m_process->GetTarget().ReadPointerFromMemory (m_kext_summary_header_ptr_addr,
- prefer_file_cache,
- error,
- m_kext_summary_header_addr))
- {
- // We got a valid address for our kext summary header and make sure it isn't NULL
- if (m_kext_summary_header_addr.IsValid() &&
- m_kext_summary_header_addr.GetFileAddress() != 0)
- {
- const size_t bytes_read = m_process->GetTarget().ReadMemory (m_kext_summary_header_addr, prefer_file_cache, buf, count, error);
- if (bytes_read == count)
- {
- uint32_t offset = 0;
- m_kext_summary_header.version = data.GetU32(&offset);
- if (m_kext_summary_header.version >= 2)
- {
- m_kext_summary_header.entry_size = data.GetU32(&offset);
- }
- else
- {
- // Versions less than 2 didn't have an entry size, it was hard coded
- m_kext_summary_header.entry_size = KERNEL_MODULE_ENTRY_SIZE_VERSION_1;
- }
- m_kext_summary_header.entry_count = data.GetU32(&offset);
- return true;
- }
- }
- }
- }
- m_kext_summary_header_addr.Clear();
- return false;
-}
-
-
-bool
-DynamicLoaderMacOSXKernel::ParseKextSummaries (const Address &kext_summary_addr,
- uint32_t count)
-{
- OSKextLoadedKextSummary::collection kext_summaries;
- LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
- if (log)
- log->Printf ("Adding %d modules.\n");
-
- Mutex::Locker locker(m_mutex);
-
- if (!ReadKextSummaries (kext_summary_addr, count, kext_summaries))
- return false;
-
- Stream *s = &m_process->GetTarget().GetDebugger().GetOutputStream();
- for (uint32_t i = 0; i < count; i++)
- {
- if (s)
- {
- const uint8_t *u = (const uint8_t *)kext_summaries[i].uuid.GetBytes();
- if (u)
- {
- s->Printf("Loading kext: %2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X 0x%16.16llx \"%s\"...\n",
- u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6], u[ 7],
- u[ 8], u[ 9], u[10], u[11], u[12], u[13], u[14], u[15],
- kext_summaries[i].address, kext_summaries[i].name);
- }
- else
- {
- s->Printf("0x%16.16llx \"%s\"...\n", kext_summaries[i].address, kext_summaries[i].name);
- }
- }
-
- DataExtractor data; // Load command data
- if (ReadMachHeader (kext_summaries[i], &data))
- {
- ParseLoadCommands (data, kext_summaries[i]);
- }
-
- if (s)
- {
- if (kext_summaries[i].module_sp)
- s->Printf(" found kext: %s/%s\n",
- kext_summaries[i].module_sp->GetFileSpec().GetDirectory().AsCString(),
- kext_summaries[i].module_sp->GetFileSpec().GetFilename().AsCString());
- }
-
- if (log)
- kext_summaries[i].PutToLog (log.get());
- }
- bool return_value = AddModulesUsingImageInfos (kext_summaries);
- return return_value;
-}
-
-// Adds the modules in image_infos to m_kext_summaries.
-// NB don't call this passing in m_kext_summaries.
-
-bool
-DynamicLoaderMacOSXKernel::AddModulesUsingImageInfos (OSKextLoadedKextSummary::collection &image_infos)
-{
- // Now add these images to the main list.
- ModuleList loaded_module_list;
-
- for (uint32_t idx = 0; idx < image_infos.size(); ++idx)
- {
- m_kext_summaries.push_back(image_infos[idx]);
-
- if (FindTargetModule (image_infos[idx], true, NULL))
- {
- // UpdateImageLoadAddress will return true if any segments
- // change load address. We need to check this so we don't
- // mention that all loaded shared libraries are newly loaded
- // each time we hit out dyld breakpoint since dyld will list all
- // shared libraries each time.
- if (UpdateImageLoadAddress (image_infos[idx]))
- {
- loaded_module_list.AppendIfNeeded (image_infos[idx].module_sp);
- }
- }
- }
-
- if (loaded_module_list.GetSize() > 0)
- {
- // FIXME: This should really be in the Runtime handlers class, which should get
- // called by the target's ModulesDidLoad, but we're doing it all locally for now
- // to save time.
- // Also, I'm assuming there can be only one libobjc dylib loaded...
-
- ObjCLanguageRuntime *objc_runtime = m_process->GetObjCLanguageRuntime();
- if (objc_runtime != NULL && !objc_runtime->HasReadObjCLibrary())
- {
- size_t num_modules = loaded_module_list.GetSize();
- for (int i = 0; i < num_modules; i++)
- {
- if (objc_runtime->IsModuleObjCLibrary (loaded_module_list.GetModuleAtIndex (i)))
- {
- objc_runtime->ReadObjCLibrary (loaded_module_list.GetModuleAtIndex (i));
- break;
- }
- }
- }
-// if (log)
-// loaded_module_list.LogUUIDAndPaths (log, "DynamicLoaderMacOSXKernel::ModulesDidLoad");
- m_process->GetTarget().ModulesDidLoad (loaded_module_list);
- }
- return true;
-}
-
-
-uint32_t
-DynamicLoaderMacOSXKernel::ReadKextSummaries (const Address &kext_summary_addr,
- uint32_t image_infos_count,
- OSKextLoadedKextSummary::collection &image_infos)
-{
- const ByteOrder endian = m_kernel.GetByteOrder();
- const uint32_t addr_size = m_kernel.GetAddressByteSize();
-
- image_infos.resize(image_infos_count);
- const size_t count = image_infos.size() * m_kext_summary_header.entry_size;
- DataBufferHeap data(count, 0);
- Error error;
-
- Stream *s = &m_process->GetTarget().GetDebugger().GetOutputStream();
-
- if (s)
- s->Printf ("Reading %u kext summaries...\n", image_infos_count);
- const bool prefer_file_cache = false;
- const size_t bytes_read = m_process->GetTarget().ReadMemory (kext_summary_addr,
- prefer_file_cache,
- data.GetBytes(),
- data.GetByteSize(),
- error);
- if (bytes_read == count)
- {
-
- DataExtractor extractor (data.GetBytes(), data.GetByteSize(), endian, addr_size);
- uint32_t i=0;
- for (uint32_t kext_summary_offset = 0;
- i < image_infos.size() && extractor.ValidOffsetForDataOfSize(kext_summary_offset, m_kext_summary_header.entry_size);
- ++i, kext_summary_offset += m_kext_summary_header.entry_size)
- {
- uint32_t offset = kext_summary_offset;
- const void *name_data = extractor.GetData(&offset, KERNEL_MODULE_MAX_NAME);
- if (name_data == NULL)
- break;
- memcpy (image_infos[i].name, name_data, KERNEL_MODULE_MAX_NAME);
- image_infos[i].uuid.SetBytes(extractor.GetData (&offset, 16));
- image_infos[i].address = extractor.GetU64(&offset);
- if (!image_infos[i].so_address.SetLoadAddress (image_infos[i].address, &m_process->GetTarget()))
- m_process->GetTarget().GetImages().ResolveFileAddress (image_infos[i].address, image_infos[i].so_address);
- image_infos[i].size = extractor.GetU64(&offset);
- image_infos[i].version = extractor.GetU64(&offset);
- image_infos[i].load_tag = extractor.GetU32(&offset);
- image_infos[i].flags = extractor.GetU32(&offset);
- if ((offset - kext_summary_offset) < m_kext_summary_header.entry_size)
- {
- image_infos[i].reference_list = extractor.GetU64(&offset);
- }
- else
- {
- image_infos[i].reference_list = 0;
- }
- }
- if (i < image_infos.size())
- image_infos.resize(i);
- }
- else
- {
- image_infos.clear();
- }
- return image_infos.size();
-}
-
-bool
-DynamicLoaderMacOSXKernel::ReadAllKextSummaries ()
-{
- LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
-
- Mutex::Locker locker(m_mutex);
-
- if (ReadKextSummaryHeader ())
- {
- if (m_kext_summary_header.entry_count > 0 && m_kext_summary_header_addr.IsValid())
- {
- Address summary_addr (m_kext_summary_header_addr);
- summary_addr.Slide(m_kext_summary_header.GetSize());
- if (!ParseKextSummaries (summary_addr, m_kext_summary_header.entry_count))
- {
- m_kext_summaries.clear();
- }
- return true;
- }
- }
- return false;
-}
-
-//----------------------------------------------------------------------
-// Read a mach_header at ADDR into HEADER, and also fill in the load
-// command data into LOAD_COMMAND_DATA if it is non-NULL.
-//
-// Returns true if we succeed, false if we fail for any reason.
-//----------------------------------------------------------------------
-bool
-DynamicLoaderMacOSXKernel::ReadMachHeader (OSKextLoadedKextSummary& kext_summary, DataExtractor *load_command_data)
-{
- DataBufferHeap header_bytes(sizeof(llvm::MachO::mach_header), 0);
- Error error;
- const bool prefer_file_cache = false;
- size_t bytes_read = m_process->GetTarget().ReadMemory (kext_summary.so_address,
- prefer_file_cache,
- header_bytes.GetBytes(),
- header_bytes.GetByteSize(),
- error);
- if (bytes_read == sizeof(llvm::MachO::mach_header))
- {
- uint32_t offset = 0;
- ::memset (&kext_summary.header, 0, sizeof(kext_summary.header));
-
- // Get the magic byte unswapped so we can figure out what we are dealing with
- DataExtractor data(header_bytes.GetBytes(), header_bytes.GetByteSize(), endian::InlHostByteOrder(), 4);
- kext_summary.header.magic = data.GetU32(&offset);
- Address load_cmd_addr = kext_summary.so_address;
- data.SetByteOrder(DynamicLoaderMacOSXKernel::GetByteOrderFromMagic(kext_summary.header.magic));
- switch (kext_summary.header.magic)
- {
- case llvm::MachO::HeaderMagic32:
- case llvm::MachO::HeaderMagic32Swapped:
- data.SetAddressByteSize(4);
- load_cmd_addr.Slide (sizeof(llvm::MachO::mach_header));
- break;
-
- case llvm::MachO::HeaderMagic64:
- case llvm::MachO::HeaderMagic64Swapped:
- data.SetAddressByteSize(8);
- load_cmd_addr.Slide (sizeof(llvm::MachO::mach_header_64));
- break;
-
- default:
- return false;
- }
-
- // Read the rest of dyld's mach header
- if (data.GetU32(&offset, &kext_summary.header.cputype, (sizeof(llvm::MachO::mach_header)/sizeof(uint32_t)) - 1))
- {
- if (load_command_data == NULL)
- return true; // We were able to read the mach_header and weren't asked to read the load command bytes
-
- DataBufferSP load_cmd_data_sp(new DataBufferHeap(kext_summary.header.sizeofcmds, 0));
-
- size_t load_cmd_bytes_read = m_process->GetTarget().ReadMemory (load_cmd_addr,
- prefer_file_cache,
- load_cmd_data_sp->GetBytes(),
- load_cmd_data_sp->GetByteSize(),
- error);
-
- if (load_cmd_bytes_read == kext_summary.header.sizeofcmds)
- {
- // Set the load command data and also set the correct endian
- // swap settings and the correct address size
- load_command_data->SetData(load_cmd_data_sp, 0, kext_summary.header.sizeofcmds);
- load_command_data->SetByteOrder(data.GetByteOrder());
- load_command_data->SetAddressByteSize(data.GetAddressByteSize());
- return true; // We successfully read the mach_header and the load command data
- }
-
- return false; // We weren't able to read the load command data
- }
- }
- return false; // We failed the read the mach_header
-}
-
-
-//----------------------------------------------------------------------
-// Parse the load commands for an image
-//----------------------------------------------------------------------
-uint32_t
-DynamicLoaderMacOSXKernel::ParseLoadCommands (const DataExtractor& data, OSKextLoadedKextSummary& image_info)
-{
- uint32_t offset = 0;
- uint32_t cmd_idx;
- Segment segment;
- image_info.Clear (true);
-
- for (cmd_idx = 0; cmd_idx < image_info.header.ncmds; cmd_idx++)
- {
- // Clear out any load command specific data from image_info since
- // we are about to read it.
-
- if (data.ValidOffsetForDataOfSize (offset, sizeof(llvm::MachO::load_command)))
- {
- llvm::MachO::load_command load_cmd;
- uint32_t load_cmd_offset = offset;
- load_cmd.cmd = data.GetU32 (&offset);
- load_cmd.cmdsize = data.GetU32 (&offset);
- switch (load_cmd.cmd)
- {
- case llvm::MachO::LoadCommandSegment32:
- {
- segment.name.SetTrimmedCStringWithLength ((const char *)data.GetData(&offset, 16), 16);
- // We are putting 4 uint32_t values 4 uint64_t values so
- // we have to use multiple 32 bit gets below.
- segment.vmaddr = data.GetU32 (&offset);
- segment.vmsize = data.GetU32 (&offset);
- segment.fileoff = data.GetU32 (&offset);
- segment.filesize = data.GetU32 (&offset);
- // Extract maxprot, initprot, nsects and flags all at once
- data.GetU32(&offset, &segment.maxprot, 4);
- image_info.segments.push_back (segment);
- }
- break;
-
- case llvm::MachO::LoadCommandSegment64:
- {
- segment.name.SetTrimmedCStringWithLength ((const char *)data.GetData(&offset, 16), 16);
- // Extract vmaddr, vmsize, fileoff, and filesize all at once
- data.GetU64(&offset, &segment.vmaddr, 4);
- // Extract maxprot, initprot, nsects and flags all at once
- data.GetU32(&offset, &segment.maxprot, 4);
- image_info.segments.push_back (segment);
- }
- break;
-
- case llvm::MachO::LoadCommandUUID:
- image_info.uuid.SetBytes(data.GetData (&offset, 16));
- break;
-
- default:
- break;
- }
- // Set offset to be the beginning of the next load command.
- offset = load_cmd_offset + load_cmd.cmdsize;
- }
- }
-#if 0
- // No slide in the kernel...
-
- // All sections listed in the dyld image info structure will all
- // either be fixed up already, or they will all be off by a single
- // slide amount that is determined by finding the first segment
- // that is at file offset zero which also has bytes (a file size
- // that is greater than zero) in the object file.
-
- // Determine the slide amount (if any)
- const size_t num_sections = image_info.segments.size();
- for (size_t i = 0; i < num_sections; ++i)
- {
- // Iterate through the object file sections to find the
- // first section that starts of file offset zero and that
- // has bytes in the file...
- if (image_info.segments[i].fileoff == 0 && image_info.segments[i].filesize > 0)
- {
- image_info.slide = image_info.address - image_info.segments[i].vmaddr;
- // We have found the slide amount, so we can exit
- // this for loop.
- break;
- }
- }
-#endif
- if (image_info.uuid.IsValid())
- {
- bool did_create = false;
- if (FindTargetModule(image_info, true, &did_create))
- {
- if (did_create)
- image_info.module_create_stop_id = m_process->GetStopID();
- }
- }
- return cmd_idx;
-}
-
-//----------------------------------------------------------------------
-// Dump a Segment to the file handle provided.
-//----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXKernel::Segment::PutToLog (Log *log, addr_t slide) const
-{
- if (log)
- {
- if (slide == 0)
- log->Printf ("\t\t%16s [0x%16.16llx - 0x%16.16llx)",
- name.AsCString(""),
- vmaddr + slide,
- vmaddr + slide + vmsize);
- else
- log->Printf ("\t\t%16s [0x%16.16llx - 0x%16.16llx) slide = 0x%llx",
- name.AsCString(""),
- vmaddr + slide,
- vmaddr + slide + vmsize,
- slide);
- }
-}
-
-const DynamicLoaderMacOSXKernel::Segment *
-DynamicLoaderMacOSXKernel::OSKextLoadedKextSummary::FindSegment (const ConstString &name) const
-{
- const size_t num_segments = segments.size();
- for (size_t i=0; i<num_segments; ++i)
- {
- if (segments[i].name == name)
- return &segments[i];
- }
- return NULL;
-}
-
-
-//----------------------------------------------------------------------
-// Dump an image info structure to the file handle provided.
-//----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXKernel::OSKextLoadedKextSummary::PutToLog (Log *log) const
-{
- if (log == NULL)
- return;
- const uint8_t *u = (uint8_t *)uuid.GetBytes();
-
- if (address == LLDB_INVALID_ADDRESS)
- {
- if (u)
- {
- log->Printf("\tuuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X name=\"%s\" (UNLOADED)",
- u[ 0], u[ 1], u[ 2], u[ 3],
- u[ 4], u[ 5], u[ 6], u[ 7],
- u[ 8], u[ 9], u[10], u[11],
- u[12], u[13], u[14], u[15],
- name);
- }
- else
- log->Printf("\tname=\"%s\" (UNLOADED)", name);
- }
- else
- {
- if (u)
- {
- log->Printf("\taddr=0x%16.16llx size=0x%16.16llx version=0x%16.16llx load-tag=0x%8.8x flags=0x%8.8x ref-list=0x%16.16llx uuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X name=\"%s\"",
- address, size, version, load_tag, flags, reference_list,
- u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6], u[ 7],
- u[ 8], u[ 9], u[10], u[11], u[12], u[13], u[14], u[15],
- name);
- }
- else
- {
- log->Printf("\t[0x%16.16llx - 0x%16.16llx) version=0x%16.16llx load-tag=0x%8.8x flags=0x%8.8x ref-list=0x%16.16llx name=\"%s\"",
- address, address+size, version, load_tag, flags, reference_list,
- name);
- }
- for (uint32_t i=0; i<segments.size(); ++i)
- segments[i].PutToLog(log, 0);
- }
-}
-
-//----------------------------------------------------------------------
-// Dump the _dyld_all_image_infos members and all current image infos
-// that we have parsed to the file handle provided.
-//----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXKernel::PutToLog(Log *log) const
-{
- if (log == NULL)
- return;
-
- Mutex::Locker locker(m_mutex);
- log->Printf("gLoadedKextSummaries = 0x%16.16llx { version=%u, entry_size=%u, entry_count=%u }",
- m_kext_summary_header_addr.GetFileAddress(),
- m_kext_summary_header.version,
- m_kext_summary_header.entry_size,
- m_kext_summary_header.entry_count);
-
- size_t i;
- const size_t count = m_kext_summaries.size();
- if (count > 0)
- {
- log->PutCString("Loaded:");
- for (i = 0; i<count; i++)
- m_kext_summaries[i].PutToLog(log);
- }
-}
-
-void
-DynamicLoaderMacOSXKernel::PrivateInitialize(Process *process)
-{
- DEBUG_PRINTF("DynamicLoaderMacOSXKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
- Clear(true);
- m_process = process;
- m_process->GetTarget().GetSectionLoadList().Clear();
-}
-
-void
-DynamicLoaderMacOSXKernel::SetNotificationBreakpointIfNeeded ()
-{
- if (m_break_id == LLDB_INVALID_BREAK_ID)
- {
- DEBUG_PRINTF("DynamicLoaderMacOSXKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
-
-
- const bool internal_bp = false;
- const LazyBool skip_prologue = eLazyBoolNo;
- Breakpoint *bp = m_process->GetTarget().CreateBreakpoint (&m_kernel.module_sp->GetFileSpec(),
- "OSKextLoadedKextSummariesUpdated",
- eFunctionNameTypeFull,
- internal_bp,
- skip_prologue).get();
-
- bp->SetCallback (DynamicLoaderMacOSXKernel::BreakpointHitCallback, this, true);
- m_break_id = bp->GetID();
- }
-}
-
-//----------------------------------------------------------------------
-// Member function that gets called when the process state changes.
-//----------------------------------------------------------------------
-void
-DynamicLoaderMacOSXKernel::PrivateProcessStateChanged (Process *process, StateType state)
-{
- DEBUG_PRINTF("DynamicLoaderMacOSXKernel::%s(%s)\n", __FUNCTION__, StateAsCString(state));
- switch (state)
- {
- case eStateConnected:
- case eStateAttaching:
- case eStateLaunching:
- case eStateInvalid:
- case eStateUnloaded:
- case eStateExited:
- case eStateDetached:
- Clear(false);
- break;
-
- case eStateStopped:
- UpdateIfNeeded();
- break;
-
- case eStateRunning:
- case eStateStepping:
- case eStateCrashed:
- case eStateSuspended:
- break;
-
- default:
- break;
- }
-}
-
-ThreadPlanSP
-DynamicLoaderMacOSXKernel::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
-{
- ThreadPlanSP thread_plan_sp;
- LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
- if (log)
- log->Printf ("Could not find symbol for step through.");
- return thread_plan_sp;
-}
-
-Error
-DynamicLoaderMacOSXKernel::CanLoadImage ()
-{
- Error error;
- error.SetErrorString("always unsafe to load or unload shared libraries in the darwin kernel");
- return error;
-}
-
-void
-DynamicLoaderMacOSXKernel::Initialize()
-{
- PluginManager::RegisterPlugin (GetPluginNameStatic(),
- GetPluginDescriptionStatic(),
- CreateInstance);
-}
-
-void
-DynamicLoaderMacOSXKernel::Terminate()
-{
- PluginManager::UnregisterPlugin (CreateInstance);
-}
-
-
-const char *
-DynamicLoaderMacOSXKernel::GetPluginNameStatic()
-{
- return "dynamic-loader.macosx-kernel";
-}
-
-const char *
-DynamicLoaderMacOSXKernel::GetPluginDescriptionStatic()
-{
- return "Dynamic loader plug-in that watches for shared library loads/unloads in the MacOSX kernel.";
-}
-
-
-//------------------------------------------------------------------
-// PluginInterface protocol
-//------------------------------------------------------------------
-const char *
-DynamicLoaderMacOSXKernel::GetPluginName()
-{
- return "DynamicLoaderMacOSXKernel";
-}
-
-const char *
-DynamicLoaderMacOSXKernel::GetShortPluginName()
-{
- return GetPluginNameStatic();
-}
-
-uint32_t
-DynamicLoaderMacOSXKernel::GetPluginVersion()
-{
- return 1;
-}
-
Removed: lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderMacOSXKernel.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-Kernel/DynamicLoaderMacOSXKernel.h?rev=138280&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderMacOSXKernel.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderMacOSXKernel.h (removed)
@@ -1,443 +0,0 @@
-//===-- DynamicLoaderMacOSXKernel.h -----------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_DynamicLoaderMacOSXKernel_h_
-#define liblldb_DynamicLoaderMacOSXKernel_h_
-
-// C Includes
-// C++ Includes
-#include <map>
-#include <vector>
-#include <string>
-
-// Other libraries and framework includes
-#include "llvm/Support/MachO.h"
-
-#include "lldb/Target/DynamicLoader.h"
-#include "lldb/Host/FileSpec.h"
-#include "lldb/Host/TimeValue.h"
-#include "lldb/Core/UUID.h"
-#include "lldb/Host/Mutex.h"
-#include "lldb/Target/Process.h"
-
-class DynamicLoaderMacOSXKernel : public lldb_private::DynamicLoader
-{
-public:
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
- static void
- Initialize();
-
- static void
- Terminate();
-
- static const char *
- GetPluginNameStatic();
-
- static const char *
- GetPluginDescriptionStatic();
-
- static lldb_private::DynamicLoader *
- CreateInstance (lldb_private::Process *process, bool force);
-
- DynamicLoaderMacOSXKernel (lldb_private::Process *process);
-
- virtual
- ~DynamicLoaderMacOSXKernel ();
- //------------------------------------------------------------------
- /// Called after attaching a process.
- ///
- /// Allow DynamicLoader plug-ins to execute some code after
- /// attaching to a process.
- //------------------------------------------------------------------
- virtual void
- DidAttach ();
-
- virtual void
- DidLaunch ();
-
- virtual lldb::ThreadPlanSP
- GetStepThroughTrampolinePlan (lldb_private::Thread &thread,
- bool stop_others);
-
- virtual lldb_private::Error
- CanLoadImage ();
-
- //------------------------------------------------------------------
- // PluginInterface protocol
- //------------------------------------------------------------------
- virtual const char *
- GetPluginName();
-
- virtual const char *
- GetShortPluginName();
-
- virtual uint32_t
- GetPluginVersion();
-
-protected:
- void
- PrivateInitialize (lldb_private::Process *process);
-
- void
- PrivateProcessStateChanged (lldb_private::Process *process,
- lldb::StateType state);
-
- void
- UpdateIfNeeded();
-
- void
- LoadKernelModuleIfNeeded ();
-
- void
- Clear (bool clear_process);
-
- void
- PutToLog (lldb_private::Log *log) const;
-
- static bool
- BreakpointHitCallback (void *baton,
- lldb_private::StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id);
-
- bool
- BreakpointHit (lldb_private::StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id);
- uint32_t
- AddrByteSize()
- {
- switch (m_kernel.header.magic)
- {
- case llvm::MachO::HeaderMagic32:
- case llvm::MachO::HeaderMagic32Swapped:
- return 4;
-
- case llvm::MachO::HeaderMagic64:
- case llvm::MachO::HeaderMagic64Swapped:
- return 8;
-
- default:
- break;
- }
- return 0;
- }
-
- static lldb::ByteOrder
- GetByteOrderFromMagic (uint32_t magic)
- {
- switch (magic)
- {
- case llvm::MachO::HeaderMagic32:
- case llvm::MachO::HeaderMagic64:
- return lldb::endian::InlHostByteOrder();
-
- case llvm::MachO::HeaderMagic32Swapped:
- case llvm::MachO::HeaderMagic64Swapped:
- if (lldb::endian::InlHostByteOrder() == lldb::eByteOrderBig)
- return lldb::eByteOrderLittle;
- else
- return lldb::eByteOrderBig;
-
- default:
- break;
- }
- return lldb::eByteOrderInvalid;
- }
-
- class Segment
- {
- public:
-
- Segment() :
- name(),
- vmaddr(LLDB_INVALID_ADDRESS),
- vmsize(0),
- fileoff(0),
- filesize(0),
- maxprot(0),
- initprot(0),
- nsects(0),
- flags(0)
- {
- }
-
- lldb_private::ConstString name;
- lldb::addr_t vmaddr;
- lldb::addr_t vmsize;
- lldb::addr_t fileoff;
- lldb::addr_t filesize;
- uint32_t maxprot;
- uint32_t initprot;
- uint32_t nsects;
- uint32_t flags;
-
- bool
- operator==(const Segment& rhs) const
- {
- return name == rhs.name && vmaddr == rhs.vmaddr && vmsize == rhs.vmsize;
- }
-
- void
- PutToLog (lldb_private::Log *log,
- lldb::addr_t slide) const;
-
- };
-
- enum
- {
- KERNEL_MODULE_MAX_NAME = 64u,
- // Versions less than 2 didn't have an entry size,
- // they had a 64 bit name, 16 byte UUID, 8 byte addr,
- // 8 byte size, 8 byte version, 4 byte load tag, and
- // 4 byte flags
- KERNEL_MODULE_ENTRY_SIZE_VERSION_1 = 64u + 16u + 8u + 8u + 8u + 4u + 4u
- };
-
- struct OSKextLoadedKextSummary
- {
- char name[KERNEL_MODULE_MAX_NAME];
- lldb::ModuleSP module_sp;
- uint32_t module_create_stop_id;
- lldb_private::UUID uuid; // UUID for this dylib if it has one, else all zeros
- lldb_private::Address so_address; // The section offset address for this kext in case it can be read from object files
- uint64_t address;
- uint64_t size;
- uint64_t version;
- uint32_t load_tag;
- uint32_t flags;
- uint64_t reference_list;
- llvm::MachO::mach_header header; // The mach header for this image
- std::vector<Segment> segments; // All segment vmaddr and vmsize pairs for this executable (from memory of inferior)
-
- OSKextLoadedKextSummary() :
- module_sp (),
- module_create_stop_id (UINT32_MAX),
- uuid (),
- so_address (),
- address (LLDB_INVALID_ADDRESS),
- size (0),
- version (0),
- load_tag (0),
- flags (0),
- reference_list (0),
- header(),
- segments()
- {
- name[0] = '\0';
- }
-
- void
- Clear (bool load_cmd_data_only)
- {
- if (!load_cmd_data_only)
- {
- so_address.Clear();
- address = LLDB_INVALID_ADDRESS;
- size = 0;
- version = 0;
- load_tag = 0;
- flags = 0;
- reference_list = 0;
- name[0] = '\0';
- ::memset (&header, 0, sizeof(header));
- }
- module_sp.reset();
- module_create_stop_id = UINT32_MAX;
- uuid.Clear();
- segments.clear();
- }
-
- bool
- operator == (const OSKextLoadedKextSummary& rhs) const
- {
- return address == rhs.address
- && size == rhs.size
- //&& module_sp.get() == rhs.module_sp.get()
- && uuid == rhs.uuid
- && version == rhs.version
- && load_tag == rhs.load_tag
- && flags == rhs.flags
- && reference_list == rhs.reference_list
- && strncmp (name, rhs.name, KERNEL_MODULE_MAX_NAME) == 0
- && memcmp(&header, &rhs.header, sizeof(header)) == 0
- && segments == rhs.segments;
- }
-
- bool
- UUIDValid() const
- {
- return uuid.IsValid();
- }
-
- uint32_t
- GetAddressByteSize ()
- {
- if (header.cputype)
- {
- if (header.cputype & llvm::MachO::CPUArchABI64)
- return 8;
- else
- return 4;
- }
- return 0;
- }
-
- lldb::ByteOrder
- GetByteOrder()
- {
- switch (header.magic)
- {
- case llvm::MachO::HeaderMagic32: // MH_MAGIC
- case llvm::MachO::HeaderMagic64: // MH_MAGIC_64
- return lldb::endian::InlHostByteOrder();
-
- case llvm::MachO::HeaderMagic32Swapped: // MH_CIGAM
- case llvm::MachO::HeaderMagic64Swapped: // MH_CIGAM_64
- if (lldb::endian::InlHostByteOrder() == lldb::eByteOrderLittle)
- return lldb::eByteOrderBig;
- else
- return lldb::eByteOrderLittle;
- default:
- assert (!"invalid header.magic value");
- break;
- }
- return lldb::endian::InlHostByteOrder();
- }
-
- lldb_private::ArchSpec
- GetArchitecture () const
- {
- return lldb_private::ArchSpec (lldb_private::eArchTypeMachO, header.cputype, header.cpusubtype);
- }
-
- const Segment *
- FindSegment (const lldb_private::ConstString &name) const;
-
- void
- PutToLog (lldb_private::Log *log) const;
-
- typedef std::vector<OSKextLoadedKextSummary> collection;
- typedef collection::iterator iterator;
- typedef collection::const_iterator const_iterator;
- };
-
- struct OSKextLoadedKextSummaryHeader
- {
- uint32_t version;
- uint32_t entry_size;
- uint32_t entry_count;
- lldb::addr_t image_infos_addr;
-
- OSKextLoadedKextSummaryHeader() :
- version (0),
- entry_size (0),
- entry_count (0),
- image_infos_addr (LLDB_INVALID_ADDRESS)
- {
- }
-
- uint32_t
- GetSize()
- {
- switch (version)
- {
- case 0: return 0; // Can't know the size without a valid version
- case 1: return 8; // Version 1 only had a version + entry_count
- default: break;
- }
- // Version 2 and above has version, entry_size, entry_count, and reserved
- return 16;
- }
-
- void
- Clear()
- {
- version = 0;
- entry_size = 0;
- entry_count = 0;
- image_infos_addr = LLDB_INVALID_ADDRESS;
- }
-
- bool
- IsValid() const
- {
- return version >= 1 || version <= 2;
- }
- };
-
- bool
- ReadMachHeader (OSKextLoadedKextSummary& kext_summary,
- lldb_private::DataExtractor *load_command_data);
-
- void
- RegisterNotificationCallbacks();
-
- void
- UnregisterNotificationCallbacks();
-
- uint32_t
- ParseLoadCommands (const lldb_private::DataExtractor& data,
- OSKextLoadedKextSummary& dylib_info);
-
- bool
- UpdateImageLoadAddress(OSKextLoadedKextSummary& info);
-
- bool
- FindTargetModule (OSKextLoadedKextSummary &image_info,
- bool can_create,
- bool *did_create_ptr);
-
- void
- SetNotificationBreakpointIfNeeded ();
-
- bool
- ReadAllKextSummaries ();
-
- bool
- ReadKextSummaryHeader ();
-
- bool
- ParseKextSummaries (const lldb_private::Address &kext_summary_addr,
- uint32_t count);
-
- bool
- AddModulesUsingImageInfos (OSKextLoadedKextSummary::collection &image_infos);
-
- void
- UpdateImageInfosHeaderAndLoadCommands(OSKextLoadedKextSummary::collection &image_infos,
- uint32_t infos_count,
- bool update_executable);
-
- bool
- UpdateCommPageLoadAddress (lldb_private::Module *module);
-
- uint32_t
- ReadKextSummaries (const lldb_private::Address &kext_summary_addr,
- uint32_t image_infos_count,
- OSKextLoadedKextSummary::collection &image_infos);
-
- bool
- UnloadImageLoadAddress (OSKextLoadedKextSummary& info);
-
- OSKextLoadedKextSummary m_kernel; // Info about the current kernel image being used
- lldb_private::Address m_kext_summary_header_ptr_addr;
- lldb_private::Address m_kext_summary_header_addr;
- OSKextLoadedKextSummaryHeader m_kext_summary_header;
- OSKextLoadedKextSummary::collection m_kext_summaries;
- mutable lldb_private::Mutex m_mutex;
- lldb::user_id_t m_break_id;
-
-private:
- DISALLOW_COPY_AND_ASSIGN (DynamicLoaderMacOSXKernel);
-};
-
-#endif // liblldb_DynamicLoaderMacOSXKernel_h_
Modified: lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/Makefile?rev=138282&r1=138280&r2=138282&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/Makefile (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/Makefile Mon Aug 22 17:23:48 2011
@@ -8,7 +8,7 @@
##===----------------------------------------------------------------------===##
LLDB_LEVEL := ../../../..
-LIBRARYNAME := lldbPluginDynamicLoaderMacOSXKernel
+LIBRARYNAME := lldbPluginDynamicLoaderDarwinKernel
BUILD_ARCHIVE = 1
include $(LLDB_LEVEL)/Makefile
Removed: lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemMacOSXKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/OperatingSystem/MacOSX-Kernel/OperatingSystemMacOSXKernel.cpp?rev=138280&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemMacOSXKernel.cpp (original)
+++ lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemMacOSXKernel.cpp (removed)
@@ -1,309 +0,0 @@
-//===-- OperatingSystemMacOSXKernel.cpp --------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "OperatingSystemMacOSXKernel.h"
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-#include "llvm/ADT/Triple.h"
-
-#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/Module.h"
-#include "lldb/Core/PluginManager.h"
-#include "lldb/Core/RegisterValue.h"
-#include "lldb/Core/ValueObjectVariable.h"
-#include "lldb/Symbol/ObjectFile.h"
-#include "lldb/Symbol/VariableList.h"
-#include "lldb/Target/Process.h"
-#include "lldb/Target/StopInfo.h"
-#include "lldb/Target/Target.h"
-#include "lldb/Target/ThreadList.h"
-#include "lldb/Target/Thread.h"
-#include "Plugins/Process/Utility/DynamicRegisterInfo.h"
-#include "Plugins/Process/Utility/RegisterContextMemory.h"
-#include "Plugins/Process/Utility/ThreadMemory.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-static ConstString &
-GetThreadGPRMemberName ()
-{
- static ConstString g_gpr_member_name("gpr");
- return g_gpr_member_name;
-}
-
-void
-OperatingSystemMacOSXKernel::Initialize()
-{
- PluginManager::RegisterPlugin (GetPluginNameStatic(),
- GetPluginDescriptionStatic(),
- CreateInstance);
-}
-
-void
-OperatingSystemMacOSXKernel::Terminate()
-{
- PluginManager::UnregisterPlugin (CreateInstance);
-}
-
-OperatingSystem *
-OperatingSystemMacOSXKernel::CreateInstance (Process *process, bool force)
-{
-#if 0
- bool create = force;
- if (!create)
- {
- Module* exe_module = process->GetTarget().GetExecutableModulePointer();
- if (exe_module)
- {
- ObjectFile *object_file = exe_module->GetObjectFile();
- if (object_file)
- {
- SectionList *section_list = object_file->GetSectionList();
- if (section_list)
- {
- static ConstString g_kld_section_name ("__KLD");
- if (section_list->FindSectionByName (g_kld_section_name))
- {
- create = true;
- }
- }
- }
- }
-
- // We can limit the creation of this plug-in to "*-apple-darwin" triples
- // if we command out the lines below...
-// if (create)
-// {
-// const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
-// create = triple_ref.getOS() == llvm::Triple::Darwin && triple_ref.getVendor() == llvm::Triple::Apple;
-// }
- }
-
- if (create)
- return new OperatingSystemMacOSXKernel (process);
-#endif
- return NULL;
-}
-
-
-const char *
-OperatingSystemMacOSXKernel::GetPluginNameStatic()
-{
- return "macosx-kernel";
-}
-
-const char *
-OperatingSystemMacOSXKernel::GetPluginDescriptionStatic()
-{
- return "Operating system plug-in that gathers OS information from darwin kernels.";
-}
-
-
-OperatingSystemMacOSXKernel::OperatingSystemMacOSXKernel (lldb_private::Process *process) :
- OperatingSystem (process),
- m_thread_list_valobj_sp (),
- m_register_info_ap ()
-{
-}
-
-OperatingSystemMacOSXKernel::~OperatingSystemMacOSXKernel ()
-{
-}
-
-ValueObjectSP
-OperatingSystemMacOSXKernel::GetThreadListValueObject ()
-{
- if (m_thread_list_valobj_sp.get() == NULL)
- {
- VariableList variable_list;
- const uint32_t max_matches = 1;
- const bool append = true;
- static ConstString g_thread_list_name("g_thread_list");
- Module *exe_module = m_process->GetTarget().GetExecutableModulePointer();
- if (exe_module)
- {
- if (exe_module->FindGlobalVariables (g_thread_list_name,
- append,
- max_matches,
- variable_list))
- {
- m_thread_list_valobj_sp = ValueObjectVariable::Create (m_process, variable_list.GetVariableAtIndex(0));
- }
- }
- }
- return m_thread_list_valobj_sp;
-}
-
-DynamicRegisterInfo *
-OperatingSystemMacOSXKernel::GetDynamicRegisterInfo ()
-{
- if (m_register_info_ap.get() == NULL && m_thread_list_valobj_sp)
- {
- m_register_info_ap.reset (new DynamicRegisterInfo());
- ConstString empty_name;
- const bool can_create = true;
- AddressType addr_type;
- addr_t base_addr = LLDB_INVALID_ADDRESS;
- ValueObjectSP gpr_valobj_sp (m_thread_list_valobj_sp->GetChildMemberWithName(GetThreadGPRMemberName (), can_create));
-
- if (gpr_valobj_sp->IsPointerType ())
- base_addr = gpr_valobj_sp->GetPointerValue (addr_type, true);
- else
- base_addr = gpr_valobj_sp->GetAddressOf (addr_type, true);
-
- ValueObjectSP child_valobj_sp;
- if (gpr_valobj_sp)
- {
- ABI *abi = m_process->GetABI().get();
- assert (abi);
- uint32_t num_children = gpr_valobj_sp->GetNumChildren();
-
- ConstString gpr_name (gpr_valobj_sp->GetName());
- uint32_t reg_num = 0;
- for (uint32_t i=0; i<num_children; ++i)
- {
- child_valobj_sp = gpr_valobj_sp->GetChildAtIndex(i, can_create);
-
- ConstString reg_name(child_valobj_sp->GetName());
- if (reg_name)
- {
- const char *reg_name_cstr = reg_name.GetCString();
- while (reg_name_cstr[0] == '_')
- ++reg_name_cstr;
- if (reg_name_cstr != reg_name.GetCString())
- reg_name.SetCString (reg_name_cstr);
- }
-
- RegisterInfo reg_info;
- if (abi->GetRegisterInfoByName(reg_name, reg_info))
- {
- // Adjust the byte size and the offset to match the layout of registers in our struct
- reg_info.byte_size = child_valobj_sp->GetByteSize();
- reg_info.byte_offset = child_valobj_sp->GetAddressOf(addr_type, true) - base_addr;
- reg_info.kinds[eRegisterKindLLDB] = reg_num++;
- m_register_info_ap->AddRegister (reg_info, reg_name, empty_name, gpr_name);
- }
- else
- {
- printf ("not able to find register info for %s\n", reg_name.GetCString()); // REMOVE THIS printf before checkin!!!
- }
- }
-
- m_register_info_ap->Finalize();
- }
- }
- assert (m_register_info_ap.get());
- return m_register_info_ap.get();
-}
-
-//------------------------------------------------------------------
-// PluginInterface protocol
-//------------------------------------------------------------------
-const char *
-OperatingSystemMacOSXKernel::GetPluginName()
-{
- return "OperatingSystemMacOSXKernel";
-}
-
-const char *
-OperatingSystemMacOSXKernel::GetShortPluginName()
-{
- return GetPluginNameStatic();
-}
-
-uint32_t
-OperatingSystemMacOSXKernel::GetPluginVersion()
-{
- return 1;
-}
-
-uint32_t
-OperatingSystemMacOSXKernel::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list)
-{
- // Make any constant strings once and cache the uniqued C string values
- // so we don't have to rehash them each time through this function call
- static ConstString g_tid_member_name("tid");
- static ConstString g_next_member_name("next");
-
- ValueObjectSP root_valobj_sp (GetThreadListValueObject ());
- ValueObjectSP valobj_sp = root_valobj_sp;
- const bool can_create = true;
- while (valobj_sp)
- {
- if (valobj_sp->GetValueAsUnsigned(0) == 0)
- break;
-
- ValueObjectSP tid_valobj_sp(valobj_sp->GetChildMemberWithName(g_tid_member_name, can_create));
- if (!tid_valobj_sp)
- break;
-
- tid_t tid = tid_valobj_sp->GetValueAsUnsigned (LLDB_INVALID_THREAD_ID);
- if (tid == LLDB_INVALID_THREAD_ID)
- break;
-
- ThreadSP thread_sp (old_thread_list.FindThreadByID (tid, false));
- if (!thread_sp)
- thread_sp.reset (new ThreadMemory (*m_process, tid, valobj_sp));
-
- new_thread_list.AddThread(thread_sp);
-
- ValueObjectSP next_valobj_sp (valobj_sp->GetChildMemberWithName(g_next_member_name, can_create));
-
- if (next_valobj_sp)
- {
- // Watch for circular linked lists
- if (next_valobj_sp.get() == root_valobj_sp.get())
- break;
- }
- next_valobj_sp.swap(valobj_sp);
- }
- return new_thread_list.GetSize(false);
-}
-
-void
-OperatingSystemMacOSXKernel::ThreadWasSelected (Thread *thread)
-{
-}
-
-RegisterContextSP
-OperatingSystemMacOSXKernel::CreateRegisterContextForThread (Thread *thread)
-{
- ThreadMemory *generic_thread = (ThreadMemory *)thread;
- RegisterContextSP reg_ctx_sp;
-
- ValueObjectSP thread_valobj_sp (generic_thread->GetValueObject());
- if (thread_valobj_sp)
- {
- const bool can_create = true;
- AddressType addr_type;
- addr_t base_addr = LLDB_INVALID_ADDRESS;
- ValueObjectSP gpr_valobj_sp (thread_valobj_sp->GetChildMemberWithName(GetThreadGPRMemberName (), can_create));
- if (gpr_valobj_sp)
- {
- if (gpr_valobj_sp->IsPointerType ())
- base_addr = gpr_valobj_sp->GetPointerValue (addr_type, true);
- else
- base_addr = gpr_valobj_sp->GetAddressOf (addr_type, true);
- reg_ctx_sp.reset (new RegisterContextMemory (*thread, 0, *GetDynamicRegisterInfo (), base_addr));
- }
- }
- return reg_ctx_sp;
-}
-
-StopInfoSP
-OperatingSystemMacOSXKernel::CreateThreadStopReason (lldb_private::Thread *thread)
-{
- StopInfoSP stop_info_sp; //(StopInfo::CreateStopReasonWithSignal (*thread, SIGSTOP));
- return stop_info_sp;
-}
-
-
Removed: lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemMacOSXKernel.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/OperatingSystem/MacOSX-Kernel/OperatingSystemMacOSXKernel.h?rev=138280&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemMacOSXKernel.h (original)
+++ lldb/trunk/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemMacOSXKernel.h (removed)
@@ -1,90 +0,0 @@
-//===-- OperatingSystemMacOSXKernel.h ----------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_OperatingSystemMacOSXKernel_h_
-#define liblldb_OperatingSystemMacOSXKernel_h_
-
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-#include "lldb/Target/OperatingSystem.h"
-
-class DynamicRegisterInfo;
-
-class OperatingSystemMacOSXKernel : public lldb_private::OperatingSystem
-{
-public:
- //------------------------------------------------------------------
- // Static Functions
- //------------------------------------------------------------------
- static lldb_private::OperatingSystem *
- CreateInstance (lldb_private::Process *process, bool force);
-
- static void
- Initialize();
-
- static void
- Terminate();
-
- static const char *
- GetPluginNameStatic();
-
- static const char *
- GetPluginDescriptionStatic();
-
- //------------------------------------------------------------------
- // Class Methods
- //------------------------------------------------------------------
- OperatingSystemMacOSXKernel (lldb_private::Process *process);
-
- virtual
- ~OperatingSystemMacOSXKernel ();
-
- //------------------------------------------------------------------
- // lldb_private::PluginInterface Methods
- //------------------------------------------------------------------
- virtual const char *
- GetPluginName();
-
- virtual const char *
- GetShortPluginName();
-
- virtual uint32_t
- GetPluginVersion();
-
- //------------------------------------------------------------------
- // lldb_private::OperatingSystem Methods
- //------------------------------------------------------------------
- virtual uint32_t
- UpdateThreadList (lldb_private::ThreadList &old_thread_list,
- lldb_private::ThreadList &new_thread_list);
-
- virtual void
- ThreadWasSelected (lldb_private::Thread *thread);
-
- virtual lldb::RegisterContextSP
- CreateRegisterContextForThread (lldb_private::Thread *thread);
-
- virtual lldb::StopInfoSP
- CreateThreadStopReason (lldb_private::Thread *thread);
-
-protected:
-
- lldb::ValueObjectSP
- GetThreadListValueObject ();
-
- DynamicRegisterInfo *
- GetDynamicRegisterInfo ();
-
- lldb::ValueObjectSP m_thread_list_valobj_sp;
- std::auto_ptr<DynamicRegisterInfo> m_register_info_ap;
-
-};
-
-#endif // #ifndef liblldb_OperatingSystemMacOSXKernel_h_
\ No newline at end of file
More information about the lldb-commits
mailing list