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 SBLineEntry; class LLDB_API SBListener; class LLDB_API SBModule; 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: 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.