7f7d26
--- crash-trace-command-2.0/trace.c.orig
7f7d26
+++ crash-trace-command-2.0/trace.c
7f7d26
@@ -34,6 +34,10 @@ static int encapsulated_current_trace;
7f7d26
  * trace_buffer is supported
7f7d26
  */
7f7d26
 static int trace_buffer_available;
7f7d26
+/*
7f7d26
+ * max_buffer is supported
7f7d26
+ */
7f7d26
+static int max_buffer_available;
7f7d26
 
7f7d26
 #define koffset(struct, member) struct##_##member##_offset
7f7d26
 
7f7d26
@@ -154,6 +158,7 @@ static int init_offsets(void)
7f7d26
 		if (koffset(struct, member) < 0) {			\
7f7d26
 			fprintf(fp, "failed to init the offset, struct:"\
7f7d26
 				#struct ", member:" #member);		\
7f7d26
+			fprintf(fp, "\n");				\
7f7d26
 			return -1;					\
7f7d26
 		}							\
7f7d26
 	} while (0)
7f7d26
@@ -163,8 +168,10 @@ static int init_offsets(void)
7f7d26
 
7f7d26
 	if (trace_buffer_available) {
7f7d26
 		init_offset(trace_array, trace_buffer);
7f7d26
-		init_offset(trace_array, max_buffer);
7f7d26
 		init_offset(trace_buffer, buffer);
7f7d26
+
7f7d26
+		if (max_buffer_available)
7f7d26
+			init_offset(trace_array, max_buffer);
7f7d26
 	} else {
7f7d26
 		init_offset(trace_array, buffer);
7f7d26
 	}
7f7d26
@@ -176,6 +183,9 @@ static int init_offsets(void)
7f7d26
 			fprintf(fp, "per cpu buffer sizes\n");
7f7d26
 	}
7f7d26
 
7f7d26
+	if (kernel_symbol_exists("ring_buffer_read"))
7f7d26
+		gdb_set_crash_scope(symbol_value("ring_buffer_read"), "ring_buffer_read");
7f7d26
+
7f7d26
 	if (!per_cpu_buffer_sizes)
7f7d26
 		init_offset(ring_buffer, pages);
7f7d26
 	init_offset(ring_buffer, flags);
7f7d26
@@ -205,7 +215,12 @@ static int init_offsets(void)
7f7d26
 
7f7d26
 	init_offset(list_head, next);
7f7d26
 
7f7d26
-	init_offset(ftrace_event_call, list);
7f7d26
+	koffset(ftrace_event_call, list) = MAX(MEMBER_OFFSET("ftrace_event_call", "list"), 
7f7d26
+		MEMBER_OFFSET("trace_event_call", "list"));
7f7d26
+	if (koffset(ftrace_event_call, list) < 0) {
7f7d26
+		fprintf(fp, "failed to init the offset, struct:[f]trace_event_call member:list)\n");
7f7d26
+		return -1;					\
7f7d26
+	}
7f7d26
 
7f7d26
 	init_offset(ftrace_event_field, link);
7f7d26
 	init_offset(ftrace_event_field, name);
7f7d26
@@ -448,6 +463,9 @@ out_fail:
7f7d26
 static int ftrace_int_max_tr_trace(void)
7f7d26
 {
7f7d26
 	if (trace_buffer_available) {
7f7d26
+		if (!max_buffer_available)
7f7d26
+			return 0;
7f7d26
+
7f7d26
 		global_max_buffer = global_trace + koffset(trace_array, max_buffer);
7f7d26
 		read_value(max_tr_ring_buffer, global_max_buffer, trace_buffer, buffer);
7f7d26
 	} else {
7f7d26
@@ -528,6 +546,9 @@ static int ftrace_init(void)
7f7d26
 
7f7d26
 	if (MEMBER_EXISTS("trace_array", "trace_buffer")) {
7f7d26
 		trace_buffer_available = 1;
7f7d26
+
7f7d26
+		if (MEMBER_EXISTS("trace_array", "max_buffer"))
7f7d26
+			max_buffer_available = 1;
7f7d26
 	} else {
7f7d26
 		sym_max_tr_trace = symbol_search("max_tr");
7f7d26
 		if (sym_max_tr_trace == NULL)
7f7d26
@@ -710,7 +731,8 @@ static int syscall_get_enter_fields(ulon
7f7d26
 		goto work;
7f7d26
 
7f7d26
 	inited = 1;
7f7d26
-	data_offset = MEMBER_OFFSET("ftrace_event_call", "data");
7f7d26
+	data_offset = MAX(MEMBER_OFFSET("ftrace_event_call", "data"), 
7f7d26
+		MEMBER_OFFSET("trace_event_call", "data"));
7f7d26
 	if (data_offset < 0)
7f7d26
 		return -1;
7f7d26
 
7f7d26
@@ -742,7 +764,8 @@ static int syscall_get_exit_fields_old(u
7f7d26
 		goto work;
7f7d26
 
7f7d26
 	inited = 1;
7f7d26
-	data_offset = MEMBER_OFFSET("ftrace_event_call", "data");
7f7d26
+	data_offset = MAX(MEMBER_OFFSET("ftrace_event_call", "data"),
7f7d26
+		MEMBER_OFFSET("trace_event_call", "data"));
7f7d26
 	if (data_offset < 0)
7f7d26
 		return -1;
7f7d26
 
7f7d26
@@ -803,18 +826,22 @@ int ftrace_get_event_type_fields(ulong c
7f7d26
 		goto work;
7f7d26
 
7f7d26
 	inited = 1;
7f7d26
-	fields_offset = MEMBER_OFFSET("ftrace_event_call", "fields");
7f7d26
+	fields_offset = MAX(MEMBER_OFFSET("ftrace_event_call", "fields"),
7f7d26
+		MEMBER_OFFSET("trace_event_call", "fields"));
7f7d26
 
7f7d26
-	class_offset = MEMBER_OFFSET("ftrace_event_call", "class");
7f7d26
+	class_offset = MAX(MEMBER_OFFSET("ftrace_event_call", "class"),
7f7d26
+		MEMBER_OFFSET("trace_event_call", "class"));
7f7d26
 	if (class_offset < 0)
7f7d26
 		goto work;
7f7d26
 
7f7d26
 	inited = 2;
7f7d26
-	fields_offset = MEMBER_OFFSET("ftrace_event_class", "fields");
7f7d26
+	fields_offset = MAX(MEMBER_OFFSET("ftrace_event_class", "fields"),
7f7d26
+		MEMBER_OFFSET("trace_event_class", "fields"));
7f7d26
 	if (fields_offset < 0)
7f7d26
 		return -1;
7f7d26
 
7f7d26
-	get_fields_offset = MEMBER_OFFSET("ftrace_event_class", "get_fields");
7f7d26
+	get_fields_offset = MAX(MEMBER_OFFSET("ftrace_event_class", "get_fields"),
7f7d26
+		MEMBER_OFFSET("trace_event_class", "get_fields"));
7f7d26
 	if ((sp = symbol_search("syscall_get_enter_fields")) != NULL)
7f7d26
 		syscall_get_enter_fields_value = sp->value;
7f7d26
 	if ((sp = symbol_search("syscall_get_exit_fields")) != NULL)
7f7d26
@@ -988,19 +1015,45 @@ static void ftrace_destroy_event_types(v
7f7d26
 	free(ftrace_common_fields);
7f7d26
 }
7f7d26
 
7f7d26
+#define TRACE_EVENT_FL_TRACEPOINT 0x40
7f7d26
+
7f7d26
 static
7f7d26
 int ftrace_get_event_type_name(ulong call, char *name, int len)
7f7d26
 {
7f7d26
 	static int inited;
7f7d26
 	static int name_offset;
7f7d26
+	static int flags_offset;
7f7d26
+	static int tp_name_offset;
7f7d26
+	uint flags;
7f7d26
 
7f7d26
 	ulong name_addr;
7f7d26
 
7f7d26
-	if (!inited) {
7f7d26
-		inited = 1;
7f7d26
-		name_offset = MEMBER_OFFSET("ftrace_event_call", "name");
7f7d26
-	}
7f7d26
+	if (inited)
7f7d26
+		goto work;
7f7d26
 
7f7d26
+	inited = 1;
7f7d26
+	name_offset = MAX(MEMBER_OFFSET("ftrace_event_call", "name"),
7f7d26
+		MEMBER_OFFSET("trace_event_call", "name"));
7f7d26
+	if (name_offset >= 0)
7f7d26
+		goto work;
7f7d26
+
7f7d26
+	name_offset = MAX(ANON_MEMBER_OFFSET("ftrace_event_call", "name"),
7f7d26
+		ANON_MEMBER_OFFSET("trace_event_call", "name"));
7f7d26
+	if (name_offset < 0)
7f7d26
+		return -1;
7f7d26
+
7f7d26
+	flags_offset = MAX(MEMBER_OFFSET("ftrace_event_call", "flags"),
7f7d26
+		MEMBER_OFFSET("trace_event_call", "flags"));
7f7d26
+	if (flags_offset < 0)
7f7d26
+		return -1;
7f7d26
+
7f7d26
+	tp_name_offset = MEMBER_OFFSET("tracepoint", "name");
7f7d26
+	if (tp_name_offset < 0)
7f7d26
+		return -1;
7f7d26
+
7f7d26
+	inited = 2;
7f7d26
+
7f7d26
+work:
7f7d26
 	if (name_offset < 0)
7f7d26
 		return -1;
7f7d26
 
7f7d26
@@ -1008,6 +1061,21 @@ int ftrace_get_event_type_name(ulong cal
7f7d26
 			"read ftrace_event_call name_addr", RETURN_ON_ERROR))
7f7d26
 		return -1;
7f7d26
 
7f7d26
+	if (inited == 2) {
7f7d26
+		if (!readmem(call + flags_offset, KVADDR, &flags,
7f7d26
+			     sizeof(flags), "read ftrace_event_call flags",
7f7d26
+			     RETURN_ON_ERROR))
7f7d26
+			return -1;
7f7d26
+
7f7d26
+		if (flags & TRACE_EVENT_FL_TRACEPOINT) {
7f7d26
+			if (!readmem(name_addr + tp_name_offset, KVADDR,
7f7d26
+				     &name_addr, sizeof(name_addr),
7f7d26
+				     "read tracepoint name", RETURN_ON_ERROR))
7f7d26
+				return -1;
7f7d26
+		}
7f7d26
+
7f7d26
+	}
7f7d26
+
7f7d26
 	if (!read_string(name_addr, name, len))
7f7d26
 		return -1;
7f7d26
 
7f7d26
@@ -1028,16 +1096,19 @@ int ftrace_get_event_type_system(ulong c
7f7d26
 		goto work;
7f7d26
 
7f7d26
 	inited = 1;
7f7d26
-	sys_offset = MEMBER_OFFSET("ftrace_event_call", "system");
7f7d26
+	sys_offset = MAX(MEMBER_OFFSET("ftrace_event_call", "system"),
7f7d26
+		MEMBER_OFFSET("trace_event_call", "system"));
7f7d26
 
7f7d26
 	if (sys_offset >= 0)
7f7d26
 		goto work;
7f7d26
 
7f7d26
-	class_offset = MEMBER_OFFSET("ftrace_event_call", "class");
7f7d26
+	class_offset = MAX(MEMBER_OFFSET("ftrace_event_call", "class"),
7f7d26
+		MEMBER_OFFSET("trace_event_call", "class"));
7f7d26
 	if (class_offset < 0)
7f7d26
 		return -1;
7f7d26
 
7f7d26
-	sys_offset = MEMBER_OFFSET("ftrace_event_class", "system");
7f7d26
+	sys_offset = MAX(MEMBER_OFFSET("ftrace_event_class", "system"),
7f7d26
+		MEMBER_OFFSET("trace_event_class", "system"));
7f7d26
 	inited = 2;
7f7d26
 
7f7d26
 work:
7f7d26
@@ -1109,7 +1180,8 @@ int ftrace_get_event_type_print_fmt(ulon
7f7d26
 
7f7d26
 	if (!inited) {
7f7d26
 		inited = 1;
7f7d26
-		fmt_offset = MEMBER_OFFSET("ftrace_event_call", "print_fmt");
7f7d26
+		fmt_offset = MAX(MEMBER_OFFSET("ftrace_event_call", "print_fmt"),
7f7d26
+			MEMBER_OFFSET("trace_event_call", "print_fmt"));
7f7d26
 	}
7f7d26
 
7f7d26
 	if (fmt_offset < 0) {
7f7d26
@@ -1132,11 +1204,13 @@ int ftrace_get_event_type_id(ulong call,
7f7d26
 
7f7d26
 	if (!inited) {
7f7d26
 		inited = 1;
7f7d26
-		id_offset = MEMBER_OFFSET("ftrace_event_call", "id");
7f7d26
+		id_offset = MAX(MEMBER_OFFSET("ftrace_event_call", "id"),
7f7d26
+			MEMBER_OFFSET("trace_event_call", "id"));
7f7d26
 
7f7d26
 		if (id_offset < 0) {
7f7d26
 			/* id = call->event.type */
7f7d26
-			int f1 = MEMBER_OFFSET("ftrace_event_call", "event");
7f7d26
+			int f1 = MAX(MEMBER_OFFSET("ftrace_event_call", "event"),
7f7d26
+				MEMBER_OFFSET("trace_event_call", "event"));
7f7d26
 			int f2 = MEMBER_OFFSET("trace_event", "type");
7f7d26
 
7f7d26
 			if (f1 >= 0 && f2 >= 0)
7f7d26
@@ -1495,7 +1569,6 @@ static void ftrace_show(int argc, char *
7f7d26
 	FILE *file;
7f7d26
 	size_t ret;
7f7d26
 	size_t nitems __attribute__ ((__unused__));
7f7d26
-	char *unused __attribute__ ((__unused__));
7f7d26
 
7f7d26
 	/* check trace-cmd */
7f7d26
 	if (env_trace_cmd)
7f7d26
@@ -1519,8 +1592,9 @@ static void ftrace_show(int argc, char *
7f7d26
 	}
7f7d26
 
7f7d26
 	/* dump trace.dat to the temp file */
7f7d26
-	unused = mktemp(tmp);
7f7d26
-	fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0644);
7f7d26
+	fd = mkstemp(tmp);
7f7d26
+	if (fd < 0)
7f7d26
+		return;
7f7d26
 	if (trace_cmd_data_output(fd) < 0)
7f7d26
 		goto out;
7f7d26