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

List:       oprofile-commits
Subject:    [oprof-cvs] CVS: oprofile/libutil++ bfd_support.cpp,1.18,1.19
From:       "Maynard Johnson" <maynardj () users ! sourceforge ! net>
Date:       2010-04-14 17:32:24
Message-ID: E1O26Rs-0000ey-Kb () sfp-cvsdas-4 ! v30 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Update of /cvsroot/oprofile/oprofile/libutil++
In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv2458/libutil++

Modified Files:
	bfd_support.cpp 
Log Message:
Fix an opreport error seen on Fedora 12 by making translate_debuginfo_syms more robust

Index: bfd_support.cpp
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libutil++/bfd_support.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -p -d -r1.18 -r1.19
--- bfd_support.cpp	26 Oct 2009 13:01:08 -0000	1.18
+++ bfd_support.cpp	14 Apr 2010 17:32:22 -0000	1.19
@@ -20,7 +20,7 @@
 
 #include <cstdlib>
 #include <cstring>
-
+#include <cassert>
 #include <iostream>
 #include <fstream>
 #include <sstream>
@@ -432,13 +432,28 @@ void bfd_info::close()
 		bfd_close(abfd);
 }
 
+/**
+ * This function is only called when processing symbols retrieved from a
+ * debuginfo file that is separate from the actual runtime binary image.
+ * Separate debuginfo files may be needed in two different cases:
+ *   1) the real image is completely stripped, where there is no symbol
+	information at all
+ *   2) the real image has debuginfo stripped, and the user is requesting "-g"
+ *   (src file/line num info)
+ * After all symbols are gathered up, there will be some filtering/removal of
+ * unnecessary symbols.  In particular, the bfd_info::interesting_symbol()
+ * function filters out symbols whose section's flag value does not include
+ * SEC_LOAD.  This filtering is required, so it must be retained.  However,
+ * we run into a problem with symbols from debuginfo files, since the
+ * section flag does NOT include SEC_LOAD.  To solve this problem, the
+ * translate_debuginfo_syms function maps the debuginfo symbol's sections to
+ * that of their corresponding real image.
+*/
 void bfd_info::translate_debuginfo_syms(asymbol ** dbg_syms, long nr_dbg_syms)
 {
-	bfd_section ** image_sect;
 	unsigned int img_sect_cnt = 0;
 	bfd * image_bfd = image_bfd_info->abfd;
-
-	image_sect = (bfd_section **) malloc(image_bfd->section_count * (sizeof(bfd_section *)));
+	multimap<string, bfd_section *> image_sections;
 
 	for (bfd_section * sect = image_bfd->sections;
 	     sect && img_sect_cnt < image_bfd->section_count;
@@ -446,20 +461,43 @@ void bfd_info::translate_debuginfo_syms(
 		// A comment section marks the end of the needed sections
 		if (strstr(sect->name, ".comment") == sect->name)
 			break;
-		image_sect[sect->index] = sect;
+		image_sections.insert(pair<string, bfd_section *>(sect->name, sect));
 		img_sect_cnt++;
 	}
 
 	asymbol * sym = dbg_syms[0];
+	string prev_sect_name = "";
+	bfd_section * matched_section = NULL;
 	for (int i = 0; i < nr_dbg_syms; sym = dbg_syms[++i]) {
+		bool section_switch;
+
+		if (strcmp(prev_sect_name.c_str(), sym->section->name)) {
+			section_switch = true;
+			prev_sect_name = sym->section->name;
+		} else {
+			section_switch = false;
+		}
 		if (sym->section->owner && sym->section->owner == abfd) {
-			if ((unsigned int)sym->section->index < img_sect_cnt) {
-				sym->section = image_sect[sym->section->index];
+			if (section_switch ) {
+				matched_section = NULL;
+				multimap<string, bfd_section *>::iterator it;
+				pair<multimap<string, bfd_section *>::iterator,
+				     multimap<string, bfd_section *>::iterator> range;
+
+				range = image_sections.equal_range(sym->section->name);
+				for (it = range.first; it != range.second; it++) {
+					if ((*it).second->vma == sym->section->vma) {
+						matched_section = (*it).second;
+						break;
+					}
+				}
+			}
+			if (matched_section) {
+				sym->section = matched_section;
 				sym->the_bfd = image_bfd;
 			}
 		}
 	}
-	free(image_sect);
 }
 
 #if SYNTHESIZE_SYMBOLS


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
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