[Lldb-commits] [lldb] r236640 - Add a language objc class-table dump command
Enrico Granata
egranata at apple.com
Wed May 6 14:01:07 PDT 2015
Author: enrico
Date: Wed May 6 16:01:07 2015
New Revision: 236640
URL: http://llvm.org/viewvc/llvm-project?rev=236640&view=rev
Log:
Add a language objc class-table dump command
This command dumps a bunch of interesting facts about all Objective-C classes known to LLDB in the inferior process
Modified:
lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
Modified: lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h?rev=236640&r1=236639&r2=236640&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h Wed May 6 16:01:07 2015
@@ -26,6 +26,8 @@
#include "lldb/Symbol/Type.h"
#include "lldb/Target/LanguageRuntime.h"
+class CommandObjectObjC_ClassTable_Dump;
+
namespace lldb_private {
class ClangUtilityFunction;
@@ -663,6 +665,11 @@ protected:
ISAToDescriptorIterator
GetDescriptorIterator (const ConstString &name);
+ friend class ::CommandObjectObjC_ClassTable_Dump;
+
+ std::pair<ISAToDescriptorIterator,ISAToDescriptorIterator>
+ GetDescriptorIteratorPair (bool update_if_needed = true);
+
void
ReadObjCLibraryIfNeeded (const ModuleList &module_list);
Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=236640&r1=236639&r2=236640&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Wed May 6 16:01:07 2015
@@ -32,6 +32,9 @@
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/Expression/ClangFunction.h"
#include "lldb/Expression/ClangUtilityFunction.h"
+#include "lldb/Interpreter/CommandObject.h"
+#include "lldb/Interpreter/CommandObjectMultiword.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/Symbol.h"
@@ -445,12 +448,112 @@ AppleObjCRuntimeV2::CreateInstance (Proc
return NULL;
}
+class CommandObjectObjC_ClassTable_Dump : public CommandObjectParsed
+{
+public:
+
+ CommandObjectObjC_ClassTable_Dump (CommandInterpreter &interpreter) :
+ CommandObjectParsed (interpreter,
+ "dump",
+ "Dump information on Objective-C classes known to the current process.",
+ "language objc class-table dump",
+ eFlagRequiresProcess |
+ eFlagProcessMustBeLaunched |
+ eFlagProcessMustBePaused )
+ {
+ }
+
+ ~CommandObjectObjC_ClassTable_Dump ()
+ {
+ }
+
+protected:
+ bool
+ DoExecute (Args& command, CommandReturnObject &result)
+ {
+ Process *process = m_exe_ctx.GetProcessPtr();
+ ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime();
+ if (objc_runtime)
+ {
+ auto iterators_pair = objc_runtime->GetDescriptorIteratorPair();
+ auto iterator = iterators_pair.first;
+ for(; iterator != iterators_pair.second; iterator++)
+ {
+ result.GetOutputStream().Printf("isa = 0x%" PRIx64, iterator->first);
+ if (iterator->second)
+ {
+ result.GetOutputStream().Printf(" name = %s", iterator->second->GetClassName().AsCString("<unknown>"));
+ result.GetOutputStream().Printf(" instance size = %" PRIu64, iterator->second->GetInstanceSize());
+ result.GetOutputStream().Printf(" num ivars = %" PRIuPTR, (uintptr_t)iterator->second->GetNumIVars());
+ if (auto superclass = iterator->second->GetSuperclass())
+ {
+ result.GetOutputStream().Printf(" superclass = %s", superclass->GetClassName().AsCString("<unknown>"));
+ }
+ result.GetOutputStream().Printf("\n");
+ }
+ else
+ {
+ result.GetOutputStream().Printf(" has no associated class.\n");
+ }
+ }
+ result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
+ }
+ else
+ {
+ result.AppendError("current process has no Objective-C runtime loaded");
+ result.SetStatus(lldb::eReturnStatusFailed);
+ return false;
+ }
+ }
+};
+
+class CommandObjectMultiwordObjC_ClassTable : public CommandObjectMultiword
+{
+public:
+
+ CommandObjectMultiwordObjC_ClassTable (CommandInterpreter &interpreter) :
+ CommandObjectMultiword (interpreter,
+ "class-table",
+ "A set of commands for operating on the Objective-C class table.",
+ "class-table <subcommand> [<subcommand-options>]")
+ {
+ LoadSubCommand ("dump", CommandObjectSP (new CommandObjectObjC_ClassTable_Dump (interpreter)));
+ }
+
+ virtual
+ ~CommandObjectMultiwordObjC_ClassTable ()
+ {
+ }
+};
+
+class CommandObjectMultiwordObjC : public CommandObjectMultiword
+{
+public:
+
+ CommandObjectMultiwordObjC (CommandInterpreter &interpreter) :
+ CommandObjectMultiword (interpreter,
+ "objc",
+ "A set of commands for operating on the Objective-C Language Runtime.",
+ "objc <subcommand> [<subcommand-options>]")
+ {
+ LoadSubCommand ("class-table", CommandObjectSP (new CommandObjectMultiwordObjC_ClassTable (interpreter)));
+ }
+
+ virtual
+ ~CommandObjectMultiwordObjC ()
+ {
+ }
+};
+
void
AppleObjCRuntimeV2::Initialize()
{
PluginManager::RegisterPlugin (GetPluginNameStatic(),
"Apple Objective C Language Runtime - Version 2",
- CreateInstance);
+ CreateInstance,
+ [] (CommandInterpreter& interpreter) -> lldb::CommandObjectSP {
+ return CommandObjectSP(new CommandObjectMultiwordObjC(interpreter));
+ });
}
void
Modified: lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ObjCLanguageRuntime.cpp?rev=236640&r1=236639&r2=236640&view=diff
==============================================================================
--- lldb/trunk/source/Target/ObjCLanguageRuntime.cpp (original)
+++ lldb/trunk/source/Target/ObjCLanguageRuntime.cpp Wed May 6 16:01:07 2015
@@ -497,6 +497,14 @@ ObjCLanguageRuntime::GetDescriptorIterat
return end;
}
+std::pair<ObjCLanguageRuntime::ISAToDescriptorIterator,ObjCLanguageRuntime::ISAToDescriptorIterator>
+ObjCLanguageRuntime::GetDescriptorIteratorPair (bool update_if_needed)
+{
+ if (update_if_needed)
+ UpdateISAToDescriptorMapIfNeeded();
+ return {m_isa_to_descriptor.begin(),m_isa_to_descriptor.end()};
+}
+
ObjCLanguageRuntime::ObjCISA
ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa)
More information about the lldb-commits
mailing list