[prev in list] [next in list] [prev in thread] [next in thread] 

List:       oprofile-commits
Subject:    [oprof-cvs] CVS: oprofile/libutil++ op_bfd.cpp, 1.79, 1.80 op_bfd.h,
From:       hanseld <hanseld () users ! sourceforge ! net>
Date:       2008-04-28 21:23:28
Message-ID: E1Jqaoq-0004Nc-Ns () sc8-pr-cvs3 ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/oprofile/oprofile/libutil++
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15532/libutil++

Modified Files:
	op_bfd.cpp op_bfd.h file_manip.cpp bfd_support.cpp 
	bfd_support.h 
Log Message:
JIT support (for profiling Java applications) added

Index: op_bfd.cpp
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libutil++/op_bfd.cpp,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -p -d -r1.79 -r1.80
--- op_bfd.cpp	18 Mar 2008 02:00:08 -0000	1.79
+++ op_bfd.cpp	28 Apr 2008 21:23:25 -0000	1.80
@@ -95,7 +95,8 @@ op_bfd::op_bfd(string const & fname, str
 	:
 	filename(fname),
 	archive_path(extra_images.get_archive_path()),
-	file_size(-1)
+	file_size(-1),
+	anon_obj(false)
 {
 	int fd;
 	struct stat st;
@@ -104,6 +105,7 @@ op_bfd::op_bfd(string const & fname, str
 	// O(Nē) behavior when we will filter vector element below
 	symbols_found_t symbols;
 	asection const * sect;
+	string suf = ".jo";
 
 	image_error img_ok;
 	string const image_path =
@@ -140,6 +142,12 @@ op_bfd::op_bfd(string const & fname, str
 		goto out_fail;
 	}
 
+	string::size_type pos;
+	pos = filename.rfind(suf);
+	if (pos != string::npos && pos == filename.size() - suf.size())
+		anon_obj = true;
+
+
 	// find .text and use it
 	for (sect = ibfd.abfd->sections; sect; sect = sect->next) {
 		if (sect->flags & SEC_CODE) {
@@ -151,6 +159,9 @@ op_bfd::op_bfd(string const & fname, str
 			}
 
 			filepos_map[sect->name] = sect->filepos;
+
+			if (sect->vma == 0 && strcmp(sect->name, ".text"))
+				filtered_section.push_back(sect);
 		}
 	}
 
@@ -182,11 +193,6 @@ unsigned long op_bfd::get_start_offset(b
 		return 0;
 	}
 
-	for (asection * sect = ibfd.abfd->sections; sect; sect = sect->next) {
-		if (sect->vma == vma)
-			return sect->filepos;
-	}
-
 	return 0;
 }
 
@@ -205,8 +211,12 @@ void op_bfd::get_symbols(op_bfd::symbols
 
 	size_t i;
 	for (i = 0; i < ibfd.nr_syms; ++i) {
-		if (interesting_symbol(ibfd.syms[i]))
-			symbols.push_back(op_bfd_symbol(ibfd.syms[i]));
+		if (!interesting_symbol(ibfd.syms[i]))
+			continue;
+		if (find(filtered_section.begin(), filtered_section.end(),
+			 ibfd.syms[i]->section) != filtered_section.end())
+			continue;
+		symbols.push_back(op_bfd_symbol(ibfd.syms[i]));
 	}
 
 	for (i = 0; i < dbfd.nr_syms; ++i) {
@@ -347,8 +357,9 @@ bool op_bfd::get_linenr(symbol_index_t s
 		return false;
 
 	bfd_info const & b = dbfd.valid() ? dbfd : ibfd;
+	op_bfd_symbol const & sym = syms[sym_idx];
 
-	linenr_info const info = find_nearest_line(b, syms[sym_idx], offset);
+	linenr_info const info = find_nearest_line(b, sym, offset, anon_obj);
 
 	if (!info.found)
 		return false;
@@ -376,7 +387,10 @@ void op_bfd::get_symbol_range(symbol_ind
 
 	bool const verbose = cverb << (vbfd & vlevel1);
 
-	start = sym.filepos();
+	if (anon_obj)
+		start = sym.vma();
+	else
+		start = sym.filepos();
 	end = start + sym.size();
 
 	if (!verbose)

Index: op_bfd.h
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libutil++/op_bfd.h,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -p -d -r1.48 -r1.49
--- op_bfd.h	18 Mar 2008 02:00:08 -0000	1.48
+++ op_bfd.h	28 Apr 2008 21:23:25 -0000	1.49
@@ -18,6 +18,7 @@
 #include <string>
 #include <list>
 #include <map>
+#include <set>
 
 #include "bfd_support.h"
 #include "utility.h"
@@ -78,8 +79,8 @@ private:
 	bool symb_hidden;
 	/// whether other symbols can override it
 	bool symb_weak;
-        /// symbol is artificially created
-        bool symb_artificial;
+	/// symbol is artificially created
+	bool symb_artificial;
 	/// code bytes corresponding to symbol -- used for XML generation
 	std::string symb_bytes;
 };
@@ -189,6 +190,8 @@ public:
 	bool get_symbol_contents(symbol_index_t sym_index,
 		unsigned char * contents) const;
 
+	bool valid() const { return ibfd.valid(); }
+
 private:
 	/// temporary container type for getting symbols
 	typedef std::list<op_bfd_symbol> symbols_found_t;
@@ -256,6 +259,12 @@ private:
 	// corresponding debug bfd object, if one is found
 	mutable bfd_info dbfd;
 
+	/// sections we will avoid to use symbol from, this is needed
+	/// because elf file allows sections with identical vma and we can't
+	/// allow overlapping symbols. Such elf layout is used actually by
+	/// kernel modules where all code section vma are set to 0.
+	std::vector<asection const *> filtered_section;
+
 	typedef std::map<std::string, u32> filepos_map_t;
 	// mapping of section names to filepos in the original binary
 	filepos_map_t filepos_map;
@@ -265,6 +274,8 @@ private:
 	 * the embedded SPU image.
 	 */
 	std::string embedding_filename;
+
+	bool anon_obj;
 };
 
 

Index: file_manip.cpp
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libutil++/file_manip.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -p -d -r1.37 -r1.38
--- file_manip.cpp	22 Feb 2008 16:17:48 -0000	1.37
+++ file_manip.cpp	28 Apr 2008 21:23:25 -0000	1.38
@@ -12,8 +12,6 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <dirent.h>
-#include <fnmatch.h>
 #include <utime.h>
 #include <limits.h>
 #include <stdlib.h>
@@ -114,49 +112,20 @@ bool op_file_readable(string const & fil
 	return op_file_readable(file.c_str());
 }
 
-inline static bool is_directory_name(char const * name)
+static void get_pathname(const char * pathname, void * name_list)
 {
-	return name[0] == '.' &&
-		(name[1] == '\0' ||
-		 (name[1] == '.' && name[2] == '\0'));
+	list<string> * file_list = (list<string> *)name_list;
+	file_list->push_back(pathname);
 }
 
-
 bool create_file_list(list<string> & file_list, string const & base_dir,
 		      string const & filter, bool recursive)
 {
-	DIR * dir;
-	struct dirent * ent;
-
-	if (!(dir = opendir(base_dir.c_str())))
-		return false;
-
-	while ((ent = readdir(dir)) != 0) {
-		if (!is_directory_name(ent->d_name) &&
-		    fnmatch(filter.c_str(), ent->d_name, 0) != FNM_NOMATCH) {
-			if (recursive) {
-				struct stat stat_buffer;
-				string name = base_dir + '/' + ent->d_name;
-				if (stat(name.c_str(), &stat_buffer) == 0) {
-					if (S_ISDIR(stat_buffer.st_mode) &&
-					    !S_ISLNK(stat_buffer.st_mode)) {
-						// recursive retrieve
-						create_file_list(file_list,
-								 name, filter,
-								 recursive);
-					} else {
-						file_list.push_back(name);
-					}
-				}
-			} else {
-				file_list.push_back(ent->d_name);
-			}
-		}
-	}
-
-	closedir(dir);
-
-	return true;
+	return !get_matching_pathnames(&file_list, get_pathname,
+				       base_dir.c_str(), filter.c_str(),
+				       recursive ? MATCH_ANY_ENTRY_RECURSION :
+				       NO_RECURSION) ? true : false;
+ 
 }
 
 
@@ -178,7 +147,6 @@ static string erase_trailing_path_separa
 	return result;
 }
 
-
 string op_dirname(string const & file_name)
 {
 	string result = erase_trailing_path_separator(file_name);

Index: bfd_support.cpp
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libutil++/bfd_support.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -p -d -r1.7 -r1.8
--- bfd_support.cpp	15 Feb 2008 18:28:19 -0000	1.7
+++ bfd_support.cpp	28 Apr 2008 21:23:25 -0000	1.8
@@ -508,7 +508,7 @@ void bfd_info::get_symbols()
 
 linenr_info const
 find_nearest_line(bfd_info const & b, op_bfd_symbol const & sym,
-                  unsigned int offset)
+                  unsigned int offset, bool anon_obj)
 {
 	char const * function = "";
 	char const * cfilename = "";
@@ -530,7 +530,10 @@ find_nearest_line(bfd_info const & b, op
 	abfd = b.abfd;
 	syms = b.syms.get();
 	section = sym.symbol()->section;
-	pc = (sym.value() + offset) - sym.filepos();
+	if (anon_obj)
+		pc = offset - sym.symbol()->section->vma;
+	else
+		pc = (sym.value() + offset) - sym.filepos();
 
 	if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0)
 		goto fail;

Index: bfd_support.h
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libutil++/bfd_support.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -p -d -r1.4 -r1.5
--- bfd_support.h	31 May 2007 15:33:18 -0000	1.4
+++ bfd_support.h	28 Apr 2008 21:23:25 -0000	1.5
@@ -128,6 +128,6 @@ struct linenr_info {
  */
 linenr_info const
 find_nearest_line(bfd_info const & ibfd, op_bfd_symbol const & sym,
-                  unsigned int offset);
+                  unsigned int offset, bool anon_obj);
 
 #endif /* !BFD_SUPPORT_H */




-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

_______________________________________________
Oprofile-commits mailing list
Oprofile-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oprofile-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic