aboutsummaryrefslogtreecommitdiffstats
path: root/vppinfra/vppinfra/backtrace.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2016-08-15 11:12:27 -0400
committerDave Barach <dave@barachs.net>2016-08-15 11:12:40 -0400
commitc379999665febd12ec55bfb3a7545224f2b39d3d (patch)
tree8bf0c11e52c2162e1239b6c3f4a5f74b62a07409 /vppinfra/vppinfra/backtrace.c
parentb3d93dacfde8ab21bbce171fff2971b2ed7bce6a (diff)
VPP-327 Coding standards cleanup for vppinfra
Fix additional a few additional deviations reported elsewhere by checkstyle Change-Id: I026a8ae1c5b1856bbe3c4a555e1b690e7501b045 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'vppinfra/vppinfra/backtrace.c')
-rw-r--r--vppinfra/vppinfra/backtrace.c263
1 files changed, 133 insertions, 130 deletions
diff --git a/vppinfra/vppinfra/backtrace.c b/vppinfra/vppinfra/backtrace.c
index dc9c2565023..bbfb792c656 100644
--- a/vppinfra/vppinfra/backtrace.c
+++ b/vppinfra/vppinfra/backtrace.c
@@ -46,28 +46,22 @@
#include <vppinfra/asm_mips.h>
uword
-clib_backtrace (uword * callers,
- uword max_callers,
- uword n_frames_to_skip)
+clib_backtrace (uword * callers, uword max_callers, uword n_frames_to_skip)
{
- u32 * pc;
- void * sp;
+ u32 *pc;
+ void *sp;
uword i, saved_pc;
/* Figure current PC, saved PC and stack pointer. */
asm volatile (".set push\n"
- ".set noat\n"
- "move %[saved_pc], $31\n"
- "move %[sp], $29\n"
+ ".set noat\n" "move %[saved_pc], $31\n" "move %[sp], $29\n"
/* Fetches current PC. */
"la $at, 1f\n"
"jalr %[pc], $at\n"
"nop\n"
"1:\n"
- ".set pop\n"
- : [pc] "=r" (pc),
- [saved_pc] "=r" (saved_pc),
- [sp] "=r" (sp));
+ ".set pop\n":[pc] "=r" (pc),
+ [saved_pc] "=r" (saved_pc),[sp] "=r" (sp));
/* Also skip current frame. */
n_frames_to_skip += 1;
@@ -77,11 +71,11 @@ clib_backtrace (uword * callers,
mips_insn_opcode_t op;
mips_insn_special_funct_t funct;
i32 insn, rs, rt, rd, immediate, found_saved_pc;
- u32 * start_pc;
+ u32 *start_pc;
/* Parse instructions until we reach prologue for this
- stack frame. We'll need to figure out where saved
- PC is and where previous stack frame lives. */
+ stack frame. We'll need to figure out where saved
+ PC is and where previous stack frame lives. */
start_pc = pc;
found_saved_pc = 0;
while (1)
@@ -94,125 +88,127 @@ clib_backtrace (uword * callers,
rd = mips_insn_get_rd (insn);
immediate = mips_insn_get_immediate (insn);
- switch (op) {
- default:
- break;
-
- case MIPS_OPCODE_sd:
- case MIPS_OPCODE_sw:
- /* Trace stores of return address. */
- if (rt == MIPS_REG_RA)
- {
- void * addr = sp + immediate;
-
- /* If RA is stored somewhere other than in the
- stack frame, give up. */
- if (rs != MIPS_REG_SP)
- goto backtrace_done;
-
- ASSERT (immediate % 4 == 0);
- if (op == MIPS_OPCODE_sw)
- saved_pc = ((u32 *) addr)[0];
- else
- saved_pc = ((u64 *) addr)[0];
- found_saved_pc = 1;
- }
- break;
-
- case MIPS_OPCODE_addiu:
- case MIPS_OPCODE_daddiu:
- case MIPS_OPCODE_addi:
- case MIPS_OPCODE_daddi:
- if (rt == MIPS_REG_SP)
- {
- if (rs != MIPS_REG_SP)
- goto backtrace_done;
-
- ASSERT (immediate % 4 == 0);
-
- /* Assume positive offset is part of the epilogue.
- E.g.
- jr ra
- add sp,sp,100
- */
- if (immediate > 0)
- continue;
-
- /* Negative offset means allocate stack space.
- This could either be the prologue or could be due to
- alloca. */
- sp -= immediate;
-
- /* This frame will not save RA. */
- if (i == 0)
- goto found_prologue;
-
- /* Assume that addiu sp,sp,-N without store of ra means
- that we have not found the prologue yet. */
- if (found_saved_pc)
- goto found_prologue;
- }
- break;
-
- case MIPS_OPCODE_slti:
- case MIPS_OPCODE_sltiu:
- case MIPS_OPCODE_andi:
- case MIPS_OPCODE_ori:
- case MIPS_OPCODE_xori:
- case MIPS_OPCODE_lui:
- case MIPS_OPCODE_ldl:
- case MIPS_OPCODE_ldr:
- case MIPS_OPCODE_lb:
- case MIPS_OPCODE_lh:
- case MIPS_OPCODE_lwl:
- case MIPS_OPCODE_lw:
- case MIPS_OPCODE_lbu:
- case MIPS_OPCODE_lhu:
- case MIPS_OPCODE_lwr:
- case MIPS_OPCODE_lwu:
- case MIPS_OPCODE_ld:
- /* Give up when we find anyone setting the stack pointer. */
- if (rt == MIPS_REG_SP)
- goto backtrace_done;
- break;
-
- case MIPS_OPCODE_SPECIAL:
- if (rd == MIPS_REG_SP)
- switch (funct) {
+ switch (op)
+ {
default:
+ break;
+
+ case MIPS_OPCODE_sd:
+ case MIPS_OPCODE_sw:
+ /* Trace stores of return address. */
+ if (rt == MIPS_REG_RA)
+ {
+ void *addr = sp + immediate;
+
+ /* If RA is stored somewhere other than in the
+ stack frame, give up. */
+ if (rs != MIPS_REG_SP)
+ goto backtrace_done;
+
+ ASSERT (immediate % 4 == 0);
+ if (op == MIPS_OPCODE_sw)
+ saved_pc = ((u32 *) addr)[0];
+ else
+ saved_pc = ((u64 *) addr)[0];
+ found_saved_pc = 1;
+ }
+ break;
+
+ case MIPS_OPCODE_addiu:
+ case MIPS_OPCODE_daddiu:
+ case MIPS_OPCODE_addi:
+ case MIPS_OPCODE_daddi:
+ if (rt == MIPS_REG_SP)
+ {
+ if (rs != MIPS_REG_SP)
+ goto backtrace_done;
+
+ ASSERT (immediate % 4 == 0);
+
+ /* Assume positive offset is part of the epilogue.
+ E.g.
+ jr ra
+ add sp,sp,100
+ */
+ if (immediate > 0)
+ continue;
+
+ /* Negative offset means allocate stack space.
+ This could either be the prologue or could be due to
+ alloca. */
+ sp -= immediate;
+
+ /* This frame will not save RA. */
+ if (i == 0)
+ goto found_prologue;
+
+ /* Assume that addiu sp,sp,-N without store of ra means
+ that we have not found the prologue yet. */
+ if (found_saved_pc)
+ goto found_prologue;
+ }
+ break;
+
+ case MIPS_OPCODE_slti:
+ case MIPS_OPCODE_sltiu:
+ case MIPS_OPCODE_andi:
+ case MIPS_OPCODE_ori:
+ case MIPS_OPCODE_xori:
+ case MIPS_OPCODE_lui:
+ case MIPS_OPCODE_ldl:
+ case MIPS_OPCODE_ldr:
+ case MIPS_OPCODE_lb:
+ case MIPS_OPCODE_lh:
+ case MIPS_OPCODE_lwl:
+ case MIPS_OPCODE_lw:
+ case MIPS_OPCODE_lbu:
+ case MIPS_OPCODE_lhu:
+ case MIPS_OPCODE_lwr:
+ case MIPS_OPCODE_lwu:
+ case MIPS_OPCODE_ld:
/* Give up when we find anyone setting the stack pointer. */
- goto backtrace_done;
-
- case MIPS_SPECIAL_FUNCT_break:
- case MIPS_SPECIAL_FUNCT_jr:
- case MIPS_SPECIAL_FUNCT_sync:
- case MIPS_SPECIAL_FUNCT_syscall:
- case MIPS_SPECIAL_FUNCT_tge:
- case MIPS_SPECIAL_FUNCT_tgeu:
- case MIPS_SPECIAL_FUNCT_tlt:
- case MIPS_SPECIAL_FUNCT_tltu:
- case MIPS_SPECIAL_FUNCT_teq:
- case MIPS_SPECIAL_FUNCT_tne:
- /* These instructions can validly have rd == MIPS_REG_SP */
+ if (rt == MIPS_REG_SP)
+ goto backtrace_done;
+ break;
+
+ case MIPS_OPCODE_SPECIAL:
+ if (rd == MIPS_REG_SP)
+ switch (funct)
+ {
+ default:
+ /* Give up when we find anyone setting the stack pointer. */
+ goto backtrace_done;
+
+ case MIPS_SPECIAL_FUNCT_break:
+ case MIPS_SPECIAL_FUNCT_jr:
+ case MIPS_SPECIAL_FUNCT_sync:
+ case MIPS_SPECIAL_FUNCT_syscall:
+ case MIPS_SPECIAL_FUNCT_tge:
+ case MIPS_SPECIAL_FUNCT_tgeu:
+ case MIPS_SPECIAL_FUNCT_tlt:
+ case MIPS_SPECIAL_FUNCT_tltu:
+ case MIPS_SPECIAL_FUNCT_teq:
+ case MIPS_SPECIAL_FUNCT_tne:
+ /* These instructions can validly have rd == MIPS_REG_SP */
+ break;
+ }
break;
}
- break;
- }
}
found_prologue:
/* Check sanity of saved pc. */
if (saved_pc & 3)
- goto backtrace_done;
+ goto backtrace_done;
if (saved_pc == 0)
- goto backtrace_done;
+ goto backtrace_done;
if (i >= n_frames_to_skip)
callers[i - n_frames_to_skip] = saved_pc;
pc = uword_to_pointer (saved_pc, u32 *);
}
- backtrace_done:
+backtrace_done:
if (i < n_frames_to_skip)
return 0;
else
@@ -223,20 +219,19 @@ clib_backtrace (uword * callers,
#ifndef clib_backtrace_defined
#define clib_backtrace_defined
-typedef struct clib_generic_stack_frame_t {
- struct clib_generic_stack_frame_t * prev;
- void * return_address;
+typedef struct clib_generic_stack_frame_t
+{
+ struct clib_generic_stack_frame_t *prev;
+ void *return_address;
} clib_generic_stack_frame_t;
/* This will only work if we have a frame pointer.
Without a frame pointer we have to parse the machine code to
parse the stack frames. */
uword
-clib_backtrace (uword * callers,
- uword max_callers,
- uword n_frames_to_skip)
+clib_backtrace (uword * callers, uword max_callers, uword n_frames_to_skip)
{
- clib_generic_stack_frame_t * f;
+ clib_generic_stack_frame_t *f;
uword i;
f = __builtin_frame_address (0);
@@ -247,18 +242,26 @@ clib_backtrace (uword * callers,
for (i = 0; i < max_callers + n_frames_to_skip; i++)
{
f = f->prev;
- if (! f)
+ if (!f)
goto backtrace_done;
- if (clib_abs ((void *) f - (void *) f->prev) > (64*1024))
+ if (clib_abs ((void *) f - (void *) f->prev) > (64 * 1024))
goto backtrace_done;
if (i >= n_frames_to_skip)
callers[i - n_frames_to_skip] = pointer_to_uword (f->return_address);
}
- backtrace_done:
+backtrace_done:
if (i < n_frames_to_skip)
- return 0;
+ return 0;
else
- return i - n_frames_to_skip;
+ return i - n_frames_to_skip;
}
#endif /* clib_backtrace_defined */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */