summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/SourceManager.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2014-01-27 23:43:24 +0000
committerGreg Clayton <gclayton@apple.com>2014-01-27 23:43:24 +0000
commit44d937820b451296f80449ac3de296345e80f183 (patch)
tree00d14538eded9f7e8bd075128d6ad5fd5ac1caed /lldb/source/Core/SourceManager.cpp
parentf1cb16e481a60dbac58affcf8c8e423dac3937cb (diff)
downloadbcm5719-llvm-44d937820b451296f80449ac3de296345e80f183.tar.gz
bcm5719-llvm-44d937820b451296f80449ac3de296345e80f183.zip
Merging the iohandler branch back into main.
The many many benefits include: 1 - Input/Output/Error streams are now handled as real streams not a push style input 2 - auto completion in python embedded interpreter 3 - multi-line input for "script" and "expression" commands now allow you to edit previous/next lines using up and down arrow keys and this makes multi-line input actually a viable thing to use 4 - it is now possible to use curses to drive LLDB (please try the "gui" command) We will need to deal with and fix any buildbot failures and tests and arise now that input/output and error are correctly hooked up in all cases. llvm-svn: 200263
Diffstat (limited to 'lldb/source/Core/SourceManager.cpp')
-rw-r--r--lldb/source/Core/SourceManager.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp
index 940034625c0..0a6a80401d8 100644
--- a/lldb/source/Core/SourceManager.cpp
+++ b/lldb/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)
{
OpenPOWER on IntegriCloud