Skip to content

Commit

Permalink
core/exceptions.c: do not include handler code in exception backtrace
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
npiggin authored and oohal committed Oct 2, 2019
1 parent 216433a commit 1785745
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/exceptions.c
Expand Up @@ -112,7 +112,7 @@ void exception_entry(struct stack_frame *stack)
l += snprintf(buf + l, EXCEPTION_MAX_STR - l, " MSR "REG, msr);
prerror("%s\n", buf);
dump_regs(stack);
backtrace();
backtrace_r1((uint64_t)stack);
if (platform.terminate)
platform.terminate(buf);
for (;;) ;
Expand All @@ -129,7 +129,7 @@ void exception_entry(struct stack_frame *stack)
l += snprintf(buf + l, EXCEPTION_MAX_STR - l, " MSR "REG, msr);
prerror("%s\n", buf);
dump_regs(stack);
backtrace();
backtrace_r1((uint64_t)stack);
if (fatal) {
if (platform.terminate)
platform.terminate(buf);
Expand Down
30 changes: 26 additions & 4 deletions core/stack.c
Expand Up @@ -17,13 +17,13 @@
static struct bt_entry bt_buf[STACK_BUF_ENTRIES];

/* Dumps backtrace to buffer */
void __nomcount backtrace_create(struct bt_entry *entries,
static void __nomcount __backtrace_create(struct bt_entry *entries,
unsigned int max_ents,
struct bt_metadata *metadata)
struct bt_metadata *metadata,
struct stack_frame *eframe)
{
unsigned long *fp = __builtin_frame_address(0);
unsigned long *fp = (unsigned long *)eframe;
unsigned long top_adj = top_of_ram;
struct stack_frame *eframe = (struct stack_frame *)fp;

/* Assume one stack for early backtraces */
if (top_of_ram == SKIBOOT_BASE + SKIBOOT_SIZE)
Expand Down Expand Up @@ -52,6 +52,16 @@ void __nomcount backtrace_create(struct bt_entry *entries,
metadata->pir = mfspr(SPR_PIR);
}

void __nomcount backtrace_create(struct bt_entry *entries,
unsigned int max_ents,
struct bt_metadata *metadata)
{
unsigned long *fp = __builtin_frame_address(0);
struct stack_frame *eframe = (struct stack_frame *)fp;

__backtrace_create(entries, max_ents, metadata, eframe);
}

void backtrace_print(struct bt_entry *entries, struct bt_metadata *metadata,
char *out_buf, unsigned int *len, bool symbols)
{
Expand Down Expand Up @@ -124,6 +134,18 @@ void backtrace(void)
unlock(&bt_lock);
}

void backtrace_r1(uint64_t r1)
{
struct bt_metadata metadata;

lock(&bt_lock);

__backtrace_create(bt_buf, STACK_BUF_ENTRIES, &metadata, (struct stack_frame *)r1);
backtrace_print(bt_buf, &metadata, NULL, NULL, true);

unlock(&bt_lock);
}

void __nomcount __stack_chk_fail(void);
void __nomcount __stack_chk_fail(void)
{
Expand Down
3 changes: 3 additions & 0 deletions include/stack.h
Expand Up @@ -123,6 +123,9 @@ extern void backtrace_print(struct bt_entry *entries,
/* For use by debug code, create and print backtrace, uses a static buffer */
extern void backtrace(void);

/* For use by exception debug code, supply an r1 */
extern void backtrace_r1(uint64_t r1);

#ifdef STACK_CHECK_ENABLED
extern void check_stacks(void);
#else
Expand Down

0 comments on commit 1785745

Please sign in to comment.