am 0c328eae: Merge "Point to gcc 4.6"

* commit '0c328eae6ea431cc7014502403830ae2b5bc1210':
  Point to gcc 4.6
diff --git a/opcontrol/opcontrol.cpp b/opcontrol/opcontrol.cpp
index 075ade6..6b440e2 100644
--- a/opcontrol/opcontrol.cpp
+++ b/opcontrol/opcontrol.cpp
@@ -342,10 +342,32 @@
     }
 }
 
+int read_num(const char* file)
+{
+    char buffer[256];
+    int fd = open(file, O_RDONLY);
+    if (fd<0) return -1;
+    int rd = read(fd, buffer, sizeof(buffer)-1);
+    buffer[rd] = 0;
+    close(fd);
+    return atoi(buffer);
+}
+
 int do_setup()
 {
     char dir[1024];
 
+    /*
+     * Kill the old daemon so that setup can be done more than once to achieve
+     * the same effect as reset.
+     */
+    int num = read_num(OP_DATA_DIR"/lock");
+    if (num >= 0) {
+        printf("Terminating the old daemon...\n");
+        kill(num, SIGTERM);
+        sleep(5);
+    }
+
     setup_session_dir();
 
     if (mkdir(OP_DRIVER_BASE, 0755)) {
@@ -471,16 +493,6 @@
     return 0;
 }
 
-int read_num(const char* file)
-{
-    char buffer[256];
-    int fd = open(file, O_RDONLY);
-    if (fd<0) return -1;
-    int rd = read(fd, buffer, sizeof(buffer)-1);
-    buffer[rd] = 0;
-    return atoi(buffer);
-}
-
 void do_status()
 {
     int num;
@@ -517,7 +529,7 @@
         sprintf(fullname, "/proc/%d", num);
         fd = open(fullname, O_RDONLY);
         if (fd == -1) {
-            printf("Session directory is not clean - do \"opcontrol --setup\""
+            printf("OProfile daemon exited prematurely - redo setup"
                    " before you continue\n");
             return;
         }
@@ -561,11 +573,8 @@
                 closedir(dir);
             }
 
-#if defined(__i386__) || defined(__x86_64__)
-            /* FIXME on ARM - backtrace seems broken there */
             num = read_num(OP_DRIVER_BASE"/backtrace_depth");
-            printf("  %9u backtrace_depth\n", num);
-#endif
+            printf("backtrace_depth: %u\n", num);
         }
     }
     else {
@@ -575,6 +584,20 @@
 
 void do_reset() 
 {
+    /*
+     * Sending SIGHUP will result in the following crash in oprofiled when
+     * profiling subsequent runs:
+     * Stack Trace:
+     * RELADDR   FUNCTION                         FILE:LINE
+     *   00008cd8  add_node+12                    oprofilelibdb/db_insert.c:32
+     *   00008d69  odb_update_node_with_offset+60 oprofilelibdb/db_insert.c:102
+     *
+     * However without sending SIGHUP oprofile cannot be restarted successfully.
+     * As a temporary workaround, change do_reset into a no-op for now and kill
+     * the old daemon in do_setup to start all over again as a heavy-weight
+     * reset.
+     */
+#if 0
     int fd;
 
     fd = open(OP_DATA_DIR"/samples/current", O_RDONLY);
@@ -583,6 +606,13 @@
     }
     close(fd);
     system("rm -r "OP_DATA_DIR"/samples/current");
+    int num = read_num(OP_DATA_DIR"/lock");
+
+    if (num >= 0) {
+        printf("Signalling daemon...\n");
+        kill(num, SIGHUP);
+    }
+#endif
 }
 
 int main(int argc, char * const argv[])
@@ -630,10 +660,6 @@
             /* --dump */ {
                 int pid = read_num(OP_DATA_DIR"/lock");
                 echo_dev("1", 0, "dump", -1);
-                if (pid >= 0) {
-                    sleep(1);
-                    kill(pid, SIGHUP);
-                }
                 break;
             }
             /* --shutdown */
@@ -824,6 +850,11 @@
 
     if (start) {
         echo_dev("1", 0, "enable", -1);
+        int num = read_num(OP_DATA_DIR"/lock");
+
+        if (num >= 0) {
+            kill(num, SIGUSR1);
+        }
     }
 
     if (stop) {
diff --git a/oprofile_android b/oprofile_android
index 8527499..efdadde 100755
--- a/oprofile_android
+++ b/oprofile_android
@@ -40,6 +40,7 @@
 
 opimport_bin = os.path.join(oprofile_bin_dir, 'opimport')
 opreport_bin = os.path.join(oprofile_bin_dir, 'opreport')
+opannotate_bin = os.path.join(oprofile_bin_dir, 'opannotate')
 
 
 # Find symbol directories
@@ -136,6 +137,11 @@
     print "      -c, --callgraph         : show callgraph"
     print "      --help                  : show help for additional opreport options"
     print
+    print "    annotate [args]       : generate annotation with specified arguments to 'annotation'"
+    print "      -s, --source            : show source"
+    print "      -a, --assembly          : show assembly"
+    print "      --help                  : show help for additional opannotate options"
+    print
 
   def main(self):
     rc = self.do_main()
@@ -187,6 +193,8 @@
       rc = self.do_import(command_args)
     elif command == 'report':
       rc = self.do_report(command_args)
+    elif command == 'annotate':
+      rc = self.do_annotate(command_args)
     else:
       print '* Unknown command: ' + command
       return 2
@@ -230,10 +238,6 @@
       print '* --timer and --event cannot be used together.'
       return 2
 
-    if timer and callgraph is not None:
-      print '* --callgraph cannot be used with --timer.'
-      return 2
-
     opcontrol_args = events
     if timer:
       opcontrol_args.append('--timer')
@@ -415,6 +419,13 @@
       return 1
     return 0
 
+  def do_annotate(self, command_args):
+    rc, output = self._execute_opannotate(command_args)
+    if rc != 0:
+      print '* Failed to generate annotation.'
+      return 1
+    return 0
+
   def _opcontrol_verbose_arg(self):
     if self.verbose:
       return ['--verbose']
@@ -426,6 +437,33 @@
       '--session-dir=' + self.session_dir,
       '--image-path=' + symbols_dir + ',' + system_dir] + args)
 
+  def _execute_opannotate(self, command_args):
+    try:
+      opts, args = getopt.getopt(command_args, 'sap:',
+                                 ['source', 'assembly', 'help', 'image-path='])
+    except getopt.GetoptError, e:
+      print '* Unsupported opannotate command arguments:', str(e)
+      return 2
+
+    # Start with the default symbols directory
+    symbols_dirs = symbols_dir
+
+    anno_flag = []
+    for o, a in opts:
+      if o in ('-s', '--source'):
+        anno_flag.append('-s')
+      if o in ('-a', '--assembly'):
+        anno_flag.append('-a')
+        anno_flag.append('--objdump-params=-Cd')
+      if o in ('--help'):
+        anno_flag.append('--help')
+      if o in ('p', '--image-path'):
+        symbols_dirs = a + ',' + symbols_dir
+
+    return execute([opannotate_bin,
+      '--session-dir=' + self.session_dir,
+      '--image-path=' + symbols_dirs + ',' + system_dir] + anno_flag + args)
+
 # Main entry point
 tool = Tool(sys.argv)
 rc = tool.main()
diff --git a/pp/opannotate.cpp b/pp/opannotate.cpp
index 5c224aa..8df841b 100644
--- a/pp/opannotate.cpp
+++ b/pp/opannotate.cpp
@@ -417,7 +417,11 @@
 	}
 
 	args.push_back(image_name);
+#if defined(ANDROID)
+	child_reader reader("arm-eabi-objdump", args);
+#else
 	child_reader reader("objdump", args);
+#endif
 	if (reader.error()) {
 		cerr << "An error occur during the execution of objdump:\n\n";
 		cerr << reader.error_str() << endl;