[mono/mono] c4a9aa1f: Add LLDB support to mono_gdb_render_native_backtraces () on POSIX.

"alexrp ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141f06c6acc-67aaf783-aeab-4e04-9f7a-bdb71638b4a2-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/12cdbfceb768...c4a9aa1f8c40

   Commit: c4a9aa1f8c40ba37834d711259662c5fa92758ea
   Author: Alex Rønne Petersen <[email protected]> 
     Date: 2013-10-25 16:20:44 GMT
      URL: https://github.com/mono/mono/commit/c4a9aa1f8c40ba37834d711259662c5fa92758ea

Add LLDB support to mono_gdb_render_native_backtraces () on POSIX.

Changed paths:
  M mono/mini/mini-posix.c

Modified: mono/mini/mini-posix.c
===================================================================
@@ -672,24 +672,54 @@
 mono_gdb_render_native_backtraces (pid_t crashed_pid)
 {
 	const char *argv [9];
+	char template [] = "/tmp/mono-lldb-commands.XXXXXX";
 	char buf1 [128];
+	FILE *commands;
+	gboolean using_lldb = FALSE;
 
 	argv [0] = g_find_program_in_path ("gdb");
 	if (argv [0] == NULL) {
-		return;
+		argv [0] = g_find_program_in_path ("lldb");
+		using_lldb = TRUE;
 	}
 
-	argv [1] = "-ex";
-	sprintf (buf1, "attach %ld", (long) crashed_pid);
-	argv [2] = buf1;
-	argv [3] = "--ex";
-	argv [4] = "info threads";
-	argv [5] = "--ex";
-	argv [6] = "thread apply all bt";
-	argv [7] = "--batch";
-	argv [8] = 0;
+	if (argv [0] == NULL)
+		return;
+
+	if (using_lldb) {
+		if (mkstemp (template) == -1)
+			return;
+
+		commands = fopen (template, "w");
+
+		fprintf (commands, "process attach --pid %ld\n", (long) crashed_pid);
+		fprintf (commands, "script lldb.debugger.HandleCommand (\"thread list\")\n");
+		fprintf (commands, "script lldb.debugger.HandleCommand (\"thread backtrace all\")\n");
+		fprintf (commands, "detach\n");
+		fprintf (commands, "quit\n");
+
+		fflush (commands);
+		fclose (commands);
+
+		argv [1] = "--source";
+		argv [2] = template;
+		argv [3] = 0;
+	} else {
+		argv [1] = "-ex";
+		sprintf (buf1, "attach %ld", (long) crashed_pid);
+		argv [2] = buf1;
+		argv [3] = "--ex";
+		argv [4] = "info threads";
+		argv [5] = "--ex";
+		argv [6] = "thread apply all bt";
+		argv [7] = "--batch";
+		argv [8] = 0;
+	}
 
 	execv (argv [0], (char**)argv);
+
+	if (using_lldb)
+		unlink (template);
 }
 #endif
 #endif /* __native_client__ */
_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.