diff options
Diffstat (limited to 'include/lldb/Core')
-rw-r--r-- | include/lldb/Core/ArchSpec.h | 25 | ||||
-rw-r--r-- | include/lldb/Core/Communication.h | 2 | ||||
-rw-r--r-- | include/lldb/Core/ConnectionFileDescriptor.h | 20 | ||||
-rw-r--r-- | include/lldb/Core/Debugger.h | 127 | ||||
-rw-r--r-- | include/lldb/Core/Disassembler.h | 3 | ||||
-rw-r--r-- | include/lldb/Core/IOHandler.h | 646 | ||||
-rw-r--r-- | include/lldb/Core/InputReader.h | 274 | ||||
-rw-r--r-- | include/lldb/Core/InputReaderEZ.h | 87 | ||||
-rw-r--r-- | include/lldb/Core/InputReaderStack.h | 58 | ||||
-rw-r--r-- | include/lldb/Core/MappedHash.h | 12 | ||||
-rw-r--r-- | include/lldb/Core/Module.h | 19 | ||||
-rw-r--r-- | include/lldb/Core/Opcode.h | 52 | ||||
-rw-r--r-- | include/lldb/Core/SourceManager.h | 15 | ||||
-rw-r--r-- | include/lldb/Core/StreamAsynchronousIO.h | 3 | ||||
-rw-r--r-- | include/lldb/Core/StringList.h | 42 | ||||
-rw-r--r-- | include/lldb/Core/ValueObject.h | 7 | ||||
-rw-r--r-- | include/lldb/Core/ValueObjectList.h | 6 |
17 files changed, 892 insertions, 506 deletions
diff --git a/include/lldb/Core/ArchSpec.h b/include/lldb/Core/ArchSpec.h index 7f2fd77a0934..4ec8e06c8b35 100644 --- a/include/lldb/Core/ArchSpec.h +++ b/include/lldb/Core/ArchSpec.h @@ -13,6 +13,7 @@ #if defined(__cplusplus) #include "lldb/lldb-private.h" +#include "lldb/Core/ConstString.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" @@ -90,6 +91,7 @@ public: eCore_x86_32_i486sx, eCore_x86_64_x86_64, + eCore_x86_64_x86_64h, // Haswell enabled x86_64 eCore_uknownMach32, eCore_uknownMach64, kNumCores, @@ -203,6 +205,27 @@ public: GetMachine () const; //------------------------------------------------------------------ + /// Returns the distribution id of the architecture. + /// + /// This will be something like "ubuntu", "fedora", etc. on Linux. + /// + /// @return A ConstString ref containing the distribution id, + /// potentially empty. + //------------------------------------------------------------------ + const ConstString& + GetDistributionId () const; + + //------------------------------------------------------------------ + /// Set the distribution id of the architecture. + /// + /// This will be something like "ubuntu", "fedora", etc. on Linux. + /// This should be the same value returned by + /// Host::GetDistributionId (). + ///------------------------------------------------------------------ + void + SetDistributionId (const char* distribution_id); + + //------------------------------------------------------------------ /// Tests if this ArchSpec is valid. /// /// @return True if the current architecture is valid, false @@ -400,6 +423,8 @@ protected: Core m_core; lldb::ByteOrder m_byte_order; + ConstString m_distribution_id; + // Called when m_def or m_entry are changed. Fills in all remaining // members with default values. void diff --git a/include/lldb/Core/Communication.h b/include/lldb/Core/Communication.h index 98d4dfd011b8..2dde55044171 100644 --- a/include/lldb/Core/Communication.h +++ b/include/lldb/Core/Communication.h @@ -286,6 +286,8 @@ public: virtual bool StopReadThread (Error *error_ptr = NULL); + virtual bool + JoinReadThread (Error *error_ptr = NULL); //------------------------------------------------------------------ /// Checks if there is a currently running read thread. /// diff --git a/include/lldb/Core/ConnectionFileDescriptor.h b/include/lldb/Core/ConnectionFileDescriptor.h index 3a2f0dd1ed0b..15598c9b1335 100644 --- a/include/lldb/Core/ConnectionFileDescriptor.h +++ b/include/lldb/Core/ConnectionFileDescriptor.h @@ -11,9 +11,7 @@ #define liblldb_ConnectionFileDescriptor_h_ // C Includes -#ifdef _WIN32 -typedef unsigned short in_port_t; -#else +#ifndef _WIN32 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> @@ -68,14 +66,17 @@ public: // 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 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 GetWritePort () const; + uint16_t + GetBoundPort (uint32_t timeout_sec); + protected: typedef enum @@ -95,7 +96,7 @@ protected: BytesAvailable (uint32_t timeout_usec, Error *error_ptr); lldb::ConnectionStatus - SocketListen (uint16_t listen_port_num, Error *error_ptr); + SocketListen (const char *host_and_port, Error *error_ptr); lldb::ConnectionStatus ConnectTCP (const char *host_and_port, Error *error_ptr); @@ -117,15 +118,16 @@ protected: FDType m_fd_send_type; FDType m_fd_recv_type; std::unique_ptr<SocketAddress> m_udp_send_sockaddr; - bool m_should_close_fd; // True if this class should close the file descriptor when it goes away. uint32_t m_socket_timeout_usec; int m_pipe_read; // A pipe that we select on the reading end of along with int m_pipe_write; // m_fd_recv so we can force ourselves out of the select. - Mutex m_mutex; + Mutex m_mutex; + Predicate<uint16_t> m_port_predicate; // Used when binding to port zero to wait for the thread that creates the socket, binds and listens to resolve the port number + bool m_should_close_fd; // True if this class should close the file descriptor when it goes away. bool m_shutting_down; // This marks that we are shutting down so if we get woken up from BytesAvailable // to disconnect, we won't try to read again. - static in_port_t + static uint16_t GetSocketPort (int fd); static int diff --git a/include/lldb/Core/Debugger.h b/include/lldb/Core/Debugger.h index a3c6d5eeb93d..e80ec8516793 100644 --- a/include/lldb/Core/Debugger.h +++ b/include/lldb/Core/Debugger.h @@ -19,9 +19,8 @@ #include "lldb/lldb-public.h" #include "lldb/Core/Broadcaster.h" #include "lldb/Core/Communication.h" -#include "lldb/Core/InputReaderStack.h" +#include "lldb/Core/IOHandler.h" #include "lldb/Core/Listener.h" -#include "lldb/Core/StreamFile.h" #include "lldb/Core/SourceManager.h" #include "lldb/Core/UserID.h" #include "lldb/Core/UserSettingsController.h" @@ -91,23 +90,25 @@ public: void SetAsyncExecution (bool async); - File & + lldb::StreamFileSP GetInputFile () { - return m_input_file.GetFile(); + return m_input_file_sp; } - File & + lldb::StreamFileSP GetOutputFile () { - return m_output_file.GetFile(); + return m_output_file_sp; } - File & + lldb::StreamFileSP GetErrorFile () { - return m_error_file.GetFile(); + return m_error_file_sp; } + + void SetInputFileHandle (FILE *fh, bool tranfer_ownership); @@ -124,18 +125,6 @@ public: void RestoreInputTerminalState(); - Stream& - GetOutputStream () - { - return m_output_file; - } - - Stream& - GetErrorStream () - { - return m_error_file; - } - lldb::StreamSP GetAsyncOutputStream (); @@ -200,24 +189,38 @@ public: void DispatchInputEndOfFile (); + //------------------------------------------------------------------ + // If any of the streams are not set, set them to the in/out/err + // stream of the top most input reader to ensure they at least have + // something + //------------------------------------------------------------------ void - DispatchInput (const char *bytes, size_t bytes_len); + AdoptTopIOHandlerFilesIfInvalid (lldb::StreamFileSP &in, + lldb::StreamFileSP &out, + lldb::StreamFileSP &err); void - WriteToDefaultReader (const char *bytes, size_t bytes_len); + PushIOHandler (const lldb::IOHandlerSP& reader_sp); + bool + PopIOHandler (const lldb::IOHandlerSP& reader_sp); + + // Synchronously run an input reader until it is done void - PushInputReader (const lldb::InputReaderSP& reader_sp); + RunIOHandler (const lldb::IOHandlerSP& reader_sp); + + bool + IsTopIOHandler (const lldb::IOHandlerSP& reader_sp); + + ConstString + GetTopIOHandlerControlSequence(char ch); bool - PopInputReader (const lldb::InputReaderSP& reader_sp); + HideTopIOHandler(); void - NotifyTopInputReader (lldb::InputReaderAction notification); + RefreshTopIOHandler(); - bool - InputReaderIsTopReader (const lldb::InputReaderSP& reader_sp); - static lldb::DebuggerSP FindDebuggerWithID (lldb::user_id_t id); @@ -240,7 +243,7 @@ public: void - CleanUpInputReaders (); + ClearIOHandlers (); static int TestDebuggerRefCount (); @@ -338,29 +341,65 @@ public: bool LoadPlugin (const FileSpec& spec, Error& error); + void + ExecuteIOHanders(); + + bool + IsForwardingEvents (); + + void + EnableForwardEvents (const lldb::ListenerSP &listener_sp); + + void + CancelForwardEvents (const lldb::ListenerSP &listener_sp); protected: - static void - DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len); + friend class CommandInterpreter; + + bool + StartEventHandlerThread(); - lldb::InputReaderSP - GetCurrentInputReader (); - void - ActivateInputReader (const lldb::InputReaderSP &reader_sp); + StopEventHandlerThread(); + + static lldb::thread_result_t + EventHandlerThread (lldb::thread_arg_t arg); bool - CheckIfTopInputReaderIsDone (); + StartIOHandlerThread(); + + void + StopIOHandlerThread(); + static lldb::thread_result_t + IOHandlerThread (lldb::thread_arg_t arg); + + void + DefaultEventHandler(); + + void + HandleBreakpointEvent (const lldb::EventSP &event_sp); + + void + HandleProcessEvent (const lldb::EventSP &event_sp); + + void + HandleThreadEvent (const lldb::EventSP &event_sp); + + size_t + GetProcessSTDOUT (Process *process, Stream *stream); + + size_t + GetProcessSTDERR (Process *process, Stream *stream); + SourceManager::SourceFileCache & GetSourceFileCache () { return m_source_file_cache; } - Communication m_input_comm; - StreamFile m_input_file; - StreamFile m_output_file; - StreamFile m_error_file; + lldb::StreamFileSP m_input_file_sp; + lldb::StreamFileSP m_output_file_sp; + lldb::StreamFileSP m_error_file_sp; TerminalState m_terminal_state; TargetList m_target_list; PlatformList m_platform_list; @@ -370,8 +409,7 @@ protected: // source file cache. std::unique_ptr<CommandInterpreter> m_command_interpreter_ap; - InputReaderStack m_input_reader_stack; - std::string m_input_reader_data; + IOHandlerStack m_input_reader_stack; typedef std::map<std::string, lldb::StreamWP> LogStreamMap; LogStreamMap m_log_streams; lldb::StreamSP m_log_callback_stream_sp; @@ -379,7 +417,10 @@ protected: static LoadPluginCallbackType g_load_plugin_callback; typedef std::vector<lldb::DynamicLibrarySP> LoadedPluginsList; LoadedPluginsList m_loaded_plugins; - + lldb::thread_t m_event_handler_thread; + lldb::thread_t m_io_handler_thread; + lldb::ListenerSP m_forward_listener_sp; + bool m_event_handler_thread_alive; void InstanceInitialize (); diff --git a/include/lldb/Core/Disassembler.h b/include/lldb/Core/Disassembler.h index f434d56943d4..06a703b4c1aa 100644 --- a/include/lldb/Core/Disassembler.h +++ b/include/lldb/Core/Disassembler.h @@ -175,6 +175,9 @@ public: uint32_t GetIndexOfInstructionAtLoadAddress (lldb::addr_t load_addr, Target &target); + uint32_t + GetIndexOfInstructionAtAddress (const Address &addr); + void Clear(); diff --git a/include/lldb/Core/IOHandler.h b/include/lldb/Core/IOHandler.h new file mode 100644 index 000000000000..a7d4880da0d3 --- /dev/null +++ b/include/lldb/Core/IOHandler.h @@ -0,0 +1,646 @@ +//===-- IOHandler.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_IOHandler_h_ +#define liblldb_IOHandler_h_ + +#include <string.h> + +#include <stack> + +#include "lldb/lldb-public.h" +#include "lldb/lldb-enumerations.h" +#include "lldb/Core/ConstString.h" +#include "lldb/Core/Error.h" +#include "lldb/Core/Flags.h" +#include "lldb/Core/StringList.h" +#include "lldb/Core/ValueObjectList.h" +#include "lldb/Host/Mutex.h" + +namespace curses +{ + class Application; + typedef std::unique_ptr<Application> ApplicationAP; +} + +namespace lldb_private { + + class IOHandler + { + public: + IOHandler (Debugger &debugger); + + IOHandler (Debugger &debugger, + const lldb::StreamFileSP &input_sp, + const lldb::StreamFileSP &output_sp, + const lldb::StreamFileSP &error_sp, + uint32_t flags); + + virtual + ~IOHandler (); + + // 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 () = 0; + + // 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 () = 0; + + // 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 () = 0; + + virtual void + Interrupt () = 0; + + virtual void + GotEOF() = 0; + + virtual bool + IsActive () + { + return m_active && !m_done; + } + + virtual void + SetIsDone (bool b) + { + m_done = b; + } + + virtual bool + GetIsDone () + { + return m_done; + } + + virtual void + Activate () + { + m_active = true; + } + + virtual void + Deactivate () + { + m_active = false; + } + + virtual const char * + GetPrompt () + { + // Prompt support isn't mandatory + return NULL; + } + + virtual bool + SetPrompt (const char *prompt) + { + // Prompt support isn't mandatory + return false; + } + + virtual ConstString + GetControlSequence (char ch) + { + return ConstString(); + } + + int + GetInputFD(); + + int + GetOutputFD(); + + int + GetErrorFD(); + + FILE * + GetInputFILE(); + + FILE * + GetOutputFILE(); + + FILE * + GetErrorFILE(); + + lldb::StreamFileSP & + GetInputStreamFile(); + + lldb::StreamFileSP & + GetOutputStreamFile(); + + lldb::StreamFileSP & + GetErrorStreamFile(); + + Debugger & + GetDebugger() + { + return m_debugger; + } + + void * + GetUserData () + { + return m_user_data; + } + + void + SetUserData (void *user_data) + { + m_user_data = user_data; + } + + Flags & + GetFlags () + { + return m_flags; + } + + const Flags & + GetFlags () const + { + return m_flags; + } + + //------------------------------------------------------------------ + /// Check if the input is being supplied interactively by a user + /// + /// This will return true if the input stream is a terminal (tty or + /// pty) and can cause IO handlers to do different things (like + /// for a comfirmation when deleting all breakpoints). + //------------------------------------------------------------------ + bool + GetIsInteractive (); + + //------------------------------------------------------------------ + /// Check if the input is coming from a real terminal. + /// + /// A real terminal has a valid size with a certain number of rows + /// and colums. If this function returns true, then terminal escape + /// sequences are expected to work (cursor movement escape sequences, + /// clearning lines, etc). + //------------------------------------------------------------------ + bool + GetIsRealTerminal (); + + protected: + Debugger &m_debugger; + lldb::StreamFileSP m_input_sp; + lldb::StreamFileSP m_output_sp; + lldb::StreamFileSP m_error_sp; + Flags m_flags; + void *m_user_data; + bool m_done; + bool m_active; + + private: + DISALLOW_COPY_AND_ASSIGN (IOHandler); + }; + + + //------------------------------------------------------------------ + /// A delegate class for use with IOHandler subclasses. + /// + /// The IOHandler delegate is designed to be mixed into classes so + /// they can use an IOHandler subclass to fetch input and notify the + /// object that inherits from this delegate class when a token is + /// received. + //------------------------------------------------------------------ + class IOHandlerDelegate + { + public: + enum class Completion { + None, + LLDBCommand, + Expression + }; + + IOHandlerDelegate (Completion completion = Completion::None) : + m_completion(completion), + m_io_handler_done (false) + { + } + + virtual + ~IOHandlerDelegate() + { + } + + virtual void + IOHandlerActivated (IOHandler &io_handler) + { + } + + virtual int + 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); + + //------------------------------------------------------------------ + /// Called when a line or lines have been retrieved. + /// + /// This funtion can handle the current line and possibly call + /// IOHandler::SetIsDone(true) when the IO handler is done like when + /// "quit" is entered as a command, of when an empty line is + /// received. It is up to the delegate to determine when a line + /// should cause a IOHandler to exit. + //------------------------------------------------------------------ + virtual void + IOHandlerInputComplete (IOHandler &io_handler, std::string &data) = 0; + + //------------------------------------------------------------------ + /// Called when a line in \a lines has been updated when doing + /// multi-line input. + /// + /// @return + /// Return an enumeration to indicate the status of the current + /// line: + /// Success - The line is good and should be added to the + /// multiple lines + /// Error - There is an error with the current line and it + /// need to be re-edited before it is acceptable + /// Done - The lines collection is complete and ready to be + /// returned. + //------------------------------------------------------------------ + virtual LineStatus + IOHandlerLinesUpdated (IOHandler &io_handler, + StringList &lines, + uint32_t line_idx, + Error &error) + { + return LineStatus::Done; // Stop getting lines on the first line that is updated + // subclasses should do something more intelligent here. + // This function will not be called on IOHandler objects + // that are getting single lines. + } + + + virtual ConstString + GetControlSequence (char ch) + { + return ConstString(); + } + + protected: + Completion m_completion; // Support for common builtin completions + bool m_io_handler_done; + }; + + //---------------------------------------------------------------------- + // IOHandlerDelegateMultiline + // + // A IOHandlerDelegate that handles terminating multi-line input when + // the last line is equal to "end_line" which is specified in the + // constructor. + //---------------------------------------------------------------------- + class IOHandlerDelegateMultiline : + public IOHandlerDelegate + { + public: + IOHandlerDelegateMultiline (const char *end_line, + Completion completion = Completion::None) : + IOHandlerDelegate (completion), + m_end_line((end_line && end_line[0]) ? end_line : "") + { + } + + virtual + ~IOHandlerDelegateMultiline () + { + } + + virtual ConstString + GetControlSequence (char ch) + { + if (ch == 'd') + return ConstString (m_end_line + "\n"); + return ConstString(); + } + + virtual LineStatus + IOHandlerLinesUpdated (IOHandler &io_handler, + StringList &lines, + uint32_t line_idx, + Error &error) + { + if (line_idx == UINT32_MAX) + { + // 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; + } + 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] == m_end_line) + return LineStatus::Done; + } + return LineStatus::Success; + } + protected: + const std::string m_end_line; + }; + + + class IOHandlerEditline : public IOHandler + { + public: + IOHandlerEditline (Debugger &debugger, + const char *editline_name, // Used for saving history files + const char *prompt, + bool multi_line, + IOHandlerDelegate &delegate); + + 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); + + virtual + ~IOHandlerEditline (); + + virtual void + Run (); + + virtual void + Hide (); + + virtual void + Refresh (); + + virtual void + Interrupt (); + + virtual void + GotEOF(); + + virtual void + Activate () + { + IOHandler::Activate(); + m_delegate.IOHandlerActivated(*this); + } + + virtual ConstString + GetControlSequence (char ch) + { + return m_delegate.GetControlSequence (ch); + } + + virtual const char * + GetPrompt (); + + virtual bool + SetPrompt (const char *prompt); + + bool + GetLine (std::string &line); + + bool + GetLines (StringList &lines); + + private: + static LineStatus + LineCompletedCallback (Editline *editline, + StringList &lines, + uint32_t line_idx, + Error &error, + void *baton); + + static int AutoCompleteCallback (const char *current_line, + const char *cursor, + const char *last_char, + int skip_first_n_matches, + int max_matches, + StringList &matches, + void *baton); + + protected: + std::unique_ptr<Editline> m_editline_ap; + IOHandlerDelegate &m_delegate; + std::string m_prompt; + bool m_multi_line; + }; + + class IOHandlerConfirm : + public IOHandlerEditline, + public IOHandlerDelegate + { + public: + IOHandlerConfirm (Debugger &debugger, + const char *prompt, + bool default_response); + + virtual + ~IOHandlerConfirm (); + + bool + GetResponse () const + { + return m_user_response; + } + + virtual int + 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); + + virtual void + IOHandlerInputComplete (IOHandler &io_handler, std::string &data); + + protected: + const bool m_default_response; + bool m_user_response; + }; + + class IOHandlerCursesGUI : + public IOHandler + { + public: + IOHandlerCursesGUI (Debugger &debugger); + + virtual + ~IOHandlerCursesGUI (); + + virtual void + Run (); + + virtual void + Hide (); + + virtual void + Refresh (); + + virtual void + Interrupt (); + + virtual void + GotEOF(); + + virtual void + Activate (); + + virtual void + Deactivate (); + + protected: + curses::ApplicationAP m_app_ap; + }; + + class IOHandlerCursesValueObjectList : + public IOHandler + { + public: + IOHandlerCursesValueObjectList (Debugger &debugger, ValueObjectList &valobj_list); + + virtual + ~IOHandlerCursesValueObjectList (); + + virtual void + Run (); + + virtual void + Hide (); + + virtual void + Refresh (); + + virtual void + Interrupt (); + + virtual void + GotEOF(); + protected: + ValueObjectList m_valobj_list; + }; + + class IOHandlerStack + { + public: + + IOHandlerStack () : + m_stack(), + m_mutex(Mutex::eMutexTypeRecursive), + m_top (NULL) + { + } + + ~IOHandlerStack () + { + } + + size_t + GetSize () const + { + Mutex::Locker locker (m_mutex); + return m_stack.size(); + } + + void + Push (const lldb::IOHandlerSP& sp) + { + if (sp) + { + Mutex::Locker locker (m_mutex); + m_stack.push (sp); + // Set m_top the non-locking IsTop() call + m_top = sp.get(); + } + } + + bool + IsEmpty () const + { + Mutex::Locker locker (m_mutex); + return m_stack.empty(); + } + + lldb::IOHandlerSP + Top () + { + lldb::IOHandlerSP sp; + { + Mutex::Locker locker (m_mutex); + if (!m_stack.empty()) + sp = m_stack.top(); + } + return sp; + } + + void + Pop () + { + Mutex::Locker locker (m_mutex); + if (!m_stack.empty()) + m_stack.pop(); + // Set m_top the non-locking IsTop() call + if (m_stack.empty()) + m_top = NULL; + else + m_top = m_stack.top().get(); + } + + Mutex & + GetMutex() + { + return m_mutex; + } + + bool + IsTop (const lldb::IOHandlerSP &io_handler_sp) const + { + return m_top == io_handler_sp.get(); + } + + ConstString + GetTopIOHandlerControlSequence (char ch) + { + if (m_top) + return m_top->GetControlSequence(ch); + return ConstString(); + } + + protected: + + std::stack<lldb::IOHandlerSP> m_stack; + mutable Mutex m_mutex; + IOHandler *m_top; + + private: + + DISALLOW_COPY_AND_ASSIGN (IOHandlerStack); + }; + +} // namespace lldb_private + +#endif // #ifndef liblldb_IOHandler_h_ diff --git a/include/lldb/Core/InputReader.h b/include/lldb/Core/InputReader.h deleted file mode 100644 index fa86e9a39e2b..000000000000 --- a/include/lldb/Core/InputReader.h +++ /dev/null @@ -1,274 +0,0 @@ -//===-- InputReader.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_InputReader_h_ -#define liblldb_InputReader_h_ - -#include <string.h> - -#include "lldb/lldb-public.h" -#include "lldb/lldb-enumerations.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/StringList.h" -#include "lldb/Host/Predicate.h" - - -namespace lldb_private { - -class InputReader -{ -public: - - typedef size_t (*Callback) (void *baton, - InputReader &reader, - lldb::InputReaderAction notification, - const char *bytes, - size_t bytes_len); - - struct HandlerData - { - InputReader& reader; - const char *bytes; - size_t bytes_len; - void* baton; - - HandlerData(InputReader& r, - const char* b, - size_t l, - void* t) : - reader(r), - bytes(b), - bytes_len(l), - baton(t) - { - } - - lldb::StreamSP - GetOutStream(); - - bool - GetBatchMode(); - }; - - struct InitializationParameters - { - private: - void* m_baton; - lldb::InputReaderGranularity m_token_size; - char* m_end_token; - char* m_prompt; - bool m_echo; - bool m_save_user_input; - public: - InitializationParameters() : - m_baton(NULL), - m_token_size(lldb::eInputReaderGranularityLine), - m_echo(true), - m_save_user_input(false) - { - SetEndToken("DONE"); - SetPrompt("> "); - } - - InitializationParameters& - SetEcho(bool e) - { - m_echo = e; - return *this; - } - - InitializationParameters& - SetSaveUserInput(bool s) - { - m_save_user_input = s; - return *this; - } - - InitializationParameters& - SetBaton(void* b) - { - m_baton = b; - return *this; - } - - InitializationParameters& - SetGranularity(lldb::InputReaderGranularity g) - { - m_token_size = g; - return *this; - } - - InitializationParameters& - SetEndToken(const char* e) - { - m_end_token = new char[strlen(e)+1]; - ::strcpy(m_end_token,e); - return *this; - } - - InitializationParameters& - SetPrompt(const char* p) - { - m_prompt = new char[strlen(p)+1]; - ::strcpy(m_prompt,p); - return *this; - } - - friend class InputReaderEZ; - - }; - - InputReader (Debugger &debugger); - - virtual - ~InputReader (); - - virtual Error - Initialize (Callback callback, - void *baton, - lldb::InputReaderGranularity token_size, - const char *end_token, - const char *prompt, - bool echo); - - virtual Error Initialize(void* baton, - lldb::InputReaderGranularity token_size = lldb::eInputReaderGranularityLine, - const char* end_token = "DONE", - const char *prompt = "> ", - bool echo = true) - { - return Error("unimplemented"); - } - - virtual Error - Initialize(InitializationParameters& params) - { - return Error("unimplemented"); - } - - // to use these handlers instead of the Callback function, you must subclass - // InputReaderEZ, and redefine the handlers for the events you care about - virtual void - ActivateHandler(HandlerData&) {} - - virtual void - DeactivateHandler(HandlerData&) {} - - virtual void - ReactivateHandler(HandlerData&) {} - - virtual void - AsynchronousOutputWrittenHandler(HandlerData&) {} - - virtual void - GotTokenHandler(HandlerData&) {} - - virtual void - InterruptHandler(HandlerData&) {} - - virtual void - EOFHandler(HandlerData&) {} - - virtual void - DoneHandler(HandlerData&) {} - - bool - IsDone () const - { - return m_done; - } - - void - SetIsDone (bool b) - { - m_done = b; - } - - lldb::InputReaderGranularity - GetGranularity () const - { - return m_granularity; - } - - bool - GetEcho () const - { - return m_echo; - } - - StringList& - GetUserInput() - { - return m_user_input; - } - - virtual bool - GetSaveUserInput() - { - return false; - } - - // Subclasses _can_ override this function to get input as it comes in - // without any granularity - virtual size_t - HandleRawBytes (const char *bytes, size_t bytes_len); - - Debugger & - GetDebugger() - { - return m_debugger; - } - - bool - IsActive () const - { - return m_active; - } - - const char * - GetPrompt () const; - - void - RefreshPrompt(); - - // If you want to read from an input reader synchronously, then just initialize the - // reader and then call WaitOnReaderIsDone, which will return when the reader is popped. - void - WaitOnReaderIsDone (); - - static const char * - GranularityAsCString (lldb::InputReaderGranularity granularity); - -protected: - friend class Debugger; - - void - Notify (lldb::InputReaderAction notification); - - Debugger &m_debugger; - Callback m_callback; - void *m_callback_baton; - std::string m_end_token; - std::string m_prompt; - lldb::InputReaderGranularity m_granularity; - bool m_done; - bool m_echo; - bool m_active; - Predicate<bool> m_reader_done; - StringList m_user_input; - bool m_save_user_input; - -private: - DISALLOW_COPY_AND_ASSIGN (InputReader); - -}; - -} // namespace lldb_private - -#endif // #ifndef liblldb_InputReader_h_ diff --git a/include/lldb/Core/InputReaderEZ.h b/include/lldb/Core/InputReaderEZ.h deleted file mode 100644 index 85561b6f0a9e..000000000000 --- a/include/lldb/Core/InputReaderEZ.h +++ /dev/null @@ -1,87 +0,0 @@ -//===-- InputReaderEZ.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_InputReaderEZ_h_ -#define liblldb_InputReaderEZ_h_ - -#include "lldb/Core/InputReader.h" - -namespace lldb_private { - -class InputReaderEZ : public InputReader -{ - -private: - - static size_t Callback_Impl(void *baton, - InputReader &reader, - lldb::InputReaderAction notification, - const char *bytes, - size_t bytes_len); -public: - - InputReaderEZ (Debugger &debugger) : - InputReader(debugger) - {} - - virtual - ~InputReaderEZ (); - - using InputReader::Initialize; - virtual Error - Initialize(void* baton, - lldb::InputReaderGranularity token_size = lldb::eInputReaderGranularityLine, - const char* end_token = "DONE", - const char *prompt = "> ", - bool echo = true); - - virtual Error - Initialize(InitializationParameters& params); - - virtual void - ActivateHandler(HandlerData&) {} - - virtual void - DeactivateHandler(HandlerData&) {} - - virtual void - ReactivateHandler(HandlerData&) {} - - virtual void - AsynchronousOutputWrittenHandler(HandlerData&) {} - - virtual void - GotTokenHandler(HandlerData&) {} - - virtual void - InterruptHandler(HandlerData&) {} - - virtual void - EOFHandler(HandlerData&) {} - - virtual void - DoneHandler(HandlerData&) {} - - virtual bool - GetSaveUserInput() - { - return m_save_user_input; - } - -protected: - friend class Debugger; - -private: - DISALLOW_COPY_AND_ASSIGN (InputReaderEZ); - -}; - -} // namespace lldb_private - -#endif // #ifndef liblldb_InputReaderEZ_h_ diff --git a/include/lldb/Core/InputReaderStack.h b/include/lldb/Core/InputReaderStack.h deleted file mode 100644 index a73b97cad571..000000000000 --- a/include/lldb/Core/InputReaderStack.h +++ /dev/null @@ -1,58 +0,0 @@ -//===-- InputReaderStack.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_InputReaderStack_h_ -#define liblldb_InputReaderStack_h_ - -#include <stack> - -#include "lldb/lldb-private.h" -#include "lldb/Host/Mutex.h" - -namespace lldb_private { - -class InputReaderStack -{ -public: - - InputReaderStack (); - - ~InputReaderStack (); - - size_t - GetSize () const; - - void - Push (const lldb::InputReaderSP& reader_sp); - - bool - IsEmpty () const; - - lldb::InputReaderSP - Top (); - - void - Pop (); - - Mutex & - GetStackMutex (); - -protected: - - std::stack<lldb::InputReaderSP> m_input_readers; - mutable Mutex m_input_readers_mutex; - -private: - - DISALLOW_COPY_AND_ASSIGN (InputReaderStack); -}; - -} // namespace lldb_private - -#endif // liblldb_InputReaderStack_h_ diff --git a/include/lldb/Core/MappedHash.h b/include/lldb/Core/MappedHash.h index 80d249d4cc9e..4b77ff1ab8fc 100644 --- a/include/lldb/Core/MappedHash.h +++ b/include/lldb/Core/MappedHash.h @@ -382,9 +382,9 @@ public: lldb::offset_t offset = m_header.Read (data, 0); if (offset != LLDB_INVALID_OFFSET && IsValid ()) { - m_hash_indexes = (uint32_t *)data.GetData (&offset, m_header.bucket_count * sizeof(uint32_t)); - m_hash_values = (uint32_t *)data.GetData (&offset, m_header.hashes_count * sizeof(uint32_t)); - m_hash_offsets = (uint32_t *)data.GetData (&offset, m_header.hashes_count * sizeof(uint32_t)); + m_hash_indexes = (const uint32_t *)data.GetData (&offset, m_header.bucket_count * sizeof(uint32_t)); + m_hash_values = (const uint32_t *)data.GetData (&offset, m_header.hashes_count * sizeof(uint32_t)); + m_hash_offsets = (const uint32_t *)data.GetData (&offset, m_header.hashes_count * sizeof(uint32_t)); } } @@ -542,9 +542,9 @@ public: protected: // Implementation agnostic information HeaderType m_header; - uint32_t *m_hash_indexes; - uint32_t *m_hash_values; - uint32_t *m_hash_offsets; + const uint32_t *m_hash_indexes; + const uint32_t *m_hash_values; + const uint32_t *m_hash_offsets; }; }; diff --git a/include/lldb/Core/Module.h b/include/lldb/Core/Module.h index cae5a30be704..56650582791b 100644 --- a/include/lldb/Core/Module.h +++ b/include/lldb/Core/Module.h @@ -113,10 +113,18 @@ public: /// @param[in] target /// The target in which to apply the section load addresses. /// - /// @param[in] offset - /// The offset to apply to all file addresses for all top - /// level sections in the object file as each section load - /// address is being set. + /// @param[in] value + /// if \a value_is_offset is true, then value is the offset to + /// apply to all file addresses for all top level sections in + /// the object file as each section load address is being set. + /// If \a value_is_offset is false, then "value" is the new + /// absolute base address for the image. + /// + /// @param[in] value_is_offset + /// If \b true, then \a value is an offset to apply to each + /// file address of each top level section. + /// If \b false, then \a value is the image base address that + /// will be used to rigidly slide all loadable sections. /// /// @param[out] changed /// If any section load addresses were changed in \a target, @@ -133,7 +141,8 @@ public: //------------------------------------------------------------------ bool SetLoadAddress (Target &target, - lldb::addr_t offset, + lldb::addr_t value, + bool value_is_offset, bool &changed); //------------------------------------------------------------------ diff --git a/include/lldb/Core/Opcode.h b/include/lldb/Core/Opcode.h index fd80231a44e7..57b8077477ce 100644 --- a/include/lldb/Core/Opcode.h +++ b/include/lldb/Core/Opcode.h @@ -15,7 +15,9 @@ // C++ Includes // Other libraries and framework includes +#include "llvm/Support/MathExtras.h" // Project includes +#include "lldb/Host/Endian.h" #include "lldb/lldb-public.h" namespace lldb @@ -39,31 +41,31 @@ namespace lldb_private { eTypeBytes }; - Opcode () : m_type (eTypeInvalid) + Opcode () : m_byte_order (lldb::eByteOrderInvalid), m_type (eTypeInvalid) { } - Opcode (uint8_t inst) : m_type (eType8) + Opcode (uint8_t inst, lldb::ByteOrder order) : m_byte_order (order), m_type (eType8) { m_data.inst8 = inst; } - Opcode (uint16_t inst) : m_type (eType16) + Opcode (uint16_t inst, lldb::ByteOrder order) : m_byte_order (order), m_type (eType16) { m_data.inst16 = inst; } - Opcode (uint32_t inst) : m_type (eType32) + Opcode (uint32_t inst, lldb::ByteOrder order) : m_byte_order (order), m_type (eType32) { m_data.inst32 = inst; } - Opcode (uint64_t inst) : m_type (eType64) + Opcode (uint64_t inst, lldb::ByteOrder order) : m_byte_order (order), m_type (eType64) { m_data.inst64 = inst; } - Opcode (uint8_t *bytes, size_t length) + Opcode (uint8_t *bytes, size_t length) : m_byte_order (lldb::eByteOrderInvalid) { SetOpcodeBytes (bytes, length); } @@ -71,6 +73,7 @@ namespace lldb_private { void Clear() { + m_byte_order = lldb::eByteOrderInvalid; m_type = Opcode::eTypeInvalid; } Opcode::Type @@ -102,7 +105,7 @@ namespace lldb_private { { case Opcode::eTypeInvalid: break; case Opcode::eType8: return m_data.inst8; - case Opcode::eType16: return m_data.inst16; + case Opcode::eType16: return GetEndianSwap() ? llvm::ByteSwap_16(m_data.inst16) : m_data.inst16; case Opcode::eType16_2: break; case Opcode::eType32: break; case Opcode::eType64: break; @@ -118,9 +121,9 @@ namespace lldb_private { { case Opcode::eTypeInvalid: break; case Opcode::eType8: return m_data.inst8; - case Opcode::eType16: return m_data.inst16; + case Opcode::eType16: return GetEndianSwap() ? llvm::ByteSwap_16(m_data.inst16) : m_data.inst16; case Opcode::eType16_2: // passthrough - case Opcode::eType32: return m_data.inst32; + case Opcode::eType32: return GetEndianSwap() ? llvm::ByteSwap_32(m_data.inst32) : m_data.inst32; case Opcode::eType64: break; case Opcode::eTypeBytes: break; } @@ -134,48 +137,53 @@ namespace lldb_private { { case Opcode::eTypeInvalid: break; case Opcode::eType8: return m_data.inst8; - case Opcode::eType16: return m_data.inst16; + case Opcode::eType16: return GetEndianSwap() ? llvm::ByteSwap_16(m_data.inst16) : m_data.inst16; case Opcode::eType16_2: // passthrough - case Opcode::eType32: return m_data.inst32; - case Opcode::eType64: return m_data.inst64; + case Opcode::eType32: return GetEndianSwap() ? llvm::ByteSwap_32(m_data.inst32) : m_data.inst32; + case Opcode::eType64: return GetEndianSwap() ? llvm::ByteSwap_64(m_data.inst64) : m_data.inst64; case Opcode::eTypeBytes: break; } return invalid_opcode; } void - SetOpcode8 (uint8_t inst) + SetOpcode8 (uint8_t inst, lldb::ByteOrder order) { m_type = eType8; m_data.inst8 = inst; + m_byte_order = order; } void - SetOpcode16 (uint16_t inst) + SetOpcode16 (uint16_t inst, lldb::ByteOrder order) { m_type = eType16; m_data.inst16 = inst; + m_byte_order = order; } void - SetOpcode16_2 (uint32_t inst) + SetOpcode16_2 (uint32_t inst, lldb::ByteOrder order) { m_type = eType16_2; m_data.inst32 = inst; + m_byte_order = order; } void - SetOpcode32 (uint32_t inst) + SetOpcode32 (uint32_t inst, lldb::ByteOrder order) { m_type = eType32; m_data.inst32 = inst; + m_byte_order = order; } void - SetOpcode64 (uint64_t inst) + SetOpcode64 (uint64_t inst, lldb::ByteOrder order) { m_type = eType64; m_data.inst64 = inst; + m_byte_order = order; } void @@ -187,6 +195,7 @@ namespace lldb_private { m_data.inst.length = length; assert (length < sizeof (m_data.inst.bytes)); memcpy (m_data.inst.bytes, bytes, length); + m_byte_order = lldb::eByteOrderInvalid; } else { @@ -249,6 +258,15 @@ namespace lldb_private { lldb::ByteOrder GetDataByteOrder () const; + bool + GetEndianSwap() const + { + return (m_byte_order == lldb::eByteOrderBig && lldb::endian::InlHostByteOrder() == lldb::eByteOrderLittle) || + (m_byte_order == lldb::eByteOrderLittle && lldb::endian::InlHostByteOrder() == lldb::eByteOrderBig); + } + + lldb::ByteOrder m_byte_order; + Opcode::Type m_type; union { diff --git a/include/lldb/Core/SourceManager.h b/include/lldb/Core/SourceManager.h index b850df774bac..d8c9eccd3477 100644 --- a/include/lldb/Core/SourceManager.h +++ b/include/lldb/Core/SourceManager.h @@ -70,6 +70,15 @@ public: return m_source_map_mod_id; } + const char * + PeekLineData (uint32_t line); + + uint32_t + GetLineLength (uint32_t line, bool include_newline_chars); + + uint32_t + GetNumLines (); + protected: bool @@ -167,11 +176,11 @@ public: uint32_t start_line, uint32_t end_line, std::vector<uint32_t> &match_lines); - -protected: - + FileSP GetFile (const FileSpec &file_spec); + +protected: //------------------------------------------------------------------ // Classes that inherit from SourceManager can see and modify these diff --git a/include/lldb/Core/StreamAsynchronousIO.h b/include/lldb/Core/StreamAsynchronousIO.h index 0e3e9ee9bcf1..a73a9567fe83 100644 --- a/include/lldb/Core/StreamAsynchronousIO.h +++ b/include/lldb/Core/StreamAsynchronousIO.h @@ -13,7 +13,6 @@ #include <string> #include "lldb/Core/Stream.h" -#include "lldb/Core/StreamString.h" namespace lldb_private { @@ -35,7 +34,7 @@ public: private: Broadcaster &m_broadcaster; uint32_t m_broadcast_event_type; - StreamString m_accumulated_data; + std::string m_accumulated_data; }; } // namespace lldb_private diff --git a/include/lldb/Core/StringList.h b/include/lldb/Core/StringList.h index 5503274173cb..b68ab4be2d6d 100644 --- a/include/lldb/Core/StringList.h +++ b/include/lldb/Core/StringList.h @@ -34,6 +34,9 @@ public: AppendString (const std::string &s); void + AppendString (std::string &&s); + + void AppendString (const char *str); void @@ -51,6 +54,34 @@ public: size_t GetSize () const; + void + SetSize (size_t n) + { + m_strings.resize(n); + } + + size_t + GetMaxStringLength () const; + + std::string & + operator [](size_t idx) + { + // No bounds checking, verify "idx" is good prior to calling this function + return m_strings[idx]; + } + + const std::string & + operator [](size_t idx) const + { + // No bounds checking, verify "idx" is good prior to calling this function + return m_strings[idx]; + } + + void + PopBack () + { + m_strings.pop_back(); + } const char * GetStringAtIndex (size_t idx) const; @@ -64,6 +95,12 @@ public: LongestCommonPrefix (std::string &common_prefix); void + InsertStringAtIndex (size_t idx, const std::string &str); + + void + InsertStringAtIndex (size_t idx, std::string &&str); + + void InsertStringAtIndex (size_t id, const char *str); void @@ -73,11 +110,14 @@ public: RemoveBlankLines (); size_t + SplitIntoLines (const std::string &lines); + + size_t SplitIntoLines (const char *lines, size_t len); std::string CopyList(const char* item_preamble = NULL, - const char* items_sep = "\n"); + const char* items_sep = "\n") const; StringList& operator << (const char* str); diff --git a/include/lldb/Core/ValueObject.h b/include/lldb/Core/ValueObject.h index 1ef421676ee1..e2847c778484 100644 --- a/include/lldb/Core/ValueObject.h +++ b/include/lldb/Core/ValueObject.h @@ -499,6 +499,10 @@ public: GetValueAsCString (); virtual bool + GetValueAsCString (const lldb_private::TypeFormatImpl& format, + std::string& destination); + + bool GetValueAsCString (lldb::Format format, std::string& destination); @@ -615,7 +619,8 @@ public: DumpPrintableRepresentation (Stream& s, ValueObjectRepresentationStyle val_obj_display = eValueObjectRepresentationStyleSummary, lldb::Format custom_format = lldb::eFormatInvalid, - PrintableRepresentationSpecialCases special = ePrintableRepresentationSpecialCasesAllow); + PrintableRepresentationSpecialCases special = ePrintableRepresentationSpecialCasesAllow, + bool do_dump_error = true); bool GetValueIsValid () const; diff --git a/include/lldb/Core/ValueObjectList.h b/include/lldb/Core/ValueObjectList.h index 5bfe40b2e952..6565367cc61c 100644 --- a/include/lldb/Core/ValueObjectList.h +++ b/include/lldb/Core/ValueObjectList.h @@ -75,6 +75,12 @@ public: void Swap (ValueObjectList &value_object_list); + void + Clear () + { + m_value_objects.clear(); + } + protected: typedef std::vector<lldb::ValueObjectSP> collection; //------------------------------------------------------------------ |