aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2014-02-18 16:23:10 +0000
committerEd Maste <emaste@FreeBSD.org>2014-02-18 16:23:10 +0000
commit866dcdacfe59f5f448e008fe2c4cb9dfcf72b2ec (patch)
tree95cb16075f0af1b3a05b9b84eb18dda8e6c903e9 /source
parentde889deb2c386f2a7831befaf226e5c86685fa53 (diff)
downloadsrc-866dcdacfe59f5f448e008fe2c4cb9dfcf72b2ec.tar.gz
src-866dcdacfe59f5f448e008fe2c4cb9dfcf72b2ec.zip
Import lldb as of SVN r201577 (git 2bdc2f6)vendor/lldb/lldb-r201577
(A number of files not required for the FreeBSD build have been removed.) Sponsored by: DARPA, AFRL
Notes
Notes: svn path=/vendor/lldb/dist/; revision=262182 svn path=/vendor/lldb/lldb-r201577/; revision=262183; tag=vendor/lldb/lldb-r201577
Diffstat (limited to 'source')
-rw-r--r--source/API/SBBreakpoint.cpp1
-rw-r--r--source/API/SBCommandInterpreter.cpp16
-rw-r--r--source/API/SBDebugger.cpp112
-rw-r--r--source/API/SBFrame.cpp22
-rw-r--r--source/API/SBInputReader.cpp216
-rw-r--r--source/API/SBModule.cpp19
-rw-r--r--source/API/SBProcess.cpp47
-rw-r--r--source/API/SBQueue.cpp368
-rw-r--r--source/API/SBQueueItem.cpp120
-rw-r--r--source/API/SBTarget.cpp185
-rw-r--r--source/API/SBType.cpp8
-rw-r--r--source/API/SBTypeCategory.cpp56
-rw-r--r--source/API/SBTypeFormat.cpp56
-rw-r--r--source/API/SBValue.cpp23
-rw-r--r--source/Breakpoint/Breakpoint.cpp11
-rw-r--r--source/Breakpoint/BreakpointLocation.cpp43
-rw-r--r--source/Breakpoint/BreakpointLocationList.cpp10
-rw-r--r--source/Breakpoint/BreakpointResolverName.cpp6
-rw-r--r--source/Commands/CommandObjectBreakpointCommand.cpp156
-rw-r--r--source/Commands/CommandObjectBreakpointCommand.h1
-rw-r--r--source/Commands/CommandObjectCommands.cpp517
-rw-r--r--source/Commands/CommandObjectDisassemble.cpp1
-rw-r--r--source/Commands/CommandObjectExpression.cpp163
-rw-r--r--source/Commands/CommandObjectExpression.h25
-rw-r--r--source/Commands/CommandObjectGUI.cpp61
-rw-r--r--source/Commands/CommandObjectGUI.h43
-rw-r--r--source/Commands/CommandObjectMultiword.cpp9
-rw-r--r--source/Commands/CommandObjectProcess.cpp184
-rw-r--r--source/Commands/CommandObjectQuit.cpp3
-rw-r--r--source/Commands/CommandObjectRegister.cpp1
-rw-r--r--source/Commands/CommandObjectSource.cpp1
-rw-r--r--source/Commands/CommandObjectTarget.cpp160
-rw-r--r--source/Commands/CommandObjectType.cpp877
-rw-r--r--source/Commands/CommandObjectWatchpointCommand.cpp158
-rw-r--r--source/Commands/CommandObjectWatchpointCommand.h3
-rw-r--r--source/Core/Address.cpp23
-rw-r--r--source/Core/ArchSpec.cpp39
-rw-r--r--source/Core/Broadcaster.cpp24
-rw-r--r--source/Core/Communication.cpp10
-rw-r--r--source/Core/ConnectionFileDescriptor.cpp176
-rw-r--r--source/Core/DataExtractor.cpp70
-rw-r--r--source/Core/Debugger.cpp897
-rw-r--r--source/Core/Disassembler.cpp22
-rw-r--r--source/Core/DynamicLoader.cpp138
-rw-r--r--source/Core/IOHandler.cpp5294
-rw-r--r--source/Core/InputReader.cpp387
-rw-r--r--source/Core/InputReaderEZ.cpp91
-rw-r--r--source/Core/InputReaderStack.cpp80
-rw-r--r--source/Core/Log.cpp25
-rw-r--r--source/Core/Mangled.cpp302
-rw-r--r--source/Core/Module.cpp32
-rw-r--r--source/Core/Opcode.cpp83
-rw-r--r--source/Core/Section.cpp1
-rw-r--r--source/Core/SourceManager.cpp50
-rw-r--r--source/Core/StreamAsynchronousIO.cpp9
-rw-r--r--source/Core/StringList.cpp91
-rw-r--r--source/Core/Value.cpp1
-rw-r--r--source/Core/ValueObject.cpp115
-rw-r--r--source/Core/ValueObjectChild.cpp8
-rw-r--r--source/Core/ValueObjectVariable.cpp14
-rw-r--r--source/DataFormatters/DataVisualization.cpp12
-rw-r--r--source/DataFormatters/FormatManager.cpp111
-rw-r--r--source/DataFormatters/LibCxx.cpp74
-rw-r--r--source/DataFormatters/LibCxxUnorderedMap.cpp3
-rw-r--r--source/DataFormatters/TypeCategory.cpp180
-rw-r--r--source/DataFormatters/TypeFormat.cpp186
-rw-r--r--source/DataFormatters/ValueObjectPrinter.cpp5
-rw-r--r--source/Expression/ClangASTSource.cpp11
-rw-r--r--source/Expression/ClangExpressionDeclMap.cpp2
-rw-r--r--source/Expression/ClangExpressionParser.cpp4
-rw-r--r--source/Expression/ClangUserExpression.cpp4
-rw-r--r--source/Expression/DWARFExpression.cpp99
-rw-r--r--source/Expression/IRDynamicChecks.cpp27
-rw-r--r--source/Expression/IRExecutionUnit.cpp30
-rw-r--r--source/Expression/IRForTarget.cpp45
-rw-r--r--source/Expression/Materializer.cpp10
-rw-r--r--source/Host/common/Editline.cpp696
-rw-r--r--source/Host/common/File.cpp128
-rw-r--r--source/Host/common/Host.cpp418
-rw-r--r--source/Host/common/OptionParser.cpp8
-rw-r--r--source/Host/common/SocketAddress.cpp78
-rw-r--r--source/Interpreter/CommandInterpreter.cpp506
-rw-r--r--source/Interpreter/CommandObject.cpp8
-rw-r--r--source/Interpreter/Options.cpp2
-rw-r--r--source/Interpreter/PythonDataObjects.cpp43
-rw-r--r--source/Interpreter/ScriptInterpreterNone.cpp5
-rw-r--r--source/Interpreter/ScriptInterpreterPython.cpp1613
-rw-r--r--source/Interpreter/embedded_interpreter.py183
-rw-r--r--source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp30
-rw-r--r--source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp141
-rw-r--r--source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h17
-rw-r--r--source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp2
-rw-r--r--source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp64
-rw-r--r--source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp5
-rw-r--r--source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp44
-rw-r--r--source/Plugins/ObjectFile/ELF/ObjectFileELF.h5
-rw-r--r--source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp35
-rw-r--r--source/Plugins/OperatingSystem/Python/OperatingSystemPython.h1
-rw-r--r--source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp18
-rw-r--r--source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h7
-rw-r--r--source/Plugins/Platform/POSIX/PlatformPOSIX.cpp5
-rw-r--r--source/Plugins/Platform/POSIX/PlatformPOSIX.h5
-rw-r--r--source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp44
-rw-r--r--source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h9
-rw-r--r--source/Plugins/Process/FreeBSD/FreeBSDThread.cpp69
-rw-r--r--source/Plugins/Process/FreeBSD/FreeBSDThread.h39
-rw-r--r--source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp145
-rw-r--r--source/Plugins/Process/FreeBSD/ProcessFreeBSD.h21
-rw-r--r--source/Plugins/Process/FreeBSD/ProcessMonitor.cpp102
-rw-r--r--source/Plugins/Process/FreeBSD/ProcessMonitor.h24
-rw-r--r--source/Plugins/Process/POSIX/POSIXThread.cpp4
-rw-r--r--source/Plugins/Process/POSIX/ProcessPOSIX.cpp16
-rw-r--r--source/Plugins/Process/POSIX/ProcessPOSIX.h8
-rw-r--r--source/Plugins/Process/Utility/HistoryThread.cpp2
-rw-r--r--source/Plugins/Process/Utility/HistoryThread.h10
-rw-r--r--source/Plugins/Process/Utility/InferiorCallPOSIX.cpp31
-rw-r--r--source/Plugins/Process/Utility/RegisterContextLLDB.cpp164
-rw-r--r--source/Plugins/Process/Utility/RegisterContextLLDB.h22
-rw-r--r--source/Plugins/Process/Utility/UnwindLLDB.cpp54
-rw-r--r--source/Plugins/Process/Utility/UnwindLLDB.h20
-rw-r--r--source/Plugins/Process/elf-core/ProcessElfCore.cpp46
-rw-r--r--source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp12
-rw-r--r--source/Plugins/Process/elf-core/ThreadElfCore.cpp70
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp256
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h43
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp411
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h54
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp641
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h145
-rw-r--r--source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp12
-rw-r--r--source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp332
-rw-r--r--source/Plugins/Process/gdb-remote/ProcessGDBRemote.h16
-rw-r--r--source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp13
-rw-r--r--source/Plugins/SymbolFile/DWARF/DWARFFormValue.h2
-rw-r--r--source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp120
-rw-r--r--source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp4
-rw-r--r--source/Symbol/ClangASTContext.cpp8
-rw-r--r--source/Symbol/ClangASTType.cpp31
-rw-r--r--source/Symbol/FuncUnwinders.cpp2
-rw-r--r--source/Symbol/Function.cpp38
-rw-r--r--source/Symbol/Symbol.cpp37
-rw-r--r--source/Symbol/Type.cpp10
-rw-r--r--source/Symbol/Variable.cpp7
-rw-r--r--source/Target/ExecutionContext.cpp13
-rw-r--r--source/Target/LanguageRuntime.cpp3
-rw-r--r--source/Target/Platform.cpp24
-rw-r--r--source/Target/Process.cpp550
-rw-r--r--source/Target/Queue.cpp127
-rw-r--r--source/Target/QueueItem.cpp77
-rw-r--r--source/Target/QueueList.cpp102
-rw-r--r--source/Target/SectionLoadHistory.cpp182
-rw-r--r--source/Target/SectionLoadList.cpp19
-rw-r--r--source/Target/StopInfo.cpp15
-rw-r--r--source/Target/SystemRuntime.cpp5
-rw-r--r--source/Target/Target.cpp264
-rw-r--r--source/Target/Thread.cpp134
-rw-r--r--source/Target/ThreadList.cpp35
-rw-r--r--source/Target/ThreadPlanStepInRange.cpp33
-rw-r--r--source/Target/ThreadPlanStepThrough.cpp2
-rw-r--r--source/Target/ThreadPlanTracer.cpp4
-rw-r--r--source/Target/UnwindAssembly.cpp6
-rw-r--r--source/Utility/StringExtractorGDBRemote.cpp145
-rw-r--r--source/Utility/StringExtractorGDBRemote.h61
-rw-r--r--source/lldb-log.cpp6
-rw-r--r--source/lldb.cpp2
165 files changed, 15549 insertions, 5888 deletions
diff --git a/source/API/SBBreakpoint.cpp b/source/API/SBBreakpoint.cpp
index 11ad149fdddc..fbdc0e32f498 100644
--- a/source/API/SBBreakpoint.cpp
+++ b/source/API/SBBreakpoint.cpp
@@ -23,6 +23,7 @@
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadSpec.h"
diff --git a/source/API/SBCommandInterpreter.cpp b/source/API/SBCommandInterpreter.cpp
index ac77e2e41126..f1faa13ba981 100644
--- a/source/API/SBCommandInterpreter.cpp
+++ b/source/API/SBCommandInterpreter.cpp
@@ -107,6 +107,22 @@ SBCommandInterpreter::AliasExists (const char *cmd)
return false;
}
+bool
+SBCommandInterpreter::IsActive ()
+{
+ if (m_opaque_ptr)
+ return m_opaque_ptr->IsActive ();
+ return false;
+}
+
+const char *
+SBCommandInterpreter::GetIOHandlerControlSequence(char ch)
+{
+ if (m_opaque_ptr)
+ return m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence (ch).GetCString();
+ return NULL;
+}
+
lldb::ReturnStatus
SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history)
{
diff --git a/source/API/SBDebugger.cpp b/source/API/SBDebugger.cpp
index 10c0b7dea208..8d6887a6c280 100644
--- a/source/API/SBDebugger.cpp
+++ b/source/API/SBDebugger.cpp
@@ -20,7 +20,6 @@
#include "lldb/API/SBError.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBFrame.h"
-#include "lldb/API/SBInputReader.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBSourceManager.h"
#include "lldb/API/SBStream.h"
@@ -37,6 +36,7 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/State.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/DataFormatters/DataVisualization.h"
#include "lldb/Host/DynamicLibrary.h"
#include "lldb/Interpreter/Args.h"
@@ -49,6 +49,29 @@ using namespace lldb;
using namespace lldb_private;
+SBInputReader::SBInputReader()
+{
+}
+SBInputReader::~SBInputReader()
+{
+}
+
+SBError
+SBInputReader::Initialize(lldb::SBDebugger& sb_debugger, unsigned long (*)(void*, lldb::SBInputReader*, lldb::InputReaderAction, char const*, unsigned long), void*, lldb::InputReaderGranularity, char const*, char const*, bool)
+{
+ return SBError();
+}
+
+void
+SBInputReader::SetIsDone(bool)
+{
+}
+bool
+SBInputReader::IsActive() const
+{
+ return false;
+}
+
static lldb::DynamicLibrarySP
LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& error)
{
@@ -111,7 +134,7 @@ SBDebugger::Clear ()
log->Printf ("SBDebugger(%p)::Clear ()", m_opaque_sp.get());
if (m_opaque_sp)
- m_opaque_sp->CleanUpInputReaders ();
+ m_opaque_sp->ClearIOHandlers ();
m_opaque_sp.reset();
}
@@ -309,7 +332,11 @@ FILE *
SBDebugger::GetInputFileHandle ()
{
if (m_opaque_sp)
- return m_opaque_sp->GetInputFile().GetStream();
+ {
+ StreamFileSP stream_file_sp (m_opaque_sp->GetInputFile());
+ if (stream_file_sp)
+ return stream_file_sp->GetFile().GetStream();
+ }
return NULL;
}
@@ -317,7 +344,11 @@ FILE *
SBDebugger::GetOutputFileHandle ()
{
if (m_opaque_sp)
- return m_opaque_sp->GetOutputFile().GetStream();
+ {
+ StreamFileSP stream_file_sp (m_opaque_sp->GetOutputFile());
+ if (stream_file_sp)
+ return stream_file_sp->GetFile().GetStream();
+ }
return NULL;
}
@@ -325,7 +356,12 @@ FILE *
SBDebugger::GetErrorFileHandle ()
{
if (m_opaque_sp)
- return m_opaque_sp->GetErrorFile().GetStream();
+ if (m_opaque_sp)
+ {
+ StreamFileSP stream_file_sp (m_opaque_sp->GetErrorFile());
+ if (stream_file_sp)
+ return stream_file_sp->GetFile().GetStream();
+ }
return NULL;
}
@@ -885,17 +921,17 @@ SBDebugger::DispatchInput (void* baton, const void *data, size_t data_len)
void
SBDebugger::DispatchInput (const void *data, size_t data_len)
{
- Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-
- if (log)
- log->Printf ("SBDebugger(%p)::DispatchInput (data=\"%.*s\", size_t=%" PRIu64 ")",
- m_opaque_sp.get(),
- (int) data_len,
- (const char *) data,
- (uint64_t)data_len);
-
- if (m_opaque_sp)
- m_opaque_sp->DispatchInput ((const char *) data, data_len);
+// Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+//
+// if (log)
+// log->Printf ("SBDebugger(%p)::DispatchInput (data=\"%.*s\", size_t=%" PRIu64 ")",
+// m_opaque_sp.get(),
+// (int) data_len,
+// (const char *) data,
+// (uint64_t)data_len);
+//
+// if (m_opaque_sp)
+// m_opaque_sp->DispatchInput ((const char *) data, data_len);
}
void
@@ -911,54 +947,18 @@ SBDebugger::DispatchInputEndOfFile ()
if (m_opaque_sp)
m_opaque_sp->DispatchInputEndOfFile ();
}
-
-bool
-SBDebugger::InputReaderIsTopReader (const lldb::SBInputReader &reader)
-{
- Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-
- if (log)
- log->Printf ("SBDebugger(%p)::InputReaderIsTopReader (SBInputReader(%p))", m_opaque_sp.get(), &reader);
-
- if (m_opaque_sp && reader.IsValid())
- {
- InputReaderSP reader_sp (*reader);
- return m_opaque_sp->InputReaderIsTopReader (reader_sp);
- }
-
- return false;
-}
-
void
SBDebugger::PushInputReader (SBInputReader &reader)
{
- Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-
- if (log)
- log->Printf ("SBDebugger(%p)::PushInputReader (SBInputReader(%p))", m_opaque_sp.get(), &reader);
-
- if (m_opaque_sp && reader.IsValid())
- {
- TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
- Mutex::Locker api_locker;
- if (target_sp)
- api_locker.Lock(target_sp->GetAPIMutex());
- InputReaderSP reader_sp(*reader);
- m_opaque_sp->PushInputReader (reader_sp);
- }
}
void
-SBDebugger::NotifyTopInputReader (InputReaderAction notification)
+SBDebugger::RunCommandInterpreter (bool auto_handle_events,
+ bool spawn_thread)
{
- Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-
- if (log)
- log->Printf ("SBDebugger(%p)::NotifyTopInputReader (%d)", m_opaque_sp.get(), notification);
-
if (m_opaque_sp)
- m_opaque_sp->NotifyTopInputReader (notification);
+ m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(auto_handle_events, spawn_thread);
}
void
@@ -1050,7 +1050,7 @@ SBDebugger::GetInternalVariableValue (const char *var_name, const char *debugger
if (!value_str.empty())
{
StringList string_list;
- string_list.SplitIntoLines(value_str.c_str(), value_str.size());
+ string_list.SplitIntoLines(value_str);
return SBStringList(&string_list);
}
}
diff --git a/source/API/SBFrame.cpp b/source/API/SBFrame.cpp
index 1a1a63bd0671..cff460208070 100644
--- a/source/API/SBFrame.cpp
+++ b/source/API/SBFrame.cpp
@@ -1386,20 +1386,22 @@ SBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &option
frame = exe_ctx.GetFramePtr();
if (frame)
{
-#ifdef LLDB_CONFIGURATION_DEBUG
- StreamString frame_description;
- frame->DumpUsingSettingsFormat (&frame_description);
- Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
- expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
-#endif
- exe_results = target->EvaluateExpression (expr,
+ if (target->GetDisplayExpressionsInCrashlogs())
+ {
+ StreamString frame_description;
+ frame->DumpUsingSettingsFormat (&frame_description);
+ Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
+ expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
+ }
+
+ exe_results = target->EvaluateExpression (expr,
frame,
expr_value_sp,
options.ref());
expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
-#ifdef LLDB_CONFIGURATION_DEBUG
- Host::SetCrashDescription (NULL);
-#endif
+
+ if (target->GetDisplayExpressionsInCrashlogs())
+ Host::SetCrashDescription (NULL);
}
else
{
diff --git a/source/API/SBInputReader.cpp b/source/API/SBInputReader.cpp
deleted file mode 100644
index 82b75c869f08..000000000000
--- a/source/API/SBInputReader.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-//===-- SBInputReader.cpp ---------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-
-#include "lldb/lldb-enumerations.h"
-
-#include "lldb/API/SBDebugger.h"
-#include "lldb/API/SBError.h"
-#include "lldb/API/SBInputReader.h"
-#include "lldb/API/SBStream.h"
-#include "lldb/API/SBStringList.h"
-#include "lldb/Core/InputReader.h"
-#include "lldb/Core/Log.h"
-
-
-using namespace lldb;
-using namespace lldb_private;
-
-SBInputReader::SBInputReader () :
- m_opaque_sp (),
- m_callback_function (NULL),
- m_callback_baton (NULL)
-
-{
-}
-
-SBInputReader::SBInputReader (const lldb::InputReaderSP &reader_sp) :
- m_opaque_sp (reader_sp)
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-
- if (log)
- log->Printf ("SBInputReader::SBInputReader (reader_sp=%p) => SBInputReader(%p)", reader_sp.get(),
- m_opaque_sp.get());
-}
-
-SBInputReader::SBInputReader (const SBInputReader &rhs) :
- m_opaque_sp (rhs.m_opaque_sp)
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-
- if (log)
- log->Printf("SBInputReader::SBInputReader (rhs.sp=%p) => SBInputReader(%p)",
- rhs.m_opaque_sp.get(), m_opaque_sp.get());
-}
-
-SBInputReader::~SBInputReader ()
-{
-}
-
-size_t
-SBInputReader::PrivateCallback
-(
- void *baton,
- InputReader &reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len
-)
-{
- SBInputReader *sb_reader = (SBInputReader *)baton;
- return sb_reader->m_callback_function (sb_reader->m_callback_baton,
- sb_reader,
- notification,
- bytes,
- bytes_len);
-}
-
-SBError
-SBInputReader::Initialize
-(
- SBDebugger &debugger,
- Callback callback_function,
- void *callback_baton,
- lldb::InputReaderGranularity granularity,
- const char *end_token,
- const char *prompt,
- bool echo
-)
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-
- if (log)
- log->Printf("SBInputReader(%p)::Initialize (SBDebugger(%p), callback_function=%p, callback_baton=%p, "
- "granularity=%s, end_token=\"%s\", prompt=\"%s\", echo=%i)",
- m_opaque_sp.get(),
- debugger.get(),
- callback_function,
- callback_baton,
- InputReader::GranularityAsCString (granularity), end_token, prompt,
- echo);
-
- SBError sb_error;
- m_opaque_sp.reset (new InputReader (debugger.ref()));
-
- m_callback_function = callback_function;
- m_callback_baton = callback_baton;
-
- if (m_opaque_sp)
- {
- sb_error.SetError (m_opaque_sp->Initialize (SBInputReader::PrivateCallback,
- this,
- granularity,
- end_token,
- prompt,
- echo));
- }
-
- if (sb_error.Fail())
- {
- m_opaque_sp.reset ();
- m_callback_function = NULL;
- m_callback_baton = NULL;
- }
-
- if (log)
- {
- SBStream sstr;
- sb_error.GetDescription (sstr);
- log->Printf ("SBInputReader(%p)::Initialize (...) => SBError(%p): %s", m_opaque_sp.get(),
- sb_error.get(), sstr.GetData());
- }
-
- return sb_error;
-}
-
-bool
-SBInputReader::IsValid () const
-{
- return (m_opaque_sp.get() != NULL);
-}
-
-const SBInputReader &
-SBInputReader::operator = (const SBInputReader &rhs)
-{
- if (this != &rhs)
- m_opaque_sp = rhs.m_opaque_sp;
- return *this;
-}
-
-InputReader *
-SBInputReader::operator->() const
-{
- return m_opaque_sp.get();
-}
-
-lldb::InputReaderSP &
-SBInputReader::operator *()
-{
- return m_opaque_sp;
-}
-
-const lldb::InputReaderSP &
-SBInputReader::operator *() const
-{
- return m_opaque_sp;
-}
-
-InputReader *
-SBInputReader::get() const
-{
- return m_opaque_sp.get();
-}
-
-InputReader &
-SBInputReader::ref() const
-{
- assert (m_opaque_sp.get());
- return *m_opaque_sp;
-}
-
-bool
-SBInputReader::IsDone () const
-{
- if (m_opaque_sp)
- return m_opaque_sp->IsDone();
- else
- return true;
-}
-
-void
-SBInputReader::SetIsDone (bool value)
-{
- if (m_opaque_sp)
- m_opaque_sp->SetIsDone (value);
-}
-
-bool
-SBInputReader::IsActive () const
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-
- bool ret_value = false;
- if (m_opaque_sp)
- ret_value = m_opaque_sp->IsActive();
-
- if (log)
- log->Printf ("SBInputReader(%p)::IsActive () => %i", m_opaque_sp.get(), ret_value);
-
- return ret_value;
-}
-
-InputReaderGranularity
-SBInputReader::GetGranularity ()
-{
- if (m_opaque_sp)
- return m_opaque_sp->GetGranularity();
- else
- return eInputReaderGranularityInvalid;
-}
diff --git a/source/API/SBModule.cpp b/source/API/SBModule.cpp
index 0285cf304d4d..c8543d4de298 100644
--- a/source/API/SBModule.cpp
+++ b/source/API/SBModule.cpp
@@ -69,7 +69,7 @@ SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) :
{
Target &target = process_sp->GetTarget();
bool changed = false;
- m_opaque_sp->SetLoadAddress(target, 0, changed);
+ m_opaque_sp->SetLoadAddress(target, 0, true, changed);
target.GetImages().Append(m_opaque_sp);
}
}
@@ -579,6 +579,23 @@ SBModule::FindTypes (const char *type)
return retval;
}
+lldb::SBType
+SBModule::GetTypeByID (lldb::user_id_t uid)
+{
+ ModuleSP module_sp (GetSP ());
+ if (module_sp)
+ {
+ SymbolVendor* vendor = module_sp->GetSymbolVendor();
+ if (vendor)
+ {
+ Type *type_ptr = vendor->ResolveTypeUID(uid);
+ if (type_ptr)
+ return SBType(type_ptr->shared_from_this());
+ }
+ }
+ return SBType();
+}
+
lldb::SBTypeList
SBModule::GetTypes (uint32_t type_mask)
{
diff --git a/source/API/SBProcess.cpp b/source/API/SBProcess.cpp
index 557006f24345..235388b5f25c 100644
--- a/source/API/SBProcess.cpp
+++ b/source/API/SBProcess.cpp
@@ -535,6 +535,53 @@ SBProcess::GetThreadAtIndex (size_t index)
}
uint32_t
+SBProcess::GetNumQueues ()
+{
+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+ uint32_t num_queues = 0;
+ ProcessSP process_sp(GetSP());
+ if (process_sp)
+ {
+ Process::StopLocker stop_locker;
+
+ Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
+ num_queues = process_sp->GetQueueList().GetSize();
+ }
+
+ if (log)
+ log->Printf ("SBProcess(%p)::GetNumQueues () => %d", process_sp.get(), num_queues);
+
+ return num_queues;
+}
+
+SBQueue
+SBProcess::GetQueueAtIndex (size_t index)
+{
+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+ SBQueue sb_queue;
+ QueueSP queue_sp;
+ ProcessSP process_sp(GetSP());
+ if (process_sp)
+ {
+ Process::StopLocker stop_locker;
+ Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
+ queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
+ sb_queue.SetQueue (queue_sp);
+ }
+
+ if (log)
+ {
+ log->Printf ("SBProcess(%p)::GetQueueAtIndex (index=%d) => SBQueue(%p)",
+ process_sp.get(), (uint32_t) index, queue_sp.get());
+ }
+
+ return sb_queue;
+}
+
+
+uint32_t
SBProcess::GetStopID(bool include_expression_stops)
{
ProcessSP process_sp(GetSP());
diff --git a/source/API/SBQueue.cpp b/source/API/SBQueue.cpp
new file mode 100644
index 000000000000..8d67a48d6b81
--- /dev/null
+++ b/source/API/SBQueue.cpp
@@ -0,0 +1,368 @@
+//===-- SBQueue.cpp ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/lldb-python.h"
+
+#include "lldb/API/SBQueue.h"
+
+#include "lldb/API/SBProcess.h"
+#include "lldb/API/SBThread.h"
+#include "lldb/Core/Log.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Queue.h"
+#include "lldb/Target/QueueItem.h"
+#include "lldb/Target/Thread.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+namespace lldb_private
+{
+
+ class QueueImpl
+ {
+ public:
+ QueueImpl () :
+ m_queue_wp(),
+ m_threads(),
+ m_thread_list_fetched(false),
+ m_pending_items(),
+ m_pending_items_fetched(false)
+ {
+ }
+
+ QueueImpl (const lldb::QueueSP &queue_sp) :
+ m_queue_wp(),
+ m_threads(),
+ m_thread_list_fetched(false),
+ m_pending_items(),
+ m_pending_items_fetched(false)
+ {
+ m_queue_wp = queue_sp;
+ }
+
+ QueueImpl (const QueueImpl &rhs)
+ {
+ if (&rhs == this)
+ return;
+ m_queue_wp = rhs.m_queue_wp;
+ m_threads = rhs.m_threads;
+ m_thread_list_fetched = rhs.m_thread_list_fetched;
+ m_pending_items = rhs.m_pending_items;
+ m_pending_items_fetched = rhs.m_pending_items_fetched;
+ }
+
+ ~QueueImpl ()
+ {
+ }
+
+ bool
+ IsValid ()
+ {
+ return m_queue_wp.lock() != NULL;
+ }
+
+ void
+ Clear ()
+ {
+ m_queue_wp.reset();
+ m_thread_list_fetched = false;
+ m_threads.clear();
+ m_pending_items_fetched = false;
+ m_pending_items.clear();
+ }
+
+ void
+ SetQueue (const lldb::QueueSP &queue_sp)
+ {
+ Clear();
+ m_queue_wp = queue_sp;
+ }
+
+ lldb::queue_id_t
+ GetQueueID () const
+ {
+ lldb::queue_id_t result = LLDB_INVALID_QUEUE_ID;
+ lldb::QueueSP queue_sp = m_queue_wp.lock();
+ if (queue_sp)
+ {
+ result = queue_sp->GetID();
+ }
+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+ if (log)
+ log->Printf ("SBQueue(%p)::GetQueueID () => 0x%" PRIx64, this, result);
+ return result;
+ }
+
+ uint32_t
+ GetIndexID () const
+ {
+ uint32_t result = LLDB_INVALID_INDEX32;
+ lldb::QueueSP queue_sp = m_queue_wp.lock();
+ if (queue_sp)
+ {
+ result = queue_sp->GetIndexID();
+ }
+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+ if (log)
+ log->Printf ("SBQueueImpl(%p)::GetIndexID () => %d", this, result);
+ return result;
+ }
+
+ const char *
+ GetName () const
+ {
+ const char *name = NULL;
+ lldb::QueueSP queue_sp = m_queue_wp.lock ();
+ if (queue_sp.get())
+ {
+ name = queue_sp->GetName();
+ }
+
+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+ if (log)
+ log->Printf ("SBQueueImpl(%p)::GetName () => %s", this, name ? name : "NULL");
+
+ return name;
+ }
+
+ void
+ FetchThreads ()
+ {
+ if (m_thread_list_fetched == false)
+ {
+ lldb::QueueSP queue_sp = m_queue_wp.lock();
+ if (queue_sp)
+ {
+ Process::StopLocker stop_locker;
+ if (stop_locker.TryLock (&queue_sp->GetProcess()->GetRunLock()))
+ {
+ const std::vector<ThreadSP> thread_list(queue_sp->GetThreads());
+ m_thread_list_fetched = true;
+ const uint32_t num_threads = thread_list.size();
+ for (uint32_t idx = 0; idx < num_threads; ++idx)
+ {
+ ThreadSP thread_sp = thread_list[idx];
+ if (thread_sp && thread_sp->IsValid())
+ {
+ m_threads.push_back (thread_sp);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ void
+ FetchItems ()
+ {
+ if (m_pending_items_fetched == false)
+ {
+ QueueSP queue_sp = m_queue_wp.lock();
+ if (queue_sp)
+ {
+ Process::StopLocker stop_locker;
+ if (stop_locker.TryLock (&queue_sp->GetProcess()->GetRunLock()))
+ {
+ const std::vector<QueueItemSP> queue_items(queue_sp->GetPendingItems());
+ m_pending_items_fetched = true;
+ const uint32_t num_pending_items = queue_items.size();
+ for (uint32_t idx = 0; idx < num_pending_items; ++idx)
+ {
+ QueueItemSP item = queue_items[idx];
+ if (item && item->IsValid())
+ {
+ m_pending_items.push_back (item);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ uint32_t
+ GetNumThreads ()
+ {
+ uint32_t result = 0;
+
+ FetchThreads();
+ if (m_thread_list_fetched)
+ {
+ result = m_threads.size();
+ }
+ return result;
+ }
+
+ lldb::SBThread
+ GetThreadAtIndex (uint32_t idx)
+ {
+ FetchThreads();
+
+ SBThread sb_thread;
+ QueueSP queue_sp = m_queue_wp.lock();
+ if (queue_sp && idx < m_threads.size())
+ {
+ ProcessSP process_sp = queue_sp->GetProcess();
+ if (process_sp)
+ {
+ ThreadSP thread_sp = m_threads[idx].lock();
+ if (thread_sp)
+ {
+ sb_thread.SetThread (thread_sp);
+ }
+ }
+ }
+ return sb_thread;
+ }
+
+
+ uint32_t
+ GetNumPendingItems ()
+ {
+ uint32_t result = 0;
+ FetchItems();
+
+ if (m_pending_items_fetched)
+ {
+ result = m_pending_items.size();
+ }
+ return result;
+ }
+
+ lldb::SBQueueItem
+ GetPendingItemAtIndex (uint32_t idx)
+ {
+ SBQueueItem result;
+ FetchItems();
+ if (m_pending_items_fetched && idx < m_pending_items.size())
+ {
+ result.SetQueueItem (m_pending_items[idx]);
+ }
+ return result;
+ }
+
+ lldb::SBProcess
+ GetProcess ()
+ {
+ SBProcess result;
+ QueueSP queue_sp = m_queue_wp.lock();
+ if (queue_sp)
+ {
+ result.SetSP (queue_sp->GetProcess());
+ }
+ return result;
+ }
+
+ private:
+ lldb::QueueWP m_queue_wp;
+ std::vector<lldb::ThreadWP> m_threads; // threads currently executing this queue's items
+ bool m_thread_list_fetched; // have we tried to fetch the threads list already?
+ std::vector<lldb::QueueItemSP> m_pending_items; // items currently enqueued
+ bool m_pending_items_fetched; // have we tried to fetch the item list already?
+ };
+
+}
+
+SBQueue::SBQueue () :
+ m_opaque_sp (new QueueImpl())
+{
+}
+
+SBQueue::SBQueue (const QueueSP& queue_sp) :
+ m_opaque_sp (new QueueImpl (queue_sp))
+{
+}
+
+SBQueue::SBQueue (const SBQueue &rhs)
+{
+ if (&rhs == this)
+ return;
+
+ m_opaque_sp = rhs.m_opaque_sp;
+}
+
+const lldb::SBQueue &
+SBQueue::operator = (const lldb::SBQueue &rhs)
+{
+ m_opaque_sp = rhs.m_opaque_sp;
+ return *this;
+}
+
+SBQueue::~SBQueue()
+{
+}
+
+bool
+SBQueue::IsValid() const
+{
+ return m_opaque_sp->IsValid();
+}
+
+
+void
+SBQueue::Clear ()
+{
+ m_opaque_sp->Clear();
+}
+
+
+void
+SBQueue::SetQueue (const QueueSP& queue_sp)
+{
+ m_opaque_sp->SetQueue (queue_sp);
+}
+
+lldb::queue_id_t
+SBQueue::GetQueueID () const
+{
+ return m_opaque_sp->GetQueueID ();
+}
+
+uint32_t
+SBQueue::GetIndexID () const
+{
+ return m_opaque_sp->GetIndexID ();
+}
+
+const char *
+SBQueue::GetName () const
+{
+ return m_opaque_sp->GetName ();
+}
+
+uint32_t
+SBQueue::GetNumThreads ()
+{
+ return m_opaque_sp->GetNumThreads ();
+}
+
+SBThread
+SBQueue::GetThreadAtIndex (uint32_t idx)
+{
+ return m_opaque_sp->GetThreadAtIndex (idx);
+}
+
+
+uint32_t
+SBQueue::GetNumPendingItems ()
+{
+ return m_opaque_sp->GetNumPendingItems ();
+}
+
+SBQueueItem
+SBQueue::GetPendingItemAtIndex (uint32_t idx)
+{
+ return m_opaque_sp->GetPendingItemAtIndex (idx);
+}
+
+SBProcess
+SBQueue::GetProcess ()
+{
+ return m_opaque_sp->GetProcess();
+}
diff --git a/source/API/SBQueueItem.cpp b/source/API/SBQueueItem.cpp
new file mode 100644
index 000000000000..481d51e55426
--- /dev/null
+++ b/source/API/SBQueueItem.cpp
@@ -0,0 +1,120 @@
+//===-- SBQueueItem.cpp -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/lldb-python.h"
+#include "lldb/lldb-forward.h"
+
+#include "lldb/API/SBAddress.h"
+#include "lldb/API/SBQueueItem.h"
+#include "lldb/API/SBThread.h"
+#include "lldb/Core/Address.h"
+#include "lldb/Target/QueueItem.h"
+#include "lldb/Target/Thread.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+//----------------------------------------------------------------------
+// Constructors
+//----------------------------------------------------------------------
+SBQueueItem::SBQueueItem () :
+ m_queue_item_sp()
+{
+}
+
+SBQueueItem::SBQueueItem (const QueueItemSP& queue_item_sp) :
+ m_queue_item_sp (queue_item_sp)
+{
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//----------------------------------------------------------------------
+SBQueueItem::~SBQueueItem()
+{
+ m_queue_item_sp.reset();
+}
+
+bool
+SBQueueItem::IsValid() const
+{
+ return m_queue_item_sp.get() != NULL;
+}
+
+
+void
+SBQueueItem::Clear ()
+{
+ m_queue_item_sp.reset();
+}
+
+
+void
+SBQueueItem::SetQueueItem (const QueueItemSP& queue_item_sp)
+{
+ m_queue_item_sp = queue_item_sp;
+}
+
+
+lldb::QueueItemKind
+SBQueueItem::GetKind () const
+{
+ QueueItemKind result = eQueueItemKindUnknown;
+ if (m_queue_item_sp)
+ {
+ result = m_queue_item_sp->GetKind ();
+ }
+ return result;
+}
+
+void
+SBQueueItem::SetKind (lldb::QueueItemKind kind)
+{
+ if (m_queue_item_sp)
+ {
+ m_queue_item_sp->SetKind (kind);
+ }
+}
+
+SBAddress
+SBQueueItem::GetAddress () const
+{
+ SBAddress result;
+ if (m_queue_item_sp)
+ {
+ result.SetAddress (&m_queue_item_sp->GetAddress());
+ }
+ return result;
+}
+
+void
+SBQueueItem::SetAddress (SBAddress addr)
+{
+ if (m_queue_item_sp)
+ {
+ m_queue_item_sp->SetAddress (addr.ref());
+ }
+}
+
+SBThread
+SBQueueItem::GetExtendedBacktraceThread (const char *type)
+{
+ SBThread result;
+ if (m_queue_item_sp)
+ {
+ ThreadSP thread_sp;
+ ConstString type_const (type);
+ thread_sp = m_queue_item_sp->GetExtendedBacktraceThread (type_const);
+ if (thread_sp)
+ {
+ result.SetThread (thread_sp);
+ }
+ }
+ return result;
+}
diff --git a/source/API/SBTarget.cpp b/source/API/SBTarget.cpp
index c8bc2171436d..224349c0bce6 100644
--- a/source/API/SBTarget.cpp
+++ b/source/API/SBTarget.cpp
@@ -52,6 +52,7 @@
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/LanguageRuntime.h"
#include "lldb/Target/Process.h"
+
#include "lldb/Target/Target.h"
#include "lldb/Target/TargetList.h"
@@ -688,57 +689,26 @@ SBTarget::Launch
return sb_process;
}
}
- else
- {
- if (listener.IsValid())
- process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
- else
- process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
- }
- if (process_sp)
- {
- sb_process.SetSP (process_sp);
- if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
- launch_flags |= eLaunchFlagDisableSTDIO;
+ if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
+ launch_flags |= eLaunchFlagDisableSTDIO;
- ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
-
- Module *exe_module = target_sp->GetExecutableModulePointer();
- if (exe_module)
- launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
- if (argv)
- launch_info.GetArguments().AppendArguments (argv);
- if (envp)
- launch_info.GetEnvironmentEntries ().SetArguments (envp);
-
- error.SetError (process_sp->Launch (launch_info));
- if (error.Success())
- {
- // We we are stopping at the entry point, we can return now!
- if (stop_at_entry)
- return sb_process;
-
- // Make sure we are stopped at the entry
- StateType state = process_sp->WaitForProcessToStop (NULL);
- if (state == eStateStopped)
- {
- // resume the process to skip the entry point
- error.SetError (process_sp->Resume());
- if (error.Success())
- {
- // If we are doing synchronous mode, then wait for the
- // process to stop yet again!
- if (target_sp->GetDebugger().GetAsyncExecution () == false)
- process_sp->WaitForProcessToStop (NULL);
- }
- }
- }
- }
+ ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
+
+ Module *exe_module = target_sp->GetExecutableModulePointer();
+ if (exe_module)
+ launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
+ if (argv)
+ launch_info.GetArguments().AppendArguments (argv);
+ if (envp)
+ launch_info.GetEnvironmentEntries ().SetArguments (envp);
+
+ if (listener.IsValid())
+ error.SetError (target_sp->Launch(listener.ref(), launch_info));
else
- {
- error.SetErrorString ("unable to create lldb_private::Process");
- }
+ error.SetError (target_sp->Launch(target_sp->GetDebugger().GetListener(), launch_info));
+
+ sb_process.SetSP(target_sp->GetProcessSP());
}
else
{
@@ -749,7 +719,7 @@ SBTarget::Launch
if (log)
{
log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
- target_sp.get(), process_sp.get());
+ target_sp.get(), sb_process.GetSP().get());
}
return sb_process;
@@ -761,7 +731,6 @@ SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
SBProcess sb_process;
- ProcessSP process_sp;
TargetSP target_sp(GetSP());
if (log)
@@ -773,7 +742,8 @@ SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
{
Mutex::Locker api_locker (target_sp->GetAPIMutex());
StateType state = eStateInvalid;
- process_sp = target_sp->GetProcessSP();
+ {
+ ProcessSP process_sp = target_sp->GetProcessSP();
if (process_sp)
{
state = process_sp->GetState();
@@ -787,58 +757,20 @@ SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
return sb_process;
}
}
-
- if (state != eStateConnected)
- process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
-
- if (process_sp)
- {
- sb_process.SetSP (process_sp);
- lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
+ }
- Module *exe_module = target_sp->GetExecutableModulePointer();
- if (exe_module)
- launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
+ lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
- const ArchSpec &arch_spec = target_sp->GetArchitecture();
- if (arch_spec.IsValid())
- launch_info.GetArchitecture () = arch_spec;
-
- error.SetError (process_sp->Launch (launch_info));
- const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false;
- if (error.Success())
- {
- if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
- {
- // If we are doing synchronous mode, then wait for the initial
- // stop to happen, else, return and let the caller watch for
- // the stop
- if (synchronous_execution)
- process_sp->WaitForProcessToStop (NULL);
- // We we are stopping at the entry point, we can return now!
- return sb_process;
- }
-
- // Make sure we are stopped at the entry
- StateType state = process_sp->WaitForProcessToStop (NULL);
- if (state == eStateStopped)
- {
- // resume the process to skip the entry point
- error.SetError (process_sp->Resume());
- if (error.Success())
- {
- // If we are doing synchronous mode, then wait for the
- // process to stop yet again!
- if (synchronous_execution)
- process_sp->WaitForProcessToStop (NULL);
- }
- }
- }
- }
- else
- {
- error.SetErrorString ("unable to create lldb_private::Process");
- }
+ Module *exe_module = target_sp->GetExecutableModulePointer();
+ if (exe_module)
+ launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
+
+ const ArchSpec &arch_spec = target_sp->GetArchitecture();
+ if (arch_spec.IsValid())
+ launch_info.GetArchitecture () = arch_spec;
+
+ error.SetError (target_sp->Launch (target_sp->GetDebugger().GetListener(), launch_info));
+ sb_process.SetSP(target_sp->GetProcessSP());
}
else
{
@@ -848,8 +780,8 @@ SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
if (log)
{
- log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
- target_sp.get(), process_sp.get());
+ log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
+ target_sp.get(), sb_process.GetSP().get());
}
return sb_process;
@@ -1263,7 +1195,7 @@ SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
if (target_sp)
{
Mutex::Locker api_locker (target_sp->GetAPIMutex());
- if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
+ if (target_sp->ResolveLoadAddress (vm_addr, addr))
return sb_addr;
}
@@ -1273,6 +1205,26 @@ SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
return sb_addr;
}
+
+lldb::SBAddress
+SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
+{
+ lldb::SBAddress sb_addr;
+ Address &addr = sb_addr.ref();
+ TargetSP target_sp(GetSP());
+ if (target_sp)
+ {
+ Mutex::Locker api_locker (target_sp->GetAPIMutex());
+ if (target_sp->ResolveLoadAddress (vm_addr, addr))
+ return sb_addr;
+ }
+
+ // We have a load address that isn't in a section, just return an address
+ // with the offset filled in (the address) and the section set to NULL
+ addr.SetRawAddress(vm_addr);
+ return sb_addr;
+}
+
SBSymbolContext
SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
uint32_t resolve_scope)
@@ -2479,10 +2431,14 @@ SBTarget::SetSectionLoadAddress (lldb::SBSection section,
}
else
{
- if (target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp, section_base_addr))
+ ProcessSP process_sp (target_sp->GetProcessSP());
+ uint32_t stop_id = 0;
+ if (process_sp)
+ stop_id = process_sp->GetStopID();
+
+ if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
{
// Flush info in the process (stack frames, etc)
- ProcessSP process_sp (target_sp->GetProcessSP());
if (process_sp)
process_sp->Flush();
}
@@ -2511,10 +2467,14 @@ SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
}
else
{
- if (target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP()))
+ ProcessSP process_sp (target_sp->GetProcessSP());
+ uint32_t stop_id = 0;
+ if (process_sp)
+ stop_id = process_sp->GetStopID();
+
+ if (target_sp->SetSectionUnloaded (section.GetSP()))
{
// Flush info in the process (stack frames, etc)
- ProcessSP process_sp (target_sp->GetProcessSP());
if (process_sp)
process_sp->Flush();
}
@@ -2539,7 +2499,7 @@ SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
if (module_sp)
{
bool changed = false;
- if (module_sp->SetLoadAddress (*target_sp, slide_offset, changed))
+ if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
{
// The load was successful, make sure that at least some sections
// changed before we notify that our module was loaded.
@@ -2586,13 +2546,18 @@ SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
SectionList *section_list = objfile->GetSectionList();
if (section_list)
{
+ ProcessSP process_sp (target_sp->GetProcessSP());
+ uint32_t stop_id = 0;
+ if (process_sp)
+ stop_id = process_sp->GetStopID();
+
bool changed = false;
const size_t num_sections = section_list->GetSize();
for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
{
SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
if (section_sp)
- changed |= target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp) > 0;
+ changed |= target_sp->SetSectionUnloaded (section_sp) > 0;
}
if (changed)
{
diff --git a/source/API/SBType.cpp b/source/API/SBType.cpp
index 3055c2752083..5ca7ddf3d813 100644
--- a/source/API/SBType.cpp
+++ b/source/API/SBType.cpp
@@ -186,6 +186,14 @@ SBType::GetReferenceType()
}
SBType
+SBType::GetTypedefedType()
+{
+ if (!IsValid())
+ return SBType();
+ return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetTypedefedType())));
+}
+
+SBType
SBType::GetDereferencedType()
{
if (!IsValid())
diff --git a/source/API/SBTypeCategory.cpp b/source/API/SBTypeCategory.cpp
index 08fdefad1be8..9fe4dad01a9f 100644
--- a/source/API/SBTypeCategory.cpp
+++ b/source/API/SBTypeCategory.cpp
@@ -87,7 +87,7 @@ SBTypeCategory::GetNumFormats ()
if (!IsValid())
return 0;
- return m_opaque_sp->GetValueNavigator()->GetCount() + m_opaque_sp->GetRegexValueNavigator()->GetCount();
+ return m_opaque_sp->GetTypeFormatsContainer()->GetCount() + m_opaque_sp->GetRegexTypeFormatsContainer()->GetCount();
}
uint32_t
@@ -95,7 +95,7 @@ SBTypeCategory::GetNumSummaries ()
{
if (!IsValid())
return 0;
- return m_opaque_sp->GetSummaryNavigator()->GetCount() + m_opaque_sp->GetRegexSummaryNavigator()->GetCount();
+ return m_opaque_sp->GetTypeSummariesContainer()->GetCount() + m_opaque_sp->GetRegexTypeSummariesContainer()->GetCount();
}
uint32_t
@@ -103,7 +103,7 @@ SBTypeCategory::GetNumFilters ()
{
if (!IsValid())
return 0;
- return m_opaque_sp->GetFilterNavigator()->GetCount() + m_opaque_sp->GetRegexFilterNavigator()->GetCount();
+ return m_opaque_sp->GetTypeFiltersContainer()->GetCount() + m_opaque_sp->GetRegexTypeFiltersContainer()->GetCount();
}
#ifndef LLDB_DISABLE_PYTHON
@@ -112,7 +112,7 @@ SBTypeCategory::GetNumSynthetics ()
{
if (!IsValid())
return 0;
- return m_opaque_sp->GetSyntheticNavigator()->GetCount() + m_opaque_sp->GetRegexSyntheticNavigator()->GetCount();
+ return m_opaque_sp->GetTypeSyntheticsContainer()->GetCount() + m_opaque_sp->GetRegexTypeSyntheticsContainer()->GetCount();
}
#endif
@@ -162,9 +162,9 @@ SBTypeCategory::GetFilterForType (SBTypeNameSpecifier spec)
lldb::SyntheticChildrenSP children_sp;
if (spec.IsRegex())
- m_opaque_sp->GetRegexFilterNavigator()->GetExact(ConstString(spec.GetName()), children_sp);
+ m_opaque_sp->GetRegexTypeFiltersContainer()->GetExact(ConstString(spec.GetName()), children_sp);
else
- m_opaque_sp->GetFilterNavigator()->GetExact(ConstString(spec.GetName()), children_sp);
+ m_opaque_sp->GetTypeFiltersContainer()->GetExact(ConstString(spec.GetName()), children_sp);
if (!children_sp)
return lldb::SBTypeFilter();
@@ -186,9 +186,9 @@ SBTypeCategory::GetFormatForType (SBTypeNameSpecifier spec)
lldb::TypeFormatImplSP format_sp;
if (spec.IsRegex())
- m_opaque_sp->GetRegexValueNavigator()->GetExact(ConstString(spec.GetName()), format_sp);
+ m_opaque_sp->GetRegexTypeFormatsContainer()->GetExact(ConstString(spec.GetName()), format_sp);
else
- m_opaque_sp->GetValueNavigator()->GetExact(ConstString(spec.GetName()), format_sp);
+ m_opaque_sp->GetTypeFormatsContainer()->GetExact(ConstString(spec.GetName()), format_sp);
if (!format_sp)
return lldb::SBTypeFormat();
@@ -209,9 +209,9 @@ SBTypeCategory::GetSummaryForType (SBTypeNameSpecifier spec)
lldb::TypeSummaryImplSP summary_sp;
if (spec.IsRegex())
- m_opaque_sp->GetRegexSummaryNavigator()->GetExact(ConstString(spec.GetName()), summary_sp);
+ m_opaque_sp->GetRegexTypeSummariesContainer()->GetExact(ConstString(spec.GetName()), summary_sp);
else
- m_opaque_sp->GetSummaryNavigator()->GetExact(ConstString(spec.GetName()), summary_sp);
+ m_opaque_sp->GetTypeSummariesContainer()->GetExact(ConstString(spec.GetName()), summary_sp);
if (!summary_sp)
return lldb::SBTypeSummary();
@@ -233,9 +233,9 @@ SBTypeCategory::GetSyntheticForType (SBTypeNameSpecifier spec)
lldb::SyntheticChildrenSP children_sp;
if (spec.IsRegex())
- m_opaque_sp->GetRegexSyntheticNavigator()->GetExact(ConstString(spec.GetName()), children_sp);
+ m_opaque_sp->GetRegexTypeSyntheticsContainer()->GetExact(ConstString(spec.GetName()), children_sp);
else
- m_opaque_sp->GetSyntheticNavigator()->GetExact(ConstString(spec.GetName()), children_sp);
+ m_opaque_sp->GetTypeSyntheticsContainer()->GetExact(ConstString(spec.GetName()), children_sp);
if (!children_sp)
return lldb::SBTypeSynthetic();
@@ -312,9 +312,9 @@ SBTypeCategory::AddTypeFormat (SBTypeNameSpecifier type_name,
return false;
if (type_name.IsRegex())
- m_opaque_sp->GetRegexValueNavigator()->Add(lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())), format.GetSP());
+ m_opaque_sp->GetRegexTypeFormatsContainer()->Add(lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())), format.GetSP());
else
- m_opaque_sp->GetValueNavigator()->Add(ConstString(type_name.GetName()), format.GetSP());
+ m_opaque_sp->GetTypeFormatsContainer()->Add(ConstString(type_name.GetName()), format.GetSP());
return true;
}
@@ -329,9 +329,9 @@ SBTypeCategory::DeleteTypeFormat (SBTypeNameSpecifier type_name)
return false;
if (type_name.IsRegex())
- return m_opaque_sp->GetRegexValueNavigator()->Delete(ConstString(type_name.GetName()));
+ return m_opaque_sp->GetRegexTypeFormatsContainer()->Delete(ConstString(type_name.GetName()));
else
- return m_opaque_sp->GetValueNavigator()->Delete(ConstString(type_name.GetName()));
+ return m_opaque_sp->GetTypeFormatsContainer()->Delete(ConstString(type_name.GetName()));
}
#ifndef LLDB_DISABLE_PYTHON
@@ -383,9 +383,9 @@ SBTypeCategory::AddTypeSummary (SBTypeNameSpecifier type_name,
}
if (type_name.IsRegex())
- m_opaque_sp->GetRegexSummaryNavigator()->Add(lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())), summary.GetSP());
+ m_opaque_sp->GetRegexTypeSummariesContainer()->Add(lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())), summary.GetSP());
else
- m_opaque_sp->GetSummaryNavigator()->Add(ConstString(type_name.GetName()), summary.GetSP());
+ m_opaque_sp->GetTypeSummariesContainer()->Add(ConstString(type_name.GetName()), summary.GetSP());
return true;
}
@@ -401,9 +401,9 @@ SBTypeCategory::DeleteTypeSummary (SBTypeNameSpecifier type_name)
return false;
if (type_name.IsRegex())
- return m_opaque_sp->GetRegexSummaryNavigator()->Delete(ConstString(type_name.GetName()));
+ return m_opaque_sp->GetRegexTypeSummariesContainer()->Delete(ConstString(type_name.GetName()));
else
- return m_opaque_sp->GetSummaryNavigator()->Delete(ConstString(type_name.GetName()));
+ return m_opaque_sp->GetTypeSummariesContainer()->Delete(ConstString(type_name.GetName()));
}
bool
@@ -420,9 +420,9 @@ SBTypeCategory::AddTypeFilter (SBTypeNameSpecifier type_name,
return false;
if (type_name.IsRegex())
- m_opaque_sp->GetRegexFilterNavigator()->Add(lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())), filter.GetSP());
+ m_opaque_sp->GetRegexTypeFiltersContainer()->Add(lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())), filter.GetSP());
else
- m_opaque_sp->GetFilterNavigator()->Add(ConstString(type_name.GetName()), filter.GetSP());
+ m_opaque_sp->GetTypeFiltersContainer()->Add(ConstString(type_name.GetName()), filter.GetSP());
return true;
}
@@ -437,9 +437,9 @@ SBTypeCategory::DeleteTypeFilter (SBTypeNameSpecifier type_name)
return false;
if (type_name.IsRegex())
- return m_opaque_sp->GetRegexFilterNavigator()->Delete(ConstString(type_name.GetName()));
+ return m_opaque_sp->GetRegexTypeFiltersContainer()->Delete(ConstString(type_name.GetName()));
else
- return m_opaque_sp->GetFilterNavigator()->Delete(ConstString(type_name.GetName()));
+ return m_opaque_sp->GetTypeFiltersContainer()->Delete(ConstString(type_name.GetName()));
}
#ifndef LLDB_DISABLE_PYTHON
@@ -491,9 +491,9 @@ SBTypeCategory::AddTypeSynthetic (SBTypeNameSpecifier type_name,
}
if (type_name.IsRegex())
- m_opaque_sp->GetRegexSyntheticNavigator()->Add(lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())), synth.GetSP());
+ m_opaque_sp->GetRegexTypeSyntheticsContainer()->Add(lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())), synth.GetSP());
else
- m_opaque_sp->GetSyntheticNavigator()->Add(ConstString(type_name.GetName()), synth.GetSP());
+ m_opaque_sp->GetTypeSyntheticsContainer()->Add(ConstString(type_name.GetName()), synth.GetSP());
return true;
}
@@ -508,9 +508,9 @@ SBTypeCategory::DeleteTypeSynthetic (SBTypeNameSpecifier type_name)
return false;
if (type_name.IsRegex())
- return m_opaque_sp->GetRegexSyntheticNavigator()->Delete(ConstString(type_name.GetName()));
+ return m_opaque_sp->GetRegexTypeSyntheticsContainer()->Delete(ConstString(type_name.GetName()));
else
- return m_opaque_sp->GetSyntheticNavigator()->Delete(ConstString(type_name.GetName()));
+ return m_opaque_sp->GetTypeSyntheticsContainer()->Delete(ConstString(type_name.GetName()));
}
#endif // LLDB_DISABLE_PYTHON
diff --git a/source/API/SBTypeFormat.cpp b/source/API/SBTypeFormat.cpp
index 34ab404a206a..d3ec9bc00bd0 100644
--- a/source/API/SBTypeFormat.cpp
+++ b/source/API/SBTypeFormat.cpp
@@ -25,7 +25,13 @@ m_opaque_sp()
SBTypeFormat::SBTypeFormat (lldb::Format format,
uint32_t options)
-: m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl(format,options)))
+: m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_Format(format,options)))
+{
+}
+
+SBTypeFormat::SBTypeFormat (const char* type,
+ uint32_t options)
+: m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_EnumType(ConstString(type ? type : ""),options)))
{
}
@@ -47,11 +53,19 @@ SBTypeFormat::IsValid() const
lldb::Format
SBTypeFormat::GetFormat ()
{
- if (IsValid())
- return m_opaque_sp->GetFormat();
+ if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
+ return ((TypeFormatImpl_Format*)m_opaque_sp.get())->GetFormat();
return lldb::eFormatInvalid;
}
+const char*
+SBTypeFormat::GetTypeName ()
+{
+ if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)
+ return ((TypeFormatImpl_EnumType*)m_opaque_sp.get())->GetTypeName().AsCString("");
+ return "";
+}
+
uint32_t
SBTypeFormat::GetOptions()
{
@@ -63,14 +77,21 @@ SBTypeFormat::GetOptions()
void
SBTypeFormat::SetFormat (lldb::Format fmt)
{
- if (CopyOnWrite_Impl())
- m_opaque_sp->SetFormat(fmt);
+ if (CopyOnWrite_Impl(Type::eTypeFormat))
+ ((TypeFormatImpl_Format*)m_opaque_sp.get())->SetFormat(fmt);
+}
+
+void
+SBTypeFormat::SetTypeName (const char* type)
+{
+ if (CopyOnWrite_Impl(Type::eTypeEnum))
+ ((TypeFormatImpl_EnumType*)m_opaque_sp.get())->SetTypeName(ConstString(type ? type : ""));
}
void
SBTypeFormat::SetOptions (uint32_t value)
{
- if (CopyOnWrite_Impl())
+ if (CopyOnWrite_Impl(Type::eTypeKeepSame))
m_opaque_sp->SetOptions(value);
}
@@ -143,13 +164,30 @@ SBTypeFormat::SBTypeFormat (const lldb::TypeFormatImplSP &typeformat_impl_sp) :
}
bool
-SBTypeFormat::CopyOnWrite_Impl()
+SBTypeFormat::CopyOnWrite_Impl(Type type)
{
if (!IsValid())
return false;
- if (m_opaque_sp.unique())
+
+ if (m_opaque_sp.unique() &&
+ ((type == Type::eTypeKeepSame) ||
+ (type == Type::eTypeFormat && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat) ||
+ (type == Type::eTypeEnum && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum))
+ )
return true;
- SetSP(TypeFormatImplSP(new TypeFormatImpl(GetFormat(),GetOptions())));
+ if (type == Type::eTypeKeepSame)
+ {
+ if (m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
+ type = Type::eTypeFormat;
+ else
+ type = Type::eTypeEnum;
+ }
+
+ if (type == Type::eTypeFormat)
+ SetSP(TypeFormatImplSP(new TypeFormatImpl_Format(GetFormat(),GetOptions())));
+ else
+ SetSP(TypeFormatImplSP(new TypeFormatImpl_EnumType(ConstString(GetTypeName()),GetOptions())));
+
return true;
}
diff --git a/source/API/SBValue.cpp b/source/API/SBValue.cpp
index 51b6790dd2b8..4bd018352ff2 100644
--- a/source/API/SBValue.cpp
+++ b/source/API/SBValue.cpp
@@ -96,7 +96,24 @@ public:
bool
IsValid ()
{
- return m_valobj_sp.get() != NULL;
+ if (m_valobj_sp.get() == NULL)
+ return false;
+ else
+ {
+ // FIXME: This check is necessary but not sufficient. We for sure don't want to touch SBValues whose owning
+ // targets have gone away. This check is a little weak in that it enforces that restriction when you call
+ // IsValid, but since IsValid doesn't lock the target, you have no guarantee that the SBValue won't go
+ // invalid after you call this...
+ // Also, an SBValue could depend on data from one of the modules in the target, and those could go away
+ // independently of the target, for instance if a module is unloaded. But right now, neither SBValues
+ // nor ValueObjects know which modules they depend on. So I have no good way to make that check without
+ // tracking that in all the ValueObject subclasses.
+ TargetSP target_sp = m_valobj_sp->GetTargetSP();
+ if (target_sp && target_sp->IsValid())
+ return true;
+ else
+ return false;
+ }
}
lldb::ValueObjectSP
@@ -120,6 +137,8 @@ public:
Target *target = value_sp->GetTargetSP().get();
if (target)
api_locker.Lock(target->GetAPIMutex());
+ else
+ return ValueObjectSP();
ProcessSP process_sp(value_sp->GetProcessSP());
if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
@@ -276,7 +295,7 @@ SBValue::IsValid ()
// If this function ever changes to anything that does more than just
// check if the opaque shared pointer is non NULL, then we need to update
// all "if (m_opaque_sp)" code in this file.
- return m_opaque_sp.get() != NULL && m_opaque_sp->GetRootSP().get() != NULL;
+ return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() && m_opaque_sp->GetRootSP().get() != NULL;
}
void
diff --git a/source/Breakpoint/Breakpoint.cpp b/source/Breakpoint/Breakpoint.cpp
index 32c0b1066f8e..5ce064fc41a0 100644
--- a/source/Breakpoint/Breakpoint.cpp
+++ b/source/Breakpoint/Breakpoint.cpp
@@ -45,14 +45,19 @@ Breakpoint::GetEventIdentifier ()
//----------------------------------------------------------------------
// Breakpoint constructor
//----------------------------------------------------------------------
-Breakpoint::Breakpoint(Target &target, SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool hardware) :
+Breakpoint::Breakpoint(Target &target,
+ SearchFilterSP &filter_sp,
+ BreakpointResolverSP &resolver_sp,
+ bool hardware,
+ bool resolve_indirect_symbols) :
m_being_created(true),
m_hardware(hardware),
m_target (target),
m_filter_sp (filter_sp),
m_resolver_sp (resolver_sp),
m_options (),
- m_locations (*this)
+ m_locations (*this),
+ m_resolve_indirect_symbols(resolve_indirect_symbols)
{
m_being_created = false;
}
@@ -87,7 +92,7 @@ Breakpoint::GetTarget () const
BreakpointLocationSP
Breakpoint::AddLocation (const Address &addr, bool *new_location)
{
- return m_locations.AddLocation (addr, new_location);
+ return m_locations.AddLocation (addr, m_resolve_indirect_symbols, new_location);
}
BreakpointLocationSP
diff --git a/source/Breakpoint/BreakpointLocation.cpp b/source/Breakpoint/BreakpointLocation.cpp
index 5009e862d84b..2c75a11e9788 100644
--- a/source/Breakpoint/BreakpointLocation.cpp
+++ b/source/Breakpoint/BreakpointLocation.cpp
@@ -39,16 +39,29 @@ BreakpointLocation::BreakpointLocation
Breakpoint &owner,
const Address &addr,
lldb::tid_t tid,
- bool hardware
+ bool hardware,
+ bool check_for_resolver
) :
StoppointLocation (loc_id, addr.GetOpcodeLoadAddress(&owner.GetTarget()), hardware),
m_being_created(true),
+ m_should_resolve_indirect_functions (false),
+ m_is_reexported (false),
+ m_is_indirect (false),
m_address (addr),
m_owner (owner),
m_options_ap (),
m_bp_site_sp (),
m_condition_mutex ()
{
+ if (check_for_resolver)
+ {
+ Symbol *symbol = m_address.CalculateSymbolContextSymbol();
+ if (symbol && symbol->IsIndirect())
+ {
+ SetShouldResolveIndirectFunctions (true);
+ }
+ }
+
SetThreadID (tid);
m_being_created = false;
}
@@ -545,7 +558,10 @@ BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
if (level == lldb::eDescriptionLevelFull || level == eDescriptionLevelInitial)
{
- s->PutCString("where = ");
+ if (IsReExported())
+ s->PutCString ("re-exported target = ");
+ else
+ s->PutCString("where = ");
sc.DumpStopContext (s, m_owner.GetTarget().GetProcessSP().get(), m_address, false, true, false);
}
else
@@ -584,7 +600,10 @@ BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
if (sc.symbol)
{
s->EOL();
- s->Indent("symbol = ");
+ if (IsReExported())
+ s->Indent ("re-exported target = ");
+ else
+ s->Indent("symbol = ");
s->PutCString(sc.symbol->GetMangled().GetName().AsCString("<unknown>"));
}
}
@@ -612,6 +631,24 @@ BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress);
else
m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress);
+
+ if (IsIndirect() && m_bp_site_sp)
+ {
+ Address resolved_address;
+ resolved_address.SetLoadAddress(m_bp_site_sp->GetLoadAddress(), target);
+ Symbol *resolved_symbol = resolved_address.CalculateSymbolContextSymbol();
+ if (resolved_symbol)
+ {
+ if (level == eDescriptionLevelFull || level == eDescriptionLevelInitial)
+ s->Printf (", ");
+ else if (level == lldb::eDescriptionLevelVerbose)
+ {
+ s->EOL();
+ s->Indent();
+ }
+ s->Printf ("indirect target = %s", resolved_symbol->GetName().GetCString());
+ }
+ }
if (level == lldb::eDescriptionLevelVerbose)
{
diff --git a/source/Breakpoint/BreakpointLocationList.cpp b/source/Breakpoint/BreakpointLocationList.cpp
index 18147deca3ec..917c776e75d2 100644
--- a/source/Breakpoint/BreakpointLocationList.cpp
+++ b/source/Breakpoint/BreakpointLocationList.cpp
@@ -19,8 +19,10 @@
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/Section.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -39,12 +41,12 @@ BreakpointLocationList::~BreakpointLocationList()
}
BreakpointLocationSP
-BreakpointLocationList::Create (const Address &addr)
+BreakpointLocationList::Create (const Address &addr, bool resolve_indirect_symbols)
{
Mutex::Locker locker (m_mutex);
// The location ID is just the size of the location list + 1
lldb::break_id_t bp_loc_id = ++m_next_id;
- BreakpointLocationSP bp_loc_sp (new BreakpointLocation (bp_loc_id, m_owner, addr, LLDB_INVALID_THREAD_ID, m_owner.IsHardware()));
+ BreakpointLocationSP bp_loc_sp (new BreakpointLocation (bp_loc_id, m_owner, addr, LLDB_INVALID_THREAD_ID, m_owner.IsHardware(), resolve_indirect_symbols));
m_locations.push_back (bp_loc_sp);
m_address_to_location[addr] = bp_loc_sp;
return bp_loc_sp;
@@ -245,7 +247,7 @@ BreakpointLocationList::GetDescription (Stream *s, lldb::DescriptionLevel level)
}
BreakpointLocationSP
-BreakpointLocationList::AddLocation (const Address &addr, bool *new_location)
+BreakpointLocationList::AddLocation (const Address &addr, bool resolve_indirect_symbols, bool *new_location)
{
Mutex::Locker locker (m_mutex);
@@ -254,7 +256,7 @@ BreakpointLocationList::AddLocation (const Address &addr, bool *new_location)
BreakpointLocationSP bp_loc_sp (FindByAddress(addr));
if (!bp_loc_sp)
{
- bp_loc_sp = Create (addr);
+ bp_loc_sp = Create (addr, resolve_indirect_symbols);
if (bp_loc_sp)
{
bp_loc_sp->ResolveBreakpointSite();
diff --git a/source/Breakpoint/BreakpointResolverName.cpp b/source/Breakpoint/BreakpointResolverName.cpp
index c82dd5ee050b..cf5d89cb7a8b 100644
--- a/source/Breakpoint/BreakpointResolverName.cpp
+++ b/source/Breakpoint/BreakpointResolverName.cpp
@@ -272,6 +272,8 @@ BreakpointResolverName::SearchCallback
{
if (func_list.GetContextAtIndex(i, sc))
{
+ bool is_reexported = false;
+
if (sc.block && sc.block->GetInlinedFunctionInfo())
{
if (!sc.block->GetStartAddress(break_addr))
@@ -293,7 +295,10 @@ BreakpointResolverName::SearchCallback
{
const Symbol *actual_symbol = sc.symbol->ResolveReExportedSymbol(m_breakpoint->GetTarget());
if (actual_symbol)
+ {
+ is_reexported = true;
break_addr = actual_symbol->GetAddress();
+ }
}
else
{
@@ -313,6 +318,7 @@ BreakpointResolverName::SearchCallback
if (filter.AddressPasses(break_addr))
{
BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(break_addr, &new_location));
+ bp_loc_sp->SetIsReExported(is_reexported);
if (bp_loc_sp && new_location && !m_breakpoint->IsInternal())
{
if (log)
diff --git a/source/Commands/CommandObjectBreakpointCommand.cpp b/source/Commands/CommandObjectBreakpointCommand.cpp
index e540461dadae..532d6cedc83e 100644
--- a/source/Commands/CommandObjectBreakpointCommand.cpp
+++ b/source/Commands/CommandObjectBreakpointCommand.cpp
@@ -16,6 +16,7 @@
#include "CommandObjectBreakpointCommand.h"
#include "CommandObjectBreakpoint.h"
+#include "lldb/Core/IOHandler.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Target/Target.h"
@@ -34,7 +35,9 @@ using namespace lldb_private;
//-------------------------------------------------------------------------
-class CommandObjectBreakpointCommandAdd : public CommandObjectParsed
+class CommandObjectBreakpointCommandAdd :
+ public CommandObjectParsed,
+ public IOHandlerDelegateMultiline
{
public:
@@ -43,6 +46,7 @@ public:
"add",
"Add a set of commands to a breakpoint, to be executed whenever the breakpoint is hit.",
NULL),
+ IOHandlerDelegateMultiline ("DONE", IOHandlerDelegate::Completion::LLDBCommand),
m_options (interpreter)
{
SetHelpLong (
@@ -207,42 +211,47 @@ one command per line.\n" );
return &m_options;
}
- void
- CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
- CommandReturnObject &result)
+ virtual void
+ IOHandlerActivated (IOHandler &io_handler)
{
- InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
- std::unique_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());
- if (reader_sp && data_ap.get())
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp)
{
- BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release()));
- bp_options->SetCallback (BreakpointOptionsCallbackFunction, baton_sp);
-
- Error err (reader_sp->Initialize (CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback,
- bp_options, // baton
- eInputReaderGranularityLine, // token size, to pass to callback function
- "DONE", // end token
- "> ", // prompt
- true)); // echo input
- if (err.Success())
- {
- m_interpreter.GetDebugger().PushInputReader (reader_sp);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError (err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
+ output_sp->PutCString(g_reader_instructions);
+ output_sp->Flush();
}
- else
+ }
+
+
+ virtual void
+ IOHandlerInputComplete (IOHandler &io_handler, std::string &line)
+ {
+ io_handler.SetIsDone(true);
+
+ BreakpointOptions *bp_options = (BreakpointOptions *) io_handler.GetUserData();
+ if (bp_options)
{
- result.AppendError("out of memory");
- result.SetStatus (eReturnStatusFailed);
+ std::unique_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());
+ if (data_ap.get())
+ {
+ data_ap->user_source.SplitIntoLines (line.c_str(), line.size());
+ BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release()));
+ bp_options->SetCallback (BreakpointOptionsCallbackFunction, baton_sp);
+ }
}
}
+ void
+ CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
+ CommandReturnObject &result)
+ {
+ m_interpreter.GetLLDBCommandsFromIOHandler ("> ", // Prompt
+ *this, // IOHandlerDelegate
+ true, // Run IOHandler in async mode
+ bp_options); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
+ }
+
/// Set a one-liner as the callback for the breakpoint.
void
SetBreakpointCommandCallback (BreakpointOptions *bp_options,
@@ -262,93 +271,6 @@ one command per line.\n" );
return;
}
-
- static size_t
- GenerateBreakpointCommandCallback (void *baton,
- InputReader &reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len)
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
-
- switch (notification)
- {
- case eInputReaderActivate:
- if (!batch_mode)
- {
- out_stream->Printf ("%s\n", g_reader_instructions);
- if (reader.GetPrompt())
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush();
- }
- break;
-
- case eInputReaderDeactivate:
- break;
-
- case eInputReaderReactivate:
- if (reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush();
- }
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
-
- case eInputReaderGotToken:
- if (bytes && bytes_len && baton)
- {
- BreakpointOptions *bp_options = (BreakpointOptions *) baton;
- if (bp_options)
- {
- Baton *bp_options_baton = bp_options->GetBaton();
- if (bp_options_baton)
- ((BreakpointOptions::CommandData *)bp_options_baton->m_data)->user_source.AppendString (bytes, bytes_len);
- }
- }
- if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush();
- }
- break;
-
- case eInputReaderInterrupt:
- {
- // Finish, and cancel the breakpoint command.
- reader.SetIsDone (true);
- BreakpointOptions *bp_options = (BreakpointOptions *) baton;
- if (bp_options)
- {
- Baton *bp_options_baton = bp_options->GetBaton ();
- if (bp_options_baton)
- {
- ((BreakpointOptions::CommandData *) bp_options_baton->m_data)->user_source.Clear();
- ((BreakpointOptions::CommandData *) bp_options_baton->m_data)->script_source.clear();
- }
- }
- if (!batch_mode)
- {
- out_stream->Printf ("Warning: No command attached to breakpoint.\n");
- out_stream->Flush();
- }
- }
- break;
-
- case eInputReaderEndOfFile:
- reader.SetIsDone (true);
- break;
-
- case eInputReaderDone:
- break;
- }
-
- return bytes_len;
- }
static bool
BreakpointOptionsCallbackFunction (void *baton,
@@ -623,7 +545,7 @@ private:
};
const char *
-CommandObjectBreakpointCommandAdd::g_reader_instructions = "Enter your debugger command(s). Type 'DONE' to end.";
+CommandObjectBreakpointCommandAdd::g_reader_instructions = "Enter your debugger command(s). Type 'DONE' to end.\n";
// FIXME: "script-type" needs to have its contents determined dynamically, so somebody can add a new scripting
// language to lldb and have it pickable here without having to change this enumeration by hand and rebuild lldb proper.
diff --git a/source/Commands/CommandObjectBreakpointCommand.h b/source/Commands/CommandObjectBreakpointCommand.h
index afedb7602cdd..e91790779510 100644
--- a/source/Commands/CommandObjectBreakpointCommand.h
+++ b/source/Commands/CommandObjectBreakpointCommand.h
@@ -19,7 +19,6 @@
#include "lldb/lldb-types.h"
#include "lldb/Interpreter/Options.h"
-#include "lldb/Core/InputReader.h"
#include "lldb/Interpreter/CommandObject.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
diff --git a/source/Commands/CommandObjectCommands.cpp b/source/Commands/CommandObjectCommands.cpp
index 6824ead0d9e0..7bfdec094d6c 100644
--- a/source/Commands/CommandObjectCommands.cpp
+++ b/source/Commands/CommandObjectCommands.cpp
@@ -18,8 +18,7 @@
// Project includes
#include "lldb/Core/Debugger.h"
-#include "lldb/Core/InputReader.h"
-#include "lldb/Core/InputReaderEZ.h"
+#include "lldb/Core/IOHandler.h"
#include "lldb/Core/StringList.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandHistory.h"
@@ -309,7 +308,9 @@ protected:
CommandOptions (CommandInterpreter &interpreter) :
Options (interpreter),
- m_stop_on_error (true)
+ m_stop_on_error (true),
+ m_silent_run (false),
+ m_stop_on_continue (true)
{
}
@@ -321,23 +322,21 @@ protected:
{
Error error;
const int short_option = m_getopt_table[option_idx].val;
- bool success;
switch (short_option)
{
case 'e':
error = m_stop_on_error.SetValueFromCString(option_arg);
break;
+
case 'c':
- m_stop_on_continue = Args::StringToBoolean(option_arg, true, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid value for stop-on-continue: %s", option_arg);
+ error = m_stop_on_continue.SetValueFromCString(option_arg);
break;
+
case 's':
- m_silent_run = Args::StringToBoolean(option_arg, true, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid value for silent-run: %s", option_arg);
+ error = m_silent_run.SetValueFromCString(option_arg);
break;
+
default:
error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
break;
@@ -350,8 +349,8 @@ protected:
OptionParsingStarting ()
{
m_stop_on_error.Clear();
- m_silent_run = false;
- m_stop_on_continue = true;
+ m_silent_run.Clear();
+ m_stop_on_continue.Clear();
}
const OptionDefinition*
@@ -367,8 +366,8 @@ protected:
// Instance variables to hold the values for command options.
OptionValueBoolean m_stop_on_error;
- bool m_silent_run;
- bool m_stop_on_continue;
+ OptionValueBoolean m_silent_run;
+ OptionValueBoolean m_stop_on_continue;
};
bool
@@ -379,22 +378,40 @@ protected:
{
const char *filename = command.GetArgumentAtIndex(0);
- result.AppendMessageWithFormat ("Executing commands in '%s'.\n", filename);
-
FileSpec cmd_file (filename, true);
ExecutionContext *exe_ctx = NULL; // Just use the default context.
- bool echo_commands = !m_options.m_silent_run;
- bool print_results = true;
- bool stop_on_error = m_options.m_stop_on_error.OptionWasSet() ? (bool)m_options.m_stop_on_error : m_interpreter.GetStopCmdSourceOnError();
-
- m_interpreter.HandleCommandsFromFile (cmd_file,
- exe_ctx,
- m_options.m_stop_on_continue,
- stop_on_error,
- echo_commands,
- print_results,
- eLazyBoolCalculate,
- result);
+
+ // If any options were set, then use them
+ if (m_options.m_stop_on_error.OptionWasSet() ||
+ m_options.m_silent_run.OptionWasSet() ||
+ m_options.m_stop_on_continue.OptionWasSet())
+ {
+ // Use user set settings
+ LazyBool print_command = m_options.m_silent_run.GetCurrentValue() ? eLazyBoolNo : eLazyBoolYes;
+ m_interpreter.HandleCommandsFromFile (cmd_file,
+ exe_ctx,
+ m_options.m_stop_on_continue.GetCurrentValue() ? eLazyBoolYes : eLazyBoolNo, // Stop on continue
+ m_options.m_stop_on_error.GetCurrentValue() ? eLazyBoolYes : eLazyBoolNo, // Stop on error
+ print_command, // Echo command
+ print_command, // Print command output
+ eLazyBoolCalculate, // Add to history
+ result);
+
+ }
+ else
+ {
+ // No options were set, inherit any settings from nested "command source" commands,
+ // or set to sane default settings...
+ m_interpreter.HandleCommandsFromFile (cmd_file,
+ exe_ctx,
+ eLazyBoolCalculate, // Stop on continue
+ eLazyBoolCalculate, // Stop on error
+ eLazyBoolCalculate, // Echo command
+ eLazyBoolCalculate, // Print command output
+ eLazyBoolCalculate, // Add to history
+ result);
+
+ }
}
else
{
@@ -423,7 +440,7 @@ CommandObjectCommandsSource::CommandOptions::g_option_table[] =
static const char *g_python_command_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
"You must define a Python function with this signature:\n"
- "def my_command_impl(debugger, args, result, internal_dict):";
+ "def my_command_impl(debugger, args, result, internal_dict):\n";
class CommandObjectCommandsAlias : public CommandObjectRaw
@@ -856,7 +873,9 @@ protected:
//-------------------------------------------------------------------------
#pragma mark CommandObjectCommandsAddRegex
-class CommandObjectCommandsAddRegex : public CommandObjectParsed
+class CommandObjectCommandsAddRegex :
+ public CommandObjectParsed,
+ public IOHandlerDelegate
{
public:
CommandObjectCommandsAddRegex (CommandInterpreter &interpreter) :
@@ -864,6 +883,7 @@ public:
"command regex",
"Allow the user to create a regular expression command.",
"command regex <cmd-name> [s/<regex>/<subst>/ ...]"),
+ IOHandlerDelegate(IOHandlerDelegate::Completion::LLDBCommand),
m_options (interpreter)
{
SetHelpLong(
@@ -899,6 +919,97 @@ public:
protected:
+
+ virtual void
+ IOHandlerActivated (IOHandler &io_handler)
+ {
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp)
+ {
+ output_sp->PutCString("Enter one of more sed substitution commands in the form: 's/<regex>/<subst>/'.\nTerminate the substitution list with an empty line.\n");
+ output_sp->Flush();
+ }
+ }
+
+ virtual void
+ IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
+ {
+ io_handler.SetIsDone(true);
+ if (m_regex_cmd_ap.get())
+ {
+ StringList lines;
+ if (lines.SplitIntoLines (data))
+ {
+ const size_t num_lines = lines.GetSize();
+ bool check_only = false;
+ for (size_t i=0; i<num_lines; ++i)
+ {
+ printf ("regex[%zu] = %s\n", i, lines[i].c_str());
+ llvm::StringRef bytes_strref (lines[i]);
+ Error error = AppendRegexSubstitution (bytes_strref, check_only);
+ if (error.Fail())
+ {
+ if (!m_interpreter.GetDebugger().GetCommandInterpreter().GetBatchCommandMode())
+ {
+ StreamSP out_stream = m_interpreter.GetDebugger().GetAsyncOutputStream();
+ out_stream->Printf("error: %s\n", error.AsCString());
+ }
+ }
+ }
+ }
+ if (m_regex_cmd_ap->HasRegexEntries())
+ {
+ CommandObjectSP cmd_sp (m_regex_cmd_ap.release());
+ m_interpreter.AddCommand(cmd_sp->GetCommandName(), cmd_sp, true);
+ }
+ }
+ }
+
+ virtual LineStatus
+ IOHandlerLinesUpdated (IOHandler &io_handler,
+ StringList &lines,
+ uint32_t line_idx,
+ Error &error)
+ {
+ if (line_idx == UINT32_MAX)
+ {
+ // Return true to indicate we are done getting lines (this
+ // is a "fake" line - the real terminating blank line was
+ // removed during a previous call with the code below)
+ error.Clear();
+ return LineStatus::Done;
+ }
+ else
+ {
+ const size_t num_lines = lines.GetSize();
+ if (line_idx + 1 == num_lines)
+ {
+ // The last line was edited, if this line is empty, then we are done
+ // getting our multiple lines.
+ if (lines[line_idx].empty())
+ {
+ // Remove the last empty line from "lines" so it doesn't appear
+ // in our final expression and return true to indicate we are done
+ // getting lines
+ lines.PopBack();
+ return LineStatus::Done;
+ }
+ }
+ // Check the current line to make sure it is formatted correctly
+ bool check_only = true;
+ llvm::StringRef regex_sed(lines[line_idx]);
+ error = AppendRegexSubstitution (regex_sed, check_only);
+ if (error.Fail())
+ {
+ return LineStatus::Error;
+ }
+ else
+ {
+ return LineStatus::Success;
+ }
+ }
+ }
+
bool
DoExecute (Args& command, CommandReturnObject &result)
{
@@ -920,21 +1031,18 @@ protected:
if (argc == 1)
{
- InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
- if (reader_sp)
+ Debugger &debugger = m_interpreter.GetDebugger();
+ const bool multiple_lines = true; // Get multiple lines
+ IOHandlerSP io_handler_sp (new IOHandlerEditline (debugger,
+ "lldb", // Name of input reader for history
+ "\033[K> ", // Prompt and clear line
+ multiple_lines,
+ *this));
+
+ if (io_handler_sp)
{
- error =reader_sp->Initialize (CommandObjectCommandsAddRegex::InputReaderCallback,
- this, // baton
- eInputReaderGranularityLine, // token size, to pass to callback function
- NULL, // end token
- "> ", // prompt
- true); // echo input
- if (error.Success())
- {
- m_interpreter.GetDebugger().PushInputReader (reader_sp);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- return true;
- }
+ debugger.PushIOHandler(io_handler_sp);
+ result.SetStatus (eReturnStatusSuccessFinishNoResult);
}
}
else
@@ -942,7 +1050,8 @@ protected:
for (size_t arg_idx = 1; arg_idx < argc; ++arg_idx)
{
llvm::StringRef arg_strref (command.GetArgumentAtIndex(arg_idx));
- error = AppendRegexSubstitution (arg_strref);
+ bool check_only = false;
+ error = AppendRegexSubstitution (arg_strref, check_only);
if (error.Fail())
break;
}
@@ -963,7 +1072,7 @@ protected:
}
Error
- AppendRegexSubstitution (const llvm::StringRef &regex_sed)
+ AppendRegexSubstitution (const llvm::StringRef &regex_sed, bool check_only)
{
Error error;
@@ -1053,10 +1162,14 @@ protected:
regex_sed.data());
return error;
}
- std::string regex(regex_sed.substr(first_separator_char_pos + 1, second_separator_char_pos - first_separator_char_pos - 1));
- std::string subst(regex_sed.substr(second_separator_char_pos + 1, third_separator_char_pos - second_separator_char_pos - 1));
- m_regex_cmd_ap->AddRegexCommand (regex.c_str(),
- subst.c_str());
+
+ if (check_only == false)
+ {
+ std::string regex(regex_sed.substr(first_separator_char_pos + 1, second_separator_char_pos - first_separator_char_pos - 1));
+ std::string subst(regex_sed.substr(second_separator_char_pos + 1, third_separator_char_pos - second_separator_char_pos - 1));
+ m_regex_cmd_ap->AddRegexCommand (regex.c_str(),
+ subst.c_str());
+ }
return error;
}
@@ -1073,89 +1186,6 @@ protected:
}
}
- void
- InputReaderDidCancel()
- {
- m_regex_cmd_ap.reset();
- }
-
- static size_t
- InputReaderCallback (void *baton,
- InputReader &reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len)
- {
- CommandObjectCommandsAddRegex *add_regex_cmd = (CommandObjectCommandsAddRegex *) baton;
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
-
- switch (notification)
- {
- case eInputReaderActivate:
- if (!batch_mode)
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream ();
- out_stream->Printf("%s\n", "Enter regular expressions in the form 's/<regex>/<subst>/' and terminate with an empty line:");
- out_stream->Flush();
- }
- break;
- case eInputReaderReactivate:
- break;
-
- case eInputReaderDeactivate:
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
-
- case eInputReaderGotToken:
- while (bytes_len > 0 && (bytes[bytes_len-1] == '\r' || bytes[bytes_len-1] == '\n'))
- --bytes_len;
- if (bytes_len == 0)
- reader.SetIsDone(true);
- else if (bytes)
- {
- llvm::StringRef bytes_strref (bytes, bytes_len);
- Error error (add_regex_cmd->AppendRegexSubstitution (bytes_strref));
- if (error.Fail())
- {
- if (!batch_mode)
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- out_stream->Printf("error: %s\n", error.AsCString());
- out_stream->Flush();
- }
- add_regex_cmd->InputReaderDidCancel ();
- reader.SetIsDone (true);
- }
- }
- break;
-
- case eInputReaderInterrupt:
- {
- reader.SetIsDone (true);
- if (!batch_mode)
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- out_stream->PutCString("Regular expression command creations was cancelled.\n");
- out_stream->Flush();
- }
- add_regex_cmd->InputReaderDidCancel ();
- }
- break;
-
- case eInputReaderEndOfFile:
- reader.SetIsDone (true);
- break;
-
- case eInputReaderDone:
- add_regex_cmd->AddRegexCommandToInterpreter();
- break;
- }
-
- return bytes_len;
- }
-
private:
std::unique_ptr<CommandObjectRegexCommand> m_regex_cmd_ap;
@@ -1526,7 +1556,9 @@ CommandObjectCommandsScriptImport::CommandOptions::g_option_table[] =
// CommandObjectCommandsScriptAdd
//-------------------------------------------------------------------------
-class CommandObjectCommandsScriptAdd : public CommandObjectParsed
+class CommandObjectCommandsScriptAdd :
+ public CommandObjectParsed,
+ public IOHandlerDelegateMultiline
{
public:
CommandObjectCommandsScriptAdd(CommandInterpreter &interpreter) :
@@ -1534,6 +1566,7 @@ public:
"command script add",
"Add a scripted function as an LLDB command.",
NULL),
+ IOHandlerDelegateMultiline ("DONE"),
m_options (interpreter)
{
CommandArgumentEntry arg1;
@@ -1567,7 +1600,7 @@ protected:
public:
CommandOptions (CommandInterpreter &interpreter) :
- Options (interpreter)
+ Options (interpreter)
{
}
@@ -1586,7 +1619,7 @@ protected:
m_funct_name = std::string(option_arg);
break;
case 's':
- m_synchronous = (ScriptedCommandSynchronicity) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
+ m_synchronicity = (ScriptedCommandSynchronicity) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
if (!error.Success())
error.SetErrorStringWithFormat ("unrecognized value for synchronicity '%s'", option_arg);
break;
@@ -1602,7 +1635,7 @@ protected:
OptionParsingStarting ()
{
m_funct_name = "";
- m_synchronous = eScriptedCommandSynchronicitySynchronous;
+ m_synchronicity = eScriptedCommandSynchronicitySynchronous;
}
const OptionDefinition*
@@ -1618,128 +1651,81 @@ protected:
// Instance variables to hold the values for command options.
std::string m_funct_name;
- ScriptedCommandSynchronicity m_synchronous;
+ ScriptedCommandSynchronicity m_synchronicity;
};
-private:
- class PythonAliasReader : public InputReaderEZ
+ virtual void
+ IOHandlerActivated (IOHandler &io_handler)
{
- private:
- CommandInterpreter& m_interpreter;
- std::string m_cmd_name;
- ScriptedCommandSynchronicity m_synchronous;
- StringList m_user_input;
- DISALLOW_COPY_AND_ASSIGN (PythonAliasReader);
- public:
- PythonAliasReader(Debugger& debugger,
- CommandInterpreter& interpreter,
- std::string cmd_name,
- ScriptedCommandSynchronicity synch) :
- InputReaderEZ(debugger),
- m_interpreter(interpreter),
- m_cmd_name(cmd_name),
- m_synchronous(synch),
- m_user_input()
- {}
-
- virtual
- ~PythonAliasReader()
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp)
{
+ output_sp->PutCString(g_python_command_instructions);
+ output_sp->Flush();
}
+ }
+
+
+ virtual void
+ IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
+ {
+ StreamFileSP error_sp = io_handler.GetErrorStreamFile();
- virtual void ActivateHandler(HandlerData& data)
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ if (interpreter)
{
- StreamSP out_stream = data.GetOutStream();
- bool batch_mode = data.GetBatchMode();
- if (!batch_mode)
- {
- out_stream->Printf ("%s\n", g_python_command_instructions);
- if (data.reader.GetPrompt())
- out_stream->Printf ("%s", data.reader.GetPrompt());
- out_stream->Flush();
- }
- }
- virtual void ReactivateHandler(HandlerData& data)
- {
- StreamSP out_stream = data.GetOutStream();
- bool batch_mode = data.GetBatchMode();
- if (data.reader.GetPrompt() && !batch_mode)
+ StringList lines;
+ lines.SplitIntoLines(data);
+ if (lines.GetSize() > 0)
{
- out_stream->Printf ("%s", data.reader.GetPrompt());
- out_stream->Flush();
- }
- }
- virtual void GotTokenHandler(HandlerData& data)
- {
- StreamSP out_stream = data.GetOutStream();
- bool batch_mode = data.GetBatchMode();
- if (data.bytes && data.bytes_len)
- {
- m_user_input.AppendString(data.bytes, data.bytes_len);
- }
- if (!data.reader.IsDone() && data.reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", data.reader.GetPrompt());
- out_stream->Flush();
+ std::string funct_name_str;
+ if (interpreter->GenerateScriptAliasFunction (lines, funct_name_str))
+ {
+ if (funct_name_str.empty())
+ {
+ error_sp->Printf ("error: unable to obtain a function name, didn't add python command.\n");
+ error_sp->Flush();
+ }
+ else
+ {
+ // everything should be fine now, let's add this alias
+
+ CommandObjectSP command_obj_sp(new CommandObjectPythonFunction (m_interpreter,
+ m_cmd_name,
+ funct_name_str.c_str(),
+ m_synchronicity));
+
+ if (!m_interpreter.AddUserCommand(m_cmd_name, command_obj_sp, true))
+ {
+ error_sp->Printf ("error: unable to add selected command, didn't add python command.\n");
+ error_sp->Flush();
+ }
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: unable to create function, didn't add python command.\n");
+ error_sp->Flush();
+ }
}
- }
- virtual void InterruptHandler(HandlerData& data)
- {
- StreamSP out_stream = data.GetOutStream();
- bool batch_mode = data.GetBatchMode();
- data.reader.SetIsDone (true);
- if (!batch_mode)
+ else
{
- out_stream->Printf ("Warning: No script attached.\n");
- out_stream->Flush();
+ error_sp->Printf ("error: empty function, didn't add python command.\n");
+ error_sp->Flush();
}
}
- virtual void EOFHandler(HandlerData& data)
+ else
{
- data.reader.SetIsDone (true);
+ error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
+ error_sp->Flush();
}
- virtual void DoneHandler(HandlerData& data)
- {
- StreamSP out_stream = data.GetOutStream();
-
- ScriptInterpreter *interpreter = data.reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
- if (!interpreter)
- {
- out_stream->Printf ("Script interpreter missing: no script attached.\n");
- out_stream->Flush();
- return;
- }
- std::string funct_name_str;
- if (!interpreter->GenerateScriptAliasFunction (m_user_input,
- funct_name_str))
- {
- out_stream->Printf ("Unable to create function: no script attached.\n");
- out_stream->Flush();
- return;
- }
- if (funct_name_str.empty())
- {
- out_stream->Printf ("Unable to obtain a function name: no script attached.\n");
- out_stream->Flush();
- return;
- }
- // everything should be fine now, let's add this alias
-
- CommandObjectSP command_obj_sp(new CommandObjectPythonFunction(m_interpreter,
- m_cmd_name,
- funct_name_str.c_str(),
- m_synchronous));
-
- if (!m_interpreter.AddUserCommand(m_cmd_name, command_obj_sp, true))
- {
- out_stream->Printf ("Unable to add selected command: no script attached.\n");
- out_stream->Flush();
- return;
- }
- }
- };
-
+
+ io_handler.SetIsDone(true);
+
+
+ }
+
protected:
bool
DoExecute (Args& command, CommandReturnObject &result)
@@ -1761,45 +1747,24 @@ protected:
return false;
}
- std::string cmd_name = command.GetArgumentAtIndex(0);
+ // Store the command name and synchronicity in case we get multi-line input
+ m_cmd_name = command.GetArgumentAtIndex(0);
+ m_synchronicity = m_options.m_synchronicity;
if (m_options.m_funct_name.empty())
{
- InputReaderSP reader_sp (new PythonAliasReader (m_interpreter.GetDebugger(),
- m_interpreter,
- cmd_name,
- m_options.m_synchronous));
-
- if (reader_sp)
- {
-
- InputReaderEZ::InitializationParameters ipr;
-
- Error err (reader_sp->Initialize (ipr.SetBaton(NULL).SetPrompt(" ")));
- if (err.Success())
- {
- m_interpreter.GetDebugger().PushInputReader (reader_sp);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError (err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendError("out of memory");
- result.SetStatus (eReturnStatusFailed);
- }
+ m_interpreter.GetPythonCommandsFromIOHandler (" ", // Prompt
+ *this, // IOHandlerDelegate
+ true, // Run IOHandler in async mode
+ NULL); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
}
else
{
CommandObjectSP new_cmd(new CommandObjectPythonFunction(m_interpreter,
- cmd_name,
+ m_cmd_name,
m_options.m_funct_name,
- m_options.m_synchronous));
- if (m_interpreter.AddUserCommand(cmd_name, new_cmd, true))
+ m_synchronicity));
+ if (m_interpreter.AddUserCommand(m_cmd_name, new_cmd, true))
{
result.SetStatus (eReturnStatusSuccessFinishNoResult);
}
@@ -1815,6 +1780,8 @@ protected:
}
CommandOptions m_options;
+ std::string m_cmd_name;
+ ScriptedCommandSynchronicity m_synchronicity;
};
static OptionEnumValueElement g_script_synchro_type[] =
diff --git a/source/Commands/CommandObjectDisassemble.cpp b/source/Commands/CommandObjectDisassemble.cpp
index fc148b1899f6..f9c683b364ce 100644
--- a/source/Commands/CommandObjectDisassemble.cpp
+++ b/source/Commands/CommandObjectDisassemble.cpp
@@ -27,6 +27,7 @@
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
diff --git a/source/Commands/CommandObjectExpression.cpp b/source/Commands/CommandObjectExpression.cpp
index 5ca44ff920d6..c772a2e58912 100644
--- a/source/Commands/CommandObjectExpression.cpp
+++ b/source/Commands/CommandObjectExpression.cpp
@@ -17,7 +17,6 @@
// Project includes
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/Value.h"
-#include "lldb/Core/InputReader.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/DataFormatters/ValueObjectPrinter.h"
#include "lldb/Expression/ClangExpressionVariable.h"
@@ -197,6 +196,7 @@ CommandObjectExpression::CommandObjectExpression (CommandInterpreter &interprete
"Evaluate a C/ObjC/C++ expression in the current program context, using user defined variables and variables currently in scope.",
NULL,
eFlagProcessMustBePaused | eFlagTryTargetAPILock),
+ IOHandlerDelegate (IOHandlerDelegate::Completion::Expression),
m_option_group (interpreter),
m_format_options (eFormatDefault),
m_command_options (),
@@ -254,87 +254,6 @@ CommandObjectExpression::GetOptions ()
return &m_option_group;
}
-size_t
-CommandObjectExpression::MultiLineExpressionCallback
-(
- void *baton,
- InputReader &reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len
-)
-{
- CommandObjectExpression *cmd_object_expr = (CommandObjectExpression *) baton;
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
-
- switch (notification)
- {
- case eInputReaderActivate:
- if (!batch_mode)
- {
- StreamSP async_strm_sp(reader.GetDebugger().GetAsyncOutputStream());
- if (async_strm_sp)
- {
- async_strm_sp->PutCString("Enter expressions, then terminate with an empty line to evaluate:\n");
- async_strm_sp->Flush();
- }
- }
- // Fall through
- case eInputReaderReactivate:
- break;
-
- case eInputReaderDeactivate:
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
-
- case eInputReaderGotToken:
- ++cmd_object_expr->m_expr_line_count;
- if (bytes && bytes_len)
- {
- cmd_object_expr->m_expr_lines.append (bytes, bytes_len + 1);
- }
-
- if (bytes_len == 0)
- reader.SetIsDone(true);
- break;
-
- case eInputReaderInterrupt:
- cmd_object_expr->m_expr_lines.clear();
- reader.SetIsDone (true);
- if (!batch_mode)
- {
- StreamSP async_strm_sp (reader.GetDebugger().GetAsyncOutputStream());
- if (async_strm_sp)
- {
- async_strm_sp->PutCString("Expression evaluation cancelled.\n");
- async_strm_sp->Flush();
- }
- }
- break;
-
- case eInputReaderEndOfFile:
- reader.SetIsDone (true);
- break;
-
- case eInputReaderDone:
- if (cmd_object_expr->m_expr_lines.size() > 0)
- {
- StreamSP output_stream = reader.GetDebugger().GetAsyncOutputStream();
- StreamSP error_stream = reader.GetDebugger().GetAsyncErrorStream();
- cmd_object_expr->EvaluateExpression (cmd_object_expr->m_expr_lines.c_str(),
- output_stream.get(),
- error_stream.get());
- output_stream->Flush();
- error_stream->Flush();
- }
- break;
- }
-
- return bytes_len;
-}
-
bool
CommandObjectExpression::EvaluateExpression
(
@@ -373,6 +292,8 @@ CommandObjectExpression::EvaluateExpression
if (m_command_options.timeout > 0)
options.SetTimeoutUsec(m_command_options.timeout);
+ else
+ options.SetTimeoutUsec(0);
exe_results = target->EvaluateExpression (expr,
exe_ctx.GetFramePtr(),
@@ -443,6 +364,48 @@ CommandObjectExpression::EvaluateExpression
return true;
}
+void
+CommandObjectExpression::IOHandlerInputComplete (IOHandler &io_handler, std::string &line)
+{
+ io_handler.SetIsDone(true);
+// StreamSP output_stream = io_handler.GetDebugger().GetAsyncOutputStream();
+// StreamSP error_stream = io_handler.GetDebugger().GetAsyncErrorStream();
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP error_sp(io_handler.GetErrorStreamFile());
+
+ EvaluateExpression (line.c_str(),
+ output_sp.get(),
+ error_sp.get());
+ if (output_sp)
+ output_sp->Flush();
+ if (error_sp)
+ error_sp->Flush();
+}
+
+LineStatus
+CommandObjectExpression::IOHandlerLinesUpdated (IOHandler &io_handler,
+ StringList &lines,
+ uint32_t line_idx,
+ Error &error)
+{
+ if (line_idx == UINT32_MAX)
+ {
+ // Remove the last line from "lines" so it doesn't appear
+ // in our final expression
+ lines.PopBack();
+ error.Clear();
+ return LineStatus::Done;
+ }
+ else if (line_idx + 1 == lines.GetSize())
+ {
+ // The last line was edited, if this line is empty, then we are done
+ // getting our multiple lines.
+ if (lines[line_idx].empty())
+ return LineStatus::Done;
+ }
+ return LineStatus::Success;
+}
+
bool
CommandObjectExpression::DoExecute
(
@@ -459,31 +422,21 @@ CommandObjectExpression::DoExecute
m_expr_lines.clear();
m_expr_line_count = 0;
- InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
- if (reader_sp)
- {
- Error err (reader_sp->Initialize (CommandObjectExpression::MultiLineExpressionCallback,
- this, // baton
- eInputReaderGranularityLine, // token size, to pass to callback function
- NULL, // end token
- NULL, // prompt
- true)); // echo input
- if (err.Success())
- {
- m_interpreter.GetDebugger().PushInputReader (reader_sp);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError (err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
+ Debugger &debugger = GetCommandInterpreter().GetDebugger();
+ const bool multiple_lines = true; // Get multiple lines
+ IOHandlerSP io_handler_sp (new IOHandlerEditline (debugger,
+ "lldb-expr", // Name of input reader for history
+ NULL, // No prompt
+ multiple_lines,
+ *this));
+
+ StreamFileSP output_sp(io_handler_sp->GetOutputStreamFile());
+ if (output_sp)
{
- result.AppendError("out of memory");
- result.SetStatus (eReturnStatusFailed);
+ output_sp->PutCString("Enter expressions, then terminate with an empty line to evaluate:\n");
+ output_sp->Flush();
}
+ debugger.PushIOHandler(io_handler_sp);
return result.Succeeded();
}
diff --git a/source/Commands/CommandObjectExpression.h b/source/Commands/CommandObjectExpression.h
index e0703a22a4cc..c943f0e8023d 100644
--- a/source/Commands/CommandObjectExpression.h
+++ b/source/Commands/CommandObjectExpression.h
@@ -14,6 +14,7 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
+#include "lldb/Core/IOHandler.h"
#include "lldb/Interpreter/CommandObject.h"
#include "lldb/Interpreter/OptionGroupFormat.h"
#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
@@ -21,7 +22,9 @@
namespace lldb_private {
-class CommandObjectExpression : public CommandObjectRaw
+class CommandObjectExpression :
+ public CommandObjectRaw,
+ public IOHandlerDelegate
{
public:
@@ -71,17 +74,23 @@ public:
GetOptions ();
protected:
+
+ //------------------------------------------------------------------
+ // IOHandler::Delegate functions
+ //------------------------------------------------------------------
+ virtual void
+ IOHandlerInputComplete (IOHandler &io_handler,
+ std::string &line);
+
+ virtual LineStatus
+ IOHandlerLinesUpdated (IOHandler &io_handler,
+ StringList &lines,
+ uint32_t line_idx,
+ Error &error);
virtual bool
DoExecute (const char *command,
CommandReturnObject &result);
- static size_t
- MultiLineExpressionCallback (void *baton,
- InputReader &reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len);
-
bool
EvaluateExpression (const char *expr,
Stream *output_stream,
diff --git a/source/Commands/CommandObjectGUI.cpp b/source/Commands/CommandObjectGUI.cpp
new file mode 100644
index 000000000000..3d05335e92e4
--- /dev/null
+++ b/source/Commands/CommandObjectGUI.cpp
@@ -0,0 +1,61 @@
+//===-- CommandObjectGUI.cpp ------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/lldb-python.h"
+
+#include "CommandObjectGUI.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/lldb-private.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+//-------------------------------------------------------------------------
+// CommandObjectGUI
+//-------------------------------------------------------------------------
+
+CommandObjectGUI::CommandObjectGUI (CommandInterpreter &interpreter) :
+ CommandObjectParsed (interpreter, "gui", "Switch into the curses based GUI mode.", "gui")
+{
+}
+
+CommandObjectGUI::~CommandObjectGUI ()
+{
+}
+
+bool
+CommandObjectGUI::DoExecute (Args& args, CommandReturnObject &result)
+{
+#ifndef LLDB_DISABLE_CURSES
+ if (args.GetArgumentCount() == 0)
+ {
+ Debugger &debugger = m_interpreter.GetDebugger();
+ IOHandlerSP io_handler_sp (new IOHandlerCursesGUI (debugger));
+ if (io_handler_sp)
+ debugger.PushIOHandler(io_handler_sp);
+ result.SetStatus (eReturnStatusSuccessFinishResult);
+ }
+ else
+ {
+ result.AppendError("the gui command takes no arguments.");
+ result.SetStatus (eReturnStatusFailed);
+ }
+ return true;
+#else
+ result.AppendError("lldb was not build with gui support");
+ return false;
+#endif
+}
+
diff --git a/source/Commands/CommandObjectGUI.h b/source/Commands/CommandObjectGUI.h
new file mode 100644
index 000000000000..72ddb961c266
--- /dev/null
+++ b/source/Commands/CommandObjectGUI.h
@@ -0,0 +1,43 @@
+//===-- CommandObjectGUI.h --------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_CommandObjectGUI_h_
+#define liblldb_CommandObjectGUI_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Interpreter/CommandObject.h"
+
+namespace lldb_private {
+
+//-------------------------------------------------------------------------
+// CommandObjectGUI
+//-------------------------------------------------------------------------
+
+class CommandObjectGUI : public CommandObjectParsed
+{
+public:
+
+ CommandObjectGUI (CommandInterpreter &interpreter);
+
+ virtual
+ ~CommandObjectGUI ();
+
+protected:
+ virtual bool
+ DoExecute (Args& args,
+ CommandReturnObject &result);
+
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_CommandObjectGUI_h_
diff --git a/source/Commands/CommandObjectMultiword.cpp b/source/Commands/CommandObjectMultiword.cpp
index f84b401f3aa6..69b178da46ba 100644
--- a/source/Commands/CommandObjectMultiword.cpp
+++ b/source/Commands/CommandObjectMultiword.cpp
@@ -235,18 +235,19 @@ CommandObjectMultiword::HandleCompletion
// completers will override this.
word_complete = true;
+ const char *arg0 = input.GetArgumentAtIndex(0);
if (cursor_index == 0)
{
CommandObject::AddNamesMatchingPartialString (m_subcommand_dict,
- input.GetArgumentAtIndex(0),
+ arg0,
matches);
if (matches.GetSize() == 1
&& matches.GetStringAtIndex(0) != NULL
- && strcmp (input.GetArgumentAtIndex(0), matches.GetStringAtIndex(0)) == 0)
+ && strcmp (arg0, matches.GetStringAtIndex(0)) == 0)
{
StringList temp_matches;
- CommandObject *cmd_obj = GetSubcommandObject (input.GetArgumentAtIndex(0),
+ CommandObject *cmd_obj = GetSubcommandObject (arg0,
&temp_matches);
if (cmd_obj != NULL)
{
@@ -270,7 +271,7 @@ CommandObjectMultiword::HandleCompletion
}
else
{
- CommandObject *sub_command_object = GetSubcommandObject (input.GetArgumentAtIndex(0),
+ CommandObject *sub_command_object = GetSubcommandObject (arg0,
&matches);
if (sub_command_object == NULL)
{
diff --git a/source/Commands/CommandObjectProcess.cpp b/source/Commands/CommandObjectProcess.cpp
index 2933c78ca908..49a392286c6a 100644
--- a/source/Commands/CommandObjectProcess.cpp
+++ b/source/Commands/CommandObjectProcess.cpp
@@ -49,7 +49,7 @@ public:
virtual ~CommandObjectProcessLaunchOrAttach () {}
protected:
bool
- StopProcessIfNecessary (Process *&process, StateType &state, CommandReturnObject &result)
+ StopProcessIfNecessary (Process *process, StateType &state, CommandReturnObject &result)
{
state = eStateInvalid;
if (process)
@@ -187,12 +187,10 @@ protected:
{
Debugger &debugger = m_interpreter.GetDebugger();
Target *target = debugger.GetSelectedTarget().get();
- Error error;
// If our listener is NULL, users aren't allows to launch
- char filename[PATH_MAX];
- const Module *exe_module = target->GetExecutableModulePointer();
+ ModuleSP exe_module_sp = target->GetExecutableModule();
- if (exe_module == NULL)
+ if (exe_module_sp == NULL)
{
result.AppendError ("no file in target, create a debug target using the 'target create' command");
result.SetStatus (eReturnStatusFailed);
@@ -200,23 +198,31 @@ protected:
}
StateType state = eStateInvalid;
- Process *process = m_exe_ctx.GetProcessPtr();
- if (!StopProcessIfNecessary(process, state, result))
+ if (!StopProcessIfNecessary(m_exe_ctx.GetProcessPtr(), state, result))
return false;
const char *target_settings_argv0 = target->GetArg0();
- exe_module->GetFileSpec().GetPath (filename, sizeof(filename));
+ if (target->GetDisableASLR())
+ m_options.launch_info.GetFlags().Set (eLaunchFlagDisableASLR);
+
+ if (target->GetDisableSTDIO())
+ m_options.launch_info.GetFlags().Set (eLaunchFlagDisableSTDIO);
+ Args environment;
+ target->GetEnvironmentAsArgs (environment);
+ if (environment.GetArgumentCount() > 0)
+ m_options.launch_info.GetEnvironmentEntries ().AppendArguments (environment);
+
if (target_settings_argv0)
{
m_options.launch_info.GetArguments().AppendArgument (target_settings_argv0);
- m_options.launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), false);
+ m_options.launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), false);
}
else
{
- m_options.launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
+ m_options.launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), true);
}
if (launch_args.GetArgumentCount() == 0)
@@ -228,122 +234,33 @@ protected:
else
{
m_options.launch_info.GetArguments().AppendArguments (launch_args);
-
// Save the arguments for subsequent runs in the current target.
target->SetRunArguments (launch_args);
}
- if (target->GetDisableASLR())
- m_options.launch_info.GetFlags().Set (eLaunchFlagDisableASLR);
-
- if (target->GetDisableSTDIO())
- m_options.launch_info.GetFlags().Set (eLaunchFlagDisableSTDIO);
-
- m_options.launch_info.GetFlags().Set (eLaunchFlagDebug);
-
- Args environment;
- target->GetEnvironmentAsArgs (environment);
- if (environment.GetArgumentCount() > 0)
- m_options.launch_info.GetEnvironmentEntries ().AppendArguments (environment);
-
- // Get the value of synchronous execution here. If you wait till after you have started to
- // run, then you could have hit a breakpoint, whose command might switch the value, and
- // then you'll pick up that incorrect value.
- bool synchronous_execution = m_interpreter.GetSynchronous ();
-
- PlatformSP platform_sp (target->GetPlatform());
-
- // Finalize the file actions, and if none were given, default to opening
- // up a pseudo terminal
- const bool default_to_use_pty = platform_sp ? platform_sp->IsHost() : false;
- m_options.launch_info.FinalizeFileActions (target, default_to_use_pty);
-
- if (state == eStateConnected)
- {
- if (m_options.launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
- {
- result.AppendWarning("can't launch in tty when launching through a remote connection");
- m_options.launch_info.GetFlags().Clear (eLaunchFlagLaunchInTTY);
- }
- }
-
- if (!m_options.launch_info.GetArchitecture().IsValid())
- m_options.launch_info.GetArchitecture() = target->GetArchitecture();
+ Error error = target->Launch(debugger.GetListener(), m_options.launch_info);
- if (platform_sp && platform_sp->CanDebugProcess ())
- {
- process = target->GetPlatform()->DebugProcess (m_options.launch_info,
- debugger,
- target,
- debugger.GetListener(),
- error).get();
- }
- else
- {
- const char *plugin_name = m_options.launch_info.GetProcessPluginName();
- process = target->CreateProcess (debugger.GetListener(), plugin_name, NULL).get();
- if (process)
- error = process->Launch (m_options.launch_info);
- }
-
- if (process == NULL)
- {
- result.SetError (error, "failed to launch or debug process");
- return false;
- }
-
-
if (error.Success())
{
- const char *archname = exe_module->GetArchitecture().GetArchitectureName();
-
- result.AppendMessageWithFormat ("Process %" PRIu64 " launched: '%s' (%s)\n", process->GetID(), filename, archname);
- result.SetDidChangeProcessState (true);
- if (m_options.launch_info.GetFlags().Test(eLaunchFlagStopAtEntry) == false)
+ const char *archname = exe_module_sp->GetArchitecture().GetArchitectureName();
+ ProcessSP process_sp (target->GetProcessSP());
+ if (process_sp)
{
- result.SetStatus (eReturnStatusSuccessContinuingNoResult);
- StateType state = process->WaitForProcessToStop (NULL, NULL, false);
-
- if (state == eStateStopped)
- {
- error = process->Resume();
- if (error.Success())
- {
- if (synchronous_execution)
- {
- state = process->WaitForProcessToStop (NULL);
- const bool must_be_alive = true;
- if (!StateIsStoppedState(state, must_be_alive))
- {
- result.AppendErrorWithFormat ("process isn't stopped: %s", StateAsCString(state));
- }
- result.SetDidChangeProcessState (true);
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.SetStatus (eReturnStatusSuccessContinuingNoResult);
- }
- }
- else
- {
- result.AppendErrorWithFormat ("process resume at entry point failed: %s", error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendErrorWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state));
- result.SetStatus (eReturnStatusFailed);
- }
+ result.AppendMessageWithFormat ("Process %" PRIu64 " launched: '%s' (%s)\n", process_sp->GetID(), exe_module_sp->GetFileSpec().GetPath().c_str(), archname);
+ result.SetStatus (eReturnStatusSuccessFinishResult);
+ result.SetDidChangeProcessState (true);
+ }
+ else
+ {
+ result.AppendError("no error returned from Target::Launch, and target has no process");
+ result.SetStatus (eReturnStatusFailed);
}
}
else
{
- result.AppendErrorWithFormat ("process launch failed: %s", error.AsCString());
+ result.AppendError(error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
-
return result.Succeeded();
}
@@ -615,37 +532,36 @@ protected:
if (error.Success())
{
+ ListenerSP listener_sp (new Listener("lldb.CommandObjectProcessAttach.DoExecute.attach.hijack"));
+ m_options.attach_info.SetHijackListener(listener_sp);
+ process->HijackProcessEvents(listener_sp.get());
error = process->Attach (m_options.attach_info);
if (error.Success())
{
result.SetStatus (eReturnStatusSuccessContinuingNoResult);
- }
- else
- {
- result.AppendErrorWithFormat ("attach failed: %s\n", error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- // If we're synchronous, wait for the stopped event and report that.
- // Otherwise just return.
- // FIXME: in the async case it will now be possible to get to the command
- // interpreter with a state eStateAttaching. Make sure we handle that correctly.
- StateType state = process->WaitForProcessToStop (NULL);
-
- result.SetDidChangeProcessState (true);
+ StateType state = process->WaitForProcessToStop (NULL, NULL, false, listener_sp.get());
- if (state == eStateStopped)
- {
- result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state));
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
+ process->RestoreProcessEvents();
+
+ result.SetDidChangeProcessState (true);
+
+ if (state == eStateStopped)
+ {
+ result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state));
+ result.SetStatus (eReturnStatusSuccessFinishNoResult);
+ }
+ else
+ {
+ result.AppendError ("attach failed: process did not stop (no such process or permission problem?)");
+ process->Destroy();
+ result.SetStatus (eReturnStatusFailed);
+ }
}
else
{
- result.AppendError ("attach failed: process did not stop (no such process or permission problem?)");
- process->Destroy();
+ result.AppendErrorWithFormat ("attach failed: %s\n", error.AsCString());
result.SetStatus (eReturnStatusFailed);
- return false;
}
}
}
@@ -1170,7 +1086,7 @@ protected:
if (process)
{
- error = process->ConnectRemote (&process->GetTarget().GetDebugger().GetOutputStream(), remote_url);
+ error = process->ConnectRemote (process->GetTarget().GetDebugger().GetOutputFile().get(), remote_url);
if (error.Fail())
{
diff --git a/source/Commands/CommandObjectQuit.cpp b/source/Commands/CommandObjectQuit.cpp
index d04ecdd9885c..ffe2a9240726 100644
--- a/source/Commands/CommandObjectQuit.cpp
+++ b/source/Commands/CommandObjectQuit.cpp
@@ -92,7 +92,8 @@ CommandObjectQuit::DoExecute (Args& command, CommandReturnObject &result)
return false;
}
}
- m_interpreter.BroadcastEvent (CommandInterpreter::eBroadcastBitQuitCommandReceived);
+ const uint32_t event_type = CommandInterpreter::eBroadcastBitQuitCommandReceived;
+ m_interpreter.BroadcastEvent (event_type);
result.SetStatus (eReturnStatusQuit);
return true;
}
diff --git a/source/Commands/CommandObjectRegister.cpp b/source/Commands/CommandObjectRegister.cpp
index 7cbfaa5d60fc..deaf2ab3793e 100644
--- a/source/Commands/CommandObjectRegister.cpp
+++ b/source/Commands/CommandObjectRegister.cpp
@@ -29,6 +29,7 @@
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Thread.h"
using namespace lldb;
diff --git a/source/Commands/CommandObjectSource.cpp b/source/Commands/CommandObjectSource.cpp
index 1f6873611a22..bf2a42e0bea0 100644
--- a/source/Commands/CommandObjectSource.cpp
+++ b/source/Commands/CommandObjectSource.cpp
@@ -28,6 +28,7 @@
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/TargetList.h"
#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Interpreter/Options.h"
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index 8e7e68aad39a..308b72f355d3 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -19,7 +19,7 @@
// Project includes
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/Debugger.h"
-#include "lldb/Core/InputReader.h"
+#include "lldb/Core/IOHandler.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/Section.h"
@@ -49,6 +49,7 @@
#include "lldb/Symbol/UnwindPlan.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadSpec.h"
@@ -2893,7 +2894,8 @@ protected:
if (m_slide_option.GetOptionValue().OptionWasSet())
{
const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
- module->SetLoadAddress (*target, slide, changed);
+ const bool slide_is_offset = true;
+ module->SetLoadAddress (*target, slide, slide_is_offset, changed);
}
else
{
@@ -4758,7 +4760,9 @@ private:
// CommandObjectTargetStopHookAdd
//-------------------------------------------------------------------------
-class CommandObjectTargetStopHookAdd : public CommandObjectParsed
+class CommandObjectTargetStopHookAdd :
+ public CommandObjectParsed,
+ public IOHandlerDelegateMultiline
{
public:
@@ -4925,9 +4929,10 @@ public:
CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) :
CommandObjectParsed (interpreter,
- "target stop-hook add ",
+ "target stop-hook add",
"Add a hook to be executed when the target stops.",
"target stop-hook add"),
+ IOHandlerDelegateMultiline ("DONE", IOHandlerDelegate::Completion::LLDBCommand),
m_options (interpreter)
{
}
@@ -4936,102 +4941,61 @@ public:
{
}
- static size_t
- ReadCommandsCallbackFunction (void *baton,
- InputReader &reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len)
+protected:
+
+ virtual void
+ IOHandlerActivated (IOHandler &io_handler)
{
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- Target::StopHook *new_stop_hook = ((Target::StopHook *) baton);
- static bool got_interrupted;
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
-
- switch (notification)
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp)
{
- case eInputReaderActivate:
- if (!batch_mode)
- {
- out_stream->Printf ("%s\n", "Enter your stop hook command(s). Type 'DONE' to end.");
- if (reader.GetPrompt())
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush();
- }
- got_interrupted = false;
- break;
-
- case eInputReaderDeactivate:
- break;
-
- case eInputReaderReactivate:
- if (reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush();
- }
- got_interrupted = false;
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
-
- case eInputReaderGotToken:
- if (bytes && bytes_len && baton)
+ output_sp->PutCString("Enter your stop hook command(s). Type 'DONE' to end.\n");
+ output_sp->Flush();
+ }
+ }
+
+
+ virtual void
+ IOHandlerInputComplete (IOHandler &io_handler, std::string &line)
+ {
+ if (m_stop_hook_sp)
+ {
+ if (line.empty())
{
- StringList *commands = new_stop_hook->GetCommandPointer();
- if (commands)
+ StreamFileSP error_sp(io_handler.GetErrorStreamFile());
+ if (error_sp)
{
- commands->AppendString (bytes, bytes_len);
+ error_sp->Printf("error: stop hook #%" PRIu64 " aborted, no commands.\n", m_stop_hook_sp->GetID());
+ error_sp->Flush();
}
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target)
+ target->RemoveStopHookByID(m_stop_hook_sp->GetID());
}
- if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush();
- }
- break;
-
- case eInputReaderInterrupt:
+ else
{
- // Finish, and cancel the stop hook.
- new_stop_hook->GetTarget()->RemoveStopHookByID(new_stop_hook->GetID());
- if (!batch_mode)
+ m_stop_hook_sp->GetCommandPointer()->SplitIntoLines(line);
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp)
{
- out_stream->Printf ("Stop hook cancelled.\n");
- out_stream->Flush();
+ output_sp->Printf("Stop hook #%" PRIu64 " added.\n", m_stop_hook_sp->GetID());
+ output_sp->Flush();
}
-
- reader.SetIsDone (true);
}
- got_interrupted = true;
- break;
-
- case eInputReaderEndOfFile:
- reader.SetIsDone (true);
- break;
-
- case eInputReaderDone:
- if (!got_interrupted && !batch_mode)
- {
- out_stream->Printf ("Stop hook #%" PRIu64 " added.\n", new_stop_hook->GetID());
- out_stream->Flush();
- }
- break;
+ m_stop_hook_sp.reset();
}
-
- return bytes_len;
+ io_handler.SetIsDone(true);
}
-
-protected:
+
bool
DoExecute (Args& command, CommandReturnObject &result)
{
+ m_stop_hook_sp.reset();
+
Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
if (target)
{
- Target::StopHookSP new_hook_sp;
- target->AddStopHook (new_hook_sp);
+ Target::StopHookSP new_hook_sp = target->CreateStopHook();
// First step, make the specifier.
std::unique_ptr<SymbolContextSpecifier> specifier_ap;
@@ -5104,31 +5068,12 @@ protected:
}
else
{
- // Otherwise gather up the command list, we'll push an input reader and suck the data from that directly into
- // the new stop hook's command string.
- InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
- if (!reader_sp)
- {
- result.AppendError("out of memory\n");
- result.SetStatus (eReturnStatusFailed);
- target->RemoveStopHookByID (new_hook_sp->GetID());
- return false;
- }
-
- Error err (reader_sp->Initialize (CommandObjectTargetStopHookAdd::ReadCommandsCallbackFunction,
- new_hook_sp.get(), // baton
- eInputReaderGranularityLine, // token size, to pass to callback function
- "DONE", // end token
- "> ", // prompt
- true)); // echo input
- if (!err.Success())
- {
- result.AppendError (err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- target->RemoveStopHookByID (new_hook_sp->GetID());
- return false;
- }
- m_interpreter.GetDebugger().PushInputReader (reader_sp);
+ m_stop_hook_sp = new_hook_sp;
+ m_interpreter.GetLLDBCommandsFromIOHandler ("> ", // Prompt
+ *this, // IOHandlerDelegate
+ true, // Run IOHandler in async mode
+ NULL); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
+
}
result.SetStatus (eReturnStatusSuccessFinishNoResult);
}
@@ -5142,6 +5087,7 @@ protected:
}
private:
CommandOptions m_options;
+ Target::StopHookSP m_stop_hook_sp;
};
OptionDefinition
diff --git a/source/Commands/CommandObjectType.cpp b/source/Commands/CommandObjectType.cpp
index 1c695b37c566..f1b1d2c1900c 100644
--- a/source/Commands/CommandObjectType.cpp
+++ b/source/Commands/CommandObjectType.cpp
@@ -19,7 +19,7 @@
#include "lldb/Core/ConstString.h"
#include "lldb/Core/Debugger.h"
-#include "lldb/Core/InputReaderEZ.h"
+#include "lldb/Core/IOHandler.h"
#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/State.h"
#include "lldb/Core/StringList.h"
@@ -42,7 +42,6 @@ public:
TypeSummaryImpl::Flags m_flags;
StringList m_target_types;
- StringList m_user_source;
bool m_regex;
@@ -74,7 +73,6 @@ public:
bool m_skip_references;
bool m_cascade;
bool m_regex;
- StringList m_user_source;
StringList m_target_types;
std::string m_category;
@@ -88,7 +86,6 @@ public:
m_skip_references(sref),
m_cascade(casc),
m_regex(regx),
- m_user_source(),
m_target_types(),
m_category(catg)
{
@@ -98,9 +95,36 @@ public:
};
+static bool
+WarnOnPotentialUnquotedUnsignedType (Args& command, CommandReturnObject &result)
+{
+ for (int idx = 0; idx < command.GetArgumentCount(); idx++)
+ {
+ const char* arg = command.GetArgumentAtIndex(idx);
+ if (idx+1 < command.GetArgumentCount())
+ {
+ if (arg && 0 == strcmp(arg,"unsigned"))
+ {
+ const char* next = command.GetArgumentAtIndex(idx+1);
+ if (next &&
+ (0 == strcmp(next, "int") ||
+ 0 == strcmp(next, "short") ||
+ 0 == strcmp(next, "char") ||
+ 0 == strcmp(next, "long")))
+ {
+ result.AppendWarningWithFormat("%s %s being treated as two types. if you meant the combined type name use quotes, as in \"%s %s\"\n",
+ arg,next,arg,next);
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
-
-class CommandObjectTypeSummaryAdd : public CommandObjectParsed
+class CommandObjectTypeSummaryAdd :
+ public CommandObjectParsed,
+ public IOHandlerDelegateMultiline
{
private:
@@ -153,10 +177,6 @@ private:
return &m_options;
}
- void
- CollectPythonScript(ScriptAddOptions *options,
- CommandReturnObject &result);
-
bool
Execute_ScriptSummary (Args& command, CommandReturnObject &result);
@@ -178,6 +198,147 @@ public:
{
}
+ virtual void
+ IOHandlerActivated (IOHandler &io_handler)
+ {
+ static const char *g_summary_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
+ "def function (valobj,internal_dict):\n"
+ " \"\"\"valobj: an SBValue which you want to provide a summary for\n"
+ " internal_dict: an LLDB support object not to be used\"\"\"";
+
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp)
+ {
+ output_sp->PutCString(g_summary_addreader_instructions);
+ output_sp->Flush();
+ }
+ }
+
+
+ virtual void
+ IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
+ {
+ StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+
+#ifndef LLDB_DISABLE_PYTHON
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ if (interpreter)
+ {
+ StringList lines;
+ lines.SplitIntoLines(data);
+ if (lines.GetSize() > 0)
+ {
+ ScriptAddOptions *options_ptr = ((ScriptAddOptions*)io_handler.GetUserData());
+ if (options_ptr)
+ {
+ ScriptAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
+
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ if (interpreter)
+ {
+ std::string funct_name_str;
+ if (interpreter->GenerateTypeScriptFunction (lines, funct_name_str))
+ {
+ if (funct_name_str.empty())
+ {
+ error_sp->Printf ("unable to obtain a valid function name from the script interpreter.\n");
+ error_sp->Flush();
+ }
+ else
+ {
+ // now I have a valid function name, let's add this as script for every type in the list
+
+ TypeSummaryImplSP script_format;
+ script_format.reset(new ScriptSummaryFormat(options->m_flags,
+ funct_name_str.c_str(),
+ lines.CopyList(" ").c_str()));
+
+ Error error;
+
+ for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
+ {
+ const char *type_name = options->m_target_types.GetStringAtIndex(i);
+ CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
+ script_format,
+ (options->m_regex ? CommandObjectTypeSummaryAdd::eRegexSummary : CommandObjectTypeSummaryAdd::eRegularSummary),
+ options->m_category,
+ &error);
+ if (error.Fail())
+ {
+ error_sp->Printf ("error: %s", error.AsCString());
+ error_sp->Flush();
+ }
+ }
+
+ if (options->m_name)
+ {
+ CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
+ script_format,
+ CommandObjectTypeSummaryAdd::eNamedSummary,
+ options->m_category,
+ &error);
+ if (error.Fail())
+ {
+ CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
+ script_format,
+ CommandObjectTypeSummaryAdd::eNamedSummary,
+ options->m_category,
+ &error);
+ if (error.Fail())
+ {
+ error_sp->Printf ("error: %s", error.AsCString());
+ error_sp->Flush();
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: %s", error.AsCString());
+ error_sp->Flush();
+ }
+ }
+ else
+ {
+ if (error.AsCString())
+ {
+ error_sp->Printf ("error: %s", error.AsCString());
+ error_sp->Flush();
+ }
+ }
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: unable to generate a function.\n");
+ error_sp->Flush();
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: no script interpreter.\n");
+ error_sp->Flush();
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: internal synchronization information missing or invalid.\n");
+ error_sp->Flush();
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: empty function, didn't add python command.\n");
+ error_sp->Flush();
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
+ error_sp->Flush();
+ }
+#endif // #ifndef LLDB_DISABLE_PYTHON
+ io_handler.SetIsDone(true);
+ }
+
static bool
AddSummary(ConstString type_name,
lldb::TypeSummaryImplSP entry,
@@ -190,7 +351,19 @@ protected:
};
-class CommandObjectTypeSynthAdd : public CommandObjectParsed
+static const char *g_synth_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
+"You must define a Python class with these methods:\n"
+" def __init__(self, valobj, dict):\n"
+" def num_children(self):\n"
+" def get_child_at_index(self, index):\n"
+" def get_child_index(self, name):\n"
+" def update(self):\n"
+" '''Optional'''\n"
+"class synthProvider:\n";
+
+class CommandObjectTypeSynthAdd :
+ public CommandObjectParsed,
+ public IOHandlerDelegateMultiline
{
private:
@@ -200,7 +373,7 @@ private:
public:
CommandOptions (CommandInterpreter &interpreter) :
- Options (interpreter)
+ Options (interpreter)
{
}
@@ -296,9 +469,6 @@ private:
return &m_options;
}
- void
- CollectPythonScript (SynthAddOptions *options,
- CommandReturnObject &result);
bool
Execute_HandwritePython (Args& command, CommandReturnObject &result);
@@ -307,8 +477,139 @@ private:
protected:
bool
- DoExecute (Args& command, CommandReturnObject &result);
+ DoExecute (Args& command, CommandReturnObject &result)
+ {
+ WarnOnPotentialUnquotedUnsignedType(command, result);
+
+ if (m_options.handwrite_python)
+ return Execute_HandwritePython(command, result);
+ else if (m_options.is_class_based)
+ return Execute_PythonClass(command, result);
+ else
+ {
+ result.AppendError("must either provide a children list, a Python class name, or use -P and type a Python class line-by-line");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ virtual void
+ IOHandlerActivated (IOHandler &io_handler)
+ {
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp)
+ {
+ output_sp->PutCString(g_synth_addreader_instructions);
+ output_sp->Flush();
+ }
+ }
+
+ virtual void
+ IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
+ {
+ StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+
+#ifndef LLDB_DISABLE_PYTHON
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ if (interpreter)
+ {
+ StringList lines;
+ lines.SplitIntoLines(data);
+ if (lines.GetSize() > 0)
+ {
+ SynthAddOptions *options_ptr = ((SynthAddOptions*)io_handler.GetUserData());
+ if (options_ptr)
+ {
+ SynthAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
+
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ if (interpreter)
+ {
+ std::string class_name_str;
+ if (interpreter->GenerateTypeSynthClass (lines, class_name_str))
+ {
+ if (class_name_str.empty())
+ {
+ error_sp->Printf ("error: unable to obtain a proper name for the class.\n");
+ error_sp->Flush();
+ }
+ else
+ {
+ // everything should be fine now, let's add the synth provider class
+
+ SyntheticChildrenSP synth_provider;
+ synth_provider.reset(new ScriptedSyntheticChildren(SyntheticChildren::Flags().SetCascades(options->m_cascade).
+ SetSkipPointers(options->m_skip_pointers).
+ SetSkipReferences(options->m_skip_references),
+ class_name_str.c_str()));
+
+
+ lldb::TypeCategoryImplSP category;
+ DataVisualization::Categories::GetCategory(ConstString(options->m_category.c_str()), category);
+
+ Error error;
+
+ for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
+ {
+ const char *type_name = options->m_target_types.GetStringAtIndex(i);
+ ConstString const_type_name(type_name);
+ if (const_type_name)
+ {
+ if (!CommandObjectTypeSynthAdd::AddSynth(const_type_name,
+ synth_provider,
+ options->m_regex ? CommandObjectTypeSynthAdd::eRegexSynth : CommandObjectTypeSynthAdd::eRegularSynth,
+ options->m_category,
+ &error))
+ {
+ error_sp->Printf("error: %s\n", error.AsCString());
+ error_sp->Flush();
+ break;
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: invalid type name.\n");
+ error_sp->Flush();
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: unable to generate a class.\n");
+ error_sp->Flush();
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: no script interpreter.\n");
+ error_sp->Flush();
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: internal synchronization data missing.\n");
+ error_sp->Flush();
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: empty function, didn't add python command.\n");
+ error_sp->Flush();
+ }
+ }
+ else
+ {
+ error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
+ error_sp->Flush();
+ }
+
+#endif // #ifndef LLDB_DISABLE_PYTHON
+ io_handler.SetIsDone(true);
+ }
+
public:
enum SynthFormatType
@@ -371,6 +672,7 @@ private:
m_skip_references = false;
m_regex = false;
m_category.assign("default");
+ m_custom_type_name.clear();
}
virtual Error
SetOptionValue (CommandInterpreter &interpreter,
@@ -400,6 +702,9 @@ private:
case 'x':
m_regex = true;
break;
+ case 't':
+ m_custom_type_name.assign(option_value);
+ break;
default:
error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
break;
@@ -419,6 +724,7 @@ private:
bool m_skip_pointers;
bool m_regex;
std::string m_category;
+ std::string m_custom_type_name;
};
OptionGroupOptions m_option_group;
@@ -480,7 +786,7 @@ public:
);
// Add the "--format" to all options groups
- m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT, LLDB_OPT_SET_ALL);
+ m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT, LLDB_OPT_SET_1);
m_option_group.Append (&m_command_options);
m_option_group.Finalize();
@@ -504,7 +810,7 @@ protected:
}
const Format format = m_format_options.GetFormat();
- if (format == eFormatInvalid)
+ if (format == eFormatInvalid && m_command_options.m_custom_type_name.empty())
{
result.AppendErrorWithFormat ("%s needs a valid format.\n", m_cmd_name.c_str());
result.SetStatus(eReturnStatusFailed);
@@ -513,10 +819,16 @@ protected:
TypeFormatImplSP entry;
- entry.reset(new TypeFormatImpl(format,
- TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
- SetSkipPointers(m_command_options.m_skip_pointers).
- SetSkipReferences(m_command_options.m_skip_references)));
+ if (m_command_options.m_custom_type_name.empty())
+ entry.reset(new TypeFormatImpl_Format(format,
+ TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
+ SetSkipPointers(m_command_options.m_skip_pointers).
+ SetSkipReferences(m_command_options.m_skip_references)));
+ else
+ entry.reset(new TypeFormatImpl_EnumType(ConstString(m_command_options.m_custom_type_name.c_str()),
+ TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
+ SetSkipPointers(m_command_options.m_skip_pointers).
+ SetSkipReferences(m_command_options.m_skip_references)));
// now I have a valid format, let's add it to every type
@@ -525,6 +837,8 @@ protected:
if (!category_sp)
return false;
+ WarnOnPotentialUnquotedUnsignedType(command, result);
+
for (size_t i = 0; i < argc; i++)
{
const char* typeA = command.GetArgumentAtIndex(i);
@@ -540,11 +854,11 @@ protected:
result.SetStatus(eReturnStatusFailed);
return false;
}
- category_sp->GetRegexSummaryNavigator()->Delete(typeCS);
- category_sp->GetRegexValueNavigator()->Add(typeRX, entry);
+ category_sp->GetRegexTypeSummariesContainer()->Delete(typeCS);
+ category_sp->GetRegexTypeFormatsContainer()->Add(typeRX, entry);
}
else
- category_sp->GetValueNavigator()->Add(typeCS, entry);
+ category_sp->GetTypeFormatsContainer()->Add(typeCS, entry);
}
else
{
@@ -562,11 +876,12 @@ protected:
OptionDefinition
CommandObjectTypeFormatAdd::CommandOptions::g_option_table[] =
{
- { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
- { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
- { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
- { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
+ { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
+ { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
+ { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
+ { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
{ LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
+ { LLDB_OPT_SET_2, false, "type", 't', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Format variables as if they were of this type."},
{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
};
@@ -817,8 +1132,8 @@ private:
PerCategoryCallback(void* param,
const lldb::TypeCategoryImplSP& cate)
{
- cate->GetValueNavigator()->Clear();
- cate->GetRegexValueNavigator()->Clear();
+ cate->GetTypeFormatsContainer()->Clear();
+ cate->GetRegexTypeFormatsContainer()->Clear();
return true;
}
@@ -996,6 +1311,7 @@ protected:
param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result,NULL,cate_regex);
DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
+ delete param;
if (cate_regex)
delete cate_regex;
@@ -1029,12 +1345,12 @@ private:
cate_name,
(cate->IsEnabled() ? "enabled" : "disabled"));
- cate->GetValueNavigator()->LoopThrough(CommandObjectTypeFormatList_LoopCallback, param_vp);
+ cate->GetTypeFormatsContainer()->LoopThrough(CommandObjectTypeFormatList_LoopCallback, param_vp);
- if (cate->GetRegexSummaryNavigator()->GetCount() > 0)
+ if (cate->GetRegexTypeSummariesContainer()->GetCount() > 0)
{
result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
- cate->GetRegexValueNavigator()->LoopThrough(CommandObjectTypeRXFormatList_LoopCallback, param_vp);
+ cate->GetRegexTypeFormatsContainer()->LoopThrough(CommandObjectTypeRXFormatList_LoopCallback, param_vp);
}
return true;
}
@@ -1089,176 +1405,6 @@ CommandObjectTypeFormatList::CommandOptions::g_option_table[] =
// CommandObjectTypeSummaryAdd
//-------------------------------------------------------------------------
-static const char *g_summary_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
- "def function (valobj,internal_dict):\n"
- " \"\"\"valobj: an SBValue which you want to provide a summary for\n"
- " internal_dict: an LLDB support object not to be used\"\"\"";
-
-class TypeScriptAddInputReader : public InputReaderEZ
-{
-private:
- DISALLOW_COPY_AND_ASSIGN (TypeScriptAddInputReader);
-public:
- TypeScriptAddInputReader(Debugger& debugger) :
- InputReaderEZ(debugger)
- {}
-
- virtual
- ~TypeScriptAddInputReader()
- {
- }
-
- virtual void ActivateHandler(HandlerData& data)
- {
- StreamSP out_stream = data.reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = data.reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
- if (!batch_mode)
- {
- out_stream->Printf ("%s\n", g_summary_addreader_instructions);
- if (data.reader.GetPrompt())
- out_stream->Printf ("%s", data.reader.GetPrompt());
- out_stream->Flush();
- }
- }
-
- virtual void ReactivateHandler(HandlerData& data)
- {
- StreamSP out_stream = data.reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = data.reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
- if (data.reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", data.reader.GetPrompt());
- out_stream->Flush();
- }
- }
- virtual void GotTokenHandler(HandlerData& data)
- {
- StreamSP out_stream = data.reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = data.reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
- if (data.bytes && data.bytes_len && data.baton)
- {
- ((ScriptAddOptions*)data.baton)->m_user_source.AppendString(data.bytes, data.bytes_len);
- }
- if (!data.reader.IsDone() && data.reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", data.reader.GetPrompt());
- out_stream->Flush();
- }
- }
- virtual void InterruptHandler(HandlerData& data)
- {
- StreamSP out_stream = data.reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = data.reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
- data.reader.SetIsDone (true);
- if (!batch_mode)
- {
- out_stream->Printf ("Warning: No command attached to breakpoint.\n");
- out_stream->Flush();
- }
- }
- virtual void EOFHandler(HandlerData& data)
- {
- data.reader.SetIsDone (true);
- }
- virtual void DoneHandler(HandlerData& data)
- {
- StreamSP out_stream = data.reader.GetDebugger().GetAsyncOutputStream();
- ScriptAddOptions *options_ptr = ((ScriptAddOptions*)data.baton);
- if (!options_ptr)
- {
- out_stream->Printf ("internal synchronization information missing or invalid.\n");
- out_stream->Flush();
- return;
- }
-
- ScriptAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
-
- ScriptInterpreter *interpreter = data.reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
- if (!interpreter)
- {
- out_stream->Printf ("no script interpreter.\n");
- out_stream->Flush();
- return;
- }
- std::string funct_name_str;
- if (!interpreter->GenerateTypeScriptFunction (options->m_user_source,
- funct_name_str))
- {
- out_stream->Printf ("unable to generate a function.\n");
- out_stream->Flush();
- return;
- }
- if (funct_name_str.empty())
- {
- out_stream->Printf ("unable to obtain a valid function name from the script interpreter.\n");
- out_stream->Flush();
- return;
- }
- // now I have a valid function name, let's add this as script for every type in the list
-
- TypeSummaryImplSP script_format;
- script_format.reset(new ScriptSummaryFormat(options->m_flags,
- funct_name_str.c_str(),
- options->m_user_source.CopyList(" ").c_str()));
-
- Error error;
-
- for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
- {
- const char *type_name = options->m_target_types.GetStringAtIndex(i);
- CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
- script_format,
- (options->m_regex ? CommandObjectTypeSummaryAdd::eRegexSummary : CommandObjectTypeSummaryAdd::eRegularSummary),
- options->m_category,
- &error);
- if (error.Fail())
- {
- out_stream->Printf ("%s", error.AsCString());
- out_stream->Flush();
- return;
- }
- }
-
- if (options->m_name)
- {
- CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
- script_format,
- CommandObjectTypeSummaryAdd::eNamedSummary,
- options->m_category,
- &error);
- if (error.Fail())
- {
- CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
- script_format,
- CommandObjectTypeSummaryAdd::eNamedSummary,
- options->m_category,
- &error);
- if (error.Fail())
- {
- out_stream->Printf ("%s", error.AsCString());
- out_stream->Flush();
- return;
- }
- }
- else
- {
- out_stream->Printf ("%s", error.AsCString());
- out_stream->Flush();
- return;
- }
- }
- else
- {
- if (error.AsCString())
- {
- out_stream->PutCString (error.AsCString());
- out_stream->Flush();
- }
- return;
- }
- }
-};
-
#endif // #ifndef LLDB_DISABLE_PYTHON
Error
@@ -1339,35 +1485,9 @@ CommandObjectTypeSummaryAdd::CommandOptions::OptionParsingStarting ()
m_category = "default";
}
+
+
#ifndef LLDB_DISABLE_PYTHON
-void
-CommandObjectTypeSummaryAdd::CollectPythonScript (ScriptAddOptions *options,
- CommandReturnObject &result)
-{
- InputReaderSP reader_sp (new TypeScriptAddInputReader(m_interpreter.GetDebugger()));
- if (reader_sp && options)
- {
-
- InputReaderEZ::InitializationParameters ipr;
-
- Error err (reader_sp->Initialize (ipr.SetBaton(options).SetPrompt(" ")));
- if (err.Success())
- {
- m_interpreter.GetDebugger().PushInputReader (reader_sp);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError (err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendError("out of memory");
- result.SetStatus (eReturnStatusFailed);
- }
-}
bool
CommandObjectTypeSummaryAdd::Execute_ScriptSummary (Args& command, CommandReturnObject &result)
@@ -1393,7 +1513,7 @@ CommandObjectTypeSummaryAdd::Execute_ScriptSummary (Args& command, CommandReturn
return false;
}
- std::string code = (" " + m_options.m_python_function + "(valobj,internal_dict)");
+ std::string code = (" " + m_options.m_python_function + "(valobj,internal_dict)");
script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
funct_name,
@@ -1432,14 +1552,15 @@ CommandObjectTypeSummaryAdd::Execute_ScriptSummary (Args& command, CommandReturn
return false;
}
- std::string code = " " + m_options.m_python_script;
+ std::string code = " " + m_options.m_python_script;
script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
funct_name_str.c_str(),
code.c_str()));
}
- else // use an InputReader to grab Python code from the user
- {
+ else
+ {
+ // Use an IOHandler to grab Python code from the user
ScriptAddOptions *options = new ScriptAddOptions(m_options.m_flags,
m_options.m_regex,
m_options.m_name,
@@ -1458,7 +1579,12 @@ CommandObjectTypeSummaryAdd::Execute_ScriptSummary (Args& command, CommandReturn
}
}
- CollectPythonScript(options,result);
+ m_interpreter.GetPythonCommandsFromIOHandler (" ", // Prompt
+ *this, // IOHandlerDelegate
+ true, // Run IOHandler in async mode
+ options); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+
return result.Succeeded();
}
@@ -1590,6 +1716,7 @@ CommandObjectTypeSummaryAdd::CommandObjectTypeSummaryAdd (CommandInterpreter &in
"type summary add",
"Add a new summary style for a type.",
NULL),
+ IOHandlerDelegateMultiline ("DONE"),
m_options (interpreter)
{
CommandArgumentEntry type_arg;
@@ -1671,6 +1798,8 @@ CommandObjectTypeSummaryAdd::CommandObjectTypeSummaryAdd (CommandInterpreter &in
bool
CommandObjectTypeSummaryAdd::DoExecute (Args& command, CommandReturnObject &result)
{
+ WarnOnPotentialUnquotedUnsignedType(command, result);
+
if (m_options.m_is_add_script)
{
#ifndef LLDB_DISABLE_PYTHON
@@ -1720,8 +1849,8 @@ CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name,
return false;
}
- category->GetRegexSummaryNavigator()->Delete(type_name);
- category->GetRegexSummaryNavigator()->Add(typeRX, entry);
+ category->GetRegexTypeSummariesContainer()->Delete(type_name);
+ category->GetRegexTypeSummariesContainer()->Add(typeRX, entry);
return true;
}
@@ -1733,7 +1862,7 @@ CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name,
}
else
{
- category->GetSummaryNavigator()->Add(type_name, entry);
+ category->GetTypeSummariesContainer()->Add(type_name, entry);
return true;
}
}
@@ -1994,8 +2123,8 @@ private:
PerCategoryCallback(void* param,
const lldb::TypeCategoryImplSP& cate)
{
- cate->GetSummaryNavigator()->Clear();
- cate->GetRegexSummaryNavigator()->Clear();
+ cate->GetTypeSummariesContainer()->Clear();
+ cate->GetRegexTypeSummariesContainer()->Clear();
return true;
}
@@ -2178,7 +2307,8 @@ protected:
param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,NULL,cate_regex);
DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
-
+ delete param;
+
if (DataVisualization::NamedSummaryFormats::GetCount() > 0)
{
result.GetOutputStream().Printf("Named summaries:\n");
@@ -2226,12 +2356,12 @@ private:
cate_name,
(cate->IsEnabled() ? "enabled" : "disabled"));
- cate->GetSummaryNavigator()->LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param_vp);
+ cate->GetTypeSummariesContainer()->LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param_vp);
- if (cate->GetRegexSummaryNavigator()->GetCount() > 0)
+ if (cate->GetRegexTypeSummariesContainer()->GetCount() > 0)
{
result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
- cate->GetRegexSummaryNavigator()->LoopThrough(CommandObjectTypeRXSummaryList_LoopCallback, param_vp);
+ cate->GetRegexTypeSummariesContainer()->LoopThrough(CommandObjectTypeRXSummaryList_LoopCallback, param_vp);
}
return true;
}
@@ -2741,6 +2871,7 @@ protected:
param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,NULL,cate_regex);
DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
+ delete param;
if (cate_regex)
delete cate_regex;
@@ -2774,12 +2905,12 @@ private:
cate_name,
(cate->IsEnabled() ? "enabled" : "disabled"));
- cate->GetFilterNavigator()->LoopThrough(CommandObjectTypeFilterList_LoopCallback, param_vp);
+ cate->GetTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterList_LoopCallback, param_vp);
- if (cate->GetRegexFilterNavigator()->GetCount() > 0)
+ if (cate->GetRegexTypeFiltersContainer()->GetCount() > 0)
{
result->GetOutputStream().Printf("Regex-based filters (slower):\n");
- cate->GetRegexFilterNavigator()->LoopThrough(CommandObjectTypeFilterRXList_LoopCallback, param_vp);
+ cate->GetRegexTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterRXList_LoopCallback, param_vp);
}
return true;
@@ -2955,7 +3086,8 @@ protected:
param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,NULL,cate_regex);
DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
-
+ delete param;
+
if (cate_regex)
delete cate_regex;
@@ -2988,12 +3120,12 @@ private:
cate_name,
(cate->IsEnabled() ? "enabled" : "disabled"));
- cate->GetSyntheticNavigator()->LoopThrough(CommandObjectTypeSynthList_LoopCallback, param_vp);
+ cate->GetTypeSyntheticsContainer()->LoopThrough(CommandObjectTypeSynthList_LoopCallback, param_vp);
- if (cate->GetRegexSyntheticNavigator()->GetCount() > 0)
+ if (cate->GetRegexTypeSyntheticsContainer()->GetCount() > 0)
{
result->GetOutputStream().Printf("Regex-based synthetic providers (slower):\n");
- cate->GetRegexSyntheticNavigator()->LoopThrough(CommandObjectTypeSynthRXList_LoopCallback, param_vp);
+ cate->GetRegexTypeSyntheticsContainer()->LoopThrough(CommandObjectTypeSynthRXList_LoopCallback, param_vp);
}
return true;
@@ -3179,8 +3311,8 @@ protected:
lldb::TypeCategoryImplSP category;
DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
- bool delete_category = category->GetFilterNavigator()->Delete(typeCS);
- delete_category = category->GetRegexFilterNavigator()->Delete(typeCS) || delete_category;
+ bool delete_category = category->GetTypeFiltersContainer()->Delete(typeCS);
+ delete_category = category->GetRegexTypeFiltersContainer()->Delete(typeCS) || delete_category;
if (delete_category)
{
@@ -3345,8 +3477,8 @@ protected:
lldb::TypeCategoryImplSP category;
DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
- bool delete_category = category->GetSyntheticNavigator()->Delete(typeCS);
- delete_category = category->GetRegexSyntheticNavigator()->Delete(typeCS) || delete_category;
+ bool delete_category = category->GetTypeSyntheticsContainer()->Delete(typeCS);
+ delete_category = category->GetRegexTypeSyntheticsContainer()->Delete(typeCS) || delete_category;
if (delete_category)
{
@@ -3484,8 +3616,8 @@ protected:
}
else
DataVisualization::Categories::GetCategory(ConstString(NULL), category);
- category->GetFilterNavigator()->Clear();
- category->GetRegexFilterNavigator()->Clear();
+ category->GetTypeFiltersContainer()->Clear();
+ category->GetRegexTypeFiltersContainer()->Clear();
}
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -3613,8 +3745,8 @@ protected:
}
else
DataVisualization::Categories::GetCategory(ConstString(NULL), category);
- category->GetSyntheticNavigator()->Clear();
- category->GetRegexSyntheticNavigator()->Clear();
+ category->GetTypeSyntheticsContainer()->Clear();
+ category->GetRegexTypeSyntheticsContainer()->Clear();
}
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -3631,193 +3763,6 @@ CommandObjectTypeSynthClear::CommandOptions::g_option_table[] =
};
-//-------------------------------------------------------------------------
-// TypeSynthAddInputReader
-//-------------------------------------------------------------------------
-
-static const char *g_synth_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
- "You must define a Python class with these methods:\n"
- " def __init__(self, valobj, dict):\n"
- " def num_children(self):\n"
- " def get_child_at_index(self, index):\n"
- " def get_child_index(self, name):\n"
- "Optionally, you can also define a method:\n"
- " def update(self):\n"
- "if your synthetic provider is holding on to any per-object state variables (currently, this is not implemented because of the way LLDB handles instances of SBValue and you should not rely on object persistence and per-object state)\n"
- "class synthProvider:";
-
-class TypeSynthAddInputReader : public InputReaderEZ
-{
-public:
- TypeSynthAddInputReader(Debugger& debugger) :
- InputReaderEZ(debugger)
- {}
-
- virtual
- ~TypeSynthAddInputReader()
- {
- }
-
- virtual void ActivateHandler(HandlerData& data)
- {
- StreamSP out_stream = data.GetOutStream();
- bool batch_mode = data.GetBatchMode();
- if (!batch_mode)
- {
- out_stream->Printf ("%s\n", g_synth_addreader_instructions);
- if (data.reader.GetPrompt())
- out_stream->Printf ("%s", data.reader.GetPrompt());
- out_stream->Flush();
- }
- }
-
- virtual void ReactivateHandler(HandlerData& data)
- {
- StreamSP out_stream = data.GetOutStream();
- bool batch_mode = data.GetBatchMode();
- if (data.reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", data.reader.GetPrompt());
- out_stream->Flush();
- }
- }
- virtual void GotTokenHandler(HandlerData& data)
- {
- StreamSP out_stream = data.GetOutStream();
- bool batch_mode = data.GetBatchMode();
- if (data.bytes && data.bytes_len && data.baton)
- {
- ((SynthAddOptions*)data.baton)->m_user_source.AppendString(data.bytes, data.bytes_len);
- }
- if (!data.reader.IsDone() && data.reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", data.reader.GetPrompt());
- out_stream->Flush();
- }
- }
- virtual void InterruptHandler(HandlerData& data)
- {
- StreamSP out_stream = data.GetOutStream();
- bool batch_mode = data.GetBatchMode();
- data.reader.SetIsDone (true);
- if (!batch_mode)
- {
- out_stream->Printf ("Warning: No command attached to breakpoint.\n");
- out_stream->Flush();
- }
- }
- virtual void EOFHandler(HandlerData& data)
- {
- data.reader.SetIsDone (true);
- }
- virtual void DoneHandler(HandlerData& data)
- {
- StreamSP out_stream = data.GetOutStream();
- SynthAddOptions *options_ptr = ((SynthAddOptions*)data.baton);
- if (!options_ptr)
- {
- out_stream->Printf ("internal synchronization data missing.\n");
- out_stream->Flush();
- return;
- }
-
- SynthAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
-
- ScriptInterpreter *interpreter = data.reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
- if (!interpreter)
- {
- out_stream->Printf ("no script interpreter.\n");
- out_stream->Flush();
- return;
- }
- std::string class_name_str;
- if (!interpreter->GenerateTypeSynthClass (options->m_user_source,
- class_name_str))
- {
- out_stream->Printf ("unable to generate a class.\n");
- out_stream->Flush();
- return;
- }
- if (class_name_str.empty())
- {
- out_stream->Printf ("unable to obtain a proper name for the class.\n");
- out_stream->Flush();
- return;
- }
-
- // everything should be fine now, let's add the synth provider class
-
- SyntheticChildrenSP synth_provider;
- synth_provider.reset(new ScriptedSyntheticChildren(SyntheticChildren::Flags().SetCascades(options->m_cascade).
- SetSkipPointers(options->m_skip_pointers).
- SetSkipReferences(options->m_skip_references),
- class_name_str.c_str()));
-
-
- lldb::TypeCategoryImplSP category;
- DataVisualization::Categories::GetCategory(ConstString(options->m_category.c_str()), category);
-
- Error error;
-
- for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
- {
- const char *type_name = options->m_target_types.GetStringAtIndex(i);
- ConstString typeCS(type_name);
- if (typeCS)
- {
- if (!CommandObjectTypeSynthAdd::AddSynth(typeCS,
- synth_provider,
- options->m_regex ? CommandObjectTypeSynthAdd::eRegexSynth : CommandObjectTypeSynthAdd::eRegularSynth,
- options->m_category,
- &error))
- {
- out_stream->Printf("%s\n", error.AsCString());
- out_stream->Flush();
- return;
- }
- }
- else
- {
- out_stream->Printf ("invalid type name.\n");
- out_stream->Flush();
- return;
- }
- }
- }
-
-private:
- DISALLOW_COPY_AND_ASSIGN (TypeSynthAddInputReader);
-};
-
-void
-CommandObjectTypeSynthAdd::CollectPythonScript (SynthAddOptions *options,
- CommandReturnObject &result)
-{
- InputReaderSP reader_sp (new TypeSynthAddInputReader(m_interpreter.GetDebugger()));
- if (reader_sp && options)
- {
-
- InputReaderEZ::InitializationParameters ipr;
-
- Error err (reader_sp->Initialize (ipr.SetBaton(options).SetPrompt(" ")));
- if (err.Success())
- {
- m_interpreter.GetDebugger().PushInputReader (reader_sp);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError (err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendError("out of memory");
- result.SetStatus (eReturnStatusFailed);
- }
-}
-
bool
CommandObjectTypeSynthAdd::Execute_HandwritePython (Args& command, CommandReturnObject &result)
{
@@ -3842,7 +3787,11 @@ CommandObjectTypeSynthAdd::Execute_HandwritePython (Args& command, CommandReturn
}
}
- CollectPythonScript(options,result);
+ m_interpreter.GetPythonCommandsFromIOHandler (" ", // Prompt
+ *this, // IOHandlerDelegate
+ true, // Run IOHandler in async mode
+ options); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
return result.Succeeded();
}
@@ -3921,6 +3870,7 @@ CommandObjectTypeSynthAdd::CommandObjectTypeSynthAdd (CommandInterpreter &interp
"type synthetic add",
"Add a new synthetic provider for a type.",
NULL),
+ IOHandlerDelegateMultiline ("DONE"),
m_options (interpreter)
{
CommandArgumentEntry type_arg;
@@ -3979,32 +3929,17 @@ CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
return false;
}
- category->GetRegexSyntheticNavigator()->Delete(type_name);
- category->GetRegexSyntheticNavigator()->Add(typeRX, entry);
+ category->GetRegexTypeSyntheticsContainer()->Delete(type_name);
+ category->GetRegexTypeSyntheticsContainer()->Add(typeRX, entry);
return true;
}
else
{
- category->GetSyntheticNavigator()->Add(type_name, entry);
+ category->GetTypeSyntheticsContainer()->Add(type_name, entry);
return true;
}
}
-
-bool
-CommandObjectTypeSynthAdd::DoExecute (Args& command, CommandReturnObject &result)
-{
- if (m_options.handwrite_python)
- return Execute_HandwritePython(command, result);
- else if (m_options.is_class_based)
- return Execute_PythonClass(command, result);
- else
- {
- result.AppendError("must either provide a children list, a Python class name, or use -P and type a Python class line-by-line");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-}
OptionDefinition
CommandObjectTypeSynthAdd::CommandOptions::g_option_table[] =
@@ -4173,14 +4108,14 @@ private:
return false;
}
- category->GetRegexFilterNavigator()->Delete(type_name);
- category->GetRegexFilterNavigator()->Add(typeRX, entry);
+ category->GetRegexTypeFiltersContainer()->Delete(type_name);
+ category->GetRegexTypeFiltersContainer()->Add(typeRX, entry);
return true;
}
else
{
- category->GetFilterNavigator()->Add(type_name, entry);
+ category->GetTypeFiltersContainer()->Add(type_name, entry);
return true;
}
}
@@ -4279,6 +4214,8 @@ protected:
Error error;
+ WarnOnPotentialUnquotedUnsignedType(command, result);
+
for (size_t i = 0; i < argc; i++)
{
const char* typeA = command.GetArgumentAtIndex(i);
diff --git a/source/Commands/CommandObjectWatchpointCommand.cpp b/source/Commands/CommandObjectWatchpointCommand.cpp
index e19216d74fce..0083ff140e5a 100644
--- a/source/Commands/CommandObjectWatchpointCommand.cpp
+++ b/source/Commands/CommandObjectWatchpointCommand.cpp
@@ -16,6 +16,7 @@
#include "CommandObjectWatchpointCommand.h"
#include "CommandObjectWatchpoint.h"
+#include "lldb/Core/IOHandler.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Target/Target.h"
@@ -34,7 +35,9 @@ using namespace lldb_private;
//-------------------------------------------------------------------------
-class CommandObjectWatchpointCommandAdd : public CommandObjectParsed
+class CommandObjectWatchpointCommandAdd :
+ public CommandObjectParsed,
+ public IOHandlerDelegateMultiline
{
public:
@@ -43,6 +46,7 @@ public:
"add",
"Add a set of commands to a watchpoint, to be executed whenever the watchpoint is hit.",
NULL),
+ IOHandlerDelegateMultiline("DONE", IOHandlerDelegate::Completion::LLDBCommand),
m_options (interpreter)
{
SetHelpLong (
@@ -185,40 +189,45 @@ but do NOT enter more than one command per line. \n" );
return &m_options;
}
- void
- CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
- CommandReturnObject &result)
+ virtual void
+ IOHandlerActivated (IOHandler &io_handler)
{
- InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
- std::unique_ptr<WatchpointOptions::CommandData> data_ap(new WatchpointOptions::CommandData());
- if (reader_sp && data_ap.get())
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp)
{
- BatonSP baton_sp (new WatchpointOptions::CommandBaton (data_ap.release()));
- wp_options->SetCallback (WatchpointOptionsCallbackFunction, baton_sp);
-
- Error err (reader_sp->Initialize (CommandObjectWatchpointCommandAdd::GenerateWatchpointCommandCallback,
- wp_options, // callback_data
- eInputReaderGranularityLine, // token size, to pass to callback function
- "DONE", // end token
- "> ", // prompt
- true)); // echo input
- if (err.Success())
- {
- m_interpreter.GetDebugger().PushInputReader (reader_sp);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError (err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
+ output_sp->PutCString("Enter your debugger command(s). Type 'DONE' to end.\n");
+ output_sp->Flush();
}
- else
+ }
+
+
+ virtual void
+ IOHandlerInputComplete (IOHandler &io_handler, std::string &line)
+ {
+ io_handler.SetIsDone(true);
+
+ // The WatchpointOptions object is owned by the watchpoint or watchpoint location
+ WatchpointOptions *wp_options = (WatchpointOptions *) io_handler.GetUserData();
+ if (wp_options)
{
- result.AppendError("out of memory");
- result.SetStatus (eReturnStatusFailed);
+ std::unique_ptr<WatchpointOptions::CommandData> data_ap(new WatchpointOptions::CommandData());
+ if (data_ap.get())
+ {
+ data_ap->user_source.SplitIntoLines(line);
+ BatonSP baton_sp (new WatchpointOptions::CommandBaton (data_ap.release()));
+ wp_options->SetCallback (WatchpointOptionsCallbackFunction, baton_sp);
+ }
}
+ }
+ void
+ CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
+ CommandReturnObject &result)
+ {
+ m_interpreter.GetLLDBCommandsFromIOHandler ("> ", // Prompt
+ *this, // IOHandlerDelegate
+ true, // Run IOHandler in async mode
+ wp_options); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
}
/// Set a one-liner as the callback for the watchpoint.
@@ -240,93 +249,6 @@ but do NOT enter more than one command per line. \n" );
return;
}
-
- static size_t
- GenerateWatchpointCommandCallback (void *callback_data,
- InputReader &reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len)
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
-
- switch (notification)
- {
- case eInputReaderActivate:
- if (!batch_mode)
- {
- out_stream->Printf ("%s\n", g_reader_instructions);
- if (reader.GetPrompt())
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush();
- }
- break;
-
- case eInputReaderDeactivate:
- break;
-
- case eInputReaderReactivate:
- if (reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush();
- }
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
-
- case eInputReaderGotToken:
- if (bytes && bytes_len && callback_data)
- {
- WatchpointOptions *wp_options = (WatchpointOptions *) callback_data;
- if (wp_options)
- {
- Baton *wp_options_baton = wp_options->GetBaton();
- if (wp_options_baton)
- ((WatchpointOptions::CommandData *)wp_options_baton->m_data)->user_source.AppendString (bytes, bytes_len);
- }
- }
- if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush();
- }
- break;
-
- case eInputReaderInterrupt:
- {
- // Finish, and cancel the watchpoint command.
- reader.SetIsDone (true);
- WatchpointOptions *wp_options = (WatchpointOptions *) callback_data;
- if (wp_options)
- {
- Baton *wp_options_baton = wp_options->GetBaton ();
- if (wp_options_baton)
- {
- ((WatchpointOptions::CommandData *) wp_options_baton->m_data)->user_source.Clear();
- ((WatchpointOptions::CommandData *) wp_options_baton->m_data)->script_source.clear();
- }
- }
- if (!batch_mode)
- {
- out_stream->Printf ("Warning: No command attached to watchpoint.\n");
- out_stream->Flush();
- }
- }
- break;
-
- case eInputReaderEndOfFile:
- reader.SetIsDone (true);
- break;
-
- case eInputReaderDone:
- break;
- }
-
- return bytes_len;
- }
static bool
WatchpointOptionsCallbackFunction (void *baton,
@@ -579,12 +501,8 @@ protected:
private:
CommandOptions m_options;
- static const char *g_reader_instructions;
-
};
-const char *
-CommandObjectWatchpointCommandAdd::g_reader_instructions = "Enter your debugger command(s). Type 'DONE' to end.";
// FIXME: "script-type" needs to have its contents determined dynamically, so somebody can add a new scripting
// language to lldb and have it pickable here without having to change this enumeration by hand and rebuild lldb proper.
diff --git a/source/Commands/CommandObjectWatchpointCommand.h b/source/Commands/CommandObjectWatchpointCommand.h
index c2faf7187db9..3bc9b3537db7 100644
--- a/source/Commands/CommandObjectWatchpointCommand.h
+++ b/source/Commands/CommandObjectWatchpointCommand.h
@@ -19,9 +19,6 @@
#include "lldb/lldb-types.h"
#include "lldb/Interpreter/Options.h"
-#include "lldb/Core/InputReader.h"
-#include "lldb/Interpreter/CommandObject.h"
-#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
diff --git a/source/Core/Address.cpp b/source/Core/Address.cpp
index de2165cff84e..5ac2bcce70f0 100644
--- a/source/Core/Address.cpp
+++ b/source/Core/Address.cpp
@@ -16,6 +16,7 @@
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Symbol/SymbolVendor.h"
@@ -327,15 +328,27 @@ Address::GetLoadAddress (Target *target) const
addr_t
Address::GetCallableLoadAddress (Target *target, bool is_indirect) const
{
- if (is_indirect && target) {
+ addr_t code_addr = LLDB_INVALID_ADDRESS;
+
+ if (is_indirect && target)
+ {
ProcessSP processSP = target->GetProcessSP();
Error error;
if (processSP.get())
- return processSP->ResolveIndirectFunction(this, error);
+ {
+ code_addr = processSP->ResolveIndirectFunction(this, error);
+ if (!error.Success())
+ code_addr = LLDB_INVALID_ADDRESS;
+ }
}
-
- addr_t code_addr = GetLoadAddress (target);
-
+ else
+ {
+ code_addr = GetLoadAddress (target);
+ }
+
+ if (code_addr == LLDB_INVALID_ADDRESS)
+ return code_addr;
+
if (target)
return target->GetCallableLoadAddress (code_addr, GetAddressClass());
return code_addr;
diff --git a/source/Core/ArchSpec.cpp b/source/Core/ArchSpec.cpp
index f2eb3751a4b5..f4fa22437a9c 100644
--- a/source/Core/ArchSpec.cpp
+++ b/source/Core/ArchSpec.cpp
@@ -104,6 +104,7 @@ static const CoreDefinition g_core_definitions[ArchSpec::kNumCores] =
{ eByteOrderLittle, 4, 1, 15, llvm::Triple::x86 , ArchSpec::eCore_x86_32_i486sx , "i486sx" },
{ eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64 , ArchSpec::eCore_x86_64_x86_64 , "x86_64" },
+ { eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64 , ArchSpec::eCore_x86_64_x86_64h , "x86_64h" },
{ eByteOrderLittle, 4, 4, 4 , llvm::Triple::UnknownArch , ArchSpec::eCore_uknownMach32 , "unknown-mach-32" },
{ eByteOrderLittle, 8, 4, 4 , llvm::Triple::UnknownArch , ArchSpec::eCore_uknownMach64 , "unknown-mach-64" }
};
@@ -205,10 +206,11 @@ static const ArchDefinitionEntry g_macho_arch_entries[] =
{ ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPU_TYPE_I386 , 3 , UINT32_MAX , SUBTYPE_MASK },
{ ArchSpec::eCore_x86_32_i486 , llvm::MachO::CPU_TYPE_I386 , 4 , UINT32_MAX , SUBTYPE_MASK },
{ ArchSpec::eCore_x86_32_i486sx , llvm::MachO::CPU_TYPE_I386 , 0x84 , UINT32_MAX , SUBTYPE_MASK },
- { ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPU_TYPE_I386 , CPU_ANY, UINT32_MAX , UINT32_MAX },
+ { ArchSpec::eCore_x86_32_i386 , llvm::MachO::CPU_TYPE_I386 , CPU_ANY, UINT32_MAX , UINT32_MAX },
{ ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPU_TYPE_X86_64 , 3 , UINT32_MAX , SUBTYPE_MASK },
{ ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPU_TYPE_X86_64 , 4 , UINT32_MAX , SUBTYPE_MASK },
- { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPU_TYPE_X86_64 , CPU_ANY, UINT32_MAX , UINT32_MAX },
+ { ArchSpec::eCore_x86_64_x86_64h , llvm::MachO::CPU_TYPE_X86_64 , 8 , UINT32_MAX , SUBTYPE_MASK },
+ { ArchSpec::eCore_x86_64_x86_64 , llvm::MachO::CPU_TYPE_X86_64 , CPU_ANY, UINT32_MAX , UINT32_MAX },
// Catch any unknown mach architectures so we can always use the object and symbol mach-o files
{ ArchSpec::eCore_uknownMach32 , 0 , 0 , 0xFF000000u, 0x00000000u },
{ ArchSpec::eCore_uknownMach64 , llvm::MachO::CPU_ARCH_ABI64 , 0 , 0xFF000000u, 0x00000000u }
@@ -349,14 +351,16 @@ FindArchDefinitionEntry (const ArchDefinition *def, ArchSpec::Core core)
ArchSpec::ArchSpec() :
m_triple (),
m_core (kCore_invalid),
- m_byte_order (eByteOrderInvalid)
+ m_byte_order (eByteOrderInvalid),
+ m_distribution_id ()
{
}
ArchSpec::ArchSpec (const char *triple_cstr, Platform *platform) :
m_triple (),
m_core (kCore_invalid),
- m_byte_order (eByteOrderInvalid)
+ m_byte_order (eByteOrderInvalid),
+ m_distribution_id ()
{
if (triple_cstr)
SetTriple(triple_cstr, platform);
@@ -366,7 +370,8 @@ ArchSpec::ArchSpec (const char *triple_cstr, Platform *platform) :
ArchSpec::ArchSpec (const char *triple_cstr) :
m_triple (),
m_core (kCore_invalid),
- m_byte_order (eByteOrderInvalid)
+ m_byte_order (eByteOrderInvalid),
+ m_distribution_id ()
{
if (triple_cstr)
SetTriple(triple_cstr);
@@ -375,7 +380,8 @@ ArchSpec::ArchSpec (const char *triple_cstr) :
ArchSpec::ArchSpec(const llvm::Triple &triple) :
m_triple (),
m_core (kCore_invalid),
- m_byte_order (eByteOrderInvalid)
+ m_byte_order (eByteOrderInvalid),
+ m_distribution_id ()
{
SetTriple(triple);
}
@@ -383,7 +389,8 @@ ArchSpec::ArchSpec(const llvm::Triple &triple) :
ArchSpec::ArchSpec (ArchitectureType arch_type, uint32_t cpu, uint32_t subtype) :
m_triple (),
m_core (kCore_invalid),
- m_byte_order (eByteOrderInvalid)
+ m_byte_order (eByteOrderInvalid),
+ m_distribution_id ()
{
SetArchitecture (arch_type, cpu, subtype);
}
@@ -403,6 +410,7 @@ ArchSpec::operator= (const ArchSpec& rhs)
m_triple = rhs.m_triple;
m_core = rhs.m_core;
m_byte_order = rhs.m_byte_order;
+ m_distribution_id = rhs.m_distribution_id;
}
return *this;
}
@@ -413,6 +421,7 @@ ArchSpec::Clear()
m_triple = llvm::Triple();
m_core = kCore_invalid;
m_byte_order = eByteOrderInvalid;
+ m_distribution_id.Clear ();
}
//===----------------------------------------------------------------------===//
@@ -468,6 +477,18 @@ ArchSpec::GetMachine () const
return llvm::Triple::UnknownArch;
}
+const ConstString&
+ArchSpec::GetDistributionId () const
+{
+ return m_distribution_id;
+}
+
+void
+ArchSpec::SetDistributionId (const char* distribution_id)
+{
+ m_distribution_id.SetCString (distribution_id);
+}
+
uint32_t
ArchSpec::GetAddressByteSize() const
{
@@ -763,6 +784,8 @@ ArchSpec::IsCompatibleMatch (const ArchSpec& rhs) const
bool
ArchSpec::IsEqualTo (const ArchSpec& rhs, bool exact_match) const
{
+ // explicitly ignoring m_distribution_id in this method.
+
if (GetByteOrder() != rhs.GetByteOrder())
return false;
@@ -873,7 +896,7 @@ cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_in
if (core2 == ArchSpec::kCore_arm_any)
return true;
break;
-
+
case ArchSpec::kCore_x86_32_any:
if ((core2 >= ArchSpec::kCore_x86_32_first && core2 <= ArchSpec::kCore_x86_32_last) || (core2 == ArchSpec::kCore_x86_32_any))
return true;
diff --git a/source/Core/Broadcaster.cpp b/source/Core/Broadcaster.cpp
index 5af7497c8da9..88f39961832f 100644
--- a/source/Core/Broadcaster.cpp
+++ b/source/Core/Broadcaster.cpp
@@ -313,18 +313,22 @@ Broadcaster::RestoreBroadcaster ()
{
Mutex::Locker event_types_locker(m_listeners_mutex);
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EVENTS));
- if (log)
+ if (!m_hijacking_listeners.empty())
{
- Listener *listener = m_hijacking_listeners.back();
- log->Printf ("%p Broadcaster(\"%s\")::RestoreBroadcaster (about to pop listener(\"%s\")=%p)",
- this,
- m_broadcaster_name.AsCString(""),
- listener->m_name.c_str(),
- listener);
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EVENTS));
+ if (log)
+ {
+ Listener *listener = m_hijacking_listeners.back();
+ log->Printf ("%p Broadcaster(\"%s\")::RestoreBroadcaster (about to pop listener(\"%s\")=%p)",
+ this,
+ m_broadcaster_name.AsCString(""),
+ listener->m_name.c_str(),
+ listener);
+ }
+ m_hijacking_listeners.pop_back();
}
- m_hijacking_listeners.pop_back();
- m_hijacking_masks.pop_back();
+ if (!m_hijacking_masks.empty())
+ m_hijacking_masks.pop_back();
}
ConstString &
diff --git a/source/Core/Communication.cpp b/source/Core/Communication.cpp
index 6ea7a11426be..f05ce320b5be 100644
--- a/source/Core/Communication.cpp
+++ b/source/Core/Communication.cpp
@@ -269,6 +269,16 @@ Communication::StopReadThread (Error *error_ptr)
return status;
}
+bool
+Communication::JoinReadThread (Error *error_ptr)
+{
+ if (!IS_VALID_LLDB_HOST_THREAD(m_read_thread))
+ return true;
+
+ bool success = Host::ThreadJoin (m_read_thread, NULL, error_ptr);
+ m_read_thread = LLDB_INVALID_HOST_THREAD;
+ return success;
+}
size_t
Communication::GetCachedBytes (void *dst, size_t dst_len)
diff --git a/source/Core/ConnectionFileDescriptor.cpp b/source/Core/ConnectionFileDescriptor.cpp
index 5764a212ab43..ed876e52c9af 100644
--- a/source/Core/ConnectionFileDescriptor.cpp
+++ b/source/Core/ConnectionFileDescriptor.cpp
@@ -97,11 +97,11 @@ ConnectionFileDescriptor::ConnectionFileDescriptor () :
m_fd_send_type (eFDTypeFile),
m_fd_recv_type (eFDTypeFile),
m_udp_send_sockaddr (new SocketAddress()),
- m_should_close_fd (false),
m_socket_timeout_usec(0),
m_pipe_read(-1),
m_pipe_write(-1),
m_mutex (Mutex::eMutexTypeRecursive),
+ m_should_close_fd (false),
m_shutting_down (false)
{
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT));
@@ -116,11 +116,11 @@ ConnectionFileDescriptor::ConnectionFileDescriptor (int fd, bool owns_fd) :
m_fd_send_type (eFDTypeFile),
m_fd_recv_type (eFDTypeFile),
m_udp_send_sockaddr (new SocketAddress()),
- m_should_close_fd (owns_fd),
m_socket_timeout_usec(0),
m_pipe_read(-1),
m_pipe_write(-1),
m_mutex (Mutex::eMutexTypeRecursive),
+ m_should_close_fd (owns_fd),
m_shutting_down (false)
{
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT));
@@ -218,12 +218,15 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr)
if (s && s[0])
{
- char *end = NULL;
if (strstr(s, "listen://"))
{
// listen://HOST:PORT
- unsigned long listen_port = ::strtoul(s + strlen("listen://"), &end, 0);
- return SocketListen (listen_port, error_ptr);
+ return SocketListen (s + strlen("listen://"), error_ptr);
+ }
+ else if (strstr(s, "accept://"))
+ {
+ // unix://SOCKNAME
+ return NamedSocketAccept (s + strlen("accept://"), error_ptr);
}
else if (strstr(s, "unix-accept://"))
{
@@ -363,6 +366,9 @@ ConnectionFileDescriptor::Disconnect (Error *error_ptr)
if (log)
log->Printf ("%p ConnectionFileDescriptor::Disconnect ()", this);
+ // Reset the port predicate when disconnecting and don't broadcast
+ m_port_predicate.SetValue(0, eBroadcastNever);
+
ConnectionStatus status = eConnectionStatusSuccess;
if (m_fd_send < 0 && m_fd_recv < 0)
@@ -1281,16 +1287,31 @@ ConnectionFileDescriptor::NamedSocketConnect (const char *socket_name, Error *er
}
ConnectionStatus
-ConnectionFileDescriptor::SocketListen (uint16_t listen_port_num, Error *error_ptr)
+ConnectionFileDescriptor::SocketListen (const char *host_and_port, Error *error_ptr)
{
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION));
if (log)
- log->Printf ("%p ConnectionFileDescriptor::SocketListen (port = %i)", this, listen_port_num);
+ log->Printf ("%p ConnectionFileDescriptor::SocketListen (%s)", this, host_and_port);
Disconnect (NULL);
m_fd_send_type = m_fd_recv_type = eFDTypeSocket;
- int listen_port = ::socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (listen_port == -1)
+ std::string host_str;
+ std::string port_str;
+ int32_t port = INT32_MIN;
+ if (!DecodeHostAndPort (host_and_port, host_str, port_str, port, error_ptr))
+ {
+ // Might be just a port number
+ port = Args::StringToSInt32(host_and_port, -1);
+ if (port == -1)
+ return eConnectionStatusError;
+ else
+ host_str.clear();
+ }
+ const sa_family_t family = AF_INET;
+ const int socktype = SOCK_STREAM;
+ const int protocol = IPPROTO_TCP;
+ int listen_fd = ::socket (family, socktype, protocol);
+ if (listen_fd == -1)
{
if (error_ptr)
error_ptr->SetErrorToErrno();
@@ -1298,41 +1319,119 @@ ConnectionFileDescriptor::SocketListen (uint16_t listen_port_num, Error *error_p
}
// enable local address reuse
- SetSocketOption (listen_port, SOL_SOCKET, SO_REUSEADDR, 1);
+ SetSocketOption (listen_fd, SOL_SOCKET, SO_REUSEADDR, 1);
- SocketAddress localhost;
- if (localhost.SetToLocalhost (AF_INET, listen_port_num))
+ SocketAddress listen_addr;
+ if (host_str.empty())
+ listen_addr.SetToLocalhost(family, port);
+ else if (host_str.compare("*") == 0)
+ listen_addr.SetToAnyAddress(family, port);
+ else
{
- int err = ::bind (listen_port, localhost, localhost.GetLength());
+ if (!listen_addr.getaddrinfo(host_str.c_str(), port_str.c_str(), family, socktype, protocol))
+ {
+ if (error_ptr)
+ error_ptr->SetErrorStringWithFormat("unable to resolve hostname '%s'", host_str.c_str());
+ Close (listen_fd, eFDTypeSocket, NULL);
+ return eConnectionStatusError;
+ }
+ }
+
+ SocketAddress anyaddr;
+ if (anyaddr.SetToAnyAddress (family, port))
+ {
+ int err = ::bind (listen_fd, anyaddr, anyaddr.GetLength());
if (err == -1)
{
if (error_ptr)
error_ptr->SetErrorToErrno();
- Close (listen_port, eFDTypeSocket, NULL);
+ Close (listen_fd, eFDTypeSocket, NULL);
return eConnectionStatusError;
}
- err = ::listen (listen_port, 1);
+ err = ::listen (listen_fd, 1);
if (err == -1)
{
if (error_ptr)
error_ptr->SetErrorToErrno();
- Close (listen_port, eFDTypeSocket, NULL);
+ Close (listen_fd, eFDTypeSocket, NULL);
return eConnectionStatusError;
}
- m_fd_send = m_fd_recv = ::accept (listen_port, NULL, 0);
+ // We were asked to listen on port zero which means we
+ // must now read the actual port that was given to us
+ // as port zero is a special code for "find an open port
+ // for me".
+ if (port == 0)
+ port = GetSocketPort(listen_fd);
+
+ // Set the port predicate since when doing a listen://<host>:<port>
+ // it often needs to accept the incoming connection which is a blocking
+ // system call. Allowing access to the bound port using a predicate allows
+ // us to wait for the port predicate to be set to a non-zero value from
+ // another thread in an efficient manor.
+ m_port_predicate.SetValue(port, eBroadcastAlways);
+
+
+ bool accept_connection = false;
+
+ // Loop until we are happy with our connection
+ while (!accept_connection)
+ {
+ struct sockaddr_in accept_addr;
+ ::memset (&accept_addr, 0, sizeof accept_addr);
+#if !(defined (__linux__) || defined(_MSC_VER))
+ accept_addr.sin_len = sizeof accept_addr;
+#endif
+ socklen_t accept_addr_len = sizeof accept_addr;
+
+ int fd = ::accept (listen_fd, (struct sockaddr *)&accept_addr, &accept_addr_len);
+
+ if (fd == -1)
+ {
+ if (error_ptr)
+ error_ptr->SetErrorToErrno();
+ break;
+ }
+
+ if (listen_addr.sockaddr_in().sin_addr.s_addr == INADDR_ANY)
+ {
+ accept_connection = true;
+ m_fd_send = m_fd_recv = fd;
+ }
+ else
+ {
+ if (
+#if !(defined(__linux__) || (defined(_MSC_VER)))
+ accept_addr_len == listen_addr.sockaddr_in().sin_len &&
+#endif
+ accept_addr.sin_addr.s_addr == listen_addr.sockaddr_in().sin_addr.s_addr)
+ {
+ accept_connection = true;
+ m_fd_send = m_fd_recv = fd;
+ }
+ else
+ {
+ ::close (fd);
+ m_fd_send = m_fd_recv = -1;
+ const uint8_t *accept_ip = (const uint8_t *)&accept_addr.sin_addr.s_addr;
+ const uint8_t *listen_ip = (const uint8_t *)&listen_addr.sockaddr_in().sin_addr.s_addr;
+ ::fprintf (stderr, "error: rejecting incoming connection from %u.%u.%u.%u (expecting %u.%u.%u.%u)\n",
+ accept_ip[0], accept_ip[1], accept_ip[2], accept_ip[3],
+ listen_ip[0], listen_ip[1], listen_ip[2], listen_ip[3]);
+ }
+ }
+ }
+
if (m_fd_send == -1)
{
- if (error_ptr)
- error_ptr->SetErrorToErrno();
- Close (listen_port, eFDTypeSocket, NULL);
+ Close (listen_fd, eFDTypeSocket, NULL);
return eConnectionStatusError;
}
}
// We are done with the listen port
- Close (listen_port, eFDTypeSocket, NULL);
+ Close (listen_fd, eFDTypeSocket, NULL);
m_should_close_fd = true;
@@ -1446,7 +1545,7 @@ ConnectionFileDescriptor::ConnectUDP (const char *host_and_port, Error *error_pt
{
// Socket was created, now lets bind to the requested port
SocketAddress addr;
- addr.SetToLocalhost (AF_INET, 0);
+ addr.SetToAnyAddress (AF_INET, 0);
if (::bind (m_fd_recv, addr, addr.GetLength()) == -1)
{
@@ -1581,21 +1680,23 @@ ConnectionFileDescriptor::SetSocketReceiveTimeout (uint32_t timeout_usec)
return false;
}
-in_port_t
+uint16_t
ConnectionFileDescriptor::GetSocketPort (int fd)
{
// We bound to port zero, so we need to figure out which port we actually bound to
- SocketAddress sock_addr;
- socklen_t sock_addr_len = sock_addr.GetMaxLength ();
- if (::getsockname (fd, sock_addr, &sock_addr_len) == 0)
- return sock_addr.GetPort ();
-
+ if (fd >= 0)
+ {
+ SocketAddress sock_addr;
+ socklen_t sock_addr_len = sock_addr.GetMaxLength ();
+ if (::getsockname (fd, sock_addr, &sock_addr_len) == 0)
+ return sock_addr.GetPort ();
+ }
return 0;
}
// If the read file descriptor is a socket, then return
// the port number that is being used by the socket.
-in_port_t
+uint16_t
ConnectionFileDescriptor::GetReadPort () const
{
return ConnectionFileDescriptor::GetSocketPort (m_fd_recv);
@@ -1603,10 +1704,23 @@ ConnectionFileDescriptor::GetReadPort () const
// If the write file descriptor is a socket, then return
// the port number that is being used by the socket.
-in_port_t
+uint16_t
ConnectionFileDescriptor::GetWritePort () const
{
return ConnectionFileDescriptor::GetSocketPort (m_fd_send);
}
-
+uint16_t
+ConnectionFileDescriptor::GetBoundPort (uint32_t timeout_sec)
+{
+ uint16_t bound_port = 0;
+ if (timeout_sec == UINT32_MAX)
+ m_port_predicate.WaitForValueNotEqualTo (0, bound_port);
+ else
+ {
+ TimeValue timeout = TimeValue::Now();
+ timeout.OffsetWithSeconds(timeout_sec);
+ m_port_predicate.WaitForValueNotEqualTo (0, bound_port, &timeout);
+ }
+ return bound_port;
+}
diff --git a/source/Core/DataExtractor.cpp b/source/Core/DataExtractor.cpp
index d1f3c09c2305..b42c6ff31449 100644
--- a/source/Core/DataExtractor.cpp
+++ b/source/Core/DataExtractor.cpp
@@ -37,6 +37,7 @@
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/ExecutionContextScope.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
using namespace lldb;
@@ -45,69 +46,97 @@ using namespace lldb_private;
static inline uint16_t
ReadInt16(const unsigned char* ptr, offset_t offset)
{
- return *(uint16_t *)(ptr + offset);
+ uint16_t value;
+ memcpy (&value, ptr + offset, 2);
+ return value;
}
+
static inline uint32_t
ReadInt32 (const unsigned char* ptr, offset_t offset)
{
- return *(uint32_t *)(ptr + offset);
+ uint32_t value;
+ memcpy (&value, ptr + offset, 4);
+ return value;
}
static inline uint64_t
ReadInt64(const unsigned char* ptr, offset_t offset)
{
- return *(uint64_t *)(ptr + offset);
+ uint64_t value;
+ memcpy (&value, ptr + offset, 8);
+ return value;
}
static inline uint16_t
ReadInt16(const void* ptr)
{
- return *(uint16_t *)(ptr);
+ uint16_t value;
+ memcpy (&value, ptr, 2);
+ return value;
}
+
static inline uint32_t
ReadInt32 (const void* ptr)
{
- return *(uint32_t *)(ptr);
+ uint32_t value;
+ memcpy (&value, ptr, 4);
+ return value;
}
static inline uint64_t
ReadInt64(const void* ptr)
{
- return *(uint64_t *)(ptr);
+ uint64_t value;
+ memcpy (&value, ptr, 8);
+ return value;
}
static inline uint16_t
ReadSwapInt16(const unsigned char* ptr, offset_t offset)
{
- return llvm::ByteSwap_16(*(uint16_t *)(ptr + offset));
+ uint16_t value;
+ memcpy (&value, ptr + offset, 2);
+ return llvm::ByteSwap_16(value);
}
static inline uint32_t
ReadSwapInt32 (const unsigned char* ptr, offset_t offset)
{
- return llvm::ByteSwap_32(*(uint32_t *)(ptr + offset));
+ uint32_t value;
+ memcpy (&value, ptr + offset, 4);
+ return llvm::ByteSwap_32(value);
}
+
static inline uint64_t
ReadSwapInt64(const unsigned char* ptr, offset_t offset)
{
- return llvm::ByteSwap_64(*(uint64_t *)(ptr + offset));
+ uint64_t value;
+ memcpy (&value, ptr + offset, 8);
+ return llvm::ByteSwap_64(value);
}
static inline uint16_t
ReadSwapInt16(const void* ptr)
{
- return llvm::ByteSwap_16(*(uint16_t *)(ptr));
+ uint16_t value;
+ memcpy (&value, ptr, 2);
+ return llvm::ByteSwap_16(value);
}
static inline uint32_t
ReadSwapInt32 (const void* ptr)
{
- return llvm::ByteSwap_32(*(uint32_t *)(ptr));
+ uint32_t value;
+ memcpy (&value, ptr, 4);
+ return llvm::ByteSwap_32(value);
}
+
static inline uint64_t
ReadSwapInt64(const void* ptr)
{
- return llvm::ByteSwap_64(*(uint64_t *)(ptr));
+ uint64_t value;
+ memcpy (&value, ptr, 8);
+ return llvm::ByteSwap_64(value);
}
#define NON_PRINTABLE_CHAR '.'
@@ -502,13 +531,17 @@ uint32_t
DataExtractor::GetU32 (offset_t *offset_ptr) const
{
uint32_t val = 0;
- const uint32_t *data = (const uint32_t *)GetData (offset_ptr, sizeof(val));
+ const uint8_t *data = (const uint8_t *)GetData (offset_ptr, sizeof(val));
if (data)
{
if (m_byte_order != lldb::endian::InlHostByteOrder())
+ {
val = ReadSwapInt32 (data);
+ }
else
- val = *data;
+ {
+ memcpy (&val, data, 4);
+ }
}
return val;
}
@@ -561,13 +594,17 @@ uint64_t
DataExtractor::GetU64 (offset_t *offset_ptr) const
{
uint64_t val = 0;
- const uint64_t *data = (const uint64_t *)GetData (offset_ptr, sizeof(val));
+ const uint8_t *data = (const uint8_t *)GetData (offset_ptr, sizeof(val));
if (data)
{
if (m_byte_order != lldb::endian::InlHostByteOrder())
+ {
val = ReadSwapInt64 (data);
+ }
else
- val = *data;
+ {
+ memcpy (&val, data, 8);
+ }
}
return val;
}
@@ -1808,6 +1845,7 @@ DataExtractor::Dump (Stream *s,
case ArchSpec::eCore_x86_32_i486:
case ArchSpec::eCore_x86_32_i486sx:
case ArchSpec::eCore_x86_64_x86_64:
+ case ArchSpec::eCore_x86_64_x86_64h:
// clang will assert when contructing the apfloat if we use a 16 byte integer value
if (GetAPInt (*this, &offset, 10, apint))
{
diff --git a/source/Core/Debugger.cpp b/source/Core/Debugger.cpp
index b57c6051a961..5b346ed636d6 100644
--- a/source/Core/Debugger.cpp
+++ b/source/Core/Debugger.cpp
@@ -18,13 +18,13 @@
#include "lldb/lldb-private.h"
#include "lldb/Core/ConnectionFileDescriptor.h"
-#include "lldb/Core/InputReader.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/State.h"
#include "lldb/Core/StreamAsynchronousIO.h"
#include "lldb/Core/StreamCallback.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Timer.h"
#include "lldb/Core/ValueObject.h"
@@ -180,6 +180,7 @@ Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
if (str.length())
new_prompt = str.c_str();
+ GetCommandInterpreter().UpdatePrompt(new_prompt);
EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));
GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
}
@@ -196,12 +197,16 @@ Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
StreamString feedback_stream;
if (!target_sp->LoadScriptingResources(errors,&feedback_stream))
{
- for (auto error : errors)
+ StreamFileSP stream_sp (GetErrorFile());
+ if (stream_sp)
{
- GetErrorStream().Printf("%s\n",error.AsCString());
+ for (auto error : errors)
+ {
+ stream_sp->Printf("%s\n",error.AsCString());
+ }
+ if (feedback_stream.GetSize())
+ stream_sp->Printf("%s",feedback_stream.GetData());
}
- if (feedback_stream.GetSize())
- GetErrorStream().Printf("%s",feedback_stream.GetData());
}
}
}
@@ -246,8 +251,7 @@ Debugger::SetPrompt(const char *p)
std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
if (str.length())
new_prompt = str.c_str();
- EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));;
- GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
+ GetCommandInterpreter().UpdatePrompt(new_prompt);
}
const char *
@@ -611,10 +615,9 @@ Debugger::FindTargetWithProcess (Process *process)
Debugger::Debugger (lldb::LogOutputCallback log_callback, void *baton) :
UserID (g_unique_id++),
Properties(OptionValuePropertiesSP(new OptionValueProperties())),
- m_input_comm("debugger.input"),
- m_input_file (),
- m_output_file (),
- m_error_file (),
+ m_input_file_sp (new StreamFile (stdin, false)),
+ m_output_file_sp (new StreamFile (stdout, false)),
+ m_error_file_sp (new StreamFile (stderr, false)),
m_terminal_state (),
m_target_list (*this),
m_platform_list (),
@@ -623,8 +626,11 @@ Debugger::Debugger (lldb::LogOutputCallback log_callback, void *baton) :
m_source_file_cache(),
m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
m_input_reader_stack (),
- m_input_reader_data (),
- m_instance_name()
+ m_instance_name (),
+ m_loaded_plugins (),
+ m_event_handler_thread (LLDB_INVALID_HOST_THREAD),
+ m_io_handler_thread (LLDB_INVALID_HOST_THREAD),
+ m_event_handler_thread_alive(false)
{
char instance_cstr[256];
snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
@@ -667,7 +673,9 @@ Debugger::~Debugger ()
void
Debugger::Clear()
{
- CleanUpInputReaders();
+ ClearIOHandlers();
+ StopIOHandlerThread();
+ StopEventHandlerThread();
m_listener.Clear();
int num_targets = m_target_list.GetNumTargets();
for (int i = 0; i < num_targets; i++)
@@ -686,23 +694,21 @@ Debugger::Clear()
// Close the input file _before_ we close the input read communications class
// as it does NOT own the input file, our m_input_file does.
m_terminal_state.Clear();
- GetInputFile().Close ();
- // Now that we have closed m_input_file, we can now tell our input communication
- // class to close down. Its read thread should quickly exit after we close
- // the input file handle above.
- m_input_comm.Clear ();
+ if (m_input_file_sp)
+ m_input_file_sp->GetFile().Close ();
}
bool
Debugger::GetCloseInputOnEOF () const
{
- return m_input_comm.GetCloseOnEOF();
+// return m_input_comm.GetCloseOnEOF();
+ return false;
}
void
Debugger::SetCloseInputOnEOF (bool b)
{
- m_input_comm.SetCloseOnEOF(b);
+// m_input_comm.SetCloseOnEOF(b);
}
bool
@@ -721,37 +727,28 @@ Debugger::SetAsyncExecution (bool async_execution)
void
Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
{
- File &in_file = GetInputFile();
- in_file.SetStream (fh, tranfer_ownership);
+ if (m_input_file_sp)
+ m_input_file_sp->GetFile().SetStream (fh, tranfer_ownership);
+ else
+ m_input_file_sp.reset (new StreamFile (fh, tranfer_ownership));
+
+ File &in_file = m_input_file_sp->GetFile();
if (in_file.IsValid() == false)
in_file.SetStream (stdin, true);
- // Disconnect from any old connection if we had one
- m_input_comm.Disconnect ();
- // Pass false as the second argument to ConnectionFileDescriptor below because
- // our "in_file" above will already take ownership if requested and we don't
- // want to objects trying to own and close a file descriptor.
- m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), false));
- m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
-
// Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState.
SaveInputTerminalState ();
-
- Error error;
- if (m_input_comm.StartReadThread (&error) == false)
- {
- File &err_file = GetErrorFile();
-
- err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
- exit(1);
- }
}
void
Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
{
- File &out_file = GetOutputFile();
- out_file.SetStream (fh, tranfer_ownership);
+ if (m_output_file_sp)
+ m_output_file_sp->GetFile().SetStream (fh, tranfer_ownership);
+ else
+ m_output_file_sp.reset (new StreamFile (fh, tranfer_ownership));
+
+ File &out_file = m_output_file_sp->GetFile();
if (out_file.IsValid() == false)
out_file.SetStream (stdout, false);
@@ -766,8 +763,12 @@ Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
void
Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
{
- File &err_file = GetErrorFile();
- err_file.SetStream (fh, tranfer_ownership);
+ if (m_error_file_sp)
+ m_error_file_sp->GetFile().SetStream (fh, tranfer_ownership);
+ else
+ m_error_file_sp.reset (new StreamFile (fh, tranfer_ownership));
+
+ File &err_file = m_error_file_sp->GetFile();
if (err_file.IsValid() == false)
err_file.SetStream (stderr, false);
}
@@ -775,9 +776,12 @@ Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
void
Debugger::SaveInputTerminalState ()
{
- File &in_file = GetInputFile();
- if (in_file.GetDescriptor() != File::kInvalidDescriptor)
- m_terminal_state.Save(in_file.GetDescriptor(), true);
+ if (m_input_file_sp)
+ {
+ File &in_file = m_input_file_sp->GetFile();
+ if (in_file.GetDescriptor() != File::kInvalidDescriptor)
+ m_terminal_state.Save(in_file.GetDescriptor(), true);
+ }
}
void
@@ -812,245 +816,211 @@ Debugger::GetSelectedExecutionContext ()
return exe_ctx;
}
-InputReaderSP
-Debugger::GetCurrentInputReader ()
-{
- InputReaderSP reader_sp;
-
- if (!m_input_reader_stack.IsEmpty())
- {
- // Clear any finished readers from the stack
- while (CheckIfTopInputReaderIsDone()) ;
-
- if (!m_input_reader_stack.IsEmpty())
- reader_sp = m_input_reader_stack.Top();
- }
-
- return reader_sp;
-}
-
-void
-Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
-{
- if (bytes_len > 0)
- ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
- else
- ((Debugger *)baton)->DispatchInputEndOfFile ();
-}
-
-
-void
-Debugger::DispatchInput (const char *bytes, size_t bytes_len)
-{
- if (bytes == NULL || bytes_len == 0)
- return;
-
- WriteToDefaultReader (bytes, bytes_len);
-}
-
void
Debugger::DispatchInputInterrupt ()
{
- m_input_reader_data.clear();
-
- InputReaderSP reader_sp (GetCurrentInputReader ());
+ Mutex::Locker locker (m_input_reader_stack.GetMutex());
+ IOHandlerSP reader_sp (m_input_reader_stack.Top());
if (reader_sp)
- {
- reader_sp->Notify (eInputReaderInterrupt);
-
- // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
- while (CheckIfTopInputReaderIsDone ()) ;
- }
+ reader_sp->Interrupt();
}
void
Debugger::DispatchInputEndOfFile ()
{
- m_input_reader_data.clear();
-
- InputReaderSP reader_sp (GetCurrentInputReader ());
+ Mutex::Locker locker (m_input_reader_stack.GetMutex());
+ IOHandlerSP reader_sp (m_input_reader_stack.Top());
if (reader_sp)
- {
- reader_sp->Notify (eInputReaderEndOfFile);
-
- // If notifying the reader of the end-of-file finished the reader, we should pop it off the stack.
- while (CheckIfTopInputReaderIsDone ()) ;
- }
+ reader_sp->GotEOF();
}
void
-Debugger::CleanUpInputReaders ()
+Debugger::ClearIOHandlers ()
{
- m_input_reader_data.clear();
-
// The bottom input reader should be the main debugger input reader. We do not want to close that one here.
+ Mutex::Locker locker (m_input_reader_stack.GetMutex());
while (m_input_reader_stack.GetSize() > 1)
{
- InputReaderSP reader_sp (GetCurrentInputReader ());
+ IOHandlerSP reader_sp (m_input_reader_stack.Top());
if (reader_sp)
{
- reader_sp->Notify (eInputReaderEndOfFile);
- reader_sp->SetIsDone (true);
+ m_input_reader_stack.Pop();
+ reader_sp->SetIsDone(true);
+ reader_sp->Interrupt();
}
}
}
void
-Debugger::NotifyTopInputReader (InputReaderAction notification)
+Debugger::ExecuteIOHanders()
{
- InputReaderSP reader_sp (GetCurrentInputReader());
- if (reader_sp)
- {
- reader_sp->Notify (notification);
+
+ while (1)
+ {
+ IOHandlerSP reader_sp(m_input_reader_stack.Top());
+ if (!reader_sp)
+ break;
- // Flush out any input readers that are done.
- while (CheckIfTopInputReaderIsDone ())
- /* Do nothing. */;
+ reader_sp->Activate();
+ reader_sp->Run();
+ reader_sp->Deactivate();
+
+ // Remove all input readers that are done from the top of the stack
+ while (1)
+ {
+ IOHandlerSP top_reader_sp = m_input_reader_stack.Top();
+ if (top_reader_sp && top_reader_sp->GetIsDone())
+ m_input_reader_stack.Pop();
+ else
+ break;
+ }
}
+ ClearIOHandlers();
}
bool
-Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp)
+Debugger::IsTopIOHandler (const lldb::IOHandlerSP& reader_sp)
{
- InputReaderSP top_reader_sp (GetCurrentInputReader());
+ return m_input_reader_stack.IsTop (reader_sp);
+}
+
- return (reader_sp.get() == top_reader_sp.get());
+ConstString
+Debugger::GetTopIOHandlerControlSequence(char ch)
+{
+ return m_input_reader_stack.GetTopIOHandlerControlSequence (ch);
}
-
void
-Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
+Debugger::RunIOHandler (const IOHandlerSP& reader_sp)
{
- if (bytes && bytes_len)
- m_input_reader_data.append (bytes, bytes_len);
-
- if (m_input_reader_data.empty())
- return;
+ Mutex::Locker locker (m_input_reader_stack.GetMutex());
+ PushIOHandler (reader_sp);
+ reader_sp->Activate();
+ reader_sp->Run();
+ PopIOHandler (reader_sp);
+}
- while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty())
+void
+Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
+{
+ // Before an IOHandler runs, it must have in/out/err streams.
+ // This function is called when one ore more of the streams
+ // are NULL. We use the top input reader's in/out/err streams,
+ // or fall back to the debugger file handles, or we fall back
+ // onto stdin/stdout/stderr as a last resort.
+
+ Mutex::Locker locker (m_input_reader_stack.GetMutex());
+ IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
+ // If no STDIN has been set, then set it appropriately
+ if (!in)
{
- // Get the input reader from the top of the stack
- InputReaderSP reader_sp (GetCurrentInputReader ());
- if (!reader_sp)
- break;
-
- size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
- m_input_reader_data.size());
- if (bytes_handled)
- {
- m_input_reader_data.erase (0, bytes_handled);
- }
+ if (top_reader_sp)
+ in = top_reader_sp->GetInputStreamFile();
else
- {
- // No bytes were handled, we might not have reached our
- // granularity, just return and wait for more data
- break;
- }
+ in = GetInputFile();
+
+ // If there is nothing, use stdin
+ if (!in)
+ in = StreamFileSP(new StreamFile(stdin, false));
+ }
+ // If no STDOUT has been set, then set it appropriately
+ if (!out)
+ {
+ if (top_reader_sp)
+ out = top_reader_sp->GetOutputStreamFile();
+ else
+ out = GetOutputFile();
+
+ // If there is nothing, use stdout
+ if (!out)
+ out = StreamFileSP(new StreamFile(stdout, false));
+ }
+ // If no STDERR has been set, then set it appropriately
+ if (!err)
+ {
+ if (top_reader_sp)
+ err = top_reader_sp->GetErrorStreamFile();
+ else
+ err = GetErrorFile();
+
+ // If there is nothing, use stderr
+ if (!err)
+ err = StreamFileSP(new StreamFile(stdout, false));
+
}
-
- // Flush out any input readers that are done.
- while (CheckIfTopInputReaderIsDone ())
- /* Do nothing. */;
-
}
void
-Debugger::PushInputReader (const InputReaderSP& reader_sp)
+Debugger::PushIOHandler (const IOHandlerSP& reader_sp)
{
if (!reader_sp)
return;
- // Deactivate the old top reader
- InputReaderSP top_reader_sp (GetCurrentInputReader ());
+ // Got the current top input reader...
+ IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
- if (top_reader_sp)
- top_reader_sp->Notify (eInputReaderDeactivate);
-
+ // Push our new input reader
m_input_reader_stack.Push (reader_sp);
- reader_sp->Notify (eInputReaderActivate);
- ActivateInputReader (reader_sp);
+
+ // Interrupt the top input reader to it will exit its Run() function
+ // and let this new input reader take over
+ if (top_reader_sp)
+ top_reader_sp->Deactivate();
}
bool
-Debugger::PopInputReader (const InputReaderSP& pop_reader_sp)
+Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp)
{
bool result = false;
+
+ Mutex::Locker locker (m_input_reader_stack.GetMutex());
// The reader on the stop of the stack is done, so let the next
// read on the stack referesh its prompt and if there is one...
if (!m_input_reader_stack.IsEmpty())
{
- // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
- InputReaderSP reader_sp(m_input_reader_stack.Top());
+ IOHandlerSP reader_sp(m_input_reader_stack.Top());
if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
{
+ reader_sp->Deactivate();
m_input_reader_stack.Pop ();
- reader_sp->Notify (eInputReaderDeactivate);
- reader_sp->Notify (eInputReaderDone);
- result = true;
+
+ reader_sp = m_input_reader_stack.Top();
+ if (reader_sp)
+ reader_sp->Activate();
- if (!m_input_reader_stack.IsEmpty())
- {
- reader_sp = m_input_reader_stack.Top();
- if (reader_sp)
- {
- ActivateInputReader (reader_sp);
- reader_sp->Notify (eInputReaderReactivate);
- }
- }
+ result = true;
}
}
return result;
}
bool
-Debugger::CheckIfTopInputReaderIsDone ()
+Debugger::HideTopIOHandler()
{
- bool result = false;
- if (!m_input_reader_stack.IsEmpty())
+ Mutex::Locker locker;
+
+ if (locker.TryLock(m_input_reader_stack.GetMutex()))
{
- // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
- InputReaderSP reader_sp(m_input_reader_stack.Top());
-
- if (reader_sp && reader_sp->IsDone())
- {
- result = true;
- PopInputReader (reader_sp);
- }
+ IOHandlerSP reader_sp(m_input_reader_stack.Top());
+ if (reader_sp)
+ reader_sp->Hide();
+ return true;
}
- return result;
+ return false;
}
void
-Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
+Debugger::RefreshTopIOHandler()
{
- int input_fd = m_input_file.GetFile().GetDescriptor();
-
- if (input_fd >= 0)
- {
- Terminal tty(input_fd);
-
- tty.SetEcho(reader_sp->GetEcho());
-
- switch (reader_sp->GetGranularity())
- {
- case eInputReaderGranularityByte:
- case eInputReaderGranularityWord:
- tty.SetCanonical (false);
- break;
-
- case eInputReaderGranularityLine:
- case eInputReaderGranularityAll:
- tty.SetCanonical (true);
- break;
-
- default:
- break;
- }
- }
+ IOHandlerSP reader_sp(m_input_reader_stack.Top());
+ if (reader_sp)
+ reader_sp->Refresh();
}
+
StreamSP
Debugger::GetAsyncOutputStream ()
{
@@ -2624,7 +2594,7 @@ Debugger::EnableLog (const char *channel, const char **categories, const char *l
}
else if (log_file == NULL || *log_file == '\0')
{
- log_stream_sp.reset(new StreamFile(GetOutputFile().GetDescriptor(), false));
+ log_stream_sp = GetOutputFile();
}
else
{
@@ -2680,3 +2650,514 @@ Debugger::GetSourceManager ()
}
+
+// This function handles events that were broadcast by the process.
+void
+Debugger::HandleBreakpointEvent (const EventSP &event_sp)
+{
+ using namespace lldb;
+ const uint32_t event_type = Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event_sp);
+
+// if (event_type & eBreakpointEventTypeAdded
+// || event_type & eBreakpointEventTypeRemoved
+// || event_type & eBreakpointEventTypeEnabled
+// || event_type & eBreakpointEventTypeDisabled
+// || event_type & eBreakpointEventTypeCommandChanged
+// || event_type & eBreakpointEventTypeConditionChanged
+// || event_type & eBreakpointEventTypeIgnoreChanged
+// || event_type & eBreakpointEventTypeLocationsResolved)
+// {
+// // Don't do anything about these events, since the breakpoint commands already echo these actions.
+// }
+//
+ if (event_type & eBreakpointEventTypeLocationsAdded)
+ {
+ uint32_t num_new_locations = Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(event_sp);
+ if (num_new_locations > 0)
+ {
+ BreakpointSP breakpoint = Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp);
+ StreamFileSP output_sp (GetOutputFile());
+ if (output_sp)
+ {
+ output_sp->Printf("%d location%s added to breakpoint %d\n",
+ num_new_locations,
+ num_new_locations == 1 ? "" : "s",
+ breakpoint->GetID());
+ RefreshTopIOHandler();
+ }
+ }
+ }
+// else if (event_type & eBreakpointEventTypeLocationsRemoved)
+// {
+// // These locations just get disabled, not sure it is worth spamming folks about this on the command line.
+// }
+// else if (event_type & eBreakpointEventTypeLocationsResolved)
+// {
+// // This might be an interesting thing to note, but I'm going to leave it quiet for now, it just looked noisy.
+// }
+}
+
+size_t
+Debugger::GetProcessSTDOUT (Process *process, Stream *stream)
+{
+ size_t total_bytes = 0;
+ if (stream == NULL)
+ stream = GetOutputFile().get();
+
+ if (stream)
+ {
+ // The process has stuff waiting for stdout; get it and write it out to the appropriate place.
+ if (process == NULL)
+ {
+ TargetSP target_sp = GetTargetList().GetSelectedTarget();
+ if (target_sp)
+ process = target_sp->GetProcessSP().get();
+ }
+ if (process)
+ {
+ Error error;
+ size_t len;
+ char stdio_buffer[1024];
+ while ((len = process->GetSTDOUT (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
+ {
+ stream->Write(stdio_buffer, len);
+ total_bytes += len;
+ }
+ }
+ stream->Flush();
+ }
+ return total_bytes;
+}
+
+size_t
+Debugger::GetProcessSTDERR (Process *process, Stream *stream)
+{
+ size_t total_bytes = 0;
+ if (stream == NULL)
+ stream = GetOutputFile().get();
+
+ if (stream)
+ {
+ // The process has stuff waiting for stderr; get it and write it out to the appropriate place.
+ if (process == NULL)
+ {
+ TargetSP target_sp = GetTargetList().GetSelectedTarget();
+ if (target_sp)
+ process = target_sp->GetProcessSP().get();
+ }
+ if (process)
+ {
+ Error error;
+ size_t len;
+ char stdio_buffer[1024];
+ while ((len = process->GetSTDERR (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
+ {
+ stream->Write(stdio_buffer, len);
+ total_bytes += len;
+ }
+ }
+ stream->Flush();
+ }
+ return total_bytes;
+}
+
+// This function handles events that were broadcast by the process.
+void
+Debugger::HandleProcessEvent (const EventSP &event_sp)
+{
+ using namespace lldb;
+ const uint32_t event_type = event_sp->GetType();
+ ProcessSP process_sp = Process::ProcessEventData::GetProcessFromEvent(event_sp.get());
+
+ const bool gui_enabled = IsForwardingEvents();
+ bool top_io_handler_hid = false;
+ if (gui_enabled == false)
+ top_io_handler_hid = HideTopIOHandler();
+
+ assert (process_sp);
+
+ if (event_type & Process::eBroadcastBitSTDOUT)
+ {
+ // The process has stdout available, get it and write it out to the
+ // appropriate place.
+ if (top_io_handler_hid)
+ GetProcessSTDOUT (process_sp.get(), NULL);
+ }
+ else if (event_type & Process::eBroadcastBitSTDERR)
+ {
+ // The process has stderr available, get it and write it out to the
+ // appropriate place.
+ if (top_io_handler_hid)
+ GetProcessSTDERR (process_sp.get(), NULL);
+ }
+ else if (event_type & Process::eBroadcastBitStateChanged)
+ {
+ // Drain all stout and stderr so we don't see any output come after
+ // we print our prompts
+ if (top_io_handler_hid)
+ {
+ StreamFileSP stream_sp (GetOutputFile());
+ GetProcessSTDOUT (process_sp.get(), stream_sp.get());
+ GetProcessSTDERR (process_sp.get(), NULL);
+ // Something changed in the process; get the event and report the process's current status and location to
+ // the user.
+ StateType event_state = Process::ProcessEventData::GetStateFromEvent (event_sp.get());
+ if (event_state == eStateInvalid)
+ return;
+
+ switch (event_state)
+ {
+ case eStateInvalid:
+ case eStateUnloaded:
+ case eStateConnected:
+ case eStateAttaching:
+ case eStateLaunching:
+ case eStateStepping:
+ case eStateDetached:
+ {
+ stream_sp->Printf("Process %" PRIu64 " %s\n",
+ process_sp->GetID(),
+ StateAsCString (event_state));
+ }
+ break;
+
+ case eStateRunning:
+ // Don't be chatty when we run...
+ break;
+
+ case eStateExited:
+ process_sp->GetStatus(*stream_sp);
+ break;
+
+ case eStateStopped:
+ case eStateCrashed:
+ case eStateSuspended:
+ // Make sure the program hasn't been auto-restarted:
+ if (Process::ProcessEventData::GetRestartedFromEvent (event_sp.get()))
+ {
+ size_t num_reasons = Process::ProcessEventData::GetNumRestartedReasons(event_sp.get());
+ if (num_reasons > 0)
+ {
+ // FIXME: Do we want to report this, or would that just be annoyingly chatty?
+ if (num_reasons == 1)
+ {
+ const char *reason = Process::ProcessEventData::GetRestartedReasonAtIndex (event_sp.get(), 0);
+ stream_sp->Printf("Process %" PRIu64 " stopped and restarted: %s\n",
+ process_sp->GetID(),
+ reason ? reason : "<UNKNOWN REASON>");
+ }
+ else
+ {
+ stream_sp->Printf("Process %" PRIu64 " stopped and restarted, reasons:\n",
+ process_sp->GetID());
+
+
+ for (size_t i = 0; i < num_reasons; i++)
+ {
+ const char *reason = Process::ProcessEventData::GetRestartedReasonAtIndex (event_sp.get(), i);
+ stream_sp->Printf("\t%s\n", reason ? reason : "<UNKNOWN REASON>");
+ }
+ }
+ }
+ }
+ else
+ {
+ // Lock the thread list so it doesn't change on us
+ ThreadList &thread_list = process_sp->GetThreadList();
+ Mutex::Locker locker (thread_list.GetMutex());
+
+ ThreadSP curr_thread (thread_list.GetSelectedThread());
+ ThreadSP thread;
+ StopReason curr_thread_stop_reason = eStopReasonInvalid;
+ if (curr_thread)
+ curr_thread_stop_reason = curr_thread->GetStopReason();
+ if (!curr_thread ||
+ !curr_thread->IsValid() ||
+ curr_thread_stop_reason == eStopReasonInvalid ||
+ curr_thread_stop_reason == eStopReasonNone)
+ {
+ // Prefer a thread that has just completed its plan over another thread as current thread.
+ ThreadSP plan_thread;
+ ThreadSP other_thread;
+ const size_t num_threads = thread_list.GetSize();
+ size_t i;
+ for (i = 0; i < num_threads; ++i)
+ {
+ thread = thread_list.GetThreadAtIndex(i);
+ StopReason thread_stop_reason = thread->GetStopReason();
+ switch (thread_stop_reason)
+ {
+ case eStopReasonInvalid:
+ case eStopReasonNone:
+ break;
+
+ case eStopReasonTrace:
+ case eStopReasonBreakpoint:
+ case eStopReasonWatchpoint:
+ case eStopReasonSignal:
+ case eStopReasonException:
+ case eStopReasonExec:
+ case eStopReasonThreadExiting:
+ if (!other_thread)
+ other_thread = thread;
+ break;
+ case eStopReasonPlanComplete:
+ if (!plan_thread)
+ plan_thread = thread;
+ break;
+ }
+ }
+ if (plan_thread)
+ thread_list.SetSelectedThreadByID (plan_thread->GetID());
+ else if (other_thread)
+ thread_list.SetSelectedThreadByID (other_thread->GetID());
+ else
+ {
+ if (curr_thread && curr_thread->IsValid())
+ thread = curr_thread;
+ else
+ thread = thread_list.GetThreadAtIndex(0);
+
+ if (thread)
+ thread_list.SetSelectedThreadByID (thread->GetID());
+ }
+ }
+
+ if (GetTargetList().GetSelectedTarget().get() == &process_sp->GetTarget())
+ {
+ const bool only_threads_with_stop_reason = true;
+ const uint32_t start_frame = 0;
+ const uint32_t num_frames = 1;
+ const uint32_t num_frames_with_source = 1;
+ process_sp->GetStatus(*stream_sp);
+ process_sp->GetThreadStatus (*stream_sp,
+ only_threads_with_stop_reason,
+ start_frame,
+ num_frames,
+ num_frames_with_source);
+ }
+ else
+ {
+ uint32_t target_idx = GetTargetList().GetIndexOfTarget(process_sp->GetTarget().shared_from_this());
+ if (target_idx != UINT32_MAX)
+ stream_sp->Printf ("Target %d: (", target_idx);
+ else
+ stream_sp->Printf ("Target <unknown index>: (");
+ process_sp->GetTarget().Dump (stream_sp.get(), eDescriptionLevelBrief);
+ stream_sp->Printf (") stopped.\n");
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ if (top_io_handler_hid)
+ RefreshTopIOHandler();
+}
+
+void
+Debugger::HandleThreadEvent (const EventSP &event_sp)
+{
+ // At present the only thread event we handle is the Frame Changed event,
+ // and all we do for that is just reprint the thread status for that thread.
+ using namespace lldb;
+ const uint32_t event_type = event_sp->GetType();
+ if (event_type == Thread::eBroadcastBitStackChanged ||
+ event_type == Thread::eBroadcastBitThreadSelected )
+ {
+ ThreadSP thread_sp (Thread::ThreadEventData::GetThreadFromEvent (event_sp.get()));
+ if (thread_sp)
+ {
+ HideTopIOHandler();
+ StreamFileSP stream_sp (GetOutputFile());
+ thread_sp->GetStatus(*stream_sp, 0, 1, 1);
+ RefreshTopIOHandler();
+ }
+ }
+}
+
+bool
+Debugger::IsForwardingEvents ()
+{
+ return (bool)m_forward_listener_sp;
+}
+
+void
+Debugger::EnableForwardEvents (const ListenerSP &listener_sp)
+{
+ m_forward_listener_sp = listener_sp;
+}
+
+void
+Debugger::CancelForwardEvents (const ListenerSP &listener_sp)
+{
+ m_forward_listener_sp.reset();
+}
+
+
+void
+Debugger::DefaultEventHandler()
+{
+ Listener& listener(GetListener());
+ ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
+ ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
+ ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
+ BroadcastEventSpec target_event_spec (broadcaster_class_target,
+ Target::eBroadcastBitBreakpointChanged);
+
+ BroadcastEventSpec process_event_spec (broadcaster_class_process,
+ Process::eBroadcastBitStateChanged |
+ Process::eBroadcastBitSTDOUT |
+ Process::eBroadcastBitSTDERR);
+
+ BroadcastEventSpec thread_event_spec (broadcaster_class_thread,
+ Thread::eBroadcastBitStackChanged |
+ Thread::eBroadcastBitThreadSelected );
+
+ listener.StartListeningForEventSpec (*this, target_event_spec);
+ listener.StartListeningForEventSpec (*this, process_event_spec);
+ listener.StartListeningForEventSpec (*this, thread_event_spec);
+ listener.StartListeningForEvents (m_command_interpreter_ap.get(),
+ CommandInterpreter::eBroadcastBitQuitCommandReceived |
+ CommandInterpreter::eBroadcastBitAsynchronousOutputData |
+ CommandInterpreter::eBroadcastBitAsynchronousErrorData );
+
+ bool done = false;
+ while (!done)
+ {
+// Mutex::Locker locker;
+// if (locker.TryLock(m_input_reader_stack.GetMutex()))
+// {
+// if (m_input_reader_stack.IsEmpty())
+// break;
+// }
+//
+ EventSP event_sp;
+ if (listener.WaitForEvent(NULL, event_sp))
+ {
+ if (event_sp)
+ {
+ Broadcaster *broadcaster = event_sp->GetBroadcaster();
+ if (broadcaster)
+ {
+ uint32_t event_type = event_sp->GetType();
+ ConstString broadcaster_class (broadcaster->GetBroadcasterClass());
+ if (broadcaster_class == broadcaster_class_process)
+ {
+ HandleProcessEvent (event_sp);
+ }
+ else if (broadcaster_class == broadcaster_class_target)
+ {
+ if (Breakpoint::BreakpointEventData::GetEventDataFromEvent(event_sp.get()))
+ {
+ HandleBreakpointEvent (event_sp);
+ }
+ }
+ else if (broadcaster_class == broadcaster_class_thread)
+ {
+ HandleThreadEvent (event_sp);
+ }
+ else if (broadcaster == m_command_interpreter_ap.get())
+ {
+ if (event_type & CommandInterpreter::eBroadcastBitQuitCommandReceived)
+ {
+ done = true;
+ }
+ else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousErrorData)
+ {
+ const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
+ if (data && data[0])
+ {
+ StreamFileSP error_sp (GetErrorFile());
+ if (error_sp)
+ {
+ HideTopIOHandler();
+ error_sp->PutCString(data);
+ error_sp->Flush();
+ RefreshTopIOHandler();
+ }
+ }
+ }
+ else if (event_type & CommandInterpreter::eBroadcastBitAsynchronousOutputData)
+ {
+ const char *data = reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event_sp.get()));
+ if (data && data[0])
+ {
+ StreamFileSP output_sp (GetOutputFile());
+ if (output_sp)
+ {
+ HideTopIOHandler();
+ output_sp->PutCString(data);
+ output_sp->Flush();
+ RefreshTopIOHandler();
+ }
+ }
+ }
+ }
+ }
+
+ if (m_forward_listener_sp)
+ m_forward_listener_sp->AddEvent(event_sp);
+ }
+ }
+ }
+}
+
+lldb::thread_result_t
+Debugger::EventHandlerThread (lldb::thread_arg_t arg)
+{
+ ((Debugger *)arg)->DefaultEventHandler();
+ return NULL;
+}
+
+bool
+Debugger::StartEventHandlerThread()
+{
+ if (!IS_VALID_LLDB_HOST_THREAD(m_event_handler_thread))
+ m_event_handler_thread = Host::ThreadCreate("lldb.debugger.event-handler", EventHandlerThread, this, NULL);
+ return IS_VALID_LLDB_HOST_THREAD(m_event_handler_thread);
+}
+
+void
+Debugger::StopEventHandlerThread()
+{
+ if (IS_VALID_LLDB_HOST_THREAD(m_event_handler_thread))
+ {
+ GetCommandInterpreter().BroadcastEvent(CommandInterpreter::eBroadcastBitQuitCommandReceived);
+ Host::ThreadJoin(m_event_handler_thread, NULL, NULL);
+ m_event_handler_thread = LLDB_INVALID_HOST_THREAD;
+ }
+}
+
+
+lldb::thread_result_t
+Debugger::IOHandlerThread (lldb::thread_arg_t arg)
+{
+ Debugger *debugger = (Debugger *)arg;
+ debugger->ExecuteIOHanders();
+ debugger->StopEventHandlerThread();
+ return NULL;
+}
+
+bool
+Debugger::StartIOHandlerThread()
+{
+ if (!IS_VALID_LLDB_HOST_THREAD(m_io_handler_thread))
+ m_io_handler_thread = Host::ThreadCreate("lldb.debugger.io-handler", IOHandlerThread, this, NULL);
+ return IS_VALID_LLDB_HOST_THREAD(m_io_handler_thread);
+}
+
+void
+Debugger::StopIOHandlerThread()
+{
+ if (IS_VALID_LLDB_HOST_THREAD(m_io_handler_thread))
+ {
+ if (m_input_file_sp)
+ m_input_file_sp->GetFile().Close();
+ Host::ThreadJoin(m_io_handler_thread, NULL, NULL);
+ m_io_handler_thread = LLDB_INVALID_HOST_THREAD;
+ }
+}
+
+
diff --git a/source/Core/Disassembler.cpp b/source/Core/Disassembler.cpp
index 7f830acba1f7..1d2b8cf04c32 100644
--- a/source/Core/Disassembler.cpp
+++ b/source/Core/Disassembler.cpp
@@ -35,6 +35,7 @@
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
@@ -1044,10 +1045,8 @@ InstructionList::GetIndexOfNextBranchInstruction(uint32_t start) const
}
uint32_t
-InstructionList::GetIndexOfInstructionAtLoadAddress (lldb::addr_t load_addr, Target &target)
+InstructionList::GetIndexOfInstructionAtAddress (const Address &address)
{
- Address address;
- address.SetLoadAddress(load_addr, &target);
size_t num_instructions = m_instructions.size();
uint32_t index = UINT32_MAX;
for (size_t i = 0; i < num_instructions; i++)
@@ -1061,6 +1060,15 @@ InstructionList::GetIndexOfInstructionAtLoadAddress (lldb::addr_t load_addr, Tar
return index;
}
+
+uint32_t
+InstructionList::GetIndexOfInstructionAtLoadAddress (lldb::addr_t load_addr, Target &target)
+{
+ Address address;
+ address.SetLoadAddress(load_addr, &target);
+ return GetIndexOfInstructionAtAddress(address);
+}
+
size_t
Disassembler::ParseInstructions (const ExecutionContext *exe_ctx,
const AddressRange &range,
@@ -1235,25 +1243,25 @@ PseudoInstruction::SetOpcode (size_t opcode_size, void *opcode_data)
case 8:
{
uint8_t value8 = *((uint8_t *) opcode_data);
- m_opcode.SetOpcode8 (value8);
+ m_opcode.SetOpcode8 (value8, eByteOrderInvalid);
break;
}
case 16:
{
uint16_t value16 = *((uint16_t *) opcode_data);
- m_opcode.SetOpcode16 (value16);
+ m_opcode.SetOpcode16 (value16, eByteOrderInvalid);
break;
}
case 32:
{
uint32_t value32 = *((uint32_t *) opcode_data);
- m_opcode.SetOpcode32 (value32);
+ m_opcode.SetOpcode32 (value32, eByteOrderInvalid);
break;
}
case 64:
{
uint64_t value64 = *((uint64_t *) opcode_data);
- m_opcode.SetOpcode64 (value64);
+ m_opcode.SetOpcode64 (value64, eByteOrderInvalid);
break;
}
default:
diff --git a/source/Core/DynamicLoader.cpp b/source/Core/DynamicLoader.cpp
index 82f84048b32a..1f545b727a1e 100644
--- a/source/Core/DynamicLoader.cpp
+++ b/source/Core/DynamicLoader.cpp
@@ -10,7 +10,11 @@
#include "lldb/lldb-private.h"
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/Section.h"
using namespace lldb;
using namespace lldb_private;
@@ -74,3 +78,137 @@ DynamicLoader::SetStopWhenImagesChange (bool stop)
m_process->SetStopOnSharedLibraryEvents (stop);
}
+ModuleSP
+DynamicLoader::GetTargetExecutable()
+{
+ Target &target = m_process->GetTarget();
+ ModuleSP executable = target.GetExecutableModule();
+
+ if (executable.get())
+ {
+ if (executable->GetFileSpec().Exists())
+ {
+ ModuleSpec module_spec (executable->GetFileSpec(), executable->GetArchitecture());
+ ModuleSP module_sp (new Module (module_spec));
+
+ // Check if the executable has changed and set it to the target executable if they differ.
+ if (module_sp.get() && module_sp->GetUUID().IsValid() && executable->GetUUID().IsValid())
+ {
+ if (module_sp->GetUUID() != executable->GetUUID())
+ executable.reset();
+ }
+ else if (executable->FileHasChanged())
+ {
+ executable.reset();
+ }
+
+ if (!executable.get())
+ {
+ executable = target.GetSharedModule(module_spec);
+ if (executable.get() != target.GetExecutableModulePointer())
+ {
+ // Don't load dependent images since we are in dyld where we will know
+ // and find out about all images that are loaded
+ const bool get_dependent_images = false;
+ target.SetExecutableModule(executable, get_dependent_images);
+ }
+ }
+ }
+ }
+ return executable;
+}
+
+void
+DynamicLoader::UpdateLoadedSections(ModuleSP module, addr_t link_map_addr, addr_t base_addr)
+{
+ UpdateLoadedSectionsCommon(module, base_addr);
+}
+
+void
+DynamicLoader::UpdateLoadedSectionsCommon(ModuleSP module, addr_t base_addr)
+{
+ bool changed;
+ const bool base_addr_is_offset = true;
+ module->SetLoadAddress(m_process->GetTarget(), base_addr, base_addr_is_offset, changed);
+}
+
+void
+DynamicLoader::UnloadSections(const ModuleSP module)
+{
+ UnloadSectionsCommon(module);
+}
+
+void
+DynamicLoader::UnloadSectionsCommon(const ModuleSP module)
+{
+ Target &target = m_process->GetTarget();
+ const SectionList *sections = GetSectionListFromModule(module);
+
+ assert(sections && "SectionList missing from unloaded module.");
+
+ const size_t num_sections = sections->GetSize();
+ for (size_t i = 0; i < num_sections; ++i)
+ {
+ SectionSP section_sp (sections->GetSectionAtIndex(i));
+ target.SetSectionUnloaded(section_sp);
+ }
+}
+
+
+const SectionList *
+DynamicLoader::GetSectionListFromModule(const ModuleSP module) const
+{
+ SectionList *sections = nullptr;
+ if (module.get())
+ {
+ ObjectFile *obj_file = module->GetObjectFile();
+ if (obj_file)
+ {
+ sections = obj_file->GetSectionList();
+ }
+ }
+ return sections;
+}
+
+ModuleSP
+DynamicLoader::LoadModuleAtAddress(const FileSpec &file, addr_t link_map_addr, addr_t base_addr)
+{
+ Target &target = m_process->GetTarget();
+ ModuleList &modules = target.GetImages();
+ ModuleSP module_sp;
+
+ ModuleSpec module_spec (file, target.GetArchitecture());
+ if ((module_sp = modules.FindFirstModule (module_spec)))
+ {
+ UpdateLoadedSections(module_sp, link_map_addr, base_addr);
+ }
+ else if ((module_sp = target.GetSharedModule(module_spec)))
+ {
+ UpdateLoadedSections(module_sp, link_map_addr, base_addr);
+ }
+
+ return module_sp;
+}
+
+int64_t
+DynamicLoader::ReadUnsignedIntWithSizeInBytes(addr_t addr, int size_in_bytes)
+{
+ Error error;
+
+ uint64_t value = m_process->ReadUnsignedIntegerFromMemory(addr, size_in_bytes, 0, error);
+ if (error.Fail())
+ return -1;
+ else
+ return (int64_t)value;
+}
+
+addr_t
+DynamicLoader::ReadPointer(addr_t addr)
+{
+ Error error;
+ addr_t value = m_process->ReadPointerFromMemory(addr, error);
+ if (error.Fail())
+ return LLDB_INVALID_ADDRESS;
+ else
+ return value;
+}
diff --git a/source/Core/IOHandler.cpp b/source/Core/IOHandler.cpp
new file mode 100644
index 000000000000..bdec19ccb06f
--- /dev/null
+++ b/source/Core/IOHandler.cpp
@@ -0,0 +1,5294 @@
+//===-- IOHandler.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "lldb/lldb-python.h"
+
+#include <string>
+
+#include "lldb/Breakpoint/BreakpointLocation.h"
+#include "lldb/Core/IOHandler.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/State.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Core/ValueObjectRegister.h"
+#include "lldb/Host/Editline.h"
+#include "lldb/Interpreter/CommandCompletions.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/Symbol.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/ThreadPlan.h"
+
+#ifndef LLDB_DISABLE_CURSES
+#include <ncurses.h>
+#include <panel.h>
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+
+IOHandler::IOHandler (Debugger &debugger) :
+ IOHandler (debugger,
+ StreamFileSP(), // Adopt STDIN from top input reader
+ StreamFileSP(), // Adopt STDOUT from top input reader
+ StreamFileSP(), // Adopt STDERR from top input reader
+ 0) // Flags
+{
+}
+
+
+IOHandler::IOHandler (Debugger &debugger,
+ const lldb::StreamFileSP &input_sp,
+ const lldb::StreamFileSP &output_sp,
+ const lldb::StreamFileSP &error_sp,
+ uint32_t flags) :
+ m_debugger (debugger),
+ m_input_sp (input_sp),
+ m_output_sp (output_sp),
+ m_error_sp (error_sp),
+ m_flags (flags),
+ m_user_data (NULL),
+ m_done (false),
+ m_active (false)
+{
+ // If any files are not specified, then adopt them from the top input reader.
+ if (!m_input_sp || !m_output_sp || !m_error_sp)
+ debugger.AdoptTopIOHandlerFilesIfInvalid (m_input_sp,
+ m_output_sp,
+ m_error_sp);
+}
+
+IOHandler::~IOHandler()
+{
+}
+
+
+int
+IOHandler::GetInputFD()
+{
+ if (m_input_sp)
+ return m_input_sp->GetFile().GetDescriptor();
+ return -1;
+}
+
+int
+IOHandler::GetOutputFD()
+{
+ if (m_output_sp)
+ return m_output_sp->GetFile().GetDescriptor();
+ return -1;
+}
+
+int
+IOHandler::GetErrorFD()
+{
+ if (m_error_sp)
+ return m_error_sp->GetFile().GetDescriptor();
+ return -1;
+}
+
+FILE *
+IOHandler::GetInputFILE()
+{
+ if (m_input_sp)
+ return m_input_sp->GetFile().GetStream();
+ return NULL;
+}
+
+FILE *
+IOHandler::GetOutputFILE()
+{
+ if (m_output_sp)
+ return m_output_sp->GetFile().GetStream();
+ return NULL;
+}
+
+FILE *
+IOHandler::GetErrorFILE()
+{
+ if (m_error_sp)
+ return m_error_sp->GetFile().GetStream();
+ return NULL;
+}
+
+StreamFileSP &
+IOHandler::GetInputStreamFile()
+{
+ return m_input_sp;
+}
+
+StreamFileSP &
+IOHandler::GetOutputStreamFile()
+{
+ return m_output_sp;
+}
+
+
+StreamFileSP &
+IOHandler::GetErrorStreamFile()
+{
+ return m_error_sp;
+}
+
+bool
+IOHandler::GetIsInteractive ()
+{
+ return GetInputStreamFile()->GetFile().GetIsInteractive ();
+}
+
+bool
+IOHandler::GetIsRealTerminal ()
+{
+ return GetInputStreamFile()->GetFile().GetIsRealTerminal();
+}
+
+IOHandlerConfirm::IOHandlerConfirm (Debugger &debugger,
+ const char *prompt,
+ bool default_response) :
+ IOHandlerEditline(debugger,
+ NULL, // NULL editline_name means no history loaded/saved
+ NULL,
+ false, // Multi-line
+ *this),
+ m_default_response (default_response),
+ m_user_response (default_response)
+{
+ StreamString prompt_stream;
+ prompt_stream.PutCString(prompt);
+ if (m_default_response)
+ prompt_stream.Printf(": [Y/n] ");
+ else
+ prompt_stream.Printf(": [y/N] ");
+
+ SetPrompt (prompt_stream.GetString().c_str());
+
+}
+
+
+IOHandlerConfirm::~IOHandlerConfirm ()
+{
+}
+
+int
+IOHandlerConfirm::IOHandlerComplete (IOHandler &io_handler,
+ const char *current_line,
+ const char *cursor,
+ const char *last_char,
+ int skip_first_n_matches,
+ int max_matches,
+ StringList &matches)
+{
+ if (current_line == cursor)
+ {
+ if (m_default_response)
+ {
+ matches.AppendString("y");
+ }
+ else
+ {
+ matches.AppendString("n");
+ }
+ }
+ return matches.GetSize();
+}
+
+void
+IOHandlerConfirm::IOHandlerInputComplete (IOHandler &io_handler, std::string &line)
+{
+ if (line.empty())
+ {
+ // User just hit enter, set the response to the default
+ m_user_response = m_default_response;
+ io_handler.SetIsDone(true);
+ return;
+ }
+
+ if (line.size() == 1)
+ {
+ switch (line[0])
+ {
+ case 'y':
+ case 'Y':
+ m_user_response = true;
+ io_handler.SetIsDone(true);
+ return;
+ case 'n':
+ case 'N':
+ m_user_response = false;
+ io_handler.SetIsDone(true);
+ return;
+ default:
+ break;
+ }
+ }
+
+ if (line == "yes" || line == "YES" || line == "Yes")
+ {
+ m_user_response = true;
+ io_handler.SetIsDone(true);
+ }
+ else if (line == "no" || line == "NO" || line == "No")
+ {
+ m_user_response = false;
+ io_handler.SetIsDone(true);
+ }
+}
+
+int
+IOHandlerDelegate::IOHandlerComplete (IOHandler &io_handler,
+ const char *current_line,
+ const char *cursor,
+ const char *last_char,
+ int skip_first_n_matches,
+ int max_matches,
+ StringList &matches)
+{
+ switch (m_completion)
+ {
+ case Completion::None:
+ break;
+
+ case Completion::LLDBCommand:
+ return io_handler.GetDebugger().GetCommandInterpreter().HandleCompletion (current_line,
+ cursor,
+ last_char,
+ skip_first_n_matches,
+ max_matches,
+ matches);
+
+ case Completion::Expression:
+ {
+ bool word_complete = false;
+ const char *word_start = cursor;
+ if (cursor > current_line)
+ --word_start;
+ while (word_start > current_line && !isspace(*word_start))
+ --word_start;
+ CommandCompletions::InvokeCommonCompletionCallbacks (io_handler.GetDebugger().GetCommandInterpreter(),
+ CommandCompletions::eVariablePathCompletion,
+ word_start,
+ skip_first_n_matches,
+ max_matches,
+ NULL,
+ word_complete,
+ matches);
+
+ size_t num_matches = matches.GetSize();
+ if (num_matches > 0)
+ {
+ std::string common_prefix;
+ matches.LongestCommonPrefix (common_prefix);
+ const size_t partial_name_len = strlen(word_start);
+
+ // If we matched a unique single command, add a space...
+ // Only do this if the completer told us this was a complete word, however...
+ if (num_matches == 1 && word_complete)
+ {
+ common_prefix.push_back(' ');
+ }
+ common_prefix.erase (0, partial_name_len);
+ matches.InsertStringAtIndex(0, std::move(common_prefix));
+ }
+ return num_matches;
+ }
+ break;
+ }
+
+
+ return 0;
+}
+
+
+IOHandlerEditline::IOHandlerEditline (Debugger &debugger,
+ const char *editline_name, // Used for saving history files
+ const char *prompt,
+ bool multi_line,
+ IOHandlerDelegate &delegate) :
+ IOHandlerEditline(debugger,
+ StreamFileSP(), // Inherit input from top input reader
+ StreamFileSP(), // Inherit output from top input reader
+ StreamFileSP(), // Inherit error from top input reader
+ 0, // Flags
+ editline_name, // Used for saving history files
+ prompt,
+ multi_line,
+ delegate)
+{
+}
+
+IOHandlerEditline::IOHandlerEditline (Debugger &debugger,
+ const lldb::StreamFileSP &input_sp,
+ const lldb::StreamFileSP &output_sp,
+ const lldb::StreamFileSP &error_sp,
+ uint32_t flags,
+ const char *editline_name, // Used for saving history files
+ const char *prompt,
+ bool multi_line,
+ IOHandlerDelegate &delegate) :
+ IOHandler (debugger, input_sp, output_sp, error_sp, flags),
+ m_editline_ap (),
+ m_delegate (delegate),
+ m_prompt (),
+ m_multi_line (multi_line)
+{
+ SetPrompt(prompt);
+
+ bool use_editline = false;
+
+#ifndef _MSC_VER
+ use_editline = m_input_sp->GetFile().GetIsRealTerminal();
+#else
+ use_editline = true;
+#endif
+
+ if (use_editline)
+ {
+ m_editline_ap.reset(new Editline (editline_name,
+ prompt ? prompt : "",
+ GetInputFILE (),
+ GetOutputFILE (),
+ GetErrorFILE ()));
+ m_editline_ap->SetLineCompleteCallback (LineCompletedCallback, this);
+ m_editline_ap->SetAutoCompleteCallback (AutoCompleteCallback, this);
+ }
+
+}
+
+IOHandlerEditline::~IOHandlerEditline ()
+{
+ m_editline_ap.reset();
+}
+
+
+bool
+IOHandlerEditline::GetLine (std::string &line)
+{
+ if (m_editline_ap)
+ {
+ return m_editline_ap->GetLine(line).Success();
+ }
+ else
+ {
+ line.clear();
+
+ FILE *in = GetInputFILE();
+ if (in)
+ {
+ if (GetIsInteractive())
+ {
+ const char *prompt = GetPrompt();
+ if (prompt && prompt[0])
+ {
+ FILE *out = GetOutputFILE();
+ if (out)
+ {
+ ::fprintf(out, "%s", prompt);
+ ::fflush(out);
+ }
+ }
+ }
+ char buffer[256];
+ bool done = false;
+ bool got_line = false;
+ while (!done)
+ {
+ if (fgets(buffer, sizeof(buffer), in) == NULL)
+ done = true;
+ else
+ {
+ got_line = true;
+ size_t buffer_len = strlen(buffer);
+ assert (buffer[buffer_len] == '\0');
+ char last_char = buffer[buffer_len-1];
+ if (last_char == '\r' || last_char == '\n')
+ {
+ done = true;
+ // Strip trailing newlines
+ while (last_char == '\r' || last_char == '\n')
+ {
+ --buffer_len;
+ if (buffer_len == 0)
+ break;
+ last_char = buffer[buffer_len-1];
+ }
+ }
+ line.append(buffer, buffer_len);
+ }
+ }
+ // We might have gotten a newline on a line by itself
+ // make sure to return true in this case.
+ return got_line;
+ }
+ else
+ {
+ // No more input file, we are done...
+ SetIsDone(true);
+ }
+ return false;
+ }
+}
+
+
+LineStatus
+IOHandlerEditline::LineCompletedCallback (Editline *editline,
+ StringList &lines,
+ uint32_t line_idx,
+ Error &error,
+ void *baton)
+{
+ IOHandlerEditline *editline_reader = (IOHandlerEditline *) baton;
+ return editline_reader->m_delegate.IOHandlerLinesUpdated(*editline_reader, lines, line_idx, error);
+}
+
+int
+IOHandlerEditline::AutoCompleteCallback (const char *current_line,
+ const char *cursor,
+ const char *last_char,
+ int skip_first_n_matches,
+ int max_matches,
+ StringList &matches,
+ void *baton)
+{
+ IOHandlerEditline *editline_reader = (IOHandlerEditline *) baton;
+ if (editline_reader)
+ return editline_reader->m_delegate.IOHandlerComplete (*editline_reader,
+ current_line,
+ cursor,
+ last_char,
+ skip_first_n_matches,
+ max_matches,
+ matches);
+ return 0;
+}
+
+const char *
+IOHandlerEditline::GetPrompt ()
+{
+ if (m_editline_ap)
+ return m_editline_ap->GetPrompt ();
+ else if (m_prompt.empty())
+ return NULL;
+ return m_prompt.c_str();
+}
+
+bool
+IOHandlerEditline::SetPrompt (const char *p)
+{
+ if (p && p[0])
+ m_prompt = p;
+ else
+ m_prompt.clear();
+ if (m_editline_ap)
+ m_editline_ap->SetPrompt (m_prompt.empty() ? NULL : m_prompt.c_str());
+ return true;
+}
+
+bool
+IOHandlerEditline::GetLines (StringList &lines)
+{
+ bool success = false;
+ if (m_editline_ap)
+ {
+ std::string end_token;
+ success = m_editline_ap->GetLines(end_token, lines).Success();
+ }
+ else
+ {
+ LineStatus lines_status = LineStatus::Success;
+
+ while (lines_status == LineStatus::Success)
+ {
+ std::string line;
+ if (GetLine(line))
+ {
+ lines.AppendString(line);
+ Error error;
+ lines_status = m_delegate.IOHandlerLinesUpdated(*this, lines, lines.GetSize() - 1, error);
+ }
+ else
+ {
+ lines_status = LineStatus::Done;
+ }
+ }
+ success = lines.GetSize() > 0;
+ }
+ return success;
+}
+
+// Each IOHandler gets to run until it is done. It should read data
+// from the "in" and place output into "out" and "err and return
+// when done.
+void
+IOHandlerEditline::Run ()
+{
+ std::string line;
+ while (IsActive())
+ {
+ if (m_multi_line)
+ {
+ StringList lines;
+ if (GetLines (lines))
+ {
+ line = lines.CopyList();
+ m_delegate.IOHandlerInputComplete(*this, line);
+ }
+ else
+ {
+ m_done = true;
+ }
+ }
+ else
+ {
+ if (GetLine(line))
+ {
+ m_delegate.IOHandlerInputComplete(*this, line);
+ }
+ else
+ {
+ m_done = true;
+ }
+ }
+ }
+}
+
+void
+IOHandlerEditline::Hide ()
+{
+ if (m_editline_ap && m_editline_ap->GettingLine())
+ m_editline_ap->Hide();
+}
+
+
+void
+IOHandlerEditline::Refresh ()
+{
+ if (m_editline_ap && m_editline_ap->GettingLine())
+ m_editline_ap->Refresh();
+ else
+ {
+ const char *prompt = GetPrompt();
+ if (prompt && prompt[0])
+ {
+ FILE *out = GetOutputFILE();
+ if (out)
+ {
+ ::fprintf(out, "%s", prompt);
+ ::fflush(out);
+ }
+ }
+ }
+}
+
+void
+IOHandlerEditline::Interrupt ()
+{
+ if (m_editline_ap)
+ m_editline_ap->Interrupt();
+}
+
+void
+IOHandlerEditline::GotEOF()
+{
+ if (m_editline_ap)
+ m_editline_ap->Interrupt();
+}
+
+// we may want curses to be disabled for some builds
+// for instance, windows
+#ifndef LLDB_DISABLE_CURSES
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/StackFrame.h"
+
+#define KEY_RETURN 10
+#define KEY_ESCAPE 27
+
+namespace curses
+{
+ class Menu;
+ class MenuDelegate;
+ class Window;
+ class WindowDelegate;
+ typedef std::shared_ptr<Menu> MenuSP;
+ typedef std::shared_ptr<MenuDelegate> MenuDelegateSP;
+ typedef std::shared_ptr<Window> WindowSP;
+ typedef std::shared_ptr<WindowDelegate> WindowDelegateSP;
+ typedef std::vector<MenuSP> Menus;
+ typedef std::vector<WindowSP> Windows;
+ typedef std::vector<WindowDelegateSP> WindowDelegates;
+
+#if 0
+type summary add -s "x=${var.x}, y=${var.y}" curses::Point
+type summary add -s "w=${var.width}, h=${var.height}" curses::Size
+type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
+#endif
+ struct Point
+ {
+ int x;
+ int y;
+
+ Point (int _x = 0, int _y = 0) :
+ x(_x),
+ y(_y)
+ {
+ }
+
+ void
+ Clear ()
+ {
+ x = 0;
+ y = 0;
+ }
+
+ Point &
+ operator += (const Point &rhs)
+ {
+ x += rhs.x;
+ y += rhs.y;
+ return *this;
+ }
+
+ void
+ Dump ()
+ {
+ printf ("(x=%i, y=%i)\n", x, y);
+ }
+
+ };
+
+ bool operator == (const Point &lhs, const Point &rhs)
+ {
+ return lhs.x == rhs.x && lhs.y == rhs.y;
+ }
+ bool operator != (const Point &lhs, const Point &rhs)
+ {
+ return lhs.x != rhs.x || lhs.y != rhs.y;
+ }
+
+ struct Size
+ {
+ int width;
+ int height;
+ Size (int w = 0, int h = 0) :
+ width (w),
+ height (h)
+ {
+ }
+
+ void
+ Clear ()
+ {
+ width = 0;
+ height = 0;
+ }
+
+ void
+ Dump ()
+ {
+ printf ("(w=%i, h=%i)\n", width, height);
+ }
+
+ };
+
+ bool operator == (const Size &lhs, const Size &rhs)
+ {
+ return lhs.width == rhs.width && lhs.height == rhs.height;
+ }
+ bool operator != (const Size &lhs, const Size &rhs)
+ {
+ return lhs.width != rhs.width || lhs.height != rhs.height;
+ }
+
+ struct Rect
+ {
+ Point origin;
+ Size size;
+
+ Rect () :
+ origin(),
+ size()
+ {
+ }
+
+ Rect (const Point &p, const Size &s) :
+ origin (p),
+ size (s)
+ {
+ }
+
+ void
+ Clear ()
+ {
+ origin.Clear();
+ size.Clear();
+ }
+
+ void
+ Dump ()
+ {
+ printf ("(x=%i, y=%i), w=%i, h=%i)\n", origin.x, origin.y, size.width, size.height);
+ }
+
+ void
+ Inset (int w, int h)
+ {
+ if (size.width > w*2)
+ size.width -= w*2;
+ origin.x += w;
+
+ if (size.height > h*2)
+ size.height -= h*2;
+ origin.y += h;
+ }
+ // Return a status bar rectangle which is the last line of
+ // this rectangle. This rectangle will be modified to not
+ // include the status bar area.
+ Rect
+ MakeStatusBar ()
+ {
+ Rect status_bar;
+ if (size.height > 1)
+ {
+ status_bar.origin.x = origin.x;
+ status_bar.origin.y = size.height;
+ status_bar.size.width = size.width;
+ status_bar.size.height = 1;
+ --size.height;
+ }
+ return status_bar;
+ }
+
+ // Return a menubar rectangle which is the first line of
+ // this rectangle. This rectangle will be modified to not
+ // include the menubar area.
+ Rect
+ MakeMenuBar ()
+ {
+ Rect menubar;
+ if (size.height > 1)
+ {
+ menubar.origin.x = origin.x;
+ menubar.origin.y = origin.y;
+ menubar.size.width = size.width;
+ menubar.size.height = 1;
+ ++origin.y;
+ --size.height;
+ }
+ return menubar;
+ }
+
+ void
+ HorizontalSplitPercentage (float top_percentage, Rect &top, Rect &bottom) const
+ {
+ float top_height = top_percentage * size.height;
+ HorizontalSplit (top_height, top, bottom);
+ }
+
+ void
+ HorizontalSplit (int top_height, Rect &top, Rect &bottom) const
+ {
+ top = *this;
+ if (top_height < size.height)
+ {
+ top.size.height = top_height;
+ bottom.origin.x = origin.x;
+ bottom.origin.y = origin.y + top.size.height;
+ bottom.size.width = size.width;
+ bottom.size.height = size.height - top.size.height;
+ }
+ else
+ {
+ bottom.Clear();
+ }
+ }
+
+ void
+ VerticalSplitPercentage (float left_percentage, Rect &left, Rect &right) const
+ {
+ float left_width = left_percentage * size.width;
+ VerticalSplit (left_width, left, right);
+ }
+
+
+ void
+ VerticalSplit (int left_width, Rect &left, Rect &right) const
+ {
+ left = *this;
+ if (left_width < size.width)
+ {
+ left.size.width = left_width;
+ right.origin.x = origin.x + left.size.width;
+ right.origin.y = origin.y;
+ right.size.width = size.width - left.size.width;
+ right.size.height = size.height;
+ }
+ else
+ {
+ right.Clear();
+ }
+ }
+ };
+
+ bool operator == (const Rect &lhs, const Rect &rhs)
+ {
+ return lhs.origin == rhs.origin && lhs.size == rhs.size;
+ }
+ bool operator != (const Rect &lhs, const Rect &rhs)
+ {
+ return lhs.origin != rhs.origin || lhs.size != rhs.size;
+ }
+
+ enum HandleCharResult
+ {
+ eKeyNotHandled = 0,
+ eKeyHandled = 1,
+ eQuitApplication = 2
+ };
+
+ enum class MenuActionResult
+ {
+ Handled,
+ NotHandled,
+ Quit // Exit all menus and quit
+ };
+
+ struct KeyHelp
+ {
+ int ch;
+ const char *description;
+ };
+
+ class WindowDelegate
+ {
+ public:
+ virtual
+ ~WindowDelegate()
+ {
+ }
+
+ virtual bool
+ WindowDelegateDraw (Window &window, bool force)
+ {
+ return false; // Drawing not handled
+ }
+
+ virtual HandleCharResult
+ WindowDelegateHandleChar (Window &window, int key)
+ {
+ return eKeyNotHandled;
+ }
+
+ virtual const char *
+ WindowDelegateGetHelpText ()
+ {
+ return NULL;
+ }
+
+ virtual KeyHelp *
+ WindowDelegateGetKeyHelp ()
+ {
+ return NULL;
+ }
+ };
+
+ class HelpDialogDelegate :
+ public WindowDelegate
+ {
+ public:
+ HelpDialogDelegate (const char *text, KeyHelp *key_help_array);
+
+ virtual
+ ~HelpDialogDelegate();
+
+ virtual bool
+ WindowDelegateDraw (Window &window, bool force);
+
+ virtual HandleCharResult
+ WindowDelegateHandleChar (Window &window, int key);
+
+ size_t
+ GetNumLines() const
+ {
+ return m_text.GetSize();
+ }
+
+ size_t
+ GetMaxLineLength () const
+ {
+ return m_text.GetMaxStringLength();
+ }
+
+ protected:
+ StringList m_text;
+ int m_first_visible_line;
+ };
+
+
+ class Window
+ {
+ public:
+
+ Window (const char *name) :
+ m_name (name),
+ m_window (NULL),
+ m_panel (NULL),
+ m_parent (NULL),
+ m_subwindows (),
+ m_delegate_sp (),
+ m_curr_active_window_idx (UINT32_MAX),
+ m_prev_active_window_idx (UINT32_MAX),
+ m_delete (false),
+ m_needs_update (true),
+ m_can_activate (true),
+ m_is_subwin (false)
+ {
+ }
+
+ Window (const char *name, WINDOW *w, bool del = true) :
+ m_name (name),
+ m_window (NULL),
+ m_panel (NULL),
+ m_parent (NULL),
+ m_subwindows (),
+ m_delegate_sp (),
+ m_curr_active_window_idx (UINT32_MAX),
+ m_prev_active_window_idx (UINT32_MAX),
+ m_delete (del),
+ m_needs_update (true),
+ m_can_activate (true),
+ m_is_subwin (false)
+ {
+ if (w)
+ Reset(w);
+ }
+
+ Window (const char *name, const Rect &bounds) :
+ m_name (name),
+ m_window (NULL),
+ m_parent (NULL),
+ m_subwindows (),
+ m_delegate_sp (),
+ m_curr_active_window_idx (UINT32_MAX),
+ m_prev_active_window_idx (UINT32_MAX),
+ m_delete (true),
+ m_needs_update (true),
+ m_can_activate (true),
+ m_is_subwin (false)
+ {
+ Reset (::newwin (bounds.size.height, bounds.size.width, bounds.origin.y, bounds.origin.y));
+ }
+
+ virtual
+ ~Window ()
+ {
+ RemoveSubWindows ();
+ Reset ();
+ }
+
+ void
+ Reset (WINDOW *w = NULL, bool del = true)
+ {
+ if (m_window == w)
+ return;
+
+ if (m_panel)
+ {
+ ::del_panel (m_panel);
+ m_panel = NULL;
+ }
+ if (m_window && m_delete)
+ {
+ ::delwin (m_window);
+ m_window = NULL;
+ m_delete = false;
+ }
+ if (w)
+ {
+ m_window = w;
+ m_panel = ::new_panel (m_window);
+ m_delete = del;
+ }
+ }
+
+ void AttributeOn (attr_t attr) { ::wattron (m_window, attr); }
+ void AttributeOff (attr_t attr) { ::wattroff (m_window, attr); }
+ void Box (chtype v_char = ACS_VLINE, chtype h_char = ACS_HLINE) { ::box(m_window, v_char, h_char); }
+ void Clear () { ::wclear (m_window); }
+ void Erase () { ::werase (m_window); }
+ Rect GetBounds () { return Rect (GetParentOrigin(), GetSize()); } // Get the rectangle in our parent window
+ int GetChar () { return ::wgetch (m_window); }
+ int GetCursorX () { return getcurx (m_window); }
+ int GetCursorY () { return getcury (m_window); }
+ Rect GetFrame () { return Rect (Point(), GetSize()); } // Get our rectangle in our own coordinate system
+ Point GetParentOrigin() { return Point (GetParentX(), GetParentY()); }
+ Size GetSize() { return Size (GetWidth(), GetHeight()); }
+ int GetParentX () { return getparx (m_window); }
+ int GetParentY () { return getpary (m_window); }
+ int GetMaxX() { return getmaxx (m_window); }
+ int GetMaxY() { return getmaxy (m_window); }
+ int GetWidth() { return GetMaxX(); }
+ int GetHeight() { return GetMaxY(); }
+ void MoveCursor (int x, int y) { ::wmove (m_window, y, x); }
+ void MoveWindow (int x, int y) { MoveWindow(Point(x,y)); }
+ void Resize (int w, int h) { ::wresize(m_window, h, w); }
+ void Resize (const Size &size) { ::wresize(m_window, size.height, size.width); }
+ void PutChar (int ch) { ::waddch (m_window, ch); }
+ void PutCString (const char *s, int len = -1) { ::waddnstr (m_window, s, len); }
+ void Refresh () { ::wrefresh (m_window); }
+ void DeferredRefresh ()
+ {
+ // We are using panels, so we don't need to call this...
+ //::wnoutrefresh(m_window);
+ }
+ void SetBackground (int color_pair_idx) { ::wbkgd (m_window,COLOR_PAIR(color_pair_idx)); }
+ void UnderlineOn () { AttributeOn(A_UNDERLINE); }
+ void UnderlineOff () { AttributeOff(A_UNDERLINE); }
+
+ void PutCStringTruncated (const char *s, int right_pad)
+ {
+ int bytes_left = GetWidth() - GetCursorX();
+ if (bytes_left > right_pad)
+ {
+ bytes_left -= right_pad;
+ ::waddnstr (m_window, s, bytes_left);
+ }
+ }
+
+ void
+ MoveWindow (const Point &origin)
+ {
+ const bool moving_window = origin != GetParentOrigin();
+ if (m_is_subwin && moving_window)
+ {
+ // Can't move subwindows, must delete and re-create
+ Size size = GetSize();
+ Reset (::subwin (m_parent->m_window,
+ size.height,
+ size.width,
+ origin.y,
+ origin.x), true);
+ }
+ else
+ {
+ ::mvwin (m_window, origin.y, origin.x);
+ }
+ }
+
+ void
+ SetBounds (const Rect &bounds)
+ {
+ const bool moving_window = bounds.origin != GetParentOrigin();
+ if (m_is_subwin && moving_window)
+ {
+ // Can't move subwindows, must delete and re-create
+ Reset (::subwin (m_parent->m_window,
+ bounds.size.height,
+ bounds.size.width,
+ bounds.origin.y,
+ bounds.origin.x), true);
+ }
+ else
+ {
+ if (moving_window)
+ MoveWindow(bounds.origin);
+ Resize (bounds.size);
+ }
+ }
+
+ void
+ Printf (const char *format, ...) __attribute__ ((format (printf, 2, 3)))
+ {
+ va_list args;
+ va_start (args, format);
+ vwprintw(m_window, format, args);
+ va_end (args);
+ }
+
+ void
+ Touch ()
+ {
+ ::touchwin (m_window);
+ if (m_parent)
+ m_parent->Touch();
+ }
+
+ WindowSP
+ CreateSubWindow (const char *name, const Rect &bounds, bool make_active)
+ {
+ WindowSP subwindow_sp;
+ if (m_window)
+ {
+ subwindow_sp.reset(new Window(name, ::subwin (m_window,
+ bounds.size.height,
+ bounds.size.width,
+ bounds.origin.y,
+ bounds.origin.x), true));
+ subwindow_sp->m_is_subwin = true;
+ }
+ else
+ {
+ subwindow_sp.reset(new Window(name, ::newwin (bounds.size.height,
+ bounds.size.width,
+ bounds.origin.y,
+ bounds.origin.x), true));
+ subwindow_sp->m_is_subwin = false;
+ }
+ subwindow_sp->m_parent = this;
+ if (make_active)
+ {
+ m_prev_active_window_idx = m_curr_active_window_idx;
+ m_curr_active_window_idx = m_subwindows.size();
+ }
+ m_subwindows.push_back(subwindow_sp);
+ ::top_panel (subwindow_sp->m_panel);
+ m_needs_update = true;
+ return subwindow_sp;
+ }
+
+ bool
+ RemoveSubWindow (Window *window)
+ {
+ Windows::iterator pos, end = m_subwindows.end();
+ size_t i = 0;
+ for (pos = m_subwindows.begin(); pos != end; ++pos, ++i)
+ {
+ if ((*pos).get() == window)
+ {
+ if (m_prev_active_window_idx == i)
+ m_prev_active_window_idx = UINT32_MAX;
+ else if (m_prev_active_window_idx != UINT32_MAX && m_prev_active_window_idx > i)
+ --m_prev_active_window_idx;
+
+ if (m_curr_active_window_idx == i)
+ m_curr_active_window_idx = UINT32_MAX;
+ else if (m_curr_active_window_idx != UINT32_MAX && m_curr_active_window_idx > i)
+ --m_curr_active_window_idx;
+ window->Erase();
+ m_subwindows.erase(pos);
+ m_needs_update = true;
+ if (m_parent)
+ m_parent->Touch();
+ else
+ ::touchwin (stdscr);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ WindowSP
+ FindSubWindow (const char *name)
+ {
+ Windows::iterator pos, end = m_subwindows.end();
+ size_t i = 0;
+ for (pos = m_subwindows.begin(); pos != end; ++pos, ++i)
+ {
+ if ((*pos)->m_name.compare(name) == 0)
+ return *pos;
+ }
+ return WindowSP();
+ }
+
+ void
+ RemoveSubWindows ()
+ {
+ m_curr_active_window_idx = UINT32_MAX;
+ m_prev_active_window_idx = UINT32_MAX;
+ for (Windows::iterator pos = m_subwindows.begin();
+ pos != m_subwindows.end();
+ pos = m_subwindows.erase(pos))
+ {
+ (*pos)->Erase();
+ }
+ if (m_parent)
+ m_parent->Touch();
+ else
+ ::touchwin (stdscr);
+ }
+
+ WINDOW *
+ get()
+ {
+ return m_window;
+ }
+
+ operator WINDOW *()
+ {
+ return m_window;
+ }
+
+ //----------------------------------------------------------------------
+ // Window drawing utilities
+ //----------------------------------------------------------------------
+ void
+ DrawTitleBox (const char *title, const char *bottom_message = NULL)
+ {
+ attr_t attr = 0;
+ if (IsActive())
+ attr = A_BOLD | COLOR_PAIR(2);
+ else
+ attr = 0;
+ if (attr)
+ AttributeOn(attr);
+
+ Box();
+ MoveCursor(3, 0);
+
+ if (title && title[0])
+ {
+ PutChar ('<');
+ PutCString (title);
+ PutChar ('>');
+ }
+
+ if (bottom_message && bottom_message[0])
+ {
+ int bottom_message_length = strlen(bottom_message);
+ int x = GetWidth() - 3 - (bottom_message_length + 2);
+
+ if (x > 0)
+ {
+ MoveCursor (x, GetHeight() - 1);
+ PutChar ('[');
+ PutCString(bottom_message);
+ PutChar (']');
+ }
+ else
+ {
+ MoveCursor (1, GetHeight() - 1);
+ PutChar ('[');
+ PutCStringTruncated (bottom_message, 1);
+ }
+ }
+ if (attr)
+ AttributeOff(attr);
+
+ }
+
+ virtual void
+ Draw (bool force)
+ {
+ if (m_delegate_sp && m_delegate_sp->WindowDelegateDraw (*this, force))
+ return;
+
+ for (auto &subwindow_sp : m_subwindows)
+ subwindow_sp->Draw(force);
+ }
+
+ bool
+ CreateHelpSubwindow ()
+ {
+ if (m_delegate_sp)
+ {
+ const char *text = m_delegate_sp->WindowDelegateGetHelpText ();
+ KeyHelp *key_help = m_delegate_sp->WindowDelegateGetKeyHelp ();
+ if ((text && text[0]) || key_help)
+ {
+ std::auto_ptr<HelpDialogDelegate> help_delegate_ap(new HelpDialogDelegate(text, key_help));
+ const size_t num_lines = help_delegate_ap->GetNumLines();
+ const size_t max_length = help_delegate_ap->GetMaxLineLength();
+ Rect bounds = GetBounds();
+ bounds.Inset(1, 1);
+ if (max_length + 4 < bounds.size.width)
+ {
+ bounds.origin.x += (bounds.size.width - max_length + 4)/2;
+ bounds.size.width = max_length + 4;
+ }
+ else
+ {
+ if (bounds.size.width > 100)
+ {
+ const int inset_w = bounds.size.width / 4;
+ bounds.origin.x += inset_w;
+ bounds.size.width -= 2*inset_w;
+ }
+ }
+
+ if (num_lines + 2 < bounds.size.height)
+ {
+ bounds.origin.y += (bounds.size.height - num_lines + 2)/2;
+ bounds.size.height = num_lines + 2;
+ }
+ else
+ {
+ if (bounds.size.height > 100)
+ {
+ const int inset_h = bounds.size.height / 4;
+ bounds.origin.y += inset_h;
+ bounds.size.height -= 2*inset_h;
+ }
+ }
+ WindowSP help_window_sp;
+ Window *parent_window = GetParent();
+ if (parent_window)
+ help_window_sp = parent_window->CreateSubWindow("Help", bounds, true);
+ else
+ help_window_sp = CreateSubWindow("Help", bounds, true);
+ help_window_sp->SetDelegate(WindowDelegateSP(help_delegate_ap.release()));
+ return true;
+ }
+ }
+ return false;
+ }
+
+ virtual HandleCharResult
+ HandleChar (int key)
+ {
+ // Always check the active window first
+ HandleCharResult result = eKeyNotHandled;
+ WindowSP active_window_sp = GetActiveWindow ();
+ if (active_window_sp)
+ {
+ result = active_window_sp->HandleChar (key);
+ if (result != eKeyNotHandled)
+ return result;
+ }
+
+ if (m_delegate_sp)
+ {
+ result = m_delegate_sp->WindowDelegateHandleChar (*this, key);
+ if (result != eKeyNotHandled)
+ return result;
+ }
+
+ // Then check for any windows that want any keys
+ // that weren't handled. This is typically only
+ // for a menubar.
+ // Make a copy of the subwindows in case any HandleChar()
+ // functions muck with the subwindows. If we don't do this,
+ // we can crash when iterating over the subwindows.
+ Windows subwindows (m_subwindows);
+ for (auto subwindow_sp : subwindows)
+ {
+ if (subwindow_sp->m_can_activate == false)
+ {
+ HandleCharResult result = subwindow_sp->HandleChar(key);
+ if (result != eKeyNotHandled)
+ return result;
+ }
+ }
+
+ return eKeyNotHandled;
+ }
+
+ bool
+ SetActiveWindow (Window *window)
+ {
+ const size_t num_subwindows = m_subwindows.size();
+ for (size_t i=0; i<num_subwindows; ++i)
+ {
+ if (m_subwindows[i].get() == window)
+ {
+ m_prev_active_window_idx = m_curr_active_window_idx;
+ ::top_panel (window->m_panel);
+ m_curr_active_window_idx = i;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ WindowSP
+ GetActiveWindow ()
+ {
+ if (!m_subwindows.empty())
+ {
+ if (m_curr_active_window_idx >= m_subwindows.size())
+ {
+ if (m_prev_active_window_idx < m_subwindows.size())
+ {
+ m_curr_active_window_idx = m_prev_active_window_idx;
+ m_prev_active_window_idx = UINT32_MAX;
+ }
+ else if (IsActive())
+ {
+ m_prev_active_window_idx = UINT32_MAX;
+ m_curr_active_window_idx = UINT32_MAX;
+
+ // Find first window that wants to be active if this window is active
+ const size_t num_subwindows = m_subwindows.size();
+ for (size_t i=0; i<num_subwindows; ++i)
+ {
+ if (m_subwindows[i]->GetCanBeActive())
+ {
+ m_curr_active_window_idx = i;
+ break;
+ }
+ }
+ }
+ }
+
+ if (m_curr_active_window_idx < m_subwindows.size())
+ return m_subwindows[m_curr_active_window_idx];
+ }
+ return WindowSP();
+ }
+
+ bool
+ GetCanBeActive () const
+ {
+ return m_can_activate;
+ }
+
+ void
+ SetCanBeActive (bool b)
+ {
+ m_can_activate = b;
+ }
+
+ const WindowDelegateSP &
+ GetDelegate () const
+ {
+ return m_delegate_sp;
+ }
+
+ void
+ SetDelegate (const WindowDelegateSP &delegate_sp)
+ {
+ m_delegate_sp = delegate_sp;
+ }
+
+ Window *
+ GetParent () const
+ {
+ return m_parent;
+ }
+
+ bool
+ IsActive () const
+ {
+ if (m_parent)
+ return m_parent->GetActiveWindow().get() == this;
+ else
+ return true; // Top level window is always active
+ }
+
+ void
+ SelectNextWindowAsActive ()
+ {
+ // Move active focus to next window
+ const size_t num_subwindows = m_subwindows.size();
+ if (m_curr_active_window_idx == UINT32_MAX)
+ {
+ uint32_t idx = 0;
+ for (auto subwindow_sp : m_subwindows)
+ {
+ if (subwindow_sp->GetCanBeActive())
+ {
+ m_curr_active_window_idx = idx;
+ break;
+ }
+ ++idx;
+ }
+ }
+ else if (m_curr_active_window_idx + 1 < num_subwindows)
+ {
+ bool handled = false;
+ m_prev_active_window_idx = m_curr_active_window_idx;
+ for (size_t idx=m_curr_active_window_idx + 1; idx<num_subwindows; ++idx)
+ {
+ if (m_subwindows[idx]->GetCanBeActive())
+ {
+ m_curr_active_window_idx = idx;
+ handled = true;
+ break;
+ }
+ }
+ if (!handled)
+ {
+ for (size_t idx=0; idx<=m_prev_active_window_idx; ++idx)
+ {
+ if (m_subwindows[idx]->GetCanBeActive())
+ {
+ m_curr_active_window_idx = idx;
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ m_prev_active_window_idx = m_curr_active_window_idx;
+ for (size_t idx=0; idx<num_subwindows; ++idx)
+ {
+ if (m_subwindows[idx]->GetCanBeActive())
+ {
+ m_curr_active_window_idx = idx;
+ break;
+ }
+ }
+ }
+ }
+
+ const char *
+ GetName () const
+ {
+ return m_name.c_str();
+ }
+ protected:
+ std::string m_name;
+ WINDOW *m_window;
+ PANEL *m_panel;
+ Window *m_parent;
+ Windows m_subwindows;
+ WindowDelegateSP m_delegate_sp;
+ uint32_t m_curr_active_window_idx;
+ uint32_t m_prev_active_window_idx;
+ bool m_delete;
+ bool m_needs_update;
+ bool m_can_activate;
+ bool m_is_subwin;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Window);
+ };
+
+ class MenuDelegate
+ {
+ public:
+ virtual ~MenuDelegate() {}
+
+ virtual MenuActionResult
+ MenuDelegateAction (Menu &menu) = 0;
+ };
+
+ class Menu : public WindowDelegate
+ {
+ public:
+ enum class Type
+ {
+ Invalid,
+ Bar,
+ Item,
+ Separator
+ };
+
+ // Menubar or separator constructor
+ Menu (Type type);
+
+ // Menuitem constructor
+ Menu (const char *name,
+ const char *key_name,
+ int key_value,
+ uint64_t identifier);
+
+ virtual ~
+ Menu ()
+ {
+ }
+
+ const MenuDelegateSP &
+ GetDelegate () const
+ {
+ return m_delegate_sp;
+ }
+
+ void
+ SetDelegate (const MenuDelegateSP &delegate_sp)
+ {
+ m_delegate_sp = delegate_sp;
+ }
+
+ void
+ RecalculateNameLengths();
+
+ void
+ AddSubmenu (const MenuSP &menu_sp);
+
+ int
+ DrawAndRunMenu (Window &window);
+
+ void
+ DrawMenuTitle (Window &window, bool highlight);
+
+ virtual bool
+ WindowDelegateDraw (Window &window, bool force);
+
+ virtual HandleCharResult
+ WindowDelegateHandleChar (Window &window, int key);
+
+ MenuActionResult
+ ActionPrivate (Menu &menu)
+ {
+ MenuActionResult result = MenuActionResult::NotHandled;
+ if (m_delegate_sp)
+ {
+ result = m_delegate_sp->MenuDelegateAction (menu);
+ if (result != MenuActionResult::NotHandled)
+ return result;
+ }
+ else if (m_parent)
+ {
+ result = m_parent->ActionPrivate(menu);
+ if (result != MenuActionResult::NotHandled)
+ return result;
+ }
+ return m_canned_result;
+ }
+
+ MenuActionResult
+ Action ()
+ {
+ // Call the recursive action so it can try to handle it
+ // with the menu delegate, and if not, try our parent menu
+ return ActionPrivate (*this);
+ }
+
+ void
+ SetCannedResult (MenuActionResult result)
+ {
+ m_canned_result = result;
+ }
+
+ Menus &
+ GetSubmenus()
+ {
+ return m_submenus;
+ }
+
+ const Menus &
+ GetSubmenus() const
+ {
+ return m_submenus;
+ }
+
+ int
+ GetSelectedSubmenuIndex () const
+ {
+ return m_selected;
+ }
+
+ void
+ SetSelectedSubmenuIndex (int idx)
+ {
+ m_selected = idx;
+ }
+
+ Type
+ GetType () const
+ {
+ return m_type;
+ }
+
+ int
+ GetStartingColumn() const
+ {
+ return m_start_col;
+ }
+
+ void
+ SetStartingColumn(int col)
+ {
+ m_start_col = col;
+ }
+
+ int
+ GetKeyValue() const
+ {
+ return m_key_value;
+ }
+
+ void
+ SetKeyValue(int key_value)
+ {
+ m_key_value = key_value;
+ }
+
+ std::string &
+ GetName()
+ {
+ return m_name;
+ }
+
+ std::string &
+ GetKeyName()
+ {
+ return m_key_name;
+ }
+
+ int
+ GetDrawWidth () const
+ {
+ return m_max_submenu_name_length + m_max_submenu_key_name_length + 8;
+ }
+
+
+ uint64_t
+ GetIdentifier() const
+ {
+ return m_identifier;
+ }
+
+ void
+ SetIdentifier (uint64_t identifier)
+ {
+ m_identifier = identifier;
+ }
+
+ protected:
+ std::string m_name;
+ std::string m_key_name;
+ uint64_t m_identifier;
+ Type m_type;
+ int m_key_value;
+ int m_start_col;
+ int m_max_submenu_name_length;
+ int m_max_submenu_key_name_length;
+ int m_selected;
+ Menu *m_parent;
+ Menus m_submenus;
+ WindowSP m_menu_window_sp;
+ MenuActionResult m_canned_result;
+ MenuDelegateSP m_delegate_sp;
+ };
+
+ // Menubar or separator constructor
+ Menu::Menu (Type type) :
+ m_name (),
+ m_key_name (),
+ m_identifier (0),
+ m_type (type),
+ m_key_value (0),
+ m_start_col (0),
+ m_max_submenu_name_length (0),
+ m_max_submenu_key_name_length (0),
+ m_selected (0),
+ m_parent (NULL),
+ m_submenus (),
+ m_canned_result (MenuActionResult::NotHandled),
+ m_delegate_sp()
+ {
+ }
+
+ // Menuitem constructor
+ Menu::Menu (const char *name,
+ const char *key_name,
+ int key_value,
+ uint64_t identifier) :
+ m_name (),
+ m_key_name (),
+ m_identifier (identifier),
+ m_type (Type::Invalid),
+ m_key_value (key_value),
+ m_start_col (0),
+ m_max_submenu_name_length (0),
+ m_max_submenu_key_name_length (0),
+ m_selected (0),
+ m_parent (NULL),
+ m_submenus (),
+ m_canned_result (MenuActionResult::NotHandled),
+ m_delegate_sp()
+ {
+ if (name && name[0])
+ {
+ m_name = name;
+ m_type = Type::Item;
+ if (key_name && key_name[0])
+ m_key_name = key_name;
+ }
+ else
+ {
+ m_type = Type::Separator;
+ }
+ }
+
+ void
+ Menu::RecalculateNameLengths()
+ {
+ m_max_submenu_name_length = 0;
+ m_max_submenu_key_name_length = 0;
+ Menus &submenus = GetSubmenus();
+ const size_t num_submenus = submenus.size();
+ for (size_t i=0; i<num_submenus; ++i)
+ {
+ Menu *submenu = submenus[i].get();
+ if (m_max_submenu_name_length < submenu->m_name.size())
+ m_max_submenu_name_length = submenu->m_name.size();
+ if (m_max_submenu_key_name_length < submenu->m_key_name.size())
+ m_max_submenu_key_name_length = submenu->m_key_name.size();
+ }
+ }
+
+ void
+ Menu::AddSubmenu (const MenuSP &menu_sp)
+ {
+ menu_sp->m_parent = this;
+ if (m_max_submenu_name_length < menu_sp->m_name.size())
+ m_max_submenu_name_length = menu_sp->m_name.size();
+ if (m_max_submenu_key_name_length < menu_sp->m_key_name.size())
+ m_max_submenu_key_name_length = menu_sp->m_key_name.size();
+ m_submenus.push_back(menu_sp);
+ }
+
+ void
+ Menu::DrawMenuTitle (Window &window, bool highlight)
+ {
+ if (m_type == Type::Separator)
+ {
+ window.MoveCursor(0, window.GetCursorY());
+ window.PutChar(ACS_LTEE);
+ int width = window.GetWidth();
+ if (width > 2)
+ {
+ width -= 2;
+ for (size_t i=0; i< width; ++i)
+ window.PutChar(ACS_HLINE);
+ }
+ window.PutChar(ACS_RTEE);
+ }
+ else
+ {
+ const int shortcut_key = m_key_value;
+ bool underlined_shortcut = false;
+ const attr_t hilgight_attr = A_REVERSE;
+ if (highlight)
+ window.AttributeOn(hilgight_attr);
+ if (isprint(shortcut_key))
+ {
+ size_t lower_pos = m_name.find(tolower(shortcut_key));
+ size_t upper_pos = m_name.find(toupper(shortcut_key));
+ const char *name = m_name.c_str();
+ size_t pos = std::min<size_t>(lower_pos, upper_pos);
+ if (pos != std::string::npos)
+ {
+ underlined_shortcut = true;
+ if (pos > 0)
+ {
+ window.PutCString(name, pos);
+ name += pos;
+ }
+ const attr_t shortcut_attr = A_UNDERLINE|A_BOLD;
+ window.AttributeOn (shortcut_attr);
+ window.PutChar(name[0]);
+ window.AttributeOff(shortcut_attr);
+ name++;
+ if (name[0])
+ window.PutCString(name);
+ }
+ }
+
+ if (!underlined_shortcut)
+ {
+ window.PutCString(m_name.c_str());
+ }
+
+ if (highlight)
+ window.AttributeOff(hilgight_attr);
+
+ if (m_key_name.empty())
+ {
+ if (!underlined_shortcut && isprint(m_key_value))
+ {
+ window.AttributeOn (COLOR_PAIR(3));
+ window.Printf (" (%c)", m_key_value);
+ window.AttributeOff (COLOR_PAIR(3));
+ }
+ }
+ else
+ {
+ window.AttributeOn (COLOR_PAIR(3));
+ window.Printf (" (%s)", m_key_name.c_str());
+ window.AttributeOff (COLOR_PAIR(3));
+ }
+ }
+ }
+
+ bool
+ Menu::WindowDelegateDraw (Window &window, bool force)
+ {
+ Menus &submenus = GetSubmenus();
+ const size_t num_submenus = submenus.size();
+ const int selected_idx = GetSelectedSubmenuIndex();
+ Menu::Type menu_type = GetType ();
+ switch (menu_type)
+ {
+ case Menu::Type::Bar:
+ {
+ window.SetBackground(2);
+ window.MoveCursor(0, 0);
+ for (size_t i=0; i<num_submenus; ++i)
+ {
+ Menu *menu = submenus[i].get();
+ if (i > 0)
+ window.PutChar(' ');
+ menu->SetStartingColumn (window.GetCursorX());
+ window.PutCString("| ");
+ menu->DrawMenuTitle (window, false);
+ }
+ window.PutCString(" |");
+ window.DeferredRefresh();
+ }
+ break;
+
+ case Menu::Type::Item:
+ {
+ int y = 1;
+ int x = 3;
+ // Draw the menu
+ int cursor_x = 0;
+ int cursor_y = 0;
+ window.Erase();
+ window.SetBackground(2);
+ window.Box();
+ for (size_t i=0; i<num_submenus; ++i)
+ {
+ const bool is_selected = i == selected_idx;
+ window.MoveCursor(x, y + i);
+ if (is_selected)
+ {
+ // Remember where we want the cursor to be
+ cursor_x = x-1;
+ cursor_y = y+i;
+ }
+ submenus[i]->DrawMenuTitle (window, is_selected);
+ }
+ window.MoveCursor(cursor_x, cursor_y);
+ window.DeferredRefresh();
+ }
+ break;
+
+ default:
+ case Menu::Type::Separator:
+ break;
+ }
+ return true; // Drawing handled...
+ }
+
+ HandleCharResult
+ Menu::WindowDelegateHandleChar (Window &window, int key)
+ {
+ HandleCharResult result = eKeyNotHandled;
+
+ Menus &submenus = GetSubmenus();
+ const size_t num_submenus = submenus.size();
+ const int selected_idx = GetSelectedSubmenuIndex();
+ Menu::Type menu_type = GetType ();
+ if (menu_type == Menu::Type::Bar)
+ {
+ MenuSP run_menu_sp;
+ switch (key)
+ {
+ case KEY_DOWN:
+ case KEY_UP:
+ // Show last menu or first menu
+ if (selected_idx < num_submenus)
+ run_menu_sp = submenus[selected_idx];
+ else if (!submenus.empty())
+ run_menu_sp = submenus.front();
+ result = eKeyHandled;
+ break;
+
+ case KEY_RIGHT:
+ {
+ ++m_selected;
+ if (m_selected >= num_submenus)
+ m_selected = 0;
+ if (m_selected < num_submenus)
+ run_menu_sp = submenus[m_selected];
+ else if (!submenus.empty())
+ run_menu_sp = submenus.front();
+ result = eKeyHandled;
+ }
+ break;
+
+ case KEY_LEFT:
+ {
+ --m_selected;
+ if (m_selected < 0)
+ m_selected = num_submenus - 1;
+ if (m_selected < num_submenus)
+ run_menu_sp = submenus[m_selected];
+ else if (!submenus.empty())
+ run_menu_sp = submenus.front();
+ result = eKeyHandled;
+ }
+ break;
+
+ default:
+ for (size_t i=0; i<num_submenus; ++i)
+ {
+ if (submenus[i]->GetKeyValue() == key)
+ {
+ SetSelectedSubmenuIndex(i);
+ run_menu_sp = submenus[i];
+ result = eKeyHandled;
+ break;
+ }
+ }
+ break;
+ }
+
+ if (run_menu_sp)
+ {
+ // Run the action on this menu in case we need to populate the
+ // menu with dynamic content and also in case check marks, and
+ // any other menu decorations need to be caclulated
+ if (run_menu_sp->Action() == MenuActionResult::Quit)
+ return eQuitApplication;
+
+ Rect menu_bounds;
+ menu_bounds.origin.x = run_menu_sp->GetStartingColumn();
+ menu_bounds.origin.y = 1;
+ menu_bounds.size.width = run_menu_sp->GetDrawWidth();
+ menu_bounds.size.height = run_menu_sp->GetSubmenus().size() + 2;
+ if (m_menu_window_sp)
+ window.GetParent()->RemoveSubWindow(m_menu_window_sp.get());
+
+ m_menu_window_sp = window.GetParent()->CreateSubWindow (run_menu_sp->GetName().c_str(),
+ menu_bounds,
+ true);
+ m_menu_window_sp->SetDelegate (run_menu_sp);
+ }
+ }
+ else if (menu_type == Menu::Type::Item)
+ {
+ switch (key)
+ {
+ case KEY_DOWN:
+ if (m_submenus.size() > 1)
+ {
+ const int start_select = m_selected;
+ while (++m_selected != start_select)
+ {
+ if (m_selected >= num_submenus)
+ m_selected = 0;
+ if (m_submenus[m_selected]->GetType() == Type::Separator)
+ continue;
+ else
+ break;
+ }
+ return eKeyHandled;
+ }
+ break;
+
+ case KEY_UP:
+ if (m_submenus.size() > 1)
+ {
+ const int start_select = m_selected;
+ while (--m_selected != start_select)
+ {
+ if (m_selected < 0)
+ m_selected = num_submenus - 1;
+ if (m_submenus[m_selected]->GetType() == Type::Separator)
+ continue;
+ else
+ break;
+ }
+ return eKeyHandled;
+ }
+ break;
+
+ case KEY_RETURN:
+ if (selected_idx < num_submenus)
+ {
+ if (submenus[selected_idx]->Action() == MenuActionResult::Quit)
+ return eQuitApplication;
+ window.GetParent()->RemoveSubWindow(&window);
+ return eKeyHandled;
+ }
+ break;
+
+ case KEY_ESCAPE: // Beware: pressing escape key has 1 to 2 second delay in case other chars are entered for escaped sequences
+ window.GetParent()->RemoveSubWindow(&window);
+ return eKeyHandled;
+
+ default:
+ {
+ bool handled = false;
+ for (size_t i=0; i<num_submenus; ++i)
+ {
+ Menu *menu = submenus[i].get();
+ if (menu->GetKeyValue() == key)
+ {
+ handled = true;
+ SetSelectedSubmenuIndex(i);
+ window.GetParent()->RemoveSubWindow(&window);
+ if (menu->Action() == MenuActionResult::Quit)
+ return eQuitApplication;
+ return eKeyHandled;
+ }
+ }
+ }
+ break;
+
+ }
+ }
+ else if (menu_type == Menu::Type::Separator)
+ {
+
+ }
+ return result;
+ }
+
+
+ class Application
+ {
+ public:
+ Application (FILE *in, FILE *out) :
+ m_window_sp(),
+ m_screen (NULL),
+ m_in (in),
+ m_out (out)
+ {
+
+ }
+
+ ~Application ()
+ {
+ m_window_delegates.clear();
+ m_window_sp.reset();
+ if (m_screen)
+ {
+ ::delscreen(m_screen);
+ m_screen = NULL;
+ }
+ }
+
+ void
+ Initialize ()
+ {
+ ::setlocale(LC_ALL, "");
+ ::setlocale(LC_CTYPE, "");
+#if 0
+ ::initscr();
+#else
+ m_screen = ::newterm(NULL, m_out, m_in);
+#endif
+ ::start_color();
+ ::curs_set(0);
+ ::noecho();
+ ::keypad(stdscr,TRUE);
+ }
+
+ void
+ Terminate ()
+ {
+ ::endwin();
+ }
+
+ void
+ Run (Debugger &debugger)
+ {
+ bool done = false;
+ int delay_in_tenths_of_a_second = 1;
+
+ // Alas the threading model in curses is a bit lame so we need to
+ // resort to polling every 0.5 seconds. We could poll for stdin
+ // ourselves and then pass the keys down but then we need to
+ // translate all of the escape sequences ourselves. So we resort to
+ // polling for input because we need to receive async process events
+ // while in this loop.
+
+ halfdelay(delay_in_tenths_of_a_second); // Poll using some number of tenths of seconds seconds when calling Window::GetChar()
+
+ ListenerSP listener_sp (new Listener ("lldb.IOHandler.curses.Application"));
+ ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
+ ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
+ ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
+ debugger.EnableForwardEvents (listener_sp);
+
+ bool update = true;
+#if defined(__APPLE__)
+ std::deque<int> escape_chars;
+#endif
+
+ while (!done)
+ {
+ if (update)
+ {
+ m_window_sp->Draw(false);
+ // All windows should be calling Window::DeferredRefresh() instead
+ // of Window::Refresh() so we can do a single update and avoid
+ // any screen blinking
+ update_panels();
+
+ // Cursor hiding isn't working on MacOSX, so hide it in the top left corner
+ m_window_sp->MoveCursor(0, 0);
+
+ doupdate();
+ update = false;
+ }
+
+#if defined(__APPLE__)
+ // Terminal.app doesn't map its function keys correctly, F1-F4 default to:
+ // \033OP, \033OQ, \033OR, \033OS, so lets take care of this here if possible
+ int ch;
+ if (escape_chars.empty())
+ ch = m_window_sp->GetChar();
+ else
+ {
+ ch = escape_chars.front();
+ escape_chars.pop_front();
+ }
+ if (ch == KEY_ESCAPE)
+ {
+ int ch2 = m_window_sp->GetChar();
+ if (ch2 == 'O')
+ {
+ int ch3 = m_window_sp->GetChar();
+ switch (ch3)
+ {
+ case 'P': ch = KEY_F(1); break;
+ case 'Q': ch = KEY_F(2); break;
+ case 'R': ch = KEY_F(3); break;
+ case 'S': ch = KEY_F(4); break;
+ default:
+ escape_chars.push_back(ch2);
+ if (ch3 != -1)
+ escape_chars.push_back(ch3);
+ break;
+ }
+ }
+ else if (ch2 != -1)
+ escape_chars.push_back(ch2);
+ }
+#else
+ int ch = m_window_sp->GetChar();
+
+#endif
+ if (ch == -1)
+ {
+ if (feof(m_in) || ferror(m_in))
+ {
+ done = true;
+ }
+ else
+ {
+ // Just a timeout from using halfdelay(), check for events
+ EventSP event_sp;
+ while (listener_sp->PeekAtNextEvent())
+ {
+ listener_sp->GetNextEvent(event_sp);
+
+ if (event_sp)
+ {
+ Broadcaster *broadcaster = event_sp->GetBroadcaster();
+ if (broadcaster)
+ {
+ //uint32_t event_type = event_sp->GetType();
+ ConstString broadcaster_class (broadcaster->GetBroadcasterClass());
+ if (broadcaster_class == broadcaster_class_process)
+ {
+ update = true;
+ continue; // Don't get any key, just update our view
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ HandleCharResult key_result = m_window_sp->HandleChar(ch);
+ switch (key_result)
+ {
+ case eKeyHandled:
+ update = true;
+ break;
+ case eKeyNotHandled:
+ break;
+ case eQuitApplication:
+ done = true;
+ break;
+ }
+ }
+ }
+
+ debugger.CancelForwardEvents (listener_sp);
+
+ }
+
+ WindowSP &
+ GetMainWindow ()
+ {
+ if (!m_window_sp)
+ m_window_sp.reset (new Window ("main", stdscr, false));
+ return m_window_sp;
+ }
+
+ WindowDelegates &
+ GetWindowDelegates ()
+ {
+ return m_window_delegates;
+ }
+
+ protected:
+ WindowSP m_window_sp;
+ WindowDelegates m_window_delegates;
+ SCREEN *m_screen;
+ FILE *m_in;
+ FILE *m_out;
+ };
+
+
+} // namespace curses
+
+
+using namespace curses;
+
+struct Row
+{
+ ValueObjectSP valobj;
+ Row *parent;
+ int row_idx;
+ int x;
+ int y;
+ bool might_have_children;
+ bool expanded;
+ bool calculated_children;
+ std::vector<Row> children;
+
+ Row (const ValueObjectSP &v, Row *p) :
+ valobj (v),
+ parent (p),
+ row_idx(0),
+ x(1),
+ y(1),
+ might_have_children (v ? v->MightHaveChildren() : false),
+ expanded (false),
+ calculated_children (false),
+ children()
+ {
+ }
+
+ size_t
+ GetDepth () const
+ {
+ if (parent)
+ return 1 + parent->GetDepth();
+ return 0;
+ }
+
+ void
+ Expand()
+ {
+ expanded = true;
+ if (!calculated_children)
+ {
+ calculated_children = true;
+ if (valobj)
+ {
+ const size_t num_children = valobj->GetNumChildren();
+ for (size_t i=0; i<num_children; ++i)
+ {
+ children.push_back(Row (valobj->GetChildAtIndex(i, true), this));
+ }
+ }
+ }
+ }
+
+ void
+ Unexpand ()
+ {
+ expanded = false;
+ }
+
+ void
+ DrawTree (Window &window)
+ {
+ if (parent)
+ parent->DrawTreeForChild (window, this, 0);
+
+ if (might_have_children)
+ {
+ // It we can get UTF8 characters to work we should try to use the "symbol"
+ // UTF8 string below
+// const char *symbol = "";
+// if (row.expanded)
+// symbol = "\xe2\x96\xbd ";
+// else
+// symbol = "\xe2\x96\xb7 ";
+// window.PutCString (symbol);
+
+ // The ACS_DARROW and ACS_RARROW don't look very nice they are just a
+ // 'v' or '>' character...
+// if (expanded)
+// window.PutChar (ACS_DARROW);
+// else
+// window.PutChar (ACS_RARROW);
+ // Since we can't find any good looking right arrow/down arrow
+ // symbols, just use a diamond...
+ window.PutChar (ACS_DIAMOND);
+ window.PutChar (ACS_HLINE);
+ }
+ }
+
+ void
+ DrawTreeForChild (Window &window, Row *child, uint32_t reverse_depth)
+ {
+ if (parent)
+ parent->DrawTreeForChild (window, this, reverse_depth + 1);
+
+ if (&children.back() == child)
+ {
+ // Last child
+ if (reverse_depth == 0)
+ {
+ window.PutChar (ACS_LLCORNER);
+ window.PutChar (ACS_HLINE);
+ }
+ else
+ {
+ window.PutChar (' ');
+ window.PutChar (' ');
+ }
+ }
+ else
+ {
+ if (reverse_depth == 0)
+ {
+ window.PutChar (ACS_LTEE);
+ window.PutChar (ACS_HLINE);
+ }
+ else
+ {
+ window.PutChar (ACS_VLINE);
+ window.PutChar (' ');
+ }
+ }
+ }
+};
+
+struct DisplayOptions
+{
+ bool show_types;
+};
+
+class TreeItem;
+
+class TreeDelegate
+{
+public:
+ TreeDelegate() {}
+ virtual ~TreeDelegate() {}
+ virtual void TreeDelegateDrawTreeItem (TreeItem &item, Window &window) = 0;
+ virtual void TreeDelegateGenerateChildren (TreeItem &item) = 0;
+ virtual bool TreeDelegateItemSelected (TreeItem &item) = 0; // Return true if we need to update views
+};
+typedef std::shared_ptr<TreeDelegate> TreeDelegateSP;
+
+class TreeItem
+{
+public:
+
+ TreeItem (TreeItem *parent, TreeDelegate &delegate, bool might_have_children) :
+ m_parent (parent),
+ m_delegate (delegate),
+ m_identifier (0),
+ m_row_idx (-1),
+ m_children (),
+ m_might_have_children (might_have_children),
+ m_is_expanded (false)
+ {
+ }
+
+ TreeItem &
+ operator=(const TreeItem &rhs)
+ {
+ if (this != &rhs)
+ {
+ m_parent = rhs.m_parent;
+ m_delegate = rhs.m_delegate;
+ m_identifier = rhs.m_identifier;
+ m_row_idx = rhs.m_row_idx;
+ m_children = rhs.m_children;
+ m_might_have_children = rhs.m_might_have_children;
+ m_is_expanded = rhs.m_is_expanded;
+ }
+ return *this;
+ }
+
+ size_t
+ GetDepth () const
+ {
+ if (m_parent)
+ return 1 + m_parent->GetDepth();
+ return 0;
+ }
+
+ int
+ GetRowIndex () const
+ {
+ return m_row_idx;
+ }
+
+ void
+ ClearChildren ()
+ {
+ m_children.clear();
+ }
+
+ void
+ Resize (size_t n, const TreeItem &t)
+ {
+ m_children.resize(n, t);
+ }
+
+ TreeItem &
+ operator [](size_t i)
+ {
+ return m_children[i];
+ }
+
+ void
+ SetRowIndex (int row_idx)
+ {
+ m_row_idx = row_idx;
+ }
+
+ size_t
+ GetNumChildren ()
+ {
+ m_delegate.TreeDelegateGenerateChildren (*this);
+ return m_children.size();
+ }
+
+ void
+ ItemWasSelected ()
+ {
+ m_delegate.TreeDelegateItemSelected(*this);
+ }
+ void
+ CalculateRowIndexes (int &row_idx)
+ {
+ SetRowIndex(row_idx);
+ ++row_idx;
+
+ // The root item must calculate its children
+ if (m_parent == NULL)
+ GetNumChildren();
+
+ const bool expanded = IsExpanded();
+ for (auto &item : m_children)
+ {
+ if (expanded)
+ item.CalculateRowIndexes(row_idx);
+ else
+ item.SetRowIndex(-1);
+ }
+ }
+
+ TreeItem *
+ GetParent ()
+ {
+ return m_parent;
+ }
+
+ bool
+ IsExpanded () const
+ {
+ return m_is_expanded;
+ }
+
+ void
+ Expand()
+ {
+ m_is_expanded = true;
+ }
+
+ void
+ Unexpand ()
+ {
+ m_is_expanded = false;
+ }
+
+ bool
+ Draw (Window &window,
+ const int first_visible_row,
+ const uint32_t selected_row_idx,
+ int &row_idx,
+ int &num_rows_left)
+ {
+ if (num_rows_left <= 0)
+ return false;
+
+ if (m_row_idx >= first_visible_row)
+ {
+ window.MoveCursor(2, row_idx + 1);
+
+ if (m_parent)
+ m_parent->DrawTreeForChild (window, this, 0);
+
+ if (m_might_have_children)
+ {
+ // It we can get UTF8 characters to work we should try to use the "symbol"
+ // UTF8 string below
+ // const char *symbol = "";
+ // if (row.expanded)
+ // symbol = "\xe2\x96\xbd ";
+ // else
+ // symbol = "\xe2\x96\xb7 ";
+ // window.PutCString (symbol);
+
+ // The ACS_DARROW and ACS_RARROW don't look very nice they are just a
+ // 'v' or '>' character...
+ // if (expanded)
+ // window.PutChar (ACS_DARROW);
+ // else
+ // window.PutChar (ACS_RARROW);
+ // Since we can't find any good looking right arrow/down arrow
+ // symbols, just use a diamond...
+ window.PutChar (ACS_DIAMOND);
+ window.PutChar (ACS_HLINE);
+ }
+ bool highlight = (selected_row_idx == m_row_idx) && window.IsActive();
+
+ if (highlight)
+ window.AttributeOn(A_REVERSE);
+
+ m_delegate.TreeDelegateDrawTreeItem(*this, window);
+
+ if (highlight)
+ window.AttributeOff(A_REVERSE);
+ ++row_idx;
+ --num_rows_left;
+ }
+
+ if (num_rows_left <= 0)
+ return false; // We are done drawing...
+
+ if (IsExpanded())
+ {
+ for (auto &item : m_children)
+ {
+ // If we displayed all the rows and item.Draw() returns
+ // false we are done drawing and can exit this for loop
+ if (item.Draw(window, first_visible_row, selected_row_idx, row_idx, num_rows_left) == false)
+ break;
+ }
+ }
+ return num_rows_left >= 0; // Return true if not done drawing yet
+ }
+
+ void
+ DrawTreeForChild (Window &window, TreeItem *child, uint32_t reverse_depth)
+ {
+ if (m_parent)
+ m_parent->DrawTreeForChild (window, this, reverse_depth + 1);
+
+ if (&m_children.back() == child)
+ {
+ // Last child
+ if (reverse_depth == 0)
+ {
+ window.PutChar (ACS_LLCORNER);
+ window.PutChar (ACS_HLINE);
+ }
+ else
+ {
+ window.PutChar (' ');
+ window.PutChar (' ');
+ }
+ }
+ else
+ {
+ if (reverse_depth == 0)
+ {
+ window.PutChar (ACS_LTEE);
+ window.PutChar (ACS_HLINE);
+ }
+ else
+ {
+ window.PutChar (ACS_VLINE);
+ window.PutChar (' ');
+ }
+ }
+ }
+
+ TreeItem *
+ GetItemForRowIndex (uint32_t row_idx)
+ {
+ if (m_row_idx == row_idx)
+ return this;
+ if (m_children.empty())
+ return NULL;
+ if (m_children.back().m_row_idx < row_idx)
+ return NULL;
+ if (IsExpanded())
+ {
+ for (auto &item : m_children)
+ {
+ TreeItem *selected_item_ptr = item.GetItemForRowIndex(row_idx);
+ if (selected_item_ptr)
+ return selected_item_ptr;
+ }
+ }
+ return NULL;
+ }
+
+// void *
+// GetUserData() const
+// {
+// return m_user_data;
+// }
+//
+// void
+// SetUserData (void *user_data)
+// {
+// m_user_data = user_data;
+// }
+ uint64_t
+ GetIdentifier() const
+ {
+ return m_identifier;
+ }
+
+ void
+ SetIdentifier (uint64_t identifier)
+ {
+ m_identifier = identifier;
+ }
+
+
+protected:
+ TreeItem *m_parent;
+ TreeDelegate &m_delegate;
+ //void *m_user_data;
+ uint64_t m_identifier;
+ int m_row_idx; // Zero based visible row index, -1 if not visible or for the root item
+ std::vector<TreeItem> m_children;
+ bool m_might_have_children;
+ bool m_is_expanded;
+
+};
+
+class TreeWindowDelegate : public WindowDelegate
+{
+public:
+ TreeWindowDelegate (Debugger &debugger, const TreeDelegateSP &delegate_sp) :
+ m_debugger (debugger),
+ m_delegate_sp (delegate_sp),
+ m_root (NULL, *delegate_sp, true),
+ m_selected_item (NULL),
+ m_num_rows (0),
+ m_selected_row_idx (0),
+ m_first_visible_row (0),
+ m_min_x (0),
+ m_min_y (0),
+ m_max_x (0),
+ m_max_y (0)
+ {
+ }
+
+ int
+ NumVisibleRows () const
+ {
+ return m_max_y - m_min_y;
+ }
+
+ virtual bool
+ WindowDelegateDraw (Window &window, bool force)
+ {
+ ExecutionContext exe_ctx (m_debugger.GetCommandInterpreter().GetExecutionContext());
+ Process *process = exe_ctx.GetProcessPtr();
+
+ bool display_content = false;
+ if (process)
+ {
+ StateType state = process->GetState();
+ if (StateIsStoppedState(state, true))
+ {
+ // We are stopped, so it is ok to
+ display_content = true;
+ }
+ else if (StateIsRunningState(state))
+ {
+ return true; // Don't do any updating when we are running
+ }
+ }
+
+ m_min_x = 2;
+ m_min_y = 1;
+ m_max_x = window.GetWidth() - 1;
+ m_max_y = window.GetHeight() - 1;
+
+ window.Erase();
+ window.DrawTitleBox (window.GetName());
+
+ if (display_content)
+ {
+ const int num_visible_rows = NumVisibleRows();
+ m_num_rows = 0;
+ m_root.CalculateRowIndexes(m_num_rows);
+
+ // If we unexpanded while having something selected our
+ // total number of rows is less than the num visible rows,
+ // then make sure we show all the rows by setting the first
+ // visible row accordingly.
+ if (m_first_visible_row > 0 && m_num_rows < num_visible_rows)
+ m_first_visible_row = 0;
+
+ // Make sure the selected row is always visible
+ if (m_selected_row_idx < m_first_visible_row)
+ m_first_visible_row = m_selected_row_idx;
+ else if (m_first_visible_row + num_visible_rows <= m_selected_row_idx)
+ m_first_visible_row = m_selected_row_idx - num_visible_rows + 1;
+
+ int row_idx = 0;
+ int num_rows_left = num_visible_rows;
+ m_root.Draw (window, m_first_visible_row, m_selected_row_idx, row_idx, num_rows_left);
+ // Get the selected row
+ m_selected_item = m_root.GetItemForRowIndex (m_selected_row_idx);
+ }
+ else
+ {
+ m_selected_item = NULL;
+ }
+
+ window.DeferredRefresh();
+
+
+ return true; // Drawing handled
+ }
+
+
+ virtual const char *
+ WindowDelegateGetHelpText ()
+ {
+ return "Thread window keyboard shortcuts:";
+ }
+
+ virtual KeyHelp *
+ WindowDelegateGetKeyHelp ()
+ {
+ static curses::KeyHelp g_source_view_key_help[] = {
+ { KEY_UP, "Select previous item" },
+ { KEY_DOWN, "Select next item" },
+ { KEY_RIGHT, "Expand the selected item" },
+ { KEY_LEFT, "Unexpand the selected item or select parent if not expanded" },
+ { KEY_PPAGE, "Page up" },
+ { KEY_NPAGE, "Page down" },
+ { 'h', "Show help dialog" },
+ { ' ', "Toggle item expansion" },
+ { ',', "Page up" },
+ { '.', "Page down" },
+ { '\0', NULL }
+ };
+ return g_source_view_key_help;
+ }
+
+ virtual HandleCharResult
+ WindowDelegateHandleChar (Window &window, int c)
+ {
+ switch(c)
+ {
+ case ',':
+ case KEY_PPAGE:
+ // Page up key
+ if (m_first_visible_row > 0)
+ {
+ if (m_first_visible_row > m_max_y)
+ m_first_visible_row -= m_max_y;
+ else
+ m_first_visible_row = 0;
+ m_selected_row_idx = m_first_visible_row;
+ m_selected_item = m_root.GetItemForRowIndex(m_selected_row_idx);
+ if (m_selected_item)
+ m_selected_item->ItemWasSelected ();
+ }
+ return eKeyHandled;
+
+ case '.':
+ case KEY_NPAGE:
+ // Page down key
+ if (m_num_rows > m_max_y)
+ {
+ if (m_first_visible_row + m_max_y < m_num_rows)
+ {
+ m_first_visible_row += m_max_y;
+ m_selected_row_idx = m_first_visible_row;
+ m_selected_item = m_root.GetItemForRowIndex(m_selected_row_idx);
+ if (m_selected_item)
+ m_selected_item->ItemWasSelected ();
+ }
+ }
+ return eKeyHandled;
+
+ case KEY_UP:
+ if (m_selected_row_idx > 0)
+ {
+ --m_selected_row_idx;
+ m_selected_item = m_root.GetItemForRowIndex(m_selected_row_idx);
+ if (m_selected_item)
+ m_selected_item->ItemWasSelected ();
+ }
+ return eKeyHandled;
+ case KEY_DOWN:
+ if (m_selected_row_idx + 1 < m_num_rows)
+ {
+ ++m_selected_row_idx;
+ m_selected_item = m_root.GetItemForRowIndex(m_selected_row_idx);
+ if (m_selected_item)
+ m_selected_item->ItemWasSelected ();
+ }
+ return eKeyHandled;
+
+ case KEY_RIGHT:
+ if (m_selected_item)
+ {
+ if (!m_selected_item->IsExpanded())
+ m_selected_item->Expand();
+ }
+ return eKeyHandled;
+
+ case KEY_LEFT:
+ if (m_selected_item)
+ {
+ if (m_selected_item->IsExpanded())
+ m_selected_item->Unexpand();
+ else if (m_selected_item->GetParent())
+ {
+ m_selected_row_idx = m_selected_item->GetParent()->GetRowIndex();
+ m_selected_item = m_root.GetItemForRowIndex(m_selected_row_idx);
+ if (m_selected_item)
+ m_selected_item->ItemWasSelected ();
+ }
+ }
+ return eKeyHandled;
+
+ case ' ':
+ // Toggle expansion state when SPACE is pressed
+ if (m_selected_item)
+ {
+ if (m_selected_item->IsExpanded())
+ m_selected_item->Unexpand();
+ else
+ m_selected_item->Expand();
+ }
+ return eKeyHandled;
+
+ case 'h':
+ window.CreateHelpSubwindow ();
+ return eKeyHandled;
+
+ default:
+ break;
+ }
+ return eKeyNotHandled;
+ }
+
+protected:
+ Debugger &m_debugger;
+ TreeDelegateSP m_delegate_sp;
+ TreeItem m_root;
+ TreeItem *m_selected_item;
+ int m_num_rows;
+ int m_selected_row_idx;
+ int m_first_visible_row;
+ int m_min_x;
+ int m_min_y;
+ int m_max_x;
+ int m_max_y;
+
+};
+
+class FrameTreeDelegate : public TreeDelegate
+{
+public:
+ FrameTreeDelegate (const ThreadSP &thread_sp) :
+ TreeDelegate(),
+ m_thread_wp()
+ {
+ if (thread_sp)
+ m_thread_wp = thread_sp;
+ }
+
+ virtual ~FrameTreeDelegate()
+ {
+ }
+
+ virtual void
+ TreeDelegateDrawTreeItem (TreeItem &item, Window &window)
+ {
+ ThreadSP thread_sp = m_thread_wp.lock();
+ if (thread_sp)
+ {
+ const uint64_t frame_idx = item.GetIdentifier();
+ StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(frame_idx);
+ if (frame_sp)
+ {
+ StreamString strm;
+ const SymbolContext &sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
+ ExecutionContext exe_ctx (frame_sp);
+ //const char *frame_format = "frame #${frame.index}: ${module.file.basename}{`${function.name}${function.pc-offset}}}";
+ const char *frame_format = "frame #${frame.index}: {${function.name}${function.pc-offset}}}";
+ if (Debugger::FormatPrompt (frame_format, &sc, &exe_ctx, NULL, strm))
+ {
+ int right_pad = 1;
+ window.PutCStringTruncated(strm.GetString().c_str(), right_pad);
+ }
+ }
+ }
+ }
+ virtual void
+ TreeDelegateGenerateChildren (TreeItem &item)
+ {
+ // No children for frames yet...
+ }
+
+ virtual bool
+ TreeDelegateItemSelected (TreeItem &item)
+ {
+ ThreadSP thread_sp = m_thread_wp.lock();
+ if (thread_sp)
+ {
+ const uint64_t frame_idx = item.GetIdentifier();
+ thread_sp->SetSelectedFrameByIndex(frame_idx);
+ return true;
+ }
+ return false;
+ }
+ void
+ SetThread (ThreadSP thread_sp)
+ {
+ m_thread_wp = thread_sp;
+ }
+
+protected:
+ ThreadWP m_thread_wp;
+};
+
+class ThreadTreeDelegate : public TreeDelegate
+{
+public:
+ ThreadTreeDelegate (Debugger &debugger) :
+ TreeDelegate(),
+ m_debugger (debugger),
+ m_thread_wp (),
+ m_tid (LLDB_INVALID_THREAD_ID),
+ m_stop_id (UINT32_MAX)
+ {
+ }
+
+ virtual
+ ~ThreadTreeDelegate()
+ {
+ }
+
+ virtual void
+ TreeDelegateDrawTreeItem (TreeItem &item, Window &window)
+ {
+ ThreadSP thread_sp = m_thread_wp.lock();
+ if (thread_sp)
+ {
+ StreamString strm;
+ ExecutionContext exe_ctx (thread_sp);
+ const char *format = "thread #${thread.index}: tid = ${thread.id}{, stop reason = ${thread.stop-reason}}";
+ if (Debugger::FormatPrompt (format, NULL, &exe_ctx, NULL, strm))
+ {
+ int right_pad = 1;
+ window.PutCStringTruncated(strm.GetString().c_str(), right_pad);
+ }
+ }
+ }
+ virtual void
+ TreeDelegateGenerateChildren (TreeItem &item)
+ {
+ TargetSP target_sp (m_debugger.GetSelectedTarget());
+ if (target_sp)
+ {
+ ProcessSP process_sp = target_sp->GetProcessSP();
+ if (process_sp && process_sp->IsAlive())
+ {
+ StateType state = process_sp->GetState();
+ if (StateIsStoppedState(state, true))
+ {
+ ThreadSP thread_sp = process_sp->GetThreadList().GetSelectedThread();
+ if (thread_sp)
+ {
+ if (m_stop_id == process_sp->GetStopID() && thread_sp->GetID() == m_tid)
+ return; // Children are already up to date
+ if (m_frame_delegate_sp)
+ m_frame_delegate_sp->SetThread(thread_sp);
+ else
+ {
+ // Always expand the thread item the first time we show it
+ item.Expand();
+ m_frame_delegate_sp.reset (new FrameTreeDelegate(thread_sp));
+ }
+
+ m_stop_id = process_sp->GetStopID();
+ m_thread_wp = thread_sp;
+ m_tid = thread_sp->GetID();
+
+ TreeItem t (&item, *m_frame_delegate_sp, false);
+ size_t num_frames = thread_sp->GetStackFrameCount();
+ item.Resize (num_frames, t);
+ for (size_t i=0; i<num_frames; ++i)
+ {
+ item[i].SetIdentifier(i);
+ }
+ }
+ return;
+ }
+ }
+ }
+ item.ClearChildren();
+ }
+
+ virtual bool
+ TreeDelegateItemSelected (TreeItem &item)
+ {
+ ThreadSP thread_sp = m_thread_wp.lock();
+ if (thread_sp)
+ {
+ ThreadList &thread_list = thread_sp->GetProcess()->GetThreadList();
+ Mutex::Locker locker (thread_list.GetMutex());
+ ThreadSP selected_thread_sp = thread_list.GetSelectedThread();
+ if (selected_thread_sp->GetID() != thread_sp->GetID())
+ {
+ thread_list.SetSelectedThreadByID(thread_sp->GetID());
+ return true;
+ }
+ }
+ return false;
+ }
+
+protected:
+ Debugger &m_debugger;
+ ThreadWP m_thread_wp;
+ std::shared_ptr<FrameTreeDelegate> m_frame_delegate_sp;
+ lldb::user_id_t m_tid;
+ uint32_t m_stop_id;
+};
+
+class ValueObjectListDelegate : public WindowDelegate
+{
+public:
+ ValueObjectListDelegate () :
+ m_valobj_list (),
+ m_rows (),
+ m_selected_row (NULL),
+ m_selected_row_idx (0),
+ m_first_visible_row (0),
+ m_num_rows (0),
+ m_max_x (0),
+ m_max_y (0)
+ {
+ }
+
+ ValueObjectListDelegate (ValueObjectList &valobj_list) :
+ m_valobj_list (valobj_list),
+ m_rows (),
+ m_selected_row (NULL),
+ m_selected_row_idx (0),
+ m_first_visible_row (0),
+ m_num_rows (0),
+ m_max_x (0),
+ m_max_y (0)
+ {
+ SetValues (valobj_list);
+ }
+
+ virtual
+ ~ValueObjectListDelegate()
+ {
+ }
+
+ void
+ SetValues (ValueObjectList &valobj_list)
+ {
+ m_selected_row = NULL;
+ m_selected_row_idx = 0;
+ m_first_visible_row = 0;
+ m_num_rows = 0;
+ m_rows.clear();
+ m_valobj_list = valobj_list;
+ const size_t num_values = m_valobj_list.GetSize();
+ for (size_t i=0; i<num_values; ++i)
+ m_rows.push_back(Row(m_valobj_list.GetValueObjectAtIndex(i), NULL));
+ }
+
+ virtual bool
+ WindowDelegateDraw (Window &window, bool force)
+ {
+ m_num_rows = 0;
+ m_min_x = 2;
+ m_min_y = 1;
+ m_max_x = window.GetWidth() - 1;
+ m_max_y = window.GetHeight() - 1;
+
+ window.Erase();
+ window.DrawTitleBox (window.GetName());
+
+ const int num_visible_rows = NumVisibleRows();
+ const int num_rows = CalculateTotalNumberRows (m_rows);
+
+ // If we unexpanded while having something selected our
+ // total number of rows is less than the num visible rows,
+ // then make sure we show all the rows by setting the first
+ // visible row accordingly.
+ if (m_first_visible_row > 0 && num_rows < num_visible_rows)
+ m_first_visible_row = 0;
+
+ // Make sure the selected row is always visible
+ if (m_selected_row_idx < m_first_visible_row)
+ m_first_visible_row = m_selected_row_idx;
+ else if (m_first_visible_row + num_visible_rows <= m_selected_row_idx)
+ m_first_visible_row = m_selected_row_idx - num_visible_rows + 1;
+
+ DisplayRows (window, m_rows, g_options);
+
+ window.DeferredRefresh();
+
+ // Get the selected row
+ m_selected_row = GetRowForRowIndex (m_selected_row_idx);
+ // Keep the cursor on the selected row so the highlight and the cursor
+ // are always on the same line
+ if (m_selected_row)
+ window.MoveCursor (m_selected_row->x,
+ m_selected_row->y);
+
+ return true; // Drawing handled
+ }
+
+ virtual KeyHelp *
+ WindowDelegateGetKeyHelp ()
+ {
+ static curses::KeyHelp g_source_view_key_help[] = {
+ { KEY_UP, "Select previous item" },
+ { KEY_DOWN, "Select next item" },
+ { KEY_RIGHT, "Expand selected item" },
+ { KEY_LEFT, "Unexpand selected item or select parent if not expanded" },
+ { KEY_PPAGE, "Page up" },
+ { KEY_NPAGE, "Page down" },
+ { 'A', "Format as annotated address" },
+ { 'b', "Format as binary" },
+ { 'B', "Format as hex bytes with ASCII" },
+ { 'c', "Format as character" },
+ { 'd', "Format as a signed integer" },
+ { 'D', "Format selected value using the default format for the type" },
+ { 'f', "Format as float" },
+ { 'h', "Show help dialog" },
+ { 'i', "Format as instructions" },
+ { 'o', "Format as octal" },
+ { 'p', "Format as pointer" },
+ { 's', "Format as C string" },
+ { 't', "Toggle showing/hiding type names" },
+ { 'u', "Format as an unsigned integer" },
+ { 'x', "Format as hex" },
+ { 'X', "Format as uppercase hex" },
+ { ' ', "Toggle item expansion" },
+ { ',', "Page up" },
+ { '.', "Page down" },
+ { '\0', NULL }
+ };
+ return g_source_view_key_help;
+ }
+
+
+ virtual HandleCharResult
+ WindowDelegateHandleChar (Window &window, int c)
+ {
+ switch(c)
+ {
+ case 'x':
+ case 'X':
+ case 'o':
+ case 's':
+ case 'u':
+ case 'd':
+ case 'D':
+ case 'i':
+ case 'A':
+ case 'p':
+ case 'c':
+ case 'b':
+ case 'B':
+ case 'f':
+ // Change the format for the currently selected item
+ if (m_selected_row)
+ m_selected_row->valobj->SetFormat (FormatForChar (c));
+ return eKeyHandled;
+
+ case 't':
+ // Toggle showing type names
+ g_options.show_types = !g_options.show_types;
+ return eKeyHandled;
+
+ case ',':
+ case KEY_PPAGE:
+ // Page up key
+ if (m_first_visible_row > 0)
+ {
+ if (m_first_visible_row > m_max_y)
+ m_first_visible_row -= m_max_y;
+ else
+ m_first_visible_row = 0;
+ m_selected_row_idx = m_first_visible_row;
+ }
+ return eKeyHandled;
+
+ case '.':
+ case KEY_NPAGE:
+ // Page down key
+ if (m_num_rows > m_max_y)
+ {
+ if (m_first_visible_row + m_max_y < m_num_rows)
+ {
+ m_first_visible_row += m_max_y;
+ m_selected_row_idx = m_first_visible_row;
+ }
+ }
+ return eKeyHandled;
+
+ case KEY_UP:
+ if (m_selected_row_idx > 0)
+ --m_selected_row_idx;
+ return eKeyHandled;
+ case KEY_DOWN:
+ if (m_selected_row_idx + 1 < m_num_rows)
+ ++m_selected_row_idx;
+ return eKeyHandled;
+
+ case KEY_RIGHT:
+ if (m_selected_row)
+ {
+ if (!m_selected_row->expanded)
+ m_selected_row->Expand();
+ }
+ return eKeyHandled;
+
+ case KEY_LEFT:
+ if (m_selected_row)
+ {
+ if (m_selected_row->expanded)
+ m_selected_row->Unexpand();
+ else if (m_selected_row->parent)
+ m_selected_row_idx = m_selected_row->parent->row_idx;
+ }
+ return eKeyHandled;
+
+ case ' ':
+ // Toggle expansion state when SPACE is pressed
+ if (m_selected_row)
+ {
+ if (m_selected_row->expanded)
+ m_selected_row->Unexpand();
+ else
+ m_selected_row->Expand();
+ }
+ return eKeyHandled;
+
+ case 'h':
+ window.CreateHelpSubwindow ();
+ return eKeyHandled;
+
+ default:
+ break;
+ }
+ return eKeyNotHandled;
+ }
+
+protected:
+ ValueObjectList m_valobj_list;
+ std::vector<Row> m_rows;
+ Row *m_selected_row;
+ uint32_t m_selected_row_idx;
+ uint32_t m_first_visible_row;
+ uint32_t m_num_rows;
+ int m_min_x;
+ int m_min_y;
+ int m_max_x;
+ int m_max_y;
+
+ static Format
+ FormatForChar (int c)
+ {
+ switch (c)
+ {
+ case 'x': return eFormatHex;
+ case 'X': return eFormatHexUppercase;
+ case 'o': return eFormatOctal;
+ case 's': return eFormatCString;
+ case 'u': return eFormatUnsigned;
+ case 'd': return eFormatDecimal;
+ case 'D': return eFormatDefault;
+ case 'i': return eFormatInstruction;
+ case 'A': return eFormatAddressInfo;
+ case 'p': return eFormatPointer;
+ case 'c': return eFormatChar;
+ case 'b': return eFormatBinary;
+ case 'B': return eFormatBytesWithASCII;
+ case 'f': return eFormatFloat;
+ }
+ return eFormatDefault;
+ }
+
+ bool
+ DisplayRowObject (Window &window,
+ Row &row,
+ DisplayOptions &options,
+ bool highlight,
+ bool last_child)
+ {
+ ValueObject *valobj = row.valobj.get();
+
+ if (valobj == NULL)
+ return false;
+
+ const char *type_name = options.show_types ? valobj->GetTypeName().GetCString() : NULL;
+ const char *name = valobj->GetName().GetCString();
+ const char *value = valobj->GetValueAsCString ();
+ const char *summary = valobj->GetSummaryAsCString ();
+
+ window.MoveCursor (row.x, row.y);
+
+ row.DrawTree (window);
+
+ if (highlight)
+ window.AttributeOn(A_REVERSE);
+
+ if (type_name && type_name[0])
+ window.Printf ("(%s) ", type_name);
+
+ if (name && name[0])
+ window.PutCString(name);
+
+ attr_t changd_attr = 0;
+ if (valobj->GetValueDidChange())
+ changd_attr = COLOR_PAIR(5) | A_BOLD;
+
+ if (value && value[0])
+ {
+ window.PutCString(" = ");
+ if (changd_attr)
+ window.AttributeOn(changd_attr);
+ window.PutCString (value);
+ if (changd_attr)
+ window.AttributeOff(changd_attr);
+ }
+
+ if (summary && summary[0])
+ {
+ window.PutChar(' ');
+ if (changd_attr)
+ window.AttributeOn(changd_attr);
+ window.PutCString(summary);
+ if (changd_attr)
+ window.AttributeOff(changd_attr);
+ }
+
+ if (highlight)
+ window.AttributeOff (A_REVERSE);
+
+ return true;
+ }
+ void
+ DisplayRows (Window &window,
+ std::vector<Row> &rows,
+ DisplayOptions &options)
+ {
+ // > 0x25B7
+ // \/ 0x25BD
+
+ bool window_is_active = window.IsActive();
+ for (auto &row : rows)
+ {
+ const bool last_child = row.parent && &rows[rows.size()-1] == &row;
+ // Save the row index in each Row structure
+ row.row_idx = m_num_rows;
+ if ((m_num_rows >= m_first_visible_row) &&
+ ((m_num_rows - m_first_visible_row) < NumVisibleRows()))
+ {
+ row.x = m_min_x;
+ row.y = m_num_rows - m_first_visible_row + 1;
+ if (DisplayRowObject (window,
+ row,
+ options,
+ window_is_active && m_num_rows == m_selected_row_idx,
+ last_child))
+ {
+ ++m_num_rows;
+ }
+ else
+ {
+ row.x = 0;
+ row.y = 0;
+ }
+ }
+ else
+ {
+ row.x = 0;
+ row.y = 0;
+ ++m_num_rows;
+ }
+
+ if (row.expanded && !row.children.empty())
+ {
+ DisplayRows (window,
+ row.children,
+ options);
+ }
+ }
+ }
+
+ int
+ CalculateTotalNumberRows (const std::vector<Row> &rows)
+ {
+ int row_count = 0;
+ for (const auto &row : rows)
+ {
+ ++row_count;
+ if (row.expanded)
+ row_count += CalculateTotalNumberRows(row.children);
+ }
+ return row_count;
+ }
+ static Row *
+ GetRowForRowIndexImpl (std::vector<Row> &rows, size_t &row_index)
+ {
+ for (auto &row : rows)
+ {
+ if (row_index == 0)
+ return &row;
+ else
+ {
+ --row_index;
+ if (row.expanded && !row.children.empty())
+ {
+ Row *result = GetRowForRowIndexImpl (row.children, row_index);
+ if (result)
+ return result;
+ }
+ }
+ }
+ return NULL;
+ }
+
+ Row *
+ GetRowForRowIndex (size_t row_index)
+ {
+ return GetRowForRowIndexImpl (m_rows, row_index);
+ }
+
+ int
+ NumVisibleRows () const
+ {
+ return m_max_y - m_min_y;
+ }
+
+ static DisplayOptions g_options;
+};
+
+class FrameVariablesWindowDelegate : public ValueObjectListDelegate
+{
+public:
+ FrameVariablesWindowDelegate (Debugger &debugger) :
+ ValueObjectListDelegate (),
+ m_debugger (debugger),
+ m_frame_block (NULL)
+ {
+ }
+
+ virtual
+ ~FrameVariablesWindowDelegate()
+ {
+ }
+
+ virtual const char *
+ WindowDelegateGetHelpText ()
+ {
+ return "Frame variable window keyboard shortcuts:";
+ }
+
+ virtual bool
+ WindowDelegateDraw (Window &window, bool force)
+ {
+ ExecutionContext exe_ctx (m_debugger.GetCommandInterpreter().GetExecutionContext());
+ Process *process = exe_ctx.GetProcessPtr();
+ Block *frame_block = NULL;
+ StackFrame *frame = NULL;
+
+ if (process)
+ {
+ StateType state = process->GetState();
+ if (StateIsStoppedState(state, true))
+ {
+ frame = exe_ctx.GetFramePtr();
+ if (frame)
+ frame_block = frame->GetFrameBlock ();
+ }
+ else if (StateIsRunningState(state))
+ {
+ return true; // Don't do any updating when we are running
+ }
+ }
+
+ ValueObjectList local_values;
+ if (frame_block)
+ {
+ // Only update the variables if they have changed
+ if (m_frame_block != frame_block)
+ {
+ m_frame_block = frame_block;
+
+ VariableList *locals = frame->GetVariableList(true);
+ if (locals)
+ {
+ const DynamicValueType use_dynamic = eDynamicDontRunTarget;
+ const size_t num_locals = locals->GetSize();
+ for (size_t i=0; i<num_locals; ++i)
+ local_values.Append(frame->GetValueObjectForFrameVariable (locals->GetVariableAtIndex(i), use_dynamic));
+ // Update the values
+ SetValues(local_values);
+ }
+ }
+ }
+ else
+ {
+ m_frame_block = NULL;
+ // Update the values with an empty list if there is no frame
+ SetValues(local_values);
+ }
+
+ return ValueObjectListDelegate::WindowDelegateDraw (window, force);
+
+ }
+
+protected:
+ Debugger &m_debugger;
+ Block *m_frame_block;
+};
+
+
+class RegistersWindowDelegate : public ValueObjectListDelegate
+{
+public:
+ RegistersWindowDelegate (Debugger &debugger) :
+ ValueObjectListDelegate (),
+ m_debugger (debugger)
+ {
+ }
+
+ virtual
+ ~RegistersWindowDelegate()
+ {
+ }
+
+ virtual const char *
+ WindowDelegateGetHelpText ()
+ {
+ return "Register window keyboard shortcuts:";
+ }
+
+ virtual bool
+ WindowDelegateDraw (Window &window, bool force)
+ {
+ ExecutionContext exe_ctx (m_debugger.GetCommandInterpreter().GetExecutionContext());
+ StackFrame *frame = exe_ctx.GetFramePtr();
+
+ ValueObjectList value_list;
+ if (frame)
+ {
+ if (frame->GetStackID() != m_stack_id)
+ {
+ m_stack_id = frame->GetStackID();
+ RegisterContextSP reg_ctx (frame->GetRegisterContext());
+ if (reg_ctx)
+ {
+ const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
+ for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
+ {
+ value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
+ }
+ }
+ SetValues(value_list);
+ }
+ }
+ else
+ {
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process && process->IsAlive())
+ return true; // Don't do any updating if we are running
+ else
+ {
+ // Update the values with an empty list if there
+ // is no process or the process isn't alive anymore
+ SetValues(value_list);
+ }
+ }
+ return ValueObjectListDelegate::WindowDelegateDraw (window, force);
+ }
+
+protected:
+ Debugger &m_debugger;
+ StackID m_stack_id;
+};
+
+static const char *
+CursesKeyToCString (int ch)
+{
+ static char g_desc[32];
+ if (ch >= KEY_F0 && ch < KEY_F0 + 64)
+ {
+ snprintf(g_desc, sizeof(g_desc), "F%u", ch - KEY_F0);
+ return g_desc;
+ }
+ switch (ch)
+ {
+ case KEY_DOWN: return "down";
+ case KEY_UP: return "up";
+ case KEY_LEFT: return "left";
+ case KEY_RIGHT: return "right";
+ case KEY_HOME: return "home";
+ case KEY_BACKSPACE: return "backspace";
+ case KEY_DL: return "delete-line";
+ case KEY_IL: return "insert-line";
+ case KEY_DC: return "delete-char";
+ case KEY_IC: return "insert-char";
+ case KEY_CLEAR: return "clear";
+ case KEY_EOS: return "clear-to-eos";
+ case KEY_EOL: return "clear-to-eol";
+ case KEY_SF: return "scroll-forward";
+ case KEY_SR: return "scroll-backward";
+ case KEY_NPAGE: return "page-down";
+ case KEY_PPAGE: return "page-up";
+ case KEY_STAB: return "set-tab";
+ case KEY_CTAB: return "clear-tab";
+ case KEY_CATAB: return "clear-all-tabs";
+ case KEY_ENTER: return "enter";
+ case KEY_PRINT: return "print";
+ case KEY_LL: return "lower-left key";
+ case KEY_A1: return "upper left of keypad";
+ case KEY_A3: return "upper right of keypad";
+ case KEY_B2: return "center of keypad";
+ case KEY_C1: return "lower left of keypad";
+ case KEY_C3: return "lower right of keypad";
+ case KEY_BTAB: return "back-tab key";
+ case KEY_BEG: return "begin key";
+ case KEY_CANCEL: return "cancel key";
+ case KEY_CLOSE: return "close key";
+ case KEY_COMMAND: return "command key";
+ case KEY_COPY: return "copy key";
+ case KEY_CREATE: return "create key";
+ case KEY_END: return "end key";
+ case KEY_EXIT: return "exit key";
+ case KEY_FIND: return "find key";
+ case KEY_HELP: return "help key";
+ case KEY_MARK: return "mark key";
+ case KEY_MESSAGE: return "message key";
+ case KEY_MOVE: return "move key";
+ case KEY_NEXT: return "next key";
+ case KEY_OPEN: return "open key";
+ case KEY_OPTIONS: return "options key";
+ case KEY_PREVIOUS: return "previous key";
+ case KEY_REDO: return "redo key";
+ case KEY_REFERENCE: return "reference key";
+ case KEY_REFRESH: return "refresh key";
+ case KEY_REPLACE: return "replace key";
+ case KEY_RESTART: return "restart key";
+ case KEY_RESUME: return "resume key";
+ case KEY_SAVE: return "save key";
+ case KEY_SBEG: return "shifted begin key";
+ case KEY_SCANCEL: return "shifted cancel key";
+ case KEY_SCOMMAND: return "shifted command key";
+ case KEY_SCOPY: return "shifted copy key";
+ case KEY_SCREATE: return "shifted create key";
+ case KEY_SDC: return "shifted delete-character key";
+ case KEY_SDL: return "shifted delete-line key";
+ case KEY_SELECT: return "select key";
+ case KEY_SEND: return "shifted end key";
+ case KEY_SEOL: return "shifted clear-to-end-of-line key";
+ case KEY_SEXIT: return "shifted exit key";
+ case KEY_SFIND: return "shifted find key";
+ case KEY_SHELP: return "shifted help key";
+ case KEY_SHOME: return "shifted home key";
+ case KEY_SIC: return "shifted insert-character key";
+ case KEY_SLEFT: return "shifted left-arrow key";
+ case KEY_SMESSAGE: return "shifted message key";
+ case KEY_SMOVE: return "shifted move key";
+ case KEY_SNEXT: return "shifted next key";
+ case KEY_SOPTIONS: return "shifted options key";
+ case KEY_SPREVIOUS: return "shifted previous key";
+ case KEY_SPRINT: return "shifted print key";
+ case KEY_SREDO: return "shifted redo key";
+ case KEY_SREPLACE: return "shifted replace key";
+ case KEY_SRIGHT: return "shifted right-arrow key";
+ case KEY_SRSUME: return "shifted resume key";
+ case KEY_SSAVE: return "shifted save key";
+ case KEY_SSUSPEND: return "shifted suspend key";
+ case KEY_SUNDO: return "shifted undo key";
+ case KEY_SUSPEND: return "suspend key";
+ case KEY_UNDO: return "undo key";
+ case KEY_MOUSE: return "Mouse event has occurred";
+ case KEY_RESIZE: return "Terminal resize event";
+ case KEY_EVENT: return "We were interrupted by an event";
+ case KEY_RETURN: return "return";
+ case ' ': return "space";
+ case '\t': return "tab";
+ case KEY_ESCAPE: return "escape";
+ default:
+ if (isprint(ch))
+ snprintf(g_desc, sizeof(g_desc), "%c", ch);
+ else
+ snprintf(g_desc, sizeof(g_desc), "\\x%2.2x", ch);
+ return g_desc;
+ }
+ return NULL;
+}
+
+HelpDialogDelegate::HelpDialogDelegate (const char *text, KeyHelp *key_help_array) :
+ m_text (),
+ m_first_visible_line (0)
+{
+ if (text && text[0])
+ {
+ m_text.SplitIntoLines(text);
+ m_text.AppendString("");
+ }
+ if (key_help_array)
+ {
+ for (KeyHelp *key = key_help_array; key->ch; ++key)
+ {
+ StreamString key_description;
+ key_description.Printf("%10s - %s", CursesKeyToCString(key->ch), key->description);
+ m_text.AppendString(std::move(key_description.GetString()));
+ }
+ }
+}
+
+HelpDialogDelegate::~HelpDialogDelegate()
+{
+}
+
+bool
+HelpDialogDelegate::WindowDelegateDraw (Window &window, bool force)
+{
+ window.Erase();
+ const int window_height = window.GetHeight();
+ int x = 2;
+ int y = 1;
+ const int min_y = y;
+ const int max_y = window_height - 1 - y;
+ const int num_visible_lines = max_y - min_y + 1;
+ const size_t num_lines = m_text.GetSize();
+ const char *bottom_message;
+ if (num_lines <= num_visible_lines)
+ bottom_message = "Press any key to exit";
+ else
+ bottom_message = "Use arrows to scroll, any other key to exit";
+ window.DrawTitleBox(window.GetName(), bottom_message);
+ while (y <= max_y)
+ {
+ window.MoveCursor(x, y);
+ window.PutCStringTruncated(m_text.GetStringAtIndex(m_first_visible_line + y - min_y), 1);
+ ++y;
+ }
+ return true;
+}
+
+HandleCharResult
+HelpDialogDelegate::WindowDelegateHandleChar (Window &window, int key)
+{
+ bool done = false;
+ const size_t num_lines = m_text.GetSize();
+ const size_t num_visible_lines = window.GetHeight() - 2;
+
+ if (num_lines <= num_visible_lines)
+ {
+ done = true;
+ // If we have all lines visible and don't need scrolling, then any
+ // key press will cause us to exit
+ }
+ else
+ {
+ switch (key)
+ {
+ case KEY_UP:
+ if (m_first_visible_line > 0)
+ --m_first_visible_line;
+ break;
+
+ case KEY_DOWN:
+ if (m_first_visible_line + num_visible_lines < num_lines)
+ ++m_first_visible_line;
+ break;
+
+ case KEY_PPAGE:
+ case ',':
+ if (m_first_visible_line > 0)
+ {
+ if (m_first_visible_line >= num_visible_lines)
+ m_first_visible_line -= num_visible_lines;
+ else
+ m_first_visible_line = 0;
+ }
+ break;
+ case KEY_NPAGE:
+ case '.':
+ if (m_first_visible_line + num_visible_lines < num_lines)
+ {
+ m_first_visible_line += num_visible_lines;
+ if (m_first_visible_line > num_lines)
+ m_first_visible_line = num_lines - num_visible_lines;
+ }
+ break;
+ default:
+ done = true;
+ break;
+ }
+ }
+ if (done)
+ window.GetParent()->RemoveSubWindow(&window);
+ return eKeyHandled;
+}
+
+class ApplicationDelegate :
+ public WindowDelegate,
+ public MenuDelegate
+{
+public:
+ enum {
+ eMenuID_LLDB = 1,
+ eMenuID_LLDBAbout,
+ eMenuID_LLDBExit,
+
+ eMenuID_Target,
+ eMenuID_TargetCreate,
+ eMenuID_TargetDelete,
+
+ eMenuID_Process,
+ eMenuID_ProcessAttach,
+ eMenuID_ProcessDetach,
+ eMenuID_ProcessLaunch,
+ eMenuID_ProcessContinue,
+ eMenuID_ProcessHalt,
+ eMenuID_ProcessKill,
+
+ eMenuID_Thread,
+ eMenuID_ThreadStepIn,
+ eMenuID_ThreadStepOver,
+ eMenuID_ThreadStepOut,
+
+ eMenuID_View,
+ eMenuID_ViewBacktrace,
+ eMenuID_ViewRegisters,
+ eMenuID_ViewSource,
+ eMenuID_ViewVariables,
+
+ eMenuID_Help,
+ eMenuID_HelpGUIHelp
+ };
+
+ ApplicationDelegate (Application &app, Debugger &debugger) :
+ WindowDelegate (),
+ MenuDelegate (),
+ m_app (app),
+ m_debugger (debugger)
+ {
+ }
+
+ virtual
+ ~ApplicationDelegate ()
+ {
+ }
+ virtual bool
+ WindowDelegateDraw (Window &window, bool force)
+ {
+ return false; // Drawing not handled, let standard window drawing happen
+ }
+
+ virtual HandleCharResult
+ WindowDelegateHandleChar (Window &window, int key)
+ {
+ switch (key)
+ {
+ case '\t':
+ window.SelectNextWindowAsActive();
+ return eKeyHandled;
+
+ case 'h':
+ window.CreateHelpSubwindow();
+ return eKeyHandled;
+
+ case KEY_ESCAPE:
+ return eQuitApplication;
+
+ default:
+ break;
+ }
+ return eKeyNotHandled;
+ }
+
+
+ virtual const char *
+ WindowDelegateGetHelpText ()
+ {
+ return "Welcome to the LLDB curses GUI.\n\n"
+ "Press the TAB key to change the selected view.\n"
+ "Each view has its own keyboard shortcuts, press 'h' to open a dialog to display them.\n\n"
+ "Common key bindings for all views:";
+ }
+
+ virtual KeyHelp *
+ WindowDelegateGetKeyHelp ()
+ {
+ static curses::KeyHelp g_source_view_key_help[] = {
+ { '\t', "Select next view" },
+ { 'h', "Show help dialog with view specific key bindings" },
+ { ',', "Page up" },
+ { '.', "Page down" },
+ { KEY_UP, "Select previous" },
+ { KEY_DOWN, "Select next" },
+ { KEY_LEFT, "Unexpand or select parent" },
+ { KEY_RIGHT, "Expand" },
+ { KEY_PPAGE, "Page up" },
+ { KEY_NPAGE, "Page down" },
+ { '\0', NULL }
+ };
+ return g_source_view_key_help;
+ }
+
+ virtual MenuActionResult
+ MenuDelegateAction (Menu &menu)
+ {
+ switch (menu.GetIdentifier())
+ {
+ case eMenuID_ThreadStepIn:
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasThreadScope())
+ {
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process && process->IsAlive() && StateIsStoppedState (process->GetState(), true))
+ exe_ctx.GetThreadRef().StepIn(true, true);
+ }
+ }
+ return MenuActionResult::Handled;
+
+ case eMenuID_ThreadStepOut:
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasThreadScope())
+ {
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process && process->IsAlive() && StateIsStoppedState (process->GetState(), true))
+ exe_ctx.GetThreadRef().StepOut();
+ }
+ }
+ return MenuActionResult::Handled;
+
+ case eMenuID_ThreadStepOver:
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasThreadScope())
+ {
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process && process->IsAlive() && StateIsStoppedState (process->GetState(), true))
+ exe_ctx.GetThreadRef().StepOver(true);
+ }
+ }
+ return MenuActionResult::Handled;
+
+ case eMenuID_ProcessContinue:
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasProcessScope())
+ {
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process && process->IsAlive() && StateIsStoppedState (process->GetState(), true))
+ process->Resume();
+ }
+ }
+ return MenuActionResult::Handled;
+
+ case eMenuID_ProcessKill:
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasProcessScope())
+ {
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process && process->IsAlive())
+ process->Destroy();
+ }
+ }
+ return MenuActionResult::Handled;
+
+ case eMenuID_ProcessHalt:
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasProcessScope())
+ {
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process && process->IsAlive())
+ process->Halt();
+ }
+ }
+ return MenuActionResult::Handled;
+
+ case eMenuID_ProcessDetach:
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasProcessScope())
+ {
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process && process->IsAlive())
+ process->Detach(false);
+ }
+ }
+ return MenuActionResult::Handled;
+
+ case eMenuID_Process:
+ {
+ // Populate the menu with all of the threads if the process is stopped when
+ // the Process menu gets selected and is about to display its submenu.
+ Menus &submenus = menu.GetSubmenus();
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process && process->IsAlive() && StateIsStoppedState (process->GetState(), true))
+ {
+ if (submenus.size() == 7)
+ menu.AddSubmenu (MenuSP (new Menu(Menu::Type::Separator)));
+ else if (submenus.size() > 8)
+ submenus.erase (submenus.begin() + 8, submenus.end());
+
+ ThreadList &threads = process->GetThreadList();
+ Mutex::Locker locker (threads.GetMutex());
+ size_t num_threads = threads.GetSize();
+ for (size_t i=0; i<num_threads; ++i)
+ {
+ ThreadSP thread_sp = threads.GetThreadAtIndex(i);
+ char menu_char = '\0';
+ if (i < 9)
+ menu_char = '1' + i;
+ StreamString thread_menu_title;
+ thread_menu_title.Printf("Thread %u", thread_sp->GetIndexID());
+ const char *thread_name = thread_sp->GetName();
+ if (thread_name && thread_name[0])
+ thread_menu_title.Printf (" %s", thread_name);
+ else
+ {
+ const char *queue_name = thread_sp->GetQueueName();
+ if (queue_name && queue_name[0])
+ thread_menu_title.Printf (" %s", queue_name);
+ }
+ menu.AddSubmenu (MenuSP (new Menu(thread_menu_title.GetString().c_str(), NULL, menu_char, thread_sp->GetID())));
+ }
+ }
+ else if (submenus.size() > 7)
+ {
+ // Remove the separator and any other thread submenu items
+ // that were previously added
+ submenus.erase (submenus.begin() + 7, submenus.end());
+ }
+ // Since we are adding and removing items we need to recalculate the name lengths
+ menu.RecalculateNameLengths();
+ }
+ return MenuActionResult::Handled;
+
+ case eMenuID_ViewVariables:
+ {
+ WindowSP main_window_sp = m_app.GetMainWindow();
+ WindowSP source_window_sp = main_window_sp->FindSubWindow("Source");
+ WindowSP variables_window_sp = main_window_sp->FindSubWindow("Variables");
+ WindowSP registers_window_sp = main_window_sp->FindSubWindow("Registers");
+ const Rect source_bounds = source_window_sp->GetBounds();
+
+ if (variables_window_sp)
+ {
+ const Rect variables_bounds = variables_window_sp->GetBounds();
+
+ main_window_sp->RemoveSubWindow(variables_window_sp.get());
+
+ if (registers_window_sp)
+ {
+ // We have a registers window, so give all the area back to the registers window
+ Rect registers_bounds = variables_bounds;
+ registers_bounds.size.width = source_bounds.size.width;
+ registers_window_sp->SetBounds(registers_bounds);
+ }
+ else
+ {
+ // We have no registers window showing so give the bottom
+ // area back to the source view
+ source_window_sp->Resize (source_bounds.size.width,
+ source_bounds.size.height + variables_bounds.size.height);
+ }
+ }
+ else
+ {
+ Rect new_variables_rect;
+ if (registers_window_sp)
+ {
+ // We have a registers window so split the area of the registers
+ // window into two columns where the left hand side will be the
+ // variables and the right hand side will be the registers
+ const Rect variables_bounds = registers_window_sp->GetBounds();
+ Rect new_registers_rect;
+ variables_bounds.VerticalSplitPercentage (0.50, new_variables_rect, new_registers_rect);
+ registers_window_sp->SetBounds (new_registers_rect);
+ }
+ else
+ {
+ // No variables window, grab the bottom part of the source window
+ Rect new_source_rect;
+ source_bounds.HorizontalSplitPercentage (0.70, new_source_rect, new_variables_rect);
+ source_window_sp->SetBounds (new_source_rect);
+ }
+ WindowSP new_window_sp = main_window_sp->CreateSubWindow ("Variables",
+ new_variables_rect,
+ false);
+ new_window_sp->SetDelegate (WindowDelegateSP(new FrameVariablesWindowDelegate(m_debugger)));
+ }
+ touchwin(stdscr);
+ }
+ return MenuActionResult::Handled;
+
+ case eMenuID_ViewRegisters:
+ {
+ WindowSP main_window_sp = m_app.GetMainWindow();
+ WindowSP source_window_sp = main_window_sp->FindSubWindow("Source");
+ WindowSP variables_window_sp = main_window_sp->FindSubWindow("Variables");
+ WindowSP registers_window_sp = main_window_sp->FindSubWindow("Registers");
+ const Rect source_bounds = source_window_sp->GetBounds();
+
+ if (registers_window_sp)
+ {
+ if (variables_window_sp)
+ {
+ const Rect variables_bounds = variables_window_sp->GetBounds();
+
+ // We have a variables window, so give all the area back to the variables window
+ variables_window_sp->Resize (variables_bounds.size.width + registers_window_sp->GetWidth(),
+ variables_bounds.size.height);
+ }
+ else
+ {
+ // We have no variables window showing so give the bottom
+ // area back to the source view
+ source_window_sp->Resize (source_bounds.size.width,
+ source_bounds.size.height + registers_window_sp->GetHeight());
+ }
+ main_window_sp->RemoveSubWindow(registers_window_sp.get());
+ }
+ else
+ {
+ Rect new_regs_rect;
+ if (variables_window_sp)
+ {
+ // We have a variables window, split it into two columns
+ // where the left hand side will be the variables and the
+ // right hand side will be the registers
+ const Rect variables_bounds = variables_window_sp->GetBounds();
+ Rect new_vars_rect;
+ variables_bounds.VerticalSplitPercentage (0.50, new_vars_rect, new_regs_rect);
+ variables_window_sp->SetBounds (new_vars_rect);
+ }
+ else
+ {
+ // No registers window, grab the bottom part of the source window
+ Rect new_source_rect;
+ source_bounds.HorizontalSplitPercentage (0.70, new_source_rect, new_regs_rect);
+ source_window_sp->SetBounds (new_source_rect);
+ }
+ WindowSP new_window_sp = main_window_sp->CreateSubWindow ("Registers",
+ new_regs_rect,
+ false);
+ new_window_sp->SetDelegate (WindowDelegateSP(new RegistersWindowDelegate(m_debugger)));
+ }
+ touchwin(stdscr);
+ }
+ return MenuActionResult::Handled;
+
+ case eMenuID_HelpGUIHelp:
+ m_app.GetMainWindow ()->CreateHelpSubwindow();
+ return MenuActionResult::Handled;
+
+ default:
+ break;
+ }
+
+ return MenuActionResult::NotHandled;
+ }
+protected:
+ Application &m_app;
+ Debugger &m_debugger;
+};
+
+
+class StatusBarWindowDelegate : public WindowDelegate
+{
+public:
+ StatusBarWindowDelegate (Debugger &debugger) :
+ m_debugger (debugger)
+ {
+ }
+
+ virtual
+ ~StatusBarWindowDelegate ()
+ {
+ }
+ virtual bool
+ WindowDelegateDraw (Window &window, bool force)
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ Process *process = exe_ctx.GetProcessPtr();
+ Thread *thread = exe_ctx.GetThreadPtr();
+ StackFrame *frame = exe_ctx.GetFramePtr();
+ window.Erase();
+ window.SetBackground(2);
+ window.MoveCursor (0, 0);
+ if (process)
+ {
+ const StateType state = process->GetState();
+ window.Printf ("Process: %5" PRIu64 " %10s", process->GetID(), StateAsCString(state));
+
+ if (StateIsStoppedState(state, true))
+ {
+ window.MoveCursor (40, 0);
+ if (thread)
+ window.Printf ("Thread: 0x%4.4" PRIx64, thread->GetID());
+
+ window.MoveCursor (60, 0);
+ if (frame)
+ window.Printf ("Frame: %3u PC = 0x%16.16" PRIx64, frame->GetFrameIndex(), frame->GetFrameCodeAddress().GetOpcodeLoadAddress (exe_ctx.GetTargetPtr()));
+ }
+ else if (state == eStateExited)
+ {
+ const char *exit_desc = process->GetExitDescription();
+ const int exit_status = process->GetExitStatus();
+ if (exit_desc && exit_desc[0])
+ window.Printf (" with status = %i (%s)", exit_status, exit_desc);
+ else
+ window.Printf (" with status = %i", exit_status);
+ }
+ }
+ window.DeferredRefresh();
+ return true;
+ }
+
+protected:
+ Debugger &m_debugger;
+};
+
+class SourceFileWindowDelegate : public WindowDelegate
+{
+public:
+ SourceFileWindowDelegate (Debugger &debugger) :
+ WindowDelegate (),
+ m_debugger (debugger),
+ m_sc (),
+ m_file_sp (),
+ m_disassembly_scope (NULL),
+ m_disassembly_sp (),
+ m_disassembly_range (),
+ m_line_width (4),
+ m_selected_line (0),
+ m_pc_line (0),
+ m_stop_id (0),
+ m_frame_idx (UINT32_MAX),
+ m_first_visible_line (0),
+ m_min_x (0),
+ m_min_y (0),
+ m_max_x (0),
+ m_max_y (0)
+ {
+ }
+
+
+ virtual
+ ~SourceFileWindowDelegate()
+ {
+ }
+
+ void
+ Update (const SymbolContext &sc)
+ {
+ m_sc = sc;
+ }
+
+ uint32_t
+ NumVisibleLines () const
+ {
+ return m_max_y - m_min_y;
+ }
+
+ virtual const char *
+ WindowDelegateGetHelpText ()
+ {
+ return "Source/Disassembly window keyboard shortcuts:";
+ }
+
+ virtual KeyHelp *
+ WindowDelegateGetKeyHelp ()
+ {
+ static curses::KeyHelp g_source_view_key_help[] = {
+ { KEY_RETURN, "Run to selected line with one shot breakpoint" },
+ { KEY_UP, "Select previous source line" },
+ { KEY_DOWN, "Select next source line" },
+ { KEY_PPAGE, "Page up" },
+ { KEY_NPAGE, "Page down" },
+ { 'b', "Set breakpoint on selected source/disassembly line" },
+ { 'c', "Continue process" },
+ { 'd', "Detach and resume process" },
+ { 'D', "Detach with process suspended" },
+ { 'h', "Show help dialog" },
+ { 'k', "Kill process" },
+ { 'n', "Step over (source line)" },
+ { 'N', "Step over (single instruction)" },
+ { 'o', "Step out" },
+ { 's', "Step in (source line)" },
+ { 'S', "Step in (single instruction)" },
+ { ',', "Page up" },
+ { '.', "Page down" },
+ { '\0', NULL }
+ };
+ return g_source_view_key_help;
+ }
+
+ virtual bool
+ WindowDelegateDraw (Window &window, bool force)
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ Process *process = exe_ctx.GetProcessPtr();
+ Thread *thread = NULL;
+
+ bool update_location = false;
+ if (process)
+ {
+ StateType state = process->GetState();
+ if (StateIsStoppedState(state, true))
+ {
+ // We are stopped, so it is ok to
+ update_location = true;
+ }
+ }
+
+ m_min_x = 1;
+ m_min_y = 1;
+ m_max_x = window.GetMaxX()-1;
+ m_max_y = window.GetMaxY()-1;
+
+ const uint32_t num_visible_lines = NumVisibleLines();
+ StackFrameSP frame_sp;
+ bool set_selected_line_to_pc = false;
+
+
+ if (update_location)
+ {
+
+ const bool process_alive = process ? process->IsAlive() : false;
+ bool thread_changed = false;
+ if (process_alive)
+ {
+ thread = exe_ctx.GetThreadPtr();
+ if (thread)
+ {
+ frame_sp = thread->GetSelectedFrame();
+ auto tid = thread->GetID();
+ thread_changed = tid != m_tid;
+ m_tid = tid;
+ }
+ else
+ {
+ if (m_tid != LLDB_INVALID_THREAD_ID)
+ {
+ thread_changed = true;
+ m_tid = LLDB_INVALID_THREAD_ID;
+ }
+ }
+ }
+ const uint32_t stop_id = process ? process->GetStopID() : 0;
+ const bool stop_id_changed = stop_id != m_stop_id;
+ bool frame_changed = false;
+ m_stop_id = stop_id;
+ if (frame_sp)
+ {
+ m_sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
+ const uint32_t frame_idx = frame_sp->GetFrameIndex();
+ frame_changed = frame_idx != m_frame_idx;
+ m_frame_idx = frame_idx;
+ }
+ else
+ {
+ m_sc.Clear(true);
+ frame_changed = m_frame_idx != UINT32_MAX;
+ m_frame_idx = UINT32_MAX;
+ }
+
+ const bool context_changed = thread_changed || frame_changed || stop_id_changed;
+
+ if (process_alive)
+ {
+ if (m_sc.line_entry.IsValid())
+ {
+ m_pc_line = m_sc.line_entry.line;
+ if (m_pc_line != UINT32_MAX)
+ --m_pc_line; // Convert to zero based line number...
+ // Update the selected line if the stop ID changed...
+ if (context_changed)
+ m_selected_line = m_pc_line;
+
+ if (m_file_sp && m_file_sp->FileSpecMatches(m_sc.line_entry.file))
+ {
+ // Same file, nothing to do, we should either have the
+ // lines or not (source file missing)
+ if (m_selected_line >= m_first_visible_line)
+ {
+ if (m_selected_line >= m_first_visible_line + num_visible_lines)
+ m_first_visible_line = m_selected_line - 10;
+ }
+ else
+ {
+ if (m_selected_line > 10)
+ m_first_visible_line = m_selected_line - 10;
+ else
+ m_first_visible_line = 0;
+ }
+ }
+ else
+ {
+ // File changed, set selected line to the line with the PC
+ m_selected_line = m_pc_line;
+ m_file_sp = m_debugger.GetSourceManager().GetFile(m_sc.line_entry.file);
+ if (m_file_sp)
+ {
+ const size_t num_lines = m_file_sp->GetNumLines();
+ int m_line_width = 1;
+ for (size_t n = num_lines; n >= 10; n = n / 10)
+ ++m_line_width;
+
+ snprintf (m_line_format, sizeof(m_line_format), " %%%iu ", m_line_width);
+ if (num_lines < num_visible_lines || m_selected_line < num_visible_lines)
+ m_first_visible_line = 0;
+ else
+ m_first_visible_line = m_selected_line - 10;
+ }
+ }
+ }
+ else
+ {
+ m_file_sp.reset();
+ }
+
+ if (!m_file_sp || m_file_sp->GetNumLines() == 0)
+ {
+ // Show disassembly
+ bool prefer_file_cache = false;
+ if (m_sc.function)
+ {
+ if (m_disassembly_scope != m_sc.function)
+ {
+ m_disassembly_scope = m_sc.function;
+ m_disassembly_sp = m_sc.function->GetInstructions (exe_ctx, NULL, prefer_file_cache);
+ if (m_disassembly_sp)
+ {
+ set_selected_line_to_pc = true;
+ m_disassembly_range = m_sc.function->GetAddressRange();
+ }
+ else
+ {
+ m_disassembly_range.Clear();
+ }
+ }
+ else
+ {
+ set_selected_line_to_pc = context_changed;
+ }
+ }
+ else if (m_sc.symbol)
+ {
+ if (m_disassembly_scope != m_sc.symbol)
+ {
+ m_disassembly_scope = m_sc.symbol;
+ m_disassembly_sp = m_sc.symbol->GetInstructions (exe_ctx, NULL, prefer_file_cache);
+ if (m_disassembly_sp)
+ {
+ set_selected_line_to_pc = true;
+ m_disassembly_range.GetBaseAddress() = m_sc.symbol->GetAddress();
+ m_disassembly_range.SetByteSize(m_sc.symbol->GetByteSize());
+ }
+ else
+ {
+ m_disassembly_range.Clear();
+ }
+ }
+ else
+ {
+ set_selected_line_to_pc = context_changed;
+ }
+ }
+ }
+ }
+ else
+ {
+ m_pc_line = UINT32_MAX;
+ }
+ }
+
+
+ window.Erase();
+ window.DrawTitleBox ("Sources");
+
+
+ Target *target = exe_ctx.GetTargetPtr();
+ const size_t num_source_lines = GetNumSourceLines();
+ if (num_source_lines > 0)
+ {
+ // Display source
+ BreakpointLines bp_lines;
+ if (target)
+ {
+ BreakpointList &bp_list = target->GetBreakpointList();
+ const size_t num_bps = bp_list.GetSize();
+ for (size_t bp_idx=0; bp_idx<num_bps; ++bp_idx)
+ {
+ BreakpointSP bp_sp = bp_list.GetBreakpointAtIndex(bp_idx);
+ const size_t num_bps_locs = bp_sp->GetNumLocations();
+ for (size_t bp_loc_idx=0; bp_loc_idx<num_bps_locs; ++bp_loc_idx)
+ {
+ BreakpointLocationSP bp_loc_sp = bp_sp->GetLocationAtIndex(bp_loc_idx);
+ LineEntry bp_loc_line_entry;
+ if (bp_loc_sp->GetAddress().CalculateSymbolContextLineEntry (bp_loc_line_entry))
+ {
+ if (m_file_sp->GetFileSpec() == bp_loc_line_entry.file)
+ {
+ bp_lines.insert(bp_loc_line_entry.line);
+ }
+ }
+ }
+ }
+ }
+
+
+ const attr_t selected_highlight_attr = A_REVERSE;
+ const attr_t pc_highlight_attr = COLOR_PAIR(1);
+
+ for (int i=0; i<num_visible_lines; ++i)
+ {
+ const uint32_t curr_line = m_first_visible_line + i;
+ if (curr_line < num_source_lines)
+ {
+ const int line_y = 1+i;
+ window.MoveCursor(1, line_y);
+ const bool is_pc_line = curr_line == m_pc_line;
+ const bool line_is_selected = m_selected_line == curr_line;
+ // Highlight the line as the PC line first, then if the selected line
+ // isn't the same as the PC line, highlight it differently
+ attr_t highlight_attr = 0;
+ attr_t bp_attr = 0;
+ if (is_pc_line)
+ highlight_attr = pc_highlight_attr;
+ else if (line_is_selected)
+ highlight_attr = selected_highlight_attr;
+
+ if (bp_lines.find(curr_line+1) != bp_lines.end())
+ bp_attr = COLOR_PAIR(2);
+
+ if (bp_attr)
+ window.AttributeOn(bp_attr);
+
+ window.Printf (m_line_format, curr_line + 1);
+
+ if (bp_attr)
+ window.AttributeOff(bp_attr);
+
+ window.PutChar(ACS_VLINE);
+ // Mark the line with the PC with a diamond
+ if (is_pc_line)
+ window.PutChar(ACS_DIAMOND);
+ else
+ window.PutChar(' ');
+
+ if (highlight_attr)
+ window.AttributeOn(highlight_attr);
+ const uint32_t line_len = m_file_sp->GetLineLength(curr_line + 1, false);
+ if (line_len > 0)
+ window.PutCString(m_file_sp->PeekLineData(curr_line + 1), line_len);
+
+ if (is_pc_line && frame_sp && frame_sp->GetConcreteFrameIndex() == 0)
+ {
+ StopInfoSP stop_info_sp;
+ if (thread)
+ stop_info_sp = thread->GetStopInfo();
+ if (stop_info_sp)
+ {
+ const char *stop_description = stop_info_sp->GetDescription();
+ if (stop_description && stop_description[0])
+ {
+ size_t stop_description_len = strlen(stop_description);
+ int desc_x = window.GetWidth() - stop_description_len - 16;
+ window.Printf ("%*s", desc_x - window.GetCursorX(), "");
+ //window.MoveCursor(window.GetWidth() - stop_description_len - 15, line_y);
+ window.Printf ("<<< Thread %u: %s ", thread->GetIndexID(), stop_description);
+ }
+ }
+ else
+ {
+ window.Printf ("%*s", window.GetWidth() - window.GetCursorX() - 1, "");
+ }
+ }
+ if (highlight_attr)
+ window.AttributeOff(highlight_attr);
+
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ else
+ {
+ size_t num_disassembly_lines = GetNumDisassemblyLines();
+ if (num_disassembly_lines > 0)
+ {
+ // Display disassembly
+ BreakpointAddrs bp_file_addrs;
+ Target *target = exe_ctx.GetTargetPtr();
+ if (target)
+ {
+ BreakpointList &bp_list = target->GetBreakpointList();
+ const size_t num_bps = bp_list.GetSize();
+ for (size_t bp_idx=0; bp_idx<num_bps; ++bp_idx)
+ {
+ BreakpointSP bp_sp = bp_list.GetBreakpointAtIndex(bp_idx);
+ const size_t num_bps_locs = bp_sp->GetNumLocations();
+ for (size_t bp_loc_idx=0; bp_loc_idx<num_bps_locs; ++bp_loc_idx)
+ {
+ BreakpointLocationSP bp_loc_sp = bp_sp->GetLocationAtIndex(bp_loc_idx);
+ LineEntry bp_loc_line_entry;
+ const lldb::addr_t file_addr = bp_loc_sp->GetAddress().GetFileAddress();
+ if (file_addr != LLDB_INVALID_ADDRESS)
+ {
+ if (m_disassembly_range.ContainsFileAddress(file_addr))
+ bp_file_addrs.insert(file_addr);
+ }
+ }
+ }
+ }
+
+
+ const attr_t selected_highlight_attr = A_REVERSE;
+ const attr_t pc_highlight_attr = COLOR_PAIR(1);
+
+ StreamString strm;
+
+ InstructionList &insts = m_disassembly_sp->GetInstructionList();
+ Address pc_address;
+
+ if (frame_sp)
+ pc_address = frame_sp->GetFrameCodeAddress();
+ const uint32_t pc_idx = pc_address.IsValid() ? insts.GetIndexOfInstructionAtAddress (pc_address) : UINT32_MAX;
+ if (set_selected_line_to_pc)
+ {
+ m_selected_line = pc_idx;
+ }
+
+ const uint32_t non_visible_pc_offset = (num_visible_lines / 5);
+ if (m_first_visible_line >= num_disassembly_lines)
+ m_first_visible_line = 0;
+
+ if (pc_idx < num_disassembly_lines)
+ {
+ if (pc_idx < m_first_visible_line ||
+ pc_idx >= m_first_visible_line + num_visible_lines)
+ m_first_visible_line = pc_idx - non_visible_pc_offset;
+ }
+
+ for (size_t i=0; i<num_visible_lines; ++i)
+ {
+ const uint32_t inst_idx = m_first_visible_line + i;
+ Instruction *inst = insts.GetInstructionAtIndex(inst_idx).get();
+ if (!inst)
+ break;
+
+ window.MoveCursor(1, i+1);
+ const bool is_pc_line = frame_sp && inst_idx == pc_idx;
+ const bool line_is_selected = m_selected_line == inst_idx;
+ // Highlight the line as the PC line first, then if the selected line
+ // isn't the same as the PC line, highlight it differently
+ attr_t highlight_attr = 0;
+ attr_t bp_attr = 0;
+ if (is_pc_line)
+ highlight_attr = pc_highlight_attr;
+ else if (line_is_selected)
+ highlight_attr = selected_highlight_attr;
+
+ if (bp_file_addrs.find(inst->GetAddress().GetFileAddress()) != bp_file_addrs.end())
+ bp_attr = COLOR_PAIR(2);
+
+ if (bp_attr)
+ window.AttributeOn(bp_attr);
+
+ window.Printf (" 0x%16.16llx ", inst->GetAddress().GetLoadAddress(target));
+
+ if (bp_attr)
+ window.AttributeOff(bp_attr);
+
+ window.PutChar(ACS_VLINE);
+ // Mark the line with the PC with a diamond
+ if (is_pc_line)
+ window.PutChar(ACS_DIAMOND);
+ else
+ window.PutChar(' ');
+
+ if (highlight_attr)
+ window.AttributeOn(highlight_attr);
+
+ const char *mnemonic = inst->GetMnemonic(&exe_ctx);
+ const char *operands = inst->GetOperands(&exe_ctx);
+ const char *comment = inst->GetComment(&exe_ctx);
+
+ if (mnemonic && mnemonic[0] == '\0')
+ mnemonic = NULL;
+ if (operands && operands[0] == '\0')
+ operands = NULL;
+ if (comment && comment[0] == '\0')
+ comment = NULL;
+
+ strm.Clear();
+
+ if (mnemonic && operands && comment)
+ strm.Printf ("%-8s %-25s ; %s", mnemonic, operands, comment);
+ else if (mnemonic && operands)
+ strm.Printf ("%-8s %s", mnemonic, operands);
+ else if (mnemonic)
+ strm.Printf ("%s", mnemonic);
+
+ int right_pad = 1;
+ window.PutCStringTruncated(strm.GetString().c_str(), right_pad);
+
+ if (is_pc_line && frame_sp && frame_sp->GetConcreteFrameIndex() == 0)
+ {
+ StopInfoSP stop_info_sp;
+ if (thread)
+ stop_info_sp = thread->GetStopInfo();
+ if (stop_info_sp)
+ {
+ const char *stop_description = stop_info_sp->GetDescription();
+ if (stop_description && stop_description[0])
+ {
+ size_t stop_description_len = strlen(stop_description);
+ int desc_x = window.GetWidth() - stop_description_len - 16;
+ window.Printf ("%*s", desc_x - window.GetCursorX(), "");
+ //window.MoveCursor(window.GetWidth() - stop_description_len - 15, line_y);
+ window.Printf ("<<< Thread %u: %s ", thread->GetIndexID(), stop_description);
+ }
+ }
+ else
+ {
+ window.Printf ("%*s", window.GetWidth() - window.GetCursorX() - 1, "");
+ }
+ }
+ if (highlight_attr)
+ window.AttributeOff(highlight_attr);
+ }
+ }
+ }
+ window.DeferredRefresh();
+ return true; // Drawing handled
+ }
+
+ size_t
+ GetNumLines ()
+ {
+ size_t num_lines = GetNumSourceLines();
+ if (num_lines == 0)
+ num_lines = GetNumDisassemblyLines();
+ return num_lines;
+ }
+
+ size_t
+ GetNumSourceLines () const
+ {
+ if (m_file_sp)
+ return m_file_sp->GetNumLines();
+ return 0;
+ }
+ size_t
+ GetNumDisassemblyLines () const
+ {
+ if (m_disassembly_sp)
+ return m_disassembly_sp->GetInstructionList().GetSize();
+ return 0;
+ }
+
+ virtual HandleCharResult
+ WindowDelegateHandleChar (Window &window, int c)
+ {
+ const uint32_t num_visible_lines = NumVisibleLines();
+ const size_t num_lines = GetNumLines ();
+
+ switch (c)
+ {
+ case ',':
+ case KEY_PPAGE:
+ // Page up key
+ if (m_first_visible_line > num_visible_lines)
+ m_first_visible_line -= num_visible_lines;
+ else
+ m_first_visible_line = 0;
+ m_selected_line = m_first_visible_line;
+ return eKeyHandled;
+
+ case '.':
+ case KEY_NPAGE:
+ // Page down key
+ {
+ if (m_first_visible_line + num_visible_lines < num_lines)
+ m_first_visible_line += num_visible_lines;
+ else if (num_lines < num_visible_lines)
+ m_first_visible_line = 0;
+ else
+ m_first_visible_line = num_lines - num_visible_lines;
+ m_selected_line = m_first_visible_line;
+ }
+ return eKeyHandled;
+
+ case KEY_UP:
+ if (m_selected_line > 0)
+ {
+ m_selected_line--;
+ if (m_first_visible_line > m_selected_line)
+ m_first_visible_line = m_selected_line;
+ }
+ return eKeyHandled;
+
+ case KEY_DOWN:
+ if (m_selected_line + 1 < num_lines)
+ {
+ m_selected_line++;
+ if (m_first_visible_line + num_visible_lines < m_selected_line)
+ m_first_visible_line++;
+ }
+ return eKeyHandled;
+
+ case '\r':
+ case '\n':
+ case KEY_ENTER:
+ // Set a breakpoint and run to the line using a one shot breakpoint
+ if (GetNumSourceLines() > 0)
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasProcessScope() && exe_ctx.GetProcessRef().IsAlive())
+ {
+ BreakpointSP bp_sp = exe_ctx.GetTargetRef().CreateBreakpoint (NULL, // Don't limit the breakpoint to certain modules
+ m_file_sp->GetFileSpec(), // Source file
+ m_selected_line + 1, // Source line number (m_selected_line is zero based)
+ eLazyBoolCalculate, // Check inlines using global setting
+ eLazyBoolCalculate, // Skip prologue using global setting,
+ false, // internal
+ false); // request_hardware
+ // Make breakpoint one shot
+ bp_sp->GetOptions()->SetOneShot(true);
+ exe_ctx.GetProcessRef().Resume();
+ }
+ }
+ else if (m_selected_line < GetNumDisassemblyLines())
+ {
+ const Instruction *inst = m_disassembly_sp->GetInstructionList().GetInstructionAtIndex(m_selected_line).get();
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasTargetScope())
+ {
+ Address addr = inst->GetAddress();
+ BreakpointSP bp_sp = exe_ctx.GetTargetRef().CreateBreakpoint (addr, // lldb_private::Address
+ false, // internal
+ false); // request_hardware
+ // Make breakpoint one shot
+ bp_sp->GetOptions()->SetOneShot(true);
+ exe_ctx.GetProcessRef().Resume();
+ }
+ }
+ return eKeyHandled;
+
+ case 'b': // 'b' == toggle breakpoint on currently selected line
+ if (m_selected_line < GetNumSourceLines())
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasTargetScope())
+ {
+ BreakpointSP bp_sp = exe_ctx.GetTargetRef().CreateBreakpoint (NULL, // Don't limit the breakpoint to certain modules
+ m_file_sp->GetFileSpec(), // Source file
+ m_selected_line + 1, // Source line number (m_selected_line is zero based)
+ eLazyBoolCalculate, // Check inlines using global setting
+ eLazyBoolCalculate, // Skip prologue using global setting,
+ false, // internal
+ false); // request_hardware
+ }
+ }
+ else if (m_selected_line < GetNumDisassemblyLines())
+ {
+ const Instruction *inst = m_disassembly_sp->GetInstructionList().GetInstructionAtIndex(m_selected_line).get();
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasTargetScope())
+ {
+ Address addr = inst->GetAddress();
+ BreakpointSP bp_sp = exe_ctx.GetTargetRef().CreateBreakpoint (addr, // lldb_private::Address
+ false, // internal
+ false); // request_hardware
+ }
+ }
+ return eKeyHandled;
+
+ case 'd': // 'd' == detach and let run
+ case 'D': // 'D' == detach and keep stopped
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasProcessScope())
+ exe_ctx.GetProcessRef().Detach(c == 'D');
+ }
+ return eKeyHandled;
+
+ case 'k':
+ // 'k' == kill
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasProcessScope())
+ exe_ctx.GetProcessRef().Destroy();
+ }
+ return eKeyHandled;
+
+ case 'c':
+ // 'c' == continue
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasProcessScope())
+ exe_ctx.GetProcessRef().Resume();
+ }
+ return eKeyHandled;
+
+ case 'o':
+ // 'o' == step out
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasThreadScope() && StateIsStoppedState (exe_ctx.GetProcessRef().GetState(), true))
+ {
+ exe_ctx.GetThreadRef().StepOut();
+ }
+ }
+ return eKeyHandled;
+ case 'n': // 'n' == step over
+ case 'N': // 'N' == step over instruction
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasThreadScope() && StateIsStoppedState (exe_ctx.GetProcessRef().GetState(), true))
+ {
+ bool source_step = (c == 'n');
+ exe_ctx.GetThreadRef().StepOver(source_step);
+ }
+ }
+ return eKeyHandled;
+ case 's': // 's' == step into
+ case 'S': // 'S' == step into instruction
+ {
+ ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
+ if (exe_ctx.HasThreadScope() && StateIsStoppedState (exe_ctx.GetProcessRef().GetState(), true))
+ {
+ bool source_step = (c == 's');
+ bool avoid_code_without_debug_info = true;
+ exe_ctx.GetThreadRef().StepIn(source_step, avoid_code_without_debug_info);
+ }
+ }
+ return eKeyHandled;
+
+ case 'h':
+ window.CreateHelpSubwindow ();
+ return eKeyHandled;
+
+ default:
+ break;
+ }
+ return eKeyNotHandled;
+ }
+
+protected:
+ typedef std::set<uint32_t> BreakpointLines;
+ typedef std::set<lldb::addr_t> BreakpointAddrs;
+
+ Debugger &m_debugger;
+ SymbolContext m_sc;
+ SourceManager::FileSP m_file_sp;
+ SymbolContextScope *m_disassembly_scope;
+ lldb::DisassemblerSP m_disassembly_sp;
+ AddressRange m_disassembly_range;
+ lldb::user_id_t m_tid;
+ char m_line_format[8];
+ int m_line_width;
+ uint32_t m_selected_line; // The selected line
+ uint32_t m_pc_line; // The line with the PC
+ uint32_t m_stop_id;
+ uint32_t m_frame_idx;
+ int m_first_visible_line;
+ int m_min_x;
+ int m_min_y;
+ int m_max_x;
+ int m_max_y;
+
+};
+
+DisplayOptions ValueObjectListDelegate::g_options = { true };
+
+IOHandlerCursesGUI::IOHandlerCursesGUI (Debugger &debugger) :
+ IOHandler (debugger)
+{
+}
+
+void
+IOHandlerCursesGUI::Activate ()
+{
+ IOHandler::Activate();
+ if (!m_app_ap)
+ {
+ m_app_ap.reset (new Application (GetInputFILE(), GetOutputFILE()));
+
+
+ // This is both a window and a menu delegate
+ std::shared_ptr<ApplicationDelegate> app_delegate_sp(new ApplicationDelegate(*m_app_ap, m_debugger));
+
+ MenuDelegateSP app_menu_delegate_sp = std::static_pointer_cast<MenuDelegate>(app_delegate_sp);
+ MenuSP lldb_menu_sp(new Menu("LLDB" , "F1", KEY_F(1), ApplicationDelegate::eMenuID_LLDB));
+ MenuSP exit_menuitem_sp(new Menu("Exit", NULL, 'x', ApplicationDelegate::eMenuID_LLDBExit));
+ exit_menuitem_sp->SetCannedResult(MenuActionResult::Quit);
+ lldb_menu_sp->AddSubmenu (MenuSP (new Menu("About LLDB", NULL, 'a', ApplicationDelegate::eMenuID_LLDBAbout)));
+ lldb_menu_sp->AddSubmenu (MenuSP (new Menu(Menu::Type::Separator)));
+ lldb_menu_sp->AddSubmenu (exit_menuitem_sp);
+
+ MenuSP target_menu_sp(new Menu("Target" ,"F2", KEY_F(2), ApplicationDelegate::eMenuID_Target));
+ target_menu_sp->AddSubmenu (MenuSP (new Menu("Create", NULL, 'c', ApplicationDelegate::eMenuID_TargetCreate)));
+ target_menu_sp->AddSubmenu (MenuSP (new Menu("Delete", NULL, 'd', ApplicationDelegate::eMenuID_TargetDelete)));
+
+ MenuSP process_menu_sp(new Menu("Process", "F3", KEY_F(3), ApplicationDelegate::eMenuID_Process));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Attach" , NULL, 'a', ApplicationDelegate::eMenuID_ProcessAttach)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Detach" , NULL, 'd', ApplicationDelegate::eMenuID_ProcessDetach)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Launch" , NULL, 'l', ApplicationDelegate::eMenuID_ProcessLaunch)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu(Menu::Type::Separator)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Continue", NULL, 'c', ApplicationDelegate::eMenuID_ProcessContinue)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Halt" , NULL, 'h', ApplicationDelegate::eMenuID_ProcessHalt)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Kill" , NULL, 'k', ApplicationDelegate::eMenuID_ProcessKill)));
+
+ MenuSP thread_menu_sp(new Menu("Thread", "F4", KEY_F(4), ApplicationDelegate::eMenuID_Thread));
+ thread_menu_sp->AddSubmenu (MenuSP (new Menu("Step In" , NULL, 'i', ApplicationDelegate::eMenuID_ThreadStepIn)));
+ thread_menu_sp->AddSubmenu (MenuSP (new Menu("Step Over", NULL, 'v', ApplicationDelegate::eMenuID_ThreadStepOver)));
+ thread_menu_sp->AddSubmenu (MenuSP (new Menu("Step Out" , NULL, 'o', ApplicationDelegate::eMenuID_ThreadStepOut)));
+
+ MenuSP view_menu_sp(new Menu("View", "F5", KEY_F(5), ApplicationDelegate::eMenuID_View));
+ view_menu_sp->AddSubmenu (MenuSP (new Menu("Backtrace", NULL, 'b', ApplicationDelegate::eMenuID_ViewBacktrace)));
+ view_menu_sp->AddSubmenu (MenuSP (new Menu("Registers", NULL, 'r', ApplicationDelegate::eMenuID_ViewRegisters)));
+ view_menu_sp->AddSubmenu (MenuSP (new Menu("Source" , NULL, 's', ApplicationDelegate::eMenuID_ViewSource)));
+ view_menu_sp->AddSubmenu (MenuSP (new Menu("Variables", NULL, 'v', ApplicationDelegate::eMenuID_ViewVariables)));
+
+ MenuSP help_menu_sp(new Menu("Help", "F6", KEY_F(6), ApplicationDelegate::eMenuID_Help));
+ help_menu_sp->AddSubmenu (MenuSP (new Menu("GUI Help", NULL, 'g', ApplicationDelegate::eMenuID_HelpGUIHelp)));
+
+ m_app_ap->Initialize();
+ WindowSP &main_window_sp = m_app_ap->GetMainWindow();
+
+ MenuSP menubar_sp(new Menu(Menu::Type::Bar));
+ menubar_sp->AddSubmenu (lldb_menu_sp);
+ menubar_sp->AddSubmenu (target_menu_sp);
+ menubar_sp->AddSubmenu (process_menu_sp);
+ menubar_sp->AddSubmenu (thread_menu_sp);
+ menubar_sp->AddSubmenu (view_menu_sp);
+ menubar_sp->AddSubmenu (help_menu_sp);
+ menubar_sp->SetDelegate(app_menu_delegate_sp);
+
+ Rect content_bounds = main_window_sp->GetFrame();
+ Rect menubar_bounds = content_bounds.MakeMenuBar();
+ Rect status_bounds = content_bounds.MakeStatusBar();
+ Rect source_bounds;
+ Rect variables_bounds;
+ Rect threads_bounds;
+ Rect source_variables_bounds;
+ content_bounds.VerticalSplitPercentage(0.80, source_variables_bounds, threads_bounds);
+ source_variables_bounds.HorizontalSplitPercentage(0.70, source_bounds, variables_bounds);
+
+ WindowSP menubar_window_sp = main_window_sp->CreateSubWindow("Menubar", menubar_bounds, false);
+ // Let the menubar get keys if the active window doesn't handle the
+ // keys that are typed so it can respond to menubar key presses.
+ menubar_window_sp->SetCanBeActive(false); // Don't let the menubar become the active window
+ menubar_window_sp->SetDelegate(menubar_sp);
+
+ WindowSP source_window_sp (main_window_sp->CreateSubWindow("Source",
+ source_bounds,
+ true));
+ WindowSP variables_window_sp (main_window_sp->CreateSubWindow("Variables",
+ variables_bounds,
+ false));
+ WindowSP threads_window_sp (main_window_sp->CreateSubWindow("Threads",
+ threads_bounds,
+ false));
+ WindowSP status_window_sp (main_window_sp->CreateSubWindow("Status",
+ status_bounds,
+ false));
+ status_window_sp->SetCanBeActive(false); // Don't let the status bar become the active window
+ main_window_sp->SetDelegate (std::static_pointer_cast<WindowDelegate>(app_delegate_sp));
+ source_window_sp->SetDelegate (WindowDelegateSP(new SourceFileWindowDelegate(m_debugger)));
+ variables_window_sp->SetDelegate (WindowDelegateSP(new FrameVariablesWindowDelegate(m_debugger)));
+ TreeDelegateSP thread_delegate_sp (new ThreadTreeDelegate(m_debugger));
+ threads_window_sp->SetDelegate (WindowDelegateSP(new TreeWindowDelegate(m_debugger, thread_delegate_sp)));
+ status_window_sp->SetDelegate (WindowDelegateSP(new StatusBarWindowDelegate(m_debugger)));
+
+ // Show the main help window once the first time the curses GUI is launched
+ static bool g_showed_help = false;
+ if (!g_showed_help)
+ {
+ g_showed_help = true;
+ main_window_sp->CreateHelpSubwindow();
+ }
+
+ init_pair (1, COLOR_WHITE , COLOR_BLUE );
+ init_pair (2, COLOR_BLACK , COLOR_WHITE );
+ init_pair (3, COLOR_MAGENTA , COLOR_WHITE );
+ init_pair (4, COLOR_MAGENTA , COLOR_BLACK );
+ init_pair (5, COLOR_RED , COLOR_BLACK );
+
+ }
+}
+
+void
+IOHandlerCursesGUI::Deactivate ()
+{
+ m_app_ap->Terminate();
+}
+
+void
+IOHandlerCursesGUI::Run ()
+{
+ m_app_ap->Run(m_debugger);
+ SetIsDone(true);
+}
+
+
+IOHandlerCursesGUI::~IOHandlerCursesGUI ()
+{
+
+}
+
+void
+IOHandlerCursesGUI::Hide ()
+{
+}
+
+
+void
+IOHandlerCursesGUI::Refresh ()
+{
+}
+
+
+void
+IOHandlerCursesGUI::Interrupt ()
+{
+}
+
+
+void
+IOHandlerCursesGUI::GotEOF()
+{
+}
+
+#endif // #ifndef LLDB_DISABLE_CURSES \ No newline at end of file
diff --git a/source/Core/InputReader.cpp b/source/Core/InputReader.cpp
deleted file mode 100644
index cbaa671bcba5..000000000000
--- a/source/Core/InputReader.cpp
+++ /dev/null
@@ -1,387 +0,0 @@
-//===-- InputReader.cpp -----------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/lldb-python.h"
-
-#include <string>
-
-#include "lldb/Core/InputReader.h"
-#include "lldb/Core/Debugger.h"
-#include "lldb/Interpreter/CommandInterpreter.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-InputReader::InputReader (Debugger &debugger) :
- m_debugger (debugger),
- m_callback (NULL),
- m_callback_baton (NULL),
- m_end_token (),
- m_granularity (eInputReaderGranularityInvalid),
- m_done (true),
- m_echo (true),
- m_active (false),
- m_reader_done (false),
- m_user_input(),
- m_save_user_input(false)
-{
-}
-
-InputReader::~InputReader ()
-{
-}
-
-Error
-InputReader::Initialize
-(
- Callback callback,
- void *baton,
- lldb::InputReaderGranularity granularity,
- const char *end_token,
- const char *prompt,
- bool echo
-)
-{
- Error err;
- m_callback = callback;
- m_callback_baton = baton,
- m_granularity = granularity;
- if (end_token != NULL)
- m_end_token = end_token;
- if (prompt != NULL)
- m_prompt = prompt;
- m_done = true;
- m_echo = echo;
-
- if (m_granularity == eInputReaderGranularityInvalid)
- {
- err.SetErrorString ("Invalid read token size: Reader must be initialized with a token size other than 'eInputReaderGranularityInvalid'.");
- }
- else
- if (end_token != NULL && granularity != eInputReaderGranularityInvalid)
- {
- if (granularity == eInputReaderGranularityByte)
- {
- // Check to see if end_token is longer than one byte.
-
- if (strlen (end_token) > 1)
- {
- err.SetErrorString ("Invalid end token: End token cannot be larger than specified token size (byte).");
- }
- }
- else if (granularity == eInputReaderGranularityWord)
- {
- // Check to see if m_end_token contains any white space (i.e. is multiple words).
-
- const char *white_space = " \t\n";
- size_t pos = m_end_token.find_first_of (white_space);
- if (pos != std::string::npos)
- {
- err.SetErrorString ("Invalid end token: End token cannot be larger than specified token size (word).");
- }
- }
- else
- {
- // Check to see if m_end_token contains any newlines; cannot handle multi-line end tokens.
-
- size_t pos = m_end_token.find_first_of ('\n');
- if (pos != std::string::npos)
- {
- err.SetErrorString ("Invalid end token: End token cannot contain a newline.");
- }
- }
- }
-
- m_done = err.Fail();
-
- return err;
-}
-
-size_t
-InputReader::HandleRawBytes (const char *bytes, size_t bytes_len)
-{
- const char *end_token = NULL;
-
- if (m_end_token.empty() == false)
- {
- end_token = ::strstr (bytes, m_end_token.c_str());
- if (end_token >= bytes + bytes_len)
- end_token = NULL;
- }
-
- const char *p = bytes;
- const char *end = bytes + bytes_len;
-
- switch (m_granularity)
- {
- case eInputReaderGranularityInvalid:
- break;
-
- case eInputReaderGranularityByte:
- while (p < end)
- {
- if (end_token == p)
- {
- p += m_end_token.size();
- SetIsDone(true);
- break;
- }
-
- if (m_callback (m_callback_baton, *this, eInputReaderGotToken, p, 1) == 0)
- break;
- ++p;
- if (IsDone())
- break;
- }
- // Return how many bytes were handled.
- return p - bytes;
- break;
-
-
- case eInputReaderGranularityWord:
- {
- char quote = '\0';
- const char *word_start = NULL;
- bool send_word = false;
- for (; p < end; ++p, send_word = false)
- {
- if (end_token && end_token == p)
- {
- m_end_token.size();
- SetIsDone(true);
- break;
- }
-
- const char ch = *p;
- if (isspace(ch) && (!quote || (quote == ch && p[-1] != '\\')))
- {
- // We have a space character or the terminating quote
- send_word = word_start != NULL;
- quote = '\0';
- }
- else if (quote)
- {
- // We are in the middle of a quoted character
- continue;
- }
- else if (ch == '"' || ch == '\'' || ch == '`')
- quote = ch;
- else if (word_start == NULL)
- {
- // We have the first character in a word
- word_start = p;
- }
-
- if (send_word)
- {
- const size_t word_len = p - word_start;
- size_t bytes_handled = m_callback (m_callback_baton,
- *this,
- eInputReaderGotToken,
- word_start,
- word_len);
-
- if (bytes_handled != word_len)
- return word_start - bytes + bytes_handled;
-
- if (IsDone())
- return p - bytes;
- }
- }
- }
- break;
-
-
- case eInputReaderGranularityLine:
- {
- const char *line_start = bytes;
- const char *end_line = NULL;
- while (p < end)
- {
- const char ch = *p;
- if (ch == '\n' || ch == '\r')
- {
- size_t line_length = p - line_start;
- // Now skip the newline character
- ++p;
- // Skip a complete DOS newline if we run into one
- if (ch == 0xd && p < end && *p == 0xa)
- ++p;
-
- if (line_start <= end_token && end_token < line_start + line_length)
- {
- SetIsDone(true);
- m_callback (m_callback_baton,
- *this,
- eInputReaderGotToken,
- line_start,
- end_token - line_start);
-
- return p - bytes;
- }
-
- size_t bytes_handled = m_callback (m_callback_baton,
- *this,
- eInputReaderGotToken,
- line_start,
- line_length);
-
- end_line = p;
-
- if (bytes_handled != line_length)
- {
- // The input reader wasn't able to handle all the data
- return line_start - bytes + bytes_handled;
- }
-
-
- if (IsDone())
- return p - bytes;
-
- line_start = p;
- }
- else
- {
- ++p;
- }
- }
-
- if (end_line)
- return end_line - bytes;
- }
- break;
-
-
- case eInputReaderGranularityAll:
- {
- // Nothing should be handle unless we see our end token
- if (end_token)
- {
- size_t length = end_token - bytes;
- size_t bytes_handled = m_callback (m_callback_baton,
- *this,
- eInputReaderGotToken,
- bytes,
- length);
- m_done = true;
-
- p += bytes_handled + m_end_token.size();
-
- // Consume any white space, such as newlines, beyond the end token
-
- while (p < end && isspace(*p))
- ++p;
-
- if (bytes_handled != length)
- return bytes_handled;
- else
- {
- return p - bytes;
- //return bytes_handled + m_end_token.size();
- }
- }
- return 0;
- }
- break;
- }
- return 0;
-}
-
-const char *
-InputReader::GetPrompt () const
-{
- if (!m_prompt.empty())
- return m_prompt.c_str();
- else
- return NULL;
-}
-
-void
-InputReader::RefreshPrompt ()
-{
- if (m_debugger.GetCommandInterpreter().GetBatchCommandMode())
- return;
-
- if (!m_prompt.empty())
- {
- File &out_file = m_debugger.GetOutputFile();
- if (out_file.IsValid())
- {
- out_file.Printf ("%s", m_prompt.c_str());
- out_file.Flush();
- }
- }
-}
-
-void
-InputReader::Notify (InputReaderAction notification)
-{
- switch (notification)
- {
- case eInputReaderActivate:
- case eInputReaderReactivate:
- m_active = true;
- m_reader_done.SetValue(false, eBroadcastAlways);
- break;
-
- case eInputReaderDeactivate:
- case eInputReaderDone:
- m_active = false;
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
-
- case eInputReaderInterrupt:
- case eInputReaderEndOfFile:
- break;
-
- case eInputReaderGotToken:
- return; // We don't notify the tokens here, it is done in HandleRawBytes
- }
- if (m_callback)
- m_callback (m_callback_baton, *this, notification, NULL, 0);
- if (notification == eInputReaderDone)
- m_reader_done.SetValue(true, eBroadcastAlways);
-}
-
-void
-InputReader::WaitOnReaderIsDone ()
-{
- m_reader_done.WaitForValueEqualTo (true);
-}
-
-const char *
-InputReader::GranularityAsCString (lldb::InputReaderGranularity granularity)
-{
- switch (granularity)
- {
- case eInputReaderGranularityInvalid: return "invalid";
- case eInputReaderGranularityByte: return "byte";
- case eInputReaderGranularityWord: return "word";
- case eInputReaderGranularityLine: return "line";
- case eInputReaderGranularityAll: return "all";
- }
-
- static char unknown_state_string[64];
- snprintf(unknown_state_string, sizeof (unknown_state_string), "InputReaderGranularity = %i", granularity);
- return unknown_state_string;
-}
-
-bool
-InputReader::HandlerData::GetBatchMode()
-{
- return reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
-}
-
-lldb::StreamSP
-InputReader::HandlerData::GetOutStream()
-{
- return reader.GetDebugger().GetAsyncOutputStream();
-}
diff --git a/source/Core/InputReaderEZ.cpp b/source/Core/InputReaderEZ.cpp
deleted file mode 100644
index 7a865bdc5097..000000000000
--- a/source/Core/InputReaderEZ.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-//===-- InputReaderEZ.cpp ---------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Core/InputReaderEZ.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-size_t
-InputReaderEZ::Callback_Impl(void *baton,
- InputReader &reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len)
-
-{
- HandlerData hand_data(reader,
- bytes,
- bytes_len,
- baton);
-
- switch (notification)
- {
- case eInputReaderActivate:
- reader.ActivateHandler(hand_data);
- break;
- case eInputReaderDeactivate:
- reader.DeactivateHandler(hand_data);
- break;
- case eInputReaderReactivate:
- reader.ReactivateHandler(hand_data);
- break;
- case eInputReaderAsynchronousOutputWritten:
- reader.AsynchronousOutputWrittenHandler(hand_data);
- break;
- case eInputReaderGotToken:
- {
- if (reader.GetSaveUserInput())
- reader.GetUserInput().AppendString(bytes, bytes_len);
- reader.GotTokenHandler(hand_data);
- }
- break;
- case eInputReaderInterrupt:
- reader.InterruptHandler(hand_data);
- break;
- case eInputReaderEndOfFile:
- reader.EOFHandler(hand_data);
- break;
- case eInputReaderDone:
- reader.DoneHandler(hand_data);
- break;
- }
- return bytes_len;
-}
-
-Error
-InputReaderEZ::Initialize(void* baton,
- lldb::InputReaderGranularity token_size,
- const char* end_token,
- const char *prompt,
- bool echo)
-{
- return InputReader::Initialize(Callback_Impl,
- baton,
- token_size,
- end_token,
- prompt,
- echo);
-}
-
-Error
-InputReaderEZ::Initialize(InitializationParameters& params)
-{
- Error ret = Initialize(params.m_baton,
- params.m_token_size,
- params.m_end_token,
- params.m_prompt,
- params.m_echo);
- m_save_user_input = params.m_save_user_input;
- return ret;
-}
-
-InputReaderEZ::~InputReaderEZ ()
-{
-}
diff --git a/source/Core/InputReaderStack.cpp b/source/Core/InputReaderStack.cpp
deleted file mode 100644
index 764ea26550f7..000000000000
--- a/source/Core/InputReaderStack.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-//===-- InputReaderStack.cpp ------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Core/InputReaderStack.h"
-
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-// Project includes
-
-
-using namespace lldb;
-using namespace lldb_private;
-
-InputReaderStack::InputReaderStack () :
- m_input_readers (),
- m_input_readers_mutex (Mutex::eMutexTypeRecursive)
-{
-}
-
-InputReaderStack::~InputReaderStack ()
-{
-}
-
-size_t
-InputReaderStack::GetSize () const
-{
- Mutex::Locker locker (m_input_readers_mutex);
- return m_input_readers.size();
-}
-
-void
-InputReaderStack::Push (const lldb::InputReaderSP& reader_sp)
-{
- if (reader_sp)
- {
- Mutex::Locker locker (m_input_readers_mutex);
- m_input_readers.push (reader_sp);
- }
-}
-
-bool
-InputReaderStack::IsEmpty () const
-{
- Mutex::Locker locker (m_input_readers_mutex);
- return m_input_readers.empty();
-}
-
-InputReaderSP
-InputReaderStack::Top ()
-{
- InputReaderSP input_reader_sp;
- {
- Mutex::Locker locker (m_input_readers_mutex);
- if (!m_input_readers.empty())
- input_reader_sp = m_input_readers.top();
- }
-
- return input_reader_sp;
-}
-
-void
-InputReaderStack::Pop ()
-{
- Mutex::Locker locker (m_input_readers_mutex);
- if (!m_input_readers.empty())
- m_input_readers.pop();
-}
-
-Mutex &
-InputReaderStack::GetStackMutex ()
-{
- return m_input_readers_mutex;
-}
diff --git a/source/Core/Log.cpp b/source/Core/Log.cpp
index 8d659cfd7522..b7dc056af6ce 100644
--- a/source/Core/Log.cpp
+++ b/source/Core/Log.cpp
@@ -83,7 +83,10 @@ Log::GetMask() const
void
Log::PrintfWithFlagsVarArg (uint32_t flags, const char *format, va_list args)
{
- if (m_stream_sp)
+ // Make a copy of our stream shared pointer in case someone disables our
+ // log while we are logging and releases the stream
+ StreamSP stream_sp(m_stream_sp);
+ if (stream_sp)
{
static uint32_t g_sequence_id = 0;
StreamString header;
@@ -116,11 +119,11 @@ Log::PrintfWithFlagsVarArg (uint32_t flags, const char *format, va_list args)
}
header.PrintfVarArg (format, args);
- m_stream_sp->Printf("%s\n", header.GetData());
+ stream_sp->Printf("%s\n", header.GetData());
if (m_options.Test (LLDB_LOG_OPTION_BACKTRACE))
- Host::Backtrace (*m_stream_sp, 1024);
- m_stream_sp->Flush();
+ Host::Backtrace (*stream_sp, 1024);
+ stream_sp->Flush();
}
}
@@ -467,8 +470,11 @@ Log::GetVerbose() const
if (m_options.Test(LLDB_LOG_OPTION_VERBOSE))
return true;
- if (m_stream_sp)
- return m_stream_sp->GetVerbose();
+ // Make a copy of our stream shared pointer in case someone disables our
+ // log while we are logging and releases the stream
+ StreamSP stream_sp(m_stream_sp);
+ if (stream_sp)
+ return stream_sp->GetVerbose();
return false;
}
@@ -478,8 +484,11 @@ Log::GetVerbose() const
bool
Log::GetDebug() const
{
- if (m_stream_sp)
- return m_stream_sp->GetDebug();
+ // Make a copy of our stream shared pointer in case someone disables our
+ // log while we are logging and releases the stream
+ StreamSP stream_sp(m_stream_sp);
+ if (stream_sp)
+ return stream_sp->GetDebug();
return false;
}
diff --git a/source/Core/Mangled.cpp b/source/Core/Mangled.cpp
index a41986de5143..55bd3cbb8e99 100644
--- a/source/Core/Mangled.cpp
+++ b/source/Core/Mangled.cpp
@@ -20,17 +20,10 @@
#ifdef LLDB_USE_BUILTIN_DEMANGLER
-#include <vector>
-#include <algorithm>
-#include <string>
-#include <numeric>
-#include <cstdlib>
-#include <cstring>
-#include <cctype>
//----------------------------------------------------------------------
// Inlined copy of:
// http://llvm.org/svn/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp
-// revision 193704.
+// revision 199944.
//
// Changes include:
// - remove the "__cxxabiv1" namespace
@@ -38,8 +31,32 @@
// - removed extern "C" from the cxa_demangle function
// - Changed the scope of the unnamed namespace to include cxa_demangle
// function.
+// - Added "#undef _LIBCPP_EXTERN_TEMPLATE" to avoid warning
//----------------------------------------------------------------------
+#undef _LIBCPP_EXTERN_TEMPLATE // Avoid warning below
+
+//===-------------------------- cxa_demangle.cpp --------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#define _LIBCPP_EXTERN_TEMPLATE(...)
+#define _LIBCPP_NO_EXCEPTIONS
+
+#include <vector>
+#include <algorithm>
+#include <string>
+#include <numeric>
+#include <cstdlib>
+#include <cstring>
+#include <cctype>
+
+
namespace
{
@@ -558,6 +575,8 @@ parse_template_param(const char* first, const char* last, C& db)
{
if (first[1] == '_')
{
+ if (db.template_param.empty())
+ return first;
if (!db.template_param.back().empty())
{
for (auto& t : db.template_param.back().front())
@@ -580,7 +599,7 @@ parse_template_param(const char* first, const char* last, C& db)
sub *= 10;
sub += static_cast<size_t>(*t - '0');
}
- if (t == last || *t != '_')
+ if (t == last || *t != '_' || db.template_param.empty())
return first;
++sub;
if (sub < db.template_param.back().size())
@@ -615,6 +634,8 @@ parse_const_cast_expr(const char* first, const char* last, C& db)
const char* t1 = parse_expression(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto expr = db.names.back().move_full();
db.names.pop_back();
db.names.back() = "const_cast<" + db.names.back().move_full() + ">(" + expr + ")";
@@ -639,6 +660,8 @@ parse_dynamic_cast_expr(const char* first, const char* last, C& db)
const char* t1 = parse_expression(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto expr = db.names.back().move_full();
db.names.pop_back();
db.names.back() = "dynamic_cast<" + db.names.back().move_full() + ">(" + expr + ")";
@@ -663,6 +686,8 @@ parse_reinterpret_cast_expr(const char* first, const char* last, C& db)
const char* t1 = parse_expression(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto expr = db.names.back().move_full();
db.names.pop_back();
db.names.back() = "reinterpret_cast<" + db.names.back().move_full() + ">(" + expr + ")";
@@ -687,6 +712,8 @@ parse_static_cast_expr(const char* first, const char* last, C& db)
const char* t1 = parse_expression(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto expr = db.names.back().move_full();
db.names.pop_back();
db.names.back() = "static_cast<" + db.names.back().move_full() + ">(" + expr + ")";
@@ -723,6 +750,8 @@ parse_sizeof_type_expr(const char* first, const char* last, C& db)
const char* t = parse_type(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back() = "sizeof (" + db.names.back().move_full() + ")";
first = t;
}
@@ -741,6 +770,8 @@ parse_sizeof_expr_expr(const char* first, const char* last, C& db)
const char* t = parse_expression(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back() = "sizeof (" + db.names.back().move_full() + ")";
first = t;
}
@@ -832,6 +863,8 @@ parse_sizeof_function_param_pack_expr(const char* first, const char* last, C& db
const char* t = parse_function_param(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back() = "sizeof...(" + db.names.back().move_full() + ")";
first = t;
}
@@ -855,6 +888,8 @@ parse_typeid_expr(const char* first, const char* last, C& db)
t = parse_type(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back() = "typeid(" + db.names.back().move_full() + ")";
first = t;
}
@@ -873,6 +908,8 @@ parse_throw_expr(const char* first, const char* last, C& db)
const char* t = parse_expression(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back() = "throw " + db.names.back().move_full();
first = t;
}
@@ -894,6 +931,8 @@ parse_dot_star_expr(const char* first, const char* last, C& db)
const char* t1 = parse_expression(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto expr = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += ".*" + expr;
@@ -918,6 +957,8 @@ parse_simple_id(const char* first, const char* last, C& db)
const char* t1 = parse_template_args(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto args = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += std::move(args);
@@ -964,6 +1005,8 @@ parse_unresolved_type(const char* first, const char* last, C& db)
t = parse_decltype(first, last, db);
if (t != first)
{
+ if (db.names.empty())
+ return first;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
first = t;
}
@@ -979,6 +1022,8 @@ parse_unresolved_type(const char* first, const char* last, C& db)
t = parse_unqualified_name(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "std::");
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
first = t;
@@ -1005,6 +1050,8 @@ parse_destructor_name(const char* first, const char* last, C& db)
t = parse_simple_id(first, last, db);
if (t != first)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "~");
first = t;
}
@@ -1036,6 +1083,8 @@ parse_base_unresolved_name(const char* first, const char* last, C& db)
first = parse_template_args(t, last, db);
if (first != t)
{
+ if (db.names.size() < 2)
+ return first;
auto args = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += std::move(args);
@@ -1060,6 +1109,8 @@ parse_base_unresolved_name(const char* first, const char* last, C& db)
first = parse_template_args(t, last, db);
if (first != t)
{
+ if (db.names.size() < 2)
+ return first;
auto args = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += std::move(args);
@@ -1109,7 +1160,11 @@ parse_unresolved_name(const char* first, const char* last, C& db)
if (t2 != t)
{
if (global)
+ {
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "::");
+ }
first = t2;
}
else if (last - t > 2 && t[0] == 's' && t[1] == 'r')
@@ -1124,6 +1179,8 @@ parse_unresolved_name(const char* first, const char* last, C& db)
t1 = parse_template_args(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto args = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += std::move(args);
@@ -1137,7 +1194,7 @@ parse_unresolved_name(const char* first, const char* last, C& db)
while (*t != 'E')
{
t1 = parse_unresolved_qualifier_level(t, last, db);
- if (t1 == t || t1 == last)
+ if (t1 == t || t1 == last || db.names.size() < 2)
return first;
auto s = db.names.back().move_full();
db.names.pop_back();
@@ -1148,9 +1205,12 @@ parse_unresolved_name(const char* first, const char* last, C& db)
t1 = parse_base_unresolved_name(t, last, db);
if (t1 == t)
{
- db.names.pop_back();
+ if (!db.names.empty())
+ db.names.pop_back();
return first;
}
+ if (db.names.size() < 2)
+ return first;
auto s = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += "::" + std::move(s);
@@ -1166,6 +1226,8 @@ parse_unresolved_name(const char* first, const char* last, C& db)
t1 = parse_template_args(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto args = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += std::move(args);
@@ -1174,9 +1236,12 @@ parse_unresolved_name(const char* first, const char* last, C& db)
t1 = parse_base_unresolved_name(t, last, db);
if (t1 == t)
{
- db.names.pop_back();
+ if (!db.names.empty())
+ db.names.pop_back();
return first;
}
+ if (db.names.size() < 2)
+ return first;
auto s = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += "::" + std::move(s);
@@ -1189,11 +1254,15 @@ parse_unresolved_name(const char* first, const char* last, C& db)
return first;
t = t1;
if (global)
+ {
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "::");
+ }
while (*t != 'E')
{
t1 = parse_unresolved_qualifier_level(t, last, db);
- if (t1 == t || t1 == last)
+ if (t1 == t || t1 == last || db.names.size() < 2)
return first;
auto s = db.names.back().move_full();
db.names.pop_back();
@@ -1204,9 +1273,12 @@ parse_unresolved_name(const char* first, const char* last, C& db)
t1 = parse_base_unresolved_name(t, last, db);
if (t1 == t)
{
- db.names.pop_back();
+ if (!db.names.empty())
+ db.names.pop_back();
return first;
}
+ if (db.names.size() < 2)
+ return first;
auto s = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += "::" + std::move(s);
@@ -1232,6 +1304,8 @@ parse_dot_expr(const char* first, const char* last, C& db)
const char* t1 = parse_unresolved_name(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto name = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += "." + name;
@@ -1255,6 +1329,8 @@ parse_call_expr(const char* first, const char* last, C& db)
{
if (t == last)
return first;
+ if (db.names.empty())
+ return first;
db.names.back().first += db.names.back().second;
db.names.back().second = typename C::String();
db.names.back().first.append("(");
@@ -1264,10 +1340,14 @@ parse_call_expr(const char* first, const char* last, C& db)
const char* t1 = parse_expression(t, last, db);
if (t1 == t || t1 == last)
return first;
+ if (db.names.empty())
+ return first;
auto tmp = db.names.back().move_full();
db.names.pop_back();
if (!tmp.empty())
{
+ if (db.names.empty())
+ return first;
if (!first_expr)
{
db.names.back().first.append(", ");
@@ -1278,6 +1358,8 @@ parse_call_expr(const char* first, const char* last, C& db)
t = t1;
}
++t;
+ if (db.names.empty())
+ return first;
db.names.back().first.append(")");
first = t;
}
@@ -1320,10 +1402,14 @@ parse_new_expr(const char* first, const char* last, C& db)
has_expr_list = true;
if (!first_expr)
{
+ if (db.names.empty())
+ return first;
auto tmp = db.names.back().move_full();
db.names.pop_back();
if (!tmp.empty())
{
+ if (db.names.empty())
+ return first;
db.names.back().first.append(", ");
db.names.back().first.append(tmp);
first_expr = false;
@@ -1349,10 +1435,14 @@ parse_new_expr(const char* first, const char* last, C& db)
return first;
if (!first_expr)
{
+ if (db.names.empty())
+ return first;
auto tmp = db.names.back().move_full();
db.names.pop_back();
if (!tmp.empty())
{
+ if (db.names.empty())
+ return first;
db.names.back().first.append(", ");
db.names.back().first.append(tmp);
first_expr = false;
@@ -1366,14 +1456,20 @@ parse_new_expr(const char* first, const char* last, C& db)
typename C::String init_list;
if (has_init)
{
+ if (db.names.empty())
+ return first;
init_list = db.names.back().move_full();
db.names.pop_back();
}
+ if (db.names.empty())
+ return first;
auto type = db.names.back().move_full();
db.names.pop_back();
typename C::String expr_list;
if (has_expr_list)
{
+ if (db.names.empty())
+ return first;
expr_list = db.names.back().move_full();
db.names.pop_back();
}
@@ -1435,10 +1531,14 @@ parse_conversion_expr(const char* first, const char* last, C& db)
return first;
if (!first_expr)
{
+ if (db.names.empty())
+ return first;
auto tmp = db.names.back().move_full();
db.names.pop_back();
if (!tmp.empty())
{
+ if (db.names.empty())
+ return first;
db.names.back().first.append(", ");
db.names.back().first.append(tmp);
first_expr = false;
@@ -1449,6 +1549,8 @@ parse_conversion_expr(const char* first, const char* last, C& db)
}
++t;
}
+ if (db.names.size() < 2)
+ return first;
auto tmp = db.names.back().move_full();
db.names.pop_back();
db.names.back() = "(" + db.names.back().move_full() + ")(" + tmp + ")";
@@ -1472,6 +1574,8 @@ parse_arrow_expr(const char* first, const char* last, C& db)
const char* t1 = parse_expression(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto tmp = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += "->";
@@ -1564,6 +1668,8 @@ parse_function_type(const char* first, const char* last, C& db)
sig += " &&";
break;
}
+ if (db.names.empty())
+ return first;
db.names.back().first += " ";
db.names.back().second.insert(0, sig);
first = t;
@@ -1587,6 +1693,8 @@ parse_pointer_to_member_type(const char* first, const char* last, C& db)
const char* t2 = parse_type(t, last, db);
if (t2 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto func = std::move(db.names.back());
db.names.pop_back();
auto class_type = std::move(db.names.back());
@@ -1621,6 +1729,8 @@ parse_array_type(const char* first, const char* last, C& db)
const char* t = parse_type(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
if (db.names.back().second.substr(0, 2) == " [")
db.names.back().second.erase(0, 1);
db.names.back().second.insert(0, " []");
@@ -1635,6 +1745,8 @@ parse_array_type(const char* first, const char* last, C& db)
const char* t2 = parse_type(t+1, last, db);
if (t2 != t+1)
{
+ if (db.names.empty())
+ return first;
if (db.names.back().second.substr(0, 2) == " [")
db.names.back().second.erase(0, 1);
db.names.back().second.insert(0, " [" + typename C::String(first+1, t) + "]");
@@ -1650,6 +1762,8 @@ parse_array_type(const char* first, const char* last, C& db)
const char* t2 = parse_type(++t, last, db);
if (t2 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto type = std::move(db.names.back());
db.names.pop_back();
auto expr = std::move(db.names.back());
@@ -1682,6 +1796,8 @@ parse_decltype(const char* first, const char* last, C& db)
const char* t = parse_expression(first+2, last, db);
if (t != first+2 && t != last && *t == 'E')
{
+ if (db.names.empty())
+ return first;
db.names.back() = "decltype(" + db.names.back().move_full() + ")";
first = t+1;
}
@@ -1719,6 +1835,8 @@ parse_vector_type(const char* first, const char* last, C& db)
const char* t1 = parse_type(t, last, db);
if (t1 != t)
{
+ if (db.names.empty())
+ return first;
db.names.back().first += " vector[" + typename C::String(num, sz) + "]";
first = t1;
}
@@ -1740,6 +1858,8 @@ parse_vector_type(const char* first, const char* last, C& db)
const char* t = parse_expression(t1, last, db);
if (t != t1)
{
+ if (db.names.empty())
+ return first;
num = db.names.back().move_full();
db.names.pop_back();
t1 = t;
@@ -1750,6 +1870,8 @@ parse_vector_type(const char* first, const char* last, C& db)
const char* t = parse_type(t1, last, db);
if (t != t1)
{
+ if (db.names.empty())
+ return first;
db.names.back().first += " vector[" + num + "]";
first = t;
}
@@ -1860,6 +1982,8 @@ parse_type(const char* first, const char* last, C& db)
t = parse_array_type(first, last, db);
if (t != first)
{
+ if (db.names.empty())
+ return first;
first = t;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
}
@@ -1868,6 +1992,8 @@ parse_type(const char* first, const char* last, C& db)
t = parse_type(first+1, last, db);
if (t != first+1)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.append(" complex");
first = t;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
@@ -1877,6 +2003,8 @@ parse_type(const char* first, const char* last, C& db)
t = parse_function_type(first, last, db);
if (t != first)
{
+ if (db.names.empty())
+ return first;
first = t;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
}
@@ -1885,6 +2013,8 @@ parse_type(const char* first, const char* last, C& db)
t = parse_type(first+1, last, db);
if (t != first+1)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.append(" imaginary");
first = t;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
@@ -1894,6 +2024,8 @@ parse_type(const char* first, const char* last, C& db)
t = parse_pointer_to_member_type(first, last, db);
if (t != first)
{
+ if (db.names.empty())
+ return first;
first = t;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
}
@@ -2021,6 +2153,8 @@ parse_type(const char* first, const char* last, C& db)
const char* t2 = parse_type(t, last, db);
if (t2 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto type = db.names.back().move_full();
db.names.pop_back();
if (db.names.back().first.substr(0, 9) != "objcproto")
@@ -2053,6 +2187,8 @@ parse_type(const char* first, const char* last, C& db)
t = parse_name(first, last, db);
if (t != first)
{
+ if (db.names.empty())
+ return first;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
first = t;
}
@@ -2068,6 +2204,8 @@ parse_type(const char* first, const char* last, C& db)
t = parse_template_args(first, last, db);
if (t != first)
{
+ if (db.names.size() < 2)
+ return first;
auto template_args = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += template_args;
@@ -2103,6 +2241,8 @@ parse_type(const char* first, const char* last, C& db)
t = parse_decltype(first, last, db);
if (t != first)
{
+ if (db.names.empty())
+ return first;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
first = t;
return first;
@@ -2112,6 +2252,8 @@ parse_type(const char* first, const char* last, C& db)
t = parse_vector_type(first, last, db);
if (t != first)
{
+ if (db.names.empty())
+ return first;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
first = t;
return first;
@@ -2133,6 +2275,8 @@ parse_type(const char* first, const char* last, C& db)
t = parse_name(first, last, db);
if (t != first)
{
+ if (db.names.empty())
+ return first;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
first = t;
}
@@ -2169,6 +2313,7 @@ parse_type(const char* first, const char* last, C& db)
// ::= gt # >
// ::= ix # []
// ::= le # <=
+// ::= li <source-name> # operator ""
// ::= ls # <<
// ::= lS # <<=
// ::= lt # <
@@ -2251,6 +2396,8 @@ parse_operator_name(const char* first, const char* last, C& db)
db.try_to_parse_template_args = try_to_parse_template_args;
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "operator ");
db.parsed_ctor_dtor_cv = true;
first = t;
@@ -2328,6 +2475,18 @@ parse_operator_name(const char* first, const char* last, C& db)
db.names.push_back("operator<=");
first += 2;
break;
+ case 'i':
+ {
+ const char* t = parse_source_name(first+2, last, db);
+ if (t != first+2)
+ {
+ if (db.names.empty())
+ return first;
+ db.names.back().first.insert(0, "operator\"\" ");
+ first = t;
+ }
+ }
+ break;
case 's':
db.names.push_back("operator<<");
first += 2;
@@ -2472,6 +2631,8 @@ parse_operator_name(const char* first, const char* last, C& db)
const char* t = parse_source_name(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "operator ");
first = t;
}
@@ -2681,6 +2842,8 @@ parse_expr_primary(const char* first, const char* last, C& db)
;
if (n != t && n != last && *n == 'E')
{
+ if (db.names.empty())
+ return first;
db.names.back() = "(" + db.names.back().move_full() + ")" + typename C::String(t, n);
first = n+1;
break;
@@ -2781,6 +2944,8 @@ parse_ctor_dtor_name(const char* first, const char* last, C& db)
case '2':
case '3':
case '5':
+ if (db.names.empty())
+ return first;
db.names.push_back(base_name(db.names.back().first));
first += 2;
db.parsed_ctor_dtor_cv = true;
@@ -2794,6 +2959,8 @@ parse_ctor_dtor_name(const char* first, const char* last, C& db)
case '1':
case '2':
case '5':
+ if (db.names.empty())
+ return first;
db.names.push_back("~" + base_name(db.names.back().first));
first += 2;
db.parsed_ctor_dtor_cv = true;
@@ -2864,6 +3031,8 @@ parse_unnamed_type_name(const char* first, const char* last, C& db)
db.names.pop_back();
return first;
}
+ if (db.names.size() < 2)
+ return first;
auto tmp = db.names.back().move_full();
db.names.pop_back();
db.names.back().first.append(tmp);
@@ -2873,6 +3042,8 @@ parse_unnamed_type_name(const char* first, const char* last, C& db)
t1 = parse_type(t0, last, db);
if (t1 == t0)
break;
+ if (db.names.size() < 2)
+ return first;
tmp = db.names.back().move_full();
db.names.pop_back();
if (!tmp.empty())
@@ -2987,7 +3158,11 @@ parse_unscoped_name(const char* first, const char* last, C& db)
if (t1 != t0)
{
if (St)
+ {
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "std::");
+ }
first = t1;
}
}
@@ -3005,6 +3180,8 @@ parse_alignof_type(const char* first, const char* last, C& db)
const char* t = parse_type(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first = "alignof (" + db.names.back().move_full() + ")";
first = t;
}
@@ -3023,6 +3200,8 @@ parse_alignof_expr(const char* first, const char* last, C& db)
const char* t = parse_expression(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first = "alignof (" + db.names.back().move_full() + ")";
first = t;
}
@@ -3037,6 +3216,8 @@ parse_noexcept_expression(const char* first, const char* last, C& db)
const char* t1 = parse_expression(first, last, db);
if (t1 != first)
{
+ if (db.names.empty())
+ return first;
db.names.back().first = "noexcept (" + db.names.back().move_full() + ")";
first = t1;
}
@@ -3050,6 +3231,8 @@ parse_prefix_expression(const char* first, const char* last, const typename C::S
const char* t1 = parse_expression(first, last, db);
if (t1 != first)
{
+ if (db.names.empty())
+ return first;
db.names.back().first = op + "(" + db.names.back().move_full() + ")";
first = t1;
}
@@ -3066,6 +3249,8 @@ parse_binary_expression(const char* first, const char* last, const typename C::S
const char* t2 = parse_expression(t1, last, db);
if (t2 != t1)
{
+ if (db.names.size() < 2)
+ return first;
auto op2 = db.names.back().move_full();
db.names.pop_back();
auto op1 = db.names.back().move_full();
@@ -3216,6 +3401,8 @@ parse_expression(const char* first, const char* last, C& db)
const char* t1 = parse_expression(t+2, last, db);
if (t1 != t+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first = (parsed_gs ? typename C::String("::") : typename C::String()) +
"delete[] " + db.names.back().move_full();
first = t1;
@@ -3235,6 +3422,8 @@ parse_expression(const char* first, const char* last, C& db)
const char* t1 = parse_expression(t+2, last, db);
if (t1 != t+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first = (parsed_gs ? typename C::String("::") : typename C::String()) +
"delete " + db.names.back().move_full();
first = t1;
@@ -3305,6 +3494,8 @@ parse_expression(const char* first, const char* last, C& db)
const char* t2 = parse_expression(t1, last, db);
if (t2 != t1)
{
+ if (db.names.size() < 2)
+ return first;
auto op2 = db.names.back().move_full();
db.names.pop_back();
auto op1 = db.names.back().move_full();
@@ -3376,6 +3567,8 @@ parse_expression(const char* first, const char* last, C& db)
const char* t1 = parse_expression(first+2, last, db);
if (t1 != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back() = "(" + db.names.back().move_full() + ")--";
first = t1;
}
@@ -3464,6 +3657,8 @@ parse_expression(const char* first, const char* last, C& db)
const char* t1 = parse_expression(first+2, last, db);
if (t1 != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back() = "(" + db.names.back().move_full() + ")++";
first = t1;
}
@@ -3491,6 +3686,8 @@ parse_expression(const char* first, const char* last, C& db)
const char* t3 = parse_expression(t2, last, db);
if (t3 != t2)
{
+ if (db.names.size() < 3)
+ return first;
auto op3 = db.names.back().move_full();
db.names.pop_back();
auto op2 = db.names.back().move_full();
@@ -3918,6 +4115,8 @@ parse_local_name(const char* first, const char* last, C& db)
{
case 's':
first = parse_discriminator(t+1, last);
+ if (db.names.empty())
+ return first;
db.names.back().first.append("::string literal");
break;
case 'd':
@@ -3930,6 +4129,8 @@ parse_local_name(const char* first, const char* last, C& db)
t1 = parse_name(t, last, db);
if (t1 != t)
{
+ if (db.names.size() < 2)
+ return first;
auto name = db.names.back().move_full();
db.names.pop_back();
db.names.back().first.append("::");
@@ -3948,6 +4149,8 @@ parse_local_name(const char* first, const char* last, C& db)
{
// parse but ignore discriminator
first = parse_discriminator(t1, last);
+ if (db.names.size() < 2)
+ return first;
auto name = db.names.back().move_full();
db.names.pop_back();
db.names.back().first.append("::");
@@ -4004,11 +4207,15 @@ parse_name(const char* first, const char* last, C& db)
{
if (t1 != last && *t1 == 'I') // <unscoped-template-name> <template-args>
{
+ if (db.names.empty())
+ return first;
db.subs.push_back(typename C::sub_type(1, db.names.back(), db.names.get_allocator()));
t0 = t1;
t1 = parse_template_args(t0, last, db);
if (t1 != t0)
{
+ if (db.names.size() < 2)
+ return first;
auto tmp = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += tmp;
@@ -4027,6 +4234,8 @@ parse_name(const char* first, const char* last, C& db)
t1 = parse_template_args(t0, last, db);
if (t1 != t0)
{
+ if (db.names.size() < 2)
+ return first;
auto tmp = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += tmp;
@@ -4112,6 +4321,8 @@ parse_special_name(const char* first, const char* last, C& db)
t = parse_type(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "vtable for ");
first = t;
}
@@ -4121,6 +4332,8 @@ parse_special_name(const char* first, const char* last, C& db)
t = parse_type(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "VTT for ");
first = t;
}
@@ -4130,6 +4343,8 @@ parse_special_name(const char* first, const char* last, C& db)
t = parse_type(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "typeinfo for ");
first = t;
}
@@ -4139,6 +4354,8 @@ parse_special_name(const char* first, const char* last, C& db)
t = parse_type(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "typeinfo name for ");
first = t;
}
@@ -4155,6 +4372,8 @@ parse_special_name(const char* first, const char* last, C& db)
t = parse_encoding(t1, last, db);
if (t != t1)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "covariant return thunk to ");
first = t;
}
@@ -4171,6 +4390,8 @@ parse_special_name(const char* first, const char* last, C& db)
const char* t1 = parse_type(++t0, last, db);
if (t1 != t0)
{
+ if (db.names.size() < 2)
+ return first;
auto left = db.names.back().move_full();
db.names.pop_back();
db.names.back().first = "construction vtable for " +
@@ -4190,6 +4411,8 @@ parse_special_name(const char* first, const char* last, C& db)
t = parse_encoding(t0, last, db);
if (t != t0)
{
+ if (db.names.empty())
+ return first;
if (first[2] == 'v')
{
db.names.back().first.insert(0, "virtual thunk to ");
@@ -4213,6 +4436,8 @@ parse_special_name(const char* first, const char* last, C& db)
t = parse_name(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "guard variable for ");
first = t;
}
@@ -4222,6 +4447,8 @@ parse_special_name(const char* first, const char* last, C& db)
t = parse_name(first+2, last, db);
if (t != first+2)
{
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "reference temporary for ");
first = t;
}
@@ -4233,6 +4460,26 @@ parse_special_name(const char* first, const char* last, C& db)
return first;
}
+template <class T>
+class save_value
+{
+ T& restore_;
+ T original_value_;
+public:
+ save_value(T& restore)
+ : restore_(restore),
+ original_value_(restore)
+ {}
+
+ ~save_value()
+ {
+ restore_ = std::move(original_value_);
+ }
+
+ save_value(const save_value&) = delete;
+ save_value& operator=(const save_value&) = delete;
+};
+
// <encoding> ::= <function name> <bare-function-type>
// ::= <data name>
// ::= <special-name>
@@ -4243,6 +4490,11 @@ parse_encoding(const char* first, const char* last, C& db)
{
if (first != last)
{
+ save_value<decltype(db.encoding_depth)> su(db.encoding_depth);
+ ++db.encoding_depth;
+ save_value<decltype(db.tag_templates)> sb(db.tag_templates);
+ if (db.encoding_depth > 1)
+ db.tag_templates = true;
switch (*first)
{
case 'G':
@@ -4258,17 +4510,23 @@ parse_encoding(const char* first, const char* last, C& db)
{
if (t != last && *t != 'E' && *t != '.')
{
- bool tag_templates = db.tag_templates;
+ save_value<bool> sb2(db.tag_templates);
db.tag_templates = false;
const char* t2;
typename C::String ret2;
+ if (db.names.empty())
+ return first;
const typename C::String& nm = db.names.back().first;
+ if (nm.empty())
+ return first;
if (!db.parsed_ctor_dtor_cv && nm.back() == '>' && nm[nm.size()-2] != '-'
&& nm[nm.size()-2] != '>')
{
t2 = parse_type(t, last, db);
if (t2 == t)
return first;
+ if (db.names.size() < 2)
+ return first;
auto ret1 = std::move(db.names.back().first);
ret2 = std::move(db.names.back().second);
if (ret2.empty())
@@ -4305,6 +4563,8 @@ parse_encoding(const char* first, const char* last, C& db)
db.names.pop_back();
if (!tmp.empty())
{
+ if (db.names.empty())
+ return first;
if (!first_arg)
db.names.back().first += ", ";
else
@@ -4315,6 +4575,8 @@ parse_encoding(const char* first, const char* last, C& db)
t = t2;
}
}
+ if (db.names.empty())
+ return first;
db.names.back().first += ')';
if (cv & 1)
db.names.back().first.append(" const");
@@ -4328,7 +4590,6 @@ parse_encoding(const char* first, const char* last, C& db)
db.names.back().first.append(" &&");
db.names.back().first += ret2;
first = t;
- db.tag_templates = tag_templates;
}
else
first = t;
@@ -4370,6 +4631,8 @@ parse_block_invoke(const char* first, const char* last, C& db)
while (t != last && isdigit(*t))
++t;
}
+ if (db.names.empty())
+ return first;
db.names.back().first.insert(0, "invocation function for block in ");
first = t;
}
@@ -4385,6 +4648,8 @@ parse_dot_suffix(const char* first, const char* last, C& db)
{
if (first != last && *first == '.')
{
+ if (db.names.empty())
+ return first;
db.names.back().first += " (" + typename C::String(first, last) + ")";
first = last;
}
@@ -4620,6 +4885,7 @@ struct Db
Vector<template_param_type> template_param;
unsigned cv;
unsigned ref;
+ unsigned encoding_depth;
bool parsed_ctor_dtor_cv;
bool tag_templates;
bool fix_forward_references;
@@ -4647,6 +4913,7 @@ __cxa_demangle(const char* mangled_name, char* buf, size_t* n, int* status)
Db db(a);
db.cv = 0;
db.ref = 0;
+ db.encoding_depth = 0;
db.parsed_ctor_dtor_cv = false;
db.tag_templates = true;
db.template_param.emplace_back(a);
@@ -4699,8 +4966,7 @@ __cxa_demangle(const char* mangled_name, char* buf, size_t* n, int* status)
return buf;
}
-} // unnamed namespace
-
+}
#endif
diff --git a/source/Core/Module.cpp b/source/Core/Module.cpp
index f90a097416df..d5758c09b1e2 100644
--- a/source/Core/Module.cpp
+++ b/source/Core/Module.cpp
@@ -33,6 +33,7 @@
#include "lldb/Target/CPPLanguageRuntime.h"
#include "lldb/Target/ObjCLanguageRuntime.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Symbol/SymbolFile.h"
@@ -1499,30 +1500,19 @@ Module::SetArchitecture (const ArchSpec &new_arch)
}
bool
-Module::SetLoadAddress (Target &target, lldb::addr_t offset, bool &changed)
+Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
{
- size_t num_loaded_sections = 0;
- SectionList *section_list = GetSectionList ();
- if (section_list)
+ ObjectFile *object_file = GetObjectFile();
+ if (object_file)
{
- const size_t num_sections = section_list->GetSize();
- size_t sect_idx = 0;
- for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
- {
- // Iterate through the object file sections to find the
- // first section that starts of file offset zero and that
- // has bytes in the file...
- SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
- // Only load non-thread specific sections when given a slide
- if (section_sp && !section_sp->IsThreadSpecific())
- {
- if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + offset))
- ++num_loaded_sections;
- }
- }
+ changed = object_file->SetLoadAddress(target, value, value_is_offset);
+ return true;
}
- changed = num_loaded_sections > 0;
- return num_loaded_sections > 0;
+ else
+ {
+ changed = false;
+ }
+ return false;
}
diff --git a/source/Core/Opcode.cpp b/source/Core/Opcode.cpp
index 978a110150f9..2bf7f5eae9b0 100644
--- a/source/Core/Opcode.cpp
+++ b/source/Core/Opcode.cpp
@@ -71,6 +71,10 @@ Opcode::Dump (Stream *s, uint32_t min_byte_width)
lldb::ByteOrder
Opcode::GetDataByteOrder () const
{
+ if (m_byte_order != eByteOrderInvalid)
+ {
+ return m_byte_order;
+ }
switch (m_type)
{
case Opcode::eTypeInvalid: break;
@@ -89,39 +93,66 @@ uint32_t
Opcode::GetData (DataExtractor &data) const
{
uint32_t byte_size = GetByteSize ();
+ uint8_t swap_buf[8];
+ const void *buf = NULL;
- DataBufferSP buffer_sp;
if (byte_size > 0)
{
- switch (m_type)
+ if (!GetEndianSwap())
+ {
+ if (m_type == Opcode::eType16_2)
+ {
+ // 32 bit thumb instruction, we need to sizzle this a bit
+ swap_buf[0] = m_data.inst.bytes[2];
+ swap_buf[1] = m_data.inst.bytes[3];
+ swap_buf[2] = m_data.inst.bytes[0];
+ swap_buf[3] = m_data.inst.bytes[1];
+ buf = swap_buf;
+ }
+ else
+ {
+ buf = GetOpcodeDataBytes();
+ }
+ }
+ else
{
- case Opcode::eTypeInvalid:
- break;
-
- case Opcode::eType8: buffer_sp.reset (new DataBufferHeap (&m_data.inst8, byte_size)); break;
- case Opcode::eType16: buffer_sp.reset (new DataBufferHeap (&m_data.inst16, byte_size)); break;
- case Opcode::eType16_2:
- {
- // 32 bit thumb instruction, we need to sizzle this a bit
- uint8_t buf[4];
- buf[0] = m_data.inst.bytes[2];
- buf[1] = m_data.inst.bytes[3];
- buf[2] = m_data.inst.bytes[0];
- buf[3] = m_data.inst.bytes[1];
- buffer_sp.reset (new DataBufferHeap (buf, byte_size));
- }
- break;
- case Opcode::eType32:
- buffer_sp.reset (new DataBufferHeap (&m_data.inst32, byte_size));
- break;
- case Opcode::eType64: buffer_sp.reset (new DataBufferHeap (&m_data.inst64, byte_size)); break;
- case Opcode::eTypeBytes:buffer_sp.reset (new DataBufferHeap (GetOpcodeBytes(), byte_size)); break;
- break;
+ switch (m_type)
+ {
+ case Opcode::eTypeInvalid:
+ break;
+ case Opcode::eType8:
+ buf = GetOpcodeDataBytes();
+ break;
+ case Opcode::eType16:
+ *(uint16_t *)swap_buf = llvm::ByteSwap_16(m_data.inst16);
+ buf = swap_buf;
+ break;
+ case Opcode::eType16_2:
+ swap_buf[0] = m_data.inst.bytes[1];
+ swap_buf[1] = m_data.inst.bytes[0];
+ swap_buf[2] = m_data.inst.bytes[3];
+ swap_buf[3] = m_data.inst.bytes[2];
+ buf = swap_buf;
+ break;
+ case Opcode::eType32:
+ *(uint32_t *)swap_buf = llvm::ByteSwap_32(m_data.inst32);
+ buf = swap_buf;
+ break;
+ case Opcode::eType64:
+ *(uint32_t *)swap_buf = llvm::ByteSwap_64(m_data.inst64);
+ buf = swap_buf;
+ break;
+ case Opcode::eTypeBytes:
+ buf = GetOpcodeDataBytes();
+ break;
+ }
}
}
-
- if (buffer_sp)
+ if (buf)
{
+ DataBufferSP buffer_sp;
+
+ buffer_sp.reset (new DataBufferHeap (buf, byte_size));
data.SetByteOrder(GetDataByteOrder());
data.SetData (buffer_sp);
return byte_size;
diff --git a/source/Core/Section.cpp b/source/Core/Section.cpp
index e2a084ceb2f2..28d7d93b9bb9 100644
--- a/source/Core/Section.cpp
+++ b/source/Core/Section.cpp
@@ -10,6 +10,7 @@
#include "lldb/Core/Section.h"
#include "lldb/Core/Module.h"
#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
using namespace lldb;
diff --git a/source/Core/SourceManager.cpp b/source/Core/SourceManager.cpp
index 940034625c0a..0a6a80401d8d 100644
--- a/source/Core/SourceManager.cpp
+++ b/source/Core/SourceManager.cpp
@@ -432,6 +432,56 @@ SourceManager::File::GetLineOffset (uint32_t line)
return UINT32_MAX;
}
+uint32_t
+SourceManager::File::GetNumLines ()
+{
+ CalculateLineOffsets();
+ return m_offsets.size();
+}
+
+const char *
+SourceManager::File::PeekLineData (uint32_t line)
+{
+ if (!LineIsValid(line))
+ return NULL;
+
+ size_t line_offset = GetLineOffset (line);
+ if (line_offset < m_data_sp->GetByteSize())
+ return (const char *)m_data_sp->GetBytes() + line_offset;
+ return NULL;
+}
+
+uint32_t
+SourceManager::File::GetLineLength (uint32_t line, bool include_newline_chars)
+{
+ if (!LineIsValid(line))
+ return false;
+
+ size_t start_offset = GetLineOffset (line);
+ size_t end_offset = GetLineOffset (line + 1);
+ if (end_offset == UINT32_MAX)
+ end_offset = m_data_sp->GetByteSize();
+
+ if (end_offset > start_offset)
+ {
+ uint32_t length = end_offset - start_offset;
+ if (include_newline_chars == false)
+ {
+ const char *line_start = (const char *)m_data_sp->GetBytes() + start_offset;
+ while (length > 0)
+ {
+ const char last_char = line_start[length-1];
+ if ((last_char == '\r') || (last_char == '\n'))
+ --length;
+ else
+ break;
+ }
+ }
+ return length;
+ }
+ return 0;
+}
+
bool
SourceManager::File::LineIsValid (uint32_t line)
{
diff --git a/source/Core/StreamAsynchronousIO.cpp b/source/Core/StreamAsynchronousIO.cpp
index b9e5cdfde721..257982ab8b29 100644
--- a/source/Core/StreamAsynchronousIO.cpp
+++ b/source/Core/StreamAsynchronousIO.cpp
@@ -28,25 +28,26 @@ StreamAsynchronousIO::StreamAsynchronousIO (Broadcaster &broadcaster, uint32_t b
StreamAsynchronousIO::~StreamAsynchronousIO ()
{
+ // Flush when we destroy to make sure we display the data
+ Flush();
}
void
StreamAsynchronousIO::Flush ()
{
- if (m_accumulated_data.GetSize() > 0)
+ if (!m_accumulated_data.empty())
{
std::unique_ptr<EventDataBytes> data_bytes_ap (new EventDataBytes);
// Let's swap the bytes to avoid LARGE string copies.
- data_bytes_ap->SwapBytes (m_accumulated_data.GetString());
+ data_bytes_ap->SwapBytes (m_accumulated_data);
EventSP new_event_sp (new Event (m_broadcast_event_type, data_bytes_ap.release()));
m_broadcaster.BroadcastEvent (new_event_sp);
- m_accumulated_data.Clear();
}
}
size_t
StreamAsynchronousIO::Write (const void *s, size_t length)
{
- m_accumulated_data.Write (s, length);
+ m_accumulated_data.append ((const char *)s, length);
return length;
}
diff --git a/source/Core/StringList.cpp b/source/Core/StringList.cpp
index 994975116789..d2fa8cfb4a88 100644
--- a/source/Core/StringList.cpp
+++ b/source/Core/StringList.cpp
@@ -56,6 +56,12 @@ StringList::AppendString (const std::string &s)
}
void
+StringList::AppendString (std::string &&s)
+{
+ m_strings.push_back (s);
+}
+
+void
StringList::AppendString (const char *str, size_t str_len)
{
if (str)
@@ -93,6 +99,20 @@ StringList::GetSize () const
return m_strings.size();
}
+size_t
+StringList::GetMaxStringLength () const
+{
+ size_t max_length = 0;
+ for (const auto &s : m_strings)
+ {
+ const size_t len = s.size();
+ if (max_length < len)
+ max_length = len;
+ }
+ return max_length;
+}
+
+
const char *
StringList::GetStringAtIndex (size_t idx) const
{
@@ -126,37 +146,39 @@ StringList::Clear ()
void
StringList::LongestCommonPrefix (std::string &common_prefix)
{
- //arg_sstr_collection::iterator pos, end = m_args.end();
- size_t pos = 0;
- size_t end = m_strings.size();
+ const size_t num_strings = m_strings.size();
- if (pos == end)
+ if (num_strings == 0)
+ {
common_prefix.clear();
+ }
else
- common_prefix = m_strings[pos];
-
- for (++pos; pos != end; ++pos)
{
- size_t new_size = strlen (m_strings[pos].c_str());
+ common_prefix = m_strings.front();
- // First trim common_prefix if it is longer than the current element:
- if (common_prefix.size() > new_size)
- common_prefix.erase (new_size);
+ for (size_t idx = 1; idx < num_strings; ++idx)
+ {
+ std::string &curr_string = m_strings[idx];
+ size_t new_size = curr_string.size();
- // Then trim it at the first disparity:
+ // First trim common_prefix if it is longer than the current element:
+ if (common_prefix.size() > new_size)
+ common_prefix.erase (new_size);
- for (size_t i = 0; i < common_prefix.size(); i++)
- {
- if (m_strings[pos][i] != common_prefix[i])
+ // Then trim it at the first disparity:
+ for (size_t i = 0; i < common_prefix.size(); i++)
{
- common_prefix.erase(i);
- break;
+ if (curr_string[i] != common_prefix[i])
+ {
+ common_prefix.erase(i);
+ break;
+ }
}
- }
- // If we've emptied the common prefix, we're done.
- if (common_prefix.empty())
- break;
+ // If we've emptied the common prefix, we're done.
+ if (common_prefix.empty())
+ break;
+ }
}
}
@@ -173,6 +195,24 @@ StringList::InsertStringAtIndex (size_t idx, const char *str)
}
void
+StringList::InsertStringAtIndex (size_t idx, const std::string &str)
+{
+ if (idx < m_strings.size())
+ m_strings.insert (m_strings.begin() + idx, str);
+ else
+ m_strings.push_back (str);
+}
+
+void
+StringList::InsertStringAtIndex (size_t idx, std::string &&str)
+{
+ if (idx < m_strings.size())
+ m_strings.insert (m_strings.begin() + idx, str);
+ else
+ m_strings.push_back (str);
+}
+
+void
StringList::DeleteStringAtIndex (size_t idx)
{
if (idx < m_strings.size())
@@ -180,6 +220,12 @@ StringList::DeleteStringAtIndex (size_t idx)
}
size_t
+StringList::SplitIntoLines (const std::string &lines)
+{
+ return SplitIntoLines (lines.c_str(), lines.size());
+}
+
+size_t
StringList::SplitIntoLines (const char *lines, size_t len)
{
const size_t orig_size = m_strings.size();
@@ -231,8 +277,7 @@ StringList::RemoveBlankLines ()
}
std::string
-StringList::CopyList(const char* item_preamble,
- const char* items_sep)
+StringList::CopyList(const char* item_preamble, const char* items_sep) const
{
StreamString strm;
for (size_t i = 0; i < GetSize(); i++)
diff --git a/source/Core/Value.cpp b/source/Core/Value.cpp
index 9dd72c7546bf..9d42a3774624 100644
--- a/source/Core/Value.cpp
+++ b/source/Core/Value.cpp
@@ -26,6 +26,7 @@
#include "lldb/Symbol/Variable.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
using namespace lldb;
diff --git a/source/Core/ValueObject.cpp b/source/Core/ValueObject.cpp
index d39d21a2a0bf..10e5ab452f0f 100644
--- a/source/Core/ValueObject.cpp
+++ b/source/Core/ValueObject.cpp
@@ -50,6 +50,7 @@
#include "lldb/Target/ObjCLanguageRuntime.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
@@ -977,14 +978,14 @@ ValueObject::GetPointeeData (DataExtractor& data,
ValueObjectSP pointee_sp = Dereference(error);
if (error.Fail() || pointee_sp.get() == NULL)
return 0;
- return pointee_sp->GetDataExtractor().Copy(data);
+ return pointee_sp->GetData(data);
}
else
{
ValueObjectSP child_sp = GetChildAtIndex(0, true);
if (child_sp.get() == NULL)
return 0;
- return child_sp->GetDataExtractor().Copy(data);
+ return child_sp->GetData(data);
}
return true;
}
@@ -1388,99 +1389,33 @@ ValueObject::GetObjectDescription ()
}
bool
-ValueObject::GetValueAsCString (lldb::Format format,
+ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
std::string& destination)
{
- if (GetClangType().IsAggregateType () == false && UpdateValueIfNeeded(false))
- {
- const Value::ContextType context_type = m_value.GetContextType();
-
- if (context_type == Value::eContextTypeRegisterInfo)
- {
- const RegisterInfo *reg_info = m_value.GetRegisterInfo();
- if (reg_info)
- {
- ExecutionContext exe_ctx (GetExecutionContextRef());
-
- StreamString reg_sstr;
- m_data.Dump (&reg_sstr,
- 0,
- format,
- reg_info->byte_size,
- 1,
- UINT32_MAX,
- LLDB_INVALID_ADDRESS,
- 0,
- 0,
- exe_ctx.GetBestExecutionContextScope());
- destination.swap(reg_sstr.GetString());
- }
- }
- else
- {
- ClangASTType clang_type = GetClangType ();
- if (clang_type)
- {
- // put custom bytes to display in this DataExtractor to override the default value logic
- lldb_private::DataExtractor special_format_data;
- if (format == eFormatCString)
- {
- Flags type_flags(clang_type.GetTypeInfo(NULL));
- if (type_flags.Test(ClangASTType::eTypeIsPointer) && !type_flags.Test(ClangASTType::eTypeIsObjC))
- {
- // if we are dumping a pointer as a c-string, get the pointee data as a string
- TargetSP target_sp(GetTargetSP());
- if (target_sp)
- {
- size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
- Error error;
- DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0));
- Address address(GetPointerValue());
- if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success())
- special_format_data.SetData(buffer_sp);
- }
- }
- }
-
- StreamString sstr;
- ExecutionContext exe_ctx (GetExecutionContextRef());
- clang_type.DumpTypeValue (&sstr, // The stream to use for display
- format, // Format to display this type with
- special_format_data.GetByteSize() ?
- special_format_data: m_data, // Data to extract from
- 0, // Byte offset into "m_data"
- GetByteSize(), // Byte size of item in "m_data"
- GetBitfieldBitSize(), // Bitfield bit size
- GetBitfieldBitOffset(), // Bitfield bit offset
- exe_ctx.GetBestExecutionContextScope());
- // Don't set the m_error to anything here otherwise
- // we won't be able to re-format as anything else. The
- // code for ClangASTType::DumpTypeValue() should always
- // return something, even if that something contains
- // an error messsage. "m_error" is used to detect errors
- // when reading the valid object, not for formatting errors.
- if (sstr.GetString().empty())
- destination.clear();
- else
- destination.swap(sstr.GetString());
- }
- }
- return !destination.empty();
- }
+ if (UpdateValueIfNeeded(false))
+ return format.FormatObject(this,destination);
else
return false;
}
+bool
+ValueObject::GetValueAsCString (lldb::Format format,
+ std::string& destination)
+{
+ return GetValueAsCString(TypeFormatImpl_Format(format),destination);
+}
+
const char *
ValueObject::GetValueAsCString ()
{
if (UpdateValueIfNeeded(true))
{
+ lldb::TypeFormatImplSP format_sp;
lldb::Format my_format = GetFormat();
if (my_format == lldb::eFormatDefault)
{
if (m_type_format_sp)
- my_format = m_type_format_sp->GetFormat();
+ format_sp = m_type_format_sp;
else
{
if (m_is_bitfield_for_scalar)
@@ -1503,7 +1438,9 @@ ValueObject::GetValueAsCString ()
if (my_format != m_last_format || m_value_str.empty())
{
m_last_format = my_format;
- if (GetValueAsCString(my_format, m_value_str))
+ if (!format_sp)
+ format_sp.reset(new TypeFormatImpl_Format(my_format));
+ if (GetValueAsCString(*format_sp.get(), m_value_str))
{
if (!m_value_did_change && m_old_value_valid)
{
@@ -1609,7 +1546,8 @@ bool
ValueObject::DumpPrintableRepresentation(Stream& s,
ValueObjectRepresentationStyle val_obj_display,
Format custom_format,
- PrintableRepresentationSpecialCases special)
+ PrintableRepresentationSpecialCases special,
+ bool do_dump_error)
{
Flags flags(GetTypeInfo());
@@ -1808,7 +1746,12 @@ ValueObject::DumpPrintableRepresentation(Stream& s,
else
{
if (m_error.Fail())
- s.Printf("<%s>", m_error.AsCString());
+ {
+ if (do_dump_error)
+ s.Printf("<%s>", m_error.AsCString());
+ else
+ return false;
+ }
else if (val_obj_display == eValueObjectRepresentationStyleSummary)
s.PutCString("<no summary available>");
else if (val_obj_display == eValueObjectRepresentationStyleValue)
@@ -3515,7 +3458,8 @@ ValueObject::CreateConstantValue (const ConstString &name)
if (!valobj_sp)
{
- valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
+ ExecutionContext exe_ctx (GetExecutionContextRef());
+ valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
}
return valobj_sp;
}
@@ -3769,7 +3713,8 @@ ValueObject::EvaluationPoint::SyncWithProcessState()
{
// Start with the target, if it is NULL, then we're obviously not going to get any further:
- ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
+ const bool thread_and_frame_only_if_stopped = true;
+ ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
if (exe_ctx.GetTargetPtr() == NULL)
return false;
diff --git a/source/Core/ValueObjectChild.cpp b/source/Core/ValueObjectChild.cpp
index 23add1ccf0e8..ccf87cd15b24 100644
--- a/source/Core/ValueObjectChild.cpp
+++ b/source/Core/ValueObjectChild.cpp
@@ -206,8 +206,12 @@ ValueObjectChild::UpdateValue ()
if (m_error.Success())
{
- ExecutionContext exe_ctx (GetExecutionContextRef().Lock());
- m_error = m_value.GetValueAsData (&exe_ctx, m_data, 0, GetModule().get());
+ const bool thread_and_frame_only_if_stopped = true;
+ ExecutionContext exe_ctx (GetExecutionContextRef().Lock(thread_and_frame_only_if_stopped));
+ if (GetClangType().GetTypeInfo() & ClangASTType::eTypeHasValue)
+ m_error = m_value.GetValueAsData (&exe_ctx, m_data, 0, GetModule().get());
+ else
+ m_error.Clear(); // No value so nothing to read...
}
}
else
diff --git a/source/Core/ValueObjectVariable.cpp b/source/Core/ValueObjectVariable.cpp
index 3d8b07a36948..2e5bb22a890c 100644
--- a/source/Core/ValueObjectVariable.cpp
+++ b/source/Core/ValueObjectVariable.cpp
@@ -328,6 +328,12 @@ ValueObjectVariable::GetLocationAsCString ()
bool
ValueObjectVariable::SetValueFromCString (const char *value_str, Error& error)
{
+ if (!UpdateValueIfNeeded())
+ {
+ error.SetErrorString("unable to update value before writing");
+ return false;
+ }
+
if (m_resolved_value.GetContextType() == Value::eContextTypeRegisterInfo)
{
RegisterInfo *reg_info = m_resolved_value.GetRegisterInfo();
@@ -360,6 +366,12 @@ ValueObjectVariable::SetValueFromCString (const char *value_str, Error& error)
bool
ValueObjectVariable::SetData (DataExtractor &data, Error &error)
{
+ if (!UpdateValueIfNeeded())
+ {
+ error.SetErrorString("unable to update value before writing");
+ return false;
+ }
+
if (m_resolved_value.GetContextType() == Value::eContextTypeRegisterInfo)
{
RegisterInfo *reg_info = m_resolved_value.GetRegisterInfo();
@@ -371,7 +383,7 @@ ValueObjectVariable::SetData (DataExtractor &data, Error &error)
error.SetErrorString("unable to retrieve register info");
return false;
}
- error = reg_value.SetValueFromData(reg_info, data, 0, false);
+ error = reg_value.SetValueFromData(reg_info, data, 0, true);
if (error.Fail())
return false;
if (reg_ctx->WriteRegister (reg_info, reg_value))
diff --git a/source/DataFormatters/DataVisualization.cpp b/source/DataFormatters/DataVisualization.cpp
index 48d3517750aa..c2c2206f3449 100644
--- a/source/DataFormatters/DataVisualization.cpp
+++ b/source/DataFormatters/DataVisualization.cpp
@@ -204,35 +204,35 @@ DataVisualization::Categories::GetCategoryAtIndex (size_t index)
bool
DataVisualization::NamedSummaryFormats::GetSummaryFormat (const ConstString &type, lldb::TypeSummaryImplSP &entry)
{
- return GetFormatManager().GetNamedSummaryNavigator().Get(type,entry);
+ return GetFormatManager().GetNamedSummaryContainer().Get(type,entry);
}
void
DataVisualization::NamedSummaryFormats::Add (const ConstString &type, const lldb::TypeSummaryImplSP &entry)
{
- GetFormatManager().GetNamedSummaryNavigator().Add(FormatManager::GetValidTypeName(type),entry);
+ GetFormatManager().GetNamedSummaryContainer().Add(FormatManager::GetValidTypeName(type),entry);
}
bool
DataVisualization::NamedSummaryFormats::Delete (const ConstString &type)
{
- return GetFormatManager().GetNamedSummaryNavigator().Delete(type);
+ return GetFormatManager().GetNamedSummaryContainer().Delete(type);
}
void
DataVisualization::NamedSummaryFormats::Clear ()
{
- GetFormatManager().GetNamedSummaryNavigator().Clear();
+ GetFormatManager().GetNamedSummaryContainer().Clear();
}
void
DataVisualization::NamedSummaryFormats::LoopThrough (TypeSummaryImpl::SummaryCallback callback, void* callback_baton)
{
- GetFormatManager().GetNamedSummaryNavigator().LoopThrough(callback, callback_baton);
+ GetFormatManager().GetNamedSummaryContainer().LoopThrough(callback, callback_baton);
}
uint32_t
DataVisualization::NamedSummaryFormats::GetCount ()
{
- return GetFormatManager().GetNamedSummaryNavigator().GetCount();
+ return GetFormatManager().GetNamedSummaryContainer().GetCount();
}
diff --git a/source/DataFormatters/FormatManager.cpp b/source/DataFormatters/FormatManager.cpp
index bec2edf5d5c2..751e61284610 100644
--- a/source/DataFormatters/FormatManager.cpp
+++ b/source/DataFormatters/FormatManager.cpp
@@ -741,12 +741,12 @@ AddFormat (TypeCategoryImpl::SharedPointer category_sp,
TypeFormatImpl::Flags flags,
bool regex = false)
{
- lldb::TypeFormatImplSP format_sp(new TypeFormatImpl(format, flags));
+ lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags));
if (regex)
- category_sp->GetRegexValueNavigator()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),format_sp);
+ category_sp->GetRegexTypeFormatsContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),format_sp);
else
- category_sp->GetValueNavigator()->Add(type_name, format_sp);
+ category_sp->GetTypeFormatsContainer()->Add(type_name, format_sp);
}
@@ -761,9 +761,9 @@ AddStringSummary(TypeCategoryImpl::SharedPointer category_sp,
string));
if (regex)
- category_sp->GetRegexSummaryNavigator()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
+ category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
else
- category_sp->GetSummaryNavigator()->Add(type_name, summary_sp);
+ category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
}
#ifndef LLDB_DISABLE_PYTHON
@@ -782,9 +782,9 @@ AddScriptSummary(TypeCategoryImpl::SharedPointer category_sp,
funct_name,
code.c_str()));
if (regex)
- category_sp->GetRegexSummaryNavigator()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
+ category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
else
- category_sp->GetSummaryNavigator()->Add(type_name, summary_sp);
+ category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
}
#endif
@@ -799,9 +799,9 @@ AddCXXSummary (TypeCategoryImpl::SharedPointer category_sp,
{
lldb::TypeSummaryImplSP summary_sp(new CXXFunctionSummaryFormat(flags,funct,description));
if (regex)
- category_sp->GetRegexSummaryNavigator()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
+ category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
else
- category_sp->GetSummaryNavigator()->Add(type_name, summary_sp);
+ category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
}
#endif
@@ -815,9 +815,27 @@ static void AddCXXSynthetic (TypeCategoryImpl::SharedPointer category_sp,
{
lldb::SyntheticChildrenSP synth_sp(new CXXSyntheticChildren(flags,description,generator));
if (regex)
- category_sp->GetRegexSyntheticNavigator()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())), synth_sp);
+ category_sp->GetRegexTypeSyntheticsContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())), synth_sp);
else
- category_sp->GetSyntheticNavigator()->Add(type_name,synth_sp);
+ category_sp->GetTypeSyntheticsContainer()->Add(type_name,synth_sp);
+}
+#endif
+
+#ifndef LLDB_DISABLE_PYTHON
+static void AddFilter (TypeCategoryImpl::SharedPointer category_sp,
+ std::vector<std::string> children,
+ const char* description,
+ ConstString type_name,
+ ScriptedSyntheticChildren::Flags flags,
+ bool regex = false)
+{
+ TypeFilterImplSP filter_sp(new TypeFilterImpl(flags));
+ for (auto child : children)
+ filter_sp->AddExpressionPath(child);
+ if (regex)
+ category_sp->GetRegexTypeFiltersContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())), filter_sp);
+ else
+ category_sp->GetTypeFiltersContainer()->Add(type_name,filter_sp);
}
#endif
@@ -838,26 +856,26 @@ FormatManager::LoadLibStdcppFormatters()
TypeCategoryImpl::SharedPointer gnu_category_sp = GetCategory(m_gnu_cpp_category_name);
- gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::string"),
+ gnu_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::string"),
std_string_summary_sp);
- gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string<char>"),
+ gnu_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::basic_string<char>"),
std_string_summary_sp);
- gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string<char,std::char_traits<char>,std::allocator<char> >"),
+ gnu_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::basic_string<char,std::char_traits<char>,std::allocator<char> >"),
std_string_summary_sp);
- gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
+ gnu_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
std_string_summary_sp);
// making sure we force-pick the summary for printing wstring (_M_p is a wchar_t*)
lldb::TypeSummaryImplSP std_wstring_summary_sp(new StringSummaryFormat(stl_summary_flags,
"${var._M_dataplus._M_p%S}"));
- gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::wstring"),
+ gnu_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::wstring"),
std_wstring_summary_sp);
- gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string<wchar_t>"),
+ gnu_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::basic_string<wchar_t>"),
std_wstring_summary_sp);
- gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >"),
+ gnu_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >"),
std_wstring_summary_sp);
- gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >"),
+ gnu_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >"),
std_wstring_summary_sp);
@@ -866,24 +884,24 @@ FormatManager::LoadLibStdcppFormatters()
SyntheticChildren::Flags stl_synth_flags;
stl_synth_flags.SetCascades(true).SetSkipPointers(false).SetSkipReferences(false);
- gnu_category_sp->GetRegexSyntheticNavigator()->Add(RegularExpressionSP(new RegularExpression("^std::vector<.+>(( )?&)?$")),
+ gnu_category_sp->GetRegexTypeSyntheticsContainer()->Add(RegularExpressionSP(new RegularExpression("^std::vector<.+>(( )?&)?$")),
SyntheticChildrenSP(new ScriptedSyntheticChildren(stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdVectorSynthProvider")));
- gnu_category_sp->GetRegexSyntheticNavigator()->Add(RegularExpressionSP(new RegularExpression("^std::map<.+> >(( )?&)?$")),
+ gnu_category_sp->GetRegexTypeSyntheticsContainer()->Add(RegularExpressionSP(new RegularExpression("^std::map<.+> >(( )?&)?$")),
SyntheticChildrenSP(new ScriptedSyntheticChildren(stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdMapSynthProvider")));
- gnu_category_sp->GetRegexSyntheticNavigator()->Add(RegularExpressionSP(new RegularExpression("^std::list<.+>(( )?&)?$")),
+ gnu_category_sp->GetRegexTypeSyntheticsContainer()->Add(RegularExpressionSP(new RegularExpression("^std::list<.+>(( )?&)?$")),
SyntheticChildrenSP(new ScriptedSyntheticChildren(stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdListSynthProvider")));
stl_summary_flags.SetDontShowChildren(false);stl_summary_flags.SetSkipPointers(true);
- gnu_category_sp->GetRegexSummaryNavigator()->Add(RegularExpressionSP(new RegularExpression("^std::vector<.+>(( )?&)?$")),
+ gnu_category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression("^std::vector<.+>(( )?&)?$")),
TypeSummaryImplSP(new StringSummaryFormat(stl_summary_flags,
"size=${svar%#}")));
- gnu_category_sp->GetRegexSummaryNavigator()->Add(RegularExpressionSP(new RegularExpression("^std::map<.+> >(( )?&)?$")),
+ gnu_category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression("^std::map<.+> >(( )?&)?$")),
TypeSummaryImplSP(new StringSummaryFormat(stl_summary_flags,
"size=${svar%#}")));
- gnu_category_sp->GetRegexSummaryNavigator()->Add(RegularExpressionSP(new RegularExpression("^std::list<.+>(( )?&)?$")),
+ gnu_category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression("^std::list<.+>(( )?&)?$")),
TypeSummaryImplSP(new StringSummaryFormat(stl_summary_flags,
"size=${svar%#}")));
@@ -891,10 +909,10 @@ FormatManager::LoadLibStdcppFormatters()
AddCXXSynthetic(gnu_category_sp, lldb_private::formatters::LibstdcppMapIteratorSyntheticFrontEndCreator, "std::map iterator synthetic children", ConstString("^std::_Rb_tree_iterator<.+>$"), stl_synth_flags, true);
- gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::vector<std::allocator<bool> >"),
+ gnu_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::vector<std::allocator<bool> >"),
TypeSummaryImplSP(new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
- gnu_category_sp->GetSyntheticNavigator()->Add(ConstString("std::vector<std::allocator<bool> >"),
+ gnu_category_sp->GetTypeSyntheticsContainer()->Add(ConstString("std::vector<std::allocator<bool> >"),
SyntheticChildrenSP(new CXXSyntheticChildren(stl_synth_flags,"libc++ std::vector<bool> synthetic children",lldb_private::formatters::LibstdcppVectorBoolSyntheticFrontEndCreator)));
#endif
@@ -921,14 +939,14 @@ FormatManager::LoadLibcxxFormatters()
TypeCategoryImpl::SharedPointer libcxx_category_sp = GetCategory(m_libcxx_category_name);
- libcxx_category_sp->GetSummaryNavigator()->Add(ConstString("std::__1::string"),
+ libcxx_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::__1::string"),
std_string_summary_sp);
- libcxx_category_sp->GetSummaryNavigator()->Add(ConstString("std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >"),
+ libcxx_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >"),
std_string_summary_sp);
- libcxx_category_sp->GetSummaryNavigator()->Add(ConstString("std::__1::wstring"),
+ libcxx_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::__1::wstring"),
std_wstring_summary_sp);
- libcxx_category_sp->GetSummaryNavigator()->Add(ConstString("std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >"),
+ libcxx_category_sp->GetTypeSummariesContainer()->Add(ConstString("std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >"),
std_wstring_summary_sp);
SyntheticChildren::Flags stl_synth_flags;
@@ -943,7 +961,7 @@ FormatManager::LoadLibcxxFormatters()
AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator, "libc++ std::multimap synthetic children", ConstString("^std::__1::multimap<.+> >(( )?&)?$"), stl_synth_flags, true);
AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEndCreator, "libc++ std::unordered containers synthetic children", ConstString("^(std::__1::)unordered_(multi)?(map|set)<.+> >$"), stl_synth_flags, true);
- libcxx_category_sp->GetRegexSyntheticNavigator()->Add(RegularExpressionSP(new RegularExpression("^(std::__1::)deque<.+>(( )?&)?$")),
+ libcxx_category_sp->GetRegexTypeSyntheticsContainer()->Add(RegularExpressionSP(new RegularExpression("^(std::__1::)deque<.+>(( )?&)?$")),
SyntheticChildrenSP(new ScriptedSyntheticChildren(stl_synth_flags,
"lldb.formatters.cpp.libcxx.stddeque_SynthProvider")));
@@ -963,13 +981,15 @@ FormatManager::LoadLibcxxFormatters()
AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::unordered containers summary provider", ConstString("^(std::__1::)unordered_(multi)?(map|set)<.+> >$"), stl_summary_flags, true);
stl_summary_flags.SetSkipPointers(true);
- AddStringSummary(libcxx_category_sp, "{${var.__ptr_%S}} (strong=${var.count} weak=${var.weak_count})}", ConstString("^std::__1::shared_ptr<.+>(( )?&)?$"), stl_summary_flags, true);
- AddStringSummary(libcxx_category_sp, "{${var.__ptr_%S}} (strong=${var.count} weak=${var.weak_count})}", ConstString("^std::__1::weak_ptr<.+>(( )?&)?$"), stl_summary_flags, true);
+
+ AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxSmartPointerSummaryProvider, "libc++ std::shared_ptr summary provider", ConstString("^std::__1::shared_ptr<.+>(( )?&)?$"), stl_summary_flags, true);
+ AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxSmartPointerSummaryProvider, "libc++ std::weak_ptr summary provider", ConstString("^std::__1::weak_ptr<.+>(( )?&)?$"), stl_summary_flags, true);
AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibCxxVectorIteratorSyntheticFrontEndCreator, "std::vector iterator synthetic children", ConstString("^std::__1::__wrap_iter<.+>$"), stl_synth_flags, true);
AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEndCreator, "std::map iterator synthetic children", ConstString("^std::__1::__map_iterator<.+>$"), stl_synth_flags, true);
+ AddFilter(libcxx_category_sp, {"__a_"}, "libc++ std::atomic filter", ConstString("^std::__1::atomic<.*>$"), stl_synth_flags, true);
#endif
}
@@ -1002,9 +1022,9 @@ FormatManager::LoadSystemFormatters()
TypeCategoryImpl::SharedPointer sys_category_sp = GetCategory(m_system_category_name);
- sys_category_sp->GetSummaryNavigator()->Add(ConstString("char *"), string_format);
- sys_category_sp->GetSummaryNavigator()->Add(ConstString("unsigned char *"), string_format);
- sys_category_sp->GetRegexSummaryNavigator()->Add(any_size_char_arr, string_array_format);
+ sys_category_sp->GetTypeSummariesContainer()->Add(ConstString("char *"), string_format);
+ sys_category_sp->GetTypeSummariesContainer()->Add(ConstString("unsigned char *"), string_format);
+ sys_category_sp->GetRegexTypeSummariesContainer()->Add(any_size_char_arr, string_array_format);
lldb::TypeSummaryImplSP ostype_summary(new StringSummaryFormat(TypeSummaryImpl::Flags().SetCascades(false)
.SetSkipPointers(true)
@@ -1015,10 +1035,10 @@ FormatManager::LoadSystemFormatters()
.SetHideItemNames(false),
"${var%O}"));
- sys_category_sp->GetSummaryNavigator()->Add(ConstString("OSType"), ostype_summary);
+ sys_category_sp->GetTypeSummariesContainer()->Add(ConstString("OSType"), ostype_summary);
#ifndef LLDB_DISABLE_PYTHON
- // FIXME because of a bug in the FormatNavigator we need to add a summary for both X* and const X* (<rdar://problem/12717717>)
+ // FIXME because of a bug in the FormattersContainer we need to add a summary for both X* and const X* (<rdar://problem/12717717>)
AddCXXSummary(sys_category_sp, lldb_private::formatters::Char16StringSummaryProvider, "char16_t * summary provider", ConstString("char16_t *"), string_flags);
AddCXXSummary(sys_category_sp, lldb_private::formatters::Char32StringSummaryProvider, "char32_t * summary provider", ConstString("char32_t *"), string_flags);
@@ -1065,11 +1085,11 @@ FormatManager::LoadObjCFormatters()
TypeCategoryImpl::SharedPointer objc_category_sp = GetCategory(m_objc_category_name);
lldb::TypeSummaryImplSP ObjC_BOOL_summary(new CXXFunctionSummaryFormat(objc_flags, lldb_private::formatters::ObjCBOOLSummaryProvider,""));
- objc_category_sp->GetSummaryNavigator()->Add(ConstString("BOOL"),
+ objc_category_sp->GetTypeSummariesContainer()->Add(ConstString("BOOL"),
ObjC_BOOL_summary);
- objc_category_sp->GetSummaryNavigator()->Add(ConstString("BOOL &"),
+ objc_category_sp->GetTypeSummariesContainer()->Add(ConstString("BOOL &"),
ObjC_BOOL_summary);
- objc_category_sp->GetSummaryNavigator()->Add(ConstString("BOOL *"),
+ objc_category_sp->GetTypeSummariesContainer()->Add(ConstString("BOOL *"),
ObjC_BOOL_summary);
#ifndef LLDB_DISABLE_PYTHON
@@ -1256,6 +1276,7 @@ FormatManager::LoadObjCFormatters()
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("NSString"), appkit_flags);
AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("CFStringRef"), appkit_flags);
+ AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("__CFString"), appkit_flags);
AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("CFMutableStringRef"), appkit_flags);
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("NSMutableString"), appkit_flags);
AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSStringSummaryProvider, "NSString summary provider", ConstString("__NSCFConstantString"), appkit_flags);
@@ -1286,7 +1307,7 @@ FormatManager::LoadObjCFormatters()
AddStringSummary(appkit_category_sp,"name:${var.name%S} reason:${var.reason%S}",ConstString("NSException"),appkit_flags);
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("NSNumber"), appkit_flags);
- AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "CFNumberRef summary provider", ConstString("CFNumberRef"), appkit_flags);
+ AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "CFNumberRef summary provider", ConstString("CFNumberRef"), appkit_flags);
AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("__NSCFBoolean"), appkit_flags);
AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("__NSCFNumber"), appkit_flags);
AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSNumberSummaryProvider, "NSNumber summary provider", ConstString("NSCFBoolean"), appkit_flags);
@@ -1306,7 +1327,7 @@ FormatManager::LoadObjCFormatters()
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSDateSummaryProvider, "NSDate summary provider", ConstString("NSCalendarDate"), appkit_flags);
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSTimeZoneSummaryProvider, "NSTimeZone summary provider", ConstString("NSTimeZone"), appkit_flags);
- AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSTimeZoneSummaryProvider, "NSTimeZone summary provider", ConstString("CFTimeZoneRef"), appkit_flags);
+ AddCXXSummary(corefoundation_category_sp, lldb_private::formatters::NSTimeZoneSummaryProvider, "NSTimeZone summary provider", ConstString("CFTimeZoneRef"), appkit_flags);
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSTimeZoneSummaryProvider, "NSTimeZone summary provider", ConstString("__NSTimeZone"), appkit_flags);
// CFAbsoluteTime is actually a double rather than a pointer to an object
@@ -1318,7 +1339,7 @@ FormatManager::LoadObjCFormatters()
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSIndexSetSummaryProvider, "NSIndexSet summary provider", ConstString("NSIndexSet"), appkit_flags);
AddCXXSummary(appkit_category_sp, lldb_private::formatters::NSIndexSetSummaryProvider, "NSIndexSet summary provider", ConstString("NSMutableIndexSet"), appkit_flags);
- AddStringSummary(appkit_category_sp,
+ AddStringSummary(corefoundation_category_sp,
"@\"${var.month%d}/${var.day%d}/${var.year%d} ${var.hour%d}:${var.minute%d}:${var.second}\"",
ConstString("CFGregorianDate"),
appkit_flags);
diff --git a/source/DataFormatters/LibCxx.cpp b/source/DataFormatters/LibCxx.cpp
index 21e104602a3f..6380d971a177 100644
--- a/source/DataFormatters/LibCxx.cpp
+++ b/source/DataFormatters/LibCxx.cpp
@@ -26,19 +26,64 @@ using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
+bool
+lldb_private::formatters::LibcxxSmartPointerSummaryProvider (ValueObject& valobj, Stream& stream)
+{
+ ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue());
+ if (!valobj_sp)
+ return false;
+ ValueObjectSP ptr_sp(valobj_sp->GetChildMemberWithName(ConstString("__ptr_"), true));
+ ValueObjectSP count_sp(valobj_sp->GetChildAtNamePath( {ConstString("__cntrl_"),ConstString("__shared_owners_")} ));
+ ValueObjectSP weakcount_sp(valobj_sp->GetChildAtNamePath( {ConstString("__cntrl_"),ConstString("__shared_weak_owners_")} ));
+
+ if (!ptr_sp)
+ return false;
+
+ if (ptr_sp->GetValueAsUnsigned(0) == 0)
+ {
+ stream.Printf("nullptr");
+ return true;
+ }
+ else
+ {
+ bool print_pointee = false;
+ Error error;
+ ValueObjectSP pointee_sp = ptr_sp->Dereference(error);
+ if (pointee_sp && error.Success())
+ {
+ if (pointee_sp->DumpPrintableRepresentation(stream,
+ ValueObject::eValueObjectRepresentationStyleSummary,
+ lldb::eFormatInvalid,
+ ValueObject::ePrintableRepresentationSpecialCasesDisable,
+ false))
+ print_pointee = true;
+ }
+ if (!print_pointee)
+ stream.Printf("ptr = 0x%" PRIx64, ptr_sp->GetValueAsUnsigned(0));
+ }
+
+ if (count_sp)
+ stream.Printf(" strong=%" PRIu64, 1+count_sp->GetValueAsUnsigned(0));
+
+ if (weakcount_sp)
+ stream.Printf(" weak=%" PRIu64, 1+weakcount_sp->GetValueAsUnsigned(0));
+
+ return true;
+}
+
lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::LibcxxVectorBoolSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
SyntheticChildrenFrontEnd(*valobj_sp.get()),
+m_bool_type(),
m_exe_ctx_ref(),
m_count(0),
m_base_data_address(0),
-m_options()
+m_children()
{
if (valobj_sp)
+ {
Update();
- m_options.SetCoerceToId(false);
- m_options.SetUnwindOnError(true);
- m_options.SetKeepInMemory(true);
- m_options.SetUseDynamic(lldb::eDynamicCanRunTarget);
+ m_bool_type = valobj_sp->GetClangType().GetBasicTypeFromAST(lldb::eBasicTypeBool);
+ }
}
size_t
@@ -50,10 +95,16 @@ lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::CalculateNumChildre
lldb::ValueObjectSP
lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::GetChildAtIndex (size_t idx)
{
+ auto iter = m_children.find(idx),
+ end = m_children.end();
+ if (iter != end)
+ return iter->second;
if (idx >= m_count)
return ValueObjectSP();
if (m_base_data_address == 0 || m_count == 0)
return ValueObjectSP();
+ if (!m_bool_type)
+ return ValueObjectSP();
size_t byte_idx = (idx >> 3); // divide by 8 to get byte index
size_t bit_index = (idx & 7); // efficient idx % 8 for bit index
lldb::addr_t byte_location = m_base_data_address + byte_idx;
@@ -88,15 +139,15 @@ lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::GetChildAtIndex (si
return ValueObjectSP();
}
bool bit_set = ((byte & mask) != 0);
- Target& target(process_sp->GetTarget());
ValueObjectSP retval_sp;
- if (bit_set)
- target.EvaluateExpression("(bool)true", NULL, retval_sp);
- else
- target.EvaluateExpression("(bool)false", NULL, retval_sp);
+ DataBufferSP buffer_sp(new DataBufferHeap(m_bool_type.GetByteSize(),0));
+ if (bit_set && buffer_sp && buffer_sp->GetBytes())
+ *(buffer_sp->GetBytes()) = 1; // regardless of endianness, anything non-zero is true
StreamString name; name.Printf("[%zu]",idx);
+ DataExtractor data(buffer_sp, process_sp->GetByteOrder(), process_sp->GetAddressByteSize());
+ retval_sp = ValueObject::CreateValueObjectFromData(name.GetData(), data, m_exe_ctx_ref, m_bool_type);
if (retval_sp)
- retval_sp->SetName(ConstString(name.GetData()));
+ m_children[idx] = retval_sp;
return retval_sp;
}
@@ -113,6 +164,7 @@ lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::GetChildAtIndex (si
bool
lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::Update()
{
+ m_children.clear();
ValueObjectSP valobj_sp = m_backend.GetSP();
if (!valobj_sp)
return false;
diff --git a/source/DataFormatters/LibCxxUnorderedMap.cpp b/source/DataFormatters/LibCxxUnorderedMap.cpp
index b73d3bf852e1..05b41d0de0c8 100644
--- a/source/DataFormatters/LibCxxUnorderedMap.cpp
+++ b/source/DataFormatters/LibCxxUnorderedMap.cpp
@@ -84,7 +84,8 @@ lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::GetChildAtInde
stream.Printf("[%zu]",idx);
DataExtractor data;
val_hash.first->GetData(data);
- ExecutionContext exe_ctx = val_hash.first->GetExecutionContextRef().Lock();
+ const bool thread_and_frame_only_if_stopped = true;
+ ExecutionContext exe_ctx = val_hash.first->GetExecutionContextRef().Lock(thread_and_frame_only_if_stopped);
return val_hash.first->CreateValueObjectFromData(stream.GetData(),
data,
exe_ctx,
diff --git a/source/DataFormatters/TypeCategory.cpp b/source/DataFormatters/TypeCategory.cpp
index a02560e78780..322d1cf55437 100644
--- a/source/DataFormatters/TypeCategory.cpp
+++ b/source/DataFormatters/TypeCategory.cpp
@@ -21,15 +21,11 @@ using namespace lldb_private;
TypeCategoryImpl::TypeCategoryImpl(IFormatChangeListener* clist,
ConstString name) :
-m_value_nav(new ValueNavigator("format",clist)),
-m_regex_value_nav(new RegexValueNavigator("regex-format",clist)),
-m_summary_nav(new SummaryNavigator("summary",clist)),
-m_regex_summary_nav(new RegexSummaryNavigator("regex-summary",clist)),
-m_filter_nav(new FilterNavigator("filter",clist)),
-m_regex_filter_nav(new RegexFilterNavigator("regex-filter",clist)),
+m_format_cont("format","regex-format",clist),
+m_summary_cont("summary","regex-summary",clist),
+m_filter_cont("filter","regex-filter",clist),
#ifndef LLDB_DISABLE_PYTHON
-m_synth_nav(new SynthNavigator("synth",clist)),
-m_regex_synth_nav(new RegexSynthNavigator("regex-synth",clist)),
+m_synth_cont("synth","regex-synth",clist),
#endif
m_enabled(false),
m_change_listener(clist),
@@ -45,9 +41,9 @@ TypeCategoryImpl::Get (ValueObject& valobj,
{
if (!IsEnabled())
return false;
- if (GetValueNavigator()->Get(candidates, entry, reason))
+ if (GetTypeFormatsContainer()->Get(candidates, entry, reason))
return true;
- bool regex = GetRegexValueNavigator()->Get(candidates, entry, reason);
+ bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry, reason);
if (regex && reason)
*reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary;
return regex;
@@ -61,9 +57,9 @@ TypeCategoryImpl::Get (ValueObject& valobj,
{
if (!IsEnabled())
return false;
- if (GetSummaryNavigator()->Get(candidates, entry, reason))
+ if (GetTypeSummariesContainer()->Get(candidates, entry, reason))
return true;
- bool regex = GetRegexSummaryNavigator()->Get(candidates, entry, reason);
+ bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry, reason);
if (regex && reason)
*reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary;
return regex;
@@ -82,16 +78,16 @@ TypeCategoryImpl::Get (ValueObject& valobj,
bool regex_filter = false;
// first find both Filter and Synth, and then check which is most recent
- if (!GetFilterNavigator()->Get(candidates, filter_sp, &reason_filter))
- regex_filter = GetRegexFilterNavigator()->Get (candidates, filter_sp, &reason_filter);
+ if (!GetTypeFiltersContainer()->Get(candidates, filter_sp, &reason_filter))
+ regex_filter = GetRegexTypeFiltersContainer()->Get (candidates, filter_sp, &reason_filter);
#ifndef LLDB_DISABLE_PYTHON
bool regex_synth = false;
uint32_t reason_synth = 0;
bool pick_synth = false;
ScriptedSyntheticChildren::SharedPointer synth;
- if (!GetSyntheticNavigator()->Get(candidates, synth, &reason_synth))
- regex_synth = GetRegexSyntheticNavigator()->Get (candidates, synth, &reason_synth);
+ if (!GetTypeSyntheticsContainer()->Get(candidates, synth, &reason_synth))
+ regex_synth = GetRegexTypeSyntheticsContainer()->Get (candidates, synth, &reason_synth);
if (!filter_sp.get() && !synth.get())
return false;
else if (!filter_sp.get() && synth.get())
@@ -137,25 +133,25 @@ void
TypeCategoryImpl::Clear (FormatCategoryItems items)
{
if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
- m_value_nav->Clear();
+ GetTypeFormatsContainer()->Clear();
if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
- m_regex_value_nav->Clear();
+ GetRegexTypeFormatsContainer()->Clear();
if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
- m_summary_nav->Clear();
+ GetTypeSummariesContainer()->Clear();
if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
- m_regex_summary_nav->Clear();
+ GetRegexTypeSummariesContainer()->Clear();
if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
- m_filter_nav->Clear();
+ GetTypeFiltersContainer()->Clear();
if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
- m_regex_filter_nav->Clear();
+ GetRegexTypeFiltersContainer()->Clear();
#ifndef LLDB_DISABLE_PYTHON
if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
- m_synth_nav->Clear();
+ GetTypeSyntheticsContainer()->Clear();
if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
- m_regex_synth_nav->Clear();
+ GetRegexTypeSyntheticsContainer()->Clear();
#endif
}
@@ -166,25 +162,25 @@ TypeCategoryImpl::Delete (ConstString name,
bool success = false;
if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
- success = m_value_nav->Delete(name) || success;
+ success = GetTypeFormatsContainer()->Delete(name) || success;
if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
- success = m_regex_value_nav->Delete(name) || success;
+ success = GetRegexTypeFormatsContainer()->Delete(name) || success;
if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
- success = m_summary_nav->Delete(name) || success;
+ success = GetTypeSummariesContainer()->Delete(name) || success;
if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
- success = m_regex_summary_nav->Delete(name) || success;
+ success = GetRegexTypeSummariesContainer()->Delete(name) || success;
if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
- success = m_filter_nav->Delete(name) || success;
+ success = GetTypeFiltersContainer()->Delete(name) || success;
if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
- success = m_regex_filter_nav->Delete(name) || success;
+ success = GetRegexTypeFiltersContainer()->Delete(name) || success;
#ifndef LLDB_DISABLE_PYTHON
if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
- success = m_synth_nav->Delete(name) || success;
+ success = GetTypeSyntheticsContainer()->Delete(name) || success;
if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
- success = m_regex_synth_nav->Delete(name) || success;
+ success = GetRegexTypeSyntheticsContainer()->Delete(name) || success;
#endif
return success;
}
@@ -195,25 +191,25 @@ TypeCategoryImpl::GetCount (FormatCategoryItems items)
uint32_t count = 0;
if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
- count += m_value_nav->GetCount();
+ count += GetTypeFormatsContainer()->GetCount();
if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
- count += m_regex_value_nav->GetCount();
+ count += GetRegexTypeFormatsContainer()->GetCount();
if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
- count += m_summary_nav->GetCount();
+ count += GetTypeSummariesContainer()->GetCount();
if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
- count += m_regex_summary_nav->GetCount();
+ count += GetRegexTypeSummariesContainer()->GetCount();
if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
- count += m_filter_nav->GetCount();
+ count += GetTypeFiltersContainer()->GetCount();
if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
- count += m_regex_filter_nav->GetCount();
+ count += GetRegexTypeFiltersContainer()->GetCount();
#ifndef LLDB_DISABLE_PYTHON
if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
- count += m_synth_nav->GetCount();
+ count += GetTypeSyntheticsContainer()->GetCount();
if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
- count += m_regex_synth_nav->GetCount();
+ count += GetRegexTypeSyntheticsContainer()->GetCount();
#endif
return count;
}
@@ -237,7 +233,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name,
if ( (items & eFormatCategoryItemValue) == eFormatCategoryItemValue )
{
- if (m_value_nav->Get(type_name, format_sp))
+ if (GetTypeFormatsContainer()->Get(type_name, format_sp))
{
if (matching_category)
*matching_category = m_name.GetCString();
@@ -248,7 +244,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name,
}
if ( (items & eFormatCategoryItemRegexValue) == eFormatCategoryItemRegexValue )
{
- if (m_regex_value_nav->Get(type_name, format_sp))
+ if (GetRegexTypeFormatsContainer()->Get(type_name, format_sp))
{
if (matching_category)
*matching_category = m_name.GetCString();
@@ -260,7 +256,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name,
if ( (items & eFormatCategoryItemSummary) == eFormatCategoryItemSummary )
{
- if (m_summary_nav->Get(type_name, summary_sp))
+ if (GetTypeSummariesContainer()->Get(type_name, summary_sp))
{
if (matching_category)
*matching_category = m_name.GetCString();
@@ -271,7 +267,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name,
}
if ( (items & eFormatCategoryItemRegexSummary) == eFormatCategoryItemRegexSummary )
{
- if (m_regex_summary_nav->Get(type_name, summary_sp))
+ if (GetRegexTypeSummariesContainer()->Get(type_name, summary_sp))
{
if (matching_category)
*matching_category = m_name.GetCString();
@@ -283,7 +279,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name,
if ( (items & eFormatCategoryItemFilter) == eFormatCategoryItemFilter )
{
- if (m_filter_nav->Get(type_name, filter_sp))
+ if (GetTypeFiltersContainer()->Get(type_name, filter_sp))
{
if (matching_category)
*matching_category = m_name.GetCString();
@@ -294,7 +290,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name,
}
if ( (items & eFormatCategoryItemRegexFilter) == eFormatCategoryItemRegexFilter )
{
- if (m_regex_filter_nav->Get(type_name, filter_sp))
+ if (GetRegexTypeFiltersContainer()->Get(type_name, filter_sp))
{
if (matching_category)
*matching_category = m_name.GetCString();
@@ -307,7 +303,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name,
#ifndef LLDB_DISABLE_PYTHON
if ( (items & eFormatCategoryItemSynth) == eFormatCategoryItemSynth )
{
- if (m_synth_nav->Get(type_name, synth_sp))
+ if (GetTypeSyntheticsContainer()->Get(type_name, synth_sp))
{
if (matching_category)
*matching_category = m_name.GetCString();
@@ -318,7 +314,7 @@ TypeCategoryImpl::AnyMatches(ConstString type_name,
}
if ( (items & eFormatCategoryItemRegexSynth) == eFormatCategoryItemRegexSynth )
{
- if (m_regex_synth_nav->Get(type_name, synth_sp))
+ if (GetRegexTypeSyntheticsContainer()->Get(type_name, synth_sp))
{
if (matching_category)
*matching_category = m_name.GetCString();
@@ -331,66 +327,66 @@ TypeCategoryImpl::AnyMatches(ConstString type_name,
return false;
}
-TypeCategoryImpl::ValueNavigator::MapValueType
+TypeCategoryImpl::FormatContainer::MapValueType
TypeCategoryImpl::GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp)
{
- ValueNavigator::MapValueType retval;
+ FormatContainer::MapValueType retval;
if (type_sp)
{
if (type_sp->IsRegex())
- m_regex_value_nav->GetExact(ConstString(type_sp->GetName()),retval);
+ GetRegexTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
else
- m_value_nav->GetExact(ConstString(type_sp->GetName()),retval);
+ GetTypeFormatsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
}
return retval;
}
-TypeCategoryImpl::SummaryNavigator::MapValueType
+TypeCategoryImpl::SummaryContainer::MapValueType
TypeCategoryImpl::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp)
{
- SummaryNavigator::MapValueType retval;
+ SummaryContainer::MapValueType retval;
if (type_sp)
{
if (type_sp->IsRegex())
- m_regex_summary_nav->GetExact(ConstString(type_sp->GetName()),retval);
+ GetRegexTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()),retval);
else
- m_summary_nav->GetExact(ConstString(type_sp->GetName()),retval);
+ GetTypeSummariesContainer()->GetExact(ConstString(type_sp->GetName()),retval);
}
return retval;
}
-TypeCategoryImpl::FilterNavigator::MapValueType
+TypeCategoryImpl::FilterContainer::MapValueType
TypeCategoryImpl::GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp)
{
- FilterNavigator::MapValueType retval;
+ FilterContainer::MapValueType retval;
if (type_sp)
{
if (type_sp->IsRegex())
- m_regex_filter_nav->GetExact(ConstString(type_sp->GetName()),retval);
+ GetRegexTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),retval);
else
- m_filter_nav->GetExact(ConstString(type_sp->GetName()),retval);
+ GetTypeFiltersContainer()->GetExact(ConstString(type_sp->GetName()),retval);
}
return retval;
}
#ifndef LLDB_DISABLE_PYTHON
-TypeCategoryImpl::SynthNavigator::MapValueType
+TypeCategoryImpl::SynthContainer::MapValueType
TypeCategoryImpl::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp)
{
- SynthNavigator::MapValueType retval;
+ SynthContainer::MapValueType retval;
if (type_sp)
{
if (type_sp->IsRegex())
- m_regex_synth_nav->GetExact(ConstString(type_sp->GetName()),retval);
+ GetRegexTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
else
- m_synth_nav->GetExact(ConstString(type_sp->GetName()),retval);
+ GetTypeSyntheticsContainer()->GetExact(ConstString(type_sp->GetName()),retval);
}
return retval;
@@ -400,74 +396,74 @@ TypeCategoryImpl::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp)
lldb::TypeNameSpecifierImplSP
TypeCategoryImpl::GetTypeNameSpecifierForSummaryAtIndex (size_t index)
{
- if (index < m_summary_nav->GetCount())
- return m_summary_nav->GetTypeNameSpecifierAtIndex(index);
+ if (index < GetTypeSummariesContainer()->GetCount())
+ return GetTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index);
else
- return m_regex_summary_nav->GetTypeNameSpecifierAtIndex(index-m_summary_nav->GetCount());
+ return GetRegexTypeSummariesContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeSummariesContainer()->GetCount());
}
-TypeCategoryImpl::ValueNavigator::MapValueType
+TypeCategoryImpl::FormatContainer::MapValueType
TypeCategoryImpl::GetFormatAtIndex (size_t index)
{
- if (index < m_value_nav->GetCount())
- return m_value_nav->GetAtIndex(index);
+ if (index < GetTypeFormatsContainer()->GetCount())
+ return GetTypeFormatsContainer()->GetAtIndex(index);
else
- return m_regex_value_nav->GetAtIndex(index-m_value_nav->GetCount());
+ return GetRegexTypeFormatsContainer()->GetAtIndex(index-GetTypeFormatsContainer()->GetCount());
}
-TypeCategoryImpl::SummaryNavigator::MapValueType
+TypeCategoryImpl::SummaryContainer::MapValueType
TypeCategoryImpl::GetSummaryAtIndex (size_t index)
{
- if (index < m_summary_nav->GetCount())
- return m_summary_nav->GetAtIndex(index);
+ if (index < GetTypeSummariesContainer()->GetCount())
+ return GetTypeSummariesContainer()->GetAtIndex(index);
else
- return m_regex_summary_nav->GetAtIndex(index-m_summary_nav->GetCount());
+ return GetRegexTypeSummariesContainer()->GetAtIndex(index-GetTypeSummariesContainer()->GetCount());
}
-TypeCategoryImpl::FilterNavigator::MapValueType
+TypeCategoryImpl::FilterContainer::MapValueType
TypeCategoryImpl::GetFilterAtIndex (size_t index)
{
- if (index < m_filter_nav->GetCount())
- return m_filter_nav->GetAtIndex(index);
+ if (index < GetTypeFiltersContainer()->GetCount())
+ return GetTypeFiltersContainer()->GetAtIndex(index);
else
- return m_regex_filter_nav->GetAtIndex(index-m_filter_nav->GetCount());
+ return GetRegexTypeFiltersContainer()->GetAtIndex(index-GetTypeFiltersContainer()->GetCount());
}
lldb::TypeNameSpecifierImplSP
TypeCategoryImpl::GetTypeNameSpecifierForFormatAtIndex (size_t index)
{
- if (index < m_value_nav->GetCount())
- return m_value_nav->GetTypeNameSpecifierAtIndex(index);
+ if (index < GetTypeFormatsContainer()->GetCount())
+ return GetTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index);
else
- return m_regex_value_nav->GetTypeNameSpecifierAtIndex(index-m_value_nav->GetCount());
+ return GetRegexTypeFormatsContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeFormatsContainer()->GetCount());
}
lldb::TypeNameSpecifierImplSP
TypeCategoryImpl::GetTypeNameSpecifierForFilterAtIndex (size_t index)
{
- if (index < m_filter_nav->GetCount())
- return m_filter_nav->GetTypeNameSpecifierAtIndex(index);
+ if (index < GetTypeFiltersContainer()->GetCount())
+ return GetTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index);
else
- return m_regex_filter_nav->GetTypeNameSpecifierAtIndex(index-m_filter_nav->GetCount());
+ return GetRegexTypeFiltersContainer()->GetTypeNameSpecifierAtIndex(index-GetTypeFiltersContainer()->GetCount());
}
#ifndef LLDB_DISABLE_PYTHON
-TypeCategoryImpl::SynthNavigator::MapValueType
+TypeCategoryImpl::SynthContainer::MapValueType
TypeCategoryImpl::GetSyntheticAtIndex (size_t index)
{
- if (index < m_synth_nav->GetCount())
- return m_synth_nav->GetAtIndex(index);
+ if (index < GetTypeSyntheticsContainer()->GetCount())
+ return GetTypeSyntheticsContainer()->GetAtIndex(index);
else
- return m_regex_synth_nav->GetAtIndex(index-m_synth_nav->GetCount());
+ return GetRegexTypeSyntheticsContainer()->GetAtIndex(index-GetTypeSyntheticsContainer()->GetCount());
}
lldb::TypeNameSpecifierImplSP
TypeCategoryImpl::GetTypeNameSpecifierForSyntheticAtIndex (size_t index)
{
- if (index < m_synth_nav->GetCount())
- return m_synth_nav->GetTypeNameSpecifierAtIndex(index);
+ if (index < GetTypeSyntheticsContainer()->GetCount())
+ return GetTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index);
else
- return m_regex_synth_nav->GetTypeNameSpecifierAtIndex(index - m_synth_nav->GetCount());
+ return GetRegexTypeSyntheticsContainer()->GetTypeNameSpecifierAtIndex(index - GetTypeSyntheticsContainer()->GetCount());
}
#endif
diff --git a/source/DataFormatters/TypeFormat.cpp b/source/DataFormatters/TypeFormat.cpp
index 7f18ddef7264..a72f551c741f 100644
--- a/source/DataFormatters/TypeFormat.cpp
+++ b/source/DataFormatters/TypeFormat.cpp
@@ -25,21 +25,117 @@
#include "lldb/DataFormatters/TypeFormat.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Symbol/ClangASTType.h"
+#include "lldb/Symbol/TypeList.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
using namespace lldb;
using namespace lldb_private;
-TypeFormatImpl::TypeFormatImpl (lldb::Format f,
- const Flags& flags) :
+TypeFormatImpl::TypeFormatImpl (const Flags& flags) :
m_flags(flags),
+m_my_revision(0)
+{
+}
+
+
+TypeFormatImpl_Format::TypeFormatImpl_Format (lldb::Format f,
+ const TypeFormatImpl::Flags& flags) :
+TypeFormatImpl(flags),
m_format (f)
{
}
+bool
+TypeFormatImpl_Format::FormatObject (ValueObject *valobj,
+ std::string& dest) const
+{
+ if (!valobj)
+ return false;
+ if (valobj->GetClangType().IsAggregateType () == false)
+ {
+ const Value& value(valobj->GetValue());
+ const Value::ContextType context_type = value.GetContextType();
+ ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
+ DataExtractor data;
+
+ if (context_type == Value::eContextTypeRegisterInfo)
+ {
+ const RegisterInfo *reg_info = value.GetRegisterInfo();
+ if (reg_info)
+ {
+ valobj->GetData(data);
+
+ StreamString reg_sstr;
+ data.Dump (&reg_sstr,
+ 0,
+ GetFormat(),
+ reg_info->byte_size,
+ 1,
+ UINT32_MAX,
+ LLDB_INVALID_ADDRESS,
+ 0,
+ 0,
+ exe_ctx.GetBestExecutionContextScope());
+ dest.swap(reg_sstr.GetString());
+ }
+ }
+ else
+ {
+ ClangASTType clang_type = valobj->GetClangType ();
+ if (clang_type)
+ {
+ // put custom bytes to display in the DataExtractor to override the default value logic
+ if (GetFormat() == eFormatCString)
+ {
+ lldb_private::Flags type_flags(clang_type.GetTypeInfo(NULL)); // disambiguate w.r.t. TypeFormatImpl::Flags
+ if (type_flags.Test(ClangASTType::eTypeIsPointer) && !type_flags.Test(ClangASTType::eTypeIsObjC))
+ {
+ // if we are dumping a pointer as a c-string, get the pointee data as a string
+ TargetSP target_sp(valobj->GetTargetSP());
+ if (target_sp)
+ {
+ size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
+ Error error;
+ DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0));
+ Address address(valobj->GetPointerValue());
+ if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success())
+ data.SetData(buffer_sp);
+ }
+ }
+ }
+ else
+ valobj->GetData(data);
+
+ StreamString sstr;
+ clang_type.DumpTypeValue (&sstr, // The stream to use for display
+ GetFormat(), // Format to display this type with
+ data, // Data to extract from
+ 0, // Byte offset into "m_data"
+ valobj->GetByteSize(), // Byte size of item in "m_data"
+ valobj->GetBitfieldBitSize(), // Bitfield bit size
+ valobj->GetBitfieldBitOffset(), // Bitfield bit offset
+ exe_ctx.GetBestExecutionContextScope());
+ // Given that we do not want to set the ValueObject's m_error
+ // for a formatting error (or else we wouldn't be able to reformat
+ // until a next update), an empty string is treated as a "false"
+ // return from here, but that's about as severe as we get
+ // ClangASTType::DumpTypeValue() should always return
+ // something, even if that something is an error message
+ if (sstr.GetString().empty())
+ dest.clear();
+ else
+ dest.swap(sstr.GetString());
+ }
+ }
+ return !dest.empty();
+ }
+ else
+ return false;
+}
+
std::string
-TypeFormatImpl::GetDescription()
+TypeFormatImpl_Format::GetDescription()
{
StreamString sstr;
sstr.Printf ("%s%s%s%s",
@@ -50,3 +146,87 @@ TypeFormatImpl::GetDescription()
return sstr.GetString();
}
+TypeFormatImpl_EnumType::TypeFormatImpl_EnumType (ConstString type_name,
+ const TypeFormatImpl::Flags& flags) :
+TypeFormatImpl(flags),
+m_enum_type(type_name),
+m_types()
+{
+}
+
+bool
+TypeFormatImpl_EnumType::FormatObject (ValueObject *valobj,
+ std::string& dest) const
+{
+ dest.clear();
+ if (!valobj)
+ return false;
+ if (valobj->GetClangType().IsAggregateType ())
+ return false;
+ ProcessSP process_sp;
+ TargetSP target_sp;
+ void* valobj_key = (process_sp = valobj->GetProcessSP()).get();
+ if (!valobj_key)
+ valobj_key = (target_sp = valobj->GetTargetSP()).get();
+ else
+ target_sp = process_sp->GetTarget().shared_from_this();
+ if (!valobj_key)
+ return false;
+ auto iter = m_types.find(valobj_key),
+ end = m_types.end();
+ ClangASTType valobj_enum_type;
+ if (iter == end)
+ {
+ // probably a redundant check
+ if (!target_sp)
+ return false;
+ const ModuleList& images(target_sp->GetImages());
+ SymbolContext sc;
+ TypeList types;
+ images.FindTypes(sc, m_enum_type, false, UINT32_MAX, types);
+ if (types.GetSize() == 0)
+ return false;
+ for (lldb::TypeSP type_sp : types.Types())
+ {
+ if (!type_sp)
+ continue;
+ if ( (type_sp->GetClangForwardType().GetTypeInfo() & ClangASTType::eTypeIsEnumeration) == ClangASTType::eTypeIsEnumeration)
+ {
+ valobj_enum_type = type_sp->GetClangFullType();
+ m_types.emplace(valobj_key,valobj_enum_type);
+ break;
+ }
+ }
+ }
+ else
+ valobj_enum_type = iter->second;
+ if (valobj_enum_type.IsValid() == false)
+ return false;
+ DataExtractor data;
+ valobj->GetData(data);
+ ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
+ StreamString sstr;
+ valobj_enum_type.DumpTypeValue(&sstr,
+ lldb::eFormatEnum,
+ data,
+ 0,
+ data.GetByteSize(),
+ 0,
+ 0,
+ exe_ctx.GetBestExecutionContextScope());
+ if (!sstr.GetString().empty())
+ dest.swap(sstr.GetString());
+ return !dest.empty();
+}
+
+std::string
+TypeFormatImpl_EnumType::GetDescription()
+{
+ StreamString sstr;
+ sstr.Printf ("as type %s%s%s%s",
+ m_enum_type.AsCString("<invalid type>"),
+ Cascades() ? "" : " (not cascading)",
+ SkipsPointers() ? " (skip pointers)" : "",
+ SkipsReferences() ? " (skip references)" : "");
+ return sstr.GetString();
+}
diff --git a/source/DataFormatters/ValueObjectPrinter.cpp b/source/DataFormatters/ValueObjectPrinter.cpp
index 5c7f48b600bf..944d6d2d13a9 100644
--- a/source/DataFormatters/ValueObjectPrinter.cpp
+++ b/source/DataFormatters/ValueObjectPrinter.cpp
@@ -403,7 +403,6 @@ ValueObjectPrinter::ShouldPrintChildren (bool is_failed_description,
// Use a new temporary pointer depth in case we override the
// current pointer depth below...
- uint32_t curr_ptr_depth = m_ptr_depth;
if (is_ptr || is_ref)
{
@@ -413,7 +412,7 @@ ValueObjectPrinter::ShouldPrintChildren (bool is_failed_description,
if (m_valobj->GetPointerValue (&ptr_address_type) == 0)
return false;
- else if (is_ref && m_curr_depth == 0)
+ else if (is_ref && m_curr_depth == 0 && curr_ptr_depth == 0)
{
// If this is the root object (depth is zero) that we are showing
// and it is a reference, and no pointer depth has been supplied
@@ -468,7 +467,7 @@ ValueObjectPrinter::PrintChild (ValueObjectSP child_sp,
ValueObjectPrinter child_printer(child_sp.get(),
m_stream,
child_options,
- (IsPtr() || IsRef()) ? curr_ptr_depth - 1 : curr_ptr_depth,
+ (IsPtr() || IsRef()) && curr_ptr_depth >= 1 ? curr_ptr_depth - 1 : curr_ptr_depth,
m_curr_depth + 1);
child_printer.PrintValueObject();
}
diff --git a/source/Expression/ClangASTSource.cpp b/source/Expression/ClangASTSource.cpp
index 316efdf9c149..853d102c5426 100644
--- a/source/Expression/ClangASTSource.cpp
+++ b/source/Expression/ClangASTSource.cpp
@@ -318,6 +318,10 @@ ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl)
m_ast_importer->CompleteObjCInterfaceDecl (interface_decl);
+ if (interface_decl->getSuperClass() &&
+ interface_decl->getSuperClass() != interface_decl)
+ CompleteType(interface_decl->getSuperClass());
+
if (log)
{
log->Printf(" [COID] After:");
@@ -970,6 +974,9 @@ ClangASTSource::FindObjCMethodDecls (NameSearchContext &context)
}
ss.Flush();
+ if (strstr(ss.GetData(), "$__lldb"))
+ return; // we don't need any results
+
ConstString selector_name(ss.GetData());
if (log)
@@ -1771,14 +1778,14 @@ NameSearchContext::AddFunDecl (const ClangASTType &type)
if (func_proto_type)
{
- unsigned NumArgs = func_proto_type->getNumArgs();
+ unsigned NumArgs = func_proto_type->getNumParams();
unsigned ArgIndex;
SmallVector<ParmVarDecl *, 5> parm_var_decls;
for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex)
{
- QualType arg_qual_type (func_proto_type->getArgType(ArgIndex));
+ QualType arg_qual_type (func_proto_type->getParamType(ArgIndex));
parm_var_decls.push_back(ParmVarDecl::Create (*ast,
const_cast<DeclContext*>(m_decl_context),
diff --git a/source/Expression/ClangExpressionDeclMap.cpp b/source/Expression/ClangExpressionDeclMap.cpp
index 87c984ddcfb9..64ef98297cd2 100644
--- a/source/Expression/ClangExpressionDeclMap.cpp
+++ b/source/Expression/ClangExpressionDeclMap.cpp
@@ -1605,6 +1605,8 @@ ClangExpressionDeclMap::AddOneVariable (NameSearchContext &context, VariableSP v
{
if (const TagType *tag_type = dyn_cast<TagType>(parser_type))
CompleteType(tag_type->getDecl());
+ if (const ObjCObjectPointerType *objc_object_ptr_type = dyn_cast<ObjCObjectPointerType>(parser_type))
+ CompleteType(objc_object_ptr_type->getInterfaceDecl());
}
diff --git a/source/Expression/ClangExpressionParser.cpp b/source/Expression/ClangExpressionParser.cpp
index f0de1edc90d3..615f29fd0c76 100644
--- a/source/Expression/ClangExpressionParser.cpp
+++ b/source/Expression/ClangExpressionParser.cpp
@@ -16,6 +16,7 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Disassembler.h"
#include "lldb/Core/Stream.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Expression/ClangASTSource.h"
#include "lldb/Expression/ClangExpression.h"
@@ -35,7 +36,6 @@
#include "clang/Basic/Version.h"
#include "clang/CodeGen/CodeGenAction.h"
#include "clang/CodeGen/ModuleBuilder.h"
-#include "clang/Driver/CC1Options.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendActions.h"
@@ -506,7 +506,7 @@ ClangExpressionParser::PrepareForExecution (lldb::addr_t &func_addr,
Stream *error_stream = NULL;
Target *target = exe_ctx.GetTargetPtr();
if (target)
- error_stream = &target->GetDebugger().GetErrorStream();
+ error_stream = target->GetDebugger().GetErrorFile().get();
IRForTarget ir_for_target(decl_map,
m_expr.NeedsVariableResolution(),
diff --git a/source/Expression/ClangUserExpression.cpp b/source/Expression/ClangUserExpression.cpp
index d9ecd41be97a..6b0eee8cf363 100644
--- a/source/Expression/ClangUserExpression.cpp
+++ b/source/Expression/ClangUserExpression.cpp
@@ -1024,7 +1024,9 @@ ClangUserExpression::Evaluate (ExecutionContext &exe_ctx,
}
if (result_valobj_sp.get() == NULL)
- result_valobj_sp = ValueObjectConstResult::Create (NULL, error);
+ {
+ result_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), error);
+ }
return execution_results;
}
diff --git a/source/Expression/DWARFExpression.cpp b/source/Expression/DWARFExpression.cpp
index b36be8e545d9..28aa6d02a56d 100644
--- a/source/Expression/DWARFExpression.cpp
+++ b/source/Expression/DWARFExpression.cpp
@@ -1429,6 +1429,12 @@ DWARFExpression::Evaluate
//----------------------------------------------------------------------
case DW_OP_deref:
{
+ if (stack.empty())
+ {
+ if (error_ptr)
+ error_ptr->SetErrorString("Expression stack empty for DW_OP_deref.");
+ return false;
+ }
Value::ValueType value_type = stack.back().GetValueType();
switch (value_type)
{
@@ -1504,6 +1510,12 @@ DWARFExpression::Evaluate
//----------------------------------------------------------------------
case DW_OP_deref_size:
{
+ if (stack.empty())
+ {
+ if (error_ptr)
+ error_ptr->SetErrorString("Expression stack empty for DW_OP_deref_size.");
+ return false;
+ }
uint8_t size = opcodes.GetU8(&offset);
Value::ValueType value_type = stack.back().GetValueType();
switch (value_type)
@@ -2562,9 +2574,90 @@ DWARFExpression::Evaluate
// variable a particular DWARF expression refers to.
//----------------------------------------------------------------------
case DW_OP_piece:
- if (error_ptr)
- error_ptr->SetErrorString ("Unimplemented opcode DW_OP_piece.");
- return false;
+ if (stack.size() < 1)
+ {
+ if (error_ptr)
+ error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_piece.");
+ return false;
+ }
+ else
+ {
+ const uint64_t piece_byte_size = opcodes.GetULEB128(&offset);
+ switch (stack.back().GetValueType())
+ {
+ case Value::eValueTypeScalar:
+ case Value::eValueTypeFileAddress:
+ case Value::eValueTypeLoadAddress:
+ case Value::eValueTypeHostAddress:
+ {
+ uint32_t bit_size = piece_byte_size * 8;
+ uint32_t bit_offset = 0;
+ if (!stack.back().GetScalar().ExtractBitfield (bit_size, bit_offset))
+ {
+ if (error_ptr)
+ error_ptr->SetErrorStringWithFormat("unable to extract %" PRIu64 " bytes from a %" PRIu64 " byte scalar value.", piece_byte_size, (uint64_t)stack.back().GetScalar().GetByteSize());
+ return false;
+ }
+ }
+ break;
+
+ case Value::eValueTypeVector:
+ {
+ if (stack.back().GetVector().length >= piece_byte_size)
+ stack.back().GetVector().length = piece_byte_size;
+ else
+ {
+ if (error_ptr)
+ error_ptr->SetErrorStringWithFormat("unable to extract %" PRIu64 " bytes from a %" PRIu64 " byte vector value.", piece_byte_size, (uint64_t)stack.back().GetVector().length);
+ return false;
+ }
+ }
+ break;
+ }
+ }
+ break;
+
+ case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
+ if (stack.size() < 1)
+ {
+ if (error_ptr)
+ error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_bit_piece.");
+ return false;
+ }
+ else
+ {
+ const uint64_t piece_bit_size = opcodes.GetULEB128(&offset);
+ const uint64_t piece_bit_offset = opcodes.GetULEB128(&offset);
+ switch (stack.back().GetValueType())
+ {
+ case Value::eValueTypeScalar:
+ case Value::eValueTypeFileAddress:
+ case Value::eValueTypeLoadAddress:
+ case Value::eValueTypeHostAddress:
+ {
+ if (!stack.back().GetScalar().ExtractBitfield (piece_bit_size, piece_bit_offset))
+ {
+ if (error_ptr)
+ error_ptr->SetErrorStringWithFormat("unable to extract %" PRIu64 " bit value with %" PRIu64 " bit offset from a %" PRIu64 " bit scalar value.",
+ piece_bit_size,
+ piece_bit_offset,
+ (uint64_t)(stack.back().GetScalar().GetByteSize()*8));
+ return false;
+ }
+ }
+ break;
+
+ case Value::eValueTypeVector:
+ if (error_ptr)
+ {
+ error_ptr->SetErrorStringWithFormat ("unable to extract %" PRIu64 " bit value with %" PRIu64 " bit offset from a vector value.",
+ piece_bit_size,
+ piece_bit_offset);
+ }
+ return false;
+ }
+ }
+ break;
//----------------------------------------------------------------------
// OPCODE: DW_OP_push_object_address
diff --git a/source/Expression/IRDynamicChecks.cpp b/source/Expression/IRDynamicChecks.cpp
index 4030f149ab2d..a75a0fca9c62 100644
--- a/source/Expression/IRDynamicChecks.cpp
+++ b/source/Expression/IRDynamicChecks.cpp
@@ -19,6 +19,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
@@ -145,7 +146,8 @@ public:
DynamicCheckerFunctions &checker_functions) :
m_module(module),
m_checker_functions(checker_functions),
- m_i8ptr_ty(NULL)
+ m_i8ptr_ty(NULL),
+ m_intptr_ty(NULL)
{
}
@@ -279,9 +281,6 @@ protected:
//------------------------------------------------------------------
llvm::Value *BuildPointerValidatorFunc(lldb::addr_t start_address)
{
- IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
- (m_module.getPointerSize() == llvm::Module::Pointer64) ? 64 : 32);
-
llvm::Type *param_array[1];
param_array[0] = const_cast<llvm::PointerType*>(GetI8PtrTy());
@@ -290,7 +289,7 @@ protected:
FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true);
PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
- Constant *fun_addr_int = ConstantInt::get(intptr_ty, start_address, false);
+ Constant *fun_addr_int = ConstantInt::get(GetIntptrTy(), start_address, false);
return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
}
@@ -306,9 +305,6 @@ protected:
//------------------------------------------------------------------
llvm::Value *BuildObjectCheckerFunc(lldb::addr_t start_address)
{
- IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
- (m_module.getPointerSize() == llvm::Module::Pointer64) ? 64 : 32);
-
llvm::Type *param_array[2];
param_array[0] = const_cast<llvm::PointerType*>(GetI8PtrTy());
@@ -318,7 +314,7 @@ protected:
FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true);
PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
- Constant *fun_addr_int = ConstantInt::get(intptr_ty, start_address, false);
+ Constant *fun_addr_int = ConstantInt::get(GetIntptrTy(), start_address, false);
return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
}
@@ -330,6 +326,18 @@ protected:
return m_i8ptr_ty;
}
+ IntegerType *GetIntptrTy()
+ {
+ if (!m_intptr_ty)
+ {
+ llvm::DataLayout data_layout(&m_module);
+
+ m_intptr_ty = llvm::Type::getIntNTy(m_module.getContext(), data_layout.getPointerSizeInBits());
+ }
+
+ return m_intptr_ty;
+ }
+
typedef std::vector <llvm::Instruction *> InstVector;
typedef InstVector::iterator InstIterator;
@@ -338,6 +346,7 @@ protected:
DynamicCheckerFunctions &m_checker_functions; ///< The dynamic checker functions for the process
private:
PointerType *m_i8ptr_ty;
+ IntegerType *m_intptr_ty;
};
class ValidPointerChecker : public Instrumenter
diff --git a/source/Expression/IRExecutionUnit.cpp b/source/Expression/IRExecutionUnit.cpp
index 104732a283c2..17bd03ae6cb5 100644
--- a/source/Expression/IRExecutionUnit.cpp
+++ b/source/Expression/IRExecutionUnit.cpp
@@ -75,12 +75,7 @@ IRExecutionUnit::WriteNow (const uint8_t *bytes,
if (err.Success())
{
DataExtractor my_extractor(my_buffer.GetBytes(), my_buffer.GetByteSize(), lldb::eByteOrderBig, 8);
-
- StreamString ss;
-
- my_extractor.Dump(&ss, 0, lldb::eFormatBytesWithASCII, 1, my_buffer.GetByteSize(), 32, allocation_process_addr, 0, 0);
-
- log->PutCString(ss.GetData());
+ my_extractor.PutToLog(log, 0, my_buffer.GetByteSize(), allocation_process_addr, 16, DataExtractor::TypeUInt8);
}
}
@@ -243,6 +238,8 @@ IRExecutionUnit::GetRunnableInfo(Error &error,
{
lldb::ProcessSP process_sp(GetProcessWP().lock());
+ static Mutex s_runnable_info_mutex(Mutex::Type::eMutexTypeRecursive);
+
func_addr = LLDB_INVALID_ADDRESS;
func_end = LLDB_INVALID_ADDRESS;
@@ -261,6 +258,8 @@ IRExecutionUnit::GetRunnableInfo(Error &error,
return;
};
+ Mutex::Locker runnable_info_mutex_locker(s_runnable_info_mutex);
+
m_did_jit = true;
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
@@ -394,6 +393,25 @@ IRExecutionUnit::GetRunnableInfo(Error &error,
{
log->Printf("Function disassembly:\n%s", disassembly_stream.GetData());
}
+
+ log->Printf("Sections: ");
+ for (AllocationRecord &record : m_records)
+ {
+ if (record.m_process_address != LLDB_INVALID_ADDRESS)
+ {
+ record.dump(log);
+
+ DataBufferHeap my_buffer(record.m_size, 0);
+ Error err;
+ ReadMemory(my_buffer.GetBytes(), record.m_process_address, record.m_size, err);
+
+ if (err.Success())
+ {
+ DataExtractor my_extractor(my_buffer.GetBytes(), my_buffer.GetByteSize(), lldb::eByteOrderBig, 8);
+ my_extractor.PutToLog(log, 0, my_buffer.GetByteSize(), record.m_process_address, 16, DataExtractor::TypeUInt8);
+ }
+ }
+ }
}
func_addr = m_function_load_addr;
diff --git a/source/Expression/IRForTarget.cpp b/source/Expression/IRForTarget.cpp
index d68dc002a5a5..a998896a98fd 100644
--- a/source/Expression/IRForTarget.cpp
+++ b/source/Expression/IRForTarget.cpp
@@ -105,6 +105,7 @@ IRForTarget::IRForTarget (lldb_private::ClangExpressionDeclMap *decl_map,
m_data_allocator(execution_unit),
m_CFStringCreateWithBytes(NULL),
m_sel_registerName(NULL),
+ m_intptr_ty(NULL),
m_error_stream(error_stream),
m_result_store(NULL),
m_result_is_pointer(false),
@@ -285,10 +286,8 @@ llvm::Constant *
IRForTarget::BuildFunctionPointer (llvm::Type *type,
uint64_t ptr)
{
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
PointerType *fun_ptr_ty = PointerType::getUnqual(type);
- Constant *fun_addr_int = ConstantInt::get(intptr_ty, ptr, false);
+ Constant *fun_addr_int = ConstantInt::get(m_intptr_ty, ptr, false);
return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
}
@@ -726,9 +725,6 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str,
Type *ns_str_ty = ns_str->getType();
Type *i8_ptr_ty = Type::getInt8PtrTy(m_module->getContext());
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize()
- == Module::Pointer64) ? 64 : 32);
Type *i32_ty = Type::getInt32Ty(m_module->getContext());
Type *i8_ty = Type::getInt8Ty(m_module->getContext());
@@ -775,7 +771,7 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str,
arg_type_array[0] = i8_ptr_ty;
arg_type_array[1] = i8_ptr_ty;
- arg_type_array[2] = intptr_ty;
+ arg_type_array[2] = m_intptr_ty;
arg_type_array[3] = i32_ty;
arg_type_array[4] = i8_ty;
@@ -785,7 +781,7 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str,
// Build the constant containing the pointer to the function
PointerType *CFSCWB_ptr_ty = PointerType::getUnqual(CFSCWB_ty);
- Constant *CFSCWB_addr_int = ConstantInt::get(intptr_ty, CFStringCreateWithBytes_addr, false);
+ Constant *CFSCWB_addr_int = ConstantInt::get(m_intptr_ty, CFStringCreateWithBytes_addr, false);
m_CFStringCreateWithBytes = ConstantExpr::getIntToPtr(CFSCWB_addr_int, CFSCWB_ptr_ty);
}
@@ -796,7 +792,7 @@ IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str,
Constant *alloc_arg = Constant::getNullValue(i8_ptr_ty);
Constant *bytes_arg = cstr ? ConstantExpr::getBitCast(cstr, i8_ptr_ty) : Constant::getNullValue(i8_ptr_ty);
- Constant *numBytes_arg = ConstantInt::get(intptr_ty, cstr ? string_array->getNumElements() - 1 : 0, false);
+ Constant *numBytes_arg = ConstantInt::get(m_intptr_ty, cstr ? string_array->getNumElements() - 1 : 0, false);
Constant *encoding_arg = ConstantInt::get(i32_ty, 0x0600, false); /* 0x0600 is kCFStringEncodingASCII */
Constant *isExternal_arg = ConstantInt::get(i8_ty, 0x0, false); /* 0x0 is false */
@@ -1149,10 +1145,8 @@ IRForTarget::RewriteObjCSelector (Instruction* selector_load)
llvm::Type *srN_type = FunctionType::get(sel_ptr_type, srN_arg_types, false);
// Build the constant containing the pointer to the function
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
PointerType *srN_ptr_ty = PointerType::getUnqual(srN_type);
- Constant *srN_addr_int = ConstantInt::get(intptr_ty, sel_registerName_addr, false);
+ Constant *srN_addr_int = ConstantInt::get(m_intptr_ty, sel_registerName_addr, false);
m_sel_registerName = ConstantExpr::getIntToPtr(srN_addr_int, srN_ptr_ty);
}
@@ -1599,10 +1593,8 @@ IRForTarget::HandleSymbol (Value *symbol)
log->Printf("Found \"%s\" at 0x%" PRIx64, name.GetCString(), symbol_addr);
Type *symbol_type = symbol->getType();
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
- Constant *symbol_addr_int = ConstantInt::get(intptr_ty, symbol_addr, false);
+ Constant *symbol_addr_int = ConstantInt::get(m_intptr_ty, symbol_addr, false);
Value *symbol_addr_ptr = ConstantExpr::getIntToPtr(symbol_addr_int, symbol_type);
@@ -1680,11 +1672,7 @@ IRForTarget::HandleObjCClass(Value *classlist_reference)
if (load_instructions.empty())
return false;
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize()
- == Module::Pointer64) ? 64 : 32);
-
- Constant *class_addr = ConstantInt::get(intptr_ty, (uint64_t)class_ptr);
+ Constant *class_addr = ConstantInt::get(m_intptr_ty, (uint64_t)class_ptr);
for (LoadInst *load_instruction : load_instructions)
{
@@ -2499,10 +2487,7 @@ IRForTarget::ReplaceVariables (Function &llvm_function)
llvm::Constant *
IRForTarget::BuildRelocation(llvm::Type *type, uint64_t offset)
{
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
-
- llvm::Constant *offset_int = ConstantInt::get(intptr_ty, offset);
+ llvm::Constant *offset_int = ConstantInt::get(m_intptr_ty, offset);
llvm::Constant *offset_array[1];
@@ -2537,10 +2522,7 @@ IRForTarget::CompleteDataAllocation ()
if (!allocation || allocation == LLDB_INVALID_ADDRESS)
return false;
- IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
-
- Constant *relocated_addr = ConstantInt::get(intptr_ty, (uint64_t)allocation);
+ Constant *relocated_addr = ConstantInt::get(m_intptr_ty, (uint64_t)allocation);
Constant *relocated_bitcast = ConstantExpr::getIntToPtr(relocated_addr, llvm::Type::getInt8PtrTy(m_module->getContext()));
m_reloc_placeholder->replaceAllUsesWith(relocated_bitcast);
@@ -2607,6 +2589,7 @@ IRForTarget::runOnModule (Module &llvm_module)
m_module = &llvm_module;
m_target_data.reset(new DataLayout(m_module));
+ m_intptr_ty = llvm::Type::getIntNTy(m_module->getContext(), m_target_data->getPointerSizeInBits());
if (log)
{
@@ -2641,13 +2624,13 @@ IRForTarget::runOnModule (Module &llvm_module)
return false;
}
- llvm::Type *intptr_ty = Type::getInt8Ty(m_module->getContext());
+ llvm::Type *int8_ty = Type::getInt8Ty(m_module->getContext());
m_reloc_placeholder = new llvm::GlobalVariable((*m_module),
- intptr_ty,
+ int8_ty,
false /* IsConstant */,
GlobalVariable::InternalLinkage,
- Constant::getNullValue(intptr_ty),
+ Constant::getNullValue(int8_ty),
"reloc_placeholder",
NULL /* InsertBefore */,
GlobalVariable::NotThreadLocal /* ThreadLocal */,
diff --git a/source/Expression/Materializer.cpp b/source/Expression/Materializer.cpp
index 8731fbebd148..90687c0739d9 100644
--- a/source/Expression/Materializer.cpp
+++ b/source/Expression/Materializer.cpp
@@ -461,7 +461,9 @@ public:
}
else
{
- lldb::addr_t addr_of_valobj = valobj_sp->GetAddressOf();
+ AddressType address_type = eAddressTypeInvalid;
+ const bool scalar_is_load_address = false;
+ lldb::addr_t addr_of_valobj = valobj_sp->GetAddressOf(scalar_is_load_address, &address_type);
if (addr_of_valobj != LLDB_INVALID_ADDRESS)
{
Error write_error;
@@ -503,6 +505,9 @@ public:
size_t bit_align = m_variable_sp->GetType()->GetClangLayoutType().GetTypeBitAlign();
size_t byte_align = (bit_align + 7) / 8;
+ if (!byte_align)
+ byte_align = 1;
+
Error alloc_error;
m_temporary_allocation = map.Malloc(data.GetByteSize(), byte_align, lldb::ePermissionsReadable | lldb::ePermissionsWritable, IRMemoryMap::eAllocationPolicyMirror, alloc_error);
@@ -739,6 +744,9 @@ public:
size_t bit_align = m_type.GetTypeBitAlign();
size_t byte_align = (bit_align + 7) / 8;
+ if (!byte_align)
+ byte_align = 1;
+
Error alloc_error;
m_temporary_allocation = map.Malloc(byte_size, byte_align, lldb::ePermissionsReadable | lldb::ePermissionsWritable, IRMemoryMap::eAllocationPolicyMirror, alloc_error);
diff --git a/source/Host/common/Editline.cpp b/source/Host/common/Editline.cpp
new file mode 100644
index 000000000000..679aadd54c4f
--- /dev/null
+++ b/source/Host/common/Editline.cpp
@@ -0,0 +1,696 @@
+//===-- Editline.cpp --------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "lldb/Host/Editline.h"
+
+#include "lldb/Core/Error.h"
+#include "lldb/Core/StreamString.h"
+#include "lldb/Core/StringList.h"
+#include "lldb/Host/Host.h"
+
+#include <limits.h>
+
+using namespace lldb;
+using namespace lldb_private;
+
+static const char k_prompt_escape_char = '\1';
+
+Editline::Editline (const char *prog, // prog can't be NULL
+ const char *prompt, // can be NULL for no prompt
+ FILE *fin,
+ FILE *fout,
+ FILE *ferr) :
+ m_editline (NULL),
+ m_history (NULL),
+ m_history_event (),
+ m_program (),
+ m_prompt (),
+ m_lines_prompt (),
+ m_getc_buffer (),
+ m_getc_mutex (Mutex::eMutexTypeNormal),
+ m_getc_cond (),
+// m_gets_mutex (Mutex::eMutexTypeNormal),
+ m_completion_callback (NULL),
+ m_completion_callback_baton (NULL),
+ m_line_complete_callback (NULL),
+ m_line_complete_callback_baton (NULL),
+ m_lines_command (Command::None),
+ m_lines_curr_line (0),
+ m_lines_max_line (0),
+ m_prompt_with_line_numbers (false),
+ m_getting_line (false),
+ m_got_eof (false),
+ m_interrupted (false)
+{
+ if (prog && prog[0])
+ {
+ m_program = prog;
+ m_editline = ::el_init(prog, fin, fout, ferr);
+ m_history = ::history_init();
+ }
+ else
+ {
+ m_editline = ::el_init("lldb-tmp", fin, fout, ferr);
+ }
+ if (prompt && prompt[0])
+ SetPrompt (prompt);
+
+ //::el_set (m_editline, EL_BIND, "^[[A", NULL); // Print binding for up arrow key
+ //::el_set (m_editline, EL_BIND, "^[[B", NULL); // Print binding for up down key
+
+ assert (m_editline);
+ ::el_set (m_editline, EL_CLIENTDATA, this);
+
+ // only defined for newer versions of editline
+#ifdef EL_PROMPT_ESC
+ ::el_set (m_editline, EL_PROMPT_ESC, GetPromptCallback, k_prompt_escape_char);
+#else
+ // fall back on old prompt setting code
+ ::el_set (m_editline, EL_PROMPT, GetPromptCallback);
+#endif
+ ::el_set (m_editline, EL_EDITOR, "emacs");
+ if (m_history)
+ {
+ ::el_set (m_editline, EL_HIST, history, m_history);
+ }
+ ::el_set (m_editline, EL_ADDFN, "lldb-complete", "Editline completion function", Editline::CallbackComplete);
+ ::el_set (m_editline, EL_ADDFN, "lldb-edit-prev-line", "Editline edit prev line", Editline::CallbackEditPrevLine);
+ ::el_set (m_editline, EL_ADDFN, "lldb-edit-next-line", "Editline edit next line", Editline::CallbackEditNextLine);
+
+ ::el_set (m_editline, EL_BIND, "^r", "em-inc-search-prev", NULL); // Cycle through backwards search, entering string
+ ::el_set (m_editline, EL_BIND, "^w", "ed-delete-prev-word", NULL); // Delete previous word, behave like bash does.
+ ::el_set (m_editline, EL_BIND, "\033[3~", "ed-delete-next-char", NULL); // Fix the delete key.
+ ::el_set (m_editline, EL_BIND, "\t", "lldb-complete", NULL); // Bind TAB to be autocompelte
+
+ // Source $PWD/.editrc then $HOME/.editrc
+ ::el_source (m_editline, NULL);
+
+ if (m_history)
+ {
+ ::history (m_history, &m_history_event, H_SETSIZE, 800);
+ ::history (m_history, &m_history_event, H_SETUNIQUE, 1);
+ }
+
+ // Always read through our callback function so we don't read
+ // stuff we aren't supposed to. This also stops the extra echoing
+ // that can happen when you have more input than editline can handle
+ // at once.
+ SetGetCharCallback(GetCharFromInputFileCallback);
+
+ LoadHistory();
+}
+
+Editline::~Editline()
+{
+ SaveHistory();
+
+ if (m_history)
+ {
+ ::history_end (m_history);
+ m_history = NULL;
+ }
+
+ // Disable edit mode to stop the terminal from flushing all input
+ // during the call to el_end() since we expect to have multiple editline
+ // instances in this program.
+ ::el_set (m_editline, EL_EDITMODE, 0);
+
+ ::el_end(m_editline);
+ m_editline = NULL;
+}
+
+void
+Editline::SetGetCharCallback (GetCharCallbackType callback)
+{
+ ::el_set (m_editline, EL_GETCFN, callback);
+}
+
+FileSpec
+Editline::GetHistoryFile()
+{
+ char history_path[PATH_MAX];
+ ::snprintf (history_path, sizeof(history_path), "~/.%s-history", m_program.c_str());
+ return FileSpec(history_path, true);
+}
+
+bool
+Editline::LoadHistory ()
+{
+ if (m_history)
+ {
+ FileSpec history_file(GetHistoryFile());
+ if (history_file.Exists())
+ ::history (m_history, &m_history_event, H_LOAD, history_file.GetPath().c_str());
+ return true;
+ }
+ return false;
+}
+
+bool
+Editline::SaveHistory ()
+{
+ if (m_history)
+ {
+ std::string history_path = GetHistoryFile().GetPath();
+ ::history (m_history, &m_history_event, H_SAVE, history_path.c_str());
+ return true;
+ }
+ return false;
+}
+
+
+Error
+Editline::PrivateGetLine(std::string &line)
+{
+ Error error;
+ if (m_interrupted)
+ {
+ error.SetErrorString("interrupted");
+ return error;
+ }
+
+ line.clear();
+ if (m_editline != NULL)
+ {
+ int line_len = 0;
+ const char *line_cstr = NULL;
+ // Call el_gets to prompt the user and read the user's input.
+// {
+// // Make sure we know when we are in el_gets() by using a mutex
+// Mutex::Locker locker (m_gets_mutex);
+ line_cstr = ::el_gets (m_editline, &line_len);
+// }
+
+ static int save_errno = (line_len < 0) ? errno : 0;
+
+ if (save_errno != 0)
+ {
+ error.SetError(save_errno, eErrorTypePOSIX);
+ }
+ else if (line_cstr)
+ {
+ // Decrement the length so we don't have newline characters in "line" for when
+ // we assign the cstr into the std::string
+ while (line_len > 0 &&
+ (line_cstr[line_len - 1] == '\n' ||
+ line_cstr[line_len - 1] == '\r'))
+ --line_len;
+
+ if (line_len > 0)
+ {
+ // We didn't strip the newlines, we just adjusted the length, and
+ // we want to add the history item with the newlines
+ if (m_history)
+ ::history (m_history, &m_history_event, H_ENTER, line_cstr);
+
+ // Copy the part of the c string that we want (removing the newline chars)
+ line.assign(line_cstr, line_len);
+ }
+ }
+ }
+ else
+ {
+ error.SetErrorString("the EditLine instance has been deleted");
+ }
+ return error;
+}
+
+
+Error
+Editline::GetLine(std::string &line)
+{
+ Error error;
+ line.clear();
+
+ // Set arrow key bindings for up and down arrows for single line
+ // mode where up and down arrows do prev/next history
+ ::el_set (m_editline, EL_BIND, "^[[A", "ed-prev-history", NULL); // Map up arrow
+ ::el_set (m_editline, EL_BIND, "^[[B", "ed-next-history", NULL); // Map down arrow
+ m_interrupted = false;
+
+ if (!m_got_eof)
+ {
+ if (m_getting_line)
+ {
+ error.SetErrorString("already getting a line");
+ return error;
+ }
+ if (m_lines_curr_line > 0)
+ {
+ error.SetErrorString("already getting lines");
+ return error;
+ }
+ m_getting_line = true;
+ error = PrivateGetLine(line);
+ m_getting_line = false;
+ }
+
+ if (m_got_eof && line.empty())
+ {
+ // Only set the error if we didn't get an error back from PrivateGetLine()
+ if (error.Success())
+ error.SetErrorString("end of file");
+ }
+
+ return error;
+}
+
+size_t
+Editline::Push (const char *bytes, size_t len)
+{
+ if (m_editline)
+ {
+ // Must NULL terminate the string for el_push() so we stick it
+ // into a std::string first
+ ::el_push(m_editline,
+ const_cast<char*>(std::string (bytes, len).c_str()));
+ return len;
+ }
+ return 0;
+}
+
+
+Error
+Editline::GetLines(const std::string &end_line, StringList &lines)
+{
+ Error error;
+ if (m_getting_line)
+ {
+ error.SetErrorString("already getting a line");
+ return error;
+ }
+ if (m_lines_curr_line > 0)
+ {
+ error.SetErrorString("already getting lines");
+ return error;
+ }
+
+ // Set arrow key bindings for up and down arrows for multiple line
+ // mode where up and down arrows do edit prev/next line
+ ::el_set (m_editline, EL_BIND, "^[[A", "lldb-edit-prev-line", NULL); // Map up arrow
+ ::el_set (m_editline, EL_BIND, "^[[B", "lldb-edit-next-line", NULL); // Map down arrow
+ ::el_set (m_editline, EL_BIND, "^b", "ed-prev-history", NULL);
+ ::el_set (m_editline, EL_BIND, "^n", "ed-next-history", NULL);
+ m_interrupted = false;
+
+ LineStatus line_status = LineStatus::Success;
+
+ lines.Clear();
+
+ FILE *out_file = GetOutputFile();
+ FILE *err_file = GetErrorFile();
+ m_lines_curr_line = 1;
+ while (line_status != LineStatus::Done)
+ {
+ const uint32_t line_idx = m_lines_curr_line-1;
+ if (line_idx >= lines.GetSize())
+ lines.SetSize(m_lines_curr_line);
+ m_lines_max_line = lines.GetSize();
+ m_lines_command = Command::None;
+ assert(line_idx < m_lines_max_line);
+ std::string &line = lines[line_idx];
+ error = PrivateGetLine(line);
+ if (error.Fail())
+ {
+ line_status = LineStatus::Error;
+ }
+ else
+ {
+ switch (m_lines_command)
+ {
+ case Command::None:
+ if (m_line_complete_callback)
+ {
+ line_status = m_line_complete_callback (this,
+ lines,
+ line_idx,
+ error,
+ m_line_complete_callback_baton);
+ }
+ else if (line == end_line)
+ {
+ line_status = LineStatus::Done;
+ }
+
+ if (line_status == LineStatus::Success)
+ {
+ ++m_lines_curr_line;
+ // If we already have content for the next line because
+ // we were editing previous lines, then populate the line
+ // with the appropriate contents
+ if (line_idx+1 < lines.GetSize() && !lines[line_idx+1].empty())
+ ::el_push (m_editline,
+ const_cast<char*>(lines[line_idx+1].c_str()));
+ }
+ else if (line_status == LineStatus::Error)
+ {
+ // Clear to end of line ("ESC[K"), then print the error,
+ // then go to the next line ("\n") and then move cursor up
+ // two lines ("ESC[2A").
+ fprintf (err_file, "\033[Kerror: %s\n\033[2A", error.AsCString());
+ }
+ break;
+ case Command::EditPrevLine:
+ if (m_lines_curr_line > 1)
+ {
+ //::fprintf (out_file, "\033[1A\033[%uD\033[2K", (uint32_t)(m_lines_prompt.size() + lines[line_idx].size())); // Make cursor go up a line and clear that line
+ ::fprintf (out_file, "\033[1A\033[1000D\033[2K");
+ if (!lines[line_idx-1].empty())
+ ::el_push (m_editline,
+ const_cast<char*>(lines[line_idx-1].c_str()));
+ --m_lines_curr_line;
+ }
+ break;
+ case Command::EditNextLine:
+ // Allow the down arrow to create a new line
+ ++m_lines_curr_line;
+ //::fprintf (out_file, "\033[1B\033[%uD\033[2K", (uint32_t)(m_lines_prompt.size() + lines[line_idx].size()));
+ ::fprintf (out_file, "\033[1B\033[1000D\033[2K");
+ if (line_idx+1 < lines.GetSize() && !lines[line_idx+1].empty())
+ ::el_push (m_editline,
+ const_cast<char*>(lines[line_idx+1].c_str()));
+ break;
+ }
+ }
+ }
+ m_lines_curr_line = 0;
+ m_lines_command = Command::None;
+
+ // If we have a callback, call it one more time to let the
+ // user know the lines are complete
+ if (m_line_complete_callback)
+ m_line_complete_callback (this,
+ lines,
+ UINT32_MAX,
+ error,
+ m_line_complete_callback_baton);
+
+ return error;
+}
+
+unsigned char
+Editline::HandleCompletion (int ch)
+{
+ if (m_completion_callback == NULL)
+ return CC_ERROR;
+
+ const LineInfo *line_info = ::el_line(m_editline);
+ StringList completions;
+ int page_size = 40;
+
+ const int num_completions = m_completion_callback (line_info->buffer,
+ line_info->cursor,
+ line_info->lastchar,
+ 0, // Don't skip any matches (start at match zero)
+ -1, // Get all the matches
+ completions,
+ m_completion_callback_baton);
+
+ FILE *out_file = GetOutputFile();
+
+// if (num_completions == -1)
+// {
+// ::el_insertstr (m_editline, m_completion_key);
+// return CC_REDISPLAY;
+// }
+// else
+ if (num_completions == -2)
+ {
+ // Replace the entire line with the first string...
+ ::el_deletestr (m_editline, line_info->cursor - line_info->buffer);
+ ::el_insertstr (m_editline, completions.GetStringAtIndex(0));
+ return CC_REDISPLAY;
+ }
+
+ // If we get a longer match display that first.
+ const char *completion_str = completions.GetStringAtIndex(0);
+ if (completion_str != NULL && *completion_str != '\0')
+ {
+ el_insertstr (m_editline, completion_str);
+ return CC_REDISPLAY;
+ }
+
+ if (num_completions > 1)
+ {
+ int num_elements = num_completions + 1;
+ ::fprintf (out_file, "\nAvailable completions:");
+ if (num_completions < page_size)
+ {
+ for (int i = 1; i < num_elements; i++)
+ {
+ completion_str = completions.GetStringAtIndex(i);
+ ::fprintf (out_file, "\n\t%s", completion_str);
+ }
+ ::fprintf (out_file, "\n");
+ }
+ else
+ {
+ int cur_pos = 1;
+ char reply;
+ int got_char;
+ while (cur_pos < num_elements)
+ {
+ int endpoint = cur_pos + page_size;
+ if (endpoint > num_elements)
+ endpoint = num_elements;
+ for (; cur_pos < endpoint; cur_pos++)
+ {
+ completion_str = completions.GetStringAtIndex(cur_pos);
+ ::fprintf (out_file, "\n\t%s", completion_str);
+ }
+
+ if (cur_pos >= num_elements)
+ {
+ ::fprintf (out_file, "\n");
+ break;
+ }
+
+ ::fprintf (out_file, "\nMore (Y/n/a): ");
+ reply = 'n';
+ got_char = el_getc(m_editline, &reply);
+ if (got_char == -1 || reply == 'n')
+ break;
+ if (reply == 'a')
+ page_size = num_elements - cur_pos;
+ }
+ }
+
+ }
+
+ if (num_completions == 0)
+ return CC_REFRESH_BEEP;
+ else
+ return CC_REDISPLAY;
+}
+
+Editline *
+Editline::GetClientData (::EditLine *e)
+{
+ Editline *editline = NULL;
+ if (e && ::el_get(e, EL_CLIENTDATA, &editline) == 0)
+ return editline;
+ return NULL;
+}
+
+FILE *
+Editline::GetInputFile ()
+{
+ return GetFilePointer (m_editline, 0);
+}
+
+FILE *
+Editline::GetOutputFile ()
+{
+ return GetFilePointer (m_editline, 1);
+}
+
+FILE *
+Editline::GetErrorFile ()
+{
+ return GetFilePointer (m_editline, 2);
+}
+
+const char *
+Editline::GetPrompt()
+{
+ if (m_prompt_with_line_numbers && m_lines_curr_line > 0)
+ {
+ StreamString strm;
+ strm.Printf("%3u: ", m_lines_curr_line);
+ m_lines_prompt = std::move(strm.GetString());
+ return m_lines_prompt.c_str();
+ }
+ else
+ {
+ return m_prompt.c_str();
+ }
+}
+
+void
+Editline::SetPrompt (const char *p)
+{
+ if (p && p[0])
+ m_prompt = p;
+ else
+ m_prompt.clear();
+ size_t start_pos = 0;
+ size_t escape_pos;
+ while ((escape_pos = m_prompt.find('\033', start_pos)) != std::string::npos)
+ {
+ m_prompt.insert(escape_pos, 1, k_prompt_escape_char);
+ start_pos += 2;
+ }
+}
+
+FILE *
+Editline::GetFilePointer (::EditLine *e, int fd)
+{
+ FILE *file_ptr = NULL;
+ if (e && ::el_get(e, EL_GETFP, fd, &file_ptr) == 0)
+ return file_ptr;
+ return NULL;
+}
+
+unsigned char
+Editline::CallbackEditPrevLine (::EditLine *e, int ch)
+{
+ Editline *editline = GetClientData (e);
+ if (editline->m_lines_curr_line > 1)
+ {
+ editline->m_lines_command = Command::EditPrevLine;
+ return CC_NEWLINE;
+ }
+ return CC_ERROR;
+}
+unsigned char
+Editline::CallbackEditNextLine (::EditLine *e, int ch)
+{
+ Editline *editline = GetClientData (e);
+ if (editline->m_lines_curr_line < editline->m_lines_max_line)
+ {
+ editline->m_lines_command = Command::EditNextLine;
+ return CC_NEWLINE;
+ }
+ return CC_ERROR;
+}
+
+unsigned char
+Editline::CallbackComplete (::EditLine *e, int ch)
+{
+ Editline *editline = GetClientData (e);
+ if (editline)
+ return editline->HandleCompletion (ch);
+ return CC_ERROR;
+}
+
+const char *
+Editline::GetPromptCallback (::EditLine *e)
+{
+ Editline *editline = GetClientData (e);
+ if (editline)
+ return editline->GetPrompt();
+ return "";
+}
+
+size_t
+Editline::SetInputBuffer (const char *c, size_t len)
+{
+ if (c && len > 0)
+ {
+ Mutex::Locker locker(m_getc_mutex);
+ SetGetCharCallback(GetCharInputBufferCallback);
+ m_getc_buffer.append(c, len);
+ m_getc_cond.Broadcast();
+ }
+ return len;
+}
+
+int
+Editline::GetChar (char *c)
+{
+ Mutex::Locker locker(m_getc_mutex);
+ if (m_getc_buffer.empty())
+ m_getc_cond.Wait(m_getc_mutex);
+ if (m_getc_buffer.empty())
+ return 0;
+ *c = m_getc_buffer[0];
+ m_getc_buffer.erase(0,1);
+ return 1;
+}
+
+int
+Editline::GetCharInputBufferCallback (EditLine *e, char *c)
+{
+ Editline *editline = GetClientData (e);
+ if (editline)
+ return editline->GetChar(c);
+ return 0;
+}
+
+int
+Editline::GetCharFromInputFileCallback (EditLine *e, char *c)
+{
+ Editline *editline = GetClientData (e);
+ if (editline && editline->m_got_eof == false)
+ {
+ char ch = ::fgetc(editline->GetInputFile());
+ if (ch == '\x04')
+ {
+ // Only turn a CTRL+D into a EOF if we receive the
+ // CTRL+D an empty line, otherwise it will forward
+ // delete the character at the cursor
+ const LineInfo *line_info = ::el_line(e);
+ if (line_info != NULL &&
+ line_info->buffer == line_info->cursor &&
+ line_info->cursor == line_info->lastchar)
+ {
+ ch = EOF;
+ }
+ }
+
+ if (ch == EOF)
+ {
+ editline->m_got_eof = true;
+ }
+ else
+ {
+ *c = ch;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void
+Editline::Hide ()
+{
+ FILE *out_file = GetOutputFile();
+ if (out_file)
+ {
+ const LineInfo *line_info = ::el_line(m_editline);
+ if (line_info)
+ ::fprintf (out_file, "\033[%uD\033[K", (uint32_t)(strlen(GetPrompt()) + line_info->cursor - line_info->buffer));
+ }
+}
+
+
+void
+Editline::Refresh()
+{
+ ::el_set (m_editline, EL_REFRESH);
+}
+
+void
+Editline::Interrupt ()
+{
+ m_interrupted = true;
+ if (m_getting_line || m_lines_curr_line > 0)
+ el_insertstr(m_editline, "\n"); // True to force the line to complete itself so we get exit from el_gets()
+}
diff --git a/source/Host/common/File.cpp b/source/Host/common/File.cpp
index bbd11858aaba..bb0ee39fbc7b 100644
--- a/source/Host/common/File.cpp
+++ b/source/Host/common/File.cpp
@@ -13,10 +13,13 @@
#include <fcntl.h>
#include <limits.h>
#include <stdarg.h>
+#include <stdio.h>
#include <sys/stat.h>
#ifdef _WIN32
#include "lldb/Host/windows/windows.h"
+#else
+#include <sys/ioctl.h>
#endif
#include "lldb/Core/DataBufferHeap.h"
@@ -76,8 +79,11 @@ FILE * File::kInvalidStream = NULL;
File::File(const char *path, uint32_t options, uint32_t permissions) :
m_descriptor (kInvalidDescriptor),
m_stream (kInvalidStream),
- m_options (0),
- m_owned (false)
+ m_options (),
+ m_own_stream (false),
+ m_own_descriptor (false),
+ m_is_interactive (eLazyBoolCalculate),
+ m_is_real_terminal (eLazyBoolCalculate)
{
Open (path, options, permissions);
}
@@ -88,7 +94,11 @@ File::File (const FileSpec& filespec,
m_descriptor (kInvalidDescriptor),
m_stream (kInvalidStream),
m_options (0),
- m_owned (false)
+ m_own_stream (false),
+ m_own_descriptor (false),
+ m_is_interactive (eLazyBoolCalculate),
+ m_is_real_terminal (eLazyBoolCalculate)
+
{
if (filespec)
{
@@ -100,7 +110,10 @@ File::File (const File &rhs) :
m_descriptor (kInvalidDescriptor),
m_stream (kInvalidStream),
m_options (0),
- m_owned (false)
+ m_own_stream (false),
+ m_own_descriptor (false),
+ m_is_interactive (eLazyBoolCalculate),
+ m_is_real_terminal (eLazyBoolCalculate)
{
Duplicate (rhs);
}
@@ -141,7 +154,7 @@ File::SetDescriptor (int fd, bool transfer_ownership)
if (IsValid())
Close();
m_descriptor = fd;
- m_owned = transfer_ownership;
+ m_own_descriptor = transfer_ownership;
}
@@ -155,10 +168,31 @@ File::GetStream ()
const char *mode = GetStreamOpenModeFromOptions (m_options);
if (mode)
{
+ if (!m_own_descriptor)
+ {
+ // We must duplicate the file descriptor if we don't own it because
+ // when you call fdopen, the stream will own the fd
+#ifdef _WIN32
+ m_descriptor = ::_dup(GetDescriptor());
+#else
+ m_descriptor = ::fcntl(GetDescriptor(), F_DUPFD);
+#endif
+ m_own_descriptor = true;
+ }
+
do
{
m_stream = ::fdopen (m_descriptor, mode);
} while (m_stream == NULL && errno == EINTR);
+
+ // If we got a stream, then we own the stream and should no
+ // longer own the descriptor because fclose() will close it for us
+
+ if (m_stream)
+ {
+ m_own_stream = true;
+ m_own_descriptor = false;
+ }
}
}
}
@@ -172,7 +206,7 @@ File::SetStream (FILE *fh, bool transfer_ownership)
if (IsValid())
Close();
m_stream = fh;
- m_owned = transfer_ownership;
+ m_own_stream = transfer_ownership;
}
Error
@@ -194,7 +228,7 @@ File::Duplicate (const File &rhs)
else
{
m_options = rhs.m_options;
- m_owned = true;
+ m_own_descriptor = true;
}
}
else
@@ -272,7 +306,10 @@ File::Open (const char *path, uint32_t options, uint32_t permissions)
if (!DescriptorIsValid())
error.SetErrorToErrno();
else
- m_owned = true;
+ {
+ m_own_descriptor = true;
+ m_options = options;
+ }
return error;
}
@@ -328,27 +365,24 @@ Error
File::Close ()
{
Error error;
- if (IsValid ())
+ if (StreamIsValid() && m_own_stream)
{
- if (m_owned)
- {
- if (StreamIsValid())
- {
- if (::fclose (m_stream) == EOF)
- error.SetErrorToErrno();
- }
-
- if (DescriptorIsValid())
- {
- if (::close (m_descriptor) != 0)
- error.SetErrorToErrno();
- }
- }
- m_descriptor = kInvalidDescriptor;
- m_stream = kInvalidStream;
- m_options = 0;
- m_owned = false;
+ if (::fclose (m_stream) == EOF)
+ error.SetErrorToErrno();
}
+
+ if (DescriptorIsValid() && m_own_descriptor)
+ {
+ if (::close (m_descriptor) != 0)
+ error.SetErrorToErrno();
+ }
+ m_descriptor = kInvalidDescriptor;
+ m_stream = kInvalidStream;
+ m_options = 0;
+ m_own_stream = false;
+ m_own_descriptor = false;
+ m_is_interactive = eLazyBoolCalculate;
+ m_is_real_terminal = eLazyBoolCalculate;
return error;
}
@@ -844,3 +878,43 @@ File::ConvertOpenOptionsForPOSIXOpen (uint32_t open_options)
return mode;
}
+
+void
+File::CalculateInteractiveAndTerminal ()
+{
+ const int fd = GetDescriptor();
+ if (fd >= 0)
+ {
+ m_is_interactive = eLazyBoolNo;
+ m_is_real_terminal = eLazyBoolNo;
+#ifndef _MSC_VER
+ if (isatty(fd))
+ {
+ m_is_interactive = eLazyBoolYes;
+ struct winsize window_size;
+ if (::ioctl (fd, TIOCGWINSZ, &window_size) == 0)
+ {
+ if (window_size.ws_col > 0)
+ m_is_real_terminal = eLazyBoolYes;
+ }
+ }
+#endif
+ }
+}
+
+bool
+File::GetIsInteractive ()
+{
+ if (m_is_interactive == eLazyBoolCalculate)
+ CalculateInteractiveAndTerminal ();
+ return m_is_interactive == eLazyBoolYes;
+}
+
+bool
+File::GetIsRealTerminal ()
+{
+ if (m_is_real_terminal == eLazyBoolCalculate)
+ CalculateInteractiveAndTerminal();
+ return m_is_real_terminal == eLazyBoolYes;
+}
+
diff --git a/source/Host/common/Host.cpp b/source/Host/common/Host.cpp
index 262776f6c719..9e5e4cbdb04a 100644
--- a/source/Host/common/Host.cpp
+++ b/source/Host/common/Host.cpp
@@ -18,6 +18,7 @@
#include <winsock2.h>
#include <WS2tcpip.h>
#else
+#include <unistd.h>
#include <dlfcn.h>
#include <grp.h>
#include <netdb.h>
@@ -37,7 +38,7 @@
#include <AvailabilityMacros.h>
#endif
-#if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
+#if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
#include <spawn.h>
#include <sys/wait.h>
#include <sys/syscall.h>
@@ -68,6 +69,18 @@
#include "llvm/Support/Host.h"
#include "llvm/Support/raw_ostream.h"
+#if defined (__APPLE__)
+#ifndef _POSIX_SPAWN_DISABLE_ASLR
+#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
+#endif
+
+extern "C"
+{
+ int __pthread_chdir(const char *path);
+ int __pthread_fchdir (int fildes);
+}
+
+#endif
using namespace lldb;
using namespace lldb_private;
@@ -367,25 +380,31 @@ Host::GetArchitecture (SystemDefaultArchitecture arch_kind)
// If the OS is Linux, "unknown" in the vendor slot isn't what we want
// for the default triple. It's probably an artifact of config.guess.
if (triple.getOS() == llvm::Triple::Linux && triple.getVendor() == llvm::Triple::UnknownVendor)
- triple.setVendorName("");
+ triple.setVendorName ("");
+
+ const char* distribution_id = GetDistributionId ().AsCString();
switch (triple.getArch())
{
default:
g_host_arch_32.SetTriple(triple);
+ g_host_arch_32.SetDistributionId (distribution_id);
g_supports_32 = true;
break;
case llvm::Triple::x86_64:
g_host_arch_64.SetTriple(triple);
+ g_host_arch_64.SetDistributionId (distribution_id);
g_supports_64 = true;
g_host_arch_32.SetTriple(triple.get32BitArchVariant());
+ g_host_arch_32.SetDistributionId (distribution_id);
g_supports_32 = true;
break;
case llvm::Triple::sparcv9:
case llvm::Triple::ppc64:
g_host_arch_64.SetTriple(triple);
+ g_host_arch_64.SetDistributionId (distribution_id);
g_supports_64 = true;
break;
}
@@ -445,6 +464,19 @@ Host::GetTargetTriple()
return g_host_triple;
}
+// See linux/Host.cpp for Linux-based implementations of this.
+// Add your platform-specific implementation to the appropriate host file.
+#if !defined(__linux__)
+
+const ConstString &
+ Host::GetDistributionId ()
+{
+ static ConstString s_distribution_id;
+ return s_distribution_id;
+}
+
+#endif // #if !defined(__linux__)
+
lldb::pid_t
Host::GetCurrentProcessID()
{
@@ -457,7 +489,7 @@ lldb::tid_t
Host::GetCurrentThreadID()
{
#if defined (__APPLE__)
- // Calling "mach_port_deallocate()" bumps the reference count on the thread
+ // Calling "mach_thread_self()" bumps the reference count on the thread
// port, so we need to deallocate it. mach_task_self() doesn't bump the ref
// count.
thread_port_t thread_self = mach_thread_self();
@@ -489,10 +521,14 @@ Host::GetSignalAsCString (int signo)
case SIGILL: return "SIGILL"; // 4 illegal instruction (not reset when caught)
case SIGTRAP: return "SIGTRAP"; // 5 trace trap (not reset when caught)
case SIGABRT: return "SIGABRT"; // 6 abort()
-#if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE))
+#if defined(SIGPOLL)
+#if !defined(SIGIO) || (SIGPOLL != SIGIO)
+// Under some GNU/Linux, SIGPOLL and SIGIO are the same. Causing the build to
+// fail with 'multiple define cases with same value'
case SIGPOLL: return "SIGPOLL"; // 7 pollable event ([XSR] generated, not supported)
#endif
-#if !defined(_POSIX_C_SOURCE)
+#endif
+#if defined(SIGEMT)
case SIGEMT: return "SIGEMT"; // 7 EMT instruction
#endif
case SIGFPE: return "SIGFPE"; // 8 floating point exception
@@ -510,15 +546,17 @@ Host::GetSignalAsCString (int signo)
case SIGCHLD: return "SIGCHLD"; // 20 to parent on child stop or exit
case SIGTTIN: return "SIGTTIN"; // 21 to readers pgrp upon background tty read
case SIGTTOU: return "SIGTTOU"; // 22 like TTIN for output if (tp->t_local&LTOSTOP)
-#if !defined(_POSIX_C_SOURCE)
+#if defined(SIGIO)
case SIGIO: return "SIGIO"; // 23 input/output possible signal
#endif
case SIGXCPU: return "SIGXCPU"; // 24 exceeded CPU time limit
case SIGXFSZ: return "SIGXFSZ"; // 25 exceeded file size limit
case SIGVTALRM: return "SIGVTALRM"; // 26 virtual time alarm
case SIGPROF: return "SIGPROF"; // 27 profiling time alarm
-#if !defined(_POSIX_C_SOURCE)
+#if defined(SIGWINCH)
case SIGWINCH: return "SIGWINCH"; // 28 window size changes
+#endif
+#if defined(SIGINFO)
case SIGINFO: return "SIGINFO"; // 29 information request
#endif
case SIGUSR1: return "SIGUSR1"; // 30 user defined signal 1
@@ -739,8 +777,8 @@ bool
Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid,
const char *thread_name, size_t len)
{
- char *namebuf = (char *)::malloc (len + 1);
-
+ std::unique_ptr<char[]> namebuf(new char[len+1]);
+
// Thread names are coming in like '<lldb.comm.debugger.edit>' and
// '<lldb.comm.debugger.editline>'. So just chopping the end of the string
// off leads to a lot of similar named threads. Go through the thread name
@@ -749,10 +787,10 @@ Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid,
if (lastdot && lastdot != thread_name)
thread_name = lastdot + 1;
- ::strncpy (namebuf, thread_name, len);
+ ::strncpy (namebuf.get(), thread_name, len);
namebuf[len] = 0;
- int namebuflen = strlen(namebuf);
+ int namebuflen = strlen(namebuf.get());
if (namebuflen > 0)
{
if (namebuf[namebuflen - 1] == '(' || namebuf[namebuflen - 1] == '>')
@@ -761,10 +799,8 @@ Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid,
namebuflen--;
namebuf[namebuflen] = 0;
}
- return Host::SetThreadName (pid, tid, namebuf);
+ return Host::SetThreadName (pid, tid, namebuf.get());
}
-
- ::free(namebuf);
return false;
}
@@ -1092,19 +1128,23 @@ Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)
{
framework_pos += strlen("LLDB.framework");
::strncpy (framework_pos, "/Resources/Python", PATH_MAX - (framework_pos - raw_path));
- }
-#else
- llvm::SmallString<256> python_version_dir;
- llvm::raw_svector_ostream os(python_version_dir);
- os << "/python" << PY_MAJOR_VERSION << '.' << PY_MINOR_VERSION << "/site-packages";
- os.flush();
+ }
+ else
+ {
+#endif
+ llvm::SmallString<256> python_version_dir;
+ llvm::raw_svector_ostream os(python_version_dir);
+ os << "/python" << PY_MAJOR_VERSION << '.' << PY_MINOR_VERSION << "/site-packages";
+ os.flush();
- // We may get our string truncated. Should we protect
- // this with an assert?
+ // We may get our string truncated. Should we protect
+ // this with an assert?
- ::strncat(raw_path, python_version_dir.c_str(),
- sizeof(raw_path) - strlen(raw_path) - 1);
+ ::strncat(raw_path, python_version_dir.c_str(),
+ sizeof(raw_path) - strlen(raw_path) - 1);
+#if defined (__APPLE__)
+ }
#endif
FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
g_lldb_python_dir.SetCString(resolved_path);
@@ -1224,6 +1264,29 @@ Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)
// TODO: where would user LLDB plug-ins be located on other systems?
return false;
}
+
+ case ePathTypeLLDBTempSystemDir:
+ {
+ static ConstString g_lldb_tmp_dir;
+ if (!g_lldb_tmp_dir)
+ {
+ const char *tmpdir_cstr = getenv("TMPDIR");
+ if (tmpdir_cstr == NULL)
+ {
+ tmpdir_cstr = getenv("TMP");
+ if (tmpdir_cstr == NULL)
+ tmpdir_cstr = getenv("TEMP");
+ }
+ if (tmpdir_cstr)
+ {
+ g_lldb_tmp_dir.SetCString(tmpdir_cstr);
+ if (log)
+ log->Printf("Host::GetLLDBPath(ePathTypeLLDBTempSystemDir) => '%s'", g_lldb_tmp_dir.GetCString());
+ }
+ }
+ file_spec.GetDirectory() = g_lldb_tmp_dir;
+ return (bool)file_spec.GetDirectory();
+ }
}
return false;
@@ -1473,21 +1536,36 @@ Host::RunShellCommand (const char *command,
if (working_dir)
launch_info.SetWorkingDirectory(working_dir);
- char output_file_path_buffer[L_tmpnam];
+ char output_file_path_buffer[PATH_MAX];
const char *output_file_path = NULL;
+
if (command_output_ptr)
{
// Create a temporary file to get the stdout/stderr and redirect the
// output of the command into this file. We will later read this file
// if all goes well and fill the data into "command_output_ptr"
- output_file_path = ::tmpnam(output_file_path_buffer);
- launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
+ FileSpec tmpdir_file_spec;
+ if (Host::GetLLDBPath (ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
+ {
+ tmpdir_file_spec.GetFilename().SetCString("lldb-shell-output.XXXXXX");
+ strncpy(output_file_path_buffer, tmpdir_file_spec.GetPath().c_str(), sizeof(output_file_path_buffer));
+ }
+ else
+ {
+ strncpy(output_file_path_buffer, "/tmp/lldb-shell-output.XXXXXX", sizeof(output_file_path_buffer));
+ }
+
+ output_file_path = ::mktemp(output_file_path_buffer);
+ }
+
+ launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
+ if (output_file_path)
+ {
launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_path, false, true);
launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO);
}
else
{
- launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true);
launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true);
}
@@ -1569,24 +1647,73 @@ Host::RunShellCommand (const char *command,
return error;
}
-#if defined(__linux__) || defined(__FreeBSD__)
-// The functions below implement process launching via posix_spawn() for Linux
-// and FreeBSD.
-// The posix_spawn() and posix_spawnp() functions first appeared in FreeBSD 8.0,
-static Error
-LaunchProcessPosixSpawn (const char *exe_path, ProcessLaunchInfo &launch_info, ::pid_t &pid)
+// LaunchProcessPosixSpawn for Apple, Linux, FreeBSD and other GLIBC
+// systems
+
+#if defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__)
+
+// this method needs to be visible to macosx/Host.cpp and
+// common/Host.cpp.
+
+short
+Host::GetPosixspawnFlags (ProcessLaunchInfo &launch_info)
+{
+ short flags = POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK;
+
+#if defined (__APPLE__)
+ if (launch_info.GetFlags().Test (eLaunchFlagExec))
+ flags |= POSIX_SPAWN_SETEXEC; // Darwin specific posix_spawn flag
+
+ if (launch_info.GetFlags().Test (eLaunchFlagDebug))
+ flags |= POSIX_SPAWN_START_SUSPENDED; // Darwin specific posix_spawn flag
+
+ if (launch_info.GetFlags().Test (eLaunchFlagDisableASLR))
+ flags |= _POSIX_SPAWN_DISABLE_ASLR; // Darwin specific posix_spawn flag
+
+ if (launch_info.GetLaunchInSeparateProcessGroup())
+ flags |= POSIX_SPAWN_SETPGROUP;
+
+#ifdef POSIX_SPAWN_CLOEXEC_DEFAULT
+#if defined (__APPLE__) && (defined (__x86_64__) || defined (__i386__))
+ static LazyBool g_use_close_on_exec_flag = eLazyBoolCalculate;
+ if (g_use_close_on_exec_flag == eLazyBoolCalculate)
+ {
+ g_use_close_on_exec_flag = eLazyBoolNo;
+
+ uint32_t major, minor, update;
+ if (Host::GetOSVersion(major, minor, update))
+ {
+ // Kernel panic if we use the POSIX_SPAWN_CLOEXEC_DEFAULT on 10.7 or earlier
+ if (major > 10 || (major == 10 && minor > 7))
+ {
+ // Only enable for 10.8 and later OS versions
+ g_use_close_on_exec_flag = eLazyBoolYes;
+ }
+ }
+ }
+#else
+ static LazyBool g_use_close_on_exec_flag = eLazyBoolYes;
+#endif
+ // Close all files exception those with file actions if this is supported.
+ if (g_use_close_on_exec_flag == eLazyBoolYes)
+ flags |= POSIX_SPAWN_CLOEXEC_DEFAULT;
+#endif
+#endif // #if defined (__APPLE__)
+ return flags;
+}
+
+Error
+Host::LaunchProcessPosixSpawn (const char *exe_path, ProcessLaunchInfo &launch_info, ::pid_t &pid)
{
Error error;
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_HOST | LIBLLDB_LOG_PROCESS));
- assert(exe_path);
- assert(!launch_info.GetFlags().Test (eLaunchFlagDebug));
-
posix_spawnattr_t attr;
-
error.SetError( ::posix_spawnattr_init (&attr), eErrorTypePOSIX);
- error.LogIfError(log, "::posix_spawnattr_init ( &attr )");
+
+ if (error.Fail() || log)
+ error.PutToLog(log, "::posix_spawnattr_init ( &attr )");
if (error.Fail())
return error;
@@ -1598,52 +1725,82 @@ LaunchProcessPosixSpawn (const char *exe_path, ProcessLaunchInfo &launch_info, :
sigset_t all_signals;
sigemptyset (&no_signals);
sigfillset (&all_signals);
- ::posix_spawnattr_setsigmask(&attr, &all_signals);
+ ::posix_spawnattr_setsigmask(&attr, &no_signals);
+#if defined (__linux__) || defined (__FreeBSD__)
::posix_spawnattr_setsigdefault(&attr, &no_signals);
+#else
+ ::posix_spawnattr_setsigdefault(&attr, &all_signals);
+#endif
- short flags = POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK;
+ short flags = GetPosixspawnFlags(launch_info);
error.SetError( ::posix_spawnattr_setflags (&attr, flags), eErrorTypePOSIX);
- error.LogIfError(log, "::posix_spawnattr_setflags ( &attr, flags=0x%8.8x )", flags);
+ if (error.Fail() || log)
+ error.PutToLog(log, "::posix_spawnattr_setflags ( &attr, flags=0x%8.8x )", flags);
if (error.Fail())
return error;
- const size_t num_file_actions = launch_info.GetNumFileActions ();
- posix_spawn_file_actions_t file_actions, *file_action_ptr = NULL;
- // Make a quick class that will cleanup the posix spawn attributes in case
- // we return in the middle of this function.
- lldb_utility::CleanUp <posix_spawn_file_actions_t *, int>
- posix_spawn_file_actions_cleanup (file_action_ptr, NULL, posix_spawn_file_actions_destroy);
+ // posix_spawnattr_setbinpref_np appears to be an Apple extension per:
+ // http://www.unix.com/man-page/OSX/3/posix_spawnattr_setbinpref_np/
+#if defined (__APPLE__) && !defined (__arm__)
- if (num_file_actions > 0)
+ // We don't need to do this for ARM, and we really shouldn't now that we
+ // have multiple CPU subtypes and no posix_spawnattr call that allows us
+ // to set which CPU subtype to launch...
+ const ArchSpec &arch_spec = launch_info.GetArchitecture();
+ cpu_type_t cpu = arch_spec.GetMachOCPUType();
+ cpu_type_t sub = arch_spec.GetMachOCPUSubType();
+ if (cpu != 0 &&
+ cpu != UINT32_MAX &&
+ cpu != LLDB_INVALID_CPUTYPE &&
+ !(cpu == 0x01000007 && sub == 8)) // If haswell is specified, don't try to set the CPU type or we will fail
{
- error.SetError( ::posix_spawn_file_actions_init (&file_actions), eErrorTypePOSIX);
- error.LogIfError(log, "::posix_spawn_file_actions_init ( &file_actions )");
- if (error.Fail())
+ size_t ocount = 0;
+ error.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX);
+ if (error.Fail() || log)
+ error.PutToLog(log, "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %llu )", cpu, (uint64_t)ocount);
+
+ if (error.Fail() || ocount != 1)
return error;
+ }
- file_action_ptr = &file_actions;
- posix_spawn_file_actions_cleanup.set(file_action_ptr);
+#endif
- for (size_t i = 0; i < num_file_actions; ++i)
- {
- const ProcessLaunchInfo::FileAction *launch_file_action = launch_info.GetFileActionAtIndex(i);
- if (launch_file_action &&
- !ProcessLaunchInfo::FileAction::AddPosixSpawnFileAction (&file_actions,
- launch_file_action,
- log,
- error))
- return error;
- }
+ const char *tmp_argv[2];
+ char * const *argv = (char * const*)launch_info.GetArguments().GetConstArgumentVector();
+ char * const *envp = (char * const*)launch_info.GetEnvironmentEntries().GetConstArgumentVector();
+ if (argv == NULL)
+ {
+ // posix_spawn gets very unhappy if it doesn't have at least the program
+ // name in argv[0]. One of the side affects I have noticed is the environment
+ // variables don't make it into the child process if "argv == NULL"!!!
+ tmp_argv[0] = exe_path;
+ tmp_argv[1] = NULL;
+ argv = (char * const*)tmp_argv;
}
- // Change working directory if neccessary.
+#if !defined (__APPLE__)
+ // manage the working directory
char current_dir[PATH_MAX];
current_dir[0] = '\0';
+#endif
const char *working_dir = launch_info.GetWorkingDirectory();
- if (working_dir != NULL)
+ if (working_dir)
{
+#if defined (__APPLE__)
+ // Set the working directory on this thread only
+ if (__pthread_chdir (working_dir) < 0) {
+ if (errno == ENOENT) {
+ error.SetErrorStringWithFormat("No such file or directory: %s", working_dir);
+ } else if (errno == ENOTDIR) {
+ error.SetErrorStringWithFormat("Path doesn't name a directory: %s", working_dir);
+ } else {
+ error.SetErrorStringWithFormat("An unknown error occurred when changing directory for process execution.");
+ }
+ return error;
+ }
+#else
if (::getcwd(current_dir, sizeof(current_dir)) == NULL)
{
error.SetError(errno, eErrorTypePOSIX);
@@ -1657,45 +1814,111 @@ LaunchProcessPosixSpawn (const char *exe_path, ProcessLaunchInfo &launch_info, :
error.LogIfError(log, "unable to change working directory to %s", working_dir);
return error;
}
+#endif
}
- const char *tmp_argv[2];
- char * const *argv = (char * const*)launch_info.GetArguments().GetConstArgumentVector();
- char * const *envp = (char * const*)launch_info.GetEnvironmentEntries().GetConstArgumentVector();
-
- // Prepare minimal argument list if we didn't get it from the launch_info structure.
- // We must pass argv into posix_spawnp and it must contain at least two items -
- // pointer to an executable and NULL.
- if (argv == NULL)
+ const size_t num_file_actions = launch_info.GetNumFileActions ();
+ if (num_file_actions > 0)
{
- tmp_argv[0] = exe_path;
- tmp_argv[1] = NULL;
- argv = (char * const*)tmp_argv;
- }
+ posix_spawn_file_actions_t file_actions;
+ error.SetError( ::posix_spawn_file_actions_init (&file_actions), eErrorTypePOSIX);
+ if (error.Fail() || log)
+ error.PutToLog(log, "::posix_spawn_file_actions_init ( &file_actions )");
+ if (error.Fail())
+ return error;
+
+ // Make a quick class that will cleanup the posix spawn attributes in case
+ // we return in the middle of this function.
+ lldb_utility::CleanUp <posix_spawn_file_actions_t *, int> posix_spawn_file_actions_cleanup (&file_actions, posix_spawn_file_actions_destroy);
+
+ for (size_t i=0; i<num_file_actions; ++i)
+ {
+ const ProcessLaunchInfo::FileAction *launch_file_action = launch_info.GetFileActionAtIndex(i);
+ if (launch_file_action)
+ {
+ if (!ProcessLaunchInfo::FileAction::AddPosixSpawnFileAction (&file_actions,
+ launch_file_action,
+ log,
+ error))
+ return error;
+ }
+ }
- error.SetError (::posix_spawnp (&pid,
- exe_path,
- (num_file_actions > 0) ? &file_actions : NULL,
- &attr,
- argv,
- envp),
- eErrorTypePOSIX);
+ error.SetError (::posix_spawnp (&pid,
+ exe_path,
+ &file_actions,
+ &attr,
+ argv,
+ envp),
+ eErrorTypePOSIX);
- error.LogIfError(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )",
- pid, exe_path, file_action_ptr, &attr, argv, envp);
+ if (error.Fail() || log)
+ {
+ error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )",
+ pid,
+ exe_path,
+ &file_actions,
+ &attr,
+ argv,
+ envp);
+ if (log)
+ {
+ for (int ii=0; argv[ii]; ++ii)
+ log->Printf("argv[%i] = '%s'", ii, argv[ii]);
+ }
+ }
- // Change back the current directory.
- // NOTE: do not override previously established error from posix_spawnp.
- if (working_dir != NULL && ::chdir(current_dir) == -1 && error.Success())
+ }
+ else
{
- error.SetError(errno, eErrorTypePOSIX);
- error.LogIfError(log, "unable to change current directory back to %s",
- current_dir);
+ error.SetError (::posix_spawnp (&pid,
+ exe_path,
+ NULL,
+ &attr,
+ argv,
+ envp),
+ eErrorTypePOSIX);
+
+ if (error.Fail() || log)
+ {
+ error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = NULL, attr = %p, argv = %p, envp = %p )",
+ pid,
+ exe_path,
+ &attr,
+ argv,
+ envp);
+ if (log)
+ {
+ for (int ii=0; argv[ii]; ++ii)
+ log->Printf("argv[%i] = '%s'", ii, argv[ii]);
+ }
+ }
+ }
+
+ if (working_dir)
+ {
+#if defined (__APPLE__)
+ // No more thread specific current working directory
+ __pthread_fchdir (-1);
+#else
+ if (::chdir(current_dir) == -1 && error.Success())
+ {
+ error.SetError(errno, eErrorTypePOSIX);
+ error.LogIfError(log, "unable to change current directory back to %s",
+ current_dir);
+ }
+#endif
}
return error;
}
+#endif // LaunchProcedssPosixSpawn: Apple, Linux, FreeBSD and other GLIBC systems
+
+
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__GLIBC__)
+// The functions below implement process launching via posix_spawn() for Linux
+// and FreeBSD.
Error
Host::LaunchProcess (ProcessLaunchInfo &launch_info)
@@ -1747,6 +1970,8 @@ Host::LaunchProcess (ProcessLaunchInfo &launch_info)
// If all went well, then set the process ID into the launch info
launch_info.SetProcessID(pid);
+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
+
// Make sure we reap any processes we spawn or we will have zombies.
if (!launch_info.MonitorProcess())
{
@@ -1755,6 +1980,13 @@ Host::LaunchProcess (ProcessLaunchInfo &launch_info)
NULL,
pid,
monitor_signals);
+ if (log)
+ log->PutCString ("monitored child process with default Process::SetProcessExitStatus.");
+ }
+ else
+ {
+ if (log)
+ log->PutCString ("monitored child process with user-specified process monitor.");
}
}
else
diff --git a/source/Host/common/OptionParser.cpp b/source/Host/common/OptionParser.cpp
index ead044f53cf1..cf133597cb84 100644
--- a/source/Host/common/OptionParser.cpp
+++ b/source/Host/common/OptionParser.cpp
@@ -9,14 +9,10 @@
#include "lldb/Host/OptionParser.h"
-#ifdef _MSC_VER
-#include "../windows/msvc/getopt.inc"
-#else
-#ifdef _WIN32
+#if (!defined( _MSC_VER ) && defined( _WIN32 ))
#define _BSD_SOURCE // Required so that getopt.h defines optreset
#endif
-#include <getopt.h>
-#endif
+#include "lldb/Host/HostGetOpt.h"
using namespace lldb_private;
diff --git a/source/Host/common/SocketAddress.cpp b/source/Host/common/SocketAddress.cpp
index 1fa7531af9dc..75f3cd13f586 100644
--- a/source/Host/common/SocketAddress.cpp
+++ b/source/Host/common/SocketAddress.cpp
@@ -95,7 +95,7 @@ GetFamilyLength (sa_family_t family)
socklen_t
SocketAddress::GetLength () const
{
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
return m_socket_addr.sa.sa_len;
#else
return GetFamilyLength (GetFamily());
@@ -118,24 +118,24 @@ void
SocketAddress::SetFamily (sa_family_t family)
{
m_socket_addr.sa.sa_family = family;
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
m_socket_addr.sa.sa_len = GetFamilyLength (family);
#endif
}
-in_port_t
+uint16_t
SocketAddress::GetPort () const
{
switch (GetFamily())
{
- case AF_INET: return m_socket_addr.sa_ipv4.sin_port;
- case AF_INET6: return m_socket_addr.sa_ipv6.sin6_port;
+ case AF_INET: return ntohs(m_socket_addr.sa_ipv4.sin_port);
+ case AF_INET6: return ntohs(m_socket_addr.sa_ipv6.sin6_port);
}
return 0;
}
bool
-SocketAddress::SetPort (in_port_t port)
+SocketAddress::SetPort (uint16_t port)
{
switch (GetFamily())
{
@@ -206,36 +206,34 @@ SocketAddress::operator=(const struct sockaddr_storage &s)
}
bool
-SocketAddress::SetAddress (const struct addrinfo *hints_ptr,
- const char *host,
- const char *service,
- struct addrinfo *addr_info_ptr)
+SocketAddress::getaddrinfo (const char *host,
+ const char *service,
+ int ai_family,
+ int ai_socktype,
+ int ai_protocol,
+ int ai_flags)
{
+ struct addrinfo hints;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = ai_family;
+ hints.ai_socktype = ai_socktype;
+ hints.ai_protocol = ai_protocol;
+ hints.ai_flags = ai_flags;
+
struct addrinfo *service_info_list = NULL;
- int err = ::getaddrinfo (host, service, hints_ptr, &service_info_list);
+ int err = ::getaddrinfo (host, service, &hints, &service_info_list);
if (err == 0 && service_info_list)
- {
- if (addr_info_ptr)
- *addr_info_ptr = *service_info_list;
*this = service_info_list;
- }
else
Clear();
:: freeaddrinfo (service_info_list);
-
- const bool is_valid = IsValid();
- if (!is_valid)
- {
- if (addr_info_ptr)
- ::memset (addr_info_ptr, 0, sizeof(struct addrinfo));
- }
- return is_valid;
+ return IsValid();
}
bool
-SocketAddress::SetToLocalhost (sa_family_t family, in_port_t port)
+SocketAddress::SetToLocalhost (sa_family_t family, uint16_t port)
{
switch (family)
{
@@ -243,7 +241,7 @@ SocketAddress::SetToLocalhost (sa_family_t family, in_port_t port)
SetFamily (AF_INET);
if (SetPort (port))
{
- m_socket_addr.sa_ipv4.sin_addr.s_addr = htonl (INADDR_ANY);
+ m_socket_addr.sa_ipv4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
return true;
}
break;
@@ -252,7 +250,7 @@ SocketAddress::SetToLocalhost (sa_family_t family, in_port_t port)
SetFamily (AF_INET6);
if (SetPort (port))
{
- m_socket_addr.sa_ipv6.sin6_addr = in6addr_any;
+ m_socket_addr.sa_ipv6.sin6_addr = in6addr_loopback;
return true;
}
break;
@@ -261,3 +259,31 @@ SocketAddress::SetToLocalhost (sa_family_t family, in_port_t port)
Clear();
return false;
}
+
+bool
+SocketAddress::SetToAnyAddress (sa_family_t family, uint16_t port)
+{
+ switch (family)
+ {
+ case AF_INET:
+ SetFamily (AF_INET);
+ if (SetPort (port))
+ {
+ m_socket_addr.sa_ipv4.sin_addr.s_addr = htonl (INADDR_ANY);
+ return true;
+ }
+ break;
+
+ case AF_INET6:
+ SetFamily (AF_INET6);
+ if (SetPort (port))
+ {
+ m_socket_addr.sa_ipv6.sin6_addr = in6addr_any;
+ return true;
+ }
+ break;
+
+ }
+ Clear();
+ return false;
+}
diff --git a/source/Interpreter/CommandInterpreter.cpp b/source/Interpreter/CommandInterpreter.cpp
index a7c892d255e8..fb0fc7f700a5 100644
--- a/source/Interpreter/CommandInterpreter.cpp
+++ b/source/Interpreter/CommandInterpreter.cpp
@@ -22,6 +22,7 @@
#include "../Commands/CommandObjectDisassemble.h"
#include "../Commands/CommandObjectExpression.h"
#include "../Commands/CommandObjectFrame.h"
+#include "../Commands/CommandObjectGUI.h"
#include "../Commands/CommandObjectHelp.h"
#include "../Commands/CommandObjectLog.h"
#include "../Commands/CommandObjectMemory.h"
@@ -42,11 +43,12 @@
#include "lldb/Core/Debugger.h"
-#include "lldb/Core/InputReader.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Stream.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/Core/Timer.h"
+#include "lldb/Host/Editline.h"
#include "lldb/Host/Host.h"
#include "lldb/Interpreter/Args.h"
@@ -99,11 +101,13 @@ CommandInterpreter::CommandInterpreter
) :
Broadcaster (&debugger, "lldb.command-interpreter"),
Properties(OptionValuePropertiesSP(new OptionValueProperties(ConstString("interpreter")))),
+ IOHandlerDelegate (IOHandlerDelegate::Completion::LLDBCommand),
m_debugger (debugger),
m_synchronous_execution (synchronous_execution),
m_skip_lldbinit_files (false),
m_skip_app_init_files (false),
m_script_interpreter_ap (),
+ m_command_io_handler_sp (),
m_comment_char ('#'),
m_batch_command_mode (false),
m_truncation_warning(eNoTruncation),
@@ -376,6 +380,7 @@ CommandInterpreter::LoadCommandDictionary ()
m_command_dict["disassemble"] = CommandObjectSP (new CommandObjectDisassemble (*this));
m_command_dict["expression"]= CommandObjectSP (new CommandObjectExpression (*this));
m_command_dict["frame"] = CommandObjectSP (new CommandObjectMultiwordFrame (*this));
+ m_command_dict["gui"] = CommandObjectSP (new CommandObjectGUI (*this));
m_command_dict["help"] = CommandObjectSP (new CommandObjectHelp (*this));
m_command_dict["log"] = CommandObjectSP (new CommandObjectLog (*this));
m_command_dict["memory"] = CommandObjectSP (new CommandObjectMemory (*this));
@@ -1929,12 +1934,19 @@ CommandInterpreter::HandleCompletionMatches (Args &parsed_line,
&& matches.GetStringAtIndex(0) != NULL
&& strcmp (parsed_line.GetArgumentAtIndex(0), matches.GetStringAtIndex(0)) == 0)
{
- look_for_subcommand = true;
- num_command_matches = 0;
- matches.DeleteStringAtIndex(0);
- parsed_line.AppendArgument ("");
- cursor_index++;
- cursor_char_position = 0;
+ if (parsed_line.GetArgumentCount() == 1)
+ {
+ word_complete = true;
+ }
+ else
+ {
+ look_for_subcommand = true;
+ num_command_matches = 0;
+ matches.DeleteStringAtIndex(0);
+ parsed_line.AppendArgument ("");
+ cursor_index++;
+ cursor_char_position = 0;
+ }
}
}
@@ -2023,7 +2035,7 @@ CommandInterpreter::HandleCompletion (const char *current_line,
const char *current_elem = partial_parsed_line.GetArgumentAtIndex(cursor_index);
if (cursor_char_position == 0 || current_elem[cursor_char_position - 1] != ' ')
{
- parsed_line.InsertArgumentAtIndex(cursor_index + 1, "", '"');
+ parsed_line.InsertArgumentAtIndex(cursor_index + 1, "", '\0');
cursor_index++;
cursor_char_position = 0;
}
@@ -2086,96 +2098,15 @@ CommandInterpreter::~CommandInterpreter ()
{
}
-const char *
-CommandInterpreter::GetPrompt ()
-{
- return m_debugger.GetPrompt();
-}
-
void
-CommandInterpreter::SetPrompt (const char *new_prompt)
+CommandInterpreter::UpdatePrompt (const char *new_prompt)
{
- m_debugger.SetPrompt (new_prompt);
+ EventSP prompt_change_event_sp (new Event(eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));;
+ BroadcastEvent (prompt_change_event_sp);
+ if (m_command_io_handler_sp)
+ m_command_io_handler_sp->SetPrompt(new_prompt);
}
-size_t
-CommandInterpreter::GetConfirmationInputReaderCallback
-(
- void *baton,
- InputReader &reader,
- lldb::InputReaderAction action,
- const char *bytes,
- size_t bytes_len
-)
-{
- File &out_file = reader.GetDebugger().GetOutputFile();
- bool *response_ptr = (bool *) baton;
-
- switch (action)
- {
- case eInputReaderActivate:
- if (out_file.IsValid())
- {
- if (reader.GetPrompt())
- {
- out_file.Printf ("%s", reader.GetPrompt());
- out_file.Flush ();
- }
- }
- break;
-
- case eInputReaderDeactivate:
- break;
-
- case eInputReaderReactivate:
- if (out_file.IsValid() && reader.GetPrompt())
- {
- out_file.Printf ("%s", reader.GetPrompt());
- out_file.Flush ();
- }
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
-
- case eInputReaderGotToken:
- if (bytes_len == 0)
- {
- reader.SetIsDone(true);
- }
- else if (bytes[0] == 'y' || bytes[0] == 'Y')
- {
- *response_ptr = true;
- reader.SetIsDone(true);
- }
- else if (bytes[0] == 'n' || bytes[0] == 'N')
- {
- *response_ptr = false;
- reader.SetIsDone(true);
- }
- else
- {
- if (out_file.IsValid() && !reader.IsDone() && reader.GetPrompt())
- {
- out_file.Printf ("Please answer \"y\" or \"n\".\n%s", reader.GetPrompt());
- out_file.Flush ();
- }
- }
- break;
-
- case eInputReaderInterrupt:
- case eInputReaderEndOfFile:
- *response_ptr = false; // Assume ^C or ^D means cancel the proposed action
- reader.SetIsDone (true);
- break;
-
- case eInputReaderDone:
- break;
- }
-
- return bytes_len;
-
-}
bool
CommandInterpreter::Confirm (const char *message, bool default_answer)
@@ -2183,31 +2114,13 @@ CommandInterpreter::Confirm (const char *message, bool default_answer)
// Check AutoConfirm first:
if (m_debugger.GetAutoConfirm())
return default_answer;
-
- InputReaderSP reader_sp (new InputReader(GetDebugger()));
- bool response = default_answer;
- if (reader_sp)
- {
- std::string prompt(message);
- prompt.append(": [");
- if (default_answer)
- prompt.append ("Y/n] ");
- else
- prompt.append ("y/N] ");
-
- Error err (reader_sp->Initialize (CommandInterpreter::GetConfirmationInputReaderCallback,
- &response, // baton
- eInputReaderGranularityLine, // token size, to pass to callback function
- NULL, // end token
- prompt.c_str(), // prompt
- true)); // echo input
- if (err.Success())
- {
- GetDebugger().PushInputReader (reader_sp);
- }
- reader_sp->WaitOnReaderIsDone();
- }
- return response;
+
+ IOHandlerConfirm *confirm = new IOHandlerConfirm(m_debugger,
+ message,
+ default_answer);
+ IOHandlerSP io_handler_sp (confirm);
+ m_debugger.RunIOHandler (io_handler_sp);
+ return confirm->GetResponse();
}
OptionArgVectorSP
@@ -2477,13 +2390,16 @@ CommandInterpreter::SourceInitFile (bool in_cwd, CommandReturnObject &result)
if (init_file.Exists())
{
- ExecutionContext *exe_ctx = NULL; // We don't have any context yet.
- bool stop_on_continue = true;
- bool stop_on_error = false;
- bool echo_commands = false;
- bool print_results = false;
-
- HandleCommandsFromFile (init_file, exe_ctx, stop_on_continue, stop_on_error, echo_commands, print_results, eLazyBoolNo, result);
+ const bool saved_batch = SetBatchCommandMode (true);
+ HandleCommandsFromFile (init_file,
+ NULL, // Execution context
+ eLazyBoolYes, // Stop on continue
+ eLazyBoolNo, // Stop on error
+ eLazyBoolNo, // Don't echo commands
+ eLazyBoolNo, // Don't print command output
+ eLazyBoolNo, // Don't add the commands that are sourced into the history buffer
+ result);
+ SetBatchCommandMode (saved_batch);
}
else
{
@@ -2546,8 +2462,8 @@ CommandInterpreter::HandleCommands (const StringList &commands,
if (echo_commands)
{
result.AppendMessageWithFormat ("%s %s\n",
- GetPrompt(),
- cmd);
+ m_debugger.GetPrompt(),
+ cmd);
}
CommandReturnObject tmp_result;
@@ -2631,30 +2547,145 @@ CommandInterpreter::HandleCommands (const StringList &commands,
return;
}
+// Make flags that we can pass into the IOHandler so our delegates can do the right thing
+enum {
+ eHandleCommandFlagStopOnContinue = (1u << 0),
+ eHandleCommandFlagStopOnError = (1u << 1),
+ eHandleCommandFlagEchoCommand = (1u << 2),
+ eHandleCommandFlagPrintResult = (1u << 3)
+};
+
void
CommandInterpreter::HandleCommandsFromFile (FileSpec &cmd_file,
ExecutionContext *context,
- bool stop_on_continue,
- bool stop_on_error,
- bool echo_command,
- bool print_result,
+ LazyBool stop_on_continue,
+ LazyBool stop_on_error,
+ LazyBool echo_command,
+ LazyBool print_result,
LazyBool add_to_history,
CommandReturnObject &result)
{
if (cmd_file.Exists())
{
- bool success;
- StringList commands;
- success = commands.ReadFileLines(cmd_file);
- if (!success)
+ StreamFileSP input_file_sp (new StreamFile());
+
+ std::string cmd_file_path = cmd_file.GetPath();
+ Error error = input_file_sp->GetFile().Open(cmd_file_path.c_str(), File::eOpenOptionRead);
+
+ if (error.Success())
{
- result.AppendErrorWithFormat ("Error reading commands from file: %s.\n", cmd_file.GetFilename().AsCString());
+ Debugger &debugger = GetDebugger();
+
+ uint32_t flags = 0;
+
+ if (stop_on_continue == eLazyBoolCalculate)
+ {
+ if (m_command_source_flags.empty())
+ {
+ // Stop on continue by default
+ flags |= eHandleCommandFlagStopOnContinue;
+ }
+ else if (m_command_source_flags.back() & eHandleCommandFlagStopOnContinue)
+ {
+ flags |= eHandleCommandFlagStopOnContinue;
+ }
+ }
+ else if (stop_on_continue == eLazyBoolYes)
+ {
+ flags |= eHandleCommandFlagStopOnContinue;
+ }
+
+ if (stop_on_error == eLazyBoolCalculate)
+ {
+ if (m_command_source_flags.empty())
+ {
+ if (GetStopCmdSourceOnError())
+ flags |= eHandleCommandFlagStopOnError;
+ }
+ else if (m_command_source_flags.back() & eHandleCommandFlagStopOnError)
+ {
+ flags |= eHandleCommandFlagStopOnError;
+ }
+ }
+ else if (stop_on_error == eLazyBoolYes)
+ {
+ flags |= eHandleCommandFlagStopOnError;
+ }
+
+ if (echo_command == eLazyBoolCalculate)
+ {
+ if (m_command_source_flags.empty())
+ {
+ // Echo command by default
+ flags |= eHandleCommandFlagEchoCommand;
+ }
+ else if (m_command_source_flags.back() & eHandleCommandFlagEchoCommand)
+ {
+ flags |= eHandleCommandFlagEchoCommand;
+ }
+ }
+ else if (echo_command == eLazyBoolYes)
+ {
+ flags |= eHandleCommandFlagEchoCommand;
+ }
+
+ if (print_result == eLazyBoolCalculate)
+ {
+ if (m_command_source_flags.empty())
+ {
+ // Print output by default
+ flags |= eHandleCommandFlagPrintResult;
+ }
+ else if (m_command_source_flags.back() & eHandleCommandFlagPrintResult)
+ {
+ flags |= eHandleCommandFlagPrintResult;
+ }
+ }
+ else if (print_result == eLazyBoolYes)
+ {
+ flags |= eHandleCommandFlagPrintResult;
+ }
+
+ if (flags & eHandleCommandFlagPrintResult)
+ {
+ debugger.GetOutputFile()->Printf("Executing commands in '%s'.\n", cmd_file_path.c_str());
+ }
+
+ // Used for inheriting the right settings when "command source" might have
+ // nested "command source" commands
+ lldb::StreamFileSP empty_stream_sp;
+ m_command_source_flags.push_back(flags);
+ IOHandlerSP io_handler_sp (new IOHandlerEditline (debugger,
+ input_file_sp,
+ empty_stream_sp, // Pass in an empty stream so we inherit the top input reader output stream
+ empty_stream_sp, // Pass in an empty stream so we inherit the top input reader error stream
+ flags,
+ NULL, // Pass in NULL for "editline_name" so no history is saved, or written
+ debugger.GetPrompt(),
+ false, // Not multi-line
+ *this));
+ const bool old_async_execution = debugger.GetAsyncExecution();
+
+ // Set synchronous execution if we not stopping when we continue
+ if ((flags & eHandleCommandFlagStopOnContinue) == 0)
+ debugger.SetAsyncExecution (false);
+
+ m_command_source_depth++;
+
+ debugger.RunIOHandler(io_handler_sp);
+ if (!m_command_source_flags.empty())
+ m_command_source_flags.pop_back();
+ m_command_source_depth--;
+ result.SetStatus (eReturnStatusSuccessFinishNoResult);
+ debugger.SetAsyncExecution (old_async_execution);
+ }
+ else
+ {
+ result.AppendErrorWithFormat ("error: an error occurred read file '%s': %s\n", cmd_file_path.c_str(), error.AsCString());
result.SetStatus (eReturnStatusFailed);
- return;
}
- m_command_source_depth++;
- HandleCommands (commands, context, stop_on_continue, stop_on_error, echo_command, print_result, add_to_history, result);
- m_command_source_depth--;
+
+
}
else
{
@@ -2894,7 +2925,6 @@ CommandInterpreter::FindCommandsForApropos (const char *search_word, StringList
}
}
-
void
CommandInterpreter::UpdateExecutionContext (ExecutionContext *override_context)
{
@@ -2908,3 +2938,195 @@ CommandInterpreter::UpdateExecutionContext (ExecutionContext *override_context)
m_exe_ctx_ref.SetTargetPtr (m_debugger.GetSelectedTarget().get(), adopt_selected);
}
}
+
+
+size_t
+CommandInterpreter::GetProcessOutput ()
+{
+ // The process has stuff waiting for stderr; get it and write it out to the appropriate place.
+ char stdio_buffer[1024];
+ size_t len;
+ size_t total_bytes = 0;
+ Error error;
+ TargetSP target_sp (m_debugger.GetTargetList().GetSelectedTarget());
+ if (target_sp)
+ {
+ ProcessSP process_sp (target_sp->GetProcessSP());
+ if (process_sp)
+ {
+ while ((len = process_sp->GetSTDOUT (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
+ {
+ size_t bytes_written = len;
+ m_debugger.GetOutputFile()->Write (stdio_buffer, bytes_written);
+ total_bytes += len;
+ }
+ while ((len = process_sp->GetSTDERR (stdio_buffer, sizeof (stdio_buffer), error)) > 0)
+ {
+ size_t bytes_written = len;
+ m_debugger.GetErrorFile()->Write (stdio_buffer, bytes_written);
+ total_bytes += len;
+ }
+ }
+ }
+ return total_bytes;
+}
+
+void
+CommandInterpreter::IOHandlerInputComplete (IOHandler &io_handler, std::string &line)
+{
+ const bool is_interactive = io_handler.GetIsInteractive();
+ if (is_interactive == false)
+ {
+ // When we are not interactive, don't execute blank lines. This will happen
+ // sourcing a commands file. We don't want blank lines to repeat the previous
+ // command and cause any errors to occur (like redefining an alias, get an error
+ // and stop parsing the commands file).
+ if (line.empty())
+ return;
+
+ // When using a non-interactive file handle (like when sourcing commands from a file)
+ // we need to echo the command out so we don't just see the command output and no
+ // command...
+ if (io_handler.GetFlags().Test(eHandleCommandFlagEchoCommand))
+ io_handler.GetOutputStreamFile()->Printf("%s%s\n", io_handler.GetPrompt(), line.c_str());
+ }
+
+ lldb_private::CommandReturnObject result;
+ HandleCommand(line.c_str(), eLazyBoolCalculate, result);
+
+ // Now emit the command output text from the command we just executed
+ if (io_handler.GetFlags().Test(eHandleCommandFlagPrintResult))
+ {
+ // Display any STDOUT/STDERR _prior_ to emitting the command result text
+ GetProcessOutput ();
+
+ if (!result.GetImmediateOutputStream())
+ {
+ const char *output = result.GetOutputData();
+ if (output && output[0])
+ io_handler.GetOutputStreamFile()->PutCString(output);
+ }
+
+ // Now emit the command error text from the command we just executed
+ if (!result.GetImmediateErrorStream())
+ {
+ const char *error = result.GetErrorData();
+ if (error && error[0])
+ io_handler.GetErrorStreamFile()->PutCString(error);
+ }
+ }
+
+ switch (result.GetStatus())
+ {
+ case eReturnStatusInvalid:
+ case eReturnStatusSuccessFinishNoResult:
+ case eReturnStatusSuccessFinishResult:
+ case eReturnStatusStarted:
+ break;
+
+ case eReturnStatusSuccessContinuingNoResult:
+ case eReturnStatusSuccessContinuingResult:
+ if (io_handler.GetFlags().Test(eHandleCommandFlagStopOnContinue))
+ io_handler.SetIsDone(true);
+ break;
+
+ case eReturnStatusFailed:
+ if (io_handler.GetFlags().Test(eHandleCommandFlagStopOnError))
+ io_handler.SetIsDone(true);
+ break;
+
+ case eReturnStatusQuit:
+ io_handler.SetIsDone(true);
+ break;
+ }
+}
+
+void
+CommandInterpreter::GetLLDBCommandsFromIOHandler (const char *prompt,
+ IOHandlerDelegate &delegate,
+ bool asynchronously,
+ void *baton)
+{
+ Debugger &debugger = GetDebugger();
+ IOHandlerSP io_handler_sp (new IOHandlerEditline (debugger,
+ "lldb", // Name of input reader for history
+ prompt, // Prompt
+ true, // Get multiple lines
+ delegate)); // IOHandlerDelegate
+
+ if (io_handler_sp)
+ {
+ io_handler_sp->SetUserData (baton);
+ if (asynchronously)
+ debugger.PushIOHandler(io_handler_sp);
+ else
+ debugger.RunIOHandler(io_handler_sp);
+ }
+
+}
+
+
+void
+CommandInterpreter::GetPythonCommandsFromIOHandler (const char *prompt,
+ IOHandlerDelegate &delegate,
+ bool asynchronously,
+ void *baton)
+{
+ Debugger &debugger = GetDebugger();
+ IOHandlerSP io_handler_sp (new IOHandlerEditline (debugger,
+ "lldb-python", // Name of input reader for history
+ prompt, // Prompt
+ true, // Get multiple lines
+ delegate)); // IOHandlerDelegate
+
+ if (io_handler_sp)
+ {
+ io_handler_sp->SetUserData (baton);
+ if (asynchronously)
+ debugger.PushIOHandler(io_handler_sp);
+ else
+ debugger.RunIOHandler(io_handler_sp);
+ }
+
+}
+
+bool
+CommandInterpreter::IsActive ()
+{
+ return m_debugger.IsTopIOHandler (m_command_io_handler_sp);
+}
+
+void
+CommandInterpreter::RunCommandInterpreter(bool auto_handle_events,
+ bool spawn_thread)
+{
+ const bool multiple_lines = false; // Only get one line at a time
+ if (!m_command_io_handler_sp)
+ m_command_io_handler_sp.reset(new IOHandlerEditline (m_debugger,
+ m_debugger.GetInputFile(),
+ m_debugger.GetOutputFile(),
+ m_debugger.GetErrorFile(),
+ eHandleCommandFlagEchoCommand | eHandleCommandFlagPrintResult,
+ "lldb",
+ m_debugger.GetPrompt(),
+ multiple_lines,
+ *this));
+ m_debugger.PushIOHandler(m_command_io_handler_sp);
+
+ if (auto_handle_events)
+ m_debugger.StartEventHandlerThread();
+
+ if (spawn_thread)
+ {
+ m_debugger.StartIOHandlerThread();
+ }
+ else
+ {
+ m_debugger.ExecuteIOHanders();
+
+ if (auto_handle_events)
+ m_debugger.StopEventHandlerThread();
+ }
+
+}
+
diff --git a/source/Interpreter/CommandObject.cpp b/source/Interpreter/CommandObject.cpp
index c71ca28b0330..c6995366c87a 100644
--- a/source/Interpreter/CommandObject.cpp
+++ b/source/Interpreter/CommandObject.cpp
@@ -261,13 +261,7 @@ CommandObject::CheckRequirements (CommandReturnObject &result)
{
Target *target = m_exe_ctx.GetTargetPtr();
if (target)
- {
- if (m_api_locker.TryLock (target->GetAPIMutex(), NULL) == false)
- {
- result.AppendError ("failed to get API lock");
- return false;
- }
- }
+ m_api_locker.Lock (target->GetAPIMutex());
}
}
diff --git a/source/Interpreter/Options.cpp b/source/Interpreter/Options.cpp
index 8d245cc15daa..c6c66d8ac650 100644
--- a/source/Interpreter/Options.cpp
+++ b/source/Interpreter/Options.cpp
@@ -952,7 +952,7 @@ Options::HandleOptionArgumentCompletion
// If this is the "shlib" option and there was an argument provided,
// restrict it to that shared library.
- if (strcmp(cur_opt_name, "shlib") == 0 && cur_arg_pos != -1)
+ if (cur_opt_name && strcmp(cur_opt_name, "shlib") == 0 && cur_arg_pos != -1)
{
const char *module_name = input.GetArgumentAtIndex(cur_arg_pos);
if (module_name)
diff --git a/source/Interpreter/PythonDataObjects.cpp b/source/Interpreter/PythonDataObjects.cpp
index 1e2bd2391191..01f2754a2cc9 100644
--- a/source/Interpreter/PythonDataObjects.cpp
+++ b/source/Interpreter/PythonDataObjects.cpp
@@ -97,7 +97,7 @@ PythonString::PythonString (PyObject *py_obj) :
PythonString::PythonString (const PythonObject &object) :
PythonObject()
{
- Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a string
+ Reset(object.get()); // Use "Reset()" to ensure that py_obj is a string
}
PythonString::PythonString (const lldb::ScriptInterpreterObjectSP &script_object_sp) :
@@ -166,7 +166,7 @@ PythonInteger::PythonInteger (PyObject *py_obj) :
PythonInteger::PythonInteger (const PythonObject &object) :
PythonObject()
{
- Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a integer type
+ Reset(object.get()); // Use "Reset()" to ensure that py_obj is a integer type
}
PythonInteger::PythonInteger (const lldb::ScriptInterpreterObjectSP &script_object_sp) :
@@ -223,8 +223,8 @@ PythonInteger::SetInteger (int64_t value)
// PythonList
//----------------------------------------------------------------------
-PythonList::PythonList () :
- PythonObject(PyList_New(0))
+PythonList::PythonList (bool create_empty) :
+ PythonObject(create_empty ? PyList_New(0) : NULL)
{
}
@@ -243,7 +243,7 @@ PythonList::PythonList (PyObject *py_obj) :
PythonList::PythonList (const PythonObject &object) :
PythonObject()
{
- Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a list
+ Reset(object.get()); // Use "Reset()" to ensure that py_obj is a list
}
PythonList::PythonList (const lldb::ScriptInterpreterObjectSP &script_object_sp) :
@@ -280,29 +280,29 @@ PythonList::GetItemAtIndex (uint32_t index)
{
if (m_py_obj)
return PythonObject(PyList_GetItem(m_py_obj, index));
- return NULL;
+ return PythonObject();
}
void
PythonList::SetItemAtIndex (uint32_t index, const PythonObject & object)
{
if (m_py_obj && object)
- PyList_SetItem(m_py_obj, index, object.GetPythonObject());
+ PyList_SetItem(m_py_obj, index, object.get());
}
void
PythonList::AppendItem (const PythonObject &object)
{
if (m_py_obj && object)
- PyList_Append(m_py_obj, object.GetPythonObject());
+ PyList_Append(m_py_obj, object.get());
}
//----------------------------------------------------------------------
// PythonDictionary
//----------------------------------------------------------------------
-PythonDictionary::PythonDictionary () :
- PythonObject(PyDict_New())
+PythonDictionary::PythonDictionary (bool create_empty) :
+PythonObject(create_empty ? PyDict_New() : NULL)
{
}
@@ -316,7 +316,7 @@ PythonDictionary::PythonDictionary (PyObject *py_obj) :
PythonDictionary::PythonDictionary (const PythonObject &object) :
PythonObject()
{
- Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a dictionary
+ Reset(object.get()); // Use "Reset()" to ensure that py_obj is a dictionary
}
PythonDictionary::PythonDictionary (const lldb::ScriptInterpreterObjectSP &script_object_sp) :
@@ -356,7 +356,7 @@ PythonDictionary::GetItemForKey (const char *key) const
PythonString python_key(key);
return GetItemForKey(python_key);
}
- return NULL;
+ return PythonObject();
}
@@ -364,7 +364,7 @@ PythonObject
PythonDictionary::GetItemForKey (const PythonString &key) const
{
if (m_py_obj && key)
- return PythonObject(PyDict_GetItem(m_py_obj, key.GetPythonObject()));
+ return PythonObject(PyDict_GetItem(m_py_obj, key.get()));
return PythonObject();
}
@@ -374,7 +374,7 @@ PythonDictionary::GetItemForKeyAsString (const PythonString &key, const char *fa
{
if (m_py_obj && key)
{
- PyObject *py_obj = PyDict_GetItem(m_py_obj, key.GetPythonObject());
+ PyObject *py_obj = PyDict_GetItem(m_py_obj, key.get());
if (py_obj && PyString_Check(py_obj))
return PyString_AsString(py_obj);
}
@@ -386,7 +386,7 @@ PythonDictionary::GetItemForKeyAsInteger (const PythonString &key, int64_t fail_
{
if (m_py_obj && key)
{
- PyObject *py_obj = PyDict_GetItem(m_py_obj, key.GetPythonObject());
+ PyObject *py_obj = PyDict_GetItem(m_py_obj, key.get());
if (py_obj)
{
if (PyInt_Check(py_obj))
@@ -404,7 +404,7 @@ PythonDictionary::GetKeys () const
{
if (m_py_obj)
return PythonList(PyDict_Keys(m_py_obj));
- return PythonList();
+ return PythonList(true);
}
PythonString
@@ -431,7 +431,7 @@ PythonDictionary::GetValueAtPosition (uint32_t pos) const
Py_ssize_t pos_iter = 0;
if (!m_py_obj)
- return NULL;
+ return PythonObject();
while (PyDict_Next(m_py_obj, &pos_iter, &key, &value)) {
if (pos-- == 0)
@@ -441,10 +441,17 @@ PythonDictionary::GetValueAtPosition (uint32_t pos) const
}
void
+PythonDictionary::SetItemForKey (const PythonString &key, PyObject *value)
+{
+ if (m_py_obj && key && value)
+ PyDict_SetItem(m_py_obj, key.get(), value);
+}
+
+void
PythonDictionary::SetItemForKey (const PythonString &key, const PythonObject &value)
{
if (m_py_obj && key && value)
- PyDict_SetItem(m_py_obj, key.GetPythonObject(), value.GetPythonObject());
+ PyDict_SetItem(m_py_obj, key.get(), value.get());
}
#endif
diff --git a/source/Interpreter/ScriptInterpreterNone.cpp b/source/Interpreter/ScriptInterpreterNone.cpp
index 6a4411494c43..e33480d1a6d5 100644
--- a/source/Interpreter/ScriptInterpreterNone.cpp
+++ b/source/Interpreter/ScriptInterpreterNone.cpp
@@ -11,6 +11,7 @@
#include "lldb/Interpreter/ScriptInterpreterNone.h"
#include "lldb/Core/Stream.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StringList.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Interpreter/CommandInterpreter.h"
@@ -30,14 +31,14 @@ ScriptInterpreterNone::~ScriptInterpreterNone ()
bool
ScriptInterpreterNone::ExecuteOneLine (const char *command, CommandReturnObject *, const ExecuteScriptOptions&)
{
- m_interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n");
+ m_interpreter.GetDebugger().GetErrorFile()->PutCString ("error: there is no embedded script interpreter in this mode.\n");
return false;
}
void
ScriptInterpreterNone::ExecuteInterpreterLoop ()
{
- m_interpreter.GetDebugger().GetErrorStream().PutCString ("error: there is no embedded script interpreter in this mode.\n");
+ m_interpreter.GetDebugger().GetErrorFile()->PutCString ("error: there is no embedded script interpreter in this mode.\n");
}
diff --git a/source/Interpreter/ScriptInterpreterPython.cpp b/source/Interpreter/ScriptInterpreterPython.cpp
index fb60fedbe94b..624a662e26bf 100644
--- a/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/source/Interpreter/ScriptInterpreterPython.cpp
@@ -27,11 +27,14 @@
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Breakpoint/WatchpointOptions.h"
+#include "lldb/Core/Communication.h"
+#include "lldb/Core/ConnectionFileDescriptor.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Timer.h"
#include "lldb/Host/Host.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/PythonDataObjects.h"
#include "lldb/Target/Thread.h"
using namespace lldb;
@@ -66,22 +69,23 @@ _check_and_flush (FILE *stream)
return fflush (stream) || prev_fail ? EOF : 0;
}
+static std::string
+ReadPythonBacktrace (PyObject* py_backtrace);
+
ScriptInterpreterPython::Locker::Locker (ScriptInterpreterPython *py_interpreter,
uint16_t on_entry,
uint16_t on_leave,
- FILE* wait_msg_handle) :
+ FILE *in,
+ FILE *out,
+ FILE *err) :
ScriptInterpreterLocker (),
m_teardown_session( (on_leave & TearDownSession) == TearDownSession ),
- m_python_interpreter(py_interpreter),
- m_tmp_fh(wait_msg_handle)
+ m_python_interpreter(py_interpreter)
{
- if (m_python_interpreter && !m_tmp_fh)
- m_tmp_fh = (m_python_interpreter->m_dbg_stdout ? m_python_interpreter->m_dbg_stdout : stdout);
-
DoAcquireLock();
if ((on_entry & InitSession) == InitSession)
{
- if (DoInitSession((on_entry & InitGlobals) == InitGlobals) == false)
+ if (DoInitSession(on_entry, in, out, err) == false)
{
// Don't teardown the session if we didn't init it.
m_teardown_session = false;
@@ -100,11 +104,11 @@ ScriptInterpreterPython::Locker::DoAcquireLock()
}
bool
-ScriptInterpreterPython::Locker::DoInitSession(bool init_lldb_globals)
+ScriptInterpreterPython::Locker::DoInitSession(uint16_t on_entry_flags, FILE *in, FILE *out, FILE *err)
{
if (!m_python_interpreter)
return false;
- return m_python_interpreter->EnterSession (init_lldb_globals);
+ return m_python_interpreter->EnterSession (on_entry_flags, in, out, err);
}
bool
@@ -133,268 +137,29 @@ ScriptInterpreterPython::Locker::~Locker()
DoFreeLock();
}
-ScriptInterpreterPython::PythonInputReaderManager::PythonInputReaderManager (ScriptInterpreterPython *interpreter) :
-m_interpreter(interpreter),
-m_debugger_sp(),
-m_reader_sp(),
-m_error(false)
-{
- if (m_interpreter == NULL)
- {
- m_error = true;
- return;
- }
-
- m_debugger_sp = m_interpreter->GetCommandInterpreter().GetDebugger().shared_from_this();
-
- if (!m_debugger_sp)
- {
- m_error = true;
- return;
- }
-
- m_reader_sp = InputReaderSP(new InputReader(*m_debugger_sp.get()));
-
- if (!m_reader_sp)
- {
- m_error = true;
- return;
- }
-
- Error error (m_reader_sp->Initialize (ScriptInterpreterPython::PythonInputReaderManager::InputReaderCallback,
- m_interpreter, // baton
- eInputReaderGranularityLine, // token size, to pass to callback function
- NULL, // end token
- NULL, // prompt
- true)); // echo input
- if (error.Fail())
- m_error = true;
- else
- {
- m_debugger_sp->PushInputReader (m_reader_sp);
- m_interpreter->m_embedded_thread_input_reader_sp = m_reader_sp;
- }
-}
-
-ScriptInterpreterPython::PythonInputReaderManager::~PythonInputReaderManager()
-{
- // Nothing to do if either m_interpreter or m_reader_sp is invalid.
- if (!m_interpreter || !m_reader_sp)
- return;
-
- m_reader_sp->SetIsDone (true);
- if (m_debugger_sp)
- m_debugger_sp->PopInputReader(m_reader_sp);
-
- // Only mess with m_interpreter's counterpart if, indeed, they are the same object.
- if (m_reader_sp.get() == m_interpreter->m_embedded_thread_input_reader_sp.get())
- {
- m_interpreter->m_embedded_thread_pty.CloseSlaveFileDescriptor();
- m_interpreter->m_embedded_thread_input_reader_sp.reset();
- }
-}
-
-size_t
-ScriptInterpreterPython::PythonInputReaderManager::InputReaderCallback (void *baton,
- InputReader &reader,
- InputReaderAction notification,
- const char *bytes,
- size_t bytes_len)
-{
- lldb::thread_t embedded_interpreter_thread;
- Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SCRIPT));
-
- if (baton == NULL)
- return 0;
-
- ScriptInterpreterPython *script_interpreter = (ScriptInterpreterPython *) baton;
-
- if (script_interpreter->m_script_lang != eScriptLanguagePython)
- return 0;
-
- switch (notification)
- {
- case eInputReaderActivate:
- {
- // Save terminal settings if we can
- int input_fd = reader.GetDebugger().GetInputFile().GetDescriptor();
- if (input_fd == File::kInvalidDescriptor)
- input_fd = STDIN_FILENO;
-
- script_interpreter->SaveTerminalState(input_fd);
-
- char error_str[1024];
- if (script_interpreter->m_embedded_thread_pty.OpenFirstAvailableMaster (O_RDWR|O_NOCTTY, error_str,
- sizeof(error_str)))
- {
- if (log)
- log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, Activate, succeeded in opening master pty (fd = %d).",
- script_interpreter->m_embedded_thread_pty.GetMasterFileDescriptor());
- {
- StreamString run_string;
- char error_str[1024];
- const char *pty_slave_name = script_interpreter->m_embedded_thread_pty.GetSlaveName (error_str, sizeof (error_str));
- if (pty_slave_name != NULL && PyThreadState_GetDict() != NULL)
- {
- ScriptInterpreterPython::Locker locker(script_interpreter,
- ScriptInterpreterPython::Locker::AcquireLock | ScriptInterpreterPython::Locker::InitSession | ScriptInterpreterPython::Locker::InitGlobals,
- ScriptInterpreterPython::Locker::FreeAcquiredLock);
- run_string.Printf ("run_one_line (%s, 'save_stderr = sys.stderr')", script_interpreter->m_dictionary_name.c_str());
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear ();
-
- run_string.Printf ("run_one_line (%s, 'sys.stderr = sys.stdout')", script_interpreter->m_dictionary_name.c_str());
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear ();
-
- run_string.Printf ("run_one_line (%s, 'save_stdin = sys.stdin')", script_interpreter->m_dictionary_name.c_str());
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear ();
-
- run_string.Printf ("run_one_line (%s, \"sys.stdin = open ('%s', 'r')\")", script_interpreter->m_dictionary_name.c_str(),
- pty_slave_name);
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear ();
- }
- }
- embedded_interpreter_thread = Host::ThreadCreate ("<lldb.script-interpreter.noninteractive-python>",
- ScriptInterpreterPython::PythonInputReaderManager::RunPythonInputReader,
- script_interpreter, NULL);
- if (IS_VALID_LLDB_HOST_THREAD(embedded_interpreter_thread))
- {
- if (log)
- log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, Activate, succeeded in creating thread (thread_t = %p)", (void *)embedded_interpreter_thread);
- Error detach_error;
- Host::ThreadDetach (embedded_interpreter_thread, &detach_error);
- }
- else
- {
- if (log)
- log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, Activate, failed in creating thread");
- reader.SetIsDone (true);
- }
- }
- else
- {
- if (log)
- log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, Activate, failed to open master pty ");
- reader.SetIsDone (true);
- }
- }
- break;
-
- case eInputReaderDeactivate:
- // When another input reader is pushed, don't leave the session...
- //script_interpreter->LeaveSession ();
- break;
-
- case eInputReaderReactivate:
-// {
-// ScriptInterpreterPython::Locker locker(script_interpreter,
-// ScriptInterpreterPython::Locker::AcquireLock | ScriptInterpreterPython::Locker::InitSession,
-// ScriptInterpreterPython::Locker::FreeAcquiredLock);
-// }
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
-
- case eInputReaderInterrupt:
- {
- PyThreadState* state = _PyThreadState_Current;
- if (!state)
- state = script_interpreter->m_command_thread_state;
- if (state)
- {
- long tid = state->thread_id;
- _PyThreadState_Current = state;
- int num_threads = PyThreadState_SetAsyncExc(tid, PyExc_KeyboardInterrupt);
- if (log)
- log->Printf("ScriptInterpreterPython::NonInteractiveInputReaderCallback, eInputReaderInterrupt, tid = %ld, num_threads = %d, state = %p",
- tid,num_threads,state);
- }
- else if (log)
- log->Printf("ScriptInterpreterPython::NonInteractiveInputReaderCallback, eInputReaderInterrupt, state = NULL");
- }
- break;
-
- case eInputReaderEndOfFile:
- reader.SetIsDone(true);
- break;
-
- case eInputReaderGotToken:
- if (script_interpreter->m_embedded_thread_pty.GetMasterFileDescriptor() != -1)
- {
- if (log)
- log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, GotToken, bytes='%s', byte_len = %zu", bytes,
- bytes_len);
- if (bytes && bytes_len)
- ::write (script_interpreter->m_embedded_thread_pty.GetMasterFileDescriptor(), bytes, bytes_len);
- ::write (script_interpreter->m_embedded_thread_pty.GetMasterFileDescriptor(), "\n", 1);
- }
- else
- {
- if (log)
- log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, GotToken, bytes='%s', byte_len = %zu, Master File Descriptor is bad.",
- bytes,
- bytes_len);
- reader.SetIsDone (true);
- }
- break;
-
- case eInputReaderDone:
- {
- StreamString run_string;
- char error_str[1024];
- const char *pty_slave_name = script_interpreter->m_embedded_thread_pty.GetSlaveName (error_str, sizeof (error_str));
- if (pty_slave_name != NULL && PyThreadState_GetDict() != NULL)
- {
- ScriptInterpreterPython::Locker locker(script_interpreter,
- ScriptInterpreterPython::Locker::AcquireLock,
- ScriptInterpreterPython::Locker::FreeAcquiredLock);
- run_string.Printf ("run_one_line (%s, 'sys.stdin = save_stdin; sys.stderr = save_stderr')", script_interpreter->m_dictionary_name.c_str());
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear();
- }
- // Restore terminal settings if they were validly saved
- if (log)
- log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, Done, closing down input reader.");
-
- script_interpreter->RestoreTerminalState ();
-
- script_interpreter->m_embedded_thread_pty.CloseMasterFileDescriptor();
- }
- break;
- }
-
- return bytes_len;
-}
ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interpreter) :
ScriptInterpreter (interpreter, eScriptLanguagePython),
- m_embedded_thread_pty (),
- m_embedded_python_pty (),
- m_embedded_thread_input_reader_sp (),
- m_embedded_python_input_reader_sp (),
- m_dbg_stdout (interpreter.GetDebugger().GetOutputFile().GetStream()),
- m_new_sysout (NULL),
- m_old_sysout (NULL),
- m_old_syserr (NULL),
- m_run_one_line (NULL),
+ IOHandlerDelegateMultiline("DONE"),
+ m_saved_stdin (),
+ m_saved_stdout (),
+ m_saved_stderr (),
+ m_main_module (),
+ m_lldb_module (),
+ m_session_dict (false), // Don't create an empty dictionary, leave it invalid
+ m_sys_module_dict (false), // Don't create an empty dictionary, leave it invalid
+ m_run_one_line_function (),
+ m_run_one_line_str_global (),
m_dictionary_name (interpreter.GetDebugger().GetInstanceName().AsCString()),
m_terminal_state (),
+ m_active_io_handler (eIOHandlerNone),
m_session_is_active (false),
+ m_pty_slave_is_open (false),
m_valid_session (true),
m_command_thread_state (NULL)
{
- static int g_initialized = false;
-
- if (!g_initialized)
- {
- g_initialized = true;
- ScriptInterpreterPython::InitializePrivate ();
- }
+ ScriptInterpreterPython::InitializePrivate ();
m_dictionary_name.append("_dict");
StreamString run_string;
@@ -425,72 +190,130 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete
run_string.Clear();
run_string.Printf ("run_one_line (%s, 'import lldb.formatters, lldb.formatters.cpp, pydoc')", m_dictionary_name.c_str());
PyRun_SimpleString (run_string.GetData());
+ run_string.Clear();
int new_count = Debugger::TestDebuggerRefCount();
if (new_count > old_count)
Debugger::Terminate();
+ run_string.Printf ("run_one_line (%s, 'import lldb.embedded_interpreter; from lldb.embedded_interpreter import run_python_interpreter; from lldb.embedded_interpreter import run_one_line')", m_dictionary_name.c_str());
+ PyRun_SimpleString (run_string.GetData());
run_string.Clear();
+
run_string.Printf ("run_one_line (%s, 'lldb.debugger_unique_id = %" PRIu64 "; pydoc.pager = pydoc.plainpager')", m_dictionary_name.c_str(),
interpreter.GetDebugger().GetID());
PyRun_SimpleString (run_string.GetData());
-
- if (m_dbg_stdout != NULL)
- {
- m_new_sysout = PyFile_FromFile (m_dbg_stdout, (char *) "", (char *) "w", _check_and_flush);
- }
-
- // get the output file handle from the debugger (if any)
- File& out_file = interpreter.GetDebugger().GetOutputFile();
- if (out_file.IsValid())
- ResetOutputFileHandle(out_file.GetStream());
}
ScriptInterpreterPython::~ScriptInterpreterPython ()
{
- Debugger &debugger = GetCommandInterpreter().GetDebugger();
+}
- if (m_embedded_thread_input_reader_sp.get() != NULL)
- {
- m_embedded_thread_input_reader_sp->SetIsDone (true);
- m_embedded_thread_pty.CloseSlaveFileDescriptor();
- const InputReaderSP reader_sp = m_embedded_thread_input_reader_sp;
- debugger.PopInputReader (reader_sp);
- m_embedded_thread_input_reader_sp.reset();
- }
+void
+ScriptInterpreterPython::IOHandlerActivated (IOHandler &io_handler)
+{
+ const char *instructions = NULL;
- if (m_embedded_python_input_reader_sp.get() != NULL)
+ switch (m_active_io_handler)
{
- m_embedded_python_input_reader_sp->SetIsDone (true);
- m_embedded_python_pty.CloseSlaveFileDescriptor();
- const InputReaderSP reader_sp = m_embedded_python_input_reader_sp;
- debugger.PopInputReader (reader_sp);
- m_embedded_python_input_reader_sp.reset();
+ case eIOHandlerNone:
+ break;
+ case eIOHandlerBreakpoint:
+ instructions = R"(Enter your Python command(s). Type 'DONE' to end.
+def function (frame, bp_loc, internal_dict):
+ """frame: the lldb.SBFrame for the location at which you stopped
+ bp_loc: an lldb.SBBreakpointLocation for the breakpoint location information
+ internal_dict: an LLDB support object not to be used"""
+)";
+ break;
+ case eIOHandlerWatchpoint:
+ instructions = "Enter your Python command(s). Type 'DONE' to end.\n";
+ break;
}
- if (m_new_sysout)
+ if (instructions)
{
- Locker locker(this,
- ScriptInterpreterPython::Locker::AcquireLock,
- ScriptInterpreterPython::Locker::FreeLock);
- Py_XDECREF ((PyObject*)m_new_sysout);
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp)
+ {
+ output_sp->PutCString(instructions);
+ output_sp->Flush();
+ }
}
}
void
-ScriptInterpreterPython::ResetOutputFileHandle (FILE *fh)
+ScriptInterpreterPython::IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
{
- if (fh == NULL)
- return;
-
- m_dbg_stdout = fh;
+ io_handler.SetIsDone(true);
+ bool batch_mode = m_interpreter.GetBatchCommandMode();
+
+ switch (m_active_io_handler)
+ {
+ case eIOHandlerNone:
+ break;
+ case eIOHandlerBreakpoint:
+ {
+ BreakpointOptions *bp_options = (BreakpointOptions *)io_handler.GetUserData();
+ std::unique_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());
+ if (data_ap.get())
+ {
+ data_ap->user_source.SplitIntoLines(data);
+
+ if (GenerateBreakpointCommandCallbackData (data_ap->user_source, data_ap->script_source))
+ {
+ BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release()));
+ bp_options->SetCallback (ScriptInterpreterPython::BreakpointCallbackFunction, baton_sp);
+ }
+ else if (!batch_mode)
+ {
+ StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+ if (error_sp)
+ {
+ error_sp->Printf ("Warning: No command attached to breakpoint.\n");
+ error_sp->Flush();
+ }
+ }
+ }
+ m_active_io_handler = eIOHandlerNone;
+ }
+ break;
+ case eIOHandlerWatchpoint:
+ {
+ WatchpointOptions *wp_options = (WatchpointOptions *)io_handler.GetUserData();
+ std::unique_ptr<WatchpointOptions::CommandData> data_ap(new WatchpointOptions::CommandData());
+ if (data_ap.get())
+ {
+ data_ap->user_source.SplitIntoLines(data);
+
+ if (GenerateWatchpointCommandCallbackData (data_ap->user_source, data_ap->script_source))
+ {
+ BatonSP baton_sp (new WatchpointOptions::CommandBaton (data_ap.release()));
+ wp_options->SetCallback (ScriptInterpreterPython::WatchpointCallbackFunction, baton_sp);
+ }
+ else if (!batch_mode)
+ {
+ StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+ if (error_sp)
+ {
+ error_sp->Printf ("Warning: No command attached to breakpoint.\n");
+ error_sp->Flush();
+ }
+ }
+ }
+ m_active_io_handler = eIOHandlerNone;
+ }
+ break;
+ }
- Locker locker(this,
- ScriptInterpreterPython::Locker::AcquireLock,
- ScriptInterpreterPython::Locker::FreeAcquiredLock);
- m_new_sysout = PyFile_FromFile (m_dbg_stdout, (char *) "", (char *) "w", _check_and_flush);
+}
+
+
+void
+ScriptInterpreterPython::ResetOutputFileHandle (FILE *fh)
+{
}
void
@@ -529,15 +352,24 @@ ScriptInterpreterPython::LeaveSession ()
// When the current thread state is NULL, PyThreadState_Get() issues a fatal error.
if (PyThreadState_GetDict())
{
- PyObject *sysmod = PyImport_AddModule ("sys");
- PyObject *sysdict = PyModule_GetDict (sysmod);
-
- if (m_new_sysout && sysmod && sysdict)
+ PythonDictionary &sys_module_dict = GetSysModuleDictionary ();
+ if (sys_module_dict)
{
- if (m_old_sysout)
- PyDict_SetItemString (sysdict, "stdout", (PyObject*)m_old_sysout);
- if (m_old_syserr)
- PyDict_SetItemString (sysdict, "stderr", (PyObject*)m_old_syserr);
+ if (m_saved_stdin)
+ {
+ sys_module_dict.SetItemForKey("stdin", m_saved_stdin);
+ m_saved_stdin.Reset ();
+ }
+ if (m_saved_stdout)
+ {
+ sys_module_dict.SetItemForKey("stdout", m_saved_stdout);
+ m_saved_stdout.Reset ();
+ }
+ if (m_saved_stderr)
+ {
+ sys_module_dict.SetItemForKey("stderr", m_saved_stderr);
+ m_saved_stderr.Reset ();
+ }
}
}
@@ -545,7 +377,10 @@ ScriptInterpreterPython::LeaveSession ()
}
bool
-ScriptInterpreterPython::EnterSession (bool init_lldb_globals)
+ScriptInterpreterPython::EnterSession (uint16_t on_entry_flags,
+ FILE *in,
+ FILE *out,
+ FILE *err)
{
// If we have already entered the session, without having officially 'left' it, then there is no need to
// 'enter' it again.
@@ -553,19 +388,19 @@ ScriptInterpreterPython::EnterSession (bool init_lldb_globals)
if (m_session_is_active)
{
if (log)
- log->Printf("ScriptInterpreterPython::EnterSession(init_lldb_globals=%i) session is already active, returning without doing anything", init_lldb_globals);
+ log->Printf("ScriptInterpreterPython::EnterSession(on_entry_flags=0x%" PRIx16 ") session is already active, returning without doing anything", on_entry_flags);
return false;
}
if (log)
- log->Printf("ScriptInterpreterPython::EnterSession(init_lldb_globals=%i)", init_lldb_globals);
+ log->Printf("ScriptInterpreterPython::EnterSession(on_entry_flags=0x%" PRIx16 ")", on_entry_flags);
m_session_is_active = true;
StreamString run_string;
- if (init_lldb_globals)
+ if (on_entry_flags & Locker::InitGlobals)
{
run_string.Printf ( "run_one_line (%s, 'lldb.debugger_unique_id = %" PRIu64, m_dictionary_name.c_str(), GetCommandInterpreter().GetDebugger().GetID());
run_string.Printf ( "; lldb.debugger = lldb.SBDebugger.FindDebuggerWithID (%" PRIu64 ")", GetCommandInterpreter().GetDebugger().GetID());
@@ -578,26 +413,61 @@ ScriptInterpreterPython::EnterSession (bool init_lldb_globals)
else
{
// If we aren't initing the globals, we should still always set the debugger (since that is always unique.)
- run_string.Printf ( "run_one_line (%s, \"lldb.debugger_unique_id = %" PRIu64, m_dictionary_name.c_str(), GetCommandInterpreter().GetDebugger().GetID());
+ run_string.Printf ( "run_one_line (%s, 'lldb.debugger_unique_id = %" PRIu64, m_dictionary_name.c_str(), GetCommandInterpreter().GetDebugger().GetID());
run_string.Printf ( "; lldb.debugger = lldb.SBDebugger.FindDebuggerWithID (%" PRIu64 ")", GetCommandInterpreter().GetDebugger().GetID());
- run_string.PutCString ("\")");
+ run_string.PutCString ("')");
}
PyRun_SimpleString (run_string.GetData());
run_string.Clear();
- PyObject *sysmod = PyImport_AddModule ("sys");
- PyObject *sysdict = PyModule_GetDict (sysmod);
-
- if (m_new_sysout && sysmod && sysdict)
+ PythonDictionary &sys_module_dict = GetSysModuleDictionary ();
+ if (sys_module_dict)
{
- m_old_sysout = PyDict_GetItemString(sysdict, "stdout");
- m_old_syserr = PyDict_GetItemString(sysdict, "stderr");
- if (m_new_sysout)
+ lldb::StreamFileSP in_sp;
+ lldb::StreamFileSP out_sp;
+ lldb::StreamFileSP err_sp;
+ if (in == NULL || out == NULL || err == NULL)
+ m_interpreter.GetDebugger().AdoptTopIOHandlerFilesIfInvalid (in_sp, out_sp, err_sp);
+
+ if (in == NULL && in_sp && (on_entry_flags & Locker::NoSTDIN) == 0)
+ in = in_sp->GetFile().GetStream();
+ if (in)
{
- PyDict_SetItemString (sysdict, "stdout", (PyObject*)m_new_sysout);
- PyDict_SetItemString (sysdict, "stderr", (PyObject*)m_new_sysout);
+ m_saved_stdin.Reset(sys_module_dict.GetItemForKey("stdin"));
+
+ PyObject *new_file = PyFile_FromFile (in, (char *) "", (char *) "r", 0);
+ sys_module_dict.SetItemForKey ("stdin", new_file);
+ Py_DECREF (new_file);
}
+ else
+ m_saved_stdin.Reset();
+
+ if (out == NULL && out_sp)
+ out = out_sp->GetFile().GetStream();
+ if (out)
+ {
+ m_saved_stdout.Reset(sys_module_dict.GetItemForKey("stdout"));
+
+ PyObject *new_file = PyFile_FromFile (out, (char *) "", (char *) "w", 0);
+ sys_module_dict.SetItemForKey ("stdout", new_file);
+ Py_DECREF (new_file);
+ }
+ else
+ m_saved_stdout.Reset();
+
+ if (err == NULL && err_sp)
+ err = err_sp->GetFile().GetStream();
+ if (err)
+ {
+ m_saved_stderr.Reset(sys_module_dict.GetItemForKey("stderr"));
+
+ PyObject *new_file = PyFile_FromFile (err, (char *) "", (char *) "w", 0);
+ sys_module_dict.SetItemForKey ("stderr", new_file);
+ Py_DECREF (new_file);
+ }
+ else
+ m_saved_stderr.Reset();
}
if (PyErr_Occurred())
@@ -606,44 +476,42 @@ ScriptInterpreterPython::EnterSession (bool init_lldb_globals)
return true;
}
-static PyObject*
-FindSessionDictionary (const char* dict_name)
+PythonObject &
+ScriptInterpreterPython::GetMainModule ()
{
- static std::map<ConstString,PyObject*> g_dict_map;
-
- ConstString dict(dict_name);
-
- std::map<ConstString,PyObject*>::iterator iter = g_dict_map.find(dict);
-
- if (iter != g_dict_map.end())
- return iter->second;
-
- PyObject *main_mod = PyImport_AddModule ("__main__");
- if (main_mod != NULL)
+ if (!m_main_module)
+ m_main_module.Reset(PyImport_AddModule ("__main__"));
+ return m_main_module;
+}
+
+PythonDictionary &
+ScriptInterpreterPython::GetSessionDictionary ()
+{
+ if (!m_session_dict)
{
- PyObject *main_dict = PyModule_GetDict (main_mod);
- if ((main_dict != NULL)
- && PyDict_Check (main_dict))
+ PythonObject &main_module = GetMainModule ();
+ if (main_module)
{
- // Go through the main dictionary looking for the correct python script interpreter dictionary
- PyObject *key, *value;
- Py_ssize_t pos = 0;
-
- while (PyDict_Next (main_dict, &pos, &key, &value))
+ PythonDictionary main_dict(PyModule_GetDict (main_module.get()));
+ if (main_dict)
{
- // We have stolen references to the key and value objects in the dictionary; we need to increment
- // them now so that Python's garbage collector doesn't collect them out from under us.
- Py_INCREF (key);
- Py_INCREF (value);
- if (strcmp (PyString_AsString (key), dict_name) == 0)
- {
- g_dict_map[dict] = value;
- return value;
- }
+ m_session_dict = main_dict.GetItemForKey(m_dictionary_name.c_str());
}
}
}
- return NULL;
+ return m_session_dict;
+}
+
+PythonDictionary &
+ScriptInterpreterPython::GetSysModuleDictionary ()
+{
+ if (!m_sys_module_dict)
+ {
+ PyObject *sys_module = PyImport_AddModule ("sys");
+ if (sys_module)
+ m_sys_module_dict.Reset(PyModule_GetDict (sys_module));
+ }
+ return m_sys_module_dict;
}
static std::string
@@ -665,82 +533,154 @@ GenerateUniqueName (const char* base_name_wanted,
}
bool
+ScriptInterpreterPython::GetEmbeddedInterpreterModuleObjects ()
+{
+ if (!m_run_one_line_function)
+ {
+ PyObject *module = PyImport_AddModule ("lldb.embedded_interpreter");
+ if (module != NULL)
+ {
+ PythonDictionary module_dict (PyModule_GetDict (module));
+ if (module_dict)
+ {
+ m_run_one_line_function = module_dict.GetItemForKey("run_one_line");
+ m_run_one_line_str_global = module_dict.GetItemForKey("g_run_one_line_str");
+ }
+ }
+ }
+ return (bool)m_run_one_line_function;
+}
+
+static void
+ReadThreadBytesReceived(void *baton, const void *src, size_t src_len)
+{
+ if (src && src_len)
+ {
+ Stream *strm = (Stream *)baton;
+ strm->Write(src, src_len);
+ strm->Flush();
+ }
+}
+
+bool
ScriptInterpreterPython::ExecuteOneLine (const char *command, CommandReturnObject *result, const ExecuteScriptOptions &options)
{
if (!m_valid_session)
return false;
-
- // We want to call run_one_line, passing in the dictionary and the command string. We cannot do this through
- // PyRun_SimpleString here because the command string may contain escaped characters, and putting it inside
- // another string to pass to PyRun_SimpleString messes up the escaping. So we use the following more complicated
- // method to pass the command string directly down to Python.
-
- Locker locker(this,
- ScriptInterpreterPython::Locker::AcquireLock | ScriptInterpreterPython::Locker::InitSession | (options.GetSetLLDBGlobals() ? ScriptInterpreterPython::Locker::InitGlobals : 0),
- ScriptInterpreterPython::Locker::FreeAcquiredLock | ScriptInterpreterPython::Locker::TearDownSession);
-
- bool success = false;
-
- if (command)
+
+ if (command && command[0])
{
- // Find the correct script interpreter dictionary in the main module.
- PyObject *script_interpreter_dict = FindSessionDictionary(m_dictionary_name.c_str());
- if (script_interpreter_dict != NULL)
+ // We want to call run_one_line, passing in the dictionary and the command string. We cannot do this through
+ // PyRun_SimpleString here because the command string may contain escaped characters, and putting it inside
+ // another string to pass to PyRun_SimpleString messes up the escaping. So we use the following more complicated
+ // method to pass the command string directly down to Python.
+ Debugger &debugger = m_interpreter.GetDebugger();
+
+ StreamFileSP input_file_sp;
+ StreamFileSP output_file_sp;
+ StreamFileSP error_file_sp;
+ Communication output_comm ("lldb.ScriptInterpreterPython.ExecuteOneLine.comm");
+ int pipe_fds[2] = { -1, -1 };
+
+ if (options.GetEnableIO())
{
- PyObject *pfunc = (PyObject*)m_run_one_line;
- PyObject *pmod = PyImport_AddModule ("lldb.embedded_interpreter");
- if (pmod != NULL)
+ if (result)
{
- PyObject *pmod_dict = PyModule_GetDict (pmod);
- if ((pmod_dict != NULL)
- && PyDict_Check (pmod_dict))
+ input_file_sp = debugger.GetInputFile();
+ // Set output to a temporary file so we can forward the results on to the result object
+
+ int err = pipe(pipe_fds);
+ if (err == 0)
{
- if (!pfunc)
+ std::unique_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor(pipe_fds[0], true));
+ if (conn_ap->IsConnected())
{
- PyObject *key, *value;
- Py_ssize_t pos = 0;
+ output_comm.SetConnection(conn_ap.release());
+ output_comm.SetReadThreadBytesReceivedCallback(ReadThreadBytesReceived, &result->GetOutputStream());
+ output_comm.StartReadThread();
+ FILE *outfile_handle = fdopen (pipe_fds[1], "w");
+ output_file_sp.reset(new StreamFile(outfile_handle, true));
+ error_file_sp = output_file_sp;
+ if (outfile_handle)
+ ::setbuf (outfile_handle, NULL);
- while (PyDict_Next (pmod_dict, &pos, &key, &value))
- {
- Py_INCREF (key);
- Py_INCREF (value);
- if (strcmp (PyString_AsString (key), "run_one_line") == 0)
- {
- pfunc = value;
- break;
- }
- }
- m_run_one_line = pfunc;
+ result->SetImmediateOutputFile(debugger.GetOutputFile()->GetFile().GetStream());
+ result->SetImmediateErrorFile(debugger.GetErrorFile()->GetFile().GetStream());
}
-
- if (pfunc && PyCallable_Check (pfunc))
+ }
+ }
+ if (!input_file_sp || !output_file_sp || !error_file_sp)
+ debugger.AdoptTopIOHandlerFilesIfInvalid(input_file_sp, output_file_sp, error_file_sp);
+ }
+ else
+ {
+ input_file_sp.reset (new StreamFile ());
+ input_file_sp->GetFile().Open("/dev/null", File::eOpenOptionRead);
+ output_file_sp.reset (new StreamFile ());
+ output_file_sp->GetFile().Open("/dev/null", File::eOpenOptionWrite);
+ error_file_sp = output_file_sp;
+ }
+
+ FILE *in_file = input_file_sp->GetFile().GetStream();
+ FILE *out_file = output_file_sp->GetFile().GetStream();
+ FILE *err_file = error_file_sp->GetFile().GetStream();
+ Locker locker(this,
+ ScriptInterpreterPython::Locker::AcquireLock |
+ ScriptInterpreterPython::Locker::InitSession |
+ (options.GetSetLLDBGlobals() ? ScriptInterpreterPython::Locker::InitGlobals : 0),
+ ScriptInterpreterPython::Locker::FreeAcquiredLock |
+ ScriptInterpreterPython::Locker::TearDownSession,
+ in_file,
+ out_file,
+ err_file);
+
+ bool success = false;
+
+ // Find the correct script interpreter dictionary in the main module.
+ PythonDictionary &session_dict = GetSessionDictionary ();
+ if (session_dict)
+ {
+ if (GetEmbeddedInterpreterModuleObjects ())
+ {
+ PyObject *pfunc = m_run_one_line_function.get();
+
+ if (pfunc && PyCallable_Check (pfunc))
+ {
+ PythonObject pargs (Py_BuildValue("(Os)", session_dict.get(), command));
+ if (pargs)
{
- PyObject *pargs = Py_BuildValue("(Os)",script_interpreter_dict,command);
- if (pargs != NULL)
+ PythonObject return_value(PyObject_CallObject (pfunc, pargs.get()));
+ if (return_value)
+ success = true;
+ else if (options.GetMaskoutErrors() && PyErr_Occurred ())
{
- PyObject *pvalue = NULL;
- { // scope for PythonInputReaderManager
- PythonInputReaderManager py_input(options.GetEnableIO() ? this : NULL);
- pvalue = PyObject_CallObject (pfunc, pargs);
- }
- Py_XDECREF (pargs);
- if (pvalue != NULL)
- {
- Py_XDECREF (pvalue);
- success = true;
- }
- else if (options.GetMaskoutErrors() && PyErr_Occurred ())
- {
- PyErr_Print();
- PyErr_Clear();
- }
+ PyErr_Print();
+ PyErr_Clear();
}
}
}
}
- Py_INCREF (script_interpreter_dict);
}
+ // Flush our output and error file handles
+ ::fflush (out_file);
+ if (out_file != err_file)
+ ::fflush (err_file);
+
+ if (pipe_fds[0] != -1)
+ {
+ // Close the write end of the pipe since we are done with our
+ // one line script. This should cause the read thread that
+ // output_comm is using to exit
+ output_file_sp->GetFile().Close();
+ // The close above should cause this thread to exit when it gets
+ // to the end of file, so let it get all its data
+ output_comm.JoinReadThread();
+ // Now we can close the read end of the pipe
+ output_comm.Disconnect();
+ }
+
+
if (success)
return true;
@@ -755,155 +695,107 @@ ScriptInterpreterPython::ExecuteOneLine (const char *command, CommandReturnObjec
return false;
}
-size_t
-ScriptInterpreterPython::InputReaderCallback
-(
- void *baton,
- InputReader &reader,
- InputReaderAction notification,
- const char *bytes,
- size_t bytes_len
-)
-{
- lldb::thread_t embedded_interpreter_thread;
- Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SCRIPT));
- if (baton == NULL)
- return 0;
+class IOHandlerPythonInterpreter :
+ public IOHandler
+{
+public:
+
+ IOHandlerPythonInterpreter (Debugger &debugger,
+ ScriptInterpreterPython *python) :
+ IOHandler (debugger),
+ m_python(python)
+ {
- ScriptInterpreterPython *script_interpreter = (ScriptInterpreterPython *) baton;
+ }
- if (script_interpreter->m_script_lang != eScriptLanguagePython)
- return 0;
+ virtual
+ ~IOHandlerPythonInterpreter()
+ {
+
+ }
- switch (notification)
+ virtual ConstString
+ GetControlSequence (char ch)
{
- case eInputReaderActivate:
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
- if (!batch_mode)
- {
- out_stream->Printf ("Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.\n");
- out_stream->Flush();
- }
-
- // Save terminal settings if we can
- int input_fd = reader.GetDebugger().GetInputFile().GetDescriptor();
- if (input_fd == File::kInvalidDescriptor)
- input_fd = STDIN_FILENO;
-
- script_interpreter->SaveTerminalState(input_fd);
-
- {
- ScriptInterpreterPython::Locker locker(script_interpreter,
- ScriptInterpreterPython::Locker::AcquireLock | ScriptInterpreterPython::Locker::InitSession | ScriptInterpreterPython::Locker::InitGlobals,
- ScriptInterpreterPython::Locker::FreeAcquiredLock);
- }
+ if (ch == 'd')
+ return ConstString("quit()\n");
+ return ConstString();
+ }
- char error_str[1024];
- if (script_interpreter->m_embedded_python_pty.OpenFirstAvailableMaster (O_RDWR|O_NOCTTY, error_str,
- sizeof(error_str)))
+ virtual void
+ Run ()
+ {
+ if (m_python)
+ {
+ int stdin_fd = GetInputFD();
+ if (stdin_fd >= 0)
{
- if (log)
- log->Printf ("ScriptInterpreterPython::InputReaderCallback, Activate, succeeded in opening master pty (fd = %d).",
- script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor());
- embedded_interpreter_thread = Host::ThreadCreate ("<lldb.script-interpreter.embedded-python-loop>",
- ScriptInterpreterPython::RunEmbeddedPythonInterpreter,
- script_interpreter, NULL);
- if (IS_VALID_LLDB_HOST_THREAD(embedded_interpreter_thread))
- {
- if (log)
- log->Printf ("ScriptInterpreterPython::InputReaderCallback, Activate, succeeded in creating thread (thread_t = %p)", (void *)embedded_interpreter_thread);
- Error detach_error;
- Host::ThreadDetach (embedded_interpreter_thread, &detach_error);
- }
- else
+ Terminal terminal(stdin_fd);
+ TerminalState terminal_state;
+ const bool is_a_tty = terminal.IsATerminal();
+
+ if (is_a_tty)
{
- if (log)
- log->Printf ("ScriptInterpreterPython::InputReaderCallback, Activate, failed in creating thread");
- reader.SetIsDone (true);
+ terminal_state.Save (stdin_fd, false);
+ terminal.SetCanonical(false);
+ terminal.SetEcho(true);
}
- }
- else
- {
- if (log)
- log->Printf ("ScriptInterpreterPython::InputReaderCallback, Activate, failed to open master pty ");
- reader.SetIsDone (true);
+
+ ScriptInterpreterPython::Locker locker (m_python,
+ ScriptInterpreterPython::Locker::AcquireLock |
+ ScriptInterpreterPython::Locker::InitSession |
+ ScriptInterpreterPython::Locker::InitGlobals,
+ ScriptInterpreterPython::Locker::FreeAcquiredLock |
+ ScriptInterpreterPython::Locker::TearDownSession);
+
+ // The following call drops into the embedded interpreter loop and stays there until the
+ // user chooses to exit from the Python interpreter.
+ // This embedded interpreter will, as any Python code that performs I/O, unlock the GIL before
+ // a system call that can hang, and lock it when the syscall has returned.
+
+ // We need to surround the call to the embedded interpreter with calls to PyGILState_Ensure and
+ // PyGILState_Release (using the Locker above). This is because Python has a global lock which must be held whenever we want
+ // to touch any Python objects. Otherwise, if the user calls Python code, the interpreter state will be off,
+ // and things could hang (it's happened before).
+
+ StreamString run_string;
+ run_string.Printf ("run_python_interpreter (%s)", m_python->GetDictionaryName ());
+ PyRun_SimpleString (run_string.GetData());
+
+ if (is_a_tty)
+ terminal_state.Restore();
}
}
- break;
-
- case eInputReaderDeactivate:
- // When another input reader is pushed, don't leave the session...
- //script_interpreter->LeaveSession ();
- break;
+ SetIsDone(true);
+ }
- case eInputReaderReactivate:
- {
- ScriptInterpreterPython::Locker locker (script_interpreter,
- ScriptInterpreterPython::Locker::AcquireLock | ScriptInterpreterPython::Locker::InitSession,
- ScriptInterpreterPython::Locker::FreeAcquiredLock);
- }
- break;
+ virtual void
+ Hide ()
+ {
- case eInputReaderAsynchronousOutputWritten:
- break;
+ }
+
+ virtual void
+ Refresh ()
+ {
- case eInputReaderInterrupt:
- ::write (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor(), "raise KeyboardInterrupt\n", 24);
- break;
+ }
+
+ virtual void
+ Interrupt ()
+ {
- case eInputReaderEndOfFile:
- ::write (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor(), "quit()\n", 7);
- break;
-
- case eInputReaderGotToken:
- if (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor() != -1)
- {
- if (log)
- log->Printf ("ScriptInterpreterPython::InputReaderCallback, GotToken, bytes='%s', byte_len = %zu", bytes,
- bytes_len);
- if (bytes && bytes_len)
- {
- if ((int) bytes[0] == 4)
- ::write (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor(), "quit()", 6);
- else
- ::write (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor(), bytes, bytes_len);
- }
- ::write (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor(), "\n", 1);
- }
- else
- {
- if (log)
- log->Printf ("ScriptInterpreterPython::InputReaderCallback, GotToken, bytes='%s', byte_len = %zu, Master File Descriptor is bad.",
- bytes,
- bytes_len);
- reader.SetIsDone (true);
- }
-
- break;
+ }
+
+ virtual void
+ GotEOF()
+ {
- case eInputReaderDone:
- {
- Locker locker(script_interpreter,
- ScriptInterpreterPython::Locker::AcquireLock,
- ScriptInterpreterPython::Locker::FreeAcquiredLock);
- script_interpreter->LeaveSession ();
- }
-
- // Restore terminal settings if they were validly saved
- if (log)
- log->Printf ("ScriptInterpreterPython::InputReaderCallback, Done, closing down input reader.");
-
- script_interpreter->RestoreTerminalState ();
-
- script_interpreter->m_embedded_python_pty.CloseMasterFileDescriptor();
- break;
}
-
- return bytes_len;
-}
+protected:
+ ScriptInterpreterPython *m_python;
+};
void
@@ -918,24 +810,13 @@ ScriptInterpreterPython::ExecuteInterpreterLoop ()
// try to embed a running interpreter loop inside the already running Python interpreter loop, so we won't
// do it.
- if (!debugger.GetInputFile().IsValid())
+ if (!debugger.GetInputFile()->GetFile().IsValid())
return;
- InputReaderSP reader_sp (new InputReader(debugger));
- if (reader_sp)
- {
- Error error (reader_sp->Initialize (ScriptInterpreterPython::InputReaderCallback,
- this, // baton
- eInputReaderGranularityLine, // token size, to pass to callback function
- NULL, // end token
- NULL, // prompt
- true)); // echo input
-
- if (error.Success())
- {
- debugger.PushInputReader (reader_sp);
- m_embedded_python_input_reader_sp = reader_sp;
- }
+ IOHandlerSP io_handler_sp (new IOHandlerPythonInterpreter (debugger, this));
+ if (io_handler_sp)
+ {
+ debugger.PushIOHandler(io_handler_sp);
}
}
@@ -951,27 +832,21 @@ ScriptInterpreterPython::ExecuteOneLineWithReturn (const char *in_string,
ScriptInterpreterPython::Locker::FreeAcquiredLock | ScriptInterpreterPython::Locker::TearDownSession);
PyObject *py_return = NULL;
- PyObject *mainmod = PyImport_AddModule ("__main__");
- PyObject *globals = PyModule_GetDict (mainmod);
- PyObject *locals = NULL;
+ PythonObject &main_module = GetMainModule ();
+ PythonDictionary globals (PyModule_GetDict(main_module.get()));
PyObject *py_error = NULL;
bool ret_success = false;
- bool should_decrement_locals = false;
int success;
- locals = FindSessionDictionary(m_dictionary_name.c_str());
+ PythonDictionary locals = GetSessionDictionary ();
- if (locals == NULL)
+ if (!locals)
{
- locals = PyObject_GetAttrString (globals, m_dictionary_name.c_str());
- should_decrement_locals = true;
+ locals = PyObject_GetAttrString (globals.get(), m_dictionary_name.c_str());
}
- if (locals == NULL)
- {
+ if (!locals)
locals = globals;
- should_decrement_locals = false;
- }
py_error = PyErr_Occurred();
if (py_error != NULL)
@@ -980,22 +855,18 @@ ScriptInterpreterPython::ExecuteOneLineWithReturn (const char *in_string,
if (in_string != NULL)
{
{ // scope for PythonInputReaderManager
- PythonInputReaderManager py_input(options.GetEnableIO() ? this : NULL);
- py_return = PyRun_String (in_string, Py_eval_input, globals, locals);
+ //PythonInputReaderManager py_input(options.GetEnableIO() ? this : NULL);
+ py_return = PyRun_String (in_string, Py_eval_input, globals.get(), locals.get());
if (py_return == NULL)
{
py_error = PyErr_Occurred ();
if (py_error != NULL)
PyErr_Clear ();
- py_return = PyRun_String (in_string, Py_single_input, globals, locals);
+ py_return = PyRun_String (in_string, Py_single_input, globals.get(), locals.get());
}
}
- if (locals != NULL
- && should_decrement_locals)
- Py_XDECREF (locals);
-
if (py_return != NULL)
{
switch (return_type)
@@ -1115,35 +986,31 @@ ScriptInterpreterPython::ExecuteOneLineWithReturn (const char *in_string,
return ret_success;
}
-bool
+Error
ScriptInterpreterPython::ExecuteMultipleLines (const char *in_string, const ExecuteScriptOptions &options)
{
-
+ Error error;
Locker locker(this,
ScriptInterpreterPython::Locker::AcquireLock | ScriptInterpreterPython::Locker::InitSession | (options.GetSetLLDBGlobals() ? ScriptInterpreterPython::Locker::InitGlobals : 0),
ScriptInterpreterPython::Locker::FreeAcquiredLock | ScriptInterpreterPython::Locker::TearDownSession);
bool success = false;
- PyObject *py_return = NULL;
- PyObject *mainmod = PyImport_AddModule ("__main__");
- PyObject *globals = PyModule_GetDict (mainmod);
- PyObject *locals = NULL;
+ PythonObject return_value;
+ PythonObject &main_module = GetMainModule ();
+ PythonDictionary globals (PyModule_GetDict(main_module.get()));
PyObject *py_error = NULL;
- bool should_decrement_locals = false;
- locals = FindSessionDictionary(m_dictionary_name.c_str());
+ PythonDictionary locals = GetSessionDictionary ();
- if (locals == NULL)
+ if (!locals)
{
- locals = PyObject_GetAttrString (globals, m_dictionary_name.c_str());
- should_decrement_locals = true;
+ locals = PyObject_GetAttrString (globals.get(), m_dictionary_name.c_str());
}
- if (locals == NULL)
+ if (!locals)
{
locals = globals;
- should_decrement_locals = false;
}
py_error = PyErr_Occurred();
@@ -1159,16 +1026,11 @@ ScriptInterpreterPython::ExecuteMultipleLines (const char *in_string, const Exec
if (compiled_code)
{
{ // scope for PythonInputReaderManager
- PythonInputReaderManager py_input(options.GetEnableIO() ? this : NULL);
- py_return = PyEval_EvalCode (compiled_code, globals, locals);
+ //PythonInputReaderManager py_input(options.GetEnableIO() ? this : NULL);
+ return_value.Reset(PyEval_EvalCode (compiled_code, globals.get(), locals.get()));
}
- if (py_return != NULL)
- {
+ if (return_value)
success = true;
- Py_XDECREF (py_return);
- }
- if (locals && should_decrement_locals)
- Py_XDECREF (locals);
}
}
}
@@ -1176,324 +1038,50 @@ ScriptInterpreterPython::ExecuteMultipleLines (const char *in_string, const Exec
py_error = PyErr_Occurred ();
if (py_error != NULL)
{
- success = false;
- if (options.GetMaskoutErrors())
- {
- if (PyErr_GivenExceptionMatches (py_error, PyExc_SyntaxError))
- PyErr_Print ();
- PyErr_Clear();
- }
- }
-
- return success;
-}
-
-static const char *g_reader_instructions = "Enter your Python command(s). Type 'DONE' to end.";
-
-static const char *g_bkpt_command_reader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
- "def function(frame,bp_loc,internal_dict):\n"
- " \"\"\"frame: the SBFrame for the location at which you stopped\n"
- " bp_loc: an SBBreakpointLocation for the breakpoint location information\n"
- " internal_dict: an LLDB support object not to be used\"\"\"";
-
-size_t
-ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback
-(
- void *baton,
- InputReader &reader,
- InputReaderAction notification,
- const char *bytes,
- size_t bytes_len
-)
-{
- static StringList commands_in_progress;
-
- switch (notification)
- {
- case eInputReaderActivate:
- {
-
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
- commands_in_progress.Clear();
- if (!batch_mode)
- {
- out_stream->Printf ("%s\n", g_bkpt_command_reader_instructions);
- if (reader.GetPrompt())
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush ();
- }
- }
- break;
-
- case eInputReaderDeactivate:
- break;
-
- case eInputReaderReactivate:
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
- if (reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush ();
- }
- }
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
+// puts(in_string);
+// _PyObject_Dump (py_error);
+// PyErr_Print();
+// success = false;
- case eInputReaderGotToken:
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
- std::string temp_string (bytes, bytes_len);
- commands_in_progress.AppendString (temp_string.c_str());
- if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush ();
- }
- }
- break;
-
- case eInputReaderEndOfFile:
- case eInputReaderInterrupt:
- // Control-c (SIGINT) & control-d both mean finish & exit.
- reader.SetIsDone(true);
+ PyObject *type = NULL;
+ PyObject *value = NULL;
+ PyObject *traceback = NULL;
+ PyErr_Fetch (&type,&value,&traceback);
- // Control-c (SIGINT) ALSO means cancel; do NOT create a breakpoint command.
- if (notification == eInputReaderInterrupt)
- commands_in_progress.Clear();
+ // get the backtrace
+ std::string bt = ReadPythonBacktrace(traceback);
- // Fall through here...
-
- case eInputReaderDone:
+ if (value && value != Py_None)
+ error.SetErrorStringWithFormat("%s\n%s", PyString_AsString(PyObject_Str(value)),bt.c_str());
+ else
+ error.SetErrorStringWithFormat("%s",bt.c_str());
+ Py_XDECREF(type);
+ Py_XDECREF(value);
+ Py_XDECREF(traceback);
+ if (options.GetMaskoutErrors())
{
- bool batch_mode = notification == eInputReaderDone ?
- reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode() :
- true;
- BreakpointOptions *bp_options = (BreakpointOptions *)baton;
- std::unique_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());
- data_ap->user_source.AppendList (commands_in_progress);
- if (data_ap.get())
- {
- ScriptInterpreter *interpreter = reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
- if (interpreter)
- {
- if (interpreter->GenerateBreakpointCommandCallbackData (data_ap->user_source,
- data_ap->script_source))
- {
- BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release()));
- bp_options->SetCallback (ScriptInterpreterPython::BreakpointCallbackFunction, baton_sp);
- }
- else if (!batch_mode)
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- out_stream->Printf ("Warning: No command attached to breakpoint.\n");
- out_stream->Flush();
- }
- }
- else
- {
- if (!batch_mode)
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- out_stream->Printf ("Warning: Unable to find script intepreter; no command attached to breakpoint.\n");
- out_stream->Flush();
- }
- }
- }
+ PyErr_Clear();
}
- break;
-
}
- return bytes_len;
+ return error;
}
-size_t
-ScriptInterpreterPython::GenerateWatchpointOptionsCommandCallback
-(
- void *baton,
- InputReader &reader,
- InputReaderAction notification,
- const char *bytes,
- size_t bytes_len
-)
-{
- static StringList commands_in_progress;
-
- switch (notification)
- {
- case eInputReaderActivate:
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
-
- commands_in_progress.Clear();
- if (!batch_mode)
- {
- out_stream->Printf ("%s\n", g_reader_instructions);
- if (reader.GetPrompt())
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush ();
- }
- }
- break;
-
- case eInputReaderDeactivate:
- break;
-
- case eInputReaderReactivate:
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
- if (reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush ();
- }
- }
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
-
- case eInputReaderGotToken:
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
- std::string temp_string (bytes, bytes_len);
- commands_in_progress.AppendString (temp_string.c_str());
- if (!reader.IsDone() && reader.GetPrompt() && !batch_mode)
- {
- out_stream->Printf ("%s", reader.GetPrompt());
- out_stream->Flush ();
- }
- }
- break;
-
- case eInputReaderEndOfFile:
- case eInputReaderInterrupt:
- // Control-c (SIGINT) & control-d both mean finish & exit.
- reader.SetIsDone(true);
-
- // Control-c (SIGINT) ALSO means cancel; do NOT create a breakpoint command.
- if (notification == eInputReaderInterrupt)
- commands_in_progress.Clear();
-
- // Fall through here...
-
- case eInputReaderDone:
- {
- bool batch_mode = notification == eInputReaderDone ?
- reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode() :
- true;
- WatchpointOptions *wp_options = (WatchpointOptions *)baton;
- std::unique_ptr<WatchpointOptions::CommandData> data_ap(new WatchpointOptions::CommandData());
- data_ap->user_source.AppendList (commands_in_progress);
- if (data_ap.get())
- {
- ScriptInterpreter *interpreter = reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
- if (interpreter)
- {
- if (interpreter->GenerateWatchpointCommandCallbackData (data_ap->user_source,
- data_ap->script_source))
- {
- BatonSP baton_sp (new WatchpointOptions::CommandBaton (data_ap.release()));
- wp_options->SetCallback (ScriptInterpreterPython::WatchpointCallbackFunction, baton_sp);
- }
- else if (!batch_mode)
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- out_stream->Printf ("Warning: No command attached to breakpoint.\n");
- out_stream->Flush();
- }
- }
- else
- {
- if (!batch_mode)
- {
- StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream();
- out_stream->Printf ("Warning: Unable to find script intepreter; no command attached to breakpoint.\n");
- out_stream->Flush();
- }
- }
- }
- }
- break;
-
- }
-
- return bytes_len;
-}
void
ScriptInterpreterPython::CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
CommandReturnObject &result)
{
- Debugger &debugger = GetCommandInterpreter().GetDebugger();
-
- InputReaderSP reader_sp (new InputReader (debugger));
-
- if (reader_sp)
- {
- Error err = reader_sp->Initialize (
- ScriptInterpreterPython::GenerateBreakpointOptionsCommandCallback,
- bp_options, // baton
- eInputReaderGranularityLine, // token size, for feeding data to callback function
- "DONE", // end token
- " ", // prompt
- true); // echo input
-
- if (err.Success())
- debugger.PushInputReader (reader_sp);
- else
- {
- result.AppendError (err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendError("out of memory");
- result.SetStatus (eReturnStatusFailed);
- }
+ m_active_io_handler = eIOHandlerBreakpoint;
+ m_interpreter.GetPythonCommandsFromIOHandler (" ", *this, true, bp_options);
}
void
ScriptInterpreterPython::CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
CommandReturnObject &result)
{
- Debugger &debugger = GetCommandInterpreter().GetDebugger();
-
- InputReaderSP reader_sp (new InputReader (debugger));
-
- if (reader_sp)
- {
- Error err = reader_sp->Initialize (
- ScriptInterpreterPython::GenerateWatchpointOptionsCommandCallback,
- wp_options, // baton
- eInputReaderGranularityLine, // token size, for feeding data to callback function
- "DONE", // end token
- "> ", // prompt
- true); // echo input
-
- if (err.Success())
- debugger.PushInputReader (reader_sp);
- else
- {
- result.AppendError (err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendError("out of memory");
- result.SetStatus (eReturnStatusFailed);
- }
+ m_active_io_handler = eIOHandlerWatchpoint;
+ m_interpreter.GetPythonCommandsFromIOHandler (" ", *this, true, wp_options);
}
// Set a Python one-liner as the callback for the breakpoint.
@@ -1548,7 +1136,7 @@ ScriptInterpreterPython::ExportFunctionDefinitionToInterpreter (StringList &func
// Convert StringList to one long, newline delimited, const char *.
std::string function_def_string(function_def.CopyList());
- return ExecuteMultipleLines (function_def_string.c_str(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false));
+ return ExecuteMultipleLines (function_def_string.c_str(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false)).Success();
}
bool
@@ -1700,7 +1288,9 @@ ScriptInterpreterPython::OSPlugin_CreatePluginObject (const char *class_name, ll
void* ret_val;
{
- Locker py_lock(this,Locker::AcquireLock,Locker::FreeLock);
+ Locker py_lock (this,
+ Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
ret_val = g_swig_create_os_plugin (class_name,
m_dictionary_name.c_str(),
process_sp);
@@ -1712,7 +1302,9 @@ ScriptInterpreterPython::OSPlugin_CreatePluginObject (const char *class_name, ll
lldb::ScriptInterpreterObjectSP
ScriptInterpreterPython::OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
{
- Locker py_lock(this,Locker::AcquireLock,Locker::FreeLock);
+ Locker py_lock(this,
+ Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
static char callee_name[] = "get_register_info";
@@ -1771,7 +1363,9 @@ ScriptInterpreterPython::OSPlugin_RegisterInfo (lldb::ScriptInterpreterObjectSP
lldb::ScriptInterpreterObjectSP
ScriptInterpreterPython::OSPlugin_ThreadsInfo (lldb::ScriptInterpreterObjectSP os_plugin_object_sp)
{
- Locker py_lock(this,Locker::AcquireLock,Locker::FreeLock);
+ Locker py_lock (this,
+ Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
static char callee_name[] = "get_thread_info";
@@ -1857,7 +1451,9 @@ lldb::ScriptInterpreterObjectSP
ScriptInterpreterPython::OSPlugin_RegisterContextData (lldb::ScriptInterpreterObjectSP os_plugin_object_sp,
lldb::tid_t tid)
{
- Locker py_lock(this,Locker::AcquireLock,Locker::FreeLock);
+ Locker py_lock (this,
+ Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
static char callee_name[] = "get_register_data";
static char *param_format = const_cast<char *>(GetPythonValueFormatString(tid));
@@ -1919,7 +1515,9 @@ ScriptInterpreterPython::OSPlugin_CreateThread (lldb::ScriptInterpreterObjectSP
lldb::tid_t tid,
lldb::addr_t context)
{
- Locker py_lock(this,Locker::AcquireLock,Locker::FreeLock);
+ Locker py_lock(this,
+ Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
static char callee_name[] = "create_thread";
std::string param_format;
@@ -2011,7 +1609,7 @@ ScriptInterpreterPython::GetDynamicSettings (lldb::ScriptInterpreterObjectSP plu
PyObject *reply_pyobj = nullptr;
{
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
TargetSP target_sp(target->shared_from_this());
reply_pyobj = (PyObject*)g_swig_plugin_get(plugin_module_sp->GetObject(),setting_name,target_sp);
}
@@ -2045,7 +1643,7 @@ ScriptInterpreterPython::CreateSyntheticScriptedProvider (const char *class_name
void* ret_val;
{
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
ret_val = g_swig_synthetic_script (class_name,
python_interpreter->m_dictionary_name.c_str(),
valobj);
@@ -2136,14 +1734,14 @@ ScriptInterpreterPython::GetScriptedSummary (const char *python_function_name,
&& *python_function_name)
{
{
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
{
- Timer scoped_timer ("g_swig_typescript_callback","g_swig_typescript_callback");
- ret_val = g_swig_typescript_callback (python_function_name,
- FindSessionDictionary(m_dictionary_name.c_str()),
- valobj,
- &new_callee,
- retval);
+ Timer scoped_timer ("g_swig_typescript_callback","g_swig_typescript_callback");
+ ret_val = g_swig_typescript_callback (python_function_name,
+ GetSessionDictionary().get(),
+ valobj,
+ &new_callee,
+ retval);
}
}
}
@@ -2188,8 +1786,7 @@ ScriptInterpreterPython::BreakpointCallbackFunction
if (!script_interpreter)
return true;
- if (python_function_name != NULL
- && python_function_name[0] != '\0')
+ if (python_function_name && python_function_name[0])
{
const StackFrameSP stop_frame_sp (exe_ctx.GetFrameSP());
BreakpointSP breakpoint_sp = target->GetBreakpointByID (break_id);
@@ -2201,8 +1798,8 @@ ScriptInterpreterPython::BreakpointCallbackFunction
{
bool ret_val = true;
{
- Locker py_lock(python_interpreter);
- ret_val = g_swig_breakpoint_callback (python_function_name,
+ Locker py_lock(python_interpreter, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
+ ret_val = g_swig_breakpoint_callback (python_function_name,
python_interpreter->m_dictionary_name.c_str(),
stop_frame_sp,
bp_loc_sp);
@@ -2243,8 +1840,7 @@ ScriptInterpreterPython::WatchpointCallbackFunction
if (!script_interpreter)
return true;
- if (python_function_name != NULL
- && python_function_name[0] != '\0')
+ if (python_function_name && python_function_name[0])
{
const StackFrameSP stop_frame_sp (exe_ctx.GetFrameSP());
WatchpointSP wp_sp = target->GetWatchpointList().FindByID (watch_id);
@@ -2254,8 +1850,8 @@ ScriptInterpreterPython::WatchpointCallbackFunction
{
bool ret_val = true;
{
- Locker py_lock(python_interpreter);
- ret_val = g_swig_watchpoint_callback (python_function_name,
+ Locker py_lock(python_interpreter, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
+ ret_val = g_swig_watchpoint_callback (python_function_name,
python_interpreter->m_dictionary_name.c_str(),
stop_frame_sp,
wp_sp);
@@ -2269,106 +1865,6 @@ ScriptInterpreterPython::WatchpointCallbackFunction
return true;
}
-lldb::thread_result_t
-ScriptInterpreterPython::RunEmbeddedPythonInterpreter (lldb::thread_arg_t baton)
-{
- ScriptInterpreterPython *script_interpreter = (ScriptInterpreterPython *) baton;
-
- Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SCRIPT));
-
- if (log)
- log->Printf ("%p ScriptInterpreterPython::RunEmbeddedPythonInterpreter () thread starting...", baton);
-
- char error_str[1024];
- const char *pty_slave_name = script_interpreter->m_embedded_python_pty.GetSlaveName (error_str, sizeof (error_str));
-
- if (pty_slave_name != NULL)
- {
- StreamString run_string;
-
- // Ensure we have the GIL before running any Python code.
- // Since we're only running a few one-liners and then dropping to the interpreter (which will release the GIL when needed),
- // we can just release the GIL after finishing our work.
- // If finer-grained locking is desirable, we can lock and unlock the GIL only when calling a python function.
- Locker locker(script_interpreter,
- ScriptInterpreterPython::Locker::AcquireLock | ScriptInterpreterPython::Locker::InitSession | ScriptInterpreterPython::Locker::InitGlobals,
- ScriptInterpreterPython::Locker::FreeAcquiredLock | ScriptInterpreterPython::Locker::TearDownSession);
-
- run_string.Printf ("run_one_line (%s, 'save_stderr = sys.stderr')", script_interpreter->m_dictionary_name.c_str());
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear ();
-
- run_string.Printf ("run_one_line (%s, 'sys.stderr = sys.stdout')", script_interpreter->m_dictionary_name.c_str());
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear ();
-
- run_string.Printf ("run_one_line (%s, 'save_stdin = sys.stdin')", script_interpreter->m_dictionary_name.c_str());
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear ();
-
- run_string.Printf ("run_one_line (%s, \"sys.stdin = open ('%s', 'r')\")", script_interpreter->m_dictionary_name.c_str(),
- pty_slave_name);
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear ();
-
- // The following call drops into the embedded interpreter loop and stays there until the
- // user chooses to exit from the Python interpreter.
- // This embedded interpreter will, as any Python code that performs I/O, unlock the GIL before
- // a system call that can hang, and lock it when the syscall has returned.
-
- // We need to surround the call to the embedded interpreter with calls to PyGILState_Ensure and
- // PyGILState_Release (using the Locker above). This is because Python has a global lock which must be held whenever we want
- // to touch any Python objects. Otherwise, if the user calls Python code, the interpreter state will be off,
- // and things could hang (it's happened before).
-
- run_string.Printf ("run_python_interpreter (%s)", script_interpreter->m_dictionary_name.c_str());
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear ();
-
- run_string.Printf ("run_one_line (%s, 'sys.stdin = save_stdin')", script_interpreter->m_dictionary_name.c_str());
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear();
-
- run_string.Printf ("run_one_line (%s, 'sys.stderr = save_stderr')", script_interpreter->m_dictionary_name.c_str());
- PyRun_SimpleString (run_string.GetData());
- run_string.Clear();
- }
-
- if (script_interpreter->m_embedded_python_input_reader_sp)
- script_interpreter->m_embedded_python_input_reader_sp->SetIsDone (true);
-
- script_interpreter->m_embedded_python_pty.CloseSlaveFileDescriptor();
-
- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SCRIPT);
- if (log)
- log->Printf ("%p ScriptInterpreterPython::RunEmbeddedPythonInterpreter () thread exiting...", baton);
-
-
- // Clean up the input reader and make the debugger pop it off the stack.
- Debugger &debugger = script_interpreter->GetCommandInterpreter().GetDebugger();
- const InputReaderSP reader_sp = script_interpreter->m_embedded_python_input_reader_sp;
- if (reader_sp)
- {
- debugger.PopInputReader (reader_sp);
- script_interpreter->m_embedded_python_input_reader_sp.reset();
- }
-
- return NULL;
-}
-
-lldb::thread_result_t
-ScriptInterpreterPython::PythonInputReaderManager::RunPythonInputReader (lldb::thread_arg_t baton)
-{
- ScriptInterpreterPython *script_interpreter = (ScriptInterpreterPython *) baton;
-
- const InputReaderSP reader_sp = script_interpreter->m_embedded_thread_input_reader_sp;
-
- if (reader_sp)
- reader_sp->WaitOnReaderIsDone();
-
- return NULL;
-}
-
size_t
ScriptInterpreterPython::CalculateNumChildren (const lldb::ScriptInterpreterObjectSP& implementor_sp)
{
@@ -2386,7 +1882,7 @@ ScriptInterpreterPython::CalculateNumChildren (const lldb::ScriptInterpreterObje
uint32_t ret_val = 0;
{
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
ret_val = g_swig_calc_children (implementor);
}
@@ -2410,7 +1906,7 @@ ScriptInterpreterPython::GetChildAtIndex (const lldb::ScriptInterpreterObjectSP&
lldb::ValueObjectSP ret_val;
{
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
void* child_ptr = g_swig_get_child_index (implementor,idx);
if (child_ptr != NULL && child_ptr != Py_None)
{
@@ -2446,7 +1942,7 @@ ScriptInterpreterPython::GetIndexOfChildWithName (const lldb::ScriptInterpreterO
int ret_val = UINT32_MAX;
{
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
ret_val = g_swig_get_index_child (implementor, child_name);
}
@@ -2470,7 +1966,7 @@ ScriptInterpreterPython::UpdateSynthProviderInstance (const lldb::ScriptInterpre
return ret_val;
{
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
ret_val = g_swig_update_provider (implementor);
}
@@ -2494,7 +1990,7 @@ ScriptInterpreterPython::MightHaveChildrenSynthProviderInstance (const lldb::Scr
return ret_val;
{
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
ret_val = g_swig_mighthavechildren_provider (implementor);
}
@@ -2582,7 +2078,7 @@ ScriptInterpreterPython::RunScriptFormatKeyword (const char* impl_function,
}
{
ProcessSP process_sp(process->shared_from_this());
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
ret_val = g_swig_run_script_keyword_process (impl_function, m_dictionary_name.c_str(), process_sp, output);
if (!ret_val)
error.SetErrorString("python script evaluation failed");
@@ -2614,7 +2110,7 @@ ScriptInterpreterPython::RunScriptFormatKeyword (const char* impl_function,
}
{
ThreadSP thread_sp(thread->shared_from_this());
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
ret_val = g_swig_run_script_keyword_thread (impl_function, m_dictionary_name.c_str(), thread_sp, output);
if (!ret_val)
error.SetErrorString("python script evaluation failed");
@@ -2646,7 +2142,7 @@ ScriptInterpreterPython::RunScriptFormatKeyword (const char* impl_function,
}
{
TargetSP target_sp(target->shared_from_this());
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
ret_val = g_swig_run_script_keyword_target (impl_function, m_dictionary_name.c_str(), target_sp, output);
if (!ret_val)
error.SetErrorString("python script evaluation failed");
@@ -2678,7 +2174,7 @@ ScriptInterpreterPython::RunScriptFormatKeyword (const char* impl_function,
}
{
StackFrameSP frame_sp(frame->shared_from_this());
- Locker py_lock(this);
+ Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
ret_val = g_swig_run_script_keyword_frame (impl_function, m_dictionary_name.c_str(), frame_sp, output);
if (!ret_val)
error.SetErrorString("python script evaluation failed");
@@ -2728,7 +2224,7 @@ ScriptInterpreterPython::LoadScriptingModule (const char* pathname,
// Before executing Pyton code, lock the GIL.
Locker py_lock (this,
- Locker::AcquireLock | (init_session ? Locker::InitSession : 0),
+ Locker::AcquireLock | (init_session ? Locker::InitSession : 0) | Locker::NoSTDIN,
Locker::FreeAcquiredLock | (init_session ? Locker::TearDownSession : 0));
if (target_file.GetFileType() == FileSpec::eFileTypeInvalid ||
@@ -2755,7 +2251,7 @@ ScriptInterpreterPython::LoadScriptingModule (const char* pathname,
command_stream.Printf("if not (sys.path.__contains__('%s')):\n sys.path.insert(1,'%s');\n\n",
directory.c_str(),
directory.c_str());
- bool syspath_retval = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false));
+ bool syspath_retval = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false)).Success();
if (!syspath_retval)
{
error.SetErrorString("Python sys.path handling failed");
@@ -2818,47 +2314,9 @@ ScriptInterpreterPython::LoadScriptingModule (const char* pathname,
else
command_stream.Printf("import %s",basename.c_str());
- bool import_retval = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false).SetMaskoutErrors(false));
- PyObject* py_error = PyErr_Occurred(); // per Python docs: "you do not need to Py_DECREF()" the return of this function
-
- if (py_error || !import_retval) // check for failure of the import
- {
- if (py_error) // if we have a Python error..
- {
- PyObject *type = NULL,*value = NULL,*traceback = NULL;
- PyErr_Fetch (&type,&value,&traceback);
-
- if (PyErr_GivenExceptionMatches (py_error, PyExc_ImportError)) // and it is an ImportError
- {
- if (value && value != Py_None)
- error.SetErrorString(PyString_AsString(PyObject_Str(value)));
- else
- error.SetErrorString("ImportError raised by imported module");
- }
- else // any other error
- {
- // get the backtrace
- std::string bt = ReadPythonBacktrace(traceback);
-
- if (value && value != Py_None)
- error.SetErrorStringWithFormat("Python error raised while importing module: %s - traceback: %s", PyString_AsString(PyObject_Str(value)),bt.c_str());
- else
- error.SetErrorStringWithFormat("Python raised an error while importing module - traceback: %s",bt.c_str());
- }
-
- Py_XDECREF(type);
- Py_XDECREF(value);
- Py_XDECREF(traceback);
- }
- else // we failed but have no error to explain why
- {
- error.SetErrorString("unknown error while importing module");
- }
-
- // anyway, clear the error indicator and return false
- PyErr_Clear();
+ error = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false));
+ if (error.Fail())
return false;
- }
// if we are here, everything worked
// call __lldb_init_module(debugger,dict)
@@ -2954,7 +2412,7 @@ ScriptInterpreterPython::RunScriptBasedCommand(const char* impl_function,
// to set the asynchronous exception - not a desirable situation
m_command_thread_state = _PyThreadState_Current;
- PythonInputReaderManager py_input(this);
+ //PythonInputReaderManager py_input(this);
ret_val = g_swig_call_command (impl_function,
m_dictionary_name.c_str(),
@@ -3007,8 +2465,8 @@ std::unique_ptr<ScriptInterpreterLocker>
ScriptInterpreterPython::AcquireInterpreterLock ()
{
std::unique_ptr<ScriptInterpreterLocker> py_lock(new Locker(this,
- Locker::AcquireLock | Locker::InitSession,
- Locker::FreeLock | Locker::TearDownSession));
+ Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN,
+ Locker::FreeLock | Locker::TearDownSession));
return py_lock;
}
@@ -3059,6 +2517,13 @@ ScriptInterpreterPython::InitializeInterpreter (SWIGInitCallback swig_init_callb
void
ScriptInterpreterPython::InitializePrivate ()
{
+ static int g_initialized = false;
+
+ if (g_initialized)
+ return;
+
+ g_initialized = true;
+
Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
// Python will muck with STDIN terminal state, so save off any current TTY
diff --git a/source/Interpreter/embedded_interpreter.py b/source/Interpreter/embedded_interpreter.py
index 0e57c1e4aec9..bc0dd6d5ae4f 100644
--- a/source/Interpreter/embedded_interpreter.py
+++ b/source/Interpreter/embedded_interpreter.py
@@ -1,103 +1,108 @@
-import readline
+import __builtin__
import code
+import lldb
import sys
import traceback
-class SimpleREPL(code.InteractiveConsole):
- def __init__(self, prompt, dict):
- code.InteractiveConsole.__init__(self,dict)
- self.prompt = prompt
- self.loop_exit = False
- self.dict = dict
+try:
+ import readline
+ import rlcompleter
+except ImportError:
+ have_readline = False
+else:
+ have_readline = True
+ if 'libedit' in readline.__doc__:
+ readline.parse_and_bind('bind ^I rl_complete')
+ else:
+ readline.parse_and_bind('tab: complete')
- def interact(self):
- try:
- sys.ps1
- except AttributeError:
- sys.ps1 = ">>> "
- try:
- sys.ps2
- except AttributeError:
- sys.ps2 = "... "
+g_builtin_override_called = False
- while not self.loop_exit:
- try:
- self.read_py_command()
- except (SystemExit, EOFError):
- # EOF while in Python just breaks out to top level.
- self.write('\n')
- self.loop_exit = True
- break
- except KeyboardInterrupt:
- self.write("\nKeyboardInterrupt\n")
- self.resetbuffer()
- more = 0
- except:
- traceback.print_exc()
+class LLDBQuitter(object):
+ def __init__(self, name):
+ self.name = name
+ def __repr__(self):
+ self()
+ def __call__(self, code=None):
+ global g_builtin_override_called
+ g_builtin_override_called = True
+ raise SystemExit(-1)
- def process_input (self, in_str):
- # Canonicalize the format of the input string
- temp_str = in_str
- temp_str.strip(' \t')
- words = temp_str.split()
- temp_str = ('').join(words)
+def setquit():
+ '''Redefine builtin functions 'quit()' and 'exit()' to print a message and raise an EOFError exception.'''
+ # This function will be called prior to each interactive
+ # interpreter loop or each single line, so we set the global
+ # g_builtin_override_called to False so we know if a SystemExit
+ # is thrown, we can catch it and tell the difference between
+ # a call to "quit()" or "exit()" and something like
+ # "sys.exit(123)"
+ global g_builtin_override_called
+ g_builtin_override_called = False
+ __builtin__.quit = LLDBQuitter('quit')
+ __builtin__.exit = LLDBQuitter('exit')
- # Check the input string to see if it was the quit
- # command. If so, intercept it, so that it doesn't
- # close stdin on us!
- if (temp_str.lower() == "quit()" or temp_str.lower() == "exit()"):
- self.loop_exit = True
- in_str = "raise SystemExit "
- return in_str
+# When running one line, we might place the string to run in this string
+# in case it would be hard to correctly escape a string's contents
- def my_raw_input (self, prompt):
- stream = sys.stdout
- stream.write (prompt)
- stream.flush ()
- try:
- line = sys.stdin.readline()
- except KeyboardInterrupt:
- line = " \n"
- except (SystemExit, EOFError):
- line = "quit()\n"
- if not line:
- raise EOFError
- if line[-1] == '\n':
- line = line[:-1]
- return line
+g_run_one_line_str = None
- def read_py_command(self):
- # Read off a complete Python command.
- more = 0
- while 1:
- if more:
- prompt = sys.ps2
- else:
- prompt = sys.ps1
- line = self.my_raw_input(prompt)
- # Can be None if sys.stdin was redefined
- encoding = getattr(sys.stdin, "encoding", None)
- if encoding and not isinstance(line, unicode):
- line = line.decode(encoding)
- line = self.process_input (line)
- more = self.push(line)
- if not more:
- break
- def one_line (self, input):
- line = self.process_input (input)
- more = self.push(line)
- if more:
- self.write ("Input not a complete line.")
- self.resetbuffer()
- more = 0
+def get_terminal_size(fd):
+ try:
+ import fcntl, termios, struct
+ hw = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
+ except:
+ hw = (0,0)
+ return hw
-def run_python_interpreter (dict):
- # Pass in the dictionary, for continuity from one session to the next.
- repl = SimpleREPL('>>> ', dict)
- repl.interact()
+def readfunc_stdio(prompt):
+ sys.stdout.write(prompt)
+ return sys.stdin.readline()
-def run_one_line (dict, input_string):
- repl = SimpleREPL ('', dict)
- repl.one_line (input_string)
+def run_python_interpreter (local_dict):
+ # Pass in the dictionary, for continuity from one session to the next.
+ setquit()
+ try:
+ fd = sys.stdin.fileno();
+ interacted = False
+ if get_terminal_size(fd)[1] == 0:
+ try:
+ import termios
+ old = termios.tcgetattr(fd)
+ if old[3] & termios.ECHO:
+ # Need to turn off echoing and restore
+ new = termios.tcgetattr(fd)
+ new[3] = new[3] & ~termios.ECHO
+ try:
+ termios.tcsetattr(fd, termios.TCSADRAIN, new)
+ interacted = True
+ code.interact(banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()'.", readfunc=readfunc_stdio, local=local_dict)
+ finally:
+ termios.tcsetattr(fd, termios.TCSADRAIN, old)
+ except:
+ pass
+ # Don't need to turn off echoing
+ if not interacted:
+ code.interact(banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.", readfunc=readfunc_stdio, local=local_dict)
+ else:
+ # We have a real interactive terminal
+ code.interact(banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.", local=local_dict)
+ except SystemExit as e:
+ global g_builtin_override_called
+ if not g_builtin_override_called:
+ print 'Script exited with %s' %(e)
+def run_one_line (local_dict, input_string):
+ global g_run_one_line_str
+ setquit()
+ try:
+ repl = code.InteractiveConsole(local_dict);
+ if input_string:
+ repl.runsource (input_string)
+ elif g_run_one_line_str:
+ repl.runsource (g_run_one_line_str)
+
+ except SystemExit as e:
+ global g_builtin_override_called
+ if not g_builtin_override_called:
+ print 'Script exited with %s' %(e)
diff --git a/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp b/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
index 61c3c64d4fc3..e9b8a9f573a3 100644
--- a/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
+++ b/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
@@ -35,6 +35,7 @@
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/StackFrame.h"
@@ -127,6 +128,7 @@ public:
bool got_op = false;
DisassemblerLLVMC &llvm_disasm = GetDisassemblerLLVMC();
const ArchSpec &arch = llvm_disasm.GetArchitecture();
+ const lldb::ByteOrder byte_order = data.GetByteOrder();
const uint32_t min_op_byte_size = arch.GetMinimumOpcodeByteSize();
const uint32_t max_op_byte_size = arch.GetMaximumOpcodeByteSize();
@@ -135,26 +137,26 @@ public:
// Fixed size instructions, just read that amount of data.
if (!data.ValidOffsetForDataOfSize(data_offset, min_op_byte_size))
return false;
-
+
switch (min_op_byte_size)
{
case 1:
- m_opcode.SetOpcode8 (data.GetU8 (&data_offset));
+ m_opcode.SetOpcode8 (data.GetU8 (&data_offset), byte_order);
got_op = true;
break;
case 2:
- m_opcode.SetOpcode16 (data.GetU16 (&data_offset));
+ m_opcode.SetOpcode16 (data.GetU16 (&data_offset), byte_order);
got_op = true;
break;
case 4:
- m_opcode.SetOpcode32 (data.GetU32 (&data_offset));
+ m_opcode.SetOpcode32 (data.GetU32 (&data_offset), byte_order);
got_op = true;
break;
case 8:
- m_opcode.SetOpcode64 (data.GetU64 (&data_offset));
+ m_opcode.SetOpcode64 (data.GetU64 (&data_offset), byte_order);
got_op = true;
break;
@@ -177,20 +179,20 @@ public:
uint32_t thumb_opcode = data.GetU16(&data_offset);
if ((thumb_opcode & 0xe000) != 0xe000 || ((thumb_opcode & 0x1800u) == 0))
{
- m_opcode.SetOpcode16 (thumb_opcode);
+ m_opcode.SetOpcode16 (thumb_opcode, byte_order);
m_is_valid = true;
}
else
{
thumb_opcode <<= 16;
thumb_opcode |= data.GetU16(&data_offset);
- m_opcode.SetOpcode16_2 (thumb_opcode);
+ m_opcode.SetOpcode16_2 (thumb_opcode, byte_order);
m_is_valid = true;
}
}
else
{
- m_opcode.SetOpcode32 (data.GetU32(&data_offset));
+ m_opcode.SetOpcode32 (data.GetU32(&data_offset), byte_order);
m_is_valid = true;
}
}
@@ -303,12 +305,13 @@ public:
inst_size = m_opcode.GetByteSize();
StreamString mnemonic_strm;
lldb::offset_t offset = 0;
+ lldb::ByteOrder byte_order = data.GetByteOrder();
switch (inst_size)
{
case 1:
{
const uint8_t uval8 = data.GetU8 (&offset);
- m_opcode.SetOpcode8 (uval8);
+ m_opcode.SetOpcode8 (uval8, byte_order);
m_opcode_name.assign (".byte");
mnemonic_strm.Printf("0x%2.2x", uval8);
}
@@ -316,7 +319,7 @@ public:
case 2:
{
const uint16_t uval16 = data.GetU16(&offset);
- m_opcode.SetOpcode16(uval16);
+ m_opcode.SetOpcode16(uval16, byte_order);
m_opcode_name.assign (".short");
mnemonic_strm.Printf("0x%4.4x", uval16);
}
@@ -324,7 +327,7 @@ public:
case 4:
{
const uint32_t uval32 = data.GetU32(&offset);
- m_opcode.SetOpcode32(uval32);
+ m_opcode.SetOpcode32(uval32, byte_order);
m_opcode_name.assign (".long");
mnemonic_strm.Printf("0x%8.8x", uval32);
}
@@ -332,7 +335,7 @@ public:
case 8:
{
const uint64_t uval64 = data.GetU64(&offset);
- m_opcode.SetOpcode64(uval64);
+ m_opcode.SetOpcode64(uval64, byte_order);
m_opcode_name.assign (".quad");
mnemonic_strm.Printf("0x%16.16" PRIx64, uval64);
}
@@ -432,7 +435,8 @@ DisassemblerLLVMC::LLVMCDisassembler::LLVMCDisassembler (const char *triple, uns
m_subtarget_info_ap.reset(curr_target->createMCSubtargetInfo(triple, "",
features_str));
- m_asm_info_ap.reset(curr_target->createMCAsmInfo(*curr_target->createMCRegInfo(triple), triple));
+ std::unique_ptr<llvm::MCRegisterInfo> reg_info(curr_target->createMCRegInfo(triple));
+ m_asm_info_ap.reset(curr_target->createMCAsmInfo(*reg_info, triple));
if (m_instr_info_ap.get() == NULL || m_reg_info_ap.get() == NULL || m_subtarget_info_ap.get() == NULL || m_asm_info_ap.get() == NULL)
{
diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index 4284558c4409..286b1ef62d9a 100644
--- a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -150,46 +150,6 @@ DynamicLoaderPOSIXDYLD::DidLaunch()
}
}
-ModuleSP
-DynamicLoaderPOSIXDYLD::GetTargetExecutable()
-{
- Target &target = m_process->GetTarget();
- ModuleSP executable = target.GetExecutableModule();
-
- if (executable.get())
- {
- if (executable->GetFileSpec().Exists())
- {
- ModuleSpec module_spec (executable->GetFileSpec(), executable->GetArchitecture());
- ModuleSP module_sp (new Module (module_spec));
-
- // Check if the executable has changed and set it to the target executable if they differ.
- if (module_sp.get() && module_sp->GetUUID().IsValid() && executable->GetUUID().IsValid())
- {
- if (module_sp->GetUUID() != executable->GetUUID())
- executable.reset();
- }
- else if (executable->FileHasChanged())
- {
- executable.reset();
- }
-
- if (!executable.get())
- {
- executable = target.GetSharedModule(module_spec);
- if (executable.get() != target.GetExecutableModulePointer())
- {
- // Don't load dependent images since we are in dyld where we will know
- // and find out about all images that are loaded
- const bool get_dependent_images = false;
- target.SetExecutableModule(executable, get_dependent_images);
- }
- }
- }
- }
- return executable;
-}
-
Error
DynamicLoaderPOSIXDYLD::ExecutePluginCommand(Args &command, Stream *strm)
{
@@ -211,48 +171,17 @@ DynamicLoaderPOSIXDYLD::CanLoadImage()
void
DynamicLoaderPOSIXDYLD::UpdateLoadedSections(ModuleSP module, addr_t link_map_addr, addr_t base_addr)
{
- SectionLoadList &load_list = m_process->GetTarget().GetSectionLoadList();
- const SectionList *sections = GetSectionListFromModule(module);
-
- assert(sections && "SectionList missing from loaded module.");
-
m_loaded_modules[module] = link_map_addr;
- const size_t num_sections = sections->GetSize();
-
- for (unsigned i = 0; i < num_sections; ++i)
- {
- SectionSP section_sp (sections->GetSectionAtIndex(i));
- lldb::addr_t new_load_addr = section_sp->GetFileAddress() + base_addr;
- lldb::addr_t old_load_addr = load_list.GetSectionLoadAddress(section_sp);
-
- // If the file address of the section is zero then this is not an
- // allocatable/loadable section (property of ELF sh_addr). Skip it.
- if (new_load_addr == base_addr)
- continue;
-
- if (old_load_addr == LLDB_INVALID_ADDRESS ||
- old_load_addr != new_load_addr)
- load_list.SetSectionLoadAddress(section_sp, new_load_addr);
- }
+ UpdateLoadedSectionsCommon(module, base_addr);
}
void
DynamicLoaderPOSIXDYLD::UnloadSections(const ModuleSP module)
{
- SectionLoadList &load_list = m_process->GetTarget().GetSectionLoadList();
- const SectionList *sections = GetSectionListFromModule(module);
-
- assert(sections && "SectionList missing from unloaded module.");
-
m_loaded_modules.erase(module);
- const size_t num_sections = sections->GetSize();
- for (size_t i = 0; i < num_sections; ++i)
- {
- SectionSP section_sp (sections->GetSectionAtIndex(i));
- load_list.SetSectionUnloaded(section_sp);
- }
+ UnloadSectionsCommon(module);
}
void
@@ -470,26 +399,6 @@ DynamicLoaderPOSIXDYLD::LoadAllCurrentModules()
m_process->GetTarget().ModulesDidLoad(module_list);
}
-ModuleSP
-DynamicLoaderPOSIXDYLD::LoadModuleAtAddress(const FileSpec &file, addr_t link_map_addr, addr_t base_addr)
-{
- Target &target = m_process->GetTarget();
- ModuleList &modules = target.GetImages();
- ModuleSP module_sp;
-
- ModuleSpec module_spec (file, target.GetArchitecture());
- if ((module_sp = modules.FindFirstModule (module_spec)))
- {
- UpdateLoadedSections(module_sp, link_map_addr, base_addr);
- }
- else if ((module_sp = target.GetSharedModule(module_spec)))
- {
- UpdateLoadedSections(module_sp, link_map_addr, base_addr);
- }
-
- return module_sp;
-}
-
addr_t
DynamicLoaderPOSIXDYLD::ComputeLoadOffset()
{
@@ -533,41 +442,6 @@ DynamicLoaderPOSIXDYLD::GetEntryPoint()
return m_entry_point;
}
-const SectionList *
-DynamicLoaderPOSIXDYLD::GetSectionListFromModule(const ModuleSP module) const
-{
- SectionList *sections = nullptr;
- if (module.get())
- {
- ObjectFile *obj_file = module->GetObjectFile();
- if (obj_file)
- {
- sections = obj_file->GetSectionList();
- }
- }
- return sections;
-}
-
-static int ReadInt(Process *process, addr_t addr)
-{
- Error error;
- int value = (int)process->ReadUnsignedIntegerFromMemory(addr, sizeof(uint32_t), 0, error);
- if (error.Fail())
- return -1;
- else
- return value;
-}
-
-static addr_t ReadPointer(Process *process, addr_t addr)
-{
- Error error;
- addr_t value = process->ReadPointerFromMemory(addr, error);
- if (error.Fail())
- return LLDB_INVALID_ADDRESS;
- else
- return value;
-}
-
lldb::addr_t
DynamicLoaderPOSIXDYLD::GetThreadLocalData (const lldb::ModuleSP module, const lldb::ThreadSP thread)
{
@@ -589,26 +463,27 @@ DynamicLoaderPOSIXDYLD::GetThreadLocalData (const lldb::ModuleSP module, const l
return LLDB_INVALID_ADDRESS;
// Find the module's modid.
- int modid = ReadInt (m_process, link_map + metadata.modid_offset);
+ int modid_size = 4; // FIXME(spucci): This isn't right for big-endian 64-bit
+ int64_t modid = ReadUnsignedIntWithSizeInBytes (link_map + metadata.modid_offset, modid_size);
if (modid == -1)
return LLDB_INVALID_ADDRESS;
// Lookup the DTV stucture for this thread.
addr_t dtv_ptr = tp + metadata.dtv_offset;
- addr_t dtv = ReadPointer (m_process, dtv_ptr);
+ addr_t dtv = ReadPointer (dtv_ptr);
if (dtv == LLDB_INVALID_ADDRESS)
return LLDB_INVALID_ADDRESS;
// Find the TLS block for this module.
addr_t dtv_slot = dtv + metadata.dtv_slot_size*modid;
- addr_t tls_block = ReadPointer (m_process, dtv_slot + metadata.tls_offset);
+ addr_t tls_block = ReadPointer (dtv_slot + metadata.tls_offset);
Module *mod = module.get();
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
if (log)
log->Printf("DynamicLoaderPOSIXDYLD::Performed TLS lookup: "
- "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64 ", modid=%i, tls_block=0x%" PRIx64 "\n",
- mod->GetObjectName().AsCString(""), link_map, tp, modid, tls_block);
+ "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64 ", modid=%" PRId64 ", tls_block=0x%" PRIx64 "\n",
+ mod->GetObjectName().AsCString(""), link_map, tp, (int64_t)modid, tls_block);
return tls_block;
}
diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
index 7997b34195a4..9ced5da8a015 100644
--- a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
+++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
@@ -126,7 +126,7 @@ protected:
/// @param link_map_addr The virtual address of the link map for the @p module.
///
/// @param base_addr The virtual base address @p module is loaded at.
- void
+ virtual void
UpdateLoadedSections(lldb::ModuleSP module,
lldb::addr_t link_map_addr,
lldb::addr_t base_addr);
@@ -134,14 +134,9 @@ protected:
/// Removes the loaded sections from the target in @p module.
///
/// @param module The module to traverse.
- void
+ virtual void
UnloadSections(const lldb::ModuleSP module);
- /// Locates or creates a module given by @p file and updates/loads the
- /// resulting module at the virtual base address @p base_addr.
- lldb::ModuleSP
- LoadModuleAtAddress(const lldb_private::FileSpec &file, lldb::addr_t link_map_addr, lldb::addr_t base_addr);
-
/// Resolves the entry point for the current inferior process and sets a
/// breakpoint at that address.
void
@@ -173,16 +168,8 @@ protected:
lldb::addr_t
GetEntryPoint();
- /// Checks to see if the target module has changed, updates the target
- /// accordingly and returns the target executable module.
- lldb::ModuleSP
- GetTargetExecutable();
-
private:
DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
-
- const lldb_private::SectionList *
- GetSectionListFromModule(const lldb::ModuleSP module) const;
};
#endif // liblldb_DynamicLoaderPOSIXDYLD_H_
diff --git a/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp b/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
index 274ba328ad1f..86cf45013a4d 100644
--- a/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
+++ b/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
@@ -134,7 +134,7 @@ DynamicLoaderStatic::LoadAllImagesAtFileAddresses ()
SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
if (section_sp)
{
- if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress()))
+ if (m_process->GetTarget().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress()))
changed = true;
}
}
diff --git a/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp b/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
index db03f4536188..f1cb41d5a913 100644
--- a/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
+++ b/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
@@ -289,37 +289,65 @@ EmulateInstructionARM::GetRegisterInfo (uint32_t reg_kind, uint32_t reg_num, Reg
uint32_t
EmulateInstructionARM::GetFramePointerRegisterNumber () const
{
- if (m_opcode_mode == eModeThumb)
+ bool is_apple = false;
+ if (m_arch.GetTriple().getVendor() == llvm::Triple::Apple)
+ is_apple = true;
+ switch (m_arch.GetTriple().getOS())
{
- switch (m_arch.GetTriple().getOS())
- {
case llvm::Triple::Darwin:
case llvm::Triple::MacOSX:
case llvm::Triple::IOS:
- return 7;
+ is_apple = true;
+ break;
default:
break;
- }
}
- return 11;
+
+ /* On Apple iOS et al, the frame pointer register is always r7.
+ * Typically on other ARM systems, thumb code uses r7; arm code uses r11.
+ */
+
+ uint32_t fp_regnum = 11;
+
+ if (is_apple)
+ fp_regnum = 7;
+
+ if (m_opcode_mode == eModeThumb)
+ fp_regnum = 7;
+
+ return fp_regnum;
}
uint32_t
EmulateInstructionARM::GetFramePointerDWARFRegisterNumber () const
{
- if (m_opcode_mode == eModeThumb)
+ bool is_apple = false;
+ if (m_arch.GetTriple().getVendor() == llvm::Triple::Apple)
+ is_apple = true;
+ switch (m_arch.GetTriple().getOS())
{
- switch (m_arch.GetTriple().getOS())
- {
case llvm::Triple::Darwin:
case llvm::Triple::MacOSX:
case llvm::Triple::IOS:
- return dwarf_r7;
+ is_apple = true;
+ break;
default:
break;
- }
}
- return dwarf_r11;
+
+ /* On Apple iOS et al, the frame pointer register is always r7.
+ * Typically on other ARM systems, thumb code uses r7; arm code uses r11.
+ */
+
+ uint32_t fp_regnum = dwarf_r11;
+
+ if (is_apple)
+ fp_regnum = dwarf_r7;
+
+ if (m_opcode_mode == eModeThumb)
+ fp_regnum = dwarf_r7;
+
+ return fp_regnum;
}
// Push Multiple Registers stores multiple registers to the stack, storing to
@@ -12889,18 +12917,18 @@ EmulateInstructionARM::ReadInstruction ()
{
if ((thumb_opcode & 0xe000) != 0xe000 || ((thumb_opcode & 0x1800u) == 0))
{
- m_opcode.SetOpcode16 (thumb_opcode);
+ m_opcode.SetOpcode16 (thumb_opcode, GetByteOrder());
}
else
{
- m_opcode.SetOpcode32 ((thumb_opcode << 16) | MemARead(read_inst_context, pc + 2, 2, 0, &success));
+ m_opcode.SetOpcode32 ((thumb_opcode << 16) | MemARead(read_inst_context, pc + 2, 2, 0, &success), GetByteOrder());
}
}
}
else
{
m_opcode_mode = eModeARM;
- m_opcode.SetOpcode32 (MemARead(read_inst_context, pc, 4, 0, &success));
+ m_opcode.SetOpcode32 (MemARead(read_inst_context, pc, 4, 0, &success), GetByteOrder());
}
}
}
@@ -13510,15 +13538,15 @@ EmulateInstructionARM::TestEmulation (Stream *out_stream, ArchSpec &arch, Option
if (arch.GetTriple().getArch() == llvm::Triple::arm)
{
m_opcode_mode = eModeARM;
- m_opcode.SetOpcode32 (test_opcode);
+ m_opcode.SetOpcode32 (test_opcode, GetByteOrder());
}
else if (arch.GetTriple().getArch() == llvm::Triple::thumb)
{
m_opcode_mode = eModeThumb;
if (test_opcode < 0x10000)
- m_opcode.SetOpcode16 (test_opcode);
+ m_opcode.SetOpcode16 (test_opcode, GetByteOrder());
else
- m_opcode.SetOpcode32 (test_opcode);
+ m_opcode.SetOpcode32 (test_opcode, GetByteOrder());
}
else
diff --git a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
index f3c2d63729ae..9781dcb093ac 100644
--- a/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
+++ b/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
@@ -23,6 +23,7 @@
#include "lldb/Symbol/TypeList.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/StopInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
@@ -402,7 +403,9 @@ ItaniumABILanguageRuntime::CreateExceptionBreakpoint (bool catch_bp,
FileSpecList filter_modules;
BreakpointResolverSP exception_resolver_sp = CreateExceptionResolver (NULL, catch_bp, throw_bp, for_expressions);
SearchFilterSP filter_sp (CreateExceptionSearchFilter ());
- return target.CreateBreakpoint (filter_sp, exception_resolver_sp, is_internal, false);
+ const bool hardware = false;
+ const bool resolve_indirect_functions = false;
+ return target.CreateBreakpoint (filter_sp, exception_resolver_sp, is_internal, hardware, resolve_indirect_functions);
}
void
diff --git a/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 7bdacfe14cde..02db05b3c6b2 100644
--- a/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -24,6 +24,7 @@
#include "lldb/Core/Stream.h"
#include "lldb/Symbol/DWARFCallFrameInfo.h"
#include "lldb/Symbol/SymbolContext.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Host/Host.h"
@@ -462,6 +463,49 @@ ObjectFileELF::IsExecutable() const
return m_header.e_entry != 0;
}
+bool
+ObjectFileELF::SetLoadAddress (Target &target,
+ lldb::addr_t value,
+ bool value_is_offset)
+{
+ bool changed = false;
+ ModuleSP module_sp = GetModule();
+ if (module_sp)
+ {
+ size_t num_loaded_sections = 0;
+ SectionList *section_list = GetSectionList ();
+ if (section_list)
+ {
+ if (value_is_offset)
+ {
+ const size_t num_sections = section_list->GetSize();
+ size_t sect_idx = 0;
+
+ for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
+ {
+ // Iterate through the object file sections to find all
+ // of the sections that have SHF_ALLOC in their flag bits.
+ SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
+ // if (section_sp && !section_sp->IsThreadSpecific())
+ if (section_sp && section_sp->Test(SHF_ALLOC))
+ {
+ if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + value))
+ ++num_loaded_sections;
+ }
+ }
+ changed = num_loaded_sections > 0;
+ return num_loaded_sections > 0;
+ }
+ else
+ {
+ // Not sure how to slide an ELF file given the base address
+ // of the ELF file in memory
+ }
+ }
+ }
+ return changed;
+}
+
ByteOrder
ObjectFileELF::GetByteOrder() const
{
diff --git a/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index a2ab9b8f3703..9b7c073d902d 100644
--- a/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -118,6 +118,11 @@ public:
virtual bool
ParseHeader();
+ virtual bool
+ SetLoadAddress (lldb_private::Target &target,
+ lldb::addr_t value,
+ bool value_is_offset);
+
virtual lldb::ByteOrder
GetByteOrder() const;
diff --git a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
index 37b324197350..7ca337e797da 100644
--- a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
+++ b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
@@ -190,6 +190,13 @@ OperatingSystemPython::UpdateThreadList (ThreadList &old_thread_list,
auto lock = m_interpreter->AcquireInterpreterLock(); // to make sure threads_list stays alive
PythonList threads_list(m_interpreter->OSPlugin_ThreadsInfo(m_python_object_sp));
+
+ const uint32_t num_cores = core_thread_list.GetSize(false);
+
+ // Make a map so we can keep track of which cores were used from the
+ // core_thread list. Any real threads/cores that weren't used should
+ // later be put back into the "new_thread_list".
+ std::vector<bool> core_used_map(num_cores, false);
if (threads_list)
{
if (log)
@@ -207,18 +214,26 @@ OperatingSystemPython::UpdateThreadList (ThreadList &old_thread_list,
PythonDictionary thread_dict(threads_list.GetItemAtIndex(i));
if (thread_dict)
{
- ThreadSP thread_sp (CreateThreadFromThreadInfo (thread_dict, core_thread_list, old_thread_list, NULL));
+ ThreadSP thread_sp (CreateThreadFromThreadInfo (thread_dict, core_thread_list, old_thread_list, core_used_map, NULL));
if (thread_sp)
new_thread_list.AddThread(thread_sp);
}
}
}
}
-
- // No new threads added from the thread info array gotten from python, just
- // display the core threads.
- if (new_thread_list.GetSize(false) == 0)
- new_thread_list = core_thread_list;
+
+ // Any real core threads that didn't end up backing a memory thread should
+ // still be in the main thread list, and they should be inserted at the beginning
+ // of the list
+ uint32_t insert_idx = 0;
+ for (uint32_t core_idx = 0; core_idx < num_cores; ++core_idx)
+ {
+ if (core_used_map[core_idx] == false)
+ {
+ new_thread_list.InsertThread (core_thread_list.GetThreadAtIndex(core_idx, false), insert_idx);
+ ++insert_idx;
+ }
+ }
return new_thread_list.GetSize(false) > 0;
}
@@ -227,6 +242,7 @@ ThreadSP
OperatingSystemPython::CreateThreadFromThreadInfo (PythonDictionary &thread_dict,
ThreadList &core_thread_list,
ThreadList &old_thread_list,
+ std::vector<bool> &core_used_map,
bool *did_create_ptr)
{
ThreadSP thread_sp;
@@ -282,6 +298,10 @@ OperatingSystemPython::CreateThreadFromThreadInfo (PythonDictionary &thread_dict
ThreadSP core_thread_sp (core_thread_list.GetThreadAtIndex(core_number, false));
if (core_thread_sp)
{
+ // Keep track of which cores were set as the backing thread for memory threads...
+ if (core_number < core_used_map.size())
+ core_used_map[core_number] = true;
+
ThreadSP backing_core_thread_sp (core_thread_sp->GetBackingThread());
if (backing_core_thread_sp)
{
@@ -398,12 +418,13 @@ OperatingSystemPython::CreateThread (lldb::tid_t tid, addr_t context)
auto lock = m_interpreter->AcquireInterpreterLock(); // to make sure thread_info_dict stays alive
PythonDictionary thread_info_dict (m_interpreter->OSPlugin_CreateThread(m_python_object_sp, tid, context));
+ std::vector<bool> core_used_map;
if (thread_info_dict)
{
ThreadList core_threads(m_process);
ThreadList &thread_list = m_process->GetThreadList();
bool did_create = false;
- ThreadSP thread_sp (CreateThreadFromThreadInfo (thread_info_dict, core_threads, thread_list, &did_create));
+ ThreadSP thread_sp (CreateThreadFromThreadInfo (thread_info_dict, core_threads, thread_list, core_used_map, &did_create));
if (did_create)
thread_list.AddThread(thread_sp);
return thread_sp;
diff --git a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h
index 077039e50d56..3b7dd264dc62 100644
--- a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h
+++ b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h
@@ -93,6 +93,7 @@ protected:
CreateThreadFromThreadInfo (lldb_private::PythonDictionary &thread_dict,
lldb_private::ThreadList &core_thread_list,
lldb_private::ThreadList &old_thread_list,
+ std::vector<bool> &core_used_map,
bool *did_create_ptr);
DynamicRegisterInfo *
diff --git a/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp b/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
index da29c16ac3ab..7eca67ac7f57 100644
--- a/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
+++ b/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
@@ -142,7 +142,8 @@ PlatformFreeBSD::Terminate ()
/// Default Constructor
//------------------------------------------------------------------
PlatformFreeBSD::PlatformFreeBSD (bool is_host) :
-Platform(is_host)
+Platform(is_host),
+m_remote_platform_sp()
{
}
@@ -312,6 +313,7 @@ PlatformFreeBSD::GetSoftwareBreakpointTrapOpcode (Target &target, BreakpointSite
case ArchSpec::eCore_x86_32_i386:
case ArchSpec::eCore_x86_64_x86_64:
+ case ArchSpec::eCore_x86_64_x86_64h:
{
static const uint8_t g_i386_opcode[] = { 0xCC };
trap_opcode = g_i386_opcode;
@@ -571,14 +573,14 @@ PlatformFreeBSD::GetGroupName (uint32_t gid)
// From PlatformMacOSX only
Error
-PlatformFreeBSD::GetFile (const FileSpec &platform_file,
- const UUID *uuid_ptr,
- FileSpec &local_file)
+PlatformFreeBSD::GetFileWithUUID (const FileSpec &platform_file,
+ const UUID *uuid_ptr,
+ FileSpec &local_file)
{
if (IsRemote())
{
if (m_remote_platform_sp)
- return m_remote_platform_sp->GetFile (platform_file, uuid_ptr, local_file);
+ return m_remote_platform_sp->GetFileWithUUID (platform_file, uuid_ptr, local_file);
}
// Default to the local case
@@ -673,3 +675,9 @@ PlatformFreeBSD::GetStatus (Stream &strm)
Platform::GetStatus(strm);
}
+
+void
+PlatformFreeBSD::CalculateTrapHandlerSymbolNames ()
+{
+ m_trap_handlers.push_back (ConstString ("_sigtramp"));
+}
diff --git a/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h b/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
index 11d1cd609779..0682eacc5a43 100644
--- a/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
+++ b/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
@@ -144,8 +144,8 @@ public:
// Only on PlatformMacOSX:
virtual lldb_private::Error
- GetFile (const lldb_private::FileSpec &platform_file,
- const lldb_private::UUID* uuid, lldb_private::FileSpec &local_file);
+ GetFileWithUUID (const lldb_private::FileSpec &platform_file,
+ const lldb_private::UUID* uuid, lldb_private::FileSpec &local_file);
lldb_private::Error
GetSharedModule (const lldb_private::ModuleSpec &module_spec,
@@ -160,6 +160,9 @@ public:
virtual void
GetStatus (lldb_private::Stream &strm);
+ virtual void
+ CalculateTrapHandlerSymbolNames ();
+
protected:
lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a remote freebsd OS
diff --git a/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
index b5f92dcc3dcd..bb07d999c4c2 100644
--- a/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ b/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -589,3 +589,8 @@ PlatformPOSIX::SetRemoteWorkingDirectory(const lldb_private::ConstString &path)
return Platform::SetRemoteWorkingDirectory(path);
}
+void
+PlatformPOSIX::CalculateTrapHandlerSymbolNames ()
+{
+ m_trap_handlers.push_back (ConstString ("_sigtramp"));
+}
diff --git a/source/Plugins/Platform/POSIX/PlatformPOSIX.h b/source/Plugins/Platform/POSIX/PlatformPOSIX.h
index 336e0f90fcad..130c84bdface 100644
--- a/source/Plugins/Platform/POSIX/PlatformPOSIX.h
+++ b/source/Plugins/Platform/POSIX/PlatformPOSIX.h
@@ -111,8 +111,11 @@ public:
uint64_t &low,
uint64_t &high);
+ virtual void
+ CalculateTrapHandlerSymbolNames ();
+
protected:
- std::auto_ptr<lldb_private::OptionGroupOptions> m_options;
+ std::unique_ptr<lldb_private::OptionGroupOptions> m_options;
lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a remote POSIX-compliant OS
diff --git a/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 248abaf6fea7..ce5645ea74fe 100644
--- a/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -119,9 +119,9 @@ PlatformRemoteGDBServer::ResolveExecutable (const FileSpec &exe_file,
}
Error
-PlatformRemoteGDBServer::GetFile (const FileSpec &platform_file,
- const UUID *uuid_ptr,
- FileSpec &local_file)
+PlatformRemoteGDBServer::GetFileWithUUID (const FileSpec &platform_file,
+ const UUID *uuid_ptr,
+ FileSpec &local_file)
{
// Default to the local case
local_file = platform_file;
@@ -418,7 +418,21 @@ PlatformRemoteGDBServer::DebugProcess (lldb_private::ProcessLaunchInfo &launch_i
if (IsConnected())
{
lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
- uint16_t port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid);
+ ArchSpec remote_arch = GetRemoteSystemArchitecture();
+ llvm::Triple &remote_triple = remote_arch.GetTriple();
+ uint16_t port = 0;
+ if (remote_triple.getVendor() == llvm::Triple::Apple && remote_triple.getOS() == llvm::Triple::IOS)
+ {
+ // When remote debugging to iOS, we use a USB mux that always talks
+ // to localhost, so we will need the remote debugserver to accept connections
+ // only from localhost, no matter what our current hostname is
+ port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, "localhost");
+ }
+ else
+ {
+ // All other hosts should use their actual hostname
+ port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, NULL);
+ }
if (port == 0)
{
@@ -492,7 +506,21 @@ PlatformRemoteGDBServer::Attach (lldb_private::ProcessAttachInfo &attach_info,
if (IsConnected())
{
lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
- uint16_t port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid);
+ ArchSpec remote_arch = GetRemoteSystemArchitecture();
+ llvm::Triple &remote_triple = remote_arch.GetTriple();
+ uint16_t port = 0;
+ if (remote_triple.getVendor() == llvm::Triple::Apple && remote_triple.getOS() == llvm::Triple::IOS)
+ {
+ // When remote debugging to iOS, we use a USB mux that always talks
+ // to localhost, so we will need the remote debugserver to accept connections
+ // only from localhost, no matter what our current hostname is
+ port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, "localhost");
+ }
+ else
+ {
+ // All other hosts should use their actual hostname
+ port = m_gdb_client.LaunchGDBserverAndGetPort(debugserver_pid, NULL);
+ }
if (port == 0)
{
@@ -673,3 +701,9 @@ PlatformRemoteGDBServer::RunShellCommand (const char *command, // Shou
{
return m_gdb_client.RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
}
+
+void
+PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames ()
+{
+ m_trap_handlers.push_back (ConstString ("_sigtramp"));
+}
diff --git a/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h b/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
index 808fb5ed61cc..e236e97c8bb3 100644
--- a/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
+++ b/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
@@ -73,9 +73,9 @@ public:
GetDescription ();
virtual lldb_private::Error
- GetFile (const lldb_private::FileSpec &platform_file,
- const lldb_private::UUID *uuid_ptr,
- lldb_private::FileSpec &local_file);
+ GetFileWithUUID (const lldb_private::FileSpec &platform_file,
+ const lldb_private::UUID *uuid_ptr,
+ lldb_private::FileSpec &local_file);
virtual bool
GetProcessInfo (lldb::pid_t pid,
@@ -209,6 +209,9 @@ public:
std::string *command_output, // Pass NULL if you don't want the command output
uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
+ virtual void
+ CalculateTrapHandlerSymbolNames ();
+
protected:
GDBRemoteCommunicationClient m_gdb_client;
std::string m_platform_description; // After we connect we can get a more complete description of what we are connected to
diff --git a/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp b/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp
new file mode 100644
index 000000000000..493f36ca8b48
--- /dev/null
+++ b/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp
@@ -0,0 +1,69 @@
+//===-- FreeBSDThread.cpp ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+#include "lldb/Core/State.h"
+
+// Project includes
+#include "FreeBSDThread.h"
+#include "ProcessFreeBSD.h"
+#include "ProcessPOSIXLog.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+//------------------------------------------------------------------------------
+// Constructors and destructors.
+
+FreeBSDThread::FreeBSDThread(Process &process, lldb::tid_t tid)
+ : POSIXThread(process, tid)
+{
+}
+
+FreeBSDThread::~FreeBSDThread()
+{
+}
+
+//------------------------------------------------------------------------------
+// ProcessInterface protocol.
+
+void
+FreeBSDThread::WillResume(lldb::StateType resume_state)
+{
+ Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
+ if (log)
+ log->Printf("tid %lu resume_state = %s", GetID(),
+ lldb_private::StateAsCString(resume_state));
+ ProcessSP process_sp(GetProcess());
+ ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(process_sp.get());
+ int signo = GetResumeSignal();
+ bool signo_valid = process->GetUnixSignals().SignalIsValid(signo);
+
+ switch (resume_state)
+ {
+ case eStateSuspended:
+ case eStateStopped:
+ process->m_suspend_tids.push_back(GetID());
+ break;
+ case eStateRunning:
+ process->m_run_tids.push_back(GetID());
+ if (signo_valid)
+ process->m_resume_signo = signo;
+ break;
+ case eStateStepping:
+ process->m_step_tids.push_back(GetID());
+ if (signo_valid)
+ process->m_resume_signo = signo;
+ break;
+ default:
+ break;
+ }
+}
diff --git a/source/Plugins/Process/FreeBSD/FreeBSDThread.h b/source/Plugins/Process/FreeBSD/FreeBSDThread.h
new file mode 100644
index 000000000000..8741075cb60b
--- /dev/null
+++ b/source/Plugins/Process/FreeBSD/FreeBSDThread.h
@@ -0,0 +1,39 @@
+//===-- FreeBSDThread.h -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_FreeBSDThread_H_
+#define liblldb_FreeBSDThread_H_
+
+// Other libraries and framework includes
+#include "POSIXThread.h"
+
+//------------------------------------------------------------------------------
+// @class FreeBSDThread
+// @brief Abstraction of a FreeBSD thread.
+class FreeBSDThread
+ : public POSIXThread
+{
+public:
+
+ //------------------------------------------------------------------
+ // Constructors and destructors
+ //------------------------------------------------------------------
+ FreeBSDThread(lldb_private::Process &process, lldb::tid_t tid);
+
+ virtual ~FreeBSDThread();
+
+ //--------------------------------------------------------------------------
+ // FreeBSDThread internal API.
+
+ // POSIXThread override
+ virtual void
+ WillResume(lldb::StateType resume_state);
+};
+
+#endif // #ifndef liblldb_FreeBSDThread_H_
diff --git a/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp b/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
index 952ec95f5873..083f08ebba84 100644
--- a/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
+++ b/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
@@ -23,7 +23,7 @@
#include "ProcessPOSIXLog.h"
#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
#include "ProcessMonitor.h"
-#include "POSIXThread.h"
+#include "FreeBSDThread.h"
using namespace lldb;
using namespace lldb_private;
@@ -140,29 +140,136 @@ ProcessFreeBSD::DoDetach(bool keep_stopped)
return error;
}
+Error
+ProcessFreeBSD::DoResume()
+{
+ Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
+
+ // FreeBSD's ptrace() uses 0 to indicate "no signal is to be sent."
+ int resume_signal = 0;
+
+ SetPrivateState(eStateRunning);
+
+ Mutex::Locker lock(m_thread_list.GetMutex());
+ bool do_step = false;
+
+ for (tid_collection::const_iterator t_pos = m_run_tids.begin(), t_end = m_run_tids.end(); t_pos != t_end; ++t_pos)
+ {
+ m_monitor->ThreadSuspend(*t_pos, false);
+ }
+ for (tid_collection::const_iterator t_pos = m_step_tids.begin(), t_end = m_step_tids.end(); t_pos != t_end; ++t_pos)
+ {
+ m_monitor->ThreadSuspend(*t_pos, false);
+ do_step = true;
+ }
+ for (tid_collection::const_iterator t_pos = m_suspend_tids.begin(), t_end = m_suspend_tids.end(); t_pos != t_end; ++t_pos)
+ {
+ m_monitor->ThreadSuspend(*t_pos, true);
+ // XXX Cannot PT_CONTINUE properly with suspended threads.
+ do_step = true;
+ }
+
+ if (log)
+ log->Printf("process %lu resuming (%s)", GetID(), do_step ? "step" : "continue");
+ if (do_step)
+ m_monitor->SingleStep(GetID(), resume_signal);
+ else
+ m_monitor->Resume(GetID(), resume_signal);
+
+ return Error();
+}
+
bool
ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list)
{
- Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
- if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
- log->Printf ("ProcessFreeBSD::%s() (pid = %" PRIu64 ")", __FUNCTION__, GetID());
-
- bool has_updated = false;
- const lldb::pid_t pid = GetID();
- // Update the process thread list with this new thread.
- // FIXME: We should be using tid, not pid.
- assert(m_monitor);
- ThreadSP thread_sp (old_thread_list.FindThreadByID (pid, false));
- if (!thread_sp) {
- ProcessSP me = this->shared_from_this();
- thread_sp.reset(new POSIXThread(*me, pid));
- has_updated = true;
+ Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
+ if (log)
+ log->Printf("ProcessFreeBSD::%s (pid = %" PRIu64 ")", __FUNCTION__, GetID());
+
+ std::vector<lldb::pid_t> tds;
+ if (!GetMonitor().GetCurrentThreadIDs(tds))
+ {
+ return false;
}
- if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
- log->Printf ("ProcessFreeBSD::%s() updated tid = %" PRIu64, __FUNCTION__, pid);
+ ThreadList old_thread_list_copy(old_thread_list);
+ for (size_t i = 0; i < tds.size(); ++i)
+ {
+ tid_t tid = tds[i];
+ ThreadSP thread_sp (old_thread_list_copy.RemoveThreadByID(tid, false));
+ if (!thread_sp)
+ {
+ thread_sp.reset(new FreeBSDThread(*this, tid));
+ if (log)
+ log->Printf("ProcessFreeBSD::%s new tid = %" PRIu64, __FUNCTION__, tid);
+ }
+ else
+ {
+ if (log)
+ log->Printf("ProcessFreeBSD::%s existing tid = %" PRIu64, __FUNCTION__, tid);
+ }
+ new_thread_list.AddThread(thread_sp);
+ }
+ for (size_t i = 0; i < old_thread_list_copy.GetSize(false); ++i)
+ {
+ ThreadSP old_thread_sp(old_thread_list_copy.GetThreadAtIndex(i, false));
+ if (old_thread_sp)
+ {
+ if (log)
+ log->Printf("ProcessFreeBSD::%s remove tid", __FUNCTION__);
+ }
+ }
- new_thread_list.AddThread(thread_sp);
+ return true;
+}
- return has_updated; // the list has been updated
+Error
+ProcessFreeBSD::WillResume()
+{
+ m_suspend_tids.clear();
+ m_run_tids.clear();
+ m_step_tids.clear();
+ return ProcessPOSIX::WillResume();
}
+
+void
+ProcessFreeBSD::SendMessage(const ProcessMessage &message)
+{
+ Mutex::Locker lock(m_message_mutex);
+
+ switch (message.GetKind())
+ {
+ case ProcessMessage::eInvalidMessage:
+ return;
+
+ case ProcessMessage::eAttachMessage:
+ SetPrivateState(eStateStopped);
+ return;
+
+ case ProcessMessage::eLimboMessage:
+ case ProcessMessage::eExitMessage:
+ m_exit_status = message.GetExitStatus();
+ SetExitStatus(m_exit_status, NULL);
+ break;
+
+ case ProcessMessage::eSignalMessage:
+ case ProcessMessage::eSignalDeliveredMessage:
+ case ProcessMessage::eBreakpointMessage:
+ case ProcessMessage::eTraceMessage:
+ case ProcessMessage::eWatchpointMessage:
+ case ProcessMessage::eCrashMessage:
+ SetPrivateState(eStateStopped);
+ break;
+
+ case ProcessMessage::eNewThreadMessage:
+ assert(0 && "eNewThreadMessage unexpected on FreeBSD");
+ break;
+
+ case ProcessMessage::eExecMessage:
+ SetPrivateState(eStateStopped);
+ break;
+ }
+
+ m_message_queue.push(message);
+}
+
diff --git a/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h b/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h
index fb549745b80c..d6ae3462c73b 100644
--- a/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h
+++ b/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h
@@ -60,6 +60,15 @@ public:
virtual bool
UpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list);
+ virtual lldb_private::Error
+ DoResume();
+
+ virtual lldb_private::Error
+ WillResume();
+
+ virtual void
+ SendMessage(const ProcessMessage &message);
+
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
@@ -80,6 +89,16 @@ public:
EnablePluginLogging(lldb_private::Stream *strm,
lldb_private::Args &command);
+protected:
+ friend class FreeBSDThread;
+
+ typedef std::vector<lldb::tid_t> tid_collection;
+ tid_collection m_suspend_tids;
+ tid_collection m_run_tids;
+ tid_collection m_step_tids;
+
+ int m_resume_signo;
+
};
-#endif // liblldb_MacOSXProcess_H_
+#endif // liblldb_ProcessFreeBSD_H_
diff --git a/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp b/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
index ac5357916501..3b260538b190 100644
--- a/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ b/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -560,6 +560,31 @@ LwpInfoOperation::Execute(ProcessMonitor *monitor)
}
//------------------------------------------------------------------------------
+/// @class ThreadSuspendOperation
+/// @brief Implements ProcessMonitor::ThreadSuspend.
+class ThreadSuspendOperation : public Operation
+{
+public:
+ ThreadSuspendOperation(lldb::tid_t tid, bool suspend, bool &result)
+ : m_tid(tid), m_suspend(suspend), m_result(result) { }
+
+ void Execute(ProcessMonitor *monitor);
+
+private:
+ lldb::tid_t m_tid;
+ bool m_suspend;
+ bool &m_result;
+} ;
+
+void
+ThreadSuspendOperation::Execute(ProcessMonitor *monitor)
+{
+ m_result = !PTRACE(m_suspend ? PT_SUSPEND : PT_RESUME, m_tid, NULL, 0);
+}
+
+
+
+//------------------------------------------------------------------------------
/// @class EventMessageOperation
/// @brief Implements ProcessMonitor::GetEventMessage.
class EventMessageOperation : public Operation
@@ -871,7 +896,8 @@ ProcessMonitor::Launch(LaunchArgs *args)
eDupStdoutFailed,
eDupStderrFailed,
eChdirFailed,
- eExecFailed
+ eExecFailed,
+ eSetGidFailed
};
// Child process.
@@ -882,7 +908,8 @@ ProcessMonitor::Launch(LaunchArgs *args)
exit(ePtraceFailed);
// Do not inherit setgid powers.
- setgid(getgid());
+ if (setgid(getgid()) != 0)
+ exit(eSetGidFailed);
// Let us have our own process group.
setpgid(0, 0);
@@ -947,6 +974,9 @@ ProcessMonitor::Launch(LaunchArgs *args)
case eExecFailed:
args->m_error.SetErrorString("Child exec failed.");
break;
+ case eSetGidFailed:
+ args->m_error.SetErrorString("Child setgid failed.");
+ break;
default:
args->m_error.SetErrorString("Child returned unknown exit status.");
break;
@@ -1041,6 +1071,29 @@ FINISH:
return args->m_error.Success();
}
+size_t
+ProcessMonitor::GetCurrentThreadIDs(std::vector<lldb::tid_t>&thread_ids)
+{
+ lwpid_t *tids;
+ int tdcnt;
+
+ thread_ids.clear();
+
+ tdcnt = PTRACE(PT_GETNUMLWPS, m_pid, NULL, 0);
+ if (tdcnt <= 0)
+ return 0;
+ tids = (lwpid_t *)malloc(tdcnt * sizeof(*tids));
+ if (tids == NULL)
+ return 0;
+ if (PTRACE(PT_GETLWPLIST, m_pid, (void *)tids, tdcnt) < 0) {
+ free(tids);
+ return 0;
+ }
+ thread_ids = std::vector<lldb::tid_t>(tids, tids + tdcnt);
+ free(tids);
+ return thread_ids.size();
+}
+
bool
ProcessMonitor::MonitorCallback(void *callback_baton,
lldb::pid_t pid,
@@ -1073,11 +1126,11 @@ ProcessMonitor::MonitorCallback(void *callback_baton,
switch (plwp.pl_siginfo.si_signo)
{
case SIGTRAP:
- message = MonitorSIGTRAP(monitor, &plwp.pl_siginfo, pid);
+ message = MonitorSIGTRAP(monitor, &plwp.pl_siginfo, plwp.pl_lwpid);
break;
default:
- message = MonitorSignal(monitor, &plwp.pl_siginfo, pid);
+ message = MonitorSignal(monitor, &plwp.pl_siginfo, plwp.pl_lwpid);
break;
}
@@ -1090,7 +1143,7 @@ ProcessMonitor::MonitorCallback(void *callback_baton,
ProcessMessage
ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor,
- const siginfo_t *info, lldb::pid_t pid)
+ const siginfo_t *info, lldb::tid_t tid)
{
ProcessMessage message;
@@ -1111,26 +1164,26 @@ ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor,
// state of "limbo" until we are explicitly commanded to detach,
// destroy, resume, etc.
unsigned long data = 0;
- if (!monitor->GetEventMessage(pid, &data))
+ if (!monitor->GetEventMessage(tid, &data))
data = -1;
if (log)
- log->Printf ("ProcessMonitor::%s() received exit? event, data = %lx, pid = %" PRIu64, __FUNCTION__, data, pid);
- message = ProcessMessage::Limbo(pid, (data >> 8));
+ log->Printf ("ProcessMonitor::%s() received exit? event, data = %lx, tid = %" PRIu64, __FUNCTION__, data, tid);
+ message = ProcessMessage::Limbo(tid, (data >> 8));
break;
}
case 0:
case TRAP_TRACE:
if (log)
- log->Printf ("ProcessMonitor::%s() received trace event, pid = %" PRIu64, __FUNCTION__, pid);
- message = ProcessMessage::Trace(pid);
+ log->Printf ("ProcessMonitor::%s() received trace event, tid = %" PRIu64, __FUNCTION__, tid);
+ message = ProcessMessage::Trace(tid);
break;
case SI_KERNEL:
case TRAP_BRKPT:
if (log)
- log->Printf ("ProcessMonitor::%s() received breakpoint event, pid = %" PRIu64, __FUNCTION__, pid);
- message = ProcessMessage::Break(pid);
+ log->Printf ("ProcessMonitor::%s() received breakpoint event, tid = %" PRIu64, __FUNCTION__, tid);
+ message = ProcessMessage::Break(tid);
break;
}
@@ -1139,7 +1192,7 @@ ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor,
ProcessMessage
ProcessMonitor::MonitorSignal(ProcessMonitor *monitor,
- const siginfo_t *info, lldb::pid_t pid)
+ const siginfo_t *info, lldb::tid_t tid)
{
ProcessMessage message;
int signo = info->si_signo;
@@ -1163,9 +1216,9 @@ ProcessMonitor::MonitorSignal(ProcessMonitor *monitor,
"SI_USER",
info->si_pid);
if (info->si_pid == getpid())
- return ProcessMessage::SignalDelivered(pid, signo);
+ return ProcessMessage::SignalDelivered(tid, signo);
else
- return ProcessMessage::Signal(pid, signo);
+ return ProcessMessage::Signal(tid, signo);
}
if (log)
@@ -1174,30 +1227,30 @@ ProcessMonitor::MonitorSignal(ProcessMonitor *monitor,
if (signo == SIGSEGV) {
lldb::addr_t fault_addr = reinterpret_cast<lldb::addr_t>(info->si_addr);
ProcessMessage::CrashReason reason = GetCrashReasonForSIGSEGV(info);
- return ProcessMessage::Crash(pid, reason, signo, fault_addr);
+ return ProcessMessage::Crash(tid, reason, signo, fault_addr);
}
if (signo == SIGILL) {
lldb::addr_t fault_addr = reinterpret_cast<lldb::addr_t>(info->si_addr);
ProcessMessage::CrashReason reason = GetCrashReasonForSIGILL(info);
- return ProcessMessage::Crash(pid, reason, signo, fault_addr);
+ return ProcessMessage::Crash(tid, reason, signo, fault_addr);
}
if (signo == SIGFPE) {
lldb::addr_t fault_addr = reinterpret_cast<lldb::addr_t>(info->si_addr);
ProcessMessage::CrashReason reason = GetCrashReasonForSIGFPE(info);
- return ProcessMessage::Crash(pid, reason, signo, fault_addr);
+ return ProcessMessage::Crash(tid, reason, signo, fault_addr);
}
if (signo == SIGBUS) {
lldb::addr_t fault_addr = reinterpret_cast<lldb::addr_t>(info->si_addr);
ProcessMessage::CrashReason reason = GetCrashReasonForSIGBUS(info);
- return ProcessMessage::Crash(pid, reason, signo, fault_addr);
+ return ProcessMessage::Crash(tid, reason, signo, fault_addr);
}
// Everything else is "normal" and does not require any special action on
// our part.
- return ProcessMessage::Signal(pid, signo);
+ return ProcessMessage::Signal(tid, signo);
}
ProcessMessage::CrashReason
@@ -1508,6 +1561,15 @@ ProcessMonitor::GetLwpInfo(lldb::tid_t tid, void *lwpinfo, int &ptrace_err)
}
bool
+ProcessMonitor::ThreadSuspend(lldb::tid_t tid, bool suspend)
+{
+ bool result;
+ ThreadSuspendOperation op(tid, suspend, result);
+ DoOperation(&op);
+ return result;
+}
+
+bool
ProcessMonitor::GetEventMessage(lldb::tid_t tid, unsigned long *message)
{
bool result;
diff --git a/source/Plugins/Process/FreeBSD/ProcessMonitor.h b/source/Plugins/Process/FreeBSD/ProcessMonitor.h
index 44219c4eb9e3..84bbac16e5e5 100644
--- a/source/Plugins/Process/FreeBSD/ProcessMonitor.h
+++ b/source/Plugins/Process/FreeBSD/ProcessMonitor.h
@@ -104,8 +104,6 @@ public:
/// dependent) offset.
///
/// This method is provided for use by RegisterContextFreeBSD derivatives.
- /// FIXME: The FreeBSD implementation of this function should use tid in order
- /// to enable support for debugging threaded programs.
bool
ReadRegisterValue(lldb::tid_t tid, unsigned offset, const char *reg_name,
unsigned size, lldb_private::RegisterValue &value);
@@ -114,49 +112,35 @@ public:
/// (architecture dependent) offset.
///
/// This method is provided for use by RegisterContextFreeBSD derivatives.
- /// FIXME: The FreeBSD implementation of this function should use tid in order
- /// to enable support for debugging threaded programs.
bool
WriteRegisterValue(lldb::tid_t tid, unsigned offset, const char *reg_name,
const lldb_private::RegisterValue &value);
/// Reads all general purpose registers into the specified buffer.
- /// FIXME: The FreeBSD implementation of this function should use tid in order
- /// to enable support for debugging threaded programs.
bool
ReadGPR(lldb::tid_t tid, void *buf, size_t buf_size);
/// Reads all floating point registers into the specified buffer.
- /// FIXME: The FreeBSD implementation of this function should use tid in order
- /// to enable support for debugging threaded programs.
bool
ReadFPR(lldb::tid_t tid, void *buf, size_t buf_size);
/// Reads the specified register set into the specified buffer.
///
/// This method is provided for use by RegisterContextFreeBSD derivatives.
- /// FIXME: The FreeBSD implementation of this function should use tid in order
- /// to enable support for debugging threaded programs.
bool
ReadRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size, unsigned int regset);
/// Writes all general purpose registers into the specified buffer.
- /// FIXME: The FreeBSD implementation of this function should use tid in order
- /// to enable support for debugging threaded programs.
bool
WriteGPR(lldb::tid_t tid, void *buf, size_t buf_size);
/// Writes all floating point registers into the specified buffer.
- /// FIXME: The FreeBSD implementation of this function should use tid in order
- /// to enable support for debugging threaded programs.
bool
WriteFPR(lldb::tid_t tid, void *buf, size_t buf_size);
/// Writes the specified register set into the specified buffer.
///
/// This method is provided for use by RegisterContextFreeBSD derivatives.
- /// FIXME: The FreeBSD implementation of this function should use tid in order
- /// to enable support for debugging threaded programs.
bool
WriteRegisterSet(lldb::tid_t tid, void *buf, size_t buf_size, unsigned int regset);
@@ -164,11 +148,19 @@ public:
bool
ReadThreadPointer(lldb::tid_t tid, lldb::addr_t &value);
+ /// Returns current thread IDs in process
+ size_t
+ GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids);
+
/// Writes a ptrace_lwpinfo structure corresponding to the given thread ID
/// to the memory region pointed to by @p lwpinfo.
bool
GetLwpInfo(lldb::tid_t tid, void *lwpinfo, int &error_no);
+ /// Suspends or unsuspends a thread prior to process resume or step.
+ bool
+ ThreadSuspend(lldb::tid_t tid, bool suspend);
+
/// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG)
/// corresponding to the given thread IDto the memory pointed to by @p
/// message.
diff --git a/source/Plugins/Process/POSIX/POSIXThread.cpp b/source/Plugins/Process/POSIX/POSIXThread.cpp
index 16399748c544..8d4c71ff269a 100644
--- a/source/Plugins/Process/POSIX/POSIXThread.cpp
+++ b/source/Plugins/Process/POSIX/POSIXThread.cpp
@@ -83,6 +83,7 @@ POSIXThread::GetMonitor()
return process.GetMonitor();
}
+// Overridden by FreeBSDThread; this is used only on Linux.
void
POSIXThread::RefreshStateAfterStop()
{
@@ -150,8 +151,6 @@ POSIXThread::GetRegisterContext()
{
case ArchSpec::eCore_mips64:
{
- RegisterInfoInterface *reg_interface = NULL;
-
switch (target_arch.GetTriple().getOS())
{
case llvm::Triple::FreeBSD:
@@ -257,6 +256,7 @@ POSIXThread::GetUnwinder()
return m_unwinder_ap.get();
}
+// Overridden by FreeBSDThread; this is used only on Linux.
void
POSIXThread::WillResume(lldb::StateType resume_state)
{
diff --git a/source/Plugins/Process/POSIX/ProcessPOSIX.cpp b/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
index 70ad3a66d9ef..62394623c59d 100644
--- a/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
+++ b/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
@@ -200,7 +200,7 @@ ProcessPOSIX::GetFilePath(
Error
ProcessPOSIX::DoLaunch (Module *module,
- const ProcessLaunchInfo &launch_info)
+ ProcessLaunchInfo &launch_info)
{
Error error;
assert(m_monitor == NULL);
@@ -632,20 +632,6 @@ ProcessPOSIX::DoDeallocateMemory(lldb::addr_t addr)
return error;
}
-addr_t
-ProcessPOSIX::ResolveIndirectFunction(const Address *address, Error &error)
-{
- addr_t function_addr = LLDB_INVALID_ADDRESS;
- if (address == NULL) {
- error.SetErrorStringWithFormat("unable to determine direct function call for NULL address");
- } else if (!InferiorCall(this, address, function_addr)) {
- function_addr = LLDB_INVALID_ADDRESS;
- error.SetErrorStringWithFormat("unable to determine direct function call for indirect function %s",
- address->CalculateSymbolContextSymbol()->GetName().AsCString());
- }
- return function_addr;
-}
-
size_t
ProcessPOSIX::GetSoftwareBreakpointTrapOpcode(BreakpointSite* bp_site)
{
diff --git a/source/Plugins/Process/POSIX/ProcessPOSIX.h b/source/Plugins/Process/POSIX/ProcessPOSIX.h
index 790041be321a..7f705d33fe68 100644
--- a/source/Plugins/Process/POSIX/ProcessPOSIX.h
+++ b/source/Plugins/Process/POSIX/ProcessPOSIX.h
@@ -58,7 +58,7 @@ public:
virtual lldb_private::Error
DoLaunch (lldb_private::Module *exe_module,
- const lldb_private::ProcessLaunchInfo &launch_info);
+ lldb_private::ProcessLaunchInfo &launch_info);
virtual void
DidLaunch();
@@ -104,9 +104,6 @@ public:
virtual lldb_private::Error
DoDeallocateMemory(lldb::addr_t ptr);
- virtual lldb::addr_t
- ResolveIndirectFunction(const lldb_private::Address *address, lldb_private::Error &error);
-
virtual size_t
GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site);
@@ -148,7 +145,8 @@ public:
// ProcessPOSIX internal API.
/// Registers the given message with this process.
- void SendMessage(const ProcessMessage &message);
+ virtual void
+ SendMessage(const ProcessMessage &message);
ProcessMonitor &
GetMonitor() { assert(m_monitor); return *m_monitor; }
diff --git a/source/Plugins/Process/Utility/HistoryThread.cpp b/source/Plugins/Process/Utility/HistoryThread.cpp
index 521136295fd5..d045bc7e10d7 100644
--- a/source/Plugins/Process/Utility/HistoryThread.cpp
+++ b/source/Plugins/Process/Utility/HistoryThread.cpp
@@ -25,7 +25,7 @@ HistoryThread::HistoryThread (lldb_private::Process &process,
std::vector<lldb::addr_t> pcs,
uint32_t stop_id,
bool stop_id_is_valid) :
- Thread (process, LLDB_INVALID_THREAD_ID),
+ Thread (process, tid),
m_framelist_mutex(),
m_framelist(),
m_pcs (pcs),
diff --git a/source/Plugins/Process/Utility/HistoryThread.h b/source/Plugins/Process/Utility/HistoryThread.h
index 01fdd1608706..f9a431d8340b 100644
--- a/source/Plugins/Process/Utility/HistoryThread.h
+++ b/source/Plugins/Process/Utility/HistoryThread.h
@@ -22,6 +22,16 @@
namespace lldb_private {
+//----------------------------------------------------------------------
+/// @class HistoryThread HistoryThread.h "HistoryThread.h"
+/// @brief A thread object representing a backtrace from a previous point in the process execution
+///
+/// This subclass of Thread is used to provide a backtrace from earlier in
+/// process execution. It is given a backtrace list of pc addresses and
+/// optionally a stop_id of when those pc addresses were collected, and it will
+/// create stack frames for them.
+//----------------------------------------------------------------------
+
class HistoryThread : public lldb_private::Thread
{
public:
diff --git a/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp b/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
index 6d1b04f7f1a7..1d5d19fad25f 100644
--- a/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ b/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -34,9 +34,16 @@
using namespace lldb;
using namespace lldb_private;
-bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
- addr_t addr, addr_t length, unsigned prot,
- unsigned flags, addr_t fd, addr_t offset) {
+bool
+lldb_private::InferiorCallMmap (Process *process,
+ addr_t &allocated_addr,
+ addr_t addr,
+ addr_t length,
+ unsigned prot,
+ unsigned flags,
+ addr_t fd,
+ addr_t offset)
+{
Thread *thread = process->GetThreadList().GetSelectedThread().get();
if (thread == NULL)
return false;
@@ -139,8 +146,11 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
return false;
}
-bool lldb_private::InferiorCallMunmap(Process *process, addr_t addr,
- addr_t length) {
+bool
+lldb_private::InferiorCallMunmap (Process *process,
+ addr_t addr,
+ addr_t length)
+{
Thread *thread = process->GetThreadList().GetSelectedThread().get();
if (thread == NULL)
return false;
@@ -209,7 +219,14 @@ bool lldb_private::InferiorCallMunmap(Process *process, addr_t addr,
return false;
}
-bool lldb_private::InferiorCall(Process *process, const Address *address, addr_t &returned_func) {
+// FIXME: This has nothing to do with Posix, it is just a convenience function that calls a
+// function of the form "void * (*)(void)". We should find a better place to put this.
+
+bool
+lldb_private::InferiorCall (Process *process,
+ const Address *address,
+ addr_t &returned_func)
+{
Thread *thread = process->GetThreadList().GetSelectedThread().get();
if (thread == NULL || address == NULL)
return false;
@@ -233,7 +250,7 @@ bool lldb_private::InferiorCall(Process *process, const Address *address, addr_t
lldb::ThreadPlanSP call_plan_sp (call_function_thread_plan);
if (call_plan_sp)
{
- StreamFile error_strm;
+ StreamString error_strm;
// This plan is a utility plan, so set it to discard itself when done.
call_plan_sp->SetIsMasterPlan (true);
call_plan_sp->SetOkayToDiscard(true);
diff --git a/source/Plugins/Process/Utility/RegisterContextLLDB.cpp b/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
index c19aec3a02c7..f87db5810740 100644
--- a/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
@@ -21,15 +21,17 @@
#include "lldb/Symbol/FuncUnwinders.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/ObjectFile.h"
-#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/Symbol.h"
+#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Target/ABI.h"
+#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
-#include "lldb/Target/DynamicLoader.h"
#include "RegisterContextLLDB.h"
@@ -75,13 +77,44 @@ RegisterContextLLDB::RegisterContextLLDB
// This same code exists over in the GetFullUnwindPlanForFrame() but it may not have been executed yet
if (IsFrameZero()
- || next_frame->m_frame_type == eSigtrampFrame
+ || next_frame->m_frame_type == eTrapHandlerFrame
|| next_frame->m_frame_type == eDebuggerFrame)
{
m_all_registers_available = true;
}
}
+bool
+RegisterContextLLDB::IsUnwindPlanValidForCurrentPC(lldb::UnwindPlanSP unwind_plan_sp, int &valid_pc_offset)
+{
+ if (!unwind_plan_sp)
+ return false;
+
+ // check if m_current_pc is valid
+ if (unwind_plan_sp->PlanValidAtAddress(m_current_pc))
+ {
+ // yes - current offset can be used as is
+ valid_pc_offset = m_current_offset;
+ return true;
+ }
+
+ // if m_current_offset <= 0, we've got nothing else to try
+ if (m_current_offset <= 0)
+ return false;
+
+ // check pc - 1 to see if it's valid
+ Address pc_minus_one (m_current_pc);
+ pc_minus_one.SetOffset(m_current_pc.GetOffset() - 1);
+ if (unwind_plan_sp->PlanValidAtAddress(pc_minus_one))
+ {
+ // *valid_pc_offset = m_current_offset - 1;
+ valid_pc_offset = m_current_pc.GetOffset() - 1;
+ return true;
+ }
+
+ return false;
+}
+
// Initialize a RegisterContextLLDB which is the first frame of a stack -- the zeroth frame or currently
// executing frame.
@@ -95,6 +128,7 @@ RegisterContextLLDB::InitializeZerothFrame()
if (reg_ctx_sp.get() == NULL)
{
m_frame_type = eNotAValidFrame;
+ UnwindLogMsg ("frame does not have a register context");
return;
}
@@ -103,6 +137,7 @@ RegisterContextLLDB::InitializeZerothFrame()
if (current_pc == LLDB_INVALID_ADDRESS)
{
m_frame_type = eNotAValidFrame;
+ UnwindLogMsg ("frame does not have a pc");
return;
}
@@ -117,7 +152,7 @@ RegisterContextLLDB::InitializeZerothFrame()
current_pc = abi->FixCodeAddress(current_pc);
// Initialize m_current_pc, an Address object, based on current_pc, an addr_t.
- process->GetTarget().GetSectionLoadList().ResolveLoadAddress (current_pc, m_current_pc);
+ m_current_pc.SetLoadAddress (current_pc, &process->GetTarget());
// If we don't have a Module for some reason, we're not going to find symbol/function information - just
// stick in some reasonable defaults and hope we can unwind past this frame.
@@ -137,11 +172,9 @@ RegisterContextLLDB::InitializeZerothFrame()
AddressRange addr_range;
m_sym_ctx.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, addr_range);
- static ConstString g_sigtramp_name ("_sigtramp");
- if ((m_sym_ctx.function && m_sym_ctx.function->GetName() == g_sigtramp_name) ||
- (m_sym_ctx.symbol && m_sym_ctx.symbol->GetName() == g_sigtramp_name))
+ if (IsTrapHandlerSymbol (process, m_sym_ctx))
{
- m_frame_type = eSigtrampFrame;
+ m_frame_type = eTrapHandlerFrame;
}
else
{
@@ -197,6 +230,7 @@ RegisterContextLLDB::InitializeZerothFrame()
if (!active_row.get())
{
+ UnwindLogMsg ("could not find an unwindplan row for this frame's pc");
m_frame_type = eNotAValidFrame;
return;
}
@@ -205,6 +239,7 @@ RegisterContextLLDB::InitializeZerothFrame()
addr_t cfa_regval = LLDB_INVALID_ADDRESS;
if (!ReadGPRValue (row_register_kind, active_row->GetCFARegister(), cfa_regval))
{
+ UnwindLogMsg ("could not read CFA register for this frame.");
m_frame_type = eNotAValidFrame;
return;
}
@@ -229,17 +264,20 @@ RegisterContextLLDB::InitializeNonZerothFrame()
if (IsFrameZero ())
{
m_frame_type = eNotAValidFrame;
+ UnwindLogMsg ("non-zeroth frame tests positive for IsFrameZero -- that shouldn't happen.");
return;
}
if (!GetNextFrame().get() || !GetNextFrame()->IsValid())
{
m_frame_type = eNotAValidFrame;
+ UnwindLogMsg ("Could not get next frame, marking this frame as invalid.");
return;
}
if (!m_thread.GetRegisterContext())
{
m_frame_type = eNotAValidFrame;
+ UnwindLogMsg ("Could not get register context for this thread, marking this frame as invalid.");
return;
}
@@ -265,6 +303,7 @@ RegisterContextLLDB::InitializeNonZerothFrame()
if (pc == 0)
{
m_frame_type = eNotAValidFrame;
+ UnwindLogMsg ("this frame has a pc of 0x0");
return;
}
@@ -276,7 +315,7 @@ RegisterContextLLDB::InitializeNonZerothFrame()
if (abi)
pc = abi->FixCodeAddress(pc);
- process->GetTarget().GetSectionLoadList().ResolveLoadAddress (pc, m_current_pc);
+ m_current_pc.SetLoadAddress (pc, &process->GetTarget());
// If we don't have a Module for some reason, we're not going to find symbol/function information - just
// stick in some reasonable defaults and hope we can unwind past this frame.
@@ -304,6 +343,7 @@ RegisterContextLLDB::InitializeNonZerothFrame()
{
// anywhere other than the second frame, a non-executable pc means we're off in the weeds -- stop now.
m_frame_type = eNotAValidFrame;
+ UnwindLogMsg ("pc is in a non-executable section of memory and this isn't the 2nd frame in the stack walk.");
return;
}
}
@@ -352,6 +392,7 @@ RegisterContextLLDB::InitializeNonZerothFrame()
&& (permissions & ePermissionsReadable) == 0)
{
m_frame_type = eNotAValidFrame;
+ UnwindLogMsg ("the CFA points to a region of memory that is not readable");
return;
}
}
@@ -366,10 +407,15 @@ RegisterContextLLDB::InitializeNonZerothFrame()
return;
}
m_frame_type = eNotAValidFrame;
+ UnwindLogMsg ("could not find any symbol for this pc, or a default unwind plan, to continue unwind.");
return;
}
bool resolve_tail_call_address = true; // m_current_pc can be one past the address range of the function...
+ // This will handle the case where the saved pc does not point to
+ // a function/symbol because it is beyond the bounds of the correct
+ // function and there's no symbol there. ResolveSymbolContextForAddress
+ // will fail to find a symbol, back up the pc by 1 and re-search.
uint32_t resolved_scope = pc_module_sp->ResolveSymbolContextForAddress (m_current_pc,
eSymbolContextFunction | eSymbolContextSymbol,
m_sym_ctx, resolve_tail_call_address);
@@ -392,18 +438,35 @@ RegisterContextLLDB::InitializeNonZerothFrame()
if (m_sym_ctx_valid == false)
decr_pc_and_recompute_addr_range = true;
- // Or if we're in the middle of the stack (and not "above" an asynchronous event like sigtramp), and
- // our "current" pc is the start of a function or our "current" pc is one past the end of a function...
+ // Or if we're in the middle of the stack (and not "above" an asynchronous event like sigtramp),
+ // and our "current" pc is the start of a function...
if (m_sym_ctx_valid
- && GetNextFrame()->m_frame_type != eSigtrampFrame
+ && GetNextFrame()->m_frame_type != eTrapHandlerFrame
&& GetNextFrame()->m_frame_type != eDebuggerFrame
&& addr_range.GetBaseAddress().IsValid()
- && addr_range.GetBaseAddress().GetSection() == m_current_pc.GetSection())
+ && addr_range.GetBaseAddress().GetSection() == m_current_pc.GetSection()
+ && addr_range.GetBaseAddress().GetOffset() == m_current_pc.GetOffset())
{
- if (addr_range.GetBaseAddress().GetOffset() == m_current_pc.GetOffset() ||
- addr_range.GetBaseAddress().GetOffset() + addr_range.GetByteSize() == m_current_pc.GetOffset())
+ decr_pc_and_recompute_addr_range = true;
+ }
+
+ // We need to back up the pc by 1 byte and re-search for the Symbol to handle the case where the "saved pc"
+ // value is pointing to the next function, e.g. if a function ends with a CALL instruction.
+ // FIXME this may need to be an architectural-dependent behavior; if so we'll need to add a member function
+ // to the ABI plugin and consult that.
+ if (decr_pc_and_recompute_addr_range)
+ {
+ Address temporary_pc(m_current_pc);
+ temporary_pc.SetOffset(m_current_pc.GetOffset() - 1);
+ m_sym_ctx.Clear(false);
+ m_sym_ctx_valid = false;
+ if ((pc_module_sp->ResolveSymbolContextForAddress (temporary_pc, eSymbolContextFunction| eSymbolContextSymbol, m_sym_ctx) & eSymbolContextSymbol) == eSymbolContextSymbol)
+ {
+ m_sym_ctx_valid = true;
+ }
+ if (!m_sym_ctx.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, addr_range))
{
- decr_pc_and_recompute_addr_range = true;
+ m_sym_ctx_valid = false;
}
}
@@ -428,11 +491,9 @@ RegisterContextLLDB::InitializeNonZerothFrame()
m_current_offset_backed_up_one = -1;
}
- static ConstString sigtramp_name ("_sigtramp");
- if ((m_sym_ctx.function && m_sym_ctx.function->GetMangled().GetMangledName() == sigtramp_name)
- || (m_sym_ctx.symbol && m_sym_ctx.symbol->GetMangled().GetMangledName() == sigtramp_name))
+ if (IsTrapHandlerSymbol (process, m_sym_ctx))
{
- m_frame_type = eSigtrampFrame;
+ m_frame_type = eTrapHandlerFrame;
}
else
{
@@ -467,9 +528,10 @@ RegisterContextLLDB::InitializeNonZerothFrame()
else
{
m_full_unwind_plan_sp = GetFullUnwindPlanForFrame ();
- if (m_full_unwind_plan_sp && m_full_unwind_plan_sp->PlanValidAtAddress (m_current_pc))
+ int valid_offset = -1;
+ if (IsUnwindPlanValidForCurrentPC(m_full_unwind_plan_sp, valid_offset))
{
- active_row = m_full_unwind_plan_sp->GetRowForFunctionOffset (m_current_offset);
+ active_row = m_full_unwind_plan_sp->GetRowForFunctionOffset (valid_offset);
row_register_kind = m_full_unwind_plan_sp->GetRegisterKind ();
if (active_row.get() && log)
{
@@ -483,6 +545,7 @@ RegisterContextLLDB::InitializeNonZerothFrame()
if (!active_row.get())
{
m_frame_type = eNotAValidFrame;
+ UnwindLogMsg ("could not find unwind row for this pc");
return;
}
@@ -551,7 +614,7 @@ RegisterContextLLDB::IsFrameZero () const
//
// On entry to this method,
//
-// 1. m_frame_type should already be set to eSigtrampFrame/eDebuggerFrame if either of those are correct,
+// 1. m_frame_type should already be set to eTrapHandlerFrame/eDebuggerFrame if either of those are correct,
// 2. m_sym_ctx should already be filled in, and
// 3. m_current_pc should have the current pc value for this frame
// 4. m_current_offset_backed_up_one should have the current byte offset into the function, maybe backed up by 1, -1 if unknown
@@ -573,7 +636,7 @@ RegisterContextLLDB::GetFastUnwindPlanForFrame ()
return unwind_plan_sp;
// If we're in _sigtramp(), unwinding past this frame requires special knowledge.
- if (m_frame_type == eSigtrampFrame || m_frame_type == eDebuggerFrame)
+ if (m_frame_type == eTrapHandlerFrame || m_frame_type == eDebuggerFrame)
return unwind_plan_sp;
unwind_plan_sp = func_unwinders_sp->GetUnwindPlanFastUnwind (m_thread);
@@ -602,7 +665,7 @@ RegisterContextLLDB::GetFastUnwindPlanForFrame ()
// On entry to this method,
//
-// 1. m_frame_type should already be set to eSigtrampFrame/eDebuggerFrame if either of those are correct,
+// 1. m_frame_type should already be set to eTrapHandlerFrame/eDebuggerFrame if either of those are correct,
// 2. m_sym_ctx should already be filled in, and
// 3. m_current_pc should have the current pc value for this frame
// 4. m_current_offset_backed_up_one should have the current byte offset into the function, maybe backed up by 1, -1 if unknown
@@ -627,7 +690,7 @@ RegisterContextLLDB::GetFullUnwindPlanForFrame ()
bool behaves_like_zeroth_frame = false;
if (IsFrameZero ()
- || GetNextFrame()->m_frame_type == eSigtrampFrame
+ || GetNextFrame()->m_frame_type == eTrapHandlerFrame
|| GetNextFrame()->m_frame_type == eDebuggerFrame)
{
behaves_like_zeroth_frame = true;
@@ -648,7 +711,7 @@ RegisterContextLLDB::GetFullUnwindPlanForFrame ()
uint32_t permissions;
addr_t current_pc_addr = m_current_pc.GetLoadAddress (exe_ctx.GetTargetPtr());
if (current_pc_addr == 0
- || (process->GetLoadAddressPermissions(current_pc_addr, permissions)
+ || (process->GetLoadAddressPermissions (current_pc_addr, permissions)
&& (permissions & ePermissionsExecutable) == 0))
{
unwind_plan_sp.reset (new UnwindPlan (lldb::eRegisterKindGeneric));
@@ -697,7 +760,7 @@ RegisterContextLLDB::GetFullUnwindPlanForFrame ()
// is properly encoded in the eh_frame section, so prefer that if available.
// On other platforms we may need to provide a platform-specific UnwindPlan which encodes the details of
// how to unwind out of sigtramp.
- if (m_frame_type == eSigtrampFrame)
+ if (m_frame_type == eTrapHandlerFrame)
{
m_fast_unwind_plan_sp.reset();
unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtCallSite (m_current_offset_backed_up_one);
@@ -735,7 +798,8 @@ RegisterContextLLDB::GetFullUnwindPlanForFrame ()
// Typically this is unwind info from an eh_frame section intended for exception handling; only valid at call sites
unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtCallSite (m_current_offset_backed_up_one);
- if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress (m_current_pc))
+ int valid_offset = -1;
+ if (IsUnwindPlanValidForCurrentPC(unwind_plan_sp, valid_offset))
{
UnwindLogMsgVerbose ("frame uses %s for full UnwindPlan", unwind_plan_sp->GetSourceName().GetCString());
return unwind_plan_sp;
@@ -744,7 +808,7 @@ RegisterContextLLDB::GetFullUnwindPlanForFrame ()
// We'd prefer to use an UnwindPlan intended for call sites when we're at a call site but if we've
// struck out on that, fall back to using the non-call-site assembly inspection UnwindPlan if possible.
unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtNonCallSite (m_thread);
- if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress (m_current_pc))
+ if (IsUnwindPlanValidForCurrentPC(unwind_plan_sp, valid_offset))
{
UnwindLogMsgVerbose ("frame uses %s for full UnwindPlan", unwind_plan_sp->GetSourceName().GetCString());
return unwind_plan_sp;
@@ -915,6 +979,12 @@ RegisterContextLLDB::IsValid () const
return m_frame_type != eNotAValidFrame;
}
+bool
+RegisterContextLLDB::IsTrapHandlerFrame () const
+{
+ return m_frame_type == eTrapHandlerFrame;
+}
+
// A skip frame is a bogus frame on the stack -- but one where we're likely to find a real frame farther
// up the stack if we keep looking. It's always the second frame in an unwind (i.e. the first frame after
// frame zero) where unwinding can be the trickiest. Ideally we'll mark up this frame in some way so the
@@ -927,6 +997,35 @@ RegisterContextLLDB::IsSkipFrame () const
return m_frame_type == eSkipFrame;
}
+bool
+RegisterContextLLDB::IsTrapHandlerSymbol (lldb_private::Process *process, const lldb_private::SymbolContext &m_sym_ctx) const
+{
+ PlatformSP platform_sp (process->GetTarget().GetPlatform());
+ if (platform_sp)
+ {
+ const std::vector<ConstString> trap_handler_names (platform_sp->GetTrapHandlerSymbolNames());
+ for (ConstString name : trap_handler_names)
+ {
+ if ((m_sym_ctx.function && m_sym_ctx.function->GetName() == name) ||
+ (m_sym_ctx.symbol && m_sym_ctx.symbol->GetName() == name))
+ {
+ return true;
+ }
+ }
+ }
+ const std::vector<ConstString> user_specified_trap_handler_names (m_parent_unwind.GetUserSpecifiedTrapHandlerFunctionNames());
+ for (ConstString name : user_specified_trap_handler_names)
+ {
+ if ((m_sym_ctx.function && m_sym_ctx.function->GetName() == name) ||
+ (m_sym_ctx.symbol && m_sym_ctx.symbol->GetName() == name))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
// Answer the question: Where did THIS frame save the CALLER frame ("previous" frame)'s register value?
enum UnwindLLDB::RegisterSearchResult
@@ -1161,7 +1260,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
regloc.type = UnwindLLDB::RegisterLocation::eRegisterValueInferred;
regloc.location.inferred_value = m_cfa + offset;
m_registers[lldb_regnum] = regloc;
- UnwindLogMsg ("supplying caller's register %d, value is CFA plus offset", lldb_regnum);
+ UnwindLogMsg ("supplying caller's register %d, value is CFA plus offset %d", lldb_regnum, offset);
return UnwindLLDB::RegisterSearchResult::eRegisterFound;
}
@@ -1171,7 +1270,7 @@ RegisterContextLLDB::SavedLocationForRegister (uint32_t lldb_regnum, lldb_privat
regloc.type = UnwindLLDB::RegisterLocation::eRegisterSavedAtMemoryLocation;
regloc.location.target_memory_location = m_cfa + offset;
m_registers[lldb_regnum] = regloc;
- UnwindLogMsg ("supplying caller's register %d from the stack, saved at CFA plus offset", lldb_regnum);
+ UnwindLogMsg ("supplying caller's register %d from the stack, saved at CFA plus offset %d", lldb_regnum, offset);
return UnwindLLDB::RegisterSearchResult::eRegisterFound;
}
@@ -1550,3 +1649,4 @@ RegisterContextLLDB::UnwindLogMsgVerbose (const char *fmt, ...)
}
}
+
diff --git a/source/Plugins/Process/Utility/RegisterContextLLDB.h b/source/Plugins/Process/Utility/RegisterContextLLDB.h
index dc6d8c61fa4a..bf9dd9a29319 100644
--- a/source/Plugins/Process/Utility/RegisterContextLLDB.h
+++ b/source/Plugins/Process/Utility/RegisterContextLLDB.h
@@ -73,6 +73,9 @@ public:
IsValid () const;
bool
+ IsTrapHandlerFrame () const;
+
+ bool
GetCFA (lldb::addr_t& cfa);
bool
@@ -86,7 +89,7 @@ private:
enum FrameType
{
eNormalFrame,
- eSigtrampFrame,
+ eTrapHandlerFrame,
eDebuggerFrame, // a debugger inferior function call frame; we get caller's registers from debugger
eSkipFrame, // The unwind resulted in a bogus frame but may get back on track so we don't want to give up yet
eNotAValidFrame // this frame is invalid for some reason - most likely it is past the top (end) of the stack
@@ -120,6 +123,19 @@ private:
bool
IsSkipFrame () const;
+
+ //------------------------------------------------------------------
+ /// Determines if a SymbolContext is a trap handler or not
+ ///
+ /// Given a SymbolContext, determines if this is a trap handler function
+ /// aka asynchronous signal handler.
+ ///
+ /// @return
+ /// Returns true if the SymbolContext is a trap handler.
+ //------------------------------------------------------------------
+ bool
+ IsTrapHandlerSymbol (lldb_private::Process *process, const lldb_private::SymbolContext &m_sym_ctx) const;
+
// Provide a location for where THIS function saved the CALLER's register value
// Or a frame "below" this one saved it, i.e. a function called by this one, preserved a register that this
// function didn't modify/use.
@@ -164,6 +180,10 @@ private:
void
UnwindLogMsgVerbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
+ bool
+ IsUnwindPlanValidForCurrentPC(lldb::UnwindPlanSP unwind_plan_sp, int &valid_pc_offset);
+
+
lldb_private::Thread& m_thread;
///
diff --git a/source/Plugins/Process/Utility/UnwindLLDB.cpp b/source/Plugins/Process/Utility/UnwindLLDB.cpp
index 552ae501bd21..a3a7002ea099 100644
--- a/source/Plugins/Process/Utility/UnwindLLDB.cpp
+++ b/source/Plugins/Process/Utility/UnwindLLDB.cpp
@@ -26,8 +26,21 @@ using namespace lldb_private;
UnwindLLDB::UnwindLLDB (Thread &thread) :
Unwind (thread),
m_frames(),
- m_unwind_complete(false)
+ m_unwind_complete(false),
+ m_user_supplied_trap_handler_functions()
{
+ ProcessSP process_sp(thread.GetProcess());
+ if (process_sp)
+ {
+ Args args;
+ process_sp->GetTarget().GetUserSpecifiedTrapHandlerNames (args);
+ size_t count = args.GetArgumentCount();
+ for (size_t i = 0; i < count; i++)
+ {
+ const char *func_name = args.GetArgumentAtIndex(i);
+ m_user_supplied_trap_handler_functions.push_back (ConstString (func_name));
+ }
+ }
}
uint32_t
@@ -95,7 +108,13 @@ UnwindLLDB::AddFirstFrame ()
first_cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
m_frames.push_back (first_cursor_sp);
return true;
+
unwind_done:
+ Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND));
+ if (log)
+ {
+ log->Printf ("th%d Unwind of this thread is complete.", m_thread.GetIndexID());
+ }
m_unwind_complete = true;
return false;
}
@@ -138,7 +157,12 @@ UnwindLLDB::AddOneMoreFrame (ABI *abi)
}
if (reg_ctx_sp.get() == NULL)
+ {
+ if (log)
+ log->Printf ("%*sFrame %d did not get a RegisterContext, stopping.",
+ cur_idx < 100 ? cur_idx : 100, "", cur_idx);
goto unwind_done;
+ }
if (!reg_ctx_sp->IsValid())
{
@@ -160,12 +184,18 @@ UnwindLLDB::AddOneMoreFrame (ABI *abi)
}
if (abi && !abi->CallFrameAddressIsValid(cursor_sp->cfa))
{
- if (log)
+ // On Mac OS X, the _sigtramp asynchronous signal trampoline frame may not have
+ // its (constructed) CFA aligned correctly -- don't do the abi alignment check for
+ // these.
+ if (reg_ctx_sp->IsTrapHandlerFrame() == false)
{
- log->Printf("%*sFrame %d did not get a valid CFA for this frame, stopping stack walk",
- cur_idx < 100 ? cur_idx : 100, "", cur_idx);
+ if (log)
+ {
+ log->Printf("%*sFrame %d did not get a valid CFA for this frame, stopping stack walk",
+ cur_idx < 100 ? cur_idx : 100, "", cur_idx);
+ }
+ goto unwind_done;
}
- goto unwind_done;
}
if (!reg_ctx_sp->ReadPC (cursor_sp->start_pc))
{
@@ -185,12 +215,26 @@ UnwindLLDB::AddOneMoreFrame (ABI *abi)
}
goto unwind_done;
}
+ if (!m_frames.empty())
+ {
+ // Infinite loop where the current cursor is the same as the previous one...
+ if (m_frames.back()->start_pc == cursor_sp->start_pc && m_frames.back()->cfa == cursor_sp->cfa)
+ {
+ if (log)
+ log->Printf ("th%d pc of this frame is the same as the previous frame and CFAs for both frames are identical -- stopping unwind", m_thread.GetIndexID());
+ goto unwind_done;
+ }
+ }
cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
m_frames.push_back (cursor_sp);
return true;
unwind_done:
+ if (log)
+ {
+ log->Printf ("th%d Unwind of this thread is complete.", m_thread.GetIndexID());
+ }
m_unwind_complete = true;
return false;
}
diff --git a/source/Plugins/Process/Utility/UnwindLLDB.h b/source/Plugins/Process/Utility/UnwindLLDB.h
index 5725654a6869..eb5400389df3 100644
--- a/source/Plugins/Process/Utility/UnwindLLDB.h
+++ b/source/Plugins/Process/Utility/UnwindLLDB.h
@@ -13,6 +13,7 @@
#include <vector>
#include "lldb/lldb-public.h"
+#include "lldb/Core/ConstString.h"
#include "lldb/Symbol/FuncUnwinders.h"
#include "lldb/Symbol/UnwindPlan.h"
#include "lldb/Target/RegisterContext.h"
@@ -90,6 +91,24 @@ protected:
SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc, uint32_t starting_frame_num, bool pc_register);
+ //------------------------------------------------------------------
+ /// Provide the list of user-specified trap handler functions
+ ///
+ /// The Platform is one source of trap handler function names; that
+ /// may be augmented via a setting. The setting needs to be converted
+ /// into an array of ConstStrings before it can be used - we only want
+ /// to do that once per thread so it's here in the UnwindLLDB object.
+ ///
+ /// @return
+ /// Vector of ConstStrings of trap handler function names. May be
+ /// empty.
+ //------------------------------------------------------------------
+ const std::vector<ConstString> &
+ GetUserSpecifiedTrapHandlerFunctionNames ()
+ {
+ return m_user_supplied_trap_handler_functions;
+ }
+
private:
struct Cursor
@@ -110,6 +129,7 @@ private:
// number of frames, etc. Otherwise we've only gone as far as directly asked, and m_frames.size()
// is how far we've currently gone.
+ std::vector<ConstString> m_user_supplied_trap_handler_functions;
bool AddOneMoreFrame (ABI *abi);
bool AddFirstFrame ();
diff --git a/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 93641ede1bc7..7ea5c89e7df4 100644
--- a/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -131,7 +131,8 @@ ProcessElfCore::AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader *head
VMRangeToFileOffset::Entry *last_entry = m_core_aranges.Back();
if (last_entry &&
last_entry->GetRangeEnd() == range_entry.GetRangeBase() &&
- last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase())
+ last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase() &&
+ last_entry->GetByteSize() == last_entry->data.GetByteSize())
{
last_entry->SetRangeEnd (range_entry.GetRangeEnd());
last_entry->data.SetRangeEnd (range_entry.data.GetRangeEnd());
@@ -294,9 +295,13 @@ ProcessElfCore::DoReadMemory (lldb::addr_t addr, void *buf, size_t size, Error &
size_t zero_fill_size = 0; // Padding
lldb::addr_t bytes_left = 0; // Number of bytes available in the core file from the given address
- if (file_end > offset)
- bytes_left = file_end - offset;
+ // Figure out how many on-disk bytes remain in this segment
+ // starting at the given offset
+ if (file_end > file_start + offset)
+ bytes_left = file_end - (file_start + offset);
+ // Figure out how many bytes we need to zero-fill if we are
+ // reading more bytes than available in the on-disk segment
if (bytes_to_read > bytes_left)
{
zero_fill_size = bytes_to_read - bytes_left;
@@ -365,12 +370,12 @@ enum {
// Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
static void
-ParseFreeBSDPrStatus(ThreadData *thread_data, DataExtractor &data,
+ParseFreeBSDPrStatus(ThreadData &thread_data, DataExtractor &data,
ArchSpec &arch)
{
lldb::offset_t offset = 0;
- bool have_padding = (arch.GetMachine() == llvm::Triple::mips64 ||
- arch.GetMachine() == llvm::Triple::x86_64);
+ bool lp64 = (arch.GetMachine() == llvm::Triple::mips64 ||
+ arch.GetMachine() == llvm::Triple::x86_64);
int pr_version = data.GetU32(&offset);
Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
@@ -380,23 +385,26 @@ ParseFreeBSDPrStatus(ThreadData *thread_data, DataExtractor &data,
log->Printf("FreeBSD PRSTATUS unexpected version %d", pr_version);
}
- if (have_padding)
- offset += 4;
- offset += 28; // pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate
- thread_data->signo = data.GetU32(&offset); // pr_cursig
+ // Skip padding, pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate
+ if (lp64)
+ offset += 32;
+ else
+ offset += 16;
+
+ thread_data.signo = data.GetU32(&offset); // pr_cursig
offset += 4; // pr_pid
- if (have_padding)
+ if (lp64)
offset += 4;
size_t len = data.GetByteSize() - offset;
- thread_data->gpregset = DataExtractor(data, offset, len);
+ thread_data.gpregset = DataExtractor(data, offset, len);
}
static void
-ParseFreeBSDThrMisc(ThreadData *thread_data, DataExtractor &data)
+ParseFreeBSDThrMisc(ThreadData &thread_data, DataExtractor &data)
{
lldb::offset_t offset = 0;
- thread_data->name = data.GetCStr(&offset, 20);
+ thread_data.name = data.GetCStr(&offset, 20);
}
/// Parse Thread context from PT_NOTE segment and store it in the thread list
@@ -418,13 +426,13 @@ ParseFreeBSDThrMisc(ThreadData *thread_data, DataExtractor &data)
/// For case (b) there may be either one NT_PRPSINFO per thread, or a single
/// one that applies to all threads (depending on the platform type).
void
-ProcessElfCore::ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader *segment_header,
+ProcessElfCore::ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader *segment_header,
DataExtractor segment_data)
{
assert(segment_header && segment_header->p_type == llvm::ELF::PT_NOTE);
lldb::offset_t offset = 0;
- ThreadData *thread_data = new ThreadData();
+ std::unique_ptr<ThreadData> thread_data(new ThreadData);
bool have_prstatus = false;
bool have_prpsinfo = false;
@@ -447,7 +455,7 @@ ProcessElfCore::ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader *
assert(thread_data->gpregset.GetByteSize() > 0);
// Add the new thread to thread list
m_thread_data.push_back(*thread_data);
- thread_data = new ThreadData();
+ *thread_data = ThreadData();
have_prstatus = false;
have_prpsinfo = false;
}
@@ -464,7 +472,7 @@ ProcessElfCore::ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader *
{
case NT_FREEBSD_PRSTATUS:
have_prstatus = true;
- ParseFreeBSDPrStatus(thread_data, note_data, arch);
+ ParseFreeBSDPrStatus(*thread_data, note_data, arch);
break;
case NT_FREEBSD_FPREGSET:
thread_data->fpregset = note_data;
@@ -473,7 +481,7 @@ ProcessElfCore::ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader *
have_prpsinfo = true;
break;
case NT_FREEBSD_THRMISC:
- ParseFreeBSDThrMisc(thread_data, note_data);
+ ParseFreeBSDThrMisc(*thread_data, note_data);
break;
case NT_FREEBSD_PROCSTAT_AUXV:
// FIXME: FreeBSD sticks an int at the beginning of the note
diff --git a/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp b/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
index 610506c20a0b..3e09c7bc2032 100644
--- a/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
+++ b/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
@@ -63,8 +63,16 @@ RegisterContextCorePOSIX_x86_64::WriteFPR()
bool
RegisterContextCorePOSIX_x86_64::ReadRegister(const RegisterInfo *reg_info, RegisterValue &value)
{
- value = *(uint64_t *)(m_gpregset + reg_info->byte_offset);
- return true;
+ switch (reg_info->byte_size)
+ {
+ case 4:
+ value = *(uint32_t *)(m_gpregset + reg_info->byte_offset);
+ return true;
+ case 8:
+ value = *(uint64_t *)(m_gpregset + reg_info->byte_offset);
+ return true;
+ }
+ return false;
}
bool
diff --git a/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index 3bda86dc0f73..cadcf53ca543 100644
--- a/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -17,6 +17,7 @@
#include "ThreadElfCore.h"
#include "ProcessElfCore.h"
#include "RegisterContextLinux_x86_64.h"
+#include "RegisterContextFreeBSD_i386.h"
#include "RegisterContextFreeBSD_mips64.h"
#include "RegisterContextFreeBSD_x86_64.h"
#include "RegisterContextPOSIXCore_mips64.h"
@@ -85,45 +86,66 @@ ThreadElfCore::CreateRegisterContextForFrame (StackFrame *frame)
ProcessElfCore *process = static_cast<ProcessElfCore *>(GetProcess().get());
ArchSpec arch = process->GetArchitecture();
- switch (arch.GetMachine())
+ RegisterInfoInterface *reg_interface = NULL;
+
+ switch (arch.GetTriple().getOS())
{
- case llvm::Triple::mips64:
- switch (arch.GetTriple().getOS())
+ case llvm::Triple::FreeBSD:
+ {
+ switch (arch.GetMachine())
{
- case llvm::Triple::FreeBSD:
- m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_mips64 (*this, new RegisterContextFreeBSD_mips64(arch), m_gpregset_data, m_fpregset_data));
+ case llvm::Triple::mips64:
+ reg_interface = new RegisterContextFreeBSD_mips64(arch);
+ break;
+ case llvm::Triple::x86:
+ reg_interface = new RegisterContextFreeBSD_i386(arch);
+ break;
+ case llvm::Triple::x86_64:
+ reg_interface = new RegisterContextFreeBSD_x86_64(arch);
break;
default:
- if (log)
- log->Printf ("elf-core::%s:: OS(%d) not supported",
- __FUNCTION__, arch.GetTriple().getOS());
- assert (false && "OS not supported");
break;
}
break;
- case llvm::Triple::x86_64:
- switch (arch.GetTriple().getOS())
+ }
+
+ case llvm::Triple::Linux:
+ {
+ switch (arch.GetMachine())
{
- case llvm::Triple::FreeBSD:
- m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64 (*this, new RegisterContextFreeBSD_x86_64(arch), m_gpregset_data, m_fpregset_data));
- break;
- case llvm::Triple::Linux:
- m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64 (*this, new RegisterContextLinux_x86_64(arch), m_gpregset_data, m_fpregset_data));
+ case llvm::Triple::x86_64:
+ reg_interface = new RegisterContextLinux_x86_64(arch);
break;
default:
- if (log)
- log->Printf ("elf-core::%s:: OS(%d) not supported",
- __FUNCTION__, arch.GetTriple().getOS());
- assert (false && "OS not supported");
break;
}
break;
+ }
+
+ default:
+ break;
+ }
+
+ if (!reg_interface) {
+ if (log)
+ log->Printf ("elf-core::%s:: Architecture(%d) or OS(%d) not supported",
+ __FUNCTION__, arch.GetMachine(), arch.GetTriple().getOS());
+ assert (false && "Architecture or OS not supported");
+ }
+
+ switch (arch.GetMachine())
+ {
+ case llvm::Triple::mips64:
+ m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_mips64 (*this, reg_interface, m_gpregset_data, m_fpregset_data));
+ break;
+ case llvm::Triple::x86:
+ case llvm::Triple::x86_64:
+ m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64 (*this, reg_interface, m_gpregset_data, m_fpregset_data));
+ break;
default:
- if (log)
- log->Printf ("elf-core::%s:: Architecture(%d) not supported",
- __FUNCTION__, arch.GetMachine());
- assert (false && "Architecture not supported");
+ break;
}
+
reg_ctx_sp = m_thread_reg_ctx_sp;
}
else if (m_unwinder_ap.get())
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index f67e1b5d49c3..1ec75a4bc7af 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -13,9 +13,11 @@
// C Includes
#include <limits.h>
#include <string.h>
+#include <sys/stat.h>
// C++ Includes
// Other libraries and framework includes
+#include "lldb/Core/ConnectionFileDescriptor.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StreamString.h"
@@ -143,7 +145,9 @@ GDBRemoteCommunication::GDBRemoteCommunication(const char *comm_name,
m_private_is_running (false),
m_history (512),
m_send_acks (true),
- m_is_platform (is_platform)
+ m_is_platform (is_platform),
+ m_listen_thread (LLDB_INVALID_HOST_THREAD),
+ m_listen_url ()
{
}
@@ -195,14 +199,14 @@ GDBRemoteCommunication::SendNack ()
return bytes_written;
}
-size_t
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunication::SendPacket (const char *payload, size_t payload_length)
{
Mutex::Locker locker(m_sequence_mutex);
return SendPacketNoLock (payload, payload_length);
}
-size_t
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunication::SendPacketNoLock (const char *payload, size_t payload_length)
{
if (IsConnected())
@@ -235,32 +239,32 @@ GDBRemoteCommunication::SendPacketNoLock (const char *payload, size_t payload_le
if (bytes_written == packet.GetSize())
{
if (GetSendAcks ())
- {
- if (GetAck () != '+')
- {
- if (log)
- log->Printf("get ack failed...");
- return 0;
- }
- }
+ return GetAck ();
+ else
+ return PacketResult::Success;
}
else
{
if (log)
log->Printf ("error: failed to send packet: %.*s", (int)packet.GetSize(), packet.GetData());
}
- return bytes_written;
}
- return 0;
+ return PacketResult::ErrorSendFailed;
}
-char
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunication::GetAck ()
{
StringExtractorGDBRemote packet;
- if (WaitForPacketWithTimeoutMicroSecondsNoLock (packet, GetPacketTimeoutInMicroSeconds ()) == 1)
- return packet.GetChar();
- return 0;
+ PacketResult result = WaitForPacketWithTimeoutMicroSecondsNoLock (packet, GetPacketTimeoutInMicroSeconds ());
+ if (result == PacketResult::Success)
+ {
+ if (packet.GetResponseType() == StringExtractorGDBRemote::ResponseType::eAck)
+ return PacketResult::Success;
+ else
+ return PacketResult::ErrorSendAck;
+ }
+ return result;
}
bool
@@ -280,7 +284,7 @@ GDBRemoteCommunication::WaitForNotRunningPrivate (const TimeValue *timeout_ptr)
return m_private_is_running.WaitForValueEqualTo (false, timeout_ptr, NULL);
}
-size_t
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractorGDBRemote &packet, uint32_t timeout_usec)
{
uint8_t buffer[8192];
@@ -290,9 +294,10 @@ GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtrac
// Check for a packet from our cache first without trying any reading...
if (CheckForPacket (NULL, 0, packet))
- return packet.GetStringRef().size();
+ return PacketResult::Success;
bool timed_out = false;
+ bool disconnected = false;
while (IsConnected() && !timed_out)
{
lldb::ConnectionStatus status = eConnectionStatusNoConnection;
@@ -309,7 +314,7 @@ GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtrac
if (bytes_read > 0)
{
if (CheckForPacket (buffer, bytes_read, packet))
- return packet.GetStringRef().size();
+ return PacketResult::Success;
}
else
{
@@ -326,13 +331,19 @@ GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtrac
case eConnectionStatusNoConnection:
case eConnectionStatusLostConnection:
case eConnectionStatusError:
+ disconnected = true;
Disconnect();
break;
}
}
}
- packet.Clear ();
- return 0;
+ packet.Clear ();
+ if (disconnected)
+ return PacketResult::ErrorDisconnected;
+ if (timed_out)
+ return PacketResult::ErrorReplyTimeout;
+ else
+ return PacketResult::ErrorReplyFailed;
}
bool
@@ -538,18 +549,65 @@ GDBRemoteCommunication::CheckForPacket (const uint8_t *src, size_t src_len, Stri
}
Error
-GDBRemoteCommunication::StartDebugserverProcess (const char *debugserver_url,
- const char *unix_socket_name, // For handshaking
- lldb_private::ProcessLaunchInfo &launch_info)
+GDBRemoteCommunication::StartListenThread (const char *hostname, uint16_t port)
{
Error error;
+ if (IS_VALID_LLDB_HOST_THREAD(m_listen_thread))
+ {
+ error.SetErrorString("listen thread already running");
+ }
+ else
+ {
+ char listen_url[512];
+ if (hostname && hostname[0])
+ snprintf(listen_url, sizeof(listen_url), "listen://%s:%i", hostname, port);
+ else
+ snprintf(listen_url, sizeof(listen_url), "listen://%i", port);
+ m_listen_url = listen_url;
+ SetConnection(new ConnectionFileDescriptor());
+ m_listen_thread = Host::ThreadCreate (listen_url, GDBRemoteCommunication::ListenThread, this, &error);
+ }
+ return error;
+}
+
+bool
+GDBRemoteCommunication::JoinListenThread ()
+{
+ if (IS_VALID_LLDB_HOST_THREAD(m_listen_thread))
+ {
+ Host::ThreadJoin(m_listen_thread, NULL, NULL);
+ m_listen_thread = LLDB_INVALID_HOST_THREAD;
+ }
+ return true;
+}
+
+lldb::thread_result_t
+GDBRemoteCommunication::ListenThread (lldb::thread_arg_t arg)
+{
+ GDBRemoteCommunication *comm = (GDBRemoteCommunication *)arg;
+ Error error;
+ ConnectionFileDescriptor *connection = (ConnectionFileDescriptor *)comm->GetConnection ();
+
+ if (connection)
+ {
+ // Do the listen on another thread so we can continue on...
+ if (connection->Connect(comm->m_listen_url.c_str(), &error) != eConnectionStatusSuccess)
+ comm->SetConnection(NULL);
+ }
+ return NULL;
+}
+
+Error
+GDBRemoteCommunication::StartDebugserverProcess (const char *hostname,
+ uint16_t in_port,
+ lldb_private::ProcessLaunchInfo &launch_info,
+ uint16_t &out_port)
+{
+ out_port = in_port;
+ Error error;
// If we locate debugserver, keep that located version around
static FileSpec g_debugserver_file_spec;
- // This function will fill in the launch information for the debugserver
- // instance that gets launched.
- launch_info.Clear();
-
char debugserver_path[PATH_MAX];
FileSpec &debugserver_file_spec = launch_info.GetExecutableFile();
@@ -591,19 +649,88 @@ GDBRemoteCommunication::StartDebugserverProcess (const char *debugserver_url,
// Start args with "debugserver /file/path -r --"
debugserver_args.AppendArgument(debugserver_path);
- debugserver_args.AppendArgument(debugserver_url);
+
+ // If a host and port is supplied then use it
+ char host_and_port[128];
+ if (hostname)
+ {
+ snprintf (host_and_port, sizeof(host_and_port), "%s:%u", hostname, in_port);
+ debugserver_args.AppendArgument(host_and_port);
+ }
+ else
+ {
+ host_and_port[0] = '\0';
+ }
+
// use native registers, not the GDB registers
debugserver_args.AppendArgument("--native-regs");
// make debugserver run in its own session so signals generated by
// special terminal key sequences (^C) don't affect debugserver
debugserver_args.AppendArgument("--setsid");
-
- if (unix_socket_name && unix_socket_name[0])
+
+ char named_pipe_path[PATH_MAX];
+ named_pipe_path[0] = '\0';
+
+ bool listen = false;
+ if (host_and_port[0])
{
- debugserver_args.AppendArgument("--unix-socket");
- debugserver_args.AppendArgument(unix_socket_name);
+ // Create a temporary file to get the stdout/stderr and redirect the
+ // output of the command into this file. We will later read this file
+ // if all goes well and fill the data into "command_output_ptr"
+
+ if (in_port == 0)
+ {
+ // Binding to port zero, we need to figure out what port it ends up
+ // using using a named pipe...
+ FileSpec tmpdir_file_spec;
+ if (Host::GetLLDBPath (ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
+ {
+ tmpdir_file_spec.GetFilename().SetCString("debugserver-named-pipe.XXXXXX");
+ strncpy(named_pipe_path, tmpdir_file_spec.GetPath().c_str(), sizeof(named_pipe_path));
+ }
+ else
+ {
+ strncpy(named_pipe_path, "/tmp/debugserver-named-pipe.XXXXXX", sizeof(named_pipe_path));
+ }
+
+ if (::mktemp (named_pipe_path))
+ {
+#if defined(_MSC_VER)
+ if ( false )
+#else
+ if (::mkfifo(named_pipe_path, 0600) == 0)
+#endif
+ {
+ debugserver_args.AppendArgument("--named-pipe");
+ debugserver_args.AppendArgument(named_pipe_path);
+ }
+ }
+ }
+ else
+ {
+ listen = true;
+ }
+ }
+ else
+ {
+ // No host and port given, so lets listen on our end and make the debugserver
+ // connect to us..
+ error = StartListenThread ("localhost", 0);
+ if (error.Fail())
+ return error;
+
+ ConnectionFileDescriptor *connection = (ConnectionFileDescriptor *)GetConnection ();
+ out_port = connection->GetBoundPort(3);
+ assert (out_port != 0);
+ char port_cstr[32];
+ snprintf(port_cstr, sizeof(port_cstr), "localhost:%i", out_port);
+ // Send the host and port down that debugserver and specify an option
+ // so that it connects back to the port we are listening to in this process
+ debugserver_args.AppendArgument("--reverse-connect");
+ debugserver_args.AppendArgument(port_cstr);
}
+
const char *env_debugserver_log_file = getenv("LLDB_DEBUGSERVER_LOG_FILE");
if (env_debugserver_log_file)
{
@@ -617,46 +744,41 @@ GDBRemoteCommunication::StartDebugserverProcess (const char *debugserver_url,
::snprintf (arg_cstr, sizeof(arg_cstr), "--log-flags=%s", env_debugserver_log_flags);
debugserver_args.AppendArgument(arg_cstr);
}
- // debugserver_args.AppendArgument("--log-file=/tmp/debugserver.txt");
- // debugserver_args.AppendArgument("--log-flags=0x802e0e");
- // We currently send down all arguments, attach pids, or attach
- // process names in dedicated GDB server packets, so we don't need
- // to pass them as arguments. This is currently because of all the
- // things we need to setup prior to launching: the environment,
- // current working dir, file actions, etc.
-#if 0
- // Now append the program arguments
- if (inferior_argv)
+ // Close STDIN, STDOUT and STDERR. We might need to redirect them
+ // to "/dev/null" if we run into any problems.
+ launch_info.AppendCloseFileAction (STDIN_FILENO);
+ launch_info.AppendCloseFileAction (STDOUT_FILENO);
+ launch_info.AppendCloseFileAction (STDERR_FILENO);
+
+ error = Host::LaunchProcess(launch_info);
+
+ if (named_pipe_path[0])
{
- // Terminate the debugserver args so we can now append the inferior args
- debugserver_args.AppendArgument("--");
-
- for (int i = 0; inferior_argv[i] != NULL; ++i)
- debugserver_args.AppendArgument (inferior_argv[i]);
+ File name_pipe_file;
+ error = name_pipe_file.Open(named_pipe_path, File::eOpenOptionRead);
+ if (error.Success())
+ {
+ char port_cstr[256];
+ port_cstr[0] = '\0';
+ size_t num_bytes = sizeof(port_cstr);
+ error = name_pipe_file.Read(port_cstr, num_bytes);
+ assert (error.Success());
+ assert (num_bytes > 0 && port_cstr[num_bytes-1] == '\0');
+ out_port = Args::StringToUInt32(port_cstr, 0);
+ name_pipe_file.Close();
+ }
+ Host::Unlink(named_pipe_path);
}
- else if (attach_pid != LLDB_INVALID_PROCESS_ID)
+ else if (listen)
{
- ::snprintf (arg_cstr, sizeof(arg_cstr), "--attach=%u", attach_pid);
- debugserver_args.AppendArgument (arg_cstr);
+
}
- else if (attach_name && attach_name[0])
+ else
{
- if (wait_for_launch)
- debugserver_args.AppendArgument ("--waitfor");
- else
- debugserver_args.AppendArgument ("--attach");
- debugserver_args.AppendArgument (attach_name);
+ // Make sure we actually connect with the debugserver...
+ JoinListenThread();
}
-#endif
-
- // Close STDIN, STDOUT and STDERR. We might need to redirect them
- // to "/dev/null" if we run into any problems.
-// launch_info.AppendCloseFileAction (STDIN_FILENO);
-// launch_info.AppendCloseFileAction (STDOUT_FILENO);
-// launch_info.AppendCloseFileAction (STDERR_FILENO);
-
- error = Host::LaunchProcess(launch_info);
}
else
{
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index a1077957c6a6..d8361113ddc8 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -35,6 +35,19 @@ public:
{
eBroadcastBitRunPacketSent = kLoUserBroadcastBit
};
+
+ enum class PacketResult
+ {
+ Success = 0, // Success
+ ErrorSendFailed, // Error sending the packet
+ ErrorSendAck, // Didn't get an ack back after sending a packet
+ ErrorReplyFailed, // Error getting the reply
+ ErrorReplyTimeout, // Timed out waiting for reply
+ ErrorReplyInvalid, // Got a reply but it wasn't valid for the packet that was sent
+ ErrorReplyAck, // Sending reply ack failed
+ ErrorDisconnected, // We were disconnected
+ ErrorNoSequenceLock // We couldn't get the sequence lock for a multi-packet request
+ };
//------------------------------------------------------------------
// Constructors and Destructors
//------------------------------------------------------------------
@@ -45,7 +58,7 @@ public:
virtual
~GDBRemoteCommunication();
- char
+ PacketResult
GetAck ();
size_t
@@ -109,9 +122,10 @@ public:
// supplied connection URL.
//------------------------------------------------------------------
lldb_private::Error
- StartDebugserverProcess (const char *connect_url,
- const char *unix_socket_name,
- lldb_private::ProcessLaunchInfo &launch_info);
+ StartDebugserverProcess (const char *hostname,
+ uint16_t in_port, // If set to zero, then out_port will contain the bound port on exit
+ lldb_private::ProcessLaunchInfo &launch_info,
+ uint16_t &out_port);
void
DumpHistory(lldb_private::Stream &strm);
@@ -223,15 +237,15 @@ protected:
mutable bool m_dumped_to_log;
};
- size_t
+ PacketResult
SendPacket (const char *payload,
size_t payload_length);
- size_t
+ PacketResult
SendPacketNoLock (const char *payload,
size_t payload_length);
- size_t
+ PacketResult
WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractorGDBRemote &response,
uint32_t timeout_usec);
@@ -242,7 +256,7 @@ protected:
// Classes that inherit from GDBRemoteCommunication can see and modify these
//------------------------------------------------------------------
uint32_t m_packet_timeout;
-#ifdef LLDB_CONFIGURATION_DEBUG
+#ifdef ENABLE_MUTEX_ERROR_CHECKING
lldb_private::TrackingMutex m_sequence_mutex;
#else
lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time
@@ -256,9 +270,22 @@ protected:
// a single process
+ lldb_private::Error
+ StartListenThread (const char *hostname = "localhost",
+ uint16_t port = 0);
+
+ bool
+ JoinListenThread ();
+ static lldb::thread_result_t
+ ListenThread (lldb::thread_arg_t arg);
private:
+
+ lldb::thread_t m_listen_thread;
+ std::string m_listen_url;
+
+
//------------------------------------------------------------------
// For GDBRemoteCommunication only
//------------------------------------------------------------------
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 2690992eeed3..aa60ec1b4a27 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -66,6 +66,9 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) :
m_prepare_for_reg_writing_reply (eLazyBoolCalculate),
m_supports_p (eLazyBoolCalculate),
m_supports_QSaveRegisterState (eLazyBoolCalculate),
+ m_supports_qXfer_libraries_read (eLazyBoolCalculate),
+ m_supports_qXfer_libraries_svr4_read (eLazyBoolCalculate),
+ m_supports_augmented_libraries_svr4_read (eLazyBoolCalculate),
m_supports_qProcessInfoPID (true),
m_supports_qfProcessInfo (true),
m_supports_qUserName (true),
@@ -84,6 +87,7 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) :
m_async_mutex (Mutex::eMutexTypeRecursive),
m_async_packet_predicate (false),
m_async_packet (),
+ m_async_result (PacketResult::Success),
m_async_response (),
m_async_signal (-1),
m_thread_id_to_used_usec_map (),
@@ -95,7 +99,8 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) :
m_os_build (),
m_os_kernel (),
m_hostname (),
- m_default_packet_timeout (0)
+ m_default_packet_timeout (0),
+ m_max_packet_size (0)
{
}
@@ -117,6 +122,14 @@ GDBRemoteCommunicationClient::HandshakeWithServer (Error *error_ptr)
// fail to send the handshake ack, there is no reason to continue...
if (SendAck())
{
+ // Wait for any responses that might have been queued up in the remote
+ // GDB server and flush them all
+ StringExtractorGDBRemote response;
+ PacketResult packet_result = PacketResult::Success;
+ const uint32_t timeout_usec = 10 * 1000; // Wait for 10 ms for a response
+ while (packet_result == PacketResult::Success)
+ packet_result = WaitForPacketWithTimeoutMicroSecondsNoLock (response, timeout_usec);
+
// The return value from QueryNoAckModeSupported() is true if the packet
// was sent and _any_ response (including UNIMPLEMENTED) was received),
// or false if no response was received. This quickly tells us if we have
@@ -140,6 +153,46 @@ GDBRemoteCommunicationClient::HandshakeWithServer (Error *error_ptr)
}
bool
+GDBRemoteCommunicationClient::GetAugmentedLibrariesSVR4ReadSupported ()
+{
+ if (m_supports_augmented_libraries_svr4_read == eLazyBoolCalculate)
+ {
+ GetRemoteQSupported();
+ }
+ return (m_supports_augmented_libraries_svr4_read == eLazyBoolYes);
+}
+
+bool
+GDBRemoteCommunicationClient::GetQXferLibrariesSVR4ReadSupported ()
+{
+ if (m_supports_qXfer_libraries_svr4_read == eLazyBoolCalculate)
+ {
+ GetRemoteQSupported();
+ }
+ return (m_supports_qXfer_libraries_svr4_read == eLazyBoolYes);
+}
+
+bool
+GDBRemoteCommunicationClient::GetQXferLibrariesReadSupported ()
+{
+ if (m_supports_qXfer_libraries_read == eLazyBoolCalculate)
+ {
+ GetRemoteQSupported();
+ }
+ return (m_supports_qXfer_libraries_read == eLazyBoolYes);
+}
+
+uint64_t
+GDBRemoteCommunicationClient::GetRemoteMaxPacketSize()
+{
+ if (m_max_packet_size == 0)
+ {
+ GetRemoteQSupported();
+ }
+ return m_max_packet_size;
+}
+
+bool
GDBRemoteCommunicationClient::QueryNoAckModeSupported ()
{
if (m_supports_not_sending_acks == eLazyBoolCalculate)
@@ -148,7 +201,7 @@ GDBRemoteCommunicationClient::QueryNoAckModeSupported ()
m_supports_not_sending_acks = eLazyBoolNo;
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse("QStartNoAckMode", response, false))
+ if (SendPacketAndWaitForResponse("QStartNoAckMode", response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
{
@@ -169,7 +222,7 @@ GDBRemoteCommunicationClient::GetListThreadsInStopReplySupported ()
m_supports_threads_in_stop_reply = eLazyBoolNo;
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse("QListThreadsInStopReply", response, false))
+ if (SendPacketAndWaitForResponse("QListThreadsInStopReply", response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
m_supports_threads_in_stop_reply = eLazyBoolYes;
@@ -185,7 +238,7 @@ GDBRemoteCommunicationClient::GetVAttachOrWaitSupported ()
m_attach_or_wait_reply = eLazyBoolNo;
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse("qVAttachOrWaitSupported", response, false))
+ if (SendPacketAndWaitForResponse("qVAttachOrWaitSupported", response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
m_attach_or_wait_reply = eLazyBoolYes;
@@ -205,7 +258,7 @@ GDBRemoteCommunicationClient::GetSyncThreadStateSupported ()
m_prepare_for_reg_writing_reply = eLazyBoolNo;
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse("qSyncThreadStateSupported", response, false))
+ if (SendPacketAndWaitForResponse("qSyncThreadStateSupported", response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
m_prepare_for_reg_writing_reply = eLazyBoolYes;
@@ -236,6 +289,9 @@ GDBRemoteCommunicationClient::ResetDiscoverableSettings()
m_supports_memory_region_info = eLazyBoolCalculate;
m_prepare_for_reg_writing_reply = eLazyBoolCalculate;
m_attach_or_wait_reply = eLazyBoolCalculate;
+ m_supports_qXfer_libraries_read = eLazyBoolCalculate;
+ m_supports_qXfer_libraries_svr4_read = eLazyBoolCalculate;
+ m_supports_augmented_libraries_svr4_read = eLazyBoolCalculate;
m_supports_qProcessInfoPID = true;
m_supports_qfProcessInfo = true;
@@ -251,8 +307,50 @@ GDBRemoteCommunicationClient::ResetDiscoverableSettings()
m_supports_QEnvironmentHexEncoded = true;
m_host_arch.Clear();
m_process_arch.Clear();
+
+ m_max_packet_size = 0;
}
+void
+GDBRemoteCommunicationClient::GetRemoteQSupported ()
+{
+ // Clear out any capabilities we expect to see in the qSupported response
+ m_supports_qXfer_libraries_svr4_read = eLazyBoolNo;
+ m_supports_qXfer_libraries_read = eLazyBoolNo;
+ m_supports_augmented_libraries_svr4_read = eLazyBoolNo;
+ m_max_packet_size = UINT64_MAX; // It's supposed to always be there, but if not, we assume no limit
+
+ StringExtractorGDBRemote response;
+ if (SendPacketAndWaitForResponse("qSupported",
+ response,
+ /*send_async=*/false) == PacketResult::Success)
+ {
+ const char *response_cstr = response.GetStringRef().c_str();
+ if (::strstr (response_cstr, "qXfer:libraries-svr4:read+"))
+ m_supports_qXfer_libraries_svr4_read = eLazyBoolYes;
+ if (::strstr (response_cstr, "augmented-libraries-svr4-read"))
+ {
+ m_supports_qXfer_libraries_svr4_read = eLazyBoolYes; // implied
+ m_supports_augmented_libraries_svr4_read = eLazyBoolYes;
+ }
+ if (::strstr (response_cstr, "qXfer:libraries:read+"))
+ m_supports_qXfer_libraries_read = eLazyBoolYes;
+
+ const char *packet_size_str = ::strstr (response_cstr, "PacketSize=");
+ if (packet_size_str)
+ {
+ StringExtractorGDBRemote packet_response(packet_size_str + strlen("PacketSize="));
+ m_max_packet_size = packet_response.GetHexMaxU64(/*little_endian=*/false, UINT64_MAX);
+ if (m_max_packet_size == 0)
+ {
+ m_max_packet_size = UINT64_MAX; // Must have been a garbled response
+ Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
+ if (log)
+ log->Printf ("Garbled PacketSize spec in qSupported response");
+ }
+ }
+ }
+}
bool
GDBRemoteCommunicationClient::GetThreadSuffixSupported ()
@@ -261,7 +359,7 @@ GDBRemoteCommunicationClient::GetThreadSuffixSupported ()
{
StringExtractorGDBRemote response;
m_supports_thread_suffix = eLazyBoolNo;
- if (SendPacketAndWaitForResponse("QThreadSuffixSupported", response, false))
+ if (SendPacketAndWaitForResponse("QThreadSuffixSupported", response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
m_supports_thread_suffix = eLazyBoolYes;
@@ -281,7 +379,7 @@ GDBRemoteCommunicationClient::GetVContSupported (char flavor)
m_supports_vCont_C = eLazyBoolNo;
m_supports_vCont_s = eLazyBoolNo;
m_supports_vCont_S = eLazyBoolNo;
- if (SendPacketAndWaitForResponse("vCont?", response, false))
+ if (SendPacketAndWaitForResponse("vCont?", response, false) == PacketResult::Success)
{
const char *response_cstr = response.GetStringRef().c_str();
if (::strstr (response_cstr, ";c"))
@@ -345,7 +443,7 @@ GDBRemoteCommunicationClient::GetpPacketSupported (lldb::tid_t tid)
else
snprintf(packet, sizeof(packet), "p0");
- if (SendPacketAndWaitForResponse(packet, response, false))
+ if (SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success)
{
if (response.IsNormalResponse())
m_supports_p = eLazyBoolYes;
@@ -354,7 +452,63 @@ GDBRemoteCommunicationClient::GetpPacketSupported (lldb::tid_t tid)
return m_supports_p;
}
-size_t
+GDBRemoteCommunicationClient::PacketResult
+GDBRemoteCommunicationClient::SendPacketsAndConcatenateResponses
+(
+ const char *payload_prefix,
+ std::string &response_string
+)
+{
+ Mutex::Locker locker;
+ if (!GetSequenceMutex(locker,
+ "ProcessGDBRemote::SendPacketsAndConcatenateResponses() failed due to not getting the sequence mutex"))
+ {
+ Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS));
+ if (log)
+ log->Printf("error: failed to get packet sequence mutex, not sending packets with prefix '%s'",
+ payload_prefix);
+ return PacketResult::ErrorNoSequenceLock;
+ }
+
+ response_string = "";
+ std::string payload_prefix_str(payload_prefix);
+ unsigned int response_size = 0x1000;
+ if (response_size > GetRemoteMaxPacketSize()) { // May send qSupported packet
+ response_size = GetRemoteMaxPacketSize();
+ }
+
+ for (unsigned int offset = 0; true; offset += response_size)
+ {
+ StringExtractorGDBRemote this_response;
+ // Construct payload
+ char sizeDescriptor[128];
+ snprintf(sizeDescriptor, sizeof(sizeDescriptor), "%x,%x", offset, response_size);
+ PacketResult result = SendPacketAndWaitForResponse((payload_prefix_str + sizeDescriptor).c_str(),
+ this_response,
+ /*send_async=*/false);
+ if (result != PacketResult::Success)
+ return result;
+
+ const std::string &this_string = this_response.GetStringRef();
+
+ // Check for m or l as first character; l seems to mean this is the last chunk
+ char first_char = *this_string.c_str();
+ if (first_char != 'm' && first_char != 'l')
+ {
+ return PacketResult::ErrorReplyInvalid;
+ }
+ // Skip past m or l
+ const char *s = this_string.c_str() + 1;
+
+ // Concatenate the result so far
+ response_string += s;
+ if (first_char == 'l')
+ // We're done
+ return PacketResult::Success;
+ }
+}
+
+GDBRemoteCommunicationClient::PacketResult
GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
(
const char *payload,
@@ -368,7 +522,18 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
send_async);
}
-size_t
+GDBRemoteCommunicationClient::PacketResult
+GDBRemoteCommunicationClient::SendPacketAndWaitForResponseNoLock (const char *payload,
+ size_t payload_length,
+ StringExtractorGDBRemote &response)
+{
+ PacketResult packet_result = SendPacketNoLock (payload, payload_length);
+ if (packet_result == PacketResult::Success)
+ packet_result = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ());
+ return packet_result;
+}
+
+GDBRemoteCommunicationClient::PacketResult
GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
(
const char *payload,
@@ -377,18 +542,13 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
bool send_async
)
{
+ PacketResult packet_result = PacketResult::ErrorSendFailed;
Mutex::Locker locker;
Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
size_t response_len = 0;
if (GetSequenceMutex (locker))
{
- if (SendPacketNoLock (payload, payload_length))
- response_len = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ());
- else
- {
- if (log)
- log->Printf("error: failed to send '%*s'", (int) payload_length, payload);
- }
+ packet_result = SendPacketAndWaitForResponseNoLock (payload, payload_length, response);
}
else
{
@@ -424,6 +584,7 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
// Swap the response buffer to avoid malloc and string copy
response.GetStringRef().swap (m_async_response.GetStringRef());
response_len = response.GetStringRef().size();
+ packet_result = m_async_result;
}
else
{
@@ -456,13 +617,7 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
if (log)
log->Printf ("async: got lock without sending interrupt");
// Send the packet normally since we got the lock
- if (SendPacketNoLock (payload, payload_length))
- response_len = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ());
- else
- {
- if (log)
- log->Printf("error: failed to send '%*s'", (int) payload_length, payload);
- }
+ packet_result = SendPacketAndWaitForResponseNoLock (payload, payload_length, response);
}
}
else
@@ -483,12 +638,7 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
log->Printf("error: failed to get packet sequence mutex, not sending packet '%*s'", (int) payload_length, payload);
}
}
- if (response_len == 0)
- {
- if (log)
- log->Printf("error: failed to get response for '%*s'", (int) payload_length, payload);
- }
- return response_len;
+ return packet_result;
}
static const char *end_delimiter = "--end--;";
@@ -615,7 +765,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
{
if (log)
log->Printf ("GDBRemoteCommunicationClient::%s () sending continue packet: %s", __FUNCTION__, continue_packet.c_str());
- if (SendPacketNoLock(continue_packet.c_str(), continue_packet.size()) == 0)
+ if (SendPacketNoLock(continue_packet.c_str(), continue_packet.size()) != PacketResult::Success)
state = eStateInvalid;
m_private_is_running.SetValue (true, eBroadcastAlways);
@@ -626,7 +776,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
if (log)
log->Printf ("GDBRemoteCommunicationClient::%s () WaitForPacket(%s)", __FUNCTION__, continue_packet.c_str());
- if (WaitForPacketWithTimeoutMicroSecondsNoLock(response, UINT32_MAX))
+ if (WaitForPacketWithTimeoutMicroSecondsNoLock(response, UINT32_MAX) == PacketResult::Success)
{
if (response.Empty())
state = eStateInvalid;
@@ -683,7 +833,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
// packet to make sure it doesn't get in the way
StringExtractorGDBRemote extra_stop_reply_packet;
uint32_t timeout_usec = 1000;
- if (WaitForPacketWithTimeoutMicroSecondsNoLock (extra_stop_reply_packet, timeout_usec))
+ if (WaitForPacketWithTimeoutMicroSecondsNoLock (extra_stop_reply_packet, timeout_usec) == PacketResult::Success)
{
switch (extra_stop_reply_packet.GetChar())
{
@@ -747,11 +897,12 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
Log * packet_log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS));
// We are supposed to send an asynchronous packet while
- // we are running.
+ // we are running.
m_async_response.Clear();
if (m_async_packet.empty())
{
- if (packet_log)
+ m_async_result = PacketResult::ErrorSendFailed;
+ if (packet_log)
packet_log->Printf ("async: error: empty async packet");
}
@@ -760,10 +911,10 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
if (packet_log)
packet_log->Printf ("async: sending packet");
- SendPacketAndWaitForResponse (&m_async_packet[0],
- m_async_packet.size(),
- m_async_response,
- false);
+ m_async_result = SendPacketAndWaitForResponse (&m_async_packet[0],
+ m_async_packet.size(),
+ m_async_response,
+ false);
}
// Let the other thread that was trying to send the async
// packet know that the packet has been sent and response is
@@ -973,7 +1124,7 @@ lldb::pid_t
GDBRemoteCommunicationClient::GetCurrentProcessID ()
{
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse("qC", strlen("qC"), response, false))
+ if (SendPacketAndWaitForResponse("qC", strlen("qC"), response, false) == PacketResult::Success)
{
if (response.GetChar() == 'Q')
if (response.GetChar() == 'C')
@@ -987,7 +1138,7 @@ GDBRemoteCommunicationClient::GetLaunchSuccess (std::string &error_str)
{
error_str.clear();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse("qLaunchSuccess", strlen("qLaunchSuccess"), response, false))
+ if (SendPacketAndWaitForResponse("qLaunchSuccess", strlen("qLaunchSuccess"), response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return true;
@@ -1050,7 +1201,7 @@ GDBRemoteCommunicationClient::SendArgumentsPacket (const ProcessLaunchInfo &laun
}
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false))
+ if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return 0;
@@ -1097,7 +1248,7 @@ GDBRemoteCommunicationClient::SendEnvironmentPacket (char const *name_equal_valu
{
packet.PutCString("QEnvironmentHexEncoded:");
packet.PutBytesAsRawHex8 (name_equal_value, strlen(name_equal_value));
- if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false))
+ if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return 0;
@@ -1113,7 +1264,7 @@ GDBRemoteCommunicationClient::SendEnvironmentPacket (char const *name_equal_valu
else if (m_supports_QEnvironment)
{
packet.Printf("QEnvironment:%s", name_equal_value);
- if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false))
+ if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return 0;
@@ -1136,7 +1287,7 @@ GDBRemoteCommunicationClient::SendLaunchArchPacket (char const *arch)
StreamString packet;
packet.Printf("QLaunchArch:%s", arch);
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false))
+ if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return 0;
@@ -1236,7 +1387,7 @@ GDBRemoteCommunicationClient::GetHostInfo (bool force)
{
m_qHostInfo_is_valid = eLazyBoolNo;
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse ("qHostInfo", response, false))
+ if (SendPacketAndWaitForResponse ("qHostInfo", response, false) == PacketResult::Success)
{
if (response.IsNormalResponse())
{
@@ -1248,6 +1399,7 @@ GDBRemoteCommunicationClient::GetHostInfo (bool force)
std::string os_name;
std::string vendor_name;
std::string triple;
+ std::string distribution_id;
uint32_t pointer_byte_size = 0;
StringExtractor extractor;
ByteOrder byte_order = eByteOrderInvalid;
@@ -1281,6 +1433,13 @@ GDBRemoteCommunicationClient::GetHostInfo (bool force)
extractor.GetHexByteString (triple);
++num_keys_decoded;
}
+ else if (name.compare ("distribution_id") == 0)
+ {
+ extractor.GetStringRef ().swap (value);
+ extractor.SetFilePos (0);
+ extractor.GetHexByteString (distribution_id);
+ ++num_keys_decoded;
+ }
else if (name.compare("os_build") == 0)
{
extractor.GetStringRef().swap(value);
@@ -1455,7 +1614,9 @@ GDBRemoteCommunicationClient::GetHostInfo (bool force)
{
assert (byte_order == m_host_arch.GetByteOrder());
}
- }
+ }
+ if (!distribution_id.empty ())
+ m_host_arch.SetDistributionId (distribution_id.c_str ());
}
}
}
@@ -1474,7 +1635,7 @@ GDBRemoteCommunicationClient::SendAttach
char packet[64];
const int packet_len = ::snprintf (packet, sizeof(packet), "vAttach;%" PRIx64, pid);
assert (packet_len < (int)sizeof(packet));
- if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success)
{
if (response.IsErrorResponse())
return response.GetError();
@@ -1514,7 +1675,7 @@ GDBRemoteCommunicationClient::AllocateMemory (size_t size, uint32_t permissions)
permissions & lldb::ePermissionsExecutable ? "x" : "");
assert (packet_len < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success)
{
if (!response.IsErrorResponse())
return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS);
@@ -1537,7 +1698,7 @@ GDBRemoteCommunicationClient::DeallocateMemory (addr_t addr)
const int packet_len = ::snprintf(packet, sizeof(packet), "_m%" PRIx64, (uint64_t)addr);
assert (packet_len < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return true;
@@ -1563,7 +1724,7 @@ GDBRemoteCommunicationClient::Detach (bool keep_stopped)
const int packet_len = ::snprintf(packet, sizeof(packet), "qSupportsDetachAndStayStopped:");
assert (packet_len < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success)
{
m_supports_detach_stay_stopped = eLazyBoolYes;
}
@@ -1580,15 +1741,15 @@ GDBRemoteCommunicationClient::Detach (bool keep_stopped)
}
else
{
- size_t num_sent = SendPacket ("D1", 2);
- if (num_sent == 0)
+ PacketResult packet_result = SendPacket ("D1", 2);
+ if (packet_result != PacketResult::Success)
error.SetErrorString ("Sending extended disconnect packet failed.");
}
}
else
{
- size_t num_sent = SendPacket ("D", 1);
- if (num_sent == 0)
+ PacketResult packet_result = SendPacket ("D", 1);
+ if (packet_result != PacketResult::Success)
error.SetErrorString ("Sending disconnect packet failed.");
}
return error;
@@ -1608,7 +1769,7 @@ GDBRemoteCommunicationClient::GetMemoryRegionInfo (lldb::addr_t addr,
const int packet_len = ::snprintf(packet, sizeof(packet), "qMemoryRegionInfo:%" PRIx64, (uint64_t)addr);
assert (packet_len < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success)
{
std::string name;
std::string value;
@@ -1711,7 +1872,7 @@ GDBRemoteCommunicationClient::GetWatchpointSupportInfo (uint32_t &num)
const int packet_len = ::snprintf(packet, sizeof(packet), "qWatchpointSupportInfo:");
assert (packet_len < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success)
{
m_supports_watchpoint_support_info = eLazyBoolYes;
std::string name;
@@ -1773,7 +1934,7 @@ GDBRemoteCommunicationClient::SetSTDIN (char const *path)
packet.PutBytesAsRawHex8(path, strlen(path));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false))
+ if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return 0;
@@ -1795,7 +1956,7 @@ GDBRemoteCommunicationClient::SetSTDOUT (char const *path)
packet.PutBytesAsRawHex8(path, strlen(path));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false))
+ if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return 0;
@@ -1817,7 +1978,7 @@ GDBRemoteCommunicationClient::SetSTDERR (char const *path)
packet.PutBytesAsRawHex8(path, strlen(path));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false))
+ if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return 0;
@@ -1833,7 +1994,7 @@ bool
GDBRemoteCommunicationClient::GetWorkingDir (std::string &cwd)
{
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse ("qGetWorkingDir", response, false))
+ if (SendPacketAndWaitForResponse ("qGetWorkingDir", response, false) == PacketResult::Success)
{
if (response.IsUnsupportedResponse())
return false;
@@ -1855,7 +2016,7 @@ GDBRemoteCommunicationClient::SetWorkingDir (char const *path)
packet.PutBytesAsRawHex8(path, strlen(path));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false))
+ if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return 0;
@@ -1874,7 +2035,7 @@ GDBRemoteCommunicationClient::SetDisableASLR (bool enable)
const int packet_len = ::snprintf (packet, sizeof (packet), "QSetDisableASLR:%i", enable ? 1 : 0);
assert (packet_len < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return 0;
@@ -1893,6 +2054,11 @@ GDBRemoteCommunicationClient::DecodeProcessInfoResponse (StringExtractorGDBRemot
std::string name;
std::string value;
StringExtractor extractor;
+
+ uint32_t cpu = LLDB_INVALID_CPUTYPE;
+ uint32_t sub = 0;
+ std::string vendor;
+ std::string os_type;
while (response.GetNameColonValue(name, value))
{
@@ -1938,6 +2104,32 @@ GDBRemoteCommunicationClient::DecodeProcessInfoResponse (StringExtractorGDBRemot
extractor.GetHexByteString (value);
process_info.GetExecutableFile().SetFile (value.c_str(), false);
}
+ else if (name.compare("cputype") == 0)
+ {
+ cpu = Args::StringToUInt32 (value.c_str(), LLDB_INVALID_CPUTYPE, 16);
+ }
+ else if (name.compare("cpusubtype") == 0)
+ {
+ sub = Args::StringToUInt32 (value.c_str(), 0, 16);
+ }
+ else if (name.compare("vendor") == 0)
+ {
+ vendor = value;
+ }
+ else if (name.compare("ostype") == 0)
+ {
+ os_type = value;
+ }
+ }
+
+ if (cpu != LLDB_INVALID_CPUTYPE && !vendor.empty() && !os_type.empty())
+ {
+ if (vendor == "apple")
+ {
+ process_info.GetArchitecture().SetArchitecture (eArchTypeMachO, cpu, sub);
+ process_info.GetArchitecture().GetTriple().setVendorName (llvm::StringRef (vendor));
+ process_info.GetArchitecture().GetTriple().setOSName (llvm::StringRef (os_type));
+ }
}
if (process_info.GetProcessID() != LLDB_INVALID_PROCESS_ID)
@@ -1957,7 +2149,7 @@ GDBRemoteCommunicationClient::GetProcessInfo (lldb::pid_t pid, ProcessInstanceIn
const int packet_len = ::snprintf (packet, sizeof (packet), "qProcessInfoPID:%" PRIu64, pid);
assert (packet_len < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success)
{
return DecodeProcessInfoResponse (response, process_info);
}
@@ -1981,7 +2173,7 @@ GDBRemoteCommunicationClient::GetCurrentProcessInfo ()
GetHostInfo ();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse ("qProcessInfo", response, false))
+ if (SendPacketAndWaitForResponse ("qProcessInfo", response, false) == PacketResult::Success)
{
if (response.IsNormalResponse())
{
@@ -2141,7 +2333,7 @@ GDBRemoteCommunicationClient::FindProcesses (const ProcessInstanceInfoMatch &mat
}
}
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false))
+ if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success)
{
do
{
@@ -2151,7 +2343,7 @@ GDBRemoteCommunicationClient::FindProcesses (const ProcessInstanceInfoMatch &mat
process_infos.Append(process_info);
response.GetStringRef().clear();
response.SetFilePos(0);
- } while (SendPacketAndWaitForResponse ("qsProcessInfo", strlen ("qsProcessInfo"), response, false));
+ } while (SendPacketAndWaitForResponse ("qsProcessInfo", strlen ("qsProcessInfo"), response, false) == PacketResult::Success);
}
else
{
@@ -2172,7 +2364,7 @@ GDBRemoteCommunicationClient::GetUserName (uint32_t uid, std::string &name)
const int packet_len = ::snprintf (packet, sizeof (packet), "qUserName:%i", uid);
assert (packet_len < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success)
{
if (response.IsNormalResponse())
{
@@ -2202,7 +2394,7 @@ GDBRemoteCommunicationClient::GetGroupName (uint32_t gid, std::string &name)
const int packet_len = ::snprintf (packet, sizeof (packet), "qGroupName:%i", gid);
assert (packet_len < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success)
{
if (response.IsNormalResponse())
{
@@ -2296,32 +2488,36 @@ GDBRemoteCommunicationClient::SendSpeedTestPacket (uint32_t send_size, uint32_t
}
StringExtractorGDBRemote response;
- return SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) > 0;
- return false;
+ return SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success;
}
uint16_t
-GDBRemoteCommunicationClient::LaunchGDBserverAndGetPort (lldb::pid_t &pid)
+GDBRemoteCommunicationClient::LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname)
{
pid = LLDB_INVALID_PROCESS_ID;
StringExtractorGDBRemote response;
StreamString stream;
stream.PutCString("qLaunchGDBServer;");
std::string hostname;
- if (Host::GetHostname (hostname))
- {
- // Make the GDB server we launch only accept connections from this host
- stream.Printf("host:%s;", hostname.c_str());
- }
+ if (remote_accept_hostname && remote_accept_hostname[0])
+ hostname = remote_accept_hostname;
else
{
- // Make the GDB server we launch accept connections from any host since we can't figure out the hostname
- stream.Printf("host:*;");
+ if (Host::GetHostname (hostname))
+ {
+ // Make the GDB server we launch only accept connections from this host
+ stream.Printf("host:%s;", hostname.c_str());
+ }
+ else
+ {
+ // Make the GDB server we launch accept connections from any host since we can't figure out the hostname
+ stream.Printf("host:*;");
+ }
}
const char *packet = stream.GetData();
int packet_len = stream.GetSize();
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
std::string name;
std::string value;
@@ -2347,7 +2543,7 @@ GDBRemoteCommunicationClient::KillSpawnedProcess (lldb::pid_t pid)
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
return true;
@@ -2369,7 +2565,7 @@ GDBRemoteCommunicationClient::SetCurrentThread (uint64_t tid)
packet_len = ::snprintf (packet, sizeof(packet), "Hg%" PRIx64, tid);
assert (packet_len + 1 < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
{
@@ -2395,7 +2591,7 @@ GDBRemoteCommunicationClient::SetCurrentThreadForRun (uint64_t tid)
assert (packet_len + 1 < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
{
@@ -2409,7 +2605,7 @@ GDBRemoteCommunicationClient::SetCurrentThreadForRun (uint64_t tid)
bool
GDBRemoteCommunicationClient::GetStopReply (StringExtractorGDBRemote &response)
{
- if (SendPacketAndWaitForResponse("?", 1, response, false))
+ if (SendPacketAndWaitForResponse("?", 1, response, false) == PacketResult::Success)
return response.IsNormalResponse();
return false;
}
@@ -2422,7 +2618,7 @@ GDBRemoteCommunicationClient::GetThreadStopInfo (lldb::tid_t tid, StringExtracto
char packet[256];
int packet_len = ::snprintf(packet, sizeof(packet), "qThreadStopInfo%" PRIx64, tid);
assert (packet_len < (int)sizeof(packet));
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.IsUnsupportedResponse())
m_supports_qThreadStopInfo = false;
@@ -2463,7 +2659,7 @@ GDBRemoteCommunicationClient::SendGDBStoppointTypePacket (GDBStoppointType type,
assert (packet_len + 1 < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, true))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, true) == PacketResult::Success)
{
if (response.IsOKResponse())
return 0;
@@ -2497,9 +2693,10 @@ GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector<lldb::tid_t> &thr
sequence_mutex_unavailable = false;
StringExtractorGDBRemote response;
- for (SendPacketNoLock ("qfThreadInfo", strlen("qfThreadInfo")) && WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ());
- response.IsNormalResponse();
- SendPacketNoLock ("qsThreadInfo", strlen("qsThreadInfo")) && WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ()))
+ PacketResult packet_result;
+ for (packet_result = SendPacketAndWaitForResponseNoLock ("qfThreadInfo", strlen("qfThreadInfo"), response);
+ packet_result == PacketResult::Success && response.IsNormalResponse();
+ packet_result = SendPacketAndWaitForResponseNoLock ("qsThreadInfo", strlen("qsThreadInfo"), response))
{
char ch = response.GetChar();
if (ch == 'l')
@@ -2539,7 +2736,7 @@ GDBRemoteCommunicationClient::GetShlibInfoAddr()
if (!IsRunning())
{
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse("qShlibInfoAddr", ::strlen ("qShlibInfoAddr"), response, false))
+ if (SendPacketAndWaitForResponse("qShlibInfoAddr", ::strlen ("qShlibInfoAddr"), response, false) == PacketResult::Success)
{
if (response.IsNormalResponse())
return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS);
@@ -2569,7 +2766,7 @@ GDBRemoteCommunicationClient::RunShellCommand (const char *command, //
const char *packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.GetChar() != 'F')
return Error("malformed reply");
@@ -2608,7 +2805,7 @@ GDBRemoteCommunicationClient::MakeDirectory (const char *path,
const char *packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
return Error(response.GetHexMaxU32(false, UINT32_MAX), eErrorTypePOSIX);
}
@@ -2628,7 +2825,7 @@ GDBRemoteCommunicationClient::SetFilePermissions (const char *path,
const char *packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
return Error(response.GetHexMaxU32(false, UINT32_MAX), eErrorTypePOSIX);
}
@@ -2679,7 +2876,7 @@ GDBRemoteCommunicationClient::OpenFile (const lldb_private::FileSpec& file_spec,
const char* packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
return ParseHostIOPacketResponse (response, UINT64_MAX, error);
}
@@ -2695,7 +2892,7 @@ GDBRemoteCommunicationClient::CloseFile (lldb::user_id_t fd,
const char* packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
return ParseHostIOPacketResponse (response, -1, error) == 0;
}
@@ -2713,7 +2910,7 @@ GDBRemoteCommunicationClient::GetFileSize (const lldb_private::FileSpec& file_sp
const char* packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.GetChar() != 'F')
return UINT64_MAX;
@@ -2733,7 +2930,7 @@ GDBRemoteCommunicationClient::GetFilePermissions(const char *path, uint32_t &fil
const char* packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.GetChar() != 'F')
{
@@ -2780,7 +2977,7 @@ GDBRemoteCommunicationClient::ReadFile (lldb::user_id_t fd,
const char* packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.GetChar() != 'F')
return 0;
@@ -2819,7 +3016,7 @@ GDBRemoteCommunicationClient::WriteFile (lldb::user_id_t fd,
const char* packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.GetChar() != 'F')
{
@@ -2861,7 +3058,7 @@ GDBRemoteCommunicationClient::CreateSymlink (const char *src, const char *dst)
const char* packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.GetChar() == 'F')
{
@@ -2902,7 +3099,7 @@ GDBRemoteCommunicationClient::Unlink (const char *path)
const char* packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.GetChar() == 'F')
{
@@ -2942,7 +3139,7 @@ GDBRemoteCommunicationClient::GetFileExists (const lldb_private::FileSpec& file_
const char* packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.GetChar() != 'F')
return false;
@@ -2966,7 +3163,7 @@ GDBRemoteCommunicationClient::CalculateMD5 (const lldb_private::FileSpec& file_s
const char* packet = stream.GetData();
int packet_len = stream.GetSize();
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success)
{
if (response.GetChar() != 'F')
return false;
@@ -2998,7 +3195,7 @@ GDBRemoteCommunicationClient::ReadRegister(lldb::tid_t tid, uint32_t reg, String
else
packet_len = ::snprintf (packet, sizeof(packet), "p%x", reg);
assert (packet_len < ((int)sizeof(packet) - 1));
- return SendPacketAndWaitForResponse(packet, response, false);
+ return SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success;
}
}
return false;
@@ -3024,7 +3221,7 @@ GDBRemoteCommunicationClient::ReadAllRegisters (lldb::tid_t tid, StringExtractor
else
packet_len = ::snprintf (packet, sizeof(packet), "g");
assert (packet_len < ((int)sizeof(packet) - 1));
- return SendPacketAndWaitForResponse(packet, response, false);
+ return SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success;
}
}
return false;
@@ -3051,7 +3248,7 @@ GDBRemoteCommunicationClient::SaveRegisterState (lldb::tid_t tid, uint32_t &save
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, response, false))
+ if (SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success)
{
if (response.IsUnsupportedResponse())
{
@@ -3094,7 +3291,7 @@ GDBRemoteCommunicationClient::RestoreRegisterState (lldb::tid_t tid, uint32_t sa
StringExtractorGDBRemote response;
- if (SendPacketAndWaitForResponse(packet, response, false))
+ if (SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success)
{
if (response.IsOKResponse())
{
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
index 564afbb2911c..a1e982b3ec4e 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -47,17 +47,38 @@ public:
bool
HandshakeWithServer (lldb_private::Error *error_ptr);
- size_t
+ PacketResult
SendPacketAndWaitForResponse (const char *send_payload,
StringExtractorGDBRemote &response,
bool send_async);
- size_t
+ PacketResult
SendPacketAndWaitForResponse (const char *send_payload,
size_t send_length,
StringExtractorGDBRemote &response,
bool send_async);
+ // For packets which specify a range of output to be returned,
+ // return all of the output via a series of request packets of the form
+ // <prefix>0,<size>
+ // <prefix><size>,<size>
+ // <prefix><size>*2,<size>
+ // <prefix><size>*3,<size>
+ // ...
+ // until a "$l..." packet is received, indicating the end.
+ // (size is in hex; this format is used by a standard gdbserver to
+ // return the given portion of the output specified by <prefix>;
+ // for example, "qXfer:libraries-svr4:read::fff,1000" means
+ // "return a chunk of the xml description file for shared
+ // library load addresses, where the chunk starts at offset 0xfff
+ // and continues for 0x1000 bytes").
+ // Concatenate the resulting server response packets together and
+ // return in response_string. If any packet fails, the return value
+ // indicates that failure and the returned string value is undefined.
+ PacketResult
+ SendPacketsAndConcatenateResponses (const char *send_payload_prefix,
+ std::string &response_string);
+
lldb::StateType
SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
const char *packet_payload,
@@ -94,7 +115,7 @@ public:
GetLaunchSuccess (std::string &error_str);
uint16_t
- LaunchGDBserverAndGetPort (lldb::pid_t &pid);
+ LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname);
bool
KillSpawnedProcess (lldb::pid_t pid);
@@ -248,6 +269,9 @@ public:
const lldb_private::ArchSpec &
GetProcessArchitecture ();
+ void
+ GetRemoteQSupported();
+
bool
GetVContSupported (char flavor);
@@ -359,6 +383,18 @@ public:
bool
SetCurrentThreadForRun (uint64_t tid);
+ bool
+ GetQXferLibrariesReadSupported ();
+
+ bool
+ GetQXferLibrariesSVR4ReadSupported ();
+
+ uint64_t
+ GetRemoteMaxPacketSize();
+
+ bool
+ GetAugmentedLibrariesSVR4ReadSupported ();
+
lldb_private::LazyBool
SupportsAllocDeallocMemory () // const
{
@@ -458,6 +494,11 @@ public:
protected:
+ PacketResult
+ SendPacketAndWaitForResponseNoLock (const char *payload,
+ size_t payload_length,
+ StringExtractorGDBRemote &response);
+
bool
GetCurrentProcessInfo ();
@@ -484,7 +525,10 @@ protected:
lldb_private::LazyBool m_prepare_for_reg_writing_reply;
lldb_private::LazyBool m_supports_p;
lldb_private::LazyBool m_supports_QSaveRegisterState;
-
+ lldb_private::LazyBool m_supports_qXfer_libraries_read;
+ lldb_private::LazyBool m_supports_qXfer_libraries_svr4_read;
+ lldb_private::LazyBool m_supports_augmented_libraries_svr4_read;
+
bool
m_supports_qProcessInfoPID:1,
m_supports_qfProcessInfo:1,
@@ -511,6 +555,7 @@ protected:
lldb_private::Mutex m_async_mutex;
lldb_private::Predicate<bool> m_async_packet_predicate;
std::string m_async_packet;
+ PacketResult m_async_result;
StringExtractorGDBRemote m_async_response;
int m_async_signal; // We were asked to deliver a signal to the inferior process.
bool m_interrupt_sent;
@@ -526,6 +571,7 @@ protected:
std::string m_os_kernel;
std::string m_hostname;
uint32_t m_default_packet_timeout;
+ uint64_t m_max_packet_size; // as returned by qSupported
bool
DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index 7cc3a05304d4..df95542d2c0f 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -25,6 +25,7 @@
#include "lldb/Host/File.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/TimeValue.h"
+#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
// Project includes
@@ -40,6 +41,7 @@ using namespace lldb_private;
//----------------------------------------------------------------------
GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(bool is_platform) :
GDBRemoteCommunication ("gdb-remote.server", "gdb-remote.server.rx_packet", is_platform),
+ m_platform_sp (Platform::GetDefaultPlatform ()),
m_async_thread (LLDB_INVALID_HOST_THREAD),
m_process_launch_info (),
m_process_launch_error (),
@@ -52,6 +54,23 @@ GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(bool is_platform) :
{
}
+GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(bool is_platform,
+ const lldb::PlatformSP& platform_sp) :
+ GDBRemoteCommunication ("gdb-remote.server", "gdb-remote.server.rx_packet", is_platform),
+ m_platform_sp (platform_sp),
+ m_async_thread (LLDB_INVALID_HOST_THREAD),
+ m_process_launch_info (),
+ m_process_launch_error (),
+ m_spawned_pids (),
+ m_spawned_pids_mutex (Mutex::eMutexTypeRecursive),
+ m_proc_infos (),
+ m_proc_infos_index (0),
+ m_port_map (),
+ m_port_offset(0)
+{
+ assert(platform_sp);
+}
+
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
@@ -90,154 +109,249 @@ GDBRemoteCommunicationServer::GetPacketAndSendResponse (uint32_t timeout_usec,
bool &quit)
{
StringExtractorGDBRemote packet;
- if (WaitForPacketWithTimeoutMicroSecondsNoLock (packet, timeout_usec))
+ PacketResult packet_result = WaitForPacketWithTimeoutMicroSecondsNoLock (packet, timeout_usec);
+ if (packet_result == PacketResult::Success)
{
const StringExtractorGDBRemote::ServerPacketType packet_type = packet.GetServerPacketType ();
switch (packet_type)
{
- case StringExtractorGDBRemote::eServerPacketType_nack:
- case StringExtractorGDBRemote::eServerPacketType_ack:
- break;
-
- case StringExtractorGDBRemote::eServerPacketType_invalid:
- error.SetErrorString("invalid packet");
- quit = true;
- break;
-
- case StringExtractorGDBRemote::eServerPacketType_interrupt:
- error.SetErrorString("interrupt received");
- interrupt = true;
- break;
+ case StringExtractorGDBRemote::eServerPacketType_nack:
+ case StringExtractorGDBRemote::eServerPacketType_ack:
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_invalid:
+ error.SetErrorString("invalid packet");
+ quit = true;
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_interrupt:
+ error.SetErrorString("interrupt received");
+ interrupt = true;
+ break;
+
+ default:
+ case StringExtractorGDBRemote::eServerPacketType_unimplemented:
+ packet_result = SendUnimplementedResponse (packet.GetStringRef().c_str());
+ break;
- case StringExtractorGDBRemote::eServerPacketType_unimplemented:
- return SendUnimplementedResponse (packet.GetStringRef().c_str()) > 0;
+ case StringExtractorGDBRemote::eServerPacketType_A:
+ packet_result = Handle_A (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_A:
- return Handle_A (packet);
+ case StringExtractorGDBRemote::eServerPacketType_qfProcessInfo:
+ packet_result = Handle_qfProcessInfo (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qfProcessInfo:
- return Handle_qfProcessInfo (packet);
+ case StringExtractorGDBRemote::eServerPacketType_qsProcessInfo:
+ packet_result = Handle_qsProcessInfo (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qsProcessInfo:
- return Handle_qsProcessInfo (packet);
+ case StringExtractorGDBRemote::eServerPacketType_qC:
+ packet_result = Handle_qC (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qC:
- return Handle_qC (packet);
+ case StringExtractorGDBRemote::eServerPacketType_qHostInfo:
+ packet_result = Handle_qHostInfo (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qHostInfo:
- return Handle_qHostInfo (packet);
+ case StringExtractorGDBRemote::eServerPacketType_qLaunchGDBServer:
+ packet_result = Handle_qLaunchGDBServer (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qLaunchGDBServer:
- return Handle_qLaunchGDBServer (packet);
+ case StringExtractorGDBRemote::eServerPacketType_qKillSpawnedProcess:
+ packet_result = Handle_qKillSpawnedProcess (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qKillSpawnedProcess:
- return Handle_qKillSpawnedProcess (packet);
+ case StringExtractorGDBRemote::eServerPacketType_k:
+ packet_result = Handle_k (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qLaunchSuccess:
- return Handle_qLaunchSuccess (packet);
+ case StringExtractorGDBRemote::eServerPacketType_qLaunchSuccess:
+ packet_result = Handle_qLaunchSuccess (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qGroupName:
- return Handle_qGroupName (packet);
+ case StringExtractorGDBRemote::eServerPacketType_qGroupName:
+ packet_result = Handle_qGroupName (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_qProcessInfoPID:
+ packet_result = Handle_qProcessInfoPID (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_qSpeedTest:
+ packet_result = Handle_qSpeedTest (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_qUserName:
+ packet_result = Handle_qUserName (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_qGetWorkingDir:
+ packet_result = Handle_qGetWorkingDir(packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_QEnvironment:
+ packet_result = Handle_QEnvironment (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_QLaunchArch:
+ packet_result = Handle_QLaunchArch (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_QSetDisableASLR:
+ packet_result = Handle_QSetDisableASLR (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_QSetSTDIN:
+ packet_result = Handle_QSetSTDIN (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_QSetSTDOUT:
+ packet_result = Handle_QSetSTDOUT (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_QSetSTDERR:
+ packet_result = Handle_QSetSTDERR (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_QSetWorkingDir:
+ packet_result = Handle_QSetWorkingDir (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_QStartNoAckMode:
+ packet_result = Handle_QStartNoAckMode (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_qPlatform_mkdir:
+ packet_result = Handle_qPlatform_mkdir (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_qPlatform_chmod:
+ packet_result = Handle_qPlatform_chmod (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_qPlatform_shell:
+ packet_result = Handle_qPlatform_shell (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qProcessInfoPID:
- return Handle_qProcessInfoPID (packet);
+ case StringExtractorGDBRemote::eServerPacketType_vFile_open:
+ packet_result = Handle_vFile_Open (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qSpeedTest:
- return Handle_qSpeedTest (packet);
-
- case StringExtractorGDBRemote::eServerPacketType_qUserName:
- return Handle_qUserName (packet);
-
- case StringExtractorGDBRemote::eServerPacketType_qGetWorkingDir:
- return Handle_qGetWorkingDir(packet);
-
- case StringExtractorGDBRemote::eServerPacketType_QEnvironment:
- return Handle_QEnvironment (packet);
+ case StringExtractorGDBRemote::eServerPacketType_vFile_close:
+ packet_result = Handle_vFile_Close (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_QLaunchArch:
- return Handle_QLaunchArch (packet);
+ case StringExtractorGDBRemote::eServerPacketType_vFile_pread:
+ packet_result = Handle_vFile_pRead (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_QSetDisableASLR:
- return Handle_QSetDisableASLR (packet);
+ case StringExtractorGDBRemote::eServerPacketType_vFile_pwrite:
+ packet_result = Handle_vFile_pWrite (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_QSetSTDIN:
- return Handle_QSetSTDIN (packet);
+ case StringExtractorGDBRemote::eServerPacketType_vFile_size:
+ packet_result = Handle_vFile_Size (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_QSetSTDOUT:
- return Handle_QSetSTDOUT (packet);
+ case StringExtractorGDBRemote::eServerPacketType_vFile_mode:
+ packet_result = Handle_vFile_Mode (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_QSetSTDERR:
- return Handle_QSetSTDERR (packet);
+ case StringExtractorGDBRemote::eServerPacketType_vFile_exists:
+ packet_result = Handle_vFile_Exists (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_QSetWorkingDir:
- return Handle_QSetWorkingDir (packet);
+ case StringExtractorGDBRemote::eServerPacketType_vFile_stat:
+ packet_result = Handle_vFile_Stat (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_QStartNoAckMode:
- return Handle_QStartNoAckMode (packet);
+ case StringExtractorGDBRemote::eServerPacketType_vFile_md5:
+ packet_result = Handle_vFile_MD5 (packet);
+ break;
- case StringExtractorGDBRemote::eServerPacketType_qPlatform_mkdir:
- return Handle_qPlatform_mkdir (packet);
-
- case StringExtractorGDBRemote::eServerPacketType_qPlatform_chmod:
- return Handle_qPlatform_chmod (packet);
-
- case StringExtractorGDBRemote::eServerPacketType_qPlatform_shell:
- return Handle_qPlatform_shell (packet);
-
- case StringExtractorGDBRemote::eServerPacketType_vFile_open:
- return Handle_vFile_Open (packet);
-
- case StringExtractorGDBRemote::eServerPacketType_vFile_close:
- return Handle_vFile_Close (packet);
+ case StringExtractorGDBRemote::eServerPacketType_vFile_symlink:
+ packet_result = Handle_vFile_symlink (packet);
+ break;
+
+ case StringExtractorGDBRemote::eServerPacketType_vFile_unlink:
+ packet_result = Handle_vFile_unlink (packet);
+ break;
+ }
+ }
+ else
+ {
+ if (!IsConnected())
+ {
+ error.SetErrorString("lost connection");
+ quit = true;
+ }
+ else
+ {
+ error.SetErrorString("timeout");
+ }
+ }
+ return packet_result == PacketResult::Success;
+}
- case StringExtractorGDBRemote::eServerPacketType_vFile_pread:
- return Handle_vFile_pRead (packet);
+lldb_private::Error
+GDBRemoteCommunicationServer::SetLaunchArguments (const char *const args[], int argc)
+{
+ if ((argc < 1) || !args || !args[0] || !args[0][0])
+ return lldb_private::Error ("%s: no process command line specified to launch", __FUNCTION__);
- case StringExtractorGDBRemote::eServerPacketType_vFile_pwrite:
- return Handle_vFile_pWrite (packet);
+ m_process_launch_info.SetArguments (const_cast<const char**> (args), true);
+ return lldb_private::Error ();
+}
- case StringExtractorGDBRemote::eServerPacketType_vFile_size:
- return Handle_vFile_Size (packet);
+lldb_private::Error
+GDBRemoteCommunicationServer::SetLaunchFlags (unsigned int launch_flags)
+{
+ m_process_launch_info.GetFlags ().Set (launch_flags);
+ return lldb_private::Error ();
+}
- case StringExtractorGDBRemote::eServerPacketType_vFile_mode:
- return Handle_vFile_Mode (packet);
+lldb_private::Error
+GDBRemoteCommunicationServer::LaunchProcess ()
+{
+ if (!m_process_launch_info.GetArguments ().GetArgumentCount ())
+ return lldb_private::Error ("%s: no process command line specified to launch", __FUNCTION__);
- case StringExtractorGDBRemote::eServerPacketType_vFile_exists:
- return Handle_vFile_Exists (packet);
+ // specify the process monitor if not already set. This should
+ // generally be what happens since we need to reap started
+ // processes.
+ if (!m_process_launch_info.GetMonitorProcessCallback ())
+ m_process_launch_info.SetMonitorProcessCallback(ReapDebuggedProcess, this, false);
- case StringExtractorGDBRemote::eServerPacketType_vFile_stat:
- return Handle_vFile_Stat (packet);
+ lldb_private::Error error = m_platform_sp->LaunchProcess (m_process_launch_info);
+ if (!error.Success ())
+ {
+ fprintf (stderr, "%s: failed to launch executable %s", __FUNCTION__, m_process_launch_info.GetArguments ().GetArgumentAtIndex (0));
+ return error;
+ }
- case StringExtractorGDBRemote::eServerPacketType_vFile_md5:
- return Handle_vFile_MD5 (packet);
+ printf ("Launched '%s' as process %" PRIu64 "...\n", m_process_launch_info.GetArguments ().GetArgumentAtIndex (0), m_process_launch_info.GetProcessID());
- case StringExtractorGDBRemote::eServerPacketType_vFile_symlink:
- return Handle_vFile_symlink (packet);
-
- case StringExtractorGDBRemote::eServerPacketType_vFile_unlink:
- return Handle_vFile_unlink (packet);
- }
- return true;
- }
- else
+ // add to list of spawned processes. On an lldb-gdbserver, we
+ // would expect there to be only one.
+ lldb::pid_t pid;
+ if ( (pid = m_process_launch_info.GetProcessID()) != LLDB_INVALID_PROCESS_ID )
{
- if (!IsConnected())
- error.SetErrorString("lost connection");
- else
- error.SetErrorString("timeout");
+ Mutex::Locker locker (m_spawned_pids_mutex);
+ m_spawned_pids.insert(pid);
}
- return false;
+ return error;
}
-size_t
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::SendUnimplementedResponse (const char *)
{
// TODO: Log the packet we aren't handling...
return SendPacketNoLock ("", 0);
}
-size_t
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::SendErrorResponse (uint8_t err)
{
char packet[16];
@@ -247,7 +361,7 @@ GDBRemoteCommunicationServer::SendErrorResponse (uint8_t err)
}
-size_t
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::SendOKResponse ()
{
return SendPacketNoLock ("OK", 2);
@@ -256,10 +370,10 @@ GDBRemoteCommunicationServer::SendOKResponse ()
bool
GDBRemoteCommunicationServer::HandshakeWithClient(Error *error_ptr)
{
- return GetAck();
+ return GetAck() == PacketResult::Success;
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet)
{
StreamString response;
@@ -272,6 +386,14 @@ GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet
response.PutCStringAsRawHex8(host_triple.getTriple().c_str());
response.Printf (";ptrsize:%u;",host_arch.GetAddressByteSize());
+ const char* distribution_id = host_arch.GetDistributionId ().AsCString ();
+ if (distribution_id)
+ {
+ response.PutCString("distribution_id:");
+ response.PutCStringAsRawHex8(distribution_id);
+ response.PutCString(";");
+ }
+
uint32_t cpu = host_arch.GetMachOCPUType();
uint32_t sub = host_arch.GetMachOCPUSubType();
if (cpu != LLDB_INVALID_CPUTYPE)
@@ -351,7 +473,7 @@ GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet
}
#endif // #if defined(__APPLE__)
- return SendPacketNoLock (response.GetData(), response.GetSize()) > 0;
+ return SendPacketNoLock (response.GetData(), response.GetSize());
}
static void
@@ -377,7 +499,7 @@ CreateProcessInfoResponse (const ProcessInstanceInfo &proc_info, StreamString &r
}
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qProcessInfoPID (StringExtractorGDBRemote &packet)
{
// Packet format: "qProcessInfoPID:%i" where %i is the pid
@@ -396,7 +518,7 @@ GDBRemoteCommunicationServer::Handle_qProcessInfoPID (StringExtractorGDBRemote &
return SendErrorResponse (1);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qfProcessInfo (StringExtractorGDBRemote &packet)
{
m_proc_infos_index = 0;
@@ -497,7 +619,7 @@ GDBRemoteCommunicationServer::Handle_qfProcessInfo (StringExtractorGDBRemote &pa
return SendErrorResponse (3);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qsProcessInfo (StringExtractorGDBRemote &packet)
{
if (m_proc_infos_index < m_proc_infos.GetSize())
@@ -510,7 +632,7 @@ GDBRemoteCommunicationServer::Handle_qsProcessInfo (StringExtractorGDBRemote &pa
return SendErrorResponse (4);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qUserName (StringExtractorGDBRemote &packet)
{
// Packet format: "qUserName:%i" where %i is the uid
@@ -530,7 +652,7 @@ GDBRemoteCommunicationServer::Handle_qUserName (StringExtractorGDBRemote &packet
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qGroupName (StringExtractorGDBRemote &packet)
{
// Packet format: "qGroupName:%i" where %i is the gid
@@ -549,7 +671,7 @@ GDBRemoteCommunicationServer::Handle_qGroupName (StringExtractorGDBRemote &packe
return SendErrorResponse (6);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qSpeedTest (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen ("qSpeedTest:"));
@@ -641,7 +763,7 @@ AcceptPortFromInferior (void *arg)
// return false;
//}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_A (StringExtractorGDBRemote &packet)
{
// The 'A' packet is the most over designed packet ever here with
@@ -708,8 +830,11 @@ GDBRemoteCommunicationServer::Handle_A (StringExtractorGDBRemote &packet)
if (success)
{
+ // FIXME: remove linux restriction once eLaunchFlagDebug is supported
+#if !defined (__linux__)
m_process_launch_info.GetFlags().Set (eLaunchFlagDebug);
- m_process_launch_error = Host::LaunchProcess (m_process_launch_info);
+#endif
+ m_process_launch_error = LaunchProcess ();
if (m_process_launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID)
{
return SendOKResponse ();
@@ -718,7 +843,7 @@ GDBRemoteCommunicationServer::Handle_A (StringExtractorGDBRemote &packet)
return SendErrorResponse (8);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qC (StringExtractorGDBRemote &packet)
{
lldb::pid_t pid = m_process_launch_info.GetProcessID();
@@ -762,11 +887,30 @@ GDBRemoteCommunicationServer::ReapDebugserverProcess (void *callback_baton,
}
bool
+GDBRemoteCommunicationServer::DebuggedProcessReaped (lldb::pid_t pid)
+{
+ // reap a process that we were debugging (but not debugserver)
+ Mutex::Locker locker (m_spawned_pids_mutex);
+ return m_spawned_pids.erase(pid) > 0;
+}
+
+bool
+GDBRemoteCommunicationServer::ReapDebuggedProcess (void *callback_baton,
+ lldb::pid_t pid,
+ bool exited,
+ int signal, // Zero for no signal
+ int status) // Exit value of process if signal is zero
+{
+ GDBRemoteCommunicationServer *server = (GDBRemoteCommunicationServer *)callback_baton;
+ server->DebuggedProcessReaped (pid);
+ return true;
+}
+
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet)
{
#ifdef _WIN32
- // No unix sockets on windows
- return false;
+ return SendErrorResponse(9);
#else
// Spawn a local debugserver as a platform so we can then attach or launch
// a process...
@@ -775,7 +919,6 @@ GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote
{
// Sleep and wait a bit for debugserver to start to listen...
ConnectionFileDescriptor file_conn;
- char connect_url[PATH_MAX];
Error error;
std::string hostname;
// TODO: /tmp/ should not be hardcoded. User might want to override /tmp
@@ -796,45 +939,23 @@ GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote
// Spawn a new thread to accept the port that gets bound after
// binding to port 0 (zero).
- lldb::thread_t accept_thread = LLDB_INVALID_HOST_THREAD;
- const char *unix_socket_name = NULL;
- char unix_socket_name_buf[PATH_MAX] = "/tmp/XXXXXXXXX";
-
- if (port == 0)
- {
- if (::mkstemp (unix_socket_name_buf) == 0)
- {
- unix_socket_name = unix_socket_name_buf;
- ::snprintf (connect_url, sizeof(connect_url), "unix-accept://%s", unix_socket_name);
- accept_thread = Host::ThreadCreate (unix_socket_name,
- AcceptPortFromInferior,
- connect_url,
- &error);
- }
- else
- {
- error.SetErrorStringWithFormat("failed to make temporary path for a unix socket: %s", strerror(errno));
- }
- }
if (error.Success())
{
// Spawn a debugserver and try to get the port it listens to.
ProcessLaunchInfo debugserver_launch_info;
- StreamString host_and_port;
if (hostname.empty())
hostname = "localhost";
- host_and_port.Printf("%s:%u", hostname.c_str(), port);
- const char *host_and_port_cstr = host_and_port.GetString().c_str();
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
if (log)
- log->Printf("Launching debugserver with: %s...\n", host_and_port_cstr);
+ log->Printf("Launching debugserver with: %s:%u...\n", hostname.c_str(), port);
debugserver_launch_info.SetMonitorProcessCallback(ReapDebugserverProcess, this, false);
- error = StartDebugserverProcess (host_and_port_cstr,
- unix_socket_name,
- debugserver_launch_info);
+ error = StartDebugserverProcess (hostname.empty() ? NULL : hostname.c_str(),
+ port,
+ debugserver_launch_info,
+ port);
lldb::pid_t debugserver_pid = debugserver_launch_info.GetProcessID();
@@ -854,45 +975,17 @@ GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote
if (error.Success())
{
- bool success = false;
+ char response[256];
+ const int response_len = ::snprintf (response, sizeof(response), "pid:%" PRIu64 ";port:%u;", debugserver_pid, port + m_port_offset);
+ assert (response_len < sizeof(response));
+ PacketResult packet_result = SendPacketNoLock (response, response_len);
- if (IS_VALID_LLDB_HOST_THREAD(accept_thread))
- {
- thread_result_t accept_thread_result = NULL;
- if (Host::ThreadJoin (accept_thread, &accept_thread_result, &error))
- {
- if (accept_thread_result)
- {
- port = (intptr_t)accept_thread_result;
- char response[256];
- const int response_len = ::snprintf (response, sizeof(response), "pid:%" PRIu64 ";port:%u;", debugserver_pid, port + m_port_offset);
- assert (response_len < sizeof(response));
- //m_port_to_pid_map[port] = debugserver_launch_info.GetProcessID();
- success = SendPacketNoLock (response, response_len) > 0;
- }
- }
- }
- else
- {
- char response[256];
- const int response_len = ::snprintf (response, sizeof(response), "pid:%" PRIu64 ";port:%u;", debugserver_pid, port + m_port_offset);
- assert (response_len < sizeof(response));
- //m_port_to_pid_map[port] = debugserver_launch_info.GetProcessID();
- success = SendPacketNoLock (response, response_len) > 0;
-
- }
- Host::Unlink (unix_socket_name);
-
- if (!success)
+ if (packet_result != PacketResult::Success)
{
if (debugserver_pid != LLDB_INVALID_PROCESS_ID)
::kill (debugserver_pid, SIGINT);
}
- return success;
- }
- else if (accept_thread)
- {
- Host::Unlink (unix_socket_name);
+ return packet_result;
}
}
}
@@ -901,59 +994,124 @@ GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote
}
bool
-GDBRemoteCommunicationServer::Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet)
+GDBRemoteCommunicationServer::KillSpawnedProcess (lldb::pid_t pid)
{
- // Spawn a local debugserver as a platform so we can then attach or launch
- // a process...
-
- if (m_is_platform)
+ // make sure we know about this process
{
- packet.SetFilePos(::strlen ("qKillSpawnedProcess:"));
+ Mutex::Locker locker (m_spawned_pids_mutex);
+ if (m_spawned_pids.find(pid) == m_spawned_pids.end())
+ return false;
+ }
- lldb::pid_t pid = packet.GetU64(LLDB_INVALID_PROCESS_ID);
+ // first try a SIGTERM (standard kill)
+ Host::Kill (pid, SIGTERM);
- // Scope for locker
+ // check if that worked
+ for (size_t i=0; i<10; ++i)
+ {
{
Mutex::Locker locker (m_spawned_pids_mutex);
if (m_spawned_pids.find(pid) == m_spawned_pids.end())
- return SendErrorResponse (10);
+ {
+ // it is now killed
+ return true;
+ }
}
- Host::Kill (pid, SIGTERM);
+ usleep (10000);
+ }
+
+ // check one more time after the final usleep
+ {
+ Mutex::Locker locker (m_spawned_pids_mutex);
+ if (m_spawned_pids.find(pid) == m_spawned_pids.end())
+ return true;
+ }
+
+ // the launched process still lives. Now try killling it again,
+ // this time with an unblockable signal.
+ Host::Kill (pid, SIGKILL);
- for (size_t i=0; i<10; ++i)
+ for (size_t i=0; i<10; ++i)
+ {
{
- // Scope for locker
+ Mutex::Locker locker (m_spawned_pids_mutex);
+ if (m_spawned_pids.find(pid) == m_spawned_pids.end())
{
- Mutex::Locker locker (m_spawned_pids_mutex);
- if (m_spawned_pids.find(pid) == m_spawned_pids.end())
- return SendOKResponse();
+ // it is now killed
+ return true;
}
- usleep (10000);
}
+ usleep (10000);
+ }
+
+ // check one more time after the final usleep
+ // Scope for locker
+ {
+ Mutex::Locker locker (m_spawned_pids_mutex);
+ if (m_spawned_pids.find(pid) == m_spawned_pids.end())
+ return true;
+ }
+
+ // no luck - the process still lives
+ return false;
+}
+
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServer::Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet)
+{
+ packet.SetFilePos(::strlen ("qKillSpawnedProcess:"));
+
+ lldb::pid_t pid = packet.GetU64(LLDB_INVALID_PROCESS_ID);
- // Scope for locker
+ // verify that we know anything about this pid.
+ // Scope for locker
+ {
+ Mutex::Locker locker (m_spawned_pids_mutex);
+ if (m_spawned_pids.find(pid) == m_spawned_pids.end())
{
- Mutex::Locker locker (m_spawned_pids_mutex);
- if (m_spawned_pids.find(pid) == m_spawned_pids.end())
- return SendOKResponse();
+ // not a pid we know about
+ return SendErrorResponse (10);
}
- Host::Kill (pid, SIGKILL);
+ }
+
+ // go ahead and attempt to kill the spawned process
+ if (KillSpawnedProcess (pid))
+ return SendOKResponse ();
+ else
+ return SendErrorResponse (11);
+}
+
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServer::Handle_k (StringExtractorGDBRemote &packet)
+{
+ // ignore for now if we're lldb_platform
+ if (m_is_platform)
+ return SendUnimplementedResponse (packet.GetStringRef().c_str());
- for (size_t i=0; i<10; ++i)
+ // shutdown all spawned processes
+ std::set<lldb::pid_t> spawned_pids_copy;
+
+ // copy pids
+ {
+ Mutex::Locker locker (m_spawned_pids_mutex);
+ spawned_pids_copy.insert (m_spawned_pids.begin (), m_spawned_pids.end ());
+ }
+
+ // nuke the spawned processes
+ for (auto it = spawned_pids_copy.begin (); it != spawned_pids_copy.end (); ++it)
+ {
+ lldb::pid_t spawned_pid = *it;
+ if (!KillSpawnedProcess (spawned_pid))
{
- // Scope for locker
- {
- Mutex::Locker locker (m_spawned_pids_mutex);
- if (m_spawned_pids.find(pid) == m_spawned_pids.end())
- return SendOKResponse();
- }
- usleep (10000);
+ fprintf (stderr, "%s: failed to kill spawned pid %" PRIu64 ", ignoring.\n", __FUNCTION__, spawned_pid);
}
}
- return SendErrorResponse (11);
+
+ // TODO figure out how to shut down gracefully at this point
+ return SendOKResponse ();
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qLaunchSuccess (StringExtractorGDBRemote &packet)
{
if (m_process_launch_error.Success())
@@ -964,7 +1122,7 @@ GDBRemoteCommunicationServer::Handle_qLaunchSuccess (StringExtractorGDBRemote &p
return SendPacketNoLock (response.GetData(), response.GetSize());
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_QEnvironment (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen ("QEnvironment:"));
@@ -977,7 +1135,7 @@ GDBRemoteCommunicationServer::Handle_QEnvironment (StringExtractorGDBRemote &pa
return SendErrorResponse (12);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_QLaunchArch (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen ("QLaunchArch:"));
@@ -992,7 +1150,7 @@ GDBRemoteCommunicationServer::Handle_QLaunchArch (StringExtractorGDBRemote &pack
return SendErrorResponse(13);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_QSetDisableASLR (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen ("QSetDisableASLR:"));
@@ -1003,7 +1161,7 @@ GDBRemoteCommunicationServer::Handle_QSetDisableASLR (StringExtractorGDBRemote &
return SendOKResponse ();
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_QSetWorkingDir (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen ("QSetWorkingDir:"));
@@ -1027,7 +1185,7 @@ GDBRemoteCommunicationServer::Handle_QSetWorkingDir (StringExtractorGDBRemote &p
return SendOKResponse ();
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qGetWorkingDir (StringExtractorGDBRemote &packet)
{
StreamString response;
@@ -1043,8 +1201,7 @@ GDBRemoteCommunicationServer::Handle_qGetWorkingDir (StringExtractorGDBRemote &p
else
{
response.PutBytesAsRawHex8(cwd, strlen(cwd));
- SendPacketNoLock(response.GetData(), response.GetSize());
- return true;
+ return SendPacketNoLock(response.GetData(), response.GetSize());
}
}
else
@@ -1053,8 +1210,7 @@ GDBRemoteCommunicationServer::Handle_qGetWorkingDir (StringExtractorGDBRemote &p
if (working_dir && working_dir[0])
{
response.PutBytesAsRawHex8(working_dir, strlen(working_dir));
- SendPacketNoLock(response.GetData(), response.GetSize());
- return true;
+ return SendPacketNoLock(response.GetData(), response.GetSize());
}
else
{
@@ -1063,7 +1219,7 @@ GDBRemoteCommunicationServer::Handle_qGetWorkingDir (StringExtractorGDBRemote &p
}
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_QSetSTDIN (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen ("QSetSTDIN:"));
@@ -1080,7 +1236,7 @@ GDBRemoteCommunicationServer::Handle_QSetSTDIN (StringExtractorGDBRemote &packet
return SendErrorResponse (15);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_QSetSTDOUT (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen ("QSetSTDOUT:"));
@@ -1097,7 +1253,7 @@ GDBRemoteCommunicationServer::Handle_QSetSTDOUT (StringExtractorGDBRemote &packe
return SendErrorResponse (16);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_QSetSTDERR (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen ("QSetSTDERR:"));
@@ -1114,16 +1270,16 @@ GDBRemoteCommunicationServer::Handle_QSetSTDERR (StringExtractorGDBRemote &packe
return SendErrorResponse (17);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_QStartNoAckMode (StringExtractorGDBRemote &packet)
{
// Send response first before changing m_send_acks to we ack this packet
- SendOKResponse ();
+ PacketResult packet_result = SendOKResponse ();
m_send_acks = false;
- return true;
+ return packet_result;
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qPlatform_mkdir (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("qPlatform_mkdir:"));
@@ -1141,7 +1297,7 @@ GDBRemoteCommunicationServer::Handle_qPlatform_mkdir (StringExtractorGDBRemote &
return SendErrorResponse(20);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qPlatform_chmod (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("qPlatform_chmod:"));
@@ -1160,7 +1316,7 @@ GDBRemoteCommunicationServer::Handle_qPlatform_chmod (StringExtractorGDBRemote &
return SendErrorResponse(19);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_Open (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("vFile:open:"));
@@ -1176,7 +1332,6 @@ GDBRemoteCommunicationServer::Handle_vFile_Open (StringExtractorGDBRemote &packe
mode_t mode = packet.GetHexMaxU32(false, 0600);
Error error;
int fd = ::open (path.c_str(), flags, mode);
- printf ("open('%s', flags=0x%x, mode=%o) fd = %i (%s)\n", path.c_str(), flags, mode, fd, fd == -1 ? strerror(errno) : "<success>");
const int save_errno = fd == -1 ? errno : 0;
StreamString response;
response.PutChar('F');
@@ -1190,7 +1345,7 @@ GDBRemoteCommunicationServer::Handle_vFile_Open (StringExtractorGDBRemote &packe
return SendErrorResponse(18);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_Close (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("vFile:close:"));
@@ -1215,7 +1370,7 @@ GDBRemoteCommunicationServer::Handle_vFile_Close (StringExtractorGDBRemote &pack
return SendPacketNoLock(response.GetData(), response.GetSize());
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_pRead (StringExtractorGDBRemote &packet)
{
#ifdef _WIN32
@@ -1257,7 +1412,7 @@ GDBRemoteCommunicationServer::Handle_vFile_pRead (StringExtractorGDBRemote &pack
#endif
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_pWrite (StringExtractorGDBRemote &packet)
{
#ifdef _WIN32
@@ -1294,7 +1449,7 @@ GDBRemoteCommunicationServer::Handle_vFile_pWrite (StringExtractorGDBRemote &pac
#endif
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_Size (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("vFile:size:"));
@@ -1316,7 +1471,7 @@ GDBRemoteCommunicationServer::Handle_vFile_Size (StringExtractorGDBRemote &packe
return SendErrorResponse(22);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_Mode (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("vFile:mode:"));
@@ -1335,7 +1490,7 @@ GDBRemoteCommunicationServer::Handle_vFile_Mode (StringExtractorGDBRemote &packe
return SendErrorResponse(23);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_Exists (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("vFile:exists:"));
@@ -1356,7 +1511,7 @@ GDBRemoteCommunicationServer::Handle_vFile_Exists (StringExtractorGDBRemote &pac
return SendErrorResponse(24);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_symlink (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("vFile:symlink:"));
@@ -1370,7 +1525,7 @@ GDBRemoteCommunicationServer::Handle_vFile_symlink (StringExtractorGDBRemote &pa
return SendPacketNoLock(response.GetData(), response.GetSize());
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_unlink (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("vFile:unlink:"));
@@ -1382,7 +1537,7 @@ GDBRemoteCommunicationServer::Handle_vFile_unlink (StringExtractorGDBRemote &pac
return SendPacketNoLock(response.GetData(), response.GetSize());
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_qPlatform_shell (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("qPlatform_shell:"));
@@ -1424,13 +1579,13 @@ GDBRemoteCommunicationServer::Handle_qPlatform_shell (StringExtractorGDBRemote &
return SendErrorResponse(24);
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_Stat (StringExtractorGDBRemote &packet)
{
return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_vFile_Stat() unimplemented");
}
-bool
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::Handle_vFile_MD5 (StringExtractorGDBRemote &packet)
{
packet.SetFilePos(::strlen("vFile:MD5:"));
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
index 721ea5012b33..913c6b673cfb 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
@@ -37,6 +37,9 @@ public:
//------------------------------------------------------------------
GDBRemoteCommunicationServer(bool is_platform);
+ GDBRemoteCommunicationServer(bool is_platform,
+ const lldb::PlatformSP& platform_sp);
+
virtual
~GDBRemoteCommunicationServer();
@@ -138,7 +141,55 @@ public:
m_port_offset = port_offset;
}
+ //------------------------------------------------------------------
+ /// Specify the program to launch and its arguments.
+ ///
+ /// The LaunchProcess () command can be executed to do the lauching.
+ ///
+ /// @param[in] args
+ /// The command line to launch.
+ ///
+ /// @param[in] argc
+ /// The number of elements in the args array of cstring pointers.
+ ///
+ /// @return
+ /// An Error object indicating the success or failure of making
+ /// the setting.
+ //------------------------------------------------------------------
+ lldb_private::Error
+ SetLaunchArguments (const char *const args[], int argc);
+
+ //------------------------------------------------------------------
+ /// Specify the launch flags for the process.
+ ///
+ /// The LaunchProcess () command can be executed to do the lauching.
+ ///
+ /// @param[in] launch_flags
+ /// The launch flags to use when launching this process.
+ ///
+ /// @return
+ /// An Error object indicating the success or failure of making
+ /// the setting.
+ //------------------------------------------------------------------
+ lldb_private::Error
+ SetLaunchFlags (unsigned int launch_flags);
+
+ //------------------------------------------------------------------
+ /// Launch a process with the current launch settings.
+ ///
+ /// This method supports running an lldb-gdbserver or similar
+ /// server in a situation where the startup code has been provided
+ /// with all the information for a child process to be launched.
+ ///
+ /// @return
+ /// An Error object indicating the success or failure of the
+ /// launch.
+ //------------------------------------------------------------------
+ lldb_private::Error
+ LaunchProcess ();
+
protected:
+ lldb::PlatformSP m_platform_sp;
lldb::thread_t m_async_thread;
lldb_private::ProcessLaunchInfo m_process_launch_info;
lldb_private::Error m_process_launch_error;
@@ -148,120 +199,123 @@ protected:
uint32_t m_proc_infos_index;
PortMap m_port_map;
uint16_t m_port_offset;
-
- size_t
+
+ PacketResult
SendUnimplementedResponse (const char *packet);
- size_t
+ PacketResult
SendErrorResponse (uint8_t error);
- size_t
+ PacketResult
SendOKResponse ();
- bool
+ PacketResult
Handle_A (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qLaunchSuccess (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qHostInfo (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
+ Handle_k (StringExtractorGDBRemote &packet);
+
+ PacketResult
Handle_qPlatform_mkdir (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qPlatform_chmod (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qProcessInfoPID (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qfProcessInfo (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qsProcessInfo (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qC (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qUserName (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qGroupName (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qSpeedTest (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_QEnvironment (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_QLaunchArch (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_QSetDisableASLR (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_QSetWorkingDir (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qGetWorkingDir (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_QStartNoAckMode (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_QSetSTDIN (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_QSetSTDOUT (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_QSetSTDERR (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_Open (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_Close (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_pRead (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_pWrite (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_Size (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_Mode (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_Exists (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_symlink (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_unlink (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_Stat (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_vFile_MD5 (StringExtractorGDBRemote &packet);
- bool
+ PacketResult
Handle_qPlatform_shell (StringExtractorGDBRemote &packet);
private:
@@ -275,6 +329,19 @@ private:
int signal,
int status);
+ bool
+ DebuggedProcessReaped (lldb::pid_t pid);
+
+ static bool
+ ReapDebuggedProcess (void *callback_baton,
+ lldb::pid_t pid,
+ bool exited,
+ int signal,
+ int status);
+
+ bool
+ KillSpawnedProcess (lldb::pid_t pid);
+
//------------------------------------------------------------------
// For GDBRemoteCommunicationServer only
//------------------------------------------------------------------
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index c291df786d10..73b9b3e8267e 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -275,7 +275,7 @@ GDBRemoteRegisterContext::SetPrimordialRegister(const lldb_private::RegisterInfo
if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(),
packet.GetString().size(),
response,
- false))
+ false) == GDBRemoteCommunication::PacketResult::Success)
{
if (response.IsOKResponse())
return true;
@@ -298,7 +298,7 @@ GDBRemoteRegisterContext::SyncThreadState(Process *process)
if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(),
packet.GetString().size(),
response,
- false))
+ false) == GDBRemoteCommunication::PacketResult::Success)
{
if (response.IsOKResponse())
InvalidateAllRegisters();
@@ -363,7 +363,7 @@ GDBRemoteRegisterContext::WriteRegisterBytes (const lldb_private::RegisterInfo *
if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(),
packet.GetString().size(),
response,
- false))
+ false) == GDBRemoteCommunication::PacketResult::Success)
{
SetAllRegisterValid (false);
if (response.IsOKResponse())
@@ -519,7 +519,7 @@ GDBRemoteRegisterContext::ReadAllRegisterValues (lldb::DataBufferSP &data_sp)
packet_len = ::snprintf (packet, sizeof(packet), "g");
assert (packet_len < ((int)sizeof(packet) - 1));
- if (gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, false) == GDBRemoteCommunication::PacketResult::Success)
{
if (response.IsErrorResponse())
return false;
@@ -591,7 +591,7 @@ GDBRemoteRegisterContext::WriteAllRegisterValues (const lldb::DataBufferSP &data
if (gdb_comm.SendPacketAndWaitForResponse (G_packet,
G_packet_len,
response,
- false))
+ false) == GDBRemoteCommunication::PacketResult::Success)
{
if (response.IsOKResponse())
return true;
@@ -660,7 +660,7 @@ GDBRemoteRegisterContext::WriteAllRegisterValues (const lldb::DataBufferSP &data
if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(),
packet.GetString().size(),
response,
- false))
+ false) == GDBRemoteCommunication::PacketResult::Success)
{
if (response.IsOKResponse())
++num_restored;
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 7f1fbefc1b7e..e1989eb1dd14 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -34,7 +34,6 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/ConnectionFileDescriptor.h"
#include "lldb/Host/FileSpec.h"
-#include "lldb/Core/InputReader.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
@@ -95,7 +94,7 @@ using namespace lldb_private;
namespace {
-
+
static PropertyDefinition
g_properties[] =
{
@@ -187,7 +186,7 @@ get_random_port ()
if (!rand_initialized)
{
time_t seed = time(NULL);
-
+
rand_initialized = true;
srand(seed);
}
@@ -386,7 +385,7 @@ ProcessGDBRemote::BuildDynamicRegisterInfo (bool force)
const int packet_len = ::snprintf (packet, sizeof(packet), "qRegisterInfo%x", reg_num);
assert (packet_len < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (m_gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ if (m_gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, false) == GDBRemoteCommunication::PacketResult::Success)
{
response_type = response.GetResponseType();
if (response_type == StringExtractorGDBRemote::eResponse)
@@ -537,6 +536,10 @@ ProcessGDBRemote::BuildDynamicRegisterInfo (bool force)
m_register_info.AddRegister(reg_info, reg_name, alt_name, set_name);
}
+ else
+ {
+ break; // ensure exit before reg_num is incremented
+ }
}
else
{
@@ -645,13 +648,20 @@ ProcessGDBRemote::DoConnectRemote (Stream *strm, const char *remote_url)
// We have a valid process
SetID (pid);
GetThreadList();
- if (m_gdb_comm.SendPacketAndWaitForResponse("?", 1, m_last_stop_packet, false))
+ if (m_gdb_comm.SendPacketAndWaitForResponse("?", 1, m_last_stop_packet, false) == GDBRemoteCommunication::PacketResult::Success)
{
- if (!m_target.GetArchitecture().IsValid()) { // Make sure we have an architecture
- m_target.SetArchitecture(m_gdb_comm.GetProcessArchitecture());
+ if (!m_target.GetArchitecture().IsValid())
+ {
+ if (m_gdb_comm.GetProcessArchitecture().IsValid())
+ {
+ m_target.SetArchitecture(m_gdb_comm.GetProcessArchitecture());
+ }
+ else
+ {
+ m_target.SetArchitecture(m_gdb_comm.GetHostArchitecture());
+ }
}
-
const StateType state = SetThreadStopInfo (m_last_stop_packet);
if (state == eStateStopped)
{
@@ -690,7 +700,7 @@ ProcessGDBRemote::WillLaunchOrAttach ()
// Process Control
//----------------------------------------------------------------------
Error
-ProcessGDBRemote::DoLaunch (Module *exe_module, const ProcessLaunchInfo &launch_info)
+ProcessGDBRemote::DoLaunch (Module *exe_module, ProcessLaunchInfo &launch_info)
{
Error error;
@@ -728,23 +738,10 @@ ProcessGDBRemote::DoLaunch (Module *exe_module, const ProcessLaunchInfo &launch_
ObjectFile * object_file = exe_module->GetObjectFile();
if (object_file)
{
- char host_port[128];
- snprintf (host_port, sizeof(host_port), "localhost:%u", get_random_port ());
- char connect_url[128];
- snprintf (connect_url, sizeof(connect_url), "connect://%s", host_port);
-
// Make sure we aren't already connected?
if (!m_gdb_comm.IsConnected())
{
- error = StartDebugserverProcess (host_port, launch_info);
- if (error.Fail())
- {
- if (log)
- log->Printf("failed to start debugserver process: %s", error.AsCString());
- return error;
- }
-
- error = ConnectToDebugserver (connect_url);
+ error = LaunchAndConnectToDebugserver (launch_info);
}
if (error.Success())
@@ -848,10 +845,18 @@ ProcessGDBRemote::DoLaunch (Module *exe_module, const ProcessLaunchInfo &launch_
return error;
}
- if (m_gdb_comm.SendPacketAndWaitForResponse("?", 1, m_last_stop_packet, false))
+ if (m_gdb_comm.SendPacketAndWaitForResponse("?", 1, m_last_stop_packet, false) == GDBRemoteCommunication::PacketResult::Success)
{
- if (!m_target.GetArchitecture().IsValid()) { // Make sure we have an architecture
- m_target.SetArchitecture(m_gdb_comm.GetProcessArchitecture());
+ if (!m_target.GetArchitecture().IsValid())
+ {
+ if (m_gdb_comm.GetProcessArchitecture().IsValid())
+ {
+ m_target.SetArchitecture(m_gdb_comm.GetProcessArchitecture());
+ }
+ else
+ {
+ m_target.SetArchitecture(m_gdb_comm.GetHostArchitecture());
+ }
}
SetPrivateState (SetThreadStopInfo (m_last_stop_packet));
@@ -886,31 +891,35 @@ Error
ProcessGDBRemote::ConnectToDebugserver (const char *connect_url)
{
Error error;
- // Sleep and wait a bit for debugserver to start to listen...
- std::unique_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor());
- if (conn_ap.get())
+ // Only connect if we have a valid connect URL
+
+ if (connect_url && connect_url[0])
{
- const uint32_t max_retry_count = 50;
- uint32_t retry_count = 0;
- while (!m_gdb_comm.IsConnected())
+ std::unique_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor());
+ if (conn_ap.get())
{
- if (conn_ap->Connect(connect_url, &error) == eConnectionStatusSuccess)
+ const uint32_t max_retry_count = 50;
+ uint32_t retry_count = 0;
+ while (!m_gdb_comm.IsConnected())
{
- m_gdb_comm.SetConnection (conn_ap.release());
- break;
- }
- else if (error.WasInterrupted())
- {
- // If we were interrupted, don't keep retrying.
- break;
- }
-
- retry_count++;
-
- if (retry_count >= max_retry_count)
- break;
+ if (conn_ap->Connect(connect_url, &error) == eConnectionStatusSuccess)
+ {
+ m_gdb_comm.SetConnection (conn_ap.release());
+ break;
+ }
+ else if (error.WasInterrupted())
+ {
+ // If we were interrupted, don't keep retrying.
+ break;
+ }
+
+ retry_count++;
+
+ if (retry_count >= max_retry_count)
+ break;
- usleep (100000);
+ usleep (100000);
+ }
}
}
@@ -1040,12 +1049,7 @@ ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid, const Process
// Make sure we aren't already connected?
if (!m_gdb_comm.IsConnected())
{
- char host_port[128];
- snprintf (host_port, sizeof(host_port), "localhost:%u", get_random_port ());
- char connect_url[128];
- snprintf (connect_url, sizeof(connect_url), "connect://%s", host_port);
-
- error = StartDebugserverProcess (host_port, attach_info);
+ error = LaunchAndConnectToDebugserver (attach_info);
if (error.Fail())
{
@@ -1055,10 +1059,6 @@ ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid, const Process
SetExitStatus (-1, error_string);
}
- else
- {
- error = ConnectToDebugserver (connect_url);
- }
}
if (error.Success())
@@ -1072,29 +1072,8 @@ ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid, const Process
return error;
}
-size_t
-ProcessGDBRemote::AttachInputReaderCallback
-(
- void *baton,
- InputReader *reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len
-)
-{
- if (notification == eInputReaderGotToken)
- {
- ProcessGDBRemote *gdb_process = (ProcessGDBRemote *)baton;
- if (gdb_process->m_waiting_for_attach)
- gdb_process->m_waiting_for_attach = false;
- reader->SetIsDone(true);
- return 1;
- }
- return 0;
-}
-
Error
-ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait_for_launch, const ProcessAttachInfo &attach_info)
+ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, const ProcessAttachInfo &attach_info)
{
Error error;
// Clear out and clean up from any current state
@@ -1105,12 +1084,8 @@ ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait
// Make sure we aren't already connected?
if (!m_gdb_comm.IsConnected())
{
- char host_port[128];
- snprintf (host_port, sizeof(host_port), "localhost:%u", get_random_port ());
- char connect_url[128];
- snprintf (connect_url, sizeof(connect_url), "connect://%s", host_port);
+ error = LaunchAndConnectToDebugserver (attach_info);
- error = StartDebugserverProcess (host_port, attach_info);
if (error.Fail())
{
const char *error_string = error.AsCString();
@@ -1119,17 +1094,13 @@ ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait
SetExitStatus (-1, error_string);
}
- else
- {
- error = ConnectToDebugserver (connect_url);
- }
}
if (error.Success())
{
StreamString packet;
- if (wait_for_launch)
+ if (attach_info.GetWaitForLaunch())
{
if (!m_gdb_comm.GetVAttachOrWaitSupported())
{
@@ -1199,7 +1170,11 @@ ProcessGDBRemote::DoResume ()
bool continue_packet_error = false;
if (m_gdb_comm.HasAnyVContSupport ())
{
- if (m_continue_c_tids.size() == num_threads)
+ if (m_continue_c_tids.size() == num_threads ||
+ (m_continue_c_tids.empty() &&
+ m_continue_C_tids.empty() &&
+ m_continue_s_tids.empty() &&
+ m_continue_S_tids.empty()))
{
// All threads are continuing, just send a "c" packet
continue_packet.PutCString ("c");
@@ -2026,7 +2001,7 @@ ProcessGDBRemote::DoDestroy ()
bool send_async = true;
const uint32_t old_packet_timeout = m_gdb_comm.SetPacketTimeout (3);
- if (m_gdb_comm.SendPacketAndWaitForResponse("k", 1, response, send_async))
+ if (m_gdb_comm.SendPacketAndWaitForResponse("k", 1, response, send_async) == GDBRemoteCommunication::PacketResult::Success)
{
char packet_cmd = response.GetChar(0);
@@ -2128,7 +2103,7 @@ ProcessGDBRemote::DoReadMemory (addr_t addr, void *buf, size_t size, Error &erro
const int packet_len = ::snprintf (packet, sizeof(packet), "m%" PRIx64 ",%" PRIx64, (uint64_t)addr, (uint64_t)size);
assert (packet_len + 1 < (int)sizeof(packet));
StringExtractorGDBRemote response;
- if (m_gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, true))
+ if (m_gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, true) == GDBRemoteCommunication::PacketResult::Success)
{
if (response.IsNormalResponse())
{
@@ -2164,7 +2139,7 @@ ProcessGDBRemote::DoWriteMemory (addr_t addr, const void *buf, size_t size, Erro
packet.Printf("M%" PRIx64 ",%" PRIx64 ":", addr, (uint64_t)size);
packet.PutBytesAsRawHex8(buf, size, lldb::endian::InlHostByteOrder(), lldb::endian::InlHostByteOrder());
StringExtractorGDBRemote response;
- if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetData(), packet.GetSize(), response, true))
+ if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetData(), packet.GetSize(), response, true) == GDBRemoteCommunication::PacketResult::Success)
{
if (response.IsOKResponse())
{
@@ -2546,14 +2521,7 @@ ProcessGDBRemote::DoSignal (int signo)
}
Error
-ProcessGDBRemote::StartDebugserverProcess (const char *debugserver_url)
-{
- ProcessLaunchInfo launch_info;
- return StartDebugserverProcess(debugserver_url, launch_info);
-}
-
-Error
-ProcessGDBRemote::StartDebugserverProcess (const char *debugserver_url, const ProcessInfo &process_info) // The connection string to use in the spawned debugserver ("localhost:1234" or "/dev/tty...")
+ProcessGDBRemote::LaunchAndConnectToDebugserver (const ProcessInfo &process_info)
{
Error error;
if (m_debugserver_pid == LLDB_INVALID_PROCESS_ID)
@@ -2562,141 +2530,55 @@ ProcessGDBRemote::StartDebugserverProcess (const char *debugserver_url, const Pr
static FileSpec g_debugserver_file_spec;
ProcessLaunchInfo debugserver_launch_info;
- char debugserver_path[PATH_MAX];
- FileSpec &debugserver_file_spec = debugserver_launch_info.GetExecutableFile();
-
- // Always check to see if we have an environment override for the path
- // to the debugserver to use and use it if we do.
- const char *env_debugserver_path = getenv("LLDB_DEBUGSERVER_PATH");
- if (env_debugserver_path)
- debugserver_file_spec.SetFile (env_debugserver_path, false);
- else
- debugserver_file_spec = g_debugserver_file_spec;
- bool debugserver_exists = debugserver_file_spec.Exists();
- if (!debugserver_exists)
- {
- // The debugserver binary is in the LLDB.framework/Resources
- // directory.
- if (Host::GetLLDBPath (ePathTypeSupportExecutableDir, debugserver_file_spec))
- {
- debugserver_file_spec.GetFilename().SetCString(DEBUGSERVER_BASENAME);
- debugserver_exists = debugserver_file_spec.Exists();
- if (debugserver_exists)
- {
- g_debugserver_file_spec = debugserver_file_spec;
- }
- else
- {
- g_debugserver_file_spec.Clear();
- debugserver_file_spec.Clear();
- }
- }
- }
-
- if (debugserver_exists)
- {
- debugserver_file_spec.GetPath (debugserver_path, sizeof(debugserver_path));
-
- m_stdio_communication.Clear();
-
- Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
-
- Args &debugserver_args = debugserver_launch_info.GetArguments();
- char arg_cstr[PATH_MAX];
+ debugserver_launch_info.SetMonitorProcessCallback (MonitorDebugserverProcess, this, false);
+ debugserver_launch_info.SetUserID(process_info.GetUserID());
- // Start args with "debugserver /file/path -r --"
- debugserver_args.AppendArgument(debugserver_path);
- debugserver_args.AppendArgument(debugserver_url);
- // use native registers, not the GDB registers
- debugserver_args.AppendArgument("--native-regs");
- // make debugserver run in its own session so signals generated by
- // special terminal key sequences (^C) don't affect debugserver
- debugserver_args.AppendArgument("--setsid");
-
- const char *env_debugserver_log_file = getenv("LLDB_DEBUGSERVER_LOG_FILE");
- if (env_debugserver_log_file)
- {
- ::snprintf (arg_cstr, sizeof(arg_cstr), "--log-file=%s", env_debugserver_log_file);
- debugserver_args.AppendArgument(arg_cstr);
- }
-
- const char *env_debugserver_log_flags = getenv("LLDB_DEBUGSERVER_LOG_FLAGS");
- if (env_debugserver_log_flags)
- {
- ::snprintf (arg_cstr, sizeof(arg_cstr), "--log-flags=%s", env_debugserver_log_flags);
- debugserver_args.AppendArgument(arg_cstr);
- }
-// debugserver_args.AppendArgument("--log-file=/tmp/debugserver.txt");
-// debugserver_args.AppendArgument("--log-flags=0x802e0e");
-
- // We currently send down all arguments, attach pids, or attach
- // process names in dedicated GDB server packets, so we don't need
- // to pass them as arguments. This is currently because of all the
- // things we need to setup prior to launching: the environment,
- // current working dir, file actions, etc.
-#if 0
- // Now append the program arguments
- if (inferior_argv)
- {
- // Terminate the debugserver args so we can now append the inferior args
- debugserver_args.AppendArgument("--");
-
- for (int i = 0; inferior_argv[i] != NULL; ++i)
- debugserver_args.AppendArgument (inferior_argv[i]);
- }
- else if (attach_pid != LLDB_INVALID_PROCESS_ID)
- {
- ::snprintf (arg_cstr, sizeof(arg_cstr), "--attach=%u", attach_pid);
- debugserver_args.AppendArgument (arg_cstr);
- }
- else if (attach_name && attach_name[0])
- {
- if (wait_for_launch)
- debugserver_args.AppendArgument ("--waitfor");
- else
- debugserver_args.AppendArgument ("--attach");
- debugserver_args.AppendArgument (attach_name);
- }
+#if defined (__APPLE__) && defined (__arm__)
+ // On iOS, still do a local connection using a random port
+ const char *hostname = "localhost";
+ uint16_t port = get_random_port ();
+#else
+ // Set hostname being NULL to do the reverse connect where debugserver
+ // will bind to port zero and it will communicate back to us the port
+ // that we will connect to
+ const char *hostname = NULL;
+ uint16_t port = 0;
#endif
-
- ProcessLaunchInfo::FileAction file_action;
-
- // Close STDIN, STDOUT and STDERR. We might need to redirect them
- // to "/dev/null" if we run into any problems.
- file_action.Close (STDIN_FILENO);
- debugserver_launch_info.AppendFileAction (file_action);
- file_action.Close (STDOUT_FILENO);
- debugserver_launch_info.AppendFileAction (file_action);
- file_action.Close (STDERR_FILENO);
- debugserver_launch_info.AppendFileAction (file_action);
-
- if (log)
- {
- StreamString strm;
- debugserver_args.Dump (&strm);
- log->Printf("%s arguments:\n%s", debugserver_args.GetArgumentAtIndex(0), strm.GetData());
- }
- debugserver_launch_info.SetMonitorProcessCallback (MonitorDebugserverProcess, this, false);
- debugserver_launch_info.SetUserID(process_info.GetUserID());
+ error = m_gdb_comm.StartDebugserverProcess (hostname,
+ port,
+ debugserver_launch_info,
+ port);
- error = Host::LaunchProcess(debugserver_launch_info);
+ if (error.Success ())
+ m_debugserver_pid = debugserver_launch_info.GetProcessID();
+ else
+ m_debugserver_pid = LLDB_INVALID_PROCESS_ID;
- if (error.Success ())
- m_debugserver_pid = debugserver_launch_info.GetProcessID();
- else
- m_debugserver_pid = LLDB_INVALID_PROCESS_ID;
+ if (m_debugserver_pid != LLDB_INVALID_PROCESS_ID)
+ StartAsyncThread ();
+
+ if (error.Fail())
+ {
+ Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
- if (error.Fail() || log)
- error.PutToLog(log, "Host::LaunchProcess (launch_info) => pid=%" PRIu64 ", path='%s'", m_debugserver_pid, debugserver_path);
+ if (log)
+ log->Printf("failed to start debugserver process: %s", error.AsCString());
+ return error;
+ }
+
+ if (m_gdb_comm.IsConnected())
+ {
+ // Finish the connection process by doing the handshake without connecting (send NULL URL)
+ ConnectToDebugserver (NULL);
}
else
{
- error.SetErrorStringWithFormat ("unable to locate " DEBUGSERVER_BASENAME);
+ StreamString connect_url;
+ connect_url.Printf("connect://%s:%u", hostname, port);
+ error = ConnectToDebugserver (connect_url.GetString().c_str());
}
- if (m_debugserver_pid != LLDB_INVALID_PROCESS_ID)
- StartAsyncThread ();
}
return error;
}
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index 35244074bab7..9331775bb896 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -21,7 +21,6 @@
#include "lldb/Core/Broadcaster.h"
#include "lldb/Core/ConstString.h"
#include "lldb/Core/Error.h"
-#include "lldb/Core/InputReader.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/StringList.h"
#include "lldb/Core/ThreadSafeValue.h"
@@ -86,7 +85,7 @@ public:
virtual lldb_private::Error
DoLaunch (lldb_private::Module *exe_module,
- const lldb_private::ProcessLaunchInfo &launch_info);
+ lldb_private::ProcessLaunchInfo &launch_info);
virtual void
DidLaunch ();
@@ -111,7 +110,6 @@ public:
virtual lldb_private::Error
DoAttachToProcessWithName (const char *process_name,
- bool wait_for_launch,
const lldb_private::ProcessAttachInfo &attach_info);
virtual void
@@ -284,10 +282,7 @@ protected:
lldb_private::ThreadList &new_thread_list);
lldb_private::Error
- StartDebugserverProcess (const char *debugserver_url);
-
- lldb_private::Error
- StartDebugserverProcess (const char *debugserver_url, const lldb_private::ProcessInfo &process_info);
+ LaunchAndConnectToDebugserver (const lldb_private::ProcessInfo &process_info);
void
KillDebugserverProcess ();
@@ -382,13 +377,6 @@ protected:
GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr,
std::string &dispatch_queue_name);
- static size_t
- AttachInputReaderCallback (void *baton,
- lldb_private::InputReader *reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len);
-
lldb_private::DynamicLoader *
GetDynamicLoader ();
diff --git a/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
index 4e475c80bdab..fb524deda813 100644
--- a/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
@@ -19,6 +19,7 @@
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StopInfo.h"
+#include "lldb/Target/SystemRuntime.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Unwind.h"
@@ -74,10 +75,10 @@ ThreadGDBRemote::GetQueueName ()
ProcessSP process_sp (GetProcess());
if (process_sp)
{
- PlatformSP platform_sp (process_sp->GetTarget().GetPlatform());
- if (platform_sp)
+ SystemRuntime *runtime = process_sp->GetSystemRuntime ();
+ if (runtime)
{
- m_dispatch_queue_name = platform_sp->GetQueueNameForThreadQAddress (process_sp.get(), m_thread_dispatch_qaddr);
+ m_dispatch_queue_name = runtime->GetQueueNameFromThreadQAddress (m_thread_dispatch_qaddr);
}
if (m_dispatch_queue_name.length() > 0)
{
@@ -96,10 +97,10 @@ ThreadGDBRemote::GetQueueID ()
ProcessSP process_sp (GetProcess());
if (process_sp)
{
- PlatformSP platform_sp (process_sp->GetTarget().GetPlatform());
- if (platform_sp)
+ SystemRuntime *runtime = process_sp->GetSystemRuntime ();
+ if (runtime)
{
- return platform_sp->GetQueueIDForThreadQAddress (process_sp.get(), m_thread_dispatch_qaddr);
+ return runtime->GetQueueIDFromThreadQAddress (m_thread_dispatch_qaddr);
}
}
}
diff --git a/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h b/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
index fce995e4ff2e..d6c580c7ab1b 100644
--- a/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
+++ b/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
@@ -53,7 +53,7 @@ public:
bool ExtractValue(const lldb_private::DWARFDataExtractor& data,
lldb::offset_t* offset_ptr,
const DWARFCompileUnit* cu);
- bool IsInlinedCStr() const { return (m_value.data != NULL) && m_value.data == (uint8_t*)m_value.value.cstr; }
+ bool IsInlinedCStr() const { return (m_value.data != NULL) && m_value.data == (const uint8_t*)m_value.value.cstr; }
const uint8_t* BlockData() const;
uint64_t Reference(const DWARFCompileUnit* cu) const;
uint64_t Reference (dw_offset_t offset) const;
diff --git a/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 09b50531b8a9..ef03cac540c6 100644
--- a/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1644,6 +1644,13 @@ struct BitfieldInfo
{
}
+ void
+ Clear()
+ {
+ bit_size = LLDB_INVALID_ADDRESS;
+ bit_offset = LLDB_INVALID_ADDRESS;
+ }
+
bool IsValid ()
{
return (bit_size != LLDB_INVALID_ADDRESS) &&
@@ -1915,12 +1922,14 @@ SymbolFileDWARF::ParseChildMembers
accessibility = default_accessibility;
member_accessibilities.push_back(accessibility);
- BitfieldInfo this_field_info;
-
- this_field_info.bit_size = bit_size;
-
- if (member_byte_offset != UINT32_MAX || bit_size != 0)
+ uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
+ if (bit_size > 0)
{
+
+ BitfieldInfo this_field_info;
+ this_field_info.bit_offset = field_bit_offset;
+ this_field_info.bit_size = bit_size;
+
/////////////////////////////////////////////////////////////
// How to locate a field given the DWARF debug information
//
@@ -1937,10 +1946,9 @@ SymbolFileDWARF::ParseChildMembers
// AT_bit_size indicates the size of the field in bits.
/////////////////////////////////////////////////////////////
- this_field_info.bit_offset = 0;
-
- this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
-
+ if (byte_size == 0)
+ byte_size = member_type->GetByteSize();
+
if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
{
this_field_info.bit_offset += byte_size * 8;
@@ -1950,30 +1958,30 @@ SymbolFileDWARF::ParseChildMembers
{
this_field_info.bit_offset += bit_offset;
}
- }
+
+ // Update the field bit offset we will report for layout
+ field_bit_offset = this_field_info.bit_offset;
- // If the member to be emitted did not start on a character boundary and there is
- // empty space between the last field and this one, then we need to emit an
- // anonymous member filling up the space up to its start. There are three cases
- // here:
- //
- // 1 If the previous member ended on a character boundary, then we can emit an
- // anonymous member starting at the most recent character boundary.
- //
- // 2 If the previous member did not end on a character boundary and the distance
- // from the end of the previous member to the current member is less than a
- // word width, then we can emit an anonymous member starting right after the
- // previous member and right before this member.
- //
- // 3 If the previous member did not end on a character boundary and the distance
- // from the end of the previous member to the current member is greater than
- // or equal a word width, then we act as in Case 1.
-
- const uint64_t character_width = 8;
- const uint64_t word_width = 32;
-
- if (this_field_info.IsValid())
- {
+ // If the member to be emitted did not start on a character boundary and there is
+ // empty space between the last field and this one, then we need to emit an
+ // anonymous member filling up the space up to its start. There are three cases
+ // here:
+ //
+ // 1 If the previous member ended on a character boundary, then we can emit an
+ // anonymous member starting at the most recent character boundary.
+ //
+ // 2 If the previous member did not end on a character boundary and the distance
+ // from the end of the previous member to the current member is less than a
+ // word width, then we can emit an anonymous member starting right after the
+ // previous member and right before this member.
+ //
+ // 3 If the previous member did not end on a character boundary and the distance
+ // from the end of the previous member to the current member is greater than
+ // or equal a word width, then we act as in Case 1.
+
+ const uint64_t character_width = 8;
+ const uint64_t word_width = 32;
+
// Objective-C has invalid DW_AT_bit_offset values in older versions
// of clang, so we have to be careful and only insert unnammed bitfields
// if we have a new enough clang.
@@ -2019,6 +2027,11 @@ SymbolFileDWARF::ParseChildMembers
layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
}
}
+ last_field_info = this_field_info;
+ }
+ else
+ {
+ last_field_info.Clear();
}
ClangASTType member_clang_type = member_type->GetClangLayoutType();
@@ -2062,11 +2075,8 @@ SymbolFileDWARF::ParseChildMembers
GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
- if (this_field_info.IsValid())
- {
- layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset));
- last_field_info = this_field_info;
- }
+ layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
+
}
else
{
@@ -2546,6 +2556,37 @@ SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
if (!base_classes.empty())
{
+ // Make sure all base classes refer to complete types and not
+ // forward declarations. If we don't do this, clang will crash
+ // with an assertion in the call to clang_type.SetBaseClassesForClassType()
+ bool base_class_error = false;
+ for (auto &base_class : base_classes)
+ {
+ clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
+ if (type_source_info)
+ {
+ ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType());
+ if (base_class_type.GetCompleteType() == false)
+ {
+ if (!base_class_error)
+ {
+ GetObjectFile()->GetModule()->ReportError ("DWARF DIE at 0x%8.8x for class '%s' has a base class '%s' that is a forward declaration, not a complete definition.\nPlease file a bug against the compiler and include the preprocessed output for %s",
+ die->GetOffset(),
+ die->GetName(this, dwarf_cu),
+ base_class_type.GetTypeName().GetCString(),
+ sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
+ }
+ // We have no choice other than to pretend that the base class
+ // is complete. If we don't do this, clang will crash when we
+ // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
+ // below. Since we provide layout assistance, all ivars in this
+ // class and other classe will be fine, this is the best we can do
+ // short of crashing.
+ base_class_type.StartTagDeclarationDefinition ();
+ base_class_type.CompleteTagDeclarationDefinition ();
+ }
+ }
+ }
clang_type.SetBaseClassesForClassType (&base_classes.front(),
base_classes.size());
@@ -6222,6 +6263,11 @@ SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu,
case DW_TAG_subprogram:
case DW_TAG_member:
case DW_TAG_APPLE_property:
+ case DW_TAG_class_type:
+ case DW_TAG_structure_type:
+ case DW_TAG_enumeration_type:
+ case DW_TAG_typedef:
+ case DW_TAG_union_type:
child_die = NULL;
is_forward_declaration = false;
break;
diff --git a/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp b/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
index 6500aabdcea3..a9f8f36e610e 100644
--- a/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
+++ b/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
@@ -9,12 +9,8 @@
#include "SymbolVendorELF.h"
-//#include <libxml/parser.h>
-// #include <libxml/tree.h>
#include <string.h>
-// #include <AvailabilityMacros.h>
-
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
diff --git a/source/Symbol/ClangASTContext.cpp b/source/Symbol/ClangASTContext.cpp
index 5ba9c6a8d796..4f30ccfc0de5 100644
--- a/source/Symbol/ClangASTContext.cpp
+++ b/source/Symbol/ClangASTContext.cpp
@@ -1152,12 +1152,18 @@ ClangASTContext::CreateRecordType (DeclContext *decl_ctx,
// the CXXRecordDecl class since we often don't know from debug information
// if something is struct or a class, so we default to always use the more
// complete definition just in case.
+
+ bool is_anonymous = (!name) || (!name[0]);
+
CXXRecordDecl *decl = CXXRecordDecl::Create (*ast,
(TagDecl::TagKind)kind,
decl_ctx,
SourceLocation(),
SourceLocation(),
- name && name[0] ? &ast->Idents.get(name) : NULL);
+ is_anonymous ? NULL : &ast->Idents.get(name));
+
+ if (is_anonymous)
+ decl->setAnonymousStructOrUnion(true);
if (decl)
{
diff --git a/source/Symbol/ClangASTType.cpp b/source/Symbol/ClangASTType.cpp
index 0dfabcc931fb..40f6462ee360 100644
--- a/source/Symbol/ClangASTType.cpp
+++ b/source/Symbol/ClangASTType.cpp
@@ -38,6 +38,7 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Scalar.h"
#include "lldb/Core/Stream.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
@@ -413,7 +414,7 @@ ClangASTType::GetNumberOfFunctionArguments () const
QualType qual_type (GetCanonicalQualType());
const FunctionProtoType* func = dyn_cast<FunctionProtoType>(qual_type.getTypePtr());
if (func)
- return func->getNumArgs();
+ return func->getNumParams();
}
return 0;
}
@@ -427,8 +428,8 @@ ClangASTType::GetFunctionArgumentAtIndex (const size_t index)
const FunctionProtoType* func = dyn_cast<FunctionProtoType>(qual_type.getTypePtr());
if (func)
{
- if (index < func->getNumArgs())
- return ClangASTType(m_ast, func->getArgType(index).getAsOpaquePtr());
+ if (index < func->getNumParams())
+ return ClangASTType(m_ast, func->getParamType(index).getAsOpaquePtr());
}
}
return ClangASTType();
@@ -1134,7 +1135,7 @@ ClangASTType::GetTypeName () const
if (typedef_type)
{
const TypedefNameDecl *typedef_decl = typedef_type->getDecl();
- type_name = typedef_decl->getQualifiedNameAsString(printing_policy);
+ type_name = typedef_decl->getQualifiedNameAsString();
}
else
{
@@ -1595,7 +1596,7 @@ ClangASTType::GetFunctionArgumentCount () const
{
const FunctionProtoType* func = dyn_cast<FunctionProtoType>(GetCanonicalQualType());
if (func)
- return func->getNumArgs();
+ return func->getNumParams();
}
return -1;
}
@@ -1608,9 +1609,9 @@ ClangASTType::GetFunctionArgumentTypeAtIndex (size_t idx)
const FunctionProtoType* func = dyn_cast<FunctionProtoType>(GetCanonicalQualType());
if (func)
{
- const uint32_t num_args = func->getNumArgs();
+ const uint32_t num_args = func->getNumParams();
if (idx < num_args)
- return ClangASTType(m_ast, func->getArgType(idx));
+ return ClangASTType(m_ast, func->getParamType(idx));
}
}
return ClangASTType();
@@ -1624,7 +1625,7 @@ ClangASTType::GetFunctionReturnType () const
QualType qual_type(GetCanonicalQualType());
const FunctionProtoType* func = dyn_cast<FunctionProtoType>(qual_type.getTypePtr());
if (func)
- return ClangASTType(m_ast, func->getResultType());
+ return ClangASTType(m_ast, func->getReturnType());
}
return ClangASTType();
}
@@ -4647,7 +4648,7 @@ ClangASTType::AddMethodToCXXRecordType (const char *name,
if (!method_function_prototype)
return NULL;
- unsigned int num_params = method_function_prototype->getNumArgs();
+ unsigned int num_params = method_function_prototype->getNumParams();
CXXDestructorDecl *cxx_dtor_decl(NULL);
CXXConstructorDecl *cxx_ctor_decl(NULL);
@@ -4714,7 +4715,7 @@ ClangASTType::AddMethodToCXXRecordType (const char *name,
cxx_method_decl = CXXConversionDecl::Create (*m_ast,
cxx_record_decl,
SourceLocation(),
- DeclarationNameInfo (m_ast->DeclarationNames.getCXXConversionFunctionName (m_ast->getCanonicalType (function_type->getResultType())), SourceLocation()),
+ DeclarationNameInfo (m_ast->DeclarationNames.getCXXConversionFunctionName (m_ast->getCanonicalType (function_type->getReturnType())), SourceLocation()),
method_qual_type,
NULL, // TypeSourceInfo *
is_inline,
@@ -4745,7 +4746,7 @@ ClangASTType::AddMethodToCXXRecordType (const char *name,
cxx_method_decl->setVirtualAsWritten (is_virtual);
if (is_attr_used)
- cxx_method_decl->addAttr(::new (*m_ast) UsedAttr(SourceRange(), *m_ast));
+ cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*m_ast));
// Populate the method decl with parameter decls
@@ -4760,7 +4761,7 @@ ClangASTType::AddMethodToCXXRecordType (const char *name,
SourceLocation(),
SourceLocation(),
NULL, // anonymous
- method_function_prototype->getArgType(param_index),
+ method_function_prototype->getParamType(param_index),
NULL,
SC_None,
NULL));
@@ -5133,7 +5134,7 @@ ClangASTType::AddMethodToObjCObjectType (const char *name, // the full symbol n
bool is_defined = false;
ObjCMethodDecl::ImplementationControl imp_control = ObjCMethodDecl::None;
- const unsigned num_args = method_function_prototype->getNumArgs();
+ const unsigned num_args = method_function_prototype->getNumParams();
if (num_args != num_selectors_with_args)
return NULL; // some debug information is corrupt. We are not going to deal with it.
@@ -5142,7 +5143,7 @@ ClangASTType::AddMethodToObjCObjectType (const char *name, // the full symbol n
SourceLocation(), // beginLoc,
SourceLocation(), // endLoc,
method_selector,
- method_function_prototype->getResultType(),
+ method_function_prototype->getReturnType(),
NULL, // TypeSourceInfo *ResultTInfo,
GetDeclContextForType (),
name[0] == '-',
@@ -5168,7 +5169,7 @@ ClangASTType::AddMethodToObjCObjectType (const char *name, // the full symbol n
SourceLocation(),
SourceLocation(),
NULL, // anonymous
- method_function_prototype->getArgType(param_index),
+ method_function_prototype->getParamType(param_index),
NULL,
SC_Auto,
NULL));
diff --git a/source/Symbol/FuncUnwinders.cpp b/source/Symbol/FuncUnwinders.cpp
index 68b05ade4bd0..134dbf5f50db 100644
--- a/source/Symbol/FuncUnwinders.cpp
+++ b/source/Symbol/FuncUnwinders.cpp
@@ -28,7 +28,7 @@ using namespace lldb_private;
FuncUnwinders::FuncUnwinders
(
UnwindTable& unwind_table,
- UnwindAssembly *assembly_profiler,
+ const lldb::UnwindAssemblySP& assembly_profiler,
AddressRange range
) :
m_unwind_table(unwind_table),
diff --git a/source/Symbol/Function.cpp b/source/Symbol/Function.cpp
index 31334a6df8d7..e6d6c000bc97 100644
--- a/source/Symbol/Function.cpp
+++ b/source/Symbol/Function.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/Symbol/Function.h"
+#include "lldb/Core/Disassembler.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/Section.h"
#include "lldb/Host/Host.h"
@@ -404,6 +405,43 @@ Function::CalculateSymbolContextFunction ()
return this;
}
+lldb::DisassemblerSP
+Function::GetInstructions (const ExecutionContext &exe_ctx,
+ const char *flavor,
+ bool prefer_file_cache)
+{
+ ModuleSP module_sp (GetAddressRange().GetBaseAddress().GetModule());
+ if (module_sp)
+ {
+ const bool prefer_file_cache = false;
+ return Disassembler::DisassembleRange (module_sp->GetArchitecture(),
+ NULL,
+ flavor,
+ exe_ctx,
+ GetAddressRange(),
+ prefer_file_cache);
+ }
+ return lldb::DisassemblerSP();
+}
+
+bool
+Function::GetDisassembly (const ExecutionContext &exe_ctx,
+ const char *flavor,
+ bool prefer_file_cache,
+ Stream &strm)
+{
+ lldb::DisassemblerSP disassembler_sp = GetInstructions (exe_ctx, flavor, prefer_file_cache);
+ if (disassembler_sp)
+ {
+ const bool show_address = true;
+ const bool show_bytes = false;
+ disassembler_sp->GetInstructionList().Dump (&strm, show_address, show_bytes, &exe_ctx);
+ return true;
+ }
+ return false;
+}
+
+
//Symbol *
//Function::CalculateSymbolContextSymbol ()
//{
diff --git a/source/Symbol/Symbol.cpp b/source/Symbol/Symbol.cpp
index a881b6f31012..6311a329739e 100644
--- a/source/Symbol/Symbol.cpp
+++ b/source/Symbol/Symbol.cpp
@@ -580,3 +580,40 @@ Symbol::ResolveReExportedSymbol (Target &target)
}
return NULL;
}
+
+
+lldb::DisassemblerSP
+Symbol::GetInstructions (const ExecutionContext &exe_ctx,
+ const char *flavor,
+ bool prefer_file_cache)
+{
+ ModuleSP module_sp (m_addr_range.GetBaseAddress().GetModule());
+ if (module_sp)
+ {
+ const bool prefer_file_cache = false;
+ return Disassembler::DisassembleRange (module_sp->GetArchitecture(),
+ NULL,
+ flavor,
+ exe_ctx,
+ m_addr_range,
+ prefer_file_cache);
+ }
+ return lldb::DisassemblerSP();
+}
+
+bool
+Symbol::GetDisassembly (const ExecutionContext &exe_ctx,
+ const char *flavor,
+ bool prefer_file_cache,
+ Stream &strm)
+{
+ lldb::DisassemblerSP disassembler_sp = GetInstructions (exe_ctx, flavor, prefer_file_cache);
+ if (disassembler_sp)
+ {
+ const bool show_address = true;
+ const bool show_bytes = false;
+ disassembler_sp->GetInstructionList().Dump (&strm, show_address, show_bytes, &exe_ctx);
+ return true;
+ }
+ return false;
+}
diff --git a/source/Symbol/Type.cpp b/source/Symbol/Type.cpp
index 32a1d474053f..073940e8a7f7 100644
--- a/source/Symbol/Type.cpp
+++ b/source/Symbol/Type.cpp
@@ -1084,6 +1084,16 @@ TypeImpl::GetReferenceType () const
}
TypeImpl
+TypeImpl::GetTypedefedType () const
+{
+ if (m_dynamic_type.IsValid())
+ {
+ return TypeImpl(m_static_type, m_dynamic_type.GetTypedefedType());
+ }
+ return TypeImpl(m_static_type.GetTypedefedType());
+}
+
+TypeImpl
TypeImpl::GetDereferencedType () const
{
if (m_dynamic_type.IsValid())
diff --git a/source/Symbol/Variable.cpp b/source/Symbol/Variable.cpp
index 7276e0a4a1a2..36fe3b1d79d4 100644
--- a/source/Symbol/Variable.cpp
+++ b/source/Symbol/Variable.cpp
@@ -832,10 +832,17 @@ PrivateAutoComplete (StackFrame *frame,
VariableList *variable_list = frame->GetVariableList(get_file_globals);
+ if (!variable_list)
+ break;
+
const size_t num_variables = variable_list->GetSize();
for (size_t i=0; i<num_variables; ++i)
{
Variable *variable = variable_list->GetVariableAtIndex(i).get();
+
+ if (!variable)
+ continue;
+
const char *variable_name = variable->GetName().AsCString();
if (strstr(variable_name, token.c_str()) == variable_name)
{
diff --git a/source/Target/ExecutionContext.cpp b/source/Target/ExecutionContext.cpp
index 7a8b60189bc8..db4025f40c05 100644
--- a/source/Target/ExecutionContext.cpp
+++ b/source/Target/ExecutionContext.cpp
@@ -154,7 +154,7 @@ ExecutionContext::ExecutionContext (const ExecutionContextRef &exe_ctx_ref) :
{
}
-ExecutionContext::ExecutionContext (const ExecutionContextRef *exe_ctx_ref_ptr) :
+ExecutionContext::ExecutionContext (const ExecutionContextRef *exe_ctx_ref_ptr, bool thread_and_frame_only_if_stopped) :
m_target_sp (),
m_process_sp (),
m_thread_sp (),
@@ -164,8 +164,11 @@ ExecutionContext::ExecutionContext (const ExecutionContextRef *exe_ctx_ref_ptr)
{
m_target_sp = exe_ctx_ref_ptr->GetTargetSP();
m_process_sp = exe_ctx_ref_ptr->GetProcessSP();
- m_thread_sp = exe_ctx_ref_ptr->GetThreadSP();
- m_frame_sp = exe_ctx_ref_ptr->GetFrameSP();
+ if (!thread_and_frame_only_if_stopped || (m_process_sp && StateIsStoppedState(m_process_sp->GetState(), true)))
+ {
+ m_thread_sp = exe_ctx_ref_ptr->GetThreadSP();
+ m_frame_sp = exe_ctx_ref_ptr->GetFrameSP();
+ }
}
}
@@ -824,9 +827,9 @@ ExecutionContextRef::GetFrameSP () const
}
ExecutionContext
-ExecutionContextRef::Lock () const
+ExecutionContextRef::Lock (bool thread_and_frame_only_if_stopped) const
{
- return ExecutionContext(this);
+ return ExecutionContext(this, thread_and_frame_only_if_stopped);
}
diff --git a/source/Target/LanguageRuntime.cpp b/source/Target/LanguageRuntime.cpp
index 2fdc2539d08b..a2b7f1d6ae85 100644
--- a/source/Target/LanguageRuntime.cpp
+++ b/source/Target/LanguageRuntime.cpp
@@ -269,7 +269,8 @@ LanguageRuntime::CreateExceptionBreakpoint (Target &target,
BreakpointResolverSP resolver_sp(new ExceptionBreakpointResolver(language, catch_bp, throw_bp));
SearchFilterSP filter_sp(new ExceptionSearchFilter(target.shared_from_this(), language));
bool hardware = false;
- BreakpointSP exc_breakpt_sp (target.CreateBreakpoint (filter_sp, resolver_sp, is_internal, hardware));
+ bool resolve_indirect_functions = false;
+ BreakpointSP exc_breakpt_sp (target.CreateBreakpoint (filter_sp, resolver_sp, is_internal, hardware, resolve_indirect_functions));
if (is_internal)
exc_breakpt_sp->SetBreakpointKind("exception");
diff --git a/source/Target/Platform.cpp b/source/Target/Platform.cpp
index 66f9c0e552a8..d6010fb22a5b 100644
--- a/source/Target/Platform.cpp
+++ b/source/Target/Platform.cpp
@@ -81,9 +81,9 @@ Platform::SetDefaultPlatform (const lldb::PlatformSP &platform_sp)
}
Error
-Platform::GetFile (const FileSpec &platform_file,
- const UUID *uuid_ptr,
- FileSpec &local_file)
+Platform::GetFileWithUUID (const FileSpec &platform_file,
+ const UUID *uuid_ptr,
+ FileSpec &local_file)
{
// Default to the local case
local_file = platform_file;
@@ -255,7 +255,9 @@ Platform::Platform (bool is_host) :
m_rsync_prefix (),
m_supports_ssh (false),
m_ssh_opts (),
- m_ignores_remote_hostname (false)
+ m_ignores_remote_hostname (false),
+ m_trap_handlers(),
+ m_calculated_trap_handlers (false)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
if (log)
@@ -1039,6 +1041,8 @@ Platform::DebugProcess (ProcessLaunchInfo &launch_info,
process_sp = Attach (attach_info, debugger, target, listener, error);
if (process_sp)
{
+ launch_info.SetHijackListener(attach_info.GetHijackListener());
+
// Since we attached to the process, it will think it needs to detach
// if the process object just goes away without an explicit call to
// Process::Kill() or Process::Detach(), so let it know to kill the
@@ -1388,3 +1392,15 @@ Platform::GetEnvironment (StringList &environment)
environment.Clear();
return false;
}
+
+const std::vector<ConstString> &
+Platform::GetTrapHandlerSymbolNames ()
+{
+ if (!m_calculated_trap_handlers)
+ {
+ CalculateTrapHandlerSymbolNames();
+ m_calculated_trap_handlers = true;
+ }
+ return m_trap_handlers;
+}
+
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index 1de322aee148..40d3e4950c6d 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -18,14 +18,16 @@
#include "lldb/Core/Event.h"
#include "lldb/Core/ConnectionFileDescriptor.h"
#include "lldb/Core/Debugger.h"
-#include "lldb/Core/InputReader.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
+#include "lldb/Symbol/Symbol.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/State.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/Expression/ClangUserExpression.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Host/Host.h"
+#include "lldb/Host/Terminal.h"
#include "lldb/Target/ABI.h"
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/OperatingSystem.h"
@@ -41,6 +43,7 @@
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadPlan.h"
#include "lldb/Target/ThreadPlanBase.h"
+#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
#ifndef LLDB_DISABLE_POSIX
#include <spawn.h>
@@ -1025,6 +1028,8 @@ Process::Process(Target &target, Listener &listener) :
m_thread_list (this),
m_extended_thread_list (this),
m_extended_thread_stop_id (0),
+ m_queue_list (this),
+ m_queue_list_stop_id (0),
m_notifications (),
m_image_tokens (),
m_listener (listener),
@@ -1048,6 +1053,7 @@ Process::Process(Target &target, Listener &listener) :
m_currently_handling_event(false),
m_finalize_called(false),
m_clear_thread_plans_on_stop (false),
+ m_force_next_event_delivery(false),
m_last_broadcast_state (eStateInvalid),
m_destroy_in_process (false),
m_can_jit(eCanJITDontKnow)
@@ -1151,6 +1157,8 @@ Process::Finalize()
m_thread_list_real.Destroy();
m_thread_list.Destroy();
m_extended_thread_list.Destroy();
+ m_queue_list.Clear();
+ m_queue_list_stop_id = 0;
std::vector<Notifications> empty_notifications;
m_notifications.swap(empty_notifications);
m_image_tokens.clear();
@@ -1235,7 +1243,7 @@ Process::GetNextEvent (EventSP &event_sp)
StateType
-Process::WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr, bool wait_always)
+Process::WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr, bool wait_always, Listener *hijack_listener)
{
// We can't just wait for a "stopped" event, because the stopped event may have restarted the target.
// We have to actually check each event, and in the case of a stopped event check the restarted flag
@@ -1264,7 +1272,7 @@ Process::WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp
while (state != eStateInvalid)
{
EventSP event_sp;
- state = WaitForStateChangedEvents (timeout, event_sp);
+ state = WaitForStateChangedEvents (timeout, event_sp, hijack_listener);
if (event_sp_ptr && event_sp)
*event_sp_ptr = event_sp;
@@ -1274,12 +1282,22 @@ Process::WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp
case eStateDetached:
case eStateExited:
case eStateUnloaded:
+ // We need to toggle the run lock as this won't get done in
+ // SetPublicState() if the process is hijacked.
+ if (hijack_listener)
+ m_public_run_lock.SetStopped();
return state;
case eStateStopped:
if (Process::ProcessEventData::GetRestartedFromEvent(event_sp.get()))
continue;
else
+ {
+ // We need to toggle the run lock as this won't get done in
+ // SetPublicState() if the process is hijacked.
+ if (hijack_listener)
+ m_public_run_lock.SetStopped();
return state;
+ }
default:
continue;
}
@@ -1292,7 +1310,8 @@ StateType
Process::WaitForState
(
const TimeValue *timeout,
- const StateType *match_states, const uint32_t num_match_states
+ const StateType *match_states,
+ const uint32_t num_match_states
)
{
EventSP event_sp;
@@ -1305,7 +1324,7 @@ Process::WaitForState
if (state == eStateDetached || state == eStateExited)
return state;
- state = WaitForStateChangedEvents (timeout, event_sp);
+ state = WaitForStateChangedEvents (timeout, event_sp, NULL);
for (i=0; i<num_match_states; ++i)
{
@@ -1351,18 +1370,22 @@ Process::RestorePrivateProcessEvents ()
}
StateType
-Process::WaitForStateChangedEvents (const TimeValue *timeout, EventSP &event_sp)
+Process::WaitForStateChangedEvents (const TimeValue *timeout, EventSP &event_sp, Listener *hijack_listener)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
if (log)
log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout);
+ Listener *listener = hijack_listener;
+ if (listener == NULL)
+ listener = &m_listener;
+
StateType state = eStateInvalid;
- if (m_listener.WaitForEventForBroadcasterWithType (timeout,
- this,
- eBroadcastBitStateChanged | eBroadcastBitInterrupt,
- event_sp))
+ if (listener->WaitForEventForBroadcasterWithType (timeout,
+ this,
+ eBroadcastBitStateChanged | eBroadcastBitInterrupt,
+ event_sp))
{
if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged)
state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
@@ -1500,6 +1523,7 @@ Process::SetExitStatus (int status, const char *cstr)
DidExit ();
SetPrivateState (eStateExited);
+ CancelWatchForSTDIN (true);
return true;
}
@@ -1600,12 +1624,32 @@ Process::UpdateThreadListIfNeeded ()
// Clear any extended threads that we may have accumulated previously
m_extended_thread_list.Clear();
m_extended_thread_stop_id = GetLastNaturalStopID ();
+
+ m_queue_list.Clear();
+ m_queue_list_stop_id = GetLastNaturalStopID ();
}
}
}
}
}
+void
+Process::UpdateQueueListIfNeeded ()
+{
+ if (m_system_runtime_ap.get())
+ {
+ if (m_queue_list.GetSize() == 0 || m_queue_list_stop_id != GetLastNaturalStopID())
+ {
+ const StateType state = GetPrivateState();
+ if (StateIsStoppedState (state, true))
+ {
+ m_system_runtime_ap->PopulateQueueList (m_queue_list);
+ m_queue_list_stop_id = GetLastNaturalStopID();
+ }
+ }
+ }
+}
+
ThreadSP
Process::CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context)
{
@@ -2084,7 +2128,60 @@ Process::EnableBreakpointSiteByID (lldb::user_id_t break_id)
lldb::break_id_t
Process::CreateBreakpointSite (const BreakpointLocationSP &owner, bool use_hardware)
{
- const addr_t load_addr = owner->GetAddress().GetOpcodeLoadAddress (&m_target);
+ addr_t load_addr = LLDB_INVALID_ADDRESS;
+
+ bool show_error = true;
+ switch (GetState())
+ {
+ case eStateInvalid:
+ case eStateUnloaded:
+ case eStateConnected:
+ case eStateAttaching:
+ case eStateLaunching:
+ case eStateDetached:
+ case eStateExited:
+ show_error = false;
+ break;
+
+ case eStateStopped:
+ case eStateRunning:
+ case eStateStepping:
+ case eStateCrashed:
+ case eStateSuspended:
+ show_error = IsAlive();
+ break;
+ }
+
+ // Reset the IsIndirect flag here, in case the location changes from
+ // pointing to a indirect symbol to a regular symbol.
+ owner->SetIsIndirect (false);
+
+ if (owner->ShouldResolveIndirectFunctions())
+ {
+ Symbol *symbol = owner->GetAddress().CalculateSymbolContextSymbol();
+ if (symbol && symbol->IsIndirect())
+ {
+ Error error;
+ load_addr = ResolveIndirectFunction (&symbol->GetAddress(), error);
+ if (!error.Success() && show_error)
+ {
+ m_target.GetDebugger().GetErrorFile()->Printf ("warning: failed to resolve indirect function at 0x%" PRIx64 " for breakpoint %i.%i: %s\n",
+ symbol->GetAddress().GetLoadAddress(&m_target),
+ owner->GetBreakpoint().GetID(),
+ owner->GetID(),
+ error.AsCString() ? error.AsCString() : "unkown error");
+ return LLDB_INVALID_BREAK_ID;
+ }
+ Address resolved_address(load_addr);
+ load_addr = resolved_address.GetOpcodeLoadAddress (&m_target);
+ owner->SetIsIndirect(true);
+ }
+ else
+ load_addr = owner->GetAddress().GetOpcodeLoadAddress (&m_target);
+ }
+ else
+ load_addr = owner->GetAddress().GetOpcodeLoadAddress (&m_target);
+
if (load_addr != LLDB_INVALID_ADDRESS)
{
BreakpointSiteSP bp_site_sp;
@@ -2113,36 +2210,14 @@ Process::CreateBreakpointSite (const BreakpointLocationSP &owner, bool use_hardw
}
else
{
- bool show_error = true;
- switch (GetState())
- {
- case eStateInvalid:
- case eStateUnloaded:
- case eStateConnected:
- case eStateAttaching:
- case eStateLaunching:
- case eStateDetached:
- case eStateExited:
- show_error = false;
- break;
-
- case eStateStopped:
- case eStateRunning:
- case eStateStepping:
- case eStateCrashed:
- case eStateSuspended:
- show_error = IsAlive();
- break;
- }
-
if (show_error)
{
// Report error for setting breakpoint...
- m_target.GetDebugger().GetErrorFile().Printf ("warning: failed to set breakpoint site at 0x%" PRIx64 " for breakpoint %i.%i: %s\n",
- load_addr,
- owner->GetBreakpoint().GetID(),
- owner->GetID(),
- error.AsCString() ? error.AsCString() : "unkown error");
+ m_target.GetDebugger().GetErrorFile()->Printf ("warning: failed to set breakpoint site at 0x%" PRIx64 " for breakpoint %i.%i: %s\n",
+ load_addr,
+ owner->GetBreakpoint().GetID(),
+ owner->GetID(),
+ error.AsCString() ? error.AsCString() : "unkown error");
}
}
}
@@ -3153,7 +3228,7 @@ Process::Attach (ProcessAttachInfo &attach_info)
const bool restarted = false;
SetPublicState (eStateAttaching, restarted);
// Now attach using these arguments.
- error = DoAttachToProcessWithName (process_name, wait_for_launch, attach_info);
+ error = DoAttachToProcessWithName (process_name, attach_info);
}
else
{
@@ -3663,8 +3738,6 @@ Process::Destroy ()
}
m_stdio_communication.StopReadThread();
m_stdio_communication.Disconnect();
- if (m_process_input_reader && m_process_input_reader->IsActive())
- m_target.GetDebugger().PopInputReader (m_process_input_reader);
if (m_process_input_reader)
m_process_input_reader.reset();
@@ -3745,33 +3818,38 @@ Process::ShouldBroadcastEvent (Event *event_ptr)
// stopped -> running: Report except when there is one or more no votes
// and no yes votes.
SynchronouslyNotifyStateChanged (state);
- switch (m_last_broadcast_state)
+ if (m_force_next_event_delivery)
+ return_value = true;
+ else
{
- case eStateRunning:
- case eStateStepping:
- // We always suppress multiple runnings with no PUBLIC stop in between.
- return_value = false;
- break;
- default:
- // TODO: make this work correctly. For now always report
- // run if we aren't running so we don't miss any runnning
- // events. If I run the lldb/test/thread/a.out file and
- // break at main.cpp:58, run and hit the breakpoints on
- // multiple threads, then somehow during the stepping over
- // of all breakpoints no run gets reported.
-
- // This is a transition from stop to run.
- switch (m_thread_list.ShouldReportRun (event_ptr))
- {
- case eVoteYes:
- case eVoteNoOpinion:
- return_value = true;
- break;
- case eVoteNo:
- return_value = false;
- break;
- }
- break;
+ switch (m_last_broadcast_state)
+ {
+ case eStateRunning:
+ case eStateStepping:
+ // We always suppress multiple runnings with no PUBLIC stop in between.
+ return_value = false;
+ break;
+ default:
+ // TODO: make this work correctly. For now always report
+ // run if we aren't running so we don't miss any runnning
+ // events. If I run the lldb/test/thread/a.out file and
+ // break at main.cpp:58, run and hit the breakpoints on
+ // multiple threads, then somehow during the stepping over
+ // of all breakpoints no run gets reported.
+
+ // This is a transition from stop to run.
+ switch (m_thread_list.ShouldReportRun (event_ptr))
+ {
+ case eVoteYes:
+ case eVoteNoOpinion:
+ return_value = true;
+ break;
+ case eVoteNo:
+ return_value = false;
+ break;
+ }
+ break;
+ }
}
break;
case eStateStopped:
@@ -3844,6 +3922,9 @@ Process::ShouldBroadcastEvent (Event *event_ptr)
break;
}
+ // Forcing the next event delivery is a one shot deal. So reset it here.
+ m_force_next_event_delivery = false;
+
// We do some coalescing of events (for instance two consecutive running events get coalesced.)
// But we only coalesce against events we actually broadcast. So we use m_last_broadcast_state
// to track that. NB - you can't use "m_public_state.GetValue()" for that purpose, as was originally done,
@@ -4046,9 +4127,14 @@ Process::HandlePrivateEvent (EventSP &event_sp)
}
Process::ProcessEventData::SetUpdateStateOnRemoval(event_sp.get());
if (StateIsRunningState (new_state))
- PushProcessInputReader ();
+ {
+ // Only push the input handler if we aren't fowarding events,
+ // as this means the curses GUI is in use...
+ if (!GetTarget().GetDebugger().IsForwardingEvents())
+ PushProcessIOHandler ();
+ }
else if (!Process::ProcessEventData::GetRestartedFromEvent(event_sp.get()))
- PopProcessInputReader ();
+ PopProcessIOHandler ();
BroadcastEvent (event_sp);
}
@@ -4594,64 +4680,195 @@ Process::STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_
process->AppendSTDOUT (static_cast<const char *>(src), src_len);
}
-size_t
-Process::ProcessInputReaderCallback (void *baton,
- InputReader &reader,
- lldb::InputReaderAction notification,
- const char *bytes,
- size_t bytes_len)
+void
+Process::ResetProcessIOHandler ()
+{
+ m_process_input_reader.reset();
+}
+
+
+class IOHandlerProcessSTDIO :
+ public IOHandler
{
- Process *process = (Process *) baton;
-
- switch (notification)
+public:
+ IOHandlerProcessSTDIO (Process *process,
+ int write_fd) :
+ IOHandler(process->GetTarget().GetDebugger()),
+ m_process (process),
+ m_read_file (),
+ m_write_file (write_fd, false),
+ m_pipe_read(),
+ m_pipe_write()
+ {
+ m_read_file.SetDescriptor(GetInputFD(), false);
+ }
+
+ virtual
+ ~IOHandlerProcessSTDIO ()
{
- case eInputReaderActivate:
- break;
-
- case eInputReaderDeactivate:
- break;
-
- case eInputReaderReactivate:
- break;
-
- case eInputReaderAsynchronousOutputWritten:
- break;
- case eInputReaderGotToken:
+ }
+
+ bool
+ OpenPipes ()
+ {
+ if (m_pipe_read.IsValid() && m_pipe_write.IsValid())
+ return true;
+
+ int fds[2];
+#ifdef _MSC_VER
+ // pipe is not supported on windows so default to a fail condition
+ int err = 1;
+#else
+ int err = pipe(fds);
+#endif
+ if (err == 0)
{
- Error error;
- process->PutSTDIN (bytes, bytes_len, error);
+ m_pipe_read.SetDescriptor(fds[0], true);
+ m_pipe_write.SetDescriptor(fds[1], true);
+ return true;
}
- break;
+ return false;
+ }
+
+ void
+ ClosePipes()
+ {
+ m_pipe_read.Close();
+ m_pipe_write.Close();
+ }
+
+ // Each IOHandler gets to run until it is done. It should read data
+ // from the "in" and place output into "out" and "err and return
+ // when done.
+ virtual void
+ Run ()
+ {
+ if (m_read_file.IsValid() && m_write_file.IsValid())
+ {
+ SetIsDone(false);
+ if (OpenPipes())
+ {
+ const int read_fd = m_read_file.GetDescriptor();
+ const int pipe_read_fd = m_pipe_read.GetDescriptor();
+ TerminalState terminal_state;
+ terminal_state.Save (read_fd, false);
+ Terminal terminal(read_fd);
+ terminal.SetCanonical(false);
+ terminal.SetEcho(false);
+// FD_ZERO, FD_SET are not supported on windows
+#ifndef _MSC_VER
+ while (!GetIsDone())
+ {
+ fd_set read_fdset;
+ FD_ZERO (&read_fdset);
+ FD_SET (read_fd, &read_fdset);
+ FD_SET (pipe_read_fd, &read_fdset);
+ const int nfds = std::max<int>(read_fd, pipe_read_fd) + 1;
+ int num_set_fds = select (nfds, &read_fdset, NULL, NULL, NULL);
+ if (num_set_fds < 0)
+ {
+ const int select_errno = errno;
+
+ if (select_errno != EINTR)
+ SetIsDone(true);
+ }
+ else if (num_set_fds > 0)
+ {
+ char ch = 0;
+ size_t n;
+ if (FD_ISSET (read_fd, &read_fdset))
+ {
+ n = 1;
+ if (m_read_file.Read(&ch, n).Success() && n == 1)
+ {
+ if (m_write_file.Write(&ch, n).Fail() || n != 1)
+ SetIsDone(true);
+ }
+ else
+ SetIsDone(true);
+ }
+ if (FD_ISSET (pipe_read_fd, &read_fdset))
+ {
+ // Consume the interrupt byte
+ n = 1;
+ m_pipe_read.Read (&ch, n);
+ SetIsDone(true);
+ }
+ }
+ }
+#endif
+ terminal_state.Restore();
+
+ }
+ else
+ SetIsDone(true);
+ }
+ else
+ SetIsDone(true);
+ }
+
+ // Hide any characters that have been displayed so far so async
+ // output can be displayed. Refresh() will be called after the
+ // output has been displayed.
+ virtual void
+ Hide ()
+ {
- case eInputReaderInterrupt:
- process->SendAsyncInterrupt();
- break;
-
- case eInputReaderEndOfFile:
- process->AppendSTDOUT ("^D", 2);
- break;
+ }
+ // Called when the async output has been received in order to update
+ // the input reader (refresh the prompt and redisplay any current
+ // line(s) that are being edited
+ virtual void
+ Refresh ()
+ {
- case eInputReaderDone:
- break;
+ }
+ virtual void
+ Interrupt ()
+ {
+ size_t n = 1;
+ char ch = 'q';
+ m_pipe_write.Write (&ch, n);
+ }
+
+ virtual void
+ GotEOF()
+ {
}
- return bytes_len;
+protected:
+ Process *m_process;
+ File m_read_file; // Read from this file (usually actual STDIN for LLDB
+ File m_write_file; // Write to this file (usually the master pty for getting io to debuggee)
+ File m_pipe_read;
+ File m_pipe_write;
+
+};
+
+void
+Process::WatchForSTDIN (IOHandler &io_handler)
+{
}
void
-Process::ResetProcessInputReader ()
-{
- m_process_input_reader.reset();
+Process::CancelWatchForSTDIN (bool exited)
+{
+ if (m_process_input_reader)
+ {
+ if (exited)
+ m_process_input_reader->SetIsDone(true);
+ m_process_input_reader->Interrupt();
+ }
}
void
-Process::SetSTDIOFileDescriptor (int file_descriptor)
+Process::SetSTDIOFileDescriptor (int fd)
{
// First set up the Read Thread for reading/handling process I/O
- std::unique_ptr<ConnectionFileDescriptor> conn_ap (new ConnectionFileDescriptor (file_descriptor, true));
+ std::unique_ptr<ConnectionFileDescriptor> conn_ap (new ConnectionFileDescriptor (fd, true));
if (conn_ap.get())
{
@@ -4664,70 +4881,37 @@ Process::SetSTDIOFileDescriptor (int file_descriptor)
// Now read thread is set up, set up input reader.
if (!m_process_input_reader.get())
- {
- m_process_input_reader.reset (new InputReader(m_target.GetDebugger()));
- Error err (m_process_input_reader->Initialize (Process::ProcessInputReaderCallback,
- this,
- eInputReaderGranularityByte,
- NULL,
- NULL,
- false));
-
- if (err.Fail())
- m_process_input_reader.reset();
- }
+ m_process_input_reader.reset (new IOHandlerProcessSTDIO (this, fd));
}
}
}
void
-Process::PushProcessInputReader ()
+Process::PushProcessIOHandler ()
{
- if (m_process_input_reader && !m_process_input_reader->IsActive())
- m_target.GetDebugger().PushInputReader (m_process_input_reader);
+ IOHandlerSP io_handler_sp (m_process_input_reader);
+ if (io_handler_sp)
+ {
+ io_handler_sp->SetIsDone(false);
+ m_target.GetDebugger().PushIOHandler (io_handler_sp);
+ }
}
void
-Process::PopProcessInputReader ()
+Process::PopProcessIOHandler ()
{
- if (m_process_input_reader && m_process_input_reader->IsActive())
- m_target.GetDebugger().PopInputReader (m_process_input_reader);
+ IOHandlerSP io_handler_sp (m_process_input_reader);
+ if (io_handler_sp)
+ {
+ io_handler_sp->Interrupt();
+ m_target.GetDebugger().PopIOHandler (io_handler_sp);
+ }
}
// The process needs to know about installed plug-ins
void
Process::SettingsInitialize ()
{
-// static std::vector<OptionEnumValueElement> g_plugins;
-//
-// int i=0;
-// const char *name;
-// OptionEnumValueElement option_enum;
-// while ((name = PluginManager::GetProcessPluginNameAtIndex (i)) != NULL)
-// {
-// if (name)
-// {
-// option_enum.value = i;
-// option_enum.string_value = name;
-// option_enum.usage = PluginManager::GetProcessPluginDescriptionAtIndex (i);
-// g_plugins.push_back (option_enum);
-// }
-// ++i;
-// }
-// option_enum.value = 0;
-// option_enum.string_value = NULL;
-// option_enum.usage = NULL;
-// g_plugins.push_back (option_enum);
-//
-// for (i=0; (name = SettingsController::instance_settings_table[i].var_name); ++i)
-// {
-// if (::strcmp (name, "plugin") == 0)
-// {
-// SettingsController::instance_settings_table[i].enum_values = &g_plugins[0];
-// break;
-// }
-// }
-//
Thread::SettingsInitialize ();
}
@@ -4925,6 +5109,22 @@ Process::RunThreadPlan (ExecutionContext &exe_ctx,
final_timeout.OffsetWithMicroSeconds(timeout_usec);
}
+ // This isn't going to work if there are unfetched events on the queue.
+ // Are there cases where we might want to run the remaining events here, and then try to
+ // call the function? That's probably being too tricky for our own good.
+
+ Event *other_events = listener.PeekAtNextEvent();
+ if (other_events != NULL)
+ {
+ errors.Printf("Calling RunThreadPlan with pending events on the queue.");
+ return eExecutionSetupError;
+ }
+
+ // We also need to make sure that the next event is delivered. We might be calling a function as part of
+ // a thread plan, in which case the last delivered event could be the running event, and we don't want
+ // event coalescing to cause us to lose OUR running event...
+ ForceNextEventDelivery();
+
// This while loop must exit out the bottom, there's cleanup that we need to do when we are done.
// So don't call return anywhere within it.
@@ -5680,6 +5880,10 @@ void
Process::Flush ()
{
m_thread_list.Flush();
+ m_extended_thread_list.Flush();
+ m_extended_thread_stop_id = 0;
+ m_queue_list.Clear();
+ m_queue_list_stop_id = 0;
}
void
@@ -5709,3 +5913,37 @@ Process::DidExec ()
target.DidExec();
}
+addr_t
+Process::ResolveIndirectFunction(const Address *address, Error &error)
+{
+ if (address == nullptr)
+ {
+ error.SetErrorString("Invalid address argument");
+ return LLDB_INVALID_ADDRESS;
+ }
+
+ addr_t function_addr = LLDB_INVALID_ADDRESS;
+
+ addr_t addr = address->GetLoadAddress(&GetTarget());
+ std::map<addr_t,addr_t>::const_iterator iter = m_resolved_indirect_addresses.find(addr);
+ if (iter != m_resolved_indirect_addresses.end())
+ {
+ function_addr = (*iter).second;
+ }
+ else
+ {
+ if (!InferiorCall(this, address, function_addr))
+ {
+ Symbol *symbol = address->CalculateSymbolContextSymbol();
+ error.SetErrorStringWithFormat ("Unable to call resolver for indirect function %s",
+ symbol ? symbol->GetName().AsCString() : "<UNKNOWN>");
+ function_addr = LLDB_INVALID_ADDRESS;
+ }
+ else
+ {
+ m_resolved_indirect_addresses.insert(std::pair<addr_t, addr_t>(addr, function_addr));
+ }
+ }
+ return function_addr;
+}
+
diff --git a/source/Target/Queue.cpp b/source/Target/Queue.cpp
new file mode 100644
index 000000000000..2b9d2a0ed9a4
--- /dev/null
+++ b/source/Target/Queue.cpp
@@ -0,0 +1,127 @@
+//===-- Queue.cpp -----------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Queue.h"
+#include "lldb/Target/QueueList.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/SystemRuntime.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+Queue::Queue (ProcessSP process_sp, lldb::queue_id_t queue_id, const char *queue_name) :
+ m_process_wp (),
+ m_queue_id (queue_id),
+ m_queue_name (),
+ m_running_work_items_count(0),
+ m_pending_work_items_count(0),
+ m_pending_items(),
+ m_dispatch_queue_t_addr(LLDB_INVALID_ADDRESS)
+{
+ if (queue_name)
+ m_queue_name = queue_name;
+
+ m_process_wp = process_sp;
+}
+
+Queue::~Queue ()
+{
+}
+
+queue_id_t
+Queue::GetID ()
+{
+ return m_queue_id;
+}
+
+const char *
+Queue::GetName ()
+{
+ const char *result = NULL;
+ if (m_queue_name.size() > 0)
+ result = m_queue_name.c_str();
+ return result;
+}
+
+uint32_t
+Queue::GetIndexID ()
+{
+ return m_queue_id;
+}
+
+std::vector<lldb::ThreadSP>
+Queue::GetThreads ()
+{
+ std::vector<ThreadSP> result;
+ ProcessSP process_sp = m_process_wp.lock();
+ if (process_sp.get ())
+ {
+ for (ThreadSP thread_sp : process_sp->Threads())
+ {
+ if (thread_sp->GetQueueID() == m_queue_id)
+ {
+ result.push_back (thread_sp);
+ }
+ }
+ }
+ return result;
+}
+
+void
+Queue::SetNumRunningWorkItems (uint32_t count)
+{
+ m_running_work_items_count = count;
+}
+
+uint32_t
+Queue::GetNumRunningWorkItems () const
+{
+ return m_running_work_items_count;
+}
+
+
+void
+Queue::SetNumPendingWorkItems (uint32_t count)
+{
+ m_pending_work_items_count = count;
+}
+
+uint32_t
+Queue::GetNumPendingWorkItems () const
+{
+ return m_pending_work_items_count;
+}
+
+void
+Queue::SetLibdispatchQueueAddress (addr_t dispatch_queue_t_addr)
+{
+ m_dispatch_queue_t_addr = dispatch_queue_t_addr;
+}
+
+addr_t
+Queue::GetLibdispatchQueueAddress () const
+{
+ return m_dispatch_queue_t_addr;
+}
+
+
+const std::vector<lldb::QueueItemSP> &
+Queue::GetPendingItems ()
+{
+ if (m_pending_items.size() == 0)
+ {
+ ProcessSP process_sp = m_process_wp.lock();
+ if (process_sp && process_sp->GetSystemRuntime())
+ {
+ process_sp->GetSystemRuntime()->PopulatePendingItemsForQueue (this);
+ }
+ }
+ return m_pending_items;
+}
diff --git a/source/Target/QueueItem.cpp b/source/Target/QueueItem.cpp
new file mode 100644
index 000000000000..bb6762829ca6
--- /dev/null
+++ b/source/Target/QueueItem.cpp
@@ -0,0 +1,77 @@
+//===-- QueueItem.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/Queue.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/QueueItem.h"
+#include "lldb/Target/SystemRuntime.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+QueueItem::QueueItem (QueueSP queue_sp) :
+ m_queue_wp (),
+ m_kind (eQueueItemKindUnknown),
+ m_address (),
+ m_item_that_enqueued_this_ref (LLDB_INVALID_ADDRESS),
+ m_enqueueing_thread_id (LLDB_INVALID_THREAD_ID),
+ m_enqueueing_queue_id (LLDB_INVALID_QUEUE_ID),
+ m_target_queue_id (LLDB_INVALID_QUEUE_ID),
+ m_stop_id (0),
+ m_backtrace(),
+ m_thread_label(),
+ m_queue_label(),
+ m_target_queue_label()
+{
+ m_queue_wp = queue_sp;
+}
+
+QueueItem::~QueueItem ()
+{
+}
+
+QueueItemKind
+QueueItem::GetKind() const
+{
+ return m_kind;
+}
+
+void
+QueueItem::SetKind (QueueItemKind item_kind)
+{
+ m_kind = item_kind;
+}
+
+Address &
+QueueItem::GetAddress ()
+{
+ return m_address;
+}
+
+void
+QueueItem::SetAddress (Address addr)
+{
+ m_address = addr;
+}
+
+ThreadSP
+QueueItem::GetExtendedBacktraceThread (ConstString type)
+{
+ ThreadSP return_thread;
+ QueueSP queue_sp = m_queue_wp.lock();
+ if (queue_sp)
+ {
+ ProcessSP process_sp = queue_sp->GetProcess();
+ if (process_sp && process_sp->GetSystemRuntime())
+ {
+ return_thread = process_sp->GetSystemRuntime()->GetExtendedBacktraceForQueueItem (this->shared_from_this(), type);
+ }
+ }
+ return return_thread;
+}
diff --git a/source/Target/QueueList.cpp b/source/Target/QueueList.cpp
new file mode 100644
index 000000000000..6134f5cc0b21
--- /dev/null
+++ b/source/Target/QueueList.cpp
@@ -0,0 +1,102 @@
+//===-- QueueList.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Queue.h"
+#include "lldb/Target/QueueList.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+QueueList::QueueList (Process *process) :
+ m_process (process),
+ m_stop_id (0),
+ m_queues (),
+ m_mutex ()
+{
+}
+
+QueueList::~QueueList ()
+{
+ Clear();
+}
+
+uint32_t
+QueueList::GetSize ()
+{
+ Mutex::Locker locker (m_mutex);
+ return m_queues.size();
+}
+
+lldb::QueueSP
+QueueList::GetQueueAtIndex (uint32_t idx)
+{
+ Mutex::Locker locker (m_mutex);
+ if (idx < m_queues.size())
+ {
+ return m_queues[idx];
+ }
+ else
+ {
+ return QueueSP();
+ }
+}
+
+void
+QueueList::Clear ()
+{
+ Mutex::Locker locker (m_mutex);
+ m_queues.clear();
+}
+
+void
+QueueList::AddQueue (QueueSP queue_sp)
+{
+ Mutex::Locker locker (m_mutex);
+ if (queue_sp.get ())
+ {
+ m_queues.push_back (queue_sp);
+ }
+}
+
+lldb::QueueSP
+QueueList::FindQueueByID (lldb::queue_id_t qid)
+{
+ QueueSP ret;
+ for (QueueSP queue_sp : Queues())
+ {
+ if (queue_sp->GetID() == qid)
+ {
+ ret = queue_sp;
+ break;
+ }
+ }
+ return ret;
+}
+
+lldb::QueueSP
+QueueList::FindQueueByIndexID (uint32_t index_id)
+{
+ QueueSP ret;
+ for (QueueSP queue_sp : Queues())
+ {
+ if (queue_sp->GetIndexID() == index_id)
+ {
+ ret = queue_sp;
+ break;
+ }
+ }
+ return ret;
+}
+
+lldb_private::Mutex &
+QueueList::GetMutex ()
+{
+ return m_mutex;
+}
diff --git a/source/Target/SectionLoadHistory.cpp b/source/Target/SectionLoadHistory.cpp
new file mode 100644
index 000000000000..527168ce42af
--- /dev/null
+++ b/source/Target/SectionLoadHistory.cpp
@@ -0,0 +1,182 @@
+//===-- SectionLoadHistory.cpp ----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/SectionLoadHistory.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Stream.h"
+#include "lldb/Target/SectionLoadList.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+
+bool
+SectionLoadHistory::IsEmpty() const
+{
+ Mutex::Locker locker(m_mutex);
+ return m_stop_id_to_section_load_list.empty();
+}
+
+void
+SectionLoadHistory::Clear ()
+{
+ Mutex::Locker locker(m_mutex);
+ m_stop_id_to_section_load_list.clear();
+}
+
+uint32_t
+SectionLoadHistory::GetLastStopID() const
+{
+ Mutex::Locker locker(m_mutex);
+ if (m_stop_id_to_section_load_list.empty())
+ return 0;
+ else
+ return m_stop_id_to_section_load_list.rbegin()->first;
+}
+
+SectionLoadList *
+SectionLoadHistory::GetSectionLoadListForStopID (uint32_t stop_id, bool read_only)
+{
+ if (m_stop_id_to_section_load_list.empty())
+ {
+ SectionLoadListSP section_load_list_sp(new SectionLoadList());
+ if (stop_id == eStopIDNow)
+ stop_id = 0;
+ m_stop_id_to_section_load_list[stop_id] = section_load_list_sp;
+ return section_load_list_sp.get();
+ }
+ else
+ {
+ if (read_only)
+ {
+ // The section load list is for reading data only so we don't need to create
+ // a new SectionLoadList for the current stop ID, just return the section
+ // load list for the stop ID that is equal to or less than the current stop ID
+ if (stop_id == eStopIDNow)
+ {
+ // If we are asking for the latest and greatest value, it is always
+ // at the end of our list becuase that will be the highest stop ID.
+ StopIDToSectionLoadList::reverse_iterator rpos = m_stop_id_to_section_load_list.rbegin();
+ return rpos->second.get();
+ }
+ else
+ {
+ StopIDToSectionLoadList::iterator pos = m_stop_id_to_section_load_list.lower_bound(stop_id);
+ if (pos != m_stop_id_to_section_load_list.end() && pos->first == stop_id)
+ return pos->second.get();
+ else if (pos != m_stop_id_to_section_load_list.begin())
+ {
+ --pos;
+ return pos->second.get();
+ }
+ }
+ }
+ else
+ {
+ // You can only use "eStopIDNow" when reading from the section load history
+ assert(stop_id != eStopIDNow);
+
+ // We are updating the section load list (not read only), so if the stop ID
+ // passed in isn't the same as the last stop ID in our collection, then create
+ // a new node using the current stop ID
+ StopIDToSectionLoadList::iterator pos = m_stop_id_to_section_load_list.lower_bound(stop_id);
+ if (pos != m_stop_id_to_section_load_list.end() && pos->first == stop_id)
+ {
+ // We already have an entry for this value
+ return pos->second.get();
+ }
+
+ // We must make a new section load list that is based on the last valid
+ // section load list, so here we copy the last section load list and add
+ // a new node for the current stop ID.
+ StopIDToSectionLoadList::reverse_iterator rpos = m_stop_id_to_section_load_list.rbegin();
+ SectionLoadListSP section_load_list_sp(new SectionLoadList(*rpos->second.get()));
+ m_stop_id_to_section_load_list[stop_id] = section_load_list_sp;
+ return section_load_list_sp.get();
+ }
+ }
+ return NULL;
+}
+
+SectionLoadList &
+SectionLoadHistory::GetCurrentSectionLoadList ()
+{
+ const bool read_only = true;
+ SectionLoadList *section_load_list = GetSectionLoadListForStopID (eStopIDNow, read_only);
+ assert(section_load_list != NULL);
+ return *section_load_list;
+}
+
+addr_t
+SectionLoadHistory::GetSectionLoadAddress (uint32_t stop_id, const lldb::SectionSP &section_sp)
+{
+ Mutex::Locker locker(m_mutex);
+ const bool read_only = true;
+ SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only);
+ return section_load_list->GetSectionLoadAddress(section_sp);
+}
+
+bool
+SectionLoadHistory::ResolveLoadAddress (uint32_t stop_id, addr_t load_addr, Address &so_addr)
+{
+ // First find the top level section that this load address exists in
+ Mutex::Locker locker(m_mutex);
+ const bool read_only = true;
+ SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only);
+ return section_load_list->ResolveLoadAddress (load_addr, so_addr);
+}
+
+bool
+SectionLoadHistory::SetSectionLoadAddress (uint32_t stop_id,
+ const lldb::SectionSP &section_sp,
+ addr_t load_addr,
+ bool warn_multiple)
+{
+ Mutex::Locker locker(m_mutex);
+ const bool read_only = false;
+ SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only);
+ return section_load_list->SetSectionLoadAddress(section_sp, load_addr, warn_multiple);
+}
+
+size_t
+SectionLoadHistory::SetSectionUnloaded (uint32_t stop_id, const lldb::SectionSP &section_sp)
+{
+ Mutex::Locker locker(m_mutex);
+ const bool read_only = false;
+ SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only);
+ return section_load_list->SetSectionUnloaded (section_sp);
+}
+
+bool
+SectionLoadHistory::SetSectionUnloaded (uint32_t stop_id, const lldb::SectionSP &section_sp, addr_t load_addr)
+{
+ Mutex::Locker locker(m_mutex);
+ const bool read_only = false;
+ SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only);
+ return section_load_list->SetSectionUnloaded (section_sp, load_addr);
+}
+
+void
+SectionLoadHistory::Dump (Stream &s, Target *target)
+{
+ Mutex::Locker locker(m_mutex);
+ StopIDToSectionLoadList::iterator pos, end = m_stop_id_to_section_load_list.end();
+ for (pos = m_stop_id_to_section_load_list.begin(); pos != end; ++pos)
+ {
+ s.Printf("StopID = %u:\n", pos->first);
+ pos->second->Dump(s, target);
+ s.EOL();
+ }
+}
+
+
diff --git a/source/Target/SectionLoadList.cpp b/source/Target/SectionLoadList.cpp
index 96713c6ea797..82f52f9db1b5 100644
--- a/source/Target/SectionLoadList.cpp
+++ b/source/Target/SectionLoadList.cpp
@@ -25,6 +25,25 @@ using namespace lldb;
using namespace lldb_private;
+SectionLoadList::SectionLoadList (const SectionLoadList& rhs) :
+ m_addr_to_sect(),
+ m_sect_to_addr(),
+ m_mutex (Mutex::eMutexTypeRecursive)
+{
+ Mutex::Locker locker(rhs.m_mutex);
+ m_addr_to_sect = rhs.m_addr_to_sect;
+ m_sect_to_addr = rhs.m_sect_to_addr;
+}
+
+void
+SectionLoadList::operator=(const SectionLoadList &rhs)
+{
+ Mutex::Locker lhs_locker (m_mutex);
+ Mutex::Locker rhs_locker (rhs.m_mutex);
+ m_addr_to_sect = rhs.m_addr_to_sect;
+ m_sect_to_addr = rhs.m_sect_to_addr;
+}
+
bool
SectionLoadList::IsEmpty() const
{
diff --git a/source/Target/StopInfo.cpp b/source/Target/StopInfo.cpp
index 914969a633e6..3664e8f0c738 100644
--- a/source/Target/StopInfo.cpp
+++ b/source/Target/StopInfo.cpp
@@ -419,8 +419,15 @@ protected:
// The breakpoint site may have many locations associated with it, not all of them valid for
// this thread. Skip the ones that aren't:
if (!bp_loc_sp->ValidForThisThread(thread_sp.get()))
+ {
+ if (log)
+ {
+ StreamString s;
+ bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief);
+ log->Printf ("Breakpoint %s hit on thread 0x%llx but it was not for this thread, continuing.", s.GetData(), thread_sp->GetID());
+ }
continue;
-
+ }
// First run the condition for the breakpoint. If that says we should stop, then we'll run
// the callback for the breakpoint. If the callback says we shouldn't stop that will win.
@@ -450,6 +457,12 @@ protected:
}
else
{
+ if (log)
+ {
+ StreamString s;
+ bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief);
+ log->Printf ("Condition evaluated for breakpoint %s on thread 0x%llx conditon_says_stop: %i.", s.GetData(), thread_sp->GetID(), condition_says_stop);
+ }
if (!condition_says_stop)
continue;
}
diff --git a/source/Target/SystemRuntime.cpp b/source/Target/SystemRuntime.cpp
index 5c07ed388ae4..c3fb9c8091fd 100644
--- a/source/Target/SystemRuntime.cpp
+++ b/source/Target/SystemRuntime.cpp
@@ -56,6 +56,11 @@ SystemRuntime::DidLaunch()
}
void
+SystemRuntime::Detach()
+{
+}
+
+void
SystemRuntime::ModulesDidLoad (ModuleList &module_list)
{
}
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index fd9626a5de8d..e7816266b415 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -28,6 +28,8 @@
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/SourceManager.h"
+#include "lldb/Core/State.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Timer.h"
#include "lldb/Core/ValueObject.h"
@@ -42,6 +44,7 @@
#include "lldb/lldb-private-log.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/SystemRuntime.h"
#include "lldb/Target/Thread.h"
@@ -69,12 +72,11 @@ Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::Plat
m_mutex (Mutex::eMutexTypeRecursive),
m_arch (target_arch),
m_images (this),
- m_section_load_list (),
+ m_section_load_history (),
m_breakpoint_list (false),
m_internal_breakpoint_list (true),
m_watchpoint_list (),
m_process_sp (),
- m_valid (true),
m_search_filter_sp (),
m_image_search_paths (ImageSearchPathsChanged, this),
m_scratch_ast_context_ap (),
@@ -84,6 +86,7 @@ Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::Plat
m_source_manager_ap(),
m_stop_hooks (),
m_stop_hook_next_id (0),
+ m_valid (true),
m_suppress_stop_hooks (false)
{
SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
@@ -158,7 +161,7 @@ Target::DeleteCurrentProcess ()
{
if (m_process_sp.get())
{
- m_section_load_list.Clear();
+ m_section_load_history.Clear();
if (m_process_sp->IsAlive())
m_process_sp->Destroy();
@@ -193,7 +196,7 @@ Target::Destroy()
m_platform_sp.reset();
m_arch.Clear();
ClearModules(true);
- m_section_load_list.Clear();
+ m_section_load_history.Clear();
const bool notify = false;
m_breakpoint_list.RemoveAll(notify);
m_internal_breakpoint_list.RemoveAll(notify);
@@ -248,7 +251,7 @@ Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
{
SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
- return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware);
+ return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
}
@@ -302,7 +305,7 @@ Target::CreateBreakpoint (const FileSpecList *containingModules,
line_no,
check_inlines,
skip_prologue));
- return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware);
+ return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
}
@@ -314,7 +317,7 @@ Target::CreateBreakpoint (lldb::addr_t addr, bool internal, bool hardware)
// it doesn't resolve to section/offset.
// Try and resolve as a load address if possible
- m_section_load_list.ResolveLoadAddress(addr, so_addr);
+ GetSectionLoadList().ResolveLoadAddress(addr, so_addr);
if (!so_addr.IsValid())
{
// The address didn't resolve, so just set this as an absolute address
@@ -329,7 +332,7 @@ Target::CreateBreakpoint (Address &addr, bool internal, bool hardware)
{
SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
- return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware);
+ return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, false);
}
BreakpointSP
@@ -354,7 +357,7 @@ Target::CreateBreakpoint (const FileSpecList *containingModules,
func_name_type_mask,
Breakpoint::Exact,
skip_prologue));
- bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware);
+ bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
}
return bp_sp;
}
@@ -381,7 +384,7 @@ Target::CreateBreakpoint (const FileSpecList *containingModules,
func_names,
func_name_type_mask,
skip_prologue));
- bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware);
+ bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
}
return bp_sp;
}
@@ -409,7 +412,7 @@ Target::CreateBreakpoint (const FileSpecList *containingModules,
num_names,
func_name_type_mask,
skip_prologue));
- bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware);
+ bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
}
return bp_sp;
}
@@ -487,7 +490,7 @@ Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
func_regex,
skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
- return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware);
+ return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true);
}
lldb::BreakpointSP
@@ -497,12 +500,12 @@ Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_
}
BreakpointSP
-Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal, bool request_hardware)
+Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal, bool request_hardware, bool resolve_indirect_symbols)
{
BreakpointSP bp_sp;
if (filter_sp && resolver_sp)
{
- bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp, request_hardware));
+ bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp, request_hardware, resolve_indirect_symbols));
resolver_sp->SetBreakpoint (bp_sp.get());
if (internal)
@@ -1004,11 +1007,11 @@ LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target)
if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error, &feedback_stream))
{
if (error.AsCString())
- target->GetDebugger().GetErrorStream().Printf("unable to load scripting data for module %s - error reported was %s\n",
+ target->GetDebugger().GetErrorFile()->Printf("unable to load scripting data for module %s - error reported was %s\n",
module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
error.AsCString());
if (feedback_stream.GetSize())
- target->GetDebugger().GetOutputStream().Printf("%s\n",
+ target->GetDebugger().GetErrorFile()->Printf("%s\n",
feedback_stream.GetData());
}
}
@@ -1017,7 +1020,7 @@ void
Target::ClearModules(bool delete_locations)
{
ModulesDidUnload (m_images, delete_locations);
- GetSectionLoadList().Clear();
+ m_section_load_history.Clear();
m_images.Clear();
m_scratch_ast_context_ap.reset();
m_scratch_ast_source_ap.reset();
@@ -1065,7 +1068,7 @@ Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
FileSpec platform_dependent_file_spec;
if (m_platform_sp)
- m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
+ m_platform_sp->GetFileWithUUID (dependent_file_spec, NULL, platform_dependent_file_spec);
else
platform_dependent_file_spec = dependent_file_spec;
@@ -1307,7 +1310,8 @@ Target::ReadMemory (const Address& addr,
Address resolved_addr;
if (!addr.IsSectionOffset())
{
- if (m_section_load_list.IsEmpty())
+ SectionLoadList &section_load_list = GetSectionLoadList();
+ if (section_load_list.IsEmpty())
{
// No sections are loaded, so we must assume we are not running
// yet and anything we are given is a file address.
@@ -1321,7 +1325,7 @@ Target::ReadMemory (const Address& addr,
// or because we have have a live process that has sections loaded
// through the dynamic loader
load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
- m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
+ section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
}
}
if (!resolved_addr.IsValid())
@@ -1534,7 +1538,8 @@ Target::ReadPointerFromMemory (const Address& addr,
addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
{
- if (m_section_load_list.IsEmpty())
+ SectionLoadList &section_load_list = GetSectionLoadList();
+ if (section_load_list.IsEmpty())
{
// No sections are loaded, so we must assume we are not running
// yet and anything we are given is a file address.
@@ -1546,7 +1551,7 @@ Target::ReadPointerFromMemory (const Address& addr,
// we have manually loaded some sections with "target modules load ..."
// or because we have have a live process that has sections loaded
// through the dynamic loader
- m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
+ section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
}
// We weren't able to resolve the pointer value, so just return
// an address with no section
@@ -1994,13 +1999,13 @@ Target::GetSourceManager ()
}
-lldb::user_id_t
-Target::AddStopHook (Target::StopHookSP &new_hook_sp)
+Target::StopHookSP
+Target::CreateStopHook ()
{
lldb::user_id_t new_uid = ++m_stop_hook_next_id;
- new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
- m_stop_hooks[new_uid] = new_hook_sp;
- return new_uid;
+ Target::StopHookSP stop_hook_sp (new StopHook(shared_from_this(), new_uid));
+ m_stop_hooks[new_uid] = stop_hook_sp;
+ return stop_hook_sp;
}
bool
@@ -2259,6 +2264,186 @@ Target::Install (ProcessLaunchInfo *launch_info)
return error;
}
+bool
+Target::ResolveLoadAddress (addr_t load_addr, Address &so_addr, uint32_t stop_id)
+{
+ return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr);
+}
+
+bool
+Target::SetSectionLoadAddress (const SectionSP &section_sp, addr_t new_section_load_addr, bool warn_multiple)
+{
+ const addr_t old_section_load_addr = m_section_load_history.GetSectionLoadAddress (SectionLoadHistory::eStopIDNow, section_sp);
+ if (old_section_load_addr != new_section_load_addr)
+ {
+ uint32_t stop_id = 0;
+ ProcessSP process_sp(GetProcessSP());
+ if (process_sp)
+ stop_id = process_sp->GetStopID();
+ else
+ stop_id = m_section_load_history.GetLastStopID();
+ if (m_section_load_history.SetSectionLoadAddress (stop_id, section_sp, new_section_load_addr, warn_multiple))
+ return true; // Return true if the section load address was changed...
+ }
+ return false; // Return false to indicate nothing changed
+
+}
+
+bool
+Target::SetSectionUnloaded (const lldb::SectionSP &section_sp)
+{
+ uint32_t stop_id = 0;
+ ProcessSP process_sp(GetProcessSP());
+ if (process_sp)
+ stop_id = process_sp->GetStopID();
+ else
+ stop_id = m_section_load_history.GetLastStopID();
+ return m_section_load_history.SetSectionUnloaded (stop_id, section_sp);
+}
+
+bool
+Target::SetSectionUnloaded (const lldb::SectionSP &section_sp, addr_t load_addr)
+{
+ uint32_t stop_id = 0;
+ ProcessSP process_sp(GetProcessSP());
+ if (process_sp)
+ stop_id = process_sp->GetStopID();
+ else
+ stop_id = m_section_load_history.GetLastStopID();
+ return m_section_load_history.SetSectionUnloaded (stop_id, section_sp, load_addr);
+}
+
+void
+Target::ClearAllLoadedSections ()
+{
+ m_section_load_history.Clear();
+}
+
+
+Error
+Target::Launch (Listener &listener, ProcessLaunchInfo &launch_info)
+{
+ Error error;
+
+ StateType state = eStateInvalid;
+
+ // Scope to temporarily get the process state in case someone has manually
+ // remotely connected already to a process and we can skip the platform
+ // launching.
+ {
+ ProcessSP process_sp (GetProcessSP());
+
+ if (process_sp)
+ state = process_sp->GetState();
+ }
+
+ launch_info.GetFlags().Set (eLaunchFlagDebug);
+
+ // Get the value of synchronous execution here. If you wait till after you have started to
+ // run, then you could have hit a breakpoint, whose command might switch the value, and
+ // then you'll pick up that incorrect value.
+ Debugger &debugger = GetDebugger();
+ const bool synchronous_execution = debugger.GetCommandInterpreter().GetSynchronous ();
+
+ PlatformSP platform_sp (GetPlatform());
+
+ // Finalize the file actions, and if none were given, default to opening
+ // up a pseudo terminal
+ const bool default_to_use_pty = platform_sp ? platform_sp->IsHost() : false;
+ launch_info.FinalizeFileActions (this, default_to_use_pty);
+
+ if (state == eStateConnected)
+ {
+ if (launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY))
+ {
+ error.SetErrorString("can't launch in tty when launching through a remote connection");
+ return error;
+ }
+ }
+
+ if (!launch_info.GetArchitecture().IsValid())
+ launch_info.GetArchitecture() = GetArchitecture();
+
+ if (state != eStateConnected && platform_sp && platform_sp->CanDebugProcess ())
+ {
+ m_process_sp = GetPlatform()->DebugProcess (launch_info,
+ debugger,
+ this,
+ listener,
+ error);
+ }
+ else
+ {
+ if (state == eStateConnected)
+ {
+ assert(m_process_sp);
+ }
+ else
+ {
+ const char *plugin_name = launch_info.GetProcessPluginName();
+ CreateProcess (listener, plugin_name, NULL);
+ }
+
+ if (m_process_sp)
+ error = m_process_sp->Launch (launch_info);
+ }
+
+ if (!m_process_sp)
+ {
+ if (error.Success())
+ error.SetErrorString("failed to launch or debug process");
+ return error;
+ }
+
+ if (error.Success())
+ {
+ if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry) == false)
+ {
+ ListenerSP hijack_listener_sp (launch_info.GetHijackListener());
+
+ StateType state = m_process_sp->WaitForProcessToStop (NULL, NULL, false, hijack_listener_sp.get());
+
+ if (state == eStateStopped)
+ {
+ if (!synchronous_execution)
+ m_process_sp->RestoreProcessEvents ();
+
+ error = m_process_sp->PrivateResume();
+
+ if (error.Success())
+ {
+ if (synchronous_execution)
+ {
+ state = m_process_sp->WaitForProcessToStop (NULL, NULL, true, hijack_listener_sp.get());
+ const bool must_be_alive = false; // eStateExited is ok, so this must be false
+ if (!StateIsStoppedState(state, must_be_alive))
+ {
+ error.SetErrorStringWithFormat("process isn't stopped: %s", StateAsCString(state));
+ }
+ }
+ }
+ else
+ {
+ Error error2;
+ error2.SetErrorStringWithFormat("process resume at entry point failed: %s", error.AsCString());
+ error = error2;
+ }
+ }
+ else
+ {
+ error.SetErrorStringWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state));
+ }
+ }
+ m_process_sp->RestoreProcessEvents ();
+ }
+ else
+ {
+ Error error2;
+ error2.SetErrorStringWithFormat ("process launch failed: %s", error.AsCString());
+ error = error2;
+ }
+ return error;
+}
//--------------------------------------------------------------
// Target::StopHook
//--------------------------------------------------------------
@@ -2452,6 +2637,8 @@ g_properties[] =
"'complete' is the default value for this setting which will load all sections and symbols by reading them from memory (slowest, most accurate). "
"'partial' will load sections and attempt to find function bounds without downloading the symbol table (faster, still accurate, missing symbol names). "
"'minimal' is the fastest setting and will load section data with no symbols, but should rarely be used as stack frames in these memory regions will be inaccurate and not provide any context (fastest). " },
+ { "display-expression-in-crashlogs" , OptionValue::eTypeBoolean , false, false, NULL, NULL, "Expressions that crash will show up in crash logs if the host system supports executable specific crash log strings and this setting is set to true." },
+ { "trap-handler-names" , OptionValue::eTypeArray , true, OptionValue::eTypeString, NULL, NULL, "A list of trap handler function names, e.g. a common Unix user process one is _sigtramp." },
{ NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL }
};
enum
@@ -2483,7 +2670,9 @@ enum
ePropertyHexImmediateStyle,
ePropertyUseFastStepping,
ePropertyLoadScriptFromSymbolFile,
- ePropertyMemoryModuleLoadLevel
+ ePropertyMemoryModuleLoadLevel,
+ ePropertyDisplayExpressionsInCrashlogs,
+ ePropertyTrapHandlerNames
};
@@ -2862,6 +3051,13 @@ TargetProperties::GetUseFastStepping () const
return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
}
+bool
+TargetProperties::GetDisplayExpressionsInCrashlogs () const
+{
+ const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs;
+ return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
+}
+
LoadScriptFromSymFile
TargetProperties::GetLoadScriptFromSymbolFile () const
{
@@ -2883,7 +3079,19 @@ TargetProperties::GetMemoryModuleLoadLevel() const
return (MemoryModuleLoadLevel)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value);
}
+bool
+TargetProperties::GetUserSpecifiedTrapHandlerNames (Args &args) const
+{
+ const uint32_t idx = ePropertyTrapHandlerNames;
+ return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
+}
+void
+TargetProperties::SetUserSpecifiedTrapHandlerNames (const Args &args)
+{
+ const uint32_t idx = ePropertyTrapHandlerNames;
+ m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
+}
//----------------------------------------------------------------------
// Target::TargetEventData
diff --git a/source/Target/Thread.cpp b/source/Target/Thread.cpp
index 07f5321990b2..72de5b8a3cf5 100644
--- a/source/Target/Thread.cpp
+++ b/source/Target/Thread.cpp
@@ -18,6 +18,7 @@
#include "lldb/Core/StreamString.h"
#include "lldb/Core/RegularExpression.h"
#include "lldb/Host/Host.h"
+#include "lldb/Interpreter/OptionValueFileSpecList.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/ExecutionContext.h"
@@ -61,12 +62,14 @@ static PropertyDefinition
g_properties[] =
{
{ "step-avoid-regexp", OptionValue::eTypeRegex , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." },
+ { "step-avoid-libraries", OptionValue::eTypeFileSpecList , true , REG_EXTENDED, NULL, NULL, "A list of libraries that source stepping won't stop in." },
{ "trace-thread", OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." },
{ NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL }
};
enum {
ePropertyStepAvoidRegex,
+ ePropertyStepAvoidLibraries,
ePropertyEnableThreadTrace
};
@@ -132,6 +135,15 @@ ThreadProperties::GetSymbolsToAvoidRegexp()
return m_collection_sp->GetPropertyAtIndexAsOptionValueRegex (NULL, idx);
}
+FileSpecList &
+ThreadProperties::GetLibrariesToAvoid() const
+{
+ const uint32_t idx = ePropertyStepAvoidLibraries;
+ OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
+ assert(option_value);
+ return option_value->GetCurrentValue();
+}
+
bool
ThreadProperties::GetTraceEnabledState() const
{
@@ -2053,3 +2065,125 @@ Thread::IsStillAtLastBreakpointHit ()
}
return false;
}
+
+
+Error
+Thread::StepIn (bool source_step,
+ bool avoid_code_without_debug_info)
+
+{
+ Error error;
+ Process *process = GetProcess().get();
+ if (StateIsStoppedState (process->GetState(), true))
+ {
+ StackFrameSP frame_sp = GetStackFrameAtIndex (0);
+ ThreadPlanSP new_plan_sp;
+ const lldb::RunMode run_mode = eOnlyThisThread;
+ const bool abort_other_plans = false;
+
+ if (source_step && frame_sp && frame_sp->HasDebugInformation ())
+ {
+ SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
+ new_plan_sp = QueueThreadPlanForStepInRange (abort_other_plans,
+ sc.line_entry.range,
+ sc,
+ NULL,
+ run_mode,
+ avoid_code_without_debug_info);
+ }
+ else
+ {
+ new_plan_sp = QueueThreadPlanForStepSingleInstruction (false,
+ abort_other_plans,
+ run_mode);
+ }
+
+ new_plan_sp->SetIsMasterPlan(true);
+ new_plan_sp->SetOkayToDiscard(false);
+
+ // Why do we need to set the current thread by ID here???
+ process->GetThreadList().SetSelectedThreadByID (GetID());
+ error = process->Resume();
+ }
+ else
+ {
+ error.SetErrorString("process not stopped");
+ }
+ return error;
+}
+
+Error
+Thread::StepOver (bool source_step)
+
+{
+ Error error;
+ Process *process = GetProcess().get();
+ if (StateIsStoppedState (process->GetState(), true))
+ {
+ StackFrameSP frame_sp = GetStackFrameAtIndex (0);
+ ThreadPlanSP new_plan_sp;
+
+ const lldb::RunMode run_mode = eOnlyThisThread;
+ const bool abort_other_plans = false;
+
+ if (source_step && frame_sp && frame_sp->HasDebugInformation ())
+ {
+ SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
+ new_plan_sp = QueueThreadPlanForStepOverRange (abort_other_plans,
+ sc.line_entry.range,
+ sc,
+ run_mode);
+ }
+ else
+ {
+ new_plan_sp = QueueThreadPlanForStepSingleInstruction (true,
+ abort_other_plans,
+ run_mode);
+ }
+
+ new_plan_sp->SetIsMasterPlan(true);
+ new_plan_sp->SetOkayToDiscard(false);
+
+ // Why do we need to set the current thread by ID here???
+ process->GetThreadList().SetSelectedThreadByID (GetID());
+ error = process->Resume();
+ }
+ else
+ {
+ error.SetErrorString("process not stopped");
+ }
+ return error;
+}
+
+Error
+Thread::StepOut ()
+{
+ Error error;
+ Process *process = GetProcess().get();
+ if (StateIsStoppedState (process->GetState(), true))
+ {
+ const bool first_instruction = false;
+ const bool stop_other_threads = false;
+ const bool abort_other_plans = false;
+
+ ThreadPlanSP new_plan_sp(QueueThreadPlanForStepOut (abort_other_plans,
+ NULL,
+ first_instruction,
+ stop_other_threads,
+ eVoteYes,
+ eVoteNoOpinion,
+ 0));
+
+ new_plan_sp->SetIsMasterPlan(true);
+ new_plan_sp->SetOkayToDiscard(false);
+
+ // Why do we need to set the current thread by ID here???
+ process->GetThreadList().SetSelectedThreadByID (GetID());
+ error = process->Resume();
+ }
+ else
+ {
+ error.SetErrorString("process not stopped");
+ }
+ return error;
+} \ No newline at end of file
diff --git a/source/Target/ThreadList.cpp b/source/Target/ThreadList.cpp
index 1f8b351100a6..4fffdac9a34e 100644
--- a/source/Target/ThreadList.cpp
+++ b/source/Target/ThreadList.cpp
@@ -85,6 +85,17 @@ ThreadList::AddThread (const ThreadSP &thread_sp)
m_threads.push_back(thread_sp);
}
+void
+ThreadList::InsertThread (const lldb::ThreadSP &thread_sp, uint32_t idx)
+{
+ Mutex::Locker locker(GetMutex());
+ if (idx < m_threads.size())
+ m_threads.insert(m_threads.begin() + idx, thread_sp);
+ else
+ m_threads.push_back (thread_sp);
+}
+
+
uint32_t
ThreadList::GetSize (bool can_update)
{
@@ -293,17 +304,31 @@ ThreadList::ShouldStop (Event *event_ptr)
{
ThreadSP thread_sp(*pos);
- did_anybody_stop_for_a_reason |= thread_sp->ThreadStoppedForAReason();
+ // We should never get a stop for which no thread had a stop reason, but sometimes we do see this -
+ // for instance when we first connect to a remote stub. In that case we should stop, since we can't figure out
+ // the right thing to do and stopping gives the user control over what to do in this instance.
+ //
+ // Note, this causes a problem when you have a thread specific breakpoint, and a bunch of threads hit the breakpoint,
+ // but not the thread which we are waiting for. All the threads that are not "supposed" to hit the breakpoint
+ // are marked as having no stop reason, which is right, they should not show a stop reason. But that triggers this
+ // code and causes us to stop seemingly for no reason.
+ //
+ // Since the only way we ever saw this error was on first attach, I'm only going to trigger set did_anybody_stop_for_a_reason
+ // to true unless this is the first stop.
+ //
+ // If this becomes a problem, we'll have to have another StopReason like "StopInfoHidden" which will look invalid
+ // everywhere but at this check.
+
+ if (thread_sp->GetProcess()->GetStopID() > 1)
+ did_anybody_stop_for_a_reason = true;
+ else
+ did_anybody_stop_for_a_reason |= thread_sp->ThreadStoppedForAReason();
const bool thread_should_stop = thread_sp->ShouldStop(event_ptr);
if (thread_should_stop)
should_stop |= true;
}
- // We should never get a stop for which no thread had a stop reason, but sometimes we do see this -
- // for instance when we first connect to a remote stub. In that case we should stop, since we can't figure out
- // the right thing to do and stopping gives the user control over what to do in this instance.
-
if (!should_stop && !did_anybody_stop_for_a_reason)
{
should_stop = true;
diff --git a/source/Target/ThreadPlanStepInRange.cpp b/source/Target/ThreadPlanStepInRange.cpp
index 2cfd29f89196..c4cb9aba1b3e 100644
--- a/source/Target/ThreadPlanStepInRange.cpp
+++ b/source/Target/ThreadPlanStepInRange.cpp
@@ -16,6 +16,7 @@
#include "lldb/lldb-private-log.h"
#include "lldb/Core/Log.h"
+#include "lldb/Core/Module.h"
#include "lldb/Core/Stream.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Symbol/Function.h"
@@ -273,10 +274,36 @@ ThreadPlanStepInRange::SetDefaultFlagValue (uint32_t new_value)
}
bool
-ThreadPlanStepInRange::FrameMatchesAvoidRegexp ()
+ThreadPlanStepInRange::FrameMatchesAvoidCriteria ()
{
StackFrame *frame = GetThread().GetStackFrameAtIndex(0).get();
+
+ // Check the library list first, as that's cheapest:
+ bool libraries_say_avoid = false;
+ FileSpecList libraries_to_avoid (GetThread().GetLibrariesToAvoid());
+ size_t num_libraries = libraries_to_avoid.GetSize();
+ if (num_libraries > 0)
+ {
+ SymbolContext sc(frame->GetSymbolContext(eSymbolContextModule));
+ FileSpec frame_library(sc.module_sp->GetFileSpec());
+
+ if (frame_library)
+ {
+ for (size_t i = 0; i < num_libraries; i++)
+ {
+ const FileSpec &file_spec(libraries_to_avoid.GetFileSpecAtIndex(i));
+ if (FileSpec::Equal (file_spec, frame_library, false))
+ {
+ libraries_say_avoid = true;
+ break;
+ }
+ }
+ }
+ }
+ if (libraries_say_avoid)
+ return true;
+
const RegularExpression *avoid_regexp_to_use = m_avoid_regexp_ap.get();
if (avoid_regexp_to_use == NULL)
avoid_regexp_to_use = GetThread().GetSymbolsToAvoidRegexp();
@@ -368,8 +395,8 @@ ThreadPlanStepInRange::DefaultShouldStopHereCallback (ThreadPlan *current_plan,
if (!should_step_out)
{
ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (current_plan);
- // Don't log the should_step_out here, it's easier to do it in FrameMatchesAvoidRegexp.
- should_step_out = step_in_range_plan->FrameMatchesAvoidRegexp ();
+ // Don't log the should_step_out here, it's easier to do it in FrameMatchesAvoidCriteria.
+ should_step_out = step_in_range_plan->FrameMatchesAvoidCriteria ();
}
}
diff --git a/source/Target/ThreadPlanStepThrough.cpp b/source/Target/ThreadPlanStepThrough.cpp
index 37cd03c6986c..18da6cdbd59c 100644
--- a/source/Target/ThreadPlanStepThrough.cpp
+++ b/source/Target/ThreadPlanStepThrough.cpp
@@ -161,7 +161,7 @@ ThreadPlanStepThrough::ShouldStop (Event *event_ptr)
// First, did we hit the backstop breakpoint?
if (HitOurBackstopBreakpoint())
{
- SetPlanComplete(false);
+ SetPlanComplete(true);
return true;
}
diff --git a/source/Target/ThreadPlanTracer.cpp b/source/Target/ThreadPlanTracer.cpp
index af6cef7ecc5a..d191170fcc08 100644
--- a/source/Target/ThreadPlanTracer.cpp
+++ b/source/Target/ThreadPlanTracer.cpp
@@ -23,11 +23,13 @@
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/State.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/Core/Value.h"
#include "lldb/Symbol/TypeList.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
using namespace lldb;
@@ -61,7 +63,7 @@ ThreadPlanTracer::GetLogStream ()
{
TargetSP target_sp (m_thread.CalculateTarget());
if (target_sp)
- return &target_sp->GetDebugger().GetOutputStream();
+ return target_sp->GetDebugger().GetOutputFile().get();
}
return NULL;
}
diff --git a/source/Target/UnwindAssembly.cpp b/source/Target/UnwindAssembly.cpp
index 72137501f38b..af7f86fe492a 100644
--- a/source/Target/UnwindAssembly.cpp
+++ b/source/Target/UnwindAssembly.cpp
@@ -15,7 +15,7 @@
using namespace lldb;
using namespace lldb_private;
-UnwindAssembly*
+UnwindAssemblySP
UnwindAssembly::FindPlugin (const ArchSpec &arch)
{
UnwindAssemblyCreateInstance create_callback;
@@ -24,9 +24,9 @@ UnwindAssembly::FindPlugin (const ArchSpec &arch)
(create_callback = PluginManager::GetUnwindAssemblyCreateCallbackAtIndex(idx)) != NULL;
++idx)
{
- std::unique_ptr<UnwindAssembly> assembly_profiler_ap (create_callback (arch));
+ UnwindAssemblySP assembly_profiler_ap (create_callback (arch));
if (assembly_profiler_ap.get ())
- return assembly_profiler_ap.release ();
+ return assembly_profiler_ap;
}
return NULL;
}
diff --git a/source/Utility/StringExtractorGDBRemote.cpp b/source/Utility/StringExtractorGDBRemote.cpp
index 08e7af725650..eccb81318131 100644
--- a/source/Utility/StringExtractorGDBRemote.cpp
+++ b/source/Utility/StringExtractorGDBRemote.cpp
@@ -80,22 +80,40 @@ StringExtractorGDBRemote::GetServerPacketType () const
return eServerPacketType_A;
case 'Q':
+
switch (packet_cstr[1])
{
case 'E':
- if (PACKET_STARTS_WITH ("QEnvironment:")) return eServerPacketType_QEnvironment;
+ if (PACKET_STARTS_WITH ("QEnvironment:")) return eServerPacketType_QEnvironment;
+ if (PACKET_STARTS_WITH ("QEnvironmentHexEncoded:")) return eServerPacketType_QEnvironmentHexEncoded;
break;
case 'S':
- if (PACKET_MATCHES ("QStartNoAckMode")) return eServerPacketType_QStartNoAckMode;
- else if (PACKET_STARTS_WITH ("QSetDisableASLR:")) return eServerPacketType_QSetDisableASLR;
- else if (PACKET_STARTS_WITH ("QSetSTDIN:")) return eServerPacketType_QSetSTDIN;
- else if (PACKET_STARTS_WITH ("QSetSTDOUT:")) return eServerPacketType_QSetSTDOUT;
- else if (PACKET_STARTS_WITH ("QSetSTDERR:")) return eServerPacketType_QSetSTDERR;
- else if (PACKET_STARTS_WITH ("QSetWorkingDir:")) return eServerPacketType_QSetWorkingDir;
+ if (PACKET_MATCHES ("QStartNoAckMode")) return eServerPacketType_QStartNoAckMode;
+ if (PACKET_STARTS_WITH ("QSaveRegisterState")) return eServerPacketType_QSaveRegisterState;
+ if (PACKET_STARTS_WITH ("QSetDisableASLR:")) return eServerPacketType_QSetDisableASLR;
+ if (PACKET_STARTS_WITH ("QSetSTDIN:")) return eServerPacketType_QSetSTDIN;
+ if (PACKET_STARTS_WITH ("QSetSTDOUT:")) return eServerPacketType_QSetSTDOUT;
+ if (PACKET_STARTS_WITH ("QSetSTDERR:")) return eServerPacketType_QSetSTDERR;
+ if (PACKET_STARTS_WITH ("QSetWorkingDir:")) return eServerPacketType_QSetWorkingDir;
+ if (PACKET_STARTS_WITH ("QSetLogging:")) return eServerPacketType_QSetLogging;
+ if (PACKET_STARTS_WITH ("QSetMaxPacketSize:")) return eServerPacketType_QSetMaxPacketSize;
+ if (PACKET_STARTS_WITH ("QSetMaxPayloadSize:")) return eServerPacketType_QSetMaxPayloadSize;
+ if (PACKET_STARTS_WITH ("QSetEnableAsyncProfiling;")) return eServerPacketType_QSetEnableAsyncProfiling;
+ if (PACKET_STARTS_WITH ("QSyncThreadState:")) return eServerPacketType_QSyncThreadState;
break;
+
case 'L':
- if (PACKET_STARTS_WITH ("QLaunchArch:")) return eServerPacketType_QLaunchArch;
+ if (PACKET_STARTS_WITH ("QLaunchArch:")) return eServerPacketType_QLaunchArch;
+ if (PACKET_MATCHES("QListThreadsInStopReply")) return eServerPacketType_QListThreadsInStopReply;
+ break;
+
+ case 'R':
+ if (PACKET_STARTS_WITH ("QRestoreRegisterState:")) return eServerPacketType_QRestoreRegisterState;
+ break;
+
+ case 'T':
+ if (PACKET_MATCHES ("QThreadSuffixSupported")) return eServerPacketType_QThreadSuffixSupported;
break;
}
break;
@@ -105,10 +123,12 @@ StringExtractorGDBRemote::GetServerPacketType () const
{
case 's':
if (PACKET_MATCHES ("qsProcessInfo")) return eServerPacketType_qsProcessInfo;
+ if (PACKET_MATCHES ("qsThreadInfo")) return eServerPacketType_qsThreadInfo;
break;
case 'f':
if (PACKET_STARTS_WITH ("qfProcessInfo")) return eServerPacketType_qfProcessInfo;
+ if (PACKET_STARTS_WITH ("qfThreadInfo")) return eServerPacketType_qfThreadInfo;
break;
case 'C':
@@ -118,6 +138,9 @@ StringExtractorGDBRemote::GetServerPacketType () const
case 'G':
if (PACKET_STARTS_WITH ("qGroupName:")) return eServerPacketType_qGroupName;
if (PACKET_MATCHES ("qGetWorkingDir")) return eServerPacketType_qGetWorkingDir;
+ if (PACKET_MATCHES ("qGetPid")) return eServerPacketType_qGetPid;
+ if (PACKET_STARTS_WITH ("qGetProfileData;")) return eServerPacketType_qGetProfileData;
+ if (PACKET_MATCHES ("qGDBServerVersion")) return eServerPacketType_qGDBServerVersion;
break;
case 'H':
@@ -133,21 +156,48 @@ StringExtractorGDBRemote::GetServerPacketType () const
if (PACKET_MATCHES ("qLaunchSuccess")) return eServerPacketType_qLaunchSuccess;
break;
+ case 'M':
+ if (PACKET_STARTS_WITH ("qMemoryRegionInfo:")) return eServerPacketType_qMemoryRegionInfo;
+ if (PACKET_MATCHES ("qMemoryRegionInfo")) return eServerPacketType_qMemoryRegionInfoSupported;
+ break;
+
case 'P':
if (PACKET_STARTS_WITH ("qProcessInfoPID:")) return eServerPacketType_qProcessInfoPID;
- if (PACKET_STARTS_WITH ("qPlatform_shell:")) return eServerPacketType_qPlatform_shell;
+ if (PACKET_STARTS_WITH ("qPlatform_shell:")) return eServerPacketType_qPlatform_shell;
if (PACKET_STARTS_WITH ("qPlatform_mkdir:")) return eServerPacketType_qPlatform_mkdir;
if (PACKET_STARTS_WITH ("qPlatform_chmod:")) return eServerPacketType_qPlatform_chmod;
+ if (PACKET_MATCHES ("qProcessInfo")) return eServerPacketType_qProcessInfo;
break;
+ case 'R':
+ if (PACKET_STARTS_WITH ("qRcmd,")) return eServerPacketType_qRcmd;
+ if (PACKET_STARTS_WITH ("qRegisterInfo")) return eServerPacketType_qRegisterInfo;
+ break;
case 'S':
if (PACKET_STARTS_WITH ("qSpeedTest:")) return eServerPacketType_qSpeedTest;
+ if (PACKET_MATCHES ("qShlibInfoAddr")) return eServerPacketType_qShlibInfoAddr;
+ if (PACKET_MATCHES ("qStepPacketSupported")) return eServerPacketType_qStepPacketSupported;
+ if (PACKET_MATCHES ("qSyncThreadStateSupported")) return eServerPacketType_qSyncThreadStateSupported;
+ break;
+
+ case 'T':
+ if (PACKET_STARTS_WITH ("qThreadExtraInfo,")) return eServerPacketType_qThreadExtraInfo;
+ if (PACKET_STARTS_WITH ("qThreadStopInfo")) return eServerPacketType_qThreadStopInfo;
break;
case 'U':
if (PACKET_STARTS_WITH ("qUserName:")) return eServerPacketType_qUserName;
break;
+
+ case 'V':
+ if (PACKET_MATCHES ("qVAttachOrWaitSupported")) return eServerPacketType_qVAttachOrWaitSupported;
+ break;
+
+ case 'W':
+ if (PACKET_STARTS_WITH ("qWatchpointSupportInfo:")) return eServerPacketType_qWatchpointSupportInfo;
+ if (PACKET_MATCHES ("qWatchpointSupportInfo")) return eServerPacketType_qWatchpointSupportInfoSupported;
+ break;
}
break;
case 'v':
@@ -165,8 +215,85 @@ StringExtractorGDBRemote::GetServerPacketType () const
else if (PACKET_STARTS_WITH("vFile:symlink")) return eServerPacketType_vFile_symlink;
else if (PACKET_STARTS_WITH("vFile:unlink")) return eServerPacketType_vFile_unlink;
+ } else {
+ if (PACKET_STARTS_WITH ("vAttach;")) return eServerPacketType_vAttach;
+ if (PACKET_STARTS_WITH ("vAttachWait;")) return eServerPacketType_vAttachWait;
+ if (PACKET_STARTS_WITH ("vAttachOrWait;")) return eServerPacketType_vAttachOrWait;
+ if (PACKET_STARTS_WITH ("vAttachName;")) return eServerPacketType_vAttachName;
+ if (PACKET_STARTS_WITH("vCont;")) return eServerPacketType_vCont;
+ if (PACKET_MATCHES ("vCont?")) return eServerPacketType_vCont_actions;
}
break;
+ case '_':
+ switch (packet_cstr[1])
+ {
+ case 'M':
+ return eServerPacketType__M;
+
+ case 'm':
+ return eServerPacketType__m;
+ }
+ break;
+
+ case '?':
+ if (packet_size == 1) return eServerPacketType_stop_reason;
+ break;
+
+ case 'c':
+ return eServerPacketType_c;
+
+ case 'C':
+ return eServerPacketType_C;
+
+ case 'D':
+ if (packet_size == 1) return eServerPacketType_D;
+ break;
+
+ case 'g':
+ if (packet_size == 1) return eServerPacketType_g;
+ break;
+
+ case 'G':
+ return eServerPacketType_G;
+
+ case 'H':
+ return eServerPacketType_H;
+
+ case 'k':
+ if (packet_size == 1) return eServerPacketType_k;
+ break;
+
+ case 'm':
+ return eServerPacketType_m;
+
+ case 'M':
+ return eServerPacketType_M;
+
+ case 'p':
+ return eServerPacketType_p;
+
+ case 'P':
+ return eServerPacketType_P;
+
+ case 's':
+ if (packet_size == 1) return eServerPacketType_s;
+ break;
+
+ case 'S':
+ return eServerPacketType_S;
+
+ case 'T':
+ return eServerPacketType_T;
+
+ case 'z':
+ if (packet_cstr[1] >= '0' && packet_cstr[1] <= '4')
+ return eServerPacketType_z;
+ break;
+
+ case 'Z':
+ if (packet_cstr[1] >= '0' && packet_cstr[1] <= '4')
+ return eServerPacketType_Z;
+ break;
}
return eServerPacketType_unimplemented;
}
diff --git a/source/Utility/StringExtractorGDBRemote.h b/source/Utility/StringExtractorGDBRemote.h
index 2379882e8bf8..f8af3ca41a79 100644
--- a/source/Utility/StringExtractorGDBRemote.h
+++ b/source/Utility/StringExtractorGDBRemote.h
@@ -80,7 +80,66 @@ public:
eServerPacketType_vFile_md5,
eServerPacketType_vFile_stat,
eServerPacketType_vFile_symlink,
- eServerPacketType_vFile_unlink
+ eServerPacketType_vFile_unlink,
+ // debug server packages
+ eServerPacketType_QEnvironmentHexEncoded,
+ eServerPacketType_QListThreadsInStopReply,
+ eServerPacketType_QRestoreRegisterState,
+ eServerPacketType_QSaveRegisterState,
+ eServerPacketType_QSetLogging,
+ eServerPacketType_QSetMaxPacketSize,
+ eServerPacketType_QSetMaxPayloadSize,
+ eServerPacketType_QSetEnableAsyncProfiling,
+ eServerPacketType_QSyncThreadState,
+ eServerPacketType_QThreadSuffixSupported,
+
+ eServerPacketType_qsThreadInfo,
+ eServerPacketType_qfThreadInfo,
+ eServerPacketType_qGetPid,
+ eServerPacketType_qGetProfileData,
+ eServerPacketType_qGDBServerVersion,
+ eServerPacketType_qMemoryRegionInfo,
+ eServerPacketType_qMemoryRegionInfoSupported,
+ eServerPacketType_qProcessInfo,
+ eServerPacketType_qRcmd,
+ eServerPacketType_qRegisterInfo,
+ eServerPacketType_qShlibInfoAddr,
+ eServerPacketType_qStepPacketSupported,
+ eServerPacketType_qSyncThreadStateSupported,
+ eServerPacketType_qThreadExtraInfo,
+ eServerPacketType_qThreadStopInfo,
+ eServerPacketType_qVAttachOrWaitSupported,
+ eServerPacketType_qWatchpointSupportInfo,
+ eServerPacketType_qWatchpointSupportInfoSupported,
+
+ eServerPacketType_vAttach,
+ eServerPacketType_vAttachWait,
+ eServerPacketType_vAttachOrWait,
+ eServerPacketType_vAttachName,
+ eServerPacketType_vCont,
+ eServerPacketType_vCont_actions, // vCont?
+
+ eServerPacketType_stop_reason, // '?'
+
+ eServerPacketType_c,
+ eServerPacketType_C,
+ eServerPacketType_D,
+ eServerPacketType_g,
+ eServerPacketType_G,
+ eServerPacketType_H,
+ eServerPacketType_k,
+ eServerPacketType_m,
+ eServerPacketType_M,
+ eServerPacketType_p,
+ eServerPacketType_P,
+ eServerPacketType_s,
+ eServerPacketType_S,
+ eServerPacketType_T,
+ eServerPacketType_Z,
+ eServerPacketType_z,
+
+ eServerPacketType__M,
+ eServerPacketType__m,
};
ServerPacketType
diff --git a/source/lldb-log.cpp b/source/lldb-log.cpp
index 5e1dc3a54e8a..12ec3a546e1b 100644
--- a/source/lldb-log.cpp
+++ b/source/lldb-log.cpp
@@ -141,6 +141,7 @@ lldb_private::DisableLog (const char **categories, Stream *feedback_strm)
else if (0 == ::strncasecmp(arg, "unwind", 6)) flag_bits &= ~LIBLLDB_LOG_UNWIND;
else if (0 == ::strncasecmp(arg, "types", 5)) flag_bits &= ~LIBLLDB_LOG_TYPES;
else if (0 == ::strncasecmp(arg, "symbol", 6)) flag_bits &= ~LIBLLDB_LOG_SYMBOLS;
+ else if (0 == ::strcasecmp(arg, "system-runtime")) flag_bits &= ~LIBLLDB_LOG_SYSTEM_RUNTIME;
else if (0 == ::strncasecmp(arg, "module", 6)) flag_bits &= ~LIBLLDB_LOG_MODULES;
else if (0 == ::strncasecmp(arg, "mmap", 4)) flag_bits &= ~LIBLLDB_LOG_MMAP;
else if (0 == ::strcasecmp(arg, "os")) flag_bits &= ~LIBLLDB_LOG_OS;
@@ -155,7 +156,10 @@ lldb_private::DisableLog (const char **categories, Stream *feedback_strm)
}
log->GetMask().Reset (flag_bits);
if (flag_bits == 0)
+ {
+ log->SetStream(lldb::StreamSP());
g_log_enabled = false;
+ }
}
return;
@@ -208,6 +212,7 @@ lldb_private::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, const ch
else if (0 == ::strcasecmp(arg, "state")) flag_bits |= LIBLLDB_LOG_STATE;
else if (0 == ::strcasecmp(arg, "step")) flag_bits |= LIBLLDB_LOG_STEP;
else if (0 == ::strncasecmp(arg, "symbol", 6)) flag_bits |= LIBLLDB_LOG_SYMBOLS;
+ else if (0 == ::strcasecmp(arg, "system-runtime")) flag_bits |= LIBLLDB_LOG_SYSTEM_RUNTIME;
else if (0 == ::strcasecmp(arg, "target")) flag_bits |= LIBLLDB_LOG_TARGET;
else if (0 == ::strncasecmp(arg, "temp", 4)) flag_bits |= LIBLLDB_LOG_TEMPORARY;
else if (0 == ::strcasecmp(arg, "thread")) flag_bits |= LIBLLDB_LOG_THREAD;
@@ -256,6 +261,7 @@ lldb_private::ListLogCategories (Stream *strm)
" state - log private and public process state changes\n"
" step - log step related activities\n"
" symbol - log symbol related issues and warnings\n"
+ " system-runtime - log system runtime events\n"
" target - log target events and activities\n"
" thread - log thread events and activities\n"
" types - log type system related activities\n"
diff --git a/source/lldb.cpp b/source/lldb.cpp
index 78e8208e0910..4817e7f2b44c 100644
--- a/source/lldb.cpp
+++ b/source/lldb.cpp
@@ -19,6 +19,7 @@
#include "lldb/Core/Timer.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/Mutex.h"
+#include "lldb/Interpreter/ScriptInterpreterPython.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
@@ -120,6 +121,7 @@ lldb_private::Initialize ()
SymbolFileDWARFDebugMap::Initialize();
ItaniumABILanguageRuntime::Initialize();
#ifndef LLDB_DISABLE_PYTHON
+ ScriptInterpreterPython::InitializePrivate();
OperatingSystemPython::Initialize();
#endif