diff options
author | Ian Lance Taylor <iant@google.com> | 2007-09-25 00:27:29 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2007-09-25 00:27:29 +0000 |
commit | ba45d2478b259454e5b4c2d7dcaa7a35ecbf329c (patch) | |
tree | e9d069c39988c400a7f41583978372080b661a92 | |
parent | 5f67a19ce6e7ddd10473df8e2754d9d229c884fe (diff) | |
download | gdb-ba45d2478b259454e5b4c2d7dcaa7a35ecbf329c.zip gdb-ba45d2478b259454e5b4c2d7dcaa7a35ecbf329c.tar.gz gdb-ba45d2478b259454e5b4c2d7dcaa7a35ecbf329c.tar.bz2 |
Break out default pbytes argument to read and get_view routines,
adding new routines.
-rw-r--r-- | gold/archive.cc | 10 | ||||
-rw-r--r-- | gold/archive.h | 8 | ||||
-rw-r--r-- | gold/fileread.cc | 33 | ||||
-rw-r--r-- | gold/fileread.h | 39 | ||||
-rw-r--r-- | gold/readsyms.cc | 3 | ||||
-rw-r--r-- | gold/script.cc | 2 |
6 files changed, 69 insertions, 26 deletions
diff --git a/gold/archive.cc b/gold/archive.cc index ef6ff74..f7194f8 100644 --- a/gold/archive.cc +++ b/gold/archive.cc @@ -329,8 +329,9 @@ Archive::include_all_members(Symbol_table* symtab, Layout* layout, while (true) { off_t bytes; - const unsigned char* p = this->get_view(off, sizeof(Archive_header), - &bytes); + const unsigned char* p = this->get_view_and_size(off, + sizeof(Archive_header), + &bytes); if (bytes < sizeof(Archive_header)) { if (bytes != 0) @@ -379,9 +380,8 @@ Archive::include_member(Symbol_table* symtab, Layout* layout, // Read enough of the file to pick up the entire ELF header. int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size; off_t bytes; - const unsigned char* p = this->input_file_->file().get_view(memoff, - ehdr_size, - &bytes); + const unsigned char* p = + this->input_file_->file().get_view_and_size(memoff, ehdr_size, &bytes); if (bytes < 4) { fprintf(stderr, _("%s: %s: member at %ld is not an ELF object"), diff --git a/gold/archive.h b/gold/archive.h index 8c35d22..7fa1d11 100644 --- a/gold/archive.h +++ b/gold/archive.h @@ -98,8 +98,12 @@ class Archive // Get a view into the underlying file. const unsigned char* - get_view(off_t start, off_t size, off_t* pbytes = NULL) - { return this->input_file_->file().get_view(start, size, pbytes); } + get_view(off_t start, off_t size) + { return this->input_file_->file().get_view(start, size); } + + const unsigned char* + get_view_and_size(off_t start, off_t size, off_t* pbytes) + { return this->input_file_->file().get_view_and_size(start, size, pbytes); } // Read the archive symbol map. void diff --git a/gold/fileread.cc b/gold/fileread.cc index 8fad789..a39d530 100644 --- a/gold/fileread.cc +++ b/gold/fileread.cc @@ -202,8 +202,25 @@ File_read::do_read(off_t start, off_t size, void* p, off_t* pbytes) return bytes; } +// Read data from the file. + void -File_read::read(off_t start, off_t size, void* p, off_t* pbytes) +File_read::read(off_t start, off_t size, void* p) +{ + gold_assert(this->lock_count_ > 0); + + File_read::View* pv = this->find_view(start, size); + if (pv != NULL) + { + memcpy(p, pv->data() + (start - pv->start()), size); + return; + } + + this->do_read(start, size, p, NULL); +} + +void +File_read::read_up_to(off_t start, off_t size, void* p, off_t* pbytes) { gold_assert(this->lock_count_ > 0); @@ -286,7 +303,15 @@ File_read::find_or_make_view(off_t start, off_t size, off_t* pbytes) // mmap. const unsigned char* -File_read::get_view(off_t start, off_t size, off_t* pbytes) +File_read::get_view(off_t start, off_t size) +{ + gold_assert(this->lock_count_ > 0); + File_read::View* pv = this->find_or_make_view(start, size, NULL); + return pv->data() + (start - pv->start()); +} + +const unsigned char* +File_read::get_view_and_size(off_t start, off_t size, off_t* pbytes) { gold_assert(this->lock_count_ > 0); File_read::View* pv = this->find_or_make_view(start, size, pbytes); @@ -294,10 +319,10 @@ File_read::get_view(off_t start, off_t size, off_t* pbytes) } File_view* -File_read::get_lasting_view(off_t start, off_t size, off_t* pbytes) +File_read::get_lasting_view(off_t start, off_t size) { gold_assert(this->lock_count_ > 0); - File_read::View* pv = this->find_or_make_view(start, size, pbytes); + File_read::View* pv = this->find_or_make_view(start, size, NULL); pv->lock(); return new File_view(*this, pv, pv->data() + (start - pv->start())); } diff --git a/gold/fileread.h b/gold/fileread.h index b2bb468..a77721d 100644 --- a/gold/fileread.h +++ b/gold/fileread.h @@ -80,24 +80,37 @@ class File_read bool is_locked(); - // Return a view into the file. The pointer will remain valid until - // the File_read is unlocked. If PBYTES is NULL, it is an error if - // we can not read enough data. Otherwise *PBYTES is set to the - // number of bytes read. + // Return a view into the file starting at file offset START for + // SIZE bytes. The pointer will remain valid until the File_read is + // unlocked. It is an error if we can not read enough data from the + // file. const unsigned char* - get_view(off_t start, off_t size, off_t* pbytes = NULL); + get_view(off_t start, off_t size); - // Read data from the file into the buffer P. PBYTES is as in - // get_view. + // Return a view into the file starting at file offset START, for up + // to SIZE bytes. Set *PBYTES to the number of bytes read. This + // may be less than SIZE. The pointer will remain valid until the + // File_read is unlocked. + const unsigned char* + get_view_and_size(off_t start, off_t size, off_t* pbytes); + + // Read data from the file into the buffer P starting at file offset + // START for SIZE bytes. + void + read(off_t start, off_t size, void* p); + + // Read up to SIZE bytes from the file into the buffer P starting at + // file offset START. Set *PBYTES to the number of bytes read. void - read(off_t start, off_t size, void* p, off_t* pbytes = NULL); + read_up_to(off_t start, off_t size, void* p, off_t* pbytes); - // Return a lasting view into the file. This is allocated with new, - // and the caller is responsible for deleting it when done. The - // data associated with this view will remain valid until the view - // is deleted. PBYTES is handled as with get_view. + // Return a lasting view into the file starting at file offset START + // for SIZE bytes. This is allocated with new, and the caller is + // responsible for deleting it when done. The data associated with + // this view will remain valid until the view is deleted. It is an + // error if we can not read enough data from the file. File_view* - get_lasting_view(off_t start, off_t size, off_t *pbytes = NULL); + get_lasting_view(off_t start, off_t size); private: // This class may not be copied. diff --git a/gold/readsyms.cc b/gold/readsyms.cc index 0e406fd..58e3385 100644 --- a/gold/readsyms.cc +++ b/gold/readsyms.cc @@ -88,7 +88,8 @@ Read_symbols::run(Workqueue* workqueue) int ehdr_size = elfcpp::Elf_sizes<64>::ehdr_size; off_t bytes; - const unsigned char* p = input_file->file().get_view(0, ehdr_size, &bytes); + const unsigned char* p = input_file->file().get_view_and_size(0, ehdr_size, + &bytes); if (bytes >= 4) { static unsigned char elfmagic[4] = diff --git a/gold/script.cc b/gold/script.cc index 582f6b7..53cd493 100644 --- a/gold/script.cc +++ b/gold/script.cc @@ -305,7 +305,7 @@ Lex::read_file(std::string* contents) unsigned char buf[BUFSIZ]; do { - this->input_file_->file().read(off, sizeof buf, buf, &got); + this->input_file_->file().read_up_to(off, sizeof buf, buf, &got); contents->append(reinterpret_cast<char*>(&buf[0]), got); off += got; } |