[Lldb-commits] [lldb] r230008 - Add -symbol-list-lines command (MI)
Ilia K
ki.stfu at gmail.com
Fri Feb 20 05:07:44 PST 2015
Author: ki.stfu
Date: Fri Feb 20 07:07:41 2015
New Revision: 230008
URL: http://llvm.org/viewvc/llvm-project?rev=230008&view=rev
Log:
Add -symbol-list-lines command (MI)
Summary:
Add -symbol-list-lines command + test.
All test passed on OS X.
Reviewers: emaste, abidh, clayborg
Reviewed By: clayborg
Subscribers: lldb-commits, clayborg, abidh, emaste
Differential Revision: http://reviews.llvm.org/D7768
Added:
lldb/trunk/test/tools/lldb-mi/TestMiSymbol.py
lldb/trunk/tools/lldb-mi/MICmdCmdSymbol.cpp
lldb/trunk/tools/lldb-mi/MICmdCmdSymbol.h
Modified:
lldb/trunk/test/tools/lldb-mi/main.c
lldb/trunk/tools/lldb-mi/CMakeLists.txt
lldb/trunk/tools/lldb-mi/MICmdCommands.cpp
lldb/trunk/tools/lldb-mi/MIUtilString.cpp
lldb/trunk/tools/lldb-mi/MIUtilString.h
Added: lldb/trunk/test/tools/lldb-mi/TestMiSymbol.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/TestMiSymbol.py?rev=230008&view=auto
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/TestMiSymbol.py (added)
+++ lldb/trunk/test/tools/lldb-mi/TestMiSymbol.py Fri Feb 20 07:07:41 2015
@@ -0,0 +1,60 @@
+"""
+Test that the lldb-mi driver works with -symbol-xxx commands
+"""
+
+import lldbmi_testcase
+from lldbtest import *
+import unittest2
+
+class MiSymbolTestCase(lldbmi_testcase.MiTestCaseBase):
+
+ @lldbmi_test
+ @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
+ @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
+ @skipIfLinux # llvm.org/pr22411: Failure presumably due to known thread races
+ def test_lldbmi_symbol_list_lines_file(self):
+ """Test that 'lldb-mi --interpreter' works for -symbol-list-lines when file exists."""
+
+ self.spawnLldbMi(args = None)
+
+ # Load executable
+ self.runCmd("-file-exec-and-symbols %s" % self.myexe)
+ self.expect("\^done")
+
+ # Run to main
+ self.runCmd("-break-insert -f main")
+ self.expect("\^done,bkpt={number=\"1\"")
+ self.runCmd("-exec-run")
+ self.expect("\^running")
+ self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+ # Get address of main
+ self.runCmd("-data-evaluate-expression main")
+ self.expect("\^done,value=\"0x[0-9a-f]+\"")
+ main_addr = int(self.child.after.split("\"")[1], 16)
+ main_line = line_number('main.c', '//FUNC_main')
+
+ # Test that -symbol-list-lines works on valid data
+ self.runCmd("-symbol-list-lines main.c")
+ self.expect("\^done,lines=\[\{pc=\"0x0*%x\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"\d+\"\})+\]" % (main_addr, main_line))
+
+ # Test that -symbol-list-lines fails when file doesn't exist
+ self.runCmd("-symbol-list-lines unknown_file")
+ self.expect("\^error,message=\"warning: No source filenames matched 'unknown_file'. error: no source filenames matched any command arguments \"")
+
+ # Test that -symbol-list-lines fails when file is specified using relative path
+ self.runCmd("-symbol-list-lines ./main.c")
+ self.expect("\^error,message=\"warning: No source filenames matched './main.c'. error: no source filenames matched any command arguments \"")
+
+ # Test that -symbol-list-lines works when file is specified using absolute path
+ import os
+ main_file = os.path.join(os.getcwd(), "main.c")
+ self.runCmd("-symbol-list-lines \"%s\"" % main_file)
+ self.expect("\^done,lines=\[\{pc=\"0x0*%x\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"\d+\"\})+\]" % (main_addr, main_line))
+
+ # Test that -symbol-list-lines fails when file doesn't exist
+ self.runCmd("-symbol-list-lines unknown_dir/main.c")
+ self.expect("\^error,message=\"warning: No source filenames matched 'unknown_dir/main.c'. error: no source filenames matched any command arguments \"")
+
+if __name__ == '__main__':
+ unittest2.main()
Modified: lldb/trunk/test/tools/lldb-mi/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/main.c?rev=230008&r1=230007&r2=230008&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/main.c (original)
+++ lldb/trunk/test/tools/lldb-mi/main.c Fri Feb 20 07:07:41 2015
@@ -19,7 +19,7 @@ static int s_MyVar = 4;
const char s_RawData[] = "\x12\x34\x56\x78"; //FIXME static const char s_RawData[] = "\x12\x34\x56\x78";
int main (int argc, char const *argv[])
-{
+{ //FUNC_main
int a, b;
printf("argc=%d\n", argc); //BP_printf_call
//BP_argctest
Modified: lldb/trunk/tools/lldb-mi/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/CMakeLists.txt?rev=230008&r1=230007&r2=230008&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/CMakeLists.txt (original)
+++ lldb/trunk/tools/lldb-mi/CMakeLists.txt Fri Feb 20 07:07:41 2015
@@ -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
Added: lldb/trunk/tools/lldb-mi/MICmdCmdSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdSymbol.cpp?rev=230008&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdSymbol.cpp (added)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdSymbol.cpp Fri Feb 20 07:07:41 2015
@@ -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();
+}
Added: lldb/trunk/tools/lldb-mi/MICmdCmdSymbol.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdSymbol.h?rev=230008&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdSymbol.h (added)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdSymbol.h Fri Feb 20 07:07:41 2015
@@ -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;
+};
Modified: lldb/trunk/tools/lldb-mi/MICmdCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCommands.cpp?rev=230008&r1=230007&r2=230008&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCommands.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCommands.cpp Fri Feb 20 07:07:41 2015
@@ -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>();
Modified: lldb/trunk/tools/lldb-mi/MIUtilString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilString.cpp?rev=230008&r1=230007&r2=230008&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilString.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MIUtilString.cpp Fri Feb 20 07:07:41 2015
@@ -308,6 +308,19 @@ CMIUtilString::SplitConsiderQuotes(const
}
//++ ------------------------------------------------------------------------------------
+// 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.
Modified: lldb/trunk/tools/lldb-mi/MIUtilString.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilString.h?rev=230008&r1=230007&r2=230008&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilString.h (original)
+++ lldb/trunk/tools/lldb-mi/MIUtilString.h Fri Feb 20 07:07:41 2015
@@ -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;
More information about the lldb-commits
mailing list