Index: include/lldb/API/SBDefines.h =================================================================== --- include/lldb/API/SBDefines.h +++ include/lldb/API/SBDefines.h @@ -55,6 +55,7 @@ class LLDB_API SBHostOS; class LLDB_API SBInstruction; class LLDB_API SBInstructionList; +class LLDB_API SBLanguageRuntime; class LLDB_API SBLaunchInfo; class LLDB_API SBLineEntry; class LLDB_API SBListener; Index: include/lldb/API/SBLanguageRuntime.h =================================================================== --- /dev/null +++ include/lldb/API/SBLanguageRuntime.h @@ -0,0 +1,29 @@ +//===-- SBLanguageRuntime.h -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_SBLanguageRuntime_h_ +#define LLDB_SBLanguageRuntime_h_ + +#include "lldb/API/SBDefines.h" + +namespace lldb { + +class SBLanguageRuntime +{ +public: + static lldb::LanguageType + GetLanguageTypeFromString (const char *string); + + static const char * + GetNameForLanguageType (lldb::LanguageType language); +}; + +} // namespace lldb + +#endif // LLDB_SBLanguageRuntime_h_ Index: scripts/Python/build-swig-Python.sh =================================================================== --- scripts/Python/build-swig-Python.sh +++ scripts/Python/build-swig-Python.sh @@ -100,6 +100,7 @@ " ${SRC_ROOT}/include/lldb/API/SBHostOS.h"\ " ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\ " ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\ +" ${SRC_ROOT}/include/lldb/API/SBLanguageRuntime.h"\ " ${SRC_ROOT}/include/lldb/API/SBLaunchInfo.h"\ " ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\ " ${SRC_ROOT}/include/lldb/API/SBListener.h"\ @@ -154,6 +155,7 @@ " ${SRC_ROOT}/scripts/interface/SBHostOS.i"\ " ${SRC_ROOT}/scripts/interface/SBInstruction.i"\ " ${SRC_ROOT}/scripts/interface/SBInstructionList.i"\ +" ${SRC_ROOT}/scripts/interface/SBLanguageRuntime.i"\ " ${SRC_ROOT}/scripts/interface/SBLaunchInfo.i"\ " ${SRC_ROOT}/scripts/interface/SBLineEntry.i"\ " ${SRC_ROOT}/scripts/interface/SBListener.i"\ Index: scripts/Python/buildSwigPython.py =================================================================== --- scripts/Python/buildSwigPython.py +++ scripts/Python/buildSwigPython.py @@ -97,6 +97,7 @@ "/include/lldb/API/SBInputReader.h", "/include/lldb/API/SBInstruction.h", "/include/lldb/API/SBInstructionList.h", + "/include/lldb/API/SBLanguageRuntime.h", "/include/lldb/API/SBLaunchInfo.h", "/include/lldb/API/SBLineEntry.h", "/include/lldb/API/SBListener.h", @@ -175,6 +176,7 @@ "/scripts/interface/SBInputReader.i", "/scripts/interface/SBInstruction.i", "/scripts/interface/SBInstructionList.i", + "/scripts/interface/SBLanguageRuntime.i", "/scripts/interface/SBLaunchInfo.i", "/scripts/interface/SBLineEntry.i", "/scripts/interface/SBListener.i", Index: scripts/interface/SBLanguageRuntime.i =================================================================== --- /dev/null +++ scripts/interface/SBLanguageRuntime.i @@ -0,0 +1,22 @@ +//===-- SWIG Interface for SBLanguageRuntime --------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +namespace lldb { + +class SBLanguageRuntime +{ +public: + static lldb::LanguageType + GetLanguageTypeFromString (const char *string); + + static const char * + GetNameForLanguageType (lldb::LanguageType language); +}; + +} // namespace lldb Index: scripts/lldb.swig =================================================================== --- scripts/lldb.swig +++ scripts/lldb.swig @@ -76,6 +76,7 @@ #include "lldb/API/SBHostOS.h" #include "lldb/API/SBInstruction.h" #include "lldb/API/SBInstructionList.h" +#include "lldb/API/SBLanguageRuntime.h" #include "lldb/API/SBLaunchInfo.h" #include "lldb/API/SBLineEntry.h" #include "lldb/API/SBListener.h" @@ -153,6 +154,7 @@ %include "./interface/SBHostOS.i" %include "./interface/SBInstruction.i" %include "./interface/SBInstructionList.i" +%include "./interface/SBLanguageRuntime.i" %include "./interface/SBLaunchInfo.i" %include "./interface/SBLineEntry.i" %include "./interface/SBListener.i" Index: source/API/CMakeLists.txt =================================================================== --- source/API/CMakeLists.txt +++ source/API/CMakeLists.txt @@ -33,6 +33,7 @@ SBHostOS.cpp SBInstruction.cpp SBInstructionList.cpp + SBLanguageRuntime.cpp SBLaunchInfo.cpp SBLineEntry.cpp SBListener.cpp Index: source/API/SBLanguageRuntime.cpp =================================================================== --- /dev/null +++ source/API/SBLanguageRuntime.cpp @@ -0,0 +1,26 @@ +//===-- SBLanguageRuntime.cpp -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/API/SBLanguageRuntime.h" +#include "lldb/Target/LanguageRuntime.h" + +using namespace lldb; +using namespace lldb_private; + +lldb::LanguageType +SBLanguageRuntime::GetLanguageTypeFromString (const char *string) +{ + return LanguageRuntime::GetLanguageTypeFromString(string); +} + +const char * +SBLanguageRuntime::GetNameForLanguageType (lldb::LanguageType language) +{ + return LanguageRuntime::GetNameForLanguageType(language); +} Index: test/tools/lldb-mi/TestMiGdbSetShow.py =================================================================== --- test/tools/lldb-mi/TestMiGdbSetShow.py +++ test/tools/lldb-mi/TestMiGdbSetShow.py @@ -98,6 +98,29 @@ @lldbmi_test @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows") + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races + def test_lldbmi_gdb_show_language(self): + """Test that 'lldb-mi --interpreter' can get current language.""" + + 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\"") + + # Test that -gdb-show language gets current language + self.runCmd("-gdb-show language") + self.expect("\^done,value=\"c\+\+\"") + + @lldbmi_test + @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows") @unittest2.expectedFailure("-gdb-set ignores unknown properties") def test_lldbmi_gdb_set_unknown(self): """Test that 'lldb-mi --interpreter' fails when setting an unknown property.""" Index: tools/lldb-mi/MICmdCmdGdbShow.h =================================================================== --- tools/lldb-mi/MICmdCmdGdbShow.h +++ tools/lldb-mi/MICmdCmdGdbShow.h @@ -68,6 +68,7 @@ bool GetOptionFn(const CMIUtilString &vrGdbOptionName, FnGdbOptionPtr &vrwpFn) const; bool OptionFnTargetAsync(const CMIUtilString::VecString_t &vrWords); bool OptionFnPrint(const CMIUtilString::VecString_t &vrWords); + bool OptionFnLanguage(const CMIUtilString::VecString_t &vrWords); bool OptionFnFallback(const CMIUtilString::VecString_t &vrWords); // Attributes: Index: tools/lldb-mi/MICmdCmdGdbShow.cpp =================================================================== --- tools/lldb-mi/MICmdCmdGdbShow.cpp +++ tools/lldb-mi/MICmdCmdGdbShow.cpp @@ -9,6 +9,12 @@ // Overview: CMICmdCmdGdbShow implementation. +// Third party headers: +#include "lldb/API/SBCompileUnit.h" +#include "lldb/API/SBFrame.h" +#include "lldb/API/SBLanguageRuntime.h" +#include "lldb/API/SBThread.h" + // In-house headers: #include "MICmdCmdGdbShow.h" #include "MICmnMIResultRecord.h" @@ -22,6 +28,7 @@ const CMICmdCmdGdbShow::MapGdbOptionNameToFnGdbOptionPtr_t CMICmdCmdGdbShow::ms_mapGdbOptionNameToFnGdbOptionPtr = { {"target-async", &CMICmdCmdGdbShow::OptionFnTargetAsync}, {"print", &CMICmdCmdGdbShow::OptionFnPrint}, + {"language", &CMICmdCmdGdbShow::OptionFnLanguage}, {"fallback", &CMICmdCmdGdbShow::OptionFnFallback}}; //++ ------------------------------------------------------------------------------------ @@ -287,6 +294,31 @@ } //++ ------------------------------------------------------------------------------------ +// Details: Carry out work to complete the GDB show option 'language' to prepare +// and send back the requested information. +// Type: Method. +// Args: vrWords - (R) List of additional parameters used by this option. +// Return: MIstatus::success - Function succeeded. +// MIstatus::failure - Function failed. +// Throws: None. +//-- +bool +CMICmdCmdGdbShow::OptionFnLanguage(const CMIUtilString::VecString_t &vrWords) +{ + MIunused(vrWords); + + // Get current language + CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); + lldb::SBThread sbThread = rSessionInfo.GetProcess().GetSelectedThread(); + const lldb::SBFrame sbFrame = sbThread.GetSelectedFrame(); + lldb::SBCompileUnit sbCompileUnit = sbFrame.GetCompileUnit(); + const lldb::LanguageType eLanguageType = sbCompileUnit.GetLanguage(); + + m_strValue = lldb::SBLanguageRuntime::GetNameForLanguageType(eLanguageType); + return MIstatus::success; +} + +//++ ------------------------------------------------------------------------------------ // Details: Carry out work to complete the GDB show option to prepare and send back the // requested information. // Type: Method.