diff options
author | emaste <emaste@FreeBSD.org> | 2015-02-09 01:44:09 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2015-02-09 01:44:09 +0000 |
commit | d61b076ede88b56f3372a55e7d1eac6a9d717120 (patch) | |
tree | a8f4b3abea3e6937e60728991c736e6e3d322fc1 /tools | |
parent | 0c2019f4ca6b2dc6d710f6bb16a0e3ed10271531 (diff) | |
download | FreeBSD-src-d61b076ede88b56f3372a55e7d1eac6a9d717120.zip FreeBSD-src-d61b076ede88b56f3372a55e7d1eac6a9d717120.tar.gz |
Import LLDB as of upstream SVN 228549 (git 39760838)
Diffstat (limited to 'tools')
42 files changed, 953 insertions, 472 deletions
diff --git a/tools/compact-unwind/compact-unwind-dumper.c b/tools/compact-unwind/compact-unwind-dumper.c index fd8ea21..0f898db 100644 --- a/tools/compact-unwind/compact-unwind-dumper.c +++ b/tools/compact-unwind/compact-unwind-dumper.c @@ -495,7 +495,14 @@ print_encoding_x86_64 (struct baton baton, uint8_t *function_start, uint32_t enc printf ("large stack "); } - printf ("frameless function: stack size %d, register count %d ", stack_size * 8, register_count); + if (mode == UNWIND_X86_64_MODE_STACK_IND) + { + printf ("frameless function: stack size %d, register count %d ", stack_size * 8, register_count); + } + else + { + printf ("frameless function: stack size %d, register count %d ", stack_size, register_count); + } if (register_count == 0) { @@ -591,7 +598,14 @@ print_encoding_x86_64 (struct baton baton, uint8_t *function_start, uint32_t enc } - printf (" CFA is rsp+%d ", stack_size * 8); + if (mode == UNWIND_X86_64_MODE_STACK_IND) + { + printf (" CFA is rsp+%d ", stack_size); + } + else + { + printf (" CFA is rsp+%d ", stack_size * 8); + } uint32_t saved_registers_offset = 1; printf (" rip=[CFA-%d]", saved_registers_offset * 8); @@ -605,24 +619,29 @@ print_encoding_x86_64 (struct baton baton, uint8_t *function_start, uint32_t enc break; case UNWIND_X86_64_REG_RBX: printf (" rbx=[CFA-%d]", saved_registers_offset * 8); + saved_registers_offset++; break; case UNWIND_X86_64_REG_R12: printf (" r12=[CFA-%d]", saved_registers_offset * 8); + saved_registers_offset++; break; case UNWIND_X86_64_REG_R13: printf (" r13=[CFA-%d]", saved_registers_offset * 8); + saved_registers_offset++; break; case UNWIND_X86_64_REG_R14: printf (" r14=[CFA-%d]", saved_registers_offset * 8); + saved_registers_offset++; break; case UNWIND_X86_64_REG_R15: printf (" r15=[CFA-%d]", saved_registers_offset * 8); + saved_registers_offset++; break; case UNWIND_X86_64_REG_RBP: printf (" rbp=[CFA-%d]", saved_registers_offset * 8); + saved_registers_offset++; break; } - saved_registers_offset++; } } @@ -712,7 +731,14 @@ print_encoding_i386 (struct baton baton, uint8_t *function_start, uint32_t encod printf ("large stack "); } - printf ("frameless function: stack size %d, register count %d ", stack_size * 4, register_count); + if (mode == UNWIND_X86_MODE_STACK_IND) + { + printf ("frameless function: stack size %d, register count %d ", stack_size, register_count); + } + else + { + printf ("frameless function: stack size %d, register count %d ", stack_size * 4, register_count); + } if (register_count == 0) { @@ -808,7 +834,14 @@ print_encoding_i386 (struct baton baton, uint8_t *function_start, uint32_t encod } - printf (" CFA is esp+%d ", stack_size * 4); + if (mode == UNWIND_X86_MODE_STACK_IND) + { + printf (" CFA is esp+%d ", stack_size); + } + else + { + printf (" CFA is esp+%d ", stack_size * 4); + } uint32_t saved_registers_offset = 1; printf (" eip=[CFA-%d]", saved_registers_offset * 4); @@ -822,24 +855,29 @@ print_encoding_i386 (struct baton baton, uint8_t *function_start, uint32_t encod break; case UNWIND_X86_REG_EBX: printf (" ebx=[CFA-%d]", saved_registers_offset * 4); + saved_registers_offset++; break; case UNWIND_X86_REG_ECX: printf (" ecx=[CFA-%d]", saved_registers_offset * 4); + saved_registers_offset++; break; case UNWIND_X86_REG_EDX: printf (" edx=[CFA-%d]", saved_registers_offset * 4); + saved_registers_offset++; break; case UNWIND_X86_REG_EDI: printf (" edi=[CFA-%d]", saved_registers_offset * 4); + saved_registers_offset++; break; case UNWIND_X86_REG_ESI: printf (" esi=[CFA-%d]", saved_registers_offset * 4); + saved_registers_offset++; break; case UNWIND_X86_REG_EBP: printf (" ebp=[CFA-%d]", saved_registers_offset * 4); + saved_registers_offset++; break; } - saved_registers_offset++; } } diff --git a/tools/lldb-mi/Driver.cpp b/tools/lldb-mi/Driver.cpp index 34a2471..2a90763 100644 --- a/tools/lldb-mi/Driver.cpp +++ b/tools/lldb-mi/Driver.cpp @@ -27,17 +27,17 @@ #ifdef _MSC_VER #include <lldb\Host\windows\getopt\GetOptInc.h> #endif // _MSC_VER -#include <lldb/API/SBBreakpoint.h> -#include <lldb/API/SBCommandInterpreter.h> -#include <lldb/API/SBCommandReturnObject.h> -#include <lldb/API/SBCommunication.h> -#include <lldb/API/SBEvent.h> -#include <lldb/API/SBHostOS.h> -#include <lldb/API/SBListener.h> -#include <lldb/API/SBStream.h> -#include <lldb/API/SBTarget.h> -#include <lldb/API/SBThread.h> -#include <lldb/API/SBProcess.h> +#include "lldb/API/SBBreakpoint.h" +#include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBCommandReturnObject.h" +#include "lldb/API/SBCommunication.h" +#include "lldb/API/SBEvent.h" +#include "lldb/API/SBHostOS.h" +#include "lldb/API/SBListener.h" +#include "lldb/API/SBStream.h" +#include "lldb/API/SBTarget.h" +#include "lldb/API/SBThread.h" +#include "lldb/API/SBProcess.h" using namespace lldb; diff --git a/tools/lldb-mi/Driver.h b/tools/lldb-mi/Driver.h index 41fc21d..5bc9738 100644 --- a/tools/lldb-mi/Driver.h +++ b/tools/lldb-mi/Driver.h @@ -15,17 +15,17 @@ #define lldb_Driver_h_ //#include "Platform.h" // IOR removed -#include <lldb/Utility/PseudoTerminal.h> +#include "lldb/Utility/PseudoTerminal.h" #include <set> #include <bitset> #include <string> #include <vector> -#include <lldb/API/SBDefines.h> -#include <lldb/API/SBBroadcaster.h> -#include <lldb/API/SBDebugger.h> -#include <lldb/API/SBError.h> +#include "lldb/API/SBDefines.h" +#include "lldb/API/SBBroadcaster.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBError.h" #include "MIDriverMgr.h" #include "MIDriverBase.h" diff --git a/tools/lldb-mi/MICmdArgValConsume.cpp b/tools/lldb-mi/MICmdArgValConsume.cpp index 3a01db4..0410055 100644 --- a/tools/lldb-mi/MICmdArgValConsume.cpp +++ b/tools/lldb-mi/MICmdArgValConsume.cpp @@ -73,31 +73,22 @@ CMICmdArgValConsume::Validate(CMICmdArgContext &vwArgContext) if (vwArgContext.IsEmpty()) return MIstatus::success; - if (vwArgContext.GetNumberArgsPresent() == 1) - { - const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse()); - m_bFound = true; - m_bValid = true; - vwArgContext.RemoveArg(rArg); - return MIstatus::success; - } - - // In reality there are more than one option, if so the file option - // is the last one (don't handle that here - find the best looking one) + // Consume the optional file, line, linenum arguments till the mode '--' argument const CMIUtilString::VecString_t vecOptions(vwArgContext.GetArgs()); CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); while (it != vecOptions.end()) { - const CMIUtilString &rTxt(*it); - m_bFound = true; - - if (vwArgContext.RemoveArg(rTxt)) + const CMIUtilString & rTxt( *it ); + + if ( rTxt.compare( "--" ) == 0 ) { + m_bFound = true; m_bValid = true; - return MIstatus::success; - } - else - return MIstatus::success; + return MIstatus::success; + } + + if ( !vwArgContext.RemoveArg( rTxt ) ) + return MIstatus::failure; // Next ++it; diff --git a/tools/lldb-mi/MICmdCmd.h b/tools/lldb-mi/MICmdCmd.h index b51318f..1fd3630 100644 --- a/tools/lldb-mi/MICmdCmd.h +++ b/tools/lldb-mi/MICmdCmd.h @@ -38,8 +38,8 @@ MI commands implemented are: // Third party headers: #include <vector> -#include <lldb/API/SBBreakpoint.h> -#include <lldb/API/SBCommandReturnObject.h> +#include "lldb/API/SBBreakpoint.h" +#include "lldb/API/SBCommandReturnObject.h" // In-house headers: #include "MICmdBase.h" diff --git a/tools/lldb-mi/MICmdCmdBreak.cpp b/tools/lldb-mi/MICmdCmdBreak.cpp index c338cf0..9ad7ea3 100644 --- a/tools/lldb-mi/MICmdCmdBreak.cpp +++ b/tools/lldb-mi/MICmdCmdBreak.cpp @@ -25,7 +25,7 @@ //-- // Third Party Headers: -#include <lldb/API/SBBreakpointLocation.h> +#include "lldb/API/SBBreakpointLocation.h" // In-house headers: #include "MICmdCmdBreak.h" @@ -180,19 +180,16 @@ CMICmdCmdBreakInsert::Execute(void) CMIUtilString fileName; MIuint nFileLine = 0; CMIUtilString strFileFn; - const MIint nPosColon = m_brkName.find(cColon); - if (nPosColon != (MIint)std::string::npos) + CMIUtilString rStrLineOrFn; + // Full path in windows can have : after drive letter. So look for the + // last colon + const size_t nPosColon = m_brkName.find_last_of(cColon); + if (nPosColon != std::string::npos) { - CMIUtilString::VecString_t vecFileAndLocation; - const MIuint nSplits = m_brkName.Split(cColon, vecFileAndLocation); - MIunused(nSplits); - if (vecFileAndLocation.size() != 2) - { - SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_BRKPT_LOCATION_FORMAT), m_cmdData.strMiCmd.c_str(), m_brkName.c_str())); - return MIstatus::failure; - } - fileName = vecFileAndLocation.at(0); - const CMIUtilString &rStrLineOrFn(vecFileAndLocation.at(1)); + // extract file name and line number from it + fileName = m_brkName.substr(0, nPosColon); + rStrLineOrFn = m_brkName.substr(nPosColon + 1, m_brkName.size() - nPosColon - 1); + if (rStrLineOrFn.empty()) eBrkPtType = eBreakPoint_ByName; else @@ -232,20 +229,20 @@ CMICmdCmdBreakInsert::Execute(void) // Ask LLDB to create a breakpoint bool bOk = MIstatus::success; CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBTarget &rTarget = rSessionInfo.m_lldbTarget; + lldb::SBTarget sbTarget = rSessionInfo.GetTarget(); switch (eBrkPtType) { case eBreakPoint_ByAddress: - m_brkPt = rTarget.BreakpointCreateByAddress(nAddress); + m_brkPt = sbTarget.BreakpointCreateByAddress(nAddress); break; case eBreakPoint_ByFileFn: - m_brkPt = rTarget.BreakpointCreateByName(strFileFn.c_str(), fileName.c_str()); + m_brkPt = sbTarget.BreakpointCreateByName(strFileFn.c_str(), fileName.c_str()); break; case eBreakPoint_ByFileLine: - m_brkPt = rTarget.BreakpointCreateByLocation(fileName.c_str(), nFileLine); + m_brkPt = sbTarget.BreakpointCreateByLocation(fileName.c_str(), nFileLine); break; case eBreakPoint_ByName: - m_brkPt = rTarget.BreakpointCreateByName(m_brkName.c_str(), rTarget.GetExecutable().GetFilename()); + m_brkPt = sbTarget.BreakpointCreateByName(m_brkName.c_str(), sbTarget.GetExecutable().GetFilename()); break; case eBreakPoint_count: case eBreakPoint_NotDefineYet: @@ -327,7 +324,7 @@ CMICmdCmdBreakInsert::Acknowledge(void) sBrkPtInfo.m_bEnabled = m_bBrkPtEnabled; sBrkPtInfo.m_bHaveArgOptionThreadGrp = m_bHaveArgOptionThreadGrp; sBrkPtInfo.m_strOptThrdGrp = m_strArgOptionThreadGrp; - sBrkPtInfo.m_nTimes = m_brkPt.GetNumLocations(); + sBrkPtInfo.m_nTimes = m_brkPt.GetHitCount(); sBrkPtInfo.m_strOrigLoc = m_brkName; sBrkPtInfo.m_nIgnore = m_nBrkPtIgnoreCount; sBrkPtInfo.m_bPending = m_bBrkPtIsPending; @@ -440,7 +437,7 @@ CMICmdCmdBreakDelete::Execute(void) } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - const bool bBrkPt = rSessionInfo.m_lldbTarget.BreakpointDelete(static_cast<lldb::break_id_t>(nBrk)); + const bool bBrkPt = rSessionInfo.GetTarget().BreakpointDelete(static_cast<lldb::break_id_t>(nBrk)); if (!bBrkPt) { const CMIUtilString strBrkNum(CMIUtilString::Format("%d", nBrk)); @@ -560,7 +557,7 @@ CMICmdCmdBreakDisable::Execute(void) } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBBreakpoint brkPt = rSessionInfo.m_lldbTarget.FindBreakpointByID(static_cast<lldb::break_id_t>(nBrk)); + lldb::SBBreakpoint brkPt = rSessionInfo.GetTarget().FindBreakpointByID(static_cast<lldb::break_id_t>(nBrk)); if (brkPt.IsValid()) { m_bBrkPtDisabledOk = true; @@ -700,7 +697,7 @@ CMICmdCmdBreakEnable::Execute(void) } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBBreakpoint brkPt = rSessionInfo.m_lldbTarget.FindBreakpointByID(static_cast<lldb::break_id_t>(nBrk)); + lldb::SBBreakpoint brkPt = rSessionInfo.GetTarget().FindBreakpointByID(static_cast<lldb::break_id_t>(nBrk)); if (brkPt.IsValid()) { m_bBrkPtEnabledOk = true; @@ -837,7 +834,7 @@ CMICmdCmdBreakAfter::Execute(void) m_nBrkPtCount = pArgCount->GetValue(); CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBBreakpoint brkPt = rSessionInfo.m_lldbTarget.FindBreakpointByID(static_cast<lldb::break_id_t>(m_nBrkPtId)); + lldb::SBBreakpoint brkPt = rSessionInfo.GetTarget().FindBreakpointByID(static_cast<lldb::break_id_t>(m_nBrkPtId)); if (brkPt.IsValid()) { brkPt.SetIgnoreCount(m_nBrkPtCount); @@ -972,7 +969,7 @@ CMICmdCmdBreakCondition::Execute(void) m_strBrkPtExpr += GetRestOfExpressionNotSurroundedInQuotes(); CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBBreakpoint brkPt = rSessionInfo.m_lldbTarget.FindBreakpointByID(static_cast<lldb::break_id_t>(m_nBrkPtId)); + lldb::SBBreakpoint brkPt = rSessionInfo.GetTarget().FindBreakpointByID(static_cast<lldb::break_id_t>(m_nBrkPtId)); if (brkPt.IsValid()) { brkPt.SetCondition(m_strBrkPtExpr.c_str()); diff --git a/tools/lldb-mi/MICmdCmdBreak.h b/tools/lldb-mi/MICmdCmdBreak.h index c9540b0..371afa1 100644 --- a/tools/lldb-mi/MICmdCmdBreak.h +++ b/tools/lldb-mi/MICmdCmdBreak.h @@ -36,7 +36,7 @@ #pragma once // Third party headers: -#include <lldb/API/SBBreakpoint.h> +#include "lldb/API/SBBreakpoint.h" // In-house headers: #include "MICmdBase.h" diff --git a/tools/lldb-mi/MICmdCmdData.cpp b/tools/lldb-mi/MICmdCmdData.cpp index e1abe83..92e4190 100644 --- a/tools/lldb-mi/MICmdCmdData.cpp +++ b/tools/lldb-mi/MICmdCmdData.cpp @@ -28,10 +28,10 @@ //-- // Third Party Headers: -#include <lldb/API/SBThread.h> -#include <lldb/API/SBInstruction.h> -#include <lldb/API/SBInstructionList.h> -#include <lldb/API/SBStream.h> +#include "lldb/API/SBThread.h" +#include "lldb/API/SBInstruction.h" +#include "lldb/API/SBInstructionList.h" +#include "lldb/API/SBStream.h" // In-house headers: #include "MICmdCmdData.h" @@ -122,22 +122,22 @@ CMICmdCmdDataEvaluateExpression::Execute(void) const CMIUtilString &rExpression(pArgExpr->GetValue()); CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; - lldb::SBThread thread = rProcess.GetSelectedThread(); + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); + lldb::SBThread thread = sbProcess.GetSelectedThread(); m_bExpressionValid = (thread.GetNumFrames() > 0); if (!m_bExpressionValid) return MIstatus::success; lldb::SBFrame frame = thread.GetSelectedFrame(); lldb::SBValue value = frame.EvaluateExpression(rExpression.c_str()); - if (!value.IsValid()) + if (!value.IsValid() || value.GetError().Fail()) value = frame.FindVariable(rExpression.c_str()); - if (!value.IsValid()) + const CMICmnLLDBUtilSBValue utilValue(value); + if (!utilValue.IsValid() || utilValue.IsValueUnknown()) { m_bEvaluatedExpression = false; return MIstatus::success; } - const CMICmnLLDBUtilSBValue utilValue(value); if (!utilValue.HasName()) { if (HaveInvalidCharacterInExpression(rExpression, m_cExpressionInvalidChar)) @@ -279,16 +279,10 @@ CMICmdCmdDataEvaluateExpression::CreateSelf(void) bool CMICmdCmdDataEvaluateExpression::HaveInvalidCharacterInExpression(const CMIUtilString &vrExpr, MIchar &vrwInvalidChar) { - bool bFoundInvalidCharInExpression = false; - vrwInvalidChar = 0x00; - - if (vrExpr.at(0) == '\\') - { - // Example: Mouse hover over "%5d" expression has \"%5d\" in it - bFoundInvalidCharInExpression = true; - vrwInvalidChar = '\\'; - } - + static const std::string strInvalidCharacters(";#\\"); + const size_t nInvalidCharacterOffset = vrExpr.find_first_of(strInvalidCharacters); + const bool bFoundInvalidCharInExpression = (nInvalidCharacterOffset != CMIUtilString::npos); + vrwInvalidChar = bFoundInvalidCharInExpression ? vrExpr[nInvalidCharacterOffset] : 0x00; return bFoundInvalidCharInExpression; } @@ -342,7 +336,7 @@ bool CMICmdCmdDataDisassemble::ParseArgs(void) { bool bOk = - m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1))); + m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); bOk = bOk && m_setCmdArgs.Add( *(new CMICmdArgValOptionShort(m_constStrArgAddrStart, true, true, CMICmdArgValListBase::eArgValType_StringQuotedNumber, 1))); @@ -373,7 +367,7 @@ CMICmdCmdDataDisassemble::Execute(void) // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; - if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) + if (pArgThread->GetFound() && !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str())); return MIstatus::failure; @@ -410,23 +404,24 @@ CMICmdCmdDataDisassemble::Execute(void) const MIuint nDisasmMode = pArgMode->GetValue(); CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBTarget &rTarget = rSessionInfo.m_lldbTarget; + lldb::SBTarget sbTarget = rSessionInfo.GetTarget(); lldb::addr_t lldbStartAddr = static_cast<lldb::addr_t>(nAddrStart); - lldb::SBInstructionList instructions = rTarget.ReadInstructions(lldb::SBAddress(lldbStartAddr, rTarget), nAddrEnd - nAddrStart); + lldb::SBInstructionList instructions = sbTarget.ReadInstructions(lldb::SBAddress(lldbStartAddr, sbTarget), nAddrEnd - nAddrStart); const MIuint nInstructions = instructions.GetSize(); for (size_t i = 0; i < nInstructions; i++) { const MIchar *pUnknown = "??"; lldb::SBInstruction instrt = instructions.GetInstructionAtIndex(i); - const MIchar *pStrMnemonic = instrt.GetMnemonic(rTarget); + const MIchar *pStrMnemonic = instrt.GetMnemonic(sbTarget); pStrMnemonic = (pStrMnemonic != nullptr) ? pStrMnemonic : pUnknown; lldb::SBAddress address = instrt.GetAddress(); - lldb::addr_t addr = address.GetLoadAddress(rTarget); + lldb::addr_t addr = address.GetLoadAddress(sbTarget); const MIchar *pFnName = address.GetFunction().GetName(); pFnName = (pFnName != nullptr) ? pFnName : pUnknown; lldb::addr_t addrOffSet = address.GetOffset(); - const MIchar *pStrOperands = instrt.GetOperands(rTarget); + const MIchar *pStrOperands = instrt.GetOperands(sbTarget); pStrOperands = (pStrOperands != nullptr) ? pStrOperands : pUnknown; + const size_t instrtSize = instrt.GetByteSize(); // MI "{address=\"0x%08llx\",func-name=\"%s\",offset=\"%lld\",inst=\"%s %s\"}" const CMICmnMIValueConst miValueConst(CMIUtilString::Format("0x%08llx", addr)); @@ -438,9 +433,12 @@ CMICmdCmdDataDisassemble::Execute(void) const CMICmnMIValueConst miValueConst3(CMIUtilString::Format("0x%lld", addrOffSet)); const CMICmnMIValueResult miValueResult3("offset", miValueConst3); miValueTuple.Add(miValueResult3); - const CMICmnMIValueConst miValueConst4(CMIUtilString::Format("%s %s", pStrMnemonic, pStrOperands)); - const CMICmnMIValueResult miValueResult4("inst", miValueConst4); + const CMICmnMIValueConst miValueConst4(CMIUtilString::Format("%d", instrtSize)); + const CMICmnMIValueResult miValueResult4("size", miValueConst4); miValueTuple.Add(miValueResult4); + const CMICmnMIValueConst miValueConst5(CMIUtilString::Format("%s %s", pStrMnemonic, pStrOperands)); + const CMICmnMIValueResult miValueResult5("inst", miValueConst5); + miValueTuple.Add(miValueResult5); if (nDisasmMode == 1) { @@ -599,9 +597,9 @@ CMICmdCmdDataReadMemoryBytes::Execute(void) } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); lldb::SBError error; - const MIuint64 nReadBytes = rProcess.ReadMemory(static_cast<lldb::addr_t>(nAddrStart), (void *)m_pBufferMemory, nAddrNumBytes, error); + const MIuint64 nReadBytes = sbProcess.ReadMemory(static_cast<lldb::addr_t>(nAddrStart), (void *)m_pBufferMemory, nAddrNumBytes, error); if (nReadBytes != nAddrNumBytes) { SetError( @@ -826,30 +824,58 @@ CMICmdCmdDataListRegisterNames::ParseArgs(void) bool CMICmdCmdDataListRegisterNames::Execute(void) { + CMICMDBASE_GETOPTION(pArgRegNo, ListOfN, m_constStrArgRegNo); + CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; - if (!rProcess.IsValid()) + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); + if (!sbProcess.IsValid()) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS), m_cmdData.strMiCmd.c_str())); return MIstatus::failure; } - lldb::SBThread thread = rProcess.GetSelectedThread(); - lldb::SBFrame frame = thread.GetSelectedFrame(); - lldb::SBValueList registers = frame.GetRegisters(); - const MIuint nRegisters = registers.GetSize(); - for (MIuint i = 0; i < nRegisters; i++) + const CMICmdArgValListBase::VecArgObjPtr_t &rVecRegNo(pArgRegNo->GetExpectedOptions()); + if (!rVecRegNo.empty()) { - lldb::SBValue value = registers.GetValueAtIndex(i); - const MIuint nRegChildren = value.GetNumChildren(); - for (MIuint j = 0; j < nRegChildren; j++) + // List of required registers + CMICmdArgValListBase::VecArgObjPtr_t::const_iterator it = rVecRegNo.begin(); + while (it != rVecRegNo.end()) { - lldb::SBValue value2 = value.GetChildAtIndex(j); - if (value2.IsValid()) + const CMICmdArgValNumber *pRegNo = static_cast<CMICmdArgValNumber *>(*it); + const MIuint nRegIndex = pRegNo->GetValue(); + lldb::SBValue regValue = GetRegister(nRegIndex); + if (regValue.IsValid()) { - const CMICmnMIValueConst miValueConst(CMICmnLLDBUtilSBValue(value2).GetName()); + const CMICmnMIValueConst miValueConst(CMICmnLLDBUtilSBValue(regValue).GetName()); m_miValueList.Add(miValueConst); } + + // Next + ++it; + } + } + else + { + // List of all registers + lldb::SBThread thread = sbProcess.GetSelectedThread(); + lldb::SBFrame frame = thread.GetSelectedFrame(); + lldb::SBValueList registers = frame.GetRegisters(); + const MIuint nRegisters = registers.GetSize(); + for (MIuint i = 0; i < nRegisters; i++) + { + lldb::SBValue value = registers.GetValueAtIndex(i); + const MIuint nRegChildren = value.GetNumChildren(); + for (MIuint j = 0; j < nRegChildren; j++) + { + lldb::SBValue regValue = value.GetChildAtIndex(j); + if (regValue.IsValid()) + { + const CMICmnMIValueConst miValueConst(CMICmnLLDBUtilSBValue(regValue).GetName()); + const bool bOk = m_miValueList.Add(miValueConst); + if (!bOk) + return MIstatus::failure; + } + } } } @@ -889,6 +915,42 @@ CMICmdCmdDataListRegisterNames::CreateSelf(void) return new CMICmdCmdDataListRegisterNames(); } +//++ ------------------------------------------------------------------------------------ +// Details: Required by the CMICmdFactory when registering *this command. The factory +// calls this function to create an instance of *this command. +// Type: Method. +// Args: None. +// Return: lldb::SBValue - LLDB SBValue object. +// Throws: None. +//-- +lldb::SBValue +CMICmdCmdDataListRegisterNames::GetRegister(const MIuint vRegisterIndex) const +{ + lldb::SBThread thread = CMICmnLLDBDebugSessionInfo::Instance().GetProcess().GetSelectedThread(); + lldb::SBFrame frame = thread.GetSelectedFrame(); + lldb::SBValueList registers = frame.GetRegisters(); + const MIuint nRegisters = registers.GetSize(); + MIuint nRegisterIndex(vRegisterIndex); + for (MIuint i = 0; i < nRegisters; i++) + { + lldb::SBValue value = registers.GetValueAtIndex(i); + const MIuint nRegChildren = value.GetNumChildren(); + if (nRegisterIndex >= nRegChildren) + { + nRegisterIndex -= nRegChildren; + continue; + } + + lldb::SBValue value2 = value.GetChildAtIndex(nRegisterIndex); + if (value2.IsValid()) + { + return value2; + } + } + + return lldb::SBValue(); +} + //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- @@ -906,7 +968,6 @@ CMICmdCmdDataListRegisterValues::CMICmdCmdDataListRegisterValues(void) , m_constStrArgFormat("fmt") , m_constStrArgRegNo("regno") , m_miValueList(true) - , m_pProcess(nullptr) { // Command factory matches this name with that received from the stdin stream m_strMiCmd = "data-list-register-values"; @@ -975,33 +1036,60 @@ CMICmdCmdDataListRegisterValues::Execute(void) } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; - if (!rProcess.IsValid()) + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); + if (!sbProcess.IsValid()) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PROCESS), m_cmdData.strMiCmd.c_str())); return MIstatus::failure; } - m_pProcess = &rProcess; const CMICmdArgValListBase::VecArgObjPtr_t &rVecRegNo(pArgRegNo->GetExpectedOptions()); - CMICmdArgValListBase::VecArgObjPtr_t::const_iterator it = rVecRegNo.begin(); - while (it != rVecRegNo.end()) + if (!rVecRegNo.empty()) { - const CMICmdArgValNumber *pRegNo = static_cast<CMICmdArgValNumber *>(*it); - const MIuint nReg = pRegNo->GetValue(); - lldb::SBValue regValue = GetRegister(nReg); - const CMIUtilString strRegValue(CMICmnLLDBDebugSessionInfoVarObj::GetValueStringFormatted(regValue, eFormat)); - - const CMICmnMIValueConst miValueConst(CMIUtilString::Format("%u", nReg)); - const CMICmnMIValueResult miValueResult("number", miValueConst); - CMICmnMIValueTuple miValueTuple(miValueResult); - const CMICmnMIValueConst miValueConst2(strRegValue); - const CMICmnMIValueResult miValueResult2("value", miValueConst2); - miValueTuple.Add(miValueResult2); - m_miValueList.Add(miValueTuple); + // List of required registers + CMICmdArgValListBase::VecArgObjPtr_t::const_iterator it = rVecRegNo.begin(); + while (it != rVecRegNo.end()) + { + const CMICmdArgValNumber *pRegNo = static_cast<CMICmdArgValNumber *>(*it); + const MIuint nRegIndex = pRegNo->GetValue(); + lldb::SBValue regValue = GetRegister(nRegIndex); + if (regValue.IsValid()) + { + const bool bOk = AddToOutput(nRegIndex, regValue, eFormat); + if (!bOk) + return MIstatus::failure; + } - // Next - ++it; + // Next + ++it; + } + } + else + { + // No register numbers are provided. Output all registers. + lldb::SBThread thread = sbProcess.GetSelectedThread(); + lldb::SBFrame frame = thread.GetSelectedFrame(); + lldb::SBValueList registers = frame.GetRegisters(); + const MIuint nRegisters = registers.GetSize(); + MIuint nRegIndex = 0; + for (MIuint i = 0; i < nRegisters; i++) + { + lldb::SBValue value = registers.GetValueAtIndex(i); + const MIuint nRegChildren = value.GetNumChildren(); + for (MIuint j = 0; j < nRegChildren; j++) + { + lldb::SBValue regValue = value.GetChildAtIndex(j); + if (regValue.IsValid()) + { + const bool bOk = AddToOutput(nRegIndex, regValue, eFormat); + if (!bOk) + return MIstatus::failure; + } + + // Next + ++nRegIndex; + } + } } return MIstatus::success; @@ -1051,27 +1139,52 @@ CMICmdCmdDataListRegisterValues::CreateSelf(void) lldb::SBValue CMICmdCmdDataListRegisterValues::GetRegister(const MIuint vRegisterIndex) const { - lldb::SBThread thread = m_pProcess->GetSelectedThread(); + lldb::SBThread thread = CMICmnLLDBDebugSessionInfo::Instance().GetProcess().GetSelectedThread(); lldb::SBFrame frame = thread.GetSelectedFrame(); lldb::SBValueList registers = frame.GetRegisters(); const MIuint nRegisters = registers.GetSize(); + MIuint nRegisterIndex(vRegisterIndex); for (MIuint i = 0; i < nRegisters; i++) { lldb::SBValue value = registers.GetValueAtIndex(i); const MIuint nRegChildren = value.GetNumChildren(); - if (nRegChildren > 0) + if (nRegisterIndex >= nRegChildren) { - lldb::SBValue value2 = value.GetChildAtIndex(vRegisterIndex); - if (value2.IsValid()) - { - return value2; - } + nRegisterIndex -= nRegChildren; + continue; + } + + lldb::SBValue value2 = value.GetChildAtIndex(nRegisterIndex); + if (value2.IsValid()) + { + return value2; } } return lldb::SBValue(); } +//++ ------------------------------------------------------------------------------------ +// Details: Adds the register value to the output list. +// Type: Method. +// Args: Value of the register, its index and output format. +// Return: None +// Throws: None. +//-- +bool +CMICmdCmdDataListRegisterValues::AddToOutput(const MIuint vnIndex, const lldb::SBValue &vrValue, + CMICmnLLDBDebugSessionInfoVarObj::varFormat_e veVarFormat) +{ + const CMICmnMIValueConst miValueConst(CMIUtilString::Format("%u", vnIndex)); + const CMICmnMIValueResult miValueResult("number", miValueConst); + CMICmnMIValueTuple miValueTuple(miValueResult); + const CMIUtilString strRegValue(CMICmnLLDBDebugSessionInfoVarObj::GetValueStringFormatted(vrValue, veVarFormat)); + const CMICmnMIValueConst miValueConst2(strRegValue); + const CMICmnMIValueResult miValueResult2("value", miValueConst2); + bool bOk = miValueTuple.Add(miValueResult2); + return bOk && m_miValueList.Add(miValueTuple); +} + //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- @@ -1371,10 +1484,10 @@ CMICmdCmdDataWriteMemory::Execute(void) *m_pBufferMemory = static_cast<MIchar>(nValue); CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); lldb::SBError error; lldb::addr_t addr = static_cast<lldb::addr_t>(m_nAddr + nAddrOffset); - const size_t nBytesWritten = rProcess.WriteMemory(addr, (const void *)m_pBufferMemory, (size_t)m_nCount, error); + const size_t nBytesWritten = sbProcess.WriteMemory(addr, (const void *)m_pBufferMemory, (size_t)m_nCount, error); if (nBytesWritten != static_cast<size_t>(m_nCount)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_LLDB_ERR_NOT_WRITE_WHOLEBLK), m_cmdData.strMiCmd.c_str(), m_nCount, addr)); diff --git a/tools/lldb-mi/MICmdCmdData.h b/tools/lldb-mi/MICmdCmdData.h index 74ceeb8..5084beea 100644 --- a/tools/lldb-mi/MICmdCmdData.h +++ b/tools/lldb-mi/MICmdCmdData.h @@ -42,6 +42,7 @@ #include "MICmdBase.h" #include "MICmnMIValueTuple.h" #include "MICmnMIValueList.h" +#include "MICmnLLDBDebugSessionInfoVarObj.h" //++ ============================================================================ // Details: MI command class. MI commands derived from the command base class. @@ -218,6 +219,10 @@ class CMICmdCmdDataListRegisterNames : public CMICmdBase // From CMICmnBase /* dtor */ virtual ~CMICmdCmdDataListRegisterNames(void); + // Methods: + private: + lldb::SBValue GetRegister(const MIuint vRegisterIndex) const; + // Attributes: private: const CMIUtilString m_constStrArgThreadGroup; // Not specified in MI spec but Eclipse gives this option @@ -255,6 +260,7 @@ class CMICmdCmdDataListRegisterValues : public CMICmdBase // Methods: private: lldb::SBValue GetRegister(const MIuint vRegisterIndex) const; + bool AddToOutput(const MIuint vnIndex, const lldb::SBValue &vrValue, CMICmnLLDBDebugSessionInfoVarObj::varFormat_e veVarFormat); // Attributes: private: @@ -263,7 +269,6 @@ class CMICmdCmdDataListRegisterValues : public CMICmdBase const CMIUtilString m_constStrArgFormat; const CMIUtilString m_constStrArgRegNo; CMICmnMIValueList m_miValueList; - lldb::SBProcess *m_pProcess; }; //++ ============================================================================ diff --git a/tools/lldb-mi/MICmdCmdExec.cpp b/tools/lldb-mi/MICmdCmdExec.cpp index 9e12243..eec62c8 100644 --- a/tools/lldb-mi/MICmdCmdExec.cpp +++ b/tools/lldb-mi/MICmdCmdExec.cpp @@ -27,9 +27,9 @@ //-- // Third Party Headers: -#include <lldb/API/SBCommandInterpreter.h> -#include <lldb/API/SBProcess.h> -#include <lldb/API/SBStream.h> +#include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBStream.h" #include "lldb/lldb-enumerations.h" // In-house headers: @@ -91,8 +91,8 @@ CMICmdCmdExecRun::Execute(void) lldb::SBError error; lldb::SBStream errMsg; uint32_t launch_flags = lldb::LaunchFlags::eLaunchFlagDebug; - lldb::SBProcess process = rSessionInfo.m_lldbTarget.Launch(rSessionInfo.m_rLlldbListener, nullptr, nullptr, nullptr, nullptr, nullptr, - nullptr, launch_flags, false, error); + lldb::SBProcess process = rSessionInfo.GetTarget().Launch(rSessionInfo.GetListener(), nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, launch_flags, false, error); if ((!process.IsValid()) || (error.Fail())) { @@ -100,9 +100,6 @@ CMICmdCmdExecRun::Execute(void) return MIstatus::failure; } - // Save the process in the session info - rSessionInfo.m_lldbProcess = process; - if (!CMIDriver::Instance().SetDriverStateRunningDebugging()) { const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription()); @@ -137,7 +134,7 @@ CMICmdCmdExecRun::Acknowledge(void) m_miResultRecord = miRecordResult; CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::pid_t pid = rSessionInfo.m_lldbProcess.GetProcessID(); + lldb::pid_t pid = rSessionInfo.GetProcess().GetProcessID(); // Give the client '=thread-group-started,id="i1" pid="xyz"' m_bHasResultRecordExtra = true; const CMICmnMIValueConst miValueConst2("i1"); @@ -212,7 +209,7 @@ CMICmdCmdExecContinue::Execute(void) { const MIchar *pCmd = "continue"; CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - const lldb::ReturnStatus rtn = rSessionInfo.m_rLldbDebugger.GetCommandInterpreter().HandleCommand(pCmd, m_lldbResult); + const lldb::ReturnStatus rtn = rSessionInfo.GetDebugger().GetCommandInterpreter().HandleCommand(pCmd, m_lldbResult); MIunused(rtn); if (m_lldbResult.GetErrorSize() == 0) @@ -328,7 +325,7 @@ bool CMICmdCmdExecNext::ParseArgs(void) { bool bOk = - m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1))); + m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgNumber, false, false))); return (bOk && ParseValidateCmdOptions()); } @@ -349,14 +346,14 @@ CMICmdCmdExecNext::Execute(void) // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; - if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) + if (pArgThread->GetFound() && !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_THREAD_INVALID), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str())); return MIstatus::failure; } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger; + lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger(); CMIUtilString strCmd("thread step-over"); if (nThreadId != UINT64_MAX) strCmd += CMIUtilString::Format(" %llu", nThreadId); @@ -455,7 +452,7 @@ bool CMICmdCmdExecStep::ParseArgs(void) { bool bOk = - m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1))); + m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgNumber, false, false))); return (bOk && ParseValidateCmdOptions()); } @@ -476,14 +473,14 @@ CMICmdCmdExecStep::Execute(void) // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; - if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) + if (pArgThread->GetFound() && !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str())); return MIstatus::failure; } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger; + lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger(); CMIUtilString strCmd("thread step-in"); if (nThreadId != UINT64_MAX) strCmd += CMIUtilString::Format(" %llu", nThreadId); @@ -582,7 +579,7 @@ bool CMICmdCmdExecNextInstruction::ParseArgs(void) { bool bOk = - m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1))); + m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgNumber, false, false))); return (bOk && ParseValidateCmdOptions()); } @@ -603,14 +600,14 @@ CMICmdCmdExecNextInstruction::Execute(void) // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; - if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) + if (pArgThread->GetFound() && !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str())); return MIstatus::failure; } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger; + lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger(); CMIUtilString strCmd("thread step-inst-over"); if (nThreadId != UINT64_MAX) strCmd += CMIUtilString::Format(" %llu", nThreadId); @@ -709,7 +706,7 @@ bool CMICmdCmdExecStepInstruction::ParseArgs(void) { bool bOk = - m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1))); + m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgNumber, false, false))); return (bOk && ParseValidateCmdOptions()); } @@ -730,14 +727,14 @@ CMICmdCmdExecStepInstruction::Execute(void) // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; - if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) + if (pArgThread->GetFound() && !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str())); return MIstatus::failure; } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger; + lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger(); CMIUtilString strCmd("thread step-inst"); if (nThreadId != UINT64_MAX) strCmd += CMIUtilString::Format(" %llu", nThreadId); @@ -836,7 +833,7 @@ bool CMICmdCmdExecFinish::ParseArgs(void) { bool bOk = - m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1))); + m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgFrame, false, false, CMICmdArgValListBase::eArgValType_Number, 1))); return (bOk && ParseValidateCmdOptions()); @@ -858,14 +855,14 @@ CMICmdCmdExecFinish::Execute(void) // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; - if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) + if (pArgThread->GetFound() && !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str())); return MIstatus::failure; } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger; + lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger(); CMIUtilString strCmd("thread step-out"); if (nThreadId != UINT64_MAX) strCmd += CMIUtilString::Format(" %llu", nThreadId); @@ -962,7 +959,7 @@ bool CMICmdCmdExecInterrupt::Execute(void) { CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBDebugger &rDebugger = rSessionInfo.m_rLldbDebugger; + lldb::SBDebugger &rDebugger = rSessionInfo.GetDebugger(); CMIUtilString strCmd("process interrupt"); const lldb::ReturnStatus status = rDebugger.GetCommandInterpreter().HandleCommand(strCmd.c_str(), m_lldbResult, false); MIunused(status); diff --git a/tools/lldb-mi/MICmdCmdExec.h b/tools/lldb-mi/MICmdCmdExec.h index cf59ec4..be03d6b 100644 --- a/tools/lldb-mi/MICmdCmdExec.h +++ b/tools/lldb-mi/MICmdCmdExec.h @@ -38,7 +38,7 @@ #pragma once // Third party headers: -#include <lldb/API/SBCommandReturnObject.h> +#include "lldb/API/SBCommandReturnObject.h" // In-house headers: #include "MICmdBase.h" diff --git a/tools/lldb-mi/MICmdCmdFile.cpp b/tools/lldb-mi/MICmdCmdFile.cpp index a954f88..83862f2 100644 --- a/tools/lldb-mi/MICmdCmdFile.cpp +++ b/tools/lldb-mi/MICmdCmdFile.cpp @@ -20,7 +20,7 @@ //-- // Third Party Headers: -#include <lldb/API/SBStream.h> +#include "lldb/API/SBStream.h" // In-house headers: #include "MICmdCmdFile.h" @@ -96,7 +96,7 @@ CMICmdCmdFileExecAndSymbols::Execute(void) CMICmdArgValFile *pArgFile = static_cast<CMICmdArgValFile *>(pArgNamedFile); const CMIUtilString &strExeFilePath(pArgFile->GetValue()); CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBDebugger &rDbgr = rSessionInfo.m_rLldbDebugger; + lldb::SBDebugger &rDbgr = rSessionInfo.GetDebugger(); lldb::SBError error; const MIchar *pTargetTriple = nullptr; // Let LLDB discover the triple required const MIchar *pTargetPlatformName = ""; @@ -137,8 +137,6 @@ CMICmdCmdFileExecAndSymbols::Execute(void) return MIstatus::failure; } - rSessionInfo.m_lldbTarget = target; - return MIstatus::success; } diff --git a/tools/lldb-mi/MICmdCmdGdbInfo.cpp b/tools/lldb-mi/MICmdCmdGdbInfo.cpp index dde6a0b..be70962 100644 --- a/tools/lldb-mi/MICmdCmdGdbInfo.cpp +++ b/tools/lldb-mi/MICmdCmdGdbInfo.cpp @@ -20,7 +20,7 @@ //-- // Third party headers: -#include <lldb/API/SBCommandReturnObject.h> +#include "lldb/API/SBCommandReturnObject.h" // In-house headers: #include "MICmdCmdGdbInfo.h" @@ -198,11 +198,11 @@ CMICmdCmdGdbInfo::PrintFnSharedLibrary(void) bool bOk = rStdout.TextToStdout("~\"From To Syms Read Shared Object Library\""); CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBTarget &rTarget = rSessionInfo.m_lldbTarget; - const MIuint nModules = rTarget.GetNumModules(); + lldb::SBTarget sbTarget = rSessionInfo.GetTarget(); + const MIuint nModules = sbTarget.GetNumModules(); for (MIuint i = 0; bOk && (i < nModules); i++) { - lldb::SBModule module = rTarget.GetModuleAtIndex(i); + lldb::SBModule module = sbTarget.GetModuleAtIndex(i); if (module.IsValid()) { const CMIUtilString strModuleFilePath(module.GetFileSpec().GetDirectory()); @@ -216,7 +216,7 @@ CMICmdCmdGdbInfo::PrintFnSharedLibrary(void) for (MIuint j = 0; j < nSections; j++) { lldb::SBSection section = module.GetSectionAtIndex(j); - lldb::addr_t addrLoad = section.GetLoadAddress(rTarget); + lldb::addr_t addrLoad = section.GetLoadAddress(sbTarget); if (addrLoad != (lldb::addr_t) - 1) { if (!bHaveAddrLoad) diff --git a/tools/lldb-mi/MICmdCmdMiscellanous.cpp b/tools/lldb-mi/MICmdCmdMiscellanous.cpp index 6b863a8..4e4e1b9 100644 --- a/tools/lldb-mi/MICmdCmdMiscellanous.cpp +++ b/tools/lldb-mi/MICmdCmdMiscellanous.cpp @@ -23,8 +23,8 @@ //-- // Third Party Headers: -#include <lldb/API/SBCommandInterpreter.h> -#include <lldb/API/SBThread.h> +#include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBThread.h" // In-house headers: #include "MICmdCmdMiscellanous.h" @@ -84,7 +84,7 @@ bool CMICmdCmdGdbExit::Execute(void) { CMICmnLLDBDebugger::Instance().GetDriver().SetExitApplicationFlag(true); - const lldb::SBError sbErr = m_rLLDBDebugSessionInfo.m_lldbProcess.Detach(); + const lldb::SBError sbErr = m_rLLDBDebugSessionInfo.GetProcess().Detach(); // Do not check for sbErr.Fail() here, m_lldbProcess is likely !IsValid() return MIstatus::success; @@ -234,17 +234,17 @@ CMICmdCmdListThreadGroups::Execute(void) m_bIsI1 = true; CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); - // Note do not check for rProcess is IsValid(), continue + // Note do not check for sbProcess is IsValid(), continue m_vecMIValueTuple.clear(); - const MIuint nThreads = rProcess.GetNumThreads(); + const MIuint nThreads = sbProcess.GetNumThreads(); for (MIuint i = 0; i < nThreads; i++) { // GetThreadAtIndex() uses a base 0 index // GetThreadByIndexID() uses a base 1 index - lldb::SBThread thread = rProcess.GetThreadAtIndex(i); + lldb::SBThread thread = sbProcess.GetThreadAtIndex(i); if (thread.IsValid()) { @@ -292,9 +292,9 @@ CMICmdCmdListThreadGroups::Acknowledge(void) miTuple.Add(miValueResult2); CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - if (rSessionInfo.m_lldbProcess.IsValid()) + if (rSessionInfo.GetProcess().IsValid()) { - const lldb::pid_t pid = rSessionInfo.m_lldbProcess.GetProcessID(); + const lldb::pid_t pid = rSessionInfo.GetProcess().GetProcessID(); const CMIUtilString strPid(CMIUtilString::Format("%lld", pid)); const CMICmnMIValueConst miValueConst3(strPid); const CMICmnMIValueResult miValueResult3("pid", miValueConst3); @@ -328,20 +328,20 @@ CMICmdCmdListThreadGroups::Acknowledge(void) miTuple.Add(miValueResult2); CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - if (rSessionInfo.m_lldbProcess.IsValid()) + if (rSessionInfo.GetProcess().IsValid()) { - const lldb::pid_t pid = rSessionInfo.m_lldbProcess.GetProcessID(); + const lldb::pid_t pid = rSessionInfo.GetProcess().GetProcessID(); const CMIUtilString strPid(CMIUtilString::Format("%lld", pid)); const CMICmnMIValueConst miValueConst3(strPid); const CMICmnMIValueResult miValueResult3("pid", miValueConst3); miTuple.Add(miValueResult3); } - if (rSessionInfo.m_lldbTarget.IsValid()) + if (rSessionInfo.GetTarget().IsValid()) { - lldb::SBTarget &rTrgt = rSessionInfo.m_lldbTarget; - const MIchar *pDir = rTrgt.GetExecutable().GetDirectory(); - const MIchar *pFileName = rTrgt.GetExecutable().GetFilename(); + lldb::SBTarget sbTrgt = rSessionInfo.GetTarget(); + const MIchar *pDir = sbTrgt.GetExecutable().GetDirectory(); + const MIchar *pFileName = sbTrgt.GetExecutable().GetFilename(); const CMIUtilString strFile(CMIUtilString::Format("%s/%s", pDir, pFileName)); const CMICmnMIValueConst miValueConst4(strFile); const CMICmnMIValueResult miValueResult4("executable", miValueConst4); @@ -470,7 +470,7 @@ CMICmdCmdInterpreterExec::Execute(void) const CMIUtilString &rStrCommand(pArgCommand->GetValue()); CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); const lldb::ReturnStatus rtn = - rSessionInfo.m_rLldbDebugger.GetCommandInterpreter().HandleCommand(rStrCommand.c_str(), m_lldbResult, true); + rSessionInfo.GetDebugger().GetCommandInterpreter().HandleCommand(rStrCommand.c_str(), m_lldbResult, true); MIunused(rtn); return MIstatus::success; @@ -588,7 +588,7 @@ CMICmdCmdInferiorTtySet::Execute(void) bool CMICmdCmdInferiorTtySet::Acknowledge(void) { - const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done); + const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error); m_miResultRecord = miRecordResult; return MIstatus::success; diff --git a/tools/lldb-mi/MICmdCmdMiscellanous.h b/tools/lldb-mi/MICmdCmdMiscellanous.h index 1cabbac..fd99094 100644 --- a/tools/lldb-mi/MICmdCmdMiscellanous.h +++ b/tools/lldb-mi/MICmdCmdMiscellanous.h @@ -34,7 +34,7 @@ #pragma once // Third party headers: -#include <lldb/API/SBCommandReturnObject.h> +#include "lldb/API/SBCommandReturnObject.h" // In-house headers: #include "MICmdBase.h" diff --git a/tools/lldb-mi/MICmdCmdStack.cpp b/tools/lldb-mi/MICmdCmdStack.cpp index 4ed6803..4ab7164 100644 --- a/tools/lldb-mi/MICmdCmdStack.cpp +++ b/tools/lldb-mi/MICmdCmdStack.cpp @@ -23,7 +23,7 @@ //-- // Third Party Headers: -#include <lldb/API/SBThread.h> +#include "lldb/API/SBThread.h" // In-house headers: #include "MICmdCmdStack.h" @@ -82,7 +82,7 @@ bool CMICmdCmdStackInfoDepth::ParseArgs(void) { bool bOk = - m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1))); + m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgMaxDepth, false, false))); return (bOk && ParseValidateCmdOptions()); } @@ -104,15 +104,15 @@ CMICmdCmdStackInfoDepth::Execute(void) // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; - if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) + if (pArgThread->GetFound() && !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str())); return MIstatus::failure; } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; - lldb::SBThread thread = (nThreadId != UINT64_MAX) ? rProcess.GetThreadByIndexID(nThreadId) : rProcess.GetSelectedThread(); + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); + lldb::SBThread thread = (nThreadId != UINT64_MAX) ? sbProcess.GetThreadByIndexID(nThreadId) : sbProcess.GetSelectedThread(); m_nThreadFrames = thread.GetNumFrames(); return MIstatus::success; @@ -202,7 +202,7 @@ bool CMICmdCmdStackListFrames::ParseArgs(void) { bool bOk = - m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, true, true, CMICmdArgValListBase::eArgValType_Number, 1))); + m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgFrameLow, false, true))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgFrameHigh, false, true))); return (bOk && ParseValidateCmdOptions()); @@ -226,7 +226,7 @@ CMICmdCmdStackListFrames::Execute(void) // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; - if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) + if (pArgThread->GetFound() && !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str())); return MIstatus::failure; @@ -237,8 +237,8 @@ CMICmdCmdStackListFrames::Execute(void) const MIuint nFrameLow = pArgFrameLow->GetFound() ? pArgFrameLow->GetValue() : 0; CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; - lldb::SBThread thread = (nThreadId != UINT64_MAX) ? rProcess.GetThreadByIndexID(nThreadId) : rProcess.GetSelectedThread(); + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); + lldb::SBThread thread = (nThreadId != UINT64_MAX) ? sbProcess.GetThreadByIndexID(nThreadId) : sbProcess.GetSelectedThread(); MIuint nThreadFrames = thread.GetNumFrames(); // Adjust nThreadFrames for the nFrameHigh argument as we use nFrameHigh+1 in the min calc as the arg @@ -350,6 +350,9 @@ CMICmdCmdStackListArguments::CMICmdCmdStackListArguments(void) , m_miValueList(true) , m_constStrArgThread("thread") , m_constStrArgPrintValues("print-values") + , m_constStrArgNoValues("no-values") + , m_constStrArgAllValues("all-values") + , m_constStrArgSimpleValues("simple-values") { // Command factory matches this name with that received from the stdin stream m_strMiCmd = "stack-list-arguments"; @@ -383,7 +386,10 @@ CMICmdCmdStackListArguments::ParseArgs(void) { bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); - bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgPrintValues, true, false))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgPrintValues, false, true))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgNoValues, false, true))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgAllValues, false, true))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgSimpleValues, false, true))); return (bOk && ParseValidateCmdOptions()); } @@ -401,6 +407,9 @@ CMICmdCmdStackListArguments::Execute(void) { CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread); CMICMDBASE_GETOPTION(pArgPrintValues, Number, m_constStrArgPrintValues); + CMICMDBASE_GETOPTION(pArgNoValues, OptionLong, m_constStrArgNoValues); + CMICMDBASE_GETOPTION(pArgAllValues, OptionLong, m_constStrArgAllValues); + CMICMDBASE_GETOPTION(pArgSimpleValues, OptionLong, m_constStrArgSimpleValues); // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; @@ -413,9 +422,32 @@ CMICmdCmdStackListArguments::Execute(void) } } + CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e eVarInfoFormat; + if (pArgPrintValues->GetFound()) + { + const MIuint nPrintValues = pArgPrintValues->GetValue(); + if (nPrintValues >= CMICmnLLDBDebugSessionInfo::kNumVariableInfoFormats) + { + SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PRINT_VALUES), m_cmdData.strMiCmd.c_str())); + return MIstatus::failure; + } + eVarInfoFormat = static_cast<CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e>(nPrintValues); + } + else if (pArgNoValues->GetFound()) + eVarInfoFormat = CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_NoValues; + else if (pArgAllValues->GetFound()) + eVarInfoFormat = CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_AllValues; + else if (pArgSimpleValues->GetFound()) + eVarInfoFormat = CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_SimpleValues; + else + { + SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PRINT_VALUES), m_cmdData.strMiCmd.c_str())); + return MIstatus::failure; + } + CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; - lldb::SBThread thread = (nThreadId != UINT64_MAX) ? rProcess.GetThreadByIndexID(nThreadId) : rProcess.GetSelectedThread(); + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); + lldb::SBThread thread = (nThreadId != UINT64_MAX) ? sbProcess.GetThreadByIndexID(nThreadId) : sbProcess.GetSelectedThread(); m_bThreadInvalid = !thread.IsValid(); if (m_bThreadInvalid) return MIstatus::success; @@ -433,7 +465,7 @@ CMICmdCmdStackListArguments::Execute(void) lldb::SBFrame frame = thread.GetFrameAtIndex(i); CMICmnMIValueList miValueList(true); const MIuint maskVarTypes = CMICmnLLDBDebugSessionInfo::eVariableType_Arguments; - if (!rSessionInfo.MIResponseFormVariableInfo3(frame, maskVarTypes, miValueList)) + if (!rSessionInfo.MIResponseFormVariableInfo3(frame, maskVarTypes, eVarInfoFormat, miValueList)) return MIstatus::failure; const CMICmnMIValueConst miValueConst(CMIUtilString::Format("%d", i)); const CMICmnMIValueResult miValueResult("level", miValueConst); @@ -508,6 +540,9 @@ CMICmdCmdStackListLocals::CMICmdCmdStackListLocals(void) , m_constStrArgThread("thread") , m_constStrArgFrame("frame") , m_constStrArgPrintValues("print-values") + , m_constStrArgNoValues("no-values") + , m_constStrArgAllValues("all-values") + , m_constStrArgSimpleValues("simple-values") { // Command factory matches this name with that received from the stdin stream m_strMiCmd = "stack-list-locals"; @@ -543,7 +578,10 @@ CMICmdCmdStackListLocals::ParseArgs(void) m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgThread, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgFrame, false, true, CMICmdArgValListBase::eArgValType_Number, 1))); - bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgPrintValues, true, false))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgPrintValues, false, true))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgNoValues, false, true))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgAllValues, false, true))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgSimpleValues, false, true))); return (bOk && ParseValidateCmdOptions()); } @@ -561,6 +599,10 @@ CMICmdCmdStackListLocals::Execute(void) { CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread); CMICMDBASE_GETOPTION(pArgFrame, OptionLong, m_constStrArgFrame); + CMICMDBASE_GETOPTION(pArgPrintValues, Number, m_constStrArgPrintValues); + CMICMDBASE_GETOPTION(pArgNoValues, OptionLong, m_constStrArgNoValues); + CMICMDBASE_GETOPTION(pArgAllValues, OptionLong, m_constStrArgAllValues); + CMICMDBASE_GETOPTION(pArgSimpleValues, OptionLong, m_constStrArgSimpleValues); // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; @@ -572,6 +614,7 @@ CMICmdCmdStackListLocals::Execute(void) return MIstatus::failure; } } + MIuint64 nFrame = UINT64_MAX; if (pArgFrame->GetFound()) { @@ -582,9 +625,32 @@ CMICmdCmdStackListLocals::Execute(void) } } + CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e eVarInfoFormat; + if (pArgPrintValues->GetFound()) + { + const MIuint nPrintValues = pArgPrintValues->GetValue(); + if (nPrintValues >= CMICmnLLDBDebugSessionInfo::kNumVariableInfoFormats) + { + SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PRINT_VALUES), m_cmdData.strMiCmd.c_str())); + return MIstatus::failure; + } + eVarInfoFormat = static_cast<CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e>(nPrintValues); + } + else if (pArgNoValues->GetFound()) + eVarInfoFormat = CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_NoValues; + else if (pArgAllValues->GetFound()) + eVarInfoFormat = CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_AllValues; + else if (pArgSimpleValues->GetFound()) + eVarInfoFormat = CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_SimpleValues; + else + { + SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PRINT_VALUES), m_cmdData.strMiCmd.c_str())); + return MIstatus::failure; + } + CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; - lldb::SBThread thread = (nThreadId != UINT64_MAX) ? rProcess.GetThreadByIndexID(nThreadId) : rProcess.GetSelectedThread(); + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); + lldb::SBThread thread = (nThreadId != UINT64_MAX) ? sbProcess.GetThreadByIndexID(nThreadId) : sbProcess.GetSelectedThread(); m_bThreadInvalid = !thread.IsValid(); if (m_bThreadInvalid) return MIstatus::success; @@ -596,12 +662,11 @@ CMICmdCmdStackListLocals::Execute(void) return MIstatus::success; } - const MIuint nFrames = thread.GetNumFrames(); - MIunused(nFrames); lldb::SBFrame frame = (nFrame != UINT64_MAX) ? thread.GetFrameAtIndex(nFrame) : thread.GetSelectedFrame(); + CMICmnMIValueList miValueList(true); const MIuint maskVarTypes = CMICmnLLDBDebugSessionInfo::eVariableType_Locals; - if (!rSessionInfo.MIResponseFormVariableInfo(frame, maskVarTypes, miValueList)) + if (!rSessionInfo.MIResponseFormVariableInfo(frame, maskVarTypes, eVarInfoFormat, miValueList)) return MIstatus::failure; m_miValueList = miValueList; diff --git a/tools/lldb-mi/MICmdCmdStack.h b/tools/lldb-mi/MICmdCmdStack.h index bae43dc..ebef7e1 100644 --- a/tools/lldb-mi/MICmdCmdStack.h +++ b/tools/lldb-mi/MICmdCmdStack.h @@ -143,7 +143,10 @@ class CMICmdCmdStackListArguments : public CMICmdBase bool m_bThreadInvalid; // True = yes invalid thread, false = thread object valid CMICmnMIValueList m_miValueList; const CMIUtilString m_constStrArgThread; // Not specified in MI spec but Eclipse gives this option - const CMIUtilString m_constStrArgPrintValues; // Not handled by *this command + const CMIUtilString m_constStrArgPrintValues; + const CMIUtilString m_constStrArgNoValues; + const CMIUtilString m_constStrArgAllValues; + const CMIUtilString m_constStrArgSimpleValues; }; //++ ============================================================================ @@ -179,5 +182,8 @@ class CMICmdCmdStackListLocals : public CMICmdBase CMICmnMIValueList m_miValueList; const CMIUtilString m_constStrArgThread; // Not specified in MI spec but Eclipse gives this option const CMIUtilString m_constStrArgFrame; // Not specified in MI spec but Eclipse gives this option - const CMIUtilString m_constStrArgPrintValues; // Not handled by *this command + const CMIUtilString m_constStrArgPrintValues; + const CMIUtilString m_constStrArgNoValues; + const CMIUtilString m_constStrArgAllValues; + const CMIUtilString m_constStrArgSimpleValues; }; diff --git a/tools/lldb-mi/MICmdCmdTarget.cpp b/tools/lldb-mi/MICmdCmdTarget.cpp index ec19493..c3ef0b4 100644 --- a/tools/lldb-mi/MICmdCmdTarget.cpp +++ b/tools/lldb-mi/MICmdCmdTarget.cpp @@ -20,9 +20,9 @@ //-- // Third Party Headers: -#include <lldb/API/SBStream.h> -#include <lldb/API/SBCommandInterpreter.h> -#include <lldb/API/SBCommandReturnObject.h> +#include "lldb/API/SBStream.h" +#include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBCommandReturnObject.h" // In-house headers: #include "MICmdCmdTarget.h" @@ -100,7 +100,7 @@ CMICmdCmdTargetSelect::Execute(void) // Check we have a valid target // Note: target created via 'file-exec-and-symbols' command - if (!rSessionInfo.m_lldbTarget.IsValid()) + if (!rSessionInfo.GetTarget().IsValid()) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_TARGET_CURRENT), m_cmdData.strMiCmd.c_str())); return MIstatus::failure; @@ -120,7 +120,7 @@ CMICmdCmdTargetSelect::Execute(void) // Ask LLDB to collect to the target port const MIchar *pPlugin("gdb-remote"); lldb::SBError error; - lldb::SBProcess process = rSessionInfo.m_lldbTarget.ConnectRemote(rSessionInfo.m_rLlldbListener, strUrl.c_str(), pPlugin, error); + lldb::SBProcess process = rSessionInfo.GetTarget().ConnectRemote(rSessionInfo.GetListener(), strUrl.c_str(), pPlugin, error); // Verify that we have managed to connect successfully lldb::SBStream errMsg; @@ -135,16 +135,11 @@ CMICmdCmdTargetSelect::Execute(void) return MIstatus::failure; } - // Save the process in the session info - // Note: Order is important here since this process handle may be used by CMICmnLLDBDebugHandleEvents - // which can fire when interpreting via HandleCommand() below. - rSessionInfo.m_lldbProcess = process; - // Set the environment path if we were given one CMIUtilString strWkDir; if (rSessionInfo.SharedDataRetrieve<CMIUtilString>(rSessionInfo.m_constStrSharedDataKeyWkDir, strWkDir)) { - lldb::SBDebugger &rDbgr = rSessionInfo.m_rLldbDebugger; + lldb::SBDebugger &rDbgr = rSessionInfo.GetDebugger(); if (!rDbgr.SetCurrentPlatformSDKRoot(strWkDir.c_str())) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_FNFAILED), m_cmdData.strMiCmd.c_str(), "target-select")); @@ -156,7 +151,7 @@ CMICmdCmdTargetSelect::Execute(void) CMIUtilString strSolibPath; if (rSessionInfo.SharedDataRetrieve<CMIUtilString>(rSessionInfo.m_constStrSharedDataSolibPath, strSolibPath)) { - lldb::SBDebugger &rDbgr = rSessionInfo.m_rLldbDebugger; + lldb::SBDebugger &rDbgr = rSessionInfo.GetDebugger(); lldb::SBCommandInterpreter cmdIterpreter = rDbgr.GetCommandInterpreter(); CMIUtilString strCmdString = CMIUtilString::Format("target modules search-paths add . %s", strSolibPath.c_str()); @@ -190,7 +185,7 @@ CMICmdCmdTargetSelect::Acknowledge(void) m_miResultRecord = miRecordResult; CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::pid_t pid = rSessionInfo.m_lldbProcess.GetProcessID(); + lldb::pid_t pid = rSessionInfo.GetProcess().GetProcessID(); // Prod the client i.e. Eclipse with out-of-band results to help it 'continue' because it is using LLDB debugger // Give the client '=thread-group-started,id="i1"' m_bHasResultRecordExtra = true; diff --git a/tools/lldb-mi/MICmdCmdThread.cpp b/tools/lldb-mi/MICmdCmdThread.cpp index 3a448a7..52fd960 100644 --- a/tools/lldb-mi/MICmdCmdThread.cpp +++ b/tools/lldb-mi/MICmdCmdThread.cpp @@ -20,8 +20,8 @@ //-- // Third Party Headers: -#include <lldb/API/SBBreakpointLocation.h> -#include <lldb/API/SBThread.h> +#include "lldb/API/SBBreakpointLocation.h" +#include "lldb/API/SBThread.h" // In-house headers: #include "MICmdCmdThread.h" @@ -99,12 +99,12 @@ CMICmdCmdThreadInfo::Execute(void) } CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; - lldb::SBThread thread = rProcess.GetSelectedThread(); + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); + lldb::SBThread thread = sbProcess.GetSelectedThread(); if (m_bSingleThread) { - thread = rProcess.GetThreadByIndexID(nThreadId); + thread = sbProcess.GetThreadByIndexID(nThreadId); m_bThreadInvalid = thread.IsValid(); if (!m_bThreadInvalid) return MIstatus::success; @@ -120,10 +120,10 @@ CMICmdCmdThreadInfo::Execute(void) // Multiple threads m_vecMIValueTuple.clear(); - const MIuint nThreads = rProcess.GetNumThreads(); + const MIuint nThreads = sbProcess.GetNumThreads(); for (MIuint i = 0; i < nThreads; i++) { - lldb::SBThread thread = rProcess.GetThreadAtIndex(i); + lldb::SBThread thread = sbProcess.GetThreadAtIndex(i); if (thread.IsValid()) { CMICmnMIValueTuple miTuple; diff --git a/tools/lldb-mi/MICmdCmdVar.cpp b/tools/lldb-mi/MICmdCmdVar.cpp index 4aa4c2a..e9568be 100644 --- a/tools/lldb-mi/MICmdCmdVar.cpp +++ b/tools/lldb-mi/MICmdCmdVar.cpp @@ -28,8 +28,8 @@ //-- // Third Party Headers: -#include <lldb/API/SBStream.h> -#include <lldb/API/SBThread.h> +#include "lldb/API/SBStream.h" +#include "lldb/API/SBThread.h" // In-house headers: #include "MICmdCmdVar.h" @@ -129,16 +129,15 @@ CMICmdCmdVarCreate::Execute(void) // Retrieve the --thread option's thread ID (only 1) MIuint64 nThreadId = UINT64_MAX; - if (!pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) + if (pArgThread->GetFound() && !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str())); return MIstatus::failure; } - m_nThreadId = nThreadId; // Retrieve the --frame option's number MIuint64 nFrame = UINT64_MAX; - if (!pArgFrame->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nFrame)) + if (pArgThread->GetFound() && !pArgFrame->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nFrame)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgFrame.c_str())); return MIstatus::failure; @@ -152,27 +151,41 @@ CMICmdCmdVarCreate::Execute(void) nFrame = pOption->GetValue(); } - bool bAutoName = false; - const CMIUtilString strArgName; + m_strVarName = "<unnamedvariable>"; if (pArgName->GetFound()) { const CMIUtilString &rArg = pArgName->GetValue(); - bAutoName = (rArg == "-"); + const bool bAutoName = (rArg == "-"); + if (bAutoName) + { + m_strVarName = CMIUtilString::Format("var%u", CMICmnLLDBDebugSessionInfoVarObj::VarObjIdGet()); + CMICmnLLDBDebugSessionInfoVarObj::VarObjIdInc(); + } + else + m_strVarName = rArg; + } + + bool bCurrentFrame = false; + if (pArgFrameAddr->GetFound()) + { + const CMIUtilString &rStrFrameAddr(pArgFrameAddr->GetValue()); + bCurrentFrame = CMIUtilString::Compare(rStrFrameAddr, "*"); + if (!bCurrentFrame && (nFrame == UINT64_MAX)) + { + //FIXME: *addr isn't implemented. Exit with error if --thread isn't specified. + SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgFrame.c_str())); + return MIstatus::failure; + } } const CMIUtilString &rStrExpression(pArgExpression->GetValue()); m_strExpression = rStrExpression; CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - m_strVarName = "<unnamedvariable>"; - if (bAutoName) - { - m_strVarName = CMIUtilString::Format("var%u", CMICmnLLDBDebugSessionInfoVarObj::VarObjIdGet()); - CMICmnLLDBDebugSessionInfoVarObj::VarObjIdInc(); - } - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; - lldb::SBThread thread = rProcess.GetThreadByIndexID(nThreadId); - lldb::SBFrame frame = thread.GetFrameAtIndex(nFrame); + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); + lldb::SBThread thread = (nThreadId != UINT64_MAX) ? sbProcess.GetThreadByIndexID(nThreadId) : sbProcess.GetSelectedThread(); + m_nThreadId = thread.GetIndexID(); + lldb::SBFrame frame = bCurrentFrame ? thread.GetSelectedFrame() : thread.GetFrameAtIndex(nFrame); lldb::SBValue value = frame.FindVariable(rStrExpression.c_str()); if (!value.IsValid()) value = frame.EvaluateExpression(rStrExpression.c_str()); @@ -260,7 +273,8 @@ CMICmdCmdVarCreate::CreateSelf(void) // Throws: None. //-- CMICmdCmdVarUpdate::CMICmdCmdVarUpdate(void) - : m_constStrArgPrintValues("print-values") + : m_eVarInfoFormat(CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_NoValues) + , m_constStrArgPrintValues("print-values") , m_constStrArgName("name") , m_bValueChangedArrayType(false) , m_bValueChangedCompositeType(false) @@ -297,7 +311,7 @@ CMICmdCmdVarUpdate::~CMICmdCmdVarUpdate(void) bool CMICmdCmdVarUpdate::ParseArgs(void) { - bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgPrintValues, false, false))); + bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgPrintValues, false, true))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValString(m_constStrArgName, true, true))); return (bOk && ParseValidateCmdOptions()); } @@ -314,6 +328,7 @@ CMICmdCmdVarUpdate::ParseArgs(void) bool CMICmdCmdVarUpdate::Execute(void) { + CMICMDBASE_GETOPTION(pArgPrintValues, Number, m_constStrArgPrintValues); CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName); const CMIUtilString &rVarObjName(pArgName->GetValue()); @@ -324,6 +339,14 @@ CMICmdCmdVarUpdate::Execute(void) return MIstatus::failure; } + const MIuint nPrintValues = pArgPrintValues->GetValue(); + if (nPrintValues >= CMICmnLLDBDebugSessionInfo::kNumVariableInfoFormats) + { + SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_INVALID_PRINT_VALUES), m_cmdData.strMiCmd.c_str())); + return MIstatus::failure; + } + m_eVarInfoFormat = static_cast<CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e>(nPrintValues); + const CMIUtilString &rVarRealName(varObj.GetNameReal()); MIunused(rVarRealName); lldb::SBValue &rValue = const_cast<lldb::SBValue &>(varObj.GetValue()); @@ -413,9 +436,12 @@ CMICmdCmdVarUpdate::Acknowledge(void) const CMICmnMIValueConst miValueConst(m_strValueName); CMICmnMIValueResult miValueResult("name", miValueConst); CMICmnMIValueTuple miValueTuple(miValueResult); - const CMICmnMIValueConst miValueConst2(strValue); - CMICmnMIValueResult miValueResult2("value", miValueConst2); - miValueTuple.Add(miValueResult2); + if (m_eVarInfoFormat != CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_NoValues) + { + const CMICmnMIValueConst miValueConst2(strValue); + CMICmnMIValueResult miValueResult2("value", miValueConst2); + miValueTuple.Add(miValueResult2); + } const CMICmnMIValueConst miValueConst3(strInScope); CMICmnMIValueResult miValueResult3("in_scope", miValueConst3); miValueTuple.Add(miValueResult3); @@ -519,8 +545,8 @@ CMICmdCmdVarUpdate::ExamineSBValueForChange(const CMICmnLLDBDebugSessionInfoVarO vrwbChanged = false; CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; - lldb::SBThread thread = rProcess.GetSelectedThread(); + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); + lldb::SBThread thread = sbProcess.GetSelectedThread(); if (thread.GetNumFrames() == 0) { return MIstatus::success; @@ -964,7 +990,10 @@ CMICmdCmdVarListChildren::CMICmdCmdVarListChildren(void) , m_nChildren(0) , m_constStrArgPrintValues("print-values") , m_constStrArgName("name") -{ + , m_constStrArgNoValues("no-values") + , m_constStrArgAllValues("all-values") + , m_constStrArgSimpleValues("simple-values") + { // Command factory matches this name with that received from the stdin stream m_strMiCmd = "var-list-children"; @@ -996,7 +1025,10 @@ CMICmdCmdVarListChildren::~CMICmdCmdVarListChildren(void) bool CMICmdCmdVarListChildren::ParseArgs(void) { - bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgPrintValues, false, false))); + bool bOk = m_setCmdArgs.Add(*(new CMICmdArgValNumber(m_constStrArgPrintValues, false, true))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgNoValues, false, true))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgAllValues, false, true))); + bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValOptionLong(m_constStrArgSimpleValues, false, true))); bOk = bOk && m_setCmdArgs.Add(*(new CMICmdArgValString(m_constStrArgName, true, true))); return (bOk && ParseValidateCmdOptions()); } @@ -1014,6 +1046,24 @@ bool CMICmdCmdVarListChildren::Execute(void) { CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName); + CMICMDBASE_GETOPTION(pArgPrintValue, Number, m_constStrArgPrintValues); + CMICMDBASE_GETOPTION(pArgNoValue, OptionLong, m_constStrArgNoValues); + CMICMDBASE_GETOPTION(pArgAllValue, OptionLong, m_constStrArgAllValues); + CMICMDBASE_GETOPTION(pArgSimpleValue, OptionLong, m_constStrArgSimpleValues); + + MIuint print_value = 0; + if (pArgPrintValue->GetFound()) + { + MIuint tmp = pArgPrintValue->GetValue(); + if (tmp <= 2) + print_value = tmp; + } + else if (pArgNoValue->GetFound()) + print_value = 0; // no value + else if (pArgAllValue->GetFound()) + print_value = 1; // all values + else if (pArgSimpleValue->GetFound()) + print_value = 2; // simple values const CMIUtilString &rVarObjName(pArgName->GetValue()); CMICmnLLDBDebugSessionInfoVarObj varObj; @@ -1041,9 +1091,6 @@ CMICmdCmdVarListChildren::Execute(void) const MIuint nChildren = member.GetNumChildren(); const CMIUtilString strThreadId(CMIUtilString::Format("%u", member.GetThread().GetIndexID())); - // Varobj gets added to CMICmnLLDBDebugSessionInfoVarObj static container of varObjs - CMICmnLLDBDebugSessionInfoVarObj var(strExp, name, member, rVarObjName); - // MI print "child={name=\"%s\",exp=\"%s\",numchild=\"%d\",value=\"%s\",type=\"%s\",thread-id=\"%u\",has_more=\"%u\"}" const CMICmnMIValueConst miValueConst(name); const CMICmnMIValueResult miValueResult("name", miValueConst); @@ -1061,11 +1108,23 @@ CMICmdCmdVarListChildren::Execute(void) const CMICmnMIValueConst miValueConst6(strThreadId); const CMICmnMIValueResult miValueResult6("thread-id", miValueConst6); miValueTuple.Add(miValueResult6); - const CMICmnMIValueConst miValueConst7("0"); - const CMICmnMIValueResult miValueResult7("has_more", miValueConst7); - miValueTuple.Add(miValueResult7); - const CMICmnMIValueResult miValueResult8("child", miValueTuple); - m_vecMiValueResult.push_back(miValueResult8); + // nChildren == 0 is used to check for simple values + if ( (print_value == 2 && nChildren == 0) || (print_value == 1) ) + { + // Varobj gets added to CMICmnLLDBDebugSessionInfoVarObj static container of varObjs + CMICmnLLDBDebugSessionInfoVarObj var(strExp, name, member, rVarObjName); + const CMIUtilString strValue( + CMICmnLLDBDebugSessionInfoVarObj::GetValueStringFormatted(member, CMICmnLLDBDebugSessionInfoVarObj::eVarFormat_Natural)); + const CMICmnMIValueConst miValueConst7(strValue); + const CMICmnMIValueResult miValueResult7("value", miValueConst7); + miValueTuple.Add(miValueResult7); + } + const CMICmnMIValueConst miValueConst8("0"); + const CMICmnMIValueResult miValueResult8("has_more", miValueConst8); + miValueTuple.Add(miValueResult8); + const CMICmnMIValueResult miValueResult9("child", miValueTuple); + m_vecMiValueResult.push_back(miValueResult9); + } return MIstatus::success; @@ -1493,7 +1552,7 @@ CMICmdCmdVarShowAttributes::Execute(void) const CMIUtilString &rVarObjName(pArgName->GetValue()); CMICmnLLDBDebugSessionInfoVarObj varObj; - if (CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj)) + if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj)) { SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST), m_cmdData.strMiCmd.c_str(), rVarObjName.c_str())); return MIstatus::failure; diff --git a/tools/lldb-mi/MICmdCmdVar.h b/tools/lldb-mi/MICmdCmdVar.h index 34ce9e1..add2058 100644 --- a/tools/lldb-mi/MICmdCmdVar.h +++ b/tools/lldb-mi/MICmdCmdVar.h @@ -42,6 +42,7 @@ #include "MICmdBase.h" #include "MICmnMIValueTuple.h" #include "MICmnMIValueList.h" +#include "MICmnLLDBDebugSessionInfo.h" #include "MICmnLLDBDebugSessionInfoVarObj.h" // Declarations: @@ -129,6 +130,7 @@ class CMICmdCmdVarUpdate : public CMICmdBase // Attribute: private: CMIUtilString m_strValueName; + CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e m_eVarInfoFormat; const CMIUtilString m_constStrArgPrintValues; // Not handled by *this command const CMIUtilString m_constStrArgName; bool m_bValueChangedArrayType; // True = yes value changed, false = no change @@ -274,8 +276,11 @@ class CMICmdCmdVarListChildren : public CMICmdBase bool m_bValueValid; // True = yes SBValue object is valid, false = not valid VecMIValueResult_t m_vecMiValueResult; MIuint m_nChildren; - const CMIUtilString m_constStrArgPrintValues; // Not handled by *this command + const CMIUtilString m_constStrArgPrintValues; const CMIUtilString m_constStrArgName; + const CMIUtilString m_constStrArgNoValues; + const CMIUtilString m_constStrArgAllValues; + const CMIUtilString m_constStrArgSimpleValues; }; //++ ============================================================================ diff --git a/tools/lldb-mi/MICmnLLDBBroadcaster.h b/tools/lldb-mi/MICmnLLDBBroadcaster.h index 70d0925..62ca054 100644 --- a/tools/lldb-mi/MICmnLLDBBroadcaster.h +++ b/tools/lldb-mi/MICmnLLDBBroadcaster.h @@ -22,7 +22,7 @@ #pragma once // In-house headers: -#include <lldb/API/SBBroadcaster.h> +#include "lldb/API/SBBroadcaster.h" #include "MICmnBase.h" #include "MIUtilSingletonBase.h" diff --git a/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp b/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp index 3e9ed22..7f6d9d5 100644 --- a/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp +++ b/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp @@ -20,13 +20,13 @@ //-- // Third party headers: -#include <lldb/API/SBThread.h> +#include "lldb/API/SBThread.h" #ifdef _WIN32 #include <io.h> // For the ::_access() #else #include <unistd.h> // For the ::access() #endif // _WIN32 -#include <lldb/API/SBBreakpointLocation.h> +#include "lldb/API/SBBreakpointLocation.h" // In-house headers: #include "MICmnLLDBDebugSessionInfo.h" @@ -47,9 +47,7 @@ // Throws: None. //-- CMICmnLLDBDebugSessionInfo::CMICmnLLDBDebugSessionInfo(void) - : m_rLldbDebugger(CMICmnLLDBDebugger::Instance().GetTheDebugger()) - , m_rLlldbListener(CMICmnLLDBDebugger::Instance().GetTheListener()) - , m_nBrkPointCntMax(INT32_MAX) + : m_nBrkPointCntMax(INT32_MAX) , m_currentSelectedThread(LLDB_INVALID_THREAD_ID) , m_constStrSharedDataKeyWkDir("Working Directory") , m_constStrSharedDataSolibPath("Solib Path") @@ -226,7 +224,7 @@ CMICmnLLDBDebugSessionInfo::RecordBrkPtInfoDelete(const MIuint vnBrkPtId) bool CMICmnLLDBDebugSessionInfo::GetThreadFrames(const SMICmdData &vCmdData, const MIuint vThreadIdx, CMIUtilString &vwrThreadFrames) { - lldb::SBThread thread = m_lldbProcess.GetThreadByIndexID(vThreadIdx); + lldb::SBThread thread = GetProcess().GetThreadByIndexID(vThreadIdx); const uint32_t nFrames = thread.GetNumFrames(); if (nFrames == 0) { @@ -255,7 +253,7 @@ CMICmnLLDBDebugSessionInfo::GetThreadFrames(const SMICmdData &vCmdData, const MI // Function args CMICmnMIValueList miValueList(true); const MIuint maskVarTypes = eVariableType_Arguments; - if (!MIResponseFormVariableInfo(frame, maskVarTypes, miValueList)) + if (!MIResponseFormVariableInfo(frame, maskVarTypes, eVariableInfoFormat_AllValues, miValueList)) return MIstatus::failure; const MIchar *pUnknown = "??"; @@ -299,7 +297,7 @@ CMICmnLLDBDebugSessionInfo::GetThreadFrames(const SMICmdData &vCmdData, const MI bool CMICmnLLDBDebugSessionInfo::GetThreadFrames2(const SMICmdData &vCmdData, const MIuint vThreadIdx, CMIUtilString &vwrThreadFrames) { - lldb::SBThread thread = m_lldbProcess.GetThreadByIndexID(vThreadIdx); + lldb::SBThread thread = GetProcess().GetThreadByIndexID(vThreadIdx); const uint32_t nFrames = thread.GetNumFrames(); if (nFrames == 0) { @@ -328,7 +326,7 @@ CMICmnLLDBDebugSessionInfo::GetThreadFrames2(const SMICmdData &vCmdData, const M // Function args CMICmnMIValueList miValueList(true); const MIuint maskVarTypes = eVariableType_Arguments; - if (!MIResponseFormVariableInfo2(frame, maskVarTypes, miValueList)) + if (!MIResponseFormVariableInfo2(frame, maskVarTypes, eVariableInfoFormat_AllValues, miValueList)) return MIstatus::failure; const MIchar *pUnknown = "??"; @@ -648,6 +646,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFormThreadInfo2(const SMICmdData &vCmdData // Type: Method. // Args: vrFrame - (R) LLDB thread object. // vMaskVarTypes - (R) Construed according to VariableType_e. +// veVarInfoFormat - (R) The type of variable info that should be shown. // vwrMIValueList - (W) MI value list object. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. @@ -655,7 +654,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFormThreadInfo2(const SMICmdData &vCmdData //-- bool CMICmnLLDBDebugSessionInfo::MIResponseFormVariableInfo2(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, - CMICmnMIValueList &vwrMiValueList) + const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList) { bool bOk = MIstatus::success; lldb::SBFrame &rFrame = const_cast<lldb::SBFrame &>(vrFrame); @@ -688,6 +687,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFormVariableInfo2(const lldb::SBFrame &vrF // Type: Method. // Args: vrFrame - (R) LLDB thread object. // vMaskVarTypes - (R) Construed according to VariableType_e. +// veVarInfoFormat - (R) The type of variable info that should be shown. // vwrMIValueList - (W) MI value list object. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. @@ -695,7 +695,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFormVariableInfo2(const lldb::SBFrame &vrF //-- bool CMICmnLLDBDebugSessionInfo::MIResponseFormVariableInfo(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, - CMICmnMIValueList &vwrMiValueList) + const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList) { bool bOk = MIstatus::success; lldb::SBFrame &rFrame = const_cast<lldb::SBFrame &>(vrFrame); @@ -711,7 +711,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFormVariableInfo(const lldb::SBFrame &vrFr for (MIuint i = 0; bOk && (i < nArgs); i++) { lldb::SBValue value = listArg.GetValueAtIndex(i); - bOk = GetVariableInfo(nMaxRecusiveDepth, value, false, vwrMiValueList, nCurrentRecursiveDepth); + bOk = GetVariableInfo(nMaxRecusiveDepth, value, false, veVarInfoFormat, vwrMiValueList, nCurrentRecursiveDepth); } return bOk; @@ -725,6 +725,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFormVariableInfo(const lldb::SBFrame &vrFr // Type: Method. // Args: vrFrame - (R) LLDB thread object. // vMaskVarTypes - (R) Construed according to VariableType_e. +// veVarInfoFormat - (R) The type of variable info that should be shown. // vwrMIValueList - (W) MI value list object. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. @@ -732,7 +733,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFormVariableInfo(const lldb::SBFrame &vrFr //-- bool CMICmnLLDBDebugSessionInfo::MIResponseFormVariableInfo3(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, - CMICmnMIValueList &vwrMiValueList) + const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList) { bool bOk = MIstatus::success; lldb::SBFrame &rFrame = const_cast<lldb::SBFrame &>(vrFrame); @@ -748,7 +749,7 @@ CMICmnLLDBDebugSessionInfo::MIResponseFormVariableInfo3(const lldb::SBFrame &vrF for (MIuint i = 0; bOk && (i < nArgs); i++) { lldb::SBValue value = listArg.GetValueAtIndex(i); - bOk = GetVariableInfo2(nMaxRecusiveDepth, value, false, vwrMiValueList, nCurrentRecursiveDepth); + bOk = GetVariableInfo2(nMaxRecusiveDepth, value, false, veVarInfoFormat, vwrMiValueList, nCurrentRecursiveDepth); } return bOk; @@ -763,15 +764,17 @@ CMICmnLLDBDebugSessionInfo::MIResponseFormVariableInfo3(const lldb::SBFrame &vrF // vrValue - (R) LLDB value object. // vbIsChildValue - (R) True = Value object is a child of a higher Value object, // - False = Value object not a child. +// veVarInfoFormat - (R) The type of variable info that should be shown. // vwrMIValueList - (W) MI value list object. // vnDepth - (RW) The current recursive depth of this function. -// // Return: MIstatus::success - Functional succeeded. +// Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMICmnLLDBDebugSessionInfo::GetVariableInfo(const MIuint vnMaxDepth, const lldb::SBValue &vrValue, const bool vbIsChildValue, - CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth) + const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList, + MIuint &vrwnDepth) { // *** Update GetVariableInfo2() with any code changes here *** @@ -809,46 +812,78 @@ CMICmnLLDBDebugSessionInfo::GetVariableInfo(const MIuint vnMaxDepth, const lldb: else { // Basic types - const CMICmnMIValueConst miValueConst(utilValue.GetName()); - const CMICmnMIValueResult miValueResult("name", miValueConst); - miValueTuple.Add(miValueResult); - const CMICmnMIValueConst miValueConst2(utilValue.GetValue()); - const CMICmnMIValueResult miValueResult2("value", miValueConst2); - miValueTuple.Add(miValueResult2); + switch (veVarInfoFormat) + { + case eVariableInfoFormat_NoValues: + { + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + return vwrMiValueList.Add(miValueResult); + } + case eVariableInfoFormat_AllValues: + case eVariableInfoFormat_SimpleValues: + { + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + miValueTuple.Add(miValueResult); + const CMICmnMIValueConst miValueConst2(utilValue.GetValue()); + const CMICmnMIValueResult miValueResult2("value", miValueConst2); + miValueTuple.Add(miValueResult2); + break; + } + default: + break; + } return vwrMiValueList.Add(miValueTuple); } } else if (bIsPointerType && utilValue.IsChildCharType()) { - // Append string text to the parent value information - const CMICmnMIValueConst miValueConst(utilValue.GetName()); - const CMICmnMIValueResult miValueResult("name", miValueConst); - miValueTuple.Add(miValueResult); - - const CMIUtilString &rText(utilValue.GetChildValueCString()); - if (rText.empty()) - { - const CMICmnMIValueConst miValueConst(utilValue.GetValue()); - const CMICmnMIValueResult miValueResult("value", miValueConst); - miValueTuple.Add(miValueResult); - } - else + switch (veVarInfoFormat) { - if (utilValue.IsValueUnknown()) + case eVariableInfoFormat_NoValues: { - const CMICmnMIValueConst miValueConst(rText); - const CMICmnMIValueResult miValueResult("value", miValueConst); - miValueTuple.Add(miValueResult); + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + return vwrMiValueList.Add(miValueResult); } - else + case eVariableInfoFormat_AllValues: + case eVariableInfoFormat_SimpleValues: { - // Note code that has const in will not show the text suffix to the string pointer - // i.e. const char * pMyStr = "blah"; ==> "0x00007000"" <-- Eclipse shows this - // but char * pMyStr = "blah"; ==> "0x00007000" "blah"" <-- Eclipse shows this - const CMICmnMIValueConst miValueConst(CMIUtilString::Format("%s %s", utilValue.GetValue().c_str(), rText.c_str())); - const CMICmnMIValueResult miValueResult("value", miValueConst); + // Append string text to the parent value information + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); miValueTuple.Add(miValueResult); + + const CMIUtilString &rText(utilValue.GetChildValueCString()); + if (rText.empty()) + { + const CMICmnMIValueConst miValueConst(utilValue.GetValue()); + const CMICmnMIValueResult miValueResult("value", miValueConst); + miValueTuple.Add(miValueResult); + } + else + { + if (utilValue.IsValueUnknown()) + { + const CMICmnMIValueConst miValueConst(rText); + const CMICmnMIValueResult miValueResult("value", miValueConst); + miValueTuple.Add(miValueResult); + } + else + { + // Note code that has const in will not show the text suffix to the string pointer + // i.e. const char * pMyStr = "blah"; ==> "0x00007000"" <-- Eclipse shows this + // but char * pMyStr = "blah"; ==> "0x00007000" "blah"" <-- Eclipse shows this + const CMICmnMIValueConst miValueConst(CMIUtilString::Format("%s %s", utilValue.GetValue().c_str(), rText.c_str())); + const CMICmnMIValueResult miValueResult("value", miValueConst); + miValueTuple.Add(miValueResult); + } + } + break; } + default: + break; } return vwrMiValueList.Add(miValueTuple); } @@ -865,30 +900,62 @@ CMICmnLLDBDebugSessionInfo::GetVariableInfo(const MIuint vnMaxDepth, const lldb: else { // Basic types - const CMICmnMIValueConst miValueConst(utilValue.GetName()); - const CMICmnMIValueResult miValueResult("name", miValueConst); - miValueTuple.Add(miValueResult); - const CMICmnMIValueConst miValueConst2(utilValue.GetValue()); - const CMICmnMIValueResult miValueResult2("value", miValueConst2); - miValueTuple.Add(miValueResult2); + switch (veVarInfoFormat) + { + case eVariableInfoFormat_NoValues: + { + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + return vwrMiValueList.Add(miValueResult); + } + case eVariableInfoFormat_AllValues: + case eVariableInfoFormat_SimpleValues: + { + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + miValueTuple.Add(miValueResult); + const CMICmnMIValueConst miValueConst2(utilValue.GetValue()); + const CMICmnMIValueResult miValueResult2("value", miValueConst2); + miValueTuple.Add(miValueResult2); + break; + } + default: + break; + } return vwrMiValueList.Add(miValueTuple); } } else { - // Build parent child composite types - CMICmnMIValueList miValueList(true); - for (MIuint i = 0; bOk && (i < nChildren); i++) + switch (veVarInfoFormat) { - lldb::SBValue member = rValue.GetChildAtIndex(i); - bOk = GetVariableInfo(vnMaxDepth, member, true, miValueList, ++vrwnDepth); + case eVariableInfoFormat_NoValues: + { + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + return vwrMiValueList.Add(miValueResult); + } + case eVariableInfoFormat_AllValues: + case eVariableInfoFormat_SimpleValues: + { + // Build parent child composite types + CMICmnMIValueList miValueList(true); + for (MIuint i = 0; bOk && (i < nChildren); i++) + { + lldb::SBValue member = rValue.GetChildAtIndex(i); + bOk = GetVariableInfo(vnMaxDepth, member, true, veVarInfoFormat, miValueList, ++vrwnDepth); + } + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + miValueTuple.Add(miValueResult); + const CMICmnMIValueConst miValueConst2(CMIUtilString::Format("{%s}", miValueList.ExtractContentNoBrackets().c_str())); + const CMICmnMIValueResult miValueResult2("value", miValueConst2); + miValueTuple.Add(miValueResult2); + break; + } + default: + break; } - const CMICmnMIValueConst miValueConst(utilValue.GetName()); - const CMICmnMIValueResult miValueResult("name", miValueConst); - miValueTuple.Add(miValueResult); - const CMICmnMIValueConst miValueConst2(CMIUtilString::Format("{%s}", miValueList.ExtractContentNoBrackets().c_str())); - const CMICmnMIValueResult miValueResult2("value", miValueConst2); - miValueTuple.Add(miValueResult2); return vwrMiValueList.Add(miValueTuple); } } @@ -902,6 +969,7 @@ CMICmnLLDBDebugSessionInfo::GetVariableInfo(const MIuint vnMaxDepth, const lldb: // vrValue - (R) LLDB value object. // vbIsChildValue - (R) True = Value object is a child of a higher Value object, // - False = Value object not a child. +// veVarInfoFormat - (R) The type of variable info that should be shown. // vwrMIValueList - (W) MI value list object. // vnDepth - (RW) The current recursive depth of this function. // // Return: MIstatus::success - Functional succeeded. @@ -910,7 +978,8 @@ CMICmnLLDBDebugSessionInfo::GetVariableInfo(const MIuint vnMaxDepth, const lldb: //-- bool CMICmnLLDBDebugSessionInfo::GetVariableInfo2(const MIuint vnMaxDepth, const lldb::SBValue &vrValue, const bool vbIsChildValue, - CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth) + const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList, + MIuint &vrwnDepth) { // *** Update GetVariableInfo() with any code changes here *** @@ -937,64 +1006,112 @@ CMICmnLLDBDebugSessionInfo::GetVariableInfo2(const MIuint vnMaxDepth, const lldb else { // Basic types - const CMICmnMIValueConst miValueConst(utilValue.GetName()); - const CMICmnMIValueResult miValueResult("name", miValueConst); - miValueTuple.Add(miValueResult); - const CMICmnMIValueConst miValueConst2(utilValue.GetValue()); - const CMICmnMIValueResult miValueResult2("value", miValueConst2); - miValueTuple.Add(miValueResult2); + switch (veVarInfoFormat) + { + case eVariableInfoFormat_NoValues: + { + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + return vwrMiValueList.Add(miValueResult); + } + case eVariableInfoFormat_AllValues: + case eVariableInfoFormat_SimpleValues: + { + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + miValueTuple.Add(miValueResult); + const CMICmnMIValueConst miValueConst2(utilValue.GetValue()); + const CMICmnMIValueResult miValueResult2("value", miValueConst2); + miValueTuple.Add(miValueResult2); + break; + } + default: + break; + } return vwrMiValueList.Add(miValueTuple); } } else if (utilValue.IsChildCharType()) { - // Append string text to the parent value information - const CMICmnMIValueConst miValueConst(utilValue.GetName()); - const CMICmnMIValueResult miValueResult("name", miValueConst); - miValueTuple.Add(miValueResult); - - const CMIUtilString &rText(utilValue.GetChildValueCString()); - if (rText.empty()) - { - const CMICmnMIValueConst miValueConst(utilValue.GetValue()); - const CMICmnMIValueResult miValueResult("value", miValueConst); - miValueTuple.Add(miValueResult); - } - else + switch (veVarInfoFormat) { - if (utilValue.IsValueUnknown()) + case eVariableInfoFormat_NoValues: { - const CMICmnMIValueConst miValueConst(rText); - const CMICmnMIValueResult miValueResult("value", miValueConst); - miValueTuple.Add(miValueResult); + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + return vwrMiValueList.Add(miValueResult); } - else + case eVariableInfoFormat_AllValues: + case eVariableInfoFormat_SimpleValues: { - // Note code that has const in will not show the text suffix to the string pointer - // i.e. const char * pMyStr = "blah"; ==> "0x00007000"" <-- Eclipse shows this - // but char * pMyStr = "blah"; ==> "0x00007000" "blah"" <-- Eclipse shows this - const CMICmnMIValueConst miValueConst(CMIUtilString::Format("%s %s", utilValue.GetValue().c_str(), rText.c_str())); - const CMICmnMIValueResult miValueResult("value", miValueConst); + // Append string text to the parent value information + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); miValueTuple.Add(miValueResult); + + const CMIUtilString &rText(utilValue.GetChildValueCString()); + if (rText.empty()) + { + const CMICmnMIValueConst miValueConst(utilValue.GetValue()); + const CMICmnMIValueResult miValueResult("value", miValueConst); + miValueTuple.Add(miValueResult); + } + else + { + if (utilValue.IsValueUnknown()) + { + const CMICmnMIValueConst miValueConst(rText); + const CMICmnMIValueResult miValueResult("value", miValueConst); + miValueTuple.Add(miValueResult); + } + else + { + // Note code that has const in will not show the text suffix to the string pointer + // i.e. const char * pMyStr = "blah"; ==> "0x00007000"" <-- Eclipse shows this + // but char * pMyStr = "blah"; ==> "0x00007000" "blah"" <-- Eclipse shows this + const CMICmnMIValueConst miValueConst(CMIUtilString::Format("%s %s", utilValue.GetValue().c_str(), rText.c_str())); + const CMICmnMIValueResult miValueResult("value", miValueConst); + miValueTuple.Add(miValueResult); + } + } + break; } + default: + break; } return vwrMiValueList.Add(miValueTuple); } else { - // Build parent child composite types - CMICmnMIValueList miValueList(true); - for (MIuint i = 0; bOk && (i < nChildren); i++) + switch (veVarInfoFormat) { - lldb::SBValue member = rValue.GetChildAtIndex(i); - bOk = GetVariableInfo(vnMaxDepth, member, true, miValueList, ++vrwnDepth); + case eVariableInfoFormat_NoValues: + { + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + return vwrMiValueList.Add(miValueResult); + } + case eVariableInfoFormat_AllValues: + case eVariableInfoFormat_SimpleValues: + { + // Build parent child composite types + CMICmnMIValueList miValueList(true); + for (MIuint i = 0; bOk && (i < nChildren); i++) + { + lldb::SBValue member = rValue.GetChildAtIndex(i); + bOk = GetVariableInfo(vnMaxDepth, member, true, veVarInfoFormat, miValueList, ++vrwnDepth); + } + const CMICmnMIValueConst miValueConst(utilValue.GetName()); + const CMICmnMIValueResult miValueResult("name", miValueConst); + miValueTuple.Add(miValueResult); + const CMICmnMIValueConst miValueConst2(CMIUtilString::Format("{%s}", miValueList.ExtractContentNoBrackets().c_str())); + const CMICmnMIValueResult miValueResult2("value", miValueConst2); + miValueTuple.Add(miValueResult2); + break; + } + default: + break; } - const CMICmnMIValueConst miValueConst(utilValue.GetName()); - const CMICmnMIValueResult miValueResult("name", miValueConst); - miValueTuple.Add(miValueResult); - const CMICmnMIValueConst miValueConst2(CMIUtilString::Format("{%s}", miValueList.ExtractContentNoBrackets().c_str())); - const CMICmnMIValueResult miValueResult2("value", miValueConst2); - miValueTuple.Add(miValueResult2); return vwrMiValueList.Add(miValueTuple); } } @@ -1329,7 +1446,7 @@ CMICmnLLDBDebugSessionInfo::GetBrkPtInfo(const lldb::SBBreakpoint &vBrkPt, SBrkP const MIchar *pFn = pUnkwn; const MIchar *pFilePath = pUnkwn; size_t nLine = 0; - const size_t nAddr = brkPtAddr.GetLoadAddress(m_lldbTarget); + const size_t nAddr = brkPtAddr.GetLoadAddress(GetTarget()); lldb::SBCompileUnit rCmplUnit = symbolCntxt.GetCompileUnit(); if (rCmplUnit.IsValid()) @@ -1356,3 +1473,55 @@ CMICmnLLDBDebugSessionInfo::GetBrkPtInfo(const lldb::SBBreakpoint &vBrkPt, SBrkP return MIstatus::success; } + +//++ ------------------------------------------------------------------------------------ +// Details: Get current debugger. +// Type: Method. +// Args: None. +// Return: lldb::SBDebugger - current debugger. +// Throws: None. +//-- +lldb::SBDebugger & +CMICmnLLDBDebugSessionInfo::GetDebugger() const +{ + return CMICmnLLDBDebugger::Instance().GetTheDebugger(); +} + +//++ ------------------------------------------------------------------------------------ +// Details: Get current listener. +// Type: Method. +// Args: None. +// Return: lldb::SBListener - current listener. +// Throws: None. +//-- +lldb::SBListener & +CMICmnLLDBDebugSessionInfo::GetListener() const +{ + return CMICmnLLDBDebugger::Instance().GetTheListener(); +} + +//++ ------------------------------------------------------------------------------------ +// Details: Get current target. +// Type: Method. +// Args: None. +// Return: lldb::SBTarget - current target. +// Throws: None. +//-- +lldb::SBTarget +CMICmnLLDBDebugSessionInfo::GetTarget() const +{ + return GetDebugger().GetSelectedTarget(); +} + +//++ ------------------------------------------------------------------------------------ +// Details: Get current process. +// Type: Method. +// Args: None. +// Return: lldb::SBProcess - current process. +// Throws: None. +//-- +lldb::SBProcess +CMICmnLLDBDebugSessionInfo::GetProcess() const +{ + return GetTarget().GetProcess(); +} diff --git a/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h b/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h index e2463f1..2e592f1 100644 --- a/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h +++ b/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h @@ -24,10 +24,10 @@ // Third party headers: #include <map> #include <vector> -#include <lldb/API/SBDebugger.h> -#include <lldb/API/SBListener.h> -#include <lldb/API/SBProcess.h> -#include <lldb/API/SBTarget.h> +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBListener.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBTarget.h" // In-house headers: #include "MICmnBase.h" @@ -35,6 +35,7 @@ #include "MICmnLLDBDebugSessionInfoVarObj.h" #include "MICmnMIValueTuple.h" #include "MIUtilMapIdToVariant.h" +#include "MIUtilThreadBaseStd.h" // Declarations: class CMICmnLLDBDebugger; @@ -116,6 +117,17 @@ class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMIC eVariableType_Arguments = (1u << 3) // Arguments. }; + //++ =================================================================== + // Details: Determine the information that should be shown by using MIResponseFormVariableInfo family functions. + //-- + enum VariableInfoFormat_e + { + eVariableInfoFormat_NoValues, + eVariableInfoFormat_AllValues, + eVariableInfoFormat_SimpleValues, + kNumVariableInfoFormats + }; + // Typedefs: public: typedef std::vector<uint32_t> VecActiveThreadId_t; @@ -147,23 +159,27 @@ class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMIC bool MIResponseFormThreadInfo(const SMICmdData &vCmdData, const lldb::SBThread &vrThread, CMICmnMIValueTuple &vwrMIValueTuple); bool MIResponseFormThreadInfo2(const SMICmdData &vCmdData, const lldb::SBThread &vrThread, CMICmnMIValueTuple &vwrMIValueTuple); bool MIResponseFormThreadInfo3(const SMICmdData &vCmdData, const lldb::SBThread &vrThread, CMICmnMIValueTuple &vwrMIValueTuple); - bool MIResponseFormVariableInfo(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList &vwrMiValueList); - bool MIResponseFormVariableInfo2(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList &vwrMiValueList); - bool MIResponseFormVariableInfo3(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, CMICmnMIValueList &vwrMiValueList); + bool MIResponseFormVariableInfo(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, + const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList); + bool MIResponseFormVariableInfo2(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, + const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList); + bool MIResponseFormVariableInfo3(const lldb::SBFrame &vrFrame, const MIuint vMaskVarTypes, + const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList); bool MIResponseFormBrkPtFrameInfo(const SBrkPtInfo &vrBrkPtInfo, CMICmnMIValueTuple &vwrMiValueTuple); bool MIResponseFormBrkPtInfo(const SBrkPtInfo &vrBrkPtInfo, CMICmnMIValueTuple &vwrMiValueTuple); bool GetBrkPtInfo(const lldb::SBBreakpoint &vBrkPt, SBrkPtInfo &vrwBrkPtInfo) const; bool RecordBrkPtInfo(const MIuint vnBrkPtId, const SBrkPtInfo &vrBrkPtInfo); bool RecordBrkPtInfoGet(const MIuint vnBrkPtId, SBrkPtInfo &vrwBrkPtInfo) const; bool RecordBrkPtInfoDelete(const MIuint vnBrkPtId); + CMIUtilThreadMutex& GetSessionMutex() { return m_sessionMutex;} + lldb::SBDebugger &GetDebugger() const; + lldb::SBListener &GetListener() const; + lldb::SBTarget GetTarget() const; + lldb::SBProcess GetProcess() const; // Attributes: public: // The following are available to all command instances - lldb::SBDebugger &m_rLldbDebugger; - lldb::SBListener &m_rLlldbListener; - lldb::SBTarget m_lldbTarget; - lldb::SBProcess m_lldbProcess; const MIuint m_nBrkPointCntMax; VecActiveThreadId_t m_vecActiveThreadId; lldb::tid_t m_currentSelectedThread; @@ -186,9 +202,9 @@ class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMIC void operator=(const CMICmnLLDBDebugSessionInfo &); // bool GetVariableInfo(const MIuint vnMaxDepth, const lldb::SBValue &vrValue, const bool vbIsChildValue, - CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth); + const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth); bool GetVariableInfo2(const MIuint vnMaxDepth, const lldb::SBValue &vrValue, const bool vbIsChildValue, - CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth); + const VariableInfoFormat_e veVarInfoFormat, CMICmnMIValueList &vwrMiValueList, MIuint &vrwnDepth); // Overridden: private: @@ -200,6 +216,7 @@ class CMICmnLLDBDebugSessionInfo : public CMICmnBase, public MI::ISingleton<CMIC CMIUtilMapIdToVariant m_mapIdToSessionData; // Hold and retrieve key to value data available across all commands VecVarObj_t m_vecVarObj; // Vector of session variable objects MapBrkPtIdToBrkPtInfo_t m_mapBrkPtIdToBrkPtInfo; + CMIUtilThreadMutex m_sessionMutex; }; //++ ------------------------------------------------------------------------------------ diff --git a/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h b/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h index 94f62a4..ecc960c 100644 --- a/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h +++ b/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h @@ -23,7 +23,7 @@ // Third Party Headers: #include <map> -#include <lldb/API/SBValue.h> +#include "lldb/API/SBValue.h" // In-house headers: #include "MIUtilString.h" diff --git a/tools/lldb-mi/MICmnLLDBDebugger.cpp b/tools/lldb-mi/MICmnLLDBDebugger.cpp index 273b805..37ddda4 100644 --- a/tools/lldb-mi/MICmnLLDBDebugger.cpp +++ b/tools/lldb-mi/MICmnLLDBDebugger.cpp @@ -20,10 +20,10 @@ //-- // Third party headers: -#include <lldb/API/SBTarget.h> -#include <lldb/API/SBThread.h> -#include <lldb/API/SBProcess.h> -#include <lldb/API/SBCommandInterpreter.h> +#include "lldb/API/SBTarget.h" +#include "lldb/API/SBThread.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBCommandInterpreter.h" // In-house headers: #include "MICmnLLDBDebugger.h" @@ -148,7 +148,8 @@ CMICmnLLDBDebugger::Shutdown(void) // Explicitly delete the remote target in case MI needs to exit prematurely otherwise // LLDB debugger may hang in its Destroy() fn waiting on events - m_lldbDebugger.DeleteTarget(CMICmnLLDBDebugSessionInfo::Instance().m_lldbTarget); + lldb::SBTarget sbTarget = CMICmnLLDBDebugSessionInfo::Instance().GetTarget(); + m_lldbDebugger.DeleteTarget(sbTarget); // Debug: May need this but does seem to work without it so commented out the fudge 19/06/2014 // It appears we need to wait as hang does not occur when hitting a debug breakpoint here @@ -663,7 +664,13 @@ CMICmnLLDBDebugger::MonitorSBListenerEvents(bool &vrbIsAlive) bool bHandledEvent = false; bool bExitAppEvent = false; - const bool bOk = CMICmnLLDBDebuggerHandleEvents::Instance().HandleEvent(event, bHandledEvent, bExitAppEvent); + + bool bOk = false; + { + // Lock Mutex before handling events so that we don't disturb a running cmd + CMIUtilThreadLock lock(CMICmnLLDBDebugSessionInfo::Instance().GetSessionMutex()); + bOk = CMICmnLLDBDebuggerHandleEvents::Instance().HandleEvent(event, bHandledEvent, bExitAppEvent); + } if (!bHandledEvent) { const CMIUtilString msg(CMIUtilString::Format(MIRSRC(IDS_LLDBDEBUGGER_WRN_UNKNOWN_EVENT), event.GetBroadcasterClass())); diff --git a/tools/lldb-mi/MICmnLLDBDebugger.h b/tools/lldb-mi/MICmnLLDBDebugger.h index 6075fd8..403d71d 100644 --- a/tools/lldb-mi/MICmnLLDBDebugger.h +++ b/tools/lldb-mi/MICmnLLDBDebugger.h @@ -24,9 +24,9 @@ // Third party headers #include <queue> #include <map> -#include <lldb/API/SBDebugger.h> -#include <lldb/API/SBListener.h> -#include <lldb/API/SBEvent.h> +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBListener.h" +#include "lldb/API/SBEvent.h" // In-house headers: #include "MICmnBase.h" diff --git a/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp b/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp index b375611..50049e6 100644 --- a/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp +++ b/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp @@ -20,13 +20,13 @@ //-- // Third party headers: -#include <lldb/API/SBEvent.h> -#include <lldb/API/SBProcess.h> -#include <lldb/API/SBBreakpoint.h> -#include <lldb/API/SBStream.h> -#include <lldb/API/SBThread.h> -#include <lldb/API/SBCommandInterpreter.h> -#include <lldb/API/SBCommandReturnObject.h> +#include "lldb/API/SBEvent.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBBreakpoint.h" +#include "lldb/API/SBStream.h" +#include "lldb/API/SBThread.h" +#include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBCommandReturnObject.h" #ifdef _WIN32 #include <io.h> // For the ::_access() #else @@ -722,9 +722,9 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStateSuspended(const lldb::SBE return MIstatus::success; bool bOk = MIstatus::success; - lldb::SBDebugger &rDebugger = CMICmnLLDBDebugSessionInfo::Instance().m_rLldbDebugger; - lldb::SBProcess &rProcess = CMICmnLLDBDebugSessionInfo::Instance().m_lldbProcess; - lldb::SBTarget target = rProcess.GetTarget(); + lldb::SBDebugger &rDebugger = CMICmnLLDBDebugSessionInfo::Instance().GetDebugger(); + lldb::SBProcess sbProcess = CMICmnLLDBDebugSessionInfo::Instance().GetProcess(); + lldb::SBTarget target = sbProcess.GetTarget(); if (rDebugger.GetSelectedTarget() == target) { if (!UpdateSelectedThread()) @@ -768,8 +768,8 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStateStopped(bool &vwrbShouldB const MIchar *pEventType = ""; bool bOk = MIstatus::success; - lldb::SBProcess &rProcess = CMICmnLLDBDebugSessionInfo::Instance().m_lldbProcess; - const lldb::StopReason eStoppedReason = rProcess.GetSelectedThread().GetStopReason(); + lldb::SBProcess sbProcess = CMICmnLLDBDebugSessionInfo::Instance().GetProcess(); + const lldb::StopReason eStoppedReason = sbProcess.GetSelectedThread().GetStopReason(); switch (eStoppedReason) { case lldb::eStopReasonInvalid: @@ -807,6 +807,9 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStateStopped(bool &vwrbShouldB case lldb::eStopReasonThreadExiting: pEventType = "eStopReasonThreadExiting"; break; + case lldb::eStopReasonInstrumentation: + pEventType = "eStopReasonInstrumentation"; + break; } // ToDo: Remove when finished coding application @@ -828,8 +831,8 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopSignal(bool &vwrbShouldBrk { bool bOk = MIstatus::success; - lldb::SBProcess &rProcess = CMICmnLLDBDebugSessionInfo::Instance().m_lldbProcess; - const MIuint64 nStopReason = rProcess.GetSelectedThread().GetStopReasonDataAtIndex(0); + lldb::SBProcess sbProcess = CMICmnLLDBDebugSessionInfo::Instance().GetProcess(); + const MIuint64 nStopReason = sbProcess.GetSelectedThread().GetStopReasonDataAtIndex(0); switch (nStopReason) { case 2: // Terminal interrupt signal. SIGINT @@ -865,7 +868,7 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopSignal(bool &vwrbShouldBrk const CMICmnMIValueConst miValueConst3("Segmentation fault"); const CMICmnMIValueResult miValueResult3("signal-meaning", miValueConst3); bOk = bOk && miOutOfBandRecord.Add(miValueResult3); - const CMIUtilString strThreadId(CMIUtilString::Format("%d", rProcess.GetSelectedThread().GetIndexID())); + const CMIUtilString strThreadId(CMIUtilString::Format("%d", sbProcess.GetSelectedThread().GetIndexID())); const CMICmnMIValueConst miValueConst4(strThreadId); const CMICmnMIValueResult miValueResult4("thread-id", miValueConst4); bOk = bOk && miOutOfBandRecord.Add(miValueResult4); @@ -878,12 +881,12 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopSignal(bool &vwrbShouldBrk } break; case 19: - if (rProcess.IsValid()) - rProcess.Continue(); + if (sbProcess.IsValid()) + sbProcess.Continue(); break; case 5: // Trace/breakpoint trap. SIGTRAP { - lldb::SBThread thread = rProcess.GetSelectedThread(); + lldb::SBThread thread = sbProcess.GetSelectedThread(); const MIuint nFrames = thread.GetNumFrames(); if (nFrames > 0) { @@ -896,9 +899,9 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopSignal(bool &vwrbShouldBrk if (CMIUtilString::Compare(threadCloneFn, fnName)) { - if (rProcess.IsValid()) + if (sbProcess.IsValid()) { - rProcess.Continue(); + sbProcess.Continue(); vwrbShouldBrk = true; break; } @@ -939,8 +942,8 @@ bool CMICmnLLDBDebuggerHandleEvents::MiHelpGetCurrentThreadFrame(CMICmnMIValueTuple &vwrMiValueTuple) { CMIUtilString strThreadFrame; - lldb::SBProcess &rProcess = CMICmnLLDBDebugSessionInfo::Instance().m_lldbProcess; - lldb::SBThread thread = rProcess.GetSelectedThread(); + lldb::SBProcess sbProcess = CMICmnLLDBDebugSessionInfo::Instance().GetProcess(); + lldb::SBThread thread = sbProcess.GetSelectedThread(); const MIuint nFrame = thread.GetNumFrames(); if (nFrame == 0) { @@ -994,9 +997,9 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopReasonBreakpoint(void) return MIstatus::failure; } - lldb::SBProcess &rProcess = CMICmnLLDBDebugSessionInfo::Instance().m_lldbProcess; - const MIuint64 brkPtId = rProcess.GetSelectedThread().GetStopReasonDataAtIndex(0); - lldb::SBBreakpoint brkPt = CMICmnLLDBDebugSessionInfo::Instance().m_lldbTarget.GetBreakpointAtIndex((MIuint)brkPtId); + lldb::SBProcess sbProcess = CMICmnLLDBDebugSessionInfo::Instance().GetProcess(); + const MIuint64 brkPtId = sbProcess.GetSelectedThread().GetStopReasonDataAtIndex(0); + lldb::SBBreakpoint brkPt = CMICmnLLDBDebugSessionInfo::Instance().GetTarget().GetBreakpointAtIndex((MIuint)brkPtId); return MiStoppedAtBreakPoint(brkPtId, brkPt); } @@ -1015,8 +1018,8 @@ CMICmnLLDBDebuggerHandleEvents::MiStoppedAtBreakPoint(const MIuint64 vBrkPtId, c { bool bOk = MIstatus::success; - lldb::SBProcess &rProcess = CMICmnLLDBDebugSessionInfo::Instance().m_lldbProcess; - lldb::SBThread thread = rProcess.GetSelectedThread(); + lldb::SBProcess sbProcess = CMICmnLLDBDebugSessionInfo::Instance().GetProcess(); + lldb::SBThread thread = sbProcess.GetSelectedThread(); const MIuint nFrame = thread.GetNumFrames(); if (nFrame == 0) { @@ -1078,7 +1081,7 @@ CMICmnLLDBDebuggerHandleEvents::MiStoppedAtBreakPoint(const MIuint64 vBrkPtId, c { CMICmnMIValueList miValueList(true); const MIuint maskVarTypes = CMICmnLLDBDebugSessionInfo::eVariableType_Arguments; - bOk = rSession.MIResponseFormVariableInfo2(frame, maskVarTypes, miValueList); + bOk = rSession.MIResponseFormVariableInfo2(frame, maskVarTypes, CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_AllValues, miValueList); CMICmnMIValueTuple miValueTuple; bOk = bOk && rSession.MIResponseFormFrameInfo2(pc, miValueList.GetString(), fnName, fileName, path, nLine, miValueTuple); @@ -1118,8 +1121,8 @@ bool CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopReasonTrace(void) { bool bOk = true; - lldb::SBProcess &rProcess = CMICmnLLDBDebugSessionInfo::Instance().m_lldbProcess; - lldb::SBThread thread = rProcess.GetSelectedThread(); + lldb::SBProcess sbProcess = CMICmnLLDBDebugSessionInfo::Instance().GetProcess(); + lldb::SBThread thread = sbProcess.GetSelectedThread(); const MIuint nFrame = thread.GetNumFrames(); if (nFrame == 0) { @@ -1154,7 +1157,7 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopReasonTrace(void) // Function args CMICmnMIValueList miValueList(true); const MIuint maskVarTypes = CMICmnLLDBDebugSessionInfo::eVariableType_Arguments; - if (!rSession.MIResponseFormVariableInfo2(frame, maskVarTypes, miValueList)) + if (!rSession.MIResponseFormVariableInfo2(frame, maskVarTypes, CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_AllValues, miValueList)) return MIstatus::failure; CMICmnMIValueTuple miValueTuple; if (!rSession.MIResponseFormFrameInfo2(pc, miValueList.GetString(), fnName, fileName, path, nLine, miValueTuple)) @@ -1197,7 +1200,7 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopReasonTrace(void) bool CMICmnLLDBDebuggerHandleEvents::UpdateSelectedThread(void) { - lldb::SBProcess process = CMICmnLLDBDebugSessionInfo::Instance().m_rLldbDebugger.GetSelectedTarget().GetProcess(); + lldb::SBProcess process = CMICmnLLDBDebugSessionInfo::Instance().GetDebugger().GetSelectedTarget().GetProcess(); if (!process.IsValid()) return MIstatus::success; @@ -1339,7 +1342,7 @@ CMICmnLLDBDebuggerHandleEvents::GetProcessStdout(void) char c; size_t nBytes = 0; CMIUtilString text; - lldb::SBProcess process = CMICmnLLDBDebugSessionInfo::Instance().m_rLldbDebugger.GetSelectedTarget().GetProcess(); + lldb::SBProcess process = CMICmnLLDBDebugSessionInfo::Instance().GetDebugger().GetSelectedTarget().GetProcess(); while (process.GetSTDOUT(&c, 1) > 0) { CMIUtilString str; @@ -1374,7 +1377,7 @@ CMICmnLLDBDebuggerHandleEvents::GetProcessStderr(void) char c; size_t nBytes = 0; CMIUtilString text; - lldb::SBProcess process = CMICmnLLDBDebugSessionInfo::Instance().m_rLldbDebugger.GetSelectedTarget().GetProcess(); + lldb::SBProcess process = CMICmnLLDBDebugSessionInfo::Instance().GetDebugger().GetSelectedTarget().GetProcess(); while (process.GetSTDERR(&c, 1) > 0) { CMIUtilString str; @@ -1448,22 +1451,22 @@ CMICmnLLDBDebuggerHandleEvents::ConvertPrintfCtrlCodeToString(const MIchar vCtrl bool CMICmnLLDBDebuggerHandleEvents::ChkForStateChanges(void) { - lldb::SBProcess &rProcess = CMICmnLLDBDebugSessionInfo::Instance().m_lldbProcess; - if (!rProcess.IsValid()) + lldb::SBProcess sbProcess = CMICmnLLDBDebugSessionInfo::Instance().GetProcess(); + if (!sbProcess.IsValid()) return MIstatus::success; - lldb::SBTarget &rTarget = CMICmnLLDBDebugSessionInfo::Instance().m_lldbTarget; - if (!rTarget.IsValid()) + lldb::SBTarget sbTarget = CMICmnLLDBDebugSessionInfo::Instance().GetTarget(); + if (!sbTarget.IsValid()) return MIstatus::success; bool bOk = MIstatus::success; // Check for created threads - const MIuint nThread = rProcess.GetNumThreads(); + const MIuint nThread = sbProcess.GetNumThreads(); for (MIuint i = 0; i < nThread; i++) { // GetThreadAtIndex() uses a base 0 index // GetThreadByIndexID() uses a base 1 index - lldb::SBThread thread = rProcess.GetThreadAtIndex(i); + lldb::SBThread thread = sbProcess.GetThreadAtIndex(i); if (!thread.IsValid()) continue; @@ -1500,7 +1503,7 @@ CMICmnLLDBDebuggerHandleEvents::ChkForStateChanges(void) } } - lldb::SBThread currentThread = rProcess.GetSelectedThread(); + lldb::SBThread currentThread = sbProcess.GetSelectedThread(); if (currentThread.IsValid()) { const MIuint threadId = currentThread.GetIndexID(); @@ -1523,7 +1526,7 @@ CMICmnLLDBDebuggerHandleEvents::ChkForStateChanges(void) while (it != CMICmnLLDBDebugSessionInfo::Instance().m_vecActiveThreadId.end()) { const MIuint nThreadId = *it; - lldb::SBThread thread = rProcess.GetThreadAtIndex(nThreadId); + lldb::SBThread thread = sbProcess.GetThreadAtIndex(nThreadId); if (!thread.IsValid()) { // Form MI "=thread-exited,id=\"%ld\",group-id=\"i1\"" diff --git a/tools/lldb-mi/MICmnLLDBProxySBValue.cpp b/tools/lldb-mi/MICmnLLDBProxySBValue.cpp index a4f36b4..6a07f20 100644 --- a/tools/lldb-mi/MICmnLLDBProxySBValue.cpp +++ b/tools/lldb-mi/MICmnLLDBProxySBValue.cpp @@ -22,7 +22,7 @@ #include <stdlib.h> // Third Party Headers: -#include <lldb/API/SBError.h> +#include "lldb/API/SBError.h" // In-house headers: #include "MICmnLLDBProxySBValue.h" @@ -129,14 +129,14 @@ CMICmnLLDBProxySBValue::GetCString(const lldb::SBValue &vrValue, CMIUtilString & return MIstatus::failure; CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); - lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess; + lldb::SBProcess sbProcess = rSessionInfo.GetProcess(); MIuint nBufferSize = 64; bool bNeedResize = false; MIchar *pBuffer = static_cast<MIchar *>(::malloc(nBufferSize)); do { lldb::SBError error; - const size_t nReadSize = rProcess.ReadCStringFromMemory((lldb::addr_t)nNum, pBuffer, nBufferSize, error); + const size_t nReadSize = sbProcess.ReadCStringFromMemory((lldb::addr_t)nNum, pBuffer, nBufferSize, error); if (nReadSize == (nBufferSize - 1)) { bNeedResize = true; diff --git a/tools/lldb-mi/MICmnLLDBProxySBValue.h b/tools/lldb-mi/MICmnLLDBProxySBValue.h index e21eb95..39befe9 100644 --- a/tools/lldb-mi/MICmnLLDBProxySBValue.h +++ b/tools/lldb-mi/MICmnLLDBProxySBValue.h @@ -22,7 +22,7 @@ #pragma once // Third Party Headers: -#include <lldb/API/SBValue.h> +#include "lldb/API/SBValue.h" // In-house headers: #include "MIDataTypes.h" diff --git a/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp b/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp index 847bba2..66a4efd 100644 --- a/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp +++ b/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp @@ -219,7 +219,7 @@ CMICmnLLDBUtilSBValue::ReadCStringFromHostMemory(const lldb::SBValue &vrValueObj const MIuint nBytes(128); const MIchar *pBufferMemory = new MIchar[nBytes]; lldb::SBError error; - const MIuint64 nReadBytes = rSessionInfo.m_lldbProcess.ReadMemory(addr, (void *)pBufferMemory, nBytes, error); + const MIuint64 nReadBytes = rSessionInfo.GetProcess().ReadMemory(addr, (void *)pBufferMemory, nBytes, error); MIunused(nReadBytes); text = CMIUtilString::Format("\\\"%s\\\"", pBufferMemory); delete[] pBufferMemory; diff --git a/tools/lldb-mi/MICmnLLDBUtilSBValue.h b/tools/lldb-mi/MICmnLLDBUtilSBValue.h index 1aa3022..a3f2c9c 100644 --- a/tools/lldb-mi/MICmnLLDBUtilSBValue.h +++ b/tools/lldb-mi/MICmnLLDBUtilSBValue.h @@ -22,7 +22,7 @@ #pragma once // Third Party Headers: -#include <lldb/API/SBValue.h> +#include "lldb/API/SBValue.h" // In-house headers: #include "MIDataTypes.h" diff --git a/tools/lldb-mi/MICmnLog.cpp b/tools/lldb-mi/MICmnLog.cpp index a18fd2d..dc7a93d 100644 --- a/tools/lldb-mi/MICmnLog.cpp +++ b/tools/lldb-mi/MICmnLog.cpp @@ -73,7 +73,6 @@ CMICmnLog::Initialize(void) // Mediums set inside because explicitly initing in MIDriverMain.cpp causes compile errors with CAtlFile CMICmnLogMediumFile &rFileLog(CMICmnLogMediumFile::Instance()); bool bOk = RegisterMedium(rFileLog); - bOk = bOk && SetEnabled(true); if (bOk) { // Set the Log trace file's header diff --git a/tools/lldb-mi/MICmnResources.cpp b/tools/lldb-mi/MICmnResources.cpp index 676e9e7..bc1fa30 100644 --- a/tools/lldb-mi/MICmnResources.cpp +++ b/tools/lldb-mi/MICmnResources.cpp @@ -82,7 +82,7 @@ const CMICmnResources::SRsrcTextData CMICmnResources::ms_pResourceId2TextData[] {IDE_MI_APP_ARG_EXECUTEABLE, "--executable\n\tUse the MI Driver in MI mode for the debugging the specified\n\texecutable. Any LLDB " "command line options are ignored even\n\tif the MI Driver falls through to the LLDB driver. " "(Depends\n\ton the build configuration see MICmnConfig.h)\n\tNormally specified from the command line."}, - {IDE_MI_APP_ARG_NO_APP_LOG, "--noLog\n\tUse this argument to tell the MI Driver not to update it's log\n\tfile '%s'."}, + {IDE_MI_APP_ARG_APP_LOG, "--log\n\tUse this argument to tell the MI Driver to update it's log\n\tfile '%s'."}, {IDE_MI_APP_ARG_EXAMPLE, "Example MI command:\n\t3-info-gdb-mi-command gdb-set\n\t3^done,command={exists=\"true\"}"}, {IDE_MI_APP_ARG_EXECUTABLE, "executable (NOT IMPLEMENTED)\n\tThe file path to the executable i.e. '\"C:\\My Dev\\foo.exe\"'."}, {IDS_STDIN_ERR_INVALID_PROMPT, "Stdin. Invalid prompt description '%s'"}, @@ -254,6 +254,7 @@ const CMICmnResources::SRsrcTextData CMICmnResources::ms_pResourceId2TextData[] {IDS_CMD_ERR_LLDB_ERR_NOT_READ_WHOLE_BLK, "Command '%s'. LLDB unable to read entire memory block of %u bytes at address 0x%08x"}, {IDS_CMD_ERR_LLDB_ERR_READ_MEM_BYTES, "Command '%s'. Unable to read memory block of %u bytes at address 0x%08x: %s "}, {IDS_CMD_ERR_INVALID_PROCESS, "Command '%s'. Invalid process during debug session"}, + {IDS_CMD_ERR_INVALID_PRINT_VALUES, "Command '%s'. Unknown value for PRINT_VALUES: must be: 0 or \"--no-values\", 1 or \"all-values\", 2 or \"simple-values\""}, {IDS_CMD_ERR_INVALID_FORMAT_TYPE, "Command '%s'. Invalid var format type '%s'"}, {IDS_CMD_ERR_BRKPT_INFO_OBJ_NOT_FOUND, "Command '%s'. Breakpoint information for breakpoint ID %d not found"}, {IDS_CMD_ERR_LLDB_ERR_READ_MEM_BYTES, "Command '%s'. Unable to write memory block of %u bytes at address 0x%08x: %s "}, diff --git a/tools/lldb-mi/MICmnResources.h b/tools/lldb-mi/MICmnResources.h index cd9208c..b561473 100644 --- a/tools/lldb-mi/MICmnResources.h +++ b/tools/lldb-mi/MICmnResources.h @@ -89,7 +89,7 @@ enum IDE_MI_APP_ARG_VERSION_LONG, IDE_MI_APP_ARG_INTERPRETER, IDE_MI_APP_ARG_EXECUTEABLE, - IDE_MI_APP_ARG_NO_APP_LOG, + IDE_MI_APP_ARG_APP_LOG, IDE_MI_APP_ARG_EXAMPLE, IDE_MI_APP_ARG_EXECUTABLE, @@ -270,6 +270,7 @@ enum IDS_CMD_ERR_LLDB_ERR_NOT_READ_WHOLE_BLK, IDS_CMD_ERR_LLDB_ERR_READ_MEM_BYTES, IDS_CMD_ERR_INVALID_PROCESS, + IDS_CMD_ERR_INVALID_PRINT_VALUES, IDS_CMD_ERR_INVALID_FORMAT_TYPE, IDS_CMD_ERR_BRKPT_INFO_OBJ_NOT_FOUND, IDS_CMD_ERR_LLDB_ERR_WRITE_MEM_BYTES, diff --git a/tools/lldb-mi/MIDriver.cpp b/tools/lldb-mi/MIDriver.cpp index accde1c..5628e34 100644 --- a/tools/lldb-mi/MIDriver.cpp +++ b/tools/lldb-mi/MIDriver.cpp @@ -22,7 +22,7 @@ // Third party headers: #include <stdarg.h> // va_list, va_start, var_end #include <iostream> -#include <lldb/API/SBError.h> +#include "lldb/API/SBError.h" // In-house headers: #include "Driver.h" @@ -41,6 +41,7 @@ #include "MICmdArgValFile.h" #include "MICmdArgValString.h" #include "MICmnConfig.h" +#include "MICmnLLDBDebugSessionInfo.h" // Instantiations: #if _DEBUG @@ -687,7 +688,13 @@ CMIDriver::ReadStdinLineQueue(void) } // Process the command - const bool bOk = InterpretCommand(lineText); + bool bOk = false; + { + // Lock Mutex before processing commands so that we don't disturb an event + // that is being processed. + CMIUtilThreadLock lock(CMICmnLLDBDebugSessionInfo::Instance().GetSessionMutex()); + bOk = InterpretCommand(lineText); + } // Draw prompt if desired if (bOk && m_rStdin.GetEnablePrompt()) diff --git a/tools/lldb-mi/MIDriverBase.cpp b/tools/lldb-mi/MIDriverBase.cpp index fd9fae8..fd1a0ec 100644 --- a/tools/lldb-mi/MIDriverBase.cpp +++ b/tools/lldb-mi/MIDriverBase.cpp @@ -20,8 +20,8 @@ //-- // Third party headers: -#include <lldb/API/SBEvent.h> -#include <lldb/API/SBBroadcaster.h> +#include "lldb/API/SBEvent.h" +#include "lldb/API/SBBroadcaster.h" // In-house headers: #include "MIDriverBase.h" diff --git a/tools/lldb-mi/MIDriverBase.h b/tools/lldb-mi/MIDriverBase.h index 7516efd..25ac238 100644 --- a/tools/lldb-mi/MIDriverBase.h +++ b/tools/lldb-mi/MIDriverBase.h @@ -22,8 +22,8 @@ #pragma once // Third party headers: -#include <lldb/API/SBDebugger.h> -#include <lldb/API/SBBroadcaster.h> +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBBroadcaster.h" // In-house headers: #include "MIUtilString.h" diff --git a/tools/lldb-mi/MIDriverMain.cpp b/tools/lldb-mi/MIDriverMain.cpp index b14fb81..5557799 100644 --- a/tools/lldb-mi/MIDriverMain.cpp +++ b/tools/lldb-mi/MIDriverMain.cpp @@ -49,7 +49,7 @@ // Third party headers: #include <stdio.h> -#include <lldb/API/SBHostOS.h> +#include "lldb/API/SBHostOS.h" // In house headers: #include "MICmnConfig.h" @@ -81,6 +81,9 @@ void sigwinch_handler(int vSigno) { +#ifdef _WIN32 // Restore handler as it is not persistent on Windows + signal(SIGWINCH, sigwinch_handler); +#endif MIunused(vSigno); struct winsize window_size; @@ -111,6 +114,9 @@ sigwinch_handler(int vSigno) void sigint_handler(int vSigno) { +#ifdef _WIN32 // Restore handler as it is not persistent on Windows + signal(SIGINT, sigint_handler); +#endif static bool g_interrupt_sent = false; CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance(); lldb::SBDebugger *pDebugger = rDriverMgr.DriverGetTheDebugger(); @@ -147,6 +153,9 @@ sigint_handler(int vSigno) void sigtstp_handler(int vSigno) { +#ifdef _WIN32 // Restore handler as it is not persistent on Windows + signal(SIGTSTP, sigtstp_handler); +#endif CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance(); lldb::SBDebugger *pDebugger = rDriverMgr.DriverGetTheDebugger(); if (pDebugger != nullptr) @@ -175,6 +184,9 @@ sigtstp_handler(int vSigno) void sigcont_handler(int vSigno) { +#ifdef _WIN32 // Restore handler as it is not persistent on Windows + signal(SIGCONT, sigcont_handler); +#endif CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance(); lldb::SBDebugger *pDebugger = rDriverMgr.DriverGetTheDebugger(); if (pDebugger != nullptr) diff --git a/tools/lldb-mi/MIDriverMgr.cpp b/tools/lldb-mi/MIDriverMgr.cpp index 79b44ca..ca900ca 100644 --- a/tools/lldb-mi/MIDriverMgr.cpp +++ b/tools/lldb-mi/MIDriverMgr.cpp @@ -20,7 +20,7 @@ //-- // Third Party Headers: -#include <lldb/API/SBError.h> +#include "lldb/API/SBError.h" // In-house headers: #include "MIDriverMgr.h" @@ -125,8 +125,6 @@ CMIDriverMgr::Shutdown(void) if (vbAppExitOk) { - // The MI Driver's log updating may have been switched off switch back on to say all is ok. - CMICmnLog::Instance().SetEnabled(true); #if _DEBUG CMICmnStreamStdout::Instance().Write(MIRSRC(IDE_MI_APP_EXIT_OK)); // Both stdout and Log #else @@ -144,8 +142,6 @@ CMIDriverMgr::Shutdown(void) } else { - // The MI Driver's log updating may have been switched off switch back on to say there has been problem. - rAppLog.SetEnabled(true); const CMIUtilString msg( CMIUtilString::Format(MIRSRC(IDE_MI_APP_EXIT_WITH_PROBLEM_NO_LOG), CMICmnLogMediumFile::Instance().GetFileName().c_str())); CMICmnStreamStdout::Instance().Write(msg); @@ -495,7 +491,7 @@ CMIDriverMgr::DriverGetTheDebugger(void) // --interpreter // --version // --versionLong -// --noLog +// --log // --executable // The above arguments are not handled by any driver object except for --executable. // The options --interpreter and --executable in code act very similar. The @@ -552,7 +548,7 @@ CMIDriverMgr::ParseArgs(const int argc, const char *argv[], bool &vwbExiting) bool bHaveArgInterpret = false; bool bHaveArgVersion = false; bool bHaveArgVersionLong = false; - bool bHaveArgNoLog = false; + bool bHaveArgLog = false; bool bHaveArgHelp = false; // Hardcode the use of the MI driver @@ -582,9 +578,9 @@ CMIDriverMgr::ParseArgs(const int argc, const char *argv[], bool &vwbExiting) { bHaveArgVersionLong = true; } - if (0 == strArg.compare("--noLog")) + if (0 == strArg.compare("--log")) { - bHaveArgNoLog = true; + bHaveArgLog = true; } if ((0 == strArg.compare("--help")) || (0 == strArg.compare("-h"))) { @@ -593,9 +589,9 @@ CMIDriverMgr::ParseArgs(const int argc, const char *argv[], bool &vwbExiting) } } - if (bHaveArgNoLog) + if (bHaveArgLog) { - CMICmnLog::Instance().SetEnabled(false); + CMICmnLog::Instance().SetEnabled(true); } // Todo: Remove this output when MI is finished. It is temporary to persuade Ecllipse plugin to work. @@ -687,7 +683,7 @@ CMIDriverMgr::GetHelpOnCmdLineArgOptions(void) const MIRSRC(IDE_MI_APP_ARG_VERSION_LONG), MIRSRC(IDE_MI_APP_ARG_INTERPRETER), MIRSRC(IDE_MI_APP_ARG_EXECUTEABLE), - CMIUtilString::Format(MIRSRC(IDE_MI_APP_ARG_NO_APP_LOG), CMICmnLogMediumFile::Instance().GetFileName().c_str()), + CMIUtilString::Format(MIRSRC(IDE_MI_APP_ARG_APP_LOG), CMICmnLogMediumFile::Instance().GetFileName().c_str()), MIRSRC(IDE_MI_APP_ARG_EXECUTABLE), MIRSRC(IDS_CMD_QUIT_HELP), MIRSRC(IDE_MI_APP_ARG_EXAMPLE)}; diff --git a/tools/lldb-mi/MIDriverMgr.h b/tools/lldb-mi/MIDriverMgr.h index d944927..9e1e121 100644 --- a/tools/lldb-mi/MIDriverMgr.h +++ b/tools/lldb-mi/MIDriverMgr.h @@ -23,7 +23,7 @@ // Third party headers: #include <map> -#include <lldb/API/SBDebugger.h> +#include "lldb/API/SBDebugger.h" // In-house headers: #include "MICmnBase.h" diff --git a/tools/lldb-mi/MIReadMe.txt b/tools/lldb-mi/MIReadMe.txt index fbd3b2d..47d28e3 100644 --- a/tools/lldb-mi/MIReadMe.txt +++ b/tools/lldb-mi/MIReadMe.txt @@ -1,5 +1,5 @@ ======================================================================== - The MI Driver - LLDB Machine Interface V2 (MI) Project Overview + The MI Driver - LLDB Machine Interface V2 (MI) Project Overview 24/07/2014 ======================================================================== |