|
| 1 | +//===-- MICmdCmdSymbol.cpp --------------------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// The LLVM Compiler Infrastructure |
| 4 | +// |
| 5 | +// This file is distributed under the University of Illinois Open Source |
| 6 | +// License. See LICENSE.TXT for details. |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +//++ |
| 11 | +// File: MICmdCmdSymbol.cpp |
| 12 | +// |
| 13 | +// Overview: CMICmdCmdSymbolListLines implementation. |
| 14 | +// |
| 15 | +// Environment: Compilers: Visual C++ 12. |
| 16 | +// gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 |
| 17 | +// Libraries: See MIReadmetxt. |
| 18 | +// |
| 19 | +// Copyright: None. |
| 20 | +//-- |
| 21 | + |
| 22 | +// Third Party Headers: |
| 23 | +#include <lldb/API/SBCommandInterpreter.h> |
| 24 | + |
| 25 | +// In-house headers: |
| 26 | +#include "MICmdArgValFile.h" |
| 27 | +#include "MICmdCmdSymbol.h" |
| 28 | +#include "MICmnLLDBDebugSessionInfo.h" |
| 29 | +#include "MICmnMIResultRecord.h" |
| 30 | +#include "MICmnMIValueList.h" |
| 31 | +#include "MICmnMIValueTuple.h" |
| 32 | + |
| 33 | +//++ ------------------------------------------------------------------------------------ |
| 34 | +// Details: CMICmdCmdSymbolListLines constructor. |
| 35 | +// Type: Method. |
| 36 | +// Args: None. |
| 37 | +// Return: None. |
| 38 | +// Throws: None. |
| 39 | +//-- |
| 40 | +CMICmdCmdSymbolListLines::CMICmdCmdSymbolListLines(void) |
| 41 | + : m_constStrArgNameFile("file") |
| 42 | +{ |
| 43 | + // Command factory matches this name with that received from the stdin stream |
| 44 | + m_strMiCmd = "symbol-list-lines"; |
| 45 | + |
| 46 | + // Required by the CMICmdFactory when registering *this command |
| 47 | + m_pSelfCreatorFn = &CMICmdCmdSymbolListLines::CreateSelf; |
| 48 | +} |
| 49 | + |
| 50 | +//++ ------------------------------------------------------------------------------------ |
| 51 | +// Details: CMICmdCmdSymbolListLines destructor. |
| 52 | +// Type: Overrideable. |
| 53 | +// Args: None. |
| 54 | +// Return: None. |
| 55 | +// Throws: None. |
| 56 | +//-- |
| 57 | +CMICmdCmdSymbolListLines::~CMICmdCmdSymbolListLines(void) |
| 58 | +{ |
| 59 | +} |
| 60 | + |
| 61 | +//++ ------------------------------------------------------------------------------------ |
| 62 | +// Details: The invoker requires this function. The parses the command line options |
| 63 | +// arguments to extract values for each of those arguments. |
| 64 | +// Type: Overridden. |
| 65 | +// Args: None. |
| 66 | +// Return: MIstatus::success - Functional succeeded. |
| 67 | +// MIstatus::failure - Functional failed. |
| 68 | +// Throws: None. |
| 69 | +//-- |
| 70 | +bool |
| 71 | +CMICmdCmdSymbolListLines::ParseArgs(void) |
| 72 | +{ |
| 73 | + bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValFile(m_constStrArgNameFile, true, true))); |
| 74 | + return (bOk && ParseValidateCmdOptions()); |
| 75 | +} |
| 76 | + |
| 77 | +//++ ------------------------------------------------------------------------------------ |
| 78 | +// Details: The invoker requires this function. The command does work in this function. |
| 79 | +// The command is likely to communicate with the LLDB SBDebugger in here. |
| 80 | +// Synopsis: -symbol-list-lines file |
| 81 | +// Ref: http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Symbol-Query.html#GDB_002fMI-Symbol-Query |
| 82 | +// Type: Overridden. |
| 83 | +// Args: None. |
| 84 | +// Return: MIstatus::success - Functional succeeded. |
| 85 | +// MIstatus::failure - Functional failed. |
| 86 | +// Throws: None. |
| 87 | +//-- |
| 88 | +bool |
| 89 | +CMICmdCmdSymbolListLines::Execute(void) |
| 90 | +{ |
| 91 | + CMICMDBASE_GETOPTION(pArgFile, File, m_constStrArgNameFile); |
| 92 | + |
| 93 | + const CMIUtilString &strFilePath(pArgFile->GetValue()); |
| 94 | + const CMIUtilString strCmd(CMIUtilString::Format("target modules dump line-table \"%s\"", strFilePath.c_str())); |
| 95 | + |
| 96 | + CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); |
| 97 | + const lldb::ReturnStatus rtn = rSessionInfo.GetDebugger().GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult); |
| 98 | + MIunused(rtn); |
| 99 | + |
| 100 | + return MIstatus::success; |
| 101 | +} |
| 102 | + |
| 103 | +//++ ------------------------------------------------------------------------------------ |
| 104 | +// Details: The invoker requires this function. The command prepares a MI Record Result |
| 105 | +// for the work carried out in the Execute(). |
| 106 | +// Type: Overridden. |
| 107 | +// Args: None. |
| 108 | +// Return: MIstatus::success - Functional succeeded. |
| 109 | +// MIstatus::failure - Functional failed. |
| 110 | +// Throws: None. |
| 111 | +//-- |
| 112 | +bool |
| 113 | +CMICmdCmdSymbolListLines::Acknowledge(void) |
| 114 | +{ |
| 115 | + if (m_lldbResult.GetErrorSize() > 0) |
| 116 | + { |
| 117 | + const MIchar *pLldbErr = m_lldbResult.GetError(); |
| 118 | + const CMIUtilString strMsg(CMIUtilString(pLldbErr).StripCRAll()); |
| 119 | + const CMICmnMIValueConst miValueConst(strMsg); |
| 120 | + const CMICmnMIValueResult miValueResult("message", miValueConst); |
| 121 | + const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult); |
| 122 | + m_miResultRecord = miRecordResult; |
| 123 | + } |
| 124 | + else |
| 125 | + { |
| 126 | + CMIUtilString::VecString_t vecLines; |
| 127 | + const CMIUtilString strLldbMsg(m_lldbResult.GetOutput()); |
| 128 | + const MIuint nLines(strLldbMsg.SplitLines(vecLines)); |
| 129 | + |
| 130 | + CMICmnMIValueList miValueList(true); |
| 131 | + for (MIuint i = 1; i < nLines; ++i) |
| 132 | + { |
| 133 | + // String looks like: |
| 134 | + // 0x0000000100000e70: /path/to/file:3[:4] |
| 135 | + const CMIUtilString &rLine(vecLines[i]); |
| 136 | + |
| 137 | + // 0x0000000100000e70: /path/to/file:3[:4] |
| 138 | + // ^^^^^^^^^^^^^^^^^^ -- pc |
| 139 | + const MIuint nAddrEndPos = rLine.find(':'); |
| 140 | + const CMIUtilString strAddr(rLine.substr(0, nAddrEndPos).c_str()); |
| 141 | + const CMICmnMIValueConst miValueConst(strAddr); |
| 142 | + const CMICmnMIValueResult miValueResult("pc", miValueConst); |
| 143 | + CMICmnMIValueTuple miValueTuple(miValueResult); |
| 144 | + |
| 145 | + // 0x0000000100000e70: /path/to/file:3[:4] |
| 146 | + // ^ -- line |
| 147 | + const MIuint nLineOrColumnStartPos = rLine.rfind(':'); |
| 148 | + const CMIUtilString strLineOrColumn(rLine.substr(nLineOrColumnStartPos + 1).c_str()); |
| 149 | + const MIuint nPathOrLineStartPos = rLine.rfind(':', nLineOrColumnStartPos - 1); |
| 150 | + const MIuint nPathOrLineLen = nLineOrColumnStartPos - nPathOrLineStartPos - 1; |
| 151 | + const CMIUtilString strPathOrLine(rLine.substr(nPathOrLineStartPos + 1, nPathOrLineLen).c_str()); |
| 152 | + const CMIUtilString strLine(strPathOrLine.IsNumber() ? strPathOrLine : strLineOrColumn); |
| 153 | + const CMICmnMIValueConst miValueConst2(strLine); |
| 154 | + const CMICmnMIValueResult miValueResult2("line", miValueConst2); |
| 155 | + bool bOk = miValueTuple.Add(miValueResult2); |
| 156 | + |
| 157 | + bOk = bOk && miValueList.Add(miValueTuple); |
| 158 | + if (!bOk) |
| 159 | + return MIstatus::failure; |
| 160 | + } |
| 161 | + |
| 162 | + // MI print "%s^done,lines=[{pc=\"%d\",line=\"%d\"}...]" |
| 163 | + const CMICmnMIValueResult miValueResult("lines", miValueList); |
| 164 | + const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult); |
| 165 | + m_miResultRecord = miRecordResult; |
| 166 | + } |
| 167 | + |
| 168 | + return MIstatus::success; |
| 169 | +} |
| 170 | + |
| 171 | +//++ ------------------------------------------------------------------------------------ |
| 172 | +// Details: Required by the CMICmdFactory when registering *this command. The factory |
| 173 | +// calls this function to create an instance of *this command. |
| 174 | +// Type: Static method. |
| 175 | +// Args: None. |
| 176 | +// Return: CMICmdBase * - Pointer to a new command. |
| 177 | +// Throws: None. |
| 178 | +//-- |
| 179 | +CMICmdBase * |
| 180 | +CMICmdCmdSymbolListLines::CreateSelf(void) |
| 181 | +{ |
| 182 | + return new CMICmdCmdSymbolListLines(); |
| 183 | +} |
0 commit comments