mirror of
https://github.com/torvalds/linux.git
synced 2024-11-26 14:12:06 +00:00
kdb: Provide forward search at more prompt
Currently kdb allows the output of comamnds to be filtered using the | grep feature. This is useful but does not permit the output emitted shortly after a string match to be examined without wading through the entire unfiltered output of the command. Such a feature is particularly useful to navigate function traces because these traces often have a useful trigger string *before* the point of interest. This patch reuses the existing filtering logic to introduce a simple forward search to kdb that can be triggered from the more prompt. Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
This commit is contained in:
parent
ab08e464a2
commit
fb6daa7520
@ -680,6 +680,12 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
|
|||||||
size_avail = sizeof(kdb_buffer) - len;
|
size_avail = sizeof(kdb_buffer) - len;
|
||||||
goto kdb_print_out;
|
goto kdb_print_out;
|
||||||
}
|
}
|
||||||
|
if (kdb_grepping_flag >= KDB_GREPPING_FLAG_SEARCH)
|
||||||
|
/*
|
||||||
|
* This was a interactive search (using '/' at more
|
||||||
|
* prompt) and it has completed. Clear the flag.
|
||||||
|
*/
|
||||||
|
kdb_grepping_flag = 0;
|
||||||
/*
|
/*
|
||||||
* at this point the string is a full line and
|
* at this point the string is a full line and
|
||||||
* should be printed, up to the null.
|
* should be printed, up to the null.
|
||||||
@ -798,11 +804,23 @@ kdb_printit:
|
|||||||
kdb_nextline = linecount - 1;
|
kdb_nextline = linecount - 1;
|
||||||
kdb_printf("\r");
|
kdb_printf("\r");
|
||||||
suspend_grep = 1; /* for this recursion */
|
suspend_grep = 1; /* for this recursion */
|
||||||
|
} else if (buf1[0] == '/' && !kdb_grepping_flag) {
|
||||||
|
kdb_printf("\r");
|
||||||
|
kdb_getstr(kdb_grep_string, KDB_GREP_STRLEN,
|
||||||
|
kdbgetenv("SEARCHPROMPT") ?: "search> ");
|
||||||
|
*strchrnul(kdb_grep_string, '\n') = '\0';
|
||||||
|
kdb_grepping_flag += KDB_GREPPING_FLAG_SEARCH;
|
||||||
|
suspend_grep = 1; /* for this recursion */
|
||||||
} else if (buf1[0] && buf1[0] != '\n') {
|
} else if (buf1[0] && buf1[0] != '\n') {
|
||||||
/* user hit something other than enter */
|
/* user hit something other than enter */
|
||||||
suspend_grep = 1; /* for this recursion */
|
suspend_grep = 1; /* for this recursion */
|
||||||
kdb_printf("\nOnly 'q' or 'Q' are processed at more "
|
if (buf1[0] != '/')
|
||||||
"prompt, input ignored\n");
|
kdb_printf(
|
||||||
|
"\nOnly 'q', 'Q' or '/' are processed at "
|
||||||
|
"more prompt, input ignored\n");
|
||||||
|
else
|
||||||
|
kdb_printf("\n'/' cannot be used during | "
|
||||||
|
"grep filtering, input ignored\n");
|
||||||
} else if (kdb_grepping_flag) {
|
} else if (kdb_grepping_flag) {
|
||||||
/* user hit enter */
|
/* user hit enter */
|
||||||
suspend_grep = 1; /* for this recursion */
|
suspend_grep = 1; /* for this recursion */
|
||||||
|
@ -50,8 +50,7 @@
|
|||||||
static int kdb_cmd_enabled = CONFIG_KDB_DEFAULT_ENABLE;
|
static int kdb_cmd_enabled = CONFIG_KDB_DEFAULT_ENABLE;
|
||||||
module_param_named(cmd_enable, kdb_cmd_enabled, int, 0600);
|
module_param_named(cmd_enable, kdb_cmd_enabled, int, 0600);
|
||||||
|
|
||||||
#define GREP_LEN 256
|
char kdb_grep_string[KDB_GREP_STRLEN];
|
||||||
char kdb_grep_string[GREP_LEN];
|
|
||||||
int kdb_grepping_flag;
|
int kdb_grepping_flag;
|
||||||
EXPORT_SYMBOL(kdb_grepping_flag);
|
EXPORT_SYMBOL(kdb_grepping_flag);
|
||||||
int kdb_grep_leading;
|
int kdb_grep_leading;
|
||||||
@ -870,7 +869,7 @@ static void parse_grep(const char *str)
|
|||||||
len = strlen(cp);
|
len = strlen(cp);
|
||||||
if (!len)
|
if (!len)
|
||||||
return;
|
return;
|
||||||
if (len >= GREP_LEN) {
|
if (len >= KDB_GREP_STRLEN) {
|
||||||
kdb_printf("search string too long\n");
|
kdb_printf("search string too long\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1280,6 +1279,8 @@ static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs,
|
|||||||
kdb_nextline = 1;
|
kdb_nextline = 1;
|
||||||
KDB_STATE_CLEAR(SUPPRESS);
|
KDB_STATE_CLEAR(SUPPRESS);
|
||||||
kdb_grepping_flag = 0;
|
kdb_grepping_flag = 0;
|
||||||
|
/* ensure the old search does not leak into '/' commands */
|
||||||
|
kdb_grep_string[0] = '\0';
|
||||||
|
|
||||||
cmdbuf = cmd_cur;
|
cmdbuf = cmd_cur;
|
||||||
*cmdbuf = '\0';
|
*cmdbuf = '\0';
|
||||||
|
@ -196,7 +196,9 @@ extern int kdb_main_loop(kdb_reason_t, kdb_reason_t,
|
|||||||
|
|
||||||
/* Miscellaneous functions and data areas */
|
/* Miscellaneous functions and data areas */
|
||||||
extern int kdb_grepping_flag;
|
extern int kdb_grepping_flag;
|
||||||
|
#define KDB_GREPPING_FLAG_SEARCH 0x8000
|
||||||
extern char kdb_grep_string[];
|
extern char kdb_grep_string[];
|
||||||
|
#define KDB_GREP_STRLEN 256
|
||||||
extern int kdb_grep_leading;
|
extern int kdb_grep_leading;
|
||||||
extern int kdb_grep_trailing;
|
extern int kdb_grep_trailing;
|
||||||
extern char *kdb_cmds[];
|
extern char *kdb_cmds[];
|
||||||
|
Loading…
Reference in New Issue
Block a user