Skip to content

Commit 00370b8

Browse files
Matt Kleinjwessel
authored andcommitted
kdb: Setup basic kdb state before invoking commands via kgdb
Although invasive kdb commands are not supported via kgdb, some useful non-invasive commands like bt* require basic kdb state to be setup before calling into the kdb code. Factor out some of this code and call it before and after executing kdb commands via kgdb. Signed-off-by: Matt Klein <mklein@twitter.com> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
1 parent 5f784f7 commit 00370b8

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

kernel/debug/debug_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ extern int dbg_kdb_mode;
7272
#ifdef CONFIG_KGDB_KDB
7373
extern int kdb_stub(struct kgdb_state *ks);
7474
extern int kdb_parse(const char *cmdstr);
75+
extern int kdb_common_init_state(struct kgdb_state *ks);
76+
extern int kdb_common_deinit_state(void);
7577
#else /* ! CONFIG_KGDB_KDB */
7678
static inline int kdb_stub(struct kgdb_state *ks)
7779
{

kernel/debug/gdbstub.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,10 @@ static void gdb_cmd_query(struct kgdb_state *ks)
782782
len = len / 2;
783783
remcom_out_buffer[len++] = 0;
784784

785+
kdb_common_init_state(ks);
785786
kdb_parse(remcom_out_buffer);
787+
kdb_common_deinit_state();
788+
786789
strcpy(remcom_out_buffer, "OK");
787790
}
788791
break;

kernel/debug/kdb/kdb_debugger.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ EXPORT_SYMBOL_GPL(kdb_poll_idx);
3434

3535
static struct kgdb_state *kdb_ks;
3636

37+
int kdb_common_init_state(struct kgdb_state *ks)
38+
{
39+
kdb_initial_cpu = atomic_read(&kgdb_active);
40+
kdb_current_task = kgdb_info[ks->cpu].task;
41+
kdb_current_regs = kgdb_info[ks->cpu].debuggerinfo;
42+
return 0;
43+
}
44+
45+
int kdb_common_deinit_state(void)
46+
{
47+
kdb_initial_cpu = -1;
48+
kdb_current_task = NULL;
49+
kdb_current_regs = NULL;
50+
return 0;
51+
}
52+
3753
int kdb_stub(struct kgdb_state *ks)
3854
{
3955
int error = 0;
@@ -94,9 +110,7 @@ int kdb_stub(struct kgdb_state *ks)
94110
}
95111
/* Set initial kdb state variables */
96112
KDB_STATE_CLEAR(KGDB_TRANS);
97-
kdb_initial_cpu = atomic_read(&kgdb_active);
98-
kdb_current_task = kgdb_info[ks->cpu].task;
99-
kdb_current_regs = kgdb_info[ks->cpu].debuggerinfo;
113+
kdb_common_init_state(ks);
100114
/* Remove any breakpoints as needed by kdb and clear single step */
101115
kdb_bp_remove();
102116
KDB_STATE_CLEAR(DOING_SS);
@@ -125,9 +139,7 @@ int kdb_stub(struct kgdb_state *ks)
125139
* Upon exit from the kdb main loop setup break points and restart
126140
* the system based on the requested continue state
127141
*/
128-
kdb_initial_cpu = -1;
129-
kdb_current_task = NULL;
130-
kdb_current_regs = NULL;
142+
kdb_common_deinit_state();
131143
KDB_STATE_CLEAR(PAGER);
132144
kdbnearsym_cleanup();
133145
if (error == KDB_CMD_KGDB) {

0 commit comments

Comments
 (0)