Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace improvments #2011

Merged
merged 2 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/arch/arm/kernel/trace_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <kernel/thread.h>
#include <mm/core_mmu.h>

const char trace_ext_prefix[] = "TEE-CORE";
const char trace_ext_prefix[] = "TC";
int trace_level = TRACE_LEVEL;
static unsigned int puts_lock = SPINLOCK_UNLOCK;

Expand Down
58 changes: 37 additions & 21 deletions lib/libutils/ext/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,41 @@ int trace_get_level(void)
return trace_level;
}

static const char *trace_level_to_string(int level, bool level_ok)
static char trace_level_to_string(int level, bool level_ok)
{
static const char lvl_strs[][9] = {
"UNKNOWN:", "ERROR: ", "INFO: ", "DEBUG: ",
"FLOW: " };
/*
* U = Unused
* E = Error
* I = Information
* D = Debug
* F = Flow
*/
static const char lvl_strs[] = { 'U', 'E', 'I', 'D', 'F' };
int l = 0;

if (!level_ok)
return "MESSAGE:";
return 'M';

if ((level >= TRACE_MIN) && (level <= TRACE_MAX))
l = level;

return lvl_strs[l];
}

static int print_thread_id(char *buf, size_t bs, int thread_id)
{
#if CFG_NUM_THREADS > 9
int num_thread_digits = 2;
#else
int num_thread_digits = 1;
#endif

if (thread_id >= 0)
return snprintk(buf, bs, "%0*d ", num_thread_digits, thread_id);
else
return snprintk(buf, bs, "%*s ", num_thread_digits, "");
}

/* Format trace of user ta. Inline with kernel ta */
void trace_printf(const char *function, int line, int level, bool level_ok,
const char *fmt, ...)
Expand All @@ -80,47 +99,44 @@ void trace_printf(const char *function, int line, int level, bool level_ok,
if (level_ok && level > trace_level)
return;

res = snprintk(buf, sizeof(buf), "%s ",
/* Print the type of message */
res = snprintk(buf, sizeof(buf), "%c/",
trace_level_to_string(level, level_ok));
if (res < 0)
return;
boffs += res;

/* Print the location, i.e., TEE core or TA */
res = snprintk(buf + boffs, sizeof(buf) - boffs, "%s:",
trace_ext_prefix);
if (res < 0)
return;
boffs += res;

/* Print the Thread ID */
if (level_ok && !(BIT(level) & CFG_MSG_LONG_PREFIX_MASK))
thread_id = -1;
else
thread_id = trace_ext_get_thread_id();

if (thread_id >= 0) {
res = snprintk(buf + boffs, sizeof(buf) - boffs, "[0x%x] ",
thread_id);
if (res < 0)
return;
boffs += res;
}
res = print_thread_id(buf + boffs, sizeof(buf) - boffs, thread_id);

res = snprintk(buf + boffs, sizeof(buf) - boffs, "%s:",
trace_ext_prefix);
if (res < 0)
return;
boffs += res;

/* Print the function and line */
if (level_ok && !(BIT(level) & CFG_MSG_LONG_PREFIX_MASK))
function = NULL;

if (function) {
res = snprintk(buf + boffs, sizeof(buf) - boffs, "%s:%d:",
res = snprintk(buf + boffs, sizeof(buf) - boffs, "%s:%d ",
function, line);
if (res < 0)
return;
boffs += res;
}

res = snprintk(buf + boffs, sizeof(buf) - boffs, " ");
if (res < 0)
return;
boffs += res;

va_start(ap, fmt);
res = vsnprintk(buf + boffs, sizeof(buf) - boffs, fmt, ap);
va_end(ap);
Expand Down
7 changes: 5 additions & 2 deletions scripts/symbolize.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
import sys

TA_UUID_RE = re.compile(r'Status of TA (?P<uuid>[0-9a-f\-]+)')
TA_INFO_RE = re.compile(': arch: (?P<arch>\w+) '
TA_INFO_RE = re.compile(' arch: (?P<arch>\w+) '
'load address: (?P<load_addr>0x[0-9a-f]+)')
CALL_STACK_RE = re.compile('Call stack:')
STACK_ADDR_RE = re.compile(r': (?P<addr>0x[0-9a-f]+)')

# This gets the address from lines looking like this:
# E/TC:0 0x001044a8
STACK_ADDR_RE = re.compile(r'[UEIDFM]/T[AC]:.*(?P<addr>0x[0-9a-f]+)')
ABORT_ADDR_RE = re.compile('-abort at address (?P<addr>0x[0-9a-f]+)')
REGION_RE = re.compile('region [0-9]+: va (?P<addr>0x[0-9a-f]+) '
'pa 0x[0-9a-f]+ size (?P<size>0x[0-9a-f]+)')
Expand Down
6 changes: 1 addition & 5 deletions ta/arch/arm/user_ta_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@

int trace_level = TRACE_LEVEL;

#ifdef TA_LOG_PREFIX
const char trace_ext_prefix[] = TA_LOG_PREFIX;
#else
const char trace_ext_prefix[] = "USER-TA";
#endif
const char trace_ext_prefix[] = "TA";

#ifndef TA_VERSION
#define TA_VERSION "Undefined version"
Expand Down