1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
|
//===-- MIDriverMgr.cpp -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Third Party Headers:
#include "lldb/API/SBError.h"
// In-house headers:
#include "MIDriverMgr.h"
#include "MICmnResources.h"
#include "MICmnLog.h"
#include "MICmnLogMediumFile.h"
#include "MIDriver.h"
#include "MICmnStreamStdout.h"
#include "MIUtilSingletonHelper.h"
//++ ------------------------------------------------------------------------------------
// Details: CMIDriverMgr constructor.
// Type: Method.
// Args: None.
// Return: None.
// Throws: None.
//--
CMIDriverMgr::CMIDriverMgr()
: m_pDriverCurrent(nullptr)
, m_bInMi2Mode(false)
{
}
//++ ------------------------------------------------------------------------------------
// Details: CMIDriverMgr destructor.
// Type: Overridden.
// Args: None.
// Return: None.
// Throws: None.
//--
CMIDriverMgr::~CMIDriverMgr()
{
Shutdown();
}
//++ ------------------------------------------------------------------------------------
// Details: Initialize *this manager.
// Type: Method.
// Args: None.
// Return: MIstatus::success - Functional succeeded.
// MIstatus::failure - Functional failed.
// Throws: None.
//--
bool
CMIDriverMgr::Initialize()
{
m_clientUsageRefCnt++;
ClrErrorDescription();
if (m_bInitialized)
return MIstatus::success;
bool bOk = MIstatus::success;
CMIUtilString errMsg;
// Note initialisation order is important here as some resources depend on previous
MI::ModuleInit<CMICmnLog>(IDS_MI_INIT_ERR_LOG, bOk, errMsg);
MI::ModuleInit<CMICmnResources>(IDS_MI_INIT_ERR_RESOURCES, bOk, errMsg);
m_bInitialized = bOk;
if (!bOk)
{
CMIUtilString strInitError(CMIUtilString::Format(MIRSRC(IDS_MI_INIT_ERR_DRIVERMGR), errMsg.c_str()));
SetErrorDescription(strInitError);
return MIstatus::failure;
}
return bOk;
}
//++ ------------------------------------------------------------------------------------
// Details: Unbind detach or release resources used by this server in general common
// functionality shared between versions of any server interfaces implemented.
// Type: Method.
// Args: vbAppExitOk - (R) True = No problems, false = App exiting with problems (investigate!).
// Return: MIstatus::success - Functional succeeded.
// MIstatus::failure - Functional failed.
// Throws: None.
//--
bool
CMIDriverMgr::Shutdown()
{
// Do not want a ref counter because this function needs to be called how ever this
// application stops running
// if( --m_clientUsageRefCnt > 0 )
// return MIstatus::success;
ClrErrorDescription();
if (!m_bInitialized)
return MIstatus::success;
m_bInitialized = false;
bool bOk = MIstatus::success;
CMIUtilString errMsg;
// Tidy up
UnregisterDriverAll();
// Note shutdown order is important here
MI::ModuleShutdown<CMICmnResources>(IDE_MI_SHTDWN_ERR_RESOURCES, bOk, errMsg);
MI::ModuleShutdown<CMICmnLog>(IDS_MI_SHTDWN_ERR_LOG, bOk, errMsg);
if (!bOk)
{
SetErrorDescriptionn(MIRSRC(IDS_MI_SHTDWN_ERR_DRIVERMGR), errMsg.c_str());
}
return bOk;
}
//++ ------------------------------------------------------------------------------------
// Details: Unregister all the Driver registered with *this manager. The manager also
// deletes
// Type: Method.
// Args: None.
// Return: MIstatus::success - Functional succeeded.
// MIstatus::failure - Functional failed.
// Throws: None.
//--
bool
CMIDriverMgr::UnregisterDriverAll()
{
MapDriverIdToDriver_t::const_iterator it = m_mapDriverIdToDriver.begin();
while (it != m_mapDriverIdToDriver.end())
{
IDriver *pDriver = (*it).second;
pDriver->DoShutdown();
// Next
++it;
}
m_mapDriverIdToDriver.clear();
m_pDriverCurrent = NULL;
return MIstatus::success;
}
//++ ------------------------------------------------------------------------------------
// Details: Register a driver with *this Driver Manager. Call SetUseThisDriverToDoWork()
// inform the manager which driver is the one to the work. The manager calls
// the driver's init function which must be successful in order to complete the
// registration.
// Type: Method.
// Args: vrDriver - (R) The driver to register.
// vrDriverID - (R) The driver's ID to lookup by.
// Return: MIstatus::success - Functional succeeded.
// MIstatus::failure - Functional failed.
// Throws: None.
//--
bool
CMIDriverMgr::RegisterDriver(const IDriver &vrDriver, const CMIUtilString &vrDriverID)
{
if (HaveDriverAlready(vrDriver))
return MIstatus::success;
IDriver *pDriver = const_cast<IDriver *>(&vrDriver);
if (!pDriver->SetId(vrDriverID))
return MIstatus::failure;
if (!pDriver->DoInitialize())
{
SetErrorDescriptionn(MIRSRC(IDS_DRIVERMGR_DRIVER_ERR_INIT), pDriver->GetName().c_str(), vrDriverID.c_str(),
pDriver->GetError().c_str());
return MIstatus::failure;
}
MapPairDriverIdToDriver_t pr(vrDriverID, pDriver);
m_mapDriverIdToDriver.insert(pr);
return MIstatus::success;
}
//++ ------------------------------------------------------------------------------------
// Details: Query the Driver Manager to see if *this manager has the driver already
// registered.
// Type: Method.
// Args: vrDriver - (R) The driver to query.
// Return: True - registered.
// False - not registered.
// Throws: None.
//--
bool
CMIDriverMgr::HaveDriverAlready(const IDriver &vrDriver) const
{
MapDriverIdToDriver_t::const_iterator it = m_mapDriverIdToDriver.begin();
while (it != m_mapDriverIdToDriver.end())
{
const IDriver *pDrvr = (*it).second;
if (pDrvr == &vrDriver)
return true;
// Next
++it;
}
return false;
}
//++ ------------------------------------------------------------------------------------
// Details: Unregister a driver from the Driver Manager. Call the SetUseThisDriverToDoWork()
// function to define another driver to do work if the one being unregistered did
// the work previously.
// Type: Method.
// Args: vrDriver - (R) The driver to unregister.
// Return: MIstatus::success - Functional succeeded.
// MIstatus::failure - Functional failed.
// Throws: None.
//--
bool
CMIDriverMgr::UnregisterDriver(const IDriver &vrDriver)
{
const IDriver *pDrvr = nullptr;
MapDriverIdToDriver_t::const_iterator it = m_mapDriverIdToDriver.begin();
while (it != m_mapDriverIdToDriver.end())
{
pDrvr = (*it).second;
if (pDrvr == &vrDriver)
break;
// Next
++it;
}
m_mapDriverIdToDriver.erase(it);
if (m_pDriverCurrent == pDrvr)
m_pDriverCurrent = nullptr;
return MIstatus::success;
}
//++ ------------------------------------------------------------------------------------
// Details: Specify the driver to do work. The Driver Manager drives this driver. Any
// previous driver doing work is not called anymore (so be sure the previous
// driver is in a tidy state before stopping it working).
// Type: Method.
// Args: vrADriver - (R) A lldb::SBBroadcaster/IDriver derived object.
// Return: MIstatus::success - Functional succeeded.
// MIstatus::failure - Functional failed.
// Throws: None.
//--
bool
CMIDriverMgr::SetUseThisDriverToDoWork(const IDriver &vrADriver)
{
m_pDriverCurrent = const_cast<IDriver *>(&vrADriver);
const CMIUtilString msg(CMIUtilString::Format(MIRSRC(IDS_DRIVER_SAY_DRIVER_USING), m_pDriverCurrent->GetName().c_str()));
m_pLog->Write(msg, CMICmnLog::eLogVerbosity_Log);
m_bInMi2Mode = m_pDriverCurrent->GetDriverIsGDBMICompatibleDriver();
return MIstatus::success;
}
//++ ------------------------------------------------------------------------------------
// Details: Ask *this manager which driver is currently doing the work.
// Type: Method.
// Args: None.
// Return: IDriver * - Pointer to a driver, NULL if there is no current working driver.
// Throws: None.
//--
CMIDriverMgr::IDriver *
CMIDriverMgr::GetUseThisDriverToDoWork() const
{
return m_pDriverCurrent;
}
//++ ------------------------------------------------------------------------------------
// Details: Call this function puts *this driver to work.
// Type: Method.
// Args: None.
// Return: MIstatus::success - Functional succeeded.
// MIstatus::failure - Functional failed.
// Throws: None.
//--
bool
CMIDriverMgr::DriverMainLoop()
{
if (m_pDriverCurrent != nullptr)
{
if (!m_pDriverCurrent->DoMainLoop())
{
const CMIUtilString errMsg(CMIUtilString::Format(MIRSRC(IDS_DRIVER_ERR_MAINLOOP), m_pDriverCurrent->GetError().c_str()));
CMICmnStreamStdout::Instance().Write(errMsg, true);
return MIstatus::failure;
}
}
else
{
const CMIUtilString errMsg(MIRSRC(IDS_DRIVER_ERR_CURRENT_NOT_SET));
CMICmnStreamStdout::Instance().Write(errMsg, true);
return MIstatus::failure;
}
return MIstatus::success;
}
//++ ------------------------------------------------------------------------------------
// Details: Get the current driver to validate executable command line arguments.
// Type: Method.
// Args: argc - (R) An integer that contains the count of arguments that follow in
// argv. The argc parameter is always greater than or equal to 1.
// argv - (R) An array of null-terminated strings representing command-line
// arguments entered by the user of the program. By convention,
// argv[0] is the command with which the program is invoked.
// vpStdOut - (R) Point to a standard output stream.
// vwbExiting - (W) True = *this want to exit, false = continue to work.
// Return: MIstatus::success - Functional succeeded.
// MIstatus::failure - Functional failed.
// Throws: None.
//--
bool
CMIDriverMgr::DriverParseArgs(const int argc, const char *argv[], FILE *vpStdOut, bool &vwbExiting)
{
if (m_pDriverCurrent == nullptr)
{
const CMIUtilString errMsg(MIRSRC(IDS_DRIVER_ERR_CURRENT_NOT_SET));
CMICmnStreamStdout::Instance().Write(errMsg, true);
return MIstatus::failure;
}
const lldb::SBError error(m_pDriverCurrent->DoParseArgs(argc, argv, vpStdOut, vwbExiting));
bool bOk = !error.Fail();
if (!bOk)
{
CMIUtilString errMsg;
const char *pErrorCstr = error.GetCString();
if (pErrorCstr != nullptr)
errMsg = CMIUtilString::Format(MIRSRC(IDS_DRIVER_ERR_PARSE_ARGS), m_pDriverCurrent->GetName().c_str(), pErrorCstr);
else
errMsg = CMIUtilString::Format(MIRSRC(IDS_DRIVER_ERR_PARSE_ARGS_UNKNOWN), m_pDriverCurrent->GetName().c_str());
bOk = CMICmnStreamStdout::Instance().Write(errMsg, true);
}
return bOk;
}
//++ ------------------------------------------------------------------------------------
// Details: Retrieve the current driver's last error condition.
// Type: Method.
// Args: None.
// Return: CMIUtilString - Text description.
// Throws: None.
//--
CMIUtilString
CMIDriverMgr::DriverGetError() const
{
if (m_pDriverCurrent != nullptr)
return m_pDriverCurrent->GetError();
else
{
const CMIUtilString errMsg(MIRSRC(IDS_DRIVER_ERR_CURRENT_NOT_SET));
CMICmnStreamStdout::Instance().Write(errMsg, true);
}
return CMIUtilString();
}
//++ ------------------------------------------------------------------------------------
// Details: Retrieve the current driver's name.
// Type: Method.
// Args: None.
// Return: CMIUtilString - Driver name.
// Empty string = no current working driver specified.
// Throws: None.
//--
CMIUtilString
CMIDriverMgr::DriverGetName() const
{
if (m_pDriverCurrent != nullptr)
return m_pDriverCurrent->GetName();
else
{
const CMIUtilString errMsg(MIRSRC(IDS_DRIVER_ERR_CURRENT_NOT_SET));
CMICmnStreamStdout::Instance().Write(errMsg, true);
}
return CMIUtilString();
}
//++ ------------------------------------------------------------------------------------
// Details: Retrieve the current driver's debugger object.
// Type: Method.
// Args: None.
// Return: lldb::SBDebugger * - Ptr to driver's debugger object.
// - NULL = no current working driver specified.
// Throws: None.
//--
lldb::SBDebugger *
CMIDriverMgr::DriverGetTheDebugger()
{
lldb::SBDebugger *pDebugger = nullptr;
if (m_pDriverCurrent != nullptr)
pDebugger = &m_pDriverCurrent->GetTheDebugger();
else
{
const CMIUtilString errMsg(MIRSRC(IDS_DRIVER_ERR_CURRENT_NOT_SET));
CMICmnStreamStdout::Instance().Write(errMsg, true);
}
return pDebugger;
}
//++ ------------------------------------------------------------------------------------
// Details: Check the arguments given on the command line. The main purpose of this
// function is to check for the presence of the --interpreter option. Having
// this option present tells *this manager to set the CMIDriver to do work. If
// not use the LLDB driver. The following are options that are only handled by
// the CMIDriverMgr are:
// --help or -h
// --interpreter
// --version
// --versionLong
// --log
// --executable
// --log-dir
// The above arguments are not handled by any driver object except for --executable.
// The options --interpreter and --executable in code act very similar. The
// --executable is necessary to differentiate whither the MI Driver is being using
// by a client i.e. Eclipse or from the command line. Eclipse issues the option
// --interpreter and also passes additional arguments which can be interpreted as an
// executable if called from the command line. Using --executable tells the MI
// Driver is being called the command line and that the executable argument is indeed
// a specified executable an so actions commands to set up the executable for a
// debug session. Using --interpreter on the command line does not action additional
// commands to initialise a debug session and so be able to launch the process. The directory
// where the log file is created is specified using --log-dir.
// Type: Method.
// Args: argc - (R) An integer that contains the count of arguments that follow in
// argv. The argc parameter is always greater than or equal to 1.
// argv - (R) An array of null-terminated strings representing command-line
// arguments entered by the user of the program. By convention,
// argv[0] is the command with which the program is invoked.
// vwbExiting - (W) True = *this want to exit, Reasons: help, invalid arg(s),
// version information only.
// False = Continue to work, start debugger i.e. Command
// interpreter.
// Return: lldb::SBError - LLDB current error status.
// Throws: None.
//--
bool
CMIDriverMgr::ParseArgs(const int argc, const char *argv[], bool &vwbExiting)
{
bool bOk = MIstatus::success;
vwbExiting = false;
// Print MI application path to the Log file
const CMIUtilString appPath(CMIUtilString::Format(MIRSRC(IDS_MI_APP_FILEPATHNAME), argv[0]));
bOk = m_pLog->Write(appPath, CMICmnLog::eLogVerbosity_Log);
// Print application arguments to the Log file
const bool bHaveArgs(argc >= 2);
CMIUtilString strArgs(MIRSRC(IDS_MI_APP_ARGS));
if (!bHaveArgs)
{
strArgs += MIRSRC(IDS_WORD_NONE);
bOk = bOk && m_pLog->Write(strArgs, CMICmnLog::eLogVerbosity_Log);
}
else
{
for (MIint i = 1; i < argc; i++)
{
strArgs += CMIUtilString::Format("%d:'%s' ", i, argv[i]);
}
bOk = bOk && m_pLog->Write(strArgs, CMICmnLog::eLogVerbosity_Log);
}
// Look for the command line options
bool bHaveArgInterpret = false;
bool bHaveArgVersion = false;
bool bHaveArgVersionLong = false;
bool bHaveArgLog = false;
bool bHaveArgLogDir = false;
bool bHaveArgHelp = false;
CMIUtilString strLogDir;
bHaveArgInterpret = true;
if (bHaveArgs)
{
// CODETAG_MIDRIVE_CMD_LINE_ARG_HANDLING
for (MIint i = 1; i < argc; i++)
{
// *** Add args to help in GetHelpOnCmdLineArgOptions() ***
const CMIUtilString strArg(argv[i]);
// Argument "--executable" is also check for in CMIDriver::ParseArgs()
if ((0 == strArg.compare("--interpreter")) || // Given by the client such as Eclipse
(0 == strArg.compare("--executable"))) // Used to specify that there is executable argument also on the command line
{ // See fn description.
bHaveArgInterpret = true;
}
if (0 == strArg.compare("--version"))
{
bHaveArgVersion = true;
}
if (0 == strArg.compare("--versionLong"))
{
bHaveArgVersionLong = true;
}
if (0 == strArg.compare("--log"))
{
bHaveArgLog = true;
}
if (0 == strArg.compare(0,10,"--log-dir="))
{
strLogDir = strArg.substr(10, CMIUtilString::npos);
bHaveArgLogDir = true;
}
if ((0 == strArg.compare("--help")) || (0 == strArg.compare("-h")))
{
bHaveArgHelp = true;
}
}
}
if (bHaveArgLog)
{
CMICmnLog::Instance().SetEnabled(true);
}
if (bHaveArgLogDir)
{
bOk = bOk && CMICmnLogMediumFile::Instance().SetDirectory(strLogDir);
}
// Todo: Remove this output when MI is finished. It is temporary to persuade Eclipse plugin to work.
// Eclipse reads this literally and will not work unless it gets this exact version text.
// Handle --version option (ignore the --interpreter option if present)
if (bHaveArgVersion)
{
vwbExiting = true;
bOk = bOk && CMICmnStreamStdout::Instance().WriteMIResponse(MIRSRC(IDE_MI_VERSION_GDB));
return bOk;
}
// Todo: Make this the --version when the above --version version is removed
// Handle --versionlong option (ignore the --interpreter option if present)
if (bHaveArgVersionLong)
{
vwbExiting = true;
bOk = bOk && CMICmnStreamStdout::Instance().WriteMIResponse(GetAppVersion());
return bOk;
}
// Both '--help' and '--interpreter' means give help for MI only. Without
// '--interpreter' help the LLDB driver is working and so help is for that.
if (bHaveArgHelp && bHaveArgInterpret)
{
vwbExiting = true;
bOk = bOk && CMICmnStreamStdout::Instance().WriteMIResponse(GetHelpOnCmdLineArgOptions());
return bOk;
}
// This makes the assumption that there is at least one MI compatible
// driver registered and one LLDB driver registered and the CMIDriver
// is the first one found.
// ToDo: Implement a better solution that handle any order, any number
// of drivers. Or this 'feature' may be removed if deemed not required.
IDriver *pLldbDriver = GetFirstNonMIDriver();
IDriver *pMi2Driver = GetFirstMIDriver();
if (bHaveArgInterpret && (pMi2Driver != nullptr))
bOk = bOk && SetUseThisDriverToDoWork(*pMi2Driver);
else if (pLldbDriver != nullptr)
bOk = bOk && SetUseThisDriverToDoWork(*pLldbDriver);
else
{
if (bOk)
{
vwbExiting = true;
const CMIUtilString msg(MIRSRC(IDS_DRIVER_ERR_NON_REGISTERED));
bOk = bOk && CMICmnStreamStdout::Instance().WriteMIResponse(msg);
}
}
return bOk;
}
//++ ------------------------------------------------------------------------------------
// Details: Return formatted application version and name information.
// Type: Method.
// Args: None.
// Return: CMIUtilString - Text data.
// Throws: None.
//--
CMIUtilString
CMIDriverMgr::GetAppVersion() const
{
const CMIUtilString strProj(MIRSRC(IDS_PROJNAME));
const CMIUtilString strVsn(CMIDriver::Instance().GetVersionDescription());
const CMIUtilString strGdb(MIRSRC(IDE_MI_VERSION_GDB));
const CMIUtilString strVrsnInfo(CMIUtilString::Format("%s\n%s\n%s", strProj.c_str(), strVsn.c_str(), strGdb.c_str()));
return strVrsnInfo;
}
//++ ------------------------------------------------------------------------------------
// Details: Return formatted help information on all the MI command line options.
// Type: Method.
// Args: None.
// Return: CMIUtilString - Text data.
// Throws: None.
//--
CMIUtilString
CMIDriverMgr::GetHelpOnCmdLineArgOptions() const
{
const CMIUtilString pHelp[] = {
MIRSRC(IDE_MI_APP_DESCRIPTION),
MIRSRC(IDE_MI_APP_INFORMATION),
MIRSRC(IDE_MI_APP_ARG_USAGE),
MIRSRC(IDE_MI_APP_ARG_HELP),
MIRSRC(IDE_MI_APP_ARG_VERSION),
MIRSRC(IDE_MI_APP_ARG_VERSION_LONG),
MIRSRC(IDE_MI_APP_ARG_INTERPRETER),
MIRSRC(IDE_MI_APP_ARG_SOURCE),
MIRSRC(IDE_MI_APP_ARG_EXECUTEABLE),
CMIUtilString::Format(MIRSRC(IDE_MI_APP_ARG_APP_LOG), CMICmnLogMediumFile::Instance().GetFileName().c_str()),
MIRSRC(IDE_MI_APP_ARG_APP_LOG_DIR),
MIRSRC(IDE_MI_APP_ARG_EXECUTABLE),
MIRSRC(IDS_CMD_QUIT_HELP),
MIRSRC(IDE_MI_APP_ARG_EXAMPLE)};
const MIuint nHelpItems = sizeof pHelp / sizeof pHelp[0];
CMIUtilString strHelp;
for (MIuint i = 0; i < nHelpItems; i++)
{
strHelp += pHelp[i];
strHelp += "\n\n";
}
return strHelp;
}
//++ ------------------------------------------------------------------------------------
// Details: Search the registered drivers and return the first driver which says it is
// GDB/MI compatible i.e. the CMIDriver class.
// Type: Method.
// Args: None.
// Return: IDriver * - Ptr to driver, NULL = no driver found.
// Throws: None.
//--
CMIDriverMgr::IDriver *
CMIDriverMgr::GetFirstMIDriver() const
{
IDriver *pDriver = nullptr;
MapDriverIdToDriver_t::const_iterator it = m_mapDriverIdToDriver.begin();
while (it != m_mapDriverIdToDriver.end())
{
const CMIUtilString &rDrvId = (*it).first;
MIunused(rDrvId);
IDriver *pDvr = (*it).second;
if (pDvr->GetDriverIsGDBMICompatibleDriver())
{
pDriver = pDvr;
break;
}
// Next
++it;
}
return pDriver;
}
//++ ------------------------------------------------------------------------------------
// Details: Search the registered drivers and return the first driver which says it is
// not GDB/MI compatible i.e. the LLDB Driver class.
// Type: Method.
// Args: None.
// Return: IDriver * - Ptr to driver, NULL = no driver found.
// Throws: None.
//--
CMIDriverMgr::IDriver *
CMIDriverMgr::GetFirstNonMIDriver() const
{
IDriver *pDriver = nullptr;
MapDriverIdToDriver_t::const_iterator it = m_mapDriverIdToDriver.begin();
while (it != m_mapDriverIdToDriver.end())
{
const CMIUtilString &rDrvId = (*it).first;
MIunused(rDrvId);
IDriver *pDvr = (*it).second;
if (!pDvr->GetDriverIsGDBMICompatibleDriver())
{
pDriver = pDvr;
break;
}
// Next
++it;
}
return pDriver;
}
//++ ------------------------------------------------------------------------------------
// Details: Search the registered drivers and return driver with the specified ID.
// Type: Method.
// Args: vrDriverId - (R) ID of a driver.
// Return: IDriver * - Ptr to driver, NULL = no driver found.
// Throws: None.
//--
CMIDriverMgr::IDriver *
CMIDriverMgr::GetDriver(const CMIUtilString &vrDriverId) const
{
MapDriverIdToDriver_t::const_iterator it = m_mapDriverIdToDriver.find(vrDriverId);
if (it == m_mapDriverIdToDriver.end())
return nullptr;
IDriver *pDriver = (*it).second;
return pDriver;
}
//++ ------------------------------------------------------------------------------------
// Details: Gets called when lldb-mi gets a signal. Passed signal to current driver.
//
// Type: Method.
// Args: signal that was delivered
// Return: None.
// Throws: None.
//--
void
CMIDriverMgr::DeliverSignal(int signal)
{
if (m_pDriverCurrent != nullptr)
m_pDriverCurrent->DeliverSignal(signal);
}
|