mirror of
https://github.com/crash-utility/crash
synced 2025-02-23 00:46:48 +00:00
Add support for the "count" argument to be used in conjunction with
the "dis -r" and "dis -f" reverse/forward modes of operation. In reverse mode, the specified "count" number of instructions leading up to and including the target address will be displayed. In forward mode, the display will be limited to "count" instructions. Without the patch, using a count argument in either mode generates a "count argument ignored" message, and the command proceeds as if it had not been entered. (anderson@redhat.com, atomlin@redhat.com)
This commit is contained in:
parent
72654f8c62
commit
6c891b667f
4
help.c
4
help.c
@ -7219,8 +7219,8 @@ char *help_dis[] = {
|
||||
" count the number of instructions to be disassembled (default is 1).",
|
||||
" If no count argument is entered, and the starting address",
|
||||
" is entered as a text symbol, then the whole routine will be",
|
||||
" disassembled. The count argument is ignored when used with",
|
||||
" the -r option.",
|
||||
" disassembled. The count argument is supported when used with",
|
||||
" the -r and -f options.",
|
||||
"\nEXAMPLES",
|
||||
" Disassemble the sys_signal() routine without, and then with, line numbers:\n",
|
||||
" %s> dis sys_signal",
|
||||
|
63
kernel.c
63
kernel.c
@ -1741,6 +1741,45 @@ duplicates:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
set_reverse_tmpfile_offset(struct gnu_request *req, ulong target)
|
||||
{
|
||||
long index, *tmpfile_offsets;
|
||||
ulong curaddr;
|
||||
char buf[BUFSIZE];
|
||||
|
||||
if ((tmpfile_offsets = (long *)calloc(sizeof(long), req->count)) == NULL)
|
||||
return FALSE;
|
||||
|
||||
rewind(pc->tmpfile);
|
||||
index = 0;
|
||||
tmpfile_offsets[index] = ftell(pc->tmpfile);
|
||||
|
||||
while (fgets(buf, BUFSIZE, pc->tmpfile)) {
|
||||
strip_beginning_whitespace(buf);
|
||||
if (STRNEQ(buf, "0x")) {
|
||||
extract_hex(buf, &curaddr, ':', TRUE);
|
||||
if (curaddr >= target)
|
||||
break;
|
||||
}
|
||||
index = (index+1) % req->count;
|
||||
tmpfile_offsets[index] = ftell(pc->tmpfile);
|
||||
}
|
||||
|
||||
if (((index+1) < req->count) && tmpfile_offsets[index+1])
|
||||
index++;
|
||||
else
|
||||
index = 0;
|
||||
|
||||
if (fseek(pc->tmpfile, tmpfile_offsets[index], SEEK_SET) < 0) {
|
||||
rewind(pc->tmpfile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This routine disassembles text in one of four manners. A starting
|
||||
* address, an expression, or symbol must be entered. Then:
|
||||
@ -1931,16 +1970,13 @@ cmd_dis(void)
|
||||
}
|
||||
|
||||
if (args[++optind]) {
|
||||
if (reverse || forward) {
|
||||
error(INFO,
|
||||
"count argument ignored with -%s option\n",
|
||||
reverse ? "r" : "f");
|
||||
} else {
|
||||
req->count = stol(args[optind],
|
||||
FAULT_ON_ERROR, NULL);
|
||||
req->flags &= ~GNU_FUNCTION_ONLY;
|
||||
count_entered++;
|
||||
}
|
||||
if (forward)
|
||||
forward = FALSE;
|
||||
req->count = stol(args[optind], FAULT_ON_ERROR, NULL);
|
||||
req->flags &= ~GNU_FUNCTION_ONLY;
|
||||
if (!req->count)
|
||||
error(FATAL, "invalid count argument: 0\n");
|
||||
count_entered++;
|
||||
}
|
||||
|
||||
if (sources) {
|
||||
@ -2023,7 +2059,12 @@ cmd_dis(void)
|
||||
error(FATAL, dis_err, req->addr);
|
||||
}
|
||||
|
||||
rewind(pc->tmpfile);
|
||||
if (reverse && count_entered &&
|
||||
set_reverse_tmpfile_offset(req, target))
|
||||
count_entered = FALSE;
|
||||
else
|
||||
rewind(pc->tmpfile);
|
||||
|
||||
while (fgets(buf2, BUFSIZE, pc->tmpfile)) {
|
||||
strip_beginning_whitespace(buf2);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user