4fe7d07c64096d4e8a2b92ada559224d
LLDB 整体架构

LLDB 整体架构

NJ大佬在上文《apropos 命令与其实现原理》提及了命令,apropos。从中我们不难窥探一些LLDB的设计思路。

今天,我们正式扬帆起航,从LLDB的整体架构说起,来探究下的LLDB的核心内幕。

LLDB本质上由诸多子工程组成,诸如DriverDebugServer等,都非常值得深挖。限于篇幅,本专栏主要探究LLDB解释器。

关键元素

如果要提LLDB整体实现的核心,我想如下两个元素可能是重中之重。

  • CommandInterpreter
  • Command

整个LLDB实际上可以理解为一个基于字符串解析的命令解释器。当你在命令行或者Xcode的调试界面中输入诸如apropos help的时候,实际上是被LLDB解释器按照特定的格式解析,映射成了对应的命令,即Command

Command究竟由多少种呢,则是由LLDB解释器在初始化的时候注册成了一张表:

  m_command_dict["apropos"] = CommandObjectSP(new CommandObjectApropos(*this));
  m_command_dict["breakpoint"] =
      CommandObjectSP(new CommandObjectMultiwordBreakpoint(*this));
  m_command_dict["bugreport"] =
      CommandObjectSP(new CommandObjectMultiwordBugreport(*this));
  m_command_dict["command"] =
      CommandObjectSP(new CommandObjectMultiwordCommands(*this));
  m_command_dict["disassemble"] =
      CommandObjectSP(new CommandObjectDisassemble(*this));
  m_command_dict["expression"] =
      CommandObjectSP(new CommandObjectExpression(*this));
  m_command_dict["frame"] =
      CommandObjectSP(new CommandObjectMultiwordFrame(*this));
  m_command_dict["gui"] = CommandObjectSP(new CommandObjectGUI(*this));
  m_command_dict["help"] = CommandObjectSP(new CommandObjectHelp(*this));
  m_command_dict["log"] = CommandObjectSP(new CommandObjectLog(*this));
  m_command_dict["memory"] = CommandObjectSP(new CommandObjectMemory(*this));
  m_command_dict["platform"] =
      CommandObjectSP(new CommandObjectPlatform(*this));
  m_command_dict["plugin"] = CommandObjectSP(new CommandObjectPlugin(*this));
  m_command_dict["process"] =
      CommandObjectSP(new CommandObjectMultiwordProcess(*this));
  m_command_dict["quit"] = CommandObjectSP(new CommandObjectQuit(*this));
  m_command_dict["register"] =
      CommandObjectSP(new CommandObjectRegister(*this));
  m_command_dict["script"] =
      CommandObjectSP(new CommandObjectScript(*this, script_language));
  m_command_dict["settings"] =
      CommandObjectSP(new CommandObjectMultiwordSettings(*this));
  m_command_dict["source"] =
      CommandObjectSP(new CommandObjectMultiwordSource(*this));
  m_command_dict["target"] =
      CommandObjectSP(new CommandObjectMultiwordTarget(*this));
  m_command_dict["thread"] =
      CommandObjectSP(new CommandObjectMultiwordThread(*this));
  m_command_dict["type"] = CommandObjectSP(new CommandObjectType(*this));
  m_command_dict["version"] = CommandObjectSP(new CommandObjectVersion(*this));
  m_command_dict["watchpoint"] =
      CommandObjectSP(new CommandObjectMultiwordWatchpoint(*this));
  m_command_dict["language"] =
      CommandObjectSP(new CommandObjectLanguage(*this));

其中有我们耳熟能详的memory, register, frame等等,也有我们第一次(至少是本菜鸡)了解的
bugreport, platform等等,这些命令我们都会在随后的文章中一一讲解。

top Created with Sketch.