@@ -166,6 +166,8 @@ struct tracecmd_input {
__thread struct tracecmd_input *tracecmd_curr_thread_handle;
+#define CHECK_READ_STATE(H, S) ((H)->file_version < 7 && (H)->file_state >= (S))
+
static int read_options_type(struct tracecmd_input *handle);
void tracecmd_set_flag(struct tracecmd_input *handle, int flag)
@@ -416,7 +418,7 @@ static int read_header_files(struct tracecmd_input *handle)
char *header;
char buf[BUFSIZ];
- if (handle->file_state >= TRACECMD_FILE_HEADERS)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_HEADERS))
return 0;
if (do_read_check(handle, buf, 12))
@@ -623,7 +625,7 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex)
int unique;
int ret;
- if (handle->file_state >= TRACECMD_FILE_FTRACE_EVENTS)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_FTRACE_EVENTS))
return 0;
if (regex) {
@@ -694,7 +696,7 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex)
int unique;
int ret;
- if (handle->file_state >= TRACECMD_FILE_ALL_EVENTS)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_ALL_EVENTS))
return 0;
if (regex) {
@@ -779,7 +781,7 @@ static int read_proc_kallsyms(struct tracecmd_input *handle)
unsigned int size;
char *buf;
- if (handle->file_state >= TRACECMD_FILE_KALLSYMS)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_KALLSYMS))
return 0;
if (read4(handle, &size) < 0)
@@ -810,7 +812,7 @@ static int read_ftrace_printk(struct tracecmd_input *handle)
unsigned int size;
char *buf;
- if (handle->file_state >= TRACECMD_FILE_PRINTK)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_PRINTK))
return 0;
if (read4(handle, &size) < 0)
@@ -856,7 +858,7 @@ static int read_cpus(struct tracecmd_input *handle)
{
unsigned int cpus;
- if (handle->file_state >= TRACECMD_FILE_CPU_COUNT)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_CPU_COUNT))
return 0;
if (read4(handle, &cpus) < 0)
@@ -2862,7 +2864,7 @@ static int read_options_type(struct tracecmd_input *handle)
{
char buf[10];
- if (handle->file_state >= TRACECMD_FILE_CPU_LATENCY)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_CPU_LATENCY))
return 0;
if (do_read_check(handle, buf, 10))
@@ -3026,7 +3028,7 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle)
unsigned long long size;
char *cmdlines;
- if (handle->file_state >= TRACECMD_FILE_CMD_LINES)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_CMD_LINES))
return 0;
if (read_data_and_size(handle, &cmdlines, &size) < 0)
Trace file version 7 has flexible structure. It allows reading almost any part of the file at any time, unlike the version 6 file when reading state must be validated at each step. Added a macro to handle these checks. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- lib/trace-cmd/trace-input.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)