diff options
Diffstat (limited to 'lldb/tools')
-rw-r--r-- | lldb/tools/lldb-mi/CMakeLists.txt | 2 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/MICmdCmdSymbol.cpp | 183 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/MICmdCmdSymbol.h | 67 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/MICmdCommands.cpp | 2 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/MIUtilString.cpp | 13 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/MIUtilString.h | 1 |
6 files changed, 268 insertions, 0 deletions
diff --git a/lldb/tools/lldb-mi/CMakeLists.txt b/lldb/tools/lldb-mi/CMakeLists.txt index 7ec9dfa6c97..032f06a615d 100644 --- a/lldb/tools/lldb-mi/CMakeLists.txt +++ b/lldb/tools/lldb-mi/CMakeLists.txt @@ -30,6 +30,7 @@ add_lldb_executable(lldb-mi MICmdCmdStack.cpp MICmdCmdSupportInfo.cpp MICmdCmdSupportList.cpp + MICmdCmdSymbol.cpp MICmdCmdTarget.cpp MICmdCmdThread.cpp MICmdCmdTrace.cpp @@ -111,6 +112,7 @@ add_lldb_executable(lldb-mi MICmdCmdStack.cpp MICmdCmdSupportInfo.cpp MICmdCmdSupportList.cpp + MICmdCmdSymbol.cpp MICmdCmdTarget.cpp MICmdCmdThread.cpp MICmdCmdTrace.cpp diff --git a/lldb/tools/lldb-mi/MICmdCmdSymbol.cpp b/lldb/tools/lldb-mi/MICmdCmdSymbol.cpp new file mode 100644 index 00000000000..5655d843e54 --- /dev/null +++ b/lldb/tools/lldb-mi/MICmdCmdSymbol.cpp @@ -0,0 +1,183 @@ +//===-- MICmdCmdSymbol.cpp --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +//++ +// File: MICmdCmdSymbol.cpp +// +// Overview: CMICmdCmdSymbolListLines implementation. +// +// Environment: Compilers: Visual C++ 12. +// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 +// Libraries: See MIReadmetxt. +// +// Copyright: None. +//-- + +// Third Party Headers: +#include <lldb/API/SBCommandInterpreter.h> + +// In-house headers: +#include "MICmdArgValFile.h" +#include "MICmdCmdSymbol.h" +#include "MICmnLLDBDebugSessionInfo.h" +#include "MICmnMIResultRecord.h" +#include "MICmnMIValueList.h" +#include "MICmnMIValueTuple.h" + +//++ ------------------------------------------------------------------------------------ +// Details: CMICmdCmdSymbolListLines constructor. +// Type: Method. +// Args: None. +// Return: None. +// Throws: None. +//-- +CMICmdCmdSymbolListLines::CMICmdCmdSymbolListLines(void) + : m_constStrArgNameFile("file") +{ + // Command factory matches this name with that received from the stdin stream + m_strMiCmd = "symbol-list-lines"; + + // Required by the CMICmdFactory when registering *this command + m_pSelfCreatorFn = &CMICmdCmdSymbolListLines::CreateSelf; +} + +//++ ------------------------------------------------------------------------------------ +// Details: CMICmdCmdSymbolListLines destructor. +// Type: Overrideable. +// Args: None. +// Return: None. +// Throws: None. +//-- +CMICmdCmdSymbolListLines::~CMICmdCmdSymbolListLines(void) +{ +} + +//++ ------------------------------------------------------------------------------------ +// Details: The invoker requires this function. The parses the command line options +// arguments to extract values for each of those arguments. +// Type: Overridden. +// Args: None. +// Return: MIstatus::success - Functional succeeded. +// MIstatus::failure - Functional failed. +// Throws: None. +//-- +bool +CMICmdCmdSymbolListLines::ParseArgs(void) +{ + bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValFile(m_constStrArgNameFile, true, true))); + return (bOk && ParseValidateCmdOptions()); +} + +//++ ------------------------------------------------------------------------------------ +// Details: The invoker requires this function. The command does work in this function. +// The command is likely to communicate with the LLDB SBDebugger in here. +// Synopsis: -symbol-list-lines file +// Ref: http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Symbol-Query.html#GDB_002fMI-Symbol-Query +// Type: Overridden. +// Args: None. +// Return: MIstatus::success - Functional succeeded. +// MIstatus::failure - Functional failed. +// Throws: None. +//-- +bool +CMICmdCmdSymbolListLines::Execute(void) +{ + CMICMDBASE_GETOPTION(pArgFile, File, m_constStrArgNameFile); + + const CMIUtilString &strFilePath(pArgFile->GetValue()); + const CMIUtilString strCmd(CMIUtilString::Format("target modules dump line-table \"%s\"", strFilePath.c_str())); + + CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); + const lldb::ReturnStatus rtn = rSessionInfo.GetDebugger().GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult); + MIunused(rtn); + + return MIstatus::success; +} + +//++ ------------------------------------------------------------------------------------ +// Details: The invoker requires this function. The command prepares a MI Record Result +// for the work carried out in the Execute(). +// Type: Overridden. +// Args: None. +// Return: MIstatus::success - Functional succeeded. +// MIstatus::failure - Functional failed. +// Throws: None. +//-- +bool +CMICmdCmdSymbolListLines::Acknowledge(void) +{ + if (m_lldbResult.GetErrorSize() > 0) + { + const MIchar *pLldbErr = m_lldbResult.GetError(); + const CMIUtilString strMsg(CMIUtilString(pLldbErr).StripCRAll()); + const CMICmnMIValueConst miValueConst(strMsg); + const CMICmnMIValueResult miValueResult("message", miValueConst); + const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult); + m_miResultRecord = miRecordResult; + } + else + { + CMIUtilString::VecString_t vecLines; + const CMIUtilString strLldbMsg(m_lldbResult.GetOutput()); + const MIuint nLines(strLldbMsg.SplitLines(vecLines)); + + CMICmnMIValueList miValueList(true); + for (MIuint i = 1; i < nLines; ++i) + { + // String looks like: + // 0x0000000100000e70: /path/to/file:3[:4] + const CMIUtilString &rLine(vecLines[i]); + + // 0x0000000100000e70: /path/to/file:3[:4] + // ^^^^^^^^^^^^^^^^^^ -- pc + const MIuint nAddrEndPos = rLine.find(':'); + const CMIUtilString strAddr(rLine.substr(0, nAddrEndPos).c_str()); + const CMICmnMIValueConst miValueConst(strAddr); + const CMICmnMIValueResult miValueResult("pc", miValueConst); + CMICmnMIValueTuple miValueTuple(miValueResult); + + // 0x0000000100000e70: /path/to/file:3[:4] + // ^ -- line + const MIuint nLineOrColumnStartPos = rLine.rfind(':'); + const CMIUtilString strLineOrColumn(rLine.substr(nLineOrColumnStartPos + 1).c_str()); + const MIuint nPathOrLineStartPos = rLine.rfind(':', nLineOrColumnStartPos - 1); + const MIuint nPathOrLineLen = nLineOrColumnStartPos - nPathOrLineStartPos - 1; + const CMIUtilString strPathOrLine(rLine.substr(nPathOrLineStartPos + 1, nPathOrLineLen).c_str()); + const CMIUtilString strLine(strPathOrLine.IsNumber() ? strPathOrLine : strLineOrColumn); + const CMICmnMIValueConst miValueConst2(strLine); + const CMICmnMIValueResult miValueResult2("line", miValueConst2); + bool bOk = miValueTuple.Add(miValueResult2); + + bOk = bOk && miValueList.Add(miValueTuple); + if (!bOk) + return MIstatus::failure; + } + + // MI print "%s^done,lines=[{pc=\"%d\",line=\"%d\"}...]" + const CMICmnMIValueResult miValueResult("lines", miValueList); + const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult); + m_miResultRecord = miRecordResult; + } + + return MIstatus::success; +} + +//++ ------------------------------------------------------------------------------------ +// Details: Required by the CMICmdFactory when registering *this command. The factory +// calls this function to create an instance of *this command. +// Type: Static method. +// Args: None. +// Return: CMICmdBase * - Pointer to a new command. +// Throws: None. +//-- +CMICmdBase * +CMICmdCmdSymbolListLines::CreateSelf(void) +{ + return new CMICmdCmdSymbolListLines(); +} diff --git a/lldb/tools/lldb-mi/MICmdCmdSymbol.h b/lldb/tools/lldb-mi/MICmdCmdSymbol.h new file mode 100644 index 00000000000..1f0bd1656c4 --- /dev/null +++ b/lldb/tools/lldb-mi/MICmdCmdSymbol.h @@ -0,0 +1,67 @@ +//===-- MICmdCmdSymbol.h ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +//++ +// File: MICmdCmdSymbol.h +// +// Overview: CMICmdCmdSymbolListLines interface. +// +// To implement new MI commands derive a new command class from the command base +// class. To enable the new command for interpretation add the new command class +// to the command factory. The files of relevance are: +// MICmdCommands.cpp +// MICmdBase.h / .cpp +// MICmdCmd.h / .cpp +// For an introduction to adding a new command see CMICmdCmdSupportInfoMiCmdQuery +// command class as an example. +// +// Environment: Compilers: Visual C++ 12. +// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 +// Libraries: See MIReadmetxt. +// +// Copyright: None. +//-- + +#pragma once + +// Third party headers: +#include <lldb/API/SBCommandReturnObject.h> + +// In-house headers: +#include "MICmdBase.h" + +//++ ============================================================================ +// Details: MI command class. MI commands derived from the command base class. +// *this class implements MI command "symbol-list-lines". +//-- +class CMICmdCmdSymbolListLines : public CMICmdBase +{ + // Statics: + public: + // Required by the CMICmdFactory when registering *this command + static CMICmdBase *CreateSelf(void); + + // Methods: + public: + /* ctor */ CMICmdCmdSymbolListLines(void); + + // Overridden: + public: + // From CMICmdInvoker::ICmd + virtual bool Execute(void); + virtual bool Acknowledge(void); + virtual bool ParseArgs(void); + // From CMICmnBase + /* dtor */ virtual ~CMICmdCmdSymbolListLines(void); + + // Attributes: + private: + lldb::SBCommandReturnObject m_lldbResult; + const CMIUtilString m_constStrArgNameFile; +}; diff --git a/lldb/tools/lldb-mi/MICmdCommands.cpp b/lldb/tools/lldb-mi/MICmdCommands.cpp index b9abfd5068b..a2e10d1a2c4 100644 --- a/lldb/tools/lldb-mi/MICmdCommands.cpp +++ b/lldb/tools/lldb-mi/MICmdCommands.cpp @@ -42,6 +42,7 @@ #include "MICmdCmdStack.h" #include "MICmdCmdSupportInfo.h" #include "MICmdCmdSupportList.h" +#include "MICmdCmdSymbol.h" #include "MICmdCmdTarget.h" #include "MICmdCmdThread.h" #include "MICmdCmdTrace.h" @@ -123,6 +124,7 @@ MICmnCommands::RegisterAll(void) bOk &= Register<CMICmdCmdStackListLocals>(); bOk &= Register<CMICmdCmdStackSelectFrame>(); bOk &= Register<CMICmdCmdSupportListFeatures>(); + bOk &= Register<CMICmdCmdSymbolListLines>(); bOk &= Register<CMICmdCmdTargetSelect>(); bOk &= Register<CMICmdCmdThreadInfo>(); bOk &= Register<CMICmdCmdVarAssign>(); diff --git a/lldb/tools/lldb-mi/MIUtilString.cpp b/lldb/tools/lldb-mi/MIUtilString.cpp index 70294285d9f..599b18b0397 100644 --- a/lldb/tools/lldb-mi/MIUtilString.cpp +++ b/lldb/tools/lldb-mi/MIUtilString.cpp @@ -308,6 +308,19 @@ CMIUtilString::SplitConsiderQuotes(const CMIUtilString &vDelimiter, VecString_t } //++ ------------------------------------------------------------------------------------ +// Details: Split string into lines using \n and return an array of strings. +// Type: Method. +// Args: vwVecSplits - (W) Container of splits found in string data. +// Return: MIuint - Number of splits found in the string data. +// Throws: None. +//-- +MIuint +CMIUtilString::SplitLines(VecString_t &vwVecSplits) const +{ + return Split("\n", vwVecSplits); +} + +//++ ------------------------------------------------------------------------------------ // Details: Remove '\n' from the end of string if found. It does not alter // *this string. // Type: Method. diff --git a/lldb/tools/lldb-mi/MIUtilString.h b/lldb/tools/lldb-mi/MIUtilString.h index c30dca3d7b4..37f3092441b 100644 --- a/lldb/tools/lldb-mi/MIUtilString.h +++ b/lldb/tools/lldb-mi/MIUtilString.h @@ -63,6 +63,7 @@ class CMIUtilString : public std::string CMIUtilString RemoveRepeatedCharacters(const MIchar vChar); MIuint Split(const CMIUtilString &vDelimiter, VecString_t &vwVecSplits) const; MIuint SplitConsiderQuotes(const CMIUtilString &vDelimiter, VecString_t &vwVecSplits) const; + MIuint SplitLines(VecString_t &vwVecSplits) const; CMIUtilString StripCREndOfLine(void) const; CMIUtilString StripCRAll(void) const; CMIUtilString Trim(void) const; |