diff options
| author | Alistair Popple <alistair@popple.id.au> | 2018-10-15 16:13:56 +1100 |
|---|---|---|
| committer | Alistair Popple <alistair@popple.id.au> | 2018-10-15 16:22:04 +1100 |
| commit | 2ba1e634c71404514889dd4be0a38b5a80faf760 (patch) | |
| tree | a4fda5bcb33177219facdc4700c71877fabc7ab6 | |
| parent | d150713c357c69247d95843717935097f5ee30b0 (diff) | |
| download | pdbg-2ba1e634c71404514889dd4be0a38b5a80faf760.tar.gz pdbg-2ba1e634c71404514889dd4be0a38b5a80faf760.zip | |
regs: Allow user to opt in to backtrace
The backtrace causes us to read memory which appears to have a high
likelihood of causing a checkstop due to an invalid address.
This adds a --backtrace flag to the regs command which enables the
backtrace. By default it is off to protect the user.
Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Alistair Popple <alistair@popple.id.au>
| -rw-r--r-- | src/main.c | 2 | ||||
| -rw-r--r-- | src/thread.c | 20 |
2 files changed, 16 insertions, 6 deletions
@@ -135,7 +135,7 @@ static struct action actions[] = { { "putmem", "<address>", "Write to system memory" }, { "threadstatus", "", "Print the status of a thread" }, { "sreset", "", "Reset" }, - { "regs", "", "State" }, + { "regs", "[--backtrace]", "State (optionally display backtrace)" }, }; static void print_usage(char *pname) diff --git a/src/thread.c b/src/thread.c index d282307..e755620 100644 --- a/src/thread.c +++ b/src/thread.c @@ -185,14 +185,16 @@ static int sreset_thread(struct pdbg_target *thread_target, uint32_t index, uint return ram_sreset_thread(thread_target) ? 0 : 1; } -static int state_thread(struct pdbg_target *thread_target, uint32_t index, uint64_t *unused, uint64_t *unused1) +static int state_thread(struct pdbg_target *thread_target, uint32_t index, uint64_t *i_doBacktrace, uint64_t *unused) { struct thread_regs regs; + bool do_backtrace = (bool) i_doBacktrace; if (ram_state_thread(thread_target, ®s)) return 0; - dump_stack(®s); + if (do_backtrace) + dump_stack(®s); return 1; } @@ -227,14 +229,22 @@ static int thread_sreset(void) } OPTCMD_DEFINE_CMD(sreset, thread_sreset); -static int thread_state(void) + +struct reg_flags { + bool do_backtrace; +}; + +#define REG_BACKTRACE_FLAG ("--backtrace", do_backtrace, parse_flag_noarg, false) + +static int thread_state(struct reg_flags flags) { int err; - err = for_each_target("thread", state_thread, NULL, NULL); + err = for_each_target("thread", state_thread, + (uint64_t *)flags.do_backtrace, NULL); for_each_target_release("thread"); return err; } -OPTCMD_DEFINE_CMD(regs, thread_state); +OPTCMD_DEFINE_CMD_ONLY_FLAGS(regs, thread_state, reg_flags, (REG_BACKTRACE_FLAG)); |

