@@ -165,6 +165,8 @@ struct tracecmd_input {
__thread struct tracecmd_input *tracecmd_curr_thread_handle;
+#define CHECK_READ_STATE(H, S) ((H)->file_version < FILE_VERSION_SECTIONS && (H)->file_state >= (S))
+
static int read_options_type(struct tracecmd_input *handle);
void tracecmd_set_flag(struct tracecmd_input *handle, int flag)
@@ -381,7 +383,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))
@@ -587,7 +589,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) {
@@ -660,7 +662,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) {
@@ -745,7 +747,7 @@ static int read_proc_kallsyms(struct tracecmd_input *handle)
char *buf = NULL;
int ret;
- if (handle->file_state >= TRACECMD_FILE_KALLSYMS)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_KALLSYMS))
return 0;
ret = read4(handle, &size);
@@ -781,7 +783,7 @@ static int read_ftrace_printk(struct tracecmd_input *handle)
char *buf = NULL;
int ret;
- if (handle->file_state >= TRACECMD_FILE_PRINTK)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_PRINTK))
return 0;
ret = read4(handle, &size);
@@ -832,7 +834,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)
@@ -2838,7 +2840,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))
@@ -3004,7 +3006,7 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle)
char *cmdlines = NULL;
int ret;
- if (handle->file_state >= TRACECMD_FILE_CMD_LINES)
+ if (CHECK_READ_STATE(handle, TRACECMD_FILE_CMD_LINES))
return 0;
ret = read_data_and_size(handle, &cmdlines, &size);
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(-)