[llvm-commits] CVS: llvm/lib/Debugger/ProgramInfo.cpp SourceFile.cpp
Reid Spencer
reid at x10sys.com
Sun Dec 12 18:59:25 PST 2004
Changes in directory llvm/lib/Debugger:
ProgramInfo.cpp updated: 1.6 -> 1.7
SourceFile.cpp updated: 1.2 -> 1.3
---
Log message:
For PR351: http://llvm.cs.uiuc.edu/PR351 : \
* Get file information from a MappedFile instance \
* Convert file type tests to sys::Path form
---
Diffs of the changes: (+17 -49)
Index: llvm/lib/Debugger/ProgramInfo.cpp
diff -u llvm/lib/Debugger/ProgramInfo.cpp:1.6 llvm/lib/Debugger/ProgramInfo.cpp:1.7
--- llvm/lib/Debugger/ProgramInfo.cpp:1.6 Wed Sep 1 17:55:35 2004
+++ llvm/lib/Debugger/ProgramInfo.cpp Sun Dec 12 20:59:15 2004
@@ -170,11 +170,16 @@
SourceFile &SourceFileInfo::getSourceText() const {
// FIXME: this should take into account the source search directories!
- if (SourceText == 0) // Read the file in if we haven't already.
- if (!Directory.empty() && FileOpenable(Directory+"/"+BaseName))
- SourceText = new SourceFile(Directory+"/"+BaseName, Descriptor);
+ if (SourceText == 0) { // Read the file in if we haven't already.
+ sys::Path tmpPath;
+ if (!Directory.empty())
+ tmpPath.setDirectory(Directory);
+ tmpPath.appendFile(BaseName);
+ if (tmpPath.readable())
+ SourceText = new SourceFile(tmpPath.toString(), Descriptor);
else
SourceText = new SourceFile(BaseName, Descriptor);
+ }
return *SourceText;
}
Index: llvm/lib/Debugger/SourceFile.cpp
diff -u llvm/lib/Debugger/SourceFile.cpp:1.2 llvm/lib/Debugger/SourceFile.cpp:1.3
--- llvm/lib/Debugger/SourceFile.cpp:1.2 Wed Sep 1 17:55:35 2004
+++ llvm/lib/Debugger/SourceFile.cpp Sun Dec 12 20:59:15 2004
@@ -20,56 +20,19 @@
#include <unistd.h>
using namespace llvm;
-/// readFile - Load Filename into FileStart and FileEnd.
+/// readFile - Load Filename
///
void SourceFile::readFile() {
- ssize_t FileSize = getFileSize(Filename);
- if (FileSize != -1) {
- FDHandle FD(open(Filename.c_str(), O_RDONLY));
- if (FD != -1) {
- char *FilePos = new char[FileSize];
- FileStart = FilePos;
-
- // If this takes a long time, inform the user what we are doing.
- SlowOperationInformer SOI("loading source file '" + Filename + "'");
-
- try {
- // Read in the whole buffer.
- unsigned Amount = FileSize;
- while (Amount) {
- unsigned AmountToRead = 512*1024;
- if (Amount < AmountToRead) AmountToRead = Amount;
- ssize_t ReadAmount = read(FD, FilePos, AmountToRead);
- if (ReadAmount < 0 && errno == EINTR)
- continue;
- else if (ReadAmount <= 0) {
- // Couldn't read whole file just free memory and continue.
- throw "Error reading file '" + Filename + "'!";
- }
- Amount -= ReadAmount;
- FilePos += ReadAmount;
-
- SOI.progress(FileSize-Amount, FileSize);
- }
-
- } catch (const std::string &Msg) {
- std::cout << Msg << "\n";
- // If the user cancels the operation, clean up after ourselves.
- delete [] FileStart;
- FileStart = 0;
- return;
- }
-
- FileEnd = FileStart+FileSize;
- }
- }
+ File.map();
}
/// calculateLineOffsets - Compute the LineOffset vector for the current file.
///
void SourceFile::calculateLineOffsets() const {
assert(LineOffset.empty() && "Line offsets already computed!");
- const char *BufPtr = FileStart;
+ const char *BufPtr = File.charBase();
+ const char *FileStart = BufPtr;
+ const char *FileEnd = FileStart + File.size();
do {
LineOffset.push_back(BufPtr-FileStart);
@@ -93,19 +56,19 @@
void SourceFile::getSourceLine(unsigned LineNo, const char *&LineStart,
const char *&LineEnd) const {
LineStart = LineEnd = 0;
- if (FileStart == 0) return; // Couldn't load file, return null pointers
+ if (!File.isMapped()) return; // Couldn't load file, return null pointers
if (LineOffset.empty()) calculateLineOffsets();
// Asking for an out-of-range line number?
if (LineNo >= LineOffset.size()) return;
// Otherwise, they are asking for a valid line, which we can fulfill.
- LineStart = FileStart+LineOffset[LineNo];
+ LineStart = File.charBase()+LineOffset[LineNo];
if (LineNo+1 < LineOffset.size())
- LineEnd = FileStart+LineOffset[LineNo+1];
+ LineEnd = File.charBase()+LineOffset[LineNo+1];
else
- LineEnd = FileEnd;
+ LineEnd = File.charBase() + File.size();
// If the line ended with a newline, strip it off.
while (LineEnd != LineStart && (LineEnd[-1] == '\n' || LineEnd[-1] == '\r'))
More information about the llvm-commits
mailing list