From: William C. <wc...@us...> - 2004-07-06 20:46:08
|
Update of /cvsroot/oprofile/oprofile/libutil++ In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28032/libutil++ Modified Files: file_manip.cpp file_manip.h op_bfd.cpp op_bfd.h Log Message: Check in oparchive support. Index: file_manip.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libutil++/file_manip.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -p -d -r1.25 -r1.26 --- file_manip.cpp 24 Jan 2004 20:05:15 -0000 1.25 +++ file_manip.cpp 6 Jul 2004 20:45:59 -0000 1.26 @@ -27,6 +27,20 @@ using namespace std; +bool copy_file(string const & source, string const & destination) +{ + struct stat buf; + int status = stat(source.c_str(), &buf); + + if (status == 0) { + /* FIXME: This code should avoid using system() if possible. */ + string copy_command("cp -a -f " + source + " " + destination); + status = system(copy_command.c_str()); + } + return !status; +} + + bool is_directory(string const & dirname) { struct stat st; Index: file_manip.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libutil++/file_manip.h,v retrieving revision 1.22 retrieving revision 1.23 diff -u -p -d -r1.22 -r1.23 --- file_manip.h 11 May 2004 19:01:44 -0000 1.22 +++ file_manip.h 6 Jul 2004 20:45:59 -0000 1.23 @@ -16,6 +16,15 @@ #include <list> +/** + * copy_file - copy a file or subtree + * @param source filename to copy from + * @param destination filename to copy into + * + * return true if copying successful + */ +bool copy_file(std::string const & source, std::string const & destination); + /// return true if dir is an existing directory bool is_directory(std::string const & dirname); Index: op_bfd.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/libutil++/op_bfd.cpp,v retrieving revision 1.51 retrieving revision 1.52 diff -u -p -d -r1.51 -r1.52 --- op_bfd.cpp 11 May 2004 17:19:56 -0000 1.51 +++ op_bfd.cpp 6 Jul 2004 20:45:59 -0000 1.52 @@ -48,6 +48,8 @@ void check_format(string const & file, b } } +} + bfd * open_bfd(string const & file) { @@ -65,6 +67,8 @@ bfd * open_bfd(string const & file) } +namespace { + bfd * fdopen_bfd(string const & file, int fd) { /* bfd keeps its own reference to the filename char *, @@ -212,8 +216,8 @@ op_bfd_symbol::op_bfd_symbol(bfd_vma vma } -op_bfd::op_bfd(string const & fname, string_filter const & symbol_filter, - bool & ok) +op_bfd::op_bfd(string const & archive_path, string const & fname, + string_filter const & symbol_filter, bool & ok) : filename(fname), file_size(-1), @@ -222,6 +226,7 @@ op_bfd::op_bfd(string const & fname, str text_offset(0), debug_info(false) { + string image_path = archive_path + filename; int fd; struct stat st; // after creating all symbol it's convenient for user code to access @@ -234,9 +239,9 @@ op_bfd::op_bfd(string const & fname, str if (!ok) goto out_fail; - fd = open(filename.c_str(), O_RDONLY); + fd = open(image_path.c_str(), O_RDONLY); if (fd == -1) { - cverb << vbfd << "open failed for " << filename << endl; + cverb << vbfd << "open failed for " << image_path << endl; ok = false; goto out_fail; } @@ -249,10 +254,10 @@ op_bfd::op_bfd(string const & fname, str file_size = st.st_size; - ibfd = fdopen_bfd(filename, fd); + ibfd = fdopen_bfd(image_path, fd); if (!ibfd) { - cverb << vbfd << "fdopen_bfd failed for " << filename << endl; + cverb << vbfd << "fdopen_bfd failed for " << image_path << endl; ok = false; goto out_fail; } @@ -277,8 +282,8 @@ op_bfd::op_bfd(string const & fname, str // if no debugging section check to see if there is an .debug file if (!debug_info) { - string global(DEBUGDIR); - string dirname(filename.substr(0, filename.rfind('/'))); + string global(archive_path + DEBUGDIR); + string dirname(image_path.substr(0, image_path.rfind('/'))); if (find_separate_debug_file (ibfd, dirname, global, debug_filename)) { cverb << vbfd Index: op_bfd.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libutil++/op_bfd.h,v retrieving revision 1.30 retrieving revision 1.31 diff -u -p -d -r1.30 -r1.31 --- op_bfd.h 11 May 2004 17:19:57 -0000 1.30 +++ op_bfd.h 6 Jul 2004 20:45:59 -0000 1.31 @@ -86,7 +86,8 @@ public: * open the bfd (because it's not there or whatever). On out, * it's set to false if the bfd couldn't be loaded. */ - op_bfd(std::string const & filename, + op_bfd(std::string const & archive_path, + std::string const & filename, string_filter const & symbol_filter, bool & ok); @@ -145,7 +146,7 @@ public: /** return the text section filepos. */ unsigned long const get_start_offset() const { return text_offset; } - + /// return the image name of the underlying binary image std::string get_filename() const; @@ -256,4 +257,6 @@ find_separate_debug_file(bfd * ibfd, std::string const & dir_in, std::string const & global_in, std::string & filename); + +extern bfd * open_bfd(std::string const & file); #endif /* !OP_BFD_H */ |